|
|
@@ -1,9 +1,20 @@
|
|
|
package com.punchsettle.server.service.manager.impl;
|
|
|
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
import java.util.Arrays;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
import java.util.Objects;
|
|
|
import java.util.Optional;
|
|
|
+import java.util.Set;
|
|
|
+import java.util.function.Function;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
import com.punchsettle.server.atomic.entity.Account;
|
|
|
import com.punchsettle.server.atomic.entity.Reward;
|
|
|
@@ -11,27 +22,22 @@ import com.punchsettle.server.atomic.entity.RewardExchangeHistory;
|
|
|
import com.punchsettle.server.atomic.entity.User;
|
|
|
import com.punchsettle.server.atomic.service.IAccountService;
|
|
|
import com.punchsettle.server.atomic.service.IRewardExchangeHistoryService;
|
|
|
+import com.punchsettle.server.atomic.service.IRewardService;
|
|
|
import com.punchsettle.server.atomic.service.IUserService;
|
|
|
import com.punchsettle.server.common.constant.CommonEnableStatusEnum;
|
|
|
import com.punchsettle.server.common.exception.BusinessException;
|
|
|
import com.punchsettle.server.common.utils.Assert;
|
|
|
import com.punchsettle.server.constant.RewardExchangeMethodEnum;
|
|
|
import com.punchsettle.server.constant.VersionStatusEnum;
|
|
|
+import com.punchsettle.server.pojo.punchIn.AccountQuery;
|
|
|
+import com.punchsettle.server.pojo.reward.RewardExchangeHistoryVO;
|
|
|
import com.punchsettle.server.pojo.reward.RewardExchangeRequest;
|
|
|
import com.punchsettle.server.pojo.reward.RewardQuery;
|
|
|
import com.punchsettle.server.pojo.reward.RewardRequest;
|
|
|
-import com.punchsettle.server.utiis.UserUtils;
|
|
|
-import org.springframework.beans.BeanUtils;
|
|
|
-import org.springframework.beans.factory.BeanFactoryUtils;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.context.annotation.Bean;
|
|
|
-import org.springframework.stereotype.Service;
|
|
|
-
|
|
|
-import com.punchsettle.server.atomic.service.IRewardService;
|
|
|
import com.punchsettle.server.pojo.reward.RewardVO;
|
|
|
import com.punchsettle.server.service.manager.IRewardManager;
|
|
|
-import org.springframework.transaction.annotation.Transactional;
|
|
|
-import org.springframework.util.CollectionUtils;
|
|
|
+import com.punchsettle.server.utiis.DateUtils;
|
|
|
+import com.punchsettle.server.utiis.UserUtils;
|
|
|
|
|
|
/**
|
|
|
* @author tyuio
|
|
|
@@ -190,11 +196,10 @@ public class RewardManagerImpl implements IRewardManager {
|
|
|
RewardExchangeHistory addRewardExchangeHistory = new RewardExchangeHistory();
|
|
|
addRewardExchangeHistory.setUserId(UserUtils.getCurrentUserId());
|
|
|
addRewardExchangeHistory.setRewardId(reward.getId());
|
|
|
- addRewardExchangeHistory.setExchangeMethod(RewardExchangeMethodEnum.AUTO);
|
|
|
+ addRewardExchangeHistory.setExchangeMethod(RewardExchangeMethodEnum.MANUAL);
|
|
|
addRewardExchangeHistory.setExchangeCount(request.getExchangeCount());
|
|
|
addRewardExchangeHistory.setExchangeTotalPoints(exchangeTotalPoints);
|
|
|
addRewardExchangeHistory.setAccountId(account.getId());
|
|
|
- addRewardExchangeHistory.setAccountName(account.getAccountName());
|
|
|
addRewardExchangeHistory.setAccountPointsBeforeExchange(accountPointsBeforeExchange);
|
|
|
addRewardExchangeHistory.setAccountPointsAfterExchange(accountPointsAfterExchange);
|
|
|
addRewardExchangeHistory.setUnusedPointsBeforeExchange(unusedPointsBeforeExchange);
|
|
|
@@ -214,4 +219,49 @@ public class RewardManagerImpl implements IRewardManager {
|
|
|
updateAccount.setPoints(accountPointsAfterExchange);
|
|
|
accountService.batchUpdate(Arrays.asList(updateAccount));
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<RewardExchangeHistoryVO> queryRewardExchangeHistory(String exchangeMonth) {
|
|
|
+ Assert.isNullInBusiness(exchangeMonth, "兑换月份不能为空");
|
|
|
+
|
|
|
+ List<RewardExchangeHistory> rewardExchangeHistories = rewardExchangeHistoryService.queryRewardExchangeHistory(UserUtils.getCurrentUserId(), exchangeMonth);
|
|
|
+ if (CollectionUtils.isEmpty(rewardExchangeHistories)) {
|
|
|
+ return List.of();
|
|
|
+ }
|
|
|
+
|
|
|
+ // 查询兑换列表
|
|
|
+ Set<Long> rewardIds = rewardExchangeHistories.stream().map(RewardExchangeHistory::getRewardId).collect(Collectors.toSet());
|
|
|
+ RewardQuery rewardQuery = new RewardQuery();
|
|
|
+ rewardQuery.setRewardIds(rewardIds);
|
|
|
+ List<Reward> rewards = rewardService.queryByCondition(rewardQuery);
|
|
|
+ Map<Long, Reward> rewardMap = rewards.stream().collect(Collectors.toMap(Reward::getId, Function.identity(), (key1, key2) -> key1));
|
|
|
+
|
|
|
+ // 查询账户
|
|
|
+ AccountQuery accountQuery = new AccountQuery();
|
|
|
+ accountQuery.setUserIds(Arrays.asList(UserUtils.getCurrentUserId()));
|
|
|
+ List<Account> accounts = accountService.getAccountByCondition(accountQuery);
|
|
|
+ Map<Long, Account> accountMap = accounts.stream().collect(Collectors.toMap(Account::getId, Function.identity(), (key1, key2) -> key1));
|
|
|
+
|
|
|
+ // 日期格式化器,格式:yyyy-MM-dd HH:mm:ss
|
|
|
+ SimpleDateFormat sdf = DateUtils.buildDateTimeFormat();
|
|
|
+
|
|
|
+ return rewardExchangeHistories.stream().map(rewardExchangeHistory -> {
|
|
|
+ RewardExchangeHistoryVO rewardExchangeHistoryVO = new RewardExchangeHistoryVO();
|
|
|
+ BeanUtils.copyProperties(rewardExchangeHistory, rewardExchangeHistoryVO);
|
|
|
+
|
|
|
+ rewardExchangeHistoryVO.setExchangeTime(sdf.format(rewardExchangeHistory.getCreationTime()));
|
|
|
+
|
|
|
+ Reward reward = rewardMap.get(rewardExchangeHistory.getRewardId());
|
|
|
+ if (Objects.nonNull(reward)) {
|
|
|
+ rewardExchangeHistoryVO.setRewardName(reward.getRewardName());
|
|
|
+ }
|
|
|
+
|
|
|
+ Account account = accountMap.get(rewardExchangeHistory.getAccountId());
|
|
|
+ if (Objects.nonNull(account)) {
|
|
|
+ rewardExchangeHistoryVO.setAccountName(account.getAccountName());
|
|
|
+ }
|
|
|
+
|
|
|
+ return rewardExchangeHistoryVO;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ }
|
|
|
}
|