| | |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.util.*; |
| | | |
| | | /** |
| | |
| | | |
| | | public static String result = ""; |
| | | |
| | | public static Map<String, String> contextMap = new HashMap<>(); |
| | | |
| | | public static double ERROR_CHECK_TAG = -100.0; |
| | | |
| | | public static double FAULT_CHECK_TAG = 85.0; |
| | | |
| | | public static double ERROR_CHECK_TAG2 = 50; |
| | | public static String ERROR_HEX = "FFFF"; |
| | | |
| | | public static double MAX_TEMP = -50.0; |
| | | public static double MIN_TEMP = 50.0; |
| | | |
| | | public static void main(String[] args) { |
| | | String str = "00000000FFEB90FEAA41E821EC21EA21EC21ED21EC21E921E221E921E921E921EC21E921ED21F021E521E521E221E421E321E321E121DE21D721E021DD21DC21DF21FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"; |
| | | System.out.println(str.substring(9*2, 10*2)); |
| | | System.out.println(str.substring(9 * 2, 10 * 2)); |
| | | } |
| | | |
| | | /** |
| | | * 00000000FFEB90FEAA41E821EC21EA21EC21ED21EC21E921E221E921E921E921EC21E921ED21F021E521E521E221E421E321E321E121DE21D721E021DD21DC21DF21FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF |
| | | * |
| | |
| | | public void analysis(String ip, int port, String hexStr) { |
| | | |
| | | result += hexStr; |
| | | if(result.length() < 1066*2){ |
| | | if (result.length() < 1066 * 2) { |
| | | log.info("分机------->>平台,报文长度不够,等待下一包数据"); |
| | | return; |
| | | } |
| | | |
| | | //封装数据 |
| | | ReMessage reMessage = ReMessageBuilder.getInstance().buildMessage(result); |
| | | reMessage.setIp(ip); |
| | | reMessage.setPort(port); |
| | | log.info("分机------->>平台:粮情完整报文信息={}", reMessage); |
| | | result = ""; |
| | | if (!BeiboGrainServerUtils.MSG_START.startsWith(reMessage.getStartStr())) { |
| | | log.error("分机------->>平台,解析粮情失败:报文起始符={}错误,不解析", reMessage.getStartStr()); |
| | | return; |
| | | try { |
| | | |
| | | |
| | | //封装数据 |
| | | ReMessage reMessage = ReMessageBuilder.getInstance().buildMessage(result); |
| | | reMessage.setIp(ip); |
| | | reMessage.setPort(port); |
| | | log.info("分机------->>平台:粮情完整报文信息={}", reMessage); |
| | | result = ""; |
| | | if (!BeiboGrainServerUtils.MSG_START.startsWith(reMessage.getStartStr())) { |
| | | log.error("分机------->>平台,解析粮情失败:报文起始符={}错误,不解析", reMessage.getStartStr()); |
| | | return; |
| | | } |
| | | |
| | | //根据分机地址获取分机信息 |
| | | DeviceSer ser = coreSerService.getCacheSer(ContextUtil.getDefaultCompanyId(), reMessage.getSerId()); |
| | | if (ser == null) { |
| | | log.error("分机-------->>平台,解析粮情失败,未获取到系统粮情主机配置:" + reMessage.getSerId()); |
| | | return; |
| | | } |
| | | |
| | | List<ExeRequest> list = exeOrderService.getInProgressOrderBySerId(BizType.GRAIN.getCode(), ser.getId()); |
| | | if (null == list || list.isEmpty()) { |
| | | String info = "粮情解析失败:分机=" + ser.getName() + "没有获取到所属仓库信息。"; |
| | | log.error("分机------>>>平台:" + info); |
| | | notifyGrainInvoker.notifyWeb(ser.getCompanyId(), OrderRespEnum.MSG_ERROR, BizType.GRAIN, info); |
| | | return; |
| | | } |
| | | |
| | | ExeRequest exeRequest = list.get(0); |
| | | log.info("获取粮情命令信息={}", exeRequest); |
| | | if (null == exeRequest) { |
| | | String info = "粮情解析失败:分机=" + ser.getName() + "没有获取历史命令。"; |
| | | log.error("贝博分机------>>>平台:" + info); |
| | | return; |
| | | } |
| | | |
| | | DepotConf depotConf = commonService.getCacheDepotConf(exeRequest.getCompanyId(), exeRequest.getDepotId()); |
| | | if (null == depotConf) { |
| | | String info = "粮情解析失败:分机=" + ser.getName() + "没有获取到粮情参数配置信息。"; |
| | | log.error("分机------>>>平台:" + info); |
| | | notifyGrainInvoker.notifyWeb(ser.getCompanyId(), |
| | | OrderRespEnum.MSG_ERROR, BizType.GRAIN, info); |
| | | return; |
| | | } |
| | | |
| | | // 首先获取到系统参数,判断是否需要批次自动优化 |
| | | DicSysConf sysConf = commonService.getCacheSysConf(ser.getCompanyId()); |
| | | |
| | | reMessage.setCompanyId(ser.getCompanyId()); |
| | | analysisGrain(depotConf, reMessage, ser, exeRequest, sysConf); |
| | | } catch (Exception e) { |
| | | result = ""; |
| | | log.error("分机------->>平台,解析粮情异常:原因={}", e.toString()); |
| | | } |
| | | |
| | | //根据分机地址获取分机信息 |
| | | DeviceSer ser = coreSerService.getCacheSer(ContextUtil.getDefaultCompanyId(), reMessage.getSerId()); |
| | | if (ser == null) { |
| | | log.error("分机-------->>平台,解析粮情失败,未获取到系统粮情主机配置:" + reMessage.getSerId()); |
| | | return; |
| | | } |
| | | |
| | | List<ExeRequest> list = exeOrderService.getInProgressOrderBySerId(BizType.GRAIN.getCode(), ser.getId()); |
| | | if (null == list || list.isEmpty()) { |
| | | String info = "粮情解析失败:分机=" + ser.getName() + "没有获取到所属仓库信息。"; |
| | | log.error("分机------>>>平台:" + info); |
| | | notifyGrainInvoker.notifyWeb(ser.getCompanyId(), OrderRespEnum.MSG_ERROR, BizType.GRAIN, info); |
| | | return; |
| | | } |
| | | |
| | | ExeRequest exeRequest = list.get(0); |
| | | log.info("获取粮情命令信息={}", exeRequest); |
| | | if (null == exeRequest) { |
| | | String info = "粮情解析失败:分机=" + ser.getName() + "没有获取历史命令。"; |
| | | log.error("贝博分机------>>>平台:" + info); |
| | | return; |
| | | } |
| | | |
| | | DepotConf depotConf = commonService.getCacheDepotConf(exeRequest.getCompanyId(), exeRequest.getDepotId()); |
| | | if (null == depotConf) { |
| | | String info = "粮情解析失败:分机=" + ser.getName() + "没有获取到粮情参数配置信息。"; |
| | | log.error("分机------>>>平台:" + info); |
| | | notifyGrainInvoker.notifyWeb(ser.getCompanyId(), |
| | | OrderRespEnum.MSG_ERROR, BizType.GRAIN, info); |
| | | return; |
| | | } |
| | | |
| | | // 首先获取到系统参数,判断是否需要批次自动优化 |
| | | DicSysConf sysConf = commonService.getCacheSysConf(ser.getCompanyId()); |
| | | |
| | | reMessage.setCompanyId(ser.getCompanyId()); |
| | | analysisGrain(depotConf, reMessage, ser, exeRequest, sysConf); |
| | | } |
| | | |
| | | |
| | |
| | | temp = "0000"; |
| | | } |
| | | //高低位转换后转为16位二进制字符串 |
| | | temp = BytesUtil.toBinary8StringSame(BytesUtil.hexToInt(BytesUtil.tran_LH(temp)), 16); |
| | | //符号位 |
| | | symbol = Integer.valueOf(temp.substring(0, 1)); |
| | | //获取温度值 |
| | | tempValue = BytesUtil.hexToInt(BytesUtil.binToHex(temp.substring(6))) * 0.0625; |
| | | if(symbol == 1){ |
| | | tempValue = (1- BytesUtil.hexToInt(BytesUtil.binToHex(temp.substring(6))))*0.0625; |
| | | temp = BytesUtil.tran_LH(temp); |
| | | if(ERROR_HEX.equals(temp)){ |
| | | tempValue = Constant.ERROR_TEMP; |
| | | }else { |
| | | //10进制转16位的2进制 |
| | | temp = BytesUtil.hexString2binaryString(temp, 16); |
| | | //符号位 |
| | | symbol = Integer.valueOf(temp.substring(0, 1)); |
| | | //获取温度值 |
| | | tempValue = BytesUtil.biannary2Decimal(temp.substring(6)) * 0.0625; |
| | | //若为负,则补码:取反加1 |
| | | if (symbol == 1) { |
| | | tempValue = ((~BytesUtil.biannary2Decimal(temp.substring(6))) + 1) * 0.0625; |
| | | } |
| | | tempValue = NumberUtil.keepPrecision(tempValue, 1); |
| | | } |
| | | tempValue = NumberUtil.keepPrecision(tempValue, 1); |
| | | |
| | | //非正常值 |
| | | if (tempValue > ERROR_CHECK_TAG2) { |
| | |
| | | temp = "0000"; |
| | | } |
| | | |
| | | //高低位转换后转为16位二进制字符串 |
| | | temp = BytesUtil.toBinary8StringSame(BytesUtil.hexToInt(BytesUtil.tran_LH(temp)), 16); |
| | | //符号位 |
| | | symbol = Integer.valueOf(temp.substring(0, 1)); |
| | | //获取温度值 |
| | | tempValue = BytesUtil.hexToInt(BytesUtil.binToHex(temp.substring(6))) * 0.0625; |
| | | if(symbol == 1){ |
| | | tempValue = (1- BytesUtil.hexToInt(BytesUtil.binToHex(temp.substring(6))))*0.0625; |
| | | if(ERROR_HEX.equals(temp)){ |
| | | tempValue = Constant.ERROR_TEMP; |
| | | }else { |
| | | //10进制转16位的2进制 |
| | | temp = BytesUtil.hexString2binaryString(temp, 16); |
| | | //符号位 |
| | | symbol = Integer.valueOf(temp.substring(0, 1)); |
| | | //获取温度值 |
| | | tempValue = BytesUtil.biannary2Decimal(temp.substring(6)) * 0.0625; |
| | | //若为负,则补码:取反加1 |
| | | if (symbol == 1) { |
| | | tempValue = ((~BytesUtil.biannary2Decimal(temp.substring(6))) + 1) * 0.0625; |
| | | } |
| | | tempValue = NumberUtil.keepPrecision(tempValue, 1); |
| | | } |
| | | tempValue = NumberUtil.keepPrecision(tempValue, 1); |
| | | |
| | | // 说明解析的数据有问题 |
| | | if (tempValue == ERROR_CHECK_TAG || tempValue == ERROR_CHECK_TAG2) { |
| | | tempValue = Constant.ERROR_TEMP; |
| | |
| | | grain.setTempIn(Constant.ERROR_TEMP); |
| | | grain.setHumidityIn(Constant.ERROR_TEMP); |
| | | |
| | | grain.setReceiveDate(msg.getReceiveDate()); |
| | | grain.setReceiveDate(new Date()); |
| | | grain.setRemark("粮温正常"); |
| | | |
| | | // 获取缓存中的命令信息 |
| | |
| | | grain.setTempIn(Constant.ERROR_TEMP); |
| | | grain.setHumidityIn(Constant.ERROR_TEMP); |
| | | |
| | | grain.setReceiveDate(msg.getReceiveDate()); |
| | | grain.setReceiveDate(new Date()); |
| | | grain.setRemark("粮温正常"); |
| | | grain.setCheckUser(exeRequest.getExeUser()); |
| | | |