From 91d7ca06128f996844aa7d2d691d083c944bdf1d Mon Sep 17 00:00:00 2001 From: lishihai <dslsh@dscom> Date: 星期三, 03 七月 2024 17:22:16 +0800 Subject: [PATCH] 导入物料/产品->新模版BUG修复 --- service/search.go | 40 ++++++++++++++++++++++++++++++---------- 1 files changed, 30 insertions(+), 10 deletions(-) diff --git a/service/search.go b/service/search.go index aa1f235..d0733cb 100644 --- a/service/search.go +++ b/service/search.go @@ -9,11 +9,11 @@ ) type LocationReport struct { - LocationProductAmount int - LocationName string `json:"name" gorm:"index;type:varchar(255);not null;comment:浣嶇疆鍚嶇О"` //浣嶇疆鍚嶇О - LocationJointName string `json:"jointName" gorm:"type:varchar(255);comment:鎷兼帴鍚嶇О"` //鎷兼帴鍚嶇О - MaterialName string `json:"materialName"` //鐗╂枡鍚嶇О - ProductCategoryName string `json:"productCategoryName"` //鍒嗙被鍚嶇О + LocationProductAmountID int + LocationName string `json:"name" gorm:"index;type:varchar(255);not null;comment:浣嶇疆鍚嶇О"` //浣嶇疆鍚嶇О + LocationJointName string `json:"jointName" gorm:"type:varchar(255);comment:鎷兼帴鍚嶇О"` //鎷兼帴鍚嶇О + MaterialName string `json:"materialName"` //鐗╂枡鍚嶇О + ProductCategoryName string `json:"productCategoryName"` //鍒嗙被鍚嶇О } const ( @@ -33,7 +33,7 @@ reports := make([]*LocationReport, 0) search := models.NewLocationProductAmountSearch() err = search.Orm.Model(&models.LocationProductAmount{}). - Raw("select wms_location_product_amount.id as LocationProductAmount, wms_location.name as LocationName, wms_location.joint_name as LocationJointName, material.name as MaterialName, wms_product_category.Name as ProductCategoryName from wms_location_product_amount " + + Raw("select wms_location_product_amount.id as LocationProductAmountID, wms_location.name as LocationName, wms_location.joint_name as LocationJointName, material.name as MaterialName, wms_product_category.Name as ProductCategoryName from wms_location_product_amount " + "left join wms_location on wms_location.id=wms_location_product_amount.location_id " + "left join material on material.id = wms_location_product_amount.product_id " + "left join wms_product_category on wms_product_category.id=material.category_id").Scan(&reports).Error @@ -41,7 +41,7 @@ logx.Errorf("InitLocationReportData scan err:%v", err) } for _, result := range reports { - err = blevex.Add(LocationReportIndexName, strconv.Itoa(result.LocationProductAmount), result) + err = blevex.Add(LocationReportIndexName, strconv.Itoa(result.LocationProductAmountID), result) if err != nil { logx.Errorf("InitLocationReportData add failed, err:%v, index:%v, data:%v", err, LocationReportIndexName, result) } @@ -49,8 +49,10 @@ return } -func SearchLocationReport(keyword string, page, pageSize int) (list []*models.LocationProductAmount, total int64, err error) { - ids, err := blevex.Search(LocationReportIndexName, keyword) +func SearchLocationReport(keyword string, page, pageSize int) (list []*models.LocationProductAmount, total uint64, err error) { + var ids []string + from := (page - 1) * pageSize + ids, total, err = blevex.Search(LocationReportIndexName, keyword, from, pageSize) if err != nil { return } @@ -61,6 +63,24 @@ for _, id := range ids { recordIds = append(recordIds, cast.ToInt(id)) } - list, total, err = models.NewLocationProductAmountSearch().SetPage(page, pageSize).SetPreload(true).SetIds(recordIds).FindByPage() + list, err = models.NewLocationProductAmountSearch().SetPreload(true).SetIds(recordIds).Find() return } + +func AddNewLocationReportRecord(id int) { + var report LocationReport + err := models.NewLocationProductAmountSearch().Orm.Model(&models.LocationProductAmount{}). + Raw("select wms_location_product_amount.id as LocationProductAmountID, wms_location.name as LocationName, wms_location.joint_name as LocationJointName, material.name as MaterialName, wms_product_category.Name as ProductCategoryName from wms_location_product_amount "+ + "left join wms_location on wms_location.id=wms_location_product_amount.location_id "+ + "left join material on material.id = wms_location_product_amount.product_id "+ + "left join wms_product_category on wms_product_category.id=material.category_id where LocationProductAmountID = ?", id).Scan(&report).Error + if err != nil { + logx.Errorf("AddNewLocationReportRecord scan err:%v", err) + return + } + err = blevex.Add(LocationReportIndexName, strconv.Itoa(id), report) + if err != nil { + logx.Errorf("AddNewLocationReportRecord add err:%v", err) + return + } +} -- Gitblit v1.8.0