81 lines
2.5 KiB
Go
81 lines
2.5 KiB
Go
package impl
|
|
|
|
import (
|
|
"ai_scheduler/internal/data/model"
|
|
"ai_scheduler/tmpl/dataTemp"
|
|
"ai_scheduler/utils"
|
|
"context"
|
|
)
|
|
|
|
type AdviceCustomerImpl struct {
|
|
dataTemp.DataTemp
|
|
}
|
|
|
|
func NewAdviceCustomerImpl(db *utils.Db) *AdviceCustomerImpl {
|
|
return &AdviceCustomerImpl{
|
|
DataTemp: *dataTemp.NewDataTemp(db, new(model.AiAdviceCustomer)),
|
|
}
|
|
}
|
|
|
|
// BatchInsert 批量插入好友记录
|
|
func (a *AdviceCustomerImpl) BatchInsert(ctx context.Context, records []model.AiAdviceCustomer) error {
|
|
if len(records) == 0 {
|
|
return nil
|
|
}
|
|
return a.Db.WithContext(ctx).Create(&records).Error
|
|
}
|
|
|
|
// BatchUpdateByWxid 按 self_wxid + user_name 批量更新已有好友记录
|
|
func (a *AdviceCustomerImpl) BatchUpdateByWxid(ctx context.Context, records []model.AiAdviceCustomer) error {
|
|
for _, r := range records {
|
|
err := a.Db.WithContext(ctx).
|
|
Model(&model.AiAdviceCustomer{}).
|
|
Where("self_wxid = ? AND user_name = ?", r.SelfWxid, r.UserName).
|
|
Updates(map[string]interface{}{
|
|
"nick_name": r.NickName,
|
|
"py_initial": r.PyInitial,
|
|
"quan_pin": r.QuanPin,
|
|
"sex": r.Sex,
|
|
"remark": r.Remark,
|
|
"remark_py_initial": r.RemarkPyInitial,
|
|
"remark_quan_pin": r.RemarkQuanPin,
|
|
"signature": r.Signature,
|
|
"alias": r.Alias,
|
|
"big_head_img_url": r.BigHeadImgUrl,
|
|
"small_head_img_url": r.SmallHeadImgUrl,
|
|
"label_list": r.LabelList,
|
|
"province": r.Province,
|
|
"city": r.City,
|
|
}).Error
|
|
if err != nil {
|
|
return err
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// UpdateLabelList 仅更新好友的标签列表
|
|
func (a *AdviceCustomerImpl) UpdateLabelList(ctx context.Context, selfWxid, userName, labelList string) error {
|
|
return a.Db.WithContext(ctx).
|
|
Model(&model.AiAdviceCustomer{}).
|
|
Where("self_wxid = ? AND user_name = ?", selfWxid, userName).
|
|
Update("label_list", labelList).Error
|
|
}
|
|
|
|
// FindBySelfWxidAndUserName 查询单个客户记录
|
|
func (a *AdviceCustomerImpl) FindBySelfWxidAndUserName(ctx context.Context, selfWxid, userName string) (model.AiAdviceCustomer, error) {
|
|
var record model.AiAdviceCustomer
|
|
err := a.Db.WithContext(ctx).
|
|
Where("self_wxid = ? AND user_name = ?", selfWxid, userName).
|
|
First(&record).Error
|
|
return record, err
|
|
}
|
|
|
|
// UpdateSessionId 更新客户的会话 ID
|
|
func (a *AdviceCustomerImpl) UpdateSessionId(ctx context.Context, customerId int32, sessionId string) error {
|
|
return a.Db.WithContext(ctx).
|
|
Model(&model.AiAdviceCustomer{}).
|
|
Where("customer_id = ?", customerId).
|
|
Update("session_id", sessionId).Error
|
|
}
|