| | |
| | | "apsClient/model/response" |
| | | "apsClient/nsq" |
| | | "apsClient/pkg/contextx" |
| | | "apsClient/pkg/convertx" |
| | | "apsClient/pkg/ecode" |
| | | "apsClient/pkg/logx" |
| | | "apsClient/pkg/safe" |
| | |
| | | "errors" |
| | | "fmt" |
| | | "github.com/gin-gonic/gin" |
| | | "gorm.io/gorm" |
| | | "github.com/jinzhu/gorm" |
| | | "github.com/spf13/cast" |
| | | "sort" |
| | | "sync" |
| | | "time" |
| | |
| | | ctx.Fail(ecode.ParamsErr) |
| | | return |
| | | } |
| | | id := convertx.Atoi(idx) |
| | | id := cast.ToUint(idx) |
| | | procedure, code := service.NewTaskService().GetProcedureById(id) |
| | | if code != ecode.OK { |
| | | ctx.Fail(code) |
| | |
| | | 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)) |
| | |
| | | ctx.Fail(ecode.ParamsErr) |
| | | return |
| | | } |
| | | id := convertx.Atoi(idx) |
| | | id := cast.ToUint(idx) |
| | | procedure, code := service.NewTaskService().GetProcedureById(id) |
| | | if code != ecode.OK { |
| | | ctx.Fail(code) |
| | |
| | | } |
| | | |
| | | err = model.WithTransaction(func(db *gorm.DB) error { |
| | | err = taskService.UpdateProcedureStatusAndChannel(db, params.ProcedureId, model.ProcedureStatusProcessing, params.Channel) |
| | | err = taskService.UpdateProcedureStatusAndChannel(db, params.ProcedureId, model.ProcedureStatusProcessing, procedure.Channel, processModel.Number) |
| | | if err != nil { |
| | | return err |
| | | } |
| | | procedure.Channel = params.Channel |
| | | err = taskService.UpdateOrderStatus(db, order.ID, model.OrderStatusProcessing) |
| | | if err != nil { |
| | | return err |
| | |
| | | return |
| | | } |
| | | plcConfig, code := service.NewDevicePlcService().GetDevicePlc() |
| | | if code != ecode.OK || plcConfig.Id == 0 { |
| | | if code != ecode.OK || plcConfig.ID == 0 { |
| | | ctx.FailWithMsg(ecode.NeedConfirmedErr, "请先配置PLC") |
| | | return |
| | | } |
| | |
| | | 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, params.Channel) |
| | | if err != nil { |
| | | return err |
| | | } |
| | | procedure.Channel = params.Channel |
| | | err = taskService.UpdateOrderStatus(db, order.ID, model.OrderStatusWaitProcess) |
| | | err = taskService.UpdateProcedureStatusAndChannel(db, params.ProcedureId, model.ProcedureStatusWaitProcess, procedure.Channel, "") |
| | | if err != nil { |
| | | return err |
| | | } |
| | |
| | | return |
| | | } |
| | | plcConfig.CurrentTryTimes = 0 |
| | | err = service.PlcWrite(plcConfig, constvar.PlcStartAddressTypeTotalNumber, params.Channel, order.Amount.IntPart()) |
| | | err = service.PlcWrite(plcConfig, constvar.PlcStartAddressTypeTotalNumber, procedure.Channel, order.Amount.IntPart()) |
| | | if err != nil { |
| | | ctx.FailWithMsg(ecode.NeedConfirmedErr, "PLC请求失败,请检查PLC配置") |
| | | return |
| | |
| | | } |
| | | |
| | | plcConfig, code := service.NewDevicePlcService().GetDevicePlc() |
| | | if code != ecode.OK || plcConfig.Id == 0 { |
| | | if code != ecode.OK || plcConfig.ID == 0 { |
| | | ctx.FailWithMsg(ecode.NeedConfirmedErr, "请先配置PLC") |
| | | return |
| | | } |
| | |
| | | ctx.FailWithMsg(ecode.NeedConfirmedErr, "PLC请求失败,请检查PLC配置!") |
| | | return |
| | | } |
| | | _ = taskService.UpdateProcedureStatusAndChannel(nil, params.ProcedureId, model.ProcedureStatusProcessing, procedure.Channel, processModel.Number) |
| | | ctx.Ok() |
| | | } |
| | | |