|
|
@@ -24,13 +24,20 @@ import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
import com.punchsettle.server.atomic.entity.PunchIn;
|
|
|
import com.punchsettle.server.atomic.entity.PunchInRecord;
|
|
|
+import com.punchsettle.server.atomic.entity.PunchInTask;
|
|
|
+import com.punchsettle.server.atomic.entity.PunchInTaskHistory;
|
|
|
import com.punchsettle.server.atomic.service.IPunchInRecordService;
|
|
|
import com.punchsettle.server.atomic.service.IPunchInService;
|
|
|
import com.punchsettle.server.common.exception.BusinessException;
|
|
|
import com.punchsettle.server.common.utils.Assert;
|
|
|
+import com.punchsettle.server.constant.CommonStatusEnum;
|
|
|
+import com.punchsettle.server.constant.CompareRuleEnum;
|
|
|
import com.punchsettle.server.constant.PunchInCategoryEnum;
|
|
|
+import com.punchsettle.server.constant.PunchInMethodEnum;
|
|
|
+import com.punchsettle.server.constant.PunchInRuleEnum;
|
|
|
import com.punchsettle.server.constant.PunchInSettleTypeEnum;
|
|
|
import com.punchsettle.server.constant.PunchInStatusEnum;
|
|
|
+import com.punchsettle.server.constant.PunchInStatusV1Enum;
|
|
|
import com.punchsettle.server.constant.PunchInStatusViewEnum;
|
|
|
import com.punchsettle.server.pojo.punchin.PunchInCalendarDataVO;
|
|
|
import com.punchsettle.server.pojo.punchin.PunchInDataQuery;
|
|
|
@@ -143,7 +150,8 @@ public class PunchInManagerImpl implements IPunchInManager {
|
|
|
PunchInRecord punchInRecord = weeklyRecordMap.get(weeklyDateStr);
|
|
|
|
|
|
// 根据过往打卡记录设置打卡状态
|
|
|
- PunchInStatusViewEnum punchInStatus = judgePunchInStatus(today, weeklyDate, punchInCreationDate, punchIn, punchInRecord);
|
|
|
+ PunchInStatusViewEnum punchInStatus =
|
|
|
+ judgePunchInStatus(today, weeklyDate, punchInCreationDate, punchIn, punchInRecord);
|
|
|
|
|
|
// 设置打卡记录
|
|
|
PunchInRecordVO punchInRecordVO = new PunchInRecordVO();
|
|
|
@@ -167,7 +175,8 @@ public class PunchInManagerImpl implements IPunchInManager {
|
|
|
return punchInWithRecordVOS;
|
|
|
}
|
|
|
|
|
|
- private PunchInStatusViewEnum judgePunchInStatus(LocalDate today, LocalDate weeklyDate, LocalDate punchInCreationDate, PunchIn punchIn, PunchInRecord punchInRecord) {
|
|
|
+ private PunchInStatusViewEnum judgePunchInStatus(LocalDate today, LocalDate weeklyDate,
|
|
|
+ LocalDate punchInCreationDate, PunchIn punchIn, PunchInRecord punchInRecord) {
|
|
|
// 一周某天还没到,无法打卡
|
|
|
if (weeklyDate.isAfter(today)) {
|
|
|
return PunchInStatusViewEnum.FUTURE_TIME;
|
|
|
@@ -180,17 +189,17 @@ public class PunchInManagerImpl implements IPunchInManager {
|
|
|
|
|
|
// 一周某天在今天之前存在打卡记录,则需要判断是否完成打卡
|
|
|
if (!Objects.isNull(punchInRecord) && weeklyDate.isBefore(today)) {
|
|
|
- if (PunchInStatusEnum.FINISH.equals(punchInRecord.getPunchInStatus())
|
|
|
- ||PunchInStatusEnum.REMAKE_FINISH.equals(punchInRecord.getPunchInStatus())) {
|
|
|
+ if (PunchInStatusV1Enum.FINISH.equals(punchInRecord.getPunchInStatus())
|
|
|
+ || PunchInStatusV1Enum.REMAKE_FINISH.equals(punchInRecord.getPunchInStatus())) {
|
|
|
return PunchInStatusViewEnum.PUNCH_IN;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 一周的某天是今天,且存在打卡记录,则判断是否完成打卡
|
|
|
if (weeklyDate.isEqual(today) && !Objects.isNull(punchInRecord)) {
|
|
|
- PunchInStatusEnum punchInStatusEnum = settleManager.judgePunchInStatus(punchIn, punchInRecord);
|
|
|
- if (PunchInStatusEnum.FINISH.equals(punchInStatusEnum)
|
|
|
- || PunchInStatusEnum.REMAKE_FINISH.equals(punchInStatusEnum)) {
|
|
|
+ PunchInStatusV1Enum punchInStatusV1Enum = settleManager.judgePunchInStatus(punchIn, punchInRecord);
|
|
|
+ if (PunchInStatusV1Enum.FINISH.equals(punchInStatusV1Enum)
|
|
|
+ || PunchInStatusV1Enum.REMAKE_FINISH.equals(punchInStatusV1Enum)) {
|
|
|
return PunchInStatusViewEnum.PUNCH_IN;
|
|
|
}
|
|
|
// 当天存在打卡记录,但是还没满足打卡条件,则认为打卡状态未知
|
|
|
@@ -221,12 +230,12 @@ public class PunchInManagerImpl implements IPunchInManager {
|
|
|
Assert.isNullInBusiness(request, "请传入任务信息");
|
|
|
|
|
|
if (PunchInCategoryEnum.COUNT.equals(request.getCategory())
|
|
|
- && (Objects.isNull(request.getRule()) || Objects.isNull(request.getCountTrack()))) {
|
|
|
+ && (Objects.isNull(request.getRule()) || Objects.isNull(request.getCountTrack()))) {
|
|
|
throw BusinessException.fail("打卡类型:计数,比较规则和次数不能为空");
|
|
|
}
|
|
|
|
|
|
if (PunchInCategoryEnum.TIME.equals(request.getCategory())
|
|
|
- && (Objects.isNull(request.getRule()) || Objects.isNull(request.getTimeTrack()))) {
|
|
|
+ && (Objects.isNull(request.getRule()) || Objects.isNull(request.getTimeTrack()))) {
|
|
|
throw BusinessException.fail("打卡类型:计时,比较规则和时间不能为空");
|
|
|
}
|
|
|
|
|
|
@@ -255,7 +264,7 @@ public class PunchInManagerImpl implements IPunchInManager {
|
|
|
}
|
|
|
|
|
|
PunchIn punchIn = Optional.ofNullable(punchInService.getById(request.getId()))
|
|
|
- .orElseThrow(() -> BusinessException.fail("无法查询到该打卡任务"));
|
|
|
+ .orElseThrow(() -> BusinessException.fail("无法查询到该打卡任务"));
|
|
|
if (PunchInCategoryEnum.TIME.equals(punchIn.getCategory()) && Objects.isNull(request.getTimeTrack())) {
|
|
|
BusinessException.throwFail("打卡类型:计时,请传入时间记录");
|
|
|
}
|
|
|
@@ -319,36 +328,42 @@ public class PunchInManagerImpl implements IPunchInManager {
|
|
|
}
|
|
|
|
|
|
// 获取打卡任务
|
|
|
- PunchIn punchIn = Optional.ofNullable(punchInService.getById(request.getPunchInId())).orElseThrow(() -> BusinessException.fail("无法查询到该打卡任务"));
|
|
|
+ PunchIn punchIn = Optional.ofNullable(punchInService.getById(request.getPunchInId()))
|
|
|
+ .orElseThrow(() -> BusinessException.fail("无法查询到该打卡任务"));
|
|
|
// 补打卡的打卡日期不能早于打卡任务创建日期
|
|
|
if (punchInDate.isBefore(punchIn.getCreationTime().toLocalDateTime().toLocalDate())) {
|
|
|
BusinessException.throwFail("补打卡日期不能早于打卡任务创建日期");
|
|
|
}
|
|
|
|
|
|
- settleManager.settleHandler(PunchInSettleTypeEnum.REMAKE, punchInDate, Arrays.asList(UserUtils.getCurrentUserId()), Arrays.asList(request.getPunchInId()));
|
|
|
+ settleManager.settleHandler(PunchInSettleTypeEnum.REMAKE, punchInDate,
|
|
|
+ Arrays.asList(UserUtils.getCurrentUserId()), Arrays.asList(request.getPunchInId()));
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void revokePunchIn(PunchInRecordRequest request) {
|
|
|
// 获取打卡任务
|
|
|
- PunchIn punchIn = Optional.ofNullable(punchInService.getById(request.getPunchInId())).orElseThrow(() -> BusinessException.fail("无法查询到该打卡任务"));
|
|
|
+ PunchIn punchIn = Optional.ofNullable(punchInService.getById(request.getPunchInId()))
|
|
|
+ .orElseThrow(() -> BusinessException.fail("无法查询到该打卡任务"));
|
|
|
|
|
|
PunchInRecordQuery punchInRecordQuery = new PunchInRecordQuery();
|
|
|
punchInRecordQuery.setPunchInId(request.getPunchInId());
|
|
|
punchInRecordQuery.setPunchInDate(LocalDate.now().toString());
|
|
|
PunchInRecord punchInRecord = punchInRecordService.selectOneByCondition(punchInRecordQuery);
|
|
|
if (Objects.isNull(punchInRecord)) {
|
|
|
- log.info("打卡任务:{},打卡日期:{} 没有找到当天打卡记录,进行撤销", punchInRecordQuery.getPunchInId(), punchInRecordQuery.getPunchInDate());
|
|
|
+ log.info("打卡任务:{},打卡日期:{} 没有找到当天打卡记录,进行撤销", punchInRecordQuery.getPunchInId(),
|
|
|
+ punchInRecordQuery.getPunchInDate());
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
// 单次打卡/计时打卡 直接删除记录即可
|
|
|
- if (PunchInCategoryEnum.SINGLE.equals(punchIn.getCategory()) || PunchInCategoryEnum.TIME.equals(punchIn.getCategory())) {
|
|
|
+ if (PunchInCategoryEnum.SINGLE.equals(punchIn.getCategory())
|
|
|
+ || PunchInCategoryEnum.TIME.equals(punchIn.getCategory())) {
|
|
|
punchInRecordService.delete(punchInRecord.getId());
|
|
|
}
|
|
|
|
|
|
// 计数打卡,需要减去打卡次数
|
|
|
- if (PunchInCategoryEnum.COUNT.equals(punchIn.getCategory()) && Optional.ofNullable(punchInRecord.getCountTrack()).orElse(0) > 0) {
|
|
|
+ if (PunchInCategoryEnum.COUNT.equals(punchIn.getCategory())
|
|
|
+ && Optional.ofNullable(punchInRecord.getCountTrack()).orElse(0) > 0) {
|
|
|
PunchInRecord updateRecord = new PunchInRecord();
|
|
|
updateRecord.setId(punchInRecord.getId());
|
|
|
updateRecord.setCountTrack(punchInRecord.getCountTrack() - 1);
|
|
|
@@ -361,7 +376,8 @@ public class PunchInManagerImpl implements IPunchInManager {
|
|
|
|
|
|
@Override
|
|
|
public PunchInDataVO queryPunchInData(PunchInDataQuery query) {
|
|
|
- PunchIn punchIn = Optional.ofNullable(punchInService.getById(query.getId())).orElseThrow(() -> BusinessException.fail("找到指定的打卡任务"));
|
|
|
+ PunchIn punchIn = Optional.ofNullable(punchInService.getById(query.getId()))
|
|
|
+ .orElseThrow(() -> BusinessException.fail("找到指定的打卡任务"));
|
|
|
|
|
|
SimpleDateFormat sdf = DateUtils.buildDateFormat();
|
|
|
YearMonth yearMonth = YearMonth.of(query.getYear(), query.getMonth());
|
|
|
@@ -387,8 +403,8 @@ public class PunchInManagerImpl implements IPunchInManager {
|
|
|
BeanUtils.copyProperties(punchInRecord, punchInRecordDataVO);
|
|
|
punchInRecordDtoList.add(punchInRecordDataVO);
|
|
|
|
|
|
- if (PunchInStatusEnum.UN_FINISH.equals(punchInRecord.getPunchInStatus())
|
|
|
- || PunchInStatusEnum.DOING.equals(punchInRecord.getPunchInStatus())) {
|
|
|
+ if (PunchInStatusV1Enum.UN_FINISH.equals(punchInRecord.getPunchInStatus())
|
|
|
+ || PunchInStatusV1Enum.DOING.equals(punchInRecord.getPunchInStatus())) {
|
|
|
continue;
|
|
|
}
|
|
|
PunchInCalendarDataVO punchInCalendarDataVO = new PunchInCalendarDataVO();
|
|
|
@@ -401,11 +417,11 @@ public class PunchInManagerImpl implements IPunchInManager {
|
|
|
// 计算全勤率
|
|
|
BigDecimal punchInRate = BigDecimal.ZERO;
|
|
|
// 要考虑任务刚创建的情况,任务较迟创建的话则使用任务创建时间
|
|
|
- long dayLength = ChronoUnit.DAYS.between(firstOfMonth.isBefore(punchInCreationDate) ? punchInCreationDate : firstOfMonth, LocalDate.now());
|
|
|
+ long dayLength = ChronoUnit.DAYS
|
|
|
+ .between(firstOfMonth.isBefore(punchInCreationDate) ? punchInCreationDate : firstOfMonth, LocalDate.now());
|
|
|
if (dayLength != 0) {
|
|
|
punchInRate = BigDecimal.valueOf(punchInCalendarDataVOS.size())
|
|
|
- .divide(BigDecimal.valueOf(dayLength), 4, RoundingMode.HALF_DOWN)
|
|
|
- .multiply(ONE_HUNDRED);
|
|
|
+ .divide(BigDecimal.valueOf(dayLength), 4, RoundingMode.HALF_DOWN).multiply(ONE_HUNDRED);
|
|
|
}
|
|
|
|
|
|
// 构造返回结果
|
|
|
@@ -419,4 +435,54 @@ public class PunchInManagerImpl implements IPunchInManager {
|
|
|
|
|
|
return punchInDataVO;
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public PunchInStatusEnum judgePunchInStatus(PunchInTask punchInTask, PunchInTaskHistory punchInTaskHistory, boolean holidayFlag) {
|
|
|
+ Assert.isNullInBusiness(punchInTask, "打卡任务不能为空 ");
|
|
|
+ // 没有打卡记录,直接没完成
|
|
|
+ if (Objects.isNull(punchInTaskHistory)) {
|
|
|
+ return PunchInStatusEnum.UNDONE;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 单次打卡,不区分是否节假日
|
|
|
+ if (PunchInMethodEnum.SINGLE.equals(punchInTask.getPunchInMethod())) {
|
|
|
+ int countTrack = Optional.ofNullable(punchInTask.getCountTrack()).orElse(0);
|
|
|
+ return countTrack > 0 ? PunchInStatusEnum.DONE : PunchInStatusEnum.UNDONE;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 打卡任务的节假日启用配置
|
|
|
+ CommonStatusEnum holidayStatus = Optional.ofNullable(punchInTask.getHolidayStatus()).orElse(CommonStatusEnum.DISABLED);
|
|
|
+ boolean enableHolidayFlag = CommonStatusEnum.ENABLED.equals(holidayStatus) && holidayFlag;
|
|
|
+
|
|
|
+ // 计数打卡,要区分是否节假日使用不同的判断标准
|
|
|
+ if (PunchInMethodEnum.COUNT.equals(punchInTask.getPunchInMethod())) {
|
|
|
+
|
|
|
+ int countTrackTarget = Optional.ofNullable(enableHolidayFlag ? punchInTask.getHolidayCountTrack() : punchInTask.getCountTrack()).orElse(0);
|
|
|
+ int countTrack = Optional.ofNullable(punchInTaskHistory.getCountTrack()).orElse(0);
|
|
|
+ if (CompareRuleEnum.GTE.equals(punchInTask.getCompareRule()) && )
|
|
|
+ if (PunchInRuleEnum.GREATER_OR_EQUAL.equals(punchIn.getRule()) && recordCountTrack.compareTo(punchIn.getCountTrack()) == -1) {
|
|
|
+ return PunchInStatusV1Enum.UN_FINISH;
|
|
|
+ }
|
|
|
+ if (PunchInRuleEnum.LESS_OR_EQUAL.equals(punchIn.getRule()) && recordCountTrack.compareTo(punchIn.getCountTrack()) == 1) {
|
|
|
+ return PunchInStatusV1Enum.UN_FINISH;
|
|
|
+ }
|
|
|
+
|
|
|
+ return PunchInStatusV1Enum.FINISH;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 计时打卡,要区分是否节假日使用不同的判断标准
|
|
|
+ if (PunchInCategoryEnum.TIME.equals(punchIn.getCategory())) {
|
|
|
+ LocalTime recordTimeTrack = Optional.ofNullable(punchInRecord.getTimeTrack()).orElse(LocalTime.parse("00:00:00.000"));
|
|
|
+ if (PunchInRuleEnum.GREATER_OR_EQUAL.equals(punchIn.getRule()) && recordTimeTrack.compareTo(punchIn.getTimeTrack()) == -1) {
|
|
|
+ return PunchInStatusV1Enum.UN_FINISH;
|
|
|
+ }
|
|
|
+ if (PunchInRuleEnum.LESS_OR_EQUAL.equals(punchIn.getRule()) && recordTimeTrack.compareTo(punchIn.getTimeTrack()) == 1) {
|
|
|
+ return PunchInStatusV1Enum.UN_FINISH;
|
|
|
+ }
|
|
|
+
|
|
|
+ return PunchInStatusV1Enum.FINISH;
|
|
|
+ }
|
|
|
+
|
|
|
+ return PunchInStatusEnum.UNDONE;
|
|
|
+ }
|
|
|
}
|