Explorar o código

优化 sop 任务、阶段、节点接口

boweniac hai 10 meses
pai
achega
5d7a422189

+ 4 - 7
desc/wechat/sop_node.api

@@ -20,10 +20,7 @@ type (
 
     // Get sop node list request params | SopNode列表请求参数
     SopNodeListReq {
-        PageInfo
-
-        // 节点名称 
-        Name  *string `json:"name,optional"`
+        StageId  *uint64 `json:"stageId"`
     }
 
     // SopNode information response | SopNode信息返回体
@@ -58,7 +55,7 @@ service Wechat {
     @handler getSopNodeList
     post /sop_node/list (SopNodeListReq) returns (SopNodeListResp)
 
-    // Get sop node by ID | 通过ID获取SopNode
-    @handler getSopNodeById
-    post /sop_node (IDReq) returns (SopNodeInfoResp)
+    // Get sop node by ID | 通过ID获取SopNode详情
+    @handler getSopNodeDetail
+    post /sop_node/detail (IDReq) returns (SopNodeInfoResp)
 }

+ 2 - 5
desc/wechat/sop_stage.api

@@ -118,10 +118,7 @@ type (
 
     // Get sop stage list request params | SopStage列表请求参数
     SopStageListReq {
-        PageInfo
-
-        // 阶段名称 
-        Name  *string `json:"name,optional"`
+        TaskId  *uint64 `json:"taskId"`
     }
 
     // SopStage information response | SopStage信息返回体
@@ -168,7 +165,7 @@ service Wechat {
     @handler getSopStageById
     post /sop_stage (IDReq) returns (SopStageInfoResp)
 
-    // Get sop stage by ID | 通过ID获取SopStage细节
+    // Get sop stage by ID | 通过ID获取SopStage详情
     @handler getSopStageDetail
     post /sop_stage/detail (IDReq) returns (SopStageInfoResp)
 

+ 1 - 1
desc/wechat/sop_task.api

@@ -65,7 +65,7 @@ service Wechat {
     @handler getSopTaskById
     post /sop_task (IDReq) returns (SopTaskInfoResp)
 
-    // Get sop task by ID | 通过ID获取SopTask细节
+    // Get sop task by ID | 通过ID获取SopTask详情
     @handler getSopTaskDetail
     post /sop_task/detail (IDReq) returns (SopTaskInfoResp)
 }

+ 2 - 2
internal/handler/routes.go

@@ -399,8 +399,8 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
 				},
 				{
 					Method:  http.MethodPost,
-					Path:    "/sop_node",
-					Handler: sop_node.GetSopNodeByIdHandler(serverCtx),
+					Path:    "/sop_node/detail",
+					Handler: sop_node.GetSopNodeDetailHandler(serverCtx),
 				},
 			}...,
 		),

+ 44 - 0
internal/handler/sop_node/get_sop_node_detail_handler.go

@@ -0,0 +1,44 @@
+package sop_node
+
+import (
+	"net/http"
+
+	"github.com/zeromicro/go-zero/rest/httpx"
+
+	"wechat-api/internal/logic/sop_node"
+	"wechat-api/internal/svc"
+	"wechat-api/internal/types"
+)
+
+// swagger:route post /sop_node/detail sop_node GetSopNodeDetail
+//
+// Get sop node by ID | 通过ID获取SopNode详情
+//
+// Get sop node by ID | 通过ID获取SopNode详情
+//
+// Parameters:
+//  + name: body
+//    require: true
+//    in: body
+//    type: IDReq
+//
+// Responses:
+//  200: SopNodeInfoResp
+
+func GetSopNodeDetailHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
+	return func(w http.ResponseWriter, r *http.Request) {
+		var req types.IDReq
+		if err := httpx.Parse(r, &req, true); err != nil {
+			httpx.ErrorCtx(r.Context(), w, err)
+			return
+		}
+
+		l := sop_node.NewGetSopNodeDetailLogic(r.Context(), svcCtx)
+		resp, err := l.GetSopNodeDetail(&req)
+		if err != nil {
+			httpx.ErrorCtx(r.Context(), w, err)
+		} else {
+			httpx.OkJsonCtx(r.Context(), w, resp)
+		}
+	}
+}

+ 66 - 0
internal/logic/sop_node/get_sop_node_detail_logic.go

@@ -0,0 +1,66 @@
+package sop_node
+
+import (
+	"context"
+	"github.com/suyuan32/simple-admin-common/msg/errormsg"
+	"github.com/suyuan32/simple-admin-common/utils/pointy"
+	"wechat-api/internal/utils/dberrorhandler"
+
+	"wechat-api/internal/svc"
+	"wechat-api/internal/types"
+
+	"github.com/zeromicro/go-zero/core/logx"
+)
+
+type GetSopNodeDetailLogic struct {
+	logx.Logger
+	ctx    context.Context
+	svcCtx *svc.ServiceContext
+}
+
+func NewGetSopNodeDetailLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetSopNodeDetailLogic {
+	return &GetSopNodeDetailLogic{
+		Logger: logx.WithContext(ctx),
+		ctx:    ctx,
+		svcCtx: svcCtx}
+}
+
+func (l *GetSopNodeDetailLogic) GetSopNodeDetail(req *types.IDReq) (resp *types.SopNodeInfoResp, err error) {
+	data, err := l.svcCtx.DB.SopNode.Get(l.ctx, req.Id)
+	if err != nil {
+		return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
+	}
+
+	var actionMessage []types.Action
+	if len(data.ActionMessage) > 0 {
+		actionMessage = make([]types.Action, len(data.ActionMessage))
+		for i, condition := range data.ActionMessage {
+			actionMessage[i] = types.Action{
+				Type:    condition.Type,
+				Content: condition.Content,
+			}
+		}
+	}
+
+	return &types.SopNodeInfoResp{
+		BaseDataInfo: types.BaseDataInfo{
+			Code: 0,
+			Msg:  errormsg.Success,
+		},
+		Data: types.SopNodeInfo{
+			BaseIDInfo: types.BaseIDInfo{
+				Id:        &data.ID,
+				CreatedAt: pointy.GetPointer(data.CreatedAt.UnixMilli()),
+				UpdatedAt: pointy.GetPointer(data.UpdatedAt.UnixMilli()),
+			},
+			Status:        &data.Status,
+			StageId:       &data.StageID,
+			ParentId:      &data.ParentID,
+			Name:          &data.Name,
+			ConditionType: &data.ConditionType,
+			ConditionList: data.ConditionList,
+			ActionMessage: actionMessage,
+			ActionLabel:   data.ActionLabel,
+		},
+	}, nil
+}

+ 7 - 5
internal/logic/sop_node/get_sop_node_list_logic.go

@@ -2,6 +2,7 @@ package sop_node
 
 import (
 	"context"
+	"fmt"
 
 	"wechat-api/ent/predicate"
 	"wechat-api/ent/sopnode"
@@ -31,10 +32,12 @@ func NewGetSopNodeListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Ge
 
 func (l *GetSopNodeListLogic) GetSopNodeList(req *types.SopNodeListReq) (*types.SopNodeListResp, error) {
 	var predicates []predicate.SopNode
-	if req.Name != nil {
-		predicates = append(predicates, sopnode.NameContains(*req.Name))
+	if req.StageId != nil {
+		predicates = append(predicates, sopnode.StageID(*req.StageId))
+	} else {
+		return nil, dberrorhandler.DefaultEntError(l.Logger, fmt.Errorf("StageId 不能为空"), req)
 	}
-	data, err := l.svcCtx.DB.SopNode.Query().Where(predicates...).Page(l.ctx, req.Page, req.PageSize)
+	data, err := l.svcCtx.DB.SopNode.Query().Where(predicates...).All(l.ctx)
 
 	if err != nil {
 		return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
@@ -42,9 +45,8 @@ func (l *GetSopNodeListLogic) GetSopNodeList(req *types.SopNodeListReq) (*types.
 
 	resp := &types.SopNodeListResp{}
 	resp.Msg = errormsg.Success
-	resp.Data.Total = data.PageDetails.Total
 
-	for _, v := range data.List {
+	for _, v := range data {
 		var actionMessage []types.Action
 		if len(v.ActionMessage) > 0 {
 			actionMessage = make([]types.Action, len(v.ActionMessage))

+ 7 - 5
internal/logic/sop_stage/get_sop_stage_list_logic.go

@@ -2,6 +2,7 @@ package sop_stage
 
 import (
 	"context"
+	"fmt"
 
 	"wechat-api/ent/predicate"
 	"wechat-api/ent/sopstage"
@@ -31,10 +32,12 @@ func NewGetSopStageListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *G
 
 func (l *GetSopStageListLogic) GetSopStageList(req *types.SopStageListReq) (*types.SopStageListResp, error) {
 	var predicates []predicate.SopStage
-	if req.Name != nil {
-		predicates = append(predicates, sopstage.NameContains(*req.Name))
+	if req.TaskId != nil {
+		predicates = append(predicates, sopstage.TaskID(*req.TaskId))
+	} else {
+		return nil, dberrorhandler.DefaultEntError(l.Logger, fmt.Errorf("TaskID 不能为空"), req)
 	}
-	data, err := l.svcCtx.DB.SopStage.Query().Where(predicates...).Page(l.ctx, req.Page, req.PageSize)
+	data, err := l.svcCtx.DB.SopStage.Query().Where(predicates...).All(l.ctx)
 
 	if err != nil {
 		return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
@@ -42,9 +45,8 @@ func (l *GetSopStageListLogic) GetSopStageList(req *types.SopStageListReq) (*typ
 
 	resp := &types.SopStageListResp{}
 	resp.Msg = errormsg.Success
-	resp.Data.Total = data.PageDetails.Total
 
-	for _, v := range data.List {
+	for _, v := range data {
 		var conditionList []types.Condition
 		if len(v.ConditionList) > 0 {
 			conditionList = make([]types.Condition, len(v.ConditionList))

+ 5 - 0
internal/logic/sop_task/create_sop_task_logic.go

@@ -27,6 +27,11 @@ func NewCreateSopTaskLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Cre
 }
 
 func (l *CreateSopTaskLogic) CreateSopTask(req *types.SopTaskInfo) (*types.BaseMsgResp, 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)
+	}
+
 	currentUserID, _ := l.ctx.Value("userId").(string)
 	fmt.Printf("ctx: %s\n\n", currentUserID)
 	_, err := l.svcCtx.DB.SopTask.Create().

+ 6 - 0
internal/logic/sop_task/update_sop_task_logic.go

@@ -2,6 +2,7 @@ package sop_task
 
 import (
 	"context"
+	"fmt"
 	"wechat-api/internal/svc"
 	"wechat-api/internal/types"
 	"wechat-api/internal/utils/dberrorhandler"
@@ -26,6 +27,11 @@ func NewUpdateSopTaskLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Upd
 }
 
 func (l *UpdateSopTaskLogic) UpdateSopTask(req *types.SopTaskInfo) (*types.BaseMsgResp, 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)
+	}
+
 	// 根据 id 查询 task 信息,如果 Status 的值不为 1,则不允许修改
 	task, err := l.svcCtx.DB.SopTask.Get(l.ctx, *req.Id)
 	if err != nil {

+ 2 - 6
internal/types/types.go

@@ -800,9 +800,7 @@ type SopStageListInfo struct {
 // Get sop stage list request params | SopStage列表请求参数
 // swagger:model SopStageListReq
 type SopStageListReq struct {
-	PageInfo
-	// 阶段名称
-	Name *string `json:"name,optional"`
+	TaskId *uint64 `json:"taskId"`
 }
 
 // SopStage information response | SopStage信息返回体
@@ -840,9 +838,7 @@ type SopNodeListInfo struct {
 // Get sop node list request params | SopNode列表请求参数
 // swagger:model SopNodeListReq
 type SopNodeListReq struct {
-	PageInfo
-	// 节点名称
-	Name *string `json:"name,optional"`
+	StageId *uint64 `json:"stageId"`
 }
 
 // SopNode information response | SopNode信息返回体