Przeglądaj źródła

feature 增加预下单记录

xiahan 2 miesięcy temu
rodzic
commit
5e75f13ad2

+ 13 - 0
zhsw-wechat-common/src/main/java/com/rongwei/wechat/system/dao/SwPaymentInitRecordDao.java

@@ -0,0 +1,13 @@
+package com.rongwei.wechat.system.dao;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.rongwe.wechat.system.domain.SwPaymentInitRecordDo;
+
+/**
+ * SwWechatPaymentInitRecordDao class
+ *
+ * @author XH
+ * @date 2025/05/13
+ */
+public interface SwPaymentInitRecordDao extends BaseMapper<SwPaymentInitRecordDo> {
+}

+ 13 - 0
zhsw-wechat-common/src/main/java/com/rongwei/wechat/system/service/SwPaymentInitRecordService.java

@@ -0,0 +1,13 @@
+package com.rongwei.wechat.system.service;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.rongwe.wechat.system.domain.SwPaymentInitRecordDo;
+
+/**
+ * SwWechatPaymentInitRecordService class
+ *
+ * @author XH
+ * @date 2025/05/13
+ */
+public interface SwPaymentInitRecordService extends IService<SwPaymentInitRecordDo> {
+}

+ 17 - 0
zhsw-wechat-common/src/main/java/com/rongwei/wechat/system/service/impl/SwPaymentInitRecordServiceImpl.java

@@ -0,0 +1,17 @@
+package com.rongwei.wechat.system.service.impl;
+
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.rongwe.wechat.system.domain.SwPaymentInitRecordDo;
+import com.rongwei.wechat.system.dao.SwPaymentInitRecordDao;
+import com.rongwei.wechat.system.service.SwPaymentInitRecordService;
+import org.springframework.stereotype.Service;
+
+/**
+ * SwWechatPaymentInitRecordServiceImpl class
+ *
+ * @author XH
+ * @date 2025/05/13
+ */
+@Service
+public class SwPaymentInitRecordServiceImpl extends ServiceImpl<SwPaymentInitRecordDao, SwPaymentInitRecordDo> implements SwPaymentInitRecordService {
+}

+ 36 - 27
zhsw-wechat-common/src/main/java/com/rongwei/wechat/system/utils/SaveConstans.java

@@ -6,20 +6,20 @@ import java.util.List;
 public class SaveConstans {
 
     // 业主对应的租户ID
-    public static final String REDIS_OWNER_KEY ="owner_%s";
+    public static final String REDIS_OWNER_KEY = "owner_%s";
 
     /**
      * 用户默认的token缓存时长
      */
-    public static final Integer DEFAULT_OWNER_CACHE_SECONDS=86400;
+    public static final Integer DEFAULT_OWNER_CACHE_SECONDS = 86400;
     /**
      * 区域前缀
      */
-    public static final String AREA_PREFIX="area-";
+    public static final String AREA_PREFIX = "area-";
 
-    public static final int REMOVE_FLAG=1;
+    public static final int REMOVE_FLAG = 1;
 
-    public static final int NO_REMOVE_FLAG=0;
+    public static final int NO_REMOVE_FLAG = 0;
 
     public static class billInfo {
 
@@ -39,19 +39,16 @@ public class SaveConstans {
         public static final String PRERECEIVEDSTATE = "1";
 
 
-
-
-
     }
 
     public static class billReccord {
 
         /**
-         *  缴费记录缴费状态   ------已缴费
+         * 缴费记录缴费状态   ------已缴费
          */
         public static final String PAIDSTATUS = "1";
         /**
-         *  缴费记录缴费状态   ------全额退款
+         * 缴费记录缴费状态   ------全额退款
          */
         public static final String FULLREFUNDSTATUS = "3";
 
@@ -80,25 +77,27 @@ public class SaveConstans {
         public static final String HAVEREVISEDSTATUS = "20";
 
 
-
     }
 
 
     public static class refundApply {
 
-        /**退款方式
+        /**
+         * 退款方式
          * 退余额-不退账单
          */
         public static final String REFUNDMETHODBALANCE = "2";
 
 
-        /**退款方式
+        /**
+         * 退款方式
          * 全部退款-按缴费记录退款并退账单
          */
         public static final String REFUNDMETHODALL = "1";
 
 
-        /** 是否已退款 Refunded
+        /**
+         * 是否已退款 Refunded
          * 已退款
          */
         public static final String REFUNDED = "y";
@@ -106,51 +105,61 @@ public class SaveConstans {
         /**
          * 退款成功
          */
-        public static final String REFUNDSUCCESSFUL ="3";
+        public static final String REFUNDSUCCESSFUL = "3";
 
         /**
          * 退款失败
          */
-        public static final String REFUNDFAILED ="4";
+        public static final String REFUNDFAILED = "4";
 
 
     }
 
-    public static class RoutineInspection{
-        public static class STATUS{
+    public static class RoutineInspection {
+        public static class STATUS {
             /**
              * 禁用
              */
-            public static final String DISABLE="disable";
+            public static final String DISABLE = "disable";
             /**
              * 启用
              */
-            public static final String ENABLE="enable";
+            public static final String ENABLE = "enable";
         }
     }
-    public static class RoutineInspectionTask{
-        public static class STATUS{
+
+    public static class RoutineInspectionTask {
+        public static class STATUS {
             /**
              * 待巡检
              */
-            public static final String WAIT="1";
+            public static final String WAIT = "1";
             /**
              * 已巡检
              */
-            public static final String OK="2";
+            public static final String OK = "2";
             /**
              * 已巡检
              */
-            public static final String PROGRESS="3";
+            public static final String PROGRESS = "3";
             /**
              * 已巡检
              */
-            public static final String CLOSE="4";
+            public static final String CLOSE = "4";
         }
-        public static class PointStatus{
+
+        public static class PointStatus {
 
         }
     }
+
+    public static class PayType {
+        public static final String WE_CHAT = "wechat";
+        public static final String A_LI_PAY = "alipay";
+
+        public static final String SUCCESS = "success";
+    }
+
     public static final List<String> MONTH_ENG = new ArrayList<String>() {{
         add("january");
         add("february");

+ 53 - 11
zhsw-wechat-common/src/main/java/com/rongwei/wechat/system/wechat/impl/PayMentServiceImpl.java

@@ -1,9 +1,11 @@
 package com.rongwei.wechat.system.wechat.impl;
 
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import com.rongwe.wechat.system.domain.SwBillManagementUnpaidDo;
 import com.rongwe.wechat.system.domain.SwEnterpriseConfigInfoDo;
+import com.rongwe.wechat.system.domain.SwPaymentInitRecordDo;
 import com.rongwe.wechat.system.vo.CreatePaymentRecordVo;
 import com.rongwe.wechat.system.vo.PrepayNoticeVo;
 import com.rongwe.wechat.system.vo.WeChatPayTransactionVo;
@@ -12,6 +14,7 @@ import com.rongwei.commonservice.service.impl.RedisServiceImpl;
 import com.rongwei.rwcommon.base.BaseDo;
 import com.rongwei.rwcommon.base.R;
 import com.rongwei.rwcommon.base.exception.CustomException;
+import com.rongwei.rwcommon.utils.SecurityUtil;
 import com.rongwei.rwcommonentity.commonservers.domain.TenantDo;
 import com.rongwei.wechat.system.config.ContextHolder;
 import com.rongwei.wechat.system.config.WeChatAboutApiPara;
@@ -19,6 +22,7 @@ import com.rongwei.wechat.system.dao.CommonBusinessDao;
 import com.rongwei.wechat.system.service.impl.SwBillManagementUnpaidServiceImpl;
 import com.rongwei.wechat.system.service.impl.SwBillingRecordServiceImpl;
 import com.rongwei.wechat.system.service.impl.SwEnterpriseConfigInfoServiceImpl;
+import com.rongwei.wechat.system.service.impl.SwPaymentInitRecordServiceImpl;
 import com.rongwei.wechat.system.utils.WxPayApi;
 import com.rongwei.wechat.system.wechat.PayMentService;
 import com.rongwei.wechat.system.wechat.PaymentRecordService;
@@ -37,9 +41,13 @@ import javax.crypto.spec.SecretKeySpec;
 import java.io.IOException;
 import java.math.BigDecimal;
 import java.math.RoundingMode;
+import java.time.LocalDateTime;
 import java.util.*;
 import java.util.stream.Collectors;
 
+import static com.rongwei.wechat.system.utils.SaveConstans.PayType.SUCCESS;
+import static com.rongwei.wechat.system.utils.SaveConstans.PayType.WE_CHAT;
+
 /**
  * PayMentServiceImpl class
  *
@@ -61,14 +69,12 @@ public class PayMentServiceImpl implements PayMentService {
     private CommonBusinessDao commonBusinessDao;
     @Autowired
     private SwBillingRecordServiceImpl swBillingRecordService;
-
     @Autowired
     private SwBillManagementUnpaidServiceImpl swBillManagementUnpaidService;
-
-
     @Autowired
     private PaymentRecordService paymentRecordService;
-
+    @Autowired
+    private SwPaymentInitRecordServiceImpl swPaymentInitRecordService;
     static final int TAG_LENGTH_BIT = 128;
 
     @Override
@@ -129,13 +135,13 @@ public class PayMentServiceImpl implements PayMentService {
         String nonceStr = UUID.randomUUID().toString().replaceAll("-", "");
         vo.setOutTradeNo(nonceStr);
         // 商户名称+
-        vo.setDescription(merchantname + "-水费");
+        vo.setDescription(merchantname + ": 户号:" + vo.getUserNumber() + "-水费");
         PrepayWithRequestPaymentResponse prepayWithRequestPaymentResponse = wxPayApi.prepayWithRequestPayment(vo);
         Map<String, Object> paymentReturnMap = new HashMap<>();
         paymentReturnMap.put("paymentSign", prepayWithRequestPaymentResponse);
         paymentReturnMap.put("orderNo", nonceStr);
         String zdId = vo.getZdId();
-
+        createAdvancePayRecordData(WE_CHAT, zdId, vo.getUserNumber(), nonceStr, vo.toString(), paymentReturnMap.toString(), vo.getOpenId());
         if (StringUtils.isNotBlank(zdId)) {
             // 预缴款项对应的账单信息 更新订单号
             List<SwBillManagementUnpaidDo> unpaidDoList = new ArrayList<>();
@@ -151,6 +157,31 @@ public class PayMentServiceImpl implements PayMentService {
         return R.ok(paymentReturnMap);
     }
 
+    /**
+     * 创建预下单记录
+     */
+    public void createAdvancePayRecordData(String payType, String zdId, String userNum,
+                                           String orderNo, String paraStr, String returnStr, String openId) {
+        LocalDateTime now = LocalDateTime.now();
+        //创建微信下单记录
+        SwPaymentInitRecordDo swPaymentInitRecordDo = new SwPaymentInitRecordDo();
+        swPaymentInitRecordDo.setId(SecurityUtil.getUUID());
+        swPaymentInitRecordDo.setCreatedate(new Date());
+        swPaymentInitRecordDo.setModifydate(new Date());
+        swPaymentInitRecordDo.setPaytype(payType);
+        swPaymentInitRecordDo.setBillid(zdId);
+        swPaymentInitRecordDo.setOrderpara(paraStr);
+        swPaymentInitRecordDo.setOrderno(orderNo);
+        swPaymentInitRecordDo.setPaydate(now);
+        swPaymentInitRecordDo.setYearnum(now.getYear());
+        swPaymentInitRecordDo.setMonthnnum(now.getMonthValue());
+        swPaymentInitRecordDo.setDaynum(now.getDayOfMonth());
+        swPaymentInitRecordDo.setReturendata(returnStr);
+        swPaymentInitRecordDo.setUsernum(userNum);
+        swPaymentInitRecordDo.setWechatsign(openId);
+        swPaymentInitRecordService.save(swPaymentInitRecordDo);
+    }
+
     /**
      * 微信支付成功回调函数
      *
@@ -224,9 +255,20 @@ public class PayMentServiceImpl implements PayMentService {
             CreatePaymentRecordVo createPaymentRecordVo = new CreatePaymentRecordVo();
             createPaymentRecordVo.setOrderNo(outTradeNo);
             createPaymentRecordVo.setPaymentAmount(amount);
-            List<SwBillManagementUnpaidDo> list = swBillManagementUnpaidService.list(new LambdaQueryWrapper<SwBillManagementUnpaidDo>()
-                    .eq(BaseDo::getDeleted, "0").eq(SwBillManagementUnpaidDo::getMerchantpaymentnumber, outTradeNo));
-            String zdIds = list.stream().map(SwBillManagementUnpaidDo::getId).collect(Collectors.joining(","));
+            SwPaymentInitRecordDo paymentInitRecordDo = swPaymentInitRecordService.getOne(new LambdaQueryWrapper<SwPaymentInitRecordDo>()
+                    .eq(BaseDo::getDeleted, "0")
+                    .eq(SwPaymentInitRecordDo::getOrderno, outTradeNo), false);
+            String zdIds = null;
+            if (paymentInitRecordDo != null) {
+                zdIds =StringUtils.isBlank(paymentInitRecordDo.getBillid()) ? null : paymentInitRecordDo.getBillid();
+                swPaymentInitRecordService.update(new LambdaUpdateWrapper<SwPaymentInitRecordDo>()
+                        .eq(SwPaymentInitRecordDo::getId,paymentInitRecordDo.getId())
+                        .set(SwPaymentInitRecordDo::getState,SUCCESS)
+                        .set(SwPaymentInitRecordDo::getCallbackcontent,transaction.toString())
+                        .set(BaseDo::getModifydate,new Date())
+                );
+            }
+
             createPaymentRecordVo.setZdId(zdIds);
             createPaymentRecordVo.setUserNumber(userNum);
             createPaymentRecordVo.setOpenId(transaction.getPayer().getOpenid());
@@ -235,9 +277,9 @@ public class PayMentServiceImpl implements PayMentService {
             createPaymentRecordVo.setSuccessTime(successTime);
             log.error("开始创建缴费记录:{}", createPaymentRecordVo);
             paymentRecordService.createRecord(createPaymentRecordVo);
-        }catch (Exception e) {
+        } catch (Exception e) {
             return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(error.toString());
-        }finally {
+        } finally {
             ContextHolder.clear();
         }
         return ResponseEntity.status(HttpStatus.OK).body("");

+ 97 - 0
zhsw-wechat-entity/src/main/java/com/rongwe/wechat/system/domain/SwPaymentInitRecordDo.java

@@ -0,0 +1,97 @@
+package com.rongwe.wechat.system.domain;
+
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.rongwei.rwcommon.base.BaseDo;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.experimental.Accessors;
+
+import java.io.Serializable;
+import java.time.LocalDateTime;
+
+import static org.apache.ibatis.type.JdbcType.TIMESTAMP;
+
+/**
+ * SwWechatPaymentInitRecordDo class
+ *
+ * @author XH
+ * @date 2025/05/13
+ */
+@Data
+@EqualsAndHashCode(callSuper = false)
+@Accessors(chain = true)
+@TableName("sw_payment_init_record")
+public class SwPaymentInitRecordDo extends BaseDo implements Serializable {
+    private static final long serialVersionUID = 478239245134424500L;
+    /**
+     * 主键
+     */
+    private String id;
+
+    /**
+     * 租户ID
+     */
+    private String tenantid;
+
+    /**
+     * 扩展json格式配置
+     */
+    private String roption;
+
+
+    /**
+     * 账单ID
+     */
+    private String billid;
+    /**
+     * 下单时的参数
+     */
+    private String orderpara;
+    /**
+     * 微信返回的数据
+     */
+    private String returendata;
+    /**
+     * 微信或第三方下单时创建的商户单号
+     */
+    private String orderno;
+    /**
+     * 下单时间
+     */
+    @TableField(value = "PLANNEDTIMEEND", jdbcType = TIMESTAMP)
+    private LocalDateTime paydate;
+    /**
+     * 年
+     */
+    private int yearnum;
+    /**
+     * 月
+     */
+    private int monthnnum;
+    /**
+     * 日
+     */
+    private int daynum;
+    /**
+     * 户号
+     */
+    private String usernum;
+    /**
+     * 微信或者第三方标识
+     */
+    private String wechatsign;
+
+    /**
+     * 付款方式(微信,支付宝)
+     */
+    private String paytype;
+    /**
+     * 是否回调
+     */
+    private String callbackcontent;
+    /**
+     * 回调结果
+     */
+    private String state;
+}