Prechádzať zdrojové kódy

气象站列表接口

zhj 2 rokov pred
rodič
commit
6d982f2a59

+ 40 - 0
src/main/java/com/welampiot/controller/NewLampPoleController.java

@@ -1,11 +1,14 @@
 package com.welampiot.controller;
 
 import com.welampiot.common.BaseResult;
+import com.welampiot.dto.EnvmonitorDTO;
 import com.welampiot.dto.WifiDTO;
 import com.welampiot.dto.WifiInfoLogDTO;
+import com.welampiot.service.EnvmonitorService;
 import com.welampiot.service.WifiInfoLogService;
 import com.welampiot.service.WifiService;
 import com.welampiot.utils.ToolUtils;
+import com.welampiot.vo.EnvmonitorVO;
 import com.welampiot.vo.WifiInfoLogVO;
 import com.welampiot.vo.WifiOutInfoVO;
 import com.welampiot.vo.WifiVO;
@@ -37,6 +40,9 @@ public class NewLampPoleController {
     @Autowired
     private WifiInfoLogService wifiInfoLogService;
 
+    @Autowired
+    private EnvmonitorService envmonitorService;
+
     @Autowired
     private ToolUtils toolUtils;
 
@@ -114,4 +120,38 @@ public class NewLampPoleController {
         return BaseResult.success(vo);
     }
 
+    /**
+     * 获取气象站数据列表
+     * @param request
+     * @return
+     */
+    @RequestMapping(value = "/weatherList", method = RequestMethod.POST)
+    public BaseResult<EnvmonitorDTO> weatherList(HttpServletRequest request){
+        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 online = request.getParameter("online") == null ? 0 : Integer.parseInt(request.getParameter("online"));
+
+        EnvmonitorDTO dto = new EnvmonitorDTO();
+        dto.setPage(count * (page - 1));
+        dto.setCount(count);
+        dto.setOnline(online);
+        dto.setSectionList(toolUtils.getSectionList(request));
+
+        EnvmonitorVO vo = envmonitorService.getWeatherList(dto);
+        return BaseResult.success(vo);
+    }
+
+    /**
+     * 获取气象站概览数据
+     * @param request
+     * @return
+     */
+    @RequestMapping(value = "/weatherInfo", method = RequestMethod.POST,produces = "application/json;charset=utf-8")
+    public BaseResult<EnvmonitorDTO> weatherInfo(HttpServletRequest request){
+        EnvmonitorDTO dto = new EnvmonitorDTO();
+        dto.setSectionList(toolUtils.getSectionList(request));
+        EnvmonitorVO vo = envmonitorService.getDeviceCountBySectionList(dto);
+        return BaseResult.success(vo);
+    }
+
 }

+ 22 - 0
src/main/java/com/welampiot/dao/EnvmonitorDao.java

@@ -0,0 +1,22 @@
+package com.welampiot.dao;
+
+import com.welampiot.dto.EnvmonitorDTO;
+
+import java.util.List;
+
+/**
+ * ClassName: EnvmonitorDao
+ * Package: com.welampiot.dao
+ * Description:
+ *
+ * @Author: zhj_Start
+ * @Create: 2023/4/13 - 9:04
+ * @Version: v1.0
+ */
+public interface EnvmonitorDao {
+    List<EnvmonitorDTO> getWeatherListByDTO(EnvmonitorDTO dto);
+
+    Integer getTotalBySectionList(EnvmonitorDTO dto);
+
+    Integer getOnlineTotalBySectionList(EnvmonitorDTO dto);
+}

+ 204 - 0
src/main/java/com/welampiot/dto/EnvmonitorDTO.java

@@ -0,0 +1,204 @@
+package com.welampiot.dto;
+
+import lombok.Data;
+
+import java.io.Serializable;
+import java.util.List;
+
+/**
+ * ClassName: EnvmonitorDTO
+ * Package: com.welampiot.dto
+ * Description:
+ *
+ * @Author: zhj_Start
+ * @Create: 2023/4/12 - 18:17
+ * @Version: v1.0
+ */
+@Data
+public class EnvmonitorDTO implements Serializable {
+    /** 主键 **/
+    private Integer id;
+
+    /** 监控器编号 **/
+    private Integer number;
+
+    /** 网络id **/
+    private Integer networkId;
+
+    /** 市区id **/
+    private Integer areaId;
+
+    /** 路段id **/
+    private Integer sectionId;
+
+    /** 监控器状态(1 正常,0 异常)**/
+    private Integer status;
+
+    /** 无线模块地址 **/
+    private String address;
+
+    /** 路段名 **/
+    private String section;
+
+    /** 纬度 **/
+    private Double latitude;
+
+    /** 经度 **/
+    private Double longitude;
+
+    /** 是否故障(1 是,0 否)**/
+    private Integer isFaulted;
+
+    /** 更新时间 **/
+    private String updateTime;
+
+    /** 创建时间 **/
+    private String createTime;
+
+    /** 灯杆id **/
+    private Integer lampPoleId;
+
+    /** 名称 **/
+    private String model;
+
+    /** 序列号 **/
+    private String num;
+
+    /** 支持参数(0 湿度,1 温度,2 土壤湿度(暂不支持))**/
+    private String importPra;
+
+    /** 设备类型(0 = 环境监控,1 = 光照度,2 = 传感器)**/
+    private Integer type;
+
+    /** 传感器名称(光照度使用)**/
+    private String name;
+
+    /** 厂家 **/
+    private String manuFactor;
+
+    /** 备注 **/
+    private String remarks;
+
+    /** 控制器类型 **/
+    private String monitorType;
+
+    /** 蓄电池AH数 **/
+    private String batteryAh;
+
+    /** 天气json更新时间 **/
+    private String weatherUpdateTime;
+
+    /** 最新光照强度 **/
+    private Integer illumination;
+
+    /** 天气信息 **/
+    private String weatherInfo;
+
+    /** 网络类型(0 以太网,1 RS485,2 其他)**/
+    private Integer netType;
+
+    /** 网络状态(0 离线,1 在线)**/
+    private Integer netStatus;
+
+    /** 设备类型(0 WE-JX-6(精讯),1 WE-FSX CS-N10,2 WE-BYH-6,
+     * 3 RY-CPM2516(耕农),4 FM-DH8(飞梦),5 FRT-RDM(富奥通),
+     * 7 ZX-706C1(众星环保),8 4G-light-sensor(4G光照度感器),9 PLC **/
+    private Integer devType;
+
+    /** 是否注册(0 否,1 是)**/
+    private Integer isRegister;
+
+    /** 设备要素类型(0 pm要素,1 co2要素)**/
+    private Integer pramType;
+
+    /** 波特率(0 1200,1 2400,2 4800,3 9600,4 19200,5 38400,6 115200)**/
+    private Integer rate;
+
+    /**  串口(0 3号串口,1 2号串口,2 1号串口) **/
+    private Integer serialPort;
+
+    /** 气象站绑定plc的测量点 **/
+    private Integer mp;
+
+    /** 是否开启光照度关、开灯(0:不开启,1:开启)**/
+    private Integer mpStatus;
+
+    /** 光照度开、关的开始时间(H:m:s)**/
+    private String mpStartTime;
+
+    /** 光照度开、关的结束时间(H:m:s) **/
+    private String mpEndTime;
+
+    /** 光照度设置开灯的亮度(0-100) **/
+    private Integer mpBright;
+
+    /** 设置光照度值 **/
+    private Integer mpIllumination;
+
+    /** 过期时间 **/
+    private String expirationDate;
+
+    /** 安装时间 **/
+    private String installDate;
+
+    /** 湿度 **/
+    private Float humidity;
+
+    /** 温度 **/
+    private Float temperature;
+
+    private Float PM100;
+
+    private Float PM10;
+
+    private Float PM25;
+
+    /** 噪声 **/
+    private Float noise;
+
+    /** 甲醛 **/
+    private Float formaldehyde;
+
+    /** 大气压强 **/
+    private Float atmosPressue;
+
+    /** 风速 **/
+    private Float windSpeed;
+
+    /** 风向 **/
+    private Integer windDire;
+
+    /** 雨量 **/
+    private Float rainfall;
+
+    /** 太阳辐射 **/
+    private Integer radiation;
+
+    /** 二氧化碳浓度 **/
+    private Integer co2;
+
+    /** 一氧化碳浓度 **/
+    private Integer co;
+
+    private Integer tsp;
+
+    /** 时区 **/
+    private Integer timezone;
+
+    /** 路段id **/
+    private List<Integer> sectionList;
+
+    /** 灯杆名 **/
+    private String lampPoleName;
+
+    /** 页码 **/
+    private Integer page;
+
+    /** 页数 **/
+    private Integer count;
+
+    /** 在线状态 **/
+    private Integer online;
+
+    private static final long serialVersionUID = 1L;
+}

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

@@ -0,0 +1,19 @@
+package com.welampiot.service;
+
+import com.welampiot.dto.EnvmonitorDTO;
+import com.welampiot.vo.EnvmonitorVO;
+
+/**
+ * ClassName: EnvmonitorService
+ * Package: com.welampiot.service
+ * Description:
+ *
+ * @Author: zhj_Start
+ * @Create: 2023/4/13 - 15:17
+ * @Version: v1.0
+ */
+public interface EnvmonitorService {
+    EnvmonitorVO getWeatherList(EnvmonitorDTO dto);
+
+    EnvmonitorVO getDeviceCountBySectionList(EnvmonitorDTO dto);
+}

+ 143 - 0
src/main/java/com/welampiot/service/impl/EnvmonitorServiceImpl.java

@@ -0,0 +1,143 @@
+package com.welampiot.service.impl;
+
+import com.welampiot.dao.EnvmonitorDao;
+import com.welampiot.dto.EnvmonitorDTO;
+import com.welampiot.service.EnvmonitorService;
+import com.welampiot.vo.EnvmonitorVO;
+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: EnvmonitorServiceImpl
+ * Package: com.welampiot.service.impl
+ * Description:
+ *
+ * @Author: zhj_Start
+ * @Create: 2023/4/13 - 15:21
+ * @Version: v1.0
+ */
+@Service
+public class EnvmonitorServiceImpl implements EnvmonitorService {
+    @Autowired
+    private EnvmonitorDao envmonitorDao;
+
+    @Override
+    public EnvmonitorVO getWeatherList(EnvmonitorDTO dto) {
+        EnvmonitorVO vo = new EnvmonitorVO();
+        vo.setTotal(envmonitorDao.getTotalBySectionList(dto));
+        List<EnvmonitorDTO> weatherList = envmonitorDao.getWeatherListByDTO(dto);
+        List<EnvmonitorDTO> list = new ArrayList<>();
+        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+        weatherList.forEach(envmonitorDTO ->{
+            if (envmonitorDTO.getLampPoleName() == null){
+                envmonitorDTO.setLampPoleName("");
+            }
+            if (envmonitorDTO.getNetStatus() != null && envmonitorDTO.getNetStatus() == 1){
+                envmonitorDTO.setNetStatus(1);
+            }else {
+                envmonitorDTO.setNetStatus(0);
+            }
+            if (envmonitorDTO.getNetType() != null && envmonitorDTO.getNetType() == 2){
+                envmonitorDTO.setNetType(2);
+            }else if (envmonitorDTO.getNetType() != null && envmonitorDTO.getNetType() == 1){
+                envmonitorDTO.setNetType(1);
+            }else {
+                envmonitorDTO.setNetType(0);
+            }
+            if (envmonitorDTO.getUpdateTime() != null && !envmonitorDTO.getUpdateTime().equals("")){
+                Date cmdTime;
+                try {
+                    cmdTime = simpleDateFormat.parse(envmonitorDTO.getUpdateTime());
+                } catch (ParseException e) {
+                    throw new RuntimeException(e);
+                }
+                //判断时区,为null默认东八区
+                long timezone = envmonitorDTO.getTimezone() == null ? 8 : envmonitorDTO.getTimezone();
+                long l = cmdTime.getTime() + timezone * 3600 * 1000;
+                cmdTime = new Date(l);
+                envmonitorDTO.setUpdateTime(simpleDateFormat.format(cmdTime));
+            }else {
+                envmonitorDTO.setUpdateTime("");
+            }
+            //获取设备安装时间
+            if (envmonitorDTO.getInstallDate() == null){
+                envmonitorDTO.setInstallDate("");
+            }else {
+                try {
+                    envmonitorDTO.setInstallDate(simpleDateFormat.format(simpleDateFormat.parse(envmonitorDTO.getInstallDate())));
+                } catch (ParseException e) {
+                    throw new RuntimeException(e);
+                }
+            }
+            //获取设备过期时间
+            if (envmonitorDTO.getExpirationDate() == null){
+                envmonitorDTO.setExpirationDate("");
+            }else {
+                try {
+                    envmonitorDTO.setExpirationDate(simpleDateFormat.format(simpleDateFormat.parse(envmonitorDTO.getExpirationDate())));
+                } catch (ParseException e) {
+                    throw new RuntimeException(e);
+                }
+            }
+            if (envmonitorDTO.getHumidity() == null){
+                envmonitorDTO.setHumidity(0.0f);
+            }
+            if (envmonitorDTO.getTemperature() == null){
+                envmonitorDTO.setTemperature(0.0f);
+            }
+            if (envmonitorDTO.getPM10() == null){
+                envmonitorDTO.setPM10(0.0f);
+            }
+            if (envmonitorDTO.getNoise() == null){
+                envmonitorDTO.setNoise(0.0f);
+            }
+            if (envmonitorDTO.getPM25() == null){
+                envmonitorDTO.setPM25(0.0f);
+            }
+            if (envmonitorDTO.getIllumination() == null){
+                envmonitorDTO.setIllumination(0);
+            }
+            if (envmonitorDTO.getWindSpeed() == null){
+                envmonitorDTO.setWindSpeed(0.0f);
+            }
+            if (envmonitorDTO.getWindDire() == null){
+                envmonitorDTO.setWindDire(0);
+            }
+            if (envmonitorDTO.getRainfall() == null){
+                envmonitorDTO.setRainfall(0.0f);
+            }
+            if (envmonitorDTO.getRadiation() == null){
+                envmonitorDTO.setRadiation(0);
+            }
+            if (envmonitorDTO.getCo() == null){
+                envmonitorDTO.setCo(0);
+            }
+            if (envmonitorDTO.getCo2() == null){
+                envmonitorDTO.setCo2(0);
+            }
+            if (envmonitorDTO.getTsp() == null){
+                envmonitorDTO.setTsp(0);
+            }
+            if (envmonitorDTO.getAtmosPressue() == null){
+                envmonitorDTO.setAtmosPressue(0.0f);
+            }
+            list.add(envmonitorDTO);
+        });
+        vo.setList(list);
+        return vo;
+    }
+
+    @Override
+    public EnvmonitorVO getDeviceCountBySectionList(EnvmonitorDTO dto) {
+        EnvmonitorVO vo = new EnvmonitorVO();
+        vo.setDeviceCount(envmonitorDao.getTotalBySectionList(dto));
+        vo.setOnlineCount(envmonitorDao.getOnlineTotalBySectionList(dto));
+        return vo;
+    }
+}

+ 29 - 0
src/main/java/com/welampiot/vo/EnvmonitorVO.java

@@ -0,0 +1,29 @@
+package com.welampiot.vo;
+
+import com.welampiot.dto.EnvmonitorDTO;
+import lombok.Data;
+
+import java.io.Serializable;
+import java.util.List;
+
+/**
+ * ClassName: EnvmonitorVO
+ * Package: com.welampiot.vo
+ * Description:
+ *
+ * @Author: zhj_Start
+ * @Create: 2023/4/13 - 15:19
+ * @Version: v1.0
+ */
+@Data
+public class EnvmonitorVO implements Serializable {
+    private Integer total;
+
+    private Integer deviceCount;
+
+    private Integer onlineCount;
+
+    private List<EnvmonitorDTO> list;
+
+    private static final long serialVersionUID = 1L;
+}

+ 60 - 0
src/main/resources/mapper/EnvmonitorMapper.xml

@@ -0,0 +1,60 @@
+<?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.EnvmonitorDao">
+
+    <select id="getWeatherListByDTO" resultType="EnvmonitorDTO">
+        select e.id,e.model as name,e.lamp_pole_id lampPoleId,e.address,e.netStatus,eil.illumination,e.netType,
+               eil.updatetime as updateTime,e.install_date installDate,e.expiration_date expirationDate,s.timezone,
+               lp.name as lampPoleName,eil.humidity,eil.temperature,eil.noise,eil.PM10,eil.PM25,eil.illumination,
+               eil.windDire,eil.windSpeed,eil.updatetime,eil.rainfall,eil.radiation,eil.co,eil.co2,eil.tsp,eil.atmospressue
+        from envmonitor e left join lamp_pole lp on e.lamp_pole_id = lp.id
+        left join section s on e.section = s.id
+        left join (SELECT t1.* FROM envmonitor_info_log t1
+                INNER JOIN ( SELECT envmonitorid, MAX( updatetime ) AS maxDateTime FROM envmonitor_info_log GROUP BY envmonitorid ) t2
+                ON t1.envmonitorid = t2.envmonitorid AND t1.updatetime = t2.maxDateTime) as eil on e.id = eil.envmonitorid
+        where e.lamp_pole_id != 0
+            <if test="sectionList != null and !sectionList.isEmpty()">
+                and e.sectionid in
+                <foreach collection="sectionList" item="dto" open="(" separator="," close=")">
+                    #{dto}
+                </foreach>
+            </if>
+            <choose>
+                <when test="online == 0">
+                    and e.netStatus = 0
+                </when>
+                <when test="online == 1">
+                    and e.netStatus = 1
+                </when>
+            </choose>
+            order by convert(lp.number using gbk) asc,
+                     convert(e.model using gbk) asc,e.id desc
+            <if test="page >= 0 and count > 0">
+                limit #{page},#{count}
+            </if>
+    </select>
+
+    <select id="getTotalBySectionList" resultType="Integer">
+        select count(e.id) as total from envmonitor e
+        left join lamp_pole lp on e.lamp_pole_id = lp.id
+        <if test="sectionList != null and !sectionList.isEmpty()">
+            where lp.sectionid in
+            <foreach collection="sectionList" item="dto" open="(" separator="," close=")">
+                #{dto}
+            </foreach>
+        </if>
+    </select>
+
+    <select id="getOnlineTotalBySectionList" resultType="Integer">
+        select count(e.id) as total from envmonitor e
+        left join lamp_pole lp on e.lamp_pole_id = lp.id
+        where e.netStatus = 1
+        <if test="sectionList != null and !sectionList.isEmpty()">
+            and lp.sectionid in
+            <foreach collection="sectionList" item="dto" open="(" separator="," close=")">
+                #{dto}
+            </foreach>
+        </if>
+    </select>
+
+</mapper>