diff --git a/pom.xml b/pom.xml index 546497ef4..6c61f6566 100644 --- a/pom.xml +++ b/pom.xml @@ -873,6 +873,13 @@ fastjson2 2.0.40 + + + + com.alibaba + transmittable-thread-local + 2.11.4 + @@ -970,11 +977,36 @@ <!–CustomClassLoader;WisdomSiteApplication;LicenseUtil;MyBootJarLauncher;MyJarClassLoader–> --> + + net.roseboy + classfinal-maven-plugin + 1.2.1 + + # + com.zhgd,com.license,com.zhwl,com.wflow + application.properties,application-dev.properties,application-gsx-other-env-show.properties + org.spring + wflow-server-1.0-SNAPSHOT.jar + C406DC319C9AF811C5DC9A84CE0DBF2CD41D8CD98F00B204E9800998ECF8427ED41D8CD98F00B204E9800998ECF8427E + + + + package + + classFinal + + + + src/main/resources - false + + **/*.properties + **/*.xml + + src/main/java diff --git a/src/main/java/com/zhgd/config/DataSourceOneConfig.java b/src/main/java/com/zhgd/config/DataSourceOneConfig.java index fcb59695e..547e491c4 100644 --- a/src/main/java/com/zhgd/config/DataSourceOneConfig.java +++ b/src/main/java/com/zhgd/config/DataSourceOneConfig.java @@ -1,6 +1,9 @@ package com.zhgd.config; +import com.baomidou.mybatisplus.annotation.DbType; import com.baomidou.mybatisplus.core.MybatisConfiguration; +import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor; +import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor; import com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean; import com.wflow.config.MyBatisPlusConfig; import org.apache.ibatis.logging.stdout.StdOutImpl; @@ -23,8 +26,6 @@ import javax.sql.DataSource; @Configuration @MapperScan(basePackages = {"com.zhgd.*.*.*.*.mapper", "com.zhgd.*.*.*.mapper"}, sqlSessionTemplateRef = "db1SqlSessionTemplate") public class DataSourceOneConfig { - @Resource - private MybatisPlusConfig mybatisPlusConfig; @Bean @ConfigurationProperties(prefix = "spring.datasource.db1") @@ -43,7 +44,9 @@ public class DataSourceOneConfig { configuration.setLogImpl(StdOutImpl.class); bean.setConfiguration(configuration); bean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath*:com/zhgd/xmgl/**/*.xml")); - bean.setPlugins(mybatisPlusConfig.mybatisPlusInterceptor()); + MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor(); + interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL)); + bean.setPlugins(interceptor); return bean.getObject(); } diff --git a/src/main/java/com/zhgd/config/DataSourceTwoConfig.java b/src/main/java/com/zhgd/config/DataSourceTwoConfig.java index 5b06a0db6..dec1c7881 100644 --- a/src/main/java/com/zhgd/config/DataSourceTwoConfig.java +++ b/src/main/java/com/zhgd/config/DataSourceTwoConfig.java @@ -1,12 +1,18 @@ package com.zhgd.config; +import com.baomidou.mybatisplus.annotation.DbType; import com.baomidou.mybatisplus.core.MybatisConfiguration; +import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor; +import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor; +import com.baomidou.mybatisplus.extension.plugins.inner.TenantLineInnerInterceptor; import com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean; +import com.zhgd.xmgl.tenant.TenantHandler; import org.apache.ibatis.logging.stdout.StdOutImpl; import org.apache.ibatis.session.SqlSessionFactory; import org.mybatis.spring.SqlSessionTemplate; import org.mybatis.spring.annotation.MapperScan; import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.jdbc.DataSourceBuilder; import org.springframework.context.annotation.Bean; @@ -21,8 +27,6 @@ import javax.sql.DataSource; @Configuration @MapperScan(basePackages = "com.wflow.mapper", sqlSessionTemplateRef = "sqlSessionTemplate2") public class DataSourceTwoConfig { - @Resource - private MybatisPlusConfig mybatisPlusConfig; @Primary @Bean(name = "dataSource2") @@ -41,8 +45,13 @@ public class DataSourceTwoConfig { configuration.setMapUnderscoreToCamelCase(true); configuration.setLogImpl(StdOutImpl.class); bean.setConfiguration(configuration); - bean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath*:mapper/*.xml")); - bean.setPlugins(mybatisPlusConfig.mybatisPlusInterceptor()); + bean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath*:com/wflow/**/*.xml")); + MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor(); + TenantLineInnerInterceptor tenantLineInnerInterceptor = new TenantLineInnerInterceptor(); + tenantLineInnerInterceptor.setTenantLineHandler(tenantHandler()); + interceptor.addInnerInterceptor(tenantLineInnerInterceptor); + interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL)); + bean.setPlugins(interceptor); return bean.getObject(); } @@ -55,4 +64,10 @@ public class DataSourceTwoConfig { public SqlSessionTemplate sqlSessionTemplate(@Qualifier("sqlSessionFactory2") SqlSessionFactory sqlSessionFactory) throws Exception { return new SqlSessionTemplate(sqlSessionFactory); } + + @Bean + @ConditionalOnMissingBean + public TenantHandler tenantHandler() { + return new TenantHandler(); + } } diff --git a/src/main/java/com/zhgd/config/MybatisPlusConfig.java b/src/main/java/com/zhgd/config/MybatisPlusConfig.java index e39300f79..b6b326f21 100644 --- a/src/main/java/com/zhgd/config/MybatisPlusConfig.java +++ b/src/main/java/com/zhgd/config/MybatisPlusConfig.java @@ -1,59 +1,64 @@ -package com.zhgd.config; - - -import com.baomidou.mybatisplus.annotation.DbType; -import com.baomidou.mybatisplus.autoconfigure.ConfigurationCustomizer; -import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor; -import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - +//package com.zhgd.config; +// +// +//import com.baomidou.mybatisplus.annotation.DbType; //import com.baomidou.mybatisplus.autoconfigure.ConfigurationCustomizer; - -/** - * Mybatis-Plus进行分页 - * 返回的数据中total总是为0问题 - */ -@Configuration -public class MybatisPlusConfig { - /** - * mybatis-plus分页插件 - */ - /*@Bean - public PaginationInterceptor paginationInterceptor() { - PaginationInterceptor page = new PaginationInterceptor(); - return page; - }*/ - - /** - * 新的分页插件,一缓和二缓遵循mybatis的规则,需要设置 MybatisConfiguration#useDeprecatedExecutor = false 避免缓存出现问题 - */ - @Bean - public MybatisPlusInterceptor mybatisPlusInterceptor() { - MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor(); - interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL)); - return interceptor; - } - - @Bean - public ConfigurationCustomizer configurationCustomizer() { - return configuration -> configuration.setUseDeprecatedExecutor(false); - - } - - - - - - - - - - - - - - - - -} \ No newline at end of file +//import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor; +//import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor; +//import com.baomidou.mybatisplus.extension.plugins.inner.TenantLineInnerInterceptor; +//import com.zhgd.xmgl.tenant.TenantHandler; +//import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +//import org.springframework.context.annotation.Bean; +//import org.springframework.context.annotation.Configuration; +// +////import com.baomidou.mybatisplus.autoconfigure.ConfigurationCustomizer; +// +///** +// * Mybatis-Plus进行分页 +// * 返回的数据中total总是为0问题 +// */ +//@Configuration +//public class MybatisPlusConfig { +// /** +// * mybatis-plus分页插件 +// */ +// /*@Bean +// public PaginationInterceptor paginationInterceptor() { +// PaginationInterceptor page = new PaginationInterceptor(); +// return page; +// }*/ +// +// /** +// * 新的分页插件,一缓和二缓遵循mybatis的规则,需要设置 MybatisConfiguration#useDeprecatedExecutor = false 避免缓存出现问题 +// */ +// @Bean +// public MybatisPlusInterceptor mybatisPlusInterceptor() { +// MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor(); +// interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL)); +// return interceptor; +// } +// +// @Bean +// public ConfigurationCustomizer configurationCustomizer() { +// return configuration -> configuration.setUseDeprecatedExecutor(false); +// +// } +// +// +// +// +// +// +// +// +// +// +// +// +// +// +// +// +// +// +//} \ No newline at end of file diff --git a/src/main/java/com/zhgd/xmgl/modules/basicdata/mapper/SystemUserMapper.java b/src/main/java/com/zhgd/xmgl/modules/basicdata/mapper/SystemUserMapper.java index 93ff34085..8df030412 100644 --- a/src/main/java/com/zhgd/xmgl/modules/basicdata/mapper/SystemUserMapper.java +++ b/src/main/java/com/zhgd/xmgl/modules/basicdata/mapper/SystemUserMapper.java @@ -67,9 +67,9 @@ public interface SystemUserMapper extends BaseMapper { * @param deptId 部门ID * @return 用户列表 type为固定值user */ - @Select("SELECT user_id id, real_name `name`, 'user' AS 'type', avatar " + - "FROM system_user" + - " WHERE xz_project_org_id = #{deptId} AND account_type = 6") + @Select("SELECT u.user_id id, w.worker_name `name`, 'user' AS 'type', u.avatar " + + "FROM system_user u left join worker_info w on u.worker_id = w.id " + + "WHERE u.xz_project_org_id = #{deptId} AND u.account_type = 6") List selectUsersByDept(@Param("deptId") String deptId); /** @@ -95,6 +95,16 @@ public interface SystemUserMapper extends BaseMapper { ""}) List getUserDepInfosBatch(@Param("list") Collection udIds); + /** + * 通过拼音搜索用户,全拼和拼音首字母模糊搜索 + * @param py 拼音 + * @return 搜索的用户列表 type为固定值user + */ + @Select("SELECT u.user_id id, w.worker_name `name`, 'user' AS 'type', u.avatar FROM system_user u " + + "left join worker_info w on u.worker_id = w.id " + + " WHERE w.worker_name LIKE '%${py}%'") + List selectUsersByPy(@Param("py") String py); + Page getSystemUserBySn(@Param("p") Map map, Page page); Page getTenantListBySn(@Param("map") Map map, Page page); diff --git a/src/main/java/com/zhgd/xmgl/modules/basicdata/service/impl/FlowOrgRepositoryServiceImpl.java b/src/main/java/com/zhgd/xmgl/modules/basicdata/service/impl/FlowOrgRepositoryServiceImpl.java index f1a6f84f4..c1a88a5fc 100644 --- a/src/main/java/com/zhgd/xmgl/modules/basicdata/service/impl/FlowOrgRepositoryServiceImpl.java +++ b/src/main/java/com/zhgd/xmgl/modules/basicdata/service/impl/FlowOrgRepositoryServiceImpl.java @@ -17,6 +17,7 @@ import com.wflow.bean.vo.UserVo; import com.wflow.mapper.WflowModelPermsMapper; import com.wflow.mapper.WflowModelsMapper; import com.wflow.service.OrgRepositoryService; +import com.zhgd.xmgl.modules.basicdata.entity.BaseRole; import com.zhgd.xmgl.modules.basicdata.entity.BaseRoleUser; import com.zhgd.xmgl.modules.basicdata.entity.Company; import com.zhgd.xmgl.modules.basicdata.entity.SystemUser; @@ -24,6 +25,11 @@ import com.zhgd.xmgl.modules.basicdata.mapper.BaseRoleMapper; import com.zhgd.xmgl.modules.basicdata.mapper.BaseRoleUserMapper; import com.zhgd.xmgl.modules.basicdata.mapper.CompanyMapper; import com.zhgd.xmgl.modules.basicdata.mapper.SystemUserMapper; +import com.zhgd.xmgl.modules.project.entity.ProjectEnterprise; +import com.zhgd.xmgl.modules.project.mapper.ProjectEnterpriseMapper; +import com.zhgd.xmgl.modules.worker.mapper.DepartmentInfoMapper; +import com.zhgd.xmgl.modules.worker.mapper.EnterpriseInfoMapper; +import com.zhgd.xmgl.modules.worker.mapper.TeamInfoMapper; import com.zhgd.xmgl.modules.xz.entity.XzProjectOrg; import com.zhgd.xmgl.modules.xz.mapper.XzProjectOrgMapper; import com.zhgd.xmgl.security.util.SecurityUtils; @@ -56,6 +62,15 @@ public class FlowOrgRepositoryServiceImpl implements OrgRepositoryService { @Autowired private WflowModelsMapper wflowModelsMapper; + @Autowired + private TeamInfoMapper teamInfoMapper; + + @Autowired + private DepartmentInfoMapper departmentInfoMapper; + + @Autowired + private EnterpriseInfoMapper enterpriseInfoMapper; + @Override public List getModelsByPerm(String userId) { List list = new ArrayList<>(); @@ -112,7 +127,7 @@ public class FlowOrgRepositoryServiceImpl implements OrgRepositoryService { @Override public List selectUsersByPy(String py) { - return null; + return systemUserMapper.selectUsersByPy(py); } @Override @@ -214,9 +229,9 @@ public class FlowOrgRepositoryServiceImpl implements OrgRepositoryService { } @Override - public List getSysAllRoles() { + public List getSysAllRoles(String projectSn) { try { - return systemRoleMapper.selectList(null).stream() + return systemRoleMapper.selectList(Wrappers.lambdaQuery().eq(BaseRole::getProjectSn, projectSn)).stream() .map(r -> new RoleDo(r.getRoleId().toString(), r.getRoleName())) .collect(Collectors.toList()); } catch (Exception e) { @@ -225,11 +240,12 @@ public class FlowOrgRepositoryServiceImpl implements OrgRepositoryService { } @Override - public Set getUsersByRoles(List roles) { - return baseRoleUserMapper.selectList(new LambdaQueryWrapper() - .select(BaseRoleUser::getUserId) + public Set getUsersByRoles(List roles, String projectSn) { + Set userIds = baseRoleUserMapper.selectList(new LambdaQueryWrapper() .in(BaseRoleUser::getRoleId, roles)).stream() - .map(Object::toString).collect(Collectors.toSet()); + .map(u -> u.getUserId()).collect(Collectors.toSet()); + return systemUserMapper.selectList(Wrappers.lambdaQuery().in(SystemUser::getUserId, userIds).eq(SystemUser::getSn, projectSn)) + .stream().map(u -> u.getUserId().toString()).collect(Collectors.toSet()); } @Override @@ -252,4 +268,19 @@ public class FlowOrgRepositoryServiceImpl implements OrgRepositoryService { return systemUserMapper.getUserDepInfosBatch(userDeptIds) .stream().collect(Collectors.toMap(UserDeptDo::getUserId, v -> v)); } + + @Override + public List getEnterpriseById(String parentId) { + int p = parentId.indexOf("P"); + String id = parentId.substring(0, p); + String projectSn = parentId.substring(p + 1); + List orgTreeVos = new ArrayList<>(); + if (id.equals("0")) { + orgTreeVos = enterpriseInfoMapper.selectByProject(projectSn); + } else { + orgTreeVos = teamInfoMapper.selectByEnterprise(id, projectSn); + orgTreeVos.addAll(departmentInfoMapper.selectByEnterprise(id, projectSn)); + } + return orgTreeVos; + } } diff --git a/src/main/java/com/zhgd/xmgl/modules/worker/mapper/DepartmentInfoMapper.java b/src/main/java/com/zhgd/xmgl/modules/worker/mapper/DepartmentInfoMapper.java index bdfd36c2c..0c30a14d1 100644 --- a/src/main/java/com/zhgd/xmgl/modules/worker/mapper/DepartmentInfoMapper.java +++ b/src/main/java/com/zhgd/xmgl/modules/worker/mapper/DepartmentInfoMapper.java @@ -3,6 +3,7 @@ package com.zhgd.xmgl.modules.worker.mapper; import java.util.List; import java.util.Map; +import com.wflow.bean.vo.OrgTreeVo; import com.zhgd.jeecg.common.mybatis.EntityMap; import com.zhgd.xmgl.modules.gt.entity.GtMaterialInOutWarehouse; import com.zhgd.xmgl.modules.worker.entity.DepartmentInfo; @@ -10,6 +11,7 @@ import org.apache.ibatis.annotations.MapKey; import org.apache.ibatis.annotations.Mapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import org.apache.ibatis.annotations.Param; +import org.apache.ibatis.annotations.Select; import org.springframework.stereotype.Repository; /** @@ -38,4 +40,11 @@ public interface DepartmentInfoMapper extends BaseMapper { EntityMap getDepartmentInfo(@Param("departmentId") Long departmentId); List queryDepartmentAndTeamList(Map map); + + /** + * 查询企业下的部门信息 + * + */ + @Select("SELECT id id, department_name `name`, 'enterprise' AS 'type' FROM department_info WHERE enterprise_id = #{enterpriseId} AND project_sn = #{projectSn}") + List selectByEnterprise(@Param("enterpriseId") String enterpriseId, @Param("projectSn") String projectSn); } diff --git a/src/main/java/com/zhgd/xmgl/modules/worker/mapper/EnterpriseInfoMapper.java b/src/main/java/com/zhgd/xmgl/modules/worker/mapper/EnterpriseInfoMapper.java index acc5de0cc..f17fd3bf7 100644 --- a/src/main/java/com/zhgd/xmgl/modules/worker/mapper/EnterpriseInfoMapper.java +++ b/src/main/java/com/zhgd/xmgl/modules/worker/mapper/EnterpriseInfoMapper.java @@ -3,10 +3,12 @@ package com.zhgd.xmgl.modules.worker.mapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.wflow.bean.vo.OrgTreeVo; import com.zhgd.jeecg.common.mybatis.EntityMap; import com.zhgd.xmgl.modules.worker.entity.EnterpriseInfo; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; +import org.apache.ibatis.annotations.Select; import java.util.List; import java.util.Map; @@ -43,4 +45,12 @@ public interface EnterpriseInfoMapper extends BaseMapper { EnterpriseInfo getXzSupplierBySocialCode(Map map); List getAllXzSupplierList(Map map); + + /** + * 查询项目下的企业信息 + * + */ + @Select("SELECT e.id id, e.enterprise_name `name`, 'enterprise' AS 'type' FROM enterprise_info e " + + "LEFT JOIN project_enterprise p ON e.id = p.enterprise_id WHERE p.project_sn = #{projectSn}") + List selectByProject(@Param("projectSn") String projectSn); } diff --git a/src/main/java/com/zhgd/xmgl/modules/worker/mapper/TeamInfoMapper.java b/src/main/java/com/zhgd/xmgl/modules/worker/mapper/TeamInfoMapper.java index cfba1e766..3a052e0b4 100644 --- a/src/main/java/com/zhgd/xmgl/modules/worker/mapper/TeamInfoMapper.java +++ b/src/main/java/com/zhgd/xmgl/modules/worker/mapper/TeamInfoMapper.java @@ -5,6 +5,7 @@ import java.util.Map; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.wflow.bean.vo.OrgTreeVo; import com.zhgd.jeecg.common.mybatis.EntityMap; import com.zhgd.xmgl.modules.basicdata.entity.DictionariesRecord; import com.zhgd.xmgl.modules.worker.entity.TeamInfo; @@ -13,6 +14,7 @@ import org.apache.ibatis.annotations.MapKey; import org.apache.ibatis.annotations.Mapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import org.apache.ibatis.annotations.Param; +import org.apache.ibatis.annotations.Select; /** * @Description: 人员班组 @@ -41,4 +43,11 @@ public interface TeamInfoMapper extends BaseMapper { List selectTeamDetailsList(Map map); IPage getGroup(Page page,@Param("q") Map map); + + /** + * 查询企业下的班组信息 + * + */ + @Select("SELECT id id, team_name `name`, 'enterprise' AS 'type' FROM team_info WHERE enterprise_id = #{enterpriseId} AND project_sn = #{projectSn}") + List selectByEnterprise(@Param("enterpriseId") String enterpriseId, @Param("projectSn") String projectSn); } diff --git a/src/main/java/com/zhgd/xmgl/security/JwtTokenFilter.java b/src/main/java/com/zhgd/xmgl/security/JwtTokenFilter.java index a0f2c5560..46fe56a02 100644 --- a/src/main/java/com/zhgd/xmgl/security/JwtTokenFilter.java +++ b/src/main/java/com/zhgd/xmgl/security/JwtTokenFilter.java @@ -7,6 +7,7 @@ import com.zhgd.xmgl.entity.sj.JwtPayloadUserInfo; import com.zhgd.xmgl.entity.sj.TokenResponse; import com.zhgd.xmgl.modules.basicdata.entity.SystemUser; import com.zhgd.xmgl.modules.basicdata.mapper.SystemUserMapper; +import com.zhgd.xmgl.tenant.TenantContextHolder; import com.zhgd.xmgl.util.EnvironmentUtil; import com.zhgd.xmgl.util.sj.JwtRsaUtils; import com.zhgd.xmgl.util.sj.SjUnifiedAuthenticationHttpUtil; @@ -77,6 +78,7 @@ public class JwtTokenFilter extends OncePerRequestFilter { } else { validateOtherProfile(request); + TenantContextHolder.setTenantId(request.getHeader("TenantId")); } } filterChain.doFilter(request, response); diff --git a/src/main/java/com/zhgd/xmgl/tenant/TenantConfigProperties.java b/src/main/java/com/zhgd/xmgl/tenant/TenantConfigProperties.java new file mode 100644 index 000000000..fdf36e4d7 --- /dev/null +++ b/src/main/java/com/zhgd/xmgl/tenant/TenantConfigProperties.java @@ -0,0 +1,28 @@ +package com.zhgd.xmgl.tenant; + +import lombok.Data; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Configuration; + +import java.util.ArrayList; +import java.util.List; + +/** + * 项目配置 + */ +@Data +@Configuration +@ConfigurationProperties(prefix = "tenant") +public class TenantConfigProperties { + + /** + * 维护项目列名称 + */ + private String column = "tenant_id"; + + /** + * 忽略项目权限的数据表集合 + */ + private List tables = new ArrayList<>(); + +} diff --git a/src/main/java/com/zhgd/xmgl/tenant/TenantContextHolder.java b/src/main/java/com/zhgd/xmgl/tenant/TenantContextHolder.java new file mode 100644 index 000000000..e93624261 --- /dev/null +++ b/src/main/java/com/zhgd/xmgl/tenant/TenantContextHolder.java @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2018-2025, clinical All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: clinical + */ + +package com.zhgd.xmgl.tenant; + +import com.alibaba.ttl.TransmittableThreadLocal; +import lombok.experimental.UtilityClass; + +@UtilityClass +public class TenantContextHolder { + + private final ThreadLocal THREAD_LOCAL_TENANT = new TransmittableThreadLocal<>(); + + public void setTenantId(String tenantId) { + THREAD_LOCAL_TENANT.set(tenantId); + } + + public String getTenantId() { + return THREAD_LOCAL_TENANT.get(); + } + + + public void clear() { + THREAD_LOCAL_TENANT.remove(); + } +} diff --git a/src/main/java/com/zhgd/xmgl/tenant/TenantHandler.java b/src/main/java/com/zhgd/xmgl/tenant/TenantHandler.java new file mode 100644 index 000000000..af8df329a --- /dev/null +++ b/src/main/java/com/zhgd/xmgl/tenant/TenantHandler.java @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2018-2025, clinical All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: clinical + */ + +package com.zhgd.xmgl.tenant; + +import com.baomidou.mybatisplus.extension.plugins.handler.TenantLineHandler; +import lombok.extern.slf4j.Slf4j; +import net.sf.jsqlparser.expression.Expression; +import net.sf.jsqlparser.expression.LongValue; +import net.sf.jsqlparser.expression.NullValue; +import net.sf.jsqlparser.expression.StringValue; +import org.springframework.beans.factory.annotation.Autowired; + +@Slf4j +public class TenantHandler implements TenantLineHandler { + + @Autowired + private TenantConfigProperties properties; + + @Override + public Expression getTenantId() { + String tenantId = TenantContextHolder.getTenantId(); + log.debug("当前项目为 >> {}", tenantId); + + if (tenantId == null) { + return new NullValue(); + } + return new StringValue(tenantId); + } + + @Override + public String getTenantIdColumn() { + return properties.getColumn(); + } + + @Override + public boolean ignoreTable(String tableName) { + String tenantId = TenantContextHolder.getTenantId(); + // 项目中ID 为空,查询全部,不进行过滤 + if (tenantId == null) { + return Boolean.TRUE; + } + + return properties.getTables().contains(tableName); + } + +} \ No newline at end of file diff --git a/src/main/resources/lib/wflow-server-1.0-SNAPSHOT.jar b/src/main/resources/lib/wflow-server-1.0-SNAPSHOT.jar index eb90ff1c7..0c047f343 100644 Binary files a/src/main/resources/lib/wflow-server-1.0-SNAPSHOT.jar and b/src/main/resources/lib/wflow-server-1.0-SNAPSHOT.jar differ