master
黄海 5 years ago
parent 177c3c29e9
commit 53e7b8bcfb

@ -6,7 +6,9 @@ import (
"dsBaseRpc/Utils/DbUtil"
"dsBaseRpc/Utils/SqlKit"
"dsBaseRpc/models"
"errors"
"github.com/xormplus/builder"
"strings"
)
var db = DbUtil.Engine
@ -63,3 +65,46 @@ func PageBaseMenu(in *BaseMenuProto.QueryArg) ([]map[string]interface{}, int32,
list, count, err := SqlKit.Query(sql)
return list, count, err
}
//调整菜单的排序号direction=1向上drection=2向下
func ChangeMenuOrder(menuId string, direction int32) (bool, error) {
if direction != 1 && direction != 2 {
return false, errors.New("传入调整方向有误向上1向下2传入值不正确")
}
//查找当前menu的sort_id
list := SqlKit.QueryByIds([]string{menuId}, "t_base_role_menu")
if len(list) == 0 {
return false, errors.New("没有找到对应的menu_id!")
}
parentId := list[0]["parent_id"].(string)
sortId := list[0]["sort_id"].(int32)
sql := `select menu_id,sort_id from t_base_menu where parent_id=? and sort_id#? order sort_id limit 1`
if direction == 1 {
sql = strings.Replace(sql, "#", "<", -1)
} else {
sql = strings.Replace(sql, "#", ">", -1)
}
list2, err := db.SQL(sql, parentId, sortId).Query().List()
if err != nil {
return false, err
}
if len(list2) == 0 {
return true, nil
}
//目标替换对象
menuId2 := list2[0]["menu_id"].(string)
sortId2 := list2[0]["sort_id"].(int32)
//更新
//1、清除Redis缓存
var ids = []string{menuId, menuId2}
var selector = SqlKit.GetBean("t_base_menu")
SqlKit.DeleteCacheByIds(ids, selector)
sql = `update t_base_menu set sort_id=? where menu_id=?`
db.SQL(sql, sortId2, menuId).Execute()
db.SQL(sql, sortId, menuId2).Execute()
return true, nil
}

Loading…
Cancel
Save