Commit e0e15591 by 丁伟峰

Merge branch 'feat-calender' into develop

2 parents 64f10509 727c0e9b
......@@ -44,4 +44,22 @@ public class DateUtils {
public static long getAge(String birth){
return ChronoUnit.YEARS.between(LocalDate.parse(birth), LocalDate.now());
}
public static LocalDate localDateFromStr(String dateStr){
return localDateFromStr(dateStr, "yyyy-MM-dd");
}
public static LocalDate localDateFromStr(String str, String pattern){
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(pattern);
return LocalDate.parse(str, formatter);
}
public static LocalDateTime localDateTimeFromStr(String str){
return localDateTimeFromStr(str, "yyyy-MM-dd HH:mm:ss");
}
public static LocalDateTime localDateTimeFromStr(String str, String pattern){
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(pattern);
return LocalDateTime.parse(str, formatter);
}
}
......@@ -60,7 +60,7 @@ public class EngineerCalendarServiceImpl implements EngineerCalendarService {
Page<EngineerInfoEntity> page = engineerUtil.filterEngineersByKeyAndPage(allCodes, req.getKey(), req.getPage(), req.getSize());
String edate = LocalDate.parse(req.getDate()).plusDays(14).toString();
String edate = DateUtils.localDateFromStr(req.getDate()).plusDays(14).toString();
for (EngineerInfoEntity e : page.getContent()) {
EngineerCalendarDTO.Engineer engineer = new EngineerCalendarDTO.Engineer();
engineer.setEngineerCode(e.getEngineerCode());
......@@ -121,8 +121,8 @@ public class EngineerCalendarServiceImpl implements EngineerCalendarService {
return Result.failed("日历配置信息不存在");
}
// todo 业务检查,暂时只需要检查日期时间必须为将来; 后面还需要检查配置项是否与其他配置项在时间上有交叉
LocalDateTime time1 = fixFrontDatetime(reqDTO.getStartTime());
LocalDateTime time2 = fixFrontDatetime(reqDTO.getEndTime());
LocalDateTime time1 = DateUtils.localDateTimeFromStr(reqDTO.getStartTime());
LocalDateTime time2 = DateUtils.localDateTimeFromStr(reqDTO.getEndTime());
if (time1.isAfter(time2)) {
return Result.failed("开始/结束时间输入错误");
}
......@@ -162,8 +162,8 @@ public class EngineerCalendarServiceImpl implements EngineerCalendarService {
if (reqDTO.getEngineerCodes().isEmpty()) {
return Result.failed("没有选中工程师");
}
LocalDateTime startDate = LocalDate.parse(reqDTO.getStartDate()).atTime(LocalTime.MIDNIGHT);
LocalDateTime endDate = LocalDate.parse(reqDTO.getEndDate()).atTime(LocalTime.MIDNIGHT);
LocalDateTime startDate = DateUtils.localDateFromStr(reqDTO.getStartDate()).atTime(LocalTime.MIDNIGHT);
LocalDateTime endDate = DateUtils.localDateFromStr(reqDTO.getEndDate()).atTime(LocalTime.MIDNIGHT);
Integer num = capacityEngineerCalendarDao.queryEngineerPlanNum(reqDTO.getEngineerCodes(), startDate, endDate, reqDTO.getType());
CalendarQueryNumDTO.Result rs = new CalendarQueryNumDTO.Result();
rs.setPlanNum(num);
......@@ -171,10 +171,6 @@ public class EngineerCalendarServiceImpl implements EngineerCalendarService {
}
private LocalDateTime fixFrontDatetime(String s) {
return LocalDateTime.parse(s);
}
private List<EngineerCalendarDTO.Calendar> getOneEngineerCalendars(String engineerCode, String bdate, String edate) {
// 返回某一个技术员,日期范围内的日历列表
List<EngineerCalendarDTO.Calendar> calendars = new ArrayList<>();
......@@ -183,8 +179,8 @@ public class EngineerCalendarServiceImpl implements EngineerCalendarService {
if (teamIds == null || teamIds.isEmpty()) {
return new ArrayList<>();
}
LocalDate startDate = LocalDate.parse(bdate);
LocalDate endDate = LocalDate.parse(edate);
LocalDate startDate = DateUtils.localDateFromStr(bdate);
LocalDate endDate = DateUtils.localDateFromStr(edate);
List<LocalDate> datesInRange = Stream.iterate(startDate, date -> date.plusDays(1))
.limit(ChronoUnit.DAYS.between(startDate, endDate.plusDays(1)))
.collect(Collectors.toList());
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!