| | |
| | | |
| | | import ( |
| | | "apsClient/constvar" |
| | | "apsClient/model/request" |
| | | "apsClient/model/response" |
| | | _ "apsClient/model/response" |
| | | "apsClient/pkg/contextx" |
| | | "apsClient/pkg/ecode" |
| | | "apsClient/pkg/safe" |
| | | "apsClient/pkg/plc" |
| | | "apsClient/service" |
| | | "fmt" |
| | | "github.com/gin-gonic/gin" |
| | | "github.com/spf13/cast" |
| | | ) |
| | |
| | | // @Tags 生产数量 |
| | | // @Summary 获取生产进度 |
| | | // @Produce application/json |
| | | // @Param object body request.SendProcessParams true "查询参数" |
| | | // @Success 200 {object} contextx.Response{data=response.ProductProgress} "成功" |
| | | // @Router /v1/plc/productProgress [get] |
| | | // @Router /v1/plc/productProgress [post] |
| | | func (slf *PlcApi) GetProductProgress(c *gin.Context) { |
| | | ctx, ok := contextx.NewContext(c, nil) |
| | | var params request.GetProductProgress |
| | | ctx, ok := contextx.NewContext(c, ¶ms) |
| | | if !ok { |
| | | return |
| | | } |
| | | finishNumber, _ := service.PlcCacheGet(constvar.PlcCacheKeyFinishNumber) |
| | | totalNumber, _ := service.PlcCacheGet(constvar.PlcCacheKeyTotalNumber) |
| | | finishNumber, _ := service.PlcCacheGet(params.Position, constvar.PlcCacheKeyFinishNumber) |
| | | totalNumber, _ := service.PlcCacheGet(params.Position, constvar.PlcCacheKeyTotalNumber) |
| | | resp := new(response.ProductProgress) |
| | | resp.FinishNumber = cast.ToInt(finishNumber) |
| | | resp.TotalNumber = cast.ToInt(totalNumber) |
| | | |
| | | plcConfig, code := service.NewDevicePlcService().GetDevicePlc() |
| | | if code != ecode.OK { |
| | | return |
| | | } |
| | | plcStatus := 1 //断开连接 |
| | | ipAddr := fmt.Sprintf("%s:%v", plcConfig.Address, plcConfig.Port) |
| | | |
| | | _, err := plc.GetModbusConnection(ipAddr) |
| | | if err == nil { |
| | | if resp.FinishNumber > 0 { //生产 |
| | | plcStatus = 2 |
| | | } else { //待机 |
| | | plcStatus = 3 |
| | | } |
| | | } |
| | | resp.PlcStatus = plcStatus |
| | | |
| | | ctx.OkWithDetailed(resp) |
| | | } |
| | | |
| | |
| | | if !ok { |
| | | return |
| | | } |
| | | |
| | | taskData, code := service.NewTaskService().GetTask() |
| | | if code != ecode.OK { |
| | | ctx.Fail(code) |
| | | return |
| | | } |
| | | |
| | | if taskData.Order == nil { |
| | | ctx.FailWithMsg(ecode.UnknownErr, "当前没有待生产工单") |
| | | return |
| | | } |
| | | |
| | | plcConfig, code := service.NewDevicePlcService().GetDevicePlc() |
| | | if code != ecode.OK { |
| | | ctx.FailWithMsg(ecode.UnknownErr, "请先配置PLC") |
| | | return |
| | | } |
| | | |
| | | safe.Go(func() { |
| | | _ = service.PlcWrite(plcConfig, constvar.PlcStartAddressTypeTotalNumber, taskData.Order.Amount.IntPart()) |
| | | }) |
| | | |
| | | ctx.Ok() |
| | | } |