Ver Fonte

同步告警,数据重复修复

sixian há 2 anos atrás
pai
commit
22195d07b4
3 ficheiros alterados com 11 adições e 3 exclusões
  1. 2 1
      .gitignore
  2. 6 1
      app/warn/dao/platformAlarmDao.go
  3. 3 1
      go.mod

+ 2 - 1
.gitignore

@@ -2,4 +2,5 @@
 log
 .idea
 go.sum
-main_demo.go
+main_demo.go
+/demo/

+ 6 - 1
app/warn/dao/platformAlarmDao.go

@@ -3,6 +3,7 @@ package dao
 import (
 	"errors"
 	"gorm.io/gorm"
+	"gorm.io/gorm/clause"
 	"iot_manager_service/app/warn/model"
 	"iot_manager_service/util/common"
 	"time"
@@ -80,7 +81,11 @@ func (a PlatformAlarm) GetMaxIdAndUpDateTime() (int64, string) {
 }
 
 func (a PlatformAlarm) BatchCreate(his []PlatformAlarm) error {
-	return Db.Debug().CreateInBatches(his, 1000).Error
+	db := Db.Debug()
+	db = db.Clauses(clause.OnConflict{
+		Columns: []clause.Column{{Name: "ID"}}, //  这里的列必须是唯一的,比如主键或是唯一索引
+	})
+	return db.CreateInBatches(his, 1000).Error
 }
 
 func (a PlatformAlarm) Update() error {

+ 3 - 1
go.mod

@@ -9,10 +9,12 @@ require (
 	github.com/golang-jwt/jwt v3.2.2+incompatible
 	github.com/lestrrat/go-file-rotatelogs v0.0.0-20180223000712-d3151e2a480f
 	github.com/minio/minio-go/v7 v7.0.43
+	github.com/mitchellh/mapstructure v1.5.0
 	github.com/mojocn/base64Captcha v1.3.5
 	github.com/robfig/cron v1.2.0
 	github.com/satori/go.uuid v1.2.0
 	github.com/sirupsen/logrus v1.9.0
+	gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df
 	gopkg.in/yaml.v2 v2.4.0
 	gorm.io/driver/mysql v1.4.4
 	gorm.io/gorm v1.24.1
@@ -44,7 +46,6 @@ require (
 	github.com/mattn/go-isatty v0.0.14 // indirect
 	github.com/minio/md5-simd v1.1.2 // indirect
 	github.com/minio/sha256-simd v1.0.0 // indirect
-	github.com/mitchellh/mapstructure v1.5.0 // indirect
 	github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
 	github.com/modern-go/reflect2 v1.0.2 // indirect
 	github.com/onsi/ginkgo v1.16.5 // indirect
@@ -60,5 +61,6 @@ require (
 	golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f // indirect
 	golang.org/x/text v0.3.7 // indirect
 	google.golang.org/protobuf v1.28.0 // indirect
+	gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc // indirect
 	gopkg.in/ini.v1 v1.66.6 // indirect
 )