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. 6
      server/service/exa_customer.go
  6. 2
      server/service/exa_file_upload_download.go
  7. 8
      server/service/jwt_black_list.go
  8. 6
      server/service/sys_api.go
  9. 5
      server/service/sys_authority.go
  10. 4
      server/service/sys_menu.go
  11. 7
      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) { func CreateAuthority(c *gin.Context) {
var auth model.SysAuthority var auth model.SysAuthority
_ = c.ShouldBindJSON(&auth) _ = c.ShouldBindJSON(&auth)
err, authBack := service.CreateAuthority(&auth)
err, authBack := service.CreateAuthority(auth)
if err != nil { if err != nil {
response.FailWithMessage(fmt.Sprintf("创建失败,%v", err), c) response.FailWithMessage(fmt.Sprintf("创建失败,%v", err), c)
} else { } 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{ modelJwt := model.JwtBlacklist{
Jwt: token, Jwt: token,
} }
err := service.JsonInBlacklist(&modelJwt)
err := service.JsonInBlacklist(modelJwt)
if err != nil { if err != nil {
response.FailWithMessage(fmt.Sprintf("jwt作废失败,%v", err), c) response.FailWithMessage(fmt.Sprintf("jwt作废失败,%v", err), c)
} else { } else {

8
server/api/v1/sys_user.go

@ -33,11 +33,11 @@ func Register(c *gin.Context) {
var R request.RegisterStruct var R request.RegisterStruct
_ = c.ShouldBindJSON(&R) _ = c.ShouldBindJSON(&R)
user := &model.SysUser{Username: R.Username, NickName: R.NickName, Password: R.Password, HeaderImg: R.HeaderImg, AuthorityId: R.AuthorityId} 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 { 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 { } 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 { } else {
var blackJWT model.JwtBlacklist var blackJWT model.JwtBlacklist
blackJWT.Jwt = jwtStr blackJWT.Jwt = jwtStr
err3 := service.JsonInBlacklist(&blackJWT)
err3 := service.JsonInBlacklist(blackJWT)
if err3 != nil { if err3 != nil {
response.FailWithMessage("jwt作废失败", c) response.FailWithMessage("jwt作废失败", c)
} else { } else {

2
server/middleware/jwt.go

@ -26,7 +26,7 @@ func JWTAuth() gin.HandlerFunc {
c.Abort() c.Abort()
return return
} }
if service.IsBlacklist(token, &modelToken) {
if service.IsBlacklist(token, modelToken) {
response.Result(response.ERROR, gin.H{ response.Result(response.ERROR, gin.H{
"reload": true, "reload": true,
}, "您的帐户异地登陆或令牌失效", c) }, "您的帐户异地登陆或令牌失效", c)

6
server/service/exa_customer.go

@ -11,7 +11,7 @@ import (
// @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) {
err = global.GVA_DB.Create(e).Error
err = global.GVA_DB.Create(&e).Error
return err return err
} }
@ -39,7 +39,7 @@ func UpdateExaCustomer(e *model.ExaCustomer) (err error) {
// @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) {
err = global.GVA_DB.Where("id = ?",id).First(&customer).Error
err = global.GVA_DB.Where("id = ?", id).First(&customer).Error
return return
} }
@ -57,7 +57,7 @@ func GetCustomerInfoList(sysUserAuthorityID string, info request.PageInfo) (err
} else { } else {
var a model.SysAuthority var a model.SysAuthority
a.AuthorityId = sysUserAuthorityID a.AuthorityId = sysUserAuthorityID
err, auth :=GetAuthorityInfo(a)
err, auth := GetAuthorityInfo(a)
var dataId []string var dataId []string
for _, v := range auth.DataAuthorityId { for _, v := range auth.DataAuthorityId {
dataId = append(dataId, v.AuthorityId) dataId = append(dataId, v.AuthorityId)

2
server/service/exa_file_upload_download.go

@ -11,7 +11,7 @@ import (
// @auth (2020/04/05 20:22 ) // @auth (2020/04/05 20:22 )
// @return error // @return error
func Upload(f model.ExaFileUploadAndDownload) error { func Upload(f model.ExaFileUploadAndDownload) error {
err := global.GVA_DB.Create(f).Error
err := global.GVA_DB.Create(&f).Error
return err return err
} }

8
server/service/jwt_black_list.go

@ -9,8 +9,8 @@ import (
// @description create jwt blacklist // @description create jwt blacklist
// @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(j model.JwtBlacklist) (err error) {
err = global.GVA_DB.Create(&j).Error
return return
} }
@ -19,8 +19,8 @@ func JsonInBlacklist(j *model.JwtBlacklist) (err error) {
// @auth (2020/04/05 20:22 ) // @auth (2020/04/05 20:22 )
// @param newPassword string // @param newPassword string
// @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, j model.JwtBlacklist) bool {
isNotFound := global.GVA_DB.Where("jwt = ?", Jwt).First(&j).RecordNotFound()
return !isNotFound return !isNotFound
} }

6
server/service/sys_api.go

@ -15,11 +15,11 @@ import (
// @param FilePath string // @param FilePath string
// @return error // @return error
func CreateApi(a model.SysApi) (err 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 { 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(&a).Error
} }
return err return err
} }
@ -111,7 +111,7 @@ func GetApiById(id float64) (err error, api model.SysApi) {
// @return error // @return error
func UpdateApi(a model.SysApi) (err error) { func UpdateApi(a model.SysApi) (err error) {
var oldA model.SysApi 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 { if !flag {
return errors.New("存在相同api路径") return errors.New("存在相同api路径")
} }

5
server/service/sys_authority.go

@ -14,8 +14,8 @@ import (
// @param FileName string // @param FileName string
// @param FilePath string // @param FilePath string
// @return error // @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 return err, a
} }
@ -86,7 +86,6 @@ func GetAuthorityInfo(a model.SysAuthority) (err error, sa model.SysAuthority)
return err, sa return err, sa
} }
// @title SetDataAuthority // @title SetDataAuthority
// @description 设置角色资源权限 // @description 设置角色资源权限
// @auth (2020/04/05 20:22 ) // @auth (2020/04/05 20:22 )

4
server/service/sys_menu.go

@ -80,14 +80,13 @@ func getBaseChildrenList(menu *model.SysBaseMenu) (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 findOne := global.GVA_DB.Where("name = ?", menu.Name).Find(&model.SysBaseMenu{}).Error
if findOne != nil { if findOne != nil {
err = global.GVA_DB.Create(menu).Error
err = global.GVA_DB.Create(&menu).Error
} else { } else {
err = errors.New("存在重复name,请修改name") err = errors.New("存在重复name,请修改name")
} }
return err return err
} }
// @title GetBaseMenuTree // @title GetBaseMenuTree
// @description 获取基础路由树 // @description 获取基础路由树
// @auth (2020/04/05 20:22 ) // @auth (2020/04/05 20:22 )
@ -115,7 +114,6 @@ func AddMenuAuthority(menus []model.SysBaseMenu, authorityId string) (err error
return err return err
} }
// @title GetMenuAuthority // @title GetMenuAuthority
// @description 查看当前角色树 // @description 查看当前角色树
// @auth (2020/04/05 20:22 ) // @auth (2020/04/05 20:22 )

7
server/service/sys_user.go

@ -14,18 +14,18 @@ import (
// @auth (2020/04/05 20:22 ) // @auth (2020/04/05 20:22 )
// @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) {
var user model.SysUser var user model.SysUser
//判断用户名是否注册 //判断用户名是否注册
notRegister := global.GVA_DB.Where("username = ?", u.Username).First(&user).RecordNotFound() notRegister := global.GVA_DB.Where("username = ?", u.Username).First(&user).RecordNotFound()
//notRegister为false表明读取到了 不能注册 //notRegister为false表明读取到了 不能注册
if !notRegister { if !notRegister {
return errors.New("用户名已注册"), nil
return errors.New("用户名已注册"), userInter
} else { } else {
// 否则 附加uuid 密码md5简单加密 注册 // 否则 附加uuid 密码md5简单加密 注册
u.Password = utils.MD5V([]byte(u.Password)) u.Password = utils.MD5V([]byte(u.Password))
u.UUID = uuid.NewV4() u.UUID = uuid.NewV4()
err = global.GVA_DB.Create(u).Error
err = global.GVA_DB.Create(&u).Error
} }
return err, u return err, u
} }
@ -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 err = global.GVA_DB.Where("uuid = ?", uuid).First(&user).Update("header_img", filePath).First(&user).Error
return err, &user 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-input v-model="form.structName" placeholder="首字母自动转换大写"></el-input>
</el-form-item> </el-form-item>
<el-form-item label="Struct简称" prop="abbreviation"> <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>
<el-form-item label="Package名称" prop="packageName"> <el-form-item label="Package名称" prop="packageName">
<el-input v-model="form.packageName"></el-input> <el-input v-model="form.packageName"></el-input>
@ -152,6 +152,13 @@ export default {
this.$refs.autoCodeForm.validate(async (valid) => { this.$refs.autoCodeForm.validate(async (valid) => {
if (valid) { if (valid) {
this.form.structName = toUpperCase(this.form.structName) 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 data = await createTemp(this.form)
const blob = new Blob([data]) const blob = new Blob([data])
const fileName = 'ginvueadmin.zip' const fileName = 'ginvueadmin.zip'

Loading…
Cancel
Save