fix:数据字典租户隔离恢复&新增表头同步其他租户
This commit is contained in:
@@ -14,29 +14,29 @@ public interface SimulationSystemMapper {
|
||||
@Insert("INSERT INTO simulation_data_dictionary(uuid,dictName,dictValue,dictOrder,valueType,aliasName,dictClass,classType,comment,tenantId,creator) VALUES (#{dict.uuid},#{dict.dictName},#{dict.dictValue},#{dict.dictOrder},#{dict.valueType},#{dict.aliasName},#{dict.dictClass},#{dict.classType},#{dict.comment},#{dict.tenantId},#{dict.creator})")
|
||||
int addDataDictionary(@Param("dict") DataDictionary dict);
|
||||
|
||||
@Select("SELECT * FROM simulation_data_dictionary WHERE dictClass=#{dictClass} ORDER BY dictOrder ASC")
|
||||
List<DataDictionary> queryDictionaryClassData(@Param("dictClass")String dictClass);
|
||||
@Select("SELECT * FROM simulation_data_dictionary WHERE dictClass=#{dictClass} AND tenantId=#{tenantId} ORDER BY dictOrder ASC")
|
||||
List<DataDictionary> queryDictionaryClassData(@Param("dictClass")String dictClass,@Param("tenantId") long tenantId);
|
||||
|
||||
@Select("SELECT * FROM simulation_data_dictionary")
|
||||
List<DataDictionary> getAllDictionaryData();
|
||||
@Select("SELECT * FROM simulation_data_dictionary WHERE tenantId=#{tenantId}")
|
||||
List<DataDictionary> getAllDictionaryData(@Param("tenantId") long tenantId);
|
||||
|
||||
@Select("SELECT * FROM simulation_data_dictionary WHERE dictName like CONCAT('%',#{dictName},'%')")
|
||||
List<DataDictionary> queryDictionaryClassByDictName(@Param("dictName") String dictName);
|
||||
@Select("SELECT * FROM simulation_data_dictionary WHERE tenantId = #{tenantId} AND dictName like CONCAT('%',#{dictName},'%')")
|
||||
List<DataDictionary> queryDictionaryClassByDictName(@Param("dictName") String dictName, @Param("tenantId") long tenantId);
|
||||
|
||||
@Delete("DELETE FROM simulation_data_dictionary WHERE dictClass=#{dictClass}")
|
||||
int deleteDictionaryClassItems(@Param("dictClass")String dictClass);
|
||||
@Delete("DELETE FROM simulation_data_dictionary WHERE dictClass=#{dictClass} AND tenantId=#{tenantId}")
|
||||
int deleteDictionaryClassItems(@Param("dictClass")String dictClass,@Param("tenantId") long tenantId);
|
||||
|
||||
@Select("SELECT * FROM simulation_data_dictionary WHERE dictName=#{dictName} AND dictClass=#{dictClass} LIMIT 1")
|
||||
DataDictionary queryDataDictionary(@Param("dictName")String dictName,@Param("dictClass")String dictClass);
|
||||
@Select("SELECT * FROM simulation_data_dictionary WHERE dictName=#{dictName} AND dictClass=#{dictClass} AND tenantId=#{tenantId} LIMIT 1")
|
||||
DataDictionary queryDataDictionary(@Param("dictName")String dictName,@Param("dictClass")String dictClass,@Param("tenantId")long tenantId);
|
||||
|
||||
@Select("SELECT * FROM simulation_data_dictionary WHERE classType=#{classType} AND dictValue=#{dictValue} LIMIT 1")
|
||||
DataDictionary queryDataDictionaryByDictTypeAndDictName(@Param("classType")String classType,@Param("dictValue")String dictValue);
|
||||
@Select("SELECT * FROM simulation_data_dictionary WHERE classType=#{classType} AND dictValue=#{dictValue} AND tenantId=#{tenantId} LIMIT 1")
|
||||
DataDictionary queryDataDictionaryByDictTypeAndDictName(@Param("classType")String classType,@Param("dictValue")String dictValue,@Param("tenantId")long tenantId);
|
||||
|
||||
@Select("SELECT * FROM simulation_data_dictionary WHERE uuid=#{uuid}")
|
||||
DataDictionary queryDictionaryDataDetail(@Param("uuid")String uuid);
|
||||
|
||||
@Select("SELECT DISTINCT (dictClass) FROM simulation_data_dictionary")
|
||||
List<String> queryDictionaryClass();
|
||||
@Select("SELECT DISTINCT (dictClass) FROM simulation_data_dictionary WHERE tenantId=#{tenantId}")
|
||||
List<String> queryDictionaryClass(long tenantId);
|
||||
|
||||
@Delete("DELETE FROM simulation_data_dictionary WHERE uuid=#{uuid}")
|
||||
int deleteDictionary(@Param("uuid") String uuid);
|
||||
@@ -50,14 +50,14 @@ public interface SimulationSystemMapper {
|
||||
@Delete("DELETE FROM simulation_dictionary_class WHERE uuid=#{uuid}")
|
||||
int deleteDictionaryClass(@Param("uuid")String uuid);
|
||||
|
||||
@Select("SELECT * FROM simulation_dictionary_class WHERE ${condition} ORDER BY createTime DESC LIMIT ${pos},${size}")
|
||||
List<DictionaryClass> queryAllDictionaryClass(@Param("condition")String condition,@Param("pos") int pos,@Param("size") int size);
|
||||
@Select("SELECT * FROM simulation_dictionary_class WHERE ${condition} AND tenantId=#{tenantId} ORDER BY createTime DESC LIMIT ${pos},${size}")
|
||||
List<DictionaryClass> queryAllDictionaryClass(@Param("condition")String condition,@Param("pos") int pos,@Param("size") int size,@Param("tenantId")long tenantId);
|
||||
|
||||
@Select("SELECT COUNT(*) FROM simulation_dictionary_class WHERE ${condition}")
|
||||
int queryDictionaryClassTotal(@Param("condition")String condition);
|
||||
@Select("SELECT COUNT(*) FROM simulation_dictionary_class WHERE ${condition} AND tenantId=#{tenantId}")
|
||||
int queryDictionaryClassTotal(@Param("condition")String condition, @Param("tenantId") long tenantId);
|
||||
|
||||
@Select("SELECT * FROM simulation_dictionary_class WHERE className=#{className}")
|
||||
DictionaryClass queryDictionaryClassByName(@Param("className")String className);
|
||||
@Select("SELECT * FROM simulation_dictionary_class WHERE className=#{className} AND tenantId=#{tenantId}")
|
||||
DictionaryClass queryDictionaryClassByName(@Param("className")String className, @Param("tenantId") long tenantId);
|
||||
|
||||
@Update("UPDATE simulation_dictionary_class SET comment=#{dictClass.comment},titleName=#{dictClass.titleName} ,classType=#{dictClass.classType}WHERE uuid=#{dictClass.uuid}")
|
||||
int updateDictinaryClass(@Param("dictClass") DictionaryClass dictClass);
|
||||
@@ -68,8 +68,8 @@ public interface SimulationSystemMapper {
|
||||
@Insert("INSERT INTO system_form_configure(formName,formConfig,comment,tenantId,creator) VALUES (#{config.formName},#{config.formConfig},#{config.comment},#{config.tenantId}#{config.creator})")
|
||||
int addFormConfigure(@Param("config") FormConfigure config);
|
||||
|
||||
@Select("SELECT * FROM system_form_configure WHERE formName=#{formName}")
|
||||
FormConfigure queryFormConfigure(@Param("formName")String formName);
|
||||
@Select("SELECT * FROM system_form_configure WHERE formName=#{formName} AND tenantId=#{tenantId}")
|
||||
FormConfigure queryFormConfigure(@Param("formName")String formName,@Param("tenantId")long tenantId);
|
||||
|
||||
@Insert("UPDATE system_form_configure SET formConfig=#{config.formConfig},comment=#{config.comment} WHERE formName=#{config.formName}")
|
||||
int updateFormConfigure(@Param("config") FormConfigure config);
|
||||
|
||||
@@ -8,6 +8,10 @@ import com.github.pagehelper.PageInfo;
|
||||
import com.sdm.common.common.SdmResponse;
|
||||
import com.sdm.common.common.ThreadLocalContext;
|
||||
import com.sdm.common.entity.bo.DataPageInfo;
|
||||
import com.sdm.common.entity.req.data.TenantListReq;
|
||||
import com.sdm.common.entity.resp.PageDataResp;
|
||||
import com.sdm.common.entity.resp.system.TenantResp;
|
||||
import com.sdm.common.feign.impl.system.SysTenantFeignClientImpl;
|
||||
import com.sdm.common.service.BaseService;
|
||||
import com.sdm.common.utils.PageUtils;
|
||||
import com.sdm.system.dao.SimulationSystemMapper;
|
||||
@@ -29,6 +33,7 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
@@ -39,6 +44,9 @@ public class SimulationSystemConfigServiceImpl extends BaseService implements IS
|
||||
@Autowired
|
||||
private IFormConfigureService formConfigureService;
|
||||
|
||||
@Autowired
|
||||
private SysTenantFeignClientImpl sysTenantFeignClient;
|
||||
|
||||
/**
|
||||
* 添加数据字典
|
||||
* @param dict
|
||||
@@ -46,17 +54,19 @@ public class SimulationSystemConfigServiceImpl extends BaseService implements IS
|
||||
*/
|
||||
public SdmResponse addDataDictionary(DataDictionary dict) {
|
||||
SdmResponse response = SdmResponse.success();
|
||||
DataDictionary dictionary = mapper.queryDataDictionary(dict.dictName, dict.dictClass);
|
||||
long tenantId = ThreadLocalContext.getTenantId();
|
||||
DataDictionary dictionary = mapper.queryDataDictionary(dict.dictName, dict.dictClass, tenantId);
|
||||
if (dictionary != null) {
|
||||
response = SdmResponse.failed("数据字典信息已存在");
|
||||
}
|
||||
|
||||
if (ObjectUtils.isNotEmpty(dict.classType)) {
|
||||
DataDictionary dataDictionary = mapper.queryDataDictionaryByDictTypeAndDictName(dict.classType, dict.dictValue);
|
||||
DataDictionary dataDictionary = mapper.queryDataDictionaryByDictTypeAndDictName(dict.classType, dict.dictValue, tenantId);
|
||||
if (dataDictionary != null) {
|
||||
response = SdmResponse.failed("数据字典:"+dataDictionary.dictClass+"-"+dataDictionary.aliasName+"已存在,请重新命名数据字典值");
|
||||
}
|
||||
}
|
||||
dict.tenantId = ThreadLocalContext.getTenantId();
|
||||
dict.creator = ThreadLocalContext.getUserId();
|
||||
dict.uuid = generateDictionaryUuid();
|
||||
if (mapper.addDataDictionary(dict) <= 0) {
|
||||
@@ -73,7 +83,8 @@ public class SimulationSystemConfigServiceImpl extends BaseService implements IS
|
||||
public SdmResponse queryDataDictioaryClasses()
|
||||
{
|
||||
SdmResponse response = SdmResponse.success();
|
||||
List<String> dictClasses = mapper.queryDictionaryClass();
|
||||
long tenantId = ThreadLocalContext.getTenantId();
|
||||
List<String> dictClasses = mapper.queryDictionaryClass(tenantId);
|
||||
response.setData(dictClasses);
|
||||
return response;
|
||||
}
|
||||
@@ -101,7 +112,8 @@ public class SimulationSystemConfigServiceImpl extends BaseService implements IS
|
||||
public SdmResponse deleteDataDictionaryClass(String className)
|
||||
{
|
||||
SdmResponse response = SdmResponse.success();
|
||||
if(mapper.deleteDictionaryClassItems(className) <= 0)
|
||||
long tenantId = ThreadLocalContext.getTenantId();
|
||||
if(mapper.deleteDictionaryClassItems(className,tenantId) <= 0)
|
||||
{
|
||||
response = SdmResponse.failed("删除数据字典分类下所有字典信息失败");
|
||||
}
|
||||
@@ -115,7 +127,8 @@ public class SimulationSystemConfigServiceImpl extends BaseService implements IS
|
||||
*/
|
||||
public SdmResponse<List<DataDictionary>> queryDictionaryData(String className)
|
||||
{
|
||||
List<DataDictionary> dictionaries = mapper.queryDictionaryClassData(className);
|
||||
long tenantId = ThreadLocalContext.getTenantId();
|
||||
List<DataDictionary> dictionaries = mapper.queryDictionaryClassData(className,tenantId);
|
||||
return SdmResponse.success(dictionaries);
|
||||
}
|
||||
|
||||
@@ -124,7 +137,8 @@ public class SimulationSystemConfigServiceImpl extends BaseService implements IS
|
||||
* @return
|
||||
*/
|
||||
public SdmResponse<Map<String, List<SimuDictionaryResp>> > getAllDictionaryData() {
|
||||
List<DataDictionary> dictionaries = mapper.getAllDictionaryData();
|
||||
long tenantId = ThreadLocalContext.getTenantId();
|
||||
List<DataDictionary> dictionaries = mapper.getAllDictionaryData(tenantId);
|
||||
List<SimuDictionaryResp> newDictionaries = dictionaries.stream().filter(i -> StringUtils.isNotBlank(i.dictClass)).map(i -> new SimuDictionaryResp(i.dictValue, i.dictClass, i.dictName)).collect(Collectors.toList());
|
||||
Map<String, List<SimuDictionaryResp>> dictionMap = newDictionaries.stream().collect(Collectors.groupingBy(SimuDictionaryResp::getDictClass));
|
||||
return SdmResponse.success(dictionMap);
|
||||
@@ -140,7 +154,8 @@ public class SimulationSystemConfigServiceImpl extends BaseService implements IS
|
||||
SdmResponse response = SdmResponse.success();
|
||||
|
||||
if (ObjectUtils.isNotEmpty(dict.classType)) {
|
||||
DataDictionary dictionary = mapper.queryDataDictionaryByDictTypeAndDictName(dict.classType, dict.dictName);
|
||||
long tenantId = ThreadLocalContext.getTenantId();
|
||||
DataDictionary dictionary = mapper.queryDataDictionaryByDictTypeAndDictName(dict.classType, dict.dictName, tenantId);
|
||||
if(dictionary != null){
|
||||
response = SdmResponse.failed("数据字典:"+dictionary.dictClass+"-"+dictionary.aliasName+"已存在,请重新命名数据字典值");
|
||||
}
|
||||
@@ -161,9 +176,11 @@ public class SimulationSystemConfigServiceImpl extends BaseService implements IS
|
||||
{
|
||||
SdmResponse response = SdmResponse.success();
|
||||
dictionaryCla.uuid = generateDictionaryUuid();
|
||||
long tenantId = ThreadLocalContext.getTenantId();
|
||||
long creator = ThreadLocalContext.getUserId();
|
||||
dictionaryCla.tenantId = tenantId;
|
||||
dictionaryCla.creator = creator;
|
||||
if(mapper.queryDictionaryClassByName(dictionaryCla.className) != null)
|
||||
if(mapper.queryDictionaryClassByName(dictionaryCla.className,tenantId) != null)
|
||||
{
|
||||
response = SdmResponse.failed("数据字典分类已存在");
|
||||
}
|
||||
@@ -180,6 +197,7 @@ public class SimulationSystemConfigServiceImpl extends BaseService implements IS
|
||||
*/
|
||||
public SdmResponse queryDictionaryDefineClass(String titleName,String className,String dictName,String dictValue,int pageNo,int size)
|
||||
{
|
||||
long tenantId = ThreadLocalContext.getTenantId();
|
||||
SdmResponse response = SdmResponse.success();
|
||||
String condition = " 1";
|
||||
if(bStringNotBlank(titleName))
|
||||
@@ -192,7 +210,7 @@ public class SimulationSystemConfigServiceImpl extends BaseService implements IS
|
||||
}
|
||||
if(bStringNotBlank(dictName) || bStringNotBlank(dictValue))
|
||||
{
|
||||
List<DataDictionary> allDictionaryData = mapper.getAllDictionaryData();
|
||||
List<DataDictionary> allDictionaryData = mapper.getAllDictionaryData(tenantId);
|
||||
if (bStringNotBlank(dictName)) {
|
||||
allDictionaryData = allDictionaryData.stream().filter(i -> i.getDictName().contains(dictName)).collect(Collectors.toList());
|
||||
}
|
||||
@@ -204,9 +222,9 @@ public class SimulationSystemConfigServiceImpl extends BaseService implements IS
|
||||
condition += " AND className IN ('" + dictClass + "')";
|
||||
}
|
||||
}
|
||||
int count = mapper.queryDictionaryClassTotal(condition);
|
||||
int count = mapper.queryDictionaryClassTotal(condition,tenantId);
|
||||
int pos = (pageNo-1)*size;
|
||||
List<DictionaryClass> classes = mapper.queryAllDictionaryClass(condition,pos,size);
|
||||
List<DictionaryClass> classes = mapper.queryAllDictionaryClass(condition,pos,size,tenantId);
|
||||
|
||||
DataPageInfo pageInfo = new DataPageInfo();
|
||||
pageInfo.total = count;
|
||||
@@ -290,15 +308,32 @@ public class SimulationSystemConfigServiceImpl extends BaseService implements IS
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public SdmResponse addSystemFormConfigure(FormConfigure configure) {
|
||||
SdmResponse response = SdmResponse.success();
|
||||
if (CollectionUtils.isNotEmpty(formConfigureService.lambdaQuery().eq(SysFormConfigure::getFormName, configure.formName).list())) {
|
||||
Long tenantId = ThreadLocalContext.getTenantId();
|
||||
if (CollectionUtils.isNotEmpty(formConfigureService.lambdaQuery().eq(SysFormConfigure::getFormName, configure.formName).eq(SysFormConfigure::getTenantId, tenantId).list())) {
|
||||
response = SdmResponse.failed("该表单配置已存在");
|
||||
} else {
|
||||
SysFormConfigure sysFormConfigure = new SysFormConfigure();
|
||||
BeanUtils.copyProperties(configure, sysFormConfigure);
|
||||
sysFormConfigure.setTenantId(tenantId);
|
||||
sysFormConfigure.setCreator(ThreadLocalContext.getUserId());
|
||||
if (!formConfigureService.save(sysFormConfigure)) {
|
||||
response = SdmResponse.failed("添加表单配置失败");
|
||||
}
|
||||
// 每当有租户新增表头,就给没有这个表头的租户同步一个表头
|
||||
TenantListReq req = new TenantListReq();
|
||||
req.setCurrent(1);
|
||||
req.setSize(1000);
|
||||
SdmResponse<PageDataResp<List<TenantResp>>> listTenantResp = sysTenantFeignClient.listTenant(req);
|
||||
if (listTenantResp.isSuccess() && listTenantResp.getData() != null && listTenantResp.getData().getData() != null) {
|
||||
List<Long> tenantIdList = listTenantResp.getData().getData().stream().map(TenantResp::getTenantId).filter(id -> !Objects.equals(id, tenantId)).toList();
|
||||
tenantIdList.forEach(i -> {
|
||||
if (CollectionUtils.isEmpty(formConfigureService.lambdaQuery().eq(SysFormConfigure::getFormName, configure.formName)
|
||||
.eq(SysFormConfigure::getTenantId, i).list())) {
|
||||
sysFormConfigure.setTenantId(tenantId);
|
||||
formConfigureService.save(sysFormConfigure);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
return response;
|
||||
}
|
||||
@@ -313,6 +348,7 @@ public class SimulationSystemConfigServiceImpl extends BaseService implements IS
|
||||
if (CollectionUtils.isNotEmpty(formConfigureService.lambdaQuery().eq(SysFormConfigure::getFormName, configure.formName).list())) {
|
||||
LambdaUpdateWrapper<SysFormConfigure> updateWrapper = new LambdaUpdateWrapper<>();
|
||||
updateWrapper.eq(SysFormConfigure::getFormName, configure.getFormName());
|
||||
updateWrapper.eq(SysFormConfigure::getTenantId, ThreadLocalContext.getTenantId());
|
||||
if (configure.getFormConfig() != null) {
|
||||
updateWrapper.set(SysFormConfigure::getFormConfig, configure.getFormConfig());
|
||||
}
|
||||
@@ -346,7 +382,8 @@ public class SimulationSystemConfigServiceImpl extends BaseService implements IS
|
||||
public SdmResponse queryFormConfigure(String formName)
|
||||
{
|
||||
SdmResponse response = SdmResponse.success();
|
||||
FormConfigure formConfigure = mapper.queryFormConfigure(formName);
|
||||
long tenantId = ThreadLocalContext.getTenantId();
|
||||
FormConfigure formConfigure = mapper.queryFormConfigure(formName,tenantId);
|
||||
if(formConfigure == null)
|
||||
{
|
||||
response = SdmResponse.failed("表单不存在");
|
||||
@@ -365,6 +402,7 @@ public class SimulationSystemConfigServiceImpl extends BaseService implements IS
|
||||
queryWrapper.like(SysFormConfigure::getFormName, req.formName);
|
||||
}
|
||||
queryWrapper.orderByDesc(SysFormConfigure::getCreateTime);
|
||||
queryWrapper.eq(SysFormConfigure::getTenantId, ThreadLocalContext.getTenantId());
|
||||
List<SysFormConfigure> list = formConfigureService.list(queryWrapper);
|
||||
if (CollectionUtils.isEmpty(list)) {
|
||||
return SdmResponse.success();
|
||||
|
||||
Reference in New Issue
Block a user