Просмотр исходного кода

【feat】【v3】
1.增加兑换记录查询
2.增加结算积分记录查询

ChenYL 11 месяцев назад
Родитель
Сommit
c46bdd1fc4

+ 1 - 1
src/main/java/com/punchsettle/server/atomic/entity/ItemConsumeWinHistory.java

@@ -19,7 +19,7 @@ import lombok.EqualsAndHashCode;
  */
 @Data
 @EqualsAndHashCode(callSuper = true)
-@Table(name = "lottery_scratch_record")
+@Table(name = "item_consume_win_history")
 public class ItemConsumeWinHistory extends BaseEntity implements Serializable {
 
     @Serial

+ 0 - 6
src/main/java/com/punchsettle/server/atomic/entity/RewardExchangeHistory.java

@@ -61,12 +61,6 @@ public class RewardExchangeHistory extends BaseEntity implements Serializable {
     @Column(name = "account_id")
     private Long accountId;
 
-    /**
-     * 兑换使用的账户名称
-     */
-    @Column(name = "account_name")
-    private String accountName;
-
     /**
      * 兑换前账户中的积分
      */

+ 10 - 0
src/main/java/com/punchsettle/server/atomic/service/IRewardExchangeHistoryService.java

@@ -2,6 +2,8 @@ package com.punchsettle.server.atomic.service;
 
 import com.punchsettle.server.atomic.entity.RewardExchangeHistory;
 
+import java.util.List;
+
 /**
  * @author tyuio
  * @version 1.0.0
@@ -15,4 +17,12 @@ public interface IRewardExchangeHistoryService {
      * @param rewardExchangeHistory
      */
     void insert(RewardExchangeHistory rewardExchangeHistory);
+
+    /**
+     * 查询兑换记录
+     * @param userId 用户ID
+     * @param exchangeMonth 兑换月份
+     * @return
+     */
+    List<RewardExchangeHistory> queryRewardExchangeHistory(Long userId, String exchangeMonth);
 }

+ 8 - 0
src/main/java/com/punchsettle/server/atomic/service/ISettlePointsHistoryService.java

@@ -17,4 +17,12 @@ public interface ISettlePointsHistoryService {
      * @param settlePointsHistories
      */
     void insertList(List<SettlePointsHistory> settlePointsHistories);
+
+    /**
+     * 根据用户id和结算月查询结算记录
+     * @param userId 用户ID
+     * @param settleMonth 结算月
+     * @return
+     */
+    List<SettlePointsHistory> querySettlePointsHistory(Long userId, String settleMonth);
 }

+ 16 - 0
src/main/java/com/punchsettle/server/atomic/service/impl/RewardExchangeHistoryServiceImpl.java

@@ -6,6 +6,10 @@ import com.punchsettle.server.atomic.service.IRewardExchangeHistoryService;
 import com.punchsettle.server.common.utils.Assert;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import tk.mybatis.mapper.weekend.Weekend;
+import tk.mybatis.mapper.weekend.WeekendCriteria;
+
+import java.util.List;
 
 /**
  * @author tyuio
@@ -24,4 +28,16 @@ public class RewardExchangeHistoryServiceImpl implements IRewardExchangeHistoryS
         Assert.isNull(rewardExchangeHistory);
         rewardExchangeHistoryMapper.insertSelective(rewardExchangeHistory);
     }
+
+    @Override
+    public List<RewardExchangeHistory> queryRewardExchangeHistory(Long userId, String exchangeMonth) {
+        Assert.isNull(userId);
+        Assert.isNull(exchangeMonth);
+
+        Weekend<RewardExchangeHistory> weekend = Weekend.of(RewardExchangeHistory.class);
+        WeekendCriteria<RewardExchangeHistory, Object> criteria = weekend.weekendCriteria();
+        criteria.andEqualTo(RewardExchangeHistory::getUserId, userId);
+        criteria.andLike(RewardExchangeHistory::getCreationTime, String.format("%s%%", exchangeMonth));
+        return rewardExchangeHistoryMapper.selectByExample(weekend);
+    }
 }

+ 15 - 0
src/main/java/com/punchsettle/server/atomic/service/impl/SettlePointsHistoryServiceImpl.java

@@ -1,11 +1,14 @@
 package com.punchsettle.server.atomic.service.impl;
 
+import com.punchsettle.server.atomic.entity.AccountTransferHistory;
 import com.punchsettle.server.atomic.entity.SettlePointsHistory;
 import com.punchsettle.server.atomic.mapper.SettlePointsHistoryMapper;
 import com.punchsettle.server.atomic.service.ISettlePointsHistoryService;
 import com.punchsettle.server.common.utils.Assert;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import tk.mybatis.mapper.weekend.Weekend;
+import tk.mybatis.mapper.weekend.WeekendCriteria;
 
 import java.util.List;
 
@@ -26,4 +29,16 @@ public class SettlePointsHistoryServiceImpl implements ISettlePointsHistoryServi
         Assert.notEmpty(settlePointsHistories);
         settlePointsHistoryMapper.insertList(settlePointsHistories);
     }
+
+    @Override
+    public List<SettlePointsHistory> querySettlePointsHistory(Long userId, String settleMonth) {
+        Assert.isNull(userId);
+        Assert.isNull(settleMonth);
+
+        Weekend<SettlePointsHistory> weekend = Weekend.of(SettlePointsHistory.class);
+        WeekendCriteria<SettlePointsHistory, Object> criteria = weekend.weekendCriteria();
+        criteria.andEqualTo(SettlePointsHistory::getUserId, userId);
+        criteria.andLike(SettlePointsHistory::getSettleDate, String.format("%s%%", settleMonth));
+        return settlePointsHistoryMapper.selectByExample(weekend);
+    }
 }

+ 76 - 0
src/main/java/com/punchsettle/server/pojo/reward/RewardExchangeHistoryVO.java

@@ -0,0 +1,76 @@
+package com.punchsettle.server.pojo.reward;
+
+import com.punchsettle.server.constant.RewardExchangeMethodEnum;
+
+import lombok.Data;
+
+/**
+ * @author myou
+ * @version 1.0.0
+ * @date 2025/5/2 21:33
+ * @description 奖励兑换记录 VO
+ */
+@Data
+public class RewardExchangeHistoryVO {
+
+    /**
+     * 奖励名称
+     */
+    private String rewardName;
+
+    /**
+     * 兑换类型(手动兑换-MANUAL,自动兑换-AUTO)
+     * @see RewardExchangeMethodEnum
+     */
+    private RewardExchangeMethodEnum exchangeMethod;
+
+    /**
+     * 兑换数量
+     */
+    private Integer exchangeCount;
+
+    /**
+     * 兑换所需总积分
+     */
+    private Integer exchangeTotalPoints;
+
+    /**
+     * 兑换使用的账户名称
+     */
+    private String accountName;
+
+    /**
+     * 兑换前账户中的积分
+     */
+    private Integer accountPointsBeforeExchange;
+
+    /**
+     * 兑换后账户中的积分
+     */
+    private Integer accountPointsAfterExchange;
+
+    /**
+     * 兑换前用户的未使用积分
+     */
+    private Integer unusedPointsBeforeExchange;
+
+    /**
+     * 兑换后用户的未使用积分
+     */
+    private Integer unusedPointsAfterExchange;
+
+    /**
+     * 兑换前用户的已使用积分
+     */
+    private Integer usedPointsBeforeExchange;
+
+    /**
+     * 兑换后用户的已使用积分
+     */
+    private Integer usedPointsAfterExchange;
+
+    /**
+     * 兑换时间
+     */
+    private String exchangeTime;
+}

+ 7 - 0
src/main/java/com/punchsettle/server/pojo/reward/RewardQuery.java

@@ -1,5 +1,7 @@
 package com.punchsettle.server.pojo.reward;
 
+import java.util.Collection;
+
 import com.punchsettle.server.constant.VersionStatusEnum;
 
 import lombok.Data;
@@ -23,4 +25,9 @@ public class RewardQuery {
      * @see VersionStatusEnum
      */
     private VersionStatusEnum rewardStatus;
+
+    /**
+     * 奖励ID列表
+     */
+    private Collection<Long> rewardIds;
 }

+ 34 - 0
src/main/java/com/punchsettle/server/pojo/settle/SettlePointsHistoryVO.java

@@ -0,0 +1,34 @@
+package com.punchsettle.server.pojo.settle;
+
+import lombok.Data;
+
+/**
+ * @author myou
+ * @version 1.0.0
+ * @date 2025/5/2 21:17
+ * @description 积分结算记录
+ */
+@Data
+public class SettlePointsHistoryVO {
+
+    /**
+     * 结算日期
+     */
+    private String settleDate;
+
+    /**
+     * 结算积分
+     */
+    private Integer settlePoints;
+
+    /**
+     * 结算前用户拥有的积分
+     */
+    private Integer beforeSettlePoints;
+
+    /**
+     * 结算后用户拥有的积分
+     *
+     */
+    private Integer afterSettlePoints;
+}

+ 9 - 0
src/main/java/com/punchsettle/server/service/controller/RewardController.java

@@ -2,6 +2,7 @@ package com.punchsettle.server.service.controller;
 
 import java.util.List;
 
+import com.punchsettle.server.pojo.reward.RewardExchangeHistoryVO;
 import com.punchsettle.server.pojo.reward.RewardExchangeRequest;
 import com.punchsettle.server.pojo.reward.RewardRequest;
 import jakarta.validation.constraints.NotNull;
@@ -73,4 +74,12 @@ public class RewardController {
     public void exchangeReward(@RequestBody RewardExchangeRequest request) {
         rewardManager.exchangeReward(request);
     }
+
+    /**
+     * 查询兑换记录
+     */
+    @GetMapping("/queryRewardExchangeHistory")
+    public List<RewardExchangeHistoryVO> queryRewardExchangeHistory(@NotNull(message = "兑换月不能为空") String exchangeMonth) {
+        return rewardManager.queryRewardExchangeHistory(exchangeMonth);
+    }
 }

+ 14 - 0
src/main/java/com/punchsettle/server/service/controller/SettleController.java

@@ -2,8 +2,11 @@ package com.punchsettle.server.service.controller;
 
 import java.util.List;
 
+import com.punchsettle.server.pojo.settle.SettlePointsHistoryVO;
+import jakarta.validation.constraints.NotBlank;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
@@ -20,6 +23,7 @@ import com.punchsettle.server.service.manager.ISettleManagerV1;
  * @description 结算 controller
  * @date 2024/11/26 15:04
  */
+@Validated
 @RestController
 @RequestMapping("/settle")
 public class SettleController {
@@ -42,4 +46,14 @@ public class SettleController {
     public List<SettleVO> querySettle(@RequestBody @Validated SettleQuery query) {
         return settleManager.querySettle(query);
     }
+
+    /**
+     * 查询结算积分记录
+     * @param settleMonth
+     * @return
+     */
+    @GetMapping("/querySettlePointsHistory")
+    public List<SettlePointsHistoryVO> querySettlePointsHistory(@NotBlank(message = "结算月不能为空") String settleMonth) {
+    	return settleManager.querySettlePointsHistory(settleMonth);
+    }
 }

+ 8 - 0
src/main/java/com/punchsettle/server/service/manager/IRewardManager.java

@@ -2,6 +2,7 @@ package com.punchsettle.server.service.manager;
 
 import java.util.List;
 
+import com.punchsettle.server.pojo.reward.RewardExchangeHistoryVO;
 import com.punchsettle.server.pojo.reward.RewardExchangeRequest;
 import com.punchsettle.server.pojo.reward.RewardRequest;
 import com.punchsettle.server.pojo.reward.RewardVO;
@@ -44,4 +45,11 @@ public interface IRewardManager {
      * @param request
      */
     void exchangeReward(RewardExchangeRequest request);
+
+    /**
+     * 查询奖励兑换历史
+     * @param exchangeMonth 兑换月
+     * @return
+     */
+    List<RewardExchangeHistoryVO> queryRewardExchangeHistory(String exchangeMonth);
 }

+ 8 - 0
src/main/java/com/punchsettle/server/service/manager/ISettleManagerV1.java

@@ -7,6 +7,7 @@ import com.punchsettle.server.atomic.entity.PunchIn;
 import com.punchsettle.server.atomic.entity.PunchInRecord;
 import com.punchsettle.server.constant.PunchInSettleTypeEnum;
 import com.punchsettle.server.constant.PunchInStatusV1Enum;
+import com.punchsettle.server.pojo.settle.SettlePointsHistoryVO;
 import com.punchsettle.server.pojo.settle.SettleQuery;
 import com.punchsettle.server.pojo.settle.SettleRequest;
 import com.punchsettle.server.pojo.settle.SettleVO;
@@ -48,4 +49,11 @@ public interface ISettleManagerV1 {
      * @return
      */
     List<SettleVO> querySettle(SettleQuery query);
+
+    /**
+     * 查询结算积分记录
+     * @param settleMonth 结算月
+     * @return
+     */
+    List<SettlePointsHistoryVO> querySettlePointsHistory(String settleMonth);
 }

+ 62 - 12
src/main/java/com/punchsettle/server/service/manager/impl/RewardManagerImpl.java

@@ -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());
+    }
 }

+ 23 - 0
src/main/java/com/punchsettle/server/service/manager/impl/SettleManagerV1Impl.java

@@ -22,12 +22,14 @@ import com.punchsettle.server.atomic.entity.PunchIn;
 import com.punchsettle.server.atomic.entity.PunchInRecord;
 import com.punchsettle.server.atomic.entity.PunchInRecordSettlementRela;
 import com.punchsettle.server.atomic.entity.PunchInSettlement;
+import com.punchsettle.server.atomic.entity.SettlePointsHistory;
 import com.punchsettle.server.atomic.entity.SettlementTask;
 import com.punchsettle.server.atomic.entity.User;
 import com.punchsettle.server.atomic.service.IPunchInRecordService;
 import com.punchsettle.server.atomic.service.IPunchInRecordSettlementRelaService;
 import com.punchsettle.server.atomic.service.IPunchInService;
 import com.punchsettle.server.atomic.service.IPunchInSettlementService;
+import com.punchsettle.server.atomic.service.ISettlePointsHistoryService;
 import com.punchsettle.server.atomic.service.ISettlementTaskService;
 import com.punchsettle.server.atomic.service.IUserService;
 import com.punchsettle.server.common.exception.BusinessException;
@@ -39,6 +41,7 @@ import com.punchsettle.server.constant.PunchInStatusV1Enum;
 import com.punchsettle.server.pojo.punchinV1.PunchInQuery;
 import com.punchsettle.server.pojo.punchinV1.PunchInRecordQuery;
 import com.punchsettle.server.pojo.settle.SettleInfoDto;
+import com.punchsettle.server.pojo.settle.SettlePointsHistoryVO;
 import com.punchsettle.server.pojo.settle.SettleQuery;
 import com.punchsettle.server.pojo.settle.SettleRequest;
 import com.punchsettle.server.pojo.settle.SettleResultDto;
@@ -46,6 +49,7 @@ import com.punchsettle.server.pojo.settle.SettleVO;
 import com.punchsettle.server.service.manager.ISettleManagerV1;
 import com.punchsettle.server.utiis.DateUtils;
 import com.punchsettle.server.utiis.SpringUtils;
+import com.punchsettle.server.utiis.UserUtils;
 
 import lombok.extern.slf4j.Slf4j;
 
@@ -77,6 +81,9 @@ public class SettleManagerV1Impl implements ISettleManagerV1 {
     @Autowired
     private IPunchInRecordSettlementRelaService punchInRecordSettlementRelaService;
 
+    @Autowired
+    private ISettlePointsHistoryService settlePointsHistoryService;
+
     @Override
     @Transactional(rollbackFor = Exception.class)
     public void settleHandler(PunchInSettleTypeEnum settleType, LocalDate settleDate, List<Long> userIds, List<Long> punchInIds) {
@@ -481,4 +488,20 @@ public class SettleManagerV1Impl implements ISettleManagerV1 {
             return settleVO;
         }).toList();
     }
+
+    @Override
+    public List<SettlePointsHistoryVO> querySettlePointsHistory(String settleMonth) {
+        Assert.isNullInBusiness(settleMonth, "结算月份不能为空");
+
+        List<SettlePointsHistory> settlePointsHistories = settlePointsHistoryService.querySettlePointsHistory(UserUtils.getCurrentUserId(), settleMonth);
+        if (CollectionUtils.isEmpty(settlePointsHistories)) {
+            return List.of();
+        }
+
+        return settlePointsHistories.stream().map(settlePointsHistory -> {
+            SettlePointsHistoryVO settlePointsHistoryVO = new SettlePointsHistoryVO();
+            BeanUtils.copyProperties(settlePointsHistory, settlePointsHistoryVO);
+            return settlePointsHistoryVO;
+        }).collect(Collectors.toList());
+    }
 }