zhangqian
2023-09-16 fbae58e8f6e6159325ef41b85917ddb468d1b98a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
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, &params)
    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()
}