|
|
|
package supply
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"git.oa00.com/supply-chain/service/client"
|
|
|
|
)
|
|
|
|
|
|
|
|
type category struct {
|
|
|
|
}
|
|
|
|
|
|
|
|
type CategoryItem struct {
|
|
|
|
Id uint `json:"id"`
|
|
|
|
Name string `json:"name"`
|
|
|
|
ParentId uint `json:"parentId"`
|
|
|
|
Hidden uint `json:"hidden"` // 隐藏状态 1=隐藏 2=显示
|
|
|
|
Children []CategoryItem `json:"children"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// All @Title 获取分类
|
|
|
|
func (c *category) All(ctx context.Context) (result []CategoryItem, err error) {
|
|
|
|
xClient, err := client.GetClient(c)
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
err = xClient.Call(ctx, "All", 0, &result)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// AllNoHidden @Title 获取显示的分类
|
|
|
|
func (c *category) AllNoHidden(ctx context.Context) (result []CategoryItem, err error) {
|
|
|
|
xClient, err := client.GetClient(c)
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
err = xClient.Call(ctx, "AllNoHidden", 0, &result)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
type ArgsCategoryAdd struct {
|
|
|
|
Name string // 分类名称
|
|
|
|
ParentId uint // 上级id
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add @Title 添加分类
|
|
|
|
func (c *category) Add(ctx context.Context, args ArgsCategoryAdd) (err error) {
|
|
|
|
reply := 0
|
|
|
|
xClient, err := client.GetClient(c)
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
return xClient.Call(ctx, "Add", args, &reply)
|
|
|
|
}
|
|
|
|
|
|
|
|
type ReplyCategoryAddError struct {
|
|
|
|
CategoryName string `json:"categoryName"`
|
|
|
|
ErrMsg string `json:"errMsg"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// Adds @Title 添加分类
|
|
|
|
func (c *category) Adds(ctx context.Context, args []ArgsCategoryAdd) (reply []ReplyCategoryAddError, err error) {
|
|
|
|
xClient, err := client.GetClient(c)
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
err = xClient.Call(ctx, "Adds", args, &reply)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
type ArgsCategoryEdit struct {
|
|
|
|
CategoryId uint // 分类id
|
|
|
|
Name string // 分类名称
|
|
|
|
ParentId uint // 上级id
|
|
|
|
}
|
|
|
|
|
|
|
|
// Edit @Title 编辑分类
|
|
|
|
func (c *category) Edit(ctx context.Context, args ArgsCategoryEdit) (err error) {
|
|
|
|
reply := 0
|
|
|
|
xClient, err := client.GetClient(c)
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
return xClient.Call(ctx, "Edit", args, &reply)
|
|
|
|
}
|
|
|
|
|
|
|
|
type ArgsCategoryFindByIds struct {
|
|
|
|
ThirdCategoryIds []uint // 三级分类id数组
|
|
|
|
}
|
|
|
|
type ThirdCategoryItem struct {
|
|
|
|
Id uint `json:"id"`
|
|
|
|
Name string `json:"name"`
|
|
|
|
ParentId uint `json:"parentId"`
|
|
|
|
Parent *ThirdCategoryItem `json:"parent"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// FindByIds @Title 三级分类获取
|
|
|
|
func (c *category) FindByIds(ctx context.Context, args ArgsCategoryFindByIds) (result []ThirdCategoryItem, err error) {
|
|
|
|
xClient, err := client.GetClient(c)
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
err = xClient.Call(ctx, "FindByIds", args, &result)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
type ArgsChangeHidden struct {
|
|
|
|
CategoryId uint
|
|
|
|
Hidden uint // 1=隐藏 2=显示
|
|
|
|
}
|
|
|
|
|
|
|
|
// ChangeHidden @Title 切换隐藏状态
|
|
|
|
func (c *category) ChangeHidden(ctx context.Context, args ArgsChangeHidden) error {
|
|
|
|
xClient, err := client.GetClient(c)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
reply := 0
|
|
|
|
return xClient.Call(ctx, "ChangeHidden", args, &reply)
|
|
|
|
}
|