Commit 58bb130b by zhouhaibao

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

1 parent ca6c9284
package cn.com.glsx.process.modules.sop.execute.executor;
import java.util.Map;
......@@ -25,33 +24,35 @@ import lombok.extern.slf4j.Slf4j;
@Service
public class SqlExecutor implements SopNodeExecutor {
@Autowired
private SopDataSourceService sopDataSourceService;
@Autowired
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
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);
String sqlTemplate = paramMap.get("source") + "";
String dataSourceId = paramMap.get("dataSourceId") + "";
String sqlTemplate = paramMap.get("source") + "";
String dataSourceId = paramMap.get("dataSourceId") + "";
// 执行sql插件
SopDataSource byId = sopDataSourceService.findByDataSourceId(dataSourceId);
SopBizAdapter mcgBizAdapter = new FlowDataAdapterImpl(byId);
// 执行sql插件
SopDataSource byId = sopDataSourceService.findByDataSourceId(dataSourceId);
SopBizAdapter mcgBizAdapter = new FlowDataAdapterImpl(byId);
String sql = FreemarkerUtil.processContent(sqlTemplate, executeStruct.toMap());
String sql = FreemarkerUtil.processContent(sqlTemplate, executeStruct.toMap());
int i = mcgBizAdapter.executeUpdate(sql);
mcgBizAdapter.executeUpdate(sql);
return "更新成功条数" + i;
} catch (Exception e) {
String message = e.getMessage();
resultMap.put(Constants.RES_FAIL_MESSAGE, message);
resultMap.put(Constants.RES_KEY, Constants.RES_FAIL);
}
return null;
}
} catch (Exception e) {
String message = e.getMessage();
resultMap.put(Constants.RES_FAIL_MESSAGE, message);
resultMap.put(Constants.RES_KEY, Constants.RES_FAIL);
}
return null;
}
}
\ No newline at end of file
......@@ -121,7 +121,13 @@ public abstract class AbstractConnect {
* @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() {
......
......@@ -175,7 +175,7 @@ public class DbConnect {
* @throws
*/
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();
Connection conn = null;
int count = 0;
......
......@@ -39,115 +39,115 @@ import cn.com.glsx.process.modules.sop.java.example.ControllerHttpDemo;
@SpringBootTest(classes = Application.class)
public class TestApplication {
@Autowired
private UserDemoService userDemoService;
@Autowired
private SopDataSourceService sopDataSourceService;
@Autowired
private SopInstNodeExecuteJobHandler sopInstNodeExecuteJobHandler;
@Autowired
private SopInstLinkService sopInstLinkService;
@Test
public void test() throws SQLException {
SopDataSource byId = sopDataSourceService.findByDataSourceId("SOP_CDP");
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'");
System.out.println(maps);
}
@Test
public void testupdate() throws SQLException {
SopDataSource byId = sopDataSourceService.getById(1);
SopBizAdapter mcgBizAdapter = new FlowDataAdapterImpl(byId);
mcgBizAdapter.executeUpdate("SELECT * FROM aa_bb");
}
@Test
public void testjava() throws Exception {
DynamicEngine de = DynamicEngine.getInstance();
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";
JSONObject jsonObject = new JSONObject();
jsonObject.put("id", 22);
Object instance = de.execute("Controller", source, "execute", new Class[] { JSON.class }, new Object[] { jsonObject });
System.out.println(JSON.toJSONString(instance));
}
@Test
public void testredis() throws InterruptedException {
// 设置并发数量
int count = 1;
// 线程池准备
CyclicBarrier cyclicBarrier = new CyclicBarrier(count);
ExecutorService executorService = Executors.newFixedThreadPool(count);
// 开始时间
long now = System.currentTimeMillis();
for (int i = 0; i < count; i++) {
executorService.execute(new Task(cyclicBarrier, i, userDemoService));
}
executorService.shutdown();
while (!executorService.isTerminated()) {
try {
Thread.sleep(10);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
public class Task implements Runnable {
private CyclicBarrier cyclicBarrier;
private int count;
private UserDemoService userDemoService;
public Task(CyclicBarrier cyclicBarrier, int count, UserDemoService userDemoService) {
this.cyclicBarrier = cyclicBarrier;
this.count = count;
this.userDemoService = userDemoService;
}
@Override
public void run() {
try {
cyclicBarrier.await();
User user = new User();
user.setAccount("123456");
userDemoService.testRedis(user);
} catch (Exception e) {
System.out.println("出现超时的线程" + count);
e.printStackTrace();
}
}
}
@Test
public void sopInstNodeExecuteJobHandler() {
SopInstNode sopInstNode = new SopInstNode();
sopInstNode.setNodeType("Java");
SopStruct sopStruct = new SopStruct();
sopInstNodeExecuteJobHandler.execute(sopStruct, sopInstNode);
}
@Test
public void testJava() {
JSONObject jsonObject = new JSONObject();
jsonObject.put("merchantNo", "44210895");
JSON execute = ControllerHttpDemo.execute(jsonObject);
System.out.println(execute);
}
@Test
public void findByInstId() {
List<SopInstNode> xblc7 = sopInstLinkService.findByInstId("xblc7");
String listString = JSON.toJSONString(xblc7, SerializerFeature.DisableCircularReferenceDetect);
System.out.println(listString);
}
@Autowired
private UserDemoService userDemoService;
@Autowired
private SopDataSourceService sopDataSourceService;
@Autowired
private SopInstNodeExecuteJobHandler sopInstNodeExecuteJobHandler;
@Autowired
private SopInstLinkService sopInstLinkService;
@Test
public void test() throws SQLException {
SopDataSource byId = sopDataSourceService.findByDataSourceId("SOP_CDP");
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'");
System.out.println(maps);
}
@Test
public void testupdate() throws SQLException {
SopDataSource byId = sopDataSourceService.findByDataSourceId("SOP_CDP");
SopBizAdapter mcgBizAdapter = new FlowDataAdapterImpl(byId);
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 {
DynamicEngine de = DynamicEngine.getInstance();
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";
JSONObject jsonObject = new JSONObject();
jsonObject.put("id", 22);
Object instance = de.execute("Controller", source, "execute", new Class[]{JSON.class}, new Object[]{jsonObject});
System.out.println(JSON.toJSONString(instance));
}
@Test
public void testredis() throws InterruptedException {
// 设置并发数量
int count = 1;
// 线程池准备
CyclicBarrier cyclicBarrier = new CyclicBarrier(count);
ExecutorService executorService = Executors.newFixedThreadPool(count);
// 开始时间
long now = System.currentTimeMillis();
for (int i = 0; i < count; i++) {
executorService.execute(new Task(cyclicBarrier, i, userDemoService));
}
executorService.shutdown();
while (!executorService.isTerminated()) {
try {
Thread.sleep(10);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
public class Task implements Runnable {
private CyclicBarrier cyclicBarrier;
private int count;
private UserDemoService userDemoService;
public Task(CyclicBarrier cyclicBarrier, int count, UserDemoService userDemoService) {
this.cyclicBarrier = cyclicBarrier;
this.count = count;
this.userDemoService = userDemoService;
}
@Override
public void run() {
try {
cyclicBarrier.await();
User user = new User();
user.setAccount("123456");
userDemoService.testRedis(user);
} catch (Exception e) {
System.out.println("出现超时的线程" + count);
e.printStackTrace();
}
}
}
@Test
public void sopInstNodeExecuteJobHandler() {
SopInstNode sopInstNode = new SopInstNode();
sopInstNode.setNodeType("Java");
SopStruct sopStruct = new SopStruct();
sopInstNodeExecuteJobHandler.execute(sopStruct, sopInstNode);
}
@Test
public void testJava() {
JSONObject jsonObject = new JSONObject();
jsonObject.put("merchantNo", "44210895");
JSON execute = ControllerHttpDemo.execute(jsonObject);
System.out.println(execute);
}
@Test
public void findByInstId() {
List<SopInstNode> xblc7 = sopInstLinkService.findByInstId("xblc7");
String listString = JSON.toJSONString(xblc7, SerializerFeature.DisableCircularReferenceDetect);
System.out.println(listString);
}
}
\ 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!