zhj 2 лет назад
Родитель
Сommit
50677506a8

+ 5 - 3
src/main/java/com/welampiot/controller/ElectricBoxController.java

@@ -6,6 +6,7 @@ import com.welampiot.dto.ElectricBoxDTO;
 import com.welampiot.service.ElectricBoxService;
 import com.welampiot.utils.ToolUtils;
 import com.welampiot.vo.ElectricBoxRequestVO;
+import com.welampiot.vo.ElectricBoxReturnVO;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.CrossOrigin;
 import org.springframework.web.bind.annotation.PostMapping;
@@ -42,10 +43,10 @@ public class ElectricBoxController {
      */
     @PostMapping("/devList")
     public BaseResult<ElectricBoxDTO> devList(HttpServletRequest request){
-        Integer page = request.getParameter("page") == null ? 0 : Integer.parseInt(request.getParameter("page"));
+        Integer page = request.getParameter("page") == null ? 1 : Integer.parseInt(request.getParameter("page"));
         Integer count = request.getParameter("count") == null ? 16 : Integer.parseInt(request.getParameter("count"));
         Integer status = request.getParameter("status") == null ? 0 : Integer.parseInt(request.getParameter("status"));
-        String keyword = request.getParameter("keyword") == null ? "0" : request.getParameter("keyword");
+        String keyword = request.getParameter("keyword") == null ? "" : request.getParameter("keyword");
 
         ElectricBoxRequestVO vo = new ElectricBoxRequestVO();
         vo.setPage(count*(page-1));
@@ -54,7 +55,8 @@ public class ElectricBoxController {
         vo.setKeyword(keyword);
         vo.setSectionList(toolUtils.getSectionList(request));
 
-        List<ElectricBoxDTO> electricBoxList = electricBoxService.getElectricBoxListBySectionId(vo);
+        ElectricBoxReturnVO electricBoxList = electricBoxService.getElectricBoxListBySectionId(vo);
+        System.out.println(electricBoxList);
         return BaseResult.success(electricBoxList);
     }
 }

+ 6 - 0
src/main/java/com/welampiot/dao/ElectricBoxDao.java

@@ -17,4 +17,10 @@ import java.util.List;
  */
 public interface ElectricBoxDao {
     List<ElectricBoxDTO> getElectricBoxListBySectionId(ElectricBoxRequestVO vo);
+
+    Integer getTotalByStatus(ElectricBoxRequestVO vo);
+
+    Integer getOnlineTotalByStatus(ElectricBoxRequestVO vo);
+
+    Integer getOfflineTotalByStatus(ElectricBoxRequestVO vo);
 }

+ 8 - 1
src/main/java/com/welampiot/service/ElectricBoxService.java

@@ -2,6 +2,7 @@ package com.welampiot.service;
 
 import com.welampiot.dto.ElectricBoxDTO;
 import com.welampiot.vo.ElectricBoxRequestVO;
+import com.welampiot.vo.ElectricBoxReturnVO;
 
 import java.util.List;
 
@@ -15,5 +16,11 @@ import java.util.List;
  * @Version: v1.0
  */
 public interface ElectricBoxService {
-    List<ElectricBoxDTO> getElectricBoxListBySectionId(ElectricBoxRequestVO vo);
+    ElectricBoxReturnVO getElectricBoxListBySectionId(ElectricBoxRequestVO vo);
+
+    Integer getTotalByStatus(ElectricBoxRequestVO vo);
+
+    Integer getOnlineTotalByStatus(ElectricBoxRequestVO vo);
+
+    Integer getOfflineTotalByStatus(ElectricBoxRequestVO vo);
 }

+ 23 - 2
src/main/java/com/welampiot/service/impl/ElectricBoxServiceImpl.java

@@ -4,6 +4,7 @@ import com.welampiot.dao.ElectricBoxDao;
 import com.welampiot.dto.ElectricBoxDTO;
 import com.welampiot.service.ElectricBoxService;
 import com.welampiot.vo.ElectricBoxRequestVO;
+import com.welampiot.vo.ElectricBoxReturnVO;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
@@ -25,10 +26,30 @@ public class ElectricBoxServiceImpl implements ElectricBoxService {
     private ElectricBoxDao electricBoxDao;
 
     @Override
-    public List<ElectricBoxDTO> getElectricBoxListBySectionId(ElectricBoxRequestVO vo) {
+    public ElectricBoxReturnVO getElectricBoxListBySectionId(ElectricBoxRequestVO vo) {
+        ElectricBoxReturnVO electricBoxReturnVO = new ElectricBoxReturnVO();
 
+        electricBoxReturnVO.setTotal(electricBoxDao.getTotalByStatus(vo));
+        electricBoxReturnVO.setDevTotal(electricBoxDao.getTotalByStatus(vo));
+        electricBoxReturnVO.setOnlineTotal(electricBoxDao.getOnlineTotalByStatus(vo));
+        electricBoxReturnVO.setOfflineTotal(electricBoxDao.getOfflineTotalByStatus(vo));
+        electricBoxReturnVO.setElectricBoxList(electricBoxDao.getElectricBoxListBySectionId(vo));
 
+        return electricBoxReturnVO;
+    }
+
+    @Override
+    public Integer getTotalByStatus(ElectricBoxRequestVO vo) {
+        return electricBoxDao.getTotalByStatus(vo);
+    }
 
-        return electricBoxDao.getElectricBoxListBySectionId(vo);
+    @Override
+    public Integer getOnlineTotalByStatus(ElectricBoxRequestVO vo) {
+        return electricBoxDao.getOnlineTotalByStatus(vo);
+    }
+
+    @Override
+    public Integer getOfflineTotalByStatus(ElectricBoxRequestVO vo) {
+        return electricBoxDao.getOfflineTotalByStatus(vo);
     }
 }

+ 2 - 29
src/main/java/com/welampiot/vo/ElectricBoxReturnVO.java

@@ -4,6 +4,7 @@ import lombok.Data;
 
 import java.io.Serializable;
 import java.util.Date;
+import java.util.List;
 
 /**
  * ClassName: ElectricBoxReturnVO
@@ -28,35 +29,7 @@ public class ElectricBoxReturnVO implements Serializable {
     /** 离线数 **/
     private Integer offlineTotal;
 
-    /** 电箱id **/
-    private Integer id;
-
-    /** 电箱名称 **/
-    private String name;
-
-    /** 电箱地址 **/
-    private String address;
-
-    /** 空开个数 **/
-    private Integer airCount;
-
-    /** 经度 **/
-    private Float longitude;
-
-    /** 纬度 **/
-    private Float latitude;
-
-    /** 在线状态(0离线,1在线) **/
-    private Integer online;
-
-    /** 配电箱绑定的图片 **/
-    private String image;
-
-    /** 安装时间 **/
-    private Date installDate;
-
-    /** 过期时间 **/
-    private Date expirationDate;
+    private List electricBoxList;
 
     private static final long serialVersionUID = 1L;
 }

+ 49 - 3
src/main/resources/mapper/ElectricBoxMapper.xml

@@ -2,7 +2,7 @@
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.welampiot.dao.ElectricBoxDao">
 
-    <resultMap id="electricBoxAndSectionAndAirSwitchInfoResultMap" type="com.welampiot.dto.ElectricBoxDTO">
+    <resultMap id="electricBoxAndAirSwitchInfoResultMap" type="com.welampiot.dto.ElectricBoxDTO">
         <id property="id" column="id" jdbcType="INTEGER"/>
         <result property="name" column="name" jdbcType="VARCHAR"/>
         <result property="sectionId" column="sectionid" jdbcType="INTEGER"/>
@@ -22,7 +22,7 @@
         </collection>
     </resultMap>
 
-    <select id="getElectricBoxListBySectionId" resultMap="electricBoxAndSectionAndAirSwitchInfoResultMap" parameterType="com.welampiot.vo.ElectricBoxRequestVO">
+    <select id="getElectricBoxListBySectionId" resultMap="electricBoxAndAirSwitchInfoResultMap" parameterType="com.welampiot.vo.ElectricBoxRequestVO">
         select e.id,e.areaid areaId,e.sectionid sectionId,e.name,e.address,count(a.id) as airCount,a.online,
                e.longitude,e.latitude,e.image,e.install_date installDate,e.expiration_date expirationDate,
                (select count(*) from air_switch_info c where c.box_id = e.id and c.online = 1) as onlineCount
@@ -30,10 +30,18 @@
         where <if test="keyword != null and keyword != ''">
                     e.name like '%${keyword}%' or e.address like '%${keyword}%'
               </if>
+              <choose>
+                  <when test="status == 1">
+                     and (select count(*) from air_switch_info c where c.box_id = e.id and c.online = 1) > 0
+                  </when>
+                  <when test="status == 2">
+                     and (select count(*) from air_switch_info c where c.box_id = e.id and c.online = 1) = 0
+                  </when>
+              </choose>
             and <if test="sectionList != null and !sectionList.isEmpty()">
                     e.sectionid in
                     <foreach item="vo" collection="sectionList" open="(" separator="," close=")">
-                        #{vo.sectionId}
+                        #{vo}
                     </foreach>
                 </if>
             order by convert(e.name using gbk) asc,e.id desc
@@ -42,4 +50,42 @@
             </if>
     </select>
 
+    <select id="getTotalByStatus" resultMap="electricBoxAndAirSwitchInfoResultMap" parameterType="com.welampiot.vo.ElectricBoxRequestVO">
+        select count(*) as total
+        from (select e.id
+              from electric_box e
+                  left join air_switch_info a on e.id = a.box_id
+              where e.sectionid in
+                    <foreach item="vo" collection="sectionList" open="(" separator="," close=")">
+                        #{vo}
+                    </foreach>
+                    group by e.id) b
+    </select>
+
+    <select id="getOnlineTotalByStatus" resultMap="electricBoxAndAirSwitchInfoResultMap" parameterType="com.welampiot.vo.ElectricBoxRequestVO">
+        select count(*) as total
+        from (select e.id
+            from electric_box e
+            left join air_switch_info a on e.id = a.box_id
+            where e.sectionid in
+            <foreach item="vo" collection="sectionList" open="(" separator="," close=")">
+                #{vo}
+            </foreach>
+            and (select count(*) from air_switch_info c where c.box_id = e.id and c.online = 1) > 0
+            group by e.id) b
+    </select>
+
+    <select id="getOfflineTotalByStatus" resultMap="electricBoxAndAirSwitchInfoResultMap" parameterType="com.welampiot.vo.ElectricBoxRequestVO">
+        select count(*) as total
+        from (select e.id
+            from electric_box e
+            left join air_switch_info a on e.id = a.box_id
+            where e.sectionid in
+            <foreach item="vo" collection="sectionList" open="(" separator="," close=")">
+                #{vo}
+            </foreach>
+            and (select count(*) from air_switch_info c where c.box_id = e.id and c.online = 1) = 0
+            group by e.id) b
+    </select>
+
 </mapper>