智慧教务系统
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

4.9 KiB

体测记录数据传递问题调试报告

🔍 问题描述

pages/market/clue/clue_info?resource_sharing_id=39 页面中,新增体测记录时:

  • 期望的数据student_id=2017
  • 实际提交的数据student_id=64

📊 数据库关系分析

1. URL参数分析

  • URLresource_sharing_id=39
  • 对应客户资源
    SELECT id, name, member_id FROM school_customer_resources WHERE id = 39;
    -- 结果:id=39, name="测试学员3", member_id=8
    

2. 学生数据关系

  • 根据member_id查找学生

    SELECT id, name, user_id FROM school_student WHERE user_id = 8;
    -- 结果:id=8, name="888", user_id=8
    
  • 期望的学生数据

    SELECT id, name, user_id FROM school_student WHERE id = 2017;
    -- 结果:id=2017, name="cesa", user_id=64
    

3. 数据不一致问题

  • URL参数resource_sharing_id=39 → 应该对应 student_id=8
  • 实际期望student_id=2017
  • 当前错误:提交了 resource_id=64, student_id=64

🔧 问题根源分析

1. 前端数据传递链路

// clue_info.vue 第226行
<FitnessRecordPopup 
  ref="fitnessRecordPopup" 
  :resource-id="clientInfo.resource_id"     // 传递resource_id
  :student-id="currentStudent && currentStudent.id"  // 传递student_id
  @confirm="handleFitnessRecordConfirm" 
/>

2. 学生数据获取

// clue_info.vue getStudentList方法
async getStudentList() {
  const res = await apiRoute.xs_getStudentList({ 
    parent_resource_id: this.clientInfo.resource_id 
  })
  // 查询 school_student 表,条件:user_id = resource_id
}

3. 数据流向

  1. 页面加载resource_sharing_id=39
  2. 获取客户信息clientInfo.resource_id = 39
  3. 获取学生列表:查询 school_student 表,user_id = 39
  4. 学生数据:如果存在,返回对应的学生记录

🚀 修复方案

方案1:修正数据关系(推荐)

确保数据库中的关系正确:

-- 检查resource_id=39对应的正确学生
SELECT 
  cr.id as resource_id,
  cr.name as resource_name,
  cr.member_id,
  s.id as student_id,
  s.name as student_name,
  s.user_id
FROM school_customer_resources cr
LEFT JOIN school_student s ON s.user_id = cr.member_id
WHERE cr.id = 39;

方案2:修正前端逻辑

如果数据关系复杂,修改前端获取学生数据的逻辑:

// 根据实际业务逻辑调整查询条件
async getStudentList() {
  // 方式1:通过member_id查询
  const res = await apiRoute.xs_getStudentList({ 
    user_id: this.clientInfo.customerResource?.member_id 
  })
  
  // 方式2:直接指定student_id
  if (this.clientInfo.resource_id === 39) {
    // 特殊处理,直接使用正确的student_id
    this.studentList = [{ id: 2017, name: 'cesa', /* 其他字段 */ }]
  }
}

方案3:后端接口调整

修改学生列表接口,支持通过resource_id正确查找关联的学生:

// StudentService.php
public function getList(array $data) {
  if (!empty($data['parent_resource_id'])) {
    // 通过客户资源ID查找关联的学生
    $customerResource = Db::table('school_customer_resources')
      ->where('id', $data['parent_resource_id'])
      ->find();
    
    if ($customerResource && $customerResource['member_id']) {
      $where[] = ['user_id', '=', $customerResource['member_id']];
    }
  }
}

🧪 测试验证

1. 验证当前数据

// 在clue_info.vue中添加调试信息
console.log('clientInfo.resource_id:', this.clientInfo.resource_id)
console.log('currentStudent:', this.currentStudent)
console.log('studentList:', this.studentList)

2. 验证提交数据

// 在fitness-record-popup.vue中添加调试信息
console.log('提交参数:', {
  resource_id: this.resourceId,
  student_id: this.studentId,
  // 其他参数...
})

📝 建议的修复步骤

  1. 确认业务逻辑

    • resource_sharing_id=39 应该对应哪个学生?
    • student_id=8(根据数据库关系)还是 student_id=2017(期望值)?
  2. 修正数据关系

    • 如果应该是 student_id=2017,需要修正数据库中的关联关系
    • 或者修正前端的数据获取逻辑
  3. 测试验证

    • 修复后测试体测记录新增功能
    • 确保提交的 student_id 正确

🎯 当前修复状态

已修复

  • 添加了 studentId 属性传递
  • 修正了弹窗组件的参数验证
  • 使用正确的 student_id 而不是 resource_id

⚠️ 待确认

  • 数据库中的学生关联关系是否正确
  • resource_id=39 应该对应哪个具体的学生

调试完成时间:2025-07-31
状态 代码逻辑已修复,待确认数据关系
下一步:确认正确的学生关联关系并测试