Commit d3b50dfc by tiger

Merge branch 'v1.0.1' of http://192.168.3.233:8090/platform/platform-process-server into v1.0.1

# Conflicts:
#	platform-process/src/test/java/cn/com/glsx/cn/com/glsx/TestApplication.java
2 parents effc0252 1943d6f0
Showing 24 changed files with 1041 additions and 41 deletions
......@@ -2,6 +2,8 @@ package cn.com.glsx.process.common.constant;
import com.glsx.plat.core.constant.BasicConstants;
import java.nio.charset.Charset;
/**
* 〈一句话功能简述〉<br>
* 公共常量类
......@@ -13,4 +15,6 @@ public final class Constants extends BasicConstants {
public final static String SERVER_NAME = "glsx_rest_admin";
public static final Charset CHARSET = Charset.forName("utf-8");
}
......@@ -28,9 +28,10 @@ public class DynamicTaskService {
private ElasticJobListener elasticJobListener;
private static LiteJobConfiguration.Builder simpleJobConfigBuilder(String jobName, Class<? extends SimpleJob> jobClass, int shardTotalCount,
String cron, String id) {
String cron, String description, String param) {
return LiteJobConfiguration.newBuilder(new SimpleJobConfiguration(
JobCoreConfiguration.newBuilder(jobName, cron, shardTotalCount).jobParameter(id).build(), jobClass.getCanonicalName()));
JobCoreConfiguration.newBuilder(jobName, cron, shardTotalCount).jobParameter(param).description(description).build(),
jobClass.getCanonicalName()));
}
/***
......@@ -42,9 +43,9 @@ public class DynamicTaskService {
* @param instance:定时任务实例
* @param parameters:参数
*/
public void create(String jobName, String cron, int shardingTotalCount, SimpleJob instance, String parameters) {
LiteJobConfiguration jobConfig = simpleJobConfigBuilder(jobName, instance.getClass(), shardingTotalCount, cron, parameters).overwrite(true)
.build();
public void create(String jobName, String cron, int shardingTotalCount, SimpleJob instance, String description, String param) {
LiteJobConfiguration jobConfig = simpleJobConfigBuilder(jobName, instance.getClass(), shardingTotalCount, cron, description, param)
.overwrite(true).build();
new SpringJobScheduler(instance, zookeeperRegistryCenter, jobConfig, elasticJobListener).init();
log.info("【动态任务】{},创建:cron:{}, job:{}", jobName, cron, instance.getClass().getSimpleName());
}
......
......@@ -30,7 +30,7 @@ public class SopInstExecuteJob implements SimpleJob {
DynamicTaskService taskService = SpringUtils.getBean(DynamicTaskService.class);
SopStruct sop = sopService.loadSop(instId);
if (taskService.isJobStoped(sop.getInst().getInstName())) {
if (taskService.isJobStoped(SopInstLoadJob.jobName(sop.getInst()))) {
// TODO 停止sop所有子任务
return;
}
......@@ -38,10 +38,11 @@ public class SopInstExecuteJob implements SimpleJob {
// TODO 创建所有节点任务
for (SopInstNode node : sop.getInstNodeMap().values()) {
if (StrUtil.isNotBlank(node.getNodeCron())) {
taskService.create(instId + "-" + node.getInstNodeId(), node.getNodeCron(), 1, new SopInstNodeJob(), instId);
taskService.create(SopInstLoadJob.jobName(sop.getInst(), node), node.getNodeCron(), 1, new SopInstNodeJob(),
sop.getInst().getInstName(),
node.getInstNodeId() + "");
}
}
}
}
......@@ -8,6 +8,7 @@ import com.glsx.plat.context.utils.SpringUtils;
import cn.com.glsx.process.job.DynamicTaskService;
import cn.com.glsx.process.modules.entity.SopInst;
import cn.com.glsx.process.modules.entity.SopInstNode;
import cn.com.glsx.process.modules.service.SopService;
import lombok.extern.slf4j.Slf4j;
......@@ -33,7 +34,7 @@ public class SopInstLoadJob implements SimpleJob {
for (SopInst inst : all) {
if (inst.getInstStatus() == 1) {
taskService.create(inst.getInstName(), inst.getInstCron(), 1, new SopInstExecuteJob(), inst.getInstId());
taskService.create(jobName(inst), inst.getInstCron(), 1, new SopInstExecuteJob(), inst.getInstName(), inst.getInstId());
} else {
taskService.stopJob(inst.getInstName());
......@@ -41,4 +42,11 @@ public class SopInstLoadJob implements SimpleJob {
}
}
public static String jobName(SopInst inst) {
return inst.getInstId();
}
public static String jobName(SopInst inst, SopInstNode node) {
return inst.getInstId() + "-" + node.getNodeId();
}
}
......@@ -20,8 +20,8 @@ public class SopInstNodeJob implements SimpleJob {
@Override
public void execute(ShardingContext shardingContext) {
// 参数
String instId = shardingContext.getJobParameter();
log.info("---------SopInstNodeJob------------- instId:{}", instId);
String instNodeId = shardingContext.getJobParameter();
log.info("---------SopInstNodeJob------------- instNodeId:{}", instNodeId);
SopService sopService = SpringUtils.getBean(SopService.class);
DynamicTaskService taskService = SpringUtils.getBean(DynamicTaskService.class);
......
package cn.com.glsx.process.modules.controller;
import com.alibaba.fastjson.JSON;
public class Controller {
public JSON execute(JSON param) {
System.out.println("测试java");
return param;
}
}
......@@ -24,38 +24,38 @@ import lombok.extern.slf4j.Slf4j;
@ResponseResultBody
public class TestJobController {
@Autowired
private DynamicTaskService dynamicTaskAdd;
@Autowired
private DynamicTaskService dynamicTaskAdd;
@Autowired
private SopService sopService;
@GetMapping("/jobtest")
@Operation(summary = "动态任务添加", description = "动态任务添加")
public void addtest(@RequestParam("cron") String cron) {
// cron表达式
dynamicTaskAdd.create("job001", cron, 1, new DynamicJob(), "test");
@GetMapping("/jobtest")
@Operation(summary = "动态任务添加", description = "动态任务添加")
public void addtest(@RequestParam("cron") String cron) {
// cron表达式
dynamicTaskAdd.create("job001", cron, 1, new DynamicJob(), "test", "");
}
}
@PostMapping("/jobtestupdate")
@Operation(summary = "动态任务更新", description = "动态任务更新")
public void updatetest(@RequestParam("cron") String cron, @RequestParam("jobName") String jobName) {
dynamicTaskAdd.updateJob(jobName, cron);
@PostMapping("/jobtestupdate")
@Operation(summary = "动态任务更新", description = "动态任务更新")
public void updatetest(@RequestParam("cron") String cron, @RequestParam("jobName") String jobName) {
dynamicTaskAdd.updateJob(jobName, cron);
}
}
@PostMapping("/jobtestdel")
@Operation(summary = "动态任务删除", description = "动态任务删除")
public void deltest(@RequestParam("jobName") String jobName) {
dynamicTaskAdd.removeJob(jobName);
}
@PostMapping("/jobtestdel")
@Operation(summary = "动态任务删除", description = "动态任务删除")
public void deltest(@RequestParam("jobName") String jobName) {
dynamicTaskAdd.removeJob(jobName);
}
@GetMapping("/inst")
@Operation(summary = "动态任务添加", description = "动态任务添加")
public void inst(@RequestParam("instId") String instId) {
// cron表达式
dynamicTaskAdd.create("SopInstLoadJob", "11 */2 * * * ?", 1, new SopInstLoadJob(), "每2分钟同步一次");
dynamicTaskAdd.create("SopInstLoadJob", "11 */2 * * * ?", 1, new SopInstLoadJob(), "每2分钟同步一次", "");
}
......
package cn.com.glsx.process.modules.service;
import cn.com.glsx.process.modules.entity.SopInst;
import cn.com.glsx.process.modules.entity.SopInstBatch;
import cn.com.glsx.process.modules.mapper.SopInstBatchMapper;
import cn.com.glsx.process.modules.mapper.SopInstMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class SopInstBatchService {
@Autowired
private SopInstBatchMapper sopInstBatchMapper;
/**
* 根据id查询
*
* @param batchNo
* @return
*/
private SopInstBatch findById(String batchNo) {
return sopInstBatchMapper.selectByPrimaryKey(batchNo);
}
/**
* 保存
*
* @param sopInstBatch
* @return
*/
public int insert(SopInstBatch sopInstBatch) {
return sopInstBatchMapper.insertUseGeneratedKeys(sopInstBatch);
}
/**
* 更新
*
* @param sopInstBatch
* @return
*/
public boolean update(SopInstBatch sopInstBatch) {
int i = sopInstBatchMapper.updateByPrimaryKeySelective(sopInstBatch);
if (i > 0) {
return true;
}
return false;
}
/**
* 根据id删除
*
* @param batchNo
* @return
*/
public boolean delete(String batchNo) {
int i = sopInstBatchMapper.deleteByPrimaryKey(batchNo);
if (i > 0) {
return true;
}
return false;
}
}
package cn.com.glsx.process.modules.service;
import cn.com.glsx.process.modules.entity.SopInstLink;
import cn.com.glsx.process.modules.mapper.SopInstLinkMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class SopInstLinkService {
@Autowired
private SopInstLinkMapper sopInstMapper;
/**
* 根据id查询
*
* @param linkId
* @return
*/
private SopInstLink findById(Integer linkId) {
return sopInstMapper.selectByPrimaryKey(linkId);
}
/**
* 保存
*
* @param sopInstLink
* @return
*/
public int insert(SopInstLink sopInstLink) {
return sopInstMapper.insertUseGeneratedKeys(sopInstLink);
}
/**
* 更新
*
* @param sopInstLink
* @return
*/
public boolean update(SopInstLink sopInstLink) {
int i = sopInstMapper.updateByPrimaryKeySelective(sopInstLink);
if (i > 0) {
return true;
}
return false;
}
/**
* 根据id删除
*
* @param linkId
* @return
*/
public boolean delete(Integer linkId) {
int i = sopInstMapper.deleteByPrimaryKey(linkId);
if (i > 0) {
return true;
}
return false;
}
}
package cn.com.glsx.process.modules.service;
import cn.com.glsx.process.modules.entity.SopInstNode;
import cn.com.glsx.process.modules.entity.SopInstNodeBatch;
import cn.com.glsx.process.modules.mapper.SopInstNodeBatchMapper;
import cn.com.glsx.process.modules.mapper.SopInstNodeMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class SopInstNodeBatchService {
@Autowired
private SopInstNodeBatchMapper sopInstNodeBatchMapper;
/**
* 根据id查询
*
* @param nodeBatchNo
* @return
*/
private SopInstNodeBatch findById(String nodeBatchNo) {
return sopInstNodeBatchMapper.selectByPrimaryKey(nodeBatchNo);
}
/**
* 保存
*
* @param sopInstNodeBatch
* @return
*/
public int insert(SopInstNodeBatch sopInstNodeBatch) {
return sopInstNodeBatchMapper.insertUseGeneratedKeys(sopInstNodeBatch);
}
/**
* 更新
*
* @param sopInstNodeBatch
* @return
*/
public boolean update(SopInstNodeBatch sopInstNodeBatch) {
int i = sopInstNodeBatchMapper.updateByPrimaryKeySelective(sopInstNodeBatch);
if (i > 0) {
return true;
}
return false;
}
/**
* 根据id删除
*
* @param nodeBatchNo
* @return
*/
public boolean delete(String nodeBatchNo) {
int i = sopInstNodeBatchMapper.deleteByPrimaryKey(nodeBatchNo);
if (i > 0) {
return true;
}
return false;
}
}
package cn.com.glsx.process.modules.service;
import cn.com.glsx.process.modules.entity.SopInstNode;
import cn.com.glsx.process.modules.mapper.SopInstNodeMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class SopInstNodeService {
@Autowired
private SopInstNodeMapper sopInstNodeMapper;
/**
* 根据id查询
*
* @param instNodeId
* @return
*/
private SopInstNode findById(Integer instNodeId) {
return sopInstNodeMapper.selectByPrimaryKey(instNodeId);
}
/**
* 保存
*
* @param sopInstNode
* @return
*/
public int insert(SopInstNode sopInstNode) {
return sopInstNodeMapper.insertUseGeneratedKeys(sopInstNode);
}
/**
* 更新
*
* @param sopInstNode
* @return
*/
public boolean update(SopInstNode sopInstNode) {
int i = sopInstNodeMapper.updateByPrimaryKeySelective(sopInstNode);
if (i > 0) {
return true;
}
return false;
}
/**
* 根据id删除
*
* @param instNodeId
* @return
*/
public boolean delete(Integer instNodeId) {
int i = sopInstNodeMapper.deleteByPrimaryKey(instNodeId);
if (i > 0) {
return true;
}
return false;
}
}
package cn.com.glsx.process.modules.service;
import cn.com.glsx.process.modules.entity.SopInst;
import cn.com.glsx.process.modules.mapper.SopInstMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class SopInstService {
@Autowired
private SopInstMapper sopInstMapper;
/**
* 根据id查询
*
* @param instId
* @return
*/
private SopInst findById(Integer instId) {
return sopInstMapper.selectByPrimaryKey(instId);
}
/**
* 保存
*
* @param sopInst
* @return
*/
public int insert(SopInst sopInst) {
return sopInstMapper.insertUseGeneratedKeys(sopInst);
}
/**
* 更新
*
* @param sopInst
* @return
*/
public boolean update(SopInst sopInst) {
int i = sopInstMapper.updateByPrimaryKeySelective(sopInst);
if (i > 0) {
return true;
}
return false;
}
/**
* 根据id删除
*
* @param instId
* @return
*/
public boolean delete(Integer instId) {
int i = sopInstMapper.deleteByPrimaryKey(instId);
if (i > 0) {
return true;
}
return false;
}
}
package cn.com.glsx.process.modules.service;
import cn.com.glsx.process.modules.entity.SopTplLink;
import cn.com.glsx.process.modules.mapper.SopTplLinkMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class SopTplLinkService {
@Autowired
private SopTplLinkMapper sopTplLinkMapper;
/**
* 根据id查询
*
* @param linkId
* @return
*/
private SopTplLink findById(Integer linkId) {
return sopTplLinkMapper.selectByPrimaryKey(linkId);
}
/**
* 保存
*
* @param sopTplLink
* @return
*/
public int insert(SopTplLink sopTplLink) {
return sopTplLinkMapper.insertUseGeneratedKeys(sopTplLink);
}
/**
* 更新
*
* @param sopTplLink
* @return
*/
public boolean update(SopTplLink sopTplLink) {
int i = sopTplLinkMapper.updateByPrimaryKeySelective(sopTplLink);
if (i > 0) {
return true;
}
return false;
}
/**
* 根据id删除
*
* @param id
* @return
*/
public boolean delete(Integer id) {
int i = sopTplLinkMapper.deleteByPrimaryKey(id);
if (i > 0) {
return true;
}
return false;
}
}
package cn.com.glsx.process.modules.service;
import cn.com.glsx.process.modules.entity.SopTplNode;
import cn.com.glsx.process.modules.mapper.SopTplNodeMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class SopTplNodeService {
@Autowired
private SopTplNodeMapper sopTplNodeMapper;
/**
* 根据id查询
*
* @param nodeId
* @return
*/
private SopTplNode findById(Integer nodeId) {
return sopTplNodeMapper.selectByPrimaryKey(nodeId);
}
/**
* 保存
*
* @param sopTplNode
* @return
*/
public int insert(SopTplNode sopTplNode) {
return sopTplNodeMapper.insertUseGeneratedKeys(sopTplNode);
}
/**
* 更新
*
* @param sopTplNode
* @return
*/
public boolean update(SopTplNode sopTplNode) {
int i = this.sopTplNodeMapper.updateByPrimaryKeySelective(sopTplNode);
if (i > 0) {
return true;
}
return false;
}
/**
* 根据id删除
*
* @param nodeId
* @return
*/
public boolean delete(Integer nodeId) {
int i = this.sopTplNodeMapper.deleteByPrimaryKey(nodeId);
if (i > 0) {
return true;
}
return false;
}
}
/*
* @Copyright (c) 2018 缪聪(mcg-helper@qq.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cn.com.glsx.process.plugin.java;
import javax.tools.SimpleJavaFileObject;
import java.net.URI;
public class CharSequenceJavaFileObject extends SimpleJavaFileObject {
private CharSequence content;
public CharSequenceJavaFileObject(String className,
CharSequence content) {
super(URI.create("string:///" + className.replace('.', '/')
+ Kind.SOURCE.extension), Kind.SOURCE);
this.content = content;
}
@Override
public CharSequence getCharContent(
boolean ignoreEncodingErrors) {
return content;
}
}
/*
* @Copyright (c) 2018 缪聪(mcg-helper@qq.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cn.com.glsx.process.plugin.java;
import javax.tools.FileObject;
import javax.tools.ForwardingJavaFileManager;
import javax.tools.JavaFileObject;
import javax.tools.StandardJavaFileManager;
import java.io.IOException;
public class ClassFileManager extends ForwardingJavaFileManager {
public JavaClassObject getJavaClassObject() {
return jclassObject;
}
private JavaClassObject jclassObject;
public ClassFileManager(StandardJavaFileManager
standardManager) {
super(standardManager);
}
@Override
public JavaFileObject getJavaFileForOutput(Location location,
String className, JavaFileObject.Kind kind, FileObject sibling)
throws IOException {
jclassObject = new JavaClassObject(className, kind);
return jclassObject;
}
}
/*
* @Copyright (c) 2018 缪聪(mcg-helper@qq.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cn.com.glsx.process.plugin.java;
import java.net.URL;
import java.net.URLClassLoader;
public class DynamicClassLoader extends URLClassLoader {
public DynamicClassLoader(ClassLoader parent) {
super(new URL[0], parent);
}
public Class<?> findClassByClassName(String className) throws ClassNotFoundException {
return this.findClass(className);
}
public Class<?> loadClass(String fullName, JavaClassObject jco) {
byte[] classData = jco.getBytes();
return this.defineClass(fullName, classData, 0, classData.length);
}
}
/*
* @Copyright (c) 2018 缪聪(mcg-helper@qq.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cn.com.glsx.process.plugin.java;
import cn.com.glsx.process.common.constant.Constants;
import javax.tools.*;
import java.io.File;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.List;
public class DynamicEngine {
private static DynamicEngine ourInstance = new DynamicEngine();
public static DynamicEngine getInstance() {
return ourInstance;
}
private URLClassLoader parentClassLoader;
private String classpath;
private DynamicEngine() {
this.parentClassLoader = (URLClassLoader) this.getClass().getClassLoader();
this.buildClassPath();
}
private void buildClassPath() {
this.classpath = null;
StringBuilder sb = new StringBuilder();
for (URL url : this.parentClassLoader.getURLs()) {
String p = url.getFile();
sb.append(p).append(File.pathSeparator);
}
this.classpath = sb.toString();
}
/**
* 调用类方法
* @param cls 类
* @param methodName 方法名
* @param paramsCls 方法参数类型
* @param params 方法参数
* @return
* @throws SecurityException
* @throws NoSuchMethodException
* @throws IllegalAccessException
* @throws InstantiationException
* @throws InvocationTargetException
* @throws IllegalArgumentException
*/
public Object invoke(Class<?> cls, String methodName, Class<?>[] paramsCls, Object[] params) throws NoSuchMethodException, SecurityException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException{
Object result = null;
Method method = cls.getDeclaredMethod(methodName, paramsCls);
Object obj = cls.newInstance();
result = method.invoke(obj, params);
return result;
}
public Object execute(String fullClassName, String javaCode, String method, Class<?>[] paramsCls,Object[] params) throws Exception {
Object result = null;
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
DiagnosticCollector<JavaFileObject> diagnostics = new DiagnosticCollector<JavaFileObject>();
ClassFileManager fileManager = new ClassFileManager(compiler.getStandardFileManager(diagnostics, null, null));
List<JavaFileObject> jfiles = new ArrayList<JavaFileObject>();
jfiles.add(new CharSequenceJavaFileObject(fullClassName, javaCode));
List<String> options = new ArrayList<String>();
options.add("-encoding");
options.add(Constants.CHARSET.toString());
options.add("-classpath");
options.add(this.classpath);
JavaCompiler.CompilationTask task = compiler.getTask(null, fileManager, diagnostics, options, null, jfiles);
boolean success = task.call();
if (success) {
JavaClassObject jco = fileManager.getJavaClassObject();
DynamicClassLoader dynamicClassLoader = new DynamicClassLoader(this.parentClassLoader);
Class<?> clazz = dynamicClassLoader.loadClass(fullClassName,jco);
result = invoke(clazz, method, paramsCls, params);
// instance = clazz.newInstance();
dynamicClassLoader.close();
} else {
StringBuilder error = new StringBuilder();
for (Diagnostic<?> diagnostic : diagnostics.getDiagnostics()) {
error.append(compilePrint(diagnostic));
}
throw new Exception(error.toString());
}
return result;
}
private String compilePrint(Diagnostic<?> diagnostic) {
StringBuilder res = new StringBuilder();
res.append("Code:[" + diagnostic.getCode() + "]\n");
res.append("Kind:[" + diagnostic.getKind() + "]\n");
res.append("Position:[" + diagnostic.getPosition() + "]\n");
res.append("Start Position:[" + diagnostic.getStartPosition() + "]\n");
res.append("End Position:[" + diagnostic.getEndPosition() + "]\n");
res.append("Source:[" + diagnostic.getSource() + "]\n");
res.append("Message:[" + diagnostic.getMessage(null) + "]\n");
res.append("LineNumber:[" + diagnostic.getLineNumber() + "]\n");
res.append("ColumnNumber:[" + diagnostic.getColumnNumber() + "]\n");
return res.toString();
}
}
/*
* @Copyright (c) 2018 缪聪(mcg-helper@qq.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cn.com.glsx.process.plugin.java;
import javax.tools.SimpleJavaFileObject;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.URI;
public class JavaClassObject extends SimpleJavaFileObject {
protected final ByteArrayOutputStream bos = new ByteArrayOutputStream();
public JavaClassObject(String name, Kind kind) {
super(URI.create("string:///" + name.replace('.', '/') + kind.extension), kind);
}
public byte[] getBytes() {
return bos.toByteArray();
}
@Override
public OutputStream openOutputStream() throws IOException {
return bos;
}
}
package cn.com.glsx.cn.com.glsx;
import java.sql.SQLException;
import java.util.List;
import java.util.Map;
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 cn.com.glsx.Application;
import cn.com.glsx.process.modules.entity.SopDataSource;
import cn.com.glsx.process.modules.service.SopDataSourceService;
import cn.com.glsx.process.modules.service.UserDemoService;
import cn.com.glsx.process.plugin.dbconn.FlowDataAdapterImpl;
import cn.com.glsx.process.plugin.dbconn.McgBizAdapter;
import cn.com.glsx.process.plugin.java.DynamicEngine;
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 java.sql.SQLException;
import java.util.List;
import java.util.Map;
/**
* 测试spring cloud 服务调用方式
......@@ -35,8 +37,33 @@ public class TestApplication {
SopDataSource byId = sopDataSourceService.getById(1);
McgBizAdapter mcgBizAdapter = new FlowDataAdapterImpl(byId);
List<Map<String, Object>> maps = mcgBizAdapter.tableQuery("SELECT * FROM sop_data_source");
List<Map<String, Object>> maps = mcgBizAdapter.tableQuery("SELECT * FROM aa_bb");
System.out.println(maps);
}
@Test
public void testupdate() throws SQLException {
SopDataSource byId = sopDataSourceService.getById(1);
McgBizAdapter 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));
}
}
\ No newline at end of file
package cn.com.glsx.process.modules.converter;
import cn.com.glsx.process.modules.entity.SopInst;
import cn.com.glsx.process.modules.entity.SopTpl;
import cn.com.glsx.process.modules.model.SopTplDTO;
import javax.annotation.Generated;
@Generated(
value = "org.mapstruct.ap.MappingProcessor",
date = "2023-09-11T15:01:39+0800",
comments = "version: 1.5.2.Final, compiler: javac, environment: Java 1.8.0_261 (Oracle Corporation)"
)
public class SopTplConverterImpl implements SopTplConverter {
@Override
public SopTplDTO do2dto(SopTpl sopTpl) {
if ( sopTpl == null ) {
return null;
}
SopTplDTO sopTplDTO = new SopTplDTO();
sopTplDTO.setTplId( sopTpl.getTplId() );
sopTplDTO.setTplName( sopTpl.getTplName() );
sopTplDTO.setTplCron( sopTpl.getTplCron() );
sopTplDTO.setTplRemark( sopTpl.getTplRemark() );
sopTplDTO.setTplStatus( sopTpl.getTplStatus() );
sopTplDTO.setTplParamDef( sopTpl.getTplParamDef() );
sopTplDTO.setTplResultDef( sopTpl.getTplResultDef() );
sopTplDTO.setTplSingleton( sopTpl.getTplSingleton() );
sopTplDTO.setCreateTime( sopTpl.getCreateTime() );
sopTplDTO.setUpdateTime( sopTpl.getUpdateTime() );
return sopTplDTO;
}
@Override
public SopTpl dto2do(SopTplDTO sopTplDTO) {
if ( sopTplDTO == null ) {
return null;
}
SopTpl sopTpl = new SopTpl();
sopTpl.setTplId( sopTplDTO.getTplId() );
sopTpl.setTplName( sopTplDTO.getTplName() );
sopTpl.setTplCron( sopTplDTO.getTplCron() );
sopTpl.setTplRemark( sopTplDTO.getTplRemark() );
sopTpl.setTplStatus( sopTplDTO.getTplStatus() );
sopTpl.setTplParamDef( sopTplDTO.getTplParamDef() );
sopTpl.setTplResultDef( sopTplDTO.getTplResultDef() );
sopTpl.setTplSingleton( sopTplDTO.getTplSingleton() );
sopTpl.setCreateTime( sopTplDTO.getCreateTime() );
sopTpl.setUpdateTime( sopTplDTO.getUpdateTime() );
return sopTpl;
}
@Override
public SopInst do2inst(SopTpl sopTpl) {
if ( sopTpl == null ) {
return null;
}
SopInst sopInst = new SopInst();
sopInst.setInstName( sopTpl.getTplName() );
sopInst.setInstCron( sopTpl.getTplCron() );
sopInst.setInstRemark( sopTpl.getTplRemark() );
sopInst.setInstParam( sopTpl.getTplParamDef() );
sopInst.setCreateTime( sopTpl.getCreateTime() );
sopInst.setUpdateTime( sopTpl.getUpdateTime() );
return sopInst;
}
}
package cn.com.glsx.process.modules.converter;
import cn.com.glsx.process.modules.entity.SopInstLink;
import cn.com.glsx.process.modules.entity.SopTplLink;
import javax.annotation.Generated;
@Generated(
value = "org.mapstruct.ap.MappingProcessor",
date = "2023-09-11T15:01:39+0800",
comments = "version: 1.5.2.Final, compiler: javac, environment: Java 1.8.0_261 (Oracle Corporation)"
)
public class SopTplLinKConverterImpl implements SopTplLinKConverter {
@Override
public SopInstLink tpl2inst(SopTplLink link) {
if ( link == null ) {
return null;
}
SopInstLink sopInstLink = new SopInstLink();
sopInstLink.setSourceId( link.getSourceId() );
sopInstLink.setTargetId( link.getTargetId() );
return sopInstLink;
}
}
package cn.com.glsx.process.modules.converter;
import cn.com.glsx.process.modules.entity.SopInstNode;
import cn.com.glsx.process.modules.entity.SopTplNode;
import javax.annotation.Generated;
@Generated(
value = "org.mapstruct.ap.MappingProcessor",
date = "2023-09-11T15:01:39+0800",
comments = "version: 1.5.2.Final, compiler: javac, environment: Java 1.8.0_261 (Oracle Corporation)"
)
public class SopTplNodeConverterImpl implements SopTplNodeConverter {
@Override
public SopInstNode tpl2inst(SopTplNode node) {
if ( node == null ) {
return null;
}
SopInstNode sopInstNode = new SopInstNode();
sopInstNode.setNodeParam( node.getNodeParamDef() );
sopInstNode.setNodeContent( node.getNodeContentDef() );
sopInstNode.setNodeId( node.getNodeId() );
sopInstNode.setNodeName( node.getNodeName() );
sopInstNode.setNodeType( node.getNodeType() );
sopInstNode.setNodeLabel( node.getNodeLabel() );
sopInstNode.setNodeKey( node.getNodeKey() );
sopInstNode.setNodeShow( node.getNodeShow() );
sopInstNode.setNodeVisible( node.getNodeVisible() );
sopInstNode.setNodeCron( node.getNodeCron() );
sopInstNode.setNodeExpireCron( node.getNodeExpireCron() );
return sopInstNode;
}
}
package cn.com.glsx.process.modules.converter;
import cn.com.glsx.process.modules.entity.User;
import cn.com.glsx.process.modules.model.UserBO;
import cn.com.glsx.process.modules.model.UserDTO;
import javax.annotation.Generated;
@Generated(
value = "org.mapstruct.ap.MappingProcessor",
date = "2023-09-11T15:01:39+0800",
comments = "version: 1.5.2.Final, compiler: javac, environment: Java 1.8.0_261 (Oracle Corporation)"
)
public class UserConverterImpl implements UserConverter {
@Override
public UserDTO do2dto(User user) {
if ( user == null ) {
return null;
}
UserDTO userDTO = new UserDTO();
userDTO.setId( user.getId() );
userDTO.setAccount( user.getAccount() );
userDTO.setUsername( user.getUsername() );
userDTO.setRealname( user.getRealname() );
userDTO.setPassword( user.getPassword() );
userDTO.setPhone( user.getPhone() );
return userDTO;
}
@Override
public User dto2do(UserDTO userDTO) {
if ( userDTO == null ) {
return null;
}
User user = new User();
user.setId( userDTO.getId() );
user.setAccount( userDTO.getAccount() );
user.setPassword( userDTO.getPassword() );
user.setUsername( userDTO.getUsername() );
user.setRealname( userDTO.getRealname() );
user.setPhone( userDTO.getPhone() );
return user;
}
@Override
public UserBO do2bo(User user) {
if ( user == null ) {
return null;
}
UserBO userBO = new UserBO();
userBO.setRealName( user.getRealname() );
userBO.setId( user.getId() );
userBO.setAccount( user.getAccount() );
userBO.setPassword( user.getPassword() );
userBO.setUsername( user.getUsername() );
userBO.setPhone( user.getPhone() );
userBO.setAvatar( user.getAvatar() );
return userBO;
}
@Override
public User bo2do(UserBO userBO) {
if ( userBO == null ) {
return null;
}
User user = new User();
user.setRealname( userBO.getRealName() );
user.setId( userBO.getId() );
user.setAccount( userBO.getAccount() );
user.setPassword( userBO.getPassword() );
user.setUsername( userBO.getUsername() );
user.setPhone( userBO.getPhone() );
user.setAvatar( userBO.getAvatar() );
return user;
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!