@Service
public class RoleServiceImpl implements RoleService {
@Resource
private RolePOMapper mapper;
@Override
public int deleteByPrimaryKey(Integer roleId) {
// TODO Auto-generated method stub
return 0;
}
@Override
public int insert(RolePO record) {
return mapper.insert(record);
}
@Override
public int insertSelective(RolePO record) {
// TODO Auto-generated method stub
return 0;
}
@Override
public RolePO selectByPrimaryKey(Integer roleId) {
return mapper.selectByPrimaryKey(roleId);
}
@Override
public List<RolePO> selectRoles(RolePO record) {
return mapper.queryList(record);
}
@Override
public int updateByPrimaryKeySelective(RolePO record) {
return 0;
}
@Override
public int updateByPrimaryKey(RolePO record) {
return mapper.updateByPrimaryKey(record);
}
@Override
public void assign(Integer roleId, Integer[] checkMenuIds) {
// 先删除原来已经分配的角色和菜单的数据
mapper.deleteAllMenuOfRole(roleId);
// 在重新插入新选择的菜单项
if (checkMenuIds != null && checkMenuIds.length >= 1) {
for (Integer menuId : checkMenuIds) {
// 插入到角色和菜单中间表
mapper.saveRoleMenu(roleId,menuId);
}
}
}
@Override
public Integer getUserCountUseRole(Integer roleId) {
return mapper.getUserCountUseRole(roleId);
}
/**
* 删除角色和角色相关信息
*/
@Override
public void deleteRoleInfo(Integer roleId) {
// 删除用户和角色中间表信息
mapper.deleteUserRole(roleId);
// 删除角色和菜单中间表信息
mapper.deleteRoleMenu(roleId);
// 删除角色信息
mapper.deleteByPrimaryKey(roleId);
}
}