package com.ots.project.tool.report.MAQNEW.base;
|
import com.ots.common.enums.LangTypeEnum;
|
import com.ots.project.exam.domain.TLibraryCode;
|
import com.ots.project.tool.report.MAQ.base.MAQConditionVO;
|
import lombok.Getter;
|
import lombok.Setter;
|
import lombok.extern.slf4j.Slf4j;
|
import java.util.*;
|
import static com.ots.common.enums.LangTypeEnum.*;
|
@Setter
|
@Getter
|
@Slf4j
|
public class MAQSummaryCondition_V2 extends BaseCondition_V2 {
|
private String name;
|
private MAQConditionVO conditionVO;
|
private Double conditionValue;
|
public MAQSummaryCondition_V2(MAQConditionVO conditionVO) {
|
this.name = conditionVO.getName();
|
this.conditionVO = conditionVO;
|
}
|
@Override
|
public Map<String, String> getMAQwaterDropsImages() {
|
HashMap<String, String> map = new HashMap<>();
|
map.put(name + IMAGE_PREFIX, Objects.isNull(conditionValue) ? "0" : String.valueOf(conditionValue));
|
return map;
|
}
|
@Override
|
public TLibraryCode calculate(Map<String, String> map, LangTypeEnum langType) {
|
try {
|
String conditionKey = conditionVO.getConditionKey();
|
String conValue = map.get(conditionKey);
|
if (checkParamsIsNull(conValue)) {
|
return null;
|
}
|
conditionValue = Double.valueOf(conValue);
|
List<String> conditionTarget = conditionVO.getConditionTarget();
|
boolean jianjian = conditionValue <= 5;
|
boolean jian = 5 < conditionValue && conditionValue <= 30;
|
boolean jia = 70 <= conditionValue && conditionValue < 95;
|
boolean jiajia = conditionValue >= 95;
|
String prefix = getPrefix(jianjian, jian, jia, jiajia);
|
if (Objects.isNull(prefix)) {
|
return null;
|
}
|
Map calculateMap = new HashMap();
|
calculateMap.put(jianjian, conditionTarget.get(0));
|
calculateMap.put(jian, conditionTarget.get(1));
|
calculateMap.put(jia, conditionTarget.get(4));
|
calculateMap.put(jiajia, conditionTarget.get(5));
|
String codeId = selectTrueObject(calculateMap);
|
|
TLibraryCode library = getMaqReportLibrary(map, codeId, langType);
|
|
String split = getTitleByLang(conditionVO.getTitle(), langType);
|
String context = "<BoldText>" + prefix + split + "</BoldText> " + library.getLangTypeContext(langType);
|
library.setLangTypeContext(context, langType);
|
return library;
|
} catch (Exception ex) {
|
log.error("MAQCondition error name={},conditionKey={},conditionTarget={} error:{}", name, conditionVO.getConditionKey(), conditionVO.getConditionTarget(), ex.getMessage(), ex);
|
return null;
|
}
|
}
|
@Override
|
public List<TLibraryCode> calculateList(Map<String, String> map, LangTypeEnum langType) {
|
try {
|
String conditionKey = conditionVO.getConditionKey();
|
String conValue = map.get(conditionKey);
|
if (checkParamsIsNull(conValue)) {
|
return null;
|
}
|
conditionValue = Double.valueOf(conValue);
|
List<String> conditionTarget = conditionVO.getConditionTarget();
|
boolean jianjian = conditionValue <= 5;
|
boolean jian = 5 < conditionValue && conditionValue <= 30;
|
boolean jia = 70 <= conditionValue && conditionValue < 95;
|
boolean jiajia = conditionValue >= 95;
|
String prefix = getPrefix(jianjian, jian, jia, jiajia);
|
if (Objects.isNull(prefix)) {
|
return null;
|
}
|
Map calculateMap = new HashMap();
|
calculateMap.put(jianjian, conditionTarget.get(0));
|
calculateMap.put(jian, conditionTarget.get(1));
|
calculateMap.put(jia, conditionTarget.get(4));
|
calculateMap.put(jiajia, conditionTarget.get(5));
|
String codeId = selectTrueObject(calculateMap);
|
String[] codes = codeId.split(",");
|
List<TLibraryCode> libcodes = new ArrayList<>();
|
Arrays.stream(codes).forEach(item -> {
|
libcodes.add(getMaqReportLibrary(map, item, langType));
|
});
|
TLibraryCode headLib = new TLibraryCode();
|
|
String split = getTitleByLang(conditionVO.getTitle(), langType);
|
String context = "<BoldText>" + prefix + split + "</BoldText> ";
|
headLib.setLibraryCode("0");
|
headLib.setLangTypeContext(context, langType);
|
headLib.setScore(conValue);
|
libcodes.add(headLib);
|
libcodes.sort(new Comparator<TLibraryCode>() {
|
@Override
|
public int compare(TLibraryCode o1, TLibraryCode o2) {
|
return o1.getLibraryCode().compareTo(o2.getLibraryCode());
|
}
|
});
|
return libcodes;
|
} catch (Exception ex) {
|
log.error("MAQCondition error name={},conditionKey={},conditionTarget={} error:{}", name, conditionVO.getConditionKey(), conditionVO.getConditionTarget(), ex.getMessage(), ex);
|
return null;
|
}
|
}
|
private String getTitleByLang(String title, LangTypeEnum langType) {
|
String[] split = title.split(",");
|
if (langType == English) {
|
return split[0];
|
} else if (langType == Chinese) {
|
return split[1];
|
}
|
return "noConfiguration";
|
}
|
private String getPrefix(boolean jianjian, boolean jian, boolean jia, boolean jiajia) {
|
String prefix = "";
|
if (jianjian) {
|
prefix = "--";
|
} else if (jian) {
|
prefix = "-";
|
} else if (jia) {
|
prefix = "+";
|
} else if (jiajia) {
|
prefix = "++";
|
} else {
|
prefix = null;
|
}
|
return prefix;
|
}
|
}
|