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 zsy
 * @description:精神卫生心理控制源量表
 * @date 2021/7/20 15:55
 */
public class MHLCScale extends BaseScale{

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

    public  JSONObject scaleCalculate() throws Exception {
        //注意力方向-外倾（外向）得分
        int score1 = 0;
        //（精力来源）-内倾（内向）得分
        int score2 = 0;
        for (int i = 0; i < jsonArray.size(); i++) {
            JSONObject jsonObject1 = jsonArray.getJSONObject(i);
            if (jsonObject1.getString("scoreDirection").equals("1")) {
                if (i == 1 || i == 2 || i == 5 || i == 7 || i == 9 || i == 10 || i == 12 || i == 13 || i == 17 || i == 19 || i == 22 || i == 23 || i == 26 || i == 27){
                    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 (i == 4 || i == 8 || i == 14 || i == 16 || i == 18 || i == 20 || i == 21 || i == 25){
                    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("scoreDirection").equals("0")){
                if (i == 1 || i == 2 || i == 5 || i == 7 || i == 9 || i == 10 || i == 12 || i == 13 || i == 17 || i == 19 || i == 22 || i == 23 || i == 26 || i == 27){
                    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 == 4 || i == 8 || i == 14 || i == 16 || i == 18 || i == 20 || i == 21 || i == 25){
                    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;
                    }
                }
            }
        }

        Map<String, String> resultMap1 = new LinkedHashMap<>();
        resultMap1.put("总分", String.valueOf(score1+score2));
        resultJson.put("总分", String.valueOf(score1+score2));
        resultMap1.put("注意力方向-外倾（外向）得分", String.valueOf(score1));
        resultJson.put("注意力方向-外倾（外向）得分", String.valueOf(score1));
        resultMap1.put("（精力来源）-内倾（内向）得分", String.valueOf(score2));
        resultJson.put("（精力来源）-内倾（内向）得分", String.valueOf(score2));

        List<Map<String,String>> resultMapList = new ArrayList<>();
        resultMapList.add(resultMap1);

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

        return returnJson;
    }
}
