Merge branch 'gva_gormv2_dev' of https://github.com/flipped-aurora/gin-vue-admin into gva_workflow

 Conflicts:
	server/api/v1/sys_work_flow.go
	server/service/sys_workflow.go
This commit is contained in:
pixel
2020-11-10 11:43:56 +08:00
89 changed files with 4351 additions and 4136 deletions
+27 -18
View File
@@ -1,12 +1,12 @@
package v1
import (
"fmt"
"gin-vue-admin/global/response"
resp "gin-vue-admin/model/response"
"gin-vue-admin/global"
"gin-vue-admin/model/response"
"gin-vue-admin/service"
"gin-vue-admin/utils"
"github.com/gin-gonic/gin"
"go.uber.org/zap"
"io/ioutil"
"strconv"
)
@@ -17,7 +17,7 @@ import (
// @accept multipart/form-data
// @Produce application/json
// @Param file formData file true "an example for breakpoint resume, 断点续传示例"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"上传成功"}"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"切片创建成功"}"
// @Router /fileUploadAndDownload/breakpointContinue [post]
func BreakpointContinue(c *gin.Context) {
fileMd5 := c.Request.FormValue("fileMd5")
@@ -27,33 +27,39 @@ func BreakpointContinue(c *gin.Context) {
chunkTotal, _ := strconv.Atoi(c.Request.FormValue("chunkTotal"))
_, FileHeader, err := c.Request.FormFile("file")
if err != nil {
response.FailWithMessage(err.Error(), c)
global.GVA_LOG.Error("接收文件失败!", zap.Any("err", err))
response.FailWithMessage("接收文件失败", c)
return
}
f, err := FileHeader.Open()
if err != nil {
response.FailWithMessage(err.Error(), c)
global.GVA_LOG.Error("文件读取失败!", zap.Any("err", err))
response.FailWithMessage("文件读取失败", c)
return
}
defer f.Close()
cen, _ := ioutil.ReadAll(f)
if flag := utils.CheckMd5(cen, chunkMd5); !flag {
response.FailWithMessage(err.Error(), c)
if !utils.CheckMd5(cen, chunkMd5) {
global.GVA_LOG.Error("检查md5失败!", zap.Any("err", err))
response.FailWithMessage("检查md5失败", c)
return
}
err, file := service.FindOrCreateFile(fileMd5, fileName, chunkTotal)
if err != nil {
response.FailWithMessage(err.Error(), c)
global.GVA_LOG.Error("查找或创建记录失败!", zap.Any("err", err))
response.FailWithMessage("查找或创建记录失败", c)
return
}
err, pathc := utils.BreakPointContinue(cen, fileName, chunkNumber, chunkTotal, fileMd5)
if err != nil {
response.FailWithMessage(err.Error(), c)
global.GVA_LOG.Error("断点续传失败!", zap.Any("err", err))
response.FailWithMessage("断点续传失败", c)
return
}
if err = service.CreateFileChunk(file.ID, pathc, chunkNumber); err != nil {
response.FailWithMessage(err.Error(), c)
global.GVA_LOG.Error("创建文件记录失败!", zap.Any("err", err))
response.FailWithMessage("创建文件记录失败", c)
return
}
response.OkWithMessage("切片创建成功", c)
@@ -73,14 +79,15 @@ func FindFile(c *gin.Context) {
chunkTotal, _ := strconv.Atoi(c.Query("chunkTotal"))
err, file := service.FindOrCreateFile(fileMd5, fileName, chunkTotal)
if err != nil {
global.GVA_LOG.Error("查找失败!", zap.Any("err", err))
response.FailWithMessage("查找失败", c)
} else {
response.OkWithData(resp.FileResponse{File: file}, c)
response.OkWithDetailed(response.FileResponse{File: file},"查找成功", c)
}
}
// @Tags ExaFileUploadAndDownload
// @Summary 查找文件
// @Summary 创建文件
// @Security ApiKeyAuth
// @accept multipart/form-data
// @Produce application/json
@@ -92,9 +99,10 @@ func BreakpointContinueFinish(c *gin.Context) {
fileName := c.Query("fileName")
err, filePath := utils.MakeFile(fileName, fileMd5)
if err != nil {
response.FailWithDetailed(response.ERROR, resp.FilePathResponse{FilePath: filePath}, fmt.Sprintf("文件创建失败:%v", err), c)
global.GVA_LOG.Error("文件创建失败!", zap.Any("err", err))
response.FailWithDetailed(response.FilePathResponse{FilePath: filePath}, "文件创建失败", c)
} else {
response.OkDetailed(resp.FilePathResponse{FilePath: filePath}, "文件创建成功", c)
response.OkWithDetailed(response.FilePathResponse{FilePath: filePath}, "文件创建成功", c)
}
}
@@ -104,7 +112,7 @@ func BreakpointContinueFinish(c *gin.Context) {
// @accept multipart/form-data
// @Produce application/json
// @Param file formData file true "删除缓存切片"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"查找成功"}"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"缓存切片删除成功"}"
// @Router /fileUploadAndDownload/removeChunk [post]
func RemoveChunk(c *gin.Context) {
fileMd5 := c.Query("fileMd5")
@@ -113,8 +121,9 @@ func RemoveChunk(c *gin.Context) {
err := utils.RemoveChunk(fileMd5)
err = service.DeleteFileChunk(fileMd5, fileName, filePath)
if err != nil {
response.FailWithDetailed(response.ERROR, resp.FilePathResponse{FilePath: filePath}, fmt.Sprintf("缓存切片删除失败:%v", err), c)
global.GVA_LOG.Error("缓存切片删除失败!", zap.Any("err", err))
response.FailWithDetailed(response.FilePathResponse{FilePath: filePath},"缓存切片删除失败", c)
} else {
response.OkDetailed(resp.FilePathResponse{FilePath: filePath}, "缓存切片删除成功", c)
response.OkWithDetailed(response.FilePathResponse{FilePath: filePath}, "缓存切片删除成功", c)
}
}
+56 -80
View File
@@ -2,164 +2,140 @@ package v1
import (
"fmt"
"gin-vue-admin/global/response"
"gin-vue-admin/global"
"gin-vue-admin/model"
"gin-vue-admin/model/request"
resp "gin-vue-admin/model/response"
"gin-vue-admin/model/response"
"gin-vue-admin/service"
"gin-vue-admin/utils"
"github.com/gin-gonic/gin"
"go.uber.org/zap"
)
// @Tags SysApi
// @Tags ExaCustomer
// @Summary 创建客户
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.ExaCustomer true "创建客户"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Param data body model.ExaCustomer true "客户用户名, 客户手机号码"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"创建成功"}"
// @Router /customer/customer [post]
func CreateExaCustomer(c *gin.Context) {
var cu model.ExaCustomer
_ = c.ShouldBindJSON(&cu)
CustomerVerify := utils.Rules{
"CustomerName": {utils.NotEmpty()},
"CustomerPhoneData": {utils.NotEmpty()},
}
CustomerVerifyErr := utils.Verify(cu, CustomerVerify)
if CustomerVerifyErr != nil {
response.FailWithMessage(CustomerVerifyErr.Error(), c)
var customer model.ExaCustomer
_ = c.ShouldBindJSON(&customer)
if err := utils.Verify(customer, utils.CustomerVerify); err != nil {
response.FailWithMessage(err.Error(), c)
return
}
claims, _ := c.Get("claims")
waitUse := claims.(*request.CustomClaims)
cu.SysUserID = waitUse.ID
cu.SysUserAuthorityID = waitUse.AuthorityId
err := service.CreateExaCustomer(cu)
if err != nil {
response.FailWithMessage(fmt.Sprintf("删除失败:%v", err), c)
customer.SysUserID = getUserID(c)
customer.SysUserAuthorityID = getUserAuthorityId(c)
if err := service.CreateExaCustomer(customer); err != nil {
global.GVA_LOG.Error("创建失败!", zap.Any("err", err))
response.FailWithMessage("创建失败", c)
} else {
response.OkWithMessage("创建成功", c)
}
}
// @Tags SysApi
// @Tags ExaCustomer
// @Summary 删除客户
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.ExaCustomer true "删除客户"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Param data body model.ExaCustomer true "客户ID"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
// @Router /customer/customer [delete]
func DeleteExaCustomer(c *gin.Context) {
var cu model.ExaCustomer
_ = c.ShouldBindJSON(&cu)
CustomerVerify := utils.Rules{
"ID": {utils.NotEmpty()},
}
CustomerVerifyErr := utils.Verify(cu.GVA_MODEL, CustomerVerify)
if CustomerVerifyErr != nil {
response.FailWithMessage(CustomerVerifyErr.Error(), c)
var customer model.ExaCustomer
_ = c.ShouldBindJSON(&customer)
if err := utils.Verify(customer.GVA_MODEL, utils.IdVerify); err != nil {
response.FailWithMessage(err.Error(), c)
return
}
err := service.DeleteExaCustomer(cu)
if err != nil {
response.FailWithMessage(fmt.Sprintf("删除失败:%v", err), c)
if err := service.DeleteExaCustomer(customer); err != nil {
global.GVA_LOG.Error("删除失败!", zap.Any("err", err))
response.FailWithMessage("删除失败", c)
} else {
response.OkWithMessage("删除成功", c)
}
}
// @Tags SysApi
// @Tags ExaCustomer
// @Summary 更新客户信息
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.ExaCustomer true "创建客户"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Param data body model.ExaCustomer true "客户ID, 客户信息"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}"
// @Router /customer/customer [put]
func UpdateExaCustomer(c *gin.Context) {
var cu model.ExaCustomer
_ = c.ShouldBindJSON(&cu)
IdCustomerVerify := utils.Rules{
"ID": {utils.NotEmpty()},
}
IdCustomerVerifyErr := utils.Verify(cu.GVA_MODEL, IdCustomerVerify)
if IdCustomerVerifyErr != nil {
response.FailWithMessage(IdCustomerVerifyErr.Error(), c)
var customer model.ExaCustomer
_ = c.ShouldBindJSON(&customer)
if err := utils.Verify(customer.GVA_MODEL, utils.IdVerify); err != nil {
response.FailWithMessage(err.Error(), c)
return
}
CustomerVerify := utils.Rules{
"CustomerName": {utils.NotEmpty()},
"CustomerPhoneData": {utils.NotEmpty()},
}
CustomerVerifyErr := utils.Verify(cu, CustomerVerify)
if CustomerVerifyErr != nil {
response.FailWithMessage(CustomerVerifyErr.Error(), c)
if err := utils.Verify(customer, utils.CustomerVerify); err != nil {
response.FailWithMessage(err.Error(), c)
return
}
err := service.UpdateExaCustomer(&cu)
if err != nil {
response.FailWithMessage(fmt.Sprintf("更新失败:%v", err), c)
if err := service.UpdateExaCustomer(&customer); err != nil {
global.GVA_LOG.Error("更新失败!", zap.Any("err", err))
response.FailWithMessage("更新失败!", c)
} else {
response.OkWithMessage("更新成功", c)
}
}
// @Tags SysApi
// @Tags ExaCustomer
// @Summary 获取单一客户信息
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.ExaCustomer true "获取单一客户信息"
// @Param data body model.ExaCustomer true "客户ID"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /customer/customer [get]
func GetExaCustomer(c *gin.Context) {
var cu model.ExaCustomer
_ = c.ShouldBindQuery(&cu)
IdCustomerVerify := utils.Rules{
"ID": {utils.NotEmpty()},
}
IdCustomerVerifyErr := utils.Verify(cu.GVA_MODEL, IdCustomerVerify)
if IdCustomerVerifyErr != nil {
response.FailWithMessage(IdCustomerVerifyErr.Error(), c)
var customer model.ExaCustomer
_ = c.ShouldBindQuery(&customer)
if err := utils.Verify(customer.GVA_MODEL, utils.IdVerify); err != nil {
response.FailWithMessage(err.Error(), c)
return
}
err, customer := service.GetExaCustomer(cu.ID)
err, data := service.GetExaCustomer(customer.ID)
if err != nil {
response.FailWithMessage(fmt.Sprintf("获取失败:%v", err), c)
global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
response.FailWithMessage("获取失败", c)
} else {
response.OkWithData(resp.ExaCustomerResponse{Customer: customer}, c)
response.OkWithDetailed(response.ExaCustomerResponse{Customer: data}, "获取成功", c)
}
}
// @Tags SysApi
// @Summary 获取权限客户列表
// @Tags ExaCustomer
// @Summary 分页获取权限客户列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.PageInfo true "获取权限客户列表"
// @Param data body request.PageInfo true "页码, 每页大小"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /customer/customerList [get]
func GetExaCustomerList(c *gin.Context) {
claims, _ := c.Get("claims")
waitUse := claims.(*request.CustomClaims)
var pageInfo request.PageInfo
_ = c.ShouldBindQuery(&pageInfo)
PageVerifyErr := utils.Verify(pageInfo, utils.CustomizeMap["PageVerify"])
if PageVerifyErr != nil {
response.FailWithMessage(PageVerifyErr.Error(), c)
if err := utils.Verify(pageInfo, utils.PageInfoVerify); err != nil {
response.FailWithMessage(err.Error(), c)
return
}
err, customerList, total := service.GetCustomerInfoList(waitUse.AuthorityId, pageInfo)
err, customerList, total := service.GetCustomerInfoList(getUserAuthorityId(c), pageInfo)
if err != nil {
global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
response.FailWithMessage(fmt.Sprintf("获取失败:%v", err), c)
} else {
response.OkWithData(resp.PageResult{
response.OkWithDetailed(response.PageResult{
List: customerList,
Total: total,
Page: pageInfo.Page,
PageSize: pageInfo.PageSize,
}, c)
}, "获取成功", c)
}
}
+16 -12
View File
@@ -1,13 +1,13 @@
package v1
import (
"fmt"
"gin-vue-admin/global/response"
"gin-vue-admin/global"
"gin-vue-admin/model"
"gin-vue-admin/model/request"
resp "gin-vue-admin/model/response"
"gin-vue-admin/model/response"
"gin-vue-admin/service"
"github.com/gin-gonic/gin"
"go.uber.org/zap"
)
// @Tags ExaFileUploadAndDownload
@@ -23,15 +23,17 @@ func UploadFile(c *gin.Context) {
noSave := c.DefaultQuery("noSave", "0")
_, header, err := c.Request.FormFile("file")
if err != nil {
response.FailWithMessage(fmt.Sprintf("上传文件失败,%v", err), c)
global.GVA_LOG.Error("接收文件失败!", zap.Any("err", err))
response.FailWithMessage("接收文件失败", c)
return
}
err, file = service.UploadFile(header, noSave) // 文件上传后拿到文件路径
if err != nil {
response.FailWithMessage(fmt.Sprintf("修改数据库链接失败,%v", err), c)
global.GVA_LOG.Error("修改数据库链接失败!", zap.Any("err", err))
response.FailWithMessage("修改数据库链接失败", c)
return
}
response.OkDetailed(resp.ExaFileResponse{File: file}, "上传成功", c)
response.OkWithDetailed(response.ExaFileResponse{File: file}, "上传成功", c)
}
// @Tags ExaFileUploadAndDownload
@@ -39,13 +41,14 @@ func UploadFile(c *gin.Context) {
// @Security ApiKeyAuth
// @Produce application/json
// @Param data body model.ExaFileUploadAndDownload true "传入文件里面id即可"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"返回成功"}"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
// @Router /fileUploadAndDownload/deleteFile [post]
func DeleteFile(c *gin.Context) {
var file model.ExaFileUploadAndDownload
_ = c.ShouldBindJSON(&file)
if err := service.DeleteFile(file); err != nil {
response.FailWithMessage(fmt.Sprintf("删除失败,%v", err), c)
global.GVA_LOG.Error("删除失败!", zap.Any("err", err))
response.FailWithMessage("删除失败", c)
return
}
response.OkWithMessage("删除成功", c)
@@ -56,7 +59,7 @@ func DeleteFile(c *gin.Context) {
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.PageInfo true "分页获取文件户列表"
// @Param data body request.PageInfo true "页码, 每页大小"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /fileUploadAndDownload/getFileList [post]
func GetFileList(c *gin.Context) {
@@ -64,13 +67,14 @@ func GetFileList(c *gin.Context) {
_ = c.ShouldBindJSON(&pageInfo)
err, list, total := service.GetFileRecordInfoList(pageInfo)
if err != nil {
response.FailWithMessage(fmt.Sprintf("获取数据失败,%v", err), c)
global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
response.FailWithMessage("获取失败", c)
} else {
response.OkWithData(resp.PageResult{
response.OkWithDetailed(response.PageResult{
List: list,
Total: total,
Page: pageInfo.Page,
PageSize: pageInfo.PageSize,
}, c)
},"获取成功", c)
}
}
+21 -15
View File
@@ -1,12 +1,13 @@
package v1
import (
"fmt"
"gin-vue-admin/global/response"
"gin-vue-admin/global"
"gin-vue-admin/model"
"gin-vue-admin/model/response"
"gin-vue-admin/service"
"gin-vue-admin/utils"
"github.com/gin-gonic/gin"
"go.uber.org/zap"
)
// @Tags SimpleUploader
@@ -15,7 +16,7 @@ import (
// @accept multipart/form-data
// @Produce application/json
// @Param file formData file true "断点续传插件版示例"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"上传成功"}"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"切片创建成功"}"
// @Router /simpleUploader/upload [post]
func SimpleUploaderUpload(c *gin.Context) {
var chunk model.ExaSimpleUploader
@@ -29,42 +30,46 @@ func SimpleUploaderUpload(c *gin.Context) {
var chunkDir = "./chunk/" + chunk.Identifier + "/"
hasDir, _ := utils.PathExists(chunkDir)
if !hasDir {
utils.CreateDir(chunkDir)
if err := utils.CreateDir(chunkDir); err != nil {
global.GVA_LOG.Error("创建目录失败!", zap.Any("err", err))
}
}
chunkPath := chunkDir + chunk.Filename + chunk.ChunkNumber
err = c.SaveUploadedFile(header, chunkPath)
if err != nil {
response.FailWithMessage(fmt.Sprintf("切片创建失败,%v", err), c)
global.GVA_LOG.Error("切片创建失败!", zap.Any("err", err))
response.FailWithMessage("切片创建失败", c)
return
}
chunk.CurrentChunkPath = chunkPath
err = service.SaveChunk(chunk)
if err != nil {
response.FailWithMessage(fmt.Sprintf("切片创建失败,%v", err), c)
global.GVA_LOG.Error("切片创建失败!", zap.Any("err", err))
response.FailWithMessage("切片创建失败", c)
return
} else {
response.Ok(c)
response.OkWithMessage("切片创建成功", c)
}
}
// @Tags SimpleUploader
// @Summary 断点续传插件版示例
// @Security ApiKeyAuth
// @Produce application/json
// @Param md5 query string true "测试文件是否已经存在和判断已经上传过的切片"
// @Param md5 query string true "md5"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}"
// @Router /simpleUploader/checkFileMd5 [get]
func CheckFileMd5(c *gin.Context) {
md5 := c.Query("md5")
err, chunks, isDone := service.CheckFileMd5(md5)
if err != nil {
response.FailWithMessage(fmt.Sprintf("md5读取失败,%v", err), c)
global.GVA_LOG.Error("md5读取失败!", zap.Any("err", err))
response.FailWithMessage("md5读取失败", c)
} else {
response.OkWithData(gin.H{
response.OkWithDetailed(gin.H{
"chunks": chunks,
"isDone": isDone,
}, c)
},"查询成功", c)
}
}
@@ -72,7 +77,7 @@ func CheckFileMd5(c *gin.Context) {
// @Summary 合并文件
// @Security ApiKeyAuth
// @Produce application/json
// @Param md5 query string true "合并文件"
// @Param md5 query string true "md5"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"合并成功"}"
// @Router /simpleUploader/mergeFileMd5 [get]
func MergeFileMd5(c *gin.Context) {
@@ -80,8 +85,9 @@ func MergeFileMd5(c *gin.Context) {
fileName := c.Query("fileName")
err := service.MergeFileMd5(md5, fileName)
if err != nil {
response.FailWithMessage(fmt.Sprintf("md5读取失败,%v", err), c)
global.GVA_LOG.Error("md5读取失败!", zap.Any("err", err))
response.FailWithMessage("md5读取失败", c)
} else {
response.OkWithData(gin.H{}, c)
response.OkWithMessage("合并成功", c)
}
}
+48 -70
View File
@@ -1,14 +1,14 @@
package v1
import (
"fmt"
"gin-vue-admin/global/response"
"gin-vue-admin/global"
"gin-vue-admin/model"
"gin-vue-admin/model/request"
resp "gin-vue-admin/model/response"
"gin-vue-admin/model/response"
"gin-vue-admin/service"
"gin-vue-admin/utils"
"github.com/gin-gonic/gin"
"go.uber.org/zap"
)
// @Tags SysApi
@@ -16,60 +16,47 @@ import (
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.SysApi true "创建api"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Param data body model.SysApi true "api路径, api中文描述, api组, 方法"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"创建成功"}"
// @Router /api/createApi [post]
func CreateApi(c *gin.Context) {
var api model.SysApi
_ = c.ShouldBindJSON(&api)
ApiVerify := utils.Rules{
"Path": {utils.NotEmpty()},
"Description": {utils.NotEmpty()},
"ApiGroup": {utils.NotEmpty()},
"Method": {utils.NotEmpty()},
}
ApiVerifyErr := utils.Verify(api, ApiVerify)
if ApiVerifyErr != nil {
response.FailWithMessage(ApiVerifyErr.Error(), c)
if err := utils.Verify(api, utils.ApiVerify); err != nil {
response.FailWithMessage(err.Error(), c)
return
}
err := service.CreateApi(api)
if err != nil {
response.FailWithMessage(fmt.Sprintf("创建失败,%v", err), c)
if err := service.CreateApi(api); err != nil {
global.GVA_LOG.Error("创建失败!", zap.Any("err", err))
response.FailWithMessage("创建失败", c)
} else {
response.OkWithMessage("创建成功", c)
}
}
// @Tags SysApi
// @Summary 删除指定api
// @Summary 删除api
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.SysApi true "删除api"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Param data body model.SysApi true "ID"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
// @Router /api/deleteApi [post]
func DeleteApi(c *gin.Context) {
var a model.SysApi
_ = c.ShouldBindJSON(&a)
ApiVerify := utils.Rules{
"ID": {utils.NotEmpty()},
}
ApiVerifyErr := utils.Verify(a.GVA_MODEL, ApiVerify)
if ApiVerifyErr != nil {
response.FailWithMessage(ApiVerifyErr.Error(), c)
var api model.SysApi
_ = c.ShouldBindJSON(&api)
if err := utils.Verify(api.GVA_MODEL, utils.IdVerify); err != nil {
response.FailWithMessage(err.Error(), c)
return
}
err := service.DeleteApi(a)
if err != nil {
response.FailWithMessage(fmt.Sprintf("删除失败,%v", err), c)
if err := service.DeleteApi(api); err != nil {
global.GVA_LOG.Error("删除失败!", zap.Any("err", err))
response.FailWithMessage("删除失败", c)
} else {
response.OkWithMessage("删除成功", c)
}
}
// 条件搜索后端看此api
// @Tags SysApi
// @Summary 分页获取API列表
// @Security ApiKeyAuth
@@ -79,24 +66,22 @@ func DeleteApi(c *gin.Context) {
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /api/getApiList [post]
func GetApiList(c *gin.Context) {
// 此结构体仅本方法使用
var sp request.SearchApiParams
_ = c.ShouldBindJSON(&sp)
PageVerifyErr := utils.Verify(sp.PageInfo, utils.CustomizeMap["PageVerify"])
if PageVerifyErr != nil {
response.FailWithMessage(PageVerifyErr.Error(), c)
var pageInfo request.SearchApiParams
_ = c.ShouldBindJSON(&pageInfo)
if err := utils.Verify(pageInfo.PageInfo, utils.PageInfoVerify); err != nil {
response.FailWithMessage(err.Error(), c)
return
}
err, list, total := service.GetAPIInfoList(sp.SysApi, sp.PageInfo, sp.OrderKey, sp.Desc)
if err != nil {
response.FailWithMessage(fmt.Sprintf("获取数据失败,%v", err), c)
if err, list, total := service.GetAPIInfoList(pageInfo.SysApi, pageInfo.PageInfo, pageInfo.OrderKey, pageInfo.Desc); err != nil {
global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
response.FailWithMessage("获取失败", c)
} else {
response.OkWithData(resp.PageResult{
response.OkWithDetailed(response.PageResult{
List: list,
Total: total,
Page: sp.PageInfo.Page,
PageSize: sp.PageInfo.PageSize,
}, c)
Page: pageInfo.Page,
PageSize: pageInfo.PageSize,
}, "获取成功", c)
}
}
@@ -111,16 +96,16 @@ func GetApiList(c *gin.Context) {
func GetApiById(c *gin.Context) {
var idInfo request.GetById
_ = c.ShouldBindJSON(&idInfo)
IdVerifyErr := utils.Verify(idInfo, utils.CustomizeMap["IdVerify"])
if IdVerifyErr != nil {
response.FailWithMessage(IdVerifyErr.Error(), c)
if err := utils.Verify(idInfo, utils.IdVerify); err != nil {
response.FailWithMessage(err.Error(), c)
return
}
err, api := service.GetApiById(idInfo.Id)
if err != nil {
response.FailWithMessage(fmt.Sprintf("获取数据失败,%v", err), c)
global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
response.FailWithMessage("获取失败", c)
} else {
response.OkWithData(resp.SysAPIResponse{Api: api}, c)
response.OkWithData(response.SysAPIResponse{Api: api}, c)
}
}
@@ -129,28 +114,21 @@ func GetApiById(c *gin.Context) {
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.SysApi true "创建api"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Param data body model.SysApi true "api路径, api中文描述, api组, 方法"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"修改成功"}"
// @Router /api/updateApi [post]
func UpdateApi(c *gin.Context) {
var api model.SysApi
_ = c.ShouldBindJSON(&api)
ApiVerify := utils.Rules{
"Path": {utils.NotEmpty()},
"Description": {utils.NotEmpty()},
"ApiGroup": {utils.NotEmpty()},
"Method": {utils.NotEmpty()},
}
ApiVerifyErr := utils.Verify(api, ApiVerify)
if ApiVerifyErr != nil {
response.FailWithMessage(ApiVerifyErr.Error(), c)
if err := utils.Verify(api, utils.ApiVerify); err != nil {
response.FailWithMessage(err.Error(), c)
return
}
err := service.UpdateApi(api)
if err != nil {
response.FailWithMessage(fmt.Sprintf("修改数据失败,%v", err), c)
if err := service.UpdateApi(api); err != nil {
global.GVA_LOG.Error("修改失败!", zap.Any("err", err))
response.FailWithMessage("修改失败", c)
} else {
response.OkWithMessage("修改数据成功", c)
response.OkWithMessage("修改成功", c)
}
}
@@ -162,10 +140,10 @@ func UpdateApi(c *gin.Context) {
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /api/getAllApis [post]
func GetAllApis(c *gin.Context) {
err, apis := service.GetAllApis()
if err != nil {
response.FailWithMessage(fmt.Sprintf("获取数据失败,%v", err), c)
if err, apis := service.GetAllApis(); err != nil {
global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
response.FailWithMessage("获取失败", c)
} else {
response.OkWithData(resp.SysAPIListResponse{Apis: apis}, c)
response.OkWithDetailed(response.SysAPIListResponse{Apis: apis}, "获取成功", c)
}
}
+60 -86
View File
@@ -1,166 +1,141 @@
package v1
import (
"fmt"
"gin-vue-admin/global/response"
"gin-vue-admin/global"
"gin-vue-admin/model"
"gin-vue-admin/model/request"
resp "gin-vue-admin/model/response"
"gin-vue-admin/model/response"
"gin-vue-admin/service"
"gin-vue-admin/utils"
"github.com/gin-gonic/gin"
"go.uber.org/zap"
)
// @Tags authority
// @Tags Authority
// @Summary 创建角色
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.SysAuthority true "创建角色"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Param data body model.SysAuthority true "权限id, 权限名, 父角色id"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"创建成功"}"
// @Router /authority/createAuthority [post]
func CreateAuthority(c *gin.Context) {
var auth model.SysAuthority
_ = c.ShouldBindJSON(&auth)
AuthorityVerify := utils.Rules{
"AuthorityId": {utils.NotEmpty()},
"AuthorityName": {utils.NotEmpty()},
"ParentId": {utils.NotEmpty()},
}
AuthorityVerifyErr := utils.Verify(auth, AuthorityVerify)
if AuthorityVerifyErr != nil {
response.FailWithMessage(AuthorityVerifyErr.Error(), c)
var authority model.SysAuthority
_ = c.ShouldBindJSON(&authority)
if err := utils.Verify(authority, utils.AuthorityVerify); err != nil {
response.FailWithMessage(err.Error(), c)
return
}
err, authBack := service.CreateAuthority(auth)
if err != nil {
response.FailWithMessage(fmt.Sprintf("创建失败,%v", err), c)
if err, authBack := service.CreateAuthority(authority); err != nil {
global.GVA_LOG.Error("创建失败!", zap.Any("err", err))
response.FailWithMessage("创建失败", c)
} else {
response.OkWithData(resp.SysAuthorityResponse{Authority: authBack}, c)
response.OkWithDetailed(response.SysAuthorityResponse{Authority: authBack}, "创建成功", c)
}
}
// @Tags authority
// @Tags Authority
// @Summary 拷贝角色
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body response.SysAuthorityCopyResponse true "拷贝角色"
// @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 resp.SysAuthorityCopyResponse
var copyInfo response.SysAuthorityCopyResponse
_ = c.ShouldBindJSON(&copyInfo)
OldAuthorityVerify := utils.Rules{
"OldAuthorityId": {utils.NotEmpty()},
}
OldAuthorityVerifyErr := utils.Verify(copyInfo, OldAuthorityVerify)
if OldAuthorityVerifyErr != nil {
response.FailWithMessage(OldAuthorityVerifyErr.Error(), c)
if err := utils.Verify(copyInfo, utils.OldAuthorityVerify); err != nil {
response.FailWithMessage(err.Error(), c)
return
}
AuthorityVerify := utils.Rules{
"AuthorityId": {utils.NotEmpty()},
"AuthorityName": {utils.NotEmpty()},
"ParentId": {utils.NotEmpty()},
}
AuthorityVerifyErr := utils.Verify(copyInfo.Authority, AuthorityVerify)
if AuthorityVerifyErr != nil {
response.FailWithMessage(AuthorityVerifyErr.Error(), c)
if err := utils.Verify(copyInfo.Authority, utils.AuthorityVerify); err != nil {
response.FailWithMessage(err.Error(), c)
return
}
err, authBack := service.CopyAuthority(copyInfo)
if err != nil {
response.FailWithMessage(fmt.Sprintf("拷贝失败,%v", err), c)
if err, authBack := service.CopyAuthority(copyInfo); err != nil {
global.GVA_LOG.Error("拷贝失败!", zap.Any("err", err))
response.FailWithMessage("拷贝失败", c)
} else {
response.OkWithData(resp.SysAuthorityResponse{Authority: authBack}, c)
response.OkWithDetailed(response.SysAuthorityResponse{Authority: authBack}, "拷贝成功", c)
}
}
// @Tags authority
// @Tags Authority
// @Summary 删除角色
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.SysAuthority true "删除角色"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
// @Router /authority/deleteAuthority [post]
func DeleteAuthority(c *gin.Context) {
var a model.SysAuthority
_ = c.ShouldBindJSON(&a)
AuthorityIdVerifyErr := utils.Verify(a, utils.CustomizeMap["AuthorityIdVerify"])
if AuthorityIdVerifyErr != nil {
response.FailWithMessage(AuthorityIdVerifyErr.Error(), c)
var authority model.SysAuthority
_ = c.ShouldBindJSON(&authority)
if err := utils.Verify(authority, utils.AuthorityIdVerify); err != nil {
response.FailWithMessage(err.Error(), c)
return
}
// 删除角色之前需要判断是否有用户正在使用此角色
err := service.DeleteAuthority(&a)
if err != nil {
response.FailWithMessage(fmt.Sprintf("删除失败,%v", err), c)
if err := service.DeleteAuthority(&authority); err != nil { // 删除角色之前需要判断是否有用户正在使用此角色
global.GVA_LOG.Error("删除失败!", zap.Any("err", err))
response.FailWithMessage("删除失败", c)
} else {
response.OkWithMessage("删除成功", c)
}
}
// @Tags authority
// @Summary 设置角色资源权限
// @Tags Authority
// @Summary 更新角色信息
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.SysAuthority true "设置角色资源权限"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"设置成功"}"
// @Param data body model.SysAuthority true "权限id, 权限名, 父角色id"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}"
// @Router /authority/updateAuthority [post]
func UpdateAuthority(c *gin.Context) {
var auth model.SysAuthority
_ = c.ShouldBindJSON(&auth)
AuthorityVerify := utils.Rules{
"AuthorityId": {utils.NotEmpty()},
"AuthorityName": {utils.NotEmpty()},
"ParentId": {utils.NotEmpty()},
}
AuthorityVerifyErr := utils.Verify(auth, AuthorityVerify)
if AuthorityVerifyErr != nil {
response.FailWithMessage(AuthorityVerifyErr.Error(), c)
if err := utils.Verify(auth, utils.AuthorityVerify); err != nil {
response.FailWithMessage(err.Error(), c)
return
}
err, authority := service.UpdateAuthority(auth)
if err != nil {
response.FailWithMessage(fmt.Sprintf("更新失败,%v", err), c)
if err, authority := service.UpdateAuthority(auth); err != nil {
global.GVA_LOG.Error("更新失败!", zap.Any("err", err))
response.FailWithMessage("更新失败", c)
} else {
response.OkWithData(resp.SysAuthorityResponse{Authority: authority}, c)
response.OkWithDetailed(response.SysAuthorityResponse{Authority: authority}, "更新成功", c)
}
}
// @Tags authority
// @Tags Authority
// @Summary 分页获取角色列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.PageInfo true "分页获取用户列表"
// @Param data body request.PageInfo true "页码, 每页大小"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /authority/getAuthorityList [post]
func GetAuthorityList(c *gin.Context) {
var pageInfo request.PageInfo
_ = c.ShouldBindJSON(&pageInfo)
PageVerifyErr := utils.Verify(pageInfo, utils.CustomizeMap["PageVerify"])
if PageVerifyErr != nil {
response.FailWithMessage(PageVerifyErr.Error(), c)
if err := utils.Verify(pageInfo, utils.PageInfoVerify); err != nil {
response.FailWithMessage(err.Error(), c)
return
}
err, list, total := service.GetAuthorityInfoList(pageInfo)
if err != nil {
response.FailWithMessage(fmt.Sprintf("获取数据失败,%v", err), c)
if err, list, total := service.GetAuthorityInfoList(pageInfo); err != nil {
global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
response.FailWithMessage("获取失败", c)
} else {
response.OkWithData(resp.PageResult{
response.OkWithDetailed(response.PageResult{
List: list,
Total: total,
Page: pageInfo.Page,
PageSize: pageInfo.PageSize,
}, c)
}, "获取成功", c)
}
}
// @Tags authority
// @Tags Authority
// @Summary 设置角色资源权限
// @Security ApiKeyAuth
// @accept application/json
@@ -171,15 +146,14 @@ func GetAuthorityList(c *gin.Context) {
func SetDataAuthority(c *gin.Context) {
var auth model.SysAuthority
_ = c.ShouldBindJSON(&auth)
AuthorityIdVerifyErr := utils.Verify(auth, utils.CustomizeMap["AuthorityIdVerify"])
if AuthorityIdVerifyErr != nil {
response.FailWithMessage(AuthorityIdVerifyErr.Error(), c)
if err := utils.Verify(auth, utils.AuthorityIdVerify); err != nil {
response.FailWithMessage(err.Error(), c)
return
}
err := service.SetDataAuthority(auth)
if err != nil {
response.FailWithMessage(fmt.Sprintf("设置关联失败,%v", err), c)
if err := service.SetDataAuthority(auth); err != nil {
global.GVA_LOG.Error("设置失败!", zap.Any("err", err))
response.FailWithMessage("设置失败", c)
} else {
response.Ok(c)
response.OkWithMessage("设置成功", c)
}
}
+40 -43
View File
@@ -3,16 +3,18 @@ package v1
import (
"fmt"
"gin-vue-admin/global"
"gin-vue-admin/global/response"
"gin-vue-admin/model"
"gin-vue-admin/model/response"
"gin-vue-admin/service"
"gin-vue-admin/utils"
"github.com/gin-gonic/gin"
"github.com/pkg/errors"
"go.uber.org/zap"
"net/url"
"os"
)
// @Tags SysApi
// @Tags AutoCode
// @Summary 自动代码模板
// @Security ApiKeyAuth
// @accept application/json
@@ -23,15 +25,8 @@ import (
func CreateTemp(c *gin.Context) {
var a model.AutoCodeStruct
_ = c.ShouldBindJSON(&a)
AutoCodeVerify := utils.Rules{
"Abbreviation": {utils.NotEmpty()},
"StructName": {utils.NotEmpty()},
"PackageName": {utils.NotEmpty()},
"Fields": {utils.NotEmpty()},
}
WKVerifyErr := utils.Verify(a, AutoCodeVerify)
if WKVerifyErr != nil {
response.FailWithMessage(WKVerifyErr.Error(), c)
if err := utils.Verify(a, utils.AutoCodeVerify); err != nil {
response.FailWithMessage(err.Error(), c)
return
}
if a.AutoCreateApiToSql {
@@ -49,7 +44,7 @@ func CreateTemp(c *gin.Context) {
Method: "DELETE",
},
{
Path: "/" + a.Abbreviation + "/" + "delete" + a.StructName+"ByIds",
Path: "/" + a.Abbreviation + "/" + "delete" + a.StructName + "ByIds",
Description: "批量删除" + a.Description,
ApiGroup: a.Abbreviation,
Method: "DELETE",
@@ -74,81 +69,83 @@ func CreateTemp(c *gin.Context) {
},
}
for _, v := range apiList {
errC := service.CreateApi(v)
if errC != nil {
if err := service.AutoCreateApi(v); err != nil {
global.GVA_LOG.Error("自动化创建失败!请自行清空垃圾数据!", zap.Any("err", err))
c.Writer.Header().Add("success", "false")
c.Writer.Header().Add("msg", url.QueryEscape(fmt.Sprintf("自动化创建失败,%v,请自行清空垃圾数据", errC)))
c.Writer.Header().Add("msg", url.QueryEscape("自动化创建失败!请自行清空垃圾数据!"))
return
}
}
}
err := service.CreateTemp(a)
if err != nil {
response.FailWithMessage(fmt.Sprintf("创建失败,%v", err), c)
os.Remove("./ginvueadmin.zip")
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")
_ = os.Remove("./ginvueadmin.zip")
}
}
// @Tags SysApi
// @Tags AutoCode
// @Summary 获取当前数据库所有表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Success 200 {string} string "{"success":true,"data":{},"msg":"创建成功"}"
// @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 {
response.FailWithMessage(fmt.Sprintf("查询table失败,%v", err), c)
global.GVA_LOG.Error("查询table失败!", zap.Any("err", err))
response.FailWithMessage("查询table失败", c)
} else {
response.OkWithData(gin.H{
"tables": tables,
}, c)
response.OkWithDetailed(gin.H{"tables": tables}, "获取成功", c)
}
}
// @Tags SysApi
// @Tags AutoCode
// @Summary 获取当前所有数据库
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Success 200 {string} string "{"success":true,"data":{},"msg":"创建成功"}"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /autoCode/getDatabase [get]
func GetDB(c *gin.Context) {
err, dbs := service.GetDB()
if err != nil {
response.FailWithMessage(fmt.Sprintf("查询table失败,%v", err), c)
if err, dbs := service.GetDB(); err != nil {
global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
response.FailWithMessage("获取失败", c)
} else {
response.OkWithData(gin.H{
"dbs": dbs,
}, c)
response.OkWithDetailed(gin.H{"dbs": dbs}, "获取成功", c)
}
}
// @Tags SysApi
// @Tags AutoCode
// @Summary 获取当前表所有字段
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Success 200 {string} string "{"success":true,"data":{},"msg":"创建成功"}"
// @Router /autoCode/getDatabase [get]
func GetColume(c *gin.Context) {
// @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")
err, columes := service.GetColume(tableName, dbName)
if err != nil {
response.FailWithMessage(fmt.Sprintf("查询table失败,%v", err), c)
if err, columns := service.GetColumn(tableName, dbName); err != nil {
global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
response.FailWithMessage("获取失败", c)
} else {
response.OkWithData(gin.H{
"columes": columes,
}, c)
response.OkWithDetailed(gin.H{"columns": columns}, "获取成功", c)
}
}
+8 -9
View File
@@ -1,33 +1,32 @@
package v1
import (
"fmt"
"gin-vue-admin/global"
"gin-vue-admin/global/response"
resp "gin-vue-admin/model/response"
"gin-vue-admin/model/response"
"github.com/gin-gonic/gin"
"github.com/mojocn/base64Captcha"
"go.uber.org/zap"
)
var store = base64Captcha.DefaultMemStore
// @Tags base
// @Tags Base
// @Summary 生成验证码
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"验证码获取成功"}"
// @Router /base/captcha [post]
func 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)
cp := base64Captcha.NewCaptcha(driver, store)
id, b64s, err := cp.Generate()
if err != nil {
response.FailWithMessage(fmt.Sprintf("获取数据失败,%v", err), c)
if id, b64s, err := cp.Generate(); err != nil {
global.GVA_LOG.Error("验证码获取失败!", zap.Any("err", err))
response.FailWithMessage("验证码获取失败", c)
} else {
response.OkDetailed(resp.SysCaptchaResponse{
response.OkWithDetailed(response.SysCaptchaResponse{
CaptchaId: id,
PicPath: b64s,
}, "验证码获取成功", c)
+21 -23
View File
@@ -1,56 +1,54 @@
package v1
import (
"fmt"
"gin-vue-admin/global/response"
"gin-vue-admin/global"
"gin-vue-admin/model/request"
resp "gin-vue-admin/model/response"
"gin-vue-admin/model/response"
"gin-vue-admin/service"
"gin-vue-admin/utils"
"github.com/gin-gonic/gin"
"go.uber.org/zap"
)
// @Tags casbin
// @Summary 更改角色api权限
// @Tags Casbin
// @Summary 更新角色api权限
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.CasbinInReceive true "更改角色api权限"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Param data body request.CasbinInReceive true "权限id, 权限模型列表"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}"
// @Router /casbin/UpdateCasbin [post]
func UpdateCasbin(c *gin.Context) {
var cmr request.CasbinInReceive
_ = c.ShouldBindJSON(&cmr)
AuthorityIdVerifyErr := utils.Verify(cmr, utils.CustomizeMap["AuthorityIdVerify"])
if AuthorityIdVerifyErr != nil {
response.FailWithMessage(AuthorityIdVerifyErr.Error(), c)
if err := utils.Verify(cmr, utils.AuthorityIdVerify); err != nil {
response.FailWithMessage(err.Error(), c)
return
}
err := service.UpdateCasbin(cmr.AuthorityId, cmr.CasbinInfos)
if err != nil {
response.FailWithMessage(fmt.Sprintf("添加规则失败,%v", err), c)
if err := service.UpdateCasbin(cmr.AuthorityId, cmr.CasbinInfos); err != nil {
global.GVA_LOG.Error("更新失败!", zap.Any("err", err))
response.FailWithMessage("更新失败", c)
} else {
response.OkWithMessage("添加规则成功", c)
response.OkWithMessage("更新成功", c)
}
}
// @Tags casbin
// @Tags Casbin
// @Summary 获取权限列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.CasbinInReceive true "获取权限列表"
// @Param data body request.CasbinInReceive true "权限id, 权限模型列表"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /casbin/getPolicyPathByAuthorityId [post]
func GetPolicyPathByAuthorityId(c *gin.Context) {
var cmr request.CasbinInReceive
_ = c.ShouldBindJSON(&cmr)
AuthorityIdVerifyErr := utils.Verify(cmr, utils.CustomizeMap["AuthorityIdVerify"])
if AuthorityIdVerifyErr != nil {
response.FailWithMessage(AuthorityIdVerifyErr.Error(), c)
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(cmr.AuthorityId)
response.OkWithData(resp.PolicyPathResponse{Paths: paths}, c)
paths := service.GetPolicyPathByAuthorityId(casbin.AuthorityId)
response.OkWithDetailed(response.PolicyPathResponse{Paths: paths}, "获取成功", c)
}
+40 -35
View File
@@ -1,13 +1,14 @@
package v1
import (
"fmt"
"gin-vue-admin/global/response"
"gin-vue-admin/global"
"gin-vue-admin/model"
"gin-vue-admin/model/request"
resp "gin-vue-admin/model/response"
"gin-vue-admin/model/response"
"gin-vue-admin/service"
"gin-vue-admin/utils"
"github.com/gin-gonic/gin"
"go.uber.org/zap"
)
// @Tags SysDictionary
@@ -15,15 +16,15 @@ import (
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.SysDictionary true "创建SysDictionary"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Param data body model.SysDictionary true "SysDictionary模型"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"创建成功"}"
// @Router /sysDictionary/createSysDictionary [post]
func CreateSysDictionary(c *gin.Context) {
var sysDictionary model.SysDictionary
_ = c.ShouldBindJSON(&sysDictionary)
err := service.CreateSysDictionary(sysDictionary)
if err != nil {
response.FailWithMessage(fmt.Sprintf("创建失败,%v", err), c)
var dictionary model.SysDictionary
_ = c.ShouldBindJSON(&dictionary)
if err := service.CreateSysDictionary(dictionary); err != nil {
global.GVA_LOG.Error("创建失败!", zap.Any("err", err))
response.FailWithMessage("创建失败", c)
} else {
response.OkWithMessage("创建成功", c)
}
@@ -34,15 +35,15 @@ func CreateSysDictionary(c *gin.Context) {
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.SysDictionary true "删除SysDictionary"
// @Param data body model.SysDictionary true "SysDictionary模型"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
// @Router /sysDictionary/deleteSysDictionary [delete]
func DeleteSysDictionary(c *gin.Context) {
var sysDictionary model.SysDictionary
_ = c.ShouldBindJSON(&sysDictionary)
err := service.DeleteSysDictionary(sysDictionary)
if err != nil {
response.FailWithMessage(fmt.Sprintf("删除失败,%v", err), c)
var dictionary model.SysDictionary
_ = c.ShouldBindJSON(&dictionary)
if err := service.DeleteSysDictionary(dictionary); err != nil {
global.GVA_LOG.Error("删除失败!", zap.Any("err", err))
response.FailWithMessage("删除失败", c)
} else {
response.OkWithMessage("删除成功", c)
}
@@ -53,15 +54,15 @@ func DeleteSysDictionary(c *gin.Context) {
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.SysDictionary true "更新SysDictionary"
// @Param data body model.SysDictionary true "SysDictionary模型"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}"
// @Router /sysDictionary/updateSysDictionary [put]
func UpdateSysDictionary(c *gin.Context) {
var sysDictionary model.SysDictionary
_ = c.ShouldBindJSON(&sysDictionary)
err := service.UpdateSysDictionary(&sysDictionary)
if err != nil {
response.FailWithMessage(fmt.Sprintf("更新失败,%v", err), c)
var dictionary model.SysDictionary
_ = c.ShouldBindJSON(&dictionary)
if err := service.UpdateSysDictionary(&dictionary); err != nil {
global.GVA_LOG.Error("更新失败!", zap.Any("err", err))
response.FailWithMessage("更新失败", c)
} else {
response.OkWithMessage("更新成功", c)
}
@@ -72,17 +73,17 @@ func UpdateSysDictionary(c *gin.Context) {
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.SysDictionary true "用id查询SysDictionary"
// @Param data body model.SysDictionary true "ID或字典英名"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}"
// @Router /sysDictionary/findSysDictionary [get]
func FindSysDictionary(c *gin.Context) {
var sysDictionary model.SysDictionary
_ = c.ShouldBindQuery(&sysDictionary)
err, resysDictionary := service.GetSysDictionary(sysDictionary.Type, sysDictionary.ID)
if err != nil {
response.FailWithMessage(fmt.Sprintf("查询失败,%v", err), c)
var dictionary model.SysDictionary
_ = c.ShouldBindQuery(&dictionary)
if err, sysDictionary := service.GetSysDictionary(dictionary.Type, dictionary.ID); err != nil {
global.GVA_LOG.Error("查询失败!", zap.Any("err", err))
response.FailWithMessage("查询失败", c)
} else {
response.OkWithData(gin.H{"resysDictionary": resysDictionary}, c)
response.OkWithDetailed(gin.H{"resysDictionary": sysDictionary}, "查询成功", c)
}
}
@@ -91,21 +92,25 @@ func FindSysDictionary(c *gin.Context) {
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.SysDictionarySearch true "分页获取SysDictionary列表"
// @Param data body request.SysDictionarySearch true "页码, 每页大小, 搜索条件"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /sysDictionary/getSysDictionaryList [get]
func GetSysDictionaryList(c *gin.Context) {
var pageInfo request.SysDictionarySearch
_ = c.ShouldBindQuery(&pageInfo)
err, list, total := service.GetSysDictionaryInfoList(pageInfo)
if err != nil {
response.FailWithMessage(fmt.Sprintf("获取数据失败,%v", err), c)
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 {
global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
response.FailWithMessage("获取失败", c)
} else {
response.OkWithData(resp.PageResult{
response.OkWithDetailed(response.PageResult{
List: list,
Total: total,
Page: pageInfo.Page,
PageSize: pageInfo.PageSize,
}, c)
}, "获取成功", c)
}
}
+38 -33
View File
@@ -1,13 +1,14 @@
package v1
import (
"fmt"
"gin-vue-admin/global/response"
"gin-vue-admin/global"
"gin-vue-admin/model"
"gin-vue-admin/model/request"
resp "gin-vue-admin/model/response"
"gin-vue-admin/model/response"
"gin-vue-admin/service"
"gin-vue-admin/utils"
"github.com/gin-gonic/gin"
"go.uber.org/zap"
)
// @Tags SysDictionaryDetail
@@ -15,15 +16,15 @@ import (
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.SysDictionaryDetail true "创建SysDictionaryDetail"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Param data body model.SysDictionaryDetail true "SysDictionaryDetail模型"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"创建成功"}"
// @Router /sysDictionaryDetail/createSysDictionaryDetail [post]
func CreateSysDictionaryDetail(c *gin.Context) {
var sysDictionaryDetail model.SysDictionaryDetail
_ = c.ShouldBindJSON(&sysDictionaryDetail)
err := service.CreateSysDictionaryDetail(sysDictionaryDetail)
if err != nil {
response.FailWithMessage(fmt.Sprintf("创建失败,%v", err), c)
var detail model.SysDictionaryDetail
_ = c.ShouldBindJSON(&detail)
if err := service.CreateSysDictionaryDetail(detail); err != nil {
global.GVA_LOG.Error("创建失败!", zap.Any("err", err))
response.FailWithMessage("创建失败", c)
} else {
response.OkWithMessage("创建成功", c)
}
@@ -34,15 +35,15 @@ func CreateSysDictionaryDetail(c *gin.Context) {
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.SysDictionaryDetail true "删除SysDictionaryDetail"
// @Param data body model.SysDictionaryDetail true "SysDictionaryDetail模型"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
// @Router /sysDictionaryDetail/deleteSysDictionaryDetail [delete]
func DeleteSysDictionaryDetail(c *gin.Context) {
var sysDictionaryDetail model.SysDictionaryDetail
_ = c.ShouldBindJSON(&sysDictionaryDetail)
err := service.DeleteSysDictionaryDetail(sysDictionaryDetail)
if err != nil {
response.FailWithMessage(fmt.Sprintf("删除失败,%v", err), c)
var detail model.SysDictionaryDetail
_ = c.ShouldBindJSON(&detail)
if err := service.DeleteSysDictionaryDetail(detail); err != nil {
global.GVA_LOG.Error("删除失败!", zap.Any("err", err))
response.FailWithMessage("删除失败", c)
} else {
response.OkWithMessage("删除成功", c)
}
@@ -57,11 +58,11 @@ func DeleteSysDictionaryDetail(c *gin.Context) {
// @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}"
// @Router /sysDictionaryDetail/updateSysDictionaryDetail [put]
func UpdateSysDictionaryDetail(c *gin.Context) {
var sysDictionaryDetail model.SysDictionaryDetail
_ = c.ShouldBindJSON(&sysDictionaryDetail)
err := service.UpdateSysDictionaryDetail(&sysDictionaryDetail)
if err != nil {
response.FailWithMessage(fmt.Sprintf("更新失败,%v", err), c)
var detail model.SysDictionaryDetail
_ = c.ShouldBindJSON(&detail)
if err := service.UpdateSysDictionaryDetail(&detail); err != nil {
global.GVA_LOG.Error("更新失败!", zap.Any("err", err))
response.FailWithMessage("更新失败", c)
} else {
response.OkWithMessage("更新成功", c)
}
@@ -76,13 +77,17 @@ func UpdateSysDictionaryDetail(c *gin.Context) {
// @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}"
// @Router /sysDictionaryDetail/findSysDictionaryDetail [get]
func FindSysDictionaryDetail(c *gin.Context) {
var sysDictionaryDetail model.SysDictionaryDetail
_ = c.ShouldBindQuery(&sysDictionaryDetail)
err, resysDictionaryDetail := service.GetSysDictionaryDetail(sysDictionaryDetail.ID)
if err != nil {
response.FailWithMessage(fmt.Sprintf("查询失败,%v", err), c)
var detail model.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 {
global.GVA_LOG.Error("查询失败!", zap.Any("err", err))
response.FailWithMessage("查询失败", c)
} else {
response.OkWithData(gin.H{"resysDictionaryDetail": resysDictionaryDetail}, c)
response.OkWithDetailed(gin.H{"resysDictionaryDetail": resysDictionaryDetail}, "查询成功", c)
}
}
@@ -91,21 +96,21 @@ func FindSysDictionaryDetail(c *gin.Context) {
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.SysDictionaryDetailSearch true "分页获取SysDictionaryDetail列表"
// @Param data body request.SysDictionaryDetailSearch true "页码, 每页大小, 搜索条件"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /sysDictionaryDetail/getSysDictionaryDetailList [get]
func GetSysDictionaryDetailList(c *gin.Context) {
var pageInfo request.SysDictionaryDetailSearch
_ = c.ShouldBindQuery(&pageInfo)
err, list, total := service.GetSysDictionaryDetailInfoList(pageInfo)
if err != nil {
response.FailWithMessage(fmt.Sprintf("获取数据失败,%v", err), c)
if err, list, total := service.GetSysDictionaryDetailInfoList(pageInfo); err != nil {
global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
response.FailWithMessage("获取失败", c)
} else {
response.OkWithData(resp.PageResult{
response.OkWithDetailed(response.PageResult{
List: list,
Total: total,
Page: pageInfo.Page,
PageSize: pageInfo.PageSize,
}, c)
}, "获取成功", c)
}
}
+8 -7
View File
@@ -1,22 +1,23 @@
package v1
import (
"fmt"
"gin-vue-admin/global/response"
"gin-vue-admin/global"
"gin-vue-admin/model/response"
"gin-vue-admin/service"
"github.com/gin-gonic/gin"
"go.uber.org/zap"
)
// @Tags system
// @Tags System
// @Summary 发送测试邮件
// @Security ApiKeyAuth
// @Produce application/json
// @Success 200 {string} string "{"success":true,"data":{},"msg":"返回成功"}"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"发送成功"}"
// @Router /email/emailTest [post]
func EmailTest(c *gin.Context) {
err := service.EmailTest()
if err != nil {
response.FailWithMessage(fmt.Sprintf("发送失败,%v", err), c)
if err := service.EmailTest(); err != nil {
global.GVA_LOG.Error("发送失败!", zap.Any("err", err))
response.FailWithMessage("发送失败", c)
} else {
response.OkWithData("发送成功", c)
}
+8 -9
View File
@@ -1,14 +1,15 @@
package v1
import (
"fmt"
"gin-vue-admin/global/response"
"gin-vue-admin/global"
"gin-vue-admin/model"
"gin-vue-admin/model/response"
"gin-vue-admin/service"
"github.com/gin-gonic/gin"
"go.uber.org/zap"
)
// @Tags jwt
// @Tags Jwt
// @Summary jwt加入黑名单
// @Security ApiKeyAuth
// @accept application/json
@@ -17,12 +18,10 @@ import (
// @Router /jwt/jsonInBlacklist [post]
func JsonInBlacklist(c *gin.Context) {
token := c.Request.Header.Get("x-token")
modelJwt := model.JwtBlacklist{
Jwt: token,
}
err := service.JsonInBlacklist(modelJwt)
if err != nil {
response.FailWithMessage(fmt.Sprintf("jwt作废失败,%v", err), c)
jwt := model.JwtBlacklist{Jwt: token}
if err := service.JsonInBlacklist(jwt); err != nil {
global.GVA_LOG.Error("jwt作废失败!", zap.Any("err", err))
response.FailWithMessage("jwt作废失败", c)
} else {
response.OkWithMessage("jwt作废成功", c)
}
+122 -162
View File
@@ -1,259 +1,219 @@
package v1
import (
"fmt"
"gin-vue-admin/global/response"
"gin-vue-admin/global"
"gin-vue-admin/model"
"gin-vue-admin/model/request"
resp "gin-vue-admin/model/response"
"gin-vue-admin/model/response"
"gin-vue-admin/service"
"gin-vue-admin/utils"
"github.com/gin-gonic/gin"
"go.uber.org/zap"
)
// @Tags authorityAndMenu
// @Tags AuthorityMenu
// @Summary 获取用户动态路由
// @Security ApiKeyAuth
// @Produce application/json
// @Param data body request.RegisterAndLoginStruct true "可以什么都不填"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"返回成功"}"
// @Param data body request.Empty true "空"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /menu/getMenu [post]
func GetMenu(c *gin.Context) {
claims, _ := c.Get("claims")
waitUse := claims.(*request.CustomClaims)
err, menus := service.GetMenuTree(waitUse.AuthorityId)
if err != nil {
response.FailWithMessage(fmt.Sprintf("获取失败,%v", err), c)
if err, menus := service.GetMenuTree(getUserAuthorityId(c)); err != nil {
global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
response.FailWithMessage("获取失败", c)
} else {
response.OkWithData(resp.SysMenusResponse{Menus: menus}, c)
response.OkWithDetailed(response.SysMenusResponse{Menus: menus}, "获取成功", c)
}
}
// @Tags menu
// @Summary 分页获取基础menu列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.PageInfo true "分页获取基础menu列表"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /menu/getMenuList [post]
func GetMenuList(c *gin.Context) {
var pageInfo request.PageInfo
_ = c.ShouldBindJSON(&pageInfo)
PageVerifyErr := utils.Verify(pageInfo, utils.CustomizeMap["PageVerify"])
if PageVerifyErr != nil {
response.FailWithMessage(PageVerifyErr.Error(), c)
return
}
err, menuList, total := service.GetInfoList()
if err != nil {
response.FailWithMessage(fmt.Sprintf("获取数据失败,%v", err), c)
} else {
response.OkWithData(resp.PageResult{
List: menuList,
Total: total,
Page: pageInfo.Page,
PageSize: pageInfo.PageSize,
}, c)
}
}
// @Tags menu
// @Summary 新增菜单
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.SysBaseMenu true "新增菜单"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /menu/addBaseMenu [post]
func AddBaseMenu(c *gin.Context) {
var menu model.SysBaseMenu
_ = c.ShouldBindJSON(&menu)
MenuVerify := utils.Rules{
"Path": {utils.NotEmpty()},
"ParentId": {utils.NotEmpty()},
"Name": {utils.NotEmpty()},
"Component": {utils.NotEmpty()},
"Sort": {utils.Ge("0")},
}
MenuVerifyErr := utils.Verify(menu, MenuVerify)
if MenuVerifyErr != nil {
response.FailWithMessage(MenuVerifyErr.Error(), c)
return
}
MetaVerify := utils.Rules{
"Title": {utils.NotEmpty()},
}
MetaVerifyErr := utils.Verify(menu.Meta, MetaVerify)
if MetaVerifyErr != nil {
response.FailWithMessage(MetaVerifyErr.Error(), c)
return
}
err := service.AddBaseMenu(menu)
if err != nil {
response.FailWithMessage(fmt.Sprintf("添加失败,%v", err), c)
} else {
response.OkWithMessage("添加成功", c)
}
}
// @Tags authorityAndMenu
// @Tags AuthorityMenu
// @Summary 获取用户动态路由
// @Security ApiKeyAuth
// @Produce application/json
// @Param data body request.RegisterAndLoginStruct true "可以什么都不填"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"返回成功"}"
// @Param data body request.Empty true "空"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /menu/getBaseMenuTree [post]
func GetBaseMenuTree(c *gin.Context) {
err, menus := service.GetBaseMenuTree()
if err != nil {
response.FailWithMessage(fmt.Sprintf("获取失败,%v", err), c)
if err, menus := service.GetBaseMenuTree(); err != nil {
global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
response.FailWithMessage("获取失败", c)
} else {
response.OkWithData(resp.SysBaseMenusResponse{Menus: menus}, c)
response.OkWithDetailed(response.SysBaseMenusResponse{Menus: menus}, "获取成功", c)
}
}
// @Tags authorityAndMenu
// @Tags AuthorityMenu
// @Summary 增加menu和角色关联关系
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.AddMenuAuthorityInfo true "增加menu和角色关联关系"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Param data body request.AddMenuAuthorityInfo true "角色ID"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"添加成功"}"
// @Router /menu/addMenuAuthority [post]
func AddMenuAuthority(c *gin.Context) {
var addMenuAuthorityInfo request.AddMenuAuthorityInfo
_ = c.ShouldBindJSON(&addMenuAuthorityInfo)
MenuVerify := utils.Rules{
"AuthorityId": {"notEmpty"},
}
MenuVerifyErr := utils.Verify(addMenuAuthorityInfo, MenuVerify)
if MenuVerifyErr != nil {
response.FailWithMessage(MenuVerifyErr.Error(), c)
var authorityMenu request.AddMenuAuthorityInfo
_ = c.ShouldBindJSON(&authorityMenu)
if err := utils.Verify(authorityMenu, utils.AuthorityIdVerify); err != nil {
response.FailWithMessage(err.Error(), c)
return
}
err := service.AddMenuAuthority(addMenuAuthorityInfo.Menus, addMenuAuthorityInfo.AuthorityId)
if err != nil {
response.FailWithMessage(fmt.Sprintf("添加失败,%v", err), c)
if err := service.AddMenuAuthority(authorityMenu.Menus, authorityMenu.AuthorityId); err != nil {
global.GVA_LOG.Error("添加失败!", zap.Any("err", err))
response.FailWithMessage("添加失败", c)
} else {
response.OkWithMessage("添加成功", c)
}
}
// @Tags authorityAndMenu
// @Tags AuthorityMenu
// @Summary 获取指定角色menu
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.AuthorityIdInfo true "增加menu和角色关联关系"
// @Param data body request.GetAuthorityId true "角色ID"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /menu/GetMenuAuthority [post]
func GetMenuAuthority(c *gin.Context) {
var authorityIdInfo request.AuthorityIdInfo
_ = c.ShouldBindJSON(&authorityIdInfo)
MenuVerify := utils.Rules{
"AuthorityId": {"notEmpty"},
}
MenuVerifyErr := utils.Verify(authorityIdInfo, MenuVerify)
if MenuVerifyErr != nil {
response.FailWithMessage(MenuVerifyErr.Error(), c)
var param request.GetAuthorityId
_ = c.ShouldBindJSON(&param)
if err := utils.Verify(param, utils.AuthorityIdVerify); err != nil {
response.FailWithMessage(err.Error(), c)
return
}
err, menus := service.GetMenuAuthority(authorityIdInfo.AuthorityId)
if err != nil {
response.FailWithDetailed(response.ERROR, resp.SysMenusResponse{Menus: menus}, fmt.Sprintf("添加失败,%v", err), c)
if err, menus := service.GetMenuAuthority(&param); err != nil {
global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
response.FailWithDetailed(response.SysMenusResponse{Menus: menus}, "获取失败", c)
} else {
response.Result(response.SUCCESS, gin.H{"menus": menus}, "获取成功", c)
response.OkWithDetailed(gin.H{"menus": menus}, "获取成功", c)
}
}
// @Tags menu
// @Tags Menu
// @Summary 新增菜单
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.SysBaseMenu true "路由path, 父菜单ID, 路由name, 对应前端文件路径, 排序标记"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"添加成功"}"
// @Router /menu/addBaseMenu [post]
func AddBaseMenu(c *gin.Context) {
var menu model.SysBaseMenu
_ = c.ShouldBindJSON(&menu)
if err := utils.Verify(menu, utils.MenuVerify); err != nil {
response.FailWithMessage(err.Error(), c)
return
}
if err := utils.Verify(menu.Meta, utils.MenuMetaVerify); err != nil {
response.FailWithMessage(err.Error(), c)
return
}
if err := service.AddBaseMenu(menu); err != nil {
global.GVA_LOG.Error("添加失败!", zap.Any("err", err))
response.FailWithMessage("添加失败", c)
} else {
response.OkWithMessage("添加成功", c)
}
}
// @Tags Menu
// @Summary 删除菜单
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.GetById true "删除菜单"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Param data body request.GetById true "菜单id"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
// @Router /menu/deleteBaseMenu [post]
func DeleteBaseMenu(c *gin.Context) {
var idInfo request.GetById
_ = c.ShouldBindJSON(&idInfo)
IdVerifyErr := utils.Verify(idInfo, utils.CustomizeMap["IdVerify"])
if IdVerifyErr != nil {
response.FailWithMessage(IdVerifyErr.Error(), c)
var menu request.GetById
_ = c.ShouldBindJSON(&menu)
if err := utils.Verify(menu, utils.IdVerify); err != nil {
response.FailWithMessage(err.Error(), c)
return
}
err := service.DeleteBaseMenu(idInfo.Id)
if err != nil {
response.FailWithMessage(fmt.Sprintf("删除失败:%v", err), c)
if err := service.DeleteBaseMenu(menu.Id); err != nil {
global.GVA_LOG.Error("删除失败!", zap.Any("err", err))
response.FailWithMessage("删除失败", c)
} else {
response.OkWithMessage("删除成功", c)
}
}
// @Tags menu
// @Tags Menu
// @Summary 更新菜单
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.SysBaseMenu true "更新菜单"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Param data body model.SysBaseMenu true "路由path, 父菜单ID, 路由name, 对应前端文件路径, 排序标记"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}"
// @Router /menu/updateBaseMenu [post]
func UpdateBaseMenu(c *gin.Context) {
var menu model.SysBaseMenu
_ = c.ShouldBindJSON(&menu)
MenuVerify := utils.Rules{
"Path": {"notEmpty"},
"ParentId": {utils.NotEmpty()},
"Name": {utils.NotEmpty()},
"Component": {utils.NotEmpty()},
"Sort": {utils.Ge("0")},
}
MenuVerifyErr := utils.Verify(menu, MenuVerify)
if MenuVerifyErr != nil {
response.FailWithMessage(MenuVerifyErr.Error(), c)
if err := utils.Verify(menu, utils.MenuVerify); err != nil {
response.FailWithMessage(err.Error(), c)
return
}
MetaVerify := utils.Rules{
"Title": {utils.NotEmpty()},
}
MetaVerifyErr := utils.Verify(menu.Meta, MetaVerify)
if MetaVerifyErr != nil {
response.FailWithMessage(MetaVerifyErr.Error(), c)
if err := utils.Verify(menu.Meta, utils.MenuMetaVerify); err != nil {
response.FailWithMessage(err.Error(), c)
return
}
err := service.UpdateBaseMenu(menu)
if err != nil {
response.FailWithMessage(fmt.Sprintf("修改失败:%v", err), c)
if err := service.UpdateBaseMenu(menu); err != nil {
global.GVA_LOG.Error("更新失败!", zap.Any("err", err))
response.FailWithMessage("更新失败", c)
} else {
response.OkWithMessage("修改成功", c)
response.OkWithMessage("更新成功", c)
}
}
// @Tags menu
// @Tags Menu
// @Summary 根据id获取菜单
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.GetById true "根据id获取菜单"
// @Param data body request.GetById true "菜单id"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /menu/getBaseMenuById [post]
func GetBaseMenuById(c *gin.Context) {
var idInfo request.GetById
_ = c.ShouldBindJSON(&idInfo)
MenuVerify := utils.Rules{
"Id": {"notEmpty"},
}
MenuVerifyErr := utils.Verify(idInfo, MenuVerify)
if MenuVerifyErr != nil {
response.FailWithMessage(MenuVerifyErr.Error(), c)
if err := utils.Verify(idInfo, utils.IdVerify); err != nil {
response.FailWithMessage(err.Error(), c)
return
}
err, menu := service.GetBaseMenuById(idInfo.Id)
if err != nil {
response.FailWithMessage(fmt.Sprintf("查询失败:%v", err), c)
if err, menu := service.GetBaseMenuById(idInfo.Id); err != nil {
global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
response.FailWithMessage("获取失败", c)
} else {
response.OkWithData(resp.SysBaseMenuResponse{Menu: menu}, c)
response.OkWithDetailed(response.SysBaseMenuResponse{Menu: menu}, "获取成功", c)
}
}
// @Tags Menu
// @Summary 分页获取基础menu列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.PageInfo true "页码, 每页大小"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /menu/getMenuList [post]
func 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 {
global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
response.FailWithMessage("获取失败", c)
} else {
response.OkWithDetailed(response.PageResult{
List: menuList,
Total: total,
Page: pageInfo.Page,
PageSize: pageInfo.PageSize,
},"获取成功", c)
}
}
+31 -26
View File
@@ -1,13 +1,14 @@
package v1
import (
"fmt"
"gin-vue-admin/global/response"
"gin-vue-admin/global"
"gin-vue-admin/model"
"gin-vue-admin/model/request"
resp "gin-vue-admin/model/response"
"gin-vue-admin/model/response"
"gin-vue-admin/service"
"gin-vue-admin/utils"
"github.com/gin-gonic/gin"
"go.uber.org/zap"
)
// @Tags SysOperationRecord
@@ -21,9 +22,9 @@ import (
func CreateSysOperationRecord(c *gin.Context) {
var sysOperationRecord model.SysOperationRecord
_ = c.ShouldBindJSON(&sysOperationRecord)
err := service.CreateSysOperationRecord(sysOperationRecord)
if err != nil {
response.FailWithMessage(fmt.Sprintf("创建失败,%v", err), c)
if err := service.CreateSysOperationRecord(sysOperationRecord); err != nil {
global.GVA_LOG.Error("创建失败!", zap.Any("err", err))
response.FailWithMessage("创建失败", c)
} else {
response.OkWithMessage("创建成功", c)
}
@@ -34,15 +35,15 @@ func CreateSysOperationRecord(c *gin.Context) {
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.SysOperationRecord true "删除SysOperationRecord"
// @Param data body model.SysOperationRecord true "SysOperationRecord模型"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
// @Router /sysOperationRecord/deleteSysOperationRecord [delete]
func DeleteSysOperationRecord(c *gin.Context) {
var sysOperationRecord model.SysOperationRecord
_ = c.ShouldBindJSON(&sysOperationRecord)
err := service.DeleteSysOperationRecord(sysOperationRecord)
if err != nil {
response.FailWithMessage(fmt.Sprintf("删除失败,%v", err), c)
if err := service.DeleteSysOperationRecord(sysOperationRecord); err != nil {
global.GVA_LOG.Error("删除失败!", zap.Any("err", err))
response.FailWithMessage("删除失败", c)
} else {
response.OkWithMessage("删除成功", c)
}
@@ -54,16 +55,16 @@ func DeleteSysOperationRecord(c *gin.Context) {
// @accept application/json
// @Produce application/json
// @Param data body request.IdsReq true "批量删除SysOperationRecord"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"批量删除成功"}"
// @Router /sysOperationRecord/deleteSysOperationRecordByIds [delete]
func DeleteSysOperationRecordByIds(c *gin.Context) {
var IDS request.IdsReq
_ = c.ShouldBindJSON(&IDS)
err := service.DeleteSysOperationRecordByIds(IDS)
if err != nil {
response.FailWithMessage(fmt.Sprintf("删除失败,%v", err), c)
if err := service.DeleteSysOperationRecordByIds(IDS); err != nil {
global.GVA_LOG.Error("批量删除失败!", zap.Any("err", err))
response.FailWithMessage("批量删除失败", c)
} else {
response.OkWithMessage("删除成功", c)
response.OkWithMessage("批量删除成功", c)
}
}
@@ -72,17 +73,21 @@ func DeleteSysOperationRecordByIds(c *gin.Context) {
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.SysOperationRecord true "用id查询SysOperationRecord"
// @Param data body model.SysOperationRecord true "Id"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}"
// @Router /sysOperationRecord/findSysOperationRecord [get]
func FindSysOperationRecord(c *gin.Context) {
var sysOperationRecord model.SysOperationRecord
_ = c.ShouldBindQuery(&sysOperationRecord)
err, resysOperationRecord := service.GetSysOperationRecord(sysOperationRecord.ID)
if err != nil {
response.FailWithMessage(fmt.Sprintf("查询失败,%v", err), c)
if err := utils.Verify(sysOperationRecord, utils.IdVerify); err != nil {
response.FailWithMessage(err.Error(), c)
return
}
if err, resysOperationRecord := service.GetSysOperationRecord(sysOperationRecord.ID); err != nil {
global.GVA_LOG.Error("查询失败!", zap.Any("err", err))
response.FailWithMessage("查询失败", c)
} else {
response.OkWithData(gin.H{"resysOperationRecord": resysOperationRecord}, c)
response.OkWithDetailed(gin.H{"resysOperationRecord": resysOperationRecord}, "查询成功", c)
}
}
@@ -91,21 +96,21 @@ func FindSysOperationRecord(c *gin.Context) {
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.SysOperationRecordSearch true "分页获取SysOperationRecord列表"
// @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
_ = c.ShouldBindQuery(&pageInfo)
err, list, total := service.GetSysOperationRecordInfoList(pageInfo)
if err != nil {
response.FailWithMessage(fmt.Sprintf("获取数据失败,%v", err), c)
if err, list, total := service.GetSysOperationRecordInfoList(pageInfo); err != nil {
global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
response.FailWithMessage("获取失败", c)
} else {
response.OkWithData(resp.PageResult{
response.OkWithDetailed(response.PageResult{
List: list,
Total: total,
Page: pageInfo.Page,
PageSize: pageInfo.PageSize,
}, c)
}, "获取成功", c)
}
}
+29 -28
View File
@@ -1,78 +1,79 @@
package v1
import (
"fmt"
"gin-vue-admin/global/response"
"gin-vue-admin/global"
"gin-vue-admin/model"
resp "gin-vue-admin/model/response"
"gin-vue-admin/model/response"
"gin-vue-admin/service"
"github.com/gin-gonic/gin"
"go.uber.org/zap"
)
// @Tags system
// @Tags System
// @Summary 获取配置文件内容
// @Security ApiKeyAuth
// @Produce application/json
// @Success 200 {string} string "{"success":true,"data":{},"msg":"返回成功"}"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /system/getSystemConfig [post]
func GetSystemConfig(c *gin.Context) {
err, config := service.GetSystemConfig()
if err != nil {
response.FailWithMessage(fmt.Sprintf("获取失败,%v", err), c)
if err, config := service.GetSystemConfig(); err != nil {
global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
response.FailWithMessage("获取失败", c)
} else {
response.OkWithData(resp.SysConfigResponse{Config: config}, c)
response.OkWithDetailed(response.SysConfigResponse{Config: config}, "获取成功", c)
}
}
// @Tags system
// @Tags System
// @Summary 设置配置文件内容
// @Security ApiKeyAuth
// @Produce application/json
// @Param data body model.System true "设置配置文件内容"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"返回成功"}"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"设置成功"}"
// @Router /system/setSystemConfig [post]
func SetSystemConfig(c *gin.Context) {
var sys model.System
_ = c.ShouldBindJSON(&sys)
err := service.SetSystemConfig(sys)
if err != nil {
response.FailWithMessage(fmt.Sprintf("设置失败,%v", err), c)
if err := service.SetSystemConfig(sys); err != nil {
global.GVA_LOG.Error("设置失败!", zap.Any("err", err))
response.FailWithMessage("设置失败", c)
} else {
response.OkWithData("设置成功", c)
}
}
// 本方法开发中 开发者windows系统 缺少linux系统所需的包 因此搁置
// @Tags system
// @Summary 设置配置文件内容
// @Tags System
// @Summary 重启系统
// @Security ApiKeyAuth
// @Produce application/json
// @Param data body model.System true "设置配置文件内容"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"返回成功"}"
// @Param data body model.System true "重启系统"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"重启系统成功"}"
// @Router /system/ReloadSystem [post]
func ReloadSystem(c *gin.Context) {
var sys model.System
_ = c.ShouldBindJSON(&sys)
err := service.SetSystemConfig(sys)
if err != nil {
response.FailWithMessage(fmt.Sprintf("设置失败,%v", err), c)
if err := service.SetSystemConfig(sys); err != nil {
global.GVA_LOG.Error("重启系统失败!", zap.Any("err", err))
response.FailWithMessage("重启系统失败", c)
} else {
response.OkWithMessage("设置成功", c)
response.OkWithMessage("重启系统成功", c)
}
}
// @Tags system
// @Tags System
// @Summary 获取服务器信息
// @Security ApiKeyAuth
// @Produce application/json
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /system/getServerInfo [post]
func GetServerInfo(c *gin.Context) {
server, err := service.GetServerInfo()
if err != nil {
response.FailWithMessage(fmt.Sprintf("获取失败,%v", err), c)
if server, err := service.GetServerInfo(); err != nil {
global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
response.FailWithMessage("获取失败", c)
return
}else {
response.OkWithDetailed(gin.H{"server": server}, "获取成功", c)
}
response.OkDetailed(gin.H{"server":server}, "获取成功",c)
}
}
+122 -118
View File
@@ -1,90 +1,50 @@
package v1
import (
"fmt"
"gin-vue-admin/global"
"gin-vue-admin/global/response"
"gin-vue-admin/middleware"
"gin-vue-admin/model"
"gin-vue-admin/model/request"
resp "gin-vue-admin/model/response"
"gin-vue-admin/model/response"
"gin-vue-admin/service"
"gin-vue-admin/utils"
"github.com/dgrijalva/jwt-go"
"github.com/gin-gonic/gin"
"github.com/go-redis/redis"
"mime/multipart"
"go.uber.org/zap"
"time"
)
// @Tags Base
// @Summary 用户注册账号
// @Produce application/json
// @Param data body model.SysUser true "用户注册接口"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"注册成功"}"
// @Router /user/register [post]
func Register(c *gin.Context) {
var R request.RegisterStruct
_ = c.ShouldBindJSON(&R)
UserVerify := utils.Rules{
"Username": {utils.NotEmpty()},
"NickName": {utils.NotEmpty()},
"Password": {utils.NotEmpty()},
"AuthorityId": {utils.NotEmpty()},
}
UserVerifyErr := utils.Verify(R, UserVerify)
if UserVerifyErr != nil {
response.FailWithMessage(UserVerifyErr.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)
if err != nil {
response.FailWithDetailed(response.ERROR, resp.SysUserResponse{User: userReturn}, fmt.Sprintf("%v", err), c)
} else {
response.OkDetailed(resp.SysUserResponse{User: userReturn}, "注册成功", c)
}
}
// @Tags Base
// @Summary 用户登录
// @Produce application/json
// @Param data body request.RegisterAndLoginStruct true "用户登录接口"
// @Param data body request.Login true "用户名, 密码, 验证码"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"登陆成功"}"
// @Router /base/login [post]
func Login(c *gin.Context) {
var L request.RegisterAndLoginStruct
var L request.Login
_ = c.ShouldBindJSON(&L)
UserVerify := utils.Rules{
"CaptchaId": {utils.NotEmpty()},
"Captcha": {utils.NotEmpty()},
"Username": {utils.NotEmpty()},
"Password": {utils.NotEmpty()},
}
UserVerifyErr := utils.Verify(L, UserVerify)
if UserVerifyErr != nil {
response.FailWithMessage(UserVerifyErr.Error(), c)
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 {
response.FailWithMessage(fmt.Sprintf("用户名密码错误或%v", err), c)
global.GVA_LOG.Error("登陆失败! 用户名不存在或者密码错误", zap.Any("err", err))
response.FailWithMessage("登陆失败!", c)
} else {
tokenNext(c, *user)
}
} else {
response.FailWithMessage("验证码错误", c)
}
}
// 登录以后签发jwt
func tokenNext(c *gin.Context, user model.SysUser) {
j := &middleware.JWT{
SigningKey: []byte(global.GVA_CONFIG.JWT.SigningKey), // 唯一签名
}
clams := request.CustomClaims{
j := &middleware.JWT{SigningKey: []byte(global.GVA_CONFIG.JWT.SigningKey)} // 唯一签名
claims := request.CustomClaims{
UUID: user.UUID,
ID: user.ID,
NickName: user.NickName,
@@ -97,32 +57,34 @@ func tokenNext(c *gin.Context, user model.SysUser) {
Issuer: "qmPlus", // 签名的发行者
},
}
token, err := j.CreateToken(clams)
token, err := j.CreateToken(claims)
if err != nil {
global.GVA_LOG.Error("获取token失败", zap.Any("err", err))
response.FailWithMessage("获取token失败", c)
return
}
if !global.GVA_CONFIG.System.UseMultipoint {
response.OkWithData(resp.LoginResponse{
response.OkWithDetailed(response.LoginResponse{
User: user,
Token: token,
ExpiresAt: clams.StandardClaims.ExpiresAt * 1000,
}, c)
ExpiresAt: claims.StandardClaims.ExpiresAt * 1000,
}, "登录成功", c)
return
}
err, jwtStr := service.GetRedisJWT(user.Username)
if err == redis.Nil {
if err, jwtStr := service.GetRedisJWT(user.Username); err == redis.Nil {
if err := service.SetRedisJWT(token, user.Username); err != nil {
global.GVA_LOG.Error("设置登录状态失败", zap.Any("err", err))
response.FailWithMessage("设置登录状态失败", c)
return
}
response.OkWithData(resp.LoginResponse{
response.OkWithDetailed(response.LoginResponse{
User: user,
Token: token,
ExpiresAt: clams.StandardClaims.ExpiresAt * 1000,
}, c)
ExpiresAt: claims.StandardClaims.ExpiresAt * 1000,
}, "登录成功", c)
} else if err != nil {
response.FailWithMessage(fmt.Sprintf("%v", err), c)
global.GVA_LOG.Error("设置登录状态失败", zap.Any("err", err))
response.FailWithMessage("设置登录状态失败", c)
} else {
var blackJWT model.JwtBlacklist
blackJWT.Jwt = jwtStr
@@ -134,11 +96,34 @@ func tokenNext(c *gin.Context, user model.SysUser) {
response.FailWithMessage("设置登录状态失败", c)
return
}
response.OkWithData(resp.LoginResponse{
response.OkWithDetailed(response.LoginResponse{
User: user,
Token: token,
ExpiresAt: clams.StandardClaims.ExpiresAt * 1000,
}, c)
ExpiresAt: claims.StandardClaims.ExpiresAt * 1000,
}, "登录成功", c)
}
}
// @Tags SysUser
// @Summary 用户注册账号
// @Produce application/json
// @Param data body model.SysUser true "用户名, 昵称, 密码, 角色ID"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"注册成功"}"
// @Router /user/register [post]
func Register(c *gin.Context) {
var R request.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)
if err != nil {
global.GVA_LOG.Error("注册失败", zap.Any("err", err))
response.FailWithDetailed(response.SysUserResponse{User: userReturn}, "注册失败", c)
} else {
response.OkWithDetailed(response.SysUserResponse{User: userReturn}, "注册成功", c)
}
}
@@ -146,60 +131,50 @@ func tokenNext(c *gin.Context, user model.SysUser) {
// @Summary 用户修改密码
// @Security ApiKeyAuth
// @Produce application/json
// @Param data body request.ChangePasswordStruct true "用户修改密码"
// @Param data body request.ChangePasswordStruct true "用户名, 原密码, 新密码"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"修改成功"}"
// @Router /user/changePassword [put]
func ChangePassword(c *gin.Context) {
var params request.ChangePasswordStruct
_ = c.ShouldBindJSON(&params)
UserVerify := utils.Rules{
"Username": {utils.NotEmpty()},
"Password": {utils.NotEmpty()},
"NewPassword": {utils.NotEmpty()},
}
UserVerifyErr := utils.Verify(params, UserVerify)
if UserVerifyErr != nil {
response.FailWithMessage(UserVerifyErr.Error(), c)
var user request.ChangePasswordStruct
_ = c.ShouldBindJSON(&user)
if err := utils.Verify(user, utils.ChangePasswordVerify); err != nil {
response.FailWithMessage(err.Error(), c)
return
}
U := &model.SysUser{Username: params.Username, Password: params.Password}
if err, _ := service.ChangePassword(U, params.NewPassword); err != nil {
response.FailWithMessage("修改失败,请检查用户名密码", c)
U := &model.SysUser{Username: user.Username, Password: user.Password}
if err, _ := service.ChangePassword(U, user.NewPassword); err != nil {
global.GVA_LOG.Error("修改失败", zap.Any("err", err))
response.FailWithMessage("修改失败,原密码与当前账户不符", c)
} else {
response.OkWithMessage("修改成功", c)
}
}
type UserHeaderImg struct {
HeaderImg multipart.File `json:"headerImg"`
}
// @Tags SysUser
// @Summary 分页获取用户列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.PageInfo true "分页获取用户列表"
// @Param data body request.PageInfo true "页码, 每页大小"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /user/getUserList [post]
func GetUserList(c *gin.Context) {
var pageInfo request.PageInfo
_ = c.ShouldBindJSON(&pageInfo)
PageVerifyErr := utils.Verify(pageInfo, utils.CustomizeMap["PageVerify"])
if PageVerifyErr != nil {
response.FailWithMessage(PageVerifyErr.Error(), c)
if err := utils.Verify(pageInfo, utils.PageInfoVerify); err != nil {
response.FailWithMessage(err.Error(), c)
return
}
err, list, total := service.GetUserInfoList(pageInfo)
if err != nil {
response.FailWithMessage(fmt.Sprintf("获取数据失败,%v", err), c)
if err, list, total := service.GetUserInfoList(pageInfo); err != nil {
global.GVA_LOG.Error("获取失败", zap.Any("err", err))
response.FailWithMessage("获取失败", c)
} else {
response.OkWithData(resp.PageResult{
response.OkWithDetailed(response.PageResult{
List: list,
Total: total,
Page: pageInfo.Page,
PageSize: pageInfo.PageSize,
}, c)
}, "获取成功", c)
}
}
@@ -208,24 +183,19 @@ func GetUserList(c *gin.Context) {
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.SetUserAuth true "设置用户权限"
// @Param data body request.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
_ = c.ShouldBindJSON(&sua)
UserVerify := utils.Rules{
"UUID": {utils.NotEmpty()},
"AuthorityId": {utils.NotEmpty()},
}
UserVerifyErr := utils.Verify(sua, UserVerify)
if UserVerifyErr != nil {
if UserVerifyErr := utils.Verify(sua, utils.SetUserAuthorityVerify); UserVerifyErr != nil {
response.FailWithMessage(UserVerifyErr.Error(), c)
return
}
err := service.SetUserAuthority(sua.UUID, sua.AuthorityId)
if err != nil {
response.FailWithMessage(fmt.Sprintf("修改失败,%v", err), c)
if err := service.SetUserAuthority(sua.UUID, sua.AuthorityId); err != nil {
global.GVA_LOG.Error("修改失败", zap.Any("err", err))
response.FailWithMessage("修改失败", c)
} else {
response.OkWithMessage("修改成功", c)
}
@@ -236,42 +206,76 @@ func SetUserAuthority(c *gin.Context) {
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.GetById true "删除用户"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"修改成功"}"
// @Param data body request.GetById true "用户ID"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
// @Router /user/deleteUser [delete]
func DeleteUser(c *gin.Context) {
var reqId request.GetById
_ = c.ShouldBindJSON(&reqId)
IdVerifyErr := utils.Verify(reqId, utils.CustomizeMap["IdVerify"])
if IdVerifyErr != nil {
response.FailWithMessage(IdVerifyErr.Error(), c)
if err := utils.Verify(reqId, utils.IdVerify); err != nil {
response.FailWithMessage(err.Error(), c)
return
}
err := service.DeleteUser(reqId.Id)
if err != nil {
response.FailWithMessage(fmt.Sprintf("删除失败,%v", err), c)
if err := service.DeleteUser(reqId.Id); err != nil {
global.GVA_LOG.Error("删除失败!", zap.Any("err", err))
response.FailWithMessage("删除失败", c)
} else {
response.OkWithMessage("删除成功", c)
}
}
// @Tags SysUser
// @Summary 删除用户
// @Summary 设置用户信息
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.SysUser true "删除用户"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"修改成功"}"
// @Param data body model.SysUser true "ID, 用户名, 昵称, 头像链接"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"设置成功"}"
// @Router /user/setUserInfo [put]
func SetUserInfo(c *gin.Context) {
var user model.SysUser
c.ShouldBindJSON(&user)
err, ReqUser := service.SetUserInfo(user)
if err != nil {
response.FailWithMessage(fmt.Sprintf("更新失败,%v", err), c)
_ = c.ShouldBindJSON(&user)
if err := utils.Verify(user, utils.SetUserVerify); err != nil {
response.FailWithMessage(err.Error(), c)
return
}
if err, ReqUser := service.SetUserInfo(user); err != nil {
global.GVA_LOG.Error("设置失败", zap.Any("err", err))
response.FailWithMessage("设置失败", c)
} else {
response.OkWithData(gin.H{
"userInfo": ReqUser,
}, c)
response.OkWithDetailed(gin.H{"userInfo": ReqUser}, "设置成功", c)
}
}
// 从Gin的Context中获取从jwt解析出来的用户ID
func getUserID(c *gin.Context) uint {
if claims, exists := c.Get("claims"); !exists {
global.GVA_LOG.Error("从Gin的Context中获取从jwt解析出来的用户ID失败, 请检查路由是否使用jwt中间件")
return 0
} else {
waitUse := claims.(*request.CustomClaims)
return waitUse.ID
}
}
// 从Gin的Context中获取从jwt解析出来的用户UUID
func getUserUuid(c *gin.Context) string {
if claims, exists := c.Get("claims"); !exists {
global.GVA_LOG.Error("从Gin的Context中获取从jwt解析出来的用户UUID失败, 请检查路由是否使用jwt中间件")
return ""
} else {
waitUse := claims.(*request.CustomClaims)
return waitUse.UUID.String()
}
}
// 从Gin的Context中获取从jwt解析出来的用户角色id
func getUserAuthorityId(c *gin.Context) string {
if claims, exists := c.Get("claims"); !exists {
global.GVA_LOG.Error("从Gin的Context中获取从jwt解析出来的用户UUID失败, 请检查路由是否使用jwt中间件")
return ""
} else {
waitUse := claims.(*request.CustomClaims)
return waitUse.AuthorityId
}
}
+32
View File
@@ -0,0 +1,32 @@
package v1
import (
"gin-vue-admin/global"
"gin-vue-admin/model"
"gin-vue-admin/model/response"
"gin-vue-admin/service"
"gin-vue-admin/utils"
"github.com/gin-gonic/gin"
"go.uber.org/zap"
)
// @Tags workflow
// @Summary 注册工作流
// @Produce application/json
// @Param data body model.SysWorkflow true "注册工作流接口"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"注册成功"}"
// @Router /workflow/createWorkFlow [post]
func CreateWorkFlow(c *gin.Context) {
var wk model.SysWorkflow
_ = c.ShouldBindJSON(&wk)
if err := utils.Verify(wk, utils.WorkFlowVerify); err != nil {
response.FailWithMessage(err.Error(), c)
return
}
if err := service.Create(wk); err != nil {
global.GVA_LOG.Error("注册失败!", zap.Any("err", err))
response.FailWithMessage("注册失败", c)
} else {
response.OkWithMessage("注册成功", c)
}
}
+1 -1
View File
@@ -68,7 +68,7 @@ var Apis = []model.SysApi{
{global.GVA_MODEL{ID: 57, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/sysOperationRecord/getSysOperationRecordList", "获取操作记录列表", "sysOperationRecord", "GET"},
{global.GVA_MODEL{ID: 58, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/autoCode/getTables", "获取数据库表", "autoCode", "GET"},
{global.GVA_MODEL{ID: 59, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/autoCode/getDB", "获取所有数据库", "autoCode", "GET"},
{global.GVA_MODEL{ID: 60, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/autoCode/getColume", "获取所选table的所有字段", "autoCode", "GET"},
{global.GVA_MODEL{ID: 60, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/autoCode/getColumn", "获取所选table的所有字段", "autoCode", "GET"},
{global.GVA_MODEL{ID: 61, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/sysOperationRecord/deleteSysOperationRecordByIds", "批量删除操作历史", "sysOperationRecord", "DELETE"},
{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"},
+1 -1
View File
@@ -52,7 +52,7 @@ var Carbines = []gormadapter.CasbinRule{
{PType: "p", V0: "888", V1: "/autoCode/createTemp", V2: "POST"},
{PType: "p", V0: "888", V1: "/autoCode/getTables", V2: "GET"},
{PType: "p", V0: "888", V1: "/autoCode/getDB", V2: "GET"},
{PType: "p", V0: "888", V1: "/autoCode/getColume", V2: "GET"},
{PType: "p", V0: "888", V1: "/autoCode/getColumn", V2: "GET"},
{PType: "p", V0: "888", V1: "/sysDictionaryDetail/createSysDictionaryDetail", V2: "POST"},
{PType: "p", V0: "888", V1: "/sysDictionaryDetail/deleteSysDictionaryDetail", V2: "DELETE"},
{PType: "p", V0: "888", V1: "/sysDictionaryDetail/updateSysDictionaryDetail", V2: "PUT"},
+1 -1
View File
@@ -11,7 +11,7 @@ import (
)
var Users = []model.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/1571627762timg.jpg", AuthorityId: "888"},
{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"},
}
+2 -2
View File
@@ -58,14 +58,14 @@ mysql:
username: 'root'
password: 'Aa@6447985'
max-idle-conns: 10
max-open-conns: 10
max-open-conns: 100
log-mode: false
# local configuration
local:
path: 'uploads/file'
# qiniu configuration (请自行七牛申请对应的 公钥 私钥 bucket 和 域名地址)
# qiniu configuration (请自行七牛申请对应的 公钥 私钥 bucket �?域名地址)
qiniu:
zone: 'ZoneHuadong'
bucket: 'qm-plus-img'
+2 -1
View File
@@ -29,9 +29,10 @@ func RunWindowsServer() {
fmt.Printf(`
欢迎使用 Gin-Vue-Admin
当前版本:V2.3.4
当前版本:V2.3.6
默认自动化文档地址:http://127.0.0.1%s/swagger/index.html
默认前端文件运行地址:http://127.0.0.1:8080
如果项目让您获得了收益,希望您能请团队喝杯可乐:https://www.gin-vue-admin.com/docs/coffee
`, address)
global.GVA_LOG.Error(s.ListenAndServe().Error())
}
+1 -1
View File
@@ -43,7 +43,7 @@ func Zap() (logger *zap.Logger) {
logger = zap.New(getEncoderCore())
}
if global.GVA_CONFIG.Zap.ShowLine {
logger.WithOptions(zap.AddCaller())
logger = logger.WithOptions(zap.AddCaller())
}
return logger
}
+342 -319
View File
File diff suppressed because it is too large Load Diff
+341 -317
View File
File diff suppressed because it is too large Load Diff
+275 -263
View File
File diff suppressed because it is too large Load Diff
+1 -1
View File
@@ -33,7 +33,7 @@ require (
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/pkg/errors v0.9.1
github.com/qiniu/api.v7/v7 v7.4.1
github.com/satori/go.uuid v1.2.0
github.com/shirou/gopsutil v2.20.8+incompatible
+2 -2
View File
@@ -2,8 +2,8 @@ package middleware
import (
"gin-vue-admin/global"
"gin-vue-admin/global/response"
"gin-vue-admin/model/request"
"gin-vue-admin/model/response"
"gin-vue-admin/service"
"github.com/gin-gonic/gin"
)
@@ -25,7 +25,7 @@ func CasbinHandler() gin.HandlerFunc {
if global.GVA_CONFIG.System.Env == "develop" || success {
c.Next()
} else {
response.Result(response.ERROR, gin.H{}, "权限不足", c)
response.FailWithDetailed(gin.H{}, "权限不足", c)
c.Abort()
return
}
+17 -28
View File
@@ -3,9 +3,9 @@ package middleware
import (
"errors"
"gin-vue-admin/global"
"gin-vue-admin/global/response"
"gin-vue-admin/model"
"gin-vue-admin/model/request"
"gin-vue-admin/model/response"
"gin-vue-admin/service"
"github.com/dgrijalva/jwt-go"
"github.com/gin-gonic/gin"
@@ -19,16 +19,12 @@ func JWTAuth() gin.HandlerFunc {
// 我们这里jwt鉴权取头部信息 x-token 登录时回返回token信息 这里前端需要把token存储到cookie或者本地localStorage中 不过需要跟后端协商过期时间 可以约定刷新令牌或者重新登录
token := c.Request.Header.Get("x-token")
if token == "" {
response.Result(response.ERROR, gin.H{
"reload": true,
}, "未登录或非法访问", c)
response.FailWithDetailed(gin.H{"reload": true}, "未登录或非法访问", c)
c.Abort()
return
}
if service.IsBlacklist(token) {
response.Result(response.ERROR, gin.H{
"reload": true,
}, "您的帐户异地登陆或令牌失效", c)
response.FailWithDetailed(gin.H{"reload": true}, "您的帐户异地登陆或令牌失效", c)
c.Abort()
return
}
@@ -37,40 +33,33 @@ func JWTAuth() gin.HandlerFunc {
claims, err := j.ParseToken(token)
if err != nil {
if err == TokenExpired {
response.Result(response.ERROR, gin.H{
"reload": true,
}, "授权已过期", c)
response.FailWithDetailed(gin.H{"reload": true}, "授权已过期", c)
c.Abort()
return
}
response.Result(response.ERROR, gin.H{
"reload": true,
}, err.Error(), c)
response.FailWithDetailed(gin.H{"reload": true}, err.Error(), c)
c.Abort()
return
}
if err, _ = service.FindUserByUuid(claims.UUID.String()); err != nil{
response.Result(response.ERROR, gin.H{
"reload": true,
}, err.Error(), c)
if err, _ = service.FindUserByUuid(claims.UUID.String()); err != nil {
response.FailWithDetailed(gin.H{"reload": true}, err.Error(), c)
c.Abort()
}
if claims.ExpiresAt - time.Now().Unix()<claims.BufferTime {
if claims.ExpiresAt-time.Now().Unix() < claims.BufferTime {
claims.ExpiresAt = time.Now().Unix() + 60*60*24*7
newToken,_ := j.CreateToken(*claims)
newClaims,_ := j.ParseToken(newToken)
c.Header("new-token",newToken)
c.Header("new-expires-at",strconv.FormatInt(newClaims.ExpiresAt,10))
newToken, _ := j.CreateToken(*claims)
newClaims, _ := j.ParseToken(newToken)
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)
if err!=nil {
global.GVA_LOG.Error("get redis jwt failed", zap.Any("err", err))
}else{
err, RedisJwtToken := service.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})
//当之前的取成功时才进行拉黑操作
}
// 无论如何都要记录当前的活跃状态
_ = service.SetRedisJWT(newToken,newClaims.Username)
_ = service.SetRedisJWT(newToken, newClaims.Username)
}
}
c.Set("claims", claims)
+8 -1
View File
@@ -13,4 +13,11 @@ type GetById struct {
type IdsReq struct {
Ids []int `json:"ids" form:"ids"`
}
}
// Get role by id structure
type GetAuthorityId struct {
AuthorityId string
}
type Empty struct {}
+6 -6
View File
@@ -1,16 +1,16 @@
package request
type DBReq struct {
Database string `json:"database";gorm:"column:database"`
Database string `json:"database" gorm:"column:database"`
}
type TableReq struct {
TableName string `json:"tableName"`
}
type ColumeReq struct {
ColumeName string `json:"columeName";gorm:"column:colume_name"`
DataType string `json:"dataType";gorm:"column:data_type"`
DataTypeLong string `json:"dataTypeLong";gorm:"column:data_type_long"`
ColumeComment string `json:"columeComment";gorm:"column:colume_comment"`
type ColumnReq struct {
ColumnName string `json:"columnName" gorm:"column:column_name"`
DataType string `json:"dataType" gorm:"column:data_type"`
DataTypeLong string `json:"dataTypeLong" gorm:"column:data_type_long"`
ColumnComment string `json:"columnComment" gorm:"column:column_comment"`
}
-5
View File
@@ -7,8 +7,3 @@ type AddMenuAuthorityInfo struct {
Menus []model.SysBaseMenu
AuthorityId string
}
// Get role by id structure
type AuthorityIdInfo struct {
AuthorityId string
}
+2 -2
View File
@@ -3,7 +3,7 @@ package request
import uuid "github.com/satori/go.uuid"
// User register structure
type RegisterStruct struct {
type Register struct {
Username string `json:"userName"`
Password string `json:"passWord"`
NickName string `json:"nickName" gorm:"default:'QMPlusUser'"`
@@ -12,7 +12,7 @@ type RegisterStruct struct {
}
// User login structure
type RegisterAndLoginStruct struct {
type Login struct {
Username string `json:"username"`
Password string `json:"password"`
Captcha string `json:"captcha"`
@@ -37,7 +37,7 @@ func OkWithData(data interface{}, c *gin.Context) {
Result(SUCCESS, data, "操作成功", c)
}
func OkDetailed(data interface{}, message string, c *gin.Context) {
func OkWithDetailed(data interface{}, message string, c *gin.Context) {
Result(SUCCESS, data, message, c)
}
@@ -49,6 +49,6 @@ func FailWithMessage(message string, c *gin.Context) {
Result(ERROR, map[string]interface{}{}, message, c)
}
func FailWithDetailed(code int, data interface{}, message string, c *gin.Context) {
Result(code, data, message, c)
func FailWithDetailed(data interface{}, message string, c *gin.Context) {
Result(ERROR, data, message, c)
}
+5
View File
@@ -1,5 +1,7 @@
package model
import "errors"
// 初始版本自动化代码工具
type AutoCodeStruct struct {
StructName string `json:"structName"`
@@ -8,6 +10,7 @@ type AutoCodeStruct struct {
Abbreviation string `json:"abbreviation"`
Description string `json:"description"`
AutoCreateApiToSql bool `json:"autoCreateApiToSql"`
AutoMoveFile bool `json:"autoMoveFile"`
Fields []Field `json:"fields"`
}
@@ -23,3 +26,5 @@ type Field struct {
FieldSearchType string `json:"fieldSearchType"`
DictType string `json:"dictType"`
}
var AutoMoveErr error = errors.New("创建代码成功并移动文件成功")
@@ -1,13 +1,13 @@
package v1
import (
"fmt"
"gin-vue-admin/global/response"
"gin-vue-admin/model"
"gin-vue-admin/model/request"
resp "gin-vue-admin/model/response"
"gin-vue-admin/service"
"github.com/gin-gonic/gin"
"gin-vue-admin/global"
"gin-vue-admin/model"
"gin-vue-admin/model/request"
"gin-vue-admin/model/response"
"gin-vue-admin/service"
"github.com/gin-gonic/gin"
"go.uber.org/zap"
)
// @Tags {{.StructName}}
@@ -21,9 +21,9 @@ import (
func Create{{.StructName}}(c *gin.Context) {
var {{.Abbreviation}} model.{{.StructName}}
_ = c.ShouldBindJSON(&{{.Abbreviation}})
err := service.Create{{.StructName}}({{.Abbreviation}})
if err != nil {
response.FailWithMessage(fmt.Sprintf("创建失败,%v", err), c)
if err := service.Create{{.StructName}}({{.Abbreviation}}); err != nil {
global.GVA_LOG.Error("创建失败!", zap.Any("err", err))
response.FailWithMessage("创建失败", c)
} else {
response.OkWithMessage("创建成功", c)
}
@@ -40,9 +40,9 @@ func Create{{.StructName}}(c *gin.Context) {
func Delete{{.StructName}}(c *gin.Context) {
var {{.Abbreviation}} model.{{.StructName}}
_ = c.ShouldBindJSON(&{{.Abbreviation}})
err := service.Delete{{.StructName}}({{.Abbreviation}})
if err != nil {
response.FailWithMessage(fmt.Sprintf("删除失败,%v", err), c)
if err := service.Delete{{.StructName}}({{.Abbreviation}}); err != nil {
global.GVA_LOG.Error("删除失败!", zap.Any("err", err))
response.FailWithMessage("删除失败", c)
} else {
response.OkWithMessage("删除成功", c)
}
@@ -54,16 +54,16 @@ func Delete{{.StructName}}(c *gin.Context) {
// @accept application/json
// @Produce application/json
// @Param data body request.IdsReq true "批量删除{{.StructName}}"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"批量删除成功"}"
// @Router /{{.Abbreviation}}/delete{{.StructName}}ByIds [delete]
func Delete{{.StructName}}ByIds(c *gin.Context) {
var IDS request.IdsReq
_ = c.ShouldBindJSON(&IDS)
err := service.Delete{{.StructName}}ByIds(IDS)
if err != nil {
response.FailWithMessage(fmt.Sprintf("删除失败,%v", err), c)
if err := service.Delete{{.StructName}}ByIds(IDS); err != nil {
global.GVA_LOG.Error("批量删除失败!", zap.Any("err", err))
response.FailWithMessage("批量删除失败", c)
} else {
response.OkWithMessage("删除成功", c)
response.OkWithMessage("批量删除成功", c)
}
}
@@ -78,9 +78,9 @@ func Delete{{.StructName}}ByIds(c *gin.Context) {
func Update{{.StructName}}(c *gin.Context) {
var {{.Abbreviation}} model.{{.StructName}}
_ = c.ShouldBindJSON(&{{.Abbreviation}})
err := service.Update{{.StructName}}(&{{.Abbreviation}})
if err != nil {
response.FailWithMessage(fmt.Sprintf("更新失败,%v", err), c)
if err := service.Update{{.StructName}}(&{{.Abbreviation}}); err != nil {
global.GVA_LOG.Error("更新失败!", zap.Any("err", err))
response.FailWithMessage("更新失败", c)
} else {
response.OkWithMessage("更新成功", c)
}
@@ -97,9 +97,9 @@ func Update{{.StructName}}(c *gin.Context) {
func Find{{.StructName}}(c *gin.Context) {
var {{.Abbreviation}} model.{{.StructName}}
_ = c.ShouldBindQuery(&{{.Abbreviation}})
err, re{{.Abbreviation}} := service.Get{{.StructName}}({{.Abbreviation}}.ID)
if err != nil {
response.FailWithMessage(fmt.Sprintf("查询失败,%v", err), c)
if err, re{{.Abbreviation}} := service.Get{{.StructName}}({{.Abbreviation}}.ID); err != nil {
global.GVA_LOG.Error("查询失败!", zap.Any("err", err))
response.FailWithMessage("查询失败", c)
} else {
response.OkWithData(gin.H{"re{{.Abbreviation}}": re{{.Abbreviation}}}, c)
}
@@ -116,15 +116,15 @@ func Find{{.StructName}}(c *gin.Context) {
func Get{{.StructName}}List(c *gin.Context) {
var pageInfo request.{{.StructName}}Search
_ = c.ShouldBindQuery(&pageInfo)
err, list, total := service.Get{{.StructName}}InfoList(pageInfo)
if err != nil {
response.FailWithMessage(fmt.Sprintf("获取数据失败,%v", err), c)
} else {
response.OkWithData(resp.PageResult{
List: list,
Total: total,
Page: pageInfo.Page,
PageSize: pageInfo.PageSize,
}, c)
}
if err, list, total := service.Get{{.StructName}}InfoList(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)
}
}
@@ -9,10 +9,10 @@ import (
type {{.StructName}} struct {
global.GVA_MODEL {{- range .Fields}}
{{- if eq .FieldType "bool" }}
{{.FieldName}} *{{.FieldType}} `json:"{{.FieldJson}}" form:"{{.FieldJson}}" gorm:"column:{{.ColumnName}};comment:{{.Comment}}{{- if .DataType -}};type:{{.DataType}}{{- if .DataTypeLong -}}({{.DataTypeLong}}){{- end -}};{{- if .DataTypeLong -}}size:{{.DataTypeLong}};{{- end -}}{{- end -}}"`
{{.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 .DataTypeLong -}}size:{{.DataTypeLong}};{{- end -}}{{- end -}}"`
{{- else }}
{{.FieldName}} {{.FieldType}} `json:"{{.FieldJson}}" form:"{{.FieldJson}}" gorm:"column:{{.ColumnName}};comment:{{.Comment}}{{- if .DataType -}};type:{{.DataType}}{{- if .DataTypeLong -}}({{.DataTypeLong}}){{- end -}};{{- if .DataTypeLong -}}size:{{.DataTypeLong}};{{- end -}}{{- end -}}"`
{{- end }} {{- end }}
{{.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 .DataTypeLong -}}size:{{.DataTypeLong}};{{- end -}}{{- end -}}"`
{{- end }} {{- end }}
}
{{ if .TableName }}
@@ -6,67 +6,66 @@ import (
"gin-vue-admin/model/request"
)
// @title Create{{.StructName}}
// @description create a {{.StructName}}
// @param {{.Abbreviation}} model.{{.StructName}}
// @auth (2020/04/05 20:22)
// @return err error
//@author: [piexlmax](https://github.com/piexlmax)
//@function: Create{{.StructName}}
//@description: 创建{{.StructName}}记录
//@param: {{.Abbreviation}} model.{{.StructName}}
//@return: err error
func Create{{.StructName}}({{.Abbreviation}} model.{{.StructName}}) (err error) {
err = global.GVA_DB.Create(&{{.Abbreviation}}).Error
return err
}
// @title Delete{{.StructName}}
// @description delete a {{.StructName}}
// @auth (2020/04/05 20:22)
// @param {{.Abbreviation}} model.{{.StructName}}
// @return error
//@author: [piexlmax](https://github.com/piexlmax)
//@function: Delete{{.StructName}}
//@description: 删除{{.StructName}}记录
//@param: {{.Abbreviation}} model.{{.StructName}}
//@return: err error
func Delete{{.StructName}}({{.Abbreviation}} model.{{.StructName}}) (err error) {
err = global.GVA_DB.Delete({{.Abbreviation}}).Error
return err
}
// @title Delete{{.StructName}}ByIds
// @description delete {{.StructName}}s
// @auth (2020/04/05 20:22)
// @param {{.Abbreviation}} model.{{.StructName}}
// @return error
//@author: [piexlmax](https://github.com/piexlmax)
//@function: Delete{{.StructName}}ByIds
//@description: 批量删除{{.StructName}}记录
//@param: ids request.IdsReq
//@return: err error
func Delete{{.StructName}}ByIds(ids request.IdsReq) (err error) {
err = global.GVA_DB.Delete(&[]model.{{.StructName}}{},"id in ?",ids.Ids).Error
return err
}
// @title Update{{.StructName}}
// @description update a {{.StructName}}
// @param {{.Abbreviation}} *model.{{.StructName}}
// @auth (2020/04/05 20:22)
// @return error
//@author: [piexlmax](https://github.com/piexlmax)
//@function: Update{{.StructName}}
//@description: 更新{{.StructName}}记录
//@param: {{.Abbreviation}} *model.{{.StructName}}
//@return: err error
func Update{{.StructName}}({{.Abbreviation}} *model.{{.StructName}}) (err error) {
err = global.GVA_DB.Save({{.Abbreviation}}).Error
return err
}
// @title Get{{.StructName}}
// @description get the info of a {{.StructName}}
// @auth (2020/04/05 20:22)
// @param id uint
// @return error
// @return {{.StructName}} {{.StructName}}
//@author: [piexlmax](https://github.com/piexlmax)
//@function: Get{{.StructName}}
//@description: 根据id获取{{.StructName}}记录
//@param: id uint
//@return: err error, {{.Abbreviation}} model.{{.StructName}}
func Get{{.StructName}}(id uint) (err error, {{.Abbreviation}} model.{{.StructName}}) {
err = global.GVA_DB.Where("id = ?", id).First(&{{.Abbreviation}}).Error
return
}
// @title Get{{.StructName}}InfoList
// @description get {{.StructName}} list by pagination, 分页获取{{.StructName}}
// @auth (2020/04/05 20:22)
// @param info PageInfo
// @return error
//@author: [piexlmax](https://github.com/piexlmax)
//@function: Get{{.StructName}}InfoList
//@description: 分页获取{{.StructName}}记录
//@param: info request.{{.StructName}}Search
//@return: err error, list interface{}, total int64
func Get{{.StructName}}InfoList(info request.{{.StructName}}Search) (err error, list interface{}, total int64) {
limit := info.PageSize
+125
View File
@@ -0,0 +1,125 @@
<template>
<div>
<el-form :model="formData" label-position="right" label-width="80px">
{{- range .Fields}}
<el-form-item label="{{.FieldDesc}}:">
{{- if eq .FieldType "bool" }}
<el-switch active-color="#13ce66" inactive-color="#ff4949" active-text="是" inactive-text="否" v-model="formData.{{.FieldJson}}" clearable ></el-switch>
{{ end -}}
{{- if eq .FieldType "string" }}
<el-input v-model="formData.{{.FieldJson}}" clearable placeholder="请输入" ></el-input>
{{ end -}}
{{- if eq .FieldType "int" }}
{{- if .DictType}}
<el-select v-model="formData.{{ .FieldJson }}" placeholder="请选择" clearable>
<el-option v-for="(item,key) in {{ .DictType }}Options" :key="key" :label="item.label" :value="item.value"></el-option>
</el-select>
{{ else -}}
<el-input v-model.number="formData.{{ .FieldJson }}" clearable placeholder="请输入"></el-input>
{{ end -}}
{{ end -}}
{{- if eq .FieldType "time.Time" }}
<el-date-picker type="date" placeholder="选择日期" v-model="formData.{{ .FieldJson }}" clearable></el-date-picker>
{{ end -}}
{{- if eq .FieldType "float64" }}
<el-input-number v-model="formData.{{ .FieldJson }}" :precision="2" clearable></el-input-number>
{{ end -}}
</el-form-item>
{{ end -}}
<el-form-item>
<el-button @click="save" type="primary">保存</el-button>
<el-button @click="back" type="primary">返回</el-button>
</el-form-item>
</el-form>
</div>
</template>
<script>
import {
create{{.StructName}},
update{{.StructName}},
find{{.StructName}}
} from "@/api/{{.PackageName}}"; // 此处请自行替换地址
import infoList from "@/mixins/infoList";
export default {
name: "{{.StructName}}",
mixins: [infoList],
data() {
return {
type: "",
{{- range .Fields}}
{{- if .DictType }}
{{ .DictType }}Options:[],
{{ end -}}
{{end -}}
formData: {
{{range .Fields}}
{{- if eq .FieldType "bool" -}}
{{.FieldJson}}:false,
{{ end -}}
{{- if eq .FieldType "string" -}}
{{.FieldJson}}:"",
{{ end -}}
{{- if eq .FieldType "int" -}}
{{.FieldJson}}:0,
{{ end -}}
{{- if eq .FieldType "time.Time" -}}
{{.FieldJson}}:new Date(),
{{ end -}}
{{- if eq .FieldType "float64" -}}
{{.FieldJson}}:0,
{{ end -}}
{{ end }}
}
};
},
methods: {
async save() {
let res;
switch (this.type) {
case "create":
res = await create{{.StructName}}(this.formData);
break;
case "update":
res = await update{{.StructName}}(this.formData);
break;
default:
res = await create{{.StructName}}(this.formData);
break;
}
if (res.code == 0) {
this.$message({
type:"success",
message:"创建/更改成功"
})
}
},
back(){
this.$router.go(-1)
}
},
async created() {
// 建议通过url传参获取目标数据ID 调用 find方法进行查询数据操作 从而决定本页面是create还是update 以下为id作为url参数示例
if(this.$route.query.id){
const res = await find{{.StructName}}({ ID: this.$route.query.id })
if(res.code == 0){
this.formData = res.data.re{{.Abbreviation}}
this.type == "update"
}
}else{
this.type == "create"
}
{{ range .Fields -}}
{{- if .DictType }}
await this.getDict("{{.DictType}}");
{{ end -}}
{{- end }}
}
};
</script>
<style>
</style>
@@ -136,7 +136,7 @@ import {
find{{.StructName}},
get{{.StructName}}List
} from "@/api/{{.PackageName}}"; // 此处请自行替换地址
import { formatTimeToStr } from "@/utils/data";
import { formatTimeToStr } from "@/utils/date";
import infoList from "@/mixins/infoList";
export default {
name: "{{.StructName}}",
@@ -149,11 +149,13 @@ export default {
type: "",
deleteVisible: false,
multipleSelection: [],
{{- range .Fields}}
{{- if .DictType }}
{{ .DictType }}Options:[],
{{ end -}}
{{end -}}
formData: {
{{range .Fields}}
{{- if eq .FieldType "bool" -}}
@@ -208,6 +210,13 @@ export default {
},
async onDelete() {
const ids = []
if(this.multipleSelection.length == 0){
this.$message({
type: 'warning',
message: '请选择要删除的数据'
})
return
}
this.multipleSelection &&
this.multipleSelection.map(item => {
ids.push(item.ID)
+2 -3
View File
@@ -9,12 +9,11 @@ import (
func InitAutoCodeRouter(Router *gin.RouterGroup) {
AutoCodeRouter := Router.Group("autoCode").
Use(middleware.JWTAuth()).
Use(middleware.CasbinHandler()).
Use(middleware.OperationRecord())
Use(middleware.CasbinHandler())
{
AutoCodeRouter.POST("createTemp", v1.CreateTemp) // 创建自动化代码
AutoCodeRouter.GET("getTables", v1.GetTables) // 获取对应数据库的表
AutoCodeRouter.GET("getDB", v1.GetDB) // 获取数据库
AutoCodeRouter.GET("getColume", v1.GetColume) // 获取指定表所有字段信息
AutoCodeRouter.GET("getColumn", v1.GetColumn) // 获取指定表所有字段信息
}
}
+15 -23
View File
@@ -7,15 +7,11 @@ import (
"gorm.io/gorm"
)
// @title FindOrCreateFile
// @description Check your file if it does not exist, or return current slice of the file
// 上传文件时检测当前文件属性,如果没有文件则创建,有则返回文件的当前切片
// @auth (2020/04/05 20:22)
// @param fileMd5 string
// @param fileName string
// @param chunkTotal int
// @return err error
// @return file ExaFile
//@author: [piexlmax](https://github.com/piexlmax)
//@function: FindOrCreateFile
//@description: 上传文件时检测当前文件属性,如果没有文件则创建,有则返回文件的当前切片
//@param: fileMd5 string, fileName string, chunkTotal int
//@return: err error, file model.ExaFile
func FindOrCreateFile(fileMd5 string, fileName string, chunkTotal int) (err error, file model.ExaFile) {
var cfile model.ExaFile
@@ -33,13 +29,11 @@ func FindOrCreateFile(fileMd5 string, fileName string, chunkTotal int) (err erro
return err, cfile
}
// @title CreateFileChunk
// @description create a chunk of the file, 创建文件切片记录
// @auth (2020/04/05 20:22)
// @param id unit
// @param fileChunkPath string
// @param fileChunkNumber int
// @return error
//@author: [piexlmax](https://github.com/piexlmax)
//@function: CreateFileChunk
//@description: 创建文件切片记录
//@param: id uint, fileChunkPath string, fileChunkNumber int
//@return: error
func CreateFileChunk(id uint, fileChunkPath string, fileChunkNumber int) error {
var chunk model.ExaFileChunk
@@ -50,13 +44,11 @@ func CreateFileChunk(id uint, fileChunkPath string, fileChunkNumber int) error {
return err
}
// @title DeleteFileChunk
// @description delete a chuck of the file, 删除文件切片记录
// @auth (2020/04/05 20:22)
// @param FileMd5 string
// @param FileName string
// @param FilePath string
// @return error
//@author: [piexlmax](https://github.com/piexlmax)
//@function: DeleteFileChunk
//@description: 删除文件切片记录
//@param: fileMd5 string, fileName string, filePath string
//@return: error
func DeleteFileChunk(fileMd5 string, fileName string, filePath string) error {
var chunks []model.ExaFileChunk
+25 -27
View File
@@ -6,57 +6,55 @@ import (
"gin-vue-admin/model/request"
)
// @title CreateExaCustomer
// @description create a customer, 创建用户
// @param e model.ExaCustomer
// @auth (2020/04/05 20:22)
// @return err error
//@author: [piexlmax](https://github.com/piexlmax)
//@function: CreateExaCustomer
//@description: 创建客户
//@param: e model.ExaCustomer
//@return: err error
func CreateExaCustomer(e model.ExaCustomer) (err error) {
err = global.GVA_DB.Create(&e).Error
return err
}
// @title DeleteFileChunk
// @description delete a customer, 删除用户
// @auth (2020/04/05 20:22)
// @param e model.ExaCustomer
// @return error
//@author: [piexlmax](https://github.com/piexlmax)
//@function: DeleteFileChunk
//@description: 删除客户
//@param: e model.ExaCustomer
//@return: err error
func DeleteExaCustomer(e model.ExaCustomer) (err error) {
err = global.GVA_DB.Delete(e).Error
return err
}
// @title UpdateExaCustomer
// @description update a customer, 更新用户
// @param e *model.ExaCustomer
// @auth (2020/04/05 20:22)
// @return error
//@author: [piexlmax](https://github.com/piexlmax)
//@function: UpdateExaCustomer
//@description: 更新客户
//@param: e *model.ExaCustomer
//@return: err error
func UpdateExaCustomer(e *model.ExaCustomer) (err error) {
err = global.GVA_DB.Save(e).Error
return err
}
// @title GetExaCustomer
// @description get the info of a costumer , 获取用户信息
// @auth (2020/04/05 20:22)
// @param id uint
// @return error
// @return customer ExaCustomer
//@author: [piexlmax](https://github.com/piexlmax)
//@function: GetExaCustomer
//@description: 获取客户信息
//@param: id uint
//@return: err error, customer model.ExaCustomer
func GetExaCustomer(id uint) (err error, customer model.ExaCustomer) {
err = global.GVA_DB.Where("id = ?", id).First(&customer).Error
return
}
// @title GetCustomerInfoList
// @description get customer list by pagination, 分页获取用户列表
// @auth (2020/04/05 20:22)
// @param sysUserAuthorityID string
// @param info PageInfo
// @return error
//@author: [piexlmax](https://github.com/piexlmax)
//@function: GetCustomerInfoList
//@description: 分页获取客户列表
//@param: sysUserAuthorityID string, info request.PageInfo
//@return: err error, list interface{}, total int64
func GetCustomerInfoList(sysUserAuthorityID string, info request.PageInfo) (err error, list interface{}, total int64) {
limit := info.PageSize
+26 -31
View File
@@ -10,22 +10,21 @@ import (
"strings"
)
// @title Upload
// @description 创建文件上传记录
// @param file model.ExaFileUploadAndDownload
// @auth (2020/04/05 20:22)
// @return error
//@author: [piexlmax](https://github.com/piexlmax)
//@function: Upload
//@description: 创建文件上传记录
//@param: file model.ExaFileUploadAndDownload
//@return: error
func Upload(file model.ExaFileUploadAndDownload) error {
err := global.GVA_DB.Create(&file).Error
return err
return global.GVA_DB.Create(&file).Error
}
// @title FindFile
// @description 删除文件切片记录
// @auth (2020/04/05 20:22)
// @param id uint
// @return error
//@author: [piexlmax](https://github.com/piexlmax)
//@function: FindFile
//@description: 删除文件切片记录
//@param: id uint
//@return: error, model.ExaFileUploadAndDownload
func FindFile(id uint) (error, model.ExaFileUploadAndDownload) {
var file model.ExaFileUploadAndDownload
@@ -33,11 +32,11 @@ func FindFile(id uint) (error, model.ExaFileUploadAndDownload) {
return err, file
}
// @title DeleteFile
// @description 删除文件记录
// @auth (2020/04/05 20:22)
// @param file model.ExaFileUploadAndDownload
// @return error
//@author: [piexlmax](https://github.com/piexlmax)
//@function: DeleteFile
//@description: 删除文件记录
//@param: file model.ExaFileUploadAndDownload
//@return: err error
func DeleteFile(file model.ExaFileUploadAndDownload) (err error) {
var fileFromDb model.ExaFileUploadAndDownload
@@ -50,13 +49,11 @@ func DeleteFile(file model.ExaFileUploadAndDownload) (err error) {
return err
}
// @title GetFileRecordInfoList
// @description 分页获取数据
// @auth (2020/04/05 20:22)
// @param info PageInfo
// @return err error
// @return list error
// @return total error
//@author: [piexlmax](https://github.com/piexlmax)
//@function: GetFileRecordInfoList
//@description: 分页获取数据
//@param: info request.PageInfo
//@return: err error, list interface{}, total int64
func GetFileRecordInfoList(info request.PageInfo) (err error, list interface{}, total int64) {
limit := info.PageSize
@@ -68,13 +65,11 @@ func GetFileRecordInfoList(info request.PageInfo) (err error, list interface{},
return err, fileLists, total
}
// @title UploadFile
// @description 根据配置文件判断是文件上传到本地或者七牛云
// @auth (2020/04/05 20:22)
// @param header *multipart.FileHeader
// @param noSave string
// @return err error
// @return file file model.ExaFileUploadAndDownload
//@author: [piexlmax](https://github.com/piexlmax)
//@function: UploadFile
//@description: 根据配置文件判断是文件上传到本地或者七牛云
//@param: header *multipart.FileHeader, noSave string
//@return: err error, file model.ExaFileUploadAndDownload
func UploadFile(header *multipart.FileHeader, noSave string) (err error, file model.ExaFileUploadAndDownload) {
oss := upload.NewOss()
+40 -26
View File
@@ -11,19 +11,34 @@ import (
"strconv"
)
// 保存文件切片路径
//@author: [piexlmax](https://github.com/piexlmax)
//@function: SaveChunk
//@description: 保存文件切片路径
//@param: uploader model.ExaSimpleUploader
//@return: err error
func SaveChunk(uploader model.ExaSimpleUploader) (err error) {
return global.GVA_DB.Create(uploader).Error
}
// 检查文件是否已经上传过
//@author: [piexlmax](https://github.com/piexlmax)
//@function: CheckFileMd5
//@description: 检查文件是否已经上传过
//@param: md5 string
//@return: err error, uploads []model.ExaSimpleUploader, isDone bool
func CheckFileMd5(md5 string) (err error, uploads []model.ExaSimpleUploader, isDone bool) {
err = global.GVA_DB.Find(&uploads, "identifier = ? AND is_done = ?", md5, false).Error
isDone = errors.Is(global.GVA_DB.First(&model.ExaSimpleUploader{}, "identifier = ? AND is_done = ?", md5, true).Error, gorm.ErrRecordNotFound)
return err, uploads, !isDone
}
// 合并文件
//@author: [piexlmax](https://github.com/piexlmax)
//@function: MergeFileMd5
//@description: 合并文件
//@param: md5 string, fileName string
//@return: err error
func MergeFileMd5(md5 string, fileName string) (err error) {
finishDir := "./finish/"
dir := "./chunk/" + md5
@@ -51,27 +66,26 @@ func MergeFileMd5(md5 string, fileName string) (err error) {
if err != nil {
return err
}
//创建事务
tx := global.GVA_DB.Begin()
//删除切片信息
err = tx.Delete(&model.ExaSimpleUploader{}, "identifier = ? AND is_done = ?", md5, false).Error
// 添加文件信息
if err != nil {
fmt.Println(err)
tx.Rollback()
}
err = tx.Create(&model.ExaSimpleUploader{
Identifier: md5,
IsDone: true,
FilePath: finishDir + fileName,
Filename: fileName,
}).Error
if err != nil {
fmt.Println(err)
tx.Rollback()
}
tx.Commit()
//清除切片
err = os.RemoveAll(dir)
return
err = global.GVA_DB.Transaction(func(tx *gorm.DB) error {
//删除切片信息
if err = tx.Delete(&model.ExaSimpleUploader{}, "identifier = ? AND is_done = ?", md5, false).Error; err != nil {
fmt.Println(err)
return err
}
data := model.ExaSimpleUploader{
Identifier: md5,
IsDone: true,
FilePath: finishDir + fileName,
Filename: fileName,
}
// 添加文件信息
if err = tx.Create(&data).Error; err != nil {
fmt.Println(err)
return err
}
return nil
})
err = os.RemoveAll(dir) //清除切片
return err
}
+20 -23
View File
@@ -8,47 +8,44 @@ import (
"time"
)
// @title JsonInBlacklist
// @description create jwt blacklist
// @param jwtList model.JwtBlacklist
// @auth (2020/04/05 20:22)
// @return err error
//@author: [piexlmax](https://github.com/piexlmax)
//@function: JsonInBlacklist
//@description: 拉黑jwt
//@param: jwtList model.JwtBlacklist
//@return: err error
func JsonInBlacklist(jwtList model.JwtBlacklist) (err error) {
err = global.GVA_DB.Create(&jwtList).Error
return
}
// @title IsBlacklist
// @description check if the Jwt is in the blacklist or not, 判断JWT是否在黑名单内部
// @auth (2020/04/05 20:22)
// @param jwt string
// @param jwtList model.JwtBlacklist
// @return err error
//@author: [piexlmax](https://github.com/piexlmax)
//@function: IsBlacklist
//@description: 判断JWT是否在黑名单内部
//@param: jwt string
//@return: bool
func IsBlacklist(jwt string) bool {
isNotFound := errors.Is(global.GVA_DB.Where("jwt = ?", jwt).First(&model.JwtBlacklist{}).Error, gorm.ErrRecordNotFound)
return !isNotFound
}
// @title GetRedisJWT
// @description Get user info in redis
// @auth (2020/04/05 20:22)
// @param userName string
// @return err error
// @return redisJWT string
//@author: [piexlmax](https://github.com/piexlmax)
//@function: GetRedisJWT
//@description: 从redis取jwt
//@param: userName string
//@return: err error, redisJWT string
func GetRedisJWT(userName string) (err error, redisJWT string) {
redisJWT, err = global.GVA_REDIS.Get(userName).Result()
return err, redisJWT
}
// @title SetRedisJWT
// @description set jwt into the Redis
// @auth (2020/04/05 20:22)
// @param jwtList model.JwtBlacklist
// @param userName string
// @return err error
//@author: [piexlmax](https://github.com/piexlmax)
//@function: SetRedisJWT
//@description: jwt存入redis并设置过期时间
//@param: userName string
//@return: err error, redisJWT string
func SetRedisJWT(jwt string, userName string) (err error) {
// 此处过期时间等于jwt过期时间
+51 -39
View File
@@ -8,25 +8,24 @@ import (
"gorm.io/gorm"
)
// @title CreateApi
// @description create base apis, 新增基础api
// @auth (2020/04/05 20:22)
// @param api model.SysApi
// @return error
//@author: [piexlmax](https://github.com/piexlmax)
//@function: CreateApi
//@description: 新增基础api
//@param: api model.SysApi
//@return: err error
func CreateApi(api model.SysApi) (err error) {
if !errors.Is(global.GVA_DB.Where("path = ? AND method = ?", api.Path, api.Method).First(&model.SysApi{}).Error, gorm.ErrRecordNotFound) {
return errors.New("存在相同api")
}
return global.GVA_DB.Create(&api).Error
}
// @title DeleteApi
// @description delete a base api, 删除基础api
// @param api model.SysApi
// @auth (2020/04/05 20:22)
// @return error
//@author: [piexlmax](https://github.com/piexlmax)
//@function: DeleteApi
//@description: 删除基础api
//@param: api model.SysApi
//@return: err error
func DeleteApi(api model.SysApi) (err error) {
err = global.GVA_DB.Delete(api).Error
@@ -34,16 +33,33 @@ func DeleteApi(api model.SysApi) (err error) {
return err
}
// @title GetInfoList
// @description get apis by pagination, 分页获取数据
// @auth (2020/04/05 20:22)
// @param api model.SysApi
// @param info request.PageInfo
// @param order string
// @param desc bool
// @return err error
// @return list interface{}
// @return total int
//@author: [piexlmax](https://github.com/piexlmax)
//@function: CreateApi
//@description: 自动创建api数据,
//@param: api model.SysApi
//@return: err error
func AutoCreateApi(api model.SysApi) (err error) {
err = global.GVA_DB.Transaction(func(tx *gorm.DB) error {
var fApi model.SysApi
var txErr error
fxErr := tx.Where("path = ? AND method = ?", api.Path, api.Method).First(&fApi).Error
if errors.Is(fxErr, gorm.ErrRecordNotFound) {
txErr = tx.Create(&api).Error
if txErr != nil{
return txErr
}
}
return nil
})
return err
}
//@author: [piexlmax](https://github.com/piexlmax)
//@function: GetAPIInfoList
//@description: 分页获取数据,
//@param: api model.SysApi, info request.PageInfo, order string, desc bool
//@return: err error
func GetAPIInfoList(api model.SysApi, info request.PageInfo, order string, desc bool) (err error, list interface{}, total int64) {
limit := info.PageSize
@@ -88,40 +104,36 @@ func GetAPIInfoList(api model.SysApi, info request.PageInfo, order string, desc
return err, apiList, total
}
// @title GetAllApis
// @description get all apis, 获取所有的api
// @auth (2020/04/05 20:22)
// @return err error
// @return apis []SysApi
//@author: [piexlmax](https://github.com/piexlmax)
//@function: GetAllApis
//@description: 获取所有的api
//@return: err error, apis []model.SysApi
func GetAllApis() (err error, apis []model.SysApi) {
err = global.GVA_DB.Find(&apis).Error
return
}
// @title GetApiById
// @description 根据id获取api
// @auth (2020/04/05 20:22)
// @param api model.SysApi
// @param id float64
// @return error
//@author: [piexlmax](https://github.com/piexlmax)
//@function: GetApiById
//@description: 根据id获取api
//@param: id float64
//@return: err error, api model.SysApi
func GetApiById(id float64) (err error, api model.SysApi) {
err = global.GVA_DB.Where("id = ?", id).First(&api).Error
return
}
// @title UpdateApi
// @description update a base api, update api
// @auth (2020/04/05 20:22)
// @param api model.SysApi
// @return error
//@author: [piexlmax](https://github.com/piexlmax)
//@function: UpdateApi
//@description: 根据id更新api
//@param: api model.SysApi
//@return: err error
func UpdateApi(api model.SysApi) (err error) {
var oldA model.SysApi
err = global.GVA_DB.Where("id = ?", api.ID).First(&oldA).Error
if oldA.Path != api.Path || oldA.Method != api.Method {
if !errors.Is(global.GVA_DB.Where("path = ? AND method = ?", api.Path, api.Method).First(&model.SysApi{}).Error, gorm.ErrRecordNotFound) {
return errors.New("存在相同api路径")
+46 -52
View File
@@ -10,12 +10,11 @@ import (
"strconv"
)
// @title CreateAuthority
// @description 创建一个角色
// @auth (2020/04/05 20:22)
// @param auth model.SysAuthority
// @return error
// @return authority model.SysAuthority
//@author: [piexlmax](https://github.com/piexlmax)
//@function: CreateAuthority
//@description: 创建一个角色
//@param: auth model.SysAuthority
//@return: err error, authority model.SysAuthority
func CreateAuthority(auth model.SysAuthority) (err error, authority model.SysAuthority) {
var authorityBox model.SysAuthority
@@ -26,12 +25,11 @@ func CreateAuthority(auth model.SysAuthority) (err error, authority model.SysAut
return err, auth
}
// @title CopyAuthority
// @description 复制一个角色
// @auth (2020/04/05 20:22)
// @param copyInfo response.SysAuthorityCopyResponse
// @return error
// @return authority model.SysAuthority
//@author: [piexlmax](https://github.com/piexlmax)
//@function: CopyAuthority
//@description: 复制一个角色
//@param: copyInfo response.SysAuthorityCopyResponse
//@return: err error, authority model.SysAuthority
func CopyAuthority(copyInfo response.SysAuthorityCopyResponse) (err error, authority model.SysAuthority) {
var authorityBox model.SysAuthority
@@ -39,7 +37,7 @@ func CopyAuthority(copyInfo response.SysAuthorityCopyResponse) (err error, autho
return errors.New("存在相同角色id"), authority
}
copyInfo.Authority.Children = []model.SysAuthority{}
err, menus := GetMenuAuthority(copyInfo.OldAuthorityId)
err, menus := GetMenuAuthority(&request.GetAuthorityId{AuthorityId: copyInfo.OldAuthorityId})
var baseMenu []model.SysBaseMenu
for _, v := range menus {
intNum, _ := strconv.Atoi(v.MenuId)
@@ -57,24 +55,22 @@ func CopyAuthority(copyInfo response.SysAuthorityCopyResponse) (err error, autho
return err, copyInfo.Authority
}
// @title UpdateAuthority
// @description 更改一个角色
// @auth (2020/04/05 20:22)
// @param auth model.SysAuthority
// @return error
// @return authority model.SysAuthority
//@author: [piexlmax](https://github.com/piexlmax)
//@function: UpdateAuthority
//@description: 更改一个角色
//@param: auth model.SysAuthority
//@return:err error, authority model.SysAuthority
func UpdateAuthority(auth model.SysAuthority) (err error, authority model.SysAuthority) {
err = global.GVA_DB.Where("authority_id = ?", auth.AuthorityId).First(&model.SysAuthority{}).Updates(&auth).Error
return err, auth
}
// @title DeleteAuthority
// @description 删除角色
// @auth (2020/04/05 20:22)
// @param auth model.SysAuthority
// @return error
// 删除角色
//@author: [piexlmax](https://github.com/piexlmax)
//@function: DeleteAuthority
//@description: 删除角色
//@param: auth *model.SysAuthority
//@return: err error
func DeleteAuthority(auth *model.SysAuthority) (err error) {
if !errors.Is(global.GVA_DB.Where("authority_id = ?", auth.AuthorityId).First(&model.SysUser{}).Error, gorm.ErrRecordNotFound) {
@@ -95,12 +91,11 @@ func DeleteAuthority(auth *model.SysAuthority) (err error) {
return err
}
// @title GetInfoList
// @description 删除文件切片记录
// @auth (2020/04/05 20:22)
// @param info request.PaveInfo
// @return error
// 分页获取数据
//@author: [piexlmax](https://github.com/piexlmax)
//@function: GetAuthorityInfoList
//@description: 分页获取数据
//@param: info request.PageInfo
//@return: err error, list interface{}, total int64
func GetAuthorityInfoList(info request.PageInfo) (err error, list interface{}, total int64) {
limit := info.PageSize
@@ -116,23 +111,22 @@ func GetAuthorityInfoList(info request.PageInfo) (err error, list interface{}, t
return err, authority, total
}
// @title GetAuthorityInfo
// @description 获取所有角色信息
// @auth (2020/04/05 20:22)
// @param auth model.SysAuthority
// @return error
// @param authority model.SysAuthority
//@author: [piexlmax](https://github.com/piexlmax)
//@function: GetAuthorityInfo
//@description: 获取所有角色信息
//@param: auth model.SysAuthority
//@return: err error, sa model.SysAuthority
func GetAuthorityInfo(auth model.SysAuthority) (err error, sa model.SysAuthority) {
err = global.GVA_DB.Preload("DataAuthorityId").Where("authority_id = ?", auth.AuthorityId).First(&sa).Error
return err, sa
}
// @title SetDataAuthority
// @description 设置角色资源权限
// @auth (2020/04/05 20:22)
// @param auth model.SysAuthority
// @return error
//@author: [piexlmax](https://github.com/piexlmax)
//@function: SetDataAuthority
//@description: 设置角色资源权限
//@param: auth model.SysAuthority
//@return:error
func SetDataAuthority(auth model.SysAuthority) error {
var s model.SysAuthority
@@ -141,11 +135,11 @@ func SetDataAuthority(auth model.SysAuthority) error {
return err
}
// @title SetMenuAuthority
// @description 菜单与角色绑定
// @auth (2020/04/05 20:22)
// @param auth *model.SysAuthority
// @return error
//@author: [piexlmax](https://github.com/piexlmax)
//@function: SetMenuAuthority
//@description: 菜单与角色绑定
//@param: auth *model.SysAuthority
//@return: error
func SetMenuAuthority(auth *model.SysAuthority) error {
var s model.SysAuthority
@@ -154,11 +148,11 @@ func SetMenuAuthority(auth *model.SysAuthority) error {
return err
}
// @title findChildrenAuthority
// @description 查询子角色
// @auth (2020/04/05 20:22)
// @param auth *model.SysAuthority
// @return error
//@author: [piexlmax](https://github.com/piexlmax)
//@function: findChildrenAuthority
//@description: 查询子角色
//@param: authority *model.SysAuthority
//@return: err error
func findChildrenAuthority(authority *model.SysAuthority) (err error) {
err = global.GVA_DB.Preload("DataAuthorityId").Where("parent_id = ?", authority.AuthorityId).Find(&authority.Children).Error
+96 -21
View File
@@ -1,27 +1,31 @@
package service
import (
"errors"
"fmt"
"gin-vue-admin/global"
"gin-vue-admin/model"
"gin-vue-admin/model/request"
"gin-vue-admin/utils"
"io/ioutil"
"os"
"path/filepath"
"strings"
"text/template"
)
type tplData struct {
template *template.Template
locationPath string
autoCodePath string
template *template.Template
locationPath string
autoCodePath string
autoMoveFilePath string
}
// @title CreateTemp
// @description 函数的详细描述
// @auth (2020/04/05 20:22)
// @param autoCode model.AutoCodeStruct
// @return err error
//@author: [piexlmax](https://github.com/piexlmax)
//@function: CreateTemp
//@description: 创建代码
//@param: model.AutoCodeStruct
//@return: error
func CreateTemp(autoCode model.AutoCodeStruct) (err error) {
basePath := "resource/template"
@@ -46,7 +50,7 @@ func CreateTemp(autoCode model.AutoCodeStruct) (err error) {
}
// 生成文件路径,填充 autoCodePath 字段,readme.txt.tpl不符合规则,需要特殊处理
// resource/template/fe/api.js.tpl -> autoCode/fe/autoCode.PackageName/api/autoCode.PackageName.js
// 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 {
@@ -88,19 +92,36 @@ func CreateTemp(autoCode model.AutoCodeStruct) (err error) {
_ = f.Close()
}
// 生成压缩包
if err := utils.ZipFiles("./ginvueadmin.zip", fileList, ".", "."); err != nil {
return err
}
// 移除中间文件
if err := os.RemoveAll(autoPath); err != nil {
return err
defer func() { // 移除中间文件
if err := os.RemoveAll(autoPath); err != nil {
return
}
}()
if autoCode.AutoMoveFile { // 判断是否需要自动转移
for index, _ := range dataList {
addAutoMoveFile(&dataList[index])
}
for _, value := range dataList { // 移动文件
if err := utils.FileMove(value.autoCodePath, value.autoMoveFilePath); err != nil {
fmt.Println(err)
return err
}
}
return errors.New("创建代码成功并移动文件成功")
} else { // 打包
if err := utils.ZipFiles("./ginvueadmin.zip", fileList, ".", "."); err != nil {
return err
}
}
return nil
}
// GetAllTplFile 用来获取 pathName 文件夹下所有 tpl 文件
//@author: [piexlmax](https://github.com/piexlmax)
//@function: GetAllTplFile
//@description: 获取 pathName 文件夹下所有 tpl 文件
//@param: pathName string, fileList []string
//@return: []string, error
func GetAllTplFile(pathName string, fileList []string) ([]string, error) {
files, err := ioutil.ReadDir(pathName)
for _, fi := range files {
@@ -118,17 +139,71 @@ func GetAllTplFile(pathName string, fileList []string) ([]string, error) {
return fileList, err
}
//@author: [piexlmax](https://github.com/piexlmax)
//@function: GetTables
//@description: 获取数据库的所有表名
//@param: pathName string
//@param: fileList []string
//@return: []string, error
func 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
}
//@author: [piexlmax](https://github.com/piexlmax)
//@function: GetDB
//@description: 获取数据库的所有数据库名
//@param: pathName string
//@param: fileList []string
//@return: []string, error
func 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
}
func GetColume(tableName string, dbName string) (err error, Columes []request.ColumeReq) {
err = global.GVA_DB.Raw("SELECT COLUMN_NAME colume_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 colume_comment FROM INFORMATION_SCHEMA.COLUMNS c WHERE table_name = ? AND table_schema = ?", tableName, dbName).Scan(&Columes).Error
return err, Columes
//@author: [piexlmax](https://github.com/piexlmax)
//@function: GetDB
//@description: 获取指定数据库和指定数据表的所有字段名,类型值等
//@param: pathName string
//@param: fileList []string
//@return: []string, error
func 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
}
//@author: [SliverHorn](https://github.com/SliverHorn)
//@author: [songzhibin97](https://github.com/songzhibin97)
//@function: addAutoMoveFile
//@description: 生成对应的迁移文件路径
//@param: *tplData
//@return: null
func addAutoMoveFile(data *tplData) {
dir := filepath.Base(filepath.Dir(data.autoCodePath))
base := filepath.Base(data.autoCodePath)
if strings.Contains(data.autoCodePath, "server") {
if strings.Contains(data.autoCodePath, "router") {
data.autoMoveFilePath = filepath.Join(dir, base)
} else if strings.Contains(data.autoCodePath, "api") {
data.autoMoveFilePath = filepath.Join(dir, "v1", base)
} else if strings.Contains(data.autoCodePath, "service") {
data.autoMoveFilePath = filepath.Join(dir, base)
} else if strings.Contains(data.autoCodePath, "model") {
data.autoMoveFilePath = filepath.Join(dir, base)
} else if strings.Contains(data.autoCodePath, "request") {
data.autoMoveFilePath = filepath.Join("model", dir, base)
}
} else if strings.Contains(data.autoCodePath, "web") {
if strings.Contains(data.autoCodePath, "js") {
data.autoMoveFilePath = filepath.Join("../", "web", "src", dir, base)
} else if strings.Contains(data.autoCodePath, "form") {
data.autoMoveFilePath = filepath.Join("../", "web", "src", "view", filepath.Base(filepath.Dir(filepath.Dir(data.autoCodePath))), strings.TrimSuffix(base, filepath.Ext(base))+"From.vue")
} else if strings.Contains(data.autoCodePath, "table") {
data.autoMoveFilePath = filepath.Join("../", "web", "src", "view", filepath.Base(filepath.Dir(filepath.Dir(data.autoCodePath))), base)
}
}
}
+45 -23
View File
@@ -7,11 +7,11 @@ import (
"gorm.io/gorm"
)
// @title DeleteBaseMenu
// @description 删除基础路由
// @auth (2020/04/05 20:22)
// @param id float64
// @return err error
//@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
@@ -30,11 +30,11 @@ func DeleteBaseMenu(id float64) (err error) {
return err
}
// @title UpdateBaseMenu
// @description 更新路由
// @auth (2020/04/05 20:22)
// @param menu model.SysBaseMenu
// @return err errorgetMenu
//@author: [piexlmax](https://github.com/piexlmax)
//@function: UpdateBaseMenu
//@description: 更新路由
//@param: menu model.SysBaseMenu
//@return:err error
func UpdateBaseMenu(menu model.SysBaseMenu) (err error) {
var oldMenu model.SysBaseMenu
@@ -50,23 +50,45 @@ func UpdateBaseMenu(menu model.SysBaseMenu) (err error) {
upDateMap["icon"] = menu.Icon
upDateMap["sort"] = menu.Sort
db := global.GVA_DB.Where("id = ?", menu.ID).Find(&oldMenu)
if oldMenu.Name != menu.Name {
if !errors.Is(global.GVA_DB.Where("id <> ? AND name = ?", menu.ID, menu.Name).First(&model.SysBaseMenu{}).Error, gorm.ErrRecordNotFound) {
global.GVA_LOG.Debug("存在相同name修改失败")
return errors.New("存在相同name修改失败")
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) {
global.GVA_LOG.Debug("存在相同name修改失败")
return errors.New("存在相同name修改失败")
}
}
}
err = global.GVA_DB.Delete(&model.SysBaseMenuParameter{}, "sys_base_menu_id = ?", menu.ID).Error
err = db.Updates(upDateMap).Error
err = tx.Delete(&model.SysBaseMenuParameter{}, "sys_base_menu_id = ?", menu.ID).Error
if err != nil {
global.GVA_LOG.Debug(err.Error())
return err
}
if len(menu.Parameters) > 0 {
for k, _ := range menu.Parameters {
menu.Parameters[k].SysBaseMenuID = menu.ID
}
err = tx.Create(&menu.Parameters).Error
if err != nil {
global.GVA_LOG.Debug(err.Error())
return err
}
}
err = db.Updates(upDateMap).Error
if err != nil {
global.GVA_LOG.Debug(err.Error())
return err
}
return nil
})
return err
}
// @title GetBaseMenuById
// @description get current menus, 返回当前选中menu
// @auth (2020/04/05 20:22)
// @param id float64
// @return err error
//@author: [piexlmax](https://github.com/piexlmax)
//@function: GetBaseMenuById
//@description: 返回当前选中menu
//@param: id float64
//@return: err error, menu model.SysBaseMenu
func GetBaseMenuById(id float64) (err error, menu model.SysBaseMenu) {
err = global.GVA_DB.Preload("Parameters").Where("id = ?", id).First(&menu).Error
+35 -40
View File
@@ -12,12 +12,11 @@ import (
"strings"
)
// @title UpdateCasbin
// @description update casbin authority, 更新casbin权限
// @auth (2020/04/05 20:22)
// @param authorityId string
// @param casbinInfos []CasbinInfo
// @return error
//@author: [piexlmax](https://github.com/piexlmax)
//@function: UpdateCasbin
//@description: 更新casbin权限
//@param: authorityId string, casbinInfos []request.CasbinInfo
//@return: error
func UpdateCasbin(authorityId string, casbinInfos []request.CasbinInfo) error {
ClearCasbin(0, authorityId)
@@ -39,14 +38,11 @@ func UpdateCasbin(authorityId string, casbinInfos []request.CasbinInfo) error {
return nil
}
// @title UpdateCasbinApi
// @description update casbin apis, API更新随动
// @auth (2020/04/05 20:22)
// @param oldPath string
// @param newPath string
// @param oldMethod string
// @param newMethod string
// @return error
//@author: [piexlmax](https://github.com/piexlmax)
//@function: UpdateCasbinApi
//@description: API更新随动
//@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{}{
@@ -56,11 +52,12 @@ func UpdateCasbinApi(oldPath string, newPath string, oldMethod string, newMethod
return err
}
// @title GetPolicyPathByAuthorityId
// @description get policy path by authorityId, 获取权限列表
// @auth (2020/04/05 20:22)
// @param authorityId string
// @return []string
//@author: [piexlmax](https://github.com/piexlmax)
//@function: GetPolicyPathByAuthorityId
//@description: 获取权限列表
//@param: authorityId string
//@return: pathMaps []request.CasbinInfo
func GetPolicyPathByAuthorityId(authorityId string) (pathMaps []request.CasbinInfo) {
e := Casbin()
@@ -74,12 +71,11 @@ func GetPolicyPathByAuthorityId(authorityId string) (pathMaps []request.CasbinIn
return pathMaps
}
// @title ClearCasbin
// @description 清除匹配的权限
// @auth (2020/04/05 20:22)
// @param v int
// @param p string
// @return bool
//@author: [piexlmax](https://github.com/piexlmax)
//@function: ClearCasbin
//@description: 清除匹配的权限
//@param: v int, p ...string
//@return: bool
func ClearCasbin(v int, p ...string) bool {
e := Casbin()
@@ -88,9 +84,10 @@ func ClearCasbin(v int, p ...string) bool {
}
// @title Casbin
// @description store to DB, 持久化到数据库 引入自定义规则
// @auth (2020/04/05 20:22)
//@author: [piexlmax](https://github.com/piexlmax)
//@function: Casbin
//@description: 持久化到数据库 引入自定义规则
//@return: *casbin.Enforcer
func Casbin() *casbin.Enforcer {
admin := global.GVA_CONFIG.Mysql
@@ -101,12 +98,11 @@ func Casbin() *casbin.Enforcer {
return e
}
// @title ParamsMatch
// @description customized rule, 自定义规则函数
// @auth (2020/04/05 20:22)
// @param fullNameKey1 string
// @param key2 string
// @return bool
//@author: [piexlmax](https://github.com/piexlmax)
//@function: ParamsMatch
//@description: 自定义规则函数
//@param: fullNameKey1 string, key2 string
//@return: bool
func ParamsMatch(fullNameKey1 string, key2 string) bool {
key1 := strings.Split(fullNameKey1, "?")[0]
@@ -114,12 +110,11 @@ func ParamsMatch(fullNameKey1 string, key2 string) bool {
return util.KeyMatch2(key1, key2)
}
// @title ParamsMatchFunc
// @description customized function, 自定义规则函数
// @auth (2020/04/05 20:22)
// @param args ...interface{}
// @return interface{}
// @return error
//@author: [piexlmax](https://github.com/piexlmax)
//@function: ParamsMatchFunc
//@description: 自定义规则函数
//@param: args ...interface{}
//@return: interface{}, error
func ParamsMatchFunc(args ...interface{}) (interface{}, error) {
name1 := args[0].(string)
+26 -26
View File
@@ -8,11 +8,11 @@ import (
"gorm.io/gorm"
)
// @title CreateSysDictionary
// @description create a SysDictionary
// @param sysDictionary model.SysDictionary
// @auth (2020/04/05 20:22)
// @return err error
//@author: [piexlmax](https://github.com/piexlmax)
//@function: DeleteSysDictionary
//@description: 创建字典数据
//@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)) {
@@ -22,22 +22,22 @@ func CreateSysDictionary(sysDictionary model.SysDictionary) (err error) {
return err
}
// @title DeleteSysDictionary
// @description delete a SysDictionary
// @auth (2020/04/05 20:22)
// @param sysDictionary model.SysDictionary
// @return error
//@author: [piexlmax](https://github.com/piexlmax)
//@function: DeleteSysDictionary
//@description: 删除字典数据
//@param: sysDictionary model.SysDictionary
//@return: err error
func DeleteSysDictionary(sysDictionary model.SysDictionary) (err error) {
err = global.GVA_DB.Delete(sysDictionary).Delete(&sysDictionary.SysDictionaryDetails).Error
return err
}
// @title UpdateSysDictionary
// @description update a SysDictionary
// @param sysDictionary *model.SysDictionary
// @auth (2020/04/05 20:22)
// @return error
//@author: [piexlmax](https://github.com/piexlmax)
//@function: UpdateSysDictionary
//@description: 更新字典数据
//@param: sysDictionary *model.SysDictionary
//@return: err error
func UpdateSysDictionary(sysDictionary *model.SysDictionary) (err error) {
var dict model.SysDictionary
@@ -60,23 +60,23 @@ func UpdateSysDictionary(sysDictionary *model.SysDictionary) (err error) {
return err
}
// @title GetSysDictionary
// @description get the info of a SysDictionary
// @auth (2020/04/05 20:22)
// @param id uint
// @return error
// @return SysDictionary SysDictionary
//@author: [piexlmax](https://github.com/piexlmax)
//@function: GetSysDictionary
//@description: 根据id或者type获取字典单条数据
//@param: Type string, Id uint
//@return: err error, sysDictionary model.SysDictionary
func GetSysDictionary(Type string, Id uint) (err error, sysDictionary model.SysDictionary) {
err = global.GVA_DB.Where("type = ? OR id = ?", Type, Id).Preload("SysDictionaryDetails").First(&sysDictionary).Error
return
}
// @title GetSysDictionaryInfoList
// @description get SysDictionary list by pagination, 分页获取用户列表
// @auth (2020/04/05 20:22)
// @param info PageInfo
// @return error
//@author: [piexlmax](https://github.com/piexlmax)
//@author: [SliverHorn](https://github.com/SliverHorn)
//@function: GetSysDictionaryInfoList
//@description: 分页获取字典列表
//@param: info request.SysDictionarySearch
//@return: err error, list interface{}, total int64
func GetSysDictionaryInfoList(info request.SysDictionarySearch) (err error, list interface{}, total int64) {
limit := info.PageSize
+25 -26
View File
@@ -6,56 +6,55 @@ import (
"gin-vue-admin/model/request"
)
// @title CreateSysDictionaryDetail
// @description create a SysDictionaryDetail
// @param sysDictionaryDetail model.SysDictionaryDetail
// @auth (2020/04/05 20:22)
// @return err error
//@author: [piexlmax](https://github.com/piexlmax)
//@function: CreateSysDictionaryDetail
//@description: 创建字典详情数据
//@param: sysDictionaryDetail model.SysDictionaryDetail
//@return: err error
func CreateSysDictionaryDetail(sysDictionaryDetail model.SysDictionaryDetail) (err error) {
err = global.GVA_DB.Create(&sysDictionaryDetail).Error
return err
}
// @title DeleteSysDictionaryDetail
// @description delete a SysDictionaryDetail
// @auth (2020/04/05 20:22)
// @param sysDictionaryDetail model.SysDictionaryDetail
// @return error
//@author: [piexlmax](https://github.com/piexlmax)
//@function: DeleteSysDictionaryDetail
//@description: 删除字典详情数据
//@param: sysDictionaryDetail model.SysDictionaryDetail
//@return: err error
func DeleteSysDictionaryDetail(sysDictionaryDetail model.SysDictionaryDetail) (err error) {
err = global.GVA_DB.Delete(sysDictionaryDetail).Error
return err
}
// @title UpdateSysDictionaryDetail
// @description update a SysDictionaryDetail
// @param sysDictionaryDetail *model.SysDictionaryDetail
// @auth (2020/04/05 20:22)
// @return error
//@author: [piexlmax](https://github.com/piexlmax)
//@function: UpdateSysDictionaryDetail
//@description: 更新字典详情数据
//@param: sysDictionaryDetail *model.SysDictionaryDetail
//@return: err error
func UpdateSysDictionaryDetail(sysDictionaryDetail *model.SysDictionaryDetail) (err error) {
err = global.GVA_DB.Save(sysDictionaryDetail).Error
return err
}
// @title GetSysDictionaryDetail
// @description get the info of a SysDictionaryDetail
// @auth (2020/04/05 20:22)
// @param id uint
// @return error
// @return SysDictionaryDetail SysDictionaryDetail
//@author: [piexlmax](https://github.com/piexlmax)
//@function: GetSysDictionaryDetail
//@description: 根据id获取字典详情单条数据
//@param: id uint
//@return: err error, sysDictionaryDetail model.SysDictionaryDetail
func GetSysDictionaryDetail(id uint) (err error, sysDictionaryDetail model.SysDictionaryDetail) {
err = global.GVA_DB.Where("id = ?", id).First(&sysDictionaryDetail).Error
return
}
// @title GetSysDictionaryDetailInfoList
// @description get SysDictionaryDetail list by pagination, 分页获取用户列表
// @auth (2020/04/05 20:22)
// @param info PageInfo
// @return error
//@author: [piexlmax](https://github.com/piexlmax)
//@function: GetSysDictionaryDetailInfoList
//@description: 分页获取字典详情列表
//@param: info request.SysDictionaryDetailSearch
//@return: err error
func GetSysDictionaryDetailInfoList(info request.SysDictionaryDetailSearch) (err error, list interface{}, total int64) {
limit := info.PageSize
+4 -4
View File
@@ -4,10 +4,10 @@ import (
"gin-vue-admin/utils"
)
// @title EmailTest
// @description 发送邮件测试
// @auth (2020/09/08 13:58
// @return err error
//@author: [maplepie](https://github.com/maplepie)
//@function: EmailTest
//@description: 发送邮件测试
//@return: err error
func EmailTest() (err error) {
subject := "test"
+50 -59
View File
@@ -4,15 +4,16 @@ import (
"errors"
"gin-vue-admin/global"
"gin-vue-admin/model"
"gin-vue-admin/model/request"
"gorm.io/gorm"
"strconv"
)
// @title getMenuTreeMap
// @description 获取路由总树map
// @auth qm (2020/05/06 10:26)
// @return err error
// @return menusMsp map{string}[]SysBaseMenu
//@author: [piexlmax](https://github.com/piexlmax)
//@function: getMenuTreeMap
//@description: 获取路由总树map
//@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
@@ -24,12 +25,11 @@ func getMenuTreeMap(authorityId string) (err error, treeMap map[string][]model.S
return err, treeMap
}
// @title GetMenuTree
// @description 获取动态菜单树
// @auth (2020/04/05 20:22)
// @param authorityId string
// @return err error
// @return menus []model.SysMenu
//@author: [piexlmax](https://github.com/piexlmax)
//@function: GetMenuTree
//@description: 获取动态菜单树
//@param: authorityId string
//@return: err error, menus []model.SysMenu
func GetMenuTree(authorityId string) (err error, menus []model.SysMenu) {
err, menuTree := getMenuTreeMap(authorityId)
@@ -40,12 +40,11 @@ func GetMenuTree(authorityId string) (err error, menus []model.SysMenu) {
return err, menus
}
// @title getChildrenList
// @description 获取子菜单
// @auth (2020/04/05 20:22)
// @param menu *model.SysMenu
// @param sql string
// @return err error
//@author: [piexlmax](https://github.com/piexlmax)
//@function: getChildrenList
//@description: 获取子菜单
//@param: menu *model.SysMenu, treeMap map[string][]model.SysMenu
//@return: err error
func getChildrenList(menu *model.SysMenu, treeMap map[string][]model.SysMenu) (err error) {
menu.Children = treeMap[menu.MenuId]
@@ -55,13 +54,10 @@ func getChildrenList(menu *model.SysMenu, treeMap map[string][]model.SysMenu) (e
return err
}
// @title GetInfoList
// @description 获取路由分页
// @auth (2020/04/05 20:22)
// @param info request.PageInfo
// @return err error
// @return list interface{}
// @return total int
//@author: [piexlmax](https://github.com/piexlmax)
//@function: GetInfoList
//@description: 获取路由分页
//@return: err error, list interface{}, total int64
func GetInfoList() (err error, list interface{}, total int64) {
var menuList []model.SysBaseMenu
@@ -73,11 +69,11 @@ func GetInfoList() (err error, list interface{}, total int64) {
return err, menuList, total
}
// @title getBaseChildrenList
// @description get children of menu, 获取菜单的子菜单
// @auth (2020/04/05 20:22)
// @param menu *model.SysBaseMenu
// @return err error
//@author: [piexlmax](https://github.com/piexlmax)
//@function: getBaseChildrenList
//@description: 获取菜单的子菜单
//@param: menu *model.SysBaseMenu, treeMap map[string][]model.SysBaseMenu
//@return: err error
func getBaseChildrenList(menu *model.SysBaseMenu, treeMap map[string][]model.SysBaseMenu) (err error) {
menu.Children = treeMap[strconv.Itoa(int(menu.ID))]
@@ -87,12 +83,11 @@ func getBaseChildrenList(menu *model.SysBaseMenu, treeMap map[string][]model.Sys
return err
}
// @title AddBaseMenu
// @description 函数的详细描述
// @auth (2020/04/05 20:22)
// @param menu *model.SysBaseMenu
// @return err error
// 增加基础路由
//@author: [piexlmax](https://github.com/piexlmax)
//@function: AddBaseMenu
//@description: 添加基础路由
//@param: menu model.SysBaseMenu
//@return: err error
func AddBaseMenu(menu model.SysBaseMenu) (err error) {
if !errors.Is(global.GVA_DB.Where("name = ?", menu.Name).First(&model.SysBaseMenu{}).Error, gorm.ErrRecordNotFound) {
@@ -102,11 +97,10 @@ func AddBaseMenu(menu model.SysBaseMenu) (err error) {
return err
}
// @title getBaseMenuTreeMap
// @description 获取路由总树map
// @auth qm (2020/05/06 10:26)
// @return err error
// @return menusMsp map{string}[]SysBaseMenu
//@author: [piexlmax](https://github.com/piexlmax)
//@function: getBaseMenuTreeMap
//@description: 获取路由总树map
//@return: err error, treeMap map[string][]model.SysBaseMenu
func getBaseMenuTreeMap() (err error, treeMap map[string][]model.SysBaseMenu) {
var allMenus []model.SysBaseMenu
@@ -118,11 +112,10 @@ func getBaseMenuTreeMap() (err error, treeMap map[string][]model.SysBaseMenu) {
return err, treeMap
}
// @title GetBaseMenuTree
// @description 获取基础路由树
// @auth (2020/04/05 20:22)
// @return err error
// @return menus []SysBaseMenu
//@author: [piexlmax](https://github.com/piexlmax)
//@function: GetBaseMenuTree
//@description: 获取基础路由树
//@return: err error, menus []model.SysBaseMenu
func GetBaseMenuTree() (err error, menus []model.SysBaseMenu) {
err, treeMap := getBaseMenuTreeMap()
@@ -133,12 +126,11 @@ func GetBaseMenuTree() (err error, menus []model.SysBaseMenu) {
return err, menus
}
// @title AddMenuAuthority
// @description 为角色增加menu树
// @auth (2020/04/05 20:22)
// @param menus []model.SysBaseMenu
// @param authorityId string
// @return error
//@author: [piexlmax](https://github.com/piexlmax)
//@function: AddMenuAuthority
//@description: 为角色增加menu树
//@param: menus []model.SysBaseMenu, authorityId string
//@return: err error
func AddMenuAuthority(menus []model.SysBaseMenu, authorityId string) (err error) {
var auth model.SysAuthority
@@ -148,16 +140,15 @@ func AddMenuAuthority(menus []model.SysBaseMenu, authorityId string) (err error)
return err
}
// @title GetMenuAuthority
// @description 查看当前角色树
// @auth (2020/04/05 20:22)
// @param authorityId string
// @return err error
// @return menus []SysBaseMenu
//@author: [piexlmax](https://github.com/piexlmax)
//@function: GetMenuAuthority
//@description: 查看当前角色树
//@param: info *request.GetAuthorityId
//@return: err error, menus []model.SysMenu
func GetMenuAuthority(authorityId string) (err error, menus []model.SysMenu) {
func GetMenuAuthority(info *request.GetAuthorityId) (err error, menus []model.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.Where("authority_id = ? ", authorityId).Order("sort").Find(&menus).Error
//err = global.GVA_DB.Raw(sql, authorityId).Scan(&menus).Error
return err, menus
}
+27 -26
View File
@@ -6,56 +6,57 @@ import (
"gin-vue-admin/model/request"
)
// @title CreateSysOperationRecord
// @description create a SysOperationRecord
// @param sysOperationRecord model.SysOperationRecord
// @auth (2020/04/05 20:22)
// @return err error
//@author: [granty1](https://github.com/granty1)
//@function: CreateSysOperationRecord
//@description: 创建记录
//@param: sysOperationRecord model.SysOperationRecord
//@return: err error
func CreateSysOperationRecord(sysOperationRecord model.SysOperationRecord) (err error) {
err = global.GVA_DB.Create(&sysOperationRecord).Error
return err
}
// @title DeleteSysOperationRecord
// @description delete SysOperationRecords
// @auth (2020/04/05 20:22)
// @param sysOperationRecord request.IdsReq
// @return error
//@author: [granty1](https://github.com/granty1)
//@author: [piexlmax](https://github.com/piexlmax)
//@function: DeleteSysOperationRecordByIds
//@description: 批量删除记录
//@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
return err
}
// @title DeleteSysOperationRecord
// @description delete a SysOperationRecord
// @auth (2020/04/05 20:22)
// @param sysOperationRecord model.SysOperationRecord
// @return error
//@author: [granty1](https://github.com/granty1)
//@function: DeleteSysOperationRecord
//@description: 删除操作记录
//@param: sysOperationRecord model.SysOperationRecord
//@return: err error
func DeleteSysOperationRecord(sysOperationRecord model.SysOperationRecord) (err error) {
err = global.GVA_DB.Delete(sysOperationRecord).Error
return err
}
// @title GetSysOperationRecord
// @description get the info of a SysOperationRecord
// @auth (2020/04/05 20:22)
// @param id uint
// @return error
// @return SysOperationRecord SysOperationRecord
//@author: [granty1](https://github.com/granty1)
//@function: DeleteSysOperationRecord
//@description: 根据id获取单条操作记录
//@param: id uint
//@return: err error, sysOperationRecord model.SysOperationRecord
func GetSysOperationRecord(id uint) (err error, sysOperationRecord model.SysOperationRecord) {
err = global.GVA_DB.Where("id = ?", id).First(&sysOperationRecord).Error
return
}
// @title GetSysOperationRecordInfoList
// @description get SysOperationRecord list by pagination, 分页获取用户列表
// @auth (2020/04/05 20:22)
// @param info PageInfo
// @return error
//@author: [granty1](https://github.com/granty1)
//@author: [piexlmax](https://github.com/piexlmax)
//@function: GetSysOperationRecordInfoList
//@description: 分页获取操作记录列表
//@param: info request.SysOperationRecordSearch
//@return: err error, list interface{}, total int64
func GetSysOperationRecordInfoList(info request.SysOperationRecordSearch) (err error, list interface{}, total int64) {
limit := info.PageSize
+14 -16
View File
@@ -8,21 +8,21 @@ import (
"go.uber.org/zap"
)
// @title GetSystemConfig
// @description 读取配置文件
// @auth (2020/04/05 20:22)
// @return err error
// @return conf Server
//@author: [piexlmax](https://github.com/piexlmax)
//@function: GetSystemConfig
//@description: 读取配置文件
//@return: err error, conf config.Server
func GetSystemConfig() (err error, conf config.Server) {
return nil, global.GVA_CONFIG
}
// @title SetSystemConfig
// @description set system config, 设置配置文件
// @auth (2020/04/05 20:22)
// @param system model.System
// @return err error
// @description set system config,
//@author: [piexlmax](https://github.com/piexlmax)
//@function: SetSystemConfig
//@description: 设置配置文件
//@param: system model.System
//@return: err error
func SetSystemConfig(system model.System) (err error) {
cs := utils.StructToMap(system.Config)
@@ -33,12 +33,10 @@ func SetSystemConfig(system model.System) (err error) {
return err
}
// @title GetServerInfo
// @description get server info , 获取服务器信息
// @auth (2020/04/05 20:22)
// @return server *utils.Server
// @return err error
//@author: [SliverHorn](https://github.com/SliverHorn)
//@function: GetServerInfo
//@description: 获取服务器信息
//@return: server *utils.Server, err error
func GetServerInfo() (server *utils.Server, err error) {
var s utils.Server
+46 -56
View File
@@ -10,12 +10,12 @@ import (
"gorm.io/gorm"
)
// @title Register
// @description register, 用户注册
// @auth (2020/04/05 20:22)
// @param u model.SysUser
// @return err error
// @return userInter *SysUser
//@author: [piexlmax](https://github.com/piexlmax)
//@function: Register
//@description: 用户注册
//@param: u model.SysUser
//@return: err error, userInter model.SysUser
func Register(u model.SysUser) (err error, userInter model.SysUser) {
var user model.SysUser
@@ -29,12 +29,11 @@ func Register(u model.SysUser) (err error, userInter model.SysUser) {
return err, u
}
// @title Login
// @description login, 用户登录
// @auth (2020/04/05 20:22)
// @param u *model.SysUser
// @return err error
// @return userInter *SysUser
//@author: [piexlmax](https://github.com/piexlmax)
//@function: Login
//@description: 用户登录
//@param: u *model.SysUser
//@return: err error, userInter *model.SysUser
func Login(u *model.SysUser) (err error, userInter *model.SysUser) {
var user model.SysUser
@@ -43,13 +42,11 @@ func Login(u *model.SysUser) (err error, userInter *model.SysUser) {
return err, &user
}
// @title ChangePassword
// @description change the password of a certain user, 修改用户密码
// @auth (2020/04/05 20:22)
// @param u *model.SysUser
// @param newPassword string
// @return err error
// @return userInter *SysUser
//@author: [piexlmax](https://github.com/piexlmax)
//@function: ChangePassword
//@description: 修改用户密码
//@param: u *model.SysUser, newPassword string
//@return: err error, userInter *model.SysUser
func ChangePassword(u *model.SysUser, newPassword string) (err error, userInter *model.SysUser) {
var user model.SysUser
@@ -58,13 +55,11 @@ func ChangePassword(u *model.SysUser, newPassword string) (err error, userInter
return err, u
}
// @title GetInfoList
// @description get user list by pagination, 分页获取数据
// @auth (2020/04/05 20:22)
// @param info request.PageInfo
// @return err error
// @return list interface{}
// @return total int
//@author: [piexlmax](https://github.com/piexlmax)
//@function: GetUserInfoList
//@description: 分页获取数据
//@param: info request.PageInfo
//@return: err error, list interface{}, total int64
func GetUserInfoList(info request.PageInfo) (err error, list interface{}, total int64) {
limit := info.PageSize
@@ -76,24 +71,22 @@ func GetUserInfoList(info request.PageInfo) (err error, list interface{}, total
return err, userList, total
}
// @title SetUserAuthority
// @description set the authority of a certain user, 设置一个用户的权限
// @auth (2020/04/05 20:22)
// @param uuid UUID
// @param authorityId string
// @return err error
//@author: [piexlmax](https://github.com/piexlmax)
//@function: SetUserAuthority
//@description: 设置一个用户的权限
//@param: uuid uuid.UUID, authorityId string
//@return: err error
func SetUserAuthority(uuid uuid.UUID, authorityId string) (err error) {
err = global.GVA_DB.Where("uuid = ?", uuid).First(&model.SysUser{}).Update("authority_id", authorityId).Error
return err
}
// @title SetUserAuthority
// @description set the authority of a certain user, 设置一个用户的权限
// @auth (2020/04/05 20:22)
// @param uuid UUID
// @param authorityId string
// @return err error
//@author: [piexlmax](https://github.com/piexlmax)
//@function: DeleteUser
//@description: 删除用户
//@param: id float64
//@return: err error
func DeleteUser(id float64) (err error) {
var user model.SysUser
@@ -101,24 +94,22 @@ func DeleteUser(id float64) (err error) {
return err
}
// @title SetUserInfo
// @description set the authority of a certain user, 设置用户信息
// @auth (2020/04/05 20:22)
// @param uuid UUID
// @param authorityId string
// @return err error
//@author: [piexlmax](https://github.com/piexlmax)
//@function: SetUserInfo
//@description: 设置用户信息
//@param: reqUser model.SysUser
//@return: err error, user model.SysUser
func SetUserInfo(reqUser model.SysUser) (err error, user model.SysUser) {
err = global.GVA_DB.Updates(&reqUser).Error
return err, reqUser
}
// @title FindUserById
// @description Get user information by id, 通过id获取用户信息
// @auth (2020/04/05 20:22)
// @param id int
// @return err error
// @return user *model.SysUser
//@author: [SliverHorn](https://github.com/SliverHorn)
//@function: FindUserById
//@description: 通过id获取用户信息
//@param: id int
//@return: err error, user *model.SysUser
func FindUserById(id int) (err error, user *model.SysUser) {
var u model.SysUser
@@ -126,12 +117,11 @@ func FindUserById(id int) (err error, user *model.SysUser) {
return err, &u
}
// @title FindUserByUuid
// @description Get user information by uuid, 通过uuid获取用户信息
// @auth (2020/04/05 20:22)
// @param uuid string
// @return err error
// @return user *model.SysUser
//@author: [SliverHorn](https://github.com/SliverHorn)
//@function: FindUserByUuid
//@description: 通过uuid获取用户信息
//@param: uuid string
//@return: err error, user *model.SysUser
func FindUserByUuid(uuid string) (err error, user *model.SysUser) {
var u model.SysUser
+17
View File
@@ -0,0 +1,17 @@
package service
import (
"gin-vue-admin/global"
"gin-vue-admin/model"
)
//@author: [piexlmax](https://github.com/piexlmax)
//@function: Create
//@description: 创建工作流
//@param: wk model.SysWorkflow
//@return: error
func Create(wk model.SysWorkflow) error {
err := global.GVA_DB.Create(&wk).Error
return err
}
+38
View File
@@ -0,0 +1,38 @@
package utils
import (
"os"
"path/filepath"
)
// FileMove: 文件移动供外部调用
// src: 源位置 绝对路径相对路径都可以
// dst: 目标位置 绝对路径相对路径都可以 dst 必须为文件夹
func FileMove(src string, dst string) (err error) {
if dst == "" {
return nil
}
src, err = filepath.Abs(src)
if err != nil {
return err
}
dst, err = filepath.Abs(dst)
if err != nil {
return err
}
var revoke = false
dir := filepath.Dir(dst)
Redirect:
_, err = os.Stat(dir)
if err != nil {
err = os.MkdirAll(dir, 0755)
if err != nil {
return err
}
if !revoke {
revoke = true
goto Redirect
}
}
return os.Rename(src, dst)
}
+21
View File
@@ -0,0 +1,21 @@
package utils
var (
IdVerify = Rules{"ID": {NotEmpty()}}
ApiVerify = Rules{"Path": {NotEmpty()}, "Description": {NotEmpty()}, "ApiGroup": {NotEmpty()}, "Method": {NotEmpty()}}
MenuVerify = Rules{"Path": {NotEmpty()}, "ParentId": {NotEmpty()}, "Name": {NotEmpty()}, "Component": {NotEmpty()}, "Sort": {Ge("0")}}
MenuMetaVerify = Rules{"Title": {NotEmpty()}}
LoginVerify = Rules{"CaptchaId": {NotEmpty()}, "Captcha": {NotEmpty()}, "Username": {NotEmpty()}, "Password": {NotEmpty()}}
SetUserVerify = Rules{"ID": {NotEmpty()}, "Username": {NotEmpty()}, "NickName": {NotEmpty()}, "HeaderImg": {NotEmpty()}}
RegisterVerify = Rules{"Username": {NotEmpty()}, "NickName": {NotEmpty()}, "Password": {NotEmpty()}, "AuthorityId": {NotEmpty()}}
PageInfoVerify = Rules{"Page": {NotEmpty()}, "PageSize": {NotEmpty()}}
CustomerVerify = Rules{"CustomerName": {NotEmpty()}, "CustomerPhoneData": {NotEmpty()}}
AutoCodeVerify = Rules{"Abbreviation": {NotEmpty()}, "StructName": {NotEmpty()}, "PackageName": {NotEmpty()}, "Fields": {NotEmpty()}}
WorkFlowVerify = Rules{"WorkflowNickName": {NotEmpty()}, "WorkflowName": {NotEmpty()}, "WorkflowDescription": {NotEmpty()}, "WorkflowStepInfo": {NotEmpty()}}
AuthorityVerify = Rules{"AuthorityId": {NotEmpty()}, "AuthorityName": {NotEmpty()}, "ParentId": {NotEmpty()}}
DictionaryVerify = Rules{"Type": {NotEmpty()}, "ID": {NotEmpty()}}
AuthorityIdVerify = Rules{"AuthorityId": {NotEmpty()}}
OldAuthorityVerify = Rules{"OldAuthorityId": {NotEmpty()}}
ChangePasswordVerify = Rules{"Username": {NotEmpty()}, "Password": {NotEmpty()}, "NewPassword": {NotEmpty()}}
SetUserAuthorityVerify = Rules{"UUID": {NotEmpty()}, "AuthorityId": {NotEmpty()}}
)