Initial commit
This commit is contained in:
@@ -0,0 +1,98 @@
|
||||
package srv_appcategory
|
||||
|
||||
import (
|
||||
"context"
|
||||
"stat/common/genId"
|
||||
"stat/common/stdLog"
|
||||
"stat/models/appcategory"
|
||||
"time"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
)
|
||||
|
||||
// GetAppCategory 按照参数搜索
|
||||
func GetAppCategory(ctx context.Context, param *AppCategorySearch) (*AppCategorySearchResp, *stdLog.SrvErr) {
|
||||
filter := bson.M{}
|
||||
opt := &options.FindOptions{}
|
||||
resp := &AppCategorySearchResp{
|
||||
List: make(appcategory.AppCategoryList, 0),
|
||||
Total: 0,
|
||||
}
|
||||
opt.SetSort(bson.M{"rank": 1})
|
||||
opt.SetSkip((param.PageNum - 1) * param.PageSize)
|
||||
opt.SetLimit(param.PageSize)
|
||||
|
||||
if param.ParentAppId != nil {
|
||||
filter["parentAppId"] = param.ParentAppId
|
||||
}
|
||||
|
||||
total, serr := appcategory.CountAppCategories(ctx, filter)
|
||||
if serr != nil {
|
||||
return resp, serr
|
||||
}
|
||||
if total == 0 {
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
list, serr := appcategory.FindManyAppCategory(ctx, filter, opt)
|
||||
if serr != nil {
|
||||
return resp, serr
|
||||
}
|
||||
if list != nil && len(list) > 0 {
|
||||
resp.List = list
|
||||
resp.Total = total
|
||||
}
|
||||
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
// AddAppCategory 添加一个
|
||||
func AddAppCategory(ctx context.Context,
|
||||
ac *appcategory.AppCategory) *stdLog.SrvErr {
|
||||
|
||||
now := time.Now()
|
||||
ac.Id = genId.GetAppCategoryId()
|
||||
ac.CreatedAt = now
|
||||
ac.UpdatedAt = now
|
||||
|
||||
if ac.Name == "" {
|
||||
return stdLog.New(stdLog.ParamError, "", "name不能传空")
|
||||
}
|
||||
_, serr := appcategory.FindOneAppCategory(ctx, bson.M{"name": ac.Name})
|
||||
if serr == nil {
|
||||
return stdLog.New(stdLog.ParamError, "", "name重名")
|
||||
}
|
||||
|
||||
serr = appcategory.InsertOneAppCategory(ctx, ac)
|
||||
if serr != nil {
|
||||
return serr
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// DelAppCategory 删除指定
|
||||
func DelAppCategory(ctx context.Context, id int64) *stdLog.SrvErr {
|
||||
adFilter := bson.M{"_id": id}
|
||||
//删除
|
||||
_, serr := appcategory.DelOneAppCategory(ctx, adFilter)
|
||||
if serr != nil {
|
||||
return serr
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// UpdateAppCategory 更新指定
|
||||
func UpdateAppCategory(ctx context.Context, id int64,
|
||||
info *AppCategoryUpdate) *stdLog.SrvErr {
|
||||
now := time.Now()
|
||||
info.UpdatedAt = &now
|
||||
|
||||
adFilter := bson.M{"_id": id}
|
||||
updateDoc := bson.M{"$set": info}
|
||||
serr := appcategory.UpdateOneAppCategory(ctx, adFilter, updateDoc)
|
||||
if serr != nil {
|
||||
return serr
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package srv_appcategory
|
||||
|
||||
import (
|
||||
"stat/common"
|
||||
"stat/models/appcategory"
|
||||
"time"
|
||||
)
|
||||
|
||||
// AppCategorySearch
|
||||
type AppCategorySearch struct {
|
||||
ParentAppId *int64 `json:"parentAppId" bson:"parentAppId"`
|
||||
common.Page
|
||||
}
|
||||
|
||||
type AppCategorySearchResp struct {
|
||||
Total int64 `json:"total"`
|
||||
List appcategory.AppCategoryList `json:"list"`
|
||||
}
|
||||
|
||||
type AppCategoryUpdate struct {
|
||||
ParentAppId *int64 `json:"parentAppId" bson:"parentAppId"`
|
||||
Name *string `json:"name" bson:"name,omitempty"` // 名称
|
||||
Desc *string `json:"desc" bson:"desc,omitempty"` // 描述
|
||||
Status *bool `json:"status" bson:"status,omitempty"` // 状态
|
||||
Rank *int64 `json:"rank" bson:"rank,omitempty"` // 应用排序
|
||||
UpdatedAt *time.Time `json:"updatedAt" bson:"updatedAt,omitempty"` // 更新时间
|
||||
ImgType *int64 `json:"imgType" bson:"imgType,omitempty"` // 图片展示类型 0:应用图标 1.小图标 2.大图标
|
||||
}
|
||||
|
||||
type AppCategoryUpdateReq struct {
|
||||
Param AppCategoryUpdate `json:"param" bson:"param"` // 参数
|
||||
Id int64 `json:"id" bson:"_id,omitempty"`
|
||||
}
|
||||
|
||||
type AppCategoryDelReq struct {
|
||||
Id int64 `json:"id" bson:"_id,omitempty"`
|
||||
}
|
||||
Reference in New Issue
Block a user