From 73b6baf6af3d88cdcb0e2df7932a9bd96b0b85c5 Mon Sep 17 00:00:00 2001 From: zhangqian <zhangqian@123.com> Date: 星期一, 01 七月 2024 22:32:34 +0800 Subject: [PATCH] 月度统计出入库按类型汇总报表定时任务和手动跑任务接口 --- models/warehouse.go | 72 +++++++++++++++++++++++++---------- 1 files changed, 51 insertions(+), 21 deletions(-) diff --git a/models/warehouse.go b/models/warehouse.go index a8db21e..e79397a 100644 --- a/models/warehouse.go +++ b/models/warehouse.go @@ -4,6 +4,7 @@ "fmt" "gorm.io/gorm" "strings" + "wms/constvar" "wms/pkg/mysqlx" ) @@ -11,20 +12,26 @@ // Warehouse 浠撳簱 Warehouse struct { WmsModel - Id int `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"` - Name string `json:"name" gorm:"index;type:varchar(255);not null;comment:浠撳簱鍚嶇О"` //浠撳簱鍚嶇О - Active bool `json:"active" gorm:"type:tinyint(1);not null;comment:鏄惁婵�娲�"` //鏄惁鍚敤锛屼紶true灏辫 - Code string `json:"code" binding:"required,min=1,max=5" gorm:"index;type:varchar(255);not null;comment:浠撳簱缂栫爜"` //浠撳簱缂栫爜 - PartnerID int `json:"partnerId" gorm:"type:int;not null;comment:鍚堜綔浼欎即id"` //鍚堜綔浼欎即id - BuyToResupply bool `json:"buyToResupply" gorm:"type:tinyint(1);not null;comment:鏄惁璐拱琛ョ粰"` //鏄惁璐拱琛ョ粰锛屽凡璐拱浜у搧鑳藉鍙戦�佸埌姝や粨搴� - ResupplyWhIdsStr string `json:"-" gorm:"column:resupply_wh_ids;type:varchar(255);not null;comment:琛ョ粰鏉ユ簮浠撳簱ID"` //琛ョ粰鏉ユ簮浠撳簱ID - ResupplyWhIds []string `json:"resupplyWhIds" gorm:"-"` //琛ョ粰鏉ユ簮浠撳簱ID - ResupplyWh []*Warehouse `json:"resupplyWh" gorm:"-"` //琛ョ粰鏉ユ簮浠撳簱 - CompanyId int `json:"companyId" gorm:"type:int;not null;comment:鍏徃id"` - Company Company `json:"company" gorm:"foreignKey:CompanyId"` - Address string `json:"address" gorm:"type:varchar(512);comment:鍦板潃"` //鍦板潃 - InboundTransportation int `json:"inboundTransportation" gorm:"type:int;comment:鍏ュ悜杩愯緭"` //鍏ュ悜杩愯緭 - OutboundTransportation int `json:"outboundTransportation" gorm:"type:int;comment:鍑哄簱杩愯緭"` //鍑哄簱杩愯緭 + Id int `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"` + Name string `json:"name" gorm:"index;type:varchar(255);not null;comment:浠撳簱鍚嶇О"` //浠撳簱鍚嶇О + Active bool `json:"active" gorm:"type:tinyint(1);not null;comment:鏄惁婵�娲�"` //鏄惁鍚敤锛屼紶true灏辫 + Code string `json:"code" gorm:"index;type:varchar(255);not null;comment:浠撳簱缂栫爜"` //浠撳簱缂栫爜 + PartnerID int `json:"partnerId" gorm:"type:int;not null;comment:鍚堜綔浼欎即id"` //鍚堜綔浼欎即id + BuyToResupply bool `json:"buyToResupply" gorm:"type:tinyint(1);not null;comment:鏄惁璐拱琛ョ粰"` //鏄惁璐拱琛ョ粰锛屽凡璐拱浜у搧鑳藉鍙戦�佸埌姝や粨搴� + ResupplyWhIdsStr string `json:"-" gorm:"column:resupply_wh_ids;type:varchar(255);not null;comment:琛ョ粰鏉ユ簮浠撳簱ID"` //琛ョ粰鏉ユ簮浠撳簱ID + ResupplyWhIds []string `json:"resupplyWhIds" gorm:"-"` //琛ョ粰鏉ユ簮浠撳簱ID + ResupplyWh []*Warehouse `json:"resupplyWh" gorm:"-"` //琛ョ粰鏉ユ簮浠撳簱 + CompanyId int `json:"companyId" gorm:"type:int;not null;comment:鍏徃id"` + Company Company `json:"company" gorm:"foreignKey:CompanyId"` + Address string `json:"address" gorm:"type:varchar(512);comment:鍦板潃"` //鍦板潃 + InboundTransportation int `json:"inboundTransportation" gorm:"type:int;comment:鍏ュ悜杩愯緭"` //鍏ュ悜杩愯緭 + OutboundTransportation int `json:"outboundTransportation" gorm:"type:int;comment:鍑哄簱杩愯緭"` //鍑哄簱杩愯緭 + LocationId int `json:"locationId" gorm:"type:int;comment:浣嶇疆id"` //榛樿浣嶇疆id + WarehouseLocation string `json:"warehouseLocation" gorm:"-"` //搴撳瓨浣嶇疆 + Contacts string `json:"contacts" gorm:"type:varchar(255);comment:鑱旂郴浜�"` //鑱旂郴浜� + FileTemplateCategoryIn constvar.FileTemplateCategory `json:"fileTemplateCategoryIn" gorm:"type:int(11);comment:鍏ュ簱妯$増绉嶇被"` + FileTemplateCategoryOut constvar.FileTemplateCategory `json:"fileTemplateCategoryOut" gorm:"type:int(11);comment:鍑哄簱妯$増绉嶇被"` + OpenMonthStats constvar.BoolType `gorm:"type:int(11);default:2;comment:鏄惁寮�鍚湀搴︾粺璁�" json:"openMonthStats"` //鏄惁寮�鍚湀搴︾粺璁� } WarehouseSearch struct { @@ -35,6 +42,7 @@ Keyword string Orm *gorm.DB Preload bool + Codes []string } ) @@ -66,13 +74,18 @@ return slf } -func (slf *WarehouseSearch) SetID(id uint) *WarehouseSearch { - slf.ID = id +func (slf *WarehouseSearch) SetID(id int) *WarehouseSearch { + slf.Id = id return slf } func (slf *WarehouseSearch) SetCode(code string) *WarehouseSearch { slf.Code = code + return slf +} + +func (slf *WarehouseSearch) SetCodes(codes []string) *WarehouseSearch { + slf.Codes = codes return slf } @@ -91,11 +104,16 @@ return slf } -func (slf *WarehouseSearch) build() *gorm.DB { - var db = slf.Orm.Model(&Warehouse{}) +func (slf *WarehouseSearch) SetOpenMonthStats(open constvar.BoolType) *WarehouseSearch { + slf.OpenMonthStats = open + return slf +} - if slf.ID != 0 { - db = db.Where("id = ?", slf.ID) +func (slf *WarehouseSearch) build() *gorm.DB { + var db = slf.Orm.Table(slf.TableName()) + + if slf.Id != 0 { + db = db.Where("id = ?", slf.Id) } if slf.Order != "" { @@ -112,6 +130,18 @@ if slf.Preload { db = db.Preload("Company") + } + + if slf.Code != "" { + db = db.Where("code = ?", slf.Code) + } + + if len(slf.Codes) > 0 { + db = db.Where("code in ?", slf.Codes) + } + + if slf.OpenMonthStats != 0 { + db = db.Where("open_month_stats = ?", slf.OpenMonthStats) } return db @@ -175,7 +205,7 @@ func (slf *WarehouseSearch) Delete() error { var db = slf.build() - return db.Delete(&Warehouse{}).Error + return db.Unscoped().Delete(&Warehouse{}).Error } func (slf *WarehouseSearch) First() (*Warehouse, error) { -- Gitblit v1.8.0