|
@@ -0,0 +1,434 @@
|
|
|
+package com.rf.psychological.scale.resultBusiness.scaleResult;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.rf.psychological.dao.dto.scale.NewResultDto;
|
|
|
+import com.rf.psychological.dao.model.AnswerEntity;
|
|
|
+import com.rf.psychological.dao.model.DimensionEntity;
|
|
|
+import com.rf.psychological.scale.dao.model.ScaleMarksEntity;
|
|
|
+import com.rf.psychological.scale.scaleresult.ScaleConstant;
|
|
|
+import com.rf.psychological.utils.Constant;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.lang.StringUtils;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
+import org.springframework.lang.Nullable;
|
|
|
+
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.text.DecimalFormat;
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author lpf
|
|
|
+ * @description:新量表(需要图表信息之类的)保存处理接口
|
|
|
+ * @date 2022/4/22 15:55
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+public class NEWCOMMONScaleCPH extends BaseScale {
|
|
|
+
|
|
|
+ public NEWCOMMONScaleCPH(JSONArray jsonArray, JSONObject resultJson) {
|
|
|
+ super(jsonArray, resultJson);
|
|
|
+ }
|
|
|
+
|
|
|
+ public JSONObject scaleCalculate() throws Exception {
|
|
|
+
|
|
|
+ //总分
|
|
|
+ double score = 0;
|
|
|
+ DecimalFormat df = new DecimalFormat("######0.00");
|
|
|
+
|
|
|
+ Map<String, String> resultMap0 = new LinkedHashMap<>();
|
|
|
+ List<Map<String, String>> resultMapList = new ArrayList<>();
|
|
|
+ //新版本数据格式
|
|
|
+ Map<String, Object> newResult = new LinkedHashMap<>();
|
|
|
+
|
|
|
+ String gender = (String) resultJson.get("gender");
|
|
|
+ String flag = (String) resultJson.get("flag");
|
|
|
+ //获取答案列表
|
|
|
+ List<AnswerEntity> answerEntities = (List<AnswerEntity>) resultJson.get("answerEntities");
|
|
|
+ AnswerEntity answer=answerEntities.stream().filter(item->StringUtils.isEmpty(item.getScore())).findFirst().orElse(null);
|
|
|
+ log.info("空分数==="+answer);
|
|
|
+ //获取评分规则列表
|
|
|
+ List<ScaleMarksEntity> scaleMarksEntities = (List<ScaleMarksEntity>) resultJson.get("scaleMarksEntities");
|
|
|
+ //抑郁形容词检查表特殊处理
|
|
|
+ if (Constant.QUEST_FLAG_DACL.equals(flag)) {
|
|
|
+ for (int i = 0; i < scaleMarksEntities.size(); i++) {
|
|
|
+ ScaleMarksEntity entity = scaleMarksEntities.get(i);
|
|
|
+ if (i % 4 == 0) {
|
|
|
+ if ("0".equals(gender)) {
|
|
|
+ entity.setScoreStart("0");
|
|
|
+ entity.setScoreEnd("10");
|
|
|
+ } else {
|
|
|
+ entity.setScoreStart("0");
|
|
|
+ entity.setScoreEnd("11");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (i % 4 == 1) {
|
|
|
+ if ("0".equals(gender)) {
|
|
|
+ entity.setScoreStart("11");
|
|
|
+ entity.setScoreEnd("15");
|
|
|
+ } else {
|
|
|
+ entity.setScoreStart("12");
|
|
|
+ entity.setScoreEnd("16");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (i % 4 == 2) {
|
|
|
+ if ("0".equals(gender)) {
|
|
|
+ entity.setScoreStart("16");
|
|
|
+ entity.setScoreEnd("21");
|
|
|
+ } else {
|
|
|
+ entity.setScoreStart("17");
|
|
|
+ entity.setScoreEnd("23");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (i % 4 == 3) {
|
|
|
+ if ("0".equals(gender)) {
|
|
|
+ entity.setScoreStart("22");
|
|
|
+ entity.setScoreEnd("34");
|
|
|
+ } else {
|
|
|
+ entity.setScoreStart("24");
|
|
|
+ entity.setScoreEnd("34");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //艾森克人格量表常模参考值处理
|
|
|
+ if (Constant.QUEST_FLAG_EPQ.equals(flag) || Constant.QUEST_FLAG_TAS_26.equals(flag)) {
|
|
|
+ for (int i = 0; i < scaleMarksEntities.size(); i++) {
|
|
|
+ ScaleMarksEntity entity = scaleMarksEntities.get(i);
|
|
|
+ if (StringUtils.isEmpty(entity.getReference())) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ String[] referencs = entity.getReference().split(")");
|
|
|
+ if (referencs.length < 2) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ String manReferenc = referencs[0].replace("男", "").replace("(", "").trim();
|
|
|
+ String wouManReferenc = referencs[1].replace("女", "").replace("(", "").replace(")", "")
|
|
|
+ .replace("(", "").trim();
|
|
|
+ if ("0".equals(gender)) {
|
|
|
+ entity.setReference(manReferenc);
|
|
|
+ } else {
|
|
|
+ entity.setReference(wouManReferenc);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //获取维度信息列表
|
|
|
+ List<DimensionEntity> dimensionEntities = (List<DimensionEntity>) resultJson.get("dimensionEntities");
|
|
|
+ //计算每个维度得分dimensionEntities
|
|
|
+ double[] dimensionScore = new double[dimensionEntities.size()];
|
|
|
+ Map<String, Double> dimensionScoreMap = new HashMap<>();
|
|
|
+ //jsonArray:用户自己选择的题目选项
|
|
|
+ for (int i = 0; i < jsonArray.size(); i++) {
|
|
|
+ JSONObject jsonObject1 = jsonArray.getJSONObject(i);
|
|
|
+ //计算总分
|
|
|
+ for (AnswerEntity answerEntity : answerEntities) {
|
|
|
+ if (answerEntity.getQuestionNo().equals(jsonObject1.getString("questionNo"))) {
|
|
|
+ if (answerEntity.getName().replaceAll("\\s", "").equals(jsonObject1.getString("checkItems").replaceAll("\\s", ""))) {
|
|
|
+ score += Double.parseDouble(answerEntity.getScore());
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //计算维度分数
|
|
|
+ for (int y = 0; y < dimensionEntities.size(); y++) {
|
|
|
+ //获取维度信息
|
|
|
+ DimensionEntity dimensionEntity = dimensionEntities.get(y);
|
|
|
+ //获取该维度下有哪些选项
|
|
|
+ String questionNos = dimensionEntity.getQuestionNo();
|
|
|
+ //删除空白字符后得到进行划分得到选择题号
|
|
|
+ String[] questionNo = questionNos.replaceAll("\\s", "").split(";");
|
|
|
+ //计算每道题的得分
|
|
|
+ for (String question : questionNo) {
|
|
|
+ if (question.equals(jsonObject1.getString("questionNo"))) {
|
|
|
+ //获取所有答案中本道题目的答案list数组
|
|
|
+ List<AnswerEntity> nowQuestionAnswerList = answerEntities.stream().filter(answerEntity -> answerEntity.getQuestionNo().equals(question)).collect(Collectors.toList());
|
|
|
+ //本题目的正确答案与自己的选项进行对比,正确的话相应分数进行相加
|
|
|
+ for (AnswerEntity answerEntity : nowQuestionAnswerList) {
|
|
|
+ if (answerEntity.getName().replaceAll("\\s", "").equals(jsonObject1.getString("checkItems").replaceAll("\\s", ""))) {
|
|
|
+ dimensionScoreMap.put(dimensionEntity.getId(), dimensionScoreMap.get(dimensionEntity.getId()) == null ? Double.parseDouble(answerEntity.getScore()) : (dimensionScoreMap.get(dimensionEntity.getId()) + Double.parseDouble(answerEntity.getScore())));
|
|
|
+ dimensionScore[y] += Double.parseDouble(answerEntity.getScore());
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ resultJson.put("dimensionScoreMap", dimensionScoreMap);
|
|
|
+ }
|
|
|
+
|
|
|
+ //判断维度分是否为求平均值
|
|
|
+ boolean totalMark = true;
|
|
|
+ if (dimensionEntities.size() > 0) {
|
|
|
+ for (int y = 0; y < dimensionEntities.size(); y++) {
|
|
|
+ String[] questionNo = dimensionEntities.get(y).getQuestionNo().split(";");
|
|
|
+ for (ScaleMarksEntity scaleMarksEntity : scaleMarksEntities) {
|
|
|
+ //判断总分是否需要处理
|
|
|
+ if (totalMark) {
|
|
|
+ if (scaleMarksEntity.getName().equals("总分") || scaleMarksEntity.getName().equals("无")) {
|
|
|
+ if (Constant.DEFAULT_VALUE_ONE.equals(StringUtils.isEmpty(scaleMarksEntity.getScoringType()) ? Constant.DEFAULT_VALUE_ZERO : scaleMarksEntity.getScoringType())) {
|
|
|
+ score = Double.parseDouble(df.format(score / jsonArray.size()));
|
|
|
+ totalMark = false;
|
|
|
+ } else if (Constant.QUESTION_TYPE_TWO.equals(StringUtils.isEmpty(scaleMarksEntity.getScoringType()) ? Constant.DEFAULT_VALUE_ZERO : scaleMarksEntity.getScoringType())) {
|
|
|
+ score = Math.round(score / jsonArray.size());
|
|
|
+ totalMark = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //判断维度分是否需要处理
|
|
|
+ if (scaleMarksEntity.getName().equals(dimensionEntities.get(y).getName())) {
|
|
|
+ if (Constant.DEFAULT_VALUE_ONE.equals(StringUtils.isEmpty(scaleMarksEntity.getScoringType()) ? Constant.DEFAULT_VALUE_ZERO : scaleMarksEntity.getScoringType())) {
|
|
|
+ dimensionScore[y] = Double.parseDouble(df.format(dimensionScore[y] / questionNo.length));
|
|
|
+ dimensionScoreMap.put(dimensionEntities.get(y).getId(), dimensionScore[y]);
|
|
|
+ break;
|
|
|
+ } else if (Constant.QUESTION_TYPE_TWO.equals(StringUtils.isEmpty(scaleMarksEntity.getScoringType()) ? Constant.DEFAULT_VALUE_ZERO : scaleMarksEntity.getScoringType())) {
|
|
|
+ dimensionScore[y] = Math.round(dimensionScore[y] / questionNo.length);
|
|
|
+ dimensionScoreMap.put(dimensionEntities.get(y).getId(), dimensionScore[y]);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ //将量表总维度根据维度名称进行分组
|
|
|
+ Map<String, List<ScaleMarksEntity>> scaleMarksMap = scaleMarksEntities.stream().collect(Collectors.groupingBy(ScaleMarksEntity::getName));
|
|
|
+ //返回值以及存数据库格式
|
|
|
+ List<NewResultDto> newResultDtos = new ArrayList<>();
|
|
|
+ resultMap0.put("总分", df.format(score));
|
|
|
+ resultJson.put("总分", df.format(score));
|
|
|
+ BigDecimal scoreDecimal = new BigDecimal(df.format(score));
|
|
|
+ //如果没有总分这一栏,需要手动赋值返回
|
|
|
+ List<ScaleMarksEntity> totalScore = scaleMarksMap.get("总分");
|
|
|
+ List<ScaleMarksEntity> totalScores = scaleMarksMap.get("无");
|
|
|
+ if (totalScore == null) {
|
|
|
+ if (totalScores == null) {
|
|
|
+ newResultDtos.add(new NewResultDto("总分", df.format(score), "无", "无",
|
|
|
+ "无", "无", "无", "无", "是"));
|
|
|
+ } else {
|
|
|
+ for (ScaleMarksEntity tempTotalScore : totalScores) {
|
|
|
+ BigDecimal scoreStart = new BigDecimal(tempTotalScore.getScoreStart());
|
|
|
+ BigDecimal scoreEnd = new BigDecimal(tempTotalScore.getScoreEnd());
|
|
|
+ if (scoreDecimal.compareTo(scoreEnd) <= 0 && scoreDecimal.compareTo(scoreStart) >= 0) {
|
|
|
+ newResultDtos.add(new NewResultDto("总分", df.format(score), tempTotalScore.getSymptom(), tempTotalScore.getImprovementSuggestions(),
|
|
|
+ tempTotalScore.getFlag(), tempTotalScore.getReference(), tempTotalScore.getNameExplain(), tempTotalScore.getSuggestion(), tempTotalScore.getIsTotalScoreExplain()));
|
|
|
+ resultMap0.put("总分症状", tempTotalScore.getSymptom());
|
|
|
+ resultMap0.put("总分指导语", tempTotalScore.getImprovementSuggestions());
|
|
|
+ resultMap0.put("总分因子解释", tempTotalScore.getNameExplain());
|
|
|
+ resultMap0.put("总分建议", tempTotalScore.getSuggestion());
|
|
|
+ resultJson.put("总分症状", tempTotalScore.getSymptom());
|
|
|
+ resultJson.put("总分指导语", tempTotalScore.getImprovementSuggestions());
|
|
|
+ resultJson.put("总分因子解释", tempTotalScore.getNameExplain());
|
|
|
+ resultJson.put("总分建议", tempTotalScore.getSuggestion());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ for (ScaleMarksEntity tempTotalScore : totalScore) {
|
|
|
+ BigDecimal scoreStart = new BigDecimal(tempTotalScore.getScoreStart());
|
|
|
+ BigDecimal scoreEnd = new BigDecimal(tempTotalScore.getScoreEnd());
|
|
|
+ if (scoreDecimal.compareTo(scoreEnd) <= 0 && scoreDecimal.compareTo(scoreStart) >= 0) {
|
|
|
+ newResultDtos.add(new NewResultDto("总分", df.format(score), tempTotalScore.getSymptom(), tempTotalScore.getImprovementSuggestions(),
|
|
|
+ tempTotalScore.getFlag(), tempTotalScore.getReference(), tempTotalScore.getNameExplain(), tempTotalScore.getSuggestion(), tempTotalScore.getIsTotalScoreExplain()));
|
|
|
+ resultMap0.put("总分症状", tempTotalScore.getSymptom());
|
|
|
+ resultMap0.put("总分指导语", tempTotalScore.getImprovementSuggestions());
|
|
|
+ resultMap0.put("总分因子解释", tempTotalScore.getNameExplain());
|
|
|
+ resultMap0.put("总分建议", tempTotalScore.getSuggestion());
|
|
|
+ resultJson.put("总分症状", tempTotalScore.getSymptom());
|
|
|
+ resultJson.put("总分指导语", tempTotalScore.getImprovementSuggestions());
|
|
|
+ resultJson.put("总分因子解释", tempTotalScore.getNameExplain());
|
|
|
+ resultJson.put("总分建议", tempTotalScore.getSuggestion());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ JSONObject iconInfo = new JSONObject();
|
|
|
+ //雷达图需要的维度以及最大值
|
|
|
+ List<Map<String, Object>> indicator = new LinkedList<>();
|
|
|
+ //雷达图所需要的常模参考值
|
|
|
+ LinkedList<String> reference = new LinkedList<>();
|
|
|
+ //雷达图需要的分数
|
|
|
+ LinkedList<String> scoreList = new LinkedList<>();
|
|
|
+ //计算维度所在评分区间
|
|
|
+ commonComputeDimensionScore(df, resultMap0, resultJson, dimensionEntities, dimensionScore, scaleMarksMap, newResultDtos, indicator, reference, scoreList);
|
|
|
+ //需要图表展示的
|
|
|
+ iconInfo.put("indicator", indicator);
|
|
|
+ //判断是否有常模参考值,即reference的内容如果全为0,则不进行返回
|
|
|
+ if (!reference.stream().allMatch("0"::equals)) {
|
|
|
+ iconInfo.put("reference", reference);
|
|
|
+ }
|
|
|
+ iconInfo.put("scoreList", scoreList);
|
|
|
+ if (indicator.size() == 0 && reference.size() == 0) {
|
|
|
+ newResult.put("iconInfo", "");
|
|
|
+ } else {
|
|
|
+ newResult.put("iconInfo", iconInfo);
|
|
|
+ }
|
|
|
+ newResult.put("result", newResultDtos);
|
|
|
+ resultMapList.add(resultMap0);
|
|
|
+
|
|
|
+
|
|
|
+ JSONObject returnJson = new JSONObject(true);
|
|
|
+ returnJson.put("resultMapList", resultMapList);
|
|
|
+ returnJson.put("resultJson", resultJson);
|
|
|
+ returnJson.put(ScaleConstant.ResultEnum.RESULT_NEW_FIELD.getKeyword(), newResult);
|
|
|
+
|
|
|
+ return returnJson;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 通用计算量表所有维度分数,以及其维度所在分数段症状等
|
|
|
+ *
|
|
|
+ * @param df 用来设置小数位数,例如保留两位小数DecimalFormat df = new DecimalFormat("######0.00");
|
|
|
+ * @param resultMap 用来向数据库存
|
|
|
+ * @param resultJson WebScaleResultController传递过来的评分规则等相关参数
|
|
|
+ * @param dimensionEntities 量表维度list信息
|
|
|
+ * @param dimensionScore 量表维度分数,需要和量表维度list对应
|
|
|
+ * @param scaleMarksMap 评分规则的map
|
|
|
+ * @param newResultDtos 各个维度的结论,等级解释等list
|
|
|
+ * @param indicator 雷达图需要的维度以及最大值
|
|
|
+ * @param reference 雷达图所需要的常模参考值
|
|
|
+ * @param scoreList 雷达图需要的分数
|
|
|
+ */
|
|
|
+ public static void commonComputeDimensionScore(@Nullable DecimalFormat df, Map<String, String> resultMap, JSONObject resultJson, List<DimensionEntity> dimensionEntities, double[] dimensionScore, Map<String, List<ScaleMarksEntity>> scaleMarksMap, List<NewResultDto> newResultDtos, List<Map<String, Object>> indicator, List<String> reference, List<String> scoreList) {
|
|
|
+ if (df == null) {
|
|
|
+ df = new DecimalFormat("######0.00");
|
|
|
+ }
|
|
|
+ for (int y = 0; y < dimensionEntities.size(); y++) {
|
|
|
+ Map<String, Object> indicatorMap = new HashMap<>();
|
|
|
+ DimensionEntity dimensionEntity = dimensionEntities.get(y);
|
|
|
+ NewResultDto newResultDto1 = new NewResultDto();
|
|
|
+ //存放该维度总分
|
|
|
+ resultMap.put(dimensionEntity.getName() + "得分", df.format(dimensionScore[y]));
|
|
|
+ resultJson.put(dimensionEntity.getName() + "得分", df.format(dimensionScore[y]));
|
|
|
+ newResultDto1.setScore(df.format(dimensionScore[y]));
|
|
|
+ newResultDtos.add(newResultDto1);
|
|
|
+ BigDecimal dimensionScoreDecimal = new BigDecimal(df.format(dimensionScore[y]));
|
|
|
+ //获取当前维度的评分规则
|
|
|
+ List<ScaleMarksEntity> scaleMarksEntities1 = scaleMarksMap.get(dimensionEntity.getName());
|
|
|
+ if (scaleMarksEntities1 != null) {
|
|
|
+ //循环遍历判断得分在哪个区间
|
|
|
+ for (ScaleMarksEntity scaleMarksEntity : scaleMarksEntities1) {
|
|
|
+ BigDecimal decimalScoreEnd = new BigDecimal(scaleMarksEntity.getScoreEnd());
|
|
|
+ BigDecimal decimalScoreStart = new BigDecimal(scaleMarksEntity.getScoreStart());
|
|
|
+ if (dimensionScoreDecimal.compareTo(decimalScoreEnd) <= 0 && dimensionScoreDecimal.compareTo(decimalScoreStart) >= 0) {
|
|
|
+ putDimResult(resultMap, resultJson, dimensionEntity.getName(), newResultDto1, scaleMarksEntity);
|
|
|
+ //需要进行图表展示的维度放入map
|
|
|
+ if ("1".equals(dimensionEntity.getIsIconFlag())) {
|
|
|
+ indicatorMap.put("text", dimensionEntity.getName());
|
|
|
+ //将当前维度按照分数的结尾值来进行排序scaleMarksEntities1
|
|
|
+ List<ScaleMarksEntity> collect = scaleMarksEntities1.stream().sorted(Comparator.comparing(ScaleMarksEntity::getScoreEnd, Comparator.comparingDouble(Double::parseDouble))
|
|
|
+ .reversed()).collect(Collectors.toList());
|
|
|
+ //排序完成后第一个的scoreEnd最大,也就是该维度最大的
|
|
|
+ indicatorMap.put("max", collect.get(0).getScoreEnd());
|
|
|
+ indicator.add(indicatorMap);
|
|
|
+ if ("无".equals(scaleMarksEntity.getReference()) || "无".equals(scaleMarksEntity.getStandardDeviation())) {
|
|
|
+ //常模参考值设为0
|
|
|
+ reference.add("0");
|
|
|
+ } else {
|
|
|
+ reference.add(scaleMarksEntity.getReference());
|
|
|
+ }
|
|
|
+ scoreList.add(String.valueOf(dimensionScore[y]));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ //如果分数规则表中无维度,而维度表中有相应维度,则只显示维度分数
|
|
|
+ newResultDto1.setFlag("无");
|
|
|
+ newResultDto1.setImprovementSuggestions("无");
|
|
|
+ newResultDto1.setName(dimensionEntity.getName());
|
|
|
+ newResultDto1.setReference("无");
|
|
|
+ newResultDto1.setNameExplain("无");
|
|
|
+ newResultDto1.setSuggestion("无");
|
|
|
+ newResultDto1.setIsTotalScoreExplain("否");
|
|
|
+ newResultDto1.setSymptom("无");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 通用计算单个维度分数,以及其维度所在分数段症状等
|
|
|
+ *
|
|
|
+ * @param df 默认为两位小数,可以为null,用来设置小数位数,例如保留两位小数DecimalFormat df = new DecimalFormat("######0.00");
|
|
|
+ * @param resultMap 用来向数据库存
|
|
|
+ * @param resultJson WebScaleResultController传递过来的评分规则等相关参数
|
|
|
+ * @param dimensionName 维度名称
|
|
|
+ * @param dimensionScore 维度分数
|
|
|
+ * @param isDimensionShow 是否在雷达图中展示
|
|
|
+ * @param scaleMarksMap 评分规则的map
|
|
|
+ * @param newResultDtos 各个维度的结论,等级解释等list
|
|
|
+ * @param indicator 雷达图需要的维度以及最大值
|
|
|
+ * @param reference 雷达图所需要的常模参考值
|
|
|
+ * @param scoreList 雷达图需要的分数
|
|
|
+ */
|
|
|
+ public static void commonComputeDimensionScore(@Nullable DecimalFormat df, Map<String, String> resultMap, JSONObject resultJson, String dimensionName, double dimensionScore, Boolean isDimensionShow, Map<String, List<ScaleMarksEntity>> scaleMarksMap, List<NewResultDto> newResultDtos, List<Map<String, Object>> indicator, List<String> reference, List<String> scoreList) {
|
|
|
+ if (df == null) {
|
|
|
+ df = new DecimalFormat("######0.00");
|
|
|
+ }
|
|
|
+ Map<String, Object> indicatorMap = new HashMap<>();
|
|
|
+ NewResultDto newResultDto = new NewResultDto();
|
|
|
+ //存放该维度总分
|
|
|
+ resultMap.put(dimensionName + "得分", df.format(dimensionScore));
|
|
|
+ resultJson.put(dimensionName + "得分", df.format(dimensionScore));
|
|
|
+ newResultDto.setScore(df.format(dimensionScore));
|
|
|
+ newResultDtos.add(newResultDto);
|
|
|
+ BigDecimal dimensionScoreDecimal = new BigDecimal(df.format(dimensionScore));
|
|
|
+ //获取当前维度的评分规则
|
|
|
+ List<ScaleMarksEntity> scaleMarksEntities1 = scaleMarksMap.get(dimensionName);
|
|
|
+ if (scaleMarksEntities1 != null) {
|
|
|
+ //循环遍历判断得分在哪个区间
|
|
|
+ for (ScaleMarksEntity scaleMarksEntity : scaleMarksEntities1) {
|
|
|
+ BigDecimal decimalScoreEnd = new BigDecimal(scaleMarksEntity.getScoreEnd());
|
|
|
+ BigDecimal decimalScoreStart = new BigDecimal(scaleMarksEntity.getScoreStart());
|
|
|
+ if (dimensionScoreDecimal.compareTo(decimalScoreEnd) <= 0 && dimensionScoreDecimal.compareTo(decimalScoreStart) >= 0) {
|
|
|
+ putDimResult(resultMap, resultJson, dimensionName, newResultDto, scaleMarksEntity);
|
|
|
+ //需要进行图表展示的维度放入map
|
|
|
+ if (isDimensionShow) {
|
|
|
+ indicatorMap.put("text", dimensionName);
|
|
|
+ //将当前维度按照分数的结尾值来进行排序scaleMarksEntities1
|
|
|
+ List<ScaleMarksEntity> collect = scaleMarksEntities1.stream().sorted(Comparator.comparing(ScaleMarksEntity::getScoreEnd, Comparator.comparingInt(Integer::parseInt))
|
|
|
+ .reversed()).collect(Collectors.toList());
|
|
|
+ //排序完成后第一个的scoreEnd最大,也就是该维度最大的
|
|
|
+ indicatorMap.put("max", collect.get(0).getScoreEnd());
|
|
|
+ indicator.add(indicatorMap);
|
|
|
+ if ("无".equals(scaleMarksEntity.getReference()) || "无".equals(scaleMarksEntity.getStandardDeviation())) {
|
|
|
+ //常模参考值设为0
|
|
|
+ reference.add("0");
|
|
|
+ } else {
|
|
|
+ reference.add(scaleMarksEntity.getReference());
|
|
|
+ }
|
|
|
+ scoreList.add(String.valueOf(dimensionScore));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ //如果分数规则表中无维度,而维度表中有相应维度,则只显示维度分数
|
|
|
+ newResultDto.setFlag("无");
|
|
|
+ newResultDto.setImprovementSuggestions("无");
|
|
|
+ newResultDto.setName(dimensionName);
|
|
|
+ newResultDto.setReference("无");
|
|
|
+ newResultDto.setNameExplain("无");
|
|
|
+ newResultDto.setSuggestion("无");
|
|
|
+ newResultDto.setIsTotalScoreExplain("否");
|
|
|
+ newResultDto.setSymptom("无");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private static void putDimResult(Map<String, String> resultMap0, JSONObject resultJson, String dimensionName, NewResultDto newResultDto1, ScaleMarksEntity scaleMarksEntity) {
|
|
|
+ //resultMap0.put(dimensionName + "常模参考值", scaleMarksEntity.getReference());
|
|
|
+ resultMap0.put(dimensionName + "症状", scaleMarksEntity.getSymptom());
|
|
|
+ resultJson.put(dimensionName + "结论", scaleMarksEntity.getSymptom());
|
|
|
+ resultMap0.put(dimensionName + "因子解释", scaleMarksEntity.getNameExplain());
|
|
|
+ resultJson.put(dimensionName + "因子解释", scaleMarksEntity.getNameExplain());
|
|
|
+ resultMap0.put(dimensionName + "指导语", scaleMarksEntity.getImprovementSuggestions());
|
|
|
+ resultJson.put(dimensionName + "指导语", scaleMarksEntity.getImprovementSuggestions());
|
|
|
+ resultMap0.put(dimensionName + "建议", scaleMarksEntity.getSuggestion());
|
|
|
+ resultJson.put(dimensionName + "建议", scaleMarksEntity.getSuggestion());
|
|
|
+ BeanUtils.copyProperties(scaleMarksEntity, newResultDto1);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|