mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-05-15 07:18:31 +08:00
Merge branch 'dev' of http://192.168.2.46:8099/jsowell/jsowell-charger-web into dev
This commit is contained in:
@@ -1073,6 +1073,44 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils {
|
|||||||
return new LocalDateTime[]{startDateTime, endDateTime};
|
return new LocalDateTime[]{startDateTime, endDateTime};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取去年这个月第一天的日期
|
||||||
|
* @return 去年这个月第一天的日期,格式为 "yyyy-MM-dd"
|
||||||
|
*/
|
||||||
|
public static String getFirstDayOfLastYearMonth() {
|
||||||
|
// 获取当前日期
|
||||||
|
LocalDate currentDate = LocalDate.now();
|
||||||
|
|
||||||
|
// 获取去年这个月的年份
|
||||||
|
int lastYear = currentDate.getYear() - 1;
|
||||||
|
|
||||||
|
// 获取这个月的月份
|
||||||
|
int currentMonth = currentDate.getMonthValue();
|
||||||
|
|
||||||
|
// 获取去年这个月第一天的日期
|
||||||
|
LocalDate firstDayOfLastYearMonth = LocalDate.of(lastYear, currentMonth, 1);
|
||||||
|
|
||||||
|
// 格式化日期为 "yyyy-MM-dd"
|
||||||
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
||||||
|
return firstDayOfLastYearMonth.format(formatter);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取当前年月最后一天的日期
|
||||||
|
* @return 当前年月最后一天的日期,格式为 "yyyy-MM-dd"
|
||||||
|
*/
|
||||||
|
public static String getLastDayOfCurrentMonth() {
|
||||||
|
// 获取当前的年份和月份
|
||||||
|
YearMonth currentYearMonth = YearMonth.now();
|
||||||
|
|
||||||
|
// 获取该年月的最后一天
|
||||||
|
LocalDate lastDayOfMonth = currentYearMonth.atEndOfMonth();
|
||||||
|
|
||||||
|
// 格式化日期为 "yyyy-MM-dd"
|
||||||
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
||||||
|
return lastDayOfMonth.format(formatter);
|
||||||
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
String startTime = "22:00:00";
|
String startTime = "22:00:00";
|
||||||
String endTime1 = "05:30:00";
|
String endTime1 = "05:30:00";
|
||||||
|
|||||||
@@ -47,6 +47,8 @@ import org.springframework.transaction.annotation.Transactional;
|
|||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.text.DecimalFormat;
|
import java.text.DecimalFormat;
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
@@ -956,16 +958,22 @@ public class PileStationInfoServiceImpl implements PileStationInfoService {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public StationBusinessAnalyzeInfoVO getStationMonthlyBusinessAnalyzeInfo(StationBusinessAnalyzeInfoDTO dto) {
|
public StationBusinessAnalyzeInfoVO getStationMonthlyBusinessAnalyzeInfo(StationBusinessAnalyzeInfoDTO dto) {
|
||||||
|
// 获取目标日期(年-月)
|
||||||
|
String dateTime = dto.getDateTime();
|
||||||
|
// 设置开始时间、结束时间
|
||||||
String stationId = dto.getStationId();
|
String stationId = dto.getStationId();
|
||||||
Calendar instance = Calendar.getInstance();
|
String startTime = DateUtils.getLastDayOfCurrentMonth(); // 去年月份第一天
|
||||||
instance.add(Calendar.YEAR, -1);
|
String endTime = DateUtils.getFirstDayOfLastYearMonth(); // 当前月份最后一天
|
||||||
String startTime = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, instance.getTime());
|
|
||||||
String endTime = DateUtils.dateTimeNow(DateUtils.YYYY_MM_DD);
|
|
||||||
// 查询订单日报表过去一年的数据
|
// 查询订单日报表过去一年的数据
|
||||||
List<SettleOrderReport> list = settleOrderReportService.queryOrderReport(Lists.newArrayList(stationId), startTime, endTime);
|
List<SettleOrderReport> list = settleOrderReportService.queryOrderReport(Lists.newArrayList(stationId), startTime, endTime);
|
||||||
|
|
||||||
// 按照日期汇总数据
|
// 按照日期汇总数据
|
||||||
Map<String, SettleOrderReport> collect = list.stream()
|
Map<String, SettleOrderReport> collect = list.stream()
|
||||||
|
.peek(report -> {
|
||||||
|
LocalDate date = LocalDate.parse(report.getTradeDate(), DateTimeFormatter.ofPattern("yyyy-MM-dd"));
|
||||||
|
String formattedDate = date.format(DateTimeFormatter.ofPattern("yyyy-MM"));
|
||||||
|
report.setTradeDate(formattedDate);
|
||||||
|
})
|
||||||
.sorted(Comparator.comparing(SettleOrderReport::getTradeDate))
|
.sorted(Comparator.comparing(SettleOrderReport::getTradeDate))
|
||||||
.collect(Collectors.toMap(SettleOrderReport::getTradeDate, Function.identity(),
|
.collect(Collectors.toMap(SettleOrderReport::getTradeDate, Function.identity(),
|
||||||
(a, b) -> {
|
(a, b) -> {
|
||||||
@@ -979,17 +987,52 @@ public class PileStationInfoServiceImpl implements PileStationInfoService {
|
|||||||
TreeMap<String, SettleOrderReport> map = new TreeMap<>(collect);
|
TreeMap<String, SettleOrderReport> map = new TreeMap<>(collect);
|
||||||
List<SettleOrderReport> settleOrderReports = new ArrayList<>(map.values());
|
List<SettleOrderReport> settleOrderReports = new ArrayList<>(map.values());
|
||||||
|
|
||||||
// StationBusinessAnalyzeInfoVO vo = StationBusinessAnalyzeInfoVO.builder()
|
SettleOrderReport nowReportInfo = new SettleOrderReport();
|
||||||
// .electricityGrowthRate()
|
SettleOrderReport lastMonthReportInfo = new SettleOrderReport();
|
||||||
// .orderAmountGrowthRate()
|
if(dateTime == null) {
|
||||||
// .serviceAmountGrowthRate()
|
// 为空默认对比最后一个月和前一个月的数据
|
||||||
//
|
nowReportInfo = settleOrderReports.get(settleOrderReports.size() - 1);
|
||||||
// .businessOrderDetailInfoVOList()
|
lastMonthReportInfo = settleOrderReports.get(settleOrderReports.size() - 2);
|
||||||
// .build();
|
}else {
|
||||||
|
// 对比目标日期和目标日期前一个月数据
|
||||||
|
nowReportInfo = map.get(dateTime);
|
||||||
|
Date lastMonth = DateUtils.addMonths(DateUtils.parseDate(dateTime), -1);
|
||||||
|
String lastMonthStr = DateUtils.parseDateToStr(DateUtils.YYYY_MM, lastMonth);
|
||||||
|
lastMonthReportInfo = map.get(lastMonthStr);
|
||||||
|
}
|
||||||
|
String electricityGrowthRate = "-";
|
||||||
|
String orderAmountGrowthRate = "";
|
||||||
|
String serviceAmountGrowthRate = "";
|
||||||
|
// 充电量增长率
|
||||||
|
BigDecimal useElectricity = nowReportInfo.getUseElectricity();
|
||||||
|
BigDecimal lastMonthUseElectricity = lastMonthReportInfo.getUseElectricity();
|
||||||
|
if (lastMonthUseElectricity.compareTo(BigDecimal.ZERO) != 0) {
|
||||||
|
BigDecimal usedElectricityRate = useElectricity.subtract(lastMonthUseElectricity).divide(lastMonthUseElectricity, 2, BigDecimal.ROUND_HALF_UP);
|
||||||
|
electricityGrowthRate = usedElectricityRate.multiply(new BigDecimal("100")) + "%";
|
||||||
|
}
|
||||||
|
// 订单金额增长率
|
||||||
|
BigDecimal totalAmount = nowReportInfo.getTotalAmount();
|
||||||
|
BigDecimal lastTotalAmount = lastMonthReportInfo.getTotalAmount();
|
||||||
|
if (lastTotalAmount.compareTo(BigDecimal.ZERO) != 0) {
|
||||||
|
BigDecimal totalAmountRate = totalAmount.subtract(lastTotalAmount).divide(lastTotalAmount, 2, BigDecimal.ROUND_HALF_UP);
|
||||||
|
orderAmountGrowthRate = totalAmountRate.multiply(new BigDecimal("100")) + "%";
|
||||||
|
}
|
||||||
|
// 服务费增长率
|
||||||
|
BigDecimal serviceAmount = nowReportInfo.getServiceAmount();
|
||||||
|
BigDecimal lastMonthServiceAmount = lastMonthReportInfo.getServiceAmount();
|
||||||
|
if (lastMonthServiceAmount.compareTo(BigDecimal.ZERO) != 0) {
|
||||||
|
BigDecimal serviceAmountRate = serviceAmount.subtract(lastMonthServiceAmount).divide(lastMonthServiceAmount, 2, BigDecimal.ROUND_HALF_UP);
|
||||||
|
serviceAmountGrowthRate = serviceAmountRate.multiply(new BigDecimal("100")) + "%";
|
||||||
|
}
|
||||||
|
|
||||||
|
StationBusinessAnalyzeInfoVO vo = StationBusinessAnalyzeInfoVO.builder()
|
||||||
|
.electricityGrowthRate(electricityGrowthRate)
|
||||||
|
.orderAmountGrowthRate(orderAmountGrowthRate)
|
||||||
|
.serviceAmountGrowthRate(serviceAmountGrowthRate)
|
||||||
|
.settleOrderReportList(settleOrderReports)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return vo;
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.jsowell.pile.vo;
|
package com.jsowell.pile.vo;
|
||||||
|
|
||||||
|
import com.jsowell.pile.domain.SettleOrderReport;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
@@ -35,4 +36,6 @@ public class StationBusinessAnalyzeInfoVO {
|
|||||||
private String serviceAmountGrowthRate;
|
private String serviceAmountGrowthRate;
|
||||||
|
|
||||||
private List<BusinessOrderDetailInfoVO> businessOrderDetailInfoVOList;
|
private List<BusinessOrderDetailInfoVO> businessOrderDetailInfoVOList;
|
||||||
|
|
||||||
|
private List<SettleOrderReport> settleOrderReportList;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user