From f6bf0ee81b080a2bad55aa5bf261c68ab3d555f8 Mon Sep 17 00:00:00 2001 From: jiangshuai <291802688@qq.com> Date: 星期二, 19 十二月 2023 18:57:43 +0800 Subject: [PATCH] 新增共用id结构体 --- service/purchase/purchase.go | 37 +++++++++++++++++++++++++------------ 1 files changed, 25 insertions(+), 12 deletions(-) diff --git a/service/purchase/purchase.go b/service/purchase/purchase.go index 58a6e2d..fb3db12 100644 --- a/service/purchase/purchase.go +++ b/service/purchase/purchase.go @@ -7,8 +7,8 @@ "github.com/spf13/cast" "gorm.io/gorm" "srm/global" - "srm/model/common/request" "srm/model/purchase" + purchaserequest "srm/model/purchase/request" "srm/proto/qualityinspect" "srm/service/test" ) @@ -123,7 +123,7 @@ //@param: info request.PageInfo //@return: list interface{}, total int64, err error -func (slf *PurchaseService) GetPurchaseList(info request.PageInfo) (list interface{}, total int64, err error) { +func (slf *PurchaseService) GetPurchaseList(info purchaserequest.PurchaseSearch) (list interface{}, total int64, err error) { limit := info.PageSize offset := info.PageSize * (info.Page - 1) db := global.GVA_DB.Model(&purchase.Purchase{}) @@ -131,26 +131,28 @@ var purchaseList = make([]*purchase.Purchase, 0) if info.Keyword != "" { db.Distinct("srm_purchase.id").Joins("left join srm_purchase_products on srm_purchase_products.purchase_id = srm_purchase.id"). - Joins("left join srm_product on srm_product.Id = srm_purchase_products.product_id"). + Joins("left join srm_supplier_material on srm_supplier_material.supplier_id = srm_purchase.id"). Joins("left join srm_supplier on srm_supplier.Id = srm_purchase.supplier_id"). Where("srm_purchase.name like ?", "%"+info.Keyword+"%"). - Or("srm_product.name like ?", "%"+info.Keyword+"%"). + Or("srm_supplier_material.name like ?", "%"+info.Keyword+"%"). Or("srm_supplier.name like ?", "%"+info.Keyword+"%") err = db.Limit(limit).Offset(offset).Find(&ids).Error if err != nil { return purchaseList, total, err } + } else if info.SupplierId != 0 { + db = db.Where("supplier_id = ?", info.SupplierId) } - err = db.Count(&total).Error - if err != nil { + if err != nil || total == 0 { return purchaseList, total, err } if len(ids) != 0 { db = global.GVA_DB.Model(&purchase.Purchase{}) - err = db.Where("id in (?)", ids).Find(&purchaseList).Error + err = db.Where("id in (?)", ids).Preload("Supplier").Order("updated_at desc").Find(&purchaseList).Error } else { - err = db.Limit(limit).Offset(offset).Find(&purchaseList).Error + //db = global.GVA_DB.Model(&purchase.Purchase{}) + err = db.Limit(limit).Offset(offset).Preload("Supplier").Order("updated_at desc").Find(&purchaseList).Error } return purchaseList, total, err @@ -173,7 +175,7 @@ //@param: id uint //@return: err error -func (slf *PurchaseService) Submit(id int, status purchase.OrderStatus) (err error) { +func (slf *PurchaseService) Submit(id int, status purchase.OrderStatus, warehouse string) (err error) { //purchaseData, err := slf.GetPurchase(id) //if err != nil { @@ -189,7 +191,12 @@ // targetStatus = purchase.OrderStatusCompleted //} err = global.GVA_DB.Transaction(func(tx *gorm.DB) error { - err = tx.Where("id = ?", id).Model(&purchase.Purchase{}).Updates(map[string]interface{}{"status": status}).Error + m := make(map[string]interface{}) + m["status"] = status + if warehouse != "" { + m["warehouse"] = warehouse + } + err = tx.Where("id = ?", id).Model(&purchase.Purchase{}).Updates(m).Error if err != nil { return err } @@ -212,7 +219,7 @@ } productIds := make([]uint, 0, len(productList)) for _, product := range productList { - productIds = append(productIds, uint(product.ProductId)) + productIds = append(productIds, product.ID) } productService := &test.ProductService{} _, productMap, err := productService.GetProducts(productIds) @@ -221,7 +228,7 @@ } inspectOrders := make([]*qualityinspect.QualityInspect, 0, len(productList)) for _, productItem := range productList { - product := productMap[uint(productItem.ProductId)] + product := productMap[productItem.ID] if product == nil { continue } @@ -290,3 +297,9 @@ err = db.Order("pin desc, sort desc, id asc").Find(&list).Error return list, err } + +func (slf *PurchaseService) MaxAutoIncr() (int, error) { + var total int64 + err := global.GVA_DB.Model(&purchase.Purchase{}).Count(&total).Error + return int(total), err +} -- Gitblit v1.8.0