From f2cdd37d118b4c1f55c21ccdd511c0e6ccec9208 Mon Sep 17 00:00:00 2001
From: jiangshuai <291802688@qq.com>
Date: 星期二, 19 九月 2023 19:56:06 +0800
Subject: [PATCH] 1.获取入库列表、修改入库信息接口服务。

---
 models/operation.go |   47 +++++++++++++++++++++++++++++++++++------------
 1 files changed, 35 insertions(+), 12 deletions(-)

diff --git a/models/operation.go b/models/operation.go
index 5fa92ad..76b7797 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"
@@ -12,7 +13,7 @@
 	Operation struct {
 		WmsModel
 		Id              int                      `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"`
-		Number          string                   `json:"number" gorm:"column:number;type:varchar(255)"`           //鍗曞彿
+		Number          string                   `json:"number" gorm:"type:varchar(255)"`                         //鍗曞彿
 		SourceNumber    string                   `json:"sourceNumber" gorm:"type:varchar(255)"`                   //婧愬崟鍙�
 		OperationTypeId int                      `json:"operationTypeId" gorm:"type:int;not null;comment:浣滀笟绫诲瀷id"` //浣滀笟绫诲瀷id
 		Status          constvar.OperationStatus `json:"status" gorm:"type:int(11);not null;comment:鐘舵��"`          //鐘舵��
@@ -26,8 +27,8 @@
 		Tracking        string                   `json:"tracking" gorm:"type:varchar(127);comment:杩借釜鍙傝��"`
 		ContacterID     int                      `json:"contacterID" gorm:"type:int;comment:鑱旂郴浜篒D"`
 		ContacterName   string                   `json:"contacterName" gorm:"type:varchar(63);comment:鑱旂郴浜哄鍚�"`
-		Weight          float64                  `json:"weight" gorm:"type:decimal;comment:閲嶉噺(kg)"`
-		TransferWeight  float64                  `json:"transferWeight" gorm:"type:decimal;comment:鐗╂祦閲嶉噺(kg)"`
+		Weight          decimal.Decimal          `json:"weight" gorm:"type:decimal(20,2);comment:閲嶉噺(kg)"`
+		TransferWeight  decimal.Decimal          `json:"transferWeight" gorm:"type:decimal(20,2);comment:鐗╂祦閲嶉噺(kg)"`
 		CompanyID       int                      `json:"companyID" gorm:"type:int;comment:鍏徃ID"`
 		CompanyName     string                   `json:"companyName" gorm:"type:varchar(127);comment:鍏徃鍚嶇О(kg)"`
 		Details         []*OperationDetails      `json:"details"`
@@ -67,13 +68,18 @@
 	return slf
 }
 
-func (slf *OperationSearch) SetID(id uint) *OperationSearch {
-	slf.ID = id
+func (slf *OperationSearch) SetID(id int) *OperationSearch {
+	slf.Id = id
 	return slf
 }
 
-func (slf *OperationSearch) SetKeyword(keyword string) *OperationSearch {
-	slf.Keyword = keyword
+//func (slf *OperationSearch) SetKeyword(keyword string) *OperationSearch {
+//	slf.Keyword = keyword
+//	return slf
+//}
+
+func (slf *OperationSearch) SetOperationTypeId(operationTypeId int) *OperationSearch {
+	slf.OperationTypeId = operationTypeId
 	return slf
 }
 
@@ -85,16 +91,23 @@
 func (slf *OperationSearch) build() *gorm.DB {
 	var db = slf.Orm.Model(&Operation{})
 
-	if slf.ID != 0 {
-		db = db.Where("id = ?", slf.ID)
+	if slf.Id != 0 {
+		db = db.Where("id = ?", slf.Id)
 	}
-
 	if slf.Order != "" {
 		db = db.Order(slf.Order)
 	}
 
-	if slf.Keyword != "" {
-		db = db.Where("product_name like ?", fmt.Sprintf("%%%v%%", slf.Keyword))
+	//if slf.Keyword != "" {
+	//	db = db.Where("product_name like ?", fmt.Sprintf("%%%v%%", slf.Keyword))
+	//}
+
+	if slf.OperationTypeId != 0 {
+		db.Where("operation_type_id = ?", slf.OperationTypeId)
+	}
+
+	if slf.Preload {
+		db = db.Model(&Operation{}).Preload("Details")
 	}
 
 	return db
@@ -122,6 +135,16 @@
 	return nil
 }
 
+func (slf *OperationSearch) Save(record *Operation) error {
+	var db = slf.build()
+
+	if err := db.Omit("CreatedAt").Save(record).Error; err != nil {
+		return fmt.Errorf("save err: %v, record: %+v", err, record)
+	}
+
+	return nil
+}
+
 func (slf *OperationSearch) Update(record *Operation) error {
 	var db = slf.build()
 

--
Gitblit v1.8.0