package com.fzzy.protocol.fzzy.server; import com.fzzy.gateway.data.BaseReqData; import java.util.HashMap; import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; /** * 工具类 * * @author Andy */ public class ServerUtils { private static Map contextOrder = new HashMap<>(); /** * 请求缓存 key = deviceId,value = requData */ private static Map contextSyncReqMap = new HashMap<>(); /** * 将执行命令信息存放在缓存 * * @param depotId 仓库编码 * @param reqData 请求参数信息 */ public static void addSyncReq2Map(String depotId, BaseReqData reqData) { contextSyncReqMap.put(depotId, reqData); } public static BaseReqData getSyncReq(String depotId) { return contextSyncReqMap.get(depotId); } 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 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; } public static String getOrderByDepotId(String depotId) { if (null == depotId) { Integer integer = contextOrder.get("ORDER"); if (null == integer) integer = 1000; integer = integer + 1; contextOrder.put("ORDER", integer); return integer + ""; } //只要数字 String regEx = "[^0-9]"; Pattern p = Pattern.compile(regEx); Matcher m = p.matcher(depotId); String regDepotId = m.replaceAll("").trim(); if (regDepotId.length() > 4) { regDepotId = regDepotId.substring(regDepotId.length() - 4); } return Integer.valueOf(regDepotId) + ""; } }