Kaynağa Gözat

大屏接口

zhj 2 yıl önce
ebeveyn
işleme
751c583a5d

+ 219 - 0
src/main/java/com/welampiot/controller/BigScreenController.java

@@ -0,0 +1,219 @@
+package com.welampiot.controller;
+
+import com.welampiot.common.BaseResult;
+import com.welampiot.common.InterfaceResultEnum;
+import com.welampiot.dto.LampInfoCacheByDayDTO;
+import com.welampiot.dto.LampInfoDTO;
+import com.welampiot.service.LampInfoCacheByDayService;
+import com.welampiot.service.LampService;
+import com.welampiot.utils.ToolUtils;
+import com.welampiot.vo.LampInfoCacheByDayVO;
+import com.welampiot.vo.LampInfoVO;
+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.text.DecimalFormat;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+
+/**
+ * ClassName: BigScreenController
+ * Package: com.welampiot.controller
+ * Description:
+ *
+ * @Author: zhj_Start
+ * @Create: 2023/8/29 - 17:38
+ * @Version: v1.0
+ */
+@RestController
+@CrossOrigin
+@RequestMapping("/bigScreen")
+public class BigScreenController {
+    @Autowired
+    private ToolUtils toolUtils;
+    @Autowired
+    private LampInfoCacheByDayService lampInfoCacheByDayService;
+    @Autowired
+    private LampService lampService;
+
+    /**
+     * 用电量统计
+     * @param request sectionList
+     * @return 用电量统计
+     */
+    @RequestMapping(value = "/statistics", method = RequestMethod.POST)
+    public BaseResult<?> statistics(HttpServletRequest request) throws ParseException {
+        Integer version = (Integer) toolUtils.getRequestContent(request,"version",1);
+        long startTime = System.currentTimeMillis() - 24L * 3600 * 1000 * 30;
+        long endTime = System.currentTimeMillis() - 24 * 3600 * 1000;
+        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
+        String startDate = simpleDateFormat.format(startTime);
+        String endDate = simpleDateFormat.format(endTime);
+        LampInfoCacheByDayDTO dayDTO = new LampInfoCacheByDayDTO();
+        dayDTO.setStartDate(startDate);
+        dayDTO.setEndDate(endDate);
+        dayDTO.setSectionList(toolUtils.getSectionList(request));
+        List<LampInfoCacheByDayDTO> list = lampInfoCacheByDayService.getSectionOfMonthConSum(dayDTO);
+        DecimalFormat decimalFormat = new DecimalFormat("0.00");
+
+        HashMap<String, Integer> objectObjectHashMap = new HashMap<>();
+        long timeT = startTime;
+        int i = 0;
+        List<Object> dateList = new ArrayList<>();
+        List<Object> valueList = new ArrayList<>();
+
+        while (timeT <= endTime) {
+            objectObjectHashMap.put(simpleDateFormat.format(new Date(timeT)),i);
+            dateList.add(simpleDateFormat.format(new Date(timeT)));
+            valueList.add(0);
+            timeT += 3600 * 1000 * 24;
+            i ++;
+        }
+
+        for (LampInfoCacheByDayDTO dto : list) {
+            Date date = new Date(simpleDateFormat.parse(dto.getUpdateTime()).getTime());
+            String s = simpleDateFormat.format(date);
+            Integer integer = null;
+            if (objectObjectHashMap.containsKey(s)) {
+                integer = objectObjectHashMap.get(s);
+            }
+
+            if (dto.getConSum() != null && !dto.getConSum().equals("0") && integer != null) {
+                String formatConSum = decimalFormat.format(dto.getConSum());
+                valueList.set(integer, Float.parseFloat(formatConSum));
+            }
+        }
+
+        LampInfoCacheByDayVO lampInfoCacheByDayVO = new LampInfoCacheByDayVO();
+        lampInfoCacheByDayVO.setDate(dateList);
+        lampInfoCacheByDayVO.setValue(valueList);
+        return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version,lampInfoCacheByDayVO);
+    }
+
+    /**
+     * 故障数量TOP5地区
+     * @param request sectionList
+     * @return 故障数量TOP5地区
+     */
+    @RequestMapping(value = "/alarmTOP", method = RequestMethod.POST)
+    public BaseResult<?> alarmTOP(HttpServletRequest request) {
+        Integer version = (Integer) toolUtils.getRequestContent(request,"version",1);
+        LampInfoDTO lampInfoDTO = new LampInfoDTO();
+        lampInfoDTO.setVersion(version);
+        lampInfoDTO.setSectionList(toolUtils.getSectionList(request));
+        List<LampInfoDTO> list = lampService.getAlarmAreaCountTop(lampInfoDTO);
+        LampInfoVO lampInfoVO = new LampInfoVO();
+        lampInfoVO.setList(list);
+        return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version,lampInfoVO);
+    }
+
+    /**
+     * 用电量TOP5路段
+     * @param request sectionList
+     * @return 用电量TOP5路段
+     */
+    @RequestMapping(value = "/consumptionTOP", method = RequestMethod.POST)
+    public BaseResult<?> consumptionTOP(HttpServletRequest request) {
+        Integer version = (Integer) toolUtils.getRequestContent(request,"version",1);
+        LampInfoDTO lampInfoDTO = new LampInfoDTO();
+        lampInfoDTO.setSectionList(toolUtils.getSectionList(request));
+        List<LampInfoDTO> list = lampService.getLampEleUseSectionTop(lampInfoDTO);
+        DecimalFormat decimalFormat = new DecimalFormat("0.00");
+        for (LampInfoDTO dto : list) {
+            if (dto.getConsumption() != null && !dto.getConsumption().equals("0.0")) {
+                float consumption = Float.parseFloat(dto.getConsumption());
+                String format = decimalFormat.format(consumption);
+                dto.setConsumption(format);
+            } else if (dto.getConsumption() == null || dto.getConsumption().equals("0.0")) {
+                dto.setConsumption("0");
+            }
+        }
+        LampInfoVO lampInfoVO = new LampInfoVO();
+        lampInfoVO.setList(list);
+        return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version,lampInfoVO);
+    }
+
+    /**
+     * 故障信息列表
+     * @param request sectionList
+     * @return 故障信息列表
+     */
+    @RequestMapping(value = "/alarmList", method = RequestMethod.POST)
+    public BaseResult<?> alarmList(HttpServletRequest request) {
+        Integer version = (Integer) toolUtils.getRequestContent(request,"version",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;
+        LampInfoDTO lampInfoDTO = new LampInfoDTO();
+        lampInfoDTO.setPage(count * (page - 1));
+        lampInfoDTO.setCount(count);
+        lampInfoDTO.setVersion(version);
+        lampInfoDTO.setSectionList(toolUtils.getSectionList(request));
+        List<LampInfoDTO> list = lampService.getLampInfoAlarmList(lampInfoDTO);
+        LampInfoVO lampInfoVO = new LampInfoVO();
+        lampInfoVO.setList(list);
+        return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version,lampInfoVO);
+    }
+
+    /**
+     * 故障数量折线图
+     * @param request sectionList
+     * @return 故障数量折线图
+     */
+    @RequestMapping(value = "/alarmChart", method = RequestMethod.POST)
+    public BaseResult<?> alarmChart(HttpServletRequest request) throws ParseException {
+        Integer version = (Integer) toolUtils.getRequestContent(request,"version",1);
+
+        long startTime = System.currentTimeMillis() - 29L * 3600 * 1000 * 24;
+        long endTime = System.currentTimeMillis();
+        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
+        String startDate = simpleDateFormat.format(startTime);
+        String endDate = simpleDateFormat.format(endTime);
+        LampInfoDTO lampInfoDTO = new LampInfoDTO();
+        lampInfoDTO.setStartDate(startDate);
+        lampInfoDTO.setEndDate(endDate);
+        lampInfoDTO.setSectionList(toolUtils.getSectionList(request));
+        List<LampInfoDTO> list = lampService.getLampAlarmTotal(lampInfoDTO);
+
+        HashMap<String, Integer> objectObjectHashMap = new HashMap<>();
+        long timeT = startTime;
+        int i = 0;
+        List<Object> dateList = new ArrayList<>();
+        List<Object> valueList = new ArrayList<>();
+
+        while (timeT <= endTime) {
+            objectObjectHashMap.put(simpleDateFormat.format(new Date(timeT)),i);
+            dateList.add(simpleDateFormat.format(new Date(timeT)));
+            valueList.add(0);
+            timeT += 3600 * 1000 * 24;
+            i ++;
+        }
+
+        for (LampInfoDTO dto : list) {
+            Date date = new Date(simpleDateFormat.parse(dto.getUpdateTime()).getTime());
+            String s = simpleDateFormat.format(date);
+            Integer integer = null;
+            if (objectObjectHashMap.containsKey(s)) {
+                integer = objectObjectHashMap.get(s);
+            }
+
+            if (dto.getLampCount() != null && dto.getLampCount() != 0 && integer != null) {
+                valueList.set(integer, dto.getLampCount());
+            }
+        }
+
+        LampInfoVO lampInfoVO = new LampInfoVO();
+        lampInfoVO.setDate(dateList);
+        lampInfoVO.setValue(valueList);
+        return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version,lampInfoVO);
+    }
+}

+ 4 - 0
src/main/java/com/welampiot/dao/LampDao.java

@@ -48,4 +48,8 @@ public interface LampDao {
     Integer getLampCountByLampPoleId(@Param("lampPoleId") Integer lampPoleId);
     void updateLampInfoForLoopId(LampInfoDTO dto);
     List<LampInfoDTO> getLampInfoListForGroup(LampVO vo);
+    List<LampInfoDTO> getAlarmAreaCountTop(LampInfoDTO dto);
+    List<LampInfoDTO> getLampEleUseSectionTop(LampInfoDTO dto);
+    List<LampInfoDTO> getLampInfoAlarmList(LampInfoDTO dto);
+    List<LampInfoDTO> getLampAlarmTotal(LampInfoDTO dto);
 }

+ 8 - 0
src/main/java/com/welampiot/dto/LampInfoDTO.java

@@ -8,6 +8,7 @@ import java.util.List;
 public class LampInfoDTO {
     private Integer id;
     private String number;
+    private String alarmStr;
     private String sn;
     private String address;
     private String area;
@@ -74,7 +75,14 @@ public class LampInfoDTO {
     private String colourVal;
     private String keyword;
     private List<Integer> sectionList;
+    private Integer alarmCount;
     private Integer type;
     private Integer alarmType;
     private String serverTime;
+    private String consumption;
+    private Integer lampCount;
+    private Integer page;
+    private Integer count;
+    private String startDate;
+    private String endDate;
 }

+ 4 - 0
src/main/java/com/welampiot/service/LampService.java

@@ -48,4 +48,8 @@ public interface LampService {
     void updateLampInfoForLoopId(LampInfoDTO dto);
     List<LampInfoDTO> getLampInfoListForGroup(LampVO vo);
     LampInfoVO getLampConsumptionData(LampInfoDataVO vo) throws ParseException;
+    List<LampInfoDTO> getAlarmAreaCountTop(LampInfoDTO dto);
+    List<LampInfoDTO> getLampEleUseSectionTop(LampInfoDTO dto);
+    List<LampInfoDTO> getLampInfoAlarmList(LampInfoDTO dto);
+    List<LampInfoDTO> getLampAlarmTotal(LampInfoDTO dto);
 }

+ 20 - 0
src/main/java/com/welampiot/service/impl/LampServiceImpl.java

@@ -654,6 +654,26 @@ public class LampServiceImpl implements LampService {
         return lampInfoVO;
     }
 
+    @Override
+    public List<LampInfoDTO> getAlarmAreaCountTop(LampInfoDTO dto) {
+        return lampDao.getAlarmAreaCountTop(dto);
+    }
+
+    @Override
+    public List<LampInfoDTO> getLampEleUseSectionTop(LampInfoDTO dto) {
+        return lampDao.getLampEleUseSectionTop(dto);
+    }
+
+    @Override
+    public List<LampInfoDTO> getLampInfoAlarmList(LampInfoDTO dto) {
+        return lampDao.getLampInfoAlarmList(dto);
+    }
+
+    @Override
+    public List<LampInfoDTO> getLampAlarmTotal(LampInfoDTO dto) {
+        return lampDao.getLampAlarmTotal(dto);
+    }
+
     @Override
     public Integer updateLight(LampInfoDTO lampInfoDTO) {
         return lampDao.updateLight(lampInfoDTO);

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

@@ -30,6 +30,8 @@ public class LampInfoCacheByDayVO implements Serializable {
     private String saveEleFree; // 节省电费
 
     private List<Object> conSumList; // 用电量
+    private List<Object> value; // 用电量
+    private List<Object> date; // 用电量
 
     private List<Object> powerSaveList; // 省电量
 

+ 109 - 0
src/main/resources/mapper/LampMapper.xml

@@ -894,5 +894,114 @@
             and l.sectionid = #{secitonId}
         </if>
     </select>
+
+    <select id="getAlarmAreaCountTop" resultType="LampInfoDTO">
+        SELECT COUNT(*) AS alarmCount
+        <choose>
+            <when test="version == 0">
+                ,a.chinese_name AS area
+            </when>
+            <when test="version == 1">
+                ,a.english_name AS area
+            </when>
+            <otherwise>
+                ,a.ru_name AS area
+            </otherwise>
+        </choose>
+        FROM `lampinfo` l
+        LEFT JOIN global_location a ON a.id = l.areaid
+        WHERE l.faultstatus != 0 AND l.faultstatus != 128
+        <if test="sectionList != null and !sectionList.isEmpty()">
+            and l.sectionid IN
+            <foreach collection="sectionList" item="item" open="(" separator="," close=")">
+                #{item}
+            </foreach>
+        </if>
+        GROUP BY l.areaid
+        ORDER BY alarmCount DESC
+        LIMIT 5
+    </select>
+
+    <select id="getLampEleUseSectionTop" resultType="LampInfoDTO">
+        SELECT
+        COUNT(l.id) as lampCount,
+        s.name as section,
+        SUM(a.total_gener_energy_cache) as consumption
+        FROM lampinfo l
+        LEFT JOIN section s ON s.id = l.sectionid
+        LEFT JOIN lamp_info_log_new a ON a.lampid = l.id
+        <if test="sectionList != null and !sectionList.isEmpty()">
+            WHERE l.sectionid IN
+            <foreach collection="sectionList" item="item" open="(" separator="," close=")">
+                #{item}
+            </foreach>
+        </if>
+        GROUP BY l.sectionid
+        ORDER BY consumption DESC
+        LIMIT 5
+    </select>
+
+    <select id="getLampInfoAlarmList" resultType="LampInfoDTO">
+        SELECT
+        a.stralarmtype AS alarmStr,
+        a.updatetime AS updateTime,
+        l.number,
+        s.name AS section
+        <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 lampinfo l
+        LEFT JOIN section s ON s.id = l.sectionid
+        LEFT JOIN global_location gl ON gl.id = s.pid
+        LEFT JOIN
+             (SELECT t1.*
+              FROM all_alarm_info_log t1,
+                   (SELECT lampid,
+                           max(updatetime) AS maxtime
+                    FROM all_alarm_info_log
+                    GROUP BY lampid) t2
+              WHERE t1.lampid = t2.lampid
+                AND t1.updatetime = t2.maxtime) AS a ON a.lampid = l.id
+        WHERE a.devType = 0
+        <if test="sectionList != null and !sectionList.isEmpty()">
+            AND l.sectionid IN
+            <foreach collection="sectionList" item="item" open="(" separator="," close=")">
+                #{item}
+            </foreach>
+        </if>
+        ORDER BY a.updatetime DESC
+        <if test="page >= 0 and count > 0">
+            LIMIT #{page},#{count}
+        </if>
+    </select>
+
+    <select id="getLampAlarmTotal" resultType="LampInfoDTO">
+        SELECT
+        COUNT(l.id) AS lampCount,
+        DATE(a.updatetime) AS updateTime
+        FROM lampinfo l
+        LEFT JOIN
+        (SELECT t1.*
+         FROM all_alarm_info_log t1,
+              (SELECT lampid, MAX(updatetime) AS maxtime FROM all_alarm_info_log ORDER BY lampid) t2
+         WHERE t1.lampid = t2.lampid AND t1.updatetime = t2.maxtime) AS a ON a.lampid = l.id
+        WHERE a.devType = 0 AND a.updatetime <![CDATA[ <= ]]> #{endDate} AND a.updatetime >= #{startDate}
+        <if test="sectionList != null and !sectionList.isEmpty()">
+            AND l.sectionid IN
+            <foreach collection="sectionList" item="item" open="(" separator="," close=")">
+                #{item}
+            </foreach>
+        </if>
+        GROUP BY DATE(a.updatetime)
+        ORDER BY DATE(a.updatetime) DESC
+    </select>
     
 </mapper>