From 5c3363a5b034a07ec9cfca6a7a269a7720827ef9 Mon Sep 17 00:00:00 2001 From: thesai <1021828630@qq.com> Date: Fri, 23 Feb 2024 09:22:07 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=86=E9=A1=B5=E6=9F=A5=E8=AF=A2=E8=BF=94?= =?UTF-8?q?=E5=9B=9E=E5=80=BCjson=E5=BA=8F=E5=88=97=E5=8C=96=E9=80=BB?= =?UTF-8?q?=E8=BE=91=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/bj_local_pxf.yml | 37 +++++++++++++++++++++++++++++++++++++ config/dev.yml | 4 ++-- dto/common.go | 11 +++++++++-- service/auth.go | 8 ++++---- service/category.go | 4 ++-- service/drafting.go | 4 ++-- service/project.go | 4 ++-- service/projectRunConfig.go | 4 ++-- service/publishedGi.go | 4 ++-- service/trainManage.go | 4 ++-- service/user.go | 4 ++-- 11 files changed, 66 insertions(+), 22 deletions(-) create mode 100644 config/bj_local_pxf.yml diff --git a/config/bj_local_pxf.yml b/config/bj_local_pxf.yml new file mode 100644 index 0000000..a38bc7b --- /dev/null +++ b/config/bj_local_pxf.yml @@ -0,0 +1,37 @@ +# 服务配置 +server: + # 服务端口 + port: 9091 + +# 数据源 +datasource: + # 数据库访问url + dsn: root:Joylink@0503@tcp(172.29.5.167:3306)/bj-rtsts?charset=utf8mb4&parseTime=true&loc=UTC + +# 日志配置 +logging: + # 日志级别 + level: info + # 格式化 + # format: json + # 日志文件路径 + path: /logs/bjrtsts + # 日志文件名 + fileName: bjrtsts.log + # 单个日志文件大小,单位mb,超过会自动滚动 + fileMaxSize: 50 + # 日志文件最大备份数量 + fileMaxBackups: 100 + # 日志文件最大保留时间,单位 天 + maxAge: 30 + # 是否压缩日志 + compress: false + # 控制台是否输出 + stdout: false + +# 消息配置 +messaging: + mqtt: + address: tcp://172.29.5.168:1883 + username: rtsts_service + password: joylink@0503 diff --git a/config/dev.yml b/config/dev.yml index 14d442f..915ee7b 100644 --- a/config/dev.yml +++ b/config/dev.yml @@ -6,7 +6,7 @@ server: # 数据源 datasource: # 数据库访问url - dsn: root:joylink0503@tcp(192.168.3.233:3306)/bj-rtss?charset=utf8mb4&parseTime=true&loc=UTC + dsn: root:joylink0503@tcp(192.168.33.233:3306)/bj-rtss?charset=utf8mb4&parseTime=true&loc=UTC # 日志配置 logging: @@ -32,6 +32,6 @@ logging: # 消息配置 messaging: mqtt: - address: tcp://192.168.3.233:1883 + address: tcp://192.168.33.233:1883 username: rtsts_service password: joylink@0503 \ No newline at end of file diff --git a/dto/common.go b/dto/common.go index 9fc4afc..3374610 100644 --- a/dto/common.go +++ b/dto/common.go @@ -32,10 +32,17 @@ type PageQueryDto struct { Orders []OrderItem `form:"orders" json:"orders"` } -type PageDto struct { +type PageDto[T any] struct { Total int `form:"total" json:"total"` PageQueryDto - Records any `form:"records" json:"records"` + Records []T `form:"records" json:"records"` +} + +func (p *PageDto[T]) MarshalJSON() ([]byte, error) { + if p.Records == nil { + p.Records = make([]T, 0) + } + return json.Marshal(*p) } type JsonTime time.Time diff --git a/service/auth.go b/service/auth.go index ed5298e..84ba194 100644 --- a/service/auth.go +++ b/service/auth.go @@ -11,13 +11,13 @@ import ( ) // 查询权限角色信息列表 -func PageAuthRoleQuery(query *dto.PageQueryDto) *dto.PageDto { +func PageAuthRoleQuery(query *dto.PageQueryDto) *dto.PageDto[*dto.AuthRoleRspDto] { d := dbquery.AuthRole records, total, err := d.Debug().Select(d.ID, d.Name).Order(d.CreateTime).FindByPage(query.Offset(), query.Size) if err != nil { panic(sys_error.New("查询权限数据库出错,请联系维护人员", err)) } - return &dto.PageDto{Total: int(total), PageQueryDto: *query, Records: dto.ConvertFromAuthRole(records)} + return &dto.PageDto[*dto.AuthRoleRspDto]{Total: int(total), PageQueryDto: *query, Records: dto.ConvertFromAuthRole(records)} } // 获取角色列表 @@ -143,7 +143,7 @@ func DeleteAuthRole(rid int32) bool { } // 查询接口路径信息列表 -func PageAuthApiPathQuery(query *dto.AuthApiPathPageReqDto) *dto.PageDto { +func PageAuthApiPathQuery(query *dto.AuthApiPathPageReqDto) *dto.PageDto[*model.AuthAPIPath] { d := dbquery.AuthAPIPath dq := d.Where() if query.Name != "" { @@ -153,7 +153,7 @@ func PageAuthApiPathQuery(query *dto.AuthApiPathPageReqDto) *dto.PageDto { if err != nil { panic(dto.ErrorDto{Code: dto.DataOperationError, Message: err.Error()}) } - return &dto.PageDto{Total: int(total), PageQueryDto: query.PageQueryDto, Records: records} + return &dto.PageDto[*model.AuthAPIPath]{Total: int(total), PageQueryDto: query.PageQueryDto, Records: records} } // 查询接口路径信息列表 diff --git a/service/category.go b/service/category.go index bb36c33..c258ad3 100644 --- a/service/category.go +++ b/service/category.go @@ -10,7 +10,7 @@ import ( ) // 查询草稿列表 -func PageCategoryQuery(query *dto.PageCategoryReqDto) *dto.PageDto { +func PageCategoryQuery(query *dto.PageCategoryReqDto) *dto.PageDto[*model.Category] { d := dbquery.Category dq := d.Where() if query.Name != "" { @@ -20,7 +20,7 @@ func PageCategoryQuery(query *dto.PageCategoryReqDto) *dto.PageDto { if err != nil { panic(dto.ErrorDto{Code: dto.QueryDBError, Message: err.Error()}) } - return &dto.PageDto{Total: int(total), PageQueryDto: query.PageQueryDto, Records: records} + return &dto.PageDto[*model.Category]{Total: int(total), PageQueryDto: query.PageQueryDto, Records: records} } // 查询草稿列表 diff --git a/service/drafting.go b/service/drafting.go index 47fad29..f04a1ce 100644 --- a/service/drafting.go +++ b/service/drafting.go @@ -11,7 +11,7 @@ import ( ) // 查询草稿列表 -func PageDraftingQuery(query *dto.PageDraftingReqDto) *dto.PageDto { +func PageDraftingQuery(query *dto.PageDraftingReqDto) *dto.PageDto[*dto.DraftingResDto] { d, u := dbquery.Drafting, dbquery.User dq := d.LeftJoin(u, u.ID.EqCol(d.CreatorID)). Select(d.ID, d.Name, d.Category, d.Type, d.CreatorID, d.CreatedAt, d.UpdateAt, u.Name.As("creator")). @@ -24,7 +24,7 @@ func PageDraftingQuery(query *dto.PageDraftingReqDto) *dto.PageDto { if err != nil { panic(sys_error.New("草稿查询错误", err)) } - return &dto.PageDto{Total: int(total), PageQueryDto: query.PageQueryDto, Records: records} + return &dto.PageDto[*dto.DraftingResDto]{Total: int(total), PageQueryDto: query.PageQueryDto, Records: records} } func ListDraftingQuery(query *dto.ListDraftingReqDto) []*model.Drafting { diff --git a/service/project.go b/service/project.go index 5472840..8ec6248 100644 --- a/service/project.go +++ b/service/project.go @@ -11,7 +11,7 @@ import ( ) // 查询项目列表 -func PageProjectQuery(query *dto.PageProjectReqDto) *dto.PageDto { +func PageProjectQuery(query *dto.PageProjectReqDto) *dto.PageDto[*model.Project] { d := dbquery.Project dq := d.Where() if query.Name != "" { @@ -24,7 +24,7 @@ func PageProjectQuery(query *dto.PageProjectReqDto) *dto.PageDto { if err != nil { panic(sys_error.New("查询失败,数据库异常", err)) } - return &dto.PageDto{Total: int(total), PageQueryDto: query.PageQueryDto, Records: records} + return &dto.PageDto[*model.Project]{Total: int(total), PageQueryDto: query.PageQueryDto, Records: records} } // 查询项目列表 diff --git a/service/projectRunConfig.go b/service/projectRunConfig.go index 94210dc..be42cd8 100644 --- a/service/projectRunConfig.go +++ b/service/projectRunConfig.go @@ -11,7 +11,7 @@ import ( ) // 查询项目运行环境列表带分页 -func PageProjectRunConfigQuery(query *dto.PageProjectRunConfigReqDto) *dto.PageDto { +func PageProjectRunConfigQuery(query *dto.PageProjectRunConfigReqDto) *dto.PageDto[*dto.ProjectRunConfigDto] { d := dbquery.ProjectRunConfig dq := d.Where() if query.Name != "" { @@ -21,7 +21,7 @@ func PageProjectRunConfigQuery(query *dto.PageProjectRunConfigReqDto) *dto.PageD if err != nil { panic(sys_error.New("查询失败,数据库错误请联系运维人员", err)) } - return &dto.PageDto{Total: int(total), PageQueryDto: query.PageQueryDto, Records: dto.ConvertToRunConfigFromSlice(records)} + return &dto.PageDto[*dto.ProjectRunConfigDto]{Total: int(total), PageQueryDto: query.PageQueryDto, Records: dto.ConvertToRunConfigFromSlice(records)} } // 查询项目运行环境列表 diff --git a/service/publishedGi.go b/service/publishedGi.go index 8e597a0..2f458f7 100644 --- a/service/publishedGi.go +++ b/service/publishedGi.go @@ -14,7 +14,7 @@ import ( var publishMapMutex sync.Mutex // 查找发布地图分页信息 -func PageQueryPublished(req *dto.PagePublishedReqDto) *dto.PageDto { +func PageQueryPublished(req *dto.PagePublishedReqDto) *dto.PageDto[*dto.PublishedDto] { p, pv, u := dbquery.Published, dbquery.PublishedVersion, dbquery.User where := p. Select( @@ -35,7 +35,7 @@ func PageQueryPublished(req *dto.PagePublishedReqDto) *dto.PageDto { if err != nil { panic(sys_error.New("查询发布地图信息失败", err)) } - return &dto.PageDto{Total: int(count), PageQueryDto: req.PageQueryDto, Records: records} + return &dto.PageDto[*dto.PublishedDto]{Total: int(count), PageQueryDto: req.PageQueryDto, Records: records} } // 地图信息列表信息 diff --git a/service/trainManage.go b/service/trainManage.go index 22ee81f..0fb2c66 100644 --- a/service/trainManage.go +++ b/service/trainManage.go @@ -16,7 +16,7 @@ import ( var trainDataType = int32(data_proto.PictureType_TrainData) // 查询列车信息列表 -func PageTrainInfoByPublished(query *dto.PageTrainInfoReqDto) *dto.PageDto { +func PageTrainInfoByPublished(query *dto.PageTrainInfoReqDto) *dto.PageDto[*dto.TrainInfoDto] { d, dv := dbquery.Published, dbquery.PublishedVersion dq := d.Select(d.ID, d.Code.As("name"), dv.Note, dv.Proto). LeftJoin(dv, d.DataID.EqCol(dv.ID)). @@ -30,7 +30,7 @@ func PageTrainInfoByPublished(query *dto.PageTrainInfoReqDto) *dto.PageDto { if err != nil { panic(sys_error.New("列车信息查询错误", err)) } - return &dto.PageDto{Total: int(total), PageQueryDto: query.PageQueryDto, Records: dto.ConvertToTrainDto(records)} + return &dto.PageDto[*dto.TrainInfoDto]{Total: int(total), PageQueryDto: query.PageQueryDto, Records: dto.ConvertToTrainDto(records)} } // 根据项目Id查询列车信息 diff --git a/service/user.go b/service/user.go index 832f0df..16599d7 100644 --- a/service/user.go +++ b/service/user.go @@ -12,7 +12,7 @@ import ( ) // 分页查询用户列表 -func PagingQueryUser(query *dto.PageUserReqDto) (*dto.PageDto, error) { +func PagingQueryUser(query *dto.PageUserReqDto) (*dto.PageDto[*dto.UserRspDto], error) { u := dbquery.User uq := u.Where() if query.Name != "" { @@ -25,7 +25,7 @@ func PagingQueryUser(query *dto.PageUserReqDto) (*dto.PageDto, error) { if err != nil { panic(dto.ErrorDto{Code: dto.QueryDBError, Message: err.Error()}) } - return &dto.PageDto{Total: int(total), PageQueryDto: query.PageQueryDto, Records: linkUserRole(records)}, err + return &dto.PageDto[*dto.UserRspDto]{Total: int(total), PageQueryDto: query.PageQueryDto, Records: linkUserRole(records)}, err } func Register(user *dto.RegisterUser) error {