|
@@ -7,6 +7,7 @@ import com.rf.psychological.dao.model.AnswerEntity;
|
|
import com.rf.psychological.dao.model.DimensionEntity;
|
|
import com.rf.psychological.dao.model.DimensionEntity;
|
|
import com.rf.psychological.scale.dao.model.ScaleMarksEntity;
|
|
import com.rf.psychological.scale.dao.model.ScaleMarksEntity;
|
|
import com.rf.psychological.scale.scaleresult.ScaleConstant;
|
|
import com.rf.psychological.scale.scaleresult.ScaleConstant;
|
|
|
|
+import com.rf.psychological.utils.Constant;
|
|
import org.springframework.beans.BeanUtils;
|
|
import org.springframework.beans.BeanUtils;
|
|
import org.springframework.lang.Nullable;
|
|
import org.springframework.lang.Nullable;
|
|
|
|
|
|
@@ -45,19 +46,19 @@ public class NEWCOMMONScale extends BaseScale {
|
|
List<DimensionEntity> dimensionEntities = (List<DimensionEntity>) resultJson.get("dimensionEntities");
|
|
List<DimensionEntity> dimensionEntities = (List<DimensionEntity>) resultJson.get("dimensionEntities");
|
|
//计算每个维度得分dimensionEntities
|
|
//计算每个维度得分dimensionEntities
|
|
double[] dimensionScore = new double[dimensionEntities.size()];
|
|
double[] dimensionScore = new double[dimensionEntities.size()];
|
|
|
|
+ Map<String,Double> dimensionScoreMap = new HashMap<>();
|
|
//jsonArray:用户自己选择的题目选项
|
|
//jsonArray:用户自己选择的题目选项
|
|
for (int i = 0; i < jsonArray.size(); i++) {
|
|
for (int i = 0; i < jsonArray.size(); i++) {
|
|
JSONObject jsonObject1 = jsonArray.getJSONObject(i);
|
|
JSONObject jsonObject1 = jsonArray.getJSONObject(i);
|
|
//计算总分
|
|
//计算总分
|
|
for (AnswerEntity answerEntity : answerEntities) {
|
|
for (AnswerEntity answerEntity : answerEntities) {
|
|
if (answerEntity.getQuestionNo().equals(jsonObject1.getString("questionNo"))) {
|
|
if (answerEntity.getQuestionNo().equals(jsonObject1.getString("questionNo"))) {
|
|
- if (answerEntity.getName().equals(jsonObject1.getString("checkItems"))) {
|
|
|
|
|
|
+ if (answerEntity.getName().replaceAll("\\s", "").equals(jsonObject1.getString("checkItems").replaceAll("\\s", ""))) {
|
|
score += Double.parseDouble(answerEntity.getScore());
|
|
score += Double.parseDouble(answerEntity.getScore());
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
//计算维度分数
|
|
//计算维度分数
|
|
for (int y = 0; y < dimensionEntities.size(); y++) {
|
|
for (int y = 0; y < dimensionEntities.size(); y++) {
|
|
//获取维度信息
|
|
//获取维度信息
|
|
@@ -65,7 +66,7 @@ public class NEWCOMMONScale extends BaseScale {
|
|
//获取该维度下有哪些选项
|
|
//获取该维度下有哪些选项
|
|
String questionNos = dimensionEntity.getQuestionNo();
|
|
String questionNos = dimensionEntity.getQuestionNo();
|
|
//删除空白字符后得到进行划分得到选择题号
|
|
//删除空白字符后得到进行划分得到选择题号
|
|
- String[] questionNo = questionNos.replaceAll("\\s","").split(";");
|
|
|
|
|
|
+ String[] questionNo = questionNos.replaceAll("\\s", "").split(";");
|
|
//计算每道题的得分
|
|
//计算每道题的得分
|
|
for (String question : questionNo) {
|
|
for (String question : questionNo) {
|
|
if (question.equals(jsonObject1.getString("questionNo"))) {
|
|
if (question.equals(jsonObject1.getString("questionNo"))) {
|
|
@@ -73,7 +74,8 @@ public class NEWCOMMONScale extends BaseScale {
|
|
List<AnswerEntity> nowQuestionAnswerList = answerEntities.stream().filter(answerEntity -> answerEntity.getQuestionNo().equals(question)).collect(Collectors.toList());
|
|
List<AnswerEntity> nowQuestionAnswerList = answerEntities.stream().filter(answerEntity -> answerEntity.getQuestionNo().equals(question)).collect(Collectors.toList());
|
|
//本题目的正确答案与自己的选项进行对比,正确的话相应分数进行相加
|
|
//本题目的正确答案与自己的选项进行对比,正确的话相应分数进行相加
|
|
for (AnswerEntity answerEntity : nowQuestionAnswerList) {
|
|
for (AnswerEntity answerEntity : nowQuestionAnswerList) {
|
|
- if (answerEntity.getName().equals(jsonObject1.getString("checkItems"))) {
|
|
|
|
|
|
+ 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());
|
|
dimensionScore[y] += Double.parseDouble(answerEntity.getScore());
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
@@ -81,7 +83,45 @@ public class NEWCOMMONScale extends BaseScale {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ 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 (scaleMarksEntity.getScoringType().equals(Constant.DEFAULT_VALUE_ONE)){
|
|
|
|
+ score = Double.parseDouble(df.format(score / jsonArray.size()));
|
|
|
|
+ totalMark = false;
|
|
|
|
+ }else if (scaleMarksEntity.getScoringType().equals(Constant.QUESTION_TYPE_TWO)){
|
|
|
|
+ score = Math.round(score / jsonArray.size());
|
|
|
|
+ totalMark = false;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ //判断维度分是否需要处理
|
|
|
|
+ if (scaleMarksEntity.getName().equals(dimensionEntities.get(y).getName())){
|
|
|
|
+ if (scaleMarksEntity.getScoringType().equals(Constant.DEFAULT_VALUE_ONE)){
|
|
|
|
+ dimensionScore[y] = Double.parseDouble(df.format(dimensionScore[y] / questionNo.length));
|
|
|
|
+ dimensionScoreMap.put(dimensionEntities.get(y).getId(),dimensionScore[y]);
|
|
|
|
+ break;
|
|
|
|
+ }else if (scaleMarksEntity.getScoringType().equals(Constant.QUESTION_TYPE_TWO)){
|
|
|
|
+ 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));
|
|
Map<String, List<ScaleMarksEntity>> scaleMarksMap = scaleMarksEntities.stream().collect(Collectors.groupingBy(ScaleMarksEntity::getName));
|
|
//返回值以及存数据库格式
|
|
//返回值以及存数据库格式
|
|
@@ -91,9 +131,29 @@ public class NEWCOMMONScale extends BaseScale {
|
|
BigDecimal scoreDecimal = new BigDecimal(df.format(score));
|
|
BigDecimal scoreDecimal = new BigDecimal(df.format(score));
|
|
//如果没有总分这一栏,需要手动赋值返回
|
|
//如果没有总分这一栏,需要手动赋值返回
|
|
List<ScaleMarksEntity> totalScore = scaleMarksMap.get("总分");
|
|
List<ScaleMarksEntity> totalScore = scaleMarksMap.get("总分");
|
|
|
|
+ List<ScaleMarksEntity> totalScores = scaleMarksMap.get("无");
|
|
if (totalScore == null) {
|
|
if (totalScore == null) {
|
|
- newResultDtos.add(new NewResultDto("总分", df.format(score), "无", "无",
|
|
|
|
- "无", "无", "无", "无", "是"));
|
|
|
|
|
|
+ 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 {
|
|
} else {
|
|
for (ScaleMarksEntity tempTotalScore : totalScore) {
|
|
for (ScaleMarksEntity tempTotalScore : totalScore) {
|
|
BigDecimal scoreStart = new BigDecimal(tempTotalScore.getScoreStart());
|
|
BigDecimal scoreStart = new BigDecimal(tempTotalScore.getScoreStart());
|
|
@@ -101,6 +161,14 @@ public class NEWCOMMONScale extends BaseScale {
|
|
if (scoreDecimal.compareTo(scoreEnd) <= 0 && scoreDecimal.compareTo(scoreStart) >= 0) {
|
|
if (scoreDecimal.compareTo(scoreEnd) <= 0 && scoreDecimal.compareTo(scoreStart) >= 0) {
|
|
newResultDtos.add(new NewResultDto("总分", df.format(score), tempTotalScore.getSymptom(), tempTotalScore.getImprovementSuggestions(),
|
|
newResultDtos.add(new NewResultDto("总分", df.format(score), tempTotalScore.getSymptom(), tempTotalScore.getImprovementSuggestions(),
|
|
tempTotalScore.getFlag(), tempTotalScore.getReference(), tempTotalScore.getNameExplain(), tempTotalScore.getSuggestion(), tempTotalScore.getIsTotalScoreExplain()));
|
|
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());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -130,6 +198,7 @@ public class NEWCOMMONScale extends BaseScale {
|
|
newResult.put("result", newResultDtos);
|
|
newResult.put("result", newResultDtos);
|
|
resultMapList.add(resultMap0);
|
|
resultMapList.add(resultMap0);
|
|
|
|
|
|
|
|
+
|
|
JSONObject returnJson = new JSONObject(true);
|
|
JSONObject returnJson = new JSONObject(true);
|
|
returnJson.put("resultMapList", resultMapList);
|
|
returnJson.put("resultMapList", resultMapList);
|
|
returnJson.put("resultJson", resultJson);
|
|
returnJson.put("resultJson", resultJson);
|
|
@@ -179,7 +248,7 @@ public class NEWCOMMONScale extends BaseScale {
|
|
if ("1".equals(dimensionEntity.getIsIconFlag())) {
|
|
if ("1".equals(dimensionEntity.getIsIconFlag())) {
|
|
indicatorMap.put("text", dimensionEntity.getName());
|
|
indicatorMap.put("text", dimensionEntity.getName());
|
|
//将当前维度按照分数的结尾值来进行排序scaleMarksEntities1
|
|
//将当前维度按照分数的结尾值来进行排序scaleMarksEntities1
|
|
- List<ScaleMarksEntity> collect = scaleMarksEntities1.stream().sorted(Comparator.comparing(ScaleMarksEntity::getScoreEnd, Comparator.comparingInt(Integer::parseInt))
|
|
|
|
|
|
+ List<ScaleMarksEntity> collect = scaleMarksEntities1.stream().sorted(Comparator.comparing(ScaleMarksEntity::getScoreEnd, Comparator.comparingDouble(Double::parseDouble))
|
|
.reversed()).collect(Collectors.toList());
|
|
.reversed()).collect(Collectors.toList());
|
|
//排序完成后第一个的scoreEnd最大,也就是该维度最大的
|
|
//排序完成后第一个的scoreEnd最大,也就是该维度最大的
|
|
indicatorMap.put("max", collect.get(0).getScoreEnd());
|
|
indicatorMap.put("max", collect.get(0).getScoreEnd());
|
|
@@ -278,13 +347,15 @@ public class NEWCOMMONScale extends BaseScale {
|
|
|
|
|
|
|
|
|
|
private static void putDimResult(Map<String, String> resultMap0, JSONObject resultJson, String dimensionName, NewResultDto newResultDto1, ScaleMarksEntity scaleMarksEntity) {
|
|
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.getReference());
|
|
resultMap0.put(dimensionName + "症状", scaleMarksEntity.getSymptom());
|
|
resultMap0.put(dimensionName + "症状", scaleMarksEntity.getSymptom());
|
|
- resultJson.put(dimensionName + "解读", scaleMarksEntity.getSymptom());
|
|
|
|
|
|
+ resultJson.put(dimensionName + "结论", scaleMarksEntity.getSymptom());
|
|
resultMap0.put(dimensionName + "因子解释", scaleMarksEntity.getNameExplain());
|
|
resultMap0.put(dimensionName + "因子解释", scaleMarksEntity.getNameExplain());
|
|
|
|
+ resultJson.put(dimensionName + "因子解释", scaleMarksEntity.getNameExplain());
|
|
resultMap0.put(dimensionName + "指导语", scaleMarksEntity.getImprovementSuggestions());
|
|
resultMap0.put(dimensionName + "指导语", scaleMarksEntity.getImprovementSuggestions());
|
|
resultJson.put(dimensionName + "指导语", scaleMarksEntity.getImprovementSuggestions());
|
|
resultJson.put(dimensionName + "指导语", scaleMarksEntity.getImprovementSuggestions());
|
|
resultMap0.put(dimensionName + "建议", scaleMarksEntity.getSuggestion());
|
|
resultMap0.put(dimensionName + "建议", scaleMarksEntity.getSuggestion());
|
|
|
|
+ resultJson.put(dimensionName + "建议", scaleMarksEntity.getSuggestion());
|
|
BeanUtils.copyProperties(scaleMarksEntity, newResultDto1);
|
|
BeanUtils.copyProperties(scaleMarksEntity, newResultDto1);
|
|
}
|
|
}
|
|
|
|
|