Browse Source

消除冗余代码 细节提示修复

main
pixel 5 years ago
parent
commit
e440b27216
  1. 2
      server/api/v1/exa_customer.go
  2. 28
      server/service/exa_customer.go
  3. 10
      server/service/exa_file_upload_download.go
  4. 59
      server/service/sys_api.go
  5. 16
      server/service/sys_authority.go
  6. 14
      server/service/sys_menu.go
  7. 10
      server/service/sys_user.go

2
server/api/v1/exa_customer.go

@ -105,7 +105,7 @@ func GetExaCustomerList(c *gin.Context) {
_ = c.ShouldBindJSON(&pageInfo) _ = c.ShouldBindJSON(&pageInfo)
err, customerList, total := service.GetCustomerInfoList(waitUse.AuthorityId, pageInfo) err, customerList, total := service.GetCustomerInfoList(waitUse.AuthorityId, pageInfo)
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.PageResult{ response.OkWithData(resp.PageResult{
List: customerList, List: customerList,

28
server/service/exa_customer.go

@ -52,23 +52,19 @@ func GetCustomerInfoList(sysUserAuthorityID string, info request.PageInfo) (err
limit := info.PageSize limit := info.PageSize
offset := info.PageSize * (info.Page - 1) offset := info.PageSize * (info.Page - 1)
db := global.GVA_DB db := global.GVA_DB
var a model.SysAuthority
a.AuthorityId = sysUserAuthorityID
err, auth := GetAuthorityInfo(a)
var dataId []string
for _, v := range auth.DataAuthorityId {
dataId = append(dataId, v.AuthorityId)
}
var CustomerList []model.ExaCustomer
err = db.Where("sys_user_authority_id in (?)", dataId).Find(&CustomerList).Count(&total).Error
if err != nil { if err != nil {
return
} else {
var a model.SysAuthority
a.AuthorityId = sysUserAuthorityID
err, auth := GetAuthorityInfo(a)
var dataId []string
for _, v := range auth.DataAuthorityId {
dataId = append(dataId, v.AuthorityId)
}
var CustomerList []model.ExaCustomer
err = db.Where("sys_user_authority_id in (?)", dataId).Find(&CustomerList).Count(&total).Error
if err != nil {
return err, CustomerList, total
} else {
err = db.Limit(limit).Offset(offset).Preload("SysUser").Where("sys_user_authority_id in (?)", dataId).Find(&CustomerList).Error
}
return err, CustomerList, total return err, CustomerList, total
} else {
err = db.Limit(limit).Offset(offset).Preload("SysUser").Where("sys_user_authority_id in (?)", dataId).Find(&CustomerList).Error
} }
return err, CustomerList, total
} }

10
server/service/exa_file_upload_download.go

@ -45,11 +45,7 @@ func GetFileRecordInfoList(info request.PageInfo) (err error, list interface{},
limit := info.PageSize limit := info.PageSize
offset := info.PageSize * (info.Page - 1) offset := info.PageSize * (info.Page - 1)
db := global.GVA_DB db := global.GVA_DB
if err != nil {
return
} else {
var fileLists []model.ExaFileUploadAndDownload
err = db.Limit(limit).Offset(offset).Order("updated_at desc").Find(&fileLists).Error
return err, fileLists, total
}
var fileLists []model.ExaFileUploadAndDownload
err = db.Limit(limit).Offset(offset).Order("updated_at desc").Find(&fileLists).Error
return err, fileLists, total
} }

59
server/service/sys_api.go

@ -30,7 +30,7 @@ func CreateApi(a model.SysApi) (err error) {
// @return error // @return error
func DeleteApi(a model.SysApi) (err error) { func DeleteApi(a model.SysApi) (err error) {
err = global.GVA_DB.Delete(a).Error err = global.GVA_DB.Delete(a).Error
ClearCasbin(1, a.Path,a.Method)
ClearCasbin(1, a.Path, a.Method)
return err return err
} }
@ -45,44 +45,39 @@ func GetAPIInfoList(a model.SysApi, info request.PageInfo, Order string, Desc bo
limit := info.PageSize limit := info.PageSize
offset := info.PageSize * (info.Page - 1) offset := info.PageSize * (info.Page - 1)
db := global.GVA_DB db := global.GVA_DB
var apiList []model.SysApi
if err != nil {
return
} else {
var apiList []model.SysApi
if a.Path != "" {
db = db.Where("path LIKE ?", "%"+a.Path+"%")
}
if a.Path != "" {
db = db.Where("path LIKE ?", "%"+a.Path+"%")
}
if a.Description != "" {
db = db.Where("description LIKE ?", "%"+a.Description+"%")
}
if a.Description != "" {
db = db.Where("description LIKE ?", "%"+a.Description+"%")
}
if a.Method != "" {
db = db.Where("method = ?", a.Method)
}
if a.Method != "" {
db = db.Where("method = ?", a.Method)
}
err = db.Find(&apiList).Count(&total).Error
err = db.Find(&apiList).Count(&total).Error
if err != nil {
return err, apiList, total
} else {
db = db.Limit(limit).Offset(offset)
if Order != "" {
var OrderStr string
if Desc {
OrderStr = Order + " desc"
} else {
OrderStr = Order
}
err = db.Order(OrderStr, true).Find(&apiList).Error
if err != nil {
return err, apiList, total
} else {
db = db.Limit(limit).Offset(offset)
if Order != "" {
var OrderStr string
if Desc {
OrderStr = Order + " desc"
} else { } else {
err = db.Order("api_group", true).Find(&apiList).Error
OrderStr = Order
} }
err = db.Order(OrderStr, true).Find(&apiList).Error
} else {
err = db.Order("api_group", true).Find(&apiList).Error
} }
return err, apiList, total
} }
return err, apiList, total
} }
// @title GetAllApis // @title GetAllApis
@ -114,7 +109,7 @@ func UpdateApi(a model.SysApi) (err error) {
err = global.GVA_DB.Where("id = ?", a.ID).First(&oldA).Error err = global.GVA_DB.Where("id = ?", a.ID).First(&oldA).Error
if oldA.Path != a.Path || oldA.Method != a.Method{
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() 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路径")
@ -123,7 +118,7 @@ func UpdateApi(a model.SysApi) (err error) {
if err != nil { if err != nil {
return err return err
} else { } else {
err = UpdateCasbinApi(oldA.Path, a.Path,oldA.Method,a.Method)
err = UpdateCasbinApi(oldA.Path, a.Path, oldA.Method, a.Method)
if err != nil { if err != nil {
return err return err
} else { } else {

16
server/service/sys_authority.go

@ -60,18 +60,14 @@ func GetAuthorityInfoList(info request.PageInfo) (err error, list interface{}, t
limit := info.PageSize limit := info.PageSize
offset := info.PageSize * (info.Page - 1) offset := info.PageSize * (info.Page - 1)
db := global.GVA_DB db := global.GVA_DB
if err != nil {
return
} else {
var authority []model.SysAuthority
err = db.Limit(limit).Offset(offset).Preload("DataAuthorityId").Where("parent_id = 0").Find(&authority).Error
if len(authority) > 0 {
for k, _ := range authority {
err = findChildrenAuthority(&authority[k])
}
var authority []model.SysAuthority
err = db.Limit(limit).Offset(offset).Preload("DataAuthorityId").Where("parent_id = 0").Find(&authority).Error
if len(authority) > 0 {
for k, _ := range authority {
err = findChildrenAuthority(&authority[k])
} }
return err, authority, total
} }
return err, authority, total
} }
// @title GetAuthorityInfo // @title GetAuthorityInfo

14
server/service/sys_menu.go

@ -46,16 +46,12 @@ func GetInfoList(info request.PageInfo) (err error, list interface{}, total int)
limit := info.PageSize limit := info.PageSize
offset := info.PageSize * (info.Page - 1) offset := info.PageSize * (info.Page - 1)
db := global.GVA_DB db := global.GVA_DB
if err != nil {
return
} else {
var menuList []model.SysBaseMenu
err = db.Limit(limit).Offset(offset).Where("parent_id = 0").Order("sort", true).Find(&menuList).Error
for i := 0; i < len(menuList); i++ {
err = getBaseChildrenList(&menuList[i])
}
return err, menuList, total
var menuList []model.SysBaseMenu
err = db.Limit(limit).Offset(offset).Where("parent_id = 0").Order("sort", true).Find(&menuList).Error
for i := 0; i < len(menuList); i++ {
err = getBaseChildrenList(&menuList[i])
} }
return err, menuList, total
} }
// @title getBaseChildrenList // @title getBaseChildrenList

10
server/service/sys_user.go

@ -71,13 +71,9 @@ func GetUserInfoList(info request.PageInfo) (err error, list interface{}, total
limit := info.PageSize limit := info.PageSize
offset := info.PageSize * (info.Page - 1) offset := info.PageSize * (info.Page - 1)
db := global.GVA_DB db := global.GVA_DB
if err != nil {
return
} else {
var userList []model.SysUser
err = db.Limit(limit).Offset(offset).Preload("Authority").Find(&userList).Error
return err, userList, total
}
var userList []model.SysUser
err = db.Limit(limit).Offset(offset).Preload("Authority").Find(&userList).Error
return err, userList, total
} }
// @title SetUserAuthority // @title SetUserAuthority

Loading…
Cancel
Save