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);
|
}
|
}
|