package com.ots.project.tool.exam;
|
import com.ots.common.utils.StringUtils;
|
import java.util.Arrays;
|
import java.util.Date;
|
import java.util.HashMap;
|
import java.util.List;
|
import java.util.Map;
|
import java.util.Objects;
|
import java.util.regex.Pattern;
|
import java.util.stream.Collectors;
|
|
public class ExamUtil {
|
public static Map<String, String> productTypeMap = new HashMap<>();
|
public static Map<String, String> waterDropPictureMap = new HashMap<>();
|
public static Map<String, String> barPictureMap = new HashMap<>();
|
static {
|
setProductTypeMap();
|
setWaterDropAndBar();
|
}
|
private static void setProductTypeMap() {
|
productTypeMap.put("personality", "MAQ");
|
productTypeMap.put("job", "JAQ");
|
productTypeMap.put("RuiLin","RuiLin");
|
productTypeMap.put("MAQ", "MAQ");
|
productTypeMap.put("MAQV2", "MAQV2");
|
productTypeMap.put("SAQ", "SAQ");
|
productTypeMap.put("JAQ", "JAQ");
|
}
|
|
/**
|
* 设置水滴背景对应图片
|
*/
|
private static void setWaterDropAndBar() {
|
//水滴图片
|
waterDropPictureMap.put("ResponseFidelityDiagnosis", "waterDropDarkBlue.png");
|
waterDropPictureMap.put("ResponseFidelityDiagnosis_V2", "waterDropDarkBlue_V2.png");
|
//SAQ简易版
|
waterDropPictureMap.put("ResponseFidelityDiagnosisSAQGs", "waterDropDarkBlue_V2.png");
|
|
waterDropPictureMap.put("ResponseFidelityDiagnosisSAQ", "waterDropDarkBlue.png");
|
|
waterDropPictureMap.put("RuilinTestResultValidityDiagnosisContext", "waterDropDarkBlue.png");
|
waterDropPictureMap.put("PersonalEnergy", "waterDropRed.png");
|
waterDropPictureMap.put("SociallyOpen", "waterDropRed.png");
|
waterDropPictureMap.put("LeadingOthers", "waterDropRed.png");
|
waterDropPictureMap.put("Influencing", "waterDropRed.png");
|
waterDropPictureMap.put("AchievementOrientation", "waterDropGreed.png");
|
waterDropPictureMap.put("Dependability", "waterDropGreed.png");
|
waterDropPictureMap.put("Thoroughness", "waterDropGreed.png");
|
waterDropPictureMap.put("Persistence", "waterDropGreed.png");
|
waterDropPictureMap.put("Initiative", "waterDropGreed.png");
|
waterDropPictureMap.put("PlanningandOrganizing", "waterDropGreed.png");
|
waterDropPictureMap.put("TrustandIntegrity", "waterDropGreed.png");
|
waterDropPictureMap.put("Flexibility", "waterDropOrange.png");
|
waterDropPictureMap.put("Creativity", "waterDropOrange.png");
|
waterDropPictureMap.put("AnalyticalApproach", "waterDropOrange.png");
|
waterDropPictureMap.put("Independence", "waterDropOrange.png");
|
waterDropPictureMap.put("Self", "waterDropLilac.png");
|
waterDropPictureMap.put("ManagingStress", "waterDropLilac.png");
|
waterDropPictureMap.put("Mindfulness", "waterDropLilac.png");
|
waterDropPictureMap.put("CooperationTeamwork", "waterDropLightBlue.png");
|
waterDropPictureMap.put("Empathetic", "waterDropLightBlue.png");
|
waterDropPictureMap.put("PoliteTactful", "waterDropLightBlue.png");
|
//背景导航条
|
barPictureMap.put("ResponseFidelityDiagnosis_waterDrops1", "Bar1.png");
|
barPictureMap.put("ResponseFidelityDiagnosis_V2_waterDrops1", "Bar1_V2.png");
|
barPictureMap.put("ResponseFidelityDiagnosis_waterDrops2", "Bar1.png");
|
barPictureMap.put("ResponseFidelityDiagnosis_V2_waterDrops2", "Bar1_V2.png");
|
barPictureMap.put("ResponseFidelityDiagnosis_waterDrops3", "Bar2.png");
|
barPictureMap.put("ResponseFidelityDiagnosis_V2_waterDrops3", "Bar2_V2.png");
|
|
barPictureMap.put("ResponseFidelityDiagnosisSAQ_waterDrops1", "Bar1.png");
|
barPictureMap.put("ResponseFidelityDiagnosisSAQ_waterDrops2", "Bar1.png");
|
barPictureMap.put("ResponseFidelityDiagnosisSAQ_waterDrops3", "Bar2.png");
|
//增加SAQ简易版
|
barPictureMap.put("ResponseFidelityDiagnosisSAQGs_waterDrops1", "Bar1_V2.png");
|
barPictureMap.put("ResponseFidelityDiagnosisSAQGs_waterDrops2", "Bar1_V2.png");
|
barPictureMap.put("ResponseFidelityDiagnosisSAQGs_waterDrops3", "Bar2_V2.png");
|
|
barPictureMap.put("RuilinTestResultValidityDiagnosisContext_waterDrops1", "RuiLin1.png");
|
barPictureMap.put("RuilinTestResultValidityDiagnosisContext_waterDrops2", "RuiLin1.png");
|
barPictureMap.put("RuilinTestResultValidityDiagnosisContext_waterDrops3", "RuiLin2.png");
|
|
barPictureMap.put("Flexibility_1_waterDrops", "Bar3.png");
|
barPictureMap.put("Creativity_2_waterDrops", "Bar3.png");
|
barPictureMap.put("AnalyticalApproach_3_waterDrops", "Bar3.png");
|
barPictureMap.put("Independence_4_waterDrops", "Bar3.png");
|
|
barPictureMap.put("AchievementOrientation_5_waterDrops","Bar4.png");
|
barPictureMap.put("Initiative_6_waterDrops","Bar4.png");
|
barPictureMap.put("Persistence_7_waterDrops","Bar4.png");
|
barPictureMap.put("Thoroughness_8_waterDrops","Bar4.png");
|
barPictureMap.put("Dependability_9_waterDrops","Bar4.png");
|
barPictureMap.put("PlanningandOrganizing_10_waterDrops","Bar4.png");
|
barPictureMap.put("TrustandIntegrity_11_waterDrops","Bar4.png");
|
|
barPictureMap.put("PersonalEnergy_12_waterDrops", "Bar5.png");
|
barPictureMap.put("SociallyOpen_13_waterDrops", "Bar5.png");
|
barPictureMap.put("LeadingOthers_14_waterDrops", "Bar5.png");
|
barPictureMap.put("Influencing_15_waterDrops", "Bar5.png");
|
|
barPictureMap.put("CooperationTeamwork_16_waterDrops", "Bar6.png");
|
barPictureMap.put("Empathetic_17_waterDrops", "Bar6.png");
|
barPictureMap.put("PoliteTactful_18_waterDrops", "Bar6.png");
|
|
barPictureMap.put("Self_Regulation_19_waterDrops", "Bar7.png");
|
barPictureMap.put("ManagingStress_20_waterDrops", "Bar7.png");
|
barPictureMap.put("Self_Confidence_21_waterDrops", "Bar7.png");
|
barPictureMap.put("Mindfulness_22_waterDrops", "Bar7.png");
|
|
barPictureMap.put("Combined_waterDrops", "CAQBar1.png");
|
barPictureMap.put("P_Abstract_context_waterDrops", "CAQBar1.png");
|
barPictureMap.put("P_Numeric_context_waterDrops", "CAQBar1.png");
|
waterDropPictureMap.put("Combined_waterDrops", "waterDropOrange.png");
|
waterDropPictureMap.put("P_Abstract_context_waterDrops", "waterDropOrange.png");
|
waterDropPictureMap.put("P_Numeric_context_waterDrops", "waterDropOrange.png");
|
}
|
public static String scoreToVM(Integer score) {
|
if (score % 10 == 0) {
|
return String.valueOf(score / 10);
|
} else {
|
return String.format("%.1f", score / 10.0);
|
}
|
}
|
public static String originalScoreToVM(Integer score) {
|
return String.valueOf(score);
|
}
|
public static Integer scoreFromVM(String score) {
|
if (score == null) {
|
return null;
|
} else {
|
return (int) (Float.parseFloat(score) * 10);
|
}
|
}
|
public static String secondToVM(Integer second) {
|
String dateTimes;
|
long days = second / (60 * 60 * 24);
|
long hours = (second % (60 * 60 * 24)) / (60 * 60);
|
long minutes = (second % (60 * 60)) / 60;
|
long seconds = second % 60;
|
if (days > 0) {
|
dateTimes = days + "天 " + hours + "时 " + minutes + "分 " + seconds + "秒";
|
} else if (hours > 0) {
|
dateTimes = hours + "时 " + minutes + "分 " + seconds + "秒";
|
} else if (minutes > 0) {
|
dateTimes = minutes + "分 " + seconds + "秒";
|
} else {
|
dateTimes = seconds + " 秒";
|
}
|
return dateTimes;
|
}
|
private static final String ANSWER_SPLIT = ",";
|
public static String contentToString(List<String> contentArray) {
|
return contentArray.stream().sorted().collect(Collectors.joining(ANSWER_SPLIT));
|
}
|
public static List<String> contentToArray(String contentArray) {
|
return Arrays.asList(contentArray.split(ANSWER_SPLIT));
|
}
|
private static final String FORM_ANSWER_SPLIT = "_";
|
public static Integer lastNum(String str) {
|
Integer start = str.lastIndexOf(FORM_ANSWER_SPLIT);
|
return Integer.parseInt(str.substring(start + 1));
|
}
|
|
public static String html2Text(String inputString) {
|
String htmlStr = inputString;
|
String textStr = "";
|
java.util.regex.Pattern p_script;
|
java.util.regex.Matcher m_script;
|
java.util.regex.Pattern p_xml;
|
java.util.regex.Matcher m_xml;
|
java.util.regex.Pattern p_style;
|
java.util.regex.Matcher m_style;
|
java.util.regex.Pattern p_html;
|
java.util.regex.Matcher m_html;
|
try {
|
String regEx_script = "<[\\s]*?script[^>]*?>[\\s\\S]*?<[\\s]*?\\/[\\s]*?script[\\s]*?>";
|
String regEx_xml = "<[\\s]*?xml[^>]*?>[\\s\\S]*?<[\\s]*?\\/[\\s]*?xml[\\s]*?>";
|
String regEx_style = "<[\\s]*?style[^>]*?>[\\s\\S]*?<[\\s]*?\\/[\\s]*?style[\\s]*?>";
|
String regEx_html = "<[^>]+>";
|
p_script = Pattern.compile(regEx_script, Pattern.CASE_INSENSITIVE);
|
m_script = p_script.matcher(htmlStr);
|
htmlStr = m_script.replaceAll("");
|
|
p_xml = Pattern.compile(regEx_xml, Pattern.CASE_INSENSITIVE);
|
m_xml = p_xml.matcher(htmlStr);
|
htmlStr = m_xml.replaceAll("");
|
p_style = Pattern.compile(regEx_style, Pattern.CASE_INSENSITIVE);
|
m_style = p_style.matcher(htmlStr);
|
htmlStr = m_style.replaceAll("");
|
p_html = Pattern.compile(regEx_html, Pattern.CASE_INSENSITIVE);
|
m_html = p_html.matcher(htmlStr);
|
htmlStr = m_html.replaceAll("");
|
textStr = htmlStr;
|
} catch (Exception e) {
|
System.err.println("Html2Text: " + e.getMessage());
|
}
|
|
textStr = textStr.replaceAll("[ ]+", " ");
|
textStr = textStr.replaceAll("(?m)^\\s*$(\\n|\\r\\n)", "");
|
return textStr;
|
}
|
|
public static String getStringMapJson(String langType, String content, Map<String, String> map) {
|
if (StringUtils.isEmpty(content)) {
|
return JsonUtil.toJSONString(map);
|
}
|
if (Objects.isNull(map)) {
|
map = new HashMap<>();
|
}
|
map.put(langType, content);
|
return JsonUtil.toJSONString(map);
|
}
|
public static String getStringMapJson(String langType, String content, String srcContent) {
|
if (StringUtils.isEmpty(langType)) {
|
return "";
|
}
|
if (StringUtils.isEmpty(content) && StringUtils.isEmpty(srcContent)) {
|
return "";
|
}
|
Map<String, String> map = null;
|
if (StringUtils.isEmpty(srcContent)) {
|
map = new HashMap<>();
|
} else {
|
map = JsonUtil.parseObject(srcContent, HashMap.class);
|
}
|
if (Objects.isNull(map)) {
|
map = new HashMap<>();
|
}
|
Map<String, String> mapNew = null;
|
if (StringUtils.isEmpty(content)) {
|
return JsonUtil.toJSONString(map);
|
} else {
|
mapNew = JsonUtil.parseObject(content, HashMap.class);
|
}
|
if (Objects.isNull(map) && Objects.isNull(mapNew)) {
|
return srcContent;
|
}
|
|
if (Objects.isNull(mapNew)) {
|
map.put(langType, content);
|
} else if (StringUtils.equals(langType, "ALL") || StringUtils.isEmpty(langType)) {
|
map.putAll(mapNew);
|
} else if (Objects.nonNull(mapNew) && StringUtils.isNotEmpty(mapNew.get(langType))) {
|
map.put(langType, mapNew.get(langType));
|
} else {
|
map.put(langType, content);
|
}
|
return JsonUtil.toJSONString(map);
|
}
|
|
public static String getLangString(String langType, String contentMapJson) {
|
if (StringUtils.isEmpty(contentMapJson)) {
|
return "";
|
}
|
if (StringUtils.isEmpty(langType)) {
|
return contentMapJson;
|
}
|
Map<String, String> contentMap = JsonUtil.parseObject(contentMapJson, HashMap.class);
|
if (Objects.isNull(contentMap)) {
|
return contentMapJson;
|
}
|
|
if (StringUtils.isNotEmpty(contentMap.get(langType))) {
|
return contentMap.get(langType);
|
} else if (StringUtils.isNotEmpty(contentMap.get("English"))) {
|
contentMap.get("English");
|
}
|
if (contentMap.isEmpty()) {
|
return "";
|
}
|
|
return contentMap.values().stream().findFirst().get();
|
}
|
|
public static String getStringByLang(String langType, String contentMapJson) {
|
if (StringUtils.isEmpty(contentMapJson)) {
|
return "";
|
}
|
if (StringUtils.isEmpty(langType)) {
|
return contentMapJson;
|
}
|
Map<String, String> contentMap = JsonUtil.parseObject(contentMapJson, HashMap.class);
|
if (Objects.isNull(contentMap)) {
|
return contentMapJson;
|
}
|
|
if (StringUtils.isNotEmpty(contentMap.get(langType))) {
|
return contentMap.get(langType);
|
} else {
|
return "";
|
}
|
}
|
|
public static String deleteLangString(String langType, String contentMapJson) {
|
if (StringUtils.isEmpty(contentMapJson)) {
|
return "";
|
}
|
Map<String, String> contentMap = JsonUtil.parseObject(contentMapJson, HashMap.class);
|
if (Objects.isNull(contentMap)) {
|
return contentMapJson;
|
}
|
if (StringUtils.isEmpty(langType)) {
|
return contentMapJson;
|
}
|
contentMap.remove(langType);
|
return JsonUtil.toJSONString(contentMap);
|
}
|
|
public static boolean isListEmpty(List<?> objList) {
|
if (Objects.isNull(objList)) {
|
return true;
|
}
|
return objList.isEmpty();
|
}
|
public static boolean isListNotEmpty(List<?> objList) {
|
return !isListEmpty(objList);
|
}
|
public static long timeSpent(Date startDate, Date endDate) {
|
if (Objects.isNull(startDate) || Objects.isNull(endDate)) {
|
return 0L;
|
}
|
long startTime = startDate.getTime();
|
long endTime = endDate.getTime();
|
long timeDifference = endTime - startTime;
|
long second = timeDifference / 1000;
|
return second;
|
}
|
public static Map<String, String> getProudctTypeMap() {
|
return productTypeMap;
|
}
|
public static String getWaterDropPictureMap(String key) {
|
if (StringUtils.isEmpty(key)) {
|
return "";
|
}
|
String value = waterDropPictureMap.get(key);
|
if (StringUtils.isNotEmpty(value)) {
|
return value;
|
}
|
return "";
|
}
|
public static String getBarPictureMap(String key) {
|
if (StringUtils.isEmpty(key)) {
|
return "";
|
}
|
String value = barPictureMap.get(key);
|
if (StringUtils.isNotEmpty(value)) {
|
return value;
|
}
|
return "";
|
}
|
}
|