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

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

    public  JSONObject scaleCalculate() throws Exception {
        //问题解决得分
        int score1 = 0;
        //沟通得分
        int score2 = 0;
        //角色得分
        int score3 = 0;
        //情感反应得分
        int score4 = 0;
        //情感介人得分
        int score5 = 0;
        //行为控制得分
        int score6 = 0;
        //总的功能得分
        int score7 = 0;
        for (int i = 0; i < jsonArray.size(); i++) {
            JSONObject jsonObject1 = jsonArray.getJSONObject(i);
            if (jsonObject1.getString("scoreDirection").equals("1")) {
                if (i == 1 || i == 11 || i == 23 || i == 37 || i == 49 || i == 59){
                    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 (i == 2 || i == 13 || i == 17 || i == 21 || i == 28 || i == 34 || i == 42 || i == 51 || i == 58){
                    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 (i == 3 || i == 7 || i == 9 || i == 14 || i == 22 || i == 29 || i == 33 || i == 39 || i == 44 || i == 52 || i == 57){
                    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 (i == 8 || i == 18 || i == 27 || i == 38 || i == 48 || i == 56){
                    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 (i == 4 || i == 12 || i == 24 || i == 32 || i == 36 || i == 41 || i == 53){
                    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 (i == 6 || i == 16 || i == 19 || i == 26 || i == 31 || i == 43 || i == 46 || i == 47 || i == 54){
                    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("非常同意（或很像我家）")) {
                        score7 += 1;
                    } else if (jsonObject1.getString("checkItems").equals("同意（或像我家）")) {
                        score7 += 2;
                    } else if (jsonObject1.getString("checkItems").equals("不同意（或不像我家）")) {
                        score7 += 3;
                    } else if (jsonObject1.getString("checkItems").equals("完全不同意（或完全不像我家）")) {
                        score7 += 4;
                    }
                }
            }else if (jsonObject1.getString("scoreDirection").equals("0")){
                if (i == 1 || i == 11 || i == 23 || i == 37 || i == 49 || i == 59){
                    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 (i == 2 || i == 13 || i == 17 || i == 21 || i == 28 || i == 34 || i == 42 || i == 51 || i == 58){
                    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 (i == 3 || i == 7 || i == 9 || i == 14 || i == 22 || i == 29 || i == 33 || i == 39 || i == 44 || i == 52 || i == 57){
                    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 (i == 8 || i == 18 || i == 27 || i == 38 || i == 48 || i == 56){
                    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 (i == 4 || i == 12 || i == 24 || i == 32 || i == 36 || i == 41 || i == 53){
                    if (jsonObject1.getString("checkItems").equals("非常同意（或很像我家）")) {
                        score5 += 4;
                    } else if (jsonObject1.getString("checkItems").equals("同意（或像我家）")) {
                        score5 += 3;
                    } else if (jsonObject1.getString("checkItems").equals("不同意（或不像我家）")) {
                        score5 += 2;
                    } else if (jsonObject1.getString("checkItems").equals("完全不同意（或完全不像我家）")) {
                        score5 += 1;
                    }
                }else if (i == 6 || i == 16 || i == 19 || i == 26 || i == 31 || i == 43 || i == 46 || i == 47 || i == 54){
                    if (jsonObject1.getString("checkItems").equals("非常同意（或很像我家）")) {
                        score6 += 4;
                    } else if (jsonObject1.getString("checkItems").equals("同意（或像我家）")) {
                        score6 += 3;
                    } else if (jsonObject1.getString("checkItems").equals("不同意（或不像我家）")) {
                        score6 += 2;
                    } else if (jsonObject1.getString("checkItems").equals("完全不同意（或完全不像我家）")) {
                        score6 += 1;
                    }
                }else {
                    if (jsonObject1.getString("checkItems").equals("非常同意（或很像我家）")) {
                        score7 += 4;
                    } else if (jsonObject1.getString("checkItems").equals("同意（或像我家）")) {
                        score7 += 3;
                    } else if (jsonObject1.getString("checkItems").equals("不同意（或不像我家）")) {
                        score7 += 2;
                    } else if (jsonObject1.getString("checkItems").equals("完全不同意（或完全不像我家）")) {
                        score7 += 1;
                    }
                }
            }
        }

        //得分列表
        List<Map<String,String>> resultMapList = new ArrayList<>();
        Map<String, String> resultMap1 = new LinkedHashMap<>();
        resultMap1.put("问题解决得分", String.valueOf(score1));
        resultJson.put("问题解决得分", String.valueOf(score1));
        resultMapList.add(resultMap1);
        Map<String, String> resultMap2 = new LinkedHashMap<>();
        resultMap2.put("沟通得分", String.valueOf(score2));
        resultJson.put("沟通得分", String.valueOf(score2));
        resultMapList.add(resultMap2);
        Map<String, String> resultMap3 = new LinkedHashMap<>();
        resultMap3.put("角色得分", String.valueOf(score3));
        resultJson.put("角色得分", String.valueOf(score3));
        resultMapList.add(resultMap3);
        Map<String, String> resultMap4 = new LinkedHashMap<>();
        resultMap4.put("情感反应得分", String.valueOf(score4));
        resultJson.put("情感反应得分", String.valueOf(score4));
        resultMapList.add(resultMap4);
        Map<String, String> resultMap5 = new LinkedHashMap<>();
        resultMap5.put("情感介人得分", String.valueOf(score5));
        resultJson.put("情感介人得分", String.valueOf(score5));
        resultMapList.add(resultMap5);
        Map<String, String> resultMap6 = new LinkedHashMap<>();
        resultMap6.put("行为控制得分", String.valueOf(score6));
        resultJson.put("行为控制得分", String.valueOf(score6));
        resultMapList.add(resultMap6);
        Map<String, String> resultMap7 = new LinkedHashMap<>();
        resultMap7.put("总的功能得分", String.valueOf(score7));
        resultJson.put("总的功能得分", String.valueOf(score7));
        resultMapList.add(resultMap7);

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

        return returnJson;
    }
}
