From 704e2047a3aa31b96d6250824e8ddd5a48e7c6fc Mon Sep 17 00:00:00 2001 From: menxipeng Date: Sun, 3 Aug 2025 22:15:27 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=9A=E5=91=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/back/ShopUserController.java | 54 +++++++++++++++++++ .../ruoyi/system/mapper/ShopUserMapper.java | 8 +++ .../system/service/IShopUserService.java | 8 +++ .../service/impl/ShopUserServiceImpl.java | 34 ++++++++++++ .../mapper/system/ShopUserMapper.xml | 9 ++++ ruoyi-ui/src/api/user/user.js | 18 ++++++- ruoyi-ui/src/views/user/manage/index.vue | 16 +++++- 7 files changed, 145 insertions(+), 2 deletions(-) diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/back/ShopUserController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/back/ShopUserController.java index 028f361..2afe3a3 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/back/ShopUserController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/back/ShopUserController.java @@ -169,4 +169,58 @@ public class ShopUserController extends BaseController return AjaxResult.error("更新在线时长异常: " + e.getMessage()); } } + + /** + * 获取用户标签 + * 根据用户历史记录中的音乐标签来返回用户的标签列表 + */ + @GetMapping("/tags/{userId}") + public AjaxResult getUserTags(@PathVariable("userId") String userId) + { + if (userId == null || userId.isEmpty()) { + return AjaxResult.error("用户ID不能为空"); + } + + try { + // 调用服务获取用户标签 + String tags = shopUserService.getUserTags(userId); + + if (tags != null && !tags.isEmpty()) { + return AjaxResult.success("获取用户标签成功", tags); + } else { + return AjaxResult.success("用户暂无标签", ""); + } + } catch (Exception e) { + log.error("获取用户[{}]标签异常", userId, e); + return AjaxResult.error("获取用户标签异常: " + e.getMessage()); + } + } + + /** + * 获取当前登录用户的标签 + */ + @GetMapping("/myTags") + public AjaxResult getMyTags() + { + try { + // 获取当前登录用户 + LoginUser loginUser = SecurityUtils.getLoginUser(); + if (loginUser == null || loginUser.getUserId() == null) { + return AjaxResult.error("用户未登录或用户ID为空"); + } + ShopUser shopUser = loginUser.getShopUser(); + + // 调用服务获取用户标签 + String tags = shopUserService.getUserTags(shopUser.getUserId().toString()); + + if (tags != null && !tags.isEmpty()) { + return AjaxResult.success("获取用户标签成功", tags); + } else { + return AjaxResult.success("用户暂无标签", ""); + } + } catch (Exception e) { + log.error("获取当前用户标签异常", e); + return AjaxResult.error("获取用户标签异常: " + e.getMessage()); + } + } } diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/mapper/ShopUserMapper.java b/ruoyi-system/src/main/java/com/ruoyi/system/mapper/ShopUserMapper.java index f84211f..697c134 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/mapper/ShopUserMapper.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/mapper/ShopUserMapper.java @@ -77,5 +77,13 @@ public interface ShopUserMapper { * @return 结果 */ public int updateUserOnlineTime(ShopUser shopUser); + + /** + * 查询用户的音乐标签 + * + * @param userId 用户ID + * @return 音乐标签列表 + */ + public List selectUserMusicTags(String userId); } \ No newline at end of file diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/IShopUserService.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/IShopUserService.java index 601074d..4c5280f 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/IShopUserService.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/IShopUserService.java @@ -69,4 +69,12 @@ public interface IShopUserService * @return 结果 */ public int updateUserOnlineTime(ShopUser shopUser); + + /** + * 获取用户标签列表 + * + * @param userId 用户ID + * @return 用户标签列表(以分号分隔的字符串) + */ + public String getUserTags(String userId); } diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/ShopUserServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/ShopUserServiceImpl.java index 871696c..14a9de9 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/ShopUserServiceImpl.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/ShopUserServiceImpl.java @@ -156,4 +156,38 @@ public class ShopUserServiceImpl implements IShopUserService return shopUserMapper.updateUserOnlineTime(updateUser); } + + /** + * 获取用户标签列表 + * + * @param userId 用户ID + * @return 用户标签列表(以分号分隔的字符串) + */ + @Override + public String getUserTags(String userId) { + if (userId == null || userId.isEmpty()) { + return ""; + } + + // 查询用户的音乐标签 + List tagList = shopUserMapper.selectUserMusicTags(userId); + + if (tagList == null || tagList.isEmpty()) { + return ""; + } + + // 将标签列表转换为分号分隔的字符串 + StringBuilder tags = new StringBuilder(); + for (int i = 0; i < tagList.size(); i++) { + String tag = tagList.get(i); + if (tag != null && !tag.isEmpty()) { + tags.append(tag); + if (i < tagList.size() - 1) { + tags.append(";"); + } + } + } + + return tags.toString(); + } } diff --git a/ruoyi-system/src/main/resources/mapper/system/ShopUserMapper.xml b/ruoyi-system/src/main/resources/mapper/system/ShopUserMapper.xml index aabe1bc..ef36af5 100644 --- a/ruoyi-system/src/main/resources/mapper/system/ShopUserMapper.xml +++ b/ruoyi-system/src/main/resources/mapper/system/ShopUserMapper.xml @@ -200,4 +200,13 @@ where user_id = #{userId} + + + \ No newline at end of file diff --git a/ruoyi-ui/src/api/user/user.js b/ruoyi-ui/src/api/user/user.js index b0cd5e4..1db7b96 100644 --- a/ruoyi-ui/src/api/user/user.js +++ b/ruoyi-ui/src/api/user/user.js @@ -35,4 +35,20 @@ export function delUser(id) { url: '/back/user/' + id, method: 'delete' }) -} \ No newline at end of file +} + +// 获取用户标签 +export function getUserTags(userId) { + return request({ + url: '/back/user/tags/' + userId, + method: 'get' + }) +} + +// 获取当前登录用户的标签 +export function getMyTags() { + return request({ + url: '/back/user/myTags', + method: 'get' + }) +} diff --git a/ruoyi-ui/src/views/user/manage/index.vue b/ruoyi-ui/src/views/user/manage/index.vue index 126a307..a468f8a 100644 --- a/ruoyi-ui/src/views/user/manage/index.vue +++ b/ruoyi-ui/src/views/user/manage/index.vue @@ -87,7 +87,7 @@