From ec58bf196fb360bfcec35ed784ae9da90ffa3d42 Mon Sep 17 00:00:00 2001
From: jiangshuai <291802688@qq.com>
Date: 星期二, 12 十二月 2023 11:06:50 +0800
Subject: [PATCH] 调整listbycondition接口服务

---
 models/operation.go |   56 ++++++++++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 46 insertions(+), 10 deletions(-)

diff --git a/models/operation.go b/models/operation.go
index 7f17d4a..d076b88 100644
--- a/models/operation.go
+++ b/models/operation.go
@@ -2,6 +2,7 @@
 
 import (
 	"fmt"
+	"github.com/shopspring/decimal"
 	"gorm.io/gorm"
 	"wms/constvar"
 	"wms/pkg/mysqlx"
@@ -27,14 +28,20 @@
 		CompanyID         int                      `json:"companyID" gorm:"type:int;comment:鍏徃ID-瀹㈡埛"`
 		CompanyName       string                   `json:"companyName" gorm:"type:varchar(127);comment:鍏徃鍚嶇О-瀹㈡埛"`
 		Comment           string                   `json:"comment" gorm:"type:text;comment:澶囨敞"`
+		LogisticCompanyId string                   `json:"logisticCompanyId"   gorm:"type:varchar(191);comment:鐗╂祦鍏徃id"`
+		LogisticCompany   LogisticCompany          `json:"logisticCompany"      gorm:"foreignKey:LogisticCompanyId"`
+		WaybillNumber     string                   `json:"waybillNumber" gorm:"type:varchar(255);comment:杩愬崟鍙�"`    //杩愬崟鍙�
+		Weight            decimal.Decimal          `gorm:"type:decimal(20,2);comment:閲嶉噺" json:"weight"`           //閲嶉噺
+		LogisticWeight    decimal.Decimal          `gorm:"type:decimal(20,2);comment:鐗╂祦閲嶉噺" json:"logisticWeight"` //鐗╂祦閲嶉噺
+		Source            string                   `json:"source" gorm:"type:varchar(255);comment:鏉ユ簮绯荤粺,鐢ㄤ簬杩斿洖淇敼鐘舵��"`
 
-		Details []*OperationDetails `json:"details" gorm:"foreignKey:OperationID;references:Id"`
+		Details           []*OperationDetails        `json:"details" gorm:"foreignKey:OperationID;references:Id"`
+		BaseOperationType constvar.BaseOperationType `json:"baseOperationType" gorm:"type:tinyint;not null;comment:鍩虹浣滀笟绫诲瀷"` //鍩虹浣滀笟绫诲瀷
 
-		//Weight          decimal.Decimal          `json:"weight" gorm:"type:decimal(20,2);comment:閲嶉噺(kg)"`
-		//TransferWeight  decimal.Decimal          `json:"transferWeight" gorm:"type:decimal(20,2);comment:鐗╂祦閲嶉噺(kg)"`
-		//CarrierID       int                      `json:"carrierID" gorm:"type:int;comment:鎵胯繍鍟咺D"`
-		//CarrierName     string                   `json:"carrierName" gorm:"type:varchar(63);comment:鎵胯繍鍟嗗悕绉�"`
-		//Tracking        string                   `json:"tracking" gorm:"type:varchar(127);comment:杩借釜鍙傝��"`
+		AuditDate     string `json:"auditDate" gorm:"type:varchar(31);comment:瀹℃壒鏃堕棿"`
+		ReceiverName  string `json:"receiverName" gorm:"type:varchar(31);comment:鏀惰揣浜哄鍚�"`
+		ReceiverPhone string `json:"receiverPhone" gorm:"type:varchar(31);comment:鑱旂郴鐢佃瘽"`
+		ReceiverAddr  string `json:"receiverAddr" gorm:"type:varchar(255);comment:鏀惰揣鍦板潃"`
 	}
 
 	OperationSearch struct {
@@ -46,6 +53,8 @@
 		Orm      *gorm.DB
 		Preload  bool
 		Disuse   bool
+		Ids      []int
+		Numbers  []string
 	}
 )
 
@@ -107,6 +116,21 @@
 	return slf
 }
 
+func (slf *OperationSearch) SetIds(ids []int) *OperationSearch {
+	slf.Ids = ids
+	return slf
+}
+
+func (slf *OperationSearch) SetStatus(status constvar.OperationStatus) *OperationSearch {
+	slf.Status = status
+	return slf
+}
+
+func (slf *OperationSearch) SetBaseOperationType(baseOperationType constvar.BaseOperationType) *OperationSearch {
+	slf.BaseOperationType = baseOperationType
+	return slf
+}
+
 func (slf *OperationSearch) build() *gorm.DB {
 	var db = slf.Orm.Model(&Operation{})
 
@@ -118,7 +142,7 @@
 	}
 
 	if slf.Keyword != "" {
-		db = db.Where("product_name like ?", fmt.Sprintf("%%%v%%", slf.Keyword))
+		db = db.Where("number like ? or source_number like ?", fmt.Sprintf("%%%v%%", slf.Keyword), fmt.Sprintf("%%%v%%", slf.Keyword))
 	}
 
 	if slf.SourceNumber != "" {
@@ -134,11 +158,23 @@
 	}
 
 	if slf.Preload {
-		db = db.Model(&Operation{}).Preload("Details").Preload("Details.Product").Preload("FromLocation").Preload("ToLocation")
+		db = db.Model(&Operation{}).Preload("Details").Preload("Details.Product").Preload("LogisticCompany").Preload("FromLocation").Preload("ToLocation")
 	}
 
 	if slf.Disuse {
 		db = db.Where("operation_type_id = ?", 0)
+	}
+
+	if len(slf.Ids) > 0 {
+		db = db.Where("id in (?)", slf.Ids)
+	}
+
+	if slf.Status > 0 {
+		db = db.Where("status = ?", slf.Status)
+	}
+
+	if slf.BaseOperationType != 0 {
+		db = db.Where("base_operation_type = ?", slf.BaseOperationType)
 	}
 
 	return db
@@ -241,7 +277,7 @@
 	if slf.PageNum*slf.PageSize > 0 {
 		db = db.Offset((slf.PageNum - 1) * slf.PageSize).Limit(slf.PageSize)
 	}
-	if err := db.Find(&records).Error; err != nil {
+	if err := db.Preload("FromLocation").Preload("ToLocation").Order("created_at desc").Find(&records).Error; err != nil {
 		return records, total, fmt.Errorf("find records err: %v", err)
 	}
 
@@ -257,7 +293,7 @@
 	if slf.PageNum*slf.PageSize > 0 {
 		db = db.Offset((slf.PageNum - 1) * slf.PageSize).Limit(slf.PageSize)
 	}
-	if err := db.Find(&records).Error; err != nil {
+	if err := db.Preload("FromLocation").Preload("ToLocation").Find(&records).Error; err != nil {
 		return records, fmt.Errorf("find records err: %v", err)
 	}
 

--
Gitblit v1.8.0