Commit fdffd27d by 刘鑫

refactor(工程师工作日历时间窗): 重构提取公共项

1 parent 7f60e171
package com.dituhui.pea.order.service;
import com.dituhui.pea.common.Result;
import com.dituhui.pea.order.common.OccupyInfo;
import com.dituhui.pea.order.common.OccupyInfoDetail;
import com.dituhui.pea.order.dto.CalendarBatAddDTO;
import com.dituhui.pea.order.dto.CalendarBatDelDTO;
......@@ -71,4 +72,14 @@ public interface EngineerCalendarService {
* @apiNote 时间窗格式:[[起始时间段1, 结束时间段1],[起始时间段2, 结束时间段2]] <br/> 时间格式: 从0点开始的分钟数, 如8:00AM 为480
*/
int[][] timeWindows(String engineerCode, String teamId, LocalDate targetDate);
/**
* 获取工程师的工作时间窗
* *
* * @param engineerCode 工程师编号
* * @param teamId 工程师所属工作队 (解决一个工程师属多个多工作对情况)
* * @param targetDate 目标日期
* * @return 时间窗格式
*/
List<OccupyInfoDetail> timeWindowsSlice(String engineerCode, String teamId, LocalDate targetDate);
}
......@@ -613,27 +613,47 @@ public class EngineerCalendarServiceImpl implements EngineerCalendarService {
@Override
public int[][] timeWindows(String engineerCode, String teamId, LocalDate targetDate) {
final LocalDateTime minDate = LocalDateTime.of(targetDate, LocalTime.MIN);
//工作时间与时间时间并集求差集
List<OccupyInfoDetail> result = timeWindowsSlice(engineerCode, teamId, targetDate);
if (CollectionUtils.isEmpty(result)) {
return new int[0][];
}
int[][] ints = new int[result.size()][2];
for (int i = 0; i < result.size(); i++) {
OccupyInfoDetail occupy = result.get(i);
int start = (int) Duration.between(occupy.getBeginTime(), minDate).abs().toMinutes();
int end = (int) Duration.between(occupy.getEndTime(), minDate).abs().toMinutes();
ints[i][0] = start;
ints[i][1] = end;
}
return ints;
}
@Override
public List<OccupyInfoDetail> timeWindowsSlice(String engineerCode, String teamId, LocalDate targetDate) {
EngineerInfoEntity engineerInfoEntity = engineerInfoDao.selectEngineerByEngineerCodeAndTeamId(engineerCode, teamId);
if (Objects.isNull(engineerInfoEntity)) {
return new int[0][];
return Collections.emptyList();
}
OrgTeamEntity e = orgTeamDao.getByTeamId(teamId);
List<String> workDay = List.of(e.getWorkdays().split(","));
final int dayOfWeek = targetDate.getDayOfWeek().getValue();
if (!workDay.contains(String.valueOf(dayOfWeek))) {
return new int[0][];
return Collections.emptyList();
}
//是工作日, 取当前天的日历事件
EngineerBusinessEntity businessEntity = engineerBusinessDao.getByEngineerCode(engineerCode);
LocalDateTime workStartTime = DateUtils.localDateTimeFromStr(String.format("%s %s:00", targetDate, businessEntity.getWorkOn()));
LocalDateTime workEndTime = DateUtils.localDateTimeFromStr(String.format("%s %s:00", targetDate, businessEntity.getWorkOff()));
final LocalDateTime minDate = LocalDateTime.of(targetDate, LocalTime.MIN);
List<OccupyInfoDetail> configs = getEngineerWorkDayCalendar(engineerCode, targetDate);
if (CollectionUtils.isEmpty(configs)) {
return new int[][]{{(int) Duration.between(workStartTime, minDate).abs().toMinutes(), (int) Duration.between(workEndTime, minDate).abs().toMinutes()}};
OccupyInfoDetail occupyInfoDetail = new OccupyInfoDetail(workStartTime, workEndTime);
return List.of(occupyInfoDetail);
}
// 多个休息时间不存在交集
......@@ -645,23 +665,9 @@ public class EngineerCalendarServiceImpl implements EngineerCalendarService {
return usedTime;
}).collect(Collectors.toList());
//工作时间与时间时间并集求差集
List<OccupyInfoDetail> result = CapacityUtils.intervalTime(workStartTime, workEndTime, usedTimeInfo);
if (CollectionUtils.isEmpty(result)) {
return new int[0][];
}
int[][] ints = new int[result.size()][2];
for (int i = 0; i < result.size(); i++) {
OccupyInfoDetail occupy = result.get(i);
int start = (int) Duration.between(occupy.getBeginTime(), minDate).abs().toMinutes();
int end = (int) Duration.between(occupy.getEndTime(), minDate).abs().toMinutes();
ints[i][0] = start;
ints[i][1] = end;
}
return ints;
return CapacityUtils.intervalTime(workStartTime, workEndTime, usedTimeInfo);
}
private EngineerCalendarDTO.Calendar getEmptyCalendar(String teamId, String date) {
// 初始化一天的日历
EngineerCalendarDTO.Calendar calendar = new EngineerCalendarDTO.Calendar();
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!