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.DimensionEntity;
import com.rf.psychological.scale.dao.model.ScaleMarksEntity;
import com.rf.psychological.scale.dao.model.WarnEntity;
import com.rf.psychological.scale.scaleresult.ScaleConstant;
import com.rf.psychological.utils.Constant;
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 zsy
 * @description:青少年学生疏离感量表
 * @date 2021/7/20 15:55
 */
public class ASASScale extends BaseScale {

    public ASASScale(JSONArray jsonArray, JSONObject resultJson) {
        super(jsonArray, resultJson);
    }

    public JSONObject scaleCalculate() throws Exception {

        // 自定义路径使用
        /*ScaleUtil.getScaleDll("ASASSCALE.dll");
        System.out.println("JSONArray:"+jsonArray);
        System.out.println("resultJson:"+resultJson);
        XScale xScale = new XScale(jsonArray,resultJson);
        String result = xScale.ASASScale(jsonArray.toString(), resultJson.toString());
        //System.out.println("dllresult:"+result);
        //解决排序问题
        LinkedHashMap<String, Object> jsonMap = JSON.parseObject(result,LinkedHashMap.class, Feature.OrderedField);
        JSONObject jsonObject = new JSONObject(true);
        jsonObject.putAll(jsonMap);
        System.out.println("jsonObject:"+jsonObject);
        return jsonObject;*/


        if (!jsonArray.getJSONObject(7).getString("checkItems").equals(jsonArray.getJSONObject(44).getString("checkItems"))
                || !jsonArray.getJSONObject(11).getString("checkItems").equals(jsonArray.getJSONObject(46).getString("checkItems"))
                || !jsonArray.getJSONObject(12).getString("checkItems").equals(jsonArray.getJSONObject(16).getString("checkItems"))) {
            resultJson.put("测试结果指导", "请认真按照实际情况如实回答");
            JSONObject returnJson = new JSONObject(true);
            returnJson.put("resultJson", resultJson);
            return returnJson;
        }
        //总得分
        int score = 0;
        //总平均分
        double GPA = 0;
        //无意义感维度得分
        int score1 = 0;
        //自我疏离感维度得分
        int score2 = 0;
        //孤独感维度得分
        int score3 = 0;
        //自然疏离感维度得分
        int score4 = 0;
        //亲人疏离感维度得分
        int score5 = 0;
        //生活环境疏离感维度得分
        int score6 = 0;
        //社会孤立感得分
        int score7 = 0;
        //压迫拘束感维度得分
        int score8 = 0;
        //不可控制感维度得分
        int score9 = 0;
        for (int i = 0; i < jsonArray.size(); i++) {
            JSONObject jsonObject1 = jsonArray.getJSONObject(i);
            if (jsonObject1.getString("scoreDirection").equals("1")) {
                if (i == 5 || i == 10 || i == 15 || i == 39 || i == 42 || i == 49) {
                    if (jsonObject1.getString("checkItems").equals("完全不符合")) {
                        score1 += 1;
                    } else if (jsonObject1.getString("checkItems").equals("比较不符合")) {
                        score1 += 2;
                    } else if (jsonObject1.getString("checkItems").equals("有点不符合")) {
                        score1 += 3;
                    } else if (jsonObject1.getString("checkItems").equals("不确定")) {
                        score1 += 4;
                    } else if (jsonObject1.getString("checkItems").equals("有点符合")) {
                        score1 += 5;
                    } else if (jsonObject1.getString("checkItems").equals("比较符合")) {
                        score1 += 6;
                    } else if (jsonObject1.getString("checkItems").equals("完全符合")) {
                        score1 += 7;
                    }
                } else if (i == 6 || i == 13 || i == 19 || i == 24 || i == 33 || i == 40) {
                    if (jsonObject1.getString("checkItems").equals("完全不符合")) {
                        score2 += 1;
                    } else if (jsonObject1.getString("checkItems").equals("比较不符合")) {
                        score2 += 2;
                    } else if (jsonObject1.getString("checkItems").equals("有点不符合")) {
                        score2 += 3;
                    } else if (jsonObject1.getString("checkItems").equals("不确定")) {
                        score2 += 4;
                    } else if (jsonObject1.getString("checkItems").equals("有点符合")) {
                        score2 += 5;
                    } else if (jsonObject1.getString("checkItems").equals("比较符合")) {
                        score2 += 6;
                    } else if (jsonObject1.getString("checkItems").equals("完全符合")) {
                        score2 += 7;
                    }
                } else if (i == 2 || i == 8 || i == 22 || i == 38) {
                    if (jsonObject1.getString("checkItems").equals("完全不符合")) {
                        score4 += 1;
                    } else if (jsonObject1.getString("checkItems").equals("比较不符合")) {
                        score4 += 2;
                    } else if (jsonObject1.getString("checkItems").equals("有点不符合")) {
                        score4 += 3;
                    } else if (jsonObject1.getString("checkItems").equals("不确定")) {
                        score4 += 4;
                    } else if (jsonObject1.getString("checkItems").equals("有点符合")) {
                        score4 += 5;
                    } else if (jsonObject1.getString("checkItems").equals("比较符合")) {
                        score4 += 6;
                    } else if (jsonObject1.getString("checkItems").equals("完全符合")) {
                        score4 += 7;
                    }
                } else if (i == 21 || i == 47 || i == 50 || i == 51) {
                    if (jsonObject1.getString("checkItems").equals("完全不符合")) {
                        score5 += 1;
                    } else if (jsonObject1.getString("checkItems").equals("比较不符合")) {
                        score5 += 2;
                    } else if (jsonObject1.getString("checkItems").equals("有点不符合")) {
                        score5 += 3;
                    } else if (jsonObject1.getString("checkItems").equals("不确定")) {
                        score5 += 4;
                    } else if (jsonObject1.getString("checkItems").equals("有点符合")) {
                        score5 += 5;
                    } else if (jsonObject1.getString("checkItems").equals("比较符合")) {
                        score5 += 6;
                    } else if (jsonObject1.getString("checkItems").equals("完全符合")) {
                        score5 += 7;
                    }
                } else if (i == 41 || i == 45 || i == 48) {
                    if (jsonObject1.getString("checkItems").equals("完全不符合")) {
                        score6 += 1;
                    } else if (jsonObject1.getString("checkItems").equals("比较不符合")) {
                        score6 += 2;
                    } else if (jsonObject1.getString("checkItems").equals("有点不符合")) {
                        score6 += 3;
                    } else if (jsonObject1.getString("checkItems").equals("不确定")) {
                        score6 += 4;
                    } else if (jsonObject1.getString("checkItems").equals("有点符合")) {
                        score6 += 5;
                    } else if (jsonObject1.getString("checkItems").equals("比较符合")) {
                        score6 += 6;
                    } else if (jsonObject1.getString("checkItems").equals("完全符合")) {
                        score6 += 7;
                    }
                } else if (i == 1 || i == 18 || i == 26 || i == 29 || i == 34 || i == 43) {
                    if (jsonObject1.getString("checkItems").equals("完全不符合")) {
                        score7 += 1;
                    } else if (jsonObject1.getString("checkItems").equals("比较不符合")) {
                        score7 += 2;
                    } else if (jsonObject1.getString("checkItems").equals("有点不符合")) {
                        score7 += 3;
                    } else if (jsonObject1.getString("checkItems").equals("不确定")) {
                        score7 += 4;
                    } else if (jsonObject1.getString("checkItems").equals("有点符合")) {
                        score7 += 5;
                    } else if (jsonObject1.getString("checkItems").equals("比较符合")) {
                        score7 += 6;
                    } else if (jsonObject1.getString("checkItems").equals("完全符合")) {
                        score7 += 7;
                    }
                } else if (i == 20 || i == 28 || i == 30 || i == 31 || i == 36 || i == 37) {
                    if (jsonObject1.getString("checkItems").equals("完全不符合")) {
                        score8 += 1;
                    } else if (jsonObject1.getString("checkItems").equals("比较不符合")) {
                        score8 += 2;
                    } else if (jsonObject1.getString("checkItems").equals("有点不符合")) {
                        score8 += 3;
                    } else if (jsonObject1.getString("checkItems").equals("不确定")) {
                        score8 += 4;
                    } else if (jsonObject1.getString("checkItems").equals("有点符合")) {
                        score8 += 5;
                    } else if (jsonObject1.getString("checkItems").equals("比较符合")) {
                        score8 += 6;
                    } else if (jsonObject1.getString("checkItems").equals("完全符合")) {
                        score8 += 7;
                    }
                } else if (i == 3 || i == 4 || i == 9 || i == 25) {
                    if (jsonObject1.getString("checkItems").equals("完全不符合")) {
                        score9 += 1;
                    } else if (jsonObject1.getString("checkItems").equals("比较不符合")) {
                        score9 += 2;
                    } else if (jsonObject1.getString("checkItems").equals("有点不符合")) {
                        score9 += 3;
                    } else if (jsonObject1.getString("checkItems").equals("不确定")) {
                        score9 += 4;
                    } else if (jsonObject1.getString("checkItems").equals("有点符合")) {
                        score9 += 5;
                    } else if (jsonObject1.getString("checkItems").equals("比较符合")) {
                        score9 += 6;
                    } else if (jsonObject1.getString("checkItems").equals("完全符合")) {
                        score9 += 7;
                    }
                } else if (i == 7 || i == 44 || i == 11 || i == 46 || i == 12 || i == 16) {
                    if (jsonObject1.getString("checkItems").equals("完全不符合")) {
                        score += 1;
                    } else if (jsonObject1.getString("checkItems").equals("比较不符合")) {
                        score += 2;
                    } else if (jsonObject1.getString("checkItems").equals("有点不符合")) {
                        score += 3;
                    } else if (jsonObject1.getString("checkItems").equals("不确定")) {
                        score += 4;
                    } else if (jsonObject1.getString("checkItems").equals("有点符合")) {
                        score += 5;
                    } else if (jsonObject1.getString("checkItems").equals("比较符合")) {
                        score += 6;
                    } else if (jsonObject1.getString("checkItems").equals("完全符合")) {
                        score += 7;
                    }
                } else {
                    if (jsonObject1.getString("checkItems").equals("完全不符合")) {
                        score3 += 1;
                    } else if (jsonObject1.getString("checkItems").equals("比较不符合")) {
                        score3 += 2;
                    } else if (jsonObject1.getString("checkItems").equals("有点不符合")) {
                        score3 += 3;
                    } else if (jsonObject1.getString("checkItems").equals("不确定")) {
                        score3 += 4;
                    } else if (jsonObject1.getString("checkItems").equals("有点符合")) {
                        score3 += 5;
                    } else if (jsonObject1.getString("checkItems").equals("比较符合")) {
                        score3 += 6;
                    } else if (jsonObject1.getString("checkItems").equals("完全符合")) {
                        score3 += 7;
                    }
                }
            } else if (jsonObject1.getString("scoreDirection").equals("0")) {
                if (i == 5 || i == 10 || i == 15 || i == 39 || i == 42 || i == 49) {
                    if (jsonObject1.getString("checkItems").equals("完全不符合")) {
                        score1 += 7;
                    } else if (jsonObject1.getString("checkItems").equals("比较不符合")) {
                        score1 += 6;
                    } else if (jsonObject1.getString("checkItems").equals("有点不符合")) {
                        score1 += 5;
                    } else if (jsonObject1.getString("checkItems").equals("不确定")) {
                        score1 += 4;
                    } else if (jsonObject1.getString("checkItems").equals("有点符合")) {
                        score1 += 3;
                    } else if (jsonObject1.getString("checkItems").equals("比较符合")) {
                        score1 += 2;
                    } else if (jsonObject1.getString("checkItems").equals("完全符合")) {
                        score1 += 1;
                    }
                } else if (i == 6 || i == 13 || i == 19 || i == 24 || i == 33 || i == 40) {
                    if (jsonObject1.getString("checkItems").equals("完全不符合")) {
                        score2 += 7;
                    } else if (jsonObject1.getString("checkItems").equals("比较不符合")) {
                        score2 += 6;
                    } else if (jsonObject1.getString("checkItems").equals("有点不符合")) {
                        score2 += 5;
                    } else if (jsonObject1.getString("checkItems").equals("不确定")) {
                        score2 += 4;
                    } else if (jsonObject1.getString("checkItems").equals("有点符合")) {
                        score2 += 3;
                    } else if (jsonObject1.getString("checkItems").equals("比较符合")) {
                        score2 += 2;
                    } else if (jsonObject1.getString("checkItems").equals("完全符合")) {
                        score2 += 1;
                    }
                } else if (i == 2 || i == 8 || i == 22 || i == 38) {
                    if (jsonObject1.getString("checkItems").equals("完全不符合")) {
                        score4 += 7;
                    } else if (jsonObject1.getString("checkItems").equals("比较不符合")) {
                        score4 += 6;
                    } else if (jsonObject1.getString("checkItems").equals("有点不符合")) {
                        score4 += 5;
                    } else if (jsonObject1.getString("checkItems").equals("不确定")) {
                        score4 += 4;
                    } else if (jsonObject1.getString("checkItems").equals("有点符合")) {
                        score4 += 3;
                    } else if (jsonObject1.getString("checkItems").equals("比较符合")) {
                        score4 += 2;
                    } else if (jsonObject1.getString("checkItems").equals("完全符合")) {
                        score4 += 1;
                    }
                } else if (i == 21 || i == 47 || i == 50 || i == 51) {
                    if (jsonObject1.getString("checkItems").equals("完全不符合")) {
                        score5 += 7;
                    } else if (jsonObject1.getString("checkItems").equals("比较不符合")) {
                        score5 += 6;
                    } else if (jsonObject1.getString("checkItems").equals("有点不符合")) {
                        score5 += 5;
                    } else if (jsonObject1.getString("checkItems").equals("不确定")) {
                        score5 += 4;
                    } else if (jsonObject1.getString("checkItems").equals("有点符合")) {
                        score5 += 3;
                    } else if (jsonObject1.getString("checkItems").equals("比较符合")) {
                        score5 += 2;
                    } else if (jsonObject1.getString("checkItems").equals("完全符合")) {
                        score5 += 1;
                    }
                } else if (i == 41 || i == 45 || i == 48) {
                    if (jsonObject1.getString("checkItems").equals("完全不符合")) {
                        score6 += 7;
                    } else if (jsonObject1.getString("checkItems").equals("比较不符合")) {
                        score6 += 6;
                    } else if (jsonObject1.getString("checkItems").equals("有点不符合")) {
                        score6 += 5;
                    } else if (jsonObject1.getString("checkItems").equals("不确定")) {
                        score6 += 4;
                    } else if (jsonObject1.getString("checkItems").equals("有点符合")) {
                        score6 += 3;
                    } else if (jsonObject1.getString("checkItems").equals("比较符合")) {
                        score6 += 2;
                    } else if (jsonObject1.getString("checkItems").equals("完全符合")) {
                        score6 += 1;
                    }
                } else if (i == 1 || i == 18 || i == 26 || i == 29 || i == 34 || i == 43) {
                    if (jsonObject1.getString("checkItems").equals("完全不符合")) {
                        score7 += 7;
                    } else if (jsonObject1.getString("checkItems").equals("比较不符合")) {
                        score7 += 6;
                    } else if (jsonObject1.getString("checkItems").equals("有点不符合")) {
                        score7 += 5;
                    } else if (jsonObject1.getString("checkItems").equals("不确定")) {
                        score7 += 4;
                    } else if (jsonObject1.getString("checkItems").equals("有点符合")) {
                        score7 += 3;
                    } else if (jsonObject1.getString("checkItems").equals("比较符合")) {
                        score7 += 2;
                    } else if (jsonObject1.getString("checkItems").equals("完全符合")) {
                        score7 += 1;
                    }
                } else if (i == 20 || i == 28 || i == 30 || i == 31 || i == 36 || i == 37) {
                    if (jsonObject1.getString("checkItems").equals("完全不符合")) {
                        score8 += 7;
                    } else if (jsonObject1.getString("checkItems").equals("比较不符合")) {
                        score8 += 6;
                    } else if (jsonObject1.getString("checkItems").equals("有点不符合")) {
                        score8 += 5;
                    } else if (jsonObject1.getString("checkItems").equals("不确定")) {
                        score8 += 4;
                    } else if (jsonObject1.getString("checkItems").equals("有点符合")) {
                        score8 += 3;
                    } else if (jsonObject1.getString("checkItems").equals("比较符合")) {
                        score8 += 2;
                    } else if (jsonObject1.getString("checkItems").equals("完全符合")) {
                        score8 += 1;
                    }
                } else if (i == 3 || i == 4 || i == 9 || i == 25) {
                    if (jsonObject1.getString("checkItems").equals("完全不符合")) {
                        score9 += 7;
                    } else if (jsonObject1.getString("checkItems").equals("比较不符合")) {
                        score9 += 6;
                    } else if (jsonObject1.getString("checkItems").equals("有点不符合")) {
                        score9 += 5;
                    } else if (jsonObject1.getString("checkItems").equals("不确定")) {
                        score9 += 4;
                    } else if (jsonObject1.getString("checkItems").equals("有点符合")) {
                        score9 += 3;
                    } else if (jsonObject1.getString("checkItems").equals("比较符合")) {
                        score9 += 2;
                    } else if (jsonObject1.getString("checkItems").equals("完全符合")) {
                        score9 += 1;
                    }
                } else if (i == 7 || i == 44 || i == 11 || i == 46 || i == 12 || i == 16) {
                    if (jsonObject1.getString("checkItems").equals("完全不符合")) {
                        score += 7;
                    } else if (jsonObject1.getString("checkItems").equals("比较不符合")) {
                        score += 6;
                    } else if (jsonObject1.getString("checkItems").equals("有点不符合")) {
                        score += 5;
                    } else if (jsonObject1.getString("checkItems").equals("不确定")) {
                        score += 4;
                    } else if (jsonObject1.getString("checkItems").equals("有点符合")) {
                        score += 3;
                    } else if (jsonObject1.getString("checkItems").equals("比较符合")) {
                        score += 2;
                    } else if (jsonObject1.getString("checkItems").equals("完全符合")) {
                        score += 1;
                    }
                } else {
                    if (jsonObject1.getString("checkItems").equals("完全不符合")) {
                        score3 += 7;
                    } else if (jsonObject1.getString("checkItems").equals("比较不符合")) {
                        score3 += 6;
                    } else if (jsonObject1.getString("checkItems").equals("有点不符合")) {
                        score3 += 5;
                    } else if (jsonObject1.getString("checkItems").equals("不确定")) {
                        score3 += 4;
                    } else if (jsonObject1.getString("checkItems").equals("有点符合")) {
                        score3 += 3;
                    } else if (jsonObject1.getString("checkItems").equals("比较符合")) {
                        score3 += 2;
                    } else if (jsonObject1.getString("checkItems").equals("完全符合")) {
                        score3 += 1;
                    }
                }
            }
        }
        List<Map<String, String>> resultMapList = new ArrayList<>();
        score = score1 + score2 + score3 + score4 + score5 + score6 + score7 + score8 + score9;
        DecimalFormat df = new DecimalFormat("######0.00");
        GPA = Double.parseDouble(df.format(score / 52));
        //得分列表
        Map<String, String> resultMap = new LinkedHashMap<>();
        resultMap.put("疏离感总分", String.valueOf(score));
        resultJson.put("疏离感总分", String.valueOf(score));
        resultMap.put("疏离感平均分", String.valueOf(GPA));
        resultJson.put("疏离感平均分", String.valueOf(GPA));
        if (GPA >= 4) {
            resultMap.put("结论", "有一定程度的疏离感");
            resultJson.put("结论", "有一定程度的疏离感");
        } else {
            resultMap.put("结论", "疏离感不明显");
            resultJson.put("结论", "疏离感不明显");
        }
        resultMapList.add(resultMap);
        //得分列表
        Map<String, String> resultMap1 = new LinkedHashMap<>();
        resultMap1.put("无意义感维度得分", String.valueOf(score1));
        resultJson.put("无意义感维度得分", String.valueOf(score1));
        resultMapList.add(resultMap1);
        Map<String, String> resultMap2 = new LinkedHashMap<>();
        resultMap2.put("自我疏离感维度得分", String.valueOf(score2));
        resultJson.put("自我疏离感维度得分", String.valueOf(score2));
        resultMapList.add(resultMap2);
        Map<String, String> resultMap3 = new LinkedHashMap<>();
        resultMap3.put("孤独感维度得分", String.valueOf(score3));
        resultJson.put("孤独感维度得分", String.valueOf(score3));
        resultMapList.add(resultMap3);
        Map<String, String> resultMap4 = new LinkedHashMap<>();
        resultMap4.put("自然疏离感维度得分", String.valueOf(score4));
        resultJson.put("自然疏离感维度得分", String.valueOf(score4));
        resultMapList.add(resultMap4);
        Map<String, String> resultMap5 = new LinkedHashMap<>();
        resultMap5.put("亲人疏离感维度得分", String.valueOf(score5));
        resultJson.put("亲人疏离感维度得分", String.valueOf(score5));
        resultMapList.add(resultMap5);
        Map<String, String> resultMap6 = new LinkedHashMap<>();
        resultMap6.put("生活环境疏离感维度得分", String.valueOf(score6));
        resultJson.put("生活环境疏离感维度得分", String.valueOf(score6));
        resultMapList.add(resultMap6);
        Map<String, String> resultMap7 = new LinkedHashMap<>();
        resultMap7.put("社会孤立感得分", String.valueOf(score7));
        resultJson.put("社会孤立感得分", String.valueOf(score7));
        resultMapList.add(resultMap7);
        Map<String, String> resultMap8 = new LinkedHashMap<>();
        resultMap8.put("压迫拘束感维度得分", String.valueOf(score8));
        resultJson.put("压迫拘束感维度得分", String.valueOf(score8));
        resultMapList.add(resultMap8);
        Map<String, String> resultMap9 = new LinkedHashMap<>();
        resultMap9.put("不可控制感维度得分", String.valueOf(score9));
        resultJson.put("不可控制感维度得分", String.valueOf(score9));
        resultMapList.add(resultMap9);
        Map<String, String> resultMap10 = new LinkedHashMap<>();
        resultMap10.put("社会疏离感得分", String.valueOf(score1 + score2 + score7 + score8));
        resultJson.put("社会疏离感得分", String.valueOf(score1 + score2 + score7 + score8));
        resultMapList.add(resultMap10);
        Map<String, String> resultMap11 = new LinkedHashMap<>();
        resultMap11.put("人际疏离感得分", String.valueOf(score3 + score5 + score9));
        resultJson.put("人际疏离感得分", String.valueOf(score3 + score5 + score9));
        resultMapList.add(resultMap11);
        Map<String, String> resultMap12 = new LinkedHashMap<>();
        resultMap12.put("环境疏离感得分", String.valueOf(score4 + score6));
        resultJson.put("环境疏离感得分", String.valueOf(score4 + score6));
        resultMapList.add(resultMap12);

        JSONObject returnJson = new JSONObject(true);
        returnJson.put("resultMapList", resultMapList);
        returnJson.put("scaleName", Constant.SHEET_NAME_ASAS);
        returnJson.put("resultJson", resultJson);

        return returnJson;
    }

    public JSONObject scaleCalculateV2() throws Exception {

        if (!jsonArray.getJSONObject(7).getString("checkItems").equals(jsonArray.getJSONObject(44).getString("checkItems"))
                || !jsonArray.getJSONObject(11).getString("checkItems").equals(jsonArray.getJSONObject(46).getString("checkItems"))
                || !jsonArray.getJSONObject(12).getString("checkItems").equals(jsonArray.getJSONObject(16).getString("checkItems"))) {
            resultJson.put("测试结果指导", "请认真按照实际情况如实回答");
            JSONObject returnJson = new JSONObject(true);
            returnJson.put("resultJson", resultJson);
            return returnJson;
        }
        //获取评分规则列表
        //List<ScaleMarksEntity> scaleMarksEntities = (List<ScaleMarksEntity>) resultJson.get("scaleMarksEntities");
        //获取维度信息列表
        //List<DimensionEntity> dimensionEntities = (List<DimensionEntity>) resultJson.get("dimensionEntities");
        //总得分
        double score = 0;
        //总平均分
        double GPA = 0;
        //无意义感维度得分
        int score1 = 0;
        //自我疏离感维度得分
        int score2 = 0;
        //孤独感维度得分
        int score3 = 0;
        //自然疏离感维度得分
        int score4 = 0;
        //亲人疏离感维度得分
        int score5 = 0;
        //生活环境疏离感维度得分
        int score6 = 0;
        //社会孤立感得分
        int score7 = 0;
        //压迫拘束感维度得分
        int score8 = 0;
        //不可控制感维度得分
        int score9 = 0;
        for (int i = 0; i < jsonArray.size(); i++) {
            JSONObject jsonObject1 = jsonArray.getJSONObject(i);
            if (jsonObject1.getString("scoreDirection").equals("1")) {
                if (i == 5 || i == 10 || i == 15 || i == 39 || i == 42 || i == 49) {
                    if (jsonObject1.getString("checkItems").equals("完全不符合")) {
                        score1 += 1;
                    } else if (jsonObject1.getString("checkItems").equals("比较不符合")) {
                        score1 += 2;
                    } else if (jsonObject1.getString("checkItems").equals("有点不符合")) {
                        score1 += 3;
                    } else if (jsonObject1.getString("checkItems").equals("不确定")) {
                        score1 += 4;
                    } else if (jsonObject1.getString("checkItems").equals("有点符合")) {
                        score1 += 5;
                    } else if (jsonObject1.getString("checkItems").equals("比较符合")) {
                        score1 += 6;
                    } else if (jsonObject1.getString("checkItems").equals("完全符合")) {
                        score1 += 7;
                    }
                } else if (i == 6 || i == 13 || i == 19 || i == 24 || i == 33 || i == 40) {
                    if (jsonObject1.getString("checkItems").equals("完全不符合")) {
                        score2 += 1;
                    } else if (jsonObject1.getString("checkItems").equals("比较不符合")) {
                        score2 += 2;
                    } else if (jsonObject1.getString("checkItems").equals("有点不符合")) {
                        score2 += 3;
                    } else if (jsonObject1.getString("checkItems").equals("不确定")) {
                        score2 += 4;
                    } else if (jsonObject1.getString("checkItems").equals("有点符合")) {
                        score2 += 5;
                    } else if (jsonObject1.getString("checkItems").equals("比较符合")) {
                        score2 += 6;
                    } else if (jsonObject1.getString("checkItems").equals("完全符合")) {
                        score2 += 7;
                    }
                } else if (i == 2 || i == 8 || i == 22 || i == 38) {
                    if (jsonObject1.getString("checkItems").equals("完全不符合")) {
                        score4 += 1;
                    } else if (jsonObject1.getString("checkItems").equals("比较不符合")) {
                        score4 += 2;
                    } else if (jsonObject1.getString("checkItems").equals("有点不符合")) {
                        score4 += 3;
                    } else if (jsonObject1.getString("checkItems").equals("不确定")) {
                        score4 += 4;
                    } else if (jsonObject1.getString("checkItems").equals("有点符合")) {
                        score4 += 5;
                    } else if (jsonObject1.getString("checkItems").equals("比较符合")) {
                        score4 += 6;
                    } else if (jsonObject1.getString("checkItems").equals("完全符合")) {
                        score4 += 7;
                    }
                } else if (i == 21 || i == 47 || i == 50 || i == 51) {
                    if (jsonObject1.getString("checkItems").equals("完全不符合")) {
                        score5 += 1;
                    } else if (jsonObject1.getString("checkItems").equals("比较不符合")) {
                        score5 += 2;
                    } else if (jsonObject1.getString("checkItems").equals("有点不符合")) {
                        score5 += 3;
                    } else if (jsonObject1.getString("checkItems").equals("不确定")) {
                        score5 += 4;
                    } else if (jsonObject1.getString("checkItems").equals("有点符合")) {
                        score5 += 5;
                    } else if (jsonObject1.getString("checkItems").equals("比较符合")) {
                        score5 += 6;
                    } else if (jsonObject1.getString("checkItems").equals("完全符合")) {
                        score5 += 7;
                    }
                } else if (i == 41 || i == 45 || i == 48) {
                    if (jsonObject1.getString("checkItems").equals("完全不符合")) {
                        score6 += 1;
                    } else if (jsonObject1.getString("checkItems").equals("比较不符合")) {
                        score6 += 2;
                    } else if (jsonObject1.getString("checkItems").equals("有点不符合")) {
                        score6 += 3;
                    } else if (jsonObject1.getString("checkItems").equals("不确定")) {
                        score6 += 4;
                    } else if (jsonObject1.getString("checkItems").equals("有点符合")) {
                        score6 += 5;
                    } else if (jsonObject1.getString("checkItems").equals("比较符合")) {
                        score6 += 6;
                    } else if (jsonObject1.getString("checkItems").equals("完全符合")) {
                        score6 += 7;
                    }
                } else if (i == 1 || i == 18 || i == 26 || i == 29 || i == 34 || i == 43) {
                    if (jsonObject1.getString("checkItems").equals("完全不符合")) {
                        score7 += 1;
                    } else if (jsonObject1.getString("checkItems").equals("比较不符合")) {
                        score7 += 2;
                    } else if (jsonObject1.getString("checkItems").equals("有点不符合")) {
                        score7 += 3;
                    } else if (jsonObject1.getString("checkItems").equals("不确定")) {
                        score7 += 4;
                    } else if (jsonObject1.getString("checkItems").equals("有点符合")) {
                        score7 += 5;
                    } else if (jsonObject1.getString("checkItems").equals("比较符合")) {
                        score7 += 6;
                    } else if (jsonObject1.getString("checkItems").equals("完全符合")) {
                        score7 += 7;
                    }
                } else if (i == 20 || i == 28 || i == 30 || i == 31 || i == 36 || i == 37) {
                    if (jsonObject1.getString("checkItems").equals("完全不符合")) {
                        score8 += 1;
                    } else if (jsonObject1.getString("checkItems").equals("比较不符合")) {
                        score8 += 2;
                    } else if (jsonObject1.getString("checkItems").equals("有点不符合")) {
                        score8 += 3;
                    } else if (jsonObject1.getString("checkItems").equals("不确定")) {
                        score8 += 4;
                    } else if (jsonObject1.getString("checkItems").equals("有点符合")) {
                        score8 += 5;
                    } else if (jsonObject1.getString("checkItems").equals("比较符合")) {
                        score8 += 6;
                    } else if (jsonObject1.getString("checkItems").equals("完全符合")) {
                        score8 += 7;
                    }
                } else if (i == 3 || i == 4 || i == 9 || i == 25) {
                    if (jsonObject1.getString("checkItems").equals("完全不符合")) {
                        score9 += 1;
                    } else if (jsonObject1.getString("checkItems").equals("比较不符合")) {
                        score9 += 2;
                    } else if (jsonObject1.getString("checkItems").equals("有点不符合")) {
                        score9 += 3;
                    } else if (jsonObject1.getString("checkItems").equals("不确定")) {
                        score9 += 4;
                    } else if (jsonObject1.getString("checkItems").equals("有点符合")) {
                        score9 += 5;
                    } else if (jsonObject1.getString("checkItems").equals("比较符合")) {
                        score9 += 6;
                    } else if (jsonObject1.getString("checkItems").equals("完全符合")) {
                        score9 += 7;
                    }
                } else if (i == 7 || i == 44 || i == 11 || i == 46 || i == 12 || i == 16) {
                    if (jsonObject1.getString("checkItems").equals("完全不符合")) {
                        score += 1;
                    } else if (jsonObject1.getString("checkItems").equals("比较不符合")) {
                        score += 2;
                    } else if (jsonObject1.getString("checkItems").equals("有点不符合")) {
                        score += 3;
                    } else if (jsonObject1.getString("checkItems").equals("不确定")) {
                        score += 4;
                    } else if (jsonObject1.getString("checkItems").equals("有点符合")) {
                        score += 5;
                    } else if (jsonObject1.getString("checkItems").equals("比较符合")) {
                        score += 6;
                    } else if (jsonObject1.getString("checkItems").equals("完全符合")) {
                        score += 7;
                    }
                } else {
                    if (jsonObject1.getString("checkItems").equals("完全不符合")) {
                        score3 += 1;
                    } else if (jsonObject1.getString("checkItems").equals("比较不符合")) {
                        score3 += 2;
                    } else if (jsonObject1.getString("checkItems").equals("有点不符合")) {
                        score3 += 3;
                    } else if (jsonObject1.getString("checkItems").equals("不确定")) {
                        score3 += 4;
                    } else if (jsonObject1.getString("checkItems").equals("有点符合")) {
                        score3 += 5;
                    } else if (jsonObject1.getString("checkItems").equals("比较符合")) {
                        score3 += 6;
                    } else if (jsonObject1.getString("checkItems").equals("完全符合")) {
                        score3 += 7;
                    }
                }
            } else if (jsonObject1.getString("scoreDirection").equals("0")) {
                if (i == 5 || i == 10 || i == 15 || i == 39 || i == 42 || i == 49) {
                    if (jsonObject1.getString("checkItems").equals("完全不符合")) {
                        score1 += 7;
                    } else if (jsonObject1.getString("checkItems").equals("比较不符合")) {
                        score1 += 6;
                    } else if (jsonObject1.getString("checkItems").equals("有点不符合")) {
                        score1 += 5;
                    } else if (jsonObject1.getString("checkItems").equals("不确定")) {
                        score1 += 4;
                    } else if (jsonObject1.getString("checkItems").equals("有点符合")) {
                        score1 += 3;
                    } else if (jsonObject1.getString("checkItems").equals("比较符合")) {
                        score1 += 2;
                    } else if (jsonObject1.getString("checkItems").equals("完全符合")) {
                        score1 += 1;
                    }
                } else if (i == 6 || i == 13 || i == 19 || i == 24 || i == 33 || i == 40) {
                    if (jsonObject1.getString("checkItems").equals("完全不符合")) {
                        score2 += 7;
                    } else if (jsonObject1.getString("checkItems").equals("比较不符合")) {
                        score2 += 6;
                    } else if (jsonObject1.getString("checkItems").equals("有点不符合")) {
                        score2 += 5;
                    } else if (jsonObject1.getString("checkItems").equals("不确定")) {
                        score2 += 4;
                    } else if (jsonObject1.getString("checkItems").equals("有点符合")) {
                        score2 += 3;
                    } else if (jsonObject1.getString("checkItems").equals("比较符合")) {
                        score2 += 2;
                    } else if (jsonObject1.getString("checkItems").equals("完全符合")) {
                        score2 += 1;
                    }
                } else if (i == 2 || i == 8 || i == 22 || i == 38) {
                    if (jsonObject1.getString("checkItems").equals("完全不符合")) {
                        score4 += 7;
                    } else if (jsonObject1.getString("checkItems").equals("比较不符合")) {
                        score4 += 6;
                    } else if (jsonObject1.getString("checkItems").equals("有点不符合")) {
                        score4 += 5;
                    } else if (jsonObject1.getString("checkItems").equals("不确定")) {
                        score4 += 4;
                    } else if (jsonObject1.getString("checkItems").equals("有点符合")) {
                        score4 += 3;
                    } else if (jsonObject1.getString("checkItems").equals("比较符合")) {
                        score4 += 2;
                    } else if (jsonObject1.getString("checkItems").equals("完全符合")) {
                        score4 += 1;
                    }
                } else if (i == 21 || i == 47 || i == 50 || i == 51) {
                    if (jsonObject1.getString("checkItems").equals("完全不符合")) {
                        score5 += 7;
                    } else if (jsonObject1.getString("checkItems").equals("比较不符合")) {
                        score5 += 6;
                    } else if (jsonObject1.getString("checkItems").equals("有点不符合")) {
                        score5 += 5;
                    } else if (jsonObject1.getString("checkItems").equals("不确定")) {
                        score5 += 4;
                    } else if (jsonObject1.getString("checkItems").equals("有点符合")) {
                        score5 += 3;
                    } else if (jsonObject1.getString("checkItems").equals("比较符合")) {
                        score5 += 2;
                    } else if (jsonObject1.getString("checkItems").equals("完全符合")) {
                        score5 += 1;
                    }
                } else if (i == 41 || i == 45 || i == 48) {
                    if (jsonObject1.getString("checkItems").equals("完全不符合")) {
                        score6 += 7;
                    } else if (jsonObject1.getString("checkItems").equals("比较不符合")) {
                        score6 += 6;
                    } else if (jsonObject1.getString("checkItems").equals("有点不符合")) {
                        score6 += 5;
                    } else if (jsonObject1.getString("checkItems").equals("不确定")) {
                        score6 += 4;
                    } else if (jsonObject1.getString("checkItems").equals("有点符合")) {
                        score6 += 3;
                    } else if (jsonObject1.getString("checkItems").equals("比较符合")) {
                        score6 += 2;
                    } else if (jsonObject1.getString("checkItems").equals("完全符合")) {
                        score6 += 1;
                    }
                } else if (i == 1 || i == 18 || i == 26 || i == 29 || i == 34 || i == 43) {
                    if (jsonObject1.getString("checkItems").equals("完全不符合")) {
                        score7 += 7;
                    } else if (jsonObject1.getString("checkItems").equals("比较不符合")) {
                        score7 += 6;
                    } else if (jsonObject1.getString("checkItems").equals("有点不符合")) {
                        score7 += 5;
                    } else if (jsonObject1.getString("checkItems").equals("不确定")) {
                        score7 += 4;
                    } else if (jsonObject1.getString("checkItems").equals("有点符合")) {
                        score7 += 3;
                    } else if (jsonObject1.getString("checkItems").equals("比较符合")) {
                        score7 += 2;
                    } else if (jsonObject1.getString("checkItems").equals("完全符合")) {
                        score7 += 1;
                    }
                } else if (i == 20 || i == 28 || i == 30 || i == 31 || i == 36 || i == 37) {
                    if (jsonObject1.getString("checkItems").equals("完全不符合")) {
                        score8 += 7;
                    } else if (jsonObject1.getString("checkItems").equals("比较不符合")) {
                        score8 += 6;
                    } else if (jsonObject1.getString("checkItems").equals("有点不符合")) {
                        score8 += 5;
                    } else if (jsonObject1.getString("checkItems").equals("不确定")) {
                        score8 += 4;
                    } else if (jsonObject1.getString("checkItems").equals("有点符合")) {
                        score8 += 3;
                    } else if (jsonObject1.getString("checkItems").equals("比较符合")) {
                        score8 += 2;
                    } else if (jsonObject1.getString("checkItems").equals("完全符合")) {
                        score8 += 1;
                    }
                } else if (i == 3 || i == 4 || i == 9 || i == 25) {
                    if (jsonObject1.getString("checkItems").equals("完全不符合")) {
                        score9 += 7;
                    } else if (jsonObject1.getString("checkItems").equals("比较不符合")) {
                        score9 += 6;
                    } else if (jsonObject1.getString("checkItems").equals("有点不符合")) {
                        score9 += 5;
                    } else if (jsonObject1.getString("checkItems").equals("不确定")) {
                        score9 += 4;
                    } else if (jsonObject1.getString("checkItems").equals("有点符合")) {
                        score9 += 3;
                    } else if (jsonObject1.getString("checkItems").equals("比较符合")) {
                        score9 += 2;
                    } else if (jsonObject1.getString("checkItems").equals("完全符合")) {
                        score9 += 1;
                    }
                } else if (i == 7 || i == 44 || i == 11 || i == 46 || i == 12 || i == 16) {
                    if (jsonObject1.getString("checkItems").equals("完全不符合")) {
                        score += 7;
                    } else if (jsonObject1.getString("checkItems").equals("比较不符合")) {
                        score += 6;
                    } else if (jsonObject1.getString("checkItems").equals("有点不符合")) {
                        score += 5;
                    } else if (jsonObject1.getString("checkItems").equals("不确定")) {
                        score += 4;
                    } else if (jsonObject1.getString("checkItems").equals("有点符合")) {
                        score += 3;
                    } else if (jsonObject1.getString("checkItems").equals("比较符合")) {
                        score += 2;
                    } else if (jsonObject1.getString("checkItems").equals("完全符合")) {
                        score += 1;
                    }
                } else {
                    if (jsonObject1.getString("checkItems").equals("完全不符合")) {
                        score3 += 7;
                    } else if (jsonObject1.getString("checkItems").equals("比较不符合")) {
                        score3 += 6;
                    } else if (jsonObject1.getString("checkItems").equals("有点不符合")) {
                        score3 += 5;
                    } else if (jsonObject1.getString("checkItems").equals("不确定")) {
                        score3 += 4;
                    } else if (jsonObject1.getString("checkItems").equals("有点符合")) {
                        score3 += 3;
                    } else if (jsonObject1.getString("checkItems").equals("比较符合")) {
                        score3 += 2;
                    } else if (jsonObject1.getString("checkItems").equals("完全符合")) {
                        score3 += 1;
                    }
                }
            }
        }

        //总分
        score = score1 + score2 + score3 + score4 + score5 + score6 + score7 + score8 + score9;
        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<>();

        //获取评分规则列表
        List<ScaleMarksEntity> scaleMarksEntities = (List<ScaleMarksEntity>) resultJson.get("scaleMarksEntities");
        //获取维度信息列表
        List<DimensionEntity> dimensionEntities = (List<DimensionEntity>) resultJson.get("dimensionEntities");
        //计算每个维度得分dimensionEntities
        double[] dimensionScore = {score1,score2,score3,score4,score5,score6,score7,score8,score9};
        Map<String,Double> dimensionScoreMap = new HashMap<>();
        //判断维度分是否为求平均值
        boolean totalMark = true;
        if(dimensionEntities != null && 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;
                            }
                        }
                    }
                    //判断维度分是否需要处理
                    if (scaleMarksEntity.getName().equals(dimensionEntities.get(y).getName())){
                        if (scaleMarksEntity.getScoringType().equals(Constant.DEFAULT_VALUE_ONE)){
                            dimensionScore[y] = Math.round(Double.parseDouble(df.format(dimensionScore[y] / questionNo.length)));
                            //dimensionScore[y] = Math.round(dimensionScore[y] / questionNo.length);
                            dimensionScoreMap.put(dimensionEntities.get(y).getId(),dimensionScore[y]);
                            break;
                        }

                    }
                }
            }
            /*for (int y = 0; y < dimensionEntities.size(); y++) {
                String[] questionNo = dimensionEntities.get(y).getQuestionNo().split("；");
                if (dimensionEntities.get(y).getScoringType().equals(Constant.DEFAULT_VALUE_ONE)){
                    //dimensionScore[y] = Math.round(Double.parseDouble(df.format(dimensionScore[y] / questionNo.length)));
                    dimensionScore[y] = Math.round(dimensionScore[y] / questionNo.length);
                    dimensionScoreMap.put(dimensionEntities.get(y).getId(),dimensionScore[y]);
                }
            }*/
        }
        resultJson.put("dimensionScoreMap",dimensionScoreMap);
        //将量表总维度根据维度名称进行分组
        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());
                    }
                }
            }
        } 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());
                }
            }
        }


        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("scaleName", Constant.SHEET_NAME_ASAS);
        returnJson.put(ScaleConstant.ResultEnum.RESULT_NEW_FIELD.getKeyword(), newResult);

        return returnJson;



        /*

        //新版本数据格式
        Map<String, Object> newResult = new LinkedHashMap<>();
        //返回值以及存数据库格式
        List<NewResultDto> newResultDtos = new ArrayList<>();

        List<Map<String, String>> resultMapList = new ArrayList<>();
        score = score1 + score2 + score3 + score4 + score5 + score6 + score7 + score8 + score9;
        DecimalFormat df = new DecimalFormat("######0.00");
        GPA = Double.parseDouble(df.format(score / 52));
        //得分列表
        Map<String, String> resultMap = new LinkedHashMap<>();
        resultMap.put("疏离感总分", String.valueOf(score));
        resultJson.put("疏离感总分", String.valueOf(score));
        resultMap.put("疏离感平均分", String.valueOf(GPA));
        resultJson.put("疏离感平均分", String.valueOf(GPA));
        newResultDtos.add(new NewResultDto("总分", String.valueOf(score), "无", "无", "无",
                "无", "无", "无", "是"));
        newResultDtos.add(new NewResultDto("平均分", String.valueOf(GPA), "无", "无", "无",
                "无", "无", "无", "否"));
        if (GPA >= 4) {
            resultMap.put("结论", "有一定程度的疏离感");
            resultJson.put("结论", "有一定程度的疏离感");
        } else {
            resultMap.put("结论", "疏离感不明显");
            resultJson.put("结论", "疏离感不明显");
        }

        //将量表总维度根据维度名称进行分组
        Map<String, List<ScaleMarksEntity>> scaleMarksMap = scaleMarksEntities.stream().collect(Collectors.groupingBy(ScaleMarksEntity::getName));
        JSONObject iconInfo = new JSONObject();
        //雷达图需要的维度以及最大值
        List<Map<String, Object>> indicator = new LinkedList<>();
        //雷达图所需要的常模参考值
        LinkedList<String> reference = new LinkedList<>();
        //雷达图需要的分数
        LinkedList<String> scoreList = new LinkedList<>();
        NEWCOMMONScale.commonComputeDimensionScore(null, resultMap, resultJson, "无意义感维度", score1, true, scaleMarksMap, newResultDtos, indicator, reference, scoreList);
        NEWCOMMONScale.commonComputeDimensionScore(null, resultMap, resultJson, "自我疏离感维度", score2, true, scaleMarksMap, newResultDtos, indicator, reference, scoreList);
        NEWCOMMONScale.commonComputeDimensionScore(null, resultMap, resultJson, "孤独感维度", score3, true, scaleMarksMap, newResultDtos, indicator, reference, scoreList);
        NEWCOMMONScale.commonComputeDimensionScore(null, resultMap, resultJson, "自然疏离感维度", score4, true, scaleMarksMap, newResultDtos, indicator, reference, scoreList);
        NEWCOMMONScale.commonComputeDimensionScore(null, resultMap, resultJson, "亲人疏离感维度", score5, true, scaleMarksMap, newResultDtos, indicator, reference, scoreList);
        NEWCOMMONScale.commonComputeDimensionScore(null, resultMap, resultJson, "生活环境疏离感维度", score6, true, scaleMarksMap, newResultDtos, indicator, reference, scoreList);
        NEWCOMMONScale.commonComputeDimensionScore(null, resultMap, resultJson, "社会孤立感维度", score7, true, scaleMarksMap, newResultDtos, indicator, reference, scoreList);
        NEWCOMMONScale.commonComputeDimensionScore(null, resultMap, resultJson, "压迫拘束感维度", score8, true, scaleMarksMap, newResultDtos, indicator, reference, scoreList);
        NEWCOMMONScale.commonComputeDimensionScore(null, resultMap, resultJson, "不可控制感维度", score9, true, 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(resultMap);

        JSONObject returnJson = new JSONObject(true);
        returnJson.put("resultMapList", resultMapList);
        returnJson.put("scaleName", Constant.SHEET_NAME_ASAS);
        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.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[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);
    }

    private WarnEntity createWarnEntry(String flag, String institutionNo, String userId, String id, double score) {
        WarnEntity warn = new WarnEntity();

        warn.setFlag(flag);
        warn.setInstitutionNo(institutionNo);
        warn.setUserId(userId);
        warn.setDimensionId(id);
        warn.setScore(String.valueOf(score));
        return warn;
    }


}
