接口开发

master
litao 3 years ago
parent 2f0449075c
commit 4d931ecbcf
  1. 13
      src/main/java/org/springblade/modules/business/controller/ReportController.java
  2. 7
      src/main/java/org/springblade/modules/business/entity/Appeal.java
  3. 14
      src/main/java/org/springblade/modules/business/service/ILargeScreenService.java
  4. 296
      src/main/java/org/springblade/modules/business/service/impl/LargeScreenServiceImpl.java
  5. 442
      src/main/java/org/springblade/modules/business/utils/LocalDateTimeUtils.java

@ -21,6 +21,8 @@ import io.swagger.annotations.Api;
import lombok.AllArgsConstructor;
import org.springblade.common.constant.CommonConstant;
import org.springblade.core.boot.ctrl.BladeController;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tenant.annotation.TenantDS;
import org.springblade.core.tool.api.R;
import org.springblade.modules.business.service.ILargeScreenService;
@ -28,6 +30,7 @@ import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.text.ParseException;
import java.util.Date;
/**
@ -89,7 +92,7 @@ public class ReportController extends BladeController {
* 事件上报热力图(中2)
*/
@GetMapping("/getAppealSubmitCountByLoc")
public R getAppealSubmitCountByLoc(Integer timeFrame, Date startTime, Date endTime) {
public R getAppealSubmitCountByLoc(Integer timeFrame, String startTime, String endTime) throws ParseException {
return R.data(largeScreenService.getAppealSubmitCountByLoc(timeFrame, startTime, endTime));
}
@ -97,7 +100,7 @@ public class ReportController extends BladeController {
* 矛盾化解热力图(中3)
*/
@GetMapping("/getAppealFinishCountByLoc")
public R getAppealFinishCountByLoc(Integer timeFrame, Date startTime, Date endTime) {
public R getAppealFinishCountByLoc(Integer timeFrame, String startTime, String endTime) throws ParseException {
return R.data(largeScreenService.getAppealFinishCountByLoc(timeFrame, startTime, endTime));
}
@ -105,7 +108,7 @@ public class ReportController extends BladeController {
* 越级上报热力图(中4)
*/
@GetMapping("/getImmediateCountByLoc")
public R getImmediateCountByLoc(Integer timeFrame, Date startTime, Date endTime) {
public R getImmediateCountByLoc(Integer timeFrame, String startTime, String endTime) throws ParseException {
return R.data(largeScreenService.getImmediateCountByLoc(timeFrame, startTime, endTime));
}
@ -113,8 +116,8 @@ public class ReportController extends BladeController {
* 越级上报事件列表(中5)
*/
@GetMapping("/getImmediateList")
public R getImmediateList(String streetId) {
return R.data(largeScreenService.getImmediateList(streetId));
public R getImmediateList(String streetId, Query query) {
return R.data(largeScreenService.getImmediateList(streetId, Condition.getPage(query)));
}
/**

@ -16,6 +16,7 @@
*/
package org.springblade.modules.business.entity;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import lombok.EqualsAndHashCode;
@ -78,4 +79,10 @@ public class Appeal extends BaseEntity {
*/
private Long handleDept;
/**
* 所属街道
*/
@TableField(exist = false)
private String street;
}

@ -17,8 +17,10 @@
package org.springblade.modules.business.service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springblade.modules.business.entity.Appeal;
import java.text.ParseException;
import java.util.Date;
import java.util.List;
import java.util.Map;
@ -36,17 +38,19 @@ public interface ILargeScreenService {
List<Appeal> getAppealList();
Map<String, Object> getAppealByMon();
Map<String, List<Object>> getAppealByMon();
Map<String, Object> getAppealTypePercent();
Map<String, Object> getAppealSubmitCountByLoc(Integer timeFrame, Date startTime, Date endTime);
Map<String, Object> getAppealSubmitCountByLoc(Integer timeFrame, String startTime, String endTime) throws ParseException;
Map<String, Object> getAppealFinishCountByLoc(Integer timeFrame, Date startTime, Date endTime);
Map<String, Object> getAppealFinishCountByLoc(Integer timeFrame, String startTime, String endTime) throws ParseException;
Map<String, Object> getImmediateCountByLoc(Integer timeFrame, Date startTime, Date endTime);
Map<String, Object> getImmediateCountByLoc(Integer timeFrame, String startTime, String endTime) throws ParseException;
List<Appeal> getImmediateList(String streetId);
// IPage getImmediateList(String streetId, IPage page);
Map<String, Object> getAppealHot();
IPage<Appeal> getImmediateList(String streetId, IPage<Appeal> page);
}

@ -16,15 +16,27 @@
*/
package org.springblade.modules.business.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.models.auth.In;
import lombok.AllArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.springblade.common.cache.DictBizCache;
import org.springblade.modules.business.entity.Appeal;
import org.springblade.modules.business.service.IAppealService;
import org.springblade.modules.business.service.ILargeScreenService;
import org.springblade.modules.business.utils.LocalDateTimeUtils;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.stream.Collectors;
/**
* 服务实现类
@ -39,57 +51,303 @@ public class LargeScreenServiceImpl implements ILargeScreenService {
@Override
public Map<String, Object> getMediateFinish() {
Map<String, Object> map = new HashMap<>();
// 化解成功状态数组
List<Integer> state = new ArrayList<>();
state.add(2);
state.add(3);
LambdaQueryWrapper<Appeal> wrapper = new LambdaQueryWrapper<>();
// 总化解数
// 本年化解数
wrapper.in(Appeal::getStatus, state);
map.put("all", appealService.count(wrapper));
wrapper.clear();
// 本年度化解数
wrapper.in(Appeal::getStatus, state);
wrapper.between(Appeal::getFinishTime, LocalDateTimeUtils.yearStartTime(), LocalDateTimeUtils.yearEndTime());
map.put("year", appealService.count(wrapper));
wrapper.clear();
// 本季度化解数
wrapper.in(Appeal::getStatus, state);
wrapper.between(Appeal::getFinishTime, LocalDateTimeUtils.quarterStartTime(), LocalDateTimeUtils.quarterEndTime());
map.put("quarterly", appealService.count(wrapper));
wrapper.clear();
// 本月化解数
return null;
wrapper.in(Appeal::getStatus, state);
wrapper.between(Appeal::getFinishTime, LocalDateTimeUtils.monthStartTime(), LocalDateTimeUtils.monthEndTime());
map.put("mon", appealService.count(wrapper));
return map;
}
@Override
public Map<String, Object> getAppealSubmit() {
return null;
Map<String, Object> map = new HashMap<>();
LambdaQueryWrapper<Appeal> wrapper = new LambdaQueryWrapper<>();
// 总化解数
map.put("all", appealService.count(wrapper));
wrapper.clear();
// 本年度化解数
wrapper.between(Appeal::getFirstRegTime, LocalDateTimeUtils.yearStartTime(), LocalDateTimeUtils.yearEndTime());
map.put("year", appealService.count(wrapper));
wrapper.clear();
// 本季度化解数
wrapper.between(Appeal::getFirstRegTime, LocalDateTimeUtils.quarterStartTime(), LocalDateTimeUtils.quarterEndTime());
map.put("quarterly", appealService.count(wrapper));
wrapper.clear();
// 本月化解数
wrapper.between(Appeal::getFirstRegTime, LocalDateTimeUtils.monthStartTime(), LocalDateTimeUtils.monthEndTime());
map.put("mon", appealService.count(wrapper));
return map;
}
@Override
public List<Appeal> getAppealList() {
return null;
// 化解成功状态数组
List<Integer> state = new ArrayList<>();
state.add(0);
state.add(1);
LambdaQueryWrapper<Appeal> wrapper = new LambdaQueryWrapper<>();
// 只查这几个字段值
// wrapper.select(Appeal::getId, Appeal::getDisputeName, Appeal::getFirstRegTime, Appeal::getStatus, Appeal::getStreetId);
// 待处理、正在处理
wrapper.in(Appeal::getStatus, state);
// 根据登记时间倒序
wrapper.orderByDesc(Appeal::getFirstRegTime);
List<Appeal> appeals = appealService.list(wrapper);
// 获取前50条
List<Appeal> appealList = appeals.stream().limit(50).collect(Collectors.toList());
// 所属街道赋字典值
appealList.forEach(appeal -> appeal.setStreet(DictBizCache.getById(appeal.getStreetId()).getDictValue()));
return appealList;
}
@Override
public Map<String, Object> getAppealByMon() {
return null;
public Map<String, List<Object>> getAppealByMon() {
Map<String, List<Object>> map = new HashMap<>();
List<Object> dateList = new ArrayList<>();
List<Object> handlerCountList = new ArrayList<>();
List<Object> finishContList = new ArrayList<>();
map.put("dateList", dateList);
map.put("handlerCountList", handlerCountList);
map.put("finishContList", finishContList);
List<Integer> state = new ArrayList<>();
state.add(2);
state.add(3);
// 当月
Map<String, List<Object>> map0 = getStartAndEndTime(map, state, 0);
// 前1个月
Map<String, List<Object>> map1 = getStartAndEndTime(map0, state, 1);
// 前2个月
Map<String, List<Object>> map2 = getStartAndEndTime(map1, state, 2);
// 前3个月
Map<String, List<Object>> map3 = getStartAndEndTime(map2, state, 3);
// 前4个月
Map<String, List<Object>> map4 = getStartAndEndTime(map3, state, 4);
// 前5个月
return getStartAndEndTime(map4, state, 5);
}
@Override
public Map<String, Object> getAppealTypePercent() {
// 先查所有
// 根据纠纷类型分组(输入的纠纷类型算其他纠纷)
return null;
List<Appeal> appeals = appealService.list();
// 根据纠纷类型分组
Map<String, List<Appeal>> collect = appeals.stream().collect(Collectors.groupingBy(Appeal::getDisputeName));
Set<String> names = collect.keySet();
// 纠纷类型对应的数量
Map<String, Integer> map = new HashMap<>();
for (String name : names) {
map.put(name, collect.get(name).size());
}
// 根据数量排序
List<Map.Entry<String, Integer>> list = new ArrayList<>(map.entrySet());
list.sort((o1, o2) -> o2.getValue() - o1.getValue());
Map<String, Object> hashMap = new HashMap<>();
DecimalFormat df = new DecimalFormat("#0.0");
if (list.size() <= 5) {
for (Map.Entry<String, Integer> entry : list) {
hashMap.put(entry.getKey(), df.format((double) entry.getValue() / (double) appeals.size() * 100) + "%");
}
} else {
for (int i = 0; i < 5; i++) {
Map.Entry<String, Integer> entry = list.get(i);
hashMap.put(entry.getKey(), df.format((double) entry.getValue() / (double) appeals.size() * 100) + "%");
}
int size = 0;
for (int i = 5; i < list.size(); i++) {
Map.Entry<String, Integer> entry = list.get(i);
size += entry.getValue();
}
hashMap.put("其他纠纷", df.format((double) size / (double) appeals.size() * 100) + "%");
}
return hashMap;
}
@Override
public Map<String, Object> getAppealSubmitCountByLoc(Integer timeFrame, Date startTime, Date endTime) {
return null;
public Map<String, Object> getAppealSubmitCountByLoc(Integer timeFrame, String startTime, String endTime) throws ParseException {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
LambdaQueryWrapper<Appeal> wrapper = new LambdaQueryWrapper<>();
if (StringUtils.isNotBlank(startTime) && StringUtils.isNotBlank(endTime)) {
wrapper.between(Appeal::getFirstRegTime, dateFormat.parse(startTime), dateFormat.parse(endTime));
} else if (timeFrame == 1) {
wrapper.between(Appeal::getFirstRegTime, LocalDateTimeUtils.monthStartTime(), LocalDateTimeUtils.monthEndTime());
} else if (timeFrame == 2) {
wrapper.between(Appeal::getFirstRegTime, LocalDateTimeUtils.quarterStartTime(), LocalDateTimeUtils.quarterEndTime());
} else if (timeFrame == 3) {
wrapper.between(Appeal::getFirstRegTime, LocalDateTimeUtils.yearStartTime(), LocalDateTimeUtils.yearEndTime());
}
List<Appeal> appeals = appealService.list(wrapper);
appeals.forEach(appeal -> appeal.setStreet(DictBizCache.getById(appeal.getStreetId()).getDictValue()));
// 根据街道分组
Map<String, List<Appeal>> collect = appeals.stream().collect(Collectors.groupingBy(Appeal::getStreet));
Set<String> names = collect.keySet();
// 街道对应的数量
Map<String, Object> map = new HashMap<>();
for (String name : names) {
map.put(name, collect.get(name).size());
}
return map;
}
@Override
public Map<String, Object> getAppealFinishCountByLoc(Integer timeFrame, Date startTime, Date endTime) {
return null;
public Map<String, Object> getAppealFinishCountByLoc(Integer timeFrame, String startTime, String endTime) throws ParseException {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
// 化解成功状态数组
List<Integer> state = new ArrayList<>();
state.add(2);
state.add(3);
LambdaQueryWrapper<Appeal> wrapper = new LambdaQueryWrapper<>();
wrapper.in(Appeal::getStatus, state);
if (StringUtils.isNotBlank(startTime) && StringUtils.isNotBlank(endTime)) {
wrapper.between(Appeal::getFirstRegTime, dateFormat.parse(startTime), dateFormat.parse(endTime));
} else if (timeFrame == 1) {
wrapper.between(Appeal::getFirstRegTime, LocalDateTimeUtils.monthStartTime(), LocalDateTimeUtils.monthEndTime());
} else if (timeFrame == 2) {
wrapper.between(Appeal::getFirstRegTime, LocalDateTimeUtils.quarterStartTime(), LocalDateTimeUtils.quarterEndTime());
} else if (timeFrame == 3) {
wrapper.between(Appeal::getFirstRegTime, LocalDateTimeUtils.yearStartTime(), LocalDateTimeUtils.yearEndTime());
}
List<Appeal> appeals = appealService.list(wrapper);
appeals.forEach(appeal -> appeal.setStreet(DictBizCache.getById(appeal.getStreetId()).getDictValue()));
// 根据街道分组
Map<String, List<Appeal>> collect = appeals.stream().collect(Collectors.groupingBy(Appeal::getStreet));
Set<String> names = collect.keySet();
// 街道对应的数量
Map<String, Object> map = new HashMap<>();
for (String name : names) {
map.put(name, collect.get(name).size());
}
return map;
}
@Override
public Map<String, Object> getImmediateCountByLoc(Integer timeFrame, Date startTime, Date endTime) {
return null;
public Map<String, Object> getImmediateCountByLoc(Integer timeFrame, String startTime, String endTime) throws ParseException {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
LambdaQueryWrapper<Appeal> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(Appeal::getSkipGrant, 1);
if (StringUtils.isNotBlank(startTime) && StringUtils.isNotBlank(endTime)) {
wrapper.between(Appeal::getFirstRegTime, dateFormat.parse(startTime), dateFormat.parse(endTime));
} else if (timeFrame == 1) {
wrapper.between(Appeal::getFirstRegTime, LocalDateTimeUtils.monthStartTime(), LocalDateTimeUtils.monthEndTime());
} else if (timeFrame == 2) {
wrapper.between(Appeal::getFirstRegTime, LocalDateTimeUtils.quarterStartTime(), LocalDateTimeUtils.quarterEndTime());
} else if (timeFrame == 3) {
wrapper.between(Appeal::getFirstRegTime, LocalDateTimeUtils.yearStartTime(), LocalDateTimeUtils.yearEndTime());
}
List<Appeal> appeals = appealService.list(wrapper);
appeals.forEach(appeal -> appeal.setStreet(DictBizCache.getById(appeal.getStreetId()).getDictValue()));
// 根据街道分组
Map<String, List<Appeal>> collect = appeals.stream().collect(Collectors.groupingBy(Appeal::getStreet));
Set<String> names = collect.keySet();
// 街道对应的数量
Map<String, Object> map = new HashMap<>();
for (String name : names) {
map.put(name, collect.get(name).size());
}
return map;
}
@Override
public List<Appeal> getImmediateList(String streetId) {
return null;
public IPage<Appeal> getImmediateList(String streetId, IPage<Appeal> page) {
LambdaQueryWrapper<Appeal> wrapper = new LambdaQueryWrapper<>();
wrapper.select(Appeal::getId, Appeal::getFirstRegTime, Appeal::getDisputeName);
wrapper.eq(Appeal::getStreetId, streetId);
wrapper.eq(Appeal::getSkipGrant, 1);
IPage<Appeal> iPage = appealService.page(page, wrapper);
return iPage;
}
@Override
public Map<String, Object> getAppealHot() {
return null;
}
private Map<String, List<Object>> getStartAndEndTime(Map<String, List<Object>> map, List<Integer> state, Integer month) {
List<Object> dateList = map.get("dateList");
List<Object> handlerCountList = map.get("handlerCountList");
List<Object> finishContList = map.get("finishContList");
// 当月开始时间
LocalDateTime start = LocalDateTime.of(LocalDate.now().withDayOfMonth(1).minusMonths(month), LocalTime.MIDNIGHT);
// 当月结束时间
LocalDateTime end = start.plusMonths(1).minusSeconds(1);
DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyy-MM");
// 月份:2023-06
dateList.add(start.format(dateFormatter));
// 登记数
LambdaQueryWrapper<Appeal> wrapper = new LambdaQueryWrapper<>();
wrapper.between(Appeal::getFirstRegTime, start, end);
handlerCountList.add(appealService.count(wrapper));
// 调解成功数
wrapper.clear();
wrapper.in(Appeal::getStatus, state);
wrapper.between(Appeal::getFirstRegTime, start, end);
finishContList.add(appealService.count(wrapper));
map.put("dateList", dateList);
map.put("handlerCountList", handlerCountList);
map.put("finishContList", finishContList);
return map;
}
}

@ -0,0 +1,442 @@
package org.springblade.modules.business.utils;
import java.time.*;
import java.time.temporal.ChronoUnit;
import java.time.temporal.TemporalAdjusters;
import java.util.Date;
/**
* LocalDateTime工具类
*
*/
public class LocalDateTimeUtils {
/**
* 当前时间
*
* @return
*/
public static LocalDateTime now() {
return LocalDateTime.now();
}
/**
* Date LocalDateTime
*
* @return
*/
public static LocalDateTime convert(Date date) {
return LocalDateTime.ofInstant(Instant.ofEpochMilli(date.getTime()), ZoneId.systemDefault());
}
/**
* LocalDateTime Date
*
* @return
*/
public static Date convert(LocalDateTime localDateTime) {
return Date.from(localDateTime.atZone(ZoneId.systemDefault()).toInstant());
}
/**
* 今天开始时间
*
* @return
*/
public static LocalDateTime todayStartTime() {
return LocalDateTime.of(LocalDate.now(), LocalTime.MIN);
}
/**
* 今天结束时间
*
* @return
*/
public static LocalDateTime todayEndTime() {
return LocalDateTime.of(LocalDate.now(), LocalTime.MAX);
}
/**
* 昨天开始时间
*
* @return
*/
public static LocalDateTime yesterdayStartTime() {
return LocalDateTime.of(LocalDate.now().minus(1L, ChronoUnit.DAYS), LocalTime.MIN);
}
/**
* 昨天结束时间
*
* @return
*/
public static LocalDateTime yesterdayEndTime() {
return LocalDateTime.of(LocalDate.now().minus(1L, ChronoUnit.DAYS), LocalTime.MAX);
}
/**
* 最近7天开始时间
*
* @return
*/
public static LocalDateTime last7DaysStartTime() {
return LocalDateTime.of(LocalDate.now().minus(6L, ChronoUnit.DAYS), LocalTime.MIN);
}
/**
* 最近7天结束时间
*
* @return
*/
public static LocalDateTime last7DaysEndTime() {
return LocalDateTime.of(LocalDate.now(), LocalTime.MAX);
}
/**
* 最近30天开始时间
*
* @return
*/
public static LocalDateTime last30DaysStartTime() {
return LocalDateTime.of(LocalDate.now().minus(29L, ChronoUnit.DAYS), LocalTime.MIN);
}
/**
* 最近30天结束时间
*
* @return
*/
public static LocalDateTime last30DaysEndTime() {
return LocalDateTime.of(LocalDate.now(), LocalTime.MAX);
}
/**
* 最近一年开始时间
*
* @return
*/
public static LocalDateTime last1YearStartTime() {
return LocalDateTime.of(LocalDate.now().minus(1L, ChronoUnit.YEARS).plus(1L, ChronoUnit.DAYS), LocalTime.MIN);
}
/**
* 最近一年结束时间
*
* @return
*/
public static LocalDateTime last1YearEndTime() {
return LocalDateTime.of(LocalDate.now(), LocalTime.MAX);
}
/**
* 本周开始时间
*
* @return
*/
public static LocalDateTime weekStartTime() {
LocalDate now = LocalDate.now();
return LocalDateTime.of(now.minusDays(now.getDayOfWeek().getValue() - 1), LocalTime.MIN);
}
/**
* 本周结束时间
*
* @return
*/
public static LocalDateTime weekEndTime() {
LocalDate now = LocalDate.now();
return LocalDateTime.of(now.plusDays(7 - now.getDayOfWeek().getValue()), LocalTime.MAX);
}
/**
* 本月开始时间
*
* @return
*/
public static LocalDateTime monthStartTime() {
return LocalDateTime.of(LocalDate.now().with(TemporalAdjusters.firstDayOfMonth()), LocalTime.MIN);
}
/**
* 本月结束时间
*
* @return
*/
public static LocalDateTime monthEndTime() {
return LocalDateTime.of(LocalDate.now().with(TemporalAdjusters.lastDayOfMonth()), LocalTime.MAX);
}
/**
* 本季度开始时间
*
* @return
*/
public static LocalDateTime quarterStartTime() {
LocalDate now = LocalDate.now();
Month month = Month.of(now.getMonth().firstMonthOfQuarter().getValue());
return LocalDateTime.of(LocalDate.of(now.getYear(), month, 1), LocalTime.MIN);
}
/**
* 本季度结束时间
*
* @return
*/
public static LocalDateTime quarterEndTime() {
LocalDate now = LocalDate.now();
Month month = Month.of(now.getMonth().firstMonthOfQuarter().getValue()).plus(2L);
return LocalDateTime.of(LocalDate.of(now.getYear(), month, month.length(now.isLeapYear())), LocalTime.MAX);
}
/**
* 本半年开始时间
*
* @return
*/
public static LocalDateTime halfYearStartTime() {
LocalDate now = LocalDate.now();
Month month = (now.getMonthValue() > 6) ? Month.JULY : Month.JANUARY;
return LocalDateTime.of(LocalDate.of(now.getYear(), month, 1), LocalTime.MIN);
}
/**
* 本半年结束时间
*
* @return
*/
public static LocalDateTime halfYearEndTime() {
LocalDate now = LocalDate.now();
Month month = (now.getMonthValue() > 6) ? Month.DECEMBER : Month.JUNE;
return LocalDateTime.of(LocalDate.of(now.getYear(), month, month.length(now.isLeapYear())), LocalTime.MAX);
}
/**
* 本年开始时间
*
* @return
*/
public static LocalDateTime yearStartTime() {
return LocalDateTime.of(LocalDate.now().with(TemporalAdjusters.firstDayOfYear()), LocalTime.MIN);
}
/**
* 本年结束时间
*
* @return
*/
public static LocalDateTime yearEndTime() {
return LocalDateTime.of(LocalDate.now().with(TemporalAdjusters.lastDayOfYear()), LocalTime.MAX);
}
/**
* 上周开始时间
*
* @return
*/
public static LocalDateTime lastWeekStartTime() {
LocalDate lastWeek = LocalDate.now().minus(1L, ChronoUnit.WEEKS);
return LocalDateTime.of(lastWeek.minusDays(lastWeek.getDayOfWeek().getValue() - 1), LocalTime.MIN);
}
/**
* 上周结束时间
*
* @return
*/
public static LocalDateTime lastWeekEndTime() {
LocalDate lastWeek = LocalDate.now().minus(1L, ChronoUnit.WEEKS);
return LocalDateTime.of(lastWeek.plusDays(7 - lastWeek.getDayOfWeek().getValue()), LocalTime.MAX);
}
/**
* 上月开始时间
*
* @return
*/
public static LocalDateTime lastMonthStartTime() {
return LocalDateTime.of(LocalDate.now().minus(1L, ChronoUnit.MONTHS).with(TemporalAdjusters.firstDayOfMonth()), LocalTime.MIN);
}
/**
* 上月结束时间
*
* @return
*/
public static LocalDateTime lastMonthEndTime() {
return LocalDateTime.of(LocalDate.now().minus(1L, ChronoUnit.MONTHS).with(TemporalAdjusters.lastDayOfMonth()), LocalTime.MAX);
}
/**
* 上季度开始时间
*
* @return
*/
public static LocalDateTime lastQuarterStartTime() {
LocalDate now = LocalDate.now();
Month firstMonthOfQuarter = Month.of(now.getMonth().firstMonthOfQuarter().getValue());
Month firstMonthOfLastQuarter = firstMonthOfQuarter.minus(3L);
int yearOfLastQuarter = firstMonthOfQuarter.getValue() < 4 ? now.getYear() - 1 : now.getYear();
return LocalDateTime.of(LocalDate.of(yearOfLastQuarter, firstMonthOfLastQuarter, 1), LocalTime.MIN);
}
/**
* 上季度结束时间
*
* @return
*/
public static LocalDateTime lastQuarterEndTime() {
LocalDate now = LocalDate.now();
Month firstMonthOfQuarter = Month.of(now.getMonth().firstMonthOfQuarter().getValue());
Month firstMonthOfLastQuarter = firstMonthOfQuarter.minus(1L);
int yearOfLastQuarter = firstMonthOfQuarter.getValue() < 4 ? now.getYear() - 1 : now.getYear();
return LocalDateTime.of(LocalDate.of(yearOfLastQuarter, firstMonthOfLastQuarter, firstMonthOfLastQuarter.maxLength()), LocalTime.MAX);
}
/**
* 上半年开始时间
*
* @return
*/
public static LocalDateTime lastHalfYearStartTime() {
LocalDate now = LocalDate.now();
int lastHalfYear = (now.getMonthValue() > 6) ? now.getYear() : now.getYear() - 1;
Month firstMonthOfLastHalfYear = (now.getMonthValue() > 6) ? Month.JANUARY : Month.JULY;
return LocalDateTime.of(LocalDate.of(lastHalfYear, firstMonthOfLastHalfYear, 1), LocalTime.MIN);
}
/**
* 上半年结束时间
*
* @return
*/
public static LocalDateTime lastHalfYearEndTime() {
LocalDate now = LocalDate.now();
int lastHalfYear = (now.getMonthValue() > 6) ? now.getYear() : now.getYear() - 1;
Month lastMonthOfLastHalfYear = (now.getMonthValue() > 6) ? Month.JUNE : Month.DECEMBER;
return LocalDateTime.of(LocalDate.of(lastHalfYear, lastMonthOfLastHalfYear, lastMonthOfLastHalfYear.maxLength()), LocalTime.MAX);
}
/**
* 上一年开始时间
*
* @return
*/
public static LocalDateTime lastYearStartTime() {
return LocalDateTime.of(LocalDate.now().minus(1L, ChronoUnit.YEARS).with(TemporalAdjusters.firstDayOfYear()), LocalTime.MIN);
}
/**
* 上一年结束时间
*
* @return
*/
public static LocalDateTime lastYearEndTime() {
return LocalDateTime.of(LocalDate.now().minus(1L, ChronoUnit.YEARS).with(TemporalAdjusters.lastDayOfYear()), LocalTime.MAX);
}
/**
* 下周开始时间
*
* @return
*/
public static LocalDateTime nextWeekStartTime() {
LocalDate nextWeek = LocalDate.now().plus(1L, ChronoUnit.WEEKS);
return LocalDateTime.of(nextWeek.minusDays(nextWeek.getDayOfWeek().getValue() - 1), LocalTime.MIN);
}
/**
* 下周结束时间
*
* @return
*/
public static LocalDateTime nextWeekEndTime() {
LocalDate nextWeek = LocalDate.now().plus(1L, ChronoUnit.WEEKS);
return LocalDateTime.of(nextWeek.plusDays(7 - nextWeek.getDayOfWeek().getValue()), LocalTime.MAX);
}
/**
* 下月开始时间
*
* @return
*/
public static LocalDateTime nextMonthStartTime() {
return LocalDateTime.of(LocalDate.now().plus(1L, ChronoUnit.MONTHS).with(TemporalAdjusters.firstDayOfMonth()), LocalTime.MIN);
}
/**
* 下月结束时间
*
* @return
*/
public static LocalDateTime nextMonthEndTime() {
return LocalDateTime.of(LocalDate.now().plus(1L, ChronoUnit.MONTHS).with(TemporalAdjusters.lastDayOfMonth()), LocalTime.MAX);
}
/**
* 下季度开始时间
*
* @return
*/
public static LocalDateTime nextQuarterStartTime() {
LocalDate now = LocalDate.now();
Month firstMonthOfQuarter = Month.of(now.getMonth().firstMonthOfQuarter().getValue());
Month firstMonthOfNextQuarter = firstMonthOfQuarter.plus(3L);
int yearOfNextQuarter = firstMonthOfQuarter.getValue() > 9 ? now.getYear() + 1 : now.getYear();
return LocalDateTime.of(LocalDate.of(yearOfNextQuarter, firstMonthOfNextQuarter, 1), LocalTime.MIN);
}
/**
* 下季度结束时间
*
* @return
*/
public static LocalDateTime nextQuarterEndTime() {
LocalDate now = LocalDate.now();
Month firstMonthOfQuarter = Month.of(now.getMonth().firstMonthOfQuarter().getValue());
Month firstMonthOfNextQuarter = firstMonthOfQuarter.plus(5L);
int yearOfNextQuarter = firstMonthOfQuarter.getValue() > 9 ? now.getYear() + 1 : now.getYear();
return LocalDateTime.of(LocalDate.of(yearOfNextQuarter, firstMonthOfNextQuarter, firstMonthOfNextQuarter.maxLength()), LocalTime.MAX);
}
/**
* 上半年开始时间
*
* @return
*/
public static LocalDateTime nextHalfYearStartTime() {
LocalDate now = LocalDate.now();
int nextHalfYear = (now.getMonthValue() > 6) ? now.getYear() + 1 : now.getYear();
Month firstMonthOfNextHalfYear = (now.getMonthValue() > 6) ? Month.JANUARY : Month.JULY;
return LocalDateTime.of(LocalDate.of(nextHalfYear, firstMonthOfNextHalfYear, 1), LocalTime.MIN);
}
/**
* 上半年结束时间
*
* @return
*/
public static LocalDateTime nextHalfYearEndTime() {
LocalDate now = LocalDate.now();
int lastHalfYear = (now.getMonthValue() > 6) ? now.getYear() + 1 : now.getYear();
Month lastMonthOfNextHalfYear = (now.getMonthValue() > 6) ? Month.JUNE : Month.DECEMBER;
return LocalDateTime.of(LocalDate.of(lastHalfYear, lastMonthOfNextHalfYear, lastMonthOfNextHalfYear.maxLength()), LocalTime.MAX);
}
/**
* 下一年开始时间
*
* @return
*/
public static LocalDateTime nextYearStartTime() {
return LocalDateTime.of(LocalDate.now().plus(1L, ChronoUnit.YEARS).with(TemporalAdjusters.firstDayOfYear()), LocalTime.MIN);
}
/**
* 下一年结束时间
*
* @return
*/
public static LocalDateTime nextYearEndTime() {
return LocalDateTime.of(LocalDate.now().plus(1L, ChronoUnit.YEARS).with(TemporalAdjusters.lastDayOfYear()), LocalTime.MAX);
}
}
Loading…
Cancel
Save