214 lines
6.7 KiB
Go
214 lines
6.7 KiB
Go
package system
|
|
|
|
import (
|
|
"context"
|
|
"gateway/internal/otelTrace"
|
|
|
|
"time"
|
|
|
|
"github.com/beego/beego/v2/client/orm"
|
|
"go.uber.org/zap"
|
|
)
|
|
|
|
const SECOND_MENU_INFO = "second_menu_info"
|
|
|
|
type SecondMenuInfo struct {
|
|
Id int
|
|
FirstMenuOrder int
|
|
FirstMenuUid string
|
|
FirstMenu string
|
|
MenuOrder int
|
|
SecondMenuUid string
|
|
SecondMenu string
|
|
SecondRouter string
|
|
Creater string
|
|
Status string
|
|
CreateTime time.Time
|
|
UpdateTime time.Time
|
|
}
|
|
|
|
type SecondMenuSlice []SecondMenuInfo
|
|
|
|
func (sm SecondMenuSlice) Len() int {
|
|
return len(sm)
|
|
}
|
|
|
|
func (sm SecondMenuSlice) Swap(i, j int) {
|
|
sm[i], sm[j] = sm[j], sm[i]
|
|
}
|
|
|
|
func (sm SecondMenuSlice) Less(i, j int) bool {
|
|
if sm[i].FirstMenuOrder == sm[j].FirstMenuOrder {
|
|
return sm[i].MenuOrder < sm[j].MenuOrder
|
|
}
|
|
return sm[i].FirstMenuOrder < sm[j].FirstMenuOrder
|
|
}
|
|
|
|
func GetSecondMenuLen(ctx context.Context) int {
|
|
o := orm.NewOrm()
|
|
cnt, err := o.QueryTable(SECOND_MENU_INFO).Count()
|
|
if err != nil {
|
|
otelTrace.Logger.WithContext(ctx).Error("get second meun len fail: ", zap.Error(err))
|
|
}
|
|
return int(cnt)
|
|
}
|
|
|
|
func GetSecondMenuInfoByMenuOrder(ctx context.Context, menuOrder int, firstMenuUid string) SecondMenuInfo {
|
|
o := orm.NewOrm()
|
|
var secondMenuInfo SecondMenuInfo
|
|
_, err := o.QueryTable(SECOND_MENU_INFO).Filter("first_menu_uid", firstMenuUid).Filter("menu_order", menuOrder).Limit(1).All(&secondMenuInfo)
|
|
if err != nil {
|
|
otelTrace.Logger.WithContext(ctx).Error("get second menu info by menu order fail: ", zap.Error(err))
|
|
}
|
|
return secondMenuInfo
|
|
}
|
|
|
|
func GetSecondMenuLenByFirstMenuUid(ctx context.Context, firstMenuUid string) int {
|
|
o := orm.NewOrm()
|
|
cnt, err := o.QueryTable(SECOND_MENU_INFO).Filter("first_menu_uid", firstMenuUid).Count()
|
|
if err != nil {
|
|
otelTrace.Logger.WithContext(ctx).Error("get second menu len by first menu uid fail: ", zap.Error(err))
|
|
}
|
|
return int(cnt)
|
|
}
|
|
|
|
func GetSecondMenuList(ctx context.Context) []SecondMenuInfo {
|
|
o := orm.NewOrm()
|
|
var secondMenuList []SecondMenuInfo
|
|
_, err := o.QueryTable(SECOND_MENU_INFO).Limit(-1).OrderBy("-update_time").All(&secondMenuList)
|
|
if err != nil {
|
|
otelTrace.Logger.WithContext(ctx).Error("get second menu list fail: ", zap.Error(err))
|
|
}
|
|
return secondMenuList
|
|
}
|
|
|
|
func GetSecondMenuInfoBySecondMenuUid(ctx context.Context, secondMenuUid string) SecondMenuInfo {
|
|
o := orm.NewOrm()
|
|
var secondMenuInfo SecondMenuInfo
|
|
_, err := o.QueryTable(SECOND_MENU_INFO).Filter("second_menu_uid", secondMenuUid).Limit(1).All(&secondMenuInfo)
|
|
if err != nil {
|
|
otelTrace.Logger.WithContext(ctx).Error("get scond menu info by second menu uid fail: ", zap.Error(err))
|
|
}
|
|
return secondMenuInfo
|
|
}
|
|
|
|
func GetSecondMenuInfoBySecondMenuUids(ctx context.Context, secondMenuUids []string) []SecondMenuInfo {
|
|
secondMenuInfoList := make([]SecondMenuInfo, 0)
|
|
for _, v := range secondMenuUids {
|
|
sm := GetSecondMenuInfoBySecondMenuUid(ctx, v)
|
|
secondMenuInfoList = append(secondMenuInfoList, sm)
|
|
}
|
|
return secondMenuInfoList
|
|
}
|
|
|
|
func GetSecondMenuListByFirstMenuUid(ctx context.Context, firstMenuUid string) []SecondMenuInfo {
|
|
o := orm.NewOrm()
|
|
var secondMenuList []SecondMenuInfo
|
|
_, err := o.QueryTable(SECOND_MENU_INFO).Filter("first_menu_uid", firstMenuUid).Limit(-1).OrderBy("-update_time").All(&secondMenuList)
|
|
if err != nil {
|
|
otelTrace.Logger.WithContext(ctx).Error("get second menu list by first menu uid fail: ", zap.Error(err))
|
|
}
|
|
return secondMenuList
|
|
}
|
|
|
|
func GetSecondMenuLenByMap(ctx context.Context, params map[string]string) int {
|
|
o := orm.NewOrm()
|
|
qs := o.QueryTable(SECOND_MENU_INFO)
|
|
for k, v := range params {
|
|
qs = qs.Filter(k, v)
|
|
}
|
|
cnt, err := qs.Limit(-1).Count()
|
|
if err != nil {
|
|
otelTrace.Logger.WithContext(ctx).Error("get second menu len by map fail: ", zap.Error(err))
|
|
}
|
|
return int(cnt)
|
|
}
|
|
|
|
func GetSecondMenuByMap(ctx context.Context, params map[string]string, displayCount, offset int) []SecondMenuInfo {
|
|
o := orm.NewOrm()
|
|
var secondMenuList []SecondMenuInfo
|
|
qs := o.QueryTable(SECOND_MENU_INFO)
|
|
for k, v := range params {
|
|
if len(v) > 0 {
|
|
qs = qs.Filter(k, v)
|
|
}
|
|
}
|
|
_, err := qs.Limit(displayCount, offset).OrderBy("-update_time").All(&secondMenuList)
|
|
if err != nil {
|
|
otelTrace.Logger.WithContext(ctx).Error("get second menu by map fail: ", zap.Error(err))
|
|
}
|
|
return secondMenuList
|
|
}
|
|
|
|
func InsertSecondMenu(ctx context.Context, secondMenuInfo SecondMenuInfo) bool {
|
|
o := orm.NewOrm()
|
|
_, err := o.Insert(&secondMenuInfo)
|
|
if err != nil {
|
|
otelTrace.Logger.WithContext(ctx).Error("insert second menu fail: ", zap.Error(err))
|
|
return false
|
|
}
|
|
return true
|
|
}
|
|
|
|
func SecondMenuIsExists(seconfMenu string) bool {
|
|
o := orm.NewOrm()
|
|
exist := o.QueryTable(SECOND_MENU_INFO).Filter("second_menu", seconfMenu).Exist()
|
|
return exist
|
|
}
|
|
|
|
func SecondMenuUidIsExists(secondMenuUid string) bool {
|
|
o := orm.NewOrm()
|
|
exist := o.QueryTable(SECOND_MENU_INFO).Filter("second_menu_uid", secondMenuUid).Exist()
|
|
return exist
|
|
}
|
|
|
|
func SecondRouterExists(secondRouter string) bool {
|
|
o := orm.NewOrm()
|
|
exist := o.QueryTable(SECOND_MENU_INFO).Filter("second_router", secondRouter).Exist()
|
|
return exist
|
|
}
|
|
|
|
func DeleteSecondMenuByFirstMenuUid(ctx context.Context, firstMenuUid string) bool {
|
|
o := orm.NewOrm()
|
|
num, err := o.QueryTable(SECOND_MENU_INFO).Filter("first_menu_uid", firstMenuUid).Delete()
|
|
if err != nil {
|
|
otelTrace.Logger.WithContext(ctx).Error("delete second menu by first menu uid fail: ", zap.Error(err))
|
|
return false
|
|
}
|
|
otelTrace.Logger.WithContext(ctx).Info("delete second menu by first menu uid success, num: ", zap.Int64("num", num))
|
|
return true
|
|
}
|
|
|
|
func DeleteSecondMenuBySecondMenuUid(ctx context.Context, secondMenuUid string) bool {
|
|
o := orm.NewOrm()
|
|
num, err := o.QueryTable(SECOND_MENU_INFO).Filter("second_menu_uid", secondMenuUid).Delete()
|
|
if err != nil {
|
|
otelTrace.Logger.WithContext(ctx).Error("delete second menu by second menu uid fail: ", zap.Error(err))
|
|
return false
|
|
}
|
|
otelTrace.Logger.WithContext(ctx).Info("delete second menu by second menu uid success, num: ", zap.Int64("num", num))
|
|
return true
|
|
}
|
|
|
|
func UpdateSecondMenuOrderBySecondUid(ctx context.Context, secondUid string, order int) {
|
|
o := orm.NewOrm()
|
|
_, err := o.QueryTable(SECOND_MENU_INFO).Filter("second_menu_uid", secondUid).Update(orm.Params{"menu_order": order})
|
|
if err != nil {
|
|
otelTrace.Logger.WithContext(ctx).Error("update second menu order by second menu uid fail: ", zap.Error(err))
|
|
}
|
|
}
|
|
|
|
func UpdateSecondMenu(ctx context.Context, secondMenu SecondMenuInfo) {
|
|
o := orm.NewOrm()
|
|
_, err := o.Update(&secondMenu)
|
|
if err != nil {
|
|
otelTrace.Logger.WithContext(ctx).Error("update second menu for first order fail: ", zap.Error(err))
|
|
}
|
|
}
|
|
|
|
func SecondMenuExistByMenuOrder(ctx context.Context, menuOrder int) bool {
|
|
o := orm.NewOrm()
|
|
exist := o.QueryTable(SECOND_MENU_INFO).Filter("menu_order", menuOrder).ExistWithCtx(ctx)
|
|
return exist
|
|
}
|