...
|
...
|
@@ -9,10 +9,11 @@ import ( |
|
|
)
|
|
|
|
|
|
func RoleAdd(param protocol.RequestRoleAdd) (*protocol.ResponseRoleInfo, error) {
|
|
|
nowTime := time.Now()
|
|
|
role := models.Role{
|
|
|
CompanyId: param.CompanyID,
|
|
|
Name: param.Name,
|
|
|
CreateAt: time.Now(),
|
|
|
CreateAt: nowTime,
|
|
|
Pid: param.Pid,
|
|
|
Types: param.Types,
|
|
|
Descript: param.Descript,
|
...
|
...
|
@@ -22,21 +23,30 @@ func RoleAdd(param protocol.RequestRoleAdd) (*protocol.ResponseRoleInfo, error) |
|
|
log.Error(e.Error())
|
|
|
return nil, protocol.NewErrWithMessage("1", e)
|
|
|
}
|
|
|
err := role.ValidatePid()
|
|
|
var (
|
|
|
parentRole *models.Role
|
|
|
err error
|
|
|
roleid int64
|
|
|
)
|
|
|
parentRole, err = role.ValidatePid()
|
|
|
if err != nil {
|
|
|
e := fmt.Errorf("ValidatePid err:%s", err)
|
|
|
log.Error(e.Error())
|
|
|
return nil, protocol.NewErrWithMessage("1", e)
|
|
|
}
|
|
|
roleid, err := models.AddRole(&role)
|
|
|
roleid, err = models.AddRole(&role)
|
|
|
if err != nil {
|
|
|
log.Error("AddRole err:%s", err)
|
|
|
return nil, protocol.NewErrWithMessage("1", err)
|
|
|
}
|
|
|
r := &protocol.ResponseRoleInfo{
|
|
|
ID: int(roleid),
|
|
|
Name: role.Name,
|
|
|
Descript: role.Descript,
|
|
|
ID: int(roleid),
|
|
|
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")
|
|
|
}
|
|
|
return r, nil
|
|
|
}
|
...
|
...
|
@@ -53,11 +63,15 @@ func RoleDelete(param protocol.RequestRoleDelete) error { |
|
|
log.Error(e.Error())
|
|
|
return protocol.NewErrWithMessage("1", e)
|
|
|
}
|
|
|
//TODO
|
|
|
//
|
|
|
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 err := models.DeleteRole(param.RoleID); err != nil {
|
|
|
if err := models.DeleteRoleByID(param.RoleID); err != nil {
|
|
|
e := fmt.Errorf("DeleteRole err:%s", err)
|
|
|
log.Error(e.Error())
|
|
|
return protocol.NewErrWithMessage("1", e)
|
...
|
...
|
@@ -67,8 +81,9 @@ func RoleDelete(param protocol.RequestRoleDelete) error { |
|
|
|
|
|
func RoleEdit(param protocol.RequestRoleEdit) (*protocol.ResponseRoleInfo, error) {
|
|
|
var (
|
|
|
role *models.Role
|
|
|
err error
|
|
|
parentRole *models.Role
|
|
|
role *models.Role
|
|
|
err error
|
|
|
)
|
|
|
role, err = models.GetRoleById(param.ID)
|
|
|
if err != nil {
|
...
|
...
|
@@ -84,7 +99,7 @@ func RoleEdit(param protocol.RequestRoleEdit) (*protocol.ResponseRoleInfo, error |
|
|
role.Pid = param.Pid
|
|
|
role.Descript = param.Descript
|
|
|
role.Name = param.Name
|
|
|
if err = role.ValidatePid(); err != nil {
|
|
|
if parentRole, err = role.ValidatePid(); err != nil {
|
|
|
e := fmt.Errorf("ValidatePid err:%s", err)
|
|
|
log.Error(e.Error())
|
|
|
return nil, protocol.NewErrWithMessage("1", e)
|
...
|
...
|
@@ -95,15 +110,19 @@ func RoleEdit(param protocol.RequestRoleEdit) (*protocol.ResponseRoleInfo, error |
|
|
return nil, protocol.NewErrWithMessage("1", e)
|
|
|
}
|
|
|
r := &protocol.ResponseRoleInfo{
|
|
|
ID: param.ID,
|
|
|
Name: param.Name,
|
|
|
Descript: param.Descript,
|
|
|
ID: role.Id,
|
|
|
Name: role.Name,
|
|
|
Descript: role.Descript,
|
|
|
Pid: role.Pid,
|
|
|
ParentName: parentRole.Name,
|
|
|
Types: role.Types,
|
|
|
CreateTime: role.CreateAt.Unix(),
|
|
|
}
|
|
|
return r, nil
|
|
|
}
|
|
|
|
|
|
func RoleGetOne(param protocol.RequestRoleOne) (*protocol.ResponseRoleInfo, error) {
|
|
|
|
|
|
// roledata, err := models.GetRoleById(param.RoleID)
|
|
|
return nil, nil
|
|
|
}
|
|
|
|
...
|
...
|
|