2021与蓝度共同重构项目,服务端
liuhaonan
2022-04-19 5459d7d124fc4c4eb93e8074354dd72c9527081e
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;
@@ -9,6 +10,8 @@
import com.sandu.common.execption.BusinessException;
import com.sandu.common.redis.RedisService;
import com.sandu.common.service.impl.BaseServiceImpl;
import com.sandu.common.util.SpringContextHolder;
import com.sandu.ximon.admin.dto.LightTaskDto;
import com.sandu.ximon.admin.manager.iot.frame.A5Frame;
import com.sandu.ximon.admin.manager.iot.frame.inner.report.A5LightHeartbeatReportInnerFrame;
import com.sandu.ximon.admin.manager.iot.frame.inner.request.A5LightBrightnessReqInnerFrame;
@@ -31,7 +34,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 +203,34 @@
     *
     * @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());
        //获取用户最近7天的单灯数据
        List<LightReportData> reportDataList = lightReportDataService.list(Wrappers.<LightReportData>lambdaQuery()
                .in(LightReportData::getDeviceCode, deviceCodeList)
                .ge(LightReportData::getCreateTime, DateUtil.offsetDay(new Date(), -7))
                .orderByDesc(LightReportData::getCreateTime));
        List<LightTaskDto> lightTaskDtos = SpringContextHolder.getBean(LightTaskService.class).listLightTask(null, null);
        lightTaskDtos.forEach(Task -> {
        if (CollectionUtil.isEmpty(reportDataList)) {
            throw new BusinessException("没有路灯数据");
                });
        return null;
    }
    /**
     * 解析开关灯指令
     */
    public void parseSwitchLightCommand(String command) {
        char[] chars = command.toCharArray();
        if(chars.length==7){
            int hour = Integer.valueOf(command.substring(0,2));
            int min = Integer.valueOf(command.substring(2,4));
            int brightness = Integer.valueOf(command.substring(4,7));
        }
        Map map = new HashMap();
        map.put("7", reportDataList);
        return map;
    }
    /**