|
|
@@ -1,32 +1,28 @@
|
|
|
package com.sckw.slope.detection.service.task;
|
|
|
|
|
|
-import cn.hutool.core.date.DateUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.sckw.core.model.constant.StringConstant;
|
|
|
import com.sckw.core.model.enums.ReportTypeEnum;
|
|
|
import com.sckw.excel.annotation.ExcelContext;
|
|
|
import com.sckw.excel.utils.ExcelUtil;
|
|
|
import com.sckw.slope.detection.dao.mysql.KwsReportTemplateMapper;
|
|
|
+import com.sckw.slope.detection.dao.tdengine.SlopeDataMapper;
|
|
|
import com.sckw.slope.detection.model.dos.mysql.KwsReportTemplate;
|
|
|
-import com.sckw.slope.detection.model.dos.mysql.KwsThreshold;
|
|
|
import com.sckw.slope.detection.model.dos.tdengine.SlopeData;
|
|
|
import com.sckw.slope.detection.model.vo.DeviceVo;
|
|
|
-import com.sckw.slope.detection.model.vo.excel.KwsAlarmExportVO;
|
|
|
import com.sckw.slope.detection.model.vo.excel.TaskReportExportVO;
|
|
|
import jakarta.annotation.Resource;
|
|
|
-import jakarta.servlet.http.HttpServletRequest;
|
|
|
-import jakarta.servlet.http.HttpServletResponse;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
-import com.sckw.slope.detection.dao.tdengine.SlopeDataMapper;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.time.LocalDateTime;
|
|
|
-import java.time.ZoneId;
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
@@ -42,6 +38,9 @@ import java.util.stream.Collectors;
|
|
|
@EnableScheduling
|
|
|
public class ReportTemplateTaskService {
|
|
|
|
|
|
+ @Value("${scheduled.template.enable}")
|
|
|
+ private String templateEnable;
|
|
|
+
|
|
|
@Resource
|
|
|
KwsReportTemplateMapper reportTemplateMapper;
|
|
|
|
|
|
@@ -53,6 +52,9 @@ public class ReportTemplateTaskService {
|
|
|
*/
|
|
|
@Scheduled(cron = "* * * * * *")
|
|
|
public void templateTaskDay() throws IOException {
|
|
|
+ if (StringConstant.isFalse.equals(templateEnable)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
List<KwsReportTemplate> kwsReportTemplates = reportTemplateMapper.selectList(new LambdaQueryWrapper<KwsReportTemplate>()
|
|
|
.eq(KwsReportTemplate::getStatus, 0)
|
|
|
.eq(KwsReportTemplate::getDelFlag, 0));
|
|
|
@@ -72,34 +74,34 @@ public class ReportTemplateTaskService {
|
|
|
list.addAll(Arrays.asList(intergration));
|
|
|
String projectId = kwsReportTemplate.getProjectId();
|
|
|
//首先查询模板中的要素关联的设备-项目中的设备
|
|
|
- List<DeviceVo> devices = reportTemplateMapper.selectDeviceByProjectId(projectId,list);
|
|
|
+ List<DeviceVo> devices = reportTemplateMapper.selectDeviceByProjectId(projectId, list);
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
List<String> deviceName = new ArrayList<>();
|
|
|
- Map<String,Object> deviceData = new HashMap<>();
|
|
|
- for (DeviceVo vo : devices){
|
|
|
+ Map<String, Object> deviceData = new HashMap<>();
|
|
|
+ for (DeviceVo vo : devices) {
|
|
|
//deviceName.add(vo.getName());
|
|
|
List<SlopeData> selectedData = slopeDataMapper.selectLineListByList(vo.getSnCode(), list, "2022-1-1 00:00:00", date2);
|
|
|
- if(Objects.nonNull(selectedData)){
|
|
|
- Map<String,List<SlopeData>> map = selectedData.stream().collect(Collectors.groupingBy(SlopeData::getMsgId));
|
|
|
+ if (Objects.nonNull(selectedData)) {
|
|
|
+ Map<String, List<SlopeData>> map = selectedData.stream().collect(Collectors.groupingBy(SlopeData::getMsgId));
|
|
|
|
|
|
List<Object> list1 = new ArrayList<>();
|
|
|
- map.forEach((key,value) -> {
|
|
|
- Map<Object,Object> mapdata = new HashMap<>();
|
|
|
- value.forEach(valuetemp->{
|
|
|
- mapdata.put("ts",valuetemp.getMsgId());
|
|
|
- for (int i = 0;i< list.size();i++){
|
|
|
- mapdata.put(valuetemp.getLine(),valuetemp.getVal());
|
|
|
+ map.forEach((key, value) -> {
|
|
|
+ Map<Object, Object> mapdata = new HashMap<>();
|
|
|
+ value.forEach(valuetemp -> {
|
|
|
+ mapdata.put("ts", valuetemp.getMsgId());
|
|
|
+ for (int i = 0; i < list.size(); i++) {
|
|
|
+ mapdata.put(valuetemp.getLine(), valuetemp.getVal());
|
|
|
}
|
|
|
});
|
|
|
list1.add(mapdata);
|
|
|
});
|
|
|
- deviceData.put(vo.getName(),list1);
|
|
|
+ deviceData.put(vo.getName(), list1);
|
|
|
//deviceData.add(list1);
|
|
|
}
|
|
|
}
|
|
|
ExcelContext excelContext = TaskReportExportVO.class.getAnnotation(ExcelContext.class);
|
|
|
- if(Objects.nonNull(devices)) {
|
|
|
- String filePath = ExcelUtil.taskExportByExcelUploadingToOss(deviceData,devices, excelContext.fileName() + ".xlsx", TaskReportExportVO.class);
|
|
|
+ if (Objects.nonNull(devices)) {
|
|
|
+ String filePath = ExcelUtil.taskExportByExcelUploadingToOss(deviceData, devices, excelContext.fileName() + ".xlsx", TaskReportExportVO.class);
|
|
|
}
|
|
|
}
|
|
|
}
|