|
@ -29,6 +29,7 @@ import java.time.LocalDateTime; |
|
|
import java.time.format.DateTimeFormatter; |
|
|
import java.time.format.DateTimeFormatter; |
|
|
import java.util.*; |
|
|
import java.util.*; |
|
|
import java.util.concurrent.CountDownLatch; |
|
|
import java.util.concurrent.CountDownLatch; |
|
|
|
|
|
import java.util.concurrent.atomic.AtomicInteger; |
|
|
import java.util.stream.Collectors; |
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -46,12 +47,21 @@ public class WorkParamReadService extends ServiceImpl<WorkParamReadMapper, WorkP |
|
|
@Autowired |
|
|
@Autowired |
|
|
private ThreadPoolTaskExecutor threadPoolTaskExecutor; |
|
|
private ThreadPoolTaskExecutor threadPoolTaskExecutor; |
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
|
private MultipDeviceReadService multipDeviceReadService; |
|
|
|
|
|
|
|
|
/*获取生产单元的参数读取配置 |
|
|
/*获取生产单元的参数读取配置 |
|
|
* */ |
|
|
* */ |
|
|
public List<DcBusiWorkReadLog> readWorkValue(ReadQueryParams readQueryParams) { |
|
|
public List<DcBusiWorkReadLog> readWorkValue(ReadQueryParams readQueryParams) { |
|
|
return baseMapper.readWorkValue(readQueryParams); |
|
|
return baseMapper.readWorkValue(readQueryParams); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static void main(String[] args) { |
|
|
|
|
|
for (int i = 0; i < 43; i++) { |
|
|
|
|
|
System.out.println("" + (i % 5)); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
private List<String> splitByDay(String startDateStr, String endDateStr) { |
|
|
private List<String> splitByDay(String startDateStr, String endDateStr) { |
|
|
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH"); |
|
|
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH"); |
|
|
LocalDateTime startDate = LocalDateTime.parse(startDateStr, dateTimeFormatter); |
|
|
LocalDateTime startDate = LocalDateTime.parse(startDateStr, dateTimeFormatter); |
|
@ -59,7 +69,7 @@ public class WorkParamReadService extends ServiceImpl<WorkParamReadMapper, WorkP |
|
|
List<String> dateRange = new ArrayList<>(); |
|
|
List<String> dateRange = new ArrayList<>(); |
|
|
while (!startDate.isAfter(endDate)) { |
|
|
while (!startDate.isAfter(endDate)) { |
|
|
dateRange.add(dateTimeFormatter.format(startDate)); |
|
|
dateRange.add(dateTimeFormatter.format(startDate)); |
|
|
startDate = startDate.plusDays(1); |
|
|
startDate = startDate.plusDays(7); |
|
|
} |
|
|
} |
|
|
dateRange.add(endDateStr); |
|
|
dateRange.add(endDateStr); |
|
|
return dateRange; |
|
|
return dateRange; |
|
@ -70,32 +80,48 @@ public class WorkParamReadService extends ServiceImpl<WorkParamReadMapper, WorkP |
|
|
Class<MultipleDeviceDataVO> clazz = MultipleDeviceDataVO.class; |
|
|
Class<MultipleDeviceDataVO> clazz = MultipleDeviceDataVO.class; |
|
|
Field[] fields = clazz.getDeclaredFields(); |
|
|
Field[] fields = clazz.getDeclaredFields(); |
|
|
String[] DEVICE_CODE_ARR = new String[]{"00011","00053","00054","00050","00055","00051","00052","00059","00056","00057","00022","00023","00024","00009","00058","00026","00029","00030","00031","00032","00044","00013","00007","00017","00046","00042","00019","00016","00001","00028","00045","00021","00010","00041","00015","00014","00005","00006","00002","00003","00004","00008","00018","00027","00043","00020","00040"}; |
|
|
String[] DEVICE_CODE_ARR = new String[]{"00011","00053","00054","00050","00055","00051","00052","00059","00056","00057","00022","00023","00024","00009","00058","00026","00029","00030","00031","00032","00044","00013","00007","00017","00046","00042","00019","00016","00001","00028","00045","00021","00010","00041","00015","00014","00005","00006","00002","00003","00004","00008","00018","00027","00043","00020","00040"}; |
|
|
String[] PARAM_CODE_ARR = new String[]{"007", "009", "011", "012", "013", "014", "045", "046", "047", "048", "028", "029"}; |
|
|
String[] PARAM_CODE_ARR = new String[]{"007", "009", "011", "012", "013", "014", "045", "046", "047", "048", "001", "002"}; |
|
|
List<WorkDataDTO> workDataDTOS = new LinkedList<>(); |
|
|
Vector<WorkDataDTO> workDataDTOS = new Vector(); |
|
|
List<String> dateList = this.splitByDay(readQueryReq.getBeginTime(), readQueryReq.getEndTime()); |
|
|
int size = DEVICE_CODE_ARR.length; |
|
|
int size = dateList.size() - 1; |
|
|
int SIGN = 10; |
|
|
CountDownLatch countDownLatch = new CountDownLatch(size); |
|
|
CountDownLatch countDownLatch = new CountDownLatch(SIGN); |
|
|
for (int i = 0; i < size; i++) { |
|
|
AtomicInteger index = new AtomicInteger(0); |
|
|
|
|
|
log.info("查询起始时间:{}", System.currentTimeMillis()); |
|
|
|
|
|
for (int i = 0, sign = SIGN; i < sign && i < size; i++) { |
|
|
|
|
|
CountDownLatch finalCountDownLatch = countDownLatch; |
|
|
|
|
|
threadPoolTaskExecutor.execute(() -> { |
|
|
|
|
|
int ii = index.getAndAdd(1); |
|
|
|
|
|
log.info("ii = {}", ii); |
|
|
ReadQueryReq req = new ReadQueryReq(); |
|
|
ReadQueryReq req = new ReadQueryReq(); |
|
|
req.setBeginTime(dateList.get(i)); |
|
|
req.setBeginTime(readQueryReq.getBeginTime()); |
|
|
req.setEndTime(dateList.get(i + 1)); |
|
|
req.setEndTime(readQueryReq.getEndTime()); |
|
|
req.setParamCodes(Arrays.asList(PARAM_CODE_ARR)); |
|
|
req.setParamCodes(Arrays.asList(PARAM_CODE_ARR)); |
|
|
req.setDeviceCodes(Arrays.asList(DEVICE_CODE_ARR)); |
|
|
req.setDeviceCodes(Arrays.asList(DEVICE_CODE_ARR[ii])); |
|
|
threadPoolTaskExecutor.execute(() -> { |
|
|
log.info("{} {} sql执行起始时间 {}", ii, DEVICE_CODE_ARR[ii], System.currentTimeMillis()); |
|
|
workDataDTOS.addAll(baseMapper.readWorkData(req)); |
|
|
workDataDTOS.addAll(multipDeviceReadService.getMultipleDeviceData(req)); |
|
|
log.info("{}~{} 执行成功", req.getBeginTime(), req.getEndTime()); |
|
|
log.info("{} {} sql执行结束时间 {}", ii, DEVICE_CODE_ARR[ii], System.currentTimeMillis()); |
|
|
countDownLatch.countDown(); |
|
|
req = null; |
|
|
|
|
|
finalCountDownLatch.countDown(); |
|
|
}); |
|
|
}); |
|
|
} |
|
|
if (i == sign - 1 || i == size - 1) { |
|
|
try { |
|
|
try { |
|
|
countDownLatch.await(); |
|
|
countDownLatch.await(); |
|
|
|
|
|
int j = size - 1 - i; |
|
|
|
|
|
if (j < SIGN) { |
|
|
|
|
|
SIGN = j; |
|
|
|
|
|
} |
|
|
|
|
|
sign += SIGN; |
|
|
|
|
|
countDownLatch = new CountDownLatch(SIGN); |
|
|
} catch (InterruptedException e) { |
|
|
} catch (InterruptedException e) { |
|
|
log.error("门闩异常", e); |
|
|
log.error("门闩异常", e); |
|
|
} |
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
log.info("查询结束时间:{}", System.currentTimeMillis()); |
|
|
if (!CollectionUtils.isEmpty(workDataDTOS)) { |
|
|
if (!CollectionUtils.isEmpty(workDataDTOS)) { |
|
|
Map<Date, List<WorkDataDTO>> timeMap = workDataDTOS.stream().collect(Collectors.groupingBy(WorkDataDTO::getThour)); |
|
|
Map<String, List<WorkDataDTO>> timeMap = workDataDTOS.stream().collect(Collectors.groupingBy(WorkDataDTO::getThour)); |
|
|
Set<Date> keySet = timeMap.keySet(); |
|
|
Set<String> keySet = timeMap.keySet(); |
|
|
List<Date> keyList = keySet.stream().sorted().collect(Collectors.toList()); |
|
|
List<String> keyList = keySet.stream().sorted().collect(Collectors.toList()); |
|
|
keyList.forEach(key -> { |
|
|
keyList.forEach(key -> { |
|
|
List<WorkDataDTO> value = timeMap.get(key); |
|
|
List<WorkDataDTO> value = timeMap.get(key); |
|
|
Map<String, List<WorkDataDTO>> deviceMap = value.stream().collect(Collectors.groupingBy(WorkDataDTO::getDeviceCode)); |
|
|
Map<String, List<WorkDataDTO>> deviceMap = value.stream().collect(Collectors.groupingBy(WorkDataDTO::getDeviceCode)); |
|
@ -143,23 +169,23 @@ public class WorkParamReadService extends ServiceImpl<WorkParamReadMapper, WorkP |
|
|
} |
|
|
} |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
log.info("多设备:{}", list); |
|
|
log.info("多设备查询完成"); |
|
|
return list; |
|
|
return list; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public List<DaTangGuanJingDataVO> getDaTangGuanJingDataVO(ReadQueryReq readQueryReq) { |
|
|
public List<DaTangGuanJingDataVO> getDaTangGuanJingDataVO(ReadQueryReq readQueryReq) { |
|
|
String[] DEVICE_CODE_ARR = new String[]{"00033"}; |
|
|
String[] DEVICE_CODE_ARR = new String[]{"00033"}; |
|
|
String[] PARAM_CODE_ARR = new String[]{"007", "009", "011", "012", "013", "014", "049", "054", "030", "031", "028", "029"}; |
|
|
String[] PARAM_CODE_ARR = new String[]{"007", "009", "011", "012", "013", "014", "049", "054", "030", "031", "001", "002"}; |
|
|
readQueryReq.setParamCodes(Arrays.asList(PARAM_CODE_ARR)); |
|
|
readQueryReq.setParamCodes(Arrays.asList(PARAM_CODE_ARR)); |
|
|
readQueryReq.setDeviceCodes(Arrays.asList(DEVICE_CODE_ARR)); |
|
|
readQueryReq.setDeviceCodes(Arrays.asList(DEVICE_CODE_ARR)); |
|
|
Class<DaTangGuanJingDataVO> clazz = DaTangGuanJingDataVO.class; |
|
|
Class<DaTangGuanJingDataVO> clazz = DaTangGuanJingDataVO.class; |
|
|
Field[] fields = clazz.getDeclaredFields(); |
|
|
Field[] fields = clazz.getDeclaredFields(); |
|
|
Vector<DaTangGuanJingDataVO> list = new Vector<>(); |
|
|
Vector<DaTangGuanJingDataVO> list = new Vector<>(); |
|
|
List<WorkDataDTO> workDataDTOS = baseMapper.readWorkData(readQueryReq); |
|
|
List<WorkDataDTO> workDataDTOS = baseMapper.readWorkData2(readQueryReq); |
|
|
if (!CollectionUtils.isEmpty(workDataDTOS)) { |
|
|
if (!CollectionUtils.isEmpty(workDataDTOS)) { |
|
|
Map<Date, List<WorkDataDTO>> timeMap = workDataDTOS.stream().collect(Collectors.groupingBy(WorkDataDTO::getThour)); |
|
|
Map<String, List<WorkDataDTO>> timeMap = workDataDTOS.stream().collect(Collectors.groupingBy(WorkDataDTO::getThour)); |
|
|
Set<Date> keySet = timeMap.keySet(); |
|
|
Set<String> keySet = timeMap.keySet(); |
|
|
List<Date> keyList = keySet.stream().sorted().collect(Collectors.toList()); |
|
|
List<String> keyList = keySet.stream().sorted().collect(Collectors.toList()); |
|
|
keyList.forEach(key -> { |
|
|
keyList.forEach(key -> { |
|
|
List<WorkDataDTO> value = timeMap.get(key); |
|
|
List<WorkDataDTO> value = timeMap.get(key); |
|
|
Map<String, List<WorkDataDTO>> deviceMap = value.stream().collect(Collectors.groupingBy(WorkDataDTO::getDeviceCode)); |
|
|
Map<String, List<WorkDataDTO>> deviceMap = value.stream().collect(Collectors.groupingBy(WorkDataDTO::getDeviceCode)); |
|
@ -206,13 +232,13 @@ public class WorkParamReadService extends ServiceImpl<WorkParamReadMapper, WorkP |
|
|
} |
|
|
} |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
log.info("大唐管井:{}", list); |
|
|
log.info("大唐管井查询完成"); |
|
|
return list; |
|
|
return list; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public List<ThourWeatherVO> getThourWeather(ReadQueryReq readQueryReq) { |
|
|
public List<ThourWeatherVO> getThourWeather(ReadQueryReq readQueryReq) { |
|
|
List<ThourWeatherVO> list = baseMapper.getThourWeather(readQueryReq); |
|
|
List<ThourWeatherVO> list = baseMapper.getThourWeather(readQueryReq); |
|
|
log.info("天气:{}", list); |
|
|
log.info("天气查询完成"); |
|
|
return list; |
|
|
return list; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|