| | |
| | | ctx.Fail(ecode.DBErr) |
| | | return |
| | | } |
| | | |
| | | processModel, err := service.NewTaskService().GetProcessParams(procedure, order) |
| | | if err != nil || processModel == nil || processModel.ParamsMap == nil { |
| | | ctx.FailWithMsg(ecode.ParamsErr, "未获取到工艺参数,请在工艺模型库中上传!") |
| | | return |
| | | var processModel *model.ProcessModel |
| | | if procedure.ProcessModelNumber != "" { |
| | | processModel, err = service.GetProcessModelByNumber(procedure.ProcessModelNumber) |
| | | if err != nil || processModel == nil || processModel.ParamsMap == nil { |
| | | ctx.FailWithMsg(ecode.ParamsErr, "未获取到工艺参数,请在工艺模型库中上传!") |
| | | return |
| | | } |
| | | } else { |
| | | processModel, err = service.NewTaskService().GetProcessParams(procedure, order) |
| | | if err != nil || processModel == nil || processModel.ParamsMap == nil { |
| | | ctx.FailWithMsg(ecode.ParamsErr, "未获取到工艺参数,请在工艺模型库中上传!") |
| | | return |
| | | } |
| | | } |
| | | |
| | | processParamsArr := make([]response.ProcessParams, 0, len(processModel.ParamsMap)) |
| | |
| | | } |
| | | |
| | | err = model.WithTransaction(func(db *gorm.DB) error { |
| | | err = taskService.UpdateProcedureStatusAndChannel(db, params.ProcedureId, model.ProcedureStatusProcessing, procedure.Channel) |
| | | err = taskService.UpdateProcedureStatusAndChannel(db, params.ProcedureId, model.ProcedureStatusProcessing, procedure.Channel, processModel.Number) |
| | | if err != nil { |
| | | return err |
| | | } |
| | |
| | | if err != nil { |
| | | logx.Errorf("SendProcessParams: %v", err.Error()) |
| | | err = model.WithTransaction(func(db *gorm.DB) error { |
| | | err = taskService.UpdateProcedureStatusAndChannel(db, params.ProcedureId, model.ProcedureStatusWaitProcess, procedure.Channel) |
| | | if err != nil { |
| | | return err |
| | | } |
| | | err = taskService.UpdateOrderStatus(db, order.ID, model.OrderStatusWaitProcess) |
| | | err = taskService.UpdateProcedureStatusAndChannel(db, params.ProcedureId, model.ProcedureStatusWaitProcess, procedure.Channel, "") |
| | | if err != nil { |
| | | return err |
| | | } |
| | |
| | | |
| | | type ( |
| | | Procedures struct { |
| | | gorm.Model `json:"-"` |
| | | ID int `gorm:"primarykey"` |
| | | WorkOrderID string `gorm:"index;type:varchar(191);not null;comment:工单ID" json:"-"` |
| | | OrderID string `gorm:"index;type:varchar(191);not null;comment:订单ID" json:"-"` |
| | | DeviceID string `gorm:"index;type:varchar(191);comment:设备ID" json:"deviceId"` |
| | | ProcedureID string `gorm:"index;type:varchar(191);comment:工序ID" json:"procedureId"` |
| | | Channel int32 `gorm:"index;comment:通道" json:"channel"` //通道 |
| | | StartTime int64 `gorm:"comment:计划开始时间" json:"startTime"` |
| | | EndTime int64 `gorm:"comment:计划结束时间" json:"endTime"` |
| | | Status ProcedureStatus |
| | | ProcedureData string `json:"-"` //common.ProductProcedure json串 |
| | | ProceduresInfo common.ProductProcedure `json:"procedure" gorm:"-"` //common.ProductProcedure 对象 |
| | | gorm.Model `json:"-"` |
| | | ID int `gorm:"primarykey"` |
| | | WorkOrderID string `gorm:"index;type:varchar(191);not null;comment:工单ID" json:"-"` |
| | | OrderID string `gorm:"index;type:varchar(191);not null;comment:订单ID" json:"-"` |
| | | DeviceID string `gorm:"index;type:varchar(191);comment:设备ID" json:"deviceId"` |
| | | ProcedureID string `gorm:"index;type:varchar(191);comment:工序ID" json:"procedureId"` |
| | | Channel int32 `gorm:"index;comment:通道" json:"channel"` //通道 |
| | | ProcessModelNumber string `gorm:"index;comment:工艺模型编号" json:"processModelNumber"` //工艺模型编号 |
| | | StartTime int64 `gorm:"comment:计划开始时间" json:"startTime"` |
| | | EndTime int64 `gorm:"comment:计划结束时间" json:"endTime"` |
| | | Status ProcedureStatus |
| | | ProcedureData string `json:"-"` //common.ProductProcedure json串 |
| | | ProceduresInfo common.ProductProcedure `json:"procedure" gorm:"-"` //common.ProductProcedure 对象 |
| | | } |
| | | |
| | | ProceduresSearch struct { |
| | |
| | | return procedure, ecode.OK |
| | | } |
| | | |
| | | func (slf TaskService) UpdateProcedureStatusAndChannel(db *gorm.DB, id int, status model.ProcedureStatus, channel int32) error { |
| | | if status == model.ProcedureStatusFinished { |
| | | func (slf TaskService) UpdateProcedureStatusAndChannel(db *gorm.DB, id int, status model.ProcedureStatus, channel int32, processModelNumber string) error { |
| | | if status == model.ProcedureStatusFinished || status == model.ProcedureStatusWaitProcess { |
| | | ProgressCacheUnset(channel) |
| | | } |
| | | return model.NewProceduresSearch(db).SetId(id).UpdateByMap(map[string]interface{}{ |
| | | "status": status, |
| | | }) |
| | | |
| | | upMap := map[string]interface{}{"status": status} |
| | | if status == model.ProcedureStatusProcessing { |
| | | upMap["process_model_number"] = processModelNumber |
| | | } else if status == model.ProcedureStatusWaitProcess { |
| | | upMap["process_model_number"] = "" |
| | | } |
| | | |
| | | return model.NewProceduresSearch(db).SetId(id).UpdateByMap(upMap) |
| | | } |
| | | |
| | | func (slf TaskService) UpdateProcedureStatus(db *gorm.DB, id int, status model.ProcedureStatus, channel int32) error { |