Преглед изворни кода

【feat】【v3】
1.增加转账记录查询
2.增加任务详情折线图数据处理
3.完善sql脚本

ChenYL пре 11 месеци
родитељ
комит
c01fc45497

+ 5 - 4
doc/sql/update-v3.sql

@@ -312,7 +312,7 @@ CREATE TABLE `pi_task_history` (
   `settle_result` varchar(20) NOT NULL COMMENT '结算结果(未结算-UNSETTLED,已结算-SETTLED)',
   `settle_pi_task_id` bigint DEFAULT NULL COMMENT '结算时的打卡任务ID',
   `settle_task_history_id` bigint DEFAULT NULL COMMENT '结算任务执行记录ID',
-  `settle_points` int DEFAULT NULL COMMENT '结算奖励积分',p
+  `settle_points` int DEFAULT NULL COMMENT '结算奖励积分',
   `created_by` bigint NOT NULL COMMENT '创建人',
   `creation_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
   `last_updated_by` bigint NOT NULL COMMENT '最后更新人',
@@ -656,7 +656,7 @@ DROP TABLE IF EXISTS punch_in_settlement;
 -- 删除无效的用户数据
 delete from user where id not in (select created_by from pi_task group by created_by);
 -- 初始化账户数据,account数从user导入
-insert into account(user_id, account_name, account_type, points, created_by, creation_time, last_updated_by, last_update_time, version, delete_flag)
+insert into account(user_id, account_name, account_category, points, created_by, creation_time, last_updated_by, last_update_time, version, delete_flag)
 select id, '基本户', 'BASIC', unused_points, id, CURRENT_TIMESTAMP(), id, CURRENT_TIMESTAMP(), 1, 0
 from user;
 -- 初始化基本奖励数据
@@ -673,12 +673,12 @@ ALTER TABLE punch_settle.reward MODIFY COLUMN reward_version int NOT NULL COMMEN
 
 ALTER TABLE punch_settle.reward_history DROP COLUMN account_name;
 insert into reward_history(user_id, reward_id, exchange_method, exchange_count, exchange_total_points, account_id, account_points_before_exchange, account_points_after_exchange,
-unused_points_before_exchange, unused_points_after_exchange, userd_points_before_exchange, userd_points_after_exchange,
+unused_points_before_exchange, unused_points_after_exchange, used_points_before_exchange, used_points_after_exchange,
 created_by, creation_time, last_updated_by, last_update_time, version, delete_flag)
 select created_by,
 (select id from reward r where r.user_id = rr.created_by and r.reward_name = '刮一次刮刮乐'),
 'MANUAL', claim_reward_num, claim_reward_num,
-(SELECT ID FROM account a where a.user_id = rr.created_by and a.account_type = 'BASIC'),
+(SELECT ID FROM account a where a.user_id = rr.created_by and a.account_category = 'BASIC'),
 rr.before_claim_reward_num , rr.after_claim_reward_num , rr.before_claim_reward_num , rr.after_claim_reward_num , rr.before_claim_reward_num , rr.after_claim_reward_num ,
 created_by, creation_time, last_updated_by, last_update_time, version, delete_flag
 from user_claim_reward_record rr;
@@ -694,6 +694,7 @@ pir.creation_time, pir.last_updated_by, pir.last_update_time, pir.version, pir.d
 from punch_in_record pir
 left join punch_in_record_settlement_rela pirsr on pir.id = pirsr.record_id;
 
+update pi_task_history set punch_in_result = 'DONE' where punch_in_result = '3';
 update pi_task_history set punch_in_result = 'DONE' where punch_in_result = '1';
 update pi_task_history set punch_in_result = 'UNDONE' where punch_in_result = '2';
 update pi_task_history set punch_in_result = 'UNDONE' where punch_in_result = '0';

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

@@ -17,4 +17,12 @@ public interface IAccountTransferHistoryService {
      * @param accountTransferHistories
      */
     void batchInsert(List<AccountTransferHistory> accountTransferHistories);
+
+    /**
+     * 查询账户转账记录
+     * @param userId 用户ID
+     * @param transferMonth 转账月份
+     * @return
+     */
+    List<AccountTransferHistory> queryTransferHistory(Long userId, String transferMonth);
 }

+ 14 - 0
src/main/java/com/punchsettle/server/atomic/service/impl/AccountTransferHistoryServiceImpl.java

@@ -6,6 +6,8 @@ import com.punchsettle.server.atomic.service.IAccountTransferHistoryService;
 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;
 
@@ -27,4 +29,16 @@ public class AccountTransferHistoryServiceImpl implements IAccountTransferHistor
         Assert.isNull(accountTransferHistories);
         accountTransferHistoryMapper.insertList(accountTransferHistories);
     }
+
+    @Override
+    public List<AccountTransferHistory> queryTransferHistory(Long userId, String transferMonth) {
+        Assert.isNull(userId);
+        Assert.isNull(transferMonth);
+
+        Weekend<AccountTransferHistory> weekend = Weekend.of(AccountTransferHistory.class);
+        WeekendCriteria<AccountTransferHistory, Object> criteria = weekend.weekendCriteria();
+        criteria.andEqualTo(AccountTransferHistory::getUserId, userId);
+        criteria.andLike(AccountTransferHistory::getCreationTime, String.format("%s%%", transferMonth));
+        return accountTransferHistoryMapper.selectByExample(weekend);
+    }
 }

+ 61 - 0
src/main/java/com/punchsettle/server/pojo/account/TransferHistoryVO.java

@@ -0,0 +1,61 @@
+package com.punchsettle.server.pojo.account;
+
+import com.punchsettle.server.constant.TransferCategoryEnum;
+
+import lombok.Data;
+
+/**
+ * @author myou
+ * @version 1.0.0
+ * @date 2025/5/2 9:34
+ * @description 转账历史VO
+ */
+@Data
+public class TransferHistoryVO {
+
+    /**
+     * 转出账户名称
+     */
+    private String senderAccountName;
+
+    /**
+     * 转入账户名称
+     */
+    private String recipientAccountName;
+
+    /**
+     * 转账类型(转账-TRANSFER,结算-SETTLE)
+     * @see TransferCategoryEnum
+     */
+    private TransferCategoryEnum transferCategory;
+
+    /**
+     * 转账积分
+     */
+    private Integer transferPoints;
+
+    /**
+     * 转出账户转出前积分
+     */
+    private Integer saPointsBeforeTransfer;
+
+    /**
+     * 转出账户转出后积分
+     */
+    private Integer saPointsAfterTransfer;
+
+    /**
+     * 转入账户转入前积分
+     */
+    private Integer raPointsBeforeTransfer;
+
+    /**
+     * 转入账户转入后积分
+     */
+    private Integer raPointsAfterTransfer;
+
+    /**
+     * 转账时间
+     */
+    private String transferTime;
+}

+ 7 - 1
src/main/java/com/punchsettle/server/pojo/punchIn/PiTaskStatVO.java

@@ -1,5 +1,6 @@
 package com.punchsettle.server.pojo.punchIn;
 
+import com.punchsettle.server.pojo.ucharts.LineVO;
 import lombok.Data;
 
 import java.math.BigDecimal;
@@ -52,5 +53,10 @@ public class PiTaskStatVO {
     /**
      * 打卡任务打卡记录统计
      */
-    List<PiTaskHistoryStatVO> piTaskHistoryStatVOS;
+    private List<PiTaskHistoryStatVO> piTaskHistoryStatVOS;
+
+    /**
+     * 折线图统计数据
+     */
+    private LineVO lineVO;
 }

+ 23 - 0
src/main/java/com/punchsettle/server/pojo/ucharts/LineSeriesVO.java

@@ -0,0 +1,23 @@
+package com.punchsettle.server.pojo.ucharts;
+
+import lombok.Data;
+
+/**
+ * @author myou
+ * @version 1.0.0
+ * @date 2025/5/1 9:57
+ * @description uCharts图表 折线图具体数据
+ */
+@Data
+public class LineSeriesVO {
+
+    /**
+     * 数据名称
+     */
+    private String name;
+
+    /**
+     * 数据
+     */
+    private Integer[] data;
+}

+ 25 - 0
src/main/java/com/punchsettle/server/pojo/ucharts/LineVO.java

@@ -0,0 +1,25 @@
+package com.punchsettle.server.pojo.ucharts;
+
+import lombok.Data;
+
+import java.util.List;
+
+/**
+ * @author myou
+ * @version 1.0.0
+ * @date 2025/5/1 9:56
+ * @description uCharts图表 折线图
+ */
+@Data
+public class LineVO {
+
+    /**
+     * 折线图横坐标
+     */
+    private String[] categories;
+
+    /**
+     * 折线图数据
+     */
+    private List<LineSeriesVO> series;
+}

+ 12 - 0
src/main/java/com/punchsettle/server/service/controller/AccountController.java

@@ -2,6 +2,8 @@ package com.punchsettle.server.service.controller;
 
 import com.punchsettle.server.pojo.account.AccountVO;
 import com.punchsettle.server.pojo.account.AccountInfoVO;
+import com.punchsettle.server.pojo.account.TransferHistoryVO;
+import jakarta.validation.constraints.NotBlank;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.DeleteMapping;
@@ -85,4 +87,14 @@ public class AccountController {
     public void transfer(@RequestBody TransferRequest request) {
         accountManager.transfer(request);
     }
+
+    /**
+     * 查询转账记录
+     * @param transferMonth 转账月份
+     * @return
+     */
+    @GetMapping("queryTransferHistory")
+    public List<TransferHistoryVO> queryTransferHistory(@NotBlank(message = "转账月份不能为空") String transferMonth) {
+        return accountManager.queryTransferHistory(transferMonth);
+    }
 }

+ 7 - 0
src/main/java/com/punchsettle/server/service/manager/IAccountManager.java

@@ -3,6 +3,7 @@ package com.punchsettle.server.service.manager;
 import com.punchsettle.server.pojo.account.AccountRequest;
 import com.punchsettle.server.pojo.account.AccountVO;
 import com.punchsettle.server.pojo.account.AccountInfoVO;
+import com.punchsettle.server.pojo.account.TransferHistoryVO;
 import com.punchsettle.server.pojo.account.TransferRequest;
 
 import java.util.List;
@@ -49,4 +50,10 @@ public interface IAccountManager {
      * @param request
      */
     void transfer(TransferRequest request);
+
+    /**
+     * 查询转账记录
+     * @param transferMonth 转账月份
+     */
+    List<TransferHistoryVO> queryTransferHistory(String transferMonth);
 }

+ 43 - 0
src/main/java/com/punchsettle/server/service/manager/impl/AccountManagerImpl.java

@@ -11,9 +11,11 @@ import com.punchsettle.server.constant.TransferCategoryEnum;
 import com.punchsettle.server.pojo.account.AccountRequest;
 import com.punchsettle.server.pojo.account.AccountVO;
 import com.punchsettle.server.pojo.account.AccountInfoVO;
+import com.punchsettle.server.pojo.account.TransferHistoryVO;
 import com.punchsettle.server.pojo.account.TransferRequest;
 import com.punchsettle.server.pojo.punchIn.AccountQuery;
 import com.punchsettle.server.service.manager.IAccountManager;
+import com.punchsettle.server.utiis.DateUtils;
 import com.punchsettle.server.utiis.UserUtils;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.BeanUtils;
@@ -22,10 +24,13 @@ import org.springframework.stereotype.Component;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.CollectionUtils;
 
+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.function.Function;
 import java.util.stream.Collectors;
 
 /**
@@ -183,4 +188,42 @@ public class AccountManagerImpl implements IAccountManager {
 
         accountService.batchUpdate(Arrays.asList(updateSenderAccount, updateRecipientAccount));
     }
+
+    @Override
+    public List<TransferHistoryVO> queryTransferHistory(String transferMonth) {
+        Assert.isNullInBusiness(transferMonth, "转账月份不能为空");
+
+        List<AccountTransferHistory> accountTransferHistories = accountTransferHistoryService.queryTransferHistory(UserUtils.getCurrentUserId(), transferMonth);
+        if (CollectionUtils.isEmpty(accountTransferHistories)) {
+            return List.of();
+        }
+
+        // 查询账户
+        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 accountTransferHistories.stream().map(accountTransferHistory -> {
+            TransferHistoryVO transferHistoryVO = new TransferHistoryVO();
+            BeanUtils.copyProperties(accountTransferHistory, transferHistoryVO);
+
+            transferHistoryVO.setTransferTime(sdf.format(accountTransferHistory.getCreationTime()));
+
+            Account senderAccount = accountMap.get(accountTransferHistory.getSenderAccountId());
+            if (Objects.nonNull(senderAccount)) {
+                transferHistoryVO.setSenderAccountName(senderAccount.getAccountName());
+            }
+
+            Account recipientAccount = accountMap.get(accountTransferHistory.getRecipientAccountId());
+            if (Objects.nonNull(recipientAccount)) {
+                transferHistoryVO.setRecipientAccountName(recipientAccount.getAccountName());
+            }
+
+            return transferHistoryVO;
+        }).collect(Collectors.toList());
+    }
 }

+ 21 - 0
src/main/java/com/punchsettle/server/service/manager/impl/PunchInManagerImpl.java

@@ -6,6 +6,7 @@ import java.text.SimpleDateFormat;
 import java.time.LocalDate;
 import java.time.LocalTime;
 import java.time.YearMonth;
+import java.time.format.DateTimeFormatter;
 import java.time.temporal.ChronoUnit;
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -19,6 +20,8 @@ import java.util.function.Function;
 import java.util.stream.Collectors;
 
 import com.punchsettle.server.pojo.punchIn.StatPiTaskQuery;
+import com.punchsettle.server.pojo.ucharts.LineSeriesVO;
+import com.punchsettle.server.pojo.ucharts.LineVO;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -566,6 +569,23 @@ public class PunchInManagerImpl implements IPunchInManager {
         // 打卡任务ID-打卡任务对象关联
         Map<Long, PiTask> piTaskMap = piTasks.stream().collect(Collectors.toMap(PiTask::getId, Function.identity(), (key1, key2) -> key1));
 
+        String statTime = null;
+        if (StatPeriodEnum.MONTH.equals(query.getStatPeriod())) {
+            String[] split = query.getStatTime().split("-");
+            statTime = String.format("%s-%s-01", split[0], split[1]);
+        }
+        List<LocalDate> dateRangeInMonth = DateUtils.getDateRangeInMonth(LocalDate.parse(statTime));
+        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("MM-dd");
+        String[] categories = dateRangeInMonth.stream().map(v -> dateTimeFormatter.format(v)).toArray(String[]::new);
+        Integer[] lineSeriesData = piTaskHistories.stream().map(PiTaskHistory::getCountTrack).toArray(Integer[]::new);
+
+        LineSeriesVO lineSeriesVO = new LineSeriesVO();
+        lineSeriesVO.setName("每日打卡次数");
+        lineSeriesVO.setData(lineSeriesData);
+        LineVO lineVO = new LineVO();
+        lineVO.setCategories(categories);
+        lineVO.setSeries(Arrays.asList(lineSeriesVO));
+
         // 组装数据
         List<PiTaskHistoryStatVO> piTaskHistoryStatVOS = piTaskHistories.stream().map(piTaskHistory -> {
             PiTaskHistoryStatVO piTaskHistoryStatVO = new PiTaskHistoryStatVO();
@@ -576,6 +596,7 @@ public class PunchInManagerImpl implements IPunchInManager {
         PiTaskStatVO piTaskStatVO = new PiTaskStatVO();
         BeanUtils.copyProperties(statPiTask, piTaskStatVO);
         piTaskStatVO.setPiTaskHistoryStatVOS(piTaskHistoryStatVOS);
+        piTaskStatVO.setLineVO(lineVO);
         return piTaskStatVO;
     }
     @Override