From 528c5a54a9445e53607f5dbe1354c312db9f1fa4 Mon Sep 17 00:00:00 2001 From: zhangqian <zhangqian@123.com> Date: 星期三, 29 十一月 2023 18:03:00 +0800 Subject: [PATCH] 出入库报表搜索增加几个字段 --- service/input_history_search.go | 23 ++++++++++++++--------- controllers/operation.go | 6 +++--- models/operation.go | 1 + 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/controllers/operation.go b/controllers/operation.go index f42fe69..e75abc4 100644 --- a/controllers/operation.go +++ b/controllers/operation.go @@ -733,7 +733,7 @@ func AddMoveHistory(operationList []*models.Operation, db *gorm.DB) error { var histories []*models.MoveHistory - operationMap := make(map[string]*models.Operation, len(operationList)) + operationMap := make(map[int]*models.Operation, len(operationList)) for _, operation := range operationList { for _, v := range operation.Details { history := &models.MoveHistory{ @@ -754,13 +754,13 @@ } histories = append(histories, history) } - operationMap[operation.Number] = operation + operationMap[operation.Id] = operation } if err := db.Model(&models.MoveHistory{}).Create(&histories).Error; err != nil { return err } for _, history := range histories { - service.AddNewHistoryReportRecord(history, operationMap[history.Number]) + service.AddNewHistoryReportRecord(history, operationMap[history.OperationId]) } return nil } diff --git a/models/operation.go b/models/operation.go index 1996968..96e5754 100644 --- a/models/operation.go +++ b/models/operation.go @@ -53,6 +53,7 @@ Preload bool Disuse bool Ids []int + Numbers []string } ) diff --git a/service/input_history_search.go b/service/input_history_search.go index ac6f575..45803c5 100644 --- a/service/input_history_search.go +++ b/service/input_history_search.go @@ -41,19 +41,24 @@ return } records := make([]*models.MoveHistory, 0, 100) - reports := make([]*HistoryReport, 0, 100) err = models.NewMoveHistorySearch().Orm.FindInBatches(&records, 100, func(tx *gorm.DB, batch int) error { - err = structx.AssignTo(records, &reports) + operationIds := make([]int, 0, len(records)) + for _, record := range records { + operationIds = append(operationIds, record.OperationId) + } + + operations, err := models.NewOperationSearch().SetPreload(true).SetIds(operationIds).FindNotTotal() if err != nil { - logx.Errorf("AddNewHistoryReportRecord AssignTo err:%v", err) return err } - for _, report := range reports { - err = blevex.Add(HistoryReportIndexName, strconv.Itoa(report.ID), report) - if err != nil { - logx.Errorf("InitHistoryReportData add failed, err:%v, index:%v, data:%v", err, HistoryReportIndexName, report) - return err - } + operationMap := make(map[int]*models.Operation, len(operations)) + + for _, operation := range operations { + operationMap[operation.Id] = operation + } + + for _, record := range records { + AddNewHistoryReportRecord(record, operationMap[record.OperationId]) } return nil }).Error -- Gitblit v1.8.0