package com.ld.igds.protocol.fzzy; import com.ld.igds.constant.*; import com.ld.igds.io.request.ExeDevice; import com.ld.igds.n2.N2ModelTag; import com.ld.igds.util.ContextUtil; import com.ld.igds.verb.AreationModel; import org.apache.commons.lang3.StringUtils; import java.util.HashMap; import java.util.Map; /** * 工具类 * * @author Andy */ public class ServerUtils { /** * 设备状态返回的结果 KEY= serId + "_STATUS_" + deviceId value = 结果状态 */ private static Map contextStatusMap = new HashMap<>(); /** * 设备解析后的装法存放 * * @param serId * @param deviceId 设备通道ID * @param status */ public static void add2StatusMap(String companyId, String serId, String deviceId, String status) { contextStatusMap.put(ContextUtil.buildDeviceStatusKey(companyId, serId, deviceId), status); } public static Map getStatusMap() { return contextStatusMap; } public static final String MSG_BEGIN = ""; public static final String MSG_END = ""; //功能码 public static final String FUNCTION_1001 = "1001";// 控制柜请求登录平台 public static final String FUNCTION_1003 = "1003";// 平台获取控制柜设备信息 public static final String FUNCTION_1004 = "1004";// 控制柜向平台推送警告通知 public static final String FUNCTION_1005 = "1005";// 控制柜主动发起心跳 public static final String FUNCTION_1006 = "1006";// 平台透传数据 public static final String FUNCTION_1007 = "1007";// 控制柜推送仓房状态 public static final String FUNCTION_1008 = "1008";// 平台远程更改仓房状态 public static final String FUNCTION_1009 = "1009";// 平台远程授权控制柜 public static final String FUNCTION_1010 = "1010";// 平台获取控制柜仓房信息 public static final String FUNCTION_2101 = "2101";// 平台发起粮情检测请求 public static final String FUNCTION_2102 = "2102";// 控制柜上报粮情采集结果 public static final String FUNCTION_2201 = "2201";// 平台发起检测请求 public static final String FUNCTION_2202 = "2202";// 控制上报送检测进度 public static final String FUNCTION_2203 = "2203";// 控制柜上报检测结果 public static final String FUNCTION_2204 = "2204";// 平台中止虫害采集 public static final String FUNCTION_2301 = "2301";// 平台发起检测请求 public static final String FUNCTION_2302 = "2302";// 控制柜上报检测进度 public static final String FUNCTION_2303 = "2303";// 控制柜上报检测结果 public static final String FUNCTION_2304 = "2304";// 平台中止气体采集 public static final String FUNCTION_3101 = "3101";// 平台远程操作设备 public static final String FUNCTION_3102 = "3102";// 平台获取终端设备状态 public static final String FUNCTION_3103 = "3103";// 平台紧急全关终端设备 public static final String FUNCTION_3201 = "3201";// 平台发起自动通风 public static final String FUNCTION_3301 = "3301";// 平台发起自动气调 public static final String FUNCTION_3302 = "3302";// 平台远程操控制氮机 public static final String FUNCTION_3303 = "3303";// 平台获取制氮机状态 public static final String FUNCTION_3304 = "3304";// 平台获取仓内气压 public static final String FUNCTION_4001 = "4001";// 平台发起能耗监测请求 public static final String FUNCTION_5001 = "5001";// 平台远程操作空调 public static final String FUNCTION_5002 = "5002";// 平台获取空调状态 public static final String FUNCTION_6001 = "6001";// //响应码 public static String RESP_0000 = "0000";// 表示执行成功 public static String RESP_1000 = "1000";// 控制柜编号错误 public static String RESP_1001 = "1001";// 终端设备不在线 public static String RESP_1010 = "1010";// 控制柜授权到期 public static String RESP_1011 = "1011";// 授权码无效 public static String RESP_1012 = "1012";// 授权码已被使用 public static String RESP_1013 = "1013";// 授权码已过期 public static String RESP_2000 = "2000";// 签名验证失败 public static String RESP_3000 = "3000";// 通风模式不支持 public static String RESP_4000 = "4000";// 气调模式不支持 public static String RESP_5000 = "5000";// 控制柜当前为手动模式,拒绝远程操作 public static String RESP_6000 = "6000";// 采集执行失败 public static String RESP_6001 = "6001";// 粮情采集执行中 public static String RESP_6002 = "6002";// 气体采集执行中 public static String RESP_6003 = "6003";// 虫害采集执行中 public static String RESP_9999 = "9999";// 未知错误 //仓库状态 static String DEPOT_STATUS_1001 = "1001";//通风 static String DEPOT_STATUS_2001 = "2001";//气调 static String DEPOT_STATUS_3001 = "3001";//熏蒸 static String DEPOT_STATUS_4001 = "4001";//温控 static String DEPOT_STATUS_5001 = "5001";//维修 static String DEPOT_STATUS_6001 = "6001";//出库 static String DEPOT_STATUS_7001 = "7001";//入库 static String DEPOT_STATUS_8001 = "8001";//满仓 static String DEPOT_STATUS_9001 = "9001";//空仓 //设备类型 public static String DEVICE_TYPE_1 = "1";// 风窗 public static String DEVICE_TYPE_2 = "2";// 风口 public static String DEVICE_TYPE_3 = "3";// 轴流风机 public static String DEVICE_TYPE_4 = "4";// 混流风机 public static String DEVICE_TYPE_5 = "5";// 环流风机 public static String DEVICE_TYPE_6 = "6";// 离心风机 public static String DEVICE_TYPE_7 = "7";//加压风机 public static String DEVICE_TYPE_8 = "8";// 电动蝶阀 public static String DEVICE_TYPE_9 = "9";// 照明 public static String DEVICE_TYPE_10 = "10";//门禁 public static String DEVICE_TYPE_11 = "11";// 空调 public static String DEVICE_TYPE_12 = "12";// 视频 //设备状态 public static String DEVICE_STATUS_01 = "1";// " 开(风机正转) 01 public static String DEVICE_STATUS_02 = "2";// 关 02 public static String DEVICE_STATUS_03 = "3";// 风机反转 03 public static String DEVICE_STATUS_04 = "4";// 开执行中 04 public static String DEVICE_STATUS_05 = "5";// 关执行中 05 public static String DEVICE_STATUS_06 = "6";// 无操作 06 public static String DEVICE_STATUS_07 = "7";// 未知状态 07 //空调模式 public static String TEMP_MODE_10 = "10";//通风 public static String TEMP_MODE_11 = "11";//制冷 public static String TEMP_MODE_20 = "20";//风速低 public static String TEMP_MODE_21 = "21";//风速中 public static String TEMP_MODE_22 = "22";//风速高 //自动气调模式 public static String AUTO_N2_10 = "10";//抽负压 10 public static String AUTO_N2_20 = "20";//气密性检测 20 public static String AUTO_N2_30 = "30";//正常充氮 30 public static String AUTO_N2_31 = "31";//加压充氮 31 public static String AUTO_N2_40 = "40";//均氮 40 public static String AUTO_N2_50 = "50";//氮气回收 50 //自动通风模式 public static String AUTO_AIR_10 = "10";// 排积热通风 10 public static String AUTO_AIR_20 = "20";//自然通风 20 public static String AUTO_AIR_30 = "30";//保水降温通风 30 public static String AUTO_AIR_40 = "40";//除湿通风 40 public static String AUTO_AIR_50 = "50";//用户模式通风 50 //仓库类型 public static String HOUSE_TYPE_1 = "1";// 平房仓 public static String HOUSE_TYPE_2 = "2";//浅圆仓 public static String HOUSE_TYPE_3 = "3";//油罐仓 public static String HOUSE_TYPE_4 = "4";//立筒仓 public static String HOUSE_TYPE_99 = "99";//其他 //设备位置 public static String DEVICE_L0 = "0";// 平房仓-仓正面 public static String DEVICE_L1 = "1";// 平房仓-仓背面 public static String DEVICE_L2 = "2";// 筒仓-顶部 public static String DEVICE_L3 = "3";// 筒仓-底部 /** * 生成TCP连接的KEY * * @param ip * @param port * @return */ public static String getServerKey(String ip, Integer port) { return ip + ":" + port; } /** * 将协议中的仓库状态转换为平台中的仓库状态 * * @param status * @return */ public static String analysisDepotStatus(String status) { if (null == status) return null; if (status.equals(DEPOT_STATUS_1001)) { return DepotStatus.STATUS_33.getCode(); } if (status.equals(DEPOT_STATUS_2001)) { return DepotStatus.STATUS_31.getCode(); } if (status.equals(DEPOT_STATUS_3001)) { return DepotStatus.STATUS_32.getCode(); } if (status.equals(DEPOT_STATUS_4001)) { return DepotStatus.STATUS_34.getCode(); } if (status.equals(DEPOT_STATUS_5001)) { return DepotStatus.STATUS_9.getCode(); } if (status.equals(DEPOT_STATUS_6001)) { return DepotStatus.STATUS_4.getCode(); } if (status.equals(DEPOT_STATUS_7001)) { return DepotStatus.STATUS_2.getCode(); } if (status.equals(DEPOT_STATUS_8001)) { return DepotStatus.STATUS_3.getCode(); } return DepotStatus.STATUS_1.getCode(); } public static String getDepotSendStatus(String status) { if (status.equals(DepotStatus.STATUS_33.getCode())) { return DEPOT_STATUS_1001; } if (status.equals(DepotStatus.STATUS_31.getCode())) { return DEPOT_STATUS_2001; } if (status.equals(DepotStatus.STATUS_32.getCode())) { return DEPOT_STATUS_3001; } if (status.equals(DepotStatus.STATUS_34.getCode())) { return DEPOT_STATUS_4001; } if (status.equals(DepotStatus.STATUS_9.getCode())) { return DEPOT_STATUS_5001; } if (status.equals(DepotStatus.STATUS_4.getCode())) { return DEPOT_STATUS_6001; } if (status.equals(DepotStatus.STATUS_2.getCode())) { return DEPOT_STATUS_7001; } if (status.equals(DepotStatus.STATUS_3.getCode())) { return DEPOT_STATUS_8001; } return DepotStatus.STATUS_1.getCode(); } /** * 根据操作模式,返回空调模式 * * @param mode * @return */ public static String getTempMode(String mode) { if (mode.equals("01")) { return TEMP_MODE_11; } if (mode.equals("02")) { return TEMP_MODE_10; } return TEMP_MODE_11; } /** * 根据操作的设备,返回需要发送的设备状态 * * @param exeDevice * @return */ public static String getDeviceSendStatus(ExeDevice exeDevice) { if (DeviceStatus.OPEN.getCode().equals(exeDevice.getTargetStatus())) return DEVICE_STATUS_01; if (DeviceStatus.CLOSE.getCode().equals(exeDevice.getTargetStatus())) return DEVICE_STATUS_02; if (DeviceStatus.W_OPEN.getCode().equals(exeDevice.getTargetStatus())) return DEVICE_STATUS_01; if (DeviceStatus.W_CLOSE.getCode().equals(exeDevice.getTargetStatus())) return DEVICE_STATUS_02; if (DeviceStatus.F_OPEN.getCode().equals(exeDevice.getTargetStatus())) return DEVICE_STATUS_01; if (DeviceStatus.F_CLOSE.getCode().equals(exeDevice.getTargetStatus())) return DEVICE_STATUS_02; if (DeviceStatus.F_OPEN_F.getCode().equals(exeDevice.getTargetStatus())) return DEVICE_STATUS_03; return DEVICE_STATUS_06; } public static String analysisDeviceStatus(String deviceId, String status) { if (DEVICE_STATUS_01.equals(status)) return DeviceStatus.OPEN.getCode(); if (DEVICE_STATUS_02.equals(status)) return DeviceStatus.CLOSE.getCode(); if (DEVICE_STATUS_03.equals(status)) return DeviceStatus.F_OPEN_F.getCode(); if (DEVICE_STATUS_04.equals(status)) return DeviceStatus.OPEN.getCode(); if (DEVICE_STATUS_05.equals(status)) return DeviceStatus.CLOSE.getCode(); if (DEVICE_STATUS_06.equals(status)) return DeviceStatus.ZERO.getCode(); return DeviceStatus.ERROR.getCode(); } /** * 根据平台自动标签获取 终端执行标签 * * @param modeTag * @return */ public static String getSendAutoAir(String modeTag) { if (AreationModel.MODEL_01.getCode().equals(modeTag)) return AUTO_AIR_30; if (AreationModel.MODEL_02.getCode().equals(modeTag)) return AUTO_AIR_20; if (AreationModel.MODEL_03.getCode().equals(modeTag)) return AUTO_AIR_30; if (AreationModel.MODEL_04.getCode().equals(modeTag)) return AUTO_AIR_40; if (AreationModel.MODEL_05.getCode().equals(modeTag)) return AUTO_AIR_10; return AUTO_AIR_50; } /** * 解析设备位置 * * @param pos * @return */ public static String analysisLocation(String pos, String name) { if (StringUtils.isEmpty(pos)) { if (name.indexOf("仓内") >= 0) return DeviceLocation.L_05.getCode(); if (name.indexOf("仓外") >= 0) return DeviceLocation.L_01.getCode(); } else { if (DEVICE_L0.equals(pos)) return DeviceLocation.L_01.getCode(); if (DEVICE_L1.equals(pos)) return DeviceLocation.L_02.getCode(); if (DEVICE_L2.equals(pos)) return DeviceLocation.L_01.getCode(); if (DEVICE_L3.equals(pos)) return DeviceLocation.L_02.getCode(); } return null; } public static String analysisDepotType(String houseType) { if (StringUtils.isEmpty(houseType)) return DepotType.TYPE_99.getCode(); if (HOUSE_TYPE_1.equals(houseType)) return DepotType.TYPE_01.getCode(); if (HOUSE_TYPE_2.equals(houseType)) return DepotType.TYPE_02.getCode(); if (HOUSE_TYPE_3.equals(houseType)) return DepotType.TYPE_03.getCode(); if (HOUSE_TYPE_3.equals(houseType)) return DepotType.TYPE_04.getCode(); return DepotType.TYPE_99.getCode(); } /** * 设备状态解析 * * @param type * @return * @fanTag 是否有风机 */ public static String analysisDeviceType(String type, boolean fanTag) { if (StringUtils.isEmpty(type)) return null; //如果有风机 if (fanTag) { if (DEVICE_TYPE_1.equals(type)) return DeviceType.TYPE_02.getCode(); if (DEVICE_TYPE_2.equals(type)) return DeviceType.TYPE_0C.getCode(); } if (DEVICE_TYPE_1.equals(type)) return DeviceType.TYPE_01.getCode(); if (DEVICE_TYPE_2.equals(type)) return DeviceType.TYPE_0B.getCode(); if (DEVICE_TYPE_5.equals(type)) return DeviceType.TYPE_04.getCode(); if (DEVICE_TYPE_7.equals(type)) return DeviceType.TYPE_0D.getCode(); if (DEVICE_TYPE_8.equals(type)) return DeviceType.TYPE_07.getCode(); if (DEVICE_TYPE_9.equals(type)) return DeviceType.TYPE_06.getCode(); if (DEVICE_TYPE_10.equals(type)) return DeviceType.TYPE_0E.getCode(); if (DEVICE_TYPE_11.equals(type)) return DeviceType.TYPE_05.getCode(); return null; } /** * 平台--控制柜,氮气模式编码转换 * * @param mode * @return */ public static String P2CN2Mode(String mode) { if (N2ModelTag.MODEL_01.getCode().equals(mode)) { return "10"; } if (N2ModelTag.MODEL_02.getCode().equals(mode)) { return "50"; } if (N2ModelTag.MODEL_03.getCode().equals(mode)) { return "30"; } if (N2ModelTag.MODEL_30.getCode().equals(mode)) { return "20"; } return "00"; } }