refactor(product): 新增平台字段区分安卓与苹果商品

- 在商品实体、VO、Service及Controller中统一增加platform字段
- 查询接口支持按平台(android/apple)过滤商品
- ChatService追加全局companionSystemPrompt配置读取
This commit is contained in:
2026-04-08 09:29:46 +08:00
parent e027918387
commit da3ee94924
7 changed files with 45 additions and 29 deletions

View File

@@ -26,6 +26,8 @@ public class AppConfig {
private LLmModel llmModel = new LLmModel(); private LLmModel llmModel = new LLmModel();
@Data @Data
public static class UserRegisterProperties { public static class UserRegisterProperties {
@@ -64,6 +66,8 @@ public class AppConfig {
//聊天消息最大长度 //聊天消息最大长度
private Integer maxMessageLength = 1000; private Integer maxMessageLength = 1000;
private String companionSystemPrompt = "";
} }
@Data @Data

View File

@@ -31,17 +31,20 @@ public class ProductsController {
private KeyboardProductItemsService productItemsService; private KeyboardProductItemsService productItemsService;
@GetMapping("/detail") @GetMapping("/detail")
@Operation(summary = "查询商品明细", description = "根据商品ID或productId查询商品详情") @Operation(summary = "查询商品明细", description = "根据商品ID或productId查询商品详情通过platform区分平台")
public BaseResponse<KeyboardProductItemRespVO> getProductDetail( public BaseResponse<KeyboardProductItemRespVO> getProductDetail(
@RequestParam(value = "id", required = false) Long id, @RequestParam(value = "id", required = false) Long id,
@RequestParam(value = "productId", required = false) String productId @RequestParam(value = "productId", required = false) String productId,
@RequestParam(value = "platform", required = false) String platform
) { ) {
if (id == null && (productId == null || productId.isBlank())) { if (id == null && (productId == null || productId.isBlank())) {
throw new BusinessException(ErrorCode.PARAMS_ERROR, "id 或 productId 至少传一个"); throw new BusinessException(ErrorCode.PARAMS_ERROR, "id 或 productId 至少传一个");
} }
// 判断平台如果是android返回安卓商品否则默认返回苹果商品
String resolvedPlatform = "android".equalsIgnoreCase(platform) ? "android" : "apple";
KeyboardProductItemRespVO result = (id != null) KeyboardProductItemRespVO result = (id != null)
? productItemsService.getProductDetailById(id) ? productItemsService.getProductDetailById(id, resolvedPlatform)
: productItemsService.getProductDetailByProductId(productId); : productItemsService.getProductDetailByProductId(productId, resolvedPlatform);
return ResultUtils.success(result); return ResultUtils.success(result);
} }

View File

@@ -112,4 +112,8 @@ public class KeyboardProductItems {
@TableField(value = "level") @TableField(value = "level")
@Schema(description = "级别") @Schema(description = "级别")
private Integer level; private Integer level;
@TableField(value = "platform")
@Schema(description = "所属平台")
private String platform;
} }

View File

@@ -45,6 +45,9 @@ public class KeyboardProductItemRespVO {
private String description; private String description;
@Schema(description = "级别") @Schema(description = "级别")
private Integer level; private Integer level;
@Schema(description = "所属平台")
private String platform;
} }

View File

@@ -12,20 +12,22 @@ import java.util.List;
public interface KeyboardProductItemsService extends IService<KeyboardProductItems>{ public interface KeyboardProductItemsService extends IService<KeyboardProductItems>{
/** /**
* 根据主键ID查询商品明细 * 根据主键ID和平台查询商品明细
* *
* @param id 商品主键ID * @param id 商品主键ID
* @param platform 平台标识android / apple
* @return 商品明细(不存在返回 null * @return 商品明细(不存在返回 null
*/ */
KeyboardProductItemRespVO getProductDetailById(Long id); KeyboardProductItemRespVO getProductDetailById(Long id, String platform);
/** /**
* 根据 Apple productId 查询商品明细 * 根据 productId 和平台查询商品明细
* *
* @param productId 商品 productId * @param productId 商品 productId
* @param platform 平台标识android / apple
* @return 商品明细(不存在返回 null * @return 商品明细(不存在返回 null
*/ */
KeyboardProductItemRespVO getProductDetailByProductId(String productId); KeyboardProductItemRespVO getProductDetailByProductId(String productId, String platform);
/** /**
* 根据 productId 获取商品实体 * 根据 productId 获取商品实体

View File

@@ -413,7 +413,7 @@ public class ChatServiceImpl implements ChatService {
if (companion.getStatus() == null || companion.getStatus() != 1) { if (companion.getStatus() == null || companion.getStatus() != 1) {
throw new BusinessException(ErrorCode.PARAMS_ERROR, "AI陪聊角色已下线"); throw new BusinessException(ErrorCode.PARAMS_ERROR, "AI陪聊角色已下线");
} }
String systemPrompt = companion.getSystemPrompt(); String systemPrompt = appConfig.getLlmConfig().getCompanionSystemPrompt() + companion.getSystemPrompt();
String voiceId = companion.getVoiceId(); String voiceId = companion.getVoiceId();
// 获取最近20条聊天记录作为上下文 // 获取最近20条聊天记录作为上下文

View File

@@ -17,45 +17,45 @@ public class KeyboardProductItemsServiceImpl extends ServiceImpl<KeyboardProduct
/** /**
* 根据ID获取产品详情 * 根据ID和平台获取产品详情
* *
* @param id 产品ID * @param id 产品ID
* @return 产品详情响应对象如果ID为空或未找到产品则返回null * @param platform 平台标识android / apple
* @return 产品详情响应对象如果未找到产品则返回null
*/ */
@Override @Override
public KeyboardProductItemRespVO getProductDetailById(Long id) { public KeyboardProductItemRespVO getProductDetailById(Long id, String platform) {
// 参数校验ID不能为空
if (id == null) { if (id == null) {
return null; return null;
} }
// 根据ID查询产品信息 KeyboardProductItems item = this.lambdaQuery()
KeyboardProductItems item = this.getById(id); .eq(KeyboardProductItems::getId, id)
.eq(KeyboardProductItems::getPlatform, platform)
.one();
// 将实体对象转换为响应VO对象并返回
return item == null ? null : BeanUtil.copyProperties(item, KeyboardProductItemRespVO.class); return item == null ? null : BeanUtil.copyProperties(item, KeyboardProductItemRespVO.class);
} }
/** /**
* 根据产品ID获取产品详情 * 根据产品ID和平台获取产品详情
* *
* @param productId 产品ID * @param productId 产品ID
* @return 产品详情响应对象如果产品ID为空或未找到产品则返回null * @param platform 平台标识android / apple
* @return 产品详情响应对象如果未找到产品则返回null
*/ */
@Override @Override
public KeyboardProductItemRespVO getProductDetailByProductId(String productId) { public KeyboardProductItemRespVO getProductDetailByProductId(String productId, String platform) {
// 参数校验产品ID不能为空
if (productId == null || productId.isBlank()) { if (productId == null || productId.isBlank()) {
return null; return null;
} }
// 根据产品ID查询产品信息
KeyboardProductItems item = this.lambdaQuery() KeyboardProductItems item = this.lambdaQuery()
.eq(KeyboardProductItems::getProductId, productId) .eq(KeyboardProductItems::getProductId, productId)
.eq(KeyboardProductItems::getPlatform, platform)
.one(); .one();
// 将实体对象转换为响应VO对象并返回
return item == null ? null : BeanUtil.copyProperties(item, KeyboardProductItemRespVO.class); return item == null ? null : BeanUtil.copyProperties(item, KeyboardProductItemRespVO.class);
} }