Skip to content

Commit e494775

Browse files
authored
fix(common): course adjust notice processing (#448)
1 parent 08bf98b commit e494775

3 files changed

Lines changed: 31 additions & 9 deletions

File tree

cmd/common/main.go

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,33 @@ func loadNotice(db *db.Database) {
7878
}
7979
for _, row := range content {
8080
ctx := context.Background()
81+
82+
ok, err := db.Notice.IsNoticeExists(ctx, row.Title, row.URL)
83+
if err != nil {
84+
logger.Warnf("syncer init: failed to check notice exists in page %d: %v", i, err)
85+
continue
86+
}
87+
// 数据库已存在,无需处理
88+
if ok {
89+
continue
90+
}
91+
8192
info := &model.Notice{
8293
Title: row.Title,
8394
PublishedAt: row.Date,
8495
URL: row.URL,
8596
}
86-
err = db.Notice.CreateNotice(ctx, info)
87-
if err != nil {
97+
if err = db.Notice.CreateNotice(ctx, info); err != nil {
8898
logger.Warnf("syncer init: failed to create notice in page %d: %v", i, err)
99+
continue
89100
}
101+
102+
go func(notice *jwch.NoticeInfo) {
103+
ctx := context.Background()
104+
if err := commonSvc.NewCommonService(ctx, clientSet, taskQueue).ProcessAutoAdjustCourseNotice(notice); err != nil {
105+
logger.Errorf("syncer init: ProcessAutoAdjustCourseNotice failed, title=%s url=%s err=%v", notice.Title, notice.URL, err)
106+
}
107+
}(row)
90108
}
91109
}
92110
logger.Infof("syncer init: notice syncer init success")
@@ -153,6 +171,8 @@ func syncNoticeTask() error {
153171
continue
154172
}
155173

174+
logger.Infof("syncNoticeTask: new notice found, title=%s url=%s", row.Title, row.URL)
175+
156176
info := &model.Notice{
157177
Title: row.Title,
158178
URL: row.URL,

internal/common/service/get_toolbox_config.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ package service
1818

1919
import (
2020
"context"
21-
"fmt"
2221

2322
"github.com/west2-online/fzuhelper-server/pkg/db/model"
23+
"github.com/west2-online/fzuhelper-server/pkg/logger"
2424
)
2525

2626
const (
@@ -97,7 +97,7 @@ func (s *CommonService) GetToolboxConfig(ctx context.Context, studentID string,
9797

9898
// 跳过不匹配的配置
9999
if matchScore < 0 {
100-
fmt.Println("matchScore < 0", matchScore)
100+
logger.Warnf("matchScore < 0: %d", matchScore)
101101
continue
102102
}
103103
toolID := config.ToolID

internal/common/service/process_auto_adjust_course_notice.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,14 @@ import (
3030

3131
// 处理教务通知中的课程调整信息
3232
func (s *CommonService) ProcessAutoAdjustCourseNotice(info *jwch.NoticeInfo) error {
33+
logger.Infof("ProcessAutoAdjustCourseNotice: processing notice, title=%s url=%s", info.Title, info.URL)
34+
3335
// 仅处理标题包含"课程调整"的通知,其余通知直接跳过
3436
if !strings.Contains(info.Title, "课程调整") {
3537
return nil
3638
}
3739

38-
// 根据通知的树节点 ID 和新闻 ID 获取通知详情(含正文 HTML)
40+
// 根据通知的 WbTreeId 和 WbNewsId 获取通知详情(含正文 HTML)
3941
detail, err := jwch.NewStudent().GetNoticeDetail(&jwch.NoticeDetailReq{
4042
WbTreeId: info.WbTreeId,
4143
WbNewsId: info.WbNewsId,
@@ -44,17 +46,17 @@ func (s *CommonService) ProcessAutoAdjustCourseNotice(info *jwch.NoticeInfo) err
4446
return fmt.Errorf("ProcessAutoAdjustCourseNotice: failed to get notice detail: %w", err)
4547
}
4648

47-
content := detail.Content
48-
49-
// 调用 AI 从通知标题和正文中提取结构化的课程调整条目
49+
// 调用 LLM 从通知标题和正文中提取结构化的课程调整条目
5050
result, err := ai.AutoAdjustCourse(s.ctx, ai.AutoAdjustCourseInput{
5151
Title: info.Title,
52-
Content: content,
52+
Content: detail.Content,
5353
})
5454
if err != nil {
5555
return fmt.Errorf("ProcessAutoAdjustCourseNotice: failed to auto adjust course: %w", err)
5656
}
5757

58+
logger.Infof("ProcessAutoAdjustCourseNotice: AI extracted %+v", result.Items)
59+
5860
// 获取学期列表,用于后续将日期映射到具体学期
5961
calendar, err := s.GetTermList()
6062
if err != nil {

0 commit comments

Comments
 (0)