Commit 58bb130b by zhouhaibao

[+]旅程节点多sql更新新增

1 parent ca6c9284
package cn.com.glsx.process.modules.sop.execute.executor; package cn.com.glsx.process.modules.sop.execute.executor;
import java.util.Map; import java.util.Map;
...@@ -25,33 +24,35 @@ import lombok.extern.slf4j.Slf4j; ...@@ -25,33 +24,35 @@ import lombok.extern.slf4j.Slf4j;
@Service @Service
public class SqlExecutor implements SopNodeExecutor { public class SqlExecutor implements SopNodeExecutor {
@Autowired @Autowired
private SopDataSourceService sopDataSourceService; private SopDataSourceService sopDataSourceService;
@Override
public Object execute(SopStruct sop, SopInstNode node, SnapshotStruct executeStruct) throws Exception {
Map<String, Object> resultMap = executeStruct.getResultMap();
try {
// 获取配置参数信息
String nodeContent = node.getNodeContent();
JSONObject paramMap = JSON.parseObject(nodeContent);
@Override String sqlTemplate = paramMap.get("source") + "";
public Object execute(SopStruct sop, SopInstNode node, SnapshotStruct executeStruct) throws Exception { String dataSourceId = paramMap.get("dataSourceId") + "";
Map<String, Object> resultMap = executeStruct.getResultMap();
try {
// 获取配置参数信息
String nodeContent = node.getNodeContent();
JSONObject paramMap = JSON.parseObject(nodeContent);
String sqlTemplate = paramMap.get("source") + ""; // 执行sql插件
String dataSourceId = paramMap.get("dataSourceId") + ""; SopDataSource byId = sopDataSourceService.findByDataSourceId(dataSourceId);
SopBizAdapter mcgBizAdapter = new FlowDataAdapterImpl(byId);
// 执行sql插件 String sql = FreemarkerUtil.processContent(sqlTemplate, executeStruct.toMap());
SopDataSource byId = sopDataSourceService.findByDataSourceId(dataSourceId);
SopBizAdapter mcgBizAdapter = new FlowDataAdapterImpl(byId);
String sql = FreemarkerUtil.processContent(sqlTemplate, executeStruct.toMap()); int i = mcgBizAdapter.executeUpdate(sql);
mcgBizAdapter.executeUpdate(sql); return "更新成功条数" + i;
} catch (Exception e) { } catch (Exception e) {
String message = e.getMessage(); String message = e.getMessage();
resultMap.put(Constants.RES_FAIL_MESSAGE, message); resultMap.put(Constants.RES_FAIL_MESSAGE, message);
resultMap.put(Constants.RES_KEY, Constants.RES_FAIL); resultMap.put(Constants.RES_KEY, Constants.RES_FAIL);
} }
return null; return null;
} }
} }
\ No newline at end of file \ No newline at end of file
...@@ -121,7 +121,13 @@ public abstract class AbstractConnect { ...@@ -121,7 +121,13 @@ public abstract class AbstractConnect {
* @throws SQLException * @throws SQLException
*/ */
public int executeUpdate(String sql, Object... para) throws SQLException { public int executeUpdate(String sql, Object... para) throws SQLException {
return dbConnect.executeUpdate(sql, para); int total=0;
String[] split = sql.split(";");
for (String s : split) {
int i = dbConnect.executeUpdate(s, para);
total=total+i;
}
return total;
} }
public boolean testConnect() { public boolean testConnect() {
......
...@@ -175,7 +175,7 @@ public class DbConnect { ...@@ -175,7 +175,7 @@ public class DbConnect {
* @throws * @throws
*/ */
public int executeUpdate(String sql, Object... para) throws SQLException { public int executeUpdate(String sql, Object... para) throws SQLException {
logger.debug("executeUpdate: {}, para: {}", sql, ToStringBuilder.reflectionToString(para)); logger.info("executeUpdate: {}, para: {}", sql, ToStringBuilder.reflectionToString(para));
QueryRunner runner = new QueryRunner(); QueryRunner runner = new QueryRunner();
Connection conn = null; Connection conn = null;
int count = 0; int count = 0;
......
...@@ -39,115 +39,115 @@ import cn.com.glsx.process.modules.sop.java.example.ControllerHttpDemo; ...@@ -39,115 +39,115 @@ import cn.com.glsx.process.modules.sop.java.example.ControllerHttpDemo;
@SpringBootTest(classes = Application.class) @SpringBootTest(classes = Application.class)
public class TestApplication { public class TestApplication {
@Autowired @Autowired
private UserDemoService userDemoService; private UserDemoService userDemoService;
@Autowired @Autowired
private SopDataSourceService sopDataSourceService; private SopDataSourceService sopDataSourceService;
@Autowired @Autowired
private SopInstNodeExecuteJobHandler sopInstNodeExecuteJobHandler; private SopInstNodeExecuteJobHandler sopInstNodeExecuteJobHandler;
@Autowired @Autowired
private SopInstLinkService sopInstLinkService; private SopInstLinkService sopInstLinkService;
@Test @Test
public void test() throws SQLException { public void test() throws SQLException {
SopDataSource byId = sopDataSourceService.findByDataSourceId("SOP_CDP"); SopDataSource byId = sopDataSourceService.findByDataSourceId("SOP_CDP");
SopBizAdapter mcgBizAdapter = new FlowDataAdapterImpl(byId); SopBizAdapter mcgBizAdapter = new FlowDataAdapterImpl(byId);
List<Map<String, Object>> maps = mcgBizAdapter.tableQuery("SELECT c.org_id, c.one_id, c.customer_name, c.customer_phone, j.sop_journey_id, j.sop_journey_enter_time, j.sop_journey_stage, j.sop_journey_stage_enter_time FROM `cdp_customer_sop_journey` j INNER JOIN cdp_customer c ON j.one_id = c.one_id AND j.org_id = c.org_id WHERE j.sop_journey_id='xblc'"); List<Map<String, Object>> maps = mcgBizAdapter.tableQuery("SELECT c.org_id, c.one_id, c.customer_name, c.customer_phone, j.sop_journey_id, j.sop_journey_enter_time, j.sop_journey_stage, j.sop_journey_stage_enter_time FROM `cdp_customer_sop_journey` j INNER JOIN cdp_customer c ON j.one_id = c.one_id AND j.org_id = c.org_id WHERE j.sop_journey_id='xblc'");
System.out.println(maps); System.out.println(maps);
} }
@Test @Test
public void testupdate() throws SQLException { public void testupdate() throws SQLException {
SopDataSource byId = sopDataSourceService.getById(1); SopDataSource byId = sopDataSourceService.findByDataSourceId("SOP_CDP");
SopBizAdapter mcgBizAdapter = new FlowDataAdapterImpl(byId); SopBizAdapter mcgBizAdapter = new FlowDataAdapterImpl(byId);
mcgBizAdapter.executeUpdate("SELECT * FROM aa_bb"); int i = mcgBizAdapter.executeUpdate("update cdp_customer_sop_journey t1,(select t1.one_id,t1.org_id from cdp_customer t1 LEFT JOIN cdp_customer_car_relation t2 on t1.one_id=t2.one_id left join cdp_car t3 on t3.car_id=t2.car_id\n" + "where to_days(t3.arrival_date) = to_days(now()) ) t2 set t1.sop_journey_stage='保费报价',t1.sop_journey_stage_enter_time=now() where t1.one_id=t2.one_id and t1.org_id=t2.org_id;\n" + "update cdp_customer_sop_journey set sop_journey_stage='战败客户',sop_journey_stage_enter_time=now() where DATEDIFF(CURDATE(), sop_journey_enter_time) > 45 and sop_journey_stage!='成功续保';\n" + "update cdp_customer_sop_journey set sop_journey_stage='意向客户',sop_journey_stage_enter_time=now() where one_id in (SELECT one_id FROM cdp_customer_event where event_type='ORDERED' and extra->'$.orderStatus'=2 and extra->'$.payStatus'=2 and extra->'$.afterSaleStatus' is null);\n" + "update cdp_customer_sop_journey set sop_journey_stage='意向客户',sop_journey_stage_enter_time=now() where one_id in (SELECT one_id FROM cdp_customer_event where event_type='RECALL_AI_CALL' and extra->'$.taskResult[0].resultValue'='A');");
} System.out.println("更新成功的行数" + i);
}
@Test
public void testjava() throws Exception { @Test
DynamicEngine de = DynamicEngine.getInstance(); public void testjava() throws Exception {
String source = "import com.alibaba.fastjson.JSON;\n" + "\n" + "public class Controller {\n" + "\n" DynamicEngine de = DynamicEngine.getInstance();
+ " public JSON execute(JSON param) {\n" + " System.out.println(\"测试java\");\n" + " return param;\n" + " }\n" String source = "import com.alibaba.fastjson.JSON;\n" + "\n" + "public class Controller {\n" + "\n" + " public JSON execute(JSON param) {\n" + " System.out.println(\"测试java\");\n" + " return param;\n" + " }\n" + "}\n";
+ "}\n"; JSONObject jsonObject = new JSONObject();
JSONObject jsonObject = new JSONObject(); jsonObject.put("id", 22);
jsonObject.put("id", 22); Object instance = de.execute("Controller", source, "execute", new Class[]{JSON.class}, new Object[]{jsonObject});
Object instance = de.execute("Controller", source, "execute", new Class[] { JSON.class }, new Object[] { jsonObject }); System.out.println(JSON.toJSONString(instance));
System.out.println(JSON.toJSONString(instance)); }
}
@Test
@Test public void testredis() throws InterruptedException {
public void testredis() throws InterruptedException {
// 设置并发数量
// 设置并发数量 int count = 1;
int count = 1; // 线程池准备
// 线程池准备 CyclicBarrier cyclicBarrier = new CyclicBarrier(count);
CyclicBarrier cyclicBarrier = new CyclicBarrier(count); ExecutorService executorService = Executors.newFixedThreadPool(count);
ExecutorService executorService = Executors.newFixedThreadPool(count); // 开始时间
// 开始时间 long now = System.currentTimeMillis();
long now = System.currentTimeMillis(); for (int i = 0; i < count; i++) {
for (int i = 0; i < count; i++) { executorService.execute(new Task(cyclicBarrier, i, userDemoService));
executorService.execute(new Task(cyclicBarrier, i, userDemoService)); }
} executorService.shutdown();
executorService.shutdown(); while (!executorService.isTerminated()) {
while (!executorService.isTerminated()) { try {
try { Thread.sleep(10);
Thread.sleep(10); } catch (InterruptedException e) {
} catch (InterruptedException e) { e.printStackTrace();
e.printStackTrace(); }
} }
} }
}
public class Task implements Runnable {
public class Task implements Runnable {
private CyclicBarrier cyclicBarrier;
private CyclicBarrier cyclicBarrier; private int count;
private int count;
private UserDemoService userDemoService;
private UserDemoService userDemoService;
public Task(CyclicBarrier cyclicBarrier, int count, UserDemoService userDemoService) {
public Task(CyclicBarrier cyclicBarrier, int count, UserDemoService userDemoService) { this.cyclicBarrier = cyclicBarrier;
this.cyclicBarrier = cyclicBarrier; this.count = count;
this.count = count; this.userDemoService = userDemoService;
this.userDemoService = userDemoService; }
}
@Override
@Override public void run() {
public void run() { try {
try { cyclicBarrier.await();
cyclicBarrier.await(); User user = new User();
User user = new User(); user.setAccount("123456");
user.setAccount("123456"); userDemoService.testRedis(user);
userDemoService.testRedis(user); } catch (Exception e) {
} catch (Exception e) { System.out.println("出现超时的线程" + count);
System.out.println("出现超时的线程" + count); e.printStackTrace();
e.printStackTrace(); }
} }
} }
}
@Test
@Test public void sopInstNodeExecuteJobHandler() {
public void sopInstNodeExecuteJobHandler() { SopInstNode sopInstNode = new SopInstNode();
SopInstNode sopInstNode = new SopInstNode(); sopInstNode.setNodeType("Java");
sopInstNode.setNodeType("Java"); SopStruct sopStruct = new SopStruct();
SopStruct sopStruct = new SopStruct(); sopInstNodeExecuteJobHandler.execute(sopStruct, sopInstNode);
sopInstNodeExecuteJobHandler.execute(sopStruct, sopInstNode); }
}
@Test
@Test public void testJava() {
public void testJava() { JSONObject jsonObject = new JSONObject();
JSONObject jsonObject = new JSONObject(); jsonObject.put("merchantNo", "44210895");
jsonObject.put("merchantNo", "44210895"); JSON execute = ControllerHttpDemo.execute(jsonObject);
JSON execute = ControllerHttpDemo.execute(jsonObject); System.out.println(execute);
System.out.println(execute); }
}
@Test @Test
public void findByInstId() { public void findByInstId() {
List<SopInstNode> xblc7 = sopInstLinkService.findByInstId("xblc7"); List<SopInstNode> xblc7 = sopInstLinkService.findByInstId("xblc7");
String listString = JSON.toJSONString(xblc7, SerializerFeature.DisableCircularReferenceDetect); String listString = JSON.toJSONString(xblc7, SerializerFeature.DisableCircularReferenceDetect);
System.out.println(listString); System.out.println(listString);
} }
} }
\ 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!