zhangqian
2023-11-28 732e1e344addd02a4fa56531c7ffd0319e2d5b6c
service/progress.go
@@ -14,15 +14,17 @@
}
func (slf ProgressService) Add(db *gorm.DB, procedure *model.Procedures, order *model.Order) error {
   _, err := model.NewProductionProgressSearch(db).SetProcedureId(procedure.ProcedureID).SetWorkOrderId(procedure.WorkOrderID).First()
   _, err := model.NewProductionProgressSearch(db).SetProceduresId(procedure.ID).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(),
         Channel:       procedure.Channel,
         ProceduresID:       procedure.ID,
         WorkOrderID:        procedure.WorkOrderID,
         OrderID:            procedure.OrderID,
         ProcedureID:        procedure.ProceduresInfo.ProcedureID,
         ProductProcedureID: procedure.ProductProcedureID,
         DeviceID:           procedure.DeviceID,
         TotalQuantity:      order.Amount.IntPart(),
         Channel:            procedure.Channel,
      }
      err := model.NewProductionProgressSearch(db).Create(progress)
      if err != nil {
@@ -34,7 +36,7 @@
   return nil
}
// UpdateProgress 仅限plc数据采集定时任务用
// UpdateProgress 仅限plc数据采集定时任务用(缺少工序id参数)
func (slf ProgressService) UpdateProgress(deviceID string, channel int32, finishedQuantity int64) (err error) {
   progressCache, err := slf.GetCurrentProgress(deviceID, channel)
   if err != nil {
@@ -51,7 +53,7 @@
   return nil
}
// GetCurrentProgress 仅限plc数据采集定时任务用
// GetCurrentProgress 仅限plc数据采集定时任务用(缺少工序id参数)
func (slf ProgressService) GetCurrentProgress(deviceID string, channel int32) (progressCache *model.ProductionProgress, err error) {
   var ok bool
   progressCache, ok = ProgressCacheGet(deviceID, channel)
@@ -74,6 +76,29 @@
   return
}
func (slf ProgressService) UpdateProgressByProceduresId(proceduresId uint, finishedQuantity int64) (err error) {
   progress, err := slf.GetCurrentProgressByProceduresId(proceduresId)
   if err != nil {
      return err
   }
   if progress == nil {
      return errors.New("progress not exists")
   }
   if finishedQuantity > progress.FinishedQuantity { //当有变化时才更新
      progress.FinishedQuantity = finishedQuantity
      return model.NewProductionProgressSearch(nil).SetId(progress.ID).Save(progress)
   }
   return nil
}
func (slf ProgressService) GetCurrentProgressByProceduresId(proceduresId uint) (progress *model.ProductionProgress, err error) {
   progress, err = model.NewProductionProgressSearch(nil).SetProceduresId(proceduresId).First()
   if err != nil {
      return nil, err
   }
   return
}
// GetProgressList 获取待同步进度工序
func (slf ProgressService) GetProgressList() (progressList []*model.ProductionProgress, err error) {
   progressList, err = model.NewProductionProgressSearch(nil).SetUnFinished().SetOrder("id desc").SetPage(1, 100).FindNotTotal()