100 lines
3.4 KiB
Go
Executable File
100 lines
3.4 KiB
Go
Executable File
package model
|
||
|
||
import (
|
||
"time"
|
||
|
||
"gorm.io/gorm"
|
||
)
|
||
|
||
// {
|
||
// id: "1",
|
||
// fileName: "上游合同-铜矿采购-2024-001.pdf",
|
||
// fileType: "pdf",
|
||
// fileSize: "2.3MB",
|
||
// uploadTime: "2024-01-20",
|
||
// folderId: "1",
|
||
// contractNumber: "SC2024001",
|
||
// companyName: "中尚鹏贸易有限公司",
|
||
// commodity: "铜矿",
|
||
// signDate: "2024-01-15",
|
||
// contractType: "upstream"
|
||
// }
|
||
|
||
type ZSPContractFolder struct {
|
||
ID uint `gorm:"primaryKey" json:"id"`
|
||
Name string `gorm:"size:100" json:"name"`
|
||
Count int `json:"count"`
|
||
CreateTime time.Time `json:"createTime"`
|
||
Description string `gorm:"size:255" json:"description"`
|
||
|
||
Files []ZSPContractFile `gorm:"foreignKey:FolderID" json:"files"`
|
||
}
|
||
|
||
type ZSPContractFile struct {
|
||
ID uint `gorm:"primaryKey" json:"id"`
|
||
FileName string `gorm:"size:255" json:"fileName"`
|
||
FileURL string `gorm:"size:500" json:"fileUrl"`
|
||
FileType string `gorm:"size:50" json:"fileType"`
|
||
FileSize int64 `json:"fileSize"`
|
||
UploadTime time.Time `json:"uploadTime"`
|
||
|
||
FolderID uint `gorm:"index" json:"folderId"`
|
||
Folder ZSPContractFolder `gorm:"foreignKey:FolderID" json:"folder"`
|
||
|
||
ContractNumber string `gorm:"size:50" json:"contractNumber"`
|
||
CompanyName string `gorm:"size:100" json:"companyName"`
|
||
Commodity string `gorm:"size:100" json:"commodity"`
|
||
SignDate time.Time `json:"signDate"`
|
||
ContractType string `gorm:"size:50" json:"contractType"`
|
||
|
||
// 合同详情
|
||
Details []ZSPContractDetail `gorm:"foreignKey:ContractFileID" json:"details"`
|
||
}
|
||
|
||
// ZSPContractDetail 合同详情表(商品明细)
|
||
type ZSPContractDetail struct {
|
||
ID uint `gorm:"primaryKey" json:"id"`
|
||
ContractFileID uint `gorm:"index;not null" json:"contractFileId"`
|
||
ContractFile ZSPContractFile `gorm:"foreignKey:ContractFileID" json:"contractFile"`
|
||
|
||
// 商品信息
|
||
CommodityName string `gorm:"size:100;not null" json:"commodityName"` // 商品名称
|
||
CommodityCode string `gorm:"size:50" json:"commodityCode"` // 商品编码
|
||
|
||
// 数量信息
|
||
TotalQuantity float64 `gorm:"not null" json:"totalQuantity"` // 合同总量
|
||
Unit string `gorm:"size:20;default:'吨'" json:"unit"` // 单位
|
||
|
||
// 价格信息
|
||
UnitPrice float64 `gorm:"not null" json:"unitPrice"` // 单价
|
||
|
||
// 提货信息
|
||
DeliveredQty float64 `gorm:"default:0" json:"deliveredQty"` // 已提货数量
|
||
PendingQty float64 `gorm:"default:0" json:"pendingQty"` // 应提货数量(自动计算 = 总量 - 已提货)
|
||
|
||
// 提单信息
|
||
BillOfLading string `gorm:"size:100" json:"billOfLading"` // 提单号
|
||
|
||
// 备注
|
||
Remark string `gorm:"size:500" json:"remark"`
|
||
|
||
// 时间戳
|
||
CreateTime time.Time `json:"createTime"`
|
||
UpdateTime time.Time `json:"updateTime"`
|
||
}
|
||
|
||
// BeforeCreate GORM钩子,在创建前自动计算应提货数量
|
||
func (d *ZSPContractDetail) BeforeCreate(tx *gorm.DB) error {
|
||
d.PendingQty = d.TotalQuantity - d.DeliveredQty
|
||
d.CreateTime = time.Now()
|
||
d.UpdateTime = time.Now()
|
||
return nil
|
||
}
|
||
|
||
// BeforeUpdate GORM钩子,在更新前自动计算应提货数量
|
||
func (d *ZSPContractDetail) BeforeUpdate(tx *gorm.DB) error {
|
||
d.PendingQty = d.TotalQuantity - d.DeliveredQty
|
||
d.UpdateTime = time.Now()
|
||
return nil
|
||
}
|