Explorar el Código

智诺云智慧灯杆列表和详情

zhj hace 2 años
padre
commit
5cff320ea1

+ 122 - 0
src/main/java/com/welampiot/controller/NewLampPoleController2.java

@@ -0,0 +1,122 @@
+package com.welampiot.controller;
+
+import com.welampiot.common.BaseResult;
+import com.welampiot.common.InterfaceResultEnum;
+import com.welampiot.dto.EmergencyInfoLogDTO;
+import com.welampiot.dto.LampPoleDTO;
+import com.welampiot.dto.WeatherDTO;
+import com.welampiot.service.EmergencyInfoLogService;
+import com.welampiot.service.LampPoleService;
+import com.welampiot.utils.ToolUtils;
+import com.welampiot.utils.WeatherUtil;
+import com.welampiot.vo.EmergencyInfoLogVO;
+import com.welampiot.vo.LampPoleVO;
+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;
+import java.util.List;
+
+/**
+ * ClassName: NewLampPoleController2
+ * Package: com.welampiot.controller
+ * Description:
+ *
+ * @Author: zhj_Start
+ * @Create: 2023/8/31 - 11:29
+ * @Version: v1.0
+ */
+@RestController
+@CrossOrigin
+@RequestMapping("/newLampPole2")
+public class NewLampPoleController2 {
+    @Autowired
+    private ToolUtils toolUtils;
+    @Autowired
+    private LampPoleService lampPoleService;
+    @Autowired
+    private EmergencyInfoLogService emergencyInfoLogService;
+
+    /**
+     * 智诺云智慧灯杆列表
+     * @param request sectionList
+     * @return 灯杆列表
+     */
+    @RequestMapping(value = "/lampPoleList", method = RequestMethod.POST)
+    public BaseResult<?> lampPoleList(HttpServletRequest request) {
+        Integer version = (Integer) toolUtils.getRequestContent(request, "version", 1);
+        Integer areaId = (Integer) toolUtils.getRequestContent(request, "areaId", 1);
+        Integer sectionId = (Integer) toolUtils.getRequestContent(request, "sectionId", 1);
+        Integer page = (Integer) toolUtils.getRequestContent(request, "page", 1);
+        Integer count = (Integer) toolUtils.getRequestContent(request, "count", 1);
+        if (page == 0) page = 1;
+        if (count == 0) count = 16;
+        LampPoleVO lampPoleVO = new LampPoleVO();
+        lampPoleVO.setVersion(version);
+        lampPoleVO.setAreaId(areaId);
+        lampPoleVO.setSectionId(sectionId);
+        lampPoleVO.setLimit(count * (page - 1));
+        lampPoleVO.setOffset(count);
+        lampPoleVO.setSectionList(toolUtils.getSectionList(request));
+        List<LampPoleDTO> list = lampPoleService.getNewLampPoleList2(lampPoleVO);
+        for (LampPoleDTO dto : list) {
+            if (dto.getDevType() != null && !dto.getDevType().isEmpty()) {
+                String devType = dto.getDevType();
+                int length = devType.split(",").length;
+                dto.setDevCount(length);
+            } else {
+                dto.setDevCount(0);
+            }
+            if (dto.getAlarmStatus() != null && dto.getAlarmStatus() == 2) {
+                dto.setAlarmStatus(0);
+            } else if (dto.getAlarmStatus() != null && dto.getAlarmStatus() != 2) {
+                dto.setAlarmStatus(1);
+            }
+        }
+        LampPoleVO lampPoleVO1 = new LampPoleVO();
+        lampPoleVO1.setList(list);
+        Integer total = lampPoleService.getLampPoleInstallTotal(lampPoleVO);
+        lampPoleVO1.setTotal(total);
+        return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version,lampPoleVO1);
+    }
+
+    /**
+     * 智诺云智慧灯杆详情
+     * @param request id
+     * @return 灯杆详情
+     */
+    @RequestMapping(value = "/lampPoleDetail", method = RequestMethod.POST)
+    public BaseResult<?> lampPoleDetail(HttpServletRequest request) throws Exception {
+        Integer version = (Integer) toolUtils.getRequestContent(request, "version", 1);
+        Integer id = (Integer) toolUtils.getRequestContent(request, "id", 1);
+        if (id == 0) return toolUtils.response(InterfaceResultEnum.LACK_PARAM_ERROR,version);
+
+        LampPoleVO lampPoleVO = new LampPoleVO();
+        lampPoleVO.setId(id);
+        LampPoleDTO lampPoleDTO = lampPoleService.getLampPoleDetails(lampPoleVO);
+        if (lampPoleDTO == null) return toolUtils.response(InterfaceResultEnum.PARAM_FAIL,version);
+        Float longitude = lampPoleDTO.getLongitude();
+        Float latitude = lampPoleDTO.getLatitude();
+
+        // 获取实时天气信息
+        WeatherDTO weatherDTO = WeatherUtil.getNowWeatherInfo(String.valueOf(longitude), String.valueOf(latitude));
+        lampPoleDTO.setTemp(weatherDTO.getTemp());         // 实时温度
+        lampPoleDTO.setWeatherCode(weatherDTO.getIcon());  // 天气状况图标代码
+        lampPoleDTO.setWeatherText(weatherDTO.getText());  // 天气状况描述
+        lampPoleDTO.setAirLevel(weatherDTO.getLevel());   // 实时空气指数级数
+        lampPoleDTO.setAirCount(weatherDTO.getAqi());     // 实时空气质量指数
+
+        // 获取报警列表
+        EmergencyInfoLogVO emergencyInfoLogVO = new EmergencyInfoLogVO();
+        List<EmergencyInfoLogDTO> nowEmList = emergencyInfoLogService.getNowEmergencyInfoLogList(emergencyInfoLogVO);
+        List<EmergencyInfoLogDTO> hisEmList = emergencyInfoLogService.getHistoryEmergencyInfoLogList(emergencyInfoLogVO);
+        lampPoleDTO.setNowEmList(nowEmList);
+        lampPoleDTO.setHisEmList(hisEmList);
+        LampPoleVO lampPoleVO1 = new LampPoleVO();
+        lampPoleVO1.setLampPoleInfo(lampPoleDTO);
+        return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version,lampPoleVO1);
+    }
+}

+ 5 - 0
src/main/java/com/welampiot/dao/EmergencyInfoLogDao.java

@@ -1,6 +1,7 @@
 package com.welampiot.dao;
 
 import com.welampiot.dto.EmergencyInfoLogDTO;
+import com.welampiot.vo.EmergencyInfoLogVO;
 import org.apache.ibatis.annotations.Param;
 
 import java.util.List;
@@ -16,4 +17,8 @@ import java.util.List;
  */
 public interface EmergencyInfoLogDao {
     List<EmergencyInfoLogDTO> getEmergencyInfoLogListBySectionList(@Param("sectionList") List<Integer> sectionList);
+
+    List<EmergencyInfoLogDTO> getNowEmergencyInfoLogList(EmergencyInfoLogVO vo);
+
+    List<EmergencyInfoLogDTO> getHistoryEmergencyInfoLogList(EmergencyInfoLogVO vo);
 }

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

@@ -39,4 +39,6 @@ public interface LampPoleDao {
     List<LampPoleDTO> getSectionLampPoleList(LampPoleVO vo);
     List<LampPoleDTO> getLampPoleByLampIds(@Param("lampIds") List<String> lampIds);
     void updateLampPoleIcon(LampPoleDTO dto);
+    List<LampPoleDTO> getNewLampPoleList2(LampPoleVO vo);
+    LampPoleDTO getLampPoleDetails(LampPoleVO vo);
 }

+ 4 - 0
src/main/java/com/welampiot/dto/EmergencyInfoLogDTO.java

@@ -24,4 +24,8 @@ public class EmergencyInfoLogDTO implements Serializable {
     private String endDate; // 报警结束时间
 
     private String name;
+
+    private String section;
+
+    private String updateTime;
 }

+ 27 - 0
src/main/java/com/welampiot/dto/LampPoleDTO.java

@@ -64,4 +64,31 @@ public class LampPoleDTO {
     private Integer select;
     private Integer dir;
     private String iconInfo;
+    private Integer devCount;
+    private Integer netStatus;
+    private Integer alarmStatus;
+    private String num;
+    private String usedEnergyTotal; // 累计用电量
+    private String powerSave; // 累计省电量
+    private Integer workTimeTotal; // 累计亮灯时间
+    private String temp;
+    private String weatherCode;
+    private String weatherText;
+    private String airCount;
+    private String airLevel;
+    private String videoUrl;
+    private Integer netType;
+    private String broadcastName;
+    private String image;
+    private Integer deviceType;
+    private Integer chargeStatus;
+    private String billAmt;
+    private String energy;
+    private String dayFlow;
+    private String flow;
+    private Integer dayDeviceCount;
+    private Integer deviceCount;
+    private Integer cloudModel;
+    private List<EmergencyInfoLogDTO> nowEmList;
+    private List<EmergencyInfoLogDTO> hisEmList;
 }

+ 22 - 0
src/main/java/com/welampiot/dto/WeatherDTO.java

@@ -0,0 +1,22 @@
+package com.welampiot.dto;
+
+import lombok.Data;
+
+/**
+ * ClassName: WeatherDTO
+ * Package: com.welampiot.dto
+ * Description:
+ *
+ * @Author: zhj_Start
+ * @Create: 2023/8/31 - 18:34
+ * @Version: v1.0
+ */
+@Data
+public class WeatherDTO {
+    private String temp; // 温度
+    private String text; // 天气状况描述
+    private String icon; // 天气状况图标代码
+    private String aqi; // 空气质量指数
+    private String level; // 空气质量水平
+    private String category; // 空气质量等级
+}

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

@@ -1,6 +1,7 @@
 package com.welampiot.service;
 
 import com.welampiot.dto.EmergencyInfoLogDTO;
+import com.welampiot.vo.EmergencyInfoLogVO;
 
 import java.util.List;
 
@@ -15,4 +16,8 @@ import java.util.List;
  */
 public interface EmergencyInfoLogService {
     List<EmergencyInfoLogDTO> getEmergencyInfoLogListBySectionList(List<Integer> sectionList);
+
+    List<EmergencyInfoLogDTO> getNowEmergencyInfoLogList(EmergencyInfoLogVO vo);
+
+    List<EmergencyInfoLogDTO> getHistoryEmergencyInfoLogList(EmergencyInfoLogVO vo);
 }

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

@@ -33,4 +33,6 @@ public interface LampPoleService {
     List<LampPoleDTO> getSectionLampPoleList(LampPoleVO vo);
     List<LampPoleDTO> getLampPoleByLampIds(List<String> lampIds);
     void updateLampPoleIcon(LampPoleDTO dto);
+    List<LampPoleDTO> getNewLampPoleList2(LampPoleVO vo);
+    LampPoleDTO getLampPoleDetails(LampPoleVO vo);
 }

+ 11 - 0
src/main/java/com/welampiot/service/impl/EmergencyInfoLogServiceImpl.java

@@ -3,6 +3,7 @@ package com.welampiot.service.impl;
 import com.welampiot.dao.EmergencyInfoLogDao;
 import com.welampiot.dto.EmergencyInfoLogDTO;
 import com.welampiot.service.EmergencyInfoLogService;
+import com.welampiot.vo.EmergencyInfoLogVO;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
@@ -26,4 +27,14 @@ public class EmergencyInfoLogServiceImpl implements EmergencyInfoLogService {
     public List<EmergencyInfoLogDTO> getEmergencyInfoLogListBySectionList(List<Integer> sectionList) {
         return emergencyInfoLogDao.getEmergencyInfoLogListBySectionList(sectionList);
     }
+
+    @Override
+    public List<EmergencyInfoLogDTO> getNowEmergencyInfoLogList(EmergencyInfoLogVO vo) {
+        return emergencyInfoLogDao.getNowEmergencyInfoLogList(vo);
+    }
+
+    @Override
+    public List<EmergencyInfoLogDTO> getHistoryEmergencyInfoLogList(EmergencyInfoLogVO vo) {
+        return emergencyInfoLogDao.getHistoryEmergencyInfoLogList(vo);
+    }
 }

+ 10 - 0
src/main/java/com/welampiot/service/impl/LampPoleServiceImpl.java

@@ -444,6 +444,16 @@ public class LampPoleServiceImpl implements LampPoleService {
         lampPoleDao.updateLampPoleIcon(dto);
     }
 
+    @Override
+    public List<LampPoleDTO> getNewLampPoleList2(LampPoleVO vo) {
+        return lampPoleDao.getNewLampPoleList2(vo);
+    }
+
+    @Override
+    public LampPoleDTO getLampPoleDetails(LampPoleVO vo) {
+        return lampPoleDao.getLampPoleDetails(vo);
+    }
+
     @Override
     public Integer getAlarmCountByVO(LampPoleCountVO lampPoleCountVO) {
         return lampPoleDao.getAlarmCountByVO(lampPoleCountVO);

+ 87 - 0
src/main/java/com/welampiot/utils/WeatherUtil.java

@@ -0,0 +1,87 @@
+package com.welampiot.utils;
+
+import com.welampiot.dto.WeatherDTO;
+import lombok.Data;
+import org.json.JSONObject;
+import org.springframework.http.HttpMethod;
+import org.springframework.web.client.RestTemplate;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.charset.StandardCharsets;
+import java.util.zip.GZIPInputStream;
+
+/**
+ * ClassName: WeatherUtil
+ * Package: com.welampiot.utils
+ * Description: 调用和风天气接口
+ *
+ * @Author: zhj_Start
+ * @Create: 2023/8/31 - 16:37
+ * @Version: v1.0
+ */
+@Data
+public class WeatherUtil {
+    private String code; // 状态码
+    private String updateTime; // 天气情况更新时间
+    private String fxLink; // 数据的响应式页面
+    private Object now; // 实时天气
+
+    /**
+     * 获取实时天气信息
+     * @param longitude 经度
+     * @param latitude 纬度
+     * @return 返回天气信息
+     * @throws Exception 异常
+     */
+    public static WeatherDTO getNowWeatherInfo(String longitude, String latitude) throws Exception {
+        String url = "https://devapi.qweather.com/v7/weather/now?location=" + longitude + "," + latitude +
+                "&key=2dca03c7d95c442ba8fbce9d7a96db78";
+        RestTemplate restTemplate = new RestTemplate();
+        byte[] oResult = restTemplate.exchange(url, HttpMethod.GET, null, byte[].class).getBody();
+        String unGZipResult = unGZip(oResult);
+
+        JSONObject jsonObject = new JSONObject(unGZipResult);
+        JSONObject object = jsonObject.getJSONObject("now");
+        String temp = object.getString("temp"); // 实时天气温度
+        String text = object.getString("text"); // 实时天气状况描述
+        String icon = object.getString("icon"); // 实时天气状况图标代码
+        WeatherDTO weatherDTO = new WeatherDTO();
+        weatherDTO.setTemp(temp);
+        weatherDTO.setIcon(icon);
+        weatherDTO.setText(text);
+
+        url = "https://devapi.qweather.com/v7/air/now?location=" + longitude + "," + latitude +
+                "&key=2dca03c7d95c442ba8fbce9d7a96db78";
+        restTemplate = new RestTemplate();
+        byte[] oResult1 = restTemplate.exchange(url, HttpMethod.GET, null, byte[].class).getBody();
+        String unGZipResult1 = unGZip(oResult1);
+
+        JSONObject jsonObject1 = new JSONObject(unGZipResult1);
+        JSONObject object1 = jsonObject1.getJSONObject("now");
+        String aqi = object1.getString("aqi"); // 实时空气质量指数
+        String level = object1.getString("level"); // 实时空气质量指数水平级数
+        String category = object1.getString("category"); // 实时空气质量指数等级
+        weatherDTO.setLevel(level);
+        weatherDTO.setCategory(category);
+        weatherDTO.setAqi(aqi);
+        return weatherDTO;
+    }
+
+    public static String unGZip(byte[] oResult) throws Exception {
+        try (InputStream inputStream = new ByteArrayInputStream(oResult);
+             ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
+             GZIPInputStream gzipInputStream = new GZIPInputStream(inputStream)) {
+            byte[] buf = new byte[4096];
+            int len;
+            while ((len = gzipInputStream.read(buf, 0, buf.length)) != -1) {
+                byteArrayOutputStream.write(buf, 0, len);
+            }
+            return new String(byteArrayOutputStream.toByteArray(), StandardCharsets.UTF_8);
+        } catch (IOException e) {
+            throw new Exception(e);
+        }
+    }
+}

+ 1 - 0
src/main/java/com/welampiot/vo/EmergencyInfoLogVO.java

@@ -18,4 +18,5 @@ import java.util.List;
 @Data
 public class EmergencyInfoLogVO implements Serializable {
     private List<EmergencyInfoLogDTO> list;
+    private List sectionList;
 }

+ 2 - 0
src/main/java/com/welampiot/vo/LampPoleVO.java

@@ -10,6 +10,7 @@ import java.util.Map;
 @Data
 public class LampPoleVO implements Serializable {
     private List sectionList; // 路段筛选
+    private Integer total;
     private Integer devType;
     private Integer devId;
     private List<Map> lightDevList;
@@ -42,4 +43,5 @@ public class LampPoleVO implements Serializable {
     private Integer dir;
     private String iconInfo;
     private List<LampPoleDTO> list;
+    private LampPoleDTO lampPoleInfo;
 }

+ 40 - 0
src/main/resources/mapper/EmergencyInfoLogMapper.xml

@@ -17,4 +17,44 @@
         </if>
     </select>
 
+    <select id="getNowEmergencyInfoLogList" resultType="EmergencyInfoLogDTO">
+        select
+        lp.name,
+        e.beginDate as updateTime,
+        s.name as section
+        from emergency_info_log e
+        left join emergency e1 on e.deviceid = e.id
+        left join lamp_pole lp on e1.lamp_pole_id = lp.id
+        left join section s on s.id = lp.sectionid
+        where (e1.status = 2 or e1.status = 3) and lp.id is not null and s.id is not null
+        <if test="sectionList != null and !sectionList.isEmpty()">
+            and lp.sectionid in
+            <foreach collection="sectionList" item="item" open="(" separator="," close=")">
+                #{item}
+            </foreach>
+        </if>
+        order by e.beginDate desc
+        limit 10
+    </select>
+
+    <select id="getHistoryEmergencyInfoLogList" resultType="EmergencyInfoLogDTO">
+        select
+        lp.name,
+        e.beginDate as updateTime,
+        s.name as section
+        from emergency_info_log e
+        left join emergency e1 on e.deviceid = e.id
+        left join lamp_pole lp on e1.lamp_pole_id = lp.id
+        left join section s on s.id = lp.sectionid
+        where (e1.status != 2 and e1.status != 3) and lp.id is not null and s.id is not null
+        <if test="sectionList != null and !sectionList.isEmpty()">
+            and lp.sectionid in
+            <foreach collection="sectionList" item="item" open="(" separator="," close=")">
+                #{item}
+            </foreach>
+        </if>
+        order by e.beginDate desc
+        limit 20
+    </select>
+
 </mapper>

+ 61 - 0
src/main/resources/mapper/LampPoleMapper.xml

@@ -623,5 +623,66 @@
         where
             l.id = #{id}
     </update>
+
+    <!-- 智诺云智慧灯杆地图灯杆列表 -->
+    <select id="getNewLampPoleList2" resultType="LampPoleDTO">
+        select lp.id,w.num,lp.name,s.name as section,n.status as netStatus,
+               l.status,lp.devtype as devType,a.status as alarmStatus
+                <choose>
+                    <when test="version == 0">
+                        ,gl.chinese_name as area
+                    </when>
+                    <when test="version == 1">
+                        ,gl.english_name as area
+                    </when>
+                    <otherwise>
+                        ,gl.ru_name as area
+                    </otherwise>
+                </choose>
+        from lamp_pole lp
+        left join section s on s.id = lp.sectionid
+        left join global_location gl on gl.id = s.pid
+        left join lampinfo l on lp.id = l.lamp_pole_id
+        left join wifi w on lp.id = w.lamp_pole_id
+        left join network n on l.networkid = n.id
+        LEFT JOIN all_alarm_info_log AS a ON a.lampid = lp.id and a.devType = 1
+        where 1=1
+        <if test="sectionList != null and !sectionList.isEmpty()">
+            and lp.sectionid in 
+            <foreach collection="sectionList" item="item" open="(" separator="," close=")">
+                #{item}
+            </foreach>
+        </if>
+        <if test="areaId != null and areaId != 0">
+            and lp.areaid = #{areaId}
+        </if>
+        <if test="sectionId != null and sectionId != 0">
+            and lp.sectionid = #{sectionId}
+        </if>
+        <if test="limit >= 0 and offset > 0">
+            limit #{limit},#{offset}
+        </if>
+    </select>
+
+    <select id="getLampPoleDetails" resultType="LampPoleDTO">
+        select lp.id,lp.name,lp.devtype as devType,l.lighteness,p.name as policyName,lp.longitude,lp.latitude,
+               vm.net_type as netType,vm.deviceType,vm.address as videoUrl,vm.image,b.name as broadcastName,
+               c.status as chargeStatus,c.bill_amt as billAmt,c.energy,w.day_flow as dayFlow,w.flow,
+               w.day_device_count as dayDeviceCount,w.device_count as deviceCount,w.model as cloudModel,
+               l2.total_gener_energy_cache as usedEnergyTotal,l2.total_ele_save_cache as powerSave,
+               l2.work_time_total as workTimeTotal
+        from lamp_pole lp
+        left join lampinfo l on lp.id = l.lamp_pole_id
+        left join lamp_info_log_new l2 on l2.lampid = l.id
+        left join network n on l.networkid = n.id
+        left join policy p on p.id = l.policyid
+        left join video_monitor vm on lp.id = vm.lamp_pole_id
+        left join screen s on lp.id = s.lamp_pole_id
+        left join broadcast b on lp.id = b.lamp_pole_id
+        left join charge c on lp.id = c.lamp_pole_id
+        left join envmonitor e on lp.id = e.lamp_pole_id
+        left join wifi w on lp.id = w.lamp_pole_id
+        where lp.id = #{id}
+    </select>
     
 </mapper>