diff --git a/server/api/v1/autocode/autocodeExample.go b/server/api/v1/autocode/autocodeExample.go new file mode 100644 index 0000000000000000000000000000000000000000..f8245237da7c5352388805f7c7d78435a94ac68f --- /dev/null +++ b/server/api/v1/autocode/autocodeExample.go @@ -0,0 +1,121 @@ +package autocode + +import ( + "gin-vue-admin/global" + "gin-vue-admin/model/autocode" + "gin-vue-admin/model/autocode/requset" + "gin-vue-admin/model/common/response" + "gin-vue-admin/service" + "gin-vue-admin/utils" + "github.com/gin-gonic/gin" + "go.uber.org/zap" +) + +type AutoCodeExampleApi struct { +} + +var autoCodeExampleService = service.ServiceGroupApp.AutoCodeServiceGroup.AutoCodeExampleService + +// @Tags AutoCodeExample +// @Summary 创建AutoCodeExample +// @Security ApiKeyAuth +// @accept application/json +// @Produce application/json +// @Param data body autocode.AutoCodeExample true "AutoCodeExample模型" +// @Success 200 {string} string "{"success":true,"data":{},"msg":"创建成功"}" +// @Router /autoCodeExample/createAutoCodeExample [post] +func (autoCodeExampleApi *AutoCodeExampleApi) CreateAutoCodeExample(c *gin.Context) { + var detail autocode.AutoCodeExample + _ = c.ShouldBindJSON(&detail) + if err := autoCodeExampleService.CreateAutoCodeExample(detail); err != nil { + global.GVA_LOG.Error("创建失败!", zap.Any("err", err)) + response.FailWithMessage("创建失败", c) + } else { + response.OkWithMessage("创建成功", c) + } +} + +// @Tags AutoCodeExample +// @Summary 删除AutoCodeExample +// @Security ApiKeyAuth +// @accept application/json +// @Produce application/json +// @Param data body autocode.AutoCodeExample true "AutoCodeExample模型" +// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}" +// @Router /autoCodeExample/deleteAutoCodeExample [delete] +func (autoCodeExampleApi *AutoCodeExampleApi) DeleteAutoCodeExample(c *gin.Context) { + var detail autocode.AutoCodeExample + _ = c.ShouldBindJSON(&detail) + if err := autoCodeExampleService.DeleteAutoCodeExample(detail); err != nil { + global.GVA_LOG.Error("删除失败!", zap.Any("err", err)) + response.FailWithMessage("删除失败", c) + } else { + response.OkWithMessage("删除成功", c) + } +} + +// @Tags AutoCodeExample +// @Summary 更新AutoCodeExample +// @Security ApiKeyAuth +// @accept application/json +// @Produce application/json +// @Param data body autocode.AutoCodeExample true "更新AutoCodeExample" +// @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}" +// @Router /autoCodeExample/updateAutoCodeExample [put] +func (autoCodeExampleApi *AutoCodeExampleApi) UpdateAutoCodeExample(c *gin.Context) { + var detail autocode.AutoCodeExample + _ = c.ShouldBindJSON(&detail) + if err := autoCodeExampleService.UpdateAutoCodeExample(&detail); err != nil { + global.GVA_LOG.Error("更新失败!", zap.Any("err", err)) + response.FailWithMessage("更新失败", c) + } else { + response.OkWithMessage("更新成功", c) + } +} + +// @Tags AutoCodeExample +// @Summary 用id查询AutoCodeExample +// @Security ApiKeyAuth +// @accept application/json +// @Produce application/json +// @Param data body autocode.AutoCodeExample true "用id查询AutoCodeExample" +// @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}" +// @Router /autoCodeExample/findAutoCodeExample [get] +func (autoCodeExampleApi *AutoCodeExampleApi) FindAutoCodeExample(c *gin.Context) { + var detail autocode.AutoCodeExample + _ = c.ShouldBindQuery(&detail) + if err := utils.Verify(detail, utils.IdVerify); err != nil { + response.FailWithMessage(err.Error(), c) + return + } + if err, reAutoCodeExample := autoCodeExampleService.GetAutoCodeExample(detail.ID); err != nil { + global.GVA_LOG.Error("查询失败!", zap.Any("err", err)) + response.FailWithMessage("查询失败", c) + } else { + response.OkWithDetailed(gin.H{"reAutoCodeExample": reAutoCodeExample}, "查询成功", c) + } +} + +// @Tags AutoCodeExample +// @Summary 分页获取AutoCodeExample列表 +// @Security ApiKeyAuth +// @accept application/json +// @Produce application/json +// @Param data body request.AutoCodeExampleSearch true "页码, 每页大小, 搜索条件" +// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}" +// @Router /autoCodeExample/getAutoCodeExampleList [get] +func (autoCodeExampleApi *AutoCodeExampleApi) GetAutoCodeExampleList(c *gin.Context) { + var pageInfo request.AutoCodeExampleSearch + _ = c.ShouldBindQuery(&pageInfo) + if err, list, total := autoCodeExampleService.GetAutoCodeExampleInfoList(pageInfo); err != nil { + global.GVA_LOG.Error("获取失败!", zap.Any("err", err)) + response.FailWithMessage("获取失败", c) + } else { + response.OkWithDetailed(response.PageResult{ + List: list, + Total: total, + Page: pageInfo.Page, + PageSize: pageInfo.PageSize, + }, "获取成功", c) + } +} diff --git a/server/api/v1/autocode/enter.go b/server/api/v1/autocode/enter.go new file mode 100644 index 0000000000000000000000000000000000000000..b578bf30d614e5122eb45fe4b13efcd46691b789 --- /dev/null +++ b/server/api/v1/autocode/enter.go @@ -0,0 +1,5 @@ +package autocode + +type ApiGroup struct { + AutoCodeExampleApi +} diff --git a/server/api/v1/enter.go b/server/api/v1/enter.go new file mode 100644 index 0000000000000000000000000000000000000000..b25171986687e19e8aae0a24bbec19776e62c165 --- /dev/null +++ b/server/api/v1/enter.go @@ -0,0 +1,15 @@ +package v1 + +import ( + "gin-vue-admin/api/v1/autocode" + "gin-vue-admin/api/v1/example" + "gin-vue-admin/api/v1/system" +) + +type ApiGroup struct { + ExampleApiGroup example.ApiGroup + SystemApiGroup system.ApiGroup + AutoCodeApiGroup autocode.ApiGroup +} + +var ApiGroupApp = new(ApiGroup) diff --git a/server/api/v1/example/enter.go b/server/api/v1/example/enter.go new file mode 100644 index 0000000000000000000000000000000000000000..d68423bf738d7b72628ff3a6760683ae3b95804b --- /dev/null +++ b/server/api/v1/example/enter.go @@ -0,0 +1,15 @@ +package example + +import "gin-vue-admin/service" + +type ApiGroup struct { + CustomerApi + ExcelApi + FileUploadAndDownloadApi + SimpleUploaderApi +} + +var fileUploadAndDownloadService = service.ServiceGroupApp.ExampleServiceGroup.FileUploadAndDownloadService +var customerService = service.ServiceGroupApp.ExampleServiceGroup.CustomerService +var excelService = service.ServiceGroupApp.ExampleServiceGroup.ExcelService +var simpleUploaderService = service.ServiceGroupApp.ExampleServiceGroup.SimpleUploaderService diff --git a/server/api/v1/exa_breakpoint_continue.go b/server/api/v1/example/exa_breakpoint_continue.go similarity index 74% rename from server/api/v1/exa_breakpoint_continue.go rename to server/api/v1/example/exa_breakpoint_continue.go index 2ecc495bd666d6500cd99f339b909b4ad0162082..03a04c1591a06e51d28cf4216a4e7f4f3e0d5ae4 100644 --- a/server/api/v1/exa_breakpoint_continue.go +++ b/server/api/v1/example/exa_breakpoint_continue.go @@ -1,9 +1,9 @@ -package v1 +package example import ( "gin-vue-admin/global" - "gin-vue-admin/model/example/response" - "gin-vue-admin/service" + "gin-vue-admin/model/common/response" + exampleRes "gin-vue-admin/model/example/response" "gin-vue-admin/utils" "github.com/gin-gonic/gin" "go.uber.org/zap" @@ -19,7 +19,7 @@ import ( // @Param file formData file true "an example for breakpoint resume, 断点续传示例" // @Success 200 {string} string "{"success":true,"data":{},"msg":"切片创建成功"}" // @Router /fileUploadAndDownload/breakpointContinue [post] -func BreakpointContinue(c *gin.Context) { +func (u *FileUploadAndDownloadApi) BreakpointContinue(c *gin.Context) { fileMd5 := c.Request.FormValue("fileMd5") fileName := c.Request.FormValue("fileName") chunkMd5 := c.Request.FormValue("chunkMd5") @@ -44,7 +44,7 @@ func BreakpointContinue(c *gin.Context) { response.FailWithMessage("检查md5失败", c) return } - err, file := service.FindOrCreateFile(fileMd5, fileName, chunkTotal) + err, file := fileUploadAndDownloadService.FindOrCreateFile(fileMd5, fileName, chunkTotal) if err != nil { global.GVA_LOG.Error("查找或创建记录失败!", zap.Any("err", err)) response.FailWithMessage("查找或创建记录失败", c) @@ -57,7 +57,7 @@ func BreakpointContinue(c *gin.Context) { return } - if err = service.CreateFileChunk(file.ID, pathc, chunkNumber); err != nil { + if err = fileUploadAndDownloadService.CreateFileChunk(file.ID, pathc, chunkNumber); err != nil { global.GVA_LOG.Error("创建文件记录失败!", zap.Any("err", err)) response.FailWithMessage("创建文件记录失败", c) return @@ -73,16 +73,16 @@ func BreakpointContinue(c *gin.Context) { // @Param file formData file true "Find the file, 查找文件" // @Success 200 {string} string "{"success":true,"data":{},"msg":"查找成功"}" // @Router /fileUploadAndDownload/findFile [post] -func FindFile(c *gin.Context) { +func (u *FileUploadAndDownloadApi) FindFile(c *gin.Context) { fileMd5 := c.Query("fileMd5") fileName := c.Query("fileName") chunkTotal, _ := strconv.Atoi(c.Query("chunkTotal")) - err, file := service.FindOrCreateFile(fileMd5, fileName, chunkTotal) + err, file := fileUploadAndDownloadService.FindOrCreateFile(fileMd5, fileName, chunkTotal) if err != nil { global.GVA_LOG.Error("查找失败!", zap.Any("err", err)) response.FailWithMessage("查找失败", c) } else { - response.OkWithDetailed(response.FileResponse{File: file}, "查找成功", c) + response.OkWithDetailed(exampleRes.FileResponse{File: file}, "查找成功", c) } } @@ -94,15 +94,15 @@ func FindFile(c *gin.Context) { // @Param file formData file true "上传文件完成" // @Success 200 {string} string "{"success":true,"data":{},"msg":"file uploaded, 文件创建成功"}" // @Router /fileUploadAndDownload/findFile [post] -func BreakpointContinueFinish(c *gin.Context) { +func (b *FileUploadAndDownloadApi) BreakpointContinueFinish(c *gin.Context) { fileMd5 := c.Query("fileMd5") fileName := c.Query("fileName") err, filePath := utils.MakeFile(fileName, fileMd5) if err != nil { global.GVA_LOG.Error("文件创建失败!", zap.Any("err", err)) - response.FailWithDetailed(response.FilePathResponse{FilePath: filePath}, "文件创建失败", c) + response.FailWithDetailed(exampleRes.FilePathResponse{FilePath: filePath}, "文件创建失败", c) } else { - response.OkWithDetailed(response.FilePathResponse{FilePath: filePath}, "文件创建成功", c) + response.OkWithDetailed(exampleRes.FilePathResponse{FilePath: filePath}, "文件创建成功", c) } } @@ -114,16 +114,16 @@ func BreakpointContinueFinish(c *gin.Context) { // @Param file formData file true "删除缓存切片" // @Success 200 {string} string "{"success":true,"data":{},"msg":"缓存切片删除成功"}" // @Router /fileUploadAndDownload/removeChunk [post] -func RemoveChunk(c *gin.Context) { +func (u *FileUploadAndDownloadApi) RemoveChunk(c *gin.Context) { fileMd5 := c.Query("fileMd5") fileName := c.Query("fileName") filePath := c.Query("filePath") err := utils.RemoveChunk(fileMd5) - err = service.DeleteFileChunk(fileMd5, fileName, filePath) + err = fileUploadAndDownloadService.DeleteFileChunk(fileMd5, fileName, filePath) if err != nil { global.GVA_LOG.Error("缓存切片删除失败!", zap.Any("err", err)) - response.FailWithDetailed(response.FilePathResponse{FilePath: filePath}, "缓存切片删除失败", c) + response.FailWithDetailed(exampleRes.FilePathResponse{FilePath: filePath}, "缓存切片删除失败", c) } else { - response.OkWithDetailed(response.FilePathResponse{FilePath: filePath}, "缓存切片删除成功", c) + response.OkWithDetailed(exampleRes.FilePathResponse{FilePath: filePath}, "缓存切片删除成功", c) } } diff --git a/server/api/v1/exa_customer.go b/server/api/v1/example/exa_customer.go similarity index 78% rename from server/api/v1/exa_customer.go rename to server/api/v1/example/exa_customer.go index a160dec6cefedf503a7cd6bd154ca655d7c89c26..80066dbed3d4ce408ce044c04d8b982c36332a3f 100644 --- a/server/api/v1/exa_customer.go +++ b/server/api/v1/example/exa_customer.go @@ -1,16 +1,19 @@ -package v1 +package example import ( "gin-vue-admin/global" + "gin-vue-admin/model/common/request" + "gin-vue-admin/model/common/response" "gin-vue-admin/model/example" - "gin-vue-admin/model/example/request" - "gin-vue-admin/model/example/response" - "gin-vue-admin/service" + exampleRes "gin-vue-admin/model/example/response" "gin-vue-admin/utils" "github.com/gin-gonic/gin" "go.uber.org/zap" ) +type CustomerApi struct { +} + // @Tags ExaCustomer // @Summary 创建客户 // @Security ApiKeyAuth @@ -19,16 +22,16 @@ import ( // @Param data body model.ExaCustomer true "客户用户名, 客户手机号码" // @Success 200 {string} string "{"success":true,"data":{},"msg":"创建成功"}" // @Router /customer/customer [post] -func CreateExaCustomer(c *gin.Context) { +func (e *CustomerApi) CreateExaCustomer(c *gin.Context) { var customer example.ExaCustomer _ = c.ShouldBindJSON(&customer) if err := utils.Verify(customer, utils.CustomerVerify); err != nil { response.FailWithMessage(err.Error(), c) return } - customer.SysUserID = getUserID(c) - customer.SysUserAuthorityID = getUserAuthorityId(c) - if err := service.CreateExaCustomer(customer); err != nil { + customer.SysUserID = utils.GetUserID(c) + customer.SysUserAuthorityID = utils.GetUserAuthorityId(c) + if err := customerService.CreateExaCustomer(customer); err != nil { global.GVA_LOG.Error("创建失败!", zap.Any("err", err)) response.FailWithMessage("创建失败", c) } else { @@ -44,14 +47,14 @@ func CreateExaCustomer(c *gin.Context) { // @Param data body model.ExaCustomer true "客户ID" // @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}" // @Router /customer/customer [delete] -func DeleteExaCustomer(c *gin.Context) { +func (e *CustomerApi) DeleteExaCustomer(c *gin.Context) { var customer example.ExaCustomer _ = c.ShouldBindJSON(&customer) if err := utils.Verify(customer.GVA_MODEL, utils.IdVerify); err != nil { response.FailWithMessage(err.Error(), c) return } - if err := service.DeleteExaCustomer(customer); err != nil { + if err := customerService.DeleteExaCustomer(customer); err != nil { global.GVA_LOG.Error("删除失败!", zap.Any("err", err)) response.FailWithMessage("删除失败", c) } else { @@ -67,7 +70,7 @@ func DeleteExaCustomer(c *gin.Context) { // @Param data body model.ExaCustomer true "客户ID, 客户信息" // @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}" // @Router /customer/customer [put] -func UpdateExaCustomer(c *gin.Context) { +func (e *CustomerApi) UpdateExaCustomer(c *gin.Context) { var customer example.ExaCustomer _ = c.ShouldBindJSON(&customer) if err := utils.Verify(customer.GVA_MODEL, utils.IdVerify); err != nil { @@ -78,7 +81,7 @@ func UpdateExaCustomer(c *gin.Context) { response.FailWithMessage(err.Error(), c) return } - if err := service.UpdateExaCustomer(&customer); err != nil { + if err := customerService.UpdateExaCustomer(&customer); err != nil { global.GVA_LOG.Error("更新失败!", zap.Any("err", err)) response.FailWithMessage("更新失败", c) } else { @@ -94,19 +97,19 @@ func UpdateExaCustomer(c *gin.Context) { // @Param data body model.ExaCustomer true "客户ID" // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}" // @Router /customer/customer [get] -func GetExaCustomer(c *gin.Context) { +func (e *CustomerApi) GetExaCustomer(c *gin.Context) { var customer example.ExaCustomer _ = c.ShouldBindQuery(&customer) if err := utils.Verify(customer.GVA_MODEL, utils.IdVerify); err != nil { response.FailWithMessage(err.Error(), c) return } - err, data := service.GetExaCustomer(customer.ID) + err, data := customerService.GetExaCustomer(customer.ID) if err != nil { global.GVA_LOG.Error("获取失败!", zap.Any("err", err)) response.FailWithMessage("获取失败", c) } else { - response.OkWithDetailed(response.ExaCustomerResponse{Customer: data}, "获取成功", c) + response.OkWithDetailed(exampleRes.ExaCustomerResponse{Customer: data}, "获取成功", c) } } @@ -118,14 +121,14 @@ func GetExaCustomer(c *gin.Context) { // @Param data body request.PageInfo true "页码, 每页大小" // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}" // @Router /customer/customerList [get] -func GetExaCustomerList(c *gin.Context) { +func (e *CustomerApi) GetExaCustomerList(c *gin.Context) { var pageInfo request.PageInfo _ = c.ShouldBindQuery(&pageInfo) if err := utils.Verify(pageInfo, utils.PageInfoVerify); err != nil { response.FailWithMessage(err.Error(), c) return } - err, customerList, total := service.GetCustomerInfoList(getUserAuthorityId(c), pageInfo) + err, customerList, total := customerService.GetCustomerInfoList(utils.GetUserAuthorityId(c), pageInfo) if err != nil { global.GVA_LOG.Error("获取失败!", zap.Any("err", err)) response.FailWithMessage("获取失败"+err.Error(), c) diff --git a/server/api/v1/exa_excel.go b/server/api/v1/example/exa_excel.go similarity index 88% rename from server/api/v1/exa_excel.go rename to server/api/v1/example/exa_excel.go index bdeed9d754f4bfb029c05a570f97628ad5159a6b..d71fed9596f390a5cddab13a2484f0589bd37662 100644 --- a/server/api/v1/exa_excel.go +++ b/server/api/v1/example/exa_excel.go @@ -1,15 +1,17 @@ -package v1 +package example import ( "gin-vue-admin/global" + "gin-vue-admin/model/common/response" "gin-vue-admin/model/example" - "gin-vue-admin/model/response" - "gin-vue-admin/service" "gin-vue-admin/utils" "github.com/gin-gonic/gin" "go.uber.org/zap" ) +type ExcelApi struct { +} + // /excel/importExcel 接口,与upload接口作用类似,只是把文件存到resource/excel目录下,用于导入Excel时存放Excel文件(ExcelImport.xlsx) // /excel/loadExcel接口,用于读取resource/excel目录下的文件((ExcelImport.xlsx)并加载为[]model.SysBaseMenu类型的示例数据 // /excel/exportExcel 接口,用于读取前端传来的tableData,生成Excel文件并返回 @@ -23,11 +25,11 @@ import ( // @Param data body model.ExcelInfo true "导出Excel文件信息" // @Success 200 // @Router /excel/exportExcel [post] -func ExportExcel(c *gin.Context) { +func (e *ExcelApi) ExportExcel(c *gin.Context) { var excelInfo example.ExcelInfo _ = c.ShouldBindJSON(&excelInfo) filePath := global.GVA_CONFIG.Excel.Dir + excelInfo.FileName - err := service.ParseInfoList2Excel(excelInfo.InfoList, filePath) + err := excelService.ParseInfoList2Excel(excelInfo.InfoList, filePath) if err != nil { global.GVA_LOG.Error("转换Excel失败!", zap.Any("err", err)) response.FailWithMessage("转换Excel失败", c) @@ -45,7 +47,7 @@ func ExportExcel(c *gin.Context) { // @Param file formData file true "导入Excel文件" // @Success 200 {string} string "{"success":true,"data":{},"msg":"导入成功"}" // @Router /excel/importExcel [post] -func ImportExcel(c *gin.Context) { +func (e *ExcelApi) ImportExcel(c *gin.Context) { _, header, err := c.Request.FormFile("file") if err != nil { global.GVA_LOG.Error("接收文件失败!", zap.Any("err", err)) @@ -62,8 +64,8 @@ func ImportExcel(c *gin.Context) { // @Produce application/json // @Success 200 {string} string "{"success":true,"data":{},"msg":"加载数据成功"}" // @Router /excel/loadExcel [get] -func LoadExcel(c *gin.Context) { - menus, err := service.ParseExcel2InfoList() +func (e *ExcelApi) LoadExcel(c *gin.Context) { + menus, err := excelService.ParseExcel2InfoList() if err != nil { global.GVA_LOG.Error("加载数据失败!", zap.Any("err", err)) response.FailWithMessage("加载数据失败", c) @@ -85,7 +87,7 @@ func LoadExcel(c *gin.Context) { // @Param fileName query string true "模板名称" // @Success 200 // @Router /excel/downloadTemplate [get] -func DownloadTemplate(c *gin.Context) { +func (e *ExcelApi) DownloadTemplate(c *gin.Context) { fileName := c.Query("fileName") filePath := global.GVA_CONFIG.Excel.Dir + fileName ok, err := utils.PathExists(filePath) diff --git a/server/api/v1/exa_file_upload_download.go b/server/api/v1/example/exa_file_upload_download.go similarity index 75% rename from server/api/v1/exa_file_upload_download.go rename to server/api/v1/example/exa_file_upload_download.go index a559675158f4334749a0d7fcb2724761940fd355..33310fbf98cfd9d0017e71577b7a8c12b07ceacf 100644 --- a/server/api/v1/exa_file_upload_download.go +++ b/server/api/v1/example/exa_file_upload_download.go @@ -1,15 +1,18 @@ -package v1 +package example import ( "gin-vue-admin/global" + "gin-vue-admin/model/common/request" + "gin-vue-admin/model/common/response" "gin-vue-admin/model/example" - "gin-vue-admin/model/example/request" - "gin-vue-admin/model/example/response" - "gin-vue-admin/service" + exampleRes "gin-vue-admin/model/example/response" "github.com/gin-gonic/gin" "go.uber.org/zap" ) +type FileUploadAndDownloadApi struct { +} + // @Tags ExaFileUploadAndDownload // @Summary 上传文件示例 // @Security ApiKeyAuth @@ -18,7 +21,7 @@ import ( // @Param file formData file true "上传文件示例" // @Success 200 {string} string "{"success":true,"data":{},"msg":"上传成功"}" // @Router /fileUploadAndDownload/upload [post] -func UploadFile(c *gin.Context) { +func (u *FileUploadAndDownloadApi) UploadFile(c *gin.Context) { var file example.ExaFileUploadAndDownload noSave := c.DefaultQuery("noSave", "0") _, header, err := c.Request.FormFile("file") @@ -27,13 +30,13 @@ func UploadFile(c *gin.Context) { response.FailWithMessage("接收文件失败", c) return } - err, file = service.UploadFile(header, noSave) // 文件上传后拿到文件路径 + err, file = fileUploadAndDownloadService.UploadFile(header, noSave) // 文件上传后拿到文件路径 if err != nil { global.GVA_LOG.Error("修改数据库链接失败!", zap.Any("err", err)) response.FailWithMessage("修改数据库链接失败", c) return } - response.OkWithDetailed(response.ExaFileResponse{File: file}, "上传成功", c) + response.OkWithDetailed(exampleRes.ExaFileResponse{File: file}, "上传成功", c) } // @Tags ExaFileUploadAndDownload @@ -43,10 +46,10 @@ func UploadFile(c *gin.Context) { // @Param data body model.ExaFileUploadAndDownload true "传入文件里面id即可" // @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}" // @Router /fileUploadAndDownload/deleteFile [post] -func DeleteFile(c *gin.Context) { +func (u *FileUploadAndDownloadApi) DeleteFile(c *gin.Context) { var file example.ExaFileUploadAndDownload _ = c.ShouldBindJSON(&file) - if err := service.DeleteFile(file); err != nil { + if err := fileUploadAndDownloadService.DeleteFile(file); err != nil { global.GVA_LOG.Error("删除失败!", zap.Any("err", err)) response.FailWithMessage("删除失败", c) return @@ -62,10 +65,10 @@ func DeleteFile(c *gin.Context) { // @Param data body request.PageInfo true "页码, 每页大小" // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}" // @Router /fileUploadAndDownload/getFileList [post] -func GetFileList(c *gin.Context) { +func (u *FileUploadAndDownloadApi) GetFileList(c *gin.Context) { var pageInfo request.PageInfo _ = c.ShouldBindJSON(&pageInfo) - err, list, total := service.GetFileRecordInfoList(pageInfo) + err, list, total := fileUploadAndDownloadService.GetFileRecordInfoList(pageInfo) if err != nil { global.GVA_LOG.Error("获取失败!", zap.Any("err", err)) response.FailWithMessage("获取失败", c) diff --git a/server/api/v1/exa_simple_uploader.go b/server/api/v1/example/exa_simple_uploader.go similarity index 81% rename from server/api/v1/exa_simple_uploader.go rename to server/api/v1/example/exa_simple_uploader.go index 0bff500924711a559eb2c8ef3558ad4ffc411168..566df369194ac1193eb4abc10cbb7a05f36881dd 100644 --- a/server/api/v1/exa_simple_uploader.go +++ b/server/api/v1/example/exa_simple_uploader.go @@ -1,15 +1,17 @@ -package v1 +package example import ( "gin-vue-admin/global" + "gin-vue-admin/model/common/response" "gin-vue-admin/model/example" - "gin-vue-admin/model/response" - "gin-vue-admin/service" "gin-vue-admin/utils" "github.com/gin-gonic/gin" "go.uber.org/zap" ) +type SimpleUploaderApi struct { +} + // @Tags SimpleUploader // @Summary 断点续传插件版示例 // @Security ApiKeyAuth @@ -17,8 +19,8 @@ import ( // @Produce application/json // @Param file formData file true "断点续传插件版示例" // @Success 200 {string} string "{"success":true,"data":{},"msg":"切片创建成功"}" -// @Router /simpleUploader/upload [post] -func SimpleUploaderUpload(c *gin.Context) { +// @Router /SimpleUploaderApi/upload [post] +func (s *SimpleUploaderApi) SimpleUploaderUpload(c *gin.Context) { var chunk example.ExaSimpleUploader _, header, err := c.Request.FormFile("file") chunk.Filename = c.PostForm("filename") @@ -42,7 +44,7 @@ func SimpleUploaderUpload(c *gin.Context) { return } chunk.CurrentChunkPath = chunkPath - err = service.SaveChunk(chunk) + err = simpleUploaderService.SaveChunk(chunk) if err != nil { global.GVA_LOG.Error("切片创建失败!", zap.Any("err", err)) response.FailWithMessage("切片创建失败", c) @@ -58,10 +60,10 @@ func SimpleUploaderUpload(c *gin.Context) { // @Produce application/json // @Param md5 query string true "md5" // @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}" -// @Router /simpleUploader/checkFileMd5 [get] -func CheckFileMd5(c *gin.Context) { +// @Router /SimpleUploaderApi/checkFileMd5 [get] +func (s *SimpleUploaderApi) CheckFileMd5(c *gin.Context) { md5 := c.Query("md5") - err, chunks, isDone := service.CheckFileMd5(md5) + err, chunks, isDone := simpleUploaderService.CheckFileMd5(md5) if err != nil { global.GVA_LOG.Error("md5读取失败!", zap.Any("err", err)) response.FailWithMessage("md5读取失败", c) @@ -79,11 +81,11 @@ func CheckFileMd5(c *gin.Context) { // @Produce application/json // @Param md5 query string true "md5" // @Success 200 {string} string "{"success":true,"data":{},"msg":"合并成功"}" -// @Router /simpleUploader/mergeFileMd5 [get] -func MergeFileMd5(c *gin.Context) { +// @Router /SimpleUploaderApi/mergeFileMd5 [get] +func (s *SimpleUploaderApi) MergeFileMd5(c *gin.Context) { md5 := c.Query("md5") fileName := c.Query("fileName") - err := service.MergeFileMd5(md5, fileName) + err := simpleUploaderService.MergeFileMd5(md5, fileName) if err != nil { global.GVA_LOG.Error("md5读取失败!", zap.Any("err", err)) response.FailWithMessage("md5读取失败", c) diff --git a/server/api/v1/system/enter.go b/server/api/v1/system/enter.go new file mode 100644 index 0000000000000000000000000000000000000000..aa4eb730f25fa8e873c1c5036c9b6d74eeb60b20 --- /dev/null +++ b/server/api/v1/system/enter.go @@ -0,0 +1,34 @@ +package system + +import "gin-vue-admin/service" + +type ApiGroup struct { + SystemApiApi + AuthorityApi + AutoCodeApi + BaseApi + CasbinApi + DictionaryApi + DictionaryDetailApi + SystemApi + DBApi + JwtApi + OperationRecordApi + AuthorityMenuApi +} + +var authorityService = service.ServiceGroupApp.SystemServiceGroup.AuthorityService +var apiService = service.ServiceGroupApp.SystemServiceGroup.ApiService +var menuService = service.ServiceGroupApp.SystemServiceGroup.MenuService +var casbinService = service.ServiceGroupApp.SystemServiceGroup.CasbinService +var autoCodeService = service.ServiceGroupApp.SystemServiceGroup.AutoCodeService +var autoCodeHistoryService = service.ServiceGroupApp.SystemServiceGroup.AutoCodeHistoryService +var dictionaryService = service.ServiceGroupApp.SystemServiceGroup.DictionaryService +var dictionaryDetailService = service.ServiceGroupApp.SystemServiceGroup.DictionaryDetailService +var emailService = service.ServiceGroupApp.SystemServiceGroup.EmailService +var initDBService = service.ServiceGroupApp.SystemServiceGroup.InitDBService +var jwtService = service.ServiceGroupApp.SystemServiceGroup.JwtService +var baseMenuService = service.ServiceGroupApp.SystemServiceGroup.BaseMenuService +var operationRecordService = service.ServiceGroupApp.SystemServiceGroup.OperationRecordService +var userService = service.ServiceGroupApp.SystemServiceGroup.UserService +var systemConfigService = service.ServiceGroupApp.SystemServiceGroup.SystemConfigService diff --git a/server/api/v1/sys_api.go b/server/api/v1/system/sys_api.go similarity index 76% rename from server/api/v1/sys_api.go rename to server/api/v1/system/sys_api.go index d5fe9e419f5d624de80c968dc13ea342b8867a98..16907961461867f6719b01f1a92faae242a11dc8 100644 --- a/server/api/v1/sys_api.go +++ b/server/api/v1/system/sys_api.go @@ -1,17 +1,21 @@ -package v1 +package system import ( "gin-vue-admin/global" + "gin-vue-admin/model/common/request" + "gin-vue-admin/model/common/response" "gin-vue-admin/model/system" - "gin-vue-admin/model/system/request" - "gin-vue-admin/model/system/response" - "gin-vue-admin/service" + systemReq "gin-vue-admin/model/system/request" + systemRes "gin-vue-admin/model/system/response" "gin-vue-admin/utils" "github.com/gin-gonic/gin" "go.uber.org/zap" ) +type SystemApiApi struct { +} + // @Tags SysApi // @Summary 创建基础api // @Security ApiKeyAuth @@ -20,14 +24,14 @@ import ( // @Param data body model.SysApi true "api路径, api中文描述, api组, 方法" // @Success 200 {string} string "{"success":true,"data":{},"msg":"创建成功"}" // @Router /api/createApi [post] -func CreateApi(c *gin.Context) { +func (s *SystemApiApi) CreateApi(c *gin.Context) { var api system.SysApi _ = c.ShouldBindJSON(&api) if err := utils.Verify(api, utils.ApiVerify); err != nil { response.FailWithMessage(err.Error(), c) return } - if err := service.CreateApi(api); err != nil { + if err := apiService.CreateApi(api); err != nil { global.GVA_LOG.Error("创建失败!", zap.Any("err", err)) response.FailWithMessage("创建失败", c) } else { @@ -43,14 +47,14 @@ func CreateApi(c *gin.Context) { // @Param data body model.SysApi true "ID" // @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}" // @Router /api/deleteApi [post] -func DeleteApi(c *gin.Context) { +func (s *SystemApiApi) DeleteApi(c *gin.Context) { var api system.SysApi _ = c.ShouldBindJSON(&api) if err := utils.Verify(api.GVA_MODEL, utils.IdVerify); err != nil { response.FailWithMessage(err.Error(), c) return } - if err := service.DeleteApi(api); err != nil { + if err := apiService.DeleteApi(api); err != nil { global.GVA_LOG.Error("删除失败!", zap.Any("err", err)) response.FailWithMessage("删除失败", c) } else { @@ -63,17 +67,17 @@ func DeleteApi(c *gin.Context) { // @Security ApiKeyAuth // @accept application/json // @Produce application/json -// @Param data body request.SearchApiParams true "分页获取API列表" +// @Param data body systemReq.SearchApiParams true "分页获取API列表" // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}" // @Router /api/getApiList [post] -func GetApiList(c *gin.Context) { - var pageInfo request.SearchApiParams +func (s *SystemApiApi) GetApiList(c *gin.Context) { + var pageInfo systemReq.SearchApiParams _ = c.ShouldBindJSON(&pageInfo) if err := utils.Verify(pageInfo.PageInfo, utils.PageInfoVerify); err != nil { response.FailWithMessage(err.Error(), c) return } - if err, list, total := service.GetAPIInfoList(pageInfo.SysApi, pageInfo.PageInfo, pageInfo.OrderKey, pageInfo.Desc); err != nil { + if err, list, total := apiService.GetAPIInfoList(pageInfo.SysApi, pageInfo.PageInfo, pageInfo.OrderKey, pageInfo.Desc); err != nil { global.GVA_LOG.Error("获取失败!", zap.Any("err", err)) response.FailWithMessage("获取失败", c) } else { @@ -94,19 +98,19 @@ func GetApiList(c *gin.Context) { // @Param data body request.GetById true "根据id获取api" // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}" // @Router /api/getApiById [post] -func GetApiById(c *gin.Context) { +func (s *SystemApiApi) GetApiById(c *gin.Context) { var idInfo request.GetById _ = c.ShouldBindJSON(&idInfo) if err := utils.Verify(idInfo, utils.IdVerify); err != nil { response.FailWithMessage(err.Error(), c) return } - err, api := service.GetApiById(idInfo.ID) + err, api := apiService.GetApiById(idInfo.ID) if err != nil { global.GVA_LOG.Error("获取失败!", zap.Any("err", err)) response.FailWithMessage("获取失败", c) } else { - response.OkWithData(response.SysAPIResponse{Api: api}, c) + response.OkWithData(systemRes.SysAPIResponse{Api: api}, c) } } @@ -118,14 +122,14 @@ func GetApiById(c *gin.Context) { // @Param data body model.SysApi true "api路径, api中文描述, api组, 方法" // @Success 200 {string} string "{"success":true,"data":{},"msg":"修改成功"}" // @Router /api/updateApi [post] -func UpdateApi(c *gin.Context) { +func (s *SystemApiApi) UpdateApi(c *gin.Context) { var api system.SysApi _ = c.ShouldBindJSON(&api) if err := utils.Verify(api, utils.ApiVerify); err != nil { response.FailWithMessage(err.Error(), c) return } - if err := service.UpdateApi(api); err != nil { + if err := apiService.UpdateApi(api); err != nil { global.GVA_LOG.Error("修改失败!", zap.Any("err", err)) response.FailWithMessage("修改失败", c) } else { @@ -140,12 +144,12 @@ func UpdateApi(c *gin.Context) { // @Produce application/json // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}" // @Router /api/getAllApis [post] -func GetAllApis(c *gin.Context) { - if err, apis := service.GetAllApis(); err != nil { +func (s *SystemApiApi) GetAllApis(c *gin.Context) { + if err, apis := apiService.GetAllApis(); err != nil { global.GVA_LOG.Error("获取失败!", zap.Any("err", err)) response.FailWithMessage("获取失败", c) } else { - response.OkWithDetailed(response.SysAPIListResponse{Apis: apis}, "获取成功", c) + response.OkWithDetailed(systemRes.SysAPIListResponse{Apis: apis}, "获取成功", c) } } @@ -157,10 +161,10 @@ func GetAllApis(c *gin.Context) { // @Param data body request.IdsReq true "ID" // @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}" // @Router /api/deleteApisByIds [delete] -func DeleteApisByIds(c *gin.Context) { +func (s *SystemApiApi) DeleteApisByIds(c *gin.Context) { var ids request.IdsReq _ = c.ShouldBindJSON(&ids) - if err := service.DeleteApisByIds(ids); err != nil { + if err := apiService.DeleteApisByIds(ids); err != nil { global.GVA_LOG.Error("删除失败!", zap.Any("err", err)) response.FailWithMessage("删除失败", c) } else { diff --git a/server/api/v1/sys_authority.go b/server/api/v1/system/sys_authority.go similarity index 72% rename from server/api/v1/sys_authority.go rename to server/api/v1/system/sys_authority.go index 9324806d2a78c308b2c710c207a17e8a00c4aff7..d1643c83e44cf618a6768e89a2978d6cfa3326fb 100644 --- a/server/api/v1/sys_authority.go +++ b/server/api/v1/system/sys_authority.go @@ -1,38 +1,43 @@ -package v1 +package system import ( "gin-vue-admin/global" + "gin-vue-admin/model/common/request" + "gin-vue-admin/model/common/response" "gin-vue-admin/model/system" - "gin-vue-admin/model/system/request" - "gin-vue-admin/model/system/response" - "gin-vue-admin/service" + systemReq "gin-vue-admin/model/system/request" + systemRes "gin-vue-admin/model/system/response" "gin-vue-admin/utils" "github.com/gin-gonic/gin" "go.uber.org/zap" ) +type AuthorityApi struct { +} + // @Tags Authority // @Summary 创建角色 // @Security ApiKeyAuth // @accept application/json // @Produce application/json -// @Param data body model.SysAuthority true "权限id, 权限名, 父角色id" +// @Param data body system.SysAuthority true "权限id, 权限名, 父角色id" // @Success 200 {string} string "{"success":true,"data":{},"msg":"创建成功"}" // @Router /authority/createAuthority [post] -func CreateAuthority(c *gin.Context) { +func (a *AuthorityApi) CreateAuthority(c *gin.Context) { var authority system.SysAuthority _ = c.ShouldBindJSON(&authority) if err := utils.Verify(authority, utils.AuthorityVerify); err != nil { response.FailWithMessage(err.Error(), c) return } - if err, authBack := service.CreateAuthority(authority); err != nil { + if err, authBack := authorityService.CreateAuthority(authority); err != nil { global.GVA_LOG.Error("创建失败!", zap.Any("err", err)) response.FailWithMessage("创建失败"+err.Error(), c) } else { - _ = service.UpdateCasbin(authority.AuthorityId, request.DefaultCasbin()) - response.OkWithDetailed(response.SysAuthorityResponse{Authority: authBack}, "创建成功", c) + _ = menuService.AddMenuAuthority(systemReq.DefaultMenu(), authority.AuthorityId) + _ = casbinService.UpdateCasbin(authority.AuthorityId, systemReq.DefaultCasbin()) + response.OkWithDetailed(systemRes.SysAuthorityResponse{Authority: authBack}, "创建成功", c) } } @@ -44,8 +49,8 @@ func CreateAuthority(c *gin.Context) { // @Param data body response.SysAuthorityCopyResponse true "旧角色id, 新权限id, 新权限名, 新父角色id" // @Success 200 {string} string "{"success":true,"data":{},"msg":"拷贝成功"}" // @Router /authority/copyAuthority [post] -func CopyAuthority(c *gin.Context) { - var copyInfo response.SysAuthorityCopyResponse +func (a *AuthorityApi) CopyAuthority(c *gin.Context) { + var copyInfo systemRes.SysAuthorityCopyResponse _ = c.ShouldBindJSON(©Info) if err := utils.Verify(copyInfo, utils.OldAuthorityVerify); err != nil { response.FailWithMessage(err.Error(), c) @@ -55,11 +60,11 @@ func CopyAuthority(c *gin.Context) { response.FailWithMessage(err.Error(), c) return } - if err, authBack := service.CopyAuthority(copyInfo); err != nil { + if err, authBack := authorityService.CopyAuthority(copyInfo); err != nil { global.GVA_LOG.Error("拷贝失败!", zap.Any("err", err)) response.FailWithMessage("拷贝失败"+err.Error(), c) } else { - response.OkWithDetailed(response.SysAuthorityResponse{Authority: authBack}, "拷贝成功", c) + response.OkWithDetailed(systemRes.SysAuthorityResponse{Authority: authBack}, "拷贝成功", c) } } @@ -71,14 +76,14 @@ func CopyAuthority(c *gin.Context) { // @Param data body model.SysAuthority true "删除角色" // @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}" // @Router /authority/deleteAuthority [post] -func DeleteAuthority(c *gin.Context) { +func (a *AuthorityApi) DeleteAuthority(c *gin.Context) { var authority system.SysAuthority _ = c.ShouldBindJSON(&authority) if err := utils.Verify(authority, utils.AuthorityIdVerify); err != nil { response.FailWithMessage(err.Error(), c) return } - if err := service.DeleteAuthority(&authority); err != nil { // 删除角色之前需要判断是否有用户正在使用此角色 + if err := authorityService.DeleteAuthority(&authority); err != nil { // 删除角色之前需要判断是否有用户正在使用此角色 global.GVA_LOG.Error("删除失败!", zap.Any("err", err)) response.FailWithMessage("删除失败"+err.Error(), c) } else { @@ -94,18 +99,18 @@ func DeleteAuthority(c *gin.Context) { // @Param data body model.SysAuthority true "权限id, 权限名, 父角色id" // @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}" // @Router /authority/updateAuthority [post] -func UpdateAuthority(c *gin.Context) { +func (a *AuthorityApi) UpdateAuthority(c *gin.Context) { var auth system.SysAuthority _ = c.ShouldBindJSON(&auth) if err := utils.Verify(auth, utils.AuthorityVerify); err != nil { response.FailWithMessage(err.Error(), c) return } - if err, authority := service.UpdateAuthority(auth); err != nil { + if err, authority := authorityService.UpdateAuthority(auth); err != nil { global.GVA_LOG.Error("更新失败!", zap.Any("err", err)) response.FailWithMessage("更新失败"+err.Error(), c) } else { - response.OkWithDetailed(response.SysAuthorityResponse{Authority: authority}, "更新成功", c) + response.OkWithDetailed(systemRes.SysAuthorityResponse{Authority: authority}, "更新成功", c) } } @@ -117,14 +122,14 @@ func UpdateAuthority(c *gin.Context) { // @Param data body request.PageInfo true "页码, 每页大小" // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}" // @Router /authority/getAuthorityList [post] -func GetAuthorityList(c *gin.Context) { +func (a *AuthorityApi) GetAuthorityList(c *gin.Context) { var pageInfo request.PageInfo _ = c.ShouldBindJSON(&pageInfo) if err := utils.Verify(pageInfo, utils.PageInfoVerify); err != nil { response.FailWithMessage(err.Error(), c) return } - if err, list, total := service.GetAuthorityInfoList(pageInfo); err != nil { + if err, list, total := authorityService.GetAuthorityInfoList(pageInfo); err != nil { global.GVA_LOG.Error("获取失败!", zap.Any("err", err)) response.FailWithMessage("获取失败"+err.Error(), c) } else { @@ -145,14 +150,14 @@ func GetAuthorityList(c *gin.Context) { // @Param data body model.SysAuthority true "设置角色资源权限" // @Success 200 {string} string "{"success":true,"data":{},"msg":"设置成功"}" // @Router /authority/setDataAuthority [post] -func SetDataAuthority(c *gin.Context) { +func (a *AuthorityApi) SetDataAuthority(c *gin.Context) { var auth system.SysAuthority _ = c.ShouldBindJSON(&auth) if err := utils.Verify(auth, utils.AuthorityIdVerify); err != nil { response.FailWithMessage(err.Error(), c) return } - if err := service.SetDataAuthority(auth); err != nil { + if err := authorityService.SetDataAuthority(auth); err != nil { global.GVA_LOG.Error("设置失败!", zap.Any("err", err)) response.FailWithMessage("设置失败"+err.Error(), c) } else { diff --git a/server/api/v1/sys_auto_code.go b/server/api/v1/system/sys_auto_code.go similarity index 77% rename from server/api/v1/sys_auto_code.go rename to server/api/v1/system/sys_auto_code.go index d833676fff19a9cbee18cdc5f04ef4c6e4ef7871..f4c93e373a2333ed732266ed3a478d6e76aad62f 100644 --- a/server/api/v1/sys_auto_code.go +++ b/server/api/v1/system/sys_auto_code.go @@ -1,13 +1,12 @@ -package v1 +package system import ( "errors" "fmt" "gin-vue-admin/global" + "gin-vue-admin/model/common/response" "gin-vue-admin/model/system" - "gin-vue-admin/model/system/request" - "gin-vue-admin/model/system/response" - "gin-vue-admin/service" + systemReq "gin-vue-admin/model/system/request" "gin-vue-admin/utils" "net/url" "os" @@ -16,18 +15,21 @@ import ( "go.uber.org/zap" ) +type AutoCodeApi struct { +} + // @Tags AutoCode // @Summary 删除回滚记录 // @Security ApiKeyAuth // @accept application/json // @Produce application/json -// @Param data body request.AutoHistoryByID true "删除回滚记录" +// @Param data body systemReq.AutoHistoryByID true "删除回滚记录" // @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}" // @Router /autoCode/delSysHistory [post] -func DelSysHistory(c *gin.Context) { - var id request.AutoHistoryByID +func (autoApi *AutoCodeApi) DelSysHistory(c *gin.Context) { + var id systemReq.AutoHistoryByID _ = c.ShouldBindJSON(&id) - err := service.DeletePage(id.ID) + err := autoCodeHistoryService.DeletePage(id.ID) if err != nil { global.GVA_LOG.Error("获取失败!", zap.Any("err", err)) response.FailWithMessage("获取失败", c) @@ -41,13 +43,13 @@ func DelSysHistory(c *gin.Context) { // @Security ApiKeyAuth // @accept application/json // @Produce application/json -// @Param data body request.SysAutoHistory true "查询回滚记录" +// @Param data body systemReq.SysAutoHistory true "查询回滚记录" // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}" // @Router /autoCode/getSysHistory [post] -func GetSysHistory(c *gin.Context) { - var search request.SysAutoHistory +func (autoApi *AutoCodeApi) GetSysHistory(c *gin.Context) { + var search systemReq.SysAutoHistory _ = c.ShouldBindJSON(&search) - err, list, total := service.GetSysHistoryPage(search.PageInfo) + err, list, total := autoCodeHistoryService.GetSysHistoryPage(search.PageInfo) if err != nil { global.GVA_LOG.Error("获取失败!", zap.Any("err", err)) response.FailWithMessage("获取失败", c) @@ -66,13 +68,13 @@ func GetSysHistory(c *gin.Context) { // @Security ApiKeyAuth // @accept application/json // @Produce application/json -// @Param data body request.AutoHistoryByID true "回滚自动生成代码" +// @Param data body systemReq.AutoHistoryByID true "回滚自动生成代码" // @Success 200 {string} string "{"success":true,"data":{},"msg":"回滚成功"}" // @Router /autoCode/rollback [post] -func RollBack(c *gin.Context) { - var id request.AutoHistoryByID +func (autoApi *AutoCodeApi) RollBack(c *gin.Context) { + var id systemReq.AutoHistoryByID _ = c.ShouldBindJSON(&id) - if err := service.RollBack(id.ID); err != nil { + if err := autoCodeHistoryService.RollBack(id.ID); err != nil { response.FailWithMessage(err.Error(), c) return } @@ -84,13 +86,13 @@ func RollBack(c *gin.Context) { // @Security ApiKeyAuth // @accept application/json // @Produce application/json -// @Param data body request.AutoHistoryByID true "获取meta信息" +// @Param data body systemReq.AutoHistoryByID true "获取meta信息" // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}" // @Router /autoCode/getMeta [post] -func GetMeta(c *gin.Context) { - var id request.AutoHistoryByID +func (autoApi *AutoCodeApi) GetMeta(c *gin.Context) { + var id systemReq.AutoHistoryByID _ = c.ShouldBindJSON(&id) - if v, err := service.GetMeta(id.ID); err != nil { + if v, err := autoCodeHistoryService.GetMeta(id.ID); err != nil { response.FailWithMessage(err.Error(), c) return } else { @@ -107,14 +109,14 @@ func GetMeta(c *gin.Context) { // @Param data body model.AutoCodeStruct true "预览创建代码" // @Success 200 {string} string "{"success":true,"data":{},"msg":"创建成功"}" // @Router /autoCode/preview [post] -func PreviewTemp(c *gin.Context) { +func (autoApi *AutoCodeApi) PreviewTemp(c *gin.Context) { var a system.AutoCodeStruct _ = c.ShouldBindJSON(&a) if err := utils.Verify(a, utils.AutoCodeVerify); err != nil { response.FailWithMessage(err.Error(), c) return } - autoCode, err := service.PreviewTemp(a) + autoCode, err := autoCodeService.PreviewTemp(a) if err != nil { global.GVA_LOG.Error("预览失败!", zap.Any("err", err)) response.FailWithMessage("预览失败", c) @@ -131,7 +133,7 @@ func PreviewTemp(c *gin.Context) { // @Param data body model.AutoCodeStruct true "创建自动代码" // @Success 200 {string} string "{"success":true,"data":{},"msg":"创建成功"}" // @Router /autoCode/createTemp [post] -func CreateTemp(c *gin.Context) { +func (autoApi *AutoCodeApi) CreateTemp(c *gin.Context) { var a system.AutoCodeStruct _ = c.ShouldBindJSON(&a) if err := utils.Verify(a, utils.AutoCodeVerify); err != nil { @@ -140,7 +142,7 @@ func CreateTemp(c *gin.Context) { } var apiIds []uint if a.AutoCreateApiToSql { - if ids, err := service.AutoCreateApi(&a); err != nil { + if ids, err := autoCodeService.AutoCreateApi(&a); err != nil { global.GVA_LOG.Error("自动化创建失败!请自行清空垃圾数据!", zap.Any("err", err)) c.Writer.Header().Add("success", "false") c.Writer.Header().Add("msg", url.QueryEscape("自动化创建失败!请自行清空垃圾数据!")) @@ -149,7 +151,7 @@ func CreateTemp(c *gin.Context) { apiIds = ids } } - err := service.CreateTemp(a, apiIds...) + err := autoCodeService.CreateTemp(a, apiIds...) if err != nil { if errors.Is(err, system.AutoMoveErr) { c.Writer.Header().Add("success", "false") @@ -176,9 +178,9 @@ func CreateTemp(c *gin.Context) { // @Produce application/json // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}" // @Router /autoCode/getTables [get] -func GetTables(c *gin.Context) { +func (autoApi *AutoCodeApi) GetTables(c *gin.Context) { dbName := c.DefaultQuery("dbName", global.GVA_CONFIG.Mysql.Dbname) - err, tables := service.GetTables(dbName) + err, tables := autoCodeService.GetTables(dbName) if err != nil { global.GVA_LOG.Error("查询table失败!", zap.Any("err", err)) response.FailWithMessage("查询table失败", c) @@ -194,8 +196,8 @@ func GetTables(c *gin.Context) { // @Produce application/json // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}" // @Router /autoCode/getDatabase [get] -func GetDB(c *gin.Context) { - if err, dbs := service.GetDB(); err != nil { +func (autoApi *AutoCodeApi) GetDB(c *gin.Context) { + if err, dbs := autoCodeService.GetDB(); err != nil { global.GVA_LOG.Error("获取失败!", zap.Any("err", err)) response.FailWithMessage("获取失败", c) } else { @@ -210,10 +212,10 @@ func GetDB(c *gin.Context) { // @Produce application/json // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}" // @Router /autoCode/getColumn [get] -func GetColumn(c *gin.Context) { +func (autoApi *AutoCodeApi) GetColumn(c *gin.Context) { dbName := c.DefaultQuery("dbName", global.GVA_CONFIG.Mysql.Dbname) tableName := c.Query("tableName") - if err, columns := service.GetColumn(tableName, dbName); err != nil { + if err, columns := autoCodeService.GetColumn(tableName, dbName); err != nil { global.GVA_LOG.Error("获取失败!", zap.Any("err", err)) response.FailWithMessage("获取失败", c) } else { diff --git a/server/api/v1/sys_captcha.go b/server/api/v1/system/sys_captcha.go similarity index 80% rename from server/api/v1/sys_captcha.go rename to server/api/v1/system/sys_captcha.go index 319461e049e393cfb9855aa3cb8943d6a4542774..dabd9b551fa30afb887006c0f2b3a6e56cce1e4c 100644 --- a/server/api/v1/sys_captcha.go +++ b/server/api/v1/system/sys_captcha.go @@ -1,8 +1,9 @@ -package v1 +package system import ( "gin-vue-admin/global" - "gin-vue-admin/model/system/response" + "gin-vue-admin/model/common/response" + systemRes "gin-vue-admin/model/system/response" "github.com/gin-gonic/gin" "github.com/mojocn/base64Captcha" "go.uber.org/zap" @@ -10,6 +11,9 @@ import ( var store = base64Captcha.DefaultMemStore +type BaseApi struct { +} + // @Tags Base // @Summary 生成验证码 // @Security ApiKeyAuth @@ -17,7 +21,7 @@ var store = base64Captcha.DefaultMemStore // @Produce application/json // @Success 200 {string} string "{"success":true,"data":{},"msg":"验证码获取成功"}" // @Router /base/captcha [post] -func Captcha(c *gin.Context) { +func (b *BaseApi) Captcha(c *gin.Context) { // 字符,公式,验证码配置 // 生成默认数字的driver driver := base64Captcha.NewDriverDigit(global.GVA_CONFIG.Captcha.ImgHeight, global.GVA_CONFIG.Captcha.ImgWidth, global.GVA_CONFIG.Captcha.KeyLong, 0.7, 80) @@ -26,7 +30,7 @@ func Captcha(c *gin.Context) { global.GVA_LOG.Error("验证码获取失败!", zap.Any("err", err)) response.FailWithMessage("验证码获取失败", c) } else { - response.OkWithDetailed(response.SysCaptchaResponse{ + response.OkWithDetailed(systemRes.SysCaptchaResponse{ CaptchaId: id, PicPath: b64s, }, "验证码获取成功", c) diff --git a/server/api/v1/sys_casbin.go b/server/api/v1/system/sys_casbin.go similarity index 73% rename from server/api/v1/sys_casbin.go rename to server/api/v1/system/sys_casbin.go index eacbef9660ef4bd0d7b4805b80a9c4b82c69757a..0b3ced481476fbb2911d77940a683dcd78567438 100644 --- a/server/api/v1/sys_casbin.go +++ b/server/api/v1/system/sys_casbin.go @@ -1,15 +1,18 @@ -package v1 +package system import ( "gin-vue-admin/global" + "gin-vue-admin/model/common/response" "gin-vue-admin/model/system/request" - "gin-vue-admin/model/system/response" - "gin-vue-admin/service" + systemRes "gin-vue-admin/model/system/response" "gin-vue-admin/utils" "github.com/gin-gonic/gin" "go.uber.org/zap" ) +type CasbinApi struct { +} + // @Tags Casbin // @Summary 更新角色api权限 // @Security ApiKeyAuth @@ -18,14 +21,14 @@ import ( // @Param data body request.CasbinInReceive true "权限id, 权限模型列表" // @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}" // @Router /casbin/UpdateCasbin [post] -func UpdateCasbin(c *gin.Context) { +func (cas *CasbinApi) UpdateCasbin(c *gin.Context) { var cmr request.CasbinInReceive _ = c.ShouldBindJSON(&cmr) if err := utils.Verify(cmr, utils.AuthorityIdVerify); err != nil { response.FailWithMessage(err.Error(), c) return } - if err := service.UpdateCasbin(cmr.AuthorityId, cmr.CasbinInfos); err != nil { + if err := casbinService.UpdateCasbin(cmr.AuthorityId, cmr.CasbinInfos); err != nil { global.GVA_LOG.Error("更新失败!", zap.Any("err", err)) response.FailWithMessage("更新失败", c) } else { @@ -41,13 +44,13 @@ func UpdateCasbin(c *gin.Context) { // @Param data body request.CasbinInReceive true "权限id, 权限模型列表" // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}" // @Router /casbin/getPolicyPathByAuthorityId [post] -func GetPolicyPathByAuthorityId(c *gin.Context) { +func (cas *CasbinApi) GetPolicyPathByAuthorityId(c *gin.Context) { var casbin request.CasbinInReceive _ = c.ShouldBindJSON(&casbin) if err := utils.Verify(casbin, utils.AuthorityIdVerify); err != nil { response.FailWithMessage(err.Error(), c) return } - paths := service.GetPolicyPathByAuthorityId(casbin.AuthorityId) - response.OkWithDetailed(response.PolicyPathResponse{Paths: paths}, "获取成功", c) + paths := casbinService.GetPolicyPathByAuthorityId(casbin.AuthorityId) + response.OkWithDetailed(systemRes.PolicyPathResponse{Paths: paths}, "获取成功", c) } diff --git a/server/api/v1/sys_dictionary.go b/server/api/v1/system/sys_dictionary.go similarity index 80% rename from server/api/v1/sys_dictionary.go rename to server/api/v1/system/sys_dictionary.go index 5a0d6033078bfdc8e34dcb24be69c07b566cb354..325fff94be6bad6e6424da3ff95b4442de801ae3 100644 --- a/server/api/v1/sys_dictionary.go +++ b/server/api/v1/system/sys_dictionary.go @@ -1,16 +1,18 @@ -package v1 +package system import ( "gin-vue-admin/global" + "gin-vue-admin/model/common/response" "gin-vue-admin/model/system" "gin-vue-admin/model/system/request" - "gin-vue-admin/model/system/response" - "gin-vue-admin/service" "gin-vue-admin/utils" "github.com/gin-gonic/gin" "go.uber.org/zap" ) +type DictionaryApi struct { +} + // @Tags SysDictionary // @Summary 创建SysDictionary // @Security ApiKeyAuth @@ -19,10 +21,10 @@ import ( // @Param data body model.SysDictionary true "SysDictionary模型" // @Success 200 {string} string "{"success":true,"data":{},"msg":"创建成功"}" // @Router /sysDictionary/createSysDictionary [post] -func CreateSysDictionary(c *gin.Context) { +func (s *DictionaryApi) CreateSysDictionary(c *gin.Context) { var dictionary system.SysDictionary _ = c.ShouldBindJSON(&dictionary) - if err := service.CreateSysDictionary(dictionary); err != nil { + if err := dictionaryService.CreateSysDictionary(dictionary); err != nil { global.GVA_LOG.Error("创建失败!", zap.Any("err", err)) response.FailWithMessage("创建失败", c) } else { @@ -38,10 +40,10 @@ func CreateSysDictionary(c *gin.Context) { // @Param data body model.SysDictionary true "SysDictionary模型" // @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}" // @Router /sysDictionary/deleteSysDictionary [delete] -func DeleteSysDictionary(c *gin.Context) { +func (s *DictionaryApi) DeleteSysDictionary(c *gin.Context) { var dictionary system.SysDictionary _ = c.ShouldBindJSON(&dictionary) - if err := service.DeleteSysDictionary(dictionary); err != nil { + if err := dictionaryService.DeleteSysDictionary(dictionary); err != nil { global.GVA_LOG.Error("删除失败!", zap.Any("err", err)) response.FailWithMessage("删除失败", c) } else { @@ -57,10 +59,10 @@ func DeleteSysDictionary(c *gin.Context) { // @Param data body model.SysDictionary true "SysDictionary模型" // @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}" // @Router /sysDictionary/updateSysDictionary [put] -func UpdateSysDictionary(c *gin.Context) { +func (s *DictionaryApi) UpdateSysDictionary(c *gin.Context) { var dictionary system.SysDictionary _ = c.ShouldBindJSON(&dictionary) - if err := service.UpdateSysDictionary(&dictionary); err != nil { + if err := dictionaryService.UpdateSysDictionary(&dictionary); err != nil { global.GVA_LOG.Error("更新失败!", zap.Any("err", err)) response.FailWithMessage("更新失败", c) } else { @@ -76,10 +78,10 @@ func UpdateSysDictionary(c *gin.Context) { // @Param data body model.SysDictionary true "ID或字典英名" // @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}" // @Router /sysDictionary/findSysDictionary [get] -func FindSysDictionary(c *gin.Context) { +func (s *DictionaryApi) FindSysDictionary(c *gin.Context) { var dictionary system.SysDictionary _ = c.ShouldBindQuery(&dictionary) - if err, sysDictionary := service.GetSysDictionary(dictionary.Type, dictionary.ID); err != nil { + if err, sysDictionary := dictionaryService.GetSysDictionary(dictionary.Type, dictionary.ID); err != nil { global.GVA_LOG.Error("查询失败!", zap.Any("err", err)) response.FailWithMessage("查询失败", c) } else { @@ -95,14 +97,14 @@ func FindSysDictionary(c *gin.Context) { // @Param data body request.SysDictionarySearch true "页码, 每页大小, 搜索条件" // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}" // @Router /sysDictionary/getSysDictionaryList [get] -func GetSysDictionaryList(c *gin.Context) { +func (s *DictionaryApi) GetSysDictionaryList(c *gin.Context) { var pageInfo request.SysDictionarySearch _ = c.ShouldBindQuery(&pageInfo) if err := utils.Verify(pageInfo.PageInfo, utils.PageInfoVerify); err != nil { response.FailWithMessage(err.Error(), c) return } - if err, list, total := service.GetSysDictionaryInfoList(pageInfo); err != nil { + if err, list, total := dictionaryService.GetSysDictionaryInfoList(pageInfo); err != nil { global.GVA_LOG.Error("获取失败!", zap.Any("err", err)) response.FailWithMessage("获取失败", c) } else { diff --git a/server/api/v1/sys_dictionary_detail.go b/server/api/v1/system/sys_dictionary_detail.go similarity index 79% rename from server/api/v1/sys_dictionary_detail.go rename to server/api/v1/system/sys_dictionary_detail.go index ff5c99d66b6ad5c3869ee51e83cb02a8481b3307..d141cc1bf03583a1a8758a5fe4084f43b10bfc88 100644 --- a/server/api/v1/sys_dictionary_detail.go +++ b/server/api/v1/system/sys_dictionary_detail.go @@ -1,16 +1,18 @@ -package v1 +package system import ( "gin-vue-admin/global" + "gin-vue-admin/model/common/response" "gin-vue-admin/model/system" "gin-vue-admin/model/system/request" - "gin-vue-admin/model/system/response" - "gin-vue-admin/service" "gin-vue-admin/utils" "github.com/gin-gonic/gin" "go.uber.org/zap" ) +type DictionaryDetailApi struct { +} + // @Tags SysDictionaryDetail // @Summary 创建SysDictionaryDetail // @Security ApiKeyAuth @@ -19,10 +21,10 @@ import ( // @Param data body model.SysDictionaryDetail true "SysDictionaryDetail模型" // @Success 200 {string} string "{"success":true,"data":{},"msg":"创建成功"}" // @Router /sysDictionaryDetail/createSysDictionaryDetail [post] -func CreateSysDictionaryDetail(c *gin.Context) { +func (s *DictionaryDetailApi) CreateSysDictionaryDetail(c *gin.Context) { var detail system.SysDictionaryDetail _ = c.ShouldBindJSON(&detail) - if err := service.CreateSysDictionaryDetail(detail); err != nil { + if err := dictionaryDetailService.CreateSysDictionaryDetail(detail); err != nil { global.GVA_LOG.Error("创建失败!", zap.Any("err", err)) response.FailWithMessage("创建失败", c) } else { @@ -38,10 +40,10 @@ func CreateSysDictionaryDetail(c *gin.Context) { // @Param data body model.SysDictionaryDetail true "SysDictionaryDetail模型" // @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}" // @Router /sysDictionaryDetail/deleteSysDictionaryDetail [delete] -func DeleteSysDictionaryDetail(c *gin.Context) { +func (s *DictionaryDetailApi) DeleteSysDictionaryDetail(c *gin.Context) { var detail system.SysDictionaryDetail _ = c.ShouldBindJSON(&detail) - if err := service.DeleteSysDictionaryDetail(detail); err != nil { + if err := dictionaryDetailService.DeleteSysDictionaryDetail(detail); err != nil { global.GVA_LOG.Error("删除失败!", zap.Any("err", err)) response.FailWithMessage("删除失败", c) } else { @@ -57,10 +59,10 @@ func DeleteSysDictionaryDetail(c *gin.Context) { // @Param data body model.SysDictionaryDetail true "更新SysDictionaryDetail" // @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}" // @Router /sysDictionaryDetail/updateSysDictionaryDetail [put] -func UpdateSysDictionaryDetail(c *gin.Context) { +func (s *DictionaryDetailApi) UpdateSysDictionaryDetail(c *gin.Context) { var detail system.SysDictionaryDetail _ = c.ShouldBindJSON(&detail) - if err := service.UpdateSysDictionaryDetail(&detail); err != nil { + if err := dictionaryDetailService.UpdateSysDictionaryDetail(&detail); err != nil { global.GVA_LOG.Error("更新失败!", zap.Any("err", err)) response.FailWithMessage("更新失败", c) } else { @@ -76,14 +78,14 @@ func UpdateSysDictionaryDetail(c *gin.Context) { // @Param data body model.SysDictionaryDetail true "用id查询SysDictionaryDetail" // @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}" // @Router /sysDictionaryDetail/findSysDictionaryDetail [get] -func FindSysDictionaryDetail(c *gin.Context) { +func (s *DictionaryDetailApi) FindSysDictionaryDetail(c *gin.Context) { var detail system.SysDictionaryDetail _ = c.ShouldBindQuery(&detail) if err := utils.Verify(detail, utils.IdVerify); err != nil { response.FailWithMessage(err.Error(), c) return } - if err, resysDictionaryDetail := service.GetSysDictionaryDetail(detail.ID); err != nil { + if err, resysDictionaryDetail := dictionaryDetailService.GetSysDictionaryDetail(detail.ID); err != nil { global.GVA_LOG.Error("查询失败!", zap.Any("err", err)) response.FailWithMessage("查询失败", c) } else { @@ -99,10 +101,10 @@ func FindSysDictionaryDetail(c *gin.Context) { // @Param data body request.SysDictionaryDetailSearch true "页码, 每页大小, 搜索条件" // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}" // @Router /sysDictionaryDetail/getSysDictionaryDetailList [get] -func GetSysDictionaryDetailList(c *gin.Context) { +func (s *DictionaryDetailApi) GetSysDictionaryDetailList(c *gin.Context) { var pageInfo request.SysDictionaryDetailSearch _ = c.ShouldBindQuery(&pageInfo) - if err, list, total := service.GetSysDictionaryDetailInfoList(pageInfo); err != nil { + if err, list, total := dictionaryDetailService.GetSysDictionaryDetailInfoList(pageInfo); err != nil { global.GVA_LOG.Error("获取失败!", zap.Any("err", err)) response.FailWithMessage("获取失败", c) } else { diff --git a/server/api/v1/sys_email.go b/server/api/v1/system/sys_email.go similarity index 75% rename from server/api/v1/sys_email.go rename to server/api/v1/system/sys_email.go index 2f594843ed58a0e5e824597203fa234b2a55e59a..39b305ca217fee1cab8ddf79df709956dbb99eaf 100644 --- a/server/api/v1/sys_email.go +++ b/server/api/v1/system/sys_email.go @@ -1,9 +1,8 @@ -package v1 +package system import ( "gin-vue-admin/global" - "gin-vue-admin/model/response" - "gin-vue-admin/service" + "gin-vue-admin/model/common/response" "github.com/gin-gonic/gin" "go.uber.org/zap" ) @@ -14,8 +13,8 @@ import ( // @Produce application/json // @Success 200 {string} string "{"success":true,"data":{},"msg":"发送成功"}" // @Router /email/emailTest [post] -func EmailTest(c *gin.Context) { - if err := service.EmailTest(); err != nil { +func (s *SystemApi) EmailTest(c *gin.Context) { + if err := emailService.EmailTest(); err != nil { global.GVA_LOG.Error("发送失败!", zap.Any("err", err)) response.FailWithMessage("发送失败", c) } else { diff --git a/server/api/v1/sys_initdb.go b/server/api/v1/system/sys_initdb.go similarity index 87% rename from server/api/v1/sys_initdb.go rename to server/api/v1/system/sys_initdb.go index 737c8b73c0594faaa45b0da4789da497e3ebe1b4..00ee98e5f00b8db09b31c205b7003aaca27aeceb 100644 --- a/server/api/v1/sys_initdb.go +++ b/server/api/v1/system/sys_initdb.go @@ -1,23 +1,24 @@ -package v1 +package system import ( "gin-vue-admin/global" + "gin-vue-admin/model/common/response" "gin-vue-admin/model/system/request" - "gin-vue-admin/model/system/response" - "gin-vue-admin/service" - "go.uber.org/zap" "github.com/gin-gonic/gin" ) +type DBApi struct { +} + // @Tags InitDB // @Summary 初始化用户数据库 // @Produce application/json // @Param data body request.InitDB true "初始化数据库参数" // @Success 200 {string} string "{"code":0,"data":{},"msg":"自动创建数据库成功"}" // @Router /init/initdb [post] -func InitDB(c *gin.Context) { +func (i *DBApi) InitDB(c *gin.Context) { if global.GVA_DB != nil { global.GVA_LOG.Error("已存在数据库配置!") response.FailWithMessage("已存在数据库配置", c) @@ -29,7 +30,7 @@ func InitDB(c *gin.Context) { response.FailWithMessage("参数校验不通过", c) return } - if err := service.InitDB(dbInfo); err != nil { + if err := initDBService.InitDB(dbInfo); err != nil { global.GVA_LOG.Error("自动创建数据库失败!", zap.Any("err", err)) response.FailWithMessage("自动创建数据库失败,请查看后台日志,检查后在进行初始化", c) return @@ -42,7 +43,7 @@ func InitDB(c *gin.Context) { // @Produce application/json // @Success 200 {string} string "{"code":0,"data":{},"msg":"探测完成"}" // @Router /init/checkdb [post] -func CheckDB(c *gin.Context) { +func (i *DBApi) CheckDB(c *gin.Context) { if global.GVA_DB != nil { global.GVA_LOG.Info("数据库无需初始化") response.OkWithDetailed(gin.H{"needInit": false}, "数据库无需初始化", c) diff --git a/server/api/v1/sys_jwt_blacklist.go b/server/api/v1/system/sys_jwt_blacklist.go similarity index 76% rename from server/api/v1/sys_jwt_blacklist.go rename to server/api/v1/system/sys_jwt_blacklist.go index dd00d83f2aa80f40f4dc5edbec217eb54d38ed7e..76bedf8a065cd9df69fb7375db368d36402f245f 100644 --- a/server/api/v1/sys_jwt_blacklist.go +++ b/server/api/v1/system/sys_jwt_blacklist.go @@ -1,14 +1,16 @@ -package v1 +package system import ( "gin-vue-admin/global" - "gin-vue-admin/model/response" + "gin-vue-admin/model/common/response" "gin-vue-admin/model/system" - "gin-vue-admin/service" "github.com/gin-gonic/gin" "go.uber.org/zap" ) +type JwtApi struct { +} + // @Tags Jwt // @Summary jwt加入黑名单 // @Security ApiKeyAuth @@ -16,10 +18,10 @@ import ( // @Produce application/json // @Success 200 {string} string "{"success":true,"data":{},"msg":"拉黑成功"}" // @Router /jwt/jsonInBlacklist [post] -func JsonInBlacklist(c *gin.Context) { +func (j *JwtApi) JsonInBlacklist(c *gin.Context) { token := c.Request.Header.Get("x-token") jwt := system.JwtBlacklist{Jwt: token} - if err := service.JsonInBlacklist(jwt); err != nil { + if err := jwtService.JsonInBlacklist(jwt); err != nil { global.GVA_LOG.Error("jwt作废失败!", zap.Any("err", err)) response.FailWithMessage("jwt作废失败", c) } else { diff --git a/server/api/v1/sys_menu.go b/server/api/v1/system/sys_menu.go similarity index 76% rename from server/api/v1/sys_menu.go rename to server/api/v1/system/sys_menu.go index c15f47678d922443cdb6dc9923c7857af38bcbdf..37f2291c5f44e56b8201dbfc4ec6cae5fa8df5cf 100644 --- a/server/api/v1/sys_menu.go +++ b/server/api/v1/system/sys_menu.go @@ -1,17 +1,21 @@ -package v1 +package system import ( "gin-vue-admin/global" + "gin-vue-admin/model/common/request" + "gin-vue-admin/model/common/response" "gin-vue-admin/model/system" - "gin-vue-admin/model/system/request" - "gin-vue-admin/model/system/response" - "gin-vue-admin/service" + systemReq "gin-vue-admin/model/system/request" + systemRes "gin-vue-admin/model/system/response" "gin-vue-admin/utils" "github.com/gin-gonic/gin" "go.uber.org/zap" ) +type AuthorityMenuApi struct { +} + // @Tags AuthorityMenu // @Summary 获取用户动态路由 // @Security ApiKeyAuth @@ -19,15 +23,15 @@ import ( // @Param data body request.Empty true "空" // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}" // @Router /menu/getMenu [post] -func GetMenu(c *gin.Context) { - if err, menus := service.GetMenuTree(getUserAuthorityId(c)); err != nil { +func (a *AuthorityMenuApi) GetMenu(c *gin.Context) { + if err, menus := menuService.GetMenuTree(utils.GetUserAuthorityId(c)); err != nil { global.GVA_LOG.Error("获取失败!", zap.Any("err", err)) response.FailWithMessage("获取失败", c) } else { if menus == nil { menus = []system.SysMenu{} } - response.OkWithDetailed(response.SysMenusResponse{Menus: menus}, "获取成功", c) + response.OkWithDetailed(systemRes.SysMenusResponse{Menus: menus}, "获取成功", c) } } @@ -38,12 +42,12 @@ func GetMenu(c *gin.Context) { // @Param data body request.Empty true "空" // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}" // @Router /menu/getBaseMenuTree [post] -func GetBaseMenuTree(c *gin.Context) { - if err, menus := service.GetBaseMenuTree(); err != nil { +func (a *AuthorityMenuApi) GetBaseMenuTree(c *gin.Context) { + if err, menus := menuService.GetBaseMenuTree(); err != nil { global.GVA_LOG.Error("获取失败!", zap.Any("err", err)) response.FailWithMessage("获取失败", c) } else { - response.OkWithDetailed(response.SysBaseMenusResponse{Menus: menus}, "获取成功", c) + response.OkWithDetailed(systemRes.SysBaseMenusResponse{Menus: menus}, "获取成功", c) } } @@ -52,17 +56,17 @@ func GetBaseMenuTree(c *gin.Context) { // @Security ApiKeyAuth // @accept application/json // @Produce application/json -// @Param data body request.AddMenuAuthorityInfo true "角色ID" +// @Param data body systemReq.AddMenuAuthorityInfo true "角色ID" // @Success 200 {string} string "{"success":true,"data":{},"msg":"添加成功"}" // @Router /menu/addMenuAuthority [post] -func AddMenuAuthority(c *gin.Context) { - var authorityMenu request.AddMenuAuthorityInfo +func (a *AuthorityMenuApi) AddMenuAuthority(c *gin.Context) { + var authorityMenu systemReq.AddMenuAuthorityInfo _ = c.ShouldBindJSON(&authorityMenu) if err := utils.Verify(authorityMenu, utils.AuthorityIdVerify); err != nil { response.FailWithMessage(err.Error(), c) return } - if err := service.AddMenuAuthority(authorityMenu.Menus, authorityMenu.AuthorityId); err != nil { + if err := menuService.AddMenuAuthority(authorityMenu.Menus, authorityMenu.AuthorityId); err != nil { global.GVA_LOG.Error("添加失败!", zap.Any("err", err)) response.FailWithMessage("添加失败", c) } else { @@ -78,16 +82,16 @@ func AddMenuAuthority(c *gin.Context) { // @Param data body request.GetAuthorityId true "角色ID" // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}" // @Router /menu/GetMenuAuthority [post] -func GetMenuAuthority(c *gin.Context) { +func (a *AuthorityMenuApi) GetMenuAuthority(c *gin.Context) { var param request.GetAuthorityId _ = c.ShouldBindJSON(¶m) if err := utils.Verify(param, utils.AuthorityIdVerify); err != nil { response.FailWithMessage(err.Error(), c) return } - if err, menus := service.GetMenuAuthority(¶m); err != nil { + if err, menus := menuService.GetMenuAuthority(¶m); err != nil { global.GVA_LOG.Error("获取失败!", zap.Any("err", err)) - response.FailWithDetailed(response.SysMenusResponse{Menus: menus}, "获取失败", c) + response.FailWithDetailed(systemRes.SysMenusResponse{Menus: menus}, "获取失败", c) } else { response.OkWithDetailed(gin.H{"menus": menus}, "获取成功", c) } @@ -101,7 +105,7 @@ func GetMenuAuthority(c *gin.Context) { // @Param data body model.SysBaseMenu true "路由path, 父菜单ID, 路由name, 对应前端文件路径, 排序标记" // @Success 200 {string} string "{"success":true,"data":{},"msg":"添加成功"}" // @Router /menu/addBaseMenu [post] -func AddBaseMenu(c *gin.Context) { +func (a *AuthorityMenuApi) AddBaseMenu(c *gin.Context) { var menu system.SysBaseMenu _ = c.ShouldBindJSON(&menu) if err := utils.Verify(menu, utils.MenuVerify); err != nil { @@ -112,7 +116,7 @@ func AddBaseMenu(c *gin.Context) { response.FailWithMessage(err.Error(), c) return } - if err := service.AddBaseMenu(menu); err != nil { + if err := menuService.AddBaseMenu(menu); err != nil { global.GVA_LOG.Error("添加失败!", zap.Any("err", err)) response.FailWithMessage("添加失败", c) @@ -129,14 +133,14 @@ func AddBaseMenu(c *gin.Context) { // @Param data body request.GetById true "菜单id" // @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}" // @Router /menu/deleteBaseMenu [post] -func DeleteBaseMenu(c *gin.Context) { +func (a *AuthorityMenuApi) DeleteBaseMenu(c *gin.Context) { var menu request.GetById _ = c.ShouldBindJSON(&menu) if err := utils.Verify(menu, utils.IdVerify); err != nil { response.FailWithMessage(err.Error(), c) return } - if err := service.DeleteBaseMenu(menu.ID); err != nil { + if err := baseMenuService.DeleteBaseMenu(menu.ID); err != nil { global.GVA_LOG.Error("删除失败!", zap.Any("err", err)) response.FailWithMessage("删除失败", c) } else { @@ -152,7 +156,7 @@ func DeleteBaseMenu(c *gin.Context) { // @Param data body model.SysBaseMenu true "路由path, 父菜单ID, 路由name, 对应前端文件路径, 排序标记" // @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}" // @Router /menu/updateBaseMenu [post] -func UpdateBaseMenu(c *gin.Context) { +func (a *AuthorityMenuApi) UpdateBaseMenu(c *gin.Context) { var menu system.SysBaseMenu _ = c.ShouldBindJSON(&menu) if err := utils.Verify(menu, utils.MenuVerify); err != nil { @@ -163,7 +167,7 @@ func UpdateBaseMenu(c *gin.Context) { response.FailWithMessage(err.Error(), c) return } - if err := service.UpdateBaseMenu(menu); err != nil { + if err := baseMenuService.UpdateBaseMenu(menu); err != nil { global.GVA_LOG.Error("更新失败!", zap.Any("err", err)) response.FailWithMessage("更新失败", c) } else { @@ -179,18 +183,18 @@ func UpdateBaseMenu(c *gin.Context) { // @Param data body request.GetById true "菜单id" // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}" // @Router /menu/getBaseMenuById [post] -func GetBaseMenuById(c *gin.Context) { +func (a *AuthorityMenuApi) GetBaseMenuById(c *gin.Context) { var idInfo request.GetById _ = c.ShouldBindJSON(&idInfo) if err := utils.Verify(idInfo, utils.IdVerify); err != nil { response.FailWithMessage(err.Error(), c) return } - if err, menu := service.GetBaseMenuById(idInfo.ID); err != nil { + if err, menu := baseMenuService.GetBaseMenuById(idInfo.ID); err != nil { global.GVA_LOG.Error("获取失败!", zap.Any("err", err)) response.FailWithMessage("获取失败", c) } else { - response.OkWithDetailed(response.SysBaseMenuResponse{Menu: menu}, "获取成功", c) + response.OkWithDetailed(systemRes.SysBaseMenuResponse{Menu: menu}, "获取成功", c) } } @@ -202,14 +206,14 @@ func GetBaseMenuById(c *gin.Context) { // @Param data body request.PageInfo true "页码, 每页大小" // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}" // @Router /menu/getMenuList [post] -func GetMenuList(c *gin.Context) { +func (a *AuthorityMenuApi) GetMenuList(c *gin.Context) { var pageInfo request.PageInfo _ = c.ShouldBindJSON(&pageInfo) if err := utils.Verify(pageInfo, utils.PageInfoVerify); err != nil { response.FailWithMessage(err.Error(), c) return } - if err, menuList, total := service.GetInfoList(); err != nil { + if err, menuList, total := menuService.GetInfoList(); err != nil { global.GVA_LOG.Error("获取失败!", zap.Any("err", err)) response.FailWithMessage("获取失败", c) } else { diff --git a/server/api/v1/sys_operation_record.go b/server/api/v1/system/sys_operation_record.go similarity index 76% rename from server/api/v1/sys_operation_record.go rename to server/api/v1/system/sys_operation_record.go index 1967fc24ca7c9989167ba5235ec96ad3b151052f..4a98ccfe2be3ee619cc6e8a812866f01dc214e54 100644 --- a/server/api/v1/sys_operation_record.go +++ b/server/api/v1/system/sys_operation_record.go @@ -1,16 +1,19 @@ -package v1 +package system import ( "gin-vue-admin/global" + "gin-vue-admin/model/common/request" + "gin-vue-admin/model/common/response" "gin-vue-admin/model/system" - "gin-vue-admin/model/system/request" - "gin-vue-admin/model/system/response" - "gin-vue-admin/service" + systemReq "gin-vue-admin/model/system/request" "gin-vue-admin/utils" "github.com/gin-gonic/gin" "go.uber.org/zap" ) +type OperationRecordApi struct { +} + // @Tags SysOperationRecord // @Summary 创建SysOperationRecord // @Security ApiKeyAuth @@ -19,10 +22,10 @@ import ( // @Param data body model.SysOperationRecord true "创建SysOperationRecord" // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}" // @Router /sysOperationRecord/createSysOperationRecord [post] -func CreateSysOperationRecord(c *gin.Context) { +func (s *OperationRecordApi) CreateSysOperationRecord(c *gin.Context) { var sysOperationRecord system.SysOperationRecord _ = c.ShouldBindJSON(&sysOperationRecord) - if err := service.CreateSysOperationRecord(sysOperationRecord); err != nil { + if err := operationRecordService.CreateSysOperationRecord(sysOperationRecord); err != nil { global.GVA_LOG.Error("创建失败!", zap.Any("err", err)) response.FailWithMessage("创建失败", c) } else { @@ -38,10 +41,10 @@ func CreateSysOperationRecord(c *gin.Context) { // @Param data body model.SysOperationRecord true "SysOperationRecord模型" // @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}" // @Router /sysOperationRecord/deleteSysOperationRecord [delete] -func DeleteSysOperationRecord(c *gin.Context) { +func (s *OperationRecordApi) DeleteSysOperationRecord(c *gin.Context) { var sysOperationRecord system.SysOperationRecord _ = c.ShouldBindJSON(&sysOperationRecord) - if err := service.DeleteSysOperationRecord(sysOperationRecord); err != nil { + if err := operationRecordService.DeleteSysOperationRecord(sysOperationRecord); err != nil { global.GVA_LOG.Error("删除失败!", zap.Any("err", err)) response.FailWithMessage("删除失败", c) } else { @@ -57,10 +60,10 @@ func DeleteSysOperationRecord(c *gin.Context) { // @Param data body request.IdsReq true "批量删除SysOperationRecord" // @Success 200 {string} string "{"success":true,"data":{},"msg":"批量删除成功"}" // @Router /sysOperationRecord/deleteSysOperationRecordByIds [delete] -func DeleteSysOperationRecordByIds(c *gin.Context) { +func (s *OperationRecordApi) DeleteSysOperationRecordByIds(c *gin.Context) { var IDS request.IdsReq _ = c.ShouldBindJSON(&IDS) - if err := service.DeleteSysOperationRecordByIds(IDS); err != nil { + if err := operationRecordService.DeleteSysOperationRecordByIds(IDS); err != nil { global.GVA_LOG.Error("批量删除失败!", zap.Any("err", err)) response.FailWithMessage("批量删除失败", c) } else { @@ -76,14 +79,14 @@ func DeleteSysOperationRecordByIds(c *gin.Context) { // @Param data body model.SysOperationRecord true "Id" // @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}" // @Router /sysOperationRecord/findSysOperationRecord [get] -func FindSysOperationRecord(c *gin.Context) { +func (s *OperationRecordApi) FindSysOperationRecord(c *gin.Context) { var sysOperationRecord system.SysOperationRecord _ = c.ShouldBindQuery(&sysOperationRecord) if err := utils.Verify(sysOperationRecord, utils.IdVerify); err != nil { response.FailWithMessage(err.Error(), c) return } - if err, resysOperationRecord := service.GetSysOperationRecord(sysOperationRecord.ID); err != nil { + if err, resysOperationRecord := operationRecordService.GetSysOperationRecord(sysOperationRecord.ID); err != nil { global.GVA_LOG.Error("查询失败!", zap.Any("err", err)) response.FailWithMessage("查询失败", c) } else { @@ -99,10 +102,10 @@ func FindSysOperationRecord(c *gin.Context) { // @Param data body request.SysOperationRecordSearch true "页码, 每页大小, 搜索条件" // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}" // @Router /sysOperationRecord/getSysOperationRecordList [get] -func GetSysOperationRecordList(c *gin.Context) { - var pageInfo request.SysOperationRecordSearch +func (s *OperationRecordApi) GetSysOperationRecordList(c *gin.Context) { + var pageInfo systemReq.SysOperationRecordSearch _ = c.ShouldBindQuery(&pageInfo) - if err, list, total := service.GetSysOperationRecordInfoList(pageInfo); err != nil { + if err, list, total := operationRecordService.GetSysOperationRecordInfoList(pageInfo); err != nil { global.GVA_LOG.Error("获取失败!", zap.Any("err", err)) response.FailWithMessage("获取失败", c) } else { diff --git a/server/api/v1/sys_system.go b/server/api/v1/system/sys_system.go similarity index 74% rename from server/api/v1/sys_system.go rename to server/api/v1/system/sys_system.go index f8b87e552f50c364b6fc880454168d5dc259bc25..2e51736865db9126be64d47877c9e2a3879db674 100644 --- a/server/api/v1/sys_system.go +++ b/server/api/v1/system/sys_system.go @@ -1,28 +1,31 @@ -package v1 +package system import ( "gin-vue-admin/global" + "gin-vue-admin/model/common/response" "gin-vue-admin/model/system" - "gin-vue-admin/model/system/response" - "gin-vue-admin/service" + systemRes "gin-vue-admin/model/system/response" "gin-vue-admin/utils" "github.com/gin-gonic/gin" "go.uber.org/zap" ) +type SystemApi struct { +} + // @Tags System // @Summary 获取配置文件内容 // @Security ApiKeyAuth // @Produce application/json // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}" // @Router /system/getSystemConfig [post] -func GetSystemConfig(c *gin.Context) { - if err, config := service.GetSystemConfig(); err != nil { +func (s *SystemApi) GetSystemConfig(c *gin.Context) { + if err, config := systemConfigService.GetSystemConfig(); err != nil { global.GVA_LOG.Error("获取失败!", zap.Any("err", err)) response.FailWithMessage("获取失败", c) } else { - response.OkWithDetailed(response.SysConfigResponse{Config: config}, "获取成功", c) + response.OkWithDetailed(systemRes.SysConfigResponse{Config: config}, "获取成功", c) } } @@ -33,10 +36,10 @@ func GetSystemConfig(c *gin.Context) { // @Param data body model.System true "设置配置文件内容" // @Success 200 {string} string "{"success":true,"data":{},"msg":"设置成功"}" // @Router /system/setSystemConfig [post] -func SetSystemConfig(c *gin.Context) { +func (s *SystemApi) SetSystemConfig(c *gin.Context) { var sys system.System _ = c.ShouldBindJSON(&sys) - if err := service.SetSystemConfig(sys); err != nil { + if err := systemConfigService.SetSystemConfig(sys); err != nil { global.GVA_LOG.Error("设置失败!", zap.Any("err", err)) response.FailWithMessage("设置失败", c) } else { @@ -50,7 +53,7 @@ func SetSystemConfig(c *gin.Context) { // @Produce application/json // @Success 200 {string} string "{"code":0,"data":{},"msg":"重启系统成功"}" // @Router /system/reloadSystem [post] -func ReloadSystem(c *gin.Context) { +func (s *SystemApi) ReloadSystem(c *gin.Context) { err := utils.Reload() if err != nil { global.GVA_LOG.Error("重启系统失败!", zap.Any("err", err)) @@ -66,8 +69,8 @@ func ReloadSystem(c *gin.Context) { // @Produce application/json // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}" // @Router /system/getServerInfo [post] -func GetServerInfo(c *gin.Context) { - if server, err := service.GetServerInfo(); err != nil { +func (s *SystemApi) GetServerInfo(c *gin.Context) { + if server, err := systemConfigService.GetServerInfo(); err != nil { global.GVA_LOG.Error("获取失败!", zap.Any("err", err)) response.FailWithMessage("获取失败", c) } else { diff --git a/server/api/v1/sys_user.go b/server/api/v1/system/sys_user.go similarity index 69% rename from server/api/v1/sys_user.go rename to server/api/v1/system/sys_user.go index e1d9e6d8d8879c5b6d233086e99ff3a229de5e51..45d008acd0a613ed02fe35a8050a1c9bf33b8cee 100644 --- a/server/api/v1/sys_user.go +++ b/server/api/v1/system/sys_user.go @@ -1,12 +1,13 @@ -package v1 +package system import ( "gin-vue-admin/global" "gin-vue-admin/middleware" + "gin-vue-admin/model/common/request" + "gin-vue-admin/model/common/response" "gin-vue-admin/model/system" - "gin-vue-admin/model/system/request" - "gin-vue-admin/model/system/response" - "gin-vue-admin/service" + systemReq "gin-vue-admin/model/system/request" + systemRes "gin-vue-admin/model/system/response" "gin-vue-admin/utils" "time" @@ -19,11 +20,11 @@ import ( // @Tags Base // @Summary 用户登录 // @Produce application/json -// @Param data body request.Login true "用户名, 密码, 验证码" +// @Param data body systemReq.Login true "用户名, 密码, 验证码" // @Success 200 {string} string "{"success":true,"data":{},"msg":"登陆成功"}" // @Router /base/login [post] -func Login(c *gin.Context) { - var l request.Login +func (b *BaseApi) Login(c *gin.Context) { + var l systemReq.Login _ = c.ShouldBindJSON(&l) if err := utils.Verify(l, utils.LoginVerify); err != nil { response.FailWithMessage(err.Error(), c) @@ -31,11 +32,11 @@ func Login(c *gin.Context) { } if store.Verify(l.CaptchaId, l.Captcha, true) { u := &system.SysUser{Username: l.Username, Password: l.Password} - if err, user := service.Login(u); err != nil { + if err, user := userService.Login(u); err != nil { global.GVA_LOG.Error("登陆失败! 用户名不存在或者密码错误!", zap.Any("err", err)) response.FailWithMessage("用户名不存在或者密码错误", c) } else { - tokenNext(c, *user) + b.tokenNext(c, *user) } } else { response.FailWithMessage("验证码错误", c) @@ -43,9 +44,9 @@ func Login(c *gin.Context) { } // 登录以后签发jwt -func tokenNext(c *gin.Context, user system.SysUser) { +func (b *BaseApi) tokenNext(c *gin.Context, user system.SysUser) { j := &middleware.JWT{SigningKey: []byte(global.GVA_CONFIG.JWT.SigningKey)} // 唯一签名 - claims := request.CustomClaims{ + claims := systemReq.CustomClaims{ UUID: user.UUID, ID: user.ID, NickName: user.NickName, @@ -65,20 +66,20 @@ func tokenNext(c *gin.Context, user system.SysUser) { return } if !global.GVA_CONFIG.System.UseMultipoint { - response.OkWithDetailed(response.LoginResponse{ + response.OkWithDetailed(systemRes.LoginResponse{ User: user, Token: token, ExpiresAt: claims.StandardClaims.ExpiresAt * 1000, }, "登录成功", c) return } - if err, jwtStr := service.GetRedisJWT(user.Username); err == redis.Nil { - if err := service.SetRedisJWT(token, user.Username); err != nil { + if err, jwtStr := jwtService.GetRedisJWT(user.Username); err == redis.Nil { + if err := jwtService.SetRedisJWT(token, user.Username); err != nil { global.GVA_LOG.Error("设置登录状态失败!", zap.Any("err", err)) response.FailWithMessage("设置登录状态失败", c) return } - response.OkWithDetailed(response.LoginResponse{ + response.OkWithDetailed(systemRes.LoginResponse{ User: user, Token: token, ExpiresAt: claims.StandardClaims.ExpiresAt * 1000, @@ -89,15 +90,15 @@ func tokenNext(c *gin.Context, user system.SysUser) { } else { var blackJWT system.JwtBlacklist blackJWT.Jwt = jwtStr - if err := service.JsonInBlacklist(blackJWT); err != nil { + if err := jwtService.JsonInBlacklist(blackJWT); err != nil { response.FailWithMessage("jwt作废失败", c) return } - if err := service.SetRedisJWT(token, user.Username); err != nil { + if err := jwtService.SetRedisJWT(token, user.Username); err != nil { response.FailWithMessage("设置登录状态失败", c) return } - response.OkWithDetailed(response.LoginResponse{ + response.OkWithDetailed(systemRes.LoginResponse{ User: user, Token: token, ExpiresAt: claims.StandardClaims.ExpiresAt * 1000, @@ -108,23 +109,23 @@ func tokenNext(c *gin.Context, user system.SysUser) { // @Tags SysUser // @Summary 用户注册账号 // @Produce application/json -// @Param data body model.SysUser true "用户名, 昵称, 密码, 角色ID" +// @Param data body systemReq.Register true "用户名, 昵称, 密码, 角色ID" // @Success 200 {string} string "{"success":true,"data":{},"msg":"注册成功"}" // @Router /user/register [post] -func Register(c *gin.Context) { - var r request.Register +func (b *BaseApi) Register(c *gin.Context) { + var r systemReq.Register _ = c.ShouldBindJSON(&r) if err := utils.Verify(r, utils.RegisterVerify); err != nil { response.FailWithMessage(err.Error(), c) return } user := &system.SysUser{Username: r.Username, NickName: r.NickName, Password: r.Password, HeaderImg: r.HeaderImg, AuthorityId: r.AuthorityId} - err, userReturn := service.Register(*user) + err, userReturn := userService.Register(*user) if err != nil { global.GVA_LOG.Error("注册失败!", zap.Any("err", err)) - response.FailWithDetailed(response.SysUserResponse{User: userReturn}, "注册失败", c) + response.FailWithDetailed(systemRes.SysUserResponse{User: userReturn}, "注册失败", c) } else { - response.OkWithDetailed(response.SysUserResponse{User: userReturn}, "注册成功", c) + response.OkWithDetailed(systemRes.SysUserResponse{User: userReturn}, "注册成功", c) } } @@ -132,18 +133,18 @@ func Register(c *gin.Context) { // @Summary 用户修改密码 // @Security ApiKeyAuth // @Produce application/json -// @Param data body request.ChangePasswordStruct true "用户名, 原密码, 新密码" +// @Param data body systemReq.ChangePasswordStruct true "用户名, 原密码, 新密码" // @Success 200 {string} string "{"success":true,"data":{},"msg":"修改成功"}" // @Router /user/changePassword [put] -func ChangePassword(c *gin.Context) { - var user request.ChangePasswordStruct +func (b *BaseApi) ChangePassword(c *gin.Context) { + var user systemReq.ChangePasswordStruct _ = c.ShouldBindJSON(&user) if err := utils.Verify(user, utils.ChangePasswordVerify); err != nil { response.FailWithMessage(err.Error(), c) return } u := &system.SysUser{Username: user.Username, Password: user.Password} - if err, _ := service.ChangePassword(u, user.NewPassword); err != nil { + if err, _ := userService.ChangePassword(u, user.NewPassword); err != nil { global.GVA_LOG.Error("修改失败!", zap.Any("err", err)) response.FailWithMessage("修改失败,原密码与当前账户不符", c) } else { @@ -159,14 +160,14 @@ func ChangePassword(c *gin.Context) { // @Param data body request.PageInfo true "页码, 每页大小" // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}" // @Router /user/getUserList [post] -func GetUserList(c *gin.Context) { +func (b *BaseApi) GetUserList(c *gin.Context) { var pageInfo request.PageInfo _ = c.ShouldBindJSON(&pageInfo) if err := utils.Verify(pageInfo, utils.PageInfoVerify); err != nil { response.FailWithMessage(err.Error(), c) return } - if err, list, total := service.GetUserInfoList(pageInfo); err != nil { + if err, list, total := userService.GetUserInfoList(pageInfo); err != nil { global.GVA_LOG.Error("获取失败!", zap.Any("err", err)) response.FailWithMessage("获取失败", c) } else { @@ -184,17 +185,17 @@ func GetUserList(c *gin.Context) { // @Security ApiKeyAuth // @accept application/json // @Produce application/json -// @Param data body request.SetUserAuth true "用户UUID, 角色ID" +// @Param data body systemReq.SetUserAuth true "用户UUID, 角色ID" // @Success 200 {string} string "{"success":true,"data":{},"msg":"修改成功"}" // @Router /user/setUserAuthority [post] -func SetUserAuthority(c *gin.Context) { - var sua request.SetUserAuth +func (b *BaseApi) SetUserAuthority(c *gin.Context) { + var sua systemReq.SetUserAuth _ = c.ShouldBindJSON(&sua) if UserVerifyErr := utils.Verify(sua, utils.SetUserAuthorityVerify); UserVerifyErr != nil { response.FailWithMessage(UserVerifyErr.Error(), c) return } - if err := service.SetUserAuthority(sua.UUID, sua.AuthorityId); err != nil { + if err := userService.SetUserAuthority(sua.UUID, sua.AuthorityId); err != nil { global.GVA_LOG.Error("修改失败!", zap.Any("err", err)) response.FailWithMessage("修改失败", c) } else { @@ -210,19 +211,19 @@ func SetUserAuthority(c *gin.Context) { // @Param data body request.GetById true "用户ID" // @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}" // @Router /user/deleteUser [delete] -func DeleteUser(c *gin.Context) { +func (b *BaseApi) DeleteUser(c *gin.Context) { var reqId request.GetById _ = c.ShouldBindJSON(&reqId) if err := utils.Verify(reqId, utils.IdVerify); err != nil { response.FailWithMessage(err.Error(), c) return } - jwtId := getUserID(c) + jwtId := utils.GetUserID(c) if jwtId == uint(reqId.ID) { response.FailWithMessage("删除失败, 自杀失败", c) return } - if err := service.DeleteUser(reqId.ID); err != nil { + if err := userService.DeleteUser(reqId.ID); err != nil { global.GVA_LOG.Error("删除失败!", zap.Any("err", err)) response.FailWithMessage("删除失败", c) } else { @@ -238,50 +239,17 @@ func DeleteUser(c *gin.Context) { // @Param data body model.SysUser true "ID, 用户名, 昵称, 头像链接" // @Success 200 {string} string "{"success":true,"data":{},"msg":"设置成功"}" // @Router /user/setUserInfo [put] -func SetUserInfo(c *gin.Context) { +func (b *BaseApi) SetUserInfo(c *gin.Context) { var user system.SysUser _ = c.ShouldBindJSON(&user) if err := utils.Verify(user, utils.IdVerify); err != nil { response.FailWithMessage(err.Error(), c) return } - if err, ReqUser := service.SetUserInfo(user); err != nil { + if err, ReqUser := userService.SetUserInfo(user); err != nil { global.GVA_LOG.Error("设置失败!", zap.Any("err", err)) response.FailWithMessage("设置失败", c) } else { response.OkWithDetailed(gin.H{"userInfo": ReqUser}, "设置成功", c) } } - -// 从Gin的Context中获取从jwt解析出来的用户ID -func getUserID(c *gin.Context) uint { - if claims, exists := c.Get("claims"); !exists { - global.GVA_LOG.Error("从Gin的Context中获取从jwt解析出来的用户ID失败, 请检查路由是否使用jwt中间件!") - return 0 - } else { - waitUse := claims.(*request.CustomClaims) - return waitUse.ID - } -} - -// 从Gin的Context中获取从jwt解析出来的用户UUID -func getUserUuid(c *gin.Context) string { - if claims, exists := c.Get("claims"); !exists { - global.GVA_LOG.Error("从Gin的Context中获取从jwt解析出来的用户UUID失败, 请检查路由是否使用jwt中间件!") - return "" - } else { - waitUse := claims.(*request.CustomClaims) - return waitUse.UUID.String() - } -} - -// 从Gin的Context中获取从jwt解析出来的用户角色id -func getUserAuthorityId(c *gin.Context) string { - if claims, exists := c.Get("claims"); !exists { - global.GVA_LOG.Error("从Gin的Context中获取从jwt解析出来的用户UUID失败, 请检查路由是否使用jwt中间件!") - return "" - } else { - waitUse := claims.(*request.CustomClaims) - return waitUse.AuthorityId - } -} diff --git a/server/initialize/gorm.go b/server/initialize/gorm.go index ee3ff8b51aa9a665a8a9b86bbbf1748e0fc98d22..8a9b529e490a9ceb1fbd59c87e4fd8d79323e922 100644 --- a/server/initialize/gorm.go +++ b/server/initialize/gorm.go @@ -3,6 +3,7 @@ package initialize import ( "gin-vue-admin/global" "gin-vue-admin/initialize/internal" + "gin-vue-admin/model/autocode" "gin-vue-admin/model/example" "gin-vue-admin/model/system" "os" @@ -51,6 +52,7 @@ func MysqlTables(db *gorm.DB) { system.SysOperationRecord{}, system.SysAutoCodeHistory{}, // Code generated by gin-vue-admin Begin; DO NOT EDIT. + autocode.AutoCodeExample{}, // Code generated by gin-vue-admin End; DO NOT EDIT. ) if err != nil { diff --git a/server/initialize/router.go b/server/initialize/router.go index 02dda6a2cea57c3781ceb3feda6222b5358def5b..213a3bbe4c88b1d25a8fb5b3f91c62799f9801a1 100644 --- a/server/initialize/router.go +++ b/server/initialize/router.go @@ -25,32 +25,38 @@ func Routers() *gin.Engine { Router.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler)) global.GVA_LOG.Info("register swagger handler") // 方便统一添加路由组前缀 多服务器上线使用 + + //获取路由组实例 + systemRouter := router.RouterGroupApp.System + exampleRouter := router.RouterGroupApp.Example + autocodeRouter := router.RouterGroupApp.Autocode PublicGroup := Router.Group("") { - router.RouterApp.System.InitBaseRouter(PublicGroup) // 注册基础功能路由 不做鉴权 - router.RouterApp.System.InitInitRouter(PublicGroup) // 自动初始化相关 + systemRouter.InitBaseRouter(PublicGroup) // 注册基础功能路由 不做鉴权 + systemRouter.InitInitRouter(PublicGroup) // 自动初始化相关 } PrivateGroup := Router.Group("") PrivateGroup.Use(middleware.JWTAuth()).Use(middleware.CasbinHandler()) { - router.RouterApp.System.InitApiRouter(PrivateGroup) // 注册功能api路由 - router.RouterApp.System.InitJwtRouter(PrivateGroup) // jwt相关路由 - router.RouterApp.System.InitUserRouter(PrivateGroup) // 注册用户路由 - router.RouterApp.System.InitMenuRouter(PrivateGroup) // 注册menu路由 - router.RouterApp.System.InitEmailRouter(PrivateGroup) // 邮件相关路由 - router.RouterApp.System.InitSystemRouter(PrivateGroup) // system相关路由 - router.RouterApp.System.InitCasbinRouter(PrivateGroup) // 权限相关路由 - router.RouterApp.Example.InitCustomerRouter(PrivateGroup) // 客户路由 - router.RouterApp.System.InitAutoCodeRouter(PrivateGroup) // 创建自动化代码 - router.RouterApp.System.InitAuthorityRouter(PrivateGroup) // 注册角色路由 - router.RouterApp.Example.InitSimpleUploaderRouter(PrivateGroup) // 断点续传(插件版) - router.RouterApp.System.InitSysDictionaryRouter(PrivateGroup) // 字典管理 - router.RouterApp.System.InitSysOperationRecordRouter(PrivateGroup) // 操作记录 - router.RouterApp.System.InitSysDictionaryDetailRouter(PrivateGroup) // 字典详情管理 - router.RouterApp.Example.InitFileUploadAndDownloadRouter(PrivateGroup) // 文件上传下载功能路由 - router.RouterApp.Example.InitExcelRouter(PrivateGroup) // 表格导入导出 + systemRouter.InitApiRouter(PrivateGroup) // 注册功能api路由 + systemRouter.InitJwtRouter(PrivateGroup) // jwt相关路由 + systemRouter.InitUserRouter(PrivateGroup) // 注册用户路由 + systemRouter.InitMenuRouter(PrivateGroup) // 注册menu路由 + systemRouter.InitEmailRouter(PrivateGroup) // 邮件相关路由 + systemRouter.InitSystemRouter(PrivateGroup) // system相关路由 + systemRouter.InitCasbinRouter(PrivateGroup) // 权限相关路由 + systemRouter.InitAutoCodeRouter(PrivateGroup) // 创建自动化代码 + systemRouter.InitAuthorityRouter(PrivateGroup) // 注册角色路由 + systemRouter.InitSysDictionaryRouter(PrivateGroup) // 字典管理 + systemRouter.InitSysOperationRecordRouter(PrivateGroup) // 操作记录 + systemRouter.InitSysDictionaryDetailRouter(PrivateGroup) // 字典详情管理 + exampleRouter.InitFileUploadAndDownloadRouter(PrivateGroup) // 文件上传下载功能路由 + exampleRouter.InitExcelRouter(PrivateGroup) // 表格导入导出 + exampleRouter.InitSimpleUploaderRouter(PrivateGroup) // 断点续传(插件版) + exampleRouter.InitCustomerRouter(PrivateGroup) // 客户路由 // Code generated by gin-vue-admin Begin; DO NOT EDIT. + autocodeRouter.InitSysAutoCodeExampleRouter(PrivateGroup) // Code generated by gin-vue-admin End; DO NOT EDIT. } global.GVA_LOG.Info("router register success") diff --git a/server/middleware/casbin_rbac.go b/server/middleware/casbin_rbac.go index e643335e8e4528f3b5dfbb3c158ad526feabd025..8812f10b2178a3122579f1431e880ce7dbd2f250 100644 --- a/server/middleware/casbin_rbac.go +++ b/server/middleware/casbin_rbac.go @@ -2,12 +2,14 @@ package middleware import ( "gin-vue-admin/global" - "gin-vue-admin/model/request" - "gin-vue-admin/model/response" + "gin-vue-admin/model/common/response" + "gin-vue-admin/model/system/request" "gin-vue-admin/service" "github.com/gin-gonic/gin" ) +var casbinService = service.ServiceGroupApp.SystemServiceGroup.CasbinService + // 拦截器 func CasbinHandler() gin.HandlerFunc { return func(c *gin.Context) { @@ -19,7 +21,7 @@ func CasbinHandler() gin.HandlerFunc { act := c.Request.Method // 获取用户的角色 sub := waitUse.AuthorityId - e := service.Casbin() + e := casbinService.Casbin() // 判断策略中是否存在 success, _ := e.Enforce(sub, obj, act) if global.GVA_CONFIG.System.Env == "develop" || success { diff --git a/server/middleware/email.go b/server/middleware/email.go index af80299e53fa501821238aba33d30a2cbdf0dd81..d6f0cbfd0aef2810ac5770d8970fe9a3909cffdc 100644 --- a/server/middleware/email.go +++ b/server/middleware/email.go @@ -2,8 +2,8 @@ package middleware import ( "gin-vue-admin/global" - "gin-vue-admin/model/request" "gin-vue-admin/model/system" + "gin-vue-admin/model/system/request" "gin-vue-admin/service" "gin-vue-admin/utils" "github.com/gin-gonic/gin" @@ -13,6 +13,8 @@ import ( "time" ) +var userService = service.ServiceGroupApp.SystemServiceGroup.UserService + func ErrorToEmail() gin.HandlerFunc { return func(c *gin.Context) { var username string @@ -21,7 +23,7 @@ func ErrorToEmail() gin.HandlerFunc { username = waitUse.Username } else { id, _ := strconv.Atoi(c.Request.Header.Get("x-user-id")) - err, user := service.FindUserById(id) + err, user := userService.FindUserById(id) if err != nil { username = "Unknown" } diff --git a/server/middleware/jwt.go b/server/middleware/jwt.go index 8f332469df3c2ab7b87d3db9df6f3f4bfc4d99a3..74b285dcc4d72edae9355f325a7f0d9cfd8901b1 100644 --- a/server/middleware/jwt.go +++ b/server/middleware/jwt.go @@ -3,9 +3,9 @@ package middleware import ( "errors" "gin-vue-admin/global" + "gin-vue-admin/model/common/response" "gin-vue-admin/model/system" "gin-vue-admin/model/system/request" - "gin-vue-admin/model/system/response" "gin-vue-admin/service" "strconv" "time" @@ -15,6 +15,8 @@ import ( "go.uber.org/zap" ) +var jwtService = service.ServiceGroupApp.SystemServiceGroup.JwtService + func JWTAuth() gin.HandlerFunc { return func(c *gin.Context) { // 我们这里jwt鉴权取头部信息 x-token 登录时回返回token信息 这里前端需要把token存储到cookie或者本地localStorage中 不过需要跟后端协商过期时间 可以约定刷新令牌或者重新登录 @@ -24,7 +26,7 @@ func JWTAuth() gin.HandlerFunc { c.Abort() return } - if service.IsBlacklist(token) { + if jwtService.IsBlacklist(token) { response.FailWithDetailed(gin.H{"reload": true}, "您的帐户异地登陆或令牌失效", c) c.Abort() return @@ -42,8 +44,8 @@ func JWTAuth() gin.HandlerFunc { c.Abort() return } - if err, _ = service.FindUserByUuid(claims.UUID.String()); err != nil { - _ = service.JsonInBlacklist(system.JwtBlacklist{Jwt: token}) + if err, _ = userService.FindUserByUuid(claims.UUID.String()); err != nil { + _ = jwtService.JsonInBlacklist(system.JwtBlacklist{Jwt: token}) response.FailWithDetailed(gin.H{"reload": true}, err.Error(), c) c.Abort() } @@ -54,14 +56,14 @@ func JWTAuth() gin.HandlerFunc { c.Header("new-token", newToken) c.Header("new-expires-at", strconv.FormatInt(newClaims.ExpiresAt, 10)) if global.GVA_CONFIG.System.UseMultipoint { - err, RedisJwtToken := service.GetRedisJWT(newClaims.Username) + err, RedisJwtToken := jwtService.GetRedisJWT(newClaims.Username) if err != nil { global.GVA_LOG.Error("get redis jwt failed", zap.Any("err", err)) } else { // 当之前的取成功时才进行拉黑操作 - _ = service.JsonInBlacklist(system.JwtBlacklist{Jwt: RedisJwtToken}) + _ = jwtService.JsonInBlacklist(system.JwtBlacklist{Jwt: RedisJwtToken}) } // 无论如何都要记录当前的活跃状态 - _ = service.SetRedisJWT(newToken, newClaims.Username) + _ = jwtService.SetRedisJWT(newToken, newClaims.Username) } } c.Set("claims", claims) diff --git a/server/middleware/need_init.go b/server/middleware/need_init.go index 4263dd9cd73d4ff39dde59b134b39190f645dc7f..c883bb8196d7644336da2c6919573d7e0e2e7ed0 100644 --- a/server/middleware/need_init.go +++ b/server/middleware/need_init.go @@ -2,7 +2,7 @@ package middleware import ( "gin-vue-admin/global" - "gin-vue-admin/model/response" + "gin-vue-admin/model/common/response" "github.com/gin-gonic/gin" ) diff --git a/server/middleware/operation.go b/server/middleware/operation.go index 29acc47b0e6c5adb6ec1a3d97af119acd98c33d2..2bfa25b5bcd28ed7c7e8c6cb4a56a59baf19cf7a 100644 --- a/server/middleware/operation.go +++ b/server/middleware/operation.go @@ -3,8 +3,8 @@ package middleware import ( "bytes" "gin-vue-admin/global" - "gin-vue-admin/model/request" "gin-vue-admin/model/system" + "gin-vue-admin/model/system/request" "gin-vue-admin/service" "github.com/gin-gonic/gin" "go.uber.org/zap" @@ -14,6 +14,8 @@ import ( "time" ) +var operationRecordService = service.ServiceGroupApp.SystemServiceGroup.OperationRecordService + func OperationRecord() gin.HandlerFunc { return func(c *gin.Context) { var body []byte @@ -65,7 +67,7 @@ func OperationRecord() gin.HandlerFunc { record.Latency = latency record.Resp = writer.body.String() - if err := service.CreateSysOperationRecord(record); err != nil { + if err := operationRecordService.CreateSysOperationRecord(record); err != nil { global.GVA_LOG.Error("create operation record error:", zap.Any("err", err)) } } diff --git a/server/model/autocode/autocodeExample.go b/server/model/autocode/autocodeExample.go new file mode 100644 index 0000000000000000000000000000000000000000..e3c64a906f0a526660f5329c04bd95d302994831 --- /dev/null +++ b/server/model/autocode/autocodeExample.go @@ -0,0 +1,12 @@ +// 自动生成模板SysDictionaryDetail +package autocode + +import ( + "gin-vue-admin/global" +) + +// 如果含有time.Time 请自行import time包 +type AutoCodeExample struct { + global.GVA_MODEL + AutoCodeExampleField string `json:"autoCodeExampleField" form:"autoCodeExampleField" gorm:"column:auto_code_example_field;comment:仅作示例条目无实际作用"` // 展示值 +} diff --git a/server/model/autocode/requset/autocodeExample.go b/server/model/autocode/requset/autocodeExample.go new file mode 100644 index 0000000000000000000000000000000000000000..cdfa48f949b557a64cd33ba2bef256798b0be8be --- /dev/null +++ b/server/model/autocode/requset/autocodeExample.go @@ -0,0 +1,13 @@ +// 自动生成模板SysDictionaryDetail +package request + +import ( + "gin-vue-admin/model/autocode" + "gin-vue-admin/model/common/request" +) + +// 如果含有time.Time 请自行import time包 +type AutoCodeExampleSearch struct { + autocode.AutoCodeExample + request.PageInfo +} diff --git a/server/model/example/request/common.go b/server/model/common/request/common.go similarity index 100% rename from server/model/example/request/common.go rename to server/model/common/request/common.go diff --git a/server/model/response/common.go b/server/model/common/response/common.go similarity index 100% rename from server/model/response/common.go rename to server/model/common/response/common.go diff --git a/server/model/response/response.go b/server/model/common/response/response.go similarity index 100% rename from server/model/response/response.go rename to server/model/common/response/response.go diff --git a/server/model/request/common.go b/server/model/request/common.go deleted file mode 100644 index 5dbfcb45e3e844d988ac33795bff0498fc125dea..0000000000000000000000000000000000000000 --- a/server/model/request/common.go +++ /dev/null @@ -1,23 +0,0 @@ -package request - -// Paging common input parameter structure -type PageInfo struct { - Page int `json:"page" form:"page"` // 页码 - PageSize int `json:"pageSize" form:"pageSize"` // 每页大小 -} - -// Find by id structure -type GetById struct { - ID float64 `json:"id" form:"id"` // 主键ID -} - -type IdsReq struct { - Ids []int `json:"ids" form:"ids"` -} - -// Get role by id structure -type GetAuthorityId struct { - AuthorityId string // 角色ID -} - -type Empty struct{} diff --git a/server/model/request/jwt.go b/server/model/request/jwt.go deleted file mode 100644 index 7aa164294b06591265269b9cc0dbd9f95edd095f..0000000000000000000000000000000000000000 --- a/server/model/request/jwt.go +++ /dev/null @@ -1,17 +0,0 @@ -package request - -import ( - "github.com/dgrijalva/jwt-go" - uuid "github.com/satori/go.uuid" -) - -// Custom claims structure -type CustomClaims struct { - UUID uuid.UUID - ID uint - Username string - NickName string - AuthorityId string - BufferTime int64 - jwt.StandardClaims -} diff --git a/server/model/example/request/jwt.go b/server/model/system/request/jwt.go similarity index 100% rename from server/model/example/request/jwt.go rename to server/model/system/request/jwt.go diff --git a/server/model/system/request/sys_api.go b/server/model/system/request/sys_api.go index 2f853421fd67a8e45871f74037e4f215889439ee..d86e8c89701b060b997992f1fb97b2600381a2c1 100644 --- a/server/model/system/request/sys_api.go +++ b/server/model/system/request/sys_api.go @@ -1,13 +1,14 @@ package request import ( + "gin-vue-admin/model/common/request" "gin-vue-admin/model/system" ) // api分页条件查询及排序结构体 type SearchApiParams struct { system.SysApi - PageInfo + request.PageInfo OrderKey string `json:"orderKey"` // 排序 Desc bool `json:"desc"` // 排序方式:升序false(默认)|降序true } diff --git a/server/model/system/request/sys_autocode.go b/server/model/system/request/sys_autocode.go index d1417b55675f2149fc698d80b2ceb1be0edb9529..9cfa2880c1cc488356a8ffe736f713b08e3be314 100644 --- a/server/model/system/request/sys_autocode.go +++ b/server/model/system/request/sys_autocode.go @@ -1,6 +1,6 @@ package request -import "gin-vue-admin/model/request" +import "gin-vue-admin/model/common/request" type SysAutoHistory struct { request.PageInfo diff --git a/server/model/system/request/sys_dictionary.go b/server/model/system/request/sys_dictionary.go index cb0a08a75c81febbf48c6ca5057cc7d29ccc5db9..4402daa70d400c94653e291143c0915e412a54e1 100644 --- a/server/model/system/request/sys_dictionary.go +++ b/server/model/system/request/sys_dictionary.go @@ -1,7 +1,7 @@ package request import ( - "gin-vue-admin/model/request" + "gin-vue-admin/model/common/request" "gin-vue-admin/model/system" ) diff --git a/server/model/system/request/sys_dictionary_detail.go b/server/model/system/request/sys_dictionary_detail.go index c6d9204fb1a84ffb61b4757ec0c2c8554ab421e0..5d688e645a40fd7d135f0ba07078bd7fe8d314c9 100644 --- a/server/model/system/request/sys_dictionary_detail.go +++ b/server/model/system/request/sys_dictionary_detail.go @@ -1,7 +1,7 @@ package request import ( - "gin-vue-admin/model/request" + "gin-vue-admin/model/common/request" "gin-vue-admin/model/system" ) diff --git a/server/model/system/request/sys_operation_record.go b/server/model/system/request/sys_operation_record.go index bb6394e4eec170df402967bb8ceeab8c8ef3a1b2..03506330a2ef8c19b049ef95d281ead23e051b59 100644 --- a/server/model/system/request/sys_operation_record.go +++ b/server/model/system/request/sys_operation_record.go @@ -1,7 +1,7 @@ package request import ( - "gin-vue-admin/model/request" + "gin-vue-admin/model/common/request" "gin-vue-admin/model/system" ) diff --git a/server/model/system/response/common.go b/server/model/system/response/common.go deleted file mode 100644 index 74610965b7aae8f9c956a6c5e9b15f806d083c8a..0000000000000000000000000000000000000000 --- a/server/model/system/response/common.go +++ /dev/null @@ -1,8 +0,0 @@ -package response - -type PageResult struct { - List interface{} `json:"list"` - Total int64 `json:"total"` - Page int `json:"page"` - PageSize int `json:"pageSize"` -} diff --git a/server/resource/template/server/model.go.tpl b/server/resource/template/server/model.go.tpl index 341ee046e879acb05bf431a14c8770d9d02dfacf..86e1874ae271eb2dfcb23f69b14a8eda1bfd58e9 100644 --- a/server/resource/template/server/model.go.tpl +++ b/server/resource/template/server/model.go.tpl @@ -1,5 +1,5 @@ // 自动生成模板{{.StructName}} -package model +package autocode import ( "gin-vue-admin/global" diff --git a/server/router/autocode/autocodeExample.go b/server/router/autocode/autocodeExample.go new file mode 100644 index 0000000000000000000000000000000000000000..d736df8166c41edfce9125c65af428cdd0e0505e --- /dev/null +++ b/server/router/autocode/autocodeExample.go @@ -0,0 +1,22 @@ +package autocode + +import ( + "gin-vue-admin/api/v1" + "gin-vue-admin/middleware" + "github.com/gin-gonic/gin" +) + +type AutoCodeExampleRouter struct { +} + +func (s *AutoCodeExampleRouter) InitSysAutoCodeExampleRouter(Router *gin.RouterGroup) { + autoCodeExampleRouter := Router.Group("autoCodeExample").Use(middleware.OperationRecord()) + var autoCodeExampleApi = v1.ApiGroupApp.AutoCodeApiGroup.AutoCodeExampleApi + { + autoCodeExampleRouter.POST("createSysAutoCodeExample", autoCodeExampleApi.CreateAutoCodeExample) // 新建AutoCodeExample + autoCodeExampleRouter.DELETE("deleteSysAutoCodeExample", autoCodeExampleApi.DeleteAutoCodeExample) // 删除AutoCodeExample + autoCodeExampleRouter.PUT("updateSysAutoCodeExample", autoCodeExampleApi.UpdateAutoCodeExample) // 更新AutoCodeExample + autoCodeExampleRouter.GET("findSysAutoCodeExample", autoCodeExampleApi.FindAutoCodeExample) // 根据ID获取AutoCodeExample + autoCodeExampleRouter.GET("getSysAutoCodeExampleList", autoCodeExampleApi.GetAutoCodeExampleList) // 获取AutoCodeExample列表 + } +} diff --git a/server/router/autocode/enter.go b/server/router/autocode/enter.go new file mode 100644 index 0000000000000000000000000000000000000000..fc6d069505029b5f9323e6541a3c194265b4ddff --- /dev/null +++ b/server/router/autocode/enter.go @@ -0,0 +1,5 @@ +package autocode + +type RouterGroup struct { + AutoCodeExampleRouter +} diff --git a/server/router/enter.go b/server/router/enter.go new file mode 100644 index 0000000000000000000000000000000000000000..dedba9c179f3961b86a3ce64de6d5b41a495e206 --- /dev/null +++ b/server/router/enter.go @@ -0,0 +1,15 @@ +package router + +import ( + "gin-vue-admin/router/autocode" + "gin-vue-admin/router/example" + "gin-vue-admin/router/system" +) + +type RouterGroup struct { + System system.RouterGroup + Example example.RouterGroup + Autocode autocode.RouterGroup +} + +var RouterGroupApp = new(RouterGroup) diff --git a/server/router/example/enter.go b/server/router/example/enter.go new file mode 100644 index 0000000000000000000000000000000000000000..11f02abb154f670ba114a5c9c52ecb000479f778 --- /dev/null +++ b/server/router/example/enter.go @@ -0,0 +1,8 @@ +package example + +type RouterGroup struct { + CustomerRouter + ExcelRouter + FileUploadAndDownloadRouter + SimpleUploaderRouter +} diff --git a/server/router/example/exa_customer.go b/server/router/example/exa_customer.go index ec486afc822575fd1a5ffa9b794eeed5ece63927..31976ee6fa4e7ab5ba1d52fbecce022a42df580f 100644 --- a/server/router/example/exa_customer.go +++ b/server/router/example/exa_customer.go @@ -1,18 +1,22 @@ package example import ( - "gin-vue-admin/api/v1" + v1 "gin-vue-admin/api/v1" "gin-vue-admin/middleware" "github.com/gin-gonic/gin" ) -func (e *Router) InitCustomerRouter(Router *gin.RouterGroup) { - CustomerRouter := Router.Group("customer").Use(middleware.OperationRecord()) +type CustomerRouter struct { +} + +func (e *CustomerRouter) InitCustomerRouter(Router *gin.RouterGroup) { + customerRouter := Router.Group("customer").Use(middleware.OperationRecord()) + var exaCustomerApi = v1.ApiGroupApp.ExampleApiGroup.CustomerApi { - CustomerRouter.POST("customer", v1.CreateExaCustomer) // 创建客户 - CustomerRouter.PUT("customer", v1.UpdateExaCustomer) // 更新客户 - CustomerRouter.DELETE("customer", v1.DeleteExaCustomer) // 删除客户 - CustomerRouter.GET("customer", v1.GetExaCustomer) // 获取单一客户信息 - CustomerRouter.GET("customerList", v1.GetExaCustomerList) // 获取客户列表 + customerRouter.POST("customer", exaCustomerApi.CreateExaCustomer) // 创建客户 + customerRouter.PUT("customer", exaCustomerApi.UpdateExaCustomer) // 更新客户 + customerRouter.DELETE("customer", exaCustomerApi.DeleteExaCustomer) // 删除客户 + customerRouter.GET("customer", exaCustomerApi.GetExaCustomer) // 获取单一客户信息 + customerRouter.GET("customerList", exaCustomerApi.GetExaCustomerList) // 获取客户列表 } } diff --git a/server/router/example/exa_excel.go b/server/router/example/exa_excel.go index 7d7a6c95e023712d094cf41cb217f6f6da3dea2f..d8f0c56099397a8ef260d72d92db17fc68962db6 100644 --- a/server/router/example/exa_excel.go +++ b/server/router/example/exa_excel.go @@ -5,12 +5,16 @@ import ( "github.com/gin-gonic/gin" ) -func (e *Router) InitExcelRouter(Router *gin.RouterGroup) { - ExcelRouter := Router.Group("excel") +type ExcelRouter struct { +} + +func (e *ExcelRouter) InitExcelRouter(Router *gin.RouterGroup) { + excelRouter := Router.Group("excel") + var exaExcelApi = v1.ApiGroupApp.ExampleApiGroup.ExcelApi { - ExcelRouter.POST("/importExcel", v1.ImportExcel) // 导入Excel - ExcelRouter.GET("/loadExcel", v1.LoadExcel) // 加载Excel数据 - ExcelRouter.POST("/exportExcel", v1.ExportExcel) // 导出Excel - ExcelRouter.GET("/downloadTemplate", v1.DownloadTemplate) // 下载模板文件 + excelRouter.POST("/importExcel", exaExcelApi.ImportExcel) // 导入Excel + excelRouter.GET("/loadExcel", exaExcelApi.LoadExcel) // 加载Excel数据 + excelRouter.POST("/exportExcel", exaExcelApi.ExportExcel) // 导出Excel + excelRouter.GET("/downloadTemplate", exaExcelApi.DownloadTemplate) // 下载模板文件 } } diff --git a/server/router/example/exa_file_upload_and_download.go b/server/router/example/exa_file_upload_and_download.go index 6220b2855fb523ff9545d2ec4b06f05658d445ab..7effbe8f525b8d7539ade3a885b10ff6a6dabe49 100644 --- a/server/router/example/exa_file_upload_and_download.go +++ b/server/router/example/exa_file_upload_and_download.go @@ -5,15 +5,19 @@ import ( "github.com/gin-gonic/gin" ) -func (e *Router) InitFileUploadAndDownloadRouter(Router *gin.RouterGroup) { - FileUploadAndDownloadRouter := Router.Group("fileUploadAndDownload") +type FileUploadAndDownloadRouter struct { +} + +func (e *FileUploadAndDownloadRouter) InitFileUploadAndDownloadRouter(Router *gin.RouterGroup) { + fileUploadAndDownloadRouter := Router.Group("fileUploadAndDownload") + var exaFileUploadAndDownloadApi = v1.ApiGroupApp.ExampleApiGroup.FileUploadAndDownloadApi { - FileUploadAndDownloadRouter.POST("/upload", v1.UploadFile) // 上传文件 - FileUploadAndDownloadRouter.POST("/getFileList", v1.GetFileList) // 获取上传文件列表 - FileUploadAndDownloadRouter.POST("/deleteFile", v1.DeleteFile) // 删除指定文件 - FileUploadAndDownloadRouter.POST("/breakpointContinue", v1.BreakpointContinue) // 断点续传 - FileUploadAndDownloadRouter.GET("/findFile", v1.FindFile) // 查询当前文件成功的切片 - FileUploadAndDownloadRouter.POST("/breakpointContinueFinish", v1.BreakpointContinueFinish) // 查询当前文件成功的切片 - FileUploadAndDownloadRouter.POST("/removeChunk", v1.RemoveChunk) // 查询当前文件成功的切片 + fileUploadAndDownloadRouter.POST("/upload", exaFileUploadAndDownloadApi.UploadFile) // 上传文件 + fileUploadAndDownloadRouter.POST("/getFileList", exaFileUploadAndDownloadApi.GetFileList) // 获取上传文件列表 + fileUploadAndDownloadRouter.POST("/deleteFile", exaFileUploadAndDownloadApi.DeleteFile) // 删除指定文件 + fileUploadAndDownloadRouter.POST("/breakpointContinue", exaFileUploadAndDownloadApi.BreakpointContinue) // 断点续传 + fileUploadAndDownloadRouter.GET("/findFile", exaFileUploadAndDownloadApi.FindFile) // 查询当前文件成功的切片 + fileUploadAndDownloadRouter.POST("/breakpointContinueFinish", exaFileUploadAndDownloadApi.BreakpointContinueFinish) // 查询当前文件成功的切片 + fileUploadAndDownloadRouter.POST("/removeChunk", exaFileUploadAndDownloadApi.RemoveChunk) // 查询当前文件成功的切片 } } diff --git a/server/router/example/exa_simple_uploader.go b/server/router/example/exa_simple_uploader.go index 7681b3ec45700f900cb37bb20f963993c1f45b8a..eab5b7da2aa49ac1b8cd8fd86433665084565fa6 100644 --- a/server/router/example/exa_simple_uploader.go +++ b/server/router/example/exa_simple_uploader.go @@ -5,11 +5,14 @@ import ( "github.com/gin-gonic/gin" ) -func (e *Router) InitSimpleUploaderRouter(Router *gin.RouterGroup) { - SimpleUploaderRouter := Router.Group("simpleUploader") +type SimpleUploaderRouter struct{} + +func (e *SimpleUploaderRouter) InitSimpleUploaderRouter(Router *gin.RouterGroup) { + simpleUploaderRouter := Router.Group("simpleUploader") + var simpleUploaderApi = v1.ApiGroupApp.ExampleApiGroup.SimpleUploaderApi { - SimpleUploaderRouter.POST("upload", v1.SimpleUploaderUpload) // 上传功能 - SimpleUploaderRouter.GET("checkFileMd5", v1.CheckFileMd5) // 文件完整度验证 - SimpleUploaderRouter.GET("mergeFileMd5", v1.MergeFileMd5) // 合并文件 + simpleUploaderRouter.POST("upload", simpleUploaderApi.SimpleUploaderUpload) // 上传功能 + simpleUploaderRouter.GET("checkFileMd5", simpleUploaderApi.CheckFileMd5) // 文件完整度验证 + simpleUploaderRouter.GET("mergeFileMd5", simpleUploaderApi.MergeFileMd5) // 合并文件 } } diff --git a/server/router/system/enter.go b/server/router/system/enter.go new file mode 100644 index 0000000000000000000000000000000000000000..d608b3645d87ca39acd0c29f33c368050df25c8a --- /dev/null +++ b/server/router/system/enter.go @@ -0,0 +1,18 @@ +package system + +type RouterGroup struct { + ApiRouter + AuthorityRouter + AutoCodeRouter + BaseRouter + CasbinRouter + DictionaryRouter + DictionaryDetailRouter + EmailRouter + InitRouter + JwtRouter + MenuRouter + OperationRecordRouter + SysRouter + UserRouter +} diff --git a/server/router/system/sys_api.go b/server/router/system/sys_api.go index 41d4721e915b3557e638e575beaa31ab77c6153d..c309de67a2a0fa974d94ed95bdd2f3d435fa734a 100644 --- a/server/router/system/sys_api.go +++ b/server/router/system/sys_api.go @@ -6,15 +6,19 @@ import ( "github.com/gin-gonic/gin" ) -func (s *Router) InitApiRouter(Router *gin.RouterGroup) { - ApiRouter := Router.Group("api").Use(middleware.OperationRecord()) +type ApiRouter struct { +} + +func (s *ApiRouter) InitApiRouter(Router *gin.RouterGroup) { + apiRouter := Router.Group("api").Use(middleware.OperationRecord()) + var apiRouterApi = v1.ApiGroupApp.SystemApiGroup.SystemApiApi { - ApiRouter.POST("createApi", v1.CreateApi) // 创建Api - ApiRouter.POST("deleteApi", v1.DeleteApi) // 删除Api - ApiRouter.POST("getApiList", v1.GetApiList) // 获取Api列表 - ApiRouter.POST("getApiById", v1.GetApiById) // 获取单条Api消息 - ApiRouter.POST("updateApi", v1.UpdateApi) // 更新api - ApiRouter.POST("getAllApis", v1.GetAllApis) // 获取所有api - ApiRouter.DELETE("deleteApisByIds", v1.DeleteApisByIds) // 删除选中api + apiRouter.POST("createApi", apiRouterApi.CreateApi) // 创建Api + apiRouter.POST("deleteApi", apiRouterApi.DeleteApi) // 删除Api + apiRouter.POST("getApiList", apiRouterApi.GetApiList) // 获取Api列表 + apiRouter.POST("getApiById", apiRouterApi.GetApiById) // 获取单条Api消息 + apiRouter.POST("updateApi", apiRouterApi.UpdateApi) // 更新api + apiRouter.POST("getAllApis", apiRouterApi.GetAllApis) // 获取所有api + apiRouter.DELETE("deleteApisByIds", apiRouterApi.DeleteApisByIds) // 删除选中api } } diff --git a/server/router/system/sys_authority.go b/server/router/system/sys_authority.go index 401dc4ad53259a2d6ba9d96ce488510a4a1596cd..f273a8414c4d8924a5717d98a418ccc6c94e2183 100644 --- a/server/router/system/sys_authority.go +++ b/server/router/system/sys_authority.go @@ -6,14 +6,18 @@ import ( "github.com/gin-gonic/gin" ) -func (s *Router) InitAuthorityRouter(Router *gin.RouterGroup) { - AuthorityRouter := Router.Group("authority").Use(middleware.OperationRecord()) +type AuthorityRouter struct { +} + +func (s *AuthorityRouter) InitAuthorityRouter(Router *gin.RouterGroup) { + authorityRouter := Router.Group("authority").Use(middleware.OperationRecord()) + var authorityApi = v1.ApiGroupApp.SystemApiGroup.AuthorityApi { - AuthorityRouter.POST("createAuthority", v1.CreateAuthority) // 创建角色 - AuthorityRouter.POST("deleteAuthority", v1.DeleteAuthority) // 删除角色 - AuthorityRouter.PUT("updateAuthority", v1.UpdateAuthority) // 更新角色 - AuthorityRouter.POST("copyAuthority", v1.CopyAuthority) // 更新角色 - AuthorityRouter.POST("getAuthorityList", v1.GetAuthorityList) // 获取角色列表 - AuthorityRouter.POST("setDataAuthority", v1.SetDataAuthority) // 设置角色资源权限 + authorityRouter.POST("createAuthority", authorityApi.CreateAuthority) // 创建角色 + authorityRouter.POST("deleteAuthority", authorityApi.DeleteAuthority) // 删除角色 + authorityRouter.PUT("updateAuthority", authorityApi.UpdateAuthority) // 更新角色 + authorityRouter.POST("copyAuthority", authorityApi.CopyAuthority) // 更新角色 + authorityRouter.POST("getAuthorityList", authorityApi.GetAuthorityList) // 获取角色列表 + authorityRouter.POST("setDataAuthority", authorityApi.SetDataAuthority) // 设置角色资源权限 } } diff --git a/server/router/system/sys_auto_code.go b/server/router/system/sys_auto_code.go index 3ce6ec0ccd38b22647c5a56485b09fd4614c4109..62abbc22b2a181c33a30796a3582c48547ac3a07 100644 --- a/server/router/system/sys_auto_code.go +++ b/server/router/system/sys_auto_code.go @@ -5,17 +5,21 @@ import ( "github.com/gin-gonic/gin" ) -func (s *Router) InitAutoCodeRouter(Router *gin.RouterGroup) { - AutoCodeRouter := Router.Group("autoCode") +type AutoCodeRouter struct { +} + +func (s *AutoCodeRouter) InitAutoCodeRouter(Router *gin.RouterGroup) { + autoCodeRouter := Router.Group("autoCode") + var authorityApi = v1.ApiGroupApp.SystemApiGroup.AutoCodeApi { - AutoCodeRouter.POST("delSysHistory", v1.DelSysHistory) // 删除回滚记录 - AutoCodeRouter.POST("getMeta", v1.GetMeta) // 根据id获取meta信息 - AutoCodeRouter.POST("getSysHistory", v1.GetSysHistory) // 获取回滚记录分页 - AutoCodeRouter.POST("rollback", v1.RollBack) // 回滚 - AutoCodeRouter.POST("preview", v1.PreviewTemp) // 获取自动创建代码预览 - AutoCodeRouter.POST("createTemp", v1.CreateTemp) // 创建自动化代码 - AutoCodeRouter.GET("getTables", v1.GetTables) // 获取对应数据库的表 - AutoCodeRouter.GET("getDB", v1.GetDB) // 获取数据库 - AutoCodeRouter.GET("getColumn", v1.GetColumn) // 获取指定表所有字段信息 + autoCodeRouter.POST("delSysHistory", authorityApi.DelSysHistory) // 删除回滚记录 + autoCodeRouter.POST("getMeta", authorityApi.GetMeta) // 根据id获取meta信息 + autoCodeRouter.POST("getSysHistory", authorityApi.GetSysHistory) // 获取回滚记录分页 + autoCodeRouter.POST("rollback", authorityApi.RollBack) // 回滚 + autoCodeRouter.POST("preview", authorityApi.PreviewTemp) // 获取自动创建代码预览 + autoCodeRouter.POST("createTemp", authorityApi.CreateTemp) // 创建自动化代码 + autoCodeRouter.GET("getTables", authorityApi.GetTables) // 获取对应数据库的表 + autoCodeRouter.GET("getDB", authorityApi.GetDB) // 获取数据库 + autoCodeRouter.GET("getColumn", authorityApi.GetColumn) // 获取指定表所有字段信息 } } diff --git a/server/router/system/sys_base.go b/server/router/system/sys_base.go index 129b5a078596e4eb858c5076c34605bcf5affb44..da24a883656920a93ffb78b37d7343964be2161d 100644 --- a/server/router/system/sys_base.go +++ b/server/router/system/sys_base.go @@ -5,11 +5,15 @@ import ( "github.com/gin-gonic/gin" ) -func (s *Router) InitBaseRouter(Router *gin.RouterGroup) (R gin.IRoutes) { - BaseRouter := Router.Group("base") +type BaseRouter struct { +} + +func (s *BaseRouter) InitBaseRouter(Router *gin.RouterGroup) (R gin.IRoutes) { + baseRouter := Router.Group("base") + var baseApi = v1.ApiGroupApp.SystemApiGroup.BaseApi { - BaseRouter.POST("login", v1.Login) - BaseRouter.POST("captcha", v1.Captcha) + baseRouter.POST("login", baseApi.Login) + baseRouter.POST("captcha", baseApi.Captcha) } - return BaseRouter + return baseRouter } diff --git a/server/router/system/sys_casbin.go b/server/router/system/sys_casbin.go index d4262b30f219abf4af40f202c7449e6f8d8edc15..4dbf7e3be0d5bea43f724aa73e1fb508b5ad33c8 100644 --- a/server/router/system/sys_casbin.go +++ b/server/router/system/sys_casbin.go @@ -6,10 +6,14 @@ import ( "github.com/gin-gonic/gin" ) -func (s *Router) InitCasbinRouter(Router *gin.RouterGroup) { - CasbinRouter := Router.Group("casbin").Use(middleware.OperationRecord()) +type CasbinRouter struct { +} + +func (s *CasbinRouter) InitCasbinRouter(Router *gin.RouterGroup) { + casbinRouter := Router.Group("casbin").Use(middleware.OperationRecord()) + var casbinApi = v1.ApiGroupApp.SystemApiGroup.CasbinApi { - CasbinRouter.POST("updateCasbin", v1.UpdateCasbin) - CasbinRouter.POST("getPolicyPathByAuthorityId", v1.GetPolicyPathByAuthorityId) + casbinRouter.POST("updateCasbin", casbinApi.UpdateCasbin) + casbinRouter.POST("getPolicyPathByAuthorityId", casbinApi.GetPolicyPathByAuthorityId) } } diff --git a/server/router/system/sys_dictionary.go b/server/router/system/sys_dictionary.go index 917ff58e9ab098e80fc56a0530313fc8c8de4b1a..d2a9b9a2a869f1d40e583bf9a39c171c76fd5d6e 100644 --- a/server/router/system/sys_dictionary.go +++ b/server/router/system/sys_dictionary.go @@ -6,13 +6,17 @@ import ( "github.com/gin-gonic/gin" ) -func (s *Router) InitSysDictionaryRouter(Router *gin.RouterGroup) { - SysDictionaryRouter := Router.Group("sysDictionary").Use(middleware.OperationRecord()) +type DictionaryRouter struct { +} + +func (s *DictionaryRouter) InitSysDictionaryRouter(Router *gin.RouterGroup) { + sysDictionaryRouter := Router.Group("sysDictionary").Use(middleware.OperationRecord()) + var sysDictionaryApi = v1.ApiGroupApp.SystemApiGroup.DictionaryApi { - SysDictionaryRouter.POST("createSysDictionary", v1.CreateSysDictionary) // 新建SysDictionary - SysDictionaryRouter.DELETE("deleteSysDictionary", v1.DeleteSysDictionary) // 删除SysDictionary - SysDictionaryRouter.PUT("updateSysDictionary", v1.UpdateSysDictionary) // 更新SysDictionary - SysDictionaryRouter.GET("findSysDictionary", v1.FindSysDictionary) // 根据ID获取SysDictionary - SysDictionaryRouter.GET("getSysDictionaryList", v1.GetSysDictionaryList) // 获取SysDictionary列表 + sysDictionaryRouter.POST("createSysDictionary", sysDictionaryApi.CreateSysDictionary) // 新建SysDictionary + sysDictionaryRouter.DELETE("deleteSysDictionary", sysDictionaryApi.DeleteSysDictionary) // 删除SysDictionary + sysDictionaryRouter.PUT("updateSysDictionary", sysDictionaryApi.UpdateSysDictionary) // 更新SysDictionary + sysDictionaryRouter.GET("findSysDictionary", sysDictionaryApi.FindSysDictionary) // 根据ID获取SysDictionary + sysDictionaryRouter.GET("getSysDictionaryList", sysDictionaryApi.GetSysDictionaryList) // 获取SysDictionary列表 } } diff --git a/server/router/system/sys_dictionary_detail.go b/server/router/system/sys_dictionary_detail.go index a61f58764f9dfdf4a922685bd5fc813be6bf2731..9814a1e07dfa466fde43aecdd3ee94ffe4e4ec0d 100644 --- a/server/router/system/sys_dictionary_detail.go +++ b/server/router/system/sys_dictionary_detail.go @@ -6,13 +6,17 @@ import ( "github.com/gin-gonic/gin" ) -func (s *Router) InitSysDictionaryDetailRouter(Router *gin.RouterGroup) { - SysDictionaryDetailRouter := Router.Group("sysDictionaryDetail").Use(middleware.OperationRecord()) +type DictionaryDetailRouter struct { +} + +func (s *DictionaryDetailRouter) InitSysDictionaryDetailRouter(Router *gin.RouterGroup) { + dictionaryDetailRouter := Router.Group("sysDictionaryDetail").Use(middleware.OperationRecord()) + var sysDictionaryDetailApi = v1.ApiGroupApp.SystemApiGroup.DictionaryDetailApi { - SysDictionaryDetailRouter.POST("createSysDictionaryDetail", v1.CreateSysDictionaryDetail) // 新建SysDictionaryDetail - SysDictionaryDetailRouter.DELETE("deleteSysDictionaryDetail", v1.DeleteSysDictionaryDetail) // 删除SysDictionaryDetail - SysDictionaryDetailRouter.PUT("updateSysDictionaryDetail", v1.UpdateSysDictionaryDetail) // 更新SysDictionaryDetail - SysDictionaryDetailRouter.GET("findSysDictionaryDetail", v1.FindSysDictionaryDetail) // 根据ID获取SysDictionaryDetail - SysDictionaryDetailRouter.GET("getSysDictionaryDetailList", v1.GetSysDictionaryDetailList) // 获取SysDictionaryDetail列表 + dictionaryDetailRouter.POST("createSysDictionaryDetail", sysDictionaryDetailApi.CreateSysDictionaryDetail) // 新建SysDictionaryDetail + dictionaryDetailRouter.DELETE("deleteSysDictionaryDetail", sysDictionaryDetailApi.DeleteSysDictionaryDetail) // 删除SysDictionaryDetail + dictionaryDetailRouter.PUT("updateSysDictionaryDetail", sysDictionaryDetailApi.UpdateSysDictionaryDetail) // 更新SysDictionaryDetail + dictionaryDetailRouter.GET("findSysDictionaryDetail", sysDictionaryDetailApi.FindSysDictionaryDetail) // 根据ID获取SysDictionaryDetail + dictionaryDetailRouter.GET("getSysDictionaryDetailList", sysDictionaryDetailApi.GetSysDictionaryDetailList) // 获取SysDictionaryDetail列表 } } diff --git a/server/router/system/sys_email.go b/server/router/system/sys_email.go index be739a10746673e45828d5461d70e888f0ee2981..c43a8d7cb292e11584accc8e603b30a12c612155 100644 --- a/server/router/system/sys_email.go +++ b/server/router/system/sys_email.go @@ -6,9 +6,13 @@ import ( "github.com/gin-gonic/gin" ) -func (s *Router) InitEmailRouter(Router *gin.RouterGroup) { - EmailRouter := Router.Group("email").Use(middleware.OperationRecord()) +type EmailRouter struct { +} + +func (s *EmailRouter) InitEmailRouter(Router *gin.RouterGroup) { + emailRouter := Router.Group("email").Use(middleware.OperationRecord()) + var systemApi = v1.ApiGroupApp.SystemApiGroup.SystemApi { - EmailRouter.POST("emailTest", v1.EmailTest) // 发送测试邮件 + emailRouter.POST("emailTest", systemApi.EmailTest) // 发送测试邮件 } } diff --git a/server/router/system/sys_initdb.go b/server/router/system/sys_initdb.go index 649698f2f16ae29abe513adba1d1208da0c6cb97..8572555747c539d4734465f55c339ce95667bd1b 100644 --- a/server/router/system/sys_initdb.go +++ b/server/router/system/sys_initdb.go @@ -5,10 +5,14 @@ import ( "github.com/gin-gonic/gin" ) -func (s *Router) InitInitRouter(Router *gin.RouterGroup) { - InitRouter := Router.Group("init") +type InitRouter struct { +} + +func (s *InitRouter) InitInitRouter(Router *gin.RouterGroup) { + initRouter := Router.Group("init") + var dbApi = v1.ApiGroupApp.SystemApiGroup.DBApi { - InitRouter.POST("initdb", v1.InitDB) // 创建Api - InitRouter.POST("checkdb", v1.CheckDB) // 创建Api + initRouter.POST("initdb", dbApi.InitDB) // 创建Api + initRouter.POST("checkdb", dbApi.CheckDB) // 创建Api } } diff --git a/server/router/system/sys_jwt.go b/server/router/system/sys_jwt.go index 3eed1abcc52815e9bcc9f6fdb013552cc81f9fdf..77f1bc569805c09fedc9eb827c8662060b71d14d 100644 --- a/server/router/system/sys_jwt.go +++ b/server/router/system/sys_jwt.go @@ -6,9 +6,13 @@ import ( "github.com/gin-gonic/gin" ) -func (s *Router) InitJwtRouter(Router *gin.RouterGroup) { - JwtRouter := Router.Group("jwt").Use(middleware.OperationRecord()) +type JwtRouter struct { +} + +func (s *JwtRouter) InitJwtRouter(Router *gin.RouterGroup) { + jwtRouter := Router.Group("jwt").Use(middleware.OperationRecord()) + var jwtApi = v1.ApiGroupApp.SystemApiGroup.JwtApi { - JwtRouter.POST("jsonInBlacklist", v1.JsonInBlacklist) // jwt加入黑名单 + jwtRouter.POST("jsonInBlacklist", jwtApi.JsonInBlacklist) // jwt加入黑名单 } } diff --git a/server/router/system/sys_menu.go b/server/router/system/sys_menu.go index 336d8986e5af302692bb68c0f01a049807142147..fa86a06ec83d9b41d7787ae99a3cab37dbf17e52 100644 --- a/server/router/system/sys_menu.go +++ b/server/router/system/sys_menu.go @@ -6,18 +6,22 @@ import ( "github.com/gin-gonic/gin" ) -func (s *Router) InitMenuRouter(Router *gin.RouterGroup) (R gin.IRoutes) { - MenuRouter := Router.Group("menu").Use(middleware.OperationRecord()) +type MenuRouter struct { +} + +func (s *MenuRouter) InitMenuRouter(Router *gin.RouterGroup) (R gin.IRoutes) { + menuRouter := Router.Group("menu").Use(middleware.OperationRecord()) + var authorityMenuApi = v1.ApiGroupApp.SystemApiGroup.AuthorityMenuApi { - MenuRouter.POST("getMenu", v1.GetMenu) // 获取菜单树 - MenuRouter.POST("getMenuList", v1.GetMenuList) // 分页获取基础menu列表 - MenuRouter.POST("addBaseMenu", v1.AddBaseMenu) // 新增菜单 - MenuRouter.POST("getBaseMenuTree", v1.GetBaseMenuTree) // 获取用户动态路由 - MenuRouter.POST("addMenuAuthority", v1.AddMenuAuthority) // 增加menu和角色关联关系 - MenuRouter.POST("getMenuAuthority", v1.GetMenuAuthority) // 获取指定角色menu - MenuRouter.POST("deleteBaseMenu", v1.DeleteBaseMenu) // 删除菜单 - MenuRouter.POST("updateBaseMenu", v1.UpdateBaseMenu) // 更新菜单 - MenuRouter.POST("getBaseMenuById", v1.GetBaseMenuById) // 根据id获取菜单 + menuRouter.POST("getMenu", authorityMenuApi.GetMenu) // 获取菜单树 + menuRouter.POST("getMenuList", authorityMenuApi.GetMenuList) // 分页获取基础menu列表 + menuRouter.POST("addBaseMenu", authorityMenuApi.AddBaseMenu) // 新增菜单 + menuRouter.POST("getBaseMenuTree", authorityMenuApi.GetBaseMenuTree) // 获取用户动态路由 + menuRouter.POST("addMenuAuthority", authorityMenuApi.AddMenuAuthority) // 增加menu和角色关联关系 + menuRouter.POST("getMenuAuthority", authorityMenuApi.GetMenuAuthority) // 获取指定角色menu + menuRouter.POST("deleteBaseMenu", authorityMenuApi.DeleteBaseMenu) // 删除菜单 + menuRouter.POST("updateBaseMenu", authorityMenuApi.UpdateBaseMenu) // 更新菜单 + menuRouter.POST("getBaseMenuById", authorityMenuApi.GetBaseMenuById) // 根据id获取菜单 } - return MenuRouter + return menuRouter } diff --git a/server/router/system/sys_operation_record.go b/server/router/system/sys_operation_record.go index 3cded63be68974044f69995218b9edc42ccd4cc0..7d490113ae92fd10631854f1ab1e267ab49824ec 100644 --- a/server/router/system/sys_operation_record.go +++ b/server/router/system/sys_operation_record.go @@ -6,14 +6,18 @@ import ( "github.com/gin-gonic/gin" ) -func (s *Router) InitSysOperationRecordRouter(Router *gin.RouterGroup) { - SysOperationRecordRouter := Router.Group("sysOperationRecord").Use(middleware.OperationRecord()) +type OperationRecordRouter struct { +} + +func (s *OperationRecordRouter) InitSysOperationRecordRouter(Router *gin.RouterGroup) { + operationRecordRouter := Router.Group("sysOperationRecord").Use(middleware.OperationRecord()) + var authorityMenuApi = v1.ApiGroupApp.SystemApiGroup.OperationRecordApi { - SysOperationRecordRouter.POST("createSysOperationRecord", v1.CreateSysOperationRecord) // 新建SysOperationRecord - SysOperationRecordRouter.DELETE("deleteSysOperationRecord", v1.DeleteSysOperationRecord) // 删除SysOperationRecord - SysOperationRecordRouter.DELETE("deleteSysOperationRecordByIds", v1.DeleteSysOperationRecordByIds) // 批量删除SysOperationRecord - SysOperationRecordRouter.GET("findSysOperationRecord", v1.FindSysOperationRecord) // 根据ID获取SysOperationRecord - SysOperationRecordRouter.GET("getSysOperationRecordList", v1.GetSysOperationRecordList) // 获取SysOperationRecord列表 + operationRecordRouter.POST("createSysOperationRecord", authorityMenuApi.CreateSysOperationRecord) // 新建SysOperationRecord + operationRecordRouter.DELETE("deleteSysOperationRecord", authorityMenuApi.DeleteSysOperationRecord) // 删除SysOperationRecord + operationRecordRouter.DELETE("deleteSysOperationRecordByIds", authorityMenuApi.DeleteSysOperationRecordByIds) // 批量删除SysOperationRecord + operationRecordRouter.GET("findSysOperationRecord", authorityMenuApi.FindSysOperationRecord) // 根据ID获取SysOperationRecord + operationRecordRouter.GET("getSysOperationRecordList", authorityMenuApi.GetSysOperationRecordList) // 获取SysOperationRecord列表 } } diff --git a/server/router/system/sys_system.go b/server/router/system/sys_system.go index ab5de9fe48a7d715f298d6eb63df835256ecd97b..91c0f1d5081a65d7375aabaf2666f3fa1641e480 100644 --- a/server/router/system/sys_system.go +++ b/server/router/system/sys_system.go @@ -6,12 +6,16 @@ import ( "github.com/gin-gonic/gin" ) -func (s *Router) InitSystemRouter(Router *gin.RouterGroup) { - SystemRouter := Router.Group("system").Use(middleware.OperationRecord()) +type SysRouter struct { +} + +func (s *SysRouter) InitSystemRouter(Router *gin.RouterGroup) { + sysRouter := Router.Group("system").Use(middleware.OperationRecord()) + var systemApi = v1.ApiGroupApp.SystemApiGroup.SystemApi { - SystemRouter.POST("getSystemConfig", v1.GetSystemConfig) // 获取配置文件内容 - SystemRouter.POST("setSystemConfig", v1.SetSystemConfig) // 设置配置文件内容 - SystemRouter.POST("getServerInfo", v1.GetServerInfo) // 获取服务器信息 - SystemRouter.POST("reloadSystem", v1.ReloadSystem) // 重启服务 + sysRouter.POST("getSystemConfig", systemApi.GetSystemConfig) // 获取配置文件内容 + sysRouter.POST("setSystemConfig", systemApi.SetSystemConfig) // 设置配置文件内容 + sysRouter.POST("getServerInfo", systemApi.GetServerInfo) // 获取服务器信息 + sysRouter.POST("reloadSystem", systemApi.ReloadSystem) // 重启服务 } } diff --git a/server/router/system/sys_user.go b/server/router/system/sys_user.go index 2324e788a42bc67259f0b23ef82d87c565990ef4..24aef1436c8790d87363133a96e67e84262625af 100644 --- a/server/router/system/sys_user.go +++ b/server/router/system/sys_user.go @@ -6,14 +6,18 @@ import ( "github.com/gin-gonic/gin" ) -func (s *Router) InitUserRouter(Router *gin.RouterGroup) { - UserRouter := Router.Group("user").Use(middleware.OperationRecord()) +type UserRouter struct { +} + +func (s *UserRouter) InitUserRouter(Router *gin.RouterGroup) { + userRouter := Router.Group("user").Use(middleware.OperationRecord()) + var baseApi = v1.ApiGroupApp.SystemApiGroup.BaseApi { - UserRouter.POST("register", v1.Register) // 用户注册账号 - UserRouter.POST("changePassword", v1.ChangePassword) // 用户修改密码 - UserRouter.POST("getUserList", v1.GetUserList) // 分页获取用户列表 - UserRouter.POST("setUserAuthority", v1.SetUserAuthority) // 设置用户权限 - UserRouter.DELETE("deleteUser", v1.DeleteUser) // 删除用户 - UserRouter.PUT("setUserInfo", v1.SetUserInfo) // 设置用户信息 + userRouter.POST("register", baseApi.Register) // 用户注册账号 + userRouter.POST("changePassword", baseApi.ChangePassword) // 用户修改密码 + userRouter.POST("getUserList", baseApi.GetUserList) // 分页获取用户列表 + userRouter.POST("setUserAuthority", baseApi.SetUserAuthority) // 设置用户权限 + userRouter.DELETE("deleteUser", baseApi.DeleteUser) // 删除用户 + userRouter.PUT("setUserInfo", baseApi.SetUserInfo) // 设置用户信息 } } diff --git a/server/service/autocode/autocodeExample.go b/server/service/autocode/autocodeExample.go new file mode 100644 index 0000000000000000000000000000000000000000..0a67873b86a2adc4bc0bc6a97bfb743082bcefbe --- /dev/null +++ b/server/service/autocode/autocodeExample.go @@ -0,0 +1,76 @@ +package autocode + +import ( + "gin-vue-admin/global" + "gin-vue-admin/model/autocode" + "gin-vue-admin/model/autocode/requset" +) + +type AutoCodeExampleService struct { +} + +//@author: [piexlmax](https://github.com/piexlmax) +//@function: CreateAutoCodeExample +//@description: 创建自动化示例数据 +//@param: autoCodeExampleService *AutoCodeExampleService +//@return: err error + +func (autoCodeExampleService *AutoCodeExampleService) CreateAutoCodeExample(autoCodeExample autocode.AutoCodeExample) (err error) { + + err = global.GVA_DB.Create(&autoCodeExample).Error + return err +} + +//@author: [piexlmax](https://github.com/piexlmax) +//@function: DeleteAutoCodeExample +//@description: 删除自动化示例数据 +//@param: autoCodeExample autocode.AutoCodeExample +//@return: err error + +func (autoCodeExampleService *AutoCodeExampleService) DeleteAutoCodeExample(autoCodeExample autocode.AutoCodeExample) (err error) { + err = global.GVA_DB.Delete(&autoCodeExample).Error + return err +} + +//@author: [piexlmax](https://github.com/piexlmax) +//@function: UpdateAutoCodeExample +//@description: 更新自动化示例数据 +//@param: autoCodeExample *autocode.AutoCodeExample +//@return: err error + +func (autoCodeExampleService *AutoCodeExampleService) UpdateAutoCodeExample(autoCodeExample *autocode.AutoCodeExample) (err error) { + err = global.GVA_DB.Save(autoCodeExample).Error + return err +} + +//@author: [piexlmax](https://github.com/piexlmax) +//@function: GetAutoCodeExampleDetail +//@description: 根据id获取自动化示例数据 +//@param: id uint +//@return: err error, autoCodeExample autocode.AutoCodeExample + +func (autoCodeExampleService *AutoCodeExampleService) GetAutoCodeExample(id uint) (err error, autoCodeExample autocode.AutoCodeExample) { + err = global.GVA_DB.Where("id = ?", id).First(&autoCodeExample).Error + return +} + +//@author: [piexlmax](https://github.com/piexlmax) +//@function: GetAutoCodeExampleInfoList +//@description: 分页获取自动化示例数据 +//@param: info request.AutoCodeExampleSearch +//@return: err error, list interface{}, total int64 + +func (autoCodeExampleService *AutoCodeExampleService) GetAutoCodeExampleInfoList(info request.AutoCodeExampleSearch) (err error, list interface{}, total int64) { + limit := info.PageSize + offset := info.PageSize * (info.Page - 1) + // 创建db + db := global.GVA_DB.Model(&autocode.AutoCodeExample{}) + var autoCodeExamples []autocode.AutoCodeExample + // 如果有条件搜索 下方会自动创建搜索语句 + if info.AutoCodeExampleField != "" { + db = db.Where("label LIKE ?", "%"+info.AutoCodeExampleField+"%") + } + err = db.Count(&total).Error + err = db.Limit(limit).Offset(offset).Find(&autoCodeExamples).Error + return err, autoCodeExamples, total +} diff --git a/server/service/autocode/enter.go b/server/service/autocode/enter.go new file mode 100644 index 0000000000000000000000000000000000000000..72d18873a86768b5fc9a5078edb5b5df53dad59b --- /dev/null +++ b/server/service/autocode/enter.go @@ -0,0 +1,5 @@ +package autocode + +type ServiceGroup struct { + AutoCodeExampleService +} diff --git a/server/service/enter.go b/server/service/enter.go new file mode 100644 index 0000000000000000000000000000000000000000..db0514ad7e46260b96b8c3252f55b14f7189b386 --- /dev/null +++ b/server/service/enter.go @@ -0,0 +1,15 @@ +package service + +import ( + "gin-vue-admin/service/autocode" + "gin-vue-admin/service/example" + "gin-vue-admin/service/system" +) + +type ServiceGroup struct { + ExampleServiceGroup example.ServiceGroup + SystemServiceGroup system.ServiceGroup + AutoCodeServiceGroup autocode.ServiceGroup +} + +var ServiceGroupApp = new(ServiceGroup) diff --git a/server/service/example/enter.go b/server/service/example/enter.go new file mode 100644 index 0000000000000000000000000000000000000000..113677d9d141ac292f811f0080f5c2cd495a7566 --- /dev/null +++ b/server/service/example/enter.go @@ -0,0 +1,8 @@ +package example + +type ServiceGroup struct { + FileUploadAndDownloadService + CustomerService + ExcelService + SimpleUploaderService +} diff --git a/server/service/exa_breakpoint_continue.go b/server/service/example/exa_breakpoint_continue.go similarity index 80% rename from server/service/exa_breakpoint_continue.go rename to server/service/example/exa_breakpoint_continue.go index 08326a364c15fd9b0cce65ae5f54d4667c538f01..f931e28de7b5913734a4d3120f5a5094736f8719 100644 --- a/server/service/exa_breakpoint_continue.go +++ b/server/service/example/exa_breakpoint_continue.go @@ -1,4 +1,4 @@ -package service +package example import ( "errors" @@ -7,13 +7,16 @@ import ( "gorm.io/gorm" ) +type FileUploadAndDownloadService struct { +} + //@author: [piexlmax](https://github.com/piexlmax) //@function: FindOrCreateFile //@description: 上传文件时检测当前文件属性,如果没有文件则创建,有则返回文件的当前切片 //@param: fileMd5 string, fileName string, chunkTotal int //@return: err error, file model.ExaFile -func FindOrCreateFile(fileMd5 string, fileName string, chunkTotal int) (err error, file example.ExaFile) { +func (e *FileUploadAndDownloadService) FindOrCreateFile(fileMd5 string, fileName string, chunkTotal int) (err error, file example.ExaFile) { var cfile example.ExaFile cfile.FileMd5 = fileMd5 cfile.FileName = fileName @@ -35,7 +38,7 @@ func FindOrCreateFile(fileMd5 string, fileName string, chunkTotal int) (err erro //@param: id uint, fileChunkPath string, fileChunkNumber int //@return: error -func CreateFileChunk(id uint, fileChunkPath string, fileChunkNumber int) error { +func (e *FileUploadAndDownloadService) CreateFileChunk(id uint, fileChunkPath string, fileChunkNumber int) error { var chunk example.ExaFileChunk chunk.FileChunkPath = fileChunkPath chunk.ExaFileID = id @@ -50,7 +53,7 @@ func CreateFileChunk(id uint, fileChunkPath string, fileChunkNumber int) error { //@param: fileMd5 string, fileName string, filePath string //@return: error -func DeleteFileChunk(fileMd5 string, fileName string, filePath string) error { +func (e *FileUploadAndDownloadService) DeleteFileChunk(fileMd5 string, fileName string, filePath string) error { var chunks []example.ExaFileChunk var file example.ExaFile err := global.GVA_DB.Where("file_md5 = ? AND file_name = ?", fileMd5, fileName).First(&file).Update("IsFinish", true).Update("file_path", filePath).Error diff --git a/server/service/exa_customer.go b/server/service/example/exa_customer.go similarity index 72% rename from server/service/exa_customer.go rename to server/service/example/exa_customer.go index b33477f21b9ee7db753ad47f8ee4159fc0488d64..d450582b75bd29409d8e26315271325d5c86e279 100644 --- a/server/service/exa_customer.go +++ b/server/service/example/exa_customer.go @@ -1,19 +1,23 @@ -package service +package example import ( "gin-vue-admin/global" + "gin-vue-admin/model/common/request" "gin-vue-admin/model/example" - "gin-vue-admin/model/example/request" "gin-vue-admin/model/system" + systemService "gin-vue-admin/service/system" ) +type CustomerService struct { +} + //@author: [piexlmax](https://github.com/piexlmax) //@function: CreateExaCustomer //@description: 创建客户 //@param: e model.ExaCustomer //@return: err error -func CreateExaCustomer(e example.ExaCustomer) (err error) { +func (exa *CustomerService) CreateExaCustomer(e example.ExaCustomer) (err error) { err = global.GVA_DB.Create(&e).Error return err } @@ -24,7 +28,7 @@ func CreateExaCustomer(e example.ExaCustomer) (err error) { //@param: e model.ExaCustomer //@return: err error -func DeleteExaCustomer(e example.ExaCustomer) (err error) { +func (exa *CustomerService) DeleteExaCustomer(e example.ExaCustomer) (err error) { err = global.GVA_DB.Delete(&e).Error return err } @@ -35,7 +39,7 @@ func DeleteExaCustomer(e example.ExaCustomer) (err error) { //@param: e *model.ExaCustomer //@return: err error -func UpdateExaCustomer(e *example.ExaCustomer) (err error) { +func (exa *CustomerService) UpdateExaCustomer(e *example.ExaCustomer) (err error) { err = global.GVA_DB.Save(e).Error return err } @@ -46,7 +50,7 @@ func UpdateExaCustomer(e *example.ExaCustomer) (err error) { //@param: id uint //@return: err error, customer model.ExaCustomer -func GetExaCustomer(id uint) (err error, customer example.ExaCustomer) { +func (exa *CustomerService) GetExaCustomer(id uint) (err error, customer example.ExaCustomer) { err = global.GVA_DB.Where("id = ?", id).First(&customer).Error return } @@ -57,13 +61,13 @@ func GetExaCustomer(id uint) (err error, customer example.ExaCustomer) { //@param: sysUserAuthorityID string, info request.PageInfo //@return: err error, list interface{}, total int64 -func GetCustomerInfoList(sysUserAuthorityID string, info request.PageInfo) (err error, list interface{}, total int64) { +func (exa *CustomerService) GetCustomerInfoList(sysUserAuthorityID string, info request.PageInfo) (err error, list interface{}, total int64) { limit := info.PageSize offset := info.PageSize * (info.Page - 1) db := global.GVA_DB.Model(&example.ExaCustomer{}) var a system.SysAuthority a.AuthorityId = sysUserAuthorityID - err, auth := GetAuthorityInfo(a) + err, auth := systemService.AuthorityServiceApp.GetAuthorityInfo(a) var dataId []string for _, v := range auth.DataAuthorityId { dataId = append(dataId, v.AuthorityId) diff --git a/server/service/exa_excel_parse.go b/server/service/example/exa_excel_parse.go similarity index 84% rename from server/service/exa_excel_parse.go rename to server/service/example/exa_excel_parse.go index 2fcbad62ec8a263f143d6e1cd732f93e515e179f..fa88ecbfff569931111c8a9c22339c08162f00ad 100644 --- a/server/service/exa_excel_parse.go +++ b/server/service/example/exa_excel_parse.go @@ -1,4 +1,4 @@ -package service +package example import ( "errors" @@ -9,7 +9,10 @@ import ( "strconv" ) -func ParseInfoList2Excel(infoList []system.SysBaseMenu, filePath string) error { +type ExcelService struct { +} + +func (exa *ExcelService) ParseInfoList2Excel(infoList []system.SysBaseMenu, filePath string) error { excel := excelize.NewFile() excel.SetSheetRow("Sheet1", "A1", &[]string{"ID", "路由Name", "路由Path", "是否隐藏", "父节点", "排序", "文件名称"}) for i, menu := range infoList { @@ -28,7 +31,7 @@ func ParseInfoList2Excel(infoList []system.SysBaseMenu, filePath string) error { return err } -func ParseExcel2InfoList() ([]system.SysBaseMenu, error) { +func (exa *ExcelService) ParseExcel2InfoList() ([]system.SysBaseMenu, error) { skipHeader := true fixedHeader := []string{"ID", "路由Name", "路由Path", "是否隐藏", "父节点", "排序", "文件名称"} file, err := excelize.OpenFile(global.GVA_CONFIG.Excel.Dir + "ExcelImport.xlsx") @@ -46,7 +49,7 @@ func ParseExcel2InfoList() ([]system.SysBaseMenu, error) { return nil, err } if skipHeader { - if compareStrSlice(row, fixedHeader) { + if exa.compareStrSlice(row, fixedHeader) { skipHeader = false continue } else { @@ -75,7 +78,7 @@ func ParseExcel2InfoList() ([]system.SysBaseMenu, error) { return menus, nil } -func compareStrSlice(a, b []string) bool { +func (exa *ExcelService) compareStrSlice(a, b []string) bool { if len(a) != len(b) { return false } diff --git a/server/service/exa_file_upload_download.go b/server/service/example/exa_file_upload_download.go similarity index 75% rename from server/service/exa_file_upload_download.go rename to server/service/example/exa_file_upload_download.go index 262540862c1f82aec0cffc7dea8fef56dc951e16..58703ed6291478e7a579c4db233791035ad1f535 100644 --- a/server/service/exa_file_upload_download.go +++ b/server/service/example/exa_file_upload_download.go @@ -1,10 +1,10 @@ -package service +package example import ( "errors" "gin-vue-admin/global" + "gin-vue-admin/model/common/request" "gin-vue-admin/model/example" - "gin-vue-admin/model/example/request" "gin-vue-admin/utils/upload" "mime/multipart" "strings" @@ -16,7 +16,7 @@ import ( //@param: file model.ExaFileUploadAndDownload //@return: error -func Upload(file example.ExaFileUploadAndDownload) error { +func (e *FileUploadAndDownloadService) Upload(file example.ExaFileUploadAndDownload) error { return global.GVA_DB.Create(&file).Error } @@ -26,7 +26,7 @@ func Upload(file example.ExaFileUploadAndDownload) error { //@param: id uint //@return: error, model.ExaFileUploadAndDownload -func FindFile(id uint) (error, example.ExaFileUploadAndDownload) { +func (e *FileUploadAndDownloadService) FindFile(id uint) (error, example.ExaFileUploadAndDownload) { var file example.ExaFileUploadAndDownload err := global.GVA_DB.Where("id = ?", id).First(&file).Error return err, file @@ -38,9 +38,9 @@ func FindFile(id uint) (error, example.ExaFileUploadAndDownload) { //@param: file model.ExaFileUploadAndDownload //@return: err error -func DeleteFile(file example.ExaFileUploadAndDownload) (err error) { +func (e *FileUploadAndDownloadService) DeleteFile(file example.ExaFileUploadAndDownload) (err error) { var fileFromDb example.ExaFileUploadAndDownload - err, fileFromDb = FindFile(file.ID) + err, fileFromDb = e.FindFile(file.ID) oss := upload.NewOss() if err = oss.DeleteFile(fileFromDb.Key); err != nil { return errors.New("文件删除失败") @@ -52,10 +52,10 @@ func DeleteFile(file example.ExaFileUploadAndDownload) (err error) { //@author: [piexlmax](https://github.com/piexlmax) //@function: GetFileRecordInfoList //@description: 分页获取数据 -//@param: info request.PageInfo +//@param: info requset.PageInfo //@return: err error, list interface{}, total int64 -func GetFileRecordInfoList(info request.PageInfo) (err error, list interface{}, total int64) { +func (e *FileUploadAndDownloadService) GetFileRecordInfoList(info request.PageInfo) (err error, list interface{}, total int64) { limit := info.PageSize offset := info.PageSize * (info.Page - 1) db := global.GVA_DB @@ -71,7 +71,7 @@ func GetFileRecordInfoList(info request.PageInfo) (err error, list interface{}, //@param: header *multipart.FileHeader, noSave string //@return: err error, file model.ExaFileUploadAndDownload -func UploadFile(header *multipart.FileHeader, noSave string) (err error, file example.ExaFileUploadAndDownload) { +func (e *FileUploadAndDownloadService) UploadFile(header *multipart.FileHeader, noSave string) (err error, file example.ExaFileUploadAndDownload) { oss := upload.NewOss() filePath, key, uploadErr := oss.UploadFile(header) if uploadErr != nil { @@ -85,7 +85,7 @@ func UploadFile(header *multipart.FileHeader, noSave string) (err error, file ex Tag: s[len(s)-1], Key: key, } - return Upload(f), f + return e.Upload(f), f } return } diff --git a/server/service/exa_simple_uploader.go b/server/service/example/exa_simple_uploader.go similarity index 86% rename from server/service/exa_simple_uploader.go rename to server/service/example/exa_simple_uploader.go index 99fbf50ea1ba8b36941792f7d901dc92dfacfe45..d28ff285cd68eb19ed3aa57d981a5be73c9d7d17 100644 --- a/server/service/exa_simple_uploader.go +++ b/server/service/example/exa_simple_uploader.go @@ -1,4 +1,4 @@ -package service +package example import ( "errors" @@ -11,13 +11,16 @@ import ( "strconv" ) +type SimpleUploaderService struct { +} + //@author: [piexlmax](https://github.com/piexlmax) //@function: SaveChunk //@description: 保存文件切片路径 //@param: uploader model.ExaSimpleUploader //@return: err error -func SaveChunk(uploader example.ExaSimpleUploader) (err error) { +func (exa *SimpleUploaderService) SaveChunk(uploader example.ExaSimpleUploader) (err error) { return global.GVA_DB.Create(uploader).Error } @@ -27,7 +30,7 @@ func SaveChunk(uploader example.ExaSimpleUploader) (err error) { //@param: md5 string //@return: err error, uploads []model.ExaSimpleUploader, isDone bool -func CheckFileMd5(md5 string) (err error, uploads []example.ExaSimpleUploader, isDone bool) { +func (exa *SimpleUploaderService) CheckFileMd5(md5 string) (err error, uploads []example.ExaSimpleUploader, isDone bool) { err = global.GVA_DB.Find(&uploads, "identifier = ? AND is_done = ?", md5, false).Error isDone = errors.Is(global.GVA_DB.First(&example.ExaSimpleUploader{}, "identifier = ? AND is_done = ?", md5, true).Error, gorm.ErrRecordNotFound) return err, uploads, !isDone @@ -39,7 +42,7 @@ func CheckFileMd5(md5 string) (err error, uploads []example.ExaSimpleUploader, i //@param: md5 string, fileName string //@return: err error -func MergeFileMd5(md5 string, fileName string) (err error) { +func (exa *SimpleUploaderService) MergeFileMd5(md5 string, fileName string) (err error) { finishDir := "./finish/" dir := "./chunk/" + md5 // 如果文件上传成功 不做后续操作 通知成功即可 diff --git a/server/service/system/enter.go b/server/service/system/enter.go new file mode 100644 index 0000000000000000000000000000000000000000..028f392c904cd368c4370dd9c58e4840357551ae --- /dev/null +++ b/server/service/system/enter.go @@ -0,0 +1,19 @@ +package system + +type ServiceGroup struct { + JwtService + ApiService + AuthorityService + AutoCodeService + AutoCodeHistoryService + BaseMenuService + CasbinService + DictionaryService + DictionaryDetailService + EmailService + InitDBService + MenuService + OperationRecordService + SystemConfigService + UserService +} diff --git a/server/service/jwt_black_list.go b/server/service/system/jwt_black_list.go similarity index 78% rename from server/service/jwt_black_list.go rename to server/service/system/jwt_black_list.go index 9dcdbab7d10eec312363dfd43b5fcadd1896228c..c15c6d381dfd5fa365af557d8d502c07a53650fb 100644 --- a/server/service/jwt_black_list.go +++ b/server/service/system/jwt_black_list.go @@ -1,4 +1,4 @@ -package service +package system import ( "context" @@ -10,13 +10,16 @@ import ( "gorm.io/gorm" ) +type JwtService struct { +} + //@author: [piexlmax](https://github.com/piexlmax) //@function: JsonInBlacklist //@description: 拉黑jwt //@param: jwtList model.JwtBlacklist //@return: err error -func JsonInBlacklist(jwtList system.JwtBlacklist) (err error) { +func (jwtService *JwtService) JsonInBlacklist(jwtList system.JwtBlacklist) (err error) { err = global.GVA_DB.Create(&jwtList).Error return } @@ -27,7 +30,7 @@ func JsonInBlacklist(jwtList system.JwtBlacklist) (err error) { //@param: jwt string //@return: bool -func IsBlacklist(jwt string) bool { +func (jwtService *JwtService) IsBlacklist(jwt string) bool { err := global.GVA_DB.Where("jwt = ?", jwt).First(&system.JwtBlacklist{}).Error isNotFound := errors.Is(err, gorm.ErrRecordNotFound) return !isNotFound @@ -39,7 +42,7 @@ func IsBlacklist(jwt string) bool { //@param: userName string //@return: err error, redisJWT string -func GetRedisJWT(userName string) (err error, redisJWT string) { +func (jwtService *JwtService) GetRedisJWT(userName string) (err error, redisJWT string) { redisJWT, err = global.GVA_REDIS.Get(context.Background(), userName).Result() return err, redisJWT } @@ -50,7 +53,7 @@ func GetRedisJWT(userName string) (err error, redisJWT string) { //@param: jwt string, userName string //@return: err error -func SetRedisJWT(jwt string, userName string) (err error) { +func (jwtService *JwtService) SetRedisJWT(jwt string, userName string) (err error) { // 此处过期时间等于jwt过期时间 timer := time.Duration(global.GVA_CONFIG.JWT.ExpiresTime) * time.Second err = global.GVA_REDIS.Set(context.Background(), userName, jwt, timer).Err() diff --git a/server/service/sys_api.go b/server/service/system/sys_api.go similarity index 76% rename from server/service/sys_api.go rename to server/service/system/sys_api.go index 5ef756ab9b9bfa2a991d9a8a7e31e80c9e862411..d7ec60739b3fbc56fbe0bb3d153aefa558bd6072 100644 --- a/server/service/sys_api.go +++ b/server/service/system/sys_api.go @@ -1,10 +1,10 @@ -package service +package system import ( "errors" "gin-vue-admin/global" + "gin-vue-admin/model/common/request" "gin-vue-admin/model/system" - "gin-vue-admin/model/system/request" "gorm.io/gorm" ) @@ -15,7 +15,12 @@ import ( //@param: api model.SysApi //@return: err error -func CreateApi(api system.SysApi) (err error) { +type ApiService struct { +} + +var ApiServiceApp = new(ApiService) + +func (apiService *ApiService) CreateApi(api system.SysApi) (err error) { if !errors.Is(global.GVA_DB.Where("path = ? AND method = ?", api.Path, api.Method).First(&system.SysApi{}).Error, gorm.ErrRecordNotFound) { return errors.New("存在相同api") } @@ -28,9 +33,9 @@ func CreateApi(api system.SysApi) (err error) { //@param: api model.SysApi //@return: err error -func DeleteApi(api system.SysApi) (err error) { +func (apiService *ApiService) DeleteApi(api system.SysApi) (err error) { err = global.GVA_DB.Delete(&api).Error - ClearCasbin(1, api.Path, api.Method) + CasbinServiceApp.ClearCasbin(1, api.Path, api.Method) return err } @@ -40,7 +45,7 @@ func DeleteApi(api system.SysApi) (err error) { //@param: api model.SysApi, info request.PageInfo, order string, desc bool //@return: err error -func GetAPIInfoList(api system.SysApi, info request.PageInfo, order string, desc bool) (err error, list interface{}, total int64) { +func (apiService *ApiService) GetAPIInfoList(api system.SysApi, info request.PageInfo, order string, desc bool) (err error, list interface{}, total int64) { limit := info.PageSize offset := info.PageSize * (info.Page - 1) db := global.GVA_DB.Model(&system.SysApi{}) @@ -88,7 +93,7 @@ func GetAPIInfoList(api system.SysApi, info request.PageInfo, order string, desc //@description: 获取所有的api //@return: err error, apis []model.SysApi -func GetAllApis() (err error, apis []system.SysApi) { +func (apiService *ApiService) GetAllApis() (err error, apis []system.SysApi) { err = global.GVA_DB.Find(&apis).Error return } @@ -99,7 +104,7 @@ func GetAllApis() (err error, apis []system.SysApi) { //@param: id float64 //@return: err error, api model.SysApi -func GetApiById(id float64) (err error, api system.SysApi) { +func (apiService *ApiService) GetApiById(id float64) (err error, api system.SysApi) { err = global.GVA_DB.Where("id = ?", id).First(&api).Error return } @@ -110,7 +115,7 @@ func GetApiById(id float64) (err error, api system.SysApi) { //@param: api model.SysApi //@return: err error -func UpdateApi(api system.SysApi) (err error) { +func (apiService *ApiService) UpdateApi(api system.SysApi) (err error) { var oldA system.SysApi err = global.GVA_DB.Where("id = ?", api.ID).First(&oldA).Error if oldA.Path != api.Path || oldA.Method != api.Method { @@ -121,7 +126,7 @@ func UpdateApi(api system.SysApi) (err error) { if err != nil { return err } else { - err = UpdateCasbinApi(oldA.Path, api.Path, oldA.Method, api.Method) + err = CasbinServiceApp.UpdateCasbinApi(oldA.Path, api.Path, oldA.Method, api.Method) if err != nil { return err } else { @@ -137,11 +142,11 @@ func UpdateApi(api system.SysApi) (err error) { //@param: apis []model.SysApi //@return: err error -func DeleteApisByIds(ids request.IdsReq) (err error) { +func (apiService *ApiService) DeleteApisByIds(ids request.IdsReq) (err error) { err = global.GVA_DB.Delete(&[]system.SysApi{}, "id in ?", ids.Ids).Error return err } -func DeleteApiByIds(ids []string) (err error) { +func (apiService *ApiService) DeleteApiByIds(ids []string) (err error) { return global.GVA_DB.Delete(system.SysApi{}, ids).Error } diff --git a/server/service/sys_authority.go b/server/service/system/sys_authority.go similarity index 73% rename from server/service/sys_authority.go rename to server/service/system/sys_authority.go index 1b1edbc98ceb5140ef75e10f146e0560f55c3471..33138e1ae612209fcef7849d5e9cc50b3588e85a 100644 --- a/server/service/sys_authority.go +++ b/server/service/system/sys_authority.go @@ -1,10 +1,10 @@ -package service +package system import ( "errors" "gin-vue-admin/global" + "gin-vue-admin/model/common/request" "gin-vue-admin/model/system" - "gin-vue-admin/model/system/request" "gin-vue-admin/model/system/response" "gorm.io/gorm" "strconv" @@ -16,7 +16,12 @@ import ( //@param: auth model.SysAuthority //@return: err error, authority model.SysAuthority -func CreateAuthority(auth system.SysAuthority) (err error, authority system.SysAuthority) { +type AuthorityService struct { +} + +var AuthorityServiceApp = new(AuthorityService) + +func (authorityService *AuthorityService) CreateAuthority(auth system.SysAuthority) (err error, authority system.SysAuthority) { var authorityBox system.SysAuthority if !errors.Is(global.GVA_DB.Where("authority_id = ?", auth.AuthorityId).First(&authorityBox).Error, gorm.ErrRecordNotFound) { return errors.New("存在相同角色id"), auth @@ -31,13 +36,13 @@ func CreateAuthority(auth system.SysAuthority) (err error, authority system.SysA //@param: copyInfo response.SysAuthorityCopyResponse //@return: err error, authority model.SysAuthority -func CopyAuthority(copyInfo response.SysAuthorityCopyResponse) (err error, authority system.SysAuthority) { +func (authorityService *AuthorityService) CopyAuthority(copyInfo response.SysAuthorityCopyResponse) (err error, authority system.SysAuthority) { var authorityBox system.SysAuthority if !errors.Is(global.GVA_DB.Where("authority_id = ?", copyInfo.Authority.AuthorityId).First(&authorityBox).Error, gorm.ErrRecordNotFound) { return errors.New("存在相同角色id"), authority } copyInfo.Authority.Children = []system.SysAuthority{} - err, menus := GetMenuAuthority(&request.GetAuthorityId{AuthorityId: copyInfo.OldAuthorityId}) + err, menus := MenuServiceApp.GetMenuAuthority(&request.GetAuthorityId{AuthorityId: copyInfo.OldAuthorityId}) var baseMenu []system.SysBaseMenu for _, v := range menus { intNum, _ := strconv.Atoi(v.MenuId) @@ -47,10 +52,10 @@ func CopyAuthority(copyInfo response.SysAuthorityCopyResponse) (err error, autho copyInfo.Authority.SysBaseMenus = baseMenu err = global.GVA_DB.Create(©Info.Authority).Error - paths := GetPolicyPathByAuthorityId(copyInfo.OldAuthorityId) - err = UpdateCasbin(copyInfo.Authority.AuthorityId, paths) + paths := CasbinServiceApp.GetPolicyPathByAuthorityId(copyInfo.OldAuthorityId) + err = CasbinServiceApp.UpdateCasbin(copyInfo.Authority.AuthorityId, paths) if err != nil { - _ = DeleteAuthority(©Info.Authority) + _ = authorityService.DeleteAuthority(©Info.Authority) } return err, copyInfo.Authority } @@ -61,7 +66,7 @@ func CopyAuthority(copyInfo response.SysAuthorityCopyResponse) (err error, autho //@param: auth model.SysAuthority //@return: err error, authority model.SysAuthority -func UpdateAuthority(auth system.SysAuthority) (err error, authority system.SysAuthority) { +func (authorityService *AuthorityService) UpdateAuthority(auth system.SysAuthority) (err error, authority system.SysAuthority) { err = global.GVA_DB.Where("authority_id = ?", auth.AuthorityId).First(&system.SysAuthority{}).Updates(&auth).Error return err, auth } @@ -72,7 +77,7 @@ func UpdateAuthority(auth system.SysAuthority) (err error, authority system.SysA //@param: auth *model.SysAuthority //@return: err error -func DeleteAuthority(auth *system.SysAuthority) (err error) { +func (authorityService *AuthorityService) DeleteAuthority(auth *system.SysAuthority) (err error) { if !errors.Is(global.GVA_DB.Where("authority_id = ?", auth.AuthorityId).First(&system.SysUser{}).Error, gorm.ErrRecordNotFound) { return errors.New("此角色有用户正在使用禁止删除") } @@ -87,7 +92,7 @@ func DeleteAuthority(auth *system.SysAuthority) (err error) { } else { err = db.Error } - ClearCasbin(0, auth.AuthorityId) + CasbinServiceApp.ClearCasbin(0, auth.AuthorityId) return err } @@ -97,7 +102,7 @@ func DeleteAuthority(auth *system.SysAuthority) (err error) { //@param: info request.PageInfo //@return: err error, list interface{}, total int64 -func GetAuthorityInfoList(info request.PageInfo) (err error, list interface{}, total int64) { +func (authorityService *AuthorityService) GetAuthorityInfoList(info request.PageInfo) (err error, list interface{}, total int64) { limit := info.PageSize offset := info.PageSize * (info.Page - 1) db := global.GVA_DB @@ -105,7 +110,7 @@ func GetAuthorityInfoList(info request.PageInfo) (err error, list interface{}, t err = db.Limit(limit).Offset(offset).Preload("DataAuthorityId").Where("parent_id = 0").Find(&authority).Error if len(authority) > 0 { for k := range authority { - err = findChildrenAuthority(&authority[k]) + err = authorityService.findChildrenAuthority(&authority[k]) } } return err, authority, total @@ -117,7 +122,7 @@ func GetAuthorityInfoList(info request.PageInfo) (err error, list interface{}, t //@param: auth model.SysAuthority //@return: err error, sa model.SysAuthority -func GetAuthorityInfo(auth system.SysAuthority) (err error, sa system.SysAuthority) { +func (authorityService *AuthorityService) GetAuthorityInfo(auth system.SysAuthority) (err error, sa system.SysAuthority) { err = global.GVA_DB.Preload("DataAuthorityId").Where("authority_id = ?", auth.AuthorityId).First(&sa).Error return err, sa } @@ -128,7 +133,7 @@ func GetAuthorityInfo(auth system.SysAuthority) (err error, sa system.SysAuthori //@param: auth model.SysAuthority //@return: error -func SetDataAuthority(auth system.SysAuthority) error { +func (authorityService *AuthorityService) SetDataAuthority(auth system.SysAuthority) error { var s system.SysAuthority global.GVA_DB.Preload("DataAuthorityId").First(&s, "authority_id = ?", auth.AuthorityId) err := global.GVA_DB.Model(&s).Association("DataAuthorityId").Replace(&auth.DataAuthorityId) @@ -141,7 +146,7 @@ func SetDataAuthority(auth system.SysAuthority) error { //@param: auth *model.SysAuthority //@return: error -func SetMenuAuthority(auth *system.SysAuthority) error { +func (authorityService *AuthorityService) SetMenuAuthority(auth *system.SysAuthority) error { var s system.SysAuthority global.GVA_DB.Preload("SysBaseMenus").First(&s, "authority_id = ?", auth.AuthorityId) err := global.GVA_DB.Model(&s).Association("SysBaseMenus").Replace(&auth.SysBaseMenus) @@ -154,11 +159,11 @@ func SetMenuAuthority(auth *system.SysAuthority) error { //@param: authority *model.SysAuthority //@return: err error -func findChildrenAuthority(authority *system.SysAuthority) (err error) { +func (authorityService *AuthorityService) findChildrenAuthority(authority *system.SysAuthority) (err error) { err = global.GVA_DB.Preload("DataAuthorityId").Where("parent_id = ?", authority.AuthorityId).Find(&authority.Children).Error if len(authority.Children) > 0 { for k := range authority.Children { - err = findChildrenAuthority(&authority.Children[k]) + err = authorityService.findChildrenAuthority(&authority.Children[k]) } } return err diff --git a/server/service/sys_auto_code.go b/server/service/system/sys_auto_code.go similarity index 89% rename from server/service/sys_auto_code.go rename to server/service/system/sys_auto_code.go index 5709d72428f651d47ba16d26f25cec04d39b7161..ee2eb3c706099db8512987ad26d9d492f53173b5 100644 --- a/server/service/sys_auto_code.go +++ b/server/service/system/sys_auto_code.go @@ -1,4 +1,4 @@ -package service +package system import ( "encoding/json" @@ -30,14 +30,19 @@ type tplData struct { autoMoveFilePath string } +type AutoCodeService struct { +} + +var AutoCodeServiceApp = new(AutoCodeService) + //@author: [songzhibin97](https://github.com/songzhibin97) //@function: PreviewTemp //@description: 预览创建代码 //@param: model.AutoCodeStruct //@return: map[string]string, error -func PreviewTemp(autoCode system.AutoCodeStruct) (map[string]string, error) { - dataList, _, needMkdir, err := getNeedList(&autoCode) +func (autoCodeService *AutoCodeService) PreviewTemp(autoCode system.AutoCodeStruct) (map[string]string, error) { + dataList, _, needMkdir, err := autoCodeService.getNeedList(&autoCode) if err != nil { return nil, err } @@ -101,8 +106,8 @@ func PreviewTemp(autoCode system.AutoCodeStruct) (map[string]string, error) { //@param: model.AutoCodeStruct //@return: err error -func CreateTemp(autoCode system.AutoCodeStruct, ids ...uint) (err error) { - dataList, fileList, needMkdir, err := getNeedList(&autoCode) +func (autoCodeService *AutoCodeService) CreateTemp(autoCode system.AutoCodeStruct, ids ...uint) (err error) { + dataList, fileList, needMkdir, err := autoCodeService.getNeedList(&autoCode) if err != nil { return err } @@ -137,8 +142,8 @@ func CreateTemp(autoCode system.AutoCodeStruct, ids ...uint) (err error) { idBf.WriteString(";") } if autoCode.AutoMoveFile { // 判断是否需要自动转移 - for index, _ := range dataList { - addAutoMoveFile(&dataList[index]) + for index := range dataList { + autoCodeService.addAutoMoveFile(&dataList[index]) } for _, value := range dataList { // 移动文件 if err := utils.FileMove(value.autoCodePath, value.autoMoveFilePath); err != nil { @@ -183,7 +188,7 @@ func CreateTemp(autoCode system.AutoCodeStruct, ids ...uint) (err error) { } if autoCode.AutoMoveFile || autoCode.AutoCreateApiToSql { if autoCode.TableName != "" { - err = CreateAutoCodeHistory( + err = AutoCodeHistoryServiceApp.CreateAutoCodeHistory( string(meta), autoCode.StructName, autoCode.Description, @@ -193,7 +198,7 @@ func CreateTemp(autoCode system.AutoCodeStruct, ids ...uint) (err error) { idBf.String(), ) } else { - err = CreateAutoCodeHistory( + err = AutoCodeHistoryServiceApp.CreateAutoCodeHistory( string(meta), autoCode.StructName, autoCode.Description, @@ -220,11 +225,11 @@ func CreateTemp(autoCode system.AutoCodeStruct, ids ...uint) (err error) { //@param: pathName string, fileList []string //@return: []string, error -func GetAllTplFile(pathName string, fileList []string) ([]string, error) { +func (autoCodeService *AutoCodeService) GetAllTplFile(pathName string, fileList []string) ([]string, error) { files, err := ioutil.ReadDir(pathName) for _, fi := range files { if fi.IsDir() { - fileList, err = GetAllTplFile(pathName+"/"+fi.Name(), fileList) + fileList, err = autoCodeService.GetAllTplFile(pathName+"/"+fi.Name(), fileList) if err != nil { return nil, err } @@ -243,7 +248,7 @@ func GetAllTplFile(pathName string, fileList []string) ([]string, error) { //@param: dbName string //@return: err error, TableNames []request.TableReq -func GetTables(dbName string) (err error, TableNames []request.TableReq) { +func (autoCodeService *AutoCodeService) GetTables(dbName string) (err error, TableNames []request.TableReq) { err = global.GVA_DB.Raw("select table_name as table_name from information_schema.tables where table_schema = ?", dbName).Scan(&TableNames).Error return err, TableNames } @@ -253,7 +258,7 @@ func GetTables(dbName string) (err error, TableNames []request.TableReq) { //@description: 获取数据库的所有数据库名 //@return: err error, DBNames []request.DBReq -func GetDB() (err error, DBNames []request.DBReq) { +func (autoCodeService *AutoCodeService) GetDB() (err error, DBNames []request.DBReq) { err = global.GVA_DB.Raw("SELECT SCHEMA_NAME AS `database` FROM INFORMATION_SCHEMA.SCHEMATA;").Scan(&DBNames).Error return err, DBNames } @@ -264,12 +269,12 @@ func GetDB() (err error, DBNames []request.DBReq) { //@param: tableName string, dbName string //@return: err error, Columns []request.ColumnReq -func GetColumn(tableName string, dbName string) (err error, Columns []request.ColumnReq) { +func (autoCodeService *AutoCodeService) GetColumn(tableName string, dbName string) (err error, Columns []request.ColumnReq) { err = global.GVA_DB.Raw("SELECT COLUMN_NAME column_name,DATA_TYPE data_type,CASE DATA_TYPE WHEN 'longtext' THEN c.CHARACTER_MAXIMUM_LENGTH WHEN 'varchar' THEN c.CHARACTER_MAXIMUM_LENGTH WHEN 'double' THEN CONCAT_WS( ',', c.NUMERIC_PRECISION, c.NUMERIC_SCALE ) WHEN 'decimal' THEN CONCAT_WS( ',', c.NUMERIC_PRECISION, c.NUMERIC_SCALE ) WHEN 'int' THEN c.NUMERIC_PRECISION WHEN 'bigint' THEN c.NUMERIC_PRECISION ELSE '' END AS data_type_long,COLUMN_COMMENT column_comment FROM INFORMATION_SCHEMA.COLUMNS c WHERE table_name = ? AND table_schema = ?", tableName, dbName).Scan(&Columns).Error return err, Columns } -func DropTable(tableName string) error { +func (autoCodeService *AutoCodeService) DropTable(tableName string) error { return global.GVA_DB.Exec("DROP TABLE " + tableName).Error } @@ -280,7 +285,7 @@ func DropTable(tableName string) error { //@param: *tplData //@return: null -func addAutoMoveFile(data *tplData) { +func (autoCodeService *AutoCodeService) addAutoMoveFile(data *tplData) { base := filepath.Base(data.autoCodePath) fileSlice := strings.Split(data.autoCodePath, string(os.PathSeparator)) n := len(fileSlice) @@ -325,7 +330,7 @@ func addAutoMoveFile(data *tplData) { //@param: a *model.AutoCodeStruct //@return: err error -func AutoCreateApi(a *system.AutoCodeStruct) (ids []uint, err error) { +func (autoCodeService *AutoCodeService) AutoCreateApi(a *system.AutoCodeStruct) (ids []uint, err error) { var apiList = []system.SysApi{ { Path: "/" + a.Abbreviation + "/" + "create" + a.StructName, @@ -381,14 +386,14 @@ func AutoCreateApi(a *system.AutoCodeStruct) (ids []uint, err error) { return ids, err } -func getNeedList(autoCode *system.AutoCodeStruct) (dataList []tplData, fileList []string, needMkdir []string, err error) { +func (autoCodeService *AutoCodeService) getNeedList(autoCode *system.AutoCodeStruct) (dataList []tplData, fileList []string, needMkdir []string, err error) { // 去除所有空格 utils.TrimSpace(autoCode) for _, field := range autoCode.Fields { utils.TrimSpace(field) } // 获取 basePath 文件夹下所有tpl文件 - tplFileList, err := GetAllTplFile(basePath, nil) + tplFileList, err := autoCodeService.GetAllTplFile(basePath, nil) if err != nil { return nil, nil, nil, err } diff --git a/server/service/sys_autocode_history.go b/server/service/system/sys_autocode_history.go similarity index 68% rename from server/service/sys_autocode_history.go rename to server/service/system/sys_autocode_history.go index f180e1fa72329d221b0581768970fc1b77558f3d..8a70da78954c473bf2ad47c804eb54e7d73bed49 100644 --- a/server/service/sys_autocode_history.go +++ b/server/service/system/sys_autocode_history.go @@ -1,8 +1,8 @@ -package service +package system import ( "gin-vue-admin/global" - "gin-vue-admin/model/request" + "gin-vue-admin/model/common/request" "gin-vue-admin/model/system" "gin-vue-admin/utils" "strings" @@ -10,8 +10,13 @@ import ( "go.uber.org/zap" ) +type AutoCodeHistoryService struct { +} + +var AutoCodeHistoryServiceApp = new(AutoCodeHistoryService) + // CreateAutoCodeHistory RouterPath : RouterPath@RouterString;RouterPath2@RouterString2 -func CreateAutoCodeHistory(meta, structName, structCNName, autoCodePath string, injectionMeta string, tableName string, apiIds string) error { +func (autoCodeHistoryService *AutoCodeHistoryService) CreateAutoCodeHistory(meta, structName, structCNName, autoCodePath string, injectionMeta string, tableName string, apiIds string) error { return global.GVA_DB.Create(&system.SysAutoCodeHistory{ RequestMeta: meta, AutoCodePath: autoCodePath, @@ -24,18 +29,18 @@ func CreateAutoCodeHistory(meta, structName, structCNName, autoCodePath string, } // RollBack 回滚 -func RollBack(id uint) error { +func (autoCodeHistoryService *AutoCodeHistoryService) RollBack(id uint) error { md := system.SysAutoCodeHistory{} if err := global.GVA_DB.First(&md, id).Error; err != nil { return err } // 清除API表 - err := DeleteApiByIds(strings.Split(md.ApiIDs, ";")) + err := ApiServiceApp.DeleteApiByIds(strings.Split(md.ApiIDs, ";")) if err != nil { global.GVA_LOG.Error("ClearTag DeleteApiByIds:", zap.Error(err)) } // 获取全部表名 - err, dbNames := GetTables(global.GVA_CONFIG.Mysql.Dbname) + err, dbNames := AutoCodeServiceApp.GetTables(global.GVA_CONFIG.Mysql.Dbname) if err != nil { global.GVA_LOG.Error("ClearTag GetTables:", zap.Error(err)) } @@ -43,7 +48,7 @@ func RollBack(id uint) error { for _, name := range dbNames { if strings.Contains(strings.ToUpper(strings.Replace(name.TableName, "_", "", -1)), strings.ToUpper(md.TableName)) { // 删除表 - if err = DropTable(name.TableName); err != nil { + if err = AutoCodeServiceApp.DropTable(name.TableName); err != nil { global.GVA_LOG.Error("ClearTag DropTable:", zap.Error(err)) } @@ -65,13 +70,13 @@ func RollBack(id uint) error { return global.GVA_DB.Save(&md).Error } -func GetMeta(id uint) (string, error) { +func (autoCodeHistoryService *AutoCodeHistoryService) GetMeta(id uint) (string, error) { var meta string return meta, global.GVA_DB.Model(system.SysAutoCodeHistory{}).Select("request_meta").First(&meta, id).Error } // GetSysHistoryPage 获取系统历史数据 -func GetSysHistoryPage(info request.PageInfo) (err error, list interface{}, total int64) { +func (autoCodeHistoryService *AutoCodeHistoryService) GetSysHistoryPage(info request.PageInfo) (err error, list interface{}, total int64) { limit := info.PageSize offset := info.PageSize * (info.Page - 1) db := global.GVA_DB @@ -82,6 +87,6 @@ func GetSysHistoryPage(info request.PageInfo) (err error, list interface{}, tota } // DeletePage 删除历史数据 -func DeletePage(id uint) error { +func (autoCodeHistoryService *AutoCodeHistoryService) DeletePage(id uint) error { return global.GVA_DB.Delete(system.SysAutoCodeHistory{}, id).Error } diff --git a/server/service/sys_base_menu.go b/server/service/system/sys_base_menu.go similarity index 88% rename from server/service/sys_base_menu.go rename to server/service/system/sys_base_menu.go index 3695c0709e77e0497fadbef13165802ece48f718..865a3338527e43f92675c85b1cbbd946e0d3aac4 100644 --- a/server/service/sys_base_menu.go +++ b/server/service/system/sys_base_menu.go @@ -1,4 +1,4 @@ -package service +package system import ( "errors" @@ -7,13 +7,16 @@ import ( "gorm.io/gorm" ) +type BaseMenuService struct { +} + //@author: [piexlmax](https://github.com/piexlmax) //@function: DeleteBaseMenu //@description: 删除基础路由 //@param: id float64 //@return: err error -func DeleteBaseMenu(id float64) (err error) { +func (baseMenuService *BaseMenuService) DeleteBaseMenu(id float64) (err error) { err = global.GVA_DB.Preload("Parameters").Where("parent_id = ?", id).First(&system.SysBaseMenu{}).Error if err != nil { var menu system.SysBaseMenu @@ -36,7 +39,7 @@ func DeleteBaseMenu(id float64) (err error) { //@param: menu model.SysBaseMenu //@return: err error -func UpdateBaseMenu(menu system.SysBaseMenu) (err error) { +func (baseMenuService *BaseMenuService) UpdateBaseMenu(menu system.SysBaseMenu) (err error) { var oldMenu system.SysBaseMenu upDateMap := make(map[string]interface{}) upDateMap["keep_alive"] = menu.KeepAlive @@ -65,7 +68,7 @@ func UpdateBaseMenu(menu system.SysBaseMenu) (err error) { return txErr } if len(menu.Parameters) > 0 { - for k, _ := range menu.Parameters { + for k := range menu.Parameters { menu.Parameters[k].SysBaseMenuID = menu.ID } txErr = tx.Create(&menu.Parameters).Error @@ -91,7 +94,7 @@ func UpdateBaseMenu(menu system.SysBaseMenu) (err error) { //@param: id float64 //@return: err error, menu model.SysBaseMenu -func GetBaseMenuById(id float64) (err error, menu system.SysBaseMenu) { +func (baseMenuService *BaseMenuService) GetBaseMenuById(id float64) (err error, menu system.SysBaseMenu) { err = global.GVA_DB.Preload("Parameters").Where("id = ?", id).First(&menu).Error return } diff --git a/server/service/sys_casbin.go b/server/service/system/sys_casbin.go similarity index 73% rename from server/service/sys_casbin.go rename to server/service/system/sys_casbin.go index c4c5907ebfc3eb22256fec155331242a636be0eb..7ad611421b88f3d8bf596b4c2a5ef0292362e748 100644 --- a/server/service/sys_casbin.go +++ b/server/service/system/sys_casbin.go @@ -1,4 +1,4 @@ -package service +package system import ( "errors" @@ -19,8 +19,13 @@ import ( //@param: authorityId string, casbinInfos []request.CasbinInfo //@return: error -func UpdateCasbin(authorityId string, casbinInfos []request.CasbinInfo) error { - ClearCasbin(0, authorityId) +type CasbinService struct { +} + +var CasbinServiceApp = new(CasbinService) + +func (casbinService *CasbinService) UpdateCasbin(authorityId string, casbinInfos []request.CasbinInfo) error { + casbinService.ClearCasbin(0, authorityId) rules := [][]string{} for _, v := range casbinInfos { cm := system.CasbinModel{ @@ -31,7 +36,7 @@ func UpdateCasbin(authorityId string, casbinInfos []request.CasbinInfo) error { } rules = append(rules, []string{cm.AuthorityId, cm.Path, cm.Method}) } - e := Casbin() + e := casbinService.Casbin() success, _ := e.AddPolicies(rules) if success == false { return errors.New("存在相同api,添加失败,请联系管理员") @@ -45,7 +50,7 @@ func UpdateCasbin(authorityId string, casbinInfos []request.CasbinInfo) error { //@param: oldPath string, newPath string, oldMethod string, newMethod string //@return: error -func UpdateCasbinApi(oldPath string, newPath string, oldMethod string, newMethod string) error { +func (casbinService *CasbinService) UpdateCasbinApi(oldPath string, newPath string, oldMethod string, newMethod string) error { err := global.GVA_DB.Table("casbin_rule").Model(&system.CasbinModel{}).Where("v1 = ? AND v2 = ?", oldPath, oldMethod).Updates(map[string]interface{}{ "v1": newPath, "v2": newMethod, @@ -59,8 +64,8 @@ func UpdateCasbinApi(oldPath string, newPath string, oldMethod string, newMethod //@param: authorityId string //@return: pathMaps []request.CasbinInfo -func GetPolicyPathByAuthorityId(authorityId string) (pathMaps []request.CasbinInfo) { - e := Casbin() +func (casbinService *CasbinService) GetPolicyPathByAuthorityId(authorityId string) (pathMaps []request.CasbinInfo) { + e := casbinService.Casbin() list := e.GetFilteredPolicy(0, authorityId) for _, v := range list { pathMaps = append(pathMaps, request.CasbinInfo{ @@ -77,8 +82,8 @@ func GetPolicyPathByAuthorityId(authorityId string) (pathMaps []request.CasbinIn //@param: v int, p ...string //@return: bool -func ClearCasbin(v int, p ...string) bool { - e := Casbin() +func (casbinService *CasbinService) ClearCasbin(v int, p ...string) bool { + e := casbinService.Casbin() success, _ := e.RemoveFilteredPolicy(v, p...) return success @@ -94,11 +99,11 @@ var ( once sync.Once ) -func Casbin() *casbin.SyncedEnforcer { +func (casbinService *CasbinService) Casbin() *casbin.SyncedEnforcer { once.Do(func() { a, _ := gormadapter.NewAdapterByDB(global.GVA_DB) syncedEnforcer, _ = casbin.NewSyncedEnforcer(global.GVA_CONFIG.Casbin.ModelPath, a) - syncedEnforcer.AddFunction("ParamsMatch", ParamsMatchFunc) + syncedEnforcer.AddFunction("ParamsMatch", casbinService.ParamsMatchFunc) }) _ = syncedEnforcer.LoadPolicy() return syncedEnforcer @@ -110,7 +115,7 @@ func Casbin() *casbin.SyncedEnforcer { //@param: fullNameKey1 string, key2 string //@return: bool -func ParamsMatch(fullNameKey1 string, key2 string) bool { +func (casbinService *CasbinService) ParamsMatch(fullNameKey1 string, key2 string) bool { key1 := strings.Split(fullNameKey1, "?")[0] // 剥离路径后再使用casbin的keyMatch2 return util.KeyMatch2(key1, key2) @@ -122,9 +127,9 @@ func ParamsMatch(fullNameKey1 string, key2 string) bool { //@param: args ...interface{} //@return: interface{}, error -func ParamsMatchFunc(args ...interface{}) (interface{}, error) { +func (casbinService *CasbinService) ParamsMatchFunc(args ...interface{}) (interface{}, error) { name1 := args[0].(string) name2 := args[1].(string) - return ParamsMatch(name1, name2), nil + return casbinService.ParamsMatch(name1, name2), nil } diff --git a/server/service/sys_dictionary.go b/server/service/system/sys_dictionary.go similarity index 81% rename from server/service/sys_dictionary.go rename to server/service/system/sys_dictionary.go index c9c30f12258043e8c46c7d61d2c1078e439baf22..451c2b2a833cef79b7746baa1ab1da57b1ebe2d4 100644 --- a/server/service/sys_dictionary.go +++ b/server/service/system/sys_dictionary.go @@ -1,4 +1,4 @@ -package service +package system import ( "errors" @@ -14,7 +14,10 @@ import ( //@param: sysDictionary model.SysDictionary //@return: err error -func CreateSysDictionary(sysDictionary system.SysDictionary) (err error) { +type DictionaryService struct { +} + +func (dictionaryService *DictionaryService) CreateSysDictionary(sysDictionary system.SysDictionary) (err error) { if (!errors.Is(global.GVA_DB.First(&system.SysDictionary{}, "type = ?", sysDictionary.Type).Error, gorm.ErrRecordNotFound)) { return errors.New("存在相同的type,不允许创建") } @@ -28,7 +31,7 @@ func CreateSysDictionary(sysDictionary system.SysDictionary) (err error) { //@param: sysDictionary model.SysDictionary //@return: err error -func DeleteSysDictionary(sysDictionary system.SysDictionary) (err error) { +func (dictionaryService *DictionaryService) DeleteSysDictionary(sysDictionary system.SysDictionary) (err error) { err = global.GVA_DB.Delete(&sysDictionary).Delete(&sysDictionary.SysDictionaryDetails).Error return err } @@ -39,7 +42,7 @@ func DeleteSysDictionary(sysDictionary system.SysDictionary) (err error) { //@param: sysDictionary *model.SysDictionary //@return: err error -func UpdateSysDictionary(sysDictionary *system.SysDictionary) (err error) { +func (dictionaryService *DictionaryService) UpdateSysDictionary(sysDictionary *system.SysDictionary) (err error) { var dict system.SysDictionary sysDictionaryMap := map[string]interface{}{ "Name": sysDictionary.Name, @@ -66,7 +69,7 @@ func UpdateSysDictionary(sysDictionary *system.SysDictionary) (err error) { //@param: Type string, Id uint //@return: err error, sysDictionary model.SysDictionary -func GetSysDictionary(Type string, Id uint) (err error, sysDictionary system.SysDictionary) { +func (dictionaryService *DictionaryService) GetSysDictionary(Type string, Id uint) (err error, sysDictionary system.SysDictionary) { err = global.GVA_DB.Where("type = ? OR id = ?", Type, Id).Preload("SysDictionaryDetails").First(&sysDictionary).Error return } @@ -78,7 +81,7 @@ func GetSysDictionary(Type string, Id uint) (err error, sysDictionary system.Sys //@param: info request.SysDictionarySearch //@return: err error, list interface{}, total int64 -func GetSysDictionaryInfoList(info request.SysDictionarySearch) (err error, list interface{}, total int64) { +func (dictionaryService *DictionaryService) GetSysDictionaryInfoList(info request.SysDictionarySearch) (err error, list interface{}, total int64) { limit := info.PageSize offset := info.PageSize * (info.Page - 1) // 创建db diff --git a/server/service/sys_dictionary_detail.go b/server/service/system/sys_dictionary_detail.go similarity index 73% rename from server/service/sys_dictionary_detail.go rename to server/service/system/sys_dictionary_detail.go index 16f7ae2e5f44d268fa83785466b81afde2b23d8d..1b6eb09b81ad49e59a775291b43b8c3d2c7dd04e 100644 --- a/server/service/sys_dictionary_detail.go +++ b/server/service/system/sys_dictionary_detail.go @@ -1,4 +1,4 @@ -package service +package system import ( "gin-vue-admin/global" @@ -12,7 +12,10 @@ import ( //@param: sysDictionaryDetail model.SysDictionaryDetail //@return: err error -func CreateSysDictionaryDetail(sysDictionaryDetail system.SysDictionaryDetail) (err error) { +type DictionaryDetailService struct { +} + +func (dictionaryDetailService *DictionaryDetailService) CreateSysDictionaryDetail(sysDictionaryDetail system.SysDictionaryDetail) (err error) { err = global.GVA_DB.Create(&sysDictionaryDetail).Error return err } @@ -23,7 +26,7 @@ func CreateSysDictionaryDetail(sysDictionaryDetail system.SysDictionaryDetail) ( //@param: sysDictionaryDetail model.SysDictionaryDetail //@return: err error -func DeleteSysDictionaryDetail(sysDictionaryDetail system.SysDictionaryDetail) (err error) { +func (dictionaryDetailService *DictionaryDetailService) DeleteSysDictionaryDetail(sysDictionaryDetail system.SysDictionaryDetail) (err error) { err = global.GVA_DB.Delete(&sysDictionaryDetail).Error return err } @@ -34,7 +37,7 @@ func DeleteSysDictionaryDetail(sysDictionaryDetail system.SysDictionaryDetail) ( //@param: sysDictionaryDetail *model.SysDictionaryDetail //@return: err error -func UpdateSysDictionaryDetail(sysDictionaryDetail *system.SysDictionaryDetail) (err error) { +func (dictionaryDetailService *DictionaryDetailService) UpdateSysDictionaryDetail(sysDictionaryDetail *system.SysDictionaryDetail) (err error) { err = global.GVA_DB.Save(sysDictionaryDetail).Error return err } @@ -45,7 +48,7 @@ func UpdateSysDictionaryDetail(sysDictionaryDetail *system.SysDictionaryDetail) //@param: id uint //@return: err error, sysDictionaryDetail model.SysDictionaryDetail -func GetSysDictionaryDetail(id uint) (err error, sysDictionaryDetail system.SysDictionaryDetail) { +func (dictionaryDetailService *DictionaryDetailService) GetSysDictionaryDetail(id uint) (err error, sysDictionaryDetail system.SysDictionaryDetail) { err = global.GVA_DB.Where("id = ?", id).First(&sysDictionaryDetail).Error return } @@ -56,7 +59,7 @@ func GetSysDictionaryDetail(id uint) (err error, sysDictionaryDetail system.SysD //@param: info request.SysDictionaryDetailSearch //@return: err error, list interface{}, total int64 -func GetSysDictionaryDetailInfoList(info request.SysDictionaryDetailSearch) (err error, list interface{}, total int64) { +func (dictionaryDetailService *DictionaryDetailService) GetSysDictionaryDetailInfoList(info request.SysDictionaryDetailSearch) (err error, list interface{}, total int64) { limit := info.PageSize offset := info.PageSize * (info.Page - 1) // 创建db diff --git a/server/service/sys_email.go b/server/service/system/sys_email.go similarity index 72% rename from server/service/sys_email.go rename to server/service/system/sys_email.go index 08b7b7d0b65ac7474decf29bcfd9cb047ee657c0..2addb45c6918e845aac27ef13dfd6ea4f4485804 100644 --- a/server/service/sys_email.go +++ b/server/service/system/sys_email.go @@ -1,15 +1,18 @@ -package service +package system import ( "gin-vue-admin/utils" ) +type EmailService struct { +} + //@author: [maplepie](https://github.com/maplepie) //@function: EmailTest //@description: 发送邮件测试 //@return: err error -func EmailTest() (err error) { +func (e *EmailService) EmailTest() (err error) { subject := "test" body := "test" err = utils.EmailTest(subject, body) diff --git a/server/service/sys_initdb.go b/server/service/system/sys_initdb.go similarity index 86% rename from server/service/sys_initdb.go rename to server/service/system/sys_initdb.go index ee3f5bc43e92872d71d033fe1ba78bce780b7f1b..265f0075fbfb321f598a740ccc45a0353694c42c 100644 --- a/server/service/sys_initdb.go +++ b/server/service/system/sys_initdb.go @@ -1,4 +1,4 @@ -package service +package system import ( "database/sql" @@ -23,7 +23,10 @@ import ( //@param: viper *viper.Viper, mysql config.Mysql //@return: error -func writeConfig(viper *viper.Viper, mysql config.Mysql) error { +type InitDBService struct { +} + +func (initDBService *InitDBService) writeConfig(viper *viper.Viper, mysql config.Mysql) error { global.GVA_CONFIG.Mysql = mysql cs := utils.StructToMap(global.GVA_CONFIG) for k, v := range cs { @@ -38,7 +41,7 @@ func writeConfig(viper *viper.Viper, mysql config.Mysql) error { //@param: dsn string, driver string, createSql //@return: error -func createTable(dsn string, driver string, createSql string) error { +func (initDBService *InitDBService) createTable(dsn string, driver string, createSql string) error { db, err := sql.Open(driver, dsn) if err != nil { return err @@ -56,7 +59,7 @@ func createTable(dsn string, driver string, createSql string) error { return err } -func initDB(InitDBFunctions ...system.InitDBFunc) (err error) { +func (initDBService *InitDBService) initDB(InitDBFunctions ...system.InitDBFunc) (err error) { for _, v := range InitDBFunctions { err = v.Init() if err != nil { @@ -72,7 +75,7 @@ func initDB(InitDBFunctions ...system.InitDBFunc) (err error) { //@param: conf request.InitDB //@return: error -func InitDB(conf request.InitDB) error { +func (initDBService *InitDBService) InitDB(conf request.InitDB) error { if conf.Host == "" { conf.Host = "127.0.0.1" @@ -83,7 +86,7 @@ func InitDB(conf request.InitDB) error { } dsn := fmt.Sprintf("%s:%s@tcp(%s:%s)/", conf.UserName, conf.Password, conf.Host, conf.Port) createSql := fmt.Sprintf("CREATE DATABASE IF NOT EXISTS `%s` DEFAULT CHARACTER SET utf8mb4 DEFAULT COLLATE utf8mb4_general_ci;", conf.DBName) - if err := createTable(dsn, "mysql", createSql); err != nil { + if err := initDBService.createTable(dsn, "mysql", createSql); err != nil { return err } @@ -138,7 +141,7 @@ func InitDB(conf request.InitDB) error { global.GVA_DB = nil return err } - err = initDB( + err = initDBService.initDB( source.Admin, source.Api, source.AuthorityMenu, @@ -154,7 +157,7 @@ func InitDB(conf request.InitDB) error { global.GVA_DB = nil return err } - if err = writeConfig(global.GVA_VP, MysqlConfig); err != nil { + if err = initDBService.writeConfig(global.GVA_VP, MysqlConfig); err != nil { return err } global.GVA_CONFIG.AutoCode.Root, _ = filepath.Abs("..") diff --git a/server/service/sys_menu.go b/server/service/system/sys_menu.go similarity index 70% rename from server/service/sys_menu.go rename to server/service/system/sys_menu.go index 248205fda881cb94d660d984f90e1318eb453242..f6b311ccf7cfba411807380e11566b782d3a50f7 100644 --- a/server/service/sys_menu.go +++ b/server/service/system/sys_menu.go @@ -1,10 +1,10 @@ -package service +package system import ( "errors" "gin-vue-admin/global" + "gin-vue-admin/model/common/request" "gin-vue-admin/model/system" - "gin-vue-admin/model/system/request" "gorm.io/gorm" "strconv" ) @@ -15,7 +15,12 @@ import ( //@param: authorityId string //@return: err error, treeMap map[string][]model.SysMenu -func getMenuTreeMap(authorityId string) (err error, treeMap map[string][]system.SysMenu) { +type MenuService struct { +} + +var MenuServiceApp = new(MenuService) + +func (menuService *MenuService) getMenuTreeMap(authorityId string) (err error, treeMap map[string][]system.SysMenu) { var allMenus []system.SysMenu treeMap = make(map[string][]system.SysMenu) err = global.GVA_DB.Where("authority_id = ?", authorityId).Order("sort").Preload("Parameters").Find(&allMenus).Error @@ -31,11 +36,11 @@ func getMenuTreeMap(authorityId string) (err error, treeMap map[string][]system. //@param: authorityId string //@return: err error, menus []model.SysMenu -func GetMenuTree(authorityId string) (err error, menus []system.SysMenu) { - err, menuTree := getMenuTreeMap(authorityId) +func (menuService *MenuService) GetMenuTree(authorityId string) (err error, menus []system.SysMenu) { + err, menuTree := menuService.getMenuTreeMap(authorityId) menus = menuTree["0"] for i := 0; i < len(menus); i++ { - err = getChildrenList(&menus[i], menuTree) + err = menuService.getChildrenList(&menus[i], menuTree) } return err, menus } @@ -46,10 +51,10 @@ func GetMenuTree(authorityId string) (err error, menus []system.SysMenu) { //@param: menu *model.SysMenu, treeMap map[string][]model.SysMenu //@return: err error -func getChildrenList(menu *system.SysMenu, treeMap map[string][]system.SysMenu) (err error) { +func (menuService *MenuService) getChildrenList(menu *system.SysMenu, treeMap map[string][]system.SysMenu) (err error) { menu.Children = treeMap[menu.MenuId] for i := 0; i < len(menu.Children); i++ { - err = getChildrenList(&menu.Children[i], treeMap) + err = menuService.getChildrenList(&menu.Children[i], treeMap) } return err } @@ -59,12 +64,12 @@ func getChildrenList(menu *system.SysMenu, treeMap map[string][]system.SysMenu) //@description: 获取路由分页 //@return: err error, list interface{}, total int64 -func GetInfoList() (err error, list interface{}, total int64) { +func (menuService *MenuService) GetInfoList() (err error, list interface{}, total int64) { var menuList []system.SysBaseMenu - err, treeMap := getBaseMenuTreeMap() + err, treeMap := menuService.getBaseMenuTreeMap() menuList = treeMap["0"] for i := 0; i < len(menuList); i++ { - err = getBaseChildrenList(&menuList[i], treeMap) + err = menuService.getBaseChildrenList(&menuList[i], treeMap) } return err, menuList, total } @@ -75,10 +80,10 @@ func GetInfoList() (err error, list interface{}, total int64) { //@param: menu *model.SysBaseMenu, treeMap map[string][]model.SysBaseMenu //@return: err error -func getBaseChildrenList(menu *system.SysBaseMenu, treeMap map[string][]system.SysBaseMenu) (err error) { +func (menuService *MenuService) getBaseChildrenList(menu *system.SysBaseMenu, treeMap map[string][]system.SysBaseMenu) (err error) { menu.Children = treeMap[strconv.Itoa(int(menu.ID))] for i := 0; i < len(menu.Children); i++ { - err = getBaseChildrenList(&menu.Children[i], treeMap) + err = menuService.getBaseChildrenList(&menu.Children[i], treeMap) } return err } @@ -89,7 +94,7 @@ func getBaseChildrenList(menu *system.SysBaseMenu, treeMap map[string][]system.S //@param: menu model.SysBaseMenu //@return: error -func AddBaseMenu(menu system.SysBaseMenu) error { +func (menuService *MenuService) AddBaseMenu(menu system.SysBaseMenu) error { if !errors.Is(global.GVA_DB.Where("name = ?", menu.Name).First(&system.SysBaseMenu{}).Error, gorm.ErrRecordNotFound) { return errors.New("存在重复name,请修改name") } @@ -101,7 +106,7 @@ func AddBaseMenu(menu system.SysBaseMenu) error { //@description: 获取路由总树map //@return: err error, treeMap map[string][]model.SysBaseMenu -func getBaseMenuTreeMap() (err error, treeMap map[string][]system.SysBaseMenu) { +func (menuService *MenuService) getBaseMenuTreeMap() (err error, treeMap map[string][]system.SysBaseMenu) { var allMenus []system.SysBaseMenu treeMap = make(map[string][]system.SysBaseMenu) err = global.GVA_DB.Order("sort").Preload("Parameters").Find(&allMenus).Error @@ -116,11 +121,11 @@ func getBaseMenuTreeMap() (err error, treeMap map[string][]system.SysBaseMenu) { //@description: 获取基础路由树 //@return: err error, menus []model.SysBaseMenu -func GetBaseMenuTree() (err error, menus []system.SysBaseMenu) { - err, treeMap := getBaseMenuTreeMap() +func (menuService *MenuService) GetBaseMenuTree() (err error, menus []system.SysBaseMenu) { + err, treeMap := menuService.getBaseMenuTreeMap() menus = treeMap["0"] for i := 0; i < len(menus); i++ { - err = getBaseChildrenList(&menus[i], treeMap) + err = menuService.getBaseChildrenList(&menus[i], treeMap) } return err, menus } @@ -131,11 +136,11 @@ func GetBaseMenuTree() (err error, menus []system.SysBaseMenu) { //@param: menus []model.SysBaseMenu, authorityId string //@return: err error -func AddMenuAuthority(menus []system.SysBaseMenu, authorityId string) (err error) { +func (menuService *MenuService) AddMenuAuthority(menus []system.SysBaseMenu, authorityId string) (err error) { var auth system.SysAuthority auth.AuthorityId = authorityId auth.SysBaseMenus = menus - err = SetMenuAuthority(&auth) + err = AuthorityServiceApp.SetMenuAuthority(&auth) return err } @@ -145,7 +150,7 @@ func AddMenuAuthority(menus []system.SysBaseMenu, authorityId string) (err error //@param: info *request.GetAuthorityId //@return: err error, menus []model.SysMenu -func GetMenuAuthority(info *request.GetAuthorityId) (err error, menus []system.SysMenu) { +func (menuService *MenuService) GetMenuAuthority(info *request.GetAuthorityId) (err error, menus []system.SysMenu) { err = global.GVA_DB.Where("authority_id = ? ", info.AuthorityId).Order("sort").Find(&menus).Error //sql := "SELECT authority_menu.keep_alive,authority_menu.default_menu,authority_menu.created_at,authority_menu.updated_at,authority_menu.deleted_at,authority_menu.menu_level,authority_menu.parent_id,authority_menu.path,authority_menu.`name`,authority_menu.hidden,authority_menu.component,authority_menu.title,authority_menu.icon,authority_menu.sort,authority_menu.menu_id,authority_menu.authority_id FROM authority_menu WHERE authority_menu.authority_id = ? ORDER BY authority_menu.sort ASC" //err = global.GVA_DB.Raw(sql, authorityId).Scan(&menus).Error diff --git a/server/service/sys_operation_record.go b/server/service/system/sys_operation_record.go similarity index 70% rename from server/service/sys_operation_record.go rename to server/service/system/sys_operation_record.go index da1222c2c9d14e396e226fd686edf1b87c6d7930..903e89365573eb7be9cf6f4b59c37b19ef85dc8b 100644 --- a/server/service/sys_operation_record.go +++ b/server/service/system/sys_operation_record.go @@ -1,9 +1,10 @@ -package service +package system import ( "gin-vue-admin/global" + "gin-vue-admin/model/common/request" "gin-vue-admin/model/system" - "gin-vue-admin/model/system/request" + systemReq "gin-vue-admin/model/system/request" ) //@author: [granty1](https://github.com/granty1) @@ -12,7 +13,10 @@ import ( //@param: sysOperationRecord model.SysOperationRecord //@return: err error -func CreateSysOperationRecord(sysOperationRecord system.SysOperationRecord) (err error) { +type OperationRecordService struct { +} + +func (operationRecordService *OperationRecordService) CreateSysOperationRecord(sysOperationRecord system.SysOperationRecord) (err error) { err = global.GVA_DB.Create(&sysOperationRecord).Error return err } @@ -24,7 +28,7 @@ func CreateSysOperationRecord(sysOperationRecord system.SysOperationRecord) (err //@param: ids request.IdsReq //@return: err error -func DeleteSysOperationRecordByIds(ids request.IdsReq) (err error) { +func (operationRecordService *OperationRecordService) DeleteSysOperationRecordByIds(ids request.IdsReq) (err error) { err = global.GVA_DB.Delete(&[]system.SysOperationRecord{}, "id in (?)", ids.Ids).Error return err } @@ -35,7 +39,7 @@ func DeleteSysOperationRecordByIds(ids request.IdsReq) (err error) { //@param: sysOperationRecord model.SysOperationRecord //@return: err error -func DeleteSysOperationRecord(sysOperationRecord system.SysOperationRecord) (err error) { +func (operationRecordService *OperationRecordService) DeleteSysOperationRecord(sysOperationRecord system.SysOperationRecord) (err error) { err = global.GVA_DB.Delete(&sysOperationRecord).Error return err } @@ -46,7 +50,7 @@ func DeleteSysOperationRecord(sysOperationRecord system.SysOperationRecord) (err //@param: id uint //@return: err error, sysOperationRecord model.SysOperationRecord -func GetSysOperationRecord(id uint) (err error, sysOperationRecord system.SysOperationRecord) { +func (operationRecordService *OperationRecordService) GetSysOperationRecord(id uint) (err error, sysOperationRecord system.SysOperationRecord) { err = global.GVA_DB.Where("id = ?", id).First(&sysOperationRecord).Error return } @@ -55,10 +59,10 @@ func GetSysOperationRecord(id uint) (err error, sysOperationRecord system.SysOpe //@author: [piexlmax](https://github.com/piexlmax) //@function: GetSysOperationRecordInfoList //@description: 分页获取操作记录列表 -//@param: info request.SysOperationRecordSearch +//@param: info systemReq.SysOperationRecordSearch //@return: err error, list interface{}, total int64 -func GetSysOperationRecordInfoList(info request.SysOperationRecordSearch) (err error, list interface{}, total int64) { +func (operationRecordService *OperationRecordService) GetSysOperationRecordInfoList(info systemReq.SysOperationRecordSearch) (err error, list interface{}, total int64) { limit := info.PageSize offset := info.PageSize * (info.Page - 1) // 创建db diff --git a/server/service/sys_system.go b/server/service/system/sys_system.go similarity index 79% rename from server/service/sys_system.go rename to server/service/system/sys_system.go index 22fd3b72165204c59deb185e580241505d34eb9f..d19614d66bd4f436da0da6fbf9b3530ef570b2e1 100644 --- a/server/service/sys_system.go +++ b/server/service/system/sys_system.go @@ -1,4 +1,4 @@ -package service +package system import ( "gin-vue-admin/config" @@ -13,7 +13,10 @@ import ( //@description: 读取配置文件 //@return: err error, conf config.Server -func GetSystemConfig() (err error, conf config.Server) { +type SystemConfigService struct { +} + +func (systemConfigService *SystemConfigService) GetSystemConfig() (err error, conf config.Server) { return nil, global.GVA_CONFIG } @@ -24,7 +27,7 @@ func GetSystemConfig() (err error, conf config.Server) { //@param: system model.System //@return: err error -func SetSystemConfig(system system.System) (err error) { +func (systemConfigService *SystemConfigService) SetSystemConfig(system system.System) (err error) { cs := utils.StructToMap(system.Config) for k, v := range cs { global.GVA_VP.Set(k, v) @@ -38,7 +41,7 @@ func SetSystemConfig(system system.System) (err error) { //@description: 获取服务器信息 //@return: server *utils.Server, err error -func GetServerInfo() (server *utils.Server, err error) { +func (systemConfigService *SystemConfigService) GetServerInfo() (server *utils.Server, err error) { var s utils.Server s.Os = utils.InitOS() if s.Cpu, err = utils.InitCPU(); err != nil { diff --git a/server/service/sys_user.go b/server/service/system/sys_user.go similarity index 78% rename from server/service/sys_user.go rename to server/service/system/sys_user.go index a16b5d18d837a3460d58531c06cc0b46b444a694..e3b44992c1d88e1fefad3d794ed444577edf6b75 100644 --- a/server/service/sys_user.go +++ b/server/service/system/sys_user.go @@ -1,10 +1,10 @@ -package service +package system import ( "errors" "gin-vue-admin/global" + "gin-vue-admin/model/common/request" "gin-vue-admin/model/system" - "gin-vue-admin/model/system/request" "gin-vue-admin/utils" uuid "github.com/satori/go.uuid" "gorm.io/gorm" @@ -16,7 +16,10 @@ import ( //@param: u model.SysUser //@return: err error, userInter model.SysUser -func Register(u system.SysUser) (err error, userInter system.SysUser) { +type UserService struct { +} + +func (userService *UserService) Register(u system.SysUser) (err error, userInter system.SysUser) { var user system.SysUser if !errors.Is(global.GVA_DB.Where("username = ?", u.Username).First(&user).Error, gorm.ErrRecordNotFound) { // 判断用户名是否注册 return errors.New("用户名已注册"), userInter @@ -34,7 +37,7 @@ func Register(u system.SysUser) (err error, userInter system.SysUser) { //@param: u *model.SysUser //@return: err error, userInter *model.SysUser -func Login(u *system.SysUser) (err error, userInter *system.SysUser) { +func (userService *UserService) Login(u *system.SysUser) (err error, userInter *system.SysUser) { var user system.SysUser u.Password = utils.MD5V([]byte(u.Password)) err = global.GVA_DB.Where("username = ? AND password = ?", u.Username, u.Password).Preload("Authority").First(&user).Error @@ -47,7 +50,7 @@ func Login(u *system.SysUser) (err error, userInter *system.SysUser) { //@param: u *model.SysUser, newPassword string //@return: err error, userInter *model.SysUser -func ChangePassword(u *system.SysUser, newPassword string) (err error, userInter *system.SysUser) { +func (userService *UserService) ChangePassword(u *system.SysUser, newPassword string) (err error, userInter *system.SysUser) { var user system.SysUser u.Password = utils.MD5V([]byte(u.Password)) err = global.GVA_DB.Where("username = ? AND password = ?", u.Username, u.Password).First(&user).Update("password", utils.MD5V([]byte(newPassword))).Error @@ -60,7 +63,7 @@ func ChangePassword(u *system.SysUser, newPassword string) (err error, userInter //@param: info request.PageInfo //@return: err error, list interface{}, total int64 -func GetUserInfoList(info request.PageInfo) (err error, list interface{}, total int64) { +func (userService *UserService) GetUserInfoList(info request.PageInfo) (err error, list interface{}, total int64) { limit := info.PageSize offset := info.PageSize * (info.Page - 1) db := global.GVA_DB.Model(&system.SysUser{}) @@ -76,7 +79,7 @@ func GetUserInfoList(info request.PageInfo) (err error, list interface{}, total //@param: uuid uuid.UUID, authorityId string //@return: err error -func SetUserAuthority(uuid uuid.UUID, authorityId string) (err error) { +func (userService *UserService) SetUserAuthority(uuid uuid.UUID, authorityId string) (err error) { err = global.GVA_DB.Where("uuid = ?", uuid).First(&system.SysUser{}).Update("authority_id", authorityId).Error return err } @@ -87,7 +90,7 @@ func SetUserAuthority(uuid uuid.UUID, authorityId string) (err error) { //@param: id float64 //@return: err error -func DeleteUser(id float64) (err error) { +func (userService *UserService) DeleteUser(id float64) (err error) { var user system.SysUser err = global.GVA_DB.Where("id = ?", id).Delete(&user).Error return err @@ -99,7 +102,7 @@ func DeleteUser(id float64) (err error) { //@param: reqUser model.SysUser //@return: err error, user model.SysUser -func SetUserInfo(reqUser system.SysUser) (err error, user system.SysUser) { +func (userService *UserService) SetUserInfo(reqUser system.SysUser) (err error, user system.SysUser) { err = global.GVA_DB.Updates(&reqUser).Error return err, reqUser } @@ -110,7 +113,7 @@ func SetUserInfo(reqUser system.SysUser) (err error, user system.SysUser) { //@param: id int //@return: err error, user *model.SysUser -func FindUserById(id int) (err error, user *system.SysUser) { +func (userService *UserService) FindUserById(id int) (err error, user *system.SysUser) { var u system.SysUser err = global.GVA_DB.Where("`id` = ?", id).First(&u).Error return err, &u @@ -122,7 +125,7 @@ func FindUserById(id int) (err error, user *system.SysUser) { //@param: uuid string //@return: err error, user *model.SysUser -func FindUserByUuid(uuid string) (err error, user *system.SysUser) { +func (userService *UserService) FindUserByUuid(uuid string) (err error, user *system.SysUser) { var u system.SysUser if err = global.GVA_DB.Where("`uuid` = ?", uuid).First(&u).Error; err != nil { return errors.New("用户不存在"), &u diff --git a/server/utils/clamis.go b/server/utils/clamis.go new file mode 100644 index 0000000000000000000000000000000000000000..1238331bdeb49d9e4341e6744a0c16d8649385f1 --- /dev/null +++ b/server/utils/clamis.go @@ -0,0 +1,40 @@ +package utils + +import ( + "gin-vue-admin/global" + systemReq "gin-vue-admin/model/system/request" + "github.com/gin-gonic/gin" +) + +// 从Gin的Context中获取从jwt解析出来的用户ID +func GetUserID(c *gin.Context) uint { + if claims, exists := c.Get("claims"); !exists { + global.GVA_LOG.Error("从Gin的Context中获取从jwt解析出来的用户ID失败, 请检查路由是否使用jwt中间件!") + return 0 + } else { + waitUse := claims.(*systemReq.CustomClaims) + return waitUse.ID + } +} + +// 从Gin的Context中获取从jwt解析出来的用户UUID +func GetUserUuid(c *gin.Context) string { + if claims, exists := c.Get("claims"); !exists { + global.GVA_LOG.Error("从Gin的Context中获取从jwt解析出来的用户UUID失败, 请检查路由是否使用jwt中间件!") + return "" + } else { + waitUse := claims.(*systemReq.CustomClaims) + return waitUse.UUID.String() + } +} + +// 从Gin的Context中获取从jwt解析出来的用户角色id +func GetUserAuthorityId(c *gin.Context) string { + if claims, exists := c.Get("claims"); !exists { + global.GVA_LOG.Error("从Gin的Context中获取从jwt解析出来的用户UUID失败, 请检查路由是否使用jwt中间件!") + return "" + } else { + waitUse := claims.(*systemReq.CustomClaims) + return waitUse.AuthorityId + } +}