|
|
@@ -26,6 +26,7 @@ import org.springframework.scheduling.annotation.EnableScheduling;
|
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
+
|
|
|
import java.io.IOException;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.net.MalformedURLException;
|
|
|
@@ -62,52 +63,48 @@ public class ReportTemplateTaskService {
|
|
|
@Autowired
|
|
|
SlopeDataMapper slopeDataMapper;
|
|
|
|
|
|
- public void report(KwsReportTemplate kwsReportTemplate,String date1,String date2) throws NoSuchAlgorithmException, IOException {
|
|
|
+ public void report(KwsReportTemplate kwsReportTemplate, String date1, String date2) throws NoSuchAlgorithmException, IOException {
|
|
|
|
|
|
- String[] title = "推送时间".split(",");
|
|
|
+ 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));
|
|
|
+ //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<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) -> {
|
|
|
+ for (List<SlopeData> value : map.values()) {
|
|
|
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("");
|
|
|
+ listObject.add(sdf.format(value.get(0).getTs()));
|
|
|
+ for (int i = 1; i < list.size(); i++) {
|
|
|
+ for (SlopeData slopeData : value) {
|
|
|
+ if (slopeData.getLine().equals(list.get(i))) {
|
|
|
+ listObject.add(slopeData.getVal());
|
|
|
}
|
|
|
}
|
|
|
- });
|
|
|
+ }
|
|
|
list1.add(listObject);
|
|
|
- });
|
|
|
+ }
|
|
|
|
|
|
- map1.put(vo.getName(),list1);
|
|
|
+ map1.put(vo.getName(), list1);
|
|
|
}
|
|
|
}
|
|
|
ExcelContext excelContext = TaskReportExportVO.class.getAnnotation(ExcelContext.class);
|
|
|
- if(devices.size()>0) {
|
|
|
+ if (devices.size() > 0) {
|
|
|
String md5 = returnMd5();
|
|
|
- String filePath = ExcelUtil.taskExportByExcelUploadingToOss(map1,devices, md5 + ".xlsx", TaskReportExportVO.class,list);
|
|
|
+ String filePath = ExcelUtil.taskExportByExcelUploadingToOss(map1, devices, md5 + ".xlsx", TaskReportExportVO.class, list);
|
|
|
//生成的日报新增到kws_report_data
|
|
|
URL url = new URL(filePath);
|
|
|
URLConnection connection = url.openConnection();
|
|
|
@@ -131,7 +128,7 @@ public class ReportTemplateTaskService {
|
|
|
/**
|
|
|
* 报表生成定时任务-天
|
|
|
*/
|
|
|
- //@Scheduled(cron = "* * * * * *")
|
|
|
+ // @Scheduled(cron = "* * * * * *")
|
|
|
public void templateTaskDay() throws IOException, NoSuchAlgorithmException {
|
|
|
List<KwsReportTemplate> kwsReportTemplates = reportTemplateMapper.selectList(new LambdaQueryWrapper<KwsReportTemplate>()
|
|
|
.eq(KwsReportTemplate::getStatus, 0)
|
|
|
@@ -145,11 +142,12 @@ 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"));
|
|
|
- report(kwsReportTemplate,date1,date2);
|
|
|
+ report(kwsReportTemplate, date1, date2);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
public String returnMd5() throws NoSuchAlgorithmException {
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
String currentTime = sdf.format(new Date());
|
|
|
@@ -192,7 +190,7 @@ 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"));
|
|
|
- report(kwsReportTemplate,date1,date2);
|
|
|
+ report(kwsReportTemplate, date1, date2);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -215,7 +213,7 @@ 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"));
|
|
|
- report(kwsReportTemplate,date1,date2);
|
|
|
+ report(kwsReportTemplate, date1, date2);
|
|
|
}
|
|
|
}
|
|
|
}
|