调整c_service_sql表,加入执行java代码脚本功能
| | |
| | | .idea |
| | | logs |
| | | *.iml |
| | | |
| | | *target/ |
| | |
| | | 3、实现异步同步数据到业务系统处理(同步方式,需要做事件监听等业务未完成,做事件监听主要为了对报文重构) |
| | | --------------------2018年04月17日----------------------- |
| | | 1、完成同步方式下订单侦听处理逻辑(主要是用来修改代码) |
| | | 2、完成订单处理逻辑,待测试版 |
| | | 2、完成订单处理逻辑,待测试版 |
| | | --------------------2018年04月23日----------------------- |
| | | 1、加入sign 鉴权处理 |
| | | 2、请求报文和返回报文加密处理 |
| | | 3、加入java脚本代码处理 |
| | |
| | | |
| | | System.out.println("1234567"); |
| | | |
| | | Thread.sleep(10000); |
| | | //Thread.sleep(10000); |
| | | throwException(); |
| | | |
| | | return 1111; |
| | |
| | | |
| | | private String proc; |
| | | |
| | | private String javaScript; |
| | | |
| | | private String template; |
| | | |
| | | private String statusCd; |
| | |
| | | this.remark = remark; |
| | | } |
| | | |
| | | public String getJavaScript() { |
| | | return javaScript; |
| | | } |
| | | |
| | | public void setJavaScript(String javaScript) { |
| | | this.javaScript = javaScript; |
| | | } |
| | | } |
| | |
| | | |
| | | public final static String QUERY_MODEL_SQL = "1"; |
| | | public final static String QUERY_MODEL_PROC = "2"; |
| | | public final static String QUERY_MODE_JAVA = "3"; |
| | | |
| | | /** |
| | | * 加密 开关 |
| | |
| | | query_model VARCHAR(1) NOT NULL COMMENT '查询方式 1、sql,2、存储过程', |
| | | `sql` LONGTEXT COMMENT '执行sql', |
| | | proc VARCHAR(200) COMMENT '存储过程名称', |
| | | java_script LONGTEXT COMMENT '执行java脚本代码', |
| | | template LONGTEXT COMMENT '输出模板', |
| | | remark VARCHAR(200) COMMENT '描述', |
| | | create_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', |
| | |
| | | <result column="query_model" jdbcType="VARCHAR" property="queryModel"/> |
| | | <result column="sql" jdbcType="CLOB" property="sql"/> |
| | | <result column="proc" jdbcType="VARCHAR" property="proc"/> |
| | | <result column="java_script" jdbcType="CLOB" property="javaScript"/> |
| | | <result column="template" jdbcType="CLOB" property="template"/> |
| | | <result column="status_cd" jdbcType="VARCHAR" property="statusCd"/> |
| | | <result column="remark" jdbcType="VARCHAR" property="remark"/> |
| | |
| | | |
| | | <select id="qureyServiceSqlAll" resultMap="serviceSqlMap"> |
| | | SELECT css.service_code,css.name,css.params,css.query_model,css.sql, |
| | | css.proc,css.template,css.remark,css.status_cd |
| | | css.proc,css.java_script,css.template,css.remark,css.status_cd |
| | | FROM c_service_sql css WHERE css.status_cd = '0' |
| | | </select> |
| | | |
| | |
| | | <artifactId>pagehelper-spring-boot-starter</artifactId> |
| | | </dependency> |
| | | --> |
| | | <dependency> |
| | | <groupId>org.beanshell</groupId> |
| | | <artifactId>bsh-core</artifactId> |
| | | </dependency> |
| | | |
| | | |
| | | <dependency> |
| | |
| | | <groupId>org.springframework</groupId> |
| | | <artifactId>spring-jms</artifactId> |
| | | </dependency> |
| | | <dependency> |
| | | <groupId>org.testng</groupId> |
| | | <artifactId>testng</artifactId> |
| | | <version>RELEASE</version> |
| | | </dependency> |
| | | </dependencies> |
| | | </project> |
| | |
| | | * @param businessInfo |
| | | * @return |
| | | */ |
| | | @RequestMapping(path = "/queryApi/query",method= RequestMethod.POST) |
| | | @RequestMapping(path = "/businessApi/query",method= RequestMethod.POST) |
| | | public String queryPost(@RequestBody String businessInfo) { |
| | | try { |
| | | DataQuery dataQuery = DataQueryFactory.newInstance().builder(businessInfo); |
| | |
| | | return ResponseTemplateUtil.createBusinessResponseJson(ResponseConstant.RESULT_CODE_ERROR,e.getMessage()+e).toJSONString(); |
| | | } |
| | | } |
| | | |
| | | @Deprecated |
| | | @RequestMapping(path = "/businessApi/do",method= RequestMethod.GET) |
| | | public String doGet(HttpServletRequest request) { |
| | | return ResponseTemplateUtil.createBusinessResponseJson(ResponseConstant.RESULT_CODE_ERROR,"不支持Get方法请求").toJSONString(); |
| | |
| | | * @param businessInfo |
| | | * @return |
| | | */ |
| | | @Deprecated |
| | | @RequestMapping(path = "/businessApi/do",method= RequestMethod.POST) |
| | | public String doPost(@RequestBody String businessInfo) { |
| | | try { |
| | |
| | | package com.java110.service.smo.impl; |
| | | |
| | | import bsh.Interpreter; |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.alibaba.fastjson.JSONPath; |
| | |
| | | if (CommonConstant.QUERY_MODEL_SQL.equals(currentServiceSql.getQueryModel())) { |
| | | doExecuteSql(dataQuery); |
| | | return; |
| | | }else if(CommonConstant.QUERY_MODE_JAVA.equals(currentServiceSql.getQueryModel())){ |
| | | doExecuteJava(dataQuery); |
| | | return ; |
| | | } |
| | | doExecuteProc(dataQuery); |
| | | }catch (BusinessException e){ |
| | |
| | | if (CommonConstant.QUERY_MODEL_SQL.equals(currentServiceSql.getQueryModel())) { |
| | | doExecuteUpdateSql(dataQuery); |
| | | return; |
| | | }else if(CommonConstant.QUERY_MODE_JAVA.equals(currentServiceSql.getQueryModel())){ |
| | | doExecuteJava(dataQuery); |
| | | return ; |
| | | } |
| | | doExecuteUpdateProc(dataQuery); |
| | | }catch (BusinessException e){ |
| | |
| | | throw new BusinessException(ResponseConstant.RESULT_CODE_INNER_ERROR,"数据交互异常。。。"); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 执行java脚本 |
| | | * @param dataQuery |
| | | * @throws BusinessException |
| | | */ |
| | | private void doExecuteJava(DataQuery dataQuery) throws BusinessException{ |
| | | try { |
| | | JSONObject params = dataQuery.getRequestParams(); |
| | | String javaCode = dataQuery.getServiceSql().getJavaScript(); |
| | | |
| | | Interpreter interpreter = new Interpreter(); |
| | | interpreter.eval(javaCode); |
| | | String param = ""; |
| | | for(String key : params.keySet()){ |
| | | param += (params.getString(key) + ","); |
| | | } |
| | | |
| | | if(param.endsWith(",")){ |
| | | param = param.substring(0,param.length()-1); |
| | | } |
| | | |
| | | dataQuery.setResponseInfo(ResponseTemplateUtil.createBusinessResponseJson(ResponseConstant.RESULT_CODE_SUCCESS, |
| | | "成功",JSONObject.parseObject(interpreter.eval("execute("+param+")").toString()))); |
| | | }catch (Exception e){ |
| | | logger.error("数据交互异常:",e); |
| | | throw new BusinessException(ResponseConstant.RESULT_CODE_INNER_ERROR,"数据交互异常。。。"); |
| | | } |
| | | } |
| | | /** |
| | | * {"PARAM:"{ |
| | | "param1": "$.a.#A#Object", |
| New file |
| | |
| | | package com.java110.service; |
| | | |
| | | import bsh.Interpreter; |
| | | import junit.framework.Test; |
| | | import junit.framework.TestCase; |
| | | import junit.framework.TestSuite; |
| | | |
| | | /** |
| | | * Created by wuxw on 2018/4/23. |
| | | */ |
| | | public class InterpreterTest extends TestCase { |
| | | |
| | | /** |
| | | * Create the test case |
| | | * |
| | | * @param testName name of the test case |
| | | */ |
| | | public InterpreterTest( String testName ) |
| | | { |
| | | super( testName ); |
| | | } |
| | | |
| | | /** |
| | | * @return the suite of tests being tested |
| | | */ |
| | | public static Test suite() |
| | | { |
| | | return new TestSuite( InterpreterTest.class ); |
| | | } |
| | | |
| | | /** |
| | | * Rigourous Test :-) |
| | | */ |
| | | public void testInterpreter() throws Exception |
| | | { |
| | | String javaCode = "public int add(int a, int b){" + |
| | | "return a+b;" + |
| | | "}" + |
| | | "" + |
| | | "public int execute(int a,int b){" + |
| | | "return add(a,b);" + |
| | | "}"; |
| | | Interpreter interpreter = new Interpreter(); |
| | | interpreter.eval(javaCode); |
| | | String param = "9,4"; |
| | | System.out.println(interpreter.eval("execute("+param+")").toString()); |
| | | } |
| | | } |
| | |
| | | </dependency> |
| | | |
| | | |
| | | <dependency> |
| | | <groupId>org.beanshell</groupId> |
| | | <artifactId>bsh-core</artifactId> |
| | | <version>2.0b4</version> |
| | | </dependency> |
| | | |
| | | |
| | | </dependencies> |
| | | |
| | | </dependencyManagement> |