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
import (
"time"
"gorm.io/gorm"
"time"
)
// ldap_department 部门表
type LdapDepartment struct {
Id int64 `gorm:"primary_key;default:0;auto_increment;" json:"id"` //
Name *string `gorm:"default:'';" json:"name"` //
Remark *string `gorm:"default:'';" json:"remark"` //
Name *string `gorm:"unique_key;default:'';" json:"name"` //
Remark *string `gorm:"unique_key;default:'';" json:"remark"` //
Creator *string `gorm:"default:'';" json:"creator"` //
Type *string `gorm:"default:'';" json:"type"` //
ParentId *int64 `gorm:"default:0;" json:"parent_id"` // 层级如 10/20/30
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"` // 排序
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"` //

View File

@ -12,9 +12,9 @@ type LdapMenus struct {
Title *string `gorm:"default:'';" json:"title"` //
Icon *string `gorm:"default:'';" json:"icon"` //
Path *string `gorm:"default:'';" json:"path"` //
Sort *int64 `gorm:"default:999;" json:"sort"` //
Status *int64 `gorm:"default:1;" json:"status"` //
ParentId *int64 `gorm:"default:0;" json:"parent_id"` //
Sort *int64 `gorm:"default:999;" json:"sort"` // 菜单顺序(1-999)
Status *int64 `gorm:"default:1;" json:"status"` // 菜单状态(正常/禁用, 默认正常)
ParentId *int64 `gorm:"default:0;" json:"parent_id"` // 父菜单编号(编号为0时表示根菜单)
Creator *string `gorm:"default:'';" json:"creator"` //
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"` //

View File

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

View File

@ -18,10 +18,10 @@ type LdapUsers struct {
Avatar *string `gorm:"default:'';" json:"avatar"` //
Position *string `gorm:"default:'';" json:"position"` //
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"` //
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"` //
Utime *time.Time `gorm:"default:'0000-00-00 00:00:00';" json:"utime"` //
}

View File

@ -1,8 +1,10 @@
package logic
import (
"fusenapi/model/gmodel"
"fusenapi/utils/auth"
"fusenapi/utils/basic"
"sort"
"context"
@ -37,9 +39,17 @@ func (l *GetDepartmentsLogic) GetDepartments(req *types.Request, userinfo *auth.
logx.Error(err)
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
mapDepartment := make(map[int64]*types.DepartmentsItem)
for _, v := range departList {
for _, v := range deps {
mapDepartment[v.Id] = &types.DepartmentsItem{
Id: v.Id,
Name: *v.Name,
@ -52,35 +62,23 @@ func (l *GetDepartmentsLogic) GetDepartments(req *types.Request, userinfo *auth.
Child: make([]*types.DepartmentsItem, 0, 50),
}
}
//组织从属关系
for _,v := range mapDepartment{
for _,val := range departList{
if *val.ParentId != v.Id{
continue
}
v.Child = append(v.Child,&types.DepartmentsItem{
Id: val.Id,
Name: *val.Name,
Remark: *val.Remark,
Type: *val.Type,
ParentId: *val.ParentId,
Dn: *val.Dn,
SyncState: *val.SyncState,
Sort: *val.Sort,
//如果有父级
if parent,ok := mapDepartment[v.ParentId];ok{
parent.Child = append(parent.Child,v)
sort.Slice(parent.Child, func(i, j int) bool {
return parent.Child[i].Sort < parent.Child[j].Sort //升序
})
}
}
list := make([]*types.DepartmentsItem, 0, len(departList))
for _, v := range mapDepartment {
if v.ParentId == 0 {
list = append(list, v)
//排序
list := make([]*types.DepartmentsItem, 0, len(deps))
for _, v := range deps {
if *v.ParentId == 0 {
list = append(list, mapDepartment[v.Id])
}
}
return resp.SetStatusWithMessage(basic.CodeOK, "success", types.GetDepartmentsRsp{
List: list,
})
return 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
import (
"fusenapi/model/gmodel"
"fusenapi/utils/auth"
"fusenapi/utils/basic"
"time"
"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) {
//todo 鉴权。。。
return resp.SetStatus(basic.CodeOK)
now := time.Now().UTC()
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 必须重新处理

View File

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

View File

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