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

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.rf.psychological.dao.cognizeModel.BSNTaskEntity;
import com.rf.psychological.dao.model.XiongYingZhanChiEntity;
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:Boston命名测验
 * @date 2021/7/20 15:55
 */
public class BSNTASKCognize extends BaseScale {

    public BSNTASKCognize(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 result = jsonObject.getJSONObject("result");
        String rightNum = result.getString("rightNum");
        String tipNum = result.getString("tipNum");
        String identifyNum = result.getString("identifyNum");
        String errorNum = result.getString("errorNum");
        JSONArray picList = result.getJSONArray("picList");

        List<BSNTaskEntity> bsnTaskEntities = picList.toJavaList(BSNTaskEntity.class);

        Map<String, String> resultMap = new LinkedHashMap<>();
        resultMap.put("正确个数", String.valueOf(rightNum));
        resultDBJson.put("正确个数", String.valueOf(rightNum));
        resultMap.put("提示个数", String.valueOf(tipNum));
        resultDBJson.put("提示个数", String.valueOf(tipNum));
        resultMap.put("辨认个数", String.valueOf(identifyNum));
        resultDBJson.put("辨认个数", String.valueOf(identifyNum));
        resultMap.put("错误个数", String.valueOf(errorNum));
        resultDBJson.put("错误个数", String.valueOf(errorNum));
        resultMapList = new ArrayList<>();
        resultMapList.add(resultMap);

        String datas = JSONArray.toJSONString(bsnTaskEntities);
        fileName = fileName + "-" + Constant.SHEET_NAME_BSNTask + ".xlsx";
        name = Constant.SHEET_NAME_BSNTask;
        ExcelUtil.createExcelFile(BSNTaskEntity.class, bsnTaskEntities, resultMapList, new ExcelClass().contentExcel(Constant.QUEST_TYPE_BSNTask), fileName, Constant.SHEET_NAME_BSNTask);

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

        return returnJson;
    }


}
