package com.rf.psychological.scale.resultBusiness.cognitiveResult;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.rf.psychological.dao.model.SHAPE2Entity;
import com.rf.psychological.file.excel.ExcelClass;
import com.rf.psychological.scale.resultBusiness.scaleResult.BaseScale;
import com.rf.psychological.utils.Constant;
import com.rf.psychological.utils.ExcelUtil;

import java.text.DecimalFormat;
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 UNCERTAINCognize extends BaseScale {

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

    public  JSONObject scaleCalculate() throws Exception {
        List<Map<String, String>> resultMapList = new ArrayList<>();
        JSONObject jsonObject = resultJson.getJSONObject("jsonObject");
        String fileName = resultJson.getString("fileName");
        String name;

        JSONObject resultDBJson = new JSONObject(true);

        String score = jsonObject.getString("userScore");
        JSONArray jsonArray = jsonObject.getJSONArray("userResponseRecords");
        List<SHAPE2Entity> shape2Entities = jsonArray.toJavaList(SHAPE2Entity.class);
        fileName = fileName + "-" + Constant.SHEET_NAME_UNCERTAIN + ".xlsx";
        name = Constant.SHEET_NAME_UNCERTAIN;

        Map<String, String> resultMap = new LinkedHashMap<>();
        resultMap.put("总分", score);
        resultDBJson.put("总分", score);
        resultMapList = new ArrayList<>();
        resultMapList.add(resultMap);
        String datas = jsonArray.toString();
        ExcelUtil.createExcelFile(SHAPE2Entity.class, shape2Entities, resultMapList, new ExcelClass().contentExcel(Constant.QUEST_TYPE_SHAPE2), fileName, Constant.SHEET_NAME_UNCERTAIN);

        JSONObject returnJson = new JSONObject(true);
        returnJson.put("fileName",fileName);
        returnJson.put("name", name);
        returnJson.put("resultJson",resultDBJson);
        returnJson.put("datas",datas);

        return returnJson;
    }


}
