package v1
|
|
import (
|
"apsClient/constvar"
|
"apsClient/model/request"
|
"apsClient/model/response"
|
_ "apsClient/model/response"
|
"apsClient/pkg/contextx"
|
"apsClient/pkg/plc/modbusx"
|
"apsClient/service"
|
"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)
|
|
plcStatus := 1 //断开连接
|
isConnect := modbusx.IsConnect()
|
if isConnect {
|
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()
|
}
|