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

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

    public  JSONObject scaleCalculate() throws Exception {
        //得分
        int score = 0;
        for (int i = 0; i < jsonArray.size(); i++) {
            JSONObject jsonObject1 = jsonArray.getJSONObject(i);
            if (jsonObject1.getString("checkItems").equals("偶尔如此")) {
                score += 3;
            } else if (jsonObject1.getString("checkItems").equals("有时如此")) {
                score += 2;
            } else if (jsonObject1.getString("checkItems").equals("经常如此")) {
                score += 1;
            }
        }
        //得分列表
        Map<String, String> resultMap = new LinkedHashMap<>();
        resultMap.put("总分", String.valueOf(score));
        resultJson.put("总分", String.valueOf(score));
        if (score < 6){
            resultMap.put("孤立解释", "无或几无孤立");
            resultJson.put("孤立解释", "无或几无孤立");
            resultMap.put("孤独解释", "无或几无孤独");
            resultJson.put("孤独解释", "无或几无孤独");
        }
        if (score >= 6 && score <= 8){
            resultMap.put("孤立解释", "一般的孤立");
            resultJson.put("孤立解释", "一般的孤立");
        }
        if (score >= 9 && score <= 12){
            resultMap.put("孤立解释", "属于一般人的孤立");
            resultJson.put("孤立解释", "属于一般人的孤立");
        }
        if (score >= 13){
            resultMap.put("孤立解释", "孤立问题严重");
            resultJson.put("孤立解释", "孤立问题严重");
        }
        if (score >= 6 && score <= 10){
            resultMap.put("孤独解释", "一般的情绪孤独");
            resultJson.put("孤独解释", "一般的情绪孤独");
        }
        if (score >= 11 && score <= 14){
            resultMap.put("孤独解释", "高于一般人的孤独");
            resultJson.put("孤独解释", "高于一般人的孤独");
        }
        if (score >= 15){
            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_ESLI);
        returnJson.put("resultJson",resultJson);

        return returnJson;
    }
}
