Merge branch 'develop' into develop

This commit is contained in:
奇淼(piexlmax
2020-11-25 02:55:43 -06:00
committed by GitHub
138 changed files with 5601 additions and 4694 deletions
+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
@@ -54,27 +69,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过期时间
+29 -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,11 @@ 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: 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 +82,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
+157 -21
View File
@@ -1,27 +1,32 @@
package service
import (
"errors"
"fmt"
"gin-vue-admin/global"
"gin-vue-admin/model"
"gin-vue-admin/model/request"
"gin-vue-admin/utils"
"gorm.io/gorm"
"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 +51,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 +93,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 +140,131 @@ 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))+"Form.vue")
} else if strings.Contains(data.autoCodePath, "table") {
data.autoMoveFilePath = filepath.Join("../", "web", "src", "view", filepath.Base(filepath.Dir(filepath.Dir(data.autoCodePath))), base)
}
}
}
//@author: [piexlmax](https://github.com/piexlmax)
//@author: [SliverHorn](https://github.com/SliverHorn)
//@function: CreateApi
//@description: 自动创建api数据,
//@param: a *model.AutoCodeStruct
//@return: error
func AutoCreateApi(a *model.AutoCodeStruct) (err error) {
var apiList = []model.SysApi{
{
Path: "/" + a.Abbreviation + "/" + "create" + a.StructName,
Description: "新增" + a.Description,
ApiGroup: a.Abbreviation,
Method: "POST",
},
{
Path: "/" + a.Abbreviation + "/" + "delete" + a.StructName,
Description: "删除" + a.Description,
ApiGroup: a.Abbreviation,
Method: "DELETE",
},
{
Path: "/" + a.Abbreviation + "/" + "delete" + a.StructName + "ByIds",
Description: "批量删除" + a.Description,
ApiGroup: a.Abbreviation,
Method: "DELETE",
},
{
Path: "/" + a.Abbreviation + "/" + "update" + a.StructName,
Description: "更新" + a.Description,
ApiGroup: a.Abbreviation,
Method: "PUT",
},
{
Path: "/" + a.Abbreviation + "/" + "find" + a.StructName,
Description: "根据ID获取" + a.Description,
ApiGroup: a.Abbreviation,
Method: "GET",
},
{
Path: "/" + a.Abbreviation + "/" + "get" + a.StructName + "List",
Description: "获取" + a.Description + "列表",
ApiGroup: a.Abbreviation,
Method: "GET",
},
}
err = global.GVA_DB.Transaction(func(tx *gorm.DB) error {
for _, v := range apiList {
var api model.SysApi
if errors.Is(tx.Where("path = ? AND method = ?", v.Path, v.Method).First(&api).Error, gorm.ErrRecordNotFound) {
if err := tx.Create(&v).Error; err != nil { // 遇到错误时回滚事务
return err
}
}
}
return nil
})
return err
}
+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
txErr := tx.Unscoped().Delete(&model.SysBaseMenuParameter{}, "sys_base_menu_id = ?", menu.ID).Error
if txErr != nil {
global.GVA_LOG.Debug(txErr.Error())
return txErr
}
if len(menu.Parameters) > 0 {
for k, _ := range menu.Parameters {
menu.Parameters[k].SysBaseMenuID = menu.ID
}
txErr = tx.Create(&menu.Parameters).Error
if txErr != nil {
global.GVA_LOG.Debug(txErr.Error())
return txErr
}
}
txErr = db.Updates(upDateMap).Error
if txErr != nil {
global.GVA_LOG.Debug(txErr.Error())
return txErr
}
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
+5 -5
View File
@@ -5,11 +5,11 @@ import (
"gin-vue-admin/model"
)
// @title Create
// @description create a workflow, 创建工作流
// @auth (2020/04/05 20:22)
// @param wk model.SysWorkflow
// @return error
//@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