Browse Source

修復部分創建bug,數據庫api更新權限更改

main
pixel 5 years ago
parent
commit
c7e2155146
  1. 4
      server/api/v1/sys_authority.go
  2. 2
      server/api/v1/sys_jwt_blacklist.go
  3. 8
      server/api/v1/sys_user.go
  4. 2
      server/middleware/jwt.go
  5. 10
      server/service/exa_customer.go
  6. 2
      server/service/exa_file_upload_download.go
  7. 8
      server/service/jwt_black_list.go
  8. 8
      server/service/sys_api.go
  9. 9
      server/service/sys_authority.go
  10. 14
      server/service/sys_menu.go
  11. 11
      server/service/sys_user.go
  12. 9
      web/src/view/systemTools/autoCode/index.vue

4
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)
}
}

2
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 {

8
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 {

2
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)

10
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)

2
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
}

8
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
}

8
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路径")
}

9
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

14
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
}
}

11
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
}

9
web/src/view/systemTools/autoCode/index.vue

@ -6,7 +6,7 @@
<el-input v-model="form.structName" placeholder="首字母自动转换大写"></el-input>
</el-form-item>
<el-form-item label="Struct简称" prop="abbreviation">
<el-input v-model="form.abbreviation"></el-input>
<el-input v-model="form.abbreviation" placeholder="简称会作为入参对象名和路由group"></el-input>
</el-form-item>
<el-form-item label="Package名称" prop="packageName">
<el-input v-model="form.packageName"></el-input>
@ -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'

Loading…
Cancel
Save