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.*;

/**
 * @author lpf
 * @description:运动认知特质焦虑量表
 * @date 2021/3/10 17:17
 */
public class YDRZScale extends BaseScale {

    public YDRZScale(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;

        for (int i = 0; i < jsonArray.size(); i++) {
            System.out.println(i);
            JSONObject jsonObject1 = jsonArray.getJSONObject(i);
            if (jsonObject1.getString("scoreDirection").equals("1")) {
                if ((i + 1) == 16 || (i + 1) == 17 || (i + 1) == 21 || (i + 1) == 22 || (i + 1) == 27 || (i + 1) == 28) {
                    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 ((i + 1) == 23 || (i + 1) == 24 || (i + 1) == 25 || (i + 1) == 26 || (i + 1) == 29 || (i + 1) == 32) {
                    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 ((i + 1) == 4 || (i + 1) == 5 || (i + 1) == 9 || (i + 1) == 11 || (i + 1) == 14) {
                    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 ((i + 1) == 8 || (i + 1) == 12 || (i + 1) == 18 || (i + 1) == 19 || (i + 1) == 33) {
                    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 (jsonObject1.getString("checkItems").equals("很不适合")) {
                        score4 += 4;
                    }
                } else if ((i + 1) == 1 || (i + 1) == 2 || (i + 1) == 6 || (i + 1) == 31) {
                    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 (jsonObject1.getString("checkItems").equals("很不适合")) {
                        score5 += 4;
                    }
                } else if ((i + 1) == 3 || (i + 1) == 7 || (i + 1) == 13 || (i + 1) == 15) {
                    if ((i + 1) == 15) {
                        if (jsonObject1.getString("checkItems").equals("很适合")) {
                            score6 += 4;
                        } else if (jsonObject1.getString("checkItems").equals("大致适合")) {
                            score6 += 3;
                        } else if (jsonObject1.getString("checkItems").equals("不太适合")) {
                            score6 += 2;
                        } else if (jsonObject1.getString("checkItems").equals("很不适合")) {
                            score6 += 1;
                        }
                    } else {
                        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 (jsonObject1.getString("checkItems").equals("很不适合")) {
                            score6 += 4;
                        }
                    }
                } else if ((i + 1) == 10 || (i + 1) == 20 || (i + 1) == 30) {
                    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 (jsonObject1.getString("checkItems").equals("很不适合")) {
                        score7 += 4;
                    }
                }
            }
        }

        //得分列表
        Map<String, String> resultMap = new LinkedHashMap<>();
        String s = String.valueOf(score1 + score2 + score3 + score4 + score5 + score6 + score7);
        resultMap.put("总分", s);
        resultJson.put("总分", s);
        Map<String,Double> dimensionScoreMap = new HashMap<>();

        if (score7 > 7) {
            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));
            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));

            dimensionScoreMap.put("ff8080817e7a8529017f625910944386", (double) score1);
            dimensionScoreMap.put("ff8080817e7a8529017f6259109a4387", (double) score2);
            dimensionScoreMap.put("ff8080817e7a8529017f625910a04388", (double) score3);
            dimensionScoreMap.put("ff8080817e7a8529017f625910a64389", (double) score4);
            dimensionScoreMap.put("ff8080817e7a8529017f625910ac438a", (double) score5);
            dimensionScoreMap.put("ff8080817e7a8529017f625910b2438b", (double) score6);
            // 0表示没有说谎
            dimensionScoreMap.put("ff8080817e7a8529017f625910b8438c",(double) score7);
        } else {
            resultMap.put("注意", "不够真实的回答");
            resultJson.put("注意", "不够真实的回答");
            //1表示说谎
            //dimensionScoreMap.put("ff8080817e7a8529017f625910b8438c",1d);
        }
        if(dimensionScoreMap.size()>0){
            resultJson.put("dimensionScoreMap",dimensionScoreMap);
        }

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

        return returnJson;
    }
}
