Browse Source

correct all comments of functions in service

main
rainyan 5 years ago
parent
commit
5d871db828
  1. 2
      server/go.mod
  2. 41
      server/service/exa_breakpoint_continue.go
  3. 5
      server/service/exa_customer.go
  4. 11
      server/service/exa_file_upload_download.go
  5. 26
      server/service/jwt_black_list.go
  6. 60
      server/service/sys_api.go
  7. 66
      server/service/sys_authority.go
  8. 41
      server/service/sys_auto_code.go
  9. 6
      server/service/sys_base_menu.go
  10. 4
      server/service/sys_casbin.go
  11. 16
      server/service/sys_menu.go
  12. 5
      server/service/sys_system.go
  13. 5
      server/service/sys_user.go
  14. 1
      server/service/sys_workflow.go

2
server/go.mod

@ -28,7 +28,7 @@ require (
github.com/onsi/gomega v1.4.3 // indirect github.com/onsi/gomega v1.4.3 // indirect
github.com/op/go-logging v0.0.0-20160315200505-970db520ece7 github.com/op/go-logging v0.0.0-20160315200505-970db520ece7
github.com/pelletier/go-toml v1.6.0 // indirect github.com/pelletier/go-toml v1.6.0 // indirect
github.com/pkg/errors v0.9.1
github.com/pkg/errors v0.9.1 // indirect
github.com/qiniu/api.v7 v7.2.5+incompatible github.com/qiniu/api.v7 v7.2.5+incompatible
github.com/qiniu/x v7.0.8+incompatible // indirect github.com/qiniu/x v7.0.8+incompatible // indirect
github.com/satori/go.uuid v1.2.0 github.com/satori/go.uuid v1.2.0

41
server/service/exa_breakpoint_continue.go

@ -9,19 +9,19 @@ import (
// @description Check your file if it does not exist, or return current slice of the file // @description Check your file if it does not exist, or return current slice of the file
// 上传文件时检测当前文件属性,如果没有文件则创建,有则返回文件的当前切片 // 上传文件时检测当前文件属性,如果没有文件则创建,有则返回文件的当前切片
// @auth (2020/04/05 20:22) // @auth (2020/04/05 20:22)
// @param FileMd5 string
// @param FileName string
// @param ChunkTotal int
// @param fileMd5 string
// @param fileName string
// @param chunkTotal int
// @return err error // @return err error
// @return file ExaFile // @return file ExaFile
func FindOrCreateFile(FileMd5 string, FileName string, ChunkTotal int) (err error, file model.ExaFile) {
func FindOrCreateFile(fileMd5 string, fileName string, chunkTotal int) (err error, file model.ExaFile) {
var cfile model.ExaFile var cfile model.ExaFile
cfile.FileMd5 = FileMd5
cfile.FileName = FileName
cfile.ChunkTotal = ChunkTotal
notHaveSameMd5Finish := global.GVA_DB.Where("file_md5 = ? AND is_finish = ?", FileMd5, true).First(&file).RecordNotFound()
cfile.FileMd5 = fileMd5
cfile.FileName = fileName
cfile.ChunkTotal = chunkTotal
notHaveSameMd5Finish := global.GVA_DB.Where("file_md5 = ? AND is_finish = ?", fileMd5, true).First(&file).RecordNotFound()
if notHaveSameMd5Finish { if notHaveSameMd5Finish {
err = global.GVA_DB.Where("file_md5 = ? AND file_name = ?", FileMd5, FileName).Preload("ExaFileChunk").FirstOrCreate(&file, cfile).Error
err = global.GVA_DB.Where("file_md5 = ? AND file_name = ?", fileMd5, fileName).Preload("ExaFileChunk").FirstOrCreate(&file, cfile).Error
return err, file return err, file
} else { } else {
cfile.IsFinish = true cfile.IsFinish = true
@ -35,14 +35,15 @@ func FindOrCreateFile(FileMd5 string, FileName string, ChunkTotal int) (err err
// @title CreateFileChunk // @title CreateFileChunk
// @description create a chunk of the file, 创建文件切片记录 // @description create a chunk of the file, 创建文件切片记录
// @auth (2020/04/05 20:22) // @auth (2020/04/05 20:22)
// @param FileChunkPath string
// @param FileChunkNumber int
// @param id unit
// @param fileChunkPath string
// @param fileChunkNumber int
// @return error // @return error
func CreateFileChunk(id uint, FileChunkPath string, FileChunkNumber int) error {
func CreateFileChunk(id uint, fileChunkPath string, fileChunkNumber int) error {
var chunk model.ExaFileChunk var chunk model.ExaFileChunk
chunk.FileChunkPath = FileChunkPath
chunk.FileChunkPath = fileChunkPath
chunk.ExaFileId = id chunk.ExaFileId = id
chunk.FileChunkNumber = FileChunkNumber
chunk.FileChunkNumber = fileChunkNumber
err := global.GVA_DB.Create(&chunk).Error err := global.GVA_DB.Create(&chunk).Error
return err return err
} }
@ -50,16 +51,16 @@ func CreateFileChunk(id uint, FileChunkPath string, FileChunkNumber int) error {
// @title FileCreateComplete // @title FileCreateComplete
// @description file creation, 文件合成完成 // @description file creation, 文件合成完成
// @auth (2020/04/05 20:22) // @auth (2020/04/05 20:22)
// @param FileMd5 string
// @param FileName string
// @param FilePath string
// @param fileMd5 string
// @param fileName string
// @param filePath string
// @return error // @return error
func FileCreateComplete(FileMd5 string, FileName string, FilePath string) error {
func FileCreateComplete(fileMd5 string, fileName string, filePath string) error {
var file model.ExaFile var file model.ExaFile
upDateFile := make(map[string]interface{}) upDateFile := make(map[string]interface{})
upDateFile["FilePath"] = FilePath
upDateFile["FilePath"] = filePath
upDateFile["IsFinish"] = true upDateFile["IsFinish"] = true
err := global.GVA_DB.Where("file_md5 = ? AND file_name = ?", FileMd5, FileName).First(&file).Updates(upDateFile).Error
err := global.GVA_DB.Where("file_md5 = ? AND file_name = ?", fileMd5, fileName).First(&file).Updates(upDateFile).Error
return err return err
} }

5
server/service/exa_customer.go

@ -8,6 +8,7 @@ import (
// @title CreateExaCustomer // @title CreateExaCustomer
// @description create a customer, 创建用户 // @description create a customer, 创建用户
// @param e model.ExaCustomer
// @auth (2020/04/05 20:22) // @auth (2020/04/05 20:22)
// @return err error // @return err error
func CreateExaCustomer(e model.ExaCustomer) (err error) { func CreateExaCustomer(e model.ExaCustomer) (err error) {
@ -18,6 +19,7 @@ func CreateExaCustomer(e model.ExaCustomer) (err error) {
// @title DeleteFileChunk // @title DeleteFileChunk
// @description delete a customer, 删除用户 // @description delete a customer, 删除用户
// @auth (2020/04/05 20:22) // @auth (2020/04/05 20:22)
// @param e *model.ExaCustomer
// @return error // @return error
func DeleteExaCustomer(e model.ExaCustomer) (err error) { func DeleteExaCustomer(e model.ExaCustomer) (err error) {
err = global.GVA_DB.Delete(e).Error err = global.GVA_DB.Delete(e).Error
@ -26,6 +28,7 @@ func DeleteExaCustomer(e model.ExaCustomer) (err error) {
// @title UpdateExaCustomer // @title UpdateExaCustomer
// @description update a customer, 更新用户 // @description update a customer, 更新用户
// @param e *model.ExaCustomer
// @auth (2020/04/05 20:22) // @auth (2020/04/05 20:22)
// @return error // @return error
func UpdateExaCustomer(e *model.ExaCustomer) (err error) { func UpdateExaCustomer(e *model.ExaCustomer) (err error) {
@ -36,6 +39,7 @@ func UpdateExaCustomer(e *model.ExaCustomer) (err error) {
// @title GetExaCustomer // @title GetExaCustomer
// @description get the info of a costumer , 获取用户信息 // @description get the info of a costumer , 获取用户信息
// @auth (2020/04/05 20:22) // @auth (2020/04/05 20:22)
// @param id uint
// @return error // @return error
// @return customer ExaCustomer // @return customer ExaCustomer
func GetExaCustomer(id uint) (err error, customer model.ExaCustomer) { func GetExaCustomer(id uint) (err error, customer model.ExaCustomer) {
@ -46,6 +50,7 @@ func GetExaCustomer(id uint) (err error, customer model.ExaCustomer) {
// @title GetCustomerInfoList // @title GetCustomerInfoList
// @description get customer list by pagination, 分页获取用户列表 // @description get customer list by pagination, 分页获取用户列表
// @auth (2020/04/05 20:22) // @auth (2020/04/05 20:22)
// @param sysUserAuthorityID string
// @param info PageInfo // @param info PageInfo
// @return error // @return error
func GetCustomerInfoList(sysUserAuthorityID string, info request.PageInfo) (err error, list interface{}, total int) { func GetCustomerInfoList(sysUserAuthorityID string, info request.PageInfo) (err error, list interface{}, total int) {

11
server/service/exa_file_upload_download.go

@ -8,16 +8,18 @@ import (
// @title Upload // @title Upload
// @description 创建文件上传记录 // @description 创建文件上传记录
// @param file model.ExaFileUploadAndDownload
// @auth (2020/04/05 20:22) // @auth (2020/04/05 20:22)
// @return error // @return error
func Upload(f model.ExaFileUploadAndDownload) error {
err := global.GVA_DB.Create(&f).Error
func Upload(file model.ExaFileUploadAndDownload) error {
err := global.GVA_DB.Create(&file).Error
return err return err
} }
// @title FindFile // @title FindFile
// @description 删除文件切片记录 // @description 删除文件切片记录
// @auth (2020/04/05 20:22) // @auth (2020/04/05 20:22)
// @param id uint
// @return error // @return error
func FindFile(id uint) (error, model.ExaFileUploadAndDownload) { func FindFile(id uint) (error, model.ExaFileUploadAndDownload) {
var file model.ExaFileUploadAndDownload var file model.ExaFileUploadAndDownload
@ -28,9 +30,10 @@ func FindFile(id uint) (error, model.ExaFileUploadAndDownload) {
// @title DeleteFile // @title DeleteFile
// @description 删除文件记录 // @description 删除文件记录
// @auth (2020/04/05 20:22) // @auth (2020/04/05 20:22)
// @param file model.ExaFileUploadAndDownload
// @return error // @return error
func DeleteFile(f model.ExaFileUploadAndDownload) error {
err := global.GVA_DB.Where("id = ?", f.ID).Unscoped().Delete(f).Error
func DeleteFile(file model.ExaFileUploadAndDownload) error {
err := global.GVA_DB.Where("id = ?", file.ID).Unscoped().Delete(file).Error
return err return err
} }

26
server/service/jwt_black_list.go

@ -7,39 +7,43 @@ import (
// @title JsonInBlacklist // @title JsonInBlacklist
// @description create jwt blacklist // @description create jwt blacklist
// @param jwtList model.JwtBlacklist
// @auth (2020/04/05 20:22) // @auth (2020/04/05 20:22)
// @return err error // @return err error
func JsonInBlacklist(j model.JwtBlacklist) (err error) {
err = global.GVA_DB.Create(&j).Error
func JsonInBlacklist(jwtList model.JwtBlacklist) (err error) {
err = global.GVA_DB.Create(&jwtList).Error
return return
} }
// @title IsBlacklist // @title IsBlacklist
// @description check if the Jwt is in the blacklist or not, 判断JWT是否在黑名单内部 // @description check if the Jwt is in the blacklist or not, 判断JWT是否在黑名单内部
// @auth (2020/04/05 20:22) // @auth (2020/04/05 20:22)
// @param newPassword string
// @param jwt string
// @param jwtList model.JwtBlacklist
// @return err error // @return err error
func IsBlacklist(Jwt string, j model.JwtBlacklist) bool {
isNotFound := global.GVA_DB.Where("jwt = ?", Jwt).First(&j).RecordNotFound()
func IsBlacklist(jwt string, jwtList model.JwtBlacklist) bool {
isNotFound := global.GVA_DB.Where("jwt = ?", jwt).First(&jwtList).RecordNotFound()
return !isNotFound return !isNotFound
} }
// @title GetRedisJWT // @title GetRedisJWT
// @description Get user info in redis // @description Get user info in redis
// @auth (2020/04/05 20:22) // @auth (2020/04/05 20:22)
// @param newPassword string
// @param userName string
// @return err error // @return err error
func GetRedisJWT(userName string) (err error, RedisJWT string) {
RedisJWT, err = global.GVA_REDIS.Get(userName).Result()
return err, RedisJWT
// @return redisJWT string
func GetRedisJWT(userName string) (err error, redisJWT string) {
redisJWT, err = global.GVA_REDIS.Get(userName).Result()
return err, redisJWT
} }
// @title SetRedisJWT // @title SetRedisJWT
// @description set jwt into the Redis // @description set jwt into the Redis
// @auth (2020/04/05 20:22) // @auth (2020/04/05 20:22)
// @param jwtList model.JwtBlacklist
// @param userName string // @param userName string
// @return err error // @return err error
func SetRedisJWT(j model.JwtBlacklist, userName string) (err error) {
err = global.GVA_REDIS.Set(userName, j.Jwt, 1000*1000*1000*60*60*24*7).Err()
func SetRedisJWT(jwtList model.JwtBlacklist, userName string) (err error) {
err = global.GVA_REDIS.Set(userName, jwtList.Jwt, 1000*1000*1000*60*60*24*7).Err()
return err return err
} }

60
server/service/sys_api.go

@ -10,53 +10,55 @@ import (
// @title CreateApi // @title CreateApi
// @description create base apis, 新增基础api // @description create base apis, 新增基础api
// @auth (2020/04/05 20:22) // @auth (2020/04/05 20:22)
// @param FileMd5 string
// @param FileName string
// @param FilePath string
// @param api model.SysApi
// @return error // @return error
func CreateApi(a model.SysApi) (err error) {
findOne := global.GVA_DB.Where("path = ? AND method = ?", a.Path, a.Method).Find(&model.SysApi{}).Error
func CreateApi(api model.SysApi) (err error) {
findOne := global.GVA_DB.Where("path = ? AND method = ?", api.Path, api.Method).Find(&model.SysApi{}).Error
if findOne == nil { if findOne == nil {
return errors.New("存在相同api") return errors.New("存在相同api")
} else { } else {
err = global.GVA_DB.Create(&a).Error
err = global.GVA_DB.Create(&api).Error
} }
return err return err
} }
// @title DeleteApi // @title DeleteApi
// @description delete base apis, 删除基础api
// @description delete a base api, 删除基础api
// @param api model.SysApi
// @auth (2020/04/05 20:22) // @auth (2020/04/05 20:22)
// @return error // @return error
func DeleteApi(a model.SysApi) (err error) {
err = global.GVA_DB.Delete(a).Error
ClearCasbin(1, a.Path, a.Method)
func DeleteApi(api model.SysApi) (err error) {
err = global.GVA_DB.Delete(api).Error
ClearCasbin(1, api.Path, api.Method)
return err return err
} }
// @title GetInfoList // @title GetInfoList
// @description get apis by pagination, 分页获取数据 // @description get apis by pagination, 分页获取数据
// @auth (2020/04/05 20:22) // @auth (2020/04/05 20:22)
// @param info PageInfo
// @param api model.SysApi
// @param info request.PageInfo
// @param order string
// @param desc bool
// @return err error // @return err error
// @return list interface{} // @return list interface{}
// @return total int // @return total int
func GetAPIInfoList(a model.SysApi, info request.PageInfo, Order string, Desc bool) (err error, list interface{}, total int) {
func GetAPIInfoList(api model.SysApi, info request.PageInfo, order string, desc bool) (err error, list interface{}, total int) {
limit := info.PageSize limit := info.PageSize
offset := info.PageSize * (info.Page - 1) offset := info.PageSize * (info.Page - 1)
db := global.GVA_DB db := global.GVA_DB
var apiList []model.SysApi var apiList []model.SysApi
if a.Path != "" {
db = db.Where("path LIKE ?", "%"+a.Path+"%")
if api.Path != "" {
db = db.Where("path LIKE ?", "%"+api.Path+"%")
} }
if a.Description != "" {
db = db.Where("description LIKE ?", "%"+a.Description+"%")
if api.Description != "" {
db = db.Where("description LIKE ?", "%"+api.Description+"%")
} }
if a.Method != "" {
db = db.Where("method = ?", a.Method)
if api.Method != "" {
db = db.Where("method = ?", api.Method)
} }
err = db.Find(&apiList).Count(&total).Error err = db.Find(&apiList).Count(&total).Error
@ -65,12 +67,12 @@ func GetAPIInfoList(a model.SysApi, info request.PageInfo, Order string, Desc bo
return err, apiList, total return err, apiList, total
} else { } else {
db = db.Limit(limit).Offset(offset) db = db.Limit(limit).Offset(offset)
if Order != "" {
if order != "" {
var OrderStr string var OrderStr string
if Desc {
OrderStr = Order + " desc"
if desc {
OrderStr = order + " desc"
} else { } else {
OrderStr = Order
OrderStr = order
} }
err = db.Order(OrderStr, true).Find(&apiList).Error err = db.Order(OrderStr, true).Find(&apiList).Error
} else { } else {
@ -93,6 +95,7 @@ func GetAllApis() (err error, apis []model.SysApi) {
// @title GetApiById // @title GetApiById
// @description 根据id获取api // @description 根据id获取api
// @auth (2020/04/05 20:22) // @auth (2020/04/05 20:22)
// @param api model.SysApi
// @param id float64 // @param id float64
// @return error // @return error
func GetApiById(id float64) (err error, api model.SysApi) { func GetApiById(id float64) (err error, api model.SysApi) {
@ -103,14 +106,15 @@ func GetApiById(id float64) (err error, api model.SysApi) {
// @title UpdateApi // @title UpdateApi
// @description update a base api, update api // @description update a base api, update api
// @auth (2020/04/05 20:22) // @auth (2020/04/05 20:22)
// @param api model.SysApi
// @return error // @return error
func UpdateApi(a model.SysApi) (err error) {
func UpdateApi(api model.SysApi) (err error) {
var oldA model.SysApi var oldA model.SysApi
err = global.GVA_DB.Where("id = ?", a.ID).First(&oldA).Error
err = global.GVA_DB.Where("id = ?", api.ID).First(&oldA).Error
if oldA.Path != a.Path || oldA.Method != a.Method {
flag := global.GVA_DB.Where("path = ? AND method = ?", a.Path, a.Method).Find(&model.SysApi{}).RecordNotFound()
if oldA.Path != api.Path || oldA.Method != api.Method {
flag := global.GVA_DB.Where("path = ? AND method = ?", api.Path, api.Method).Find(&model.SysApi{}).RecordNotFound()
if !flag { if !flag {
return errors.New("存在相同api路径") return errors.New("存在相同api路径")
} }
@ -118,11 +122,11 @@ func UpdateApi(a model.SysApi) (err error) {
if err != nil { if err != nil {
return err return err
} else { } else {
err = UpdateCasbinApi(oldA.Path, a.Path, oldA.Method, a.Method)
err = UpdateCasbinApi(oldA.Path, api.Path, oldA.Method, api.Method)
if err != nil { if err != nil {
return err return err
} else { } else {
err = global.GVA_DB.Save(a).Error
err = global.GVA_DB.Save(api).Error
} }
} }
return err return err

66
server/service/sys_authority.go

@ -10,50 +10,45 @@ import (
// @title CreateAuthority // @title CreateAuthority
// @description 创建一个角色 // @description 创建一个角色
// @auth (2020/04/05 20:22) // @auth (2020/04/05 20:22)
// @param FileMd5 string
// @param FileName string
// @param FilePath string
// @param auth model.SysAuthority
// @return error // @return error
func CreateAuthority(a model.SysAuthority) (err error, authority model.SysAuthority) {
err = global.GVA_DB.Create(&a).Error
return err, a
// @return authority model.SysAuthority
func CreateAuthority(auth model.SysAuthority) (err error, authority model.SysAuthority) {
err = global.GVA_DB.Create(&auth).Error
return err, auth
} }
// @title DeleteAuthority // @title DeleteAuthority
// @description 删除角色 // @description 删除角色
// @auth (2020/04/05 20:22) // @auth (2020/04/05 20:22)
// @param FileMd5 string
// @param FileName string
// @param FilePath string
// @param auth model.SysAuthority
// @return error // @return error
// 删除角色 // 删除角色
func DeleteAuthority(a model.SysAuthority) (err error) {
err = global.GVA_DB.Where("authority_id = ?", a.AuthorityId).Find(&model.SysUser{}).Error
func DeleteAuthority(auth model.SysAuthority) (err error) {
err = global.GVA_DB.Where("authority_id = ?", auth.AuthorityId).Find(&model.SysUser{}).Error
if err == nil { if err == nil {
err = errors.New("此角色有用户正在使用禁止删除") err = errors.New("此角色有用户正在使用禁止删除")
return return
} }
err = global.GVA_DB.Where("parent_id = ?", a.AuthorityId).Find(&model.SysAuthority{}).Error
err = global.GVA_DB.Where("parent_id = ?", auth.AuthorityId).Find(&model.SysAuthority{}).Error
if err == nil { if err == nil {
err = errors.New("此角色存在子角色不允许删除") err = errors.New("此角色存在子角色不允许删除")
return return
} }
db := global.GVA_DB.Preload("SysBaseMenus").Where("authority_id = ?", a.AuthorityId).First(a).Unscoped().Delete(a)
if len(a.SysBaseMenus) > 0 {
err = db.Association("SysBaseMenus").Delete(a.SysBaseMenus).Error
db := global.GVA_DB.Preload("SysBaseMenus").Where("authority_id = ?", auth.AuthorityId).First(auth).Unscoped().Delete(auth)
if len(auth.SysBaseMenus) > 0 {
err = db.Association("SysBaseMenus").Delete(auth.SysBaseMenus).Error
} else { } else {
err = db.Error err = db.Error
} }
ClearCasbin(0, a.AuthorityId)
ClearCasbin(0, auth.AuthorityId)
return err return err
} }
// @title GetInfoList // @title GetInfoList
// @description 删除文件切片记录 // @description 删除文件切片记录
// @auth (2020/04/05 20:22) // @auth (2020/04/05 20:22)
// @param FileMd5 string
// @param FileName string
// @param FilePath string
// @param info request.PaveInfo
// @return error // @return error
// 分页获取数据 // 分页获取数据
func GetAuthorityInfoList(info request.PageInfo) (err error, list interface{}, total int) { func GetAuthorityInfoList(info request.PageInfo) (err error, list interface{}, total int) {
@ -73,49 +68,42 @@ func GetAuthorityInfoList(info request.PageInfo) (err error, list interface{}, t
// @title GetAuthorityInfo // @title GetAuthorityInfo
// @description 获取所有角色信息 // @description 获取所有角色信息
// @auth (2020/04/05 20:22) // @auth (2020/04/05 20:22)
// @param FileMd5 string
// @param FileName string
// @param FilePath string
// @param auth model.SysAuthority
// @return error // @return error
func GetAuthorityInfo(a model.SysAuthority) (err error, sa model.SysAuthority) {
err = global.GVA_DB.Preload("DataAuthorityId").Where("authority_id = ?", a.AuthorityId).First(&sa).Error
// @param authority 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 return err, sa
} }
// @title SetDataAuthority // @title SetDataAuthority
// @description 设置角色资源权限 // @description 设置角色资源权限
// @auth (2020/04/05 20:22) // @auth (2020/04/05 20:22)
// @param FileMd5 string
// @param FileName string
// @param FilePath string
// @param auth model.SysAuthority
// @return error // @return error
func SetDataAuthority(a model.SysAuthority) error {
func SetDataAuthority(auth model.SysAuthority) error {
var s model.SysAuthority var s model.SysAuthority
global.GVA_DB.Preload("DataAuthorityId").First(&s, "authority_id = ?", a.AuthorityId)
err := global.GVA_DB.Model(&s).Association("DataAuthorityId").Replace(&a.DataAuthorityId).Error
global.GVA_DB.Preload("DataAuthorityId").First(&s, "authority_id = ?", auth.AuthorityId)
err := global.GVA_DB.Model(&s).Association("DataAuthorityId").Replace(&auth.DataAuthorityId).Error
return err return err
} }
// @title SetMenuAuthority // @title SetMenuAuthority
// @description 菜单与角色绑定 // @description 菜单与角色绑定
// @auth (2020/04/05 20:22) // @auth (2020/04/05 20:22)
// @param FileMd5 string
// @param FileName string
// @param FilePath string
// @param auth *model.SysAuthority
// @return error // @return error
func SetMenuAuthority(a *model.SysAuthority) error {
func SetMenuAuthority(auth *model.SysAuthority) error {
var s model.SysAuthority var s model.SysAuthority
global.GVA_DB.Preload("SysBaseMenus").First(&s, "authority_id = ?", a.AuthorityId)
err := global.GVA_DB.Model(&s).Association("SysBaseMenus").Replace(&a.SysBaseMenus).Error
global.GVA_DB.Preload("SysBaseMenus").First(&s, "authority_id = ?", auth.AuthorityId)
err := global.GVA_DB.Model(&s).Association("SysBaseMenus").Replace(&auth.SysBaseMenus).Error
return err return err
} }
// @title findChildrenAuthority // @title findChildrenAuthority
// @description 查询子角色 // @description 查询子角色
// @auth (2020/04/05 20:22) // @auth (2020/04/05 20:22)
// @param FileMd5 string
// @param FileName string
// @param FilePath string
// @param auth *model.SysAuthority
// @return error // @return error
func findChildrenAuthority(authority *model.SysAuthority) (err error) { func findChildrenAuthority(authority *model.SysAuthority) (err error) {
err = global.GVA_DB.Preload("DataAuthorityId").Where("parent_id = ?", authority.AuthorityId).Find(&authority.Children).Error err = global.GVA_DB.Preload("DataAuthorityId").Where("parent_id = ?", authority.AuthorityId).Find(&authority.Children).Error

41
server/service/sys_auto_code.go

@ -10,8 +10,9 @@ import (
// @title CreateTemp // @title CreateTemp
// @description 函数的详细描述 // @description 函数的详细描述
// @auth (2020/04/05 20:22) // @auth (2020/04/05 20:22)
// @param autoCode model.AutoCodeStruct
// @return err error // @return err error
func CreateTemp(a model.AutoCodeStruct) (err error) {
func CreateTemp(autoCode model.AutoCodeStruct) (err error) {
basePath := "./resource/template" basePath := "./resource/template"
modelTmpl, err := template.ParseFiles(basePath + "/te/model.go.tpl") modelTmpl, err := template.ParseFiles(basePath + "/te/model.go.tpl")
if err != nil { if err != nil {
@ -37,31 +38,31 @@ func CreateTemp(a model.AutoCodeStruct) (err error) {
_autoCode := "./autoCode/" _autoCode := "./autoCode/"
//自动化后台代码目录 //自动化后台代码目录
_te := "./autoCode/te/" _te := "./autoCode/te/"
_dir := _te + a.PackageName
_modeldir := _te + a.PackageName + "/model"
_apidir := _te + a.PackageName + "/api"
_routerdir := _te + a.PackageName + "/router"
_dir := _te + autoCode.PackageName
_modeldir := _te + autoCode.PackageName + "/model"
_apidir := _te + autoCode.PackageName + "/api"
_routerdir := _te + autoCode.PackageName + "/router"
//自动化前台代码目录 //自动化前台代码目录
_fe := "./autoCode/fe/" _fe := "./autoCode/fe/"
_fe_dir := _fe + a.PackageName
_fe_apidir := _fe + a.PackageName + "/api"
_fe_dir := _fe + autoCode.PackageName
_fe_apidir := _fe + autoCode.PackageName + "/api"
err = utils.CreateDir(_autoCode, _te, _dir, _modeldir, _apidir, _routerdir, _fe, _fe_dir, _fe_apidir) err = utils.CreateDir(_autoCode, _te, _dir, _modeldir, _apidir, _routerdir, _fe, _fe_dir, _fe_apidir)
if err != nil { if err != nil {
return err return err
} }
model, err := os.OpenFile(_te+a.PackageName+"/model/model.go", os.O_CREATE|os.O_WRONLY, 0755)
model, err := os.OpenFile(_te+autoCode.PackageName+"/model/model.go", os.O_CREATE|os.O_WRONLY, 0755)
if err != nil { if err != nil {
return err return err
} }
api, err := os.OpenFile(_te+a.PackageName+"/api/api.go", os.O_CREATE|os.O_WRONLY, 0755)
api, err := os.OpenFile(_te+autoCode.PackageName+"/api/api.go", os.O_CREATE|os.O_WRONLY, 0755)
if err != nil { if err != nil {
return err return err
} }
router, err := os.OpenFile(_te+a.PackageName+"/router/router.go", os.O_CREATE|os.O_WRONLY, 0755)
router, err := os.OpenFile(_te+autoCode.PackageName+"/router/router.go", os.O_CREATE|os.O_WRONLY, 0755)
if err != nil { if err != nil {
return err return err
} }
feapi, err := os.OpenFile(_fe+a.PackageName+"/api/api.js", os.O_CREATE|os.O_WRONLY, 0755)
feapi, err := os.OpenFile(_fe+autoCode.PackageName+"/api/api.js", os.O_CREATE|os.O_WRONLY, 0755)
if err != nil { if err != nil {
return err return err
} }
@ -71,23 +72,23 @@ func CreateTemp(a model.AutoCodeStruct) (err error) {
} }
// 生成代码 // 生成代码
{ {
err = modelTmpl.Execute(model, a)
err = modelTmpl.Execute(model, autoCode)
if err != nil { if err != nil {
return err return err
} }
err = apiTmpl.Execute(api, a)
err = apiTmpl.Execute(api, autoCode)
if err != nil { if err != nil {
return err return err
} }
err = routerTmpl.Execute(router, a)
err = routerTmpl.Execute(router, autoCode)
if err != nil { if err != nil {
return err return err
} }
err = feapiTmpl.Execute(feapi, a)
err = feapiTmpl.Execute(feapi, autoCode)
if err != nil { if err != nil {
return err return err
} }
err = readmeTmpl.Execute(readme, a)
err = readmeTmpl.Execute(readme, autoCode)
if err != nil { if err != nil {
return err return err
} }
@ -98,10 +99,10 @@ func CreateTemp(a model.AutoCodeStruct) (err error) {
_ = feapi.Close() _ = feapi.Close()
_ = readme.Close() _ = readme.Close()
fileList := []string{ fileList := []string{
_te + a.PackageName + "/model/model.go",
_te + a.PackageName + "/api/api.go",
_te + a.PackageName + "/router/router.go",
_fe + a.PackageName + "/api/api.js",
_te + autoCode.PackageName + "/model/model.go",
_te + autoCode.PackageName + "/api/api.go",
_te + autoCode.PackageName + "/router/router.go",
_fe + autoCode.PackageName + "/api/api.js",
_autoCode + "readme.txt", _autoCode + "readme.txt",
} }
err = utils.ZipFiles("./ginvueadmin.zip", fileList, ".", ".") err = utils.ZipFiles("./ginvueadmin.zip", fileList, ".", ".")

6
server/service/sys_base_menu.go

@ -9,7 +9,7 @@ import (
// @title DeleteBaseMenu // @title DeleteBaseMenu
// @description 删除基础路由 // @description 删除基础路由
// @auth (2020/04/05 20:22) // @auth (2020/04/05 20:22)
// @param newPassword string
// @param id float64
// @return err error // @return err error
func DeleteBaseMenu(id float64) (err error) { func DeleteBaseMenu(id float64) (err error) {
err = global.GVA_DB.Where("parent_id = ?", id).First(&model.SysBaseMenu{}).Error err = global.GVA_DB.Where("parent_id = ?", id).First(&model.SysBaseMenu{}).Error
@ -30,7 +30,7 @@ func DeleteBaseMenu(id float64) (err error) {
// @title UpdateBaseMenu // @title UpdateBaseMenu
// @description 更新路由 // @description 更新路由
// @auth (2020/04/05 20:22) // @auth (2020/04/05 20:22)
// @param newPassword string
// @param menu model.SysBaseMenu
// @return err error // @return err error
func UpdateBaseMenu(menu model.SysBaseMenu) (err error) { func UpdateBaseMenu(menu model.SysBaseMenu) (err error) {
upDateMap := make(map[string]interface{}) upDateMap := make(map[string]interface{})
@ -50,7 +50,7 @@ func UpdateBaseMenu(menu model.SysBaseMenu) (err error) {
// @title GetBaseMenuById // @title GetBaseMenuById
// @description get current menus, 返回当前选中menu // @description get current menus, 返回当前选中menu
// @auth (2020/04/05 20:22) // @auth (2020/04/05 20:22)
// @param newPassword string
// @param id float64
// @return err error // @return err error
func GetBaseMenuById(id float64) (err error, menu model.SysBaseMenu) { func GetBaseMenuById(id float64) (err error, menu model.SysBaseMenu) {
err = global.GVA_DB.Where("id = ?", id).First(&menu).Error err = global.GVA_DB.Where("id = ?", id).First(&menu).Error

4
server/service/sys_casbin.go

@ -38,7 +38,7 @@ func UpdateCasbin(authorityId string, casbinInfos []request.CasbinInfo) error {
// @title AddCasbin // @title AddCasbin
// @description add casbin authority, 添加权限 // @description add casbin authority, 添加权限
// @auth (2020/04/05 20:22) // @auth (2020/04/05 20:22)
// @param cm CasbinModel
// @param cm model.CasbinModel
// @return bool // @return bool
func AddCasbin(cm model.CasbinModel) bool { func AddCasbin(cm model.CasbinModel) bool {
e := Casbin() e := Casbin()
@ -50,6 +50,8 @@ func AddCasbin(cm model.CasbinModel) bool {
// @auth (2020/04/05 20:22) // @auth (2020/04/05 20:22)
// @param oldPath string // @param oldPath string
// @param newPath string // @param newPath string
// @param oldMethod string
// @param newMethod string
// @return error // @return error
func UpdateCasbinApi(oldPath string, newPath string, oldMethod string, newMethod string) error { func UpdateCasbinApi(oldPath string, newPath string, oldMethod string, newMethod string) error {
var cs []model.CasbinModel var cs []model.CasbinModel

16
server/service/sys_menu.go

@ -12,7 +12,7 @@ import (
// @auth (2020/04/05 20:22) // @auth (2020/04/05 20:22)
// @param authorityId string // @param authorityId string
// @return err error // @return err error
// @return menus []SysMenu
// @return menus []model.SysMenu
func GetMenuTree(authorityId string) (err error, menus []model.SysMenu) { func GetMenuTree(authorityId string) (err error, menus []model.SysMenu) {
sql := "SELECT 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 = ? AND authority_menu.parent_id = ?" sql := "SELECT 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 = ? AND authority_menu.parent_id = ?"
@ -26,8 +26,8 @@ func GetMenuTree(authorityId string) (err error, menus []model.SysMenu) {
// @title getChildrenList // @title getChildrenList
// @description 获取子菜单 // @description 获取子菜单
// @auth (2020/04/05 20:22) // @auth (2020/04/05 20:22)
// @param menu *SysMenu
// @param SQLstatement string
// @param menu *model.SysMenu
// @param sql string
// @return err error // @return err error
func getChildrenList(menu *model.SysMenu, sql string) (err error) { func getChildrenList(menu *model.SysMenu, sql string) (err error) {
err = global.GVA_DB.Raw(sql, menu.AuthorityId, menu.MenuId).Scan(&menu.Children).Error err = global.GVA_DB.Raw(sql, menu.AuthorityId, menu.MenuId).Scan(&menu.Children).Error
@ -40,8 +40,10 @@ func getChildrenList(menu *model.SysMenu, sql string) (err error) {
// @title GetInfoList // @title GetInfoList
// @description 获取路由分页 // @description 获取路由分页
// @auth (2020/04/05 20:22) // @auth (2020/04/05 20:22)
// @param newPassword string
// @param info request.PageInfo
// @return err error // @return err error
// @return list interface{}
// @return total int
func GetInfoList(info request.PageInfo) (err error, list interface{}, total int) { func GetInfoList(info request.PageInfo) (err error, list interface{}, total int) {
limit := info.PageSize limit := info.PageSize
offset := info.PageSize * (info.Page - 1) offset := info.PageSize * (info.Page - 1)
@ -57,7 +59,7 @@ func GetInfoList(info request.PageInfo) (err error, list interface{}, total int)
// @title getBaseChildrenList // @title getBaseChildrenList
// @description get children of menu, 获取菜单的子菜单 // @description get children of menu, 获取菜单的子菜单
// @auth (2020/04/05 20:22) // @auth (2020/04/05 20:22)
// @param menu *SysBaseMenu
// @param menu *model.SysBaseMenu
// @return err error // @return err error
func getBaseChildrenList(menu *model.SysBaseMenu) (err error) { func getBaseChildrenList(menu *model.SysBaseMenu) (err error) {
err = global.GVA_DB.Where("parent_id = ?", menu.ID).Order("sort", true).Find(&menu.Children).Error err = global.GVA_DB.Where("parent_id = ?", menu.ID).Order("sort", true).Find(&menu.Children).Error
@ -70,7 +72,7 @@ func getBaseChildrenList(menu *model.SysBaseMenu) (err error) {
// @title AddBaseMenu // @title AddBaseMenu
// @description 函数的详细描述 // @description 函数的详细描述
// @auth (2020/04/05 20:22) // @auth (2020/04/05 20:22)
// @param newPassword string
// @param menu *model.SysBaseMenu
// @return err error // @return err error
//增加基础路由 //增加基础路由
func AddBaseMenu(menu model.SysBaseMenu) (err error) { func AddBaseMenu(menu model.SysBaseMenu) (err error) {
@ -99,7 +101,7 @@ func GetBaseMenuTree() (err error, menus []model.SysBaseMenu) {
// @title AddMenuAuthority // @title AddMenuAuthority
// @description 为角色增加menu树 // @description 为角色增加menu树
// @auth (2020/04/05 20:22) // @auth (2020/04/05 20:22)
// @param menus []SysBaseMenu
// @param menus []model.SysBaseMenu
// @param authorityId string // @param authorityId string
// @return error // @return error
func AddMenuAuthority(menus []model.SysBaseMenu, authorityId string) (err error) { func AddMenuAuthority(menus []model.SysBaseMenu, authorityId string) (err error) {

5
server/service/sys_system.go

@ -20,9 +20,10 @@ func GetSystemConfig() (err error, conf config.Server) {
// @title SetSystemConfig // @title SetSystemConfig
// @description set system config, 设置配置文件 // @description set system config, 设置配置文件
// @auth (2020/04/05 20:22) // @auth (2020/04/05 20:22)
// @param system model.System
// @return err error // @return err error
func SetSystemConfig(s model.System) (err error) {
cs := utils.StructToMap(s.Config)
func SetSystemConfig(system model.System) (err error) {
cs := utils.StructToMap(system.Config)
for k, v := range cs { for k, v := range cs {
global.GVA_VP.Set(k, v) global.GVA_VP.Set(k, v)
} }

5
server/service/sys_user.go

@ -12,6 +12,7 @@ import (
// @title Register // @title Register
// @description register, 用户注册 // @description register, 用户注册
// @auth (2020/04/05 20:22) // @auth (2020/04/05 20:22)
// @param u model.SysUser
// @return err error // @return err error
// @return userInter *SysUser // @return userInter *SysUser
func Register(u model.SysUser) (err error, userInter model.SysUser) { func Register(u model.SysUser) (err error, userInter model.SysUser) {
@ -33,6 +34,7 @@ func Register(u model.SysUser) (err error, userInter model.SysUser) {
// @title Login // @title Login
// @description login, 用户登录 // @description login, 用户登录
// @auth (2020/04/05 20:22) // @auth (2020/04/05 20:22)
// @param u *model.SysUser
// @return err error // @return err error
// @return userInter *SysUser // @return userInter *SysUser
func Login(u *model.SysUser) (err error, userInter *model.SysUser) { func Login(u *model.SysUser) (err error, userInter *model.SysUser) {
@ -49,6 +51,7 @@ func Login(u *model.SysUser) (err error, userInter *model.SysUser) {
// @title ChangePassword // @title ChangePassword
// @description change the password of a certain user, 修改用户密码 // @description change the password of a certain user, 修改用户密码
// @auth (2020/04/05 20:22) // @auth (2020/04/05 20:22)
// @param u *model.SysUser
// @param newPassword string // @param newPassword string
// @return err error // @return err error
// @return userInter *SysUser // @return userInter *SysUser
@ -63,7 +66,7 @@ func ChangePassword(u *model.SysUser, newPassword string) (err error, userInter
// @title GetInfoList // @title GetInfoList
// @description get user list by pagination, 分页获取数据 // @description get user list by pagination, 分页获取数据
// @auth (2020/04/05 20:22) // @auth (2020/04/05 20:22)
// @param PageInfo int
// @param info request.PageInfo
// @return err error // @return err error
// @return list interface{} // @return list interface{}
// @return total int // @return total int

1
server/service/sys_workflow.go

@ -8,6 +8,7 @@ import (
// @title Create // @title Create
// @description create a workflow, 创建工作流 // @description create a workflow, 创建工作流
// @auth (2020/04/05 20:22) // @auth (2020/04/05 20:22)
// @param wk model.SysWorkflow
// @return error // @return error
func Create(wk model.SysWorkflow) error { func Create(wk model.SysWorkflow) error {
err := global.GVA_DB.Create(&wk).Error err := global.GVA_DB.Create(&wk).Error

Loading…
Cancel
Save