|
|
@@ -43,7 +43,6 @@ import com.punchsettle.server.constant.PunchInMethodEnum;
|
|
|
import com.punchsettle.server.constant.PunchInResultEnum;
|
|
|
import com.punchsettle.server.constant.PunchInResultViewEnum;
|
|
|
import com.punchsettle.server.constant.RepeatCategoryEnum;
|
|
|
-import com.punchsettle.server.constant.SettleResultEnum;
|
|
|
import com.punchsettle.server.constant.StatPeriodEnum;
|
|
|
import com.punchsettle.server.constant.VersionStatusEnum;
|
|
|
import com.punchsettle.server.pojo.punchIn.PiTaskHistoryQuery;
|
|
|
@@ -63,7 +62,6 @@ import com.punchsettle.server.pojo.ucharts.LineVO;
|
|
|
import com.punchsettle.server.service.manager.ICalendarManager;
|
|
|
import com.punchsettle.server.service.manager.IPunchInCoreManager;
|
|
|
import com.punchsettle.server.service.manager.IPunchInManager;
|
|
|
-import com.punchsettle.server.service.manager.ISettleManager;
|
|
|
import com.punchsettle.server.utiis.DateUtils;
|
|
|
import com.punchsettle.server.utiis.UserUtils;
|
|
|
|
|
|
@@ -79,9 +77,6 @@ import lombok.extern.slf4j.Slf4j;
|
|
|
@Service
|
|
|
public class PunchInManagerImpl implements IPunchInManager {
|
|
|
|
|
|
- @Autowired
|
|
|
- private ISettleManager settleManager;
|
|
|
-
|
|
|
@Autowired
|
|
|
private IPiTaskService piTaskService;
|
|
|
|
|
|
@@ -107,9 +102,9 @@ public class PunchInManagerImpl implements IPunchInManager {
|
|
|
private IPiStatusService piStatusService;
|
|
|
|
|
|
/**
|
|
|
- * 默认显示时间00:00:00.000
|
|
|
+ * 默认时间00:00:00.000
|
|
|
*/
|
|
|
- private static final LocalTime DEFAULT_DISPLAY_TIME = LocalTime.parse("00:00:00.000");
|
|
|
+ private static final LocalTime ZERO_TIME = LocalTime.parse("00:00:00.000");
|
|
|
|
|
|
@Override
|
|
|
public List<PiTaskToDoVO> queryToDoList(Long currentUserId) {
|
|
|
@@ -138,7 +133,7 @@ public class PunchInManagerImpl implements IPunchInManager {
|
|
|
// 3.根据displayOrder进行排序,按自然顺序排列
|
|
|
return piTasks.stream().filter(piTask -> punchInCoreManager.judgeRepeat(piTask, today))
|
|
|
.filter(piTask -> {
|
|
|
- LocalTime displayTime = Optional.ofNullable(piTask.getDisplayTime()).orElse(DEFAULT_DISPLAY_TIME);
|
|
|
+ LocalTime displayTime = Optional.ofNullable(piTask.getDisplayTime()).orElse(ZERO_TIME);
|
|
|
return nowTime.compareTo(displayTime) > -1;
|
|
|
})
|
|
|
.sorted(Comparator.comparing(piTask -> Optional.ofNullable(piTask.getDisplayOrder()).orElse(0)))
|
|
|
@@ -163,11 +158,7 @@ public class PunchInManagerImpl implements IPunchInManager {
|
|
|
public List<PiTaskSimpleVO> queryTaskList() {
|
|
|
Long currentUserId = UserUtils.getCurrentUserId();
|
|
|
// 查询打卡任务
|
|
|
- PiTaskQuery piTaskQuery = new PiTaskQuery();
|
|
|
- piTaskQuery.setArchiveStatus(ArchiveStatusEnum.ACTIVE);
|
|
|
- piTaskQuery.setTaskStatus(VersionStatusEnum.ACTIVE);
|
|
|
- piTaskQuery.setUserIds(Arrays.asList(currentUserId));
|
|
|
- List<PiTask> piTasks = piTaskService.queryByCondition(piTaskQuery);
|
|
|
+ List<PiTask> piTasks = piTaskService.getActiveTask(Arrays.asList(currentUserId));
|
|
|
|
|
|
if (CollectionUtils.isEmpty(piTasks)) {
|
|
|
return List.of();
|
|
|
@@ -288,6 +279,11 @@ public class PunchInManagerImpl implements IPunchInManager {
|
|
|
public void saveTask(PiTaskRequest request) {
|
|
|
Assert.isNullInBusiness(request, "请传入任务信息");
|
|
|
|
|
|
+ // 今天
|
|
|
+ LocalDate today = LocalDate.now();
|
|
|
+ // 当前用户ID
|
|
|
+ Long currentUserId = UserUtils.getCurrentUserId();
|
|
|
+
|
|
|
// 数据校验
|
|
|
if (PunchInMethodEnum.TIMING.equals(request.getPunchInMethod())) {
|
|
|
if (Objects.isNull(request.getCompareRule()) || Objects.isNull(request.getTimeTrack())) {
|
|
|
@@ -328,6 +324,9 @@ public class PunchInManagerImpl implements IPunchInManager {
|
|
|
if (CommonEnableStatusEnum.ENABLED.equals(request.getTaskPointsStatus()) && CollectionUtils.isEmpty(request.getContinueTaskExtList())) {
|
|
|
throw BusinessException.fail("启用了任务积分计算,连续任务积分区间信息不能为空");
|
|
|
}
|
|
|
+ if (Objects.nonNull(request.getEndDate()) && request.getEndDate().isBefore(today)) {
|
|
|
+ throw BusinessException.fail("任务自动归档时间无效,必需大于等于当前时间");
|
|
|
+ }
|
|
|
|
|
|
// 新增打卡任务
|
|
|
PiTask addPiTask = new PiTask();
|
|
|
@@ -350,11 +349,6 @@ public class PunchInManagerImpl implements IPunchInManager {
|
|
|
piTaskService.update(updatePiTask);
|
|
|
}
|
|
|
|
|
|
- // 今天
|
|
|
- LocalDate today = LocalDate.now();
|
|
|
- // 当前用户ID
|
|
|
- Long currentUserId = UserUtils.getCurrentUserId();
|
|
|
-
|
|
|
// 保存数据
|
|
|
piTaskService.insert(addPiTask);
|
|
|
// 如果首次保存,需要设置唯一ID
|
|
|
@@ -494,54 +488,6 @@ public class PunchInManagerImpl implements IPunchInManager {
|
|
|
cacheManager.getCache(CacheNameConstant.TASK_STAT).evict(String.format("%s_%s", currentUserId, punchInDate.substring(0, 4)));
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public void autoPunchIn(PiTask piTask, String punchInDate) {
|
|
|
- // 当前用户ID
|
|
|
- Long currentUserId = piTask.getCreatedBy();
|
|
|
- // 是否节假日
|
|
|
- boolean holidayFlag = calendarManager.judgeHoliday(punchInDate);
|
|
|
-
|
|
|
- // 查询今天的打卡记录
|
|
|
- PiTaskHistory oldPiTaskHistory = piTaskHistoryService.getByTaskUniqueIdAndPunchInDate(piTask.getUniqueId(), punchInDate);
|
|
|
-
|
|
|
- // 新增的打卡记录
|
|
|
- PiTaskHistory tempPiTaskHistory = new PiTaskHistory();
|
|
|
- tempPiTaskHistory.setTaskId(piTask.getId());
|
|
|
- tempPiTaskHistory.setTaskUniqueId(piTask.getUniqueId());
|
|
|
- tempPiTaskHistory.setPunchInDate(punchInDate);
|
|
|
- tempPiTaskHistory.setUserId(currentUserId);
|
|
|
-
|
|
|
- // 打卡类型:单次打卡,
|
|
|
- if (PunchInMethodEnum.SINGLE.equals(piTask.getPunchInMethod())) {
|
|
|
- // 默认打卡次数是1,是计数打卡的特例
|
|
|
- tempPiTaskHistory.setCountTrack(1);
|
|
|
- }
|
|
|
-
|
|
|
- // 打卡类型:计数,需要累加打卡次数
|
|
|
- if (PunchInMethodEnum.COUNT.equals(piTask.getPunchInMethod())) {
|
|
|
- tempPiTaskHistory.setCountTrack(holidayFlag ? piTask.getHolidayCountTrack() : piTask.getCountTrack());
|
|
|
- }
|
|
|
-
|
|
|
- // 打卡类型:计时,需要记录最新打卡时长
|
|
|
- if (PunchInMethodEnum.TIMING.equals(piTask.getPunchInMethod())) {
|
|
|
- tempPiTaskHistory.setTimeTrack(holidayFlag ? piTask.getHolidayTimeTrack() : piTask.getTimeTrack());
|
|
|
- }
|
|
|
-
|
|
|
- // 设置打卡结果
|
|
|
- PunchInResultEnum punchInResult = punchInCoreManager.judgePunchInResultInTask(piTask, tempPiTaskHistory);
|
|
|
- tempPiTaskHistory.setPunchInResult(punchInResult);
|
|
|
-
|
|
|
- // 新增或更新
|
|
|
- piTaskHistoryService.insert(tempPiTaskHistory);
|
|
|
-
|
|
|
- // 清楚缓存
|
|
|
- cacheManager.getCache(CacheNameConstant.TASK_LIST_VO).evict(currentUserId);
|
|
|
- cacheManager.getCache(CacheNameConstant.TASK_PUNCH_IN_HISTORY).evict(String.format("%s_%s", currentUserId, punchInDate));
|
|
|
- cacheManager.getCache(CacheNameConstant.TASK_HISTORY_LIST_FOR_USER).evict(String.format("%s_%s", currentUserId, punchInDate));
|
|
|
- cacheManager.getCache(CacheNameConstant.TASK_STAT).evict(String.format("%s_%s", currentUserId, punchInDate.substring(0, 7)));
|
|
|
- cacheManager.getCache(CacheNameConstant.TASK_STAT).evict(String.format("%s_%s", currentUserId, punchInDate.substring(0, 4)));
|
|
|
- }
|
|
|
-
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public void archiveTask(Long id) {
|
|
|
@@ -580,7 +526,7 @@ public class PunchInManagerImpl implements IPunchInManager {
|
|
|
|
|
|
// 计时打卡 时间置为00:00:00.000
|
|
|
if (PunchInMethodEnum.TIMING.equals(piTask.getPunchInMethod())) {
|
|
|
- updatePiTaskHistory.setTimeTrack(DEFAULT_DISPLAY_TIME);
|
|
|
+ updatePiTaskHistory.setTimeTrack(ZERO_TIME);
|
|
|
}
|
|
|
|
|
|
// 计数打卡,当前打卡次数减1
|
|
|
@@ -729,14 +675,7 @@ public class PunchInManagerImpl implements IPunchInManager {
|
|
|
@Cacheable(cacheNames = CacheNameConstant.TASK_LIST_FOR_USER, key = "#userId", condition = "#userId != null")
|
|
|
public List<PiTask> getTaskListInCache(Long userId) {
|
|
|
Assert.isNullInBusiness(userId, "用户ID不能为空");
|
|
|
-
|
|
|
- PiTaskQuery piTaskQuery = new PiTaskQuery();
|
|
|
- piTaskQuery.setArchiveStatus(ArchiveStatusEnum.ACTIVE);
|
|
|
- piTaskQuery.setTaskStatus(VersionStatusEnum.ACTIVE);
|
|
|
- piTaskQuery.setUserIds(Arrays.asList(userId));
|
|
|
- List<PiTask> piTasks = piTaskService.queryByCondition(piTaskQuery);
|
|
|
-
|
|
|
- return piTasks;
|
|
|
+ return piTaskService.getActiveTask(Arrays.asList(userId));
|
|
|
}
|
|
|
|
|
|
@Override
|