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

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.rf.psychological.dao.model.SHAPE2Entity;
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.text.DecimalFormat;
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 XJWLCognize extends BaseScale {

    public XJWLCognize(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");
        XuanJingWanLiEntity xuanJingWanLiEntity = data.toJavaObject(XuanJingWanLiEntity.class);

        fileName = fileName + "-" + Constant.SHEET_NAME_XJWL + ".xlsx";
        name = Constant.SHEET_NAME_XJWL;

        Map<String, String> resultMap = new LinkedHashMap<>();
        resultMap.put("总分", xuanJingWanLiEntity.getFenFen());
        resultMap.put("关卡数", xuanJingWanLiEntity.getNanNan() + "");
        resultMap.put("正确率", xuanJingWanLiEntity.getZhengQue());
        resultMap.put("正确个数", xuanJingWanLiEntity.getZhengZheng() + "");
        resultMap.put("错误个数", xuanJingWanLiEntity.getCuo() + "");
        resultDBJson.put("总分", xuanJingWanLiEntity.getFenFen());
        resultDBJson.put("关卡数", xuanJingWanLiEntity.getNanNan() + "");
        resultDBJson.put("正确率", xuanJingWanLiEntity.getZhengQue());
        resultDBJson.put("正确个数", xuanJingWanLiEntity.getZhengZheng() + "");
        resultDBJson.put("错误个数", xuanJingWanLiEntity.getCuo() + "");
        resultMapList = new ArrayList<>();
        resultMapList.add(resultMap);

        String datas = data.toString();
        List<XuanJingWanLiEntity> xuanJingWanLiEntities = new ArrayList<>();
        xuanJingWanLiEntities.add(xuanJingWanLiEntity);
        ExcelUtil.createExcelFile(XuanJingWanLiEntity.class, xuanJingWanLiEntities, resultMapList, new ExcelClass().contentExcel(Constant.SHEET_NAME_XJWL), fileName, Constant.SHEET_NAME_XJWL);

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

        return returnJson;
    }


}
