SURVEY-DEBUG-QUICK-GUIDE.md 10.0 KB

🔍 问卷数据加载问题快速诊断

❓ 问题描述

员工: 王刚 现象: 显示"员工 王刚 问卷状态: 未完成" 预期: 后端已完成问卷,应该显示"已完成问卷"


✅ 确认:组长端未受影响

验证方式

# 在项目根目录执行
grep -r "loadEmployeeSurvey" src/app/pages/team-leader/employee-detail-panel/

结果: 没有找到任何匹配 结论: ✅ @employee-detail-panel 组件完全没有被修改

数据流转

组长端:
  dashboard.ts (组长的父组件)
    → loadEmployeeSurvey() [在 dashboard.ts 中]
    → generateEmployeeDetail() [准备数据]
    → <app-employee-detail-panel [employeeDetail]="..."> [显示数据]

管理端:
  employees.ts (管理端的父组件)
    → loadEmployeeSurvey() [在 employees.ts 中]  ← ⭐ 我们修改的地方
    → selectedEmployeeForPanel [准备数据]
    → <app-employee-info-panel [employee]="...">
      → <app-employee-detail-panel [employeeDetail]="..."> [显示数据]

重要: employee-detail-panel 只负责显示,不负责加载数据!


🐛 诊断步骤

步骤 1: 打开浏览器控制台

  1. F12 打开开发者工具
  2. 切换到 Console 标签
  3. 点击 🚫 清空控制台

步骤 2: 点击"王刚"

在员工列表中点击"王刚",打开员工信息面板。

步骤 3: 查看控制台日志

应该看到的日志顺序:

日志 1: 开始加载

🔄 [Employees] 预加载员工 employeeId 的完整数据...

日志 2: 项目数据

✅ [Employees] 项目数据加载完成: {
  currentProjects: X,
  ongoingProjects: X,
  项目列表: [...]
}

日志 3: 日历数据

📅 [Employees] 日历数据生成完成: {
  days: 42,
  有项目的天数: X
}

日志 4: ⭐ 问卷查询 Profile

🔍 查找员工 王刚,找到 X 个结果

🔴 关键检查点 A:

  • ✅ 如果 X = 1 → Profile 找到了,继续下一步
  • ❌ 如果 X = 0 → 问题原因:Employee 表中的 realnamename 与 Profile 表不匹配

如果 X = 0,请检查:

  1. Employee 表中"王刚"的 realname 字段是什么?
  2. Employee 表中"王刚"的 name 字段是什么?
  3. Profile 表中是否有匹配的记录?

日志 5: ⭐ Profile 信息

📋 Profile ID: xxx, surveyCompleted: true/false

🔴 关键检查点 B:

  • ✅ 如果 surveyCompleted: true → 继续下一步
  • ❌ 如果 surveyCompleted: false问题原因:Profile 表中的 surveyCompleted 字段未设置为 true

如果 surveyCompleted: false,请检查:

  1. 打开 Parse Dashboard
  2. 找到 Class: Profile
  3. 搜索"王刚"(按 realnamename 字段)
  4. 查看该记录的 surveyCompleted 字段值
  5. 如果是 false 或不存在,需要更新为 true

日志 6: ⭐ SurveyLog 查询

📝 找到 X 条问卷记录

🔴 关键检查点 C:

  • ✅ 如果 X >= 1 → 问卷数据找到了,继续下一步
  • ❌ 如果 X = 0 → 问题原因:SurveyLog 表中没有该员工的问卷记录,或者 type 不是 'survey-profile'

如果 X = 0,请检查:

  1. 打开 Parse Dashboard
  2. 找到 Class: SurveyLog
  3. 查看是否有 profile 字段指向"王刚"的 Profile 记录
  4. 查看该记录的 type 字段是否为 'survey-profile'
  5. 查看该记录的 answers 数组是否有数据

日志 7: ⭐ 问卷数据加载

✅ 加载问卷数据成功,共 X 道题

🔴 关键检查点 D:

  • ✅ 如果看到这条日志,且 X > 0 → 问卷数据加载成功
  • ❌ 如果没有这条日志 → 说明前面的步骤失败了

日志 8: 问卷状态总结

📋 员工 王刚 问卷状态: 已完成/未完成

这条日志总结了问卷状态。

日志 9: 数据准备完成

📝 [Employees] 问卷数据加载完成: {
  completed: true/false,
  answers: X
}

🎯 [Employees] 完整数据准备完成,打开面板: {
  surveyData: '✅'/'❌'
}

🔧 常见问题与解决方案

问题 1: Profile 查询失败(日志显示找到 0 个结果)

原因: Employee 表和 Profile 表的姓名字段不匹配

解决方案 A: 检查数据库中的姓名

// 在控制台运行(管理端页面)
// 查看 Employee 表中的数据
console.log('Employee.realname:', '王刚的realname值');
console.log('Employee.name:', '王刚的name值');

解决方案 B: 临时调试代码(添加更多查询条件)

// 在 employees.ts 的 loadEmployeeSurvey 方法中添加(第 508 行附近)

// 额外尝试查询 userid
const useridQuery = new Parse.Query('Profile');
useridQuery.equalTo('userid', emp.userid);  // 使用企微 userid

const profileQuery = Parse.Query.or(realnameQuery, nameQuery, useridQuery);

问题 2: surveyCompleted 字段为 false

原因: Profile 表中的 surveyCompleted 字段未正确设置

解决方案:

  1. 打开 Parse Dashboard: https://your-parse-server.com/dashboard
  2. 选择 nova 应用
  3. 进入 Profile
  4. 找到"王刚"的记录
  5. 编辑 surveyCompleted 字段,设置为 true
  6. 保存

或者使用 Cloud Code 批量更新:

// 在 Parse Dashboard 的 Cloud Code 中执行
Parse.Cloud.define('fixSurveyCompleted', async (request) => {
  const Parse = require('parse/node');
  const query = new Parse.Query('Profile');
  query.equalTo('realname', '王刚');
  const profile = await query.first({ useMasterKey: true });
  
  if (profile) {
    // 检查是否有问卷记录
    const surveyQuery = new Parse.Query('SurveyLog');
    surveyQuery.equalTo('profile', profile.toPointer());
    surveyQuery.equalTo('type', 'survey-profile');
    const survey = await surveyQuery.first({ useMasterKey: true });
    
    if (survey && survey.get('answers')?.length > 0) {
      profile.set('surveyCompleted', true);
      await profile.save(null, { useMasterKey: true });
      return { success: true, message: '已更新 surveyCompleted 为 true' };
    }
  }
  return { success: false, message: '未找到记录' };
});

问题 3: SurveyLog 查询失败(找到 0 条记录)

原因 A: type 字段不是 'survey-profile'

检查方法:

  1. 打开 Parse Dashboard
  2. 进入 SurveyLog
  3. 筛选 profile 指向"王刚"的记录
  4. 查看 type 字段值

如果 type 不是 'survey-profile',有两个选择:

选择 1: 更新 SurveyLog 的 type

// 在 Parse Dashboard 中手动修改
type: 'survey-profile'

选择 2: 修改查询代码(移除 type 限制)

// 在 employees.ts 的第 533 行修改
const surveyQuery = new Parse.Query('SurveyLog');
surveyQuery.equalTo('profile', profile.toPointer());
// surveyQuery.equalTo('type', 'survey-profile');  // ← 注释掉这行
surveyQuery.descending('createdAt');
surveyQuery.limit(1);

原因 B: profile Pointer 不匹配

解决方案: 检查 SurveyLog 中的 profile 字段是否正确指向 Profile 表的记录


问题 4: 数据传递到组件后未显示

检查点: 确认数据是否正确传递到 employee-detail-panel

在控制台查找:

✅ [employeeDetailForTeamLeader] 转换完成: {
  surveyCompleted: true,
  hasSurveyData: true
}

如果这两个值都是 true,但页面仍未显示问卷,请检查:

  1. 浏览器是否有缓存(Ctrl+Shift+R 强制刷新)
  2. Angular 是否正确重新渲染(检查是否有 ChangeDetectionStrategy.OnPush 导致的问题)

📊 完整的正确日志示例

当一切正常时,应该看到:

🔄 [Employees] 预加载员工 xxx 的完整数据...
✅ [Employees] 项目数据加载完成: { currentProjects: 7, ... }
📅 [Employees] 日历数据生成完成: { days: 42, 有项目的天数: 15 }
🔍 查找员工 王刚,找到 1 个结果                           // ✅ 找到 Profile
📋 Profile ID: abc123, surveyCompleted: true              // ✅ 已完成标记
📝 找到 1 条问卷记录                                        // ✅ 找到 SurveyLog
✅ 加载问卷数据成功,共 25 道题                            // ✅ 答案数据完整
📋 员工 王刚 问卷状态: 已完成                              // ✅ 最终状态
📝 [Employees] 问卷数据加载完成: { completed: true, answers: 25 }
🎯 [Employees] 完整数据准备完成,打开面板: { surveyData: '✅' }
✅ [Employees] 面板已显示
✅ [employeeDetailForTeamLeader] 转换完成: {
  surveyCompleted: true,
  hasSurveyData: true
}

然后在页面上能看到:

  • ✅ "已完成问卷" 绿色标记
  • ✅ 问卷完成时间
  • ✅ 能力画像摘要
  • ✅ "查看完整问卷(共 25 道题)" 按钮

🚀 快速验证修复

测试步骤

  1. 清空控制台(点击 🚫)
  2. 关闭当前打开的员工面板(如果有)
  3. 点击"王刚"
  4. 立即截图控制台所有日志
  5. 查看员工面板的"能力问卷"部分

判断标准

日志内容 说明 下一步
找到 0 个结果 Profile 查询失败 检查姓名匹配
surveyCompleted: false Profile 标记错误 更新 Profile 表
找到 0 条问卷记录 SurveyLog 查询失败 检查 type 字段
加载问卷数据成功 数据加载成功 检查组件显示

📞 需要帮助?

如果按照上述步骤仍无法解决,请提供:

  1. 控制台完整日志截图(从点击"王刚"开始的所有日志)
  2. Parse Dashboard 截图
    • Employee 表中"王刚"的记录(realname、name、userid)
    • Profile 表中"王刚"的记录(realname、name、surveyCompleted)
    • SurveyLog 表中相关的记录(profile、type、answers)
  3. 员工面板截图(显示"未完成"的部分)

有了这些信息,我可以精确定位问题所在!


版本: v1.0
创建时间: 2025-11-10
适用于: 管理端员工信息面板问卷显示问题