Pārlūkot izejas kodu

发布 sop 任务时,publish 接口和 update 接口二合一

boweniac 1 mēnesi atpakaļ
vecāks
revīzija
1b65ecb718

+ 1 - 1
desc/wechat/sop_task.api

@@ -198,7 +198,7 @@ service Wechat {
 
     // Publish sop task | 发布 SopTask
     @handler publishSopTask
-    post /sop_task/publish (IDReq) returns (BaseMsgResp)
+    post /sop_task/publish (SopTaskInfo) returns (BaseMsgResp)
 
     // task start | SopTask 开始
     @handler sopTaskStart

+ 2 - 2
internal/handler/sop_task/publish_sop_task_handler.go

@@ -20,14 +20,14 @@ import (
 //  + name: body
 //    require: true
 //    in: body
-//    type: IDReq
+//    type: SopTaskInfo
 //
 // Responses:
 //  200: BaseMsgResp
 
 func PublishSopTaskHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
 	return func(w http.ResponseWriter, r *http.Request) {
-		var req types.IDReq
+		var req types.SopTaskInfo
 		if err := httpx.Parse(r, &req, true); err != nil {
 			httpx.ErrorCtx(r.Context(), w, err)
 			return

+ 7 - 6
internal/logic/sop_task/publish_sop_task_logic.go

@@ -37,7 +37,7 @@ func NewPublishSopTaskLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Pu
 		svcCtx: svcCtx}
 }
 
-func (l *PublishSopTaskLogic) PublishSopTask(req *types.IDReq) (resp *types.BaseMsgResp, err error) {
+func (l *PublishSopTaskLogic) PublishSopTask(req *types.SopTaskInfo) (resp *types.BaseMsgResp, err error) {
 	organizationId := l.ctx.Value("organizationId").(uint64)
 
 	// 开始事务
@@ -49,7 +49,7 @@ func (l *PublishSopTaskLogic) PublishSopTask(req *types.IDReq) (resp *types.Base
 	// 根据 id 查询 sop_task
 	sopTask, err := l.svcCtx.DB.SopTask.Query().
 		Where(
-			soptask.ID(req.Id),
+			soptask.ID(*req.Id),
 			soptask.Status(1),
 			soptask.OrganizationIDEQ(organizationId),
 		).
@@ -62,11 +62,11 @@ func (l *PublishSopTaskLogic) PublishSopTask(req *types.IDReq) (resp *types.Base
 
 	// 判断 sop_task 是否存在
 	if sopTask != nil {
-		if sopTask.BotWxidList == nil {
+		if req.BotWxidList == nil {
 			return nil, errors.New(errormsg.ValidationError)
 		}
 
-		if len(sopTask.BotWxidList) == 0 {
+		if len(req.BotWxidList) == 0 {
 			return nil, errorx.NewInvalidArgumentError("发信人不能为空")
 		}
 		if len(sopTask.Edges.TaskStages) == 0 {
@@ -74,8 +74,9 @@ func (l *PublishSopTaskLogic) PublishSopTask(req *types.IDReq) (resp *types.Base
 		}
 
 		// 查询任务的所有 sop_stages
-		err = l.svcCtx.DB.SopTask.UpdateOneID(req.Id).
+		err = l.svcCtx.DB.SopTask.UpdateOneID(*req.Id).
 			SetStatus(3).
+			SetBotWxidList(req.BotWxidList).
 			Exec(l.ctx)
 
 		if err != nil {
@@ -128,7 +129,7 @@ func (l *PublishSopTaskLogic) PublishSopTask(req *types.IDReq) (resp *types.Base
 				// 遍历 contacts
 				for _, c := range contacts {
 					// 判断联系人所属微信是否包含在任务当中
-					if sopTask.BotWxidList == nil || (sopTask.BotWxidList != nil && valueInArray(c.WxWxid, sopTask.BotWxidList)) {
+					if req.BotWxidList == nil || (req.BotWxidList != nil && valueInArray(c.WxWxid, req.BotWxidList)) {
 						if stage.ActionMessage != nil {
 							for i, message := range stage.ActionMessage {
 								meta := custom_types.Meta{}