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

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

    public  JSONObject scaleCalculate() throws Exception {

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

        //总分
        double score = 0;
        //突显性维度得分
        int score1 = 0;
        //耐受性维度得分
        int score2 = 0;
        //强迫性上网/戒断症状维度得分
        int score3 = 0;
        //心境改变维度得分
        int score4 = 0;
        //社交抚慰维度得分
        int score5 = 0;
        //消极后果维度得分
        int score6 = 0;
        for (int i = 0; i < jsonArray.size(); i++) {
            JSONObject jsonObject1 = jsonArray.getJSONObject(i);
            if (i == 0 || i == 2 || i == 21){
                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 == 5 || i == 7 || i == 9 || i == 28 || i == 34){
                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 == 16 || i == 19 || i == 22 || i == 23 || i == 25){
                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;
                }
            }else if (i == 11 || i == 13 || i == 15 || i == 17 || i == 24 || i == 36){
                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 (jsonObject1.getString("checkItems").equals("完全符合")) {
                    score5 += 5;
                }
            }else if (i == 1 || i == 4 || i == 6 || i == 8 || i == 10 || i == 30 || i == 33 || i == 35){
                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 (jsonObject1.getString("checkItems").equals("完全符合")) {
                    score6 += 5;
                }
            }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;
                }
            }
        }
        score = score1 + score2 + score3 + score4 + score5 + score6;
        Map<String, String> resultMap0 = new LinkedHashMap<>();
        resultMap0.put("总分", String.valueOf(score));
        resultJson.put("总分", String.valueOf(score));
        if(score/38 < 3){
            resultMap0.put("结论", "正常群体");
            resultJson.put("结论", "正常群体");
        }else if (score/38 < 3.15 && score/38 >= 3 ){
            resultMap0.put("结论", "PIU边缘群体");
            resultJson.put("结论", "PIU边缘群体");
        }else {
            resultMap0.put("结论", "PIU群体（也可以理解为网络成痛群体）");
            resultJson.put("结论", "PIU群体（也可以理解为网络成痛群体）");
        }
        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));
        resultMap0.put("社交抚慰维度分", String.valueOf(score5));
        resultJson.put("社交抚慰维度分", String.valueOf(score5));
        resultMap0.put("消极后果维度分", String.valueOf(score6));
        resultJson.put("消极后果维度分", String.valueOf(score6));

        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_APIUS);
        returnJson.put("resultJson",resultJson);
        System.out.println("resultJson：" + returnJson);
        return returnJson;
    }
}
