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

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.rf.psychological.dao.model.EATEntity;
import com.rf.psychological.dao.model.EPRTEntity;
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.Comparator;
import java.util.List;
import java.util.Map;

/**
 * @author zsy
 * @description:情绪图片评定任务
 * @date 2021/7/20 15:55
 */
public class EPRTCognize extends BaseScale {

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

        JSONArray jsonArray = jsonObject.getJSONArray("results");
        List<EPRTEntity> eprtEntityList = jsonArray.toJavaList(EPRTEntity.class);

        fileName = fileName + "-" + Constant.SHEET_NAME_EPRT + ".xlsx";
        name = Constant.SHEET_NAME_EPRT;
        String datas = jsonArray.toString();
        ExcelUtil.createExcelFile(EPRTEntity.class, eprtEntityList, resultMapList, new ExcelClass().contentExcel(Constant.QUEST_TYPE_EPRT), fileName, name);

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

        return returnJson;
    }


}
