RtMallOrderPaymentApi.java 3.06 KB
package com.diligrp.cashier.mall.api;

import com.diligrp.cashier.mall.domain.rtmall.RtMarkMessage;
import com.diligrp.cashier.mall.domain.rtmall.co.OrderCO;
import com.diligrp.cashier.mall.domain.rtmall.co.PaymentAllocateCO;
import com.diligrp.cashier.mall.domain.rtmall.vo.OrderSuccessVO;
import com.diligrp.cashier.mall.service.biz.MallBizOrderService;
import com.diligrp.cashier.mall.service.biz.MallBizPaymentService;
import com.diligrp.cashier.mall.sign.RtMallSign;
import com.diligrp.cashier.mall.type.OrderType;
import com.diligrp.cashier.mall.util.RtMallValidateUtils;
import com.diligrp.cashier.shared.annotation.ParamLogPrint;
import com.diligrp.cashier.shared.annotation.RepeatSubmit;
import com.diligrp.cashier.shared.annotation.Sign;
import com.diligrp.cashier.shared.handler.duplication.SpelDuplicationSubmit;
import com.diligrp.cashier.shared.util.JsonUtils;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 扫码下单接口
 * Pos扫支付码后,推送订单信息到商户,商户返回收银台链接
 */
@RestController
@RequestMapping(path = {"/api/rt/mall/scan", "/rt/mall/scan"})
@Validated
public class RtMallOrderPaymentApi {
    @Resource
    private MallBizPaymentService mallBizPaymentService;
    @Resource
    private MallBizOrderService mallBizOrderService;

    /**
     * 扫码下单接口
     * Pos扫支付码后,推送订单信息到商户,商户返回收银台链接
     */
    @PostMapping("/order/v1")
    @ParamLogPrint(outPrint = true)
    @Sign(sign = RtMallSign.class)
    @RepeatSubmit(prefix = "order_payment_sync:", value = "#req['trade_id']", duplicationSubmit = SpelDuplicationSubmit.class)
    public RtMarkMessage<OrderSuccessVO> createOrderPayment(@Valid @RequestBody Object req) {
        OrderCO orderCo = JsonUtils.convertValue(req, OrderCO.class);
        orderCo.setOrderType(OrderType.OFFLINE_SCAN.code);
        RtMallValidateUtils.valid(orderCo);
        return RtMarkMessage.success(mallBizOrderService.createOrder(List.of(orderCo)));
    }

    /**
     * 支付分摊回调接口
     * POS完成支付分摊后,调用此接口通知商户商品信息已就绪
     */
    @PostMapping("/status/callback")
    @ParamLogPrint(outPrint = true)
    @Sign(sign = RtMallSign.class)
    @RepeatSubmit(prefix = "payment_allocate_callback:", value = {
            "#req['trade_list'].![trade_id].![#root + #this]",}, duplicationSubmit = SpelDuplicationSubmit.class)
    public RtMarkMessage<?> handlePaymentAllocate(@Valid @RequestBody Object req) {
        PaymentAllocateCO allocateCO = JsonUtils.convertValue(req, PaymentAllocateCO.class);
        RtMallValidateUtils.valid(allocateCO);
        mallBizPaymentService.handlePaymentAllocate(allocateCO);
        return RtMarkMessage.success();
    }
}