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

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.rf.psychological.dao.model.ObjectEntity;
import com.rf.psychological.dao.model.XiongYingZhanChiEntity;
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.*;

/**
 * @author zsy
 * @description:动物词语流畅性测试
 * @date 2021/7/20 15:55
 */
public class AMWSTASKCognize extends BaseScale {

    public AMWSTASKCognize(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 result = jsonObject.getJSONObject("result");
        String num = result.getString("num");
        ObjectEntity num1 = new ObjectEntity("成绩", num);

        resultDBJson.put("versionNo",Constant.COGNITION_RESULT_VERSION);
        JSONArray totalScores = new JSONArray();
        JSONObject totalScore = new JSONObject(true);
        String desc = null;
        totalScore.put("totalScore",num);
        if (Double.valueOf(num) > 40){
            desc = "您的语言流畅性很好，相关语言功能脑区（额叶及颞叶)的功能正常。";
        }else if(Double.valueOf(num) > 30 && Double.valueOf(num) <= 40){
            desc = "您的语言流畅性较好，相关语言功能脑区（额叶及颞叶)的功能正常。";
        }else if(Double.valueOf(num) > 20 && Double.valueOf(num) <= 30){
            desc = "您的语言流畅性一般，相关语言功能脑区（额叶及颞叶)的功能正常。";
        }else if(Double.valueOf(num) > 10 && Double.valueOf(num) <= 20){
            desc = "您的语言流畅性较差，相关语言功能脑区的功能可能存在减退，建议进行进一步的轻度认知障碍测试。";
        }else if(Double.valueOf(num) <= 10){
            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);

        ArrayList<ObjectEntity> objects = new ArrayList<>();
        objects.add(num1);

        Map<String, String> resultMap = new HashMap<>();
        resultMap.put("成绩", num);
        resultDBJson.put("成绩", num);

        fileName = fileName + "-" + Constant.SHEET_NAME_AMWSTask + ".xlsx";
        name = Constant.SHEET_NAME_AMWSTask;
        ExcelUtil.createExcelFile(ObjectEntity.class, objects, resultMapList, new ExcelClass().contentExcel(Constant.QUEST_TYPE_AMWSTask), fileName, Constant.SHEET_NAME_AMWSTask);

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

        return returnJson;
    }


}
