jimmyyem 4 тижнів тому
батько
коміт
a638e36b5e

+ 4 - 0
desc/wechat/xunji.api

@@ -89,4 +89,8 @@ service Wechat {
     // Get xunji by ID | 通过ID获取Xunji
     @handler getXunjiById
     post /xunji (IDReq) returns (XunjiInfoResp)
+
+	// Get xunji  | 通过机构ID获取Xunji
+	@handler getXunji
+	post /xunji/detail () returns (XunjiInfoResp)
 }

+ 5 - 0
internal/handler/routes.go

@@ -2212,6 +2212,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
 					Path:    "/xunji",
 					Handler: xunji.GetXunjiByIdHandler(serverCtx),
 				},
+				{
+					Method:  http.MethodPost,
+					Path:    "/xunji/detail",
+					Handler: xunji.GetXunjiHandler(serverCtx),
+				},
 			}...,
 		),
 		rest.WithJwt(serverCtx.Config.Auth.AccessSecret),

+ 31 - 0
internal/handler/xunji/get_xunji_handler.go

@@ -0,0 +1,31 @@
+package xunji
+
+import (
+	"net/http"
+
+	"github.com/zeromicro/go-zero/rest/httpx"
+
+	"wechat-api/internal/logic/xunji"
+	"wechat-api/internal/svc"
+)
+
+// swagger:route post /xunji/detail xunji GetXunji
+//
+// Get xunji  | 通过机构ID获取Xunji
+//
+// Get xunji  | 通过机构ID获取Xunji
+//
+// Responses:
+//  200: XunjiInfoResp
+
+func GetXunjiHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
+	return func(w http.ResponseWriter, r *http.Request) {
+		l := xunji.NewGetXunjiLogic(r.Context(), svcCtx)
+		resp, err := l.GetXunji()
+		if err != nil {
+			httpx.ErrorCtx(r.Context(), w, err)
+		} else {
+			httpx.OkJsonCtx(r.Context(), w, resp)
+		}
+	}
+}

+ 59 - 0
internal/logic/xunji/get_xunji_logic.go

@@ -0,0 +1,59 @@
+package xunji
+
+import (
+	"context"
+	"github.com/suyuan32/simple-admin-common/msg/errormsg"
+	"github.com/suyuan32/simple-admin-common/utils/pointy"
+	"wechat-api/ent"
+	"wechat-api/ent/xunji"
+	"wechat-api/internal/utils/dberrorhandler"
+
+	"wechat-api/internal/svc"
+	"wechat-api/internal/types"
+
+	"github.com/zeromicro/go-zero/core/logx"
+)
+
+type GetXunjiLogic struct {
+	logx.Logger
+	ctx    context.Context
+	svcCtx *svc.ServiceContext
+}
+
+func NewGetXunjiLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetXunjiLogic {
+	return &GetXunjiLogic{
+		Logger: logx.WithContext(ctx),
+		ctx:    ctx,
+		svcCtx: svcCtx}
+}
+
+func (l *GetXunjiLogic) GetXunji() (resp *types.XunjiInfoResp, err error) {
+	organizationId := l.ctx.Value("organizationId").(uint64)
+
+	data, err := l.svcCtx.DB.Xunji.Query().Where(
+		xunji.OrganizationID(organizationId),
+	).Order(ent.Desc(xunji.FieldCreatedAt)).First(l.ctx)
+	if err != nil {
+		return nil, dberrorhandler.DefaultEntError(l.Logger, err, nil)
+	}
+
+	return &types.XunjiInfoResp{
+		BaseDataInfo: types.BaseDataInfo{
+			Code: 0,
+			Msg:  errormsg.Success,
+		},
+		Data: types.XunjiInfo{
+			BaseIDInfo: types.BaseIDInfo{
+				Id:        &data.ID,
+				CreatedAt: pointy.GetPointer(data.CreatedAt.UnixMilli()),
+				UpdatedAt: pointy.GetPointer(data.UpdatedAt.UnixMilli()),
+			},
+			Status:         &data.Status,
+			AppKey:         &data.AppKey,
+			AppSecret:      &data.AppSecret,
+			Token:          &data.Token,
+			EncodingKey:    &data.EncodingKey,
+			OrganizationId: &data.OrganizationID,
+		},
+	}, nil
+}