|
|
|
@ -11,6 +11,7 @@ import com.mh.user.entity.EnergyDataEntity;
|
|
|
|
|
import com.mh.user.mapper.EnergyDataMapper; |
|
|
|
|
import com.mh.user.model.EnergyModel; |
|
|
|
|
import com.mh.user.service.EnergyDataService; |
|
|
|
|
import com.mh.user.utils.ExchangeStringUtil; |
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
|
@ -142,6 +143,58 @@ public class EnergyDataServiceImpl implements EnergyDataService {
|
|
|
|
|
newEndDayDate = newEndDayDate.minusDays(1).withHour(23).withMinute(59).withSecond(59); |
|
|
|
|
} |
|
|
|
|
lastEndDate = newEndDayDate.format(dayMatter); |
|
|
|
|
break; |
|
|
|
|
case 4: |
|
|
|
|
tableName = "energy_data_month"; |
|
|
|
|
dateType = "month"; |
|
|
|
|
// 假设传入的时间格式为 "2023"
|
|
|
|
|
String yearStr = startDate; |
|
|
|
|
|
|
|
|
|
// 1. 获取当前年份
|
|
|
|
|
int year = Integer.parseInt(yearStr); |
|
|
|
|
|
|
|
|
|
// 2. 计算今年的开始月份
|
|
|
|
|
int startMonth = 1; |
|
|
|
|
|
|
|
|
|
// 3. 获取当前月份
|
|
|
|
|
LocalDate now = LocalDate.now(); |
|
|
|
|
int currentMonth = now.getMonthValue(); |
|
|
|
|
|
|
|
|
|
// 4. 计算环比月份
|
|
|
|
|
int yearForComparison = year; |
|
|
|
|
int monthForComparison = currentMonth - 1; |
|
|
|
|
if (monthForComparison == 0) { |
|
|
|
|
monthForComparison = 12; |
|
|
|
|
yearForComparison = year - 1; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
int lastMonth = startMonth - 1; |
|
|
|
|
int lastYear = year; |
|
|
|
|
if (lastMonth == 0) { |
|
|
|
|
lastMonth = 12; |
|
|
|
|
lastYear = year - 1; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 当前时间
|
|
|
|
|
startDate = year + "-" + ExchangeStringUtil.addZeroForNum(String.valueOf(startMonth), 2); |
|
|
|
|
endDate = year + "-" + ExchangeStringUtil.addZeroForNum(String.valueOf(currentMonth), 2); |
|
|
|
|
|
|
|
|
|
// 环比时间
|
|
|
|
|
lastStartDate = lastYear + "-" + ExchangeStringUtil.addZeroForNum(String.valueOf(lastMonth), 2); |
|
|
|
|
lastEndDate = yearForComparison + "-" + ExchangeStringUtil.addZeroForNum(String.valueOf(monthForComparison), 2); |
|
|
|
|
break; |
|
|
|
|
case 5: |
|
|
|
|
tableName = "energy_data_year"; |
|
|
|
|
dateType = "year"; |
|
|
|
|
// 假设传入的时间格式为 "2023"
|
|
|
|
|
// 1. 获取当前年份
|
|
|
|
|
int startYear = Integer.parseInt(startDate); |
|
|
|
|
int endYear = Integer.parseInt(endDate); |
|
|
|
|
|
|
|
|
|
// 环比时间
|
|
|
|
|
lastStartDate = String.valueOf(startYear - 1); |
|
|
|
|
lastEndDate = String.valueOf(endYear - 1); |
|
|
|
|
break; |
|
|
|
|
default: |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
@ -160,4 +213,128 @@ public class EnergyDataServiceImpl implements EnergyDataService {
|
|
|
|
|
dateType); |
|
|
|
|
return MybatisPageHelper.getPageResult(pageRequest, new PageInfo<>(resultList)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public PageResult queryYoyEnergyData(EnergyModel energyModel) { |
|
|
|
|
String projectId=energyModel.getProjectId(); |
|
|
|
|
String startDate=energyModel.getStartDate(); |
|
|
|
|
String endDate=energyModel.getEndDate(); |
|
|
|
|
int page=energyModel.getPage(); |
|
|
|
|
int limit=energyModel.getLimit(); |
|
|
|
|
int type=energyModel.getType(); |
|
|
|
|
int queryType=energyModel.getQueryType(); |
|
|
|
|
|
|
|
|
|
String lastStartDate = ""; |
|
|
|
|
String lastEndDate = ""; |
|
|
|
|
String tableName = "energy_data_hour"; |
|
|
|
|
String dateType = "hour"; |
|
|
|
|
|
|
|
|
|
if (StringUtils.isBlank(endDate)) { |
|
|
|
|
endDate = startDate; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
switch (type) { |
|
|
|
|
case 1: |
|
|
|
|
// 按十分钟查询
|
|
|
|
|
break; |
|
|
|
|
case 2: |
|
|
|
|
// 按小时查询
|
|
|
|
|
startDate = startDate + " 00"; |
|
|
|
|
endDate = endDate + " 23"; |
|
|
|
|
|
|
|
|
|
// 定义日期时间格式
|
|
|
|
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH"); |
|
|
|
|
|
|
|
|
|
// startDate 减一年
|
|
|
|
|
LocalDateTime startDateTime = LocalDateTime.parse(startDate, formatter); |
|
|
|
|
LocalDateTime newStartDateTime = startDateTime.minusYears(1); |
|
|
|
|
lastStartDate = newStartDateTime.format(formatter); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// endDate 减一年
|
|
|
|
|
LocalDateTime endDateTime = LocalDateTime.parse(endDate, formatter); |
|
|
|
|
LocalDateTime newEndDateTime = endDateTime.minusYears(1); |
|
|
|
|
lastEndDate = newEndDateTime.format(formatter); |
|
|
|
|
break; |
|
|
|
|
case 3: |
|
|
|
|
tableName = "energy_data_day"; |
|
|
|
|
dateType = "day"; |
|
|
|
|
// 按天查询
|
|
|
|
|
YearMonth yearMonthStart = YearMonth.parse(startDate, DateTimeFormatter.ofPattern("yyyy-MM")); |
|
|
|
|
LocalDate firstDayOfMonth = yearMonthStart.atDay(1); |
|
|
|
|
LocalDate lastDayOfMonth = yearMonthStart.atEndOfMonth(); |
|
|
|
|
|
|
|
|
|
startDate = firstDayOfMonth.toString(); |
|
|
|
|
endDate = lastDayOfMonth.toString(); |
|
|
|
|
|
|
|
|
|
// 定义日期时间格式
|
|
|
|
|
DateTimeFormatter dayMatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); |
|
|
|
|
|
|
|
|
|
// startDate 减一年
|
|
|
|
|
LocalDateTime startDayDate = LocalDateTime.parse(startDate + "T00:00:00", DateTimeFormatter.ISO_LOCAL_DATE_TIME); |
|
|
|
|
LocalDateTime newStartDayDate = startDayDate.minusYears(1); |
|
|
|
|
lastStartDate = newStartDayDate.format(dayMatter); |
|
|
|
|
|
|
|
|
|
// endDate 减一年
|
|
|
|
|
LocalDateTime endDayDate = LocalDateTime.parse(endDate + "T23:59:59", DateTimeFormatter.ISO_LOCAL_DATE_TIME); |
|
|
|
|
LocalDateTime newEndDayDate = endDayDate.minusYears(1); |
|
|
|
|
if (newEndDayDate.getDayOfMonth() == 1) { |
|
|
|
|
newEndDayDate = newEndDayDate.minusYears(1).withHour(23).withMinute(59).withSecond(59); |
|
|
|
|
} |
|
|
|
|
lastEndDate = newEndDayDate.format(dayMatter); |
|
|
|
|
break; |
|
|
|
|
case 4: |
|
|
|
|
tableName = "energy_data_month"; |
|
|
|
|
dateType = "month"; |
|
|
|
|
// 假设传入的时间格式为 "2023"
|
|
|
|
|
String yearStr = startDate; |
|
|
|
|
|
|
|
|
|
// 1. 获取当前年份
|
|
|
|
|
int year = Integer.parseInt(yearStr); |
|
|
|
|
|
|
|
|
|
// 2. 计算今年的开始月份
|
|
|
|
|
int startMonth = 1; |
|
|
|
|
|
|
|
|
|
// 3. 获取当前月份
|
|
|
|
|
LocalDate now = LocalDate.now(); |
|
|
|
|
int currentMonth = now.getMonthValue(); |
|
|
|
|
|
|
|
|
|
// 当前时间
|
|
|
|
|
startDate = year + "-" + ExchangeStringUtil.addZeroForNum(String.valueOf(startMonth), 2); |
|
|
|
|
endDate = year + "-" + ExchangeStringUtil.addZeroForNum(String.valueOf(currentMonth), 2); |
|
|
|
|
|
|
|
|
|
// 环比时间
|
|
|
|
|
lastStartDate = year-1 + "-" + ExchangeStringUtil.addZeroForNum(String.valueOf(startMonth), 2); |
|
|
|
|
lastEndDate = year-1 + "-" + ExchangeStringUtil.addZeroForNum(String.valueOf(currentMonth), 2); |
|
|
|
|
break; |
|
|
|
|
case 5: |
|
|
|
|
tableName = "energy_data_year"; |
|
|
|
|
dateType = "year"; |
|
|
|
|
// 假设传入的时间格式为 "2023"
|
|
|
|
|
// 1. 获取当前年份
|
|
|
|
|
int startYear = Integer.parseInt(startDate); |
|
|
|
|
int endYear = Integer.parseInt(endDate); |
|
|
|
|
|
|
|
|
|
// 环比时间
|
|
|
|
|
lastStartDate = String.valueOf(startYear - 1); |
|
|
|
|
lastEndDate = String.valueOf(endYear - 1); |
|
|
|
|
break; |
|
|
|
|
default: |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
PageRequest pageRequest = new PageRequest(); |
|
|
|
|
if (page != 0) { |
|
|
|
|
PageHelper.startPage(page, limit); |
|
|
|
|
pageRequest.setPageNum(page); |
|
|
|
|
pageRequest.setPageSize(limit); |
|
|
|
|
} |
|
|
|
|
List<EnergyMomYoyDataDTO> resultList = energyDataMapper.queryYoyEnergyHourAndDayData(tableName, |
|
|
|
|
projectId, |
|
|
|
|
startDate, |
|
|
|
|
endDate, |
|
|
|
|
lastStartDate, |
|
|
|
|
lastEndDate, |
|
|
|
|
dateType); |
|
|
|
|
return MybatisPageHelper.getPageResult(pageRequest, new PageInfo<>(resultList)); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|