From f9f5fc34a58e472af62e949b9381521aae87b62b Mon Sep 17 00:00:00 2001
From: phpcjl <phpcjl@gmail.com>
Date: 星期三, 11 十二月 2024 15:27:40 +0800
Subject: [PATCH] 1.后台管理-商品管理

---
 ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/service/impl/UserPointServiceImpl.java |    3 +--
 ruoyi-service/ruoyi-account/src/main/resources/mapper/account/UserPointMapper.xml                  |   10 ++++++++++
 ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/mapper/UserPointMapper.java            |    3 +++
 3 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/mapper/UserPointMapper.java b/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/mapper/UserPointMapper.java
index 65af734..addb4f1 100644
--- a/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/mapper/UserPointMapper.java
+++ b/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/mapper/UserPointMapper.java
@@ -3,6 +3,8 @@
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.ruoyi.account.api.model.UserPoint;
 
+import java.util.List;
+
 /**
  * <p>
  *  Mapper 接口
@@ -13,4 +15,5 @@
  */
 public interface UserPointMapper extends BaseMapper<UserPoint> {
 
+    List<UserPoint> findLatestUserPointByTypeForUser(Long userId);
 }
diff --git a/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/service/impl/UserPointServiceImpl.java b/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/service/impl/UserPointServiceImpl.java
index 922bf81..db675e1 100644
--- a/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/service/impl/UserPointServiceImpl.java
+++ b/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/service/impl/UserPointServiceImpl.java
@@ -55,8 +55,7 @@
     @Override
     public UserPointVO getUserPoint(Long userId) {
         AppUser appUser = appUserService.getById(userId);
-        List<UserPoint> userPointList = list(new LambdaQueryWrapper<UserPoint>()
-                .eq(UserPoint::getAppUserId, userId));
+        List<UserPoint> userPointList = this.baseMapper.findLatestUserPointByTypeForUser(userId);
 
         Map<Integer, Integer> userBalanceMap = userPointList.stream()
                 .collect(Collectors.toMap(UserPoint::getType, UserPoint::getBalance));
diff --git a/ruoyi-service/ruoyi-account/src/main/resources/mapper/account/UserPointMapper.xml b/ruoyi-service/ruoyi-account/src/main/resources/mapper/account/UserPointMapper.xml
index 35c2f57..9f38579 100644
--- a/ruoyi-service/ruoyi-account/src/main/resources/mapper/account/UserPointMapper.xml
+++ b/ruoyi-service/ruoyi-account/src/main/resources/mapper/account/UserPointMapper.xml
@@ -17,5 +17,15 @@
     <sql id="Base_Column_List">
         id, type, historical_point, variable_point, create_time, app_user_id, object_id
     </sql>
+    <select id="findLatestUserPointByTypeForUser" resultType="com.ruoyi.account.api.model.UserPoint">
+        SELECT
+            t1.*
+        FROM
+            t_user_point t1
+                INNER JOIN ( SELECT type, MAX( create_time ) AS max_create_time FROM t_user_point WHERE app_user_id = 1864118151377129473 GROUP BY type ) t2 ON t1.type = t2.type
+                AND t1.create_time = t2.max_create_time
+        WHERE
+            t1.app_user_id = #{userId}
+    </select>
 
 </mapper>

--
Gitblit v1.7.1