Selaa lähdekoodia

获取回路列表

zhj 2 vuotta sitten
vanhempi
commit
ade6200e71

+ 53 - 0
src/main/java/com/welampiot/controller/LoopController.java

@@ -0,0 +1,53 @@
+package com.welampiot.controller;
+
+import com.welampiot.common.BaseResult;
+import com.welampiot.dto.LoopDTO;
+import com.welampiot.service.LoopService;
+import com.welampiot.utils.ToolUtils;
+import com.welampiot.vo.LoopVO;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.CrossOrigin;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RestController;
+
+import javax.servlet.http.HttpServletRequest;
+
+/**
+ * ClassName: LoopController
+ * Package: com.welampiot.controller
+ * Description:
+ *
+ * @Author: zhj_Start
+ * @Create: 2023/4/4 - 15:05
+ * @Version: v1.0
+ */
+@RestController
+@CrossOrigin
+@RequestMapping("/api/LoopController")
+public class LoopController {
+
+    @Autowired
+    private LoopService loopService;
+
+    @Autowired
+    private ToolUtils toolUtils;
+
+    @RequestMapping(value = "/getList", method = RequestMethod.POST)
+    public BaseResult<LoopDTO> getList(HttpServletRequest request){
+        Integer id = request.getParameter("id") == null ? 0 : Integer.parseInt(request.getParameter("id"));
+        Integer page = request.getParameter("page") == null ? 1 : Integer.parseInt(request.getParameter("page"));
+        Integer count = request.getParameter("count") == null ? 16 : Integer.parseInt(request.getParameter("count"));
+        String keyword = request.getParameter("keyword") == null ? "" : request.getParameter("keyword");
+
+        LoopDTO loopDTO = new LoopDTO();
+        loopDTO.setId(id);
+        loopDTO.setPage(count * (page - 1));
+        loopDTO.setCount(count);
+        loopDTO.setKeyword(keyword);
+        loopDTO.setSectionList(toolUtils.getSectionList(request));
+        LoopVO loopList = loopService.getLoopList(loopDTO);
+        return BaseResult.success(loopList);
+    }
+
+}

+ 20 - 0
src/main/java/com/welampiot/dao/LoopDao.java

@@ -0,0 +1,20 @@
+package com.welampiot.dao;
+
+import com.welampiot.dto.LoopDTO;
+
+import java.util.List;
+
+/**
+ * ClassName: LoopDao
+ * Package: com.welampiot.dao
+ * Description:
+ *
+ * @Author: zhj_Start
+ * @Create: 2023/4/4 - 13:55
+ * @Version: v1.0
+ */
+public interface LoopDao {
+    List<LoopDTO> getLoopListByLoopDTO(LoopDTO dto);
+
+    Integer getTotalBySectionList(LoopDTO dto);
+}

+ 191 - 0
src/main/java/com/welampiot/dto/LoopDTO.java

@@ -0,0 +1,191 @@
+package com.welampiot.dto;
+
+import lombok.Data;
+
+import java.io.Serializable;
+import java.util.List;
+
+/**
+ * ClassName: LoopDTO
+ * Package: com.welampiot.dto
+ * Description: 回路表
+ *
+ * @Author: zhj_Start
+ * @Create: 2023/4/4 - 10:04
+ * @Version: v1.0
+ */
+@Data
+public class LoopDTO implements Serializable {
+    /** 主键 **/
+    private Integer id;
+
+    /** 回路名字 **/
+    private String name;
+
+    /** 回路编号 **/
+    private Integer number;
+
+    /** 设备id **/
+    private Integer deviceId;
+
+    /** 控制器类型(0 GPRS,1 NB,2 Lora, 3 PLC,4 zigbee) **/
+    private Integer controlType;
+
+    /** 区、县id **/
+    private Integer areaId;
+
+    /** 路段、街道id **/
+    private Integer sectionId;
+
+    /** 路灯数 **/
+    private Integer lampCount;
+
+    /** 开合闸状态(0 合闸,1 分闸) **/
+    private Integer status;
+
+    /** 创建时间 **/
+    private String createTime;
+
+    /** 设备SN **/
+    private String sn;
+
+    /** 设备类型(0 单相,1 三相) **/
+    private Integer devType;
+
+    /** 费率id **/
+    private Integer rateId;
+
+    /** 网络id **/
+    private Integer networkId;
+
+    /** 策略id **/
+    private Integer policyId;
+
+    /** 网络状态(0 离线,1 在线) **/
+    private Integer netStatus;
+
+    /** 更新时间(0时区时间) **/
+    private String updateTime;
+
+    /** 锁状态(0 解锁,1 锁死) **/
+    private Integer lockStatus;
+
+    /** 故障内容(多个故障用逗号隔开) **/
+    private String alarmStr;
+
+    /** 故障状态(0 正常,1 故障) **/
+    private Integer alarmStatus;
+
+    /** 操作类型(1 手动,2 策略) **/
+    private Integer type;
+
+    /** 指令状态(0 下发完成,1 下发中) **/
+    private Integer cmdStatus;
+
+    /** A相电压 **/
+    private Float volPa;
+
+    /** B相电压 **/
+    private Float volPb;
+
+    /** C相电压 **/
+    private Float volPc;
+
+    /** A相电流 **/
+    private Float curA;
+
+    /** B相电流 **/
+    private Float curB;
+
+    /** C相电流 **/
+    private Float curC;
+
+    /** A相有功功率 **/
+    private Float insPa;
+
+    /** B相有功功率 **/
+    private Float insPb;
+
+    /** C相有功功率 **/
+    private Float insPc;
+
+    /** A相功率因素 **/
+    private Float pwrFa;
+
+    /** B相功率因素 **/
+    private Float pwrFb;
+
+    /** C相功率因素 **/
+    private Float pwrFc;
+
+    /** 电网频率 **/
+    private Float freq;
+
+    /** 总有功电能 **/
+    private Float epT;
+
+    /** 费率1有功电能 **/
+    private Float epT1;
+
+    /** 费率2有功电能 **/
+    private Float epT2;
+
+    /** 费率3有功电能 **/
+    private Float epT3;
+
+    /** 费率4有功电能 **/
+    private Float epT4;
+
+    /** 协议类型(0 非MQTT,1 MQTT)(GPRS设备使用) **/
+    private Integer proType;
+
+    /** 灯杆id **/
+    private Integer lampPoleId;
+
+    /** 经度 **/
+    private Float longitude;
+
+    /** 纬度 **/
+    private Float latitude;
+
+    /** 版本号 **/
+    private String version;
+
+    /** 是否成功保存本地策略(0 否,1 是) **/
+    private Integer localPolicyStatus;
+
+    /** 设备类型(mqtt设备下发指令使用) **/
+    private String mqttDevType;
+
+    /** 创建人员 **/
+    private Integer createId;
+
+    /** iccId **/
+    private String iccId;
+
+    /** 力合微plc广播状态(0:关闭,1:开启) **/
+    private Integer broadcastStatus;
+
+    /** 策略名称 **/
+    private String policyName;
+
+    /** 时区 **/
+    private Integer timezone;
+
+    /** 页码 **/
+    private Integer page;
+
+    /** 单页显示数量 **/
+    private Integer count;
+
+    /** 关键字搜索 **/
+    private String keyword;
+
+    /** 下载(0 列表,1导出) **/
+    private Integer download;
+
+    /** 获取所有路段id **/
+    private List sectionList;
+
+    private static final long serialVersionUID = 1L;
+}

+ 17 - 0
src/main/java/com/welampiot/service/LoopService.java

@@ -0,0 +1,17 @@
+package com.welampiot.service;
+
+import com.welampiot.dto.LoopDTO;
+import com.welampiot.vo.LoopVO;
+
+/**
+ * ClassName: LoopService
+ * Package: com.welampiot.service
+ * Description:
+ *
+ * @Author: zhj_Start
+ * @Create: 2023/4/4 - 15:13
+ * @Version: v1.0
+ */
+public interface LoopService {
+    LoopVO getLoopList(LoopDTO dto);
+}

+ 63 - 0
src/main/java/com/welampiot/service/impl/LoopServiceImpl.java

@@ -0,0 +1,63 @@
+package com.welampiot.service.impl;
+
+import com.welampiot.dao.LoopDao;
+import com.welampiot.dto.LoopDTO;
+import com.welampiot.service.LoopService;
+import com.welampiot.vo.LoopVO;
+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: LoopServiceImpl
+ * Package: com.welampiot.service.impl
+ * Description:
+ *
+ * @Author: zhj_Start
+ * @Create: 2023/4/4 - 15:14
+ * @Version: v1.0
+ */
+@Service
+public class LoopServiceImpl implements LoopService {
+
+    @Autowired
+    private LoopDao loopDao;
+
+    @Override
+    public LoopVO getLoopList(LoopDTO dto) {
+        LoopVO loopVO = new LoopVO();
+        Integer devTotal = loopDao.getTotalBySectionList(dto);//获取设备总数
+        loopVO.setTotal((int)Math.ceil((double)devTotal/dto.getCount()));
+        List<LoopDTO> loopList = loopDao.getLoopListByLoopDTO(dto);
+        List<LoopDTO> list = new ArrayList<>();
+        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+        loopList.forEach(loopDTO->{
+            if (loopDTO.getPolicyId() == null || loopDTO.getPolicyId() == 0){
+                loopDTO.setPolicyName("");
+            }
+            if (loopDTO.getUpdateTime() != null){
+                Date cmdTime;
+                try {
+                    cmdTime = simpleDateFormat.parse(loopDTO.getUpdateTime());
+                } catch (ParseException e) {
+                    throw new RuntimeException(e);
+                }
+                //判断时区,为null默认东八区
+                long timezone = loopDTO.getTimezone() == null ? 8 : loopDTO.getTimezone();
+                long l = cmdTime.getTime() + timezone * 3600 * 1000;
+                cmdTime = new Date(l);
+                loopDTO.setUpdateTime(simpleDateFormat.format(cmdTime));
+            }else {
+                loopDTO.setUpdateTime("");
+            }
+            list.add(loopDTO);
+        });
+        loopVO.setList(list);
+        return loopVO;
+    }
+}

+ 25 - 0
src/main/java/com/welampiot/vo/LoopVO.java

@@ -0,0 +1,25 @@
+package com.welampiot.vo;
+
+import lombok.Data;
+
+import java.io.Serializable;
+import java.util.List;
+
+/**
+ * ClassName: LoopVO
+ * Package: com.welampiot.vo
+ * Description:
+ *
+ * @Author: zhj_Start
+ * @Create: 2023/4/4 - 21:14
+ * @Version: v1.0
+ */
+@Data
+public class LoopVO implements Serializable {
+    /** 总页数 **/
+    private Integer total;
+
+    private List list;
+
+    private static final long serialVersionUID = 1L;
+}

+ 10 - 10
src/main/resources/mapper/ElectricBoxMapper.xml

@@ -8,7 +8,7 @@
                (select count(*) from air_switch_info c where c.box_id = e.id and c.online = 1) as onlineCount
         from electric_box e left join air_switch_info a on a.box_id = e.id
         where 1=1 <if test="keyword != null and keyword != ''">
-                  and e.name like '%${keyword}%' or e.address like '%${keyword}%'
+                  and (e.name like '%${keyword}%' or e.address like '%${keyword}%')
               </if>
               <choose>
                   <when test="status == 1">
@@ -20,12 +20,12 @@
               </choose>
             and <if test="sectionList != null and !sectionList.isEmpty()">
                     e.sectionid in
-                    <foreach item="vo" collection="sectionList" open="(" separator="," close=")">
-                        #{vo}
+                    <foreach item="dto" collection="sectionList" open="(" separator="," close=")">
+                        #{dto}
                     </foreach>
                 </if>
             order by convert(e.name using gbk) asc,e.id desc
-            <if test="page != 0">
+            <if test="page >= 0">
                  limit #{page},#{count}
             </if>
     </select>
@@ -36,8 +36,8 @@
               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 item="dto" collection="sectionList" open="(" separator="," close=")">
+                        #{dto}
                     </foreach>
                     group by e.id) b
     </select>
@@ -48,8 +48,8 @@
             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 item="dto" collection="sectionList" open="(" separator="," close=")">
+                #{dto}
             </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
@@ -61,8 +61,8 @@
             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 item="dto" collection="sectionList" open="(" separator="," close=")">
+                #{dto}
             </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

+ 39 - 0
src/main/resources/mapper/LoopMapper.xml

@@ -0,0 +1,39 @@
+<?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.LoopDao">
+
+    <select id="getLoopListByLoopDTO" resultType="LoopDTO" parameterType="LoopDTO">
+        select l.id,l.name,l.sn,l.dev_type as devType,l.net_status netStatus,
+               l.volPa,l.cura as curA,l.insPa,l.volPb,l.curb as curB,l.insPb,
+               l.volPc,l.curc as curC,l.insPc,l.updatetime as updateTime,l.lampcount as lampCount,
+               l.type,l.lock_status lockStatus,l.status,l.policyid as policyId,lp.name as policyName,s.timezone
+        from `loop` l left join loop_policy lp on l.policyid = lp.id left join section s on l.sectionid = s.id
+        where 1=1 <if test="id != null and id != 0">
+                and l.id = #{id}
+            </if>
+            <if test="keyword != null and keyword != ''">
+                and (l.name like '%${keyword}%' or l.number like '%${keyword}%')
+            </if>
+            <if test="sectionList != null and !sectionList.isEmpty()">
+                and l.sectionid in
+                <foreach item="dto" collection="sectionList" open="(" separator="," close=")">
+                    #{dto}
+                </foreach>
+            </if>
+            order by convert(l.name using gbk) asc,l.id desc
+            <if test="page >= 0">
+                limit #{page},#{count}
+            </if>
+    </select>
+
+    <select id="getTotalBySectionList" resultType="Integer" parameterType="LoopDTO">
+        select count(l.id) as total from `loop` l
+        <if test="sectionList != null and !sectionList.isEmpty()">
+            where l.sectionid in
+                <foreach item="dto" collection="sectionList" open="(" separator="," close=")">
+                    #{dto}
+                </foreach>
+        </if>
+    </select>
+
+</mapper>