Merge branch 'develop' of gitee.com:fusenpack/fusenapi into develop

This commit is contained in:
momo 2023-11-14 15:03:07 +08:00
commit 65a055fcf9
8 changed files with 62 additions and 39 deletions

View File

@ -1,21 +1,20 @@
package gmodel package gmodel
import ( import (
"time"
"gorm.io/gorm" "gorm.io/gorm"
"time"
) )
// ldap_department 部门表 // ldap_department 部门表
type LdapDepartment struct { type LdapDepartment struct {
Id int64 `gorm:"primary_key;default:0;auto_increment;" json:"id"` // Id int64 `gorm:"primary_key;default:0;auto_increment;" json:"id"` //
Name *string `gorm:"default:'';" json:"name"` // Name *string `gorm:"unique_key;default:'';" json:"name"` //
Remark *string `gorm:"default:'';" json:"remark"` // Remark *string `gorm:"unique_key;default:'';" json:"remark"` //
Creator *string `gorm:"default:'';" json:"creator"` // Creator *string `gorm:"default:'';" json:"creator"` //
Type *string `gorm:"default:'';" json:"type"` // Type *string `gorm:"default:'';" json:"type"` //
ParentId *int64 `gorm:"default:0;" json:"parent_id"` // 层级如 10/20/30 ParentId *int64 `gorm:"default:0;" json:"parent_id"` // 层级如 10/20/30
Dn *string `gorm:"default:'';" json:"dn"` // Dn *string `gorm:"default:'';" json:"dn"` //
SyncState *int64 `gorm:"default:1;" json:"sync_state"` // SyncState *int64 `gorm:"default:1;" json:"sync_state"` // 同步状态:1已同步, 2未同步
Sort *int64 `gorm:"default:999;" json:"sort"` // 排序 Sort *int64 `gorm:"default:999;" json:"sort"` // 排序
Ctime *time.Time `gorm:"default:'0000-00-00 00:00:00';" json:"ctime"` // Ctime *time.Time `gorm:"default:'0000-00-00 00:00:00';" json:"ctime"` //
Utime *time.Time `gorm:"default:'0000-00-00 00:00:00';" json:"utime"` // Utime *time.Time `gorm:"default:'0000-00-00 00:00:00';" json:"utime"` //

View File

@ -12,9 +12,9 @@ type LdapMenus struct {
Title *string `gorm:"default:'';" json:"title"` // Title *string `gorm:"default:'';" json:"title"` //
Icon *string `gorm:"default:'';" json:"icon"` // Icon *string `gorm:"default:'';" json:"icon"` //
Path *string `gorm:"default:'';" json:"path"` // Path *string `gorm:"default:'';" json:"path"` //
Sort *int64 `gorm:"default:999;" json:"sort"` // Sort *int64 `gorm:"default:999;" json:"sort"` // 菜单顺序(1-999)
Status *int64 `gorm:"default:1;" json:"status"` // Status *int64 `gorm:"default:1;" json:"status"` // 菜单状态(正常/禁用, 默认正常)
ParentId *int64 `gorm:"default:0;" json:"parent_id"` // ParentId *int64 `gorm:"default:0;" json:"parent_id"` // 父菜单编号(编号为0时表示根菜单)
Creator *string `gorm:"default:'';" json:"creator"` // Creator *string `gorm:"default:'';" json:"creator"` //
Ctime *time.Time `gorm:"default:'0000-00-00 00:00:00';" json:"ctime"` // Ctime *time.Time `gorm:"default:'0000-00-00 00:00:00';" json:"ctime"` //
Utime *time.Time `gorm:"default:'0000-00-00 00:00:00';" json:"utime"` // Utime *time.Time `gorm:"default:'0000-00-00 00:00:00';" json:"utime"` //

View File

@ -11,8 +11,8 @@ type LdapRoles struct {
Name *string `gorm:"unique_key;default:'';" json:"name"` // Name *string `gorm:"unique_key;default:'';" json:"name"` //
Keyword *string `gorm:"unique_key;default:'';" json:"keyword"` // Keyword *string `gorm:"unique_key;default:'';" json:"keyword"` //
Remark *string `gorm:"default:'';" json:"remark"` // Remark *string `gorm:"default:'';" json:"remark"` //
Status *int64 `gorm:"default:1;" json:"status"` // Status *int64 `gorm:"default:1;" json:"status"` // 1正常, 2禁用
Sort *int64 `gorm:"default:999;" json:"sort"` // Sort *int64 `gorm:"default:999;" json:"sort"` // 角色排序(排序越大权限越低, 不能查看比自己序号小的角色, 不能编辑同序号用户权限, 排序为1表示超级管理员)
Creator *string `gorm:"default:'';" json:"creator"` // Creator *string `gorm:"default:'';" json:"creator"` //
Ctime *time.Time `gorm:"default:'0000-00-00 00:00:00';" json:"ctime"` // Ctime *time.Time `gorm:"default:'0000-00-00 00:00:00';" json:"ctime"` //
Utime *time.Time `gorm:"default:'0000-00-00 00:00:00';" json:"utime"` // Utime *time.Time `gorm:"default:'0000-00-00 00:00:00';" json:"utime"` //

View File

@ -18,10 +18,10 @@ type LdapUsers struct {
Avatar *string `gorm:"default:'';" json:"avatar"` // Avatar *string `gorm:"default:'';" json:"avatar"` //
Position *string `gorm:"default:'';" json:"position"` // Position *string `gorm:"default:'';" json:"position"` //
Introduction *string `gorm:"default:'';" json:"introduction"` // Introduction *string `gorm:"default:'';" json:"introduction"` //
Status *int64 `gorm:"default:1;" json:"status"` // Status *int64 `gorm:"default:1;" json:"status"` // 状态:1在职, 2离职
Creator *string `gorm:"default:'';" json:"creator"` // Creator *string `gorm:"default:'';" json:"creator"` //
UserDn *string `gorm:"default:'';" json:"user_dn"` // UserDn *string `gorm:"default:'';" json:"user_dn"` //
SyncState *int64 `gorm:"default:1;" json:"sync_state"` // SyncState *int64 `gorm:"default:1;" json:"sync_state"` // 同步状态:1已同步, 2未同步
Ctime *time.Time `gorm:"default:'0000-00-00 00:00:00';" json:"ctime"` // Ctime *time.Time `gorm:"default:'0000-00-00 00:00:00';" json:"ctime"` //
Utime *time.Time `gorm:"default:'0000-00-00 00:00:00';" json:"utime"` // Utime *time.Time `gorm:"default:'0000-00-00 00:00:00';" json:"utime"` //
} }

View File

@ -1,8 +1,10 @@
package logic package logic
import ( import (
"fusenapi/model/gmodel"
"fusenapi/utils/auth" "fusenapi/utils/auth"
"fusenapi/utils/basic" "fusenapi/utils/basic"
"sort"
"context" "context"
@ -37,9 +39,17 @@ func (l *GetDepartmentsLogic) GetDepartments(req *types.Request, userinfo *auth.
logx.Error(err) logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "获取部门列表失败") return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "获取部门列表失败")
} }
//变成树形结构
list := l.DepartmentListToTree(departList)
return resp.SetStatusWithMessage(basic.CodeOK, "success", types.GetDepartmentsRsp{
List: list,
})
}
func (l *GetDepartmentsLogic)DepartmentListToTree(deps []gmodel.LdapDepartment)[]*types.DepartmentsItem{
//存入map //存入map
mapDepartment := make(map[int64]*types.DepartmentsItem) mapDepartment := make(map[int64]*types.DepartmentsItem)
for _, v := range departList { for _, v := range deps {
mapDepartment[v.Id] = &types.DepartmentsItem{ mapDepartment[v.Id] = &types.DepartmentsItem{
Id: v.Id, Id: v.Id,
Name: *v.Name, Name: *v.Name,
@ -52,35 +62,23 @@ func (l *GetDepartmentsLogic) GetDepartments(req *types.Request, userinfo *auth.
Child: make([]*types.DepartmentsItem, 0, 50), Child: make([]*types.DepartmentsItem, 0, 50),
} }
} }
//组织从属关系
for _,v := range mapDepartment{ for _,v := range mapDepartment{
for _,val := range departList{ //如果有父级
if *val.ParentId != v.Id{ if parent,ok := mapDepartment[v.ParentId];ok{
continue parent.Child = append(parent.Child,v)
} sort.Slice(parent.Child, func(i, j int) bool {
v.Child = append(v.Child,&types.DepartmentsItem{ return parent.Child[i].Sort < parent.Child[j].Sort //升序
Id: val.Id,
Name: *val.Name,
Remark: *val.Remark,
Type: *val.Type,
ParentId: *val.ParentId,
Dn: *val.Dn,
SyncState: *val.SyncState,
Sort: *val.Sort,
}) })
} }
} }
list := make([]*types.DepartmentsItem, 0, len(departList)) //排序
for _, v := range mapDepartment { list := make([]*types.DepartmentsItem, 0, len(deps))
if v.ParentId == 0 { for _, v := range deps {
list = append(list, v) if *v.ParentId == 0 {
list = append(list, mapDepartment[v.Id])
} }
} }
return resp.SetStatusWithMessage(basic.CodeOK, "success", types.GetDepartmentsRsp{ return list
List: list,
})
} }
// 处理逻辑后 w,r 如:重定向, resp 必须重新处理
// func (l *GetDepartmentsLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) {
// // httpx.OkJsonCtx(r.Context(), w, resp)
// }

View File

@ -1,8 +1,10 @@
package logic package logic
import ( import (
"fusenapi/model/gmodel"
"fusenapi/utils/auth" "fusenapi/utils/auth"
"fusenapi/utils/basic" "fusenapi/utils/basic"
"time"
"context" "context"
@ -31,8 +33,30 @@ func NewSaveDepartmentLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Sa
// } // }
func (l *SaveDepartmentLogic) SaveDepartment(req *types.SaveDepartmentReq, userinfo *auth.UserInfo) (resp *basic.Response) { func (l *SaveDepartmentLogic) SaveDepartment(req *types.SaveDepartmentReq, userinfo *auth.UserInfo) (resp *basic.Response) {
//todo 鉴权。。。 now := time.Now().UTC()
return resp.SetStatus(basic.CodeOK) data := &gmodel.LdapDepartment{
Name: &req.Name,
Remark: &req.Remark,
Type: &req.Type,
ParentId: &req.ParentId,
Dn: &req.Dn,
Sort: &req.Sort,
Utime: &now,
}
if req.Id > 0{//更新
if err := l.svcCtx.AllModels.LdapDepartment.Update(l.ctx,req.Id,data);err != nil{
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeDbSqlErr,"更新失败")
}
return resp.SetStatusWithMessage(basic.CodeOK,"更新成功")
}
//添加
data.Ctime = &now
if err := l.svcCtx.AllModels.LdapDepartment.Create(l.ctx,data);err != nil{
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeDbSqlErr,"添加失败")
}
return resp.SetStatusWithMessage(basic.CodeOK,"添加成功")
} }
// 处理逻辑后 w,r 如:重定向, resp 必须重新处理 // 处理逻辑后 w,r 如:重定向, resp 必须重新处理

View File

@ -43,6 +43,7 @@ type SaveDepartmentReq struct {
Type string `json:"type"` Type string `json:"type"`
ParentId int64 `json:"parent_id"` ParentId int64 `json:"parent_id"`
Dn string `json:"dn"` Dn string `json:"dn"`
Sort int64 `json:"sort"`
} }
type Request struct { type Request struct {

View File

@ -64,4 +64,5 @@ type SaveDepartmentReq {
Type string `json:"type"` Type string `json:"type"`
ParentId int64 `json:"parent_id"` ParentId int64 `json:"parent_id"`
Dn string `json:"dn"` Dn string `json:"dn"`
Sort int64 `json:"sort"`
} }