Commit b68032e5 by zhouhaibao

[+]流程节点处理

1 parent d5d03470
...@@ -32,4 +32,6 @@ public class CustomerInfo { ...@@ -32,4 +32,6 @@ public class CustomerInfo {
private String talkId; private String talkId;
private String vin; private String vin;
private String arrivalDate;
} }
package cn.com.glsx.process.modules.sop; package cn.com.glsx.process.modules.sop;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.Field;
import java.security.GeneralSecurityException; import java.security.GeneralSecurityException;
import java.security.MessageDigest; import java.security.MessageDigest;
import java.text.DateFormat; import java.text.DateFormat;
...@@ -112,6 +113,26 @@ public class SopHelper { ...@@ -112,6 +113,26 @@ public class SopHelper {
return null; return null;
} }
public static Map<String, Object> objectToMap(Object obj) {
Map<String, Object> map = new HashMap<>();
Class<?> clazz = obj.getClass();
Field[] fields = clazz.getDeclaredFields();
for (Field field : fields) {
field.setAccessible(true);
String fieldName = field.getName();
Object fieldValue = null;
try {
fieldValue = field.get(obj);
} catch (IllegalAccessException e) {
e.printStackTrace();
}
map.put(fieldName, fieldValue);
}
return map;
}
public static String getValueFromJsonString(String jsonString, String objectName, String fieldName) { public static String getValueFromJsonString(String jsonString, String objectName, String fieldName) {
try { try {
ObjectMapper objectMapper = new ObjectMapper(); ObjectMapper objectMapper = new ObjectMapper();
......
...@@ -56,15 +56,17 @@ public class ControllerDisTasksDemo { ...@@ -56,15 +56,17 @@ public class ControllerDisTasksDemo {
for (int i = 0; i < customerInfoList.size(); i++) { for (int i = 0; i < customerInfoList.size(); i++) {
CustomerInfo customerInfo = customerInfoList.get(i); CustomerInfo customerInfo = customerInfoList.get(i);
multiValueMap.add("requestList[" + i + "].customerId", customerInfo.getOneId()); multiValueMap.add("requestList[0].customerList[" + i + "].customerId", customerInfo.getOneId());
multiValueMap.add("requestList[" + i + "].followStaffUuid", customerInfo.getFollowStaffUuid()); multiValueMap.add("requestList[0].customerList[" + i + "].followStaffUuid", customerInfo.getFollowStaffUuid());
multiValueMap.add("requestList[" + i + "].messageContent", customerInfo.getMessageContent()); multiValueMap.add("requestList[0].customerList[" + i + "].messageContent", customerInfo.getMessageContent());
multiValueMap.add("requestList[" + i + "].messageId", customerInfo.getMessageId()); multiValueMap.add("requestList[0].customerList[" + i + "].messageId", customerInfo.getMessageId());
multiValueMap.add("requestList[" + i + "].talkId", customerInfo.getTalkId()); multiValueMap.add("requestList[0].customerList[" + i + "].talkId", customerInfo.getTalkId());
} }
try { try {
System.out.println("入参" + JSONObject.toJSONString(multiValueMap));
post = SopHelper.post(multiValueMap, Object.class, baseurl, method); post = SopHelper.post(multiValueMap, Object.class, baseurl, method);
System.out.println("返回" + JSONObject.toJSONString(post));
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
......
...@@ -10,9 +10,12 @@ import com.alibaba.fastjson.JSONArray; ...@@ -10,9 +10,12 @@ import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.apache.commons.lang3.time.DateUtils;
import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap; import org.springframework.util.MultiValueMap;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
...@@ -24,15 +27,15 @@ import java.util.stream.Collectors; ...@@ -24,15 +27,15 @@ import java.util.stream.Collectors;
*/ */
public class ControllerFoundInsDemo { public class ControllerFoundInsDemo {
private final static String baseurl = "http://scrm.dev.glsx.com.cn/rop-scrm-stoassistant/router"; private final static String baseurl = "http://scrm.dev.glsx.com.cn/rop-scrm-marketing/router";
private final static String method = "marketing.api.supermarket.customers.page"; private final static String method = "marketing.api.supermarket.renewal.queryByVins";
public static JSON execute(JSON param) { public static JSON execute(JSON param) {
// 将JSON字符串转换为Map // 将JSON字符串转换为Map
// 将Map中的数据放入MultiValueMap中 // 将Map中的数据放入MultiValueMap中
Object post = null; List<CustomerInfo> result = new ArrayList<>();
MultiValueMap<String, String> multiValueMap = new LinkedMultiValueMap<>(); MultiValueMap<String, String> multiValueMap = new LinkedMultiValueMap<>();
SopExecutorResult excustorParam = SopHelper.getExcustorParam(param); SopExecutorResult excustorParam = SopHelper.getExcustorParam(param);
Map<String, Object> resultData = excustorParam.getResultData(); Map<String, Object> resultData = excustorParam.getResultData();
...@@ -42,11 +45,24 @@ public class ControllerFoundInsDemo { ...@@ -42,11 +45,24 @@ public class ControllerFoundInsDemo {
List<String> collect = customerInfoList.stream().filter(index -> StringUtils.isNotEmpty(index.getVin())).map(CustomerInfo::getVin).collect(Collectors.toList()); List<String> collect = customerInfoList.stream().filter(index -> StringUtils.isNotEmpty(index.getVin())).map(CustomerInfo::getVin).collect(Collectors.toList());
try { try {
multiValueMap.put("vins", collect); multiValueMap.put("vins", collect);
post = SopHelper.post(multiValueMap, Object.class, baseurl, method); Object post = SopHelper.post(multiValueMap, Object.class, baseurl, method);
JSONObject json = (JSONObject) JSONObject.toJSON(post);
Object data = json.get("data");
Map<String, Object> stringObjectMap = (Map<String, Object>) (data);
if (!stringObjectMap.isEmpty()) {
for (String key : stringObjectMap.keySet()) {
String s = stringObjectMap.get(key) + "";
CustomerInfo customerInfo = new CustomerInfo();
customerInfo.setVin(key);
customerInfo.setArrivalDate(DateFormatUtils.formatUTC(Long.parseLong(s), "yyyy-mm-dd mm:ss"));
result.add(customerInfo);
}
}
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
} }
return (JSONObject) JSONObject.toJSON(post);
return JSONArray.parseArray(JSONObject.toJSONString(result));
} }
} }
\ No newline at end of file \ No newline at end of file
package cn.com.glsx.test; package cn.com.glsx.test;
import cn.com.glsx.Application; 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.SopInstNode;
import cn.com.glsx.process.modules.entity.User;
import cn.com.glsx.process.modules.model.SopStruct; 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.SopService;
import cn.com.glsx.process.modules.service.UserDemoService;
import cn.com.glsx.process.modules.sop.CustomerInfo; 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.ControllerDisTasksDemo;
import cn.com.glsx.process.modules.sop.java.example.ControllerHttpDemo; import cn.com.glsx.process.modules.sop.java.example.ControllerFoundInsDemo;
import cn.com.glsx.process.modules.sop.java.example.ControllerScreenPersonDemo; import cn.com.glsx.process.modules.sop.java.example.ControllerScreenPersonDemo;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.glsx.plat.common.utils.DateUtils;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.sql.SQLException; import java.util.Arrays;
import java.util.*; import java.util.Date;
import java.util.concurrent.CyclicBarrier; import java.util.HashMap;
import java.util.concurrent.ExecutorService; import java.util.Map;
import java.util.concurrent.Executors;
/** /**
* 测试spring cloud 服务调用方式 * 测试spring cloud 服务调用方式
...@@ -76,13 +66,13 @@ public class JavaNodeTestApplication { ...@@ -76,13 +66,13 @@ public class JavaNodeTestApplication {
customerInfo.setCustomerPhone("13476670746"); customerInfo.setCustomerPhone("13476670746");
customerInfo.setOrgId("123456"); customerInfo.setOrgId("123456");
customerInfo.setVin("ceshi"); customerInfo.setVin("ceshi");
customerInfo.setMessageId("ceshi"); customerInfo.setMessageId("1");
customerInfo.setMessageContent("ceshi"); customerInfo.setMessageContent("ceshi");
customerInfo.setSopJourneyId("xblc7"); customerInfo.setSopJourneyId("xblc7");
customerInfo.setSopJourneyEnterTime(new Date()); customerInfo.setSopJourneyEnterTime(new Date());
customerInfo.setCustomerPhone("13476670746"); customerInfo.setCustomerPhone("13476670746");
customerInfo.setSop_journey_stage("潜客"); customerInfo.setSop_journey_stage("潜客");
customerInfo.setSopJourneyStageEnterTime(new Date()); customerInfo.setSopJourneyStageEnterTime(DateUtils.parse("2023-09-22"));
resultData.put("user1", Arrays.asList(customerInfo)); resultData.put("user1", Arrays.asList(customerInfo));
SopStruct sopStruct = sopService.loadSop("xblc7"); SopStruct sopStruct = sopService.loadSop("xblc7");
SopInstNode sopInstNode = sopStruct.getInstNodeMap().get(3); SopInstNode sopInstNode = sopStruct.getInstNodeMap().get(3);
...@@ -94,5 +84,32 @@ public class JavaNodeTestApplication { ...@@ -94,5 +84,32 @@ public class JavaNodeTestApplication {
System.out.println(execute); 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" + "}";
@Test
public void ControllerFoundInsDemo() {
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(DateUtils.parse("2023-09-22"));
customerInfo.setVin("WAURFCF24MN013761");
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 = ControllerFoundInsDemo.execute(jsonObject);
System.out.println(execute);
}
} }
\ 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!