From 155f70979af20ca520a55b89c6ec8cd46c43f8a5 Mon Sep 17 00:00:00 2001
From: zhangqian <zhangqian@123.com>
Date: 星期三, 31 七月 2024 15:47:33 +0800
Subject: [PATCH] 产品流水表增加多单位存储

---
 models/material.go |   40 ++++++++++++++++++++++++++++++++++++----
 1 files changed, 36 insertions(+), 4 deletions(-)

diff --git a/models/material.go b/models/material.go
index 031fc32..f28215e 100644
--- a/models/material.go
+++ b/models/material.go
@@ -51,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
@@ -81,7 +80,9 @@
 		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:澶氬崟浣嶅��"`
+		MoreUnitValue           string          `json:"-" gorm:"type:varchar(255);comment:澶氬崟浣嶅��"` //澶氬崟浣嶆崲绠楁瘮渚�
+		StockMoreUnitList       []UnitItems     `json:"-" gorm:"-"`                              //澶氬崟浣嶅瓨鍌ㄧ殑鍊�
+		StockMoreUnitValue      string          `json:"-" gorm:"type:varchar(512);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:姣涢噸鍗曚綅"`
@@ -96,6 +97,8 @@
 		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 {
@@ -119,7 +122,7 @@
 	}
 
 	UnitItems struct {
-		Amount   decimal.Decimal `json:"amount"`
+		Amount   decimal.Decimal `json:"amount"` //鍦ㄧ墿鏂欎腑涓烘崲绠楃巼锛�1杈呭崟浣�=鎹㈢畻鐜�*涓诲崟浣嶏級锛屽湪鏄庣粏鎴栧簱瀛樹腑涓哄叿浣撳��
 		Unit     string          `json:"unit"`
 		Floating bool            `json:"floating"` //鏄惁娴姩鍒╃巼
 	}
@@ -163,11 +166,32 @@
 		}
 	}
 	if len(slf.MoreUnitList) != 0 {
-		str, err := json.Marshal(slf.MoreUnitList)
+		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)
+	}
+	if len(slf.StockMoreUnitList) != 0 {
+		items := make([]UnitItems, 0)
+		for k, item := range slf.StockMoreUnitList {
+			if item.Unit != "" && !item.Amount.IsZero() {
+				items = append(items, slf.StockMoreUnitList[k])
+			}
+		}
+
+		str, err := json.Marshal(items)
+		if err != nil {
+			return err
+		}
+		slf.StockMoreUnitValue = string(str)
 	}
 	return
 }
@@ -197,6 +221,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
 }
 
@@ -271,6 +300,9 @@
 	if slf.ID != "" {
 		db = db.Where("id = ?", slf.ID)
 	}
+	if slf.BarCode != "" {
+		db = db.Where("bar_code = ?", slf.BarCode)
+	}
 
 	if slf.Name != "" {
 		db = db.Where("name = ?", slf.Name)

--
Gitblit v1.8.0