diff --git a/src/main/java/com/supervision/police/service/ModelAtomicIndexService.java b/src/main/java/com/supervision/police/service/ModelAtomicIndexService.java index df079e2..13b8e3c 100644 --- a/src/main/java/com/supervision/police/service/ModelAtomicIndexService.java +++ b/src/main/java/com/supervision/police/service/ModelAtomicIndexService.java @@ -1,12 +1,13 @@ package com.supervision.police.service; import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.service.IService; import com.supervision.police.domain.ModelAtomicIndex; import com.supervision.police.mapper.ModelAtomicIndexMapper; import java.util.List; -public interface ModelAtomicIndexService { +public interface ModelAtomicIndexService extends IService { ModelAtomicIndexMapper getMapper(); diff --git a/src/main/java/com/supervision/police/service/impl/ModelIndexServiceImpl.java b/src/main/java/com/supervision/police/service/impl/ModelIndexServiceImpl.java index d49307a..97eed52 100644 --- a/src/main/java/com/supervision/police/service/impl/ModelIndexServiceImpl.java +++ b/src/main/java/com/supervision/police/service/impl/ModelIndexServiceImpl.java @@ -2,6 +2,7 @@ package com.supervision.police.service.impl; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.lang.Assert; +import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; import cn.hutool.json.JSONUtil; import com.alibaba.druid.sql.ast.SQLStatement; @@ -61,8 +62,9 @@ public class ModelIndexServiceImpl extends ServiceImpl allowedTables; + @Override - @Transactional(transactionManager = "dataSourceTransactionManager",rollbackFor = Exception.class) + @Transactional(transactionManager = "dataSourceTransactionManager", rollbackFor = Exception.class) public R selectAll(ModelIndex modelIndex, Integer page, Integer size) { IPage iPage = new Page<>(page, size); LambdaQueryWrapper wrapper = Wrappers.lambdaQuery(); @@ -72,7 +74,7 @@ public class ModelIndexServiceImpl extends ServiceImpl records = iPage.getRecords(); List dicts = comDictionaryService.list(); for (ModelIndex index : records) { @@ -99,7 +101,7 @@ public class ModelIndexServiceImpl extends ServiceImpl addOrUpd(ModelIndex modelIndex) { int i = 0; if (StringUtils.isEmpty(modelIndex.getId())) { @@ -115,7 +117,7 @@ public class ModelIndexServiceImpl extends ServiceImpl del(String id) { ModelIndex index = modelIndexMapper.selectById(id); index.setDataStatus(StringUtils.getUUID()); @@ -128,10 +130,10 @@ public class ModelIndexServiceImpl extends ServiceImpl selectAllAtomic(ModelAtomicIndex modelAtomicIndex, Integer page, Integer size) { IPage iPage = new Page<>(page, size); - iPage = modelAtomicIndexService.selectAll(iPage, modelAtomicIndex); + iPage = modelAtomicIndexService.selectAll(iPage, modelAtomicIndex); List records = iPage.getRecords(); List dicts = comDictionaryService.list(); for (ModelAtomicIndex index : records) { @@ -144,14 +146,19 @@ public class ModelIndexServiceImpl extends ServiceImpl addOrUpdAtomic(ModelAtomicIndex modelAtomicIndex) { int i = 0; - if (StringUtils.equals("2", modelAtomicIndex.getIndexSource())){ + if (StringUtils.equals("2", modelAtomicIndex.getIndexSource())) { // 如果查询类型为数据查询,则校验查询语句 Assert.notEmpty(modelAtomicIndex.getQueryLang(), "查询语言不能为空"); Assert.isTrue(checkSql(modelAtomicIndex.getQueryLang()), "查询语句不合法"); } + // 校验是否已经存在了相同名称的原子指标 + ModelAtomicIndex existIndex = modelAtomicIndexService.lambdaQuery().eq(ModelAtomicIndex::getName, modelAtomicIndex.getName()).last("limit 1").one(); + if (ObjectUtil.isNotEmpty(existIndex) && !StringUtils.equals(modelAtomicIndex.getId(), existIndex.getId())){ + throw new RuntimeException("已存在相同名称的原子指标"); + } if (StringUtils.isEmpty(modelAtomicIndex.getId())) { i = modelAtomicIndexService.getMapper().insert(modelAtomicIndex); } else { @@ -165,7 +172,7 @@ public class ModelIndexServiceImpl extends ServiceImpl delAtomic(String id) { ModelAtomicIndex index = modelAtomicIndexService.getMapper().selectById(id); index.setDataStatus(StringUtils.getUUID()); @@ -178,7 +185,7 @@ public class ModelIndexServiceImpl extends ServiceImpl listCaseAtomicIndex(String caseId, String indexSource) { Assert.notEmpty(caseId, "案件id不能为空"); @@ -194,7 +201,7 @@ public class ModelIndexServiceImpl extends ServiceImpl modelIndexList = modelIndexMapper.selectList( Wrappers.lambdaQuery(ModelIndex.class) .eq(ModelIndex::getCaseType, caseType).eq(ModelIndex::getDataStatus, "1")); - if (CollUtil.isEmpty(modelIndexList)){ + if (CollUtil.isEmpty(modelIndexList)) { return new ArrayList<>(1); } @@ -203,13 +210,13 @@ public class ModelIndexServiceImpl extends ServiceImpl pickAtomicIndexIds(modelIndex.getJudgeLogic())) .flatMap(Collection::stream).distinct().toList(); - if (CollUtil.isEmpty(automicIndexIds)){ + if (CollUtil.isEmpty(automicIndexIds)) { return new ArrayList<>(1); } // 查询原子指标相关信息 List modelAtomicIndexList = modelAtomicIndexService.listCaseAtomicIndex(automicIndexIds, caseType, indexSource); - if (CollUtil.isEmpty(modelAtomicIndexList)){ + if (CollUtil.isEmpty(modelAtomicIndexList)) { return new ArrayList<>(1); } Map modelAtomicIndexMap = modelAtomicIndexList.stream().collect(Collectors.toMap(ModelAtomicIndex::getId, v -> v, (v1, v2) -> v1)); @@ -233,7 +240,7 @@ public class ModelIndexServiceImpl extends ServiceImpl - caseAtomicIndexDTO.toModelAtomicResult( - caseAtomicResultWrapper.getCaseId(), caseAtomicResultWrapper.getActorId())).toList() + caseAtomicIndexDTO.toModelAtomicResult( + caseAtomicResultWrapper.getCaseId(), caseAtomicResultWrapper.getActorId())).toList() .forEach(modelAtomicResultMapper::insert); return true; @@ -266,7 +273,7 @@ public class ModelIndexServiceImpl extends ServiceImpl tableList = SqlParserUtil.extractTableNames(sqlStatement); - if (CollUtil.isEmpty(tableList)){ + if (CollUtil.isEmpty(tableList)) { log.warn("checkSql:未检测到表"); return false; } long count = tableList.stream().filter(table -> !this.allowedTables.contains(table)).count(); - if (count > 0){ - log.warn("checkSql:表{}不在允许的表列表中",tableList); + if (count > 0) { + log.warn("checkSql:表{}不在允许的表列表中", tableList); return false; } return true; @@ -297,21 +304,24 @@ public class ModelIndexServiceImpl extends ServiceImpl modelAtomicIndexList = modelAtomicIndexService.listCaseAtomicIndex(null, caseType, indexSource); List automicIndexIds = modelAtomicIndexList.stream().map(ModelAtomicIndex::getId).distinct().toList(); modelAtomicResultMapper.delete(Wrappers.lambdaQuery(ModelAtomicResult.class) .eq(ModelAtomicResult::getCaseId, caseId) .eq(ModelAtomicResult::getCasePersonId, actorId) - .in(CollUtil.isNotEmpty(automicIndexIds),ModelAtomicResult::getAtomicId, automicIndexIds)); + .in(CollUtil.isNotEmpty(automicIndexIds), ModelAtomicResult::getAtomicId, automicIndexIds)); } + /** * 从逻辑中获取原子指标id + * * @param judgeLogic 判断逻辑json字符串 * @return 原子指标id(不重复) */ @@ -321,38 +331,38 @@ public class ModelIndexServiceImpl extends ServiceImpl atomicData = judge.getAtomicData(); for (AtomicData atomic : atomicData) { - if (!ids.contains(atomic.getAtomicIndex())){ + if (!ids.contains(atomic.getAtomicIndex())) { ids.add(atomic.getAtomicIndex()); } } } return ids; - } + } - private Map> groupModelIndexByAtomicIndexId(List modelIndexList) { - Map> groupMap = new HashMap<>(); - if (CollUtil.isEmpty(modelIndexList)){ + private Map> groupModelIndexByAtomicIndexId(List modelIndexList) { + Map> groupMap = new HashMap<>(); + if (CollUtil.isEmpty(modelIndexList)) { return groupMap; } - for (ModelIndex modelIndex : modelIndexList) { - if (StrUtil.isEmpty(modelIndex.getJudgeLogic())){ - continue; - } - String judgeLogic = modelIndex.getJudgeLogic(); - List judgeLogicList = JSONUtil.toList(judgeLogic, JudgeLogic.class); - for (JudgeLogic logic : judgeLogicList) { - List atomicData = logic.getAtomicData(); - if (CollUtil.isEmpty(atomicData)){ - continue; - } - for (AtomicData atomic : atomicData) { - List modelIndexs = groupMap.getOrDefault(atomic.getAtomicIndex(), new ArrayList<>()); + for (ModelIndex modelIndex : modelIndexList) { + if (StrUtil.isEmpty(modelIndex.getJudgeLogic())) { + continue; + } + String judgeLogic = modelIndex.getJudgeLogic(); + List judgeLogicList = JSONUtil.toList(judgeLogic, JudgeLogic.class); + for (JudgeLogic logic : judgeLogicList) { + List atomicData = logic.getAtomicData(); + if (CollUtil.isEmpty(atomicData)) { + continue; + } + for (AtomicData atomic : atomicData) { + List modelIndexs = groupMap.getOrDefault(atomic.getAtomicIndex(), new ArrayList<>()); modelIndexs.add(modelIndex); - groupMap.put(atomic.getAtomicIndex(),modelIndexs); - } - } - } - return groupMap; - } + groupMap.put(atomic.getAtomicIndex(), modelIndexs); + } + } + } + return groupMap; + } }