Browse Source

优化:创建sop任务、阶段、节点后返回id

boweniac 10 months ago
parent
commit
8faa605d0a

+ 9 - 1
desc/wechat/sop_node.api

@@ -30,6 +30,14 @@ type (
         // SopNode information | SopNode数据
         Data SopNodeInfo `json:"data"`
     }
+
+    // SopNode create response | SopNode创建返回体
+    SopNodeCreateResp {
+        BaseDataInfo
+
+        // SopNode id | SopNode id
+        Data uint64 `json:"data"`
+    }
 )
 
 @server(
@@ -41,7 +49,7 @@ type (
 service Wechat {
     // Create sop node information | 创建SopNode
     @handler createSopNode
-    post /sop_node/create (SopNodeInfo) returns (BaseMsgResp)
+    post /sop_node/create (SopNodeInfo) returns (SopNodeCreateResp)
 
     // Update sop node information | 更新SopNode
     @handler updateSopNode

+ 9 - 1
desc/wechat/sop_stage.api

@@ -129,6 +129,14 @@ type (
         Data SopStageInfo `json:"data"`
     }
 
+    // SopStage create response | SopStage创建回体
+    SopStageCreateResp {
+        BaseDataInfo
+
+        // SopStage id | SopStage id
+        Data uint64 `json:"data"`
+    }
+
     // Move sop stage request params | 移动阶段请求参数
     SopStageMoveReq {
         BaseIDInfo
@@ -147,7 +155,7 @@ type (
 service Wechat {
     // Create sop stage information | 创建SopStage
     @handler createSopStage
-    post /sop_stage/create (SopStageInfo) returns (BaseMsgResp)
+    post /sop_stage/create (SopStageInfo) returns (SopStageCreateResp)
 
     // Update sop stage information | 更新SopStage
     @handler updateSopStage

+ 9 - 1
desc/wechat/sop_task.api

@@ -36,6 +36,14 @@ type (
         // SopTask information | SopTask数据
         Data SopTaskInfo `json:"data"`
     }
+
+    // SopTask create response | SopTask创建回体
+    SopTaskCreateResp {
+        BaseDataInfo
+
+        // SopTask id | SopTask id
+        Data uint64 `json:"data"`
+    }
 )
 
 @server(
@@ -47,7 +55,7 @@ type (
 service Wechat {
     // Create sop task information | 创建SopTask
     @handler createSopTask
-    post /sop_task/create (SopTaskInfo) returns (BaseMsgResp)
+    post /sop_task/create (SopTaskInfo) returns (SopTaskCreateResp)
 
     // Update sop task information | 更新SopTask
     @handler updateSopTask

+ 3 - 3
internal/logic/sop_node/create_sop_node_logic.go

@@ -27,7 +27,7 @@ func NewCreateSopNodeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Cre
 	}
 }
 
-func (l *CreateSopNodeLogic) CreateSopNode(req *types.SopNodeInfo) (*types.BaseMsgResp, error) {
+func (l *CreateSopNodeLogic) CreateSopNode(req *types.SopNodeInfo) (*types.SopNodeCreateResp, error) {
 	// 根据 id 关联查询处 task 信息,并判断 status 是否为 1
 	data, err := l.svcCtx.DB.SopStage.Query().
 		Where(sopstage.ID(*req.StageId)).
@@ -52,7 +52,7 @@ func (l *CreateSopNodeLogic) CreateSopNode(req *types.SopNodeInfo) (*types.BaseM
 		}
 	}
 
-	_, err = l.svcCtx.DB.SopNode.Create().
+	newNode, err := l.svcCtx.DB.SopNode.Create().
 		SetNotNilStatus(req.Status).
 		SetNotNilStageID(req.StageId).
 		SetNotNilParentID(req.ParentId).
@@ -67,5 +67,5 @@ func (l *CreateSopNodeLogic) CreateSopNode(req *types.SopNodeInfo) (*types.BaseM
 		return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
 	}
 
-	return &types.BaseMsgResp{Msg: errormsg.CreateSuccess}, nil
+	return &types.SopNodeCreateResp{BaseDataInfo: types.BaseDataInfo{Msg: errormsg.CreateSuccess}, Data: newNode.ID}, nil
 }

+ 3 - 3
internal/logic/sop_stage/create_sop_stage_logic.go

@@ -28,7 +28,7 @@ func NewCreateSopStageLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Cr
 	}
 }
 
-func (l *CreateSopStageLogic) CreateSopStage(req *types.SopStageInfo) (*types.BaseMsgResp, error) {
+func (l *CreateSopStageLogic) CreateSopStage(req *types.SopStageInfo) (*types.SopStageCreateResp, error) {
 	// 根据 task_id 查询 task 是否存在
 	task, err := l.svcCtx.DB.SopTask.Get(l.ctx, *req.TaskId)
 	if err != nil {
@@ -65,7 +65,7 @@ func (l *CreateSopStageLogic) CreateSopStage(req *types.SopStageInfo) (*types.Ba
 		}
 	}
 
-	_, err = l.svcCtx.DB.SopStage.Create().
+	newStage, err := l.svcCtx.DB.SopStage.Create().
 		SetNotNilStatus(req.Status).
 		SetNotNilTaskID(req.TaskId).
 		SetNotNilName(req.Name).
@@ -81,5 +81,5 @@ func (l *CreateSopStageLogic) CreateSopStage(req *types.SopStageInfo) (*types.Ba
 		return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
 	}
 
-	return &types.BaseMsgResp{Msg: errormsg.CreateSuccess}, nil
+	return &types.SopStageCreateResp{BaseDataInfo: types.BaseDataInfo{Msg: errormsg.CreateSuccess}, Data: newStage.ID}, nil
 }

+ 3 - 3
internal/logic/sop_task/create_sop_task_logic.go

@@ -26,7 +26,7 @@ func NewCreateSopTaskLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Cre
 	}
 }
 
-func (l *CreateSopTaskLogic) CreateSopTask(req *types.SopTaskInfo) (*types.BaseMsgResp, error) {
+func (l *CreateSopTaskLogic) CreateSopTask(req *types.SopTaskInfo) (*types.SopTaskCreateResp, error) {
 	// 判断 planEndTime 和 planStartTime 是否非空,且 planEndTime 是否大于 planStartTime
 	if req.PlanEndTime != nil && req.PlanStartTime != nil && (*req.PlanEndTime <= *req.PlanStartTime) {
 		return nil, dberrorhandler.DefaultEntError(l.Logger, fmt.Errorf("planEndTime must be greater than planStartTime"), req)
@@ -34,7 +34,7 @@ func (l *CreateSopTaskLogic) CreateSopTask(req *types.SopTaskInfo) (*types.BaseM
 
 	currentUserID, _ := l.ctx.Value("userId").(string)
 	fmt.Printf("ctx: %s\n\n", currentUserID)
-	_, err := l.svcCtx.DB.SopTask.Create().
+	newTask, err := l.svcCtx.DB.SopTask.Create().
 		SetNotNilStatus(req.Status).
 		SetNotNilName(req.Name).
 		SetNotNilBotWxidList(req.BotWxidList).
@@ -48,5 +48,5 @@ func (l *CreateSopTaskLogic) CreateSopTask(req *types.SopTaskInfo) (*types.BaseM
 		return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
 	}
 
-	return &types.BaseMsgResp{Msg: errormsg.CreateSuccess}, nil
+	return &types.SopTaskCreateResp{BaseDataInfo: types.BaseDataInfo{Msg: errormsg.CreateSuccess}, Data: newTask.ID}, nil
 }

+ 24 - 0
internal/types/types.go

@@ -718,6 +718,14 @@ type SopTaskInfoResp struct {
 	Data SopTaskInfo `json:"data"`
 }
 
+// SopTask create response | SopTask创建回体
+// swagger:model SopTaskCreateResp
+type SopTaskCreateResp struct {
+	BaseDataInfo
+	// SopTask id | SopTask id
+	Data uint64 `json:"data"`
+}
+
 // The response data of sop stage information | SopStage信息
 // swagger:model SopStageInfo
 type SopStageInfo struct {
@@ -822,6 +830,14 @@ type SopStageInfoResp struct {
 	Data SopStageInfo `json:"data"`
 }
 
+// SopStage create response | SopStage创建回体
+// swagger:model SopStageCreateResp
+type SopStageCreateResp struct {
+	BaseDataInfo
+	// SopStage id | SopStage id
+	Data uint64 `json:"data"`
+}
+
 // Move sop stage request params | 移动阶段请求参数
 // swagger:model SopStageMoveReq
 type SopStageMoveReq struct {
@@ -860,6 +876,14 @@ type SopNodeInfoResp struct {
 	Data SopNodeInfo `json:"data"`
 }
 
+// SopNode create response | SopNode创建返回体
+// swagger:model SopNodeCreateResp
+type SopNodeCreateResp struct {
+	BaseDataInfo
+	// SopNode id | SopNode id
+	Data uint64 `json:"data"`
+}
+
 // The response data of message records information | MessageRecords信息
 // swagger:model MessageRecordsInfo
 type MessageRecordsInfo struct {