src/Biz/Course/Job/RefreshLearningProgressJob.php

(开头部分) 2KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

<?php

namespace Biz\Course\Job;

use Biz\AppLoggerConstant;
use Biz\Course\Dao\CourseDao;
use Biz\Course\Dao\CourseJobDao;
use Biz\Course\Dao\LearningDataAnalysisDao;
use Biz\Course\Service\MemberService;
use Biz\System\Service\LogService;
use Codeages\Biz\Framework\Scheduler\AbstractJob;

class RefreshLearningProgressJob extends AbstractJob
{
    private $step = 1000;

    public function execute()
    {
        try {
            $courseIds = $this->getShouldRefreshCourseIds();

            $this->getLogService()->info(AppLoggerConstant::COURSE, 'refresh_learning_progress', '开始执行刷新学习进度的定时任务', $courseIds);

            foreach ($courseIds as $courseId) {
                $this->refreshLearningProgress($courseId);
            }

            $this->getLogService()->info(AppLoggerConstant::COURSE, 'refresh_learning_progress', '刷新学习进度的定时任务执行成功', $courseIds);
        } catch (\Exception $e) {
            $this->getLogService()->error(AppLoggerConstant::COURSE, 'refresh_learning_progress', '刷新学习进度的定时任务执行失败', array('error' => $e->getMessage()));
        }
    }

    private function refreshLearningProgress($courseId)
    {
        try {
            $memberUserIds = $this->getCourseMemberService()->findMemberUserIdsByCourseId($courseId);
            for ($i = 0; $i < count($memberUserIds) / $this->step; ++$i) {
                $userIds = array_slice($memberUserIds, $this->step * $i, $this->step);
                $this->getLearningDataAnalysisDao()->batchRefreshUserLearningData($courseId, $userIds);
            }

            $this->getCourseJobDao()->deleteByTypeAndCourseId('refresh_learning_progress', $courseId);

            $this->getLogService()->info(AppLoggerConstant::COURSE, 'refresh_learning_progress', "刷新计划#{$courseId}学习进度成功");
        } catch (\Exception $e) {
            $this->getLogService()->error(AppLoggerConstant::COURSE, 'refresh_learning_progress', "刷新计划#{$courseId}学习进度失败", array('error' => $e->getMessage()));
        }
    }

    private function getShouldRefreshCourseIds()
    {
        $courseJobs = $this->getCourseJobDao()->findByType('refresh_learning_progress');

        $courseJobs = array_filter($courseJobs, function ($courseJob) {
            return count(array_filter($courseJob['data'])) > 0;
        });

        $courseIds = array_column($courseJobs, 'courseId');

24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明

AI 解读 AI

登录后可用,每次 10 算力,解读结果公开显示在下面。

还没有人解读过这个文件。