You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

55 lines
1.5 KiB
Go

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

// Package model -----------------------------
// @file : container.go
// @author : JJXu
// @contact : wavingbear@163.com
// @time : 2024/7/1 上午11:47
// -------------------------------------------
package model
import (
"github.com/fonchain/fonchain-container/pkg/util"
"gorm.io/gorm"
)
// Container 货柜
type Container struct {
Model
ContainerUid string `gorm:"column:container_uid;comment:货柜编号"`
Name string `gorm:"column:name;comment:货柜名称"`
ColumnLen int `gorm:"column:column_len;comment:货柜列数"`
RowLen int `gorm:"column:row_len;comment:货柜行数"`
}
func (c Container) TableName() string {
return "container"
}
func (c *Container) BeforeCreate(tx *gorm.DB) (err error) {
if c.ContainerUid == "" {
c.ContainerUid, err = util.GetUid()
}
return nil
}
// func (d *Device) BeforeCreate(tx *gorm.DB) error {
// // 获取当前日期格式化为yyMMdd
// currentDate := time.Now().Format(stime.Format_NoSpacer_YMD)
//
// // 生成一个4位的随机序列号范围0000-9999
// randomSeq := fmt.Sprintf("%04d", rand.Intn(10000))
//
// // 构造SN号主体部分
// sn := currentDate + productCode + randomSeq
//
// // 计算校验位这里简单使用所有字符ASCII值之和对11取模
// var checkSum int
// for _, char := range sn {
// checkSum += int(char)
// }
// checkSum %= 11
// checkSumStr := fmt.Sprintf("%01d", checkSum)
//
// // 返回完整的SN号包括校验位
// d.SN = sn + checkSumStr
// return nil
// }