|
@@ -13,6 +13,13 @@ import java.util.Set;
|
|
|
import java.util.function.Function;
|
|
import java.util.function.Function;
|
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
+import com.punchsettle.server.atomic.entity.Account;
|
|
|
|
|
+import com.punchsettle.server.atomic.entity.AccountTransferHistory;
|
|
|
|
|
+import com.punchsettle.server.atomic.service.IAccountService;
|
|
|
|
|
+import com.punchsettle.server.atomic.service.IAccountTransferHistoryService;
|
|
|
|
|
+import com.punchsettle.server.constant.AccountCategoryEnum;
|
|
|
|
|
+import com.punchsettle.server.constant.TransferCategoryEnum;
|
|
|
|
|
+import com.punchsettle.server.pojo.punchIn.AccountQuery;
|
|
|
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.Component;
|
|
import org.springframework.stereotype.Component;
|
|
@@ -135,6 +142,12 @@ public class PunchInSettleManagerImpl implements IPunchInSettleManager {
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private ISettleManager settleManager;
|
|
private ISettleManager settleManager;
|
|
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private IAccountService accountService;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private IAccountTransferHistoryService accountTransferHistoryService;
|
|
|
|
|
+
|
|
|
@Override
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public void punchInSettle(List<Long> userIds, String punchInDateStr, Long settleTaskHistoryId) {
|
|
public void punchInSettle(List<Long> userIds, String punchInDateStr, Long settleTaskHistoryId) {
|
|
@@ -161,6 +174,10 @@ public class PunchInSettleManagerImpl implements IPunchInSettleManager {
|
|
|
List<StatPiTaskMonth> addStatPiTaskMonthList = new ArrayList<>();
|
|
List<StatPiTaskMonth> addStatPiTaskMonthList = new ArrayList<>();
|
|
|
// 结算积分记录 新增列表
|
|
// 结算积分记录 新增列表
|
|
|
List<SettlePointsHistory> addSettlePointsHistories = new ArrayList<>();
|
|
List<SettlePointsHistory> addSettlePointsHistories = new ArrayList<>();
|
|
|
|
|
+ // 转张记录 新增列表
|
|
|
|
|
+ List<AccountTransferHistory> addAccountTransferHistories = new ArrayList<>();
|
|
|
|
|
+ // 账户 更新列表
|
|
|
|
|
+ List<Account> updateAccountList = new ArrayList<>();
|
|
|
// 用户信息 更新列表
|
|
// 用户信息 更新列表
|
|
|
List<User> updateUserList = new ArrayList<>();
|
|
List<User> updateUserList = new ArrayList<>();
|
|
|
// 打卡状态 更新列表
|
|
// 打卡状态 更新列表
|
|
@@ -168,7 +185,8 @@ public class PunchInSettleManagerImpl implements IPunchInSettleManager {
|
|
|
// 打卡任务记录 更新列表
|
|
// 打卡任务记录 更新列表
|
|
|
List<PiTaskHistory> updatePunchInTaskHistories = new ArrayList<>();
|
|
List<PiTaskHistory> updatePunchInTaskHistories = new ArrayList<>();
|
|
|
// 打卡多任务记录 更新列表
|
|
// 打卡多任务记录 更新列表
|
|
|
- List<PiMultiTaskHistory> updatePunchInMultiTaskHistories = new ArrayList<>(userIds.size());
|
|
|
|
|
|
|
+ List<PiMultiTaskHistory> updatePunchInMultiTaskHistories = new ArrayList<>();
|
|
|
|
|
+
|
|
|
// 获取结算数据
|
|
// 获取结算数据
|
|
|
List<PunchInSettleData> punchInSettleData = getPunchInSettleData(userIds, punchInDateStr);
|
|
List<PunchInSettleData> punchInSettleData = getPunchInSettleData(userIds, punchInDateStr);
|
|
|
|
|
|
|
@@ -193,6 +211,7 @@ public class PunchInSettleManagerImpl implements IPunchInSettleManager {
|
|
|
BeanUtils.copyProperties(piStatus, piStatusHistoryInTask);
|
|
BeanUtils.copyProperties(piStatus, piStatusHistoryInTask);
|
|
|
addPiStatusHistories.add(piStatusHistoryInTask);
|
|
addPiStatusHistories.add(piStatusHistoryInTask);
|
|
|
|
|
|
|
|
|
|
+ // 打卡记录
|
|
|
PiTaskHistory updatePiTaskHistory = new PiTaskHistory();
|
|
PiTaskHistory updatePiTaskHistory = new PiTaskHistory();
|
|
|
updatePiTaskHistory.setId(piTaskHistory.getId());
|
|
updatePiTaskHistory.setId(piTaskHistory.getId());
|
|
|
|
|
|
|
@@ -209,126 +228,17 @@ public class PunchInSettleManagerImpl implements IPunchInSettleManager {
|
|
|
punchInSettle.getPiMultiTaskHistory().setPunchInResult(punchInResult);
|
|
punchInSettle.getPiMultiTaskHistory().setPunchInResult(punchInResult);
|
|
|
updatePiTaskHistory.setPunchInResult(punchInResult);
|
|
updatePiTaskHistory.setPunchInResult(punchInResult);
|
|
|
|
|
|
|
|
- // 更新状态表数据
|
|
|
|
|
|
|
+ // 更新打卡状态
|
|
|
piStatus.setStatusDate(punchInDateStr);
|
|
piStatus.setStatusDate(punchInDateStr);
|
|
|
|
|
+ refreshPiStatus(piStatus, punchInResult, piTask, piTaskHistory, punchInDate, isMonday, isFirstDayOfMonth, yearWeek, yearMonth);
|
|
|
|
|
|
|
|
- // 设置任务连续状态
|
|
|
|
|
- ContinueStatusEnum oldTaskContinueStatus = piStatus.getTaskContinueStatus();
|
|
|
|
|
- piStatus.setTaskContinueStatus(punchInResult.equals(PunchInResultEnum.DONE)
|
|
|
|
|
- ? ContinueStatusEnum.CONTINUE : ContinueStatusEnum.INTERRUPTED);
|
|
|
|
|
- piStatus.setTaskContinueDay(oldTaskContinueStatus.equals(piStatus.getTaskContinueStatus())
|
|
|
|
|
- ? piStatus.getTaskContinueDay() + 1 : 1);
|
|
|
|
|
-
|
|
|
|
|
- // 旧的连续阶段
|
|
|
|
|
- ContinueStageEnum oldContinueStage = piStatus.getContinueStage();
|
|
|
|
|
- // 判断当前处于的连续阶段
|
|
|
|
|
- ContinueStageEnum continueStageResult =
|
|
|
|
|
- punchInManager.judgeContinueStageInTask(piTask, piTaskHistory, piStatus, punchInDate);
|
|
|
|
|
- piStatus.setContinueStage(continueStageResult);
|
|
|
|
|
- // 下面3种情况不处理:宽限期 变 宽限期;正常打卡期 变 正常打卡期;惩罚期 变 惩罚期;
|
|
|
|
|
- // 宽限期 变 正常打卡期,则设置阶段开始时间,重置中断次数
|
|
|
|
|
- if (ContinueStageEnum.GRACE_STAGE.equals(oldContinueStage)
|
|
|
|
|
- && ContinueStageEnum.NORMAL_STAGE.equals(continueStageResult)) {
|
|
|
|
|
- piStatus.setStageStartDate(punchInDate);
|
|
|
|
|
- piStatus.setContinueInterruptedCount(0);
|
|
|
|
|
- }
|
|
|
|
|
- // 如果正常打卡期 变 惩罚期,则设置阶段开始时间和阶段结束时间,增加中断次数
|
|
|
|
|
- if (ContinueStageEnum.NORMAL_STAGE.equals(oldContinueStage)
|
|
|
|
|
- && ContinueStageEnum.PENALTY_STAGE.equals(continueStageResult)) {
|
|
|
|
|
- piStatus.setStageStartDate(punchInDate);
|
|
|
|
|
- piStatus.setStageEndDate(punchInDate.plusDays(piTask.getPenaltyDay()));
|
|
|
|
|
- piStatus.setContinueInterruptedCount(piStatus.getContinueInterruptedCount() + 1);
|
|
|
|
|
- }
|
|
|
|
|
- // 如果惩罚期 变 正常打卡期,则设置阶段开始时间
|
|
|
|
|
- if (ContinueStageEnum.PENALTY_STAGE.equals(oldContinueStage)
|
|
|
|
|
- && ContinueStageEnum.NORMAL_STAGE.equals(continueStageResult)) {
|
|
|
|
|
- piStatus.setStageStartDate(punchInDate);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // 周一或月初
|
|
|
|
|
- if (isMonday || isFirstDayOfMonth) {
|
|
|
|
|
- piStatus.setRepeatCategory(piTask.getRepeatCategory());
|
|
|
|
|
- piStatus.setRepeatCustomDay(piTask.getRepeatCustomDay());
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // 周一
|
|
|
|
|
- if (isMonday) {
|
|
|
|
|
- piStatus.setStatTimeInWeek(yearWeek);
|
|
|
|
|
-
|
|
|
|
|
- // 设置本周总打卡次数
|
|
|
|
|
- int PunchInTotalCountInWeek = punchInManager.getPunchInTotalCountInRange(piTask.getRepeatCategory(),
|
|
|
|
|
- piTask.getRepeatCustomDay(), DateUtils.getFirstDayOfWeek(punchInDate),
|
|
|
|
|
- DateUtils.getLastDayOfWeek(punchInDate));
|
|
|
|
|
- piStatus.setPunchInTotalCountInWeek(PunchInTotalCountInWeek);
|
|
|
|
|
-
|
|
|
|
|
- // 重置数据
|
|
|
|
|
- piStatus.setPunchInCountInWeek(0);
|
|
|
|
|
- piStatus.setPunchInDoneCountInWeek(0);
|
|
|
|
|
- piStatus.setRepeatPrevTotalCountInWeek(0);
|
|
|
|
|
- piStatus.setRepeatStartDateInWeek(punchInDate);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // 打卡日所在月的第一天
|
|
|
|
|
- if (isFirstDayOfMonth) {
|
|
|
|
|
- piStatus.setStatTimeInMonth(yearMonth);
|
|
|
|
|
-
|
|
|
|
|
- // 设置本月总打卡次数
|
|
|
|
|
- int PunchInTotalCountInMonth = punchInManager.getPunchInTotalCountInRange(piTask.getRepeatCategory(),
|
|
|
|
|
- piTask.getRepeatCustomDay(), DateUtils.getFirstDayOfMonth(punchInDate),
|
|
|
|
|
- DateUtils.getLastDayOfMonth(punchInDate));
|
|
|
|
|
- piStatus.setPunchInTotalCountInMonth(PunchInTotalCountInMonth);
|
|
|
|
|
-
|
|
|
|
|
- // 重置数据
|
|
|
|
|
- piStatus.setPunchInCountInMonth(0);
|
|
|
|
|
- piStatus.setPunchInDoneCountInMonth(0);
|
|
|
|
|
- piStatus.setRepeatPrevTotalCountInMonth(0);
|
|
|
|
|
- piStatus.setRepeatStartDateInMonth(punchInDate);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // 重复类型发生变换,总打卡次数=历史真实发生的总打卡次数+变换前发生的总打卡次数+变换后可能的总打卡次数
|
|
|
|
|
- if (!piStatus.getRepeatCategory().equals(piTask.getRepeatCategory())) {
|
|
|
|
|
- // 历史真实发生的总打卡次数(周)
|
|
|
|
|
- Integer oldPrevTotalCountInWeek = Optional.ofNullable(piStatus.getRepeatPrevTotalCountInWeek()).orElse(0);
|
|
|
|
|
- // 变换前发生的总打卡次数(周)
|
|
|
|
|
- int prevTotalCountInWeek = punchInManager.getPunchInTotalCountInRange(piStatus.getRepeatCategory(),
|
|
|
|
|
- piStatus.getRepeatCustomDay(), piStatus.getRepeatStartDateInWeek(),
|
|
|
|
|
- punchInDate.minusDays(1));
|
|
|
|
|
- // 变换后可能的总打卡次数(周)
|
|
|
|
|
- int punchInTotalCountInWeek = punchInManager.getPunchInTotalCountInRange(piTask.getRepeatCategory(), piTask.getRepeatCustomDay(), punchInDate, DateUtils.getLastDayOfWeek(punchInDate));
|
|
|
|
|
-
|
|
|
|
|
- // 历史真实发生的总打卡次数(月)
|
|
|
|
|
- Integer oldPrevTotalCountInMonth = Optional.ofNullable(piStatus.getRepeatPrevTotalCountInMonth()).orElse(0);
|
|
|
|
|
- // 变换前发生的总打卡次数(月)
|
|
|
|
|
- int prevTotalCountInMonth = punchInManager.getPunchInTotalCountInRange(piStatus.getRepeatCategory(),
|
|
|
|
|
- piStatus.getRepeatCustomDay(), piStatus.getRepeatStartDateInMonth(),
|
|
|
|
|
- punchInDate.minusDays(1));
|
|
|
|
|
- // 变换后可能的总打卡次数(月 )
|
|
|
|
|
- int punchInTotalCountInMonth = punchInManager.getPunchInTotalCountInRange(piTask.getRepeatCategory(), piTask.getRepeatCustomDay(), punchInDate, DateUtils.getLastDayOfMonth(punchInDate));
|
|
|
|
|
-
|
|
|
|
|
- // 设置实时数据
|
|
|
|
|
- piStatus.setRepeatPrevTotalCountInWeek(prevTotalCountInWeek + oldPrevTotalCountInWeek);
|
|
|
|
|
- piStatus.setPunchInTotalCountInWeek(piStatus.getRepeatPrevTotalCountInWeek() + punchInTotalCountInWeek);
|
|
|
|
|
- piStatus.setRepeatPrevTotalCountInMonth(prevTotalCountInMonth + oldPrevTotalCountInMonth);
|
|
|
|
|
- piStatus.setPunchInTotalCountInMonth(piStatus.getRepeatPrevTotalCountInMonth() + punchInTotalCountInMonth);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // 存在打卡记录则已打卡数加1
|
|
|
|
|
- if (Objects.nonNull(piTaskHistory)) {
|
|
|
|
|
- piStatus.setPunchInCountInWeek(piStatus.getPunchInCountInWeek() + 1);
|
|
|
|
|
- piStatus.setPunchInCountInMonth(piStatus.getPunchInCountInMonth() + 1);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // 完成打卡则完成打卡数记录加一
|
|
|
|
|
- if (PunchInResultEnum.DONE.equals(punchInResult)) {
|
|
|
|
|
- piStatus.setPunchInDoneCountInWeek(piStatus.getPunchInDoneCountInWeek() + 1);
|
|
|
|
|
- piStatus.setPunchInDoneCountInMonth(piStatus.getPunchInDoneCountInMonth() + 1);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // 计算积分
|
|
|
|
|
|
|
+ // 计算积分,要先刷新打卡状态
|
|
|
int taskPoints = settleManager.calculatePointsInTask(piTask, piTaskExtList, piTaskHistory, piStatus);
|
|
int taskPoints = settleManager.calculatePointsInTask(piTask, piTaskExtList, piTaskHistory, piStatus);
|
|
|
|
|
+ settlePoints += taskPoints;
|
|
|
|
|
+
|
|
|
|
|
+ // 更新打卡状态
|
|
|
piStatus.setPointsInWeek(piStatus.getPointsInWeek() + taskPoints);
|
|
piStatus.setPointsInWeek(piStatus.getPointsInWeek() + taskPoints);
|
|
|
piStatus.setPointsInMonth(piStatus.getPointsInMonth() + taskPoints);
|
|
piStatus.setPointsInMonth(piStatus.getPointsInMonth() + taskPoints);
|
|
|
- settlePoints += taskPoints;
|
|
|
|
|
|
|
|
|
|
// 打卡记录 更新
|
|
// 打卡记录 更新
|
|
|
updatePiTaskHistory.setSettlePoints(taskPoints);
|
|
updatePiTaskHistory.setSettlePoints(taskPoints);
|
|
@@ -338,61 +248,16 @@ public class PunchInSettleManagerImpl implements IPunchInSettleManager {
|
|
|
|
|
|
|
|
updatePiStatusList.add(piStatus);
|
|
updatePiStatusList.add(piStatus);
|
|
|
updatePunchInTaskHistories.add(updatePiTaskHistory);
|
|
updatePunchInTaskHistories.add(updatePiTaskHistory);
|
|
|
|
|
+
|
|
|
|
|
+ // 周日构建周统计数据
|
|
|
if (isSunday) {
|
|
if (isSunday) {
|
|
|
- StatPiTaskWeek statPiTaskWeek = new StatPiTaskWeek();
|
|
|
|
|
- statPiTaskWeek.setUserId(punchInSettle.getUserId());
|
|
|
|
|
- statPiTaskWeek.setTaskUniqueId(piTask.getUniqueId());
|
|
|
|
|
- statPiTaskWeek.setStatTime(piStatus.getStatTimeInWeek());
|
|
|
|
|
- statPiTaskWeek.setPunchInTotalCount(piStatus.getPunchInTotalCountInWeek());
|
|
|
|
|
- statPiTaskWeek.setPunchInCount(piStatus.getPunchInCountInWeek());
|
|
|
|
|
- statPiTaskWeek.setPunchInDoneCount(piStatus.getPunchInDoneCountInWeek());
|
|
|
|
|
- statPiTaskWeek.setPoints(piStatus.getPointsInWeek());
|
|
|
|
|
-
|
|
|
|
|
- Integer punchInTotalCount = Optional.ofNullable(piStatus.getPunchInTotalCountInWeek()).orElse(0);
|
|
|
|
|
- if (punchInTotalCount == 0) {
|
|
|
|
|
- statPiTaskWeek.setPunchInRate(ZERO_RATE);
|
|
|
|
|
- statPiTaskWeek.setPunchInDoneRate(ZERO_RATE);
|
|
|
|
|
- } else {
|
|
|
|
|
- Integer punchInCount = Optional.ofNullable(piStatus.getPunchInCountInWeek()).orElse(0);
|
|
|
|
|
- Integer punchInDoneCount = Optional.ofNullable(piStatus.getPunchInDoneCountInWeek()).orElse(0);
|
|
|
|
|
- BigDecimal totalCount = new BigDecimal(punchInTotalCount);
|
|
|
|
|
-
|
|
|
|
|
- BigDecimal punchInRate = BigDecimal.valueOf(punchInCount).divide(totalCount, 2, RoundingMode.HALF_UP).multiply(ONE_HUNDRED);
|
|
|
|
|
- statPiTaskWeek.setPunchInRate(punchInRate);
|
|
|
|
|
-
|
|
|
|
|
- BigDecimal punchInDoneRate = BigDecimal.valueOf(punchInDoneCount).divide(totalCount, 2, RoundingMode.HALF_UP).multiply(ONE_HUNDRED);
|
|
|
|
|
- statPiTaskWeek.setPunchInDoneRate(punchInDoneRate);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
|
|
+ StatPiTaskWeek statPiTaskWeek = buildStatPiTaskWeek(punchInSettle.getUserId(), piTask, piStatus);
|
|
|
addStatPiTaskWeekList.add(statPiTaskWeek);
|
|
addStatPiTaskWeekList.add(statPiTaskWeek);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ // 月末构建月统计数据
|
|
|
if (isLastDayOfMonth) {
|
|
if (isLastDayOfMonth) {
|
|
|
- StatPiTaskMonth statPiTaskMonth = new StatPiTaskMonth();
|
|
|
|
|
- statPiTaskMonth.setUserId(punchInSettle.getUserId());
|
|
|
|
|
- statPiTaskMonth.setTaskUniqueId(piTask.getUniqueId());
|
|
|
|
|
- statPiTaskMonth.setStatTime(piStatus.getStatTimeInMonth());
|
|
|
|
|
- statPiTaskMonth.setPunchInTotalCount(piStatus.getPunchInTotalCountInMonth());
|
|
|
|
|
- statPiTaskMonth.setPunchInCount(piStatus.getPunchInCountInMonth());
|
|
|
|
|
- statPiTaskMonth.setPunchInDoneCount(piStatus.getPunchInDoneCountInMonth());
|
|
|
|
|
- statPiTaskMonth.setPoints(piStatus.getPointsInMonth());
|
|
|
|
|
-
|
|
|
|
|
- Integer punchInTotalCount = Optional.ofNullable(piStatus.getPunchInTotalCountInMonth()).orElse(0);
|
|
|
|
|
- if (punchInTotalCount == 0) {
|
|
|
|
|
- statPiTaskMonth.setPunchInRate(ZERO_RATE);
|
|
|
|
|
- statPiTaskMonth.setPunchInDoneRate(ZERO_RATE);
|
|
|
|
|
- } else {
|
|
|
|
|
- Integer punchInCount = Optional.ofNullable(piStatus.getPunchInCountInMonth()).orElse(0);
|
|
|
|
|
- Integer punchInDoneCount = Optional.ofNullable(piStatus.getPunchInDoneCountInMonth()).orElse(0);
|
|
|
|
|
- BigDecimal totalCount = new BigDecimal(punchInTotalCount);
|
|
|
|
|
-
|
|
|
|
|
- BigDecimal punchInRate = BigDecimal.valueOf(punchInCount).divide(totalCount, 2, RoundingMode.HALF_UP).multiply(ONE_HUNDRED);
|
|
|
|
|
- statPiTaskMonth.setPunchInRate(punchInRate);
|
|
|
|
|
-
|
|
|
|
|
- BigDecimal punchInDoneRate = BigDecimal.valueOf(punchInDoneCount).divide(totalCount, 2, RoundingMode.HALF_UP).multiply(ONE_HUNDRED);
|
|
|
|
|
- statPiTaskMonth.setPunchInDoneRate(punchInDoneRate);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
|
|
+ StatPiTaskMonth statPiTaskMonth = buildStatPiTaskMonth(punchInSettle.getUserId(), piTask, piStatus);
|
|
|
addStatPiTaskMonthList.add(statPiTaskMonth);
|
|
addStatPiTaskMonthList.add(statPiTaskMonth);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -417,42 +282,60 @@ public class PunchInSettleManagerImpl implements IPunchInSettleManager {
|
|
|
piMultiTaskHistory.setPunchInResult(punchInResult);
|
|
piMultiTaskHistory.setPunchInResult(punchInResult);
|
|
|
updatePiMultiTaskHistory.setPunchInResult(punchInResult);
|
|
updatePiMultiTaskHistory.setPunchInResult(punchInResult);
|
|
|
|
|
|
|
|
- // 设置统计时间
|
|
|
|
|
|
|
+ // 设置多任务统计时间
|
|
|
piStatusInMultiTask.setStatusDate(punchInDateStr);
|
|
piStatusInMultiTask.setStatusDate(punchInDateStr);
|
|
|
- // 设置任务连续状态
|
|
|
|
|
|
|
+ // 设置多任务连续状态
|
|
|
ContinueStatusEnum oldTaskContinueStatus = piStatusInMultiTask.getTaskContinueStatus();
|
|
ContinueStatusEnum oldTaskContinueStatus = piStatusInMultiTask.getTaskContinueStatus();
|
|
|
piStatusInMultiTask.setTaskContinueStatus(punchInResult.equals(PunchInResultEnum.DONE)
|
|
piStatusInMultiTask.setTaskContinueStatus(punchInResult.equals(PunchInResultEnum.DONE)
|
|
|
? ContinueStatusEnum.CONTINUE : ContinueStatusEnum.INTERRUPTED);
|
|
? ContinueStatusEnum.CONTINUE : ContinueStatusEnum.INTERRUPTED);
|
|
|
piStatusInMultiTask.setTaskContinueDay(oldTaskContinueStatus.equals(piStatusInMultiTask.getTaskContinueStatus())
|
|
piStatusInMultiTask.setTaskContinueDay(oldTaskContinueStatus.equals(piStatusInMultiTask.getTaskContinueStatus())
|
|
|
? piStatusInMultiTask.getTaskContinueDay() + 1 : 1);
|
|
? piStatusInMultiTask.getTaskContinueDay() + 1 : 1);
|
|
|
|
|
|
|
|
|
|
+ // 计算多任务积分
|
|
|
int multiTaskPoints = settleManager.calculatePointsInMultiTask(piMultiTask,
|
|
int multiTaskPoints = settleManager.calculatePointsInMultiTask(piMultiTask,
|
|
|
punchInSettle.getPiMultiTaskExtList(), piMultiTaskHistory,
|
|
punchInSettle.getPiMultiTaskExtList(), piMultiTaskHistory,
|
|
|
punchInSettle.getPiStatus());
|
|
punchInSettle.getPiStatus());
|
|
|
settlePoints += multiTaskPoints;
|
|
settlePoints += multiTaskPoints;
|
|
|
|
|
|
|
|
|
|
+ // 设置打卡记录表信息
|
|
|
updatePiMultiTaskHistory.setSettlePoints(multiTaskPoints);
|
|
updatePiMultiTaskHistory.setSettlePoints(multiTaskPoints);
|
|
|
updatePiMultiTaskHistory.setSettleResult(SettleResultEnum.SETTLED);
|
|
updatePiMultiTaskHistory.setSettleResult(SettleResultEnum.SETTLED);
|
|
|
updatePiMultiTaskHistory.setSettleTaskHistoryId(settleTaskHistoryId);
|
|
updatePiMultiTaskHistory.setSettleTaskHistoryId(settleTaskHistoryId);
|
|
|
updatePunchInMultiTaskHistories.add(updatePiMultiTaskHistory);
|
|
updatePunchInMultiTaskHistories.add(updatePiMultiTaskHistory);
|
|
|
|
|
|
|
|
|
|
+ // 获取并设置用户信息
|
|
|
User user = punchInSettle.getUser();
|
|
User user = punchInSettle.getUser();
|
|
|
- Integer totalPoints = Optional.ofNullable(user.getTotalPoints()).orElse(0);
|
|
|
|
|
- Integer unusedPoints = Optional.ofNullable(user.getUnusedPoints()).orElse(0);
|
|
|
|
|
-
|
|
|
|
|
|
|
+ Integer beforeTotalPoints = Optional.ofNullable(user.getTotalPoints()).orElse(0);
|
|
|
|
|
+ Integer beforeUnusedPoints = Optional.ofNullable(user.getUnusedPoints()).orElse(0);
|
|
|
User updateUser = new User();
|
|
User updateUser = new User();
|
|
|
updateUser.setId(user.getId());
|
|
updateUser.setId(user.getId());
|
|
|
- updateUser.setTotalPoints(totalPoints);
|
|
|
|
|
- updateUser.setUnusedPoints(unusedPoints + settlePoints);
|
|
|
|
|
|
|
+ updateUser.setTotalPoints(beforeTotalPoints + settlePoints);
|
|
|
|
|
+ updateUser.setUnusedPoints(beforeUnusedPoints + settlePoints);
|
|
|
updateUserList.add(user);
|
|
updateUserList.add(user);
|
|
|
|
|
|
|
|
|
|
+ // 更新账户信息
|
|
|
|
|
+ Account account = punchInSettle.getAccount();
|
|
|
|
|
+ Integer beforeAccountPoints = Optional.ofNullable(account.getPoints()).orElse(0);
|
|
|
|
|
+ account.setPoints(beforeAccountPoints + settlePoints);
|
|
|
|
|
+ updateAccountList.add(account);
|
|
|
|
|
+
|
|
|
|
|
+ // 增加账户转账记录
|
|
|
|
|
+ AccountTransferHistory accountTransferHistory = new AccountTransferHistory();
|
|
|
|
|
+ accountTransferHistory.setTransferPoints(settlePoints);
|
|
|
|
|
+ accountTransferHistory.setTransferCategory(TransferCategoryEnum.SETTLE);
|
|
|
|
|
+ accountTransferHistory.setRecipientAccountId(account.getId());
|
|
|
|
|
+ accountTransferHistory.setRaPointsAfterTransfer(beforeAccountPoints);
|
|
|
|
|
+ accountTransferHistory.setRaPointsAfterTransfer(account.getPoints());
|
|
|
|
|
+ addAccountTransferHistories.add(accountTransferHistory);
|
|
|
|
|
+
|
|
|
|
|
+ // 设置结算积分记录
|
|
|
SettlePointsHistory addSettlePointsHistory = new SettlePointsHistory();
|
|
SettlePointsHistory addSettlePointsHistory = new SettlePointsHistory();
|
|
|
addSettlePointsHistory.setSettleTaskHistoryId(settleTaskHistoryId);
|
|
addSettlePointsHistory.setSettleTaskHistoryId(settleTaskHistoryId);
|
|
|
addSettlePointsHistory.setUserId(user.getId());
|
|
addSettlePointsHistory.setUserId(user.getId());
|
|
|
addSettlePointsHistory.setSettleDate(punchInDateStr);
|
|
addSettlePointsHistory.setSettleDate(punchInDateStr);
|
|
|
addSettlePointsHistory.setSettlePoints(settlePoints);
|
|
addSettlePointsHistory.setSettlePoints(settlePoints);
|
|
|
- addSettlePointsHistory.setBeforeSettlePoints(totalPoints);
|
|
|
|
|
- addSettlePointsHistory.setAfterSettlePoints(totalPoints + settlePoints);
|
|
|
|
|
|
|
+ addSettlePointsHistory.setBeforeSettlePoints(beforeTotalPoints);
|
|
|
|
|
+ addSettlePointsHistory.setAfterSettlePoints(beforeTotalPoints + settlePoints);
|
|
|
addSettlePointsHistories.add(addSettlePointsHistory);
|
|
addSettlePointsHistories.add(addSettlePointsHistory);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -481,6 +364,12 @@ public class PunchInSettleManagerImpl implements IPunchInSettleManager {
|
|
|
if (!CollectionUtils.isEmpty(updatePunchInMultiTaskHistories)) {
|
|
if (!CollectionUtils.isEmpty(updatePunchInMultiTaskHistories)) {
|
|
|
piMultiTaskHistoryService.batchUpdate(updatePunchInMultiTaskHistories);
|
|
piMultiTaskHistoryService.batchUpdate(updatePunchInMultiTaskHistories);
|
|
|
}
|
|
}
|
|
|
|
|
+ if (!CollectionUtils.isEmpty(updateAccountList)) {
|
|
|
|
|
+ accountService.batchUpdate(updateAccountList);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!CollectionUtils.isEmpty(addAccountTransferHistories)) {
|
|
|
|
|
+ accountTransferHistoryService.batchInsert(addAccountTransferHistories);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -495,6 +384,13 @@ public class PunchInSettleManagerImpl implements IPunchInSettleManager {
|
|
|
List<User> users = userService.listByIds(userIds);
|
|
List<User> users = userService.listByIds(userIds);
|
|
|
Map<Long, User> userMap = users.stream().collect(Collectors.toMap(User::getId, Function.identity(), (key1, key2) -> key1));
|
|
Map<Long, User> userMap = users.stream().collect(Collectors.toMap(User::getId, Function.identity(), (key1, key2) -> key1));
|
|
|
|
|
|
|
|
|
|
+ // 获取账户信息,用户ID-账户信息关联
|
|
|
|
|
+ AccountQuery accountQuery = new AccountQuery();
|
|
|
|
|
+ accountQuery.setAccountCategory(AccountCategoryEnum.BASIC);
|
|
|
|
|
+ accountQuery.setUserIds(userIds);
|
|
|
|
|
+ List<Account> accounts = accountService.getAccountByCondition(accountQuery);
|
|
|
|
|
+ Map<Long, Account> accountMap = accounts.stream().collect(Collectors.toMap(Account::getUserId, Function.identity(), (key1, key2) -> key1));
|
|
|
|
|
+
|
|
|
// 获取多任务信息,用户ID-多任务关联
|
|
// 获取多任务信息,用户ID-多任务关联
|
|
|
PiMultiTaskQuery piMultiTaskQuery = new PiMultiTaskQuery();
|
|
PiMultiTaskQuery piMultiTaskQuery = new PiMultiTaskQuery();
|
|
|
piMultiTaskQuery.setMultiTaskTaskStatus(ArchiveStatusEnum.ACTIVE);
|
|
piMultiTaskQuery.setMultiTaskTaskStatus(ArchiveStatusEnum.ACTIVE);
|
|
@@ -575,6 +471,10 @@ public class PunchInSettleManagerImpl implements IPunchInSettleManager {
|
|
|
User user = userMap.get(userId);
|
|
User user = userMap.get(userId);
|
|
|
punchInSettleData.setUser(user);
|
|
punchInSettleData.setUser(user);
|
|
|
|
|
|
|
|
|
|
+ // 获取并设置账户信息
|
|
|
|
|
+ Account account = accountMap.get(userId);
|
|
|
|
|
+ punchInSettleData.setAccount(account);
|
|
|
|
|
+
|
|
|
// TODO 获取并设置多任务打卡信息,这个不可能为空,为空则用户初始注册时创建时有问题
|
|
// TODO 获取并设置多任务打卡信息,这个不可能为空,为空则用户初始注册时创建时有问题
|
|
|
PiMultiTask piMultiTask = piMultiTaskMap.get(userId);
|
|
PiMultiTask piMultiTask = piMultiTaskMap.get(userId);
|
|
|
punchInSettleData.setPiMultiTask(piMultiTask);
|
|
punchInSettleData.setPiMultiTask(piMultiTask);
|
|
@@ -633,4 +533,200 @@ public class PunchInSettleManagerImpl implements IPunchInSettleManager {
|
|
|
return punchInSettleData;
|
|
return punchInSettleData;
|
|
|
}).collect(Collectors.toList());
|
|
}).collect(Collectors.toList());
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 更新打卡任务状态
|
|
|
|
|
+ * @param piStatus 打卡任务状态
|
|
|
|
|
+ * @param punchInResult 打卡结果
|
|
|
|
|
+ * @param piTask 打卡任务
|
|
|
|
|
+ * @param piTaskHistory 打卡任务记录
|
|
|
|
|
+ * @param punchInDate 打卡日期
|
|
|
|
|
+ * @param isMonday 是否周一
|
|
|
|
|
+ * @param isFirstDayOfMonth 是否本月第一天
|
|
|
|
|
+ * @param yearWeek 周数
|
|
|
|
|
+ * @param yearMonth 月份数
|
|
|
|
|
+ */
|
|
|
|
|
+ private void refreshPiStatus(PiStatus piStatus, PunchInResultEnum punchInResult, PiTask piTask, PiTaskHistory piTaskHistory, LocalDate punchInDate, boolean isMonday, boolean isFirstDayOfMonth, String yearWeek, String yearMonth) {
|
|
|
|
|
+ // 设置任务连续状态
|
|
|
|
|
+ ContinueStatusEnum oldTaskContinueStatus = piStatus.getTaskContinueStatus();
|
|
|
|
|
+ piStatus.setTaskContinueStatus(punchInResult.equals(PunchInResultEnum.DONE)
|
|
|
|
|
+ ? ContinueStatusEnum.CONTINUE : ContinueStatusEnum.INTERRUPTED);
|
|
|
|
|
+ piStatus.setTaskContinueDay(oldTaskContinueStatus.equals(piStatus.getTaskContinueStatus())
|
|
|
|
|
+ ? piStatus.getTaskContinueDay() + 1 : 1);
|
|
|
|
|
+
|
|
|
|
|
+ // 旧的连续阶段
|
|
|
|
|
+ ContinueStageEnum oldContinueStage = piStatus.getContinueStage();
|
|
|
|
|
+ // 判断当前处于的连续阶段
|
|
|
|
|
+ ContinueStageEnum continueStageResult =
|
|
|
|
|
+ punchInManager.judgeContinueStageInTask(piTask, piTaskHistory, piStatus, punchInDate);
|
|
|
|
|
+ piStatus.setContinueStage(continueStageResult);
|
|
|
|
|
+ // 下面3种情况不处理:宽限期 变 宽限期;正常打卡期 变 正常打卡期;惩罚期 变 惩罚期;
|
|
|
|
|
+ // 宽限期 变 正常打卡期,则设置阶段开始时间,重置中断次数
|
|
|
|
|
+ if (ContinueStageEnum.GRACE_STAGE.equals(oldContinueStage)
|
|
|
|
|
+ && ContinueStageEnum.NORMAL_STAGE.equals(continueStageResult)) {
|
|
|
|
|
+ piStatus.setStageStartDate(punchInDate);
|
|
|
|
|
+ piStatus.setContinueInterruptedCount(0);
|
|
|
|
|
+ }
|
|
|
|
|
+ // 如果正常打卡期 变 惩罚期,则设置阶段开始时间和阶段结束时间,增加中断次数
|
|
|
|
|
+ if (ContinueStageEnum.NORMAL_STAGE.equals(oldContinueStage)
|
|
|
|
|
+ && ContinueStageEnum.PENALTY_STAGE.equals(continueStageResult)) {
|
|
|
|
|
+ piStatus.setStageStartDate(punchInDate);
|
|
|
|
|
+ piStatus.setStageEndDate(punchInDate.plusDays(piTask.getPenaltyDay()));
|
|
|
|
|
+ piStatus.setContinueInterruptedCount(piStatus.getContinueInterruptedCount() + 1);
|
|
|
|
|
+ }
|
|
|
|
|
+ // 如果惩罚期 变 正常打卡期,则设置阶段开始时间
|
|
|
|
|
+ if (ContinueStageEnum.PENALTY_STAGE.equals(oldContinueStage)
|
|
|
|
|
+ && ContinueStageEnum.NORMAL_STAGE.equals(continueStageResult)) {
|
|
|
|
|
+ piStatus.setStageStartDate(punchInDate);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 周一或月初
|
|
|
|
|
+ if (isMonday || isFirstDayOfMonth) {
|
|
|
|
|
+ piStatus.setRepeatCategory(piTask.getRepeatCategory());
|
|
|
|
|
+ piStatus.setRepeatCustomDay(piTask.getRepeatCustomDay());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 周一
|
|
|
|
|
+ if (isMonday) {
|
|
|
|
|
+ piStatus.setStatTimeInWeek(yearWeek);
|
|
|
|
|
+
|
|
|
|
|
+ // 设置本周总打卡次数
|
|
|
|
|
+ int PunchInTotalCountInWeek = punchInManager.getPunchInTotalCountInRange(piTask.getRepeatCategory(),
|
|
|
|
|
+ piTask.getRepeatCustomDay(), DateUtils.getFirstDayOfWeek(punchInDate),
|
|
|
|
|
+ DateUtils.getLastDayOfWeek(punchInDate));
|
|
|
|
|
+ piStatus.setPunchInTotalCountInWeek(PunchInTotalCountInWeek);
|
|
|
|
|
+
|
|
|
|
|
+ // 重置数据
|
|
|
|
|
+ piStatus.setPunchInCountInWeek(0);
|
|
|
|
|
+ piStatus.setPunchInDoneCountInWeek(0);
|
|
|
|
|
+ piStatus.setRepeatPrevTotalCountInWeek(0);
|
|
|
|
|
+ piStatus.setRepeatStartDateInWeek(punchInDate);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 打卡日所在月的第一天
|
|
|
|
|
+ if (isFirstDayOfMonth) {
|
|
|
|
|
+ piStatus.setStatTimeInMonth(yearMonth);
|
|
|
|
|
+
|
|
|
|
|
+ // 设置本月总打卡次数
|
|
|
|
|
+ int PunchInTotalCountInMonth = punchInManager.getPunchInTotalCountInRange(piTask.getRepeatCategory(),
|
|
|
|
|
+ piTask.getRepeatCustomDay(), DateUtils.getFirstDayOfMonth(punchInDate),
|
|
|
|
|
+ DateUtils.getLastDayOfMonth(punchInDate));
|
|
|
|
|
+ piStatus.setPunchInTotalCountInMonth(PunchInTotalCountInMonth);
|
|
|
|
|
+
|
|
|
|
|
+ // 重置数据
|
|
|
|
|
+ piStatus.setPunchInCountInMonth(0);
|
|
|
|
|
+ piStatus.setPunchInDoneCountInMonth(0);
|
|
|
|
|
+ piStatus.setRepeatPrevTotalCountInMonth(0);
|
|
|
|
|
+ piStatus.setRepeatStartDateInMonth(punchInDate);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 重复类型发生变换,总打卡次数=历史真实发生的总打卡次数+变换前发生的总打卡次数+变换后可能的总打卡次数
|
|
|
|
|
+ if (!piStatus.getRepeatCategory().equals(piTask.getRepeatCategory())) {
|
|
|
|
|
+ // 历史真实发生的总打卡次数(周)
|
|
|
|
|
+ Integer oldPrevTotalCountInWeek = Optional.ofNullable(piStatus.getRepeatPrevTotalCountInWeek()).orElse(0);
|
|
|
|
|
+ // 变换前发生的总打卡次数(周)
|
|
|
|
|
+ int prevTotalCountInWeek = punchInManager.getPunchInTotalCountInRange(piStatus.getRepeatCategory(),
|
|
|
|
|
+ piStatus.getRepeatCustomDay(), piStatus.getRepeatStartDateInWeek(),
|
|
|
|
|
+ punchInDate.minusDays(1));
|
|
|
|
|
+ // 变换后可能的总打卡次数(周)
|
|
|
|
|
+ int punchInTotalCountInWeek = punchInManager.getPunchInTotalCountInRange(piTask.getRepeatCategory(), piTask.getRepeatCustomDay(), punchInDate, DateUtils.getLastDayOfWeek(punchInDate));
|
|
|
|
|
+
|
|
|
|
|
+ // 历史真实发生的总打卡次数(月)
|
|
|
|
|
+ Integer oldPrevTotalCountInMonth = Optional.ofNullable(piStatus.getRepeatPrevTotalCountInMonth()).orElse(0);
|
|
|
|
|
+ // 变换前发生的总打卡次数(月)
|
|
|
|
|
+ int prevTotalCountInMonth = punchInManager.getPunchInTotalCountInRange(piStatus.getRepeatCategory(),
|
|
|
|
|
+ piStatus.getRepeatCustomDay(), piStatus.getRepeatStartDateInMonth(),
|
|
|
|
|
+ punchInDate.minusDays(1));
|
|
|
|
|
+ // 变换后可能的总打卡次数(月 )
|
|
|
|
|
+ int punchInTotalCountInMonth = punchInManager.getPunchInTotalCountInRange(piTask.getRepeatCategory(), piTask.getRepeatCustomDay(), punchInDate, DateUtils.getLastDayOfMonth(punchInDate));
|
|
|
|
|
+
|
|
|
|
|
+ // 设置实时数据
|
|
|
|
|
+ piStatus.setRepeatPrevTotalCountInWeek(prevTotalCountInWeek + oldPrevTotalCountInWeek);
|
|
|
|
|
+ piStatus.setPunchInTotalCountInWeek(piStatus.getRepeatPrevTotalCountInWeek() + punchInTotalCountInWeek);
|
|
|
|
|
+ piStatus.setRepeatPrevTotalCountInMonth(prevTotalCountInMonth + oldPrevTotalCountInMonth);
|
|
|
|
|
+ piStatus.setPunchInTotalCountInMonth(piStatus.getRepeatPrevTotalCountInMonth() + punchInTotalCountInMonth);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 存在打卡记录则已打卡数加1
|
|
|
|
|
+ if (Objects.nonNull(piTaskHistory)) {
|
|
|
|
|
+ piStatus.setPunchInCountInWeek(piStatus.getPunchInCountInWeek() + 1);
|
|
|
|
|
+ piStatus.setPunchInCountInMonth(piStatus.getPunchInCountInMonth() + 1);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 完成打卡则完成打卡数记录加一
|
|
|
|
|
+ if (PunchInResultEnum.DONE.equals(punchInResult)) {
|
|
|
|
|
+ piStatus.setPunchInDoneCountInWeek(piStatus.getPunchInDoneCountInWeek() + 1);
|
|
|
|
|
+ piStatus.setPunchInDoneCountInMonth(piStatus.getPunchInDoneCountInMonth() + 1);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 构建周统计数据
|
|
|
|
|
+ * @param userId 用户ID
|
|
|
|
|
+ * @param piTask 打卡任务
|
|
|
|
|
+ * @param piStatus 打卡任务状态
|
|
|
|
|
+ * @return
|
|
|
|
|
+ */
|
|
|
|
|
+ private static StatPiTaskWeek buildStatPiTaskWeek(Long userId, PiTask piTask, PiStatus piStatus) {
|
|
|
|
|
+ StatPiTaskWeek statPiTaskWeek = new StatPiTaskWeek();
|
|
|
|
|
+ statPiTaskWeek.setUserId(userId);
|
|
|
|
|
+ statPiTaskWeek.setTaskUniqueId(piTask.getUniqueId());
|
|
|
|
|
+ statPiTaskWeek.setStatTime(piStatus.getStatTimeInWeek());
|
|
|
|
|
+ statPiTaskWeek.setPunchInTotalCount(piStatus.getPunchInTotalCountInWeek());
|
|
|
|
|
+ statPiTaskWeek.setPunchInCount(piStatus.getPunchInCountInWeek());
|
|
|
|
|
+ statPiTaskWeek.setPunchInDoneCount(piStatus.getPunchInDoneCountInWeek());
|
|
|
|
|
+ statPiTaskWeek.setPoints(piStatus.getPointsInWeek());
|
|
|
|
|
+
|
|
|
|
|
+ Integer punchInTotalCount = Optional.ofNullable(piStatus.getPunchInTotalCountInWeek()).orElse(0);
|
|
|
|
|
+ if (punchInTotalCount == 0) {
|
|
|
|
|
+ statPiTaskWeek.setPunchInRate(ZERO_RATE);
|
|
|
|
|
+ statPiTaskWeek.setPunchInDoneRate(ZERO_RATE);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ Integer punchInCount = Optional.ofNullable(piStatus.getPunchInCountInWeek()).orElse(0);
|
|
|
|
|
+ Integer punchInDoneCount = Optional.ofNullable(piStatus.getPunchInDoneCountInWeek()).orElse(0);
|
|
|
|
|
+ BigDecimal totalCount = new BigDecimal(punchInTotalCount);
|
|
|
|
|
+
|
|
|
|
|
+ BigDecimal punchInRate = BigDecimal.valueOf(punchInCount).divide(totalCount, 2, RoundingMode.HALF_UP).multiply(ONE_HUNDRED);
|
|
|
|
|
+ statPiTaskWeek.setPunchInRate(punchInRate);
|
|
|
|
|
+
|
|
|
|
|
+ BigDecimal punchInDoneRate = BigDecimal.valueOf(punchInDoneCount).divide(totalCount, 2, RoundingMode.HALF_UP).multiply(ONE_HUNDRED);
|
|
|
|
|
+ statPiTaskWeek.setPunchInDoneRate(punchInDoneRate);
|
|
|
|
|
+ }
|
|
|
|
|
+ return statPiTaskWeek;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 构建月统计数据
|
|
|
|
|
+ * @param userId 用户ID
|
|
|
|
|
+ * @param piTask 打卡任务
|
|
|
|
|
+ * @param piStatus 打卡任务状态
|
|
|
|
|
+ * @return
|
|
|
|
|
+ */
|
|
|
|
|
+ private static StatPiTaskMonth buildStatPiTaskMonth(Long userId, PiTask piTask, PiStatus piStatus) {
|
|
|
|
|
+ StatPiTaskMonth statPiTaskMonth = new StatPiTaskMonth();
|
|
|
|
|
+ statPiTaskMonth.setUserId(userId);
|
|
|
|
|
+ statPiTaskMonth.setTaskUniqueId(piTask.getUniqueId());
|
|
|
|
|
+ statPiTaskMonth.setStatTime(piStatus.getStatTimeInMonth());
|
|
|
|
|
+ statPiTaskMonth.setPunchInTotalCount(piStatus.getPunchInTotalCountInMonth());
|
|
|
|
|
+ statPiTaskMonth.setPunchInCount(piStatus.getPunchInCountInMonth());
|
|
|
|
|
+ statPiTaskMonth.setPunchInDoneCount(piStatus.getPunchInDoneCountInMonth());
|
|
|
|
|
+ statPiTaskMonth.setPoints(piStatus.getPointsInMonth());
|
|
|
|
|
+
|
|
|
|
|
+ Integer punchInTotalCount = Optional.ofNullable(piStatus.getPunchInTotalCountInMonth()).orElse(0);
|
|
|
|
|
+ if (punchInTotalCount == 0) {
|
|
|
|
|
+ statPiTaskMonth.setPunchInRate(ZERO_RATE);
|
|
|
|
|
+ statPiTaskMonth.setPunchInDoneRate(ZERO_RATE);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ Integer punchInCount = Optional.ofNullable(piStatus.getPunchInCountInMonth()).orElse(0);
|
|
|
|
|
+ Integer punchInDoneCount = Optional.ofNullable(piStatus.getPunchInDoneCountInMonth()).orElse(0);
|
|
|
|
|
+ BigDecimal totalCount = new BigDecimal(punchInTotalCount);
|
|
|
|
|
+
|
|
|
|
|
+ BigDecimal punchInRate = BigDecimal.valueOf(punchInCount).divide(totalCount, 2, RoundingMode.HALF_UP).multiply(ONE_HUNDRED);
|
|
|
|
|
+ statPiTaskMonth.setPunchInRate(punchInRate);
|
|
|
|
|
+
|
|
|
|
|
+ BigDecimal punchInDoneRate = BigDecimal.valueOf(punchInDoneCount).divide(totalCount, 2, RoundingMode.HALF_UP).multiply(ONE_HUNDRED);
|
|
|
|
|
+ statPiTaskMonth.setPunchInDoneRate(punchInDoneRate);
|
|
|
|
|
+ }
|
|
|
|
|
+ return statPiTaskMonth;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|