新增了反向商品信息输出表
This commit is contained in:
parent
62dacbb5fc
commit
50e8cbca61
@ -270,8 +270,13 @@ func Init() {
|
||||
log.Fatal("Config表迁移失败:", err)
|
||||
}
|
||||
|
||||
// 初始化商品表
|
||||
InitProductBookTables()
|
||||
// 初始化默认管理员账号
|
||||
createDefaultAdmin()
|
||||
// 初始化任务数据库
|
||||
InitTaskDB()
|
||||
// 打印连接信息
|
||||
log.Println("MySQL数据库连接成功:", cfg.Database.Host, cfg.Database.Name)
|
||||
}
|
||||
|
||||
|
||||
23
database/product_book.go
Normal file
23
database/product_book.go
Normal file
@ -0,0 +1,23 @@
|
||||
package database
|
||||
|
||||
import (
|
||||
"log"
|
||||
"psi/models"
|
||||
)
|
||||
|
||||
// InitProductBookTables 初始化商品书籍分表(product_book_00 ~ product_book_99)
|
||||
func InitProductBookTables() {
|
||||
migrator := DB.Migrator()
|
||||
tableNames := models.ProductBookAllTableNames()
|
||||
|
||||
for _, tableName := range tableNames {
|
||||
if !migrator.HasTable(tableName) {
|
||||
err := DB.Set("gorm:table_options", "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='商品书籍分表'").
|
||||
Table(tableName).AutoMigrate(&models.ProductBook{})
|
||||
if err != nil {
|
||||
log.Fatalf("%s 表迁移失败: %v", tableName, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
log.Printf("商品书籍分表初始化完成,共 %d 张表(%s ~ %s)", len(tableNames), tableNames[0], tableNames[len(tableNames)-1])
|
||||
}
|
||||
71
models/product_book.go
Normal file
71
models/product_book.go
Normal file
@ -0,0 +1,71 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"gorm.io/datatypes"
|
||||
)
|
||||
|
||||
// ProductBook 商品书籍分表(按ISBN后两位分表 product_book_00 ~ product_book_99)
|
||||
type ProductBook struct {
|
||||
ID int64 `json:"id" gorm:"primarykey;comment:商品ID"`
|
||||
CategoryID int64 `json:"category_id" gorm:"not null;default:0;comment:分类ID"`
|
||||
AboutId int64 `json:"about_id" gorm:"not null;default:0;index;comment:关联ID"`
|
||||
WarehouseID int64 `json:"warehouse_id" gorm:"not null;default:0;index;comment:仓库ID"`
|
||||
WarehouseName string `json:"warehouse_name" gorm:"size:100;not null;default:'';comment:仓库名称"`
|
||||
LocationID int64 `json:"location_id" gorm:"not null;default:0;index;comment:货位ID"`
|
||||
LocationName string `json:"location_name" gorm:"size:50;not null;default:'';comment:货位名称"`
|
||||
StandardProductID int64 `json:"standard_product_id" gorm:"not null;default:0;index;comment:关联标品ID"`
|
||||
Fid int64 `json:"fid" gorm:"not null;default:0;comment:父级ID"`
|
||||
Type int8 `json:"type" gorm:"not null;default:0;comment:类型 1正常 2套装书 3一号多书 4无书号"`
|
||||
ISBN string `json:"isbn" gorm:"size:20;not null;default:'';index:idx_isbn;comment:ISBN"`
|
||||
FISBN string `json:"f_isbn" gorm:"size:20;not null;default:'';comment:FISBN"`
|
||||
BookName string `json:"book_name" gorm:"size:100;not null;default:'';comment:书名"`
|
||||
FBookName string `json:"f_book_name" gorm:"size:100;not null;default:'';comment:副书名"`
|
||||
Author string `json:"author" gorm:"size:100;not null;default:'';comment:作者"`
|
||||
Publishing string `json:"publishing" gorm:"size:50;not null;default:'';comment:出版社"`
|
||||
PublicationTime int64 `json:"publication_time" gorm:"type:bigint;not null;default:0;comment:出版日期时间戳"`
|
||||
Binding string `json:"binding" gorm:"size:10;not null;default:'';comment:装帧"`
|
||||
PagesCount int64 `json:"pages_count" gorm:"not null;default:0;comment:页数"`
|
||||
WordsCount int64 `json:"words_count" gorm:"not null;default:0;comment:字数"`
|
||||
Format int64 `json:"format" gorm:"not null;default:0;comment:开本"`
|
||||
CatID datatypes.JSON `json:"cat_id" gorm:"type:json;not null;comment:类目json"`
|
||||
Name string `json:"name" gorm:"size:255;not null;default:'';comment:商品名称"`
|
||||
Appearance int64 `json:"appearance" gorm:"not null;default:0;comment:品相"`
|
||||
Barcode string `json:"barcode" gorm:"size:100;not null;default:'';index;comment:条码"`
|
||||
Price int64 `json:"price" gorm:"not null;default:0;comment:价格"`
|
||||
SalePrice int64 `json:"sale_price" gorm:"not null;default:0;comment:书价"`
|
||||
Cost int64 `json:"cost" gorm:"not null;default:0;comment:最低运费"`
|
||||
LiveImage datatypes.JSON `json:"live_image" gorm:"type:json;not null;comment:实拍图json"`
|
||||
IsBatchManaged int8 `json:"is_batch_managed" gorm:"type:tinyint(1);not null;default:0;comment:是否批次管理(0:否,1:是)"`
|
||||
IsShelfLifeManaged int8 `json:"is_shelf_life_managed" gorm:"type:tinyint(1);not null;default:0;comment:是否效期管理(0:否,1:是)"`
|
||||
Status int8 `json:"status" gorm:"type:tinyint(1);not null;default:1;comment:状态(0:禁用,1:启用)"`
|
||||
CreatedAt int64 `json:"created_at" gorm:"type:bigint;not null;default:0;comment:创建时间戳"`
|
||||
UpdatedAt int64 `json:"updated_at" gorm:"type:bigint;not null;default:0;comment:更新时间戳"`
|
||||
IsDel int8 `json:"is_del" gorm:"not null;default:0;comment:逻辑删除"`
|
||||
}
|
||||
|
||||
func (ProductBook) TableName() string {
|
||||
return "product_book_00"
|
||||
}
|
||||
|
||||
func (ProductBook) TableOptions() string {
|
||||
return "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='商品书籍分表'"
|
||||
}
|
||||
|
||||
// ProductBookTableName 根据ISBN后两位获取分表名
|
||||
func ProductBookTableName(isbn string) string {
|
||||
suffix := "00"
|
||||
if len(isbn) >= 2 {
|
||||
suffix = isbn[len(isbn)-2:]
|
||||
}
|
||||
return fmt.Sprintf("product_book_%s", suffix)
|
||||
}
|
||||
|
||||
// ProductBookAllTableNames 获取所有分表名(00~99)
|
||||
func ProductBookAllTableNames() []string {
|
||||
names := make([]string, 0, 100)
|
||||
for i := 0; i < 100; i++ {
|
||||
names = append(names, fmt.Sprintf("product_book_%02d", i))
|
||||
}
|
||||
return names
|
||||
}
|
||||
@ -44,13 +44,13 @@ type GroupConfig struct {
|
||||
}
|
||||
|
||||
type UpdateLocationRequest struct {
|
||||
WarehouseID int64 `form:"warehouse_id" binding:"required"`
|
||||
IDs []int64 `form:"ids[]"`
|
||||
Code string `form:"code"`
|
||||
Type *int8 `form:"type"`
|
||||
Capacity *int64 `form:"capacity"`
|
||||
Sort *int `form:"sort"`
|
||||
Status *int8 `form:"status"`
|
||||
WarehouseID int64 `form:"warehouse_id" binding:"required"` // 仓库ID
|
||||
IDs []int64 `form:"ids[]"` // 库位ID
|
||||
Code string `form:"code"` // 库位编码
|
||||
Type *int8 `form:"type"` // 库位类型
|
||||
Capacity *int64 `form:"capacity"` // 库位容量
|
||||
Sort *int `form:"sort"` // 库位排序
|
||||
Status *int8 `form:"status"` // 库位状态
|
||||
}
|
||||
|
||||
type DeleteLocationRequest struct {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user