zhangqian
2023-11-28 732e1e344addd02a4fa56531c7ffd0319e2d5b6c
进度更改兼容新旧模板
3个文件已修改
70 ■■■■ 已修改文件
model/production_progress.go 25 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service/progress.go 43 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service/report_work.go 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/production_progress.go
@@ -9,13 +9,15 @@
type (
    ProductionProgress struct {
        gorm.Model
        WorkOrderID      string `gorm:"index;type:varchar(191);not null" json:"workOrderID"`
        OrderID          string `gorm:"index;type:varchar(191);not null" json:"orderID"`
        ProcedureID      string `gorm:"type:varchar(191)" json:"procedureId"`
        DeviceID         string `gorm:"type:varchar(191);not null" json:"deviceId"`
        FinishedQuantity int64  `gorm:"type:int;not null" json:"finishedQuantity"`
        Channel          int32  `gorm:"type:int" json:"channel"` //通道
        TotalQuantity    int64  `gorm:"type:int;not null" json:"totalQuantity"`
        ProceduresID       uint   `gorm:"index;type:varchar(191)" json:"proceduresId"` //procedures表的id
        WorkOrderID        string `gorm:"index;type:varchar(191);not null" json:"workOrderID"`
        OrderID            string `gorm:"index;type:varchar(191);not null" json:"orderID"`
        ProcedureID        string `gorm:"type:varchar(191)" json:"procedureId"`
        ProductProcedureID string `gorm:"type:varchar(191);not null" json:"productProcedureID"` //产品工序id
        DeviceID           string `gorm:"type:varchar(191);not null" json:"deviceId"`
        FinishedQuantity   int64  `gorm:"type:int;not null" json:"finishedQuantity"`
        Channel            int32  `gorm:"type:int" json:"channel"` //通道
        TotalQuantity      int64  `gorm:"type:int;not null" json:"totalQuantity"`
    }
    ProductionProgressSearch struct {
@@ -64,6 +66,11 @@
    return slf
}
func (slf *ProductionProgressSearch) SetProceduresId(proceduresId uint) *ProductionProgressSearch {
    slf.ProceduresID = proceduresId
    return slf
}
func (slf *ProductionProgressSearch) SetDeviceId(id string) *ProductionProgressSearch {
    slf.DeviceID = id
    return slf
@@ -107,6 +114,10 @@
        db = db.Where("procedure_id = ?", slf.ProcedureID)
    }
    if slf.ProceduresID != 0 {
        db = db.Where("procedures_id = ?", slf.ProceduresID)
    }
    if slf.DeviceID != "" {
        db = db.Where("device_id = ?", slf.DeviceID)
    }
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()
service/report_work.go
@@ -90,7 +90,7 @@
        logx.Errorf("save report work transaction error: %v", err)
        return err
    }
    _ = NewProgressService().UpdateProgress(conf.Conf.CurrentDeviceID, procedure.Channel, int64(params.ReportAmount))
    _ = NewProgressService().UpdateProgressByProceduresId(procedure.ID, int64(params.ReportAmount))
    return nil
}