Parcourir la source

界面抒写java功能完成

wuxw il y a 6 ans
Parent
commit
af32e0cc49

+ 12 - 0
CommunityService/src/main/java/com/java110/community/CommunityServiceApplicationStart.java

@@ -51,6 +51,18 @@ public class CommunityServiceApplicationStart {
         return restTemplate;
     }
 
+    /**
+     * 实例化RestTemplate
+     *
+     * @return restTemplate
+     */
+    @Bean
+    public com.java110.core.client.RestTemplate restTemplateNoLoadBalanced() {
+        StringHttpMessageConverter m = new StringHttpMessageConverter(Charset.forName("UTF-8"));
+        com.java110.core.client.RestTemplate restTemplate = new RestTemplateBuilder().additionalMessageConverters(m).build(com.java110.core.client.RestTemplate.class);
+        return restTemplate;
+    }
+
     public static void main(String[] args) throws Exception {
         ApplicationContext context = SpringApplication.run(CommunityServiceApplicationStart.class, args);
         ServiceStartInit.initSystemConfig(context);

+ 1 - 1
OrderService/src/main/java/com/java110/order/api/CacheApi.java

@@ -5,7 +5,7 @@ import com.java110.common.constant.ResponseConstant;
 import com.java110.core.base.controller.BaseController;
 import com.java110.core.factory.DataQueryFactory;
 import com.java110.core.factory.DataTransactionFactory;
-import com.java110.entity.service.DataQuery;
+import com.java110.service.context.DataQuery;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;

+ 1 - 1
OrderService/src/main/java/com/java110/order/smo/ICenterServiceCacheSMO.java

@@ -1,6 +1,6 @@
 package com.java110.order.smo;
 
-import com.java110.entity.service.DataQuery;
+import com.java110.service.context.DataQuery;
 
 import java.util.Map;
 

+ 1 - 1
OrderService/src/main/java/com/java110/order/smo/impl/CenterServiceCacheSMOImpl.java

@@ -15,7 +15,7 @@ import com.java110.common.util.Assert;
 import com.java110.core.factory.DataTransactionFactory;
 import com.java110.entity.center.AppRoute;
 import com.java110.entity.mapping.Mapping;
-import com.java110.entity.service.DataQuery;
+import com.java110.service.context.DataQuery;
 import com.java110.entity.service.ServiceSql;
 import com.java110.service.dao.IQueryServiceDAO;
 import org.slf4j.Logger;

+ 1 - 1
java110-core/src/main/java/com/java110/core/factory/DataQueryFactory.java

@@ -1,7 +1,7 @@
 package com.java110.core.factory;
 
 import com.java110.common.cache.ServiceSqlCache;
-import com.java110.entity.service.DataQuery;
+import com.java110.core.context.service.DataQuery;
 import com.java110.entity.service.ServiceSql;
 
 /**

+ 1 - 1
java110-core/src/main/java/com/java110/core/javassist/IJavassist.java

@@ -1,6 +1,6 @@
 package com.java110.core.javassist;
 
-import com.java110.entity.service.DataQuery;
+import com.java110.core.context.service.DataQuery;
 
 /**
  * @ClassName IJavassist

+ 0 - 12
java110-core/src/main/java/com/java110/core/javassist/Java110CoreTemplateJavassist.java

@@ -1,12 +0,0 @@
-package com.java110.core.javassist;
-
-/**
- * @ClassName CoreTemplateJavassist
- * @Description TODO
- * @Author wuxw
- * @Date 2019/9/4 23:11
- * @Version 1.0
- * add by wuxw 2019/9/4
- **/
-public class Java110CoreTemplateJavassist {
-}

+ 1 - 1
java110-service/src/main/java/com/java110/service/api/BusinessApi.java

@@ -6,7 +6,7 @@ import com.java110.common.util.Assert;
 import com.java110.core.factory.DataQueryFactory;
 import com.java110.core.factory.DataTransactionFactory;
 import com.java110.core.base.controller.BaseController;
-import com.java110.entity.service.DataQuery;
+import com.java110.service.context.DataQuery;
 import com.java110.service.smo.IQueryServiceSMO;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiImplicitParam;

+ 45 - 2
java110-bean/src/main/java/com/java110/entity/service/DataQuery.java

@@ -1,9 +1,14 @@
-package com.java110.entity.service;
+package com.java110.service.context;
 
-import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
+import com.java110.common.factory.ApplicationContextFactory;
+import com.java110.entity.service.ServiceSql;
+import com.java110.service.dao.IQueryServiceDAO;
+import org.springframework.http.RequestEntity;
 import org.springframework.http.ResponseEntity;
+import org.springframework.web.client.RestTemplate;
 
+import java.util.List;
 import java.util.Map;
 
 /**
@@ -120,4 +125,42 @@ public class DataQuery {
         this.setRequestParams(JSONObject.parseObject(JSONObject.toJSONString(headers.get("params"))));
         return this;
     }
+
+    /**
+     * 根据SQL查询数据
+     * @param sql sql 语句
+     * @param sqlParam sql 参数
+     * @return 查询结果
+     */
+    public Object queryDataBySql(String sql, List<Object> sqlParam){
+        IQueryServiceDAO queryServiceDAOImpl = ApplicationContextFactory.getBean("queryServiceDAOImpl",IQueryServiceDAO.class);
+        return queryServiceDAOImpl.executeSql(sql, sqlParam.toArray());
+    }
+
+    /**
+     * 调用服务接口
+     * @param requestEntity 请求实体
+     * @return
+     */
+    public ResponseEntity<String> callService(RequestEntity requestEntity){
+        return callService(requestEntity,false);
+    }
+
+    /**
+     * 调用服务接口
+     * @param requestEntity 请求实体
+     * @param innerService 内部服务 true 外部服务为false
+     * @return
+     */
+    public ResponseEntity<String> callService(RequestEntity requestEntity,Boolean innerService){
+
+        RestTemplate restTemplate = null;
+
+        if(innerService){
+            restTemplate = ApplicationContextFactory.getBean("restTemplate",RestTemplate.class);
+        }else{
+            restTemplate = ApplicationContextFactory.getBean("restTemplateNoLoadBalanced",RestTemplate.class);
+        }
+        return restTemplate.exchange(requestEntity,String.class);
+    }
 }

+ 1 - 2
java110-service/src/main/java/com/java110/service/smo/IQueryServiceSMO.java

@@ -1,8 +1,7 @@
 package com.java110.service.smo;
 
-import com.alibaba.fastjson.JSONObject;
 import com.java110.common.exception.BusinessException;
-import com.java110.entity.service.DataQuery;
+import com.java110.service.context.DataQuery;
 
 /**
  * 公用查询处理

+ 1 - 2
java110-service/src/main/java/com/java110/service/smo/impl/QueryServiceSMOImpl.java

@@ -12,11 +12,10 @@ import com.java110.core.factory.DataTransactionFactory;
 import com.java110.common.log.LoggerEngine;
 import com.java110.common.util.Assert;
 import com.java110.common.util.StringUtil;
-import com.java110.entity.service.DataQuery;
+import com.java110.service.context.DataQuery;
 import com.java110.entity.service.ServiceSql;
 import com.java110.service.dao.IQueryServiceDAO;
 import com.java110.service.smo.IQueryServiceSMO;
-import javassist.ClassPool;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.ibatis.ognl.Ognl;
 import org.apache.ibatis.ognl.OgnlException;

+ 29 - 4
java110-service/src/test/java/com/java110/service/smo/impl/QueryServiceSMOImplTest.java

@@ -1,14 +1,15 @@
 package com.java110.service.smo.impl;
 
-
 import javassist.CannotCompileException;
-import javassist.ClassClassPath;
 import javassist.ClassPool;
 import javassist.CtClass;
 import javassist.CtMethod;
 import javassist.CtNewMethod;
+import javassist.NotFoundException;
+import javassist.util.HotSwapper;
 import junit.framework.TestCase;
 
+import java.io.IOException;
 import java.lang.reflect.Constructor;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
@@ -16,25 +17,49 @@ import java.lang.reflect.Method;
 public class QueryServiceSMOImplTest extends TestCase {
 
 
-    public void testJava() throws CannotCompileException, NoSuchMethodException, InvocationTargetException, IllegalAccessException {
+    public void testJava() throws CannotCompileException, NoSuchMethodException, InvocationTargetException, IllegalAccessException, NotFoundException, IOException, ClassNotFoundException {
         String javaCode = "public static void testJava2() {       DataQuery dataQuery = new DataQuery();\n dataQuery.setServiceCode(\"服务编码\");  System.out.println(dataQuery.getServiceCode());\n}\n";
                 String    javaCode2 ="public static void testJava1() {     testJava2(); ServiceSql serviceSql = new ServiceSql();  System.out.println(\"623213\");\n}";
+                String    javaCode3 ="public static void testJava3() {     ServiceSql serviceSql = new ServiceSql();  System.out.println(\"723213\");\n}";
         ClassPool classPool = ClassPool.getDefault();
         classPool.importPackage("com.java110.entity.service.DataQuery");
         classPool.importPackage("com.java110.entity.service.ServiceSql");
-        CtClass ctClass = classPool.makeClass("com.java110.service.smo.WuxwTest");
+        CtClass ctClass = classPool.makeClass("com.java110.service.smo.WuxwTest3");
         CtMethod helloM = CtNewMethod.make(javaCode, ctClass);
         ctClass.addMethod(helloM);
 
         CtMethod helloM1 = CtNewMethod.make(javaCode2, ctClass);
         ctClass.addMethod(helloM1);
         Class pc=ctClass.toClass();
+        //ctClass.writeFile("./1111");
         Method move= pc.getMethod("testJava1",new Class[]{});
 
         Constructor<?> con=pc.getConstructor(new Class[]{});
 
         move.invoke(con);
 
+        CtClass ctClass2 = classPool.get("com.java110.service.smo.WuxwTest3");
+        CtMethod helloM3 = CtNewMethod.make(javaCode3, ctClass2);
+        ctClass2.addMethod(helloM3);
+        //ctClass.detach();
+
+       // CtClass ctClass3 = classPool.get("com.java110.service.smo.WuxwTest1");
+
+        /*HotSwapper swap = new HotSwapper(8000);
+        swap.reload("com.java110.service.smo.WuxwTest3",ctClass2.toBytecode());
+        Class ctClass1 = Class.forName("com.java110.service.smo.WuxwTest3");
+
+
+         move= ctClass1.getMethod("testJava3",new Class[]{});
+
+         con=ctClass1.getConstructor(new Class[]{});
+
+        move.invoke(con);*/
+
+
+
+
+
 
 
     }