1. 指标列表根据原子指标进行过滤查询

topo_dev
xueqingkun 10 months ago
parent 90baf9dcde
commit c827dbdb53

@ -6,6 +6,7 @@ import com.supervision.police.domain.ModelIndex;
import com.supervision.police.dto.CaseAtomicIndexDTO;
import com.supervision.police.dto.CaseAtomicResultWrapper;
import com.supervision.police.service.ModelIndexService;
import com.supervision.police.vo.ModelIndexReqVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import lombok.RequiredArgsConstructor;
@ -35,7 +36,7 @@ public class ModelIndexController {
* @return
*/
@PostMapping("/selectAll")
public R<?> selectAll(@RequestBody ModelIndex modelIndex,
public R<?> selectAll(@RequestBody ModelIndexReqVO modelIndex,
@RequestParam(required = false, defaultValue = "1") Integer page,
@RequestParam(required = false, defaultValue = "20") Integer size) {
return modelIndexService.selectAll(modelIndex, page, size);

@ -1,11 +1,11 @@
package com.supervision.police.domain;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.annotation.*;
import java.io.Serializable;
import java.time.LocalDateTime;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
/**
@ -18,6 +18,7 @@ public class ModelIndexAtomicRelation implements Serializable {
/**
* id
*/
@TableId
private String id;
/**
@ -38,6 +39,8 @@ public class ModelIndexAtomicRelation implements Serializable {
/**
*
*/
@TableField(fill = FieldFill.INSERT_UPDATE)
@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
private LocalDateTime createTime;
/**
@ -48,6 +51,8 @@ public class ModelIndexAtomicRelation implements Serializable {
/**
*
*/
@TableField(fill = FieldFill.INSERT_UPDATE)
@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
private LocalDateTime updateTime;
@TableField(exist = false)

@ -0,0 +1,24 @@
package com.supervision.police.dto;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@Data
public class ModelIndexAtomicRelationDTO {
@Schema(description = "主键")
private String id;
@Schema(description = "指标id")
private String modelIndexId;
@Schema(description = "指标名称")
private String modelIndexName;
@Schema(description = "原子id")
private String atomicIndexId;
@Schema(description = "原子关系名称")
private String atomicIndexName;
}

@ -2,6 +2,9 @@ package com.supervision.police.mapper;
import com.supervision.police.domain.ModelIndexAtomicRelation;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.supervision.police.dto.ModelIndexAtomicRelationDTO;
import java.util.List;
/**
* @author Administrator
@ -11,6 +14,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
*/
public interface ModelIndexAtomicRelationMapper extends BaseMapper<ModelIndexAtomicRelation> {
List<ModelIndexAtomicRelationDTO> listByAtomicIndexName(String atomicIndexName);
}

@ -1,7 +1,11 @@
package com.supervision.police.service;
import com.supervision.police.domain.ModelIndex;
import com.supervision.police.domain.ModelIndexAtomicRelation;
import com.baomidou.mybatisplus.extension.service.IService;
import com.supervision.police.dto.ModelIndexAtomicRelationDTO;
import java.util.List;
/**
* @author Administrator
@ -10,4 +14,31 @@ import com.baomidou.mybatisplus.extension.service.IService;
*/
public interface ModelIndexAtomicRelationService extends IService<ModelIndexAtomicRelation> {
/**
*
* @param atomicIndexName
* @return
*/
List<ModelIndexAtomicRelationDTO> listByAtomicIndexName(String atomicIndexName);
/**
*
* @param modelIndex
*/
void saveByModelIndex(ModelIndex modelIndex);
/**
*
* @param modelIndex
*/
void updateByModelIndex(ModelIndex modelIndex);
/**
* id
* @param modelIndexId id
*/
void deleteByModelIndex(String modelIndexId);
}

@ -6,6 +6,7 @@ import com.supervision.police.domain.ModelAtomicIndex;
import com.supervision.police.domain.ModelIndex;
import com.supervision.police.dto.CaseAtomicIndexDTO;
import com.supervision.police.dto.CaseAtomicResultWrapper;
import com.supervision.police.vo.ModelIndexReqVO;
import java.util.List;
@ -17,7 +18,7 @@ import java.util.List;
*/
public interface ModelIndexService extends IService<ModelIndex> {
R<?> selectAll(ModelIndex modelIndex, Integer page, Integer size);
R<?> selectAll(ModelIndexReqVO modelIndex, Integer page, Integer size);
R<?> addOrUpd(ModelIndex modelIndex);

@ -1,20 +1,89 @@
package com.supervision.police.service.impl;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.supervision.police.domain.ModelIndex;
import com.supervision.police.domain.ModelIndexAtomicRelation;
import com.supervision.police.dto.ModelIndexAtomicRelationDTO;
import com.supervision.police.service.ModelIndexAtomicRelationService;
import com.supervision.police.mapper.ModelIndexAtomicRelationMapper;
import com.supervision.utils.JudgeLogicUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
import java.util.Objects;
/**
* @author Administrator
* @description model_index_atomic_relation()Service
* @createDate 2024-08-07 10:52:56
*/
@Slf4j
@Service
public class ModelIndexAtomicRelationServiceImpl extends ServiceImpl<ModelIndexAtomicRelationMapper, ModelIndexAtomicRelation>
implements ModelIndexAtomicRelationService{
@Override
public List<ModelIndexAtomicRelationDTO> listByAtomicIndexName(String atomicIndexName) {
return super.baseMapper.listByAtomicIndexName(atomicIndexName);
}
@Override
@Transactional(transactionManager = "dataSourceTransactionManager", rollbackFor = Exception.class)
public void saveByModelIndex(ModelIndex modelIndex) {
if (Objects.isNull(modelIndex.getId())){
log.warn("saveByModelIndex: modelIndexId 为空,不保存关联关系....");
return;
}
if (StrUtil.isEmpty(modelIndex.getId())){
log.warn("saveByModelIndex: modelIndexId 为空,不保存关联关系....modelIndex:{}", JSONUtil.toJsonStr(modelIndex));
return;
}
String judgeLogic = modelIndex.getJudgeLogic();
if (StrUtil.isEmpty(judgeLogic)){
log.info("saveByModelIndex: modelIndex judgeLogic 为空,不保存关联关系....modelIndex:{}", JSONUtil.toJsonStr(modelIndex));
return;
}
List<String> atomicIndexIds = JudgeLogicUtil.pickAtomicIndexIds(judgeLogic);
atomicIndexIds.forEach(atomicIndexId -> {
ModelIndexAtomicRelation modelIndexAtomicRelation = new ModelIndexAtomicRelation();
modelIndexAtomicRelation.setModelIndexId(modelIndex.getId());
modelIndexAtomicRelation.setAtomicIndexId(atomicIndexId);
super.save(modelIndexAtomicRelation);
});
}
@Override
@Transactional(transactionManager = "dataSourceTransactionManager", rollbackFor = Exception.class)
public void updateByModelIndex(ModelIndex modelIndex) {
if (Objects.isNull(modelIndex.getId())){
log.warn("updateByModelIndex: modelIndexId 为空,不保存关联关系....");
return;
}
if (StrUtil.isEmpty(modelIndex.getId())){
log.warn("updateByModelIndex: modelIndexId 为空,不保存关联关系....modelIndex:{}", JSONUtil.toJsonStr(modelIndex));
return;
}
deleteByModelIndex(modelIndex.getId());
saveByModelIndex(modelIndex);
}
@Override
public void deleteByModelIndex(String modelIndexId) {
if (StrUtil.isEmpty(modelIndexId)){
log.warn("deleteModelIndex: modelIndexId 为空,不删除关联关系....modelIndexId:{}", modelIndexId);
return;
}
super.remove(new LambdaQueryWrapper<ModelIndexAtomicRelation>().eq(ModelIndexAtomicRelation::getModelIndexId, modelIndexId));
}
}

@ -17,14 +17,13 @@ import com.supervision.common.utils.IPages;
import com.supervision.common.utils.StringUtils;
import com.supervision.constant.DataStatus;
import com.supervision.police.domain.*;
import com.supervision.police.dto.AtomicData;
import com.supervision.police.dto.CaseAtomicIndexDTO;
import com.supervision.police.dto.CaseAtomicResultWrapper;
import com.supervision.police.dto.JudgeLogic;
import com.supervision.police.dto.*;
import com.supervision.police.mapper.CasePersonMapper;
import com.supervision.police.mapper.ModelAtomicResultMapper;
import com.supervision.police.mapper.ModelIndexMapper;
import com.supervision.police.service.*;
import com.supervision.police.vo.ModelIndexReqVO;
import com.supervision.utils.JudgeLogicUtil;
import com.supervision.utils.SqlParserUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
@ -60,12 +59,16 @@ public class ModelIndexServiceImpl extends ServiceImpl<ModelIndexMapper, ModelIn
private final CaseStatusManageService caseStatusManageService;
private final ModelIndexAtomicRelationService modelIndexAtomicRelationService;
@Value("${case.evidence.table}")
private List<String> allowedTables;
@Override
@Transactional(transactionManager = "dataSourceTransactionManager", rollbackFor = Exception.class)
public R<?> selectAll(ModelIndex modelIndex, Integer page, Integer size) {
public R<?> selectAll(ModelIndexReqVO modelIndex, Integer page, Integer size) {
// 构建查询条件
IPage<ModelIndex> iPage = new Page<>(page, size);
LambdaQueryWrapper<ModelIndex> wrapper = Wrappers.lambdaQuery();
wrapper.like(modelIndex.getName() != null, ModelIndex::getName, modelIndex.getName())
@ -74,9 +77,22 @@ public class ModelIndexServiceImpl extends ServiceImpl<ModelIndexMapper, ModelIn
.eq(StringUtils.isNotEmpty(modelIndex.getIndexType()), ModelIndex::getIndexType, modelIndex.getIndexType())
.eq(StringUtils.isNotEmpty(modelIndex.getCaseType()), ModelIndex::getCaseType, modelIndex.getCaseType())
.eq(ModelIndex::getDataStatus, "1");
if (StrUtil.isNotEmpty(modelIndex.getAtomicIndexName())){
// 如果查询条件中有原子指标名称则根据原子指标名称过滤关联的指标id
List<ModelIndexAtomicRelationDTO> modelIndexAtomicDTOS = modelIndexAtomicRelationService.listByAtomicIndexName(modelIndex.getAtomicIndexName());
List<String> indexIdList = modelIndexAtomicDTOS.stream().map(ModelIndexAtomicRelationDTO::getModelIndexId).distinct().toList();
wrapper.in(CollUtil.isNotEmpty(indexIdList),ModelIndex::getId, indexIdList);
}
iPage = modelIndexMapper.selectPage(iPage, wrapper);
// 分页查询
List<ModelIndex> records = iPage.getRecords();
List<ComDictionary> dicts = comDictionaryService.list();
// 查询结果拼装
for (ModelIndex index : records) {
index.setIndexTypeName(comDictionaryService.getName(dicts, "index_type", index.getIndexType()));
index.setCaseTypeName(comDictionaryService.getName(dicts, "case_type", index.getCaseType()));
@ -106,8 +122,10 @@ public class ModelIndexServiceImpl extends ServiceImpl<ModelIndexMapper, ModelIn
int i = 0;
if (StringUtils.isEmpty(modelIndex.getId())) {
i = modelIndexMapper.insert(modelIndex);
modelIndexAtomicRelationService.saveByModelIndex(modelIndex);
} else {
i = modelIndexMapper.updateById(modelIndex);
modelIndexAtomicRelationService.updateByModelIndex(modelIndex);
}
if (i > 0) {
return R.okMsg("保存成功");
@ -123,6 +141,7 @@ public class ModelIndexServiceImpl extends ServiceImpl<ModelIndexMapper, ModelIn
index.setDataStatus(DataStatus.NOT_AVAILABLE.getCode());
int i = modelIndexMapper.updateById(index);
if (i > 0) {
modelIndexAtomicRelationService.deleteByModelIndex(id);
return R.okMsg("删除成功");
} else {
return R.fail("删除失败");
@ -209,7 +228,7 @@ public class ModelIndexServiceImpl extends ServiceImpl<ModelIndexMapper, ModelIn
// 从指标中计算出所有原子指标id
List<String> atomicIndexIds = modelIndexList.stream().filter(modelIndex -> StrUtil.isNotEmpty(modelIndex.getJudgeLogic()))
.map(modelIndex -> pickAtomicIndexIds(modelIndex.getJudgeLogic()))
.map(modelIndex -> JudgeLogicUtil.pickAtomicIndexIds(modelIndex.getJudgeLogic()))
.flatMap(Collection::stream).distinct().toList();
if (CollUtil.isEmpty(atomicIndexIds)) {
@ -321,25 +340,6 @@ public class ModelIndexServiceImpl extends ServiceImpl<ModelIndexMapper, ModelIn
.in(CollUtil.isNotEmpty(automicIndexIds), ModelAtomicResult::getAtomicId, automicIndexIds));
}
/**
* id
*
* @param judgeLogic json
* @return id()
*/
private List<String> pickAtomicIndexIds(String judgeLogic) {
List<String> ids = new ArrayList<>();
List<JudgeLogic> logic = JSONUtil.toList(judgeLogic, JudgeLogic.class);
for (JudgeLogic judge : logic) {
List<AtomicData> atomicData = judge.getAtomicData();
for (AtomicData atomic : atomicData) {
if (!ids.contains(atomic.getAtomicIndex())) {
ids.add(atomic.getAtomicIndex());
}
}
}
return ids;
}
private Map<String, List<ModelIndex>> groupModelIndexByAtomicIndexId(List<ModelIndex> modelIndexList) {
Map<String, List<ModelIndex>> groupMap = new HashMap<>();

@ -0,0 +1,38 @@
package com.supervision.police.vo;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.time.LocalDateTime;
@Data
public class ModelIndexReqVO {
@Schema(description = "指标名称")
private String name;
@Schema(description = "指标简称")
private String shortName;
@Schema(description = "原子指标名称")
private String atomicIndexName;
@Schema(description = "指标类型")
private String indexType;
@Schema(description = "案件类型")
private String caseType;
@Schema(description = "备注")
private String remark;
@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
private LocalDateTime updateStartTime;
@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
private LocalDateTime updateEndTime;
}

@ -0,0 +1,37 @@
package com.supervision.utils;
import cn.hutool.json.JSONUtil;
import com.supervision.police.dto.AtomicData;
import com.supervision.police.dto.JudgeLogic;
import lombok.extern.slf4j.Slf4j;
import java.util.ArrayList;
import java.util.List;
@Slf4j
public class JudgeLogicUtil {
public static List<JudgeLogic> parse(String logic) {
return JSONUtil.toList(logic, JudgeLogic.class);
}
/**
* id
*
* @param judgeLogic json
* @return id()
*/
public static List<String> pickAtomicIndexIds(String judgeLogic) {
List<String> ids = new ArrayList<>();
List<JudgeLogic> logic = parse(judgeLogic);
for (JudgeLogic judge : logic) {
List<AtomicData> atomicData = judge.getAtomicData();
for (AtomicData atomic : atomicData) {
if (!ids.contains(atomic.getAtomicIndex())) {
ids.add(atomic.getAtomicIndex());
}
}
}
return ids;
}
}

@ -19,4 +19,13 @@
create_user_id,create_time,update_user_id,
update_time
</sql>
<select id="listByAtomicIndexName" resultType="com.supervision.police.dto.ModelIndexAtomicRelationDTO">
select r.id as id,
r.model_index_id as modelIndexId,
r.atomic_index_id as atomicIndexId,
a.name as atomicIndexName
from model_index_atomic_relation r
join model_atomic_index a on r.atomic_index_id = a.id
where a.name like concat('%', #{atomicIndexName}, '%')
</select>
</mapper>

@ -5,6 +5,7 @@ import cn.hutool.core.lang.UUID;
import cn.hutool.json.JSONUtil;
import cn.hutool.poi.excel.ExcelReader;
import cn.hutool.poi.excel.ExcelUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.supervision.police.domain.ModelAtomicIndex;
import com.supervision.police.domain.ModelIndex;
import com.supervision.police.dto.AtomicData;
@ -12,6 +13,7 @@ import com.supervision.police.dto.JudgeLogic;
import com.supervision.police.mapper.ModelAtomicIndexMapper;
import com.supervision.police.mapper.ModelIndexMapper;
import com.supervision.police.mybatis.RowSqlMapper;
import com.supervision.police.service.ModelIndexAtomicRelationService;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.mapping.BoundSql;
@ -35,6 +37,9 @@ public class ModelIndexTest {
@Autowired
private ModelAtomicIndexMapper modelAtomicIndexMapper;
@Autowired
private ModelIndexAtomicRelationService modelIndexAtomicRelationService;
@Autowired
private RowSqlMapper rowSqlMapper;
//@Test
@ -50,6 +55,15 @@ public class ModelIndexTest {
}
}
//@Test
public void modelIndexRelationGenerate() {
List<ModelIndex> modelIndexList = modelIndexMapper.selectList(new LambdaQueryWrapper<>());
for (ModelIndex modelIndex : modelIndexList) {
modelIndexAtomicRelationService.updateByModelIndex(modelIndex);
}
}
@Test
public void modelAtomicIndexGenerate() {

Loading…
Cancel
Save