53 lines
1.8 KiB
Go
53 lines
1.8 KiB
Go
package repository
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"finclip-app-manager/domain/entity"
|
|
"finclip-app-manager/domain/entity/proto/apiproto"
|
|
utils "finclip-app-manager/infrastructure/cache/redis"
|
|
fcredis "gitlab.finogeeks.club/finclip-backend-v2/finclip-redis"
|
|
"time"
|
|
)
|
|
|
|
//const MENUINFO_DB_NAME = "menuInfo"
|
|
//
|
|
//var (
|
|
// MenuIdOrNameExiErr = errors.New("ID OR Name exists")
|
|
// MenuLockKey = "mop_app_manage_svr_menu_lock_key"
|
|
//)
|
|
//
|
|
//type MenuInfo struct {
|
|
// TraceId string `bson:"trace_id" json:"traceId"`
|
|
// Name string `bson:"name" json:"name"`
|
|
// InfoId string `bson:"info_id" json:"infoId"`
|
|
// ImageUrl string `bson:"image_url" json:"imageUrl"`
|
|
// SortNum int `bson:"sort_num" json:"sortNum"`
|
|
// CreateTime int64 `bson:"create_time" json:"createTime"`
|
|
// UpdateTime int64 `bson:"update_time" json:"updateTime"`
|
|
// UpdateOperator string `bson:"update_operator" json:"updateOperator"`
|
|
//}
|
|
|
|
type IMenuInfoRepo interface {
|
|
GetInfoByTraceId(ctx context.Context, id string) (*entity.MenuInfo, error)
|
|
GetAllMenuList(ctx context.Context, sort []string) ([]entity.MenuInfo, int, error)
|
|
Add(ctx context.Context, info *entity.MenuInfo) error
|
|
GetNextSortNum(ctx context.Context) (int, error)
|
|
DelByTraceId(ctx context.Context, id string) error
|
|
UpdateInfo(ctx context.Context, id string, info *entity.MenuInfo) error
|
|
AllCount(ctx context.Context) (int, error)
|
|
Sort(ctx context.Context, req *apiproto.MenuSortReq) error
|
|
NotFound(err error) bool
|
|
}
|
|
|
|
func Lock(ctx context.Context, t time.Duration) error {
|
|
notExi, _ := utils.Setnx(ctx, entity.MenuLockKey, "ok", int(t.Seconds()))
|
|
if notExi {
|
|
return nil
|
|
}
|
|
return errors.New("try lock err")
|
|
}
|
|
func Unlock(ctx context.Context) error {
|
|
return fcredis.Client().Del(ctx, entity.MenuLockKey).Err()
|
|
}
|