会员
This commit is contained in:
@@ -169,4 +169,58 @@ public class ShopUserController extends BaseController
|
|||||||
return AjaxResult.error("更新在线时长异常: " + e.getMessage());
|
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());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -78,4 +78,12 @@ public interface ShopUserMapper {
|
|||||||
*/
|
*/
|
||||||
public int updateUserOnlineTime(ShopUser shopUser);
|
public int updateUserOnlineTime(ShopUser shopUser);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询用户的音乐标签
|
||||||
|
*
|
||||||
|
* @param userId 用户ID
|
||||||
|
* @return 音乐标签列表
|
||||||
|
*/
|
||||||
|
public List<String> selectUserMusicTags(String userId);
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -69,4 +69,12 @@ public interface IShopUserService
|
|||||||
* @return 结果
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
public int updateUserOnlineTime(ShopUser shopUser);
|
public int updateUserOnlineTime(ShopUser shopUser);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取用户标签列表
|
||||||
|
*
|
||||||
|
* @param userId 用户ID
|
||||||
|
* @return 用户标签列表(以分号分隔的字符串)
|
||||||
|
*/
|
||||||
|
public String getUserTags(String userId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -156,4 +156,38 @@ public class ShopUserServiceImpl implements IShopUserService
|
|||||||
|
|
||||||
return shopUserMapper.updateUserOnlineTime(updateUser);
|
return shopUserMapper.updateUserOnlineTime(updateUser);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取用户标签列表
|
||||||
|
*
|
||||||
|
* @param userId 用户ID
|
||||||
|
* @return 用户标签列表(以分号分隔的字符串)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String getUserTags(String userId) {
|
||||||
|
if (userId == null || userId.isEmpty()) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
// 查询用户的音乐标签
|
||||||
|
List<String> 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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -200,4 +200,13 @@
|
|||||||
</set>
|
</set>
|
||||||
where user_id = #{userId}
|
where user_id = #{userId}
|
||||||
</update>
|
</update>
|
||||||
|
|
||||||
|
<!-- 查询用户的音乐标签 -->
|
||||||
|
<select id="selectUserMusicTags" parameterType="String" resultType="String">
|
||||||
|
SELECT mi.label FROM user_history uh
|
||||||
|
LEFT JOIN music_info mi on uh.music_id = mi.music_id
|
||||||
|
LEFT JOIN shop_user su on uh.user_id = su.user_id
|
||||||
|
WHERE su.user_id = #{userId} AND mi.label IS NOT NULL AND mi.label != ''
|
||||||
|
GROUP BY mi.label
|
||||||
|
</select>
|
||||||
</mapper>
|
</mapper>
|
||||||
@@ -36,3 +36,19 @@ export function delUser(id) {
|
|||||||
method: 'delete'
|
method: 'delete'
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 获取用户标签
|
||||||
|
export function getUserTags(userId) {
|
||||||
|
return request({
|
||||||
|
url: '/back/user/tags/' + userId,
|
||||||
|
method: 'get'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取当前登录用户的标签
|
||||||
|
export function getMyTags() {
|
||||||
|
return request({
|
||||||
|
url: '/back/user/myTags',
|
||||||
|
method: 'get'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|||||||
@@ -87,7 +87,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { listUser, updateUserStatus } from "@/api/user/user";
|
import { listUser, updateUserStatus, getUserTags } from "@/api/user/user";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "User",
|
name: "User",
|
||||||
@@ -119,6 +119,20 @@ export default {
|
|||||||
listUser(this.queryParams).then(response => {
|
listUser(this.queryParams).then(response => {
|
||||||
this.userList = response.rows;
|
this.userList = response.rows;
|
||||||
this.total = response.total;
|
this.total = response.total;
|
||||||
|
|
||||||
|
// 获取每个用户的播放标签
|
||||||
|
this.userList.forEach(user => {
|
||||||
|
getUserTags(user.userId).then(tagResponse => {
|
||||||
|
if (tagResponse.code === 200 && tagResponse.data) {
|
||||||
|
this.$set(user, 'playTag', tagResponse.data);
|
||||||
|
} else {
|
||||||
|
this.$set(user, 'playTag', '暂无标签');
|
||||||
|
}
|
||||||
|
}).catch(() => {
|
||||||
|
this.$set(user, 'playTag', '获取失败');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
this.loading = false;
|
this.loading = false;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user