mirror of
https://gitee.com/XM-GO/PandaX.git
synced 2026-04-25 03:48:35 +08:00
[fix]异常处理
This commit is contained in:
@@ -3,6 +3,7 @@ package api
|
||||
import (
|
||||
entity "pandax/apps/system/entity"
|
||||
services "pandax/apps/system/services"
|
||||
"pandax/kit/biz"
|
||||
"pandax/kit/casbin"
|
||||
"pandax/kit/model"
|
||||
"pandax/kit/restfulx"
|
||||
@@ -17,12 +18,14 @@ type SystemApiApi struct {
|
||||
func (s *SystemApiApi) CreateApi(rc *restfulx.ReqCtx) {
|
||||
var api entity.SysApi
|
||||
restfulx.BindJsonAndValid(rc, &api)
|
||||
s.ApiApp.Insert(api)
|
||||
_, err := s.ApiApp.Insert(api)
|
||||
biz.ErrIsNil(err, "添加APi失败")
|
||||
}
|
||||
|
||||
func (s *SystemApiApi) DeleteApi(rc *restfulx.ReqCtx) {
|
||||
ids := rc.Request.PathParameter("id")
|
||||
s.ApiApp.Delete(utils.IdsStrToIdsIntGroup(ids))
|
||||
err := s.ApiApp.Delete(utils.IdsStrToIdsIntGroup(ids))
|
||||
biz.ErrIsNil(err, "删除APi失败")
|
||||
}
|
||||
|
||||
func (s *SystemApiApi) GetApiList(rc *restfulx.ReqCtx) {
|
||||
@@ -33,7 +36,8 @@ func (s *SystemApiApi) GetApiList(rc *restfulx.ReqCtx) {
|
||||
method := rc.Request.QueryParameter("method")
|
||||
apiGroup := rc.Request.QueryParameter("apiGroup")
|
||||
api := entity.SysApi{Path: path, Description: description, Method: method, ApiGroup: apiGroup}
|
||||
list, total := s.ApiApp.FindListPage(pageNum, pageSize, api)
|
||||
list, total, err := s.ApiApp.FindListPage(pageNum, pageSize, api)
|
||||
biz.ErrIsNil(err, "查询APi分页列表失败")
|
||||
rc.ResData = model.ResultPage{
|
||||
Total: total,
|
||||
PageNum: int64(pageNum),
|
||||
@@ -44,18 +48,23 @@ func (s *SystemApiApi) GetApiList(rc *restfulx.ReqCtx) {
|
||||
|
||||
func (s *SystemApiApi) GetApiById(rc *restfulx.ReqCtx) {
|
||||
id := restfulx.QueryInt(rc, "id", 0)
|
||||
rc.ResData = s.ApiApp.FindOne(int64(id))
|
||||
data, err := s.ApiApp.FindOne(int64(id))
|
||||
biz.ErrIsNil(err, "查询APi失败")
|
||||
rc.ResData = data
|
||||
|
||||
}
|
||||
|
||||
func (s *SystemApiApi) UpdateApi(rc *restfulx.ReqCtx) {
|
||||
var api entity.SysApi
|
||||
restfulx.BindJsonAndValid(rc, &api)
|
||||
s.ApiApp.Update(api)
|
||||
err := s.ApiApp.Update(api)
|
||||
biz.ErrIsNil(err, "查询APi失败")
|
||||
}
|
||||
|
||||
func (s *SystemApiApi) GetAllApis(rc *restfulx.ReqCtx) {
|
||||
rc.ResData = s.ApiApp.FindList(entity.SysApi{})
|
||||
data, err := s.ApiApp.FindList(entity.SysApi{})
|
||||
biz.ErrIsNil(err, "查询APi列表失败")
|
||||
rc.ResData = data
|
||||
}
|
||||
|
||||
func (s *SystemApiApi) GetPolicyPathByRoleId(rc *restfulx.ReqCtx) {
|
||||
|
||||
@@ -20,8 +20,8 @@ func (p *ConfigApi) GetConfigList(rc *restfulx.ReqCtx) {
|
||||
configKey := rc.Request.QueryParameter("configKey")
|
||||
configType := rc.Request.QueryParameter("configType")
|
||||
config := entity.SysConfig{ConfigName: configName, ConfigKey: configKey, ConfigType: configType}
|
||||
list, total := p.ConfigApp.FindListPage(pageNum, pageSize, config)
|
||||
|
||||
list, total, err := p.ConfigApp.FindListPage(pageNum, pageSize, config)
|
||||
biz.ErrIsNil(err, "查询配置分页列表失败")
|
||||
rc.ResData = model.ResultPage{
|
||||
Total: total,
|
||||
PageNum: int64(pageNum),
|
||||
@@ -33,28 +33,35 @@ func (p *ConfigApi) GetConfigList(rc *restfulx.ReqCtx) {
|
||||
func (p *ConfigApi) GetConfigListByKey(rc *restfulx.ReqCtx) {
|
||||
configKey := rc.Request.QueryParameter("configKey")
|
||||
biz.IsTrue(configKey != "", "请传入配置Key")
|
||||
rc.ResData = p.ConfigApp.FindList(entity.SysConfig{ConfigKey: configKey})
|
||||
data, err := p.ConfigApp.FindList(entity.SysConfig{ConfigKey: configKey})
|
||||
biz.ErrIsNil(err, "查询配置列表失败")
|
||||
rc.ResData = data
|
||||
}
|
||||
|
||||
func (p *ConfigApi) GetConfig(rc *restfulx.ReqCtx) {
|
||||
id := restfulx.PathParamInt(rc, "configId")
|
||||
p.ConfigApp.FindOne(int64(id))
|
||||
data, err := p.ConfigApp.FindOne(int64(id))
|
||||
biz.ErrIsNil(err, "查询配置失败")
|
||||
rc.ResData = data
|
||||
}
|
||||
|
||||
func (p *ConfigApi) InsertConfig(rc *restfulx.ReqCtx) {
|
||||
var config entity.SysConfig
|
||||
restfulx.BindJsonAndValid(rc, &config)
|
||||
|
||||
p.ConfigApp.Insert(config)
|
||||
_, err := p.ConfigApp.Insert(config)
|
||||
biz.ErrIsNil(err, "添加配置失败")
|
||||
}
|
||||
|
||||
func (p *ConfigApi) UpdateConfig(rc *restfulx.ReqCtx) {
|
||||
var post entity.SysConfig
|
||||
restfulx.BindJsonAndValid(rc, &post)
|
||||
p.ConfigApp.Update(post)
|
||||
err := p.ConfigApp.Update(post)
|
||||
biz.ErrIsNil(err, "修改配置失败")
|
||||
}
|
||||
|
||||
func (p *ConfigApi) DeleteConfig(rc *restfulx.ReqCtx) {
|
||||
configId := rc.Request.PathParameter("configId")
|
||||
p.ConfigApp.Delete(utils.IdsStrToIdsIntGroup(configId))
|
||||
err := p.ConfigApp.Delete(utils.IdsStrToIdsIntGroup(configId))
|
||||
biz.ErrIsNil(err, "删除配置失败")
|
||||
}
|
||||
|
||||
@@ -23,7 +23,8 @@ func (p *DictApi) GetDictTypeList(rc *restfulx.ReqCtx) {
|
||||
dictName := restfulx.QueryParam(rc, "dictName")
|
||||
dictType := restfulx.QueryParam(rc, "dictType")
|
||||
|
||||
list, total := p.DictType.FindListPage(pageNum, pageSize, entity.SysDictType{Status: status, DictName: dictName, DictType: dictType})
|
||||
list, total, err := p.DictType.FindListPage(pageNum, pageSize, entity.SysDictType{Status: status, DictName: dictName, DictType: dictType})
|
||||
biz.ErrIsNil(err, "查询字典类型分页失败")
|
||||
rc.ResData = model.ResultPage{
|
||||
Total: total,
|
||||
PageNum: int64(pageNum),
|
||||
@@ -34,7 +35,9 @@ func (p *DictApi) GetDictTypeList(rc *restfulx.ReqCtx) {
|
||||
|
||||
func (p *DictApi) GetDictType(rc *restfulx.ReqCtx) {
|
||||
dictId := restfulx.PathParamInt(rc, "dictId")
|
||||
p.DictType.FindOne(int64(dictId))
|
||||
data, err := p.DictType.FindOne(int64(dictId))
|
||||
biz.ErrIsNil(err, "查询字典类型失败")
|
||||
rc.ResData = data
|
||||
}
|
||||
|
||||
func (p *DictApi) InsertDictType(rc *restfulx.ReqCtx) {
|
||||
@@ -42,7 +45,8 @@ func (p *DictApi) InsertDictType(rc *restfulx.ReqCtx) {
|
||||
restfulx.BindJsonAndValid(rc, &dict)
|
||||
|
||||
dict.CreateBy = rc.LoginAccount.UserName
|
||||
p.DictType.Insert(dict)
|
||||
_, err := p.DictType.Insert(dict)
|
||||
biz.ErrIsNil(err, "添加字典类型失败")
|
||||
}
|
||||
|
||||
func (p *DictApi) UpdateDictType(rc *restfulx.ReqCtx) {
|
||||
@@ -50,7 +54,8 @@ func (p *DictApi) UpdateDictType(rc *restfulx.ReqCtx) {
|
||||
restfulx.BindJsonAndValid(rc, &dict)
|
||||
|
||||
dict.CreateBy = rc.LoginAccount.UserName
|
||||
p.DictType.Update(dict)
|
||||
err := p.DictType.Update(dict)
|
||||
biz.ErrIsNil(err, "修改字典类型失败")
|
||||
}
|
||||
|
||||
func (p *DictApi) DeleteDictType(rc *restfulx.ReqCtx) {
|
||||
@@ -59,15 +64,22 @@ func (p *DictApi) DeleteDictType(rc *restfulx.ReqCtx) {
|
||||
|
||||
deList := make([]int64, 0)
|
||||
for _, id := range dictIds {
|
||||
one := p.DictType.FindOne(id)
|
||||
list := p.DictData.FindList(entity.SysDictData{DictType: one.DictType})
|
||||
one, err := p.DictType.FindOne(id)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
list, err := p.DictData.FindList(entity.SysDictData{DictType: one.DictType})
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
if len(*list) == 0 {
|
||||
deList = append(deList, id)
|
||||
} else {
|
||||
global.Log.Info(fmt.Sprintf("dictId: %d 存在字典数据绑定无法删除", id))
|
||||
}
|
||||
}
|
||||
p.DictType.Delete(deList)
|
||||
err := p.DictType.Delete(deList)
|
||||
biz.ErrIsNil(err, "删除字典类型失败")
|
||||
}
|
||||
|
||||
func (p *DictApi) ExportDictType(rc *restfulx.ReqCtx) {
|
||||
@@ -76,7 +88,8 @@ func (p *DictApi) ExportDictType(rc *restfulx.ReqCtx) {
|
||||
dictName := restfulx.QueryParam(rc, "dictName")
|
||||
dictType := restfulx.QueryParam(rc, "dictType")
|
||||
|
||||
list := p.DictType.FindList(entity.SysDictType{Status: status, DictName: dictName, DictType: dictType})
|
||||
list, err := p.DictType.FindList(entity.SysDictType{Status: status, DictName: dictName, DictType: dictType})
|
||||
biz.ErrIsNil(err, "查询字典类型列表失败")
|
||||
fileName := utils.GetFileName(global.Conf.Server.ExcelDir, filename)
|
||||
utils.InterfaceToExcel(*list, fileName)
|
||||
rc.Download(fileName)
|
||||
@@ -86,25 +99,32 @@ func (p *DictApi) GetDictDataList(rc *restfulx.ReqCtx) {
|
||||
dictLabel := restfulx.QueryParam(rc, "dictLabel")
|
||||
dictType := restfulx.QueryParam(rc, "dictType")
|
||||
status := restfulx.QueryParam(rc, "status")
|
||||
rc.ResData = p.DictData.FindList(entity.SysDictData{Status: status, DictType: dictType, DictLabel: dictLabel})
|
||||
data, err := p.DictData.FindList(entity.SysDictData{Status: status, DictType: dictType, DictLabel: dictLabel})
|
||||
biz.ErrIsNil(err, "查询字典列表失败")
|
||||
rc.ResData = data
|
||||
}
|
||||
|
||||
func (p *DictApi) GetDictDataListByDictType(rc *restfulx.ReqCtx) {
|
||||
dictType := restfulx.QueryParam(rc, "dictType")
|
||||
biz.IsTrue(dictType != "", "请传入字典类型")
|
||||
rc.ResData = p.DictData.FindList(entity.SysDictData{DictType: dictType})
|
||||
data, err := p.DictData.FindList(entity.SysDictData{DictType: dictType})
|
||||
biz.ErrIsNil(err, "查询字典列表失败")
|
||||
rc.ResData = data
|
||||
}
|
||||
|
||||
func (p *DictApi) GetDictData(rc *restfulx.ReqCtx) {
|
||||
dictCode := restfulx.PathParamInt(rc, "dictCode")
|
||||
p.DictData.FindOne(int64(dictCode))
|
||||
data, err := p.DictData.FindOne(int64(dictCode))
|
||||
biz.ErrIsNil(err, "查询字典失败")
|
||||
rc.ResData = data
|
||||
}
|
||||
|
||||
func (p *DictApi) InsertDictData(rc *restfulx.ReqCtx) {
|
||||
var data entity.SysDictData
|
||||
restfulx.BindJsonAndValid(rc, &data)
|
||||
data.CreateBy = rc.LoginAccount.UserName
|
||||
p.DictData.Insert(data)
|
||||
_, err := p.DictData.Insert(data)
|
||||
biz.ErrIsNil(err, "添加字典失败")
|
||||
}
|
||||
|
||||
func (p *DictApi) UpdateDictData(rc *restfulx.ReqCtx) {
|
||||
@@ -112,10 +132,12 @@ func (p *DictApi) UpdateDictData(rc *restfulx.ReqCtx) {
|
||||
restfulx.BindJsonAndValid(rc, &data)
|
||||
|
||||
data.CreateBy = rc.LoginAccount.UserName
|
||||
p.DictData.Update(data)
|
||||
err := p.DictData.Update(data)
|
||||
biz.ErrIsNil(err, "修改字典失败")
|
||||
}
|
||||
|
||||
func (p *DictApi) DeleteDictData(rc *restfulx.ReqCtx) {
|
||||
dictCode := restfulx.PathParam(rc, "dictCode")
|
||||
p.DictData.Delete(utils.IdsStrToIdsIntGroup(dictCode))
|
||||
err := p.DictData.Delete(utils.IdsStrToIdsIntGroup(dictCode))
|
||||
biz.ErrIsNil(err, "修改字典失败")
|
||||
}
|
||||
|
||||
@@ -18,23 +18,27 @@ type MenuApi struct {
|
||||
}
|
||||
|
||||
func (m *MenuApi) GetMenuTreeSelect(rc *restfulx.ReqCtx) {
|
||||
lable := m.MenuApp.SelectMenuLable(entity.SysMenu{})
|
||||
lable, err := m.MenuApp.SelectMenuLable(entity.SysMenu{})
|
||||
biz.ErrIsNil(err, "查询菜单树失败")
|
||||
rc.ResData = lable
|
||||
}
|
||||
|
||||
func (m *MenuApi) GetMenuRole(rc *restfulx.ReqCtx) {
|
||||
roleKey := restfulx.QueryParam(rc, "roleKey")
|
||||
biz.IsTrue(roleKey != "", "请传入角色Key")
|
||||
rc.ResData = Build(*m.MenuApp.SelectMenuRole(roleKey))
|
||||
data, err := m.MenuApp.SelectMenuRole(roleKey)
|
||||
biz.ErrIsNil(err, "查询角色菜单失败")
|
||||
rc.ResData = Build(*data)
|
||||
}
|
||||
|
||||
func (m *MenuApi) GetMenuTreeRoleSelect(rc *restfulx.ReqCtx) {
|
||||
roleId := restfulx.PathParamInt(rc, "roleId")
|
||||
|
||||
result := m.MenuApp.SelectMenuLable(entity.SysMenu{})
|
||||
result, err := m.MenuApp.SelectMenuLable(entity.SysMenu{})
|
||||
biz.ErrIsNil(err, "查询菜单树失败")
|
||||
menuIds := make([]int64, 0)
|
||||
if roleId != 0 {
|
||||
menuIds = m.RoleApp.GetRoleMeunId(entity.SysRole{RoleId: int64(roleId)})
|
||||
menuIds, err = m.RoleApp.GetRoleMeunId(entity.SysRole{RoleId: int64(roleId)})
|
||||
biz.ErrIsNil(err, "通过角色查询菜单失败")
|
||||
}
|
||||
rc.ResData = vo.MenuTreeVo{
|
||||
Menus: *result,
|
||||
@@ -45,7 +49,9 @@ func (m *MenuApi) GetMenuTreeRoleSelect(rc *restfulx.ReqCtx) {
|
||||
func (m *MenuApi) GetMenuPaths(rc *restfulx.ReqCtx) {
|
||||
roleKey := restfulx.QueryParam(rc, "roleKey")
|
||||
biz.IsTrue(roleKey != "", "请传入角色Key")
|
||||
rc.ResData = m.RoleMenuApp.GetMenuPaths(entity.SysRoleMenu{RoleName: roleKey})
|
||||
data, err := m.RoleMenuApp.GetMenuPaths(entity.SysRoleMenu{RoleName: roleKey})
|
||||
biz.ErrIsNil(err, "查询菜单路径失败")
|
||||
rc.ResData = data
|
||||
}
|
||||
|
||||
func (m *MenuApi) GetMenuList(rc *restfulx.ReqCtx) {
|
||||
@@ -54,16 +60,21 @@ func (m *MenuApi) GetMenuList(rc *restfulx.ReqCtx) {
|
||||
|
||||
menu := entity.SysMenu{MenuName: menuName, Status: status}
|
||||
if menu.MenuName == "" {
|
||||
rc.ResData = m.MenuApp.SelectMenu(menu)
|
||||
data, err := m.MenuApp.SelectMenu(menu)
|
||||
biz.ErrIsNil(err, "查询菜单列表失败")
|
||||
rc.ResData = data
|
||||
} else {
|
||||
rc.ResData = m.MenuApp.FindList(menu)
|
||||
data, err := m.MenuApp.FindList(menu)
|
||||
biz.ErrIsNil(err, "查询菜单列表失败")
|
||||
rc.ResData = data
|
||||
}
|
||||
}
|
||||
|
||||
func (m *MenuApi) GetMenu(rc *restfulx.ReqCtx) {
|
||||
menuId := restfulx.PathParamInt(rc, "menuId")
|
||||
|
||||
rc.ResData = m.MenuApp.FindOne(int64(menuId))
|
||||
data, err := m.MenuApp.FindOne(int64(menuId))
|
||||
biz.ErrIsNil(err, "查询菜单失败")
|
||||
rc.ResData = data
|
||||
}
|
||||
|
||||
func (m *MenuApi) InsertMenu(rc *restfulx.ReqCtx) {
|
||||
@@ -71,8 +82,8 @@ func (m *MenuApi) InsertMenu(rc *restfulx.ReqCtx) {
|
||||
restfulx.BindJsonAndValid(rc, &menu)
|
||||
menu.CreateBy = rc.LoginAccount.UserName
|
||||
m.MenuApp.Insert(menu)
|
||||
permis := m.RoleMenuApp.GetPermis(rc.LoginAccount.RoleId)
|
||||
menus := m.MenuApp.SelectMenuRole(rc.LoginAccount.RoleKey)
|
||||
permis, _ := m.RoleMenuApp.GetPermis(rc.LoginAccount.RoleId)
|
||||
menus, _ := m.MenuApp.SelectMenuRole(rc.LoginAccount.RoleKey)
|
||||
rc.ResData = vo.MenuPermisVo{
|
||||
Menus: Build(*menus),
|
||||
Permissions: permis,
|
||||
@@ -84,8 +95,8 @@ func (m *MenuApi) UpdateMenu(rc *restfulx.ReqCtx) {
|
||||
restfulx.BindJsonAndValid(rc, &menu)
|
||||
menu.UpdateBy = rc.LoginAccount.UserName
|
||||
m.MenuApp.Update(menu)
|
||||
permis := m.RoleMenuApp.GetPermis(rc.LoginAccount.RoleId)
|
||||
menus := m.MenuApp.SelectMenuRole(rc.LoginAccount.RoleKey)
|
||||
permis, _ := m.RoleMenuApp.GetPermis(rc.LoginAccount.RoleId)
|
||||
menus, _ := m.MenuApp.SelectMenuRole(rc.LoginAccount.RoleKey)
|
||||
rc.ResData = vo.MenuPermisVo{
|
||||
Menus: Build(*menus),
|
||||
Permissions: permis,
|
||||
@@ -94,5 +105,6 @@ func (m *MenuApi) UpdateMenu(rc *restfulx.ReqCtx) {
|
||||
|
||||
func (m *MenuApi) DeleteMenu(rc *restfulx.ReqCtx) {
|
||||
menuId := restfulx.PathParam(rc, "menuId")
|
||||
m.MenuApp.Delete(utils.IdsStrToIdsIntGroup(menuId))
|
||||
err := m.MenuApp.Delete(utils.IdsStrToIdsIntGroup(menuId))
|
||||
biz.ErrIsNil(err, "删除菜单失败")
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package api
|
||||
import (
|
||||
"pandax/apps/system/entity"
|
||||
"pandax/apps/system/services"
|
||||
"pandax/kit/biz"
|
||||
"pandax/kit/model"
|
||||
"pandax/kit/restfulx"
|
||||
"pandax/kit/utils"
|
||||
@@ -22,13 +23,14 @@ func (p *NoticeApi) GetNoticeList(rc *restfulx.ReqCtx) {
|
||||
title := restfulx.QueryParam(rc, "title")
|
||||
|
||||
// 获取组织的子组织id
|
||||
one := p.OrganizationApp.FindOne(rc.LoginAccount.OrganizationId)
|
||||
one, err := p.OrganizationApp.FindOne(rc.LoginAccount.OrganizationId)
|
||||
biz.ErrIsNil(err, "组织查询失败")
|
||||
split := strings.Split(strings.Trim(one.OrganizationPath, "/"), "/")
|
||||
// 获取所有父组织id
|
||||
ids := utils.OrganizationPCIds(split, rc.LoginAccount.OrganizationId, true)
|
||||
notice := entity.SysNotice{NoticeType: noticeType, Title: title, OrganizationIds: ids}
|
||||
list, total := p.NoticeApp.FindListPage(pageNum, pageSize, notice)
|
||||
|
||||
list, total, err := p.NoticeApp.FindListPage(pageNum, pageSize, notice)
|
||||
biz.ErrIsNil(err, "查询通知列表失败")
|
||||
rc.ResData = model.ResultPage{
|
||||
Total: total,
|
||||
PageNum: int64(pageNum),
|
||||
@@ -42,7 +44,8 @@ func (p *NoticeApi) InsertNotice(rc *restfulx.ReqCtx) {
|
||||
var notice entity.SysNotice
|
||||
restfulx.BindJsonAndValid(rc, ¬ice)
|
||||
notice.UserName = rc.LoginAccount.UserName
|
||||
p.NoticeApp.Insert(notice)
|
||||
_, err := p.NoticeApp.Insert(notice)
|
||||
biz.ErrIsNil(err, "添加通知失败")
|
||||
}
|
||||
|
||||
// UpdateNotice 修改通知
|
||||
@@ -50,12 +53,14 @@ func (p *NoticeApi) UpdateNotice(rc *restfulx.ReqCtx) {
|
||||
var notice entity.SysNotice
|
||||
restfulx.BindJsonAndValid(rc, ¬ice)
|
||||
|
||||
p.NoticeApp.Update(notice)
|
||||
err := p.NoticeApp.Update(notice)
|
||||
biz.ErrIsNil(err, "修改通知失败")
|
||||
}
|
||||
|
||||
// DeleteNotice 删除通知
|
||||
func (p *NoticeApi) DeleteNotice(rc *restfulx.ReqCtx) {
|
||||
noticeId := restfulx.PathParam(rc, "noticeId")
|
||||
noticeIds := utils.IdsStrToIdsIntGroup(noticeId)
|
||||
p.NoticeApp.Delete(noticeIds)
|
||||
err := p.NoticeApp.Delete(noticeIds)
|
||||
biz.ErrIsNil(err, "删除通知失败")
|
||||
}
|
||||
|
||||
@@ -21,11 +21,12 @@ type OrganizationApi struct {
|
||||
func (m *OrganizationApi) GetOrganizationTreeRoleSelect(rc *restfulx.ReqCtx) {
|
||||
roleId := restfulx.PathParamInt(rc, "roleId")
|
||||
var organization entity.SysOrganization
|
||||
result := m.OrganizationApp.SelectOrganizationLable(organization)
|
||||
|
||||
result, err := m.OrganizationApp.SelectOrganizationLable(organization)
|
||||
biz.ErrIsNil(err, "查询组织树失败")
|
||||
organizationIds := make([]int64, 0)
|
||||
if roleId != 0 {
|
||||
organizationIds = m.RoleApp.GetRoleOrganizationId(entity.SysRole{RoleId: int64(roleId)})
|
||||
organizationIds, err = m.RoleApp.GetRoleOrganizationId(entity.SysRole{RoleId: int64(roleId)})
|
||||
biz.ErrIsNil(err, "查询角色组织失败")
|
||||
}
|
||||
rc.ResData = vo.OrganizationTreeVo{
|
||||
Organizations: result,
|
||||
@@ -34,24 +35,27 @@ func (m *OrganizationApi) GetOrganizationTreeRoleSelect(rc *restfulx.ReqCtx) {
|
||||
}
|
||||
|
||||
func (a *OrganizationApi) GetOrganizationList(rc *restfulx.ReqCtx) {
|
||||
//pageNum := restfulx.QueryInt(rc.GinCtx, "pageNum", 1)
|
||||
//pageSize := restfulx.QueryInt(rc.GinCtx, "pageSize", 10)
|
||||
organizationName := restfulx.QueryParam(rc, "organizationName")
|
||||
status := restfulx.QueryParam(rc, "status")
|
||||
organizationId := restfulx.QueryInt(rc, "organizationId", 0)
|
||||
organization := entity.SysOrganization{OrganizationName: organizationName, Status: status, OrganizationId: int64(organizationId)}
|
||||
|
||||
if organization.OrganizationName == "" {
|
||||
rc.ResData = a.OrganizationApp.SelectOrganization(organization)
|
||||
data, err := a.OrganizationApp.SelectOrganization(organization)
|
||||
biz.ErrIsNil(err, "查询组织树失败")
|
||||
rc.ResData = data
|
||||
} else {
|
||||
rc.ResData = a.OrganizationApp.FindList(organization)
|
||||
data, err := a.OrganizationApp.FindList(organization)
|
||||
biz.ErrIsNil(err, "查询组织列表失败")
|
||||
rc.ResData = data
|
||||
}
|
||||
}
|
||||
|
||||
func (a *OrganizationApi) GetOrdinaryOrganizationList(rc *restfulx.ReqCtx) {
|
||||
var organization entity.SysOrganization
|
||||
|
||||
rc.ResData = a.OrganizationApp.FindList(organization)
|
||||
data, err := a.OrganizationApp.FindList(organization)
|
||||
biz.ErrIsNil(err, "查询组织列表失败")
|
||||
rc.ResData = data
|
||||
}
|
||||
|
||||
func (a *OrganizationApi) GetOrganizationTree(rc *restfulx.ReqCtx) {
|
||||
@@ -60,19 +64,24 @@ func (a *OrganizationApi) GetOrganizationTree(rc *restfulx.ReqCtx) {
|
||||
organizationId := restfulx.QueryInt(rc, "organizationId", 0)
|
||||
organization := entity.SysOrganization{OrganizationName: organizationName, Status: status, OrganizationId: int64(organizationId)}
|
||||
|
||||
rc.ResData = a.OrganizationApp.SelectOrganization(organization)
|
||||
data, err := a.OrganizationApp.SelectOrganization(organization)
|
||||
biz.ErrIsNil(err, "查询组织树失败")
|
||||
rc.ResData = data
|
||||
}
|
||||
|
||||
func (a *OrganizationApi) GetOrganization(rc *restfulx.ReqCtx) {
|
||||
organizationId := restfulx.PathParamInt(rc, "organizationId")
|
||||
rc.ResData = a.OrganizationApp.FindOne(int64(organizationId))
|
||||
data, err := a.OrganizationApp.FindOne(int64(organizationId))
|
||||
biz.ErrIsNil(err, "查询组织失败")
|
||||
rc.ResData = data
|
||||
}
|
||||
|
||||
func (a *OrganizationApi) InsertOrganization(rc *restfulx.ReqCtx) {
|
||||
var organization entity.SysOrganization
|
||||
restfulx.BindJsonAndValid(rc, &organization)
|
||||
organization.CreateBy = rc.LoginAccount.UserName
|
||||
a.OrganizationApp.Insert(organization)
|
||||
_, err := a.OrganizationApp.Insert(organization)
|
||||
biz.ErrIsNil(err, "添加组织失败")
|
||||
}
|
||||
|
||||
func (a *OrganizationApi) UpdateOrganization(rc *restfulx.ReqCtx) {
|
||||
@@ -80,7 +89,8 @@ func (a *OrganizationApi) UpdateOrganization(rc *restfulx.ReqCtx) {
|
||||
restfulx.BindJsonAndValid(rc, &organization)
|
||||
|
||||
organization.UpdateBy = rc.LoginAccount.UserName
|
||||
a.OrganizationApp.Update(organization)
|
||||
err := a.OrganizationApp.Update(organization)
|
||||
biz.ErrIsNil(err, "修改组织失败")
|
||||
}
|
||||
|
||||
func (a *OrganizationApi) DeleteOrganization(rc *restfulx.ReqCtx) {
|
||||
@@ -91,7 +101,10 @@ func (a *OrganizationApi) DeleteOrganization(rc *restfulx.ReqCtx) {
|
||||
for _, id := range organizationIds {
|
||||
user := entity.SysUser{}
|
||||
user.OrganizationId = id
|
||||
list := a.UserApp.FindList(user)
|
||||
list, err := a.UserApp.FindList(user)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
if len(*list) == 0 {
|
||||
deList = append(deList, id)
|
||||
} else {
|
||||
|
||||
@@ -28,8 +28,8 @@ func (p *PostApi) GetPostList(rc *restfulx.ReqCtx) {
|
||||
postCode := restfulx.QueryParam(rc, "postCode")
|
||||
post := entity.SysPost{Status: status, PostName: postName, PostCode: postCode}
|
||||
|
||||
list, total := p.PostApp.FindListPage(pageNum, pageSize, post)
|
||||
|
||||
list, total, err := p.PostApp.FindListPage(pageNum, pageSize, post)
|
||||
biz.ErrIsNil(err, "查询部门列表失败")
|
||||
rc.ResData = model.ResultPage{
|
||||
Total: total,
|
||||
PageNum: int64(pageNum),
|
||||
@@ -41,7 +41,9 @@ func (p *PostApi) GetPostList(rc *restfulx.ReqCtx) {
|
||||
// GetPost 获取职位
|
||||
func (p *PostApi) GetPost(rc *restfulx.ReqCtx) {
|
||||
postId := restfulx.PathParamInt(rc, "postId")
|
||||
p.PostApp.FindOne(int64(postId))
|
||||
data, err := p.PostApp.FindOne(int64(postId))
|
||||
biz.ErrIsNil(err, "查询部门失败")
|
||||
rc.ResData = data
|
||||
}
|
||||
|
||||
// InsertPost 添加职位
|
||||
@@ -49,7 +51,8 @@ func (p *PostApi) InsertPost(rc *restfulx.ReqCtx) {
|
||||
var post entity.SysPost
|
||||
restfulx.BindJsonAndValid(rc, &post)
|
||||
post.CreateBy = rc.LoginAccount.UserName
|
||||
p.PostApp.Insert(post)
|
||||
_, err := p.PostApp.Insert(post)
|
||||
biz.ErrIsNil(err, "添加部门失败")
|
||||
}
|
||||
|
||||
// UpdatePost 修改职位
|
||||
@@ -58,7 +61,8 @@ func (p *PostApi) UpdatePost(rc *restfulx.ReqCtx) {
|
||||
restfulx.BindJsonAndValid(rc, &post)
|
||||
|
||||
post.CreateBy = rc.LoginAccount.UserName
|
||||
p.PostApp.Update(post)
|
||||
err := p.PostApp.Update(post)
|
||||
biz.ErrIsNil(err, "修改部门失败")
|
||||
}
|
||||
|
||||
// DeletePost 删除职位
|
||||
@@ -70,7 +74,10 @@ func (p *PostApi) DeletePost(rc *restfulx.ReqCtx) {
|
||||
for _, id := range postIds {
|
||||
user := entity.SysUser{}
|
||||
user.PostId = id
|
||||
list := p.UserApp.FindList(user)
|
||||
list, err := p.UserApp.FindList(user)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
if len(*list) == 0 {
|
||||
deList = append(deList, id)
|
||||
} else {
|
||||
@@ -80,5 +87,6 @@ func (p *PostApi) DeletePost(rc *restfulx.ReqCtx) {
|
||||
if len(deList) == 0 {
|
||||
biz.ErrIsNil(errors.New("所有岗位都已绑定用户,无法删除"), "所有岗位都已绑定用户,无法删除")
|
||||
}
|
||||
p.PostApp.Delete(deList)
|
||||
err := p.PostApp.Delete(deList)
|
||||
biz.ErrIsNil(err, "删除部门失败")
|
||||
}
|
||||
|
||||
@@ -29,8 +29,8 @@ func (r *RoleApi) GetRoleList(rc *restfulx.ReqCtx) {
|
||||
roleName := restfulx.QueryParam(rc, "roleName")
|
||||
roleKey := restfulx.QueryParam(rc, "roleKey")
|
||||
role := entity.SysRole{Status: status, RoleName: roleName, RoleKey: roleKey}
|
||||
list, total := r.RoleApp.FindListPage(pageNum, pageSize, role)
|
||||
|
||||
list, total, err := r.RoleApp.FindListPage(pageNum, pageSize, role)
|
||||
biz.ErrIsNil(err, "查询角色分页列表失败")
|
||||
rc.ResData = model.ResultPage{
|
||||
Total: total,
|
||||
PageNum: int64(pageNum),
|
||||
@@ -42,9 +42,11 @@ func (r *RoleApi) GetRoleList(rc *restfulx.ReqCtx) {
|
||||
// GetRole 获取Role数据
|
||||
func (r *RoleApi) GetRole(rc *restfulx.ReqCtx) {
|
||||
roleId := restfulx.PathParamInt(rc, "roleId")
|
||||
role := r.RoleApp.FindOne(int64(roleId))
|
||||
role.MenuIds = r.RoleApp.GetRoleMeunId(entity.SysRole{RoleId: int64(roleId)})
|
||||
|
||||
role, err := r.RoleApp.FindOne(int64(roleId))
|
||||
biz.ErrIsNil(err, "查询角色失败")
|
||||
menuIds, err := r.RoleApp.GetRoleMeunId(entity.SysRole{RoleId: int64(roleId)})
|
||||
biz.ErrIsNil(err, "查询角色菜单失败")
|
||||
role.MenuIds = menuIds
|
||||
rc.ResData = role
|
||||
}
|
||||
|
||||
@@ -57,7 +59,8 @@ func (r *RoleApi) InsertRole(rc *restfulx.ReqCtx) {
|
||||
role.DataScope = "0"
|
||||
}
|
||||
// 添加角色对应的菜单
|
||||
insert := r.RoleApp.Insert(role)
|
||||
insert, err := r.RoleApp.Insert(role)
|
||||
biz.ErrIsNil(err, "添加角色失败")
|
||||
role.RoleId = insert.RoleId
|
||||
r.RoleMenuApp.Insert(insert.RoleId, role.MenuIds)
|
||||
//添加权限
|
||||
@@ -71,11 +74,13 @@ func (r *RoleApi) UpdateRole(rc *restfulx.ReqCtx) {
|
||||
restfulx.BindJsonAndValid(rc, &role)
|
||||
role.UpdateBy = rc.LoginAccount.UserName
|
||||
// 修改角色
|
||||
r.RoleApp.Update(role)
|
||||
_, err := r.RoleApp.Update(role)
|
||||
biz.ErrIsNil(err, "修改角色失败")
|
||||
// 删除角色的菜单绑定
|
||||
r.RoleMenuApp.DeleteRoleMenu(role.RoleId)
|
||||
// 添加角色菜单绑定
|
||||
r.RoleMenuApp.Insert(role.RoleId, role.MenuIds)
|
||||
err = r.RoleMenuApp.Insert(role.RoleId, role.MenuIds)
|
||||
biz.ErrIsNil(err, "添加角色菜单绑定失败")
|
||||
//修改api权限
|
||||
ca := casbin.CasbinService{ModelPath: global.Conf.Casbin.ModelPath}
|
||||
ca.UpdateCasbin(role.RoleKey, role.ApiIds)
|
||||
@@ -87,7 +92,8 @@ func (r *RoleApi) UpdateRoleStatus(rc *restfulx.ReqCtx) {
|
||||
restfulx.BindJsonAndValid(rc, &role)
|
||||
role.UpdateBy = rc.LoginAccount.UserName
|
||||
// 修改角色
|
||||
r.RoleApp.Update(role)
|
||||
_, err := r.RoleApp.Update(role)
|
||||
biz.ErrIsNil(err, "修改角色失败")
|
||||
}
|
||||
|
||||
// UpdateRoleDataScope 修改用户角色组织
|
||||
@@ -96,12 +102,17 @@ func (r *RoleApi) UpdateRoleDataScope(rc *restfulx.ReqCtx) {
|
||||
restfulx.BindJsonAndValid(rc, &role)
|
||||
role.UpdateBy = rc.LoginAccount.UserName
|
||||
// 修改角色
|
||||
update := r.RoleApp.Update(role)
|
||||
update, err := r.RoleApp.Update(role)
|
||||
biz.ErrIsNil(err, "修改角色失败")
|
||||
go func() {
|
||||
if role.DataScope != entity.SELFDATASCOPE {
|
||||
organizationIds := make([]int64, 0)
|
||||
if role.DataScope == entity.ALLDATASCOPE {
|
||||
for _, organization := range *r.OrganizationApp.FindList(entity.SysOrganization{}) {
|
||||
orgs, err := r.OrganizationApp.FindList(entity.SysOrganization{})
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
for _, organization := range *orgs {
|
||||
organizationIds = append(organizationIds, organization.OrganizationId)
|
||||
}
|
||||
}
|
||||
@@ -113,7 +124,11 @@ func (r *RoleApi) UpdateRoleDataScope(rc *restfulx.ReqCtx) {
|
||||
}
|
||||
if role.DataScope == entity.ORGALLDATASCOPE {
|
||||
//organizationIds = append(organizationIds, rc.LoginAccount.OrganizationId)
|
||||
organizationIds = r.OrganizationApp.SelectOrganizationIds(entity.SysOrganization{OrganizationId: rc.LoginAccount.OrganizationId})
|
||||
orgIds, err := r.OrganizationApp.SelectOrganizationIds(entity.SysOrganization{OrganizationId: rc.LoginAccount.OrganizationId})
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
organizationIds = orgIds
|
||||
}
|
||||
// 删除角色的组织绑定
|
||||
r.RoleOrganizationApp.Delete(entity.SysRoleOrganization{RoleId: update.RoleId})
|
||||
@@ -134,8 +149,8 @@ func (r *RoleApi) DeleteRole(rc *restfulx.ReqCtx) {
|
||||
// 判断角色下面是否绑定用户
|
||||
for _, rid := range roleIds {
|
||||
user.RoleId = rid
|
||||
role := r.RoleApp.FindOne(rid)
|
||||
list := r.UserApp.FindList(user)
|
||||
role, _ := r.RoleApp.FindOne(rid)
|
||||
list, _ := r.UserApp.FindList(user)
|
||||
if len(*list) == 0 {
|
||||
delList = append(delList, rid)
|
||||
//删除角色绑定api
|
||||
@@ -160,8 +175,8 @@ func (p *RoleApi) ExportRole(rc *restfulx.ReqCtx) {
|
||||
roleKey := restfulx.QueryParam(rc, "roleKey")
|
||||
role := entity.SysRole{Status: status, RoleName: roleName, RoleKey: roleKey}
|
||||
|
||||
list := p.RoleApp.FindList(role)
|
||||
|
||||
list, err := p.RoleApp.FindList(role)
|
||||
biz.ErrIsNil(err, "查询角色列表失败")
|
||||
fileName := utils.GetFileName(global.Conf.Server.ExcelDir, filename)
|
||||
utils.InterfaceToExcel(*list, fileName)
|
||||
rc.Download(fileName)
|
||||
|
||||
@@ -2,9 +2,6 @@ package api
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/kakuilan/kgo"
|
||||
"net/http"
|
||||
"os"
|
||||
"pandax/kit/biz"
|
||||
"pandax/kit/oss"
|
||||
"pandax/kit/restfulx"
|
||||
@@ -17,18 +14,15 @@ import (
|
||||
|
||||
type UploadApi struct{}
|
||||
|
||||
const filePath = "uploads/file"
|
||||
|
||||
// UploadImage 图片上传
|
||||
func (up *UploadApi) UploadImage(rc *restfulx.ReqCtx) {
|
||||
_, fileHeader, err := rc.Request.Request.FormFile("file")
|
||||
fileType := restfulx.QueryParam(rc, "fileType")
|
||||
biz.ErrIsNil(err, "请传入文件")
|
||||
// 判断上传文件类型,不支持返回
|
||||
biz.IsTrue(kgo.KFile.IsImg(fileHeader.Filename), "请传入图片文件")
|
||||
|
||||
local := &tool.Local{Path: filePath}
|
||||
local := &tool.Local{Path: tool.GetFilePath(fileType)}
|
||||
link, fileName, err := local.UploadFile(fileHeader)
|
||||
biz.ErrIsNil(err, "文件上传失败")
|
||||
|
||||
rc.ResData = map[string]string{"fileName": fileName, "filePath": link}
|
||||
}
|
||||
|
||||
@@ -45,18 +39,20 @@ func (p *UploadApi) UplaodToOss(rc *restfulx.ReqCtx) {
|
||||
rc.ResData = fmt.Sprintf("http://%s/%s/%s", config.Endpoint, config.BucketName, yunFileTmpPath)
|
||||
}
|
||||
|
||||
// subpath 是fileName
|
||||
func (up *UploadApi) GetImage(rc *restfulx.ReqCtx) {
|
||||
actual := path.Join(filePath, restfulx.PathParam(rc, "subpath"))
|
||||
http.ServeFile(
|
||||
rc.Response.ResponseWriter,
|
||||
rc.Request.Request,
|
||||
actual)
|
||||
fileType := restfulx.QueryParam(rc, "fileType")
|
||||
actual := path.Join(tool.GetFilePath(fileType), restfulx.PathParam(rc, "subpath"))
|
||||
|
||||
rc.Download(actual)
|
||||
}
|
||||
|
||||
func (up *UploadApi) DeleteImage(rc *restfulx.ReqCtx) {
|
||||
fileName := restfulx.QueryParam(rc, "fileName")
|
||||
fileType := restfulx.QueryParam(rc, "fileType")
|
||||
biz.NotEmpty(fileName, "请传要删除的图片名")
|
||||
err := os.Remove(fmt.Sprintf("%s/%s", filePath, fileName))
|
||||
local := &tool.Local{Path: tool.GetFilePath(fileType)}
|
||||
err := local.DeleteFile(fileName)
|
||||
biz.ErrIsNil(err, "文件删除失败")
|
||||
}
|
||||
|
||||
|
||||
@@ -1,16 +1,17 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"github.com/dgrijalva/jwt-go"
|
||||
"github.com/emicklei/go-restful/v3"
|
||||
"github.com/kakuilan/kgo"
|
||||
"github.com/mssola/user_agent"
|
||||
"pandax/apps/system/api/form"
|
||||
"pandax/apps/system/api/vo"
|
||||
"pandax/apps/system/entity"
|
||||
"pandax/kit/model"
|
||||
"pandax/kit/token"
|
||||
|
||||
"github.com/dgrijalva/jwt-go"
|
||||
"github.com/emicklei/go-restful/v3"
|
||||
"github.com/kakuilan/kgo"
|
||||
"github.com/mssola/user_agent"
|
||||
|
||||
logEntity "pandax/apps/log/entity"
|
||||
logServices "pandax/apps/log/services"
|
||||
|
||||
@@ -63,8 +64,10 @@ func (u *UserApi) Login(rc *restfulx.ReqCtx) {
|
||||
restfulx.BindJsonAndValid(rc, &l)
|
||||
biz.IsTrue(captcha.Verify(l.CaptchaId, l.Captcha), "验证码认证失败")
|
||||
|
||||
login := u.UserApp.Login(entity.Login{Username: l.Username, Password: l.Password})
|
||||
role := u.RoleApp.FindOne(login.RoleId)
|
||||
login, err := u.UserApp.Login(entity.Login{Username: l.Username, Password: l.Password})
|
||||
biz.ErrIsNil(err, "登录失败,用户不存在!")
|
||||
role, err := u.RoleApp.FindOne(login.RoleId)
|
||||
biz.ErrIsNil(err, "用户所属角色查询失败")
|
||||
j := token.NewJWT("", []byte(global.Conf.Jwt.Key), jwt.SigningMethodHS256)
|
||||
token, err := j.CreateToken(token.Claims{
|
||||
UserId: login.UserId,
|
||||
@@ -110,11 +113,13 @@ func (u *UserApi) Auth(rc *restfulx.ReqCtx) {
|
||||
biz.NotEmpty(userName, "用户名必传")
|
||||
var user entity.SysUser
|
||||
user.Username = userName
|
||||
userData := u.UserApp.FindOne(user)
|
||||
role := u.RoleApp.FindOne(userData.RoleId)
|
||||
userData, err := u.UserApp.FindOne(user)
|
||||
biz.ErrIsNil(err, "用户可能不存在!")
|
||||
role, err := u.RoleApp.FindOne(userData.RoleId)
|
||||
biz.ErrIsNil(err, "用户所属角色查询失败")
|
||||
//前端权限
|
||||
permis := u.RoleMenuApp.GetPermis(role.RoleId)
|
||||
menus := u.MenuApp.SelectMenuRole(role.RoleKey)
|
||||
permis, _ := u.RoleMenuApp.GetPermis(role.RoleId)
|
||||
menus, _ := u.MenuApp.SelectMenuRole(role.RoleKey)
|
||||
|
||||
rc.ResData = vo.AuthVo{
|
||||
User: *userData,
|
||||
@@ -156,8 +161,8 @@ func (u *UserApi) GetSysUserList(rc *restfulx.ReqCtx) {
|
||||
user.Phone = phone
|
||||
user.OrganizationId = int64(organizationId)
|
||||
|
||||
list, total := u.UserApp.FindListPage(pageNum, pageSize, user)
|
||||
|
||||
list, total, err := u.UserApp.FindListPage(pageNum, pageSize, user)
|
||||
biz.ErrIsNil(err, "查询用户分页列表失败")
|
||||
rc.ResData = model.ResultPage{
|
||||
Total: total,
|
||||
PageNum: int64(pageNum),
|
||||
@@ -171,14 +176,14 @@ func (u *UserApi) GetSysUserProfile(rc *restfulx.ReqCtx) {
|
||||
|
||||
sysUser := entity.SysUser{}
|
||||
sysUser.UserId = rc.LoginAccount.UserId
|
||||
user := u.UserApp.FindOne(sysUser)
|
||||
|
||||
user, err := u.UserApp.FindOne(sysUser)
|
||||
biz.ErrIsNil(err, "用户可能不存在!")
|
||||
//获取角色列表
|
||||
roleList := u.RoleApp.FindList(entity.SysRole{RoleId: rc.LoginAccount.RoleId})
|
||||
roleList, _ := u.RoleApp.FindList(entity.SysRole{RoleId: rc.LoginAccount.RoleId})
|
||||
//岗位列表
|
||||
postList := u.PostApp.FindList(entity.SysPost{PostId: rc.LoginAccount.PostId})
|
||||
postList, _ := u.PostApp.FindList(entity.SysPost{PostId: rc.LoginAccount.PostId})
|
||||
//获取组织列表
|
||||
organizationList := u.OrganizationApp.FindList(entity.SysOrganization{OrganizationId: rc.LoginAccount.OrganizationId})
|
||||
organizationList, _ := u.OrganizationApp.FindList(entity.SysOrganization{OrganizationId: rc.LoginAccount.OrganizationId})
|
||||
|
||||
postIds := make([]int64, 0)
|
||||
postIds = append(postIds, rc.LoginAccount.PostId)
|
||||
@@ -213,7 +218,8 @@ func (u *UserApi) InsetSysUserAvatar(rc *restfulx.ReqCtx) {
|
||||
sysuser.Avatar = "/" + filPath
|
||||
sysuser.UpdateBy = rc.LoginAccount.UserName
|
||||
|
||||
u.UserApp.Update(sysuser)
|
||||
err := u.UserApp.Update(sysuser)
|
||||
biz.ErrIsNil(err, "修改头像失败")
|
||||
}
|
||||
|
||||
// SysUserUpdatePwd 修改密码
|
||||
@@ -223,7 +229,8 @@ func (u *UserApi) SysUserUpdatePwd(rc *restfulx.ReqCtx) {
|
||||
|
||||
user := entity.SysUser{}
|
||||
user.UserId = rc.LoginAccount.UserId
|
||||
u.UserApp.SetPwd(user, pws)
|
||||
err := u.UserApp.SetPwd(user, pws)
|
||||
biz.ErrIsNil(err, "修改密码失败")
|
||||
}
|
||||
|
||||
// GetSysUser 获取用户
|
||||
@@ -232,19 +239,23 @@ func (u *UserApi) GetSysUser(rc *restfulx.ReqCtx) {
|
||||
|
||||
user := entity.SysUser{}
|
||||
user.UserId = int64(userId)
|
||||
result := u.UserApp.FindOne(user)
|
||||
|
||||
result, err := u.UserApp.FindOne(user)
|
||||
biz.ErrIsNil(err, "用户可能不存在!")
|
||||
var role entity.SysRole
|
||||
var post entity.SysPost
|
||||
var organization entity.SysOrganization
|
||||
|
||||
roles, _ := u.RoleApp.FindList(role)
|
||||
posts, _ := u.PostApp.FindList(post)
|
||||
orgs, _ := u.OrganizationApp.SelectOrganization(organization)
|
||||
|
||||
rc.ResData = vo.UserVo{
|
||||
Data: result,
|
||||
PostIds: result.PostIds,
|
||||
RoleIds: result.RoleIds,
|
||||
Roles: *u.RoleApp.FindList(role),
|
||||
Posts: *u.PostApp.FindList(post),
|
||||
Organizations: u.OrganizationApp.SelectOrganization(organization),
|
||||
Roles: *roles,
|
||||
Posts: *posts,
|
||||
Organizations: orgs,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -252,9 +263,9 @@ func (u *UserApi) GetSysUser(rc *restfulx.ReqCtx) {
|
||||
func (u *UserApi) GetSysUserInit(rc *restfulx.ReqCtx) {
|
||||
|
||||
var role entity.SysRole
|
||||
roles := u.RoleApp.FindList(role)
|
||||
roles, _ := u.RoleApp.FindList(role)
|
||||
var post entity.SysPost
|
||||
posts := u.PostApp.FindList(post)
|
||||
posts, _ := u.PostApp.FindList(post)
|
||||
rc.ResData = vo.UserRolePost{
|
||||
Roles: *roles,
|
||||
Posts: *posts,
|
||||
@@ -266,16 +277,22 @@ func (u *UserApi) GetUserRolePost(rc *restfulx.ReqCtx) {
|
||||
var user entity.SysUser
|
||||
user.UserId = rc.LoginAccount.UserId
|
||||
|
||||
resData := u.UserApp.FindOne(user)
|
||||
|
||||
resData, err := u.UserApp.FindOne(user)
|
||||
biz.ErrIsNil(err, "用户可能不存在!")
|
||||
roles := make([]entity.SysRole, 0)
|
||||
posts := make([]entity.SysPost, 0)
|
||||
for _, roleId := range strings.Split(resData.RoleIds, ",") {
|
||||
ro := u.RoleApp.FindOne(kgo.KConv.Str2Int64(roleId))
|
||||
ro, err := u.RoleApp.FindOne(kgo.KConv.Str2Int64(roleId))
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
roles = append(roles, *ro)
|
||||
}
|
||||
for _, postId := range strings.Split(resData.PostIds, ",") {
|
||||
po := u.PostApp.FindOne(kgo.KConv.Str2Int64(postId))
|
||||
po, err := u.PostApp.FindOne(kgo.KConv.Str2Int64(postId))
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
posts = append(posts, *po)
|
||||
}
|
||||
rc.ResData = vo.UserRolePost{
|
||||
@@ -289,7 +306,8 @@ func (u *UserApi) InsertSysUser(rc *restfulx.ReqCtx) {
|
||||
var sysUser entity.SysUser
|
||||
restfulx.BindJsonAndValid(rc, &sysUser)
|
||||
sysUser.CreateBy = rc.LoginAccount.UserName
|
||||
u.UserApp.Insert(sysUser)
|
||||
_, err := u.UserApp.Insert(sysUser)
|
||||
biz.ErrIsNil(err, "添加用户失败")
|
||||
}
|
||||
|
||||
// UpdateSysUser 修改用户数据
|
||||
@@ -297,7 +315,8 @@ func (u *UserApi) UpdateSysUser(rc *restfulx.ReqCtx) {
|
||||
var sysUser entity.SysUser
|
||||
restfulx.BindJsonAndValid(rc, &sysUser)
|
||||
sysUser.CreateBy = rc.LoginAccount.UserName
|
||||
u.UserApp.Update(sysUser)
|
||||
err := u.UserApp.Update(sysUser)
|
||||
biz.ErrIsNil(err, "修改用户失败")
|
||||
}
|
||||
|
||||
// UpdateSysUserSelf 用户修改数据
|
||||
@@ -305,7 +324,8 @@ func (u *UserApi) UpdateSysUserSelf(rc *restfulx.ReqCtx) {
|
||||
var sysUser entity.SysUser
|
||||
restfulx.BindJsonAndValid(rc, &sysUser)
|
||||
sysUser.UserId = rc.LoginAccount.UserId
|
||||
u.UserApp.Update(sysUser)
|
||||
err := u.UserApp.Update(sysUser)
|
||||
biz.ErrIsNil(err, "修改用户数据失败")
|
||||
}
|
||||
|
||||
// UpdateSysUserStu 修改用户状态
|
||||
@@ -313,13 +333,15 @@ func (u *UserApi) UpdateSysUserStu(rc *restfulx.ReqCtx) {
|
||||
var sysUser entity.SysUser
|
||||
restfulx.BindJsonAndValid(rc, &sysUser)
|
||||
sysUser.CreateBy = rc.LoginAccount.UserName
|
||||
u.UserApp.Update(sysUser)
|
||||
err := u.UserApp.Update(sysUser)
|
||||
biz.ErrIsNil(err, "修改用户状态失败")
|
||||
}
|
||||
|
||||
// DeleteSysUser 删除用户数据
|
||||
func (u *UserApi) DeleteSysUser(rc *restfulx.ReqCtx) {
|
||||
userIds := restfulx.PathParam(rc, "userId")
|
||||
u.UserApp.Delete(utils.IdsStrToIdsIntGroup(userIds))
|
||||
err := u.UserApp.Delete(utils.IdsStrToIdsIntGroup(userIds))
|
||||
biz.ErrIsNil(err, "删除用户失败")
|
||||
}
|
||||
|
||||
// ExportUser 导出用户
|
||||
@@ -334,7 +356,8 @@ func (u *UserApi) ExportUser(rc *restfulx.ReqCtx) {
|
||||
user.Username = username
|
||||
user.Phone = phone
|
||||
|
||||
list := u.UserApp.FindList(user)
|
||||
list, err := u.UserApp.FindList(user)
|
||||
biz.ErrIsNil(err, "用户列表查询失败")
|
||||
// 对设置的文件名进行处理
|
||||
fileName := utils.GetFileName(global.Conf.Server.ExcelDir, filename)
|
||||
utils.InterfaceToExcel(*list, fileName)
|
||||
|
||||
Reference in New Issue
Block a user