From 40529f7d2cadd71c72cb89c7f79046a8ff689df5 Mon Sep 17 00:00:00 2001 From: huanghongfa <18228131219@163.com> Date: 星期四, 24 十二月 2020 17:45:10 +0800 Subject: [PATCH] 系统管理 --- springcloud_k8s_panzhihuazhihuishequ/service_user/src/main/java/com/panzhihua/service_user/service/impl/RoleServiceImpl.java | 142 +++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 142 insertions(+), 0 deletions(-) diff --git a/springcloud_k8s_panzhihuazhihuishequ/service_user/src/main/java/com/panzhihua/service_user/service/impl/RoleServiceImpl.java b/springcloud_k8s_panzhihuazhihuishequ/service_user/src/main/java/com/panzhihua/service_user/service/impl/RoleServiceImpl.java new file mode 100644 index 0000000..8eb14b8 --- /dev/null +++ b/springcloud_k8s_panzhihuazhihuishequ/service_user/src/main/java/com/panzhihua/service_user/service/impl/RoleServiceImpl.java @@ -0,0 +1,142 @@ +package com.panzhihua.service_user.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.panzhihua.common.model.vos.MenuVO; +import com.panzhihua.common.model.vos.R; +import com.panzhihua.common.model.vos.user.RoleVO; +import com.panzhihua.service_user.dao.RoleDAO; +import com.panzhihua.service_user.dao.SysUserRoleDAO; +import com.panzhihua.service_user.model.dos.SysRoleDO; +import com.panzhihua.service_user.model.dos.SysUserRoleDO; +import com.panzhihua.service_user.service.RoleService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.BeanUtils; +import org.springframework.stereotype.Service; +import org.springframework.util.ObjectUtils; + +import javax.annotation.Resource; +import java.util.ArrayList; +import java.util.List; + +/** + * @program: springcloud_k8s_panzhihuazhihuishequ + * @description: 权限 + * @author: huang.hongfa weixin hhf9596 qq 959656820 + * @create: 2020-11-25 15:59 + **/ +@Slf4j +@Service +public class RoleServiceImpl implements RoleService { + @Resource + private RoleDAO roleDAO; + @Resource + private SysUserRoleDAO sysUserRoleDAO; + /** + * 获取平台所有的菜单按钮权限 + * + * @return 菜单按钮权限 + */ + @Override + public R<List<MenuVO>> getAllMenu() { + List<MenuVO> menuVOS=roleDAO.selectAllMenuUrl(); + return R.ok(menuVOS); + } + + /** + * 获取某个人的所有角色 + * + * @param username 用户ID + * @return 所有角色 + */ + @Override + public R<List<String>> getUserRoles(String username) { + List<String> roles=roleDAO.selectRoles(username); + return R.ok(roles); + } + + /** + * 查询社区的党委角色 + * + * @param communityId 社区id + * @return 党委角色列表 + */ + @Override + public R listIdentity(Integer communityId) { + List<RoleVO> roleVOS=new ArrayList<>(); + List<SysRoleDO> sysRoleDOS = roleDAO.selectList(new QueryWrapper<SysRoleDO>().lambda().eq(SysRoleDO::getCommunityId, communityId)); + if (!ObjectUtils.isEmpty(sysRoleDOS)) { + sysRoleDOS.forEach(sysRoleDO -> { + RoleVO roleVO=new RoleVO(); + BeanUtils.copyProperties(sysRoleDO,roleVO); + roleVOS.add(roleVO); + }); + } + return R.ok(roleVOS); + } + + /** + * 角色下拉列表 + * + * @param communityId 对应社区 0 表示运营后台 + * @return 角色集合 + */ + @Override + public R listRoleBackstage(Long communityId) { + List<SysRoleDO> sysRoleDOS = roleDAO.selectList(new QueryWrapper<SysRoleDO>().lambda().eq(SysRoleDO::getCommunityId, communityId)); + if (ObjectUtils.isEmpty(sysRoleDOS)) { + return R.fail("角色列表为空"); + } + List<RoleVO>roleVOS=new ArrayList<>(); + sysRoleDOS.forEach(sysRoleDO -> { + RoleVO roleVO=new RoleVO(); + BeanUtils.copyProperties(sysRoleDO,roleVO); + roleVOS.add(roleVO); + }); + return R.ok(roleVOS); + } + + /** + * 新增角色 + * + * @param roleVO 角色信息 + * @return 新增结果 + */ + @Override + public R addRoleBackstage(RoleVO roleVO) { + SysRoleDO sysRoleDO=new SysRoleDO(); + BeanUtils.copyProperties(roleVO,sysRoleDO); + int insert = 0; + try { + insert = roleDAO.insert(sysRoleDO); + } catch (Exception e) { + e.printStackTrace(); + log.error("新增角色失败,失败原因【{}】",e.getMessage()); + if (e.getMessage().contains("unique_role_name_community_id")) { + return R.fail("角色已经存在"); + } + } + if (insert>0) { + return R.ok(); + } + return R.fail(); + } + + /** + * 删除角色 + * + * @param roleVO 角色主键 + * @return 删除结果 + */ + @Override + public R deleteRoleBackstage(RoleVO roleVO) { + Integer integer = sysUserRoleDAO.selectCount(new QueryWrapper<SysUserRoleDO>().lambda().eq(SysUserRoleDO::getRoleId, roleVO.getRoleId())); + if (integer>0) { + return R.fail("该角色的关联用户数量不为0,不能删除"); + } + int delete = roleDAO.deleteById(roleVO.getRoleId()); + if (delete==0) { + return R.fail("角色不存在"); + } + return R.ok(); + } +} -- Gitblit v1.7.1