refactor platform logic modules

This commit is contained in:
david
2026-07-28 13:55:40 +08:00
parent bc39021c0d
commit bc8138f978
29 changed files with 861 additions and 776 deletions

View File

@@ -5,7 +5,18 @@ import (
"git.apinb.com/bsm-sdk/core/middleware"
"git.apinb.com/heqiapp/platforms/backend/api/internal/logic/common"
"git.apinb.com/heqiapp/platforms/backend/api/internal/logic/platform"
platformbase "git.apinb.com/heqiapp/platforms/backend/api/internal/logic/platform"
"git.apinb.com/heqiapp/platforms/backend/api/internal/logic/platform/dashboard"
"git.apinb.com/heqiapp/platforms/backend/api/internal/logic/platform/delivery"
"git.apinb.com/heqiapp/platforms/backend/api/internal/logic/platform/ec"
"git.apinb.com/heqiapp/platforms/backend/api/internal/logic/platform/fin"
"git.apinb.com/heqiapp/platforms/backend/api/internal/logic/platform/gas"
"git.apinb.com/heqiapp/platforms/backend/api/internal/logic/platform/gasorder"
platformlogic "git.apinb.com/heqiapp/platforms/backend/api/internal/logic/platform/platform"
"git.apinb.com/heqiapp/platforms/backend/api/internal/logic/platform/product"
"git.apinb.com/heqiapp/platforms/backend/api/internal/logic/platform/staff"
userlogic "git.apinb.com/heqiapp/platforms/backend/api/internal/logic/platform/user"
"git.apinb.com/heqiapp/platforms/backend/api/internal/logic/platform/wallet"
"git.apinb.com/heqiapp/platforms/backend/api/internal/models"
"github.com/gin-gonic/gin"
)
@@ -14,15 +25,15 @@ import (
func RegisterPlatform(serviceKey string, engine *gin.Engine) {
basePath := fmt.Sprintf("/%s/platform/v1", serviceKey)
anonymous := engine.Group(basePath)
anonymous.GET("/ping/hello", platform.PingHello)
anonymous.POST("/auth/login", platform.Login)
anonymous.GET("/ping/hello", dashboard.PingHello)
anonymous.POST("/auth/login", platformbase.Login)
protected := engine.Group(basePath)
protected.Use(middleware.JwtAuth(true))
protected.Use(platform.RequirePlatformMenuAccess())
protected.GET("/auth/profile", platform.CurrentProfile)
protected.PUT("/auth/password", platform.ChangePassword)
protected.GET("/dashboard/overview", platform.DashboardOverview)
protected.Use(platformlogic.RequirePlatformMenuAccess())
protected.GET("/auth/profile", platformbase.CurrentProfile)
protected.PUT("/auth/password", platformbase.ChangePassword)
protected.GET("/dashboard/overview", dashboard.DashboardOverview)
registerGasRoute(protected)
registerDeliveryRoute(protected)
@@ -38,50 +49,50 @@ func RegisterPlatform(serviceKey string, engine *gin.Engine) {
}
func registerGasRoute(group *gin.RouterGroup) {
registerWritableResource(group, "/gas_basic", platform.ListGasBasic, platform.CreateGasBasic, platform.GetGasBasic, platform.UpdateGasBasic, &models.GasBasic{})
registerWritableResource(group, "/gas_account", platform.ListGasAccount, platform.CreateGasAccount, platform.GetGasAccount, platform.UpdateGasAccount, &models.GasAccount{})
registerWritableResource(group, "/gas_basic", gas.ListGasBasic, gas.CreateGasBasic, gas.GetGasBasic, gas.UpdateGasBasic, &models.GasBasic{})
registerWritableResource(group, "/gas_account", gas.ListGasAccount, gas.CreateGasAccount, gas.GetGasAccount, gas.UpdateGasAccount, &models.GasAccount{})
}
func registerDeliveryRoute(group *gin.RouterGroup) {
registerWritableResource(group, "/delivery_basic", platform.ListDeliveryBasic, platform.CreateDeliveryBasic, platform.GetDeliveryBasic, platform.UpdateDeliveryBasic, &models.DeliveryBasic{})
registerWritableResource(group, "/delivery_account", platform.ListDeliveryAccount, platform.CreateDeliveryAccount, platform.GetDeliveryAccount, platform.UpdateDeliveryAccount, &models.DeliveryAccount{})
registerWritableResource(group, "/delivery_basic", delivery.ListDeliveryBasic, delivery.CreateDeliveryBasic, delivery.GetDeliveryBasic, delivery.UpdateDeliveryBasic, &models.DeliveryBasic{})
registerWritableResource(group, "/delivery_account", delivery.ListDeliveryAccount, delivery.CreateDeliveryAccount, delivery.GetDeliveryAccount, delivery.UpdateDeliveryAccount, &models.DeliveryAccount{})
}
func registerGasorderRoute(group *gin.RouterGroup) {
contract := group.Group("/gasorder_contract")
contract.GET("", platform.ListGasorderContract)
contract.POST("", platform.CreateGasorderContract)
contract.GET("/:identity", platform.GetGasorderContract)
contract.PUT("/:identity", platform.UpdateGasorderContract)
contract.POST("/:identity/activate", platform.ActivateGasorderContract)
contract.POST("/:identity/renew", platform.RenewGasorderContract)
contract.POST("/:identity/terminate", platform.TerminateGasorderContract)
contract.GET("", gasorder.ListGasorderContract)
contract.POST("", gasorder.CreateGasorderContract)
contract.GET("/:identity", gasorder.GetGasorderContract)
contract.PUT("/:identity", gasorder.UpdateGasorderContract)
contract.POST("/:identity/activate", gasorder.ActivateGasorderContract)
contract.POST("/:identity/renew", gasorder.RenewGasorderContract)
contract.POST("/:identity/terminate", gasorder.TerminateGasorderContract)
contractProduct := group.Group("/gasorder_contract_product")
contractProduct.GET("", platform.ListGasorderContractProduct)
contractProduct.POST("", platform.BindGasorderContractProduct)
contractProduct.GET("/:identity", platform.GetGasorderContractProduct)
contractProduct.POST("/:identity/unbind", platform.UnbindGasorderContractProduct)
registerReadOnlyHandlers(group, "/gasorder_contract_revision", platform.ListGasorderContractRevision, platform.GetGasorderContractRevision)
contractProduct.GET("", gasorder.ListGasorderContractProduct)
contractProduct.POST("", gasorder.BindGasorderContractProduct)
contractProduct.GET("/:identity", gasorder.GetGasorderContractProduct)
contractProduct.POST("/:identity/unbind", gasorder.UnbindGasorderContractProduct)
registerReadOnlyHandlers(group, "/gasorder_contract_revision", gasorder.ListGasorderContractRevision, gasorder.GetGasorderContractRevision)
order := group.Group("/gasorder_basic")
order.GET("", platform.ListGasorderBasic)
order.POST("", platform.CreateGasorderBasic)
order.GET("/:identity", platform.GetGasorderBasic)
order.POST("/:identity/assign", platform.AssignGasorderBasic)
order.POST("/:identity/filling", platform.GasorderStartFilling)
order.POST("/:identity/ready", platform.GasorderReady)
order.POST("/:identity/exception", platform.GasorderException)
order.POST("/:identity/recover", platform.GasorderRecover)
order.POST("/:identity/cancel", platform.GasorderCancel)
order.GET("", gasorder.ListGasorderBasic)
order.POST("", gasorder.CreateGasorderBasic)
order.GET("/:identity", gasorder.GetGasorderBasic)
order.POST("/:identity/assign", gasorder.AssignGasorderBasic)
order.POST("/:identity/filling", gasorder.GasorderStartFilling)
order.POST("/:identity/ready", gasorder.GasorderReady)
order.POST("/:identity/exception", gasorder.GasorderException)
order.POST("/:identity/recover", gasorder.GasorderRecover)
order.POST("/:identity/cancel", gasorder.GasorderCancel)
registerReadOnlyHandlers(group, "/gasorder_item", platform.ListGasorderItem, platform.GetGasorderItem)
registerReadOnlyHandlers(group, "/gasorder_assign", platform.ListGasorderAssign, platform.GetGasorderAssign)
registerReadOnlyHandlers(group, "/gasorder_status", platform.ListGasorderStatus, platform.GetGasorderStatus)
registerReadOnlyHandlers(group, "/gasorder_track", platform.ListGasorderTrack, platform.GetGasorderTrack)
registerReadOnlyHandlers(group, "/gasorder_track_point", platform.ListGasorderTrackPoint, platform.GetGasorderTrackPoint)
registerReadOnlyHandlers(group, "/gasorder_confirm", platform.ListGasorderConfirm, platform.GetGasorderConfirm)
registerReadOnlyHandlers(group, "/gasorder_payment", platform.ListGasorderPayment, platform.GetGasorderPayment)
registerReadOnlyHandlers(group, "/gasorder_item", gasorder.ListGasorderItem, gasorder.GetGasorderItem)
registerReadOnlyHandlers(group, "/gasorder_assign", gasorder.ListGasorderAssign, gasorder.GetGasorderAssign)
registerReadOnlyHandlers(group, "/gasorder_status", gasorder.ListGasorderStatus, gasorder.GetGasorderStatus)
registerReadOnlyHandlers(group, "/gasorder_track", gasorder.ListGasorderTrack, gasorder.GetGasorderTrack)
registerReadOnlyHandlers(group, "/gasorder_track_point", gasorder.ListGasorderTrackPoint, gasorder.GetGasorderTrackPoint)
registerReadOnlyHandlers(group, "/gasorder_confirm", gasorder.ListGasorderConfirm, gasorder.GetGasorderConfirm)
registerReadOnlyHandlers(group, "/gasorder_payment", gasorder.ListGasorderPayment, gasorder.GetGasorderPayment)
}
func registerProductRoute(group *gin.RouterGroup) {
@@ -95,20 +106,20 @@ func registerProductRoute(group *gin.RouterGroup) {
optionalRelation("delivery_basic_identity", "delivery_basic_id", &models.DeliveryBasic{}),
optionalRelation("user_account_identity", "user_account_id", &models.UserAccount{}),
}
infoList, infoCreate, infoGet, infoUpdate := platform.ProductInfoHandlers(infoRelations...)
infoList, infoCreate, infoGet, infoUpdate := product.ProductInfoHandlers(infoRelations...)
info := group.Group("/product_info")
info.GET("", infoList)
info.POST("", infoCreate)
info.GET("/:identity", infoGet)
info.PUT("/:identity", infoUpdate)
info.PATCH("/:identity/status", platform.UpdateProductInfoStatus)
info.PATCH("/:identity/status", product.UpdateProductInfoStatus)
repairList, repairCreate, repairGet, repairUpdate := platform.ProductRepairHandlers(
repairList, repairCreate, repairGet, repairUpdate := product.ProductRepairHandlers(
requiredRelation("product_info_identity", "product_info_id", &models.ProductInfo{}),
)
registerNoDeleteResource(group, "/product_repair", repairList, repairCreate, repairGet, repairUpdate, &models.ProductRepair{})
ownerList, ownerCreate, ownerGet := platform.ProductOwnerHandlers(
ownerList, ownerCreate, ownerGet := product.ProductOwnerHandlers(
requiredRelation("product_info_identity", "product_info_id", &models.ProductInfo{}),
optionalRelation("warehouse_identity", "warehouse_id", &models.ProductWarehouse{}),
optionalRelation("gas_basic_identity", "gas_basic_id", &models.GasBasic{}),
@@ -123,90 +134,90 @@ func registerProductRoute(group *gin.RouterGroup) {
func registerWalletRoute(group *gin.RouterGroup) {
basic := group.Group("/wallet_basic")
basic.GET("", platform.ListWalletBasic)
basic.GET("/:identity", platform.GetWalletBasic)
basic.PATCH("/:identity/status", platform.UpdateWalletBasicStatus)
basic.POST("/:identity/recharge", platform.RechargeWalletBasic)
basic.GET("/owner/:owner_type/:owner_identity", platform.GetOrCreateOwnerWallet)
basic.GET("", wallet.ListWalletBasic)
basic.GET("/:identity", wallet.GetWalletBasic)
basic.PATCH("/:identity/status", wallet.UpdateWalletBasicStatus)
basic.POST("/:identity/recharge", wallet.RechargeWalletBasic)
basic.GET("/owner/:owner_type/:owner_identity", wallet.GetOrCreateOwnerWallet)
bank := group.Group("/wallet_bank")
bank.GET("", platform.ListWalletBank)
bank.GET("/:identity", platform.GetWalletBank)
bank.GET("", wallet.ListWalletBank)
bank.GET("/:identity", wallet.GetWalletBank)
payment := group.Group("/wallet_payment")
payment.GET("", platform.ListWalletPayment)
payment.GET("/:identity", platform.GetWalletPayment)
payment.GET("", wallet.ListWalletPayment)
payment.GET("/:identity", wallet.GetWalletPayment)
record := group.Group("/wallet_record")
record.GET("", platform.ListWalletRecord)
record.GET("/:identity", platform.GetWalletRecord)
record.GET("", wallet.ListWalletRecord)
record.GET("/:identity", wallet.GetWalletRecord)
refund := group.Group("/wallet_refund")
refund.GET("", platform.ListWalletRefund)
refund.GET("/:identity", platform.GetWalletRefund)
refund.GET("", wallet.ListWalletRefund)
refund.GET("/:identity", wallet.GetWalletRefund)
applyCash := group.Group("/wallet_apply_cash")
applyCash.GET("", platform.ListWalletApplyCash)
applyCash.GET("/:identity", platform.GetWalletApplyCash)
applyCash.POST("/:identity/approve", platform.ApproveWalletApplyCash)
applyCash.POST("/:identity/reject", platform.RejectWalletApplyCash)
applyCash.GET("", wallet.ListWalletApplyCash)
applyCash.GET("/:identity", wallet.GetWalletApplyCash)
applyCash.POST("/:identity/approve", wallet.ApproveWalletApplyCash)
applyCash.POST("/:identity/reject", wallet.RejectWalletApplyCash)
}
func registerCommerceRoute(group *gin.RouterGroup) {
categoryRelations := []common.ResourceRelation{optionalRelation("parent_identity", "parent_id", &models.EcCategory{})}
_, categoryCreate, _, categoryUpdate := common.ResourceHandlers(&models.EcCategory{}, []string{"name", "sort_no"}, []string{"name", "sort_no"}, categoryRelations...)
registerWritableResource(group, "/ec_category", platform.ListEcCategory, categoryCreate, platform.GetEcCategory, categoryUpdate, &models.EcCategory{})
registerWritableResource(group, "/ec_category", ec.ListEcCategory, categoryCreate, ec.GetEcCategory, categoryUpdate, &models.EcCategory{})
registerRestrictedWritableResource(group, "/ec_product", &models.EcProduct{}, []string{"product_code", "name", "price_amount", "stock_quantity"}, requiredRelation("ec_category_identity", "ec_category_id", &models.EcCategory{}))
registerRestrictedWritableResource(group, "/ec_product_attribute", &models.EcProductAttribute{}, []string{"name", "value", "sort_no"}, requiredRelation("ec_product_identity", "ec_product_id", &models.EcProduct{}))
registerRestrictedWritableResource(group, "/ec_product_image", &models.EcProductImage{}, []string{"image_uri", "sort_no", "is_cover"}, requiredRelation("ec_product_identity", "ec_product_id", &models.EcProduct{}))
registerRestrictedWritableResource(group, "/ec_cart", &models.EcCart{}, []string{"quantity", "selected"}, requiredRelation("user_account_identity", "user_account_id", &models.UserAccount{}), requiredRelation("ec_product_identity", "ec_product_id", &models.EcProduct{}))
orderRelations := []common.ResourceRelation{requiredRelation("user_account_identity", "user_account_id", &models.UserAccount{}), optionalRelation("gas_basic_identity", "gas_station_id", &models.GasBasic{}), optionalRelation("delivery_basic_identity", "delivery_point_id", &models.DeliveryBasic{})}
list, create, _, update := common.ResourceHandlers(&models.EcOrder{}, []string{"order_no", "total_amount"}, []string{"total_amount"}, orderRelations...)
registerWritableResource(group, "/ec_order", list, create, platform.GetEcOrder, update, &models.EcOrder{})
registerWritableResource(group, "/ec_order", list, create, ec.GetEcOrder, update, &models.EcOrder{})
registerRestrictedWritableResource(group, "/ec_order_item", &models.EcOrderItem{}, []string{"product_snapshot", "quantity", "sale_amount"}, requiredRelation("ec_order_identity", "ec_order_id", &models.EcOrder{}), requiredRelation("ec_product_identity", "ec_product_id", &models.EcProduct{}))
registerRestrictedWritableResource(group, "/ec_review", &models.EcReview{}, []string{"score", "content"}, requiredRelation("ec_order_identity", "ec_order_id", &models.EcOrder{}), requiredRelation("ec_product_identity", "ec_product_id", &models.EcProduct{}), requiredRelation("user_account_identity", "user_account_id", &models.UserAccount{}))
}
func registerStaffRoute(group *gin.RouterGroup) {
registerWritableResource(group, "/staff_account", platform.ListStaff, platform.CreateStaff, platform.GetStaff, platform.UpdateStaff, &models.StaffAccount{})
registerWritableResource(group, "/staff_credential", platform.ListStaffCredential, platform.CreateStaffCredential, platform.GetStaffCredential, platform.UpdateStaffCredential, &models.StaffCredential{})
registerWritableResource(group, "/staff_account", staff.ListStaff, staff.CreateStaff, staff.GetStaff, staff.UpdateStaff, &models.StaffAccount{})
registerWritableResource(group, "/staff_credential", staff.ListStaffCredential, staff.CreateStaffCredential, staff.GetStaffCredential, staff.UpdateStaffCredential, &models.StaffCredential{})
}
func registerUserRoute(group *gin.RouterGroup) {
registerWritableResource(group, "/user_account", platform.ListUser, platform.CreateUser, platform.GetUser, platform.UpdateUser, &models.UserAccount{})
registerWritableResource(group, "/user_address", platform.ListUserAddress, platform.CreateUserAddress, platform.GetUserAddress, platform.UpdateUserAddress, &models.UserAddress{})
registerWritableResource(group, "/user_service_relation", platform.ListUserServiceRelation, platform.CreateUserServiceRelation, platform.GetUserServiceRelation, platform.UpdateUserServiceRelation, &models.UserServiceRelation{})
registerWritableResource(group, "/user_account", userlogic.ListUser, userlogic.CreateUser, userlogic.GetUser, userlogic.UpdateUser, &models.UserAccount{})
registerWritableResource(group, "/user_address", userlogic.ListUserAddress, userlogic.CreateUserAddress, userlogic.GetUserAddress, userlogic.UpdateUserAddress, &models.UserAddress{})
registerWritableResource(group, "/user_service_relation", userlogic.ListUserServiceRelation, userlogic.CreateUserServiceRelation, userlogic.GetUserServiceRelation, userlogic.UpdateUserServiceRelation, &models.UserServiceRelation{})
}
func registerPlatformRoute(group *gin.RouterGroup) {
account := group.Group("/platform_account")
account.GET("", platform.ListPlatformAccount)
account.POST("", platform.CreatePlatformAccount)
account.GET("/:identity", platform.GetPlatformAccount)
account.PUT("/:identity", platform.UpdatePlatformAccount)
account.PATCH("/:identity/status", platform.UpdatePlatformAccountStatus)
account.DELETE("/:identity", platform.ArchivePlatformAccount)
account.GET("", platformlogic.ListPlatformAccount)
account.POST("", platformlogic.CreatePlatformAccount)
account.GET("/:identity", platformlogic.GetPlatformAccount)
account.PUT("/:identity", platformlogic.UpdatePlatformAccount)
account.PATCH("/:identity/status", platformlogic.UpdatePlatformAccountStatus)
account.DELETE("/:identity", platformlogic.ArchivePlatformAccount)
role := group.Group("/platform_role")
role.GET("", platform.ListPlatformRole)
role.POST("", platform.CreatePlatformRole)
role.GET("/:identity", platform.GetPlatformRole)
role.PUT("/:identity", platform.UpdatePlatformRole)
role.PATCH("/:identity/status", platform.UpdatePlatformRoleStatus)
role.DELETE("/:identity", platform.ArchivePlatformRole)
role.GET("/:identity/menu", platform.ListPlatformRoleMenuIdentities)
role.PUT("/:identity/menu", platform.ReplacePlatformRoleMenus)
role.GET("", platformlogic.ListPlatformRole)
role.POST("", platformlogic.CreatePlatformRole)
role.GET("/:identity", platformlogic.GetPlatformRole)
role.PUT("/:identity", platformlogic.UpdatePlatformRole)
role.PATCH("/:identity/status", platformlogic.UpdatePlatformRoleStatus)
role.DELETE("/:identity", platformlogic.ArchivePlatformRole)
role.GET("/:identity/menu", platformlogic.ListPlatformRoleMenuIdentities)
role.PUT("/:identity/menu", platformlogic.ReplacePlatformRoleMenus)
menu := group.Group("/platform_menu")
menu.GET("", platform.ListPlatformMenu)
menu.POST("", platform.CreatePlatformMenu)
menu.GET("/:identity", platform.GetPlatformMenu)
menu.PUT("/:identity", platform.UpdatePlatformMenu)
menu.PATCH("/:identity/status", platform.UpdatePlatformMenuStatus)
menu.DELETE("/:identity", platform.ArchivePlatformMenu)
menu.GET("", platformlogic.ListPlatformMenu)
menu.POST("", platformlogic.CreatePlatformMenu)
menu.GET("/:identity", platformlogic.GetPlatformMenu)
menu.PUT("/:identity", platformlogic.UpdatePlatformMenu)
menu.PATCH("/:identity/status", platformlogic.UpdatePlatformMenuStatus)
menu.DELETE("/:identity", platformlogic.ArchivePlatformMenu)
}
func registerFinanceRoute(group *gin.RouterGroup) {
registerRestrictedWritableResource(group, "/fin_payment", &models.FinPayment{}, []string{"channel", "amount", "paid_at"}, requiredRelation("ec_order_identity", "ec_order_id", &models.EcOrder{}))
settlementList, settlementCreate, settlementGet, settlementUpdate := platform.FinSettlementHandlers()
settlementList, settlementCreate, settlementGet, settlementUpdate := fin.FinSettlementHandlers()
registerWritableResource(group, "/fin_settlement", settlementList, settlementCreate, settlementGet, settlementUpdate, &models.FinSettlement{})
registerRestrictedWritableResource(group, "/fin_reconciliation", &models.FinReconciliation{}, []string{"channel", "bill_date", "difference_amount"})