jimmyyem 5 сар өмнө
parent
commit
646cf7d8ac

+ 44 - 0
internal/handler/sop_task/get_api_sop_task_list_handler.go

@@ -0,0 +1,44 @@
+package sop_task
+
+import (
+	"net/http"
+
+	"github.com/zeromicro/go-zero/rest/httpx"
+
+	"wechat-api/internal/logic/sop_task"
+	"wechat-api/internal/svc"
+	"wechat-api/internal/types"
+)
+
+// swagger:route post /api/sop_task/list sop_task GetApiSopTaskList
+//
+
+//
+
+//
+// Parameters:
+//  + name: body
+//    require: true
+//    in: body
+//    type: SopApiListReq
+//
+// Responses:
+//  200: SopTaskListResp
+
+func GetApiSopTaskListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
+	return func(w http.ResponseWriter, r *http.Request) {
+		var req types.SopApiListReq
+		if err := httpx.Parse(r, &req, true); err != nil {
+			httpx.ErrorCtx(r.Context(), w, err)
+			return
+		}
+
+		l := sop_task.NewGetApiSopTaskListLogic(r.Context(), svcCtx)
+		resp, err := l.GetApiSopTaskList(&req, r)
+		if err != nil {
+			httpx.ErrorCtx(r.Context(), w, err)
+		} else {
+			httpx.OkJsonCtx(r.Context(), w, resp)
+		}
+	}
+}

+ 77 - 0
internal/logic/sop_task/get_api_sop_task_list_logic.go

@@ -0,0 +1,77 @@
+package sop_task
+
+import (
+	"context"
+	"github.com/suyuan32/simple-admin-common/msg/errormsg"
+	"github.com/suyuan32/simple-admin-common/utils/pointy"
+	"github.com/zeromicro/go-zero/core/errorx"
+	"net/http"
+	"wechat-api/ent/predicate"
+	"wechat-api/ent/soptask"
+	"wechat-api/ent/wx"
+	"wechat-api/hook"
+	"wechat-api/internal/utils/dberrorhandler"
+
+	"wechat-api/internal/svc"
+	"wechat-api/internal/types"
+
+	"github.com/zeromicro/go-zero/core/logx"
+)
+
+type GetApiSopTaskListLogic struct {
+	logx.Logger
+	ctx    context.Context
+	svcCtx *svc.ServiceContext
+}
+
+func NewGetApiSopTaskListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetApiSopTaskListLogic {
+	return &GetApiSopTaskListLogic{
+		Logger: logx.WithContext(ctx),
+		ctx:    ctx,
+		svcCtx: svcCtx}
+}
+
+func (l *GetApiSopTaskListLogic) GetApiSopTaskList(req *types.SopApiListReq, r *http.Request) (*types.SopTaskListResp, error) {
+	tokenStr := r.Header.Get("Authorization")
+	token, err := hook.CheckDesktopAuth(tokenStr, l.svcCtx.DB)
+	if err != nil {
+		return nil, errorx.NewCodeInvalidArgumentError("check auth failed")
+	}
+
+	var predicates []predicate.SopTask
+	predicates = append(predicates, soptask.OrganizationIDEQ(token.OrganizationID))
+	predicates = append(predicates, soptask.StatusEQ(uint8(3)))
+	data, err := l.svcCtx.DB.SopTask.Query().Where(predicates...).Page(l.ctx, req.Page, req.PageSize)
+
+	if err != nil {
+		return nil, dberrorhandler.DefaultEntError(l.Logger, err, nil)
+	}
+
+	resp := &types.SopTaskListResp{}
+	resp.Msg = errormsg.Success
+	resp.Data.Total = data.PageDetails.Total
+
+	for _, v := range data.List {
+		wxInfos, _ := l.svcCtx.DB.Wx.Query().Where(wx.WxidIn(v.BotWxidList...)).All(l.ctx)
+		var botWxidList []string
+		for _, b := range wxInfos {
+			botWxidList = append(botWxidList, b.Nickname)
+		}
+		resp.Data.Data = append(resp.Data.Data, types.SopTaskInfo{
+			BaseIDInfo: types.BaseIDInfo{
+				Id:        &v.ID,
+				CreatedAt: pointy.GetPointer(v.CreatedAt.UnixMilli()),
+				UpdatedAt: pointy.GetPointer(v.UpdatedAt.UnixMilli()),
+			},
+			Status:        &v.Status,
+			Name:          &v.Name,
+			BotWxidList:   botWxidList,
+			Type:          &v.Type,
+			PlanStartTime: pointy.GetUnixMilliPointer(v.PlanStartTime.UnixMilli()),
+			PlanEndTime:   pointy.GetUnixMilliPointer(v.PlanEndTime.UnixMilli()),
+			CreatorId:     &v.CreatorID,
+		})
+	}
+
+	return resp, nil
+}