2021与蓝度共同重构项目,服务端
liuhaonan
2022-04-19 9330e9b0e4e70151d36084ecb5695b818cfda2db
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.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.HexUtil;
import cn.hutool.core.util.StrUtil;
@@ -31,7 +32,11 @@
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import java.util.*;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
@@ -196,26 +201,43 @@
     *
     * @return
     */
    public Map controlEnergySaving() {
    public List<LightReportData> 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(clientId, null);
//        List<String> deviceCodeList = listLight.stream().map(LightBo::getDeviceCode).collect(Collectors.toList());
        List<String> deviceCodeList = new ArrayList<>();
        deviceCodeList.add("32313243305005ffa633ffff");
//        DateTime startDate = DateUtil.date();
//        DateTime endDate = DateUtil.offsetDay(startDate, 3);
//        if (CollectionUtil.isNotEmpty(deviceCodeList)) {
//
//            List<LightReportDataBo> reportDataList = lightReportDataService.reportDataList(deviceCodeList, startDate,  endDate);
//        }
        //获取用户最近7天的单灯数据
        List<LightReportData> reportDataList = lightReportDataService.list(Wrappers.<LightReportData>lambdaQuery()
                .in(LightReportData::getDeviceCode, deviceCodeList)
                .ge(LightReportData::getCreateTime, DateUtil.offsetDay(new Date(), -7))
                .ge(LightReportData::getCreateTime, DateUtil.offsetDay(DateUtil.yesterday(), -7))
                .orderByDesc(LightReportData::getCreateTime));
        if (CollectionUtil.isEmpty(reportDataList)) {
            throw new BusinessException("没有路灯数据");
        }
        LocalDateTime dateTime = LocalDateTime.now();
        dateTime.plusDays(7L);
        reportDataList.forEach(
                reportData -> {
                    LocalDateTime createTime = reportData.getCreateTime();
                    if(dateTime.plusDays(-1L).getDayOfMonth()==createTime.getDayOfMonth()){
                    }
                }
        );
        Map map = new HashMap();
        map.put("7", reportDataList);
        map.put("-1", null);
        return map;
        return reportDataList;
    }
    /**
@@ -224,8 +246,12 @@
     * @return
     */
    public List<Light> listLight() {
        Long clientId = SecurityUtils.getClientId();
        List<LightBo> listLight = baseMapper.listLight(clientId, null);
        List<LightBo> listLight;
        if (SecurityUtils.getClientId() != null) {
            listLight = baseMapper.listLight(SecurityUtils.getUserId(), null);
        } else {
            listLight = baseMapper.listLight(null, null);
        }
        List<Light> lightList = new ArrayList<>();
        for (LightBo bean : listLight) {
            Light light = getLight(bean.getDeviceCode());