소스 검색

+ 多租户,支持批处理脚本,织入租户id

chen.cheng 2 달 전
부모
커밋
bd5075869f

+ 1 - 1
bd-park/park-backend/park-core/src/main/java/com/huashe/park/core/mapper/MachineProcessResultMapper.java

@@ -63,7 +63,7 @@ public interface MachineProcessResultMapper {
      */
      */
     public int deleteMachineProcessResultByIds(Long[] ids);
     public int deleteMachineProcessResultByIds(Long[] ids);
 
 
-    @Tenant(tableAlias = "cmpr")
+    @Tenant(tableAlias = "cphir")
     List<ConsUnitResult> qeyConsUnitResult(Long consUnitId);
     List<ConsUnitResult> qeyConsUnitResult(Long consUnitId);
 
 
 }
 }

+ 3 - 0
bd-park/park-backend/park-core/src/main/java/com/huashe/park/core/mapper/SysCustConfigMapper.java

@@ -1,6 +1,7 @@
 package com.huashe.park.core.mapper;
 package com.huashe.park.core.mapper;
 
 
 import com.huashe.common.annotation.DataSource;
 import com.huashe.common.annotation.DataSource;
+import com.huashe.common.annotation.mybatis.IgnoreTenant;
 import com.huashe.common.enums.DataSourceType;
 import com.huashe.common.enums.DataSourceType;
 import com.huashe.park.domain.entity.CustSysConfig;
 import com.huashe.park.domain.entity.CustSysConfig;
 
 
@@ -9,8 +10,10 @@ public interface SysCustConfigMapper {
 
 
     int updateConfig(CustSysConfig custSysConfig);
     int updateConfig(CustSysConfig custSysConfig);
 
 
+    @IgnoreTenant
     CustSysConfig selectConfigById(Long id);
     CustSysConfig selectConfigById(Long id);
 
 
+    @IgnoreTenant
     CustSysConfig checkConfigKeyUnique(String configKey);
     CustSysConfig checkConfigKeyUnique(String configKey);
 
 
     CustSysConfig selectConfig(CustSysConfig param);
     CustSysConfig selectConfig(CustSysConfig param);

+ 2 - 0
bd-park/park-backend/park-core/src/main/resources/mapper/cons/ConsPileHoleInfoMapper.xml

@@ -166,6 +166,7 @@
         diameter,
         diameter,
         cons_unit_id,
         cons_unit_id,
         update_time,
         update_time,
+        create_by,
         create_time,
         create_time,
         tenant_id
         tenant_id
         )
         )
@@ -186,6 +187,7 @@
             #{item.diameter},
             #{item.diameter},
             #{item.consUnitId},
             #{item.consUnitId},
             now(),
             now(),
+            #{item.createBy},
             now(),
             now(),
             #{item.tenantId})
             #{item.tenantId})
         </foreach>
         </foreach>

+ 1 - 0
bd-park/park-backend/park-core/src/main/resources/mapper/sys/SysCustConfigMapper.xml

@@ -30,6 +30,7 @@
             <if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
             <if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
             <if test="remark != null">remark = #{remark},</if>
             <if test="remark != null">remark = #{remark},</if>
             <if test="cfgJson != null">cfg_json = #{cfgJson},</if>
             <if test="cfgJson != null">cfg_json = #{cfgJson},</if>
+            <if test="tenantId  != null">tenant_id = #{tenantId},</if>
             update_time = sysdate()
             update_time = sysdate()
         </set>
         </set>
         where config_id = #{configId}
         where config_id = #{configId}

+ 73 - 87
bd-park/park-backend/park-infrastructure/src/main/java/com/huashe/park/infrastructure/cfg/mybatis/MybatisInterceptor.java

@@ -1,10 +1,9 @@
 package com.huashe.park.infrastructure.cfg.mybatis;
 package com.huashe.park.infrastructure.cfg.mybatis;
 
 
-import java.lang.reflect.Field;
+import java.util.Collection;
 import java.util.Date;
 import java.util.Date;
 
 
 import org.apache.ibatis.binding.MapperMethod;
 import org.apache.ibatis.binding.MapperMethod;
-import org.apache.ibatis.binding.MapperMethod.ParamMap;
 import org.apache.ibatis.executor.Executor;
 import org.apache.ibatis.executor.Executor;
 import org.apache.ibatis.mapping.MappedStatement;
 import org.apache.ibatis.mapping.MappedStatement;
 import org.apache.ibatis.mapping.SqlCommandType;
 import org.apache.ibatis.mapping.SqlCommandType;
@@ -16,7 +15,9 @@ import org.apache.ibatis.plugin.Signature;
 import org.slf4j.Logger;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.slf4j.LoggerFactory;
 import org.springframework.stereotype.Component;
 import org.springframework.stereotype.Component;
+import org.springframework.util.ReflectionUtils;
 
 
+import com.huashe.common.annotation.mybatis.TenantField;
 import com.ruoyi.common.core.domain.model.LoginUser;
 import com.ruoyi.common.core.domain.model.LoginUser;
 
 
 @Component
 @Component
@@ -34,111 +35,96 @@ public class MybatisInterceptor extends BaseInterceptor implements Interceptor {
         String sqlId = mappedStatement.getId();
         String sqlId = mappedStatement.getId();
         log.debug("------sqlId------" + sqlId);
         log.debug("------sqlId------" + sqlId);
         SqlCommandType sqlCommandType = mappedStatement.getSqlCommandType();
         SqlCommandType sqlCommandType = mappedStatement.getSqlCommandType();
-        Object parameter = invocation.getArgs()[1];
+        Object parameterObject = invocation.getArgs()[1];
         log.debug("------sqlCommandType------" + sqlCommandType);
         log.debug("------sqlCommandType------" + sqlCommandType);
 
 
-        if (parameter == null) {
+        if (parameterObject == null) {
             return invocation.proceed();
             return invocation.proceed();
         }
         }
-        if (SqlCommandType.INSERT == sqlCommandType) {
-            LoginUser sysUser = getLoginUser();
-            Field[] fields = getAllFields(parameter);
-            assert fields != null;
-            for (Field field : fields) {
-                try {
-                    if ("createBy".equals(field.getName())) {
-                        field.setAccessible(true);
-                        Object local_createBy = field.get(parameter);
-                        if (local_createBy == null || local_createBy.equals("")) {
-                            if (sysUser != null) {
-                                // 登录人账号
-                                field.set(parameter, sysUser.getUser().getNickName());
-                            }
-                        }
-                        field.setAccessible(false);
-                    }
-                    if ("createName".equals(field.getName())) {
-                        field.setAccessible(true);
-                        Object local_createBy = field.get(parameter);
-
-                        if (local_createBy == null || local_createBy.equals("")) {
-                            if (sysUser != null) {
-                                // 登录人账号
-                                field.set(parameter, sysUser.getUser().getNickName());
-                            }
-                        }
-                        field.setAccessible(false);
-                    }
-                    // 注入创建时间
-                    if ("createTime".equals(field.getName())) {
-                        field.setAccessible(true);
-                        Object local_createDate = field.get(parameter);
-
-                        if (local_createDate == null || local_createDate.equals("")) {
-                            field.set(parameter, new Date());
-                        }
-                        field.setAccessible(false);
-                    }
-
+        if (parameterObject instanceof MapperMethod.ParamMap) {
+            MapperMethod.ParamMap paramMap = (MapperMethod.ParamMap) parameterObject;
+            for (Object value : paramMap.values()) {
+                if (!(value instanceof Collection)) {
+                    continue;
                 }
                 }
-                catch (Exception e) {
-                    log.error("------MybatisInterceptor field.name------{},error:", field.getName(), e);
+                for (Object item : (Collection<?>) value) {
+                    injectCreateModifyInfo(item, sqlCommandType);
                 }
                 }
-                setTenantField(parameter, field);
             }
             }
-
         }
         }
-        if (SqlCommandType.UPDATE == sqlCommandType) {
-            LoginUser sysUser = this.getLoginUser();
-            Field[] fields = null;
-            if (parameter instanceof MapperMethod.ParamMap) {
-                MapperMethod.ParamMap<?> p = (ParamMap<?>) parameter;
-                // update-begin-author:scott date:20190729 for:批量更新报错issues/IZA3Q--
-                if (p.containsKey("et")) {
-                    parameter = p.get("arg0");
-                }
-                else if (p.containsKey("arg0")) {
-                    parameter = p.get("arg0");
-                }
-                else {
-                    parameter = p.get("param1");
-                }
-                // update-end-author:scott date:20190729 for:批量更新报错issues/IZA3Q-
-
-                // update-begin-author:scott date:20190729 for:更新指定字段时报错 issues/#516-
-                if (parameter == null) {
-                    return invocation.proceed();
-                }
-                // update-end-author:scott date:20190729 for:更新指定字段时报错 issues/#516-
-
-                fields = this.getAllFields(parameter);
+        // 处理集合类型参数(List/数组)
+        if (parameterObject instanceof Collection) {
+            for (Object item : (Collection<?>) parameterObject) {
+                injectCreateModifyInfo(item, sqlCommandType);
             }
             }
-            else {
-                fields = this.getAllFields(parameter);
+        }
+        else if (parameterObject.getClass().isArray()) {
+            for (Object item : (Object[]) parameterObject) {
+                injectCreateModifyInfo(item, sqlCommandType);
             }
             }
+        }
+        else {
+            injectCreateModifyInfo(parameterObject, sqlCommandType);
+        }
 
 
-            for (Field field : fields) {
+        return invocation.proceed();
+    }
+
+    private void injectCreateModifyInfo(Object target, SqlCommandType sqlCommandType) {
+        if (target == null) {
+            return;
+        }
+        LoginUser sysUser = getLoginUser();
+        if (SqlCommandType.INSERT == sqlCommandType) {
+            ReflectionUtils.doWithFields(target.getClass(), field -> {
                 field.setAccessible(true);
                 field.setAccessible(true);
-                try {
-                    if ("updateBy".equals(field.getName())) {
-                        // 获取登录用户信息
+                if (field.isAnnotationPresent(TenantField.class)) {
+                    field.set(target, sysUser.getUser().getTenantId());
+                }
+                if ("createBy".equals(field.getName())) {
+                    Object local_createBy = field.get(target);
+                    if (local_createBy == null || local_createBy.equals("")) {
+                        if (sysUser != null) {
+                            // 登录人账号
+                            field.set(target, sysUser.getUser().getNickName());
+                        }
+                    }
+                }
+                if ("createName".equals(field.getName())) {
+                    Object local_createBy = field.get(target);
+                    if (local_createBy == null || local_createBy.equals("")) {
                         if (sysUser != null) {
                         if (sysUser != null) {
-                            // 登录账号
-                            field.set(parameter, sysUser.getUser().getNickName());
+                            // 登录账号
+                            field.set(target, sysUser.getUser().getNickName());
                         }
                         }
                     }
                     }
-                    if ("updateTime".equals(field.getName())) {
-                        field.set(parameter, new Date());
+                }
+                // 注入创建时间
+                if ("createTime".equals(field.getName())) {
+                    Object local_createDate = field.get(target);
+                    if (local_createDate == null || local_createDate.equals("")) {
+                        field.set(target, new Date());
+                    }
+                }
+                field.setAccessible(false);
+            });
+        }
+        if (SqlCommandType.UPDATE == sqlCommandType) {
+            ReflectionUtils.doWithFields(target.getClass(), field -> {
+                field.setAccessible(true);
+                if ("updateBy".equals(field.getName())) {
+                    // 获取登录用户信息
+                    if (sysUser != null) {
+                        // 登录账号
+                        field.set(target, sysUser.getUser().getNickName());
                     }
                     }
                 }
                 }
-                catch (Exception e) {
-                    log.error("------ MybatisInterceptor field.name------{},error:", field.getName(), e);
+                if ("updateTime".equals(field.getName())) {
+                    field.set(target, new Date());
                 }
                 }
                 field.setAccessible(false);
                 field.setAccessible(false);
-                setTenantField(parameter, field);
-            }
+            });
         }
         }
-        return invocation.proceed();
     }
     }
 
 
     @Override
     @Override

+ 4 - 0
bd-park/park-backend/park-infrastructure/src/main/java/com/huashe/park/infrastructure/cfg/mybatis/RegisterCustomerInterceptor.java

@@ -20,6 +20,9 @@ public class RegisterCustomerInterceptor implements ApplicationListener<ContextR
     private TenantSqlInterceptor tenantSqlInterceptor;
     private TenantSqlInterceptor tenantSqlInterceptor;
 
 
     @Autowired
     @Autowired
+    private TenantIdInterceptor tenantIdInterceptor;
+
+    @Autowired
     private List<SqlSessionFactory> sqlSessionFactories;
     private List<SqlSessionFactory> sqlSessionFactories;
 
 
     @Override
     @Override
@@ -31,6 +34,7 @@ public class RegisterCustomerInterceptor implements ApplicationListener<ContextR
             // factory.getConfiguration().getTypeHandlerRegistry().register(new MySqlJsonHandler<>());
             // factory.getConfiguration().getTypeHandlerRegistry().register(new MySqlJsonHandler<>());
             // 由于mybatis拦截器使用责任链模式,有可能会导致自定义拦截器失效,因此下面方法可以将自定义拦截器重新注入到sql中
             // 由于mybatis拦截器使用责任链模式,有可能会导致自定义拦截器失效,因此下面方法可以将自定义拦截器重新注入到sql中
             factory.getConfiguration().addInterceptor(tenantSqlInterceptor);
             factory.getConfiguration().addInterceptor(tenantSqlInterceptor);
+            factory.getConfiguration().addInterceptor(tenantIdInterceptor);
             factory.getConfiguration().addInterceptor(mybatisInterceptor);
             factory.getConfiguration().addInterceptor(mybatisInterceptor);
             // factory.getConfiguration().addInterceptor(new FieldConvertInterceptor());
             // factory.getConfiguration().addInterceptor(new FieldConvertInterceptor());
         }
         }

+ 81 - 0
bd-park/park-backend/park-infrastructure/src/main/java/com/huashe/park/infrastructure/cfg/mybatis/TenantIdInterceptor.java

@@ -0,0 +1,81 @@
+package com.huashe.park.infrastructure.cfg.mybatis;
+
+import java.util.Collection;
+import java.util.Map;
+
+import org.apache.commons.lang3.ObjectUtils;
+import org.apache.ibatis.executor.Executor;
+import org.apache.ibatis.mapping.MappedStatement;
+import org.apache.ibatis.mapping.SqlCommandType;
+import org.apache.ibatis.plugin.Interceptor;
+import org.apache.ibatis.plugin.Intercepts;
+import org.apache.ibatis.plugin.Invocation;
+import org.apache.ibatis.plugin.Signature;
+import org.apache.ibatis.session.ResultHandler;
+import org.apache.ibatis.session.RowBounds;
+import org.springframework.stereotype.Component;
+import org.springframework.util.ReflectionUtils;
+
+import com.huashe.common.annotation.mybatis.TenantField;
+
+@Intercepts({
+    @Signature(type = Executor.class, method = "query", args = {
+        MappedStatement.class, Object.class, RowBounds.class, ResultHandler.class
+    })
+})
+@Component
+public class TenantIdInterceptor extends BaseInterceptor implements Interceptor {
+    @Override
+    public Object intercept(Invocation invocation) throws Throwable {
+        MappedStatement mappedStatement = (MappedStatement) invocation.getArgs()[0];
+        SqlCommandType sqlCommandType = mappedStatement.getSqlCommandType();
+        Object parameterObject = invocation.getArgs()[1];
+        Long tenantId = getLoginUser().getUser().getTenantId();
+        // 无租户 ID 或无参数对象直接跳过
+        if (sqlCommandType != SqlCommandType.SELECT || ObjectUtils.isEmpty(tenantId)
+            || ObjectUtils.isEmpty(parameterObject)) {
+            return invocation.proceed();
+        }
+
+        // 处理集合类型参数(List/数组)
+        if (parameterObject instanceof Collection) {
+            for (Object item : (Collection<?>) parameterObject) {
+                injectTenantId(item, tenantId);
+            }
+        }
+        else if (parameterObject.getClass().isArray()) {
+            for (Object item : (Object[]) parameterObject) {
+                injectTenantId(item, tenantId);
+            }
+        }
+        else {
+            injectTenantId(parameterObject, tenantId);
+        }
+
+        return invocation.proceed();
+    }
+
+    // 公共注入逻辑
+    private void injectTenantId(Object target, Long tenantId) {
+        if (target == null)
+            return;
+
+        // 处理 Map 类型
+        if (target instanceof Map) {
+            Map<?, ?> map = (Map<?, ?>) target;
+            if (!map.containsKey("tenantId")) {
+                ((Map<String, Object>) map).put("tenantId", tenantId);
+            }
+        }
+        // 处理实体对象
+        else {
+            ReflectionUtils.doWithFields(target.getClass(), field -> {
+                if (field.isAnnotationPresent(TenantField.class)) {
+                    field.setAccessible(true);
+                    field.set(target, getLoginUser().getUser().getTenantId());
+                    field.setAccessible(false);
+                }
+            });
+        }
+    }
+}

+ 2 - 4
bd-park/park-backend/park-infrastructure/src/main/java/com/huashe/park/infrastructure/cfg/mybatis/TenantSqlInterceptor.java

@@ -16,8 +16,10 @@ import org.apache.ibatis.plugin.Signature;
 import org.apache.ibatis.reflection.MetaObject;
 import org.apache.ibatis.reflection.MetaObject;
 import org.apache.ibatis.reflection.SystemMetaObject;
 import org.apache.ibatis.reflection.SystemMetaObject;
 import org.springframework.stereotype.Component;
 import org.springframework.stereotype.Component;
+import org.springframework.util.ReflectionUtils;
 
 
 import com.huashe.common.annotation.mybatis.Tenant;
 import com.huashe.common.annotation.mybatis.Tenant;
+import com.huashe.common.annotation.mybatis.TenantField;
 import com.huashe.park.common.animations.mybatis.MethodMetadataCache;
 import com.huashe.park.common.animations.mybatis.MethodMetadataCache;
 
 
 import net.sf.jsqlparser.expression.Expression;
 import net.sf.jsqlparser.expression.Expression;
@@ -118,8 +120,4 @@ public class TenantSqlInterceptor extends BaseInterceptor implements Interceptor
     @Override
     @Override
     public void setProperties(Properties properties) {
     public void setProperties(Properties properties) {
     }
     }
-
-    public static void main(String[] args) {
-
-    }
 }
 }

+ 83 - 71
common-application/ruoyi-system/src/main/resources/mapper/system/SysConfigMapper.xml

@@ -1,96 +1,105 @@
 <?xml version="1.0" encoding="UTF-8" ?>
 <?xml version="1.0" encoding="UTF-8" ?>
 <!DOCTYPE mapper
 <!DOCTYPE mapper
-PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
-"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.ruoyi.system.mapper.SysConfigMapper">
 <mapper namespace="com.ruoyi.system.mapper.SysConfigMapper">
-    
+
     <resultMap type="SysConfig" id="SysConfigResult">
     <resultMap type="SysConfig" id="SysConfigResult">
-    	<id     property="configId"      column="config_id"      />
-        <result property="configName"    column="config_name"    />
-        <result property="configKey"     column="config_key"     />
-        <result property="configValue"   column="config_value"   />
-        <result property="configType"    column="config_type"    />
-        <result property="createBy"      column="create_by"      />
-        <result property="createTime"    column="create_time"    />
-        <result property="updateBy"      column="update_by"      />
-        <result property="updateTime"    column="update_time"    />
+        <id property="configId" column="config_id"/>
+        <result property="configName" column="config_name"/>
+        <result property="configKey" column="config_key"/>
+        <result property="configValue" column="config_value"/>
+        <result property="configType" column="config_type"/>
+        <result property="createBy" column="create_by"/>
+        <result property="createTime" column="create_time"/>
+        <result property="updateBy" column="update_by"/>
+        <result property="updateTime" column="update_time"/>
+        <result property="tenantId" column="tenant_id"/>
     </resultMap>
     </resultMap>
-    
+
     <sql id="selectConfigVo">
     <sql id="selectConfigVo">
-        select config_id, config_name, config_key, config_value, config_type, create_by, create_time, update_by, update_time, remark 
-		from sys_config
+        select *
+        from sys_config
     </sql>
     </sql>
-    
+
     <!-- 查询条件 -->
     <!-- 查询条件 -->
-	<sql id="sqlwhereSearch">
-		<where>
-			<if test="configId !=null">
-				and config_id = #{configId}
-			</if>
-			<if test="configKey !=null and configKey != ''">
-				and config_key = #{configKey}
-			</if>
-		</where>
-	</sql>
-    
+    <sql id="sqlwhereSearch">
+        <where>
+            <if test="configId !=null">
+                and config_id = #{configId}
+            </if>
+            <if test="configKey !=null and configKey != ''">
+                and config_key = #{configKey}
+            </if>
+        </where>
+    </sql>
+
     <select id="selectConfig" parameterType="SysConfig" resultMap="SysConfigResult">
     <select id="selectConfig" parameterType="SysConfig" resultMap="SysConfigResult">
         <include refid="selectConfigVo"/>
         <include refid="selectConfigVo"/>
         <include refid="sqlwhereSearch"/>
         <include refid="sqlwhereSearch"/>
     </select>
     </select>
-    
+
     <select id="selectConfigList" parameterType="SysConfig" resultMap="SysConfigResult">
     <select id="selectConfigList" parameterType="SysConfig" resultMap="SysConfigResult">
         <include refid="selectConfigVo"/>
         <include refid="selectConfigVo"/>
         <where>
         <where>
-			<if test="configName != null and configName != ''">
-				AND config_name like concat('%', #{configName}, '%')
-			</if>
-			<if test="configType != null and configType != ''">
-				AND config_type = #{configType}
-			</if>
-			<if test="configKey != null and configKey != ''">
-				AND config_key like concat('%', #{configKey}, '%')
-			</if>
-			<if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 -->
-				and date_format(create_time,'%Y%m%d') &gt;= date_format(#{params.beginTime},'%Y%m%d')
-			</if>
-			<if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 -->
-				and date_format(create_time,'%Y%m%d') &lt;= date_format(#{params.endTime},'%Y%m%d')
-			</if>
-		</where>
+            <if test="configName != null and configName != ''">
+                AND config_name like concat('%', #{configName}, '%')
+            </if>
+            <if test="configType != null and configType != ''">
+                AND config_type = #{configType}
+            </if>
+            <if test="configKey != null and configKey != ''">
+                AND config_key like concat('%', #{configKey}, '%')
+            </if>
+            <if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 -->
+                and date_format(create_time,'%Y%m%d') &gt;= date_format(#{params.beginTime},'%Y%m%d')
+            </if>
+            <if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 -->
+                and date_format(create_time,'%Y%m%d') &lt;= date_format(#{params.endTime},'%Y%m%d')
+            </if>
+            <if test="params.configName != null and params.configName != ''">
+                and config_name like concat('%', #{params.configName}, '%')
+            </if>
+            <if test="tenantId  != null and tenantId != ''">
+                and (tenant_id is null or tenant_id = #{tenantId})
+            </if>
+        </where>
     </select>
     </select>
-    
+
     <select id="selectConfigById" parameterType="Long" resultMap="SysConfigResult">
     <select id="selectConfigById" parameterType="Long" resultMap="SysConfigResult">
         <include refid="selectConfigVo"/>
         <include refid="selectConfigVo"/>
         where config_id = #{configId}
         where config_id = #{configId}
     </select>
     </select>
-	
+
     <select id="checkConfigKeyUnique" parameterType="String" resultMap="SysConfigResult">
     <select id="checkConfigKeyUnique" parameterType="String" resultMap="SysConfigResult">
         <include refid="selectConfigVo"/>
         <include refid="selectConfigVo"/>
         where config_key = #{configKey} limit 1
         where config_key = #{configKey} limit 1
     </select>
     </select>
-    
+
     <insert id="insertConfig" parameterType="SysConfig">
     <insert id="insertConfig" parameterType="SysConfig">
         insert into sys_config (
         insert into sys_config (
-			<if test="configName != null and configName != '' ">config_name,</if>
-			<if test="configKey != null and configKey != '' ">config_key,</if>
-			<if test="configValue != null and configValue != '' ">config_value,</if>
-			<if test="configType != null and configType != '' ">config_type,</if>
-			<if test="createBy != null and createBy != ''">create_by,</if>
-			<if test="remark != null and remark != ''">remark,</if>
- 			create_time
+        <if test="configName != null and configName != '' ">config_name,</if>
+        <if test="configKey != null and configKey != '' ">config_key,</if>
+        <if test="configValue != null and configValue != '' ">config_value,</if>
+        <if test="configType != null and configType != '' ">config_type,</if>
+        <if test="createBy != null and createBy != ''">create_by,</if>
+        <if test="remark != null and remark != ''">remark,</if>
+        <if test="configType != 'Y' and tenantId != null and tenantId != ''">tenant_id,</if>
+        create_time
         )values(
         )values(
-			<if test="configName != null and configName != ''">#{configName},</if>
-			<if test="configKey != null and configKey != ''">#{configKey},</if>
-			<if test="configValue != null and configValue != ''">#{configValue},</if>
-			<if test="configType != null and configType != ''">#{configType},</if>
-			<if test="createBy != null and createBy != ''">#{createBy},</if>
-			<if test="remark != null and remark != ''">#{remark},</if>
- 			sysdate()
-		)
+        <if test="configName != null and configName != ''">#{configName},</if>
+        <if test="configKey != null and configKey != ''">#{configKey},</if>
+        <if test="configValue != null and configValue != ''">#{configValue},</if>
+        <if test="configType != null and configType != ''">#{configType},</if>
+        <if test="createBy != null and createBy != ''">#{createBy},</if>
+        <if test="remark != null and remark != ''">#{remark},</if>
+        <if test="configType != 'Y' and tenantId != null and tenantId != ''">#{tenantId},</if>
+        sysdate()
+        )
     </insert>
     </insert>
-	 
+
     <update id="updateConfig" parameterType="SysConfig">
     <update id="updateConfig" parameterType="SysConfig">
-        update sys_config 
+        update sys_config
         <set>
         <set>
             <if test="configName != null and configName != ''">config_name = #{configName},</if>
             <if test="configName != null and configName != ''">config_name = #{configName},</if>
             <if test="configKey != null and configKey != ''">config_key = #{configKey},</if>
             <if test="configKey != null and configKey != ''">config_key = #{configKey},</if>
@@ -98,20 +107,23 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="configType != null and configType != ''">config_type = #{configType},</if>
             <if test="configType != null and configType != ''">config_type = #{configType},</if>
             <if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
             <if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
             <if test="remark != null">remark = #{remark},</if>
             <if test="remark != null">remark = #{remark},</if>
- 			update_time = sysdate()
+            <if test="configType != 'Y' and tenantId != null and tenantId != ''">tenant_id = #{tenantId},</if>
+            update_time = sysdate()
         </set>
         </set>
         where config_id = #{configId}
         where config_id = #{configId}
     </update>
     </update>
-	
+
     <delete id="deleteConfigById" parameterType="Long">
     <delete id="deleteConfigById" parameterType="Long">
-        delete from sys_config where config_id = #{configId}
+        delete
+        from sys_config
+        where config_id = #{configId}
     </delete>
     </delete>
-    
+
     <delete id="deleteConfigByIds" parameterType="Long">
     <delete id="deleteConfigByIds" parameterType="Long">
-        delete from sys_config where config_id in 
+        delete from sys_config where config_id in
         <foreach item="configId" collection="array" open="(" separator="," close=")">
         <foreach item="configId" collection="array" open="(" separator="," close=")">
-        	#{configId}
+            #{configId}
         </foreach>
         </foreach>
     </delete>
     </delete>
-    
+
 </mapper>
 </mapper>