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

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

    public  JSONObject scaleCalculate() throws Exception {

        // 自定义路径使用
        /*ScaleUtil.getScaleDll("SCCSScale.dll");
        System.out.println("JSONArray:"+jsonArray);
        System.out.println("resultJson:"+resultJson);
        XScale xScale = new XScale(jsonArray,resultJson);
        String result = xScale.SCCSScale(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;*/

        //总分
        int score = 0;
        //自我与经验的不和谐得分
        int score1 = 0;
        //自我的灵活性得分
        int score2 = 0;
        //自我的刻板性得分
        int score3 = 0;
        //自我的灵活性反向得分
        int score4 = 0;
        for (int i = 0; i < jsonArray.size(); i++) {
            JSONObject jsonObject1 = jsonArray.getJSONObject(i);
            if (i == 5 || i == 8 || i == 12 || i == 19 || i == 24 || i == 25 || i == 33){
                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 == 1 || i == 2 || i == 4 || i == 7 || i == 10 || i == 15 || i == 17 || i == 21 || i == 23 || i == 29 || i == 31 || i == 34){
                if (jsonObject1.getString("checkItems").equals("完全不符合")) {
                    score2 += 1;
                    score4 += 5;
                }else if (jsonObject1.getString("checkItems").equals("基本不符合")) {
                    score2 += 2;
                    score4 += 4;
                }else if (jsonObject1.getString("checkItems").equals("不确定")) {
                    score2 += 3;
                    score4 += 3;
                }else if (jsonObject1.getString("checkItems").equals("基本符合")) {
                    score2 += 4;
                    score4 += 2;
                }else if (jsonObject1.getString("checkItems").equals("完全符合")) {
                    score2 += 5;
                    score4 += 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;
                }
            }
        }
        score = score1 + score3 + score4;
        Map<String, String> resultMap0 = new LinkedHashMap<>();
        resultMap0.put("总分", String.valueOf(score));
        resultJson.put("总分", String.valueOf(score));
        if(score <= 74){
            resultMap0.put("结论", "自我和谐程度低");
            resultJson.put("结论", "自我和谐程度低");
        }else if (score <= 102 && score <= 75 ){
            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));

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

        return returnJson;
    }
}
