zhangqian
2023-11-29 528c5a54a9445e53607f5dbe1354c312db9f1fa4
出入库报表搜索增加几个字段
3个文件已修改
30 ■■■■■ 已修改文件
controllers/operation.go 6 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
models/operation.go 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service/input_history_search.go 23 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
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
}
models/operation.go
@@ -53,6 +53,7 @@
        Preload  bool
        Disuse   bool
        Ids      []int
        Numbers  []string
    }
)
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