From 73b6baf6af3d88cdcb0e2df7932a9bd96b0b85c5 Mon Sep 17 00:00:00 2001 From: zhangqian <zhangqian@123.com> Date: 星期一, 01 七月 2024 22:32:34 +0800 Subject: [PATCH] 月度统计出入库按类型汇总报表定时任务和手动跑任务接口 --- models/material.go | 45 ++++++++++++++++++++++++++++++++++++++++----- 1 files changed, 40 insertions(+), 5 deletions(-) diff --git a/models/material.go b/models/material.go index 5c03da9..e410f35 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 @@ -79,13 +78,14 @@ 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:鍚姩澶氬崟浣�"` + 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:"-"` @@ -95,6 +95,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 { @@ -109,6 +111,7 @@ Orm *gorm.DB CategoryIds []int Preload bool + Fields string } IdAndName struct { @@ -119,7 +122,7 @@ UnitItems struct { Amount decimal.Decimal `json:"amount"` Unit string `json:"unit"` - Floating bool `json:"floating"` + Floating bool `json:"floating"` //鏄惁娴姩鍒╃巼 } ) @@ -161,7 +164,14 @@ } } 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 } @@ -195,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 } @@ -258,11 +273,19 @@ 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 != "" { @@ -322,6 +345,10 @@ } if len(slf.CategoryIds) > 0 { db = db.Where("category_id in ?", slf.CategoryIds) + } + + if slf.Fields != "" { + db = db.Select(slf.Fields) } if slf.Preload { @@ -592,7 +619,7 @@ 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-瀹㈡埛"` + 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 @@ -611,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