This commit is contained in:
laodaming 2023-11-13 18:57:11 +08:00
parent 3bde233e8a
commit e4c8d033dc
12 changed files with 254 additions and 12 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

@ -12,7 +12,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,45 @@
package gmodel
import "context"
import (
"context"
"errors"
"gorm.io/gorm"
)
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)GetList(ctx context.Context,page,limit int,sort string)(resp []LdapDepartment,total int64,err error){
db := d.db.WithContext(ctx).Model(&LdapDepartment{})
if sort != ""{
db = db.Order(sort)
}
if err = db.Count(&total).Error;err != nil{
return nil, 0, err
}
offset := (page - 1) * limit
err = db.Offset(offset).Limit(limit).Find(&resp).Error
return resp, total, err
}
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
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)Create(ctx context.Context,data *LdapDepartment)error{
return d.db.WithContext(ctx).Model(&LdapDepartment{}).Create(&data).Error
}
func (d *LdapDepartmentModel)CreateOrUpdate(ctx context.Context,id int64,data *LdapDepartment)error{
_,err := d.FindOne(ctx,id)
if err != nil{
if errors.Is(err,gorm.ErrRecordNotFound){
return d.Create(ctx,data)
}
return err
}
return d.Update(ctx,id,data)
}

View File

@ -12,7 +12,7 @@ type LdapUsers struct {
Password *string `gorm:"default:'';" json:"password"` //
Nickname *string `gorm:"default:'';" json:"nickname"` //
GivenName *string `gorm:"default:'';" json:"given_name"` //
Email *string `gorm:"default:'';" json:"email"` //
Email *string `gorm:"unique_key;default:'';" json:"email"` //
JobNumber *string `gorm:"default:'';" json:"job_number"` //
Mobile *string `gorm:"unique_key;default:'';" json:"mobile"` //
Avatar *string `gorm:"default:'';" json:"avatar"` //

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

@ -17,6 +17,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
Path: "/api/ldap-admin/get_departments",
Handler: GetDepartmentsHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/api/ldap-admin/save_department",
Handler: SaveDepartmentHandler(serverCtx),
},
},
)
}

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 SaveDepartmentHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.SaveDepartmentReq
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
if err != nil {
return
}
// 创建一个业务逻辑层实例
l := logic.NewSaveDepartmentLogic(r.Context(), svcCtx)
rl := reflect.ValueOf(l)
basic.BeforeLogic(w, r, rl)
resp := l.SaveDepartment(&req, userinfo)
if !basic.AfterLogic(w, r, rl, resp) {
basic.NormalAfterLogic(w, r, resp)
}
}
}

View File

@ -4,6 +4,7 @@ import (
"fusenapi/constants"
"fusenapi/utils/auth"
"fusenapi/utils/basic"
"math"
"context"
@ -32,18 +33,39 @@ func NewGetDepartmentsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Ge
// }
func (l *GetDepartmentsLogic) GetDepartments(req *types.GetDepartmentsReq, userinfo *auth.UserInfo) (resp *basic.Response) {
//todo 鉴权 。。。。
if req.CurrentPage <= 0{
req.CurrentPage = constants.DEFAULT_PAGE
}
if req.PageSize <= 0{
req.PageSize = constants.DEFAULT_PAGE_SIZE
if req.Limit <= 0{
req.Limit = constants.DEFAULT_PAGE_SIZE
}
/*departList,total,err := l.svcCtx.AllModels.LdapDepartment.GetList(l.ctx,req.CurrentPage,req.PageSize,"")
departList,total,err := l.svcCtx.AllModels.LdapDepartment.GetList(l.ctx,req.CurrentPage,req.Limit,"")
if err != nil{
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeDbSqlErr,"获取部门列表失败")
}*/
return resp.SetStatus(basic.CodeOK)
}
list := make([]types.DepartmentsItem,0,len(departList))
for _,v := range departList{
list = append(list,types.DepartmentsItem{
Id: v.Id,
Name: *v.Name,
Remark: *v.Remark,
Type: *v.Type,
ParentId: *v.ParentId,
Dn: *v.Dn,
SyncState: *v.SyncState,
})
}
return resp.SetStatus(basic.CodeOK,"success",types.GetDepartmentsRsp{
List: list,
Meta: types.Meta{
TotalCount: total,
PageCount: int64(math.Ceil(float64(total) / float64(req.Limit))),
CurrentPage: req.CurrentPage,
PerPage: req.Limit,
},
})
}
// 处理逻辑后 w,r 如:重定向, resp 必须重新处理

View File

@ -0,0 +1,41 @@
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 SaveDepartmentLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewSaveDepartmentLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SaveDepartmentLogic {
return &SaveDepartmentLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
// 处理进入前逻辑w,r
// func (l *SaveDepartmentLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) {
// }
func (l *SaveDepartmentLogic) SaveDepartment(req *types.SaveDepartmentReq, userinfo *auth.UserInfo) (resp *basic.Response) {
//todo 鉴权。。。
return resp.SetStatus(basic.CodeOK)
}
// 处理逻辑后 w,r 如:重定向, resp 必须重新处理
// func (l *SaveDepartmentLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) {
// // httpx.OkJsonCtx(r.Context(), w, resp)
// }

View File

@ -7,7 +7,31 @@ import (
type GetDepartmentsReq struct {
CurrentPage int `form:"current_page"`
PageSize int `form:"page_size"`
Limit int `form:"limit"`
}
type GetDepartmentsRsp struct {
List []DepartmentsItem `json:"list"`
Meta Meta `json:"meta"`
}
type DepartmentsItem struct {
Id int64 `json:"id"`
Name string `json:"name"`
Remark string `json:"remark"`
Type string `json:"type"`
ParentId int64 `json:"parent_id"`
Dn string `json:"dn"`
SyncState int64 `json:"sync_state"`
}
type SaveDepartmentReq struct {
Id int64 `json:"id"`
Name string `json:"name"`
Remark string `json:"remark"`
Type string `json:"type"`
ParentId int64 `json:"parent_id"`
Dn string `json:"dn"`
}
type Request struct {

View File

@ -13,10 +13,35 @@ service ldap-admin {
//获取部门列表
@handler GetDepartmentsHandler
post /api/ldap-admin/get_departments(GetDepartmentsReq) returns (response);
//保存部门信息
@handler SaveDepartmentHandler
post /api/ldap-admin/save_department(SaveDepartmentReq) returns (response);
}
//获取部门列表
type GetDepartmentsReq {
CurrentPage int `form:"current_page"`
PageSize int `form:"page_size"`
Limit int `form:"limit"`
}
type GetDepartmentsRsp {
List []DepartmentsItem `json:"list"`
Meta Meta `json:"meta"`
}
type DepartmentsItem {
Id int64 `json:"id"`
Name string `json:"name"`
Remark string `json:"remark"`
Type string `json:"type"`
ParentId int64 `json:"parent_id"`
Dn string `json:"dn"`
SyncState int64 `json:"sync_state"`
}
//保存部门信息
type SaveDepartmentReq {
Id int64 `json:"id"`
Name string `json:"name"`
Remark string `json:"remark"`
Type string `json:"type"`
ParentId int64 `json:"parent_id"`
Dn string `json:"dn"`
}