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

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

    public  JSONObject scaleCalculate() throws Exception {

        // 自定义路径使用
        /*ScaleUtil.getScaleDll("QSAScale.dll");
        System.out.println("JSONArray:"+jsonArray);
        System.out.println("resultJson:"+resultJson);
        XScale xScale = new XScale(jsonArray,resultJson);
        String result = xScale.QSAScale(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;
        //对自杀行为性质的认识（F1）
        int scoreF1 = 0;
        //对自杀者的态度（F2）
        int scoreF2 = 0;
        //对自杀者家属的态度（F3）
        int scoreF3 = 0;
        //对安乐死的态度（F4）
        int scoreF4 = 0;
        for (int i = 0; i < jsonArray.size(); i++) {
            JSONObject jsonObject1 = jsonArray.getJSONObject(i);
            if (jsonObject1.getString("scoreDirection").equals("1")) {
                if (i == 4 || i == 10 || i == 15 || i == 20 || i == 26){
                    if (jsonObject1.getString("checkItems").equals("完全赞同")) {
                        scoreF4 += 1;
                    } else if (jsonObject1.getString("checkItems").equals("赞同")) {
                        scoreF4 += 2;
                    } else if (jsonObject1.getString("checkItems").equals("中立")) {
                        scoreF4 += 3;
                    } else if (jsonObject1.getString("checkItems").equals("不赞同")) {
                        scoreF4 += 4;
                    } else if (jsonObject1.getString("checkItems").equals("完全不赞同")) {
                        scoreF4 += 5;
                    }
                }else if (i == 3 || i == 5 || i == 9 || i == 14 || i == 27){
                    if (jsonObject1.getString("checkItems").equals("完全赞同")) {
                        scoreF3 += 1;
                    } else if (jsonObject1.getString("checkItems").equals("赞同")) {
                        scoreF3 += 2;
                    } else if (jsonObject1.getString("checkItems").equals("中立")) {
                        scoreF3 += 3;
                    } else if (jsonObject1.getString("checkItems").equals("不赞同")) {
                        scoreF3 += 4;
                    } else if (jsonObject1.getString("checkItems").equals("完全不赞同")) {
                        scoreF3 += 5;
                    }
                }else if (i == 1 || i == 2 || i == 7 || i == 8 || i == 12 || i == 13 || i == 17 || i == 19 || i == 23 || i == 24){
                    if (jsonObject1.getString("checkItems").equals("完全赞同")) {
                        scoreF2 += 1;
                    } else if (jsonObject1.getString("checkItems").equals("赞同")) {
                        scoreF2 += 2;
                    } else if (jsonObject1.getString("checkItems").equals("中立")) {
                        scoreF2 += 3;
                    } else if (jsonObject1.getString("checkItems").equals("不赞同")) {
                        scoreF2 += 4;
                    } else if (jsonObject1.getString("checkItems").equals("完全不赞同")) {
                        scoreF2 += 5;
                    }
                }else if (i == 0 || i == 6 || i == 11 || i == 16 || i == 18 || i == 21 || i == 22 || i == 25 || i == 28){
                    if (jsonObject1.getString("checkItems").equals("完全赞同")) {
                        scoreF1 += 1;
                    } else if (jsonObject1.getString("checkItems").equals("赞同")) {
                        scoreF1 += 2;
                    } else if (jsonObject1.getString("checkItems").equals("中立")) {
                        scoreF1 += 3;
                    } else if (jsonObject1.getString("checkItems").equals("不赞同")) {
                        scoreF1 += 4;
                    } else if (jsonObject1.getString("checkItems").equals("完全不赞同")) {
                        scoreF1 += 5;
                    }
                }
            } else if (jsonObject1.getString("scoreDirection").equals("0")){
                if (i == 4 || i == 10 || i == 15 || i == 20 || i == 26){
                    if (jsonObject1.getString("checkItems").equals("完全赞同")) {
                        scoreF4 += 5;
                    } else if (jsonObject1.getString("checkItems").equals("赞同")) {
                        scoreF4 += 4;
                    } else if (jsonObject1.getString("checkItems").equals("中立")) {
                        scoreF4 += 3;
                    } else if (jsonObject1.getString("checkItems").equals("不赞同")) {
                        scoreF4 += 2;
                    } else if (jsonObject1.getString("checkItems").equals("完全不赞同")) {
                        scoreF4 += 1;
                    }
                }else if (i == 3 || i == 5 || i == 9 || i == 14 || i == 27){
                    if (jsonObject1.getString("checkItems").equals("完全赞同")) {
                        scoreF3 += 5;
                    } else if (jsonObject1.getString("checkItems").equals("赞同")) {
                        scoreF3 += 4;
                    } else if (jsonObject1.getString("checkItems").equals("中立")) {
                        scoreF3 += 3;
                    } else if (jsonObject1.getString("checkItems").equals("不赞同")) {
                        scoreF3 += 2;
                    } else if (jsonObject1.getString("checkItems").equals("完全不赞同")) {
                        scoreF3 += 1;
                    }
                }else if (i == 1 || i == 2 || i == 7 || i == 8 || i == 12 || i == 13 || i == 17 || i == 19 || i == 23 || i == 24){
                    if (jsonObject1.getString("checkItems").equals("完全赞同")) {
                        scoreF2 += 5;
                    } else if (jsonObject1.getString("checkItems").equals("赞同")) {
                        scoreF2 += 4;
                    } else if (jsonObject1.getString("checkItems").equals("中立")) {
                        scoreF2 += 3;
                    } else if (jsonObject1.getString("checkItems").equals("不赞同")) {
                        scoreF2 += 2;
                    } else if (jsonObject1.getString("checkItems").equals("完全不赞同")) {
                        scoreF2 += 1;
                    }
                }else if (i == 0 || i == 6 || i == 11 || i == 16 || i == 18 || i == 21 || i == 22 || i == 25 || i == 28){
                    if (jsonObject1.getString("checkItems").equals("完全赞同")) {
                        scoreF1 += 5;
                    } else if (jsonObject1.getString("checkItems").equals("赞同")) {
                        scoreF1 += 4;
                    } else if (jsonObject1.getString("checkItems").equals("中立")) {
                        scoreF1 += 3;
                    } else if (jsonObject1.getString("checkItems").equals("不赞同")) {
                        scoreF1 += 2;
                    } else if (jsonObject1.getString("checkItems").equals("完全不赞同")) {
                        scoreF1 += 1;
                    }
                }
            }
        }
        //得分列表
        Map<String, String> resultMap = new LinkedHashMap<>();

        resultMap.put("对自杀行为性质的认识（F1）", String.valueOf(scoreF1));
        resultJson.put("对自杀行为性质的认识（F1）", String.valueOf(scoreF1));
        if (scoreF1 >= 3.5){
            resultMap.put("对自杀行为性质的认识态度（F1）", "对自杀持反对、否定、排斥和歧视态度");
            resultJson.put("对自杀行为性质的认识态度（F1）", "对自杀持反对、否定、排斥和歧视态度");
        }else if (scoreF1 < 3.5 && scoreF1 > 2.5){
            resultMap.put("对自杀行为性质的认识态度（F1）", "矛盾或中立态度");
            resultJson.put("对自杀行为性质的认识态度（F1）", "矛盾或中立态度");
        }else if (scoreF1 <= 2.5){
            resultMap.put("对自杀行为性质的认识态度（F1）", "对自杀持肯定、认可、理解和宽容的态度");
            resultJson.put("对自杀行为性质的认识态度（F1）", "对自杀持肯定、认可、理解和宽容的态度");
        }
        resultMap.put("对自杀者的态度（F2）", String.valueOf(scoreF2));
        resultJson.put("对自杀者的态度（F2）", String.valueOf(scoreF2));
        if (score >= 3.5){
            resultMap.put("对自杀者的态度（F2）", "对自杀持反对、否定、排斥和歧视态度");
            resultJson.put("对自杀者的态度（F2）", "对自杀持反对、否定、排斥和歧视态度");
        }else if (score < 3.5 && score > 2.5){
            resultMap.put("对自杀者的态度（F2）", "矛盾或中立态度");
            resultJson.put("对自杀者的态度（F2）", "矛盾或中立态度");
        }else if (score <= 2.5){
            resultMap.put("对自杀者的态度（F2）", "对自杀持肯定、认可、理解和宽容的态度");
            resultJson.put("对自杀者的态度（F2）", "对自杀持肯定、认可、理解和宽容的态度");
        }
        resultMap.put("对自杀者家属的态度（F3）", String.valueOf(scoreF3));
        resultJson.put("对自杀者家属的态度（F3）", String.valueOf(scoreF3));
        if (score >= 3.5){
            resultMap.put("对自杀者家属的态度（F3）", "对自杀持反对、否定、排斥和歧视态度");
            resultJson.put("对自杀者家属的态度（F3）", "对自杀持反对、否定、排斥和歧视态度");
        }else if (score < 3.5 && score > 2.5){
            resultMap.put("对自杀者家属的态度（F3）", "矛盾或中立态度");
            resultJson.put("对自杀者家属的态度（F3）", "矛盾或中立态度");
        }else if (score <= 2.5){
            resultMap.put("对自杀者家属的态度（F3）", "对自杀持肯定、认可、理解和宽容的态度");
            resultJson.put("对自杀者家属的态度（F3）", "对自杀持肯定、认可、理解和宽容的态度");
        }
        resultMap.put("对安乐死的态度（F4）", String.valueOf(scoreF4));
        resultJson.put("对安乐死的态度（F4）", String.valueOf(scoreF4));
        if (score >= 3.5){
            resultMap.put("对安乐死的态度（F4）", "对自杀持反对、否定、排斥和歧视态度");
            resultJson.put("对安乐死的态度（F4）", "对自杀持反对、否定、排斥和歧视态度");
        }else if (score < 3.5 && score > 2.5){
            resultMap.put("对安乐死的态度（F4）", "矛盾或中立态度");
            resultJson.put("对安乐死的态度（F4）", "矛盾或中立态度");
        }else if (score <= 2.5){
            resultMap.put("对安乐死的态度（F4）", "对自杀持肯定、认可、理解和宽容的态度");
            resultJson.put("对安乐死的态度（F4）", "对自杀持肯定、认可、理解和宽容的态度");
        }

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

        return returnJson;
    }
}
