更新AI陪聊角色查询以支持国际化信息
This commit is contained in:
@@ -42,9 +42,17 @@ public class AiCompanionController {
|
|||||||
|
|
||||||
@PostMapping("/page")
|
@PostMapping("/page")
|
||||||
@Operation(summary = "分页查询AI陪聊角色", description = "分页查询已上线的AI陪聊角色列表,包含点赞数、评论数和当前用户点赞状态")
|
@Operation(summary = "分页查询AI陪聊角色", description = "分页查询已上线的AI陪聊角色列表,包含点赞数、评论数和当前用户点赞状态")
|
||||||
public BaseResponse<IPage<AiCompanionVO>> pageList(@RequestBody PageDTO pageDTO) {
|
public BaseResponse<IPage<AiCompanionVO>> pageList(
|
||||||
|
@RequestBody PageDTO pageDTO,
|
||||||
|
@RequestHeader(value = "Accept-Language", required = false) String acceptLanguage
|
||||||
|
) {
|
||||||
Long userId = StpUtil.getLoginIdAsLong();
|
Long userId = StpUtil.getLoginIdAsLong();
|
||||||
IPage<AiCompanionVO> result = aiCompanionService.pageListWithLikeStatus(userId, pageDTO.getPageNum(), pageDTO.getPageSize());
|
IPage<AiCompanionVO> result = aiCompanionService.pageListWithLikeStatus(
|
||||||
|
userId,
|
||||||
|
pageDTO.getPageNum(),
|
||||||
|
pageDTO.getPageSize(),
|
||||||
|
acceptLanguage
|
||||||
|
);
|
||||||
return ResultUtils.success(result);
|
return ResultUtils.success(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -62,28 +70,35 @@ public class AiCompanionController {
|
|||||||
|
|
||||||
@GetMapping("/liked")
|
@GetMapping("/liked")
|
||||||
@Operation(summary = "获取当前用户点赞过的AI角色列表", description = "查询当前用户点赞过的所有AI角色,返回角色详细信息")
|
@Operation(summary = "获取当前用户点赞过的AI角色列表", description = "查询当前用户点赞过的所有AI角色,返回角色详细信息")
|
||||||
public BaseResponse<List<AiCompanionVO>> getLikedCompanions() {
|
public BaseResponse<List<AiCompanionVO>> getLikedCompanions(
|
||||||
|
@RequestHeader(value = "Accept-Language", required = false) String acceptLanguage
|
||||||
|
) {
|
||||||
Long userId = StpUtil.getLoginIdAsLong();
|
Long userId = StpUtil.getLoginIdAsLong();
|
||||||
List<AiCompanionVO> result = aiCompanionService.getLikedCompanions(userId);
|
List<AiCompanionVO> result = aiCompanionService.getLikedCompanions(userId, acceptLanguage);
|
||||||
return ResultUtils.success(result);
|
return ResultUtils.success(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/chatted")
|
@GetMapping("/chatted")
|
||||||
@Operation(summary = "获取当前用户聊过天的AI角色列表", description = "查询当前用户聊过天的所有AI角色,返回角色详细信息")
|
@Operation(summary = "获取当前用户聊过天的AI角色列表", description = "查询当前用户聊过天的所有AI角色,返回角色详细信息")
|
||||||
public BaseResponse<List<AiCompanionVO>> getChattedCompanions() {
|
public BaseResponse<List<AiCompanionVO>> getChattedCompanions(
|
||||||
|
@RequestHeader(value = "Accept-Language", required = false) String acceptLanguage
|
||||||
|
) {
|
||||||
Long userId = StpUtil.getLoginIdAsLong();
|
Long userId = StpUtil.getLoginIdAsLong();
|
||||||
List<AiCompanionVO> result = aiCompanionService.getChattedCompanions(userId);
|
List<AiCompanionVO> result = aiCompanionService.getChattedCompanions(userId, acceptLanguage);
|
||||||
return ResultUtils.success(result);
|
return ResultUtils.success(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/{companionId}")
|
@GetMapping("/{companionId}")
|
||||||
@Operation(summary = "根据ID获取AI角色详情", description = "根据AI角色ID查询角色详细信息,包含点赞数、评论数和当前用户点赞状态")
|
@Operation(summary = "根据ID获取AI角色详情", description = "根据AI角色ID查询角色详细信息,包含点赞数、评论数和当前用户点赞状态")
|
||||||
public BaseResponse<AiCompanionVO> getCompanionById(@PathVariable Long companionId) {
|
public BaseResponse<AiCompanionVO> getCompanionById(
|
||||||
|
@PathVariable Long companionId,
|
||||||
|
@RequestHeader(value = "Accept-Language", required = false) String acceptLanguage
|
||||||
|
) {
|
||||||
if (companionId == null) {
|
if (companionId == null) {
|
||||||
throw new BusinessException(ErrorCode.COMPANION_ID_EMPTY);
|
throw new BusinessException(ErrorCode.COMPANION_ID_EMPTY);
|
||||||
}
|
}
|
||||||
Long userId = StpUtil.getLoginIdAsLong();
|
Long userId = StpUtil.getLoginIdAsLong();
|
||||||
AiCompanionVO result = aiCompanionService.getCompanionById(userId, companionId);
|
AiCompanionVO result = aiCompanionService.getCompanionById(userId, companionId, acceptLanguage);
|
||||||
return ResultUtils.success(result);
|
return ResultUtils.success(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package com.yolo.keyborad.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.yolo.keyborad.model.entity.KeyboardAiCompanionI18n;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @author: ziin
|
||||||
|
* @date: 2026/4/2 09:35
|
||||||
|
*/
|
||||||
|
|
||||||
|
public interface KeyboardAiCompanionI18nMapper extends BaseMapper<KeyboardAiCompanionI18n> {
|
||||||
|
}
|
||||||
@@ -27,12 +27,6 @@ public class KeyboardAiCompanion {
|
|||||||
@Schema(description="陪聊角色唯一ID")
|
@Schema(description="陪聊角色唯一ID")
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
/**
|
|
||||||
* 角色名称(展示用,如:Katie Leona)
|
|
||||||
*/
|
|
||||||
@TableField(value = "\"name\"")
|
|
||||||
@Schema(description="角色名称(展示用,如:Katie Leona)")
|
|
||||||
private String name;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 角色头像URL,用于列表页和聊天页
|
* 角色头像URL,用于列表页和聊天页
|
||||||
@@ -62,20 +56,6 @@ public class KeyboardAiCompanion {
|
|||||||
@Schema(description="角色年龄段描述(如:20s、25-30)")
|
@Schema(description="角色年龄段描述(如:20s、25-30)")
|
||||||
private String ageRange;
|
private String ageRange;
|
||||||
|
|
||||||
/**
|
|
||||||
* 一句话人设描述,用于卡片或列表展示
|
|
||||||
*/
|
|
||||||
@TableField(value = "short_desc")
|
|
||||||
@Schema(description="一句话人设描述,用于卡片或列表展示")
|
|
||||||
private String shortDesc;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 角色详细介绍文案,用于角色详情页
|
|
||||||
*/
|
|
||||||
@TableField(value = "intro_text")
|
|
||||||
@Schema(description="角色详细介绍文案,用于角色详情页")
|
|
||||||
private String introText;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 角色性格标签数组(如:温柔、黏人、治愈)
|
* 角色性格标签数组(如:温柔、黏人、治愈)
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -0,0 +1,78 @@
|
|||||||
|
package com.yolo.keyborad.model.entity;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import java.util.Date;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @author: ziin
|
||||||
|
* @date: 2026/4/2 09:35
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* AI陪聊角色国际化表,用于存储不同语言下的角色名称、一句话描述和详细介绍
|
||||||
|
*/
|
||||||
|
@Schema(description="AI陪聊角色国际化表,用于存储不同语言下的角色名称、一句话描述和详细介绍")
|
||||||
|
@Data
|
||||||
|
@TableName(value = "keyboard_ai_companion_i18n")
|
||||||
|
public class KeyboardAiCompanionI18n {
|
||||||
|
/**
|
||||||
|
* 主键ID
|
||||||
|
*/
|
||||||
|
@TableId(value = "id", type = IdType.AUTO)
|
||||||
|
@Schema(description="主键ID")
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 陪聊角色主表ID,对应 keyboard_ai_companion.id
|
||||||
|
*/
|
||||||
|
@TableField(value = "companion_id")
|
||||||
|
@Schema(description="陪聊角色主表ID,对应 keyboard_ai_companion.id")
|
||||||
|
private Long companionId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 语言标识,如 zh-CN、en-US、ja-JP
|
||||||
|
*/
|
||||||
|
@TableField(value = "\"locale\"")
|
||||||
|
@Schema(description="语言标识,如 zh-CN、en-US、ja-JP")
|
||||||
|
private String locale;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 角色名称(多语言)
|
||||||
|
*/
|
||||||
|
@TableField(value = "\"name\"")
|
||||||
|
@Schema(description="角色名称(多语言)")
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 一句话人设描述(多语言)
|
||||||
|
*/
|
||||||
|
@TableField(value = "short_desc")
|
||||||
|
@Schema(description="一句话人设描述(多语言)")
|
||||||
|
private String shortDesc;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 角色详细介绍文案(多语言)
|
||||||
|
*/
|
||||||
|
@TableField(value = "intro_text")
|
||||||
|
@Schema(description="角色详细介绍文案(多语言)")
|
||||||
|
private String introText;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建时间
|
||||||
|
*/
|
||||||
|
@TableField(value = "created_at")
|
||||||
|
@Schema(description="创建时间")
|
||||||
|
private Date createdAt;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新时间
|
||||||
|
*/
|
||||||
|
@TableField(value = "updated_at")
|
||||||
|
@Schema(description="更新时间")
|
||||||
|
private Date updatedAt;
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package com.yolo.keyborad.service;
|
||||||
|
|
||||||
|
import com.yolo.keyborad.model.entity.KeyboardAiCompanionI18n;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
/*
|
||||||
|
* @author: ziin
|
||||||
|
* @date: 2026/4/2 09:35
|
||||||
|
*/
|
||||||
|
|
||||||
|
public interface KeyboardAiCompanionI18nService extends IService<KeyboardAiCompanionI18n>{
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -20,7 +20,11 @@ public interface KeyboardAiCompanionService extends IService<KeyboardAiCompanion
|
|||||||
* @param pageSize 每页数量
|
* @param pageSize 每页数量
|
||||||
* @return 分页结果
|
* @return 分页结果
|
||||||
*/
|
*/
|
||||||
IPage<AiCompanionVO> pageList(Integer pageNum, Integer pageSize);
|
IPage<AiCompanionVO> pageList(Integer pageNum, Integer pageSize, String acceptLanguage);
|
||||||
|
|
||||||
|
default IPage<AiCompanionVO> pageList(Integer pageNum, Integer pageSize) {
|
||||||
|
return pageList(pageNum, pageSize, null);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 分页查询已上线的AI陪聊角色(带当前用户点赞状态)
|
* 分页查询已上线的AI陪聊角色(带当前用户点赞状态)
|
||||||
@@ -30,7 +34,11 @@ public interface KeyboardAiCompanionService extends IService<KeyboardAiCompanion
|
|||||||
* @param pageSize 每页数量
|
* @param pageSize 每页数量
|
||||||
* @return 分页结果
|
* @return 分页结果
|
||||||
*/
|
*/
|
||||||
IPage<AiCompanionVO> pageListWithLikeStatus(Long userId, Integer pageNum, Integer pageSize);
|
IPage<AiCompanionVO> pageListWithLikeStatus(Long userId, Integer pageNum, Integer pageSize, String acceptLanguage);
|
||||||
|
|
||||||
|
default IPage<AiCompanionVO> pageListWithLikeStatus(Long userId, Integer pageNum, Integer pageSize) {
|
||||||
|
return pageListWithLikeStatus(userId, pageNum, pageSize, null);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据AI人设ID获取系统提示词
|
* 根据AI人设ID获取系统提示词
|
||||||
@@ -46,7 +54,11 @@ public interface KeyboardAiCompanionService extends IService<KeyboardAiCompanion
|
|||||||
* @param userId 用户ID
|
* @param userId 用户ID
|
||||||
* @return 点赞过的AI角色列表
|
* @return 点赞过的AI角色列表
|
||||||
*/
|
*/
|
||||||
List<AiCompanionVO> getLikedCompanions(Long userId);
|
List<AiCompanionVO> getLikedCompanions(Long userId, String acceptLanguage);
|
||||||
|
|
||||||
|
default List<AiCompanionVO> getLikedCompanions(Long userId) {
|
||||||
|
return getLikedCompanions(userId, null);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取用户聊过天的AI角色列表
|
* 获取用户聊过天的AI角色列表
|
||||||
@@ -54,7 +66,11 @@ public interface KeyboardAiCompanionService extends IService<KeyboardAiCompanion
|
|||||||
* @param userId 用户ID
|
* @param userId 用户ID
|
||||||
* @return 聊过天的AI角色列表
|
* @return 聊过天的AI角色列表
|
||||||
*/
|
*/
|
||||||
List<AiCompanionVO> getChattedCompanions(Long userId);
|
List<AiCompanionVO> getChattedCompanions(Long userId, String acceptLanguage);
|
||||||
|
|
||||||
|
default List<AiCompanionVO> getChattedCompanions(Long userId) {
|
||||||
|
return getChattedCompanions(userId, null);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据ID获取AI角色详情(带点赞数、评论数和当前用户点赞状态)
|
* 根据ID获取AI角色详情(带点赞数、评论数和当前用户点赞状态)
|
||||||
@@ -63,5 +79,9 @@ public interface KeyboardAiCompanionService extends IService<KeyboardAiCompanion
|
|||||||
* @param companionId AI角色ID
|
* @param companionId AI角色ID
|
||||||
* @return AI角色详情
|
* @return AI角色详情
|
||||||
*/
|
*/
|
||||||
AiCompanionVO getCompanionById(Long userId, Long companionId);
|
AiCompanionVO getCompanionById(Long userId, Long companionId, String acceptLanguage);
|
||||||
|
|
||||||
|
default AiCompanionVO getCompanionById(Long userId, Long companionId) {
|
||||||
|
return getCompanionById(userId, companionId, null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
package com.yolo.keyborad.service.impl;
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import java.util.List;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.yolo.keyborad.mapper.KeyboardAiCompanionI18nMapper;
|
||||||
|
import com.yolo.keyborad.model.entity.KeyboardAiCompanionI18n;
|
||||||
|
import com.yolo.keyborad.service.KeyboardAiCompanionI18nService;
|
||||||
|
/*
|
||||||
|
* @author: ziin
|
||||||
|
* @date: 2026/4/2 09:35
|
||||||
|
*/
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class KeyboardAiCompanionI18nServiceImpl extends ServiceImpl<KeyboardAiCompanionI18nMapper, KeyboardAiCompanionI18n> implements KeyboardAiCompanionI18nService{
|
||||||
|
|
||||||
|
}
|
||||||
@@ -4,21 +4,26 @@ import cn.hutool.core.bean.BeanUtil;
|
|||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import com.yolo.keyborad.mapper.KeyboardAiCompanionI18nMapper;
|
||||||
import com.yolo.keyborad.common.ErrorCode;
|
import com.yolo.keyborad.common.ErrorCode;
|
||||||
import com.yolo.keyborad.exception.BusinessException;
|
import com.yolo.keyborad.exception.BusinessException;
|
||||||
import com.yolo.keyborad.model.entity.KeyboardAiCompanionComment;
|
import com.yolo.keyborad.model.entity.KeyboardAiCompanionComment;
|
||||||
|
import com.yolo.keyborad.model.entity.KeyboardAiCompanionI18n;
|
||||||
import com.yolo.keyborad.model.entity.KeyboardAiCompanionLike;
|
import com.yolo.keyborad.model.entity.KeyboardAiCompanionLike;
|
||||||
import com.yolo.keyborad.model.vo.AiCompanionVO;
|
import com.yolo.keyborad.model.vo.AiCompanionVO;
|
||||||
import com.yolo.keyborad.service.KeyboardAiCompanionCommentService;
|
import com.yolo.keyborad.service.KeyboardAiCompanionCommentService;
|
||||||
import com.yolo.keyborad.service.KeyboardAiCompanionLikeService;
|
import com.yolo.keyborad.service.KeyboardAiCompanionLikeService;
|
||||||
import com.yolo.keyborad.service.KeyboardAiChatMessageService;
|
import com.yolo.keyborad.service.KeyboardAiChatMessageService;
|
||||||
|
import com.yolo.keyborad.utils.RequestLocaleUtils;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import com.yolo.keyborad.model.entity.KeyboardAiCompanion;
|
import com.yolo.keyborad.model.entity.KeyboardAiCompanion;
|
||||||
import com.yolo.keyborad.mapper.KeyboardAiCompanionMapper;
|
import com.yolo.keyborad.mapper.KeyboardAiCompanionMapper;
|
||||||
import com.yolo.keyborad.service.KeyboardAiCompanionService;
|
import com.yolo.keyborad.service.KeyboardAiCompanionService;
|
||||||
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@@ -40,8 +45,11 @@ public class KeyboardAiCompanionServiceImpl extends ServiceImpl<KeyboardAiCompan
|
|||||||
@Resource
|
@Resource
|
||||||
private KeyboardAiChatMessageService chatMessageService;
|
private KeyboardAiChatMessageService chatMessageService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private KeyboardAiCompanionI18nMapper keyboardAiCompanionI18nMapper;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IPage<AiCompanionVO> pageList(Integer pageNum, Integer pageSize) {
|
public IPage<AiCompanionVO> pageList(Integer pageNum, Integer pageSize, String acceptLanguage) {
|
||||||
Page<KeyboardAiCompanion> page = new Page<>(pageNum, pageSize);
|
Page<KeyboardAiCompanion> page = new Page<>(pageNum, pageSize);
|
||||||
LambdaQueryWrapper<KeyboardAiCompanion> queryWrapper = new LambdaQueryWrapper<>();
|
LambdaQueryWrapper<KeyboardAiCompanion> queryWrapper = new LambdaQueryWrapper<>();
|
||||||
queryWrapper.eq(KeyboardAiCompanion::getStatus, 1)
|
queryWrapper.eq(KeyboardAiCompanion::getStatus, 1)
|
||||||
@@ -54,6 +62,7 @@ public class KeyboardAiCompanionServiceImpl extends ServiceImpl<KeyboardAiCompan
|
|||||||
List<Long> companionIds = entityPage.getRecords().stream()
|
List<Long> companionIds = entityPage.getRecords().stream()
|
||||||
.map(KeyboardAiCompanion::getId)
|
.map(KeyboardAiCompanion::getId)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
Map<Long, KeyboardAiCompanionI18n> i18nMap = getCompanionI18nMap(companionIds, acceptLanguage);
|
||||||
|
|
||||||
// 批量统计点赞数
|
// 批量统计点赞数
|
||||||
Map<Long, Long> likeCountMap = Map.of();
|
Map<Long, Long> likeCountMap = Map.of();
|
||||||
@@ -81,7 +90,7 @@ public class KeyboardAiCompanionServiceImpl extends ServiceImpl<KeyboardAiCompan
|
|||||||
Map<Long, Long> finalLikeCountMap = likeCountMap;
|
Map<Long, Long> finalLikeCountMap = likeCountMap;
|
||||||
Map<Long, Long> finalCommentCountMap = commentCountMap;
|
Map<Long, Long> finalCommentCountMap = commentCountMap;
|
||||||
return entityPage.convert(entity -> {
|
return entityPage.convert(entity -> {
|
||||||
AiCompanionVO vo = BeanUtil.copyProperties(entity, AiCompanionVO.class);
|
AiCompanionVO vo = toAiCompanionVO(entity, i18nMap);
|
||||||
vo.setLikeCount(finalLikeCountMap.getOrDefault(entity.getId(), 0L).intValue());
|
vo.setLikeCount(finalLikeCountMap.getOrDefault(entity.getId(), 0L).intValue());
|
||||||
vo.setCommentCount(finalCommentCountMap.getOrDefault(entity.getId(), 0L).intValue());
|
vo.setCommentCount(finalCommentCountMap.getOrDefault(entity.getId(), 0L).intValue());
|
||||||
return vo;
|
return vo;
|
||||||
@@ -89,7 +98,7 @@ public class KeyboardAiCompanionServiceImpl extends ServiceImpl<KeyboardAiCompan
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IPage<AiCompanionVO> pageListWithLikeStatus(Long userId, Integer pageNum, Integer pageSize) {
|
public IPage<AiCompanionVO> pageListWithLikeStatus(Long userId, Integer pageNum, Integer pageSize, String acceptLanguage) {
|
||||||
Page<KeyboardAiCompanion> page = new Page<>(pageNum, pageSize);
|
Page<KeyboardAiCompanion> page = new Page<>(pageNum, pageSize);
|
||||||
LambdaQueryWrapper<KeyboardAiCompanion> queryWrapper = new LambdaQueryWrapper<>();
|
LambdaQueryWrapper<KeyboardAiCompanion> queryWrapper = new LambdaQueryWrapper<>();
|
||||||
queryWrapper.eq(KeyboardAiCompanion::getStatus, 1)
|
queryWrapper.eq(KeyboardAiCompanion::getStatus, 1)
|
||||||
@@ -103,6 +112,7 @@ public class KeyboardAiCompanionServiceImpl extends ServiceImpl<KeyboardAiCompan
|
|||||||
List<Long> companionIds = entityPage.getRecords().stream()
|
List<Long> companionIds = entityPage.getRecords().stream()
|
||||||
.map(KeyboardAiCompanion::getId)
|
.map(KeyboardAiCompanion::getId)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
Map<Long, KeyboardAiCompanionI18n> i18nMap = getCompanionI18nMap(companionIds, acceptLanguage);
|
||||||
|
|
||||||
// 批量统计点赞数
|
// 批量统计点赞数
|
||||||
Map<Long, Long> likeCountMap = Map.of();
|
Map<Long, Long> likeCountMap = Map.of();
|
||||||
@@ -133,7 +143,7 @@ public class KeyboardAiCompanionServiceImpl extends ServiceImpl<KeyboardAiCompan
|
|||||||
Map<Long, Long> finalLikeCountMap = likeCountMap;
|
Map<Long, Long> finalLikeCountMap = likeCountMap;
|
||||||
Map<Long, Long> finalCommentCountMap = commentCountMap;
|
Map<Long, Long> finalCommentCountMap = commentCountMap;
|
||||||
return entityPage.convert(entity -> {
|
return entityPage.convert(entity -> {
|
||||||
AiCompanionVO vo = BeanUtil.copyProperties(entity, AiCompanionVO.class);
|
AiCompanionVO vo = toAiCompanionVO(entity, i18nMap);
|
||||||
vo.setLikeCount(finalLikeCountMap.getOrDefault(entity.getId(), 0L).intValue());
|
vo.setLikeCount(finalLikeCountMap.getOrDefault(entity.getId(), 0L).intValue());
|
||||||
vo.setCommentCount(finalCommentCountMap.getOrDefault(entity.getId(), 0L).intValue());
|
vo.setCommentCount(finalCommentCountMap.getOrDefault(entity.getId(), 0L).intValue());
|
||||||
vo.setLiked(likedCompanionIds.contains(entity.getId()));
|
vo.setLiked(likedCompanionIds.contains(entity.getId()));
|
||||||
@@ -154,7 +164,7 @@ public class KeyboardAiCompanionServiceImpl extends ServiceImpl<KeyboardAiCompan
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<AiCompanionVO> getLikedCompanions(Long userId) {
|
public List<AiCompanionVO> getLikedCompanions(Long userId, String acceptLanguage) {
|
||||||
// 获取用户点赞过的所有AI角色ID
|
// 获取用户点赞过的所有AI角色ID
|
||||||
List<Long> likedCompanionIds = companionLikeService.getAllLikedCompanionIds(userId);
|
List<Long> likedCompanionIds = companionLikeService.getAllLikedCompanionIds(userId);
|
||||||
if (likedCompanionIds.isEmpty()) {
|
if (likedCompanionIds.isEmpty()) {
|
||||||
@@ -178,6 +188,7 @@ public class KeyboardAiCompanionServiceImpl extends ServiceImpl<KeyboardAiCompan
|
|||||||
List<Long> companionIds = companions.stream()
|
List<Long> companionIds = companions.stream()
|
||||||
.map(KeyboardAiCompanion::getId)
|
.map(KeyboardAiCompanion::getId)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
Map<Long, KeyboardAiCompanionI18n> i18nMap = getCompanionI18nMap(companionIds, acceptLanguage);
|
||||||
|
|
||||||
// 批量统计点赞数
|
// 批量统计点赞数
|
||||||
LambdaQueryWrapper<KeyboardAiCompanionLike> likeWrapper = new LambdaQueryWrapper<>();
|
LambdaQueryWrapper<KeyboardAiCompanionLike> likeWrapper = new LambdaQueryWrapper<>();
|
||||||
@@ -197,7 +208,7 @@ public class KeyboardAiCompanionServiceImpl extends ServiceImpl<KeyboardAiCompan
|
|||||||
|
|
||||||
// 转换为VO并填充统计数据
|
// 转换为VO并填充统计数据
|
||||||
return companions.stream().map(entity -> {
|
return companions.stream().map(entity -> {
|
||||||
AiCompanionVO vo = BeanUtil.copyProperties(entity, AiCompanionVO.class);
|
AiCompanionVO vo = toAiCompanionVO(entity, i18nMap);
|
||||||
vo.setLikeCount(likeCountMap.getOrDefault(entity.getId(), 0L).intValue());
|
vo.setLikeCount(likeCountMap.getOrDefault(entity.getId(), 0L).intValue());
|
||||||
vo.setCommentCount(commentCountMap.getOrDefault(entity.getId(), 0L).intValue());
|
vo.setCommentCount(commentCountMap.getOrDefault(entity.getId(), 0L).intValue());
|
||||||
vo.setLiked(true); // 用户已点赞
|
vo.setLiked(true); // 用户已点赞
|
||||||
@@ -206,7 +217,7 @@ public class KeyboardAiCompanionServiceImpl extends ServiceImpl<KeyboardAiCompan
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<AiCompanionVO> getChattedCompanions(Long userId) {
|
public List<AiCompanionVO> getChattedCompanions(Long userId, String acceptLanguage) {
|
||||||
// 获取用户聊过天的所有AI角色ID
|
// 获取用户聊过天的所有AI角色ID
|
||||||
List<Long> chattedCompanionIds = chatMessageService.getChattedCompanionIds(userId);
|
List<Long> chattedCompanionIds = chatMessageService.getChattedCompanionIds(userId);
|
||||||
if (chattedCompanionIds.isEmpty()) {
|
if (chattedCompanionIds.isEmpty()) {
|
||||||
@@ -228,6 +239,7 @@ public class KeyboardAiCompanionServiceImpl extends ServiceImpl<KeyboardAiCompan
|
|||||||
List<Long> companionIds = companions.stream()
|
List<Long> companionIds = companions.stream()
|
||||||
.map(KeyboardAiCompanion::getId)
|
.map(KeyboardAiCompanion::getId)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
Map<Long, KeyboardAiCompanionI18n> i18nMap = getCompanionI18nMap(companionIds, acceptLanguage);
|
||||||
|
|
||||||
// 批量统计点赞数
|
// 批量统计点赞数
|
||||||
LambdaQueryWrapper<KeyboardAiCompanionLike> likeWrapper = new LambdaQueryWrapper<>();
|
LambdaQueryWrapper<KeyboardAiCompanionLike> likeWrapper = new LambdaQueryWrapper<>();
|
||||||
@@ -256,7 +268,7 @@ public class KeyboardAiCompanionServiceImpl extends ServiceImpl<KeyboardAiCompan
|
|||||||
.filter(companionMap::containsKey)
|
.filter(companionMap::containsKey)
|
||||||
.map(id -> {
|
.map(id -> {
|
||||||
KeyboardAiCompanion entity = companionMap.get(id);
|
KeyboardAiCompanion entity = companionMap.get(id);
|
||||||
AiCompanionVO vo = BeanUtil.copyProperties(entity, AiCompanionVO.class);
|
AiCompanionVO vo = toAiCompanionVO(entity, i18nMap);
|
||||||
vo.setLikeCount(likeCountMap.getOrDefault(entity.getId(), 0L).intValue());
|
vo.setLikeCount(likeCountMap.getOrDefault(entity.getId(), 0L).intValue());
|
||||||
vo.setCommentCount(commentCountMap.getOrDefault(entity.getId(), 0L).intValue());
|
vo.setCommentCount(commentCountMap.getOrDefault(entity.getId(), 0L).intValue());
|
||||||
vo.setLiked(likedCompanionIds.contains(entity.getId()));
|
vo.setLiked(likedCompanionIds.contains(entity.getId()));
|
||||||
@@ -265,7 +277,7 @@ public class KeyboardAiCompanionServiceImpl extends ServiceImpl<KeyboardAiCompan
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AiCompanionVO getCompanionById(Long userId, Long companionId) {
|
public AiCompanionVO getCompanionById(Long userId, Long companionId, String acceptLanguage) {
|
||||||
// 查询AI角色
|
// 查询AI角色
|
||||||
KeyboardAiCompanion companion = this.getById(companionId);
|
KeyboardAiCompanion companion = this.getById(companionId);
|
||||||
if (companion == null) {
|
if (companion == null) {
|
||||||
@@ -291,11 +303,44 @@ public class KeyboardAiCompanionServiceImpl extends ServiceImpl<KeyboardAiCompan
|
|||||||
boolean liked = companionLikeService.hasLiked(userId, companionId);
|
boolean liked = companionLikeService.hasLiked(userId, companionId);
|
||||||
|
|
||||||
// 转换为VO
|
// 转换为VO
|
||||||
AiCompanionVO vo = BeanUtil.copyProperties(companion, AiCompanionVO.class);
|
Map<Long, KeyboardAiCompanionI18n> i18nMap = getCompanionI18nMap(List.of(companionId), acceptLanguage);
|
||||||
|
AiCompanionVO vo = toAiCompanionVO(companion, i18nMap);
|
||||||
vo.setLikeCount((int) likeCount);
|
vo.setLikeCount((int) likeCount);
|
||||||
vo.setCommentCount((int) commentCount);
|
vo.setCommentCount((int) commentCount);
|
||||||
vo.setLiked(liked);
|
vo.setLiked(liked);
|
||||||
|
|
||||||
return vo;
|
return vo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private AiCompanionVO toAiCompanionVO(KeyboardAiCompanion entity, Map<Long, KeyboardAiCompanionI18n> i18nMap) {
|
||||||
|
AiCompanionVO vo = BeanUtil.copyProperties(entity, AiCompanionVO.class);
|
||||||
|
KeyboardAiCompanionI18n i18n = i18nMap.get(entity.getId());
|
||||||
|
if (i18n == null) {
|
||||||
|
return vo;
|
||||||
|
}
|
||||||
|
vo.setName(i18n.getName());
|
||||||
|
vo.setShortDesc(i18n.getShortDesc());
|
||||||
|
vo.setIntroText(i18n.getIntroText());
|
||||||
|
return vo;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Map<Long, KeyboardAiCompanionI18n> getCompanionI18nMap(List<Long> companionIds, String acceptLanguage) {
|
||||||
|
String locale = RequestLocaleUtils.resolveLanguage(acceptLanguage);
|
||||||
|
if (companionIds == null || companionIds.isEmpty() || !StringUtils.hasText(locale)) {
|
||||||
|
return Collections.emptyMap();
|
||||||
|
}
|
||||||
|
List<KeyboardAiCompanionI18n> i18nList = keyboardAiCompanionI18nMapper.selectList(
|
||||||
|
new LambdaQueryWrapper<KeyboardAiCompanionI18n>()
|
||||||
|
.in(KeyboardAiCompanionI18n::getCompanionId, companionIds)
|
||||||
|
.eq(KeyboardAiCompanionI18n::getLocale, locale)
|
||||||
|
);
|
||||||
|
if (i18nList == null || i18nList.isEmpty()) {
|
||||||
|
return Collections.emptyMap();
|
||||||
|
}
|
||||||
|
return i18nList.stream().collect(Collectors.toMap(
|
||||||
|
KeyboardAiCompanionI18n::getCompanionId,
|
||||||
|
item -> item,
|
||||||
|
(left, right) -> left
|
||||||
|
));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
20
src/main/resources/mapper/KeyboardAiCompanionI18nMapper.xml
Normal file
20
src/main/resources/mapper/KeyboardAiCompanionI18nMapper.xml
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<mapper namespace="com.yolo.keyborad.mapper.KeyboardAiCompanionI18nMapper">
|
||||||
|
<resultMap id="BaseResultMap" type="com.yolo.keyborad.model.entity.KeyboardAiCompanionI18n">
|
||||||
|
<!--@mbg.generated-->
|
||||||
|
<!--@Table keyboard_ai_companion_i18n-->
|
||||||
|
<id column="id" jdbcType="BIGINT" property="id" />
|
||||||
|
<result column="companion_id" jdbcType="BIGINT" property="companionId" />
|
||||||
|
<result column="locale" jdbcType="VARCHAR" property="locale" />
|
||||||
|
<result column="name" jdbcType="VARCHAR" property="name" />
|
||||||
|
<result column="short_desc" jdbcType="VARCHAR" property="shortDesc" />
|
||||||
|
<result column="intro_text" jdbcType="VARCHAR" property="introText" />
|
||||||
|
<result column="created_at" jdbcType="TIMESTAMP" property="createdAt" />
|
||||||
|
<result column="updated_at" jdbcType="TIMESTAMP" property="updatedAt" />
|
||||||
|
</resultMap>
|
||||||
|
<sql id="Base_Column_List">
|
||||||
|
<!--@mbg.generated-->
|
||||||
|
id, companion_id, "locale", "name", short_desc, intro_text, created_at, updated_at
|
||||||
|
</sql>
|
||||||
|
</mapper>
|
||||||
@@ -5,13 +5,10 @@
|
|||||||
<!--@mbg.generated-->
|
<!--@mbg.generated-->
|
||||||
<!--@Table keyboard_ai_companion-->
|
<!--@Table keyboard_ai_companion-->
|
||||||
<id column="id" jdbcType="BIGINT" property="id" />
|
<id column="id" jdbcType="BIGINT" property="id" />
|
||||||
<result column="name" jdbcType="VARCHAR" property="name" />
|
|
||||||
<result column="avatar_url" jdbcType="VARCHAR" property="avatarUrl" />
|
<result column="avatar_url" jdbcType="VARCHAR" property="avatarUrl" />
|
||||||
<result column="cover_image_url" jdbcType="VARCHAR" property="coverImageUrl" />
|
<result column="cover_image_url" jdbcType="VARCHAR" property="coverImageUrl" />
|
||||||
<result column="gender" jdbcType="VARCHAR" property="gender" />
|
<result column="gender" jdbcType="VARCHAR" property="gender" />
|
||||||
<result column="age_range" jdbcType="VARCHAR" property="ageRange" />
|
<result column="age_range" jdbcType="VARCHAR" property="ageRange" />
|
||||||
<result column="short_desc" jdbcType="VARCHAR" property="shortDesc" />
|
|
||||||
<result column="intro_text" jdbcType="VARCHAR" property="introText" />
|
|
||||||
<result column="personality_tags" jdbcType="VARCHAR" property="personalityTags" />
|
<result column="personality_tags" jdbcType="VARCHAR" property="personalityTags" />
|
||||||
<result column="speaking_style" jdbcType="VARCHAR" property="speakingStyle" />
|
<result column="speaking_style" jdbcType="VARCHAR" property="speakingStyle" />
|
||||||
<result column="system_prompt" jdbcType="VARCHAR" property="systemPrompt" />
|
<result column="system_prompt" jdbcType="VARCHAR" property="systemPrompt" />
|
||||||
@@ -24,7 +21,7 @@
|
|||||||
</resultMap>
|
</resultMap>
|
||||||
<sql id="Base_Column_List">
|
<sql id="Base_Column_List">
|
||||||
<!--@mbg.generated-->
|
<!--@mbg.generated-->
|
||||||
id, "name", avatar_url, cover_image_url, gender, age_range, short_desc, intro_text,
|
id, avatar_url, cover_image_url, gender, age_range,
|
||||||
personality_tags, speaking_style, system_prompt, "status", visibility, sort_order,
|
personality_tags, speaking_style, system_prompt, "status", visibility, sort_order,
|
||||||
popularity_score, created_at, updated_at
|
popularity_score, created_at, updated_at
|
||||||
</sql>
|
</sql>
|
||||||
|
|||||||
Reference in New Issue
Block a user