|
|
@ -1,18 +1,34 @@ |
|
|
|
package com.lzbi.task.service; |
|
|
|
|
|
|
|
import com.alibaba.excel.EasyExcel; |
|
|
|
import com.alibaba.excel.ExcelWriter; |
|
|
|
import com.alibaba.excel.write.metadata.WriteSheet; |
|
|
|
import com.alibaba.fastjson2.JSONArray; |
|
|
|
import com.baomidou.dynamic.datasource.annotation.DS; |
|
|
|
import com.baomidou.mybatisplus.extension.service.IService; |
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
|
|
|
import com.lzbi.common.config.RuoYiConfig; |
|
|
|
import com.lzbi.common.constant.PartitionConstants; |
|
|
|
import com.lzbi.draft.entity.req.TargetDraftMonthReportReq; |
|
|
|
import com.lzbi.draft.entity.vo.TargetDraftMonthReportVO; |
|
|
|
import com.lzbi.task.domain.*; |
|
|
|
import com.lzbi.task.mapper.WorkParamReadMapper; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.format.annotation.DateTimeFormat; |
|
|
|
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.util.CollectionUtils; |
|
|
|
|
|
|
|
import java.io.File; |
|
|
|
import java.lang.reflect.Field; |
|
|
|
import java.math.BigDecimal; |
|
|
|
import java.math.RoundingMode; |
|
|
|
import java.time.LocalDate; |
|
|
|
import java.time.LocalDateTime; |
|
|
|
import java.time.format.DateTimeFormatter; |
|
|
|
import java.util.*; |
|
|
|
import java.util.concurrent.CountDownLatch; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
|
|
@ -27,24 +43,61 @@ import java.util.stream.Collectors; |
|
|
|
@Slf4j |
|
|
|
public class WorkParamReadService extends ServiceImpl<WorkParamReadMapper, WorkParamInfo> implements IService<WorkParamInfo> { |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private ThreadPoolTaskExecutor threadPoolTaskExecutor; |
|
|
|
|
|
|
|
/*获取生产单元的参数读取配置 |
|
|
|
* */ |
|
|
|
public List<DcBusiWorkReadLog> readWorkValue(ReadQueryParams readQueryParams) { |
|
|
|
return baseMapper.readWorkValue(readQueryParams); |
|
|
|
} |
|
|
|
|
|
|
|
public List<MultipleDeviceDataVO> getMultipleDeviceData(ReadQueryParams readQueryParams) { |
|
|
|
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"}; |
|
|
|
readQueryParams.setParamCodes(Arrays.asList(PARAM_CODE_ARR)); |
|
|
|
readQueryParams.setDeviceCodes(Arrays.asList(DEVICE_CODE_ARR)); |
|
|
|
private List<String> splitByDay(String startDateStr, String endDateStr) { |
|
|
|
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH"); |
|
|
|
LocalDateTime startDate = LocalDateTime.parse(startDateStr, dateTimeFormatter); |
|
|
|
LocalDateTime endDate = LocalDateTime.parse(endDateStr, dateTimeFormatter); |
|
|
|
List<String> dateRange = new ArrayList<>(); |
|
|
|
while (!startDate.isAfter(endDate)) { |
|
|
|
dateRange.add(dateTimeFormatter.format(startDate)); |
|
|
|
startDate = startDate.plusDays(1); |
|
|
|
} |
|
|
|
dateRange.add(endDateStr); |
|
|
|
return dateRange; |
|
|
|
} |
|
|
|
|
|
|
|
public List<MultipleDeviceDataVO> getMultipleDeviceData(ReadQueryReq readQueryReq) { |
|
|
|
Vector<MultipleDeviceDataVO> list = new Vector<>(); |
|
|
|
Class<MultipleDeviceDataVO> clazz = MultipleDeviceDataVO.class; |
|
|
|
Field[] fields = clazz.getDeclaredFields(); |
|
|
|
List<MultipleDeviceDataVO> list = new ArrayList<>(); |
|
|
|
List<WorkDataDTO> workDataDTOS = baseMapper.readWorkData(readQueryParams); |
|
|
|
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++) { |
|
|
|
ReadQueryReq req = new ReadQueryReq(); |
|
|
|
req.setBeginTime(dateList.get(i)); |
|
|
|
req.setEndTime(dateList.get(i + 1)); |
|
|
|
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(); |
|
|
|
}); |
|
|
|
} |
|
|
|
try { |
|
|
|
countDownLatch.await(); |
|
|
|
} catch (InterruptedException e) { |
|
|
|
log.error("门闩异常", e); |
|
|
|
} |
|
|
|
if (!CollectionUtils.isEmpty(workDataDTOS)) { |
|
|
|
Map<Date, List<WorkDataDTO>> timeMap = workDataDTOS.stream().collect(Collectors.groupingBy(WorkDataDTO::getThour)); |
|
|
|
timeMap.forEach((key, value) -> { |
|
|
|
Set<Date> keySet = timeMap.keySet(); |
|
|
|
List<Date> 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)); |
|
|
|
for (String deviceCode : DEVICE_CODE_ARR) { |
|
|
|
if (deviceMap.containsKey(deviceCode)) { |
|
|
@ -55,11 +108,11 @@ public class WorkParamReadService extends ServiceImpl<WorkParamReadMapper, WorkP |
|
|
|
MultipleDeviceDataVO multipleDeviceDataVO = new MultipleDeviceDataVO(); |
|
|
|
multipleDeviceDataVO.setThour(key); |
|
|
|
multipleDeviceDataVO.setDeviceName(deviceMap.get(deviceCode).get(0).getDeviceName()); |
|
|
|
multipleDeviceDataVO.setPartion(p); |
|
|
|
multipleDeviceDataVO.setPartion(PartitionConstants.partition.get(p)); |
|
|
|
for (int i = 0, len = PARAM_CODE_ARR.length; i < len; i++) { |
|
|
|
try { |
|
|
|
if (!fields[i].isAccessible()) { |
|
|
|
fields[i].setAccessible(true); |
|
|
|
if (!fields[i + 3].isAccessible()) { |
|
|
|
fields[i + 3].setAccessible(true); |
|
|
|
} |
|
|
|
List<WorkDataDTO> workDataDTOList1 = paramModelMap.get(PARAM_CODE_ARR[i]); |
|
|
|
if (!CollectionUtils.isEmpty(workDataDTOList1)) { |
|
|
@ -77,7 +130,7 @@ public class WorkParamReadService extends ServiceImpl<WorkParamReadMapper, WorkP |
|
|
|
|
|
|
|
if (null != v && !Double.isNaN(v)) { |
|
|
|
v = BigDecimal.valueOf(v).setScale(2, RoundingMode.HALF_EVEN).doubleValue(); |
|
|
|
fields[i].set(multipleDeviceDataVO, v); |
|
|
|
fields[i + 3].set(multipleDeviceDataVO, v); |
|
|
|
} |
|
|
|
} |
|
|
|
} catch (IllegalAccessException e) { |
|
|
@ -90,21 +143,25 @@ public class WorkParamReadService extends ServiceImpl<WorkParamReadMapper, WorkP |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
log.info("多设备:{}", list); |
|
|
|
return list; |
|
|
|
} |
|
|
|
|
|
|
|
public List<DaTangGuanJingDataVO> getDaTangGuanJingDataVO(ReadQueryParams readQueryParams) { |
|
|
|
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"}; |
|
|
|
readQueryParams.setParamCodes(Arrays.asList(PARAM_CODE_ARR)); |
|
|
|
readQueryParams.setDeviceCodes(Arrays.asList(DEVICE_CODE_ARR)); |
|
|
|
readQueryReq.setParamCodes(Arrays.asList(PARAM_CODE_ARR)); |
|
|
|
readQueryReq.setDeviceCodes(Arrays.asList(DEVICE_CODE_ARR)); |
|
|
|
Class<DaTangGuanJingDataVO> clazz = DaTangGuanJingDataVO.class; |
|
|
|
Field[] fields = clazz.getDeclaredFields(); |
|
|
|
List<DaTangGuanJingDataVO> list = new ArrayList<>(); |
|
|
|
List<WorkDataDTO> workDataDTOS = baseMapper.readWorkData(readQueryParams); |
|
|
|
Vector<DaTangGuanJingDataVO> list = new Vector<>(); |
|
|
|
List<WorkDataDTO> workDataDTOS = baseMapper.readWorkData(readQueryReq); |
|
|
|
if (!CollectionUtils.isEmpty(workDataDTOS)) { |
|
|
|
Map<Date, List<WorkDataDTO>> timeMap = workDataDTOS.stream().collect(Collectors.groupingBy(WorkDataDTO::getThour)); |
|
|
|
timeMap.forEach((key, value) -> { |
|
|
|
Set<Date> keySet = timeMap.keySet(); |
|
|
|
List<Date> 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)); |
|
|
|
for (String deviceCode : DEVICE_CODE_ARR) { |
|
|
|
if (deviceMap.containsKey(deviceCode)) { |
|
|
@ -115,11 +172,11 @@ public class WorkParamReadService extends ServiceImpl<WorkParamReadMapper, WorkP |
|
|
|
DaTangGuanJingDataVO daTangGuanJingDataVO = new DaTangGuanJingDataVO(); |
|
|
|
daTangGuanJingDataVO.setThour(key); |
|
|
|
daTangGuanJingDataVO.setDeviceName(deviceMap.get(deviceCode).get(0).getDeviceName()); |
|
|
|
daTangGuanJingDataVO.setPartion(p); |
|
|
|
daTangGuanJingDataVO.setPartion(PartitionConstants.partition.get(p)); |
|
|
|
for (int i = 0, len = PARAM_CODE_ARR.length; i < len; i++) { |
|
|
|
try { |
|
|
|
if (!fields[i].isAccessible()) { |
|
|
|
fields[i].setAccessible(true); |
|
|
|
if (!fields[i + 3].isAccessible()) { |
|
|
|
fields[i + 3].setAccessible(true); |
|
|
|
} |
|
|
|
List<WorkDataDTO> workDataDTOList1 = paramModelMap.get(PARAM_CODE_ARR[i]); |
|
|
|
if (!CollectionUtils.isEmpty(workDataDTOList1)) { |
|
|
@ -136,7 +193,7 @@ public class WorkParamReadService extends ServiceImpl<WorkParamReadMapper, WorkP |
|
|
|
} |
|
|
|
if (null != v && !Double.isNaN(v)) { |
|
|
|
v = BigDecimal.valueOf(v).setScale(2, RoundingMode.HALF_EVEN).doubleValue(); |
|
|
|
fields[i].set(daTangGuanJingDataVO, v); |
|
|
|
fields[i + 3].set(daTangGuanJingDataVO, v); |
|
|
|
} |
|
|
|
} |
|
|
|
} catch (IllegalAccessException e) { |
|
|
@ -149,10 +206,14 @@ public class WorkParamReadService extends ServiceImpl<WorkParamReadMapper, WorkP |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
log.info("大唐管井:{}", list); |
|
|
|
return list; |
|
|
|
} |
|
|
|
|
|
|
|
public List<ThourWeatherVO> getThourWeather(ReadQueryParams readQueryParams) { |
|
|
|
return baseMapper.getThourWeather(readQueryParams); |
|
|
|
public List<ThourWeatherVO> getThourWeather(ReadQueryReq readQueryReq) { |
|
|
|
List<ThourWeatherVO> list = baseMapper.getThourWeather(readQueryReq); |
|
|
|
log.info("天气:{}", list); |
|
|
|
return list; |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|