任务接收增加channel字段,postion字段改为channel
| | |
| | | if !ok { |
| | | return |
| | | } |
| | | finishNumber, _ := service.PlcCacheGet(params.Position, constvar.PlcCacheKeyFinishNumber) |
| | | totalNumber, _ := service.PlcCacheGet(params.Position, constvar.PlcCacheKeyTotalNumber) |
| | | finishNumber, _ := service.PlcCacheGet(params.Channel, constvar.PlcCacheKeyFinishNumber) |
| | | totalNumber, _ := service.PlcCacheGet(params.Channel, constvar.PlcCacheKeyTotalNumber) |
| | | resp := new(response.ProductProgress) |
| | | resp.FinishNumber = cast.ToInt(finishNumber) |
| | | resp.TotalNumber = cast.ToInt(totalNumber) |
| | |
| | | plcStatus := 1 //断开连接 |
| | | isConnect := service.PlcIsConnect() |
| | | if isConnect { |
| | | lastUpdateTime := service.FinishUpdateTimeGet(params.Position) |
| | | lastUpdateTime := service.FinishUpdateTimeGet(params.Channel) |
| | | if time.Now().Unix()-cast.ToInt64(lastUpdateTime) < conf.Conf.PLC.StandbyTime { //生产 |
| | | plcStatus = 2 |
| | | } else { |
| | |
| | | params.Page = 1 |
| | | } |
| | | if params.PageSize <= 0 { |
| | | params.PageSize = 1 |
| | | params.PageSize = 100 |
| | | } |
| | | |
| | | taskResponse, code := service.NewTaskService().GetTask(params.Page, params.PageSize, service.TaskModeUnStarted) //时间到了未开始的 |
| | |
| | | ctx.Fail(code) |
| | | return |
| | | } |
| | | err := service.NewTaskService().UpdateProcedureStatus(nil, id, model.ProcedureStatusFinished, procedure.Position) |
| | | err := service.NewTaskService().UpdateProcedureStatus(nil, id, model.ProcedureStatusFinished, procedure.Channel) |
| | | if err != nil { |
| | | logx.Errorf("UpdateProcedureStatus err: %v", err.Error()) |
| | | ctx.Fail(ecode.UnknownErr) |
| | |
| | | } |
| | | |
| | | err = model.WithTransaction(func(db *gorm.DB) error { |
| | | err = taskService.UpdateProcedureStatusAndPosition(db, params.ProcedureId, model.ProcedureStatusProcessing, params.Position) |
| | | err = taskService.UpdateProcedureStatusAndChannel(db, params.ProcedureId, model.ProcedureStatusProcessing, params.Channel) |
| | | if err != nil { |
| | | return err |
| | | } |
| | | procedure.Position = params.Position |
| | | procedure.Channel = params.Channel |
| | | err = taskService.UpdateOrderStatus(db, order.ID, model.OrderStatusProcessing) |
| | | if err != nil { |
| | | return err |
| | |
| | | if err != nil { |
| | | logx.Errorf("SendProcessParams: %v", err.Error()) |
| | | err = model.WithTransaction(func(db *gorm.DB) error { |
| | | err = taskService.UpdateProcedureStatusAndPosition(db, params.ProcedureId, model.ProcedureStatusWaitProcess, params.Position) |
| | | err = taskService.UpdateProcedureStatusAndChannel(db, params.ProcedureId, model.ProcedureStatusWaitProcess, params.Channel) |
| | | if err != nil { |
| | | return err |
| | | } |
| | | procedure.Position = params.Position |
| | | procedure.Channel = params.Channel |
| | | err = taskService.UpdateOrderStatus(db, order.ID, model.OrderStatusWaitProcess) |
| | | if err != nil { |
| | | return err |
| | |
| | | return |
| | | } |
| | | plcConfig.CurrentTryTimes = 0 |
| | | err = service.PlcWrite(plcConfig, constvar.PlcStartAddressTypeTotalNumber, params.Position, order.Amount.IntPart()) |
| | | err = service.PlcWrite(plcConfig, constvar.PlcStartAddressTypeTotalNumber, params.Channel, order.Amount.IntPart()) |
| | | if err != nil { |
| | | ctx.FailWithMsg(ecode.NeedConfirmedErr, "糟糕,工艺下发失败。") |
| | | return |
| | |
| | | } |
| | | finishNumber := cast.ToInt64(value) |
| | | if finishNumber != 0 { |
| | | service.PlcCacheSet(addressItem.Position, constvar.PlcCacheKeyFinishNumber, finishNumber) |
| | | _ = service.NewProgressService().UpdateProgress(addressItem.Position, cast.ToInt64(finishNumber)) |
| | | service.PlcCacheSet(addressItem.Channel, constvar.PlcCacheKeyFinishNumber, finishNumber) |
| | | _ = service.NewProgressService().UpdateProgress(addressItem.Channel, cast.ToInt64(finishNumber)) |
| | | } |
| | | logx.Infof("plc read finish number: %v", finishNumber) |
| | | } |
| | |
| | | } |
| | | totalNumber := cast.ToInt64(value) |
| | | if totalNumber != 0 { |
| | | service.PlcCacheSet(addressItem.Position, constvar.PlcCacheKeyTotalNumber, totalNumber) |
| | | _ = service.NewProgressService().UpdateProgress(addressItem.Position, cast.ToInt64(totalNumber)) |
| | | service.PlcCacheSet(addressItem.Channel, constvar.PlcCacheKeyTotalNumber, totalNumber) |
| | | _ = service.NewProgressService().UpdateProgress(addressItem.Channel, cast.ToInt64(totalNumber)) |
| | | } |
| | | logx.Infof("plc read total number: %v", totalNumber) |
| | | } |
| | |
| | | if code != ecode.OK { |
| | | return |
| | | } |
| | | var positions []int |
| | | var channels []int32 |
| | | for _, item := range plcConfig.Details { |
| | | if item.FieldName == constvar.PlcStartAddressTypeFinishNumber { |
| | | positions = append(positions, item.Position) |
| | | channels = append(channels, item.Channel) |
| | | } |
| | | } |
| | | for _, position := range positions { |
| | | progress, err := service.NewProgressService().GetCurrentProgress(position) |
| | | for _, channel := range channels { |
| | | progress, err := service.NewProgressService().GetCurrentProgress(channel) |
| | | if err != nil { |
| | | return |
| | | } |
| | |
| | | "type": "string" |
| | | } |
| | | }, |
| | | "channel": { |
| | | "description": "通道序号", |
| | | "type": "integer" |
| | | }, |
| | | "deviceId": { |
| | | "type": "string" |
| | | }, |
| | |
| | | "model.DevicePlcAddress": { |
| | | "type": "object", |
| | | "properties": { |
| | | "channel": { |
| | | "description": "数据起始地址", |
| | | "type": "integer" |
| | | }, |
| | | "fieldName": { |
| | | "description": "对应系统字段", |
| | | "allOf": [ |
| | |
| | | }, |
| | | "length": { |
| | | "description": "数据长度", |
| | | "type": "integer" |
| | | }, |
| | | "position": { |
| | | "description": "数据起始地址", |
| | | "type": "integer" |
| | | }, |
| | | "startAddress": { |
| | |
| | | "model.Procedures": { |
| | | "type": "object", |
| | | "properties": { |
| | | "channel": { |
| | | "description": "通道", |
| | | "type": "integer" |
| | | }, |
| | | "deviceId": { |
| | | "type": "string" |
| | | }, |
| | |
| | | "type": "integer" |
| | | }, |
| | | "id": { |
| | | "type": "integer" |
| | | }, |
| | | "position": { |
| | | "description": "每个设备可能有多个机位同时生产,用position表示位置", |
| | | "type": "integer" |
| | | }, |
| | | "procedure": { |
| | |
| | | "procedureId" |
| | | ], |
| | | "properties": { |
| | | "position": { |
| | | "channel": { |
| | | "type": "integer" |
| | | }, |
| | | "procedureId": { |
| | |
| | | "description": "是否可以开始生产", |
| | | "type": "boolean" |
| | | }, |
| | | "channel": { |
| | | "description": "当前任务在设备第几个通道", |
| | | "type": "integer" |
| | | }, |
| | | "currentProcedureIndex": { |
| | | "type": "integer" |
| | | }, |
| | | "order": { |
| | | "$ref": "#/definitions/model.Order" |
| | | }, |
| | | "position": { |
| | | "description": "当前任务在设备第几个位置", |
| | | "type": "integer" |
| | | }, |
| | | "procedure": { |
| | | "$ref": "#/definitions/model.Procedures" |
| | |
| | | "type": "string" |
| | | } |
| | | }, |
| | | "channel": { |
| | | "description": "通道序号", |
| | | "type": "integer" |
| | | }, |
| | | "deviceId": { |
| | | "type": "string" |
| | | }, |
| | |
| | | "model.DevicePlcAddress": { |
| | | "type": "object", |
| | | "properties": { |
| | | "channel": { |
| | | "description": "数据起始地址", |
| | | "type": "integer" |
| | | }, |
| | | "fieldName": { |
| | | "description": "对应系统字段", |
| | | "allOf": [ |
| | |
| | | }, |
| | | "length": { |
| | | "description": "数据长度", |
| | | "type": "integer" |
| | | }, |
| | | "position": { |
| | | "description": "数据起始地址", |
| | | "type": "integer" |
| | | }, |
| | | "startAddress": { |
| | |
| | | "model.Procedures": { |
| | | "type": "object", |
| | | "properties": { |
| | | "channel": { |
| | | "description": "通道", |
| | | "type": "integer" |
| | | }, |
| | | "deviceId": { |
| | | "type": "string" |
| | | }, |
| | |
| | | "type": "integer" |
| | | }, |
| | | "id": { |
| | | "type": "integer" |
| | | }, |
| | | "position": { |
| | | "description": "每个设备可能有多个机位同时生产,用position表示位置", |
| | | "type": "integer" |
| | | }, |
| | | "procedure": { |
| | |
| | | "procedureId" |
| | | ], |
| | | "properties": { |
| | | "position": { |
| | | "channel": { |
| | | "type": "integer" |
| | | }, |
| | | "procedureId": { |
| | |
| | | "description": "是否可以开始生产", |
| | | "type": "boolean" |
| | | }, |
| | | "channel": { |
| | | "description": "当前任务在设备第几个通道", |
| | | "type": "integer" |
| | | }, |
| | | "currentProcedureIndex": { |
| | | "type": "integer" |
| | | }, |
| | | "order": { |
| | | "$ref": "#/definitions/model.Order" |
| | | }, |
| | | "position": { |
| | | "description": "当前任务在设备第几个位置", |
| | | "type": "integer" |
| | | }, |
| | | "procedure": { |
| | | "$ref": "#/definitions/model.Procedures" |
| | |
| | | items: |
| | | type: string |
| | | type: array |
| | | channel: |
| | | description: 通道序号 |
| | | type: integer |
| | | deviceId: |
| | | type: string |
| | | deviceName: |
| | |
| | | type: object |
| | | model.DevicePlcAddress: |
| | | properties: |
| | | channel: |
| | | description: 数据起始地址 |
| | | type: integer |
| | | fieldName: |
| | | allOf: |
| | | - $ref: '#/definitions/constvar.PlcStartAddressType' |
| | | description: 对应系统字段 |
| | | length: |
| | | description: 数据长度 |
| | | type: integer |
| | | position: |
| | | description: 数据起始地址 |
| | | type: integer |
| | | startAddress: |
| | | description: 数据起始地址 |
| | |
| | | - ProcedureStatusFinished |
| | | model.Procedures: |
| | | properties: |
| | | channel: |
| | | description: 通道 |
| | | type: integer |
| | | deviceId: |
| | | type: string |
| | | endTime: |
| | | type: integer |
| | | id: |
| | | type: integer |
| | | position: |
| | | description: 每个设备可能有多个机位同时生产,用position表示位置 |
| | | type: integer |
| | | procedure: |
| | | allOf: |
| | |
| | | type: object |
| | | request.SendProcessParams: |
| | | properties: |
| | | position: |
| | | channel: |
| | | type: integer |
| | | procedureId: |
| | | type: integer |
| | |
| | | canStarted: |
| | | description: 是否可以开始生产 |
| | | type: boolean |
| | | channel: |
| | | description: 当前任务在设备第几个通道 |
| | | type: integer |
| | | currentProcedureIndex: |
| | | type: integer |
| | | order: |
| | | $ref: '#/definitions/model.Order' |
| | | position: |
| | | description: 当前任务在设备第几个位置 |
| | | type: integer |
| | | procedure: |
| | | $ref: '#/definitions/model.Procedures' |
| | | type: object |
| | |
| | | OutputMaterials []*ProcedureMaterial `json:"outputMaterials"` // 输出物料列表 |
| | | Workers []*ProcedureWorker `json:"workers"` // 人员列表 |
| | | AllProcedureNames []string `json:"allProcedureNames"` // 所属工单工序列表 |
| | | Channel int32 `json:"channel"` //通道序号 |
| | | } |
| | | |
| | | DeliverScheduleTask struct { |
| | |
| | | KeyData []byte |
| | | AddressData []byte |
| | | DeviceId string |
| | | PlcAddressList []*PlcAddress |
| | | PlcConfig PlcConfig |
| | | PlcAddressList []*PlcAddress //plc 完成量,总量, 读写地址 |
| | | PlcConfig PlcConfig //用网口还是端口以及网口ip port |
| | | } |
| | | |
| | | PlcConfig struct { |
| | |
| | | |
| | | PlcAddress struct { |
| | | DeviceID string `json:"deviceID"` // 设备id |
| | | Position int `json:"position"` // 生产位置,一个机器可能有多个机位,需要分别配置plc地址 |
| | | Channel int `json:"channel"` // 生产通道on,一个机器可能有多个机位,需要分别配置plc地址 |
| | | StartAddress int `json:"startAddress"` // 数据起始地址 |
| | | Length int `json:"length"` // 数据长度 |
| | | Type string `json:"type"` // 数据类型 |
| | |
| | | } |
| | | |
| | | DevicePlcAddress struct { |
| | | Position int `json:"position"` // 数据起始地址 |
| | | Channel int32 `json:"channel"` // 数据起始地址 |
| | | StartAddress int `json:"startAddress"` // 数据起始地址 |
| | | Length int `json:"length"` // 数据长度 |
| | | Type constvar.PlcStartAddressValueType `json:"type"` // 数据类型 |
| | |
| | | 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"` |
| | | Position int `gorm:"type:int;comment:工作位置" json:"position"` //每个设备可能有多个机位同时生产,用position表示位置 |
| | | Channel int32 `gorm:"index;comment:通道" json:"channel"` //通道 |
| | | StartTime int64 `gorm:"comment:计划开始时间" json:"startTime"` |
| | | EndTime int64 `gorm:"comment:计划结束时间" json:"endTime"` |
| | | Status ProcedureStatus |
| | |
| | | ProcedureID string `gorm:"type:varchar(191);comment:工序ID" json:"procedureId"` |
| | | DeviceID string `gorm:"type:varchar(191);not null;comment:设备ID" json:"deviceId"` |
| | | FinishedQuantity int64 `gorm:"type:int;not null;comment:完成数量" json:"finishedQuantity"` |
| | | Position int `gorm:"type:int;comment:工作位置" json:"position"` //每个设备可能有多个机位同时生产,用position表示位置 |
| | | Channel int32 `gorm:"type:int;comment:工作通道" json:"channel"` //通道 |
| | | TotalQuantity int64 `gorm:"type:int;not null;comment:总量" json:"totalQuantity"` |
| | | } |
| | | |
| | |
| | | return slf |
| | | } |
| | | |
| | | func (slf *ProductionProgressSearch) SetPosition(position int) *ProductionProgressSearch { |
| | | slf.Position = position |
| | | func (slf *ProductionProgressSearch) SetChannel(channel int32) *ProductionProgressSearch { |
| | | slf.Channel = channel |
| | | return slf |
| | | } |
| | | |
| | |
| | | db = db.Where("device_id = ?", slf.DeviceID) |
| | | } |
| | | |
| | | if slf.Position != 0 { |
| | | db = db.Where("position = ?", slf.Position) |
| | | if slf.Channel != 0 { |
| | | db = db.Where("channel = ?", slf.Channel) |
| | | } |
| | | |
| | | return db |
| | |
| | | } |
| | | |
| | | type SendProcessParams struct { |
| | | ProcedureId int `json:"procedureId" binding:"required"` |
| | | Position int `json:"position"` |
| | | ProcedureId int `json:"procedureId" binding:"required"` |
| | | Channel int32 `json:"channel"` |
| | | } |
| | | |
| | | type GetProductProgress struct { |
| | | ProcedureId int `json:"procedureId" binding:"required"` |
| | | Position int `json:"position"` |
| | | ProcedureId int `json:"procedureId" binding:"required"` |
| | | Channel int32 `json:"channel"` |
| | | } |
| | |
| | | Order *model.Order |
| | | Procedure *model.Procedures |
| | | |
| | | Position int //当前任务在设备第几个位置 |
| | | Channel int32 //当前任务在设备第几个通道 |
| | | AllProcedures []string |
| | | CurrentProcedureIndex int |
| | | CanStarted bool //是否可以开始生产 |
| | |
| | | StartTime: procedure.StartTime, |
| | | EndTime: procedure.EndTime, |
| | | Status: model.ProcedureStatusWaitProcess, |
| | | Channel: procedure.Channel, |
| | | ProceduresInfo: common.ProductProcedure{}, |
| | | } |
| | | procedureData, err := json.Marshal(procedure) |
| | |
| | | } |
| | | |
| | | const ( |
| | | PlcCacheKey = "plc:%v:%v" //plc:position:key |
| | | PlcCacheKey = "plc:%v:%v" //plc:channel:key |
| | | CurrentTaskCacheKey = "current_task" |
| | | CurrentProgressCacheKey = "current_progress:%v" //current_progress:position |
| | | PlcCacheKeyUpdateTime = "finish_number_update_time:%v" //finish_number_update_time:position |
| | | CurrentProgressCacheKey = "current_progress:%v" //current_progress:channel |
| | | PlcCacheKeyUpdateTime = "finish_number_update_time:%v" //finish_number_update_time:channel |
| | | ) |
| | | |
| | | func PlcCacheGet(position int, key string) (interface{}, bool) { |
| | | return defaultCacheStore.Get(fmt.Sprintf(PlcCacheKey, position, key)) |
| | | func PlcCacheGet(channel int32, key string) (interface{}, bool) { |
| | | return defaultCacheStore.Get(fmt.Sprintf(PlcCacheKey, channel, key)) |
| | | } |
| | | |
| | | func PlcCacheSet(position int, key string, value interface{}) { |
| | | func PlcCacheSet(channel int32, key string, value interface{}) { |
| | | if key == constvar.PlcCacheKeyFinishNumber { |
| | | oldFinishNumber, exists := PlcCacheGet(position, key) |
| | | oldFinishNumber, exists := PlcCacheGet(channel, key) |
| | | if !exists || cast.ToInt(oldFinishNumber) != cast.ToInt(value) { //finishNumber有了变化,设置更新时间缓存 |
| | | FinishUpdateTimeSet(position, time.Now().Unix()) |
| | | FinishUpdateTimeSet(channel, time.Now().Unix()) |
| | | } |
| | | } |
| | | defaultCacheStore.Add(fmt.Sprintf(PlcCacheKey, position, key), value) |
| | | defaultCacheStore.Add(fmt.Sprintf(PlcCacheKey, channel, key), value) |
| | | } |
| | | |
| | | func FinishUpdateTimeGet(position int) interface{} { |
| | | val, ok := defaultCacheStore.Get(fmt.Sprintf(PlcCacheKeyUpdateTime, position)) |
| | | func FinishUpdateTimeGet(channel int32) interface{} { |
| | | val, ok := defaultCacheStore.Get(fmt.Sprintf(PlcCacheKeyUpdateTime, channel)) |
| | | if ok { |
| | | return val |
| | | } |
| | | return 0 |
| | | } |
| | | |
| | | func FinishUpdateTimeSet(position int, value interface{}) { |
| | | defaultCacheStore.Add(fmt.Sprintf(PlcCacheKeyUpdateTime, position), value) |
| | | func FinishUpdateTimeSet(channel int32, value interface{}) { |
| | | defaultCacheStore.Add(fmt.Sprintf(PlcCacheKeyUpdateTime, channel), value) |
| | | } |
| | | |
| | | func TaskCacheSet(value *response.TaskData) { |
| | |
| | | return nil, false |
| | | } |
| | | |
| | | func ProgressCacheGet(position int) (*model.ProductionProgress, bool) { |
| | | if v, ok := defaultCacheStore.Get(fmt.Sprintf(CurrentProgressCacheKey, position)); ok { |
| | | func ProgressCacheGet(channel int32) (*model.ProductionProgress, bool) { |
| | | if v, ok := defaultCacheStore.Get(fmt.Sprintf(CurrentProgressCacheKey, channel)); ok { |
| | | return v.(*model.ProductionProgress), ok |
| | | } |
| | | return nil, false |
| | | } |
| | | |
| | | func ProgressCacheSet(position int, value *model.ProductionProgress) { |
| | | defaultCacheStore.Add(fmt.Sprintf(CurrentProgressCacheKey, position), value) |
| | | func ProgressCacheSet(channel int32, value *model.ProductionProgress) { |
| | | defaultCacheStore.Add(fmt.Sprintf(CurrentProgressCacheKey, channel), value) |
| | | } |
| | | |
| | | func ProgressCacheUnset(position int) { |
| | | defaultCacheStore.Remove(fmt.Sprintf(CurrentProgressCacheKey, position)) |
| | | func ProgressCacheUnset(channel int32) { |
| | | defaultCacheStore.Remove(fmt.Sprintf(CurrentProgressCacheKey, channel)) |
| | | } |
| | |
| | | "github.com/spf13/cast" |
| | | ) |
| | | |
| | | func PlcWrite(plcConfig *model.DevicePlc, fieldType constvar.PlcStartAddressType, position int, value interface{}) (err error) { |
| | | func PlcWrite(plcConfig *model.DevicePlc, fieldType constvar.PlcStartAddressType, channel int32, value interface{}) (err error) { |
| | | var ( |
| | | startAddress int |
| | | ipAddr string |
| | |
| | | plcConfig.CurrentTryTimes++ |
| | | |
| | | for _, pc := range plcConfig.Details { |
| | | if pc.FieldName == fieldType && pc.Position == position { |
| | | if pc.FieldName == fieldType && pc.Channel == channel { |
| | | startAddress = pc.StartAddress |
| | | } |
| | | } |
| | |
| | | if err != nil { |
| | | logx.Errorf("plc write failed, address: %v, value: %v, err: %v", startAddress, value, err.Error()) |
| | | plcConfig.CurrentErr = err |
| | | return PlcWrite(plcConfig, fieldType, position, value) |
| | | return PlcWrite(plcConfig, fieldType, channel, value) |
| | | } |
| | | logx.Infof("plc write ok, address: %v, value: %v", startAddress, value) |
| | | } else if plcConfig.Method == constvar.PlcMethodSerial { |
| | |
| | | ProcedureID: procedure.ProceduresInfo.ProcedureID, |
| | | DeviceID: procedure.DeviceID, |
| | | TotalQuantity: order.Amount.IntPart(), |
| | | Position: procedure.Position, |
| | | Channel: procedure.Channel, |
| | | } |
| | | err := model.NewProductionProgressSearch(db).Create(progress) |
| | | if err != nil { |
| | | return err |
| | | } |
| | | ProgressCacheSet(procedure.Position, progress) |
| | | ProgressCacheSet(procedure.Channel, progress) |
| | | } |
| | | |
| | | return nil |
| | | } |
| | | |
| | | func (slf ProgressService) UpdateProgress(position int, finishedQuantity int64) (err error) { |
| | | progressCache, err := slf.GetCurrentProgress(position) |
| | | func (slf ProgressService) UpdateProgress(channel int32, finishedQuantity int64) (err error) { |
| | | progressCache, err := slf.GetCurrentProgress(channel) |
| | | if err != nil { |
| | | return err |
| | | } |
| | |
| | | } |
| | | if finishedQuantity > progressCache.FinishedQuantity { //当有变化时才更新 |
| | | progressCache.FinishedQuantity = finishedQuantity |
| | | ProgressCacheSet(position, progressCache) |
| | | ProgressCacheSet(channel, progressCache) |
| | | return model.NewProductionProgressSearch(nil).SetId(progressCache.ID).Save(progressCache) |
| | | } |
| | | return nil |
| | | } |
| | | |
| | | func (slf ProgressService) GetCurrentProgress(position int) (progressCache *model.ProductionProgress, err error) { |
| | | func (slf ProgressService) GetCurrentProgress(channel int32) (progressCache *model.ProductionProgress, err error) { |
| | | var ok bool |
| | | progressCache, ok = ProgressCacheGet(position) |
| | | progressCache, ok = ProgressCacheGet(channel) |
| | | if !ok { |
| | | progressCache, err = model.NewProductionProgressSearch(nil).SetPosition(position).SetOrder("id desc").First() |
| | | progressCache, err = model.NewProductionProgressSearch(nil).SetChannel(channel).SetOrder("id desc").First() |
| | | if err == gorm.ErrRecordNotFound { |
| | | return nil, errors.New("progress not found") |
| | | } |
| | |
| | | progressCache = nil |
| | | } |
| | | if progressCache != nil { |
| | | ProgressCacheSet(position, progressCache) |
| | | ProgressCacheSet(channel, progressCache) |
| | | } |
| | | } |
| | | return |
| | |
| | | Procedure: procedure, |
| | | AllProcedures: procedure.ProceduresInfo.AllProcedureNames, |
| | | CurrentProcedureIndex: 0, |
| | | Position: procedure.Position, |
| | | Channel: procedure.Channel, |
| | | } |
| | | index := 0 |
| | | for _, name := range procedure.ProceduresInfo.AllProcedureNames { |
| | |
| | | return procedure, ecode.OK |
| | | } |
| | | |
| | | func (slf TaskService) UpdateProcedureStatusAndPosition(db *gorm.DB, id int, status model.ProcedureStatus, position int) error { |
| | | func (slf TaskService) UpdateProcedureStatusAndChannel(db *gorm.DB, id int, status model.ProcedureStatus, channel int32) error { |
| | | if status == model.ProcedureStatusFinished { |
| | | ProgressCacheUnset(position) |
| | | ProgressCacheUnset(channel) |
| | | } |
| | | return model.NewProceduresSearch(db).SetId(id).UpdateByMap(map[string]interface{}{ |
| | | "status": status, |
| | | "position": position, |
| | | "status": status, |
| | | "channel": channel, |
| | | }) |
| | | } |
| | | |
| | | func (slf TaskService) UpdateProcedureStatus(db *gorm.DB, id int, status model.ProcedureStatus, position int) error { |
| | | func (slf TaskService) UpdateProcedureStatus(db *gorm.DB, id int, status model.ProcedureStatus, channel int32) error { |
| | | if status == model.ProcedureStatusFinished { |
| | | ProgressCacheUnset(position) |
| | | ProgressCacheUnset(channel) |
| | | } |
| | | return model.NewProceduresSearch(db).SetId(id).UpdateByMap(map[string]interface{}{ |
| | | "status": status, |