@Override public void modifyUser2Menu(User user) throws BusinessException { if (user == null || user.getId() == null) { throw new BusinessException("用户不存在!"); } CoreUserModel coreUserEntity = new CoreUserModel(); coreUserEntity.setId(user.getId()); // 先清除旧的关联关系,后再计算新的关联关系 User2MenuModel user2MenuModel = new User2MenuModel(); user2MenuModel.setUserId(user.getId()); user2MenuDao.deleteByModel(user2MenuModel); Set<Integer> menuIds = user.getMenuIds(); if (menuIds != null && !menuIds.isEmpty()) { List<User2MenuModel> user2MenuModelList = new ArrayList<User2MenuModel>(); Iterator<Integer> it = menuIds.iterator(); while (it.hasNext()) { Integer menuId = it.next(); if (menuId != null) { user2MenuModel = new User2MenuModel(); user2MenuModel.setUserId(user.getId()); user2MenuModel.setMenuId(menuId); user2MenuModelList.add(user2MenuModel); } } user2MenuDao.batchInsert(user2MenuModelList); } }
@Override public List<User> getUsersByModel(CoreUserModel userModel) { if (userModel != null && StringUtils.isNotBlank(userModel.getUsername())) { userModel.setUsername("%" + userModel.getUsername() + "%"); } List<User> list = coreUserDao.getUsersByModel(userModel); return list; }