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;

/**
 * @description A型、B型性格测试
 */
public class ABTScale extends BaseScale {
    public ABTScale(JSONArray jsonArray, JSONObject resultJson) {
        super(jsonArray, resultJson);
    }

    public JSONObject scaleCalculate() throws Exception {
        //是总分
        int scoreA = 0;
        //否总分
        int scoreB = 0;

        for (int i = 0; i < jsonArray.size(); i++) {
            JSONObject jsonObject1 = jsonArray.getJSONObject(i);
            if (jsonObject1.getString("checkItems").equals("是")) {
                scoreA += 1;
            } else if (jsonObject1.getString("checkItems").equals("否")) {
                scoreB += 1;
            }
        }


        //得分列表
        Map<String, String> resultMap = new LinkedHashMap<>();
        resultMap.put("A总分", String.valueOf(scoreA));
        resultMap.put("B总分", String.valueOf(scoreB));
        resultJson.put("A总分", String.valueOf(scoreA));
        resultJson.put("B总分", String.valueOf(scoreB));


        if (scoreA > scoreB) {
            resultMap.put("结论", "A性性格倾向");
            resultJson.put("结论", "A性性格倾向");
        } else {
            resultMap.put("结论", "B性性格倾向");
            resultJson.put("结论", "B性性格倾向");
        }


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

        return returnJson;
    }
}
