Browse Source

20241218

java8
qiezi 1 year ago
parent
commit
321289f3cf
  1. 1
      src/main/java/com/xujie/sys/modules/reader/config/TCPClient.java
  2. 32
      src/main/java/com/xujie/sys/modules/reader/service/impl/GetInformationForExcelServiceImpl.java
  3. 1
      src/main/java/com/xujie/sys/modules/reader/service/impl/ModbusCommunicateServiceImpl.java

1
src/main/java/com/xujie/sys/modules/reader/config/TCPClient.java

@ -52,6 +52,7 @@ public class TCPClient {
scheduler.scheduleWithFixedDelay(() -> {
checkConnection(config);
}, CHECK_INTERVAL, CHECK_INTERVAL, TimeUnit.SECONDS);
executorService.shutdown();
}
}

32
src/main/java/com/xujie/sys/modules/reader/service/impl/GetInformationForExcelServiceImpl.java

@ -57,22 +57,25 @@ public class GetInformationForExcelServiceImpl extends ServiceImpl<GetInformatio
public void saveByExcel() {
//获取每一个文件夹路径
List<EquipmentFolderLocation> locationList = equipmentFolderLocationService
.lambdaQuery().ne(EquipmentFolderLocation::getSuffix,"RS232/RS485")
.lambdaQuery()
.ne(EquipmentFolderLocation::getSuffix,"RS232/RS485")
.ne(EquipmentFolderLocation::getSuffix,"PLC")
.eq(EquipmentFolderLocation::getId,56)
.list();
if (CollectionUtils.isEmpty(locationList)) {
return;
}
//创建线程池
ExecutorService executorService = Executors.newFixedThreadPool(locationList.size());//线程池的最大数量为文件夹的个数
for (EquipmentFolderLocation excel : locationList) {
for (EquipmentFolderLocation location : locationList) {
executorService.submit(() -> {
try {
if (StringUtils.isNotEmpty(excel.getFolderPath())) {
if (StringUtils.isNotEmpty(location.getFolderPath())) {
//对文件夹下的文件进行读取并保存
saveInformation(excel);
saveInformation(location);
}
} catch (Exception e) {
e.printStackTrace();
log.error("获取文件夹下的文件信息异常:{}", e.getMessage());
}
});
}
@ -125,7 +128,7 @@ public class GetInformationForExcelServiceImpl extends ServiceImpl<GetInformatio
}
}
private void saveInformation(EquipmentFolderLocation equipmentFolderLocation) throws Exception {
private void saveInformation(EquipmentFolderLocation equipmentFolderLocation) throws Exception {
String folderFiler = equipmentFolderLocation.getFolderPath();
//获取文件夹下所有文件
//创建本地文件夹路径
@ -133,9 +136,13 @@ public class GetInformationForExcelServiceImpl extends ServiceImpl<GetInformatio
//获取本地文件夹下所有文件
File[] files = fileInfo.listFiles();
//如果文件夹下面的文件是空,则退出
if (files == null ||files.length==0) {
if (files == null || files.length == 0) {
return;
}
Map<String,List<File>> map = new HashMap<>();
map.put("img",new ArrayList<>());
map.put("excel",new ArrayList<>());
map.put("txt",new ArrayList<>());
//图片
List<String> imageFiles = new ArrayList<>();
//创建一个list用来存储所有的的excel(csv)文件路径
@ -155,12 +162,15 @@ public class GetInformationForExcelServiceImpl extends ServiceImpl<GetInformatio
if (s.equals(type)) {
if (s.equals("jpg") || s.equals("png") || s.equals("gif")) {
imageFiles.add(fileName);
map.get("img").add(file);
}
if (s.equals("csv") || s.equals("xls") || s.equals("xlsx")) {
excelName.add(equipmentFolderLocation.getFolderPath() + File.separator + fileName);
map.get("excel").add(file);
}
if (s.equals("txt") || s.equals("tff")) {
txtName.add(equipmentFolderLocation.getFolderPath() + File.separator + fileName);
map.get("txt").add(file);
}
}
}
@ -203,7 +213,7 @@ public class GetInformationForExcelServiceImpl extends ServiceImpl<GetInformatio
equipmentFolderLocation.setBatchDate("1");
}
int time = Integer.parseInt(equipmentFolderLocation.getBatchDate());
Long finalTime = date.getTime() - createDate.getTime();
long finalTime = date.getTime() - createDate.getTime();
if (finalTime / 1000 > time) {
batchNo = (Integer)resultList.get(0).get("batchNo");
//对应的不是第一次新增的情况下如果批次号不为空的情况下那么草果规定时间 批次号就加一,下次获取的时候就可以直接引用
@ -424,8 +434,10 @@ public class GetInformationForExcelServiceImpl extends ServiceImpl<GetInformatio
throw new RuntimeException("读取设备信息为配置");
}
String data = list.get(i).get(equipmentFolderLocation.getExcelCompareFieldsY()-1);
String[] split = data.split(equipmentFolderLocation.getCuttingSymbol());
insertByEntity(equipmentDataDetail, new HashMap<>(), split);
if (org.springframework.util.StringUtils.hasText(data)){
String[] split = data.split(equipmentFolderLocation.getCuttingSymbol());
insertByEntity(equipmentDataDetail, new HashMap<>(), split);
}
}else {
insertByEntity(equipmentDataDetail, list.get(i), null);
}

1
src/main/java/com/xujie/sys/modules/reader/service/impl/ModbusCommunicateServiceImpl.java

@ -75,6 +75,7 @@ public class ModbusCommunicateServiceImpl implements ModbusCommunicateService {
}
});
}
executor.shutdown();
}
private void handleData(EquipmentFolderLocation folderLocation, long startTime) {

Loading…
Cancel
Save