| | |
| | | purchaseNumbers = append(purchaseNumbers, item.Number) |
| | | } |
| | | resultList := make([]*purchaseRes.QualityInspectList, 0, len(purchaseList)) |
| | | if len(purchaseList) == 0 { |
| | | if len(purchaseList) != 0 { |
| | | err = utils.AssignTo(purchaseList, &resultList) |
| | | if err != nil { |
| | | global.GVA_LOG.Error("mapStructure decode", zap.Error(err)) |
| | |
| | | } |
| | | } |
| | | } |
| | | |
| | | response.OkWithDetailed(response.PageResult{ |
| | | List: resultList, |
| | | Total: total, |
| | |
| | | global.GVA_LOG.Error("获取失败!", zap.Error(err)) |
| | | response.FailWithMessage("获取失败", c) |
| | | } else { |
| | | //添加供应商名称 |
| | | for i := 0; i < len(list); i++ { |
| | | list[i].SupplierName = list[i].Supplier.Name |
| | | } |
| | | response.OkWithDetailed(response.PageResult{ |
| | | List: list, |
| | | Total: total, |
| | |
| | | MinimumStock int `json:"minimumStock" form:"minimumStock" gorm:"column:minimum_stock;comment:最低库存;"` |
| | | MaximumStock int `json:"maximumStock" form:"maximumStock" gorm:"column:maximum_stock;comment:最高库存;"` |
| | | Remark string `json:"remark" form:"remark" gorm:"column:remark;comment:备注;size:255;"` |
| | | SupplierName string `json:"supplierName" gorm:"-"` |
| | | } |
| | | |
| | | // TableName Product 表名 |
| | |
| | | limit := info.PageSize |
| | | offset := info.PageSize * (info.Page - 1) |
| | | db := global.GVA_DB.Model(&purchase.Purchase{}) |
| | | var ids []uint |
| | | var purchaseList = make([]*purchase.Purchase, 0) |
| | | if info.Keyword != "" { |
| | | db.Distinct("purchases.id").Joins("left join purchase_products on purchase_products.purchase_id = purchases.id"). |
| | | Joins("left join Product on Product.Id = purchase_products.product_id"). |
| | |
| | | Where("purchases.name like ?", "%"+info.Keyword+"%"). |
| | | Or("Product.name like ?", "%"+info.Keyword+"%"). |
| | | Or("supplier.name like ?", "%"+info.Keyword+"%") |
| | | err = db.Limit(limit).Offset(offset).Find(&ids).Error |
| | | if err != nil { |
| | | return purchaseList, total, err |
| | | } |
| | | } |
| | | var purchaseList []*purchase.Purchase |
| | | |
| | | err = db.Count(&total).Error |
| | | if err != nil { |
| | | return purchaseList, total, err |
| | | } |
| | | err = db.Limit(limit).Offset(offset).Find(&purchaseList).Error |
| | | if len(ids) != 0 { |
| | | db = global.GVA_DB.Model(&purchase.Purchase{}) |
| | | err = db.Where("id in (?)", ids).Find(&purchaseList).Error |
| | | } else { |
| | | err = db.Limit(limit).Offset(offset).Find(&purchaseList).Error |
| | | } |
| | | |
| | | return purchaseList, total, err |
| | | } |
| | | |