鞍钢鲅鱼圈能源管控系统后端代码
潘志宝
昨天 1d9abe2a92a8c2bdf7d4534ad1aa20ad615b33ca
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package com.iailab.module.ansteel.power.service.impl;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.iailab.framework.common.pojo.PageResult;
import com.iailab.module.ansteel.api.vo.PowerMaxDemandMainPageReqVO;
import com.iailab.module.ansteel.power.dao.PowerMaxdemandMainDao;
import com.iailab.module.ansteel.power.entity.PowerMaxdemandMainEntity;
import com.iailab.module.ansteel.power.service.PowerMaxdemandMainService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
 
import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;
 
/**
 * @author PanZhibao
 * @Description
 * @createTime 2025年05月07日
 */
@Slf4j
@Service
public class PowerMaxdemandMainServiceImpl implements PowerMaxdemandMainService {
 
    @Autowired
    private PowerMaxdemandMainDao powerMaxdemandMainDao;
 
    @Override
    public PageResult<PowerMaxdemandMainEntity> page(PowerMaxDemandMainPageReqVO reqVO) {
        return powerMaxdemandMainDao.selectPage(reqVO);
    }
 
    @Override
    public String add(PowerMaxdemandMainEntity entity) {
        entity.setId(UUID.randomUUID().toString());
        powerMaxdemandMainDao.insert(entity);
        return entity.getId();
    }
 
    @Override
    public BigDecimal getMax(String code, Date start, Date end) {
        BigDecimal max = new BigDecimal(0);
        QueryWrapper<PowerMaxdemandMainEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("code", code)
                .ge("occur_time", start)
                .le("occur_time", end);
        List<PowerMaxdemandMainEntity> list = powerMaxdemandMainDao.selectList(queryWrapper);
        if (CollectionUtils.isEmpty(list)) {
            return max;
        }
        List<Double> demandValueList = list.stream().map(item -> {
            return item.getMaxDemand().doubleValue();
        }).collect(Collectors.toList());
 
        max = new BigDecimal(demandValueList.stream().max(Double::compareTo).get());
        log.info("max : {}", max);
        return max;
    }
}