diff --git "a/server/GORMV2\346\216\245\345\217\243\346\265\213\350\257\225\346\226\207\346\241\243.md" "b/server/GORMV2\346\216\245\345\217\243\346\265\213\350\257\225\346\226\207\346\241\243.md" index 7f16aac4446bcf08da35819334582b836f0483f8..2c3e7d5aa1e0dd36552a5615e127a28d413dc8f7 100644 --- "a/server/GORMV2\346\216\245\345\217\243\346\265\213\350\257\225\346\226\207\346\241\243.md" +++ "b/server/GORMV2\346\216\245\345\217\243\346\265\213\350\257\225\346\226\207\346\241\243.md" @@ -1,68 +1,68 @@ -| 路由path | 路由描述 | 测试情况 | -| ------------------------------------------------- | ----------------------- | :------: | -| /base/login | 用户登录 | √ | -| /base/register | 用户注册 | | -| /api/createApi | 创建api | | -| /api/getApiList | 获取api详细信息 | | -| /api/deleteApi | 删除Api | | -| /api/updateApi | 更新Api | | -| /api/getAllApis | 获取所有api | | -| /authority/createAuthority | 创建角色 | √ | -| /authority/createAuthority | 创建子角色 | √ | -| /authority/deleteAuthority | 删除角色 | √ | -| /authority/getAuthorityList | 获取角色列表 | √ | -| /menu/getMenu | 获取菜单树 | | -| /menu/getMenuList | 分页获取基础menu列表 | | -| /menu/addBaseMenu | 新增菜单 | | -| /menu/getBaseMenuTree | 获取用户动态路由 | | -| /menu/addMenuAuthority | 增加menu和角色关联关系 | | -| /menu/getMenuAuthority | 获取指定角色menu | | -| /menu/deleteBaseMenu | 删除菜单 | | -| /menu/updateBaseMenu | 更新菜单 | | -| /menu/getBaseMenuById | 根据id获取菜单 | | -| /user/changePassword | 修改密码 | | -| /user/uploadHeaderImg | 上传头像 | | -| /user/getInfoList | 分页获取用户列表 | | -| /user/getUserList | 获取用户列表 | | -| /user/setUserAuthority | 修改用户角色 | | -| /fileUploadAndDownload/upload | 文件上传示例 | | -| /fileUploadAndDownload/getFileList | 获取上传文件列表 | | -| /casbin/updateCasbin | 更改角色api权限 | | -| /casbin/getPolicyPathByAuthorityId | 获取权限列表 | | -| /fileUploadAndDownload/deleteFile | 删除文件 | | -| /jwt/jsonInBlacklist | jwt加入黑名单 | | -| /authority/setDataAuthority | 设置角色资源权限 | | -| /system/getSystemConfig | 获取配置文件内容 | | -| /system/setSystemConfig | 设置配置文件内容 | | -| /customer/customer | 创建客户 | | -| /customer/customer | 更新客户 | | -| /customer/customer | 删除客户 | | -| /customer/customer | 获取单一客户 | | -| /customer/customerList | 获取客户列表 | | -| /casbin/casbinTest/:pathParam | RESTFUL模式测试 | | -| /autoCode/createTemp | 自动化代码 | | -| /authority/updateAuthority | 更新角色信息 | | -| /authority/copyAuthority | 拷贝角色 | | -| /user/deleteUser | 删除用户 | | -| /sysDictionaryDetail/createSysDictionaryDetail | 新增字典内容 | | -| /sysDictionaryDetail/deleteSysDictionaryDetail | 新增字典内容 | | -| /sysDictionaryDetail/updateSysDictionaryDetail | 新增字典内容 | | -| /sysDictionaryDetail/findSysDictionaryDetail | 根据ID获取字典内容 | | -| /sysDictionaryDetail/getSysDictionaryDetailList | 获取字典内容列表 | | -| /sysDictionary/createSysDictionary | 新增字典 | | -| /sysDictionary/deleteSysDictionary | 删除字典 | | -| /sysDictionary/updateSysDictionary | 更新字典 | | -| /sysDictionary/findSysDictionary | 根据ID获取字典 | | -| /sysDictionary/getSysDictionaryList | 获取字典列表 | | -| /sysOperationRecord/createSysOperationRecord | 新增操作记录 | | -| /sysOperationRecord/deleteSysOperationRecord | 删除操作记录 | | -| /sysOperationRecord/updateSysOperationRecord | 更新操作记录 | | -| /sysOperationRecord/findSysOperationRecord | 根据ID获取操作记录 | | -| /sysOperationRecord/getSysOperationRecordList | 获取操作记录列表 | | -| /autoCode/getTables | 获取数据库表 | √ | -| /autoCode/getDB | 获取所有数据库 | √ | -| /autoCode/getColume | 获取所选table的所有字段 | √ | -| /sysOperationRecord/deleteSysOperationRecordByIds | 批量删除操作历史 | | -| /simpleUploader/upload | 插件版分片上传 | | -| /simpleUploader/checkFileMd5 | 文件完整度验证 | | -| /simpleUploader/mergeFileMd5 | 上传完成合并文件 | | +| 路由path | 路由描述 | 测试情况 | 备注 | +| ------------------------------------------------- | ----------------------- | :------: | ---------- | +| /base/login | 用户登录 | √ | SliverHorn | +| /base/register | 用户注册 | | | +| /api/createApi | 创建api | √ | SliverHorn | +| /api/getApiList | 获取api详细信息 | √ | SliverHorn | +| /api/deleteApi | 删除Api | √ | SliverHorn | +| /api/updateApi | 更新Api | √ | SliverHorn | +| /api/getAllApis | 获取所有api | √ | SliverHorn | +| /authority/createAuthority | 创建角色 | √ | SliverHorn | +| /authority/createAuthority | 创建子角色 | √ | SliverHorn | +| /authority/deleteAuthority | 删除角色 | √ | SliverHorn | +| /authority/getAuthorityList | 获取角色列表 | √ | SliverHorn | +| /menu/getMenu | 获取菜单树 | √ | SliverHorn | +| /menu/getMenuList | 分页获取基础menu列表 | | | +| /menu/addBaseMenu | 新增菜单 | | | +| /menu/getBaseMenuTree | 获取用户动态路由 | | | +| /menu/addMenuAuthority | 增加menu和角色关联关系 | | | +| /menu/getMenuAuthority | 获取指定角色menu | | | +| /menu/deleteBaseMenu | 删除菜单 | | | +| /menu/updateBaseMenu | 更新菜单 | | | +| /menu/getBaseMenuById | 根据id获取菜单 | | | +| /user/changePassword | 修改密码 | | | +| /user/uploadHeaderImg | 上传头像 | | | +| /user/getInfoList | 分页获取用户列表 | | | +| /user/getUserList | 获取用户列表 | | | +| /user/setUserAuthority | 修改用户角色 | | | +| /fileUploadAndDownload/upload | 文件上传示例 | | | +| /fileUploadAndDownload/getFileList | 获取上传文件列表 | | | +| /casbin/updateCasbin | 更改角色api权限 | | | +| /casbin/getPolicyPathByAuthorityId | 获取权限列表 | | | +| /fileUploadAndDownload/deleteFile | 删除文件 | | | +| /jwt/jsonInBlacklist | jwt加入黑名单 | | | +| /authority/setDataAuthority | 设置角色资源权限 | | | +| /system/getSystemConfig | 获取配置文件内容 | | | +| /system/setSystemConfig | 设置配置文件内容 | | | +| /customer/customer | 创建客户 | | | +| /customer/customer | 更新客户 | | | +| /customer/customer | 删除客户 | | | +| /customer/customer | 获取单一客户 | | | +| /customer/customerList | 获取客户列表 | | | +| /casbin/casbinTest/:pathParam | RESTFUL模式测试 | | | +| /autoCode/createTemp | 自动化代码 | | | +| /authority/updateAuthority | 更新角色信息 | | | +| /authority/copyAuthority | 拷贝角色 | | | +| /user/deleteUser | 删除用户 | | | +| /sysDictionaryDetail/createSysDictionaryDetail | 新增字典内容 | | | +| /sysDictionaryDetail/deleteSysDictionaryDetail | 新增字典内容 | | | +| /sysDictionaryDetail/updateSysDictionaryDetail | 新增字典内容 | | | +| /sysDictionaryDetail/findSysDictionaryDetail | 根据ID获取字典内容 | | | +| /sysDictionaryDetail/getSysDictionaryDetailList | 获取字典内容列表 | | | +| /sysDictionary/createSysDictionary | 新增字典 | | | +| /sysDictionary/deleteSysDictionary | 删除字典 | | | +| /sysDictionary/updateSysDictionary | 更新字典 | | | +| /sysDictionary/findSysDictionary | 根据ID获取字典 | | | +| /sysDictionary/getSysDictionaryList | 获取字典列表 | | | +| /sysOperationRecord/createSysOperationRecord | 新增操作记录 | | | +| /sysOperationRecord/deleteSysOperationRecord | 删除操作记录 | | | +| /sysOperationRecord/updateSysOperationRecord | 更新操作记录 | | | +| /sysOperationRecord/findSysOperationRecord | 根据ID获取操作记录 | | | +| /sysOperationRecord/getSysOperationRecordList | 获取操作记录列表 | | | +| /autoCode/getTables | 获取数据库表 | √ | | +| /autoCode/getDB | 获取所有数据库 | √ | | +| /autoCode/getColume | 获取所选table的所有字段 | √ | | +| /sysOperationRecord/deleteSysOperationRecordByIds | 批量删除操作历史 | | | +| /simpleUploader/upload | 插件版分片上传 | | | +| /simpleUploader/checkFileMd5 | 文件完整度验证 | | | +| /simpleUploader/mergeFileMd5 | 上传完成合并文件 | | | diff --git a/server/service/sys_api.go b/server/service/sys_api.go index 68bdab6eeb7641cdb1f677f9d68fe60109ab85a5..f871503453609502fbe7b927473729cdae3c7c54 100644 --- a/server/service/sys_api.go +++ b/server/service/sys_api.go @@ -15,13 +15,10 @@ import ( // @return 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 !errors.Is(global.GVA_DB.Where("path = ? AND method = ?", api.Path, api.Method).First(&model.SysApi{}).Error, gorm.ErrRecordNotFound){ return errors.New("存在相同api") - } else { - err = global.GVA_DB.Create(&api).Error } - return err + return global.GVA_DB.Create(&api).Error } // @title DeleteApi @@ -125,8 +122,7 @@ func UpdateApi(api model.SysApi) (err error) { err = global.GVA_DB.Where("id = ?", api.ID).First(&oldA).Error if oldA.Path != api.Path || oldA.Method != api.Method { - flag := errors.Is(global.GVA_DB.Where("path = ? AND method = ?", api.Path, api.Method).Find(&model.SysApi{}).Error, gorm.ErrRecordNotFound) - if !flag { + if !errors.Is(global.GVA_DB.Where("path = ? AND method = ?", api.Path, api.Method).First(&model.SysApi{}).Error, gorm.ErrRecordNotFound) { return errors.New("存在相同api路径") } } diff --git a/server/service/sys_casbin.go b/server/service/sys_casbin.go index 790ce6fde5815fef7f898cb477813a3611d55913..19c7721d932452229351a5d35fc652328edc802a 100644 --- a/server/service/sys_casbin.go +++ b/server/service/sys_casbin.go @@ -58,8 +58,7 @@ func AddCasbin(cm model.CasbinModel) bool { // @return 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).Updates(map[string]string{ + err := global.GVA_DB.Table("casbin_rule").Model(&model.CasbinModel{}).Where("v1 = ? AND v2 = ?", oldPath, oldMethod).Updates(map[string]interface{}{ "v1": newPath, "v2": newMethod, }).Error