package com.casic.missiles.modular.system.warpper;

import com.casic.missiles.core.util.EhcacheConstant;
import com.casic.missiles.core.base.warpper.BaseControllerWarpper;
import com.casic.missiles.core.util.ToolUtil;

import java.util.HashMap;
import java.util.Map;

//@Service
//@Primary
public class AlarmRecordWarpper extends BaseControllerWarpper {
    //    private EhcacheConstant ehcacheConstant = new EhcacheConstant();
    public AlarmRecordWarpper(Object list) {
        super(list);
    }

    @Override
    public void warpTheMap(Map<String, Object> map) {
/*
        SELECT ar.ID as id,ar.WELL_CODE as wellCode,ar.ALARM_CONTENT as alarmContent,
        ar.ALARM_TIME as alarmTime,ar.DEVICE_ID as deviceId,
        ar.STATUS as status,ar.alarm_type as alarmType,
        aj.JOB_STATUS as jobStatus,ar.JOB_ID as jobId
 */
        Map<String, Object> wellInfoMap = new HashMap<>();
        Map<String, Object> userInfoMap = new HashMap<>();
        String alarmTypeStr = map.get("alarmType").toString();
        String statusStr = map.get("status").toString();
        String wellCode = map.get("wellCode").toString();
        String alarmContentNameStr = map.get("alarmContentName").toString();
        if (ToolUtil.isEmpty(map.get("handlePerson"))) map.replace("handlePerson", "--");
        if (ToolUtil.isEmpty(map.get("handleTime"))) map.replace("handleTime", "--");
        if (alarmContentNameStr.contains("井盖") || "2".equals(alarmTypeStr)) {
            map.replace("alarmValue", "--");
        }
//        String alarmContentStr = map.get("alarmContent").toString(); dictionary version
        String jobStatusStr = map.get("jobStatus").toString();//if notnull
//        int alarmContent = ToolUtil.isEmpty(alarmContentStr)? -1: Integer.valueOf(alarmContentStr) ;//if notnull

        wellInfoMap = EhcacheConstant.retBean().getWellInfoViaCode(wellCode);
        String deptidStr = wellInfoMap.get("deptid").toString();
        long deptid = ToolUtil.isEmpty(deptidStr) ? -1 : Long.valueOf(deptidStr);
        String staffStr = (String) wellInfoMap.get("staff");
        if (EhcacheConstant.isNumL(staffStr)) {
            userInfoMap = EhcacheConstant.retBean().getUserInfoById(Long.valueOf(staffStr));
            wellInfoMap.putAll(userInfoMap);
        }
//        if (EhcacheConstant.isNumL(staffStr)){
//            wellInfoMap.replace("staff",EhcacheConstant.retBean().getUsernameById(Long.valueOf(staffStr)));
//        }

        map.put("alarmTypeName", EhcacheConstant.retBean().getAlarmTypeNameByCodeNum(alarmTypeStr));
        map.put("deptName", EhcacheConstant.retBean().getDeptNameById(deptid));
        map.put("alarmContent", EhcacheConstant.retBean().getAlarmContentByName(alarmContentNameStr));
//        map.put("alarmContentName",EhcacheConstant.retBean().getAlarmContentName(alarmContent));//dictionaryversion
        map.put("statusName", EhcacheConstant.retBean().getDictNameByCodeCodeNum(statusStr, "alarmStatus"));//std dictionary
        map.put("jobStatusName", EhcacheConstant.retBean().getJobStatusNameByCodeNum(jobStatusStr));

        map.putAll(wellInfoMap);

//        map.clear();
    }
}
