@Override public void terminateInvite(Long id) { CompanyInvite companyInvite = companyInviteDao.findUniqueBy("id", id); companyInvite.setStatus(InviteState.INVITE_TERMINATE.getIndex()); String hql = "from UserCompany uc where uc.userId=? and uc.companyId=?"; UserCompany userCompany = userCompanyDao.findUnique(hql, companyInvite.getReceiverId(), companyInvite.getCompanyId()); userCompanyDao.delete(userCompany.getId()); List<UserGroupCompany> userGroupCompanys = UserGroupCompanyDao.findBy("companyId", companyInvite.getCompanyId()); if (!userGroupCompanys.isEmpty()) { List<Long> ids = new ArrayList<Long>(); for (UserGroupCompany userGroupCompany : userGroupCompanys) { ids.add(userGroupCompany.getUserGroupId()); } String dHql = "delete UserUserGroup uug where uug.userId=:userId and uug.userGroupId in (:ids)"; Map<String, Object> map = new HashMap<String, Object>(); map.put("ids", ids); map.put("userId", companyInvite.getReceiverId()); userUserGroupDao.delete(dHql, map); } }
@Override public void acceptedInvite(long id) { CompanyInvite companyInvite = companyInviteDao.findUniqueBy("id", id); companyInvite.setStatus(InviteState.INVITE_ACCEPTED.getIndex()); UserCompany userCompany = new UserCompany(); userCompany.setCompanyId(companyInvite.getCompanyId()); userCompany.setUserId(companyInvite.getReceiverId()); userCompanyDao.save(userCompany); }