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

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

    public  JSONObject scaleCalculate() throws Exception {
        //得分
        int score = 0;
        //生理舒适分量表
        int physioScore = 0;
        //心理舒适分量表
        int psychologyScore = 0;
        //社会文化舒适分量表
        int cultureScore = 0;
        //环境舒适分量表
        int environmentScore = 0;
        for (int i = 0; i < jsonArray.size(); i++) {
            JSONObject jsonObject1 = jsonArray.getJSONObject(i);
            if (jsonObject1.getString("scoreDirection").equals("1")) {
                if (i == 1 || i == 8 || i == 12 || i == 15 || i == 16){
                    if (jsonObject1.getString("checkItems").equals("非常不同意")) {
                        score += 1;
                        physioScore += 1;
                    } else if (jsonObject1.getString("checkItems").equals("不同意")) {
                        score += 2;
                        physioScore += 2;
                    } else if (jsonObject1.getString("checkItems").equals("同意")) {
                        score += 3;
                        physioScore += 3;
                    } else if (jsonObject1.getString("checkItems").equals("非常同意")) {
                        score += 4;
                        physioScore += 4;
                    }
                }else if (i == 2 || i == 3 || i == 4 || i == 11 || i == 14 || i == 17 || i == 21 || i == 23 || i == 25 || i == 27){
                    if (jsonObject1.getString("checkItems").equals("非常不同意")) {
                        score += 1;
                        psychologyScore += 1;
                    } else if (jsonObject1.getString("checkItems").equals("不同意")) {
                        score += 2;
                        psychologyScore += 2;
                    } else if (jsonObject1.getString("checkItems").equals("同意")) {
                        score += 3;
                        psychologyScore += 3;
                    } else if (jsonObject1.getString("checkItems").equals("非常同意")) {
                        score += 4;
                        psychologyScore += 4;
                    }
                }else if (i == 0 || i == 5 || i == 6 || i == 9 || i == 22 || i == 24 || i == 28 || i == 29){
                    if (jsonObject1.getString("checkItems").equals("非常不同意")) {
                        score += 1;
                        cultureScore += 1;
                    } else if (jsonObject1.getString("checkItems").equals("不同意")) {
                        score += 2;
                        cultureScore += 2;
                    } else if (jsonObject1.getString("checkItems").equals("同意")) {
                        score += 3;
                        cultureScore += 3;
                    } else if (jsonObject1.getString("checkItems").equals("非常同意")) {
                        score += 4;
                        cultureScore += 4;
                    }
                }else if (i == 6 || i == 10 || i == 13 || i == 18 || i == 19 || i == 20 || i == 26){
                    if (jsonObject1.getString("checkItems").equals("非常不同意")) {
                        score += 1;
                        environmentScore += 1;
                    } else if (jsonObject1.getString("checkItems").equals("不同意")) {
                        score += 2;
                        environmentScore += 2;
                    } else if (jsonObject1.getString("checkItems").equals("同意")) {
                        score += 3;
                        environmentScore += 3;
                    } else if (jsonObject1.getString("checkItems").equals("非常同意")) {
                        score += 4;
                        environmentScore += 4;
                    }
                }
            } else if (jsonObject1.getString("scoreDirection").equals("0")){
                if (i == 1 || i == 8 || i == 12 || i == 15 || i == 16){
                    if (jsonObject1.getString("checkItems").equals("非常不同意")) {
                        score += 4;
                        physioScore += 4;
                    } else if (jsonObject1.getString("checkItems").equals("不同意")) {
                        score += 3;
                        physioScore += 3;
                    } else if (jsonObject1.getString("checkItems").equals("同意")) {
                        score += 2;
                        physioScore += 2;
                    } else if (jsonObject1.getString("checkItems").equals("非常同意")) {
                        score += 1;
                        physioScore += 1;
                    }
                }else if (i == 2 || i == 3 || i == 4 || i == 11 || i == 14 || i == 17 || i == 21 || i == 23 || i == 25 || i == 27){
                    if (jsonObject1.getString("checkItems").equals("非常不同意")) {
                        score += 4;
                        psychologyScore += 4;
                    } else if (jsonObject1.getString("checkItems").equals("不同意")) {
                        score += 3;
                        psychologyScore += 3;
                    } else if (jsonObject1.getString("checkItems").equals("同意")) {
                        score += 2;
                        psychologyScore += 2;
                    } else if (jsonObject1.getString("checkItems").equals("非常同意")) {
                        score += 1;
                        psychologyScore += 1;
                    }
                }else if (i == 0 || i == 5 || i == 6 || i == 9 || i == 22 || i == 24 || i == 28 || i == 29){
                    if (jsonObject1.getString("checkItems").equals("非常不同意")) {
                        score += 4;
                        cultureScore += 4;
                    } else if (jsonObject1.getString("checkItems").equals("不同意")) {
                        score += 3;
                        cultureScore += 3;
                    } else if (jsonObject1.getString("checkItems").equals("同意")) {
                        score += 2;
                        cultureScore += 2;
                    } else if (jsonObject1.getString("checkItems").equals("非常同意")) {
                        score += 1;
                        cultureScore += 1;
                    }
                }else if (i == 6 || i == 10 || i == 13 || i == 18 || i == 19 || i == 20 || i == 26){
                    if (jsonObject1.getString("checkItems").equals("非常不同意")) {
                        score += 4;
                        environmentScore += 4;
                    } else if (jsonObject1.getString("checkItems").equals("不同意")) {
                        score += 3;
                        environmentScore += 3;
                    } else if (jsonObject1.getString("checkItems").equals("同意")) {
                        score += 2;
                        environmentScore += 2;
                    } else if (jsonObject1.getString("checkItems").equals("非常同意")) {
                        score += 1;
                        environmentScore += 1;
                    }
                }
            }
        }

        //得分列表
        Map<String, String> resultMap = new LinkedHashMap<>();
        resultMap.put("总分", String.valueOf(score));
        resultJson.put("总分", String.valueOf(score));
        System.out.println("得分：" + score);
        //根据得分判断信任度
        if (score >= 90){
            resultMap.put("舒适度", "高度舒适");
            resultJson.put("舒适度", "高度舒适");
        }else if (score < 90 && score >= 60){
            resultMap.put("舒适度", "中度舒适");
            resultJson.put("舒适度", "中度舒适");
        }else if (score < 60){
            resultMap.put("舒适度", "低度舒适");
            resultJson.put("舒适度", "低度舒适");
        }
        resultMap.put("生理舒适分量表", String.valueOf(physioScore));
        resultJson.put("生理舒适分量表", String.valueOf(physioScore));
        resultMap.put("心理舒适分量表", String.valueOf(psychologyScore));
        resultJson.put("心理舒适分量表", String.valueOf(psychologyScore));
        resultMap.put("社会文化舒适分量表", String.valueOf(cultureScore));
        resultJson.put("社会文化舒适分量表", String.valueOf(cultureScore));
        resultMap.put("环境舒适分量表", String.valueOf(environmentScore));
        resultJson.put("环境舒适分量表", String.valueOf(environmentScore));

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

        return returnJson;
    }
}
