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

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

    public  JSONObject scaleCalculate() throws Exception {

        // 自定义路径使用
        /*ScaleUtil.getScaleDll("PRCAScale.dll");
        System.out.println("JSONArray:"+jsonArray);
        System.out.println("resultJson:"+resultJson);
        XScale xScale = new XScale(jsonArray,resultJson);
        String result = xScale.PRCAScale(jsonArray.toString(), resultJson.toString());
        //System.out.println("dllresult:"+result);
        //解决排序问题
        LinkedHashMap<String, Object> jsonMap = JSON.parseObject(result,LinkedHashMap.class, Feature.OrderedField);
        JSONObject jsonObject = new JSONObject(true);
        jsonObject.putAll(jsonMap);
        System.out.println("jsonObject:"+jsonObject);
        return jsonObject;*/

        //总分
        double score = 0;
        //小组得分
        double score1 = 18;
        //会议得分
        double score2 = 18;
        //二人得分
        double score3 = 18;
        //公众得分
        double score4 = 18;
        for (int i = 0; i < jsonArray.size(); i++) {
            JSONObject jsonObject1 = jsonArray.getJSONObject(i);
            if (i <= 5){
                if (i == 0 || i == 2 || i == 4){
                    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;
                    }
                }else {
                    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 (i <= 11 && i > 5){
                if (i == 6 || i == 9 || i == 10){
                    if (jsonObject1.getString("checkItems").equals("非常同意")) {
                        score2 -= 5;
                    }else if (jsonObject1.getString("checkItems").equals("同意")) {
                        score2 -= 4;
                    }else if (jsonObject1.getString("checkItems").equals("不确定")) {
                        score2 -= 3;
                    }else if (jsonObject1.getString("checkItems").equals("不同意")) {
                        score2 -= 2;
                    }else if (jsonObject1.getString("checkItems").equals("非常不同意")) {
                        score2 -= 1;
                    }
                }else {
                    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 (jsonObject1.getString("checkItems").equals("非常不同意")) {
                        score2 += 5;
                    }
                }
            }else if (i <= 17 && i > 11){
                if (i == 12 || i == 14 || i == 17){
                    if (jsonObject1.getString("checkItems").equals("非常同意")) {
                        score3 -= 5;
                    }else if (jsonObject1.getString("checkItems").equals("同意")) {
                        score3 -= 4;
                    }else if (jsonObject1.getString("checkItems").equals("不确定")) {
                        score3 -= 3;
                    }else if (jsonObject1.getString("checkItems").equals("不同意")) {
                        score3 -= 2;
                    }else if (jsonObject1.getString("checkItems").equals("非常不同意")) {
                        score3 -= 1;
                    }
                }else {
                    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 (jsonObject1.getString("checkItems").equals("非常不同意")) {
                        score3 += 5;
                    }
                }
            }else {
                if (i == 19 || i == 21 || i == 23){
                    if (jsonObject1.getString("checkItems").equals("非常同意")) {
                        score4 -= 5;
                    }else if (jsonObject1.getString("checkItems").equals("同意")) {
                        score4 -= 4;
                    }else if (jsonObject1.getString("checkItems").equals("不确定")) {
                        score4 -= 3;
                    }else if (jsonObject1.getString("checkItems").equals("不同意")) {
                        score4 -= 2;
                    }else if (jsonObject1.getString("checkItems").equals("非常不同意")) {
                        score4 -= 1;
                    }
                }else {
                    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 (jsonObject1.getString("checkItems").equals("非常不同意")) {
                        score4 += 5;
                    }
                }
            }
        }
        score = score1 + score2 + score3 + score4;
        Map<String, String> resultMap0 = new LinkedHashMap<>();
        resultMap0.put("总分", String.valueOf(score));
        resultJson.put("总分", String.valueOf(score));
        if(score < 52){
            resultMap0.put("结论", "低度恐惧");
            resultJson.put("结论", "低度恐惧");
        }else if (score > 79){
            resultMap0.put("结论", "高度恐惧");
            resultJson.put("结论", "高度恐惧");
        }else {
            resultMap0.put("结论", "中度恐惧");
            resultJson.put("结论", "中度恐惧");
        }
        resultMap0.put("小组分", String.valueOf(score1));
        resultJson.put("小组分", String.valueOf(score1));
        resultMap0.put("会议分", String.valueOf(score2));
        resultJson.put("会议分", String.valueOf(score2));
        resultMap0.put("二人分", String.valueOf(score3));
        resultJson.put("二人分", String.valueOf(score3));
        resultMap0.put("公众分", String.valueOf(score4));
        resultJson.put("公众分", String.valueOf(score4));

        List<Map<String,String>> resultMapList = new ArrayList<>();
        resultMapList.add(resultMap0);

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

        return returnJson;
    }
}
