package v1 import ( "apsClient/constvar" "apsClient/model/request" "apsClient/model/response" _ "apsClient/model/response" "apsClient/pkg/contextx" "apsClient/pkg/ecode" "apsClient/pkg/plc" "apsClient/service" "fmt" "github.com/gin-gonic/gin" "github.com/spf13/cast" ) type PlcApi struct{} // GetProductProgress // @Tags 生产数量 // @Summary 获取生产进度 // @Produce application/json // @Param object body request.SendProcessParams true "查询参数" // @Success 200 {object} contextx.Response{data=response.ProductProgress} "成功" // @Router /v1/plc/productProgress [post] func (slf *PlcApi) GetProductProgress(c *gin.Context) { var params request.GetProductProgress ctx, ok := contextx.NewContext(c, ¶ms) if !ok { return } 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) } // SetProductNumber // @Tags 生产数量 // @Summary 设置生产总量 // @Produce application/json // @Success 200 {object} contextx.Response{} "成功" // @Router /v1/plc/setProductNumber [post] func (slf *PlcApi) SetProductNumber(c *gin.Context) { ctx, ok := contextx.NewContext(c, nil) if !ok { return } ctx.Ok() }