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 DXSLAScale extends BaseScale {

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

    public JSONObject scaleCalculate() throws Exception {
        //总得分
        float score = 0;

        int score1 = 0;

        int score2 = 0;

        float score3 = 0;


        for (int i = 0; i < jsonArray.size(); i++) {
            JSONObject jsonObject1 = jsonArray.getJSONObject(i);
            if (jsonObject1.getString("scoreDirection").equals("1")) {
                if (i >= 1 && i <= 7) {
                    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 >= 8 && i <= 17) {
                    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 >= 18 && i <= 27) {
                    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;
                    }
                }
            }
        }
        score1 = score1 * 2;
        score3 = (float) (score3 * 0.5);
        score = score1 + score2 + score3;
        //得分列表
        Map<String, String> resultMap = new LinkedHashMap<>();
        resultMap.put("总分", String.valueOf(score));
        resultJson.put("总分", String.valueOf(score));
        if (score <= 45) {
            resultMap.put("结论", "低压区");
            resultJson.put("结论", "低压区");
        } else if (score <= 75) {
            resultMap.put("结论", "常态区");
            resultJson.put("结论", "常态区");
        } else if (score <= 105) {
            resultMap.put("结论", "显压区");
            resultJson.put("结论", "显压区");
        } else if (score <= 145) {
            resultMap.put("结论", "高压区");
            resultJson.put("结论", "高压区");
        }

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

        return returnJson;
    }
}
