Browse Source

获取空开设备列表

zhj 2 years ago
parent
commit
8e762190fd

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

@@ -3,8 +3,10 @@ package com.welampiot.controller;
 import com.welampiot.common.BaseResult;
 import com.welampiot.dto.AirSwitchInfoDTO;
 import com.welampiot.dto.ElectricBoxDTO;
+import com.welampiot.service.AirSwitchInfoService;
 import com.welampiot.service.ElectricBoxService;
 import com.welampiot.utils.ToolUtils;
+import com.welampiot.vo.AirSwitchInfoReturnVO;
 import com.welampiot.vo.ElectricBoxReturnVO;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.CrossOrigin;
@@ -30,6 +32,9 @@ public class ElectricBoxController {
     @Autowired
     private ElectricBoxService electricBoxService;
 
+    @Autowired
+    private AirSwitchInfoService airSwitchInfoService;
+
     @Autowired
     private ToolUtils toolUtils;
 
@@ -53,7 +58,6 @@ public class ElectricBoxController {
         dto.setSectionList(toolUtils.getSectionList(request));
 
         ElectricBoxReturnVO electricBoxList = electricBoxService.getElectricBoxListBySectionId(dto);
-        System.out.println(electricBoxList);
         return BaseResult.success(electricBoxList);
     }
 
@@ -66,9 +70,14 @@ public class ElectricBoxController {
     public BaseResult<AirSwitchInfoDTO> airSwitchList(HttpServletRequest request){
         Integer boxId = request.getParameter("boxId") == null ? 0 : Integer.parseInt(request.getParameter("boxId"));
         Integer online = request.getParameter("online") == null ? 0 : Integer.parseInt(request.getParameter("online"));
-
-
-
-        return BaseResult.success();
+        AirSwitchInfoReturnVO airSwitchInfoReturnVO;
+        if (online == 1){
+           airSwitchInfoReturnVO = airSwitchInfoService.getAirSwitchInfo(boxId,1);
+        }else if (online == 2){
+           airSwitchInfoReturnVO = airSwitchInfoService.getAirSwitchInfo(boxId,2);
+        }else {
+           airSwitchInfoReturnVO =  airSwitchInfoService.getAirSwitchInfo(boxId,online);
+        }
+        return BaseResult.success(airSwitchInfoReturnVO);
     }
 }

+ 29 - 0
src/main/java/com/welampiot/dao/AirSwitchInfoDao.java

@@ -0,0 +1,29 @@
+package com.welampiot.dao;
+
+import com.welampiot.dto.AirSwitchInfoDTO;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
+
+/**
+ * ClassName: AirSwitchInfoDao
+ * Package: com.welampiot.dao
+ * Description:
+ *
+ * @Author: zhj_Start
+ * @Create: 2023/3/28 - 21:19
+ * @Version: v1.0
+ */
+public interface AirSwitchInfoDao {
+    List<AirSwitchInfoDTO> getAirSwitchInfoByBoxId(@Param("boxId") Integer boxId, @Param("online") Integer online);
+
+    Integer getCountByBoxId(@Param("boxId") Integer boxId);
+
+    Integer getCountByBoxIdAndType(@Param("boxId") Integer boxId, @Param("type") Integer type);
+
+    Integer getCountByBoxIdAndAlarmStatus(@Param("boxId") Integer boxId);
+
+    Integer getPolicyIdByBoxId(@Param("boxId") Integer boxId);
+
+    String getPolicyNameByPolicyId(@Param("policyId") Integer policyId);
+}

+ 17 - 2
src/main/java/com/welampiot/dto/AirSwitchInfoDTO.java

@@ -49,6 +49,9 @@ public class AirSwitchInfoDTO implements Serializable {
     /** A相温度 **/
     private Float tempA;
 
+    /** A相漏电电流(mA)**/
+    private Float leakageCurA;
+
     /** B相电压 **/
     private Float volB;
 
@@ -61,6 +64,9 @@ public class AirSwitchInfoDTO implements Serializable {
     /** B相温度 **/
     private Float tempB;
 
+    /** B相漏电电流(mA)**/
+    private Float leakageCurB;
+
     /** C相电压 **/
     private Float volC;
 
@@ -73,11 +79,14 @@ public class AirSwitchInfoDTO implements Serializable {
     /** C相温度 **/
     private Float tempC;
 
+    /** C相漏电电流(mA)**/
+    private Float leakageCurC;
+
     /** 数据更新时间(0时区) **/
-    private Date logTime;
+    private String logTime;
 
     /** 设备创建时间 **/
-    private Date createTime;
+    private String createTime;
 
     /** 策略id **/
     private Integer policyId;
@@ -106,5 +115,11 @@ public class AirSwitchInfoDTO implements Serializable {
     /** C相故障内容 **/
     private String alarmInfoC;
 
+    /** 策略名称 **/
+    private String policyName;
+
+    /** 时区 **/
+    private Integer timezone;
+
     private static final long serialVersionUID = 1L;
 }

+ 19 - 0
src/main/java/com/welampiot/service/AirSwitchInfoService.java

@@ -0,0 +1,19 @@
+package com.welampiot.service;
+
+import com.welampiot.dto.AirSwitchInfoDTO;
+import com.welampiot.vo.AirSwitchInfoReturnVO;
+
+import java.util.List;
+
+/**
+ * ClassName: AirSwitchInfoService
+ * Package: com.welampiot.service
+ * Description:
+ *
+ * @Author: zhj_Start
+ * @Create: 2023/3/28 - 21:24
+ * @Version: v1.0
+ */
+public interface AirSwitchInfoService {
+    AirSwitchInfoReturnVO getAirSwitchInfo(Integer boxId, Integer online);
+}

+ 81 - 0
src/main/java/com/welampiot/service/impl/AirSwitchInfoServiceImpl.java

@@ -0,0 +1,81 @@
+package com.welampiot.service.impl;
+
+import com.welampiot.dao.AirSwitchInfoDao;
+import com.welampiot.dto.AirSwitchInfoDTO;
+import com.welampiot.service.AirSwitchInfoService;
+import com.welampiot.vo.AirSwitchInfoReturnVO;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+/**
+ * ClassName: AirSwitchInfoServiceImpl
+ * Package: com.welampiot.service.impl
+ * Description:
+ *
+ * @Author: zhj_Start
+ * @Create: 2023/3/28 - 21:27
+ * @Version: v1.0
+ */
+@Service
+public class AirSwitchInfoServiceImpl implements AirSwitchInfoService {
+
+    @Autowired
+    private AirSwitchInfoDao airSwitchInfoDao;
+
+    @Override
+    public AirSwitchInfoReturnVO getAirSwitchInfo(Integer boxId, Integer online) {
+        AirSwitchInfoReturnVO airSwitchInfoReturnVO = new AirSwitchInfoReturnVO();
+        airSwitchInfoReturnVO.setTotalDev(airSwitchInfoDao.getCountByBoxId(boxId));
+        airSwitchInfoReturnVO.setOneDev(airSwitchInfoDao.getCountByBoxIdAndType(boxId,0));
+        airSwitchInfoReturnVO.setThreeDev(airSwitchInfoDao.getCountByBoxIdAndType(boxId,1));
+        airSwitchInfoReturnVO.setAlarmCount(airSwitchInfoDao.getCountByBoxIdAndAlarmStatus(boxId));
+        airSwitchInfoReturnVO.setPolicyId(airSwitchInfoDao.getPolicyIdByBoxId(boxId));
+        if (airSwitchInfoReturnVO.getPolicyId() != null && airSwitchInfoReturnVO.getPolicyId() != 0){
+            airSwitchInfoReturnVO.setPolicyName(airSwitchInfoDao.getPolicyNameByPolicyId(airSwitchInfoReturnVO.getPolicyId()));
+        }else {
+            airSwitchInfoReturnVO.setPolicyName("");
+        }
+        List<AirSwitchInfoDTO> airSwitchList = airSwitchInfoDao.getAirSwitchInfoByBoxId(boxId, online);
+        List<AirSwitchInfoDTO> airSwitchInfoDTOS = new ArrayList<>();
+        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+        airSwitchList.forEach(airSwitchInfoDTO -> {
+            if (airSwitchInfoDTO.getPolicyId() == null || airSwitchInfoDTO.getPolicyId() == 0){
+                airSwitchInfoDTO.setPolicyName("");
+            }
+            if (airSwitchInfoDTO.getLogTime() != null){
+                Date cmdTime;
+                try {
+                    cmdTime = simpleDateFormat.parse(airSwitchInfoDTO.getLogTime());
+                } catch (ParseException e) {
+                    throw new RuntimeException(e);
+                }
+                //判断时区,为null默认东八区
+                long timezone = airSwitchInfoDTO.getTimezone() == null ? 8 : airSwitchInfoDTO.getTimezone();
+                long l = cmdTime.getTime() + timezone * 3600 * 1000;
+                cmdTime = new Date(l);
+                airSwitchInfoDTO.setLogTime(simpleDateFormat.format(cmdTime));
+            }else {
+                airSwitchInfoDTO.setLogTime("");
+            }
+            if (airSwitchInfoDTO.getStatus() != null && airSwitchInfoDTO.getStatus() == 1){
+                airSwitchInfoDTO.setStatus(1);
+            }else {
+                airSwitchInfoDTO.setStatus(0);
+            }
+            if (airSwitchInfoDTO.getType() != null && airSwitchInfoDTO.getType() == 1) {
+                airSwitchInfoDTO.setType(1);
+            }else {
+                airSwitchInfoDTO.setType(0);
+            }
+            airSwitchInfoDTOS.add(airSwitchInfoDTO);
+        });
+        airSwitchInfoReturnVO.setList(airSwitchInfoDTOS);
+        return airSwitchInfoReturnVO;
+    }
+}

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

@@ -41,12 +41,12 @@ public class ElectricBoxServiceImpl implements ElectricBoxService {
             if (electricBoxDTO.getInstallDate() == null){
                 electricBoxDTO.setInstallDate("");
             }else {
-                simpleDateFormat.format(electricBoxDTO.getInstallDate());
+                electricBoxDTO.setInstallDate(simpleDateFormat.format(electricBoxDTO.getInstallDate()));
             }
             if (electricBoxDTO.getExpirationDate() == null){
                 electricBoxDTO.setExpirationDate("");
             }else {
-                simpleDateFormat.format(electricBoxDTO.getExpirationDate());
+                electricBoxDTO.setExpirationDate(simpleDateFormat.format(electricBoxDTO.getExpirationDate()));
             }
             if (electricBoxDTO.getOnlineCount() != null && electricBoxDTO.getOnlineCount() > 0){
                 electricBoxDTO.setOnline(1);

+ 41 - 0
src/main/java/com/welampiot/vo/AirSwitchInfoReturnVO.java

@@ -0,0 +1,41 @@
+package com.welampiot.vo;
+
+import lombok.Data;
+
+import java.io.Serializable;
+import java.util.List;
+
+/**
+ * ClassName: AirSwitchInfoReturnVO
+ * Package: com.welampiot.vo
+ * Description:
+ *
+ * @Author: zhj_Start
+ * @Create: 2023/3/28 - 21:30
+ * @Version: v1.0
+ */
+@Data
+public class AirSwitchInfoReturnVO implements Serializable {
+    /** 设备总数 **/
+    private Integer totalDev;
+
+    /** 单相数 **/
+    private Integer oneDev;
+
+    /** 三相数 **/
+    private Integer threeDev;
+
+    /** 故障次数 **/
+    private Integer alarmCount;
+
+    /** 策略名称 **/
+    private String policyName;
+
+    /** 策略id(为0表示没有绑定策略)**/
+    private Integer policyId;
+
+    /** 空开列表 **/
+    private List list;
+
+    private static final long serialVersionUID = 1L;
+}

+ 47 - 0
src/main/resources/mapper/AirSwitchInfoMapper.xml

@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.welampiot.dao.AirSwitchInfoDao">
+
+
+    <select id="getAirSwitchInfoByBoxId" resultType="AirSwitchInfoDTO" parameterType="Integer">
+        select a.id,a.name,a.address,a.online,a.status,a.type,a.volA,a.curA,a.powerA,a.tempA,
+               a.alarm_info alarmInfo,a.leakagecurA as leakageCurA,a.volB,a.curB,a.powerB,a.tempB,
+               a.alarm_infoB alarmInfoB,a.leakagecurB as leakageCurB,a.volC,a.curC,a.powerC,a.tempC,
+               a.alarm_infoC alarmInfoC,a.leakagecurC as leakageCurC,a.policyid as policyId,a.alarm_status alarmStatus,
+               a.alarm_statusB alarmStatusB,a.alarm_statusC alarmStatusC,a.logtime as logTime,lp.name policyName,s.timezone
+        from air_switch_info a left join loop_policy lp on a.policyId = lp.id left join electric_box e on a.box_id = e.id
+        left join section s on e.sectionid = s.id
+        where a.box_id = #{boxId}
+        <choose>
+            <when test="online == 1">
+                and a.online = 1
+            </when>
+            <when test="online == 2">
+                and a.online = 0
+            </when>
+        </choose>
+        order by convert(a.name using gbk) asc,a.id desc
+    </select>
+
+    <select id="getCountByBoxId" resultType="Integer" parameterType="Integer">
+        select count(a.id) from air_switch_info a where a.box_id = #{boxId}
+    </select>
+
+    <select id="getCountByBoxIdAndType" resultType="Integer" parameterType="Integer">
+        select count(a.id) from air_switch_info a where a.box_id = #{boxId} and a.type = #{type}
+    </select>
+
+    <select id="getCountByBoxIdAndAlarmStatus" resultType="Integer" parameterType="Integer">
+        select count(a.id) from air_switch_info a
+        where a.box_id = #{boxId} and a.alarm_status = 1 or a.alarm_statusB = 1 or a.alarm_statusC = 1
+    </select>
+
+    <select id="getPolicyIdByBoxId" resultType="Integer" parameterType="Integer">
+        select e.policyid from electric_box e where e.id = #{boxId}
+    </select>
+
+    <select id="getPolicyNameByPolicyId" resultType="String" parameterType="Integer">
+        select lp.name policyName from loop_policy lp where lp.id = #{policyId}
+    </select>
+
+</mapper>