Browse Source

益寿源多商户号切换

三七 6 days ago
parent
commit
14755aa8fc

+ 26 - 13
fs-company/src/main/java/com/fs/company/controller/company/SysRedpacketConfigMoreController.java → fs-admin/src/main/java/com/fs/company/controller/SysRedpacketConfigMoreController.java

@@ -1,13 +1,15 @@
-package com.fs.company.controller.company;
+package com.fs.company.controller;
 
 
 import com.fs.common.annotation.Log;
 import com.fs.common.core.controller.BaseController;
 import com.fs.common.core.domain.AjaxResult;
+import com.fs.common.core.domain.R;
 import com.fs.common.core.page.TableDataInfo;
 import com.fs.common.enums.BusinessType;
 import com.fs.common.utils.poi.ExcelUtil;
 import com.fs.his.domain.SysRedpacketConfigMore;
+import com.fs.his.param.updateChangeMchIdParam;
 import com.fs.his.service.ISysRedpacketConfigMoreService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.security.access.prepost.PreAuthorize;
@@ -40,18 +42,6 @@ public class SysRedpacketConfigMoreController extends BaseController
         return getDataTable(list);
     }
 
-    /**
-     * 导出多商户配置列表
-     */
-    @PreAuthorize("@ss.hasPermi('redPacket:more:export')")
-    @Log(title = "多商户配置", businessType = BusinessType.EXPORT)
-    @GetMapping("/export")
-    public AjaxResult export(SysRedpacketConfigMore sysRedpacketConfigMore)
-    {
-        List<SysRedpacketConfigMore> list = sysRedpacketConfigMoreService.selectSysRedpacketConfigMoreList(sysRedpacketConfigMore);
-        ExcelUtil<SysRedpacketConfigMore> util = new ExcelUtil<SysRedpacketConfigMore>(SysRedpacketConfigMore.class);
-        return util.exportExcel(list, "多商户配置数据");
-    }
 
     /**
      * 获取多商户配置详细信息
@@ -63,6 +53,19 @@ public class SysRedpacketConfigMoreController extends BaseController
         return AjaxResult.success(sysRedpacketConfigMoreService.selectSysRedpacketConfigMoreById(id));
     }
 
+    /**
+     * 获取当前发红包的商户号
+     */
+    @PreAuthorize("@ss.hasPermi('redPacket:more:editConfig')")
+    @GetMapping(value = "/getRedPacketConfig")
+    public AjaxResult getRedPacketConFig()
+    {
+        return AjaxResult.success(sysRedpacketConfigMoreService.getRedPacketConFig());
+    }
+
+
+
+
     /**
      * 新增多商户配置
      */
@@ -74,6 +77,16 @@ public class SysRedpacketConfigMoreController extends BaseController
         return toAjax(sysRedpacketConfigMoreService.insertSysRedpacketConfigMore(sysRedpacketConfigMore));
     }
 
+    /**
+     * 修改发商户号的商户
+     */
+    @Log(title = "修改发商户号的商户", businessType = BusinessType.UPDATE)
+    @PostMapping("/updateChangeMchId")
+    public R updateChangeMchId(@RequestBody updateChangeMchIdParam param)
+    {
+        return sysRedpacketConfigMoreService.updateChangeMchId(param);
+    }
+
     /**
      * 修改多商户配置
      */

+ 18 - 0
fs-admin/src/main/java/com/fs/company/controller/companyTask/companyTask.java

@@ -0,0 +1,18 @@
+package com.fs.company.controller.companyTask;
+
+import com.fs.his.service.ISysRedpacketConfigMoreService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+@Component("companyTask")
+public class companyTask {
+
+    @Autowired
+    private ISysRedpacketConfigMoreService sysRedpacketConfigMoreService;
+
+    //切换商户号
+    public void changeRedPacketConfig()
+    {
+        sysRedpacketConfigMoreService.changeRedPacketConfig();
+    }
+}

+ 2 - 1
fs-quartz/src/main/java/com/fs/quartz/config/ScheduleConfig.java

@@ -8,7 +8,7 @@ import java.util.Properties;
 
 /**
  * 定时任务配置
- * 
+ *
 
  */
 @Configuration
@@ -51,6 +51,7 @@ public class ScheduleConfig
         factory.setOverwriteExistingJobs(true);
         // 设置自动启动,默认为true
         factory.setAutoStartup(true);
+//        factory.setAutoStartup(false);
 
         return factory;
     }

+ 3 - 3
fs-service/src/main/java/com/fs/his/domain/SysRedpacketConfigMore.java

@@ -13,15 +13,15 @@ import lombok.EqualsAndHashCode;
  * @date 2025-11-27
  */
 @Data
-@EqualsAndHashCode(callSuper = true)
-public class SysRedpacketConfigMore extends BaseEntity {
+@EqualsAndHashCode(callSuper = false)
+public class SysRedpacketConfigMore  {
 
     /** $column.columnComment */
     private Long id;
 
     /** 0:老商户 商家转账到零钱 1:新商户 商家转账 */
     @Excel(name = "0:老商户 商家转账到零钱 1:新商户 商家转账")
-    private Long isNew;
+    private Integer isNew;
 
     /** 公众号appId */
     @Excel(name = "公众号appId")

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

@@ -0,0 +1,9 @@
+package com.fs.his.param;
+
+import lombok.Data;
+
+@Data
+public class updateChangeMchIdParam {
+    private Long oldChangeMchId;
+    private Long newChangeMchId;
+}

+ 6 - 0
fs-service/src/main/java/com/fs/his/service/ISysRedpacketConfigMoreService.java

@@ -2,7 +2,9 @@ package com.fs.his.service;
 
 
 import com.baomidou.mybatisplus.extension.service.IService;
+import com.fs.common.core.domain.R;
 import com.fs.his.domain.SysRedpacketConfigMore;
+import com.fs.his.param.updateChangeMchIdParam;
 
 import java.util.List;
 
@@ -20,6 +22,10 @@ public interface ISysRedpacketConfigMoreService extends IService<SysRedpacketCon
      * @return 多商户配置
      */
     SysRedpacketConfigMore selectSysRedpacketConfigMoreById(Long id);
+    Long getRedPacketConFig();
+    R updateChangeMchId(updateChangeMchIdParam param);
+    void changeRedPacketConfig();
+
 
     /**
      * 查询多商户配置列表

+ 14 - 5
fs-service/src/main/java/com/fs/his/service/impl/FsStorePaymentServiceImpl.java

@@ -87,6 +87,7 @@ import com.github.binarywang.wxpay.service.WxPayService;
 import com.github.binarywang.wxpay.service.impl.WxPayServiceImpl;
 import com.google.gson.Gson;
 import com.hc.openapi.tool.fastjson.JSON;
+import io.netty.util.internal.StringUtil;
 import me.chanjar.weixin.common.error.WxErrorException;
 import org.redisson.api.RedissonClient;
 import org.slf4j.Logger;
@@ -542,7 +543,10 @@ public class FsStorePaymentServiceImpl implements IFsStorePaymentService {
         // 根据红包模式获取配置
         switch (param.getRedPacketMode()) {
             case 1:
-                json = configService.selectConfigByKey("redPacket.config");
+                json = redisCache.getCacheObject("sys_config:redPacket.config.new");
+                if (StringUtil.isNullOrEmpty(json) || json.isEmpty()) {
+                    json = configService.selectConfigByKey("redPacket.config");
+                }
                 config = JSONUtil.toBean(json, RedPacketConfig.class);
                 break;
             case 2:
@@ -565,7 +569,10 @@ public class FsStorePaymentServiceImpl implements IFsStorePaymentService {
         } else {
             result = sendRedPacketLegacyInternal(param, config);
         }
-//        if (result.getMsg().equals("余额不足") && param.getRedPacketMode() == 1) {
+
+        if (result.getMsg().equals("商家余额不足") && param.getRedPacketMode() == 1) {
+            redisCache.incr("sys_config:redPacket.config.newCount",1L);
+        }
 //            String backConfigStr = configService.selectConfigByKey("redPacket.config.back");
 //            if (StringUtils.isNotBlank(backConfigStr)) {
 //                List<RedPacketConfig> backConfigList = JSONArray.parseArray(backConfigStr, RedPacketConfig.class);
@@ -645,7 +652,8 @@ public class FsStorePaymentServiceImpl implements IFsStorePaymentService {
             return R.ok("发送红包成功").put("data", transferBillsResult);
         } catch (WxPayException e) {
             logger.error("商家转账支付失败:参数: {} :原因: {}", JSON.toJSONString(param), e.getMessage(), e);
-            if ("NOT_ENOUGH".equals(e.getErrCode())) {
+            if (e.getMessage() != null
+                    && (e.getMessage().contains("商户运营账户资金不足") || e.getMessage().contains("超出商户单日转账额度"))) {
                 return R.error("商家余额不足");
             }
             return R.error("发送红包失败");
@@ -699,10 +707,11 @@ public class FsStorePaymentServiceImpl implements IFsStorePaymentService {
             return R.ok("发送红包成功").put("orderCode", transferBatchesResult.getOutBatchNo()).put("batchId", transferBatchesResult.getBatchId());
         } catch (WxPayException e) {
             logger.error("商家转账支付失败:参数: {} :原因: {}", JSON.toJSONString(param), e.getMessage(), e);
-            if ("NOT_ENOUGH".equals(e.getErrCode())) {
+            if (e.getMessage() != null
+                    && (e.getMessage().contains("商户运营账户资金不足") || e.getMessage().contains("超出商户单日转账额度"))) {
                 return R.error("商家余额不足");
             }
-            return R.error("发送红包失败");
+            return R.error("发送红包失败:商家余额不足");
         }
     }
 

+ 110 - 0
fs-service/src/main/java/com/fs/his/service/impl/SysRedpacketConfigMoreServiceImpl.java

@@ -1,13 +1,29 @@
 package com.fs.his.service.impl;
 
 
+import cn.hutool.json.JSONUtil;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.fs.common.BeanCopyUtils;
+import com.fs.common.core.domain.R;
+import com.fs.common.core.redis.RedisCache;
+import com.fs.common.utils.StringUtils;
+import com.fs.course.config.RedPacketConfig;
 import com.fs.his.domain.SysRedpacketConfigMore;
 import com.fs.his.mapper.SysRedpacketConfigMoreMapper;
+import com.fs.his.param.updateChangeMchIdParam;
 import com.fs.his.service.ISysRedpacketConfigMoreService;
+import com.fs.system.service.ISysConfigService;
+import io.netty.util.internal.StringUtil;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.util.Comparator;
 import java.util.List;
+import java.util.OptionalInt;
+import java.util.stream.Collectors;
+import java.util.stream.IntStream;
 
 /**
  * 多商户配置Service业务层处理
@@ -15,9 +31,17 @@ import java.util.List;
  * @author fs
  * @date 2025-11-27
  */
+@Slf4j
 @Service
 public class SysRedpacketConfigMoreServiceImpl extends ServiceImpl<SysRedpacketConfigMoreMapper, SysRedpacketConfigMore> implements ISysRedpacketConfigMoreService {
 
+
+    @Autowired
+    private ISysConfigService configService;
+
+    @Autowired
+    private RedisCache redisCache;
+
     /**
      * 查询多商户配置
      *
@@ -30,6 +54,92 @@ public class SysRedpacketConfigMoreServiceImpl extends ServiceImpl<SysRedpacketC
         return baseMapper.selectSysRedpacketConfigMoreById(id);
     }
 
+    @Override
+    public Long getRedPacketConFig() {
+
+        String json = redisCache.getCacheObject("sys_config:redPacket.config.new");
+        if (StringUtil.isNullOrEmpty(json) || json.isEmpty()) {
+            json = configService.selectConfigByKey("redPacket.config");
+        }
+
+        RedPacketConfig config   = JSONUtil.toBean(json, RedPacketConfig.class);
+
+        return Long.valueOf(config.getMchId());
+
+    }
+
+    @Override
+    public R updateChangeMchId(updateChangeMchIdParam param) {
+
+        SysRedpacketConfigMore configMore = baseMapper.selectOne(new QueryWrapper<SysRedpacketConfigMore>().eq("mch_id", param.getNewChangeMchId()));
+
+        if (configMore == null || configMore.getMchId() == null) {
+            return R.error("商户号不存在");
+        }
+
+        RedPacketConfig config = new RedPacketConfig();
+        BeanCopyUtils.copy(configMore,config);
+
+        if (config.getMchId()!=null){
+            redisCache.setCacheObject("sys_config:redPacket.config.new", JSONUtil.toJsonStr(config));
+        }
+
+        return R.ok();
+    }
+
+    @Override
+    public void changeRedPacketConfig() {
+        long count = Long.parseLong(redisCache.getCacheObject("sys_config:redPacket.config.newCount"));
+        if (count >= 100) {
+            String json = redisCache.getCacheObject("sys_config:redPacket.config.new");
+            if (StringUtil.isNullOrEmpty(json) || json.isEmpty()) {
+                json = configService.selectConfigByKey("redPacket.config");
+            }
+
+            RedPacketConfig config   = JSONUtil.toBean(json, RedPacketConfig.class);
+
+            SysRedpacketConfigMore configMore = baseMapper.selectOne(new QueryWrapper<SysRedpacketConfigMore>().eq("mch_id", config.getMchId()));
+
+            List<SysRedpacketConfigMore> configMoreList = baseMapper.selectList(
+                    new QueryWrapper<SysRedpacketConfigMore>().orderByAsc("id")
+            );
+
+            // 空列表处理
+            if (configMoreList.isEmpty()) {
+                log.error("商户号列表为空");
+            }
+
+
+            // 查找当前元素的索引
+            int currentIndex = -1;
+            Long currentId = configMore != null ? configMore.getId() : null;
+
+            for (int i = 0; i < configMoreList.size(); i++) {
+                if (configMoreList.get(i).getId().equals(currentId)) {
+                    currentIndex = i;
+                    break;
+                }
+            }
+
+            // 计算下一个索引(使用取模实现循环)
+            int nextIndex = (currentIndex + 1) % configMoreList.size();
+
+            SysRedpacketConfigMore configMoreNew = configMoreList.get(nextIndex);
+
+
+            RedPacketConfig configNew = new RedPacketConfig();
+            BeanCopyUtils.copy(configMoreNew,configNew);
+
+            if (configNew.getMchId()!=null){
+                redisCache.setCacheObject("sys_config:redPacket.config.new", JSONUtil.toJsonStr(configNew));
+                redisCache.deleteObject("sys_config:redPacket.config.newCount");
+            }
+        }
+    }
+
+
+
+
     /**
      * 查询多商户配置列表
      *

+ 118 - 0
fs-service/src/main/resources/mapper/his/SysRedpacketConfigMoreMapper.xml

@@ -0,0 +1,118 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper
+PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.fs.his.mapper.SysRedpacketConfigMoreMapper">
+
+    <resultMap type="SysRedpacketConfigMore" id="SysRedpacketConfigMoreResult">
+        <result property="id"    column="id"    />
+        <result property="isNew"    column="is_new"    />
+        <result property="appId"    column="app_id"    />
+        <result property="miniappId"    column="miniapp_id"    />
+        <result property="mchId"    column="mch_id"    />
+        <result property="mchKey"    column="mch_key"    />
+        <result property="keyPath"    column="key_path"    />
+        <result property="privateKeyPath"    column="private_key_path"    />
+        <result property="privateCertPath"    column="private_cert_path"    />
+        <result property="apiV3Key"    column="api_v3_key"    />
+        <result property="publicKeyId"    column="public_key_id"    />
+        <result property="publicKeyPath"    column="public_key_path"    />
+        <result property="notifyUrl"    column="notify_url"    />
+        <result property="notifyUrlScrm"    column="notify_url_scrm"    />
+    </resultMap>
+
+    <sql id="selectSysRedpacketConfigMoreVo">
+        select id, is_new, app_id, miniapp_id, mch_id, mch_key, key_path, private_key_path, private_cert_path, api_v3_key, public_key_id, public_key_path, notify_url, notify_url_scrm from sys_redpacket_config_more
+    </sql>
+
+    <select id="selectSysRedpacketConfigMoreList" parameterType="SysRedpacketConfigMore" resultMap="SysRedpacketConfigMoreResult">
+        <include refid="selectSysRedpacketConfigMoreVo"/>
+        <where>
+            <if test="isNew != null "> and is_new = #{isNew}</if>
+            <if test="appId != null  and appId != ''"> and app_id = #{appId}</if>
+            <if test="miniappId != null  and miniappId != ''"> and miniapp_id = #{miniappId}</if>
+            <if test="mchId != null  and mchId != ''"> and mch_id = #{mchId}</if>
+            <if test="mchKey != null  and mchKey != ''"> and mch_key = #{mchKey}</if>
+            <if test="keyPath != null  and keyPath != ''"> and key_path = #{keyPath}</if>
+            <if test="privateKeyPath != null  and privateKeyPath != ''"> and private_key_path = #{privateKeyPath}</if>
+            <if test="privateCertPath != null  and privateCertPath != ''"> and private_cert_path = #{privateCertPath}</if>
+            <if test="apiV3Key != null  and apiV3Key != ''"> and api_v3_key = #{apiV3Key}</if>
+            <if test="publicKeyId != null  and publicKeyId != ''"> and public_key_id = #{publicKeyId}</if>
+            <if test="publicKeyPath != null  and publicKeyPath != ''"> and public_key_path = #{publicKeyPath}</if>
+            <if test="notifyUrl != null  and notifyUrl != ''"> and notify_url = #{notifyUrl}</if>
+            <if test="notifyUrlScrm != null  and notifyUrlScrm != ''"> and notify_url_scrm = #{notifyUrlScrm}</if>
+        </where>
+    </select>
+
+    <select id="selectSysRedpacketConfigMoreById" parameterType="Long" resultMap="SysRedpacketConfigMoreResult">
+        <include refid="selectSysRedpacketConfigMoreVo"/>
+        where id = #{id}
+    </select>
+
+    <insert id="insertSysRedpacketConfigMore" parameterType="SysRedpacketConfigMore">
+        insert into sys_redpacket_config_more
+        <trim prefix="(" suffix=")" suffixOverrides=",">
+            <if test="id != null">id,</if>
+            <if test="isNew != null">is_new,</if>
+            <if test="appId != null">app_id,</if>
+            <if test="miniappId != null">miniapp_id,</if>
+            <if test="mchId != null">mch_id,</if>
+            <if test="mchKey != null">mch_key,</if>
+            <if test="keyPath != null">key_path,</if>
+            <if test="privateKeyPath != null">private_key_path,</if>
+            <if test="privateCertPath != null">private_cert_path,</if>
+            <if test="apiV3Key != null">api_v3_key,</if>
+            <if test="publicKeyId != null">public_key_id,</if>
+            <if test="publicKeyPath != null">public_key_path,</if>
+            <if test="notifyUrl != null">notify_url,</if>
+            <if test="notifyUrlScrm != null">notify_url_scrm,</if>
+         </trim>
+        <trim prefix="values (" suffix=")" suffixOverrides=",">
+            <if test="id != null">#{id},</if>
+            <if test="isNew != null">#{isNew},</if>
+            <if test="appId != null">#{appId},</if>
+            <if test="miniappId != null">#{miniappId},</if>
+            <if test="mchId != null">#{mchId},</if>
+            <if test="mchKey != null">#{mchKey},</if>
+            <if test="keyPath != null">#{keyPath},</if>
+            <if test="privateKeyPath != null">#{privateKeyPath},</if>
+            <if test="privateCertPath != null">#{privateCertPath},</if>
+            <if test="apiV3Key != null">#{apiV3Key},</if>
+            <if test="publicKeyId != null">#{publicKeyId},</if>
+            <if test="publicKeyPath != null">#{publicKeyPath},</if>
+            <if test="notifyUrl != null">#{notifyUrl},</if>
+            <if test="notifyUrlScrm != null">#{notifyUrlScrm},</if>
+         </trim>
+    </insert>
+
+    <update id="updateSysRedpacketConfigMore" parameterType="SysRedpacketConfigMore">
+        update sys_redpacket_config_more
+        <trim prefix="SET" suffixOverrides=",">
+            <if test="isNew != null">is_new = #{isNew},</if>
+            <if test="appId != null">app_id = #{appId},</if>
+            <if test="miniappId != null">miniapp_id = #{miniappId},</if>
+            <if test="mchId != null">mch_id = #{mchId},</if>
+            <if test="mchKey != null">mch_key = #{mchKey},</if>
+            <if test="keyPath != null">key_path = #{keyPath},</if>
+            <if test="privateKeyPath != null">private_key_path = #{privateKeyPath},</if>
+            <if test="privateCertPath != null">private_cert_path = #{privateCertPath},</if>
+            <if test="apiV3Key != null">api_v3_key = #{apiV3Key},</if>
+            <if test="publicKeyId != null">public_key_id = #{publicKeyId},</if>
+            <if test="publicKeyPath != null">public_key_path = #{publicKeyPath},</if>
+            <if test="notifyUrl != null">notify_url = #{notifyUrl},</if>
+            <if test="notifyUrlScrm != null">notify_url_scrm = #{notifyUrlScrm},</if>
+        </trim>
+        where id = #{id}
+    </update>
+
+    <delete id="deleteSysRedpacketConfigMoreById" parameterType="Long">
+        delete from sys_redpacket_config_more where id = #{id}
+    </delete>
+
+    <delete id="deleteSysRedpacketConfigMoreByIds" parameterType="String">
+        delete from sys_redpacket_config_more where id in
+        <foreach item="id" collection="array" open="(" separator="," close=")">
+            #{id}
+        </foreach>
+    </delete>
+</mapper>