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

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.rf.psychological.dao.model.HaiKongJiZhanAndTanKeHongLiuEntity;
import com.rf.psychological.dao.model.XuanJingWanLiEntity;
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:坦克洪流   海空激战
 * @date 2021/7/20 15:55
 */
public class TKHLCognize extends BaseScale {

    public TKHLCognize(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;
        String type = resultJson.getString("type");

        JSONObject resultDBJson = new JSONObject(true);

        JSONObject userResponseRecords = jsonObject.getJSONObject("userResponseRecords");
        String levelNum = userResponseRecords.getString("levelNum");
        String everyReactionTimes = userResponseRecords.getString("everyReactionTimes");
        String averageSlideTimes = userResponseRecords.getString("averageSlideTimes");
        String scores = userResponseRecords.getString("scores");
        String correctRate = userResponseRecords.getString("correctRate");
        HaiKongJiZhanAndTanKeHongLiuEntity haiKongJiZhanAndTanKeHongLiuEntity = new HaiKongJiZhanAndTanKeHongLiuEntity(levelNum, everyReactionTimes, averageSlideTimes, scores, correctRate);

        Map<String, String> resultMap = new LinkedHashMap<>();
        resultMap.put("关卡数", String.valueOf(levelNum));
        resultDBJson.put("关卡数", String.valueOf(levelNum));
        resultMap.put("得分", String.valueOf(scores));
        resultDBJson.put("得分", String.valueOf(scores));
        resultMap.put("正确率", String.valueOf(correctRate));
        resultDBJson.put("正确率", String.valueOf(correctRate));
        resultMapList = new ArrayList<>();
        resultMapList.add(resultMap);

        ArrayList<HaiKongJiZhanAndTanKeHongLiuEntity> haiKongJiZhanAndTanKeHongLiuEntities = new ArrayList<>();
        haiKongJiZhanAndTanKeHongLiuEntities.add(haiKongJiZhanAndTanKeHongLiuEntity);
        if (Constant.QUEST_TYPE_TKHL.equals(type)) {
            fileName = fileName + "-" + Constant.SHEET_NAMEE_TKHL + ".xlsx";
            name = Constant.SHEET_NAMEE_TKHL;
            ExcelUtil.createExcelFile(HaiKongJiZhanAndTanKeHongLiuEntity.class, haiKongJiZhanAndTanKeHongLiuEntities, resultMapList, new ExcelClass().contentExcel(Constant.QUEST_TYPE_TKHL), fileName, Constant.SHEET_NAMEE_TKHL);
        } else {
            fileName = fileName + "-" + Constant.SHEET_NAME_HKJZ + ".xlsx";
            name = Constant.SHEET_NAME_HKJZ;
            ExcelUtil.createExcelFile(HaiKongJiZhanAndTanKeHongLiuEntity.class, haiKongJiZhanAndTanKeHongLiuEntities, resultMapList, new ExcelClass().contentExcel(Constant.QUEST_TYPE_HKJZ), fileName, Constant.SHEET_NAME_HKJZ);
        }
        String datas = userResponseRecords.toString();

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

        return returnJson;
    }


}
