浏览代码

+ 大屏接口研发,《设备》

chen.cheng 10 月之前
父节点
当前提交
47b566bfff

+ 41 - 16
ems-cloud/ems-modules/ems-server/src/main/java/com/ruoyi/ems/controller/DeviceController.java

@@ -1,5 +1,23 @@
 package com.ruoyi.ems.controller;
 
+import java.util.List;
+import java.util.stream.Collectors;
+
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.commons.collections4.CollectionUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.DeleteMapping;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.PutMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
+
 import com.ruoyi.common.core.utils.poi.ExcelUtil;
 import com.ruoyi.common.core.web.controller.BaseController;
 import com.ruoyi.common.core.web.domain.AjaxResult;
@@ -15,23 +33,8 @@ import com.ruoyi.ems.domain.vo.QueryDevice;
 import com.ruoyi.ems.service.IAreaBuildingService;
 import com.ruoyi.ems.service.IAreaBuildingZoningService;
 import com.ruoyi.ems.service.IEmsDeviceService;
-import io.swagger.annotations.Api;
-import org.apache.commons.collections4.CollectionUtils;
-import org.apache.commons.lang3.StringUtils;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.DeleteMapping;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.PathVariable;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.PutMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestParam;
-import org.springframework.web.bind.annotation.RestController;
 
-import javax.servlet.http.HttpServletResponse;
-import java.util.List;
-import java.util.stream.Collectors;
+import io.swagger.annotations.Api;
 
 /**
  * 能源设备Controller
@@ -162,4 +165,26 @@ public class DeviceController extends BaseController {
     public AjaxResult remove(@PathVariable Long[] ids) {
         return toAjax(deviceService.deleteEmsDeviceByIds(ids));
     }
+
+    /**
+     * 设备-设备状态统计
+     *
+     * @param areaCode
+     * @return
+     */
+    @GetMapping(value = "/status/cnt")
+    public AjaxResult getDeviceStatusCnt(@RequestParam("areaCode") String areaCode) {
+        return success(deviceService.cntDeviceStatus(areaCode));
+    }
+
+    /**
+     * 设备-类型在线率
+     *
+     * @param areaCode
+     * @return
+     */
+    @GetMapping(value = "/type/online")
+    public AjaxResult getDeviceOnlineSummary(@RequestParam("areaCode") String areaCode) {
+        return success(deviceService.calcDeviceOnlineSummary(areaCode));
+    }
 }

+ 8 - 1
ems-cloud/ems-modules/ems-server/src/main/java/com/ruoyi/ems/mapper/EmsDeviceMapper.java

@@ -1,6 +1,7 @@
 package com.ruoyi.ems.mapper;
 
 import java.util.List;
+import java.util.Map;
 
 import org.apache.ibatis.annotations.Param;
 
@@ -24,6 +25,7 @@ public interface EmsDeviceMapper {
 
     /**
      * 查询能源设备
+     *
      * @param code 能源设备编码
      * @return 能源设备
      */
@@ -39,6 +41,7 @@ public interface EmsDeviceMapper {
 
     /**
      * 根据区域树递归查询设备
+     *
      * @param queryDevice 条件
      * @return 设备列表
      */
@@ -76,5 +79,9 @@ public interface EmsDeviceMapper {
      */
     int deleteEmsDeviceByIds(Long[] ids);
 
-    String selectDevicePath(@Param("areaType") String areaType, @Param("refArea") String areaCode);
+    String selectDevicePath(@Param("areaType") String areaType, @Param("refArea") String refArea);
+
+    List<Map<String, Object>> cntDeviceStatus(@Param("areaCode") String areaCode);
+
+    List<Map<String, Object>> calcDeviceOnlineSummary(@Param("areaCode") String areaCode);
 }

+ 5 - 0
ems-cloud/ems-modules/ems-server/src/main/java/com/ruoyi/ems/service/IEmsDeviceService.java

@@ -1,6 +1,7 @@
 package com.ruoyi.ems.service;
 
 import java.util.List;
+import java.util.Map;
 
 import com.ruoyi.ems.domain.EmsDevice;
 import com.ruoyi.ems.domain.vo.QueryDevice;
@@ -82,4 +83,8 @@ public interface IEmsDeviceService {
      * @return 结果
      */
     int deleteEmsDeviceById(Long id);
+
+    List<Map<String, Object>> cntDeviceStatus(String areaCode);
+
+    List<Map<String, Object>> calcDeviceOnlineSummary(String areaCode);
 }

+ 25 - 15
ems-cloud/ems-modules/ems-server/src/main/java/com/ruoyi/ems/service/impl/EmsDeviceServiceImpl.java

@@ -1,5 +1,16 @@
 package com.ruoyi.ems.service.impl;
 
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+
+import org.apache.commons.collections4.CollectionUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
 import com.ruoyi.common.core.utils.DateUtils;
 import com.ruoyi.ems.domain.Area;
 import com.ruoyi.ems.domain.AreaBuilding;
@@ -15,16 +26,6 @@ import com.ruoyi.ems.service.IAreaBuildingZoningService;
 import com.ruoyi.ems.service.IAreaService;
 import com.ruoyi.ems.service.IEmsDeviceService;
 import com.ruoyi.ems.service.IEmsFacsService;
-import org.apache.commons.collections4.CollectionUtils;
-import org.apache.commons.lang3.StringUtils;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Service;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.function.Function;
-import java.util.stream.Collectors;
 
 /**
  * 能源设备Service业务层处理
@@ -189,13 +190,12 @@ public class EmsDeviceServiceImpl implements IEmsDeviceService {
                 else if (StringUtils.equals(AreaTier.Zoning.name(), device.getAreaType())) {
                     AreaBuildingZoning zoning = zoningMap.get(device.getRefArea());
                     AreaBuilding building = zoning != null ? buildingMap.get(zoning.getBldgCode()) : null;
-                    namePrefix = (building != null ? building.getBldgName() : "") + "/" + (zoning != null ?
-                        zoning.getZoningName() : "");
+                    namePrefix = (building != null ? building.getBldgName() : "") + "/"
+                        + (zoning != null ? zoning.getZoningName() : "");
                 }
 
-                String label = StringUtils.isNotBlank(namePrefix) ?
-                    namePrefix + " - " + device.getDeviceName() :
-                    device.getDeviceName();
+                String label = StringUtils.isNotBlank(namePrefix) ? namePrefix + " - " + device.getDeviceName()
+                    : device.getDeviceName();
 
                 TreeEntity entity = new TreeEntity();
                 entity.setId(device.getDeviceCode());
@@ -314,4 +314,14 @@ public class EmsDeviceServiceImpl implements IEmsDeviceService {
             }
         }
     }
+
+    @Override
+    public List<Map<String, Object>> cntDeviceStatus(String areaCode) {
+        return emsDeviceMapper.cntDeviceStatus(areaCode);
+    }
+
+    @Override
+    public List<Map<String, Object>> calcDeviceOnlineSummary(String areaCode) {
+        return emsDeviceMapper.calcDeviceOnlineSummary(areaCode);
+    }
 }

+ 33 - 0
ems-cloud/ems-modules/ems-server/src/main/resources/mapper/ems/EmsDeviceMapper.xml

@@ -185,4 +185,37 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         </where>
         limit 1
     </select>
+    <select id="cntDeviceStatus">
+        SELECT
+        device_status deviceStatus,
+        count( id ) cnt
+        FROM
+        adm_ems_device
+        <where>
+            <if test="areaCode !=null and areaCode!=''">
+                area_ancestors like CONCAT('%',#{areaCode},'%')
+            </if>
+        </where>
+        GROUP BY
+        device_status
+    </select>
+
+    <select id="calcDeviceOnlineSummary">
+        SELECT
+            device_status  deviceStatus,
+            devcType.type_name typeName,
+            count( devc.id ) total,
+            SUM( CASE WHEN device_status = '0' THEN 1 ELSE 0 END ) AS onlineCount
+        FROM
+            adm_ems_device devc
+                INNER JOIN dim_devc_type devcType ON devc.device_type = devcType.type_code
+        <where>
+            <if test="areaCode !=null and areaCode!=''">
+                area_ancestors like CONCAT('%',#{areaCode},'%')
+            </if>
+        </where>
+        GROUP BY
+            device_type
+    </select>
+
 </mapper>