From 033c8090c90fe3770cefdd772a5a70153ceadf23 Mon Sep 17 00:00:00 2001 From: Matrix-X Date: Tue, 8 Oct 2024 23:57:46 +0800 Subject: [PATCH] feat(migrate): change migrate schema with config schema --- cmd/ctl/database/migrate/powerx.go | 6 +- cmd/ctl/powerxctl.go | 1 + internal/model/crm/market/media.go | 12 ++++ internal/model/crm/market/mgm.go | 61 +++++++++++++++++++ internal/model/crm/market/promotion.go | 17 +++++- internal/model/crm/market/store.go | 14 ++++- internal/model/crm/operation/membership.go | 13 ++++ internal/model/crm/operation/ticket.go | 4 +- internal/model/crm/product/artisan.go | 12 +++- .../product/pivotproducttoproductcategory.go | 17 ++++-- .../crm/product/pivotskutospecificoption.go | 17 ++++-- .../model/crm/product/pivotstoretoartisan.go | 17 ++++-- internal/model/crm/product/pricebook.go | 13 ++++ internal/model/crm/product/pricebookentry.go | 13 ++++ internal/model/crm/product/priceconfig.go | 13 ++++ internal/model/crm/product/product.go | 26 ++++---- internal/model/crm/product/productcategory.go | 12 ++++ internal/model/crm/product/productspecific.go | 29 ++++++++- .../model/crm/product/productstatistics.go | 17 +++++- internal/model/crm/product/sku.go | 13 ++++ internal/model/crm/trade/billingaddress.go | 17 +++++- internal/model/crm/trade/cart.go | 25 ++++++++ internal/model/crm/trade/deliveryaddress.go | 17 +++++- internal/model/crm/trade/inventory.go | 17 +++++- internal/model/crm/trade/logistics.go | 13 ++++ internal/model/crm/trade/order.go | 38 ++++++++++++ internal/model/crm/trade/payment.go | 25 ++++++++ .../crm/trade/pivotordertonventorylog.go | 13 ++++ .../crm/trade/pivotproducttopromotion.go | 13 ++++ internal/model/crm/trade/refund.go | 25 ++++++++ internal/model/crm/trade/shippingaddress.go | 17 +++++- internal/model/crm/trade/token.go | 61 +++++++++++++++++++ internal/model/crm/trade/warehouse.go | 17 +++++- internal/model/custom/artisanspecific.go | 13 ++++ internal/model/datadictionary.go | 37 ++++++++++- internal/model/infoorganization/category.go | 12 ++++ internal/model/infoorganization/label.go | 12 ++++ .../infoorganization/pivotcategorytobject.go | 17 ++++-- .../infoorganization/pivotlabeltobject.go | 17 ++++-- .../model/infoorganization/pivottagtobject.go | 17 ++++-- internal/model/infoorganization/tag.go | 12 ++++ internal/model/media/mediaresource.go | 13 ++++ .../model/media/pivotMediaResourceToObject.go | 17 ++++-- internal/model/operationlog.go | 26 ++++---- internal/model/organization/department.go | 20 ++++-- internal/model/organization/position.go | 16 ++++- internal/model/organization/user.go | 29 ++++++--- internal/model/scene/activeqrcode.go | 20 +++--- internal/model/scrm/app/weworkappgroup.go | 20 +++--- .../model/scrm/customer/weworkcustomer.go | 29 +++++---- .../customer/weworkcustomerExternalFollow.go | 20 +++--- .../scrm/organization/weworkdepartment.go | 21 ++++--- .../model/scrm/organization/weworkuser.go | 20 +++--- internal/model/scrm/resource/department.go | 21 ++++--- internal/model/scrm/tag/weworkgroup.go | 21 ++++--- internal/model/scrm/tag/weworktag.go | 21 ++++--- internal/model/tables.go | 27 ++++++-- internal/model/tag/pivotobjecttotag.go | 17 ++++-- internal/model/tag/tag.go | 11 ++++ internal/model/wechat/miniprogram.go | 16 ++++- internal/model/wechat/offiaccount.go | 16 ++++- internal/uc/powerx/organization.go | 3 +- internal/uc/powerx/scrm/wechat/weworktag.go | 6 +- 63 files changed, 984 insertions(+), 188 deletions(-) diff --git a/cmd/ctl/database/migrate/powerx.go b/cmd/ctl/database/migrate/powerx.go index 3fa5fe2b..eaa8c94e 100644 --- a/cmd/ctl/database/migrate/powerx.go +++ b/cmd/ctl/database/migrate/powerx.go @@ -88,7 +88,7 @@ func (m *PowerMigrator) AutoMigrate() { &customerdomain.Lead{}, &customerdomain.Contact{}, customerdomain.RegisterCode{}, &customerdomain.Customer{}, &operation.Membership{}, ) - _ = m.db.AutoMigrate(&wechat.WechatOACustomer{}, &wechat.WechatMPCustomer{}, &wechat.WeWorkExternalContact{}) + _ = m.db.AutoMigrate(&wechat.WechatOACustomer{}, &wechat.WechatMPCustomer{}) _ = m.db.AutoMigrate( &product.PivotProductToProductCategory{}, ) @@ -96,8 +96,8 @@ func (m *PowerMigrator) AutoMigrate() { _ = m.db.AutoMigrate(&product.Product{}, &product.ProductCategory{}) _ = m.db.AutoMigrate(&product.ProductSpecific{}, &product.SpecificOption{}, &product.ProductStatistics{}) _ = m.db.AutoMigrate(&product.SKU{}, &product.PivotSkuToSpecificOption{}) - _ = m.db.AutoMigrate(&product.PriceBook{}, &product.PriceBookEntry{}, &product.PriceConfig{}) - _ = m.db.AutoMigrate(&market.Store{}, &product.Artisan{}, &product.PivotStoreToArtisan{}) + _ = m.db.AutoMigrate(&product.PriceBookEntry{}, &product.PriceBook{}, &product.PriceConfig{}) + _ = m.db.AutoMigrate(&product.PivotStoreToArtisan{}, &market.Store{}, &product.Artisan{}) // market _ = m.db.AutoMigrate(&market.Media{}) diff --git a/cmd/ctl/powerxctl.go b/cmd/ctl/powerxctl.go index 8904732a..bc64abbb 100644 --- a/cmd/ctl/powerxctl.go +++ b/cmd/ctl/powerxctl.go @@ -125,6 +125,7 @@ func ActionSeed(cCtx *cli.Context) error { var c config.Config conf.MustLoad(configFile, &c) c.EtcDir = filepath.Dir(configFile) + model.PowerXSchema = c.PowerXDatabase.Schema // seed tables s, _ := seed.NewPowerSeeder(&c) diff --git a/internal/model/crm/market/media.go b/internal/model/crm/market/media.go index 40621f6a..ffcec6e2 100644 --- a/internal/model/crm/market/media.go +++ b/internal/model/crm/market/media.go @@ -24,6 +24,18 @@ type Media struct { const MediaUniqueId = powermodel.UniqueId +func (mdl *Media) TableName() string { + return model.PowerXSchema + "." + model.TableNameMedia +} + +func (mdl *Media) GetTableName(needFull bool) string { + tableName := model.TableNameMedia + if needFull { + tableName = mdl.TableName() + } + return tableName +} + const TypeMediaType = "_media_type" const ( diff --git a/internal/model/crm/market/mgm.go b/internal/model/crm/market/mgm.go index 6832be48..d2b3258c 100644 --- a/internal/model/crm/market/mgm.go +++ b/internal/model/crm/market/mgm.go @@ -1,6 +1,7 @@ package market import ( + "PowerX/internal/model" "PowerX/internal/model/powermodel" ) @@ -16,6 +17,18 @@ type MGMRule struct { const MGMRuleUniqueId = powermodel.UniqueId +func (mdl *MGMRule) TableName() string { + return model.PowerXSchema + "." + model.TableNameMGMRule +} + +func (mdl *MGMRule) GetTableName(needFull bool) string { + tableName := model.TableNameMGMRule + if needFull { + tableName = mdl.TableName() + } + return tableName +} + const ( TypeMGMScene = "_mgm_scene" @@ -43,6 +56,18 @@ type CustomerChannel struct { Code string `gorm:"comment:渠道码" json:"code"` } +func (mdl *CustomerChannel) TableName() string { + return model.PowerXSchema + "." + model.TableNameCustomerChannel +} + +func (mdl *CustomerChannel) GetTableName(needFull bool) string { + tableName := model.TableNameCustomerChannel + if needFull { + tableName = mdl.TableName() + } + return tableName +} + // InviteRecord 表示会员邀请记录 type InviteRecord struct { powermodel.PowerModel @@ -53,6 +78,18 @@ type InviteRecord struct { MgmSceneId int `gorm:"comment:MGM场景ID" json:"mgmSceneId"` } +func (mdl *InviteRecord) TableName() string { + return model.PowerXSchema + "." + model.TableNameInviteRecord +} + +func (mdl *InviteRecord) GetTableName(needFull bool) string { + tableName := model.TableNameInviteRecord + if needFull { + tableName = mdl.TableName() + } + return tableName +} + // CommissionRecord 表示分佣记录 type CommissionRecord struct { powermodel.PowerModel @@ -64,6 +101,18 @@ type CommissionRecord struct { OperationId int64 `gorm:"comment:操作对象ID" json:"operationId"` } +func (mdl *CommissionRecord) TableName() string { + return model.PowerXSchema + "." + model.TableNameCommissionRecord +} + +func (mdl *CommissionRecord) GetTableName(needFull bool) string { + tableName := model.TableNameCommissionRecord + if needFull { + tableName = mdl.TableName() + } + return tableName +} + // RewardRecord 表示奖励记录 type RewardRecord struct { powermodel.PowerModel @@ -73,3 +122,15 @@ type RewardRecord struct { OperationType string `gorm:"comment:操作对象类型" json:"operationType"` OperationId int64 `gorm:"comment:操作对象ID" json:"operationId"` } + +func (mdl *RewardRecord) TableName() string { + return model.PowerXSchema + "." + model.TableNameRewardRecord +} + +func (mdl *RewardRecord) GetTableName(needFull bool) string { + tableName := model.TableNameRewardRecord + if needFull { + tableName = mdl.TableName() + } + return tableName +} diff --git a/internal/model/crm/market/promotion.go b/internal/model/crm/market/promotion.go index 1923024b..b72d5dbc 100644 --- a/internal/model/crm/market/promotion.go +++ b/internal/model/crm/market/promotion.go @@ -1,6 +1,9 @@ package market -import "PowerX/internal/model/powermodel" +import ( + "PowerX/internal/model" + "PowerX/internal/model/powermodel" +) type PromotionRule struct { powermodel.PowerModel @@ -8,3 +11,15 @@ type PromotionRule struct { MinPurchase float64 `gorm:"comment:起订购买量" json:"minPurchase"` BonusAmount float64 `gorm:"comment:额外赠送" json:"bonusAmount"` } + +func (mdl *PromotionRule) TableName() string { + return model.PowerXSchema + "." + model.TableNamePromotionRule +} + +func (mdl *PromotionRule) GetTableName(needFull bool) string { + tableName := model.TableNamePromotionRule + if needFull { + tableName = mdl.TableName() + } + return tableName +} diff --git a/internal/model/crm/market/store.go b/internal/model/crm/market/store.go index 931814fa..59e1e239 100644 --- a/internal/model/crm/market/store.go +++ b/internal/model/crm/market/store.go @@ -12,7 +12,7 @@ import ( type Store struct { powermodel.PowerModel - Artisans []*product.Artisan `gorm:"many2many:public.pivot_store_to_artisan;foreignKey:Id;joinForeignKey:StoreId;References:Id;JoinReferences:ArtisanId" json:"priceBooks"` + Artisans []*product.Artisan `gorm:"many2many:pivot_store_to_artisan;foreignKey:Id;joinForeignKey:StoreId;References:Id;JoinReferences:ArtisanId" json:"priceBooks"` PivotDetailImages []*media.PivotMediaResourceToObject `gorm:"polymorphic:Object;polymorphicValue:stores" json:"pivotDetailImages"` CoverImage *media.MediaResource `gorm:"foreignKey:CoverImageId;references:Id" json:"coverImage"` @@ -31,6 +31,18 @@ type Store struct { const StoreUniqueId = powermodel.UniqueId +func (mdl *Store) TableName() string { + return model.PowerXSchema + "." + model.TableNameStore +} + +func (mdl *Store) GetTableName(needFull bool) string { + tableName := model.TableNameStore + if needFull { + tableName = mdl.TableName() + } + return tableName +} + func (mdl *Store) LoadArtisans(db *gorm.DB, conditions *map[string]interface{}, withClauseAssociations bool) error { mdl.Artisans = []*product.Artisan{} diff --git a/internal/model/crm/operation/membership.go b/internal/model/crm/operation/membership.go index 1ace41cb..26a2830d 100644 --- a/internal/model/crm/operation/membership.go +++ b/internal/model/crm/operation/membership.go @@ -1,6 +1,7 @@ package operation import ( + "PowerX/internal/model" "PowerX/internal/model/crm/customerdomain" "PowerX/internal/model/powermodel" "time" @@ -30,6 +31,18 @@ type Membership struct { const MembershipUniqueId = powermodel.UniqueId +func (mdl *Membership) TableName() string { + return model.PowerXSchema + "." + model.TableNameMembership +} + +func (mdl *Membership) GetTableName(needFull bool) string { + tableName := model.TableNameMembership + if needFull { + tableName = mdl.TableName() + } + return tableName +} + const TypeMembershipType = "_membership_type" const TypeMembershipStatus = "_membership_status" diff --git a/internal/model/crm/operation/ticket.go b/internal/model/crm/operation/ticket.go index 1584d64e..721d7781 100644 --- a/internal/model/crm/operation/ticket.go +++ b/internal/model/crm/operation/ticket.go @@ -17,13 +17,13 @@ type TicketRecord struct { } func (mdl *TicketRecord) TableName() string { - return model.TableNameTicketRecord + return model.PowerXSchema + "." + model.TableNameTicketRecord } func (mdl *TicketRecord) GetTableName(needFull bool) string { tableName := model.TableNameTicketRecord if needFull { - tableName = "public." + tableName + tableName = mdl.TableName() } return tableName } diff --git a/internal/model/crm/product/artisan.go b/internal/model/crm/product/artisan.go index 74eef572..5f6ee67d 100644 --- a/internal/model/crm/product/artisan.go +++ b/internal/model/crm/product/artisan.go @@ -36,7 +36,17 @@ type Artisan struct { const ArtisanUniqueId = powermodel.UniqueId -// artisan level dd type +func (mdl *Artisan) TableName() string { + return model.PowerXSchema + "." + model.TableNameArtisan +} + +func (mdl *Artisan) GetTableName(needFull bool) string { + tableName := model.TableNameArtisan + if needFull { + tableName = mdl.TableName() + } + return tableName +} // artisan level dd type const ArtisanLevelType = "_artisan_level" // artisan level dd items diff --git a/internal/model/crm/product/pivotproducttoproductcategory.go b/internal/model/crm/product/pivotproducttoproductcategory.go index 7c42f2f2..40f822ba 100644 --- a/internal/model/crm/product/pivotproducttoproductcategory.go +++ b/internal/model/crm/product/pivotproducttoproductcategory.go @@ -5,11 +5,6 @@ import ( "PowerX/internal/model/powermodel" ) -// Table Name -func (mdl *PivotProductToProductCategory) TableName() string { - return model.TableNamePivotProductToProductCategory -} - // 数据表结构 type PivotProductToProductCategory struct { powermodel.PowerPivot @@ -18,6 +13,18 @@ type PivotProductToProductCategory struct { ProductCategoryId int64 `gorm:"column:product_category_id; not null;index:idx_product_category_id" json:"productCategoryId"` } +func (mdl *PivotProductToProductCategory) TableName() string { + return model.PowerXSchema + "." + model.TableNamePivotProductToProductCategory +} + +func (mdl *PivotProductToProductCategory) GetTableName(needFull bool) string { + tableName := model.TableNamePivotProductToProductCategory + if needFull { + tableName = mdl.TableName() + } + return tableName +} + const PivotProductToCategoryForeignKey = "product_id" const PivotProductToCategoryJoinKey = "product_category_id" diff --git a/internal/model/crm/product/pivotskutospecificoption.go b/internal/model/crm/product/pivotskutospecificoption.go index d9c3eaac..f308f77c 100644 --- a/internal/model/crm/product/pivotskutospecificoption.go +++ b/internal/model/crm/product/pivotskutospecificoption.go @@ -8,11 +8,6 @@ import ( "github.com/ArtisanCloud/PowerLibs/v3/object" ) -// Table Name -func (mdl *PivotSkuToSpecificOption) TableName() string { - return model.TableNamePivotSkuToSpecificOption -} - // 数据表结构 type PivotSkuToSpecificOption struct { powermodel.PowerPivot @@ -27,6 +22,18 @@ type PivotSkuToSpecificOption struct { const PivotPivotSkuToSpecificOptionsUniqueId = "index_unique_id" +func (mdl *PivotSkuToSpecificOption) TableName() string { + return model.PowerXSchema + "." + model.TableNamePivotSkuToSpecificOption +} + +func (mdl *PivotSkuToSpecificOption) GetTableName(needFull bool) string { + tableName := model.TableNamePivotSkuToSpecificOption + if needFull { + tableName = mdl.TableName() + } + return tableName +} + func (mdl *PivotSkuToSpecificOption) GetPivotComposedUniqueID() object.NullString { if mdl.ProductId > 0 && mdl.SkuId > 0 && mdl.SpecificId > 0 && mdl.SpecificOptionId > 0 { strUniqueID := fmt.Sprintf("%d-%d-%d-%d-%d", mdl.ProductId, mdl.SkuId, mdl.SpecificId, mdl.SpecificOptionId, mdl.DeletedAt.Time.Unix()) diff --git a/internal/model/crm/product/pivotstoretoartisan.go b/internal/model/crm/product/pivotstoretoartisan.go index e0e4372f..8cb4b054 100644 --- a/internal/model/crm/product/pivotstoretoartisan.go +++ b/internal/model/crm/product/pivotstoretoartisan.go @@ -5,11 +5,6 @@ import ( "PowerX/internal/model/powermodel" ) -// Table Name -func (mdl *PivotStoreToArtisan) TableName() string { - return model.TableNamePivotStoreToArtisan -} - // 数据表结构 type PivotStoreToArtisan struct { powermodel.PowerPivot @@ -18,6 +13,18 @@ type PivotStoreToArtisan struct { ArtisanId int64 `gorm:"column:artisan_id; not null;index:idx_artisan_id" json:"artisanId"` } +func (mdl *PivotStoreToArtisan) TableName() string { + return model.PowerXSchema + "." + model.TableNamePivotStoreToArtisan +} + +func (mdl *PivotStoreToArtisan) GetTableName(needFull bool) string { + tableName := model.TableNamePivotStoreToArtisan + if needFull { + tableName = mdl.TableName() + } + return tableName +} + const PivotStoreToArtisanForeignKey = "store_id" const PivotStoreToArtisanJoinKey = "artisan_id" diff --git a/internal/model/crm/product/pricebook.go b/internal/model/crm/product/pricebook.go index 76bc1245..ef0fe5c6 100644 --- a/internal/model/crm/product/pricebook.go +++ b/internal/model/crm/product/pricebook.go @@ -1,6 +1,7 @@ package product import ( + "PowerX/internal/model" "PowerX/internal/model/powermodel" ) @@ -17,3 +18,15 @@ type PriceBook struct { } const PriceBookUniqueId = powermodel.UniqueId + +func (mdl *PriceBook) TableName() string { + return model.PowerXSchema + "." + model.TableNamePriceBook +} + +func (mdl *PriceBook) GetTableName(needFull bool) string { + tableName := model.TableNamePriceBook + if needFull { + tableName = mdl.TableName() + } + return tableName +} diff --git a/internal/model/crm/product/pricebookentry.go b/internal/model/crm/product/pricebookentry.go index 566b6e52..8dcb6a0b 100644 --- a/internal/model/crm/product/pricebookentry.go +++ b/internal/model/crm/product/pricebookentry.go @@ -1,6 +1,7 @@ package product import ( + "PowerX/internal/model" "PowerX/internal/model/powermodel" "PowerX/pkg/securityx" "fmt" @@ -29,6 +30,18 @@ type PriceBookEntry struct { const PriceBookEntryUniqueId = "index_unique_id" +func (mdl *PriceBookEntry) TableName() string { + return model.PowerXSchema + "." + model.TableNamePriceBookEntry +} + +func (mdl *PriceBookEntry) GetTableName(needFull bool) string { + tableName := model.TableNamePriceBookEntry + if needFull { + tableName = mdl.TableName() + } + return tableName +} + func (mdl *PriceBookEntry) GetComposedUniqueID() object.NullString { if mdl.PriceBookId > 0 && mdl.ProductId > 0 { strUniqueID := fmt.Sprintf("%d-%d-%d-%d", mdl.PriceBookId, mdl.ProductId, mdl.SkuId, mdl.DeletedAt.Time.Unix()) diff --git a/internal/model/crm/product/priceconfig.go b/internal/model/crm/product/priceconfig.go index 4aaed241..d06c8ab0 100644 --- a/internal/model/crm/product/priceconfig.go +++ b/internal/model/crm/product/priceconfig.go @@ -1,6 +1,7 @@ package product import ( + "PowerX/internal/model" "time" ) @@ -14,6 +15,18 @@ type PriceConfig struct { EndDate time.Time `gorm:"column:end_date; comment:活动场景结束时间" json:"endDate"` } +func (mdl *PriceConfig) TableName() string { + return model.PowerXSchema + "." + model.TableNamePriceConfig +} + +func (mdl *PriceConfig) GetTableName(needFull bool) string { + tableName := model.TableNamePriceConfig + if needFull { + tableName = mdl.TableName() + } + return tableName +} + const TypeListPrice = "List_Price" const TypeMember = "Member" const TypeMemberEarlyBird = "Member_Early_Bird" diff --git a/internal/model/crm/product/product.go b/internal/model/crm/product/product.go index d5921421..6967427a 100644 --- a/internal/model/crm/product/product.go +++ b/internal/model/crm/product/product.go @@ -22,17 +22,17 @@ type ProductAttribute struct { type Product struct { SKUs []*SKU `gorm:"foreignKey:ProductId;references:Id" json:"skus"` ProductSpecifics []*ProductSpecific `gorm:"foreignKey:ProductId;references:Id" json:"productSpecifics"` - ProductCategories []*ProductCategory `gorm:"many2many:public.pivot_product_to_product_category;foreignKey:Id;joinForeignKey:ProductId;References:Id;JoinReferences:ProductCategoryId" json:"productCategories"` + ProductCategories []*ProductCategory `gorm:"many2many:pivot_product_to_product_category;foreignKey:Id;joinForeignKey:ProductId;References:Id;JoinReferences:ProductCategoryId" json:"productCategories"` PivotCoverImages []*media.PivotMediaResourceToObject `gorm:"polymorphic:Object;polymorphicValue:products" json:"pivotCoverImages"` PivotDetailImages []*media.PivotMediaResourceToObject `gorm:"polymorphic:Object;polymorphicValue:products" json:"pivotDetailImages"` - PriceBooks []*PriceBook `gorm:"many2many:public.price_book_entries;foreignKey:Id;joinForeignKey:Id;References:Id;JoinReferences:PriceBookId" json:"priceBooks"` + PriceBooks []*PriceBook `gorm:"many2many:price_book_entries;foreignKey:Id;joinForeignKey:Id;References:Id;JoinReferences:PriceBookId" json:"priceBooks"` PriceBookEntries []*PriceBookEntry `gorm:"foreignKey:ProductId;references:Id" json:"priceBookEntries"` PivotSalesChannels []*model.PivotDataDictionaryToObject `gorm:"polymorphic:Object;polymorphicValue:products" json:"pivotSalesChannels"` PivotPromoteChannels []*model.PivotDataDictionaryToObject `gorm:"polymorphic:Object;polymorphicValue:products" json:"pivotPromoteChannels"` ProductCategoryIds []int64 `gorm:"-"` SalesChannelsItemIds []int64 `gorm:"-"` PromoteChannelsItemIds []int64 `gorm:"-"` - //Coupons []*Coupon `gorm:"many2many:public.r_product_to_coupon;foreignKey:Id;joinForeignKey:ProductId;References:Id;JoinReferences:CouponId" json:"coupons"` + //Coupons []*Coupon `gorm:"many2many:r_product_to_coupon;foreignKey:Id;joinForeignKey:ProductId;References:Id;JoinReferences:CouponId" json:"coupons"` powermodel.PowerModel @@ -56,6 +56,18 @@ type Product struct { const ProductUniqueId = powermodel.UniqueId +func (mdl *Product) TableName() string { + return model.PowerXSchema + "." + model.TableNameProduct +} + +func (mdl *Product) GetTableName(needFull bool) string { + tableName := model.TableNameProduct + if needFull { + tableName = mdl.TableName() + } + return tableName +} + // Data Dictionary const TypeProductType = "_product_type" const TypeProductPlan = "_product_plan" @@ -67,14 +79,6 @@ const ProductTypeService = "_service" const ProductPlanOnce = "_once" const ProductPlanPeriod = "_period" -func (mdl *Product) GetTableName(needFull bool) string { - tableName := model.TableNameProduct - if needFull { - tableName = "public." + tableName - } - return tableName -} - func (mdl *Product) GetForeignReferValue() int64 { return mdl.Id } diff --git a/internal/model/crm/product/productcategory.go b/internal/model/crm/product/productcategory.go index 370a04b3..71f09623 100644 --- a/internal/model/crm/product/productcategory.go +++ b/internal/model/crm/product/productcategory.go @@ -26,6 +26,18 @@ type ProductCategory struct { const ProductCategoryUniqueId = powermodel.UniqueId +func (mdl *ProductCategory) TableName() string { + return model.PowerXSchema + "." + model.TableNameProductCategory +} + +func (mdl *ProductCategory) GetTableName(needFull bool) string { + tableName := model.TableNameProductCategory + if needFull { + tableName = mdl.TableName() + } + return tableName +} + func (mdl *ProductCategory) GetCategoryIds(categories []*ProductCategory) []int64 { uniqueIds := make(map[int64]bool) arrayIds := []int64{} diff --git a/internal/model/crm/product/productspecific.go b/internal/model/crm/product/productspecific.go index 4fc2499c..f0d4a0e5 100644 --- a/internal/model/crm/product/productspecific.go +++ b/internal/model/crm/product/productspecific.go @@ -1,6 +1,9 @@ package product -import "PowerX/internal/model/powermodel" +import ( + "PowerX/internal/model" + "PowerX/internal/model/powermodel" +) type ProductSpecific struct { Options []*SpecificOption `gorm:"foreignKey:ProductSpecificId" json:"options"` @@ -11,6 +14,18 @@ type ProductSpecific struct { Name string `gorm:"comment:规格名称;" json:"name"` } +func (mdl *ProductSpecific) TableName() string { + return model.PowerXSchema + "." + model.TableNameProductSpecific +} + +func (mdl *ProductSpecific) GetTableName(needFull bool) string { + tableName := model.TableNameProductSpecific + if needFull { + tableName = mdl.TableName() + } + return tableName +} + type SpecificOption struct { powermodel.PowerModel @@ -21,3 +36,15 @@ type SpecificOption struct { const ProductSpecificUniqueId = powermodel.UniqueId const SpecificOptionUniqueId = powermodel.UniqueId + +func (mdl *SpecificOption) TableName() string { + return model.PowerXSchema + "." + model.TableNameSpecificOption +} + +func (mdl *SpecificOption) GetTableName(needFull bool) string { + tableName := model.TableNameSpecificOption + if needFull { + tableName = mdl.TableName() + } + return tableName +} diff --git a/internal/model/crm/product/productstatistics.go b/internal/model/crm/product/productstatistics.go index 5e618e93..8f3fcd24 100644 --- a/internal/model/crm/product/productstatistics.go +++ b/internal/model/crm/product/productstatistics.go @@ -1,6 +1,9 @@ package product -import "PowerX/internal/model/powermodel" +import ( + "PowerX/internal/model" + "PowerX/internal/model/powermodel" +) type ProductStatistics struct { powermodel.PowerModel @@ -15,3 +18,15 @@ type ProductStatistics struct { } const ProductStatisticsUniqueId = "product_id" + +func (mdl *ProductStatistics) TableName() string { + return model.PowerXSchema + "." + model.TableNameProductStatistics +} + +func (mdl *ProductStatistics) GetTableName(needFull bool) string { + tableName := model.TableNameProductStatistics + if needFull { + tableName = mdl.TableName() + } + return tableName +} diff --git a/internal/model/crm/product/sku.go b/internal/model/crm/product/sku.go index eb95c12b..85eca595 100644 --- a/internal/model/crm/product/sku.go +++ b/internal/model/crm/product/sku.go @@ -1,6 +1,7 @@ package product import ( + "PowerX/internal/model" "PowerX/internal/model/powermodel" "PowerX/pkg/securityx" "fmt" @@ -24,6 +25,18 @@ type SKU struct { const SkuUniqueId = "index_unique_id" +func (mdl *SKU) TableName() string { + return model.PowerXSchema + "." + model.TableNameSKU +} + +func (mdl *SKU) GetTableName(needFull bool) string { + tableName := model.TableNameSKU + if needFull { + tableName = mdl.TableName() + } + return tableName +} + func (mdl *SKU) GetComposedUniqueID() object.NullString { if len(mdl.OptionIds) > 0 && mdl.ProductId > 0 { strUniqueID := fmt.Sprintf("%d-%s-%d", mdl.ProductId, mdl.OptionIds.String(), mdl.DeletedAt.Time.Unix()) diff --git a/internal/model/crm/trade/billingaddress.go b/internal/model/crm/trade/billingaddress.go index 29a72fa9..4fcd0866 100644 --- a/internal/model/crm/trade/billingaddress.go +++ b/internal/model/crm/trade/billingaddress.go @@ -1,6 +1,9 @@ package trade -import "PowerX/internal/model/powermodel" +import ( + "PowerX/internal/model" + "PowerX/internal/model/powermodel" +) // 订单开票地址 type BillingAddress struct { @@ -19,3 +22,15 @@ type BillingAddress struct { Country string `gorm:"comment:国家" json:"country"` PhoneNumber string `gorm:"comment:联系电话" json:"phoneNumber"` } + +func (mdl *BillingAddress) TableName() string { + return model.PowerXSchema + "." + model.TableNameBillingAddress +} + +func (mdl *BillingAddress) GetTableName(needFull bool) string { + tableName := model.TableNameBillingAddress + if needFull { + tableName = mdl.TableName() + } + return tableName +} diff --git a/internal/model/crm/trade/cart.go b/internal/model/crm/trade/cart.go index d0eca245..d505ef5f 100644 --- a/internal/model/crm/trade/cart.go +++ b/internal/model/crm/trade/cart.go @@ -1,6 +1,7 @@ package trade import ( + "PowerX/internal/model" "PowerX/internal/model/crm/product" "PowerX/internal/model/powermodel" ) @@ -15,6 +16,18 @@ type Cart struct { const CartUniqueId = powermodel.UniqueId +func (mdl *Cart) TableName() string { + return model.PowerXSchema + "." + model.TableNameCart +} + +func (mdl *Cart) GetTableName(needFull bool) string { + tableName := model.TableNameCart + if needFull { + tableName = mdl.TableName() + } + return tableName +} + type CartItem struct { *powermodel.PowerModel @@ -34,6 +47,18 @@ type CartItem struct { ImageURL string `gorm:"comment:商品图片URL" json:"imageUrl"` } +func (mdl *CartItem) TableName() string { + return model.PowerXSchema + "." + model.TableNameCartItem +} + +func (mdl *CartItem) GetTableName(needFull bool) string { + tableName := model.TableNameCartItem + if needFull { + tableName = mdl.TableName() + } + return tableName +} + type CartStatus string const ( diff --git a/internal/model/crm/trade/deliveryaddress.go b/internal/model/crm/trade/deliveryaddress.go index 4e6bbd8a..a5b92508 100644 --- a/internal/model/crm/trade/deliveryaddress.go +++ b/internal/model/crm/trade/deliveryaddress.go @@ -1,6 +1,9 @@ package trade -import "PowerX/internal/model/powermodel" +import ( + "PowerX/internal/model" + "PowerX/internal/model/powermodel" +) // 订单发货地址 type DeliveryAddress struct { @@ -19,3 +22,15 @@ type DeliveryAddress struct { Country string `gorm:"comment:国家" json:"country"` PhoneNumber string `gorm:"comment:联系电话" json:"phoneNumber"` } + +func (mdl *DeliveryAddress) TableName() string { + return model.PowerXSchema + "." + model.TableNameDeliveryAddress +} + +func (mdl *DeliveryAddress) GetTableName(needFull bool) string { + tableName := model.TableNameDeliveryAddress + if needFull { + tableName = mdl.TableName() + } + return tableName +} diff --git a/internal/model/crm/trade/inventory.go b/internal/model/crm/trade/inventory.go index ee62460d..c9106138 100644 --- a/internal/model/crm/trade/inventory.go +++ b/internal/model/crm/trade/inventory.go @@ -1,6 +1,9 @@ package trade -import "PowerX/internal/model/powermodel" +import ( + "PowerX/internal/model" + "PowerX/internal/model/powermodel" +) // 仓库 type Inventory struct { @@ -11,3 +14,15 @@ type Inventory struct { SkuID int64 `gorm:"comment:SkuId" json:"skuID"` Quantity int `gorm:"comment:库存数量" json:"quantity"` } + +func (mdl *Inventory) TableName() string { + return model.PowerXSchema + "." + model.TableNameInventory +} + +func (mdl *Inventory) GetTableName(needFull bool) string { + tableName := model.TableNameInventory + if needFull { + tableName = mdl.TableName() + } + return tableName +} diff --git a/internal/model/crm/trade/logistics.go b/internal/model/crm/trade/logistics.go index 0430f1ad..38c84449 100644 --- a/internal/model/crm/trade/logistics.go +++ b/internal/model/crm/trade/logistics.go @@ -1,6 +1,7 @@ package trade import ( + "PowerX/internal/model" "PowerX/internal/model/powermodel" "time" ) @@ -16,6 +17,18 @@ type Logistics struct { ActualDeliveryDate time.Time `gorm:"comment:实际送达时间" json:"actualDeliveryDate"` } +func (mdl *Logistics) TableName() string { + return model.PowerXSchema + "." + model.TableNameLogistics +} + +func (mdl *Logistics) GetTableName(needFull bool) string { + tableName := model.TableNameLogistics + if needFull { + tableName = mdl.TableName() + } + return tableName +} + type LogisticsStatus string const ( diff --git a/internal/model/crm/trade/order.go b/internal/model/crm/trade/order.go index c06d6d72..c81ead36 100644 --- a/internal/model/crm/trade/order.go +++ b/internal/model/crm/trade/order.go @@ -1,6 +1,7 @@ package trade import ( + "PowerX/internal/model" "PowerX/internal/model/crm/customerdomain" "PowerX/internal/model/crm/product" "PowerX/internal/model/media" @@ -45,6 +46,19 @@ const TypeOrderType = "_order_type" const TypeOrderStatus = "_order_status" const OrderUniqueId = powermodel.UniqueId + +func (mdl *Order) TableName() string { + return model.PowerXSchema + "." + model.TableNameOrder +} + +func (mdl *Order) GetTableName(needFull bool) string { + tableName := model.TableNameOrder + if needFull { + tableName = mdl.TableName() + } + return tableName +} + const ( OrderStatusPending = "_pending" // 待处理 OrderStatusToBePaid = "_to_be_paid" // 待付款 @@ -100,6 +114,18 @@ type OrderItem struct { Discount float64 `gorm:"type:decimal(10,2); comment:折扣" json:"discount"` } +func (mdl *OrderItem) TableName() string { + return model.PowerXSchema + "." + model.TableNameOrderItem +} + +func (mdl *OrderItem) GetTableName(needFull bool) string { + tableName := model.TableNameOrderItem + if needFull { + tableName = mdl.TableName() + } + return tableName +} + type OrderStatusTransition struct { *powermodel.PowerModel @@ -112,6 +138,18 @@ type OrderStatusTransition struct { TransitionTime time.Time `gorm:"comment:状态转换时间" json:"transitionTime"` } +func (mdl *OrderStatusTransition) TableName() string { + return model.PowerXSchema + "." + model.TableNameOrderStatusTransition +} + +func (mdl *OrderStatusTransition) GetTableName(needFull bool) string { + tableName := model.TableNameOrderStatusTransition + if needFull { + tableName = mdl.TableName() + } + return tableName +} + func GenerateOrderNumber() string { //return "SO" + carbon.Now().Format("YmdHis") + object.QuickRandom(4) diff --git a/internal/model/crm/trade/payment.go b/internal/model/crm/trade/payment.go index ee525989..3a8ce916 100644 --- a/internal/model/crm/trade/payment.go +++ b/internal/model/crm/trade/payment.go @@ -1,6 +1,7 @@ package trade import ( + "PowerX/internal/model" "PowerX/internal/model/powermodel" "github.com/ArtisanCloud/PowerLibs/v3/object" "github.com/golang-module/carbon/v2" @@ -23,6 +24,18 @@ type Payment struct { Status int `gorm:"comment:支付单状态" json:"status"` } +func (mdl *Payment) TableName() string { + return model.PowerXSchema + "." + model.TableNamePayment +} + +func (mdl *Payment) GetTableName(needFull bool) string { + tableName := model.TableNamePayment + if needFull { + tableName = mdl.TableName() + } + return tableName +} + const TypePaymentType = "_payment_type" const TypePaymentStatus = "_payment_status" @@ -62,6 +75,18 @@ type PaymentItem struct { const PaymentUniqueId = powermodel.UniqueId +func (mdl *PaymentItem) TableName() string { + return model.PowerXSchema + "." + model.TableNamePaymentItem +} + +func (mdl *PaymentItem) GetTableName(needFull bool) string { + tableName := model.TableNamePaymentItem + if needFull { + tableName = mdl.TableName() + } + return tableName +} + func GeneratePaymentNumber() string { return "PO" + carbon.Now().Format("YmdHis") + object.QuickRandom(6) } diff --git a/internal/model/crm/trade/pivotordertonventorylog.go b/internal/model/crm/trade/pivotordertonventorylog.go index d3fed746..51e81eb4 100644 --- a/internal/model/crm/trade/pivotordertonventorylog.go +++ b/internal/model/crm/trade/pivotordertonventorylog.go @@ -1,6 +1,7 @@ package trade import ( + "PowerX/internal/model" "PowerX/internal/model/powermodel" ) @@ -10,3 +11,15 @@ type PivotProductToPromotion struct { PromotionRuleId int64 `gorm:"comment:促销规则d; not null;index:idx_promotion_rule_id" json:"promotionRuleId"` ProductId int64 `gorm:"comment:商品Id; not null;index:idx_product_id" json:"productId"` } + +func (mdl *PivotProductToPromotion) TableName() string { + return model.PowerXSchema + "." + model.TableNamePivotProductToPromotion +} + +func (mdl *PivotProductToPromotion) GetTableName(needFull bool) string { + tableName := model.TableNamePivotProductToPromotion + if needFull { + tableName = mdl.TableName() + } + return tableName +} diff --git a/internal/model/crm/trade/pivotproducttopromotion.go b/internal/model/crm/trade/pivotproducttopromotion.go index f3e15917..b7261c0e 100644 --- a/internal/model/crm/trade/pivotproducttopromotion.go +++ b/internal/model/crm/trade/pivotproducttopromotion.go @@ -1,6 +1,7 @@ package trade import ( + "PowerX/internal/model" "PowerX/internal/model/powermodel" "time" ) @@ -18,6 +19,18 @@ type PivotOrderToInventoryLog struct { StockQuantityAfter int `gorm:"comment:回滚后的库存数量" json:"stockQuantityAfter"` } +func (mdl *PivotOrderToInventoryLog) TableName() string { + return model.PowerXSchema + "." + model.TableNamePivotOrderToInventoryLog +} + +func (mdl *PivotOrderToInventoryLog) GetTableName(needFull bool) string { + tableName := model.TableNamePivotOrderToInventoryLog + if needFull { + tableName = mdl.TableName() + } + return tableName +} + type ActionType int const ( diff --git a/internal/model/crm/trade/refund.go b/internal/model/crm/trade/refund.go index c814b00a..5c31d7ee 100644 --- a/internal/model/crm/trade/refund.go +++ b/internal/model/crm/trade/refund.go @@ -1,6 +1,7 @@ package trade import ( + "PowerX/internal/model" "PowerX/internal/model/crm/customerdomain" "PowerX/internal/model/powermodel" "time" @@ -24,6 +25,18 @@ type RefundOrder struct { RefundDate time.Time `gorm:"comment:退款日期" json:"refundDate"` } +func (mdl *RefundOrder) TableName() string { + return model.PowerXSchema + "." + model.TableNameRefundOrder +} + +func (mdl *RefundOrder) GetTableName(needFull bool) string { + tableName := model.TableNameRefundOrder + if needFull { + tableName = mdl.TableName() + } + return tableName +} + type RefundStatus int const RefundOrderUniqueId = powermodel.UniqueId @@ -48,3 +61,15 @@ type RefundOrderItem struct { RefundAmount float64 `gorm:"type:decimal(10,2); comment:退款金额" json:"refundAmount"` RefundDate time.Time `gorm:"comment:退款日期" json:"refundDate"` } + +func (mdl *RefundOrderItem) TableName() string { + return model.PowerXSchema + "." + model.TableNameRefundOrderItem +} + +func (mdl *RefundOrderItem) GetTableName(needFull bool) string { + tableName := model.TableNameRefundOrderItem + if needFull { + tableName = mdl.TableName() + } + return tableName +} diff --git a/internal/model/crm/trade/shippingaddress.go b/internal/model/crm/trade/shippingaddress.go index f55ef41a..9da2e670 100644 --- a/internal/model/crm/trade/shippingaddress.go +++ b/internal/model/crm/trade/shippingaddress.go @@ -1,6 +1,9 @@ package trade -import "PowerX/internal/model/powermodel" +import ( + "PowerX/internal/model" + "PowerX/internal/model/powermodel" +) // 用户发货地址 type ShippingAddress struct { @@ -22,6 +25,18 @@ type ShippingAddress struct { const ShippingAddressUniqueId = powermodel.UniqueId +func (mdl *ShippingAddress) TableName() string { + return model.PowerXSchema + "." + model.TableNameShippingAddress +} + +func (mdl *ShippingAddress) GetTableName(needFull bool) string { + tableName := model.TableNameShippingAddress + if needFull { + tableName = mdl.TableName() + } + return tableName +} + func (mdl *ShippingAddress) MakeDeliveryAddress() *DeliveryAddress { return &DeliveryAddress{ CustomerId: mdl.CustomerId, diff --git a/internal/model/crm/trade/token.go b/internal/model/crm/trade/token.go index 6e1e4894..def1de6f 100644 --- a/internal/model/crm/trade/token.go +++ b/internal/model/crm/trade/token.go @@ -1,6 +1,7 @@ package trade import ( + "PowerX/internal/model" "PowerX/internal/model/crm/customerdomain" "PowerX/internal/model/powermodel" ) @@ -12,6 +13,18 @@ type TokenExchangeRatio struct { Ratio float64 `gorm:"comment:兑换比例" json:"ratio"` } +func (mdl *TokenExchangeRatio) TableName() string { + return model.PowerXSchema + "." + model.TableNameTokenExchangeRatio +} + +func (mdl *TokenExchangeRatio) GetTableName(needFull bool) string { + tableName := model.TableNameTokenExchangeRatio + if needFull { + tableName = mdl.TableName() + } + return tableName +} + type TokenBalance struct { powermodel.PowerModel @@ -25,6 +38,18 @@ type TokenBalance struct { const TokenBalanceUniqueId = powermodel.UniqueId const TokenExchangeRecordId = powermodel.UniqueId +func (mdl *TokenBalance) TableName() string { + return model.PowerXSchema + "." + model.TableNameTokenBalance +} + +func (mdl *TokenBalance) GetTableName(needFull bool) string { + tableName := model.TableNameTokenBalance + if needFull { + tableName = mdl.TableName() + } + return tableName +} + type TokenExchangeRecord struct { powermodel.PowerModel @@ -38,6 +63,18 @@ type TokenExchangeRecord struct { ExchangeRate float64 `gorm:"comment:兑换比例" json:"exchangeRate"` } +func (mdl *TokenExchangeRecord) TableName() string { + return model.PowerXSchema + "." + model.TableNameTokenExchangeRecord +} + +func (mdl *TokenExchangeRecord) GetTableName(needFull bool) string { + tableName := model.TableNameTokenExchangeRecord + if needFull { + tableName = mdl.TableName() + } + return tableName +} + // TokenCategory 代表代币的种类 const TypeTokenCategory = "_token_category" @@ -62,6 +99,18 @@ type TokenReservation struct { IsConfirmed bool `gorm:"comment:是否已确认" json:"isConfirmed"` } +func (mdl *TokenReservation) TableName() string { + return model.PowerXSchema + "." + model.TableNameTokenReservation +} + +func (mdl *TokenReservation) GetTableName(needFull bool) string { + tableName := model.TableNameTokenReservation + if needFull { + tableName = mdl.TableName() + } + return tableName +} + // 定义交易记录对象 type TokenTransaction struct { powermodel.PowerModel @@ -73,6 +122,18 @@ type TokenTransaction struct { SourceID int64 `gorm:"column:source_id; not null;index:idx_src_id;comment:对象Id" json:"sourceId"` } +func (mdl *TokenTransaction) TableName() string { + return model.PowerXSchema + "." + model.TableNameTokenTransaction +} + +func (mdl *TokenTransaction) GetTableName(needFull bool) string { + tableName := model.TableNameTokenTransaction + if needFull { + tableName = mdl.TableName() + } + return tableName +} + const TokenTransactionId = powermodel.UniqueId const TypeTokenTransactionType = "_token_transaction_type" diff --git a/internal/model/crm/trade/warehouse.go b/internal/model/crm/trade/warehouse.go index 41cd8d4b..4d9908be 100644 --- a/internal/model/crm/trade/warehouse.go +++ b/internal/model/crm/trade/warehouse.go @@ -1,6 +1,9 @@ package trade -import "PowerX/internal/model/powermodel" +import ( + "PowerX/internal/model" + "PowerX/internal/model/powermodel" +) // 仓库 type Warehouse struct { @@ -16,3 +19,15 @@ type Warehouse struct { ContactPhone string `gorm:"comment:联系电话" json:"contactPhone"` IsActive bool `gorm:"comment:是否活动" json:"isActive"` } + +func (mdl *Warehouse) TableName() string { + return model.PowerXSchema + "." + model.TableNameWarehouse +} + +func (mdl *Warehouse) GetTableName(needFull bool) string { + tableName := model.TableNameWarehouse + if needFull { + tableName = mdl.TableName() + } + return tableName +} diff --git a/internal/model/custom/artisanspecific.go b/internal/model/custom/artisanspecific.go index 8cc94a99..985ef58c 100644 --- a/internal/model/custom/artisanspecific.go +++ b/internal/model/custom/artisanspecific.go @@ -1,6 +1,7 @@ package custom import ( + "PowerX/internal/model" "PowerX/internal/model/powermodel" ) @@ -11,3 +12,15 @@ type ArtisanSpecific struct { } const ArtisanSpecificUniqueId = powermodel.UniqueId + +func (mdl *ArtisanSpecific) TableName() string { + return model.PowerXSchema + "." + model.TableNameArtisanSpecific +} + +func (mdl *ArtisanSpecific) GetTableName(needFull bool) string { + tableName := model.TableNameArtisanSpecific + if needFull { + tableName = mdl.TableName() + } + return tableName +} diff --git a/internal/model/datadictionary.go b/internal/model/datadictionary.go index 8deb7bff..90cd5690 100644 --- a/internal/model/datadictionary.go +++ b/internal/model/datadictionary.go @@ -53,6 +53,18 @@ type DataDictionaryItem struct { const DataDictionaryItemUniqueId = powermodel.UniqueId +func (mdl *DataDictionaryItem) TableName() string { + return PowerXSchema + "." + TableNameDataDictionaryItem +} + +func (mdl *DataDictionaryItem) GetTableName(needFull bool) string { + tableName := TableNameDataDictionaryItem + if needFull { + tableName = mdl.TableName() + } + return tableName +} + // 数据字典类型,聚合数据字典 type DataDictionaryType struct { powermodel.PowerModel @@ -66,9 +78,16 @@ type DataDictionaryType struct { const DataDictionaryTypeUniqueId = powermodel.UniqueId -// Table Name -func (mdl *PivotDataDictionaryToObject) TableName() string { - return TableNamePivotDataDictionaryToObject +func (mdl *DataDictionaryType) TableName() string { + return PowerXSchema + "." + TableNameDataDictionaryType +} + +func (mdl *DataDictionaryType) GetTableName(needFull bool) string { + tableName := TableNameDataDictionaryType + if needFull { + tableName = mdl.TableName() + } + return tableName } // 数据表结构 @@ -87,6 +106,18 @@ type PivotDataDictionaryToObject struct { const PivotDataDictionaryToObjectOwnerKey = "object_type" const PivotDataDictionaryToObjectForeignKey = "object_id" +func (mdl *PivotDataDictionaryToObject) TableName() string { + return PowerXSchema + "." + TableNamePivotDataDictionaryToObject +} + +func (mdl *PivotDataDictionaryToObject) GetTableName(needFull bool) string { + tableName := TableNamePivotDataDictionaryToObject + if needFull { + tableName = mdl.TableName() + } + return tableName +} + func (mdl *PivotDataDictionaryToObject) GetOwnerKey() string { // 因为是morphy类型,所以外键是Owner return PivotDataDictionaryToObjectOwnerKey diff --git a/internal/model/infoorganization/category.go b/internal/model/infoorganization/category.go index 41add634..3661b408 100644 --- a/internal/model/infoorganization/category.go +++ b/internal/model/infoorganization/category.go @@ -26,6 +26,18 @@ type Category struct { const CategoryUniqueId = powermodel.UniqueId +func (mdl *Category) TableName() string { + return model.PowerXSchema + "." + model.TableNameCategory +} + +func (mdl *Category) GetTableName(needFull bool) string { + tableName := model.TableNameCategory + if needFull { + tableName = mdl.TableName() + } + return tableName +} + func (mdl *Category) GetCategoryIds(categories []*Category) []int64 { uniqueIds := make(map[int64]bool) arrayIds := []int64{} diff --git a/internal/model/infoorganization/label.go b/internal/model/infoorganization/label.go index c0e323c2..0c72c777 100644 --- a/internal/model/infoorganization/label.go +++ b/internal/model/infoorganization/label.go @@ -26,6 +26,18 @@ type Label struct { const LabelUniqueId = powermodel.UniqueId +func (mdl *Label) TableName() string { + return model.PowerXSchema + "." + model.TableNameLabel +} + +func (mdl *Label) GetTableName(needFull bool) string { + tableName := model.TableNameLabel + if needFull { + tableName = mdl.TableName() + } + return tableName +} + func GetLabelIds(categories []*Label) []int64 { uniqueIds := make(map[int64]bool) arrayIds := []int64{} diff --git a/internal/model/infoorganization/pivotcategorytobject.go b/internal/model/infoorganization/pivotcategorytobject.go index 74e48bca..c797f244 100644 --- a/internal/model/infoorganization/pivotcategorytobject.go +++ b/internal/model/infoorganization/pivotcategorytobject.go @@ -9,11 +9,6 @@ import ( "gorm.io/gorm" ) -// Table Name -func (mdl *PivotCategoryToObject) TableName() string { - return model.TableNamePivotCategoryToObject -} - // Pivot表 type PivotCategoryToObject struct { powermodel.PowerPivot @@ -34,6 +29,18 @@ const PivotCategoryToObjectOwnerKey = "object_type" const PivotCategoryToObjectForeignKey = "object_id" const PivotCategoryToObjectJoinKey = "category_id" +func (mdl *PivotCategoryToObject) TableName() string { + return model.PowerXSchema + "." + model.TableNamePivotCategoryToObject +} + +func (mdl *PivotCategoryToObject) GetTableName(needFull bool) string { + tableName := model.TableNamePivotCategoryToObject + if needFull { + tableName = mdl.TableName() + } + return tableName +} + func (mdl *PivotCategoryToObject) GetOwnerKey() string { // 因为是morphy类型,所以外键是Owner return PivotCategoryToObjectOwnerKey diff --git a/internal/model/infoorganization/pivotlabeltobject.go b/internal/model/infoorganization/pivotlabeltobject.go index 9bbf6f79..8135b06d 100644 --- a/internal/model/infoorganization/pivotlabeltobject.go +++ b/internal/model/infoorganization/pivotlabeltobject.go @@ -9,11 +9,6 @@ import ( "gorm.io/gorm" ) -// Table Name -func (mdl *PivotLabelToObject) TableName() string { - return model.TableNamePivotLabelToObject -} - // Pivot表 type PivotLabelToObject struct { powermodel.PowerPivot @@ -32,6 +27,18 @@ const PivotLabelToObjectOwnerKey = "object_type" const PivotLabelToObjectForeignKey = "object_id" const PivotLabelToObjectJoinKey = "label_id" +func (mdl *PivotLabelToObject) TableName() string { + return model.PowerXSchema + "." + model.TableNamePivotLabelToObject +} + +func (mdl *PivotLabelToObject) GetTableName(needFull bool) string { + tableName := model.TableNamePivotLabelToObject + if needFull { + tableName = mdl.TableName() + } + return tableName +} + func (mdl *PivotLabelToObject) GetOwnerKey() string { // 因为是morphy类型,所以外键是Owner return PivotLabelToObjectOwnerKey diff --git a/internal/model/infoorganization/pivottagtobject.go b/internal/model/infoorganization/pivottagtobject.go index 872eb7ca..4ddf68e7 100644 --- a/internal/model/infoorganization/pivottagtobject.go +++ b/internal/model/infoorganization/pivottagtobject.go @@ -9,11 +9,6 @@ import ( "gorm.io/gorm" ) -// Table Name -func (mdl *PivotTagToObject) TableName() string { - return model.TableNamePivotTagToObject -} - // Pivot表 type PivotTagToObject struct { powermodel.PowerPivot @@ -32,6 +27,18 @@ const PivotTagToObjectOwnerKey = "object_type" const PivotTagToObjectForeignKey = "object_id" const PivotTagToObjectJoinKey = "tag_id" +func (mdl *PivotTagToObject) TableName() string { + return model.PowerXSchema + "." + model.TableNamePivotTagToObject +} + +func (mdl *PivotTagToObject) GetTableName(needFull bool) string { + tableName := model.TableNamePivotTagToObject + if needFull { + tableName = mdl.TableName() + } + return tableName +} + func (mdl *PivotTagToObject) GetOwnerKey() string { // 因为是morphy类型,所以外键是Owner return PivotTagToObjectOwnerKey diff --git a/internal/model/infoorganization/tag.go b/internal/model/infoorganization/tag.go index 07f6b927..7a55fdc6 100644 --- a/internal/model/infoorganization/tag.go +++ b/internal/model/infoorganization/tag.go @@ -26,6 +26,18 @@ type Tag struct { const TagUniqueId = powermodel.UniqueId +func (mdl *Tag) TableName() string { + return model.PowerXSchema + "." + model.TableNameTag +} + +func (mdl *Tag) GetTableName(needFull bool) string { + tableName := model.TableNameTag + if needFull { + tableName = mdl.TableName() + } + return tableName +} + func GetTagIds(categories []*Tag) []int64 { uniqueIds := make(map[int64]bool) arrayIds := []int64{} diff --git a/internal/model/media/mediaresource.go b/internal/model/media/mediaresource.go index bb4ab038..146422a5 100644 --- a/internal/model/media/mediaresource.go +++ b/internal/model/media/mediaresource.go @@ -1,6 +1,7 @@ package media import ( + "PowerX/internal/model" "PowerX/internal/model/powermodel" "PowerX/internal/types" ) @@ -23,6 +24,18 @@ type MediaResource struct { type MediaSet struct { } +func (mdl *MediaResource) TableName() string { + return model.PowerXSchema + "." + model.TableNameMediaResource +} + +func (mdl *MediaResource) GetTableName(needFull bool) string { + tableName := model.TableNameMediaResource + if needFull { + tableName = mdl.TableName() + } + return tableName +} + const MediaUsageCover = "_cover" const MediaUsageDetail = "_detail" diff --git a/internal/model/media/pivotMediaResourceToObject.go b/internal/model/media/pivotMediaResourceToObject.go index 7ddb6567..94f9c522 100644 --- a/internal/model/media/pivotMediaResourceToObject.go +++ b/internal/model/media/pivotMediaResourceToObject.go @@ -9,11 +9,6 @@ import ( "gorm.io/gorm" ) -// Table Name -func (mdl *PivotMediaResourceToObject) TableName() string { - return model.TableNamePivotMediaResourceToObject -} - // Pivot表 type PivotMediaResourceToObject struct { powermodel.PowerPivot @@ -36,6 +31,18 @@ const PivotMediaResourceToObjectOwnerKey = "object_type" const PivotMediaResourceToObjectForeignKey = "object_id" const PivotMediaResourceToObjectJoinKey = "media_id" +func (mdl *PivotMediaResourceToObject) TableName() string { + return model.PowerXSchema + "." + model.TableNamePivotMediaResourceToObject +} + +func (mdl *PivotMediaResourceToObject) GetTableName(needFull bool) string { + tableName := model.TableNamePivotMediaResourceToObject + if needFull { + tableName = mdl.TableName() + } + return tableName +} + func (mdl *PivotMediaResourceToObject) GetOwnerKey() string { // 因为是morphy类型,所以外键是Owner return PivotMediaResourceToObjectOwnerKey diff --git a/internal/model/operationlog.go b/internal/model/operationlog.go index f2e4be9e..48a3e8ec 100644 --- a/internal/model/operationlog.go +++ b/internal/model/operationlog.go @@ -14,11 +14,6 @@ const OperationResultSuccess = 1 const OperationResultFailed = 2 const OperationResultCancel = 3 -// TableName overrides the table name used by price_book to `profiles` -func (mdl *PowerOperationLog) TableName() string { - return mdl.GetTableName(true) -} - // PowerOperationLog 数据表结构 type PowerOperationLog struct { *powermodel.PowerModel @@ -37,6 +32,18 @@ type PowerOperationLog struct { const OperationLogUniqueId = powermodel.UniqueId +func (mdl *PowerOperationLog) TableName() string { + return PowerXSchema + "." + TableNamePowerOperationLog +} + +func (mdl *PowerOperationLog) GetTableName(needFull bool) string { + tableName := TableNamePowerOperationLog + if needFull { + tableName = mdl.TableName() + } + return tableName +} + func NewPowerOperationLog(mapObject *object.Collection) *PowerOperationLog { if mapObject == nil { @@ -58,15 +65,6 @@ func NewPowerOperationLog(mapObject *object.Collection) *PowerOperationLog { } } -// 获取当前 Model 的数据库表名称 -func (mdl *PowerOperationLog) GetTableName(needFull bool) string { - tableName := TableNameOperationLog - if needFull { - tableName = "public.ac_" + tableName - } - return tableName -} - func (mdl *PowerOperationLog) SaveOps(db *gorm.DB, operatorName string, operator powermodel.ModelInterface, module int16, operate string, event int8, diff --git a/internal/model/organization/department.go b/internal/model/organization/department.go index 06ed72fd..eaff941c 100644 --- a/internal/model/organization/department.go +++ b/internal/model/organization/department.go @@ -2,12 +2,14 @@ package organization import ( "PowerX/internal/model" + "PowerX/internal/model/powermodel" "gorm.io/gorm" "gorm.io/gorm/clause" ) type Department struct { - model.Model + powermodel.PowerModel + PDep *Department `gorm:"foreignKey:PId"` Leader *User `gorm:"foreignKey:LeaderId"` Ancestors []*Department `gorm:"many2many:department_ancestors;"` @@ -23,13 +25,21 @@ type Department struct { IsWeWorkArchitecture bool `gorm:"comment:是否启用企微架构;column:is_we_work_architecture" json:"is_we_work_architecture"` } -func (e *Department) TableName() string { - return `departments` +func (mdl *Department) TableName() string { + return model.PowerXSchema + "." + model.TableNameDepartment +} + +func (mdl *Department) GetTableName(needFull bool) string { + tableName := model.TableNameDepartment + if needFull { + tableName = mdl.TableName() + } + return tableName } -func (e *Department) Action(db *gorm.DB, departments []*Department) { +func (mdl *Department) Action(db *gorm.DB, departments []*Department) { - err := db.Table(e.TableName()).Clauses(clause.OnConflict{Columns: []clause.Column{{Name: "we_work_user_id"}}, UpdateAll: true}).CreateInBatches(&departments, 100).Error + err := db.Table(mdl.TableName()).Clauses(clause.OnConflict{Columns: []clause.Column{{Name: "we_work_user_id"}}, UpdateAll: true}).CreateInBatches(&departments, 100).Error if err != nil { panic(err) } diff --git a/internal/model/organization/position.go b/internal/model/organization/position.go index 2d29e1c9..b23711e9 100644 --- a/internal/model/organization/position.go +++ b/internal/model/organization/position.go @@ -3,13 +3,27 @@ package organization import ( "PowerX/internal/model" "PowerX/internal/model/permission" + "PowerX/internal/model/powermodel" ) // Position 职位 type Position struct { - model.Model + powermodel.PowerModel + Name string `gorm:"comment:职位名称;column:name" json:"name"` Desc string `gorm:"comment:描述;column:desc" json:"desc"` Roles []*permission.AdminRole `gorm:"many2many:position_roles;foreignKey:Id;References:RoleCode" json:"roles"` Level string `gorm:"comment:职级;column:level" json:"level"` } + +func (mdl *Position) TableName() string { + return model.PowerXSchema + "." + model.TableNamePosition +} + +func (mdl *Position) GetTableName(needFull bool) string { + tableName := model.TableNamePosition + if needFull { + tableName = mdl.TableName() + } + return tableName +} diff --git a/internal/model/organization/user.go b/internal/model/organization/user.go index ce3be753..2a9773cd 100644 --- a/internal/model/organization/user.go +++ b/internal/model/organization/user.go @@ -2,6 +2,7 @@ package organization import ( "PowerX/internal/model" + "PowerX/internal/model/powermodel" "github.com/pkg/errors" "golang.org/x/crypto/bcrypt" "gorm.io/gorm" @@ -9,7 +10,7 @@ import ( ) type User struct { - model.Model + powermodel.PowerModel UUID string `json:"comment:唯一标识;column:uuid;unique;type:uuid" json:"uuid"` Account string `gorm:"comment:账户;column:account unique;type:varchar" json:"account"` @@ -34,9 +35,21 @@ type User struct { WeWorkUserId string `gorm:"comment:微信账户;column:we_work_user_id;type:varchar" json:"we_work_user_id"` } -func (e *User) HashPassword() (err error) { - if e.Password != "" { - e.Password, err = HashPassword(e.Password) +func (mdl *User) TableName() string { + return model.PowerXSchema + "." + model.TableNameCart +} + +func (mdl *User) GetTableName(needFull bool) string { + tableName := model.TableNameCart + if needFull { + tableName = mdl.TableName() + } + return tableName +} + +func (mdl *User) HashPassword() (err error) { + if mdl.Password != "" { + mdl.Password, err = HashPassword(mdl.Password) } return nil } @@ -69,13 +82,9 @@ func VerifyPassword(hashedPwd string, pwd string) bool { return err == nil } -func (e *User) TableName() string { - return `users` -} - -func (e *User) Action(db *gorm.DB, users []*User) { +func (mdl *User) Action(db *gorm.DB, users []*User) { - err := db.Table(e.TableName()). + err := db.Table(mdl.TableName()). //Debug(). Clauses( clause.OnConflict{Columns: []clause.Column{{Name: `we_work_user_id`}}, diff --git a/internal/model/scene/activeqrcode.go b/internal/model/scene/activeqrcode.go index c1a40939..a067c82a 100644 --- a/internal/model/scene/activeqrcode.go +++ b/internal/model/scene/activeqrcode.go @@ -2,12 +2,13 @@ package scene import ( "PowerX/internal/model" + "PowerX/internal/model/powermodel" "gorm.io/gorm" "gorm.io/gorm/clause" ) type SceneQRCode struct { - model.Model + powermodel.PowerModel QId string `gorm:"comment:唯一标识;unique;column:qid" json:"qid"` Name string `gorm:"comment:活码名称;column:name" json:"name"` Desc string `gorm:"comment:描述;column:desc" json:"desc"` @@ -26,13 +27,16 @@ type SceneQRCode struct { State int `gorm:"comment:状态1:启用 2:禁用 3:删除;column:state" json:"state"` } -// Table -// -// @Description: -// @receiver e -// @return string -func (e SceneQRCode) TableName() string { - return model.TableNameSceneQRCode +func (mdl *SceneQRCode) TableName() string { + return model.PowerXSchema + "." + model.TableNameSceneQRCode +} + +func (mdl *SceneQRCode) GetTableName(needFull bool) string { + tableName := model.TableNameSceneQRCode + if needFull { + tableName = mdl.TableName() + } + return tableName } // Query diff --git a/internal/model/scrm/app/weworkappgroup.go b/internal/model/scrm/app/weworkappgroup.go index 0639063d..645f3ca1 100644 --- a/internal/model/scrm/app/weworkappgroup.go +++ b/internal/model/scrm/app/weworkappgroup.go @@ -2,12 +2,13 @@ package app import ( "PowerX/internal/model" + "PowerX/internal/model/powermodel" "gorm.io/gorm" "gorm.io/gorm/clause" ) type WeWorkAppGroup struct { - model.Model + powermodel.PowerModel Name string `gorm:"comment:群名称;column:name" json:"name"` Owner string `gorm:"comment:群主;column:owner" json:"owner"` @@ -15,13 +16,16 @@ type WeWorkAppGroup struct { ChatID string `gorm:"comment:群ID;unique"` } -// Table -// -// @Description: -// @receiver e -// @return string -func (e WeWorkAppGroup) TableName() string { - return model.WeWorkAppGroup +func (mdl *WeWorkAppGroup) TableName() string { + return model.PowerXSchema + "." + model.TableNameWeWorkAppGroup +} + +func (mdl *WeWorkAppGroup) GetTableName(needFull bool) string { + tableName := model.TableNameWeWorkAppGroup + if needFull { + tableName = mdl.TableName() + } + return tableName } type ( diff --git a/internal/model/scrm/customer/weworkcustomer.go b/internal/model/scrm/customer/weworkcustomer.go index c9e483bc..27c6240e 100644 --- a/internal/model/scrm/customer/weworkcustomer.go +++ b/internal/model/scrm/customer/weworkcustomer.go @@ -2,12 +2,14 @@ package customer import ( "PowerX/internal/model" + "PowerX/internal/model/powermodel" "gorm.io/gorm" "gorm.io/gorm/clause" ) type WeWorkExternalContact struct { - model.Model + powermodel.PowerModel + WeWorkExternalContactFollow WeWorkExternalContactFollow `gorm:"foreignKey:ExternalUserId;references:external_user_id" json:"WeWorkExternalContactFollow"` ExternalUserId string `gorm:"comment:客户ID;unique;not null;" json:"externalUserId"` AppId string `gorm:"comment:应用ID;index:idx_app_id;column:app_id" json:"appId"` @@ -29,13 +31,16 @@ type WeWorkExternalContact struct { Active bool `gorm:"active" json:"active"` } -// Table -// -// @Description: -// @receiver e -// @return string -func (e WeWorkExternalContact) TableName() string { - return model.TableNameWeWorkExternalContact +func (mdl *WeWorkExternalContact) TableName() string { + return model.PowerXSchema + "." + model.TableNameWeWorkExternalContact +} + +func (mdl *WeWorkExternalContact) GetTableName(needFull bool) string { + tableName := model.TableNameWeWorkExternalContact + if needFull { + tableName = mdl.TableName() + } + return tableName } // Query @@ -44,9 +49,9 @@ func (e WeWorkExternalContact) TableName() string { // @receiver e // @param db // @return contacts -func (e WeWorkExternalContact) Query(db *gorm.DB) (contacts []*WeWorkExternalContact) { +func (mdl *WeWorkExternalContact) Query(db *gorm.DB) (contacts []*WeWorkExternalContact) { - err := db.Model(e).Find(&contacts).Error + err := db.Model(mdl).Find(&contacts).Error if err != nil { panic(err) } @@ -60,9 +65,9 @@ func (e WeWorkExternalContact) Query(db *gorm.DB) (contacts []*WeWorkExternalCon // @receiver e // @param db // @param contacts -func (e *WeWorkExternalContact) Action(db *gorm.DB, contacts []*WeWorkExternalContact) { +func (mdl *WeWorkExternalContact) Action(db *gorm.DB, contacts []*WeWorkExternalContact) { - err := db.Table(e.TableName()).Clauses(clause.OnConflict{Columns: []clause.Column{{Name: "external_user_id"}}, UpdateAll: true}).CreateInBatches(&contacts, 100).Error + err := db.Table(mdl.TableName()).Clauses(clause.OnConflict{Columns: []clause.Column{{Name: "external_user_id"}}, UpdateAll: true}).CreateInBatches(&contacts, 100).Error if err != nil { panic(err) } diff --git a/internal/model/scrm/customer/weworkcustomerExternalFollow.go b/internal/model/scrm/customer/weworkcustomerExternalFollow.go index 7e654f26..ed1b80fb 100644 --- a/internal/model/scrm/customer/weworkcustomerExternalFollow.go +++ b/internal/model/scrm/customer/weworkcustomerExternalFollow.go @@ -2,12 +2,13 @@ package customer import ( "PowerX/internal/model" + "PowerX/internal/model/powermodel" "gorm.io/gorm" "gorm.io/gorm/clause" ) type WeWorkExternalContactFollow struct { - model.Model + powermodel.PowerModel ExternalUserId string `gorm:"comment:客户ID;column:external_user_id;unique" json:"external_user_id"` UserId string `gorm:"comment:员工ID;column:user_id" json:"user_id"` @@ -24,13 +25,16 @@ type WeWorkExternalContactFollow struct { State string `gorm:"comment:State;column:state" json:"state"` } -// Table -// -// @Description: -// @receiver e -// @return string -func (e WeWorkExternalContactFollow) TableName() string { - return model.TableNameWeWorkExternalContactFollow +func (mdl *WeWorkExternalContactFollow) TableName() string { + return model.PowerXSchema + "." + model.TableNameWeWorkExternalContactFollow +} + +func (mdl *WeWorkExternalContactFollow) GetTableName(needFull bool) string { + tableName := model.TableNameWeWorkExternalContactFollow + if needFull { + tableName = mdl.TableName() + } + return tableName } // Query diff --git a/internal/model/scrm/organization/weworkdepartment.go b/internal/model/scrm/organization/weworkdepartment.go index c6152584..0361cf4b 100644 --- a/internal/model/scrm/organization/weworkdepartment.go +++ b/internal/model/scrm/organization/weworkdepartment.go @@ -2,12 +2,14 @@ package organization import ( "PowerX/internal/model" + "PowerX/internal/model/powermodel" "gorm.io/gorm" "gorm.io/gorm/clause" ) type WeWorkDepartment struct { - model.Model + powermodel.PowerModel + // Leader *WeWorkUser `gorm:"foreignKey:LeaderId"` WeWorkDepId int `gorm:"comment:部门ID;column:we_work_dep_id;unique" json:"we_work_dep_id"` Name string `gorm:"comment:部门名称;column:name" json:"name"` @@ -18,13 +20,16 @@ type WeWorkDepartment struct { RefDepartmentId int64 `gorm:"comment:-;column:ref_department_id" json:"ref_department_id"` } -// Table -// -// @Description: -// @receiver e -// @return string -func (e WeWorkDepartment) TableName() string { - return model.TableNameWeWorkDepartment +func (mdl *WeWorkDepartment) TableName() string { + return model.PowerXSchema + "." + model.TableNameWeWorkDepartment +} + +func (mdl *WeWorkDepartment) GetTableName(needFull bool) string { + tableName := model.TableNameWeWorkDepartment + if needFull { + tableName = mdl.TableName() + } + return tableName } // Query diff --git a/internal/model/scrm/organization/weworkuser.go b/internal/model/scrm/organization/weworkuser.go index c49aebab..e4b94465 100644 --- a/internal/model/scrm/organization/weworkuser.go +++ b/internal/model/scrm/organization/weworkuser.go @@ -2,12 +2,13 @@ package organization import ( "PowerX/internal/model" + "PowerX/internal/model/powermodel" "gorm.io/gorm" "gorm.io/gorm/clause" ) type WeWorkUser struct { - model.Model + powermodel.PowerModel WeWorkUserId string `gorm:"comment:员工ID;column:we_work_user_id;unique" json:"we_work_user_id"` Name string `gorm:"comment:员工名称;column:name" json:"name"` @@ -29,13 +30,16 @@ type WeWorkUser struct { RefUserId int64 `gorm:"comment:RefUserId;column:ref_user_id" json:"ref_user_id"` } -// Table -// -// @Description: -// @receiver e -// @return string -func (e WeWorkUser) TableName() string { - return model.TableNameWeWorkUser +func (mdl *WeWorkUser) TableName() string { + return model.PowerXSchema + "." + model.TableNameWeWorkUser +} + +func (mdl *WeWorkUser) GetTableName(needFull bool) string { + tableName := model.TableNameWeWorkUser + if needFull { + tableName = mdl.TableName() + } + return tableName } type ( diff --git a/internal/model/scrm/resource/department.go b/internal/model/scrm/resource/department.go index 6c615079..ba444d97 100644 --- a/internal/model/scrm/resource/department.go +++ b/internal/model/scrm/resource/department.go @@ -2,12 +2,14 @@ package resource import ( "PowerX/internal/model" + "PowerX/internal/model/powermodel" "gorm.io/gorm" "gorm.io/gorm/clause" ) type WeWorkResource struct { - model.Model + powermodel.PowerModel + Url string `gorm:"comment:微信地址;column:url" json:"url"` FileName string `gorm:"unique;comment:文件名;column:file_name" json:"file_name"` Remark string `gorm:"comment:备注;column:remark" json:"remark"` @@ -16,13 +18,16 @@ type WeWorkResource struct { ResourceType string `gorm:"comment:资源类型:image,voice,file, video, other;column:resource_type" json:"resource_type"` } -// TableName -// -// @Description: -// @receiver e -// @return string -func (e WeWorkResource) TableName() string { - return model.TableNameWeWorkResource +func (mdl *WeWorkResource) TableName() string { + return model.PowerXSchema + "." + model.TableNameWeWorkResource +} + +func (mdl *WeWorkResource) GetTableName(needFull bool) string { + tableName := model.TableNameWeWorkResource + if needFull { + tableName = mdl.TableName() + } + return tableName } // Query diff --git a/internal/model/scrm/tag/weworkgroup.go b/internal/model/scrm/tag/weworkgroup.go index 6b39ab3e..7275be24 100644 --- a/internal/model/scrm/tag/weworkgroup.go +++ b/internal/model/scrm/tag/weworkgroup.go @@ -2,12 +2,14 @@ package tag import ( "PowerX/internal/model" + "PowerX/internal/model/powermodel" "gorm.io/gorm" "gorm.io/gorm/clause" ) type WeWorkTagGroup struct { - model.Model + powermodel.PowerModel + WeWorkGroupTags []*WeWorkTag `gorm:"foreignKey:GroupId;references:group_id" json:"WeWorkGroupTags"` AgentId int `gorm:"comment:应用ID;column:agent_id" json:"agent_id"` GroupId string `gorm:"comment:标签组ID;column:group_id;unique" json:"group_id"` @@ -16,13 +18,16 @@ type WeWorkTagGroup struct { IsDelete bool `gorm:"comment:是否删除;column:is_delete" json:"is_delete"` } -// Table -// -// @Description: -// @receiver e -// @return string -func (e WeWorkTagGroup) TableName() string { - return model.TableNameWeWorkTagGroup +func (mdl *WeWorkTagGroup) TableName() string { + return model.PowerXSchema + "." + model.TableNameWeWorkTagGroup +} + +func (mdl *WeWorkTagGroup) GetTableName(needFull bool) string { + tableName := model.TableNameWeWorkTagGroup + if needFull { + tableName = mdl.TableName() + } + return tableName } // Query diff --git a/internal/model/scrm/tag/weworktag.go b/internal/model/scrm/tag/weworktag.go index 72902a76..cc053049 100644 --- a/internal/model/scrm/tag/weworktag.go +++ b/internal/model/scrm/tag/weworktag.go @@ -2,13 +2,15 @@ package tag import ( "PowerX/internal/model" + "PowerX/internal/model/powermodel" "gorm.io/gorm" "gorm.io/gorm/clause" "time" ) type WeWorkTag struct { - model.Model + powermodel.PowerModel + WeWorkGroup *WeWorkTagGroup `gorm:"foreignKey:GroupId;references:group_id" json:"WeWorkGroup"` // IsSelf int `gorm:"comment:是否自建:1:平台创建:其他:微信创建;column:is_self" json:"is_self"` @@ -20,13 +22,16 @@ type WeWorkTag struct { IsDelete bool `gorm:"comment:是否删除;column:is_delete" json:"is_delete"` } -// Table -// -// @Description: -// @receiver e -// @return string -func (e WeWorkTag) TableName() string { - return model.TableNameWeWorkTag +func (mdl *WeWorkTag) TableName() string { + return model.PowerXSchema + "." + model.TableNameWeWorkTag +} + +func (mdl *WeWorkTag) GetTableName(needFull bool) string { + tableName := model.TableNameWeWorkTag + if needFull { + tableName = mdl.TableName() + } + return tableName } // Query diff --git a/internal/model/tables.go b/internal/model/tables.go index 2f93e519..890cb90d 100644 --- a/internal/model/tables.go +++ b/internal/model/tables.go @@ -11,7 +11,11 @@ const TableNameRegisterCode = "register_codes" // crm market const TableNameMedia = "media" -const TableNameMGM = "mgm_rules" +const TableNameMGMRule = "mgm_rules" +const TableNameCustomerChannel = "customer_channels" +const TableNameInviteRecord = "invite_records" +const TableNameCommissionRecord = "commission_records" +const TableNameRewardRecord = "reward_records" const TableNamePromotionRule = "promotion_rules" const TableNameStore = "stores" @@ -30,24 +34,29 @@ const TableNamePriceConfig = "price_configs" const TableNameProduct = "products" const TableNameProductCategory = "product_categories" const TableNameProductSpecific = "product_specifics" +const TableNameSpecificOption = "product_options" const TableNameProductStatistics = "product_statistics" const TableNameSKU = "sku" // trade const TableNameBillingAddress = "billing_addresses" -const TableNameBillingCart = "carts" -const TableNameBillingCartItem = "cart_items" +const TableNameCart = "carts" +const TableNameCartItem = "cart_items" const TableNameDeliveryAddress = "delivery_addresses" const TableNameInventory = "inventories" const TableNameLogistics = "logistics" const TableNameOrder = "orders" +const TableNameOrderItem = "order_items" +const TableNameOrderStatusTransition = "order_status_transitions" const TableNamePayment = "payments" +const TableNamePaymentItem = "payment_items" const TableNamePivotProductToPromotion = "pivot_product_to_promotion" const TableNamePivotOrderToInventoryLog = "pivot_order_to_inventory_log" const TableNameRefundOrder = "refund_orders" const TableNameRefundOrderItem = "refund_order_items" const TableNameShippingAddress = "shipping_addresses" const TableNameTokenExchangeRatio = "token_exchange_ratios" +const TableNameTokenBalance = "token_balances" const TableNameTokenExchangeRecord = "token_exchange_records" const TableNameTokenReservation = "token_reservations" const TableNameTokenTransaction = "token_transactions" @@ -75,14 +84,12 @@ const TableNameOperationLog = "power_operation_logs" // scene const TableNameSceneQRCode = "scene_qr_codes" -const TableNamePivotDataDictionaryToObject = "pivot_data_dictionary_to_object" - // tag const TableNamePivotObjectToTag = "pivot_object_to_tag" const TableNameTag = "tags" // scrm app -const WeWorkAppGroup = "wework_app_groups" +const TableNameWeWorkAppGroup = "wework_app_groups" // scrm customer const TableNameWeWorkExternalContact = "we_work_external_contacts" @@ -103,5 +110,13 @@ const TableNameWeWorkTag = "we_work_tags" const TableNameWechatMPCustomer = "wechat_mp_customers" const TableNameWechatOACustomer = "wechat_oa_customers" +// data dictionary +const TableNameDataDictionaryItem = "data_dictionary_items" +const TableNameDataDictionaryType = "data_dictionary_types" +const TableNamePivotDataDictionaryToObject = "pivot_data_dictionary_to_object" + +// operation log +const TableNamePowerOperationLog = "power_operation_logs" + // custom const TableNameArtisanSpecific = "artisan_specifics" diff --git a/internal/model/tag/pivotobjecttotag.go b/internal/model/tag/pivotobjecttotag.go index a31c9d6e..ccf5334d 100644 --- a/internal/model/tag/pivotobjecttotag.go +++ b/internal/model/tag/pivotobjecttotag.go @@ -8,11 +8,6 @@ import ( "gorm.io/gorm" ) -// Table Name -func (mdl *PivotObjectToTag) TableName() string { - return model.TableNamePivotObjectToTag -} - // 数据表结构 type PivotObjectToTag struct { powermodel.PowerPivot @@ -28,6 +23,18 @@ const PivotObjectToTagForeignOwnerKey = "object_type" const PivotObjectToTagForeignKey = "object_id" const PivotObjectToTagJoinKey = "tag_id" +func (mdl *PivotObjectToTag) TableName() string { + return model.PowerXSchema + "." + model.TableNamePivotObjectToTag +} + +func (mdl *PivotObjectToTag) GetTableName(needFull bool) string { + tableName := model.TableNamePivotObjectToTag + if needFull { + tableName = mdl.TableName() + } + return tableName +} + func (mdl *PivotObjectToTag) GetOwnerKey() string { // 因为是morphy类型,所以外键是Owner return PivotObjectToTagForeignOwnerKey diff --git a/internal/model/tag/tag.go b/internal/model/tag/tag.go index d6d27b55..c8793897 100644 --- a/internal/model/tag/tag.go +++ b/internal/model/tag/tag.go @@ -26,6 +26,17 @@ type Tag struct { const TagUniqueId = powermodel.UniqueId +func (mdl *Tag) TableName() string { + return model.PowerXSchema + "." + model.TableNameTag +} + +func (mdl *Tag) GetTableName(needFull bool) string { + tableName := model.TableNameTag + if needFull { + tableName = mdl.TableName() + } + return tableName +} func GetTagIds(tags []*Tag) []int64 { uniqueIds := make(map[int64]bool) arrayIds := []int64{} diff --git a/internal/model/wechat/miniprogram.go b/internal/model/wechat/miniprogram.go index d776ec88..24f1ccce 100644 --- a/internal/model/wechat/miniprogram.go +++ b/internal/model/wechat/miniprogram.go @@ -3,15 +3,17 @@ package wechat import ( "PowerX/internal/model" customerdomain2 "PowerX/internal/model/crm/customerdomain" + "PowerX/internal/model/powermodel" "fmt" "github.com/ArtisanCloud/PowerLibs/v3/security" ) // 小程序客户信息 type WechatMPCustomer struct { + powermodel.PowerModel + Customer *customerdomain2.Customer `gorm:"foreignKey:OpenId;references:OpenIdInMiniProgram" json:"customer"` - model.Model UniqueID string `gorm:"unique" json:"uniqueId"` SessionKey string `json:"-"` OpenId string `json:"openId"` @@ -34,6 +36,18 @@ type WechatMPCustomer struct { const WechatMpCustomerUniqueId = "unique_id" +func (mdl *WechatMPCustomer) TableName() string { + return model.PowerXSchema + "." + model.TableNameWechatMPCustomer +} + +func (mdl *WechatMPCustomer) GetTableName(needFull bool) string { + tableName := model.TableNameWechatMPCustomer + if needFull { + tableName = mdl.TableName() + } + return tableName +} + // 小程序获取手机号 // https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/user-info/phone-number/getPhoneNumber.html type MPPhoneInfo struct { diff --git a/internal/model/wechat/offiaccount.go b/internal/model/wechat/offiaccount.go index f87974e6..173050a2 100644 --- a/internal/model/wechat/offiaccount.go +++ b/internal/model/wechat/offiaccount.go @@ -3,6 +3,7 @@ package wechat import ( "PowerX/internal/model" customerdomain2 "PowerX/internal/model/crm/customerdomain" + "PowerX/internal/model/powermodel" "gorm.io/datatypes" ) @@ -10,9 +11,10 @@ import ( // 公众号的客户信息 // https://developers.weixin.qq.com/doc/offiaccount/User_Management/Get_users_basic_information_UnionId.html#UinonId type WechatOACustomer struct { + powermodel.PowerModel + Customer *customerdomain2.Customer `gorm:"foreignKey:OpenId;references:OpenIdInWeChatOfficialAccount" json:"customer"` - model.Model Subscribe int `json:"subscribe"` SessionKey string `json:"-"` OpenId string `json:"openId"` @@ -26,3 +28,15 @@ type WechatOACustomer struct { QrScene int `json:"qrScene"` QrSceneStr string `json:"qrSceneStr"` } + +func (mdl *WechatOACustomer) TableName() string { + return model.PowerXSchema + "." + model.TableNameWechatOACustomer +} + +func (mdl *WechatOACustomer) GetTableName(needFull bool) string { + tableName := model.TableNameWechatOACustomer + if needFull { + tableName = mdl.TableName() + } + return tableName +} diff --git a/internal/uc/powerx/organization.go b/internal/uc/powerx/organization.go index 216aacbf..a82850b7 100644 --- a/internal/uc/powerx/organization.go +++ b/internal/uc/powerx/organization.go @@ -1,7 +1,6 @@ package powerx import ( - "PowerX/internal/model" "PowerX/internal/model/option" "PowerX/internal/model/organization" "PowerX/internal/model/permission" @@ -164,7 +163,7 @@ func (uc *OrganizationUseCase) FindOneUserById(ctx context.Context, id int64) (u func (uc *OrganizationUseCase) UpdateUserById(ctx context.Context, user *organization.User, userId int64) error { whereCase := organization.User{ - Model: model.Model{ + PowerModel: powermodel.PowerModel{ Id: userId, }, IsReserved: false, diff --git a/internal/uc/powerx/scrm/wechat/weworktag.go b/internal/uc/powerx/scrm/wechat/weworktag.go index 8ee9fdec..3f6a1cf6 100644 --- a/internal/uc/powerx/scrm/wechat/weworktag.go +++ b/internal/uc/powerx/scrm/wechat/weworktag.go @@ -1,7 +1,7 @@ package wechat import ( - "PowerX/internal/model" + "PowerX/internal/model/powermodel" "PowerX/internal/model/scrm/customer" "PowerX/internal/model/scrm/tag" "PowerX/internal/types" @@ -170,7 +170,7 @@ func (this wechatUseCase) transferWeWorkToModel(data []*response.CorpTagGroup, a if data != nil { for _, val := range data { groups = append(groups, &tag.WeWorkTagGroup{ - Model: model.Model{ + PowerModel: powermodel.PowerModel{ CreatedAt: time.Unix(int64(val.CreateTime), 0), }, //AgentId: int(*agentId), @@ -182,7 +182,7 @@ func (this wechatUseCase) transferWeWorkToModel(data []*response.CorpTagGroup, a if val.Tags != nil { for _, value := range val.Tags { tags = append(tags, &tag.WeWorkTag{ - Model: model.Model{ + PowerModel: powermodel.PowerModel{ CreatedAt: time.Unix(int64(value.CreateTime), 0), }, Type: 1,