|
|
@ -29,6 +29,7 @@ import java.time.LocalDateTime; |
|
|
|
import java.time.format.DateTimeFormatter; |
|
|
|
import java.util.*; |
|
|
|
import java.util.concurrent.CountDownLatch; |
|
|
|
import java.util.concurrent.atomic.AtomicInteger; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
|
|
@ -46,12 +47,21 @@ public class WorkParamReadService extends ServiceImpl<WorkParamReadMapper, WorkP |
|
|
|
@Autowired |
|
|
|
private ThreadPoolTaskExecutor threadPoolTaskExecutor; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private MultipDeviceReadService multipDeviceReadService; |
|
|
|
|
|
|
|
/*获取生产单元的参数读取配置 |
|
|
|
* */ |
|
|
|
public List<DcBusiWorkReadLog> readWorkValue(ReadQueryParams 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) { |
|
|
|
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH"); |
|
|
|
LocalDateTime startDate = LocalDateTime.parse(startDateStr, dateTimeFormatter); |
|
|
@ -59,7 +69,7 @@ public class WorkParamReadService extends ServiceImpl<WorkParamReadMapper, WorkP |
|
|
|
List<String> dateRange = new ArrayList<>(); |
|
|
|
while (!startDate.isAfter(endDate)) { |
|
|
|
dateRange.add(dateTimeFormatter.format(startDate)); |
|
|
|
startDate = startDate.plusDays(1); |
|
|
|
startDate = startDate.plusDays(7); |
|
|
|
} |
|
|
|
dateRange.add(endDateStr); |
|
|
|
return dateRange; |
|
|
@ -70,32 +80,48 @@ public class WorkParamReadService extends ServiceImpl<WorkParamReadMapper, WorkP |
|
|
|
Class<MultipleDeviceDataVO> clazz = MultipleDeviceDataVO.class; |
|
|
|
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[] PARAM_CODE_ARR = new String[]{"007", "009", "011", "012", "013", "014", "045", "046", "047", "048", "028", "029"}; |
|
|
|
List<WorkDataDTO> workDataDTOS = new LinkedList<>(); |
|
|
|
List<String> dateList = this.splitByDay(readQueryReq.getBeginTime(), readQueryReq.getEndTime()); |
|
|
|
int size = dateList.size() - 1; |
|
|
|
CountDownLatch countDownLatch = new CountDownLatch(size); |
|
|
|
for (int i = 0; i < size; i++) { |
|
|
|
String[] PARAM_CODE_ARR = new String[]{"007", "009", "011", "012", "013", "014", "045", "046", "047", "048", "001", "002"}; |
|
|
|
Vector<WorkDataDTO> workDataDTOS = new Vector(); |
|
|
|
int size = DEVICE_CODE_ARR.length; |
|
|
|
int SIGN = 10; |
|
|
|
CountDownLatch countDownLatch = new CountDownLatch(SIGN); |
|
|
|
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(); |
|
|
|
req.setBeginTime(dateList.get(i)); |
|
|
|
req.setEndTime(dateList.get(i + 1)); |
|
|
|
req.setBeginTime(readQueryReq.getBeginTime()); |
|
|
|
req.setEndTime(readQueryReq.getEndTime()); |
|
|
|
req.setParamCodes(Arrays.asList(PARAM_CODE_ARR)); |
|
|
|
req.setDeviceCodes(Arrays.asList(DEVICE_CODE_ARR)); |
|
|
|
threadPoolTaskExecutor.execute(() -> { |
|
|
|
workDataDTOS.addAll(baseMapper.readWorkData(req)); |
|
|
|
log.info("{}~{} 执行成功", req.getBeginTime(), req.getEndTime()); |
|
|
|
countDownLatch.countDown(); |
|
|
|
req.setDeviceCodes(Arrays.asList(DEVICE_CODE_ARR[ii])); |
|
|
|
log.info("{} {} sql执行起始时间 {}", ii, DEVICE_CODE_ARR[ii], System.currentTimeMillis()); |
|
|
|
workDataDTOS.addAll(multipDeviceReadService.getMultipleDeviceData(req)); |
|
|
|
log.info("{} {} sql执行结束时间 {}", ii, DEVICE_CODE_ARR[ii], System.currentTimeMillis()); |
|
|
|
req = null; |
|
|
|
finalCountDownLatch.countDown(); |
|
|
|
}); |
|
|
|
} |
|
|
|
if (i == sign - 1 || i == size - 1) { |
|
|
|
try { |
|
|
|
countDownLatch.await(); |
|
|
|
int j = size - 1 - i; |
|
|
|
if (j < SIGN) { |
|
|
|
SIGN = j; |
|
|
|
} |
|
|
|
sign += SIGN; |
|
|
|
countDownLatch = new CountDownLatch(SIGN); |
|
|
|
} catch (InterruptedException e) { |
|
|
|
log.error("门闩异常", e); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
log.info("查询结束时间:{}", System.currentTimeMillis()); |
|
|
|
if (!CollectionUtils.isEmpty(workDataDTOS)) { |
|
|
|
Map<Date, List<WorkDataDTO>> timeMap = workDataDTOS.stream().collect(Collectors.groupingBy(WorkDataDTO::getThour)); |
|
|
|
Set<Date> keySet = timeMap.keySet(); |
|
|
|
List<Date> keyList = keySet.stream().sorted().collect(Collectors.toList()); |
|
|
|
Map<String, List<WorkDataDTO>> timeMap = workDataDTOS.stream().collect(Collectors.groupingBy(WorkDataDTO::getThour)); |
|
|
|
Set<String> keySet = timeMap.keySet(); |
|
|
|
List<String> keyList = keySet.stream().sorted().collect(Collectors.toList()); |
|
|
|
keyList.forEach(key -> { |
|
|
|
List<WorkDataDTO> value = timeMap.get(key); |
|
|
|
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; |
|
|
|
} |
|
|
|
|
|
|
|
public List<DaTangGuanJingDataVO> getDaTangGuanJingDataVO(ReadQueryReq readQueryReq) { |
|
|
|
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.setDeviceCodes(Arrays.asList(DEVICE_CODE_ARR)); |
|
|
|
Class<DaTangGuanJingDataVO> clazz = DaTangGuanJingDataVO.class; |
|
|
|
Field[] fields = clazz.getDeclaredFields(); |
|
|
|
Vector<DaTangGuanJingDataVO> list = new Vector<>(); |
|
|
|
List<WorkDataDTO> workDataDTOS = baseMapper.readWorkData(readQueryReq); |
|
|
|
List<WorkDataDTO> workDataDTOS = baseMapper.readWorkData2(readQueryReq); |
|
|
|
if (!CollectionUtils.isEmpty(workDataDTOS)) { |
|
|
|
Map<Date, List<WorkDataDTO>> timeMap = workDataDTOS.stream().collect(Collectors.groupingBy(WorkDataDTO::getThour)); |
|
|
|
Set<Date> keySet = timeMap.keySet(); |
|
|
|
List<Date> keyList = keySet.stream().sorted().collect(Collectors.toList()); |
|
|
|
Map<String, List<WorkDataDTO>> timeMap = workDataDTOS.stream().collect(Collectors.groupingBy(WorkDataDTO::getThour)); |
|
|
|
Set<String> keySet = timeMap.keySet(); |
|
|
|
List<String> keyList = keySet.stream().sorted().collect(Collectors.toList()); |
|
|
|
keyList.forEach(key -> { |
|
|
|
List<WorkDataDTO> value = timeMap.get(key); |
|
|
|
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; |
|
|
|
} |
|
|
|
|
|
|
|
public List<ThourWeatherVO> getThourWeather(ReadQueryReq readQueryReq) { |
|
|
|
List<ThourWeatherVO> list = baseMapper.getThourWeather(readQueryReq); |
|
|
|
log.info("天气:{}", list); |
|
|
|
log.info("天气查询完成"); |
|
|
|
return list; |
|
|
|
} |
|
|
|
|
|
|
|