|
@@ -13,6 +13,11 @@ import org.springframework.stereotype.Service;
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
import java.math.RoundingMode;
|
|
import java.math.RoundingMode;
|
|
import java.text.SimpleDateFormat;
|
|
import java.text.SimpleDateFormat;
|
|
|
|
+import java.time.LocalDate;
|
|
|
|
+import java.time.LocalDateTime;
|
|
|
|
+import java.time.LocalTime;
|
|
|
|
+import java.time.ZoneId;
|
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
import java.util.*;
|
|
import java.util.*;
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@@ -25,16 +30,17 @@ public class ElectricityRestrictionServiceImpl implements ElectricityRestriction
|
|
|
|
|
|
private final ElectricFieldService electricFieldService;
|
|
private final ElectricFieldService electricFieldService;
|
|
|
|
|
|
- private final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
|
|
|
+ private SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
|
|
|
- private final static SimpleDateFormat formatDate = new SimpleDateFormat("HH:mm");
|
|
|
|
|
|
+ private SimpleDateFormat formatDate = new SimpleDateFormat("HH:mm");
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public List getElectricityRestriction(Date startTime, Date endTime, String stationCode) {
|
|
public List getElectricityRestriction(Date startTime, Date endTime, String stationCode) {
|
|
List<ElectricField> electricFieldList;
|
|
List<ElectricField> electricFieldList;
|
|
List<ElectricityRestrictionDto> list = new ArrayList<>();
|
|
List<ElectricityRestrictionDto> list = new ArrayList<>();
|
|
|
|
+ System.out.println(System.currentTimeMillis());
|
|
List<PowerStationStatusData> powerStationStatusDataList = powerStationStatusDataService.findByTimeBetweenAndStationCode(startTime, new Date(endTime.getTime() + 1000L), stationCode);
|
|
List<PowerStationStatusData> powerStationStatusDataList = powerStationStatusDataService.findByTimeBetweenAndStationCode(startTime, new Date(endTime.getTime() + 1000L), stationCode);
|
|
-
|
|
|
|
|
|
+ System.out.println(System.currentTimeMillis());
|
|
if (null == stationCode) {
|
|
if (null == stationCode) {
|
|
electricFieldList = electricFieldService.list();
|
|
electricFieldList = electricFieldService.list();
|
|
for (ElectricField electricField : electricFieldList) {
|
|
for (ElectricField electricField : electricFieldList) {
|
|
@@ -59,18 +65,47 @@ public class ElectricityRestrictionServiceImpl implements ElectricityRestriction
|
|
*/
|
|
*/
|
|
public List<ElectricityRestrictionDto> get(List<PowerStationStatusData> powerStationStatusDataList, Date startTime, Date endTime, String stationCode) {
|
|
public List<ElectricityRestrictionDto> get(List<PowerStationStatusData> powerStationStatusDataList, Date startTime, Date endTime, String stationCode) {
|
|
List<ElectricityRestrictionDto> list = new ArrayList<>();
|
|
List<ElectricityRestrictionDto> list = new ArrayList<>();
|
|
- if (null != powerStationStatusDataList && powerStationStatusDataList.size() > 0) {
|
|
|
|
|
|
+
|
|
|
|
+ DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
|
|
|
+ DateTimeFormatter timeFormatter = DateTimeFormatter.ofPattern("HH:mm");
|
|
|
|
+ // 使用toMap收集器进行分组,特别处理0点数据
|
|
|
|
+ Map<String, List<PowerStationStatusData>> groupMap = powerStationStatusDataList.stream()
|
|
|
|
+ .collect(Collectors.toMap(
|
|
|
|
+ t -> {
|
|
|
|
+ LocalDateTime dateTime = t.getTime().toInstant()
|
|
|
|
+ .atZone(ZoneId.systemDefault())
|
|
|
|
+ .toLocalDateTime();
|
|
|
|
+ // 如果时间是0点,我们计算前一天的日期
|
|
|
|
+ if (dateTime.toLocalTime().equals(LocalTime.MIDNIGHT)) {
|
|
|
|
+ LocalDate previousDate = dateTime.toLocalDate().minusDays(1);
|
|
|
|
+ return dateFormatter.format(previousDate);
|
|
|
|
+ }
|
|
|
|
+ // 对于非0点数据,直接使用当天的日期
|
|
|
|
+ return dateFormatter.format(dateTime.toLocalDate());
|
|
|
|
+ },
|
|
|
|
+ Collections::singletonList,
|
|
|
|
+ (list1, list2) -> {
|
|
|
|
+ List<PowerStationStatusData> combined = new ArrayList<>(list1);
|
|
|
|
+ combined.addAll(list2);
|
|
|
|
+ return combined;
|
|
|
|
+ }
|
|
|
|
+ ));
|
|
|
|
+
|
|
|
|
+ if (null != groupMap && groupMap.size() > 0) {
|
|
|
|
+
|
|
List<String> dayList = DateTimeUtil.getDatesInRange(startTime, endTime);
|
|
List<String> dayList = DateTimeUtil.getDatesInRange(startTime, endTime);
|
|
for (String s : dayList) {
|
|
for (String s : dayList) {
|
|
- List<PowerStationStatusData> collectList = powerStationStatusDataList.stream().filter(f -> dateFormat.format(f.getTime()).equals(s) && !formatDate.format(f.getTime()).equals("00:00")).collect(Collectors.toList());
|
|
|
|
- // 判断下一天00:00数据是否限电
|
|
|
|
- List<PowerStationStatusData> dataList = powerStationStatusDataList.stream().filter(f -> f.getTime().getTime() == DateTimeUtil.getDayStartTime(startTime.getTime() + 24 * 60 * 60 * 1000L).getTime()).collect(Collectors.toList());
|
|
|
|
- if (dataList.size() > 0) {
|
|
|
|
- PowerStationStatusData powerStationStatusData = new PowerStationStatusData();
|
|
|
|
- powerStationStatusData = dataList.get(0);
|
|
|
|
- powerStationStatusData.setTime(new Date(startTime.getTime() + 24 * 60 * 60 * 1000L - 60*1000L));
|
|
|
|
- collectList.add(powerStationStatusData);
|
|
|
|
- }
|
|
|
|
|
|
+ if (groupMap.get(s) != null){
|
|
|
|
+
|
|
|
|
+ List<PowerStationStatusData> collectList = groupMap.get(s);
|
|
|
|
+// // 判断下一天00:00数据是否限电
|
|
|
|
+// List<PowerStationStatusData> dataList = powerStationStatusDataList.stream().filter(f -> f.getTime().getTime() == DateTimeUtil.getDayStartTime(startTime.getTime() + 24 * 60 * 60 * 1000L).getTime()).collect(Collectors.toList());
|
|
|
|
+// if (dataList.size() > 0) {
|
|
|
|
+// PowerStationStatusData powerStationStatusData = new PowerStationStatusData();
|
|
|
|
+// powerStationStatusData = dataList.get(0);
|
|
|
|
+// powerStationStatusData.setTime(new Date(startTime.getTime() + 24 * 60 * 60 * 1000L - 60 * 1000L));
|
|
|
|
+// collectList.add(powerStationStatusData);
|
|
|
|
+// }
|
|
if (collectList.size() > 0) {
|
|
if (collectList.size() > 0) {
|
|
ElectricityRestrictionDto electricityRestrictionDto = new ElectricityRestrictionDto();
|
|
ElectricityRestrictionDto electricityRestrictionDto = new ElectricityRestrictionDto();
|
|
// 总限电量
|
|
// 总限电量
|
|
@@ -86,6 +121,7 @@ public class ElectricityRestrictionServiceImpl implements ElectricityRestriction
|
|
list.add(electricityRestrictionDto);
|
|
list.add(electricityRestrictionDto);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ }
|
|
}
|
|
}
|
|
return list;
|
|
return list;
|
|
}
|
|
}
|
|
@@ -111,10 +147,10 @@ public class ElectricityRestrictionServiceImpl implements ElectricityRestriction
|
|
for (int i = 0; i < list.size(); i++) {
|
|
for (int i = 0; i < list.size(); i++) {
|
|
Date calculateTime = list.get(i).getTime();
|
|
Date calculateTime = list.get(i).getTime();
|
|
Date finalTime;
|
|
Date finalTime;
|
|
- if (formatDate.format(list.get(i).getTime()).equals("23:59")){
|
|
|
|
- finalTime= new Date(list.get(i).getTime().getTime() - 4 * 60 * 1000l);
|
|
|
|
- }else {
|
|
|
|
- finalTime = new Date(list.get(i).getTime().getTime() - 5 * 60 * 1000l);
|
|
|
|
|
|
+ if (formatDate.format(calculateTime).equals("23:59")) {
|
|
|
|
+ finalTime = new Date(calculateTime.getTime() - 4 * 60 * 1000l);
|
|
|
|
+ } else {
|
|
|
|
+ finalTime = new Date(calculateTime.getTime() - 5 * 60 * 1000l);
|
|
}
|
|
}
|
|
|
|
|
|
if (null == prevDate) {
|
|
if (null == prevDate) {
|
|
@@ -127,7 +163,7 @@ public class ElectricityRestrictionServiceImpl implements ElectricityRestriction
|
|
result.append(formatDate.format(finalTime) + "~");
|
|
result.append(formatDate.format(finalTime) + "~");
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
- if ( formatDate.format(calculateTime).equals("23:59")?DateTimeUtil.isMinutesDifference(calculateTime, prevDate, 4L) :DateTimeUtil.isMinutesDifference(calculateTime, prevDate, 5L)) {
|
|
|
|
|
|
+ if (formatDate.format(calculateTime).equals("23:59") ? DateTimeUtil.isMinutesDifference(calculateTime, prevDate, 4L) : DateTimeUtil.isMinutesDifference(calculateTime, prevDate, 5L)) {
|
|
prevDate = calculateTime;
|
|
prevDate = calculateTime;
|
|
if (i == list.size() - 1) {
|
|
if (i == list.size() - 1) {
|
|
result.append(formatDate.format(calculateTime) + ";");
|
|
result.append(formatDate.format(calculateTime) + ";");
|
|
@@ -145,10 +181,16 @@ public class ElectricityRestrictionServiceImpl implements ElectricityRestriction
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- return result.toString();
|
|
|
|
- }
|
|
|
|
|
|
+ String modifiedTimePeriods = result.toString();
|
|
|
|
+ if (judge(result.toString())){
|
|
|
|
+ int lastIndex = result.toString().lastIndexOf("00:00");
|
|
|
|
+ int endIndex = (lastIndex + 4 < result.toString().length() && result.toString().charAt(lastIndex + 4) == ';') ? lastIndex + 5 : result.toString().length();
|
|
|
|
|
|
|
|
+ modifiedTimePeriods = result.toString().substring(0, lastIndex) + "23:59" + (endIndex > lastIndex + 4 ? result.toString().substring(endIndex) : "");
|
|
|
|
|
|
|
|
+ }
|
|
|
|
+ return modifiedTimePeriods;
|
|
|
|
+ }
|
|
@Data
|
|
@Data
|
|
public class ElectricityRestrictionDto {
|
|
public class ElectricityRestrictionDto {
|
|
// 日期
|
|
// 日期
|
|
@@ -162,4 +204,28 @@ public class ElectricityRestrictionServiceImpl implements ElectricityRestriction
|
|
// 场站编号
|
|
// 场站编号
|
|
private String stationCode;
|
|
private String stationCode;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 判断限电结果是否以00:00结尾
|
|
|
|
+ * @param result
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ public boolean judge(String result){
|
|
|
|
+ boolean flag = false;
|
|
|
|
+
|
|
|
|
+ String[] spiltOne = result.split(";");
|
|
|
|
+ if (spiltOne.length > 1){
|
|
|
|
+ String[] spiltTwo = spiltOne[spiltOne.length-1].split("~");
|
|
|
|
+ if (spiltTwo[1].equals("00:00")){
|
|
|
|
+ flag = true;
|
|
|
|
+ }
|
|
|
|
+ }else {
|
|
|
|
+ String[] spiltTwo = spiltOne[0].split("~");
|
|
|
|
+ if (spiltTwo[1].equals("00:00")){
|
|
|
|
+ flag = true;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return flag;
|
|
|
|
+ }
|
|
}
|
|
}
|