123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- package label_relationship
- import (
- "context"
- "wechat-api/internal/svc"
- "wechat-api/internal/types"
- "github.com/zeromicro/go-zero/core/logx"
- )
- type BatchUpdateLabelRelationshipsLogic struct {
- logx.Logger
- ctx context.Context
- svcCtx *svc.ServiceContext
- }
- func NewBatchUpdateLabelRelationshipsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *BatchUpdateLabelRelationshipsLogic {
- return &BatchUpdateLabelRelationshipsLogic{
- Logger: logx.WithContext(ctx),
- ctx: ctx,
- svcCtx: svcCtx}
- }
- func (l *BatchUpdateLabelRelationshipsLogic) BatchUpdateLabelRelationships(req *types.BatchLabelRelationshipsInfo) (resp *types.BaseMsgResp, err error) {
- //organizationId := l.ctx.Value("organizationId").(uint64)
- //// 开始事务
- //tx, err := l.svcCtx.DB.Tx(context.Background())
- //if err != nil {
- // return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
- //}
- //
- //// 遍历所有联系人
- //for _, contactId := range req.ContactIds {
- // // 获取联系人信息
- // c, err := tx.Contact.Query().Where(contact.ID(contactId), contact.OrganizationIDEQ(organizationId)).Only(l.ctx)
- // // 获取联系人当前已关联的标签
- // currentLabelRelationships, err := tx.LabelRelationship.Query().Where(labelrelationship.ContactID(contactId)).All(l.ctx)
- // if err != nil {
- // _ = tx.Rollback()
- // return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
- // }
- //
- // // 提取当前标签ID
- // var currentLabelIds []uint64
- // for _, relationship := range currentLabelRelationships {
- // currentLabelIds = append(currentLabelIds, relationship.LabelID)
- // }
- //
- // // 对比新旧标签ID,找出需要新增和移除的标签
- // addLabelIds, removeLabelIds := compareLabelIds(req.LabelIds, currentLabelIds)
- //
- // // 如果 req.UpdateType 为空,或 req.UpdateType 的值为 “all” 时
- // if req.UpdateType == nil || *req.UpdateType == "all" {
- // // 删除需要移除的标签关系
- // for _, id := range removeLabelIds {
- // _, err := tx.LabelRelationship.
- // Delete().
- // Where(
- // labelrelationship.ContactID(*req.ContactId),
- // labelrelationship.LabelID(id),
- // ).
- // Exec(l.ctx)
- // if err != nil {
- // _ = tx.Rollback()
- // return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
- // }
- // }
- // }
- //
- // // 创建需要新增的标签关系
- // for _, id := range addLabelIds {
- // _, _ = tx.LabelRelationship.Create().
- // SetLabelID(id).
- // SetContactID(*req.ContactId).
- // SetOrganizationID(organizationId).
- // Save(l.ctx)
- // //if err != nil {
- // // return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
- // //}
- // }
- //
- // // 获取所有 status 为 3 且 bot_wxid_list 包含 c.wx_wxid 的 sop_task
- // sopTasks, err := tx.SopTask.Query().Where(soptask.Status(3), soptask.OrganizationIDEQ(organizationId)).All(l.ctx)
- // if err != nil {
- // _ = tx.Rollback()
- // return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
- // }
- //
- // var filteredSopTasks []*ent.SopTask
- // for _, task := range sopTasks {
- // for _, botWxid := range task.BotWxidList {
- // if botWxid == c.WxWxid {
- // filteredSopTasks = append(filteredSopTasks, task)
- // break
- // }
- // }
- // }
- //
- // // 获取所有 filteredSopTasks 的 sop_stages
- // var sopStages []*ent.SopStage
- // for _, task := range filteredSopTasks {
- // stages, err := task.QueryTaskStages().All(l.ctx)
- // if err != nil {
- // _ = tx.Rollback()
- // return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
- // }
- // sopStages = append(sopStages, stages...)
- // }
- // err = l.AddLabelRelationships(sopStages, *c, req.LabelIds, organizationId)
- //
- // if err != nil {
- // _ = tx.Rollback()
- // return nil, err
- // }
- // // 所有操作成功,提交事务
- // err = tx.Commit()
- // if err != nil {
- // return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
- // }
- //}
- //
- //return &types.BaseMsgResp{Msg: errormsg.UpdateSuccess}, nil
- return nil, nil
- }
|