Prechádzať zdrojové kódy

新增商户号字段

yfh 2 dní pred
rodič
commit
d893e1ecfa

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

@@ -57,5 +57,10 @@ public class MerchantAppConfig extends BaseEntity{
     /** 修改人ID或用户名 */
     private String updatedBy;
 
+    /**
+     * 商户号
+     */
+    private String merchantId;
+
 
 }

+ 13 - 0
fs-service/src/main/java/com/fs/his/mapper/MerchantAppConfigMapper.java

@@ -11,6 +11,19 @@ import com.fs.his.domain.MerchantAppConfig;
  * @date 2025-12-05
  */
 public interface MerchantAppConfigMapper extends BaseMapper<MerchantAppConfig>{
+
+
+    /**
+     * 检查表是否存在
+     */
+    Integer checkTableExists();
+
+    /**
+     * 创建商户配置表
+     */
+    void createMerchantAppConfigTable();
+
+
     /**
      * 查询商户应用配置
      *

+ 61 - 0
fs-service/src/main/java/com/fs/his/service/impl/MerchantAppConfigServiceImpl.java

@@ -1,12 +1,28 @@
 package com.fs.his.service.impl;
 
 import java.util.List;
+import java.util.concurrent.CompletableFuture;
+
+import cn.hutool.core.util.ObjectUtil;
+import com.alibaba.fastjson.JSON;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.fs.common.core.domain.entity.SysDictType;
+import com.fs.his.domain.FsPayConfig;
 import com.fs.his.domain.MerchantAppConfig;
 import com.fs.his.mapper.MerchantAppConfigMapper;
 import com.fs.his.service.IMerchantAppConfigService;
+import com.fs.hisStore.domain.FsPayConfigScrm;
+import com.fs.system.domain.SysConfig;
+import com.fs.system.mapper.SysConfigMapper;
+import com.fs.system.mapper.SysDictTypeMapper;
+import com.google.gson.Gson;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import javax.annotation.PostConstruct;
 
 /**
  * 商户应用配置Service业务层处理
@@ -15,8 +31,53 @@ import org.springframework.stereotype.Service;
  * @date 2025-12-05
  */
 @Service
+@Slf4j
 public class MerchantAppConfigServiceImpl extends ServiceImpl<MerchantAppConfigMapper, MerchantAppConfig> implements IMerchantAppConfigService {
 
+    @Autowired
+    private SysConfigMapper sysConfigMapper;
+
+    /**
+     * 异步初始化方法
+     */
+    @PostConstruct
+    @Async("merchantInitExecutor")
+    public void init() {
+        log.info("开始异步初始化商户配置表...");
+
+        // 使用CompletableFuture进行异步初始化
+        CompletableFuture.runAsync(() -> {
+            try {
+                // 延迟5秒,等待数据库连接就绪
+                Thread.sleep(5000);
+                Integer count = baseMapper.checkTableExists();
+                if (ObjectUtil.isNotNull(count)&&count>0) {
+                    return;
+                }
+                // 1. 检查并创建表
+                initMerchantTable();
+
+            } catch (Exception e) {
+                log.error("初始化商户配置表失败", e);
+            }
+        });
+    }
+
+    /**
+     * 初始化商户配置表
+     */
+    @Transactional(rollbackFor = Exception.class)
+    public void initMerchantTable() {
+        try {
+            // 检查表是否存在
+            log.info("商户配置表不存在,开始创建...");
+            baseMapper.createMerchantAppConfigTable();
+            log.info("商户配置表创建成功");
+        } catch (Exception e) {
+            log.error("初始化商户配置表失败", e);
+            throw e;
+        }
+    }
     /**
      * 查询商户应用配置
      *

+ 34 - 1
fs-service/src/main/resources/mapper/MerchantAppConfigMapper.xml

@@ -15,10 +15,40 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         <result property="isDeleted"    column="is_deleted"    />
         <result property="createdBy"    column="created_by"    />
         <result property="updatedBy"    column="updated_by"    />
+        <result property="merchantId"    column="merchant_id"    />
     </resultMap>
 
+    <!-- 检查表是否存在 -->
+    <select id="checkTableExists" resultType="java.lang.Integer">
+        SELECT COUNT(*) FROM information_schema.tables
+        WHERE table_schema = DATABASE() AND table_name = 'merchant_app_config'
+    </select>
+
+    <!-- 创建商户配置表 -->
+    <update id="createMerchantAppConfigTable">
+        CREATE TABLE `merchant_app_config` (
+        `id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键ID',
+        `merchant_type` varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '商户类型:如WECHAT_PAY、ALIPAY等',
+        `app_id` varchar(64) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '应用ID',
+        `callback_url` varchar(512) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '回调地址,用于接收支付结果等通知',
+        `data_json` json DEFAULT NULL COMMENT '扩展配置数据,JSON格式存储其他配置信息',
+        `created_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
+        `updated_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
+        `is_deleted` tinyint NOT NULL DEFAULT '0' COMMENT '删除状态:0-正常,1-已删除',
+        `created_by` varchar(64) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '创建人ID或用户名',
+        `updated_by` varchar(64) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '修改人ID或用户名',
+        `merchant_id` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '商户号',
+        PRIMARY KEY (`id`),
+        KEY `idx_merchant_type` (`merchant_type`),
+        KEY `idx_app_id` (`app_id`),
+        KEY `idx_created_time` (`created_time`),
+        KEY `merchant_app_config_merchant_type_IDX` (`merchant_type`,`is_deleted`,`merchant_id`) USING BTREE
+        ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='商户应用配置表'
+    </update>
+
+
     <sql id="selectMerchantAppConfigVo">
-        select id, merchant_type, app_id, callback_url, data_json, created_time, updated_time, is_deleted, created_by, updated_by from merchant_app_config
+        select id, merchant_type, app_id, merchant_id,callback_url, data_json, created_time, updated_time, is_deleted, created_by, updated_by from merchant_app_config
     </sql>
 
     <select id="selectMerchantAppConfigList" parameterType="MerchantAppConfig" resultMap="MerchantAppConfigResult">
@@ -48,6 +78,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="isDeleted != null">is_deleted,</if>
             <if test="createdBy != null and createdBy != ''">created_by,</if>
             <if test="updatedBy != null and updatedBy != ''">updated_by,</if>
+            <if test="merchantId != null and merchantId != ''">merchant_id,</if>
          </trim>
         <trim prefix="values (" suffix=")" suffixOverrides=",">
             <if test="merchantType != null and merchantType != ''">#{merchantType},</if>
@@ -59,6 +90,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="isDeleted != null">#{isDeleted},</if>
             <if test="createdBy != null and createdBy != ''">#{createdBy},</if>
             <if test="updatedBy != null and updatedBy != ''">#{updatedBy},</if>
+            <if test="merchantId != null and merchantId != ''">#{merchantId},</if>
          </trim>
     </insert>
 
@@ -74,6 +106,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="isDeleted != null">is_deleted = #{isDeleted},</if>
             <if test="createdBy != null and createdBy != ''">created_by = #{createdBy},</if>
             <if test="updatedBy != null and updatedBy != ''">updated_by = #{updatedBy},</if>
+            <if test="merchantId != null and merchantId != ''">merchant_id = #{merchantId},</if>
         </trim>
         where id = #{id}
     </update>