From c0c45a72a621f25403f45febaaad75e36d13a8d5 Mon Sep 17 00:00:00 2001 From: xh <11675084@qq.com> Date: Tue, 24 Jun 2025 11:51:03 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- admin/package.json | 2 +- admin/src/layout/default/index.vue | 1 - admin/src/views/monitor/client/index.vue | 18 +-------- admin/vite.config.ts | 7 ++-- server/.vscode/settings.json | 1 + .../monitor_client/monitor_client_service.go | 1 - .../monitor_error/monitor_error_service.go | 37 ++++++++++--------- server/go.mod | 12 ++---- server/go.sum | 6 +-- server/model/user_protocol.go | 20 +++++----- server/util/cache.go | 2 + server/util/excel2/excel_import.go | 7 ++++ 12 files changed, 53 insertions(+), 61 deletions(-) diff --git a/admin/package.json b/admin/package.json index d48ff99..78de25a 100644 --- a/admin/package.json +++ b/admin/package.json @@ -9,7 +9,7 @@ "preview": "vite preview --port 4173", "build": "node ./scripts/build.mjs", "type-check": "vue-tsc --noEmit --checkJs true --skipLibCheck", - "lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix --ignore-path .gitignore", + "lint": "eslint src --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts src --fix --ignore-path .gitignore", "preinstall": "npx only-allow pnpm", "outdated": "pnpm outdated" }, diff --git a/admin/src/layout/default/index.vue b/admin/src/layout/default/index.vue index 280ee0b..5fe23d7 100644 --- a/admin/src/layout/default/index.vue +++ b/admin/src/layout/default/index.vue @@ -22,5 +22,4 @@ import LayoutHeader from './components/header/index.vue' defineOptions({ name: 'LayoutDefault' }) - diff --git a/admin/src/views/monitor/client/index.vue b/admin/src/views/monitor/client/index.vue index feac66e..5b41928 100644 --- a/admin/src/views/monitor/client/index.vue +++ b/admin/src/views/monitor/client/index.vue @@ -208,13 +208,11 @@ diff --git a/admin/vite.config.ts b/admin/vite.config.ts index f411896..537f7ea 100644 --- a/admin/vite.config.ts +++ b/admin/vite.config.ts @@ -41,7 +41,7 @@ export default ({ mode }) => { }, { name: 'vue-router', - test:/node_modules\/vue-router/ + test: /node_modules\/vue-router/ }, { name: 'element-plus', @@ -84,9 +84,8 @@ export default ({ mode }) => { { name: '@wangeditor/editor', test: /node_modules\/@wangeditor/ - }, - - ], + } + ] // vue: ['vue'], // 'vue-router': ['vue-router'], // pinia: ['pinia'], diff --git a/server/.vscode/settings.json b/server/.vscode/settings.json index 2977aa6..a207a72 100644 --- a/server/.vscode/settings.json +++ b/server/.vscode/settings.json @@ -21,6 +21,7 @@ "mediumtext", "nvarchar", "oneof", + "primarykey", "qrtz", "rmvb", "singleflight", diff --git a/server/admin/monitor_client/monitor_client_service.go b/server/admin/monitor_client/monitor_client_service.go index 36069e8..6628cdc 100644 --- a/server/admin/monitor_client/monitor_client_service.go +++ b/server/admin/monitor_client/monitor_client_service.go @@ -164,7 +164,6 @@ func (service monitorClientService) Detail(Id int) (res MonitorClientResp, e err cacheUtil.SetCache(obj.Id, obj) cacheUtil.SetCache("ClientId:"+obj.ClientId, obj) } - convert_util.Copy(&res, obj) return } diff --git a/server/admin/monitor_error/monitor_error_service.go b/server/admin/monitor_error/monitor_error_service.go index 15b688a..b9a9a78 100644 --- a/server/admin/monitor_error/monitor_error_service.go +++ b/server/admin/monitor_error/monitor_error_service.go @@ -17,22 +17,25 @@ import ( ) var MonitorErrorService = NewMonitorErrorService() -var cacheUtil = util.CacheUtil{ - Name: MonitorErrorService.Name, -} + +// var cacheUtil = util.CacheUtil{ +// Name: MonitorErrorService.Name, +// } // NewMonitorErrorService 初始化 func NewMonitorErrorService() *monitorErrorService { return &monitorErrorService{ - db: core.GetDB(), - Name: "monitorError", + db: core.GetDB(), + CacheUtil: util.CacheUtil{ + Name: "monitorError", + }, } } // monitorErrorService 监控-错误列服务实现类 type monitorErrorService struct { - db *gorm.DB - Name string + db *gorm.DB + CacheUtil util.CacheUtil } // List 监控-错误列列表 @@ -112,7 +115,7 @@ func (service monitorErrorService) ListAll(listReq MonitorErrorListReq) (res []M // Detail 监控-错误列详情 func (service monitorErrorService) Detail(Id int) (res MonitorErrorResp, e error) { var obj = model.MonitorError{} - err := cacheUtil.GetCache(Id, &obj) + err := service.CacheUtil.GetCache(Id, &obj) if err != nil { err := service.db.Where("id = ?", Id).Limit(1).First(&obj).Error if e = response.CheckErrDBNotRecord(err, "数据不存在!"); e != nil { @@ -121,7 +124,7 @@ func (service monitorErrorService) Detail(Id int) (res MonitorErrorResp, e error if e = response.CheckErr(err, "获取详情失败"); e != nil { return } - cacheUtil.SetCache(obj.Id, obj) + service.CacheUtil.SetCache(obj.Id, obj) } convert_util.Copy(&res, obj) @@ -131,7 +134,7 @@ func (service monitorErrorService) Detail(Id int) (res MonitorErrorResp, e error // DetailByMD5 监控-错误列详情 func (service monitorErrorService) DetailByMD5(md5 string) (res MonitorErrorResp, e error) { var obj = model.MonitorError{} - err := cacheUtil.GetCache("md5:"+md5, &obj) + err := service.CacheUtil.GetCache("md5:"+md5, &obj) if err != nil { err := service.db.Where("md5 = ?", md5).Order("id DESC").Limit(1).First(&obj).Error if e = response.CheckErrDBNotRecord(err, "数据不存在!"); e != nil { @@ -140,7 +143,7 @@ func (service monitorErrorService) DetailByMD5(md5 string) (res MonitorErrorResp if e = response.CheckErr(err, "获取详情失败"); e != nil { return } - cacheUtil.SetCache("md5:"+md5, obj) + service.CacheUtil.SetCache("md5:"+md5, obj) } convert_util.Copy(&res, obj) @@ -166,8 +169,8 @@ func (service monitorErrorService) Add(addReq MonitorErrorAddReq) (createId int, return 0, err } createId = obj.Id - cacheUtil.SetCache(createId, obj) - cacheUtil.SetCache("md5:"+Md5, obj) + service.CacheUtil.SetCache(createId, obj) + service.CacheUtil.SetCache("md5:"+Md5, obj) } else { createId = errorDetails.Id } @@ -200,8 +203,8 @@ func (service monitorErrorService) Del(Id int) (e error) { // 删除 err = service.db.Delete(&obj).Error e = response.CheckErr(err, "删除失败") - cacheUtil.RemoveCache(obj.Id) - cacheUtil.RemoveCache("md5:" + obj.Md5) + service.CacheUtil.RemoveCache(obj.Id) + service.CacheUtil.RemoveCache("md5:" + obj.Md5) return } @@ -226,8 +229,8 @@ func (service monitorErrorService) DelBatch(Ids []string) (e error) { md5s = append(md5s, "md5:"+v.Md5) } // 删除缓存 - cacheUtil.RemoveCache(Ids) - cacheUtil.RemoveCache(md5s) + service.CacheUtil.RemoveCache(Ids) + service.CacheUtil.RemoveCache(md5s) return nil } diff --git a/server/go.mod b/server/go.mod index 20ee082..13c1e3c 100644 --- a/server/go.mod +++ b/server/go.mod @@ -1,8 +1,6 @@ module x_admin -go 1.21.4 - -toolchain go1.22.4 +go 1.24.2 require ( github.com/fatih/structs v1.1.0 @@ -30,7 +28,9 @@ require ( ) require ( - github.com/guregu/null/v5 v5.0.0 + github.com/duke-git/lancet/v2 v2.3.2 + github.com/lionsoul2014/ip2region/binding/golang v0.0.0-20240510055607-89e20ab7b6c6 + github.com/mitchellh/mapstructure v1.5.0 github.com/redis/go-redis/v9 v9.5.2 go.uber.org/ratelimit v0.3.1 golang.org/x/sync v0.7.0 @@ -47,7 +47,6 @@ require ( github.com/cloudwego/base64x v0.1.4 // indirect github.com/cloudwego/iasm v0.2.0 // indirect github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect - github.com/duke-git/lancet/v2 v2.3.2 // indirect github.com/fsnotify/fsnotify v1.7.0 // indirect github.com/gabriel-vasile/mimetype v1.4.3 // indirect github.com/gin-contrib/sse v0.1.0 // indirect @@ -65,12 +64,9 @@ require ( github.com/json-iterator/go v1.1.12 // indirect github.com/klauspost/cpuid/v2 v2.2.7 // indirect github.com/leodido/go-urn v1.4.0 // indirect - github.com/lionsoul2014/ip2region/binding/golang v0.0.0-20240510055607-89e20ab7b6c6 // indirect github.com/magiconair/properties v1.8.7 // indirect github.com/mailru/easyjson v0.7.7 // indirect github.com/mattn/go-isatty v0.0.20 // indirect - github.com/mitchellh/go-homedir v1.1.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/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect diff --git a/server/go.sum b/server/go.sum index 8577513..cdf9fbc 100644 --- a/server/go.sum +++ b/server/go.sum @@ -81,8 +81,6 @@ github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeN github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/guregu/null/v5 v5.0.0 h1:PRxjqyOekS11W+w/7Vfz6jgJE/BCwELWtgvOJzddimw= -github.com/guregu/null/v5 v5.0.0/go.mod h1:SjupzNy+sCPtwQTKWhUCqjhVCO69hpsl2QsZrWHjlwU= github.com/hashicorp/golang-lru v0.5.4/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4= github.com/hashicorp/golang-lru v1.0.2 h1:dV3g9Z/unq5DpblPpw+Oqcv4dU/1omnb4Ok8iPY6p1c= github.com/hashicorp/golang-lru v1.0.2/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4= @@ -127,8 +125,6 @@ github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWE github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/mattn/go-sqlite3 v1.14.3 h1:j7a/xn1U6TKA/PHHxqZuzh64CdtRc7rU9M+AvkOl5bA= github.com/mattn/go-sqlite3 v1.14.3/go.mod h1:WVKg1VTActs4Qso6iwGbiFih2UIHo0ENGwNd0Lj+XmI= -github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y= -github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= @@ -209,6 +205,8 @@ github.com/xuri/nfp v0.0.0-20230919160717-d98342af3f05/go.mod h1:WwHg+CVyzlv/TX9 github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= github.com/yusufpapurcu/wmi v1.2.3 h1:E1ctvB7uKFMOJw3fdOW32DwGE9I7t++CRUEMKvFoFiw= github.com/yusufpapurcu/wmi v1.2.3/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0= +go.uber.org/atomic v1.9.0 h1:ECmE8Bn/WFTYwEW/bpKD3M8VtR/zQVbavAoalC1PYyE= +go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE= go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0= diff --git a/server/model/user_protocol.go b/server/model/user_protocol.go index 70ac48f..5a559a1 100644 --- a/server/model/user_protocol.go +++ b/server/model/user_protocol.go @@ -1,17 +1,19 @@ package model + import ( "x_admin/core" + "gorm.io/plugin/soft_delete" ) -//UserProtocol 用户协议实体 +// UserProtocol 用户协议实体 type UserProtocol struct { - Id int `gorm:"primarykey;comment:''"` // - Title string `gorm:"comment:'标题'"` // 标题 - Content string `gorm:"comment:'协议内容'"` // 协议内容 - Sort core.NullFloat `gorm:"comment:'排序'"` // 排序 - IsDelete soft_delete.DeletedAt `gorm:"not null;default:0;softDelete:flag,DeletedAtField:DeleteTime;comment:'是否删除: 0=否, 1=是'"` - CreateTime core.NullTime `gorm:"autoCreateTime;comment:'创建时间'"` // 创建时间 - UpdateTime core.NullTime `gorm:"autoUpdateTime;comment:'更新时间'"` // 更新时间 - DeleteTime core.NullTime `gorm:"comment:'删除时间'"` // 删除时间 + Id int `gorm:"primarykey;comment:''"` // + Title string `gorm:"comment:'标题'"` // 标题 + Content string `gorm:"comment:'协议内容'"` // 协议内容 + Sort core.NullFloat `gorm:"comment:'排序'"` // 排序 + IsDelete soft_delete.DeletedAt `gorm:"not null;default:0;softDelete:flag,DeletedAtField:DeleteTime;comment:'是否删除: 0=否, 1=是'"` + CreateTime core.NullTime `gorm:"autoCreateTime;comment:'创建时间'"` // 创建时间 + UpdateTime core.NullTime `gorm:"autoUpdateTime;comment:'更新时间'"` // 更新时间 + DeleteTime core.NullTime `gorm:"comment:'删除时间'"` // 删除时间 } diff --git a/server/util/cache.go b/server/util/cache.go index 083abf2..77effbf 100644 --- a/server/util/cache.go +++ b/server/util/cache.go @@ -35,6 +35,8 @@ func (c CacheUtil) GetCache(key interface{}, obj interface{}) error { switch k := key.(type) { case int: cacheKey = strconv.Itoa(k) + case int64: + cacheKey = strconv.FormatInt(k, 10) case string: cacheKey = k default: diff --git a/server/util/excel2/excel_import.go b/server/util/excel2/excel_import.go index cfd4f31..2d115d2 100644 --- a/server/util/excel2/excel_import.go +++ b/server/util/excel2/excel_import.go @@ -11,6 +11,13 @@ import ( "github.com/xuri/excelize/v2" ) +/** + * @Description: 获取导入数据 + * @param file 上传的文件 + * @param dst 导入目标对象【传指针】 + * @param cols 列信息 + * @return err + */ func GetExcelData(file multipart.File, dst interface{}, cols []Col) (err error) { // 创建缓冲区 buf := new(bytes.Buffer)