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

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

    public RHYTHMCognize(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;
        String name;

        JSONObject resultDBJson = new JSONObject(true);

        String score = jsonObject.getString("score");
        String types = jsonObject.getString("type");
        String subType = jsonObject.getString("subType");
        String interval = jsonObject.getString("interval");
        String duration = jsonObject.getString("duration");
        String questionNo = jsonObject.getString("questionNo");

        fileName = resultJson.getString("fileName") + "-" + Constant.SHEET_NAME_RHYTHM + ".xlsx";
        name = Constant.SHEET_NAME_RHYTHM;

        resultDBJson.put("总分", score);
        resultDBJson.put("模式类型", types + "-" + subType);
        resultDBJson.put("节拍间隔", interval + "ms");
        resultDBJson.put("持续时间", duration + "s");
        String b64Img = questionNo;
        RhythmEntity rhythmEntity = new RhythmEntity();
        rhythmEntity.setDuration(duration + "s");
        rhythmEntity.setInterval(interval + "ms");
        rhythmEntity.setSubType(types + "-" + subType);
        rhythmEntity.setScore(score);
        rhythmEntity.setQuestionNo(questionNo);
        List<RhythmEntity> rhythmEntities = new ArrayList<>();
        rhythmEntities.add(rhythmEntity);
        String datas = jsonObject.toString();
        ExcelUtil.createExcelFile(RhythmEntity.class, rhythmEntities, null, new ExcelClass().contentExcel(Constant.QUEST_TYPE_RHYTHM), fileName, Constant.SHEET_NAME_RHYTHM);

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

        return returnJson;
    }


}
