From 0d3d5a03d100614e0216249ec5ebbbbef8ff174c Mon Sep 17 00:00:00 2001 From: zhangqian <zhangqian@123.com> Date: 星期六, 16 九月 2023 19:13:54 +0800 Subject: [PATCH] fix --- api/v1/plc.go | 21 +++++++++++++++++---- 1 files changed, 17 insertions(+), 4 deletions(-) diff --git a/api/v1/plc.go b/api/v1/plc.go index 907e8d8..5f3b279 100644 --- a/api/v1/plc.go +++ b/api/v1/plc.go @@ -6,6 +6,7 @@ "apsClient/model/response" _ "apsClient/model/response" "apsClient/pkg/contextx" + "apsClient/pkg/plc/apacheplc4x" "apsClient/service" "github.com/gin-gonic/gin" "github.com/spf13/cast" @@ -19,18 +20,30 @@ // @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) { - var params request.SendProcessParams + 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) + + plcStatus := 1 //鏂紑杩炴帴 + isConnect := apacheplc4x.IsConnect() + if isConnect { + if resp.FinishNumber > 0 { //鐢熶骇 + plcStatus = 2 + } else { //寰呮満 + plcStatus = 3 + } + } + resp.PlcStatus = plcStatus + ctx.OkWithDetailed(resp) } -- Gitblit v1.8.0