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 DACLScale extends BaseScale {
    public DACLScale(JSONArray jsonArray, JSONObject resultJson) {
        super(jsonArray, resultJson);
    }

    public JSONObject scaleCalculate() throws Exception {
        //总分
        int score = 0;
        //分表E总分
        int scoreE = 0;
        //分表F总分
        int scoreF = 0;
        //分表G总分
        int scoreG = 0;

        for (int i = 0; i < jsonArray.size(); i++) {
            JSONObject jsonObject1 = jsonArray.getJSONObject(i);
            if (i <= 33) {
                if (jsonObject1.getString("scoreDirection").equals("1")) {
                    if (jsonObject1.getString("checkItems").equals("符合描写")) {
                        scoreE += 1;
                    } else if (jsonObject1.getString("checkItems").equals("不符合描写")) {
                        scoreE += 0;
                    }
                } else if (jsonObject1.getString("scoreDirection").equals("0")) {
                    if (jsonObject1.getString("checkItems").equals("符合描写")) {
                        scoreE += 0;
                    } else if (jsonObject1.getString("checkItems").equals("不符合描写")) {
                        scoreE += 1;
                    }

                }
            } else if (i <= 67) {
                if (jsonObject1.getString("scoreDirection").equals("1")) {
                    if (jsonObject1.getString("checkItems").equals("符合描写")) {
                        scoreF += 1;
                    } else if (jsonObject1.getString("checkItems").equals("不符合描写")) {
                        scoreF += 0;
                    }
                } else if (jsonObject1.getString("scoreDirection").equals("0")) {
                    if (jsonObject1.getString("checkItems").equals("符合描写")) {
                        scoreF += 0;
                    } else if (jsonObject1.getString("checkItems").equals("不符合描写")) {
                        scoreF += 1;
                    }

                }
            } else if (i <= 101) {
                if (jsonObject1.getString("scoreDirection").equals("1")) {
                    if (jsonObject1.getString("checkItems").equals("符合描写")) {
                        scoreG += 1;
                    } else if (jsonObject1.getString("checkItems").equals("不符合描写")) {
                        scoreG += 0;
                    }
                } else if (jsonObject1.getString("scoreDirection").equals("0")) {
                    if (jsonObject1.getString("checkItems").equals("符合描写")) {
                        scoreG += 0;
                    } else if (jsonObject1.getString("checkItems").equals("不符合描写")) {
                        scoreG += 1;
                    }
                }
            }
        }
        score = scoreE + scoreE + scoreG;

        //得分列表
        Map<String, String> resultMap = new LinkedHashMap<>();
        resultMap.put("总分", String.valueOf(score));
        resultJson.put("总分", String.valueOf(score));
        resultMap.put("E总分", String.valueOf(scoreE));
        resultJson.put("E总分", String.valueOf(scoreE));
        resultMap.put("F总分", String.valueOf(scoreF));
        resultJson.put("F总分", String.valueOf(scoreF));
        resultMap.put("G总分", String.valueOf(scoreG));
        resultJson.put("G总分", String.valueOf(scoreG));

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

        return returnJson;
    }
}
