wangchangsheng 1 год назад
Родитель
Сommit
bad96ba1e7

+ 44 - 8
ims-service/ims-eval/src/main/java/com/ims/eval/service/impl/OrganizationEvaluationInfoServiceImpl.java

@@ -34,6 +34,8 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.math.BigDecimal;
 import java.util.*;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 import java.util.stream.Collectors;
 
 import static com.ims.eval.util.ExcelUtil.readExcel;
@@ -230,22 +232,32 @@ public class OrganizationEvaluationInfoServiceImpl extends ServiceImpl<Organizat
 									List<OrganizationEvaluationInfoResDTO> indicator = ruleIdGropListEntry.getValue();
 									Map<String, List<OrganizationEvaluationInfoResDTO>> childCodeGropList = indicator.stream().collect(Collectors.groupingBy(OrganizationEvaluationInfoResDTO::getChildCode));
 
-									double totalScore = 0.00;
+//									double totalScore = 0.00;
 									for (Map.Entry<String, List<OrganizationEvaluationInfoResDTO>> childCodeGropListEntry : childCodeGropList.entrySet()) {
 										for (OrganizationEvaluationInfoResDTO dto : childCodeGropListEntry.getValue()) {
 
-											if ((!dto.getOptionCode().equals("CZ") && !dto.getOptionCode().equals("LRGXL") && !dto.getOptionCode().equals("DWQWLR")) || StringUtils.isEmpty(dto.getFormula())) {
+											if (!(dto.getOptionCode().equals("LRZE") || dto.getOptionCode().equals("CZ") ||  dto.getOptionCode().equals("LRGXKH")|| dto.getOptionCode().equals("LRGXL") || dto.getOptionCode().equals("DWQWLR")) || StringUtils.isEmpty(dto.getFormula())) {
+												System.out.println("前置跳过--|"+dto.getOptionCode());
 												continue;//当前属性没有配置公式跳过
 											}
 
-											for (OrganizationEvaluationInfoResDTO f : childCodeGropListEntry.getValue()) {
+											//获取去参与计算的属性
+											List<String> optionCodes = getOptionCode(dto.getFormula());
+
+											List<OrganizationEvaluationInfoResDTO> newInfoResInfo = childCodeGropListEntry.getValue().stream()
+																									.filter(item -> optionCodes.contains(item.getOptionCode()))
+																									.collect(Collectors.toList());
+
+											//循环替换属性
+											for (OrganizationEvaluationInfoResDTO f : newInfoResInfo) {
 												dto.setFormula(dto.getFormula().replace("[" + f.getOptionCode() + "]", f.getQuantifiedValue() + ""));
 											}
+
 											double score = FormulaUtils.calculateFormula(dto.getFormula());
-											if (StringUtils.inStringIgnoreCase("DF", dto.getOptionCode())) {
-												totalScore = totalScore + score;
-											}
-											log.info(dto.getOrganizationShortName() + "|" + dto.getChildName() + "|" + dto.getOptionCode() + "----------" + dto.getFormula() + "=" + score);
+//											if (StringUtils.inStringIgnoreCase("DF", dto.getOptionCode())) {
+//												totalScore = totalScore + score;
+//											}
+											log.info(dto.getOrganizationShortName() + "|" + dto.getChildName() + "|" + dto.getOptionCode() + "|" + dto.getFormula() + "=" + score);
 											OrganizationEvaluationInfo info = baseMapper.selectById(dto.getId());
 											//将计算结果保存
 											info.setQuantifiedValue(score);
@@ -310,7 +322,15 @@ public class OrganizationEvaluationInfoServiceImpl extends ServiceImpl<Organizat
 											scoreCount.setBinStage(dto.getBinStage());
 											scoreCount.setBinSection(dto.getBinSection());
 
-											for (OrganizationEvaluationInfoResDTO f : childCodeGropListEntry.getValue()){
+											//获取去参与计算的属性
+											List<String> optionCodes = getOptionCode(dto.getFormula());
+											List<OrganizationEvaluationInfoResDTO> newInfoResInfo = childCodeGropListEntry.getValue().stream()
+													.filter(item -> optionCodes.contains(item.getOptionCode()))
+													.collect(Collectors.toList());
+
+
+											//替换属性值
+											for (OrganizationEvaluationInfoResDTO f : newInfoResInfo){
 												if(f.getOptionCode().endsWith("MIN") || f.getOptionCode().endsWith("MAX")){
 													System.out.println("-------"+f.getOptionCode());
 													f.setQuantifiedValue(map.get(f.getOptionCode()));
@@ -1133,4 +1153,20 @@ public class OrganizationEvaluationInfoServiceImpl extends ServiceImpl<Organizat
 	}
 
 
+
+	private List<String> getOptionCode(String formula){
+		List<String> optionCode = new ArrayList<>();
+		String pattern = "\\[(.*?)\\]";
+		Pattern regex = Pattern.compile(pattern);
+		Matcher matcher = regex.matcher(formula);
+		while (matcher.find()) {
+			String match = matcher.group(1);
+			optionCode.add(match);
+		}
+		Set<String> uniqueOptionCode = new HashSet<>(optionCode);
+		List<String> setOptionCode = new ArrayList<>(uniqueOptionCode);
+		return setOptionCode;
+	}
+
+
 }