Переглянути джерело

灯控数量统计数据概览

zhj 9 місяців тому
батько
коміт
f8b09fa70c

+ 15 - 1
src/main/java/com/welampiot/controller/LampController.java

@@ -35,7 +35,7 @@ import java.util.stream.Collectors;
 @RestController
 @CrossOrigin
 @RequestMapping("/lamp")
-public class LampController {
+public class LampController extends BaseController {
     @Autowired
     private LampService lampService;
     @Autowired
@@ -1849,4 +1849,18 @@ public class LampController {
         LampLogVO lampLogVO = lampInfoLogService.getMonthLightTimeLogList(lampVO.getId());
         return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS, version, lampLogVO);
     }
+
+    /**
+     * 灯控数量统计
+     */
+    @RequestMapping(value = "/lampSectionCounts", method = RequestMethod.POST)
+    public BaseResult<?> lampSectionCounts(BaseVO baseVO) {
+        Integer version = baseVO.getVersion();
+        List<Integer> sectionList = getSectionList(baseVO.getUsername());
+        baseVO.setSectionList(sectionList);
+        SectionDTO lampCounts = sectionService.getSectionLampCountsByBaseVO(baseVO);
+        Integer lampPoleCount = networkService.getLampPoleCountByBaseVO(baseVO);
+        lampCounts.setLampPoleCount(lampPoleCount);
+        return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS, version, lampCounts);
+    }
 }

+ 2 - 0
src/main/java/com/welampiot/dao/NetworkDao.java

@@ -1,6 +1,7 @@
 package com.welampiot.dao;
 
 import com.welampiot.dto.NetworkDTO;
+import com.welampiot.vo.BaseVO;
 import com.welampiot.vo.NetworkVO;
 import org.apache.ibatis.annotations.Param;
 
@@ -24,4 +25,5 @@ public interface NetworkDao {
     void updateSimDate(NetworkDTO dto);
     NetworkDTO getSimpleData(NetworkDTO dto);
     Integer getLoopNetworkCountByDTO(NetworkDTO dto);
+    Integer getLampPoleCountByBaseVO(BaseVO baseVO);
 }

+ 1 - 0
src/main/java/com/welampiot/dao/SectionDao.java

@@ -27,4 +27,5 @@ public interface SectionDao {
     void updateSectionById(SectionDTO dto);
     List<SectionDTO> getSectionLampCountsListByBaseVO(BaseVO baseVO);
     Integer getSectionAllCountByBaseVO(BaseVO baseVO);
+    SectionDTO getSectionLampCountsByBaseVO(BaseVO baseVO);
 }

+ 1 - 0
src/main/java/com/welampiot/dto/SectionDTO.java

@@ -73,6 +73,7 @@ public class SectionDTO implements Serializable {
 
     private Integer lampTotal;
     private Integer lampOnlineCount;
+    private Integer lampOfflineCount;
     private Integer lampLightCount;
     private Integer lampAlarmCount;
 

+ 2 - 0
src/main/java/com/welampiot/service/NetworkService.java

@@ -1,6 +1,7 @@
 package com.welampiot.service;
 
 import com.welampiot.dto.NetworkDTO;
+import com.welampiot.vo.BaseVO;
 import com.welampiot.vo.NetworkVO;
 
 import java.util.List;
@@ -23,4 +24,5 @@ public interface NetworkService {
     void updateSimDate(NetworkDTO dto);
     NetworkDTO getSimpleData(NetworkDTO dto);
     Integer getLoopNetworkCountByDTO(NetworkDTO dto);
+    Integer getLampPoleCountByBaseVO(BaseVO baseVO);
 }

+ 1 - 0
src/main/java/com/welampiot/service/SectionService.java

@@ -28,4 +28,5 @@ public interface SectionService {
     void updateSectionById(SectionDTO dto);
     List<SectionDTO> getSectionLampCountsListByBaseVO(BaseVO baseVO);
     Integer getSectionAllCountByBaseVO(BaseVO baseVO);
+    SectionDTO getSectionLampCountsByBaseVO(BaseVO baseVO);
 }

+ 6 - 0
src/main/java/com/welampiot/service/impl/NetworkServiceImpl.java

@@ -3,6 +3,7 @@ package com.welampiot.service.impl;
 import com.welampiot.dao.NetworkDao;
 import com.welampiot.dto.NetworkDTO;
 import com.welampiot.service.NetworkService;
+import com.welampiot.vo.BaseVO;
 import com.welampiot.vo.NetworkVO;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -173,4 +174,9 @@ public class NetworkServiceImpl implements NetworkService {
     public Integer getLoopNetworkCountByDTO(NetworkDTO dto) {
         return networkDao.getLoopNetworkCountByDTO(dto);
     }
+
+    @Override
+    public Integer getLampPoleCountByBaseVO(BaseVO baseVO) {
+        return networkDao.getLampPoleCountByBaseVO(baseVO);
+    }
 }

+ 5 - 0
src/main/java/com/welampiot/service/impl/SectionServiceImpl.java

@@ -96,4 +96,9 @@ public class SectionServiceImpl implements SectionService {
     public Integer getSectionAllCountByBaseVO(BaseVO baseVO) {
         return sectionDao.getSectionAllCountByBaseVO(baseVO);
     }
+
+    @Override
+    public SectionDTO getSectionLampCountsByBaseVO(BaseVO baseVO) {
+        return sectionDao.getSectionLampCountsByBaseVO(baseVO);
+    }
 }

+ 32 - 0
src/main/resources/mapper/NetworkMapper.xml

@@ -416,4 +416,36 @@
              ) b
     </select>
 
+    <select id="getLampPoleCountByBaseVO" resultType="Integer">
+        SELECT COUNT(*)
+        FROM network n
+        LEFT JOIN global_location a ON a.id = n.areaid
+        LEFT JOIN global_location b ON b.id = a.pid
+        LEFT JOIN global_location c ON c.id = a.pid
+        WHERE n.net_type = 1
+          AND (
+                  SELECT COUNT(*)
+                  FROM lampinfo l
+                  WHERE l.networkid = n.id
+              ) > 0
+        <if test="sectionId != null and sectionId != 0">
+            and n.sectionid = #{sectionId}
+        </if>
+        <if test="areaId != null and areaId != 0">
+            and n.areaid = #{areaId}
+        </if>
+        <if test="cityId != null and cityId != 0">
+            and b.id = #{cityId}
+        </if>
+        <if test="provinceId != null and provinceId != 0">
+            and c.id = #{provinceId}
+        </if>
+        <if test="sectionList != null and !sectionList.isEmpty()">
+            and n.sectionid in
+            <foreach collection="sectionList" item="item" open="(" separator="," close=")">
+                #{item}
+            </foreach>
+        </if>
+    </select>
+
 </mapper>

+ 35 - 0
src/main/resources/mapper/SectionMapper.xml

@@ -213,4 +213,39 @@
         </if>
     </select>
 
+    <select id="getSectionLampCountsByBaseVO" resultType="SectionDTO">
+        SELECT
+        COALESCE(COUNT(l.id), 0) AS lampTotal,
+        COALESCE(SUM(IF(l.online = 1, 1, 0)), 0) AS lampOnlineCount,
+        COALESCE(SUM(IF(l.online = 0, 1, 0)), 0) AS lampOfflineCount,
+        COALESCE(SUM(IF(l.online = 1 AND l.lighteness > 0, 1, 0)), 0) AS lampLightCount,
+        COALESCE(SUM(IF(l.online = 1 AND l.faultstatus != 0 AND l.faultstatus != 128, 1, 0)), 0) AS lampAlarmCount
+        FROM
+        section s
+        LEFT JOIN lampinfo l ON s.id = l.sectionid
+        LEFT JOIN global_location a ON a.id = s.pid
+        LEFT JOIN global_location b ON b.id = a.pid
+        LEFT JOIN global_location c ON c.id = b.pid
+        WHERE
+        1=1
+        <if test="sectionList != null and !sectionList.isEmpty()">
+            AND s.id IN
+            <foreach collection="sectionList" item="item" open="(" separator="," close=")">
+                #{item}
+            </foreach>
+        </if>
+        <if test="provinceId != null and provinceId != 0">
+            AND c.id = #{provinceId}
+        </if>
+        <if test="cityId != null and cityId != 0">
+            AND b.id = #{cityId}
+        </if>
+        <if test="areaId != null and areaId != 0">
+            AND a.id = #{areaId}
+        </if>
+        <if test="sectionId != null and sectionId != 0">
+            AND s.id = #{sectionId}
+        </if>
+    </select>
+
 </mapper>