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:中学生自我导向学习倾向性量表 SDLRS
 * @date 2021/3/10 17:17
 */
public class SDLRSScale extends BaseScale {

    public SDLRSScale(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;

        for (int i = 0; i < jsonArray.size(); i++) {
            JSONObject jsonObject1 = jsonArray.getJSONObject(i);
            if ((i + 1) == 2 || (i + 1) == 4 || (i + 1) == 7 || (i + 1) == 8 || (i + 1) == 10 || (i + 1) == 13 || (i + 1) == 14 || (i + 1) == 15 || (i + 1) == 16 || (i + 1) == 17 || (i + 1) == 18 || (i + 1) == 21 || (i + 1) == 24 || (i + 1) == 27) {
                score1 = getScores(score1, jsonObject1);
            } else if ((i + 1) == 3 || (i + 1) == 6 || (i + 1) == 9 || (i + 1) == 12 || (i + 1) == 19 || (i + 1) == 20 || (i + 1) == 22 || (i + 1) == 23 || (i + 1) == 29 || (i + 1) == 32 || (i + 1) == 53) {
                score2 = getScores(score2, jsonObject1);
            } else if ((i + 1) == 11 || (i + 1) == 25 || (i + 1) == 28 || (i + 1) == 33 || (i + 1) == 35 || (i + 1) == 37 || (i + 1) == 38 || (i + 1) == 39 || (i + 1) == 52 || (i + 1) == 54) {
                score3 = getScores(score3, jsonObject1);
            } else if ((i + 1) == 1 || (i + 1) == 5 || (i + 1) == 41 || (i + 1) == 44 || (i + 1) == 50) {
                score4 = getScores(score4, jsonObject1);
            } else if ((i + 1) == 31 || (i + 1) == 40 || (i + 1) == 42 || (i + 1) == 43 || (i + 1) == 45 || (i + 1) == 46 || (i + 1) == 47 || (i + 1) == 48 || (i + 1) == 49 || (i + 1) == 51 || (i + 1) == 55) {
                score5 = getScores(score5, jsonObject1);
            } else if ((i + 1) == 26 || (i + 1) == 30 || (i + 1) == 34 || (i + 1) == 36) {
                score6 = getScores(score6, jsonObject1);
            }
        }


        Map<String, String> resultMap = new LinkedHashMap<>();
        resultMap.put("主动学习因子总分", String.valueOf(score1));
        resultJson.put("主动学习因子总分", String.valueOf(score1));
        resultMap.put("消极学习因子总分", String.valueOf(score2));
        resultJson.put("消极学习因子总分", String.valueOf(score2));
        resultMap.put("有效学习因子总分", String.valueOf(score3));
        resultJson.put("有效学习因子总分", String.valueOf(score3));
        resultMap.put("喜爱学习因子总分", String.valueOf(score4));
        resultJson.put("喜爱学习因子总分", String.valueOf(score4));
        resultMap.put("开放学习因子总分", String.valueOf(score5));
        resultJson.put("开放学习因子总分", String.valueOf(score5));
        resultMap.put("终身学习因子总分", String.valueOf(score6));
        resultJson.put("终身学习因子总分", String.valueOf(score6));

        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_SDLRS);
        returnJson.put("resultJson", resultJson);

        return returnJson;
    }

    private int getScores(int score, JSONObject jsonObject) {
        if (jsonObject.getString("checkItems").equals("完全不是这样")) {
            score += 1;
        } else if (jsonObject.getString("checkItems").equals("我只偶尔有此想法")) {
            score += 2;
        } else if (jsonObject.getString("checkItems").equals("我有一半时间有此想法")) {
            score += 3;
        } else if (jsonObject.getString("checkItems").equals("我有大半时间有此想法")) {
            score += 4;
        } else if (jsonObject.getString("checkItems").equals("完全是这样")) {
            score += 5;
        }
        return score;
    }


}
