Skip to content

Commit c81927d

Browse files
committed
feat: 自动记录课程名称
1 parent a46c459 commit c81927d

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

internal/controller/search.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ func Search(c *gin.Context) {
9090
resp := util.FillAnswerResponse(result, &req)
9191

9292
if len(localAnswer) == 0 && c.Query("noRecord") == "" { // 只有本地题库没有答案或者明确标志不要记录
93-
middleware.CollectAnswer(resp, c.Query("extra"))
93+
middleware.CollectAnswer(resp, c.Query("courseName"), c.Query("extra"))
9494
}
9595
c.JSON(http.StatusOK, resp)
9696
}

internal/middleware/collect_answer.go

+9-9
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"github.com/itihey/tikuAdapter/internal/registry/manager"
1010
"github.com/itihey/tikuAdapter/pkg/logger"
1111
"github.com/itihey/tikuAdapter/pkg/model"
12-
"os"
1312
"sort"
1413
"strconv"
1514
)
@@ -38,7 +37,7 @@ func FillHash(t *entity.Tiku) {
3837
}
3938

4039
// CollectAnswer 收集没有搜索到的答案
41-
func CollectAnswer(resp model.SearchResponse, extra string) {
40+
func CollectAnswer(resp model.SearchResponse, courseName, extra string) {
4241
sort.Strings(resp.Options) // 将选项排序
4342
opts, err := json.Marshal(resp.Options)
4443
if err != nil {
@@ -53,14 +52,15 @@ func CollectAnswer(resp model.SearchResponse, extra string) {
5352
ans = string(marshal)
5453
}
5554
// 记录空答案或者有答案才会被记录
56-
if manager.GetManager().GetConfig().RecordEmptyAnswer || ans != "[]" || os.Getenv("SQL_DSN") != "" {
55+
if manager.GetManager().GetConfig().RecordEmptyAnswer || ans != "[]" {
5756
t := entity.Tiku{
58-
Extra: extra,
59-
Type: int32(resp.Type),
60-
Question: resp.Question,
61-
Answer: ans,
62-
Options: string(opts),
63-
Plat: int32(resp.Plat),
57+
CourseName: courseName,
58+
Extra: extra,
59+
Type: int32(resp.Type),
60+
Question: resp.Question,
61+
Answer: ans,
62+
Options: string(opts),
63+
Plat: int32(resp.Plat),
6464
}
6565
FillHash(&t)
6666
err := dao.Tiku.Create(&t)

web/src/components/TikuComponent/TikuComponent.vue

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<a-card style="margin: 24px 50px 0;">
66
<a-row>
77
<a-col :span="5">
8-
<a-form-item label="来源" :label-col="labelCol" :wrapper-col="wrapperCol">
8+
<a-form-item label="平台" :label-col="labelCol" :wrapper-col="wrapperCol">
99
<a-select
1010
v-model:value="platValue"
1111
show-search
@@ -17,7 +17,7 @@
1717
</a-form-item>
1818
</a-col>
1919
<a-col :span="4">
20-
<a-form-item label=" 课程" :label-col="labelCol" :wrapper-col="wrapperCol">
20+
<a-form-item label="课程" :label-col="labelCol" :wrapper-col="wrapperCol">
2121
<a-select
2222
v-model:value="courseValue"
2323
show-search

0 commit comments

Comments
 (0)