Commit c638a358 by zhouhaibao

[+]执行器处理

1 parent 677699eb
package cn.com.glsx.process.modules.sop;
import lombok.Data;
import java.util.Date;
@Data
public class CustomerInfo {
private String orgId;
private String oneId;
private String customerName;
private String customerPhone;
private String sopJourneyId;
private Date sopJourneyEnterTime;
private String sop_journey_stage;
private Date sopJourneyStageEnterTime;
private String followStaffUuid;
private String messageContent;
private String messageId;
private String talkId;
private String vin;
}
package cn.com.glsx.process.modules.sop;
import cn.com.glsx.process.modules.entity.SopInst;
import cn.com.glsx.process.modules.entity.SopInstNode;
import lombok.Data;
import java.util.Map;
@Data
public class SopExecutorResult {
private SopInst sopInst;
private SopInstNode sopInstNode;
private Map<String, Object> resultData;
public SopExecutorResult(SopInst sopInst, SopInstNode sopInstNode, Map<String, Object> resultData) {
this.sopInst = sopInst;
this.sopInstNode = sopInstNode;
this.resultData = resultData;
}
public SopExecutorResult() {
}
}
...@@ -3,12 +3,18 @@ package cn.com.glsx.process.modules.sop; ...@@ -3,12 +3,18 @@ package cn.com.glsx.process.modules.sop;
import java.io.IOException; import java.io.IOException;
import java.security.GeneralSecurityException; import java.security.GeneralSecurityException;
import java.security.MessageDigest; import java.security.MessageDigest;
import java.util.ArrayList; import java.text.DateFormat;
import java.util.Collections; import java.text.ParseException;
import java.util.Iterator; import java.text.SimpleDateFormat;
import java.util.List; import java.util.*;
import java.util.Map; import java.util.stream.Collectors;
import cn.com.glsx.process.modules.entity.SopInstNode;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap; import org.springframework.util.MultiValueMap;
...@@ -41,7 +47,88 @@ public class SopHelper { ...@@ -41,7 +47,88 @@ public class SopHelper {
DistributedLockUtils.unlock(key); DistributedLockUtils.unlock(key);
} }
public static boolean diffDay(Date now, Integer days) {
DateFormat dft = new SimpleDateFormat("yyyy-MM-dd");
try {
Date star = dft.parse("2020-02-03");//开始时间
Date endDay = dft.parse("2025-03-02");//结束时间
Long starTime = star.getTime();
Long endTime = endDay.getTime();
return (endTime - starTime) / 24 / 60 / 60 / 1000 == days;
} catch (ParseException e) {
throw new RuntimeException(e);
}
}
/**
* 获取构建的信息
*
* @param param 入参
* @return
*/
public static SopExecutorResult getExcustorParam(JSON param) {
JSONObject jsonObject = (JSONObject) param;
SopInst sopInst = (SopInst) jsonObject.get("sopInst");
SopInstNode sopInstNode = (SopInstNode) jsonObject.get("sopInstNode");
Map<String, Object> resultData = (Map<String, Object>) jsonObject.get("instSnapshot");
return new SopExecutorResult(sopInst, sopInstNode, resultData);
}
/**
* 获取匹配上的信息
*
* @param sopInstNode 节点信息
* @param resultData 上个节点返回的信息
* @return
*/
public static List<CustomerInfo> getMeetWithCustomer(SopInstNode sopInstNode, Map<String, Object> resultData) {
String nodeParam = sopInstNode.getNodeParam();
String nodeKey = sopInstNode.getNodeKey();
String[] split = nodeKey.split("\\|");
// 拿到过滤出阶段的客户
List<CustomerInfo> customerInfoList = JSON.parseArray(JSON.toJSONString(resultData.get(split[0])), CustomerInfo.class);
String day = SopHelper.getValueFromJsonString(nodeParam, "day");
if (org.apache.commons.lang3.StringUtils.isEmpty(day)) {
return null;
}
if (CollectionUtils.isNotEmpty(customerInfoList)) {
return customerInfoList;
/*return customerInfoList.stream().filter(index -> SopHelper.diffDay(index.getSopJourneyStageEnterTime(), Integer.getInteger(day))).collect(Collectors.toList());*/
}
return null;
}
public static String getValueFromJsonString(String jsonString, String objectName, String fieldName) {
try {
ObjectMapper objectMapper = new ObjectMapper();
JsonNode rootNode = objectMapper.readTree(jsonString);
JsonNode objectNode = rootNode.get(objectName);
JsonNode fieldNode = objectNode.get(fieldName);
return fieldNode.asText();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
public static String getValueFromJsonString(String jsonString, String fieldName) {
try {
ObjectMapper objectMapper = new ObjectMapper();
JsonNode rootNode = objectMapper.readTree(jsonString);
JsonNode fieldNode = rootNode.get(fieldName);
if (fieldNode != null) {
return fieldNode.asText();
} else {
return null;
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
public static <T> T post(MultiValueMap<String, String> paramsMap, Class<T> responseType, String baseurl, String method) throws Exception { public static <T> T post(MultiValueMap<String, String> paramsMap, Class<T> responseType, String baseurl, String method) throws Exception {
......
...@@ -33,26 +33,20 @@ public class JavaExecutor implements SopNodeExecutor { ...@@ -33,26 +33,20 @@ public class JavaExecutor implements SopNodeExecutor {
// 获取实例快照,传给处理器 // 获取实例快照,传给处理器
SopInst inst = sop.getInst(); SopInst inst = sop.getInst();
String instSnapshot = inst.getInstSnapshot();
JSONObject jsonObject = new JSONObject(); JSONObject jsonObject = new JSONObject();
// 实例信息
jsonObject.put("sopInst", inst);
// 节点信息 // 节点信息
jsonObject.put("sopId", inst.getInstId()); jsonObject.put("sopInstNode", node);
jsonObject.put("sopName", inst.getInstName());
jsonObject.put("nodeId", node.getNodeId());
jsonObject.put("nodeName", node.getNodeName());
// 节点入参
jsonObject.put("nodeData", node.getNodeParam());
// 实例快照 // 实例快照
jsonObject.put("instSnapshot", instSnapshot); jsonObject.put("instSnapshot", executeStruct.getResultMap());
Object instance = de.execute("Controller", javacode, "execute", new Class[] { JSON.class }, new Object[] { jsonObject }); Object instance = de.execute("Controller", javacode, "execute", new Class[] { JSON.class }, new Object[] { jsonObject });
// 处理返回结果 // 处理返回结果
return instance; return instance;
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace();
} }
return null; return null;
......
package cn.com.glsx.process.modules.sop.java.example;
import cn.com.glsx.process.modules.entity.SopInst;
import cn.com.glsx.process.modules.entity.SopInstNode;
import cn.com.glsx.process.modules.sop.CustomerInfo;
import cn.com.glsx.process.modules.sop.SopExecutorResult;
import cn.com.glsx.process.modules.sop.SopHelper;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import java.util.List;
import java.util.Map;
/**
* java执行器使用demo,rop请求,类名Controller,方法名execute
* 1.下发门店助手任务
*/
public class ControllerDisTasksDemo {
private final static String baseurl = "http://scrm.dev.glsx.com.cn/rop-scrm-stoassistant/router";
private final static String method = "scrm.api.sop.marketing.task.customer";
public static JSON execute(JSON param) {
// 将JSON字符串转换为Map
// 将Map中的数据放入MultiValueMap中
Object post = null;
MultiValueMap<String, String> multiValueMap = new LinkedMultiValueMap<>();
SopExecutorResult excustorParam = SopHelper.getExcustorParam(param);
Map<String, Object> resultData = excustorParam.getResultData();
SopInst sopInst = excustorParam.getSopInst();
SopInstNode sopInstNode = excustorParam.getSopInstNode();
String nodeParam = sopInstNode.getNodeParam();
List<CustomerInfo> customerInfoList = SopHelper.getMeetWithCustomer(sopInstNode, resultData);
// 营销的客户存在执行任务下发
if (CollectionUtils.isNotEmpty(customerInfoList)) {
String instSnapshot = sopInst.getInstSnapshot();
multiValueMap.add("requestList[0].activityId", SopHelper.getValueFromJsonString(instSnapshot, "activityId"));
multiValueMap.add("requestList[0].nodeId", sopInstNode.getNodeId() + "");
multiValueMap.add("requestList[0].nodeName", sopInstNode.getNodeName());
multiValueMap.add("requestList[0].stageId", SopHelper.getValueFromJsonString(nodeParam, "stage"));
multiValueMap.add("requestList[0].stageName", SopHelper.getValueFromJsonString(nodeParam, "stage"));
multiValueMap.add("requestList[0].taskId", sopInst.getInstId());
multiValueMap.add("requestList[0].taskName", sopInst.getInstName());
multiValueMap.add("requestList[0].taskType", SopHelper.getValueFromJsonString(nodeParam, "taskType"));
for (int i = 0; i < customerInfoList.size(); i++) {
CustomerInfo customerInfo = customerInfoList.get(i);
multiValueMap.add("requestList[" + i + "].customerId", customerInfo.getOneId());
multiValueMap.add("requestList[" + i + "].followStaffUuid", customerInfo.getFollowStaffUuid());
multiValueMap.add("requestList[" + i + "].messageContent", customerInfo.getMessageContent());
multiValueMap.add("requestList[" + i + "].messageId", customerInfo.getMessageId());
multiValueMap.add("requestList[" + i + "].talkId", customerInfo.getTalkId());
}
try {
post = SopHelper.post(multiValueMap, Object.class, baseurl, method);
} catch (Exception e) {
throw new RuntimeException(e);
}
return (JSONObject) JSONObject.toJSON(post);
}
return null;
}
}
\ No newline at end of file \ No newline at end of file
package cn.com.glsx.process.modules.sop.java.example;
import cn.com.glsx.process.modules.entity.SopInst;
import cn.com.glsx.process.modules.entity.SopInstNode;
import cn.com.glsx.process.modules.sop.CustomerInfo;
import cn.com.glsx.process.modules.sop.SopExecutorResult;
import cn.com.glsx.process.modules.sop.SopHelper;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* java执行器使用demo,rop请求,类名Controller,方法名execute
* 查询到保日期
*/
public class ControllerFoundInsDemo {
private final static String baseurl = "http://scrm.dev.glsx.com.cn/rop-scrm-stoassistant/router";
private final static String method = "marketing.api.supermarket.customers.page";
public static JSON execute(JSON param) {
// 将JSON字符串转换为Map
// 将Map中的数据放入MultiValueMap中
Object post = null;
MultiValueMap<String, String> multiValueMap = new LinkedMultiValueMap<>();
SopExecutorResult excustorParam = SopHelper.getExcustorParam(param);
Map<String, Object> resultData = excustorParam.getResultData();
SopInstNode sopInstNode = excustorParam.getSopInstNode();
List<CustomerInfo> customerInfoList = SopHelper.getMeetWithCustomer(sopInstNode, resultData);
if (CollectionUtils.isNotEmpty(customerInfoList)) {
List<String> collect = customerInfoList.stream().filter(index -> StringUtils.isNotEmpty(index.getVin())).map(CustomerInfo::getVin).collect(Collectors.toList());
try {
multiValueMap.put("vins", collect);
post = SopHelper.post(multiValueMap, Object.class, baseurl, method);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
return (JSONObject) JSONObject.toJSON(post);
}
}
\ No newline at end of file \ No newline at end of file
...@@ -7,7 +7,8 @@ import com.alibaba.fastjson.JSONObject; ...@@ -7,7 +7,8 @@ import com.alibaba.fastjson.JSONObject;
/** /**
* java执行器使用demo,http请求,类名Controller,方法名execute * java执行器使用demo,http请求,类名Controller,方法名execute
* TODO 1.推送客户行为数据 * 隐藏任务跑sql
*
*/ */
public class ControllerHttpDemo { public class ControllerHttpDemo {
......
package cn.com.glsx.process.modules.sop.java.example;
import cn.com.glsx.process.modules.sop.SopHelper;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
/**
* java执行器使用demo,rop请求,类名Controller,方法名execute
* TODO 1.下发门店助手任务
* TODO 2.查询到保日期
*/
public class ControllerRopHttpDemo {
private final static String baseurl = "http://rop-merchant.test.glsx.com.cn/rop-merchants/router";
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") + "";
// TODO 组装任务需要的参数
JSONObject instSnapshotData = JSONObject.parseObject(instSnapshot);
//
MultiValueMap<String, String> multiValueMap = new LinkedMultiValueMap<>();
for (Object key : jsonObject.keySet()) {
String keyString = (String) key;
String value = (String) jsonObject.get(key);
multiValueMap.add(keyString, value);
}
try {
post = SopHelper.post(multiValueMap, Object.class, baseurl, method);
} catch (Exception e) {
throw new RuntimeException(e);
}
return (JSONObject) JSONObject.toJSON(post);
}
}
\ No newline at end of file \ No newline at end of file
package cn.com.glsx.process.modules.sop.java.example;
import cn.com.glsx.process.modules.entity.SopInstNode;
import cn.com.glsx.process.modules.sop.CustomerInfo;
import cn.com.glsx.process.modules.sop.SopExecutorResult;
import cn.com.glsx.process.modules.sop.SopHelper;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.collections.CollectionUtils;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* java执行器使用demo,http请求,类名Controller,方法名execute
* 筛选客户
*/
public class ControllerScreenPersonDemo {
public static JSON execute(JSON param) {
SopExecutorResult excustorParam = SopHelper.getExcustorParam(param);
SopInstNode sopInstNode = excustorParam.getSopInstNode();
String nodeParam = sopInstNode.getNodeParam();
String stage = SopHelper.getValueFromJsonString(nodeParam, "stage");
Map<String, Object> resultData = excustorParam.getResultData();
List<CustomerInfo> customerInfoList = JSON.parseArray(JSON.toJSONString(resultData.get("users")), CustomerInfo.class);
if (CollectionUtils.isNotEmpty(customerInfoList)) {
List<CustomerInfo> collect = customerInfoList.stream().filter(index -> stage.equals(index.getSop_journey_stage())).collect(Collectors.toList());
return (JSONArray) JSONObject.toJSON(collect);
}
return null;
}
}
\ No newline at end of file \ No newline at end of file
package cn.com.glsx.test;
import cn.com.glsx.Application;
import cn.com.glsx.process.job.xxljob.impl.SopInstNodeExecuteJobHandler;
import cn.com.glsx.process.modules.entity.SopDataSource;
import cn.com.glsx.process.modules.entity.SopInst;
import cn.com.glsx.process.modules.entity.SopInstNode;
import cn.com.glsx.process.modules.entity.User;
import cn.com.glsx.process.modules.model.SopStruct;
import cn.com.glsx.process.modules.service.SopDataSourceService;
import cn.com.glsx.process.modules.service.SopService;
import cn.com.glsx.process.modules.service.UserDemoService;
import cn.com.glsx.process.modules.sop.CustomerInfo;
import cn.com.glsx.process.modules.sop.execute.plugin.dbconn.FlowDataAdapterImpl;
import cn.com.glsx.process.modules.sop.execute.plugin.dbconn.SopBizAdapter;
import cn.com.glsx.process.modules.sop.execute.plugin.java.DynamicEngine;
import cn.com.glsx.process.modules.sop.java.example.ControllerDisTasksDemo;
import cn.com.glsx.process.modules.sop.java.example.ControllerHttpDemo;
import cn.com.glsx.process.modules.sop.java.example.ControllerScreenPersonDemo;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import javax.annotation.Resource;
import java.sql.SQLException;
import java.util.*;
import java.util.concurrent.CyclicBarrier;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
/**
* 测试spring cloud 服务调用方式
*/
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = Application.class)
public class JavaNodeTestApplication {
@Resource
private SopService sopService;
@Test
public void testJava() {
Map<String, Object> resultData = new HashMap<>();
CustomerInfo customerInfo = new CustomerInfo();
customerInfo.setOneId("123456");
customerInfo.setCustomerPhone("13476670746");
customerInfo.setOrgId("123456");
customerInfo.setVin("ceshi");
customerInfo.setMessageId("ceshi");
customerInfo.setMessageContent("ceshi");
customerInfo.setSopJourneyId("xblc7");
customerInfo.setSopJourneyEnterTime(new Date());
customerInfo.setCustomerPhone("13476670746");
customerInfo.setSop_journey_stage("潜客");
customerInfo.setSopJourneyStageEnterTime(new Date());
resultData.put("users", Arrays.asList(customerInfo));
SopStruct sopStruct = sopService.loadSop("xblc7");
SopInstNode sopInstNode = sopStruct.getInstNodeMap().get(2);
JSONObject jsonObject = new JSONObject();
jsonObject.put("sopInst", sopStruct.getInst());
jsonObject.put("sopInstNode", sopInstNode);
jsonObject.put("instSnapshot", resultData);
JSON execute = ControllerScreenPersonDemo.execute(jsonObject);
System.out.println(execute);
}
@Test
public void ControllerDisTasksDemotestJava() {
Map<String, Object> resultData = new HashMap<>();
CustomerInfo customerInfo = new CustomerInfo();
customerInfo.setOneId("123456");
customerInfo.setCustomerPhone("13476670746");
customerInfo.setOrgId("123456");
customerInfo.setVin("ceshi");
customerInfo.setMessageId("ceshi");
customerInfo.setMessageContent("ceshi");
customerInfo.setSopJourneyId("xblc7");
customerInfo.setSopJourneyEnterTime(new Date());
customerInfo.setCustomerPhone("13476670746");
customerInfo.setSop_journey_stage("潜客");
customerInfo.setSopJourneyStageEnterTime(new Date());
resultData.put("user1", Arrays.asList(customerInfo));
SopStruct sopStruct = sopService.loadSop("xblc7");
SopInstNode sopInstNode = sopStruct.getInstNodeMap().get(3);
JSONObject jsonObject = new JSONObject();
jsonObject.put("sopInst", sopStruct.getInst());
jsonObject.put("sopInstNode", sopInstNode);
jsonObject.put("instSnapshot", resultData);
JSON execute = ControllerDisTasksDemo.execute(jsonObject);
System.out.println(execute);
}
String aa="\timport cn.com.glsx.process.modules.entity.SopInstNode;\n" + "import cn.com.glsx.process.modules.sop.CustomerInfo;\n" + "import cn.com.glsx.process.modules.sop.SopExecutorResult;\n" + "import cn.com.glsx.process.modules.sop.SopHelper;\n" + "import com.alibaba.fastjson.JSON;\n" + "import com.alibaba.fastjson.JSONArray;\n" + "import com.alibaba.fastjson.JSONObject;\n" + "import org.apache.commons.collections.CollectionUtils;\n" + "\n" + "import java.util.List;\n" + "import java.util.Map;\n" + "import java.util.stream.Collectors;\n" + "\n" + "/**\n" + " * java执行器使用demo,http请求,类名Controller,方法名execute\n" + " * 筛选客户\n" + " */\n" + "public class ControllerScreenPersonDemo {\n" + "\n" + "\n" + " public static JSON execute(JSON param) {\n" + "\n" + " SopExecutorResult excustorParam = SopHelper.getExcustorParam(param);\n" + " SopInstNode sopInstNode = excustorParam.getSopInstNode();\n" + " String nodeParam = sopInstNode.getNodeParam();\n" + " String stage = SopHelper.getValueFromJsonString(nodeParam, \"stage\");\n" + "\n" + " Map<String, Object> resultData = excustorParam.getResultData();\n" + "\n" + " List<CustomerInfo> customerInfoList = JSON.parseArray(JSON.toJSONString(resultData.get(\"users\")), CustomerInfo.class);\n" + " if (CollectionUtils.isNotEmpty(customerInfoList)) {\n" + " List<CustomerInfo> collect = customerInfoList.stream().filter(index -> stage.equals(index.getSop_journey_stage())).collect(Collectors.toList());\n" + " return (JSONArray) JSONObject.toJSON(collect);\n" + " }\n" + " return null;\n" + " }\n" + "}";
}
\ No newline at end of file \ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!