全新模型分析方法整体调整
parent
e7921a26a4
commit
42ba581ea6
@ -0,0 +1,29 @@
|
||||
package com.supervision.police.handler;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.handlers.AbstractJsonTypeHandler;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.supervision.police.dto.indexRule.IndexRule;
|
||||
|
||||
public class IndexRuleTypeHandler extends AbstractJsonTypeHandler<IndexRule> {
|
||||
private static final ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
@Override
|
||||
protected IndexRule parse(String json) {
|
||||
try {
|
||||
return objectMapper.readValue(json, new TypeReference<IndexRule>() {
|
||||
});
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Failed to parse JSON to List<IndexRule>", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String toJson(IndexRule obj) {
|
||||
try {
|
||||
return objectMapper.writeValueAsString(obj);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Failed to convert List<IndexRule> to JSON", e);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,7 +1,4 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.supervision.police.mapper.ModelIndexMapper">
|
||||
<select id="selectByCaseType" resultType="com.supervision.police.domain.ModelIndex">
|
||||
select * from model_index where data_status = '1' and case_type = #{caseType}
|
||||
</select>
|
||||
</mapper>
|
@ -0,0 +1,80 @@
|
||||
package com.supervision.demo;
|
||||
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.supervision.police.domain.ModelAtomicIndex;
|
||||
import com.supervision.police.domain.ModelIndex;
|
||||
import com.supervision.police.dto.AnalyseCaseDTO;
|
||||
import com.supervision.police.dto.JudgeLogic;
|
||||
import com.supervision.police.dto.indexRule.*;
|
||||
import com.supervision.police.service.ModelAtomicIndexService;
|
||||
import com.supervision.police.service.ModelIndexService;
|
||||
import com.supervision.police.service.ModelService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Slf4j
|
||||
@SpringBootTest
|
||||
public class CaseTest {
|
||||
|
||||
@Autowired
|
||||
private ModelService modelService;
|
||||
@Autowired
|
||||
private ModelIndexService modelIndexService;
|
||||
@Autowired
|
||||
private ModelAtomicIndexService modelAtomicIndexService;
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
long start = System.currentTimeMillis();
|
||||
AnalyseCaseDTO analyseCaseDTO = new AnalyseCaseDTO();
|
||||
analyseCaseDTO.setCaseId("1831221360763416578");
|
||||
modelService.analyseCaseNew(analyseCaseDTO);
|
||||
long end = System.currentTimeMillis();
|
||||
log.info("耗时:{}ms", end - start);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void judgeLogicTransform() {
|
||||
List<ModelIndex> indices = modelIndexService.list();
|
||||
List<ModelAtomicIndex> modelAtomicIndices = modelAtomicIndexService.list();
|
||||
indices.forEach(index -> {
|
||||
String judgeLogicStr = index.getJudgeLogic();
|
||||
List<JudgeLogic> judgeLogics = JSONUtil.toList(judgeLogicStr, JudgeLogic.class);
|
||||
IndexRule indexRule = new IndexRule();
|
||||
if (judgeLogics.size() == 2) {
|
||||
indexRule.setGroupLogic(judgeLogics.get(1).getGroupLogic());
|
||||
}
|
||||
List<RuleConditionGroup> ruleConditionGroups = new ArrayList<>();
|
||||
judgeLogics.forEach(judgeLogic -> {
|
||||
RuleConditionGroup ruleConditionGroup = new RuleConditionGroup();
|
||||
List<RuleCondition> ruleConditions = new ArrayList<>();
|
||||
if (!judgeLogic.getRowLogic().equals("&")) {
|
||||
ruleConditionGroup.setRowLogic(judgeLogic.getRowLogic());
|
||||
}
|
||||
judgeLogic.getAtomicData().forEach(atomicData -> {
|
||||
RuleCondition ruleCondition = new RuleCondition();
|
||||
OperandUnit operandUnit = new OperandUnit();
|
||||
Operand left = new Operand();
|
||||
left.setAtomicIndexId(atomicData.getAtomicIndex());
|
||||
left.setRelationalSymbol(atomicData.getRelationalSymbol());
|
||||
modelAtomicIndices.stream().filter(modelAtomicIndex -> modelAtomicIndex.getId().equals(atomicData.getAtomicIndex())).findFirst().ifPresent(modelAtomicIndex -> {
|
||||
left.setOperandType(modelAtomicIndex.getIndexSource());
|
||||
});
|
||||
operandUnit.setLeftOperand(left);
|
||||
ruleCondition.setOperandUnitList(List.of(operandUnit));
|
||||
ruleConditions.add(ruleCondition);
|
||||
});
|
||||
ruleConditionGroup.setRuleConditionList(ruleConditions);
|
||||
ruleConditionGroups.add(ruleConditionGroup);
|
||||
});
|
||||
indexRule.setRuleConditionGroupList(ruleConditionGroups);
|
||||
index.setIndexRule(indexRule);
|
||||
modelIndexService.updateById(index);
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue