From a8f4a2afa67704ff88f84bc1257985ccccd3795a Mon Sep 17 00:00:00 2001 From: sugarBecomer Date: Mon, 22 Dec 2025 17:25:51 +0800 Subject: [PATCH] =?UTF-8?q?:bug:=20=E4=BF=AE=E5=A4=8D=E5=AD=A6=E4=B9=A0?= =?UTF-8?q?=E9=80=9A=E5=88=B7=E8=AF=BE=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/application/xuexitong/xuexitong_chapter.go | 12 +++++++----- internal/application/xuexitong/xuexitong_test.go | 4 ++-- internal/application/xuexitong/xuexitong_video.go | 1 + internal/framework/logger/zap.go | 2 ++ internal/service/course/course.go | 13 ------------- 5 files changed, 12 insertions(+), 20 deletions(-) diff --git a/internal/application/xuexitong/xuexitong_chapter.go b/internal/application/xuexitong/xuexitong_chapter.go index 0e64abb..ceb930b 100644 --- a/internal/application/xuexitong/xuexitong_chapter.go +++ b/internal/application/xuexitong/xuexitong_chapter.go @@ -288,7 +288,9 @@ func (c *XuexitongCourse) FetchChapterCards(ctx context.Context, course entity.X logger.Logger.Debug("解析卡片失败", zap.Error(err)) continue } - + if iframes == nil { + continue + } for _, iframe := range iframes { if !iframe.HasData { continue @@ -319,7 +321,7 @@ func (c *XuexitongCourse) FetchChapterCards(ctx context.Context, course entity.X point.ObjectID = objectID point.JobID = jobID - cords2, err := c.FetchChapterCards2(ctx, course, card.KnowledgeID) + cords2, err := c.FetchChapterCards2(ctx, course, cardIndex, card.KnowledgeID) if err == nil && cords2 != nil { c.fillVideoPointFromCards2(cords2, &point, objectID) } @@ -524,9 +526,9 @@ func (c *XuexitongCourse) parseIframeData(htmlString string) ([]entity.IframeAtt } // FetchChapterCards2 获取章节卡片(新接口,用于获取 otherInfo 等) -func (c *XuexitongCourse) FetchChapterCards2(ctx context.Context, course entity.XueXiTCourse, knowledgeID int) (map[string]interface{}, error) { - urlStr := fmt.Sprintf("%s?clazzid=%s&courseid=%s&knowledgeid=%d&num=0&ut=s&cpi=%d&v=2025-0424-1038-3&mooc2=1&isMicroCourse=false&editorPreview=0", - ApiChapterCards2, course.Key, course.CourseID, knowledgeID, course.Cpi) +func (c *XuexitongCourse) FetchChapterCards2(ctx context.Context, course entity.XueXiTCourse, num int, knowledgeID int) (map[string]interface{}, error) { + urlStr := fmt.Sprintf("%s?clazzid=%s&courseid=%s&knowledgeid=%d&num=%d&ut=s&cpi=%d&v=2025-0424-1038-3&mooc2=1&isMicroCourse=false&editorPreview=0", + ApiChapterCards2, course.Key, course.CourseID, knowledgeID, num, course.Cpi) logger.Logger.Debug("FetchChapterCards2 请求", zap.String("url", urlStr), diff --git a/internal/application/xuexitong/xuexitong_test.go b/internal/application/xuexitong/xuexitong_test.go index 0929723..125c9e8 100644 --- a/internal/application/xuexitong/xuexitong_test.go +++ b/internal/application/xuexitong/xuexitong_test.go @@ -37,7 +37,7 @@ func getAIConfig(ctx context.Context) *quesbank.AIConfig { func TestSchedule(t *testing.T) { ctx := context.Background() xuexitongLogin := NewXuexitongLogin(ctx) - err := xuexitongLogin.Login(context.Background(), "13151832241", "yyz@083422", 5) + err := xuexitongLogin.Login(context.Background(), "15754238084", "1575423yuan.dby", 5) utils.OkOrPanic(err) client := xuexitongLogin.GetClient() @@ -54,7 +54,7 @@ func TestSchedule(t *testing.T) { logger.Logger.Warn("AI配置为空,作业将被跳过") } - err = courseService.AutoStudyByCourseIDWithOptions(ctx, "258109701", &AutoStudyOptions{ + err = courseService.AutoStudyByCourseIDWithOptions(ctx, "255690793", &AutoStudyOptions{ AIConfig: config, AutoSubmit: true, // 默认不自动提交,仅保存 Thread: 1, diff --git a/internal/application/xuexitong/xuexitong_video.go b/internal/application/xuexitong/xuexitong_video.go index ca0492a..a72a332 100644 --- a/internal/application/xuexitong/xuexitong_video.go +++ b/internal/application/xuexitong/xuexitong_video.go @@ -252,6 +252,7 @@ func (c *XuexitongCourse) attachmentDetectVideo(attachment *entity.AttachmentSet // AutoPlayVideoByPoint 自动播放视频(使用统一的 ChapterPoint) func (c *XuexitongCourse) AutoPlayVideoByPoint(ctx context.Context, course entity.XueXiTCourse, p *entity.ChapterPoint) error { + if err := c.VideoDtoFetchByPoint(ctx, p); err != nil { return fmt.Errorf("获取视频信息失败: %w", err) } diff --git a/internal/framework/logger/zap.go b/internal/framework/logger/zap.go index 1a073a3..4879d75 100644 --- a/internal/framework/logger/zap.go +++ b/internal/framework/logger/zap.go @@ -15,6 +15,8 @@ func init() { config := zap.NewProductionConfig() if IsDebug() { config.Level = zap.NewAtomicLevelAt(zap.DebugLevel) // Enable debug logs + } else { + config.Level = zap.NewAtomicLevelAt(zap.InfoLevel) } config.EncoderConfig.EncodeTime = BeijingTimeEncoder diff --git a/internal/service/course/course.go b/internal/service/course/course.go index 55576db..c7148f8 100644 --- a/internal/service/course/course.go +++ b/internal/service/course/course.go @@ -59,19 +59,6 @@ func (s CourseServiceV1) List(ctx context.Context, req *v1.CourseListReq) *utils func (s CourseServiceV1) AddCourse(ctx context.Context, req *v1.AddCourseReq) *utils.Response[any] { user := utils.GetUserInfoFromCtx(ctx) - // 检查是否已经存在相同的刷课任务 - exists := db2.Global.CourseEntity.Query(). - Where( - courseentity.HasSysUserWith(sysuser.ID(user.ID)), - courseentity.Username(req.Username), - courseentity.CourseID(req.CourseID), - ). - ExistX(ctx) - - if exists { - utils.OkOrPanic(errors2.NewBusinessError(400, "该课程已存在刷课任务")) - } - // 登录学习通获取节点信息 loginClient := xuexitong.NewXuexitongLogin(ctx) err := loginClient.Login(ctx, req.Username, req.Password, 3)