作者 唐旭辉

职位,角色相关功能

### 接口完成进度
| 功能 | 完成状态 | 时间 | 接口路径 | 请求方式 |
| ---------- | -------- | ---------- | ---------------------- | -------- |
| 登录 | 进行中 | | |
| 短信验证码 | 未开始 | | |
| 获取 token | 未开始 | | |
| 刷新 token | 未开始 | | |
| 添加角色 | 完成 | 2019.11.26 | /v1/rbac/role | post |
| 编辑角色 | 完成 | 2019.11.26 | /v1/rbac/role | put |
| 删除角色 | 完成 | 2019.11.26 | /v1/rbac/role | delete |
| 添加部门 | 完成 | 2019.11.28 | /v1/company/department | post |
| 编辑部门 | 完成 | 2019.11.29 | /v1/company/department | put |
| 删除部门 | 完成 | 2019.11.29 | /v1/company/department | delete |
| 添加职位 | 进行中 | | /v1/company/position | post |
| 编辑职位 | 进行中 | | /v1/company/position | put |
| 删除职位 | 进行中 | | | delete |
| 添加员工 | 未开始 | | | post |
| 编辑员工 | 未开始 | | | put |
| 删除员工 | 未开始 | | | delete |
| 公告管理 | 未开始 | | | |
| 公告管理 | 未开始 | | | |
| 公告管理 | 未开始 | | | |
| 功能 | 完成状态 | 时间 | 接口路径 | 请求方式 |
| -------------- | ------------------ | -------------- | -------------------------- | -------- |
| 登录 | 进行中 | | |
| 短信验证码 | 未开始 | | |
| 获取 token | 未开始 | | |
| 刷新 token | 未开始 | | |
| 添加角色 | 完成 | 2019.11.26 | /v1/rbac/role | post |
| 编辑角色 | 完成 | 2019.11.26 | /v1/rbac/role | put |
| 删除角色 | 完成 | 2019.11.26 | /v1/rbac/role | delete |
| 添加部门 | 完成 | 2019.11.28 | /v1/company/department | post |
| 编辑部门 | 完成 | 2019.11.29 | /v1/company/department | put |
| ~~删除部门~~ | ~~完成(待变更)~~ | ~~2019.11.29~~ | ~~/v1/company/department~~ | delete |
| 删除部门 | 完成 | 2019.12.2 | /v1/company/department | delete |
| 添加职位 | 完成 | 2019.12.2 | /v1/company/position | post |
| 编辑职位 | 完成 | 2019.12.2 | /v1/company/position | put |
| 删除职位 | 完成 | 2019.12.2 | /v1/company/position | delete |
| 添加员工 | 未开始 | | /v1/company/user | post |
| 编辑员工 | 未开始 | | /v1/company/user | put |
| 删除员工 | 未开始 | | /v1/company/user | delete |
| 公告管理 | 未开始 | | | |
| 公告管理 | 未开始 | | | |
| 公告管理 | 未开始 | | | |
| 机会&审批 模板 | 未开始 | | | |
| 机会&审批 模板 | 未开始 | | | |
| 机会&审批 模板 | 未开始 | | | |
| 机会&审批 模板 | 未开始 | | | |
... ...
机会导向项目
\ No newline at end of file
机会导向项目
... ...
... ... @@ -78,12 +78,62 @@ func (c *CompanyController) DepartmentDelete() {
msg = protocol.BadRequestParam("1")
return
}
if param.ID <= 0 {
log.Error(" param.ID <= 0 ")
err := servecompany.DepartmentDelete(param)
msg = protocol.NewReturnResponse(nil, err)
return
}
// PositionAdd 添加职位
// @router /position [post]
func (c *CompanyController) PositionAdd() {
var msg *protocol.ResponseMessage
defer func() {
c.ResposeJson(msg)
}()
var param protocol.RequestPositionAdd
if err := json.Unmarshal(c.Ctx.Input.RequestBody, &param); err != nil {
log.Error("json 解析失败 err:%s", err)
msg = protocol.BadRequestParam("1")
return
}
err := servecompany.DepartmentDelete(param)
positioninfo, err := servecompany.PositionAdd(param)
msg = protocol.NewReturnResponse(positioninfo, err)
return
}
// PositionEdit 编辑职位
// @router /position [put]
func (c *CompanyController) PositionEdit() {
var msg *protocol.ResponseMessage
defer func() {
c.ResposeJson(msg)
}()
var param protocol.RequestPositionEdit
if err := json.Unmarshal(c.Ctx.Input.RequestBody, &param); err != nil {
log.Error("json 解析失败 err:%s", err)
msg = protocol.BadRequestParam("1")
return
}
positioninfo, err := servecompany.PositionEdit(param)
msg = protocol.NewReturnResponse(positioninfo, err)
return
}
// PositionDelete 删除职位
// @router /position [delete]
func (c *CompanyController) PositionDelete() {
var msg *protocol.ResponseMessage
defer func() {
c.ResposeJson(msg)
}()
var param protocol.RequestPositionDelete
if err := json.Unmarshal(c.Ctx.Input.RequestBody, &param); err != nil {
log.Error("json 解析失败 err:%s", err)
msg = protocol.BadRequestParam("1")
return
}
err := servecompany.PositionDelete(param)
msg = protocol.NewReturnResponse(nil, err)
return
}
... ...
... ... @@ -16,7 +16,9 @@ type Position struct {
Relation string `orm:"column(relation);size(1000)" description:"父子级关系树"`
CreateAt time.Time `orm:"column(create_at);type(timestamp)" description:"创建时间"`
UpdateAt time.Time `orm:"column(update_at);type(timestamp)" description:"更新时间"`
DeleteAt time.Time `orm:"column(delete_at);type(timestamp)" description:"删除时间"`
EnableStatus string `orm:"column(enable_status);size(255)" description:"有效状态 1:有效 0:无效"`
Member int `orm:"column(member)"`
}
func (t *Position) TableName() string {
... ... @@ -38,16 +40,6 @@ func (t *Position) SetRelation(parent *Position) error {
}
return nil
}
func (t *Position) ValidatePid() error {
roledata, err := GetPositionById(t.ParentId)
if err != nil {
return err
}
if roledata.CompanyId != t.CompanyId {
return errors.New("validate companyId err")
}
return nil
}
// AddPosition insert a new Position into database and returns
// last inserted Id on success.
... ...
... ... @@ -17,6 +17,7 @@ type Role struct {
Descript string `orm:"column(descript)"`
CreateAt time.Time `orm:"column(create_at);type(timestamp)"`
DeleteAt time.Time `orm:"column(delete_at);type(timestamp)"`
IsDefault int8 `orm:"column(is_default)"`
}
func (t *Role) TableName() string {
... ... @@ -27,11 +28,18 @@ func init() {
orm.RegisterModel(new(Role))
}
//角色类型
const (
ROLETYPES_GROUP int8 = 1 //角色组
ROLETYPES_ROLE int8 = 2 //角色
)
//默认角色
const (
ROLE_DEFAULR int8 = 1 //默认
ROLE_DEFAULR_NOT int8 = 0 // 非默认
)
func (t *Role) ValidateTypes() bool {
switch t.Types {
case ROLETYPES_GROUP:
... ... @@ -43,6 +51,9 @@ func (t *Role) ValidateTypes() bool {
}
func (t *Role) ValidatePid() (*Role, error) {
if t.Pid == 0 {
return nil, nil
}
roledata, err := GetRoleById(t.Pid)
if err != nil {
return nil, err
... ...
... ... @@ -32,8 +32,8 @@ type RequestDepartmentEdit struct {
//RequestDepartmentDelete ...
type RequestDepartmentDelete struct {
ID int64 `json:"id"`
CompanyID int64 `json:"company_id"` //公司
IDs []int64 `json:"ids"`
CompanyID int64 `json:"company_id"` //公司
}
//ResponseDepartmentList ....
... ... @@ -50,6 +50,21 @@ type RequestPositionAdd struct {
//RequestPositionEdit 编辑职位
type RequestPositionEdit struct {
ID int `json:"id"`
ID int64 `json:"id"`
RequestPositionAdd
}
//ResponsePositionInfo ...
type ResponsePositionInfo struct {
ID int64 `json:"id"`
CompanyID int64 `json:"company_id"`
Name string `json:"name"`
ParentID int64 `json:"parent_id"`
ParemtName string `json:"parent_name`
CreateTime int64 `json:"create_time`
}
type RequestPositionDelete struct {
CompanyID int64 `json:"company_id"`
IDs []int64 `json:"ids"`
}
... ...
... ... @@ -15,6 +15,8 @@ func init() {
beego.NSRouter("/department", &controllers.CompanyController{}, "post:DepartmentAdd"),
beego.NSRouter("/department", &controllers.CompanyController{}, "put:DepartmentUpdate"),
beego.NSRouter("/department", &controllers.CompanyController{}, "delete:DepartmentDelete"),
beego.NSRouter("/position", &controllers.CompanyController{}, "post:PositionAdd"),
beego.NSRouter("/position", &controllers.CompanyController{}, "put:PositionEdit"),
),
beego.NSNamespace("/rbac",
beego.NSRouter("/role", &controllers.RbacController{}, "post:RoleAdd"),
... ...
... ... @@ -126,6 +126,11 @@ func DepartmentEdit(param protocol.RequestDepartmentEdit) error {
log.Error(e.Error())
return protocol.NewErrWithMessage("1", e)
}
if newparent.CompanyId != departUpdate.CompanyId {
e := fmt.Errorf("ParentID err")
log.Error(e.Error())
return protocol.NewErrWithMessage("1", e)
}
}
//更新部门关系数据
err = departmentRelationUpdate(departUpdate, newparent)
... ... @@ -201,56 +206,122 @@ func departmentRelationUpdate(departUpdate *models.Department, newparent *models
}
//DepartmentDelete 部门删除,删除整个分枝
// func DepartmentDelete(param protocol.RequestDepartmentDelete) error {
// var (
// departDelete *models.Department
// err error
// )
// departDelete, err = models.GetDepartmentById(param.ID)
// if err != nil {
// e := fmt.Errorf("GetDepartmentById err:%s", err)
// log.Error(e.Error())
// return protocol.NewErrWithMessage("1", e)
// }
// if departDelete.CompanyId != param.CompanyID {
// e := fmt.Errorf("departDelete.CompanyId != param.CompanyID")
// log.Error(e.Error())
// return protocol.NewErrWithMessage("1", e)
// }
// const (
// //获取部门子集 锁数据 select ... for update,
// dataSql0 string = `SELECT id,relation,member FROM department WHERE relation LIKE ? AND delete_at = 0 FOR UPDATE`
// dataSql2 string = `update department set delete_at=? where relation LIKE ?`
// )
// var (
// departSubset []models.Department
// relationLike string = departDelete.Relation + "%"
// nowTime string = time.Now().String()
// )
// o := orm.NewOrm()
// o.Begin()
// err = utils.ExecuteQueryAllWithOrmer(o, &departSubset, dataSql0, relationLike)
// if err != nil {
// o.Rollback()
// e := fmt.Errorf("")
// log.Error(e.Error())
// return protocol.NewErrWithMessage("1", e)
// }
// for _, v := range departSubset {
// if v.Member > 0 {
// o.Rollback()
// e := fmt.Errorf("Member > 0 ")
// log.Error(e.Error())
// return protocol.NewErrWithMessage("1", e)
// }
// }
// err = utils.ExecuteSQLWithOrmer(o, dataSql2, nowTime, relationLike)
// if err != nil {
// o.Rollback()
// e := fmt.Errorf("EXECUTE SQL err:%s", err)
// log.Error(e.Error())
// return protocol.NewErrWithMessage("1", e)
// }
// o.Commit()
// return nil
// }
func DepartmentDelete(param protocol.RequestDepartmentDelete) error {
//检查是否可以被删除
var (
departDelete *models.Department
err error
//根据参数获取的职位
departDelete []*models.Department
//最终需要操作的职位
toDelete = make(map[int64]*models.Department)
)
departDelete, err = models.GetDepartmentById(param.ID)
if err != nil {
e := fmt.Errorf("GetDepartmentById err:%s", err)
log.Error(e.Error())
return protocol.NewErrWithMessage("1", e)
}
if departDelete.CompanyId != param.CompanyID {
e := fmt.Errorf("departDelete.CompanyId != param.CompanyID")
log.Error(e.Error())
return protocol.NewErrWithMessage("1", e)
}
const (
//获取部门子集 锁数据 select ... for update,
dataSql0 string = `SELECT id,relation,member FROM department WHERE relation LIKE ? AND delete_at = 0 FOR UPDATE`
//获取部门子集,
dataSql0 string = `SELECT id,relation,member FROM department WHERE relation LIKE ? AND delete_at = 0 `
dataSql2 string = `update department set delete_at=? where relation LIKE ?`
)
var (
departSubset []models.Department
relationLike string = departDelete.Relation + "%"
nowTime string = time.Now().String()
)
for _, id := range param.IDs {
var p *models.Department
p, err := models.GetDepartmentById(id)
if err != nil {
e := fmt.Errorf("GetDepartmentById(%d)", id)
log.Error(e.Error())
return protocol.NewErrWithMessage("1", e)
}
if p.CompanyId != param.CompanyID {
e := fmt.Errorf("CompanyID err")
log.Error(e.Error())
return protocol.NewErrWithMessage("1", e)
}
departDelete = append(departDelete, p)
toDelete[p.Id] = p
}
for _, pos := range departDelete {
var departSubset []models.Department
relationLike := pos.Relation + "%"
err := utils.ExecuteQueryAll(&departSubset, dataSql0, relationLike)
if err != nil {
e := fmt.Errorf("EXECUTE SQL err:%s", err)
log.Error(e.Error())
return protocol.NewErrWithMessage("1", e)
}
for _, subset := range departSubset {
if subset.Member > 0 {
e := fmt.Errorf("user in department,relation:%s", subset.Relation)
log.Error(e.Error())
return protocol.NewErrWithMessage("1", e)
}
if _, ok := toDelete[subset.Id]; ok {
delete(toDelete, subset.Id)
}
}
}
o := orm.NewOrm()
o.Begin()
err = utils.ExecuteQueryAllWithOrmer(o, &departSubset, dataSql0, relationLike)
if err != nil {
o.Rollback()
e := fmt.Errorf("")
log.Error(e.Error())
return protocol.NewErrWithMessage("1", e)
}
for _, v := range departSubset {
if v.Member > 0 {
nowTime := time.Now()
for _, d := range toDelete {
relationlike := d.Relation + "%"
err := utils.ExecuteSQLWithOrmer(o, dataSql2, nowTime.String(), relationlike)
if err != nil {
o.Rollback()
e := fmt.Errorf("Member > 0 ")
e := fmt.Errorf("EXECUTE SQL err:%s", err)
log.Error(e.Error())
return protocol.NewErrWithMessage("1", e)
}
}
err = utils.ExecuteSQLWithOrmer(o, dataSql2, nowTime, relationLike)
if err != nil {
o.Rollback()
e := fmt.Errorf("EXECUTE SQL err:%s", err)
log.Error(e.Error())
return protocol.NewErrWithMessage("1", e)
}
o.Commit()
return nil
}
... ...
... ... @@ -5,37 +5,42 @@ import (
"oppmg/common/log"
"oppmg/models"
"oppmg/protocol"
"oppmg/utils"
"strings"
"time"
"github.com/astaxie/beego/orm"
)
//PositionAdd 添加职位
func PositionAdd(param protocol.RequestDepartmentAdd) error {
func PositionAdd(param protocol.RequestPositionAdd) (*protocol.ResponsePositionInfo, error) {
var (
parentPosition *models.Position
err error
nowTime = time.Now()
positioninfo *protocol.ResponsePositionInfo
)
positionAdd := &models.Position{
CompanyId: param.CompanyID,
Name: param.Name,
CreateAt: nowTime,
UpdateAt: nowTime,
DeleteAt: time.Unix(0, 0),
ParentId: param.ParentID,
}
if param.ParentID > 0 {
parentPosition, err = models.GetPositionById(param.ParentID)
if err != nil {
e := fmt.Errorf("GetDepartmentById(%d) err:%s", param.ParentID, err)
e := fmt.Errorf("GetPositionById(%d) err:%s", param.ParentID, err)
log.Error(e.Error())
return protocol.NewErrWithMessage("1", e)
return nil, protocol.NewErrWithMessage("1", e)
}
if parentPosition.CompanyId != param.CompanyID {
e := fmt.Errorf("parentDepart.CompanyId != param.CompanyID")
e := fmt.Errorf("parentPosition.CompanyId != param.CompanyID")
log.Error(e.Error())
return protocol.NewErrWithMessage("1", e)
return nil, protocol.NewErrWithMessage("1", e)
}
}
positionAdd := &models.Position{
CompanyId: param.CompanyID,
Name: param.Name,
CreateAt: time.Now(),
UpdateAt: time.Now(),
ParentId: param.ParentID,
}
o := orm.NewOrm()
o.Begin()
... ... @@ -44,23 +49,224 @@ func PositionAdd(param protocol.RequestDepartmentAdd) error {
o.Rollback()
e := fmt.Errorf("AddPosition err:%s", err)
log.Error(e.Error())
return protocol.NewErrWithMessage("1", e)
return nil, protocol.NewErrWithMessage("1", e)
}
err = positionAdd.SetRelation(parentPosition)
if err != nil {
o.Rollback()
e := fmt.Errorf("SetRelation err:%s", err)
log.Error(e.Error())
return protocol.NewErrWithMessage("1", e)
return nil, protocol.NewErrWithMessage("1", e)
}
err = models.UpdatePositionById(positionAdd, []string{"Relation"}, o)
if err != nil {
o.Rollback()
e := fmt.Errorf("UpdatePositionById err:%s", err)
log.Error(e.Error())
return nil, protocol.NewErrWithMessage("1", e)
}
o.Commit()
positioninfo = &protocol.ResponsePositionInfo{
ID: positionAdd.Id,
CompanyID: positionAdd.CompanyId,
Name: positionAdd.Name,
ParentID: positionAdd.ParentId,
ParemtName: "",
CreateTime: nowTime.Unix(),
}
if parentPosition != nil {
positioninfo.ParemtName = parentPosition.Name
}
return positioninfo, nil
}
func PositionEdit(param protocol.RequestPositionEdit) (*protocol.ResponsePositionInfo, error) {
var (
positionUpdate *models.Position
err error
parentPosition *models.Position
positioninfo *protocol.ResponsePositionInfo
nowTime = time.Now()
)
positionUpdate, err = models.GetPositionById(param.ID)
if err != nil {
e := fmt.Errorf("GetDepartmentById(%d) err:%s", param.ID, err)
log.Error(e.Error())
return nil, protocol.NewErrWithMessage("1", e)
}
if positionUpdate.CompanyId != param.CompanyID {
e := fmt.Errorf("depart.CompanyId(%d) !=param.CompanyID(%d)", positionUpdate.CompanyId, param.CompanyID)
log.Error(e.Error())
return nil, protocol.NewErrWithMessage("1", e)
}
positionUpdate.Name = param.Name
positionUpdate.UpdateAt = nowTime
err = models.UpdatePositionById(positionUpdate, []string{"Name", "UpdateAt"})
if err != nil {
e := fmt.Errorf("UpdatePositionById err:%s", err)
log.Error(e.Error())
return nil, protocol.NewErrWithMessage("1", e)
}
//理部门上级发生变化的情况
if param.ParentID != 0 {
parentPosition, err = models.GetPositionById(param.ParentID)
if err != nil {
e := fmt.Errorf("GetDepartmentById(%d) err:%s", param.ParentID, err)
log.Error(e.Error())
return nil, protocol.NewErrWithMessage("1", e)
}
if parentPosition.CompanyId != positionUpdate.CompanyId {
e := fmt.Errorf("ParentID err")
log.Error(e.Error())
return nil, protocol.NewErrWithMessage("1")
}
}
//更新部门关系数据
err = positionRelationUpdate(positionUpdate, parentPosition)
if err != nil {
e := fmt.Errorf("positionRelationUpdate err:%s", err)
log.Error(e.Error())
return nil, protocol.NewErrWithMessage("1", e)
}
positioninfo = &protocol.ResponsePositionInfo{
ID: positionUpdate.Id,
CompanyID: positionUpdate.CompanyId,
Name: positionUpdate.Name,
CreateTime: positionUpdate.CreateAt.Unix(),
}
if param.ParentID != 0 {
positioninfo.ParentID = parentPosition.Id
positioninfo.ParemtName = parentPosition.Name
}
return positioninfo, nil
}
//positionRelationUpdate 处理部门上级发生变化的情况
func positionRelationUpdate(positionUpdate *models.Position, newparent *models.Position) error {
if newparent == nil {
return nil
}
const (
//获取某个部门的下级部门 select ... for update
dataSql0 string = `SELECT id,relation FROM position WHERE relation LIKE ? AND delete_at = 0 FOR UPDATE`
//更新关系树
dataSql2 string = `update position set relation=? where id=?`
//更新departUpdate的parent_id
dataSql3 string = `update position set parent_id=? where id=?`
)
var (
positionSubset []models.Position //子级部门
err error
oldRelation string = positionUpdate.Relation
relationLike string = oldRelation + "%"
newRelation string = fmt.Sprintf("%s/%d", newparent.Relation, positionUpdate.Id)
)
o := orm.NewOrm()
o.Begin()
//修改部门的parent_id
err = utils.ExecuteSQLWithOrmer(o, dataSql3, newparent.Id, positionUpdate.Id)
if err != nil {
o.Rollback()
e := fmt.Errorf("EXECUTE SQL err:%s", err)
log.Error(e.Error())
return protocol.NewErrWithMessage("1", e)
}
//获取部门及子级部门的relation和id
err = utils.ExecuteQueryAllWithOrmer(o, &positionSubset, dataSql0, relationLike)
if err != nil {
o.Rollback()
e := fmt.Errorf("EXECUTE SQL err:%s", err)
log.Error(e.Error())
return protocol.NewErrWithMessage("1", e)
}
//修改部门及子级部门的relation
for i := range positionSubset {
if positionSubset[i].Id == newparent.Id {
//确认新的父级id是否合法
o.Rollback()
e := fmt.Errorf("departSubset[i].Id == newparent.Id")
log.Error(e.Error())
return protocol.NewErrWithMessage("1", e)
}
//重建关系树
s := strings.TrimPrefix(positionSubset[i].Relation, oldRelation)
positionSubset[i].Relation = strings.TrimSpace(fmt.Sprintf("%s%s", newRelation, s))
err = utils.ExecuteSQLWithOrmer(o, dataSql2, positionSubset[i].Relation, positionSubset[i].Id)
if err != nil {
o.Rollback()
e := fmt.Errorf("EXECUTE SQL err:%s", err)
log.Error(e.Error())
return protocol.NewErrWithMessage("1", e)
}
}
o.Commit()
return nil
}
func PositionDelete(param protocol.RequestPositionDelete) error {
//检查是否可以被删除
var (
//根据参数获取的职位
positionDelete []*models.Position
//最终需要操作的职位
toDelete = make(map[int64]*models.Position)
)
const (
//获取部门子集,
dataSql0 string = `SELECT id,relation,member FROM position WHERE relation LIKE ? AND delete_at = 0 `
dataSql2 string = `update position set delete_at=? where relation LIKE ?`
)
for _, id := range param.IDs {
var p *models.Position
p, err := models.GetPositionById(id)
if err != nil {
e := fmt.Errorf("GetPositionById(%d)", id)
log.Error(e.Error())
return protocol.NewErrWithMessage("1", e)
}
if p.CompanyId != param.CompanyID {
e := fmt.Errorf("CompanyID err")
log.Error(e.Error())
return protocol.NewErrWithMessage("1", e)
}
positionDelete = append(positionDelete, p)
toDelete[p.Id] = p
}
for _, pos := range positionDelete {
var positionsubset []models.Position
relationLike := pos.Relation + "%"
err := utils.ExecuteQueryAll(&positionsubset, dataSql0, relationLike)
if err != nil {
e := fmt.Errorf("EXECUTE SQL err:%s", err)
log.Error(e.Error())
return protocol.NewErrWithMessage("1", e)
}
for _, subset := range positionsubset {
if subset.Member > 0 {
e := fmt.Errorf("user in position,relation:%s", subset.Relation)
log.Error(e.Error())
return protocol.NewErrWithMessage("1", e)
}
if _, ok := toDelete[subset.Id]; ok {
delete(toDelete, subset.Id)
}
}
}
o := orm.NewOrm()
o.Begin()
nowTime := time.Now()
for _, d := range toDelete {
relationlike := d.Relation + "%"
err := utils.ExecuteSQLWithOrmer(o, dataSql2, nowTime.String(), relationlike)
if err != nil {
o.Rollback()
e := fmt.Errorf("EXECUTE SQL err:%s", err)
log.Error(e.Error())
return protocol.NewErrWithMessage("1", e)
}
}
o.Commit()
return nil
}
... ...
package company
func userAdd() error {
return nil
}
func userEdit() error {
return nil
}
... ...
package rbac
... ...
... ... @@ -24,11 +24,11 @@ func RoleAdd(param protocol.RequestRoleAdd) (*protocol.ResponseRoleInfo, error)
return nil, protocol.NewErrWithMessage("1", e)
}
var (
parentRole *models.Role
err error
roleid int64
//parentRole *models.Role
err error
roleid int64
)
parentRole, err = role.ValidatePid()
_, err = role.ValidatePid()
if err != nil {
e := fmt.Errorf("ValidatePid err:%s", err)
log.Error(e.Error())
... ... @@ -44,7 +44,6 @@ func RoleAdd(param protocol.RequestRoleAdd) (*protocol.ResponseRoleInfo, error)
Name: role.Name,
Descript: role.Descript,
Pid: role.Pid,
ParentName: parentRole.Name,
Types: role.Types,
CreateTime: role.CreateAt.Unix(), //Format("2006-01-02 15:04:05")
}
... ... @@ -81,9 +80,9 @@ func RoleDelete(param protocol.RequestRoleDelete) error {
func RoleEdit(param protocol.RequestRoleEdit) (*protocol.ResponseRoleInfo, error) {
var (
parentRole *models.Role
role *models.Role
err error
//parentRole *models.Role
role *models.Role
err error
)
role, err = models.GetRoleById(param.ID)
if err != nil {
... ... @@ -99,7 +98,7 @@ func RoleEdit(param protocol.RequestRoleEdit) (*protocol.ResponseRoleInfo, error
role.Pid = param.Pid
role.Descript = param.Descript
role.Name = param.Name
if parentRole, err = role.ValidatePid(); err != nil {
if _, err = role.ValidatePid(); err != nil {
e := fmt.Errorf("ValidatePid err:%s", err)
log.Error(e.Error())
return nil, protocol.NewErrWithMessage("1", e)
... ... @@ -114,7 +113,6 @@ func RoleEdit(param protocol.RequestRoleEdit) (*protocol.ResponseRoleInfo, error
Name: role.Name,
Descript: role.Descript,
Pid: role.Pid,
ParentName: parentRole.Name,
Types: role.Types,
CreateTime: role.CreateAt.Unix(),
}
... ... @@ -166,3 +164,7 @@ func RoleHasPermission() error {
func PermissionHasRole() error {
return nil
}
func RolsHasUser() error {
return nil
}
... ...
package rbac
... ...