| | |
| | | if (Constants.RECORD_DATA.equals(tab)) { //出入站 |
| | | if (Constants.ONE.equals(valueString)) {//入站 |
| | | Integer recordDataDone = 11; |
| | | miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".StartTime").value(new Date()).build()); |
| | | miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".RecordDataDone").value(recordDataDone).build()); |
| | | } else if(Constants.TWO.equals(valueString)){//出站 |
| | | Integer result = 21; |
| | |
| | | } |
| | | }else if (Constants.RECORD_SN.equals(tab)){//请求产品序列号 |
| | | if (Constants.ONE.equals(valueString)){ |
| | | Integer result = 11; |
| | | //进站PLC给产品类型,MES读取产品类型 |
| | | Object productTypeObjcet = miloService.readFromOpcUa(thoroughfare + "." + device + ".ProductType").getValue();//产品类型 |
| | | if (ObjectUtil.isNotNull(productTypeObjcet)){ |
| | |
| | | receivingWorkOrders(thoroughfare, device,materialCode); |
| | | }); |
| | | }else{ |
| | | result = 12; |
| | | miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".RecordSNDone").value(12).build()); |
| | | } |
| | | miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".RecordSNDone").value(result).build()); |
| | | |
| | | } |
| | | }else if(Constants.SCREW.equals(tab)){ |
| | | List<String> list = new ArrayList<>(); |
| | | String[] suffixes = {"Torque", "Angle", "TorqueResult", "AngleResult"}; |
| | | |
| | | for (String suffix : suffixes) { |
| | | String string = thoroughfare + "." + device + "." + suffix; |
| | | list.add(string); |
| | | } |
| | | List<ReadWriteEntity> list1 = miloService.readFromOpcUa(list); |
| | | List<Object> collect = list1.stream().map(ReadWriteEntity::getValue).collect(Collectors.toList()); |
| | | String joinedString = String.join(",", collect.toString()); |
| | | WebSocketUsers.sendMessageToUserByText(map.get(device), TightenTheConversionOkNg(joinedString)); |
| | | } |
| | | }catch (Exception e) { |
| | | log.error(e.getMessage()); |
| | |
| | | if(!productNum.isEmpty() && !orderNum.isEmpty()){ |
| | | miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".ModuleCode").value(productNum).build()); |
| | | miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".WorkOrderNumber").value(orderNum).build()); |
| | | miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + device + ".RecordSNDone").value(11).build()); |
| | | } |
| | | |
| | | } catch (Exception e) { |
| | |
| | | throw new RuntimeException(e); |
| | | } |
| | | } |
| | | |
| | | public static String TightenTheConversionOkNg(String param){ |
| | | // 去除首尾的方括号,然后按照逗号分割字符串 |
| | | String[] parts = param.substring(1, param.length() - 1).split(","); |
| | | |
| | | // 创建一个新的StringBuilder来构建替换后的字符串 |
| | | StringBuilder sb = new StringBuilder(); |
| | | sb.append('['); // 添加左方括号 |
| | | |
| | | for (int i = 0; i < parts.length; i++) { |
| | | String part = parts[i].trim(); // 去除可能的空格 |
| | | float value; |
| | | try { |
| | | value = Float.parseFloat(part); // 尝试将字符串转换为浮点数 |
| | | String replacement; |
| | | if(i<2){ |
| | | replacement = part; |
| | | }else{ |
| | | if (value == 1f) { |
| | | replacement = "OK"; |
| | | } else{ |
| | | replacement = "NG"; |
| | | } |
| | | } |
| | | /* if (value == 1f) { |
| | | replacement = "OK"; |
| | | } else if (value == 2f) { |
| | | replacement = "NG"; |
| | | } else { |
| | | replacement = part; // 如果不是1或2,则保持不变 |
| | | }*/ |
| | | sb.append(replacement); |
| | | if (i < parts.length - 1) { |
| | | sb.append(','); // 添加逗号(除了最后一个元素) |
| | | } |
| | | } catch (NumberFormatException e) { |
| | | // 如果转换失败,则保持原样(或进行其他错误处理) |
| | | sb.append(part); |
| | | if (i < parts.length - 1) { |
| | | sb.append(','); |
| | | } |
| | | } |
| | | } |
| | | sb.append(']'); // 添加右方括号 |
| | | return sb.toString(); |
| | | } |
| | | } |