spring-boot - Drools 规则未从 Spring Boot 应用程序中的计划作业执行
问题描述
我处于 Drools 的初学者水平。我有一个用例,我需要从 Spring Boot 应用程序中安排一个作业(cron)。在这项工作中,我需要触发存储在 .xlsx 文件中的规则。问题是 cron 作业运行时没有触发规则。但是当我通过单元测试类运行相同的 cron 作业时,规则会成功执行。我试图调试问题,但无法检测到问题。请在下面找到我的 drools 配置和 cron 作业。
private void getKieRepository() {
final KieRepository kieRepository = kieServices.getRepository();
kieRepository.addKieModule(new KieModule() {
public ReleaseId getReleaseId() {
return kieRepository.getDefaultReleaseId();
}
});
}
public KieSession getKieSession() {
getKieRepository();
KieFileSystem kieFileSystem = kieServices.newKieFileSystem();
kieFileSystem.write(ResourceFactory.newClassPathResource("rules/hospitalRules.xlsx"));
KieBuilder kb = kieServices.newKieBuilder(kieFileSystem);
kb.buildAll();
KieModule kieModule = kb.getKieModule();
KieContainer kContainer = kieServices.newKieContainer(kieModule.getReleaseId());
return kContainer.newKieSession();
}
下面是我注释为@Schedule 的方法:
@Autowired
DroolsConfigurationForBilling config;
@Scheduled(cron = "${bill.cron.job}")
public void calculateDailyBilling() throws ParseException {
log.info("# Billing job started at ");
String uploadDir = fileStorageProperties.getUploadDir();
LocalDate current = LocalDate.now();
String start = current.withDayOfMonth(1).format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
String end = current.withDayOfMonth(current.lengthOfMonth()).format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
Date startDate1 = formatter.parse(start);
Date endDate1 = formatter.parse(end);
List<Study> studies = billStudyRepository.getBillingStudyByDate(startDate1, endDate1);
BillStudy bs = null;
Double hospitalRate = null, userRate = null;
BillComputationResult bcr = null;
try {
for (Study s : studies) {
bs = billStudyRepository.findByStudyId(s.getId());
if (bs == null) {
bs = new BillStudy();
}
bs.setStudy(s);
hospitalRate = computeHospitalBill(s);
bcr = computeDoctorBill(s);
}
log.info("# Billing utility run successfully");
} catch (Exception e) {
log.error("# Error while calculating flat bill for studies.", e);
}
private Double computeHospitalBill(Study s) {
BillHospital bh = null;
String modality = modalityMapping.get(s.getModality().getName());
String hospitalName = s.getHospital().getName();
HospitalBillingDto dto = new HospitalBillingDto();
dto.setHospitalName(hospitalName);
dto.setModality(modality);
dto.setDoctorName(s.getSubmittedDoctor().getFirstName());
dto.setStudyDescription(s.getStudyDescription());
KieSession kieSession = config.getKieSession();
kieSession.insert(dto);
int fireAllRules = kieSession.fireAllRules();
System.out.println("Hospital " + dto.getHospitalName() + " " + dto.getModality() + " " + dto.getHospitalRate());
// }
if (modality == null) {
return null;
}
bh = s.getHospital().getBillHospital();
if (bh == null) {
log.error("Hospital bill not defined, could not compute bill");
return null;
}
return new Double(dto.getHospitalRate());
}
}
解决方案
推荐阅读
- google-chrome - 无法安装站点:页面没有清单URL
- sql - 查询以下内容的最佳或最简单方法是什么
- wordpress - 加载简码 Wordpress 直到页面加载完成
- html - SVG(?)导致空白
- python - 在弧形补丁之间填充 - Matplotlib
- firebase - 有没有办法从 Google Endpoints 调用 firebase 可调用函数
- php - php list - 将项目放在单独的行上
- firebase-realtime-database - Firebase RTDB REST API 重新连接而不发送数据
- python-3.x - 如何拆分“['string1']['string2']['string3']”
- laravel - 如何在 OctoberCMS 中覆盖模型属性和方法?