...
|
...
|
@@ -40,7 +40,7 @@ func RoleAdd(param protocol.RequestRoleAdd) (*protocol.ResponseRoleInfo, error) |
|
|
return nil, protocol.NewErrWithMessage("1", err)
|
|
|
}
|
|
|
r := &protocol.ResponseRoleInfo{
|
|
|
ID: int(roleid),
|
|
|
ID: roleid,
|
|
|
Name: role.Name,
|
|
|
Descript: role.Descript,
|
|
|
Pid: role.Pid,
|
...
|
...
|
@@ -63,12 +63,18 @@ func RoleDelete(param protocol.RequestRoleDelete) error { |
|
|
return protocol.NewErrWithMessage("1", e)
|
|
|
}
|
|
|
//
|
|
|
if role.Types == models.ROLETYPES_GROUP {
|
|
|
if err := models.DeleteRoleByPid(param.RoleID); err != nil {
|
|
|
e := fmt.Errorf("DeleteRoleByPid err:%s", err)
|
|
|
log.Error(e.Error())
|
|
|
return protocol.NewErrWithMessage("1", e)
|
|
|
}
|
|
|
if role.Types != models.ROLETYPES_ROLE {
|
|
|
e := fmt.Errorf("role.types err")
|
|
|
log.Error(e.Error())
|
|
|
return protocol.NewErrWithMessage("1")
|
|
|
}
|
|
|
cnt, err := models.CountRoleRelatedByUser(param.RoleID)
|
|
|
if err != nil {
|
|
|
log.Error(err.Error())
|
|
|
return protocol.NewErrWithMessage("1")
|
|
|
}
|
|
|
if cnt > 0 {
|
|
|
return protocol.NewErrWithMessage("30001")
|
|
|
}
|
|
|
if err := models.DeleteRoleByID(param.RoleID); err != nil {
|
|
|
e := fmt.Errorf("DeleteRole err:%s", err)
|
...
|
...
|
@@ -119,40 +125,55 @@ func RoleEdit(param protocol.RequestRoleEdit) (*protocol.ResponseRoleInfo, error |
|
|
return r, nil
|
|
|
}
|
|
|
|
|
|
func RoleGroupDelete(param protocol.RequestRoleDelete) error {
|
|
|
var (
|
|
|
roleinfo *models.Role
|
|
|
err error
|
|
|
cnt int64
|
|
|
)
|
|
|
roleinfo, err = models.GetRoleById(param.RoleID)
|
|
|
if err != nil {
|
|
|
e := fmt.Errorf("GetRoleById(%d) err:%s", param.RoleID, err)
|
|
|
log.Error(e.Error())
|
|
|
return protocol.NewErrWithMessage("1", e)
|
|
|
}
|
|
|
if roleinfo.CompanyId != param.CompanyID {
|
|
|
e := fmt.Errorf("roleinfo.CompanyId(%d) != param.CompanyID(%d)", roleinfo.CompanyId, param.CompanyID)
|
|
|
log.Error(e.Error())
|
|
|
return protocol.NewErrWithMessage("1", e)
|
|
|
}
|
|
|
if roleinfo.Types != models.ROLETYPES_GROUP {
|
|
|
e := fmt.Errorf("it is not group")
|
|
|
log.Error(e.Error())
|
|
|
return protocol.NewErrWithMessage("1", e)
|
|
|
}
|
|
|
cnt, err = models.CountRoleByPid(roleinfo.Id)
|
|
|
if err != nil {
|
|
|
log.Error(err.Error())
|
|
|
return protocol.NewErrWithMessage("1")
|
|
|
}
|
|
|
if cnt > 0 {
|
|
|
return protocol.NewErrWithMessage("30001")
|
|
|
}
|
|
|
err = models.DeleteRoleByID(param.RoleID)
|
|
|
if err != nil {
|
|
|
e := fmt.Errorf("DeleteRoleByID(%d) err:%s", param.RoleID, err)
|
|
|
log.Error(e.Error())
|
|
|
return protocol.NewErrWithMessage("1", e)
|
|
|
}
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
//CanSetRole 操作员是否可以操作角色
|
|
|
func CanSetRole(adminId int64, groupId int64) bool {
|
|
|
return false
|
|
|
}
|
|
|
|
|
|
func RoleGetOne(param protocol.RequestRoleOne) (*protocol.ResponseRoleInfo, error) {
|
|
|
// roledata, err := models.GetRoleById(param.RoleID)
|
|
|
return nil, nil
|
|
|
}
|
|
|
|
|
|
// func RoleGetByPage(param protocol.RequestRoleList) (*protocol.ResponseRoleList, error) {
|
|
|
// var (
|
|
|
// where string = `a.company_id=? and a.delete_at=0`
|
|
|
// dataSql string = `SELECT a.id,a.name,a.descript,a.create_at,a.update_at
|
|
|
// FROM role AS a
|
|
|
// where ` + where
|
|
|
// countSql string = `SELECT COUNT(*) FROM role as a where ` + where
|
|
|
// )
|
|
|
// var (
|
|
|
// roleList []protocol.ResponseRoleInfo
|
|
|
// pageinfo protocol.ResponsePageInfo
|
|
|
// err error
|
|
|
// )
|
|
|
// pagequery := utils.NewQueryDataByPage(countSql, dataSql)
|
|
|
// pagequery.LimitPage(param.PageIndex, param.PageSize)
|
|
|
// pagequery.AddParam(param.CompanyId)
|
|
|
// pageinfo, err = pagequery.Query(&roleList)
|
|
|
// if err != nil {
|
|
|
// e := fmt.Errorf("SQL EXECUTE err:%s", err)
|
|
|
// log.Error(e.Error())
|
|
|
// return nil, protocol.NewErrWithMessage("1", e)
|
|
|
// }
|
|
|
// r := &protocol.ResponseRoleList{
|
|
|
// ResponsePageInfo: pageinfo,
|
|
|
// Data: roleList,
|
|
|
// }
|
|
|
// return r, nil
|
|
|
// }
|
|
|
|
|
|
func GetRoleGroup() error {
|
|
|
return nil
|
|
|
}
|
...
|
...
|
|