| | |
| | | |
| | | 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{ |
| | |
| | | } |
| | | 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 |
| | | } |
| | |
| | | Preload bool |
| | | Disuse bool |
| | | Ids []int |
| | | Numbers []string |
| | | } |
| | | ) |
| | | |
| | |
| | | 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 |