Selaa lähdekoodia

add:同步支付状态 添加错误记录

ct 1 päivä sitten
vanhempi
commit
4ee15f2e14

+ 25 - 4
fs-admin/src/main/java/com/fs/his/controller/FsStorePaymentController.java

@@ -5,10 +5,10 @@ import java.util.List;
 
 import com.fs.common.core.domain.R;
 import com.fs.common.utils.SecurityUtils;
-import com.fs.his.domain.FsExportTask;
+import com.fs.his.domain.*;
 import com.fs.his.mapper.FsPrescribeMapper;
 import com.fs.his.param.FsStorePaymentParam;
-import com.fs.his.service.IFsExportTaskService;
+import com.fs.his.service.*;
 import com.fs.his.vo.FsStorePaymentExcelVO;
 import com.fs.his.vo.FsStorePaymentVO;
 import lombok.extern.slf4j.Slf4j;
@@ -26,8 +26,6 @@ import com.fs.common.annotation.Log;
 import com.fs.common.core.controller.BaseController;
 import com.fs.common.core.domain.AjaxResult;
 import com.fs.common.enums.BusinessType;
-import com.fs.his.domain.FsStorePayment;
-import com.fs.his.service.IFsStorePaymentService;
 import com.fs.common.utils.poi.ExcelUtil;
 import com.fs.common.core.page.TableDataInfo;
 
@@ -44,11 +42,17 @@ public class FsStorePaymentController extends BaseController
 {
     @Autowired
     private IFsStorePaymentService fsStorePaymentService;
+
+    @Autowired
+    private IFsStorePaymentErrorService fsStorePaymentErrorService;
     @Autowired
     FsPrescribeMapper fsPrescribeMapper;
 
     @Autowired
     private IFsExportTaskService exportTaskService;
+    @Autowired
+    private IFsPackageOrderService fsPackageOrderService;
+
     /**
      * 查询支付明细列表
      */
@@ -169,4 +173,21 @@ public class FsStorePaymentController extends BaseController
     {
         return toAjax(fsStorePaymentService.deleteFsStorePaymentByPaymentIds(paymentIds));
     }
+
+    /**
+     * 查询支付错误明细
+     */
+    @GetMapping("/error/list")
+    public TableDataInfo list(FsStorePaymentError fsStorePaymentError)
+    {
+        startPage();
+        List<FsStorePaymentError> list = fsStorePaymentErrorService.selectFsStorePaymentErrorList(fsStorePaymentError);
+        for (FsStorePaymentError vo : list){
+            if (vo.getBusinessType() != null && vo.getBusinessType()==3 &&  vo.getOrderId() != null) {
+                FsPackageOrder fsPackageOrder = fsPackageOrderService.selectFsPackageOrderByOrderId(vo.getOrderId());
+                vo.setOrderNo(fsPackageOrder.getOrderSn());
+            }
+        }
+        return getDataTable(list);
+    }
 }

+ 5 - 0
fs-service/src/main/java/com/fs/his/domain/FsStorePaymentError.java

@@ -35,4 +35,9 @@ public class FsStorePaymentError extends BaseEntity
     @Excel(name = "0未处理 1已处理")
     private Integer status;
 
+
+    private Long orderId;
+
+    private Integer businessType;
+
 }

+ 9 - 0
fs-service/src/main/java/com/fs/his/service/IFsStorePaymentErrorService.java

@@ -0,0 +1,9 @@
+package com.fs.his.service;
+
+import com.fs.his.domain.FsStorePaymentError;
+
+import java.util.List;
+
+public interface IFsStorePaymentErrorService {
+    List<FsStorePaymentError> selectFsStorePaymentErrorList(FsStorePaymentError fsStorePaymentError);
+}

+ 21 - 0
fs-service/src/main/java/com/fs/his/service/impl/FsStorePaymentErrorServiceImpl.java

@@ -0,0 +1,21 @@
+package com.fs.his.service.impl;
+
+import com.fs.his.domain.FsStorePaymentError;
+import com.fs.his.mapper.FsStorePaymentErrorMapper;
+import com.fs.his.service.IFsStorePaymentErrorService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+@Service
+public class FsStorePaymentErrorServiceImpl implements IFsStorePaymentErrorService {
+    @Autowired
+    private FsStorePaymentErrorMapper fsStorePaymentErrorMapper;
+
+    public List<FsStorePaymentError> selectFsStorePaymentErrorList(FsStorePaymentError fsStorePaymentError){
+        return fsStorePaymentErrorMapper.selectFsStorePaymentErrorList(fsStorePaymentError);
+    }
+
+
+}

+ 43 - 4
fs-service/src/main/java/com/fs/his/service/impl/FsStorePaymentServiceImpl.java

@@ -48,9 +48,7 @@ import com.fs.his.domain.*;
 import com.fs.his.dto.PayConfigDTO;
 import com.fs.his.enums.PaymentMethodEnum;
 import com.fs.his.mapper.*;
-import com.fs.his.param.FsStorePaymentParam;
-import com.fs.his.param.PayOrderParam;
-import com.fs.his.param.WxSendRedPacketParam;
+import com.fs.his.param.*;
 import com.fs.his.service.IFsInquiryOrderService;
 
 import com.fs.his.param.WxSendRedPacketParam;
@@ -217,6 +215,9 @@ public class FsStorePaymentServiceImpl implements IFsStorePaymentService {
     @Value("${cloud_host.company_name}")
     private String signProjectName;
 
+    @Autowired
+    private FsStorePaymentErrorMapper fsStorePaymentErrorMapper;
+
     /**
      * 红包账户锁
      */
@@ -1648,6 +1649,7 @@ public class FsStorePaymentServiceImpl implements IFsStorePaymentService {
         return "SUCCESS";
     }
 
+    long TWENTY_DAYS_IN_MILLIS = 1728000000L;// 使用毫秒判断,20天 = 20 * 24 * 60 * 60 * 1000 毫秒
     @Override
     public void synchronizePayStatus() {
         FsStorePayment queryParam = new FsStorePayment();
@@ -1659,7 +1661,44 @@ public class FsStorePaymentServiceImpl implements IFsStorePaymentService {
             List<CompletableFuture<Void>> futures = new ArrayList<>();
             for (FsStorePayment fsStorePayment : list) {
                 CompletableFuture<Void> future = CompletableFuture.runAsync(() -> {
-                    updateFsStorePaymentByDecryptForm(fsStorePayment.getPaymentId());
+                    try {
+                        updateFsStorePaymentByDecryptForm(fsStorePayment.getPaymentId());
+                        //查询是否改为已支付
+                        FsStorePayment finalPayment = fsStorePaymentMapper.selectFsStorePaymentByPaymentId(fsStorePayment.getPaymentId());
+                        try {
+                            Date createTime = finalPayment.getCreateTime();
+                            Date now = new Date();
+                            long value = now.getTime() - createTime.getTime();
+                            if(finalPayment.getStatus() == 0
+                                    && finalPayment.getBusinessType() == 3
+                                    && (value > TWENTY_DAYS_IN_MILLIS)
+                                    && finalPayment.getBusinessId() != null){
+                                //套餐包超过20天取消订单
+                                FsPackageOrderCancelParam param = new FsPackageOrderCancelParam();
+                                param.setOrderId(Long.valueOf(finalPayment.getBusinessId()));
+                                packageOrderService.cancel(param);
+                            }
+                        } catch (NumberFormatException e) {
+                            logger.info("定时任务:同步支付状态超时取消订单失败,payment_id:{}",fsStorePayment.getPaymentId());
+                        }
+                    } catch (Exception e) {
+                        //添加失败记录
+                        FsStorePaymentError fsStorePaymentError = new FsStorePaymentError();
+                        fsStorePaymentError.setOrderFlowNo(fsStorePayment.getTradeNo());
+                        String businessId = fsStorePayment.getBusinessId();
+                        fsStorePaymentError.setBusinessType(fsStorePayment.getBusinessType());
+                        fsStorePaymentError.setMsg(e.getMessage());
+                        fsStorePaymentError.setStatus(0);
+                        fsStorePaymentError.setCreateTime(new Date());
+                        if (businessId != null && fsStorePayment.getBusinessType() == 3) {
+                            fsStorePaymentError.setOrderId(Long.valueOf(businessId));
+                            FsPackageOrder fsPackageOrder = packageOrderService.selectFsPackageOrderByOrderId(Long.valueOf(businessId));
+                            if (fsPackageOrder != null) {
+                                fsStorePaymentError.setOrderNo(fsPackageOrder.getOrderSn());
+                            }
+                        }
+                        fsStorePaymentErrorMapper.insertFsStorePaymentError(fsStorePaymentError);
+                    }
                     logger.info("定时任务:同步支付状态,payment_id:{}",fsStorePayment.getPaymentId());
                 });
                 futures.add(future);

+ 11 - 2
fs-service/src/main/resources/mapper/his/FsStorePaymentErrorMapper.xml

@@ -11,10 +11,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         <result property="msg"    column="msg"    />
         <result property="status"    column="status"    />
         <result property="createTime"    column="create_time"    />
+        <result property="orderId"    column="order_id"    />
+        <result property="businessType"    column="business_type"    />
     </resultMap>
 
     <sql id="selectFsStorePaymentErrorVo">
-        select id, order_flow_no, order_no, msg, status, create_time from fs_store_payment_error
+        select id, order_flow_no, order_no, msg, status, create_time,order_id,business_type from fs_store_payment_error
     </sql>
 
     <select id="selectFsStorePaymentErrorList" parameterType="FsStorePaymentError" resultMap="FsStorePaymentErrorResult">
@@ -23,7 +25,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="orderFlowNo != null  and orderFlowNo != ''"> and order_flow_no = #{orderFlowNo}</if>
             <if test="orderNo != null  and orderNo != ''"> and order_no = #{orderNo}</if>
             <if test="msg != null  and msg != ''"> and msg = #{msg}</if>
-            <if test="status != null "> and status = #{status}</if>
+            <if test="orderId != null "> and order_id = #{orderId}</if>
+            <if test="businessType != null "> and business_type = #{businessType}</if>
         </where>
     </select>
     
@@ -41,6 +44,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="msg != null">msg,</if>
             <if test="status != null">status,</if>
             <if test="createTime != null">create_time,</if>
+            <if test="orderId != null">order_id,</if>
+            <if test="businessType != null">business_type,</if>
          </trim>
         <trim prefix="values (" suffix=")" suffixOverrides=",">
             <if test="id != null">#{id},</if>
@@ -49,6 +54,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="msg != null">#{msg},</if>
             <if test="status != null">#{status},</if>
             <if test="createTime != null">#{createTime},</if>
+            <if test="orderId != null">#{orderId},</if>
+            <if test="businessType != null">#{businessType},</if>
          </trim>
     </insert>
 
@@ -60,6 +67,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="msg != null">msg = #{msg},</if>
             <if test="status != null">status = #{status},</if>
             <if test="createTime != null">create_time = #{createTime},</if>
+            <if test="orderId != null">order_id = #{orderId},</if>
+            <if test="businessType != null">business_type = #{businessType},</if>
         </trim>
         where id = #{id}
     </update>