...
|
...
|
@@ -5,6 +5,7 @@ import ( |
|
|
"oppmg/common/log"
|
|
|
"oppmg/models"
|
|
|
"oppmg/protocol"
|
|
|
"oppmg/utils"
|
|
|
"time"
|
|
|
)
|
|
|
|
...
|
...
|
@@ -43,9 +44,7 @@ func RoleAdd(param protocol.RequestRoleAdd) (*protocol.ResponseRoleInfo, error) |
|
|
ID: roleid,
|
|
|
Name: role.Name,
|
|
|
Descript: role.Descript,
|
|
|
Pid: role.Pid,
|
|
|
Types: role.Types,
|
|
|
CreateTime: role.CreateAt.Unix(), //Format("2006-01-02 15:04:05")
|
|
|
}
|
|
|
return r, nil
|
|
|
}
|
...
|
...
|
@@ -53,7 +52,7 @@ func RoleAdd(param protocol.RequestRoleAdd) (*protocol.ResponseRoleInfo, error) |
|
|
func RoleDelete(param protocol.RequestRoleDelete) error {
|
|
|
role, err := models.GetRoleById(param.RoleID)
|
|
|
if err != nil {
|
|
|
e := fmt.Errorf("GetRoleById err:%s", err)
|
|
|
e := fmt.Errorf("GetRoleById(%d) err:%s", param.RoleID, err)
|
|
|
log.Error(e.Error())
|
|
|
return protocol.NewErrWithMessage("1", e)
|
|
|
}
|
...
|
...
|
@@ -86,7 +85,6 @@ func RoleDelete(param protocol.RequestRoleDelete) error { |
|
|
|
|
|
func RoleEdit(param protocol.RequestRoleEdit) (*protocol.ResponseRoleInfo, error) {
|
|
|
var (
|
|
|
//parentRole *models.Role
|
|
|
role *models.Role
|
|
|
err error
|
|
|
)
|
...
|
...
|
@@ -118,9 +116,7 @@ func RoleEdit(param protocol.RequestRoleEdit) (*protocol.ResponseRoleInfo, error |
|
|
ID: role.Id,
|
|
|
Name: role.Name,
|
|
|
Descript: role.Descript,
|
|
|
Pid: role.Pid,
|
|
|
Types: role.Types,
|
|
|
CreateTime: role.CreateAt.Unix(),
|
|
|
}
|
|
|
return r, nil
|
|
|
}
|
...
|
...
|
@@ -169,6 +165,57 @@ func CanSetRole(adminId int64, groupId int64) bool { |
|
|
return false
|
|
|
}
|
|
|
|
|
|
func GetRoleList(companyId int64) ([]protocol.RoleGroup, error) {
|
|
|
var (
|
|
|
roleGroups []protocol.RoleGroup
|
|
|
err error
|
|
|
groups []protocol.RoleInfo
|
|
|
)
|
|
|
groups, err = getRoleGroupByCompany(companyId)
|
|
|
if err != nil {
|
|
|
log.Error("getRoleGroupByCompany err:%s", err)
|
|
|
return roleGroups, protocol.NewErrWithMessage("1")
|
|
|
}
|
|
|
for k, v := range groups {
|
|
|
var roles []protocol.RoleInfo
|
|
|
roles, err = getRoleInfoByPid(companyId, v.Id)
|
|
|
if err != nil {
|
|
|
log.Error("getRoleInfoByPid err:%s", err)
|
|
|
return roleGroups, protocol.NewErrWithMessage("1")
|
|
|
}
|
|
|
rolegroup := protocol.RoleGroup{
|
|
|
RoleInfo: groups[k],
|
|
|
Roles: roles,
|
|
|
}
|
|
|
roleGroups = append(roleGroups, rolegroup)
|
|
|
}
|
|
|
return roleGroups, nil
|
|
|
}
|
|
|
|
|
|
func getRoleInfoByPid(companyid int64, pid int64) ([]protocol.RoleInfo, error) {
|
|
|
const (
|
|
|
dataSql string = `SELECT id,name,is_default FROM role WHERE company_id=? AND pid=? and delete_at=0 `
|
|
|
)
|
|
|
var (
|
|
|
err error
|
|
|
roles []protocol.RoleInfo
|
|
|
)
|
|
|
err = utils.ExecuteQueryAll(&roles, dataSql, companyid, pid)
|
|
|
return roles, err
|
|
|
}
|
|
|
|
|
|
func getRoleGroupByCompany(companyid int64) ([]protocol.RoleInfo, error) {
|
|
|
const (
|
|
|
datasql string = `SELECT id,name,is_default FROM role WHERE company_id=? AND types=? AND delete_at=0 `
|
|
|
)
|
|
|
var (
|
|
|
err error
|
|
|
roles []protocol.RoleInfo
|
|
|
)
|
|
|
err = utils.ExecuteQueryAll(&roles, datasql, companyid, models.ROLETYPES_GROUP)
|
|
|
return roles, err
|
|
|
}
|
|
|
|
|
|
func RoleGetOne(param protocol.RequestRoleOne) (*protocol.ResponseRoleInfo, error) {
|
|
|
// roledata, err := models.GetRoleById(param.RoleID)
|
|
|
return nil, nil
|
...
|
...
|
|