Commit 072eb612 by zhouhaibao

[+]策略代码处理

1 parent 84dcaa58
package cn.com.glsx.process.modules.sop.execute.executor;
import cn.com.glsx.process.common.constant.Constants;
import cn.com.glsx.process.modules.entity.SopInst;
import org.springframework.stereotype.Service;
import com.alibaba.fastjson.JSON;
......@@ -31,8 +32,24 @@ public class JavaExecutor implements SopNodeExecutor {
// java参数处理,执行java
DynamicEngine de = DynamicEngine.getInstance();
// 获取实例快照,传给处理器
SopInst inst = sop.getInst();
String instSnapshot = inst.getInstSnapshot();
JSONObject jsonObject = new JSONObject();
jsonObject.put("id", 22);
// 节点信息
jsonObject.put("sopId", inst.getInstId());
jsonObject.put("sopName", inst.getInstName());
jsonObject.put("nodeId", node.getNodeId());
jsonObject.put("nodeName", node.getNodeName());
// 节点入参
jsonObject.put("nodeData", node.getNodeParam());
// 实例快照
jsonObject.put("instSnapshot", instSnapshot);
Object instance = de.execute("Controller", javacode, "execute", new Class[]{JSON.class}, new Object[]{jsonObject});
// 处理返回结果
......
......@@ -3,6 +3,7 @@
package cn.com.glsx.process.modules.sop.execute.executor;
import cn.com.glsx.process.common.constant.Constants;
import cn.com.glsx.process.modules.entity.SopInst;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
......@@ -36,12 +37,17 @@ public class SqlExecutor implements SopNodeExecutor {
// 获取配置参数信息
String nodeContent = node.getNodeContent();
JSONObject paramMap = JSON.parseObject(nodeContent);
String sqlcode = paramMap.get("source") + "";
String dataSourceId = paramMap.get("dataSourceId") + "";
// 执行sql插件
SopDataSource byId = sopDataSourceService.findByName(dataSourceId);
SopBizAdapter mcgBizAdapter = new FlowDataAdapterImpl(byId);
codeReplace(sqlcode, sop, node);
int i = mcgBizAdapter.executeUpdate(sqlcode);
// 处理执行结果
......@@ -55,4 +61,34 @@ public class SqlExecutor implements SopNodeExecutor {
return executeStruct;
}
/**
* 替换sql里面的通配符
*
* @param sqlcode sql脚本
* @param sop sop实例
* @param node sop节点
*/
private void codeReplace(String sqlcode, SopStruct sop, SopInstNode node) {
SopInst inst = sop.getInst();
String instSnapshot = inst.getInstSnapshot();
JSONObject jsonObject = JSONObject.parseObject(instSnapshot);
// 替换关联业务的活动id
String activityId = jsonObject.get("activityId") + "";
if (activityId != null) {
sqlcode.replace("#{activityId}", activityId);
}
// 替换关联的instId
if (activityId != null) {
sqlcode.replace("#{instId}", inst.getInstId());
}
String nodeParam = node.getNodeParam();
JSONObject nodeJsonObject = JSONObject.parseObject(nodeParam);
for (Map.Entry<String, Object> entry : nodeJsonObject.entrySet()) {
sqlcode.replace("#{" + entry.getKey() + "}", entry.getValue() + "");
}
}
}
\ No newline at end of file
......@@ -5,6 +5,7 @@ import java.util.List;
import java.util.Map;
import cn.com.glsx.process.common.constant.Constants;
import cn.com.glsx.process.modules.entity.SopInst;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
......@@ -43,6 +44,7 @@ public class SqlQueryExecutor implements SopNodeExecutor {
SopDataSource byId = sopDataSourceService.findByName(dataSourceId);
SopBizAdapter mcgBizAdapter = new FlowDataAdapterImpl(byId);
List<Map<String, Object>> maps = mcgBizAdapter.tableQuery(sqlcode);
codeReplace(sqlcode, sop, node);
// 处理执行结果
resultMap.put(Constants.RES_DATE_KEY, maps);
......@@ -55,4 +57,28 @@ public class SqlQueryExecutor implements SopNodeExecutor {
return executeStruct;
}
private void codeReplace(String sqlcode, SopStruct sop, SopInstNode node) {
SopInst inst = sop.getInst();
String instSnapshot = inst.getInstSnapshot();
JSONObject jsonObject = JSONObject.parseObject(instSnapshot);
// 替换关联业务的活动id
String activityId = jsonObject.get("activityId") + "";
if (activityId != null) {
sqlcode.replace("#{activityId}", activityId);
}
// 替换关联的instId
if (activityId != null) {
sqlcode.replace("#{instId}", inst.getInstId());
}
String nodeParam = node.getNodeParam();
JSONObject nodeJsonObject = JSONObject.parseObject(nodeParam);
for (Map.Entry<String, Object> entry : nodeJsonObject.entrySet()) {
sqlcode.replace("#{" + entry.getKey() + "}", entry.getValue() + "");
}
}
}
\ No newline at end of file
......@@ -43,10 +43,6 @@ public class StartExecutor implements SopNodeExecutor {
return executeStruct;
}
public void updateBatch() {
}
public static void main(String[] args) {
String json = "{\"merchantId\":{\"paramName\":\"merchantId\",\"paramDesc\":\"门店id,分配给门店时需要赋值\",\"valueType\":\"String\",\"defaultValue\":\"\",\"required\":true},\"stages\":{\"paramName\":\"stages\",\"paramDesc\":\"旅程阶段,值类型为Json\",\"valueType\":\"Json\",\"defaultValue\":{\"stage1\":{\"value\":\"潜客\",\"editable\":false,\"conditions\":[\"链接(#膨胀金活动名称#) 反馈\",\"链接(#膨胀金活动名称#) 反馈\"]},\"stage2\":{\"value\":\"高意向\",\"editable\":true,\"conditions\":[\"链接(#膨胀金活动名称#) 反馈\",\"链接(#膨胀金活动名称#) 反馈\"]},\"stage3\":{\"value\":\"下单\",\"editable\":false,\"conditions\":[\"链接(#膨胀金活动名称#) 反馈\",\"链接(#膨胀金活动名称#) 反馈\"]},\"stage4\":{\"value\":\"战败\",\"editable\":false,\"conditions\":[\"链接(#膨胀金活动名称#) 反馈\",\"链接(#膨胀金活动名称#) 反馈\"]}},\"required\":true},\"users\":{\"paramName\":\"users\",\"paramDesc\":\"通过膨胀金活动导入的用户信息\",\"valueType\":\"Json\",\"defaultValue\":{\"u0001\":{\"userId\":\"u0001\",\"userName\":\"张三\",\"followId\":\"跟进人id1\",\"textContent\":\"文案内容:尊敬的${userName},优惠券领取url.cn/dE32C1Ab7\"},\"u0002\":{\"userId\":\"u0002\",\"userName\":\"李四\",\"followId\":\"跟进人id2\",\"textContent\":\"文案内容:尊敬的${userName},优惠券领取url.cn/dE32C1Ab7\"}},\"required\":true}}";
......
......@@ -7,6 +7,7 @@ import com.alibaba.fastjson.JSONObject;
/**
* java执行器使用demo,http请求,类名Controller,方法名execute
* TODO 1.推送客户行为数据
*/
public class ControllerHttpDemo {
......
......@@ -23,6 +23,8 @@ import com.alibaba.fastjson.JSONObject;
/**
* java执行器使用demo,rop请求,类名Controller,方法名execute
* TODO 1.下发门店助手任务
* TODO 2.查询到保日期
*/
public class ControllerRopHttpDemo {
......@@ -36,10 +38,20 @@ public class ControllerRopHttpDemo {
private final static String method = "merchants.api.open.findStaffListByMerchantNo";
public static JSON execute(JSON param) {
// 将JSON字符串转换为Map
// 将Map中的数据放入MultiValueMap中
Object post = null;
JSONObject jsonObject = (JSONObject) param;
String nodeData = jsonObject.get("nodeData") + "";
String instSnapshot = jsonObject.get("instSnapshot") + "";
String sopId = jsonObject.get("sopId") + "";
String sopName = jsonObject.get("sopName") + "";
String nodeId = jsonObject.get("nodeId") + "";
String nodeName = jsonObject.get("nodeName") + "";
// 组装任务需要的参数
MultiValueMap<String, String> multiValueMap = new LinkedMultiValueMap<>();
for (Object key : jsonObject.keySet()) {
String keyString = (String) key;
......@@ -100,14 +112,6 @@ public class ControllerRopHttpDemo {
return params;
}
public static MultiValueMap<String, String> getSysParamsE() {
MultiValueMap<String, String> params = new LinkedMultiValueMap<String, String>(16);
params.add("app_key", appKey);
params.add("format", "json");
params.add("timestamp", System.currentTimeMillis() + "");
return params;
}
static class RopUriTemplateHandler extends DefaultUriBuilderFactory {
public RopUriTemplateHandler(String baseUriTemplate) {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!