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/dto/ModelIndexDTO.java

152 lines
4.4 KiB
Java

1 year ago
package com.supervision.police.dto;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
import com.supervision.common.utils.StringUtils;
import com.supervision.police.domain.ModelIndex;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import javax.imageio.plugins.tiff.TIFFDirectory;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
@Data
@Slf4j
public class ModelIndexDTO {
@Schema(description = "指标id")
private String id;
@Schema(description = "指标名称")
private String name;
@Schema(description = "指标简称")
private String shortName;
@Schema(description = "指标说明")
private String remark;
@Schema(description = "指标类别")
private String indexType;
@Schema(description = "指标分数")
private Integer indexScore;
@Schema(description = "案件类型")
private String caseType;
@Schema(description = "判断逻辑字符串")
private String judgeLogic;
@Schema(description = "判断逻辑list")
private List<JudgeLogic> judgeLogicList;
public ModelIndexDTO() {
}
public ModelIndexDTO(ModelIndex modelIndex) {
if (Objects.isNull(modelIndex)){
return;
}
this.id = modelIndex.getId();
this.name = modelIndex.getName();
this.shortName = modelIndex.getShortName();
this.remark = modelIndex.getRemark();
this.indexType = modelIndex.getIndexType();
this.indexScore = modelIndex.getIndexScore();
this.caseType = modelIndex.getCaseType();
this.judgeLogic = modelIndex.getJudgeLogic();
if (StrUtil.isNotEmpty(this.judgeLogic)){
try {
this.judgeLogicList = JSONUtil.toList(this.judgeLogic, JudgeLogic.class);
} catch (Exception e) {
log.error("ModelIndexDTO: 解析judgeLogic失败:id:{},judgeLogic:{}",this.id,this.judgeLogic,e);
}
}
}
/**
*
* @param atomicIndexId id
* @return
*/
public boolean logicContainAtomicIndex(String atomicIndexId) {
if (StrUtil.isEmpty(atomicIndexId)){
return false;
}
if (CollUtil.isEmpty(this.judgeLogicList)) {
return false;
}
return this.judgeLogicList.stream().anyMatch(logic -> logicContainAtomicIndex(logic, atomicIndexId));
}
private boolean logicContainAtomicIndex(JudgeLogic logic,String atomicIndexId) {
if (Objects.isNull(logic)){
return false;
}
List<AtomicData> atomicData = logic.getAtomicData();
if (CollUtil.isEmpty(atomicData)){
return false;
}
for (AtomicData atomicDatum : atomicData) {
if (atomicIndexId.equals(atomicDatum.getAtomicIndex())){
return true;
}
}
return false;
}
/**
*
* @param atomicIndexId id
* @return
*/
public List<JudgeLogic> judgeLogicExcludeAtomicIndex(String atomicIndexId) {
if (StrUtil.isEmpty(atomicIndexId)){
return this.judgeLogicList;
}
if (CollUtil.isEmpty(this.judgeLogicList)){
return CollUtil.newArrayList();
}
List<JudgeLogic> result = new ArrayList<>();
for (JudgeLogic logic : this.judgeLogicList) {
if (Objects.isNull(logic)){
continue;
}
List<AtomicData> atomicDataList = new ArrayList<>();
for (AtomicData atomicDatum : logic.getAtomicData()) {
if (!atomicIndexId.equals(atomicDatum.getAtomicIndex())){
atomicDataList.add(atomicDatum);
}
}
JudgeLogic resultLogic = new JudgeLogic();
resultLogic.setRowLogic(logic.getRowLogic());
resultLogic.setGroupLogic(logic.getGroupLogic());
resultLogic.setAtomicData(atomicDataList);
result.add(resultLogic);
}
return result;
}
/**
* listjson
* @param judgeLogicList
* @return
*/
public String judgeLogicToJson(List<JudgeLogic> judgeLogicList) {
return JSONUtil.toJsonStr(judgeLogicList);
}
}