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 {
    public AlarmRecordWarpper(Object list) { super(list); }
    @Override
    public void warpTheMap(Map<String, Object> map) {

        // 设置闸井相关字段
        String wellCode = map.get("wellCode").toString();
        Map<String,Object> wellInfoMap = EhcacheConstant.retBean().getWellInfoViaCode(wellCode);
        // 设置权属单位、负责人、联系电话
        String deptidStr = wellInfoMap.get("deptid").toString();
        long deptid = ToolUtil.isEmpty(deptidStr)? -1: Long.valueOf(deptidStr);
        map.put("deptName",EhcacheConstant.retBean().getDeptNameById(deptid));
        if(deptid>0){
            Long staffstr = EhcacheConstant.retBean().getUserByDept(deptid);
            if(ToolUtil.isEmpty(staffstr)){
                wellInfoMap.replace("staff","");
                wellInfoMap.replace("tel","");
            }else {
                Map<String,Object> userInfoMap = EhcacheConstant.retBean().getUserInfoById(staffstr);
                wellInfoMap.putAll(userInfoMap);
            }
        }
        map.putAll(wellInfoMap);

        // 告警类型
        String alarmTypeStr = map.get("alarmType").toString();
        map.put("alarmTypeName",EhcacheConstant.retBean().getAlarmTypeNameByCodeNum(alarmTypeStr));

        // 告警内容
        String alarmContentNameStr = map.get("alarmContentName").toString();
        map.put("alarmContent",EhcacheConstant.retBean().getAlarmContentByName(alarmContentNameStr));

        // 告警值加单位
        if(ToolUtil.isNotEmpty(map.get("alarmValue"))){
            String alarmValue = map.get("alarmValue").toString();
            String alarmContentName = map.get("alarmContentName").toString();
            if("液位超限".equals(alarmContentName)) {
                alarmValue += "m";
                map.replace("alarmValue",alarmValue);
            }
            if("浓度超限".equals(alarmContentName)) {
                alarmValue += "%LEL";
                map.replace("alarmValue",alarmValue);
            }
            if("疑似开挖".equals(alarmContentName)) {
                alarmValue += "mg";
                map.replace("alarmValue",alarmValue);
            }
        }

        // 告警值
        if (alarmContentNameStr.contains("井盖") || "2".equals(alarmTypeStr))
        {
            map.replace("alarmValue","--");
        }

        // 告警状态
        String statusStr = map.get("status").toString();
        map.put("statusName",EhcacheConstant.retBean().getDictNameByCodeCodeNum(statusStr,"alarmStatus"));

        // 工单状态
        if(ToolUtil.isNotEmpty(map.get("jobStatus"))){
            String jobStatusStr = map.get("jobStatus").toString();
            map.put("jobStatusName",EhcacheConstant.retBean().getJobStatusNameByCodeNum(jobStatusStr));
        }

    }
}
