From 9852e9aa54408c29e05dbcd603a10ffc09acd40b Mon Sep 17 00:00:00 2001
From: zhangqian <zhangqian@123.com>
Date: 星期四, 09 十一月 2023 14:02:16 +0800
Subject: [PATCH] 增加设置是否跳过设置工艺参数接口

---
 model/request/common.go |    4 +
 service/device.go       |   10 ++
 model/device.go         |   13 +-
 docs/swagger.yaml       |   45 +++++++++-
 api/v1/device.go        |   26 ++++++
 docs/docs.go            |   65 ++++++++++++++--
 docs/swagger.json       |   65 ++++++++++++++--
 7 files changed, 197 insertions(+), 31 deletions(-)

diff --git a/api/v1/device.go b/api/v1/device.go
index 6f16b3a..eb079eb 100644
--- a/api/v1/device.go
+++ b/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   鑾峰彇褰撳墠闈㈡澘缁戝畾鐨勮澶囧垪琛�
diff --git a/docs/docs.go b/docs/docs.go
index df8f13f..dacaa1b 100644
--- a/docs/docs.go
+++ b/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": {
diff --git a/docs/swagger.json b/docs/swagger.json
index a341a69..a8aedd3 100644
--- a/docs/swagger.json
+++ b/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": {
diff --git a/docs/swagger.yaml b/docs/swagger.yaml
index e027ea9..393866b 100644
--- a/docs/swagger.yaml
+++ b/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: 宸ユ帶鏈鸿澶嘔D
@@ -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
diff --git a/model/device.go b/model/device.go
index 5f8d669..1e490d3 100644
--- a/model/device.go
+++ b/model/device.go
@@ -11,12 +11,13 @@
 	// Device 璁惧
 	Device struct {
 		gorm.Model
-		DeviceID         string   `gorm:"column:device_id;type:varchar(255);not null;unique" json:"deviceID"` //璁惧缂栧彿
-		DeviceName       string   `gorm:"column:device_name;type:varchar(255);" json:"deviceName"`            //璁惧鍚嶇О
-		ExtChannelAmount int      `gorm:"type:tinyint;default:0" json:"extChannelAmount"`
-		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"`                                                   //璁惧鏀寔鐨勫伐搴忓垏鐗�
+		DeviceID             string   `gorm:"column:device_id;type:varchar(255);not null;unique" json:"deviceID"` //璁惧缂栧彿
+		DeviceName           string   `gorm:"column:device_name;type:varchar(255);" json:"deviceName"`            //璁惧鍚嶇О
+		ExtChannelAmount     int      `gorm:"type:tinyint;default:0" json:"extChannelAmount"`
+		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 {
diff --git a/model/request/common.go b/model/request/common.go
index c515c4e..7059381 100644
--- a/model/request/common.go
+++ b/model/request/common.go
@@ -12,3 +12,7 @@
 type SetCurrentDevice struct {
 	CurrentDeviceID string `json:"currentDeviceID,omitempty"` //褰撳墠閫夊畾鐨勭敓浜ц澶�
 }
+
+type DeviceConfig struct {
+	NeedSetProcessParams bool `json:"needSetProcessParams,omitempty"` //鏄惁闇�瑕佽缃伐鑹哄弬鏁�
+}
diff --git a/service/device.go b/service/device.go
index e11b959..c81500b 100644
--- a/service/device.go
+++ b/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)
+}

--
Gitblit v1.8.0