|
|
@@ -0,0 +1,94 @@
|
|
|
+package com.lc.ibps.platform.plan.job;
|
|
|
+
|
|
|
+import com.lc.ibps.base.core.util.AppUtil;
|
|
|
+import com.lc.ibps.base.core.util.BeanUtils;
|
|
|
+import com.lc.ibps.base.core.util.JacksonUtil;
|
|
|
+import com.lc.ibps.base.saas.token.ITenantTokenService;
|
|
|
+import com.lc.ibps.base.web.context.ContextUtil;
|
|
|
+import com.lc.ibps.bpmn.api.IBpmInstService;
|
|
|
+import com.lc.ibps.cloud.entity.APIResult;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.quartz.JobDataMap;
|
|
|
+import org.quartz.JobExecutionContext;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
+
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+public class ThirdPartyWorkflowJob extends AbstractJob{
|
|
|
+
|
|
|
+ public static final String TABLE_NAME = "TABLE_NAME";
|
|
|
+ public static final String FORM_KEY = "FORM_KEY";
|
|
|
+ public static final String DEF_KEY = "DEF_KEY";
|
|
|
+ public static final String NODE_NUM = "NODE_NUM";
|
|
|
+
|
|
|
+ private static final Logger logger = LoggerFactory.getLogger(QualityIndicatorJob.class);
|
|
|
+ @Override
|
|
|
+ public void executeJob(JobExecutionContext context) throws Exception {
|
|
|
+ JobDataMap dataMap = context.getMergedJobDataMap();
|
|
|
+ logger.warn("group={} job={} trigger={} is running.",
|
|
|
+ context.getJobDetail().getKey().getGroup(),
|
|
|
+ context.getJobDetail().getKey().getName(),
|
|
|
+ context.getTrigger().getKey().getName());
|
|
|
+ logger.warn("jobDataMap=is {}.", JacksonUtil.toJsonString(dataMap.getWrappedMap()));
|
|
|
+ String[] tableNameAry = dataMap.getString(TABLE_NAME).split(";");
|
|
|
+ String[] formKeyAry = dataMap.getString(FORM_KEY).split(";");
|
|
|
+ String[] defKeyAry = dataMap.getString(DEF_KEY).split(";");
|
|
|
+ String[] nodeNumAry = dataMap.getString(NODE_NUM).split(";");
|
|
|
+ splitAry(tableNameAry,formKeyAry, defKeyAry,nodeNumAry);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取第三方数据后存入表中,再根据定时任务启动流程
|
|
|
+ * 其中定时任务配置参数如果有多个按照";"分隔,每个参数一一对应,如
|
|
|
+ * TABLE_NAME:t_dlxmsnzkyfx;t_fjbbjlb
|
|
|
+ * FORM_KEY:dlxmsnzkyfxzjbg;fjbbjlb
|
|
|
+ * DEF_KEY:Process_1cauof8;Process_0mg6v16
|
|
|
+ *
|
|
|
+ * @param tableNameAry
|
|
|
+ * @param formKeyAry
|
|
|
+ * @param defKeyAry
|
|
|
+ */
|
|
|
+ private void splitAry(String[] tableNameAry, String[] formKeyAry, String[] defKeyAry, String[] nodeNumAry) {
|
|
|
+ for (int i = 0; i < tableNameAry.length; i++) {
|
|
|
+ String tableName = tableNameAry[i];
|
|
|
+ String formKey = formKeyAry[i];
|
|
|
+ String defKey = defKeyAry[i];
|
|
|
+ String nodeNum = nodeNumAry[i];
|
|
|
+ if(tableName != null && !tableName.isEmpty() &&
|
|
|
+ formKey != null && !formKey.isEmpty() &&
|
|
|
+ defKey != null && !defKey.isEmpty()&&
|
|
|
+ nodeNum != null && !nodeNum.isEmpty()) {
|
|
|
+ logger.warn("Ready Start Workflow:tableName={},formKey={},defKey={},nodeNum={}", tableName, formKey, defKey, nodeNum);
|
|
|
+ startWorkflow(tableName,formKey,defKey, Integer.parseInt(nodeNum));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ protected void startWorkflow(String tableName, String formKey, String defKey, Integer nodeNum) {
|
|
|
+ String fetchSql = "SELECT id_ FROM %s WHERE shi_fou_guo_shen_='待编制'";
|
|
|
+ fetchSql = String.format(fetchSql,tableName);
|
|
|
+ List<Map<String, Object>> list = (List<Map<String, Object>>) commonDao.query(fetchSql);
|
|
|
+ if (BeanUtils.isEmpty(list)) return;
|
|
|
+ IBpmInstService bpmInstService = AppUtil.getBean(IBpmInstService.class);
|
|
|
+ if (StringUtils.isBlank(ContextUtil.getCurrentAccessToken())) {
|
|
|
+ ITenantTokenService tenantTokenService = AppUtil.getBean(ITenantTokenService.class);
|
|
|
+ String accessToken = tenantTokenService.getAccessToken();
|
|
|
+ ContextUtil.setCurrentAccessToken(accessToken);
|
|
|
+ }
|
|
|
+ for (Map<String, Object> objectMap : list) {
|
|
|
+ APIResult<String> result = bpmInstService.startFlowFromList(new String[]{(String) objectMap.get("id_")}, formKey, defKey);
|
|
|
+ result.getState();
|
|
|
+ if (nodeNum >1) {
|
|
|
+ //流程节点大于1的要改变状态避免被下次定时任务查到
|
|
|
+ String updateSql = "update "+tableName+" set shi_fou_guo_shen_='已编制' where id_='"+objectMap.get("id_")+"'";
|
|
|
+ commonDao.execute(updateSql);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+}
|