zhangqian
2023-11-09 9852e9aa54408c29e05dbcd603a10ffc09acd40b
增加设置是否跳过设置工艺参数接口
7个文件已修改
216 ■■■■ 已修改文件
api/v1/device.go 26 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/docs.go 65 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/swagger.json 65 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/swagger.yaml 45 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/device.go 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/request/common.go 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service/device.go 10 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
api/v1/device.go
@@ -56,6 +56,32 @@
    ctx.Ok()
}
// SetDeviceConfig
// @Tags      设备
// @Summary   设置设备一些配置
// @Produce   application/json
// @Param     object  body    request.DeviceConfig true  "查询参数"
// @Success   200   {object}  contextx.Response{}  "成功"
// @Router    /v1/device/config [post]
func (slf *DeviceApi) config(c *gin.Context) {
    var params request.DeviceConfig
    ctx, ok := contextx.NewContext(c, &params)
    if !ok {
        return
    }
    if conf.Conf.CurrentDeviceID == "" {
        ctx.FailWithMsg(ecode.UnknownErr, "当前设备为空,请检查")
        return
    }
    err := service.UpdateDevice(conf.Conf.CurrentDeviceID, params.NeedSetProcessParams)
    if err != nil {
        logx.Errorf("save device config err:%v", err)
        ctx.Fail(ecode.DBErr)
        return
    }
    ctx.Ok()
}
// DeviceList
// @Tags      设备
// @Summary   获取当前面板绑定的设备列表
docs/docs.go
@@ -152,6 +152,36 @@
                }
            }
        },
        "/v1/device/config": {
            "post": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "设备"
                ],
                "summary": "设置设备一些配置",
                "parameters": [
                    {
                        "description": "查询参数",
                        "name": "object",
                        "in": "body",
                        "required": true,
                        "schema": {
                            "$ref": "#/definitions/request.DeviceConfig"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "成功",
                        "schema": {
                            "$ref": "#/definitions/contextx.Response"
                        }
                    }
                }
            }
        },
        "/v1/device/list": {
            "get": {
                "produces": [
@@ -555,11 +585,6 @@
                "summary": "获取任务",
                "parameters": [
                    {
                        "type": "string",
                        "name": "deviceID",
                        "in": "query"
                    },
                    {
                        "type": "integer",
                        "description": "页码",
                        "name": "page",
@@ -953,11 +978,13 @@
            "type": "string",
            "enum": [
                "string",
                "int"
                "int16",
                "int32"
            ],
            "x-enum-varnames": [
                "PlcStartAddressValueTypeString",
                "PlcStartAddressValueTypeInt"
                "PlcStartAddressValueTypeInt16",
                "PlcStartAddressValueTypeInt32"
            ]
        },
        "constvar.ProblemCode": {
@@ -1441,6 +1468,15 @@
                }
            }
        },
        "request.DeviceConfig": {
            "type": "object",
            "properties": {
                "needSetProcessParams": {
                    "description": "是否需要设置工艺参数",
                    "type": "boolean"
                }
            }
        },
        "request.GetProductProgress": {
            "type": "object",
            "properties": {
@@ -1570,6 +1606,17 @@
                }
            }
        },
        "response.Device": {
            "type": "object",
            "properties": {
                "deviceID": {
                    "type": "string"
                },
                "deviceName": {
                    "type": "string"
                }
            }
        },
        "response.DeviceListResponse": {
            "type": "object",
            "properties": {
@@ -1585,11 +1632,11 @@
                    "description": "当前选定的生产设备",
                    "type": "string"
                },
                "deviceIDList": {
                "deviceList": {
                    "description": "生产设备id列表",
                    "type": "array",
                    "items": {
                        "type": "string"
                        "$ref": "#/definitions/response.Device"
                    }
                },
                "systemDeviceID": {
docs/swagger.json
@@ -140,6 +140,36 @@
                }
            }
        },
        "/v1/device/config": {
            "post": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "设备"
                ],
                "summary": "设置设备一些配置",
                "parameters": [
                    {
                        "description": "查询参数",
                        "name": "object",
                        "in": "body",
                        "required": true,
                        "schema": {
                            "$ref": "#/definitions/request.DeviceConfig"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "成功",
                        "schema": {
                            "$ref": "#/definitions/contextx.Response"
                        }
                    }
                }
            }
        },
        "/v1/device/list": {
            "get": {
                "produces": [
@@ -543,11 +573,6 @@
                "summary": "获取任务",
                "parameters": [
                    {
                        "type": "string",
                        "name": "deviceID",
                        "in": "query"
                    },
                    {
                        "type": "integer",
                        "description": "页码",
                        "name": "page",
@@ -941,11 +966,13 @@
            "type": "string",
            "enum": [
                "string",
                "int"
                "int16",
                "int32"
            ],
            "x-enum-varnames": [
                "PlcStartAddressValueTypeString",
                "PlcStartAddressValueTypeInt"
                "PlcStartAddressValueTypeInt16",
                "PlcStartAddressValueTypeInt32"
            ]
        },
        "constvar.ProblemCode": {
@@ -1429,6 +1456,15 @@
                }
            }
        },
        "request.DeviceConfig": {
            "type": "object",
            "properties": {
                "needSetProcessParams": {
                    "description": "是否需要设置工艺参数",
                    "type": "boolean"
                }
            }
        },
        "request.GetProductProgress": {
            "type": "object",
            "properties": {
@@ -1558,6 +1594,17 @@
                }
            }
        },
        "response.Device": {
            "type": "object",
            "properties": {
                "deviceID": {
                    "type": "string"
                },
                "deviceName": {
                    "type": "string"
                }
            }
        },
        "response.DeviceListResponse": {
            "type": "object",
            "properties": {
@@ -1573,11 +1620,11 @@
                    "description": "当前选定的生产设备",
                    "type": "string"
                },
                "deviceIDList": {
                "deviceList": {
                    "description": "生产设备id列表",
                    "type": "array",
                    "items": {
                        "type": "string"
                        "$ref": "#/definitions/response.Device"
                    }
                },
                "systemDeviceID": {
docs/swagger.yaml
@@ -113,11 +113,13 @@
  constvar.PlcStartAddressValueType:
    enum:
    - string
    - int
    - int16
    - int32
    type: string
    x-enum-varnames:
    - PlcStartAddressValueTypeString
    - PlcStartAddressValueTypeInt
    - PlcStartAddressValueTypeInt16
    - PlcStartAddressValueTypeInt32
  constvar.ProblemCode:
    enum:
    - service
@@ -454,6 +456,12 @@
      updatedAt:
        type: string
    type: object
  request.DeviceConfig:
    properties:
      needSetProcessParams:
        description: 是否需要设置工艺参数
        type: boolean
    type: object
  request.GetProductProgress:
    properties:
      channel:
@@ -541,6 +549,13 @@
      updatedAt:
        type: string
    type: object
  response.Device:
    properties:
      deviceID:
        type: string
      deviceName:
        type: string
    type: object
  response.DeviceListResponse:
    properties:
      clusterNodeQuantity:
@@ -552,10 +567,10 @@
      currentDeviceID:
        description: 当前选定的生产设备
        type: string
      deviceIDList:
      deviceList:
        description: 生产设备id列表
        items:
          type: string
          $ref: '#/definitions/response.Device'
        type: array
      systemDeviceID:
        description: 工控机设备ID
@@ -753,6 +768,25 @@
      summary: 更新plc配置
      tags:
      - Config
  /v1/device/config:
    post:
      parameters:
      - description: 查询参数
        in: body
        name: object
        required: true
        schema:
          $ref: '#/definitions/request.DeviceConfig'
      produces:
      - application/json
      responses:
        "200":
          description: 成功
          schema:
            $ref: '#/definitions/contextx.Response'
      summary: 设置设备一些配置
      tags:
      - 设备
  /v1/device/list:
    get:
      produces:
@@ -990,9 +1024,6 @@
  /v1/task/get:
    get:
      parameters:
      - in: query
        name: deviceID
        type: string
      - description: 页码
        in: query
        name: page
model/device.go
@@ -17,6 +17,7 @@
        Procedures       string   `gorm:"column:procedure;type:varchar(255);not null;default ''" json:"procedures"` //设备支持的工序,用逗号分隔
        DeviceMac        string   `gorm:"type:varchar(255);" json:"deviceMac"`                                      //绑定的工控机设备ID
        ProceduresArr    []string `gorm:"-" json:"ProceduresArr"`                                                   //设备支持的工序切片
        NeedSetProcessParams bool     `gorm:"column:need_set_process_params" json:"needSetProcessParams"`               //是否需要设置工艺参数                                          //设备支持的工序切片
    }
    DeviceSearch struct {
model/request/common.go
@@ -12,3 +12,7 @@
type SetCurrentDevice struct {
    CurrentDeviceID string `json:"currentDeviceID,omitempty"` //当前选定的生产设备
}
type DeviceConfig struct {
    NeedSetProcessParams bool `json:"needSetProcessParams,omitempty"` //是否需要设置工艺参数
}
service/device.go
@@ -5,6 +5,7 @@
    "apsClient/model"
    "apsClient/model/response"
    "apsClient/pkg/logx"
    "errors"
    "github.com/jinzhu/gorm"
    "os"
    "strings"
@@ -84,3 +85,12 @@
    deviceId = strings.Trim(deviceId, "\n")
    return deviceId
}
func UpdateDevice(deviceId string, needSetProcessParams bool) (err error) {
    device, err := model.NewDeviceSearch().SetDeviceId(deviceId).First()
    if err == gorm.ErrRecordNotFound {
        return errors.New("设备不存在")
    }
    device.NeedSetProcessParams = needSetProcessParams
    return model.NewDeviceSearch().SetID(device.ID).Save(device)
}