Selaa lähdekoodia

Merge branch 'usky-zyj' of uskycloud/usky-modules into server-165

James 1 vuosi sitten
vanhempi
commit
897a94a6ce

+ 23 - 0
service-park/service-park-biz/src/main/java/com/usky/park/controller/web/DmpDeviceController.java

@@ -3,9 +3,11 @@ package com.usky.park.controller.web;
 
 import com.usky.common.core.bean.ApiResult;
 import com.usky.common.core.bean.CommonPage;
+import com.usky.common.core.utils.poi.ExcelUtil;
 import com.usky.park.domain.DataRealTime;
 import com.usky.park.service.DataRealTimeService;
 import com.usky.park.service.DmpDeviceService;
+import com.usky.park.service.vo.DeviceHistoryDataExportVO;
 import com.usky.park.service.vo.DmpDeviceVO;
 import com.usky.park.service.vo.HistoryAttributeVO;
 import org.bouncycastle.cert.ocsp.Req;
@@ -17,6 +19,8 @@ import org.springframework.stereotype.Controller;
 import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
 
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
 import java.util.List;
 import java.util.Map;
 
@@ -84,6 +88,25 @@ public class DmpDeviceController {
         return ApiResult.success(deviceService.deviceCurrentDataList(deviceName,installAddress,deviceType,switchStatus,pageNum,pageSize));
     }
 
+    /**
+     * 数据中心-设备历史数据全量导出
+     *
+     * @param deviceType  设备类型(501、监控系统  502、门禁系统  503、梯控系统  504、机房系统  509、环境系统  510、照明系统)
+     * @param startDate  开始时间  格式 yyyy-MM-dd HH:mm:ss
+     * @param endDate  结束时间  格式 yyyy-MM-dd HH:mm:ss
+     * @return
+     */
+    @GetMapping("deviceHistoryDataListExport")
+    void deviceHistoryDataListExport(@RequestParam(value = "deviceType") Integer deviceType,
+                                                                           @RequestParam(value = "startDate") String startDate,
+                                                                           @RequestParam(value = "endDate") String endDate, HttpServletResponse response) throws IOException {
+        String name = "环境设备_"+startDate.substring(0,10)+"_"+endDate.substring(0,10);
+        List<DeviceHistoryDataExportVO> list = deviceService.deviceHistoryDataListExport(deviceType,startDate,endDate);
+        ExcelUtil<DeviceHistoryDataExportVO> util = new ExcelUtil<DeviceHistoryDataExportVO>(DeviceHistoryDataExportVO.class);
+        util.exportExcel(response,list,name,name);
+    }
+
+
     /**
      * 数据中心-机房系统、环境系统、照明系统心跳历史数据列表查询接口
      *

+ 5 - 1
service-park/service-park-biz/src/main/java/com/usky/park/mapper/DmpDeviceMapper.java

@@ -2,6 +2,10 @@ package com.usky.park.mapper;
 
 import com.usky.park.domain.DmpDevice;
 import com.usky.common.mybatis.core.CrudMapper;
+import com.usky.park.service.vo.DeviceDataHistoryMiddleVO;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
 
 /**
  * <p>
@@ -12,5 +16,5 @@ import com.usky.common.mybatis.core.CrudMapper;
  * @since 2023-03-30
  */
 public interface DmpDeviceMapper extends CrudMapper<DmpDevice> {
-
+    List<DeviceDataHistoryMiddleVO> QueryDeviceHistoryData(@Param("tableName") String tableName, @Param("startDate") String startDate, @Param("endDate") String endDate);
 }

+ 5 - 0
service-park/service-park-biz/src/main/java/com/usky/park/service/DmpDeviceService.java

@@ -3,6 +3,7 @@ package com.usky.park.service;
 import com.usky.common.core.bean.CommonPage;
 import com.usky.park.domain.DmpDevice;
 import com.usky.common.mybatis.core.CrudService;
+import com.usky.park.service.vo.DeviceHistoryDataExportVO;
 import com.usky.park.service.vo.DmpDeviceVO;
 import com.usky.park.service.vo.HistoryAttributeVO;
 
@@ -47,6 +48,10 @@ public interface DmpDeviceService extends CrudService<DmpDevice> {
      */
     CommonPage<Object> deviceCurrentDataList(String deviceName,String installAddress,Integer deviceType,Integer switchStatus,Integer pageNum,Integer pageSize);
 
+
+    List<DeviceHistoryDataExportVO> deviceHistoryDataListExport(Integer deviceType, String startDate, String endDate);
+
+
     /**
      * 数据中心-机房系统、环境系统、照明系统心跳历史数据列表查询接口
      *

+ 74 - 7
service-park/service-park-biz/src/main/java/com/usky/park/service/impl/DmpDeviceServiceImpl.java

@@ -16,9 +16,7 @@ import com.usky.park.service.DataLgHistoryService;
 import com.usky.park.mapper.DmpDeviceMapper;
 import com.usky.park.service.*;
 import com.usky.common.mybatis.core.AbstractCrudService;
-import com.usky.park.service.vo.DmpDeviceVO;
-import com.usky.park.service.vo.HistoryAttributeVO;
-import com.usky.park.service.vo.KeyValueVO;
+import com.usky.park.service.vo.*;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
@@ -201,6 +199,7 @@ public class DmpDeviceServiceImpl extends AbstractCrudService<DmpDeviceMapper, D
                 dataRealList = dataRealTimeService.list(queryWrapper1);
                 if(dataRealList.size()>0){
                     Boolean found = true;
+                    boolean exist = false;
                     for(int j=0;j<dataRealList.size();j++){
                         map.put(dataRealList.get(j).getAttributeName(),dataRealList.get(j).getAttributeData());
                         map.put(dataRealList.get(j).getAttributeName()+"Time",dataRealList.get(j).getDataTime());
@@ -209,13 +208,18 @@ public class DmpDeviceServiceImpl extends AbstractCrudService<DmpDeviceMapper, D
                                 found = false;
                             }
                         }
+                        if(-50 == Integer.valueOf(dataRealList.get(j).getAttributeData())){
+                            exist = true;
+                        }
                     }
-                    if(deviceType == 510){
-                        if(found){
+                    if(!exist){
+                        if(deviceType == 510){
+                            if(found){
+                                list.add(map);
+                            }
+                        }else{
                             list.add(map);
                         }
-                    }else{
-                        list.add(map);
                     }
                 }
 
@@ -240,6 +244,69 @@ public class DmpDeviceServiceImpl extends AbstractCrudService<DmpDeviceMapper, D
         return new CommonPage<>(objectList,total,pageNum,pageSize);
     }
 
+    public List<DeviceHistoryDataExportVO> deviceHistoryDataListExport(Integer deviceType, String startDate, String endDate){
+        List<DeviceHistoryDataExportVO> list = new ArrayList<>();
+
+        String tableName = "data_"+"ev"+"_history";
+
+        List<DeviceDataHistoryMiddleVO> list1 = new ArrayList<>();
+        list1 = baseMapper.QueryDeviceHistoryData(tableName,startDate,endDate);
+
+        if(CollectionUtils.isNotEmpty(list1)){
+            List<String> dateList = new ArrayList<>();
+            List<String> deviceIdList = new ArrayList<>();
+            for(int i=0;i<list1.size();i++){
+                if(!dateList.contains(list1.get(i).getDataDate())){
+                    dateList.add(list1.get(i).getDataDate());
+                }
+                if(!deviceIdList.contains(list1.get(i).getDeviceId())){
+                    deviceIdList.add(list1.get(i).getDeviceId());
+                }
+            }
+            if(CollectionUtils.isNotEmpty(dateList) && CollectionUtils.isNotEmpty(deviceIdList)){
+                for(int i=0;i<deviceIdList.size();i++){
+                    for(int j=0;j<dateList.size();j++){
+                        DeviceHistoryDataExportVO responseVO = new DeviceHistoryDataExportVO();
+                        responseVO.setDeviceId(deviceIdList.get(i));
+                        responseVO.setDataDate(dateList.get(j));
+                        for(int k=0;k<list1.size();k++){
+                            if(deviceIdList.get(i).equals(list1.get(k).getDeviceId()) && dateList.get(j).equals(list1.get(k).getDataDate())){
+                                if(list1.get(k).getAttributeName().equals("wd")){
+                                    responseVO.setWd(list1.get(k).getAttributeData());
+                                }
+                                if(list1.get(k).getAttributeName().equals("sd")){
+                                    responseVO.setSd(list1.get(k).getAttributeData());
+                                }
+                                if(list1.get(k).getAttributeName().equals("co2")){
+                                    responseVO.setCo2(list1.get(k).getAttributeData());
+                                }
+                                if(list1.get(k).getAttributeName().equals("jq")){
+                                    responseVO.setJq(list1.get(k).getAttributeData());
+                                }
+                                if(list1.get(k).getAttributeName().equals("pm2.5")){
+                                    responseVO.setPm2_5(list1.get(k).getAttributeData());
+                                }
+                                if(list1.get(k).getAttributeName().equals("tvoc")){
+                                    responseVO.setTvoc(list1.get(k).getAttributeData());
+                                }
+                                if(list1.get(k).getAttributeName().equals("pm1.0")){
+                                    responseVO.setPm1_0(list1.get(k).getAttributeData());
+                                }
+                                if(list1.get(k).getAttributeName().equals("pm10")){
+                                    responseVO.setPm10(list1.get(k).getAttributeData());
+                                }
+                            }
+                        }
+                        list.add(responseVO);
+                    }
+                }
+            }
+        }
+
+        return list;
+
+    }
+
     public List<HistoryAttributeVO> deviceHistoryDataList(String deviceId, Integer deviceType, List<String> deviceAttribute, String startDate, String endDate){
         List<HistoryAttributeVO> list = new ArrayList<>();
         switch (deviceType){

+ 15 - 0
service-park/service-park-biz/src/main/java/com/usky/park/service/vo/DeviceDataHistoryMiddleVO.java

@@ -0,0 +1,15 @@
+package com.usky.park.service.vo;
+
+import lombok.Data;
+
+@Data
+public class DeviceDataHistoryMiddleVO {
+
+    private String deviceId;
+
+    private String dataDate;
+
+    private String attributeName;
+
+    private String attributeData;
+}

+ 68 - 0
service-park/service-park-biz/src/main/java/com/usky/park/service/vo/DeviceHistoryDataExportVO.java

@@ -0,0 +1,68 @@
+package com.usky.park.service.vo;
+
+import com.usky.common.core.annotation.Excel;
+import lombok.Data;
+
+@Data
+public class DeviceHistoryDataExportVO {
+
+    /**
+     * 设备Id
+     */
+    @Excel(name = "设备Id")
+    private String deviceId;
+
+    /**
+     * 数据时间
+     */
+    @Excel(name = "数据时间")
+    private String dataDate;
+
+    /**
+     * 温度
+     */
+    @Excel(name = "温度")
+    private String wd;
+
+    /**
+     * 湿度
+     */
+    @Excel(name = "湿度")
+    private String sd;
+
+    /**
+     * 二氧化碳
+     */
+    @Excel(name = "二氧化碳")
+    private String co2;
+
+    /**
+     * 甲醛
+     */
+    @Excel(name = "甲醛")
+    private String jq;
+
+    /**
+     * PM2.5
+     */
+    @Excel(name = "PM2.5")
+    private String pm2_5;
+
+    /**
+     * TVOC
+     */
+    @Excel(name = "TVOC")
+    private String tvoc;
+
+    /**
+     * PM1.0
+     */
+    @Excel(name = "PM1.0")
+    private String pm1_0;
+
+    /**
+     * PM10
+     */
+    @Excel(name = "PM10")
+    private String pm10;
+}

+ 7 - 0
service-park/service-park-biz/src/main/resources/mapper/park/DmpDeviceMapper.xml

@@ -24,5 +24,12 @@
         <result column="company_code" property="companyCode" />
         <result column="install_address" property="installAddress" />
     </resultMap>
+    <select id="QueryDeviceHistoryData" resultType="com.usky.park.service.vo.DeviceDataHistoryMiddleVO">
+        select device_id as deviceId, data_time as dataDate, attribute_name as attributeName, avg(attribute_data) as attributeData
+        FROM ${tableName}
+        WHERE data_time  BETWEEN  #{startDate} AND  #{endDate}
+        and attribute_data != 0 and attribute_data != -50
+        group by device_id,data_time,attribute_name;
+    </select>
 
 </mapper>