50 lines
1.7 KiB
Go
50 lines
1.7 KiB
Go
package seed
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/gogf/gf/v2/database/gdb"
|
|
"github.com/gogf/gf/v2/frame/g"
|
|
|
|
"36wisdom/biz/consts"
|
|
"36wisdom/common"
|
|
)
|
|
|
|
// annotateAll 拼音补标:对 *_pinyin 为空的记录按原文标注。
|
|
// 启动维护一次性(约 500 行),单事务内逐行 UPDATE,失败告警不阻断。
|
|
// 注意:迁移补列的历史记录为 NULL,须同时匹配 ” 与 NULL。
|
|
func annotateAll(ctx context.Context) {
|
|
type target struct{ table, pinyinCol, textCol string }
|
|
targets := []target{
|
|
{consts.TableStrategy, "meaning_pinyin", "meaning"},
|
|
{consts.TableStrategy, "teach_content_pinyin", "teach_content"},
|
|
{consts.TableStrategy, "summary_q_pinyin", "summary_q"},
|
|
{consts.TableStrategy, "summary_options_pinyin", "summary_options"},
|
|
{consts.TableLevel, "scene_content_pinyin", "scene_content"},
|
|
{consts.TableSceneNode, "content_pinyin", "content"},
|
|
{consts.TableNodeOption, "text_pinyin", "text"},
|
|
{consts.TableNodeOption, "feedback_pinyin", "feedback"},
|
|
{consts.TableElement, "name_pinyin", "name"},
|
|
{consts.TableElement, "description_pinyin", "description"},
|
|
}
|
|
if err := g.DB().Transaction(ctx, func(ctx context.Context, tx gdb.TX) error {
|
|
for _, t := range targets {
|
|
recs, err := tx.Model(t.table).Ctx(ctx).Where(t.pinyinCol, "").WhereOr(t.pinyinCol, nil).Fields("id," + t.textCol).All()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
for _, rec := range recs {
|
|
if _, err := tx.Model(t.table).Ctx(ctx).WherePri(rec["id"].Int64()).
|
|
Data(g.Map{t.pinyinCol: common.AnnotatePinyin(rec[t.textCol].String())}).Update(); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
}
|
|
return nil
|
|
}); err != nil {
|
|
g.Log().Warningf(ctx, "seed: 拼音补标失败: %v", err)
|
|
return
|
|
}
|
|
g.Log().Info(ctx, "seed: 拼音补标完成")
|
|
}
|