fix
This commit is contained in:
commit
76e534ef0b
@ -1,8 +1,9 @@
|
|||||||
package gmodel
|
package gmodel
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"gorm.io/gorm"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"gorm.io/gorm"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ldap_department 部门表
|
// ldap_department 部门表
|
||||||
|
@ -3,42 +3,45 @@ package gmodel
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
|
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
)
|
)
|
||||||
|
|
||||||
//获取列表
|
// 获取列表
|
||||||
func (d *LdapDepartmentModel)GetAll(ctx context.Context,sort string)(resp []LdapDepartment,total int64,err error){
|
func (d *LdapDepartmentModel) GetAll(ctx context.Context, sort string) (resp []LdapDepartment, total int64, err error) {
|
||||||
db := d.db.WithContext(ctx).Model(&LdapDepartment{})
|
db := d.db.WithContext(ctx).Model(&LdapDepartment{})
|
||||||
if sort != ""{
|
if sort != "" {
|
||||||
db = db.Order(sort)
|
db = db.Order(sort)
|
||||||
}
|
}
|
||||||
if err = db.Count(&total).Error;err != nil{
|
if err = db.Count(&total).Error; err != nil {
|
||||||
return nil, 0, err
|
return nil, 0, err
|
||||||
}
|
}
|
||||||
err = db.Find(&resp).Error
|
err = db.Find(&resp).Error
|
||||||
return resp, total, err
|
return resp, total, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *LdapDepartmentModel)FindOne(ctx context.Context,id int64)(resp *LdapDepartment,err error){
|
func (d *LdapDepartmentModel) FindOne(ctx context.Context, id int64) (resp *LdapDepartment, err error) {
|
||||||
err = d.db.WithContext(ctx).Model(&LdapDepartment{}).Where("id = ?",id).Take(&resp).Error
|
err = d.db.WithContext(ctx).Model(&LdapDepartment{}).Where("id = ?", id).Take(&resp).Error
|
||||||
return resp,err
|
return resp, err
|
||||||
}
|
}
|
||||||
//更新
|
|
||||||
func (d *LdapDepartmentModel)Update(ctx context.Context,id int64,data *LdapDepartment)error{
|
// 更新
|
||||||
return d.db.WithContext(ctx).Model(&LdapDepartment{}).Where("id = ?",id).Updates(&data).Error
|
func (d *LdapDepartmentModel) Update(ctx context.Context, id int64, data *LdapDepartment) error {
|
||||||
|
return d.db.WithContext(ctx).Model(&LdapDepartment{}).Where("id = ?", id).Updates(&data).Error
|
||||||
}
|
}
|
||||||
//创建
|
|
||||||
func (d *LdapDepartmentModel)Create(ctx context.Context,data *LdapDepartment)error{
|
// 创建
|
||||||
|
func (d *LdapDepartmentModel) Create(ctx context.Context, data *LdapDepartment) error {
|
||||||
return d.db.WithContext(ctx).Model(&LdapDepartment{}).Create(&data).Error
|
return d.db.WithContext(ctx).Model(&LdapDepartment{}).Create(&data).Error
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *LdapDepartmentModel)CreateOrUpdate(ctx context.Context,id int64,data *LdapDepartment)error{
|
func (d *LdapDepartmentModel) CreateOrUpdate(ctx context.Context, id int64, data *LdapDepartment) error {
|
||||||
_,err := d.FindOne(ctx,id)
|
_, err := d.FindOne(ctx, id)
|
||||||
if err != nil{
|
if err != nil {
|
||||||
if errors.Is(err,gorm.ErrRecordNotFound){
|
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||||
return d.Create(ctx,data)
|
return d.Create(ctx, data)
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return d.Update(ctx,id,data)
|
return d.Update(ctx, id, data)
|
||||||
}
|
}
|
@ -1,2 +1,15 @@
|
|||||||
package gmodel
|
package gmodel
|
||||||
|
|
||||||
|
import "context"
|
||||||
|
|
||||||
// TODO: 使用model的属性做你想做的
|
// TODO: 使用model的属性做你想做的
|
||||||
|
|
||||||
|
// 获取全部菜单
|
||||||
|
func (d *LdapMenusModel) GetAll(ctx context.Context) (resp []LdapMenus, err error) {
|
||||||
|
var menus []LdapMenus
|
||||||
|
result := d.db.Model(&LdapMenus{}).Where("status = ?", 1).Find(&menus)
|
||||||
|
if result.Error != nil {
|
||||||
|
return nil, result.Error
|
||||||
|
}
|
||||||
|
return menus, nil
|
||||||
|
}
|
||||||
|
@ -2,6 +2,7 @@ package config
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fusenapi/server/ldap-admin/internal/types"
|
"fusenapi/server/ldap-admin/internal/types"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/rest"
|
"github.com/zeromicro/go-zero/rest"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
package logic
|
package logic
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"fusenapi/utils/auth"
|
"fusenapi/utils/auth"
|
||||||
"fusenapi/utils/basic"
|
"fusenapi/utils/basic"
|
||||||
|
|
||||||
|
"context"
|
||||||
|
|
||||||
"fusenapi/server/ldap-admin/internal/svc"
|
"fusenapi/server/ldap-admin/internal/svc"
|
||||||
"fusenapi/server/ldap-admin/internal/types"
|
"fusenapi/server/ldap-admin/internal/types"
|
||||||
|
|
||||||
@ -30,6 +31,7 @@ func NewGetDepartmentsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Ge
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
func (l *GetDepartmentsLogic) GetDepartments(req *types.Request, userinfo *auth.UserInfo) (resp *basic.Response) {
|
func (l *GetDepartmentsLogic) GetDepartments(req *types.Request, userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||||
|
<<<<<<< HEAD
|
||||||
//todo 鉴权 。。。。
|
//todo 鉴权 。。。。
|
||||||
departList, _, err := l.svcCtx.AllModels.LdapDepartment.GetAll(l.ctx, "sort ASC")
|
departList, _, err := l.svcCtx.AllModels.LdapDepartment.GetAll(l.ctx, "sort ASC")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user