From f5e4814599288c39ab9018ca96c50b635ca8cbc5 Mon Sep 17 00:00:00 2001
From: jiangshuai <291802688@qq.com>
Date: 星期二, 12 十二月 2023 14:07:28 +0800
Subject: [PATCH] 调整listbycondition接口服务
---
models/operation_type.go | 49 ++++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 48 insertions(+), 1 deletions(-)
diff --git a/models/operation_type.go b/models/operation_type.go
index acb9c79..4857259 100644
--- a/models/operation_type.go
+++ b/models/operation_type.go
@@ -18,6 +18,7 @@
Company Company `json:"company" gorm:"foreignKey:CompanyId"` //鍏徃
WarehouseId int `json:"warehouseId" gorm:"type:int;not null;comment:浠撳簱id"` //浠撳簱id
Warehouse Warehouse `json:"warehouse" gorm:"foreignKey:WarehouseId"` //浠撳簱
+ Prefix string `json:"prefix" gorm:"type:varchar(255);comment:鍓嶇紑"` //鍓嶇紑
DefaultLocationSrcId int `json:"defaultLocationSrcId" gorm:"type:int;not null;comment:榛樿婧愪綅缃甶d"` //榛樿婧愪綅缃甶d
DefaultLocationSrc Location `json:"defaultLocationSrc" gorm:"foreignKey:DefaultLocationSrcId"` //榛樿婧愪綅缃�
@@ -29,9 +30,13 @@
ReservationDaysBefore int `json:"reservationDaysBefore" gorm:"type:int;"` //鏀惰揣鍓嶅嚑澶�
ReservationDaysBeforePriority int `json:"ReservationDaysBeforePriority" gorm:"type:int;"` //鍦ㄤ紭鍏堢骇鐨勫墠鍑犲ぉ
ShowOperations bool `json:"showOperations" gorm:"column:show_operations;type:int"` //鏄剧ず浣滀笟璇︽儏
+ EarlyOperations bool `json:"earlyOperations" gorm:"type:int;comment:棰勫~鍐欎綔涓氳鎯�"` //棰勫~鍐欎綔涓氳鎯�
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:"-"` //瀹屾垚鏁伴噺
+ CancelCount int `json:"cancelCount" gorm:"-"` //鍙栨秷鏁伴噺
}
OperationTypeSearch struct {
@@ -43,10 +48,16 @@
Orm *gorm.DB
Preload bool
}
+
+ OperationTypeByStatus struct {
+ Id int `gorm:"column:id"`
+ Status constvar.OperationStatus `gorm:"column:status"`
+ Count int `gorm:"column:count"`
+ }
)
func (slf *OperationType) TableName() string {
- return "job_type"
+ return "wms_job_type"
}
func NewOperationTypeSearch() *OperationTypeSearch {
@@ -88,6 +99,16 @@
return slf
}
+func (slf *OperationTypeSearch) SetBaseOperationType(baseOperationType constvar.BaseOperationType) *OperationTypeSearch {
+ slf.BaseOperationType = baseOperationType
+ 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{})
@@ -109,6 +130,14 @@
if slf.Preload {
db = db.Preload("Company").Preload("Warehouse").Preload("DefaultLocationSrc").Preload("DefaultLocationDest")
+ }
+
+ if slf.WarehouseId > 0 {
+ db = db.Where("warehouse_id = ?", slf.WarehouseId)
+ }
+
+ if int(slf.BaseOperationType) != 0 {
+ db = db.Where("base_operation_type = ?", slf.BaseOperationType)
}
return db
@@ -261,3 +290,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