Преглед на файлове

Merge branch 'smb' of http://192.168.0.200:3000/liuj/factoring-trade-backend into smb

wanglang преди 1 месец
родител
ревизия
1f7bd10066

+ 169 - 1
src/main/java/com/sunxung/factoring/job/impl/SmbTaskJob.java

@@ -1,7 +1,28 @@
 package com.sunxung.factoring.job.impl;
 
+import cn.hutool.core.collection.CollectionUtil;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.snb.fsos.bean.LoanApply;
+import com.sunxung.factoring.component.exception.BusinessException;
+import com.sunxung.factoring.component.exception.ValidatorException;
+import com.sunxung.factoring.component.util.CodeUtil;
+import com.sunxung.factoring.entity.entprise.Enterprise;
+import com.sunxung.factoring.entity.financing.apply.CFinancingAccountsReceivableInfo;
+import com.sunxung.factoring.entity.financing.apply.CFinancingApplicantInfo;
+import com.sunxung.factoring.entity.financing.apply.CFinancingBasicInfo;
+import com.sunxung.factoring.entity.smb.FinancingFromInvestors;
+import com.sunxung.factoring.entity.smb.FinancingFromInvestorsHistory;
+import com.sunxung.factoring.entity.smb.FinancingFromInvestorsNotice;
+import com.sunxung.factoring.service.entprise.IEnterpriseService;
+import com.sunxung.factoring.service.financing.apply.ICFinancingAccountsReceivableInfoService;
+import com.sunxung.factoring.service.financing.apply.ICFinancingApplicantInfoService;
+import com.sunxung.factoring.service.financing.apply.ICFinancingBasicInfoService;
+import com.sunxung.factoring.service.financing.review.ReviewQuotaDisburseService;
+import com.sunxung.factoring.service.smb.IFinancingFromInvestorsHistoryService;
 import com.sunxung.factoring.service.smb.IFinancingFromInvestorsService;
 import com.sunxung.factoring.service.smb.IFinancingLoanInfoService;
+import com.sunxung.factoring.service.smbApi.api.SMBApiService;
+import com.sunxung.factoring.service.smbApi.dto.LoanCreditRiskMsgDto;
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -9,9 +30,13 @@ import org.springframework.scheduling.annotation.EnableScheduling;
 import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Component;
 
+import java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.List;
+
 /**
- * @notice 苏商定时任务
  * @author liutao
+ * @notice 苏商定时任务
  * @date 2024-09-14
  */
 @Component
@@ -26,6 +51,21 @@ public class SmbTaskJob {
     @Autowired
     private IFinancingLoanInfoService financingLoanInfoService;
 
+    @Autowired
+    private ReviewQuotaDisburseService reviewQuotaDisburseService;
+    @Autowired
+    private IFinancingFromInvestorsHistoryService financingFromInvestorsHistoryService;
+    @Autowired
+    private ICFinancingBasicInfoService financingBasicInfoService;
+    @Autowired
+    private ICFinancingApplicantInfoService financingApplicantInfoService;
+    @Autowired
+    private ICFinancingAccountsReceivableInfoService financingAccountsReceivableInfoService;
+    @Autowired
+    private IEnterpriseService enterpriseService;
+    @Autowired
+    private SMBApiService smbApiService;
+
     @Scheduled(cron = "0 0/30 * * * ?")
     public void process() {
         log.info("苏商定时任务任务执行开始...");
@@ -42,4 +82,132 @@ public class SmbTaskJob {
         financingLoanInfoService.withdrawStatusQuery();
         log.info("苏商提款状态查询定时任务执行结束...");
     }
+
+    /**
+     * 苏商提款状态查询接口(每小时执行一次)
+     */
+    @Scheduled(cron = "0 0 */1 * * ?")
+    public void withdrawApplyProcess() {
+
+        CFinancingBasicInfo financingBasicInfo = financingBasicInfoService.getById(63L);
+        FinancingFromInvestorsNotice notice = reviewQuotaDisburseService.getFinancingFromInvestorsNotice(financingBasicInfo.getId());
+        FinancingFromInvestorsHistory financingFromInvestorsHistory = financingFromInvestorsHistoryService.getById(notice.getFinancingFromInvestorsHistoryId());
+        FinancingFromInvestors financingFromInvestors = financingFromInvestorsService.getById(financingFromInvestorsHistory.getFinancingFromInvestorsId());
+        if (notice == null) {
+            throw new BusinessException(CodeUtil.FAIL, "获取不到对应的资方融资回调信息");
+        }
+        LoanApply loanApplyReq = new LoanApply();
+        //额度编号
+        loanApplyReq.setProductLimitNo(notice.getLimitNumber());
+        //放款金额
+        loanApplyReq.setBusiAmt("3000.00");
+        //还款方式
+        loanApplyReq.setRepayMethod("2");
+        //期限
+        loanApplyReq.setTerm("12");
+        //期限单位
+        loanApplyReq.setTermUnit("M");
+        //还款账户
+        loanApplyReq.setRepayAcctno(financingFromInvestors.getRepaymentAccount());
+        //还款账户名
+        loanApplyReq.setRepayAcctName(financingFromInvestors.getRepaymentAccountName());
+        //还款账户账号类型-默认为内部户
+        loanApplyReq.setRepayAccType("5");
+        //支付方式
+        loanApplyReq.setPayWay("0");
+        //收款卡标识
+        CFinancingApplicantInfo financingApplicantInfo = financingApplicantInfoService.lambdaQuery()
+                .eq(CFinancingApplicantInfo::getFinancingBasicInfoId, financingBasicInfo.getId()).one();
+        if (financingApplicantInfo == null || financingApplicantInfo.getSmb() == null) {
+            throw new BusinessException(CodeUtil.FAIL, "获取不到对应的融资申请-申请人信息");
+        }
+        if (financingApplicantInfo.getSmb()) {
+            loanApplyReq.setPayeeInnerCardFlag("0");
+        } else {
+            loanApplyReq.setPayeeInnerCardFlag("1");
+        }
+        //收款账户
+        loanApplyReq.setPayeeAcctThNbr(financingApplicantInfo.getApplicantDesignatedAccount());
+        //收款账户名
+        loanApplyReq.setPayeeAcctThName(financingApplicantInfo.getApplicantDesignatedAccountName());
+
+        LoanCreditRiskMsgDto loanCreditRiskMsg = new LoanCreditRiskMsgDto();
+        //精准扶贫类型代码
+        loanCreditRiskMsg.setPovertyAlleviationFlag("Z");
+        //涉农贷款类型代码
+        loanCreditRiskMsg.setAgricultureType("00");
+        //地方政府融资平台标志
+        loanCreditRiskMsg.setGovernmentFlag("0");
+        //贷款发放地区代码
+        String[] strArray = financingFromInvestors.getRegisteredAddress().split(",");
+        if (strArray.length == 3) {
+            loanCreditRiskMsg.setLoanAreaAddress(strArray[2]);
+        }
+        //创业担保贷款
+        loanCreditRiskMsg.setUndertakingGuarantee("00");
+        //普惠型小微企业法人贷款
+        loanCreditRiskMsg.setLoanType("06");
+        //绿色贷款类型
+        loanCreditRiskMsg.setGreenLoanFlag("00");
+        //行业类型代码
+        loanCreditRiskMsg.setIndustryFlag(financingFromInvestors.getIndustryTypeThree());
+        //担保方式
+        loanCreditRiskMsg.setGuaranteeFlag("3");
+        //贷款方式
+        loanCreditRiskMsg.setPurpose("03");
+        //应收账款金额
+        List<CFinancingAccountsReceivableInfo> informationList = financingAccountsReceivableInfoService.list(new QueryWrapper<CFinancingAccountsReceivableInfo>()
+                .eq("c_financing_basic_info_id", financingBasicInfo.getId()));
+        BigDecimal accountsReceivableAmount = BigDecimal.ZERO;
+        if (CollectionUtil.isNotEmpty(informationList)) {
+            accountsReceivableAmount = informationList.stream().filter(accountsReceivable -> accountsReceivable.getAccountsReceivableAmount() != null)
+                    .map(CFinancingAccountsReceivableInfo::getAccountsReceivableAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
+        }
+        loanCreditRiskMsg.setReceivables(accountsReceivableAmount.toString());
+        //应收账款编号
+        loanCreditRiskMsg.setReceivablesNumber(financingBasicInfo.getPurchContractNumber());
+        //核心企业名称
+        Enterprise coreEnterprise = enterpriseService.getById(financingBasicInfo.getCoreEnterpriseId());
+        if (coreEnterprise == null || coreEnterprise.getSocialCreditCode() == null) {
+            throw new ValidatorException(CodeUtil.FAIL, "核心企业或核心企业的统一社会信用代码不存在");
+        }
+        loanCreditRiskMsg.setContractor(coreEnterprise.getCorporateName());
+
+        List<LoanCreditRiskMsgDto.FileInfo> fileList = new ArrayList<>();
+
+        LoanCreditRiskMsgDto.FileInfo fileInfo1 = new LoanCreditRiskMsgDto.FileInfo();
+        fileInfo1.setFileType("811");
+        fileInfo1.setFileSdossId("a272a720e74840048a8775cf40a6ca6f.pdf");
+        fileList.add(fileInfo1);
+
+        LoanCreditRiskMsgDto.FileInfo fileInfo2 = new LoanCreditRiskMsgDto.FileInfo();
+        fileInfo2.setFileType("811");
+        fileInfo2.setFileSdossId("ea91c8c9d16b40a7aa3a4a23cffea127.pdf");
+        fileList.add(fileInfo2);
+
+        LoanCreditRiskMsgDto.FileInfo fileInfo3 = new LoanCreditRiskMsgDto.FileInfo();
+        fileInfo3.setFileType("811");
+        fileInfo3.setFileSdossId("7170a4bf595e49e3aa34555e4f3c0557.pdf");
+        fileList.add(fileInfo3);
+
+        LoanCreditRiskMsgDto.FileInfo fileInfo4 = new LoanCreditRiskMsgDto.FileInfo();
+        fileInfo4.setFileType("812");
+        fileInfo4.setFileSdossId("81a1234b99e14e009ece60bfc2d92b4a.pdf");
+        fileList.add(fileInfo4);
+
+        LoanCreditRiskMsgDto.FileInfo fileInfo5 = new LoanCreditRiskMsgDto.FileInfo();
+        fileInfo5.setFileType("813");
+        fileInfo5.setFileSdossId("622fd4bb33dc472bac8a3f7d88c3922e.docx");
+        fileList.add(fileInfo5);
+
+        LoanCreditRiskMsgDto.FileInfo fileInfo6 = new LoanCreditRiskMsgDto.FileInfo();
+        fileInfo6.setFileType("814");
+        fileInfo6.setFileSdossId("b3b2ed4c245a4608aabd3cc8566fce87.pdf");
+        fileList.add(fileInfo6);
+
+        loanCreditRiskMsg.setFileList(fileList);
+        //获取openId
+        String openId = financingFromInvestors.getOpenId();
+        smbApiService.loanApply(loanApplyReq, loanCreditRiskMsg, openId);
+    }
 }

+ 10 - 0
src/main/java/com/sunxung/factoring/service/financing/payment/IPaymentApplyService.java

@@ -1,6 +1,7 @@
 package com.sunxung.factoring.service.financing.payment;
 
 import com.baomidou.mybatisplus.extension.service.IService;
+import com.sunxung.factoring.entity.financing.apply.CFinancingBasicInfo;
 import com.sunxung.factoring.entity.financing.payment.PaymentApply;
 import com.sunxung.factoring.entity.financing.payment.PaymentApproval;
 import com.sunxung.factoring.entity.financing.payment.PaymentCondition;
@@ -52,4 +53,13 @@ public interface IPaymentApplyService extends IService<PaymentApply> {
      */
     List<PaymentCondition> findConditions(Long applyId);
 
+    /**
+     * 向sop推送融资信息
+     *
+     * @param financingBasicInfo
+     * @param management
+     * @param payoutDate
+     */
+    void financingToSop(CFinancingBasicInfo financingBasicInfo, String management, String payoutDate);
+
 }

+ 2 - 1
src/main/java/com/sunxung/factoring/service/financing/payment/impl/PaymentApplyServiceImpl.java

@@ -851,7 +851,8 @@ public class PaymentApplyServiceImpl extends ServiceImpl<PaymentApplyMapper, Pay
      * @param management         资方名称
      * @param payoutDate         放款日期
      */
-    private void financingToSop(CFinancingBasicInfo financingBasicInfo, String management, String payoutDate) {
+    @Override
+    public void financingToSop(CFinancingBasicInfo financingBasicInfo, String management, String payoutDate) {
         //查询sop对应的业务编号
         String getBusinessNoByTradeUrl = getBusinessNoByTrade + "?businessNumber=" + financingBasicInfo.getBusinessNumber();
         ResponseEntity<String> responseEntity = restTemplate.getForEntity(getBusinessNoByTradeUrl, String.class);

+ 21 - 0
src/main/java/com/sunxung/factoring/service/smb/impl/FinancingLoanInfoServiceImpl.java

@@ -5,12 +5,16 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.github.pagehelper.Page;
 import com.github.pagehelper.PageHelper;
+import com.sunxung.factoring.component.util.ConstantUtil;
 import com.sunxung.factoring.entity.GridPage;
 import com.sunxung.factoring.entity.entprise.Enterprise;
+import com.sunxung.factoring.entity.financing.apply.CFinancingBasicInfo;
 import com.sunxung.factoring.entity.smb.FinancingLoanInfo;
 import com.sunxung.factoring.entity.smb.vo.FinancingLoanInfoSearch;
 import com.sunxung.factoring.mapper.smb.FinancingLoanInfoMapper;
 import com.sunxung.factoring.service.entprise.IEnterpriseService;
+import com.sunxung.factoring.service.financing.apply.ICFinancingBasicInfoService;
+import com.sunxung.factoring.service.financing.payment.IPaymentApplyService;
 import com.sunxung.factoring.service.smb.IFinancingLoanInfoService;
 import com.sunxung.factoring.service.smbApi.api.SMBApiService;
 import com.sunxung.factoring.service.smbApi.resp.LoanApplyStatusResp;
@@ -35,6 +39,10 @@ public class FinancingLoanInfoServiceImpl extends ServiceImpl<FinancingLoanInfoM
     private IEnterpriseService enterpriseService;
     @Autowired
     private SMBApiService smbApiService;
+    @Autowired
+    private ICFinancingBasicInfoService financingBasicInfoService;
+    @Autowired
+    private IPaymentApplyService paymentApplyService;
 
     @Override
     public GridPage<FinancingLoanInfo> findBySearch(FinancingLoanInfoSearch search) {
@@ -78,7 +86,20 @@ public class FinancingLoanInfoServiceImpl extends ServiceImpl<FinancingLoanInfoM
                     loanInfo.setPayoutStatus(loanApplyStatusResp.getStatus());
                     //放款金额
                     loanInfo.setLoanAmount(loanApplyStatusResp.getBusiAmt());
+                    if ("03".equals(loanApplyStatusResp.getStatus())) {
+                        //如果提款失败,添加失败原因
+                        loanInfo.setFailMsg(loanApplyStatusResp.getRemark());
+                    }
                     updateById(loanInfo);
+                    if ("02".equals(loanApplyStatusResp.getStatus())) {
+                        //如果提款成功后、需要向sop推送融资信息
+                        if (loanInfo.getcFinancingBasicInfoId() != null) {
+                            CFinancingBasicInfo financingBasicInfo = financingBasicInfoService.getById(loanInfo.getcFinancingBasicInfoId());
+                            if (financingBasicInfo != null) {
+                                paymentApplyService.financingToSop(financingBasicInfo, ConstantUtil.JIANGSU_SUSHANG_BANK, loanInfo.getPayoutDate());
+                            }
+                        }
+                    }
                 }
             }
         }

+ 96 - 0
src/main/java/com/sunxung/factoring/start/impl/SMBNoticeInit.java

@@ -0,0 +1,96 @@
+package com.sunxung.factoring.start.impl;
+
+import com.sunxung.factoring.component.util.ConstantUtil;
+import com.sunxung.factoring.component.util.SpringUtil;
+import com.sunxung.factoring.entity.financing.apply.CFinancingBasicInfo;
+import com.sunxung.factoring.entity.smb.FinancingLoanInfo;
+import com.sunxung.factoring.service.financing.apply.ICFinancingBasicInfoService;
+import com.sunxung.factoring.service.financing.payment.IPaymentApplyService;
+import com.sunxung.factoring.service.smb.IFinancingLoanInfoService;
+import com.sunxung.factoring.service.smbApi.dto.SMBNotifyRespDto;
+import com.sunxung.factoring.service.smbApi.dto.WithdrawNotifyPayloadDto;
+import com.sunxung.factoring.service.smbApi.spi.SMBSpiRegister;
+
+import java.util.function.Function;
+
+/**
+ * 苏商注册提款结果通知回调函数初始化
+ */
+public class SMBNoticeInit {
+
+    public void run() {
+        Function<WithdrawNotifyPayloadDto, SMBNotifyRespDto> withdrawNotifyHandler = withdrawNotifyPayloadDto -> {
+            if (withdrawNotifyPayloadDto.getPayoutNo() != null) {
+                FinancingLoanInfo loanInfo = getFinancingLoanInfoService().lambdaQuery().eq(FinancingLoanInfo::getPayoutNo, withdrawNotifyPayloadDto.getPayoutNo()).one();
+                if (loanInfo != null) {
+                    //借据编号
+                    loanInfo.setDueBillNo(withdrawNotifyPayloadDto.getDuebillNo());
+                    //到期日期
+                    loanInfo.setMaturityDate(withdrawNotifyPayloadDto.getMaturity());
+                    //提款申请日期
+                    loanInfo.setLoanApplyDate(withdrawNotifyPayloadDto.getLoanApplyTime());
+                    //放款日期
+                    loanInfo.setPayoutDate(withdrawNotifyPayloadDto.getPayoutDate());
+                    //放款状态
+                    loanInfo.setPayoutStatus(withdrawNotifyPayloadDto.getStatus());
+                    //放款金额
+                    loanInfo.setLoanAmount(withdrawNotifyPayloadDto.getBusiAmt());
+                    if ("03".equals(withdrawNotifyPayloadDto.getStatus())) {
+                        //如果提款失败,添加失败原因
+                        loanInfo.setFailMsg(withdrawNotifyPayloadDto.getRemark());
+                    }
+                    getFinancingLoanInfoService().updateById(loanInfo);
+                    if ("02".equals(withdrawNotifyPayloadDto.getStatus())) {
+                        //如果提款成功后、需要向sop推送融资信息
+                        if (loanInfo.getcFinancingBasicInfoId() != null) {
+                            CFinancingBasicInfo financingBasicInfo = getFinancingBasicInfoService().getById(loanInfo.getcFinancingBasicInfoId());
+                            if (financingBasicInfo != null) {
+                                getPaymentApplyService().financingToSop(financingBasicInfo, ConstantUtil.JIANGSU_SUSHANG_BANK, loanInfo.getPayoutDate());
+                            }
+                        }
+                    }
+                }
+            }
+            SMBNotifyRespDto respDto = new SMBNotifyRespDto();
+            respDto.setRespResult(true);
+            return respDto;
+        };
+        getSMBSpiRegister().registerWithdrawNotifyHandler(withdrawNotifyHandler);
+    }
+
+    private static SMBSpiRegister smbSpiRegister;
+
+    private static SMBSpiRegister getSMBSpiRegister() {
+        if (smbSpiRegister == null) {
+            smbSpiRegister = SpringUtil.getBeanByType(SMBSpiRegister.class);
+        }
+        return smbSpiRegister;
+    }
+
+    private static IFinancingLoanInfoService financingLoanInfoService;
+
+    private static IFinancingLoanInfoService getFinancingLoanInfoService() {
+        if (financingLoanInfoService == null) {
+            financingLoanInfoService = SpringUtil.getBeanByType(IFinancingLoanInfoService.class);
+        }
+        return financingLoanInfoService;
+    }
+
+    private static ICFinancingBasicInfoService financingBasicInfoService;
+
+    private static ICFinancingBasicInfoService getFinancingBasicInfoService() {
+        if (financingBasicInfoService == null) {
+            financingBasicInfoService = SpringUtil.getBeanByType(ICFinancingBasicInfoService.class);
+        }
+        return financingBasicInfoService;
+    }
+
+    private static IPaymentApplyService paymentApplyService;
+
+    private static IPaymentApplyService getPaymentApplyService() {
+        if (paymentApplyService == null) {
+            paymentApplyService = SpringUtil.getBeanByType(IPaymentApplyService.class);
+        }
+        return paymentApplyService;
+    }
+}

+ 24 - 22
src/main/java/com/sunxung/factoring/start/impl/StartLoadImpl.java

@@ -1,6 +1,5 @@
 package com.sunxung.factoring.start.impl;
 
-import com.sunxung.factoring.component.util.MockAdminThreadLocalUtil;
 import com.sunxung.factoring.entity.sys.SqlVersion;
 import com.sunxung.factoring.start.StartLoad;
 import org.apache.logging.log4j.LogManager;
@@ -15,6 +14,7 @@ import org.springframework.stereotype.Component;
 public class StartLoadImpl implements StartLoad {
 
     private static Logger log = LogManager.getLogger(StartLoadImpl.class);
+
     /**
      * 是否初始化
      */
@@ -39,27 +39,29 @@ public class StartLoadImpl implements StartLoad {
      * @throws Exception
      */
     private void init() throws Exception {
-        long startTime = System.currentTimeMillis();
-        log.error("开始初始化");
-        log.error("开始初始化数据库");
-        MockAdminThreadLocalUtil.mock();
-        log.error("开始初始化字典项");
-        new DictionaryInit().run();
-        log.error("开始初始化权限");
-        new PermissionInit().run();
-        log.error("开始初始化组织机构");
-        new OrgInit().run();
-        log.error("开始初始化行政区划");
-        log.error("开始初始化角色");
-        new RoleInit().run();
-        log.error("开始初始化用户");
-        new UserInit().run();
-        log.error("开始初始化工作日");
-        new WorkingDayInit().run();
-        log.error("开始初始化脚本升级最大版本号");
-        addSqlVersion();
-        log.error("成功初始化,耗时:" + (System.currentTimeMillis() - startTime) / 1000.0 + "秒");
-        MockAdminThreadLocalUtil.destroy();
+//        long startTime = System.currentTimeMillis();
+//        log.error("开始初始化");
+//        log.error("开始初始化数据库");
+//        MockAdminThreadLocalUtil.mock();
+//        log.error("开始初始化字典项");
+//        new DictionaryInit().run();
+//        log.error("开始初始化权限");
+//        new PermissionInit().run();
+//        log.error("开始初始化组织机构");
+//        new OrgInit().run();
+//        log.error("开始初始化行政区划");
+//        log.error("开始初始化角色");
+//        new RoleInit().run();
+//        log.error("开始初始化用户");
+//        new UserInit().run();
+//        log.error("开始初始化工作日");
+//        new WorkingDayInit().run();
+//        log.error("开始初始化脚本升级最大版本号");
+//        addSqlVersion();
+//        log.error("成功初始化,耗时:" + (System.currentTimeMillis() - startTime) / 1000.0 + "秒");
+//        MockAdminThreadLocalUtil.destroy();
+        log.error("开始初始化苏商注册提款结果通知回调函数");
+        new SMBNoticeInit().run();
     }
 
     /**

+ 1 - 1
src/main/resources/application-dev.yml

@@ -1,7 +1,7 @@
 #数据库启动方式
 data:
   #是否初始化
-  init: false
+  init: true
   #脚本升级版本号
   upgradeVersion: 1