Просмотр исходного кода

根据用户路段权限计算灯控的平均使用年限,平均亮度,平均亮灯时长

zhj 9 месяцев назад
Родитель
Сommit
02c5747c40

+ 25 - 0
src/main/java/com/welampiot/controller/DataController.java

@@ -754,4 +754,29 @@ public class DataController extends BaseController {
         setLampLogData(baseVO, lampLogVO);
         return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS, version, lampLogVO);
     }
+
+    /**
+     * 灯控平均数据
+     */
+    @RequestMapping(value = "/lampAvgData", method = RequestMethod.POST)
+    public BaseResult<?> lampAvgData(BaseVO baseVO) {
+        Integer version = baseVO.getVersion();
+
+        List<Integer> sectionList = getSectionList(baseVO.getUsername());
+        baseVO.setSectionList(sectionList);
+        LampInfoDTO lampInfoDTO = lampService.getLampAvgDataByBaseVO(baseVO);
+
+        DecimalFormat df = new DecimalFormat("0.##");
+        LampInfoDataVO lampInfoDataVO = new LampInfoDataVO();
+        if (lampInfoDTO == null) {
+            lampInfoDataVO.setAveLightness("0");
+            lampInfoDataVO.setAveUsageYears("0");
+            lampInfoDataVO.setAveLightTime("0");
+        } else {
+            lampInfoDataVO.setAveLightness(df.format(lampInfoDTO.getAveLightness()));
+            lampInfoDataVO.setAveUsageYears(df.format(lampInfoDTO.getAveUsageYears()));
+            lampInfoDataVO.setAveLightTime(df.format(lampInfoDTO.getAveLightTime() / 60));
+        }
+        return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS, version, lampInfoDataVO);
+    }
 }

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

@@ -72,4 +72,5 @@ public interface LampDao {
     List<LampInfoDTO> getLampLocaltion(LampInfoDTO dto);
     LampInfoDTO getLampById(Integer id);
     List<LampInfoDTO> getLampListByIdList(@Param("idList") List<String> idList);
+    LampInfoDTO getLampAvgDataByBaseVO(BaseVO baseVO);
 }

+ 3 - 1
src/main/java/com/welampiot/dto/LampInfoDTO.java

@@ -2,7 +2,6 @@ package com.welampiot.dto;
 
 import com.welampiot.common.LampControlTypeEnum;
 import lombok.Data;
-import org.apache.poi.ss.formula.functions.T;
 
 import java.util.List;
 import java.util.Objects;
@@ -116,6 +115,9 @@ public class LampInfoDTO {
     private List<Object> powerSaveList; // 省电量列表
     private List<Object> saveList; // 省电量列表
     private String deviceId;
+    private Double aveLightness;
+    private Double aveUsageYears;
+    private Double aveLightTime;
     public LampInfoDTO(){
     }
     /**

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

@@ -72,4 +72,5 @@ public interface LampService {
     List<LampInfoDTO> getLampLocaltion(LampInfoDTO dto);
     LampInfoDTO getLampById(Integer id);
     List<LampInfoDTO> getLampListByIdList(List<String> idList);
+    LampInfoDTO getLampAvgDataByBaseVO(BaseVO baseVO);
 }

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

@@ -808,4 +808,9 @@ public class LampServiceImpl implements LampService {
     public List<LampInfoDTO> getLampListByIdList(List<String> idList) {
         return lampDao.getLampListByIdList(idList);
     }
+
+    @Override
+    public LampInfoDTO getLampAvgDataByBaseVO(BaseVO baseVO) {
+        return lampDao.getLampAvgDataByBaseVO(baseVO);
+    }
 }

+ 4 - 0
src/main/java/com/welampiot/vo/LampInfoDataVO.java

@@ -26,6 +26,10 @@ public class LampInfoDataVO implements Serializable {
 
     private Integer version;
 
+    private String aveLightness;
+    private String aveUsageYears;
+    private String aveLightTime;
+
     public LampInfoDataVO getLampInfoDataVO(@NotNull LampInfoDataVO vo) {
         if (vo.getVersion() == null) {
             vo.setVersion(0);

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

@@ -1393,4 +1393,26 @@
         </foreach>
     </select>
 
+    <select id="getLampAvgDataByBaseVO" resultType="LampInfoDTO">
+        select
+        AVG(l.lighteness) AS aveLightness,
+        AVG(TIMESTAMPDIFF(YEAR, l.createtime, NOW())) AS aveUsageYears,
+        AVG(a.work_time_total) AS aveLightTime
+        from lampinfo l
+        left join lamp_info_log_new a on a.lampid = l.id
+        where 1=1
+        <if test="areaId != null and areaId != 0">
+            and l.areaid = #{areaId}
+        </if>
+        <if test="sectionId != null and sectionId != 0">
+            and l.sectionid = #{sectionId}
+        </if>
+        <if test="sectionList != null and !sectionList.isEmpty()">
+            and l.sectionid in
+            <foreach collection="sectionList" item="item" open="(" separator="," close=")">
+                #{item}
+            </foreach>
+        </if>
+    </select>
+
 </mapper>