Explorar el Código

智能照明数据概览模块

crazycat hace 2 años
padre
commit
0ae64b30b6

+ 8 - 2
pom.xml

@@ -162,13 +162,19 @@
         <dependency>
             <groupId>org.apache.httpcomponents</groupId>
             <artifactId>httpclient</artifactId>
-            <version>4.5.10</version>
+<!--            <version>4.5.10</version>-->
         </dependency>
+
         <dependency>
             <groupId>org.apache.httpcomponents</groupId>
             <artifactId>httpmime</artifactId>
             <version>4.5.12</version>
         </dependency>
+        <dependency>
+            <groupId>org.apache.httpcomponents</groupId>
+            <artifactId>httpclient</artifactId>
+            <version>4.5.13</version>
+        </dependency>
 
     </dependencies>
 
@@ -224,7 +230,7 @@
             </resource>
             <resource>
                 <directory>src/main/resources/${profiles.active}</directory>
-                <filtering>true</filtering>
+<!--                <filtering>true</filtering>-->
                 <includes>
                     <include>*.yml</include>
                     <include>*.xml</include>

+ 40 - 29
src/main/java/com/welampiot/controller/DataController.java

@@ -6,6 +6,7 @@ import com.welampiot.dto.*;
 import com.welampiot.service.*;
 import com.welampiot.utils.ExcelUtil;
 import com.welampiot.utils.ToolUtils;
+import com.welampiot.utils.WebUtils;
 import com.welampiot.vo.*;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -15,6 +16,8 @@ import org.springframework.web.bind.annotation.RequestMethod;
 import org.springframework.web.bind.annotation.RestController;
 
 import javax.servlet.http.HttpServletRequest;
+import java.math.BigDecimal;
+import java.math.RoundingMode;
 import java.text.DecimalFormat;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
@@ -47,6 +50,8 @@ public class DataController {
     private RepairPersonnelService repairPersonnelService;
     @Autowired
     private LampInfoCacheByDayService lampInfoCacheByDayService;
+    @Autowired
+    private SectionCacheByDayService sectionCacheByDayService;
 
     @RequestMapping(value = "/info",method = RequestMethod.POST)
     public BaseResult<InfoResponseVO> info(HttpServletRequest request){
@@ -57,12 +62,12 @@ public class DataController {
         InfoResponseVO data = new InfoResponseVO();
         data.setCompany(toolUtils.getUser().getCompany());
         data.setCompanyAddress(toolUtils.getUser().getAddress());
-        Integer userId = toolUtils.getUser().getId();
-        Integer role = toolUtils.getUser().getRole();
+
         //设备数量,路灯数量,灯杆数量
         LampCountVO lampCountVO = new LampCountVO();
         if (!sectionList.isEmpty()) lampCountVO.setSectionList(sectionList);
         data.setLampCount(lampService.getCountByVO(lampCountVO)); // 灯控总数
+        data.setDevCount(data.getLampCount()); // 灯控总数
         lampCountVO.setOnlineStatus(1);
         lampCountVO.setLampStatus(1);
         data.setLightCount(lampService.getCountByVO(lampCountVO)); // 亮灯数
@@ -85,61 +90,67 @@ public class DataController {
 
         SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd 00:00:00");
         lampCountVO.setStartDate(simpleDateFormat.format(new Date()).toString());
-        Float dayConsumptionByVO = lampService.getDayConsumptionByVO(lampCountVO);
-        data.setDayConsumption((float) (Math.round(dayConsumptionByVO*100)/100f));
+//        Float dayConsumptionByVO = lampService.getDayConsumptionByVO(lampCountVO);
+//        data.setDayConsumption((float) (Math.round(dayConsumptionByVO*100)/100f));
         simpleDateFormat = new SimpleDateFormat("yyyy-MM-01 00:00:00");
         // 当月
         LampVO lampVO = new LampVO();
         lampVO.setSectionList(sectionList);
+        // 灯控故障数,在线数
+        data.setAlarmCount(lampService.getAlarmCountByVO(lampVO));
+        data.setOnlineCount(lampService.getOnlineCountByVO(lampVO));
+
         LampInfoLogNewDTO comBySectionList = lampService.getComBySectionList(lampVO);
-        comBySectionList.getDayGeneraEnergy();
-//        lampCountVO.setStartDate(simpleDateFormat.format(new Date()).toString());
+        data.setDaySavePower((float) (Math.round(Float.valueOf(comBySectionList.getDayEleSave())*100)/100f));
+        data.setDayConsumption((float) (Math.round(Float.valueOf(comBySectionList.getDayGeneraEnergy())*100)/100f));
+
         Float monthConsumption = Float.valueOf(comBySectionList.getDayGeneraEnergy())+Float.valueOf(comBySectionList.getMonthGeneraEnergyCache());
-//        monthConsumption = monthConsumption == null ? 0 : monthConsumption;
-        data.setMonthConsumption((float) (Math.round((dayConsumptionByVO+monthConsumption)*100)/100f));
+        data.setMonthConsumption((float) (Math.round((monthConsumption)*100)/100f));
         // 当年
         simpleDateFormat = new SimpleDateFormat("yyyy-01-01 00:00:00");
-//        lampCountVO.setStartDate(simpleDateFormat.format(new Date()).toString());
-//        Float yearConsumption = lampService.getConsumptionByVO(lampCountVO);
-//        yearConsumption = yearConsumption == null ? 0 : yearConsumption;
         Float yearConsumption = Float.valueOf(comBySectionList.getDayGeneraEnergy())+Float.valueOf(comBySectionList.getYearGeneraEnergyCache());
-        data.setYearConsumption((float) (Math.round((dayConsumptionByVO+yearConsumption)*100)/100f));
+        data.setYearConsumption((float) (Math.round((yearConsumption)*100)/100f));
         // 累计
-//        lampCountVO.setStartDate(null);
-//        Float totalConsumption = lampService.getConsumptionByVO(lampCountVO);
-//        totalConsumption = totalConsumption == null ? 0 : totalConsumption;
-        Float totalConsumption = Float.valueOf(comBySectionList.getDayGeneraEnergy())+Float.valueOf(comBySectionList.getTotalGeneraEnergyCache());
-        data.setTotalConsumption((float) (Math.round((dayConsumptionByVO+totalConsumption)*100)/100f));
-//        Date startDate = new Date(System.currentTimeMillis() - 20*24*3600*1000);
+        double v = (double) (Math.round(Float.valueOf(comBySectionList.getDayGeneraEnergy())*100)/100f);
+        double v2 = (double) (Math.round(Float.valueOf(comBySectionList.getTotalGeneraEnergyCache())*100)/100f);
+        data.setTotalConsumption(WebUtils.round(v+v2,2));
+        data.setTotalElectricharge(WebUtils.round(data.getTotalConsumption() * 0.75,2));
+        data.setTotalCarbonEmission(WebUtils.round(data.getTotalConsumption() * 0.785/1000,3));
+
+        Double totalEleSaveCache = Double.valueOf(comBySectionList.getDayEleSave())+Double.valueOf(comBySectionList.getTotalEleSaveCache());
+        data.setTotalSavePower(WebUtils.round(totalEleSaveCache,2));
+        data.setTotalSaveElectricharge(WebUtils.round(data.getTotalSavePower() * 0.75,2));
+        data.setTotalSaveCarbonEmission(WebUtils.round(data.getTotalSavePower() * 0.785/1000,3));
+
         Date endDate = new Date(System.currentTimeMillis() - 24*3600*1000);
         Calendar calendar = Calendar.getInstance();
         calendar.setTime(endDate);
         calendar.add(Calendar.MONDAY, -1);
 
         simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd 00:00:00");
-//        Date startDate = simpleDateFormat.format(calendar.getTime());
-//        for (int i = 0; i < 30; i++) {
-//            long t = startDate.getTime() + i * 24 * 3600 * 1000;
-//        }
-        lampCountVO.setStartDate(simpleDateFormat.format(calendar.getTime()));
-        lampCountVO.setEndDate(simpleDateFormat.format(endDate).toString());
-        System.out.println(lampCountVO.getStartDate());
-        System.out.println(lampCountVO.getEndDate());
-        List<LampLogVO> consumptionListByVO = lampService.getConsumptionListByVO(lampCountVO);
+        SectionCacheByDayDTO sectionCacheByDayDTO = new SectionCacheByDayDTO();
+        sectionCacheByDayDTO.setStartDate(simpleDateFormat.format(calendar.getTime()));
+        sectionCacheByDayDTO.setEndDate(simpleDateFormat.format(endDate).toString());
+
+        List<SectionCacheByDayDTO> consumptionListByDTO = sectionCacheByDayService.getConsumptionListByDTO(sectionCacheByDayDTO);
         simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
         List date = new ArrayList<>();
         List value = new ArrayList<>();
         List savePower = new ArrayList<>();
-        for (LampLogVO t :consumptionListByVO) {
-            String updateTime = simpleDateFormat.format(t.getUpdateTime()).toString();
+        List lightDev = new ArrayList<>();
+        for (SectionCacheByDayDTO t :consumptionListByDTO) {
+//            String updateTime = simpleDateFormat.format(t.getUpdateTime()).toString();
+            String updateTime = t.getUpdateTime();
             Float consumption = t.getConsumption();
             Float powerSave = t.getPowerSave();
             date.add(updateTime);
             value.add((float) (Math.round((consumption)*100)/100f));
             savePower.add((float) (Math.round((powerSave)*100)/100f));
+            lightDev.add(t.getLightCount());
         }
         data.setDate(date);
         data.setValue(value);
+        data.setLightDev(lightDev);
         data.setSavePower(savePower);
         return BaseResult.success(data);
     }

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

@@ -54,4 +54,6 @@ public interface LampDao {
     List<LampInfoDTO> getLampEleUseSectionTop(LampInfoDTO dto);
     List<LampInfoDTO> getLampInfoAlarmList(LampInfoDTO dto);
     List<LampInfoDTO> getLampAlarmTotal(LampInfoDTO dto);
+    int getAlarmCountByVO(LampVO lampVO);
+    int getOnlineCountByVO(LampVO lampVO);
 }

+ 9 - 0
src/main/java/com/welampiot/dao/SectionCacheByDayDao.java

@@ -0,0 +1,9 @@
+package com.welampiot.dao;
+
+import com.welampiot.dto.SectionCacheByDayDTO;
+
+import java.util.List;
+
+public interface SectionCacheByDayDao {
+    List<SectionCacheByDayDTO> getConsumptionListByDTO(SectionCacheByDayDTO dto);
+}

+ 1 - 0
src/main/java/com/welampiot/dto/LampInfoLogNewDTO.java

@@ -77,5 +77,6 @@ public class LampInfoLogNewDTO implements Serializable {
 
     private String sumDayGeneraEnergy; // 当天用电量之和
 
+    private String dayEleSave; // 当天省电量
     private String sumDayEleSave; // 当天省电量之和
 }

+ 16 - 0
src/main/java/com/welampiot/dto/SectionCacheByDayDTO.java

@@ -0,0 +1,16 @@
+package com.welampiot.dto;
+
+import lombok.Data;
+
+import java.util.List;
+
+@Data
+public class SectionCacheByDayDTO {
+    private String startDate;
+    private String endDate;
+    private List sectionList;
+    private float consumption;
+    private float powerSave;
+    private int lightCount;
+    private String updateTime;
+}

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

@@ -54,4 +54,6 @@ public interface LampService {
     List<LampInfoDTO> getLampEleUseSectionTop(LampInfoDTO dto);
     List<LampInfoDTO> getLampInfoAlarmList(LampInfoDTO dto);
     List<LampInfoDTO> getLampAlarmTotal(LampInfoDTO dto);
+    int getAlarmCountByVO(LampVO lampVO);
+    int getOnlineCountByVO(LampVO lampVO);
 }

+ 9 - 0
src/main/java/com/welampiot/service/SectionCacheByDayService.java

@@ -0,0 +1,9 @@
+package com.welampiot.service;
+
+import com.welampiot.dto.SectionCacheByDayDTO;
+
+import java.util.List;
+
+public interface SectionCacheByDayService {
+    List<SectionCacheByDayDTO> getConsumptionListByDTO(SectionCacheByDayDTO dto);
+}

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

@@ -675,6 +675,16 @@ public class LampServiceImpl implements LampService {
         return lampDao.getLampAlarmTotal(dto);
     }
 
+    @Override
+    public int getAlarmCountByVO(LampVO lampVO) {
+        return lampDao.getAlarmCountByVO(lampVO);
+    }
+
+    @Override
+    public int getOnlineCountByVO(LampVO lampVO) {
+        return lampDao.getOnlineCountByVO(lampVO);
+    }
+
     @Override
     public LampInfoLogNewDTO getComBySectionList(LampVO vo) {
         return lampDao.getComBySectionList(vo);

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

@@ -0,0 +1,20 @@
+package com.welampiot.service.impl;
+
+import com.welampiot.dao.SectionCacheByDayDao;
+import com.welampiot.dto.SectionCacheByDayDTO;
+import com.welampiot.service.SectionCacheByDayService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+@Service
+public class SectionCacheByDayServiceImpl implements SectionCacheByDayService {
+    @Autowired
+    private SectionCacheByDayDao sectionCacheByDayDao;
+
+    @Override
+    public List<SectionCacheByDayDTO> getConsumptionListByDTO(SectionCacheByDayDTO dto) {
+        return sectionCacheByDayDao.getConsumptionListByDTO(dto);
+    }
+}

+ 22 - 0
src/main/java/com/welampiot/utils/WebUtils.java

@@ -19,6 +19,8 @@ import java.io.BufferedReader;
 import java.io.DataOutputStream;
 import java.io.IOException;
 import java.io.InputStreamReader;
+import java.math.BigDecimal;
+import java.math.RoundingMode;
 import java.net.HttpURLConnection;
 import java.net.URL;
 import java.net.URLConnection;
@@ -199,4 +201,24 @@ public class WebUtils
         return result;
     }
 
+    /**
+     * double 数据保留几位小数
+     * @param n double 数据
+     * @param c 保留小数位数
+     * @return 返回装换结果
+     */
+    public static double round(double n,int c){
+        BigDecimal two1 = new BigDecimal(n);
+        return two1.setScale(c, RoundingMode.HALF_UP).doubleValue();
+    }
+    /**
+     * float 数据保留几位小数
+     * @param n float 数据
+     * @param c 保留小数位数
+     * @return 返回装换结果
+     */
+    public static double round(float n,int c){
+        BigDecimal two1 = new BigDecimal(n);
+        return two1.setScale(c, RoundingMode.HALF_UP).doubleValue();
+    }
 }

+ 12 - 1
src/main/java/com/welampiot/vo/InfoResponseVO.java

@@ -8,6 +8,8 @@ import java.util.List;
 public class InfoResponseVO {
     private Integer lightCount; // 亮灯数
     private Integer lampCount; // 灯控总数
+    private Integer alarmCount; // 故障数
+    private Integer onlineCount; // 在线数
     private Integer devCount; // 设备总数
     private String  company; // 公司名称
     private String  companyAddress; // 公司地址
@@ -17,9 +19,18 @@ public class InfoResponseVO {
     private Float dayConsumption; // 当日用电量
     private Float monthConsumption; // 当月用电量
     private Float yearConsumption; // 当年用电量
-    private Float totalConsumption; // 	累计用电量
+    private double totalConsumption; // 	累计用电量
+    private Float daySavePower; // 当日省电量
+    private Float monthSavePower; // 当月省电量
+    private Float yearSavePower; // 当年省电量
+    private double totalSavePower; // 	累计省电量
+    private double totalElectricharge; // 	累计电费
+    private double totalSaveElectricharge; // 	累计节省电费
+    private double totalCarbonEmission; // 	累计碳排放(t)
+    private double totalSaveCarbonEmission; // 		累计节约碳排放(t)
     private List date; // 报表时间轴
     private List value; // 用电量报表值
     private List savePower; // 	省电量报表值
+    private List lightDev; // 	亮灯数报表值
 
 }

+ 35 - 3
src/main/resources/mapper/LampMapper.xml

@@ -1006,11 +1006,43 @@
         ORDER BY DATE(a.updatetime) DESC
     </select>
     <select id="getComBySectionList" resultType="com.welampiot.dto.LampInfoLogNewDTO" parameterType="com.welampiot.vo.LampVO">
-        select sum(day_gener_energy) as dayGeneraEnergy,sum(month_gener_energy_cache) as monthGeneraEnergyCache,sum(year_gener_energy_cache) as yearGeneraEnergyCache,sum(total_gener_energy_cache) as totalGeneraEnergyCache from lampinfo a
+        select sum(b.day_gener_energy) as dayGeneraEnergy,
+        sum(b.month_gener_energy_cache) as monthGeneraEnergyCache,
+        sum(b.year_gener_energy_cache) as yearGeneraEnergyCache,
+        sum(b.total_gener_energy_cache) as totalGeneraEnergyCache,
+        sum(b.month_ele_save_cache) as monthEleSaveCache,
+        sum(b.year_ele_save_cache) as yearEleSaveCache,
+        sum(b.total_ele_save_cache) as totalEleSaveCache,
+        sum(b.day_ele_save) as dayEleSave
+        from lampinfo a
         left join lamp_info_log_new b on b.lampid = a.id
-        where 1=1
+        where a.id is not null and b.day_gener_energy &lt; 50 and b.day_ele_save &lt; 50
+        <if test="sectionList != null and !sectionList.isEmpty()">
+            and a.sectionid in
+            <foreach item="vo" collection="sectionList" open="(" separator="," close=")">
+                #{vo}
+            </foreach>
+        </if>
+    </select>
+
+    <select id="getAlarmCountByVO" resultType="int" parameterType="com.welampiot.vo.LampVO">
+        select count(*)
+        from lampinfo a
+        where ((a.faultstatus != 0 and a.faultstatus != 128) or a.new_faultstatus != 0)
         <if test="sectionList != null and !sectionList.isEmpty()">
-            and LP.sectionid in
+            and a.sectionid in
+            <foreach item="vo" collection="sectionList" open="(" separator="," close=")">
+                #{vo}
+            </foreach>
+        </if>
+    </select>
+    <select id="getOnlineCountByVO" resultType="int" parameterType="com.welampiot.vo.LampVO">
+        select count(*)
+        from lampinfo a
+        left join network b on a.networkid = b.id
+        where b.status = 1
+        <if test="sectionList != null and !sectionList.isEmpty()">
+            and a.sectionid in
             <foreach item="vo" collection="sectionList" open="(" separator="," close=")">
                 #{vo}
             </foreach>

+ 24 - 0
src/main/resources/mapper/SectionCacheByDayMapper.xml

@@ -0,0 +1,24 @@
+<?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.SectionCacheByDayDao">
+    <select id="getConsumptionListByDTO" resultType="com.welampiot.dto.SectionCacheByDayDTO" parameterType="com.welampiot.dto.SectionCacheByDayDTO">
+        select * from (
+        select sum(a.consum) as consumption,sum(a.powerSave) as powerSave,sum(lightCount) as lightCount,a.updatetime as updateTime
+        from section_cache_by_day a
+        where 1=1
+        <if test="sectionList != null and !sectionList.isEmpty()">
+            and a.sectionid in
+            <foreach item="vo" collection="sectionList" open="(" separator="," close=")">
+                #{vo}
+            </foreach>
+        </if>
+        <if test="startDate != null and startDate != ''">
+            and a.updatetime >= #{startDate}
+        </if>
+        <if test="endDate != null and endDate != ''">
+            and a.updatetime &lt;= #{endDate}
+        </if>
+        group by a.updatetime
+        ) as t order by t.updatetime asc
+    </select>
+</mapper>