更新2.1.2版本,优化部门、角色权限,增加上下级关系;增加登录、系统、短信日志;优化省市区编码

This commit is contained in:
孟帅
2023-01-25 11:49:21 +08:00
parent 11fad0132d
commit 93e0fe7250
190 changed files with 35896 additions and 7208 deletions

View File

@@ -67,9 +67,14 @@ func RandomCreateBytes(n int, alphabets ...byte) []byte {
return bytes
}
// GetStack 格式化错误的堆栈信息
func GetStack(err error) []string {
stack := gstr.Split(gerror.Stack(err), "\n")
// ParseErrStack 解析错误的堆栈信息
func ParseErrStack(err error) []string {
return ParseStack(gerror.Stack(err))
}
// ParseStack 解析堆栈信息
func ParseStack(st string) []string {
stack := gstr.Split(st, "\n")
for i := 0; i < len(stack); i++ {
stack[i] = gstr.Replace(stack[i], "\t", "--> ")
}

View File

@@ -12,17 +12,31 @@ import (
"strings"
)
var (
pidName = "pid"
treeBeginCut = "tr_" // 树标识开头
treeEndCut = " " // 树标识结尾
const (
treeDefaultId = "id" // 树ID
treeDefaultPid = "pid" // 上级树ID
treeDefaultChildren = "children" // 下级属性
treeBeginCut = "tr_" // 树标识开头
treeEndCut = " " // 树标识结尾
)
// GenOption 生成选项
type GenOption struct {
IdField string
PidField string
ChildrenField string
}
// GenLabel 生成关系树标识
func GenLabel(basic string, appendId int64) string {
return fmt.Sprintf("%v%v%v%v", basic, treeBeginCut, appendId, treeEndCut)
}
// GetIdLabel 获取指定Id的树标签
func GetIdLabel(Id int64) string {
return fmt.Sprintf("%v%v%v", treeBeginCut, Id, treeEndCut)
}
// GetIds 获取上级ID集合
func GetIds(tree string) (ids []int64) {
idsStr := strings.Split(tree, treeEndCut)
@@ -44,41 +58,50 @@ func GetIds(tree string) (ids []int64) {
// GenTree 生成关系树
func GenTree(menus []map[string]interface{}) (realMenu []map[string]interface{}) {
return GenTreeWithField(menus, GenOption{
IdField: treeDefaultId,
PidField: treeDefaultPid,
ChildrenField: treeDefaultChildren,
})
}
// GenTreeWithField 生成关系树 自定义生成属性
func GenTreeWithField(menus []map[string]interface{}, op GenOption) (realMenu []map[string]interface{}) {
if len(menus) < 1 {
return nil
}
minPid := GetMinPid(menus)
minPid := GetMinPid(menus, op.PidField)
formatMenu := make(map[int]map[string]interface{})
for _, m := range menus {
formatMenu[gconv.Int(m["id"])] = m
if gconv.Int(m[pidName]) == minPid {
formatMenu[gconv.Int(m[op.IdField])] = m
if gconv.Int(m[op.PidField]) == minPid {
realMenu = append(realMenu, m) // 需要返回的顶级菜单
}
}
// 得益于都是地址操作,可以直接往父级塞
for _, m := range formatMenu {
if formatMenu[gconv.Int(m[pidName])] == nil {
if formatMenu[gconv.Int(m[op.PidField])] == nil {
continue
}
if formatMenu[gconv.Int(m[pidName])]["children"] == nil {
formatMenu[gconv.Int(m[pidName])]["children"] = []map[string]interface{}{}
if formatMenu[gconv.Int(m[op.PidField])][op.ChildrenField] == nil {
formatMenu[gconv.Int(m[op.PidField])][op.ChildrenField] = []map[string]interface{}{}
}
formatMenu[gconv.Int(m[pidName])]["children"] = append(formatMenu[gconv.Int(m[pidName])]["children"].([]map[string]interface{}), m)
formatMenu[gconv.Int(m[op.PidField])][op.ChildrenField] = append(formatMenu[gconv.Int(m[op.PidField])][op.ChildrenField].([]map[string]interface{}), m)
}
return
}
func GetMinPid(menus []map[string]interface{}) int {
func GetMinPid(menus []map[string]interface{}, pidField string) int {
index := -1
for _, m := range menus {
if index == -1 {
index = gconv.Int(m[pidName])
index = gconv.Int(m[pidField])
continue
}
if gconv.Int(m[pidName]) < index {
index = gconv.Int(m[pidName])
if gconv.Int(m[pidField]) < index {
index = gconv.Int(m[pidField])
}
}