我有一个简单的检查用户 ID 是否存在于 db 中rule "check if user is already present"agenda-group "dbcheck" when $blackListUserDto : BlackListUserDto( ) eval( BlackListServiceImpl.isUserBlacklisted($blackListUserDto) ) then System.out.println("to be executed first"); System.out.println($blackListUserDto.isUserAlreadyBlacklisted());endisUserBlacklisted方法如下public static boolean isUserBlacklisted(BlackListUserDto blackListUserDto) { try { BlackListEntity blackListEntity = blackListRepository.findByUserId(blackListUserDto.getUserId()); if(blackListEntity!=null) { blackListUserDto.setUserAlreadyBlacklisted(true); } else //do something else } catch (Exception e) { e.printStackTrace(); return false; } return true; }可以看出,我正在通过 setUserAlreadyBlacklisted(true) 修改 fact(dto) blackListUserDto。但是在我打印值时规则的“然后”部分System.out.println($blackListUserDto.isUserAlreadyBlacklisted()); 输出仍然是假的。我还需要在另一个规则中共享这些数据,如下所示rule "blacklist user"agenda-group "blacklist" when (BlackListUserDto( userAlreadyBlacklisted == false )) then //do something elseend到目前为止,我的理解是,当我编辑事实时,我们是否需要再次重新插入它们?如果是,那么我如何将它插入到同一个会话中,因为有另一种方法可以创建此会话,如下所示:-public void blacklistUser(String userId) throws IOException { BlackListUserDto blackListUserDto=new BlackListUserDto(); blackListUserDto.setUserId(userId); KieSession kieSession = kContainer.newKieSession(); Agenda agenda = kieSession.getAgenda(); agenda.getAgendaGroup( "blacklist" ).setFocus(); agenda.getAgendaGroup( "dbcheck" ).setFocus(); kieSession.insert(blackListUserDto); kieSession.insert(queryTypeDto); kieSession.fireAllRules(); kieSession.dispose(); }为了确保事实得到更新并且更新后的值反映在下一条规则中,需要进行哪些更改。
添加回答
举报
0/150
提交
取消