Api/pom.xml
@@ -25,6 +25,12 @@ <dependency> <groupId>com.java110</groupId> <artifactId>java110-service</artifactId> <exclusions> <exclusion> <artifactId>java110-db</artifactId> <groupId>com.java110</groupId> </exclusion> </exclusions> </dependency> <dependency> Api/src/main/java/com/java110/api/ApiApplicationStart.java
@@ -1,3 +1,4 @@ package com.java110.api; import com.java110.core.annotation.Java110ListenerDiscovery; @@ -8,7 +9,9 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; import org.springframework.boot.web.client.RestTemplateBuilder; import org.springframework.cloud.client.discovery.EnableDiscoveryClient; import org.springframework.cloud.client.loadbalancer.LoadBalanced; @@ -37,13 +40,18 @@ * @date 2016年8月6日 * @tag */ @SpringBootApplication(scanBasePackages = {"com.java110.service", "com.java110.api", "com.java110.core", "com.java110.event.service.api", "com.java110.cache"}) @SpringBootApplication(scanBasePackages = {"com.java110.service.aop", "com.java110.service.configuration", "com.java110.service.controller", "com.java110.service.filter", "com.java110.service.init", "com.java110.api", "com.java110.core", "com.java110.event.service.api", "com.java110.cache"}) @EnableDiscoveryClient @Java110ListenerDiscovery(listenerPublishClass = ServiceDataFlowEventPublishing.class, basePackages = {"com.java110.api.listener"}) @EnableSwagger2 //@EnableConfigurationProperties(EventProperties.class) @EnableFeignClients(basePackages = {"com.java110.core.smo"}) @EnableAutoConfiguration(exclude = {DataSourceAutoConfiguration.class}) public class ApiApplicationStart { private static Logger logger = LoggerFactory.getLogger(ApiApplicationStart.class); @@ -73,6 +81,10 @@ return restTemplate; } /** * swagger 插件 * @return Docket 对象 */ @Bean public Docket swaggerSpringMvcPlugin() { return new Docket(DocumentationType.SWAGGER_2) CodeService/src/main/java/com/java110/code/CodeServiceApplicationStart.java
@@ -36,7 +36,7 @@ * @tag */ @SpringBootApplication(scanBasePackages = {"com.java110.service", "com.java110.code", "com.java110.core", "com.java110.cache", "com.java110.config.properties.code"}) "com.java110.config.properties.code", "com.java110.db"}) //@SpringBootApplication(scanBasePackages = {"com.java110.service","com.java110.code","com.java110.config.properties.code"}) @EnableDiscoveryClient @EnableFeignClients(basePackages = {"com.java110.core.smo"}) CommunityService/pom.xml
@@ -27,6 +27,7 @@ <groupId>com.java110</groupId> <artifactId>java110-service</artifactId> </dependency> <dependency> <groupId>com.java110</groupId> <artifactId>java110-event</artifactId> CommunityService/src/main/java/com/java110/community/CommunityServiceApplicationStart.java
@@ -28,7 +28,7 @@ * @date 2016年8月6日 * @tag */ @SpringBootApplication(scanBasePackages = {"com.java110.service", "com.java110.community", "com.java110.core", "com.java110.cache"}) @SpringBootApplication(scanBasePackages = {"com.java110.service", "com.java110.community", "com.java110.core", "com.java110.cache", "com.java110.db"}) @EnableDiscoveryClient @Java110ListenerDiscovery(listenerPublishClass = BusinessServiceDataFlowEventPublishing.class, basePackages = {"com.java110.community.listener"}) WebService/pom.xml
@@ -25,6 +25,12 @@ <dependency> <groupId>com.java110</groupId> <artifactId>java110-service</artifactId> <exclusions> <exclusion> <artifactId>java110-db</artifactId> <groupId>com.java110</groupId> </exclusion> </exclusions> </dependency> <dependency> WebService/src/main/java/com/java110/web/WebServiceApplicationStart.java
@@ -9,7 +9,9 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory; import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory; import org.springframework.boot.web.client.RestTemplateBuilder; @@ -32,10 +34,15 @@ * @date 2016年8月6日 * @tag */ @SpringBootApplication(scanBasePackages = {"com.java110.service", "com.java110.web", "com.java110.core", "com.java110.cache"}) @SpringBootApplication(scanBasePackages = {"com.java110.service.aop", "com.java110.service.configuration", "com.java110.service.controller", "com.java110.service.filter", "com.java110.service.init", "com.java110.web", "com.java110.core", "com.java110.cache"}) @EnableDiscoveryClient //@EnableConfigurationProperties(EventProperties.class) @EnableAutoConfiguration(exclude = {DataSourceAutoConfiguration.class}) public class WebServiceApplicationStart { /** WebService/src/main/resources/application-dev.yml
@@ -51,26 +51,6 @@ max-idle: 100 min-idle: 0 timeout: 0 datasource: connectionProperties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000 minIdle: 5 validationQuery: SELECT 1 FROM DUAL initialSize: 5 maxWait: 60000 filters: stat,wall,log4j poolPreparedStatements: true type: com.alibaba.druid.pool.DruidDataSource url: jdbc:mysql://dev.db.java110.com:3306/TT?useUnicode=true&characterEncoding=utf-8 maxPoolPreparedStatementPerConnectionSize: 20 password: TT@12345678 testOnBorrow: false testWhileIdle: true minEvictableIdleTimeMillis: 300000 timeBetweenEvictionRunsMillis: 60000 testOnReturn: false driverClassName: com.mysql.jdbc.Driver maxActive: 20 username: TT thymeleaf: mode: LEGACYHTML5 WebService/src/main/resources/application-prod.yml
@@ -51,26 +51,6 @@ max-idle: 100 min-idle: 0 timeout: 0 datasource: connectionProperties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000 minIdle: 5 validationQuery: SELECT 1 FROM DUAL initialSize: 5 maxWait: 60000 filters: stat,wall,log4j poolPreparedStatements: true type: com.alibaba.druid.pool.DruidDataSource url: jdbc:mysql://prod.db.java110.com:3306/TT?useUnicode=true&characterEncoding=utf-8 maxPoolPreparedStatementPerConnectionSize: 20 password: TT@12345678 testOnBorrow: false testWhileIdle: true minEvictableIdleTimeMillis: 300000 timeBetweenEvictionRunsMillis: 60000 testOnReturn: false driverClassName: com.mysql.jdbc.Driver maxActive: 20 username: TT thymeleaf: mode: LEGACYHTML5 WebService/src/main/resources/application-test.yml
@@ -51,26 +51,6 @@ max-idle: 100 min-idle: 0 timeout: 0 datasource: connectionProperties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000 minIdle: 5 validationQuery: SELECT 1 FROM DUAL initialSize: 5 maxWait: 60000 filters: stat,wall,log4j poolPreparedStatements: true type: com.alibaba.druid.pool.DruidDataSource url: jdbc:mysql://test.db.java110.com:3306/TT?useUnicode=true&characterEncoding=utf-8 maxPoolPreparedStatementPerConnectionSize: 20 password: TT@12345678 testOnBorrow: false testWhileIdle: true minEvictableIdleTimeMillis: 300000 timeBetweenEvictionRunsMillis: 60000 testOnReturn: false driverClassName: com.mysql.jdbc.Driver maxActive: 20 username: TT thymeleaf: mode: LEGACYHTML5 java110-config/src/main/resources/css/bootstrap-grid.css
File was deleted java110-config/src/main/resources/css/bootstrap-grid.css.map
File was deleted java110-config/src/main/resources/css/bootstrap-grid.min.css
File was deleted java110-config/src/main/resources/css/bootstrap-grid.min.css.map
File was deleted java110-config/src/main/resources/css/bootstrap-reboot.css
File was deleted java110-config/src/main/resources/css/bootstrap-reboot.css.map
File was deleted java110-config/src/main/resources/css/bootstrap-reboot.min.css
File was deleted java110-config/src/main/resources/css/bootstrap-reboot.min.css.map
File was deleted java110-config/src/main/resources/css/bootstrap.css
File was deleted java110-config/src/main/resources/css/bootstrap.css.map
File was deleted java110-config/src/main/resources/css/bootstrap.min.css
File was deleted java110-config/src/main/resources/css/bootstrap.min.css.map
File was deleted java110-config/src/main/resources/db/db.properties
File was deleted java110-config/src/main/resources/html/error.html
File was deleted java110-config/src/main/resources/js/bootstrap.bundle.js
File was deleted java110-config/src/main/resources/js/bootstrap.bundle.js.map
File was deleted java110-config/src/main/resources/js/bootstrap.bundle.min.js
File was deleted java110-config/src/main/resources/js/bootstrap.bundle.min.js.map
File was deleted java110-config/src/main/resources/js/bootstrap.js
File was deleted java110-config/src/main/resources/js/bootstrap.js.map
File was deleted java110-config/src/main/resources/js/bootstrap.min.js
File was deleted java110-config/src/main/resources/js/bootstrap.min.js.map
File was deleted java110-db/db/AgentService/create_table.sql
java110-db/db/CommentService/create_table.sql
java110-db/db/CommunityService/create_owner.sql
java110-db/db/CommunityService/create_room.sql
java110-db/db/CommunityService/create_table.sql
java110-db/db/LogService/create_table.db
java110-db/db/OrderService/create_table.sql
java110-db/db/PropertyService/create_table.sql
java110-db/db/ShopService/create_table.sql
java110-db/db/StoreService/create_table.sql
java110-db/db/UserService/create_table.db
java110-db/db/WebService/create_table.db
java110-db/db/WebService/menu.sql
java110-db/pom.xml
New file @@ -0,0 +1,51 @@ <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <parent> <artifactId>MicroCommunity</artifactId> <groupId>com.java110</groupId> <version>1.0-SNAPSHOT</version> </parent> <modelVersion>4.0.0</modelVersion> <artifactId>java110-db</artifactId> <packaging>jar</packaging> <name>java110-db</name> <!-- FIXME change it to the project's website --> <url>http://www.example.com</url> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <maven.compiler.source>1.7</maven.compiler.source> <maven.compiler.target>1.7</maven.compiler.target> </properties> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.11</version> <scope>test</scope> </dependency> <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> </dependency> <dependency> <groupId>com.alibaba</groupId> <artifactId>druid</artifactId> </dependency> <!--mapper--> <dependency> <groupId>tk.mybatis</groupId> <artifactId>mapper-spring-boot-starter</artifactId> </dependency> <dependency> <groupId>io.shardingsphere</groupId> <artifactId>sharding-jdbc</artifactId> </dependency> </dependencies> </project> java110-db/src/main/java/com/java110/db/MyBatisConfig.java
File was renamed from java110-service/src/main/java/com/java110/service/MyBatisConfig.java @@ -1,4 +1,4 @@ package com.java110.service; package com.java110.db; import com.alibaba.druid.pool.DruidDataSource; import org.apache.ibatis.session.SqlSessionFactory; @@ -32,11 +32,10 @@ @Bean(name = "dataSource") @ConfigurationProperties(prefix = "spring.datasource") public DataSource dataSource(){ public DataSource dataSource() { DruidDataSource druidDataSource = new DruidDataSource(); return druidDataSource; } @Bean(name = "sqlSessionFactory") java110-db/src/main/java/com/java110/db/MyBatisMapperScannerConfig.java
File was renamed from java110-service/src/main/java/com/java110/service/MyBatisMapperScannerConfig.java @@ -1,4 +1,4 @@ package com.java110.service; package com.java110.db; import org.mybatis.spring.mapper.MapperScannerConfigurer; import org.springframework.boot.autoconfigure.AutoConfigureAfter; java110-db/src/main/java/com/java110/db/druid/DruidConfiguration.java
File was renamed from java110-service/src/main/java/com/java110/service/druid/DruidConfiguration.java @@ -1,4 +1,4 @@ package com.java110.service.druid; package com.java110.db.druid; import com.alibaba.druid.support.http.StatViewServlet; import com.alibaba.druid.support.http.WebStatFilter; @@ -14,38 +14,40 @@ */ public class DruidConfiguration { private final static Logger logger = LoggerFactory.getLogger(DruidConfiguration.class); private static Logger logger = LoggerFactory.getLogger(DruidConfiguration.class); /** * 注册一个StatViewServlet * * @return */ @Bean public ServletRegistrationBean DruidStatViewServle2(){ public ServletRegistrationBean DruidStatViewServle2() { //org.springframework.boot.context.embedded.ServletRegistrationBean提供类的进行注册. ServletRegistrationBean servletRegistrationBean = new ServletRegistrationBean(new StatViewServlet(),"/druid2/*"); ServletRegistrationBean servletRegistrationBean = new ServletRegistrationBean(new StatViewServlet(), "/druid2/*"); //添加初始化参数:initParams //白名单: servletRegistrationBean.addInitParameter("allow","127.0.0.1"); servletRegistrationBean.addInitParameter("allow", "127.0.0.1"); //IP黑名单 (存在共同时,deny优先于allow) : 如果满足deny的话提示:Sorry, you are not permitted to view this page. servletRegistrationBean.addInitParameter("deny","192.168.1.73"); servletRegistrationBean.addInitParameter("deny", "192.168.1.73"); //登录查看信息的账号密码. servletRegistrationBean.addInitParameter("loginUsername","admin2"); servletRegistrationBean.addInitParameter("loginPassword","123456"); servletRegistrationBean.addInitParameter("loginUsername", "admin2"); servletRegistrationBean.addInitParameter("loginPassword", "123456"); //是否能够重置数据. servletRegistrationBean.addInitParameter("resetEnable","false"); servletRegistrationBean.addInitParameter("resetEnable", "false"); return servletRegistrationBean; } /** * 注册一个:filterRegistrationBean * * @return */ @Bean public FilterRegistrationBean druidStatFilter2(){ public FilterRegistrationBean druidStatFilter2() { FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean(new WebStatFilter()); @@ -53,7 +55,7 @@ filterRegistrationBean.addUrlPatterns("/*"); //添加不需要忽略的格式信息. filterRegistrationBean.addInitParameter("exclusions","*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid2/*"); filterRegistrationBean.addInitParameter("exclusions", "*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid2/*"); return filterRegistrationBean; } } java110-db/src/main/resources/mapper/agent/AgentServiceDaoImplMapper.xml
java110-db/src/main/resources/mapper/center/CenterServiceDAOImplMapper.xml
java110-db/src/main/resources/mapper/center/PrivilegeDAOImplMapper.xml
java110-db/src/main/resources/mapper/comment/CommentServiceDaoImplMapper.xml
java110-db/src/main/resources/mapper/common/CommonServiceDaoImplMapper.xml
java110-db/src/main/resources/mapper/common/PrimaryKeyServiceDaoImplMapper.xml
java110-db/src/main/resources/mapper/community/CommunityServiceDaoImplMapper.xml
java110-db/src/main/resources/mapper/floor/FloorServiceDaoImplMapper.xml
java110-db/src/main/resources/mapper/listener/ListenerServiceDaoImplMapper.xml
java110-db/src/main/resources/mapper/log/LogServiceDaoImplMapper.xml
java110-db/src/main/resources/mapper/order/OrderServiceDaoImplMapper.xml
java110-db/src/main/resources/mapper/owner/OwnerServiceDaoImplMapper.xml
java110-db/src/main/resources/mapper/product/ProductServiceDaoImplMapper.xml
java110-db/src/main/resources/mapper/property/PropertyServiceDaoImplMapper.xml
java110-db/src/main/resources/mapper/room/RoomAttrServiceDaoImplMapper.xml
java110-db/src/main/resources/mapper/room/RoomServiceDaoImplMapper.xml
java110-db/src/main/resources/mapper/rule/RuleDaoImplMapper.xml
java110-db/src/main/resources/mapper/service/QueryServiceDAOImplMapper.xml
java110-db/src/main/resources/mapper/shop/ShopServiceDaoImplMapper.xml
java110-db/src/main/resources/mapper/store/MerchantMemberServiceDaoImplMapper.xml
java110-db/src/main/resources/mapper/store/StoreServiceDaoImplMapper.xml
java110-db/src/main/resources/mapper/unit/UnitServiceDaoImplMapper.xml
java110-db/src/main/resources/mapper/user/UserServiceDaoImplMapper.xml
java110-db/src/test/java/com/java110/AppTest.java
New file @@ -0,0 +1,20 @@ package com.java110; import static org.junit.Assert.assertTrue; import org.junit.Test; /** * Unit test for simple App. */ public class AppTest { /** * Rigorous Test :-) */ @Test public void shouldAnswerWithTrue() { assertTrue( true ); } } java110-service/pom.xml
@@ -29,23 +29,6 @@ </dependency> <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> </dependency> <dependency> <groupId>com.alibaba</groupId> <artifactId>druid</artifactId> </dependency> <!--mapper--> <dependency> <groupId>tk.mybatis</groupId> <artifactId>mapper-spring-boot-starter</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-aop</artifactId> </dependency> @@ -72,6 +55,11 @@ <scope>provided</scope> </dependency> <dependency> <groupId>com.java110</groupId> <artifactId>java110-db</artifactId> </dependency> <dependency> <groupId>mysql</groupId> java110-service/src/main/java/com/java110/service/aop/PageProcessAspect.java
@@ -36,7 +36,7 @@ @Component public class PageProcessAspect { private static Logger logger = LoggerFactory.getLogger(PageProcessAspect.class); private static Logger logger = LoggerFactory.getLogger(PageProcessAspect.class); @Pointcut("execution(public * com.java110..*.*Controller.*(..)) || execution(public * com.java110..*.*Rest.*(..))") public void dataProcess() { java110-service/src/main/java/com/java110/service/dao/impl/QueryServiceDAOImpl.java
@@ -10,8 +10,16 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.sql.*; import java.util.*; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.ResultSetMetaData; import java.sql.SQLException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; /** * Created by wuxw on 2018/4/20. @@ -23,35 +31,36 @@ private final static Logger logger = LoggerFactory.getLogger(QueryServiceDAOImpl.class); /** * 防止sql注入 改造成直接用prepareStatement 预处理sql * 防止sql注入 改造成直接用prepareStatement 预处理sql * * @param sql * @param params * @return */ @Override public List<Map<String,Object>> executeSql(String sql,Object[] params) { logger.debug("----【queryServiceDAOImpl.executeSql】入参 : "+sql+" params= "+params); public List<Map<String, Object>> executeSql(String sql, Object[] params) { logger.debug("----【queryServiceDAOImpl.executeSql】入参 : " + sql + " params= " + params); Connection conn = null; ResultSet rs = null; PreparedStatement ps = null; List<Map<String,Object>> mapList = new ArrayList<Map<String,Object>>(); List<Map<String, Object>> mapList = new ArrayList<Map<String, Object>>(); try { conn = sqlSessionTemplate.getConnection(); ps = conn.prepareStatement(sql); if(params != null){ for(int i = 0 ; i < params.length ; i++){ ps.setObject(i+1, params[i]); if (params != null) { for (int i = 0; i < params.length; i++) { ps.setObject(i + 1, params[i]); } } rs = ps.executeQuery(); //精髓的地方就在这里,类ResultSet有getMetaData()会返回数据的列和对应的值的信息,然后我们将列名和对应的值作为map的键值存入map对象之中... ResultSetMetaData rsmd = rs.getMetaData(); while(rs.next()){ Map<String,Object> map = new HashMap<String,Object>(); for(int i = 0 ; i < rsmd.getColumnCount() ; i++){ String col_name = rsmd.getColumnLabel(i+1); while (rs.next()) { Map<String, Object> map = new HashMap<String, Object>(); for (int i = 0; i < rsmd.getColumnCount(); i++) { String col_name = rsmd.getColumnLabel(i + 1); Object col_value = rs.getObject(col_name); if(col_value == null){ if (col_value == null) { col_value = ""; } map.put(col_name, col_value); @@ -60,15 +69,15 @@ } return mapList; } catch (SQLException e) { logger.error("执行sql异常:" + sql +params,e); logger.error("执行sql异常:" + sql + params, e); return null; }finally{ } finally { try { //conn.close(); if( ps!=null) { if (ps != null) { ps.close(); } if(rs != null) { if (rs != null) { rs.close(); } } catch (SQLException e) { @@ -80,28 +89,29 @@ /** * 防止sql注入 改造成直接用prepareStatement 预处理sql * * @param sql * @param params * @return */ public int updateSql(String sql,Object[] params){ logger.debug("----【queryServiceDAOImpl.updateSql】入参 : "+sql+" params= "+params); public int updateSql(String sql, Object[] params) { logger.debug("----【queryServiceDAOImpl.updateSql】入参 : " + sql + " params= " + params); Connection conn = null; PreparedStatement ps = null; try { conn = sqlSessionTemplate.getConnection(); ps = conn.prepareStatement(sql); if(params != null){ for(int i = 0 ; i < params.length ; i++){ ps.setObject(i+1, params[i]); if (params != null) { for (int i = 0; i < params.length; i++) { ps.setObject(i + 1, params[i]); } } return ps.executeUpdate(); //精髓的地方就在这里,类ResultSet有getMetaData()会返回数据的列和对应的值的信息,然后我们将列名和对应的值作为map的键值存入map对象之中... } catch (SQLException e) { logger.error("执行sql异常:" + sql +params,e); logger.error("执行sql异常:" + sql + params, e); return 0; }finally{ } finally { try { //conn.close(); ps.close(); @@ -113,51 +123,52 @@ } @Override public String executeProc(Map<String,Object> paramsInfo) { public String executeProc(Map<String, Object> paramsInfo) { String paramsInfoStr = ""; for (String key : paramsInfo.keySet()){ if("procName".equals(key)){ for (String key : paramsInfo.keySet()) { if ("procName".equals(key)) { paramsInfoStr += (paramsInfo.get("procName") + "("); }else{ if(StringUtil.isNullOrNone(paramsInfo.get(key))){ } else { if (StringUtil.isNullOrNone(paramsInfo.get(key))) { paramsInfoStr += "'',"; }else{ paramsInfoStr += "'"+paramsInfo.get(key)+"',"; } else { paramsInfoStr += "'" + paramsInfo.get(key) + "',"; } } } paramsInfo.put("paramsInfo",paramsInfoStr); paramsInfo.put("paramsInfo", paramsInfoStr); sqlSessionTemplate.selectOne("queryServiceDAOImpl.executeProc",paramsInfo); sqlSessionTemplate.selectOne("queryServiceDAOImpl.executeProc", paramsInfo); return paramsInfo.get("resMsg") ==null ?"" :paramsInfo.get("resMsg").toString(); return paramsInfo.get("resMsg") == null ? "" : paramsInfo.get("resMsg").toString(); } @Override public String updateProc(Map<String,Object> paramsInfo) { public String updateProc(Map<String, Object> paramsInfo) { String paramsInfoStr = ""; for (String key : paramsInfo.keySet()){ if("procName".equals(key)){ for (String key : paramsInfo.keySet()) { if ("procName".equals(key)) { paramsInfoStr += (paramsInfo.get("procName") + "("); }else{ if(StringUtil.isNullOrNone(paramsInfo.get(key))){ } else { if (StringUtil.isNullOrNone(paramsInfo.get(key))) { paramsInfoStr += "'',"; }else{ paramsInfoStr += "'"+paramsInfo.get(key)+"',"; } else { paramsInfoStr += "'" + paramsInfo.get(key) + "',"; } } } paramsInfo.put("paramsInfo",paramsInfoStr); paramsInfo.put("paramsInfo", paramsInfoStr); sqlSessionTemplate.update("queryServiceDAOImpl.updateProc",paramsInfo); sqlSessionTemplate.update("queryServiceDAOImpl.updateProc", paramsInfo); return paramsInfo.get("resMsg") ==null ?"" :paramsInfo.get("resMsg").toString(); return paramsInfo.get("resMsg") == null ? "" : paramsInfo.get("resMsg").toString(); } /** * 查询 ServiceSql * * @return */ @Override @@ -168,9 +179,10 @@ /** * 查询服务业务信息 * * @return */ public List<ServiceBusiness> qureyServiceBusiness(){ public List<ServiceBusiness> qureyServiceBusiness() { return sqlSessionTemplate.selectList("queryServiceDAOImpl.queryServiceBusiness"); } } java110-service/src/main/java/com/java110/service/smo/impl/QueryServiceSMOImpl.java
@@ -38,7 +38,7 @@ public class QueryServiceSMOImpl extends LoggerEngine implements IQueryServiceSMO { private final static Logger logger = LoggerFactory.getLogger(QueryServiceSMOImpl.class); private static Logger logger = LoggerFactory.getLogger(QueryServiceSMOImpl.class); @Autowired @@ -51,62 +51,63 @@ try { ServiceSql currentServiceSql = ServiceSqlCache.getServiceSql(dataQuery.getServiceCode()); if (currentServiceSql == null) { throw new BusinessException(ResponseConstant.RESULT_CODE_INNER_ERROR,"未提供该服务 serviceCode = " + dataQuery.getServiceCode()); throw new BusinessException(ResponseConstant.RESULT_CODE_INNER_ERROR, "未提供该服务 serviceCode = " + dataQuery.getServiceCode()); } if ("".equals(currentServiceSql.getQueryModel())) { throw new BusinessException(ResponseConstant.RESULT_CODE_INNER_ERROR,"配置服务 serviceCode = " + dataQuery.getServiceCode() + " 错误,未配置QueryModel,请联系管理员"); throw new BusinessException(ResponseConstant.RESULT_CODE_INNER_ERROR, "配置服务 serviceCode = " + dataQuery.getServiceCode() + " 错误,未配置QueryModel,请联系管理员"); } //请求参数校验 List<String> sysParams = currentServiceSql.getParamList(); for(String param : sysParams) { if(!dataQuery.getRequestParams().containsKey(param)){ for (String param : sysParams) { if (!dataQuery.getRequestParams().containsKey(param)) { //2019-04-10 这里修改为不抛出异常而是写为空字符串 //throw new BusinessException(ResponseConstant.RESULT_PARAM_ERROR,"请求参数错误,请求报文中未包含参数 " + param + " 信息"); dataQuery.getRequestParams().put(param,""); dataQuery.getRequestParams().put(param, ""); } } dataQuery.setServiceSql(currentServiceSql); if (CommonConstant.QUERY_MODEL_SQL.equals(currentServiceSql.getQueryModel())) { doExecuteSql(dataQuery); }else if(CommonConstant.QUERY_MODE_JAVA.equals(currentServiceSql.getQueryModel())){ } else if (CommonConstant.QUERY_MODE_JAVA.equals(currentServiceSql.getQueryModel())) { doExecuteJava(dataQuery); }else { } else { doExecuteProc(dataQuery); } responseEntity = new ResponseEntity<String>(dataQuery.getResponseInfo().toJSONString(), HttpStatus.OK); }catch (BusinessException e){ logger.error("公用查询异常:",e); } catch (BusinessException e) { logger.error("公用查询异常:", e); /*dataQuery.setResponseInfo(DataTransactionFactory.createBusinessResponseJson(ResponseConstant.RESULT_PARAM_ERROR, e.getMessage()));*/ responseEntity = new ResponseEntity<String>("请求发生异常,"+e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR); }finally { responseEntity = new ResponseEntity<String>("请求发生异常," + e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR); } finally { dataQuery.setResponseEntity(responseEntity); } } @Override public void commonDoService(DataQuery dataQuery) throws BusinessException { //查询缓存查询 对应处理的ServiceSql try { ServiceSql currentServiceSql = ServiceSqlCache.getServiceSql(dataQuery.getServiceCode()); if (currentServiceSql == null) { throw new BusinessException(ResponseConstant.RESULT_CODE_INNER_ERROR,"未提供该服务 serviceCode = " + dataQuery.getServiceCode()); throw new BusinessException(ResponseConstant.RESULT_CODE_INNER_ERROR, "未提供该服务 serviceCode = " + dataQuery.getServiceCode()); } if ("".equals(currentServiceSql.getQueryModel())) { throw new BusinessException(ResponseConstant.RESULT_CODE_INNER_ERROR,"配置服务 serviceCode = " + dataQuery.getServiceCode() + " 错误,未配置QueryModel,请联系管理员"); throw new BusinessException(ResponseConstant.RESULT_CODE_INNER_ERROR, "配置服务 serviceCode = " + dataQuery.getServiceCode() + " 错误,未配置QueryModel,请联系管理员"); } dataQuery.setServiceSql(currentServiceSql); if (CommonConstant.QUERY_MODEL_SQL.equals(currentServiceSql.getQueryModel())) { doExecuteUpdateSql(dataQuery); return; }else if(CommonConstant.QUERY_MODE_JAVA.equals(currentServiceSql.getQueryModel())){ } else if (CommonConstant.QUERY_MODE_JAVA.equals(currentServiceSql.getQueryModel())) { doExecuteJava(dataQuery); return ; return; } doExecuteUpdateProc(dataQuery); }catch (BusinessException e){ logger.error("公用查询异常:",e); } catch (BusinessException e) { logger.error("公用查询异常:", e); dataQuery.setResponseInfo(DataTransactionFactory.createBusinessResponseJson(ResponseConstant.RESULT_PARAM_ERROR, e.getMessage())); } @@ -115,15 +116,16 @@ /** * {"PARAM:"{ "param1": "$.a.#A#Object", "param2": "$.a.b.A#B#Array", "param3": "$.a.b.c.A.B#C#Array" },"TEMPLATE":"{}" } * "param1": "$.a.#A#Object", * "param2": "$.a.b.A#B#Array", * "param3": "$.a.b.c.A.B#C#Array" * },"TEMPLATE":"{}" * } * 执行sql * * @param dataQuery */ private void doExecuteUpdateSql(DataQuery dataQuery) throws BusinessException{ private void doExecuteUpdateSql(DataQuery dataQuery) throws BusinessException { JSONObject business = null; try { JSONObject params = dataQuery.getRequestParams(); @@ -132,7 +134,7 @@ business = JSONObject.parseObject(templateObj.getString("TEMPLATE")); List<Object> currentParams = new ArrayList<Object>(); String currentSql = ""; for(String key : sqlObj.keySet()) { for (String key : sqlObj.keySet()) { currentSql = sqlObj.getString(key); String[] sqls = currentSql.split("#"); String currentSqlNew = ""; @@ -146,28 +148,29 @@ //currentSqlNew += params.get(sqls[sqlIndex]) instanceof Integer ? params.getInteger(sqls[sqlIndex]) : "'" + params.getString(sqls[sqlIndex]) + "'"; } int flag = queryServiceDAOImpl.updateSql(currentSqlNew,currentParams.toArray()); int flag = queryServiceDAOImpl.updateSql(currentSqlNew, currentParams.toArray()); if (flag < 1) { throw new BusinessException(ResponseConstant.RESULT_PARAM_ERROR, "数据交互失败"); } } }catch (Exception e){ logger.error("数据交互异常:",e); throw new BusinessException(ResponseConstant.RESULT_CODE_INNER_ERROR,"数据交互异常。。。"); } catch (Exception e) { logger.error("数据交互异常:", e); throw new BusinessException(ResponseConstant.RESULT_CODE_INNER_ERROR, "数据交互异常。。。"); } dataQuery.setResponseInfo(DataTransactionFactory.createBusinessResponseJson(ResponseConstant.RESULT_CODE_SUCCESS, "成功",business)); "成功", business)); } /** * 执行java脚本 * * @param dataQuery * @throws BusinessException */ private void doExecuteJava(DataQuery dataQuery) throws BusinessException{ private void doExecuteJava(DataQuery dataQuery) throws BusinessException { try { JSONObject params = dataQuery.getRequestParams(); String javaCode = dataQuery.getServiceSql().getJavaScript(); @@ -175,32 +178,34 @@ Interpreter interpreter = new Interpreter(); interpreter.eval(javaCode); String param = ""; for(String key : params.keySet()){ for (String key : params.keySet()) { param += (params.getString(key) + ","); } if(param.endsWith(",")){ param = param.substring(0,param.length()-1); if (param.endsWith(",")) { param = param.substring(0, param.length() - 1); } dataQuery.setResponseInfo(DataTransactionFactory.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,"数据交互异常。。。"); "成功", 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", "param2": "$.a.b.A#B#Array", "param3": "$.a.b.c.A.B#C#Array" },"TEMPLATE":"{}" } * "param1": "$.a.#A#Object", * "param2": "$.a.b.A#B#Array", * "param3": "$.a.b.c.A.B#C#Array" * },"TEMPLATE":"{}" * } * 执行sql * * @param dataQuery */ private void doExecuteSql(DataQuery dataQuery) throws BusinessException{ private void doExecuteSql(DataQuery dataQuery) throws BusinessException { JSONObject templateObj = JSONObject.parseObject(dataQuery.getServiceSql().getTemplate()); JSONObject templateParams = templateObj.getJSONObject("PARAM"); @@ -209,7 +214,7 @@ String[] values = null; JSONObject currentJsonObj = null; JSONArray currentJsonArr = null; for(String key:templateParams.keySet()){ for (String key : templateParams.keySet()) { template = templateParams.getString(key); values = judgeResponseTemplate(template); @@ -217,28 +222,29 @@ Object o = JSONPath.eval(business, values[0]); dataQuery.setTemplateKey(key); if(o instanceof JSONObject){ currentJsonObj = (JSONObject)o; doJsonObject(currentJsonObj,dataQuery,values); }else if(o instanceof JSONArray){ if (o instanceof JSONObject) { currentJsonObj = (JSONObject) o; doJsonObject(currentJsonObj, dataQuery, values); } else if (o instanceof JSONArray) { currentJsonArr = (JSONArray) o; doJsonArray(currentJsonArr,dataQuery,values); }else{ throw new BusinessException(ResponseConstant.RESULT_CODE_INNER_ERROR,"template 配置 不正确,value 值 和 TEMPLATE 配置不一致"); doJsonArray(currentJsonArr, dataQuery, values); } else { throw new BusinessException(ResponseConstant.RESULT_CODE_INNER_ERROR, "template 配置 不正确,value 值 和 TEMPLATE 配置不一致"); } } dataQuery.setResponseInfo(DataTransactionFactory.createBusinessResponseJson(ResponseConstant.RESULT_CODE_SUCCESS, "成功",business)); "成功", business)); } /** * 处理 jsonObject * * @param obj * @param dataQuery * @param values */ private void doJsonObject(JSONObject obj,DataQuery dataQuery,String[] values){ private void doJsonObject(JSONObject obj, DataQuery dataQuery, String[] values) { try { JSONObject params = dataQuery.getRequestParams(); JSONObject sqlObj = JSONObject.parseObject(dataQuery.getServiceSql().getSql()); @@ -253,7 +259,7 @@ continue; } if (sqls[sqlIndex].startsWith("PARENT_")) { if(obj.isEmpty()){ if (obj.isEmpty()) { currentSqlNew += "?"; currentParams.add("''"); continue; @@ -270,12 +276,12 @@ } } else { currentSqlNew += "?"; Object param = params.getString(sqls[sqlIndex]); if(params.get(sqls[sqlIndex]) instanceof Integer){ Object param = params.getString(sqls[sqlIndex]); if (params.get(sqls[sqlIndex]) instanceof Integer) { param = params.getInteger(sqls[sqlIndex]); } //这里对 page 和 rows 特殊处理 ,目前没有想到其他的办法 if(StringUtils.isNumeric(param.toString()) && "page,rows".contains(sqls[sqlIndex])){ //这里对 page 和 rows 特殊处理 ,目前没有想到其他的办法 if (StringUtils.isNumeric(param.toString()) && "page,rows".contains(sqls[sqlIndex])) { param = Integer.parseInt(param.toString()); } currentParams.add(param); @@ -283,93 +289,96 @@ } } List<Map<String,Object>> results = queryServiceDAOImpl.executeSql(currentSqlNew, currentParams.toArray()); List<Map<String, Object>> results = queryServiceDAOImpl.executeSql(currentSqlNew, currentParams.toArray()); if (results == null || results.size() == 0) { if(StringUtil.isNullOrNone(values[1])){ return ; if (StringUtil.isNullOrNone(values[1])) { return; } obj.put(values[1], values[2].equals("Object")?new JSONObject():new JSONArray()); obj.put(values[1], values[2].equals("Object") ? new JSONObject() : new JSONArray()); return; } if (values[2].equals("Object")) { if(StringUtil.isNullOrNone(values[1])){ if (StringUtil.isNullOrNone(values[1])) { obj.putAll(JSONObject.parseObject(JSONObject.toJSONString(results.get(0)))); return ; return; } obj.put(values[1], JSONObject.parseObject(JSONObject.toJSONString(results.get(0)))); } else if (values[2].equals("Array")) { if(StringUtil.isNullOrNone(values[1])){ if (StringUtil.isNullOrNone(values[1])) { JSONArray datas = JSONArray.parseArray(JSONArray.toJSONString(results)); for(int dataIndex = 0;dataIndex < datas.size();dataIndex ++){ for (int dataIndex = 0; dataIndex < datas.size(); dataIndex++) { obj.putAll(datas.getJSONObject(dataIndex)); } return ; return; } obj.put(values[1], JSONArray.parseArray(JSONArray.toJSONString(results))); } }catch (Exception e){ logger.error("数据交互异常:",e); throw new BusinessException(ResponseConstant.RESULT_CODE_INNER_ERROR,"数据交互异常。。。"); } catch (Exception e) { logger.error("数据交互异常:", e); throw new BusinessException(ResponseConstant.RESULT_CODE_INNER_ERROR, "数据交互异常。。。"); } } /** * 处理JSONArray * * @param objs * @param dataQuery * @param values */ private void doJsonArray(JSONArray objs,DataQuery dataQuery,String[] values){ private void doJsonArray(JSONArray objs, DataQuery dataQuery, String[] values) { for (int objIndex = 0 ; objIndex < objs.size();objIndex ++){ doJsonObject(objs.getJSONObject(objIndex),dataQuery,values); for (int objIndex = 0; objIndex < objs.size(); objIndex++) { doJsonObject(objs.getJSONObject(objIndex), dataQuery, values); } } /** * 执行存储 * * @param dataQuery */ private void doExecuteUpdateProc(DataQuery dataQuery){ private void doExecuteUpdateProc(DataQuery dataQuery) { Map info = new TreeMap(); info.put("procName",dataQuery.getServiceSql().getProc()); info.put("procName", dataQuery.getServiceSql().getProc()); JSONObject params = dataQuery.getRequestParams(); info.putAll(params); String jsonStr = queryServiceDAOImpl.updateProc(info); if(!Assert.isJsonObject(jsonStr)){ throw new BusinessException(ResponseConstant.RESULT_CODE_INNER_ERROR,"存储过程 procName = " + dataQuery.getServiceSql().getProc() + " 返回结果不是Json格式"); if (!Assert.isJsonObject(jsonStr)) { throw new BusinessException(ResponseConstant.RESULT_CODE_INNER_ERROR, "存储过程 procName = " + dataQuery.getServiceSql().getProc() + " 返回结果不是Json格式"); } dataQuery.setResponseInfo(DataTransactionFactory.createBusinessResponseJson(ResponseConstant.RESULT_CODE_SUCCESS, "成功",JSONObject.parseObject(jsonStr))); "成功", JSONObject.parseObject(jsonStr))); } /** * 校验 返回模板 * * @param template * @return * @throws BusinessException */ private String[] judgeResponseTemplate(String template) throws BusinessException{ private String[] judgeResponseTemplate(String template) throws BusinessException { if(!template.startsWith("$.")){ throw new BusinessException(ResponseConstant.RESULT_CODE_INNER_ERROR,"template 配置 不正确,value 必须以$.开头"); if (!template.startsWith("$.")) { throw new BusinessException(ResponseConstant.RESULT_CODE_INNER_ERROR, "template 配置 不正确,value 必须以$.开头"); } String[] values = template.split("#"); if(values == null || values.length != 3){ throw new BusinessException(ResponseConstant.RESULT_CODE_INNER_ERROR,"template 配置 不正确,value 必须有两个#号"); if (values == null || values.length != 3) { throw new BusinessException(ResponseConstant.RESULT_CODE_INNER_ERROR, "template 配置 不正确,value 必须有两个#号"); } if(StringUtil.isNullOrNone(values[1]) && !"$.##Object".equals(template) && !"$.##Array".equals(template)){ throw new BusinessException(ResponseConstant.RESULT_CODE_INNER_ERROR,"template 配置 不正确,目前只支持 $.##Object 和 $.##Array "); if (StringUtil.isNullOrNone(values[1]) && !"$.##Object".equals(template) && !"$.##Array".equals(template)) { throw new BusinessException(ResponseConstant.RESULT_CODE_INNER_ERROR, "template 配置 不正确,目前只支持 $.##Object 和 $.##Array "); } return values; @@ -378,22 +387,23 @@ /** * 执行存储 * * @param dataQuery */ private void doExecuteProc(DataQuery dataQuery){ private void doExecuteProc(DataQuery dataQuery) { Map info = new TreeMap(); info.put("procName",dataQuery.getServiceSql().getProc()); info.put("procName", dataQuery.getServiceSql().getProc()); JSONObject params = dataQuery.getRequestParams(); info.putAll(params); String jsonStr = queryServiceDAOImpl.executeProc(info); if(!Assert.isJsonObject(jsonStr)){ throw new BusinessException(ResponseConstant.RESULT_CODE_INNER_ERROR,"存储过程 procName = " + dataQuery.getServiceSql().getProc() + " 返回结果不是Json格式"); if (!Assert.isJsonObject(jsonStr)) { throw new BusinessException(ResponseConstant.RESULT_CODE_INNER_ERROR, "存储过程 procName = " + dataQuery.getServiceSql().getProc() + " 返回结果不是Json格式"); } dataQuery.setResponseInfo(DataTransactionFactory.createBusinessResponseJson(ResponseConstant.RESULT_CODE_SUCCESS, "成功",JSONObject.parseObject(jsonStr))); "成功", JSONObject.parseObject(jsonStr))); } pom.xml
@@ -32,6 +32,7 @@ <module>Api</module> <module>CommunityService</module> <module>java110-code-generator</module> <module>java110-db</module> </modules> <parent> @@ -173,6 +174,11 @@ <artifactId>java110-logAgent</artifactId> <version>${microcommunity.version}</version> </dependency> <dependency> <groupId>com.java110</groupId> <artifactId>java110-db</artifactId> <version>${microcommunity.version}</version> </dependency> <!-- logback 日志组件支持 --> <dependency> @@ -299,6 +305,12 @@ <version>${httpclient.verion}</version> </dependency> <dependency> <groupId>io.shardingsphere</groupId> <artifactId>sharding-jdbc</artifactId> <version>3.0.0.M3</version> </dependency> <!-- https://mvnrepository.com/artifact/org.apache.axis2/axis2 <dependency>