package com.ots.project.tool.report.MAQNEW.condition;
|
import com.ots.common.enums.LangTypeEnum;
|
import com.ots.common.utils.StringUtils;
|
import com.ots.project.exam.domain.TLibraryCode;
|
import com.ots.project.tool.report.MAQNEW.base.BaseCondition_V2;
|
import com.ots.project.tool.report.MAQNEW.base.MAQSummaryCondition_V2;
|
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 MAQSummary_V2 extends BaseCondition_V2 {
|
private final List<MAQSummaryCondition_V2> paramList;
|
private String name;
|
public MAQSummary_V2(String name, List<MAQSummaryCondition_V2> paramList) {
|
this.name = name;
|
this.paramList = paramList;
|
}
|
@Override
|
public TLibraryCode calculate(Map<String, String> map, LangTypeEnum langType) {
|
if (Objects.isNull(paramList) || paramList.isEmpty()) {
|
return null;
|
}
|
StringBuffer context = new StringBuffer();
|
paramList.stream().forEach(item -> {
|
TLibraryCode calculate = item.calculate(map, langType);
|
if (Objects.nonNull(calculate)) {
|
context.append(calculate.getLangTypeContext(langType));
|
context.append("%line-feed%");
|
}
|
});
|
TLibraryCode maqReportLibrary = new TLibraryCode();
|
if (StringUtils.isBlank(context)) {
|
if (langType == English) {
|
context.append("Mid-range on all these scales.Implications Notes: No strength and weakness was found.");
|
} else if (langType == Chinese) {
|
context.append("所有维度的分数都在中等范围,没有高分和低分项。");
|
} else if (langType == Thai) {
|
context.append("Mid-range on all these scales.Implications Notes: No strength and weakness was found.");
|
}
|
}
|
maqReportLibrary.setLangTypeContext(context.toString(), langType);
|
return maqReportLibrary;
|
}
|
@Override
|
public List<TLibraryCode> calculateList(Map<String, String> map, LangTypeEnum langType) {
|
if (Objects.isNull(paramList) || paramList.isEmpty()) {
|
return null;
|
}
|
StringBuffer context = new StringBuffer();
|
List<TLibraryCode> libcodes = new ArrayList<>();
|
List<Map<Integer, List<TLibraryCode>>> sortList = new ArrayList<>();
|
for (MAQSummaryCondition_V2 maqSummaryCondition_v2 : paramList) {
|
List<TLibraryCode> tLibraryCodes = maqSummaryCondition_v2.calculateList(map, langType);
|
if (tLibraryCodes != null && tLibraryCodes.size() > 0) {
|
Integer sortLevel = getSortLevel(tLibraryCodes, langType);
|
Map<Integer, List<TLibraryCode>> sortMap = new HashMap<>();
|
sortMap.put(sortLevel, tLibraryCodes);
|
sortList.add(sortMap);
|
}
|
}
|
sortList.sort(new Comparator<Map<Integer, List<TLibraryCode>>>() {
|
@Override
|
public int compare(Map<Integer, List<TLibraryCode>> o1, Map<Integer, List<TLibraryCode>> o2) {
|
Integer o1_level = new ArrayList<>(o1.keySet()).get(0);
|
Integer o2_level = new ArrayList<>(o2.keySet()).get(0);
|
if(o1_level.intValue() != o2_level.intValue()){
|
return o2_level - o1_level;
|
}else{
|
List<TLibraryCode> o1_tLibraryCodes = o1.get(o1_level);
|
List<TLibraryCode> o2_tLibraryCodes = o2.get(o2_level);
|
return Integer.parseInt(o2_tLibraryCodes.get(0).getScore()) - Integer.parseInt(o1_tLibraryCodes.get(0).getScore());
|
}
|
}
|
});
|
for (Map<Integer, List<TLibraryCode>> integerListMap : sortList) {
|
for (Integer integer : integerListMap.keySet()) {
|
libcodes.addAll(integerListMap.get(integer));
|
}
|
}
|
TLibraryCode maqReportLibrary = new TLibraryCode();
|
if (libcodes.size() < 1) {
|
if (langType == English) {
|
context.append("Mid-range on all these scales.Implications Notes: No strength and weakness was found.");
|
} else if (langType == Chinese) {
|
context.append("所有维度的分数都在中等范围,没有高分和低分项。");
|
} else if (langType == Thai) {
|
context.append("Mid-range on all these scales.Implications Notes: No strength and weakness was found.");
|
}
|
maqReportLibrary.setLangTypeContext(context.toString(), langType);
|
libcodes.add(maqReportLibrary);
|
} else {
|
libcodes.add(getMaqReportLibrary(map, "LIBMAQV233063", langType));
|
}
|
return libcodes;
|
}
|
private Integer getSortLevel(List<TLibraryCode> tLibraryCodes, LangTypeEnum langType) {
|
TLibraryCode tLibraryCode = tLibraryCodes.get(0);
|
String context = getContext(tLibraryCode, langType);
|
int index = 1;
|
while (context.indexOf("-") > 0 || context.indexOf("+") > 0) {
|
if (context.indexOf("-") > 0) {
|
context = context.replaceFirst("-", "");
|
index = index * 10;
|
} else if (context.indexOf("+") > 0) {
|
context = context.replaceFirst("\\+", "");
|
index = index * 1000;
|
}
|
}
|
return index;
|
}
|
private String getContext(TLibraryCode tLibraryCode, LangTypeEnum langType) {
|
String context = "";
|
if (langType == English) {
|
context = tLibraryCode.getEnglistContent();
|
} else if (langType == Chinese) {
|
context = tLibraryCode.getChineseContent();
|
} else if (langType == Thai) {
|
context = tLibraryCode.getThaiContent();
|
}
|
return context;
|
}
|
@Override
|
public Map<String, String> getMAQwaterDropsImages() {
|
return null;
|
}
|
}
|