From 5bb159358f3d390f8bc69502293ec4f8a3c41aef Mon Sep 17 00:00:00 2001 From: En Date: Wed, 8 Apr 2026 22:57:03 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20Webhook=E5=90=8C=E6=AD=A5=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E2=80=94=E2=80=94=E5=AE=9E=E7=8E=B0findUserIdByPhone?= =?UTF-8?q?=EF=BC=8C=E8=A1=A5=E5=85=85PROCESSING=E7=8A=B6=E6=80=81coverUrl?= =?UTF-8?q?=E5=90=8C=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. 实现 findUserIdByPhone() 方法(原为 TODO 占位),注入 SysUserMapper 按手机号查询用户 2. updateProcessing() 方法补充 coverUrl 字段同步,AI创作过程中推送的封面图不再被丢弃 3. insertNewWork 中增加 WARN 日志,记录手机号未找到用户或手机号为空的情况 Co-Authored-By: Claude Opus 4.6 --- .../modules/leai/service/LeaiSyncService.java | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/backend-java/src/main/java/com/competition/modules/leai/service/LeaiSyncService.java b/backend-java/src/main/java/com/competition/modules/leai/service/LeaiSyncService.java index 38c1e71..fe90ec3 100644 --- a/backend-java/src/main/java/com/competition/modules/leai/service/LeaiSyncService.java +++ b/backend-java/src/main/java/com/competition/modules/leai/service/LeaiSyncService.java @@ -4,6 +4,8 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.competition.common.enums.Visibility; import com.competition.modules.leai.util.LeaiUtil; +import com.competition.modules.sys.entity.SysUser; +import com.competition.modules.sys.mapper.SysUserMapper; import com.competition.modules.ugc.entity.UgcWork; import com.competition.modules.ugc.entity.UgcWorkPage; import com.competition.modules.ugc.mapper.UgcWorkMapper; @@ -28,6 +30,7 @@ public class LeaiSyncService implements ILeaiSyncService { private final UgcWorkMapper ugcWorkMapper; private final UgcWorkPageMapper ugcWorkPageMapper; private final LeaiApiClient leaiApiClient; + private final SysUserMapper sysUserMapper; /** * V4.0 核心同步逻辑 @@ -128,7 +131,11 @@ public class LeaiSyncService implements ILeaiSyncService { Long userId = findUserIdByPhone(phone); if (userId != null) { work.setUserId(userId); + } else { + log.warn("通过手机号未找到对应用户,作品将无法关联用户: remoteWorkId={}, phone={}", remoteWorkId, phone); } + } else if (phone == null) { + log.warn("Webhook回调中手机号为空,无法关联用户: remoteWorkId={}", remoteWorkId); } ugcWorkMapper.insert(work); @@ -165,6 +172,12 @@ public class LeaiSyncService implements ILeaiSyncService { if (remoteData.containsKey("progressMessage")) { wrapper.set(UgcWork::getProgressMessage, LeaiUtil.toString(remoteData.get("progressMessage"), null)); } + // 同步封面图(AI创作过程中可能推送 coverUrl) + Object coverUrl = remoteData.get("coverUrl"); + if (coverUrl == null) coverUrl = remoteData.get("cover_url"); + if (coverUrl != null) { + wrapper.set(UgcWork::getCoverUrl, coverUrl.toString()); + } wrapper.set(UgcWork::getModifyTime, LocalDateTime.now()); ugcWorkMapper.update(null, wrapper); @@ -269,11 +282,12 @@ public class LeaiSyncService implements ILeaiSyncService { /** * 通过手机号查找用户ID - * 多租户场景:需要确定租户后查找 */ private Long findUserIdByPhone(String phone) { - // TODO: 如果需要按租户隔离,需要传入 orgId(即租户 code/tenant_code)查找租户再查找用户 - // 当前简化处理:直接通过手机号查用户 - return null; // 暂时不自动关联用户,后续通过 phone + orgId(租户 code)查询 + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(SysUser::getPhone, phone) + .last("LIMIT 1"); + SysUser user = sysUserMapper.selectOne(wrapper); + return user != null ? user.getId() : null; } }