123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- package service
- import (
- "iot_manager_service/app/system/dao"
- "iot_manager_service/app/system/model"
- "iot_manager_service/util"
- )
- // 角色管理服务
- var RoleService = new(roleService)
- type roleService struct{}
- func (s *roleService) Get(id int64) (*dao.Role, error) {
- role := &dao.Role{
- ID: id,
- }
- err := role.Get()
- if err != nil {
- return nil, err
- }
- return role, nil
- }
- func (s *roleService) List(roleName, tenantId, roleAlias string, current, size int) ([]dao.Role, error) {
- role := &dao.Role{}
- offset := (current - 1) * size
- limit := size
- if roleName != "" {
- role.RoleName = roleName
- }
- if tenantId != "" {
- role.TenantId = tenantId
- }
- if roleAlias != "" {
- role.RoleAlias = roleAlias
- }
- roles, err := role.GetRoles(offset, limit)
- if err != nil {
- return nil, err
- }
- return roles, nil
- }
- func (s *roleService) Tree() error {
- return nil
- }
- func (s *roleService) Submit(req dao.Role) *util.Errors {
- role := &req
- if role.ID == 0 {
- err := role.Save()
- if err != nil {
- return util.FailResponse(err.Error(), nil)
- }
- return util.SuccessResponse(util.Succeeded, nil)
- }
- err := role.Update()
- if err != nil {
- return util.FailResponse(err.Error(), nil)
- }
- return util.SuccessResponse(util.Succeeded, nil)
- }
- func (s *roleService) GetList() ([]dao.Role, error) {
- role := &dao.Role{}
- roles, err := role.GetAll()
- if err != nil {
- return nil, err
- }
- return roles, nil
- }
- func (s *roleService) Remove(id int64) *util.Errors {
- role := &dao.Role{
- ID: id,
- IsDeleted: 1,
- }
- queryRole := &dao.Role{
- ParentId: id,
- IsDeleted: 0,
- }
- if queryRole.IsExistChild() {
- return util.FailResponse(model.ExistChild, nil)
- }
- err := role.Remove()
- if err != nil {
- return util.FailResponse(err.Error(), nil)
- }
- return nil
- }
- func (s *roleService) Grant(req *model.ReqRoleGrant) error {
- roleIds := util.StringToIntArray(req.RoleIds)
- //todo 数据权限 接口权限
- menuIds := util.StringToIntArray(req.MenuIds)
- menuErr := RoleMenuService.UpdateRoleMenus(roleIds, menuIds)
- return menuErr
- }
|