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

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.rf.psychological.dao.cognizeModel.EMEMEntity;
import com.rf.psychological.dao.model.ObjectEntity;
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.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/**
 * @author zsy
 * @description:EMEM情绪识别记忆任务
 * @date 2021/7/20 15:55
 */
public class EMEMCognize extends BaseScale {

    public EMEMCognize(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);

        List<EMEMEntity> ememEntities = jsonObject.getJSONArray("data").toJavaList(EMEMEntity.class);
        JSONObject result = jsonObject.getJSONObject("result");
        String posCorrectRate = result.getString("posCorrectRate");
        String negCorrectRate = result.getString("negCorrectRate");
        String totalCorrectRate = result.getString("totalCorrectRate");

        Map<String, String> resultMap = new LinkedHashMap<>();
        resultMap.put("总体正确率", totalCorrectRate);
        resultDBJson.put("总体正确率", totalCorrectRate);
        resultMap.put("积极词语的正确率", posCorrectRate);
        resultDBJson.put("积极词语的正确率", posCorrectRate);
        resultMap.put("消极词语的正确率", negCorrectRate);
        resultDBJson.put("消极词语的正确率", negCorrectRate);

        resultMapList = new ArrayList<>();
        resultMapList.add(resultMap);

        fileName = fileName + "-" + Constant.SHEET_NAME_EMEM + ".xlsx";
        name = Constant.SHEET_NAME_EMEM;
        ExcelUtil.createExcelFile(EMEMEntity.class, ememEntities, resultMapList, new ExcelClass().contentExcel(Constant.QUEST_TYPE_EMEM), fileName, Constant.SHEET_NAME_EMEM);

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

        return returnJson;
    }


}
