一个在调度作业中,异常后发送SQL的实例代码原创
2人赞赏了该文章
469次浏览
编辑于2021年11月10日 20:32:24
屏蔽具体的业务逻辑,我需要在调度作业A中根据查询到符合条件的ids(个数不定),然后在线程池里一一执行,执行中发现有异常的话,就给数据库直接下语句。相关内容在开发门户有提示,
https://dev.kingdee.com/index/docsNew/6e2418bb-5ad6-4122-8b0e-3b8e2f6156ee
我完成了对应的功能,提供代码如下,是在异常中下语句给SQL的,代码如下
public class ybfQueryTask extends AbstractTask { private final static Log logger= LogFactory.getLog(ybfQueryTask.class); private final static String operaterecordFormId ="kdps_operaterecord"; @Override public void execute(RequestContext requestContext, Map<String, Object> map) throws KDException { DynamicObjectCollection backComandIds = QueryServiceHelper.query( operaterecordFormId, "kdps_commandid, id", new QFilter[]{ new QFilter("kdps_isneed", QCP.equals, "A") , new QFilter("kdps_opertype", QCP.equals, "backup"), new QFilter("kdps_commandid", QCP.is_notnull, "") , new QFilter("kdps_commandid", QCP.not_equals, "") }, "id desc", 10000); for( int k=0; k<backComandIds.size(); k++ ) { DynamicObject data = BusinessDataServiceHelper.newDynamicObject(operaterecordFormId); String dbroukey = data.getDynamicObjectType().getDBRouteKey(); String backComandId = ((DynamicObject) backComandIds.get(k)).getString("kdps_commandid"); String sql = "update tk_kdps_operate set fk_kdps_isneed='B', fk_kdps_issuccess='0', fk_kdps_isouttime='1' where fk_kdps_commandid ='"+backComandId +"' " ; long recodId = ((DynamicObject) backComandIds.get(k)).getLong("id"); ThreadPools.executeOnce("ybfQueryTask", new Runnable() { @Override public void run() { boolean isoutTime = false; try { Optional<HelperResult<?>> res = AskExecuteResult.getResultJsonObject(backComandId); if(res.isPresent()) { HelperResult helperResult = res.get(); ////这是成功的表示 if(helperResult.getCode()==200) { Optional<HelperBackUpRs> qbackupRs = Optional.ofNullable(JSONObject.parseObject(String.valueOf(helperResult.getData()), HelperBackUpRs.class)); if(qbackupRs.isPresent()) { HelperBackUpRs rs = qbackupRs.get(); JSONObject data = (JSONObject)rs.getDatas().get(0); DBOperHelper.backup_candle( (Object)data.get("BillNo"), data.getString("BakName"), data.getString("FileKey"),data.getFloat("FileSize"), data.getString("FileMD5") , recodId ); } } } } catch (Exception e) { ////因为过时,要进行处理了 String meg = e.getMessage().toString(); if(meg.contains("commandid不存在,请录入正确的命令id")) { DB.execute(DBRoute.of(dbroukey), sql); } } } }); } } }
值得一提的dbroukty,是可以在单据type中获取的,其代码为
DynamicObject data = BusinessDataServiceHelper.newDynamicObject(operaterecordFormId);
String dbroukey = data.getDynamicObjectType().getDBRouteKey();
抛砖引玉,共勉。
赞 2
2人点赞
还没有人点赞,快来当第一个点赞的人吧!
打赏
0人打赏
还没有人打赏,快来当第一个打赏的人吧!
推荐阅读