jiangshuai
2023-11-14 22a93375823a1fe58e5ca2dcd0545ddf1dfc883c
models/material.go
@@ -67,9 +67,14 @@
      //HSCode                  string                     `gorm:"type:varchar(255);comment:HS编码" json:"HSCode"`                    //HS编码
      //OriginCountryId         int                        `gorm:"type:int(11);comment:原产地id" json:"originCountryId"`               //原产地id
      //OriginCountryName       string                     `gorm:"type:varchar(255);comment:原产地名称" json:"originCountryName"`        //原产地名称
      InStorageExplain        string `gorm:"type:varchar(512);comment:入库说明" json:"inStorageExplain"`          //入库说明
      OutStorageExplain       string `gorm:"type:varchar(512);comment:出库说明" json:"outStorageExplain"`         //出库说明
      InternalTransferExplain string `gorm:"type:varchar(512);comment:内部调拨说明" json:"internalTransferExplain"` //内部调拨说明
      InStorageExplain        string          `gorm:"type:varchar(512);comment:入库说明" json:"inStorageExplain"`          //入库说明
      OutStorageExplain       string          `gorm:"type:varchar(512);comment:出库说明" json:"outStorageExplain"`         //出库说明
      InternalTransferExplain string          `gorm:"type:varchar(512);comment:内部调拨说明" json:"internalTransferExplain"` //内部调拨说明
      AttachmentList          []*Attachment   `json:"attachmentList" gorm:"many2many:material_attachment"`
      AttachmentIDs           []uint          `json:"attachmentIDs" gorm:"-"`
      PredictionAmount        decimal.Decimal `json:"predictionAmount" gorm:"-"`
      InputAmount             decimal.Decimal `json:"inputAmount" gorm:"-"`
      OutputAmount            decimal.Decimal `json:"outputAmount" gorm:"-"`
   }
   MaterialSearch struct {
@@ -83,6 +88,7 @@
      Ids         []string
      Orm         *gorm.DB
      CategoryIds []int
      Preload     bool
   }
   IdAndName struct {
@@ -174,6 +180,11 @@
//   return slf
//}
func (slf *MaterialSearch) SetPreload(preload bool) *MaterialSearch {
   slf.Preload = preload
   return slf
}
func (slf *MaterialSearch) build() *gorm.DB {
   var db = slf.Orm.Table(slf.TableName())
@@ -238,6 +249,10 @@
   }
   if len(slf.CategoryIds) > 0 {
      db = db.Where("category_id in ?", slf.CategoryIds)
   }
   if slf.Preload {
      db = db.Preload("AttachmentList")
   }
   return db
@@ -329,7 +344,7 @@
      db      = slf.build()
   )
   if err := db.Count(&total).Error; err != nil {
   if err := db.Model(&Material{}).Count(&total).Error; err != nil {
      return records, total, fmt.Errorf("find count err: %v", err)
   }
   if slf.PageNum*slf.PageSize > 0 {