/** @generated */ @Transactional public void save(String userId, String roleId) { Assert.notNull(userId, "保存用户不能为空!"); Assert.notNull(roleId, "保存角色不能为空!"); GsysUser gsysUser = new GsysUser(); gsysUser.setId(userId); GsysRole gsysRole = new GsysRole(); gsysRole.setId(roleId); GsysRelUserRole gsysRelUserRole = new GsysRelUserRole(); gsysRelUserRole.setGsysUser(gsysUser); gsysRelUserRole.setGsysRole(gsysRole); hibernateDao.save(gsysRelUserRole); }
/** @generated */ @Transactional public void save(String userId, String[] roleIds) { Assert.notNull(userId, "保存用户不能为空!"); Assert.notNull(roleIds, "保存角色不能为空!"); GsysUser gsysUser = new GsysUser(); gsysUser.setId(userId); List<GsysRelUserRole> gsysRelUserRoleList = new ArrayList<GsysRelUserRole>(); for (String roleId : roleIds) { GsysRole gsysRole = new GsysRole(); gsysRole.setId(roleId); GsysRelUserRole gsysRelUserRole = new GsysRelUserRole(); gsysRelUserRole.setGsysUser(gsysUser); gsysRelUserRole.setGsysRole(gsysRole); gsysRelUserRoleList.add(gsysRelUserRole); } hibernateDao.save(gsysRelUserRoleList); }
@Transactional public void addNewRole(GsysUser gsysUser, List<String> relGsysRoleCheckIdList) { Assert.notNull(gsysUser, "用户不能为空!"); Assert.notNull(gsysUser.getId(), "用户标识不能为空!"); if (null == relGsysRoleCheckIdList) return; List<GsysRelUserRole> gsysRelUserRolelist = new ArrayList<GsysRelUserRole>(); for (String roleId : relGsysRoleCheckIdList) { final String hql = "select count(*) from GsysRelUserRole m where m.gsysUser.id =:userId and m.gsysRole.id =:roleId"; int count = IntegerUtil.valueOf( hibernateDao .createQuery(hql) .setString("userId", gsysUser.getId()) .setString("roleId", roleId) .uniqueResult()); if (count == 1) { continue; } if (count > 1) { final String delhql = "delete from GsysRelUserRole m where m.gsysUser.id =:userId and m.gsysRole.id =:roleId"; hibernateDao .createQuery(delhql) .setString("userId", gsysUser.getId()) .setString("roleId", roleId) .executeUpdate(); } GsysRelUserRole gsysRoleUserRole = new GsysRelUserRole(); // rel gsysRole GsysRole gsysRole = new GsysRole(); gsysRole.setId(roleId); gsysRoleUserRole.setGsysRole(gsysRole); // rel gsysUser gsysRoleUserRole.setGsysUser(gsysUser); gsysRelUserRolelist.add(gsysRoleUserRole); } if (!gsysRelUserRolelist.isEmpty()) { hibernateDao.save(gsysRelUserRolelist); } }
public void checkGsysUserRelGsysRole(GsysUser gsysUser, List<String> relGsysRoleCheckIdList) { Assert.notNull(gsysUser, "用户不能为空!"); Assert.notNull(gsysUser.getId(), "用户标识不能为空!"); List<String> relIds = getRelGsysRoleIdsByGsysUserId(gsysUser.getId()); if (null == relGsysRoleCheckIdList || relGsysRoleCheckIdList.isEmpty()) { if (null != relIds && relIds.size() > 0) { final String hql = "delete from GsysRelUserRole m where m.gsysUser.id =?"; hibernateDao.delete(hql, gsysUser.getId()); } return; } // 需要添加的对象 List<String> deleteIds = ChangeUtil.exclude(relIds, relGsysRoleCheckIdList); // 需要删除的对象 List<String> addIds = ChangeUtil.exclude(relGsysRoleCheckIdList, relIds); if (null != deleteIds && !deleteIds.isEmpty()) { final String hql = "delete from GsysRelUserRole m where m.gsysUser.id =:userId and m.gsysRole.id in (:deleteIds)"; hibernateDao .createQuery(hql) .setString("userId", gsysUser.getId()) .setParameterList("deleteIds", deleteIds) .executeUpdate(); } if (null != addIds && !addIds.isEmpty()) { List<GsysRelUserRole> gsysRelUserRolelist = new ArrayList<GsysRelUserRole>(); for (String gsysRoleId : addIds) { GsysRelUserRole gsysRoleUserRole = new GsysRelUserRole(); // rel gsysRole GsysRole gsysRole = new GsysRole(); gsysRole.setId(gsysRoleId); gsysRoleUserRole.setGsysRole(gsysRole); // rel gsysUser gsysRoleUserRole.setGsysUser(gsysUser); gsysRelUserRolelist.add(gsysRoleUserRole); } hibernateDao.save(gsysRelUserRolelist); } }