|
@@ -1,8 +1,9 @@
|
|
|
package com.punchsettle.server.service.manager.impl;
|
|
package com.punchsettle.server.service.manager.impl;
|
|
|
|
|
|
|
|
import java.sql.Timestamp;
|
|
import java.sql.Timestamp;
|
|
|
-import java.time.DayOfWeek;
|
|
|
|
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
import java.time.LocalDate;
|
|
import java.time.LocalDate;
|
|
|
|
|
+import java.time.LocalTime;
|
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
@@ -11,23 +12,12 @@ import java.util.Optional;
|
|
|
import java.util.function.Function;
|
|
import java.util.function.Function;
|
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
-import com.punchsettle.server.common.exception.BusinessException;
|
|
|
|
|
-import com.punchsettle.server.common.utils.Assert;
|
|
|
|
|
-import com.punchsettle.server.constant.PunchInCategoryEnum;
|
|
|
|
|
-import com.punchsettle.server.constant.PunchInRuleEnum;
|
|
|
|
|
-import com.punchsettle.server.constant.PunchInSettleTypeEnum;
|
|
|
|
|
-import com.punchsettle.server.constant.PunchInStatusEnum;
|
|
|
|
|
-import com.punchsettle.server.dto.settle.SettleDto;
|
|
|
|
|
-import com.punchsettle.server.dto.settle.SettleInfoDto;
|
|
|
|
|
-import com.punchsettle.server.dto.settle.SettleQuery;
|
|
|
|
|
-import com.punchsettle.server.dto.settle.SettleRequest;
|
|
|
|
|
-import com.punchsettle.server.dto.settle.SettleResultDto;
|
|
|
|
|
-import com.punchsettle.server.utiis.SpringUtils;
|
|
|
|
|
import org.springframework.beans.BeanUtils;
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
+import org.springframework.util.StringUtils;
|
|
|
|
|
|
|
|
import com.punchsettle.server.atomic.entity.PunchIn;
|
|
import com.punchsettle.server.atomic.entity.PunchIn;
|
|
|
import com.punchsettle.server.atomic.entity.PunchInRecord;
|
|
import com.punchsettle.server.atomic.entity.PunchInRecord;
|
|
@@ -41,14 +31,24 @@ import com.punchsettle.server.atomic.service.IPunchInService;
|
|
|
import com.punchsettle.server.atomic.service.IPunchInSettlementService;
|
|
import com.punchsettle.server.atomic.service.IPunchInSettlementService;
|
|
|
import com.punchsettle.server.atomic.service.ISettlementTaskService;
|
|
import com.punchsettle.server.atomic.service.ISettlementTaskService;
|
|
|
import com.punchsettle.server.atomic.service.IUserService;
|
|
import com.punchsettle.server.atomic.service.IUserService;
|
|
|
|
|
+import com.punchsettle.server.common.exception.BusinessException;
|
|
|
|
|
+import com.punchsettle.server.common.utils.Assert;
|
|
|
|
|
+import com.punchsettle.server.constant.PunchInCategoryEnum;
|
|
|
|
|
+import com.punchsettle.server.constant.PunchInRuleEnum;
|
|
|
|
|
+import com.punchsettle.server.constant.PunchInSettleTypeEnum;
|
|
|
|
|
+import com.punchsettle.server.constant.PunchInStatusEnum;
|
|
|
import com.punchsettle.server.dto.punchin.PunchInQuery;
|
|
import com.punchsettle.server.dto.punchin.PunchInQuery;
|
|
|
import com.punchsettle.server.dto.punchin.PunchInRecordQuery;
|
|
import com.punchsettle.server.dto.punchin.PunchInRecordQuery;
|
|
|
-import com.punchsettle.server.dto.task.SettleRewardTaskDto;
|
|
|
|
|
|
|
+import com.punchsettle.server.dto.settle.SettleDto;
|
|
|
|
|
+import com.punchsettle.server.dto.settle.SettleInfoDto;
|
|
|
|
|
+import com.punchsettle.server.dto.settle.SettleQuery;
|
|
|
|
|
+import com.punchsettle.server.dto.settle.SettleRequest;
|
|
|
|
|
+import com.punchsettle.server.dto.settle.SettleResultDto;
|
|
|
import com.punchsettle.server.service.manager.ISettleManager;
|
|
import com.punchsettle.server.service.manager.ISettleManager;
|
|
|
import com.punchsettle.server.utiis.DateUtils;
|
|
import com.punchsettle.server.utiis.DateUtils;
|
|
|
|
|
+import com.punchsettle.server.utiis.SpringUtils;
|
|
|
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
-import org.springframework.util.StringUtils;
|
|
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* @author tyuio
|
|
* @author tyuio
|
|
@@ -117,7 +117,9 @@ public class SettleManagerImpl implements ISettleManager {
|
|
|
// 读取用户的打卡任务,如果punchIds为空则结算用户所有的打卡任务
|
|
// 读取用户的打卡任务,如果punchIds为空则结算用户所有的打卡任务
|
|
|
PunchInQuery punchInQuery = new PunchInQuery();
|
|
PunchInQuery punchInQuery = new PunchInQuery();
|
|
|
punchInQuery.setUserIds(userIds);
|
|
punchInQuery.setUserIds(userIds);
|
|
|
- punchInQuery.setPunchInIds(punchInIds);
|
|
|
|
|
|
|
+ if (!CollectionUtils.isEmpty(punchInIds)) {
|
|
|
|
|
+ punchInQuery.setPunchInIds(punchInIds);
|
|
|
|
|
+ }
|
|
|
List<PunchIn> punchIns = punchInService.listByCondition(punchInQuery);
|
|
List<PunchIn> punchIns = punchInService.listByCondition(punchInQuery);
|
|
|
if (CollectionUtils.isEmpty(punchIns)) {
|
|
if (CollectionUtils.isEmpty(punchIns)) {
|
|
|
log.info("结算任务结束,原因:没有找到打卡任务");
|
|
log.info("结算任务结束,原因:没有找到打卡任务");
|
|
@@ -132,7 +134,7 @@ public class SettleManagerImpl implements ISettleManager {
|
|
|
recordQuery.setEndDate(settleInfo.getSettleDateStr());
|
|
recordQuery.setEndDate(settleInfo.getSettleDateStr());
|
|
|
recordQuery.setPunchInIds(punchInIds);
|
|
recordQuery.setPunchInIds(punchInIds);
|
|
|
List<PunchInRecord> punchInRecords = punchInRecordService.listByCondition(recordQuery);
|
|
List<PunchInRecord> punchInRecords = punchInRecordService.listByCondition(recordQuery);
|
|
|
- if (CollectionUtils.isEmpty(punchInRecords)) {
|
|
|
|
|
|
|
+ if (CollectionUtils.isEmpty(punchInRecords) && !PunchInSettleTypeEnum.REMAKE.equals(settleInfo.getSettleType())) {
|
|
|
log.info("结算任务结束,原因:没有打卡记录");
|
|
log.info("结算任务结束,原因:没有打卡记录");
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
@@ -155,17 +157,6 @@ public class SettleManagerImpl implements ISettleManager {
|
|
|
// 打卡任务-打卡记录 map
|
|
// 打卡任务-打卡记录 map
|
|
|
Map<Long, PunchInRecord> punchInRecordMap = punchInRecords.stream().collect(Collectors.toMap(PunchInRecord::getPunchInId, Function.identity(), (key1, key2) -> key1));
|
|
Map<Long, PunchInRecord> punchInRecordMap = punchInRecords.stream().collect(Collectors.toMap(PunchInRecord::getPunchInId, Function.identity(), (key1, key2) -> key1));
|
|
|
|
|
|
|
|
- // 待更新的用户
|
|
|
|
|
- List<User> updateUsers = new ArrayList<>();
|
|
|
|
|
- // 新增的打卡结算关联关系
|
|
|
|
|
- List<PunchInRecordSettlementRela> addRelas = new ArrayList<>();
|
|
|
|
|
- // 待更新的打卡记录
|
|
|
|
|
- List<PunchInRecord> updatePunchInRecords = new ArrayList<>();
|
|
|
|
|
- // 待新增的打卡记录
|
|
|
|
|
- List<PunchInRecord> addPunchInRecords = new ArrayList<>();
|
|
|
|
|
- // 待新增的打卡结算信息
|
|
|
|
|
- List<PunchInSettlement> addPunchInSettlements = new ArrayList<>();
|
|
|
|
|
-
|
|
|
|
|
// 先创建结算任务执行记录
|
|
// 先创建结算任务执行记录
|
|
|
SettlementTask settlementTask = new SettlementTask();
|
|
SettlementTask settlementTask = new SettlementTask();
|
|
|
settlementTask.setSettleDate(settleDate.toString());
|
|
settlementTask.setSettleDate(settleDate.toString());
|
|
@@ -174,13 +165,27 @@ public class SettleManagerImpl implements ISettleManager {
|
|
|
settlementTaskService.insert(settlementTask);
|
|
settlementTaskService.insert(settlementTask);
|
|
|
|
|
|
|
|
// 结算
|
|
// 结算
|
|
|
|
|
+ List<SettleResultDto> settleResultDtoList = new ArrayList<>();
|
|
|
for (User user : users) {
|
|
for (User user : users) {
|
|
|
SettleResultDto settleResult = settle(settleInfo, user, userPunchInMap.get(user.getId()), punchInRecordMap, weeklyPunchInRecords);
|
|
SettleResultDto settleResult = settle(settleInfo, user, userPunchInMap.get(user.getId()), punchInRecordMap, weeklyPunchInRecords);
|
|
|
|
|
+ settleResultDtoList.add(settleResult);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 更新数据
|
|
|
|
|
+ // 待更新的用户
|
|
|
|
|
+ List<User> updateUsers = new ArrayList<>();
|
|
|
|
|
+ // 待更新的打卡记录
|
|
|
|
|
+ List<PunchInRecord> updatePunchInRecords = new ArrayList<>();
|
|
|
|
|
+ // 待新增的打卡记录
|
|
|
|
|
+ List<PunchInRecord> addPunchInRecords = new ArrayList<>();
|
|
|
|
|
+ // 待新增的打卡结算信息
|
|
|
|
|
+ List<PunchInSettlement> addPunchInSettlements = new ArrayList<>();
|
|
|
|
|
+
|
|
|
|
|
+ for (SettleResultDto settleResult : settleResultDtoList) {
|
|
|
updateUsers.add(settleResult.getUpdateUser());
|
|
updateUsers.add(settleResult.getUpdateUser());
|
|
|
- addRelas.addAll(settleResult.getAddRelas());
|
|
|
|
|
addPunchInRecords.addAll(settleResult.getAddPunchInRecords());
|
|
addPunchInRecords.addAll(settleResult.getAddPunchInRecords());
|
|
|
updatePunchInRecords.addAll(settleResult.getUpdatePunchInRecords());
|
|
updatePunchInRecords.addAll(settleResult.getUpdatePunchInRecords());
|
|
|
- addPunchInSettlements.add(settleResult.getAddPunchInSettlements());
|
|
|
|
|
|
|
+ addPunchInSettlements.add(settleResult.getAddPunchInSettlement());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 更新用户奖励信息
|
|
// 更新用户奖励信息
|
|
@@ -193,18 +198,24 @@ public class SettleManagerImpl implements ISettleManager {
|
|
|
punchInRecordService.batchInsert(addPunchInRecords);
|
|
punchInRecordService.batchInsert(addPunchInRecords);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ // 更新已有的打卡记录
|
|
|
if (!CollectionUtils.isEmpty(updatePunchInRecords)) {
|
|
if (!CollectionUtils.isEmpty(updatePunchInRecords)) {
|
|
|
punchInRecordService.batchUpdate(updatePunchInRecords);
|
|
punchInRecordService.batchUpdate(updatePunchInRecords);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 新增结算信息
|
|
// 新增结算信息
|
|
|
if (!CollectionUtils.isEmpty(addPunchInSettlements)) {
|
|
if (!CollectionUtils.isEmpty(addPunchInSettlements)) {
|
|
|
|
|
+ // 补充本次的计算任务ID
|
|
|
|
|
+ addPunchInSettlements.stream().forEach(v -> v.setSettlementTaskId(settlementTask.getId()));
|
|
|
punchInSettlementService.batchInsert(addPunchInSettlements);
|
|
punchInSettlementService.batchInsert(addPunchInSettlements);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 新增关联信息
|
|
// 新增关联信息
|
|
|
- if (!CollectionUtils.isEmpty(addRelas)) {
|
|
|
|
|
- punchInRecordSettlementRelaService.batchInsert(addRelas);
|
|
|
|
|
|
|
+ if (!CollectionUtils.isEmpty(settleResultDtoList)) {
|
|
|
|
|
+ List<PunchInRecordSettlementRela> relaList = buildPunchInRecordSettlementRelaList(settleResultDtoList);
|
|
|
|
|
+ if (!CollectionUtils.isEmpty(relaList)) {
|
|
|
|
|
+ punchInRecordSettlementRelaService.batchInsert(relaList);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 构造并新增结算任务信息
|
|
// 构造并新增结算任务信息
|
|
@@ -228,8 +239,6 @@ public class SettleManagerImpl implements ISettleManager {
|
|
|
private SettleResultDto settle(SettleInfoDto settleInfo, User user, List<PunchIn> punchIns, Map<Long, PunchInRecord> punchInRecordMap, Map<Long, List<PunchInRecord>> weeklyPunchInRecordMap) {
|
|
private SettleResultDto settle(SettleInfoDto settleInfo, User user, List<PunchIn> punchIns, Map<Long, PunchInRecord> punchInRecordMap, Map<Long, List<PunchInRecord>> weeklyPunchInRecordMap) {
|
|
|
// 结算奖励数
|
|
// 结算奖励数
|
|
|
int settleRewardNum = 0;
|
|
int settleRewardNum = 0;
|
|
|
- // 新增的打卡结算关联关系
|
|
|
|
|
- List<PunchInRecordSettlementRela> addRelas = new ArrayList<>();
|
|
|
|
|
// 待更新的打卡记录
|
|
// 待更新的打卡记录
|
|
|
List<PunchInRecord> updatePunchInRecords = new ArrayList<>();
|
|
List<PunchInRecord> updatePunchInRecords = new ArrayList<>();
|
|
|
// 待新增的打卡记录
|
|
// 待新增的打卡记录
|
|
@@ -238,43 +247,49 @@ public class SettleManagerImpl implements ISettleManager {
|
|
|
for (PunchIn punchIn : punchIns) {
|
|
for (PunchIn punchIn : punchIns) {
|
|
|
// 获取打卡记录
|
|
// 获取打卡记录
|
|
|
PunchInRecord punchInRecord = punchInRecordMap.get(punchIn.getId());
|
|
PunchInRecord punchInRecord = punchInRecordMap.get(punchIn.getId());
|
|
|
|
|
+ // 不是补打卡且不存在打卡记录直接跳过,无须结算和更新记录状态
|
|
|
|
|
+ if (!PunchInSettleTypeEnum.REMAKE.equals(settleInfo.getSettleType()) && Objects.isNull(punchInRecord)) {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
// 判断是否满足打卡规则
|
|
// 判断是否满足打卡规则
|
|
|
PunchInStatusEnum punchInStatus = judgePunchInStatus(punchIn, punchInRecord);
|
|
PunchInStatusEnum punchInStatus = judgePunchInStatus(punchIn, punchInRecord);
|
|
|
- //不满足则跳过无需接续,如果是补卡则直接完成继续计算
|
|
|
|
|
|
|
+ // 不是补卡或打卡任务未完成,则跳过
|
|
|
if (!PunchInSettleTypeEnum.REMAKE.equals(settleInfo.getSettleType()) && PunchInStatusEnum.UN_FINISH.equals(punchInStatus)) {
|
|
if (!PunchInSettleTypeEnum.REMAKE.equals(settleInfo.getSettleType()) && PunchInStatusEnum.UN_FINISH.equals(punchInStatus)) {
|
|
|
- punchInRecord.setPunchInStatus(punchInStatus);
|
|
|
|
|
- updatePunchInRecords.add(punchInRecord);
|
|
|
|
|
|
|
+ PunchInRecord updatePunchInRecord = buildPunchInRecordForSettle(punchIn);
|
|
|
|
|
+ updatePunchInRecord.setId(punchInRecord.getId());
|
|
|
|
|
+ updatePunchInRecord.setPunchInStatus(punchInStatus);
|
|
|
|
|
+ updatePunchInRecords.add(updatePunchInRecord);
|
|
|
continue;
|
|
continue;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 补打卡,完全没有打卡记录则需要补充打卡记录
|
|
// 补打卡,完全没有打卡记录则需要补充打卡记录
|
|
|
if (PunchInSettleTypeEnum.REMAKE.equals(settleInfo.getSettleType()) && Objects.isNull(punchInRecord)) {
|
|
if (PunchInSettleTypeEnum.REMAKE.equals(settleInfo.getSettleType()) && Objects.isNull(punchInRecord)) {
|
|
|
- punchInRecord = new PunchInRecord();
|
|
|
|
|
|
|
+ punchInRecord = buildPunchInRecordForSettle(punchIn);
|
|
|
punchInRecord.setPunchInId(punchIn.getId());
|
|
punchInRecord.setPunchInId(punchIn.getId());
|
|
|
punchInRecord.setPunchInDate(settleInfo.getSettleDateStr());
|
|
punchInRecord.setPunchInDate(settleInfo.getSettleDateStr());
|
|
|
|
|
+ punchInRecord.setPunchInStatus(PunchInStatusEnum.REMAKE_FINISH);
|
|
|
addPunchInRecords.add(punchInRecord);
|
|
addPunchInRecords.add(punchInRecord);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 补打卡,已有打卡记录但是不满足打卡规则,则需要对打卡记录做准备
|
|
// 补打卡,已有打卡记录但是不满足打卡规则,则需要对打卡记录做准备
|
|
|
if (PunchInSettleTypeEnum.REMAKE.equals(settleInfo.getSettleType()) && PunchInStatusEnum.UN_FINISH.equals(punchInStatus)) {
|
|
if (PunchInSettleTypeEnum.REMAKE.equals(settleInfo.getSettleType()) && PunchInStatusEnum.UN_FINISH.equals(punchInStatus)) {
|
|
|
- punchInRecord.setPunchInStatus(PunchInStatusEnum.REMAKE_FINISH);
|
|
|
|
|
fillTrack(punchIn, punchInRecord);
|
|
fillTrack(punchIn, punchInRecord);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ // 不是补卡,且打卡状态为完成,需要更新打卡状态为完成
|
|
|
|
|
+ if (Objects.isNull(punchInRecord.getPunchInStatus()) || PunchInStatusEnum.DOING.equals(punchInRecord.getPunchInStatus())) {
|
|
|
|
|
+ PunchInRecord updatePunchInRecord = buildPunchInRecordForSettle(punchIn);
|
|
|
|
|
+ updatePunchInRecord.setId(punchInRecord.getId());
|
|
|
|
|
+ updatePunchInRecord.setPunchInStatus(punchInStatus);
|
|
|
|
|
+ updatePunchInRecords.add(updatePunchInRecord);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
// 周末双倍奖励,否则计算普通奖励
|
|
// 周末双倍奖励,否则计算普通奖励
|
|
|
settleRewardNum += settleInfo.getWeekendFlag() ? punchIn.getRewardNum() * 2 : punchIn.getRewardNum();
|
|
settleRewardNum += settleInfo.getWeekendFlag() ? punchIn.getRewardNum() * 2 : punchIn.getRewardNum();
|
|
|
// 计算全勤双倍奖励
|
|
// 计算全勤双倍奖励
|
|
|
if (judgeFullAttendance(settleInfo, punchIn, weeklyPunchInRecordMap)) {
|
|
if (judgeFullAttendance(settleInfo, punchIn, weeklyPunchInRecordMap)) {
|
|
|
settleRewardNum += punchIn.getRewardNum() * 2;
|
|
settleRewardNum += punchIn.getRewardNum() * 2;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- // 构建结算任务与记录关联信息
|
|
|
|
|
- PunchInRecordSettlementRela rela = new PunchInRecordSettlementRela();
|
|
|
|
|
- rela.setRecordId(punchInRecord.getId());
|
|
|
|
|
- rela.setRewardNum(punchIn.getRewardNum());
|
|
|
|
|
- rela.setCategory(punchIn.getCategory());
|
|
|
|
|
- rela.setRule(punchIn.getRule());
|
|
|
|
|
- addRelas.add(rela);
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 计算结算前后,用户奖励数的变化
|
|
// 计算结算前后,用户奖励数的变化
|
|
@@ -297,11 +312,10 @@ public class SettleManagerImpl implements ISettleManager {
|
|
|
updateUser.setUnclaimedRewardNum(afterSettleRewardNum);
|
|
updateUser.setUnclaimedRewardNum(afterSettleRewardNum);
|
|
|
|
|
|
|
|
SettleResultDto settleResultDto = new SettleResultDto();
|
|
SettleResultDto settleResultDto = new SettleResultDto();
|
|
|
- settleResultDto.setAddRelas(addRelas);
|
|
|
|
|
settleResultDto.setUpdateUser(updateUser);
|
|
settleResultDto.setUpdateUser(updateUser);
|
|
|
settleResultDto.setAddPunchInRecords(addPunchInRecords);
|
|
settleResultDto.setAddPunchInRecords(addPunchInRecords);
|
|
|
settleResultDto.setUpdatePunchInRecords(updatePunchInRecords);
|
|
settleResultDto.setUpdatePunchInRecords(updatePunchInRecords);
|
|
|
- settleResultDto.setAddPunchInSettlements(addPunchInSettlement);
|
|
|
|
|
|
|
+ settleResultDto.setAddPunchInSettlement(addPunchInSettlement);
|
|
|
return settleResultDto;
|
|
return settleResultDto;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -319,16 +333,17 @@ public class SettleManagerImpl implements ISettleManager {
|
|
|
|
|
|
|
|
// 计数打卡
|
|
// 计数打卡
|
|
|
if (PunchInCategoryEnum.COUNT.equals(punchIn.getCategory())) {
|
|
if (PunchInCategoryEnum.COUNT.equals(punchIn.getCategory())) {
|
|
|
- if (PunchInRuleEnum.GREATER.equals(punchIn.getRule()) && punchInRecord.getCountTrack().compareTo(punchIn.getCountTrack()) < 1) {
|
|
|
|
|
|
|
+ Integer recordCountTrack = Optional.ofNullable(punchInRecord.getCountTrack()).orElse(0);
|
|
|
|
|
+ if (PunchInRuleEnum.GREATER.equals(punchIn.getRule()) && recordCountTrack.compareTo(punchIn.getCountTrack()) < 1) {
|
|
|
return PunchInStatusEnum.UN_FINISH;
|
|
return PunchInStatusEnum.UN_FINISH;
|
|
|
}
|
|
}
|
|
|
- if (PunchInRuleEnum.GREATER_OR_EQUAL.equals(punchIn.getRule()) && punchInRecord.getCountTrack().compareTo(punchIn.getCountTrack()) == -1) {
|
|
|
|
|
|
|
+ if (PunchInRuleEnum.GREATER_OR_EQUAL.equals(punchIn.getRule()) && recordCountTrack.compareTo(punchIn.getCountTrack()) == -1) {
|
|
|
return PunchInStatusEnum.UN_FINISH;
|
|
return PunchInStatusEnum.UN_FINISH;
|
|
|
}
|
|
}
|
|
|
- if (PunchInRuleEnum.LESS.equals(punchIn.getRule()) && punchInRecord.getCountTrack().compareTo(punchIn.getCountTrack()) > -1) {
|
|
|
|
|
|
|
+ if (PunchInRuleEnum.LESS.equals(punchIn.getRule()) && recordCountTrack.compareTo(punchIn.getCountTrack()) > -1) {
|
|
|
return PunchInStatusEnum.UN_FINISH;
|
|
return PunchInStatusEnum.UN_FINISH;
|
|
|
}
|
|
}
|
|
|
- if (PunchInRuleEnum.LESS_OR_EQUAL.equals(punchIn.getRule()) && punchInRecord.getCountTrack().compareTo(punchIn.getCountTrack()) == 1) {
|
|
|
|
|
|
|
+ if (PunchInRuleEnum.LESS_OR_EQUAL.equals(punchIn.getRule()) && recordCountTrack.compareTo(punchIn.getCountTrack()) == 1) {
|
|
|
return PunchInStatusEnum.UN_FINISH;
|
|
return PunchInStatusEnum.UN_FINISH;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -337,16 +352,17 @@ public class SettleManagerImpl implements ISettleManager {
|
|
|
|
|
|
|
|
// 计时打卡
|
|
// 计时打卡
|
|
|
if (PunchInCategoryEnum.TIME.equals(punchIn.getCategory())) {
|
|
if (PunchInCategoryEnum.TIME.equals(punchIn.getCategory())) {
|
|
|
- if (PunchInRuleEnum.GREATER.equals(punchIn.getRule()) && punchInRecord.getTimeTrack().compareTo(punchIn.getTimeTrack()) < 1) {
|
|
|
|
|
|
|
+ LocalTime recordTimeTrack = Optional.ofNullable(punchInRecord.getTimeTrack()).orElse(LocalTime.parse("00:00:00.000"));
|
|
|
|
|
+ if (PunchInRuleEnum.GREATER.equals(punchIn.getRule()) && recordTimeTrack.compareTo(punchIn.getTimeTrack()) < 1) {
|
|
|
return PunchInStatusEnum.UN_FINISH;
|
|
return PunchInStatusEnum.UN_FINISH;
|
|
|
}
|
|
}
|
|
|
- if (PunchInRuleEnum.GREATER_OR_EQUAL.equals(punchIn.getRule()) && punchInRecord.getTimeTrack().compareTo(punchIn.getTimeTrack()) == -1) {
|
|
|
|
|
|
|
+ if (PunchInRuleEnum.GREATER_OR_EQUAL.equals(punchIn.getRule()) && recordTimeTrack.compareTo(punchIn.getTimeTrack()) == -1) {
|
|
|
return PunchInStatusEnum.UN_FINISH;
|
|
return PunchInStatusEnum.UN_FINISH;
|
|
|
}
|
|
}
|
|
|
- if (PunchInRuleEnum.LESS.equals(punchIn.getRule()) && punchInRecord.getTimeTrack().compareTo(punchIn.getTimeTrack()) > -1) {
|
|
|
|
|
|
|
+ if (PunchInRuleEnum.LESS.equals(punchIn.getRule()) && recordTimeTrack.compareTo(punchIn.getTimeTrack()) > -1) {
|
|
|
return PunchInStatusEnum.UN_FINISH;
|
|
return PunchInStatusEnum.UN_FINISH;
|
|
|
}
|
|
}
|
|
|
- if (PunchInRuleEnum.LESS_OR_EQUAL.equals(punchIn.getRule()) && punchInRecord.getTimeTrack().compareTo(punchIn.getTimeTrack()) == 1) {
|
|
|
|
|
|
|
+ if (PunchInRuleEnum.LESS_OR_EQUAL.equals(punchIn.getRule()) && recordTimeTrack.compareTo(punchIn.getTimeTrack()) == 1) {
|
|
|
return PunchInStatusEnum.UN_FINISH;
|
|
return PunchInStatusEnum.UN_FINISH;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -410,9 +426,57 @@ public class SettleManagerImpl implements ISettleManager {
|
|
|
return weeklyFinishRecord.size() >= 5;
|
|
return weeklyFinishRecord.size() >= 5;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 构建待更新结算数据的打卡记录
|
|
|
|
|
+ * @return
|
|
|
|
|
+ */
|
|
|
|
|
+ private PunchInRecord buildPunchInRecordForSettle(PunchIn punchIn) {
|
|
|
|
|
+ PunchInRecord updatePunchInRecord = new PunchInRecord();
|
|
|
|
|
+ updatePunchInRecord.setSettleRewardNum(punchIn.getRewardNum());
|
|
|
|
|
+ updatePunchInRecord.setSettleCategory(punchIn.getCategory());
|
|
|
|
|
+ updatePunchInRecord.setSettleRule(punchIn.getRule());
|
|
|
|
|
+ updatePunchInRecord.setSettleCountTrack(punchIn.getCountTrack());
|
|
|
|
|
+ updatePunchInRecord.setSettleTimeTrack(punchIn.getTimeTrack());
|
|
|
|
|
+ return updatePunchInRecord;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 构造打卡记录与结算记录的关联关系
|
|
|
|
|
+ * @param settleResultDtos
|
|
|
|
|
+ * @return
|
|
|
|
|
+ */
|
|
|
|
|
+ private static List<PunchInRecordSettlementRela> buildPunchInRecordSettlementRelaList(List<SettleResultDto> settleResultDtos) {
|
|
|
|
|
+ if (CollectionUtils.isEmpty(settleResultDtos)) {
|
|
|
|
|
+ return List.of();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ List<PunchInRecordSettlementRela> relaList = new ArrayList();
|
|
|
|
|
+ // 补充关联关系ID(结算记录ID、打卡记录ID)
|
|
|
|
|
+ for (SettleResultDto settleResultDto : settleResultDtos) {
|
|
|
|
|
+ for (PunchInRecord punchInRecord : settleResultDto.getAddPunchInRecords()) {
|
|
|
|
|
+ PunchInRecordSettlementRela rela = new PunchInRecordSettlementRela();
|
|
|
|
|
+ rela.setRecordId(punchInRecord.getId());
|
|
|
|
|
+ rela.setSettlementId(settleResultDto.getAddPunchInSettlement().getId());
|
|
|
|
|
+ relaList.add(rela);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ for (PunchInRecord punchInRecord : settleResultDto.getUpdatePunchInRecords()) {
|
|
|
|
|
+ PunchInRecordSettlementRela rela = new PunchInRecordSettlementRela();
|
|
|
|
|
+ rela.setRecordId(punchInRecord.getId());
|
|
|
|
|
+ rela.setSettlementId(settleResultDto.getAddPunchInSettlement().getId());
|
|
|
|
|
+ relaList.add(rela);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return relaList;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
@Override
|
|
@Override
|
|
|
public void manualSettle(SettleRequest settleRequest) {
|
|
public void manualSettle(SettleRequest settleRequest) {
|
|
|
|
|
+ // TODO 这里考虑加判断条件防止重复手动结算
|
|
|
Assert.isNullInBusiness(settleRequest, "结算请求不能为空");
|
|
Assert.isNullInBusiness(settleRequest, "结算请求不能为空");
|
|
|
|
|
+ if (!PunchInSettleTypeEnum.OPS.equals(settleRequest.getSettleType())) {
|
|
|
|
|
+ BusinessException.throwFail("非运维结算,禁止执行");
|
|
|
|
|
+ }
|
|
|
SpringUtils.getBean(ISettleManager.class).settleHandler(settleRequest.getSettleType(), LocalDate.parse(settleRequest.getSettleDate()), settleRequest.getUserIds(), settleRequest.getPunchInIds());
|
|
SpringUtils.getBean(ISettleManager.class).settleHandler(settleRequest.getSettleType(), LocalDate.parse(settleRequest.getSettleDate()), settleRequest.getUserIds(), settleRequest.getPunchInIds());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -425,10 +489,13 @@ public class SettleManagerImpl implements ISettleManager {
|
|
|
query.setStartDate(String.format("%s 00:00:00.000", query.getStartDate()));
|
|
query.setStartDate(String.format("%s 00:00:00.000", query.getStartDate()));
|
|
|
query.setEndDate(String.format("%s 23:59:59.999", query.getEndDate()));
|
|
query.setEndDate(String.format("%s 23:59:59.999", query.getEndDate()));
|
|
|
|
|
|
|
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
|
|
+
|
|
|
List<PunchInSettlement> punchInSettlements = punchInSettlementService.listByCondition(query);
|
|
List<PunchInSettlement> punchInSettlements = punchInSettlementService.listByCondition(query);
|
|
|
return punchInSettlements.stream().map(settlement -> {
|
|
return punchInSettlements.stream().map(settlement -> {
|
|
|
SettleDto dto = new SettleDto();
|
|
SettleDto dto = new SettleDto();
|
|
|
BeanUtils.copyProperties(settlement, dto);
|
|
BeanUtils.copyProperties(settlement, dto);
|
|
|
|
|
+ dto.setSettlementTime(sdf.format(settlement.getSettlementTime()));
|
|
|
return dto;
|
|
return dto;
|
|
|
}).toList();
|
|
}).toList();
|
|
|
}
|
|
}
|