15928045575 2 лет назад
Родитель
Сommit
0c091ab90a

+ 19 - 22
slope-common/slope-common-excel/src/main/java/com/sckw/excel/utils/ExcelUtil.java

@@ -528,9 +528,18 @@ public class ExcelUtil {
      * @param fileName   文件名字
      * @param excelClass 报表实体类的Class(根据该Class的属性来设置Excel的头属性)
      */
-    public static String taskExportByExcelUploadingToOss(Map<String,Object> listData,List<?> data, String fileName, Class<?> excelClass) throws IOException {
+    public static String taskExportByExcelUploadingToOss(Map<String,List<Object>> listData,List<?> data, String fileName, Class<?> excelClass,List<String> listHead) throws IOException {
+        List<List<String>> listTitle = new ArrayList<>();
+        //List<String> head = new ArrayList<>();
+        //head.add("ts");
+        //listTitle.add(head);
+        for(int k=0;k<listHead.size();k++){
+            List<String> head1 = new ArrayList<>();
+            head1.add(listHead.get(k));
+            listTitle.add(head1);
+        }
+        //listTitle.add(listHead);
         @Cleanup ByteArrayOutputStream os = new ByteArrayOutputStream();
-
         ExcelWriter excelWriter = com.alibaba.excel.EasyExcel.write(os, excelClass)
                 .autoCloseStream(Boolean.FALSE)
                 .registerConverter(new LongStringConverter())
@@ -538,41 +547,29 @@ public class ExcelUtil {
                 .registerWriteHandler(new RowWriteHandlerImpl())
                 // 自定义列宽、行高
                 .registerWriteHandler(new CustomCellWeightWeightConfig())
+                .head(listTitle)
 //                .registerWriteHandler(formatExcel())
                 .registerWriteHandler(new ExcelUtil.ExcelWidthStyleStrategy()).build();
+        List<List<Object>> list = new ArrayList<>();
 
         for (String key : listData.keySet()) {
             String sheetName = key;
-            Object getData = listData.get(key);
-            //List<Object> list = Arrays.asList(getData);
-            List<Object> list = new ArrayList<Object>();
-            if (getData instanceof ArrayList<?>) {
-                for (Object o : (List<?>) getData) {
-                    list.add(o);
-                }
-            }
-            // 把查询到的数据按设置的sheet的容量进行切割
-            List<? extends List<?>> lists = com.sckw.core.utils.StringUtils.splitList(list, PAGE_SIZE);
+            List<Object> getData = listData.get(key);
+
             ExcelWriterSheetBuilder excelWriterSheetBuilder;
             WriteSheet writeSheet;
-            //for (int i = 1; i <= lists.size(); ++i) {
-                excelWriterSheetBuilder = new ExcelWriterSheetBuilder(excelWriter);
-                excelWriterSheetBuilder.sheetName(sheetName);
-                writeSheet = excelWriterSheetBuilder.build();
-                excelWriter.write(list, writeSheet);
-            //}
+            excelWriterSheetBuilder = new ExcelWriterSheetBuilder(excelWriter);
+            excelWriterSheetBuilder.sheetName(sheetName);
+            writeSheet = excelWriterSheetBuilder.build();
+            excelWriter.write(getData, writeSheet);
 
         }
         // 必须要finish才会写入,不finish只会创建empty的文件
         excelWriter.finish();
         //String sheetName = excelClass.getAnnotation(ExcelContext.class).sheetName();
-
-
         byte[] content = os.toByteArray();
         @Cleanup InputStream is = new ByteArrayInputStream(content);
 
-
-
         // 文件上传到OSS
         Map<String, String> map = FileUtils.uploadFileByInfo(is, fileName, FileEnum.FILE_STORE_TYPE_ALIYUN);
         System.out.println(com.alibaba.fastjson2.JSONObject.toJSONString(map));

+ 12 - 0
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/model/vo/excel/TaskReportExportVO.java

@@ -35,6 +35,18 @@ public class TaskReportExportVO implements Serializable {
     @ExcelProperty("lat")
     private String lat;
 
+    /**
+     * e
+     */
+    @ExcelProperty("e")
+    private String e;
+
+    /**
+     * e
+     */
+    @ExcelProperty("n")
+    private String n;
+
 
     private static final long serialVersionUID = 1L;
 }

+ 48 - 13
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/service/task/ReportTemplateTaskService.java

@@ -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();
+    }
 
     /**
      * 报表生成定时任务-周