zhangqian
2024-04-07 a8914a16b23e93f6bfd12bcfd5cbe8b24cf7eb84
models/location.go
@@ -26,6 +26,9 @@
      RecentlyCount        string                        `json:"recentlyCount" gorm:"type:varchar(255);comment:最近盘点"`   //最近盘点
      NextCount            string                        `json:"nextCount" gorm:"type:varchar(255);comment:下次盘点"`       //下次盘点
      JointName            string                        `json:"jointName" gorm:"type:varchar(255);comment:拼接名称"`       //拼接名称
      Children             []*Location                   `json:"children" gorm:"-"`
      WarehouseId          int                           `json:"warehouseId" gorm:"type:int;not null;default:0;comment:仓库ID"` //仓库ID
      Warehouse            Warehouse                     `json:"warehouse" gorm:"foreignKey:WarehouseId"`                     //仓库
   }
   LocationSearch struct {
@@ -37,6 +40,7 @@
      Orm        *gorm.DB
      Preload    bool
      JointNames []string
      Ids        []int
   }
)
@@ -65,6 +69,11 @@
func (slf *LocationSearch) SetID(ID int) *LocationSearch {
   slf.Id = ID
   return slf
}
func (slf *LocationSearch) SetIds(ids []int) *LocationSearch {
   slf.Ids = ids
   return slf
}
@@ -108,11 +117,20 @@
   return slf
}
func (slf *LocationSearch) SetIsScrapLocation(isScrapLocation bool) *LocationSearch {
   slf.IsScrapLocation = isScrapLocation
   return slf
}
func (slf *LocationSearch) build() *gorm.DB {
   var db = slf.Orm.Table(slf.TableName())
   if slf.Id != 0 {
      db = db.Where("id = ?", slf.Id)
   }
   if len(slf.Ids) > 0 {
      db = db.Where("id in (?)", slf.Ids)
   }
   if slf.Order != "" {
@@ -142,6 +160,14 @@
   }
   if len(slf.JointNames) != 0 {
      db = db.Where("joint_name in (?)", slf.JointNames)
   }
   if slf.IsScrapLocation {
      db = db.Where("is_scrap_location = ?", slf.IsScrapLocation)
   }
   if slf.Preload {
      db = db.Preload("Warehouse")
   }
   return db
@@ -337,7 +363,7 @@
   locations = append(locations, &Location{Name: "库存损失", Type: 5, JointName: "库存损失"})
   locations = append(locations, &Location{Name: "生产", Type: 6, JointName: "生产"})
   locations = append(locations, &Location{Name: "中转位置", Type: 7, JointName: "中转位置"})
   locations = append(locations, &Location{Name: "报废位置", Type: 8, JointName: "报废位置"})
   locations = append(locations, &Location{Name: "报废位置", Type: 8, JointName: "报废位置", IsScrapLocation: true})
   locations = append(locations, &Location{Name: "库存盘点", Type: 9, JointName: "库存盘点"})
   return slf.CreateBatch(locations)
}