From c7e2155146a39d4e312736e147c816408292c86c Mon Sep 17 00:00:00 2001 From: pixel <303176530@qq.com> Date: Thu, 9 Apr 2020 11:07:43 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=BE=A9=E9=83=A8=E5=88=86=E5=89=B5?= =?UTF-8?q?=E5=BB=BAbug=EF=BC=8C=E6=95=B8=E6=93=9A=E5=BA=ABapi=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E6=AC=8A=E9=99=90=E6=9B=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/api/v1/sys_authority.go | 4 ++-- server/api/v1/sys_jwt_blacklist.go | 2 +- server/api/v1/sys_user.go | 8 ++++---- server/middleware/jwt.go | 2 +- server/service/exa_customer.go | 10 +++++----- server/service/exa_file_upload_download.go | 2 +- server/service/jwt_black_list.go | 8 ++++---- server/service/sys_api.go | 8 ++++---- server/service/sys_authority.go | 9 ++++----- server/service/sys_menu.go | 14 ++++++-------- server/service/sys_user.go | 11 +++++------ web/src/view/systemTools/autoCode/index.vue | 9 ++++++++- 12 files changed, 45 insertions(+), 42 deletions(-) diff --git a/server/api/v1/sys_authority.go b/server/api/v1/sys_authority.go index 7135f54e..690d3a7d 100644 --- a/server/api/v1/sys_authority.go +++ b/server/api/v1/sys_authority.go @@ -21,11 +21,11 @@ import ( func CreateAuthority(c *gin.Context) { var auth model.SysAuthority _ = c.ShouldBindJSON(&auth) - err, authBack := service.CreateAuthority(&auth) + err, authBack := service.CreateAuthority(auth) if err != nil { response.FailWithMessage(fmt.Sprintf("创建失败,%v", err), c) } else { - response.OkWithData(resp.SysAuthorityResponse{Authority: *authBack}, c) + response.OkWithData(resp.SysAuthorityResponse{Authority: authBack}, c) } } diff --git a/server/api/v1/sys_jwt_blacklist.go b/server/api/v1/sys_jwt_blacklist.go index 5b6d7ba3..235d5668 100644 --- a/server/api/v1/sys_jwt_blacklist.go +++ b/server/api/v1/sys_jwt_blacklist.go @@ -20,7 +20,7 @@ func JsonInBlacklist(c *gin.Context) { modelJwt := model.JwtBlacklist{ Jwt: token, } - err := service.JsonInBlacklist(&modelJwt) + err := service.JsonInBlacklist(modelJwt) if err != nil { response.FailWithMessage(fmt.Sprintf("jwt作废失败,%v", err), c) } else { diff --git a/server/api/v1/sys_user.go b/server/api/v1/sys_user.go index 78460b29..b1266adf 100644 --- a/server/api/v1/sys_user.go +++ b/server/api/v1/sys_user.go @@ -33,11 +33,11 @@ func Register(c *gin.Context) { var R request.RegisterStruct _ = c.ShouldBindJSON(&R) user := &model.SysUser{Username: R.Username, NickName: R.NickName, Password: R.Password, HeaderImg: R.HeaderImg, AuthorityId: R.AuthorityId} - err, user := service.Register(user) + err, userReturn := service.Register(*user) if err != nil { - response.FailWithDetailed(response.ERROR, resp.SysUserResponse{User: *user}, fmt.Sprintf("%v", err), c) + response.FailWithDetailed(response.ERROR, resp.SysUserResponse{User: userReturn}, fmt.Sprintf("%v", err), c) } else { - response.OkDetailed(resp.SysUserResponse{User: *user}, "注册成功", c) + response.OkDetailed(resp.SysUserResponse{User: userReturn}, "注册成功", c) } } @@ -103,7 +103,7 @@ func tokenNext(c *gin.Context, user model.SysUser) { } else { var blackJWT model.JwtBlacklist blackJWT.Jwt = jwtStr - err3 := service.JsonInBlacklist(&blackJWT) + err3 := service.JsonInBlacklist(blackJWT) if err3 != nil { response.FailWithMessage("jwt作废失败", c) } else { diff --git a/server/middleware/jwt.go b/server/middleware/jwt.go index cfc9d0bb..bb1b0039 100644 --- a/server/middleware/jwt.go +++ b/server/middleware/jwt.go @@ -26,7 +26,7 @@ func JWTAuth() gin.HandlerFunc { c.Abort() return } - if service.IsBlacklist(token, &modelToken) { + if service.IsBlacklist(token, modelToken) { response.Result(response.ERROR, gin.H{ "reload": true, }, "您的帐户异地登陆或令牌失效", c) diff --git a/server/service/exa_customer.go b/server/service/exa_customer.go index dca99f17..2f8baec7 100644 --- a/server/service/exa_customer.go +++ b/server/service/exa_customer.go @@ -11,7 +11,7 @@ import ( // @auth (2020/04/05 20:22 ) // @return err error func CreateExaCustomer(e model.ExaCustomer) (err error) { - err = global.GVA_DB.Create(e).Error + err = global.GVA_DB.Create(&e).Error return err } @@ -19,7 +19,7 @@ func CreateExaCustomer(e model.ExaCustomer) (err error) { // @description delete a customer, 删除用户 // @auth (2020/04/05 20:22 ) // @return error -func DeleteExaCustomer(e model.ExaCustomer) (err error) { +func DeleteExaCustomer(e model.ExaCustomer) (err error) { err = global.GVA_DB.Delete(e).Error return err } @@ -39,7 +39,7 @@ func UpdateExaCustomer(e *model.ExaCustomer) (err error) { // @return error // @return customer ExaCustomer func GetExaCustomer(id uint) (err error, customer model.ExaCustomer) { - err = global.GVA_DB.Where("id = ?",id).First(&customer).Error + err = global.GVA_DB.Where("id = ?", id).First(&customer).Error return } @@ -48,7 +48,7 @@ func GetExaCustomer(id uint) (err error, customer model.ExaCustomer) { // @auth (2020/04/05 20:22 ) // @param info PageInfo // @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) { limit := info.PageSize offset := info.PageSize * (info.Page - 1) db := global.GVA_DB @@ -57,7 +57,7 @@ func GetCustomerInfoList(sysUserAuthorityID string, info request.PageInfo) (err } else { var a model.SysAuthority a.AuthorityId = sysUserAuthorityID - err, auth :=GetAuthorityInfo(a) + err, auth := GetAuthorityInfo(a) var dataId []string for _, v := range auth.DataAuthorityId { dataId = append(dataId, v.AuthorityId) diff --git a/server/service/exa_file_upload_download.go b/server/service/exa_file_upload_download.go index 5c14d940..e56953b4 100644 --- a/server/service/exa_file_upload_download.go +++ b/server/service/exa_file_upload_download.go @@ -11,7 +11,7 @@ import ( // @auth (2020/04/05 20:22 ) // @return error func Upload(f model.ExaFileUploadAndDownload) error { - err := global.GVA_DB.Create(f).Error + err := global.GVA_DB.Create(&f).Error return err } diff --git a/server/service/jwt_black_list.go b/server/service/jwt_black_list.go index eab1b55f..388c12c3 100644 --- a/server/service/jwt_black_list.go +++ b/server/service/jwt_black_list.go @@ -9,8 +9,8 @@ import ( // @description create jwt blacklist // @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(j model.JwtBlacklist) (err error) { + err = global.GVA_DB.Create(&j).Error return } @@ -19,8 +19,8 @@ func JsonInBlacklist(j *model.JwtBlacklist) (err error) { // @auth (2020/04/05 20:22 ) // @param newPassword string // @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, j model.JwtBlacklist) bool { + isNotFound := global.GVA_DB.Where("jwt = ?", Jwt).First(&j).RecordNotFound() return !isNotFound } diff --git a/server/service/sys_api.go b/server/service/sys_api.go index 41fce077..b704508c 100644 --- a/server/service/sys_api.go +++ b/server/service/sys_api.go @@ -15,11 +15,11 @@ import ( // @param FilePath string // @return error func CreateApi(a model.SysApi) (err error) { - findOne := global.GVA_DB.Where("path = ?", a.Path).Find(&model.SysApi{}).Error + findOne := global.GVA_DB.Where("path = ? AND method = ?", a.Path, a.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(&a).Error } return err } @@ -109,9 +109,9 @@ func GetApiById(id float64) (err error, api model.SysApi) { // @description update a base api, update api // @auth (2020/04/05 20:22 ) // @return error -func UpdateApi(a model.SysApi) (err error) { +func UpdateApi(a model.SysApi) (err error) { var oldA model.SysApi - flag := global.GVA_DB.Where("path = ?", a.Path).Find(&model.SysApi{}).RecordNotFound() + flag := global.GVA_DB.Where("path = ? AND method = ?", a.Path, a.Method).Find(&model.SysApi{}).RecordNotFound() if !flag { return errors.New("存在相同api路径") } diff --git a/server/service/sys_authority.go b/server/service/sys_authority.go index 0dff4220..49e8f3d3 100644 --- a/server/service/sys_authority.go +++ b/server/service/sys_authority.go @@ -14,8 +14,8 @@ import ( // @param FileName string // @param FilePath string // @return error -func CreateAuthority(a *model.SysAuthority) (err error, authority *model.SysAuthority) { - err = global.GVA_DB.Create(a).Error +func CreateAuthority(a model.SysAuthority) (err error, authority model.SysAuthority) { + err = global.GVA_DB.Create(&a).Error return err, a } @@ -81,12 +81,11 @@ func GetAuthorityInfoList(info request.PageInfo) (err error, list interface{}, t // @param FileName string // @param FilePath string // @return error -func GetAuthorityInfo(a model.SysAuthority) (err error, sa model.SysAuthority) { +func GetAuthorityInfo(a model.SysAuthority) (err error, sa model.SysAuthority) { err = global.GVA_DB.Preload("DataAuthorityId").Where("authority_id = ?", a.AuthorityId).First(&sa).Error return err, sa } - // @title SetDataAuthority // @description 设置角色资源权限 // @auth (2020/04/05 20:22 ) @@ -108,7 +107,7 @@ func SetDataAuthority(a model.SysAuthority) error { // @param FileName string // @param FilePath string // @return error -func SetMenuAuthority(a *model.SysAuthority) error { +func SetMenuAuthority(a *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 diff --git a/server/service/sys_menu.go b/server/service/sys_menu.go index ef5b42c4..0e1b8e5c 100644 --- a/server/service/sys_menu.go +++ b/server/service/sys_menu.go @@ -77,23 +77,22 @@ func getBaseChildrenList(menu *model.SysBaseMenu) (err error) { // @param newPassword string // @return err error //增加基础路由 -func AddBaseMenu(menu model.SysBaseMenu) (err error) { +func AddBaseMenu(menu model.SysBaseMenu) (err error) { findOne := global.GVA_DB.Where("name = ?", menu.Name).Find(&model.SysBaseMenu{}).Error if findOne != nil { - err = global.GVA_DB.Create(menu).Error + err = global.GVA_DB.Create(&menu).Error } else { err = errors.New("存在重复name,请修改name") } return err } - // @title GetBaseMenuTree // @description 获取基础路由树 // @auth (2020/04/05 20:22 ) // @return err error // @return menus []SysBaseMenu -func GetBaseMenuTree() (err error, menus []model.SysBaseMenu) { +func GetBaseMenuTree() (err error, menus []model.SysBaseMenu) { err = global.GVA_DB.Where(" parent_id = ?", 0).Order("sort", true).Find(&menus).Error for i := 0; i < len(menus); i++ { err = getBaseChildrenList(&menus[i]) @@ -107,7 +106,7 @@ func GetBaseMenuTree() (err error, menus []model.SysBaseMenu) { // @param menus []SysBaseMenu // @param authorityId string // @return error -func AddMenuAuthority(menus []model.SysBaseMenu, authorityId string) (err error) { +func AddMenuAuthority(menus []model.SysBaseMenu, authorityId string) (err error) { var auth model.SysAuthority auth.AuthorityId = authorityId auth.SysBaseMenus = menus @@ -115,15 +114,14 @@ 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 -func GetMenuAuthority(authorityId string) (err error, menus []model.SysMenu) { +func GetMenuAuthority(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 = ?" err = global.GVA_DB.Raw(sql, authorityId).Scan(&menus).Error return err, menus -} \ No newline at end of file +} diff --git a/server/service/sys_user.go b/server/service/sys_user.go index 3c414377..f526aad2 100644 --- a/server/service/sys_user.go +++ b/server/service/sys_user.go @@ -14,18 +14,18 @@ import ( // @auth (2020/04/05 20:22 ) // @return err error // @return userInter *SysUser -func Register(u *model.SysUser) (err error, userInter *model.SysUser) { +func Register(u model.SysUser) (err error, userInter model.SysUser) { var user model.SysUser //判断用户名是否注册 notRegister := global.GVA_DB.Where("username = ?", u.Username).First(&user).RecordNotFound() //notRegister为false表明读取到了 不能注册 if !notRegister { - return errors.New("用户名已注册"), nil + return errors.New("用户名已注册"), userInter } else { // 否则 附加uuid 密码md5简单加密 注册 u.Password = utils.MD5V([]byte(u.Password)) u.UUID = uuid.NewV4() - err = global.GVA_DB.Create(u).Error + err = global.GVA_DB.Create(&u).Error } return err, u } @@ -52,7 +52,7 @@ func Login(u *model.SysUser) (err error, userInter *model.SysUser) { // @param newPassword string // @return err error // @return userInter *SysUser -func ChangePassword(u *model.SysUser, newPassword string) (err error, userInter *model.SysUser) { +func ChangePassword(u *model.SysUser, newPassword string) (err error, userInter *model.SysUser) { var user model.SysUser //后期修改jwt+password模式 u.Password = utils.MD5V([]byte(u.Password)) @@ -86,7 +86,7 @@ func GetUserInfoList(info request.PageInfo) (err error, list interface{}, total // @param uuid UUID // @param authorityId string // @return err error -func SetUserAuthority(uuid uuid.UUID, authorityId string) (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 } @@ -103,4 +103,3 @@ func UploadHeaderImg(uuid uuid.UUID, filePath string) (err error, userInter *mod err = global.GVA_DB.Where("uuid = ?", uuid).First(&user).Update("header_img", filePath).First(&user).Error return err, &user } - diff --git a/web/src/view/systemTools/autoCode/index.vue b/web/src/view/systemTools/autoCode/index.vue index e1326d7f..521fd6cd 100644 --- a/web/src/view/systemTools/autoCode/index.vue +++ b/web/src/view/systemTools/autoCode/index.vue @@ -6,7 +6,7 @@ - + @@ -152,6 +152,13 @@ export default { this.$refs.autoCodeForm.validate(async (valid) => { if (valid) { this.form.structName = toUpperCase(this.form.structName) + if(this.form.structName == this.form.abbreviation){ + this.$message({ + type:"error", + message:"structName和struct简称不能相同" + }) + return false + } const data = await createTemp(this.form) const blob = new Blob([data]) const fileName = 'ginvueadmin.zip'