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

+ 4 - 0
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/model/dos/mysql/KwsReportData.java

@@ -24,6 +24,10 @@ public class KwsReportData implements Serializable {
      */
     private Long templateId;
 
+    /**
+     * 矿山id
+     */
+    private String mountainId;
     /**
      * 企业id
      */

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

@@ -38,35 +38,10 @@ public class TaskReportExportVO implements Serializable {
     /**
      * e
      */
-    @ExcelProperty("a")
-    private String a;
+    @ExcelProperty("high")
+    private String high;
 
-    /**
-     * e
-     */
-    @ExcelProperty("b")
-    private String b;
-
-    @ExcelProperty("c")
-    private String c;
-
-    @ExcelProperty("d")
-    private String d;
-
-    @ExcelProperty("e")
-    private String e;
-
-    @ExcelProperty("f")
-    private String f;
-
-    @ExcelProperty("g")
-    private String g;
-
-    @ExcelProperty("h")
-    private String h;
 
-    @ExcelProperty("j")
-    private String j;
 
 
 

+ 2 - 1
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/service/DeviceService.java

@@ -260,6 +260,7 @@ public class DeviceService {
                 .eq(KwsDeviceModel::getId, vo.getModelId()));
         if (deviceModel != null) {
             vo.setDeviceType(Integer.parseInt(deviceModel.getDeviceType()));
+            vo.setMName(deviceModel.getName());
             vo.setManufacturer(deviceModel.getManufacturer());
             vo.setManufacturerContacts(deviceModel.getManufacturerContacts());
             vo.setManufacturerPhone(deviceModel.getManufacturerPhone());
@@ -718,7 +719,7 @@ public class DeviceService {
 
             if (Objects.isNull(reference)) {
                 kwsDeviceReference.setOffset(zero);
-                kwsDeviceReference.setOriginalValue(zero);
+                kwsDeviceReference.setOriginalValue(value);
                 kwsDeviceReference.setCurrentValue(value);
             } else {
                 //如果有数据,则先删除原有数据。

+ 99 - 53
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/service/task/ReportTemplateTaskService.java

@@ -1,23 +1,36 @@
 package com.sckw.slope.detection.service.task;
 
 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.utils.IdWorker;
 import com.sckw.excel.annotation.ExcelContext;
 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.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.tdengine.SlopeData;
 import com.sckw.slope.detection.model.vo.DeviceVo;
 import com.sckw.slope.detection.model.vo.excel.TaskReportExportVO;
 import jakarta.annotation.Resource;
 import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 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;
+import java.net.URL;
+import java.net.URLConnection;
 import java.security.MessageDigest;
 import java.security.NoSuchAlgorithmException;
 import java.text.SimpleDateFormat;
@@ -43,9 +56,78 @@ public class ReportTemplateTaskService {
     @Resource
     KwsReportTemplateMapper reportTemplateMapper;
 
+    @Autowired
+    KwsReportDataMapper kwsReportDataMapper;
+
     @Autowired
     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());
                     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<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 ? * *")
-    /*public void templateTaskWeek() {
+    public void templateTaskWeek() throws NoSuchAlgorithmException, IOException {
         List<KwsReportTemplate> kwsReportTemplates = reportTemplateMapper.selectList(new LambdaQueryWrapper<KwsReportTemplate>()
                 .eq(KwsReportTemplate::getStatus, 0)
                 .eq(KwsReportTemplate::getDelFlag, 0));
@@ -149,19 +187,22 @@ public class ReportTemplateTaskService {
             for (KwsReportTemplate kwsReportTemplate : kwsReportTemplates) {
                 Integer type = kwsReportTemplate.getType();
                 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 ? * *")
-    /*public void templateTaskMonth() {
+    public void templateTaskMonth() throws NoSuchAlgorithmException, IOException {
         List<KwsReportTemplate> kwsReportTemplates = reportTemplateMapper.selectList(new LambdaQueryWrapper<KwsReportTemplate>()
                 .eq(KwsReportTemplate::getStatus, 0)
                 .eq(KwsReportTemplate::getDelFlag, 0));
@@ -169,9 +210,14 @@ public class ReportTemplateTaskService {
             for (KwsReportTemplate kwsReportTemplate : kwsReportTemplates) {
                 Integer type = kwsReportTemplate.getType();
                 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);
                 }
             }
         }
-    }*/
+    }
 }

+ 6 - 14
slope-modules/slope-detection/src/main/resources/mapper/mysql/KwsReportDataMapper.xml

@@ -49,20 +49,12 @@
   </delete>
   <insert id="insert" parameterType="com.sckw.slope.detection.model.dos.mysql.KwsReportData">
     <!--@mbg.generated-->
-    insert into kws_report_data (id, template_id, project_id, 
-      project_name, device_id, device_name, 
-      sn_code, `alias`, model_id, 
-      model_name, device_type, device_label, 
-      lat, lng, alt, alarm_type, 
-      alarm_title, content, items, 
-      alarm_time, create_time)
-    values (#{id,jdbcType=BIGINT}, #{templateId,jdbcType=BIGINT}, #{projectId,jdbcType=BIGINT}, 
-      #{projectName,jdbcType=VARCHAR}, #{deviceId,jdbcType=BIGINT}, #{deviceName,jdbcType=VARCHAR}, 
-      #{snCode,jdbcType=VARCHAR}, #{alias,jdbcType=VARCHAR}, #{modelId,jdbcType=BIGINT}, 
-      #{modelName,jdbcType=VARCHAR}, #{deviceType,jdbcType=VARCHAR}, #{deviceLabel,jdbcType=VARCHAR}, 
-      #{lat,jdbcType=VARCHAR}, #{lng,jdbcType=VARCHAR}, #{alt,jdbcType=VARCHAR}, #{alarmType,jdbcType=INTEGER}, 
-      #{alarmTitle,jdbcType=VARCHAR}, #{content,jdbcType=VARCHAR}, #{items,jdbcType=VARCHAR}, 
-      #{alarmTime,jdbcType=TIMESTAMP}, #{createTime,jdbcType=TIMESTAMP})
+    insert into kws_report_data (id,mountain_id,company_id, template_id, project_id,
+      project_name, file_size, file_url,create_time
+      )
+    values (#{id,jdbcType=BIGINT}, #{mountainId,jdbcType=BIGINT}, #{companyId,jdbcType=BIGINT},
+      #{templateId,jdbcType=VARCHAR}, #{projectId,jdbcType=BIGINT}, #{projectName,jdbcType=VARCHAR},
+      #{fileSize,jdbcType=VARCHAR}, #{fileUrl,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP})
   </insert>
   <insert id="insertSelective" parameterType="com.sckw.slope.detection.model.dos.mysql.KwsReportData">
     <!--@mbg.generated-->