| | |
| | | |
| | | LocationSearch struct { |
| | | Location |
| | | Order string |
| | | PageNum int |
| | | PageSize int |
| | | Keyword string |
| | | Orm *gorm.DB |
| | | Preload bool |
| | | Codes []string |
| | | Order string |
| | | PageNum int |
| | | PageSize int |
| | | Keyword string |
| | | Orm *gorm.DB |
| | | Preload bool |
| | | JointNames []string |
| | | } |
| | | ) |
| | | |
| | |
| | | slf.Id = ID |
| | | return slf |
| | | } |
| | | func (slf *LocationSearch) SetCodes(ids []string) *LocationSearch { |
| | | slf.Codes = ids |
| | | |
| | | func (slf *LocationSearch) SetJointName(code string) *LocationSearch { |
| | | slf.JointName = code |
| | | return slf |
| | | } |
| | | |
| | | func (slf *LocationSearch) SetJointNames(codes []string) *LocationSearch { |
| | | slf.JointNames = codes |
| | | return slf |
| | | } |
| | | |
| | |
| | | if slf.CompanyId != 0 { |
| | | db = db.Where("company_id=?", slf.CompanyId) |
| | | } |
| | | if len(slf.Codes) != 0 { |
| | | db = db.Where("warehouse_code in (?)", slf.Codes) |
| | | if slf.JointName != "" { |
| | | db = db.Where("joint_name like ?", slf.JointName+"%") |
| | | } |
| | | if len(slf.JointNames) != 0 { |
| | | db = db.Where("joint_name in (?)", slf.JointNames) |
| | | } |
| | | |
| | | return db |
| | |
| | | } |
| | | return records, nil |
| | | } |
| | | |
| | | // InitDefaultData 初始化数据 |
| | | func (slf *LocationSearch) InitDefaultData() error { |
| | | var ( |
| | | db = slf.Orm.Table(slf.TableName()) |
| | | total int64 = 0 |
| | | ) |
| | | if err := db.Count(&total).Error; err != nil { |
| | | return err |
| | | } |
| | | if total != 0 { |
| | | return nil |
| | | } |
| | | locations := make([]*Location, 0) |
| | | locations = append(locations, &Location{Name: "供应商位置", Type: 1, JointName: "供应商位置"}) |
| | | locations = append(locations, &Location{Name: "视图", Type: 2, JointName: "视图"}) |
| | | locations = append(locations, &Location{Name: "客户位置", Type: 4, JointName: "客户位置"}) |
| | | 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: 9, JointName: "库存盘点"}) |
| | | return slf.CreateBatch(locations) |
| | | } |