fix: Webhook同步修复——实现findUserIdByPhone,补充PROCESSING状态coverUrl同步

1. 实现 findUserIdByPhone() 方法(原为 TODO 占位),注入 SysUserMapper 按手机号查询用户
2. updateProcessing() 方法补充 coverUrl 字段同步,AI创作过程中推送的封面图不再被丢弃
3. insertNewWork 中增加 WARN 日志,记录手机号未找到用户或手机号为空的情况

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
En 2026-04-08 22:57:03 +08:00
parent 6365dd8dd0
commit 5bb159358f

View File

@ -4,6 +4,8 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.competition.common.enums.Visibility; import com.competition.common.enums.Visibility;
import com.competition.modules.leai.util.LeaiUtil; 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.UgcWork;
import com.competition.modules.ugc.entity.UgcWorkPage; import com.competition.modules.ugc.entity.UgcWorkPage;
import com.competition.modules.ugc.mapper.UgcWorkMapper; import com.competition.modules.ugc.mapper.UgcWorkMapper;
@ -28,6 +30,7 @@ public class LeaiSyncService implements ILeaiSyncService {
private final UgcWorkMapper ugcWorkMapper; private final UgcWorkMapper ugcWorkMapper;
private final UgcWorkPageMapper ugcWorkPageMapper; private final UgcWorkPageMapper ugcWorkPageMapper;
private final LeaiApiClient leaiApiClient; private final LeaiApiClient leaiApiClient;
private final SysUserMapper sysUserMapper;
/** /**
* V4.0 核心同步逻辑 * V4.0 核心同步逻辑
@ -128,7 +131,11 @@ public class LeaiSyncService implements ILeaiSyncService {
Long userId = findUserIdByPhone(phone); Long userId = findUserIdByPhone(phone);
if (userId != null) { if (userId != null) {
work.setUserId(userId); work.setUserId(userId);
} else {
log.warn("通过手机号未找到对应用户,作品将无法关联用户: remoteWorkId={}, phone={}", remoteWorkId, phone);
} }
} else if (phone == null) {
log.warn("Webhook回调中手机号为空无法关联用户: remoteWorkId={}", remoteWorkId);
} }
ugcWorkMapper.insert(work); ugcWorkMapper.insert(work);
@ -165,6 +172,12 @@ public class LeaiSyncService implements ILeaiSyncService {
if (remoteData.containsKey("progressMessage")) { if (remoteData.containsKey("progressMessage")) {
wrapper.set(UgcWork::getProgressMessage, LeaiUtil.toString(remoteData.get("progressMessage"), null)); 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()); wrapper.set(UgcWork::getModifyTime, LocalDateTime.now());
ugcWorkMapper.update(null, wrapper); ugcWorkMapper.update(null, wrapper);
@ -269,11 +282,12 @@ public class LeaiSyncService implements ILeaiSyncService {
/** /**
* 通过手机号查找用户ID * 通过手机号查找用户ID
* 多租户场景需要确定租户后查找
*/ */
private Long findUserIdByPhone(String phone) { private Long findUserIdByPhone(String phone) {
// TODO: 如果需要按租户隔离需要传入 orgId即租户 code/tenant_code查找租户再查找用户 LambdaQueryWrapper<SysUser> wrapper = new LambdaQueryWrapper<>();
// 当前简化处理直接通过手机号查用户 wrapper.eq(SysUser::getPhone, phone)
return null; // 暂时不自动关联用户后续通过 phone + orgId租户 code查询 .last("LIMIT 1");
SysUser user = sysUserMapper.selectOne(wrapper);
return user != null ? user.getId() : null;
} }
} }