From 02a84fb6fb2a39bfe7fc5cf6c0137bbf231b17fe Mon Sep 17 00:00:00 2001
From: zhangqian <zhangqian@123.com>
Date: 星期四, 09 十一月 2023 14:14:17 +0800
Subject: [PATCH] 设备列表返回是否设置工艺参数字段

---
 service/device.go |   38 ++++++++++++++++++++++++++++++++++++--
 1 files changed, 36 insertions(+), 2 deletions(-)

diff --git a/service/device.go b/service/device.go
index 29f2784..f09559e 100644
--- a/service/device.go
+++ b/service/device.go
@@ -3,13 +3,19 @@
 import (
 	"apsClient/conf"
 	"apsClient/model"
+	"apsClient/model/response"
 	"apsClient/pkg/logx"
+	"errors"
+	"github.com/jinzhu/gorm"
 	"os"
 	"strings"
 )
 
 func GetDeviceIDList() (deviceIds []string, err error) {
 	devices, err := model.NewDeviceSearch().SetDeviceMac(conf.Conf.System.DeviceId).FindNotTotal()
+	if err == gorm.ErrRecordNotFound {
+		return nil, nil
+	}
 	if err != nil {
 		return nil, err
 	}
@@ -18,6 +24,25 @@
 		deviceIds = append(deviceIds, device.DeviceID)
 	}
 	return deviceIds, nil
+}
+
+func GetDeviceList() (deviceList []*response.Device, err error) {
+	devices, err := model.NewDeviceSearch().SetDeviceMac(conf.Conf.System.DeviceId).FindNotTotal()
+	if err == gorm.ErrRecordNotFound {
+		return nil, nil
+	}
+	if err != nil {
+		return nil, err
+	}
+	deviceList = make([]*response.Device, 0, len(devices))
+	for _, device := range devices {
+		deviceList = append(deviceList, &response.Device{
+			DeviceID:             device.DeviceID,
+			DeviceName:           device.DeviceName,
+			NeedSetProcessParams: device.NeedSetProcessParams,
+		})
+	}
+	return deviceList, nil
 }
 
 func InitCurrentDeviceID() (err error) {
@@ -32,9 +57,9 @@
 	}
 	if len(deviceList) == 0 {
 		conf.Conf.CurrentDeviceID = conf.Conf.System.DeviceId
-		return nil
+	} else {
+		conf.Conf.CurrentDeviceID = deviceList[0]
 	}
-	conf.Conf.CurrentDeviceID = deviceList[0]
 	SetDeviceIDToFile(conf.Conf.CurrentDeviceID)
 	return nil
 }
@@ -61,3 +86,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