|
@@ -7,23 +7,21 @@ import com.rf.psychological.dao.model.DimensionEntity;
|
|
|
import com.rf.psychological.scale.dao.model.ScaleMarksEntity;
|
|
|
|
|
|
import java.text.DecimalFormat;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.LinkedHashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import java.util.*;
|
|
|
|
|
|
/**
|
|
|
* @author zsy
|
|
|
* @description:简单相加和分维度量表通用算法
|
|
|
* @date 2021/7/20 15:55
|
|
|
*/
|
|
|
-public class COMMONScale extends BaseScale{
|
|
|
+public class COMMONScale extends BaseScale {
|
|
|
+
|
|
|
|
|
|
public COMMONScale(JSONArray jsonArray, JSONObject resultJson) {
|
|
|
super(jsonArray, resultJson);
|
|
|
}
|
|
|
|
|
|
- public JSONObject scaleCalculate() throws Exception {
|
|
|
+ public JSONObject scaleCalculate() throws Exception {
|
|
|
|
|
|
// 自定义路径使用
|
|
|
/*ScaleUtil.getScaleDll("FESCVSCALE.dll");
|
|
@@ -38,7 +36,7 @@ public class COMMONScale extends BaseScale{
|
|
|
//总分
|
|
|
double score = 0;
|
|
|
Map<String, String> resultMap0 = new LinkedHashMap<>();
|
|
|
- List<Map<String,String>> resultMapList = new ArrayList<>();
|
|
|
+ List<Map<String, String>> resultMapList = new ArrayList<>();
|
|
|
|
|
|
//获取答案列表
|
|
|
List<AnswerEntity> answerEntities = (List<AnswerEntity>) resultJson.get("answerEntities");
|
|
@@ -46,21 +44,25 @@ public class COMMONScale extends BaseScale{
|
|
|
List<ScaleMarksEntity> scaleMarksEntities = (List<ScaleMarksEntity>) resultJson.get("scaleMarksEntities");
|
|
|
//获取维度信息列表
|
|
|
List<DimensionEntity> dimensionEntities = (List<DimensionEntity>) resultJson.get("dimensionEntities");
|
|
|
- if (dimensionEntities.size() > 0){
|
|
|
+ double[] dimensionScore = new double[dimensionEntities.size()];
|
|
|
+ Map<String,Double> dimensionScoreMap = new HashMap<>();
|
|
|
+ if (dimensionEntities.size() > 0) {
|
|
|
+
|
|
|
//计算每个维度得分
|
|
|
- double[] dimensionScore = new double[dimensionEntities.size()];
|
|
|
+
|
|
|
for (int i = 0; i < jsonArray.size(); i++) {
|
|
|
JSONObject jsonObject1 = jsonArray.getJSONObject(i);
|
|
|
for (int y = 0; y < dimensionEntities.size(); y++) {
|
|
|
//for (DimensionEntity dimensionEntity:dimensionEntities){
|
|
|
DimensionEntity dimensionEntity = dimensionEntities.get(y);
|
|
|
String questionNos = dimensionEntity.getQuestionNo();
|
|
|
- String[] questionNo = questionNos.split(";");
|
|
|
- for (String question:questionNo){
|
|
|
- if (question.equals(jsonObject1.getString("questionNo"))){
|
|
|
- for (AnswerEntity answerEntity:answerEntities){
|
|
|
- if (answerEntity.getQuestionNo().equals(question) && answerEntity.getName().equals(jsonObject1.getString("checkItems"))){
|
|
|
- dimensionScore[y] += Double.valueOf(answerEntity.getScore());
|
|
|
+ String[] questionNo = questionNos.replaceAll("\\s", "").split(";");
|
|
|
+ for (String question : questionNo) {
|
|
|
+ if (question.equals(jsonObject1.getString("questionNo"))) {
|
|
|
+ for (AnswerEntity answerEntity : answerEntities) {
|
|
|
+ if (answerEntity.getQuestionNo().equals(question) && answerEntity.getName().replaceAll("\\s", "").equals(jsonObject1.getString("checkItems").replaceAll("\\s", ""))) {
|
|
|
+ dimensionScore[y] += Double.parseDouble(answerEntity.getScore());
|
|
|
+ dimensionScoreMap.put(dimensionEntity.getId(),dimensionScoreMap.get(dimensionEntity.getId())==null?Double.parseDouble(answerEntity.getScore()):(dimensionScoreMap.get(dimensionEntity.getId()) +Double.parseDouble(answerEntity.getScore())));
|
|
|
}
|
|
|
}
|
|
|
break;
|
|
@@ -68,10 +70,10 @@ public class COMMONScale extends BaseScale{
|
|
|
}
|
|
|
}
|
|
|
//计算总分
|
|
|
- for (AnswerEntity answerEntity:answerEntities){
|
|
|
- if (answerEntity.getQuestionNo().equals(String.valueOf(i+1))){
|
|
|
- if (answerEntity.getName().equals(jsonObject1.getString("checkItems"))){
|
|
|
- score += Integer.valueOf(answerEntity.getScore());
|
|
|
+ for (AnswerEntity answerEntity : answerEntities) {
|
|
|
+ if (answerEntity.getQuestionNo().equals(String.valueOf(i + 1))) {
|
|
|
+ if (answerEntity.getName().replaceAll("\\s", "").equals(jsonObject1.getString("checkItems").replaceAll("\\s", ""))) {
|
|
|
+ score += Integer.parseInt(answerEntity.getScore());
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -79,15 +81,15 @@ public class COMMONScale extends BaseScale{
|
|
|
|
|
|
resultMap0.put("总分", String.valueOf(score));
|
|
|
resultJson.put("总分", String.valueOf(score));
|
|
|
- if (scaleMarksEntities.size() > 0){
|
|
|
- for (ScaleMarksEntity scaleMarksEntity:scaleMarksEntities){
|
|
|
- if (scaleMarksEntity.getName() != null && scaleMarksEntity.getName().equals("无")){
|
|
|
- if (score <= Integer.valueOf(scaleMarksEntity.getScoreEnd()) && score >= Integer.valueOf(scaleMarksEntity.getScoreStart())){
|
|
|
- if (!scaleMarksEntity.getSymptom().equals("无")){
|
|
|
- resultMap0.put("解读", scaleMarksEntity.getSymptom());
|
|
|
- resultJson.put("解读", scaleMarksEntity.getSymptom());
|
|
|
+ if (scaleMarksEntities.size() > 0) {
|
|
|
+ for (ScaleMarksEntity scaleMarksEntity : scaleMarksEntities) {
|
|
|
+ if (scaleMarksEntity.getName() != null && (scaleMarksEntity.getName().equals("无") || scaleMarksEntity.getName().equals("总分"))) {
|
|
|
+ if (score <= Integer.parseInt(scaleMarksEntity.getScoreEnd()) && score >= Integer.parseInt(scaleMarksEntity.getScoreStart())) {
|
|
|
+ if (!scaleMarksEntity.getSymptom().equals("无")) {
|
|
|
+ resultMap0.put("结论", scaleMarksEntity.getSymptom());
|
|
|
+ resultJson.put("结论", scaleMarksEntity.getSymptom());
|
|
|
}
|
|
|
- if (scaleMarksEntity.getImprovementSuggestions() != null && !scaleMarksEntity.getImprovementSuggestions().equals("无")){
|
|
|
+ if (scaleMarksEntity.getImprovementSuggestions() != null && !scaleMarksEntity.getImprovementSuggestions().equals("无")) {
|
|
|
resultMap0.put("建议", scaleMarksEntity.getImprovementSuggestions());
|
|
|
resultJson.put("建议", scaleMarksEntity.getImprovementSuggestions());
|
|
|
}
|
|
@@ -95,29 +97,29 @@ public class COMMONScale extends BaseScale{
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- if (scaleMarksEntities.size() > 0){
|
|
|
+ if (scaleMarksEntities.size() > 0) {
|
|
|
for (int y = 0; y < dimensionEntities.size(); y++) {
|
|
|
DimensionEntity dimensionEntity = dimensionEntities.get(y);
|
|
|
- DecimalFormat df = new DecimalFormat("######0.00");
|
|
|
- resultMap0.put(dimensionEntity.getName()+"得分", String.valueOf(Double.parseDouble(df.format(dimensionScore[y]))));
|
|
|
- resultJson.put(dimensionEntity.getName()+"得分", String.valueOf(Double.parseDouble(df.format(dimensionScore[y]))));
|
|
|
- for (ScaleMarksEntity scaleMarksEntity:scaleMarksEntities){
|
|
|
- if (scaleMarksEntity.getName() != null && scaleMarksEntity.getName().equals(dimensionEntity.getName())){
|
|
|
- if (dimensionScore[y] <= Integer.valueOf(scaleMarksEntity.getScoreEnd()) && dimensionScore[y] >= Integer.valueOf(scaleMarksEntity.getScoreStart())){
|
|
|
- if (!scaleMarksEntity.getSymptom().equals("无")){
|
|
|
- resultMap0.put(dimensionEntity.getName()+"解读", scaleMarksEntity.getSymptom());
|
|
|
- resultJson.put(dimensionEntity.getName()+"解读", scaleMarksEntity.getSymptom());
|
|
|
+ DecimalFormat df = new DecimalFormat("######0.00");
|
|
|
+ resultMap0.put(dimensionEntity.getName() + "得分", String.valueOf(Double.parseDouble(df.format(dimensionScore[y]))));
|
|
|
+ resultJson.put(dimensionEntity.getName() + "得分", String.valueOf(Double.parseDouble(df.format(dimensionScore[y]))));
|
|
|
+ for (ScaleMarksEntity scaleMarksEntity : scaleMarksEntities) {
|
|
|
+ if (scaleMarksEntity.getName() != null && scaleMarksEntity.getName().equals(dimensionEntity.getName())) {
|
|
|
+ if (dimensionScore[y] <= Integer.parseInt(scaleMarksEntity.getScoreEnd()) && dimensionScore[y] >= Integer.parseInt(scaleMarksEntity.getScoreStart())) {
|
|
|
+ if (!scaleMarksEntity.getSymptom().equals("无")) {
|
|
|
+ resultMap0.put(dimensionEntity.getName() + "结论", scaleMarksEntity.getSymptom());
|
|
|
+ resultJson.put(dimensionEntity.getName() + "结论", scaleMarksEntity.getSymptom());
|
|
|
}
|
|
|
- if (scaleMarksEntity.getImprovementSuggestions() != null && !scaleMarksEntity.getImprovementSuggestions().equals("无")){
|
|
|
- resultMap0.put(dimensionEntity.getName()+"建议", scaleMarksEntity.getImprovementSuggestions());
|
|
|
- resultJson.put(dimensionEntity.getName()+"建议", scaleMarksEntity.getImprovementSuggestions());
|
|
|
+ if (scaleMarksEntity.getImprovementSuggestions() != null && !scaleMarksEntity.getImprovementSuggestions().equals("无")) {
|
|
|
+ resultMap0.put(dimensionEntity.getName() + "建议", scaleMarksEntity.getImprovementSuggestions());
|
|
|
+ resultJson.put(dimensionEntity.getName() + "建议", scaleMarksEntity.getImprovementSuggestions());
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
resultMapList.add(resultMap0);
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
for (int y = 0; y < dimensionEntities.size(); y++) {
|
|
|
DimensionEntity dimensionEntity = dimensionEntities.get(y);
|
|
|
DecimalFormat df = new DecimalFormat("######0.00");
|
|
@@ -126,14 +128,13 @@ public class COMMONScale extends BaseScale{
|
|
|
}
|
|
|
resultMapList.add(resultMap0);
|
|
|
}
|
|
|
-
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
for (int i = 0; i < jsonArray.size(); i++) {
|
|
|
JSONObject jsonObject1 = jsonArray.getJSONObject(i);
|
|
|
- for (AnswerEntity answerEntity:answerEntities){
|
|
|
- if (answerEntity.getQuestionNo().equals(String.valueOf(i+1))){
|
|
|
- if (answerEntity.getName().equals(jsonObject1.getString("checkItems"))){
|
|
|
- score += Integer.valueOf(answerEntity.getScore());
|
|
|
+ for (AnswerEntity answerEntity : answerEntities) {
|
|
|
+ if (answerEntity.getQuestionNo().equals(String.valueOf(i + 1))) {
|
|
|
+ if (answerEntity.getName().replaceAll("\\s", "").equals(jsonObject1.getString("checkItems").replaceAll("\\s", ""))) {
|
|
|
+ score += Double.parseDouble(answerEntity.getScore());
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -141,14 +142,14 @@ public class COMMONScale extends BaseScale{
|
|
|
|
|
|
resultMap0.put("总分", String.valueOf(score));
|
|
|
resultJson.put("总分", String.valueOf(score));
|
|
|
- if (scaleMarksEntities.size() > 0){
|
|
|
- for (ScaleMarksEntity scaleMarksEntity:scaleMarksEntities){
|
|
|
- if (score <= Integer.valueOf(scaleMarksEntity.getScoreEnd()) && score >= Integer.valueOf(scaleMarksEntity.getScoreStart())){
|
|
|
- if (!scaleMarksEntity.getSymptom().equals("无")){
|
|
|
- resultMap0.put("解读", scaleMarksEntity.getSymptom());
|
|
|
- resultJson.put("解读", scaleMarksEntity.getSymptom());
|
|
|
+ if (scaleMarksEntities.size() > 0) {
|
|
|
+ for (ScaleMarksEntity scaleMarksEntity : scaleMarksEntities) {
|
|
|
+ if (score <= Integer.parseInt(scaleMarksEntity.getScoreEnd()) && score >= Integer.parseInt(scaleMarksEntity.getScoreStart())) {
|
|
|
+ if (!scaleMarksEntity.getSymptom().equals("无")) {
|
|
|
+ resultMap0.put("结论", scaleMarksEntity.getSymptom());
|
|
|
+ resultJson.put("结论", scaleMarksEntity.getSymptom());
|
|
|
}
|
|
|
- if (scaleMarksEntity.getImprovementSuggestions() != null && !scaleMarksEntity.getImprovementSuggestions().equals("无")){
|
|
|
+ if (scaleMarksEntity.getImprovementSuggestions() != null && !scaleMarksEntity.getImprovementSuggestions().equals("无")) {
|
|
|
resultMap0.put("建议", scaleMarksEntity.getImprovementSuggestions());
|
|
|
resultJson.put("建议", scaleMarksEntity.getImprovementSuggestions());
|
|
|
}
|
|
@@ -157,12 +158,16 @@ public class COMMONScale extends BaseScale{
|
|
|
}
|
|
|
resultMapList.add(resultMap0);
|
|
|
}
|
|
|
+ resultJson.put("dimensionScoreMap",dimensionScoreMap);
|
|
|
+
|
|
|
+
|
|
|
|
|
|
JSONObject returnJson = new JSONObject(true);
|
|
|
- returnJson.put("resultMapList",resultMapList);
|
|
|
- //returnJson.put("scaleName",resultJson.getString("scaleName"));
|
|
|
- returnJson.put("resultJson",resultJson);
|
|
|
+ returnJson.put("resultMapList", resultMapList);
|
|
|
+ returnJson.put("resultJson", resultJson);
|
|
|
|
|
|
return returnJson;
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
}
|