|
@@ -34,13 +34,13 @@ func NewPublishSopTaskLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Pu
|
|
|
|
|
|
func (l *PublishSopTaskLogic) PublishSopTask(req *types.IDReq) (resp *types.BaseMsgResp, err error) {
|
|
|
// 开始事务
|
|
|
- tx, err := l.svcCtx.DB.Tx(context.Background())
|
|
|
- if err != nil {
|
|
|
- return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
|
|
|
- }
|
|
|
+ //tx, err := l.svcCtx.DB.Tx(context.Background())
|
|
|
+ //if err != nil {
|
|
|
+ // return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
|
|
|
+ //}
|
|
|
|
|
|
// 根据 id 查询 sop_task
|
|
|
- sopTask, err := tx.SopTask.Query().
|
|
|
+ sopTask, err := l.svcCtx.DB.SopTask.Query().
|
|
|
Where(
|
|
|
soptask.ID(req.Id),
|
|
|
soptask.Status(1),
|
|
@@ -48,7 +48,7 @@ func (l *PublishSopTaskLogic) PublishSopTask(req *types.IDReq) (resp *types.Base
|
|
|
WithTaskStages().
|
|
|
Only(l.ctx)
|
|
|
if err != nil {
|
|
|
- _ = tx.Rollback()
|
|
|
+ //_ = tx.Rollback()
|
|
|
return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
|
|
|
}
|
|
|
|
|
@@ -59,18 +59,18 @@ func (l *PublishSopTaskLogic) PublishSopTask(req *types.IDReq) (resp *types.Base
|
|
|
}
|
|
|
|
|
|
// 查询任务的所有 sop_stages
|
|
|
- err = tx.SopTask.UpdateOneID(req.Id).
|
|
|
+ err = l.svcCtx.DB.SopTask.UpdateOneID(req.Id).
|
|
|
SetStatus(3).
|
|
|
Exec(l.ctx)
|
|
|
|
|
|
if err != nil {
|
|
|
- _ = tx.Rollback()
|
|
|
+ //_ = tx.Rollback()
|
|
|
return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
|
|
|
}
|
|
|
|
|
|
- sopStages, err := tx.SopStage.Query().All(l.ctx)
|
|
|
+ sopStages, err := l.svcCtx.DB.SopStage.Query().All(l.ctx)
|
|
|
if err != nil {
|
|
|
- _ = tx.Rollback()
|
|
|
+ //_ = tx.Rollback()
|
|
|
return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
|
|
|
}
|
|
|
|
|
@@ -93,13 +93,13 @@ func (l *PublishSopTaskLogic) PublishSopTask(req *types.IDReq) (resp *types.Base
|
|
|
var err error
|
|
|
sourceType := 3
|
|
|
if stage.ConditionOperator == 1 {
|
|
|
- contacts, err = tx.Contact.Query().Where(contact.And(predicates...)).All(l.ctx)
|
|
|
+ contacts, err = l.svcCtx.DB.Contact.Query().Where(contact.And(predicates...)).All(l.ctx)
|
|
|
} else {
|
|
|
- contacts, err = tx.Contact.Query().Where(contact.Or(predicates...)).All(l.ctx)
|
|
|
+ contacts, err = l.svcCtx.DB.Contact.Query().Where(contact.Or(predicates...)).All(l.ctx)
|
|
|
}
|
|
|
|
|
|
if err != nil {
|
|
|
- _ = tx.Rollback()
|
|
|
+ //_ = tx.Rollback()
|
|
|
return nil, err
|
|
|
}
|
|
|
|
|
@@ -108,7 +108,7 @@ func (l *PublishSopTaskLogic) PublishSopTask(req *types.IDReq) (resp *types.Base
|
|
|
// 判断联系人所属微信是否包含在任务当中
|
|
|
if sopTask.BotWxidList == nil || (sopTask.BotWxidList != nil && valueInArray(c.WxWxid, sopTask.BotWxidList)) {
|
|
|
for _, message := range stage.ActionMessage {
|
|
|
- _, _ = tx.MessageRecords.Create().
|
|
|
+ _, _ = l.svcCtx.DB.MessageRecords.Create().
|
|
|
SetNotNilBotWxid(&c.WxWxid).
|
|
|
SetNotNilContactID(&c.ID).
|
|
|
SetNotNilContactType(&c.Type).
|
|
@@ -125,9 +125,9 @@ func (l *PublishSopTaskLogic) PublishSopTask(req *types.IDReq) (resp *types.Base
|
|
|
}
|
|
|
|
|
|
// 查询当前联系人的标签关系
|
|
|
- currentLabelRelationships, err := tx.LabelRelationship.Query().Where(labelrelationship.ContactID(c.ID)).All(l.ctx)
|
|
|
+ currentLabelRelationships, err := l.svcCtx.DB.LabelRelationship.Query().Where(labelrelationship.ContactID(c.ID)).All(l.ctx)
|
|
|
if err != nil {
|
|
|
- _ = tx.Rollback()
|
|
|
+ //_ = tx.Rollback()
|
|
|
return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
|
|
|
}
|
|
|
|
|
@@ -141,7 +141,7 @@ func (l *PublishSopTaskLogic) PublishSopTask(req *types.IDReq) (resp *types.Base
|
|
|
// 递归调用 AddLabelRelationships
|
|
|
err = l.AddLabelRelationships(sopStages, *c, currentLabelIds, stage.ActionLabel)
|
|
|
if err != nil {
|
|
|
- _ = tx.Rollback()
|
|
|
+ //_ = tx.Rollback()
|
|
|
return nil, err
|
|
|
}
|
|
|
}
|
|
@@ -150,18 +150,18 @@ func (l *PublishSopTaskLogic) PublishSopTask(req *types.IDReq) (resp *types.Base
|
|
|
}
|
|
|
}
|
|
|
// 所有操作成功,提交事务
|
|
|
- err = tx.Commit()
|
|
|
- if err != nil {
|
|
|
- return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
|
|
|
- }
|
|
|
+ //err = tx.Commit()
|
|
|
+ //if err != nil {
|
|
|
+ // return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
|
|
|
+ //}
|
|
|
return &types.BaseMsgResp{Msg: errormsg.Success}, nil
|
|
|
} else {
|
|
|
// 所有操作成功,提交事务
|
|
|
- err = tx.Commit()
|
|
|
- if err != nil {
|
|
|
- return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
|
|
|
- }
|
|
|
- // 返回错误信息:任务不存在
|
|
|
+ //err = tx.Commit()
|
|
|
+ //if err != nil {
|
|
|
+ // return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
|
|
|
+ //}
|
|
|
+ //// 返回错误信息:任务不存在
|
|
|
return nil, errors.New(errormsg.TargetNotFound)
|
|
|
}
|
|
|
}
|