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 lhl
 * @description:训练比赛满意感量表
 * @date 2021/10/28 15:55
 */
public class TCSScale extends BaseScale {
    public TCSScale(JSONArray jsonArray, JSONObject resultJson) { super(jsonArray, resultJson); }
    public JSONObject scaleCalculate() throws Exception {
        //总分
        double score1 = 0;
        List<Map<String, String>> resultMapList = new ArrayList<>();
         for (int i = 0; i < jsonArray.size(); i++) {
            JSONObject jsonObject1 = jsonArray.getJSONObject(i);
            if (i != 4 ){
                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 (jsonObject1.getString("checkItems").equals("同意")) {
                    score1 += 6;
                } else if (jsonObject1.getString("checkItems").equals("完全同意")) {
                    score1 += 7;
                }
            }else {
                if (jsonObject1.getString("checkItems").equals("完全不同意")) {
                    score1 += 7;
                } else if (jsonObject1.getString("checkItems").equals("不同意")) {
                    score1 += 6;
                } else if (jsonObject1.getString("checkItems").equals("有点不同意")) {
                    score1 += 5;
                } else if (jsonObject1.getString("checkItems").equals("不确定")) {
                    score1 += 4;
                }else if (jsonObject1.getString("checkItems").equals("有点同意")) {
                    score1 += 3;
                } else if (jsonObject1.getString("checkItems").equals("同意")) {
                    score1 += 2;
                } else if (jsonObject1.getString("checkItems").equals("完全同意")) {
                    score1 += 1;
                }
            }

        }
        //得分列表
        Map<String, String> resultMap = new LinkedHashMap<>();
        resultMap.put("总分", String.valueOf(score1));
        resultJson.put("总分", String.valueOf(score1));

        resultMapList.add(resultMap);

        JSONObject returnJson = new JSONObject(true);
        returnJson.put("resultMapList",resultMapList);
        returnJson.put("scaleName", Constant.SHEET_NAME_TTT);
        returnJson.put("resultJson",resultJson);

        return returnJson;
    }

}
