| | |
| | | "apsClient/model/response" |
| | | _ "apsClient/model/response" |
| | | "apsClient/pkg/contextx" |
| | | "apsClient/pkg/ecode" |
| | | "apsClient/pkg/logx" |
| | | "apsClient/pkg/plc/apacheplc4x" |
| | | "apsClient/service" |
| | | "github.com/gin-gonic/gin" |
| | |
| | | } |
| | | ctx.Ok() |
| | | } |
| | | |
| | | // GetProductProgressRealTime |
| | | // @Tags 生产数量 |
| | | // @Summary 实时获取生产进度 |
| | | // @Produce application/json |
| | | // @Param object body request.SendProcessParams true "查询参数" |
| | | // @Success 200 {object} contextx.Response{data=response.ProductProgress} "成功" |
| | | // @Router /v1/plc/productProgressRealTime [post] |
| | | func (slf *PlcApi) GetProductProgressRealTime(c *gin.Context) { |
| | | var params request.GetProductProgress |
| | | ctx, ok := contextx.NewContext(c, ¶ms) |
| | | if !ok { |
| | | return |
| | | } |
| | | var finishNumber, totalNumber int64 |
| | | plcConfig, code := service.NewDevicePlcService().GetDevicePlc() |
| | | if code != ecode.OK { |
| | | return |
| | | } |
| | | for _, addressItem := range plcConfig.Details { |
| | | if addressItem.FieldName == constvar.PlcStartAddressTypeFinishNumber { |
| | | value, err := service.PlcReadDirect(plcConfig, addressItem.StartAddress, addressItem.Length, addressItem.Type) |
| | | if err != nil { |
| | | logx.Infof("plc read finish number err: %v", err) |
| | | continue |
| | | } |
| | | finishNumber = cast.ToInt64(value) |
| | | logx.Infof("plc read finish number: %v", finishNumber) |
| | | break |
| | | } |
| | | } |
| | | |
| | | for _, addressItem := range plcConfig.Details { |
| | | if addressItem.FieldName == constvar.PlcStartAddressTypeTotalNumber { |
| | | value, err := service.PlcReadDirect(plcConfig, addressItem.StartAddress, addressItem.Length, addressItem.Type) |
| | | if err != nil { |
| | | logx.Infof("plc read total number err: %v", err) |
| | | continue |
| | | } |
| | | totalNumber = cast.ToInt64(value) |
| | | logx.Infof("plc read total number: %v", totalNumber) |
| | | break |
| | | } |
| | | } |
| | | 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) |
| | | } |
| | |
| | | } |
| | | } |
| | | }, |
| | | "/v1/plc/productProgressRealTime": { |
| | | "post": { |
| | | "produces": [ |
| | | "application/json" |
| | | ], |
| | | "tags": [ |
| | | "生产数量" |
| | | ], |
| | | "summary": "实时获取生产进度", |
| | | "parameters": [ |
| | | { |
| | | "description": "查询参数", |
| | | "name": "object", |
| | | "in": "body", |
| | | "required": true, |
| | | "schema": { |
| | | "$ref": "#/definitions/request.SendProcessParams" |
| | | } |
| | | } |
| | | ], |
| | | "responses": { |
| | | "200": { |
| | | "description": "成功", |
| | | "schema": { |
| | | "allOf": [ |
| | | { |
| | | "$ref": "#/definitions/contextx.Response" |
| | | }, |
| | | { |
| | | "type": "object", |
| | | "properties": { |
| | | "data": { |
| | | "$ref": "#/definitions/response.ProductProgress" |
| | | } |
| | | } |
| | | } |
| | | ] |
| | | } |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | "/v1/plc/setProductNumber": { |
| | | "post": { |
| | | "produces": [ |
| | |
| | | } |
| | | } |
| | | }, |
| | | "/v1/plc/productProgressRealTime": { |
| | | "post": { |
| | | "produces": [ |
| | | "application/json" |
| | | ], |
| | | "tags": [ |
| | | "生产数量" |
| | | ], |
| | | "summary": "实时获取生产进度", |
| | | "parameters": [ |
| | | { |
| | | "description": "查询参数", |
| | | "name": "object", |
| | | "in": "body", |
| | | "required": true, |
| | | "schema": { |
| | | "$ref": "#/definitions/request.SendProcessParams" |
| | | } |
| | | } |
| | | ], |
| | | "responses": { |
| | | "200": { |
| | | "description": "成功", |
| | | "schema": { |
| | | "allOf": [ |
| | | { |
| | | "$ref": "#/definitions/contextx.Response" |
| | | }, |
| | | { |
| | | "type": "object", |
| | | "properties": { |
| | | "data": { |
| | | "$ref": "#/definitions/response.ProductProgress" |
| | | } |
| | | } |
| | | } |
| | | ] |
| | | } |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | "/v1/plc/setProductNumber": { |
| | | "post": { |
| | | "produces": [ |
| | |
| | | summary: 获取生产进度 |
| | | tags: |
| | | - 生产数量 |
| | | /v1/plc/productProgressRealTime: |
| | | post: |
| | | parameters: |
| | | - description: 查询参数 |
| | | in: body |
| | | name: object |
| | | required: true |
| | | schema: |
| | | $ref: '#/definitions/request.SendProcessParams' |
| | | produces: |
| | | - application/json |
| | | responses: |
| | | "200": |
| | | description: 成功 |
| | | schema: |
| | | allOf: |
| | | - $ref: '#/definitions/contextx.Response' |
| | | - properties: |
| | | data: |
| | | $ref: '#/definitions/response.ProductProgress' |
| | | type: object |
| | | summary: 实时获取生产进度 |
| | | tags: |
| | | - 生产数量 |
| | | /v1/plc/setProductNumber: |
| | | post: |
| | | produces: |
| | |
| | | plcApi := new(v1.PlcApi) |
| | | plcGroup := v1Group.Group("plc") |
| | | { |
| | | plcGroup.POST("productProgress", plcApi.GetProductProgress) // 获取网络配置 |
| | | plcGroup.POST("setProductNumber", plcApi.SetProductNumber) // 下发生产总量 |
| | | plcGroup.POST("productProgress", plcApi.GetProductProgress) // 获取生产进度 |
| | | plcGroup.POST("productProgressRealTime", plcApi.GetProductProgressRealTime) // 实时获取生产进度 |
| | | plcGroup.POST("setProductNumber", plcApi.SetProductNumber) // 下发生产总量 |
| | | } |
| | | |
| | | InitPlcBrandRouter(v1Group) |