whyclxw
2025-05-08 ddf6daa3a1aa46b5797d3ad33b691bccb9129856
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
62
63
package com.whyc.service;
 
import com.whyc.dto.Response;
import com.whyc.mapper.CommonMapper;
import com.whyc.mapper.PwrDevDataHistoryGWMapper;
import com.whyc.pojo.PwrDevDataHistoryGW;
import com.whyc.util.ActionUtil;
import com.whyc.util.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import javax.annotation.Resource;
import java.text.ParseException;
import java.util.*;
import java.util.stream.Collectors;
 
@Service
public class PwrDevDataHistoryGWService {
 
    @Resource
    private PwrDevDataHistoryGWMapper mapper;
 
    @Resource
    private CommonMapper commonMapper;
 
 
    @Autowired
    private SubTablePageInfoService subService;
 
    public Response getListByParam(PwrDevDataHistoryGW param) throws ParseException {
        List<PwrDevDataHistoryGW> list = new LinkedList<>();
        Date startTime = param.getStartTime();
        Date endTime = param.getEndTime();
        Long powerDeviceId = param.getPowerDeviceId();
        Map<String, List<Date>> subTablesByMonthMap = DateUtil.getMonthListDesc(startTime, endTime);
        Set<String> monthSet = subTablesByMonthMap.keySet();
        //存在的时间范围内的表
        List<String> tableList = commonMapper.getTableListLike("db_pwrdev_data_history_gw", "tb_pwrdev_historydata_gw_" + powerDeviceId);
        tableList = tableList.stream().filter(table -> {
            String tableMonth = table.replace("tb_pwrdev_historydata_gw_" + powerDeviceId + "_", "");
            return monthSet.contains(tableMonth);
        }).collect(Collectors.toList());
        //表时间
        List<String> tableMonthList = tableList.stream().map(table->table.replace("tb_pwrdev_historydata_gw_" + powerDeviceId + "_","")).collect(Collectors.toList());
        //查询
        for (String tableMonth : tableMonthList) {
            List<Date> dates = subTablesByMonthMap.get(tableMonth);
            Date subStartTime = dates.get(0);
            Date subEndTime = dates.get(1);
            //List<PwrDevDataHistoryGW> subList = mapper.getListByParam(powerDeviceId,tableMonth,subStartTime,subEndTime);
            List<PwrDevDataHistoryGW> subList = subService.getListByParam(powerDeviceId,tableMonth,subStartTime,subEndTime);
            list.addAll(subList);
        }
        return new Response().set(1,list);
    }
    //获取当前天平均负载电流
    public Response getAvgLoadCurr(Integer powerId) {
        String tableName="db_pwrdev_data_history_gw"+"."+"tb_pwrdev_historydata_gw_"+powerId;
        tableName=tableName+"_"+ActionUtil.sdfwithOutday.format(new Date());
        Float avgCurr=subService.getAvgLoadCurr(powerId,tableName);
        return new Response().setII(1,true,avgCurr,"");
    }
}