From 96844c22ef3fba86a55e0af1b51bc1009d6fa950 Mon Sep 17 00:00:00 2001
From: jiangshuai <291802688@qq.com>
Date: 星期五, 20 十月 2023 11:57:48 +0800
Subject: [PATCH] 1.库存盘点bug修改

---
 models/operation_type.go |   35 +++++++++++++++++++++++++++++++++++
 1 files changed, 35 insertions(+), 0 deletions(-)

diff --git a/models/operation_type.go b/models/operation_type.go
index b97e0b0..5c1c4b3 100644
--- a/models/operation_type.go
+++ b/models/operation_type.go
@@ -34,6 +34,8 @@
 		CreateBackorder               constvar.WhetherType       `json:"createBackorder" gorm:"column:create_backorder"`                 //鍒涘缓娆犲崟
 		ReturnOperationTypeID         int                        `json:"returnOperationTypeID" gorm:"column:return_job_type_id"`         //閫�璐х被鍨婭D
 		ReturnOperationType           string                     `json:"returnOperationType" gorm:"-"`                                   //閫�璐х被鍨嬪悕绉�
+		ReadyCount                    int                        `json:"readyCount" gorm:"-"`                                            //灏辩华鏁伴噺
+		FinishCount                   int                        `json:"finishCount" gorm:"-"`                                           //瀹屾垚鏁伴噺
 	}
 
 	OperationTypeSearch struct {
@@ -44,6 +46,12 @@
 		Keyword  string
 		Orm      *gorm.DB
 		Preload  bool
+	}
+
+	OperationTypeByStatus struct {
+		Id     int                      `gorm:"column:id"`
+		Status constvar.OperationStatus `gorm:"column:status"`
+		Count  int                      `gorm:"column:count"`
 	}
 )
 
@@ -95,6 +103,11 @@
 	return slf
 }
 
+func (slf *OperationTypeSearch) SetWarehouseId(warehouseId int) *OperationTypeSearch {
+	slf.WarehouseId = warehouseId
+	return slf
+}
+
 func (slf *OperationTypeSearch) build() *gorm.DB {
 	var db = slf.Orm.Model(&OperationType{})
 
@@ -116,6 +129,10 @@
 
 	if slf.Preload {
 		db = db.Preload("Company").Preload("Warehouse").Preload("DefaultLocationSrc").Preload("DefaultLocationDest")
+	}
+
+	if slf.WarehouseId > 0 {
+		db = db.Where("warehouse_id = ?", slf.WarehouseId)
 	}
 
 	return db
@@ -268,3 +285,21 @@
 
 	return records, nil
 }
+
+func (slf *OperationTypeSearch) ListByStatusAndCount(idList []int) ([]*OperationTypeByStatus, error) {
+	var (
+		records = make([]*OperationTypeByStatus, 0)
+		db      = slf.Orm
+	)
+	db = db.Table("wms_job_type").Select("wms_job_type.id,wms_operation.status,count(wms_operation.id) as count").InnerJoins("inner join wms_operation on wms_operation.operation_type_id=wms_job_type.id").Where("wms_operation.deleted_at is null").
+		Group("wms_job_type.id,wms_operation.status")
+	if len(idList) > 0 {
+		db = db.Where("wms_job_type.id IN ?", idList)
+	}
+
+	if err := db.Find(&records).Error; err != nil {
+		return records, fmt.Errorf("func ListByStatusAndCount err: %v, ", err)
+	}
+
+	return records, nil
+}

--
Gitblit v1.8.0