You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
fu-hsi-service/src/main/java/com/supervision/police/service/impl/ModelIndexServiceImpl.java

230 lines
9.9 KiB
Java

10 months ago
package com.supervision.police.service.impl;
10 months ago
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
10 months ago
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
10 months ago
import com.baomidou.mybatisplus.core.toolkit.Assert;
10 months ago
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.supervision.common.domain.R;
import com.supervision.common.utils.IPages;
import com.supervision.common.utils.StringUtils;
10 months ago
import com.supervision.police.domain.*;
10 months ago
import com.supervision.police.dto.AtomicData;
10 months ago
import com.supervision.police.dto.CaseAtomicIndexDTO;
10 months ago
import com.supervision.police.dto.JudgeLogic;
10 months ago
import com.supervision.police.mapper.ModelAtomicResultMapper;
10 months ago
import com.supervision.police.mapper.ModelIndexMapper;
import com.supervision.police.service.ComDictionaryService;
10 months ago
import com.supervision.police.service.ModelAtomicIndexService;
import com.supervision.police.service.ModelCaseService;
10 months ago
import com.supervision.police.service.ModelIndexService;
10 months ago
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
10 months ago
import org.springframework.stereotype.Service;
import java.util.ArrayList;
10 months ago
import java.util.Collection;
10 months ago
import java.util.List;
10 months ago
import java.util.Map;
import java.util.stream.Collectors;
10 months ago
/**
* (ModelIndex)
*
* @author qmy
* @since 2024-07-05 09:20:10
*/
10 months ago
@Slf4j
10 months ago
@Service
10 months ago
@RequiredArgsConstructor
10 months ago
public class ModelIndexServiceImpl extends ServiceImpl<ModelIndexMapper, ModelIndex> implements ModelIndexService {
10 months ago
private final ComDictionaryService comDictionaryService;
10 months ago
10 months ago
private final ModelIndexMapper modelIndexMapper;
10 months ago
10 months ago
private final ModelAtomicIndexService modelAtomicIndexService;
10 months ago
10 months ago
private final ModelCaseService modelCaseService;
private final ModelAtomicResultMapper modelAtomicResultMapper;
10 months ago
@Override
public R<?> selectAll(ModelIndex 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())
.like(modelIndex.getShortName() != null, ModelIndex::getShortName, modelIndex.getShortName())
.like(modelIndex.getRemark() != null, ModelIndex::getRemark, modelIndex.getRemark())
.eq(StringUtils.isNotEmpty(modelIndex.getIndexType()), ModelIndex::getIndexType, modelIndex.getIndexType())
.eq(StringUtils.isNotEmpty(modelIndex.getCaseType()), ModelIndex::getCaseType, modelIndex.getCaseType())
.eq(ModelIndex::getDataStatus, "1");
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()));
//原子指标
String judgeLogic = index.getJudgeLogic();
List<String> ids = new ArrayList<>();
if (StringUtils.isNotEmpty(judgeLogic)) {
List<JudgeLogic> logic = JSONUtil.toList(judgeLogic, JudgeLogic.class);
for (JudgeLogic judge : logic) {
List<AtomicData> atomicData = judge.getAtomicData();
for (AtomicData atomic : atomicData) {
ids.add(atomic.getAtomicIndex());
}
}
10 months ago
List<ModelAtomicIndex> atomicIndexList = modelAtomicIndexService.selectBatchIds(ids);
10 months ago
index.setAtomicIndexList(atomicIndexList);
}
index.setAtomicIndexNum(ids.size());
}
iPage.setRecords(records);
return R.ok(IPages.buildDataMap(iPage));
}
@Override
public R<?> addOrUpd(ModelIndex modelIndex) {
int i = 0;
if (StringUtils.isEmpty(modelIndex.getId())) {
i = modelIndexMapper.insert(modelIndex);
} else {
i = modelIndexMapper.updateById(modelIndex);
}
if (i > 0) {
return R.okMsg("保存成功");
} else {
return R.fail("保存失败");
}
}
@Override
public R<?> del(String id) {
ModelIndex index = modelIndexMapper.selectById(id);
index.setDataStatus(StringUtils.getUUID());
int i = modelIndexMapper.updateById(index);
if (i > 0) {
return R.okMsg("删除成功");
} else {
return R.fail("删除失败");
}
}
@Override
public R<?> selectAllAtomic(ModelAtomicIndex modelAtomicIndex, Integer page, Integer size) {
IPage<ModelAtomicIndex> iPage = new Page<>(page, size);
10 months ago
iPage = modelAtomicIndexService.selectAll(iPage, modelAtomicIndex);
10 months ago
List<ModelAtomicIndex> records = iPage.getRecords();
List<ComDictionary> dicts = comDictionaryService.list();
for (ModelAtomicIndex index : records) {
index.setCaseTypeName(comDictionaryService.getName(dicts, "case_type", index.getCaseType()));
index.setIndexSourceName(comDictionaryService.getName(dicts, "index_source", index.getIndexSource()));
index.setRecordTypeName(comDictionaryService.getName(dicts, "record_type", index.getRecordType()));
}
iPage.setRecords(records);
return R.ok(IPages.buildDataMap(iPage));
}
@Override
public R<?> addOrUpdAtomic(ModelAtomicIndex modelAtomicIndex) {
int i = 0;
if (StringUtils.isEmpty(modelAtomicIndex.getId())) {
10 months ago
i = modelAtomicIndexService.getMapper().insert(modelAtomicIndex);
10 months ago
} else {
10 months ago
i = modelAtomicIndexService.getMapper().updateById(modelAtomicIndex);
10 months ago
}
if (i > 0) {
return R.okMsg("保存成功");
} else {
return R.fail("保存失败");
}
}
@Override
public R<?> delAtomic(String id) {
10 months ago
ModelAtomicIndex index = modelAtomicIndexService.getMapper().selectById(id);
10 months ago
index.setDataStatus(StringUtils.getUUID());
10 months ago
int i = modelAtomicIndexService.getMapper().updateById(index);
10 months ago
if (i > 0) {
return R.okMsg("删除成功");
} else {
return R.fail("删除失败");
}
}
10 months ago
@Override
public List<CaseAtomicIndexDTO> listCaseAtomicIndex(String caseId, String indexSource) {
Assert.notEmpty(caseId, "案件id不能为空");
ModelCase modelCase = modelCaseService.getById(caseId);
Assert.notNull(modelCase, "案件不存在");
String caseType = modelCase.getCaseType();
Assert.notEmpty(caseType, "案件类型不能为空");
// 获取案件类型对应的指标
List<ModelIndex> modelIndexList = modelIndexMapper.selectList(
Wrappers.lambdaQuery(ModelIndex.class)
.eq(ModelIndex::getCaseType, caseType)
.eq(ModelIndex::getIndexType, indexSource).eq(ModelIndex::getDataStatus, "1"));
10 months ago
if (CollUtil.isEmpty(modelIndexList)){
return new ArrayList<>(1);
}
// 从指标中计算出所有原子指标id
List<String> automicIndexIds = modelIndexList.stream().filter(modelIndex -> StrUtil.isNotEmpty(modelIndex.getJudgeLogic()))
.map(modelIndex -> pickAtomicIndexIds(modelIndex.getJudgeLogic()))
.flatMap(Collection::stream).distinct().toList();
if (CollUtil.isEmpty(automicIndexIds)){
return new ArrayList<>(1);
}
// 查询原子指标相关信息
List<ModelAtomicIndex> modelAtomicIndexList = modelAtomicIndexService.listCaseAtomicIndex(automicIndexIds, caseType, indexSource);
if (CollUtil.isEmpty(modelAtomicIndexList)){
return new ArrayList<>(1);
}
Map<String, ModelAtomicIndex> modelAtomicIndexMap = modelAtomicIndexList.stream().collect(Collectors.toMap(ModelAtomicIndex::getId, v -> v, (v1, v2) -> v1));
// 查询判定结果数据
List<ModelAtomicResult> modelAtomicResults = modelAtomicResultMapper.selectList(
Wrappers.lambdaQuery(ModelAtomicResult.class).eq(ModelAtomicResult::getCaseId, caseId)
.in(ModelAtomicResult::getAtomicId, automicIndexIds));
10 months ago
Map<String, ModelAtomicResult> modelAtomicResultMap = modelAtomicResults.stream()
.filter(modelAtomicResult -> StrUtil.isEmpty(modelAtomicResult.getAtomicId())).collect(Collectors.toMap(ModelAtomicResult::getAtomicId, v -> v, (v1, v2) -> v1));
// 以指标为基础数据,组装原子指标的值。然后把数据进行平铺
return modelIndexList.stream().flatMap(modelIndex -> {
String judgeLogic = modelIndex.getJudgeLogic();
List<String> indexIds = pickAtomicIndexIds(judgeLogic);
return indexIds.stream().map(indexId ->
new CaseAtomicIndexDTO(modelAtomicIndexMap.get(indexId), modelIndex, modelAtomicResultMap.get(indexId))).toList().stream();
10 months ago
}).toList();
}
/**
* id
* @param judgeLogic json
* @return id()
*/
10 months ago
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;
}
10 months ago
}