refactor: 重构资产模型与DAO层实现

This commit is contained in:
2026-03-19 17:45:06 +08:00
parent 5236c45a39
commit f30141679c
24 changed files with 570 additions and 600 deletions

View File

@@ -5,30 +5,74 @@ import (
"assets/consts/stock"
"gitea.com/red-future/common/beans"
"github.com/gogf/gf/v2/encoding/gjson"
"github.com/gogf/gf/v2/os/gtime"
)
type assetCol struct {
beans.SQLBaseCol
Name string
Description string
Type string
CategoryId string
CategoryPath string
ImageURL string
Images string
Status string
BasePrice string
Currency string
UnlimitedStock string
StockMode string
OnlineTime string
OfflineTime string
PhysicalAssetConfig string
ServiceAssetConfig string
VirtualAssetConfig string
Metadata string
TenantModuleType string
}
var AssetCol = assetCol{
SQLBaseCol: beans.DefSQLBaseCol,
Name: "name",
Description: "description",
Type: "type",
CategoryId: "category_id",
CategoryPath: "category_path",
ImageURL: "image_url",
Images: "images",
Status: "status",
BasePrice: "base_price",
Currency: "currency",
UnlimitedStock: "unlimited_stock",
StockMode: "stock_mode",
OnlineTime: "online_time",
OfflineTime: "offline_time",
PhysicalAssetConfig: "physical_asset_config",
ServiceAssetConfig: "service_asset_config",
VirtualAssetConfig: "virtual_asset_config",
Metadata: "metadata",
TenantModuleType: "tenant_module_type",
}
// Asset 资产实体
type Asset struct {
beans.SQLBaseDO `orm:",inherit"` // 嵌入基础字段Id, Creator, CreatedAt, Updater, UpdatedAt, IsDeleted
beans.SQLBaseDO `orm:",inherit"`
// 基础信息
Name string `orm:"name" json:"name" description:"资产名称"`
Description string `orm:"description" json:"description" description:"资产描述"`
Type consts.AssetType `orm:"type" json:"type" description:"资产类型physical实物/virtual虚拟/service服务"`
CategoryId uint64 `orm:"category_id" json:"categoryId" description:"分类ID"`
CategoryPath string `orm:"category_path" json:"categoryPath" description:"分类路径"`
ImageURL string `orm:"image_url" json:"imageUrl" description:"主图URL"`
Images []string `orm:"images" json:"images" description:"图片列表(JSONB)"`
Status *consts.AssetStatus `orm:"status" json:"status" description:"资产状态1启用/0停用"`
BasePrice int `orm:"base_price" json:"basePrice" description:"基础价格(分为单位)"`
Currency string `orm:"currency" json:"currency" description:"货币单位默认CNY"`
UnlimitedStock bool `orm:"unlimited_stock" json:"unlimitedStock" description:"是否无库存限制"`
StockMode stock.StockMode `orm:"stock_mode" json:"stockMode" description:"库存管理模式1-明细模式 2-批次模式"`
// 上线和下线时间配置(由定时任务处理资产状态)
OnlineTime *gtime.Time `orm:"online_time" json:"onlineTime,omitempty" description:"线时间"`
OfflineTime *gtime.Time `orm:"offline_time" json:"offlineTime,omitempty" description:"下线时间"`
Name string `orm:"name" json:"name" description:"资产名称"`
Description string `orm:"description" json:"description" description:"资产描述"`
Type consts.AssetType `orm:"type" json:"type" description:"资产类型physical实物/virtual虚拟/service服务"`
CategoryId int64 `orm:"category_id" json:"categoryId" description:"分类ID"`
CategoryPath string `orm:"category_path" json:"categoryPath" description:"分类路径"`
ImageURL string `orm:"image_url" json:"imageUrl" description:"主图URL"`
Images []string `orm:"images" json:"images" description:"图片列表(JSONB)"`
Status consts.AssetStatusType `orm:"status" json:"status" description:"资产状态1启用/0停用"`
BasePrice int `orm:"base_price" json:"basePrice" description:"基础价格(分为单位)"`
Currency string `orm:"currency" json:"currency" description:"货币单位默认CNY"`
UnlimitedStock bool `orm:"unlimited_stock" json:"unlimitedStock" description:"是否无库存限制"`
StockMode stock.StockMode `orm:"stock_mode" json:"stockMode" description:"库存管理模式1-明细模式 2-批次模式"`
OnlineTime *gtime.Time `orm:"online_time" json:"onlineTime,omitempty" description:"上线时间"` // 上线和下线时间配置(由定时任务处理资产状态)
OfflineTime *gtime.Time `orm:"offline_time" json:"offlineTime,omitempty" description:"线时间"` // 上线和下线时间配置(由定时任务处理资产状态)
// 类型专用配置 - 实物资产配置(JSONB)
PhysicalAssetConfig *gjson.Json `orm:"physical_asset_config" json:"physicalAssetConfig" description:"实物资产配置(JSONB)"`
@@ -37,7 +81,7 @@ type Asset struct {
// 类型专用配置 - 虚拟资产配置(JSONB)
VirtualAssetConfig *gjson.Json `orm:"virtual_asset_config" json:"virtualAssetConfig" description:"虚拟资产配置(JSONB)"`
// 扩展字段(JSONB)
Metadata *gjson.Json `orm:"metadata" json:"metadata" description:"动态元数据(JSONB)"`
Metadata []gjson.Json `orm:"metadata" json:"metadata" description:"动态元数据(JSONB)"`
TenantModuleType string `orm:"tenant_module_type" json:"tenantModuleType" description:"租户模块类型"`
TenantModuleType beans.TenantModuleType `orm:"tenant_module_type" json:"tenantModuleType" description:"租户模块类型"`
}