wuxw7
2018-04-23 605b9a1a15bcb8b5186ffd708691634559aeb1e9
调整c_service_sql表,加入执行java代码脚本功能
12个文件已修改
1个文件已添加
128 ■■■■■ 已修改文件
.gitignore 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
CenterService/doc/centerService.docx 补丁 | 查看 | 原始文档 | blame | 历史
CodingLog.txt 6 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
OrderService/src/test/java/com/java110/order/executor/PrintInt.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
java110-bean/src/main/java/com/java110/entity/service/ServiceSql.java 8 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
java110-common/src/main/java/com/java110/common/constant/CommonConstant.java 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
java110-config/db/CenterService/create_table.db 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
java110-config/src/main/resources/mapper/service/QueryServiceDAOImplMapper.xml 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
java110-service/pom.xml 9 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
java110-service/src/main/java/com/java110/service/rest/BusinessApi.java 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
java110-service/src/main/java/com/java110/service/smo/impl/QueryServiceSMOImpl.java 36 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
java110-service/src/test/java/com/java110/service/InterpreterTest.java 48 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pom.xml 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
.gitignore
@@ -24,3 +24,5 @@
.idea
logs
*.iml
*target/
CenterService/doc/centerService.docx
Binary files differ
CodingLog.txt
@@ -16,4 +16,8 @@
3、实现异步同步数据到业务系统处理(同步方式,需要做事件监听等业务未完成,做事件监听主要为了对报文重构)
--------------------2018年04月17日-----------------------
1、完成同步方式下订单侦听处理逻辑(主要是用来修改代码)
2、完成订单处理逻辑,待测试版
2、完成订单处理逻辑,待测试版
--------------------2018年04月23日-----------------------
1、加入sign 鉴权处理
2、请求报文和返回报文加密处理
3、加入java脚本代码处理
OrderService/src/test/java/com/java110/order/executor/PrintInt.java
@@ -11,7 +11,7 @@
        System.out.println("1234567");
        Thread.sleep(10000);
        //Thread.sleep(10000);
        throwException();
        return 1111;
java110-bean/src/main/java/com/java110/entity/service/ServiceSql.java
@@ -24,6 +24,8 @@
    private String proc;
    private String javaScript;
    private String template;
    private String statusCd;
@@ -109,5 +111,11 @@
        this.remark = remark;
    }
    public String getJavaScript() {
        return javaScript;
    }
    public void setJavaScript(String javaScript) {
        this.javaScript = javaScript;
    }
}
java110-common/src/main/java/com/java110/common/constant/CommonConstant.java
@@ -31,6 +31,7 @@
    public final static String QUERY_MODEL_SQL = "1";
    public final static String QUERY_MODEL_PROC = "2";
    public final static String QUERY_MODE_JAVA = "3";
    /**
     * 加密 开关
java110-config/db/CenterService/create_table.db
@@ -173,6 +173,7 @@
    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 '创建时间',
java110-config/src/main/resources/mapper/service/QueryServiceDAOImplMapper.xml
@@ -11,6 +11,7 @@
        <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"/>
@@ -39,7 +40,7 @@
    <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>
java110-service/pom.xml
@@ -48,6 +48,10 @@
            <artifactId>pagehelper-spring-boot-starter</artifactId>
        </dependency>
        -->
        <dependency>
            <groupId>org.beanshell</groupId>
            <artifactId>bsh-core</artifactId>
        </dependency>
        <dependency>
@@ -86,5 +90,10 @@
            <groupId>org.springframework</groupId>
            <artifactId>spring-jms</artifactId>
        </dependency>
        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>RELEASE</version>
        </dependency>
    </dependencies>
</project>
java110-service/src/main/java/com/java110/service/rest/BusinessApi.java
@@ -47,7 +47,7 @@
     * @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);
@@ -59,7 +59,7 @@
            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();
@@ -81,6 +81,7 @@
     * @param businessInfo
     * @return
     */
    @Deprecated
    @RequestMapping(path = "/businessApi/do",method= RequestMethod.POST)
    public String doPost(@RequestBody String businessInfo) {
        try {
java110-service/src/main/java/com/java110/service/smo/impl/QueryServiceSMOImpl.java
@@ -1,5 +1,6 @@
package com.java110.service.smo.impl;
import bsh.Interpreter;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.JSONPath;
@@ -48,6 +49,9 @@
            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){
@@ -72,6 +76,9 @@
            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){
@@ -123,6 +130,35 @@
            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",
java110-service/src/test/java/com/java110/service/InterpreterTest.java
New file
@@ -0,0 +1,48 @@
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());
    }
}
pom.xml
@@ -335,6 +335,13 @@
            </dependency>
            <dependency>
                <groupId>org.beanshell</groupId>
                <artifactId>bsh-core</artifactId>
                <version>2.0b4</version>
            </dependency>
        </dependencies>
    </dependencyManagement>