|
@@ -1,23 +1,36 @@
|
|
|
package com.sckw.slope.detection.service.task;
|
|
package com.sckw.slope.detection.service.task;
|
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
|
+import com.sckw.core.model.constant.NumberConstant;
|
|
|
|
|
+import com.sckw.core.model.enums.DeviceEnum;
|
|
|
import com.sckw.core.model.enums.ReportTypeEnum;
|
|
import com.sckw.core.model.enums.ReportTypeEnum;
|
|
|
|
|
+import com.sckw.core.utils.IdWorker;
|
|
|
import com.sckw.excel.annotation.ExcelContext;
|
|
import com.sckw.excel.annotation.ExcelContext;
|
|
|
import com.sckw.excel.utils.ExcelUtil;
|
|
import com.sckw.excel.utils.ExcelUtil;
|
|
|
|
|
+import com.sckw.slope.detection.dao.mysql.KwsProjectDeviceMapper;
|
|
|
|
|
+import com.sckw.slope.detection.dao.mysql.KwsReportDataMapper;
|
|
|
import com.sckw.slope.detection.dao.mysql.KwsReportTemplateMapper;
|
|
import com.sckw.slope.detection.dao.mysql.KwsReportTemplateMapper;
|
|
|
import com.sckw.slope.detection.dao.tdengine.SlopeDataMapper;
|
|
import com.sckw.slope.detection.dao.tdengine.SlopeDataMapper;
|
|
|
|
|
+import com.sckw.slope.detection.model.dos.mysql.KwsDevice;
|
|
|
|
|
+import com.sckw.slope.detection.model.dos.mysql.KwsReportData;
|
|
|
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.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.TaskReportExportVO;
|
|
import com.sckw.slope.detection.model.vo.excel.TaskReportExportVO;
|
|
|
import jakarta.annotation.Resource;
|
|
import jakarta.annotation.Resource;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
|
|
|
|
+import org.springframework.scheduling.annotation.Scheduled;
|
|
|
import org.springframework.stereotype.Component;
|
|
import org.springframework.stereotype.Component;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
import org.springframework.util.CollectionUtils;
|
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
|
|
+import java.net.MalformedURLException;
|
|
|
|
|
+import java.net.URL;
|
|
|
|
|
+import java.net.URLConnection;
|
|
|
import java.security.MessageDigest;
|
|
import java.security.MessageDigest;
|
|
|
import java.security.NoSuchAlgorithmException;
|
|
import java.security.NoSuchAlgorithmException;
|
|
|
import java.text.SimpleDateFormat;
|
|
import java.text.SimpleDateFormat;
|
|
@@ -43,9 +56,78 @@ public class ReportTemplateTaskService {
|
|
|
@Resource
|
|
@Resource
|
|
|
KwsReportTemplateMapper reportTemplateMapper;
|
|
KwsReportTemplateMapper reportTemplateMapper;
|
|
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ KwsReportDataMapper kwsReportDataMapper;
|
|
|
|
|
+
|
|
|
@Autowired
|
|
@Autowired
|
|
|
SlopeDataMapper slopeDataMapper;
|
|
SlopeDataMapper slopeDataMapper;
|
|
|
|
|
|
|
|
|
|
+ public void report(KwsReportTemplate kwsReportTemplate,String date1,String date2) throws NoSuchAlgorithmException, IOException {
|
|
|
|
|
+
|
|
|
|
|
+ String[] title = "推送时间".split(",");
|
|
|
|
|
+ String[] part = kwsReportTemplate.getPartNames().split(",");
|
|
|
|
|
+ String[] intergration = kwsReportTemplate.getIntergrationNames().split(",");
|
|
|
|
|
+ List<String> list = new ArrayList<>();
|
|
|
|
|
+ list.addAll(Arrays.asList(title));
|
|
|
|
|
+ list.addAll(Arrays.asList(part));
|
|
|
|
|
+ list.addAll(Arrays.asList(intergration));
|
|
|
|
|
+ String projectId = kwsReportTemplate.getProjectId();
|
|
|
|
|
+ //首先查询模板中的要素关联的设备-项目中的设备
|
|
|
|
|
+ List<DeviceVo> devices = reportTemplateMapper.selectDeviceByProjectId(projectId, list);
|
|
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
|
|
+ //List<Object> deviceName = new ArrayList<>();
|
|
|
|
|
+ List<Map<String,Object>> deviceData = new ArrayList<>();
|
|
|
|
|
+ Map<String,List<Object>> map1 = new HashMap<>();
|
|
|
|
|
+ for (DeviceVo vo : devices){
|
|
|
|
|
+ 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));
|
|
|
|
|
+
|
|
|
|
|
+ List<Object> list1 = new ArrayList<>();
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ map.forEach((key,value) -> {
|
|
|
|
|
+ List<Object> listObject = new ArrayList<>();
|
|
|
|
|
+ value.forEach(valuetemp->{
|
|
|
|
|
+ listObject.add(sdf.format(valuetemp.getTs()));
|
|
|
|
|
+ for (int i = 0;i< list.size();i++){
|
|
|
|
|
+ if(valuetemp.getLine().equals(list.get(i))){
|
|
|
|
|
+ listObject.add(valuetemp.getVal());
|
|
|
|
|
+ }else{
|
|
|
|
|
+ listObject.add("");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ list1.add(listObject);
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ map1.put(vo.getName(),list1);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ ExcelContext excelContext = TaskReportExportVO.class.getAnnotation(ExcelContext.class);
|
|
|
|
|
+ if(devices.size()>0) {
|
|
|
|
|
+ String md5 = returnMd5();
|
|
|
|
|
+ String filePath = ExcelUtil.taskExportByExcelUploadingToOss(map1,devices, md5 + ".xlsx", TaskReportExportVO.class,list);
|
|
|
|
|
+ //生成的日报新增到kws_report_data
|
|
|
|
|
+ URL url = new URL(filePath);
|
|
|
|
|
+ URLConnection connection = url.openConnection();
|
|
|
|
|
+ int fileSize = connection.getContentLength();
|
|
|
|
|
+ KwsReportData report = new KwsReportData();
|
|
|
|
|
+ LocalDateTime now = LocalDateTime.now();
|
|
|
|
|
+ long id = new IdWorker(NumberConstant.ONE).nextId();
|
|
|
|
|
+ report.setMountainId(kwsReportTemplate.getCompanyId());
|
|
|
|
|
+ report.setCompanyId(kwsReportTemplate.getCompanyId());
|
|
|
|
|
+ report.setTemplateId(kwsReportTemplate.getId());
|
|
|
|
|
+ report.setProjectId(Long.parseLong(kwsReportTemplate.getProjectId()));
|
|
|
|
|
+ report.setFileSize(new BigDecimal(fileSize));
|
|
|
|
|
+ report.setFileUrl(filePath);
|
|
|
|
|
+ report.setId(id);
|
|
|
|
|
+ report.setCreateTime(now);
|
|
|
|
|
+ report.setDelFlag(NumberConstant.ZERO);
|
|
|
|
|
+ kwsReportDataMapper.insert(report);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 报表生成定时任务-天
|
|
* 报表生成定时任务-天
|
|
|
*/
|
|
*/
|
|
@@ -63,51 +145,7 @@ public class ReportTemplateTaskService {
|
|
|
LocalDateTime dateStart = com.sckw.excel.utils.DateUtil.localDateToLocalDateTimeStart(localDateTime.toLocalDate());
|
|
LocalDateTime dateStart = com.sckw.excel.utils.DateUtil.localDateToLocalDateTimeStart(localDateTime.toLocalDate());
|
|
|
String date1 = dateStart.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
|
|
String date1 = dateStart.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
|
|
|
String date2 = dateEnd.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
|
|
String date2 = dateEnd.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
|
|
|
- String[] title = "推送时间".split(",");
|
|
|
|
|
- String[] part = kwsReportTemplate.getPartNames().split(",");
|
|
|
|
|
- String[] intergration = kwsReportTemplate.getIntergrationNames().split(",");
|
|
|
|
|
- List<String> list = new ArrayList<>();
|
|
|
|
|
- list.addAll(Arrays.asList(title));
|
|
|
|
|
- list.addAll(Arrays.asList(part));
|
|
|
|
|
- list.addAll(Arrays.asList(intergration));
|
|
|
|
|
- String projectId = kwsReportTemplate.getProjectId();
|
|
|
|
|
- //首先查询模板中的要素关联的设备-项目中的设备
|
|
|
|
|
- List<DeviceVo> devices = reportTemplateMapper.selectDeviceByProjectId(projectId, list);
|
|
|
|
|
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
|
|
- //List<Object> deviceName = new ArrayList<>();
|
|
|
|
|
- List<Map<String,Object>> deviceData = new ArrayList<>();
|
|
|
|
|
- Map<String,List<Object>> map1 = new HashMap<>();
|
|
|
|
|
- for (DeviceVo vo : devices){
|
|
|
|
|
- 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));
|
|
|
|
|
-
|
|
|
|
|
- List<Object> list1 = new ArrayList<>();
|
|
|
|
|
- map.forEach((key,value) -> {
|
|
|
|
|
- //Map<Object,Object> mapdata = new HashMap<>();
|
|
|
|
|
- List<Object> listObject = new ArrayList<>();
|
|
|
|
|
- value.forEach(valuetemp->{
|
|
|
|
|
- //mapdata.put("ts",valuetemp.getMsgId());
|
|
|
|
|
- listObject.add(sdf.format(valuetemp.getTs()));
|
|
|
|
|
- for (int i = 0;i< list.size();i++){
|
|
|
|
|
- if(valuetemp.getLine().equals(list.get(i))){
|
|
|
|
|
- listObject.add(valuetemp.getVal());
|
|
|
|
|
- }else{
|
|
|
|
|
- listObject.add("");
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
- list1.add(listObject);
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
- map1.put(vo.getName(),list1);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- ExcelContext excelContext = TaskReportExportVO.class.getAnnotation(ExcelContext.class);
|
|
|
|
|
- if(Objects.nonNull(devices)) {
|
|
|
|
|
- String md5 = returnMd5();
|
|
|
|
|
- String filePath = ExcelUtil.taskExportByExcelUploadingToOss(map1,devices, md5 + ".xlsx", TaskReportExportVO.class,list);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ report(kwsReportTemplate,date1,date2);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -141,7 +179,7 @@ public class ReportTemplateTaskService {
|
|
|
* 报表生成定时任务-周
|
|
* 报表生成定时任务-周
|
|
|
*/
|
|
*/
|
|
|
// @Scheduled(cron = "0 0 0 ? * *")
|
|
// @Scheduled(cron = "0 0 0 ? * *")
|
|
|
- /*public void templateTaskWeek() {
|
|
|
|
|
|
|
+ public void templateTaskWeek() throws NoSuchAlgorithmException, 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));
|
|
@@ -149,19 +187,22 @@ public class ReportTemplateTaskService {
|
|
|
for (KwsReportTemplate kwsReportTemplate : kwsReportTemplates) {
|
|
for (KwsReportTemplate kwsReportTemplate : kwsReportTemplates) {
|
|
|
Integer type = kwsReportTemplate.getType();
|
|
Integer type = kwsReportTemplate.getType();
|
|
|
if (ReportTypeEnum.WEEK.getCode() == type) {
|
|
if (ReportTypeEnum.WEEK.getCode() == type) {
|
|
|
- if (2 != DateUtil.thisDayOfWeekEnum().getValue()) {
|
|
|
|
|
- continue;
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ LocalDateTime localDateTime = LocalDateTime.now().minusDays(7);
|
|
|
|
|
+ LocalDateTime dateEnd = com.sckw.excel.utils.DateUtil.localDateToLocalDateTimeEnd(localDateTime.toLocalDate());
|
|
|
|
|
+ LocalDateTime dateStart = com.sckw.excel.utils.DateUtil.localDateToLocalDateTimeStart(localDateTime.toLocalDate());
|
|
|
|
|
+ String date1 = dateStart.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
|
|
|
|
|
+ String date2 = dateEnd.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
|
|
|
|
|
+ report(kwsReportTemplate,date1,date2);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- }*/
|
|
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 报表生成定时任务-月
|
|
* 报表生成定时任务-月
|
|
|
*/
|
|
*/
|
|
|
// @Scheduled(cron = "0 0 0 ? * *")
|
|
// @Scheduled(cron = "0 0 0 ? * *")
|
|
|
- /*public void templateTaskMonth() {
|
|
|
|
|
|
|
+ public void templateTaskMonth() throws NoSuchAlgorithmException, 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));
|
|
@@ -169,9 +210,14 @@ public class ReportTemplateTaskService {
|
|
|
for (KwsReportTemplate kwsReportTemplate : kwsReportTemplates) {
|
|
for (KwsReportTemplate kwsReportTemplate : kwsReportTemplates) {
|
|
|
Integer type = kwsReportTemplate.getType();
|
|
Integer type = kwsReportTemplate.getType();
|
|
|
if (ReportTypeEnum.MONTH.getCode() == type) {
|
|
if (ReportTypeEnum.MONTH.getCode() == type) {
|
|
|
-
|
|
|
|
|
|
|
+ LocalDateTime localDateTime = LocalDateTime.now().minusDays(30);
|
|
|
|
|
+ LocalDateTime dateEnd = com.sckw.excel.utils.DateUtil.localDateToLocalDateTimeEnd(localDateTime.toLocalDate());
|
|
|
|
|
+ LocalDateTime dateStart = com.sckw.excel.utils.DateUtil.localDateToLocalDateTimeStart(localDateTime.toLocalDate());
|
|
|
|
|
+ String date1 = dateStart.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
|
|
|
|
|
+ String date2 = dateEnd.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
|
|
|
|
|
+ report(kwsReportTemplate,date1,date2);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- }*/
|
|
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|