新增部门角色

This commit is contained in:
momo 2023-11-14 11:45:25 +08:00
parent 3bde233e8a
commit 8542091977
23 changed files with 791 additions and 15 deletions

View File

@ -0,0 +1,24 @@
package gmodel
import (
"gorm.io/gorm"
)
// casbin_rule
type CasbinRule struct {
PType *string `gorm:"default:'';" json:"p_type"` //
V0 *string `gorm:"default:'';" json:"v0"` //
V1 *string `gorm:"default:'';" json:"v1"` //
V2 *string `gorm:"default:'';" json:"v2"` //
V3 *string `gorm:"default:'';" json:"v3"` //
V4 *string `gorm:"default:'';" json:"v4"` //
V5 *string `gorm:"default:'';" json:"v5"` //
}
type CasbinRuleModel struct {
db *gorm.DB
name string
}
func NewCasbinRuleModel(db *gorm.DB) *CasbinRuleModel {
return &CasbinRuleModel{db: db, name: "casbin_rule"}
}

View File

@ -0,0 +1,2 @@
package gmodel
// TODO: 使用model的属性做你想做的

View File

@ -1,8 +1,9 @@
package gmodel
import (
"gorm.io/gorm"
"time"
"gorm.io/gorm"
)
// ldap_department 部门表
@ -12,7 +13,7 @@ type LdapDepartment struct {
Remark *string `gorm:"default:'';" json:"remark"` //
Creator *string `gorm:"default:'';" json:"creator"` //
Type *string `gorm:"default:'';" json:"type"` //
ParentId *int64 `gorm:"default:0;" json:"parent_id"` //
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"` //
Ctime *time.Time `gorm:"default:'0000-00-00 00:00:00';" json:"ctime"` //

View File

@ -1,7 +1,49 @@
package gmodel
import "context"
import (
"context"
"time"
)
func (d *LdapDepartmentModel)GetList(ctx context.Context,page,pageSize int,sort string)(resp []LdapDepartment,total int64,err error){
return nil, 0, nil
}
func (d *LdapDepartmentModel) GetOneById(ctx context.Context, id int64) (resp LdapDepartment, err error) {
db := d.db.WithContext(ctx).Model(&FsShoppingCart{})
return resp, db.Take(&resp).Error
}
func (d *LdapDepartmentModel) GetList(ctx context.Context, page, pageSize int, sort string) (resp []LdapDepartment, total int64, err error) {
db := d.db.WithContext(ctx).Model(&FsShoppingCart{})
if sort != "" {
db = db.Order(sort)
}
//查询数量
if err = db.Limit(1).Count(&total).Error; err != nil {
return nil, 0, err
}
offset := (page - 1) * pageSize
err = db.Offset(offset).Limit(pageSize).Find(&resp).Error
return resp, total, err
}
// InsertOne 单个插入
func (d *LdapDepartmentModel) InsertOne(ctx context.Context, insertData LdapDepartment) error {
var nowTime = time.Now().UTC()
insertData.Ctime = &nowTime
insertData.Utime = &nowTime
result := d.db.WithContext(ctx).Model(&LdapDepartment{}).Create(&insertData)
if result.Error != nil {
return result.Error
} else {
return nil
}
}
// UpdateOne 单个更新
func (d *LdapDepartmentModel) UpdateOne(ctx context.Context, Department LdapDepartment, updateData map[string]interface{}) error {
result := d.db.WithContext(ctx).Model(&Department).Updates(updateData)
if result.Error != nil {
return result.Error
} else {
return nil
}
}

View File

@ -1,2 +1,15 @@
package gmodel
// TODO: 使用model的属性做你想做的
import "context"
// 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
}

View File

@ -4,6 +4,7 @@ import "gorm.io/gorm"
// AllModelsGen 所有Model集合,修改单行,只要不改字段名,不会根据新的内容修改,需要修改的话手动删除
type AllModelsGen struct {
CasbinRule *CasbinRuleModel // casbin_rule
FsAddress *FsAddressModel // fs_address 用户地址表
FsAuthAssignment *FsAuthAssignmentModel // fs_auth_assignment 用户角色和权限信息
FsAuthItem *FsAuthItemModel // fs_auth_item 用户角色和权限信息
@ -16,14 +17,19 @@ type AllModelsGen struct {
FsCardGroup *FsCardGroupModel // fs_card_group 卡号分组表
FsCart *FsCartModel // fs_cart 购物车
FsChangeCode *FsChangeCodeModel // fs_change_code 忘记密码code表
FsCloudDeliverEveryTmpOld *FsCloudDeliverEveryTmpOldModel // fs_cloud_deliver_every_tmp_old
FsCloudDeliverTmpOld *FsCloudDeliverTmpOldModel // fs_cloud_deliver_tmp_old
FsCloudOld *FsCloudOldModel // fs_cloud_old 云仓表
FsCloudPickUpDetailOld *FsCloudPickUpDetailOldModel // fs_cloud_pick_up_detail_old 云仓提货单-详情
FsCloudPickUpOld *FsCloudPickUpOldModel // fs_cloud_pick_up_old 云仓提货单
FsCloudReceiveEveryOld *FsCloudReceiveEveryOldModel // fs_cloud_receive_every_old
FsCloudReceiveOld *FsCloudReceiveOldModel // fs_cloud_receive_old 云仓接收工厂总单
FsCloudRenderLog *FsCloudRenderLogModel // fs_cloud_render_log 云渲染日志表
FsCloudStorage *FsCloudStorageModel // fs_cloud_storage 仓库的基本信息, 只做映射
FsCloudStorageStock *FsCloudStorageStockModel // fs_cloud_storage_stock
FsCloudUserApplyBackOld *FsCloudUserApplyBackOldModel // fs_cloud_user_apply_back_old 该表废弃
FsContact *FsContactModel // fs_contact 该表暂未使用
FsContactService *FsContactServiceModel // fs_contact_service
FsCoupon *FsCouponModel // fs_coupon 代金券(暂未使用)
FsDeliver *FsDeliverModel // fs_deliver 发货表 云仓 直发 通用(已废弃)
FsDeliverEvery *FsDeliverEveryModel // fs_deliver_every 发货详细表(已废弃)
@ -34,6 +40,7 @@ type AllModelsGen struct {
FsFactoryDeliver *FsFactoryDeliverModel // fs_factory_deliver 工厂发货主表(废弃)
FsFactoryDeliverEvery *FsFactoryDeliverEveryModel // fs_factory_deliver_every 该表废弃
FsFactoryProduct *FsFactoryProductModel // fs_factory_product 工厂生产表(废弃)
FsFactoryShipTmp *FsFactoryShipTmpModel // fs_factory_ship_tmp
FsFaq *FsFaqModel // fs_faq 常见问题
FsFeishuWebhookLog *FsFeishuWebhookLogModel // fs_feishu_webhook_log 飞书webhook记录表
FsFont *FsFontModel // fs_font 字体配置
@ -51,6 +58,7 @@ type AllModelsGen struct {
FsOrderCombineImageRecord *FsOrderCombineImageRecordModel // fs_order_combine_image_record 刀版图记录表
FsOrderDetailOld *FsOrderDetailOldModel // fs_order_detail_old 订单详细表
FsOrderDetailTemplateOld *FsOrderDetailTemplateOldModel // fs_order_detail_template_old 订单模板详细表
FsOrderOld *FsOrderOldModel // fs_order_old
FsOrderRemarkOld *FsOrderRemarkOldModel // fs_order_remark_old 订单备注表
FsOrderTrade *FsOrderTradeModel // fs_order_trade 订单交易表
FsOrderTradeEvent *FsOrderTradeEventModel // fs_order_trade_event 订单交易事件表
@ -59,11 +67,13 @@ type AllModelsGen struct {
FsProductCollection *FsProductCollectionModel // fs_product_collection 产品收藏表
FsProductCopy1 *FsProductCopy1Model // fs_product_copy1 产品表
FsProductDesign *FsProductDesignModel // fs_product_design 产品设计表
FsProductDesignGather *FsProductDesignGatherModel // fs_product_design_gather
FsProductHistoryTemplate *FsProductHistoryTemplateModel // fs_product_history_template 模板历史表
FsProductModel3d *FsProductModel3dModel // fs_product_model3d 产品模型表
FsProductModel3dLight *FsProductModel3dLightModel // fs_product_model3d_light 模型-灯光组表
FsProductOption *FsProductOptionModel // fs_product_option 产品选项表(已废弃)
FsProductPrice *FsProductPriceModel // fs_product_price 阶梯价格表
FsProductRenderDesign *FsProductRenderDesignModel // fs_product_render_design
FsProductScene *FsProductSceneModel // fs_product_scene 产品场景表
FsProductSize *FsProductSizeModel // fs_product_size 产品尺寸表
FsProductTagProp *FsProductTagPropModel // fs_product_tag_prop 产品标签相关属性表
@ -73,6 +83,7 @@ type AllModelsGen struct {
FsProductTemplateTags *FsProductTemplateTagsModel // fs_product_template_tags 模板标签表
FsProductTemplateV2 *FsProductTemplateV2Model // fs_product_template_v2 产品-模型- 模板表
FsProductV2Tmp *FsProductV2TmpModel // fs_product_v2_tmp 产品表
FsQrcode *FsQrcodeModel // fs_qrcode
FsQrcodeLog *FsQrcodeLogModel // fs_qrcode_log 二维码扫描日志
FsQrcodeSet *FsQrcodeSetModel // fs_qrcode_set 二维码边框配置表
FsQrcodeUser *FsQrcodeUserModel // fs_qrcode_user 二维码-用户名表
@ -82,6 +93,7 @@ type AllModelsGen struct {
FsQuotationRemarkTemplate *FsQuotationRemarkTemplateModel // fs_quotation_remark_template 报价单备注模板
FsQuotationSaler *FsQuotationSalerModel // fs_quotation_saler 报价单业务员表
FsQuotationSizeLayout *FsQuotationSizeLayoutModel // fs_quotation_size_layout 产品尺寸排版表
FsRefundReason *FsRefundReasonModel // fs_refund_reason
FsResource *FsResourceModel // fs_resource 资源表
FsShoppingCart *FsShoppingCartModel // fs_shopping_cart 新版购物车表
FsStandardLogo *FsStandardLogoModel // fs_standard_logo 标准logo
@ -89,6 +101,7 @@ type AllModelsGen struct {
FsToolLogs *FsToolLogsModel // fs_tool_logs 3d设计工具日志表
FsToolTemplate *FsToolTemplateModel // fs_tool_template 设计工具模板(废弃)
FsToolUser *FsToolUserModel // fs_tool_user 3d设计工具用户表
FsTrade *FsTradeModel // fs_trade
FsUser *FsUserModel // fs_user 用户表
FsUserDebug *FsUserDebugModel // fs_user_debug 用户debug
FsUserInfo *FsUserInfoModel // fs_user_info 用户信息表
@ -110,6 +123,7 @@ type AllModelsGen struct {
func NewAllModels(gdb *gorm.DB) *AllModelsGen {
models := &AllModelsGen{
CasbinRule: NewCasbinRuleModel(gdb),
FsAddress: NewFsAddressModel(gdb),
FsAuthAssignment: NewFsAuthAssignmentModel(gdb),
FsAuthItem: NewFsAuthItemModel(gdb),
@ -122,14 +136,19 @@ func NewAllModels(gdb *gorm.DB) *AllModelsGen {
FsCardGroup: NewFsCardGroupModel(gdb),
FsCart: NewFsCartModel(gdb),
FsChangeCode: NewFsChangeCodeModel(gdb),
FsCloudDeliverEveryTmpOld: NewFsCloudDeliverEveryTmpOldModel(gdb),
FsCloudDeliverTmpOld: NewFsCloudDeliverTmpOldModel(gdb),
FsCloudOld: NewFsCloudOldModel(gdb),
FsCloudPickUpDetailOld: NewFsCloudPickUpDetailOldModel(gdb),
FsCloudPickUpOld: NewFsCloudPickUpOldModel(gdb),
FsCloudReceiveEveryOld: NewFsCloudReceiveEveryOldModel(gdb),
FsCloudReceiveOld: NewFsCloudReceiveOldModel(gdb),
FsCloudRenderLog: NewFsCloudRenderLogModel(gdb),
FsCloudStorage: NewFsCloudStorageModel(gdb),
FsCloudStorageStock: NewFsCloudStorageStockModel(gdb),
FsCloudUserApplyBackOld: NewFsCloudUserApplyBackOldModel(gdb),
FsContact: NewFsContactModel(gdb),
FsContactService: NewFsContactServiceModel(gdb),
FsCoupon: NewFsCouponModel(gdb),
FsDeliver: NewFsDeliverModel(gdb),
FsDeliverEvery: NewFsDeliverEveryModel(gdb),
@ -140,6 +159,7 @@ func NewAllModels(gdb *gorm.DB) *AllModelsGen {
FsFactoryDeliver: NewFsFactoryDeliverModel(gdb),
FsFactoryDeliverEvery: NewFsFactoryDeliverEveryModel(gdb),
FsFactoryProduct: NewFsFactoryProductModel(gdb),
FsFactoryShipTmp: NewFsFactoryShipTmpModel(gdb),
FsFaq: NewFsFaqModel(gdb),
FsFeishuWebhookLog: NewFsFeishuWebhookLogModel(gdb),
FsFont: NewFsFontModel(gdb),
@ -157,6 +177,7 @@ func NewAllModels(gdb *gorm.DB) *AllModelsGen {
FsOrderCombineImageRecord: NewFsOrderCombineImageRecordModel(gdb),
FsOrderDetailOld: NewFsOrderDetailOldModel(gdb),
FsOrderDetailTemplateOld: NewFsOrderDetailTemplateOldModel(gdb),
FsOrderOld: NewFsOrderOldModel(gdb),
FsOrderRemarkOld: NewFsOrderRemarkOldModel(gdb),
FsOrderTrade: NewFsOrderTradeModel(gdb),
FsOrderTradeEvent: NewFsOrderTradeEventModel(gdb),
@ -165,11 +186,13 @@ func NewAllModels(gdb *gorm.DB) *AllModelsGen {
FsProductCollection: NewFsProductCollectionModel(gdb),
FsProductCopy1: NewFsProductCopy1Model(gdb),
FsProductDesign: NewFsProductDesignModel(gdb),
FsProductDesignGather: NewFsProductDesignGatherModel(gdb),
FsProductHistoryTemplate: NewFsProductHistoryTemplateModel(gdb),
FsProductModel3d: NewFsProductModel3dModel(gdb),
FsProductModel3dLight: NewFsProductModel3dLightModel(gdb),
FsProductOption: NewFsProductOptionModel(gdb),
FsProductPrice: NewFsProductPriceModel(gdb),
FsProductRenderDesign: NewFsProductRenderDesignModel(gdb),
FsProductScene: NewFsProductSceneModel(gdb),
FsProductSize: NewFsProductSizeModel(gdb),
FsProductTagProp: NewFsProductTagPropModel(gdb),
@ -179,6 +202,7 @@ func NewAllModels(gdb *gorm.DB) *AllModelsGen {
FsProductTemplateTags: NewFsProductTemplateTagsModel(gdb),
FsProductTemplateV2: NewFsProductTemplateV2Model(gdb),
FsProductV2Tmp: NewFsProductV2TmpModel(gdb),
FsQrcode: NewFsQrcodeModel(gdb),
FsQrcodeLog: NewFsQrcodeLogModel(gdb),
FsQrcodeSet: NewFsQrcodeSetModel(gdb),
FsQrcodeUser: NewFsQrcodeUserModel(gdb),
@ -188,6 +212,7 @@ func NewAllModels(gdb *gorm.DB) *AllModelsGen {
FsQuotationRemarkTemplate: NewFsQuotationRemarkTemplateModel(gdb),
FsQuotationSaler: NewFsQuotationSalerModel(gdb),
FsQuotationSizeLayout: NewFsQuotationSizeLayoutModel(gdb),
FsRefundReason: NewFsRefundReasonModel(gdb),
FsResource: NewFsResourceModel(gdb),
FsShoppingCart: NewFsShoppingCartModel(gdb),
FsStandardLogo: NewFsStandardLogoModel(gdb),
@ -195,6 +220,7 @@ func NewAllModels(gdb *gorm.DB) *AllModelsGen {
FsToolLogs: NewFsToolLogsModel(gdb),
FsToolTemplate: NewFsToolTemplateModel(gdb),
FsToolUser: NewFsToolUserModel(gdb),
FsTrade: NewFsTradeModel(gdb),
FsUser: NewFsUserModel(gdb),
FsUserDebug: NewFsUserDebugModel(gdb),
FsUserInfo: NewFsUserInfoModel(gdb),

View File

@ -1,6 +1,10 @@
package config
import "github.com/zeromicro/go-zero/rest"
import (
"fusenapi/server/ldap-admin/internal/types"
"github.com/zeromicro/go-zero/rest"
)
type Config struct {
rest.RestConf

View File

@ -0,0 +1,35 @@
package handler
import (
"net/http"
"reflect"
"fusenapi/utils/basic"
"fusenapi/server/ldap-admin/internal/logic"
"fusenapi/server/ldap-admin/internal/svc"
"fusenapi/server/ldap-admin/internal/types"
)
func AddDepartmentHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.AddDepartmentReq
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
if err != nil {
return
}
// 创建一个业务逻辑层实例
l := logic.NewAddDepartmentLogic(r.Context(), svcCtx)
rl := reflect.ValueOf(l)
basic.BeforeLogic(w, r, rl)
resp := l.AddDepartment(&req, userinfo)
if !basic.AfterLogic(w, r, rl, resp) {
basic.NormalAfterLogic(w, r, resp)
}
}
}

View File

@ -0,0 +1,35 @@
package handler
import (
"net/http"
"reflect"
"fusenapi/utils/basic"
"fusenapi/server/ldap-admin/internal/logic"
"fusenapi/server/ldap-admin/internal/svc"
"fusenapi/server/ldap-admin/internal/types"
)
func AddMenuHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.AddMenuHandler
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
if err != nil {
return
}
// 创建一个业务逻辑层实例
l := logic.NewAddMenuLogic(r.Context(), svcCtx)
rl := reflect.ValueOf(l)
basic.BeforeLogic(w, r, rl)
resp := l.AddMenu(&req, userinfo)
if !basic.AfterLogic(w, r, rl, resp) {
basic.NormalAfterLogic(w, r, resp)
}
}
}

View File

@ -0,0 +1,35 @@
package handler
import (
"net/http"
"reflect"
"fusenapi/utils/basic"
"fusenapi/server/ldap-admin/internal/logic"
"fusenapi/server/ldap-admin/internal/svc"
"fusenapi/server/ldap-admin/internal/types"
)
func DeleteDepartmentHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.DeleteDepartmentReq
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
if err != nil {
return
}
// 创建一个业务逻辑层实例
l := logic.NewDeleteDepartmentLogic(r.Context(), svcCtx)
rl := reflect.ValueOf(l)
basic.BeforeLogic(w, r, rl)
resp := l.DeleteDepartment(&req, userinfo)
if !basic.AfterLogic(w, r, rl, resp) {
basic.NormalAfterLogic(w, r, resp)
}
}
}

View File

@ -0,0 +1,35 @@
package handler
import (
"net/http"
"reflect"
"fusenapi/utils/basic"
"fusenapi/server/ldap-admin/internal/logic"
"fusenapi/server/ldap-admin/internal/svc"
"fusenapi/server/ldap-admin/internal/types"
)
func EditDepartmentHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.EditDepartmentReq
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
if err != nil {
return
}
// 创建一个业务逻辑层实例
l := logic.NewEditDepartmentLogic(r.Context(), svcCtx)
rl := reflect.ValueOf(l)
basic.BeforeLogic(w, r, rl)
resp := l.EditDepartment(&req, userinfo)
if !basic.AfterLogic(w, r, rl, resp) {
basic.NormalAfterLogic(w, r, resp)
}
}
}

View File

@ -0,0 +1,35 @@
package handler
import (
"net/http"
"reflect"
"fusenapi/utils/basic"
"fusenapi/server/ldap-admin/internal/logic"
"fusenapi/server/ldap-admin/internal/svc"
"fusenapi/server/ldap-admin/internal/types"
)
func EditMenuHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.EditMenuHandler
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
if err != nil {
return
}
// 创建一个业务逻辑层实例
l := logic.NewEditMenuLogic(r.Context(), svcCtx)
rl := reflect.ValueOf(l)
basic.BeforeLogic(w, r, rl)
resp := l.EditMenu(&req, userinfo)
if !basic.AfterLogic(w, r, rl, resp) {
basic.NormalAfterLogic(w, r, resp)
}
}
}

View File

@ -0,0 +1,35 @@
package handler
import (
"net/http"
"reflect"
"fusenapi/utils/basic"
"fusenapi/server/ldap-admin/internal/logic"
"fusenapi/server/ldap-admin/internal/svc"
"fusenapi/server/ldap-admin/internal/types"
)
func GetMenusTreeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.GetMenusTreeReq
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
if err != nil {
return
}
// 创建一个业务逻辑层实例
l := logic.NewGetMenusTreeLogic(r.Context(), svcCtx)
rl := reflect.ValueOf(l)
basic.BeforeLogic(w, r, rl)
resp := l.GetMenusTree(&req, userinfo)
if !basic.AfterLogic(w, r, rl, resp) {
basic.NormalAfterLogic(w, r, resp)
}
}
}

View File

@ -17,6 +17,36 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
Path: "/api/ldap-admin/get_departments",
Handler: GetDepartmentsHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/api/ldap-admin/add_department",
Handler: AddDepartmentHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/api/ldap-admin/edit_department",
Handler: EditDepartmentHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/api/ldap-admin/delete_department",
Handler: DeleteDepartmentHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/api/ldap-admin/get_menus_tree",
Handler: GetMenusTreeHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/api/ldap-admin/add_menu",
Handler: AddMenuHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/api/ldap-admin/edit_menu",
Handler: EditMenuHandler(serverCtx),
},
},
)
}

View File

@ -0,0 +1,62 @@
package logic
import (
"errors"
"fusenapi/model/gmodel"
"fusenapi/utils/auth"
"fusenapi/utils/basic"
"context"
"fusenapi/server/ldap-admin/internal/svc"
"fusenapi/server/ldap-admin/internal/types"
"github.com/zeromicro/go-zero/core/logx"
"gorm.io/gorm"
)
type AddDepartmentLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewAddDepartmentLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddDepartmentLogic {
return &AddDepartmentLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
// 处理进入前逻辑w,r
// func (l *AddDepartmentLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) {
// }
func (l *AddDepartmentLogic) AddDepartment(req *types.AddDepartmentReq, userinfo *auth.UserInfo) (resp *basic.Response) {
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
// userinfo 传入值时, 一定不为null
if req.ParentId > 0 {
_, err := l.svcCtx.AllModels.LdapDepartment.GetOneById(l.ctx, req.ParentId)
if err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
basic.CodeServiceErr.Message = "查询不到上级"
} else {
basic.CodeServiceErr.Message = "系统出错"
}
return resp.SetStatus(basic.CodeServiceErr)
}
}
err := l.svcCtx.AllModels.LdapDepartment.InsertOne(l.ctx, gmodel.LdapDepartment{
Name: &req.Name,
})
if err != nil {
return resp.SetStatus(basic.CodeServiceErr)
}
return resp.SetStatus(basic.CodeOK)
}
// 处理逻辑后 w,r 如:重定向, resp 必须重新处理
// func (l *AddDepartmentLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) {
// // httpx.OkJsonCtx(r.Context(), w, resp)
// }

View File

@ -0,0 +1,43 @@
package logic
import (
"fusenapi/utils/auth"
"fusenapi/utils/basic"
"context"
"fusenapi/server/ldap-admin/internal/svc"
"fusenapi/server/ldap-admin/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type AddMenuLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewAddMenuLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddMenuLogic {
return &AddMenuLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
// 处理进入前逻辑w,r
// func (l *AddMenuLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) {
// }
func (l *AddMenuLogic) AddMenu(req *types.AddMenuHandler, userinfo *auth.UserInfo) (resp *basic.Response) {
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
// userinfo 传入值时, 一定不为null
return resp.SetStatus(basic.CodeOK)
}
// 处理逻辑后 w,r 如:重定向, resp 必须重新处理
// func (l *AddMenuLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) {
// // httpx.OkJsonCtx(r.Context(), w, resp)
// }

View File

@ -0,0 +1,43 @@
package logic
import (
"fusenapi/utils/auth"
"fusenapi/utils/basic"
"context"
"fusenapi/server/ldap-admin/internal/svc"
"fusenapi/server/ldap-admin/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type DeleteDepartmentLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewDeleteDepartmentLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteDepartmentLogic {
return &DeleteDepartmentLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
// 处理进入前逻辑w,r
// func (l *DeleteDepartmentLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) {
// }
func (l *DeleteDepartmentLogic) DeleteDepartment(req *types.DeleteDepartmentReq, userinfo *auth.UserInfo) (resp *basic.Response) {
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
// userinfo 传入值时, 一定不为null
return resp.SetStatus(basic.CodeOK)
}
// 处理逻辑后 w,r 如:重定向, resp 必须重新处理
// func (l *DeleteDepartmentLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) {
// // httpx.OkJsonCtx(r.Context(), w, resp)
// }

View File

@ -0,0 +1,43 @@
package logic
import (
"fusenapi/utils/auth"
"fusenapi/utils/basic"
"context"
"fusenapi/server/ldap-admin/internal/svc"
"fusenapi/server/ldap-admin/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type EditDepartmentLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewEditDepartmentLogic(ctx context.Context, svcCtx *svc.ServiceContext) *EditDepartmentLogic {
return &EditDepartmentLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
// 处理进入前逻辑w,r
// func (l *EditDepartmentLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) {
// }
func (l *EditDepartmentLogic) EditDepartment(req *types.EditDepartmentReq, userinfo *auth.UserInfo) (resp *basic.Response) {
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
// userinfo 传入值时, 一定不为null
return resp.SetStatus(basic.CodeOK)
}
// 处理逻辑后 w,r 如:重定向, resp 必须重新处理
// func (l *EditDepartmentLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) {
// // httpx.OkJsonCtx(r.Context(), w, resp)
// }

View File

@ -0,0 +1,43 @@
package logic
import (
"fusenapi/utils/auth"
"fusenapi/utils/basic"
"context"
"fusenapi/server/ldap-admin/internal/svc"
"fusenapi/server/ldap-admin/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type EditMenuLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewEditMenuLogic(ctx context.Context, svcCtx *svc.ServiceContext) *EditMenuLogic {
return &EditMenuLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
// 处理进入前逻辑w,r
// func (l *EditMenuLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) {
// }
func (l *EditMenuLogic) EditMenu(req *types.EditMenuHandler, userinfo *auth.UserInfo) (resp *basic.Response) {
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
// userinfo 传入值时, 一定不为null
return resp.SetStatus(basic.CodeOK)
}
// 处理逻辑后 w,r 如:重定向, resp 必须重新处理
// func (l *EditMenuLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) {
// // httpx.OkJsonCtx(r.Context(), w, resp)
// }

View File

@ -4,6 +4,7 @@ import (
"fusenapi/constants"
"fusenapi/utils/auth"
"fusenapi/utils/basic"
"math"
"context"
@ -32,18 +33,34 @@ func NewGetDepartmentsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Ge
// }
func (l *GetDepartmentsLogic) GetDepartments(req *types.GetDepartmentsReq, userinfo *auth.UserInfo) (resp *basic.Response) {
if req.CurrentPage <= 0{
if req.CurrentPage <= 0 {
req.CurrentPage = constants.DEFAULT_PAGE
}
if req.PageSize <= 0{
if req.PageSize <= 0 {
req.PageSize = constants.DEFAULT_PAGE_SIZE
}
/*departList,total,err := l.svcCtx.AllModels.LdapDepartment.GetList(l.ctx,req.CurrentPage,req.PageSize,"")
if err != nil{
resList, resTotal, err := l.svcCtx.AllModels.LdapDepartment.GetList(l.ctx, req.CurrentPage, req.PageSize, "")
if err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeDbSqlErr,"获取部门列表失败")
}*/
return resp.SetStatus(basic.CodeOK)
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "获取部门列表失败")
}
var pageCount int64 = 1
if resTotal > int64(req.PageSize) {
var float64Count = float64(resTotal)
var float64PerPage = float64(req.PageSize)
pageCountFloat := math.Ceil(float64Count / float64PerPage)
pageCount = int64(pageCountFloat)
}
return resp.SetStatus(basic.CodeOK, map[string]interface{}{
"list": resList,
"meta": map[string]int64{
"total_count": resTotal,
"page_count": pageCount,
"current_page": int64(req.CurrentPage),
"per_page": int64(req.PageSize),
},
})
}
// 处理逻辑后 w,r 如:重定向, resp 必须重新处理

View File

@ -0,0 +1,43 @@
package logic
import (
"fusenapi/utils/auth"
"fusenapi/utils/basic"
"context"
"fusenapi/server/ldap-admin/internal/svc"
"fusenapi/server/ldap-admin/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type GetMenusTreeLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewGetMenusTreeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetMenusTreeLogic {
return &GetMenusTreeLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
// 处理进入前逻辑w,r
// func (l *GetMenusTreeLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) {
// }
func (l *GetMenusTreeLogic) GetMenusTree(req *types.GetMenusTreeReq, userinfo *auth.UserInfo) (resp *basic.Response) {
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
// userinfo 传入值时, 一定不为null
return resp.SetStatus(basic.CodeOK)
}
// 处理逻辑后 w,r 如:重定向, resp 必须重新处理
// func (l *GetMenusTreeLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) {
// // httpx.OkJsonCtx(r.Context(), w, resp)
// }

View File

@ -5,6 +5,57 @@ import (
"fusenapi/utils/basic"
)
type EditMenuHandler struct {
Id int64 `json:"id"`
Name string `json:"name"`
Title string `json:"title"`
Icon string `json:"icon"`
Path string `json:"path"`
Sort int64 `json:"sort"`
Status int64 `json:"status"`
ParentId int64 `json:"parent_id"`
Creator string `json:"creator"`
}
type AddMenuHandler struct {
Name string `json:"name"`
Title string `json:"title"`
Icon string `json:"icon"`
Path string `json:"path"`
Sort int64 `json:"sort"`
Status int64 `json:"status"`
ParentId int64 `json:"parent_id"`
Creator string `json:"creator"`
}
type GetMenusTreeReq struct {
}
type AddDepartmentReq struct {
Name string `json:"name"`
Remark string `json:"remark"`
Creator string `json:"creator"`
Type string `json:"type"`
ParentId int64 `json:"parent_id"`
Dn string `json:"dn"`
SyncState int64 `json:"sync_state"`
}
type EditDepartmentReq struct {
Id int64 `json:"id"`
Name string `json:"name"`
Remark string `json:"remark"`
Creator string `json:"creator"`
Type string `json:"type"`
ParentId int64 `json:"parent_id"`
Dn string `json:"dn"`
SyncState int64 `json:"sync_state"`
}
type DeleteDepartmentReq struct {
Id int64 `json:"id"`
}
type GetDepartmentsReq struct {
CurrentPage int `form:"current_page"`
PageSize int `form:"page_size"`

View File

@ -13,6 +13,85 @@ service ldap-admin {
//获取部门列表
@handler GetDepartmentsHandler
post /api/ldap-admin/get_departments(GetDepartmentsReq) returns (response);
// 新增部门
@handler AddDepartmentHandler
post /api/ldap-admin/add_department(AddDepartmentReq) returns (response);
// 编辑部门
@handler EditDepartmentHandler
post /api/ldap-admin/edit_department(EditDepartmentReq) returns (response);
// 删除部门
@handler DeleteDepartmentHandler
post /api/ldap-admin/delete_department(DeleteDepartmentReq) returns (response);
//获取菜单列表--树形
@handler GetMenusTreeHandler
post /api/ldap-admin/get_menus_tree(GetMenusTreeReq) returns (response);
// 新增菜单
@handler AddMenuHandler
post /api/ldap-admin/add_menu(AddMenuHandler) returns (response);
// 编辑菜单
@handler EditMenuHandler
post /api/ldap-admin/edit_menu(EditMenuHandler) returns (response);
}
type EditMenuHandler {
Id int64 `json:"id"`
Name string `json:"name"`
Title string `json:"title"`
Icon string `json:"icon"`
Path string `json:"path"`
Sort int64 `json:"sort"`
Status int64 `json:"status"`
ParentId int64 `json:"parent_id"`
Creator string `json:"creator"`
}
type AddMenuHandler {
Name string `json:"name"`
Title string `json:"title"`
Icon string `json:"icon"`
Path string `json:"path"`
Sort int64 `json:"sort"`
Status int64 `json:"status"`
ParentId int64 `json:"parent_id"`
Creator string `json:"creator"`
}
//获取菜单列表--树形
type GetMenusTreeReq {
}
// 新增部门
type AddDepartmentReq {
Name string `json:"name"`
Remark string `json:"remark"`
Creator string `json:"creator"`
Type string `json:"type"`
ParentId int64 `json:"parent_id"`
Dn string `json:"dn"`
SyncState int64 `json:"sync_state"`
}
// 编辑部门
type EditDepartmentReq {
Id int64 `json:"id"`
Name string `json:"name"`
Remark string `json:"remark"`
Creator string `json:"creator"`
Type string `json:"type"`
ParentId int64 `json:"parent_id"`
Dn string `json:"dn"`
SyncState int64 `json:"sync_state"`
}
// 删除部门
type DeleteDepartmentReq {
Id int64 `json:"id"`
}
//获取部门列表