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

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.rf.psychological.dao.cognizeModel.ECATEntity;
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:EREC
 * @date 2021/7/20 15:55
 */
public class ERECCognize extends BaseScale {

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

        JSONObject data = jsonObject.getJSONObject("data");
        String totalWords = data.getString("totalWords");
        String positiveWordCount = data.getString("positiveWordCount");
        String negtiveWordCount = data.getString("negtiveWordCount");
        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);

        ObjectEntity totalObjectEntity = new ObjectEntity("总词数", totalWords);
        ObjectEntity posObjectEntity = new ObjectEntity("积极词语个数", positiveWordCount);
        ObjectEntity negObjectEntity = new ObjectEntity("消极词语个数", negtiveWordCount);
        ArrayList<ObjectEntity> objects = new ArrayList<>();
        objects.add(totalObjectEntity);
        objects.add(posObjectEntity);
        objects.add(negObjectEntity);

        fileName = fileName + "-" + Constant.SHEET_NAME_EREC + ".xlsx";
        name = Constant.SHEET_NAME_EREC;
        ExcelUtil.createExcelFile(ObjectEntity.class, objects, resultMapList, new ExcelClass().contentExcel(Constant.QUEST_TYPE_EREC), fileName, Constant.SHEET_NAME_EREC);

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

        return returnJson;
    }


}
