common:LocalDateTimeUtils 增加方法:月份开始时间、月份结束时间

plp
owen 2 years ago
parent e7876b1520
commit cafa938ff4

@ -6,6 +6,7 @@ import java.time.Duration;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.temporal.TemporalAdjusters;
/**
* {@link java.time.LocalDateTime}
@ -97,4 +98,29 @@ public class LocalDateTimeUtils {
LocalDateTime.of(nowDate, startTime2), LocalDateTime.of(nowDate, endTime2));
}
/**
*
* 2023-09-30 00:00:00,000
*
* @param date
* @return
*/
public static LocalDateTime beginOfMonth(LocalDateTime date) {
return date
.with(TemporalAdjusters.firstDayOfMonth())
.with(LocalTime.MIN);
}
/**
*
* 2023-09-30 23:59:59,999
*
* @param date
* @return
*/
public static LocalDateTime endOfMonth(LocalDateTime date) {
return date
.with(TemporalAdjusters.lastDayOfMonth())
.with(LocalTime.MAX);
}
}

@ -1,6 +1,7 @@
package cn.iocoder.yudao.module.statistics.service.trade;
import cn.hutool.core.date.LocalDateTimeUtil;
import cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils;
import cn.iocoder.yudao.module.statistics.controller.admin.trade.vo.TradeStatisticsComparisonRespVO;
import cn.iocoder.yudao.module.statistics.controller.admin.trade.vo.TradeSummaryRespVO;
import cn.iocoder.yudao.module.statistics.controller.admin.trade.vo.TradeTrendSummaryRespVO;
@ -13,8 +14,6 @@ import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource;
import java.time.Duration;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.temporal.TemporalAdjusters;
import java.util.List;
/**
@ -79,18 +78,9 @@ public class TradeStatisticsServiceImpl implements TradeStatisticsService {
* @return
*/
private TradeSummaryRespBO getTradeSummaryByMonths(int months) {
// TODO @疯狂:可以在 LocalDateUtils 封装方法;获得月份的开始;以及结束两个方法;然后这里就可以直接调用了
// 月份开始时间
LocalDateTime beginOfMonth = LocalDateTime.now()
.plusMonths(months)
.with(TemporalAdjusters.firstDayOfMonth())
.with(LocalTime.MIN);
// 月份截止时间
LocalDateTime endOfToday = LocalDateTime.now()
.plusMonths(months)
.with(TemporalAdjusters.lastDayOfMonth())
.with(LocalTime.MAX);
return tradeStatisticsMapper.selectOrderCreateCountSumAndOrderPayPriceSumByTimeBetween(beginOfMonth, endOfToday);
LocalDateTime monthDate = LocalDateTime.now().plusMonths(months);
return tradeStatisticsMapper.selectOrderCreateCountSumAndOrderPayPriceSumByTimeBetween(
LocalDateTimeUtils.beginOfMonth(monthDate), LocalDateTimeUtils.endOfMonth(monthDate));
}
}

Loading…
Cancel
Save