我是春季靴子和流口水的新手。 我编写(复制)了一些代码以将流口水(决策表)公开为Web服务。 一切正常,但我有问题。
我想在应用程序运行时在excel电子表格中进行更改。
当我进行更改并构建应用程序时,虽然进行了更改,但我希望它在应用程序运行时能够正常工作。
对不起,语法和代码格式是我的第一个问题。 预先谢谢你
@RestController
public class FCCRObjectScoreController {
private final DroolsService service;
@Autowired
public FCCRObjectScoreController(DroolsService service) {
this.service = service;
}
@RequestMapping(value = "/fraud",
method = /*RequestMethod.GET*/ RequestMethod.POST, produces = "application/json")
public Client getQuestions(
@RequestParam(required = true) boolean resident,
@RequestParam(required = true) String name,
@RequestParam(required = true) int age,
@RequestParam(required = true) String type,
@RequestParam(required = true) String fraud,
@RequestParam(required = true) String emp) throws JsonParseException, JsonMappingException, IOException {
ObjectMapper mapper = new ObjectMapper();
Employer employer = mapper.readValue(emp, Employer.class);
Client client = new Client(name, resident, age, type, fraud,employer);
return service.getOutput(client);
}
}
@Service
public class DroolsService {
private KieSession kieSession = new DroolsConfiguration().getKieSession();;
public Client getOutput(Client cli){
kieSession.insert(cli);
kieSession.fireAllRules();
return cli;
}
}
public class DroolsConfiguration {
private static final String RULES_PATH = "/drools-demo-springboot/src/main/resources/drools/";
private KieServices kieServices;
private KieFileSystem getKieFileSystem() throws IOException{
KieFileSystem kieFileSystem = kieServices.newKieFileSystem();
System.out.println("ovde");
List<String> rules=Arrays.asList("rules.xlsx");
System.out.println("ovde");
for(String rule:rules){
kieFileSystem.write(ResourceFactory.newClassPathResource(rule));
}
return kieFileSystem;
}
public KieContainer getKieContainer() throws IOException {
getKieRepository();
KieBuilder kb = kieServices.newKieBuilder(getKieFileSystem());
kb.buildAll();
KieModule kieModule = kb.getKieModule();
KieContainer kContainer = kieServices.newKieContainer(kieModule.getReleaseId());
return kContainer;
}
private void getKieRepository() {
this.kieServices=KieServices.Factory.get();
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("drools/rules.xlsx"));
KieBuilder kb = kieServices.newKieBuilder(kieFileSystem);
kb.buildAll();
KieModule kieModule = kb.getKieModule();
KieContainer kContainer = kieServices.newKieContainer(kieModule.getReleaseId());
return kContainer.newKieSession();
}
}