| | |
| | | package models |
| | | |
| | | import ( |
| | | "encoding/json" |
| | | "fmt" |
| | | "github.com/shopspring/decimal" |
| | | "gorm.io/gorm" |
| | |
| | | // FinenessCheckItem 纤度检验明细 |
| | | FinenessCheckItem struct { |
| | | gorm.Model |
| | | FinenessRegisterID uint `gorm:"not null;comment:纤度登记表ID" json:"finenessRegisterID"` //纤度登记表ID |
| | | FinenessCheckID uint `gorm:"not null;comment:纤度检验表ID" json:"finenessCheckID"` //纤度检验表ID |
| | | Position int `json:"position"` //车号 |
| | | FinenessRoundingItem []*FinenessRoundingItem |
| | | Deviation decimal.Decimal `gorm:"type:decimal(12,2);not null;comment:偏差" json:"deviation"` //偏差 |
| | | TotalDeviation decimal.Decimal `gorm:"type:decimal(12,2);not null;comment:总差" json:"totalDeviation"` //总差 |
| | | FinenessGrade string `gorm:"type:varchar(255);not null;comment:纤度等级" json:"finenessGrade"` //纤度等级 |
| | | Cleanliness decimal.Decimal `gorm:"type:varchar(255);not null;comment:清洁度" json:"cleanliness"` //清洁度 |
| | | Purity decimal.Decimal `gorm:"type:varchar(255);not null;comment:洁净度" json:"purity"` //洁净度 |
| | | TwiceChange decimal.Decimal `gorm:"type:varchar(255);not null;comment:二度变化" json:"twiceChange"` //二度变化 |
| | | Remark string `gorm:"type:varchar(255);not null;comment:备注" json:"remark"` //备注 |
| | | FinenessRegisterID uint `gorm:"not null;comment:纤度登记表ID" json:"finenessRegisterID"` //纤度登记表ID |
| | | //FinenessCheckID uint `gorm:"not null;comment:纤度检验表ID" json:"finenessCheckID"` //纤度检验表ID |
| | | Position int `json:"position"` //车号 |
| | | FinenessRoundingItems []*FinenessRoundingItem `json:"finenessRoundingItems" gorm:"-"` //纤度列表 |
| | | FinenessRounding string `json:"-"` |
| | | Deviation decimal.Decimal `gorm:"type:decimal(12,2);not null;comment:偏差" json:"deviation"` //偏差 |
| | | TotalDeviation decimal.Decimal `gorm:"type:decimal(12,2);not null;comment:总差" json:"totalDeviation"` //总差 |
| | | FinenessGrade string `gorm:"type:varchar(255);not null;comment:纤度等级" json:"finenessGrade"` //纤度等级 |
| | | Cleanliness decimal.Decimal `gorm:"type:varchar(255);not null;comment:清洁度" json:"cleanliness"` //清洁度 |
| | | Purity decimal.Decimal `gorm:"type:varchar(255);not null;comment:洁净度" json:"purity"` //洁净度 |
| | | TwiceChange decimal.Decimal `gorm:"type:varchar(255);not null;comment:二度变化" json:"twiceChange"` //二度变化 |
| | | Remark string `gorm:"type:varchar(255);not null;default:'';comment:备注" json:"remark"` //备注 |
| | | } |
| | | |
| | | FinenessRoundingItem struct { |
| | |
| | | ) |
| | | |
| | | func (slf *FinenessCheckItem) TableName() string { |
| | | return "fineness_check" |
| | | return "fineness_check_item" |
| | | } |
| | | |
| | | func (slf *FinenessCheckItem) AfterFind(tx *gorm.DB) error { |
| | | if slf.FinenessRounding != "" { |
| | | items := make([]*FinenessRoundingItem, 0) |
| | | err := json.Unmarshal([]byte(slf.FinenessRounding), &items) |
| | | if err != nil { |
| | | return err |
| | | } |
| | | slf.FinenessRoundingItems = items |
| | | } |
| | | return nil |
| | | } |
| | | |
| | | func (slf *FinenessCheckItem) BeforeCreate(tx *gorm.DB) error { |
| | | if len(slf.FinenessRoundingItems) > 0 { |
| | | bts, err := json.Marshal(slf.FinenessRoundingItems) |
| | | if err != nil { |
| | | return err |
| | | } |
| | | slf.FinenessRounding = string(bts) |
| | | } |
| | | return nil |
| | | } |
| | | |
| | | func NewFinenessCheckItemSearch() *FinenessCheckItemSearch { |
| | |
| | | return slf |
| | | } |
| | | |
| | | func (slf *FinenessCheckItemSearch) SetFinenessRegisterID(id uint) *FinenessCheckItemSearch { |
| | | slf.FinenessRegisterID = id |
| | | return slf |
| | | } |
| | | |
| | | func (slf *FinenessCheckItemSearch) build() *gorm.DB { |
| | | var db = slf.Orm.Table(slf.TableName()) |
| | | |
| | |
| | | db = db.Where("id = ?", slf.ID) |
| | | } |
| | | |
| | | if slf.FinenessRegisterID != 0 { |
| | | db = db.Where("fineness_register_id = ?", slf.FinenessRegisterID) |
| | | } |
| | | |
| | | if slf.Order != "" { |
| | | db = db.Order(slf.Order) |
| | | } |