plc断开连接时获取工序最后一次报工数量作为加工数
| | |
| | | import ( |
| | | "apsClient/conf" |
| | | "apsClient/constvar" |
| | | "apsClient/model" |
| | | "apsClient/model/request" |
| | | "apsClient/model/response" |
| | | _ "apsClient/model/response" |
| | |
| | | if !ok { |
| | | return |
| | | } |
| | | finishNumber, _ := service.PlcCacheGet(conf.Conf.CurrentDeviceID, params.Channel, constvar.PlcCacheKeyFinishNumber) |
| | | totalNumber, _ := service.PlcCacheGet(conf.Conf.CurrentDeviceID, params.Channel, constvar.PlcCacheKeyTotalNumber) |
| | | isConnect := service.PlcIsConnect() |
| | | var ( |
| | | finishNumber interface{} |
| | | totalNumber interface{} |
| | | ) |
| | | if isConnect { |
| | | finishNumber, _ = service.PlcCacheGet(conf.Conf.CurrentDeviceID, params.Channel, constvar.PlcCacheKeyFinishNumber) |
| | | totalNumber, _ = service.PlcCacheGet(conf.Conf.CurrentDeviceID, params.Channel, constvar.PlcCacheKeyTotalNumber) |
| | | } else if params.ProcedureId != 0 { |
| | | reportWork, err := service.GetLastReportWork(params.ProcedureId) |
| | | if err == nil { |
| | | finishNumber = reportWork.ReportAmount |
| | | } |
| | | workOrder, err := model.NewOrderSearch(nil).SetWorkOrderId(reportWork.WorkOrderID).First() |
| | | if err == nil { |
| | | totalNumber = workOrder.Amount.IntPart() |
| | | } |
| | | } |
| | | |
| | | resp := new(response.ProductProgress) |
| | | resp.FinishNumber = cast.ToInt(finishNumber) |
| | | resp.TotalNumber = cast.ToInt(totalNumber) |
| | | |
| | | plcStatus := 1 //断开连接 |
| | | isConnect := service.PlcIsConnect() |
| | | if isConnect { |
| | | lastUpdateTime := service.FinishUpdateTimeGet(conf.Conf.CurrentDeviceID, params.Channel) |
| | | if time.Now().Unix()-cast.ToInt64(lastUpdateTime) < conf.Conf.PLC.StandbyTime { //生产 |
| | |
| | | Channel int32 `gorm:"index;" json:"channel"` //通道 |
| | | StartTime int64 `json:"startTime"` |
| | | EndTime int64 `json:"endTime"` |
| | | WorkerID string `json:"workerID"` //报工人id |
| | | WorkerName string `json:"workerName"` //报工人姓名 |
| | | ReportAmount int `json:"reportAmount"` //报工数量 |
| | | WorkerID string `json:"workerID"` //报工人id |
| | | WorkerName string `json:"workerName"` //报工人姓名 |
| | | } |
| | | |
| | | ReportWorkSearch struct { |
| | |
| | | } |
| | | |
| | | type GetProductProgress struct { |
| | | Channel int32 `json:"channel"` |
| | | ProcedureId uint `json:"procedureId"` |
| | | Channel int32 `json:"channel"` |
| | | } |
| | | |
| | | // ProcessModelList 工艺参数列表请求参数 |
| | |
| | | reportWorkApi := new(v1.ReportWorkApi) |
| | | reportWorkGroup := v1Group.Group("reportWork") |
| | | { |
| | | reportWorkGroup.GET("report", reportWorkApi.Report) // 报工 |
| | | reportWorkGroup.POST("report", reportWorkApi.Report) // 报工 |
| | | reportWorkGroup.GET("list", reportWorkApi.ReportList) // 报工列表 |
| | | } |
| | | |
| | |
| | | |
| | | import ( |
| | | "apsClient/conf" |
| | | "apsClient/constvar" |
| | | "apsClient/model" |
| | | "apsClient/model/request" |
| | | "errors" |
| | |
| | | if err != nil { |
| | | return err |
| | | } |
| | | |
| | | if procedure.Status != model.ProcedureStatusProcessing { |
| | | return errors.New("当前工序未开始或已结束,不允许报工") |
| | | } |
| | | |
| | | nowTs := time.Now().Unix() |
| | | var startTs int64 |
| | | var workerName string |
| | |
| | | Channel: procedure.Channel, |
| | | StartTime: startTs, |
| | | EndTime: nowTs, |
| | | ReportAmount: params.ReportAmount, |
| | | WorkerID: params.WorkerID, |
| | | WorkerName: workerName, |
| | | } |
| | | return model.NewReportWorkSearch(nil).Create(record) |
| | | |
| | | err = model.NewReportWorkSearch(nil).Create(record) |
| | | if err != nil { |
| | | return err |
| | | } |
| | | PlcCacheSet(conf.Conf.CurrentDeviceID, procedure.Channel, constvar.PlcCacheKeyFinishNumber, params.ReportAmount) |
| | | return nil |
| | | } |
| | | |
| | | // GetLastReportWork 获取最后一个报工 |
| | | func GetLastReportWork(procedureId uint) (reportWork *model.ReportWork, err error) { |
| | | return model.NewReportWorkSearch(nil).SetProceduresId(procedureId).SetDeviceId(conf.Conf.CurrentDeviceID).SetOrder("id desc").First() |
| | | } |