|
|
|
@ -57,18 +57,27 @@ public class ModbusCommunicateServiceImpl implements ModbusCommunicateService { |
|
|
|
|
|
|
|
@Override |
|
|
|
public void getInfoByModbus() { |
|
|
|
log.info("modbus请求开始解析"); |
|
|
|
log.info("PLC开始"); |
|
|
|
long startTime = System.nanoTime(); |
|
|
|
List<EquipmentFolderLocation> list = equipmentFolderLocationService.lambdaQuery().eq(EquipmentFolderLocation::getSuffix, "PLC").list(); |
|
|
|
if (list.isEmpty()){ |
|
|
|
log.error("设备消息未维护"); |
|
|
|
return; |
|
|
|
} |
|
|
|
log.info("PLC设备数量:{}",list.size()); |
|
|
|
// 创建线程池 |
|
|
|
ExecutorService executor = Executors.newFixedThreadPool(list.size()); |
|
|
|
for (EquipmentFolderLocation folderLocation : list) { |
|
|
|
//EquipmentFolderLocation folderLocation = equipmentFolderLocationService.lambdaQuery().eq(EquipmentFolderLocation::getSuffix, "PLC").one(); |
|
|
|
executor.submit(()->{ |
|
|
|
try { |
|
|
|
handleData(folderLocation, startTime); |
|
|
|
}catch (Exception e){ |
|
|
|
log.error("获取数据失败", e); |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private void handleData(EquipmentFolderLocation folderLocation, long startTime) { |
|
|
|
final String MODBUS_IP = folderLocation.getIp(); |
|
|
|
if (StringUtils.isEmpty(MODBUS_IP) || "127.0.0.1".equals(MODBUS_IP)) { |
|
|
|
return; |
|
|
|
return ; |
|
|
|
} |
|
|
|
final int MODBUS_PORT = folderLocation.getPort(); |
|
|
|
int registerAddress = folderLocation.getRegisterAddress(); |
|
|
|
@ -79,51 +88,11 @@ public class ModbusCommunicateServiceImpl implements ModbusCommunicateService { |
|
|
|
//获取单号 |
|
|
|
String inspectionOrderNumber = getInspectionOrderNumber(MODBUS_IP, MODBUS_PORT, registerAddressInspection, registerNumInspection, unitId).trim(); |
|
|
|
if (StringUtils.isEmpty(inspectionOrderNumber)) {//判断是空或者是寄存器是零的话就返回 |
|
|
|
return; |
|
|
|
return ; |
|
|
|
} |
|
|
|
|
|
|
|
//获取对应检验单号的值 |
|
|
|
List<List<Float>> floatValues = getValue(MODBUS_IP, MODBUS_PORT, registerAddress, registerNum, unitId); |
|
|
|
|
|
|
|
//获取对应的batchNo |
|
|
|
// LambdaQueryWrapper<EquipmentFolderSortEntity> wrapper = new LambdaQueryWrapper<>(); |
|
|
|
// wrapper.eq(EquipmentFolderSortEntity::getSite,folderLocation.getSite()); |
|
|
|
// wrapper.eq(EquipmentFolderSortEntity::getBuNo,folderLocation.getBuNo()); |
|
|
|
// wrapper.eq(EquipmentFolderSortEntity::getInspectionNo,inspectionOrderNumber); |
|
|
|
// EquipmentFolderSortEntity one = equipmentFolderSortService.getOne(wrapper); |
|
|
|
// Integer batchNo ; |
|
|
|
// //在所有的数据新增玩之后 , 对应的获取批次号进行新增或者修改(数据第一次就新增) |
|
|
|
// if (one==null) { |
|
|
|
// EquipmentFolderSortEntity equipmentFolderSortEntity = new EquipmentFolderSortEntity(); |
|
|
|
// equipmentFolderSortEntity.setSite(folderLocation.getSite()); |
|
|
|
// equipmentFolderSortEntity.setBuNo(folderLocation.getBuNo()); |
|
|
|
// equipmentFolderSortEntity.setInspectionNo(inspectionOrderNumber); |
|
|
|
// equipmentFolderSortEntity.setBatchNo(2); |
|
|
|
// equipmentFolderSortEntity.setFileNo(folderLocation.getFileNo()); |
|
|
|
// equipmentFolderSortEntity.setCreateDate(new Date()); |
|
|
|
// equipmentFolderSortService.save(equipmentFolderSortEntity); |
|
|
|
// //对应的批次号为1 |
|
|
|
// batchNo = 1; |
|
|
|
// } else { |
|
|
|
// Date createDate = one.getCreateDate();//获取最近新增一条信息的时间 |
|
|
|
// Date date = new Date(); |
|
|
|
// if (StringUtils.isEmpty(folderLocation.getBatchDate())) { |
|
|
|
// folderLocation.setBatchDate("1"); |
|
|
|
// } |
|
|
|
// int time = Integer.parseInt(folderLocation.getBatchDate()); |
|
|
|
// Long finalTime = date.getTime() - createDate.getTime(); |
|
|
|
// if (finalTime / 1000 > time) { |
|
|
|
// batchNo = one.getBatchNo(); |
|
|
|
// //对应的不是第一次新增的情况下如果批次号不为空的情况下那么草果规定时间 批次号就加一,下次获取的时候就可以直接引用 |
|
|
|
// one.setBatchNo(batchNo+1); |
|
|
|
// one.setFileNo(folderLocation.getFileNo()); |
|
|
|
// one.setCreateDate(new Date()); |
|
|
|
// equipmentFolderSortService.updateById(one); |
|
|
|
// } else { |
|
|
|
// batchNo = one.getBatchNo(); |
|
|
|
// } |
|
|
|
// } |
|
|
|
|
|
|
|
int num = 1; |
|
|
|
List<EquipmentDataDetail> detailList = new ArrayList<>(); |
|
|
|
for (List<Float> aFloat : floatValues) { |
|
|
|
@ -148,7 +117,6 @@ public class ModbusCommunicateServiceImpl implements ModbusCommunicateService { |
|
|
|
log.info("num: {}", num); |
|
|
|
saveInformation(detailList); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
@Transactional |
|
|
|
|