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;

/**
 * @description: 内控性、有势力的他人及机遇量表
 */
public class IPCScale extends BaseScale {

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

    public JSONObject scaleCalculate() throws Exception {
        //内控性
        int score1 = 0;
        //有势力的他人
        int score2 = 0;
        //机遇
        int score3 = 0;

        for (int i = 0; i < jsonArray.size(); i++) {
            JSONObject jsonObject1 = jsonArray.getJSONObject(i);
            if ((i + 1) == 1 || (i + 1) == 4 || (i + 1) == 5 || (i + 1) == 9 || (i + 1) == 18 || (i + 1) == 19 || (i + 1) == 21 || (i + 1) == 23) {
                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 (jsonObject1.getString("checkItems").equals("基本同意")) {
                    score1 += 1;
                } else if (jsonObject1.getString("checkItems").equals("同意")) {
                    score1 += 2;
                } else if (jsonObject1.getString("checkItems").equals("很同意")) {
                    score1 += 3;
                }
            } else if ((i + 1) == 3 || (i + 1) == 8 || (i + 1) == 11 || (i + 1) == 13 || (i + 1) == 15 || (i + 1) == 17 || (i + 1) == 20 || (i + 1) == 22) {
                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 (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("很不同意")) {
                    score3 += -3;
                } else if (jsonObject1.getString("checkItems").equals("不同意")) {
                    score3 += -2;
                } else if (jsonObject1.getString("checkItems").equals("不太同意")) {
                    score3 += -1;
                } else if (jsonObject1.getString("checkItems").equals("基本同意")) {
                    score3 += 1;
                } else if (jsonObject1.getString("checkItems").equals("同意")) {
                    score3 += 2;
                } else if (jsonObject1.getString("checkItems").equals("很同意")) {
                    score3 += 3;
                }
            }
        }

        score1 = score1 + 24;
        score2 = score2 + 24;
        score3 = score3 + 24;

        //得分列表
        Map<String, String> resultMap = new LinkedHashMap<>();
        resultMap.put("内控性", String.valueOf(score1));
        resultMap.put("有势力的他人", String.valueOf(score2));
        resultMap.put("机遇", String.valueOf(score3));
        resultJson.put("内控性", String.valueOf(score1));
        resultJson.put("有势力的他人", String.valueOf(score2));
        resultJson.put("机遇", String.valueOf(score3));


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

        return returnJson;
    }
}
