From 4497935a55e286ee922b99e6e478b7714a35d0b2 Mon Sep 17 00:00:00 2001
From: zhangqian <zhangqian@123.com>
Date: 星期五, 03 十一月 2023 16:28:33 +0800
Subject: [PATCH] fix
---
model/net_config.go | 34 ++++++++++++++++++----------------
1 files changed, 18 insertions(+), 16 deletions(-)
diff --git a/model/net_config.go b/model/net_config.go
index 75a9fa5..0223a47 100644
--- a/model/net_config.go
+++ b/model/net_config.go
@@ -3,20 +3,19 @@
import (
"apsClient/pkg/sqlitex"
"fmt"
- "gorm.io/gorm"
+ "github.com/jinzhu/gorm"
"sync"
)
type (
NetConfig struct {
- gorm.Model `json:"-"`
- Id int `gorm:"primarykey;type:int;" json:"id"`
- NetworkCard string `gorm:"type:varchar(100);not null;default '';comment:缃戝崱" json:"networkCard" binding:"required"` //缃戝崱
- IP string `gorm:"type:varchar(100);not null;default '';comment:鏈満ip" json:"ip" binding:"required"` //鏈満ip
- MASK string `gorm:"type:varchar(100);not null;default '';comment:瀛愮綉鎺╃爜" json:"mask" binding:"required"` //瀛愮綉鎺╃爜
- Gateway string `gorm:"type:varchar(100);not null;default '';comment:缃戝叧" json:"gateway" binding:"required"` //缃戝叧
- DNS string `gorm:"type:varchar(100);not null;default '';comment:DNS" json:"dns"` //dns
- Status NetConfigStatus `gorm:"type:tinyint;not null;default 0;comment:鐘舵�侊紙1鍚姩2绂佺敤锛�" json:"status"` //鐘舵�侊紙1鍚敤2绂佺敤锛�
+ gorm.Model
+ NetworkCard string `gorm:"type:varchar(100);not null;default ''" json:"networkCard" binding:"required"` //缃戝崱
+ IP string `gorm:"type:varchar(100);not null;default ''" json:"ip" binding:"required"` //鏈満ip
+ MASK string `gorm:"type:varchar(100);not null;default ''" json:"mask" binding:"required"` //瀛愮綉鎺╃爜
+ Gateway string `gorm:"type:varchar(100);not null;default ''" json:"gateway" binding:"required"` //缃戝叧
+ DNS string `gorm:"type:varchar(100);not null;default ''" json:"dns"` //dns
+ Status NetConfigStatus `gorm:"type:tinyint;not null;default 0" json:"status"` //鐘舵�侊紙1鍚敤2绂佺敤锛�
}
NetConfigSearch struct {
@@ -53,14 +52,16 @@
return slf
}
-func (slf *NetConfigSearch) SetId(id int) *NetConfigSearch {
- slf.Id = id
+func (slf *NetConfigSearch) SetId(id uint) *NetConfigSearch {
+ slf.ID = id
return slf
}
func (slf *NetConfigSearch) build() *gorm.DB {
var db = slf.Orm.Model(&NetConfig{})
-
+ if slf.ID > 0 {
+ db = db.Where("id = ?", slf.ID)
+ }
return db
}
@@ -171,7 +172,10 @@
func (slf *NetConfigSearch) CreateBatch(records []*NetConfig) error {
var db = slf.build()
- return db.Create(records).Error
+ for _, record := range records{
+ db.Create(record)
+ }
+ return nil
}
// InitDefaultData 鍒濆鍖栨暟鎹�
@@ -191,7 +195,6 @@
}
records := []*NetConfig{
{
- Id: 1,
NetworkCard: "enp3s0",
IP: "",
MASK: "",
@@ -200,8 +203,7 @@
Status: 0,
},
{
- Id: 2,
- NetworkCard: "",
+ NetworkCard: "enp2s0",
IP: "",
MASK: "",
Gateway: "",
--
Gitblit v1.8.0