| | |
| | | return &ProgressService{} |
| | | } |
| | | |
| | | func (slf ProgressService) AddProgress(db *gorm.DB, procedure *model.Procedures, order *model.Order) error { |
| | | progress := &model.ProductionProgress{ |
| | | WorkOrderID: procedure.WorkOrderID, |
| | | OrderID: procedure.OrderID, |
| | | ProcedureID: procedure.ProceduresInfo.ProcedureID, |
| | | DeviceID: procedure.DeviceID, |
| | | TotalQuantity: order.Amount.IntPart(), |
| | | Position: procedure.Position, |
| | | func (slf ProgressService) Upsert(db *gorm.DB, procedure *model.Procedures, order *model.Order) error { |
| | | _, err := model.NewProductionProgressSearch(db).SetProcedureId(procedure.ProcedureID).SetWorkOrderId(procedure.WorkOrderID).First() |
| | | if err == gorm.ErrRecordNotFound { |
| | | progress := &model.ProductionProgress{ |
| | | WorkOrderID: procedure.WorkOrderID, |
| | | OrderID: procedure.OrderID, |
| | | ProcedureID: procedure.ProceduresInfo.ProcedureID, |
| | | DeviceID: procedure.DeviceID, |
| | | TotalQuantity: order.Amount.IntPart(), |
| | | Position: procedure.Position, |
| | | } |
| | | err := model.NewProductionProgressSearch(db).Create(progress) |
| | | if err != nil { |
| | | return err |
| | | } |
| | | ProgressCacheSet(procedure.Position, progress) |
| | | } |
| | | err := model.NewProductionProgressSearch(db).Create(progress) |
| | | if err != nil { |
| | | return err |
| | | } |
| | | ProgressCacheSet(procedure.Position, progress) |
| | | |
| | | return nil |
| | | } |
| | | |