fix(user-sync): 修复用户同步时tenantId为空问题

- 在用户同步数据中添加tenantId字段,tenantId为空时默认传0
- 更新同步日志,增加tenantId信息输出,便于调试跟踪
- 在扫码登录流程中添加多处详细调试日志,输出关键变量状态
- 添加System.out调试信息,帮助排查绑定用户及扫码登录异常情况
This commit is contained in:
2026-04-06 23:27:25 +08:00
parent 4ff46dbefe
commit 003a248d37
3 changed files with 52 additions and 3 deletions

View File

@@ -0,0 +1,37 @@
## 2026-04-06 - 修复编译错误和用户同步问题
### 修复的问题
1. **QrLoginServiceImpl.java编译错误**: 修复了`CommonUtil`类找不到的编译错误
- 原始错误: `java: cannot find symbol class CommonUtil location: package com.gxwebsoft.common.core.utils`
2. **WxOfficialController.java编译错误**: 缺少`DateUtil`导入
- 真正的问题根源,导致链式编译失败
3. **用户同步失败**: `Column 'tenant_id' cannot be null` 数据库完整性约束错误
- 问题: 在同步用户到websopy系统时没有传递tenant_id字段
- 结果: websopy端插入`app_user_cache`表时tenant_id为NULL违反非空约束
### 解决方案
1. **CommonUtil.java修复**: 添加缺失的导入`import com.gxwebsoft.common.core.utils.JSONUtil;`
- 原因: `CommonUtil.responseError()`方法使用了`JSONUtil.toJSONString()`但未导入
2. **WxOfficialController.java修复**:
- 添加缺失的导入`import cn.hutool.core.date.DateUtil;`
- 添加详细的调试日志,跟踪扫码登录流程
-`processWxUser`方法中添加"已存在绑定用户"的日志
-`completeQrLogin`方法中添加开始和完成的详细日志
3. **UserSyncService.java修复**:
- 在同步数据中添加`tenantId`字段: `userCache.put("tenantId", tenantIdValue)`
- 处理tenantId可能为null的情况默认传0: `Integer tenantIdValue = user.getTenantId() != null ? user.getTenantId() : 0`
- 更新日志输出包含tenantId信息
### 验证结果
- 执行`mvn clean compile`成功通过,编译无错误
- 所有代码修改语法正确,无编译警告
### 技术要点
1. **Java编译链式失败**: 一个文件的编译错误可能导致依赖它的其他文件也出现"找不到符号"的错误
2. **数据库完整性约束**: REST API调用时需要确保传递所有必填字段
3. **分布式系统调试**: 当同步到外部系统失败时,需要检查两边数据格式的一致性
4. **日志分级**: 在不同阶段添加适当的System.out和log.info日志便于问题排查