mirror of
https://gitee.com/xiangheng/x_admin.git
synced 2025-10-05 16:17:00 +08:00
ConvertUtil独立为包convert_util
This commit is contained in:
@@ -5,7 +5,7 @@ import (
|
|||||||
"x_admin/core/request"
|
"x_admin/core/request"
|
||||||
"x_admin/core/response"
|
"x_admin/core/response"
|
||||||
"x_admin/model"
|
"x_admin/model"
|
||||||
"x_admin/util"
|
"x_admin/util/convert_util"
|
||||||
|
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
)
|
)
|
||||||
@@ -58,7 +58,7 @@ func (service ArticleCollectService) List(page request.PageReq, listReq ArticleC
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
result := []ArticleCollectResp{}
|
result := []ArticleCollectResp{}
|
||||||
util.ConvertUtil.Copy(&result, modelList)
|
convert_util.Copy(&result, modelList)
|
||||||
return response.PageResp{
|
return response.PageResp{
|
||||||
PageNo: page.PageNo,
|
PageNo: page.PageNo,
|
||||||
PageSize: page.PageSize,
|
PageSize: page.PageSize,
|
||||||
|
@@ -8,6 +8,7 @@ import (
|
|||||||
"x_admin/core/response"
|
"x_admin/core/response"
|
||||||
"x_admin/model/common_model"
|
"x_admin/model/common_model"
|
||||||
"x_admin/util"
|
"x_admin/util"
|
||||||
|
"x_admin/util/convert_util"
|
||||||
|
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
)
|
)
|
||||||
@@ -66,7 +67,7 @@ func (albSrv albumService) AlbumList(page request.PageReq, listReq CommonAlbumLi
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
albumResps := []CommonAlbumListResp{}
|
albumResps := []CommonAlbumListResp{}
|
||||||
util.ConvertUtil.Copy(&albumResps, albums)
|
convert_util.Copy(&albumResps, albums)
|
||||||
// TODO: engine默认local
|
// TODO: engine默认local
|
||||||
engine := "local"
|
engine := "local"
|
||||||
for i := 0; i < len(albumResps); i++ {
|
for i := 0; i < len(albumResps); i++ {
|
||||||
@@ -134,7 +135,7 @@ func (albSrv albumService) AlbumAdd(addReq CommonAlbumAddReq) (res uint, e error
|
|||||||
// core.Logger.Errorf("AlbumAdd Decode err: err=[%+v]", err)
|
// core.Logger.Errorf("AlbumAdd Decode err: err=[%+v]", err)
|
||||||
// return response.SystemError
|
// return response.SystemError
|
||||||
//}
|
//}
|
||||||
util.ConvertUtil.Copy(&alb, addReq)
|
convert_util.Copy(&alb, addReq)
|
||||||
err := albSrv.db.Create(&alb).Error
|
err := albSrv.db.Create(&alb).Error
|
||||||
if e = response.CheckErr(err, "Album添加失败"); e != nil {
|
if e = response.CheckErr(err, "Album添加失败"); e != nil {
|
||||||
return
|
return
|
||||||
@@ -173,14 +174,14 @@ func (albSrv albumService) CateList(listReq CommonCateListReq) (mapList []Common
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
cateResps := []CommonCateListResp{}
|
cateResps := []CommonCateListResp{}
|
||||||
util.ConvertUtil.Copy(&cateResps, cates)
|
convert_util.Copy(&cateResps, cates)
|
||||||
return cateResps, nil
|
return cateResps, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// CateAdd 分类新增
|
// CateAdd 分类新增
|
||||||
func (albSrv albumService) CateAdd(addReq CommonCateAddReq) (e error) {
|
func (albSrv albumService) CateAdd(addReq CommonCateAddReq) (e error) {
|
||||||
var cate common_model.AlbumCate
|
var cate common_model.AlbumCate
|
||||||
util.ConvertUtil.Copy(&cate, addReq)
|
convert_util.Copy(&cate, addReq)
|
||||||
err := albSrv.db.Create(&cate).Error
|
err := albSrv.db.Create(&cate).Error
|
||||||
e = response.CheckErr(err, "Cate添加失败")
|
e = response.CheckErr(err, "Cate添加失败")
|
||||||
return
|
return
|
||||||
|
@@ -4,7 +4,7 @@ import (
|
|||||||
"mime/multipart"
|
"mime/multipart"
|
||||||
"x_admin/admin/common/album"
|
"x_admin/admin/common/album"
|
||||||
"x_admin/plugin"
|
"x_admin/plugin"
|
||||||
"x_admin/util"
|
"x_admin/util/convert_util"
|
||||||
)
|
)
|
||||||
|
|
||||||
type IUploadService interface {
|
type IUploadService interface {
|
||||||
@@ -39,14 +39,14 @@ func (upSrv uploadService) uploadFile(file *multipart.FileHeader, folder string,
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
var addReq album.CommonAlbumAddReq
|
var addReq album.CommonAlbumAddReq
|
||||||
util.ConvertUtil.Copy(&addReq, upRes)
|
convert_util.Copy(&addReq, upRes)
|
||||||
addReq.Aid = aid
|
addReq.Aid = aid
|
||||||
addReq.Cid = cid
|
addReq.Cid = cid
|
||||||
var albumId uint
|
var albumId uint
|
||||||
if albumId, e = album.Service.AlbumAdd(addReq); e != nil {
|
if albumId, e = album.Service.AlbumAdd(addReq); e != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
util.ConvertUtil.Copy(&res, addReq)
|
convert_util.Copy(&res, addReq)
|
||||||
res.ID = albumId
|
res.ID = albumId
|
||||||
res.Path = upRes.Path
|
res.Path = upRes.Path
|
||||||
return res, nil
|
return res, nil
|
||||||
|
@@ -8,6 +8,7 @@ import (
|
|||||||
"x_admin/core/response"
|
"x_admin/core/response"
|
||||||
"x_admin/model"
|
"x_admin/model"
|
||||||
"x_admin/util"
|
"x_admin/util"
|
||||||
|
"x_admin/util/convert_util"
|
||||||
|
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
)
|
)
|
||||||
@@ -81,7 +82,7 @@ func (service flowApplyService) List(page request.PageReq, listReq FlowApplyList
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
result := []FlowApplyResp{}
|
result := []FlowApplyResp{}
|
||||||
util.ConvertUtil.Copy(&result, modelList)
|
convert_util.Copy(&result, modelList)
|
||||||
return response.PageResp{
|
return response.PageResp{
|
||||||
PageNo: page.PageNo,
|
PageNo: page.PageNo,
|
||||||
PageSize: page.PageSize,
|
PageSize: page.PageSize,
|
||||||
@@ -100,7 +101,7 @@ func (service flowApplyService) Detail(id int) (res FlowApplyResp, e error) {
|
|||||||
if e = response.CheckErr(err, "详情获取失败"); e != nil {
|
if e = response.CheckErr(err, "详情获取失败"); e != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
util.ConvertUtil.Copy(&res, obj)
|
convert_util.Copy(&res, obj)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -111,7 +112,7 @@ func (service flowApplyService) Add(addReq FlowApplyAddReq) (e error) {
|
|||||||
if e = response.CheckErrDBNotRecord(err, "模板不存在!"); e != nil {
|
if e = response.CheckErrDBNotRecord(err, "模板不存在!"); e != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
util.ConvertUtil.Copy(&obj, addReq)
|
convert_util.Copy(&obj, addReq)
|
||||||
// obj.FlowName = flow_template_resp.FlowName
|
// obj.FlowName = flow_template_resp.FlowName
|
||||||
obj.FlowGroup = flow_template_resp.FlowGroup
|
obj.FlowGroup = flow_template_resp.FlowGroup
|
||||||
obj.FlowRemark = flow_template_resp.FlowRemark
|
obj.FlowRemark = flow_template_resp.FlowRemark
|
||||||
@@ -136,7 +137,7 @@ func (service flowApplyService) Edit(editReq FlowApplyEditReq) (e error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
// 更新
|
// 更新
|
||||||
util.ConvertUtil.Copy(&obj, editReq)
|
convert_util.Copy(&obj, editReq)
|
||||||
err = service.db.Model(&obj).Updates(obj).Error
|
err = service.db.Model(&obj).Updates(obj).Error
|
||||||
e = response.CheckErr(err, "编辑失败")
|
e = response.CheckErr(err, "编辑失败")
|
||||||
return
|
return
|
||||||
|
@@ -14,6 +14,7 @@ import (
|
|||||||
"x_admin/model"
|
"x_admin/model"
|
||||||
"x_admin/model/system_model"
|
"x_admin/model/system_model"
|
||||||
"x_admin/util"
|
"x_admin/util"
|
||||||
|
"x_admin/util/convert_util"
|
||||||
|
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
)
|
)
|
||||||
@@ -93,7 +94,7 @@ func (service flowHistoryService) List(page request.PageReq, listReq FlowHistory
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
list := []FlowHistoryResp{}
|
list := []FlowHistoryResp{}
|
||||||
util.ConvertUtil.Copy(&list, modelList)
|
convert_util.Copy(&list, modelList)
|
||||||
return response.PageResp{
|
return response.PageResp{
|
||||||
PageNo: page.PageNo,
|
PageNo: page.PageNo,
|
||||||
PageSize: page.PageSize,
|
PageSize: page.PageSize,
|
||||||
@@ -122,7 +123,7 @@ func (service flowHistoryService) ListAll(listReq FlowHistoryListReq) (res []Flo
|
|||||||
if e = response.CheckErr(err, "获取列表失败"); e != nil {
|
if e = response.CheckErr(err, "获取列表失败"); e != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
util.ConvertUtil.Copy(&res, modelList)
|
convert_util.Copy(&res, modelList)
|
||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -136,14 +137,14 @@ func (service flowHistoryService) Detail(id int) (res FlowHistoryResp, e error)
|
|||||||
if e = response.CheckErr(err, "详情获取失败"); e != nil {
|
if e = response.CheckErr(err, "详情获取失败"); e != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
util.ConvertUtil.Copy(&res, obj)
|
convert_util.Copy(&res, obj)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add 流程历史新增
|
// Add 流程历史新增
|
||||||
func (service flowHistoryService) Add(addReq FlowHistoryAddReq) (e error) {
|
func (service flowHistoryService) Add(addReq FlowHistoryAddReq) (e error) {
|
||||||
var obj model.FlowHistory
|
var obj model.FlowHistory
|
||||||
util.ConvertUtil.Copy(&obj, addReq)
|
convert_util.Copy(&obj, addReq)
|
||||||
err := service.db.Create(&obj).Error
|
err := service.db.Create(&obj).Error
|
||||||
e = response.CheckErr(err, "添加失败")
|
e = response.CheckErr(err, "添加失败")
|
||||||
return
|
return
|
||||||
@@ -161,7 +162,7 @@ func (service flowHistoryService) Edit(editReq FlowHistoryEditReq) (e error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
// 更新
|
// 更新
|
||||||
util.ConvertUtil.Copy(&obj, editReq)
|
convert_util.Copy(&obj, editReq)
|
||||||
err = service.db.Model(&obj).Updates(obj).Error
|
err = service.db.Model(&obj).Updates(obj).Error
|
||||||
e = response.CheckErr(err, "编辑失败")
|
e = response.CheckErr(err, "编辑失败")
|
||||||
return
|
return
|
||||||
@@ -422,7 +423,7 @@ func (service flowHistoryService) Back(back BackReq) (e error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var obj model.FlowApply
|
var obj model.FlowApply
|
||||||
util.ConvertUtil.Copy(&obj, applyDetail)
|
convert_util.Copy(&obj, applyDetail)
|
||||||
obj.Status = 4
|
obj.Status = 4
|
||||||
err = tx.Save(&obj).Error
|
err = tx.Save(&obj).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@@ -5,7 +5,7 @@ import (
|
|||||||
"x_admin/core/request"
|
"x_admin/core/request"
|
||||||
"x_admin/core/response"
|
"x_admin/core/response"
|
||||||
"x_admin/model"
|
"x_admin/model"
|
||||||
"x_admin/util"
|
"x_admin/util/convert_util"
|
||||||
|
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
)
|
)
|
||||||
@@ -67,7 +67,7 @@ func (service flowTemplateService) List(page request.PageReq, listReq FlowTempla
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
result := []FlowTemplateResp{}
|
result := []FlowTemplateResp{}
|
||||||
util.ConvertUtil.Copy(&result, modelList)
|
convert_util.Copy(&result, modelList)
|
||||||
return response.PageResp{
|
return response.PageResp{
|
||||||
PageNo: page.PageNo,
|
PageNo: page.PageNo,
|
||||||
PageSize: page.PageSize,
|
PageSize: page.PageSize,
|
||||||
@@ -83,7 +83,7 @@ func (service flowTemplateService) ListAll() (res []FlowTemplateResp, e error) {
|
|||||||
if e = response.CheckErr(err, "获取列表失败"); e != nil {
|
if e = response.CheckErr(err, "获取列表失败"); e != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
util.ConvertUtil.Copy(&res, modelList)
|
convert_util.Copy(&res, modelList)
|
||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,14 +97,14 @@ func (service flowTemplateService) Detail(id int) (res FlowTemplateResp, e error
|
|||||||
if e = response.CheckErr(err, "详情获取失败"); e != nil {
|
if e = response.CheckErr(err, "详情获取失败"); e != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
util.ConvertUtil.Copy(&res, obj)
|
convert_util.Copy(&res, obj)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add 流程模板新增
|
// Add 流程模板新增
|
||||||
func (service flowTemplateService) Add(addReq FlowTemplateAddReq) (e error) {
|
func (service flowTemplateService) Add(addReq FlowTemplateAddReq) (e error) {
|
||||||
var obj model.FlowTemplate
|
var obj model.FlowTemplate
|
||||||
util.ConvertUtil.Copy(&obj, addReq)
|
convert_util.Copy(&obj, addReq)
|
||||||
err := service.db.Create(&obj).Error
|
err := service.db.Create(&obj).Error
|
||||||
e = response.CheckErr(err, "添加失败")
|
e = response.CheckErr(err, "添加失败")
|
||||||
return
|
return
|
||||||
@@ -122,7 +122,7 @@ func (service flowTemplateService) Edit(editReq FlowTemplateEditReq) (e error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
// 更新
|
// 更新
|
||||||
util.ConvertUtil.Copy(&obj, editReq)
|
convert_util.Copy(&obj, editReq)
|
||||||
err = service.db.Model(&obj).Updates(obj).Error
|
err = service.db.Model(&obj).Updates(obj).Error
|
||||||
e = response.CheckErr(err, "编辑失败")
|
e = response.CheckErr(err, "编辑失败")
|
||||||
return
|
return
|
||||||
|
@@ -9,6 +9,7 @@ import (
|
|||||||
"x_admin/core/request"
|
"x_admin/core/request"
|
||||||
"x_admin/core/response"
|
"x_admin/core/response"
|
||||||
"x_admin/model/gen_model"
|
"x_admin/model/gen_model"
|
||||||
|
"x_admin/util/convert_util"
|
||||||
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@@ -123,11 +124,11 @@ func (genSrv generateService) Detail(id uint) (res GenTableDetailResp, e error)
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
var base GenTableBaseResp
|
var base GenTableBaseResp
|
||||||
util.ConvertUtil.Copy(&base, genTb)
|
convert_util.Copy(&base, genTb)
|
||||||
var gen GenTableGenResp
|
var gen GenTableGenResp
|
||||||
util.ConvertUtil.Copy(&gen, genTb)
|
convert_util.Copy(&gen, genTb)
|
||||||
var colResp []GenColumnResp
|
var colResp []GenColumnResp
|
||||||
util.ConvertUtil.Copy(&colResp, columns)
|
convert_util.Copy(&colResp, columns)
|
||||||
return GenTableDetailResp{
|
return GenTableDetailResp{
|
||||||
Base: base,
|
Base: base,
|
||||||
Gen: gen,
|
Gen: gen,
|
||||||
@@ -143,7 +144,7 @@ func (genSrv generateService) ImportTable(tableNames []string) (e error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
var tables []gen_model.GenTable
|
var tables []gen_model.GenTable
|
||||||
util.ConvertUtil.Copy(&tables, dbTbs)
|
convert_util.Copy(&tables, dbTbs)
|
||||||
if len(tables) == 0 {
|
if len(tables) == 0 {
|
||||||
e = response.AssertArgumentError.SetMessage("表不存在!")
|
e = response.AssertArgumentError.SetMessage("表不存在!")
|
||||||
return
|
return
|
||||||
@@ -281,7 +282,7 @@ func (genSrv generateService) EditTable(editReq EditTableReq) (e error) {
|
|||||||
if e = response.CheckErr(err, "查找数据失败"); e != nil {
|
if e = response.CheckErr(err, "查找数据失败"); e != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
util.ConvertUtil.Copy(&genTable, editReq)
|
convert_util.Copy(&genTable, editReq)
|
||||||
err = genSrv.db.Transaction(func(tx *gorm.DB) error {
|
err = genSrv.db.Transaction(func(tx *gorm.DB) error {
|
||||||
genTable.SubTableName = strings.Replace(editReq.SubTableName, config.Config.DbTablePrefix, "", 1)
|
genTable.SubTableName = strings.Replace(editReq.SubTableName, config.Config.DbTablePrefix, "", 1)
|
||||||
txErr := tx.Save(&genTable).Error
|
txErr := tx.Save(&genTable).Error
|
||||||
@@ -290,7 +291,7 @@ func (genSrv generateService) EditTable(editReq EditTableReq) (e error) {
|
|||||||
}
|
}
|
||||||
for i := 0; i < len(editReq.Columns); i++ {
|
for i := 0; i < len(editReq.Columns); i++ {
|
||||||
var col gen_model.GenTableColumn
|
var col gen_model.GenTableColumn
|
||||||
util.ConvertUtil.Copy(&col, editReq.Columns[i])
|
convert_util.Copy(&col, editReq.Columns[i])
|
||||||
txErr = tx.Save(&col).Error
|
txErr = tx.Save(&col).Error
|
||||||
if te := response.CheckErr(txErr, "更新失败"); te != nil {
|
if te := response.CheckErr(txErr, "更新失败"); te != nil {
|
||||||
return te
|
return te
|
||||||
|
@@ -7,6 +7,7 @@ import (
|
|||||||
"x_admin/model"
|
"x_admin/model"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
"x_admin/util"
|
"x_admin/util"
|
||||||
|
"x_admin/util/convert_util"
|
||||||
"x_admin/util/excel2"
|
"x_admin/util/excel2"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -82,7 +83,7 @@ func (service {{{ toCamelCase .EntityName }}}Service) List(page request.PageReq,
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
result := []{{{ toUpperCamelCase .EntityName }}}Resp{}
|
result := []{{{ toUpperCamelCase .EntityName }}}Resp{}
|
||||||
util.ConvertUtil.Copy(&result, modelList)
|
convert_util.Copy(&result, modelList)
|
||||||
return response.PageResp{
|
return response.PageResp{
|
||||||
PageNo: page.PageNo,
|
PageNo: page.PageNo,
|
||||||
PageSize: page.PageSize,
|
PageSize: page.PageSize,
|
||||||
@@ -100,7 +101,7 @@ func (service {{{ toCamelCase .EntityName }}}Service) ListAll(listReq {{{ toUppe
|
|||||||
if e = response.CheckErr(err, "查询全部失败"); e != nil {
|
if e = response.CheckErr(err, "查询全部失败"); e != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
util.ConvertUtil.Copy(&res, modelList)
|
convert_util.Copy(&res, modelList)
|
||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -125,14 +126,14 @@ func (service {{{ toCamelCase .EntityName }}}Service) Detail({{{ toUpperCamelCas
|
|||||||
cacheUtil.SetCache(obj.{{{ toUpperCamelCase .PrimaryKey }}}, obj)
|
cacheUtil.SetCache(obj.{{{ toUpperCamelCase .PrimaryKey }}}, obj)
|
||||||
}
|
}
|
||||||
|
|
||||||
util.ConvertUtil.Copy(&res, obj)
|
convert_util.Copy(&res, obj)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add {{{ .FunctionName }}}新增
|
// Add {{{ .FunctionName }}}新增
|
||||||
func (service {{{ toCamelCase .EntityName }}}Service) Add(addReq {{{ toUpperCamelCase .EntityName }}}AddReq) (createId int,e error) {
|
func (service {{{ toCamelCase .EntityName }}}Service) Add(addReq {{{ toUpperCamelCase .EntityName }}}AddReq) (createId int,e error) {
|
||||||
var obj model.{{{ toUpperCamelCase .EntityName }}}
|
var obj model.{{{ toUpperCamelCase .EntityName }}}
|
||||||
util.ConvertUtil.StructToStruct(addReq,&obj)
|
convert_util.StructToStruct(addReq,&obj)
|
||||||
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 {
|
||||||
@@ -154,7 +155,7 @@ func (service {{{ toCamelCase .EntityName }}}Service) Edit(editReq {{{ toUpperCa
|
|||||||
if e = response.CheckErr(err, "查询失败"); e != nil {
|
if e = response.CheckErr(err, "查询失败"); e != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
util.ConvertUtil.Copy(&obj, editReq)
|
convert_util.Copy(&obj, editReq)
|
||||||
|
|
||||||
err = service.db.Model(&obj).Select("*").Updates(obj).Error
|
err = service.db.Model(&obj).Select("*").Updates(obj).Error
|
||||||
if e = response.CheckErr(err, "编辑失败"); e != nil {
|
if e = response.CheckErr(err, "编辑失败"); e != nil {
|
||||||
@@ -235,14 +236,14 @@ func (service {{{ toCamelCase .EntityName }}}Service) ExportFile(listReq {{{ toU
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
result := []{{{ toUpperCamelCase .EntityName }}}Resp{}
|
result := []{{{ toUpperCamelCase .EntityName }}}Resp{}
|
||||||
util.ConvertUtil.Copy(&result, modelList)
|
convert_util.Copy(&result, modelList)
|
||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 导入
|
// 导入
|
||||||
func (service {{{ toCamelCase .EntityName }}}Service) ImportFile(importReq []{{{ toUpperCamelCase .EntityName }}}Resp) (e error) {
|
func (service {{{ toCamelCase .EntityName }}}Service) ImportFile(importReq []{{{ toUpperCamelCase .EntityName }}}Resp) (e error) {
|
||||||
var importData []model.{{{ toUpperCamelCase .EntityName }}}
|
var importData []model.{{{ toUpperCamelCase .EntityName }}}
|
||||||
util.ConvertUtil.Copy(&importData, importReq)
|
convert_util.Copy(&importData, importReq)
|
||||||
err := service.db.Create(&importData).Error
|
err := service.db.Create(&importData).Error
|
||||||
e = response.CheckErr(err, "添加失败")
|
e = response.CheckErr(err, "添加失败")
|
||||||
return e
|
return e
|
||||||
|
@@ -7,6 +7,7 @@ import (
|
|||||||
"x_admin/core/response"
|
"x_admin/core/response"
|
||||||
"x_admin/model"
|
"x_admin/model"
|
||||||
"x_admin/util"
|
"x_admin/util"
|
||||||
|
"x_admin/util/convert_util"
|
||||||
"x_admin/util/excel2"
|
"x_admin/util/excel2"
|
||||||
|
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
@@ -103,7 +104,7 @@ func (service monitorClientService) List(page request.PageReq, listReq MonitorCl
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
result := []MonitorClientResp{}
|
result := []MonitorClientResp{}
|
||||||
util.ConvertUtil.Copy(&result, modelList)
|
convert_util.Copy(&result, modelList)
|
||||||
return response.PageResp{
|
return response.PageResp{
|
||||||
PageNo: page.PageNo,
|
PageNo: page.PageNo,
|
||||||
PageSize: page.PageSize,
|
PageSize: page.PageSize,
|
||||||
@@ -122,7 +123,7 @@ func (service monitorClientService) ListAll(listReq MonitorClientListReq) (res [
|
|||||||
if e = response.CheckErr(err, "查询全部失败"); e != nil {
|
if e = response.CheckErr(err, "查询全部失败"); e != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
util.ConvertUtil.Copy(&res, modelList)
|
convert_util.Copy(&res, modelList)
|
||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -144,7 +145,7 @@ func (service monitorClientService) DetailByClientId(ClientId string) (res Monit
|
|||||||
cacheUtil.SetCache("ClientId:"+obj.ClientId, obj)
|
cacheUtil.SetCache("ClientId:"+obj.ClientId, obj)
|
||||||
}
|
}
|
||||||
|
|
||||||
util.ConvertUtil.Copy(&res, obj)
|
convert_util.Copy(&res, obj)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -164,7 +165,7 @@ func (service monitorClientService) Detail(Id int) (res MonitorClientResp, e err
|
|||||||
cacheUtil.SetCache("ClientId:"+obj.ClientId, obj)
|
cacheUtil.SetCache("ClientId:"+obj.ClientId, obj)
|
||||||
}
|
}
|
||||||
|
|
||||||
util.ConvertUtil.Copy(&res, obj)
|
convert_util.Copy(&res, obj)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -173,14 +174,14 @@ func (service monitorClientService) ErrorUsers(error_id int) (res []MonitorClien
|
|||||||
var obj = []model.MonitorClient{}
|
var obj = []model.MonitorClient{}
|
||||||
service.db.Raw("SELECT client.*,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)
|
service.db.Raw("SELECT client.*,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)
|
||||||
|
|
||||||
util.ConvertUtil.Copy(&res, obj)
|
convert_util.Copy(&res, obj)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add 监控-客户端信息新增
|
// Add 监控-客户端信息新增
|
||||||
func (service monitorClientService) Add(addReq MonitorClientAddReq) (createId int, e error) {
|
func (service monitorClientService) Add(addReq MonitorClientAddReq) (createId int, e error) {
|
||||||
var obj model.MonitorClient
|
var obj model.MonitorClient
|
||||||
util.ConvertUtil.StructToStruct(addReq, &obj)
|
convert_util.StructToStruct(addReq, &obj)
|
||||||
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 {
|
||||||
@@ -268,14 +269,14 @@ func (service monitorClientService) ExportFile(listReq MonitorClientListReq) (re
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
result := []MonitorClientResp{}
|
result := []MonitorClientResp{}
|
||||||
util.ConvertUtil.Copy(&result, modelList)
|
convert_util.Copy(&result, modelList)
|
||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 导入
|
// 导入
|
||||||
func (service monitorClientService) ImportFile(importReq []MonitorClientResp) (e error) {
|
func (service monitorClientService) ImportFile(importReq []MonitorClientResp) (e error) {
|
||||||
var importData []model.MonitorClient
|
var importData []model.MonitorClient
|
||||||
util.ConvertUtil.Copy(&importData, importReq)
|
convert_util.Copy(&importData, importReq)
|
||||||
err := service.db.Create(&importData).Error
|
err := service.db.Create(&importData).Error
|
||||||
e = response.CheckErr(err, "添加失败")
|
e = response.CheckErr(err, "添加失败")
|
||||||
return e
|
return e
|
||||||
|
@@ -10,6 +10,7 @@ import (
|
|||||||
"x_admin/core/response"
|
"x_admin/core/response"
|
||||||
"x_admin/model"
|
"x_admin/model"
|
||||||
"x_admin/util"
|
"x_admin/util"
|
||||||
|
"x_admin/util/convert_util"
|
||||||
"x_admin/util/excel2"
|
"x_admin/util/excel2"
|
||||||
|
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
@@ -85,7 +86,7 @@ func (service monitorErrorService) List(page request.PageReq, listReq MonitorErr
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
result := []MonitorErrorResp{}
|
result := []MonitorErrorResp{}
|
||||||
util.ConvertUtil.Copy(&result, modelList)
|
convert_util.Copy(&result, modelList)
|
||||||
return response.PageResp{
|
return response.PageResp{
|
||||||
PageNo: page.PageNo,
|
PageNo: page.PageNo,
|
||||||
PageSize: page.PageSize,
|
PageSize: page.PageSize,
|
||||||
@@ -104,7 +105,7 @@ func (service monitorErrorService) ListAll(listReq MonitorErrorListReq) (res []M
|
|||||||
if e = response.CheckErr(err, "查询全部失败"); e != nil {
|
if e = response.CheckErr(err, "查询全部失败"); e != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
util.ConvertUtil.Copy(&res, modelList)
|
convert_util.Copy(&res, modelList)
|
||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -123,7 +124,7 @@ func (service monitorErrorService) Detail(Id int) (res MonitorErrorResp, e error
|
|||||||
cacheUtil.SetCache(obj.Id, obj)
|
cacheUtil.SetCache(obj.Id, obj)
|
||||||
}
|
}
|
||||||
|
|
||||||
util.ConvertUtil.Copy(&res, obj)
|
convert_util.Copy(&res, obj)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -142,7 +143,7 @@ func (service monitorErrorService) DetailByMD5(md5 string) (res MonitorErrorResp
|
|||||||
cacheUtil.SetCache("md5:"+md5, obj)
|
cacheUtil.SetCache("md5:"+md5, obj)
|
||||||
}
|
}
|
||||||
|
|
||||||
util.ConvertUtil.Copy(&res, obj)
|
convert_util.Copy(&res, obj)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -150,7 +151,7 @@ func (service monitorErrorService) DetailByMD5(md5 string) (res MonitorErrorResp
|
|||||||
func (service monitorErrorService) Add(addReq MonitorErrorAddReq) (createId int, err error) {
|
func (service monitorErrorService) Add(addReq MonitorErrorAddReq) (createId int, err error) {
|
||||||
|
|
||||||
var obj model.MonitorError
|
var obj model.MonitorError
|
||||||
util.ConvertUtil.StructToStruct(addReq, &obj)
|
convert_util.StructToStruct(addReq, &obj)
|
||||||
|
|
||||||
Md5 := util.ToolsUtil.MakeMd5(obj.ProjectKey + obj.EventType + obj.Message + obj.Path + obj.Stack)
|
Md5 := util.ToolsUtil.MakeMd5(obj.ProjectKey + obj.EventType + obj.Message + obj.Path + obj.Stack)
|
||||||
|
|
||||||
@@ -258,14 +259,14 @@ func (service monitorErrorService) ExportFile(listReq MonitorErrorListReq) (res
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
result := []MonitorErrorResp{}
|
result := []MonitorErrorResp{}
|
||||||
util.ConvertUtil.Copy(&result, modelList)
|
convert_util.Copy(&result, modelList)
|
||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 导入
|
// 导入
|
||||||
func (service monitorErrorService) ImportFile(importReq []MonitorErrorResp) (e error) {
|
func (service monitorErrorService) ImportFile(importReq []MonitorErrorResp) (e error) {
|
||||||
var importData []model.MonitorError
|
var importData []model.MonitorError
|
||||||
util.ConvertUtil.Copy(&importData, importReq)
|
convert_util.Copy(&importData, importReq)
|
||||||
err := service.db.Create(&importData).Error
|
err := service.db.Create(&importData).Error
|
||||||
e = response.CheckErr(err, "添加失败")
|
e = response.CheckErr(err, "添加失败")
|
||||||
return e
|
return e
|
||||||
|
@@ -4,7 +4,7 @@ import (
|
|||||||
"x_admin/core"
|
"x_admin/core"
|
||||||
"x_admin/core/response"
|
"x_admin/core/response"
|
||||||
"x_admin/model"
|
"x_admin/model"
|
||||||
"x_admin/util"
|
"x_admin/util/convert_util"
|
||||||
|
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
)
|
)
|
||||||
@@ -28,7 +28,7 @@ type monitorErrorListService struct {
|
|||||||
// Add 错误对应的用户记录新增
|
// Add 错误对应的用户记录新增
|
||||||
func (service monitorErrorListService) Add(addReq MonitorErrorListAddReq) (createId int, e error) {
|
func (service monitorErrorListService) Add(addReq MonitorErrorListAddReq) (createId int, e error) {
|
||||||
var obj model.MonitorErrorList
|
var obj model.MonitorErrorList
|
||||||
util.ConvertUtil.StructToStruct(addReq, &obj)
|
convert_util.StructToStruct(addReq, &obj)
|
||||||
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 {
|
||||||
|
@@ -6,6 +6,7 @@ import (
|
|||||||
"x_admin/core/response"
|
"x_admin/core/response"
|
||||||
"x_admin/model"
|
"x_admin/model"
|
||||||
"x_admin/util"
|
"x_admin/util"
|
||||||
|
"x_admin/util/convert_util"
|
||||||
"x_admin/util/excel2"
|
"x_admin/util/excel2"
|
||||||
|
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
@@ -81,7 +82,7 @@ func (service monitorProjectService) List(page request.PageReq, listReq MonitorP
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
result := []MonitorProjectResp{}
|
result := []MonitorProjectResp{}
|
||||||
util.ConvertUtil.Copy(&result, modelList)
|
convert_util.Copy(&result, modelList)
|
||||||
return response.PageResp{
|
return response.PageResp{
|
||||||
PageNo: page.PageNo,
|
PageNo: page.PageNo,
|
||||||
PageSize: page.PageSize,
|
PageSize: page.PageSize,
|
||||||
@@ -100,7 +101,7 @@ func (service monitorProjectService) ListAll(listReq MonitorProjectListReq) (res
|
|||||||
if e = response.CheckErr(err, "查询全部失败"); e != nil {
|
if e = response.CheckErr(err, "查询全部失败"); e != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
util.ConvertUtil.Copy(&res, modelList)
|
convert_util.Copy(&res, modelList)
|
||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -119,14 +120,14 @@ func (service monitorProjectService) Detail(Id int) (res MonitorProjectResp, e e
|
|||||||
cacheUtil.SetCache(obj.Id, obj)
|
cacheUtil.SetCache(obj.Id, obj)
|
||||||
}
|
}
|
||||||
|
|
||||||
util.ConvertUtil.Copy(&res, obj)
|
convert_util.Copy(&res, obj)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add 监控项目新增
|
// Add 监控项目新增
|
||||||
func (service monitorProjectService) Add(addReq MonitorProjectAddReq) (createId int, e error) {
|
func (service monitorProjectService) Add(addReq MonitorProjectAddReq) (createId int, e error) {
|
||||||
var obj model.MonitorProject
|
var obj model.MonitorProject
|
||||||
util.ConvertUtil.StructToStruct(addReq, &obj)
|
convert_util.StructToStruct(addReq, &obj)
|
||||||
obj.ProjectKey = util.ToolsUtil.MakeUuid()
|
obj.ProjectKey = util.ToolsUtil.MakeUuid()
|
||||||
err := service.db.Create(&obj).Error
|
err := service.db.Create(&obj).Error
|
||||||
e = response.CheckMysqlErr(err)
|
e = response.CheckMysqlErr(err)
|
||||||
@@ -149,7 +150,7 @@ func (service monitorProjectService) Edit(editReq MonitorProjectEditReq) (e erro
|
|||||||
if e = response.CheckErr(err, "查询失败"); e != nil {
|
if e = response.CheckErr(err, "查询失败"); e != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
util.ConvertUtil.Copy(&obj, editReq)
|
convert_util.Copy(&obj, editReq)
|
||||||
|
|
||||||
err = service.db.Model(&obj).Select("*").Updates(obj).Error
|
err = service.db.Model(&obj).Select("*").Updates(obj).Error
|
||||||
if e = response.CheckErr(err, "编辑失败"); e != nil {
|
if e = response.CheckErr(err, "编辑失败"); e != nil {
|
||||||
@@ -221,14 +222,14 @@ func (service monitorProjectService) ExportFile(listReq MonitorProjectListReq) (
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
result := []MonitorProjectResp{}
|
result := []MonitorProjectResp{}
|
||||||
util.ConvertUtil.Copy(&result, modelList)
|
convert_util.Copy(&result, modelList)
|
||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 导入
|
// 导入
|
||||||
func (service monitorProjectService) ImportFile(importReq []MonitorProjectResp) (e error) {
|
func (service monitorProjectService) ImportFile(importReq []MonitorProjectResp) (e error) {
|
||||||
var importData []model.MonitorProject
|
var importData []model.MonitorProject
|
||||||
util.ConvertUtil.Copy(&importData, importReq)
|
convert_util.Copy(&importData, importReq)
|
||||||
err := service.db.Create(&importData).Error
|
err := service.db.Create(&importData).Error
|
||||||
e = response.CheckErr(err, "添加失败")
|
e = response.CheckErr(err, "添加失败")
|
||||||
return e
|
return e
|
||||||
|
@@ -5,12 +5,14 @@ import (
|
|||||||
"x_admin/core/request"
|
"x_admin/core/request"
|
||||||
"x_admin/core/response"
|
"x_admin/core/response"
|
||||||
"x_admin/model"
|
"x_admin/model"
|
||||||
"gorm.io/gorm"
|
|
||||||
"x_admin/util"
|
"x_admin/util"
|
||||||
|
"x_admin/util/convert_util"
|
||||||
"x_admin/util/excel2"
|
"x_admin/util/excel2"
|
||||||
|
|
||||||
|
"gorm.io/gorm"
|
||||||
)
|
)
|
||||||
|
|
||||||
var MonitorSlowService=NewMonitorSlowService()
|
var MonitorSlowService = NewMonitorSlowService()
|
||||||
var cacheUtil = util.CacheUtil{
|
var cacheUtil = util.CacheUtil{
|
||||||
Name: MonitorSlowService.Name,
|
Name: MonitorSlowService.Name,
|
||||||
}
|
}
|
||||||
@@ -23,41 +25,40 @@ func NewMonitorSlowService() *monitorSlowService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//monitorSlowService 监控-错误列服务实现类
|
// monitorSlowService 监控-错误列服务实现类
|
||||||
type monitorSlowService struct {
|
type monitorSlowService struct {
|
||||||
db *gorm.DB
|
db *gorm.DB
|
||||||
Name string
|
Name string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// List 监控-错误列列表
|
// List 监控-错误列列表
|
||||||
func (service monitorSlowService) GetModel(listReq MonitorSlowListReq) *gorm.DB {
|
func (service monitorSlowService) GetModel(listReq MonitorSlowListReq) *gorm.DB {
|
||||||
// 查询
|
// 查询
|
||||||
dbModel := service.db.Model(&model.MonitorSlow{})
|
dbModel := service.db.Model(&model.MonitorSlow{})
|
||||||
if listReq.ProjectKey!= nil {
|
if listReq.ProjectKey != nil {
|
||||||
dbModel = dbModel.Where("project_key = ?", *listReq.ProjectKey)
|
dbModel = dbModel.Where("project_key = ?", *listReq.ProjectKey)
|
||||||
}
|
}
|
||||||
if listReq.ClientId!= nil {
|
if listReq.ClientId != nil {
|
||||||
dbModel = dbModel.Where("client_id = ?", *listReq.ClientId)
|
dbModel = dbModel.Where("client_id = ?", *listReq.ClientId)
|
||||||
}
|
}
|
||||||
if listReq.UserId!= nil {
|
if listReq.UserId != nil {
|
||||||
dbModel = dbModel.Where("user_id = ?", *listReq.UserId)
|
dbModel = dbModel.Where("user_id = ?", *listReq.UserId)
|
||||||
}
|
}
|
||||||
if listReq.Path!= nil {
|
if listReq.Path != nil {
|
||||||
dbModel = dbModel.Where("path = ?", *listReq.Path)
|
dbModel = dbModel.Where("path = ?", *listReq.Path)
|
||||||
}
|
}
|
||||||
if listReq.Time!= nil {
|
if listReq.Time != nil {
|
||||||
dbModel = dbModel.Where("time = ?", *listReq.Time)
|
dbModel = dbModel.Where("time = ?", *listReq.Time)
|
||||||
}
|
}
|
||||||
if listReq.CreateTimeStart!= nil {
|
if listReq.CreateTimeStart != nil {
|
||||||
dbModel = dbModel.Where("create_time >= ?", *listReq.CreateTimeStart)
|
dbModel = dbModel.Where("create_time >= ?", *listReq.CreateTimeStart)
|
||||||
}
|
}
|
||||||
if listReq.CreateTimeEnd!= nil {
|
if listReq.CreateTimeEnd != nil {
|
||||||
dbModel = dbModel.Where("create_time <= ?", *listReq.CreateTimeEnd)
|
dbModel = dbModel.Where("create_time <= ?", *listReq.CreateTimeEnd)
|
||||||
}
|
}
|
||||||
return dbModel
|
return dbModel
|
||||||
}
|
}
|
||||||
|
|
||||||
// List 监控-错误列列表
|
// List 监控-错误列列表
|
||||||
func (service monitorSlowService) List(page request.PageReq, listReq MonitorSlowListReq) (res response.PageResp, e error) {
|
func (service monitorSlowService) List(page request.PageReq, listReq MonitorSlowListReq) (res response.PageResp, e error) {
|
||||||
// 分页信息
|
// 分页信息
|
||||||
@@ -77,7 +78,7 @@ func (service monitorSlowService) List(page request.PageReq, listReq MonitorSlow
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
result := []MonitorSlowResp{}
|
result := []MonitorSlowResp{}
|
||||||
util.ConvertUtil.Copy(&result, modelList)
|
convert_util.Copy(&result, modelList)
|
||||||
return response.PageResp{
|
return response.PageResp{
|
||||||
PageNo: page.PageNo,
|
PageNo: page.PageNo,
|
||||||
PageSize: page.PageSize,
|
PageSize: page.PageSize,
|
||||||
@@ -85,6 +86,7 @@ func (service monitorSlowService) List(page request.PageReq, listReq MonitorSlow
|
|||||||
Lists: result,
|
Lists: result,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ListAll 监控-错误列列表
|
// ListAll 监控-错误列列表
|
||||||
func (service monitorSlowService) ListAll(listReq MonitorSlowListReq) (res []MonitorSlowResp, e error) {
|
func (service monitorSlowService) ListAll(listReq MonitorSlowListReq) (res []MonitorSlowResp, e error) {
|
||||||
dbModel := service.GetModel(listReq)
|
dbModel := service.GetModel(listReq)
|
||||||
@@ -95,7 +97,7 @@ func (service monitorSlowService) ListAll(listReq MonitorSlowListReq) (res []Mon
|
|||||||
if e = response.CheckErr(err, "查询全部失败"); e != nil {
|
if e = response.CheckErr(err, "查询全部失败"); e != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
util.ConvertUtil.Copy(&res, modelList)
|
convert_util.Copy(&res, modelList)
|
||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -114,18 +116,18 @@ func (service monitorSlowService) Detail(Id int) (res MonitorSlowResp, e error)
|
|||||||
cacheUtil.SetCache(obj.Id, obj)
|
cacheUtil.SetCache(obj.Id, obj)
|
||||||
}
|
}
|
||||||
|
|
||||||
util.ConvertUtil.Copy(&res, obj)
|
convert_util.Copy(&res, obj)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add 监控-错误列新增
|
// Add 监控-错误列新增
|
||||||
func (service monitorSlowService) Add(addReq MonitorSlowAddReq) (createId int,e error) {
|
func (service monitorSlowService) Add(addReq MonitorSlowAddReq) (createId int, e error) {
|
||||||
var obj model.MonitorSlow
|
var obj model.MonitorSlow
|
||||||
util.ConvertUtil.StructToStruct(addReq,&obj)
|
convert_util.StructToStruct(addReq, &obj)
|
||||||
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 {
|
||||||
return 0,e
|
return 0, e
|
||||||
}
|
}
|
||||||
cacheUtil.SetCache(obj.Id, obj)
|
cacheUtil.SetCache(obj.Id, obj)
|
||||||
createId = obj.Id
|
createId = obj.Id
|
||||||
@@ -143,7 +145,7 @@ func (service monitorSlowService) Edit(editReq MonitorSlowEditReq) (e error) {
|
|||||||
if e = response.CheckErr(err, "查询失败"); e != nil {
|
if e = response.CheckErr(err, "查询失败"); e != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
util.ConvertUtil.Copy(&obj, editReq)
|
convert_util.Copy(&obj, editReq)
|
||||||
|
|
||||||
err = service.db.Model(&obj).Select("*").Updates(obj).Error
|
err = service.db.Model(&obj).Select("*").Updates(obj).Error
|
||||||
if e = response.CheckErr(err, "编辑失败"); e != nil {
|
if e = response.CheckErr(err, "编辑失败"); e != nil {
|
||||||
@@ -165,9 +167,9 @@ func (service monitorSlowService) Del(Id int) (e error) {
|
|||||||
if e = response.CheckErr(err, "查询数据失败"); e != nil {
|
if e = response.CheckErr(err, "查询数据失败"); e != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// 删除
|
// 删除
|
||||||
err = service.db.Delete(&obj).Error
|
err = service.db.Delete(&obj).Error
|
||||||
e = response.CheckErr(err, "删除失败")
|
e = response.CheckErr(err, "删除失败")
|
||||||
cacheUtil.RemoveCache(obj.Id)
|
cacheUtil.RemoveCache(obj.Id)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -192,7 +194,7 @@ func (service monitorSlowService) GetExcelCol() []excel2.Col {
|
|||||||
{Name: "用户id", Key: "UserId", Width: 15},
|
{Name: "用户id", Key: "UserId", Width: 15},
|
||||||
{Name: "URL地址", Key: "Path", Width: 15},
|
{Name: "URL地址", Key: "Path", Width: 15},
|
||||||
{Name: "时间", Key: "Time", Width: 15},
|
{Name: "时间", Key: "Time", Width: 15},
|
||||||
{Name: "创建时间", Key: "CreateTime", Width: 15, Decode: util.NullTimeUtil.DecodeTime },
|
{Name: "创建时间", Key: "CreateTime", Width: 15, Decode: util.NullTimeUtil.DecodeTime},
|
||||||
}
|
}
|
||||||
// 还可以考虑字典,请求下来加上 Replace 实现替换导出
|
// 还可以考虑字典,请求下来加上 Replace 实现替换导出
|
||||||
return cols
|
return cols
|
||||||
@@ -210,14 +212,14 @@ func (service monitorSlowService) ExportFile(listReq MonitorSlowListReq) (res []
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
result := []MonitorSlowResp{}
|
result := []MonitorSlowResp{}
|
||||||
util.ConvertUtil.Copy(&result, modelList)
|
convert_util.Copy(&result, modelList)
|
||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 导入
|
// 导入
|
||||||
func (service monitorSlowService) ImportFile(importReq []MonitorSlowResp) (e error) {
|
func (service monitorSlowService) ImportFile(importReq []MonitorSlowResp) (e error) {
|
||||||
var importData []model.MonitorSlow
|
var importData []model.MonitorSlow
|
||||||
util.ConvertUtil.Copy(&importData, importReq)
|
convert_util.Copy(&importData, importReq)
|
||||||
err := service.db.Create(&importData).Error
|
err := service.db.Create(&importData).Error
|
||||||
e = response.CheckErr(err, "添加失败")
|
e = response.CheckErr(err, "添加失败")
|
||||||
return e
|
return e
|
||||||
|
@@ -6,6 +6,7 @@ import (
|
|||||||
"x_admin/core/response"
|
"x_admin/core/response"
|
||||||
"x_admin/model/setting_model"
|
"x_admin/model/setting_model"
|
||||||
"x_admin/util"
|
"x_admin/util"
|
||||||
|
"x_admin/util/convert_util"
|
||||||
|
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
)
|
)
|
||||||
@@ -58,7 +59,7 @@ func (ddSrv settingDictDataService) All(allReq SettingDictDataListReq) (res []Se
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
res = []SettingDictDataResp{}
|
res = []SettingDictDataResp{}
|
||||||
util.ConvertUtil.Copy(&res, dictDatas)
|
convert_util.Copy(&res, dictDatas)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -95,7 +96,7 @@ func (ddSrv settingDictDataService) List(page request.PageReq, listReq SettingDi
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
dtResp := []SettingDictDataResp{}
|
dtResp := []SettingDictDataResp{}
|
||||||
util.ConvertUtil.Copy(&dtResp, dds)
|
convert_util.Copy(&dtResp, dds)
|
||||||
return response.PageResp{
|
return response.PageResp{
|
||||||
PageNo: page.PageNo,
|
PageNo: page.PageNo,
|
||||||
PageSize: page.PageSize,
|
PageSize: page.PageSize,
|
||||||
@@ -114,7 +115,7 @@ func (ddSrv settingDictDataService) Detail(id uint) (res SettingDictDataResp, e
|
|||||||
if e = response.CheckErr(err, "详情获取失败"); e != nil {
|
if e = response.CheckErr(err, "详情获取失败"); e != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
util.ConvertUtil.Copy(&res, dd)
|
convert_util.Copy(&res, dd)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -124,7 +125,7 @@ func (ddSrv settingDictDataService) Add(addReq SettingDictDataAddReq) (e error)
|
|||||||
return response.AssertArgumentError.SetMessage("字典数据已存在!")
|
return response.AssertArgumentError.SetMessage("字典数据已存在!")
|
||||||
}
|
}
|
||||||
var dd setting_model.DictData
|
var dd setting_model.DictData
|
||||||
util.ConvertUtil.Copy(&dd, addReq)
|
convert_util.Copy(&dd, addReq)
|
||||||
err := ddSrv.db.Create(&dd).Error
|
err := ddSrv.db.Create(&dd).Error
|
||||||
e = response.CheckErr(err, "添加失败")
|
e = response.CheckErr(err, "添加失败")
|
||||||
return
|
return
|
||||||
@@ -144,7 +145,7 @@ func (ddSrv settingDictDataService) Edit(editReq SettingDictDataEditReq) (e erro
|
|||||||
return response.AssertArgumentError.SetMessage("字典数据已存在!")
|
return response.AssertArgumentError.SetMessage("字典数据已存在!")
|
||||||
}
|
}
|
||||||
|
|
||||||
util.ConvertUtil.Copy(&dd, editReq)
|
convert_util.Copy(&dd, editReq)
|
||||||
err = ddSrv.db.Save(&dd).Error
|
err = ddSrv.db.Save(&dd).Error
|
||||||
e = response.CheckErr(err, "编辑失败")
|
e = response.CheckErr(err, "编辑失败")
|
||||||
return
|
return
|
||||||
|
@@ -6,6 +6,7 @@ import (
|
|||||||
"x_admin/core/response"
|
"x_admin/core/response"
|
||||||
"x_admin/model/setting_model"
|
"x_admin/model/setting_model"
|
||||||
"x_admin/util"
|
"x_admin/util"
|
||||||
|
"x_admin/util/convert_util"
|
||||||
|
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
)
|
)
|
||||||
@@ -40,7 +41,7 @@ func (dtSrv settingDictTypeService) All() (res []SettingDictTypeResp, e error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
res = []SettingDictTypeResp{}
|
res = []SettingDictTypeResp{}
|
||||||
util.ConvertUtil.Copy(&res, dictTypes)
|
convert_util.Copy(&res, dictTypes)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -69,7 +70,7 @@ func (dtSrv settingDictTypeService) List(page request.PageReq, listReq SettingDi
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
dtResp := []SettingDictTypeResp{}
|
dtResp := []SettingDictTypeResp{}
|
||||||
util.ConvertUtil.Copy(&dtResp, dts)
|
convert_util.Copy(&dtResp, dts)
|
||||||
return response.PageResp{
|
return response.PageResp{
|
||||||
PageNo: page.PageNo,
|
PageNo: page.PageNo,
|
||||||
PageSize: page.PageSize,
|
PageSize: page.PageSize,
|
||||||
@@ -88,7 +89,7 @@ func (dtSrv settingDictTypeService) Detail(id uint) (res SettingDictTypeResp, e
|
|||||||
if e = response.CheckErr(err, "详情获取失败"); e != nil {
|
if e = response.CheckErr(err, "详情获取失败"); e != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
util.ConvertUtil.Copy(&res, dt)
|
convert_util.Copy(&res, dt)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -101,7 +102,7 @@ func (dtSrv settingDictTypeService) Add(addReq SettingDictTypeAddReq) (e error)
|
|||||||
return response.AssertArgumentError.SetMessage("字典类型已存在!")
|
return response.AssertArgumentError.SetMessage("字典类型已存在!")
|
||||||
}
|
}
|
||||||
var dt setting_model.DictType
|
var dt setting_model.DictType
|
||||||
util.ConvertUtil.Copy(&dt, addReq)
|
convert_util.Copy(&dt, addReq)
|
||||||
err := dtSrv.db.Create(&dt).Error
|
err := dtSrv.db.Create(&dt).Error
|
||||||
e = response.CheckErr(err, "添加失败")
|
e = response.CheckErr(err, "添加失败")
|
||||||
return
|
return
|
||||||
@@ -124,7 +125,7 @@ func (dtSrv settingDictTypeService) Edit(editReq SettingDictTypeEditReq) (e erro
|
|||||||
return response.AssertArgumentError.SetMessage("字典类型已存在!")
|
return response.AssertArgumentError.SetMessage("字典类型已存在!")
|
||||||
}
|
}
|
||||||
|
|
||||||
util.ConvertUtil.Copy(&dt, editReq)
|
convert_util.Copy(&dt, editReq)
|
||||||
// err = dtSrv.db.Model(&dt).Updates(&up).Error
|
// err = dtSrv.db.Model(&dt).Updates(&up).Error
|
||||||
err = dtSrv.db.Save(&dt).Error
|
err = dtSrv.db.Save(&dt).Error
|
||||||
e = response.CheckErr(err, "编辑失败")
|
e = response.CheckErr(err, "编辑失败")
|
||||||
|
@@ -13,6 +13,7 @@ import (
|
|||||||
"x_admin/core/response"
|
"x_admin/core/response"
|
||||||
"x_admin/model/system_model"
|
"x_admin/model/system_model"
|
||||||
"x_admin/util"
|
"x_admin/util"
|
||||||
|
"x_admin/util/convert_util"
|
||||||
|
|
||||||
"github.com/fatih/structs"
|
"github.com/fatih/structs"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
@@ -78,7 +79,7 @@ func (adminSrv systemAuthAdminService) Self(adminId uint) (res SystemAuthAdminSe
|
|||||||
auths = append(auths, "*")
|
auths = append(auths, "*")
|
||||||
}
|
}
|
||||||
var admin SystemAuthAdminSelfOneResp
|
var admin SystemAuthAdminSelfOneResp
|
||||||
util.ConvertUtil.Copy(&admin, sysAdmin)
|
convert_util.Copy(&admin, sysAdmin)
|
||||||
admin.Dept = strconv.FormatUint(uint64(sysAdmin.DeptId), 10)
|
admin.Dept = strconv.FormatUint(uint64(sysAdmin.DeptId), 10)
|
||||||
admin.Avatar = util.UrlUtil.ToAbsoluteUrl(sysAdmin.Avatar)
|
admin.Avatar = util.UrlUtil.ToAbsoluteUrl(sysAdmin.Avatar)
|
||||||
return SystemAuthAdminSelfResp{User: admin, Permissions: auths}, nil
|
return SystemAuthAdminSelfResp{User: admin, Permissions: auths}, nil
|
||||||
@@ -151,7 +152,7 @@ func (adminSrv systemAuthAdminService) ExportFile(listReq SystemAuthAdminListReq
|
|||||||
// 导入
|
// 导入
|
||||||
func (adminSrv systemAuthAdminService) ImportFile(importReq []SystemAuthAdminResp) (e error) {
|
func (adminSrv systemAuthAdminService) ImportFile(importReq []SystemAuthAdminResp) (e error) {
|
||||||
var sysAdmin []system_model.SystemAuthAdmin
|
var sysAdmin []system_model.SystemAuthAdmin
|
||||||
util.ConvertUtil.Copy(&sysAdmin, importReq)
|
convert_util.Copy(&sysAdmin, importReq)
|
||||||
err := adminSrv.db.Create(&sysAdmin).Error
|
err := adminSrv.db.Create(&sysAdmin).Error
|
||||||
e = response.CheckErr(err, "添加失败")
|
e = response.CheckErr(err, "添加失败")
|
||||||
return e
|
return e
|
||||||
@@ -254,7 +255,7 @@ func (adminSrv systemAuthAdminService) Detail(id uint) (res SystemAuthAdminResp,
|
|||||||
if e = response.CheckErr(err, "详情获取失败"); e != nil {
|
if e = response.CheckErr(err, "详情获取失败"); e != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
util.ConvertUtil.Copy(&res, sysAdmin)
|
convert_util.Copy(&res, sysAdmin)
|
||||||
res.Avatar = util.UrlUtil.ToAbsoluteUrl(res.Avatar)
|
res.Avatar = util.UrlUtil.ToAbsoluteUrl(res.Avatar)
|
||||||
if res.Dept == "" {
|
if res.Dept == "" {
|
||||||
res.Dept = strconv.FormatUint(uint64(res.DeptId), 10)
|
res.Dept = strconv.FormatUint(uint64(res.DeptId), 10)
|
||||||
@@ -295,7 +296,7 @@ func (adminSrv systemAuthAdminService) Add(addReq SystemAuthAdminAddReq) (e erro
|
|||||||
return response.Failed.SetMessage("密码格式不正确")
|
return response.Failed.SetMessage("密码格式不正确")
|
||||||
}
|
}
|
||||||
salt := util.ToolsUtil.RandomString(5)
|
salt := util.ToolsUtil.RandomString(5)
|
||||||
util.ConvertUtil.Copy(&sysAdmin, addReq)
|
convert_util.Copy(&sysAdmin, addReq)
|
||||||
sysAdmin.Role = strconv.FormatUint(uint64(addReq.Role), 10)
|
sysAdmin.Role = strconv.FormatUint(uint64(addReq.Role), 10)
|
||||||
sysAdmin.Salt = salt
|
sysAdmin.Salt = salt
|
||||||
sysAdmin.Password = util.ToolsUtil.MakeMd5(strings.Trim(addReq.Password, " ") + salt)
|
sysAdmin.Password = util.ToolsUtil.MakeMd5(strings.Trim(addReq.Password, " ") + salt)
|
||||||
|
@@ -4,7 +4,7 @@ import (
|
|||||||
"x_admin/core"
|
"x_admin/core"
|
||||||
"x_admin/core/response"
|
"x_admin/core/response"
|
||||||
"x_admin/model/system_model"
|
"x_admin/model/system_model"
|
||||||
"x_admin/util"
|
"x_admin/util/convert_util"
|
||||||
|
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
)
|
)
|
||||||
@@ -39,7 +39,7 @@ func (service systemAuthDeptService) All() (res []SystemAuthDeptResp, e error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
res = []SystemAuthDeptResp{}
|
res = []SystemAuthDeptResp{}
|
||||||
util.ConvertUtil.Copy(&res, depts)
|
convert_util.Copy(&res, depts)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -57,7 +57,7 @@ func (service systemAuthDeptService) List(listReq SystemAuthDeptListReq) (deptRe
|
|||||||
if e = response.CheckErr(err, "列表获取失败"); e != nil {
|
if e = response.CheckErr(err, "列表获取失败"); e != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
util.ConvertUtil.Copy(&deptResps, depts)
|
convert_util.Copy(&deptResps, depts)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -71,7 +71,7 @@ func (service systemAuthDeptService) Detail(id uint) (res SystemAuthDeptResp, e
|
|||||||
if e = response.CheckErr(err, "详情获取失败"); e != nil {
|
if e = response.CheckErr(err, "详情获取失败"); e != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
util.ConvertUtil.Copy(&res, dept)
|
convert_util.Copy(&res, dept)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -87,7 +87,7 @@ func (service systemAuthDeptService) Add(addReq SystemAuthDeptAddReq) (e error)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
var dept system_model.SystemAuthDept
|
var dept system_model.SystemAuthDept
|
||||||
util.ConvertUtil.Copy(&dept, addReq)
|
convert_util.Copy(&dept, addReq)
|
||||||
err := service.db.Create(&dept).Error
|
err := service.db.Create(&dept).Error
|
||||||
e = response.CheckErr(err, "添加失败")
|
e = response.CheckErr(err, "添加失败")
|
||||||
return
|
return
|
||||||
@@ -111,7 +111,7 @@ func (service systemAuthDeptService) Edit(editReq SystemAuthDeptEditReq) (e erro
|
|||||||
return response.AssertArgumentError.SetMessage("上级部门不能是自己!")
|
return response.AssertArgumentError.SetMessage("上级部门不能是自己!")
|
||||||
}
|
}
|
||||||
// 更新
|
// 更新
|
||||||
util.ConvertUtil.Copy(&dept, editReq)
|
convert_util.Copy(&dept, editReq)
|
||||||
err = service.db.Model(&dept).Select("*").Updates(dept).Error
|
err = service.db.Model(&dept).Select("*").Updates(dept).Error
|
||||||
e = response.CheckErr(err, "编辑失败")
|
e = response.CheckErr(err, "编辑失败")
|
||||||
return
|
return
|
||||||
|
@@ -7,6 +7,7 @@ import (
|
|||||||
"x_admin/core/response"
|
"x_admin/core/response"
|
||||||
"x_admin/model/system_model"
|
"x_admin/model/system_model"
|
||||||
"x_admin/util"
|
"x_admin/util"
|
||||||
|
"x_admin/util/convert_util"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
@@ -57,9 +58,9 @@ func (menuSrv systemAuthMenuService) SelectMenuByRoleId(c *gin.Context, roleId u
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
var menuResps []SystemAuthMenuResp
|
var menuResps []SystemAuthMenuResp
|
||||||
util.ConvertUtil.Copy(&menuResps, menus)
|
convert_util.Copy(&menuResps, menus)
|
||||||
mapList = util.ArrayUtil.ListToTree(
|
mapList = util.ArrayUtil.ListToTree(
|
||||||
util.ConvertUtil.StructsToMaps(menuResps), "id", "pid", "children")
|
convert_util.StructsToMaps(menuResps), "id", "pid", "children")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -71,7 +72,7 @@ func (menuSrv systemAuthMenuService) List() (res interface{}, e error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
var menuResps []SystemAuthMenuResp
|
var menuResps []SystemAuthMenuResp
|
||||||
util.ConvertUtil.Copy(&menuResps, menus)
|
convert_util.Copy(&menuResps, menus)
|
||||||
return menuResps, nil
|
return menuResps, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -85,13 +86,13 @@ func (menuSrv systemAuthMenuService) Detail(id uint) (res SystemAuthMenuResp, e
|
|||||||
if e = response.CheckErr(err, "详情获取失败"); e != nil {
|
if e = response.CheckErr(err, "详情获取失败"); e != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
util.ConvertUtil.Copy(&res, menu)
|
convert_util.Copy(&res, menu)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (menuSrv systemAuthMenuService) Add(addReq SystemAuthMenuAddReq) (e error) {
|
func (menuSrv systemAuthMenuService) Add(addReq SystemAuthMenuAddReq) (e error) {
|
||||||
var menu system_model.SystemAuthMenu
|
var menu system_model.SystemAuthMenu
|
||||||
util.ConvertUtil.Copy(&menu, addReq)
|
convert_util.Copy(&menu, addReq)
|
||||||
err := menuSrv.db.Create(&menu).Error
|
err := menuSrv.db.Create(&menu).Error
|
||||||
if e = response.CheckErr(err, "添加失败"); e != nil {
|
if e = response.CheckErr(err, "添加失败"); e != nil {
|
||||||
return
|
return
|
||||||
@@ -109,7 +110,7 @@ func (menuSrv systemAuthMenuService) Edit(editReq SystemAuthMenuEditReq) (e erro
|
|||||||
if e = response.CheckErr(err, "Edit Find err"); e != nil {
|
if e = response.CheckErr(err, "Edit Find err"); e != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
util.ConvertUtil.Copy(&menu, editReq)
|
convert_util.Copy(&menu, editReq)
|
||||||
|
|
||||||
err = menuSrv.db.Model(&menu).Select("*").Updates(menu).Error
|
err = menuSrv.db.Model(&menu).Select("*").Updates(menu).Error
|
||||||
if e = response.CheckErr(err, "编辑失败"); e != nil {
|
if e = response.CheckErr(err, "编辑失败"); e != nil {
|
||||||
|
@@ -5,7 +5,7 @@ import (
|
|||||||
"x_admin/core/request"
|
"x_admin/core/request"
|
||||||
"x_admin/core/response"
|
"x_admin/core/response"
|
||||||
"x_admin/model/system_model"
|
"x_admin/model/system_model"
|
||||||
"x_admin/util"
|
"x_admin/util/convert_util"
|
||||||
|
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
)
|
)
|
||||||
@@ -40,7 +40,7 @@ func (service systemAuthPostService) All() (res []SystemAuthPostResp, e error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
res = []SystemAuthPostResp{}
|
res = []SystemAuthPostResp{}
|
||||||
util.ConvertUtil.Copy(&res, posts)
|
convert_util.Copy(&res, posts)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -73,7 +73,7 @@ func (service systemAuthPostService) List(page request.PageReq, listReq SystemAu
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
postResps := []SystemAuthPostResp{}
|
postResps := []SystemAuthPostResp{}
|
||||||
util.ConvertUtil.Copy(&postResps, posts)
|
convert_util.Copy(&postResps, posts)
|
||||||
return response.PageResp{
|
return response.PageResp{
|
||||||
PageNo: page.PageNo,
|
PageNo: page.PageNo,
|
||||||
PageSize: page.PageSize,
|
PageSize: page.PageSize,
|
||||||
@@ -92,7 +92,7 @@ func (service systemAuthPostService) Detail(id uint) (res SystemAuthPostResp, e
|
|||||||
if e = response.CheckErr(err, "详情获取失败"); e != nil {
|
if e = response.CheckErr(err, "详情获取失败"); e != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
util.ConvertUtil.Copy(&res, post)
|
convert_util.Copy(&res, post)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -106,7 +106,7 @@ func (service systemAuthPostService) Add(addReq SystemAuthPostAddReq) (e error)
|
|||||||
return response.AssertArgumentError.SetMessage("该岗位已存在!")
|
return response.AssertArgumentError.SetMessage("该岗位已存在!")
|
||||||
}
|
}
|
||||||
var post system_model.SystemAuthPost
|
var post system_model.SystemAuthPost
|
||||||
util.ConvertUtil.Copy(&post, addReq)
|
convert_util.Copy(&post, addReq)
|
||||||
err := service.db.Create(&post).Error
|
err := service.db.Create(&post).Error
|
||||||
e = response.CheckErr(err, "添加失败")
|
e = response.CheckErr(err, "添加失败")
|
||||||
return
|
return
|
||||||
@@ -131,7 +131,7 @@ func (service systemAuthPostService) Edit(editReq SystemAuthPostEditReq) (e erro
|
|||||||
return response.AssertArgumentError.SetMessage("该岗位已存在!")
|
return response.AssertArgumentError.SetMessage("该岗位已存在!")
|
||||||
}
|
}
|
||||||
// 更新
|
// 更新
|
||||||
util.ConvertUtil.Copy(&post, editReq)
|
convert_util.Copy(&post, editReq)
|
||||||
err = service.db.Model(&post).Select("*").Updates(post).Error
|
err = service.db.Model(&post).Select("*").Updates(post).Error
|
||||||
e = response.CheckErr(err, "编辑失败")
|
e = response.CheckErr(err, "编辑失败")
|
||||||
return
|
return
|
||||||
|
@@ -9,6 +9,7 @@ import (
|
|||||||
"x_admin/core/response"
|
"x_admin/core/response"
|
||||||
"x_admin/model/system_model"
|
"x_admin/model/system_model"
|
||||||
"x_admin/util"
|
"x_admin/util"
|
||||||
|
"x_admin/util/convert_util"
|
||||||
|
|
||||||
"github.com/fatih/structs"
|
"github.com/fatih/structs"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
@@ -43,7 +44,7 @@ func (roleSrv systemAuthRoleService) All() (res []SystemAuthRoleSimpleResp, e er
|
|||||||
if e = response.CheckErr(err, "All Find err"); e != nil {
|
if e = response.CheckErr(err, "All Find err"); e != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
util.ConvertUtil.Copy(&res, roles)
|
convert_util.Copy(&res, roles)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -63,7 +64,7 @@ func (roleSrv systemAuthRoleService) List(page request.PageReq) (res response.Pa
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
var roleResp []SystemAuthRoleResp
|
var roleResp []SystemAuthRoleResp
|
||||||
util.ConvertUtil.Copy(&roleResp, roles)
|
convert_util.Copy(&roleResp, roles)
|
||||||
for i := 0; i < len(roleResp); i++ {
|
for i := 0; i < len(roleResp); i++ {
|
||||||
roleResp[i].Menus = []uint{}
|
roleResp[i].Menus = []uint{}
|
||||||
roleResp[i].Member = roleSrv.getMemberCnt(roleResp[i].ID)
|
roleResp[i].Member = roleSrv.getMemberCnt(roleResp[i].ID)
|
||||||
@@ -86,7 +87,7 @@ func (roleSrv systemAuthRoleService) Detail(id uint) (res SystemAuthRoleResp, e
|
|||||||
if e = response.CheckErr(err, "详情获取失败"); e != nil {
|
if e = response.CheckErr(err, "详情获取失败"); e != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
util.ConvertUtil.Copy(&res, role)
|
convert_util.Copy(&res, role)
|
||||||
res.Member = roleSrv.getMemberCnt(role.ID)
|
res.Member = roleSrv.getMemberCnt(role.ID)
|
||||||
res.Menus, _ = PermService.SelectMenuIdsByRoleId(role.ID)
|
res.Menus, _ = PermService.SelectMenuIdsByRoleId(role.ID)
|
||||||
return
|
return
|
||||||
@@ -105,7 +106,7 @@ func (roleSrv systemAuthRoleService) Add(addReq SystemAuthRoleAddReq) (e error)
|
|||||||
if r := roleSrv.db.Where("name = ?", strings.Trim(addReq.Name, " ")).Limit(1).First(&role); r.RowsAffected > 0 {
|
if r := roleSrv.db.Where("name = ?", strings.Trim(addReq.Name, " ")).Limit(1).First(&role); r.RowsAffected > 0 {
|
||||||
return response.AssertArgumentError.SetMessage("角色名称已存在!")
|
return response.AssertArgumentError.SetMessage("角色名称已存在!")
|
||||||
}
|
}
|
||||||
util.ConvertUtil.Copy(&role, addReq)
|
convert_util.Copy(&role, addReq)
|
||||||
role.Name = strings.Trim(addReq.Name, " ")
|
role.Name = strings.Trim(addReq.Name, " ")
|
||||||
// 事务
|
// 事务
|
||||||
err := roleSrv.db.Transaction(func(tx *gorm.DB) error {
|
err := roleSrv.db.Transaction(func(tx *gorm.DB) error {
|
||||||
|
@@ -6,6 +6,7 @@ import (
|
|||||||
"x_admin/core/response"
|
"x_admin/core/response"
|
||||||
"x_admin/model"
|
"x_admin/model"
|
||||||
"x_admin/util"
|
"x_admin/util"
|
||||||
|
"x_admin/util/convert_util"
|
||||||
"x_admin/util/excel2"
|
"x_admin/util/excel2"
|
||||||
|
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
@@ -78,7 +79,7 @@ func (service userProtocolService) List(page request.PageReq, listReq UserProtoc
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
result := []UserProtocolResp{}
|
result := []UserProtocolResp{}
|
||||||
util.ConvertUtil.Copy(&result, modelList)
|
convert_util.Copy(&result, modelList)
|
||||||
return response.PageResp{
|
return response.PageResp{
|
||||||
PageNo: page.PageNo,
|
PageNo: page.PageNo,
|
||||||
PageSize: page.PageSize,
|
PageSize: page.PageSize,
|
||||||
@@ -97,7 +98,7 @@ func (service userProtocolService) ListAll(listReq UserProtocolListReq) (res []U
|
|||||||
if e = response.CheckErr(err, "查询全部失败"); e != nil {
|
if e = response.CheckErr(err, "查询全部失败"); e != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
util.ConvertUtil.Copy(&res, modelList)
|
convert_util.Copy(&res, modelList)
|
||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -116,14 +117,14 @@ func (service userProtocolService) Detail(Id int) (res UserProtocolResp, e error
|
|||||||
cacheUtil.SetCache(obj.Id, obj)
|
cacheUtil.SetCache(obj.Id, obj)
|
||||||
}
|
}
|
||||||
|
|
||||||
util.ConvertUtil.Copy(&res, obj)
|
convert_util.Copy(&res, obj)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add 用户协议新增
|
// Add 用户协议新增
|
||||||
func (service userProtocolService) Add(addReq UserProtocolAddReq) (createId int, e error) {
|
func (service userProtocolService) Add(addReq UserProtocolAddReq) (createId int, e error) {
|
||||||
var obj model.UserProtocol
|
var obj model.UserProtocol
|
||||||
util.ConvertUtil.StructToStruct(addReq, &obj)
|
convert_util.StructToStruct(addReq, &obj)
|
||||||
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 {
|
||||||
@@ -145,7 +146,7 @@ func (service userProtocolService) Edit(editReq UserProtocolEditReq) (e error) {
|
|||||||
if e = response.CheckErr(err, "查询失败"); e != nil {
|
if e = response.CheckErr(err, "查询失败"); e != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
util.ConvertUtil.Copy(&obj, editReq)
|
convert_util.Copy(&obj, editReq)
|
||||||
|
|
||||||
err = service.db.Model(&obj).Select("*").Updates(obj).Error
|
err = service.db.Model(&obj).Select("*").Updates(obj).Error
|
||||||
if e = response.CheckErr(err, "编辑失败"); e != nil {
|
if e = response.CheckErr(err, "编辑失败"); e != nil {
|
||||||
@@ -215,14 +216,14 @@ func (service userProtocolService) ExportFile(listReq UserProtocolListReq) (res
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
result := []UserProtocolResp{}
|
result := []UserProtocolResp{}
|
||||||
util.ConvertUtil.Copy(&result, modelList)
|
convert_util.Copy(&result, modelList)
|
||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 导入
|
// 导入
|
||||||
func (service userProtocolService) ImportFile(importReq []UserProtocolResp) (e error) {
|
func (service userProtocolService) ImportFile(importReq []UserProtocolResp) (e error) {
|
||||||
var importData []model.UserProtocol
|
var importData []model.UserProtocol
|
||||||
util.ConvertUtil.Copy(&importData, importReq)
|
convert_util.Copy(&importData, importReq)
|
||||||
err := service.db.Create(&importData).Error
|
err := service.db.Create(&importData).Error
|
||||||
e = response.CheckErr(err, "添加失败")
|
e = response.CheckErr(err, "添加失败")
|
||||||
return e
|
return e
|
||||||
|
@@ -4,7 +4,7 @@ import (
|
|||||||
"database/sql/driver"
|
"database/sql/driver"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"strconv"
|
"strconv"
|
||||||
"x_admin/util/convert"
|
"x_admin/util/convert_util"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Float类型别名,支持前端传递null,float64, string类型
|
// Float类型别名,支持前端传递null,float64, string类型
|
||||||
@@ -46,7 +46,7 @@ func DecodeFloat(value any) (any, error) {
|
|||||||
func (f *NullFloat) Scan(value interface{}) error {
|
func (f *NullFloat) Scan(value interface{}) error {
|
||||||
f.Valid = false
|
f.Valid = false
|
||||||
|
|
||||||
result, err := convert.ConvertUtil.ToFloat64(value)
|
result, err := convert_util.ToFloat64(value)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@@ -9,7 +9,7 @@ import (
|
|||||||
|
|
||||||
var ConfigUtil = configUtil{}
|
var ConfigUtil = configUtil{}
|
||||||
|
|
||||||
// convertUtil 数据库配置操作工具
|
// 数据库配置操作工具
|
||||||
type configUtil struct{}
|
type configUtil struct{}
|
||||||
|
|
||||||
// Get 根据类型和名称获取配置字典
|
// Get 根据类型和名称获取配置字典
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
package convert
|
package convert_util
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
@@ -13,12 +13,7 @@ import (
|
|||||||
"github.com/mitchellh/mapstructure"
|
"github.com/mitchellh/mapstructure"
|
||||||
)
|
)
|
||||||
|
|
||||||
var ConvertUtil = convertUtil{}
|
func ToFloat64(value interface{}) (float64, error) {
|
||||||
|
|
||||||
// convertUtil 转换工具
|
|
||||||
type convertUtil struct{}
|
|
||||||
|
|
||||||
func (c convertUtil) ToFloat64(value interface{}) (float64, error) {
|
|
||||||
switch v := value.(type) {
|
switch v := value.(type) {
|
||||||
case float64, float32:
|
case float64, float32:
|
||||||
return strconv.ParseFloat(fmt.Sprintf("%f", v), 64)
|
return strconv.ParseFloat(fmt.Sprintf("%f", v), 64)
|
||||||
@@ -30,7 +25,7 @@ func (c convertUtil) ToFloat64(value interface{}) (float64, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// StructToMap 结构体转换成map,深度转换
|
// StructToMap 结构体转换成map,深度转换
|
||||||
func (c convertUtil) StructToMap(from interface{}) map[string]interface{} {
|
func StructToMap(from interface{}) map[string]interface{} {
|
||||||
// var m = map[string]interface{}{}
|
// var m = map[string]interface{}{}
|
||||||
// mapstructure.Decode(from, &m) //深度转换所有结构体
|
// mapstructure.Decode(from, &m) //深度转换所有结构体
|
||||||
|
|
||||||
@@ -39,7 +34,7 @@ func (c convertUtil) StructToMap(from interface{}) map[string]interface{} {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// StructsToMaps 将结构体转换成Map列表
|
// StructsToMaps 将结构体转换成Map列表
|
||||||
func (c convertUtil) StructsToMaps(from interface{}) (data []map[string]interface{}) {
|
func StructsToMaps(from interface{}) (data []map[string]interface{}) {
|
||||||
var objList []interface{}
|
var objList []interface{}
|
||||||
err := copier.Copy(&objList, from)
|
err := copier.Copy(&objList, from)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -47,13 +42,13 @@ func (c convertUtil) StructsToMaps(from interface{}) (data []map[string]interfac
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
for _, v := range objList {
|
for _, v := range objList {
|
||||||
data = append(data, c.StructToMap(v))
|
data = append(data, StructToMap(v))
|
||||||
}
|
}
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
|
||||||
// ShallowStructToMap 将结构体转换成map,浅转换
|
// ShallowStructToMap 将结构体转换成map,浅转换
|
||||||
func (c convertUtil) ShallowStructToMap(from interface{}) map[string]interface{} {
|
func ShallowStructToMap(from interface{}) map[string]interface{} {
|
||||||
m := make(map[string]interface{})
|
m := make(map[string]interface{})
|
||||||
v := reflect.ValueOf(from)
|
v := reflect.ValueOf(from)
|
||||||
t := v.Type()
|
t := v.Type()
|
||||||
@@ -68,7 +63,7 @@ func (c convertUtil) ShallowStructToMap(from interface{}) map[string]interface{}
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ShallowStructsToMaps 将结构体列表转换成Map列表,浅转换
|
// ShallowStructsToMaps 将结构体列表转换成Map列表,浅转换
|
||||||
func (c convertUtil) ShallowStructsToMaps(from interface{}) (data []map[string]interface{}) {
|
func ShallowStructsToMaps(from interface{}) (data []map[string]interface{}) {
|
||||||
var objList []interface{}
|
var objList []interface{}
|
||||||
err := copier.Copy(&objList, from)
|
err := copier.Copy(&objList, from)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -76,26 +71,26 @@ func (c convertUtil) ShallowStructsToMaps(from interface{}) (data []map[string]i
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
for _, v := range objList {
|
for _, v := range objList {
|
||||||
data = append(data, c.ShallowStructToMap(v))
|
data = append(data, ShallowStructToMap(v))
|
||||||
}
|
}
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
|
||||||
// MapToStruct 将map弱类型转换成结构体
|
// MapToStruct 将map弱类型转换成结构体
|
||||||
func (c convertUtil) MapToStruct(from interface{}, to interface{}) (err error) {
|
func MapToStruct(from interface{}, to interface{}) (err error) {
|
||||||
err = mapstructure.WeakDecode(from, to) // 需要tag:mapstructure
|
err = mapstructure.WeakDecode(from, to) // 需要tag:mapstructure
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// StructToStruct 将结构体from弱类型转换成结构体to
|
// StructToStruct 将结构体from弱类型转换成结构体to
|
||||||
func (c convertUtil) StructToStruct(from interface{}, to interface{}) (err error) {
|
func StructToStruct(from interface{}, to interface{}) (err error) {
|
||||||
m := c.StructToMap(from)
|
m := StructToMap(from)
|
||||||
err = c.MapToStruct(m, to)
|
err = MapToStruct(m, to)
|
||||||
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c convertUtil) Copy(toValue interface{}, fromValue interface{}) interface{} {
|
func Copy(toValue interface{}, fromValue interface{}) interface{} {
|
||||||
if err := copier.Copy(toValue, fromValue); err != nil {
|
if err := copier.Copy(toValue, fromValue); err != nil {
|
||||||
// core.Logger.Errorf("Copy err: err=[%+v]", err)
|
// core.Logger.Errorf("Copy err: err=[%+v]", err)
|
||||||
panic("SystemError")
|
panic("SystemError")
|
@@ -2,7 +2,7 @@ package excel2
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"x_admin/util"
|
"x_admin/util/convert_util"
|
||||||
|
|
||||||
"github.com/xuri/excelize/v2"
|
"github.com/xuri/excelize/v2"
|
||||||
)
|
)
|
||||||
@@ -26,7 +26,7 @@ func GetExcelColumnName(columnNumber int) string {
|
|||||||
func Export(lists any, cols []Col, sheet string, title string) (file *excelize.File, err error) {
|
func Export(lists any, cols []Col, sheet string, title string) (file *excelize.File, err error) {
|
||||||
e := ExcelInit()
|
e := ExcelInit()
|
||||||
|
|
||||||
data := util.ConvertUtil.ShallowStructsToMaps(lists)
|
data := convert_util.ShallowStructsToMaps(lists)
|
||||||
|
|
||||||
err = ExportExcel(sheet, title, data, cols, e)
|
err = ExportExcel(sheet, title, data, cols, e)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@@ -6,7 +6,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"mime/multipart"
|
"mime/multipart"
|
||||||
"x_admin/util"
|
"x_admin/util/convert_util"
|
||||||
|
|
||||||
"github.com/xuri/excelize/v2"
|
"github.com/xuri/excelize/v2"
|
||||||
)
|
)
|
||||||
@@ -99,7 +99,7 @@ func importData(f *excelize.File, dst interface{}, sheetName string, startRow in
|
|||||||
data = append(data, rowMap)
|
data = append(data, rowMap)
|
||||||
|
|
||||||
}
|
}
|
||||||
util.ConvertUtil.MapToStruct(data, dst)
|
convert_util.MapToStruct(data, dst)
|
||||||
|
|
||||||
// fmt.Println("Type.Name:", field.Type.Name(), field.Type.Kind())
|
// fmt.Println("Type.Name:", field.Type.Name(), field.Type.Kind())
|
||||||
// // 根据字段类型设置值
|
// // 根据字段类型设置值
|
||||||
|
Reference in New Issue
Block a user