| package com.xzx.gc.role.service; | 
|   | 
|   | 
| import com.github.pagehelper.PageHelper; | 
| import com.github.pagehelper.PageInfo; | 
| import com.xzx.gc.entity.*; | 
| import com.xzx.gc.model.RoleDataAccessFunction; | 
| import com.xzx.gc.model.admin.CoreFunctionModel; | 
| import com.xzx.gc.model.admin.MoneyModel; | 
| import com.xzx.gc.model.dto.LazyEntity; | 
| import com.xzx.gc.model.query.FunctionQuery; | 
| import com.xzx.gc.role.mapper.CoreMenuMapper; | 
| import com.xzx.gc.role.mapper.CoreRoleMenuMapper; | 
| import com.xzx.gc.role.mapper.RoleFunctionConsoleMapper; | 
| import com.xzx.gc.role.rbac.tree.FunctionItem; | 
|   | 
| import org.springframework.beans.factory.annotation.Autowired; | 
| import org.springframework.stereotype.Service; | 
| import org.springframework.transaction.annotation.Transactional; | 
| import tk.mybatis.mapper.entity.Example; | 
|   | 
| import java.util.*; | 
|   | 
| /** | 
|  * @author lijiazhi | 
|  * | 
|  */ | 
| @Service | 
| @Transactional | 
| public class FunctionConsoleService{ | 
|   | 
|     @Autowired | 
|     RoleFunctionConsoleMapper roleFunctionConsoleDao; | 
|     @Autowired | 
|     CoreRoleMenuMapper sysRoleMenuDao; | 
|     @Autowired | 
|     CorePlatformService platformService; | 
|     /** | 
|      * 得到角色对应的所有功能点 | 
|      * @param roleId | 
|      * @return | 
|      */ | 
|     public List<Long> getFunctionByRole(Long roleId){ | 
|         return roleFunctionConsoleDao.getFunctionIdByRole(roleId); | 
|     } | 
|   | 
|     public void updateSysRoleFunction(Long roleId,List<Long> adds,List<Long> dels){ | 
|         for(Long del:dels){ | 
|   | 
|             //同时,需要删除与此功能关联的菜单 | 
|             CoreRoleMenu sysRoleMenu = querySysRoleMenu(roleId,del); | 
|             if(sysRoleMenu!=null){ | 
|                 sysRoleMenuDao.deleteByPrimaryKey(sysRoleMenu.getId()); | 
|             } | 
|         } | 
|         List<CoreRoleMenu> sysRoleMenuList = querySysRoleMenuList(roleId); | 
|         for (CoreRoleMenu menu:sysRoleMenuList) { | 
|             sysRoleMenuDao.deleteByPrimaryKey(menu.getId()); | 
|         } | 
|         for(Long add:adds){ | 
|             //同时,需要增加菜单 | 
|             CoreRoleMenu roleMenu = new CoreRoleMenu(); | 
|             roleMenu.setMenuId(add); | 
|             roleMenu.setRoleId(roleId); | 
|             sysRoleMenuDao.insert(roleMenu); | 
|         } | 
|         //} | 
|   | 
|         //清楚缓存 | 
|         platformService.clearFunctionCache(); | 
|   | 
|     } | 
|   | 
|     private CoreRoleMenu querySysRoleMenu(Long roleId,Long menuId){ | 
|         Example example = new Example(CoreRoleMenu.class); | 
|         Example.Criteria criteria = example.createCriteria(); | 
|         criteria.andEqualTo("menuId",menuId); | 
|         criteria.andEqualTo("roleId",roleId); | 
|        /* CoreRoleMenu query= new CoreRoleMenu(); | 
|         query.setMenuId(menuId); | 
|         query.setRoleId(roleId);*/ | 
|         List<CoreRoleMenu> menus = sysRoleMenuDao.selectByExample(example); | 
|         return menus.isEmpty()?null:menus.get(0); | 
|     } | 
|   | 
|     private List<CoreRoleMenu> querySysRoleMenuList(Long roleId){ | 
|         Example example = new Example(CoreRoleMenu.class); | 
|         Example.Criteria criteria = example.createCriteria(); | 
|         criteria.andEqualTo("roleId",roleId); | 
|         List<CoreRoleMenu> menus = sysRoleMenuDao.selectByExample(example); | 
|         return menus; | 
|     } | 
|   | 
|     public List<Long> getFunctionByRoleMenu(Long roleId){ | 
|         return roleFunctionConsoleDao.getFunctionByRoleMenu(roleId); | 
|     } | 
|   | 
| } |