@Override
public void setStatus(String id, Integer bpmStatus) {
List<LyntglAmmeterInfoDO> lyntglAmmeterInfoDOS = lyntglAmmeterInfoMapper.selectBpmList(id);
if (lyntglAmmeterInfoDOS != null && lyntglAmmeterInfoDOS.size()>0){
lyntglAmmeterInfoDOS.forEach(item->{
item.setStatus(Long.parseLong(bpmStatus.toString()));
lyntglAmmeterInfoMapper.updateById(item);
});
}
if (bpmStatus == 3){
if (!lyntglAmmeterInfoDOS.isEmpty()) {
String subNoBatch = lyntglAmmeterInfoDOS.get(0).getSubBatchNo(); // 假设subnobatch是你需要的参数
// 执行kettle,传递subnobatch参数
kettleUtils.runKTR(kettleFileName,subNoBatch);
}
}
}
审批成功后执行kettle传递批次号参数
runKTR:
/**
* @title runKTR
* @description 执行KTR文件
* @param fileName
* @param subBatchNo 提交批次号
* @return Map
*/
public Map<String,Object> runKTR(String fileName,String subBatchNo) {
Map<String,Object> map = new HashMap<>();
int code = 200;
String msg = "";
try {
System.setProperty("KETTLE_PLUGIN_CLASSES", "org.pentaho.di.trans.steps.append.AppendMeta");
// 初始化环境
KettleEnvironment.init();
TransMeta transMeta = new TransMeta(kettleFilePath+fileName);
Trans trans = new Trans(transMeta);
// 向作业中添加参数-批次号
trans.setParameterValue("sub_batch_no", subBatchNo);
// 执行Kettle作业
trans.execute(null);
trans.waitUntilFinished();
if (trans.getErrors() > 0) {
code = 500;
msg = "KTR failed with errors.";
}
msg = "KTR executed successfully.";
} catch (KettleException e) {
msg = "Error-KTR: " + e.getMessage();
}
map.put("code",code);
map.put("msg",msg);
return map;
}
需要的pom依赖:
<!-- 关联kettle -->
<dependency>
<groupId>pentaho-kettle</groupId>
<artifactId>kettle-core</artifactId>
</dependency>
<dependency>
<groupId>pentaho-kettle</groupId>
<artifactId>kettle-engine</artifactId>
</dependency>
<dependency>
<groupId>org.pentaho.di.plugins</groupId>
<artifactId>pdi-core-plugins-impl</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>