liujie
2025-11-25 b502ac4e96aca2ab29caa77187ab7673a853a797
ManagementJYXTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/huifu/controller/DouGongNotifyController.java
@@ -5,11 +5,19 @@
import com.huifu.bspay.sdk.opps.core.utils.RsaUtils;
import com.stylefeng.guns.modular.huifu.properties.HuiFuProperties;
import com.stylefeng.guns.modular.system.model.TCompanyWithdraw;
import com.stylefeng.guns.modular.system.model.TDriver;
import com.stylefeng.guns.modular.system.model.TEnterpriseWithdrawal;
import com.stylefeng.guns.modular.system.model.TOrderCrossCity;
import com.stylefeng.guns.modular.system.model.TOrderLogistics;
import com.stylefeng.guns.modular.system.model.TPubWithdrawal;
import com.stylefeng.guns.modular.system.model.TUser;
import com.stylefeng.guns.modular.system.service.ITCompanyWithdrawService;
import com.stylefeng.guns.modular.system.service.ITDriverService;
import com.stylefeng.guns.modular.system.service.ITEnterpriseWithdrawalService;
import com.stylefeng.guns.modular.system.service.ITOrderCrossCityService;
import com.stylefeng.guns.modular.system.service.ITOrderLogisticsService;
import com.stylefeng.guns.modular.system.service.ITPubWithdrawalService;
import com.stylefeng.guns.modular.system.service.ITUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
@@ -18,8 +26,12 @@
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.math.BigDecimal;
import java.util.Objects;
/**
@@ -32,10 +44,24 @@
public class DouGongNotifyController {
    @Autowired
    private HuiFuProperties huiFuProperties;
    @Autowired
    private ITCompanyWithdrawService companyWithdrawService;
    @Autowired
    private ITPubWithdrawalService pubWithdrawalService;
    @Autowired
    private ITOrderCrossCityService orderCrossCityService;
    @Autowired
    private ITOrderLogisticsService orderLogisticsService;
    @Autowired
    private ITUserService userService;
    @Autowired
    private ITDriverService driverService;
    /**
     * 斗拱主动取现接口企业回调
@@ -43,10 +69,10 @@
     * @param response
     */
    @PostMapping("/ent/encashment")
    public ResponseEntity<String> entEncashment(HttpServletRequest request, HttpServletResponse response) {
    public void entEncashment(HttpServletRequest request, HttpServletResponse response) {
        String sign =request.getParameter("sign");
        String resp_data = request.getParameter("resp_data");
        log.info("斗拱企业提现响应内容:{}", resp_data);
        log.info("斗拱企业提现回调响应内容:{}", resp_data);
        // 使用汇付公钥验签
        resp_data =  resp_data.replaceAll("& #40;", "(").replaceAll("& #41;",")");
        boolean verify = RsaUtils.verify(resp_data, huiFuProperties.getRsaPublicKey(), sign);
@@ -57,7 +83,7 @@
            String transStat = respDataJson.getString("trans_stat");//S:成功 F:失败 P:处理中;示例值:S
            TCompanyWithdraw companyWithdraw = companyWithdrawService.selectOne(new EntityWrapper<TCompanyWithdraw>().eq("reqSeqId", reqSeqId).or().eq("hfSeqId", hfSeqId).last("limit 1"));
            if (Objects.isNull(companyWithdraw)) {
                return ResponseEntity.ok("");
                return;
            }
            if ("S".equalsIgnoreCase(transStat)) {
                companyWithdraw.setStatus(1);
@@ -66,9 +92,15 @@
            }
            companyWithdrawService.updateById(companyWithdraw);
            log.info("更新企业提现记录成功,更新内容“{}", JSONObject.toJSON(companyWithdraw));
            return ResponseEntity.ok("RECV_ORD_ID_" + reqSeqId);
            PrintWriter writer = null;
            try {
                writer = response.getWriter();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
            writer.print("200");
            writer.close();
        }
        return null;
    }
    /**
     * 斗拱主动取现接口回调
@@ -76,10 +108,10 @@
     * @param response
     */
    @PostMapping("/user/encashment")
    public ResponseEntity<String> userEncashment(HttpServletRequest request, HttpServletResponse response) {
    public void userEncashment(HttpServletRequest request, HttpServletResponse response) {
        String sign =request.getParameter("sign");
        String resp_data = request.getParameter("resp_data");
        log.info("斗拱企业提现响应内容:{}", resp_data);
        log.info("斗拱用户提现回调响应内容:{}", resp_data);
        // 使用汇付公钥验签
        resp_data =  resp_data.replaceAll("& #40;", "(").replaceAll("& #41;",")");
        boolean verify = RsaUtils.verify(resp_data, huiFuProperties.getRsaPublicKey(), sign);
@@ -90,17 +122,109 @@
            String transStat = respDataJson.getString("trans_stat");//S:成功 F:失败 P:处理中;示例值:S
            TPubWithdrawal pubWithdrawal = pubWithdrawalService.selectOne(new EntityWrapper<TPubWithdrawal>().eq("reqSeqId", reqSeqId).or().eq("hfSeqId", hfSeqId).last("limit 1"));
            if (Objects.isNull(pubWithdrawal)) {
                return ResponseEntity.ok("");
                return;
            }
            if ("S".equalsIgnoreCase(transStat)) {
                pubWithdrawal.setState(2);
            } else if ("F".equalsIgnoreCase(transStat)) {
                pubWithdrawal.setState(3);
                if (pubWithdrawal.getUserType() == 1) {
                    TUser tUser = userService.selectById(pubWithdrawal.getUserId());
                    tUser.setBalance(tUser.getBalance().add(pubWithdrawal.getMoney()));
                    userService.updateById(tUser);
                } else {
                    TDriver driver = driverService.selectById(pubWithdrawal.getUserId());
                    driver.setLaveBusinessMoney(new BigDecimal(driver.getLaveBusinessMoney()).add(pubWithdrawal.getMoney()).doubleValue());
                    driverService.updateById(driver);
                }
            }
            pubWithdrawalService.updateById(pubWithdrawal);
            log.info("更新用户/司机提现记录成功,更新内容“{}", JSONObject.toJSON(pubWithdrawal));
            return ResponseEntity.ok("RECV_ORD_ID_" + reqSeqId);
            PrintWriter writer = null;
            try {
                writer = response.getWriter();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
            writer.print("200");
            writer.close();
        }
        return null;
    }
    /**
     * 斗拱主动取现接口回调
     * @param request
     * @param response
     */
    @PostMapping("/refund-logistics")
    public void refundLogistics(HttpServletRequest request, HttpServletResponse response) {
        String sign =request.getParameter("sign");
        String resp_data = request.getParameter("resp_data");
        log.info("斗拱用户提现回调响应内容:{}", resp_data);
        // 使用汇付公钥验签
        resp_data =  resp_data.replaceAll("& #40;", "(").replaceAll("& #41;",")");
        boolean verify = RsaUtils.verify(resp_data, huiFuProperties.getRsaPublicKey(), sign);
        if(verify){
            JSONObject respDataJson = JSONObject.parseObject(resp_data);
            String reqSeqId = respDataJson.getString("req_seq_id");
            String orgReqSeqId = respDataJson.getString("org_req_seq_id");
            String transStat = respDataJson.getString("trans_stat");//S:成功 F:失败 P:处理中;示例值:S
            TOrderLogistics orderLogistics = orderLogisticsService.selectOne(new EntityWrapper<TOrderLogistics>()
                    .eq("refundReqSeqId", reqSeqId).or().eq("outTradeNo", orgReqSeqId).last("limit 1"));
            if (Objects.isNull(orderLogistics)) {
                return;
            }
            if ("S".equalsIgnoreCase(transStat)) {
                orderLogistics.setState(10);
            }
            orderLogisticsService.updateById(orderLogistics);
            log.info("更新小件物流取消订单状态成功,更新内容“{}", JSONObject.toJSON(orderLogistics));
            PrintWriter writer = null;
            try {
                writer = response.getWriter();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
            writer.print("200");
            writer.close();
        }
    }
    /**
     * 斗拱主动取现接口回调
     * @param request
     * @param response
     */
    @PostMapping("/refund-crosscity")
    public void refundCrossCity(HttpServletRequest request, HttpServletResponse response) {
        String sign =request.getParameter("sign");
        String resp_data = request.getParameter("resp_data");
        log.info("斗拱用户提现回调响应内容:{}", resp_data);
        // 使用汇付公钥验签
        resp_data =  resp_data.replaceAll("& #40;", "(").replaceAll("& #41;",")");
        boolean verify = RsaUtils.verify(resp_data, huiFuProperties.getRsaPublicKey(), sign);
        if(verify){
            JSONObject respDataJson = JSONObject.parseObject(resp_data);
            String reqSeqId = respDataJson.getString("req_seq_id");
            String orgReqSeqId = respDataJson.getString("org_req_seq_id");
            String transStat = respDataJson.getString("trans_stat");//S:成功 F:失败 P:处理中;示例值:S
            TOrderCrossCity orderCrossCity = orderCrossCityService.selectOne(new EntityWrapper<TOrderCrossCity>()
                    .eq("refundReqSeqId", reqSeqId).or().eq("outTradeNo", orgReqSeqId).last("limit 1"));
            if (Objects.isNull(orderCrossCity)) {
                return;
            }
            if ("S".equalsIgnoreCase(transStat)) {
                orderCrossCity.setState(10);
            }
            orderCrossCityService.updateById(orderCrossCity);
            log.info("更新跨城订单取消订单状态成功,更新内容“{}", JSONObject.toJSON(orderCrossCity));
            PrintWriter writer = null;
            try {
                writer = response.getWriter();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
            writer.print("200");
            writer.close();
        }
    }
}