diff --git a/server/api/v1/autocode/autocodeExample.go b/server/api/v1/autocode/autocodeExample.go new file mode 100644 index 00000000..f520f475 --- /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" + autocodeReq "gin-vue-admin/model/autocode/request" + "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 autoCodeExample autocode.AutoCodeExample + _ = c.ShouldBindJSON(&autoCodeExample) + if err := autoCodeExampleService.CreateAutoCodeExample(autoCodeExample); 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 autoCodeExample autocode.AutoCodeExample + _ = c.ShouldBindJSON(&autoCodeExample) + if err := autoCodeExampleService.DeleteAutoCodeExample(autoCodeExample); 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 autoCodeExample autocode.AutoCodeExample + _ = c.ShouldBindJSON(&autoCodeExample) + if err := autoCodeExampleService.UpdateAutoCodeExample(&autoCodeExample); 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 autoCodeExample autocode.AutoCodeExample + _ = c.ShouldBindQuery(&autoCodeExample) + if err := utils.Verify(autoCodeExample, utils.IdVerify); err != nil { + response.FailWithMessage(err.Error(), c) + return + } + if err, reAutoCodeExample := autoCodeExampleService.GetAutoCodeExample(autoCodeExample.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 autocodeReq.AutoCodeExampleSearch true "页码, 每页大小, 搜索条件" +// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}" +// @Router /autoCodeExample/getAutoCodeExampleList [get] +func (autoCodeExampleApi *AutoCodeExampleApi) GetAutoCodeExampleList(c *gin.Context) { + var pageInfo autocodeReq.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 00000000..f391196c --- /dev/null +++ b/server/api/v1/autocode/enter.go @@ -0,0 +1,7 @@ +package autocode + +type ApiGroup struct { + // Code generated by gin-vue-admin Begin; DO NOT EDIT. + AutoCodeExampleApi + // Code generated by gin-vue-admin End; DO NOT EDIT. +} diff --git a/server/api/v1/enter.go b/server/api/v1/enter.go new file mode 100644 index 00000000..b2517198 --- /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 00000000..d68423bf --- /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 91f5d55f..03a04c15 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/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 69% rename from server/api/v1/exa_customer.go rename to server/api/v1/example/exa_customer.go index 6069fb84..caca26b0 100644 --- a/server/api/v1/exa_customer.go +++ b/server/api/v1/example/exa_customer.go @@ -1,34 +1,37 @@ -package v1 +package example import ( "gin-vue-admin/global" - "gin-vue-admin/model" - "gin-vue-admin/model/request" - "gin-vue-admin/model/response" - "gin-vue-admin/service" + "gin-vue-admin/model/common/request" + "gin-vue-admin/model/common/response" + "gin-vue-admin/model/example" + 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 // @accept application/json // @Produce application/json -// @Param data body model.ExaCustomer true "客户用户名, 客户手机号码" +// @Param data body example.ExaCustomer true "客户用户名, 客户手机号码" // @Success 200 {string} string "{"success":true,"data":{},"msg":"创建成功"}" // @Router /customer/customer [post] -func CreateExaCustomer(c *gin.Context) { - var customer model.ExaCustomer +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 { @@ -41,17 +44,17 @@ func CreateExaCustomer(c *gin.Context) { // @Security ApiKeyAuth // @accept application/json // @Produce application/json -// @Param data body model.ExaCustomer true "客户ID" +// @Param data body example.ExaCustomer true "客户ID" // @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}" // @Router /customer/customer [delete] -func DeleteExaCustomer(c *gin.Context) { - var customer model.ExaCustomer +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 { @@ -64,11 +67,11 @@ func DeleteExaCustomer(c *gin.Context) { // @Security ApiKeyAuth // @accept application/json // @Produce application/json -// @Param data body model.ExaCustomer true "客户ID, 客户信息" +// @Param data body example.ExaCustomer true "客户ID, 客户信息" // @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}" // @Router /customer/customer [put] -func UpdateExaCustomer(c *gin.Context) { - var customer model.ExaCustomer +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 { response.FailWithMessage(err.Error(), c) @@ -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 { @@ -91,22 +94,22 @@ func UpdateExaCustomer(c *gin.Context) { // @Security ApiKeyAuth // @accept application/json // @Produce application/json -// @Param data body model.ExaCustomer true "客户ID" +// @Param data body example.ExaCustomer true "客户ID" // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}" // @Router /customer/customer [get] -func GetExaCustomer(c *gin.Context) { - var customer model.ExaCustomer +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 84% rename from server/api/v1/exa_excel.go rename to server/api/v1/example/exa_excel.go index 6637cb27..dc2a0c66 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" - "gin-vue-admin/model/response" - "gin-vue-admin/service" + "gin-vue-admin/model/common/response" + "gin-vue-admin/model/example" "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文件并返回 @@ -20,14 +22,14 @@ import ( // @Security ApiKeyAuth // @accept application/json // @Produce application/octet-stream -// @Param data body model.ExcelInfo true "导出Excel文件信息" +// @Param data body example.ExcelInfo true "导出Excel文件信息" // @Success 200 // @Router /excel/exportExcel [post] -func ExportExcel(c *gin.Context) { - var excelInfo model.ExcelInfo +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 68% rename from server/api/v1/exa_file_upload_download.go rename to server/api/v1/example/exa_file_upload_download.go index ab007488..7c4dbe71 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" - "gin-vue-admin/model/request" - "gin-vue-admin/model/response" - "gin-vue-admin/service" + "gin-vue-admin/model/common/request" + "gin-vue-admin/model/common/response" + "gin-vue-admin/model/example" + 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,8 +21,8 @@ import ( // @Param file formData file true "上传文件示例" // @Success 200 {string} string "{"success":true,"data":{},"msg":"上传成功"}" // @Router /fileUploadAndDownload/upload [post] -func UploadFile(c *gin.Context) { - var file model.ExaFileUploadAndDownload +func (u *FileUploadAndDownloadApi) UploadFile(c *gin.Context) { + var file example.ExaFileUploadAndDownload noSave := c.DefaultQuery("noSave", "0") _, header, err := c.Request.FormFile("file") if err != nil { @@ -27,26 +30,26 @@ 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 // @Summary 删除文件 // @Security ApiKeyAuth // @Produce application/json -// @Param data body model.ExaFileUploadAndDownload true "传入文件里面id即可" +// @Param data body example.ExaFileUploadAndDownload true "传入文件里面id即可" // @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}" // @Router /fileUploadAndDownload/deleteFile [post] -func DeleteFile(c *gin.Context) { - var file model.ExaFileUploadAndDownload +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 78% rename from server/api/v1/exa_simple_uploader.go rename to server/api/v1/example/exa_simple_uploader.go index cf86477c..566df369 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" - "gin-vue-admin/model/response" - "gin-vue-admin/service" + "gin-vue-admin/model/common/response" + "gin-vue-admin/model/example" "gin-vue-admin/utils" "github.com/gin-gonic/gin" "go.uber.org/zap" ) +type SimpleUploaderApi struct { +} + // @Tags SimpleUploader // @Summary 断点续传插件版示例 // @Security ApiKeyAuth @@ -17,9 +19,9 @@ 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) { - var chunk model.ExaSimpleUploader +// @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") chunk.ChunkNumber = c.PostForm("chunkNumber") @@ -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/sys_auto_code.go b/server/api/v1/sys_auto_code.go deleted file mode 100644 index 09ac2418..00000000 --- a/server/api/v1/sys_auto_code.go +++ /dev/null @@ -1,135 +0,0 @@ -package v1 - -import ( - "errors" - "fmt" - "gin-vue-admin/global" - "gin-vue-admin/model" - "gin-vue-admin/model/response" - "gin-vue-admin/service" - "gin-vue-admin/utils" - "net/url" - "os" - - "github.com/gin-gonic/gin" - "go.uber.org/zap" -) - -// @Tags AutoCode -// @Summary 预览创建后的代码 -// @Security ApiKeyAuth -// @accept application/json -// @Produce application/json -// @Param data body model.AutoCodeStruct true "预览创建代码" -// @Success 200 {string} string "{"success":true,"data":{},"msg":"创建成功"}" -// @Router /autoCode/preview [post] -func PreviewTemp(c *gin.Context) { - var a model.AutoCodeStruct - _ = c.ShouldBindJSON(&a) - if err := utils.Verify(a, utils.AutoCodeVerify); err != nil { - response.FailWithMessage(err.Error(), c) - return - } - autoCode, err := service.PreviewTemp(a) - if err != nil { - global.GVA_LOG.Error("预览失败!", zap.Any("err", err)) - response.FailWithMessage("预览失败", c) - } else { - response.OkWithDetailed(gin.H{"autoCode": autoCode}, "预览成功", c) - } -} - -// @Tags AutoCode -// @Summary 自动代码模板 -// @Security ApiKeyAuth -// @accept application/json -// @Produce application/json -// @Param data body model.AutoCodeStruct true "创建自动代码" -// @Success 200 {string} string "{"success":true,"data":{},"msg":"创建成功"}" -// @Router /autoCode/createTemp [post] -func CreateTemp(c *gin.Context) { - var a model.AutoCodeStruct - _ = c.ShouldBindJSON(&a) - if err := utils.Verify(a, utils.AutoCodeVerify); err != nil { - response.FailWithMessage(err.Error(), c) - return - } - if a.AutoCreateApiToSql { - if err := service.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("自动化创建失败!请自行清空垃圾数据!")) - return - } - } - err := service.CreateTemp(a) - if err != nil { - if errors.Is(err, model.AutoMoveErr) { - c.Writer.Header().Add("success", "false") - c.Writer.Header().Add("msgtype", "success") - c.Writer.Header().Add("msg", url.QueryEscape(err.Error())) - } else { - c.Writer.Header().Add("success", "false") - c.Writer.Header().Add("msg", url.QueryEscape(err.Error())) - _ = os.Remove("./ginvueadmin.zip") - } - } else { - c.Writer.Header().Add("Content-Disposition", fmt.Sprintf("attachment; filename=%s", "ginvueadmin.zip")) // fmt.Sprintf("attachment; filename=%s", filename)对下载的文件重命名 - c.Writer.Header().Add("Content-Type", "application/json") - c.Writer.Header().Add("success", "true") - c.File("./ginvueadmin.zip") - _ = os.Remove("./ginvueadmin.zip") - } -} - -// @Tags AutoCode -// @Summary 获取当前数据库所有表 -// @Security ApiKeyAuth -// @accept application/json -// @Produce application/json -// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}" -// @Router /autoCode/getTables [get] -func GetTables(c *gin.Context) { - dbName := c.DefaultQuery("dbName", global.GVA_CONFIG.Mysql.Dbname) - err, tables := service.GetTables(dbName) - if err != nil { - global.GVA_LOG.Error("查询table失败!", zap.Any("err", err)) - response.FailWithMessage("查询table失败", c) - } else { - response.OkWithDetailed(gin.H{"tables": tables}, "获取成功", c) - } -} - -// @Tags AutoCode -// @Summary 获取当前所有数据库 -// @Security ApiKeyAuth -// @accept application/json -// @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 { - global.GVA_LOG.Error("获取失败!", zap.Any("err", err)) - response.FailWithMessage("获取失败", c) - } else { - response.OkWithDetailed(gin.H{"dbs": dbs}, "获取成功", c) - } -} - -// @Tags AutoCode -// @Summary 获取当前表所有字段 -// @Security ApiKeyAuth -// @accept application/json -// @Produce application/json -// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}" -// @Router /autoCode/getColumn [get] -func 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 { - global.GVA_LOG.Error("获取失败!", zap.Any("err", err)) - response.FailWithMessage("获取失败", c) - } else { - response.OkWithDetailed(gin.H{"columns": columns}, "获取成功", c) - } -} diff --git a/server/api/v1/system/enter.go b/server/api/v1/system/enter.go new file mode 100644 index 00000000..aa4eb730 --- /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 71% rename from server/api/v1/sys_api.go rename to server/api/v1/system/sys_api.go index 32573644..cae0eb55 100644 --- a/server/api/v1/sys_api.go +++ b/server/api/v1/system/sys_api.go @@ -1,33 +1,37 @@ -package v1 +package system import ( "gin-vue-admin/global" - "gin-vue-admin/model" - "gin-vue-admin/model/request" - "gin-vue-admin/model/response" - "gin-vue-admin/service" + "gin-vue-admin/model/common/request" + "gin-vue-admin/model/common/response" + "gin-vue-admin/model/system" + 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 // @accept application/json // @Produce application/json -// @Param data body model.SysApi true "api路径, api中文描述, api组, 方法" +// @Param data body system.SysApi true "api路径, api中文描述, api组, 方法" // @Success 200 {string} string "{"success":true,"data":{},"msg":"创建成功"}" // @Router /api/createApi [post] -func CreateApi(c *gin.Context) { - var api model.SysApi +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 { @@ -40,17 +44,17 @@ func CreateApi(c *gin.Context) { // @Security ApiKeyAuth // @accept application/json // @Produce application/json -// @Param data body model.SysApi true "ID" +// @Param data body system.SysApi true "ID" // @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}" // @Router /api/deleteApi [post] -func DeleteApi(c *gin.Context) { - var api model.SysApi +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) } } @@ -115,17 +119,17 @@ func GetApiById(c *gin.Context) { // @Security ApiKeyAuth // @accept application/json // @Produce application/json -// @Param data body model.SysApi true "api路径, api中文描述, api组, 方法" +// @Param data body system.SysApi true "api路径, api中文描述, api组, 方法" // @Success 200 {string} string "{"success":true,"data":{},"msg":"修改成功"}" // @Router /api/updateApi [post] -func UpdateApi(c *gin.Context) { - var api model.SysApi +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 66% rename from server/api/v1/sys_authority.go rename to server/api/v1/system/sys_authority.go index d2740fe0..e8f28f22 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" - "gin-vue-admin/model/request" - "gin-vue-admin/model/response" - "gin-vue-admin/service" + "gin-vue-admin/model/common/request" + "gin-vue-admin/model/common/response" + "gin-vue-admin/model/system" + 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) { - var authority model.SysAuthority +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) } } @@ -68,17 +73,17 @@ func CopyAuthority(c *gin.Context) { // @Security ApiKeyAuth // @accept application/json // @Produce application/json -// @Param data body model.SysAuthority true "删除角色" +// @Param data body system.SysAuthority true "删除角色" // @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}" // @Router /authority/deleteAuthority [post] -func DeleteAuthority(c *gin.Context) { - var authority model.SysAuthority +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 { @@ -91,21 +96,21 @@ func DeleteAuthority(c *gin.Context) { // @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/updateAuthority [post] -func UpdateAuthority(c *gin.Context) { - var auth model.SysAuthority +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 { @@ -142,17 +147,17 @@ func GetAuthorityList(c *gin.Context) { // @Security ApiKeyAuth // @accept application/json // @Produce application/json -// @Param data body model.SysAuthority true "设置角色资源权限" +// @Param data body system.SysAuthority true "设置角色资源权限" // @Success 200 {string} string "{"success":true,"data":{},"msg":"设置成功"}" // @Router /authority/setDataAuthority [post] -func SetDataAuthority(c *gin.Context) { - var auth model.SysAuthority +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/system/sys_auto_code.go b/server/api/v1/system/sys_auto_code.go new file mode 100644 index 00000000..c7efd0ea --- /dev/null +++ b/server/api/v1/system/sys_auto_code.go @@ -0,0 +1,224 @@ +package system + +import ( + "errors" + "fmt" + "gin-vue-admin/global" + "gin-vue-admin/model/common/response" + "gin-vue-admin/model/system" + systemReq "gin-vue-admin/model/system/request" + "gin-vue-admin/utils" + "net/url" + "os" + + "github.com/gin-gonic/gin" + "go.uber.org/zap" +) + +type AutoCodeApi struct { +} + +// @Tags AutoCode +// @Summary 删除回滚记录 +// @Security ApiKeyAuth +// @accept application/json +// @Produce application/json +// @Param data body systemReq.AutoHistoryByID true "删除回滚记录" +// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}" +// @Router /autoCode/delSysHistory [post] +func (autoApi *AutoCodeApi) DelSysHistory(c *gin.Context) { + var id systemReq.AutoHistoryByID + _ = c.ShouldBindJSON(&id) + err := autoCodeHistoryService.DeletePage(id.ID) + if err != nil { + global.GVA_LOG.Error("获取失败!", zap.Any("err", err)) + response.FailWithMessage("获取失败", c) + } + response.OkWithMessage("删除成功", c) + +} + +// @Tags AutoCode +// @Summary 查询回滚记录 +// @Security ApiKeyAuth +// @accept application/json +// @Produce application/json +// @Param data body systemReq.SysAutoHistory true "查询回滚记录" +// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}" +// @Router /autoCode/getSysHistory [post] +func (autoApi *AutoCodeApi) GetSysHistory(c *gin.Context) { + var search systemReq.SysAutoHistory + _ = c.ShouldBindJSON(&search) + err, list, total := autoCodeHistoryService.GetSysHistoryPage(search.PageInfo) + if err != nil { + global.GVA_LOG.Error("获取失败!", zap.Any("err", err)) + response.FailWithMessage("获取失败", c) + } else { + response.OkWithDetailed(response.PageResult{ + List: list, + Total: total, + Page: search.Page, + PageSize: search.PageSize, + }, "获取成功", c) + } +} + +// @Tags AutoCode +// @Summary 回滚 +// @Security ApiKeyAuth +// @accept application/json +// @Produce application/json +// @Param data body systemReq.AutoHistoryByID true "回滚自动生成代码" +// @Success 200 {string} string "{"success":true,"data":{},"msg":"回滚成功"}" +// @Router /autoCode/rollback [post] +func (autoApi *AutoCodeApi) RollBack(c *gin.Context) { + var id systemReq.AutoHistoryByID + _ = c.ShouldBindJSON(&id) + if err := autoCodeHistoryService.RollBack(id.ID); err != nil { + response.FailWithMessage(err.Error(), c) + return + } + response.OkWithMessage("回滚成功", c) +} + +// @Tags AutoCode +// @Summary 回滚 +// @Security ApiKeyAuth +// @accept application/json +// @Produce application/json +// @Param data body systemReq.AutoHistoryByID true "获取meta信息" +// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}" +// @Router /autoCode/getMeta [post] +func (autoApi *AutoCodeApi) GetMeta(c *gin.Context) { + var id systemReq.AutoHistoryByID + _ = c.ShouldBindJSON(&id) + if v, err := autoCodeHistoryService.GetMeta(id.ID); err != nil { + response.FailWithMessage(err.Error(), c) + return + } else { + response.OkWithDetailed(gin.H{"meta": v}, "获取成功", c) + } + +} + +// @Tags AutoCode +// @Summary 预览创建后的代码 +// @Security ApiKeyAuth +// @accept application/json +// @Produce application/json +// @Param data body system.AutoCodeStruct true "预览创建代码" +// @Success 200 {string} string "{"success":true,"data":{},"msg":"创建成功"}" +// @Router /autoCode/preview [post] +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 := autoCodeService.PreviewTemp(a) + if err != nil { + global.GVA_LOG.Error("预览失败!", zap.Any("err", err)) + response.FailWithMessage("预览失败", c) + } else { + response.OkWithDetailed(gin.H{"autoCode": autoCode}, "预览成功", c) + } +} + +// @Tags AutoCode +// @Summary 自动代码模板 +// @Security ApiKeyAuth +// @accept application/json +// @Produce application/json +// @Param data body system.AutoCodeStruct true "创建自动代码" +// @Success 200 {string} string "{"success":true,"data":{},"msg":"创建成功"}" +// @Router /autoCode/createTemp [post] +func (autoApi *AutoCodeApi) CreateTemp(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 + } + var apiIds []uint + if a.AutoCreateApiToSql { + 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("自动化创建失败!请自行清空垃圾数据!")) + return + } else { + apiIds = ids + } + } + err := autoCodeService.CreateTemp(a, apiIds...) + if err != nil { + if errors.Is(err, system.AutoMoveErr) { + c.Writer.Header().Add("success", "false") + c.Writer.Header().Add("msgtype", "success") + c.Writer.Header().Add("msg", url.QueryEscape(err.Error())) + } else { + c.Writer.Header().Add("success", "false") + c.Writer.Header().Add("msg", url.QueryEscape(err.Error())) + _ = os.Remove("./ginvueadmin.zip") + } + } else { + c.Writer.Header().Add("Content-Disposition", fmt.Sprintf("attachment; filename=%s", "ginvueadmin.zip")) // fmt.Sprintf("attachment; filename=%s", filename)对下载的文件重命名 + c.Writer.Header().Add("Content-Type", "application/json") + c.Writer.Header().Add("success", "true") + c.File("./ginvueadmin.zip") + _ = os.Remove("./ginvueadmin.zip") + } +} + +// @Tags AutoCode +// @Summary 获取当前数据库所有表 +// @Security ApiKeyAuth +// @accept application/json +// @Produce application/json +// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}" +// @Router /autoCode/getTables [get] +func (autoApi *AutoCodeApi) GetTables(c *gin.Context) { + dbName := c.DefaultQuery("dbName", global.GVA_CONFIG.Mysql.Dbname) + err, tables := autoCodeService.GetTables(dbName) + if err != nil { + global.GVA_LOG.Error("查询table失败!", zap.Any("err", err)) + response.FailWithMessage("查询table失败", c) + } else { + response.OkWithDetailed(gin.H{"tables": tables}, "获取成功", c) + } +} + +// @Tags AutoCode +// @Summary 获取当前所有数据库 +// @Security ApiKeyAuth +// @accept application/json +// @Produce application/json +// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}" +// @Router /autoCode/getDatabase [get] +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 { + response.OkWithDetailed(gin.H{"dbs": dbs}, "获取成功", c) + } +} + +// @Tags AutoCode +// @Summary 获取当前表所有字段 +// @Security ApiKeyAuth +// @accept application/json +// @Produce application/json +// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}" +// @Router /autoCode/getColumn [get] +func (autoApi *AutoCodeApi) GetColumn(c *gin.Context) { + dbName := c.DefaultQuery("dbName", global.GVA_CONFIG.Mysql.Dbname) + tableName := c.Query("tableName") + if err, columns := autoCodeService.GetColumn(tableName, dbName); err != nil { + global.GVA_LOG.Error("获取失败!", zap.Any("err", err)) + response.FailWithMessage("获取失败", c) + } else { + response.OkWithDetailed(gin.H{"columns": columns}, "获取成功", c) + } +} diff --git a/server/api/v1/sys_captcha.go b/server/api/v1/system/sys_captcha.go similarity index 71% rename from server/api/v1/sys_captcha.go rename to server/api/v1/system/sys_captcha.go index fe46a20a..0aed33d5 100644 --- a/server/api/v1/sys_captcha.go +++ b/server/api/v1/system/sys_captcha.go @@ -1,15 +1,21 @@ -package v1 +package system import ( "gin-vue-admin/global" - "gin-vue-admin/model/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" ) +// 当开启多服务器部署时,替换下面的配置,使用redis共享存储验证码 +// var store = captcha.NewDefaultRedisStore() var store = base64Captcha.DefaultMemStore +type BaseApi struct { +} + // @Tags Base // @Summary 生成验证码 // @Security ApiKeyAuth @@ -17,7 +23,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 +32,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 71% rename from server/api/v1/sys_casbin.go rename to server/api/v1/system/sys_casbin.go index 24e0ba5e..0b3ced48 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/request" - "gin-vue-admin/model/response" - "gin-vue-admin/service" + "gin-vue-admin/model/common/response" + "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 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 69% rename from server/api/v1/sys_dictionary.go rename to server/api/v1/system/sys_dictionary.go index 23477de2..9cbaff28 100644 --- a/server/api/v1/sys_dictionary.go +++ b/server/api/v1/system/sys_dictionary.go @@ -1,28 +1,30 @@ -package v1 +package system import ( "gin-vue-admin/global" - "gin-vue-admin/model" - "gin-vue-admin/model/request" - "gin-vue-admin/model/response" - "gin-vue-admin/service" + "gin-vue-admin/model/common/response" + "gin-vue-admin/model/system" + "gin-vue-admin/model/system/request" "gin-vue-admin/utils" "github.com/gin-gonic/gin" "go.uber.org/zap" ) +type DictionaryApi struct { +} + // @Tags SysDictionary // @Summary 创建SysDictionary // @Security ApiKeyAuth // @accept application/json // @Produce application/json -// @Param data body model.SysDictionary true "SysDictionary模型" +// @Param data body system.SysDictionary true "SysDictionary模型" // @Success 200 {string} string "{"success":true,"data":{},"msg":"创建成功"}" // @Router /sysDictionary/createSysDictionary [post] -func CreateSysDictionary(c *gin.Context) { - var dictionary model.SysDictionary +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 { @@ -35,13 +37,13 @@ func CreateSysDictionary(c *gin.Context) { // @Security ApiKeyAuth // @accept application/json // @Produce application/json -// @Param data body model.SysDictionary true "SysDictionary模型" +// @Param data body system.SysDictionary true "SysDictionary模型" // @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}" // @Router /sysDictionary/deleteSysDictionary [delete] -func DeleteSysDictionary(c *gin.Context) { - var dictionary model.SysDictionary +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 { @@ -54,13 +56,13 @@ func DeleteSysDictionary(c *gin.Context) { // @Security ApiKeyAuth // @accept application/json // @Produce application/json -// @Param data body model.SysDictionary true "SysDictionary模型" +// @Param data body system.SysDictionary true "SysDictionary模型" // @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}" // @Router /sysDictionary/updateSysDictionary [put] -func UpdateSysDictionary(c *gin.Context) { - var dictionary model.SysDictionary +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 { @@ -73,13 +75,13 @@ func UpdateSysDictionary(c *gin.Context) { // @Security ApiKeyAuth // @accept application/json // @Produce application/json -// @Param data body model.SysDictionary true "ID或字典英名" +// @Param data body system.SysDictionary true "ID或字典英名" // @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}" // @Router /sysDictionary/findSysDictionary [get] -func FindSysDictionary(c *gin.Context) { - var dictionary model.SysDictionary +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 67% rename from server/api/v1/sys_dictionary_detail.go rename to server/api/v1/system/sys_dictionary_detail.go index a1c2f3f7..49ab796d 100644 --- a/server/api/v1/sys_dictionary_detail.go +++ b/server/api/v1/system/sys_dictionary_detail.go @@ -1,28 +1,30 @@ -package v1 +package system import ( "gin-vue-admin/global" - "gin-vue-admin/model" - "gin-vue-admin/model/request" - "gin-vue-admin/model/response" - "gin-vue-admin/service" + "gin-vue-admin/model/common/response" + "gin-vue-admin/model/system" + "gin-vue-admin/model/system/request" "gin-vue-admin/utils" "github.com/gin-gonic/gin" "go.uber.org/zap" ) +type DictionaryDetailApi struct { +} + // @Tags SysDictionaryDetail // @Summary 创建SysDictionaryDetail // @Security ApiKeyAuth // @accept application/json // @Produce application/json -// @Param data body model.SysDictionaryDetail true "SysDictionaryDetail模型" +// @Param data body system.SysDictionaryDetail true "SysDictionaryDetail模型" // @Success 200 {string} string "{"success":true,"data":{},"msg":"创建成功"}" // @Router /sysDictionaryDetail/createSysDictionaryDetail [post] -func CreateSysDictionaryDetail(c *gin.Context) { - var detail model.SysDictionaryDetail +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 { @@ -35,13 +37,13 @@ func CreateSysDictionaryDetail(c *gin.Context) { // @Security ApiKeyAuth // @accept application/json // @Produce application/json -// @Param data body model.SysDictionaryDetail true "SysDictionaryDetail模型" +// @Param data body system.SysDictionaryDetail true "SysDictionaryDetail模型" // @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}" // @Router /sysDictionaryDetail/deleteSysDictionaryDetail [delete] -func DeleteSysDictionaryDetail(c *gin.Context) { - var detail model.SysDictionaryDetail +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 { @@ -54,13 +56,13 @@ func DeleteSysDictionaryDetail(c *gin.Context) { // @Security ApiKeyAuth // @accept application/json // @Produce application/json -// @Param data body model.SysDictionaryDetail true "更新SysDictionaryDetail" +// @Param data body system.SysDictionaryDetail true "更新SysDictionaryDetail" // @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}" // @Router /sysDictionaryDetail/updateSysDictionaryDetail [put] -func UpdateSysDictionaryDetail(c *gin.Context) { - var detail model.SysDictionaryDetail +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 { @@ -73,17 +75,17 @@ func UpdateSysDictionaryDetail(c *gin.Context) { // @Security ApiKeyAuth // @accept application/json // @Produce application/json -// @Param data body model.SysDictionaryDetail true "用id查询SysDictionaryDetail" +// @Param data body system.SysDictionaryDetail true "用id查询SysDictionaryDetail" // @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}" // @Router /sysDictionaryDetail/findSysDictionaryDetail [get] -func FindSysDictionaryDetail(c *gin.Context) { - var detail model.SysDictionaryDetail +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 2f594843..39b305ca 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 85% rename from server/api/v1/sys_initdb.go rename to server/api/v1/system/sys_initdb.go index 9cbe974c..00ee98e5 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/request" - "gin-vue-admin/model/response" - "gin-vue-admin/service" - + "gin-vue-admin/model/common/response" + "gin-vue-admin/model/system/request" "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 68% rename from server/api/v1/sys_jwt_blacklist.go rename to server/api/v1/system/sys_jwt_blacklist.go index 62d7ff94..76bedf8a 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" - "gin-vue-admin/model/response" - "gin-vue-admin/service" + "gin-vue-admin/model/common/response" + "gin-vue-admin/model/system" "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 := model.JwtBlacklist{Jwt: token} - if err := service.JsonInBlacklist(jwt); err != nil { + jwt := system.JwtBlacklist{Jwt: token} + 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 71% rename from server/api/v1/sys_menu.go rename to server/api/v1/system/sys_menu.go index 72eeb26c..0335d0b9 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" - "gin-vue-admin/model/request" - "gin-vue-admin/model/response" - "gin-vue-admin/service" + "gin-vue-admin/model/common/request" + "gin-vue-admin/model/common/response" + "gin-vue-admin/model/system" + 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 = []model.SysMenu{} + 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) } @@ -98,11 +102,11 @@ func GetMenuAuthority(c *gin.Context) { // @Security ApiKeyAuth // @accept application/json // @Produce application/json -// @Param data body model.SysBaseMenu true "路由path, 父菜单ID, 路由name, 对应前端文件路径, 排序标记" +// @Param data body system.SysBaseMenu true "路由path, 父菜单ID, 路由name, 对应前端文件路径, 排序标记" // @Success 200 {string} string "{"success":true,"data":{},"msg":"添加成功"}" // @Router /menu/addBaseMenu [post] -func AddBaseMenu(c *gin.Context) { - var menu model.SysBaseMenu +func (a *AuthorityMenuApi) AddBaseMenu(c *gin.Context) { + var menu system.SysBaseMenu _ = c.ShouldBindJSON(&menu) if err := utils.Verify(menu, utils.MenuVerify); err != nil { response.FailWithMessage(err.Error(), c) @@ -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 { @@ -149,11 +153,11 @@ func DeleteBaseMenu(c *gin.Context) { // @Security ApiKeyAuth // @accept application/json // @Produce application/json -// @Param data body model.SysBaseMenu true "路由path, 父菜单ID, 路由name, 对应前端文件路径, 排序标记" +// @Param data body system.SysBaseMenu true "路由path, 父菜单ID, 路由name, 对应前端文件路径, 排序标记" // @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}" // @Router /menu/updateBaseMenu [post] -func UpdateBaseMenu(c *gin.Context) { - var menu model.SysBaseMenu +func (a *AuthorityMenuApi) UpdateBaseMenu(c *gin.Context) { + var menu system.SysBaseMenu _ = c.ShouldBindJSON(&menu) if err := utils.Verify(menu, utils.MenuVerify); err != nil { response.FailWithMessage(err.Error(), c) @@ -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 68% rename from server/api/v1/sys_operation_record.go rename to server/api/v1/system/sys_operation_record.go index d3d5745e..43380be3 100644 --- a/server/api/v1/sys_operation_record.go +++ b/server/api/v1/system/sys_operation_record.go @@ -1,28 +1,31 @@ -package v1 +package system import ( "gin-vue-admin/global" - "gin-vue-admin/model" - "gin-vue-admin/model/request" - "gin-vue-admin/model/response" - "gin-vue-admin/service" + "gin-vue-admin/model/common/request" + "gin-vue-admin/model/common/response" + "gin-vue-admin/model/system" + 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 // @accept application/json // @Produce application/json -// @Param data body model.SysOperationRecord true "创建SysOperationRecord" +// @Param data body system.SysOperationRecord true "创建SysOperationRecord" // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}" // @Router /sysOperationRecord/createSysOperationRecord [post] -func CreateSysOperationRecord(c *gin.Context) { - var sysOperationRecord model.SysOperationRecord +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 { @@ -35,13 +38,13 @@ func CreateSysOperationRecord(c *gin.Context) { // @Security ApiKeyAuth // @accept application/json // @Produce application/json -// @Param data body model.SysOperationRecord true "SysOperationRecord模型" +// @Param data body system.SysOperationRecord true "SysOperationRecord模型" // @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}" // @Router /sysOperationRecord/deleteSysOperationRecord [delete] -func DeleteSysOperationRecord(c *gin.Context) { - var sysOperationRecord model.SysOperationRecord +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 { @@ -73,17 +76,17 @@ func DeleteSysOperationRecordByIds(c *gin.Context) { // @Security ApiKeyAuth // @accept application/json // @Produce application/json -// @Param data body model.SysOperationRecord true "Id" +// @Param data body system.SysOperationRecord true "Id" // @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}" // @Router /sysOperationRecord/findSysOperationRecord [get] -func FindSysOperationRecord(c *gin.Context) { - var sysOperationRecord model.SysOperationRecord +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 69% rename from server/api/v1/sys_system.go rename to server/api/v1/system/sys_system.go index 49b76ffd..a022639a 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" - "gin-vue-admin/model/response" - "gin-vue-admin/service" + "gin-vue-admin/model/common/response" + "gin-vue-admin/model/system" + 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) } } @@ -30,13 +33,13 @@ func GetSystemConfig(c *gin.Context) { // @Summary 设置配置文件内容 // @Security ApiKeyAuth // @Produce application/json -// @Param data body model.System true "设置配置文件内容" +// @Param data body system.System true "设置配置文件内容" // @Success 200 {string} string "{"success":true,"data":{},"msg":"设置成功"}" // @Router /system/setSystemConfig [post] -func SetSystemConfig(c *gin.Context) { - var sys model.System +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 58% rename from server/api/v1/sys_user.go rename to server/api/v1/system/sys_user.go index 1d29ff40..6db0c34f 100644 --- a/server/api/v1/sys_user.go +++ b/server/api/v1/system/sys_user.go @@ -1,13 +1,15 @@ -package v1 +package system import ( "gin-vue-admin/global" "gin-vue-admin/middleware" - "gin-vue-admin/model" - "gin-vue-admin/model/request" - "gin-vue-admin/model/response" - "gin-vue-admin/service" + "gin-vue-admin/model/common/request" + "gin-vue-admin/model/common/response" + "gin-vue-admin/model/system" + systemReq "gin-vue-admin/model/system/request" + systemRes "gin-vue-admin/model/system/response" "gin-vue-admin/utils" + "strconv" "time" "github.com/dgrijalva/jwt-go" @@ -19,23 +21,23 @@ 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) return } if store.Verify(l.CaptchaId, l.Captcha, true) { - u := &model.SysUser{Username: l.Username, Password: l.Password} - if err, user := service.Login(u); err != nil { + u := &system.SysUser{Username: l.Username, Password: l.Password} + 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 +45,9 @@ func Login(c *gin.Context) { } // 登录以后签发jwt -func tokenNext(c *gin.Context, user model.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 +67,20 @@ func tokenNext(c *gin.Context, user model.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, @@ -87,17 +89,17 @@ func tokenNext(c *gin.Context, user model.SysUser) { global.GVA_LOG.Error("设置登录状态失败!", zap.Any("err", err)) response.FailWithMessage("设置登录状态失败", c) } else { - var blackJWT model.JwtBlacklist + 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 +110,29 @@ func tokenNext(c *gin.Context, user model.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 := &model.SysUser{Username: r.Username, NickName: r.NickName, Password: r.Password, HeaderImg: r.HeaderImg, AuthorityId: r.AuthorityId} - err, userReturn := service.Register(*user) + var authorities []system.SysAuthority + for _, v := range r.AuthorityIds { + authorities = append(authorities, system.SysAuthority{ + AuthorityId: v, + }) + } + user := &system.SysUser{Username: r.Username, NickName: r.NickName, Password: r.Password, HeaderImg: r.HeaderImg, AuthorityId: r.AuthorityId, Authorities: authorities} + 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 +140,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 := &model.SysUser{Username: user.Username, Password: user.Password} - if err, _ := service.ChangePassword(u, user.NewPassword); err != nil { + u := &system.SysUser{Username: user.Username, Password: user.Password} + if err, _ := userService.ChangePassword(u, user.NewPassword); err != nil { global.GVA_LOG.Error("修改失败!", zap.Any("err", err)) response.FailWithMessage("修改失败,原密码与当前账户不符", c) } else { @@ -159,14 +167,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 { @@ -180,21 +188,53 @@ func GetUserList(c *gin.Context) { } // @Tags SysUser -// @Summary 设置用户权限 +// @Summary 更改用户权限 // @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 { + userID := utils.GetUserID(c) + uuid := utils.GetUserUuid(c) + if err := userService.SetUserAuthority(userID, uuid, sua.AuthorityId); err != nil { + global.GVA_LOG.Error("修改失败!", zap.Any("err", err)) + response.FailWithMessage(err.Error(), c) + } else { + claims := utils.GetUserInfo(c) + j := &middleware.JWT{SigningKey: []byte(global.GVA_CONFIG.JWT.SigningKey)} // 唯一签名 + claims.AuthorityId = sua.AuthorityId + if token, err := j.CreateToken(*claims); err != nil { + global.GVA_LOG.Error("修改失败!", zap.Any("err", err)) + response.FailWithMessage(err.Error(), c) + } else { + c.Header("new-token", token) + c.Header("new-expires-at", strconv.FormatInt(claims.ExpiresAt, 10)) + response.OkWithMessage("修改成功", c) + } + + } +} + +// @Tags SysUser +// @Summary 设置用户权限 +// @Security ApiKeyAuth +// @accept application/json +// @Produce application/json +// @Param data body systemReq.SetUserAuthorities true "用户UUID, 角色ID" +// @Success 200 {string} string "{"success":true,"data":{},"msg":"修改成功"}" +// @Router /user/setUserAuthorities [post] +func (b *BaseApi) SetUserAuthorities(c *gin.Context) { + var sua systemReq.SetUserAuthorities + _ = c.ShouldBindJSON(&sua) + if err := userService.SetUserAuthorities(sua.ID, sua.AuthorityIds); err != nil { global.GVA_LOG.Error("修改失败!", zap.Any("err", err)) response.FailWithMessage("修改失败", c) } else { @@ -210,19 +250,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 { @@ -235,17 +275,17 @@ func DeleteUser(c *gin.Context) { // @Security ApiKeyAuth // @accept application/json // @Produce application/json -// @Param data body model.SysUser true "ID, 用户名, 昵称, 头像链接" +// @Param data body system.SysUser true "ID, 用户名, 昵称, 头像链接" // @Success 200 {string} string "{"success":true,"data":{},"msg":"设置成功"}" // @Router /user/setUserInfo [put] -func SetUserInfo(c *gin.Context) { - var user model.SysUser +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 { @@ -253,35 +293,19 @@ func SetUserInfo(c *gin.Context) { } } -// 从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 +// @Tags SysUser +// @Summary 获取用户信息 +// @Security ApiKeyAuth +// @accept application/json +// @Produce application/json +// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}" +// @Router /user/getUserInfo [get] +func (b *BaseApi) GetUserInfo(c *gin.Context) { + uuid := utils.GetUserUuid(c) + if err, ReqUser := userService.GetUserInfo(uuid); err != nil { + global.GVA_LOG.Error("获取失败!", zap.Any("err", err)) + response.FailWithMessage("获取失败", c) } 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 + response.OkWithDetailed(gin.H{"userInfo": ReqUser}, "获取成功", c) } } diff --git a/server/config.yaml b/server/config.yaml index 5c78bce6..fa0c233d 100644 --- a/server/config.yaml +++ b/server/config.yaml @@ -62,8 +62,8 @@ mysql: password: '' max-idle-conns: 10 max-open-conns: 100 - log-mode: "" - log-zap: false + log-mode: false + log-zap: "" # local configuration local: @@ -74,12 +74,12 @@ autocode: transfer-restart: true root: "" server: /server - server-api: /api/v1 + server-api: /api/v1/autocode server-initialize: /initialize - server-model: /model - server-request: /model/request/ - server-router: /router - server-service: /service + server-model: /model/autocode + server-request: /model/autocode/request/ + server-router: /router/autocode + server-service: /service/autocode web: /web/src web-api: /api web-flow: /view diff --git a/server/core/server.go b/server/core/server.go index 9839a5ac..e6b8c4cb 100644 --- a/server/core/server.go +++ b/server/core/server.go @@ -29,7 +29,7 @@ func RunWindowsServer() { fmt.Printf(` 欢迎使用 Gin-Vue-Admin - 当前版本:V2.4.3 + 当前版本:V2.4.4 加群方式:微信号:shouzi_1994 QQ群:622360840 默认自动化文档地址:http://127.0.0.1%s/swagger/index.html 默认前端文件运行地址:http://127.0.0.1:8080 diff --git a/server/docs/docs.go b/server/docs/docs.go index 07296df7..c68decca 100644 --- a/server/docs/docs.go +++ b/server/docs/docs.go @@ -1,6 +1,5 @@ // GENERATED BY THE COMMAND ABOVE; DO NOT EDIT -// This file was generated by swaggo/swag at -// 2021-05-14 11:28:23.4731221 +0800 CST m=+1.258292701 +// This file was generated by swaggo/swag package docs @@ -25,6 +24,108 @@ var doc = `{ "host": "{{.Host}}", "basePath": "{{.BasePath}}", "paths": { + "/SimpleUploaderApi/checkFileMd5": { + "get": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "produces": [ + "application/json" + ], + "tags": [ + "SimpleUploader" + ], + "summary": "断点续传插件版示例", + "parameters": [ + { + "type": "string", + "description": "md5", + "name": "md5", + "in": "query", + "required": true + } + ], + "responses": { + "200": { + "description": "{\"success\":true,\"data\":{},\"msg\":\"查询成功\"}", + "schema": { + "type": "string" + } + } + } + } + }, + "/SimpleUploaderApi/mergeFileMd5": { + "get": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "produces": [ + "application/json" + ], + "tags": [ + "SimpleUploader" + ], + "summary": "合并文件", + "parameters": [ + { + "type": "string", + "description": "md5", + "name": "md5", + "in": "query", + "required": true + } + ], + "responses": { + "200": { + "description": "{\"success\":true,\"data\":{},\"msg\":\"合并成功\"}", + "schema": { + "type": "string" + } + } + } + } + }, + "/SimpleUploaderApi/upload": { + "post": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "consumes": [ + "multipart/form-data" + ], + "produces": [ + "application/json" + ], + "tags": [ + "SimpleUploader" + ], + "summary": "断点续传插件版示例", + "parameters": [ + { + "type": "file", + "description": "断点续传插件版示例", + "name": "file", + "in": "formData", + "required": true + } + ], + "responses": { + "200": { + "description": "{\"success\":true,\"data\":{},\"msg\":\"切片创建成功\"}", + "schema": { + "type": "string" + } + } + } + } + }, "/api/createApi": { "post": { "security": [ @@ -49,7 +150,7 @@ var doc = `{ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/model.SysApi" + "$ref": "#/definitions/system.SysApi" } } ], @@ -87,7 +188,7 @@ var doc = `{ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/model.SysApi" + "$ref": "#/definitions/system.SysApi" } } ], @@ -266,7 +367,7 @@ var doc = `{ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/model.SysApi" + "$ref": "#/definitions/system.SysApi" } } ], @@ -342,7 +443,7 @@ var doc = `{ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/model.SysAuthority" + "$ref": "#/definitions/system.SysAuthority" } } ], @@ -380,7 +481,7 @@ var doc = `{ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/model.SysAuthority" + "$ref": "#/definitions/system.SysAuthority" } } ], @@ -456,7 +557,7 @@ var doc = `{ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/model.SysAuthority" + "$ref": "#/definitions/system.SysAuthority" } } ], @@ -494,7 +595,7 @@ var doc = `{ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/model.SysAuthority" + "$ref": "#/definitions/system.SysAuthority" } } ], @@ -532,7 +633,7 @@ var doc = `{ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/model.AutoCodeStruct" + "$ref": "#/definitions/system.AutoCodeStruct" } } ], @@ -546,6 +647,44 @@ var doc = `{ } } }, + "/autoCode/delSysHistory": { + "post": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "AutoCode" + ], + "summary": "删除回滚记录", + "parameters": [ + { + "description": "删除回滚记录", + "name": "data", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/request.AutoHistoryByID" + } + } + ], + "responses": { + "200": { + "description": "{\"success\":true,\"data\":{},\"msg\":\"删除成功\"}", + "schema": { + "type": "string" + } + } + } + } + }, "/autoCode/getColumn": { "get": { "security": [ @@ -600,6 +739,82 @@ var doc = `{ } } }, + "/autoCode/getMeta": { + "post": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "AutoCode" + ], + "summary": "回滚", + "parameters": [ + { + "description": "获取meta信息", + "name": "data", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/request.AutoHistoryByID" + } + } + ], + "responses": { + "200": { + "description": "{\"success\":true,\"data\":{},\"msg\":\"获取成功\"}", + "schema": { + "type": "string" + } + } + } + } + }, + "/autoCode/getSysHistory": { + "post": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "AutoCode" + ], + "summary": "查询回滚记录", + "parameters": [ + { + "description": "查询回滚记录", + "name": "data", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/request.SysAutoHistory" + } + } + ], + "responses": { + "200": { + "description": "{\"success\":true,\"data\":{},\"msg\":\"获取成功\"}", + "schema": { + "type": "string" + } + } + } + } + }, "/autoCode/getTables": { "get": { "security": [ @@ -651,7 +866,7 @@ var doc = `{ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/model.AutoCodeStruct" + "$ref": "#/definitions/system.AutoCodeStruct" } } ], @@ -665,6 +880,234 @@ var doc = `{ } } }, + "/autoCode/rollback": { + "post": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "AutoCode" + ], + "summary": "回滚", + "parameters": [ + { + "description": "回滚自动生成代码", + "name": "data", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/request.AutoHistoryByID" + } + } + ], + "responses": { + "200": { + "description": "{\"success\":true,\"data\":{},\"msg\":\"回滚成功\"}", + "schema": { + "type": "string" + } + } + } + } + }, + "/autoCodeExample/createAutoCodeExample": { + "post": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "AutoCodeExample" + ], + "summary": "创建AutoCodeExample", + "parameters": [ + { + "description": "AutoCodeExample模型", + "name": "data", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/autocode.AutoCodeExample" + } + } + ], + "responses": { + "200": { + "description": "{\"success\":true,\"data\":{},\"msg\":\"创建成功\"}", + "schema": { + "type": "string" + } + } + } + } + }, + "/autoCodeExample/deleteAutoCodeExample": { + "delete": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "AutoCodeExample" + ], + "summary": "删除AutoCodeExample", + "parameters": [ + { + "description": "AutoCodeExample模型", + "name": "data", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/autocode.AutoCodeExample" + } + } + ], + "responses": { + "200": { + "description": "{\"success\":true,\"data\":{},\"msg\":\"删除成功\"}", + "schema": { + "type": "string" + } + } + } + } + }, + "/autoCodeExample/findAutoCodeExample": { + "get": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "AutoCodeExample" + ], + "summary": "用id查询AutoCodeExample", + "parameters": [ + { + "description": "用id查询AutoCodeExample", + "name": "data", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/autocode.AutoCodeExample" + } + } + ], + "responses": { + "200": { + "description": "{\"success\":true,\"data\":{},\"msg\":\"查询成功\"}", + "schema": { + "type": "string" + } + } + } + } + }, + "/autoCodeExample/getAutoCodeExampleList": { + "get": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "AutoCodeExample" + ], + "summary": "分页获取AutoCodeExample列表", + "parameters": [ + { + "description": "页码, 每页大小, 搜索条件", + "name": "data", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/request.AutoCodeExampleSearch" + } + } + ], + "responses": { + "200": { + "description": "{\"success\":true,\"data\":{},\"msg\":\"获取成功\"}", + "schema": { + "type": "string" + } + } + } + } + }, + "/autoCodeExample/updateAutoCodeExample": { + "put": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "AutoCodeExample" + ], + "summary": "更新AutoCodeExample", + "parameters": [ + { + "description": "更新AutoCodeExample", + "name": "data", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/autocode.AutoCodeExample" + } + } + ], + "responses": { + "200": { + "description": "{\"success\":true,\"data\":{},\"msg\":\"更新成功\"}", + "schema": { + "type": "string" + } + } + } + } + }, "/base/captcha": { "post": { "security": [ @@ -822,7 +1265,7 @@ var doc = `{ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/model.ExaCustomer" + "$ref": "#/definitions/example.ExaCustomer" } } ], @@ -858,7 +1301,7 @@ var doc = `{ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/model.ExaCustomer" + "$ref": "#/definitions/example.ExaCustomer" } } ], @@ -894,7 +1337,7 @@ var doc = `{ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/model.ExaCustomer" + "$ref": "#/definitions/example.ExaCustomer" } } ], @@ -930,7 +1373,7 @@ var doc = `{ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/model.ExaCustomer" + "$ref": "#/definitions/example.ExaCustomer" } } ], @@ -1063,7 +1506,7 @@ var doc = `{ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/model.ExcelInfo" + "$ref": "#/definitions/example.ExcelInfo" } } ], @@ -1191,7 +1634,7 @@ var doc = `{ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/model.ExaFileUploadAndDownload" + "$ref": "#/definitions/example.ExaFileUploadAndDownload" } } ], @@ -1489,7 +1932,7 @@ var doc = `{ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/model.SysBaseMenu" + "$ref": "#/definitions/system.SysBaseMenu" } } ], @@ -1749,7 +2192,7 @@ var doc = `{ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/model.SysBaseMenu" + "$ref": "#/definitions/system.SysBaseMenu" } } ], @@ -1763,108 +2206,6 @@ var doc = `{ } } }, - "/simpleUploader/checkFileMd5": { - "get": { - "security": [ - { - "ApiKeyAuth": [] - } - ], - "produces": [ - "application/json" - ], - "tags": [ - "SimpleUploader" - ], - "summary": "断点续传插件版示例", - "parameters": [ - { - "type": "string", - "description": "md5", - "name": "md5", - "in": "query", - "required": true - } - ], - "responses": { - "200": { - "description": "{\"success\":true,\"data\":{},\"msg\":\"查询成功\"}", - "schema": { - "type": "string" - } - } - } - } - }, - "/simpleUploader/mergeFileMd5": { - "get": { - "security": [ - { - "ApiKeyAuth": [] - } - ], - "produces": [ - "application/json" - ], - "tags": [ - "SimpleUploader" - ], - "summary": "合并文件", - "parameters": [ - { - "type": "string", - "description": "md5", - "name": "md5", - "in": "query", - "required": true - } - ], - "responses": { - "200": { - "description": "{\"success\":true,\"data\":{},\"msg\":\"合并成功\"}", - "schema": { - "type": "string" - } - } - } - } - }, - "/simpleUploader/upload": { - "post": { - "security": [ - { - "ApiKeyAuth": [] - } - ], - "consumes": [ - "multipart/form-data" - ], - "produces": [ - "application/json" - ], - "tags": [ - "SimpleUploader" - ], - "summary": "断点续传插件版示例", - "parameters": [ - { - "type": "file", - "description": "断点续传插件版示例", - "name": "file", - "in": "formData", - "required": true - } - ], - "responses": { - "200": { - "description": "{\"success\":true,\"data\":{},\"msg\":\"切片创建成功\"}", - "schema": { - "type": "string" - } - } - } - } - }, "/sysDictionary/createSysDictionary": { "post": { "security": [ @@ -1889,7 +2230,7 @@ var doc = `{ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/model.SysDictionary" + "$ref": "#/definitions/system.SysDictionary" } } ], @@ -1927,7 +2268,7 @@ var doc = `{ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/model.SysDictionary" + "$ref": "#/definitions/system.SysDictionary" } } ], @@ -1965,7 +2306,7 @@ var doc = `{ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/model.SysDictionary" + "$ref": "#/definitions/system.SysDictionary" } } ], @@ -2041,7 +2382,7 @@ var doc = `{ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/model.SysDictionary" + "$ref": "#/definitions/system.SysDictionary" } } ], @@ -2079,7 +2420,7 @@ var doc = `{ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/model.SysDictionaryDetail" + "$ref": "#/definitions/system.SysDictionaryDetail" } } ], @@ -2117,7 +2458,7 @@ var doc = `{ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/model.SysDictionaryDetail" + "$ref": "#/definitions/system.SysDictionaryDetail" } } ], @@ -2155,7 +2496,7 @@ var doc = `{ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/model.SysDictionaryDetail" + "$ref": "#/definitions/system.SysDictionaryDetail" } } ], @@ -2231,7 +2572,7 @@ var doc = `{ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/model.SysDictionaryDetail" + "$ref": "#/definitions/system.SysDictionaryDetail" } } ], @@ -2269,7 +2610,7 @@ var doc = `{ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/model.SysOperationRecord" + "$ref": "#/definitions/system.SysOperationRecord" } } ], @@ -2307,7 +2648,7 @@ var doc = `{ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/model.SysOperationRecord" + "$ref": "#/definitions/system.SysOperationRecord" } } ], @@ -2383,7 +2724,7 @@ var doc = `{ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/model.SysOperationRecord" + "$ref": "#/definitions/system.SysOperationRecord" } } ], @@ -2528,7 +2869,7 @@ var doc = `{ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/model.System" + "$ref": "#/definitions/system.System" } } ], @@ -2669,7 +3010,7 @@ var doc = `{ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/model.SysUser" + "$ref": "#/definitions/request.Register" } } ], @@ -2745,7 +3086,7 @@ var doc = `{ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/model.SysUser" + "$ref": "#/definitions/system.SysUser" } } ], @@ -2761,6 +3102,27 @@ var doc = `{ } }, "definitions": { + "autocode.AutoCodeExample": { + "type": "object", + "properties": { + "autoCodeExampleField": { + "description": "展示值", + "type": "string" + }, + "createdAt": { + "description": "创建时间", + "type": "string" + }, + "id": { + "description": "主键ID", + "type": "integer" + }, + "updatedAt": { + "description": "更新时间", + "type": "string" + } + } + }, "config.AliyunOSS": { "type": "object", "properties": { @@ -2770,6 +3132,9 @@ var doc = `{ "accessKeySecret": { "type": "string" }, + "basePath": { + "type": "string" + }, "bucketName": { "type": "string" }, @@ -2808,6 +3173,9 @@ var doc = `{ "serverService": { "type": "string" }, + "transferRestart": { + "type": "boolean" + }, "web": { "type": "string" }, @@ -2948,10 +3316,11 @@ var doc = `{ }, "logMode": { "description": "是否开启Gorm全局日志", - "type": "boolean" + "type": "string" }, "logZap": { - "type": "string" + "description": "是否通过zap写入日志文件", + "type": "boolean" }, "maxIdleConns": { "description": "空闲中的最大连接数", @@ -3186,46 +3555,7 @@ var doc = `{ } } }, - "model.AutoCodeStruct": { - "type": "object", - "properties": { - "abbreviation": { - "description": "Struct简称", - "type": "string" - }, - "autoCreateApiToSql": { - "description": "是否自动创建api", - "type": "boolean" - }, - "autoMoveFile": { - "description": "是否自动移动文件", - "type": "boolean" - }, - "description": { - "description": "Struct中文名称", - "type": "string" - }, - "fields": { - "type": "array", - "items": { - "$ref": "#/definitions/model.Field" - } - }, - "packageName": { - "description": "文件名称", - "type": "string" - }, - "structName": { - "description": "Struct名称", - "type": "string" - }, - "tableName": { - "description": "表名", - "type": "string" - } - } - }, - "model.ExaCustomer": { + "example.ExaCustomer": { "type": "object", "properties": { "createdAt": { @@ -3246,7 +3576,7 @@ var doc = `{ }, "sysUser": { "description": "管理详情", - "$ref": "#/definitions/model.SysUser" + "$ref": "#/definitions/system.SysUser" }, "sysUserAuthorityID": { "description": "管理角色ID", @@ -3262,7 +3592,7 @@ var doc = `{ } } }, - "model.ExaFileUploadAndDownload": { + "example.ExaFileUploadAndDownload": { "type": "object", "properties": { "createdAt": { @@ -3295,7 +3625,7 @@ var doc = `{ } } }, - "model.ExcelInfo": { + "example.ExcelInfo": { "type": "object", "properties": { "fileName": { @@ -3305,434 +3635,11 @@ var doc = `{ "infoList": { "type": "array", "items": { - "$ref": "#/definitions/model.SysBaseMenu" + "$ref": "#/definitions/system.SysBaseMenu" } } } }, - "model.Field": { - "type": "object", - "properties": { - "columnName": { - "description": "数据库字段", - "type": "string" - }, - "comment": { - "description": "数据库字段描述", - "type": "string" - }, - "dataType": { - "description": "数据库字段类型", - "type": "string" - }, - "dataTypeLong": { - "description": "数据库字段长度", - "type": "string" - }, - "dictType": { - "description": "字典", - "type": "string" - }, - "fieldDesc": { - "description": "中文名", - "type": "string" - }, - "fieldJson": { - "description": "FieldJson", - "type": "string" - }, - "fieldName": { - "description": "Field名", - "type": "string" - }, - "fieldSearchType": { - "description": "搜索条件", - "type": "string" - }, - "fieldType": { - "description": "Field数据类型", - "type": "string" - } - } - }, - "model.SysApi": { - "type": "object", - "properties": { - "apiGroup": { - "description": "api组", - "type": "string" - }, - "createdAt": { - "description": "创建时间", - "type": "string" - }, - "description": { - "description": "api中文描述", - "type": "string" - }, - "id": { - "description": "主键ID", - "type": "integer" - }, - "method": { - "description": "方法:创建POST(默认)|查看GET|更新PUT|删除DELETE", - "type": "string" - }, - "path": { - "description": "api路径", - "type": "string" - }, - "updatedAt": { - "description": "更新时间", - "type": "string" - } - } - }, - "model.SysAuthority": { - "type": "object", - "properties": { - "authorityId": { - "description": "角色ID", - "type": "string" - }, - "authorityName": { - "description": "角色名", - "type": "string" - }, - "children": { - "type": "array", - "items": { - "$ref": "#/definitions/model.SysAuthority" - } - }, - "createdAt": { - "description": "创建时间", - "type": "string" - }, - "dataAuthorityId": { - "type": "array", - "items": { - "$ref": "#/definitions/model.SysAuthority" - } - }, - "defaultRouter": { - "description": "默认菜单(默认dashboard)", - "type": "string" - }, - "deletedAt": { - "type": "string" - }, - "menus": { - "type": "array", - "items": { - "$ref": "#/definitions/model.SysBaseMenu" - } - }, - "parentId": { - "description": "父角色ID", - "type": "string" - }, - "updatedAt": { - "description": "更新时间", - "type": "string" - } - } - }, - "model.SysBaseMenu": { - "type": "object", - "properties": { - "authoritys": { - "type": "array", - "items": { - "$ref": "#/definitions/model.SysAuthority" - } - }, - "children": { - "type": "array", - "items": { - "$ref": "#/definitions/model.SysBaseMenu" - } - }, - "closeTab": { - "description": "自动关闭tab", - "type": "boolean" - }, - "component": { - "description": "对应前端文件路径", - "type": "string" - }, - "createdAt": { - "description": "创建时间", - "type": "string" - }, - "defaultMenu": { - "description": "是否是基础路由(开发中)", - "type": "boolean" - }, - "hidden": { - "description": "是否在列表隐藏", - "type": "boolean" - }, - "icon": { - "description": "菜单图标", - "type": "string" - }, - "id": { - "description": "主键ID", - "type": "integer" - }, - "keepAlive": { - "description": "是否缓存", - "type": "boolean" - }, - "name": { - "description": "路由name", - "type": "string" - }, - "parameters": { - "type": "array", - "items": { - "$ref": "#/definitions/model.SysBaseMenuParameter" - } - }, - "parentId": { - "description": "父菜单ID", - "type": "string" - }, - "path": { - "description": "路由path", - "type": "string" - }, - "sort": { - "description": "排序标记", - "type": "integer" - }, - "title": { - "description": "菜单名", - "type": "string" - }, - "updatedAt": { - "description": "更新时间", - "type": "string" - } - } - }, - "model.SysBaseMenuParameter": { - "type": "object", - "properties": { - "createdAt": { - "description": "创建时间", - "type": "string" - }, - "id": { - "description": "主键ID", - "type": "integer" - }, - "key": { - "description": "地址栏携带参数的key", - "type": "string" - }, - "sysBaseMenuID": { - "type": "integer" - }, - "type": { - "description": "地址栏携带参数为params还是query", - "type": "string" - }, - "updatedAt": { - "description": "更新时间", - "type": "string" - }, - "value": { - "description": "地址栏携带参数的值", - "type": "string" - } - } - }, - "model.SysDictionary": { - "type": "object", - "properties": { - "createdAt": { - "description": "创建时间", - "type": "string" - }, - "desc": { - "description": "描述", - "type": "string" - }, - "id": { - "description": "主键ID", - "type": "integer" - }, - "name": { - "description": "字典名(中)", - "type": "string" - }, - "status": { - "description": "状态", - "type": "boolean" - }, - "sysDictionaryDetails": { - "type": "array", - "items": { - "$ref": "#/definitions/model.SysDictionaryDetail" - } - }, - "type": { - "description": "字典名(英)", - "type": "string" - }, - "updatedAt": { - "description": "更新时间", - "type": "string" - } - } - }, - "model.SysDictionaryDetail": { - "type": "object", - "properties": { - "createdAt": { - "description": "创建时间", - "type": "string" - }, - "id": { - "description": "主键ID", - "type": "integer" - }, - "label": { - "description": "展示值", - "type": "string" - }, - "sort": { - "description": "排序标记", - "type": "integer" - }, - "status": { - "description": "启用状态", - "type": "boolean" - }, - "sysDictionaryID": { - "description": "关联标记", - "type": "integer" - }, - "updatedAt": { - "description": "更新时间", - "type": "string" - }, - "value": { - "description": "字典值", - "type": "integer" - } - } - }, - "model.SysOperationRecord": { - "type": "object", - "properties": { - "agent": { - "description": "代理", - "type": "string" - }, - "body": { - "description": "请求Body", - "type": "string" - }, - "createdAt": { - "description": "创建时间", - "type": "string" - }, - "error_message": { - "description": "错误信息", - "type": "string" - }, - "id": { - "description": "主键ID", - "type": "integer" - }, - "ip": { - "description": "请求ip", - "type": "string" - }, - "latency": { - "description": "延迟", - "type": "string" - }, - "method": { - "description": "请求方法", - "type": "string" - }, - "path": { - "description": "请求路径", - "type": "string" - }, - "resp": { - "description": "响应Body", - "type": "string" - }, - "status": { - "description": "请求状态", - "type": "integer" - }, - "updatedAt": { - "description": "更新时间", - "type": "string" - }, - "user": { - "$ref": "#/definitions/model.SysUser" - }, - "user_id": { - "description": "用户id", - "type": "integer" - } - } - }, - "model.SysUser": { - "type": "object", - "properties": { - "authority": { - "$ref": "#/definitions/model.SysAuthority" - }, - "authorityId": { - "description": "用户角色ID", - "type": "string" - }, - "createdAt": { - "description": "创建时间", - "type": "string" - }, - "headerImg": { - "description": "用户头像", - "type": "string" - }, - "id": { - "description": "主键ID", - "type": "integer" - }, - "nickName": { - "description": "用户昵称", - "type": "string" - }, - "updatedAt": { - "description": "更新时间", - "type": "string" - }, - "userName": { - "description": "用户登录名", - "type": "string" - }, - "uuid": { - "description": "用户UUID", - "type": "string" - } - } - }, - "model.System": { - "type": "object", - "properties": { - "config": { - "$ref": "#/definitions/config.Server" - } - } - }, "request.AddMenuAuthorityInfo": { "type": "object", "properties": { @@ -3743,11 +3650,48 @@ var doc = `{ "menus": { "type": "array", "items": { - "$ref": "#/definitions/model.SysBaseMenu" + "$ref": "#/definitions/system.SysBaseMenu" } } } }, + "request.AutoCodeExampleSearch": { + "type": "object", + "properties": { + "autoCodeExampleField": { + "description": "展示值", + "type": "string" + }, + "createdAt": { + "description": "创建时间", + "type": "string" + }, + "id": { + "description": "主键ID", + "type": "integer" + }, + "page": { + "description": "页码", + "type": "integer" + }, + "pageSize": { + "description": "每页大小", + "type": "integer" + }, + "updatedAt": { + "description": "更新时间", + "type": "string" + } + } + }, + "request.AutoHistoryByID": { + "type": "object", + "properties": { + "id": { + "type": "integer" + } + } + }, "request.CasbinInReceive": { "type": "object", "properties": { @@ -3888,6 +3832,26 @@ var doc = `{ } } }, + "request.Register": { + "type": "object", + "properties": { + "authorityId": { + "type": "string" + }, + "headerImg": { + "type": "string" + }, + "nickName": { + "type": "string" + }, + "passWord": { + "type": "string" + }, + "userName": { + "type": "string" + } + } + }, "request.SearchApiParams": { "type": "object", "properties": { @@ -3950,6 +3914,19 @@ var doc = `{ } } }, + "request.SysAutoHistory": { + "type": "object", + "properties": { + "page": { + "description": "页码", + "type": "integer" + }, + "pageSize": { + "description": "每页大小", + "type": "integer" + } + } + }, "request.SysDictionaryDetailSearch": { "type": "object", "properties": { @@ -4029,7 +4006,7 @@ var doc = `{ "sysDictionaryDetails": { "type": "array", "items": { - "$ref": "#/definitions/model.SysDictionaryDetail" + "$ref": "#/definitions/system.SysDictionaryDetail" } }, "type": { @@ -4102,7 +4079,7 @@ var doc = `{ "type": "string" }, "user": { - "$ref": "#/definitions/model.SysUser" + "$ref": "#/definitions/system.SysUser" }, "user_id": { "description": "用户id", @@ -4114,13 +4091,491 @@ var doc = `{ "type": "object", "properties": { "authority": { - "$ref": "#/definitions/model.SysAuthority" + "$ref": "#/definitions/system.SysAuthority" }, "oldAuthorityId": { "description": "旧角色ID", "type": "string" } } + }, + "system.AutoCodeStruct": { + "type": "object", + "properties": { + "abbreviation": { + "description": "Struct简称", + "type": "string" + }, + "autoCreateApiToSql": { + "description": "是否自动创建api", + "type": "boolean" + }, + "autoMoveFile": { + "description": "是否自动移动文件", + "type": "boolean" + }, + "description": { + "description": "Struct中文名称", + "type": "string" + }, + "fields": { + "type": "array", + "items": { + "$ref": "#/definitions/system.Field" + } + }, + "humpPackageName": { + "description": "go文件名称", + "type": "string" + }, + "packageName": { + "description": "文件名称", + "type": "string" + }, + "structName": { + "description": "Struct名称", + "type": "string" + }, + "tableName": { + "description": "表名", + "type": "string" + } + } + }, + "system.Field": { + "type": "object", + "properties": { + "columnName": { + "description": "数据库字段", + "type": "string" + }, + "comment": { + "description": "数据库字段描述", + "type": "string" + }, + "dataType": { + "description": "数据库字段类型", + "type": "string" + }, + "dataTypeLong": { + "description": "数据库字段长度", + "type": "string" + }, + "dictType": { + "description": "字典", + "type": "string" + }, + "fieldDesc": { + "description": "中文名", + "type": "string" + }, + "fieldJson": { + "description": "FieldJson", + "type": "string" + }, + "fieldName": { + "description": "Field名", + "type": "string" + }, + "fieldSearchType": { + "description": "搜索条件", + "type": "string" + }, + "fieldType": { + "description": "Field数据类型", + "type": "string" + } + } + }, + "system.SysApi": { + "type": "object", + "properties": { + "apiGroup": { + "description": "api组", + "type": "string" + }, + "createdAt": { + "description": "创建时间", + "type": "string" + }, + "description": { + "description": "api中文描述", + "type": "string" + }, + "id": { + "description": "主键ID", + "type": "integer" + }, + "method": { + "description": "方法:创建POST(默认)|查看GET|更新PUT|删除DELETE", + "type": "string" + }, + "path": { + "description": "api路径", + "type": "string" + }, + "updatedAt": { + "description": "更新时间", + "type": "string" + } + } + }, + "system.SysAuthority": { + "type": "object", + "properties": { + "authorityId": { + "description": "角色ID", + "type": "string" + }, + "authorityName": { + "description": "角色名", + "type": "string" + }, + "children": { + "type": "array", + "items": { + "$ref": "#/definitions/system.SysAuthority" + } + }, + "createdAt": { + "description": "创建时间", + "type": "string" + }, + "dataAuthorityId": { + "type": "array", + "items": { + "$ref": "#/definitions/system.SysAuthority" + } + }, + "defaultRouter": { + "description": "默认菜单(默认dashboard)", + "type": "string" + }, + "deletedAt": { + "type": "string" + }, + "menus": { + "type": "array", + "items": { + "$ref": "#/definitions/system.SysBaseMenu" + } + }, + "parentId": { + "description": "父角色ID", + "type": "string" + }, + "updatedAt": { + "description": "更新时间", + "type": "string" + } + } + }, + "system.SysBaseMenu": { + "type": "object", + "properties": { + "authoritys": { + "type": "array", + "items": { + "$ref": "#/definitions/system.SysAuthority" + } + }, + "children": { + "type": "array", + "items": { + "$ref": "#/definitions/system.SysBaseMenu" + } + }, + "closeTab": { + "description": "自动关闭tab", + "type": "boolean" + }, + "component": { + "description": "对应前端文件路径", + "type": "string" + }, + "createdAt": { + "description": "创建时间", + "type": "string" + }, + "defaultMenu": { + "description": "是否是基础路由(开发中)", + "type": "boolean" + }, + "hidden": { + "description": "是否在列表隐藏", + "type": "boolean" + }, + "icon": { + "description": "菜单图标", + "type": "string" + }, + "id": { + "description": "主键ID", + "type": "integer" + }, + "keepAlive": { + "description": "是否缓存", + "type": "boolean" + }, + "name": { + "description": "路由name", + "type": "string" + }, + "parameters": { + "type": "array", + "items": { + "$ref": "#/definitions/system.SysBaseMenuParameter" + } + }, + "parentId": { + "description": "父菜单ID", + "type": "string" + }, + "path": { + "description": "路由path", + "type": "string" + }, + "sort": { + "description": "排序标记", + "type": "integer" + }, + "title": { + "description": "菜单名", + "type": "string" + }, + "updatedAt": { + "description": "更新时间", + "type": "string" + } + } + }, + "system.SysBaseMenuParameter": { + "type": "object", + "properties": { + "createdAt": { + "description": "创建时间", + "type": "string" + }, + "id": { + "description": "主键ID", + "type": "integer" + }, + "key": { + "description": "地址栏携带参数的key", + "type": "string" + }, + "sysBaseMenuID": { + "type": "integer" + }, + "type": { + "description": "地址栏携带参数为params还是query", + "type": "string" + }, + "updatedAt": { + "description": "更新时间", + "type": "string" + }, + "value": { + "description": "地址栏携带参数的值", + "type": "string" + } + } + }, + "system.SysDictionary": { + "type": "object", + "properties": { + "createdAt": { + "description": "创建时间", + "type": "string" + }, + "desc": { + "description": "描述", + "type": "string" + }, + "id": { + "description": "主键ID", + "type": "integer" + }, + "name": { + "description": "字典名(中)", + "type": "string" + }, + "status": { + "description": "状态", + "type": "boolean" + }, + "sysDictionaryDetails": { + "type": "array", + "items": { + "$ref": "#/definitions/system.SysDictionaryDetail" + } + }, + "type": { + "description": "字典名(英)", + "type": "string" + }, + "updatedAt": { + "description": "更新时间", + "type": "string" + } + } + }, + "system.SysDictionaryDetail": { + "type": "object", + "properties": { + "createdAt": { + "description": "创建时间", + "type": "string" + }, + "id": { + "description": "主键ID", + "type": "integer" + }, + "label": { + "description": "展示值", + "type": "string" + }, + "sort": { + "description": "排序标记", + "type": "integer" + }, + "status": { + "description": "启用状态", + "type": "boolean" + }, + "sysDictionaryID": { + "description": "关联标记", + "type": "integer" + }, + "updatedAt": { + "description": "更新时间", + "type": "string" + }, + "value": { + "description": "字典值", + "type": "integer" + } + } + }, + "system.SysOperationRecord": { + "type": "object", + "properties": { + "agent": { + "description": "代理", + "type": "string" + }, + "body": { + "description": "请求Body", + "type": "string" + }, + "createdAt": { + "description": "创建时间", + "type": "string" + }, + "error_message": { + "description": "错误信息", + "type": "string" + }, + "id": { + "description": "主键ID", + "type": "integer" + }, + "ip": { + "description": "请求ip", + "type": "string" + }, + "latency": { + "description": "延迟", + "type": "string" + }, + "method": { + "description": "请求方法", + "type": "string" + }, + "path": { + "description": "请求路径", + "type": "string" + }, + "resp": { + "description": "响应Body", + "type": "string" + }, + "status": { + "description": "请求状态", + "type": "integer" + }, + "updatedAt": { + "description": "更新时间", + "type": "string" + }, + "user": { + "$ref": "#/definitions/system.SysUser" + }, + "user_id": { + "description": "用户id", + "type": "integer" + } + } + }, + "system.SysUser": { + "type": "object", + "properties": { + "activeColor": { + "description": "活跃颜色", + "type": "string" + }, + "authority": { + "$ref": "#/definitions/system.SysAuthority" + }, + "authorityId": { + "description": "用户角色ID", + "type": "string" + }, + "baseColor": { + "description": "基础颜色", + "type": "string" + }, + "createdAt": { + "description": "创建时间", + "type": "string" + }, + "headerImg": { + "description": "用户头像", + "type": "string" + }, + "id": { + "description": "主键ID", + "type": "integer" + }, + "nickName": { + "description": "用户昵称", + "type": "string" + }, + "sideMode": { + "description": "用户侧边主题", + "type": "string" + }, + "updatedAt": { + "description": "更新时间", + "type": "string" + }, + "userName": { + "description": "用户登录名", + "type": "string" + }, + "uuid": { + "description": "用户UUID", + "type": "string" + } + } + }, + "system.System": { + "type": "object", + "properties": { + "config": { + "$ref": "#/definitions/config.Server" + } + } } }, "securityDefinitions": { diff --git a/server/docs/swagger.json b/server/docs/swagger.json index 9884a45d..9fc6f9ab 100644 --- a/server/docs/swagger.json +++ b/server/docs/swagger.json @@ -8,6 +8,108 @@ }, "basePath": "/", "paths": { + "/SimpleUploaderApi/checkFileMd5": { + "get": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "produces": [ + "application/json" + ], + "tags": [ + "SimpleUploader" + ], + "summary": "断点续传插件版示例", + "parameters": [ + { + "type": "string", + "description": "md5", + "name": "md5", + "in": "query", + "required": true + } + ], + "responses": { + "200": { + "description": "{\"success\":true,\"data\":{},\"msg\":\"查询成功\"}", + "schema": { + "type": "string" + } + } + } + } + }, + "/SimpleUploaderApi/mergeFileMd5": { + "get": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "produces": [ + "application/json" + ], + "tags": [ + "SimpleUploader" + ], + "summary": "合并文件", + "parameters": [ + { + "type": "string", + "description": "md5", + "name": "md5", + "in": "query", + "required": true + } + ], + "responses": { + "200": { + "description": "{\"success\":true,\"data\":{},\"msg\":\"合并成功\"}", + "schema": { + "type": "string" + } + } + } + } + }, + "/SimpleUploaderApi/upload": { + "post": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "consumes": [ + "multipart/form-data" + ], + "produces": [ + "application/json" + ], + "tags": [ + "SimpleUploader" + ], + "summary": "断点续传插件版示例", + "parameters": [ + { + "type": "file", + "description": "断点续传插件版示例", + "name": "file", + "in": "formData", + "required": true + } + ], + "responses": { + "200": { + "description": "{\"success\":true,\"data\":{},\"msg\":\"切片创建成功\"}", + "schema": { + "type": "string" + } + } + } + } + }, "/api/createApi": { "post": { "security": [ @@ -32,7 +134,7 @@ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/model.SysApi" + "$ref": "#/definitions/system.SysApi" } } ], @@ -70,7 +172,7 @@ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/model.SysApi" + "$ref": "#/definitions/system.SysApi" } } ], @@ -249,7 +351,7 @@ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/model.SysApi" + "$ref": "#/definitions/system.SysApi" } } ], @@ -325,7 +427,7 @@ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/model.SysAuthority" + "$ref": "#/definitions/system.SysAuthority" } } ], @@ -363,7 +465,7 @@ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/model.SysAuthority" + "$ref": "#/definitions/system.SysAuthority" } } ], @@ -439,7 +541,7 @@ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/model.SysAuthority" + "$ref": "#/definitions/system.SysAuthority" } } ], @@ -477,7 +579,7 @@ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/model.SysAuthority" + "$ref": "#/definitions/system.SysAuthority" } } ], @@ -515,7 +617,7 @@ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/model.AutoCodeStruct" + "$ref": "#/definitions/system.AutoCodeStruct" } } ], @@ -529,6 +631,44 @@ } } }, + "/autoCode/delSysHistory": { + "post": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "AutoCode" + ], + "summary": "删除回滚记录", + "parameters": [ + { + "description": "删除回滚记录", + "name": "data", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/request.AutoHistoryByID" + } + } + ], + "responses": { + "200": { + "description": "{\"success\":true,\"data\":{},\"msg\":\"删除成功\"}", + "schema": { + "type": "string" + } + } + } + } + }, "/autoCode/getColumn": { "get": { "security": [ @@ -583,6 +723,82 @@ } } }, + "/autoCode/getMeta": { + "post": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "AutoCode" + ], + "summary": "回滚", + "parameters": [ + { + "description": "获取meta信息", + "name": "data", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/request.AutoHistoryByID" + } + } + ], + "responses": { + "200": { + "description": "{\"success\":true,\"data\":{},\"msg\":\"获取成功\"}", + "schema": { + "type": "string" + } + } + } + } + }, + "/autoCode/getSysHistory": { + "post": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "AutoCode" + ], + "summary": "查询回滚记录", + "parameters": [ + { + "description": "查询回滚记录", + "name": "data", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/request.SysAutoHistory" + } + } + ], + "responses": { + "200": { + "description": "{\"success\":true,\"data\":{},\"msg\":\"获取成功\"}", + "schema": { + "type": "string" + } + } + } + } + }, "/autoCode/getTables": { "get": { "security": [ @@ -634,7 +850,7 @@ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/model.AutoCodeStruct" + "$ref": "#/definitions/system.AutoCodeStruct" } } ], @@ -648,6 +864,234 @@ } } }, + "/autoCode/rollback": { + "post": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "AutoCode" + ], + "summary": "回滚", + "parameters": [ + { + "description": "回滚自动生成代码", + "name": "data", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/request.AutoHistoryByID" + } + } + ], + "responses": { + "200": { + "description": "{\"success\":true,\"data\":{},\"msg\":\"回滚成功\"}", + "schema": { + "type": "string" + } + } + } + } + }, + "/autoCodeExample/createAutoCodeExample": { + "post": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "AutoCodeExample" + ], + "summary": "创建AutoCodeExample", + "parameters": [ + { + "description": "AutoCodeExample模型", + "name": "data", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/autocode.AutoCodeExample" + } + } + ], + "responses": { + "200": { + "description": "{\"success\":true,\"data\":{},\"msg\":\"创建成功\"}", + "schema": { + "type": "string" + } + } + } + } + }, + "/autoCodeExample/deleteAutoCodeExample": { + "delete": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "AutoCodeExample" + ], + "summary": "删除AutoCodeExample", + "parameters": [ + { + "description": "AutoCodeExample模型", + "name": "data", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/autocode.AutoCodeExample" + } + } + ], + "responses": { + "200": { + "description": "{\"success\":true,\"data\":{},\"msg\":\"删除成功\"}", + "schema": { + "type": "string" + } + } + } + } + }, + "/autoCodeExample/findAutoCodeExample": { + "get": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "AutoCodeExample" + ], + "summary": "用id查询AutoCodeExample", + "parameters": [ + { + "description": "用id查询AutoCodeExample", + "name": "data", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/autocode.AutoCodeExample" + } + } + ], + "responses": { + "200": { + "description": "{\"success\":true,\"data\":{},\"msg\":\"查询成功\"}", + "schema": { + "type": "string" + } + } + } + } + }, + "/autoCodeExample/getAutoCodeExampleList": { + "get": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "AutoCodeExample" + ], + "summary": "分页获取AutoCodeExample列表", + "parameters": [ + { + "description": "页码, 每页大小, 搜索条件", + "name": "data", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/request.AutoCodeExampleSearch" + } + } + ], + "responses": { + "200": { + "description": "{\"success\":true,\"data\":{},\"msg\":\"获取成功\"}", + "schema": { + "type": "string" + } + } + } + } + }, + "/autoCodeExample/updateAutoCodeExample": { + "put": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "AutoCodeExample" + ], + "summary": "更新AutoCodeExample", + "parameters": [ + { + "description": "更新AutoCodeExample", + "name": "data", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/autocode.AutoCodeExample" + } + } + ], + "responses": { + "200": { + "description": "{\"success\":true,\"data\":{},\"msg\":\"更新成功\"}", + "schema": { + "type": "string" + } + } + } + } + }, "/base/captcha": { "post": { "security": [ @@ -805,7 +1249,7 @@ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/model.ExaCustomer" + "$ref": "#/definitions/example.ExaCustomer" } } ], @@ -841,7 +1285,7 @@ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/model.ExaCustomer" + "$ref": "#/definitions/example.ExaCustomer" } } ], @@ -877,7 +1321,7 @@ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/model.ExaCustomer" + "$ref": "#/definitions/example.ExaCustomer" } } ], @@ -913,7 +1357,7 @@ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/model.ExaCustomer" + "$ref": "#/definitions/example.ExaCustomer" } } ], @@ -1046,7 +1490,7 @@ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/model.ExcelInfo" + "$ref": "#/definitions/example.ExcelInfo" } } ], @@ -1174,7 +1618,7 @@ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/model.ExaFileUploadAndDownload" + "$ref": "#/definitions/example.ExaFileUploadAndDownload" } } ], @@ -1472,7 +1916,7 @@ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/model.SysBaseMenu" + "$ref": "#/definitions/system.SysBaseMenu" } } ], @@ -1732,7 +2176,7 @@ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/model.SysBaseMenu" + "$ref": "#/definitions/system.SysBaseMenu" } } ], @@ -1746,108 +2190,6 @@ } } }, - "/simpleUploader/checkFileMd5": { - "get": { - "security": [ - { - "ApiKeyAuth": [] - } - ], - "produces": [ - "application/json" - ], - "tags": [ - "SimpleUploader" - ], - "summary": "断点续传插件版示例", - "parameters": [ - { - "type": "string", - "description": "md5", - "name": "md5", - "in": "query", - "required": true - } - ], - "responses": { - "200": { - "description": "{\"success\":true,\"data\":{},\"msg\":\"查询成功\"}", - "schema": { - "type": "string" - } - } - } - } - }, - "/simpleUploader/mergeFileMd5": { - "get": { - "security": [ - { - "ApiKeyAuth": [] - } - ], - "produces": [ - "application/json" - ], - "tags": [ - "SimpleUploader" - ], - "summary": "合并文件", - "parameters": [ - { - "type": "string", - "description": "md5", - "name": "md5", - "in": "query", - "required": true - } - ], - "responses": { - "200": { - "description": "{\"success\":true,\"data\":{},\"msg\":\"合并成功\"}", - "schema": { - "type": "string" - } - } - } - } - }, - "/simpleUploader/upload": { - "post": { - "security": [ - { - "ApiKeyAuth": [] - } - ], - "consumes": [ - "multipart/form-data" - ], - "produces": [ - "application/json" - ], - "tags": [ - "SimpleUploader" - ], - "summary": "断点续传插件版示例", - "parameters": [ - { - "type": "file", - "description": "断点续传插件版示例", - "name": "file", - "in": "formData", - "required": true - } - ], - "responses": { - "200": { - "description": "{\"success\":true,\"data\":{},\"msg\":\"切片创建成功\"}", - "schema": { - "type": "string" - } - } - } - } - }, "/sysDictionary/createSysDictionary": { "post": { "security": [ @@ -1872,7 +2214,7 @@ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/model.SysDictionary" + "$ref": "#/definitions/system.SysDictionary" } } ], @@ -1910,7 +2252,7 @@ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/model.SysDictionary" + "$ref": "#/definitions/system.SysDictionary" } } ], @@ -1948,7 +2290,7 @@ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/model.SysDictionary" + "$ref": "#/definitions/system.SysDictionary" } } ], @@ -2024,7 +2366,7 @@ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/model.SysDictionary" + "$ref": "#/definitions/system.SysDictionary" } } ], @@ -2062,7 +2404,7 @@ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/model.SysDictionaryDetail" + "$ref": "#/definitions/system.SysDictionaryDetail" } } ], @@ -2100,7 +2442,7 @@ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/model.SysDictionaryDetail" + "$ref": "#/definitions/system.SysDictionaryDetail" } } ], @@ -2138,7 +2480,7 @@ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/model.SysDictionaryDetail" + "$ref": "#/definitions/system.SysDictionaryDetail" } } ], @@ -2214,7 +2556,7 @@ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/model.SysDictionaryDetail" + "$ref": "#/definitions/system.SysDictionaryDetail" } } ], @@ -2252,7 +2594,7 @@ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/model.SysOperationRecord" + "$ref": "#/definitions/system.SysOperationRecord" } } ], @@ -2290,7 +2632,7 @@ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/model.SysOperationRecord" + "$ref": "#/definitions/system.SysOperationRecord" } } ], @@ -2366,7 +2708,7 @@ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/model.SysOperationRecord" + "$ref": "#/definitions/system.SysOperationRecord" } } ], @@ -2511,7 +2853,7 @@ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/model.System" + "$ref": "#/definitions/system.System" } } ], @@ -2652,7 +2994,7 @@ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/model.SysUser" + "$ref": "#/definitions/request.Register" } } ], @@ -2728,7 +3070,7 @@ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/model.SysUser" + "$ref": "#/definitions/system.SysUser" } } ], @@ -2744,6 +3086,27 @@ } }, "definitions": { + "autocode.AutoCodeExample": { + "type": "object", + "properties": { + "autoCodeExampleField": { + "description": "展示值", + "type": "string" + }, + "createdAt": { + "description": "创建时间", + "type": "string" + }, + "id": { + "description": "主键ID", + "type": "integer" + }, + "updatedAt": { + "description": "更新时间", + "type": "string" + } + } + }, "config.AliyunOSS": { "type": "object", "properties": { @@ -2753,6 +3116,9 @@ "accessKeySecret": { "type": "string" }, + "basePath": { + "type": "string" + }, "bucketName": { "type": "string" }, @@ -2791,6 +3157,9 @@ "serverService": { "type": "string" }, + "transferRestart": { + "type": "boolean" + }, "web": { "type": "string" }, @@ -2931,10 +3300,11 @@ }, "logMode": { "description": "是否开启Gorm全局日志", - "type": "boolean" + "type": "string" }, "logZap": { - "type": "string" + "description": "是否通过zap写入日志文件", + "type": "boolean" }, "maxIdleConns": { "description": "空闲中的最大连接数", @@ -3169,46 +3539,7 @@ } } }, - "model.AutoCodeStruct": { - "type": "object", - "properties": { - "abbreviation": { - "description": "Struct简称", - "type": "string" - }, - "autoCreateApiToSql": { - "description": "是否自动创建api", - "type": "boolean" - }, - "autoMoveFile": { - "description": "是否自动移动文件", - "type": "boolean" - }, - "description": { - "description": "Struct中文名称", - "type": "string" - }, - "fields": { - "type": "array", - "items": { - "$ref": "#/definitions/model.Field" - } - }, - "packageName": { - "description": "文件名称", - "type": "string" - }, - "structName": { - "description": "Struct名称", - "type": "string" - }, - "tableName": { - "description": "表名", - "type": "string" - } - } - }, - "model.ExaCustomer": { + "example.ExaCustomer": { "type": "object", "properties": { "createdAt": { @@ -3229,7 +3560,7 @@ }, "sysUser": { "description": "管理详情", - "$ref": "#/definitions/model.SysUser" + "$ref": "#/definitions/system.SysUser" }, "sysUserAuthorityID": { "description": "管理角色ID", @@ -3245,7 +3576,7 @@ } } }, - "model.ExaFileUploadAndDownload": { + "example.ExaFileUploadAndDownload": { "type": "object", "properties": { "createdAt": { @@ -3278,7 +3609,7 @@ } } }, - "model.ExcelInfo": { + "example.ExcelInfo": { "type": "object", "properties": { "fileName": { @@ -3288,434 +3619,11 @@ "infoList": { "type": "array", "items": { - "$ref": "#/definitions/model.SysBaseMenu" + "$ref": "#/definitions/system.SysBaseMenu" } } } }, - "model.Field": { - "type": "object", - "properties": { - "columnName": { - "description": "数据库字段", - "type": "string" - }, - "comment": { - "description": "数据库字段描述", - "type": "string" - }, - "dataType": { - "description": "数据库字段类型", - "type": "string" - }, - "dataTypeLong": { - "description": "数据库字段长度", - "type": "string" - }, - "dictType": { - "description": "字典", - "type": "string" - }, - "fieldDesc": { - "description": "中文名", - "type": "string" - }, - "fieldJson": { - "description": "FieldJson", - "type": "string" - }, - "fieldName": { - "description": "Field名", - "type": "string" - }, - "fieldSearchType": { - "description": "搜索条件", - "type": "string" - }, - "fieldType": { - "description": "Field数据类型", - "type": "string" - } - } - }, - "model.SysApi": { - "type": "object", - "properties": { - "apiGroup": { - "description": "api组", - "type": "string" - }, - "createdAt": { - "description": "创建时间", - "type": "string" - }, - "description": { - "description": "api中文描述", - "type": "string" - }, - "id": { - "description": "主键ID", - "type": "integer" - }, - "method": { - "description": "方法:创建POST(默认)|查看GET|更新PUT|删除DELETE", - "type": "string" - }, - "path": { - "description": "api路径", - "type": "string" - }, - "updatedAt": { - "description": "更新时间", - "type": "string" - } - } - }, - "model.SysAuthority": { - "type": "object", - "properties": { - "authorityId": { - "description": "角色ID", - "type": "string" - }, - "authorityName": { - "description": "角色名", - "type": "string" - }, - "children": { - "type": "array", - "items": { - "$ref": "#/definitions/model.SysAuthority" - } - }, - "createdAt": { - "description": "创建时间", - "type": "string" - }, - "dataAuthorityId": { - "type": "array", - "items": { - "$ref": "#/definitions/model.SysAuthority" - } - }, - "defaultRouter": { - "description": "默认菜单(默认dashboard)", - "type": "string" - }, - "deletedAt": { - "type": "string" - }, - "menus": { - "type": "array", - "items": { - "$ref": "#/definitions/model.SysBaseMenu" - } - }, - "parentId": { - "description": "父角色ID", - "type": "string" - }, - "updatedAt": { - "description": "更新时间", - "type": "string" - } - } - }, - "model.SysBaseMenu": { - "type": "object", - "properties": { - "authoritys": { - "type": "array", - "items": { - "$ref": "#/definitions/model.SysAuthority" - } - }, - "children": { - "type": "array", - "items": { - "$ref": "#/definitions/model.SysBaseMenu" - } - }, - "closeTab": { - "description": "自动关闭tab", - "type": "boolean" - }, - "component": { - "description": "对应前端文件路径", - "type": "string" - }, - "createdAt": { - "description": "创建时间", - "type": "string" - }, - "defaultMenu": { - "description": "是否是基础路由(开发中)", - "type": "boolean" - }, - "hidden": { - "description": "是否在列表隐藏", - "type": "boolean" - }, - "icon": { - "description": "菜单图标", - "type": "string" - }, - "id": { - "description": "主键ID", - "type": "integer" - }, - "keepAlive": { - "description": "是否缓存", - "type": "boolean" - }, - "name": { - "description": "路由name", - "type": "string" - }, - "parameters": { - "type": "array", - "items": { - "$ref": "#/definitions/model.SysBaseMenuParameter" - } - }, - "parentId": { - "description": "父菜单ID", - "type": "string" - }, - "path": { - "description": "路由path", - "type": "string" - }, - "sort": { - "description": "排序标记", - "type": "integer" - }, - "title": { - "description": "菜单名", - "type": "string" - }, - "updatedAt": { - "description": "更新时间", - "type": "string" - } - } - }, - "model.SysBaseMenuParameter": { - "type": "object", - "properties": { - "createdAt": { - "description": "创建时间", - "type": "string" - }, - "id": { - "description": "主键ID", - "type": "integer" - }, - "key": { - "description": "地址栏携带参数的key", - "type": "string" - }, - "sysBaseMenuID": { - "type": "integer" - }, - "type": { - "description": "地址栏携带参数为params还是query", - "type": "string" - }, - "updatedAt": { - "description": "更新时间", - "type": "string" - }, - "value": { - "description": "地址栏携带参数的值", - "type": "string" - } - } - }, - "model.SysDictionary": { - "type": "object", - "properties": { - "createdAt": { - "description": "创建时间", - "type": "string" - }, - "desc": { - "description": "描述", - "type": "string" - }, - "id": { - "description": "主键ID", - "type": "integer" - }, - "name": { - "description": "字典名(中)", - "type": "string" - }, - "status": { - "description": "状态", - "type": "boolean" - }, - "sysDictionaryDetails": { - "type": "array", - "items": { - "$ref": "#/definitions/model.SysDictionaryDetail" - } - }, - "type": { - "description": "字典名(英)", - "type": "string" - }, - "updatedAt": { - "description": "更新时间", - "type": "string" - } - } - }, - "model.SysDictionaryDetail": { - "type": "object", - "properties": { - "createdAt": { - "description": "创建时间", - "type": "string" - }, - "id": { - "description": "主键ID", - "type": "integer" - }, - "label": { - "description": "展示值", - "type": "string" - }, - "sort": { - "description": "排序标记", - "type": "integer" - }, - "status": { - "description": "启用状态", - "type": "boolean" - }, - "sysDictionaryID": { - "description": "关联标记", - "type": "integer" - }, - "updatedAt": { - "description": "更新时间", - "type": "string" - }, - "value": { - "description": "字典值", - "type": "integer" - } - } - }, - "model.SysOperationRecord": { - "type": "object", - "properties": { - "agent": { - "description": "代理", - "type": "string" - }, - "body": { - "description": "请求Body", - "type": "string" - }, - "createdAt": { - "description": "创建时间", - "type": "string" - }, - "error_message": { - "description": "错误信息", - "type": "string" - }, - "id": { - "description": "主键ID", - "type": "integer" - }, - "ip": { - "description": "请求ip", - "type": "string" - }, - "latency": { - "description": "延迟", - "type": "string" - }, - "method": { - "description": "请求方法", - "type": "string" - }, - "path": { - "description": "请求路径", - "type": "string" - }, - "resp": { - "description": "响应Body", - "type": "string" - }, - "status": { - "description": "请求状态", - "type": "integer" - }, - "updatedAt": { - "description": "更新时间", - "type": "string" - }, - "user": { - "$ref": "#/definitions/model.SysUser" - }, - "user_id": { - "description": "用户id", - "type": "integer" - } - } - }, - "model.SysUser": { - "type": "object", - "properties": { - "authority": { - "$ref": "#/definitions/model.SysAuthority" - }, - "authorityId": { - "description": "用户角色ID", - "type": "string" - }, - "createdAt": { - "description": "创建时间", - "type": "string" - }, - "headerImg": { - "description": "用户头像", - "type": "string" - }, - "id": { - "description": "主键ID", - "type": "integer" - }, - "nickName": { - "description": "用户昵称", - "type": "string" - }, - "updatedAt": { - "description": "更新时间", - "type": "string" - }, - "userName": { - "description": "用户登录名", - "type": "string" - }, - "uuid": { - "description": "用户UUID", - "type": "string" - } - } - }, - "model.System": { - "type": "object", - "properties": { - "config": { - "$ref": "#/definitions/config.Server" - } - } - }, "request.AddMenuAuthorityInfo": { "type": "object", "properties": { @@ -3726,11 +3634,48 @@ "menus": { "type": "array", "items": { - "$ref": "#/definitions/model.SysBaseMenu" + "$ref": "#/definitions/system.SysBaseMenu" } } } }, + "request.AutoCodeExampleSearch": { + "type": "object", + "properties": { + "autoCodeExampleField": { + "description": "展示值", + "type": "string" + }, + "createdAt": { + "description": "创建时间", + "type": "string" + }, + "id": { + "description": "主键ID", + "type": "integer" + }, + "page": { + "description": "页码", + "type": "integer" + }, + "pageSize": { + "description": "每页大小", + "type": "integer" + }, + "updatedAt": { + "description": "更新时间", + "type": "string" + } + } + }, + "request.AutoHistoryByID": { + "type": "object", + "properties": { + "id": { + "type": "integer" + } + } + }, "request.CasbinInReceive": { "type": "object", "properties": { @@ -3871,6 +3816,26 @@ } } }, + "request.Register": { + "type": "object", + "properties": { + "authorityId": { + "type": "string" + }, + "headerImg": { + "type": "string" + }, + "nickName": { + "type": "string" + }, + "passWord": { + "type": "string" + }, + "userName": { + "type": "string" + } + } + }, "request.SearchApiParams": { "type": "object", "properties": { @@ -3933,6 +3898,19 @@ } } }, + "request.SysAutoHistory": { + "type": "object", + "properties": { + "page": { + "description": "页码", + "type": "integer" + }, + "pageSize": { + "description": "每页大小", + "type": "integer" + } + } + }, "request.SysDictionaryDetailSearch": { "type": "object", "properties": { @@ -4012,7 +3990,7 @@ "sysDictionaryDetails": { "type": "array", "items": { - "$ref": "#/definitions/model.SysDictionaryDetail" + "$ref": "#/definitions/system.SysDictionaryDetail" } }, "type": { @@ -4085,7 +4063,7 @@ "type": "string" }, "user": { - "$ref": "#/definitions/model.SysUser" + "$ref": "#/definitions/system.SysUser" }, "user_id": { "description": "用户id", @@ -4097,13 +4075,491 @@ "type": "object", "properties": { "authority": { - "$ref": "#/definitions/model.SysAuthority" + "$ref": "#/definitions/system.SysAuthority" }, "oldAuthorityId": { "description": "旧角色ID", "type": "string" } } + }, + "system.AutoCodeStruct": { + "type": "object", + "properties": { + "abbreviation": { + "description": "Struct简称", + "type": "string" + }, + "autoCreateApiToSql": { + "description": "是否自动创建api", + "type": "boolean" + }, + "autoMoveFile": { + "description": "是否自动移动文件", + "type": "boolean" + }, + "description": { + "description": "Struct中文名称", + "type": "string" + }, + "fields": { + "type": "array", + "items": { + "$ref": "#/definitions/system.Field" + } + }, + "humpPackageName": { + "description": "go文件名称", + "type": "string" + }, + "packageName": { + "description": "文件名称", + "type": "string" + }, + "structName": { + "description": "Struct名称", + "type": "string" + }, + "tableName": { + "description": "表名", + "type": "string" + } + } + }, + "system.Field": { + "type": "object", + "properties": { + "columnName": { + "description": "数据库字段", + "type": "string" + }, + "comment": { + "description": "数据库字段描述", + "type": "string" + }, + "dataType": { + "description": "数据库字段类型", + "type": "string" + }, + "dataTypeLong": { + "description": "数据库字段长度", + "type": "string" + }, + "dictType": { + "description": "字典", + "type": "string" + }, + "fieldDesc": { + "description": "中文名", + "type": "string" + }, + "fieldJson": { + "description": "FieldJson", + "type": "string" + }, + "fieldName": { + "description": "Field名", + "type": "string" + }, + "fieldSearchType": { + "description": "搜索条件", + "type": "string" + }, + "fieldType": { + "description": "Field数据类型", + "type": "string" + } + } + }, + "system.SysApi": { + "type": "object", + "properties": { + "apiGroup": { + "description": "api组", + "type": "string" + }, + "createdAt": { + "description": "创建时间", + "type": "string" + }, + "description": { + "description": "api中文描述", + "type": "string" + }, + "id": { + "description": "主键ID", + "type": "integer" + }, + "method": { + "description": "方法:创建POST(默认)|查看GET|更新PUT|删除DELETE", + "type": "string" + }, + "path": { + "description": "api路径", + "type": "string" + }, + "updatedAt": { + "description": "更新时间", + "type": "string" + } + } + }, + "system.SysAuthority": { + "type": "object", + "properties": { + "authorityId": { + "description": "角色ID", + "type": "string" + }, + "authorityName": { + "description": "角色名", + "type": "string" + }, + "children": { + "type": "array", + "items": { + "$ref": "#/definitions/system.SysAuthority" + } + }, + "createdAt": { + "description": "创建时间", + "type": "string" + }, + "dataAuthorityId": { + "type": "array", + "items": { + "$ref": "#/definitions/system.SysAuthority" + } + }, + "defaultRouter": { + "description": "默认菜单(默认dashboard)", + "type": "string" + }, + "deletedAt": { + "type": "string" + }, + "menus": { + "type": "array", + "items": { + "$ref": "#/definitions/system.SysBaseMenu" + } + }, + "parentId": { + "description": "父角色ID", + "type": "string" + }, + "updatedAt": { + "description": "更新时间", + "type": "string" + } + } + }, + "system.SysBaseMenu": { + "type": "object", + "properties": { + "authoritys": { + "type": "array", + "items": { + "$ref": "#/definitions/system.SysAuthority" + } + }, + "children": { + "type": "array", + "items": { + "$ref": "#/definitions/system.SysBaseMenu" + } + }, + "closeTab": { + "description": "自动关闭tab", + "type": "boolean" + }, + "component": { + "description": "对应前端文件路径", + "type": "string" + }, + "createdAt": { + "description": "创建时间", + "type": "string" + }, + "defaultMenu": { + "description": "是否是基础路由(开发中)", + "type": "boolean" + }, + "hidden": { + "description": "是否在列表隐藏", + "type": "boolean" + }, + "icon": { + "description": "菜单图标", + "type": "string" + }, + "id": { + "description": "主键ID", + "type": "integer" + }, + "keepAlive": { + "description": "是否缓存", + "type": "boolean" + }, + "name": { + "description": "路由name", + "type": "string" + }, + "parameters": { + "type": "array", + "items": { + "$ref": "#/definitions/system.SysBaseMenuParameter" + } + }, + "parentId": { + "description": "父菜单ID", + "type": "string" + }, + "path": { + "description": "路由path", + "type": "string" + }, + "sort": { + "description": "排序标记", + "type": "integer" + }, + "title": { + "description": "菜单名", + "type": "string" + }, + "updatedAt": { + "description": "更新时间", + "type": "string" + } + } + }, + "system.SysBaseMenuParameter": { + "type": "object", + "properties": { + "createdAt": { + "description": "创建时间", + "type": "string" + }, + "id": { + "description": "主键ID", + "type": "integer" + }, + "key": { + "description": "地址栏携带参数的key", + "type": "string" + }, + "sysBaseMenuID": { + "type": "integer" + }, + "type": { + "description": "地址栏携带参数为params还是query", + "type": "string" + }, + "updatedAt": { + "description": "更新时间", + "type": "string" + }, + "value": { + "description": "地址栏携带参数的值", + "type": "string" + } + } + }, + "system.SysDictionary": { + "type": "object", + "properties": { + "createdAt": { + "description": "创建时间", + "type": "string" + }, + "desc": { + "description": "描述", + "type": "string" + }, + "id": { + "description": "主键ID", + "type": "integer" + }, + "name": { + "description": "字典名(中)", + "type": "string" + }, + "status": { + "description": "状态", + "type": "boolean" + }, + "sysDictionaryDetails": { + "type": "array", + "items": { + "$ref": "#/definitions/system.SysDictionaryDetail" + } + }, + "type": { + "description": "字典名(英)", + "type": "string" + }, + "updatedAt": { + "description": "更新时间", + "type": "string" + } + } + }, + "system.SysDictionaryDetail": { + "type": "object", + "properties": { + "createdAt": { + "description": "创建时间", + "type": "string" + }, + "id": { + "description": "主键ID", + "type": "integer" + }, + "label": { + "description": "展示值", + "type": "string" + }, + "sort": { + "description": "排序标记", + "type": "integer" + }, + "status": { + "description": "启用状态", + "type": "boolean" + }, + "sysDictionaryID": { + "description": "关联标记", + "type": "integer" + }, + "updatedAt": { + "description": "更新时间", + "type": "string" + }, + "value": { + "description": "字典值", + "type": "integer" + } + } + }, + "system.SysOperationRecord": { + "type": "object", + "properties": { + "agent": { + "description": "代理", + "type": "string" + }, + "body": { + "description": "请求Body", + "type": "string" + }, + "createdAt": { + "description": "创建时间", + "type": "string" + }, + "error_message": { + "description": "错误信息", + "type": "string" + }, + "id": { + "description": "主键ID", + "type": "integer" + }, + "ip": { + "description": "请求ip", + "type": "string" + }, + "latency": { + "description": "延迟", + "type": "string" + }, + "method": { + "description": "请求方法", + "type": "string" + }, + "path": { + "description": "请求路径", + "type": "string" + }, + "resp": { + "description": "响应Body", + "type": "string" + }, + "status": { + "description": "请求状态", + "type": "integer" + }, + "updatedAt": { + "description": "更新时间", + "type": "string" + }, + "user": { + "$ref": "#/definitions/system.SysUser" + }, + "user_id": { + "description": "用户id", + "type": "integer" + } + } + }, + "system.SysUser": { + "type": "object", + "properties": { + "activeColor": { + "description": "活跃颜色", + "type": "string" + }, + "authority": { + "$ref": "#/definitions/system.SysAuthority" + }, + "authorityId": { + "description": "用户角色ID", + "type": "string" + }, + "baseColor": { + "description": "基础颜色", + "type": "string" + }, + "createdAt": { + "description": "创建时间", + "type": "string" + }, + "headerImg": { + "description": "用户头像", + "type": "string" + }, + "id": { + "description": "主键ID", + "type": "integer" + }, + "nickName": { + "description": "用户昵称", + "type": "string" + }, + "sideMode": { + "description": "用户侧边主题", + "type": "string" + }, + "updatedAt": { + "description": "更新时间", + "type": "string" + }, + "userName": { + "description": "用户登录名", + "type": "string" + }, + "uuid": { + "description": "用户UUID", + "type": "string" + } + } + }, + "system.System": { + "type": "object", + "properties": { + "config": { + "$ref": "#/definitions/config.Server" + } + } } }, "securityDefinitions": { diff --git a/server/docs/swagger.yaml b/server/docs/swagger.yaml index c8299717..429aa6f5 100644 --- a/server/docs/swagger.yaml +++ b/server/docs/swagger.yaml @@ -1,11 +1,28 @@ basePath: / definitions: + autocode.AutoCodeExample: + properties: + autoCodeExampleField: + description: 展示值 + type: string + createdAt: + description: 创建时间 + type: string + id: + description: 主键ID + type: integer + updatedAt: + description: 更新时间 + type: string + type: object config.AliyunOSS: properties: accessKeyId: type: string accessKeySecret: type: string + basePath: + type: string bucketName: type: string bucketUrl: @@ -31,6 +48,8 @@ definitions: type: string serverService: type: string + transferRestart: + type: boolean web: type: string webApi: @@ -129,9 +148,10 @@ definitions: type: string logMode: description: 是否开启Gorm全局日志 - type: boolean - logZap: type: string + logZap: + description: 是否通过zap写入日志文件 + type: boolean maxIdleConns: description: 空闲中的最大连接数 type: integer @@ -296,35 +316,7 @@ definitions: description: 栈名 type: string type: object - model.AutoCodeStruct: - properties: - abbreviation: - description: Struct简称 - type: string - autoCreateApiToSql: - description: 是否自动创建api - type: boolean - autoMoveFile: - description: 是否自动移动文件 - type: boolean - description: - description: Struct中文名称 - type: string - fields: - items: - $ref: '#/definitions/model.Field' - type: array - packageName: - description: 文件名称 - type: string - structName: - description: Struct名称 - type: string - tableName: - description: 表名 - type: string - type: object - model.ExaCustomer: + example.ExaCustomer: properties: createdAt: description: 创建时间 @@ -339,7 +331,7 @@ definitions: description: 主键ID type: integer sysUser: - $ref: '#/definitions/model.SysUser' + $ref: '#/definitions/system.SysUser' description: 管理详情 sysUserAuthorityID: description: 管理角色ID @@ -351,7 +343,7 @@ definitions: description: 更新时间 type: string type: object - model.ExaFileUploadAndDownload: + example.ExaFileUploadAndDownload: properties: createdAt: description: 创建时间 @@ -375,321 +367,16 @@ definitions: description: 文件地址 type: string type: object - model.ExcelInfo: + example.ExcelInfo: properties: fileName: description: 文件名 type: string infoList: items: - $ref: '#/definitions/model.SysBaseMenu' + $ref: '#/definitions/system.SysBaseMenu' type: array type: object - model.Field: - properties: - columnName: - description: 数据库字段 - type: string - comment: - description: 数据库字段描述 - type: string - dataType: - description: 数据库字段类型 - type: string - dataTypeLong: - description: 数据库字段长度 - type: string - dictType: - description: 字典 - type: string - fieldDesc: - description: 中文名 - type: string - fieldJson: - description: FieldJson - type: string - fieldName: - description: Field名 - type: string - fieldSearchType: - description: 搜索条件 - type: string - fieldType: - description: Field数据类型 - type: string - type: object - model.SysApi: - properties: - apiGroup: - description: api组 - type: string - createdAt: - description: 创建时间 - type: string - description: - description: api中文描述 - type: string - id: - description: 主键ID - type: integer - method: - description: 方法:创建POST(默认)|查看GET|更新PUT|删除DELETE - type: string - path: - description: api路径 - type: string - updatedAt: - description: 更新时间 - type: string - type: object - model.SysAuthority: - properties: - authorityId: - description: 角色ID - type: string - authorityName: - description: 角色名 - type: string - children: - items: - $ref: '#/definitions/model.SysAuthority' - type: array - createdAt: - description: 创建时间 - type: string - dataAuthorityId: - items: - $ref: '#/definitions/model.SysAuthority' - type: array - defaultRouter: - description: 默认菜单(默认dashboard) - type: string - deletedAt: - type: string - menus: - items: - $ref: '#/definitions/model.SysBaseMenu' - type: array - parentId: - description: 父角色ID - type: string - updatedAt: - description: 更新时间 - type: string - type: object - model.SysBaseMenu: - properties: - authoritys: - items: - $ref: '#/definitions/model.SysAuthority' - type: array - children: - items: - $ref: '#/definitions/model.SysBaseMenu' - type: array - closeTab: - description: 自动关闭tab - type: boolean - component: - description: 对应前端文件路径 - type: string - createdAt: - description: 创建时间 - type: string - defaultMenu: - description: 是否是基础路由(开发中) - type: boolean - hidden: - description: 是否在列表隐藏 - type: boolean - icon: - description: 菜单图标 - type: string - id: - description: 主键ID - type: integer - keepAlive: - description: 是否缓存 - type: boolean - name: - description: 路由name - type: string - parameters: - items: - $ref: '#/definitions/model.SysBaseMenuParameter' - type: array - parentId: - description: 父菜单ID - type: string - path: - description: 路由path - type: string - sort: - description: 排序标记 - type: integer - title: - description: 菜单名 - type: string - updatedAt: - description: 更新时间 - type: string - type: object - model.SysBaseMenuParameter: - properties: - createdAt: - description: 创建时间 - type: string - id: - description: 主键ID - type: integer - key: - description: 地址栏携带参数的key - type: string - sysBaseMenuID: - type: integer - type: - description: 地址栏携带参数为params还是query - type: string - updatedAt: - description: 更新时间 - type: string - value: - description: 地址栏携带参数的值 - type: string - type: object - model.SysDictionary: - properties: - createdAt: - description: 创建时间 - type: string - desc: - description: 描述 - type: string - id: - description: 主键ID - type: integer - name: - description: 字典名(中) - type: string - status: - description: 状态 - type: boolean - sysDictionaryDetails: - items: - $ref: '#/definitions/model.SysDictionaryDetail' - type: array - type: - description: 字典名(英) - type: string - updatedAt: - description: 更新时间 - type: string - type: object - model.SysDictionaryDetail: - properties: - createdAt: - description: 创建时间 - type: string - id: - description: 主键ID - type: integer - label: - description: 展示值 - type: string - sort: - description: 排序标记 - type: integer - status: - description: 启用状态 - type: boolean - sysDictionaryID: - description: 关联标记 - type: integer - updatedAt: - description: 更新时间 - type: string - value: - description: 字典值 - type: integer - type: object - model.SysOperationRecord: - properties: - agent: - description: 代理 - type: string - body: - description: 请求Body - type: string - createdAt: - description: 创建时间 - type: string - error_message: - description: 错误信息 - type: string - id: - description: 主键ID - type: integer - ip: - description: 请求ip - type: string - latency: - description: 延迟 - type: string - method: - description: 请求方法 - type: string - path: - description: 请求路径 - type: string - resp: - description: 响应Body - type: string - status: - description: 请求状态 - type: integer - updatedAt: - description: 更新时间 - type: string - user: - $ref: '#/definitions/model.SysUser' - user_id: - description: 用户id - type: integer - type: object - model.SysUser: - properties: - authority: - $ref: '#/definitions/model.SysAuthority' - authorityId: - description: 用户角色ID - type: string - createdAt: - description: 创建时间 - type: string - headerImg: - description: 用户头像 - type: string - id: - description: 主键ID - type: integer - nickName: - description: 用户昵称 - type: string - updatedAt: - description: 更新时间 - type: string - userName: - description: 用户登录名 - type: string - uuid: - description: 用户UUID - type: string - type: object - model.System: - properties: - config: - $ref: '#/definitions/config.Server' - type: object request.AddMenuAuthorityInfo: properties: authorityId: @@ -697,9 +384,35 @@ definitions: type: string menus: items: - $ref: '#/definitions/model.SysBaseMenu' + $ref: '#/definitions/system.SysBaseMenu' type: array type: object + request.AutoCodeExampleSearch: + properties: + autoCodeExampleField: + description: 展示值 + type: string + createdAt: + description: 创建时间 + type: string + id: + description: 主键ID + type: integer + page: + description: 页码 + type: integer + pageSize: + description: 每页大小 + type: integer + updatedAt: + description: 更新时间 + type: string + type: object + request.AutoHistoryByID: + properties: + id: + type: integer + type: object request.CasbinInReceive: properties: authorityId: @@ -797,6 +510,19 @@ definitions: description: 每页大小 type: integer type: object + request.Register: + properties: + authorityId: + type: string + headerImg: + type: string + nickName: + type: string + passWord: + type: string + userName: + type: string + type: object request.SearchApiParams: properties: apiGroup: @@ -842,6 +568,15 @@ definitions: description: 用户UUID type: string type: object + request.SysAutoHistory: + properties: + page: + description: 页码 + type: integer + pageSize: + description: 每页大小 + type: integer + type: object request.SysDictionaryDetailSearch: properties: createdAt: @@ -900,7 +635,7 @@ definitions: type: boolean sysDictionaryDetails: items: - $ref: '#/definitions/model.SysDictionaryDetail' + $ref: '#/definitions/system.SysDictionaryDetail' type: array type: description: 字典名(英) @@ -954,7 +689,7 @@ definitions: description: 更新时间 type: string user: - $ref: '#/definitions/model.SysUser' + $ref: '#/definitions/system.SysUser' user_id: description: 用户id type: integer @@ -962,17 +697,424 @@ definitions: response.SysAuthorityCopyResponse: properties: authority: - $ref: '#/definitions/model.SysAuthority' + $ref: '#/definitions/system.SysAuthority' oldAuthorityId: description: 旧角色ID type: string type: object + system.AutoCodeStruct: + properties: + abbreviation: + description: Struct简称 + type: string + autoCreateApiToSql: + description: 是否自动创建api + type: boolean + autoMoveFile: + description: 是否自动移动文件 + type: boolean + description: + description: Struct中文名称 + type: string + fields: + items: + $ref: '#/definitions/system.Field' + type: array + humpPackageName: + description: go文件名称 + type: string + packageName: + description: 文件名称 + type: string + structName: + description: Struct名称 + type: string + tableName: + description: 表名 + type: string + type: object + system.Field: + properties: + columnName: + description: 数据库字段 + type: string + comment: + description: 数据库字段描述 + type: string + dataType: + description: 数据库字段类型 + type: string + dataTypeLong: + description: 数据库字段长度 + type: string + dictType: + description: 字典 + type: string + fieldDesc: + description: 中文名 + type: string + fieldJson: + description: FieldJson + type: string + fieldName: + description: Field名 + type: string + fieldSearchType: + description: 搜索条件 + type: string + fieldType: + description: Field数据类型 + type: string + type: object + system.SysApi: + properties: + apiGroup: + description: api组 + type: string + createdAt: + description: 创建时间 + type: string + description: + description: api中文描述 + type: string + id: + description: 主键ID + type: integer + method: + description: 方法:创建POST(默认)|查看GET|更新PUT|删除DELETE + type: string + path: + description: api路径 + type: string + updatedAt: + description: 更新时间 + type: string + type: object + system.SysAuthority: + properties: + authorityId: + description: 角色ID + type: string + authorityName: + description: 角色名 + type: string + children: + items: + $ref: '#/definitions/system.SysAuthority' + type: array + createdAt: + description: 创建时间 + type: string + dataAuthorityId: + items: + $ref: '#/definitions/system.SysAuthority' + type: array + defaultRouter: + description: 默认菜单(默认dashboard) + type: string + deletedAt: + type: string + menus: + items: + $ref: '#/definitions/system.SysBaseMenu' + type: array + parentId: + description: 父角色ID + type: string + updatedAt: + description: 更新时间 + type: string + type: object + system.SysBaseMenu: + properties: + authoritys: + items: + $ref: '#/definitions/system.SysAuthority' + type: array + children: + items: + $ref: '#/definitions/system.SysBaseMenu' + type: array + closeTab: + description: 自动关闭tab + type: boolean + component: + description: 对应前端文件路径 + type: string + createdAt: + description: 创建时间 + type: string + defaultMenu: + description: 是否是基础路由(开发中) + type: boolean + hidden: + description: 是否在列表隐藏 + type: boolean + icon: + description: 菜单图标 + type: string + id: + description: 主键ID + type: integer + keepAlive: + description: 是否缓存 + type: boolean + name: + description: 路由name + type: string + parameters: + items: + $ref: '#/definitions/system.SysBaseMenuParameter' + type: array + parentId: + description: 父菜单ID + type: string + path: + description: 路由path + type: string + sort: + description: 排序标记 + type: integer + title: + description: 菜单名 + type: string + updatedAt: + description: 更新时间 + type: string + type: object + system.SysBaseMenuParameter: + properties: + createdAt: + description: 创建时间 + type: string + id: + description: 主键ID + type: integer + key: + description: 地址栏携带参数的key + type: string + sysBaseMenuID: + type: integer + type: + description: 地址栏携带参数为params还是query + type: string + updatedAt: + description: 更新时间 + type: string + value: + description: 地址栏携带参数的值 + type: string + type: object + system.SysDictionary: + properties: + createdAt: + description: 创建时间 + type: string + desc: + description: 描述 + type: string + id: + description: 主键ID + type: integer + name: + description: 字典名(中) + type: string + status: + description: 状态 + type: boolean + sysDictionaryDetails: + items: + $ref: '#/definitions/system.SysDictionaryDetail' + type: array + type: + description: 字典名(英) + type: string + updatedAt: + description: 更新时间 + type: string + type: object + system.SysDictionaryDetail: + properties: + createdAt: + description: 创建时间 + type: string + id: + description: 主键ID + type: integer + label: + description: 展示值 + type: string + sort: + description: 排序标记 + type: integer + status: + description: 启用状态 + type: boolean + sysDictionaryID: + description: 关联标记 + type: integer + updatedAt: + description: 更新时间 + type: string + value: + description: 字典值 + type: integer + type: object + system.SysOperationRecord: + properties: + agent: + description: 代理 + type: string + body: + description: 请求Body + type: string + createdAt: + description: 创建时间 + type: string + error_message: + description: 错误信息 + type: string + id: + description: 主键ID + type: integer + ip: + description: 请求ip + type: string + latency: + description: 延迟 + type: string + method: + description: 请求方法 + type: string + path: + description: 请求路径 + type: string + resp: + description: 响应Body + type: string + status: + description: 请求状态 + type: integer + updatedAt: + description: 更新时间 + type: string + user: + $ref: '#/definitions/system.SysUser' + user_id: + description: 用户id + type: integer + type: object + system.SysUser: + properties: + activeColor: + description: 活跃颜色 + type: string + authority: + $ref: '#/definitions/system.SysAuthority' + authorityId: + description: 用户角色ID + type: string + baseColor: + description: 基础颜色 + type: string + createdAt: + description: 创建时间 + type: string + headerImg: + description: 用户头像 + type: string + id: + description: 主键ID + type: integer + nickName: + description: 用户昵称 + type: string + sideMode: + description: 用户侧边主题 + type: string + updatedAt: + description: 更新时间 + type: string + userName: + description: 用户登录名 + type: string + uuid: + description: 用户UUID + type: string + type: object + system.System: + properties: + config: + $ref: '#/definitions/config.Server' + type: object info: contact: {} description: This is a sample Server pets title: Swagger Example API version: 0.0.1 paths: + /SimpleUploaderApi/checkFileMd5: + get: + parameters: + - description: md5 + in: query + name: md5 + required: true + type: string + produces: + - application/json + responses: + "200": + description: '{"success":true,"data":{},"msg":"查询成功"}' + schema: + type: string + security: + - ApiKeyAuth: [] + summary: 断点续传插件版示例 + tags: + - SimpleUploader + /SimpleUploaderApi/mergeFileMd5: + get: + parameters: + - description: md5 + in: query + name: md5 + required: true + type: string + produces: + - application/json + responses: + "200": + description: '{"success":true,"data":{},"msg":"合并成功"}' + schema: + type: string + security: + - ApiKeyAuth: [] + summary: 合并文件 + tags: + - SimpleUploader + /SimpleUploaderApi/upload: + post: + consumes: + - multipart/form-data + parameters: + - description: 断点续传插件版示例 + in: formData + name: file + required: true + type: file + produces: + - application/json + responses: + "200": + description: '{"success":true,"data":{},"msg":"切片创建成功"}' + schema: + type: string + security: + - ApiKeyAuth: [] + summary: 断点续传插件版示例 + tags: + - SimpleUploader /api/createApi: post: consumes: @@ -983,7 +1125,7 @@ paths: name: data required: true schema: - $ref: '#/definitions/model.SysApi' + $ref: '#/definitions/system.SysApi' produces: - application/json responses: @@ -1006,7 +1148,7 @@ paths: name: data required: true schema: - $ref: '#/definitions/model.SysApi' + $ref: '#/definitions/system.SysApi' produces: - application/json responses: @@ -1114,7 +1256,7 @@ paths: name: data required: true schema: - $ref: '#/definitions/model.SysApi' + $ref: '#/definitions/system.SysApi' produces: - application/json responses: @@ -1160,7 +1302,7 @@ paths: name: data required: true schema: - $ref: '#/definitions/model.SysAuthority' + $ref: '#/definitions/system.SysAuthority' produces: - application/json responses: @@ -1183,7 +1325,7 @@ paths: name: data required: true schema: - $ref: '#/definitions/model.SysAuthority' + $ref: '#/definitions/system.SysAuthority' produces: - application/json responses: @@ -1229,7 +1371,7 @@ paths: name: data required: true schema: - $ref: '#/definitions/model.SysAuthority' + $ref: '#/definitions/system.SysAuthority' produces: - application/json responses: @@ -1252,7 +1394,7 @@ paths: name: data required: true schema: - $ref: '#/definitions/model.SysAuthority' + $ref: '#/definitions/system.SysAuthority' produces: - application/json responses: @@ -1275,7 +1417,7 @@ paths: name: data required: true schema: - $ref: '#/definitions/model.AutoCodeStruct' + $ref: '#/definitions/system.AutoCodeStruct' produces: - application/json responses: @@ -1288,6 +1430,29 @@ paths: summary: 自动代码模板 tags: - AutoCode + /autoCode/delSysHistory: + post: + consumes: + - application/json + parameters: + - description: 删除回滚记录 + in: body + name: data + required: true + schema: + $ref: '#/definitions/request.AutoHistoryByID' + produces: + - application/json + responses: + "200": + description: '{"success":true,"data":{},"msg":"删除成功"}' + schema: + type: string + security: + - ApiKeyAuth: [] + summary: 删除回滚记录 + tags: + - AutoCode /autoCode/getColumn: get: consumes: @@ -1320,6 +1485,52 @@ paths: summary: 获取当前所有数据库 tags: - AutoCode + /autoCode/getMeta: + post: + consumes: + - application/json + parameters: + - description: 获取meta信息 + in: body + name: data + required: true + schema: + $ref: '#/definitions/request.AutoHistoryByID' + produces: + - application/json + responses: + "200": + description: '{"success":true,"data":{},"msg":"获取成功"}' + schema: + type: string + security: + - ApiKeyAuth: [] + summary: 回滚 + tags: + - AutoCode + /autoCode/getSysHistory: + post: + consumes: + - application/json + parameters: + - description: 查询回滚记录 + in: body + name: data + required: true + schema: + $ref: '#/definitions/request.SysAutoHistory' + produces: + - application/json + responses: + "200": + description: '{"success":true,"data":{},"msg":"获取成功"}' + schema: + type: string + security: + - ApiKeyAuth: [] + summary: 查询回滚记录 + tags: + - AutoCode /autoCode/getTables: get: consumes: @@ -1346,7 +1557,7 @@ paths: name: data required: true schema: - $ref: '#/definitions/model.AutoCodeStruct' + $ref: '#/definitions/system.AutoCodeStruct' produces: - application/json responses: @@ -1359,6 +1570,144 @@ paths: summary: 预览创建后的代码 tags: - AutoCode + /autoCode/rollback: + post: + consumes: + - application/json + parameters: + - description: 回滚自动生成代码 + in: body + name: data + required: true + schema: + $ref: '#/definitions/request.AutoHistoryByID' + produces: + - application/json + responses: + "200": + description: '{"success":true,"data":{},"msg":"回滚成功"}' + schema: + type: string + security: + - ApiKeyAuth: [] + summary: 回滚 + tags: + - AutoCode + /autoCodeExample/createAutoCodeExample: + post: + consumes: + - application/json + parameters: + - description: AutoCodeExample模型 + in: body + name: data + required: true + schema: + $ref: '#/definitions/autocode.AutoCodeExample' + produces: + - application/json + responses: + "200": + description: '{"success":true,"data":{},"msg":"创建成功"}' + schema: + type: string + security: + - ApiKeyAuth: [] + summary: 创建AutoCodeExample + tags: + - AutoCodeExample + /autoCodeExample/deleteAutoCodeExample: + delete: + consumes: + - application/json + parameters: + - description: AutoCodeExample模型 + in: body + name: data + required: true + schema: + $ref: '#/definitions/autocode.AutoCodeExample' + produces: + - application/json + responses: + "200": + description: '{"success":true,"data":{},"msg":"删除成功"}' + schema: + type: string + security: + - ApiKeyAuth: [] + summary: 删除AutoCodeExample + tags: + - AutoCodeExample + /autoCodeExample/findAutoCodeExample: + get: + consumes: + - application/json + parameters: + - description: 用id查询AutoCodeExample + in: body + name: data + required: true + schema: + $ref: '#/definitions/autocode.AutoCodeExample' + produces: + - application/json + responses: + "200": + description: '{"success":true,"data":{},"msg":"查询成功"}' + schema: + type: string + security: + - ApiKeyAuth: [] + summary: 用id查询AutoCodeExample + tags: + - AutoCodeExample + /autoCodeExample/getAutoCodeExampleList: + get: + consumes: + - application/json + parameters: + - description: 页码, 每页大小, 搜索条件 + in: body + name: data + required: true + schema: + $ref: '#/definitions/request.AutoCodeExampleSearch' + produces: + - application/json + responses: + "200": + description: '{"success":true,"data":{},"msg":"获取成功"}' + schema: + type: string + security: + - ApiKeyAuth: [] + summary: 分页获取AutoCodeExample列表 + tags: + - AutoCodeExample + /autoCodeExample/updateAutoCodeExample: + put: + consumes: + - application/json + parameters: + - description: 更新AutoCodeExample + in: body + name: data + required: true + schema: + $ref: '#/definitions/autocode.AutoCodeExample' + produces: + - application/json + responses: + "200": + description: '{"success":true,"data":{},"msg":"更新成功"}' + schema: + type: string + security: + - ApiKeyAuth: [] + summary: 更新AutoCodeExample + tags: + - AutoCodeExample /base/captcha: post: consumes: @@ -1450,7 +1799,7 @@ paths: name: data required: true schema: - $ref: '#/definitions/model.ExaCustomer' + $ref: '#/definitions/example.ExaCustomer' produces: - application/json responses: @@ -1472,7 +1821,7 @@ paths: name: data required: true schema: - $ref: '#/definitions/model.ExaCustomer' + $ref: '#/definitions/example.ExaCustomer' produces: - application/json responses: @@ -1494,7 +1843,7 @@ paths: name: data required: true schema: - $ref: '#/definitions/model.ExaCustomer' + $ref: '#/definitions/example.ExaCustomer' produces: - application/json responses: @@ -1516,7 +1865,7 @@ paths: name: data required: true schema: - $ref: '#/definitions/model.ExaCustomer' + $ref: '#/definitions/example.ExaCustomer' produces: - application/json responses: @@ -1596,7 +1945,7 @@ paths: name: data required: true schema: - $ref: '#/definitions/model.ExcelInfo' + $ref: '#/definitions/example.ExcelInfo' produces: - application/octet-stream responses: @@ -1673,7 +2022,7 @@ paths: name: data required: true schema: - $ref: '#/definitions/model.ExaFileUploadAndDownload' + $ref: '#/definitions/example.ExaFileUploadAndDownload' produces: - application/json responses: @@ -1855,7 +2204,7 @@ paths: name: data required: true schema: - $ref: '#/definitions/model.SysBaseMenu' + $ref: '#/definitions/system.SysBaseMenu' produces: - application/json responses: @@ -2012,7 +2361,7 @@ paths: name: data required: true schema: - $ref: '#/definitions/model.SysBaseMenu' + $ref: '#/definitions/system.SysBaseMenu' produces: - application/json responses: @@ -2025,68 +2374,6 @@ paths: summary: 更新菜单 tags: - Menu - /simpleUploader/checkFileMd5: - get: - parameters: - - description: md5 - in: query - name: md5 - required: true - type: string - produces: - - application/json - responses: - "200": - description: '{"success":true,"data":{},"msg":"查询成功"}' - schema: - type: string - security: - - ApiKeyAuth: [] - summary: 断点续传插件版示例 - tags: - - SimpleUploader - /simpleUploader/mergeFileMd5: - get: - parameters: - - description: md5 - in: query - name: md5 - required: true - type: string - produces: - - application/json - responses: - "200": - description: '{"success":true,"data":{},"msg":"合并成功"}' - schema: - type: string - security: - - ApiKeyAuth: [] - summary: 合并文件 - tags: - - SimpleUploader - /simpleUploader/upload: - post: - consumes: - - multipart/form-data - parameters: - - description: 断点续传插件版示例 - in: formData - name: file - required: true - type: file - produces: - - application/json - responses: - "200": - description: '{"success":true,"data":{},"msg":"切片创建成功"}' - schema: - type: string - security: - - ApiKeyAuth: [] - summary: 断点续传插件版示例 - tags: - - SimpleUploader /sysDictionary/createSysDictionary: post: consumes: @@ -2097,7 +2384,7 @@ paths: name: data required: true schema: - $ref: '#/definitions/model.SysDictionary' + $ref: '#/definitions/system.SysDictionary' produces: - application/json responses: @@ -2120,7 +2407,7 @@ paths: name: data required: true schema: - $ref: '#/definitions/model.SysDictionary' + $ref: '#/definitions/system.SysDictionary' produces: - application/json responses: @@ -2143,7 +2430,7 @@ paths: name: data required: true schema: - $ref: '#/definitions/model.SysDictionary' + $ref: '#/definitions/system.SysDictionary' produces: - application/json responses: @@ -2189,7 +2476,7 @@ paths: name: data required: true schema: - $ref: '#/definitions/model.SysDictionary' + $ref: '#/definitions/system.SysDictionary' produces: - application/json responses: @@ -2212,7 +2499,7 @@ paths: name: data required: true schema: - $ref: '#/definitions/model.SysDictionaryDetail' + $ref: '#/definitions/system.SysDictionaryDetail' produces: - application/json responses: @@ -2235,7 +2522,7 @@ paths: name: data required: true schema: - $ref: '#/definitions/model.SysDictionaryDetail' + $ref: '#/definitions/system.SysDictionaryDetail' produces: - application/json responses: @@ -2258,7 +2545,7 @@ paths: name: data required: true schema: - $ref: '#/definitions/model.SysDictionaryDetail' + $ref: '#/definitions/system.SysDictionaryDetail' produces: - application/json responses: @@ -2304,7 +2591,7 @@ paths: name: data required: true schema: - $ref: '#/definitions/model.SysDictionaryDetail' + $ref: '#/definitions/system.SysDictionaryDetail' produces: - application/json responses: @@ -2327,7 +2614,7 @@ paths: name: data required: true schema: - $ref: '#/definitions/model.SysOperationRecord' + $ref: '#/definitions/system.SysOperationRecord' produces: - application/json responses: @@ -2350,7 +2637,7 @@ paths: name: data required: true schema: - $ref: '#/definitions/model.SysOperationRecord' + $ref: '#/definitions/system.SysOperationRecord' produces: - application/json responses: @@ -2396,7 +2683,7 @@ paths: name: data required: true schema: - $ref: '#/definitions/model.SysOperationRecord' + $ref: '#/definitions/system.SysOperationRecord' produces: - application/json responses: @@ -2482,7 +2769,7 @@ paths: name: data required: true schema: - $ref: '#/definitions/model.System' + $ref: '#/definitions/system.System' produces: - application/json responses: @@ -2570,7 +2857,7 @@ paths: name: data required: true schema: - $ref: '#/definitions/model.SysUser' + $ref: '#/definitions/request.Register' produces: - application/json responses: @@ -2614,7 +2901,7 @@ paths: name: data required: true schema: - $ref: '#/definitions/model.SysUser' + $ref: '#/definitions/system.SysUser' produces: - application/json responses: diff --git a/server/global/global.go b/server/global/global.go index 829714b0..404bb8ae 100644 --- a/server/global/global.go +++ b/server/global/global.go @@ -9,7 +9,7 @@ import ( "gin-vue-admin/config" - "github.com/go-redis/redis" + "github.com/go-redis/redis/v8" "github.com/spf13/viper" "gorm.io/gorm" ) diff --git a/server/go.mod b/server/go.mod index 6eb7497d..1dcc8ef4 100644 --- a/server/go.mod +++ b/server/go.mod @@ -10,33 +10,34 @@ require ( github.com/baiyubin/aliyun-sts-go-sdk v0.0.0-20180326062324-cfa1a18b161f // indirect github.com/casbin/casbin/v2 v2.11.0 github.com/casbin/gorm-adapter/v3 v3.0.2 + github.com/cpuguy83/go-md2man/v2 v2.0.0 // indirect github.com/dgrijalva/jwt-go v3.2.0+incompatible github.com/fastly/go-utils v0.0.0-20180712184237-d95a45783239 // indirect github.com/fsnotify/fsnotify v1.4.9 github.com/fvbock/endless v0.0.0-20170109170031-447134032cb6 github.com/gin-gonic/gin v1.6.3 github.com/go-ole/go-ole v1.2.4 // indirect - github.com/go-openapi/spec v0.19.7 // indirect - github.com/go-openapi/swag v0.19.8 // indirect + github.com/go-openapi/jsonreference v0.19.6 // indirect + github.com/go-openapi/spec v0.20.3 // indirect + github.com/go-openapi/swag v0.19.15 // indirect github.com/go-playground/validator/v10 v10.3.0 // indirect github.com/go-redis/redis v6.15.7+incompatible + github.com/go-redis/redis/v8 v8.11.0 github.com/go-sql-driver/mysql v1.5.0 - github.com/golang/protobuf v1.4.2 // indirect github.com/gookit/color v1.3.1 github.com/jehiah/go-strftime v0.0.0-20171201141054-1d33003b3869 // indirect github.com/jordan-wright/email v0.0.0-20200824153738-3f5bafa1cd84 github.com/json-iterator/go v1.1.10 // indirect github.com/lestrrat-go/file-rotatelogs v2.3.0+incompatible github.com/lestrrat-go/strftime v1.0.3 // indirect - github.com/mailru/easyjson v0.7.1 // indirect + github.com/mailru/easyjson v0.7.7 // indirect github.com/mitchellh/mapstructure v1.2.2 // indirect github.com/mojocn/base64Captcha v1.3.1 - github.com/onsi/ginkgo v1.7.0 // indirect - github.com/onsi/gomega v1.4.3 // indirect github.com/pelletier/go-toml v1.6.0 // indirect github.com/pkg/errors v0.9.1 // indirect github.com/qiniu/api.v7/v7 v7.4.1 github.com/robfig/cron/v3 v3.0.1 + github.com/russross/blackfriday/v2 v2.1.0 // indirect github.com/satori/go.uuid v1.2.0 github.com/shirou/gopsutil v3.21.1+incompatible github.com/spf13/afero v1.2.2 // indirect @@ -44,18 +45,19 @@ require ( github.com/spf13/jwalterweatherman v1.1.0 // indirect github.com/spf13/pflag v1.0.5 // indirect github.com/spf13/viper v1.7.0 - github.com/swaggo/gin-swagger v1.2.0 - github.com/swaggo/swag v1.6.7 + github.com/swaggo/gin-swagger v1.3.0 + github.com/swaggo/swag v1.7.0 github.com/tebeka/strftime v0.1.3 // indirect github.com/tencentyun/cos-go-sdk-v5 v0.7.19 github.com/unrolled/secure v1.0.7 go.uber.org/zap v1.10.0 golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2 // indirect + golang.org/x/net v0.0.0-20210716203947-853a461950ff // indirect golang.org/x/sync v0.0.0-20210220032951-036812b2e83c - golang.org/x/tools v0.0.0-20200324003944-a576cf524670 // indirect + golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c // indirect + golang.org/x/tools v0.1.5 // indirect google.golang.org/protobuf v1.24.0 // indirect gopkg.in/ini.v1 v1.55.0 // indirect - gopkg.in/yaml.v2 v2.3.0 // indirect gorm.io/driver/mysql v1.0.1 gorm.io/gorm v1.20.7 ) diff --git a/server/initialize/gorm.go b/server/initialize/gorm.go index c3d997c8..8a9b529e 100644 --- a/server/initialize/gorm.go +++ b/server/initialize/gorm.go @@ -3,7 +3,9 @@ package initialize import ( "gin-vue-admin/global" "gin-vue-admin/initialize/internal" - "gin-vue-admin/model" + "gin-vue-admin/model/autocode" + "gin-vue-admin/model/example" + "gin-vue-admin/model/system" "os" "go.uber.org/zap" @@ -34,22 +36,23 @@ func Gorm() *gorm.DB { func MysqlTables(db *gorm.DB) { err := db.AutoMigrate( - model.SysUser{}, - model.SysAuthority{}, - model.SysApi{}, - model.SysBaseMenu{}, - model.SysBaseMenuParameter{}, - model.JwtBlacklist{}, - model.SysDictionary{}, - model.SysDictionaryDetail{}, - model.ExaFileUploadAndDownload{}, - model.ExaFile{}, - model.ExaFileChunk{}, - model.ExaSimpleUploader{}, - model.ExaCustomer{}, - model.SysOperationRecord{}, - + system.SysUser{}, + system.SysAuthority{}, + system.SysApi{}, + system.SysBaseMenu{}, + system.SysBaseMenuParameter{}, + system.JwtBlacklist{}, + system.SysDictionary{}, + system.SysDictionaryDetail{}, + example.ExaFileUploadAndDownload{}, + example.ExaFile{}, + example.ExaFileChunk{}, + example.ExaSimpleUploader{}, + example.ExaCustomer{}, + 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/redis.go b/server/initialize/redis.go index f9571ddf..6ecc5a8e 100644 --- a/server/initialize/redis.go +++ b/server/initialize/redis.go @@ -1,8 +1,10 @@ package initialize import ( + "context" "gin-vue-admin/global" - "github.com/go-redis/redis" + + "github.com/go-redis/redis/v8" "go.uber.org/zap" ) @@ -13,7 +15,7 @@ func Redis() { Password: redisCfg.Password, // no password set DB: redisCfg.DB, // use default DB }) - pong, err := client.Ping().Result() + pong, err := client.Ping(context.Background()).Result() if err != nil { global.GVA_LOG.Error("redis connect ping failed, err:", zap.Any("err", err)) } else { diff --git a/server/initialize/router.go b/server/initialize/router.go index 0744d258..213a3bbe 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.InitBaseRouter(PublicGroup) // 注册基础功能路由 不做鉴权 - router.InitInitRouter(PublicGroup) // 自动初始化相关 + systemRouter.InitBaseRouter(PublicGroup) // 注册基础功能路由 不做鉴权 + systemRouter.InitInitRouter(PublicGroup) // 自动初始化相关 } PrivateGroup := Router.Group("") PrivateGroup.Use(middleware.JWTAuth()).Use(middleware.CasbinHandler()) { - router.InitApiRouter(PrivateGroup) // 注册功能api路由 - router.InitJwtRouter(PrivateGroup) // jwt相关路由 - router.InitUserRouter(PrivateGroup) // 注册用户路由 - router.InitMenuRouter(PrivateGroup) // 注册menu路由 - router.InitEmailRouter(PrivateGroup) // 邮件相关路由 - router.InitSystemRouter(PrivateGroup) // system相关路由 - router.InitCasbinRouter(PrivateGroup) // 权限相关路由 - router.InitCustomerRouter(PrivateGroup) // 客户路由 - router.InitAutoCodeRouter(PrivateGroup) // 创建自动化代码 - router.InitAuthorityRouter(PrivateGroup) // 注册角色路由 - router.InitSimpleUploaderRouter(PrivateGroup) // 断点续传(插件版) - router.InitSysDictionaryRouter(PrivateGroup) // 字典管理 - router.InitSysOperationRecordRouter(PrivateGroup) // 操作记录 - router.InitSysDictionaryDetailRouter(PrivateGroup) // 字典详情管理 - router.InitFileUploadAndDownloadRouter(PrivateGroup) // 文件上传下载功能路由 - router.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 e643335e..8812f10b 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 c9d4e79b..d6f0cbfd 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" - "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,14 +23,14 @@ 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" } username = user.Username } body, _ := ioutil.ReadAll(c.Request.Body) - record := model.SysOperationRecord{ + record := system.SysOperationRecord{ Ip: c.ClientIP(), Method: c.Request.Method, Path: c.Request.URL.Path, diff --git a/server/middleware/jwt.go b/server/middleware/jwt.go index 9ab94cd6..74b285dc 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" - "gin-vue-admin/model/request" - "gin-vue-admin/model/response" + "gin-vue-admin/model/common/response" + "gin-vue-admin/model/system" + "gin-vue-admin/model/system/request" "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(model.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(model.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 4263dd9c..c883bb81 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 3c4ea2b6..2bfa25b5 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" - "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 @@ -37,7 +39,7 @@ func OperationRecord() gin.HandlerFunc { } userId = id } - record := model.SysOperationRecord{ + record := system.SysOperationRecord{ Ip: c.ClientIP(), Method: c.Request.Method, Path: c.Request.URL.Path, @@ -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 00000000..e3c64a90 --- /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/request/autocodeExample.go b/server/model/autocode/request/autocodeExample.go new file mode 100644 index 00000000..cdfa48f9 --- /dev/null +++ b/server/model/autocode/request/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/request/common.go b/server/model/common/request/common.go similarity index 100% rename from server/model/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/exa_customer.go b/server/model/exa_customer.go deleted file mode 100644 index 066032c5..00000000 --- a/server/model/exa_customer.go +++ /dev/null @@ -1,14 +0,0 @@ -package model - -import ( - "gin-vue-admin/global" -) - -type ExaCustomer struct { - global.GVA_MODEL - CustomerName string `json:"customerName" form:"customerName" gorm:"comment:客户名"` // 客户名 - CustomerPhoneData string `json:"customerPhoneData" form:"customerPhoneData" gorm:"comment:客户手机号"` // 客户手机号 - SysUserID uint `json:"sysUserId" form:"sysUserId" gorm:"comment:管理ID"` // 管理ID - SysUserAuthorityID string `json:"sysUserAuthorityID" form:"sysUserAuthorityID" gorm:"comment:管理角色ID"` // 管理角色ID - SysUser SysUser `json:"sysUser" form:"sysUser" gorm:"comment:管理详情"` // 管理详情 -} diff --git a/server/model/exa_excel.go b/server/model/exa_excel.go deleted file mode 100644 index facaceb8..00000000 --- a/server/model/exa_excel.go +++ /dev/null @@ -1,6 +0,0 @@ -package model - -type ExcelInfo struct { - FileName string `json:"fileName"` // 文件名 - InfoList []SysBaseMenu `json:"infoList"` -} diff --git a/server/model/exa_breakpoint_continue.go b/server/model/example/exa_breakpoint_continue.go similarity index 96% rename from server/model/exa_breakpoint_continue.go rename to server/model/example/exa_breakpoint_continue.go index 9dd6e253..4505100c 100644 --- a/server/model/exa_breakpoint_continue.go +++ b/server/model/example/exa_breakpoint_continue.go @@ -1,4 +1,4 @@ -package model +package example import ( "gin-vue-admin/global" diff --git a/server/model/example/exa_customer.go b/server/model/example/exa_customer.go new file mode 100644 index 00000000..6955ba9c --- /dev/null +++ b/server/model/example/exa_customer.go @@ -0,0 +1,15 @@ +package example + +import ( + "gin-vue-admin/global" + "gin-vue-admin/model/system" +) + +type ExaCustomer struct { + global.GVA_MODEL + CustomerName string `json:"customerName" form:"customerName" gorm:"comment:客户名"` // 客户名 + CustomerPhoneData string `json:"customerPhoneData" form:"customerPhoneData" gorm:"comment:客户手机号"` // 客户手机号 + SysUserID uint `json:"sysUserId" form:"sysUserId" gorm:"comment:管理ID"` // 管理ID + SysUserAuthorityID string `json:"sysUserAuthorityID" form:"sysUserAuthorityID" gorm:"comment:管理角色ID"` // 管理角色ID + SysUser system.SysUser `json:"sysUser" form:"sysUser" gorm:"comment:管理详情"` // 管理详情 +} diff --git a/server/model/example/exa_excel.go b/server/model/example/exa_excel.go new file mode 100644 index 00000000..a84e62de --- /dev/null +++ b/server/model/example/exa_excel.go @@ -0,0 +1,8 @@ +package example + +import "gin-vue-admin/model/system" + +type ExcelInfo struct { + FileName string `json:"fileName"` // 文件名 + InfoList []system.SysBaseMenu `json:"infoList"` +} diff --git a/server/model/exa_file_upload_download.go b/server/model/example/exa_file_upload_download.go similarity index 95% rename from server/model/exa_file_upload_download.go rename to server/model/example/exa_file_upload_download.go index 5504375f..1299440f 100644 --- a/server/model/exa_file_upload_download.go +++ b/server/model/example/exa_file_upload_download.go @@ -1,4 +1,4 @@ -package model +package example import ( "gin-vue-admin/global" diff --git a/server/model/exa_simple_uploader.go b/server/model/example/exa_simple_uploader.go similarity index 97% rename from server/model/exa_simple_uploader.go rename to server/model/example/exa_simple_uploader.go index 4e5285fd..1e7e82a7 100644 --- a/server/model/exa_simple_uploader.go +++ b/server/model/example/exa_simple_uploader.go @@ -1,4 +1,4 @@ -package model +package example type ExaSimpleUploader struct { ChunkNumber string `json:"chunkNumber" gorm:"comment:当前切片标记"` diff --git a/server/model/response/exa_breakpoint_continue.go b/server/model/example/response/exa_breakpoint_continue.go similarity index 61% rename from server/model/response/exa_breakpoint_continue.go rename to server/model/example/response/exa_breakpoint_continue.go index 43596696..55c1235c 100644 --- a/server/model/response/exa_breakpoint_continue.go +++ b/server/model/example/response/exa_breakpoint_continue.go @@ -1,11 +1,11 @@ package response -import "gin-vue-admin/model" +import "gin-vue-admin/model/example" type FilePathResponse struct { FilePath string `json:"filePath"` } type FileResponse struct { - File model.ExaFile `json:"file"` + File example.ExaFile `json:"file"` } diff --git a/server/model/example/response/exa_customer.go b/server/model/example/response/exa_customer.go new file mode 100644 index 00000000..36efc075 --- /dev/null +++ b/server/model/example/response/exa_customer.go @@ -0,0 +1,7 @@ +package response + +import "gin-vue-admin/model/example" + +type ExaCustomerResponse struct { + Customer example.ExaCustomer `json:"customer"` +} diff --git a/server/model/example/response/exa_file_upload_download.go b/server/model/example/response/exa_file_upload_download.go new file mode 100644 index 00000000..e04bd5f3 --- /dev/null +++ b/server/model/example/response/exa_file_upload_download.go @@ -0,0 +1,7 @@ +package response + +import "gin-vue-admin/model/example" + +type ExaFileResponse struct { + File example.ExaFileUploadAndDownload `json:"file"` +} diff --git a/server/model/request/sys_casbin.go b/server/model/request/sys_casbin.go deleted file mode 100644 index 40ac21cd..00000000 --- a/server/model/request/sys_casbin.go +++ /dev/null @@ -1,17 +0,0 @@ -package request - -// Casbin info structure -type CasbinInfo struct { - Path string `json:"path"` // 路径 - Method string `json:"method"` // 方法 -} - -// Casbin structure for input parameters -type CasbinInReceive struct { - AuthorityId string `json:"authorityId"` // 权限id - CasbinInfos []CasbinInfo `json:"casbinInfos"` -} - -func DefaultCasbin() []CasbinInfo { - return []CasbinInfo{{Path: "/menu/getMenu", Method: "POST"}, {Path: "/jwt/jsonInBlacklist", Method: "POST"}} -} diff --git a/server/model/request/sys_dictionary.go b/server/model/request/sys_dictionary.go deleted file mode 100644 index abd8ff04..00000000 --- a/server/model/request/sys_dictionary.go +++ /dev/null @@ -1,8 +0,0 @@ -package request - -import "gin-vue-admin/model" - -type SysDictionarySearch struct { - model.SysDictionary - PageInfo -} diff --git a/server/model/request/sys_dictionary_detail.go b/server/model/request/sys_dictionary_detail.go deleted file mode 100644 index 8b5e1065..00000000 --- a/server/model/request/sys_dictionary_detail.go +++ /dev/null @@ -1,8 +0,0 @@ -package request - -import "gin-vue-admin/model" - -type SysDictionaryDetailSearch struct { - model.SysDictionaryDetail - PageInfo -} diff --git a/server/model/request/sys_operation_record.go b/server/model/request/sys_operation_record.go deleted file mode 100644 index a9b7abbe..00000000 --- a/server/model/request/sys_operation_record.go +++ /dev/null @@ -1,8 +0,0 @@ -package request - -import "gin-vue-admin/model" - -type SysOperationRecordSearch struct { - model.SysOperationRecord - PageInfo -} diff --git a/server/model/response/exa_customer.go b/server/model/response/exa_customer.go deleted file mode 100644 index 3a4102ac..00000000 --- a/server/model/response/exa_customer.go +++ /dev/null @@ -1,7 +0,0 @@ -package response - -import "gin-vue-admin/model" - -type ExaCustomerResponse struct { - Customer model.ExaCustomer `json:"customer"` -} diff --git a/server/model/response/exa_file_upload_download.go b/server/model/response/exa_file_upload_download.go deleted file mode 100644 index 56dbc0fc..00000000 --- a/server/model/response/exa_file_upload_download.go +++ /dev/null @@ -1,7 +0,0 @@ -package response - -import "gin-vue-admin/model" - -type ExaFileResponse struct { - File model.ExaFileUploadAndDownload `json:"file"` -} diff --git a/server/model/response/sys_api.go b/server/model/response/sys_api.go deleted file mode 100644 index d3025fdb..00000000 --- a/server/model/response/sys_api.go +++ /dev/null @@ -1,11 +0,0 @@ -package response - -import "gin-vue-admin/model" - -type SysAPIResponse struct { - Api model.SysApi `json:"api"` -} - -type SysAPIListResponse struct { - Apis []model.SysApi `json:"apis"` -} diff --git a/server/model/response/sys_authority.go b/server/model/response/sys_authority.go deleted file mode 100644 index 7b1f75d8..00000000 --- a/server/model/response/sys_authority.go +++ /dev/null @@ -1,12 +0,0 @@ -package response - -import "gin-vue-admin/model" - -type SysAuthorityResponse struct { - Authority model.SysAuthority `json:"authority"` -} - -type SysAuthorityCopyResponse struct { - Authority model.SysAuthority `json:"authority"` - OldAuthorityId string `json:"oldAuthorityId"` // 旧角色ID -} diff --git a/server/model/response/sys_menu.go b/server/model/response/sys_menu.go deleted file mode 100644 index 6c7dbbdf..00000000 --- a/server/model/response/sys_menu.go +++ /dev/null @@ -1,15 +0,0 @@ -package response - -import "gin-vue-admin/model" - -type SysMenusResponse struct { - Menus []model.SysMenu `json:"menus"` -} - -type SysBaseMenusResponse struct { - Menus []model.SysBaseMenu `json:"menus"` -} - -type SysBaseMenuResponse struct { - Menu model.SysBaseMenu `json:"menu"` -} diff --git a/server/model/response/sys_user.go b/server/model/response/sys_user.go deleted file mode 100644 index 75d92827..00000000 --- a/server/model/response/sys_user.go +++ /dev/null @@ -1,15 +0,0 @@ -package response - -import ( - "gin-vue-admin/model" -) - -type SysUserResponse struct { - User model.SysUser `json:"user"` -} - -type LoginResponse struct { - User model.SysUser `json:"user"` - Token string `json:"token"` - ExpiresAt int64 `json:"expiresAt"` -} diff --git a/server/model/sys_base_menu.go b/server/model/sys_base_menu.go deleted file mode 100644 index 83a287b7..00000000 --- a/server/model/sys_base_menu.go +++ /dev/null @@ -1,36 +0,0 @@ -package model - -import ( - "gin-vue-admin/global" -) - -type SysBaseMenu struct { - global.GVA_MODEL - MenuLevel uint `json:"-"` - ParentId string `json:"parentId" gorm:"comment:父菜单ID"` // 父菜单ID - Path string `json:"path" gorm:"comment:路由path"` // 路由path - Name string `json:"name" gorm:"comment:路由name"` // 路由name - Hidden bool `json:"hidden" gorm:"comment:是否在列表隐藏"` // 是否在列表隐藏 - Component string `json:"component" gorm:"comment:对应前端文件路径"` // 对应前端文件路径 - Sort int `json:"sort" gorm:"comment:排序标记"` // 排序标记 - Meta `json:"meta" gorm:"comment:附加属性"` // 附加属性 - SysAuthoritys []SysAuthority `json:"authoritys" gorm:"many2many:sys_authority_menus;"` - Children []SysBaseMenu `json:"children" gorm:"-"` - Parameters []SysBaseMenuParameter `json:"parameters"` -} - -type Meta struct { - KeepAlive bool `json:"keepAlive" gorm:"comment:是否缓存"` // 是否缓存 - DefaultMenu bool `json:"defaultMenu" gorm:"comment:是否是基础路由(开发中)"` // 是否是基础路由(开发中) - Title string `json:"title" gorm:"comment:菜单名"` // 菜单名 - Icon string `json:"icon" gorm:"comment:菜单图标"` // 菜单图标 - CloseTab bool `json:"closeTab" gorm:"comment:自动关闭tab"` // 自动关闭tab -} - -type SysBaseMenuParameter struct { - global.GVA_MODEL - SysBaseMenuID uint - Type string `json:"type" gorm:"comment:地址栏携带参数为params还是query"` // 地址栏携带参数为params还是query - Key string `json:"key" gorm:"comment:地址栏携带参数的key"` // 地址栏携带参数的key - Value string `json:"value" gorm:"comment:地址栏携带参数的值"` // 地址栏携带参数的值 -} diff --git a/server/model/sys_user.go b/server/model/sys_user.go deleted file mode 100644 index 4ddc2367..00000000 --- a/server/model/sys_user.go +++ /dev/null @@ -1,20 +0,0 @@ -package model - -import ( - "gin-vue-admin/global" - "github.com/satori/go.uuid" -) - -type SysUser struct { - global.GVA_MODEL - UUID uuid.UUID `json:"uuid" gorm:"comment:用户UUID"` // 用户UUID - Username string `json:"userName" gorm:"comment:用户登录名"` // 用户登录名 - Password string `json:"-" gorm:"comment:用户登录密码"` // 用户登录密码 - NickName string `json:"nickName" gorm:"default:系统用户;comment:用户昵称"` // 用户昵称 - HeaderImg string `json:"headerImg" gorm:"default:http://qmplusimg.henrongyi.top/head.png;comment:用户头像"` // 用户头像 - Authority SysAuthority `json:"authority" gorm:"foreignKey:AuthorityId;references:AuthorityId;comment:用户角色"` - AuthorityId string `json:"authorityId" gorm:"default:888;comment:用户角色ID"` // 用户角色ID - SideMode string `json:"sideMode" gorm:"default:dark;comment:用户角色ID"` // 用户侧边主题 - ActiveColor string `json:"activeColor" gorm:"default:#1890ff;comment:用户角色ID"` // 活跃颜色 - BaseColor string `json:"baseColor" gorm:"default:#fff;comment:用户角色ID"` // 基础颜色 -} diff --git a/server/model/request/jwt.go b/server/model/system/request/jwt.go similarity index 100% rename from server/model/request/jwt.go rename to server/model/system/request/jwt.go diff --git a/server/model/request/sys_api.go b/server/model/system/request/sys_api.go similarity index 66% rename from server/model/request/sys_api.go rename to server/model/system/request/sys_api.go index f9d5ec03..d86e8c89 100644 --- a/server/model/request/sys_api.go +++ b/server/model/system/request/sys_api.go @@ -1,11 +1,14 @@ package request -import "gin-vue-admin/model" +import ( + "gin-vue-admin/model/common/request" + "gin-vue-admin/model/system" +) // api分页条件查询及排序结构体 type SearchApiParams struct { - model.SysApi - PageInfo + system.SysApi + request.PageInfo OrderKey string `json:"orderKey"` // 排序 Desc bool `json:"desc"` // 排序方式:升序false(默认)|降序true } diff --git a/server/model/request/sys_autocode.go b/server/model/system/request/sys_autocode.go similarity index 75% rename from server/model/request/sys_autocode.go rename to server/model/system/request/sys_autocode.go index d97be350..9cfa2880 100644 --- a/server/model/request/sys_autocode.go +++ b/server/model/system/request/sys_autocode.go @@ -1,5 +1,15 @@ package request +import "gin-vue-admin/model/common/request" + +type SysAutoHistory struct { + request.PageInfo +} + +type AutoHistoryByID struct { + ID uint `json:"id"` +} + type DBReq struct { Database string `json:"database" gorm:"column:database"` } diff --git a/server/model/system/request/sys_casbin.go b/server/model/system/request/sys_casbin.go new file mode 100644 index 00000000..d0031dcf --- /dev/null +++ b/server/model/system/request/sys_casbin.go @@ -0,0 +1,26 @@ +package request + +// Casbin info structure +type CasbinInfo struct { + Path string `json:"path"` // 路径 + Method string `json:"method"` // 方法 +} + +// Casbin structure for input parameters +type CasbinInReceive struct { + AuthorityId string `json:"authorityId"` // 权限id + CasbinInfos []CasbinInfo `json:"casbinInfos"` +} + +func DefaultCasbin() []CasbinInfo { + return []CasbinInfo{ + {Path: "/menu/getMenu", Method: "POST"}, + {Path: "/jwt/jsonInBlacklist", Method: "POST"}, + {Path: "/base/login", Method: "POST"}, + {Path: "/user/register", Method: "POST"}, + {Path: "/user/changePassword", Method: "POST"}, + {Path: "/user/setUserAuthority", Method: "POST"}, + {Path: "/user/setUserInfo", Method: "PUT"}, + {Path: "/user/getUserInfo", Method: "GET"}, + } +} diff --git a/server/model/system/request/sys_dictionary.go b/server/model/system/request/sys_dictionary.go new file mode 100644 index 00000000..4402daa7 --- /dev/null +++ b/server/model/system/request/sys_dictionary.go @@ -0,0 +1,11 @@ +package request + +import ( + "gin-vue-admin/model/common/request" + "gin-vue-admin/model/system" +) + +type SysDictionarySearch struct { + system.SysDictionary + request.PageInfo +} diff --git a/server/model/system/request/sys_dictionary_detail.go b/server/model/system/request/sys_dictionary_detail.go new file mode 100644 index 00000000..5d688e64 --- /dev/null +++ b/server/model/system/request/sys_dictionary_detail.go @@ -0,0 +1,11 @@ +package request + +import ( + "gin-vue-admin/model/common/request" + "gin-vue-admin/model/system" +) + +type SysDictionaryDetailSearch struct { + system.SysDictionaryDetail + request.PageInfo +} diff --git a/server/model/request/sys_init.go b/server/model/system/request/sys_init.go similarity index 100% rename from server/model/request/sys_init.go rename to server/model/system/request/sys_init.go diff --git a/server/model/request/sys_menu.go b/server/model/system/request/sys_menu.go similarity index 70% rename from server/model/request/sys_menu.go rename to server/model/system/request/sys_menu.go index c88f9c69..c19ee6ae 100644 --- a/server/model/request/sys_menu.go +++ b/server/model/system/request/sys_menu.go @@ -2,24 +2,24 @@ package request import ( "gin-vue-admin/global" - "gin-vue-admin/model" + "gin-vue-admin/model/system" ) // Add menu authority info structure type AddMenuAuthorityInfo struct { - Menus []model.SysBaseMenu + Menus []system.SysBaseMenu AuthorityId string // 角色ID } -func DefaultMenu() []model.SysBaseMenu { - return []model.SysBaseMenu{{ +func DefaultMenu() []system.SysBaseMenu { + return []system.SysBaseMenu{{ GVA_MODEL: global.GVA_MODEL{ID: 1}, ParentId: "0", Path: "dashboard", Name: "dashboard", Component: "view/dashboard/index.vue", Sort: 1, - Meta: model.Meta{ + Meta: system.Meta{ Title: "仪表盘", Icon: "setting", }, diff --git a/server/model/system/request/sys_operation_record.go b/server/model/system/request/sys_operation_record.go new file mode 100644 index 00000000..03506330 --- /dev/null +++ b/server/model/system/request/sys_operation_record.go @@ -0,0 +1,11 @@ +package request + +import ( + "gin-vue-admin/model/common/request" + "gin-vue-admin/model/system" +) + +type SysOperationRecordSearch struct { + system.SysOperationRecord + request.PageInfo +} diff --git a/server/model/request/sys_user.go b/server/model/system/request/sys_user.go similarity index 52% rename from server/model/request/sys_user.go rename to server/model/system/request/sys_user.go index f2b147ed..84ab1ef4 100644 --- a/server/model/request/sys_user.go +++ b/server/model/system/request/sys_user.go @@ -1,14 +1,13 @@ package request -import uuid "github.com/satori/go.uuid" - // User register structure type Register struct { - Username string `json:"userName"` - Password string `json:"passWord"` - NickName string `json:"nickName" gorm:"default:'QMPlusUser'"` - HeaderImg string `json:"headerImg" gorm:"default:'http://www.henrongyi.top/avatar/lufu.jpg'"` - AuthorityId string `json:"authorityId" gorm:"default:888"` + Username string `json:"userName"` + Password string `json:"passWord"` + NickName string `json:"nickName" gorm:"default:'QMPlusUser'"` + HeaderImg string `json:"headerImg" gorm:"default:'http://www.henrongyi.top/avatar/lufu.jpg'"` + AuthorityId string `json:"authorityId" gorm:"default:888"` + AuthorityIds []string `json:"authorityIds"` } // User login structure @@ -28,6 +27,11 @@ type ChangePasswordStruct struct { // Modify user's auth structure type SetUserAuth struct { - UUID uuid.UUID `json:"uuid"` // 用户UUID - AuthorityId string `json:"authorityId"` // 角色ID + AuthorityId string `json:"authorityId"` // 角色ID +} + +// Modify user's auth structure +type SetUserAuthorities struct { + ID uint + AuthorityIds []string `json:"authorityIds"` // 角色ID } diff --git a/server/model/system/response/sys_api.go b/server/model/system/response/sys_api.go new file mode 100644 index 00000000..35492a13 --- /dev/null +++ b/server/model/system/response/sys_api.go @@ -0,0 +1,11 @@ +package response + +import "gin-vue-admin/model/system" + +type SysAPIResponse struct { + Api system.SysApi `json:"api"` +} + +type SysAPIListResponse struct { + Apis []system.SysApi `json:"apis"` +} diff --git a/server/model/system/response/sys_authority.go b/server/model/system/response/sys_authority.go new file mode 100644 index 00000000..5a107802 --- /dev/null +++ b/server/model/system/response/sys_authority.go @@ -0,0 +1,12 @@ +package response + +import "gin-vue-admin/model/system" + +type SysAuthorityResponse struct { + Authority system.SysAuthority `json:"authority"` +} + +type SysAuthorityCopyResponse struct { + Authority system.SysAuthority `json:"authority"` + OldAuthorityId string `json:"oldAuthorityId"` // 旧角色ID +} diff --git a/server/model/response/sys_captcha.go b/server/model/system/response/sys_captcha.go similarity index 100% rename from server/model/response/sys_captcha.go rename to server/model/system/response/sys_captcha.go diff --git a/server/model/response/sys_casbin.go b/server/model/system/response/sys_casbin.go similarity index 66% rename from server/model/response/sys_casbin.go rename to server/model/system/response/sys_casbin.go index 5bf962c2..ef57bc3f 100644 --- a/server/model/response/sys_casbin.go +++ b/server/model/system/response/sys_casbin.go @@ -1,6 +1,8 @@ package response -import "gin-vue-admin/model/request" +import ( + "gin-vue-admin/model/system/request" +) type PolicyPathResponse struct { Paths []request.CasbinInfo `json:"paths"` diff --git a/server/model/system/response/sys_menu.go b/server/model/system/response/sys_menu.go new file mode 100644 index 00000000..26bcc1c1 --- /dev/null +++ b/server/model/system/response/sys_menu.go @@ -0,0 +1,15 @@ +package response + +import "gin-vue-admin/model/system" + +type SysMenusResponse struct { + Menus []system.SysMenu `json:"menus"` +} + +type SysBaseMenusResponse struct { + Menus []system.SysBaseMenu `json:"menus"` +} + +type SysBaseMenuResponse struct { + Menu system.SysBaseMenu `json:"menu"` +} diff --git a/server/model/response/sys_system.go b/server/model/system/response/sys_system.go similarity index 100% rename from server/model/response/sys_system.go rename to server/model/system/response/sys_system.go diff --git a/server/model/system/response/sys_user.go b/server/model/system/response/sys_user.go new file mode 100644 index 00000000..91602311 --- /dev/null +++ b/server/model/system/response/sys_user.go @@ -0,0 +1,15 @@ +package response + +import ( + "gin-vue-admin/model/system" +) + +type SysUserResponse struct { + User system.SysUser `json:"user"` +} + +type LoginResponse struct { + User system.SysUser `json:"user"` + Token string `json:"token"` + ExpiresAt int64 `json:"expiresAt"` +} diff --git a/server/model/sys_api.go b/server/model/system/sys_api.go similarity index 80% rename from server/model/sys_api.go rename to server/model/system/sys_api.go index 03fbeba0..ce945a6f 100644 --- a/server/model/sys_api.go +++ b/server/model/system/sys_api.go @@ -1,4 +1,4 @@ -package model +package system import ( "gin-vue-admin/global" @@ -6,8 +6,8 @@ import ( type SysApi struct { global.GVA_MODEL - Path string `json:"path" gorm:"comment:api路径"` // api路径 - Description string `json:"description" gorm:"comment:api中文描述"` // api中文描述 - ApiGroup string `json:"apiGroup" gorm:"comment:api组"` // api组 + Path string `json:"path" gorm:"comment:api路径"` // api路径 + Description string `json:"description" gorm:"comment:api中文描述"` // api中文描述 + ApiGroup string `json:"apiGroup" gorm:"comment:api组"` // api组 Method string `json:"method" gorm:"default:POST;comment:方法"` // 方法:创建POST(默认)|查看GET|更新PUT|删除DELETE } diff --git a/server/model/sys_authority.go b/server/model/system/sys_authority.go similarity index 98% rename from server/model/sys_authority.go rename to server/model/system/sys_authority.go index de2964ae..580b0b9f 100644 --- a/server/model/sys_authority.go +++ b/server/model/system/sys_authority.go @@ -1,4 +1,4 @@ -package model +package system import ( "time" diff --git a/server/model/sys_authority_menu.go b/server/model/system/sys_authority_menu.go similarity index 96% rename from server/model/sys_authority_menu.go rename to server/model/system/sys_authority_menu.go index 23ee4ab2..7af5f54d 100644 --- a/server/model/sys_authority_menu.go +++ b/server/model/system/sys_authority_menu.go @@ -1,4 +1,4 @@ -package model +package system type SysMenu struct { SysBaseMenu diff --git a/server/model/sys_auto_code.go b/server/model/system/sys_auto_code.go similarity index 93% rename from server/model/sys_auto_code.go rename to server/model/system/sys_auto_code.go index 9e030f5d..7047b810 100644 --- a/server/model/sys_auto_code.go +++ b/server/model/system/sys_auto_code.go @@ -1,4 +1,4 @@ -package model +package system import "errors" @@ -7,7 +7,7 @@ type AutoCodeStruct struct { StructName string `json:"structName"` // Struct名称 TableName string `json:"tableName"` // 表名 PackageName string `json:"packageName"` // 文件名称 - HumpPackageName string `json:"humpPackageName"` // go文件名称 + HumpPackageName string `json:"humpPackageName"` // go文件名称 Abbreviation string `json:"abbreviation"` // Struct简称 Description string `json:"description"` // Struct中文名称 AutoCreateApiToSql bool `json:"autoCreateApiToSql"` // 是否自动创建api diff --git a/server/model/system/sys_autocode_history.go b/server/model/system/sys_autocode_history.go new file mode 100644 index 00000000..aef66c6b --- /dev/null +++ b/server/model/system/sys_autocode_history.go @@ -0,0 +1,18 @@ +package system + +import "gin-vue-admin/global" + +// 自动迁移代码记录,用于回滚,重放使用 + +type SysAutoCodeHistory struct { + global.GVA_MODEL + TableName string `json:"tableName"` + RequestMeta string `gorm:"type:text" json:"requestMeta,omitempty"` // 前端传入的结构化信息 + AutoCodePath string `gorm:"type:text" json:"autoCodePath,omitempty"` // 其他meta信息 path;path + InjectionMeta string `gorm:"type:text" json:"injectionMeta,omitempty"` // 注入的内容 RouterPath@functionName@RouterString; + StructName string `json:"structName"` + StructCNName string `json:"structCNName"` + ApiIDs string `json:"apiIDs,omitempty"` // api表注册内容 + Flag int `json:"flag"` // 表示对应状态 0 代表创建, 1 代表回滚 ... + +} diff --git a/server/model/system/sys_base_menu.go b/server/model/system/sys_base_menu.go new file mode 100644 index 00000000..84c3b416 --- /dev/null +++ b/server/model/system/sys_base_menu.go @@ -0,0 +1,36 @@ +package system + +import ( + "gin-vue-admin/global" +) + +type SysBaseMenu struct { + global.GVA_MODEL + MenuLevel uint `json:"-"` + ParentId string `json:"parentId" gorm:"comment:父菜单ID"` // 父菜单ID + Path string `json:"path" gorm:"comment:路由path"` // 路由path + Name string `json:"name" gorm:"comment:路由name"` // 路由name + Hidden bool `json:"hidden" gorm:"comment:是否在列表隐藏"` // 是否在列表隐藏 + Component string `json:"component" gorm:"comment:对应前端文件路径"` // 对应前端文件路径 + Sort int `json:"sort" gorm:"comment:排序标记"` // 排序标记 + Meta `json:"meta" gorm:"comment:附加属性"` // 附加属性 + SysAuthoritys []SysAuthority `json:"authoritys" gorm:"many2many:sys_authority_menus;"` + Children []SysBaseMenu `json:"children" gorm:"-"` + Parameters []SysBaseMenuParameter `json:"parameters"` +} + +type Meta struct { + KeepAlive bool `json:"keepAlive" gorm:"comment:是否缓存"` // 是否缓存 + DefaultMenu bool `json:"defaultMenu" gorm:"comment:是否是基础路由(开发中)"` // 是否是基础路由(开发中) + Title string `json:"title" gorm:"comment:菜单名"` // 菜单名 + Icon string `json:"icon" gorm:"comment:菜单图标"` // 菜单图标 + CloseTab bool `json:"closeTab" gorm:"comment:自动关闭tab"` // 自动关闭tab +} + +type SysBaseMenuParameter struct { + global.GVA_MODEL + SysBaseMenuID uint + Type string `json:"type" gorm:"comment:地址栏携带参数为params还是query"` // 地址栏携带参数为params还是query + Key string `json:"key" gorm:"comment:地址栏携带参数的key"` // 地址栏携带参数的key + Value string `json:"value" gorm:"comment:地址栏携带参数的值"` // 地址栏携带参数的值 +} diff --git a/server/model/sys_casbin.go b/server/model/system/sys_casbin.go similarity index 94% rename from server/model/sys_casbin.go rename to server/model/system/sys_casbin.go index 9bb19886..d205bb95 100644 --- a/server/model/sys_casbin.go +++ b/server/model/system/sys_casbin.go @@ -1,4 +1,4 @@ -package model +package system type CasbinModel struct { Ptype string `json:"ptype" gorm:"column:ptype"` diff --git a/server/model/sys_dictionary.go b/server/model/system/sys_dictionary.go similarity index 98% rename from server/model/sys_dictionary.go rename to server/model/system/sys_dictionary.go index 153a0f4f..1eeb30b2 100644 --- a/server/model/sys_dictionary.go +++ b/server/model/system/sys_dictionary.go @@ -1,5 +1,5 @@ // 自动生成模板SysDictionary -package model +package system import ( "gin-vue-admin/global" diff --git a/server/model/sys_dictionary_detail.go b/server/model/system/sys_dictionary_detail.go similarity index 98% rename from server/model/sys_dictionary_detail.go rename to server/model/system/sys_dictionary_detail.go index b75d1336..1bd9cd2c 100644 --- a/server/model/sys_dictionary_detail.go +++ b/server/model/system/sys_dictionary_detail.go @@ -1,5 +1,5 @@ // 自动生成模板SysDictionaryDetail -package model +package system import ( "gin-vue-admin/global" diff --git a/server/model/sys_initdb.go b/server/model/system/sys_initdb.go similarity index 77% rename from server/model/sys_initdb.go rename to server/model/system/sys_initdb.go index 05ee62e9..ae05a748 100644 --- a/server/model/sys_initdb.go +++ b/server/model/system/sys_initdb.go @@ -1,4 +1,4 @@ -package model +package system type InitDBFunc interface { Init() (err error) diff --git a/server/model/sys_jwt_blacklist.go b/server/model/system/sys_jwt_blacklist.go similarity index 89% rename from server/model/sys_jwt_blacklist.go rename to server/model/system/sys_jwt_blacklist.go index 6cda6e2e..06b23e66 100644 --- a/server/model/sys_jwt_blacklist.go +++ b/server/model/system/sys_jwt_blacklist.go @@ -1,4 +1,4 @@ -package model +package system import ( "gin-vue-admin/global" diff --git a/server/model/sys_operation_record.go b/server/model/system/sys_operation_record.go similarity index 99% rename from server/model/sys_operation_record.go rename to server/model/system/sys_operation_record.go index 46d02f83..b3522ebb 100644 --- a/server/model/sys_operation_record.go +++ b/server/model/system/sys_operation_record.go @@ -1,5 +1,5 @@ // 自动生成模板SysOperationRecord -package model +package system import ( "gin-vue-admin/global" diff --git a/server/model/sys_system.go b/server/model/system/sys_system.go similarity index 87% rename from server/model/sys_system.go rename to server/model/system/sys_system.go index 44910003..8ea71140 100644 --- a/server/model/sys_system.go +++ b/server/model/system/sys_system.go @@ -1,4 +1,4 @@ -package model +package system import ( "gin-vue-admin/config" diff --git a/server/model/system/sys_user.go b/server/model/system/sys_user.go new file mode 100644 index 00000000..1fccf157 --- /dev/null +++ b/server/model/system/sys_user.go @@ -0,0 +1,21 @@ +package system + +import ( + "gin-vue-admin/global" + "github.com/satori/go.uuid" +) + +type SysUser struct { + global.GVA_MODEL + UUID uuid.UUID `json:"uuid" gorm:"comment:用户UUID"` // 用户UUID + Username string `json:"userName" gorm:"comment:用户登录名"` // 用户登录名 + Password string `json:"-" gorm:"comment:用户登录密码"` // 用户登录密码 + NickName string `json:"nickName" gorm:"default:系统用户;comment:用户昵称"` // 用户昵称 + HeaderImg string `json:"headerImg" gorm:"default:http://qmplusimg.henrongyi.top/head.png;comment:用户头像"` // 用户头像 + Authority SysAuthority `json:"authority" gorm:"foreignKey:AuthorityId;references:AuthorityId;comment:用户角色"` + AuthorityId string `json:"authorityId" gorm:"default:888;comment:用户角色ID"` // 用户角色ID + SideMode string `json:"sideMode" gorm:"default:dark;comment:用户角色ID"` // 用户侧边主题 + ActiveColor string `json:"activeColor" gorm:"default:#1890ff;comment:用户角色ID"` // 活跃颜色 + BaseColor string `json:"baseColor" gorm:"default:#fff;comment:用户角色ID"` // 基础颜色 + Authorities []SysAuthority `json:"authorities" gorm:"many2many:sys_user_authority;"` +} diff --git a/server/model/system/sys_user_authority.go b/server/model/system/sys_user_authority.go new file mode 100644 index 00000000..ba37605a --- /dev/null +++ b/server/model/system/sys_user_authority.go @@ -0,0 +1,10 @@ +package system + +type SysUseAuthority struct { + SysUserId uint `gorm:"column:sys_user_id"` + SysAuthorityAuthorityId string `gorm:"column:sys_authority_authority_id"` +} + +func (s *SysUseAuthority) TableName() string { + return "sys_user_authority" +} diff --git a/server/resource/template/server/api.go.tpl b/server/resource/template/server/api.go.tpl index 0ab3dea7..1b639d63 100644 --- a/server/resource/template/server/api.go.tpl +++ b/server/resource/template/server/api.go.tpl @@ -1,28 +1,35 @@ -package v1 +package autocode import ( "gin-vue-admin/global" - "gin-vue-admin/model" - "gin-vue-admin/model/request" - "gin-vue-admin/model/response" + "gin-vue-admin/model/autocode" + "gin-vue-admin/model/common/request" + autocodeReq "gin-vue-admin/model/autocode/request" + "gin-vue-admin/model/common/response" "gin-vue-admin/service" "github.com/gin-gonic/gin" "go.uber.org/zap" ) +type {{.StructName}}Api struct { +} + +var {{.Abbreviation}}Service = service.ServiceGroupApp.AutoCodeServiceGroup.{{.StructName}}Service + + // Create{{.StructName}} 创建{{.StructName}} // @Tags {{.StructName}} // @Summary 创建{{.StructName}} // @Security ApiKeyAuth // @accept application/json // @Produce application/json -// @Param data body model.{{.StructName}} true "创建{{.StructName}}" +// @Param data body autocode.{{.StructName}} true "创建{{.StructName}}" // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}" // @Router /{{.Abbreviation}}/create{{.StructName}} [post] -func Create{{.StructName}}(c *gin.Context) { - var {{.Abbreviation}} model.{{.StructName}} +func ({{.Abbreviation}}Api *{{.StructName}}Api) Create{{.StructName}}(c *gin.Context) { + var {{.Abbreviation}} autocode.{{.StructName}} _ = c.ShouldBindJSON(&{{.Abbreviation}}) - if err := service.Create{{.StructName}}({{.Abbreviation}}); err != nil { + if err := {{.Abbreviation}}Service.Create{{.StructName}}({{.Abbreviation}}); err != nil { global.GVA_LOG.Error("创建失败!", zap.Any("err", err)) response.FailWithMessage("创建失败", c) } else { @@ -36,13 +43,13 @@ func Create{{.StructName}}(c *gin.Context) { // @Security ApiKeyAuth // @accept application/json // @Produce application/json -// @Param data body model.{{.StructName}} true "删除{{.StructName}}" +// @Param data body autocode.{{.StructName}} true "删除{{.StructName}}" // @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}" // @Router /{{.Abbreviation}}/delete{{.StructName}} [delete] -func Delete{{.StructName}}(c *gin.Context) { - var {{.Abbreviation}} model.{{.StructName}} +func ({{.Abbreviation}}Api *{{.StructName}}Api) Delete{{.StructName}}(c *gin.Context) { + var {{.Abbreviation}} autocode.{{.StructName}} _ = c.ShouldBindJSON(&{{.Abbreviation}}) - if err := service.Delete{{.StructName}}({{.Abbreviation}}); err != nil { + if err := {{.Abbreviation}}Service.Delete{{.StructName}}({{.Abbreviation}}); err != nil { global.GVA_LOG.Error("删除失败!", zap.Any("err", err)) response.FailWithMessage("删除失败", c) } else { @@ -59,10 +66,10 @@ func Delete{{.StructName}}(c *gin.Context) { // @Param data body request.IdsReq true "批量删除{{.StructName}}" // @Success 200 {string} string "{"success":true,"data":{},"msg":"批量删除成功"}" // @Router /{{.Abbreviation}}/delete{{.StructName}}ByIds [delete] -func Delete{{.StructName}}ByIds(c *gin.Context) { +func ({{.Abbreviation}}Api *{{.StructName}}Api) Delete{{.StructName}}ByIds(c *gin.Context) { var IDS request.IdsReq _ = c.ShouldBindJSON(&IDS) - if err := service.Delete{{.StructName}}ByIds(IDS); err != nil { + if err := {{.Abbreviation}}Service.Delete{{.StructName}}ByIds(IDS); err != nil { global.GVA_LOG.Error("批量删除失败!", zap.Any("err", err)) response.FailWithMessage("批量删除失败", c) } else { @@ -76,13 +83,13 @@ func Delete{{.StructName}}ByIds(c *gin.Context) { // @Security ApiKeyAuth // @accept application/json // @Produce application/json -// @Param data body model.{{.StructName}} true "更新{{.StructName}}" +// @Param data body autocode.{{.StructName}} true "更新{{.StructName}}" // @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}" // @Router /{{.Abbreviation}}/update{{.StructName}} [put] -func Update{{.StructName}}(c *gin.Context) { - var {{.Abbreviation}} model.{{.StructName}} +func ({{.Abbreviation}}Api *{{.StructName}}Api) Update{{.StructName}}(c *gin.Context) { + var {{.Abbreviation}} autocode.{{.StructName}} _ = c.ShouldBindJSON(&{{.Abbreviation}}) - if err := service.Update{{.StructName}}({{.Abbreviation}}); err != nil { + if err := {{.Abbreviation}}Service.Update{{.StructName}}({{.Abbreviation}}); err != nil { global.GVA_LOG.Error("更新失败!", zap.Any("err", err)) response.FailWithMessage("更新失败", c) } else { @@ -96,13 +103,13 @@ func Update{{.StructName}}(c *gin.Context) { // @Security ApiKeyAuth // @accept application/json // @Produce application/json -// @Param data body model.{{.StructName}} true "用id查询{{.StructName}}" +// @Param data body autocode.{{.StructName}} true "用id查询{{.StructName}}" // @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}" // @Router /{{.Abbreviation}}/find{{.StructName}} [get] -func Find{{.StructName}}(c *gin.Context) { - var {{.Abbreviation}} model.{{.StructName}} +func ({{.Abbreviation}}Api *{{.StructName}}Api) Find{{.StructName}}(c *gin.Context) { + var {{.Abbreviation}} autocode.{{.StructName}} _ = c.ShouldBindQuery(&{{.Abbreviation}}) - if err, re{{.Abbreviation}} := service.Get{{.StructName}}({{.Abbreviation}}.ID); err != nil { + if err, re{{.Abbreviation}} := {{.Abbreviation}}Service.Get{{.StructName}}({{.Abbreviation}}.ID); err != nil { global.GVA_LOG.Error("查询失败!", zap.Any("err", err)) response.FailWithMessage("查询失败", c) } else { @@ -116,13 +123,13 @@ func Find{{.StructName}}(c *gin.Context) { // @Security ApiKeyAuth // @accept application/json // @Produce application/json -// @Param data body request.{{.StructName}}Search true "分页获取{{.StructName}}列表" +// @Param data body autocodeReq.{{.StructName}}Search true "分页获取{{.StructName}}列表" // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}" // @Router /{{.Abbreviation}}/get{{.StructName}}List [get] -func Get{{.StructName}}List(c *gin.Context) { - var pageInfo request.{{.StructName}}Search +func ({{.Abbreviation}}Api *{{.StructName}}Api) Get{{.StructName}}List(c *gin.Context) { + var pageInfo autocodeReq.{{.StructName}}Search _ = c.ShouldBindQuery(&pageInfo) - if err, list, total := service.Get{{.StructName}}InfoList(pageInfo); err != nil { + if err, list, total := {{.Abbreviation}}Service.Get{{.StructName}}InfoList(pageInfo); err != nil { global.GVA_LOG.Error("获取失败!", zap.Any("err", err)) response.FailWithMessage("获取失败", c) } else { diff --git a/server/resource/template/server/model.go.tpl b/server/resource/template/server/model.go.tpl index b0b14e83..86e1874a 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" @@ -9,7 +9,7 @@ import ( // 如果含有time.Time 请自行import time包 type {{.StructName}} struct { global.GVA_MODEL {{- range .Fields}} - {{- if eq .FieldType "bool" }} + {{- if ne .FieldType "string" }} {{.FieldName}} *{{.FieldType}} `json:"{{.FieldJson}}" form:"{{.FieldJson}}" gorm:"column:{{.ColumnName}};comment:{{.Comment}}{{- if .DataType -}};type:{{.DataType}}{{- end }}"` {{- else }} {{.FieldName}} {{.FieldType}} `json:"{{.FieldJson}}" form:"{{.FieldJson}}" gorm:"column:{{.ColumnName}};comment:{{.Comment}}{{- if .DataType -}};type:{{.DataType}}{{- if eq .FieldType "string" -}}{{- if .DataTypeLong -}}({{.DataTypeLong}}){{- end -}}{{- end -}};{{- if ne .FieldType "string" -}}{{- if .DataTypeLong -}}size:{{.DataTypeLong}};{{- end -}}{{- end -}}{{- end -}}"` diff --git a/server/resource/template/server/request.go.tpl b/server/resource/template/server/request.go.tpl index 68cc026d..e9e7f121 100644 --- a/server/resource/template/server/request.go.tpl +++ b/server/resource/template/server/request.go.tpl @@ -1,8 +1,11 @@ package request -import "gin-vue-admin/model" +import ( + "gin-vue-admin/model/autocode" + "gin-vue-admin/model/common/request" +) type {{.StructName}}Search struct{ - model.{{.StructName}} - PageInfo + autocode.{{.StructName}} + request.PageInfo } \ No newline at end of file diff --git a/server/resource/template/server/router.go.tpl b/server/resource/template/server/router.go.tpl index 0e649589..0100966b 100644 --- a/server/resource/template/server/router.go.tpl +++ b/server/resource/template/server/router.go.tpl @@ -1,4 +1,4 @@ -package router +package autocode import ( "gin-vue-admin/api/v1" @@ -6,15 +6,19 @@ import ( "github.com/gin-gonic/gin" ) +type {{.StructName}}Router struct { +} + // Init{{.StructName}}Router 初始化 {{.StructName}} 路由信息 -func Init{{.StructName}}Router(Router *gin.RouterGroup) { - {{.StructName}}Router := Router.Group("{{.Abbreviation}}").Use(middleware.OperationRecord()) +func (s *{{.StructName}}Router) Init{{.StructName}}Router(Router *gin.RouterGroup) { + {{.Abbreviation}}Router := Router.Group("{{.Abbreviation}}").Use(middleware.OperationRecord()) + var {{.Abbreviation}}Api = v1.ApiGroupApp.AutoCodeApiGroup.{{.StructName}}Api { - {{.StructName}}Router.POST("create{{.StructName}}", v1.Create{{.StructName}}) // 新建{{.StructName}} - {{.StructName}}Router.DELETE("delete{{.StructName}}", v1.Delete{{.StructName}}) // 删除{{.StructName}} - {{.StructName}}Router.DELETE("delete{{.StructName}}ByIds", v1.Delete{{.StructName}}ByIds) // 批量删除{{.StructName}} - {{.StructName}}Router.PUT("update{{.StructName}}", v1.Update{{.StructName}}) // 更新{{.StructName}} - {{.StructName}}Router.GET("find{{.StructName}}", v1.Find{{.StructName}}) // 根据ID获取{{.StructName}} - {{.StructName}}Router.GET("get{{.StructName}}List", v1.Get{{.StructName}}List) // 获取{{.StructName}}列表 + {{.Abbreviation}}Router.POST("create{{.StructName}}", {{.Abbreviation}}Api.Create{{.StructName}}) // 新建{{.StructName}} + {{.Abbreviation}}Router.DELETE("delete{{.StructName}}", {{.Abbreviation}}Api.Delete{{.StructName}}) // 删除{{.StructName}} + {{.Abbreviation}}Router.DELETE("delete{{.StructName}}ByIds", {{.Abbreviation}}Api.Delete{{.StructName}}ByIds) // 批量删除{{.StructName}} + {{.Abbreviation}}Router.PUT("update{{.StructName}}", {{.Abbreviation}}Api.Update{{.StructName}}) // 更新{{.StructName}} + {{.Abbreviation}}Router.GET("find{{.StructName}}", {{.Abbreviation}}Api.Find{{.StructName}}) // 根据ID获取{{.StructName}} + {{.Abbreviation}}Router.GET("get{{.StructName}}List", {{.Abbreviation}}Api.Get{{.StructName}}List) // 获取{{.StructName}}列表 } } diff --git a/server/resource/template/server/service.go.tpl b/server/resource/template/server/service.go.tpl index b1da36c5..69a04b1c 100644 --- a/server/resource/template/server/service.go.tpl +++ b/server/resource/template/server/service.go.tpl @@ -1,54 +1,58 @@ -package service +package autocode import ( "gin-vue-admin/global" - "gin-vue-admin/model" - "gin-vue-admin/model/request" + "gin-vue-admin/model/autocode" + "gin-vue-admin/model/common/request" + autoCodeReq "gin-vue-admin/model/autocode/request" ) +type {{.StructName}}Service struct { +} + // Create{{.StructName}} 创建{{.StructName}}记录 // Author [piexlmax](https://github.com/piexlmax) -func Create{{.StructName}}({{.Abbreviation}} model.{{.StructName}}) (err error) { +func ({{.Abbreviation}}Service *{{.StructName}}Service) Create{{.StructName}}({{.Abbreviation}} autocode.{{.StructName}}) (err error) { err = global.GVA_DB.Create(&{{.Abbreviation}}).Error return err } // Delete{{.StructName}} 删除{{.StructName}}记录 // Author [piexlmax](https://github.com/piexlmax) -func Delete{{.StructName}}({{.Abbreviation}} model.{{.StructName}}) (err error) { +func ({{.Abbreviation}}Service *{{.StructName}}Service)Delete{{.StructName}}({{.Abbreviation}} autocode.{{.StructName}}) (err error) { err = global.GVA_DB.Delete(&{{.Abbreviation}}).Error return err } // Delete{{.StructName}}ByIds 批量删除{{.StructName}}记录 // Author [piexlmax](https://github.com/piexlmax) -func Delete{{.StructName}}ByIds(ids request.IdsReq) (err error) { - err = global.GVA_DB.Delete(&[]model.{{.StructName}}{},"id in ?",ids.Ids).Error +func ({{.Abbreviation}}Service *{{.StructName}}Service)Delete{{.StructName}}ByIds(ids request.IdsReq) (err error) { + err = global.GVA_DB.Delete(&[]autocode.{{.StructName}}{},"id in ?",ids.Ids).Error return err } // Update{{.StructName}} 更新{{.StructName}}记录 // Author [piexlmax](https://github.com/piexlmax) -func Update{{.StructName}}({{.Abbreviation}} model.{{.StructName}}) (err error) { +func ({{.Abbreviation}}Service *{{.StructName}}Service)Update{{.StructName}}({{.Abbreviation}} autocode.{{.StructName}}) (err error) { err = global.GVA_DB.Save(&{{.Abbreviation}}).Error return err } // Get{{.StructName}} 根据id获取{{.StructName}}记录 // Author [piexlmax](https://github.com/piexlmax) -func Get{{.StructName}}(id uint) (err error, {{.Abbreviation}} model.{{.StructName}}) { +func ({{.Abbreviation}}Service *{{.StructName}}Service)Get{{.StructName}}(id uint) (err error, {{.Abbreviation}} autocode.{{.StructName}}) { err = global.GVA_DB.Where("id = ?", id).First(&{{.Abbreviation}}).Error return } // Get{{.StructName}}InfoList 分页获取{{.StructName}}记录 // Author [piexlmax](https://github.com/piexlmax) -func Get{{.StructName}}InfoList(info request.{{.StructName}}Search) (err error, list interface{}, total int64) { +func ({{.Abbreviation}}Service *{{.StructName}}Service)Get{{.StructName}}InfoList(info autoCodeReq.{{.StructName}}Search) (err error, list interface{}, total int64) { limit := info.PageSize offset := info.PageSize * (info.Page - 1) // 创建db - db := global.GVA_DB.Model(&model.{{.StructName}}{}) - var {{.Abbreviation}}s []model.{{.StructName}} + db := global.GVA_DB.Model(&autocode.{{.StructName}}{}) + var {{.Abbreviation}}s []autocode.{{.StructName}} // 如果有条件搜索 下方会自动创建搜索语句 {{- range .Fields}} {{- if .FieldSearchType}} @@ -61,15 +65,15 @@ func Get{{.StructName}}InfoList(info request.{{.StructName}}Search) (err error, db = db.Where("`{{.ColumnName}}` {{.FieldSearchType}} ?",{{if eq .FieldSearchType "LIKE"}}"%"+{{ end }}info.{{.FieldName}}{{if eq .FieldSearchType "LIKE"}}+"%"{{ end }}) } {{- else if eq .FieldType "int" }} - if info.{{.FieldName}} != 0 { + if info.{{.FieldName}} != nil { db = db.Where("`{{.ColumnName}}` {{.FieldSearchType}} ?",{{if eq .FieldSearchType "LIKE"}}"%"+{{ end }}info.{{.FieldName}}{{if eq .FieldSearchType "LIKE"}}+"%"{{ end }}) } {{- else if eq .FieldType "float64" }} - if info.{{.FieldName}} != 0 { + if info.{{.FieldName}} != nil { db = db.Where("`{{.ColumnName}}` {{.FieldSearchType}} ?",{{if eq .FieldSearchType "LIKE"}}"%"+{{ end }}info.{{.FieldName}}{{if eq .FieldSearchType "LIKE"}}+"%"{{ end }}) } {{- else if eq .FieldType "time.Time" }} - if !info.{{.FieldName}}.IsZero() { + if !info.{{.FieldName}} != nil { db = db.Where("`{{.ColumnName}}` {{.FieldSearchType}} ?",{{if eq .FieldSearchType "LIKE"}}"%"+{{ end }}info.{{.FieldName}}{{if eq .FieldSearchType "LIKE"}}+"%"{{ end }}) } {{- end }} diff --git a/server/resource/template/web/table.vue.tpl b/server/resource/template/web/table.vue.tpl index da6123d9..52d68967 100644 --- a/server/resource/template/web/table.vue.tpl +++ b/server/resource/template/web/table.vue.tpl @@ -4,7 +4,7 @@ {{- range .Fields}} {{- if .FieldSearchType}} {{- if eq .FieldType "bool" }} - + 0 { for k := range authority { - err = findChildrenAuthority(&authority[k]) + err = authorityService.findChildrenAuthority(&authority[k]) } } return err, authority, total @@ -117,7 +123,7 @@ func GetAuthorityInfoList(info request.PageInfo) (err error, list interface{}, t //@param: auth model.SysAuthority //@return: err error, sa model.SysAuthority -func GetAuthorityInfo(auth model.SysAuthority) (err error, sa model.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,8 +134,8 @@ func GetAuthorityInfo(auth model.SysAuthority) (err error, sa model.SysAuthority //@param: auth model.SysAuthority //@return: error -func SetDataAuthority(auth model.SysAuthority) error { - var s model.SysAuthority +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) return err @@ -141,8 +147,8 @@ func SetDataAuthority(auth model.SysAuthority) error { //@param: auth *model.SysAuthority //@return: error -func SetMenuAuthority(auth *model.SysAuthority) error { - var s model.SysAuthority +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) return err @@ -154,11 +160,11 @@ func SetMenuAuthority(auth *model.SysAuthority) error { //@param: authority *model.SysAuthority //@return: err error -func findChildrenAuthority(authority *model.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 68% rename from server/service/sys_auto_code.go rename to server/service/system/sys_auto_code.go index 679120af..0fb7a143 100644 --- a/server/service/sys_auto_code.go +++ b/server/service/system/sys_auto_code.go @@ -1,14 +1,17 @@ -package service +package system import ( + "encoding/json" "errors" + "fmt" "gin-vue-admin/global" - "gin-vue-admin/model" - "gin-vue-admin/model/request" + "gin-vue-admin/model/system" + "gin-vue-admin/model/system/request" "gin-vue-admin/utils" "io/ioutil" "os" "path/filepath" + "strconv" "strings" "text/template" @@ -16,10 +19,56 @@ import ( ) const ( - autoPath = "autoCode/" + autoPath = "autocode_template/" basePath = "resource/template" ) +var injectionPaths []injectionMeta + +func Init() { + if len(injectionPaths) != 0 { + return + } + injectionPaths = []injectionMeta{ + { + path: filepath.Join(global.GVA_CONFIG.AutoCode.Root, + global.GVA_CONFIG.AutoCode.Server, global.GVA_CONFIG.AutoCode.SInitialize, "gorm.go"), + funcName: "MysqlTables", + structNameF: "autocode.%s{},", + }, + { + path: filepath.Join(global.GVA_CONFIG.AutoCode.Root, + global.GVA_CONFIG.AutoCode.Server, global.GVA_CONFIG.AutoCode.SInitialize, "router.go"), + funcName: "Routers", + structNameF: "autocodeRouter.Init%sRouter(PrivateGroup)", + }, + { + path: filepath.Join(global.GVA_CONFIG.AutoCode.Root, + global.GVA_CONFIG.AutoCode.Server, global.GVA_CONFIG.AutoCode.SApi, "enter.go"), + funcName: "ApiGroup", + structNameF: "%sApi", + }, + { + path: filepath.Join(global.GVA_CONFIG.AutoCode.Root, + global.GVA_CONFIG.AutoCode.Server, global.GVA_CONFIG.AutoCode.SRouter, "enter.go"), + funcName: "RouterGroup", + structNameF: "%sRouter", + }, + { + path: filepath.Join(global.GVA_CONFIG.AutoCode.Root, + global.GVA_CONFIG.AutoCode.Server, global.GVA_CONFIG.AutoCode.SService, "enter.go"), + funcName: "ServiceGroup", + structNameF: "%sService", + }, + } +} + +type injectionMeta struct { + path string + funcName string + structNameF string // 带格式化的 +} + type tplData struct { template *template.Template locationPath string @@ -27,14 +76,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 model.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 } @@ -98,11 +152,12 @@ func PreviewTemp(autoCode model.AutoCodeStruct) (map[string]string, error) { //@param: model.AutoCodeStruct //@return: err error -func CreateTemp(autoCode model.AutoCodeStruct) (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 } + meta, _ := json.Marshal(autoCode) // 写入文件前,先创建文件夹 if err = utils.CreateDir(needMkdir...); err != nil { return err @@ -125,39 +180,76 @@ func CreateTemp(autoCode model.AutoCodeStruct) (err error) { return } }() + bf := strings.Builder{} + idBf := strings.Builder{} + injectionCodeMeta := strings.Builder{} + for _, id := range ids { + idBf.WriteString(strconv.Itoa(int(id))) + idBf.WriteString(";") + } if autoCode.AutoMoveFile { // 判断是否需要自动转移 - for index, _ := range dataList { - addAutoMoveFile(&dataList[index]) + Init() + for index := range dataList { + autoCodeService.addAutoMoveFile(&dataList[index]) } for _, value := range dataList { // 移动文件 if err := utils.FileMove(value.autoCodePath, value.autoMoveFilePath); err != nil { return err } } - initializeGormFilePath := filepath.Join(global.GVA_CONFIG.AutoCode.Root, - global.GVA_CONFIG.AutoCode.Server, global.GVA_CONFIG.AutoCode.SInitialize, "gorm.go") - initializeRouterFilePath := filepath.Join(global.GVA_CONFIG.AutoCode.Root, - global.GVA_CONFIG.AutoCode.Server, global.GVA_CONFIG.AutoCode.SInitialize, "router.go") - err = utils.AutoInjectionCode(initializeGormFilePath, "MysqlTables", "model."+autoCode.StructName+"{},") + err = injectionCode(autoCode.StructName, &injectionCodeMeta) if err != nil { - return err + return } - err = utils.AutoInjectionCode(initializeRouterFilePath, "Routers", "router.Init"+autoCode.StructName+"Router(PrivateGroup)") - if err != nil { - return err + // 保存生成信息 + for _, data := range dataList { + if len(data.autoMoveFilePath) != 0 { + bf.WriteString(data.autoMoveFilePath) + bf.WriteString(";") + } } + if global.GVA_CONFIG.AutoCode.TransferRestart { go func() { _ = utils.Reload() }() } - return errors.New("创建代码成功并移动文件成功") } else { // 打包 - if err := utils.ZipFiles("./ginvueadmin.zip", fileList, ".", "."); err != nil { + if err = utils.ZipFiles("./ginvueadmin.zip", fileList, ".", "."); err != nil { return err } } + if autoCode.AutoMoveFile || autoCode.AutoCreateApiToSql { + if autoCode.TableName != "" { + err = AutoCodeHistoryServiceApp.CreateAutoCodeHistory( + string(meta), + autoCode.StructName, + autoCode.Description, + bf.String(), + injectionCodeMeta.String(), + autoCode.TableName, + idBf.String(), + ) + } else { + err = AutoCodeHistoryServiceApp.CreateAutoCodeHistory( + string(meta), + autoCode.StructName, + autoCode.Description, + bf.String(), + injectionCodeMeta.String(), + autoCode.StructName, + idBf.String(), + ) + } + } + if err != nil { + return err + } + if autoCode.AutoMoveFile { + return errors.New("创建代码成功并移动文件成功") + } return nil + } //@author: [piexlmax](https://github.com/piexlmax) @@ -166,11 +258,11 @@ func CreateTemp(autoCode model.AutoCodeStruct) (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 } @@ -189,7 +281,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 } @@ -199,7 +291,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 } @@ -210,11 +302,15 @@ 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 (autoCodeService *AutoCodeService) DropTable(tableName string) error { + return global.GVA_DB.Exec("DROP TABLE " + tableName).Error +} + //@author: [SliverHorn](https://github.com/SliverHorn) //@author: [songzhibin97](https://github.com/songzhibin97) //@function: addAutoMoveFile @@ -222,7 +318,7 @@ func GetColumn(tableName string, dbName string) (err error, Columns []request.Co //@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) @@ -267,8 +363,8 @@ func addAutoMoveFile(data *tplData) { //@param: a *model.AutoCodeStruct //@return: err error -func AutoCreateApi(a *model.AutoCodeStruct) (err error) { - var apiList = []model.SysApi{ +func (autoCodeService *AutoCodeService) AutoCreateApi(a *system.AutoCodeStruct) (ids []uint, err error) { + var apiList = []system.SysApi{ { Path: "/" + a.Abbreviation + "/" + "create" + a.StructName, Description: "新增" + a.Description, @@ -307,27 +403,30 @@ func AutoCreateApi(a *model.AutoCodeStruct) (err error) { }, } err = global.GVA_DB.Transaction(func(tx *gorm.DB) error { + for _, v := range apiList { - var api model.SysApi + var api system.SysApi if errors.Is(tx.Where("path = ? AND method = ?", v.Path, v.Method).First(&api).Error, gorm.ErrRecordNotFound) { - if err := tx.Create(&v).Error; err != nil { // 遇到错误时回滚事务 + if err = tx.Create(&v).Error; err != nil { // 遇到错误时回滚事务 return err + } else { + ids = append(ids, v.ID) } } } return nil }) - return err + return ids, err } -func getNeedList(autoCode *model.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 } @@ -348,7 +447,6 @@ func getNeedList(autoCode *model.AutoCodeStruct) (dataList []tplData, fileList [ // 生成文件路径,填充 autoCodePath 字段,readme.txt.tpl不符合规则,需要特殊处理 // resource/template/web/api.js.tpl -> autoCode/web/autoCode.PackageName/api/autoCode.PackageName.js // resource/template/readme.txt.tpl -> autoCode/readme.txt - autoPath := "autoCode/" for index, value := range dataList { trimBase := strings.TrimPrefix(value.locationPath, basePath+"/") if trimBase == "readme.txt.tpl" { @@ -361,10 +459,10 @@ func getNeedList(autoCode *model.AutoCodeStruct) (dataList []tplData, fileList [ firstDot := strings.Index(origFileName, ".") if firstDot != -1 { var fileName string - if origFileName[firstDot:] !=".go"{ - fileName = autoCode.PackageName+origFileName[firstDot:] - }else{ - fileName = autoCode.HumpPackageName+origFileName[firstDot:] + if origFileName[firstDot:] != ".go" { + fileName = autoCode.PackageName + origFileName[firstDot:] + } else { + fileName = autoCode.HumpPackageName + origFileName[firstDot:] } dataList[index].autoCodePath = filepath.Join(autoPath, trimBase[:lastSeparator], autoCode.PackageName, @@ -381,3 +479,15 @@ func getNeedList(autoCode *model.AutoCodeStruct) (dataList []tplData, fileList [ } return dataList, fileList, needMkdir, err } + +// injectionCode 封装代码注入 +func injectionCode(structName string, bf *strings.Builder) error { + for _, meta := range injectionPaths { + code := fmt.Sprintf(meta.structNameF, structName) + if err := utils.AutoInjectionCode(meta.path, meta.funcName, code); err != nil { + return err + } + bf.WriteString(fmt.Sprintf("%s@%s@%s;", meta.path, meta.funcName, code)) + } + return nil +} diff --git a/server/service/system/sys_autocode_history.go b/server/service/system/sys_autocode_history.go new file mode 100644 index 00000000..8a70da78 --- /dev/null +++ b/server/service/system/sys_autocode_history.go @@ -0,0 +1,92 @@ +package system + +import ( + "gin-vue-admin/global" + "gin-vue-admin/model/common/request" + "gin-vue-admin/model/system" + "gin-vue-admin/utils" + "strings" + + "go.uber.org/zap" +) + +type AutoCodeHistoryService struct { +} + +var AutoCodeHistoryServiceApp = new(AutoCodeHistoryService) + +// CreateAutoCodeHistory RouterPath : RouterPath@RouterString;RouterPath2@RouterString2 +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, + InjectionMeta: injectionMeta, + StructName: structName, + StructCNName: structCNName, + TableName: tableName, + ApiIDs: apiIds, + }).Error +} + +// RollBack 回滚 +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 := ApiServiceApp.DeleteApiByIds(strings.Split(md.ApiIDs, ";")) + if err != nil { + global.GVA_LOG.Error("ClearTag DeleteApiByIds:", zap.Error(err)) + } + // 获取全部表名 + err, dbNames := AutoCodeServiceApp.GetTables(global.GVA_CONFIG.Mysql.Dbname) + if err != nil { + global.GVA_LOG.Error("ClearTag GetTables:", zap.Error(err)) + } + // 删除表 + for _, name := range dbNames { + if strings.Contains(strings.ToUpper(strings.Replace(name.TableName, "_", "", -1)), strings.ToUpper(md.TableName)) { + // 删除表 + if err = AutoCodeServiceApp.DropTable(name.TableName); err != nil { + global.GVA_LOG.Error("ClearTag DropTable:", zap.Error(err)) + + } + } + } + // 删除文件 + for _, path := range strings.Split(md.AutoCodePath, ";") { + _ = utils.DeLFile(path) + } + // 清除注入 + for _, v := range strings.Split(md.InjectionMeta, ";") { + // RouterPath@functionName@RouterString + meta := strings.Split(v, "@") + if len(meta) == 3 { + _ = utils.AutoClearCode(meta[0], meta[2]) + } + } + md.Flag = 1 + return global.GVA_DB.Save(&md).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 (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 + var fileLists []system.SysAutoCodeHistory + err = db.Find(&fileLists).Count(&total).Error + err = db.Limit(limit).Offset(offset).Order("updated_at desc").Select("id,created_at,updated_at,struct_name,struct_cn_name,flag,table_name").Find(&fileLists).Error + return err, fileLists, total +} + +// DeletePage 删除历史数据 +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 75% rename from server/service/sys_base_menu.go rename to server/service/system/sys_base_menu.go index 3e6378a7..865a3338 100644 --- a/server/service/sys_base_menu.go +++ b/server/service/system/sys_base_menu.go @@ -1,24 +1,27 @@ -package service +package system import ( "errors" "gin-vue-admin/global" - "gin-vue-admin/model" + "gin-vue-admin/model/system" "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) { - err = global.GVA_DB.Preload("Parameters").Where("parent_id = ?", id).First(&model.SysBaseMenu{}).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 model.SysBaseMenu + var menu system.SysBaseMenu db := global.GVA_DB.Preload("SysAuthoritys").Where("id = ?", id).First(&menu).Delete(&menu) - err = global.GVA_DB.Delete(&model.SysBaseMenuParameter{}, "sys_base_menu_id = ?", id).Error + err = global.GVA_DB.Delete(&system.SysBaseMenuParameter{}, "sys_base_menu_id = ?", id).Error if len(menu.SysAuthoritys) > 0 { err = global.GVA_DB.Model(&menu).Association("SysAuthoritys").Delete(&menu.SysAuthoritys) } else { @@ -36,8 +39,8 @@ func DeleteBaseMenu(id float64) (err error) { //@param: menu model.SysBaseMenu //@return: err error -func UpdateBaseMenu(menu model.SysBaseMenu) (err error) { - var oldMenu model.SysBaseMenu +func (baseMenuService *BaseMenuService) UpdateBaseMenu(menu system.SysBaseMenu) (err error) { + var oldMenu system.SysBaseMenu upDateMap := make(map[string]interface{}) upDateMap["keep_alive"] = menu.KeepAlive upDateMap["close_tab"] = menu.CloseTab @@ -54,18 +57,18 @@ func UpdateBaseMenu(menu model.SysBaseMenu) (err error) { err = global.GVA_DB.Transaction(func(tx *gorm.DB) error { db := tx.Where("id = ?", menu.ID).Find(&oldMenu) if oldMenu.Name != menu.Name { - if !errors.Is(tx.Where("id <> ? AND name = ?", menu.ID, menu.Name).First(&model.SysBaseMenu{}).Error, gorm.ErrRecordNotFound) { + if !errors.Is(tx.Where("id <> ? AND name = ?", menu.ID, menu.Name).First(&system.SysBaseMenu{}).Error, gorm.ErrRecordNotFound) { global.GVA_LOG.Debug("存在相同name修改失败") return errors.New("存在相同name修改失败") } } - txErr := tx.Unscoped().Delete(&model.SysBaseMenuParameter{}, "sys_base_menu_id = ?", menu.ID).Error + txErr := tx.Unscoped().Delete(&system.SysBaseMenuParameter{}, "sys_base_menu_id = ?", menu.ID).Error if txErr != nil { global.GVA_LOG.Debug(txErr.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 model.SysBaseMenu) (err error) { //@param: id float64 //@return: err error, menu model.SysBaseMenu -func GetBaseMenuById(id float64) (err error, menu model.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 67% rename from server/service/sys_casbin.go rename to server/service/system/sys_casbin.go index 93c8bff0..7ad61142 100644 --- a/server/service/sys_casbin.go +++ b/server/service/system/sys_casbin.go @@ -1,10 +1,10 @@ -package service +package system import ( "errors" "gin-vue-admin/global" - "gin-vue-admin/model" - "gin-vue-admin/model/request" + "gin-vue-admin/model/system" + "gin-vue-admin/model/system/request" "github.com/casbin/casbin/v2" "github.com/casbin/casbin/v2/util" gormadapter "github.com/casbin/gorm-adapter/v3" @@ -19,11 +19,16 @@ 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 := model.CasbinModel{ + cm := system.CasbinModel{ Ptype: "p", AuthorityId: authorityId, Path: v.Path, @@ -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,8 +50,8 @@ 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 { - err := global.GVA_DB.Table("casbin_rule").Model(&model.CasbinModel{}).Where("v1 = ? AND v2 = ?", oldPath, oldMethod).Updates(map[string]interface{}{ +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, }).Error @@ -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 71% rename from server/service/sys_dictionary.go rename to server/service/system/sys_dictionary.go index 4f7251df..451c2b2a 100644 --- a/server/service/sys_dictionary.go +++ b/server/service/system/sys_dictionary.go @@ -1,10 +1,10 @@ -package service +package system import ( "errors" "gin-vue-admin/global" - "gin-vue-admin/model" - "gin-vue-admin/model/request" + "gin-vue-admin/model/system" + "gin-vue-admin/model/system/request" "gorm.io/gorm" ) @@ -14,8 +14,11 @@ import ( //@param: sysDictionary model.SysDictionary //@return: err error -func CreateSysDictionary(sysDictionary model.SysDictionary) (err error) { - if (!errors.Is(global.GVA_DB.First(&model.SysDictionary{}, "type = ?", sysDictionary.Type).Error, gorm.ErrRecordNotFound)) { +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,不允许创建") } err = global.GVA_DB.Create(&sysDictionary).Error @@ -28,7 +31,7 @@ func CreateSysDictionary(sysDictionary model.SysDictionary) (err error) { //@param: sysDictionary model.SysDictionary //@return: err error -func DeleteSysDictionary(sysDictionary model.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,8 +42,8 @@ func DeleteSysDictionary(sysDictionary model.SysDictionary) (err error) { //@param: sysDictionary *model.SysDictionary //@return: err error -func UpdateSysDictionary(sysDictionary *model.SysDictionary) (err error) { - var dict model.SysDictionary +func (dictionaryService *DictionaryService) UpdateSysDictionary(sysDictionary *system.SysDictionary) (err error) { + var dict system.SysDictionary sysDictionaryMap := map[string]interface{}{ "Name": sysDictionary.Name, "Type": sysDictionary.Type, @@ -51,7 +54,7 @@ func UpdateSysDictionary(sysDictionary *model.SysDictionary) (err error) { if dict.Type == sysDictionary.Type { err = db.Updates(sysDictionaryMap).Error } else { - if (!errors.Is(global.GVA_DB.First(&model.SysDictionary{}, "type = ?", sysDictionary.Type).Error, gorm.ErrRecordNotFound)) { + if (!errors.Is(global.GVA_DB.First(&system.SysDictionary{}, "type = ?", sysDictionary.Type).Error, gorm.ErrRecordNotFound)) { return errors.New("存在相同的type,不允许创建") } err = db.Updates(sysDictionaryMap).Error @@ -66,7 +69,7 @@ func UpdateSysDictionary(sysDictionary *model.SysDictionary) (err error) { //@param: Type string, Id uint //@return: err error, sysDictionary model.SysDictionary -func GetSysDictionary(Type string, Id uint) (err error, sysDictionary model.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,12 +81,12 @@ func GetSysDictionary(Type string, Id uint) (err error, sysDictionary model.SysD //@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 - db := global.GVA_DB.Model(&model.SysDictionary{}) - var sysDictionarys []model.SysDictionary + db := global.GVA_DB.Model(&system.SysDictionary{}) + var sysDictionarys []system.SysDictionary // 如果有条件搜索 下方会自动创建搜索语句 if info.Name != "" { db = db.Where("`name` LIKE ?", "%"+info.Name+"%") diff --git a/server/service/sys_dictionary_detail.go b/server/service/system/sys_dictionary_detail.go similarity index 67% rename from server/service/sys_dictionary_detail.go rename to server/service/system/sys_dictionary_detail.go index bbc2f2a7..1b6eb09b 100644 --- a/server/service/sys_dictionary_detail.go +++ b/server/service/system/sys_dictionary_detail.go @@ -1,9 +1,9 @@ -package service +package system import ( "gin-vue-admin/global" - "gin-vue-admin/model" - "gin-vue-admin/model/request" + "gin-vue-admin/model/system" + "gin-vue-admin/model/system/request" ) //@author: [piexlmax](https://github.com/piexlmax) @@ -12,7 +12,10 @@ import ( //@param: sysDictionaryDetail model.SysDictionaryDetail //@return: err error -func CreateSysDictionaryDetail(sysDictionaryDetail model.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 model.SysDictionaryDetail) (e //@param: sysDictionaryDetail model.SysDictionaryDetail //@return: err error -func DeleteSysDictionaryDetail(sysDictionaryDetail model.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 model.SysDictionaryDetail) (e //@param: sysDictionaryDetail *model.SysDictionaryDetail //@return: err error -func UpdateSysDictionaryDetail(sysDictionaryDetail *model.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 *model.SysDictionaryDetail) ( //@param: id uint //@return: err error, sysDictionaryDetail model.SysDictionaryDetail -func GetSysDictionaryDetail(id uint) (err error, sysDictionaryDetail model.SysDictionaryDetail) { +func (dictionaryDetailService *DictionaryDetailService) GetSysDictionaryDetail(id uint) (err error, sysDictionaryDetail system.SysDictionaryDetail) { err = global.GVA_DB.Where("id = ?", id).First(&sysDictionaryDetail).Error return } @@ -56,12 +59,12 @@ func GetSysDictionaryDetail(id uint) (err error, sysDictionaryDetail model.SysDi //@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 - db := global.GVA_DB.Model(&model.SysDictionaryDetail{}) - var sysDictionaryDetails []model.SysDictionaryDetail + db := global.GVA_DB.Model(&system.SysDictionaryDetail{}) + var sysDictionaryDetails []system.SysDictionaryDetail // 如果有条件搜索 下方会自动创建搜索语句 if info.Label != "" { db = db.Where("label LIKE ?", "%"+info.Label+"%") 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 08b7b7d0..2addb45c 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 74% rename from server/service/sys_initdb.go rename to server/service/system/sys_initdb.go index b84a0868..91ac5ba5 100644 --- a/server/service/sys_initdb.go +++ b/server/service/system/sys_initdb.go @@ -1,12 +1,13 @@ -package service +package system import ( "database/sql" "fmt" "gin-vue-admin/config" "gin-vue-admin/global" - "gin-vue-admin/model" - "gin-vue-admin/model/request" + "gin-vue-admin/model/example" + "gin-vue-admin/model/system" + "gin-vue-admin/model/system/request" "gin-vue-admin/source" "gin-vue-admin/utils" "path/filepath" @@ -22,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 { @@ -37,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 @@ -55,7 +59,7 @@ func createTable(dsn string, driver string, createSql string) error { return err } -func initDB(InitDBFunctions ...model.InitDBFunc) (err error) { +func (initDBService *InitDBService) initDB(InitDBFunctions ...system.InitDBFunc) (err error) { for _, v := range InitDBFunctions { err = v.Init() if err != nil { @@ -71,7 +75,7 @@ func initDB(InitDBFunctions ...model.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" @@ -82,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 } @@ -117,26 +121,27 @@ func InitDB(conf request.InitDB) error { } err := global.GVA_DB.AutoMigrate( - model.SysUser{}, - model.SysAuthority{}, - model.SysApi{}, - model.SysBaseMenu{}, - model.SysBaseMenuParameter{}, - model.JwtBlacklist{}, - model.SysDictionary{}, - model.SysDictionaryDetail{}, - model.ExaFileUploadAndDownload{}, - model.ExaFile{}, - model.ExaFileChunk{}, - model.ExaSimpleUploader{}, - model.ExaCustomer{}, - model.SysOperationRecord{}, + system.SysUser{}, + system.SysAuthority{}, + system.SysApi{}, + system.SysBaseMenu{}, + system.SysBaseMenuParameter{}, + system.JwtBlacklist{}, + system.SysDictionary{}, + system.SysDictionaryDetail{}, + example.ExaFileUploadAndDownload{}, + example.ExaFile{}, + example.ExaFileChunk{}, + example.ExaSimpleUploader{}, + example.ExaCustomer{}, + system.SysOperationRecord{}, + system.SysAutoCodeHistory{}, ) if err != nil { global.GVA_DB = nil return err } - err = initDB( + err = initDBService.initDB( source.Admin, source.Api, source.AuthorityMenu, @@ -147,12 +152,14 @@ func InitDB(conf request.InitDB) error { source.Dictionary, source.DictionaryDetail, source.File, - source.BaseMenu) + source.BaseMenu, + source.UserAuthority, + ) if err != nil { 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 65% rename from server/service/sys_menu.go rename to server/service/system/sys_menu.go index b26c1d3b..f6b311cc 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" - "gin-vue-admin/model/request" + "gin-vue-admin/model/common/request" + "gin-vue-admin/model/system" "gorm.io/gorm" "strconv" ) @@ -15,9 +15,14 @@ import ( //@param: authorityId string //@return: err error, treeMap map[string][]model.SysMenu -func getMenuTreeMap(authorityId string) (err error, treeMap map[string][]model.SysMenu) { - var allMenus []model.SysMenu - treeMap = make(map[string][]model.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 for _, v := range allMenus { treeMap[v.ParentId] = append(treeMap[v.ParentId], v) @@ -31,11 +36,11 @@ func getMenuTreeMap(authorityId string) (err error, treeMap map[string][]model.S //@param: authorityId string //@return: err error, menus []model.SysMenu -func GetMenuTree(authorityId string) (err error, menus []model.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 []model.SysMenu) { //@param: menu *model.SysMenu, treeMap map[string][]model.SysMenu //@return: err error -func getChildrenList(menu *model.SysMenu, treeMap map[string][]model.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 *model.SysMenu, treeMap map[string][]model.SysMenu) (e //@description: 获取路由分页 //@return: err error, list interface{}, total int64 -func GetInfoList() (err error, list interface{}, total int64) { - var menuList []model.SysBaseMenu - err, treeMap := getBaseMenuTreeMap() +func (menuService *MenuService) GetInfoList() (err error, list interface{}, total int64) { + var menuList []system.SysBaseMenu + 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 *model.SysBaseMenu, treeMap map[string][]model.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,8 +94,8 @@ func getBaseChildrenList(menu *model.SysBaseMenu, treeMap map[string][]model.Sys //@param: menu model.SysBaseMenu //@return: error -func AddBaseMenu(menu model.SysBaseMenu) error { - if !errors.Is(global.GVA_DB.Where("name = ?", menu.Name).First(&model.SysBaseMenu{}).Error, gorm.ErrRecordNotFound) { +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") } return global.GVA_DB.Create(&menu).Error @@ -101,9 +106,9 @@ func AddBaseMenu(menu model.SysBaseMenu) error { //@description: 获取路由总树map //@return: err error, treeMap map[string][]model.SysBaseMenu -func getBaseMenuTreeMap() (err error, treeMap map[string][]model.SysBaseMenu) { - var allMenus []model.SysBaseMenu - treeMap = make(map[string][]model.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 for _, v := range allMenus { treeMap[v.ParentId] = append(treeMap[v.ParentId], v) @@ -116,11 +121,11 @@ func getBaseMenuTreeMap() (err error, treeMap map[string][]model.SysBaseMenu) { //@description: 获取基础路由树 //@return: err error, menus []model.SysBaseMenu -func GetBaseMenuTree() (err error, menus []model.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 []model.SysBaseMenu) { //@param: menus []model.SysBaseMenu, authorityId string //@return: err error -func AddMenuAuthority(menus []model.SysBaseMenu, authorityId string) (err error) { - var auth model.SysAuthority +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 []model.SysBaseMenu, authorityId string) (err error) //@param: info *request.GetAuthorityId //@return: err error, menus []model.SysMenu -func GetMenuAuthority(info *request.GetAuthorityId) (err error, menus []model.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 62% rename from server/service/sys_operation_record.go rename to server/service/system/sys_operation_record.go index 8cd85d58..903e8936 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" - "gin-vue-admin/model/request" + "gin-vue-admin/model/common/request" + "gin-vue-admin/model/system" + 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 model.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,8 +28,8 @@ func CreateSysOperationRecord(sysOperationRecord model.SysOperationRecord) (err //@param: ids request.IdsReq //@return: err error -func DeleteSysOperationRecordByIds(ids request.IdsReq) (err error) { - err = global.GVA_DB.Delete(&[]model.SysOperationRecord{}, "id in (?)", ids.Ids).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 model.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 model.SysOperationRecord) (err //@param: id uint //@return: err error, sysOperationRecord model.SysOperationRecord -func GetSysOperationRecord(id uint) (err error, sysOperationRecord model.SysOperationRecord) { +func (operationRecordService *OperationRecordService) GetSysOperationRecord(id uint) (err error, sysOperationRecord system.SysOperationRecord) { err = global.GVA_DB.Where("id = ?", id).First(&sysOperationRecord).Error return } @@ -55,15 +59,15 @@ func GetSysOperationRecord(id uint) (err error, sysOperationRecord model.SysOper //@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 - db := global.GVA_DB.Model(&model.SysOperationRecord{}) - var sysOperationRecords []model.SysOperationRecord + db := global.GVA_DB.Model(&system.SysOperationRecord{}) + var sysOperationRecords []system.SysOperationRecord // 如果有条件搜索 下方会自动创建搜索语句 if info.Method != "" { db = db.Where("method = ?", info.Method) diff --git a/server/service/sys_system.go b/server/service/system/sys_system.go similarity index 77% rename from server/service/sys_system.go rename to server/service/system/sys_system.go index 66d83b2e..d19614d6 100644 --- a/server/service/sys_system.go +++ b/server/service/system/sys_system.go @@ -1,9 +1,9 @@ -package service +package system import ( "gin-vue-admin/config" "gin-vue-admin/global" - "gin-vue-admin/model" + "gin-vue-admin/model/system" "gin-vue-admin/utils" "go.uber.org/zap" ) @@ -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 model.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 model.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/system/sys_user.go b/server/service/system/sys_user.go new file mode 100644 index 00000000..894c3e56 --- /dev/null +++ b/server/service/system/sys_user.go @@ -0,0 +1,178 @@ +package system + +import ( + "errors" + "gin-vue-admin/global" + "gin-vue-admin/model/common/request" + "gin-vue-admin/model/system" + "gin-vue-admin/utils" + uuid "github.com/satori/go.uuid" + "gorm.io/gorm" +) + +//@author: [piexlmax](https://github.com/piexlmax) +//@function: Register +//@description: 用户注册 +//@param: u model.SysUser +//@return: err error, userInter model.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 + } + // 否则 附加uuid 密码md5简单加密 注册 + u.Password = utils.MD5V([]byte(u.Password)) + u.UUID = uuid.NewV4() + err = global.GVA_DB.Create(&u).Error + return err, u +} + +//@author: [piexlmax](https://github.com/piexlmax) +//@function: Login +//@description: 用户登录 +//@param: u *model.SysUser +//@return: err error, userInter *model.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("Authorities").Preload("Authority").First(&user).Error + return err, &user +} + +//@author: [piexlmax](https://github.com/piexlmax) +//@function: ChangePassword +//@description: 修改用户密码 +//@param: u *model.SysUser, newPassword string +//@return: err error, userInter *model.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 + return err, u +} + +//@author: [piexlmax](https://github.com/piexlmax) +//@function: GetUserInfoList +//@description: 分页获取数据 +//@param: info request.PageInfo +//@return: 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{}) + var userList []system.SysUser + err = db.Count(&total).Error + err = db.Limit(limit).Offset(offset).Preload("Authorities").Preload("Authority").Find(&userList).Error + return err, userList, total +} + +//@author: [piexlmax](https://github.com/piexlmax) +//@function: SetUserAuthority +//@description: 设置一个用户的权限 +//@param: uuid uuid.UUID, authorityId string +//@return: err error + +func (userService *UserService) SetUserAuthority(id uint, uuid uuid.UUID, authorityId string) (err error) { + assignErr := global.GVA_DB.Where("sys_user_id = ? AND sys_authority_authority_id = ?", id, authorityId).First(&system.SysUseAuthority{}).Error + if errors.Is(assignErr, gorm.ErrRecordNotFound) { + return errors.New("该用户无此角色") + } + err = global.GVA_DB.Where("uuid = ?", uuid).First(&system.SysUser{}).Update("authority_id", authorityId).Error + return err +} + +//@author: [piexlmax](https://github.com/piexlmax) +//@function: SetUserAuthorities +//@description: 设置一个用户的权限 +//@param: id uint, authorityIds []string +//@return: err error + +func (userService *UserService) SetUserAuthorities(id uint, authorityIds []string) (err error) { + return global.GVA_DB.Transaction(func(tx *gorm.DB) error { + TxErr := tx.Delete(&[]system.SysUseAuthority{}, "sys_user_id = ?", id).Error + if TxErr != nil { + return TxErr + } + useAuthority := []system.SysUseAuthority{} + for _, v := range authorityIds { + useAuthority = append(useAuthority, system.SysUseAuthority{ + id, v, + }) + } + TxErr = tx.Create(&useAuthority).Error + if TxErr != nil { + return TxErr + } + // 返回 nil 提交事务 + return nil + }) +} + +//@author: [piexlmax](https://github.com/piexlmax) +//@function: DeleteUser +//@description: 删除用户 +//@param: id float64 +//@return: err error + +func (userService *UserService) DeleteUser(id float64) (err error) { + var user system.SysUser + err = global.GVA_DB.Where("id = ?", id).Delete(&user).Error + err = global.GVA_DB.Delete(&[]system.SysUseAuthority{}, "sys_user_id = ?", id).Error + return err +} + +//@author: [piexlmax](https://github.com/piexlmax) +//@function: SetUserInfo +//@description: 设置用户信息 +//@param: reqUser model.SysUser +//@return: err error, user model.SysUser + +func (userService *UserService) SetUserInfo(reqUser system.SysUser) (err error, user system.SysUser) { + err = global.GVA_DB.Updates(&reqUser).Error + return err, reqUser +} + +//@author: [piexlmax](https://github.com/piexlmax) +//@function: GetUserInfo +//@description: 获取用户信息 +//@param: uuid uuid.UUID +//@return: err error, user system.SysUser + +func (userService *UserService) GetUserInfo(uuid uuid.UUID) (err error, user system.SysUser) { + var reqUser system.SysUser + err = global.GVA_DB.Preload("Authorities").Preload("Authority").First(&reqUser, "uuid = ?", uuid).Error + return err, reqUser +} + +//@author: [SliverHorn](https://github.com/SliverHorn) +//@function: FindUserById +//@description: 通过id获取用户信息 +//@param: id int +//@return: err error, user *model.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 +} + +//@author: [SliverHorn](https://github.com/SliverHorn) +//@function: FindUserByUuid +//@description: 通过uuid获取用户信息 +//@param: uuid string +//@return: err error, user *model.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 + } + return nil, &u +} diff --git a/server/source/admin.go b/server/source/admin.go index 1f0f36c0..96ca8e31 100644 --- a/server/source/admin.go +++ b/server/source/admin.go @@ -2,7 +2,7 @@ package source import ( "gin-vue-admin/global" - "gin-vue-admin/model" + "gin-vue-admin/model/system" "github.com/gookit/color" "time" @@ -14,7 +14,7 @@ var Admin = new(admin) type admin struct{} -var admins = []model.SysUser{ +var admins = []system.SysUser{ {GVA_MODEL: global.GVA_MODEL{ID: 1, CreatedAt: time.Now(), UpdatedAt: time.Now()}, UUID: uuid.NewV4(), Username: "admin", Password: "e10adc3949ba59abbe56e057f20f883e", NickName: "超级管理员", HeaderImg: "http://qmplusimg.henrongyi.top/gva_header.jpg", AuthorityId: "888"}, {GVA_MODEL: global.GVA_MODEL{ID: 2, CreatedAt: time.Now(), UpdatedAt: time.Now()}, UUID: uuid.NewV4(), Username: "a303176530", Password: "3ec063004a6f31642261936a379fde3d", NickName: "QMPlusUser", HeaderImg: "http://qmplusimg.henrongyi.top/1572075907logo.png", AuthorityId: "9528"}, } @@ -23,7 +23,7 @@ var admins = []model.SysUser{ //@description: sys_users 表数据初始化 func (a *admin) Init() error { return global.GVA_DB.Transaction(func(tx *gorm.DB) error { - if tx.Where("id IN ?", []int{1, 2}).Find(&[]model.SysUser{}).RowsAffected == 2 { + if tx.Where("id IN ?", []int{1, 2}).Find(&[]system.SysUser{}).RowsAffected == 2 { color.Danger.Println("\n[Mysql] --> sys_users 表的初始数据已存在!") return nil } diff --git a/server/source/api.go b/server/source/api.go index f3c1cffe..d46d7668 100644 --- a/server/source/api.go +++ b/server/source/api.go @@ -2,7 +2,7 @@ package source import ( "gin-vue-admin/global" - "gin-vue-admin/model" + "gin-vue-admin/model/system" "github.com/gookit/color" "time" @@ -13,9 +13,9 @@ var Api = new(api) type api struct{} -var apis = []model.SysApi{ - {global.GVA_MODEL{ID: 1, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/base/login", "用户登录", "base", "POST"}, - {global.GVA_MODEL{ID: 2, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/user/register", "用户注册", "user", "POST"}, +var apis = []system.SysApi{ + {global.GVA_MODEL{ID: 1, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/base/login", "用户登录(必选)", "base", "POST"}, + {global.GVA_MODEL{ID: 2, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/user/register", "用户注册(必选)", "user", "POST"}, {global.GVA_MODEL{ID: 3, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/api/createApi", "创建api", "api", "POST"}, {global.GVA_MODEL{ID: 4, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/api/getApiList", "获取api列表", "api", "POST"}, {global.GVA_MODEL{ID: 5, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/api/getApiById", "获取api详细信息", "api", "POST"}, @@ -25,7 +25,7 @@ var apis = []model.SysApi{ {global.GVA_MODEL{ID: 9, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/authority/createAuthority", "创建角色", "authority", "POST"}, {global.GVA_MODEL{ID: 10, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/authority/deleteAuthority", "删除角色", "authority", "POST"}, {global.GVA_MODEL{ID: 11, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/authority/getAuthorityList", "获取角色列表", "authority", "POST"}, - {global.GVA_MODEL{ID: 12, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/menu/getMenu", "获取菜单树", "menu", "POST"}, + {global.GVA_MODEL{ID: 12, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/menu/getMenu", "获取菜单树(必选)", "menu", "POST"}, {global.GVA_MODEL{ID: 13, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/menu/getMenuList", "分页获取基础menu列表", "menu", "POST"}, {global.GVA_MODEL{ID: 14, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/menu/addBaseMenu", "新增菜单", "menu", "POST"}, {global.GVA_MODEL{ID: 15, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/menu/getBaseMenuTree", "获取用户动态路由", "menu", "POST"}, @@ -34,15 +34,15 @@ var apis = []model.SysApi{ {global.GVA_MODEL{ID: 18, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/menu/deleteBaseMenu", "删除菜单", "menu", "POST"}, {global.GVA_MODEL{ID: 19, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/menu/updateBaseMenu", "更新菜单", "menu", "POST"}, {global.GVA_MODEL{ID: 20, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/menu/getBaseMenuById", "根据id获取菜单", "menu", "POST"}, - {global.GVA_MODEL{ID: 21, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/user/changePassword", "修改密码", "user", "POST"}, + {global.GVA_MODEL{ID: 21, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/user/changePassword", "修改密码(建议选择)", "user", "POST"}, {global.GVA_MODEL{ID: 23, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/user/getUserList", "获取用户列表", "user", "POST"}, - {global.GVA_MODEL{ID: 24, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/user/setUserAuthority", "修改用户角色", "user", "POST"}, + {global.GVA_MODEL{ID: 24, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/user/setUserAuthority", "修改用户角色(必选)", "user", "POST"}, {global.GVA_MODEL{ID: 25, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/fileUploadAndDownload/upload", "文件上传示例", "fileUploadAndDownload", "POST"}, {global.GVA_MODEL{ID: 26, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/fileUploadAndDownload/getFileList", "获取上传文件列表", "fileUploadAndDownload", "POST"}, {global.GVA_MODEL{ID: 27, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/casbin/updateCasbin", "更改角色api权限", "casbin", "POST"}, {global.GVA_MODEL{ID: 28, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/casbin/getPolicyPathByAuthorityId", "获取权限列表", "casbin", "POST"}, {global.GVA_MODEL{ID: 29, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/fileUploadAndDownload/deleteFile", "删除文件", "fileUploadAndDownload", "POST"}, - {global.GVA_MODEL{ID: 30, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/jwt/jsonInBlacklist", "jwt加入黑名单(退出)", "jwt", "POST"}, + {global.GVA_MODEL{ID: 30, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/jwt/jsonInBlacklist", "jwt加入黑名单(退出,必选)", "jwt", "POST"}, {global.GVA_MODEL{ID: 31, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/authority/setDataAuthority", "设置角色资源权限", "authority", "POST"}, {global.GVA_MODEL{ID: 32, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/system/getSystemConfig", "获取配置文件内容", "system", "POST"}, {global.GVA_MODEL{ID: 33, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/system/setSystemConfig", "设置配置文件内容", "system", "POST"}, @@ -77,7 +77,7 @@ var apis = []model.SysApi{ {global.GVA_MODEL{ID: 62, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/simpleUploader/upload", "插件版分片上传", "simpleUploader", "POST"}, {global.GVA_MODEL{ID: 63, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/simpleUploader/checkFileMd5", "文件完整度验证", "simpleUploader", "GET"}, {global.GVA_MODEL{ID: 64, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/simpleUploader/mergeFileMd5", "上传完成合并文件", "simpleUploader", "GET"}, - {global.GVA_MODEL{ID: 65, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/user/setUserInfo", "设置用户信息", "user", "PUT"}, + {global.GVA_MODEL{ID: 65, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/user/setUserInfo", "设置用户信息(必选)", "user", "PUT"}, {global.GVA_MODEL{ID: 66, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/system/getServerInfo", "获取服务器信息", "system", "POST"}, {global.GVA_MODEL{ID: 67, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/email/emailTest", "发送测试邮件", "email", "POST"}, {global.GVA_MODEL{ID: 80, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/autoCode/preview", "预览自动化代码", "autoCode", "POST"}, @@ -86,13 +86,19 @@ var apis = []model.SysApi{ {global.GVA_MODEL{ID: 83, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/excel/exportExcel", "导出excel", "excel", "POST"}, {global.GVA_MODEL{ID: 84, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/excel/downloadTemplate", "下载excel模板", "excel", "GET"}, {global.GVA_MODEL{ID: 85, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/api/deleteApisByIds", "批量删除api", "api", "DELETE"}, + {global.GVA_MODEL{ID: 86, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/autoCode/getSysHistory", "查询回滚记录", "autoCode", "POST"}, + {global.GVA_MODEL{ID: 87, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/autoCode/rollback", "回滚自动生成代码", "autoCode", "POST"}, + {global.GVA_MODEL{ID: 88, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/autoCode/getMeta", "获取meta信息", "autoCode", "POST"}, + {global.GVA_MODEL{ID: 89, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/autoCode/delSysHistory", "删除回滚记录", "autoCode", "POST"}, + {global.GVA_MODEL{ID: 90, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/user/setUserAuthorities", "设置权限组", "user", "POST"}, + {global.GVA_MODEL{ID: 91, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/user/getUserInfo", "获取自身信息(必选)", "user", "GET"}, } //@author: [SliverHorn](https://github.com/SliverHorn) //@description: sys_apis 表数据初始化 func (a *api) Init() error { return global.GVA_DB.Transaction(func(tx *gorm.DB) error { - if tx.Where("id IN ?", []int{1, 67}).Find(&[]model.SysApi{}).RowsAffected == 2 { + if tx.Where("id IN ?", []int{1, 67}).Find(&[]system.SysApi{}).RowsAffected == 2 { color.Danger.Println("\n[Mysql] --> sys_apis 表的初始数据已存在!") return nil } diff --git a/server/source/authorities_menus.go b/server/source/authorities_menus.go index 932ef0c3..0d0bc030 100644 --- a/server/source/authorities_menus.go +++ b/server/source/authorities_menus.go @@ -39,6 +39,8 @@ var authorityMenus = []AuthorityMenus{ {"888", 21}, {"888", 22}, {"888", 23}, + {"888", 24}, + {"888", 25}, {"8881", 1}, {"8881", 2}, {"8881", 8}, diff --git a/server/source/authority.go b/server/source/authority.go index e0bbf117..0f4b4619 100644 --- a/server/source/authority.go +++ b/server/source/authority.go @@ -2,7 +2,7 @@ package source import ( "gin-vue-admin/global" - "gin-vue-admin/model" + "gin-vue-admin/model/system" "github.com/gookit/color" "time" @@ -13,7 +13,7 @@ var Authority = new(authority) type authority struct{} -var authorities = []model.SysAuthority{ +var authorities = []system.SysAuthority{ {CreatedAt: time.Now(), UpdatedAt: time.Now(), AuthorityId: "888", AuthorityName: "普通用户", ParentId: "0", DefaultRouter: "dashboard"}, {CreatedAt: time.Now(), UpdatedAt: time.Now(), AuthorityId: "8881", AuthorityName: "普通用户子角色", ParentId: "888", DefaultRouter: "dashboard"}, {CreatedAt: time.Now(), UpdatedAt: time.Now(), AuthorityId: "9528", AuthorityName: "测试角色", ParentId: "0", DefaultRouter: "dashboard"}, @@ -23,7 +23,7 @@ var authorities = []model.SysAuthority{ //@description: sys_authorities 表数据初始化 func (a *authority) Init() error { return global.GVA_DB.Transaction(func(tx *gorm.DB) error { - if tx.Where("authority_id IN ? ", []string{"888", "9528"}).Find(&[]model.SysAuthority{}).RowsAffected == 2 { + if tx.Where("authority_id IN ? ", []string{"888", "9528"}).Find(&[]system.SysAuthority{}).RowsAffected == 2 { color.Danger.Println("\n[Mysql] --> sys_authorities 表的初始数据已存在!") return nil } diff --git a/server/source/authority_menu.go b/server/source/authority_menu.go index ddd9a173..9c73b8d9 100644 --- a/server/source/authority_menu.go +++ b/server/source/authority_menu.go @@ -2,7 +2,7 @@ package source import ( "gin-vue-admin/global" - "gin-vue-admin/model" + "gin-vue-admin/model/system" "github.com/gookit/color" ) @@ -13,7 +13,7 @@ type authorityMenu struct{} //@author: [SliverHorn](https://github.com/SliverHorn) //@description: authority_menu 视图数据初始化 func (a *authorityMenu) Init() error { - if global.GVA_DB.Find(&[]model.SysMenu{}).RowsAffected > 0 { + if global.GVA_DB.Find(&[]system.SysMenu{}).RowsAffected > 0 { color.Danger.Println("\n[Mysql] --> authority_menu 视图已存在!") return nil } diff --git a/server/source/casbin.go b/server/source/casbin.go index a7b642c5..909bb2d2 100644 --- a/server/source/casbin.go +++ b/server/source/casbin.go @@ -86,6 +86,12 @@ var carbines = []gormadapter.CasbinRule{ {PType: "p", V0: "888", V1: "/excel/exportExcel", V2: "POST"}, {PType: "p", V0: "888", V1: "/excel/downloadTemplate", V2: "GET"}, {PType: "p", V0: "888", V1: "/api/deleteApisByIds", V2: "DELETE"}, + {PType: "p", V0: "888", V1: "/autoCode/getSysHistory", V2: "POST"}, + {PType: "p", V0: "888", V1: "/autoCode/rollback", V2: "POST"}, + {PType: "p", V0: "888", V1: "/autoCode/getMeta", V2: "POST"}, + {PType: "p", V0: "888", V1: "/autoCode/delSysHistory", V2: "POST"}, + {PType: "p", V0: "888", V1: "/user/setUserAuthorities", V2: "POST"}, + {PType: "p", V0: "888", V1: "/user/getUserInfo", V2: "GET"}, {PType: "p", V0: "8881", V1: "/base/login", V2: "POST"}, {PType: "p", V0: "8881", V1: "/user/register", V2: "POST"}, {PType: "p", V0: "8881", V1: "/api/createApi", V2: "POST"}, @@ -123,6 +129,7 @@ var carbines = []gormadapter.CasbinRule{ {PType: "p", V0: "8881", V1: "/customer/customer", V2: "DELETE"}, {PType: "p", V0: "8881", V1: "/customer/customer", V2: "GET"}, {PType: "p", V0: "8881", V1: "/customer/customerList", V2: "GET"}, + {PType: "p", V0: "8881", V1: "/user/getUserInfo", V2: "GET"}, {PType: "p", V0: "9528", V1: "/base/login", V2: "POST"}, {PType: "p", V0: "9528", V1: "/user/register", V2: "POST"}, {PType: "p", V0: "9528", V1: "/api/createApi", V2: "POST"}, @@ -161,6 +168,7 @@ var carbines = []gormadapter.CasbinRule{ {PType: "p", V0: "9528", V1: "/customer/customer", V2: "GET"}, {PType: "p", V0: "9528", V1: "/customer/customerList", V2: "GET"}, {PType: "p", V0: "9528", V1: "/autoCode/createTemp", V2: "POST"}, + {PType: "p", V0: "9528", V1: "/user/getUserInfo", V2: "GET"}, } //@author: [SliverHorn](https://github.com/SliverHorn) diff --git a/server/source/dictionary.go b/server/source/dictionary.go index e6ead8f1..dbfb886d 100644 --- a/server/source/dictionary.go +++ b/server/source/dictionary.go @@ -2,7 +2,7 @@ package source import ( "gin-vue-admin/global" - "gin-vue-admin/model" + "gin-vue-admin/model/system" "github.com/gookit/color" "time" @@ -19,7 +19,7 @@ var status = new(bool) //@description: sys_dictionaries 表数据初始化 func (d *dictionary) Init() error { *status = true - var dictionaries = []model.SysDictionary{ + var dictionaries = []system.SysDictionary{ {GVA_MODEL: global.GVA_MODEL{ID: 1, CreatedAt: time.Now(), UpdatedAt: time.Now()}, Name: "性别", Type: "sex", Status: status, Desc: "性别字典"}, {GVA_MODEL: global.GVA_MODEL{ID: 2, CreatedAt: time.Now(), UpdatedAt: time.Now()}, Name: "数据库int类型", Type: "int", Status: status, Desc: "int类型对应的数据库类型"}, {GVA_MODEL: global.GVA_MODEL{ID: 3, CreatedAt: time.Now(), UpdatedAt: time.Now()}, Name: "数据库时间日期类型", Type: "time.Time", Status: status, Desc: "数据库时间日期类型"}, @@ -28,7 +28,7 @@ func (d *dictionary) Init() error { {GVA_MODEL: global.GVA_MODEL{ID: 6, CreatedAt: time.Now(), UpdatedAt: time.Now()}, Name: "数据库bool类型", Type: "bool", Status: status, Desc: "数据库bool类型"}, } return global.GVA_DB.Transaction(func(tx *gorm.DB) error { - if tx.Where("id IN ?", []int{1, 6}).Find(&[]model.SysDictionary{}).RowsAffected == 2 { + if tx.Where("id IN ?", []int{1, 6}).Find(&[]system.SysDictionary{}).RowsAffected == 2 { color.Danger.Println("\n[Mysql] --> sys_dictionaries 表初始数据已存在!") return nil } diff --git a/server/source/dictionary_details.go b/server/source/dictionary_details.go index 06825368..2b3c0632 100644 --- a/server/source/dictionary_details.go +++ b/server/source/dictionary_details.go @@ -2,7 +2,7 @@ package source import ( "gin-vue-admin/global" - "gin-vue-admin/model" + "gin-vue-admin/model/system" "github.com/gookit/color" "time" @@ -16,7 +16,7 @@ type dictionaryDetail struct{} //@author: [SliverHorn](https://github.com/SliverHorn) //@description: dictionary_details 表数据初始化 func (d *dictionaryDetail) Init() error { - var details = []model.SysDictionaryDetail{ + var details = []system.SysDictionaryDetail{ {global.GVA_MODEL{ID: 1, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "smallint", 1, status, 1, 2}, {global.GVA_MODEL{ID: 2, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "mediumint", 2, status, 2, 2}, {global.GVA_MODEL{ID: 3, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "int", 3, status, 3, 2}, @@ -42,7 +42,7 @@ func (d *dictionaryDetail) Init() error { {global.GVA_MODEL{ID: 23, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "tinyint", 0, status, 0, 6}, } return global.GVA_DB.Transaction(func(tx *gorm.DB) error { - if tx.Where("id IN ?", []int{1, 23}).Find(&[]model.SysDictionaryDetail{}).RowsAffected == 2 { + if tx.Where("id IN ?", []int{1, 23}).Find(&[]system.SysDictionaryDetail{}).RowsAffected == 2 { color.Danger.Println("\n[Mysql] --> sys_dictionary_details 表的初始数据已存在!") return nil } diff --git a/server/source/file.go b/server/source/file.go index 2b7aa712..ea1f624e 100644 --- a/server/source/file.go +++ b/server/source/file.go @@ -2,7 +2,7 @@ package source import ( "gin-vue-admin/global" - "gin-vue-admin/model" + "gin-vue-admin/model/example" "github.com/gookit/color" "gorm.io/gorm" "time" @@ -12,7 +12,7 @@ var File = new(file) type file struct{} -var files = []model.ExaFileUploadAndDownload{ +var files = []example.ExaFileUploadAndDownload{ {global.GVA_MODEL{ID: 1, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "10.png", "http://qmplusimg.henrongyi.top/gvalogo.png", "png", "158787308910.png"}, {global.GVA_MODEL{ID: 2, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "logo.png", "http://qmplusimg.henrongyi.top/1576554439myAvatar.png", "png", "1587973709logo.png"}, } @@ -21,7 +21,7 @@ var files = []model.ExaFileUploadAndDownload{ //@description: exa_file_upload_and_downloads 表初始化数据 func (f *file) Init() error { return global.GVA_DB.Transaction(func(tx *gorm.DB) error { - if tx.Where("id IN ?", []int{1, 2}).Find(&[]model.ExaFileUploadAndDownload{}).RowsAffected == 2 { + if tx.Where("id IN ?", []int{1, 2}).Find(&[]example.ExaFileUploadAndDownload{}).RowsAffected == 2 { color.Danger.Println("\n[Mysql] --> exa_file_upload_and_downloads 表初始数据已存在!") return nil } diff --git a/server/source/menu.go b/server/source/menu.go index 673e7c2c..e66e2469 100644 --- a/server/source/menu.go +++ b/server/source/menu.go @@ -2,7 +2,7 @@ package source import ( "gin-vue-admin/global" - "gin-vue-admin/model" + "gin-vue-admin/model/system" "github.com/gookit/color" "time" @@ -13,37 +13,39 @@ var BaseMenu = new(menu) type menu struct{} -var menus = []model.SysBaseMenu{ - {GVA_MODEL: global.GVA_MODEL{ID: 1, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, ParentId: "0", Path: "dashboard", Name: "dashboard", Hidden: false, Component: "view/dashboard/index.vue", Sort: 1, Meta: model.Meta{Title: "仪表盘", Icon: "setting"}}, - {GVA_MODEL: global.GVA_MODEL{ID: 2, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "0", Path: "about", Name: "about", Component: "view/about/index.vue", Sort: 7, Meta: model.Meta{Title: "关于我们", Icon: "info"}}, - {GVA_MODEL: global.GVA_MODEL{ID: 3, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "0", Path: "admin", Name: "superAdmin", Component: "view/superAdmin/index.vue", Sort: 3, Meta: model.Meta{Title: "超级管理员", Icon: "user-solid"}}, - {GVA_MODEL: global.GVA_MODEL{ID: 4, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "3", Path: "authority", Name: "authority", Component: "view/superAdmin/authority/authority.vue", Sort: 1, Meta: model.Meta{Title: "角色管理", Icon: "s-custom"}}, - {GVA_MODEL: global.GVA_MODEL{ID: 5, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "3", Path: "menu", Name: "menu", Component: "view/superAdmin/menu/menu.vue", Sort: 2, Meta: model.Meta{Title: "菜单管理", Icon: "s-order", KeepAlive: true}}, - {GVA_MODEL: global.GVA_MODEL{ID: 6, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "3", Path: "api", Name: "api", Component: "view/superAdmin/api/api.vue", Sort: 3, Meta: model.Meta{Title: "api管理", Icon: "s-platform", KeepAlive: true}}, - {GVA_MODEL: global.GVA_MODEL{ID: 7, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "3", Path: "user", Name: "user", Component: "view/superAdmin/user/user.vue", Sort: 4, Meta: model.Meta{Title: "用户管理", Icon: "coordinate"}}, - {GVA_MODEL: global.GVA_MODEL{ID: 8, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: true, ParentId: "0", Path: "person", Name: "person", Component: "view/person/person.vue", Sort: 4, Meta: model.Meta{Title: "个人信息", Icon: "message-solid"}}, - {GVA_MODEL: global.GVA_MODEL{ID: 9, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "0", Path: "example", Name: "example", Component: "view/example/index.vue", Sort: 6, Meta: model.Meta{Title: "示例文件", Icon: "s-management"}}, - {GVA_MODEL: global.GVA_MODEL{ID: 10, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "9", Path: "excel", Name: "excel", Component: "view/example/excel/excel.vue", Sort: 4, Meta: model.Meta{Title: "excel导入导出", Icon: "s-marketing"}}, - {GVA_MODEL: global.GVA_MODEL{ID: 11, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "9", Path: "upload", Name: "upload", Component: "view/example/upload/upload.vue", Sort: 5, Meta: model.Meta{Title: "媒体库(上传下载)", Icon: "upload"}}, - {GVA_MODEL: global.GVA_MODEL{ID: 12, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "9", Path: "breakpoint", Name: "breakpoint", Component: "view/example/breakpoint/breakpoint.vue", Sort: 6, Meta: model.Meta{Title: "断点续传", Icon: "upload"}}, - {GVA_MODEL: global.GVA_MODEL{ID: 13, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "9", Path: "customer", Name: "customer", Component: "view/example/customer/customer.vue", Sort: 7, Meta: model.Meta{Title: "客户列表(资源示例)", Icon: "s-custom"}}, - {GVA_MODEL: global.GVA_MODEL{ID: 14, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "0", Path: "systemTools", Name: "systemTools", Component: "view/systemTools/index.vue", Sort: 5, Meta: model.Meta{Title: "系统工具", Icon: "s-cooperation"}}, - {GVA_MODEL: global.GVA_MODEL{ID: 15, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "14", Path: "autoCode", Name: "autoCode", Component: "view/systemTools/autoCode/index.vue", Sort: 1, Meta: model.Meta{Title: "代码生成器", Icon: "cpu", KeepAlive: true}}, - {GVA_MODEL: global.GVA_MODEL{ID: 16, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "14", Path: "formCreate", Name: "formCreate", Component: "view/systemTools/formCreate/index.vue", Sort: 2, Meta: model.Meta{Title: "表单生成器", Icon: "magic-stick", KeepAlive: true}}, - {GVA_MODEL: global.GVA_MODEL{ID: 17, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "14", Path: "system", Name: "system", Component: "view/systemTools/system/system.vue", Sort: 3, Meta: model.Meta{Title: "系统配置", Icon: "s-operation"}}, - {GVA_MODEL: global.GVA_MODEL{ID: 18, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "3", Path: "dictionary", Name: "dictionary", Component: "view/superAdmin/dictionary/sysDictionary.vue", Sort: 5, Meta: model.Meta{Title: "字典管理", Icon: "notebook-2"}}, - {GVA_MODEL: global.GVA_MODEL{ID: 19, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: true, ParentId: "3", Path: "dictionaryDetail/:id", Name: "dictionaryDetail", Component: "view/superAdmin/dictionary/sysDictionaryDetail.vue", Sort: 1, Meta: model.Meta{Title: "字典详情", Icon: "s-order"}}, - {GVA_MODEL: global.GVA_MODEL{ID: 20, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "3", Path: "operation", Name: "operation", Component: "view/superAdmin/operation/sysOperationRecord.vue", Sort: 6, Meta: model.Meta{Title: "操作历史", Icon: "time"}}, - {GVA_MODEL: global.GVA_MODEL{ID: 21, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "9", Path: "simpleUploader", Name: "simpleUploader", Component: "view/example/simpleUploader/simpleUploader", Sort: 6, Meta: model.Meta{Title: "断点续传(插件版)", Icon: "upload"}}, - {GVA_MODEL: global.GVA_MODEL{ID: 22, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, ParentId: "0", Path: "https://www.gin-vue-admin.com", Name: "https://www.gin-vue-admin.com", Hidden: false, Component: "/", Sort: 0, Meta: model.Meta{Title: "官方网站", Icon: "s-home"}}, - {GVA_MODEL: global.GVA_MODEL{ID: 23, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, ParentId: "0", Path: "state", Name: "state", Hidden: false, Component: "view/system/state.vue", Sort: 6, Meta: model.Meta{Title: "服务器状态", Icon: "cloudy"}}, +var menus = []system.SysBaseMenu{ + {GVA_MODEL: global.GVA_MODEL{ID: 1, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, ParentId: "0", Path: "dashboard", Name: "dashboard", Hidden: false, Component: "view/dashboard/index.vue", Sort: 1, Meta: system.Meta{Title: "仪表盘", Icon: "setting"}}, + {GVA_MODEL: global.GVA_MODEL{ID: 2, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "0", Path: "about", Name: "about", Component: "view/about/index.vue", Sort: 7, Meta: system.Meta{Title: "关于我们", Icon: "info"}}, + {GVA_MODEL: global.GVA_MODEL{ID: 3, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "0", Path: "admin", Name: "superAdmin", Component: "view/superAdmin/index.vue", Sort: 3, Meta: system.Meta{Title: "超级管理员", Icon: "user-solid"}}, + {GVA_MODEL: global.GVA_MODEL{ID: 4, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "3", Path: "authority", Name: "authority", Component: "view/superAdmin/authority/authority.vue", Sort: 1, Meta: system.Meta{Title: "角色管理", Icon: "s-custom"}}, + {GVA_MODEL: global.GVA_MODEL{ID: 5, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "3", Path: "menu", Name: "menu", Component: "view/superAdmin/menu/menu.vue", Sort: 2, Meta: system.Meta{Title: "菜单管理", Icon: "s-order", KeepAlive: true}}, + {GVA_MODEL: global.GVA_MODEL{ID: 6, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "3", Path: "api", Name: "api", Component: "view/superAdmin/api/api.vue", Sort: 3, Meta: system.Meta{Title: "api管理", Icon: "s-platform", KeepAlive: true}}, + {GVA_MODEL: global.GVA_MODEL{ID: 7, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "3", Path: "user", Name: "user", Component: "view/superAdmin/user/user.vue", Sort: 4, Meta: system.Meta{Title: "用户管理", Icon: "coordinate"}}, + {GVA_MODEL: global.GVA_MODEL{ID: 8, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: true, ParentId: "0", Path: "person", Name: "person", Component: "view/person/person.vue", Sort: 4, Meta: system.Meta{Title: "个人信息", Icon: "message-solid"}}, + {GVA_MODEL: global.GVA_MODEL{ID: 9, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "0", Path: "example", Name: "example", Component: "view/example/index.vue", Sort: 6, Meta: system.Meta{Title: "示例文件", Icon: "s-management"}}, + {GVA_MODEL: global.GVA_MODEL{ID: 10, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "9", Path: "excel", Name: "excel", Component: "view/example/excel/excel.vue", Sort: 4, Meta: system.Meta{Title: "excel导入导出", Icon: "s-marketing"}}, + {GVA_MODEL: global.GVA_MODEL{ID: 11, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "9", Path: "upload", Name: "upload", Component: "view/example/upload/upload.vue", Sort: 5, Meta: system.Meta{Title: "媒体库(上传下载)", Icon: "upload"}}, + {GVA_MODEL: global.GVA_MODEL{ID: 12, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "9", Path: "breakpoint", Name: "breakpoint", Component: "view/example/breakpoint/breakpoint.vue", Sort: 6, Meta: system.Meta{Title: "断点续传", Icon: "upload"}}, + {GVA_MODEL: global.GVA_MODEL{ID: 13, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "9", Path: "customer", Name: "customer", Component: "view/example/customer/customer.vue", Sort: 7, Meta: system.Meta{Title: "客户列表(资源示例)", Icon: "s-custom"}}, + {GVA_MODEL: global.GVA_MODEL{ID: 14, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "0", Path: "systemTools", Name: "systemTools", Component: "view/systemTools/index.vue", Sort: 5, Meta: system.Meta{Title: "系统工具", Icon: "s-cooperation"}}, + {GVA_MODEL: global.GVA_MODEL{ID: 15, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "14", Path: "autoCode", Name: "autoCode", Component: "view/systemTools/autoCode/index.vue", Sort: 1, Meta: system.Meta{Title: "代码生成器", Icon: "cpu", KeepAlive: true}}, + {GVA_MODEL: global.GVA_MODEL{ID: 16, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "14", Path: "formCreate", Name: "formCreate", Component: "view/systemTools/formCreate/index.vue", Sort: 2, Meta: system.Meta{Title: "表单生成器", Icon: "magic-stick", KeepAlive: true}}, + {GVA_MODEL: global.GVA_MODEL{ID: 17, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "14", Path: "system", Name: "system", Component: "view/systemTools/system/system.vue", Sort: 3, Meta: system.Meta{Title: "系统配置", Icon: "s-operation"}}, + {GVA_MODEL: global.GVA_MODEL{ID: 18, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "3", Path: "dictionary", Name: "dictionary", Component: "view/superAdmin/dictionary/sysDictionary.vue", Sort: 5, Meta: system.Meta{Title: "字典管理", Icon: "notebook-2"}}, + {GVA_MODEL: global.GVA_MODEL{ID: 19, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: true, ParentId: "3", Path: "dictionaryDetail/:id", Name: "dictionaryDetail", Component: "view/superAdmin/dictionary/sysDictionaryDetail.vue", Sort: 1, Meta: system.Meta{Title: "字典详情", Icon: "s-order"}}, + {GVA_MODEL: global.GVA_MODEL{ID: 20, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "3", Path: "operation", Name: "operation", Component: "view/superAdmin/operation/sysOperationRecord.vue", Sort: 6, Meta: system.Meta{Title: "操作历史", Icon: "time"}}, + {GVA_MODEL: global.GVA_MODEL{ID: 21, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "9", Path: "simpleUploader", Name: "simpleUploader", Component: "view/example/simpleUploader/simpleUploader", Sort: 6, Meta: system.Meta{Title: "断点续传(插件版)", Icon: "upload"}}, + {GVA_MODEL: global.GVA_MODEL{ID: 22, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, ParentId: "0", Path: "https://www.gin-vue-admin.com", Name: "https://www.gin-vue-admin.com", Hidden: false, Component: "/", Sort: 0, Meta: system.Meta{Title: "官方网站", Icon: "s-home"}}, + {GVA_MODEL: global.GVA_MODEL{ID: 23, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, ParentId: "0", Path: "state", Name: "state", Hidden: false, Component: "view/system/state.vue", Sort: 6, Meta: system.Meta{Title: "服务器状态", Icon: "cloudy"}}, + {GVA_MODEL: global.GVA_MODEL{ID: 24, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, ParentId: "14", Path: "autoCodeAdmin", Name: "autoCodeAdmin", Hidden: false, Component: "view/systemTools/autoCodeAdmin/index.vue", Sort: 1, Meta: system.Meta{Title: "自动化代码管理", Icon: "s-finance"}}, + {GVA_MODEL: global.GVA_MODEL{ID: 25, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, ParentId: "14", Path: "autoCodeEdit/:id", Name: "autoCodeEdit", Hidden: true, Component: "view/systemTools/autoCode/index.vue", Sort: 0, Meta: system.Meta{Title: "自动化代码(复用)", Icon: "s-finance"}}, } //@author: [SliverHorn](https://github.com/SliverHorn) //@description: sys_base_menus 表数据初始化 func (m *menu) Init() error { return global.GVA_DB.Transaction(func(tx *gorm.DB) error { - if tx.Where("id IN ?", []int{1, 29}).Find(&[]model.SysBaseMenu{}).RowsAffected == 2 { + if tx.Where("id IN ?", []int{1, 29}).Find(&[]system.SysBaseMenu{}).RowsAffected == 2 { color.Danger.Println("\n[Mysql] --> sys_base_menus 表的初始数据已存在!") return nil } diff --git a/server/source/user_authority.go.go b/server/source/user_authority.go.go new file mode 100644 index 00000000..197675c9 --- /dev/null +++ b/server/source/user_authority.go.go @@ -0,0 +1,34 @@ +package source + +import ( + "gin-vue-admin/global" + "gin-vue-admin/model/system" + "github.com/gookit/color" + "gorm.io/gorm" +) + +var UserAuthority = new(userAuthority) + +type userAuthority struct{} + +var userAuthorityModel = []system.SysUseAuthority{ + {1, "888"}, + {1, "8881"}, + {1, "9528"}, + {2, "888"}, +} + +//@description: user_authority 数据初始化 +func (a *userAuthority) Init() error { + return global.GVA_DB.Model(&system.SysUseAuthority{}).Transaction(func(tx *gorm.DB) error { + if tx.Where("sys_user_id IN (1, 2)").Find(&[]AuthorityMenus{}).RowsAffected == 4 { + color.Danger.Println("\n[Mysql] --> sys_user_authority 表的初始数据已存在!") + return nil + } + if err := tx.Create(&userAuthorityModel).Error; err != nil { // 遇到错误时回滚事务 + return err + } + color.Info.Println("\n[Mysql] --> sys_user_authority 表初始数据成功!") + return nil + }) +} diff --git a/server/utils/captcha/redis.go b/server/utils/captcha/redis.go new file mode 100644 index 00000000..2e0a906f --- /dev/null +++ b/server/utils/captcha/redis.go @@ -0,0 +1,50 @@ +package captcha + +import ( + "gin-vue-admin/global" + "time" + + "github.com/mojocn/base64Captcha" + "go.uber.org/zap" +) + +func NewDefaultRedisStore() base64Captcha.Store { + return &RedisStore{ + Expiration: time.Second * 180, + PreKey: "CAPTCHA_", + } +} + +type RedisStore struct { + Expiration time.Duration + PreKey string +} + +func (rs *RedisStore) Set(id string, value string) { + err := global.GVA_REDIS.Set(rs.PreKey+id, value, rs.Expiration).Err() + if err != nil { + global.GVA_LOG.Error("RedisStoreSetError!", zap.Error(err)) + } +} + +func (rs *RedisStore) Get(key string, clear bool) string { + val, err := global.GVA_REDIS.Get(key).Result() + if err != nil { + global.GVA_LOG.Error("RedisStoreGetError!", zap.Error(err)) + return "" + } + if clear { + err := global.GVA_REDIS.Del(key).Err() + if err != nil { + global.GVA_LOG.Error("RedisStoreClearError!", zap.Error(err)) + return "" + } + } + return val +} + +func (rs *RedisStore) Verify(id, answer string, clear bool) bool { + key := rs.PreKey + id + v := rs.Get(key, clear) + return v == answer +} diff --git a/server/utils/clamis.go b/server/utils/clamis.go new file mode 100644 index 00000000..71deb93d --- /dev/null +++ b/server/utils/clamis.go @@ -0,0 +1,52 @@ +package utils + +import ( + "gin-vue-admin/global" + systemReq "gin-vue-admin/model/system/request" + "github.com/gin-gonic/gin" + uuid "github.com/satori/go.uuid" +) + +// 从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) uuid.UUID { + if claims, exists := c.Get("claims"); !exists { + global.GVA_LOG.Error("从Gin的Context中获取从jwt解析出来的用户UUID失败, 请检查路由是否使用jwt中间件!") + return uuid.UUID{} + } else { + waitUse := claims.(*systemReq.CustomClaims) + return waitUse.UUID + } +} + +// 从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 + } +} + +// 从Gin的Context中获取从jwt解析出来的用户角色id +func GetUserInfo(c *gin.Context) *systemReq.CustomClaims { + if claims, exists := c.Get("claims"); !exists { + global.GVA_LOG.Error("从Gin的Context中获取从jwt解析出来的用户UUID失败, 请检查路由是否使用jwt中间件!") + return nil + } else { + waitUse := claims.(*systemReq.CustomClaims) + return waitUse + } +} diff --git a/server/utils/file_operations.go b/server/utils/file_operations.go index 36115c69..0e747773 100644 --- a/server/utils/file_operations.go +++ b/server/utils/file_operations.go @@ -42,6 +42,10 @@ Redirect: return os.Rename(src, dst) } +func DeLFile(filePath string) error { + return os.RemoveAll(filePath) +} + //@author: [songzhibin97](https://github.com/songzhibin97) //@function: TrimSpace //@description: 去除结构体空格 diff --git a/server/utils/injectionCode.go b/server/utils/injectionCode.go index 5bc66c4f..5b12f11d 100644 --- a/server/utils/injectionCode.go +++ b/server/utils/injectionCode.go @@ -1,6 +1,7 @@ package utils import ( + "errors" "fmt" "go/ast" "go/parser" @@ -15,9 +16,18 @@ import ( //@param: filepath string, funcName string, codeData string //@return: error +const ( + startComment = "Code generated by gin-vue-admin Begin; DO NOT EDIT." + endComment = "Code generated by gin-vue-admin End; DO NOT EDIT." +) + +//@author: [LeonardWang](https://github.com/WangLeonard) +//@function: AutoInjectionCode +//@description: 向文件中固定注释位置写入代码 +//@param: filepath string, funcName string, codeData string +//@return: error + func AutoInjectionCode(filepath string, funcName string, codeData string) error { - startComment := "Code generated by gin-vue-admin Begin; DO NOT EDIT." - endComment := "Code generated by gin-vue-admin End; DO NOT EDIT." srcData, err := ioutil.ReadFile(filepath) if err != nil { return err @@ -141,3 +151,30 @@ func checkExist(srcData *[]byte, startPos int, endPos int, blockStmt *ast.BlockS } return false } + +func AutoClearCode(filepath string, codeData string) error { + srcData, err := ioutil.ReadFile(filepath) + if err != nil { + return err + } + srcData, err = cleanCode(codeData, string(srcData)) + if err != nil { + return err + } + return ioutil.WriteFile(filepath, srcData, 0600) +} + +func cleanCode(clearCode string, srcData string) ([]byte, error) { + bf := make([]rune, 0, 1024) + for i, v := range srcData { + if v == '\n' { + if strings.TrimSpace(string(bf)) == clearCode { + return append([]byte(srcData[:i-len(bf)]), []byte(srcData[i+1:])...), nil + } + bf = (bf)[:0] + continue + } + bf = append(bf, v) + } + return []byte(srcData), errors.New("未找到内容") +} diff --git a/server/utils/verify.go b/server/utils/verify.go index 9e5796f7..2725d473 100644 --- a/server/utils/verify.go +++ b/server/utils/verify.go @@ -14,5 +14,5 @@ var ( AuthorityIdVerify = Rules{"AuthorityId": {NotEmpty()}} OldAuthorityVerify = Rules{"OldAuthorityId": {NotEmpty()}} ChangePasswordVerify = Rules{"Username": {NotEmpty()}, "Password": {NotEmpty()}, "NewPassword": {NotEmpty()}} - SetUserAuthorityVerify = Rules{"UUID": {NotEmpty()}, "AuthorityId": {NotEmpty()}} + SetUserAuthorityVerify = Rules{"AuthorityId": {NotEmpty()}} ) diff --git a/web/Dockerfile b/web/Dockerfile index d616262d..b40db4ac 100644 --- a/web/Dockerfile +++ b/web/Dockerfile @@ -3,8 +3,7 @@ FROM node:12.16.1 WORKDIR /gva_web/ COPY . . -RUN npm install -g cnpm --registry=https://registry.npm.taobao.org -RUN cnpm install || npm install +RUN npm install RUN npm run build FROM nginx:alpine diff --git a/web/public/index.html b/web/public/index.html index 75281b94..20222d92 100644 --- a/web/public/index.html +++ b/web/public/index.html @@ -8,7 +8,7 @@ <%=htmlWebpackPlugin.options.title%> - <% if(process.env.NODE_ENV!=='development'){ %> + <% if(process.env.NODE_ENV!=='development' && htmlWebpackPlugin.options.cdns){ %> <% htmlWebpackPlugin.options.cdns.forEach(function(item){ if(item.js){ %> <% } }) %> diff --git a/web/src/api/autoCode.js b/web/src/api/autoCode.js index ad7f40bd..fc732919 100644 --- a/web/src/api/autoCode.js +++ b/web/src/api/autoCode.js @@ -60,3 +60,35 @@ export const getColumn = (params) => { params }) } + +export const getSysHistory = (data) => { + return service({ + url: '/autoCode/getSysHistory', + method: 'post', + data + }) +} + +export const rollback = (data) => { + return service({ + url: '/autoCode/rollback', + method: 'post', + data + }) +} + +export const getMeta = (data) => { + return service({ + url: '/autoCode/getMeta', + method: 'post', + data + }) +} + +export const delSysHistory = (data) => { + return service({ + url: '/autoCode/delSysHistory', + method: 'post', + data + }) +} diff --git a/web/src/api/user.js b/web/src/api/user.js index a833888c..32ee55c1 100644 --- a/web/src/api/user.js +++ b/web/src/api/user.js @@ -111,3 +111,33 @@ export const setUserInfo = (data) => { data: data }) } + +// @Tags User +// @Summary 设置用户权限 +// @Security ApiKeyAuth +// @accept application/json +// @Produce application/json +// @Param data body api.setUserAuthorities true "设置用户权限" +// @Success 200 {string} json "{"success":true,"data":{},"msg":"修改成功"}" +// @Router /user/setUserAuthorities [post] +export const setUserAuthorities = (data) => { + return service({ + url: '/user/setUserAuthorities', + method: 'post', + data: data + }) +} + +// @Tags User +// @Summary 获取用户信息 +// @Security ApiKeyAuth +// @accept application/json +// @Produce application/json +// @Success 200 {string} json "{"success":true,"data":{},"msg":"获取成功"}" +// @Router /user/getUserInfo [get] +export const getUserInfo = () => { + return service({ + url: '/user/getUserInfo', + method: 'get' + }) +} diff --git a/web/src/core/gin-vue-admin.js b/web/src/core/gin-vue-admin.js index 6a6f51dc..6f2381f3 100644 --- a/web/src/core/gin-vue-admin.js +++ b/web/src/core/gin-vue-admin.js @@ -22,7 +22,7 @@ Vue.use(uploader) console.log(` 欢迎使用 Gin-Vue-Admin - 当前版本:V2.4.3 + 当前版本:V2.4.4 加群方式:微信:shouzi_1994 QQ群:622360840 默认自动化文档地址:http://127.0.0.1:${process.env.VUE_APP_SERVER_PORT}/swagger/index.html 默认前端文件运行地址:http://127.0.0.1:${process.env.VUE_APP_CLI_PORT} diff --git a/web/src/permission.js b/web/src/permission.js index eef9e364..676240a8 100644 --- a/web/src/permission.js +++ b/web/src/permission.js @@ -23,6 +23,7 @@ router.beforeEach(async(to, from, next) => { if (!asyncRouterFlag && store.getters['router/asyncRouters'].length === 0) { asyncRouterFlag++ await store.dispatch('router/SetAsyncRouter') + await store.dispatch('user/GetUserInfo') const asyncRouters = store.getters['router/asyncRouters'] router.addRoutes(asyncRouters) next({ ...to, replace: true }) diff --git a/web/src/store/module/user.js b/web/src/store/module/user.js index 82ee944b..0e7908f9 100644 --- a/web/src/store/module/user.js +++ b/web/src/store/module/user.js @@ -1,4 +1,4 @@ -import { login } from '@/api/user' +import { login, getUserInfo } from '@/api/user' import { jsonInBlacklist } from '@/api/jwt' import router from '@/router/index' import { setUserInfo } from '@/api/user' @@ -56,6 +56,13 @@ export const user = { } }, actions: { + async GetUserInfo({ commit }) { + const res = await getUserInfo() + if (res.code === 0) { + commit('setUserInfo', res.data.userInfo) + } + return res + }, async LoginIn({ commit, dispatch, rootGetters, getters }, loginInfo) { const res = await login(loginInfo) if (res.code === 0) { diff --git a/web/src/style/base.scss b/web/src/style/base.scss index ac30d538..91c52758 100644 --- a/web/src/style/base.scss +++ b/web/src/style/base.scss @@ -64,6 +64,10 @@ border: 1px solid #409EFF; } +.el-pager li.active+li{ + border-left: 1px; +} + .el-pager li:hover{ color: #409EFF !important; border: 1px solid #409EFF; diff --git a/web/src/view/layout/index.vue b/web/src/view/layout/index.vue index ae2a965d..7bb7d08b 100644 --- a/web/src/view/layout/index.vue +++ b/web/src/view/layout/index.vue @@ -45,11 +45,17 @@ - - 更多信息 - + + 当前角色:{{ userInfo.authority.authorityName }} + 个人信息 登 出 @@ -90,6 +96,7 @@ import BottomInfo from '@/view/layout/bottomInfo/bottomInfo' import { mapGetters, mapActions } from 'vuex' import CustomPic from '@/components/customPic' import Setting from './setting' +import { setUserAuthority } from '@/api/user' export default { name: 'Layout', components: { @@ -186,7 +193,15 @@ export default { } }, methods: { - ...mapActions('user', ['LoginOut']), + ...mapActions('user', ['LoginOut', 'GetUserInfo']), + async changeUserAuth(id) { + const res = await setUserAuthority({ + authorityId: id + }) + if (res.code === 0) { + window.location.reload() + } + }, reload() { this.reloadFlag = false this.$nextTick(() => { diff --git a/web/src/view/superAdmin/authority/authority.vue b/web/src/view/superAdmin/authority/authority.vue index a04cedc4..8497af11 100644 --- a/web/src/view/superAdmin/authority/authority.vue +++ b/web/src/view/superAdmin/authority/authority.vue @@ -43,6 +43,7 @@ + 注:右上角头像下拉可切换角色 diff --git a/web/src/view/superAdmin/user/user.vue b/web/src/view/superAdmin/user/user.vue index 169f2342..7ecdc717 100644 --- a/web/src/view/superAdmin/user/user.vue +++ b/web/src/view/superAdmin/user/user.vue @@ -17,12 +17,14 @@ @@ -39,6 +41,7 @@ + 注:右上角头像下拉可切换角色 @@ -91,7 +95,7 @@ const path = process.env.VUE_APP_BASE_API import { getUserList, - setUserAuthority, + setUserAuthorities, register, deleteUser } from '@/api/user' @@ -115,7 +119,8 @@ export default { password: '', nickName: '', headerImg: '', - authorityId: '' + authorityId: '', + authorityIds: [] }, rules: { username: [ @@ -139,11 +144,20 @@ export default { ...mapGetters('user', ['token']) }, async created() { - this.getTableData() + await this.getTableData() + this.setAuthorityIds() const res = await getAuthorityList({ page: 1, pageSize: 999 }) this.setOptions(res.data.list) }, methods: { + setAuthorityIds() { + this.tableData && this.tableData.forEach((user) => { + const authorityIds = user.authorities && user.authorities.map(i => { + return i.authorityId + }) + this.$set(user, 'authorityIds', authorityIds) + }) + }, openHeaderChange() { this.$refs.chooseImg.open() }, @@ -174,11 +188,14 @@ export default { async deleteUser(row) { const res = await deleteUser({ id: row.ID }) if (res.code === 0) { - this.getTableData() + this.$message.success('删除成功') + await this.getTableData() + this.setAuthorityIds() row.visible = false } }, async enterAddUserDialog() { + this.userInfo.authorityId = this.userInfo.authorityIds[0] this.$refs.userForm.validate(async valid => { if (valid) { const res = await register(this.userInfo) @@ -186,6 +203,7 @@ export default { this.$message({ type: 'success', message: '创建成功' }) } await this.getTableData() + this.setAuthorityIds() this.closeAddUserDialog() } }) @@ -194,20 +212,22 @@ export default { this.$refs.userForm.resetFields() this.addUserDialog = false }, - handleAvatarSuccess(res) { - this.userInfo.headerImg = res.data.file.url - }, addUser() { this.addUserDialog = true }, - async changeAuthority(row) { - const res = await setUserAuthority({ - uuid: row.uuid, - authorityId: row.authority.authorityId - }) - if (res.code === 0) { - this.$message({ type: 'success', message: '角色设置成功' }) + async changeAuthority(row, flag) { + if (flag) { + return } + this.$nextTick(async() => { + const res = await setUserAuthorities({ + ID: row.ID, + authorityIds: row.authorityIds + }) + if (res.code === 0) { + this.$message({ type: 'success', message: '角色设置成功' }) + } + }) } } } diff --git a/web/src/view/systemTools/autoCode/index.vue b/web/src/view/systemTools/autoCode/index.vue index 3bc55e50..f02059b8 100644 --- a/web/src/view/systemTools/autoCode/index.vue +++ b/web/src/view/systemTools/autoCode/index.vue @@ -165,7 +165,7 @@ const fieldTemplate = { import FieldDialog from '@/view/systemTools/autoCode/component/fieldDialog.vue' import PreviewCodeDialg from '@/view/systemTools/autoCode/component/previewCodeDialg.vue' import { toUpperCase, toHump, toSQLLine } from '@/utils/stringFun' -import { createTemp, getDB, getTable, getColumn, preview } from '@/api/autoCode' +import { createTemp, getDB, getTable, getColumn, preview, getMeta } from '@/api/autoCode' import { getDict } from '@/utils/dictionary' export default { @@ -223,6 +223,10 @@ export default { created() { this.getDb() this.setFdMap() + const id = this.$route.params.id + if (id) { + this.getAutoCodeJson(id) + } }, methods: { editAndAddField(item) { @@ -305,7 +309,6 @@ export default { return false } this.form.humpPackageName = toSQLLine(this.form.packageName) - debugger if (isPreview) { const data = await preview(this.form) this.preViewCode = data.data.autoCode @@ -396,6 +399,12 @@ export default { this.fdMap[item.label] = fdtype }) }) + }, + async getAutoCodeJson(id) { + const res = await getMeta({ id: Number(id) }) + if (res.code === 0) { + this.form = JSON.parse(res.data.meta) + } } } } diff --git a/web/src/view/systemTools/autoCodeAdmin/index.vue b/web/src/view/systemTools/autoCodeAdmin/index.vue new file mode 100644 index 00000000..4f0345ae --- /dev/null +++ b/web/src/view/systemTools/autoCodeAdmin/index.vue @@ -0,0 +1,159 @@ + + + + +