2021与蓝度共同重构项目,服务端
liuhaonan
2022-04-19 cb502443ec3193181f587bdecc35cfdbc9827175
ximon-admin/src/main/java/com/sandu/ximon/admin/service/LightService.java
@@ -1,6 +1,7 @@
package com.sandu.ximon.admin.service;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.HexUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
@@ -30,10 +31,7 @@
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.stream.Collectors;
/**
@@ -87,10 +85,7 @@
     * @return 返回组合数据dto
     */
    public List<LightBo> listLight(int pageNo, int pageSize, String keyword) {
        Long clientId=null;
        if(SecurityUtils.getClientId()!=null){
            clientId = SecurityUtils.getClientId();
        }
        Long clientId = SecurityUtils.getClientId();
        PageHelper.startPage(pageNo, pageSize);
@@ -126,6 +121,7 @@
    /**
     * 获取单个路灯信息
     *
     * @param deviceCode 设备码
     * @return
     */
@@ -197,31 +193,42 @@
    /**
     * 单灯节能率
     *
     * @return
     */
    public List<Map<String, Object>> controlEnergySaving() {
    public Map controlEnergySaving() {
        Long clientId = SecurityUtils.getClientId();
        List<LightBo> listLight = baseMapper.listLight(clientId, null);
        List<String> deviceCodeList = listLight.stream().map(LightBo::getDeviceCode).collect(Collectors.toList());
        List<LightBo> listLight = baseMapper.listLight(SecurityUtils.getUserId(), null);
        //获取用户最近7天的单灯数据
        List<LightReportData> reportDataList = lightReportDataService.list(Wrappers.<LightReportData>lambdaQuery()
                .in(LightReportData::getDeviceCode, deviceCodeList)
                .ge(LightReportData::getCreateTime, DateUtil.offsetDay(new Date(), -7))
                .orderByDesc(LightReportData::getCreateTime));
        return null;
        if (CollectionUtil.isEmpty(reportDataList)) {
            throw new BusinessException("没有路灯数据");
        }
        Map map = new HashMap();
        map.put("7", reportDataList);
        return map;
    }
    /**
     * 用户拥有的路灯
     *
     * @return
     */
    public List<Light> listLight() {
        List<LightBo> listLight = baseMapper.listLight(SecurityUtils.getUserId(), null);
        if (CollectionUtil.isEmpty(listLight)) {
            throw new BusinessException("没有路灯数据");
        }
        List<String> deviceCodeList = listLight.stream().map(LightBo::getDeviceCode).collect(Collectors.toList());
        List<LightReportData> reportDataList = lightReportDataService.list(Wrappers.<LightReportData>lambdaQuery().in(LightReportData::getDeviceCode, deviceCodeList));
        if (CollectionUtil.isEmpty(reportDataList)) {
            throw new BusinessException("没有路灯数据");
        }
        Long clientId = SecurityUtils.getClientId();
        List<LightBo> listLight = baseMapper.listLight(clientId, null);
        List<Light> lightList = new ArrayList<>();
        for (String deviceCode : deviceCodeList) {
            Light light = getLight(deviceCode);
        for (LightBo bean : listLight) {
            Light light = getLight(bean.getDeviceCode());
            lightList.add(light);
        }
        return lightList;