2026-04-09 10:01:23 +08:00
|
|
|
package quickreply
|
|
|
|
|
|
|
|
|
|
import (
|
2026-08-21 00:41:07 +08:00
|
|
|
"code.tczkiot.com/wlw/ai-agent/cmd/testdata/seedlang"
|
|
|
|
|
"code.tczkiot.com/wlw/ai-agent/cmd/testdata/seeds"
|
|
|
|
|
"code.tczkiot.com/wlw/ai-agent/internal/models"
|
|
|
|
|
"code.tczkiot.com/wlw/ai-agent/internal/repositories"
|
2026-04-09 10:01:23 +08:00
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
"github.com/mlogclub/simple/sqls"
|
|
|
|
|
)
|
|
|
|
|
|
2026-06-01 12:03:57 +08:00
|
|
|
func Init(lang seedlang.Language) error {
|
2026-06-01 12:15:41 +08:00
|
|
|
seed := seeds.QuickReplySeeds(lang)
|
2026-06-01 12:03:57 +08:00
|
|
|
return sqls.WithTransaction(func(ctx *sqls.TxContext) error {
|
|
|
|
|
now := time.Now()
|
|
|
|
|
for _, row := range seed {
|
2026-06-01 12:15:41 +08:00
|
|
|
existing := repositories.QuickReplyRepository.Get(ctx.Tx, row.ID)
|
2026-06-01 12:03:57 +08:00
|
|
|
if existing == nil {
|
|
|
|
|
item := &models.QuickReply{
|
2026-06-01 12:15:41 +08:00
|
|
|
ID: row.ID,
|
|
|
|
|
GroupName: row.GroupName,
|
|
|
|
|
Title: row.Title,
|
|
|
|
|
Content: row.Content,
|
|
|
|
|
Status: row.Status,
|
|
|
|
|
SortNo: row.SortNo,
|
2026-06-01 12:03:57 +08:00
|
|
|
AuditFields: models.AuditFields{
|
|
|
|
|
CreatedAt: now,
|
|
|
|
|
CreateUserID: 0,
|
|
|
|
|
CreateUserName: "system",
|
|
|
|
|
UpdatedAt: now,
|
|
|
|
|
UpdateUserID: 0,
|
|
|
|
|
UpdateUserName: "system",
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
if err := repositories.QuickReplyRepository.Create(ctx.Tx, item); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
continue
|
|
|
|
|
}
|
2026-06-01 12:15:41 +08:00
|
|
|
if err := repositories.QuickReplyRepository.Updates(ctx.Tx, row.ID, map[string]any{
|
|
|
|
|
"group_name": row.GroupName,
|
|
|
|
|
"title": row.Title,
|
|
|
|
|
"content": row.Content,
|
|
|
|
|
"status": row.Status,
|
|
|
|
|
"sort_no": row.SortNo,
|
2026-06-01 12:03:57 +08:00
|
|
|
"updated_at": now,
|
|
|
|
|
"update_user_id": 0,
|
|
|
|
|
"update_user_name": "system",
|
|
|
|
|
}); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
})
|
|
|
|
|
}
|