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

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.rf.psychological.dao.cognizeModel.FDOTEntity;
import com.rf.psychological.dao.model.ObjectEntity;
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 VASCognize extends BaseScale {

    public VASCognize(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);

        resultMapList = new ArrayList<>();
        JSONArray jsonArray = jsonObject.getJSONArray("data");
        List<ObjectEntity> dataList = jsonArray.toJavaList(ObjectEntity.class);

        resultDBJson.put("versionNo",Constant.COGNITION_RESULT_VERSION);
        JSONArray totalScores = new JSONArray();
        JSONObject totalScore = new JSONObject(true);
        String desc = null;
        String score = dataList.get(0).getValue();
        totalScore.put("totalScore",score);
        if (Double.valueOf(score) > 8){
            desc = "您非常渴求甲基苯丙胺/海洛因";
        }else if(Double.valueOf(score) > 6 && Double.valueOf(score) <= 8){
            desc = "您渴求甲基苯丙胺/海洛因";
        }else if(Double.valueOf(score) > 3 && Double.valueOf(score) <= 6){
            desc = "您对甲基苯丙胺/海洛因有轻度的渴求";
        }else if(Double.valueOf(score) <= 3){
            desc = "您对甲基苯丙胺/海洛因基本不渴求";
        }
        totalScore.put("totalScoreDesc",desc);
        totalScores.add(totalScore);
        resultDBJson.put("totalScore",totalScores);

        JSONObject ifShow = new JSONObject(true);
        ifShow.put("totalScore",true);
        ifShow.put("dimensions",false);
        ifShow.put("note",false);
        ifShow.put("radar",false);
        ifShow.put("table",false);
        resultDBJson.put("ifShow",ifShow);

        Map<String, String> resultMap = new LinkedHashMap<>();
        resultMap.put("总分", dataList.get(0).getValue());
        resultMapList.add(resultMap);
        fileName = fileName + "-" + Constant.SHEET_NAME_VAS + ".xlsx";
        name = Constant.SHEET_NAME_VAS;
        String datas = jsonArray.toString();
        ExcelUtil.createExcelFile(ObjectEntity.class, dataList, resultMapList, new ExcelClass().contentExcel(Constant.QUEST_TYPE_MMSE), fileName, Constant.SHEET_NAME_VAS);

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

        return returnJson;
    }


}
