Compare commits

...

4 Commits

Author SHA1 Message Date
0d65a890f6 commit code
All checks were successful
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 54s
2025-06-01 11:02:33 +08:00
ca373ad91f commit code 2025-05-31 21:44:34 +08:00
bfca5d7d0b commit code 2025-05-31 17:21:57 +08:00
e5446bf836 实现category service基础接口 2025-05-31 16:27:01 +08:00
46 changed files with 1912 additions and 152 deletions

View File

@ -11,6 +11,7 @@ godemo/ # 项目根目录
├── go.sum # 依赖校验
├── docker/ # Docker文件目录
└── docker-gateway/ # gateway服务的Docker文件目录
├── etc/config.yaml # gateway服务配置文件用于配置启动服务Optional
├── Dockerfile # gateway服务的Dockerfile文件
└── docker-compose.yml # gateway服务的docker-compose文件
├── sql/ # 数据库SQL定义
@ -144,7 +145,7 @@ networks:
```bash
# 在对应服务的docker目录执行以file服务为例
> docker/docker-file> docker compose up -d
docker/docker-file> docker compose up -d
```
## RPC服务测试/调试
@ -166,13 +167,25 @@ networks:
**接口定义**
- 用户注册
- 用户登录
- 获取用户信息
- 用户注册
- 用户注销
## 文件服务
- 文件上传
- 获取文件URL下载文件
- 文件删除
```dev
# 上传文件
grpcurl -d '{\"filename\": \"1a.png\", \"folder\": \"zhang san/li si\", \"bucket\": \"wallpaper\", \"content\": \"iVBORw0KGgoAAAANSUhEUgAAAC8AAAAhCAYAAABJLfLcAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAVhSURBVFhH7ZZpbJRFGMd/8777Lu1u6UFpC9tDCqVFDkGOgFDlLHJIQUDQGCFgpOIHvnBpqZRbBEm1FFAwFUzEKxJjKoGABDQoJIggV6jUSmi70O1BW3bb7R7jh22lLPuuQRMbTH/JZLPzzPvMM/95npkRo0aNkjykKP4dDxMdwbcXHcG3F//34AXdJqxg+wfvs+utefQP9bffRbE8zcp3d7CjYD1zU42+TqGgquq/aorwn8mHwb/jfhSEMYSwsM5oTg0dPy1omCIiidQa0QBQSZy2mrWze6B4/9l1IhQPv3++mvXfluP1s+kqryVPJ+e9AvLz81g1oycaICJG8OqWfPK357M5awRRAoQQCCEAgdJGIkVVfQuVEq+USP+GQDFoaJqGZlARBBgjJdLrH/JdhN4NqyXPYcPa6SSo/hYf9Wf38ol1LPMnxKG0ehAGjJ0MKEg8zU7qL+9n/bZjVAaYQXtkBjm5s+llBMeFQnK2HqNSN06JDOBDN3glIoG0+AgUBJ0ff46sKSlo1afYu+coVq+CdDsJG7mYJRO66aZS05V9ZG88isOSgiWs7SiF6CfmkZWRhEFW89NHuzlS5mpjv4u3oYKSiob7UoagwWtGNEUgpUr3SctYMzcNreo423I/5nIjSKkR07svSeFttiY0jWdeyqCHoZIf93/JzzfLuHjOStycDeRmJqCziUHwUF60jlWfXiPQ0nQKNpIRr21i8bDwFlWF77fraJYWjPYNaS5mf85GDl/vRs/Ien4ra0DpHsVEADzcLjnDqeJmQCOuxWuT9QqXyh2YEwfQJ06ltuRXSmo9AGixaTyW1JnG8otctjoxxfejb3df2euhW7C0FKKv/dXZpkANWCYsZ/vOLbz+8miSDCCEvjsAt/U4hXn7OFnpAbxUn/mM/Lw88vJ28vWlO0ig+foR9uQVcsLqW1QwdJSv4/SupZzfI5BSIbpfOsMSQ8FdzaWTZyhrwldEkenEPDmA/r0nMnXg9+y2BsxAHTSSn81l51RfNqtGUxAlA6MzXuJxOrDb7TgcDtwxw5g2axYzx6dgdNix2+3Y7Q4c5ac48kstUkQzZPJILDpS6OF1OXE6W5o7UEkGR3e68KFZrFk0BLOUKMZQjABR6SzJH46U4K44xDsbD3D5h7PYRo4nNnU8GX3O+LsJgovrRZtZ900ZHoykvriJN6d09x8UFB3lQSpGQs1mwsLCMBlbzgnViMlkxmw2Y+7k63MUn+TUtXKunDjGuSr3vU6CohI7agErs7PJzl7GC4MjdI9cPXSVbyo+wJacIpCCyOHzWZKZglZ9kt3bD3LDLZDuBirdgLzKF2tXICWolqlM83eki0J4fBp941v/t5xoD4Cu8q7b5ZSWllL6RynWutbKb6bulpVbNQ00q9Ekp8YR4nsBACADXYO6uLj2VQ6vLFzIwgVZbDhs5UG+Rl/5cNLGjmOgJYrIqCi6JlowAKLLUywtGIOqCkBiO1FAvisSg+Ki2duJhPQRJBoBjxdvgIeYNKUwJjOWrqE+W4hlKBmTmgEIjWlJzc5pjMtMoIv57wtY54Y1MXDR2ywf3SXIVnooP7SVD2/P5I3nU30F3YrjAoXZb/OdTQIaveb+pzesk+qKKhpdIbjqblNju8VNq5WKm7ew2WzYqqqpra2n/s4dROpQamUqca2rlE1cP17Eadv9mjRcOczBczUB3yn3ohA9aDITHzX7G+5BR3kQqgHF68YT0NqGkBh6JkUg3G5cTgf1NTXUNbrb5K+BrmmDSY02IB03OH/uBo57HATCRMKggSSZBO7qYs5erSLQOaYb/MOA7mnzMNARfHvREXx70RF8e/EnBBEDlIbPjKIAAAAASUVORK5CYII=\"}' -plaintext localhost:60200 file.File/Upload
# 获取文件URL
grpcurl -d '{\"file_id\": \"zhangsan/a24c8397-d373-4eb7-a563-b0c9c3f4591c.png\"}' -plaintext localhost:60200 file.File/GetFileUrl
```
## 分类服务
分类服务Category Service这是一个用于统一管理多系统/多模块分类体系的微服务。
@ -193,6 +206,9 @@ grpcurl -plaintext -d '{\"id\": \"d628cf35-539f-4533-a5a2-492d729ecf3b\",\"name\
# 查
grpcurl -plaintext -d '{\"id\": \"d628cf35-539f-4533-a5a2-492d729ecf3b\"}' localhost:60300 category.Category/GetCategory
# 查询某一分类的完整分类(从根分类到当前分类)
grpcurl -plaintext -d '{\"id\": \"da24a78c-ad51-4e82-8aa9-b35342f7ef30\"}' localhost:60300 category.Category/GetFullCategories
```
## 图库服务
@ -208,7 +224,11 @@ grpcurl -plaintext -d '{\"id\": \"d628cf35-539f-4533-a5a2-492d729ecf3b\"}' local
- 获取图片URL
- 下载图片
/api/gallery/v1/
```dev
# 上传图片
grpcurl -d '{\"file_name\": \"1a.png\", \"category_id\": \"da24a78c-ad51-4e82-8aa9-b35342f7ef30\", \"title\": \"背景\", \"file_content\": \"iVBORw0KGgoAAAANSUhEUgAAAC8AAAAhCAYAAABJLfLcAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAVhSURBVFhH7ZZpbJRFGMd/8777Lu1u6UFpC9tDCqVFDkGOgFDlLHJIQUDQGCFgpOIHvnBpqZRbBEm1FFAwFUzEKxJjKoGABDQoJIggV6jUSmi70O1BW3bb7R7jh22lLPuuQRMbTH/JZLPzzPvMM/95npkRo0aNkjykKP4dDxMdwbcXHcG3F//34AXdJqxg+wfvs+utefQP9bffRbE8zcp3d7CjYD1zU42+TqGgquq/aorwn8mHwb/jfhSEMYSwsM5oTg0dPy1omCIiidQa0QBQSZy2mrWze6B4/9l1IhQPv3++mvXfluP1s+kqryVPJ+e9AvLz81g1oycaICJG8OqWfPK357M5awRRAoQQCCEAgdJGIkVVfQuVEq+USP+GQDFoaJqGZlARBBgjJdLrH/JdhN4NqyXPYcPa6SSo/hYf9Wf38ol1LPMnxKG0ehAGjJ0MKEg8zU7qL+9n/bZjVAaYQXtkBjm5s+llBMeFQnK2HqNSN06JDOBDN3glIoG0+AgUBJ0ff46sKSlo1afYu+coVq+CdDsJG7mYJRO66aZS05V9ZG88isOSgiWs7SiF6CfmkZWRhEFW89NHuzlS5mpjv4u3oYKSiob7UoagwWtGNEUgpUr3SctYMzcNreo423I/5nIjSKkR07svSeFttiY0jWdeyqCHoZIf93/JzzfLuHjOStycDeRmJqCziUHwUF60jlWfXiPQ0nQKNpIRr21i8bDwFlWF77fraJYWjPYNaS5mf85GDl/vRs/Ien4ra0DpHsVEADzcLjnDqeJmQCOuxWuT9QqXyh2YEwfQJ06ltuRXSmo9AGixaTyW1JnG8otctjoxxfejb3df2euhW7C0FKKv/dXZpkANWCYsZ/vOLbz+8miSDCCEvjsAt/U4hXn7OFnpAbxUn/mM/Lw88vJ28vWlO0ig+foR9uQVcsLqW1QwdJSv4/SupZzfI5BSIbpfOsMSQ8FdzaWTZyhrwldEkenEPDmA/r0nMnXg9+y2BsxAHTSSn81l51RfNqtGUxAlA6MzXuJxOrDb7TgcDtwxw5g2axYzx6dgdNix2+3Y7Q4c5ac48kstUkQzZPJILDpS6OF1OXE6W5o7UEkGR3e68KFZrFk0BLOUKMZQjABR6SzJH46U4K44xDsbD3D5h7PYRo4nNnU8GX3O+LsJgovrRZtZ900ZHoykvriJN6d09x8UFB3lQSpGQs1mwsLCMBlbzgnViMlkxmw2Y+7k63MUn+TUtXKunDjGuSr3vU6CohI7agErs7PJzl7GC4MjdI9cPXSVbyo+wJacIpCCyOHzWZKZglZ9kt3bD3LDLZDuBirdgLzKF2tXICWolqlM83eki0J4fBp941v/t5xoD4Cu8q7b5ZSWllL6RynWutbKb6bulpVbNQ00q9Ekp8YR4nsBACADXYO6uLj2VQ6vLFzIwgVZbDhs5UG+Rl/5cNLGjmOgJYrIqCi6JlowAKLLUywtGIOqCkBiO1FAvisSg+Ki2duJhPQRJBoBjxdvgIeYNKUwJjOWrqE+W4hlKBmTmgEIjWlJzc5pjMtMoIv57wtY54Y1MXDR2ywf3SXIVnooP7SVD2/P5I3nU30F3YrjAoXZb/OdTQIaveb+pzesk+qKKhpdIbjqblNju8VNq5WKm7ew2WzYqqqpra2n/s4dROpQamUqca2rlE1cP17Eadv9mjRcOczBczUB3yn3ohA9aDITHzX7G+5BR3kQqgHF68YT0NqGkBh6JkUg3G5cTgf1NTXUNbrb5K+BrmmDSY02IB03OH/uBo57HATCRMKggSSZBO7qYs5erSLQOaYb/MOA7mnzMNARfHvREXx70RF8e/EnBBEDlIbPjKIAAAAASUVORK5CYII=\"}' -plaintext localhost:50000 gallery.Gallery/UploadImage
```

View File

@ -1,5 +1,12 @@
syntax = "v1"
// ================== 通用类型定义 ==================
type BaseResp {
Code int `json:"code"` // 状态码 (0=成功)
Message string `json:"message"` // 消息
}
// ================== 用户服务类型 ==================
type RegisterReq {
Username string `json:"username"`
Password string `json:"password"`
@ -40,22 +47,139 @@ type GetUserInfoResp {
Roles []string `json:"roles"`
}
service user-api {
// ================== 分类服务类型 ==================
type BaseCategory {
ID string `json:"id"` // 分类ID (UUID)
SystemID string `json:"systemId"` // 所属系统ID
Name string `json:"name"` // 分类名称
Alias string `json:"alias"` // URL别名
ParentID string `json:"parentId"` // 父分类ID (可为空)
Description string `json:"description"` // 分类描述
CreatedAt string `json:"createdAt"` // 创建时间 (ISO8601)
UpdatedAt string `json:"updatedAt"` // 更新时间 (ISO8601)
}
type CategoryDetail {
BaseCategory
Parent *BaseCategory `json:"parent"` // 父分类信息
}
type TreeNode {
BaseCategory
Children []*TreeNode `json:"children"` // 子分类列表
}
type CreateCategoryReq {
SystemID string `json:"systemId" validate:"required"` // 所属系统ID
Name string `json:"name" validate:"required"` // 分类名称
Alias string `json:"alias,optional"` // URL别名
ParentID string `json:"parentId,optional"` // 父分类ID
Description string `json:"description,optional"` // 分类描述
}
type CreateCategoryResp {
ID string `json:"id"` // 新创建的分类ID
}
type ListCategoriesReq {
SystemID string `form:"systemId,optional"` // 按系统ID过滤
ParentID string `form:"parentId,optional"` // 按父分类ID过滤
Name string `form:"name,optional"` // 按名称模糊搜索
Page int `form:"page,default=1"` // 页码
PageSize int `form:"pageSize,default=20"` // 每页数量
}
type ListCategoriesResp {
Total int64 `json:"total"` // 总数
List []BaseCategory `json:"list"` // 分类列表
}
type GetCategoryReq {
ID string `path:"id"` // 分类ID
}
type CategoryDetailResp {
CategoryDetail
}
type UpdateCategoryReq {
ID string `path:"id"` // 分类ID
Name string `json:"name,optional"` // 新名称
Alias string `json:"alias,optional"` // 新别名
ParentID string `json:"parentId,optional"` // 新父分类ID
Description string `json:"description,optional"` // 新描述
}
type GetCategoryTreeReq {
ID string `path:"id"` // 起始分类ID
}
type CategoryTreeResp {
Root TreeNode `json:"root"` // 分类树根节点
}
type GetSystemCategoriesReq {
SystemID string `path:"system_id"` // 系统ID
ParentID string `form:"parentId,optional"` // 父分类ID (可选)
IncludeDescendants bool `form:"includeDescendants,default=true"` // 是否包含子分类
}
type DeleteCategoryReq {
ID string `path:"id"` // 分类ID
}
// ================== 网关服务定义 ==================
@server (
prefix: /api
)
service gateway-api {
// ===== 用户服务 =====
// 公共接口(无需认证)
@handler registerHandler
post /api/user/register (RegisterReq) returns (RegisterResp)
post /user/register (RegisterReq) returns (RegisterResp)
@handler loginHandler
post /api/user/login (LoginReq) returns (LoginResp)
post /user/login (LoginReq) returns (LoginResp)
}
@server (
jwt: JwtAuth
prefix: /api
jwt: JwtAuth
)
service user-api {
service gateway-api {
@handler logoutHandler
post /api/user/logout (LogoutReq) returns (LogoutResp)
post /user/logout (LogoutReq) returns (LogoutResp)
@handler getUserInfoHandler
get /api/user/:user_id (GetUserInfoReq) returns (GetUserInfoResp)
get /user/:user_id (GetUserInfoReq) returns (GetUserInfoResp)
// ===== 分类服务 =====
// 创建分类
@handler createCategoryHandler
post /category/v1 (CreateCategoryReq) returns (CreateCategoryResp)
// 批量获取分类(带分页和过滤)
@handler listCategoriesHandler
get /category/v1 (ListCategoriesReq) returns (ListCategoriesResp)
// 获取单个分类详情
@handler getCategoryHandler
get /category/v1/:id (GetCategoryReq) returns (CategoryDetailResp)
// 更新分类
@handler updateCategoryHandler
put /category/v1/:id (UpdateCategoryReq) returns (BaseResp)
// 删除分类
@handler deleteCategoryHandler
delete /category/v1/:id (DeleteCategoryReq) returns (BaseResp)
// 获取子分类树
@handler getCategoryTreeHandler
get /category/v1/:id/tree (GetCategoryTreeReq) returns (CategoryTreeResp)
// 根据系统ID获取分类
@handler getSystemCategoriesHandler
get /category/v1/system/:system_id (GetSystemCategoriesReq) returns (ListCategoriesResp)
}

View File

@ -501,6 +501,51 @@ func (x *GetCategoryRequest) GetId() string {
return ""
}
// 获取全分类名称的响应
type GetFullCategoriesResponse struct {
state protoimpl.MessageState `protogen:"open.v1"`
FullCategoryName string `protobuf:"bytes,1,opt,name=full_category_name,json=fullCategoryName,proto3" json:"full_category_name,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *GetFullCategoriesResponse) Reset() {
*x = GetFullCategoriesResponse{}
mi := &file_rpc_category_proto_msgTypes[8]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *GetFullCategoriesResponse) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*GetFullCategoriesResponse) ProtoMessage() {}
func (x *GetFullCategoriesResponse) ProtoReflect() protoreflect.Message {
mi := &file_rpc_category_proto_msgTypes[8]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use GetFullCategoriesResponse.ProtoReflect.Descriptor instead.
func (*GetFullCategoriesResponse) Descriptor() ([]byte, []int) {
return file_rpc_category_proto_rawDescGZIP(), []int{8}
}
func (x *GetFullCategoriesResponse) GetFullCategoryName() string {
if x != nil {
return x.FullCategoryName
}
return ""
}
// 分类信息响应
type CategoryInfoResponse struct {
state protoimpl.MessageState `protogen:"open.v1"`
@ -511,7 +556,7 @@ type CategoryInfoResponse struct {
func (x *CategoryInfoResponse) Reset() {
*x = CategoryInfoResponse{}
mi := &file_rpc_category_proto_msgTypes[8]
mi := &file_rpc_category_proto_msgTypes[9]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
@ -523,7 +568,7 @@ func (x *CategoryInfoResponse) String() string {
func (*CategoryInfoResponse) ProtoMessage() {}
func (x *CategoryInfoResponse) ProtoReflect() protoreflect.Message {
mi := &file_rpc_category_proto_msgTypes[8]
mi := &file_rpc_category_proto_msgTypes[9]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
@ -536,7 +581,7 @@ func (x *CategoryInfoResponse) ProtoReflect() protoreflect.Message {
// Deprecated: Use CategoryInfoResponse.ProtoReflect.Descriptor instead.
func (*CategoryInfoResponse) Descriptor() ([]byte, []int) {
return file_rpc_category_proto_rawDescGZIP(), []int{8}
return file_rpc_category_proto_rawDescGZIP(), []int{9}
}
func (x *CategoryInfoResponse) GetCategory() *CategoryInfo {
@ -557,7 +602,7 @@ type GetChildrenRequest struct {
func (x *GetChildrenRequest) Reset() {
*x = GetChildrenRequest{}
mi := &file_rpc_category_proto_msgTypes[9]
mi := &file_rpc_category_proto_msgTypes[10]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
@ -569,7 +614,7 @@ func (x *GetChildrenRequest) String() string {
func (*GetChildrenRequest) ProtoMessage() {}
func (x *GetChildrenRequest) ProtoReflect() protoreflect.Message {
mi := &file_rpc_category_proto_msgTypes[9]
mi := &file_rpc_category_proto_msgTypes[10]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
@ -582,7 +627,7 @@ func (x *GetChildrenRequest) ProtoReflect() protoreflect.Message {
// Deprecated: Use GetChildrenRequest.ProtoReflect.Descriptor instead.
func (*GetChildrenRequest) Descriptor() ([]byte, []int) {
return file_rpc_category_proto_rawDescGZIP(), []int{9}
return file_rpc_category_proto_rawDescGZIP(), []int{10}
}
func (x *GetChildrenRequest) GetParentId() string {
@ -610,7 +655,7 @@ type GetTreeRequest struct {
func (x *GetTreeRequest) Reset() {
*x = GetTreeRequest{}
mi := &file_rpc_category_proto_msgTypes[10]
mi := &file_rpc_category_proto_msgTypes[11]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
@ -622,7 +667,7 @@ func (x *GetTreeRequest) String() string {
func (*GetTreeRequest) ProtoMessage() {}
func (x *GetTreeRequest) ProtoReflect() protoreflect.Message {
mi := &file_rpc_category_proto_msgTypes[10]
mi := &file_rpc_category_proto_msgTypes[11]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
@ -635,7 +680,7 @@ func (x *GetTreeRequest) ProtoReflect() protoreflect.Message {
// Deprecated: Use GetTreeRequest.ProtoReflect.Descriptor instead.
func (*GetTreeRequest) Descriptor() ([]byte, []int) {
return file_rpc_category_proto_rawDescGZIP(), []int{10}
return file_rpc_category_proto_rawDescGZIP(), []int{11}
}
func (x *GetTreeRequest) GetSystemId() string {
@ -663,7 +708,7 @@ type MoveCategoryRequest struct {
func (x *MoveCategoryRequest) Reset() {
*x = MoveCategoryRequest{}
mi := &file_rpc_category_proto_msgTypes[11]
mi := &file_rpc_category_proto_msgTypes[12]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
@ -675,7 +720,7 @@ func (x *MoveCategoryRequest) String() string {
func (*MoveCategoryRequest) ProtoMessage() {}
func (x *MoveCategoryRequest) ProtoReflect() protoreflect.Message {
mi := &file_rpc_category_proto_msgTypes[11]
mi := &file_rpc_category_proto_msgTypes[12]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
@ -688,7 +733,7 @@ func (x *MoveCategoryRequest) ProtoReflect() protoreflect.Message {
// Deprecated: Use MoveCategoryRequest.ProtoReflect.Descriptor instead.
func (*MoveCategoryRequest) Descriptor() ([]byte, []int) {
return file_rpc_category_proto_rawDescGZIP(), []int{11}
return file_rpc_category_proto_rawDescGZIP(), []int{12}
}
func (x *MoveCategoryRequest) GetId() string {
@ -715,7 +760,7 @@ type GetAncestorPathRequest struct {
func (x *GetAncestorPathRequest) Reset() {
*x = GetAncestorPathRequest{}
mi := &file_rpc_category_proto_msgTypes[12]
mi := &file_rpc_category_proto_msgTypes[13]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
@ -727,7 +772,7 @@ func (x *GetAncestorPathRequest) String() string {
func (*GetAncestorPathRequest) ProtoMessage() {}
func (x *GetAncestorPathRequest) ProtoReflect() protoreflect.Message {
mi := &file_rpc_category_proto_msgTypes[12]
mi := &file_rpc_category_proto_msgTypes[13]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
@ -740,7 +785,7 @@ func (x *GetAncestorPathRequest) ProtoReflect() protoreflect.Message {
// Deprecated: Use GetAncestorPathRequest.ProtoReflect.Descriptor instead.
func (*GetAncestorPathRequest) Descriptor() ([]byte, []int) {
return file_rpc_category_proto_rawDescGZIP(), []int{12}
return file_rpc_category_proto_rawDescGZIP(), []int{13}
}
func (x *GetAncestorPathRequest) GetId() string {
@ -760,7 +805,7 @@ type CategoryPathResponse struct {
func (x *CategoryPathResponse) Reset() {
*x = CategoryPathResponse{}
mi := &file_rpc_category_proto_msgTypes[13]
mi := &file_rpc_category_proto_msgTypes[14]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
@ -772,7 +817,7 @@ func (x *CategoryPathResponse) String() string {
func (*CategoryPathResponse) ProtoMessage() {}
func (x *CategoryPathResponse) ProtoReflect() protoreflect.Message {
mi := &file_rpc_category_proto_msgTypes[13]
mi := &file_rpc_category_proto_msgTypes[14]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
@ -785,7 +830,7 @@ func (x *CategoryPathResponse) ProtoReflect() protoreflect.Message {
// Deprecated: Use CategoryPathResponse.ProtoReflect.Descriptor instead.
func (*CategoryPathResponse) Descriptor() ([]byte, []int) {
return file_rpc_category_proto_rawDescGZIP(), []int{13}
return file_rpc_category_proto_rawDescGZIP(), []int{14}
}
func (x *CategoryPathResponse) GetPath() []*CategoryInfo {
@ -805,7 +850,7 @@ type BatchCreateRequest struct {
func (x *BatchCreateRequest) Reset() {
*x = BatchCreateRequest{}
mi := &file_rpc_category_proto_msgTypes[14]
mi := &file_rpc_category_proto_msgTypes[15]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
@ -817,7 +862,7 @@ func (x *BatchCreateRequest) String() string {
func (*BatchCreateRequest) ProtoMessage() {}
func (x *BatchCreateRequest) ProtoReflect() protoreflect.Message {
mi := &file_rpc_category_proto_msgTypes[14]
mi := &file_rpc_category_proto_msgTypes[15]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
@ -830,7 +875,7 @@ func (x *BatchCreateRequest) ProtoReflect() protoreflect.Message {
// Deprecated: Use BatchCreateRequest.ProtoReflect.Descriptor instead.
func (*BatchCreateRequest) Descriptor() ([]byte, []int) {
return file_rpc_category_proto_rawDescGZIP(), []int{14}
return file_rpc_category_proto_rawDescGZIP(), []int{15}
}
func (x *BatchCreateRequest) GetCategories() []*CreateCategoryRequest {
@ -851,7 +896,7 @@ type BatchCreateResponse struct {
func (x *BatchCreateResponse) Reset() {
*x = BatchCreateResponse{}
mi := &file_rpc_category_proto_msgTypes[15]
mi := &file_rpc_category_proto_msgTypes[16]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
@ -863,7 +908,7 @@ func (x *BatchCreateResponse) String() string {
func (*BatchCreateResponse) ProtoMessage() {}
func (x *BatchCreateResponse) ProtoReflect() protoreflect.Message {
mi := &file_rpc_category_proto_msgTypes[15]
mi := &file_rpc_category_proto_msgTypes[16]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
@ -876,7 +921,7 @@ func (x *BatchCreateResponse) ProtoReflect() protoreflect.Message {
// Deprecated: Use BatchCreateResponse.ProtoReflect.Descriptor instead.
func (*BatchCreateResponse) Descriptor() ([]byte, []int) {
return file_rpc_category_proto_rawDescGZIP(), []int{15}
return file_rpc_category_proto_rawDescGZIP(), []int{16}
}
func (x *BatchCreateResponse) GetCreatedCategories() []*CategoryInfo {
@ -909,7 +954,7 @@ type BatchUpdateRequest struct {
func (x *BatchUpdateRequest) Reset() {
*x = BatchUpdateRequest{}
mi := &file_rpc_category_proto_msgTypes[16]
mi := &file_rpc_category_proto_msgTypes[17]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
@ -921,7 +966,7 @@ func (x *BatchUpdateRequest) String() string {
func (*BatchUpdateRequest) ProtoMessage() {}
func (x *BatchUpdateRequest) ProtoReflect() protoreflect.Message {
mi := &file_rpc_category_proto_msgTypes[16]
mi := &file_rpc_category_proto_msgTypes[17]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
@ -934,7 +979,7 @@ func (x *BatchUpdateRequest) ProtoReflect() protoreflect.Message {
// Deprecated: Use BatchUpdateRequest.ProtoReflect.Descriptor instead.
func (*BatchUpdateRequest) Descriptor() ([]byte, []int) {
return file_rpc_category_proto_rawDescGZIP(), []int{16}
return file_rpc_category_proto_rawDescGZIP(), []int{17}
}
func (x *BatchUpdateRequest) GetCategories() []*UpdateCategoryRequest {
@ -955,7 +1000,7 @@ type BatchUpdateResponse struct {
func (x *BatchUpdateResponse) Reset() {
*x = BatchUpdateResponse{}
mi := &file_rpc_category_proto_msgTypes[17]
mi := &file_rpc_category_proto_msgTypes[18]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
@ -967,7 +1012,7 @@ func (x *BatchUpdateResponse) String() string {
func (*BatchUpdateResponse) ProtoMessage() {}
func (x *BatchUpdateResponse) ProtoReflect() protoreflect.Message {
mi := &file_rpc_category_proto_msgTypes[17]
mi := &file_rpc_category_proto_msgTypes[18]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
@ -980,7 +1025,7 @@ func (x *BatchUpdateResponse) ProtoReflect() protoreflect.Message {
// Deprecated: Use BatchUpdateResponse.ProtoReflect.Descriptor instead.
func (*BatchUpdateResponse) Descriptor() ([]byte, []int) {
return file_rpc_category_proto_rawDescGZIP(), []int{17}
return file_rpc_category_proto_rawDescGZIP(), []int{18}
}
func (x *BatchUpdateResponse) GetUpdatedCategories() []*CategoryInfo {
@ -1019,7 +1064,7 @@ type ListCategoryRequest struct {
func (x *ListCategoryRequest) Reset() {
*x = ListCategoryRequest{}
mi := &file_rpc_category_proto_msgTypes[18]
mi := &file_rpc_category_proto_msgTypes[19]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
@ -1031,7 +1076,7 @@ func (x *ListCategoryRequest) String() string {
func (*ListCategoryRequest) ProtoMessage() {}
func (x *ListCategoryRequest) ProtoReflect() protoreflect.Message {
mi := &file_rpc_category_proto_msgTypes[18]
mi := &file_rpc_category_proto_msgTypes[19]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
@ -1044,7 +1089,7 @@ func (x *ListCategoryRequest) ProtoReflect() protoreflect.Message {
// Deprecated: Use ListCategoryRequest.ProtoReflect.Descriptor instead.
func (*ListCategoryRequest) Descriptor() ([]byte, []int) {
return file_rpc_category_proto_rawDescGZIP(), []int{18}
return file_rpc_category_proto_rawDescGZIP(), []int{19}
}
func (x *ListCategoryRequest) GetSystemId() string {
@ -1100,7 +1145,7 @@ type CategoryListResponse struct {
func (x *CategoryListResponse) Reset() {
*x = CategoryListResponse{}
mi := &file_rpc_category_proto_msgTypes[19]
mi := &file_rpc_category_proto_msgTypes[20]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
@ -1112,7 +1157,7 @@ func (x *CategoryListResponse) String() string {
func (*CategoryListResponse) ProtoMessage() {}
func (x *CategoryListResponse) ProtoReflect() protoreflect.Message {
mi := &file_rpc_category_proto_msgTypes[19]
mi := &file_rpc_category_proto_msgTypes[20]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
@ -1125,7 +1170,7 @@ func (x *CategoryListResponse) ProtoReflect() protoreflect.Message {
// Deprecated: Use CategoryListResponse.ProtoReflect.Descriptor instead.
func (*CategoryListResponse) Descriptor() ([]byte, []int) {
return file_rpc_category_proto_rawDescGZIP(), []int{19}
return file_rpc_category_proto_rawDescGZIP(), []int{20}
}
func (x *CategoryListResponse) GetCategories() []*CategoryInfo {
@ -1152,7 +1197,7 @@ type CategoryTreeResponse struct {
func (x *CategoryTreeResponse) Reset() {
*x = CategoryTreeResponse{}
mi := &file_rpc_category_proto_msgTypes[20]
mi := &file_rpc_category_proto_msgTypes[21]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
@ -1164,7 +1209,7 @@ func (x *CategoryTreeResponse) String() string {
func (*CategoryTreeResponse) ProtoMessage() {}
func (x *CategoryTreeResponse) ProtoReflect() protoreflect.Message {
mi := &file_rpc_category_proto_msgTypes[20]
mi := &file_rpc_category_proto_msgTypes[21]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
@ -1177,7 +1222,7 @@ func (x *CategoryTreeResponse) ProtoReflect() protoreflect.Message {
// Deprecated: Use CategoryTreeResponse.ProtoReflect.Descriptor instead.
func (*CategoryTreeResponse) Descriptor() ([]byte, []int) {
return file_rpc_category_proto_rawDescGZIP(), []int{20}
return file_rpc_category_proto_rawDescGZIP(), []int{21}
}
func (x *CategoryTreeResponse) GetRoot() *CategoryTreeResponse_TreeNode {
@ -1199,7 +1244,7 @@ type CheckAliasRequest struct {
func (x *CheckAliasRequest) Reset() {
*x = CheckAliasRequest{}
mi := &file_rpc_category_proto_msgTypes[21]
mi := &file_rpc_category_proto_msgTypes[22]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
@ -1211,7 +1256,7 @@ func (x *CheckAliasRequest) String() string {
func (*CheckAliasRequest) ProtoMessage() {}
func (x *CheckAliasRequest) ProtoReflect() protoreflect.Message {
mi := &file_rpc_category_proto_msgTypes[21]
mi := &file_rpc_category_proto_msgTypes[22]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
@ -1224,7 +1269,7 @@ func (x *CheckAliasRequest) ProtoReflect() protoreflect.Message {
// Deprecated: Use CheckAliasRequest.ProtoReflect.Descriptor instead.
func (*CheckAliasRequest) Descriptor() ([]byte, []int) {
return file_rpc_category_proto_rawDescGZIP(), []int{21}
return file_rpc_category_proto_rawDescGZIP(), []int{22}
}
func (x *CheckAliasRequest) GetSystemId() string {
@ -1259,7 +1304,7 @@ type CheckAliasResponse struct {
func (x *CheckAliasResponse) Reset() {
*x = CheckAliasResponse{}
mi := &file_rpc_category_proto_msgTypes[22]
mi := &file_rpc_category_proto_msgTypes[23]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
@ -1271,7 +1316,7 @@ func (x *CheckAliasResponse) String() string {
func (*CheckAliasResponse) ProtoMessage() {}
func (x *CheckAliasResponse) ProtoReflect() protoreflect.Message {
mi := &file_rpc_category_proto_msgTypes[22]
mi := &file_rpc_category_proto_msgTypes[23]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
@ -1284,7 +1329,7 @@ func (x *CheckAliasResponse) ProtoReflect() protoreflect.Message {
// Deprecated: Use CheckAliasResponse.ProtoReflect.Descriptor instead.
func (*CheckAliasResponse) Descriptor() ([]byte, []int) {
return file_rpc_category_proto_rawDescGZIP(), []int{22}
return file_rpc_category_proto_rawDescGZIP(), []int{23}
}
func (x *CheckAliasResponse) GetIsAvailable() bool {
@ -1301,6 +1346,150 @@ func (x *CheckAliasResponse) GetExistingId() string {
return ""
}
type GetSystemCategoriesRequest struct {
state protoimpl.MessageState `protogen:"open.v1"`
SystemId string `protobuf:"bytes,1,opt,name=system_id,json=systemId,proto3" json:"system_id,omitempty"` // 系统标识 (必需)
ParentId string `protobuf:"bytes,2,opt,name=parent_id,json=parentId,proto3" json:"parent_id,omitempty"` // 父分类ID (可选)
Page int32 `protobuf:"varint,3,opt,name=page,proto3" json:"page,omitempty"` // 分页参数
PageSize int32 `protobuf:"varint,4,opt,name=page_size,json=pageSize,proto3" json:"page_size,omitempty"` // 分页参数
IncludeDescendants bool `protobuf:"varint,5,opt,name=include_descendants,json=includeDescendants,proto3" json:"include_descendants,omitempty"` // 是否包含后代
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *GetSystemCategoriesRequest) Reset() {
*x = GetSystemCategoriesRequest{}
mi := &file_rpc_category_proto_msgTypes[24]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *GetSystemCategoriesRequest) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*GetSystemCategoriesRequest) ProtoMessage() {}
func (x *GetSystemCategoriesRequest) ProtoReflect() protoreflect.Message {
mi := &file_rpc_category_proto_msgTypes[24]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use GetSystemCategoriesRequest.ProtoReflect.Descriptor instead.
func (*GetSystemCategoriesRequest) Descriptor() ([]byte, []int) {
return file_rpc_category_proto_rawDescGZIP(), []int{24}
}
func (x *GetSystemCategoriesRequest) GetSystemId() string {
if x != nil {
return x.SystemId
}
return ""
}
func (x *GetSystemCategoriesRequest) GetParentId() string {
if x != nil {
return x.ParentId
}
return ""
}
func (x *GetSystemCategoriesRequest) GetPage() int32 {
if x != nil {
return x.Page
}
return 0
}
func (x *GetSystemCategoriesRequest) GetPageSize() int32 {
if x != nil {
return x.PageSize
}
return 0
}
func (x *GetSystemCategoriesRequest) GetIncludeDescendants() bool {
if x != nil {
return x.IncludeDescendants
}
return false
}
type GetSystemCategoriesResponse struct {
state protoimpl.MessageState `protogen:"open.v1"`
Categories []*CategoryInfo `protobuf:"bytes,1,rep,name=categories,proto3" json:"categories,omitempty"`
Total int64 `protobuf:"varint,2,opt,name=total,proto3" json:"total,omitempty"`
CurrentPage int32 `protobuf:"varint,3,opt,name=current_page,json=currentPage,proto3" json:"current_page,omitempty"`
PageSize int32 `protobuf:"varint,4,opt,name=page_size,json=pageSize,proto3" json:"page_size,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *GetSystemCategoriesResponse) Reset() {
*x = GetSystemCategoriesResponse{}
mi := &file_rpc_category_proto_msgTypes[25]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *GetSystemCategoriesResponse) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*GetSystemCategoriesResponse) ProtoMessage() {}
func (x *GetSystemCategoriesResponse) ProtoReflect() protoreflect.Message {
mi := &file_rpc_category_proto_msgTypes[25]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use GetSystemCategoriesResponse.ProtoReflect.Descriptor instead.
func (*GetSystemCategoriesResponse) Descriptor() ([]byte, []int) {
return file_rpc_category_proto_rawDescGZIP(), []int{25}
}
func (x *GetSystemCategoriesResponse) GetCategories() []*CategoryInfo {
if x != nil {
return x.Categories
}
return nil
}
func (x *GetSystemCategoriesResponse) GetTotal() int64 {
if x != nil {
return x.Total
}
return 0
}
func (x *GetSystemCategoriesResponse) GetCurrentPage() int32 {
if x != nil {
return x.CurrentPage
}
return 0
}
func (x *GetSystemCategoriesResponse) GetPageSize() int32 {
if x != nil {
return x.PageSize
}
return 0
}
type CategoryTreeResponse_TreeNode struct {
state protoimpl.MessageState `protogen:"open.v1"`
Category *CategoryInfo `protobuf:"bytes,1,opt,name=category,proto3" json:"category,omitempty"`
@ -1311,7 +1500,7 @@ type CategoryTreeResponse_TreeNode struct {
func (x *CategoryTreeResponse_TreeNode) Reset() {
*x = CategoryTreeResponse_TreeNode{}
mi := &file_rpc_category_proto_msgTypes[23]
mi := &file_rpc_category_proto_msgTypes[26]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
@ -1323,7 +1512,7 @@ func (x *CategoryTreeResponse_TreeNode) String() string {
func (*CategoryTreeResponse_TreeNode) ProtoMessage() {}
func (x *CategoryTreeResponse_TreeNode) ProtoReflect() protoreflect.Message {
mi := &file_rpc_category_proto_msgTypes[23]
mi := &file_rpc_category_proto_msgTypes[26]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
@ -1336,7 +1525,7 @@ func (x *CategoryTreeResponse_TreeNode) ProtoReflect() protoreflect.Message {
// Deprecated: Use CategoryTreeResponse_TreeNode.ProtoReflect.Descriptor instead.
func (*CategoryTreeResponse_TreeNode) Descriptor() ([]byte, []int) {
return file_rpc_category_proto_rawDescGZIP(), []int{20, 0}
return file_rpc_category_proto_rawDescGZIP(), []int{21, 0}
}
func (x *CategoryTreeResponse_TreeNode) GetCategory() *CategoryInfo {
@ -1390,7 +1579,9 @@ const file_rpc_category_proto_rawDesc = "" +
"\x0eDeleteResponse\x12\x18\n" +
"\asuccess\x18\x01 \x01(\bR\asuccess\"$\n" +
"\x12GetCategoryRequest\x12\x0e\n" +
"\x02id\x18\x01 \x01(\tR\x02id\"J\n" +
"\x02id\x18\x01 \x01(\tR\x02id\"I\n" +
"\x19GetFullCategoriesResponse\x12,\n" +
"\x12full_category_name\x18\x01 \x01(\tR\x10fullCategoryName\"J\n" +
"\x14CategoryInfoResponse\x122\n" +
"\bcategory\x18\x01 \x01(\v2\x16.category.CategoryInfoR\bcategory\"O\n" +
"\x12GetChildrenRequest\x12\x1b\n" +
@ -1448,7 +1639,20 @@ const file_rpc_category_proto_rawDesc = "" +
"\x12CheckAliasResponse\x12!\n" +
"\fis_available\x18\x01 \x01(\bR\visAvailable\x12\x1f\n" +
"\vexisting_id\x18\x02 \x01(\tR\n" +
"existingId2\xfd\a\n" +
"existingId\"\xb8\x01\n" +
"\x1aGetSystemCategoriesRequest\x12\x1b\n" +
"\tsystem_id\x18\x01 \x01(\tR\bsystemId\x12\x1b\n" +
"\tparent_id\x18\x02 \x01(\tR\bparentId\x12\x12\n" +
"\x04page\x18\x03 \x01(\x05R\x04page\x12\x1b\n" +
"\tpage_size\x18\x04 \x01(\x05R\bpageSize\x12/\n" +
"\x13include_descendants\x18\x05 \x01(\bR\x12includeDescendants\"\xab\x01\n" +
"\x1bGetSystemCategoriesResponse\x126\n" +
"\n" +
"categories\x18\x01 \x03(\v2\x16.category.CategoryInfoR\n" +
"categories\x12\x14\n" +
"\x05total\x18\x02 \x01(\x03R\x05total\x12!\n" +
"\fcurrent_page\x18\x03 \x01(\x05R\vcurrentPage\x12\x1b\n" +
"\tpage_size\x18\x04 \x01(\x05R\bpageSize2\xb9\t\n" +
"\bCategory\x125\n" +
"\x04Ping\x12\x15.category.PingRequest\x1a\x16.category.PingResponse\x12Q\n" +
"\x0eCreateCategory\x12\x1f.category.CreateCategoryRequest\x1a\x1e.category.CategoryInfoResponse\x12Q\n" +
@ -1463,7 +1667,9 @@ const file_rpc_category_proto_rawDesc = "" +
"\x15BatchUpdateCategories\x12\x1c.category.BatchUpdateRequest\x1a\x1d.category.BatchUpdateResponse\x12O\n" +
"\x0eListCategories\x12\x1d.category.ListCategoryRequest\x1a\x1e.category.CategoryListResponse\x12G\n" +
"\n" +
"CheckAlias\x12\x1b.category.CheckAliasRequest\x1a\x1c.category.CheckAliasResponseB\fZ\n" +
"CheckAlias\x12\x1b.category.CheckAliasRequest\x1a\x1c.category.CheckAliasResponse\x12b\n" +
"\x13GetSystemCategories\x12$.category.GetSystemCategoriesRequest\x1a%.category.GetSystemCategoriesResponse\x12V\n" +
"\x11GetFullCategories\x12\x1c.category.GetCategoryRequest\x1a#.category.GetFullCategoriesResponseB\fZ\n" +
"./categoryb\x06proto3"
var (
@ -1478,7 +1684,7 @@ func file_rpc_category_proto_rawDescGZIP() []byte {
return file_rpc_category_proto_rawDescData
}
var file_rpc_category_proto_msgTypes = make([]protoimpl.MessageInfo, 24)
var file_rpc_category_proto_msgTypes = make([]protoimpl.MessageInfo, 27)
var file_rpc_category_proto_goTypes = []any{
(*PingRequest)(nil), // 0: category.PingRequest
(*PingResponse)(nil), // 1: category.PingResponse
@ -1488,22 +1694,25 @@ var file_rpc_category_proto_goTypes = []any{
(*DeleteCategoryRequest)(nil), // 5: category.DeleteCategoryRequest
(*DeleteResponse)(nil), // 6: category.DeleteResponse
(*GetCategoryRequest)(nil), // 7: category.GetCategoryRequest
(*CategoryInfoResponse)(nil), // 8: category.CategoryInfoResponse
(*GetChildrenRequest)(nil), // 9: category.GetChildrenRequest
(*GetTreeRequest)(nil), // 10: category.GetTreeRequest
(*MoveCategoryRequest)(nil), // 11: category.MoveCategoryRequest
(*GetAncestorPathRequest)(nil), // 12: category.GetAncestorPathRequest
(*CategoryPathResponse)(nil), // 13: category.CategoryPathResponse
(*BatchCreateRequest)(nil), // 14: category.BatchCreateRequest
(*BatchCreateResponse)(nil), // 15: category.BatchCreateResponse
(*BatchUpdateRequest)(nil), // 16: category.BatchUpdateRequest
(*BatchUpdateResponse)(nil), // 17: category.BatchUpdateResponse
(*ListCategoryRequest)(nil), // 18: category.ListCategoryRequest
(*CategoryListResponse)(nil), // 19: category.CategoryListResponse
(*CategoryTreeResponse)(nil), // 20: category.CategoryTreeResponse
(*CheckAliasRequest)(nil), // 21: category.CheckAliasRequest
(*CheckAliasResponse)(nil), // 22: category.CheckAliasResponse
(*CategoryTreeResponse_TreeNode)(nil), // 23: category.CategoryTreeResponse.TreeNode
(*GetFullCategoriesResponse)(nil), // 8: category.GetFullCategoriesResponse
(*CategoryInfoResponse)(nil), // 9: category.CategoryInfoResponse
(*GetChildrenRequest)(nil), // 10: category.GetChildrenRequest
(*GetTreeRequest)(nil), // 11: category.GetTreeRequest
(*MoveCategoryRequest)(nil), // 12: category.MoveCategoryRequest
(*GetAncestorPathRequest)(nil), // 13: category.GetAncestorPathRequest
(*CategoryPathResponse)(nil), // 14: category.CategoryPathResponse
(*BatchCreateRequest)(nil), // 15: category.BatchCreateRequest
(*BatchCreateResponse)(nil), // 16: category.BatchCreateResponse
(*BatchUpdateRequest)(nil), // 17: category.BatchUpdateRequest
(*BatchUpdateResponse)(nil), // 18: category.BatchUpdateResponse
(*ListCategoryRequest)(nil), // 19: category.ListCategoryRequest
(*CategoryListResponse)(nil), // 20: category.CategoryListResponse
(*CategoryTreeResponse)(nil), // 21: category.CategoryTreeResponse
(*CheckAliasRequest)(nil), // 22: category.CheckAliasRequest
(*CheckAliasResponse)(nil), // 23: category.CheckAliasResponse
(*GetSystemCategoriesRequest)(nil), // 24: category.GetSystemCategoriesRequest
(*GetSystemCategoriesResponse)(nil), // 25: category.GetSystemCategoriesResponse
(*CategoryTreeResponse_TreeNode)(nil), // 26: category.CategoryTreeResponse.TreeNode
}
var file_rpc_category_proto_depIdxs = []int32{
2, // 0: category.CategoryInfoResponse.category:type_name -> category.CategoryInfo
@ -1513,40 +1722,45 @@ var file_rpc_category_proto_depIdxs = []int32{
4, // 4: category.BatchUpdateRequest.categories:type_name -> category.UpdateCategoryRequest
2, // 5: category.BatchUpdateResponse.updated_categories:type_name -> category.CategoryInfo
2, // 6: category.CategoryListResponse.categories:type_name -> category.CategoryInfo
23, // 7: category.CategoryTreeResponse.root:type_name -> category.CategoryTreeResponse.TreeNode
2, // 8: category.CategoryTreeResponse.TreeNode.category:type_name -> category.CategoryInfo
23, // 9: category.CategoryTreeResponse.TreeNode.children:type_name -> category.CategoryTreeResponse.TreeNode
0, // 10: category.Category.Ping:input_type -> category.PingRequest
3, // 11: category.Category.CreateCategory:input_type -> category.CreateCategoryRequest
4, // 12: category.Category.UpdateCategory:input_type -> category.UpdateCategoryRequest
5, // 13: category.Category.DeleteCategory:input_type -> category.DeleteCategoryRequest
7, // 14: category.Category.GetCategory:input_type -> category.GetCategoryRequest
9, // 15: category.Category.GetChildren:input_type -> category.GetChildrenRequest
10, // 16: category.Category.GetTree:input_type -> category.GetTreeRequest
11, // 17: category.Category.MoveCategory:input_type -> category.MoveCategoryRequest
12, // 18: category.Category.GetAncestorPath:input_type -> category.GetAncestorPathRequest
14, // 19: category.Category.BatchCreateCategories:input_type -> category.BatchCreateRequest
16, // 20: category.Category.BatchUpdateCategories:input_type -> category.BatchUpdateRequest
18, // 21: category.Category.ListCategories:input_type -> category.ListCategoryRequest
21, // 22: category.Category.CheckAlias:input_type -> category.CheckAliasRequest
1, // 23: category.Category.Ping:output_type -> category.PingResponse
8, // 24: category.Category.CreateCategory:output_type -> category.CategoryInfoResponse
8, // 25: category.Category.UpdateCategory:output_type -> category.CategoryInfoResponse
6, // 26: category.Category.DeleteCategory:output_type -> category.DeleteResponse
8, // 27: category.Category.GetCategory:output_type -> category.CategoryInfoResponse
19, // 28: category.Category.GetChildren:output_type -> category.CategoryListResponse
20, // 29: category.Category.GetTree:output_type -> category.CategoryTreeResponse
8, // 30: category.Category.MoveCategory:output_type -> category.CategoryInfoResponse
13, // 31: category.Category.GetAncestorPath:output_type -> category.CategoryPathResponse
15, // 32: category.Category.BatchCreateCategories:output_type -> category.BatchCreateResponse
17, // 33: category.Category.BatchUpdateCategories:output_type -> category.BatchUpdateResponse
19, // 34: category.Category.ListCategories:output_type -> category.CategoryListResponse
22, // 35: category.Category.CheckAlias:output_type -> category.CheckAliasResponse
23, // [23:36] is the sub-list for method output_type
10, // [10:23] is the sub-list for method input_type
10, // [10:10] is the sub-list for extension type_name
10, // [10:10] is the sub-list for extension extendee
0, // [0:10] is the sub-list for field type_name
26, // 7: category.CategoryTreeResponse.root:type_name -> category.CategoryTreeResponse.TreeNode
2, // 8: category.GetSystemCategoriesResponse.categories:type_name -> category.CategoryInfo
2, // 9: category.CategoryTreeResponse.TreeNode.category:type_name -> category.CategoryInfo
26, // 10: category.CategoryTreeResponse.TreeNode.children:type_name -> category.CategoryTreeResponse.TreeNode
0, // 11: category.Category.Ping:input_type -> category.PingRequest
3, // 12: category.Category.CreateCategory:input_type -> category.CreateCategoryRequest
4, // 13: category.Category.UpdateCategory:input_type -> category.UpdateCategoryRequest
5, // 14: category.Category.DeleteCategory:input_type -> category.DeleteCategoryRequest
7, // 15: category.Category.GetCategory:input_type -> category.GetCategoryRequest
10, // 16: category.Category.GetChildren:input_type -> category.GetChildrenRequest
11, // 17: category.Category.GetTree:input_type -> category.GetTreeRequest
12, // 18: category.Category.MoveCategory:input_type -> category.MoveCategoryRequest
13, // 19: category.Category.GetAncestorPath:input_type -> category.GetAncestorPathRequest
15, // 20: category.Category.BatchCreateCategories:input_type -> category.BatchCreateRequest
17, // 21: category.Category.BatchUpdateCategories:input_type -> category.BatchUpdateRequest
19, // 22: category.Category.ListCategories:input_type -> category.ListCategoryRequest
22, // 23: category.Category.CheckAlias:input_type -> category.CheckAliasRequest
24, // 24: category.Category.GetSystemCategories:input_type -> category.GetSystemCategoriesRequest
7, // 25: category.Category.GetFullCategories:input_type -> category.GetCategoryRequest
1, // 26: category.Category.Ping:output_type -> category.PingResponse
9, // 27: category.Category.CreateCategory:output_type -> category.CategoryInfoResponse
9, // 28: category.Category.UpdateCategory:output_type -> category.CategoryInfoResponse
6, // 29: category.Category.DeleteCategory:output_type -> category.DeleteResponse
9, // 30: category.Category.GetCategory:output_type -> category.CategoryInfoResponse
20, // 31: category.Category.GetChildren:output_type -> category.CategoryListResponse
21, // 32: category.Category.GetTree:output_type -> category.CategoryTreeResponse
9, // 33: category.Category.MoveCategory:output_type -> category.CategoryInfoResponse
14, // 34: category.Category.GetAncestorPath:output_type -> category.CategoryPathResponse
16, // 35: category.Category.BatchCreateCategories:output_type -> category.BatchCreateResponse
18, // 36: category.Category.BatchUpdateCategories:output_type -> category.BatchUpdateResponse
20, // 37: category.Category.ListCategories:output_type -> category.CategoryListResponse
23, // 38: category.Category.CheckAlias:output_type -> category.CheckAliasResponse
25, // 39: category.Category.GetSystemCategories:output_type -> category.GetSystemCategoriesResponse
8, // 40: category.Category.GetFullCategories:output_type -> category.GetFullCategoriesResponse
26, // [26:41] is the sub-list for method output_type
11, // [11:26] is the sub-list for method input_type
11, // [11:11] is the sub-list for extension type_name
11, // [11:11] is the sub-list for extension extendee
0, // [0:11] is the sub-list for field type_name
}
func init() { file_rpc_category_proto_init() }
@ -1560,7 +1774,7 @@ func file_rpc_category_proto_init() {
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: unsafe.Slice(unsafe.StringData(file_rpc_category_proto_rawDesc), len(file_rpc_category_proto_rawDesc)),
NumEnums: 0,
NumMessages: 24,
NumMessages: 27,
NumExtensions: 0,
NumServices: 1,
},

View File

@ -32,6 +32,8 @@ const (
Category_BatchUpdateCategories_FullMethodName = "/category.Category/BatchUpdateCategories"
Category_ListCategories_FullMethodName = "/category.Category/ListCategories"
Category_CheckAlias_FullMethodName = "/category.Category/CheckAlias"
Category_GetSystemCategories_FullMethodName = "/category.Category/GetSystemCategories"
Category_GetFullCategories_FullMethodName = "/category.Category/GetFullCategories"
)
// CategoryClient is the client API for Category service.
@ -58,6 +60,10 @@ type CategoryClient interface {
// 查询过滤
ListCategories(ctx context.Context, in *ListCategoryRequest, opts ...grpc.CallOption) (*CategoryListResponse, error)
CheckAlias(ctx context.Context, in *CheckAliasRequest, opts ...grpc.CallOption) (*CheckAliasResponse, error)
// 根据系统ID获取分类
GetSystemCategories(ctx context.Context, in *GetSystemCategoriesRequest, opts ...grpc.CallOption) (*GetSystemCategoriesResponse, error)
// 获取某一个类别的完整类别(从根类别到当前类别的所有类别)
GetFullCategories(ctx context.Context, in *GetCategoryRequest, opts ...grpc.CallOption) (*GetFullCategoriesResponse, error)
}
type categoryClient struct {
@ -198,6 +204,26 @@ func (c *categoryClient) CheckAlias(ctx context.Context, in *CheckAliasRequest,
return out, nil
}
func (c *categoryClient) GetSystemCategories(ctx context.Context, in *GetSystemCategoriesRequest, opts ...grpc.CallOption) (*GetSystemCategoriesResponse, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(GetSystemCategoriesResponse)
err := c.cc.Invoke(ctx, Category_GetSystemCategories_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *categoryClient) GetFullCategories(ctx context.Context, in *GetCategoryRequest, opts ...grpc.CallOption) (*GetFullCategoriesResponse, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(GetFullCategoriesResponse)
err := c.cc.Invoke(ctx, Category_GetFullCategories_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
return out, nil
}
// CategoryServer is the server API for Category service.
// All implementations must embed UnimplementedCategoryServer
// for forward compatibility.
@ -222,6 +248,10 @@ type CategoryServer interface {
// 查询过滤
ListCategories(context.Context, *ListCategoryRequest) (*CategoryListResponse, error)
CheckAlias(context.Context, *CheckAliasRequest) (*CheckAliasResponse, error)
// 根据系统ID获取分类
GetSystemCategories(context.Context, *GetSystemCategoriesRequest) (*GetSystemCategoriesResponse, error)
// 获取某一个类别的完整类别(从根类别到当前类别的所有类别)
GetFullCategories(context.Context, *GetCategoryRequest) (*GetFullCategoriesResponse, error)
mustEmbedUnimplementedCategoryServer()
}
@ -271,6 +301,12 @@ func (UnimplementedCategoryServer) ListCategories(context.Context, *ListCategory
func (UnimplementedCategoryServer) CheckAlias(context.Context, *CheckAliasRequest) (*CheckAliasResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method CheckAlias not implemented")
}
func (UnimplementedCategoryServer) GetSystemCategories(context.Context, *GetSystemCategoriesRequest) (*GetSystemCategoriesResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method GetSystemCategories not implemented")
}
func (UnimplementedCategoryServer) GetFullCategories(context.Context, *GetCategoryRequest) (*GetFullCategoriesResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method GetFullCategories not implemented")
}
func (UnimplementedCategoryServer) mustEmbedUnimplementedCategoryServer() {}
func (UnimplementedCategoryServer) testEmbeddedByValue() {}
@ -526,6 +562,42 @@ func _Category_CheckAlias_Handler(srv interface{}, ctx context.Context, dec func
return interceptor(ctx, in, info, handler)
}
func _Category_GetSystemCategories_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(GetSystemCategoriesRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(CategoryServer).GetSystemCategories(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: Category_GetSystemCategories_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(CategoryServer).GetSystemCategories(ctx, req.(*GetSystemCategoriesRequest))
}
return interceptor(ctx, in, info, handler)
}
func _Category_GetFullCategories_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(GetCategoryRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(CategoryServer).GetFullCategories(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: Category_GetFullCategories_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(CategoryServer).GetFullCategories(ctx, req.(*GetCategoryRequest))
}
return interceptor(ctx, in, info, handler)
}
// Category_ServiceDesc is the grpc.ServiceDesc for Category service.
// It's only intended for direct use with grpc.RegisterService,
// and not to be introspected or modified (even as a copy)
@ -585,6 +657,14 @@ var Category_ServiceDesc = grpc.ServiceDesc{
MethodName: "CheckAlias",
Handler: _Category_CheckAlias_Handler,
},
{
MethodName: "GetSystemCategories",
Handler: _Category_GetSystemCategories_Handler,
},
{
MethodName: "GetFullCategories",
Handler: _Category_GetFullCategories_Handler,
},
},
Streams: []grpc.StreamDesc{},
Metadata: "rpc/category.proto",

View File

@ -32,6 +32,9 @@ type (
GetAncestorPathRequest = category.GetAncestorPathRequest
GetCategoryRequest = category.GetCategoryRequest
GetChildrenRequest = category.GetChildrenRequest
GetFullCategoriesResponse = category.GetFullCategoriesResponse
GetSystemCategoriesRequest = category.GetSystemCategoriesRequest
GetSystemCategoriesResponse = category.GetSystemCategoriesResponse
GetTreeRequest = category.GetTreeRequest
ListCategoryRequest = category.ListCategoryRequest
MoveCategoryRequest = category.MoveCategoryRequest
@ -58,6 +61,10 @@ type (
// 查询过滤
ListCategories(ctx context.Context, in *ListCategoryRequest, opts ...grpc.CallOption) (*CategoryListResponse, error)
CheckAlias(ctx context.Context, in *CheckAliasRequest, opts ...grpc.CallOption) (*CheckAliasResponse, error)
// 根据系统ID获取分类
GetSystemCategories(ctx context.Context, in *GetSystemCategoriesRequest, opts ...grpc.CallOption) (*GetSystemCategoriesResponse, error)
// 获取某一个类别的完整类别(从根类别到当前类别的所有类别)
GetFullCategories(ctx context.Context, in *GetCategoryRequest, opts ...grpc.CallOption) (*GetFullCategoriesResponse, error)
}
defaultCategory struct {
@ -140,3 +147,15 @@ func (m *defaultCategory) CheckAlias(ctx context.Context, in *CheckAliasRequest,
client := category.NewCategoryClient(m.cli.Conn())
return client.CheckAlias(ctx, in, opts...)
}
// 根据系统ID获取分类
func (m *defaultCategory) GetSystemCategories(ctx context.Context, in *GetSystemCategoriesRequest, opts ...grpc.CallOption) (*GetSystemCategoriesResponse, error) {
client := category.NewCategoryClient(m.cli.Conn())
return client.GetSystemCategories(ctx, in, opts...)
}
// 获取某一个类别的完整类别(从根类别到当前类别的所有类别)
func (m *defaultCategory) GetFullCategories(ctx context.Context, in *GetCategoryRequest, opts ...grpc.CallOption) (*GetFullCategoriesResponse, error) {
client := category.NewCategoryClient(m.cli.Conn())
return client.GetFullCategories(ctx, in, opts...)
}

View File

@ -7,7 +7,7 @@ Etcd:
Key: category.rpc
DB:
DataSource: postgres://postgres:postgres@localhost:5432/godemo?sslmode=disable
DataSource: postgres://postgres:postgres@localhost:19732/godemo?sslmode=disable
MaxOpenConns: 100
MaxIdleConns: 20
ConnMaxLifetime: 3600

View File

@ -0,0 +1,73 @@
package logic
import (
"context"
"errors"
"godemo/category/category"
"godemo/category/internal/model"
"godemo/category/internal/svc"
"github.com/zeromicro/go-zero/core/logx"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
type GetFullCategoriesLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewGetFullCategoriesLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetFullCategoriesLogic {
return &GetFullCategoriesLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
// 获取某一个类别的完整类别(从根类别到当前类别的所有类别)
func (l *GetFullCategoriesLogic) GetFullCategories(in *category.GetCategoryRequest) (*category.GetFullCategoriesResponse, error) {
// 1. 参数校验
if in.Id == "" {
return nil, status.Error(codes.InvalidArgument, "分类ID不能为空")
}
// 2. 查询当前分类
current, err := l.svcCtx.CategoryModel.FindOne(l.ctx, in.Id)
if err != nil {
if errors.Is(err, model.ErrNotFound) {
l.Logger.Errorf("分类不存在, ID: %s", in.Id)
return nil, status.Error(codes.NotFound, "分类不存在")
}
l.Logger.Errorf("数据库查询失败: %v", err)
return nil, status.Error(codes.Internal, "内部错误")
}
// 3. 初始化路径为当前分类名称
fullPath := current.Name
// 4. 循环获取父分类
parentID := current.ParentId
for parentID.Valid {
// 查询父分类
parent, err := l.svcCtx.CategoryModel.FindOne(l.ctx, parentID.String)
if err != nil {
if errors.Is(err, model.ErrNotFound) {
l.Logger.Errorf("父分类不存在, ID: %s", parentID.String)
break // 遇到不存在的父分类时停止循环
}
l.Logger.Errorf("查询父分类失败: %v", err)
break // 其他错误也停止循环
}
// 将父分类名称添加到路径前面
fullPath = parent.Name + "/" + fullPath
parentID = parent.ParentId // 准备查询上一级父分类
}
return &category.GetFullCategoriesResponse{
FullCategoryName: fullPath,
}, nil
}

View File

@ -0,0 +1,167 @@
package logic
import (
"context"
"godemo/category/category"
"godemo/category/internal/model"
"godemo/category/internal/svc"
"github.com/zeromicro/go-zero/core/logx"
"github.com/zeromicro/go-zero/core/stores/sqlx"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
type GetSystemCategoriesLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewGetSystemCategoriesLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetSystemCategoriesLogic {
return &GetSystemCategoriesLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
// 根据系统ID获取分类
func (l *GetSystemCategoriesLogic) GetSystemCategories(in *category.GetSystemCategoriesRequest) (*category.GetSystemCategoriesResponse, error) {
// 1. 参数验证
if in.SystemId == "" {
return nil, status.Error(codes.InvalidArgument, "system_id is required")
}
// 2. 设置默认分页值
page, pageSize := normalizePagination(in.Page, in.PageSize)
// 3. 根据是否包含后代选择查询方式
var categories []*model.Categories
var total int64
var err error
if in.IncludeDescendants {
// 递归查询所有后代
categories, err = l.getDescendantsRecursively(in.SystemId, in.ParentId)
if err != nil {
return nil, status.Error(codes.Internal, "failed to get descendant categories")
}
total = int64(len(categories))
} else {
// 直接查询子分类
categories, total, err = l.getDirectChildren(in.SystemId, in.ParentId, page, pageSize)
if err != nil {
return nil, status.Error(codes.Internal, "failed to get categories")
}
}
// 4. 转换模型到protobuf
pbCategories := make([]*category.CategoryInfo, 0, len(categories))
for _, cat := range categories {
pbCategories = append(pbCategories, convertToPbCategory(cat))
}
// 5. 构建响应
return &category.GetSystemCategoriesResponse{
Categories: pbCategories,
Total: total,
CurrentPage: int32(page),
PageSize: int32(pageSize),
}, nil
}
// 获取直接子分类(非递归)
func (l *GetSystemCategoriesLogic) getDirectChildren(systemID, parentID string, page, pageSize int) ([]*model.Categories, int64, error) {
// 构建基础查询
query := l.svcCtx.CategoryModel.RowBuilder().
Where("system_id = $1", systemID)
// 处理父分类ID
if parentID == "" {
query = query.Where("(parent_id IS NULL OR parent_id = '')")
} else {
query = query.Where("parent_id = $2", parentID)
}
// 获取总数
total, err := l.svcCtx.CategoryModel.FindCount(l.ctx, query.RemoveColumns())
if err != nil {
return nil, 0, err
}
// 分页查询
query = query.OrderBy("created_at DESC").
Offset(uint64((page - 1) * pageSize)).
Limit(uint64(pageSize))
categories, err := l.svcCtx.CategoryModel.FindAll(l.ctx, query)
if err != nil {
return nil, 0, err
}
return categories, total, nil
}
// 递归获取所有后代分类
func (l *GetSystemCategoriesLogic) getDescendantsRecursively(systemID, parentID string) ([]*model.Categories, error) {
// 使用递归CTE查询
query := `
WITH RECURSIVE category_tree AS (
SELECT id, system_id, name, alias, parent_id, description, created_at, updated_at
FROM categories
WHERE system_id = $1
AND (
CASE
WHEN $2 = '' THEN parent_id IS NULL
ELSE parent_id = $2
END
)
UNION ALL
SELECT c.id, c.system_id, c.name, c.alias, c.parent_id, c.description, c.created_at, c.updated_at
FROM categories c
INNER JOIN category_tree ct ON c.parent_id = ct.id
)
SELECT * FROM category_tree
`
var categories []*model.Categories
err := l.svcCtx.SqlConn.QueryRowsCtx(l.ctx, &categories, query, systemID, parentID)
if err != nil && err != sqlx.ErrNotFound {
return nil, err
}
return categories, nil
}
// 转换模型到protobuf
func convertToPbCategory(cat *model.Categories) *category.CategoryInfo {
return &category.CategoryInfo{
Id: cat.Id,
SystemId: cat.SystemId,
Name: cat.Name,
Alias: cat.Alias.String,
ParentId: cat.ParentId.String,
Description: cat.Description.String,
CreatedAt: cat.CreatedAt.Unix(),
UpdatedAt: cat.UpdatedAt.Time.Unix(),
}
}
// 规范化分页参数
func normalizePagination(page, pageSize int32) (int, int) {
p := int(page)
ps := int(pageSize)
if p <= 0 {
p = 1
}
if ps <= 0 {
ps = 20
} else if ps > 100 {
ps = 100
}
return p, ps
}

View File

@ -3,6 +3,7 @@ package model
import (
"context"
"github.com/Masterminds/squirrel"
"github.com/zeromicro/go-zero/core/stores/sqlx"
)
@ -17,6 +18,11 @@ type (
Transact(ctx context.Context, fn func(ctx context.Context, session sqlx.Session) error) error
FindBySystemParentName(ctx context.Context, systemID string, parentID string, name string) (*Categories, error)
FindBySystemParentAlias(ctx context.Context, systemID string, parentID string, alias string) (*Categories, error)
// 新增方法
RowBuilder() squirrel.SelectBuilder
FindCount(ctx context.Context, builder squirrel.SelectBuilder) (int64, error)
FindAll(ctx context.Context, builder squirrel.SelectBuilder) ([]*Categories, error)
}
customCategoriesModel struct {
@ -72,3 +78,81 @@ func (m *customCategoriesModel) FindBySystemParentAlias(ctx context.Context, sys
}
return &resp, nil
}
// === 新增方法实现 ===
// RowBuilder 创建一个基本的SELECT查询构建器
func (m *customCategoriesModel) RowBuilder() squirrel.SelectBuilder {
return squirrel.Select(categoriesRows).From(m.table)
}
// FindCount 执行COUNT查询
func (m *customCategoriesModel) FindCount(ctx context.Context, builder squirrel.SelectBuilder) (int64, error) {
// 将SELECT转换为COUNT
builder = builder.Columns("COUNT(1) AS count")
query, args, err := builder.ToSql()
if err != nil {
return 0, err
}
var count int64
err = m.conn.QueryRowCtx(ctx, &count, query, args...)
if err != nil {
return 0, err
}
return count, nil
}
// FindAll 执行查询并返回所有结果
func (m *customCategoriesModel) FindAll(ctx context.Context, builder squirrel.SelectBuilder) ([]*Categories, error) {
query, args, err := builder.ToSql()
if err != nil {
return nil, err
}
var categories []*Categories
err = m.conn.QueryRowsCtx(ctx, &categories, query, args...)
if err != nil && err != sqlx.ErrNotFound {
return nil, err
}
return categories, nil
}
// === 辅助函数 ===
// 添加分页支持
func (m *customCategoriesModel) FindAllWithPagination(
ctx context.Context,
builder squirrel.SelectBuilder,
orderBy string,
page int,
pageSize int,
) ([]*Categories, int64, error) {
// 获取总数
total, err := m.FindCount(ctx, builder)
if err != nil {
return nil, 0, err
}
// 添加分页
if page > 0 && pageSize > 0 {
offset := (page - 1) * pageSize
builder = builder.Offset(uint64(offset)).Limit(uint64(pageSize))
}
// 添加排序
if orderBy != "" {
builder = builder.OrderBy(orderBy)
}
// 执行查询
categories, err := m.FindAll(ctx, builder)
if err != nil {
return nil, 0, err
}
return categories, total, nil
}

View File

@ -92,3 +92,15 @@ func (s *CategoryServer) CheckAlias(ctx context.Context, in *category.CheckAlias
l := logic.NewCheckAliasLogic(ctx, s.svcCtx)
return l.CheckAlias(in)
}
// 根据系统ID获取分类
func (s *CategoryServer) GetSystemCategories(ctx context.Context, in *category.GetSystemCategoriesRequest) (*category.GetSystemCategoriesResponse, error) {
l := logic.NewGetSystemCategoriesLogic(ctx, s.svcCtx)
return l.GetSystemCategories(in)
}
// 获取某一个类别的完整类别(从根类别到当前类别的所有类别)
func (s *CategoryServer) GetFullCategories(ctx context.Context, in *category.GetCategoryRequest) (*category.GetFullCategoriesResponse, error) {
l := logic.NewGetFullCategoriesLogic(ctx, s.svcCtx)
return l.GetFullCategories(in)
}

View File

@ -11,6 +11,7 @@ import (
type ServiceContext struct {
Config config.Config
CategoryModel model.CategoriesModel
SqlConn sqlx.SqlConn // 添加这个字段
}
func NewServiceContext(c config.Config) *ServiceContext {
@ -18,5 +19,6 @@ func NewServiceContext(c config.Config) *ServiceContext {
return &ServiceContext{
Config: c,
CategoryModel: model.NewCategoriesModel(conn),
SqlConn: conn, // 赋值
}
}

View File

@ -1,7 +1,7 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.36.6
// protoc v3.20.3
// protoc v3.19.4
// source: rpc/file.proto
package file
@ -27,7 +27,8 @@ type UploadRequest struct {
Filename string `protobuf:"bytes,1,opt,name=filename,proto3" json:"filename,omitempty"` // 文件名(建议客户端传原始名,服务端会生成唯一名)
ContentType string `protobuf:"bytes,2,opt,name=content_type,json=contentType,proto3" json:"content_type,omitempty"` // 文件类型(如 image/jpeg
Content []byte `protobuf:"bytes,3,opt,name=content,proto3" json:"content,omitempty"` // 文件二进制内容base64 编码由客户端完成)
Folder string `protobuf:"bytes,4,opt,name=folder,proto3" json:"folder,omitempty"` // 可选,文件夹或分类路径,如 "avatars"、"wallpapers"
Folder string `protobuf:"bytes,4,opt,name=folder,proto3" json:"folder,omitempty"` // 可选,文件夹或分类路径,支持多级,如 "avatars"、"wallpapers/animals"
Bucket string `protobuf:"bytes,5,opt,name=bucket,proto3" json:"bucket,omitempty"` // bucket name
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
@ -90,6 +91,13 @@ func (x *UploadRequest) GetFolder() string {
return ""
}
func (x *UploadRequest) GetBucket() string {
if x != nil {
return x.Bucket
}
return ""
}
// 上传响应
type UploadResponse struct {
state protoimpl.MessageState `protogen:"open.v1"`
@ -327,12 +335,13 @@ var File_rpc_file_proto protoreflect.FileDescriptor
const file_rpc_file_proto_rawDesc = "" +
"\n" +
"\x0erpc/file.proto\x12\x04file\"\x80\x01\n" +
"\x0erpc/file.proto\x12\x04file\"\x98\x01\n" +
"\rUploadRequest\x12\x1a\n" +
"\bfilename\x18\x01 \x01(\tR\bfilename\x12!\n" +
"\fcontent_type\x18\x02 \x01(\tR\vcontentType\x12\x18\n" +
"\acontent\x18\x03 \x01(\fR\acontent\x12\x16\n" +
"\x06folder\x18\x04 \x01(\tR\x06folder\";\n" +
"\x06folder\x18\x04 \x01(\tR\x06folder\x12\x16\n" +
"\x06bucket\x18\x05 \x01(\tR\x06bucket\";\n" +
"\x0eUploadResponse\x12\x17\n" +
"\afile_id\x18\x01 \x01(\tR\x06fileId\x12\x10\n" +
"\x03url\x18\x02 \x01(\tR\x03url\",\n" +

View File

@ -1,7 +1,7 @@
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
// versions:
// - protoc-gen-go-grpc v1.5.1
// - protoc v3.20.3
// - protoc v3.19.4
// source: rpc/file.proto
package file

View File

@ -34,8 +34,8 @@ func NewUploadLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UploadLogi
// 上传文件(图片/头像/壁纸等)
func (l *UploadLogic) Upload(in *file.UploadRequest) (*file.UploadResponse, error) {
bucketName := "default"
if in.Folder != "" {
bucketName = in.Folder
if in.Bucket != "" {
bucketName = in.Bucket
}
// 确保 bucket 存在(自动创建)
@ -54,6 +54,10 @@ func (l *UploadLogic) Upload(in *file.UploadRequest) (*file.UploadResponse, erro
ext := getFileExtension(in.Filename)
newFileName := uuid.New().String() + ext
if in.Folder != "" {
newFileName = in.Folder + "/" + newFileName
}
// 上传对象
_, err = l.svcCtx.MinioClient.PutObject(l.ctx, bucketName, newFileName,
bytes.NewReader(in.Content),

View File

@ -1,5 +1,13 @@
Name: gallery.rpc
ListenOn: 0.0.0.0:50000
Mode: dev
DB:
DataSource: postgres://postgres:postgres@localhost:19732/godemo?sslmode=disable
MaxOpenConns: 100
MaxIdleConns: 20
ConnMaxLifetime: 3600
Etcd:
Hosts:
- 127.0.0.1:2379
@ -10,3 +18,9 @@ FileRpc:
Hosts:
- 127.0.0.1:2379
Key: file.rpc
CategoryRpc:
Etcd:
Hosts:
- 127.0.0.1:2379
Key: category.rpc

View File

@ -4,5 +4,12 @@ import "github.com/zeromicro/go-zero/zrpc"
type Config struct {
zrpc.RpcServerConf
FileRpc zrpc.RpcClientConf
FileRpc zrpc.RpcClientConf
CategoryRpc zrpc.RpcClientConf
DB struct {
DataSource string
MaxOpenConns int
MaxIdleConns int
ConnMaxLifetime int
}
}

View File

@ -2,12 +2,18 @@ package logic
import (
"context"
"database/sql"
"godemo/category/category"
"godemo/file/file"
"godemo/gallery/gallery"
"godemo/gallery/internal/model"
"godemo/gallery/internal/svc"
"github.com/google/uuid"
"github.com/zeromicro/go-zero/core/logx"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
type UploadImageLogic struct {
@ -27,16 +33,38 @@ func NewUploadImageLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Uploa
// 图片上传
func (l *UploadImageLogic) UploadImage(in *gallery.UploadImageRequest) (*gallery.UploadImageResponse, error) {
// 1. 根据 in.CategoryId 查询分类信息,获取分类名称
var categoryName string
getFullCategoryRpcResp, getFullCategoryRpcErr := l.svcCtx.CategoryRpc.GetFullCategories(l.ctx, &category.GetCategoryRequest{
Id: *in.CategoryId,
})
if getFullCategoryRpcErr != nil {
return nil, status.Error(codes.Internal, getFullCategoryRpcErr.Error())
}
// 2. 调用 file rpc Upload 接口上传文件到MinIO
l.svcCtx.FileRpc.Upload(l.ctx, &file.UploadRequest{
fileUploadRpcResp, fileUploadRpcErr := l.svcCtx.FileRpc.Upload(l.ctx, &file.UploadRequest{
Filename: in.FileName,
Content: in.FileContent,
Folder: categoryName,
Folder: getFullCategoryRpcResp.FullCategoryName,
Bucket: "gallery",
})
if fileUploadRpcErr != nil {
return nil, status.Error(codes.Internal, fileUploadRpcErr.Error())
}
// 3. 图片信息存入数据库
insertResult, insertErr := l.svcCtx.ImagesModel.Insert(l.ctx, &model.Images{
ImageId: uuid.New().String(),
StorageKey: *in.Title,
FileName: fileUploadRpcResp.FileId,
MimeType: "image/jpeg",
FileSize: 10,
CategoryId: sql.NullString{String: *in.CategoryId, Valid: true},
})
if insertErr != nil {
return nil, status.Error(codes.Internal, insertErr.Error())
}
print(insertResult.LastInsertId())
// 4. 返回接口执行结果
return &gallery.UploadImageResponse{}, nil

View File

@ -0,0 +1,29 @@
package model
import "github.com/zeromicro/go-zero/core/stores/sqlx"
var _ ImagesModel = (*customImagesModel)(nil)
type (
// ImagesModel is an interface to be customized, add more methods here,
// and implement the added methods in customImagesModel.
ImagesModel interface {
imagesModel
withSession(session sqlx.Session) ImagesModel
}
customImagesModel struct {
*defaultImagesModel
}
)
// NewImagesModel returns a model for the database table.
func NewImagesModel(conn sqlx.SqlConn) ImagesModel {
return &customImagesModel{
defaultImagesModel: newImagesModel(conn),
}
}
func (m *customImagesModel) withSession(session sqlx.Session) ImagesModel {
return NewImagesModel(sqlx.NewSqlConnFromSession(session))
}

View File

@ -0,0 +1,97 @@
// Code generated by goctl. DO NOT EDIT.
// versions:
// goctl version: 1.8.3
package model
import (
"context"
"database/sql"
"fmt"
"strings"
"time"
"github.com/lib/pq"
"github.com/zeromicro/go-zero/core/stores/builder"
"github.com/zeromicro/go-zero/core/stores/sqlx"
"github.com/zeromicro/go-zero/core/stringx"
)
var (
imagesFieldNames = builder.RawFieldNames(&Images{}, true)
imagesRows = strings.Join(imagesFieldNames, ",")
imagesRowsExpectAutoSet = strings.Join(stringx.Remove(imagesFieldNames, "create_at", "create_time", "created_at", "update_at", "update_time", "updated_at"), ",")
imagesRowsWithPlaceHolder = builder.PostgreSqlJoin(stringx.Remove(imagesFieldNames, "image_id", "create_at", "create_time", "created_at", "update_at", "update_time", "updated_at"))
)
type (
imagesModel interface {
Insert(ctx context.Context, data *Images) (sql.Result, error)
FindOne(ctx context.Context, imageId string) (*Images, error)
Update(ctx context.Context, data *Images) error
Delete(ctx context.Context, imageId string) error
}
defaultImagesModel struct {
conn sqlx.SqlConn
table string
}
Images struct {
ImageId string `db:"image_id"`
StorageKey string `db:"storage_key"`
FileName string `db:"file_name"`
MimeType string `db:"mime_type"`
FileSize int64 `db:"file_size"`
Width sql.NullInt64 `db:"width"`
Height sql.NullInt64 `db:"height"`
CategoryId sql.NullString `db:"category_id"`
Tags pq.StringArray `db:"tags"`
CreatedAt time.Time `db:"created_at"`
UpdatedAt time.Time `db:"updated_at"`
IsDeleted bool `db:"is_deleted"`
}
)
func newImagesModel(conn sqlx.SqlConn) *defaultImagesModel {
return &defaultImagesModel{
conn: conn,
table: `"public"."images"`,
}
}
func (m *defaultImagesModel) Delete(ctx context.Context, imageId string) error {
query := fmt.Sprintf("delete from %s where image_id = $1", m.table)
_, err := m.conn.ExecCtx(ctx, query, imageId)
return err
}
func (m *defaultImagesModel) FindOne(ctx context.Context, imageId string) (*Images, error) {
query := fmt.Sprintf("select %s from %s where image_id = $1 limit 1", imagesRows, m.table)
var resp Images
err := m.conn.QueryRowCtx(ctx, &resp, query, imageId)
switch err {
case nil:
return &resp, nil
case sqlx.ErrNotFound:
return nil, ErrNotFound
default:
return nil, err
}
}
func (m *defaultImagesModel) Insert(ctx context.Context, data *Images) (sql.Result, error) {
query := fmt.Sprintf("insert into %s (%s) values ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)", m.table, imagesRowsExpectAutoSet)
ret, err := m.conn.ExecCtx(ctx, query, data.ImageId, data.StorageKey, data.FileName, data.MimeType, data.FileSize, data.Width, data.Height, data.CategoryId, data.Tags, data.IsDeleted)
return ret, err
}
func (m *defaultImagesModel) Update(ctx context.Context, data *Images) error {
query := fmt.Sprintf("update %s set %s where image_id = $1", m.table, imagesRowsWithPlaceHolder)
_, err := m.conn.ExecCtx(ctx, query, data.ImageId, data.StorageKey, data.FileName, data.MimeType, data.FileSize, data.Width, data.Height, data.CategoryId, data.Tags, data.IsDeleted)
return err
}
func (m *defaultImagesModel) tableName() string {
return m.table
}

View File

@ -0,0 +1,5 @@
package model
import "github.com/zeromicro/go-zero/core/stores/sqlx"
var ErrNotFound = sqlx.ErrNotFound

View File

@ -1,21 +1,28 @@
package svc
import (
"godemo/category/category"
"godemo/file/file"
"godemo/gallery/internal/config"
"godemo/gallery/internal/model"
_ "github.com/lib/pq"
"github.com/zeromicro/go-zero/core/stores/sqlx"
"github.com/zeromicro/go-zero/zrpc"
)
type ServiceContext struct {
Config config.Config
FileRpc file.FileClient
Config config.Config
FileRpc file.FileClient
CategoryRpc category.CategoryClient
ImagesModel model.ImagesModel
}
func NewServiceContext(c config.Config) *ServiceContext {
conn := zrpc.MustNewClient(c.FileRpc).Conn()
return &ServiceContext{
Config: c,
FileRpc: file.NewFileClient(conn),
Config: c,
FileRpc: file.NewFileClient(zrpc.MustNewClient(c.FileRpc).Conn()),
CategoryRpc: category.NewCategoryClient(zrpc.MustNewClient(c.CategoryRpc).Conn()),
ImagesModel: model.NewImagesModel(sqlx.NewSqlConn("postgres", c.DB.DataSource)),
}
}

View File

@ -11,3 +11,9 @@ UserRpc:
Hosts:
- 127.0.0.1:2379
Key: user.rpc
CategoryRpc:
Etcd:
Hosts:
- 127.0.0.1:2379
Key: category.rpc

View File

@ -11,5 +11,6 @@ type Config struct {
AccessSecret string
AccessExpire int64
}
UserRpc zrpc.RpcClientConf
UserRpc zrpc.RpcClientConf
CategoryRpc zrpc.RpcClientConf
}

View File

@ -0,0 +1,50 @@
package handler
import (
"net/http"
"godemo/gateway/internal/logic"
"godemo/gateway/internal/svc"
"godemo/gateway/internal/types"
"github.com/zeromicro/go-zero/rest/httpx"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
func createCategoryHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.CreateCategoryReq
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := logic.NewCreateCategoryLogic(r.Context(), svcCtx)
resp, err := l.CreateCategory(&req)
if err != nil {
if s, ok := status.FromError(err); ok {
// 判断 gRPC 错误码,并自定义 HTTP 返回
var code int
switch s.Code() {
case codes.NotFound:
code = http.StatusNotFound
case codes.InvalidArgument:
code = http.StatusBadRequest
default:
code = http.StatusInternalServerError
}
// 自定义 JSON 错误格式
httpx.WriteJson(w, code, map[string]interface{}{
"code": code,
"message": s.Message(),
})
} else {
httpx.ErrorCtx(r.Context(), w, err)
}
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}

View File

@ -0,0 +1,28 @@
package handler
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"godemo/gateway/internal/logic"
"godemo/gateway/internal/svc"
"godemo/gateway/internal/types"
)
func deleteCategoryHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.DeleteCategoryReq
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := logic.NewDeleteCategoryLogic(r.Context(), svcCtx)
resp, err := l.DeleteCategory(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}

View File

@ -0,0 +1,28 @@
package handler
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"godemo/gateway/internal/logic"
"godemo/gateway/internal/svc"
"godemo/gateway/internal/types"
)
func getCategoryHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.GetCategoryReq
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := logic.NewGetCategoryLogic(r.Context(), svcCtx)
resp, err := l.GetCategory(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}

View File

@ -0,0 +1,28 @@
package handler
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"godemo/gateway/internal/logic"
"godemo/gateway/internal/svc"
"godemo/gateway/internal/types"
)
func getCategoryTreeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.GetCategoryTreeReq
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := logic.NewGetCategoryTreeLogic(r.Context(), svcCtx)
resp, err := l.GetCategoryTree(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}

View File

@ -0,0 +1,28 @@
package handler
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"godemo/gateway/internal/logic"
"godemo/gateway/internal/svc"
"godemo/gateway/internal/types"
)
func getSystemCategoriesHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.GetSystemCategoriesReq
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := logic.NewGetSystemCategoriesLogic(r.Context(), svcCtx)
resp, err := l.GetSystemCategories(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}

View File

@ -0,0 +1,28 @@
package handler
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"godemo/gateway/internal/logic"
"godemo/gateway/internal/svc"
"godemo/gateway/internal/types"
)
func listCategoriesHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.ListCategoriesReq
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := logic.NewListCategoriesLogic(r.Context(), svcCtx)
resp, err := l.ListCategories(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}

View File

@ -16,30 +16,67 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
[]rest.Route{
{
Method: http.MethodPost,
Path: "/api/user/login",
Path: "/user/login",
Handler: loginHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/api/user/register",
Path: "/user/register",
Handler: registerHandler(serverCtx),
},
},
rest.WithPrefix("/api"),
)
server.AddRoutes(
[]rest.Route{
{
Method: http.MethodPost,
Path: "/category/v1",
Handler: createCategoryHandler(serverCtx),
},
{
Method: http.MethodGet,
Path: "/api/user/:user_id",
Path: "/category/v1",
Handler: listCategoriesHandler(serverCtx),
},
{
Method: http.MethodGet,
Path: "/category/v1/:id",
Handler: getCategoryHandler(serverCtx),
},
{
Method: http.MethodPut,
Path: "/category/v1/:id",
Handler: updateCategoryHandler(serverCtx),
},
{
Method: http.MethodDelete,
Path: "/category/v1/:id",
Handler: deleteCategoryHandler(serverCtx),
},
{
Method: http.MethodGet,
Path: "/category/v1/:id/tree",
Handler: getCategoryTreeHandler(serverCtx),
},
{
Method: http.MethodGet,
Path: "/category/v1/system/:system_id",
Handler: getSystemCategoriesHandler(serverCtx),
},
{
Method: http.MethodGet,
Path: "/user/:user_id",
Handler: getUserInfoHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/api/user/logout",
Path: "/user/logout",
Handler: logoutHandler(serverCtx),
},
},
rest.WithJwt(serverCtx.Config.JwtAuth.AccessSecret),
rest.WithPrefix("/api"),
)
}

View File

@ -0,0 +1,28 @@
package handler
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"godemo/gateway/internal/logic"
"godemo/gateway/internal/svc"
"godemo/gateway/internal/types"
)
func updateCategoryHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.UpdateCategoryReq
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := logic.NewUpdateCategoryLogic(r.Context(), svcCtx)
resp, err := l.UpdateCategory(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}

View File

@ -0,0 +1,103 @@
package logic
import (
"context"
"strings"
"godemo/category/category"
"godemo/gateway/internal/svc"
"godemo/gateway/internal/types"
"github.com/zeromicro/go-zero/core/logx"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
type CreateCategoryLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewCreateCategoryLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateCategoryLogic {
return &CreateCategoryLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *CreateCategoryLogic) CreateCategory(req *types.CreateCategoryReq) (resp *types.CreateCategoryResp, err error) {
// 1. 参数验证
if err := validateCreateRequest(req); err != nil {
return nil, err
}
// 2. 准备 RPC 请求
rpcReq := &category.CreateCategoryRequest{
SystemId: req.SystemID,
Name: req.Name,
Description: req.Description,
}
// 可选参数处理
if req.Alias != "" {
rpcReq.Alias = req.Alias
}
if req.ParentID != "" {
rpcReq.ParentId = req.ParentID
}
// 3. 调用 RPC 服务
rpcResp, rpcErr := l.svcCtx.CategoryRpc.CreateCategory(l.ctx, rpcReq)
if rpcErr != nil {
return nil, rpcErr
}
// 4. 构建响应
resp = &types.CreateCategoryResp{
ID: rpcResp.Category.Id,
}
l.Logger.Infof("Category created successfully: ID=%s, Name=%s", resp.ID, req.Name)
return resp, nil
}
// validateCreateRequest 验证创建分类请求
func validateCreateRequest(req *types.CreateCategoryReq) error {
// 必需字段检查
if strings.TrimSpace(req.SystemID) == "" {
return status.Error(codes.InvalidArgument, "systemId不能为空")
}
if strings.TrimSpace(req.Name) == "" {
return status.Error(codes.InvalidArgument, "name不能为空")
}
// 名称长度限制
if len(req.Name) > 50 {
return status.Error(codes.InvalidArgument, "alias cannot exceed 50 characters")
}
// 别名格式验证 (只允许字母、数字、连字符和下划线)
// if req.Alias != "" {
// if len(req.Alias) > 50 {
// return errors.New("alias cannot exceed 50 characters")
// }
// for _, ch := range req.Alias {
// if !(ch >= 'a' && ch <= 'z') &&
// !(ch >= 'A' && ch <= 'Z') &&
// !(ch >= '0' && ch <= '9') &&
// ch != '-' && ch != '_' {
// return errors.New("alias can only contain letters, numbers, hyphens and underscores")
// }
// }
// }
// 描述长度限制
if len(req.Description) > 500 {
return status.Error(codes.InvalidArgument, "description cannot exceed 500 characters")
}
return nil
}

View File

@ -0,0 +1,30 @@
package logic
import (
"context"
"godemo/gateway/internal/svc"
"godemo/gateway/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type DeleteCategoryLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewDeleteCategoryLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteCategoryLogic {
return &DeleteCategoryLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *DeleteCategoryLogic) DeleteCategory(req *types.DeleteCategoryReq) (resp *types.BaseResp, err error) {
// todo: add your logic here and delete this line
return
}

View File

@ -0,0 +1,59 @@
package logic
import (
"context"
"time"
"godemo/category/category"
"godemo/gateway/internal/svc"
"godemo/gateway/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type GetCategoryLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewGetCategoryLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetCategoryLogic {
return &GetCategoryLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *GetCategoryLogic) GetCategory(req *types.GetCategoryReq) (resp *types.CategoryDetailResp, err error) {
rpcResp, err := l.svcCtx.CategoryRpc.GetCategory(l.ctx, &category.GetCategoryRequest{
Id: req.ID,
})
if err != nil {
return nil, err
}
// 转换主分类的时间
createdAtStr := time.Unix(rpcResp.Category.CreatedAt, 0).Format(time.RFC3339)
updatedAtStr := ""
if rpcResp.Category.UpdatedAt != 0 {
updatedAtStr = time.Unix(rpcResp.Category.UpdatedAt, 0).Format(time.RFC3339)
}
resp = &types.CategoryDetailResp{
CategoryDetail: types.CategoryDetail{
BaseCategory: types.BaseCategory{
ID: rpcResp.Category.Id,
Name: rpcResp.Category.Name,
Alias: rpcResp.Category.Alias,
Description: rpcResp.Category.Description,
ParentID: rpcResp.Category.ParentId,
SystemID: rpcResp.Category.SystemId,
CreatedAt: createdAtStr,
UpdatedAt: updatedAtStr,
},
Parent: nil,
},
}
return
}

View File

@ -0,0 +1,30 @@
package logic
import (
"context"
"godemo/gateway/internal/svc"
"godemo/gateway/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type GetCategoryTreeLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewGetCategoryTreeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetCategoryTreeLogic {
return &GetCategoryTreeLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *GetCategoryTreeLogic) GetCategoryTree(req *types.GetCategoryTreeReq) (resp *types.CategoryTreeResp, err error) {
// todo: add your logic here and delete this line
return
}

View File

@ -0,0 +1,97 @@
package logic
import (
"context"
"strings"
"time"
"godemo/category/category"
"godemo/gateway/internal/svc"
"godemo/gateway/internal/types"
"github.com/zeromicro/go-zero/core/logx"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
type GetSystemCategoriesLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewGetSystemCategoriesLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetSystemCategoriesLogic {
return &GetSystemCategoriesLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *GetSystemCategoriesLogic) GetSystemCategories(req *types.GetSystemCategoriesReq) (resp *types.ListCategoriesResp, err error) {
// 1. 验证系统ID
if strings.TrimSpace(req.SystemID) == "" {
return nil, status.Error(codes.InvalidArgument, "system_id is required")
}
// 2. 准备 RPC 请求
rpcReq := &category.GetSystemCategoriesRequest{
SystemId: req.SystemID,
IncludeDescendants: req.IncludeDescendants,
}
// 添加父分类ID过滤如果提供
if req.ParentID != "" {
rpcReq.ParentId = req.ParentID
}
// 3. 调用 RPC 服务
rpcResp, rpcErr := l.svcCtx.CategoryRpc.GetSystemCategories(l.ctx, rpcReq)
if rpcErr != nil {
st, ok := status.FromError(rpcErr)
if ok && st.Code() == codes.NotFound {
// 返回空列表而不是错误
return &types.ListCategoriesResp{
Total: 0,
List: []types.BaseCategory{},
}, nil
}
l.Logger.Errorf("RPC error: %v", rpcErr)
return nil, rpcErr
}
// 4. 转换响应数据
categories := make([]types.BaseCategory, 0, len(rpcResp.Categories))
for _, cat := range rpcResp.Categories {
// 转换时间格式
createdAt := ""
if cat.CreatedAt > 0 {
createdAt = time.Unix(cat.CreatedAt, 0).Format(time.RFC3339)
}
updatedAt := ""
if cat.UpdatedAt > 0 {
updatedAt = time.Unix(cat.UpdatedAt, 0).Format(time.RFC3339)
}
categories = append(categories, types.BaseCategory{
ID: cat.Id,
SystemID: cat.SystemId,
Name: cat.Name,
Alias: cat.Alias,
ParentID: cat.ParentId,
Description: cat.Description,
CreatedAt: createdAt,
UpdatedAt: updatedAt,
})
}
// 5. 构建响应
resp = &types.ListCategoriesResp{
Total: rpcResp.Total,
List: categories,
}
l.Logger.Infof("Retrieved %d categories for system %s (parent: %s)", len(categories), req.SystemID, req.ParentID)
return resp, nil
}

View File

@ -0,0 +1,30 @@
package logic
import (
"context"
"godemo/gateway/internal/svc"
"godemo/gateway/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type ListCategoriesLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewListCategoriesLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListCategoriesLogic {
return &ListCategoriesLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *ListCategoriesLogic) ListCategories(req *types.ListCategoriesReq) (resp *types.ListCategoriesResp, err error) {
// todo: add your logic here and delete this line
return
}

View File

@ -0,0 +1,30 @@
package logic
import (
"context"
"godemo/gateway/internal/svc"
"godemo/gateway/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type UpdateCategoryLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewUpdateCategoryLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateCategoryLogic {
return &UpdateCategoryLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *UpdateCategoryLogic) UpdateCategory(req *types.UpdateCategoryReq) (resp *types.BaseResp, err error) {
// todo: add your logic here and delete this line
return
}

View File

@ -1,6 +1,7 @@
package svc
import (
"godemo/category/category"
"godemo/gateway/internal/config"
"godemo/user/user"
@ -8,14 +9,15 @@ import (
)
type ServiceContext struct {
Config config.Config
UserRpc user.UserClient
Config config.Config
UserRpc user.UserClient
CategoryRpc category.CategoryClient
}
func NewServiceContext(c config.Config) *ServiceContext {
conn := zrpc.MustNewClient(c.UserRpc).Conn()
return &ServiceContext{
Config: c,
UserRpc: user.NewUserClient(conn),
Config: c,
UserRpc: user.NewUserClient(zrpc.MustNewClient(c.UserRpc).Conn()),
CategoryRpc: category.NewCategoryClient(zrpc.MustNewClient(c.CategoryRpc).Conn()),
}
}

View File

@ -3,6 +3,65 @@
package types
type BaseCategory struct {
ID string `json:"id"` // 分类ID (UUID)
SystemID string `json:"systemId"` // 所属系统ID
Name string `json:"name"` // 分类名称
Alias string `json:"alias"` // URL别名
ParentID string `json:"parentId"` // 父分类ID (可为空)
Description string `json:"description"` // 分类描述
CreatedAt string `json:"createdAt"` // 创建时间 (ISO8601)
UpdatedAt string `json:"updatedAt"` // 更新时间 (ISO8601)
}
type BaseResp struct {
Code int `json:"code"` // 状态码 (0=成功)
Message string `json:"message"` // 消息
}
type CategoryDetail struct {
BaseCategory
Parent *BaseCategory `json:"parent"` // 父分类信息
}
type CategoryDetailResp struct {
CategoryDetail
}
type CategoryTreeResp struct {
Root TreeNode `json:"root"` // 分类树根节点
}
type CreateCategoryReq struct {
SystemID string `json:"systemId" validate:"required"` // 所属系统ID
Name string `json:"name" validate:"required"` // 分类名称
Alias string `json:"alias,optional"` // URL别名
ParentID string `json:"parentId,optional"` // 父分类ID
Description string `json:"description,optional"` // 分类描述
}
type CreateCategoryResp struct {
ID string `json:"id"` // 新创建的分类ID
}
type DeleteCategoryReq struct {
ID string `path:"id"` // 分类ID
}
type GetCategoryReq struct {
ID string `path:"id"` // 分类ID
}
type GetCategoryTreeReq struct {
ID string `path:"id"` // 起始分类ID
}
type GetSystemCategoriesReq struct {
SystemID string `path:"system_id"` // 系统ID
ParentID string `form:"parentId,optional"` // 父分类ID (可选)
IncludeDescendants bool `form:"includeDescendants,default=true"` // 是否包含子分类
}
type GetUserInfoReq struct {
UserId string `path:"user_id"`
}
@ -15,6 +74,19 @@ type GetUserInfoResp struct {
Roles []string `json:"roles"`
}
type ListCategoriesReq struct {
SystemID string `form:"systemId,optional"` // 按系统ID过滤
ParentID string `form:"parentId,optional"` // 按父分类ID过滤
Name string `form:"name,optional"` // 按名称模糊搜索
Page int `form:"page,default=1"` // 页码
PageSize int `form:"pageSize,default=20"` // 每页数量
}
type ListCategoriesResp struct {
Total int64 `json:"total"` // 总数
List []BaseCategory `json:"list"` // 分类列表
}
type LoginReq struct {
Username string `json:"username"`
Password string `json:"password"`
@ -42,3 +114,16 @@ type RegisterReq struct {
type RegisterResp struct {
UserId string `json:"user_id"`
}
type TreeNode struct {
BaseCategory
Children []*TreeNode `json:"children"` // 子分类列表
}
type UpdateCategoryReq struct {
ID string `path:"id"` // 分类ID
Name string `json:"name,optional"` // 新名称
Alias string `json:"alias,optional"` // 新别名
ParentID string `json:"parentId,optional"` // 新父分类ID
Description string `json:"description,optional"` // 新描述
}

5
go.mod
View File

@ -8,7 +8,7 @@ require (
github.com/lib/pq v1.10.9
github.com/zeromicro/go-zero v1.8.3
golang.org/x/crypto v0.36.0
google.golang.org/grpc v1.72.1
google.golang.org/grpc v1.72.2
google.golang.org/protobuf v1.36.6
)
@ -19,12 +19,15 @@ require (
github.com/go-sql-driver/mysql v1.9.0 // indirect
github.com/goccy/go-json v0.10.5 // indirect
github.com/klauspost/cpuid/v2 v2.2.10 // indirect
github.com/lann/builder v0.0.0-20180802200727-47ae307949d0 // indirect
github.com/lann/ps v0.0.0-20150810152359-62de8c46ede0 // indirect
github.com/minio/crc64nvme v1.0.1 // indirect
github.com/minio/md5-simd v1.1.2 // indirect
github.com/rs/xid v1.6.0 // indirect
)
require (
github.com/Masterminds/squirrel v1.5.4
github.com/beorn7/perks v1.0.1 // indirect
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect

11
go.sum
View File

@ -2,6 +2,8 @@ filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=
github.com/DATA-DOG/go-sqlmock v1.5.2 h1:OcvFkGmslmlZibjAjaHm3L//6LiuBgolP7OputlJIzU=
github.com/DATA-DOG/go-sqlmock v1.5.2/go.mod h1:88MAG/4G7SMwSE3CeA0ZKzrT5CiOU3OJ+JlNzwDqpNU=
github.com/Masterminds/squirrel v1.5.4 h1:uUcX/aBc8O7Fg9kaISIUsHXdKuqehiXAMQTYX8afzqM=
github.com/Masterminds/squirrel v1.5.4/go.mod h1:NNaOrjSoIDfDA40n7sr2tPNZRfjzjA400rg+riTZj10=
github.com/alicebob/gopher-json v0.0.0-20230218143504-906a9b012302 h1:uvdUDbHQHO85qeSydJtItA4T55Pw6BtAejd0APRJOCE=
github.com/alicebob/gopher-json v0.0.0-20230218143504-906a9b012302/go.mod h1:SGnFV6hVsYE877CKEZ6tDNTjaSXYUk6QqoIK6PrAtcc=
github.com/alicebob/miniredis/v2 v2.34.0 h1:mBFWMaJSNL9RwdGRyEDoAAv8OQc5UlEhLDQggTglU/0=
@ -103,6 +105,10 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
github.com/lann/builder v0.0.0-20180802200727-47ae307949d0 h1:SOEGU9fKiNWd/HOJuq6+3iTQz8KNCLtVX6idSoTLdUw=
github.com/lann/builder v0.0.0-20180802200727-47ae307949d0/go.mod h1:dXGbAdH5GtBTC4WfIxhKZfyBF/HBFgRZSWwZ9g/He9o=
github.com/lann/ps v0.0.0-20150810152359-62de8c46ede0 h1:P6pPBnrTSX3DEVR4fDembhRWSsG5rVo6hYhAB/ADZrk=
github.com/lann/ps v0.0.0-20150810152359-62de8c46ede0/go.mod h1:vmVJ0l/dxyfGW6FmdpVm2joNMFikkuWg0EoCKLGUMNw=
github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw=
github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
@ -164,6 +170,7 @@ github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSS
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY=
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
@ -276,8 +283,8 @@ google.golang.org/genproto/googleapis/api v0.0.0-20250218202821-56aae31c358a h1:
google.golang.org/genproto/googleapis/api v0.0.0-20250218202821-56aae31c358a/go.mod h1:3kWAYMk1I75K4vykHtKt2ycnOgpA6974V7bREqbsenU=
google.golang.org/genproto/googleapis/rpc v0.0.0-20250218202821-56aae31c358a h1:51aaUVRocpvUOSQKM6Q7VuoaktNIaMCLuhZB6DKksq4=
google.golang.org/genproto/googleapis/rpc v0.0.0-20250218202821-56aae31c358a/go.mod h1:uRxBH1mhmO8PGhU89cMcHaXKZqO+OfakD8QQO0oYwlQ=
google.golang.org/grpc v1.72.1 h1:HR03wO6eyZ7lknl75XlxABNVLLFc2PAb6mHlYh756mA=
google.golang.org/grpc v1.72.1/go.mod h1:wH5Aktxcg25y1I3w7H69nHfXdOG3UiadoBtjh3izSDM=
google.golang.org/grpc v1.72.2 h1:TdbGzwb82ty4OusHWepvFWGLgIbNo1/SUynEN0ssqv8=
google.golang.org/grpc v1.72.2/go.mod h1:wH5Aktxcg25y1I3w7H69nHfXdOG3UiadoBtjh3izSDM=
google.golang.org/protobuf v1.36.6 h1:z1NpPI8ku2WgiWnf+t9wTPsn6eP1L7ksHUlkfLvd9xY=
google.golang.org/protobuf v1.36.6/go.mod h1:jduwjTPXsFjZGTmRluh+L6NjiWu7pchiJ2/5YcXBHnY=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=

View File

@ -28,6 +28,12 @@ service Category {
// 查询过滤
rpc ListCategories(ListCategoryRequest) returns (CategoryListResponse);
rpc CheckAlias(CheckAliasRequest) returns (CheckAliasResponse);
// 根据系统ID获取分类
rpc GetSystemCategories(GetSystemCategoriesRequest) returns (GetSystemCategoriesResponse);
// 获取某一个类别的完整类别(从根类别到当前类别的所有类别)
rpc GetFullCategories(GetCategoryRequest) returns (GetFullCategoriesResponse);
}
// 健康检查请求
@ -85,6 +91,11 @@ message GetCategoryRequest {
string id = 1;
}
// 获取全分类名称的响应
message GetFullCategoriesResponse {
string full_category_name = 1;
}
// 分类信息响应
message CategoryInfoResponse {
CategoryInfo category = 1;
@ -176,3 +187,18 @@ message CheckAliasResponse {
bool is_available = 1;
string existing_id = 2; // 冲突时返回已存在的分类ID
}
message GetSystemCategoriesRequest {
string system_id = 1; // 系统标识 (必需)
string parent_id = 2; // 父分类ID (可选)
int32 page = 3; // 分页参数
int32 page_size = 4; // 分页参数
bool include_descendants = 5; // 是否包含后代
}
message GetSystemCategoriesResponse {
repeated CategoryInfo categories = 1;
int64 total = 2;
int32 current_page = 3;
int32 page_size = 4;
}

View File

@ -21,7 +21,8 @@ message UploadRequest {
string filename = 1; // 文件名(建议客户端传原始名,服务端会生成唯一名)
string content_type = 2; // 文件类型(如 image/jpeg
bytes content = 3; // 文件二进制内容base64 编码由客户端完成)
string folder = 4; // 可选,文件夹或分类路径,如 "avatars"、"wallpapers"
string folder = 4; // 可选,文件夹或分类路径,支持多级,如 "avatars"、"wallpapers/animals"
string bucket = 5; // bucket name
}
// 上传响应

View File

@ -1,18 +1,18 @@
-- 图片主表基础版
CREATE TABLE images (
-- 核心标识字段
image_id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
image_id VARCHAR(36) PRIMARY KEY DEFAULT gen_random_uuid()::varchar,
-- 存储元数据
storage_key TEXT NOT NULL CHECK (storage_key ~ '^[a-z0-9/-]+$'),
file_name TEXT NOT NULL,
storage_key TEXT NOT NULL, -- 文件显示名称
file_name TEXT NOT NULL, -- 文件存储名称,可以包含路径
mime_type VARCHAR(32) NOT NULL CHECK (mime_type LIKE 'image/%'),
file_size BIGINT NOT NULL CHECK (file_size > 0),
width INT CHECK (width > 0),
height INT CHECK (height > 0),
-- 业务元数据
category_id UUID, -- 分类服务提供的UUID
category_id VARCHAR(36), -- 分类服务提供的UUID
tags TEXT[] DEFAULT '{}'::TEXT[],
-- 系统管控字段

View File

@ -6,8 +6,8 @@ Etcd:
- localhost:2379
Key: user.rpc
DataSource: "postgres://postgres:postgres@localhost:5432/godemo?sslmode=disable"
DataSource: "postgres://postgres:postgres@localhost:19732/godemo?sslmode=disable"
JwtAuth:
AccessSecret: "your-secure-secret"
AccessExpire: 900 # 可选单位秒15分钟
AccessExpire: 3600 # 可选单位秒15分钟