This commit is contained in:
xiangheng
2024-04-22 02:25:56 +08:00
parent 762a1b1c10
commit 174c8a83c7
5 changed files with 73 additions and 143 deletions

View File

@@ -32,7 +32,7 @@ type MonitorClientAddReq struct {
Width int `form:"width"` // 屏幕 Width int `form:"width"` // 屏幕
Height int `form:"height"` // 屏幕高度 Height int `form:"height"` // 屏幕高度
Ua string `form:"ua"` // ua记录 Ua string `form:"ua"` // ua记录
ClientTime core.TsTime `form:"clientTime"` // 客户端时间 ClientTime string `form:"clientTime"` // 客户端时间
} }
//MonitorClientEditReq 客户端信息编辑参数 //MonitorClientEditReq 客户端信息编辑参数
@@ -47,7 +47,7 @@ type MonitorClientEditReq struct {
Width int `form:"width"` // 屏幕 Width int `form:"width"` // 屏幕
Height int `form:"height"` // 屏幕高度 Height int `form:"height"` // 屏幕高度
Ua string `form:"ua"` // ua记录 Ua string `form:"ua"` // ua记录
ClientTime core.TsTime `form:"clientTime"` // 客户端时间 ClientTime string `form:"clientTime"` // 客户端时间
} }
//MonitorClientDelReq 客户端信息新增参数 //MonitorClientDelReq 客户端信息新增参数
@@ -67,6 +67,6 @@ type MonitorClientResp struct {
Width int `json:"width" structs:"width" excel:"name:屏幕;"` // 屏幕 Width int `json:"width" structs:"width" excel:"name:屏幕;"` // 屏幕
Height int `json:"height" structs:"height" excel:"name:屏幕高度;"` // 屏幕高度 Height int `json:"height" structs:"height" excel:"name:屏幕高度;"` // 屏幕高度
Ua string `json:"ua" structs:"ua" excel:"name:ua记录;"` // ua记录 Ua string `json:"ua" structs:"ua" excel:"name:ua记录;"` // ua记录
ClientTime int `json:"clientTime" structs:"clientTime" excel:"name:客户端时间;"` // 客户端时间 ClientTime core.TsTime `json:"clientTime" structs:"clientTime" excel:"name:客户端时间;"` // 客户端时间
CreateTime core.TsTime `json:"createTime" structs:"createTime" excel:"name:创建时间;"` // 创建时间 CreateTime core.TsTime `json:"createTime" structs:"createTime" excel:"name:创建时间;"` // 创建时间
} }

View File

@@ -76,38 +76,7 @@ func (service monitorClientService) List(page request.PageReq, listReq MonitorCl
offset := page.PageSize * (page.PageNo - 1) offset := page.PageSize * (page.PageNo - 1)
dbModel := service.GetModel(listReq) dbModel := service.GetModel(listReq)
// 查询
// dbModel := service.db.Model(&model.MonitorClient{})
// if listReq.ProjectKey != "" {
// dbModel = dbModel.Where("project_key = ?", listReq.ProjectKey)
// }
// if listReq.ClientId != "" {
// dbModel = dbModel.Where("client_id = ?", listReq.ClientId)
// }
// if listReq.UserId != "" {
// dbModel = dbModel.Where("user_id = ?", listReq.UserId)
// }
// if listReq.Os != "" {
// dbModel = dbModel.Where("os = ?", listReq.Os)
// }
// if listReq.Browser != "" {
// dbModel = dbModel.Where("browser = ?", listReq.Browser)
// }
// if listReq.City != "" {
// dbModel = dbModel.Where("city = ?", listReq.City)
// }
// if listReq.Width > 0 {
// dbModel = dbModel.Where("width = ?", listReq.Width)
// }
// if listReq.Height > 0 {
// dbModel = dbModel.Where("height = ?", listReq.Height)
// }
// if listReq.Ua != "" {
// dbModel = dbModel.Where("ua = ?", listReq.Ua)
// }
// if listReq.ClientTime > 0 {
// dbModel = dbModel.Where("client_time = ?", listReq.ClientTime)
// }
// 总数 // 总数
var count int64 var count int64
err := dbModel.Count(&count).Error err := dbModel.Count(&count).Error
@@ -160,6 +129,8 @@ func (service monitorClientService) Detail(id int) (res MonitorClientResp, e err
func (service monitorClientService) Add(addReq MonitorClientAddReq) (e error) { func (service monitorClientService) Add(addReq MonitorClientAddReq) (e error) {
var obj model.MonitorClient var obj model.MonitorClient
response.Copy(&obj, addReq) response.Copy(&obj, addReq)
obj.ClientTime = core.ToUnix(addReq.ClientTime)
err := service.db.Create(&obj).Error err := service.db.Create(&obj).Error
e = response.CheckMysqlErr(err) e = response.CheckMysqlErr(err)
if e != nil { if e != nil {
@@ -209,38 +180,6 @@ func (service monitorClientService) ExportFile(listReq MonitorClientListReq) (re
// 查询 // 查询
dbModel := service.GetModel(listReq) dbModel := service.GetModel(listReq)
// dbModel := service.db.Model(&model.MonitorClient{})
// if listReq.ProjectKey != "" {
// dbModel = dbModel.Where("project_key = ?", listReq.ProjectKey)
// }
// if listReq.ClientId != "" {
// dbModel = dbModel.Where("client_id = ?", listReq.ClientId)
// }
// if listReq.UserId != "" {
// dbModel = dbModel.Where("user_id = ?", listReq.UserId)
// }
// if listReq.Os != "" {
// dbModel = dbModel.Where("os = ?", listReq.Os)
// }
// if listReq.Browser != "" {
// dbModel = dbModel.Where("browser = ?", listReq.Browser)
// }
// if listReq.City != "" {
// dbModel = dbModel.Where("city = ?", listReq.City)
// }
// if listReq.Width > 0 {
// dbModel = dbModel.Where("width = ?", listReq.Width)
// }
// if listReq.Height > 0 {
// dbModel = dbModel.Where("height = ?", listReq.Height)
// }
// if listReq.Ua != "" {
// dbModel = dbModel.Where("ua = ?", listReq.Ua)
// }
// if listReq.ClientTime > 0 {
// dbModel = dbModel.Where("client_time = ?", listReq.ClientTime)
// }
// 数据 // 数据
var objs []model.MonitorClient var objs []model.MonitorClient
err := dbModel.Order("id asc").Find(&objs).Error err := dbModel.Order("id asc").Find(&objs).Error

View File

@@ -29,7 +29,7 @@ type MonitorWebAddReq struct {
Page string `form:"page"` // URL地址 Page string `form:"page"` // URL地址
Message string `form:"message"` // 错误消息 Message string `form:"message"` // 错误消息
Stack string `form:"stack"` // 错误堆栈 Stack string `form:"stack"` // 错误堆栈
ClientTime core.TsTime `form:"clientTime"` // 客户端时间 ClientTime string `form:"clientTime"` // 客户端时间
} }
//MonitorWebEditReq 错误收集error编辑参数 //MonitorWebEditReq 错误收集error编辑参数
@@ -41,7 +41,7 @@ type MonitorWebEditReq struct {
Page string `form:"page"` // URL地址 Page string `form:"page"` // URL地址
Message string `form:"message"` // 错误消息 Message string `form:"message"` // 错误消息
Stack string `form:"stack"` // 错误堆栈 Stack string `form:"stack"` // 错误堆栈
ClientTime core.TsTime `form:"clientTime"` // 客户端时间 ClientTime string `form:"clientTime"` // 客户端时间
} }
//MonitorWebDelReq 错误收集error新增参数 //MonitorWebDelReq 错误收集error新增参数

View File

@@ -2,10 +2,7 @@ package core
import ( import (
"encoding/json" "encoding/json"
"strconv"
"time" "time"
"github.com/gin-gonic/gin"
) )
const DateFormat = "2006-01-02" const DateFormat = "2006-01-02"
@@ -34,20 +31,6 @@ type OnlyRespTsTime time.Time
// return json.Marshal(tt) // return json.Marshal(tt)
// } // }
// //
// 实现自定义的解析逻辑
func (t *TsTime) Bind(ctx *gin.Context) error {
// 尝试从表单中获取时间字符串
str := ctx.Query("clientTime") // 对于GET请求使用Query对于POST请求使用PostForm
// 对于POST请求中的JSON体你应该使用 ShouldBindJSON 或其他相关的ShouldBind方法
// 假设传入的是UNIX时间戳的字符串形式
i, err := strconv.ParseInt(str, 10, 64)
if err != nil {
return err
}
*t = TsTime(i)
return nil
}
func (tst *TsTime) UnmarshalJSON(bs []byte) error { func (tst *TsTime) UnmarshalJSON(bs []byte) error {
var date string var date string
@@ -67,6 +50,15 @@ func (tst TsTime) MarshalJSON() ([]byte, error) {
return json.Marshal(tt) return json.Marshal(tt)
} }
// 通过时间字符串生成时间戳
func ToUnix(date string) int64 {
if date == "" {
return 0
}
tt, _ := time.ParseInLocation(TimeFormat, date, time.Local)
return tt.Unix()
}
func (otst OnlyRespTsTime) MarshalJSON() ([]byte, error) { func (otst OnlyRespTsTime) MarshalJSON() ([]byte, error) {
tt := time.Time(otst).Format(TimeFormat) tt := time.Time(otst).Format(TimeFormat)
return json.Marshal(tt) return json.Marshal(tt)

View File

@@ -2,7 +2,6 @@ package model
//MonitorClient 客户端信息实体 //MonitorClient 客户端信息实体
type MonitorClient struct { type MonitorClient struct {
Id int `gorm:"primarykey;comment:'uuid'" excel:"name:uuid;"` // uuid Id int `gorm:"primarykey;comment:'uuid'" excel:"name:uuid;"` // uuid
ProjectKey string `gorm:"comment:'项目key'" excel:"name:项目key;"` // 项目key ProjectKey string `gorm:"comment:'项目key'" excel:"name:项目key;"` // 项目key
@@ -23,7 +22,7 @@ type MonitorClient struct {
Ua string `gorm:"comment:'ua记录'" excel:"name:ua记录;"` // ua记录 Ua string `gorm:"comment:'ua记录'" excel:"name:ua记录;"` // ua记录
ClientTime int `gorm:"comment:'客户端时间'" excel:"name:客户端时间;"` // 客户端时间 ClientTime int64 `gorm:"comment:'客户端时间'" excel:"name:客户端时间;"` // 客户端时间
CreateTime int64 `gorm:"autoCreateTime;comment:'创建时间'" excel:"name:创建时间;"` // 创建时间 CreateTime int64 `gorm:"autoCreateTime;comment:'创建时间'" excel:"name:创建时间;"` // 创建时间