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:Russell吸烟原因问卷
 * @date 2021/3/10 17:17
 */
public class RussellScale extends BaseScale {

    public RussellScale(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;
        int score7 = 0;
        int score8 = 0;
        for (int i = 0; i < jsonArray.size(); i++) {
            JSONObject jsonObject1 = jsonArray.getJSONObject(i);
            if (jsonObject1.getString("scoreDirection").equals("1")) {
                if ((i + 1) == 6 || (i + 1) == 19 || (i + 1) == 23) {
                    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) == 5 || (i + 1) == 10 || (i + 1) == 22) {
                    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 ((i + 1) == 3 || (i + 1) == 4 || (i + 1) == 16) {
                    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 ((i + 1) == 7 || (i + 1) == 12 || (i + 1) == 24) {
                    if (jsonObject1.getString("checkItems").equals("有")) {
                        score4 += 1;
                    } else if (jsonObject1.getString("checkItems").equals("有时")) {
                        score4 += 2;
                    } else if (jsonObject1.getString("checkItems").equals("经常")) {
                        score4 += 3;
                    }
                } else if ((i + 1) == 8 || (i + 1) == 13 || (i + 1) == 17) {
                    if (jsonObject1.getString("checkItems").equals("有")) {
                        score5 += 1;
                    } else if (jsonObject1.getString("checkItems").equals("有时")) {
                        score5 += 2;
                    } else if (jsonObject1.getString("checkItems").equals("经常")) {
                        score5 += 3;
                    }
                } else if ((i + 1) == 11 || (i + 1) == 18 || (i + 1) == 20) {
                    if (jsonObject1.getString("checkItems").equals("有")) {
                        score6 += 1;
                    } else if (jsonObject1.getString("checkItems").equals("有时")) {
                        score6 += 2;
                    } else if (jsonObject1.getString("checkItems").equals("经常")) {
                        score6 += 3;
                    }
                } else if ((i + 1) == 2 || (i + 1) == 9 || (i + 1) == 15) {
                    if (jsonObject1.getString("checkItems").equals("有")) {
                        score7 += 1;
                    } else if (jsonObject1.getString("checkItems").equals("有时")) {
                        score7 += 2;
                    } else if (jsonObject1.getString("checkItems").equals("经常")) {
                        score7 += 3;
                    }
                } else if ((i + 1) == 1 || (i + 1) == 14 || (i + 1) == 21) {
                    if (jsonObject1.getString("checkItems").equals("有")) {
                        score8 += 1;
                    } else if (jsonObject1.getString("checkItems").equals("有时")) {
                        score8 += 2;
                    } else if (jsonObject1.getString("checkItems").equals("经常")) {
                        score8 += 3;
                    }
                }
            }
        }
        score = (score6 + score7 + score8);
        //得分列表
        Map<String, String> resultMap = new LinkedHashMap<>();
        resultMap.put("心理意象得分", String.valueOf(score1));
        resultMap.put("口手活动得分", String.valueOf(score2));
        resultMap.put("享乐得分", String.valueOf(score3));
        resultMap.put("镇静得分", String.valueOf(score4));
        resultMap.put("刺激得分", String.valueOf(score5));
        resultMap.put("瘾得分", String.valueOf(score6));
        resultMap.put("自动得分", String.valueOf(score7));
        resultMap.put("依赖得分", String.valueOf(score));
        resultJson.put("心理意象得分", String.valueOf(score1));
        resultJson.put("口手活动得分", String.valueOf(score2));
        resultJson.put("享乐得分", String.valueOf(score3));
        resultJson.put("镇静得分", String.valueOf(score4));
        resultJson.put("刺激得分", String.valueOf(score5));
        resultJson.put("瘾得分", String.valueOf(score6));
        resultJson.put("自动得分", String.valueOf(score7));
        resultJson.put("依赖得分", String.valueOf(score));

        if (score >= 6 && score <= 20) {
            resultMap.put("结论", "可能有依赖");
            resultJson.put("结论", "可能有依赖");
        } else if (score > 20 && score <= 27) {
            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_Russell);
        returnJson.put("resultJson", resultJson);

        return returnJson;
    }
}
