|
|
@@ -22,8 +22,9 @@ 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.security.MessageDigest;
|
|
|
import java.io.IOException;
|
|
|
+import java.security.NoSuchAlgorithmException;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.time.ZoneId;
|
|
|
@@ -51,8 +52,8 @@ public class ReportTemplateTaskService {
|
|
|
/**
|
|
|
* 报表生成定时任务-天
|
|
|
*/
|
|
|
- @Scheduled(cron = "* * * * * *")
|
|
|
- public void templateTaskDay() throws IOException {
|
|
|
+ //@Scheduled(cron = "* * * * * *")
|
|
|
+ public void templateTaskDay() throws IOException, NoSuchAlgorithmException {
|
|
|
List<KwsReportTemplate> kwsReportTemplates = reportTemplateMapper.selectList(new LambdaQueryWrapper<KwsReportTemplate>()
|
|
|
.eq(KwsReportTemplate::getStatus, 0)
|
|
|
.eq(KwsReportTemplate::getDelFlag, 0));
|
|
|
@@ -65,46 +66,80 @@ public class ReportTemplateTaskService {
|
|
|
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"));
|
|
|
+ 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<String> deviceName = new ArrayList<>();
|
|
|
- Map<String,Object> deviceData = new HashMap<>();
|
|
|
+ //List<Object> deviceName = new ArrayList<>();
|
|
|
+ List<Map<String,Object>> deviceData = new ArrayList<>();
|
|
|
+ Map<String,List<Object>> map1 = 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));
|
|
|
|
|
|
List<Object> list1 = new ArrayList<>();
|
|
|
map.forEach((key,value) -> {
|
|
|
- Map<Object,Object> mapdata = new HashMap<>();
|
|
|
+ //Map<Object,Object> mapdata = new HashMap<>();
|
|
|
+ List<Object> listObject = new ArrayList<>();
|
|
|
value.forEach(valuetemp->{
|
|
|
- mapdata.put("ts",valuetemp.getMsgId());
|
|
|
+ //mapdata.put("ts",valuetemp.getMsgId());
|
|
|
+ listObject.add(sdf.format(valuetemp.getTs()));
|
|
|
for (int i = 0;i< list.size();i++){
|
|
|
- mapdata.put(valuetemp.getLine(),valuetemp.getVal());
|
|
|
+ if(valuetemp.getLine().equals(list.get(i))){
|
|
|
+ listObject.add(valuetemp.getVal());
|
|
|
+ }else{
|
|
|
+ listObject.add("");
|
|
|
+ }
|
|
|
}
|
|
|
});
|
|
|
- list1.add(mapdata);
|
|
|
+ list1.add(listObject);
|
|
|
});
|
|
|
- deviceData.put(vo.getName(),list1);
|
|
|
- //deviceData.add(list1);
|
|
|
+ //deviceData.put(vo.getName(),list1);
|
|
|
+ //deviceName.add(list1);
|
|
|
+ map1.put(vo.getName(),list1);
|
|
|
}
|
|
|
}
|
|
|
ExcelContext excelContext = TaskReportExportVO.class.getAnnotation(ExcelContext.class);
|
|
|
if(Objects.nonNull(devices)) {
|
|
|
- String filePath = ExcelUtil.taskExportByExcelUploadingToOss(deviceData,devices, excelContext.fileName() + ".xlsx", TaskReportExportVO.class);
|
|
|
+ String md5 = returnMd5();
|
|
|
+ String filePath = ExcelUtil.taskExportByExcelUploadingToOss(map1,devices, md5 + ".xlsx", TaskReportExportVO.class,list);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ public String returnMd5() throws NoSuchAlgorithmException {
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
+ String currentTime = sdf.format(new Date());
|
|
|
+
|
|
|
+ // 将当前时间转换为字节数组
|
|
|
+ byte[] bytes = currentTime.getBytes();
|
|
|
+
|
|
|
+ // 创建 MD5 对象
|
|
|
+ MessageDigest md = MessageDigest.getInstance("MD5");
|
|
|
+
|
|
|
+ // 计算 MD5 值
|
|
|
+ byte[] md5Bytes = md.digest(bytes);
|
|
|
+
|
|
|
+ // 将 MD5 值转换为十六进制字符串
|
|
|
+ StringBuilder sb = new StringBuilder();
|
|
|
+ for (byte b : md5Bytes) {
|
|
|
+ String hex = Integer.toHexString(b & 0xFF);
|
|
|
+ if (hex.length() == 1) {
|
|
|
+ sb.append('0');
|
|
|
+ }
|
|
|
+ sb.append(hex);
|
|
|
+ }
|
|
|
+ return sb.toString();
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* 报表生成定时任务-周
|