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

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.rf.psychological.dao.model.XiongYingZhanChiEntity;
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 XYZCCognize extends BaseScale {

    public XYZCCognize(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 userResponseRecords = jsonObject.getJSONObject("userResponseRecords");
        String levelNum = userResponseRecords.getString("levelNum");
        String everySlideTimes = userResponseRecords.getString("everySlideTimes");
        String averageSlideTimes = userResponseRecords.getString("averageSlideTimes");
        String scores = userResponseRecords.getString("scores");
        XiongYingZhanChiEntity xiongYingZhanChiEntity = new XiongYingZhanChiEntity(levelNum, everySlideTimes, averageSlideTimes, scores);

        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));
        resultMapList = new ArrayList<>();
        resultMapList.add(resultMap);

        ArrayList<XiongYingZhanChiEntity> xiongYingZhanChiEntities = new ArrayList<>();
        xiongYingZhanChiEntities.add(xiongYingZhanChiEntity);


        String datas = userResponseRecords.toString();
        fileName = fileName + "-" + Constant.SHEET_NAME_XYZC + ".xlsx";
        name = Constant.SHEET_NAME_XYZC;
        ExcelUtil.createExcelFile(XiongYingZhanChiEntity.class, xiongYingZhanChiEntities, resultMapList, new ExcelClass().contentExcel(Constant.QUEST_TYPE_XYZC), fileName, Constant.SHEET_NAME_XYZC);

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

        return returnJson;
    }


}
