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.
310 lines
11 KiB
310 lines
11 KiB
<?php
|
|
// +----------------------------------------------------------------------
|
|
// | Niucloud-admin 企业快速开发的多应用管理平台
|
|
// +----------------------------------------------------------------------
|
|
// | 官方网址:https://www.niucloud.com
|
|
// +----------------------------------------------------------------------
|
|
// | niucloud团队 版权所有 开源版本可自由商用
|
|
// +----------------------------------------------------------------------
|
|
// | Author: Niucloud Team
|
|
// +----------------------------------------------------------------------
|
|
|
|
namespace app\job\transfer\schedule;
|
|
|
|
use app\model\staff\Staff;
|
|
use app\model\service\TeachingService;
|
|
use app\model\course\Course;
|
|
use app\model\course_schedule\CourseSchedule;
|
|
use core\base\BaseJob;
|
|
use think\facade\Log;
|
|
|
|
/**
|
|
* 定时为教务或教练创建服务内容任务
|
|
* 根据教务/教练的课程安排自动生成服务内容记录
|
|
*/
|
|
class TeachingServiceJob extends BaseJob
|
|
{
|
|
/**
|
|
* 执行定时任务
|
|
* @param mixed ...$data 任务参数
|
|
* @return bool 处理结果
|
|
*/
|
|
public function doJob(...$data)
|
|
{
|
|
Log::write('开始执行教务/教练服务内容生成任务');
|
|
|
|
try {
|
|
$currentDate = date('Y-m-d');
|
|
|
|
// 为教务人员创建服务内容
|
|
$academicResult = $this->createAcademicServices($currentDate);
|
|
|
|
// 为教练创建服务内容
|
|
$coachResult = $this->createCoachServices($currentDate);
|
|
|
|
// 为助教创建服务内容
|
|
$assistantResult = $this->createAssistantServices($currentDate);
|
|
|
|
// 更新服务完成状态
|
|
$completionResult = $this->updateServiceCompletion($currentDate);
|
|
|
|
Log::write('教务/教练服务内容生成任务执行完成:' . print_r([
|
|
'academic_services' => $academicResult['count'],
|
|
'coach_services' => $coachResult['count'],
|
|
'assistant_services' => $assistantResult['count'],
|
|
'completed_services' => $completionResult['count']
|
|
], true));
|
|
|
|
return true;
|
|
|
|
} catch (\Exception $e) {
|
|
Log::write('教务/教练服务内容生成任务执行失败:' . $e->getMessage());
|
|
throw $e;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 为教务人员创建服务内容
|
|
* @param string $date 日期
|
|
* @return array 处理结果
|
|
*/
|
|
protected function createAcademicServices($date)
|
|
{
|
|
// 获取所有教务人员
|
|
$academicStaff = Staff::where('role_type', 'academic')
|
|
->where('status', 1)
|
|
->select();
|
|
|
|
$count = 0;
|
|
foreach ($academicStaff as $staff) {
|
|
// 检查今日是否已有服务记录
|
|
$existingService = TeachingService::where('staff_id', $staff->id)
|
|
->where('service_date', $date)
|
|
->count();
|
|
|
|
if ($existingService == 0) {
|
|
// 创建教务服务内容
|
|
$service = new TeachingService();
|
|
$service->staff_id = $staff->id;
|
|
$service->staff_name = $staff->real_name;
|
|
$service->service_date = $date;
|
|
$service->service_type = 'academic';
|
|
$service->service_content = $this->generateAcademicServiceContent($staff, $date);
|
|
$service->status = 'pending';
|
|
$service->created_at = date('Y-m-d H:i:s');
|
|
$service->save();
|
|
|
|
$count++;
|
|
Log::write("为教务人员创建服务内容:员工ID {$staff->id}, 姓名: {$staff->real_name}");
|
|
}
|
|
}
|
|
|
|
return ['count' => $count];
|
|
}
|
|
|
|
/**
|
|
* 为教练创建服务内容
|
|
* @param string $date 日期
|
|
* @return array 处理结果
|
|
*/
|
|
protected function createCoachServices($date)
|
|
{
|
|
// 获取所有教练
|
|
$coaches = Staff::where('role_type', 'coach')
|
|
->where('status', 1)
|
|
->select();
|
|
|
|
$count = 0;
|
|
foreach ($coaches as $coach) {
|
|
// 获取教练当日的课程安排
|
|
$todaySchedules = CourseSchedule::where('coach_id', $coach->id)
|
|
->where('course_date', $date)
|
|
->select();
|
|
|
|
if (count($todaySchedules) > 0) {
|
|
// 检查是否已有服务记录
|
|
$existingService = TeachingService::where('staff_id', $coach->id)
|
|
->where('service_date', $date)
|
|
->count();
|
|
|
|
if ($existingService == 0) {
|
|
// 创建教练服务内容
|
|
$service = new TeachingService();
|
|
$service->staff_id = $coach->id;
|
|
$service->staff_name = $coach->real_name;
|
|
$service->service_date = $date;
|
|
$service->service_type = 'coach';
|
|
$service->service_content = $this->generateCoachServiceContent($coach, $todaySchedules);
|
|
$service->scheduled_courses = count($todaySchedules);
|
|
$service->status = 'scheduled';
|
|
$service->created_at = date('Y-m-d H:i:s');
|
|
$service->save();
|
|
|
|
$count++;
|
|
Log::write("为教练创建服务内容:员工ID {$coach->id}, 课程数: " . count($todaySchedules));
|
|
}
|
|
}
|
|
}
|
|
|
|
return ['count' => $count];
|
|
}
|
|
|
|
/**
|
|
* 为助教创建服务内容
|
|
* @param string $date 日期
|
|
* @return array 处理结果
|
|
*/
|
|
protected function createAssistantServices($date)
|
|
{
|
|
// 获取所有助教
|
|
$assistants = Staff::where('role_type', 'assistant')
|
|
->where('status', 1)
|
|
->select();
|
|
|
|
$count = 0;
|
|
foreach ($assistants as $assistant) {
|
|
// 获取助教需要协助的课程
|
|
$assistantSchedules = CourseSchedule::where('assistant_id', $assistant->id)
|
|
->where('course_date', $date)
|
|
->select();
|
|
|
|
if (count($assistantSchedules) > 0) {
|
|
// 检查是否已有服务记录
|
|
$existingService = TeachingService::where('staff_id', $assistant->id)
|
|
->where('service_date', $date)
|
|
->count();
|
|
|
|
if ($existingService == 0) {
|
|
// 创建助教服务内容
|
|
$service = new TeachingService();
|
|
$service->staff_id = $assistant->id;
|
|
$service->staff_name = $assistant->real_name;
|
|
$service->service_date = $date;
|
|
$service->service_type = 'assistant';
|
|
$service->service_content = $this->generateAssistantServiceContent($assistant, $assistantSchedules);
|
|
$service->scheduled_courses = count($assistantSchedules);
|
|
$service->status = 'scheduled';
|
|
$service->created_at = date('Y-m-d H:i:s');
|
|
$service->save();
|
|
|
|
$count++;
|
|
Log::write("为助教创建服务内容:员工ID {$assistant->id}, 协助课程数: " . count($assistantSchedules));
|
|
}
|
|
}
|
|
}
|
|
|
|
return ['count' => $count];
|
|
}
|
|
|
|
/**
|
|
* 更新服务完成状态
|
|
* @param string $date 日期
|
|
* @return array 处理结果
|
|
*/
|
|
protected function updateServiceCompletion($date)
|
|
{
|
|
$currentTime = date('H:i:s');
|
|
$completionThreshold = '22:00:00'; // 22:00后自动标记为完成
|
|
|
|
if ($currentTime < $completionThreshold) {
|
|
return ['count' => 0];
|
|
}
|
|
|
|
// 更新当日未完成的服务为已完成状态
|
|
$pendingServices = TeachingService::where('service_date', $date)
|
|
->where('status', 'scheduled')
|
|
->select();
|
|
|
|
$count = 0;
|
|
foreach ($pendingServices as $service) {
|
|
$service->status = 'completed';
|
|
$service->completed_at = date('Y-m-d H:i:s');
|
|
$service->save();
|
|
|
|
$count++;
|
|
Log::write("自动标记服务完成:员工ID {$service->staff_id}, 服务类型: {$service->service_type}");
|
|
}
|
|
|
|
return ['count' => $count];
|
|
}
|
|
|
|
/**
|
|
* 生成教务服务内容
|
|
* @param Staff $staff 员工对象
|
|
* @param string $date 日期
|
|
* @return string 服务内容描述
|
|
*/
|
|
protected function generateAcademicServiceContent($staff, $date)
|
|
{
|
|
$content = [];
|
|
$content[] = "日期:{$date}";
|
|
$content[] = "教务人员:{$staff->real_name}";
|
|
$content[] = "服务内容:";
|
|
$content[] = "1. 学员课程安排和调度管理";
|
|
$content[] = "2. 教练课表协调和优化";
|
|
$content[] = "3. 学员咨询和问题解答";
|
|
$content[] = "4. 课程质量跟踪和反馈收集";
|
|
$content[] = "5. 学员学习进度监控";
|
|
$content[] = "6. 教学资源配置和管理";
|
|
|
|
return implode("\n", $content);
|
|
}
|
|
|
|
/**
|
|
* 生成教练服务内容
|
|
* @param Staff $coach 教练对象
|
|
* @param array $schedules 课程安排
|
|
* @return string 服务内容描述
|
|
*/
|
|
protected function generateCoachServiceContent($coach, $schedules)
|
|
{
|
|
$content = [];
|
|
$content[] = "教练:{$coach->real_name}";
|
|
$content[] = "预定课程数:" . count($schedules);
|
|
$content[] = "课程安排:";
|
|
|
|
foreach ($schedules as $schedule) {
|
|
$course = Course::find($schedule->course_id);
|
|
$courseName = $course ? $course->course_name : "未知课程";
|
|
$content[] = "- {$schedule->time_slot}: {$courseName} (场地ID: {$schedule->venue_id})";
|
|
}
|
|
|
|
$content[] = "服务职责:";
|
|
$content[] = "1. 按时到达指定场地进行授课";
|
|
$content[] = "2. 确保课程质量和安全性";
|
|
$content[] = "3. 记录学员学习情况和进度";
|
|
$content[] = "4. 提供专业指导和建议";
|
|
$content[] = "5. 维护教学设备和场地整洁";
|
|
|
|
return implode("\n", $content);
|
|
}
|
|
|
|
/**
|
|
* 生成助教服务内容
|
|
* @param Staff $assistant 助教对象
|
|
* @param array $schedules 课程安排
|
|
* @return string 服务内容描述
|
|
*/
|
|
protected function generateAssistantServiceContent($assistant, $schedules)
|
|
{
|
|
$content = [];
|
|
$content[] = "助教:{$assistant->real_name}";
|
|
$content[] = "协助课程数:" . count($schedules);
|
|
$content[] = "协助安排:";
|
|
|
|
foreach ($schedules as $schedule) {
|
|
$course = Course::find($schedule->course_id);
|
|
$courseName = $course ? $course->course_name : "未知课程";
|
|
$content[] = "- {$schedule->time_slot}: 协助 {$courseName}";
|
|
}
|
|
|
|
$content[] = "服务职责:";
|
|
$content[] = "1. 协助主教练进行课程教学";
|
|
$content[] = "2. 维护课堂秩序和安全";
|
|
$content[] = "3. 帮助学员纠正动作和姿势";
|
|
$content[] = "4. 准备和整理教学器材";
|
|
$content[] = "5. 记录学员出勤和表现";
|
|
|
|
return implode("\n", $content);
|
|
}
|
|
}
|