Kaynağa Gözat

定时任务处理

郎学彬 3 yıl önce
ebeveyn
işleme
f9f1955a4f

+ 26 - 2
taskMan/src/main/java/com/huyi/task/base/entity/PayAccDetail.java

@@ -14,8 +14,8 @@ import lombok.experimental.Accessors;
  * 账户历史信息表
  * </p>
  *
- * @author xuefy
- * @since 2021-08-16
+ * @author pxh
+ * @since 2021-10-15
  */
 @Data
 @EqualsAndHashCode(callSuper = false)
@@ -127,5 +127,29 @@ public class PayAccDetail implements Serializable {
     @TableField("update_time")
     private Date updateTime;
 
+    /**
+     * 状态(00:交易中 01:成功 02:失败)
+     */
+    @TableField("PAD_STATE")
+    private String padState;
+
+    /**
+     * 业务表主键
+     */
+    @TableField("pad_business_id")
+    private String padBusinessId;
+
+    /**
+     * 交易查询次数
+     */
+    @TableField("pad_tar_count")
+    private String padTarCount;
+
+    /**
+     * 转账查询次数
+     */
+    @TableField("pad_pay_count")
+    private String padPayCount;
+
 
 }

+ 27 - 8
taskMan/src/main/java/com/huyi/task/base/entity/PayAccInf.java

@@ -1,21 +1,22 @@
 package com.huyi.task.base.entity;
 
-import com.baomidou.mybatisplus.annotation.TableName;
-import java.util.Date;
-import com.baomidou.mybatisplus.annotation.TableId;
 import com.baomidou.mybatisplus.annotation.TableField;
-import java.io.Serializable;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
 import lombok.Data;
 import lombok.EqualsAndHashCode;
 import lombok.experimental.Accessors;
 
+import java.io.Serializable;
+import java.util.Date;
+
 /**
  * <p>
  * 账户信息表
  * </p>
  *
- * @author xuefy
- * @since 2021-08-16
+ * @author pxh
+ * @since 2021-10-13
  */
 @Data
 @EqualsAndHashCode(callSuper = false)
@@ -28,7 +29,7 @@ public class PayAccInf implements Serializable {
     /**
      * 企业ID(sys_company.scy_id)
      */
-    @TableId("PAI_CSTNO")
+    @TableField("PAI_CSTNO")
     private String paiCstno;
 
     /**
@@ -62,7 +63,7 @@ public class PayAccInf implements Serializable {
     private String paiAvabalance;
 
     /**
-     * 账户类型(00基本账户01贷款账户02信用账户03手续费账户04待结算账户05提现账户06邢台银行虚拟账户)
+     * 账户类型(00基本账户01一般账户02信用账户03手续费账户04待结算账户05提现账户06虚拟账户07:公共计息账户08:资金初始化账户09:公共调账账户)
      */
     @TableField("PAI_ACCTYPE")
     private String paiAcctype;
@@ -109,5 +110,23 @@ public class PayAccInf implements Serializable {
     @TableField("update_time")
     private Date updateTime;
 
+    /**
+     * 账户名称
+     */
+    @TableField("pai_accno_name")
+    private String paiAccnoName;
+
+    /**
+     * 银行名称
+     */
+    @TableField("pai_bank_name")
+    private String paiBankName;
+
+    /**
+     * 主键
+     */
+    @TableId("pai_id")
+    private String paiId;
+
 
 }

+ 2 - 2
taskMan/src/main/java/com/huyi/task/base/mapper/PayAccDetailMapper.java

@@ -8,8 +8,8 @@ import com.huyi.task.base.entity.PayAccDetail;
  * 账户历史信息表 Mapper 接口
  * </p>
  *
- * @author xuefy
- * @since 2021-08-16
+ * @author pxh
+ * @since 2021-10-15
  */
 public interface PayAccDetailMapper extends BaseMapper<PayAccDetail> {
 

+ 2 - 2
taskMan/src/main/java/com/huyi/task/base/mapper/PayAccInfMapper.java

@@ -8,8 +8,8 @@ import com.huyi.task.base.entity.PayAccInf;
  * 账户信息表 Mapper 接口
  * </p>
  *
- * @author xuefy
- * @since 2021-08-16
+ * @author pxh
+ * @since 2021-10-13
  */
 public interface PayAccInfMapper extends BaseMapper<PayAccInf> {
 

+ 2 - 2
taskMan/src/main/java/com/huyi/task/base/service/IPayAccDetailService.java

@@ -13,8 +13,8 @@ import java.util.List;
  * Description: PayAccDetailService接口 <br>
  * Company: keao
  *
- * @author xuefy
- * @version v1.0.0    2021-08-16  xuefy    由Generator自动创建
+ * @author pxh
+ * @version v1.0.0    2021-10-15  pxh    由Generator自动创建
  */
 public interface IPayAccDetailService extends IService<PayAccDetail> {
     /**

+ 2 - 2
taskMan/src/main/java/com/huyi/task/base/service/IPayAccInfService.java

@@ -13,8 +13,8 @@ import java.util.List;
  * Description: PayAccInfService接口 <br>
  * Company: keao
  *
- * @author xuefy
- * @version v1.0.0    2021-08-16  xuefy    由Generator自动创建
+ * @author pxh
+ * @version v1.0.0    2021-10-13  pxh    由Generator自动创建
  */
 public interface IPayAccInfService extends IService<PayAccInf> {
     /**

+ 2 - 2
taskMan/src/main/java/com/huyi/task/base/service/impl/PayAccDetailServiceImpl.java

@@ -20,8 +20,8 @@ import java.util.List;
  * Description: IPayAccDetailService实现 <br>
  * Company: keao
  *
- * @author xuefy
- * @version v1.0.0    2021-08-16  xuefy    由Generator自动创建
+ * @author pxh
+ * @version v1.0.0    2021-10-15  pxh    由Generator自动创建
  */
 @Service
 @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)

+ 2 - 2
taskMan/src/main/java/com/huyi/task/base/service/impl/PayAccInfServiceImpl.java

@@ -20,8 +20,8 @@ import java.util.List;
  * Description: IPayAccInfService实现 <br>
  * Company: keao
  *
- * @author xuefy
- * @version v1.0.0    2021-08-16  xuefy    由Generator自动创建
+ * @author pxh
+ * @version v1.0.0    2021-10-13  pxh    由Generator自动创建
  */
 @Service
 @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)

+ 17 - 0
taskMan/src/main/java/com/huyi/task/taskMan/mapper/BankTaskMapper.java

@@ -0,0 +1,17 @@
+package com.huyi.task.taskMan.mapper;
+
+import java.util.List;
+import java.util.Map;
+
+
+public interface BankTaskMapper
+{
+
+    /**
+     * 查询到期的授信
+     * @param map
+     * @return
+     */
+    public List<Map> selectTranList(Map map);
+
+}

+ 231 - 0
taskMan/src/main/java/com/huyi/task/taskMan/schedule/BankTask.java

@@ -0,0 +1,231 @@
+package com.huyi.task.taskMan.schedule;
+
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.huyi.task.base.entity.PayAccDetail;
+import com.huyi.task.base.entity.SysCompany;
+import com.huyi.task.base.entity.SysUserCompanyRel;
+import com.huyi.task.base.entity.ZcChargeInf;
+import com.huyi.task.base.service.IPayAccDetailService;
+import com.huyi.task.base.service.ISysCompanyService;
+import com.huyi.task.base.service.ISysUserCompanyRelService;
+import com.huyi.task.base.service.IZcChargeInfService;
+import com.huyi.task.taskMan.service.BankTaskService;
+import com.tianhu.common.core.domain.R;
+import com.tianhu.common.core.utils.AmtUtil;
+import com.tianhu.common.core.utils.CommonUtil;
+import com.tianhu.system.api.RemoteSystemService;
+import com.tianhu.system.api.RemoteZxBankService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.scheduling.annotation.EnableScheduling;
+import org.springframework.scheduling.annotation.Scheduled;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+@Configuration      //1.主要用于标记配置类,兼备Component的效果。
+@EnableScheduling   // 2.开启定时任务
+public class BankTask {
+    private static final Logger log = LoggerFactory.getLogger(BankTask.class);
+
+    @Autowired
+    private RemoteZxBankService remoteZxBankService;
+    @Autowired
+    private IPayAccDetailService iPayAccDetailService;
+    @Autowired
+    private IZcChargeInfService iZcChargeInfService;
+    @Autowired
+    private RemoteSystemService remoteSystemService;
+    @Autowired
+    private ISysUserCompanyRelService iSysUserCompanyRelService;
+    @Autowired
+    private BankTaskService bankTaskService;
+    @Autowired
+    private ISysCompanyService iSysCompanyService;
+    /**
+     * 交易中的流水查证
+     */
+    //每30分钟
+    @Scheduled(cron = "0 */30 * * * ?")
+    //每天凌晨一点
+//    @Scheduled(cron = "0 0 1 * * ?")
+    private void changeCreditStates() throws Exception{
+        //查询交易明细表
+        LambdaQueryWrapper<PayAccDetail> queryWrapper = new LambdaQueryWrapper<>();
+        queryWrapper.eq(PayAccDetail::getPadState,"00");
+        List<PayAccDetail> detailList = iPayAccDetailService.list(queryWrapper);
+
+        for(PayAccDetail detail : detailList){
+            //查询费用列表交易中的数据
+            LambdaQueryWrapper<ZcChargeInf> wrapper = new LambdaQueryWrapper<>();
+            wrapper.in(ZcChargeInf::getZciStatus,"01","04");
+            wrapper.eq(ZcChargeInf::getZciId,detail.getPadBusinessId());
+            List<ZcChargeInf> zcChargeInfList =iZcChargeInfService.list(wrapper);
+            //查询次数
+            String count = detail.getPadTarCount();
+            if (CommonUtil.isNotEmpty(count)) {
+                count = AmtUtil.add(count, "1", 0);
+            } else {
+                count = AmtUtil.add("0", "1", 0);
+            }
+            //若次数大于三次 则不再查询
+            if (CommonUtil.compare(count, "3") != 1) {
+                //根据交易状态查询接口处理费用列表接口。
+                R payStatus = remoteZxBankService.stateQuery(detail.getPadPayflowno());
+                System.out.println("交易查询接口========》"+payStatus.getData());
+                Map map = (Map) payStatus.getData();
+                PayAccDetail payAccDetail = new PayAccDetail();
+                payAccDetail.setPadNo(detail.getPadNo());
+
+                //有无费用列表数据
+                if(zcChargeInfList.size()>0) {
+                    ZcChargeInf zcChargeInf = zcChargeInfList.get(0);
+                    //费用列表状态  (00:待缴费;01:缴费中;02:已缴费;03:已退款 04:退款中05:缴费失败 06 退款失败)
+                    String status = zcChargeInf.getZciStatus();
+                    ZcChargeInf inf = new ZcChargeInf();
+                    inf.setZciId(zcChargeInf.getZciId());
+                    //根据查询结果处理
+                    if (map.containsKey("status")) {
+                        //stt 状态 0:未知 1成功 2 失败
+                        String stt = map.get("status").toString();
+                        if ("1".equals(stt)) {
+                            payAccDetail.setPadState("01");
+                            if ("01".equals(status)) {
+                                inf.setZciStatus("02");
+                            } else {
+                                inf.setZciStatus("03");
+                            }
+                        } else if ("0".equals(stt)) {
+                            payAccDetail.setPadState("00");
+                        } else {
+                            payAccDetail.setPadState("02");
+                            if ("01".equals(status)) {
+                                inf.setZciStatus("05");
+                            } else {
+                                inf.setZciStatus("06");
+                            }
+                        }
+                    }
+                    iZcChargeInfService.updateZcChargeInf(inf);
+                    //无费用列表时,只更改流水状态
+                }else{
+                    if (map.containsKey("status")) {
+                        //stt 状态 0:未知 1成功 2 失败
+                        String stt = map.get("status").toString();
+                        if ("1".equals(stt)) {
+                            payAccDetail.setPadState("01");
+                        } else if ("0".equals(stt)) {
+                            payAccDetail.setPadState("00");
+                        } else {
+                            payAccDetail.setPadState("02");
+                        }
+                    }
+                }
+                payAccDetail.setPadTarCount(count);
+                iPayAccDetailService.updatePayAccDetail(payAccDetail);
+                //若达到三次则生成待办
+                if ("3".equals(count)) {
+                    LambdaQueryWrapper<SysUserCompanyRel> userLambdaQueryWrapper = new LambdaQueryWrapper<>();
+                    userLambdaQueryWrapper.eq(SysUserCompanyRel::getSucrCompanyId, "000000");
+                    List<SysUserCompanyRel> userCompany = iSysUserCompanyRelService.list(userLambdaQueryWrapper);
+                    String userList = "";
+                    for (SysUserCompanyRel rel : userCompany) {
+                        userList = userList + rel.getSucrUserId() + ",";
+                    }
+                    SysCompany company = iSysCompanyService.getById(detail.getPadCstno());
+                    String title = "【交易失败】"+company.getScyName()+"向中信银行交易请求连续失败,请及时线下核实处理";
+                    remoteSystemService.sendNotice("000000", "", title, "00", null, "10", "0", userList, null, "00", null);
+                }
+            }
+        }
+    }
+
+    /**
+     * 转账 调账跑批
+     * @throws Exception
+     */
+    //每30分钟
+    @Scheduled(cron = "0 */2 * * * ?")
+    //每天凌晨一点
+//    @Scheduled(cron = "0 0 1 * * ?")
+    private void transferAmtHandle() throws Exception{
+        Map map = new HashMap();
+        //查询 退款 及平台调账  失败的数据进行再次转账
+        List<Map> tranList = bankTaskService.selectTranList(map);
+        for(Map detail : tranList){
+            //业务表id
+            String businessId = detail.get("businessId").toString();
+            //查询费用列表交易中的数据
+            LambdaQueryWrapper<ZcChargeInf> wrapper = new LambdaQueryWrapper<>();
+            wrapper.eq(ZcChargeInf::getZciId,businessId);
+            List<ZcChargeInf> zcChargeInfList =iZcChargeInfService.list(wrapper);
+            if(zcChargeInfList.size()>0){
+                ZcChargeInf inf = zcChargeInfList.get(0);
+                //备注
+                String remrk = detail.get("remrk").toString();
+                //付款账户
+                String accNo = detail.get("accNo").toString();
+                //交易金额
+                String tranAmt = detail.get("trxamout").toString();
+                //企业id
+                String companyId = detail.get("companyId").toString();
+                //类型 30 退款 94:平台调账
+                String type = detail.get("tranType").toString();
+                if(CommonUtil.isNotEmpty(remrk)){
+                    String[] remrks = remrk.split(",");
+                    String[] recvAccNo = remrks[1].split(":");
+                    String[] recvAccNm = remrks[2].split(":");
+                    R mess = remoteZxBankService.transfer(accNo,recvAccNo[1],recvAccNm[1],tranAmt,businessId,companyId,type);
+                    System.out.println("交易查询接口========》"+mess.getData());
+                    //数据信息
+                    Map maps = (Map) mess.getData();
+                    //状态是否存在
+                    if(maps.containsKey("status")){
+                        //状态 0 交易中 1 成功 2  失败
+                        String status = maps.get("status").toString();
+                        //退款
+                        String title = "";
+                        if ("30".equals(type)){
+                            //退款时,只要不成功就给待办
+                            if("0".equals(status)){
+                                inf.setZciStatus("04");
+                                title = "【转账受阻】中信银行业务流水号:" + maps.get("flow") + "转账受阻,请及时线下核实处理;";
+                            }else if("1".equals(status)){
+                                inf.setZciStatus("03");
+                            }else {
+                                inf.setZciStatus("06");
+                                title = "【转账受阻】中信银行业务流水号:" + maps.get("flow") + "转账受阻,请及时线下核实处理;";
+
+                            }
+                            iZcChargeInfService.updateZcChargeInf(inf);
+                            //平台调账时,只要不成功就给待办处理
+                        }else{
+                            if(!"1".equals(status)){
+                                title = "【转账受阻】中信银行业务流水号:" + maps.get("flow") + "转账受阻,请及时线下核实处理;";
+                            }
+                        }
+                        //若标题不为空,则进行添加待办
+                        if(CommonUtil.isNotEmpty(title)){
+                            LambdaQueryWrapper<SysUserCompanyRel> userLambdaQueryWrapper = new LambdaQueryWrapper<>();
+                            userLambdaQueryWrapper.eq(SysUserCompanyRel::getSucrCompanyId, "000000");
+                            List<SysUserCompanyRel> userCompany = iSysUserCompanyRelService.list(userLambdaQueryWrapper);
+                            String userList = "";
+                            for (SysUserCompanyRel rel : userCompany) {
+                                userList = userList + rel.getSucrUserId() + ",";
+                            }
+                            remoteSystemService.sendNotice("000000", "", title, "00", null, "10", "0", userList, null, "00", null);
+                        }
+
+                    }
+                }
+            }
+        }
+    }
+
+
+
+}
+

+ 20 - 0
taskMan/src/main/java/com/huyi/task/taskMan/service/BankTaskService.java

@@ -0,0 +1,20 @@
+package com.huyi.task.taskMan.service;
+
+
+import java.util.List;
+import java.util.Map;
+
+
+public interface BankTaskService
+{
+    /**
+     * 查询失败的转账信息
+     * @param map
+     * @return
+     */
+    public List<Map> selectTranList(Map map);
+
+
+
+
+}

+ 28 - 0
taskMan/src/main/java/com/huyi/task/taskMan/service/impl/BankTaskServiceImpl.java

@@ -0,0 +1,28 @@
+package com.huyi.task.taskMan.service.impl;
+
+import com.huyi.task.taskMan.mapper.BankTaskMapper;
+import com.huyi.task.taskMan.service.BankTaskService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * 还款Service业务层处理
+ *
+ * @author ch
+ * @date 2021-09-06
+ */
+@Service
+public class BankTaskServiceImpl implements BankTaskService
+{
+    @Autowired
+    private BankTaskMapper bankTaskMapper;
+
+
+    @Override
+    public List<Map> selectTranList(Map map) {
+        return bankTaskMapper.selectTranList(map);
+    }
+}

+ 4 - 0
taskMan/src/main/resources/mapper/base/PayAccDetailMapper.xml

@@ -21,6 +21,10 @@
         <result column="create_time" property="createTime" />
         <result column="update_by" property="updateBy" />
         <result column="update_time" property="updateTime" />
+        <result column="PAD_STATE" property="padState" />
+        <result column="pad_business_id" property="padBusinessId" />
+        <result column="pad_tar_count" property="padTarCount" />
+        <result column="pad_pay_count" property="padPayCount" />
     </resultMap>
 
 </mapper>

+ 4 - 1
taskMan/src/main/resources/mapper/base/PayAccInfMapper.xml

@@ -4,7 +4,8 @@
 
     <!-- 通用查询映射结果 -->
     <resultMap id="BaseResultMap" type="com.huyi.task.base.entity.PayAccInf">
-        <id column="PAI_CSTNO" property="paiCstno" />
+        <id column="pai_id" property="paiId" />
+        <result column="PAI_CSTNO" property="paiCstno" />
         <result column="PAI_ACCNO" property="paiAccno" />
         <result column="PAI_VERSION" property="paiVersion" />
         <result column="PAI_STATUS" property="paiStatus" />
@@ -18,6 +19,8 @@
         <result column="create_time" property="createTime" />
         <result column="update_by" property="updateBy" />
         <result column="update_time" property="updateTime" />
+        <result column="pai_accno_name" property="paiAccnoName" />
+        <result column="pai_bank_name" property="paiBankName" />
     </resultMap>
 
 </mapper>