dev-chenjiajian #1
@ -186,11 +186,31 @@ public class AppParentAgentActivityService implements IAppParentAgentActivitySer
|
||||
result = parseAiResponse(content);
|
||||
result.setConstellation(request.getConstellation());
|
||||
|
||||
// 先查询该家长是否已有性格测试记录,有则更新,无则新增
|
||||
MpTestChildCharacterEntity existingEntity = mpTestChildCharacterService
|
||||
.lambdaQuery()
|
||||
.eq(MpTestChildCharacterEntity::getParentId, parentId)
|
||||
.orderByDesc(MpTestChildCharacterEntity::getCreateTime)
|
||||
.last("LIMIT 1")
|
||||
.one();
|
||||
|
||||
// 如果AI调用成功则将测试结果保存到数据库中
|
||||
MpTestChildCharacterEntity entity = getCharacterEntity(request, parentId, result);
|
||||
boolean save = mpTestChildCharacterService.save(entity);
|
||||
if (save) {
|
||||
log.info("保存性格测试结果成功");
|
||||
|
||||
boolean saveOrUpdateResult;
|
||||
if (existingEntity != null) {
|
||||
// 如果存在记录,则更新
|
||||
entity.setId(existingEntity.getId());
|
||||
saveOrUpdateResult = mpTestChildCharacterService.updateById(entity);
|
||||
log.info("更新性格测试结果成功,家长ID: {}", parentId);
|
||||
} else {
|
||||
// 如果不存在记录,则新增
|
||||
saveOrUpdateResult = mpTestChildCharacterService.save(entity);
|
||||
log.info("保存性格测试结果成功,家长ID: {}", parentId);
|
||||
}
|
||||
|
||||
if (!saveOrUpdateResult) {
|
||||
log.error("保存或更新性格测试结果失败,家长ID: {}", parentId);
|
||||
}
|
||||
} else {
|
||||
// 如果AI调用失败,返回默认响应
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user