diff --git a/server/app/controller/admin_ctl/monitorController/monitor_client_ctl.go b/server/app/controller/admin_ctl/monitorController/monitor_client_ctl.go index fd73c5e..dc8c6c0 100644 --- a/server/app/controller/admin_ctl/monitorController/monitor_client_ctl.go +++ b/server/app/controller/admin_ctl/monitorController/monitor_client_ctl.go @@ -5,7 +5,6 @@ import ( "fmt" "net/http" "net/url" - "strconv" "strings" "time" "x_admin/app/schema/monitorSchema" @@ -112,7 +111,7 @@ func (hd *MonitorClientHandler) Detail(c *gin.Context) { if response.IsFailWithResp(c, util.VerifyUtil.VerifyQuery(c, &detailReq)) { return } - res, err, _ := hd.requestGroup.Do("MonitorClient:Detail:"+strconv.Itoa(detailReq.Id), func() (any, error) { + res, err, _ := hd.requestGroup.Do("MonitorClient:Detail:"+detailReq.Id, func() (any, error) { v, err := monitorService.MonitorClientService.Detail(detailReq.Id) return v, err }) diff --git a/server/app/controller/admin_ctl/monitorController/monitor_error_ctl.go b/server/app/controller/admin_ctl/monitorController/monitor_error_ctl.go index 14f85c9..3fc155e 100644 --- a/server/app/controller/admin_ctl/monitorController/monitor_error_ctl.go +++ b/server/app/controller/admin_ctl/monitorController/monitor_error_ctl.go @@ -4,7 +4,6 @@ import ( "encoding/json" "net/http" "net/url" - "strconv" "strings" "time" . "x_admin/app/schema/monitorSchema" @@ -87,7 +86,7 @@ func (hd *MonitorErrorHandler) Detail(c *gin.Context) { if response.IsFailWithResp(c, util.VerifyUtil.VerifyQuery(c, &detailReq)) { return } - res, err, _ := hd.requestGroup.Do("MonitorError:Detail:"+strconv.Itoa(detailReq.Id), func() (any, error) { + res, err, _ := hd.requestGroup.Do("MonitorError:Detail:"+detailReq.Id, func() (any, error) { v, err := monitorService.MonitorErrorService.Detail(detailReq.Id) return v, err }) diff --git a/server/app/controller/admin_ctl/monitorController/monitor_project_ctl.go b/server/app/controller/admin_ctl/monitorController/monitor_project_ctl.go index bd788d1..bc1ebc6 100644 --- a/server/app/controller/admin_ctl/monitorController/monitor_project_ctl.go +++ b/server/app/controller/admin_ctl/monitorController/monitor_project_ctl.go @@ -2,7 +2,6 @@ package monitorController import ( "net/http" - "strconv" "strings" "time" . "x_admin/app/schema/monitorSchema" @@ -84,7 +83,7 @@ func (hd *MonitorProjectHandler) Detail(c *gin.Context) { if response.IsFailWithResp(c, util.VerifyUtil.VerifyQuery(c, &detailReq)) { return } - res, err, _ := hd.requestGroup.Do("MonitorProject:Detail:"+strconv.Itoa(detailReq.Id), func() (any, error) { + res, err, _ := hd.requestGroup.Do("MonitorProject:Detail:"+detailReq.Id, func() (any, error) { v, err := monitorService.MonitorProjectService.Detail(detailReq.Id) return v, err }) diff --git a/server/app/schema/monitorSchema/monitor_client_schema.go b/server/app/schema/monitorSchema/monitor_client_schema.go index 73728a3..b685c0d 100644 --- a/server/app/schema/monitorSchema/monitor_client_schema.go +++ b/server/app/schema/monitorSchema/monitor_client_schema.go @@ -41,7 +41,7 @@ type MonitorClientAddReq struct { // MonitorClientEditReq 监控-客户端信息编辑参数 type MonitorClientEditReq struct { - Id int // uuid + Id string // uuid ProjectKey *string // 项目key ClientId *string // sdk生成的客户端id UserId *string // 用户id @@ -57,12 +57,12 @@ type MonitorClientEditReq struct { // MonitorClientDetailReq 监控-客户端信息详情参数 type MonitorClientDetailReq struct { - Id int // uuid + Id string // uuid } // MonitorClientDelReq 监控-客户端信息删除参数 type MonitorClientDelReq struct { - Id int // uuid + Id string // uuid } // MonitorClientDelReq 监控-客户端信息批量删除参数 @@ -72,7 +72,7 @@ type MonitorClientDelBatchReq struct { // MonitorClientResp 监控-客户端信息返回信息 type MonitorClientResp struct { - Id int // uuid + Id string // uuid ProjectKey string // 项目key ClientId string // sdk生成的客户端id UserId string // 用户id diff --git a/server/app/schema/monitorSchema/monitor_error_list_schema.go b/server/app/schema/monitorSchema/monitor_error_list_schema.go index 35199bc..29dbc85 100644 --- a/server/app/schema/monitorSchema/monitor_error_list_schema.go +++ b/server/app/schema/monitorSchema/monitor_error_list_schema.go @@ -15,7 +15,7 @@ type MonitorErrorListAddReq struct { // MonitorErrorListResp 错误对应的用户记录返回信息 type MonitorErrorListResp struct { - Id int // 项目id + Id string // 项目id Eid string // 错误id Cid string // 客户端id Width core.NullInt // 屏幕 diff --git a/server/app/schema/monitorSchema/monitor_error_schema.go b/server/app/schema/monitorSchema/monitor_error_schema.go index 47cae87..12fd8d5 100644 --- a/server/app/schema/monitorSchema/monitor_error_schema.go +++ b/server/app/schema/monitorSchema/monitor_error_schema.go @@ -32,12 +32,12 @@ type MonitorErrorAddReq struct { // MonitorErrorDetailReq 监控-错误列详情参数 type MonitorErrorDetailReq struct { - Id int // 错误id + Id string // 错误id } // MonitorErrorDelReq 监控-错误列删除参数 type MonitorErrorDelReq struct { - Id int // 错误id + Id string // 错误id } // MonitorErrorDelReq 监控-错误列批量删除参数 @@ -47,7 +47,7 @@ type MonitorErrorDelBatchReq struct { // MonitorErrorResp 监控-错误列返回信息 type MonitorErrorResp struct { - Id int // 错误id + Id string // 错误id ProjectKey string // 项目key EventType string // 事件类型 Path string // URL地址 diff --git a/server/app/schema/monitorSchema/monitor_project_schema.go b/server/app/schema/monitorSchema/monitor_project_schema.go index df7630c..98b16b8 100644 --- a/server/app/schema/monitorSchema/monitor_project_schema.go +++ b/server/app/schema/monitorSchema/monitor_project_schema.go @@ -26,7 +26,7 @@ type MonitorProjectAddReq struct { // MonitorProjectEditReq 监控项目编辑参数 type MonitorProjectEditReq struct { - Id int // 项目id + Id string // 项目id ProjectKey *string // 项目uuid ProjectName *string // 项目名称 ProjectType *string // 项目类型go java web node php 等 @@ -35,12 +35,12 @@ type MonitorProjectEditReq struct { // MonitorProjectDetailReq 监控项目详情参数 type MonitorProjectDetailReq struct { - Id int // 项目id + Id string // 项目id } // MonitorProjectDelReq 监控项目删除参数 type MonitorProjectDelReq struct { - Id int // 项目id + Id string // 项目id } // MonitorProjectDelReq 监控项目批量删除参数 @@ -50,7 +50,7 @@ type MonitorProjectDelBatchReq struct { // MonitorProjectResp 监控项目返回信息 type MonitorProjectResp struct { - Id int // 项目id + Id string // 项目id ProjectKey string // 项目uuid ProjectName string // 项目名称 ProjectType string // 项目类型go java web node php 等 diff --git a/server/app/service/monitorService/monitor_client_service.go b/server/app/service/monitorService/monitor_client_service.go index 63b4bfd..82b2e2e 100644 --- a/server/app/service/monitorService/monitor_client_service.go +++ b/server/app/service/monitorService/monitor_client_service.go @@ -145,7 +145,7 @@ func (service monitorClientService) DetailByClientId(ClientId string) (res monit } // Detail 监控-客户端信息详情 -func (service monitorClientService) Detail(Id int) (res monitorSchema.MonitorClientResp, e error) { +func (service monitorClientService) Detail(Id string) (res monitorSchema.MonitorClientResp, e error) { var obj = model.MonitorClient{} err := service.CacheUtil.GetCache(Id, &obj) if err != nil { @@ -164,7 +164,7 @@ func (service monitorClientService) Detail(Id int) (res monitorSchema.MonitorCli } // ErrorUser 监控-客户端信息详情 -func (service monitorClientService) ErrorUsers(error_id int) (res []monitorSchema.MonitorClientResp, e error) { +func (service monitorClientService) ErrorUsers(error_id string) (res []monitorSchema.MonitorClientResp, e error) { var obj = []monitorSchema.MonitorClientResp{} service.db.Raw("SELECT client.*,list.width,list.height,list.create_time AS create_time from x_monitor_error_list as list right join x_monitor_client as client on client.id = list.cid where list.eid = ? Order by list.id DESC LIMIT 0,20", error_id).Scan(&obj) @@ -173,13 +173,13 @@ func (service monitorClientService) ErrorUsers(error_id int) (res []monitorSchem } // Add 监控-客户端信息新增 -func (service monitorClientService) Add(addReq monitorSchema.MonitorClientAddReq) (createId int, e error) { +func (service monitorClientService) Add(addReq monitorSchema.MonitorClientAddReq) (createId string, e error) { var obj model.MonitorClient convert_util.Copy(&obj, addReq) err := service.db.Create(&obj).Error e = response.CheckMysqlErr(err) if e != nil { - return 0, e + return "", e } service.CacheUtil.SetCache(obj.Id, obj) service.CacheUtil.SetCache("ClientId:"+obj.ClientId, obj) @@ -188,7 +188,7 @@ func (service monitorClientService) Add(addReq monitorSchema.MonitorClientAddReq } // Del 监控-客户端信息删除 -func (service monitorClientService) Del(Id int) (e error) { +func (service monitorClientService) Del(Id string) (e error) { var obj model.MonitorClient err := service.db.Where("id = ?", Id).Limit(1).First(&obj).Error // 校验 diff --git a/server/app/service/monitorService/monitor_error_list_service.go b/server/app/service/monitorService/monitor_error_list_service.go index 43c1425..a7ab384 100644 --- a/server/app/service/monitorService/monitor_error_list_service.go +++ b/server/app/service/monitorService/monitor_error_list_service.go @@ -27,13 +27,13 @@ type monitorErrorListService struct { } // Add 错误对应的用户记录新增 -func (service monitorErrorListService) Add(addReq monitorSchema.MonitorErrorListAddReq) (createId int, e error) { +func (service monitorErrorListService) Add(addReq monitorSchema.MonitorErrorListAddReq) (createId string, e error) { var obj model.MonitorErrorList convert_util.Copy(&obj, addReq) err := service.db.Create(&obj).Error e = response.CheckMysqlErr(err) if e != nil { - return 0, e + return "", e } createId = obj.Id diff --git a/server/app/service/monitorService/monitor_error_service.go b/server/app/service/monitorService/monitor_error_service.go index f822721..dbddbed 100644 --- a/server/app/service/monitorService/monitor_error_service.go +++ b/server/app/service/monitorService/monitor_error_service.go @@ -2,7 +2,6 @@ package monitorService import ( "errors" - "strconv" "x_admin/app/schema/monitorSchema" "x_admin/core" @@ -109,7 +108,7 @@ func (service monitorErrorService) ListAll(listReq monitorSchema.MonitorErrorLis } // Detail 监控-错误列详情 -func (service monitorErrorService) Detail(Id int) (res monitorSchema.MonitorErrorResp, e error) { +func (service monitorErrorService) Detail(Id string) (res monitorSchema.MonitorErrorResp, e error) { var obj = model.MonitorError{} err := service.db.Where("id = ?", Id).Limit(1).First(&obj).Error @@ -144,7 +143,7 @@ func (service monitorErrorService) DetailByMD5(md5 string) (res monitorSchema.Mo } // Add 监控-错误列新增 -func (service monitorErrorService) Add(addReq monitorSchema.MonitorErrorAddReq) (createId int, err error) { +func (service monitorErrorService) Add(addReq monitorSchema.MonitorErrorAddReq) (createId string, err error) { var obj model.MonitorError convert_util.Copy(&obj, addReq) @@ -159,7 +158,7 @@ func (service monitorErrorService) Add(addReq monitorSchema.MonitorErrorAddReq) err := service.db.Create(&obj).Error err = response.CheckMysqlErr(err) if err != nil { - return 0, err + return "", err } createId = obj.Id @@ -169,12 +168,12 @@ func (service monitorErrorService) Add(addReq monitorSchema.MonitorErrorAddReq) } client, err := MonitorClientService.DetailByClientId(addReq.ClientId) if err != nil { - return 0, err + return "", err } _, err = MonitorErrorListService.Add(monitorSchema.MonitorErrorListAddReq{ - Eid: strconv.Itoa(createId), - Cid: strconv.Itoa(client.Id), + Eid: createId, + Cid: client.Id, Width: addReq.Width, Height: addReq.Height, // ClientId: addReq.ClientId, @@ -185,7 +184,7 @@ func (service monitorErrorService) Add(addReq monitorSchema.MonitorErrorAddReq) } // Del 监控-错误列删除 -func (service monitorErrorService) Del(Id int) (e error) { +func (service monitorErrorService) Del(Id string) (e error) { var obj model.MonitorError err := service.db.Where("id = ?", Id).Limit(1).First(&obj).Error // 校验 diff --git a/server/app/service/monitorService/monitor_project_service.go b/server/app/service/monitorService/monitor_project_service.go index 31ee639..a5a4e0b 100644 --- a/server/app/service/monitorService/monitor_project_service.go +++ b/server/app/service/monitorService/monitor_project_service.go @@ -106,7 +106,7 @@ func (service monitorProjectService) ListAll(listReq monitorSchema.MonitorProjec } // Detail 监控项目详情 -func (service monitorProjectService) Detail(Id int) (res monitorSchema.MonitorProjectResp, e error) { +func (service monitorProjectService) Detail(Id string) (res monitorSchema.MonitorProjectResp, e error) { var obj = model.MonitorProject{} err := service.CacheUtil.GetCache(Id, &obj) if err != nil { @@ -125,14 +125,14 @@ func (service monitorProjectService) Detail(Id int) (res monitorSchema.MonitorPr } // Add 监控项目新增 -func (service monitorProjectService) Add(addReq monitorSchema.MonitorProjectAddReq) (createId int, e error) { +func (service monitorProjectService) Add(addReq monitorSchema.MonitorProjectAddReq) (createId string, e error) { var obj model.MonitorProject convert_util.Copy(&obj, addReq) obj.ProjectKey = util.ToolsUtil.MakeUuidV7() err := service.db.Create(&obj).Error e = response.CheckMysqlErr(err) if e != nil { - return 0, e + return "", e } service.CacheUtil.SetCache(obj.Id, obj) createId = obj.Id @@ -162,7 +162,7 @@ func (service monitorProjectService) Edit(editReq monitorSchema.MonitorProjectEd } // Del 监控项目删除 -func (service monitorProjectService) Del(Id int) (e error) { +func (service monitorProjectService) Del(Id string) (e error) { var obj model.MonitorProject err := service.db.Where("id = ? AND is_delete = ?", Id, 0).Limit(1).First(&obj).Error // 校验 diff --git a/server/model/monitor_client.go b/server/model/monitor_client.go index 5091916..f30bd7f 100644 --- a/server/model/monitor_client.go +++ b/server/model/monitor_client.go @@ -2,23 +2,34 @@ package model import ( "x_admin/core" + + "github.com/google/uuid" + "gorm.io/gorm" ) // MonitorClient 监控-客户端信息实体 type MonitorClient struct { - Id int `gorm:"primarykey;comment:'uuid'"` // uuid - ProjectKey string `gorm:"comment:'项目key'"` // 项目key - ClientId string `gorm:"comment:'sdk生成的客户端id'"` // sdk生成的客户端id - UserId string `gorm:"comment:'用户id'"` // 用户id - Os string `gorm:"comment:'系统'"` // 系统 - Browser string `gorm:"comment:'浏览器'"` // 浏览器 - Country string `gorm:"comment:'国家'"` // 国家 - Province string `gorm:"comment:'省份'"` // 省份 - City string `gorm:"comment:'城市'"` // 城市 - Operator string `gorm:"comment:'电信运营商'"` // 电信运营商 - Ip string `gorm:"comment:'ip'"` // ip - - Ua string `gorm:"comment:'ua记录'"` // ua记录 - CreateTime core.NullTime `gorm:"autoCreateTime;comment:'创建时间'"` // 创建时间 - // ClientTime core.NullTime `gorm:"comment:'更新时间'"` // 更新时间 + Id string `gorm:"primarykey;type:char(36);comment:'uuid'"` // uuid + ProjectKey string `gorm:"comment:'项目key'"` // 项目key + ClientId string `gorm:"comment:'sdk生成的客户端id'"` // sdk生成的客户端id + UserId string `gorm:"comment:'用户id'"` // 用户id + Os string `gorm:"comment:'系统'"` // 系统 + Browser string `gorm:"comment:'浏览器'"` // 浏览器 + Country string `gorm:"comment:'国家'"` // 国家 + Province string `gorm:"comment:'省份'"` // 省份 + City string `gorm:"comment:'城市'"` // 城市 + Operator string `gorm:"comment:'电信运营商'"` // 电信运营商 + Ip string `gorm:"comment:'ip'"` // ip + Ua string `gorm:"comment:'ua记录'"` // ua记录 + CreateTime core.NullTime `gorm:"autoCreateTime;comment:'创建时间'"` // 创建时间 +} + +// BeforeCreate 在创建前生成UUIDv7 +func (m *MonitorClient) BeforeCreate(tx *gorm.DB) (err error) { + id, err := uuid.NewV7() + if err != nil { + return err + } + m.Id = id.String() + return nil } diff --git a/server/model/monitor_error.go b/server/model/monitor_error.go index 149504e..632571b 100644 --- a/server/model/monitor_error.go +++ b/server/model/monitor_error.go @@ -2,16 +2,29 @@ package model import ( "x_admin/core" + + "github.com/google/uuid" + "gorm.io/gorm" ) // MonitorError 监控-错误列实体 type MonitorError struct { - Id int `gorm:"primarykey;comment:'错误id'"` // 错误id - ProjectKey string `gorm:"comment:'项目key'"` // 项目key - EventType string `gorm:"comment:'事件类型'"` // 事件类型 - Path string `gorm:"comment:'URL地址'"` // URL地址 - Message string `gorm:"comment:'错误消息'"` // 错误消息 - Stack string `gorm:"comment:'错误堆栈'"` // 错误堆栈 - Md5 string `gorm:"comment:'md5'"` // md5 - CreateTime core.NullTime `gorm:"autoCreateTime;comment:'创建时间'"` // 创建时间 + Id string `gorm:"primarykey;type:char(36);comment:'错误id'"` // 错误id + ProjectKey string `gorm:"comment:'项目key'"` // 项目key + EventType string `gorm:"comment:'事件类型'"` // 事件类型 + Path string `gorm:"comment:'URL地址'"` // URL地址 + Message string `gorm:"comment:'错误消息'"` // 错误消息 + Stack string `gorm:"comment:'错误堆栈'"` // 错误堆栈 + Md5 string `gorm:"comment:'md5'"` // md5 + CreateTime core.NullTime `gorm:"autoCreateTime;comment:'创建时间'"` // 创建时间 +} + +// BeforeCreate 在创建前生成UUIDv7 +func (m *MonitorError) BeforeCreate(tx *gorm.DB) (err error) { + id, err := uuid.NewV7() + if err != nil { + return err + } + m.Id = id.String() + return nil } diff --git a/server/model/monitor_error_list.go b/server/model/monitor_error_list.go index 5b18e8b..a075c86 100644 --- a/server/model/monitor_error_list.go +++ b/server/model/monitor_error_list.go @@ -2,14 +2,27 @@ package model import ( "x_admin/core" + + "github.com/google/uuid" + "gorm.io/gorm" ) // MonitorErrorList 错误对应的用户记录实体 type MonitorErrorList struct { - Id int `gorm:"primarykey;comment:'id'"` - Eid string `gorm:"comment:'错误id'"` // 错误表id - Cid string `gorm:"comment:'客户端id'"` // 客户端表id - Width core.NullInt `gorm:"comment:'屏幕'"` // 屏幕 - Height core.NullInt `gorm:"comment:'屏幕高度'"` // 屏幕高度 - CreateTime core.NullTime `gorm:"autoCreateTime;comment:'创建时间'"` // 创建时间 + Id string `gorm:"primarykey;type:char(36);comment:'id'"` // id + Eid string `gorm:"comment:'错误id'"` // 错误表id + Cid string `gorm:"comment:'客户端id'"` // 客户端表id + Width core.NullInt `gorm:"comment:'屏幕'"` // 屏幕 + Height core.NullInt `gorm:"comment:'屏幕高度'"` // 屏幕高度 + CreateTime core.NullTime `gorm:"autoCreateTime;comment:'创建时间'"` // 创建时间 +} + +// BeforeCreate 在创建前生成UUIDv7 +func (m *MonitorErrorList) BeforeCreate(tx *gorm.DB) (err error) { + id, err := uuid.NewV7() + if err != nil { + return err + } + m.Id = id.String() + return nil } diff --git a/server/model/monitor_project.go b/server/model/monitor_project.go index 86448f2..07f820b 100644 --- a/server/model/monitor_project.go +++ b/server/model/monitor_project.go @@ -3,18 +3,30 @@ package model import ( "x_admin/core" + "github.com/google/uuid" + "gorm.io/gorm" "gorm.io/plugin/soft_delete" ) // MonitorProject 监控项目实体 type MonitorProject struct { - Id int `gorm:"primarykey;comment:'项目id'"` // 项目id - ProjectKey string `gorm:"comment:'项目uuid'"` // 项目uuid - ProjectName string `gorm:"comment:'项目名称'"` // 项目名称 - ProjectType string `gorm:"comment:'项目类型go java web node php 等'"` // 项目类型go java web node php 等 - Status core.NullInt `gorm:"comment:'是否启用: 0=否, 1=是'"` // 是否启用: 0=否, 1=是 + Id string `gorm:"primarykey;type:char(36);comment:'项目id'"` // 项目id + ProjectKey string `gorm:"comment:'项目uuid'"` // 项目uuid + ProjectName string `gorm:"comment:'项目名称'"` // 项目名称 + ProjectType string `gorm:"comment:'项目类型go java web node php 等'"` // 项目类型go java web node php 等 + Status core.NullInt `gorm:"comment:'是否启用: 0=否, 1=是'"` // 是否启用: 0=否, 1=是 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:'删除时间'"` // 删除时间 } + +// BeforeCreate 在创建前生成UUIDv7 +func (m *MonitorProject) BeforeCreate(tx *gorm.DB) (err error) { + id, err := uuid.NewV7() + if err != nil { + return err + } + m.Id = id.String() + return nil +} diff --git a/server/model/monitor_slow.go b/server/model/monitor_slow.go deleted file mode 100644 index 72b0d37..0000000 --- a/server/model/monitor_slow.go +++ /dev/null @@ -1,16 +0,0 @@ -package model - -import ( - "x_admin/core" -) - -// MonitorSlow 监控-错误列实体 -type MonitorSlow struct { - Id int `gorm:"primarykey;comment:'错误id'"` // 错误id - ProjectKey string `gorm:"comment:'项目key'"` // 项目key - ClientId string `gorm:"comment:'sdk生成的客户端id'"` // sdk生成的客户端id - UserId string `gorm:"comment:'用户id'"` // 用户id - Path string `gorm:"comment:'URL地址'"` // URL地址 - Time core.NullFloat `gorm:"comment:'时间'"` // 时间 - CreateTime core.NullTime `gorm:"autoCreateTime;comment:'创建时间'"` // 创建时间 -}