package com.rf.psychological.scale.resultBusiness.scaleResult;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.rf.psychological.utils.Constant;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/**
 * @author lpf
 * @description:中国中学生心理健康量表
 * @date 2021/3/10 17:17
 */
public class STUHEAScale extends BaseScale {

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

    public JSONObject scaleCalculate() throws Exception {
        //总得分
        int score = 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;
        //心理不平衡
        int score10 = 0;
        for (int i = 0; i < jsonArray.size(); i++) {
            JSONObject jsonObject1 = jsonArray.getJSONObject(i);
            if ((i + 1) == 3 || (i + 1) == 10 || (i + 1) == 12 || (i + 1) == 22 || (i + 1) == 23 || (i + 1) == 48) {
                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 ((i + 1) == 11 || (i + 1) == 20 || (i + 1) == 24 || (i + 1) == 26 || (i + 1) == 47 || (i + 1) == 49) {
                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 ((i + 1) == 19 || (i + 1) == 21 || (i + 1) == 25 || (i + 1) == 50 || (i + 1) == 52 || (i + 1) == 58) {
                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 ((i + 1) == 4 || (i + 1) == 17 || (i + 1) == 18 || (i + 1) == 45 || (i + 1) == 51 || (i + 1) == 59) {
                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 ((i + 1) == 5 || (i + 1) == 13 || (i + 1) == 14 || (i + 1) == 16 || (i + 1) == 44 || (i + 1) == 57) {
                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 ((i + 1) == 6 || (i + 1) == 15 || (i + 1) == 34 || (i + 1) == 43 || (i + 1) == 46 || (i + 1) == 56) {
                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 ((i + 1) == 31 || (i + 1) == 33 || (i + 1) == 36 || (i + 1) == 38 || (i + 1) == 40 || (i + 1) == 55) {
                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 ((i + 1) == 1 || (i + 1) == 8 || (i + 1) == 9 || (i + 1) == 29 || (i + 1) == 39 || (i + 1) == 41) {
                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 ((i + 1) == 2 || (i + 1) == 7 || (i + 1) == 27 || (i + 1) == 32 || (i + 1) == 35 || (i + 1) == 53) {
                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 ((i + 1) == 28 || (i + 1) == 30 || (i + 1) == 37 || (i + 1) == 42 || (i + 1) == 54 || (i + 1) == 60) {
                if (jsonObject1.getString("checkItems").equals("无")) {
                    score10 += 1;
                } else if (jsonObject1.getString("checkItems").equals("轻度")) {
                    score10 += 2;
                } else if (jsonObject1.getString("checkItems").equals("中度")) {
                    score10 += 3;
                } else if (jsonObject1.getString("checkItems").equals("偏重")) {
                    score10 += 4;
                } else if (jsonObject1.getString("checkItems").equals("重度")) {
                    score10 += 5;
                }
            }
        }

        //心理健康总均分
        score = (score1 + score2 + score3 + score4 + score5 + score6 + score7 + score8 + score9 + score10) / 60;
        score1 = score1 / 6;
        score2 = score2 / 6;
        score3 = score3 / 6;
        score4 = score4 / 6;
        score5 = score5 / 6;
        score6 = score6 / 6;
        score7 = score7 / 6;
        score8 = score8 / 6;
        score9 = score9 / 6;
        score10 = score10 / 6;


        Map<String, String> resultMap = new LinkedHashMap<>();
        checkScores(score1, resultMap, resultJson, "强迫症状");
        checkScores(score2, resultMap, resultJson, "偏执");
        checkScores(score3, resultMap, resultJson, "敌对");
        checkScores(score4, resultMap, resultJson, "人际关系敏感");
        checkScores(score5, resultMap, resultJson, "抑郁");
        checkScores(score6, resultMap, resultJson, "焦虑");
        checkScores(score7, resultMap, resultJson, "学习压力感");
        checkScores(score8, resultMap, resultJson, "适应不良");
        checkScores(score9, resultMap, resultJson, "情绪不稳定");
        checkScores(score10, resultMap, resultJson, "心理不平衡");
        checkScores(score, resultMap, resultJson, "心理健康状态");
        resultMap.put("总分", String.valueOf(score));
        resultJson.put("总分", String.valueOf(score));


        List<Map<String, String>> resultMapList = new ArrayList<>();
        resultMapList.add(resultMap);
        JSONObject returnJson = new JSONObject(true);
        returnJson.put("resultMapList", resultMapList);
        returnJson.put("scaleName", Constant.SHEET_NAME_STUHEA);
        returnJson.put("resultJson", resultJson);

        return returnJson;
    }

    private static void checkScores(int score, Map<String, String> resultMap, JSONObject resultJson, String flag) {
        if (score >= 2 && score <= 2.99) {
            resultMap.put(flag, "轻度问题");
            resultJson.put(flag, "轻度问题");
        } else if (score >= 3 && score <= 3.99) {
            resultMap.put(flag, "中等问题");
            resultJson.put(flag, "中等问题");
        } else if (score >= 4 && score <= 4.99) {
            resultMap.put(flag, "较重问题");
            resultJson.put(flag, "较重问题");
        } else if (score == 5) {
            resultMap.put(flag, "严重问题");
            resultJson.put(flag, "严重问题");
        }
    }


}
