From c4b9d130cb0aa98f4b65a987b11fc5c2bea3a1c7 Mon Sep 17 00:00:00 2001
From: yinbentan <yinbentan@live.com>
Date: 星期三, 03 七月 2024 10:37:25 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/jialian' into jialian
---
models/material.go | 206 +++++++++++++++++++++++++++++++++++++++++----------
1 files changed, 165 insertions(+), 41 deletions(-)
diff --git a/models/material.go b/models/material.go
index 77f3181..e410f35 100644
--- a/models/material.go
+++ b/models/material.go
@@ -1,9 +1,12 @@
package models
import (
+ "encoding/json"
"fmt"
"github.com/shopspring/decimal"
+ "github.com/spf13/cast"
"gorm.io/gorm"
+ "strings"
"wms/constvar"
"wms/pkg/mysqlx"
)
@@ -12,19 +15,19 @@
// Material 鐗╂枡
Material struct {
BaseModelString
- Name string `gorm:"unique;type:varchar(191);not null;comment:鐗╂枡鍚嶇О" json:"name"` //鐗╂枡鍚嶇О
+ Name string `gorm:"type:varchar(191);not null;comment:鐗╂枡鍚嶇О" json:"name"` //鐗╂枡鍚嶇О
//MaterialType constvar.ProductType `gorm:"index;type:int(11);comment:鐗╂枡绫诲瀷(鏁板瓧)" json:"materialType"`
Model constvar.MaterialMode `gorm:"type:varchar(191);not null;comment:鐗╂枡绫诲瀷(瀛楃涓�)" json:"model"` //鐗╂枡绫诲瀷(瀛楃涓�)
//Explain string `gorm:"type:varchar(512);comment:缂栧彿璇存槑" json:"explain"`
- //CodeStandardID string `gorm:"type:varchar(191);comment:缂栫爜瑙勮寖ID" json:"codeStandardID"`
- //Specs string `gorm:"type:varchar(191);comment:鐗╂枡瑙勬牸" json:"specs"`
- //Type string `gorm:"type:varchar(191);comment:鐗╂枡鍨嬪彿" json:"type"`
- MinInventory decimal.Decimal `gorm:"type:decimal(35,18);comment:鏈�灏忓簱瀛�" json:"minInventory"` //鏈�灏忓簱瀛�
- MaxInventory decimal.Decimal `gorm:"type:decimal(35,18);comment:鏈�澶у簱瀛�" json:"maxInventory"` //鏈�澶у簱瀛�
- Amount decimal.Decimal `gorm:"type:decimal(35,18);comment:鏁伴噺" json:"amount"` //鏁伴噺
+ CodeStandardID string `gorm:"type:varchar(191);comment:缂栫爜瑙勮寖ID" json:"codeStandardID"`
+ Specs string `gorm:"type:varchar(191);comment:鐗╂枡瑙勬牸" json:"specs"`
+ Type string `gorm:"type:varchar(191);comment:鐗╂枡鍨嬪彿" json:"type"`
+ MinInventory decimal.Decimal `gorm:"type:decimal(35,18);comment:鏈�灏忓簱瀛�" json:"minInventory"` //鏈�灏忓簱瀛�
+ MaxInventory decimal.Decimal `gorm:"type:decimal(35,18);comment:鏈�澶у簱瀛�" json:"maxInventory"` //鏈�澶у簱瀛�
+ Amount decimal.Decimal `gorm:"type:decimal(35,18);comment:鏁伴噺" json:"amount"` //鏁伴噺
//LockAmount decimal.Decimal `gorm:"type:decimal(35,18);default:0;comment:閿佸畾鏁伴噺" json:"lockAmount"`
- Unit string `gorm:"type:varchar(100);comment:鍗曚綅" json:"unit"` //鍗曚綅
- //Note string `gorm:"type:varchar(1024);comment:澶囨敞" json:"note"`
+ Unit string `gorm:"type:varchar(100);comment:鍗曚綅" json:"unit"` //鍗曚綅
+ Note string `gorm:"type:varchar(1024);comment:澶囨敞" json:"note"`
TemplateID string `gorm:"type:varchar(191);comment:妯℃澘ID" json:"templateID"` //妯℃澘ID
//FSource string `gorm:"type:varchar(191);comment:鐢熶骇杞﹂棿" json:"-"`
//Status constvar.MaterialStatus `gorm:"type:int(11);comment:鐘舵��" json:"status"`
@@ -32,11 +35,13 @@
PurchasePrice decimal.Decimal `gorm:"type:decimal(35,18);comment:閲囪喘浠锋牸" json:"purchasePrice"` //閲囪喘浠锋牸
//PurchaseAheadDay int `gorm:"type:int(11);comment:閲囪喘鎻愬墠鏈�(澶�)" json:"purchaseAheadDay"`
//ProduceAheadDay int `gorm:"type:int(11);comment:鍒堕�犳彁鍓嶆湡(澶�)" json:"produceAheadDay"`
- MinPurchaseAmount decimal.Decimal `gorm:"type:decimal(35,18);comment:鏈�灏忛噰璐噺" json:"minPurchaseAmount"` //鏈�灏忛噰璐噺
- //PurchaseType constvar.PurchaseType `gorm:"type:int(11);comment:閲囪喘绫诲瀷" json:"purchaseType"`
- IsSale bool `gorm:"type:tinyint(1);comment:鏄惁閿�鍞�" json:"isSale"` //鏄惁閿�鍞�
- SalePrice decimal.Decimal `gorm:"type:decimal(35,18);comment:閿�鍞崟浠�" json:"salePrice"` //閿�鍞崟浠�
- AutoIncr uint `gorm:"type:int(11);comment:鑷ID;default:0;" json:"-"`
+ MinPurchaseAmount decimal.Decimal `gorm:"type:decimal(35,18);comment:鏈�灏忛噰璐噺" json:"minPurchaseAmount"` //鏈�灏忛噰璐噺
+ PurchaseType constvar.PurchaseType `gorm:"type:int(11);comment:閲囪喘绫诲瀷" json:"purchaseType"`
+ PurchaseTypes string `gorm:"type:varchar(255);comment:閲囪喘绫诲瀷鑼冨洿" json:"-"`
+ PurchaseTypeList []int `gorm:"-" json:"purchaseTypeList"`
+ IsSale bool `gorm:"type:tinyint(1);comment:鏄惁閿�鍞�" json:"isSale"` //鏄惁閿�鍞�
+ SalePrice decimal.Decimal `gorm:"type:decimal(35,18);comment:閿�鍞崟浠�" json:"salePrice"` //閿�鍞崟浠�
+ AutoIncr uint `gorm:"type:int(11);comment:鑷ID;default:0;" json:"autoIncr"`
//wms娣诲姞瀛楁
ProductType constvar.ProductType `gorm:"type:int(11);comment:浜у搧绫诲瀷" json:"productType"` //浜у搧绫诲瀷
InvoicingStrategy constvar.InvoicingStrategy `gorm:"type:int(11);comment:寮�绁ㄧ瓥鐣�" json:"invoicingStrategy"` //寮�绁ㄧ瓥鐣�
@@ -46,7 +51,6 @@
CategoryId int `gorm:"type:int(11);comment:浜у搧绫诲埆id" json:"categoryId"` //浜у搧绫诲埆id
CategoryName string `gorm:"type:varchar(255);comment:浜у搧绫诲埆鍚嶇О" json:"categoryName"` //浜у搧绫诲埆鍚嶇О
InternalReference string `gorm:"type:varchar(255);comment:鍐呴儴鍙傝��" json:"internalReference"` //鍐呴儴鍙傝��
- Barcode string `gorm:"type:varchar(255);comment:鏉$爜" json:"barcode"` //鏉$爜
ProductTagId int `gorm:"type:int(11);comment:浜у搧鏍囩id" json:"productTagId"` //浜у搧鏍囩id
ProductTagName string `gorm:"type:varchar(255);comment:浜у搧鏍囩鍚嶇О" json:"productTagName"` //浜у搧鏍囩鍚嶇О
CompanyId int `gorm:"type:int(11);comment:鍏徃id" json:"companyId"` //鍏徃id
@@ -59,7 +63,7 @@
ControlStrategy constvar.InvoicingStrategy `gorm:"type:int(11);comment:鎺у埗绛栫暐" json:"controlStrategy"` //鎺у埗绛栫暐
BuyExplain string `gorm:"type:varchar(512);comment:閲囪喘璇存槑" json:"buyExplain"` //閲囪喘璇存槑
Principal string `gorm:"type:varchar(255);comment:璐熻矗浜�" json:"principal"` //璐熻矗浜�
- Weight decimal.Decimal `gorm:"type:decimal(20,2);comment:閲嶉噺" json:"weight"` //閲嶉噺
+ Weight decimal.Decimal `gorm:"type:decimal(20,3);comment:閲嶉噺" json:"weight"` //閲嶉噺
Volume decimal.Decimal `gorm:"type:decimal(20,2);comment:浣撶Н" json:"volume"` //浣撶Н
MakeAdvanceTime decimal.Decimal `gorm:"type:decimal(20,2);comment:鍒堕�犲墠缃椂闂�" json:"makeAdvanceTime"` //鍒堕�犲墠缃椂闂�(澶�)
OrderAdvanceTime decimal.Decimal `gorm:"type:decimal(20,2);comment:璁㈠崟鍑嗗澶╂暟" json:"orderAdvanceTime"` //璁㈠崟鍑嗗澶╂暟(澶�)
@@ -67,9 +71,32 @@
//HSCode string `gorm:"type:varchar(255);comment:HS缂栫爜" json:"HSCode"` //HS缂栫爜
//OriginCountryId int `gorm:"type:int(11);comment:鍘熶骇鍦癷d" json:"originCountryId"` //鍘熶骇鍦癷d
//OriginCountryName string `gorm:"type:varchar(255);comment:鍘熶骇鍦板悕绉�" json:"originCountryName"` //鍘熶骇鍦板悕绉�
- InStorageExplain string `gorm:"type:varchar(512);comment:鍏ュ簱璇存槑" json:"inStorageExplain"` //鍏ュ簱璇存槑
- OutStorageExplain string `gorm:"type:varchar(512);comment:鍑哄簱璇存槑" json:"outStorageExplain"` //鍑哄簱璇存槑
- InternalTransferExplain string `gorm:"type:varchar(512);comment:鍐呴儴璋冩嫧璇存槑" json:"internalTransferExplain"` //鍐呴儴璋冩嫧璇存槑
+ InStorageExplain string `gorm:"type:varchar(512);comment:鍏ュ簱璇存槑" json:"inStorageExplain"` //鍏ュ簱璇存槑
+ OutStorageExplain string `gorm:"type:varchar(512);comment:鍑哄簱璇存槑" json:"outStorageExplain"` //鍑哄簱璇存槑
+ InternalTransferExplain string `gorm:"type:varchar(512);comment:鍐呴儴璋冩嫧璇存槑" json:"internalTransferExplain"` //鍐呴儴璋冩嫧璇存槑
+ AttachmentList []*Attachment `json:"attachmentList" gorm:"many2many:material_attachment"`
+ IsStorage int `gorm:"type:tinyint(1);default:1;comment:鏄惁瀛樺簱(1鏄�2鍚�)" json:"isStorage"` //鏃犲簱瀛樼殑鍦╳ms浠ュ強srm涓渶瑕佽繃婊ゆ帀
+ IsVirtual int `json:"isVirtual" gorm:"type:tinyint(1);default:2;comment:鏄惁铏氭嫙鐗╂枡(1鏄�2鍚�)"` //铏氭嫙鐗╂枡鍦∕RP璁$畻鏃惰烦杩囪灞傜骇鐩存帴棰嗙敤涓嬬骇鐗╂枡锛岃櫄鎷熺墿鏂欎笉鐢熸垚宸ュ崟
+ ReorderRuleNum int64 `json:"reorderRuleNum"`
+ MoreUnit *bool `json:"moreUnit" gorm:"type:tinyint(1);default:false;comment:鍚姩澶氬崟浣�"`
+ MoreUnitList []UnitItems `json:"moreUnitList" gorm:"-"`
+ MoreUnitValue string `json:"-" gorm:"type:varchar(255);comment:澶氬崟浣嶅��"`
+ GrossWeight decimal.Decimal `json:"grossWeight" gorm:"type:decimal(20,3);comment:姣涢噸"`
+ NetWeight decimal.Decimal `json:"netWeight" gorm:"type:decimal(20,3);comment:鍑�閲�"`
+ GrossUnit string `json:"grossUnit" gorm:"type:varchar(255);comment:姣涢噸鍗曚綅"`
+ NetUnit string `json:"netUnit" gorm:"type:varchar(255);comment:鍑�閲嶅崟浣�"`
+ Attributes []Attribute `json:"attributes" gorm:"-"` //鍔ㄦ�佸睘鎬�
+
+ //浠ヤ笅涓轰笉瀛樺簱鐨勫瓧娈�
+ AttachmentIDs []uint `json:"attachmentIDs" gorm:"-"`
+ PredictionAmount decimal.Decimal `json:"predictionAmount" gorm:"-"`
+ InputAmount decimal.Decimal `json:"inputAmount" gorm:"-"`
+ OutputAmount decimal.Decimal `json:"outputAmount" gorm:"-"`
+ MinInventoryRule decimal.Decimal `json:"minInventoryRule" gorm:"-"` //鏈�灏忓簱瀛�
+ MaxInventoryRule decimal.Decimal `json:"maxInventoryRule" gorm:"-"` //鏈�澶у簱瀛�
+
+ CreateBy string `gorm:"type:varchar(255);comment:瀵煎叆浜恒�佸垱寤轰汉" json:"createBy"` //鍒涘缓浜�
+ BarCode string `gorm:"type:varchar(255);comment:(鍟嗗搧/浜у搧/鐗╂枡鐨�)鏉″舰鐮�" json:"barCode"` //鏉$爜
}
MaterialSearch struct {
@@ -83,11 +110,19 @@
Ids []string
Orm *gorm.DB
CategoryIds []int
+ Preload bool
+ Fields string
}
IdAndName struct {
Id string `json:"id"`
Name string `json:"name"`
+ }
+
+ UnitItems struct {
+ Amount decimal.Decimal `json:"amount"`
+ Unit string `json:"unit"`
+ Floating bool `json:"floating"` //鏄惁娴姩鍒╃巼
}
)
@@ -95,8 +130,62 @@
return "material"
}
+func (slf *Material) AfterFind(tx *gorm.DB) (err error) {
+ if slf.PurchaseTypes != "" && strings.Contains(slf.PurchaseTypes, ",") {
+ list := strings.Split(slf.PurchaseTypes, ",")
+ for _, v := range list {
+ slf.PurchaseTypeList = append(slf.PurchaseTypeList, cast.ToInt(v))
+ }
+ } else if slf.PurchaseType != 0 { //鍏煎鏃ф暟鎹�
+ slf.PurchaseTypeList = append(slf.PurchaseTypeList, int(slf.PurchaseType))
+ }
+ if slf.MoreUnitValue != "" {
+ var arr []UnitItems
+ err := json.Unmarshal([]byte(slf.MoreUnitValue), &arr)
+ if err != nil {
+ return err
+ }
+ slf.MoreUnitList = arr
+ }
+ return
+}
+
+func (slf *Material) BeforeCreate(tx *gorm.DB) (err error) {
+ if len(slf.PurchaseTypeList) > 0 {
+ var typeList []string
+ for _, v := range slf.PurchaseTypeList {
+ if v != 0 {
+ typeList = append(typeList, cast.ToString(v))
+ }
+ }
+ slf.PurchaseTypes = strings.Join(typeList, ",")
+ if len(slf.PurchaseTypeList) == 1 {
+ slf.PurchaseType = constvar.PurchaseType(slf.PurchaseTypeList[0])
+ }
+ }
+ if len(slf.MoreUnitList) != 0 {
+ items := make([]UnitItems, 0)
+ for k, item := range slf.MoreUnitList {
+ if item.Unit != "" && !item.Amount.IsZero() {
+ items = append(items, slf.MoreUnitList[k])
+ }
+ }
+
+ str, err := json.Marshal(items)
+ if err != nil {
+ return err
+ }
+ slf.MoreUnitValue = string(str)
+ }
+ return
+}
+
+func (slf *Material) BeforeUpdate(tx *gorm.DB) (err error) {
+ return slf.BeforeCreate(tx)
+}
+
func NewMaterialSearch() *MaterialSearch {
- return &MaterialSearch{Orm: mysqlx.GetDB()}
+ return &MaterialSearch{Orm: mysqlx.GetDB().Where("is_storage = ?", 1)} //鍙煡璇㈡湁搴撳瓨鐨�
}
func (slf *MaterialSearch) SetOrm(tx *gorm.DB) *MaterialSearch {
@@ -116,6 +205,11 @@
func (slf *MaterialSearch) SetID(id string) *MaterialSearch {
slf.ID = id
+ return slf
+}
+
+func (slf *MaterialSearch) SetBarCode(barCode string) *MaterialSearch {
+ slf.BarCode = barCode
return slf
}
@@ -174,11 +268,24 @@
// return slf
//}
+func (slf *MaterialSearch) SetPreload(preload bool) *MaterialSearch {
+ slf.Preload = preload
+ return slf
+}
+
+func (slf *MaterialSearch) SetFields(fields string) *MaterialSearch {
+ slf.Fields = fields
+ return slf
+}
+
func (slf *MaterialSearch) build() *gorm.DB {
var db = slf.Orm.Table(slf.TableName())
if slf.ID != "" {
db = db.Where("id = ?", slf.ID)
+ }
+ if slf.BarCode != "" {
+ db = db.Where("bar_code = ?", slf.BarCode)
}
if slf.Name != "" {
@@ -238,6 +345,14 @@
}
if len(slf.CategoryIds) > 0 {
db = db.Where("category_id in ?", slf.CategoryIds)
+ }
+
+ if slf.Fields != "" {
+ db = db.Select(slf.Fields)
+ }
+
+ if slf.Preload {
+ db = db.Preload("AttachmentList")
}
return db
@@ -329,7 +444,7 @@
db = slf.build()
)
- if err := db.Count(&total).Error; err != nil {
+ if err := db.Model(&Material{}).Count(&total).Error; err != nil {
return records, total, fmt.Errorf("find count err: %v", err)
}
if slf.PageNum*slf.PageSize > 0 {
@@ -475,9 +590,9 @@
// return fileName, nil
//}
-func (slf *MaterialSearch) MaxAutoIncr() (int64, error) {
+func (slf *MaterialSearch) MaxAutoIncr() (int, error) {
type Result struct {
- Max int64
+ Max int
}
var (
@@ -493,24 +608,25 @@
}
type ResponseDisuseList struct {
- Id int `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"`
- Number string `json:"number" gorm:"type:varchar(255)"` //鍗曞彿
- SourceNumber string `json:"sourceNumber" gorm:"type:varchar(255)"` //婧愬崟鍙�
- Status constvar.OperationStatus `json:"status" gorm:"type:int(11);not null;comment:鐘舵��"` //鐘舵��
- FromLocationID int `json:"fromLocationId" gorm:"type:int;not null;comment:婧愪綅缃甶d"` //婧愪綅缃甶d
- FromLocation Location `json:"fromLocation" gorm:"foreignKey:FromLocationID;references:Id"` //婧愪綅缃�
- ToLocation Location `json:"toLocation" gorm:"foreignKey:ToLocationID;references:Id"` //鐩爣浣嶇疆
- ToLocationID int `json:"toLocationId" gorm:"type:int;not null;comment:鐩爣浣嶇疆id"` //鐩爣浣嶇疆id
- OperationDate string `json:"operationDate" gorm:"type:varchar(31);comment:瀹夋帓鏃ユ湡"`
- ContacterID int `json:"contacterID" gorm:"type:int;comment:鑱旂郴浜篒D"`
- ContacterName string `json:"contacterName" gorm:"type:varchar(63);comment:鑱旂郴浜哄鍚�"`
- 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:澶囨敞"`
- ProductId string `json:"productId" gorm:"type:varchar(191);not null;comment:浜у搧id"` //浜у搧id
- ProductName string `json:"productName" gorm:"type:varchar(255);not null;comment:浜у搧鍚嶇О"` //浜у搧鍚嶇О
- Amount decimal.Decimal `json:"amount" gorm:"type:decimal(20,2);not null;comment:鏁伴噺"` //鏁伴噺
- Unit string `json:"unit" gorm:"type:varchar(31);comment:鍗曚綅"`
+ Id int `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"`
+ Number string `json:"number" gorm:"type:varchar(255)"` //鍗曞彿
+ SourceNumber string `json:"sourceNumber" gorm:"type:varchar(255)"` //婧愬崟鍙�
+ Status constvar.OperationStatus `json:"status" gorm:"type:int(11);not null;comment:鐘舵��"` //鐘舵��
+ FromLocationID int `json:"fromLocationId" gorm:"type:int;not null;comment:婧愪綅缃甶d"` //婧愪綅缃甶d
+ FromLocation Location `json:"fromLocation" gorm:"foreignKey:FromLocationID;references:Id"` //婧愪綅缃�
+ ToLocation Location `json:"toLocation" gorm:"foreignKey:ToLocationID;references:Id"` //鐩爣浣嶇疆
+ ToLocationID int `json:"toLocationId" gorm:"type:int;not null;comment:鐩爣浣嶇疆id"` //鐩爣浣嶇疆id
+ OperationDate string `json:"operationDate" gorm:"type:varchar(31);comment:瀹夋帓鏃ユ湡"`
+ ContacterID int `json:"contacterID" gorm:"type:int;comment:鑱旂郴浜篒D"`
+ ContacterName string `json:"contacterName" gorm:"type:varchar(63);comment:鑱旂郴浜哄鍚�"`
+ CompanyID string `json:"companyID"` //鍏徃ID-瀹㈡埛
+ CompanyName string `json:"companyName" gorm:"type:varchar(127);comment:鍏徃鍚嶇О-瀹㈡埛"`
+ Comment string `json:"comment" gorm:"type:text;comment:澶囨敞"`
+ ProductId string `json:"productId" gorm:"type:varchar(191);not null;comment:浜у搧id"` //浜у搧id
+ ProductName string `json:"productName" gorm:"type:varchar(255);not null;comment:浜у搧鍚嶇О"` //浜у搧鍚嶇О
+ Amount decimal.Decimal `json:"amount" gorm:"type:decimal(20,2);not null;comment:鏁伴噺"` //鏁伴噺
+ Unit string `json:"unit" gorm:"type:varchar(31);comment:鍗曚綅"`
+ BaseOperationType constvar.BaseOperationType `json:"baseOperationType" gorm:"type:tinyint;not null;comment:鍩虹浣滀笟绫诲瀷"` //鍩虹浣滀笟绫诲瀷
}
func (slf *MaterialSearch) Update(record *Material) error {
@@ -522,3 +638,11 @@
return nil
}
+
+func MaterialMap(records []*Material) (m map[string]*Material) {
+ m = make(map[string]*Material, len(records))
+ for _, record := range records {
+ m[record.ID] = record
+ }
+ return m
+}
--
Gitblit v1.8.0