|
@@ -3,12 +3,18 @@ package com.sckw.slope.detection.service.task;
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.sckw.core.model.enums.ReportTypeEnum;
|
|
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.mysql.KwsReportTemplateMapper;
|
|
|
import com.sckw.slope.detection.model.dos.mysql.KwsReportTemplate;
|
|
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.mysql.KwsThreshold;
|
|
|
import com.sckw.slope.detection.model.dos.tdengine.SlopeData;
|
|
import com.sckw.slope.detection.model.dos.tdengine.SlopeData;
|
|
|
import com.sckw.slope.detection.model.vo.DeviceVo;
|
|
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.annotation.Resource;
|
|
|
|
|
+import jakarta.servlet.http.HttpServletRequest;
|
|
|
|
|
+import jakarta.servlet.http.HttpServletResponse;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
|
@@ -17,6 +23,7 @@ import org.springframework.stereotype.Component;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
import org.springframework.util.CollectionUtils;
|
|
|
import com.sckw.slope.detection.dao.tdengine.SlopeDataMapper;
|
|
import com.sckw.slope.detection.dao.tdengine.SlopeDataMapper;
|
|
|
|
|
|
|
|
|
|
+import java.io.IOException;
|
|
|
import java.text.SimpleDateFormat;
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.time.LocalDateTime;
|
|
import java.time.LocalDateTime;
|
|
|
import java.time.ZoneId;
|
|
import java.time.ZoneId;
|
|
@@ -44,8 +51,8 @@ public class ReportTemplateTaskService {
|
|
|
/**
|
|
/**
|
|
|
* 报表生成定时任务-天
|
|
* 报表生成定时任务-天
|
|
|
*/
|
|
*/
|
|
|
- //@Scheduled(cron = "* * * * * *")
|
|
|
|
|
- public void templateTaskDay() {
|
|
|
|
|
|
|
+ @Scheduled(cron = "* * * * * *")
|
|
|
|
|
+ public void templateTaskDay() throws IOException {
|
|
|
List<KwsReportTemplate> kwsReportTemplates = reportTemplateMapper.selectList(new LambdaQueryWrapper<KwsReportTemplate>()
|
|
List<KwsReportTemplate> kwsReportTemplates = reportTemplateMapper.selectList(new LambdaQueryWrapper<KwsReportTemplate>()
|
|
|
.eq(KwsReportTemplate::getStatus, 0)
|
|
.eq(KwsReportTemplate::getStatus, 0)
|
|
|
.eq(KwsReportTemplate::getDelFlag, 0));
|
|
.eq(KwsReportTemplate::getDelFlag, 0));
|
|
@@ -67,7 +74,10 @@ public class ReportTemplateTaskService {
|
|
|
//首先查询模板中的要素关联的设备-项目中的设备
|
|
//首先查询模板中的要素关联的设备-项目中的设备
|
|
|
List<DeviceVo> devices = reportTemplateMapper.selectDeviceByProjectId(projectId,list);
|
|
List<DeviceVo> devices = reportTemplateMapper.selectDeviceByProjectId(projectId,list);
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
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){
|
|
for (DeviceVo vo : devices){
|
|
|
|
|
+ //deviceName.add(vo.getName());
|
|
|
List<SlopeData> selectedData = slopeDataMapper.selectLineListByList(vo.getSnCode(), list, "2022-1-1 00:00:00", date2);
|
|
List<SlopeData> selectedData = slopeDataMapper.selectLineListByList(vo.getSnCode(), list, "2022-1-1 00:00:00", date2);
|
|
|
if(Objects.nonNull(selectedData)){
|
|
if(Objects.nonNull(selectedData)){
|
|
|
Map<String,List<SlopeData>> map = selectedData.stream().collect(Collectors.groupingBy(SlopeData::getMsgId));
|
|
Map<String,List<SlopeData>> map = selectedData.stream().collect(Collectors.groupingBy(SlopeData::getMsgId));
|
|
@@ -76,19 +86,21 @@ public class ReportTemplateTaskService {
|
|
|
map.forEach((key,value) -> {
|
|
map.forEach((key,value) -> {
|
|
|
Map<Object,Object> mapdata = new HashMap<>();
|
|
Map<Object,Object> mapdata = new HashMap<>();
|
|
|
value.forEach(valuetemp->{
|
|
value.forEach(valuetemp->{
|
|
|
- mapdata.put("ts",sdf.format(valuetemp.getTs()));
|
|
|
|
|
|
|
+ mapdata.put("ts",valuetemp.getMsgId());
|
|
|
for (int i = 0;i< list.size();i++){
|
|
for (int i = 0;i< list.size();i++){
|
|
|
- // if(valuetemp.getLine().equals(list[i].get("line"))){
|
|
|
|
|
- mapdata.put(valuetemp.getLine(),valuetemp.getVal());
|
|
|
|
|
- //}
|
|
|
|
|
|
|
+ mapdata.put(valuetemp.getLine(),valuetemp.getVal());
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
- list1.add(map);
|
|
|
|
|
|
|
+ list1.add(mapdata);
|
|
|
});
|
|
});
|
|
|
- vo.setData(list1);
|
|
|
|
|
|
|
+ deviceData.put(vo.getName(),list1);
|
|
|
|
|
+ //deviceData.add(list1);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- log.info("aaa:{}",devices);
|
|
|
|
|
|
|
+ ExcelContext excelContext = TaskReportExportVO.class.getAnnotation(ExcelContext.class);
|
|
|
|
|
+ if(Objects.nonNull(devices)) {
|
|
|
|
|
+ String filePath = ExcelUtil.taskExportByExcelUploadingToOss(deviceData,devices, excelContext.fileName() + ".xlsx", TaskReportExportVO.class);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|