From 5d871db828cdf7c68f3e70643f774b426ec99f97 Mon Sep 17 00:00:00 2001 From: rainyan Date: Fri, 10 Apr 2020 10:36:15 +0800 Subject: [PATCH] correct all comments of functions in service --- server/go.mod | 2 +- server/service/exa_breakpoint_continue.go | 49 ++++++------- server/service/exa_customer.go | 15 ++-- server/service/exa_file_upload_download.go | 19 ++--- server/service/jwt_black_list.go | 34 +++++---- server/service/sys_api.go | 72 ++++++++++--------- server/service/sys_authority.go | 80 +++++++++------------- server/service/sys_auto_code.go | 43 ++++++------ server/service/sys_base_menu.go | 12 ++-- server/service/sys_casbin.go | 22 +++--- server/service/sys_menu.go | 32 +++++---- server/service/sys_system.go | 9 +-- server/service/sys_user.go | 17 +++-- server/service/sys_workflow.go | 3 +- server/utils/directory.go | 4 +- 15 files changed, 214 insertions(+), 199 deletions(-) diff --git a/server/go.mod b/server/go.mod index 59bba837..f9895752 100644 --- a/server/go.mod +++ b/server/go.mod @@ -28,7 +28,7 @@ require ( github.com/onsi/gomega v1.4.3 // indirect github.com/op/go-logging v0.0.0-20160315200505-970db520ece7 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/x v7.0.8+incompatible // indirect github.com/satori/go.uuid v1.2.0 diff --git a/server/service/exa_breakpoint_continue.go b/server/service/exa_breakpoint_continue.go index 99c038a1..8c3d8a90 100644 --- a/server/service/exa_breakpoint_continue.go +++ b/server/service/exa_breakpoint_continue.go @@ -8,20 +8,20 @@ import ( // @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 +// @auth (2020/04/05 20:22) +// @param fileMd5 string +// @param fileName string +// @param chunkTotal int // @return err error // @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 - 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 { - 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 } else { cfile.IsFinish = true @@ -34,38 +34,39 @@ func FindOrCreateFile(FileMd5 string, FileName string, ChunkTotal int) (err err // @title CreateFileChunk // @description create a chunk of the file, 创建文件切片记录 -// @auth (2020/04/05 20:22 ) -// @param FileChunkPath string -// @param FileChunkNumber int +// @auth (2020/04/05 20:22) +// @param id unit +// @param fileChunkPath string +// @param fileChunkNumber int // @return error -func CreateFileChunk(id uint, FileChunkPath string, FileChunkNumber int) error { +func CreateFileChunk(id uint, fileChunkPath string, fileChunkNumber int) error { var chunk model.ExaFileChunk - chunk.FileChunkPath = FileChunkPath + chunk.FileChunkPath = fileChunkPath chunk.ExaFileId = id - chunk.FileChunkNumber = FileChunkNumber + chunk.FileChunkNumber = fileChunkNumber err := global.GVA_DB.Create(&chunk).Error return err } // @title FileCreateComplete // @description file creation, 文件合成完成 -// @auth (2020/04/05 20:22 ) -// @param FileMd5 string -// @param FileName string -// @param FilePath string +// @auth (2020/04/05 20:22) +// @param fileMd5 string +// @param fileName string +// @param filePath string // @return error -func FileCreateComplete(FileMd5 string, FileName string, FilePath string) error { +func FileCreateComplete(fileMd5 string, fileName string, filePath string) error { var file model.ExaFile upDateFile := make(map[string]interface{}) - upDateFile["FilePath"] = FilePath + upDateFile["FilePath"] = filePath 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 } // @title DeleteFileChunk // @description delete a chuck of the file, 删除文件切片记录 -// @auth (2020/04/05 20:22 ) +// @auth (2020/04/05 20:22) // @param FileMd5 string // @param FileName string // @param FilePath string diff --git a/server/service/exa_customer.go b/server/service/exa_customer.go index 97ad4bc2..2e9d927c 100644 --- a/server/service/exa_customer.go +++ b/server/service/exa_customer.go @@ -8,7 +8,8 @@ import ( // @title CreateExaCustomer // @description create a customer, 创建用户 -// @auth (2020/04/05 20:22 ) +// @param e model.ExaCustomer +// @auth (2020/04/05 20:22) // @return err error func CreateExaCustomer(e model.ExaCustomer) (err error) { err = global.GVA_DB.Create(&e).Error @@ -17,7 +18,8 @@ func CreateExaCustomer(e model.ExaCustomer) (err error) { // @title DeleteFileChunk // @description delete a customer, 删除用户 -// @auth (2020/04/05 20:22 ) +// @auth (2020/04/05 20:22) +// @param e *model.ExaCustomer // @return error func DeleteExaCustomer(e model.ExaCustomer) (err error) { err = global.GVA_DB.Delete(e).Error @@ -26,7 +28,8 @@ func DeleteExaCustomer(e model.ExaCustomer) (err error) { // @title UpdateExaCustomer // @description update a customer, 更新用户 -// @auth (2020/04/05 20:22 ) +// @param e *model.ExaCustomer +// @auth (2020/04/05 20:22) // @return error func UpdateExaCustomer(e *model.ExaCustomer) (err error) { err = global.GVA_DB.Save(e).Error @@ -35,7 +38,8 @@ func UpdateExaCustomer(e *model.ExaCustomer) (err error) { // @title GetExaCustomer // @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 customer ExaCustomer func GetExaCustomer(id uint) (err error, customer model.ExaCustomer) { @@ -45,7 +49,8 @@ func GetExaCustomer(id uint) (err error, customer model.ExaCustomer) { // @title GetCustomerInfoList // @description get customer list by pagination, 分页获取用户列表 -// @auth (2020/04/05 20:22 ) +// @auth (2020/04/05 20:22) +// @param sysUserAuthorityID string // @param info PageInfo // @return error func GetCustomerInfoList(sysUserAuthorityID string, info request.PageInfo) (err error, list interface{}, total int) { diff --git a/server/service/exa_file_upload_download.go b/server/service/exa_file_upload_download.go index 69512d86..a9a314d1 100644 --- a/server/service/exa_file_upload_download.go +++ b/server/service/exa_file_upload_download.go @@ -8,16 +8,18 @@ import ( // @title Upload // @description 创建文件上传记录 -// @auth (2020/04/05 20:22 ) +// @param file model.ExaFileUploadAndDownload +// @auth (2020/04/05 20:22) // @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 } // @title FindFile // @description 删除文件切片记录 -// @auth (2020/04/05 20:22 ) +// @auth (2020/04/05 20:22) +// @param id uint // @return error func FindFile(id uint) (error, model.ExaFileUploadAndDownload) { var file model.ExaFileUploadAndDownload @@ -27,16 +29,17 @@ func FindFile(id uint) (error, model.ExaFileUploadAndDownload) { // @title DeleteFile // @description 删除文件记录 -// @auth (2020/04/05 20:22 ) +// @auth (2020/04/05 20:22) +// @param file model.ExaFileUploadAndDownload // @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 } // @title GetFileRecordInfoList // @description 分页获取数据 -// @auth (2020/04/05 20:22 ) +// @auth (2020/04/05 20:22) // @param info PageInfo // @return err error // @return list error diff --git a/server/service/jwt_black_list.go b/server/service/jwt_black_list.go index 388c12c3..236cfcbd 100644 --- a/server/service/jwt_black_list.go +++ b/server/service/jwt_black_list.go @@ -7,39 +7,43 @@ import ( // @title JsonInBlacklist // @description create jwt blacklist -// @auth (2020/04/05 20:22 ) +// @param jwtList model.JwtBlacklist +// @auth (2020/04/05 20:22) // @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 } // @title IsBlacklist // @description check if the Jwt is in the blacklist or not, 判断JWT是否在黑名单内部 -// @auth (2020/04/05 20:22 ) -// @param newPassword string +// @auth (2020/04/05 20:22) +// @param jwt string +// @param jwtList model.JwtBlacklist // @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 } // @title GetRedisJWT // @description Get user info in redis -// @auth (2020/04/05 20:22 ) -// @param newPassword string +// @auth (2020/04/05 20:22) +// @param userName string // @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 // @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 // @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 } diff --git a/server/service/sys_api.go b/server/service/sys_api.go index 1c1d5a37..cec3ab92 100644 --- a/server/service/sys_api.go +++ b/server/service/sys_api.go @@ -9,54 +9,56 @@ import ( // @title CreateApi // @description create base apis, 新增基础api -// @auth (2020/04/05 20:22 ) -// @param FileMd5 string -// @param FileName string -// @param FilePath string +// @auth (2020/04/05 20:22) +// @param api model.SysApi // @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 { return errors.New("存在相同api") } else { - err = global.GVA_DB.Create(&a).Error + err = global.GVA_DB.Create(&api).Error } return err } // @title DeleteApi -// @description delete base apis, 删除基础api -// @auth (2020/04/05 20:22 ) +// @description delete a base api, 删除基础api +// @param api model.SysApi +// @auth (2020/04/05 20:22) // @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 } // @title GetInfoList // @description get apis by pagination, 分页获取数据 -// @auth (2020/04/05 20:22 ) -// @param info PageInfo +// @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 -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 offset := info.PageSize * (info.Page - 1) db := global.GVA_DB 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 @@ -65,12 +67,12 @@ func GetAPIInfoList(a model.SysApi, info request.PageInfo, Order string, Desc bo return err, apiList, total } else { db = db.Limit(limit).Offset(offset) - if Order != "" { + if order != "" { var OrderStr string - if Desc { - OrderStr = Order + " desc" + if desc { + OrderStr = order + " desc" } else { - OrderStr = Order + OrderStr = order } err = db.Order(OrderStr, true).Find(&apiList).Error } else { @@ -82,7 +84,7 @@ func GetAPIInfoList(a model.SysApi, info request.PageInfo, Order string, Desc bo // @title GetAllApis // @description get all apis, 获取所有的api -// @auth (2020/04/05 20:22 ) +// @auth (2020/04/05 20:22) // @return err error // @return apis []SysApi func GetAllApis() (err error, apis []model.SysApi) { @@ -92,7 +94,8 @@ func GetAllApis() (err error, apis []model.SysApi) { // @title GetApiById // @description 根据id获取api -// @auth (2020/04/05 20:22 ) +// @auth (2020/04/05 20:22) +// @param api model.SysApi // @param id float64 // @return error func GetApiById(id float64) (err error, api model.SysApi) { @@ -102,15 +105,16 @@ func GetApiById(id float64) (err error, api model.SysApi) { // @title UpdateApi // @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 -func UpdateApi(a model.SysApi) (err error) { +func UpdateApi(api model.SysApi) (err error) { 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 { return errors.New("存在相同api路径") } @@ -118,11 +122,11 @@ func UpdateApi(a model.SysApi) (err error) { if err != nil { return err } else { - err = UpdateCasbinApi(oldA.Path, a.Path, oldA.Method, a.Method) + err = UpdateCasbinApi(oldA.Path, api.Path, oldA.Method, api.Method) if err != nil { return err } else { - err = global.GVA_DB.Save(a).Error + err = global.GVA_DB.Save(api).Error } } return err diff --git a/server/service/sys_authority.go b/server/service/sys_authority.go index 90ab2525..6f8dab4b 100644 --- a/server/service/sys_authority.go +++ b/server/service/sys_authority.go @@ -9,51 +9,46 @@ import ( // @title CreateAuthority // @description 创建一个角色 -// @auth (2020/04/05 20:22 ) -// @param FileMd5 string -// @param FileName string -// @param FilePath string +// @auth (2020/04/05 20:22) +// @param auth model.SysAuthority // @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 // @description 删除角色 -// @auth (2020/04/05 20:22 ) -// @param FileMd5 string -// @param FileName string -// @param FilePath string +// @auth (2020/04/05 20:22) +// @param auth model.SysAuthority // @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 { err = errors.New("此角色有用户正在使用禁止删除") 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 { err = errors.New("此角色存在子角色不允许删除") 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 { err = db.Error } - ClearCasbin(0, a.AuthorityId) + ClearCasbin(0, auth.AuthorityId) return err } // @title GetInfoList // @description 删除文件切片记录 -// @auth (2020/04/05 20:22 ) -// @param FileMd5 string -// @param FileName string -// @param FilePath string +// @auth (2020/04/05 20:22) +// @param info request.PaveInfo // @return error // 分页获取数据 func GetAuthorityInfoList(info request.PageInfo) (err error, list interface{}, total int) { @@ -72,50 +67,43 @@ func GetAuthorityInfoList(info request.PageInfo) (err error, list interface{}, t // @title GetAuthorityInfo // @description 获取所有角色信息 -// @auth (2020/04/05 20:22 ) -// @param FileMd5 string -// @param FileName string -// @param FilePath string +// @auth (2020/04/05 20:22) +// @param auth model.SysAuthority // @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 } // @title SetDataAuthority // @description 设置角色资源权限 -// @auth (2020/04/05 20:22 ) -// @param FileMd5 string -// @param FileName string -// @param FilePath string +// @auth (2020/04/05 20:22) +// @param auth model.SysAuthority // @return error -func SetDataAuthority(a model.SysAuthority) error { +func SetDataAuthority(auth model.SysAuthority) error { 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 } // @title SetMenuAuthority // @description 菜单与角色绑定 -// @auth (2020/04/05 20:22 ) -// @param FileMd5 string -// @param FileName string -// @param FilePath string +// @auth (2020/04/05 20:22) +// @param auth *model.SysAuthority // @return error -func SetMenuAuthority(a *model.SysAuthority) error { +func SetMenuAuthority(auth *model.SysAuthority) error { 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 } // @title findChildrenAuthority // @description 查询子角色 -// @auth (2020/04/05 20:22 ) -// @param FileMd5 string -// @param FileName string -// @param FilePath string +// @auth (2020/04/05 20:22) +// @param auth *model.SysAuthority // @return error func findChildrenAuthority(authority *model.SysAuthority) (err error) { err = global.GVA_DB.Preload("DataAuthorityId").Where("parent_id = ?", authority.AuthorityId).Find(&authority.Children).Error diff --git a/server/service/sys_auto_code.go b/server/service/sys_auto_code.go index 3f98e353..f5501f05 100644 --- a/server/service/sys_auto_code.go +++ b/server/service/sys_auto_code.go @@ -9,9 +9,10 @@ import ( // @title CreateTemp // @description 函数的详细描述 -// @auth (2020/04/05 20:22 ) +// @auth (2020/04/05 20:22) +// @param autoCode model.AutoCodeStruct // @return err error -func CreateTemp(a model.AutoCodeStruct) (err error) { +func CreateTemp(autoCode model.AutoCodeStruct) (err error) { basePath := "./resource/template" modelTmpl, err := template.ParseFiles(basePath + "/te/model.go.tpl") if err != nil { @@ -37,31 +38,31 @@ func CreateTemp(a model.AutoCodeStruct) (err error) { _autoCode := "./autoCode/" //自动化后台代码目录 _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_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) if err != nil { 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 { 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 { 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 { 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 { 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 { return err } - err = apiTmpl.Execute(api, a) + err = apiTmpl.Execute(api, autoCode) if err != nil { return err } - err = routerTmpl.Execute(router, a) + err = routerTmpl.Execute(router, autoCode) if err != nil { return err } - err = feapiTmpl.Execute(feapi, a) + err = feapiTmpl.Execute(feapi, autoCode) if err != nil { return err } - err = readmeTmpl.Execute(readme, a) + err = readmeTmpl.Execute(readme, autoCode) if err != nil { return err } @@ -98,10 +99,10 @@ func CreateTemp(a model.AutoCodeStruct) (err error) { _ = feapi.Close() _ = readme.Close() 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", } err = utils.ZipFiles("./ginvueadmin.zip", fileList, ".", ".") diff --git a/server/service/sys_base_menu.go b/server/service/sys_base_menu.go index ac2f84a7..5c47cf55 100644 --- a/server/service/sys_base_menu.go +++ b/server/service/sys_base_menu.go @@ -8,8 +8,8 @@ import ( // @title DeleteBaseMenu // @description 删除基础路由 -// @auth (2020/04/05 20:22 ) -// @param newPassword string +// @auth (2020/04/05 20:22) +// @param id float64 // @return err error func DeleteBaseMenu(id float64) (err error) { err = global.GVA_DB.Where("parent_id = ?", id).First(&model.SysBaseMenu{}).Error @@ -29,8 +29,8 @@ func DeleteBaseMenu(id float64) (err error) { // @title UpdateBaseMenu // @description 更新路由 -// @auth (2020/04/05 20:22 ) -// @param newPassword string +// @auth (2020/04/05 20:22) +// @param menu model.SysBaseMenu // @return err error func UpdateBaseMenu(menu model.SysBaseMenu) (err error) { upDateMap := make(map[string]interface{}) @@ -49,8 +49,8 @@ func UpdateBaseMenu(menu model.SysBaseMenu) (err error) { // @title GetBaseMenuById // @description get current menus, 返回当前选中menu -// @auth (2020/04/05 20:22 ) -// @param newPassword string +// @auth (2020/04/05 20:22) +// @param id float64 // @return err error func GetBaseMenuById(id float64) (err error, menu model.SysBaseMenu) { err = global.GVA_DB.Where("id = ?", id).First(&menu).Error diff --git a/server/service/sys_casbin.go b/server/service/sys_casbin.go index 678ded16..917b8e57 100644 --- a/server/service/sys_casbin.go +++ b/server/service/sys_casbin.go @@ -13,7 +13,7 @@ import ( // @title UpdateCasbin // @description update casbin authority, 更新casbin权限 -// @auth (2020/04/05 20:22 ) +// @auth (2020/04/05 20:22) // @param authorityId string // @param casbinInfos []CasbinInfo // @return error @@ -37,8 +37,8 @@ func UpdateCasbin(authorityId string, casbinInfos []request.CasbinInfo) error { // @title AddCasbin // @description add casbin authority, 添加权限 -// @auth (2020/04/05 20:22 ) -// @param cm CasbinModel +// @auth (2020/04/05 20:22) +// @param cm model.CasbinModel // @return bool func AddCasbin(cm model.CasbinModel) bool { e := Casbin() @@ -47,11 +47,13 @@ func AddCasbin(cm model.CasbinModel) bool { // @title UpdateCasbinApi // @description update casbin apis, API更新随动 -// @auth (2020/04/05 20:22 ) +// @auth (2020/04/05 20:22) // @param oldPath string // @param newPath string +// @param oldMethod string +// @param newMethod string // @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 err := global.GVA_DB.Table("casbin_rule").Where("v1 = ? AND v2 = ?", oldPath,oldMethod).Find(&cs).Update("v1", newPath).Update("v2", newMethod).Error return err @@ -59,7 +61,7 @@ func UpdateCasbinApi(oldPath string, newPath string,oldMethod string, newMethod // @title GetPolicyPathByAuthorityId // @description get policy path by authorityId, 获取权限列表 -// @auth (2020/04/05 20:22 ) +// @auth (2020/04/05 20:22) // @param authorityId string // @return []string func GetPolicyPathByAuthorityId(authorityId string) []string { @@ -74,7 +76,7 @@ func GetPolicyPathByAuthorityId(authorityId string) []string { // @title ClearCasbin // @description 清除匹配的权限 -// @auth (2020/04/05 20:22 ) +// @auth (2020/04/05 20:22) // @param v int // @param p string // @return bool @@ -86,7 +88,7 @@ func ClearCasbin(v int, p ...string) bool { // @title Casbin // @description store to DB, 持久化到数据库 引入自定义规则 -// @auth (2020/04/05 20:22 ) +// @auth (2020/04/05 20:22) func Casbin() *casbin.Enforcer { a := gormadapter.NewAdapterByDB(global.GVA_DB) e := casbin.NewEnforcer(global.GVA_CONFIG.Casbin.ModelPath, a) @@ -97,7 +99,7 @@ func Casbin() *casbin.Enforcer { // @title ParamsMatch // @description customized rule, 自定义规则函数 -// @auth (2020/04/05 20:22 ) +// @auth (2020/04/05 20:22) // @param fullNameKey1 string // @param key2 string // @return bool @@ -109,7 +111,7 @@ func ParamsMatch(fullNameKey1 string, key2 string) bool { // @title ParamsMatchFunc // @description customized function, 自定义规则函数 -// @auth (2020/04/05 20:22 ) +// @auth (2020/04/05 20:22) // @param args ...interface{} // @return interface{} // @return error diff --git a/server/service/sys_menu.go b/server/service/sys_menu.go index d4a0c739..02b11da2 100644 --- a/server/service/sys_menu.go +++ b/server/service/sys_menu.go @@ -9,10 +9,10 @@ import ( // @title GetMenuTree // @description 获取动态菜单树 -// @auth (2020/04/05 20:22 ) +// @auth (2020/04/05 20:22) // @param authorityId string // @return err error -// @return menus []SysMenu +// @return 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 = ?" @@ -25,9 +25,9 @@ func GetMenuTree(authorityId string) (err error, menus []model.SysMenu) { // @title getChildrenList // @description 获取子菜单 -// @auth (2020/04/05 20:22 ) -// @param menu *SysMenu -// @param SQLstatement string +// @auth (2020/04/05 20:22) +// @param menu *model.SysMenu +// @param sql string // @return 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 @@ -39,9 +39,11 @@ func getChildrenList(menu *model.SysMenu, sql string) (err error) { // @title GetInfoList // @description 获取路由分页 -// @auth (2020/04/05 20:22 ) -// @param newPassword string +// @auth (2020/04/05 20:22) +// @param info request.PageInfo // @return err error +// @return list interface{} +// @return total int func GetInfoList(info request.PageInfo) (err error, list interface{}, total int) { limit := info.PageSize offset := info.PageSize * (info.Page - 1) @@ -56,8 +58,8 @@ func GetInfoList(info request.PageInfo) (err error, list interface{}, total int) // @title getBaseChildrenList // @description get children of menu, 获取菜单的子菜单 -// @auth (2020/04/05 20:22 ) -// @param menu *SysBaseMenu +// @auth (2020/04/05 20:22) +// @param menu *model.SysBaseMenu // @return 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 @@ -69,8 +71,8 @@ func getBaseChildrenList(menu *model.SysBaseMenu) (err error) { // @title AddBaseMenu // @description 函数的详细描述 -// @auth (2020/04/05 20:22 ) -// @param newPassword string +// @auth (2020/04/05 20:22) +// @param menu *model.SysBaseMenu // @return err error //增加基础路由 func AddBaseMenu(menu model.SysBaseMenu) (err error) { @@ -85,7 +87,7 @@ func AddBaseMenu(menu model.SysBaseMenu) (err error) { // @title GetBaseMenuTree // @description 获取基础路由树 -// @auth (2020/04/05 20:22 ) +// @auth (2020/04/05 20:22) // @return err error // @return menus []SysBaseMenu func GetBaseMenuTree() (err error, menus []model.SysBaseMenu) { @@ -98,8 +100,8 @@ func GetBaseMenuTree() (err error, menus []model.SysBaseMenu) { // @title AddMenuAuthority // @description 为角色增加menu树 -// @auth (2020/04/05 20:22 ) -// @param menus []SysBaseMenu +// @auth (2020/04/05 20:22) +// @param menus []model.SysBaseMenu // @param authorityId string // @return error func AddMenuAuthority(menus []model.SysBaseMenu, authorityId string) (err error) { @@ -112,7 +114,7 @@ func AddMenuAuthority(menus []model.SysBaseMenu, authorityId string) (err error) // @title GetMenuAuthority // @description 查看当前角色树 -// @auth (2020/04/05 20:22 ) +// @auth (2020/04/05 20:22) // @param authorityId string // @return err error // @return menus []SysBaseMenu diff --git a/server/service/sys_system.go b/server/service/sys_system.go index b7df76fe..4934ee21 100644 --- a/server/service/sys_system.go +++ b/server/service/sys_system.go @@ -9,7 +9,7 @@ import ( // @title GetSystemConfig // @description 读取配置文件 -// @auth (2020/04/05 20:22 ) +// @auth (2020/04/05 20:22) // @return err error // @return conf Server func GetSystemConfig() (err error, conf config.Server) { @@ -19,10 +19,11 @@ func GetSystemConfig() (err error, conf config.Server) { // @title SetSystemConfig // @description set system config, 设置配置文件 -// @auth (2020/04/05 20:22 ) +// @auth (2020/04/05 20:22) +// @param system model.System // @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 { global.GVA_VP.Set(k, v) } diff --git a/server/service/sys_user.go b/server/service/sys_user.go index a8e63cf9..09c03323 100644 --- a/server/service/sys_user.go +++ b/server/service/sys_user.go @@ -11,7 +11,8 @@ import ( // @title Register // @description register, 用户注册 -// @auth (2020/04/05 20:22 ) +// @auth (2020/04/05 20:22) +// @param u model.SysUser // @return err error // @return userInter *SysUser func Register(u model.SysUser) (err error, userInter model.SysUser) { @@ -32,7 +33,8 @@ func Register(u model.SysUser) (err error, userInter model.SysUser) { // @title Login // @description login, 用户登录 -// @auth (2020/04/05 20:22 ) +// @auth (2020/04/05 20:22) +// @param u *model.SysUser // @return err error // @return userInter *SysUser func Login(u *model.SysUser) (err error, userInter *model.SysUser) { @@ -48,7 +50,8 @@ func Login(u *model.SysUser) (err error, userInter *model.SysUser) { // @title ChangePassword // @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 // @return err error // @return userInter *SysUser @@ -62,8 +65,8 @@ func ChangePassword(u *model.SysUser, newPassword string) (err error, userInter // @title GetInfoList // @description get user list by pagination, 分页获取数据 -// @auth (2020/04/05 20:22 ) -// @param PageInfo int +// @auth (2020/04/05 20:22) +// @param info request.PageInfo // @return err error // @return list interface{} // @return total int @@ -78,7 +81,7 @@ func GetUserInfoList(info request.PageInfo) (err error, list interface{}, total // @title SetUserAuthority // @description set the authority of a certain user, 设置一个用户的权限 -// @auth (2020/04/05 20:22 ) +// @auth (2020/04/05 20:22) // @param uuid UUID // @param authorityId string // @return err error @@ -89,7 +92,7 @@ func SetUserAuthority(uuid uuid.UUID, authorityId string) (err error) { // @title UploadHeaderImg // @description upload avatar, 用户头像上传更新地址 -// @auth (2020/04/05 20:22 ) +// @auth (2020/04/05 20:22) // @param uuid UUID // @param filePath string // @return err error diff --git a/server/service/sys_workflow.go b/server/service/sys_workflow.go index 5d1ed246..8c2fe968 100644 --- a/server/service/sys_workflow.go +++ b/server/service/sys_workflow.go @@ -7,7 +7,8 @@ import ( // @title Create // @description create a workflow, 创建工作流 -// @auth (2020/04/05 20:22 ) +// @auth (2020/04/05 20:22) +// @param wk model.SysWorkflow // @return error func Create(wk model.SysWorkflow) error { err := global.GVA_DB.Create(&wk).Error diff --git a/server/utils/directory.go b/server/utils/directory.go index 94258491..e252cc75 100644 --- a/server/utils/directory.go +++ b/server/utils/directory.go @@ -4,7 +4,7 @@ import "os" // @title PathExists // @description 文件目录是否存在 -// @auth (2020/04/05 20:22 ) +// @auth (2020/04/05 20:22) // @param path string // @return err error func PathExists(path string) (bool, error) { @@ -20,7 +20,7 @@ func PathExists(path string) (bool, error) { // @title createDir // @description 批量创建文件夹 -// @auth (2020/04/05 20:22 ) +// @auth (2020/04/05 20:22) // @param dirs string // @return err error func CreateDir(dirs ...string) (err error) { -- GitLab