├── .gitignore ├── README.md ├── deploy.sh ├── pom-service-hbase.xml ├── pom-service-search.xml ├── pom.xml ├── release-note.txt ├── rz-common ├── .gitignore ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── rick │ │ └── scaffold │ │ └── common │ │ ├── config │ │ └── Global.java │ │ ├── http │ │ ├── HttpService.java │ │ └── HttpServiceImpl.java │ │ ├── jsontool │ │ └── JsonMapper.java │ │ └── utils │ │ ├── FileUtils.java │ │ └── SpringContextHolder.java │ └── resources │ └── config │ └── props │ ├── cluster.properties │ ├── db.properties │ ├── domain.properties │ └── scaffold.properties ├── rz-core ├── .gitignore ├── db │ ├── v1.2 │ │ ├── 41.sql │ │ ├── 42.sql │ │ ├── 45.sql │ │ ├── goods.sql │ │ └── init_shop.sql │ └── v1 │ │ ├── init.sql │ │ └── product.sql ├── mycat │ ├── rule.xml │ ├── schema.xml │ ├── server.xml │ └── wrapper.conf ├── pom-gen.xml ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── rick │ │ │ └── scaffold │ │ │ ├── common │ │ │ ├── Constants.java │ │ │ ├── persistence │ │ │ │ ├── annotation │ │ │ │ │ └── MyBatisDao.java │ │ │ │ └── tool │ │ │ │ │ └── IncrSequenceTimeHandler.java │ │ │ ├── security │ │ │ │ └── SecurityComponent.java │ │ │ └── utils │ │ │ │ ├── CacheUtils.java │ │ │ │ ├── ExceptionUtils.java │ │ │ │ └── JedisUtils.java │ │ │ └── core │ │ │ ├── dao │ │ │ ├── address │ │ │ │ ├── AddressDao.java │ │ │ │ └── RegionDao.java │ │ │ ├── admin │ │ │ │ └── AdminDao.java │ │ │ ├── cart │ │ │ │ ├── CartDao.java │ │ │ │ └── CartItemDao.java │ │ │ ├── generic │ │ │ │ ├── BaseDao.java │ │ │ │ └── CrudDao.java │ │ │ ├── goods │ │ │ │ ├── CategoryDao.java │ │ │ │ ├── GoodsDao.java │ │ │ │ └── GoodsGalleryDao.java │ │ │ ├── order │ │ │ │ ├── OrderDao.java │ │ │ │ └── OrderItemDao.java │ │ │ ├── product │ │ │ │ └── ProductDao.java │ │ │ ├── shop │ │ │ │ └── ShopDao.java │ │ │ └── user │ │ │ │ ├── CompanyDao.java │ │ │ │ ├── PhotoDao.java │ │ │ │ ├── UserDao.java │ │ │ │ └── UsersDao.java │ │ │ ├── entity │ │ │ ├── address │ │ │ │ ├── Address.java │ │ │ │ └── Region.java │ │ │ ├── admin │ │ │ │ └── Admin.java │ │ │ ├── cart │ │ │ │ ├── Cart.java │ │ │ │ └── CartItem.java │ │ │ ├── generic │ │ │ │ ├── BaseEntity.java │ │ │ │ └── DataEntity.java │ │ │ ├── goods │ │ │ │ ├── Category.java │ │ │ │ ├── Goods.java │ │ │ │ └── GoodsGallery.java │ │ │ ├── order │ │ │ │ ├── Order.java │ │ │ │ └── OrderItem.java │ │ │ ├── product │ │ │ │ └── Product.java │ │ │ ├── shop │ │ │ │ └── Shop.java │ │ │ └── user │ │ │ │ ├── Company.java │ │ │ │ ├── FullUser.java │ │ │ │ ├── Photo.java │ │ │ │ ├── User.java │ │ │ │ └── Users.java │ │ │ ├── service │ │ │ ├── address │ │ │ │ ├── AddressService.java │ │ │ │ └── RegionService.java │ │ │ ├── admin │ │ │ │ └── AdminService.java │ │ │ ├── cart │ │ │ │ ├── CartItemService.java │ │ │ │ └── CartService.java │ │ │ ├── generic │ │ │ │ ├── BaseService.java │ │ │ │ └── CrudService.java │ │ │ ├── goods │ │ │ │ ├── CategoryService.java │ │ │ │ ├── GoodsGalleryService.java │ │ │ │ └── GoodsService.java │ │ │ ├── order │ │ │ │ ├── OrderItemService.java │ │ │ │ └── OrderService.java │ │ │ ├── product │ │ │ │ └── ProductService.java │ │ │ ├── shop │ │ │ │ └── ShopService.java │ │ │ └── user │ │ │ │ ├── CompanyService.java │ │ │ │ ├── PhotoService.java │ │ │ │ ├── UserService.java │ │ │ │ └── UsersService.java │ │ │ └── vo │ │ │ └── Paginator.java │ └── resources │ │ ├── config │ │ ├── cache │ │ │ └── ehcache-local.xml │ │ ├── mybatis │ │ │ └── mybatis-config.xml │ │ └── spring │ │ │ ├── spring-core.xml │ │ │ ├── spring-ehcache.xml │ │ │ ├── spring-jdbc.xml │ │ │ └── spring-jedis.xml │ │ ├── mappings │ │ ├── address │ │ │ ├── AddressMapper.xml │ │ │ └── RegionMapper.xml │ │ ├── admin │ │ │ └── AdminMapper.xml │ │ ├── cart │ │ │ ├── CartItemMapper.xml │ │ │ └── CartMapper.xml │ │ ├── goods │ │ │ ├── CategoryMapper.xml │ │ │ ├── GoodsGalleryMapper.xml │ │ │ └── GoodsMapper.xml │ │ ├── order │ │ │ ├── OrderItemMapper.xml │ │ │ └── OrderMapper.xml │ │ ├── product │ │ │ └── ProductMapper.xml │ │ ├── shop │ │ │ └── ShopMapper.xml │ │ └── user │ │ │ ├── CompanyMapper.xml │ │ │ ├── PhotoMapper.xml │ │ │ ├── UserMapper.xml │ │ │ └── UsersMapper.xml │ │ └── mybatis-generator │ │ ├── generatorConfig.xml │ │ └── mybatis-generator.properties │ └── test │ ├── java │ └── com │ │ └── rick │ │ └── scaffold │ │ ├── base │ │ └── BaseTest.java │ │ └── service │ │ ├── address │ │ └── TestRegion.java │ │ └── user │ │ └── TestObjectId.java │ └── resources │ └── test-applicationContext-core.xml ├── rz-hbase ├── .gitignore ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── rick │ │ │ └── scaffold │ │ │ ├── hbase │ │ │ ├── HbaseConstants.java │ │ │ ├── delegate │ │ │ │ ├── HbaseService.java │ │ │ │ └── HbaseServiceImpl.java │ │ │ ├── module │ │ │ │ └── goods │ │ │ │ │ └── GoodsHbaseImpl.java │ │ │ └── utils │ │ │ │ └── HbaseClient.java │ │ │ └── soa │ │ │ └── hbase │ │ │ ├── HbaseResult.java │ │ │ └── service │ │ │ └── GoodsHbase.java │ └── resources │ │ ├── config │ │ └── spring │ │ │ ├── spring-hbase-soa.xml │ │ │ └── spring-hbase.xml │ │ └── log4j.xml │ └── test │ ├── java │ └── com │ │ └── rick │ │ └── scaffold │ │ ├── base │ │ └── BaseTest.java │ │ └── hbase │ │ └── TestHbase.java │ └── resources │ └── test-spring-hbase.xml ├── rz-search ├── .gitignore ├── maven-eclipse.xml ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── rick │ │ │ └── scaffold │ │ │ ├── search │ │ │ ├── SearchConstants.java │ │ │ ├── module │ │ │ │ └── goods │ │ │ │ │ └── GoodsSearchImpl.java │ │ │ ├── services │ │ │ │ ├── RZEntry.java │ │ │ │ ├── RZFacet.java │ │ │ │ ├── RZGetResponse.java │ │ │ │ ├── RZIndexKeywordRequest.java │ │ │ │ ├── RZSearchField.java │ │ │ │ ├── RZSearchHit.java │ │ │ │ ├── RZSearchRequest.java │ │ │ │ ├── RZSearchResponse.java │ │ │ │ ├── RZSearchService.java │ │ │ │ ├── delegate │ │ │ │ │ ├── SearchDelegate.java │ │ │ │ │ └── SearchDelegateImpl.java │ │ │ │ ├── field │ │ │ │ │ ├── RZBooleanField.java │ │ │ │ │ ├── RZDateField.java │ │ │ │ │ ├── RZDoubleField.java │ │ │ │ │ ├── RZField.java │ │ │ │ │ ├── RZIntegerField.java │ │ │ │ │ ├── RZListField.java │ │ │ │ │ ├── RZLongField.java │ │ │ │ │ └── RZStringField.java │ │ │ │ ├── worker │ │ │ │ │ ├── DeleteKeywordsImpl.java │ │ │ │ │ ├── DeleteObjectImpl.java │ │ │ │ │ ├── DeleteObjectWorker.java │ │ │ │ │ ├── IndexWorker.java │ │ │ │ │ ├── KeywordIndexerImpl.java │ │ │ │ │ ├── KeywordSearchWorker.java │ │ │ │ │ ├── KeywordSearchWorkerImpl.java │ │ │ │ │ ├── ObjectIndexerImpl.java │ │ │ │ │ ├── SearchWorker.java │ │ │ │ │ └── SearchWorkerImpl.java │ │ │ │ └── workflow │ │ │ │ │ ├── DeleteObjectWorkflow.java │ │ │ │ │ ├── GetWorkflow.java │ │ │ │ │ ├── ImportWorkflow.java │ │ │ │ │ ├── IndexWorkflow.java │ │ │ │ │ ├── SearchWorkflow.java │ │ │ │ │ └── Workflow.java │ │ │ └── utils │ │ │ │ ├── CustomIndexConfiguration.java │ │ │ │ ├── CustomIndexFieldConfiguration.java │ │ │ │ ├── IndexConfiguration.java │ │ │ │ ├── SearchClient.java │ │ │ │ └── ServerConfiguration.java │ │ │ └── soa │ │ │ └── search │ │ │ ├── IndexObject.java │ │ │ ├── SearchEntry.java │ │ │ ├── SearchFacet.java │ │ │ ├── SearchKeywords.java │ │ │ ├── SearchResult.java │ │ │ ├── model │ │ │ └── IndexGoods.java │ │ │ └── service │ │ │ └── GoodsSearch.java │ └── resources │ │ ├── config │ │ ├── search │ │ │ ├── indice_mappings_goods.json │ │ │ └── indice_settings_cn.json │ │ └── spring │ │ │ ├── spring-search-soa.xml │ │ │ └── spring-search.xml │ │ └── log4j.xml │ └── test │ ├── java │ └── com │ │ └── rick │ │ └── scaffold │ │ ├── base │ │ └── BaseTest.java │ │ └── goods │ │ └── TestGoods.java │ └── resources │ ├── complex_search.json │ └── test-spring-search.xml └── rz-web ├── .gitignore ├── pom.xml ├── src ├── main │ ├── java │ │ └── com │ │ │ └── rick │ │ │ └── scaffold │ │ │ ├── common │ │ │ ├── listener │ │ │ │ ├── CorsFilter.java │ │ │ │ └── WebContextListener.java │ │ │ └── security │ │ │ │ ├── AuthenticationFilter.java │ │ │ │ ├── AuthenticationInterceptor.java │ │ │ │ └── AuthenticationRealm.java │ │ │ ├── exception │ │ │ ├── APIException.java │ │ │ └── CommonException.java │ │ │ ├── soa │ │ │ ├── hbase │ │ │ │ ├── HbaseResult.java │ │ │ │ └── service │ │ │ │ │ └── GoodsHbase.java │ │ │ └── search │ │ │ │ ├── IndexObject.java │ │ │ │ ├── SearchEntry.java │ │ │ │ ├── SearchFacet.java │ │ │ │ ├── SearchKeywords.java │ │ │ │ ├── SearchResult.java │ │ │ │ ├── model │ │ │ │ └── IndexGoods.java │ │ │ │ └── service │ │ │ │ └── GoodsSearch.java │ │ │ └── web │ │ │ ├── api │ │ │ ├── generic │ │ │ │ └── BaseAPI.java │ │ │ ├── product │ │ │ │ └── ProductAPI.java │ │ │ └── user │ │ │ │ └── UserAPI.java │ │ │ ├── bean │ │ │ └── generic │ │ │ │ ├── FailBean.java │ │ │ │ └── SuccessBean.java │ │ │ └── controller │ │ │ ├── AdminController.java │ │ │ └── LoginController.java │ ├── resources │ │ └── config │ │ │ ├── logger │ │ │ └── log4j.xml │ │ │ └── spring │ │ │ ├── dispatcher-servlet.xml │ │ │ ├── spring-shiro.xml │ │ │ ├── spring-soa.xml │ │ │ └── spring-web.xml │ └── webapp │ │ ├── META-INF │ │ └── MANIFEST.MF │ │ ├── WEB-INF │ │ ├── .gitignore │ │ ├── views │ │ │ ├── adminIndex.jsp │ │ │ ├── error │ │ │ │ ├── 404.jsp │ │ │ │ └── 500.jsp │ │ │ └── login.jsp │ │ └── web.xml │ │ └── static │ │ ├── css │ │ ├── bootstrap.min.css │ │ └── jquery.validate.min.css │ │ └── js │ │ ├── angular.js │ │ ├── bootstrap.min.js │ │ ├── jquery.min.js │ │ ├── jquery.validate.min.js │ │ ├── ui-bootstrap-tpls.js │ │ └── ui-bootstrap.js └── test │ ├── java │ └── com │ │ └── rick │ │ └── scaffold │ │ ├── api │ │ └── user │ │ │ └── TestUser.java │ │ ├── base │ │ ├── BaseApiTest.java │ │ └── BaseTest.java │ │ └── service │ │ ├── goods │ │ ├── TestGoods.java │ │ └── TestHbase.java │ │ └── user │ │ ├── TestCompany.java │ │ ├── TestES.java │ │ ├── TestPhoto.java │ │ ├── TestRedis.java │ │ ├── TestUser.java │ │ └── TestUsers.java │ └── resources │ ├── complex_search.json │ ├── test-applicationContext-all.xml │ └── test-spring-soa.xml └── tomcat ├── conf └── context.xml └── lib ├── commons-pool2-2.3.jar ├── jedis-2.7.2.jar └── redis-tomcat-0.0.1-SNAPSHOT.jar /.gitignore: -------------------------------------------------------------------------------- 1 | .mymetadata 2 | .checkstyle 3 | .classpath 4 | .project 5 | *.class 6 | .war 7 | .zip 8 | .rar 9 | .idea 10 | *.iml 11 | .ext* 12 | */.settings/* 13 | .settings 14 | /indexes/* 15 | /target/* 16 | /src/main/webapp/WEB-INF/classes/* 17 | /src/main/webapp/userfiles/* 18 | /target/ 19 | /data/ 20 | /bin/ 21 | */logs 22 | deploy.sh 23 | *~ 24 | zookeeper.out 25 | dump.rdb 26 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # scaffold 2 | J2EE scaffold 3 | 4 | A skeleton of J2EE project 5 | -------------------------------------------------------------------------------- /deploy.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | shutdown.sh 3 | mvn package 4 | rm -rf /Users/user/dev/tomcat7/webapps/scaffold* 5 | \cp -r /Users/user/Desktop/lib/scaffold/rz-web/target/scaffold.war /Users/user/dev/tomcat7/webapps 6 | startup.sh 7 | -------------------------------------------------------------------------------- /pom-service-hbase.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.rick 7 | scaffold 8 | 1.1.0 9 | pom 10 | 11 | scaffold 12 | http://www.rick.com 13 | 2015-2020 14 | 15 | 16 | 4.1.7.RELEASE 17 | 2.4.0 18 | 19 | 1.7 20 | UTF-8 21 | 22 | 23 | 24 | 25 | rz-common 26 | rz-hbase 27 | 28 | 29 | 30 | 31 | 32 | 33 | com.yzlpie 34 | Rick 35 | rickatyzlpie.com 36 | 37 | Code Farmer 38 | 39 | +8 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /pom-service-search.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.rick 7 | scaffold 8 | 1.1.0 9 | pom 10 | 11 | scaffold 12 | http://www.rick.com 13 | 2015-2020 14 | 15 | 16 | 4.1.7.RELEASE 17 | 2.4.0 18 | 19 | 1.7 20 | UTF-8 21 | 22 | 23 | 24 | 25 | rz-common 26 | rz-search 27 | 28 | 29 | 30 | 31 | 32 | 33 | com.yzlpie 34 | Rick 35 | rickatyzlpie.com 36 | 37 | Code Farmer 38 | 39 | +8 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.rick 7 | scaffold 8 | 1.1.0 9 | pom 10 | 11 | scaffold 12 | http://www.rick.com 13 | 2015-2020 14 | 15 | 16 | 17 | 4.1.7.RELEASE 18 | 4.2.17.Final 19 | 3.2.8 20 | 1.2.2 21 | 4.2.17.Final 22 | 1.2.3 23 | 24 | 25 | 1.2 26 | 2.4.0 27 | 28 | 29 | 5.1.31 30 | 31 | 32 | 1.7 33 | 2.2 34 | 7.6.14.v20131031 35 | 80 36 | UTF-8 37 | 38 | 39 | 40 | 41 | rz-common 42 | rz-core 43 | rz-web 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | com.yzlpie 54 | Rick 55 | rickatyzlpie.com 56 | 57 | Code Farmer 58 | 59 | +8 60 | 61 | 62 | 63 | -------------------------------------------------------------------------------- /release-note.txt: -------------------------------------------------------------------------------- 1 | v1.2.0 2 | modify rz-search as service, import dubbo -------------------------------------------------------------------------------- /rz-common/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | -------------------------------------------------------------------------------- /rz-common/src/main/java/com/rick/scaffold/common/config/Global.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.common.config; 2 | 3 | import java.util.Map; 4 | import java.util.Properties; 5 | 6 | import org.apache.commons.lang3.StringUtils; 7 | 8 | import com.google.common.base.Optional; 9 | import com.google.common.collect.Maps; 10 | import com.rick.scaffold.common.utils.FileUtils; 11 | 12 | /** 13 | * 全局配置类 14 | * @author Rick 15 | * @version 2015-08-25 16 | */ 17 | public class Global { 18 | 19 | /** 20 | * 当前对象实例 21 | */ 22 | private static Global global = new Global(); 23 | 24 | /** 25 | * 保存全局属性值 26 | */ 27 | private static Map map = Maps.newHashMap(); 28 | 29 | /** 30 | * 属性文件加载对象 31 | */ 32 | private static Properties loader = FileUtils.loadProps("config/props/scaffold.properties"); 33 | 34 | /** 35 | * 获取当前对象实例 36 | */ 37 | public static Global getInstance() { 38 | return global; 39 | } 40 | 41 | /** 42 | * 获取配置 43 | */ 44 | public static String getConfig(String key) { 45 | String value = map.get(key); 46 | if (value == null){ 47 | value = loader.getProperty(key); 48 | map.put(key, Optional.fromNullable(value).or(StringUtils.EMPTY)); 49 | } 50 | return value; 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /rz-common/src/main/java/com/rick/scaffold/common/http/HttpService.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.common.http; 2 | 3 | public interface HttpService { 4 | 5 | String put(String url, String params); 6 | } 7 | -------------------------------------------------------------------------------- /rz-common/src/main/java/com/rick/scaffold/common/http/HttpServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.common.http; 2 | 3 | import java.io.IOException; 4 | 5 | import org.apache.http.client.config.RequestConfig; 6 | import org.apache.http.client.methods.CloseableHttpResponse; 7 | import org.apache.http.client.methods.HttpPut; 8 | import org.apache.http.entity.StringEntity; 9 | import org.apache.http.impl.client.CloseableHttpClient; 10 | import org.apache.http.impl.client.HttpClients; 11 | import org.apache.http.util.EntityUtils; 12 | import org.springframework.stereotype.Component; 13 | 14 | @Component 15 | public class HttpServiceImpl implements HttpService { 16 | 17 | 18 | 19 | @Override 20 | public String put(String url, String params) { 21 | CloseableHttpClient httpclient = HttpClients.createDefault(); 22 | HttpPut httpput = new HttpPut(url); 23 | //timeout 24 | RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(5000).setConnectTimeout(2000).build(); 25 | httpput.setConfig(requestConfig); 26 | 27 | httpput.setHeader("Content-type", "application/json"); 28 | StringEntity requestParam = new StringEntity(params,"utf-8"); 29 | httpput.setEntity(requestParam); 30 | CloseableHttpResponse response = null; 31 | String result = null; 32 | try { 33 | response = httpclient.execute(httpput); 34 | result = EntityUtils.toString(response.getEntity()); 35 | System.out.println(result); 36 | } catch (Exception e) { 37 | e.printStackTrace(); 38 | } finally { 39 | try { 40 | if(response != null) { 41 | response.close(); 42 | } 43 | } catch (IOException e) { 44 | e.printStackTrace(); 45 | } 46 | } 47 | return result; 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /rz-common/src/main/java/com/rick/scaffold/common/utils/FileUtils.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.common.utils; 2 | 3 | import java.io.File; 4 | import java.io.IOException; 5 | import java.io.InputStream; 6 | import java.util.Properties; 7 | 8 | import org.apache.log4j.Logger; 9 | 10 | import com.google.common.base.Charsets; 11 | import com.google.common.io.Files; 12 | 13 | public class FileUtils { 14 | 15 | private static Logger log = Logger.getLogger(FileUtils.class); 16 | 17 | public static String readFileAsString(String fileName) { 18 | String path = FileUtils.class.getClassLoader().getResource(fileName).getPath(); 19 | File file = new File(path); 20 | try { 21 | String fileReaded = Files.asCharSource(file, Charsets.UTF_8).read(); 22 | return fileReaded; 23 | } catch (IOException e) { 24 | log.warn("read file "+ fileName + "error."); 25 | return null; 26 | } 27 | } 28 | 29 | public static Properties loadProps(String propsFile){ 30 | Properties props = new Properties(); 31 | InputStream inp = Thread.currentThread().getContextClassLoader().getResourceAsStream(propsFile); 32 | 33 | if (inp == null) { 34 | throw new java.lang.RuntimeException("time sequnce properties not found " + propsFile); 35 | } 36 | try { 37 | props.load(inp); 38 | } catch (IOException e) { 39 | throw new java.lang.RuntimeException(e); 40 | } 41 | return props; 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /rz-common/src/main/java/com/rick/scaffold/common/utils/SpringContextHolder.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.common.utils; 2 | 3 | import org.apache.commons.lang3.Validate; 4 | import org.slf4j.Logger; 5 | import org.slf4j.LoggerFactory; 6 | import org.springframework.beans.factory.DisposableBean; 7 | import org.springframework.context.ApplicationContext; 8 | import org.springframework.context.ApplicationContextAware; 9 | import org.springframework.context.annotation.Lazy; 10 | import org.springframework.stereotype.Service; 11 | 12 | /** 13 | * 以静态变量保存Spring ApplicationContext, 可在任何代码任何地方任何时候取出ApplicaitonContext. 14 | * 15 | * @author Zaric 16 | * @date 2013-5-29 下午1:25:40 17 | */ 18 | @Service 19 | @Lazy(false) 20 | public class SpringContextHolder implements ApplicationContextAware, DisposableBean { 21 | 22 | private static ApplicationContext applicationContext = null; 23 | 24 | private static Logger logger = LoggerFactory.getLogger(SpringContextHolder.class); 25 | 26 | /** 27 | * 取得存储在静态变量中的ApplicationContext. 28 | */ 29 | public static ApplicationContext getApplicationContext() { 30 | assertContextInjected(); 31 | return applicationContext; 32 | } 33 | 34 | /** 35 | * 从静态变量applicationContext中取得Bean, 自动转型为所赋值对象的类型. 36 | */ 37 | @SuppressWarnings("unchecked") 38 | public static T getBean(String name) { 39 | assertContextInjected(); 40 | return (T) applicationContext.getBean(name); 41 | } 42 | 43 | /** 44 | * 从静态变量applicationContext中取得Bean, 自动转型为所赋值对象的类型. 45 | */ 46 | public static T getBean(Class requiredType) { 47 | assertContextInjected(); 48 | return applicationContext.getBean(requiredType); 49 | } 50 | 51 | /** 52 | * 清除SpringContextHolder中的ApplicationContext为Null. 53 | */ 54 | public static void clearHolder() { 55 | if (logger.isDebugEnabled()){ 56 | logger.debug("清除SpringContextHolder中的ApplicationContext:" + applicationContext); 57 | } 58 | applicationContext = null; 59 | } 60 | 61 | /** 62 | * 实现ApplicationContextAware接口, 注入Context到静态变量中. 63 | */ 64 | @Override 65 | public void setApplicationContext(ApplicationContext applicationContext) { 66 | SpringContextHolder.applicationContext = applicationContext; 67 | } 68 | 69 | /** 70 | * 实现DisposableBean接口, 在Context关闭时清理静态变量. 71 | */ 72 | @Override 73 | public void destroy() throws Exception { 74 | SpringContextHolder.clearHolder(); 75 | } 76 | 77 | /** 78 | * 检查ApplicationContext不为空. 79 | */ 80 | private static void assertContextInjected() { 81 | Validate.validState(applicationContext != null, "applicaitonContext属性未注入, 请在applicationContext.xml中定义SpringContextHolder."); 82 | } 83 | } -------------------------------------------------------------------------------- /rz-common/src/main/resources/config/props/cluster.properties: -------------------------------------------------------------------------------- 1 | SEQ.DATAACENTERID=1 2 | SEQ.WORKID=1 -------------------------------------------------------------------------------- /rz-common/src/main/resources/config/props/db.properties: -------------------------------------------------------------------------------- 1 | db.driver=com.mysql.jdbc.Driver 2 | db.url=jdbc:mysql://192.168.6.49:8066/scaffold?useUnicode=true&characterEncoding=UTF-8 3 | db.user=root 4 | db.password=eros 5 | 6 | connection_pools.initial_pool_size=5 7 | connection_pools.min_pool_size=5 8 | connection_pools.max_pool_size=100 9 | connection_pools.max_idle_time=600 10 | connection_pools.acquire_increment=5 11 | connection_pools.checkout_timeout=60000 12 | 13 | #ubuntu path 14 | #mybatis.driver.path=/home/eros/.m2/repository/mysql/mysql-connector-java/5.1.31/mysql-connector-java-5.1.31.jar 15 | #mac path 16 | mybatis.driver.path=/Users/user/.m2/repository/mysql/mysql-connector-java/5.1.31/mysql-connector-java-5.1.31.jar 17 | #windows office 18 | #mybatis.driver.path=C:/Users/user/.m2/repository/mysql/mysql-connector-java/5.1.31/mysql-connector-java-5.1.31.jar 19 | 20 | mybatis.model.package=com.rick.scaffold.core.entity 21 | mybatis.mapper.package=mappings 22 | mybatis.dao.package=com.rick.scaffold.core.dao -------------------------------------------------------------------------------- /rz-common/src/main/resources/config/props/domain.properties: -------------------------------------------------------------------------------- 1 | domain.name=http://localhost -------------------------------------------------------------------------------- /rz-common/src/main/resources/config/props/scaffold.properties: -------------------------------------------------------------------------------- 1 | #global 2 | global.productName=scaffold 3 | global.version=1.0 4 | global.staticDomain=http://localhost:8080/scaffold/static 5 | 6 | #redis settings 7 | redis.keyPrefix=scaffold 8 | redis.host=192.168.6.41 9 | redis.port=6379 10 | 11 | #elasticsearch settings 12 | es.clusterName=elasticsearch 13 | es.host1=192.168.6.41 14 | es.port1=9300 15 | 16 | #zookeeper settings 17 | zoo.address=192.168.6.45:2181,192.168.6.42:2181,192.168.6.43:2181 18 | zoo.master.host=192.168.6.45 19 | zoo.master.port=2181 20 | 21 | #jsp file directory 22 | web.view.prefix=/WEB-INF/views/ 23 | web.view.suffix=.jsp -------------------------------------------------------------------------------- /rz-core/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | -------------------------------------------------------------------------------- /rz-core/db/v1/init.sql: -------------------------------------------------------------------------------- 1 | SET SESSION FOREIGN_KEY_CHECKS=0; 2 | 3 | /* Drop Tables */ 4 | 5 | DROP TABLE IF EXISTS sys_user; 6 | 7 | 8 | /* Create Tables */ 9 | 10 | CREATE TABLE sys_user 11 | ( 12 | id bigint(20) unique, 13 | login_name varchar(100) NOT NULL unique, 14 | password varchar(100) NOT NULL, 15 | name varchar(100) NOT NULL, 16 | email varchar(200), 17 | phone varchar(200), 18 | user_tag bigint(20), 19 | avatar varchar(255), 20 | login_ip varchar(100), 21 | login_date datetime, 22 | create_date datetime NOT NULL, 23 | update_date datetime NOT NULL, 24 | del_flag tinyint(1) DEFAULT 0 NOT NULL, 25 | company_id varchar(24) not null, 26 | PRIMARY KEY (id) 27 | ); 28 | 29 | CREATE INDEX idx_sys_user_update_date ON sys_user (update_date ASC); 30 | CREATE INDEX idx_sys_user_del_flag ON sys_user (del_flag ASC); 31 | 32 | drop table if exists sys_company; 33 | create table sys_company 34 | ( 35 | id bigint(20) unique, 36 | name varchar(100) NOT NULL, 37 | phone varchar(100) NOT NULL, 38 | primary key (id) 39 | ); 40 | 41 | drop table if exists sys_photo; 42 | create table sys_photo 43 | ( 44 | id bigint(20) unique, 45 | url varchar(100) NOT NULL, 46 | size int(11) NOT NULL, 47 | user_id bigint(20), 48 | primary key (id), 49 | FOREIGN KEY (user_id) REFERENCES sys_user(id) 50 | ); 51 | -------------------------------------------------------------------------------- /rz-core/db/v1/product.sql: -------------------------------------------------------------------------------- 1 | -- MySQL dump 10.13 Distrib 5.6.19, for debian-linux-gnu (x86_64) 2 | -- 3 | -- Host: localhost Database: zjsy 4 | -- ------------------------------------------------------ 5 | -- Server version 5.6.19-0ubuntu0.14.04.1 6 | 7 | /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; 8 | /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; 9 | /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; 10 | /*!40101 SET NAMES utf8 */; 11 | /*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; 12 | /*!40103 SET TIME_ZONE='+00:00' */; 13 | /*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; 14 | /*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; 15 | /*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; 16 | /*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; 17 | 18 | -- 19 | -- Table structure for table `yzl_product` 20 | -- 21 | 22 | DROP TABLE IF EXISTS `sys_product`; 23 | /*!40101 SET @saved_cs_client = @@character_set_client */; 24 | /*!40101 SET character_set_client = utf8 */; 25 | CREATE TABLE `sys_product` ( 26 | `id` bigint(20) unique, 27 | `create_date` datetime NOT NULL, 28 | `modify_date` datetime NOT NULL, 29 | `image` varchar(255), 30 | `remark` varchar(255), 31 | `name` varchar(255) NOT NULL, 32 | `price` decimal(21,2) NOT NULL, 33 | `sn` varchar(100) NOT NULL, 34 | `unit` varchar(255) NOT NULL, 35 | `amount` float NOT NULL DEFAULT 0, 36 | `delFlag` tinyint(1) NOT NULL DEFAULT 0, 37 | PRIMARY KEY (`id`) 38 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8; -------------------------------------------------------------------------------- /rz-core/mycat/schema.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 11 |
12 | 13 | 15 |
16 | 17 | 18 |
19 | 21 |
22 |
23 | 24 | 25 | 26 | 27 | 28 | 29 | 31 | select user() 32 | 33 | 34 | 36 | select user() 37 | 38 | 39 | 41 | select user() 42 | 43 | 44 | 45 | 46 |
47 | -------------------------------------------------------------------------------- /rz-core/mycat/server.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 12 | 13 | druidparser 14 | 15 | 16 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 33 | 34 | 38 | 40 | 42 | 43 | eros 44 | scaffold 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /rz-core/pom-gen.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | 7 | com.rick 8 | scaffold 9 | 1.1.0 10 | 11 | 12 | rz-core 13 | jar 14 | 15 | rz-core 16 | http://www.rick.com 17 | 2015-2020 18 | 19 | 20 | 21 | 22 | 23 | 24 | org.mybatis.generator 25 | mybatis-generator-maven-plugin 26 | 1.3.2 27 | 28 | src/main/resources/mybatis-generator/generatorConfig.xml 29 | true 30 | true 31 | 32 | 33 | 34 | Generate MyBatis Artifacts 35 | 36 | generate 37 | 38 | 39 | 40 | 41 | 42 | org.mybatis.generator 43 | mybatis-generator-core 44 | 1.3.2 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | -------------------------------------------------------------------------------- /rz-core/src/main/java/com/rick/scaffold/common/Constants.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.common; 2 | 3 | 4 | public interface Constants { 5 | 6 | String HTTP_STATUS_OK = "OK"; 7 | String HTTP_STATUS_ERROR = "Error"; 8 | 9 | String STRING_SEPERATOR = "!@#"; 10 | String SEARCH_INDICE = "scaffold"; 11 | } 12 | -------------------------------------------------------------------------------- /rz-core/src/main/java/com/rick/scaffold/common/persistence/annotation/MyBatisDao.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.common.persistence.annotation; 2 | 3 | import java.lang.annotation.Documented; 4 | import java.lang.annotation.ElementType; 5 | import java.lang.annotation.Retention; 6 | import java.lang.annotation.RetentionPolicy; 7 | import java.lang.annotation.Target; 8 | 9 | import org.springframework.stereotype.Component; 10 | 11 | /** 12 | * 标识MyBatis的DAO,方便{@link org.mybatis.spring.mapper.MapperScannerConfigurer}的扫描。 13 | */ 14 | @Retention(RetentionPolicy.RUNTIME) 15 | @Target(ElementType.TYPE) 16 | @Documented 17 | @Component 18 | public @interface MyBatisDao { 19 | 20 | /** 21 | * The value may indicate a suggestion for a logical component name, 22 | * to be turned into a Spring bean in case of an autodetected component. 23 | * @return the suggested component name, if any 24 | */ 25 | String value() default ""; 26 | 27 | } -------------------------------------------------------------------------------- /rz-core/src/main/java/com/rick/scaffold/common/utils/CacheUtils.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.common.utils; 2 | 3 | import net.sf.ehcache.Cache; 4 | import net.sf.ehcache.CacheManager; 5 | import net.sf.ehcache.Element; 6 | 7 | /** 8 | * Cache工具类 9 | * 10 | */ 11 | public class CacheUtils { 12 | 13 | private static CacheManager cacheManager = ((CacheManager)SpringContextHolder.getBean("cacheManager")); 14 | 15 | private static final String SYS_CACHE = "sysCache"; 16 | 17 | /** 18 | * 获取SYS_CACHE缓存 19 | * @param key 20 | * @return 21 | */ 22 | public static Object get(String key) { 23 | return get(SYS_CACHE, key); 24 | } 25 | 26 | /** 27 | * 写入SYS_CACHE缓存 28 | * @param key 29 | * @return 30 | */ 31 | public static void put(String key, Object value) { 32 | put(SYS_CACHE, key, value); 33 | } 34 | 35 | /** 36 | * 从SYS_CACHE缓存中移除 37 | * @param key 38 | * @return 39 | */ 40 | public static void remove(String key) { 41 | remove(SYS_CACHE, key); 42 | } 43 | 44 | /** 45 | * 获取缓存 46 | * @param cacheName 47 | * @param key 48 | * @return 49 | */ 50 | public static Object get(String cacheName, String key) { 51 | Element element = getCache(cacheName).get(key); 52 | return element==null?null:element.getObjectValue(); 53 | } 54 | 55 | /** 56 | * 写入缓存 57 | * @param cacheName 58 | * @param key 59 | * @param value 60 | */ 61 | public static void put(String cacheName, String key, Object value) { 62 | Element element = new Element(key, value); 63 | getCache(cacheName).put(element); 64 | } 65 | 66 | /** 67 | * 从缓存中移除 68 | * @param cacheName 69 | * @param key 70 | */ 71 | public static void remove(String cacheName, String key) { 72 | getCache(cacheName).remove(key); 73 | } 74 | 75 | /** 76 | * 获得一个Cache,没有则创建一个。 77 | * @param cacheName 78 | * @return 79 | */ 80 | private static Cache getCache(String cacheName){ 81 | Cache cache = cacheManager.getCache(cacheName); 82 | if (cache == null){ 83 | cacheManager.addCache(cacheName); 84 | cache = cacheManager.getCache(cacheName); 85 | cache.getCacheConfiguration().setEternal(true); 86 | } 87 | return cache; 88 | } 89 | 90 | public static CacheManager getCacheManager() { 91 | return cacheManager; 92 | } 93 | 94 | } 95 | -------------------------------------------------------------------------------- /rz-core/src/main/java/com/rick/scaffold/common/utils/ExceptionUtils.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.common.utils; 2 | 3 | import java.util.UUID; 4 | 5 | public class ExceptionUtils { 6 | 7 | public static String getTrackID() { 8 | return UUID.randomUUID().toString(); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /rz-core/src/main/java/com/rick/scaffold/core/dao/address/AddressDao.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.core.dao.address; 2 | 3 | import com.rick.scaffold.common.persistence.annotation.MyBatisDao; 4 | import com.rick.scaffold.core.dao.generic.CrudDao; 5 | import com.rick.scaffold.core.entity.address.Address; 6 | 7 | @MyBatisDao 8 | public interface AddressDao extends CrudDao
{ 9 | 10 | } -------------------------------------------------------------------------------- /rz-core/src/main/java/com/rick/scaffold/core/dao/address/RegionDao.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.core.dao.address; 2 | 3 | import com.rick.scaffold.common.persistence.annotation.MyBatisDao; 4 | import com.rick.scaffold.core.dao.generic.BaseDao; 5 | import com.rick.scaffold.core.entity.address.Region; 6 | 7 | @MyBatisDao 8 | public interface RegionDao extends BaseDao { 9 | 10 | } -------------------------------------------------------------------------------- /rz-core/src/main/java/com/rick/scaffold/core/dao/admin/AdminDao.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.core.dao.admin; 2 | 3 | import com.rick.scaffold.common.persistence.annotation.MyBatisDao; 4 | import com.rick.scaffold.core.dao.generic.CrudDao; 5 | import com.rick.scaffold.core.entity.admin.Admin; 6 | 7 | @MyBatisDao 8 | public interface AdminDao extends CrudDao { 9 | 10 | } -------------------------------------------------------------------------------- /rz-core/src/main/java/com/rick/scaffold/core/dao/cart/CartDao.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.core.dao.cart; 2 | 3 | import com.rick.scaffold.common.persistence.annotation.MyBatisDao; 4 | import com.rick.scaffold.core.dao.generic.CrudDao; 5 | import com.rick.scaffold.core.entity.cart.Cart; 6 | 7 | @MyBatisDao 8 | public interface CartDao extends CrudDao { 9 | 10 | } -------------------------------------------------------------------------------- /rz-core/src/main/java/com/rick/scaffold/core/dao/cart/CartItemDao.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.core.dao.cart; 2 | 3 | import com.rick.scaffold.common.persistence.annotation.MyBatisDao; 4 | import com.rick.scaffold.core.dao.generic.BaseDao; 5 | import com.rick.scaffold.core.entity.cart.CartItem; 6 | 7 | @MyBatisDao 8 | public interface CartItemDao extends BaseDao { 9 | 10 | } -------------------------------------------------------------------------------- /rz-core/src/main/java/com/rick/scaffold/core/dao/generic/BaseDao.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.core.dao.generic; 2 | 3 | import java.util.List; 4 | 5 | /** 6 | * DAO支持类实现 7 | */ 8 | public interface BaseDao { 9 | 10 | /** 11 | * 获取单条数据 12 | * @param id 13 | * @return 14 | */ 15 | public T findOne(Long id); 16 | 17 | /** 18 | * @param entity 19 | * @return 20 | */ 21 | public List findAll(); 22 | 23 | /** 24 | * 插入数据 25 | * @param entity 26 | * @return 27 | */ 28 | public int insert(T entity); 29 | 30 | /** 31 | * 更新数据 32 | * @param entity 33 | * @return 34 | */ 35 | public int update(T entity); 36 | 37 | /** 38 | * 删除数据(一般为逻辑删除,更新del_flag字段为1) 39 | * @param id 40 | * @see public int delete(T entity) 41 | * @return 42 | */ 43 | public int delete(Long id); 44 | } -------------------------------------------------------------------------------- /rz-core/src/main/java/com/rick/scaffold/core/dao/generic/CrudDao.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.core.dao.generic; 2 | 3 | 4 | /** 5 | * DAO支持类实现 6 | * @param 7 | */ 8 | public interface CrudDao extends BaseDao { 9 | 10 | } -------------------------------------------------------------------------------- /rz-core/src/main/java/com/rick/scaffold/core/dao/goods/CategoryDao.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.core.dao.goods; 2 | 3 | import com.rick.scaffold.common.persistence.annotation.MyBatisDao; 4 | import com.rick.scaffold.core.dao.generic.CrudDao; 5 | import com.rick.scaffold.core.entity.goods.Category; 6 | 7 | @MyBatisDao 8 | public interface CategoryDao extends CrudDao { 9 | 10 | } -------------------------------------------------------------------------------- /rz-core/src/main/java/com/rick/scaffold/core/dao/goods/GoodsDao.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.core.dao.goods; 2 | 3 | import com.rick.scaffold.common.persistence.annotation.MyBatisDao; 4 | import com.rick.scaffold.core.dao.generic.CrudDao; 5 | import com.rick.scaffold.core.entity.goods.Goods; 6 | 7 | @MyBatisDao 8 | public interface GoodsDao extends CrudDao { 9 | 10 | } -------------------------------------------------------------------------------- /rz-core/src/main/java/com/rick/scaffold/core/dao/goods/GoodsGalleryDao.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.core.dao.goods; 2 | 3 | import com.rick.scaffold.common.persistence.annotation.MyBatisDao; 4 | import com.rick.scaffold.core.dao.generic.BaseDao; 5 | import com.rick.scaffold.core.entity.goods.GoodsGallery; 6 | 7 | @MyBatisDao 8 | public interface GoodsGalleryDao extends BaseDao { 9 | 10 | } -------------------------------------------------------------------------------- /rz-core/src/main/java/com/rick/scaffold/core/dao/order/OrderDao.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.core.dao.order; 2 | 3 | import com.rick.scaffold.common.persistence.annotation.MyBatisDao; 4 | import com.rick.scaffold.core.dao.generic.CrudDao; 5 | import com.rick.scaffold.core.entity.order.Order; 6 | 7 | @MyBatisDao 8 | public interface OrderDao extends CrudDao { 9 | 10 | } -------------------------------------------------------------------------------- /rz-core/src/main/java/com/rick/scaffold/core/dao/order/OrderItemDao.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.core.dao.order; 2 | 3 | import com.rick.scaffold.common.persistence.annotation.MyBatisDao; 4 | import com.rick.scaffold.core.dao.generic.BaseDao; 5 | import com.rick.scaffold.core.entity.order.OrderItem; 6 | 7 | @MyBatisDao 8 | public interface OrderItemDao extends BaseDao { 9 | 10 | } -------------------------------------------------------------------------------- /rz-core/src/main/java/com/rick/scaffold/core/dao/product/ProductDao.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.core.dao.product; 2 | 3 | import com.rick.scaffold.common.persistence.annotation.MyBatisDao; 4 | import com.rick.scaffold.core.dao.generic.CrudDao; 5 | import com.rick.scaffold.core.entity.product.Product; 6 | 7 | @MyBatisDao 8 | public interface ProductDao extends CrudDao { 9 | 10 | } -------------------------------------------------------------------------------- /rz-core/src/main/java/com/rick/scaffold/core/dao/shop/ShopDao.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.core.dao.shop; 2 | 3 | import com.rick.scaffold.common.persistence.annotation.MyBatisDao; 4 | import com.rick.scaffold.core.dao.generic.CrudDao; 5 | import com.rick.scaffold.core.entity.shop.Shop; 6 | 7 | @MyBatisDao 8 | public interface ShopDao extends CrudDao { 9 | 10 | } -------------------------------------------------------------------------------- /rz-core/src/main/java/com/rick/scaffold/core/dao/user/CompanyDao.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.core.dao.user; 2 | 3 | import com.rick.scaffold.common.persistence.annotation.MyBatisDao; 4 | import com.rick.scaffold.core.dao.generic.BaseDao; 5 | import com.rick.scaffold.core.entity.user.Company; 6 | 7 | @MyBatisDao 8 | public interface CompanyDao extends BaseDao { 9 | 10 | } -------------------------------------------------------------------------------- /rz-core/src/main/java/com/rick/scaffold/core/dao/user/PhotoDao.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.core.dao.user; 2 | 3 | import com.rick.scaffold.common.persistence.annotation.MyBatisDao; 4 | import com.rick.scaffold.core.dao.generic.BaseDao; 5 | import com.rick.scaffold.core.entity.user.Photo; 6 | 7 | @MyBatisDao 8 | public interface PhotoDao extends BaseDao { 9 | 10 | } -------------------------------------------------------------------------------- /rz-core/src/main/java/com/rick/scaffold/core/dao/user/UserDao.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.core.dao.user; 2 | 3 | import java.util.List; 4 | 5 | import org.apache.ibatis.annotations.Param; 6 | 7 | import com.rick.scaffold.common.persistence.annotation.MyBatisDao; 8 | import com.rick.scaffold.core.dao.generic.CrudDao; 9 | import com.rick.scaffold.core.entity.user.FullUser; 10 | import com.rick.scaffold.core.entity.user.User; 11 | 12 | @MyBatisDao 13 | public interface UserDao extends CrudDao { 14 | 15 | User findOne1(@Param("id") Long id, @Param("name") String name); 16 | 17 | List findCascade(Long id); 18 | 19 | List findLazy(Long id); 20 | 21 | User findByName(String name); 22 | } -------------------------------------------------------------------------------- /rz-core/src/main/java/com/rick/scaffold/core/dao/user/UsersDao.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.core.dao.user; 2 | 3 | import com.rick.scaffold.common.persistence.annotation.MyBatisDao; 4 | import com.rick.scaffold.core.dao.generic.CrudDao; 5 | import com.rick.scaffold.core.entity.user.Users; 6 | 7 | @MyBatisDao 8 | public interface UsersDao extends CrudDao { 9 | 10 | Users findByName(String name); 11 | } -------------------------------------------------------------------------------- /rz-core/src/main/java/com/rick/scaffold/core/entity/address/Address.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.core.entity.address; 2 | 3 | import com.rick.scaffold.core.entity.generic.DataEntity; 4 | 5 | public class Address extends DataEntity
{ 6 | 7 | private String addressName; 8 | 9 | private Long userId; 10 | 11 | private String consignee; 12 | 13 | private String email; 14 | 15 | private Integer province; 16 | 17 | private Integer city; 18 | 19 | private Integer district; 20 | 21 | private String fullAddress; 22 | 23 | private String zipcode; 24 | 25 | private String mobile; 26 | 27 | 28 | public String getAddressName() { 29 | return addressName; 30 | } 31 | 32 | public void setAddressName(String addressName) { 33 | this.addressName = addressName == null ? null : addressName.trim(); 34 | } 35 | 36 | public Long getUserId() { 37 | return userId; 38 | } 39 | 40 | public void setUserId(Long userId) { 41 | this.userId = userId; 42 | } 43 | 44 | public String getConsignee() { 45 | return consignee; 46 | } 47 | 48 | public void setConsignee(String consignee) { 49 | this.consignee = consignee == null ? null : consignee.trim(); 50 | } 51 | 52 | public String getEmail() { 53 | return email; 54 | } 55 | 56 | public void setEmail(String email) { 57 | this.email = email == null ? null : email.trim(); 58 | } 59 | 60 | public Integer getProvince() { 61 | return province; 62 | } 63 | 64 | public void setProvince(Integer province) { 65 | this.province = province; 66 | } 67 | 68 | public Integer getCity() { 69 | return city; 70 | } 71 | 72 | public void setCity(Integer city) { 73 | this.city = city; 74 | } 75 | 76 | public Integer getDistrict() { 77 | return district; 78 | } 79 | 80 | public void setDistrict(Integer district) { 81 | this.district = district; 82 | } 83 | 84 | public String getFullAddress() { 85 | return fullAddress; 86 | } 87 | 88 | public void setFullAddress(String fullAddress) { 89 | this.fullAddress = fullAddress == null ? null : fullAddress.trim(); 90 | } 91 | 92 | public String getZipcode() { 93 | return zipcode; 94 | } 95 | 96 | public void setZipcode(String zipcode) { 97 | this.zipcode = zipcode == null ? null : zipcode.trim(); 98 | } 99 | 100 | public String getMobile() { 101 | return mobile; 102 | } 103 | 104 | public void setMobile(String mobile) { 105 | this.mobile = mobile == null ? null : mobile.trim(); 106 | } 107 | } -------------------------------------------------------------------------------- /rz-core/src/main/java/com/rick/scaffold/core/entity/address/Region.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.core.entity.address; 2 | 3 | import com.rick.scaffold.core.entity.generic.BaseEntity; 4 | 5 | public class Region extends BaseEntity { 6 | 7 | private Integer parentId; 8 | 9 | private String regionName; 10 | 11 | private Byte regionType; 12 | 13 | 14 | public Integer getParentId() { 15 | return parentId; 16 | } 17 | 18 | public void setParentId(Integer parentId) { 19 | this.parentId = parentId; 20 | } 21 | 22 | public String getRegionName() { 23 | return regionName; 24 | } 25 | 26 | public void setRegionName(String regionName) { 27 | this.regionName = regionName == null ? null : regionName.trim(); 28 | } 29 | 30 | public Byte getRegionType() { 31 | return regionType; 32 | } 33 | 34 | public void setRegionType(Byte regionType) { 35 | this.regionType = regionType; 36 | } 37 | } -------------------------------------------------------------------------------- /rz-core/src/main/java/com/rick/scaffold/core/entity/admin/Admin.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.core.entity.admin; 2 | 3 | import com.rick.scaffold.core.entity.generic.DataEntity; 4 | 5 | public class Admin extends DataEntity { 6 | 7 | private String username; 8 | 9 | private String password; 10 | 11 | private String nickName; 12 | 13 | private String mobile; 14 | 15 | private String avatar; 16 | 17 | private String email; 18 | 19 | private Byte role; 20 | 21 | private Long shopId; 22 | 23 | public String getUsername() { 24 | return username; 25 | } 26 | 27 | public void setUsername(String username) { 28 | this.username = username == null ? null : username.trim(); 29 | } 30 | 31 | public String getPassword() { 32 | return password; 33 | } 34 | 35 | public void setPassword(String password) { 36 | this.password = password == null ? null : password.trim(); 37 | } 38 | 39 | public String getNickName() { 40 | return nickName; 41 | } 42 | 43 | public void setNickName(String nickName) { 44 | this.nickName = nickName == null ? null : nickName.trim(); 45 | } 46 | 47 | public String getMobile() { 48 | return mobile; 49 | } 50 | 51 | public void setMobile(String mobile) { 52 | this.mobile = mobile == null ? null : mobile.trim(); 53 | } 54 | 55 | public String getAvatar() { 56 | return avatar; 57 | } 58 | 59 | public void setAvatar(String avatar) { 60 | this.avatar = avatar == null ? null : avatar.trim(); 61 | } 62 | 63 | public String getEmail() { 64 | return email; 65 | } 66 | 67 | public void setEmail(String email) { 68 | this.email = email == null ? null : email.trim(); 69 | } 70 | 71 | public Byte getRole() { 72 | return role; 73 | } 74 | 75 | public void setRole(Byte role) { 76 | this.role = role; 77 | } 78 | 79 | public Long getShopId() { 80 | return shopId; 81 | } 82 | 83 | public void setShopId(Long shopId) { 84 | this.shopId = shopId; 85 | } 86 | } -------------------------------------------------------------------------------- /rz-core/src/main/java/com/rick/scaffold/core/entity/cart/Cart.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.core.entity.cart; 2 | 3 | import com.rick.scaffold.core.entity.generic.DataEntity; 4 | 5 | import java.math.BigDecimal; 6 | 7 | public class Cart extends DataEntity { 8 | 9 | private Long userId; 10 | 11 | private Long shopId; 12 | 13 | private BigDecimal productPrice; 14 | 15 | public Long getUserId() { 16 | return userId; 17 | } 18 | 19 | public void setUserId(Long userId) { 20 | this.userId = userId; 21 | } 22 | 23 | public Long getShopId() { 24 | return shopId; 25 | } 26 | 27 | public void setShopId(Long shopId) { 28 | this.shopId = shopId; 29 | } 30 | 31 | public BigDecimal getProductPrice() { 32 | return productPrice; 33 | } 34 | 35 | public void setProductPrice(BigDecimal productPrice) { 36 | this.productPrice = productPrice; 37 | } 38 | } -------------------------------------------------------------------------------- /rz-core/src/main/java/com/rick/scaffold/core/entity/cart/CartItem.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.core.entity.cart; 2 | 3 | import com.rick.scaffold.core.entity.generic.BaseEntity; 4 | 5 | import java.math.BigDecimal; 6 | 7 | public class CartItem extends BaseEntity { 8 | 9 | private Long cartId; 10 | 11 | private Long goodsId; 12 | 13 | private String goodsName; 14 | 15 | private String goodsSn; 16 | 17 | private Integer goodsAmount; 18 | 19 | private String unit; 20 | 21 | private BigDecimal marketPrice; 22 | 23 | private BigDecimal goodsPrice; 24 | 25 | private Long shopId; 26 | 27 | 28 | public Long getCartId() { 29 | return cartId; 30 | } 31 | 32 | public void setCartId(Long cartId) { 33 | this.cartId = cartId; 34 | } 35 | 36 | public Long getGoodsId() { 37 | return goodsId; 38 | } 39 | 40 | public void setGoodsId(Long goodsId) { 41 | this.goodsId = goodsId; 42 | } 43 | 44 | public String getGoodsName() { 45 | return goodsName; 46 | } 47 | 48 | public void setGoodsName(String goodsName) { 49 | this.goodsName = goodsName == null ? null : goodsName.trim(); 50 | } 51 | 52 | public String getGoodsSn() { 53 | return goodsSn; 54 | } 55 | 56 | public void setGoodsSn(String goodsSn) { 57 | this.goodsSn = goodsSn == null ? null : goodsSn.trim(); 58 | } 59 | 60 | public Integer getGoodsAmount() { 61 | return goodsAmount; 62 | } 63 | 64 | public void setGoodsAmount(Integer goodsAmount) { 65 | this.goodsAmount = goodsAmount; 66 | } 67 | 68 | public String getUnit() { 69 | return unit; 70 | } 71 | 72 | public void setUnit(String unit) { 73 | this.unit = unit == null ? null : unit.trim(); 74 | } 75 | 76 | public BigDecimal getMarketPrice() { 77 | return marketPrice; 78 | } 79 | 80 | public void setMarketPrice(BigDecimal marketPrice) { 81 | this.marketPrice = marketPrice; 82 | } 83 | 84 | public BigDecimal getGoodsPrice() { 85 | return goodsPrice; 86 | } 87 | 88 | public void setGoodsPrice(BigDecimal goodsPrice) { 89 | this.goodsPrice = goodsPrice; 90 | } 91 | 92 | public Long getShopId() { 93 | return shopId; 94 | } 95 | 96 | public void setShopId(Long shopId) { 97 | this.shopId = shopId; 98 | } 99 | } -------------------------------------------------------------------------------- /rz-core/src/main/java/com/rick/scaffold/core/entity/generic/BaseEntity.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.core.entity.generic; 2 | 3 | import java.io.Serializable; 4 | 5 | import org.apache.commons.lang3.builder.ReflectionToStringBuilder; 6 | 7 | import com.fasterxml.jackson.annotation.JsonProperty; 8 | import com.rick.scaffold.common.persistence.tool.IncrSequenceTimeHandler; 9 | 10 | /** 11 | * Entity支持类 12 | */ 13 | public abstract class BaseEntity implements Serializable { 14 | 15 | private static final long serialVersionUID = 1L; 16 | 17 | /** 18 | * 实体编号(唯一标识) 19 | */ 20 | @JsonProperty("_id") 21 | protected Long id; 22 | 23 | 24 | public BaseEntity() { 25 | 26 | } 27 | 28 | public BaseEntity(Long id) { 29 | this(); 30 | this.id = id; 31 | } 32 | 33 | /** 34 | * 插入之前执行方法,需要手动调用 35 | */ 36 | public void preInsert(){ 37 | this.id = IncrSequenceTimeHandler.getInstance().nextId(); 38 | } 39 | 40 | public Long getId() { 41 | return id; 42 | } 43 | 44 | public void setId(Long id) { 45 | this.id = id; 46 | } 47 | 48 | 49 | @Override 50 | public boolean equals(Object obj) { 51 | if (null == obj) { 52 | return false; 53 | } 54 | if (this == obj) { 55 | return true; 56 | } 57 | if (!getClass().equals(obj.getClass())) { 58 | return false; 59 | } 60 | BaseEntity that = (BaseEntity) obj; 61 | return null == this.getId() ? false : this.getId().equals(that.getId()); 62 | } 63 | 64 | @Override 65 | public String toString() { 66 | return ReflectionToStringBuilder.toString(this); 67 | } 68 | 69 | } 70 | 71 | -------------------------------------------------------------------------------- /rz-core/src/main/java/com/rick/scaffold/core/entity/generic/DataEntity.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.core.entity.generic; 2 | 3 | import java.util.Date; 4 | 5 | import com.fasterxml.jackson.annotation.JsonFormat; 6 | import com.fasterxml.jackson.annotation.JsonIgnore; 7 | 8 | /** 9 | * 数据Entity类 10 | * 11 | */ 12 | public abstract class DataEntity extends BaseEntity { 13 | 14 | private static final long serialVersionUID = 1L; 15 | 16 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") 17 | protected Date createDate; // 创建日期 18 | 19 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") 20 | protected Date modifyDate; // 更新日期 21 | 22 | @JsonIgnore 23 | protected Boolean delFlag = false; // 删除标记(false:正常;true:删除;) 24 | 25 | public DataEntity() { 26 | super(); 27 | } 28 | 29 | public DataEntity(Long id) { 30 | super(id); 31 | } 32 | 33 | /** 34 | * 插入之前执行方法,需要手动调用 35 | */ 36 | @Override 37 | public void preInsert(){ 38 | super.preInsert(); 39 | this.modifyDate = new Date(); 40 | this.createDate = this.modifyDate; 41 | } 42 | 43 | /** 44 | * 更新之前执行方法,需要手动调用 45 | */ 46 | public void preUpdate(){ 47 | this.modifyDate = new Date(); 48 | } 49 | 50 | public Date getCreateDate() { 51 | return createDate; 52 | } 53 | 54 | public void setCreateDate(Date createDate) { 55 | this.createDate = createDate; 56 | } 57 | 58 | public Date getModifyDate() { 59 | return modifyDate; 60 | } 61 | 62 | public void setModifyDate(Date modifyDate) { 63 | this.modifyDate = modifyDate; 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /rz-core/src/main/java/com/rick/scaffold/core/entity/goods/Category.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.core.entity.goods; 2 | 3 | import com.rick.scaffold.core.entity.generic.DataEntity; 4 | 5 | public class Category extends DataEntity { 6 | 7 | private String name; 8 | 9 | private String desc; 10 | 11 | private String cateImage; 12 | 13 | private Long parentId; 14 | 15 | private Boolean showInNav; 16 | 17 | private Boolean isShow; 18 | 19 | private Long shopId; 20 | 21 | private Byte level; 22 | 23 | 24 | public String getName() { 25 | return name; 26 | } 27 | 28 | public void setName(String name) { 29 | this.name = name == null ? null : name.trim(); 30 | } 31 | 32 | public String getDesc() { 33 | return desc; 34 | } 35 | 36 | public void setDesc(String desc) { 37 | this.desc = desc == null ? null : desc.trim(); 38 | } 39 | 40 | public String getCateImage() { 41 | return cateImage; 42 | } 43 | 44 | public void setCateImage(String cateImage) { 45 | this.cateImage = cateImage == null ? null : cateImage.trim(); 46 | } 47 | 48 | public Long getParentId() { 49 | return parentId; 50 | } 51 | 52 | public void setParentId(Long parentId) { 53 | this.parentId = parentId; 54 | } 55 | 56 | public Boolean getShowInNav() { 57 | return showInNav; 58 | } 59 | 60 | public void setShowInNav(Boolean showInNav) { 61 | this.showInNav = showInNav; 62 | } 63 | 64 | public Boolean getIsShow() { 65 | return isShow; 66 | } 67 | 68 | public void setIsShow(Boolean isShow) { 69 | this.isShow = isShow; 70 | } 71 | 72 | public Long getShopId() { 73 | return shopId; 74 | } 75 | 76 | public void setShopId(Long shopId) { 77 | this.shopId = shopId; 78 | } 79 | 80 | public Byte getLevel() { 81 | return level; 82 | } 83 | 84 | public void setLevel(Byte level) { 85 | this.level = level; 86 | } 87 | } -------------------------------------------------------------------------------- /rz-core/src/main/java/com/rick/scaffold/core/entity/goods/GoodsGallery.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.core.entity.goods; 2 | 3 | import com.rick.scaffold.core.entity.generic.BaseEntity; 4 | 5 | public class GoodsGallery extends BaseEntity { 6 | 7 | private Long goodsId; 8 | 9 | private String imgUrl; 10 | 11 | private String imgDesc; 12 | 13 | private Byte imgType; 14 | 15 | 16 | 17 | public Long getGoodsId() { 18 | return goodsId; 19 | } 20 | 21 | public void setGoodsId(Long goodsId) { 22 | this.goodsId = goodsId; 23 | } 24 | 25 | public String getImgUrl() { 26 | return imgUrl; 27 | } 28 | 29 | public void setImgUrl(String imgUrl) { 30 | this.imgUrl = imgUrl == null ? null : imgUrl.trim(); 31 | } 32 | 33 | public String getImgDesc() { 34 | return imgDesc; 35 | } 36 | 37 | public void setImgDesc(String imgDesc) { 38 | this.imgDesc = imgDesc == null ? null : imgDesc.trim(); 39 | } 40 | 41 | public Byte getImgType() { 42 | return imgType; 43 | } 44 | 45 | public void setImgType(Byte imgType) { 46 | this.imgType = imgType; 47 | } 48 | } -------------------------------------------------------------------------------- /rz-core/src/main/java/com/rick/scaffold/core/entity/order/OrderItem.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.core.entity.order; 2 | 3 | import com.rick.scaffold.core.entity.generic.BaseEntity; 4 | 5 | import java.math.BigDecimal; 6 | 7 | public class OrderItem extends BaseEntity { 8 | 9 | private Long orderId; 10 | 11 | private Long goodsId; 12 | 13 | private String goodsName; 14 | 15 | private String goodsSn; 16 | 17 | private Integer goodsAmount; 18 | 19 | private String unit; 20 | 21 | private BigDecimal marketPrice; 22 | 23 | private BigDecimal goodsPrice; 24 | 25 | private Long shopId; 26 | 27 | 28 | 29 | public Long getOrderId() { 30 | return orderId; 31 | } 32 | 33 | public void setOrderId(Long orderId) { 34 | this.orderId = orderId; 35 | } 36 | 37 | public Long getGoodsId() { 38 | return goodsId; 39 | } 40 | 41 | public void setGoodsId(Long goodsId) { 42 | this.goodsId = goodsId; 43 | } 44 | 45 | public String getGoodsName() { 46 | return goodsName; 47 | } 48 | 49 | public void setGoodsName(String goodsName) { 50 | this.goodsName = goodsName == null ? null : goodsName.trim(); 51 | } 52 | 53 | public String getGoodsSn() { 54 | return goodsSn; 55 | } 56 | 57 | public void setGoodsSn(String goodsSn) { 58 | this.goodsSn = goodsSn == null ? null : goodsSn.trim(); 59 | } 60 | 61 | public Integer getGoodsAmount() { 62 | return goodsAmount; 63 | } 64 | 65 | public void setGoodsAmount(Integer goodsAmount) { 66 | this.goodsAmount = goodsAmount; 67 | } 68 | 69 | public String getUnit() { 70 | return unit; 71 | } 72 | 73 | public void setUnit(String unit) { 74 | this.unit = unit == null ? null : unit.trim(); 75 | } 76 | 77 | public BigDecimal getMarketPrice() { 78 | return marketPrice; 79 | } 80 | 81 | public void setMarketPrice(BigDecimal marketPrice) { 82 | this.marketPrice = marketPrice; 83 | } 84 | 85 | public BigDecimal getGoodsPrice() { 86 | return goodsPrice; 87 | } 88 | 89 | public void setGoodsPrice(BigDecimal goodsPrice) { 90 | this.goodsPrice = goodsPrice; 91 | } 92 | 93 | public Long getShopId() { 94 | return shopId; 95 | } 96 | 97 | public void setShopId(Long shopId) { 98 | this.shopId = shopId; 99 | } 100 | } -------------------------------------------------------------------------------- /rz-core/src/main/java/com/rick/scaffold/core/entity/product/Product.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.core.entity.product; 2 | 3 | import java.math.BigDecimal; 4 | 5 | import com.rick.scaffold.core.entity.generic.DataEntity; 6 | 7 | public class Product extends DataEntity { 8 | 9 | /** 10 | * 11 | */ 12 | private static final long serialVersionUID = 1L; 13 | 14 | private String image; 15 | 16 | private String remark; 17 | 18 | private String name; 19 | 20 | private BigDecimal price; 21 | 22 | private String sn; 23 | 24 | private String unit; 25 | 26 | private Float amount; 27 | 28 | public String getImage() { 29 | return image; 30 | } 31 | 32 | public void setImage(String image) { 33 | this.image = image == null ? null : image.trim(); 34 | } 35 | 36 | public String getRemark() { 37 | return remark; 38 | } 39 | 40 | public void setRemark(String remark) { 41 | this.remark = remark == null ? null : remark.trim(); 42 | } 43 | 44 | public String getName() { 45 | return name; 46 | } 47 | 48 | public void setName(String name) { 49 | this.name = name == null ? null : name.trim(); 50 | } 51 | 52 | public BigDecimal getPrice() { 53 | return price; 54 | } 55 | 56 | public void setPrice(BigDecimal price) { 57 | this.price = price; 58 | } 59 | 60 | public String getSn() { 61 | return sn; 62 | } 63 | 64 | public void setSn(String sn) { 65 | this.sn = sn == null ? null : sn.trim(); 66 | } 67 | 68 | public String getUnit() { 69 | return unit; 70 | } 71 | 72 | public void setUnit(String unit) { 73 | this.unit = unit == null ? null : unit.trim(); 74 | } 75 | 76 | public Float getAmount() { 77 | return amount; 78 | } 79 | 80 | public void setAmount(Float amount) { 81 | this.amount = amount; 82 | } 83 | } -------------------------------------------------------------------------------- /rz-core/src/main/java/com/rick/scaffold/core/entity/shop/Shop.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.core.entity.shop; 2 | 3 | import com.rick.scaffold.core.entity.generic.DataEntity; 4 | 5 | public class Shop extends DataEntity { 6 | 7 | private String shopName; 8 | 9 | private String shopImage; 10 | 11 | private String phone; 12 | 13 | private String address; 14 | 15 | 16 | public String getShopName() { 17 | return shopName; 18 | } 19 | 20 | public void setShopName(String shopName) { 21 | this.shopName = shopName == null ? null : shopName.trim(); 22 | } 23 | 24 | public String getShopImage() { 25 | return shopImage; 26 | } 27 | 28 | public void setShopImage(String shopImage) { 29 | this.shopImage = shopImage == null ? null : shopImage.trim(); 30 | } 31 | 32 | public String getPhone() { 33 | return phone; 34 | } 35 | 36 | public void setPhone(String phone) { 37 | this.phone = phone == null ? null : phone.trim(); 38 | } 39 | 40 | public String getAddress() { 41 | return address; 42 | } 43 | 44 | public void setAddress(String address) { 45 | this.address = address == null ? null : address.trim(); 46 | } 47 | } -------------------------------------------------------------------------------- /rz-core/src/main/java/com/rick/scaffold/core/entity/user/Company.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.core.entity.user; 2 | 3 | import com.rick.scaffold.core.entity.generic.BaseEntity; 4 | 5 | public class Company extends BaseEntity { 6 | 7 | private static final long serialVersionUID = 1L; 8 | 9 | private String name; 10 | private String phone; 11 | 12 | public String getName() { 13 | return name; 14 | } 15 | public void setName(String name) { 16 | this.name = name; 17 | } 18 | public String getPhone() { 19 | return phone; 20 | } 21 | public void setPhone(String phone) { 22 | this.phone = phone; 23 | } 24 | 25 | 26 | } 27 | -------------------------------------------------------------------------------- /rz-core/src/main/java/com/rick/scaffold/core/entity/user/FullUser.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.core.entity.user; 2 | 3 | import java.util.List; 4 | 5 | public class FullUser extends User { 6 | 7 | /** 8 | * 9 | */ 10 | private static final long serialVersionUID = 1L; 11 | 12 | private Company company; 13 | private List photos; 14 | 15 | public Company getCompany() { 16 | return company; 17 | } 18 | public void setCompany(Company company) { 19 | this.company = company; 20 | } 21 | public List getPhotos() { 22 | return photos; 23 | } 24 | public void setPhotos(List photos) { 25 | this.photos = photos; 26 | } 27 | 28 | 29 | } 30 | -------------------------------------------------------------------------------- /rz-core/src/main/java/com/rick/scaffold/core/entity/user/Photo.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.core.entity.user; 2 | 3 | import com.rick.scaffold.core.entity.generic.BaseEntity; 4 | 5 | public class Photo extends BaseEntity { 6 | 7 | /** 8 | * 9 | */ 10 | private static final long serialVersionUID = 1L; 11 | 12 | private String url; 13 | private int size; 14 | private Long userId; 15 | 16 | 17 | 18 | public Long getUserId() { 19 | return userId; 20 | } 21 | public void setUserId(Long userId) { 22 | this.userId = userId; 23 | } 24 | public String getUrl() { 25 | return url; 26 | } 27 | public void setUrl(String url) { 28 | this.url = url; 29 | } 30 | public int getSize() { 31 | return size; 32 | } 33 | public void setSize(int size) { 34 | this.size = size; 35 | } 36 | 37 | 38 | } 39 | -------------------------------------------------------------------------------- /rz-core/src/main/java/com/rick/scaffold/core/entity/user/User.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.core.entity.user; 2 | 3 | import java.util.Date; 4 | 5 | import com.rick.scaffold.core.entity.generic.DataEntity; 6 | 7 | public class User extends DataEntity { 8 | 9 | /** 10 | * 11 | */ 12 | private static final long serialVersionUID = 1L; 13 | 14 | private String loginName; 15 | 16 | private String password; 17 | 18 | private String name; 19 | 20 | private String email; 21 | 22 | private String phone; 23 | 24 | private Long userTag; 25 | 26 | private String avatar; 27 | 28 | private String loginIp; 29 | 30 | private Date loginDate; 31 | 32 | private Long companyId; 33 | 34 | 35 | 36 | public Long getCompanyId() { 37 | return companyId; 38 | } 39 | 40 | public void setCompanyId(Long companyId) { 41 | this.companyId = companyId; 42 | } 43 | 44 | public String getLoginName() { 45 | return loginName; 46 | } 47 | 48 | public void setLoginName(String loginName) { 49 | this.loginName = loginName == null ? null : loginName.trim(); 50 | } 51 | 52 | public String getPassword() { 53 | return password; 54 | } 55 | 56 | public void setPassword(String password) { 57 | this.password = password == null ? null : password.trim(); 58 | } 59 | 60 | public String getName() { 61 | return name; 62 | } 63 | 64 | public void setName(String name) { 65 | this.name = name == null ? null : name.trim(); 66 | } 67 | 68 | public String getEmail() { 69 | return email; 70 | } 71 | 72 | public void setEmail(String email) { 73 | this.email = email == null ? null : email.trim(); 74 | } 75 | 76 | public String getPhone() { 77 | return phone; 78 | } 79 | 80 | public void setPhone(String phone) { 81 | this.phone = phone == null ? null : phone.trim(); 82 | } 83 | 84 | public Long getUserTag() { 85 | return userTag; 86 | } 87 | 88 | public void setUserTag(Long userTag) { 89 | this.userTag = userTag; 90 | } 91 | 92 | public String getAvatar() { 93 | return avatar; 94 | } 95 | 96 | public void setAvatar(String avatar) { 97 | this.avatar = avatar == null ? null : avatar.trim(); 98 | } 99 | 100 | public String getLoginIp() { 101 | return loginIp; 102 | } 103 | 104 | public void setLoginIp(String loginIp) { 105 | this.loginIp = loginIp == null ? null : loginIp.trim(); 106 | } 107 | 108 | public Date getLoginDate() { 109 | return loginDate; 110 | } 111 | 112 | public void setLoginDate(Date loginDate) { 113 | this.loginDate = loginDate; 114 | } 115 | 116 | } -------------------------------------------------------------------------------- /rz-core/src/main/java/com/rick/scaffold/core/entity/user/Users.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.core.entity.user; 2 | 3 | import com.rick.scaffold.core.entity.generic.DataEntity; 4 | 5 | public class Users extends DataEntity { 6 | 7 | private String email; 8 | 9 | private String username; 10 | 11 | private String password; 12 | 13 | private Byte sex; 14 | 15 | private Integer point; 16 | 17 | private String nickName; 18 | 19 | 20 | public String getEmail() { 21 | return email; 22 | } 23 | 24 | public void setEmail(String email) { 25 | this.email = email; 26 | } 27 | 28 | public String getUsername() { 29 | return username; 30 | } 31 | 32 | public void setUsername(String username) { 33 | this.username = username; 34 | } 35 | 36 | public String getPassword() { 37 | return password; 38 | } 39 | 40 | public void setPassword(String password) { 41 | this.password = password; 42 | } 43 | 44 | public Byte getSex() { 45 | return sex; 46 | } 47 | 48 | public void setSex(Byte sex) { 49 | this.sex = sex; 50 | } 51 | 52 | public Integer getPoint() { 53 | return point; 54 | } 55 | 56 | public void setPoint(Integer point) { 57 | this.point = point; 58 | } 59 | 60 | public String getNickName() { 61 | return nickName; 62 | } 63 | 64 | public void setNickName(String nickName) { 65 | this.nickName = nickName; 66 | } 67 | } -------------------------------------------------------------------------------- /rz-core/src/main/java/com/rick/scaffold/core/service/address/AddressService.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.core.service.address; 2 | 3 | import com.rick.scaffold.core.dao.address.AddressDao; 4 | import com.rick.scaffold.core.entity.address.Address; 5 | import com.rick.scaffold.core.service.generic.CrudService; 6 | import org.springframework.stereotype.Service; 7 | 8 | /** 9 | * Created by user on 16/3/10. 10 | */ 11 | @Service 12 | public class AddressService extends CrudService { 13 | } 14 | -------------------------------------------------------------------------------- /rz-core/src/main/java/com/rick/scaffold/core/service/address/RegionService.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.core.service.address; 2 | 3 | import com.rick.scaffold.core.dao.address.RegionDao; 4 | import com.rick.scaffold.core.entity.address.Region; 5 | import com.rick.scaffold.core.service.generic.BaseService; 6 | import org.springframework.stereotype.Service; 7 | 8 | /** 9 | * Created by user on 16/3/10. 10 | */ 11 | @Service 12 | public class RegionService extends BaseService { 13 | } 14 | -------------------------------------------------------------------------------- /rz-core/src/main/java/com/rick/scaffold/core/service/admin/AdminService.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.core.service.admin; 2 | 3 | import com.rick.scaffold.core.dao.admin.AdminDao; 4 | import com.rick.scaffold.core.entity.admin.Admin; 5 | import com.rick.scaffold.core.service.generic.CrudService; 6 | import org.springframework.stereotype.Service; 7 | 8 | /** 9 | * Created by user on 16/3/10. 10 | */ 11 | @Service 12 | public class AdminService extends CrudService { 13 | } 14 | -------------------------------------------------------------------------------- /rz-core/src/main/java/com/rick/scaffold/core/service/cart/CartItemService.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.core.service.cart; 2 | 3 | import com.rick.scaffold.core.dao.cart.CartItemDao; 4 | import com.rick.scaffold.core.entity.cart.CartItem; 5 | import com.rick.scaffold.core.service.generic.BaseService; 6 | import org.springframework.stereotype.Service; 7 | 8 | /** 9 | * Created by user on 16/3/10. 10 | */ 11 | @Service 12 | public class CartItemService extends BaseService { 13 | } 14 | -------------------------------------------------------------------------------- /rz-core/src/main/java/com/rick/scaffold/core/service/cart/CartService.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.core.service.cart; 2 | 3 | import com.rick.scaffold.core.dao.cart.CartDao; 4 | import com.rick.scaffold.core.entity.cart.Cart; 5 | import com.rick.scaffold.core.service.generic.CrudService; 6 | import org.springframework.stereotype.Service; 7 | 8 | /** 9 | * Created by user on 16/3/10. 10 | */ 11 | @Service 12 | public class CartService extends CrudService { 13 | } 14 | -------------------------------------------------------------------------------- /rz-core/src/main/java/com/rick/scaffold/core/service/generic/BaseService.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.core.service.generic; 2 | 3 | import java.util.List; 4 | 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.transaction.annotation.Transactional; 7 | 8 | import com.rick.scaffold.common.utils.JedisUtils; 9 | import com.rick.scaffold.core.dao.generic.BaseDao; 10 | import com.rick.scaffold.core.entity.generic.BaseEntity; 11 | 12 | /** 13 | * Service基类 14 | */ 15 | @Transactional(readOnly = true) 16 | public abstract class BaseService, T extends BaseEntity> { 17 | 18 | /** 19 | * 持久层对象 20 | */ 21 | @Autowired 22 | protected D dao; 23 | 24 | /** 25 | * 获取单条数据 26 | * @param id 27 | * @return 28 | */ 29 | public T findOne(Long id) { 30 | return dao.findOne(id); 31 | } 32 | 33 | /** 34 | * 查询列表数据 35 | * @param entity 36 | * @return 37 | */ 38 | public List findAll() { 39 | return dao.findAll(); 40 | } 41 | 42 | /** 43 | * 保存数据(插入或更新) 44 | * @param entity 45 | */ 46 | @Transactional(readOnly = false) 47 | public int saveAndCache(T entity, int cacheExpireTime) { 48 | entity.preInsert(); 49 | int res = dao.insert(entity); 50 | JedisUtils.setObject(entity.getId().toString(), entity, cacheExpireTime); 51 | return res; 52 | } 53 | 54 | @Transactional(readOnly = false) 55 | public int saveAndCache(T entity) { 56 | entity.preInsert(); 57 | int res = dao.insert(entity); 58 | JedisUtils.setObject(entity.getId().toString(), entity, 0); 59 | return res; 60 | } 61 | 62 | @Transactional(readOnly = false) 63 | public int save(T entity) { 64 | entity.preInsert(); 65 | return dao.insert(entity); 66 | } 67 | 68 | /** 69 | * 更新数据(插入或更新) 70 | * @param entity 71 | */ 72 | @Transactional(readOnly = false) 73 | public int updateAndCache(T entity, int cacheExpireTime) { 74 | int res = dao.update(entity); 75 | JedisUtils.setObject(entity.getId().toString(), entity, cacheExpireTime); 76 | return res; 77 | } 78 | 79 | @Transactional(readOnly = false) 80 | public int updateAndCache(T entity) { 81 | int res = dao.update(entity); 82 | JedisUtils.setObject(entity.getId().toString(), entity, 0); 83 | return res; 84 | } 85 | 86 | @Transactional(readOnly = false) 87 | public int update(T entity) { 88 | return dao.update(entity); 89 | } 90 | 91 | /** 92 | * 删除数据 93 | * @param entity 94 | */ 95 | @Transactional(readOnly = false) 96 | public int delete(Long id) { 97 | return dao.delete(id); 98 | } 99 | 100 | @Transactional(readOnly = false) 101 | public int deleteAndCache(Long id) { 102 | JedisUtils.delObject(id.toString()); 103 | return dao.delete(id); 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /rz-core/src/main/java/com/rick/scaffold/core/service/generic/CrudService.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.core.service.generic; 2 | 3 | import org.springframework.transaction.annotation.Transactional; 4 | 5 | import com.rick.scaffold.common.utils.JedisUtils; 6 | import com.rick.scaffold.core.dao.generic.CrudDao; 7 | import com.rick.scaffold.core.entity.generic.DataEntity; 8 | 9 | /** 10 | * Service基类 11 | */ 12 | public abstract class CrudService, T extends DataEntity> extends BaseService { 13 | 14 | /** 15 | * 保存数据(插入或更新) 16 | * @param entity 17 | */ 18 | @Override 19 | @Transactional(readOnly = false) 20 | public int save(T entity) { 21 | entity.preInsert(); 22 | return dao.insert(entity); 23 | } 24 | 25 | @Override 26 | @Transactional(readOnly = false) 27 | public int saveAndCache(T entity) { 28 | entity.preInsert(); 29 | int res = dao.insert(entity); 30 | JedisUtils.setObject(entity.getId().toString(), entity, 0); 31 | return res; 32 | } 33 | 34 | @Override 35 | @Transactional(readOnly = false) 36 | public int saveAndCache(T entity, int cacheExpireTime) { 37 | entity.preInsert(); 38 | int res = dao.insert(entity); 39 | JedisUtils.setObject(entity.getId().toString(), entity, cacheExpireTime); 40 | return res; 41 | } 42 | 43 | /** 44 | * 更新数据(插入或更新) 45 | * @param entity 46 | */ 47 | @Override 48 | @Transactional(readOnly = false) 49 | public int update(T entity) { 50 | entity.preUpdate(); 51 | return dao.update(entity); 52 | } 53 | 54 | @Override 55 | @Transactional(readOnly = false) 56 | public int updateAndCache(T entity, int cacheExpireTime) { 57 | entity.preUpdate(); 58 | int res = dao.update(entity); 59 | JedisUtils.setObject(entity.getId().toString(), entity, cacheExpireTime); 60 | return res; 61 | } 62 | 63 | @Override 64 | @Transactional(readOnly = false) 65 | public int updateAndCache(T entity) { 66 | entity.preUpdate(); 67 | int res = dao.update(entity); 68 | JedisUtils.setObject(entity.getId().toString(), entity, 0); 69 | return res; 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /rz-core/src/main/java/com/rick/scaffold/core/service/goods/CategoryService.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.core.service.goods; 2 | 3 | import com.rick.scaffold.core.dao.goods.CategoryDao; 4 | import com.rick.scaffold.core.entity.goods.Category; 5 | import com.rick.scaffold.core.service.generic.CrudService; 6 | import org.springframework.stereotype.Service; 7 | 8 | /** 9 | * Created by user on 16/3/10. 10 | */ 11 | @Service 12 | public class CategoryService extends CrudService { 13 | } 14 | -------------------------------------------------------------------------------- /rz-core/src/main/java/com/rick/scaffold/core/service/goods/GoodsGalleryService.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.core.service.goods; 2 | 3 | import com.rick.scaffold.core.dao.goods.GoodsGalleryDao; 4 | import com.rick.scaffold.core.entity.goods.GoodsGallery; 5 | import com.rick.scaffold.core.service.generic.BaseService; 6 | import org.springframework.stereotype.Service; 7 | 8 | /** 9 | * Created by user on 16/3/10. 10 | */ 11 | @Service 12 | public class GoodsGalleryService extends BaseService { 13 | } 14 | -------------------------------------------------------------------------------- /rz-core/src/main/java/com/rick/scaffold/core/service/goods/GoodsService.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.core.service.goods; 2 | 3 | import com.rick.scaffold.core.dao.goods.GoodsDao; 4 | import com.rick.scaffold.core.entity.goods.Goods; 5 | import com.rick.scaffold.core.service.generic.CrudService; 6 | import org.springframework.stereotype.Service; 7 | 8 | /** 9 | * Created by user on 16/3/10. 10 | */ 11 | @Service 12 | public class GoodsService extends CrudService { 13 | } 14 | -------------------------------------------------------------------------------- /rz-core/src/main/java/com/rick/scaffold/core/service/order/OrderItemService.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.core.service.order; 2 | 3 | import com.rick.scaffold.core.dao.order.OrderItemDao; 4 | import com.rick.scaffold.core.entity.order.OrderItem; 5 | import com.rick.scaffold.core.service.generic.BaseService; 6 | import org.springframework.stereotype.Service; 7 | 8 | /** 9 | * Created by user on 16/3/10. 10 | */ 11 | @Service 12 | public class OrderItemService extends BaseService { 13 | } 14 | -------------------------------------------------------------------------------- /rz-core/src/main/java/com/rick/scaffold/core/service/order/OrderService.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.core.service.order; 2 | 3 | import com.rick.scaffold.core.dao.order.OrderDao; 4 | import com.rick.scaffold.core.entity.order.Order; 5 | import com.rick.scaffold.core.service.generic.CrudService; 6 | import org.springframework.stereotype.Service; 7 | 8 | /** 9 | * Created by user on 16/3/10. 10 | */ 11 | @Service 12 | public class OrderService extends CrudService { 13 | } 14 | -------------------------------------------------------------------------------- /rz-core/src/main/java/com/rick/scaffold/core/service/product/ProductService.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.core.service.product; 2 | 3 | import org.springframework.stereotype.Service; 4 | import org.springframework.transaction.annotation.Transactional; 5 | 6 | import com.rick.scaffold.core.dao.product.ProductDao; 7 | import com.rick.scaffold.core.entity.product.Product; 8 | import com.rick.scaffold.core.service.generic.CrudService; 9 | 10 | @Service 11 | public class ProductService extends CrudService { 12 | 13 | } 14 | -------------------------------------------------------------------------------- /rz-core/src/main/java/com/rick/scaffold/core/service/shop/ShopService.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.core.service.shop; 2 | 3 | import com.rick.scaffold.core.dao.shop.ShopDao; 4 | import com.rick.scaffold.core.entity.shop.Shop; 5 | import com.rick.scaffold.core.service.generic.CrudService; 6 | import org.springframework.stereotype.Service; 7 | 8 | /** 9 | * Created by user on 16/3/10. 10 | */ 11 | @Service 12 | public class ShopService extends CrudService { 13 | } 14 | -------------------------------------------------------------------------------- /rz-core/src/main/java/com/rick/scaffold/core/service/user/CompanyService.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.core.service.user; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.stereotype.Service; 5 | import org.springframework.transaction.annotation.Transactional; 6 | 7 | import com.rick.scaffold.core.dao.user.CompanyDao; 8 | import com.rick.scaffold.core.entity.user.Company; 9 | import com.rick.scaffold.core.service.generic.BaseService; 10 | 11 | @Service 12 | public class CompanyService extends BaseService { 13 | 14 | @Autowired 15 | private CompanyDao companyDao; 16 | 17 | } 18 | 19 | -------------------------------------------------------------------------------- /rz-core/src/main/java/com/rick/scaffold/core/service/user/PhotoService.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.core.service.user; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.stereotype.Service; 5 | import org.springframework.transaction.annotation.Transactional; 6 | 7 | import com.rick.scaffold.core.dao.user.PhotoDao; 8 | import com.rick.scaffold.core.entity.user.Photo; 9 | import com.rick.scaffold.core.service.generic.BaseService; 10 | 11 | @Service 12 | public class PhotoService extends BaseService { 13 | 14 | @Autowired 15 | private PhotoDao photoDao; 16 | } 17 | 18 | -------------------------------------------------------------------------------- /rz-core/src/main/java/com/rick/scaffold/core/service/user/UserService.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.core.service.user; 2 | 3 | import java.util.List; 4 | import java.util.Map; 5 | 6 | import org.springframework.beans.BeanUtils; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.cache.annotation.CachePut; 9 | import org.springframework.cache.annotation.Cacheable; 10 | import org.springframework.stereotype.Service; 11 | import org.springframework.transaction.annotation.Transactional; 12 | 13 | import com.github.pagehelper.Page; 14 | import com.github.pagehelper.PageHelper; 15 | import com.google.common.collect.Maps; 16 | import com.rick.scaffold.core.dao.user.UserDao; 17 | import com.rick.scaffold.core.entity.user.FullUser; 18 | import com.rick.scaffold.core.entity.user.User; 19 | import com.rick.scaffold.core.service.generic.CrudService; 20 | import com.rick.scaffold.core.vo.Paginator; 21 | 22 | @Service 23 | public class UserService extends CrudService { 24 | 25 | @Autowired 26 | private UserDao userDao; 27 | 28 | public Map findAll1() { 29 | PageHelper.startPage(1, 10, "id desc"); 30 | List users = userDao.findAll(); 31 | Page page = (Page)users; 32 | Paginator p = new Paginator(); 33 | BeanUtils.copyProperties(page, p); 34 | Map map = Maps.newHashMap(); 35 | map.put("users", users); 36 | map.put("page", p); 37 | return map; 38 | } 39 | 40 | @Override 41 | public User findOne(Long id) { 42 | return userDao.findOne(id); 43 | } 44 | 45 | 46 | @Override 47 | @Transactional(readOnly = false) 48 | public int save(User entity) { 49 | return super.save(entity); 50 | } 51 | 52 | public User findOne1() { 53 | return userDao.findOne1(56886380597248L, "zzh"); 54 | } 55 | 56 | public List findCascade(Long id) { 57 | return userDao.findCascade(id); 58 | } 59 | 60 | public List findLazy(Long id) { 61 | return userDao.findLazy(id); 62 | } 63 | 64 | public User findByName(String name) { 65 | return userDao.findByName(name); 66 | } 67 | } 68 | 69 | -------------------------------------------------------------------------------- /rz-core/src/main/java/com/rick/scaffold/core/service/user/UsersService.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.core.service.user; 2 | 3 | import com.rick.scaffold.core.dao.user.UsersDao; 4 | import com.rick.scaffold.core.entity.user.Users; 5 | import com.rick.scaffold.core.service.generic.CrudService; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.stereotype.Service; 8 | 9 | /** 10 | * Created by user on 16/3/10. 11 | */ 12 | @Service 13 | public class UsersService extends CrudService { 14 | 15 | @Autowired 16 | private UsersDao usersDao; 17 | 18 | public Users findByName(String name) { 19 | return usersDao.findByName(name); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /rz-core/src/main/java/com/rick/scaffold/core/vo/Paginator.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.core.vo; 2 | 3 | public class Paginator { 4 | 5 | private int pageNum; 6 | private int pageSize; 7 | private long total; 8 | 9 | public int getPageNum() { 10 | return pageNum; 11 | } 12 | public void setPageNum(int pageNum) { 13 | this.pageNum = pageNum; 14 | } 15 | public int getPageSize() { 16 | return pageSize; 17 | } 18 | public void setPageSize(int pageSize) { 19 | this.pageSize = pageSize; 20 | } 21 | public long getTotal() { 22 | return total; 23 | } 24 | public void setTotal(long total) { 25 | this.total = total; 26 | } 27 | 28 | 29 | } 30 | -------------------------------------------------------------------------------- /rz-core/src/main/resources/config/cache/ehcache-local.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 19 | 20 | 21 | 28 | 29 | -------------------------------------------------------------------------------- /rz-core/src/main/resources/config/spring/spring-core.xml: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | Spring Configuration 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /rz-core/src/main/resources/config/spring/spring-ehcache.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /rz-core/src/main/resources/config/spring/spring-jedis.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | Jedis Configuration 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /rz-core/src/main/resources/mappings/address/RegionMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | id, parent_id, region_name, region_type 12 | 13 | 19 | 20 | delete from cs_region 21 | where id = #{id} 22 | 23 | 24 | insert into cs_region 25 | 26 | 27 | id, 28 | 29 | 30 | parent_id, 31 | 32 | 33 | region_name, 34 | 35 | 36 | region_type, 37 | 38 | 39 | 40 | 41 | #{id,jdbcType=INTEGER}, 42 | 43 | 44 | #{parentId,jdbcType=INTEGER}, 45 | 46 | 47 | #{regionName,jdbcType=VARCHAR}, 48 | 49 | 50 | #{regionType,jdbcType=TINYINT}, 51 | 52 | 53 | 54 | 55 | 56 | update cs_region 57 | 58 | 59 | parent_id = #{parentId}, 60 | 61 | 62 | region_name = #{regionName,jdbcType=VARCHAR}, 63 | 64 | 65 | region_type = #{regionType,jdbcType=TINYINT}, 66 | 67 | 68 | where id = #{id} 69 | 70 | -------------------------------------------------------------------------------- /rz-core/src/main/resources/mappings/user/CompanyMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | id, name, phone 11 | 12 | 18 | 19 | delete from sys_company 20 | where id = #{id} 21 | 22 | 23 | insert into sys_company (id, name, phone 24 | ) 25 | values (#{id}, #{name,jdbcType=VARCHAR}, #{phone,jdbcType=VARCHAR} 26 | ) 27 | 28 | 29 | 30 | update sys_company 31 | 32 | 33 | name = #{name,jdbcType=VARCHAR}, 34 | 35 | 36 | phone = #{phone,jdbcType=VARCHAR}, 37 | 38 | 39 | where id = #{id} 40 | 41 | -------------------------------------------------------------------------------- /rz-core/src/main/resources/mappings/user/PhotoMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | id, url, size, user_id 12 | 13 | 19 | 25 | 26 | delete from sys_photo 27 | where id = #{id} 28 | 29 | 30 | insert into sys_photo (id, url, size, 31 | user_id) 32 | values (#{id}, #{url,jdbcType=VARCHAR}, #{size,jdbcType=INTEGER}, 33 | #{userId,jdbcType=BIGINT}) 34 | 35 | 36 | 37 | update sys_photo 38 | 39 | 40 | url = #{url,jdbcType=VARCHAR}, 41 | 42 | 43 | size = #{size,jdbcType=INTEGER}, 44 | 45 | 46 | user_id = #{userId,jdbcType=BIGINT}, 47 | 48 | 49 | where id = #{id} 50 | 51 | -------------------------------------------------------------------------------- /rz-core/src/main/resources/mybatis-generator/mybatis-generator.properties: -------------------------------------------------------------------------------- 1 | db.driver=com.mysql.jdbc.Driver 2 | db.url=jdbc:mysql://localhost:3306/cloudshop?useUnicode=true&characterEncoding=UTF-8 3 | db.user=root 4 | db.password=eros 5 | 6 | #ubuntu path 7 | #mybatis.driver.path=/home/eros/.m2/repository/mysql/mysql-connector-java/5.1.31/mysql-connector-java-5.1.31.jar 8 | #mac path 9 | mybatis.driver.path=/Users/user/.m2/repository/mysql/mysql-connector-java/5.1.31/mysql-connector-java-5.1.31.jar 10 | #windows office 11 | #mybatis.driver.path=C:/Users/user/.m2/repository/mysql/mysql-connector-java/5.1.31/mysql-connector-java-5.1.31.jar 12 | 13 | mybatis.model.package=com.rick.scaffold.core.entity 14 | mybatis.mapper.package=mappings 15 | mybatis.dao.package=com.rick.scaffold.core.dao -------------------------------------------------------------------------------- /rz-core/src/test/java/com/rick/scaffold/base/BaseTest.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.base; 2 | 3 | import org.junit.runner.RunWith; 4 | import org.springframework.test.context.ContextConfiguration; 5 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 6 | 7 | @RunWith(SpringJUnit4ClassRunner.class) 8 | @ContextConfiguration(locations = "classpath:test-applicationContext-core.xml") 9 | public abstract class BaseTest { 10 | 11 | } 12 | -------------------------------------------------------------------------------- /rz-core/src/test/java/com/rick/scaffold/service/address/TestRegion.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.service.address; 2 | 3 | import com.rick.scaffold.base.BaseTest; 4 | import com.rick.scaffold.common.jsontool.JsonMapper; 5 | import com.rick.scaffold.core.entity.address.Region; 6 | import com.rick.scaffold.core.service.address.RegionService; 7 | import org.junit.Test; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | 10 | /** 11 | * Created by user on 16/3/10. 12 | */ 13 | public class TestRegion extends BaseTest { 14 | 15 | @Autowired 16 | private RegionService rs; 17 | 18 | @Test 19 | public void testGetRegion() { 20 | Region region = rs.findOne(3L); 21 | System.out.println(JsonMapper.getInstance().toJson(region)); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /rz-core/src/test/java/com/rick/scaffold/service/user/TestObjectId.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.service.user; 2 | 3 | import org.junit.Test; 4 | 5 | import com.rick.scaffold.common.persistence.tool.IncrSequenceTimeHandler; 6 | 7 | public class TestObjectId { 8 | 9 | // @Test 10 | // public void testObjectId() { 11 | // System.out.println(ObjectId.get().toString()); 12 | // } 13 | 14 | @Test 15 | public void testSequence() { 16 | long id = IncrSequenceTimeHandler.getInstance().nextId(); 17 | System.out.println(id); 18 | } 19 | 20 | @Test 21 | public void testCurrentTime() { 22 | System.out.println(System.currentTimeMillis()); 23 | System.out.println(1288834974657L); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /rz-hbase/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | -------------------------------------------------------------------------------- /rz-hbase/src/main/java/com/rick/scaffold/hbase/HbaseConstants.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.hbase; 2 | 3 | public interface HbaseConstants { 4 | 5 | String DBNAME = "scaffold"; 6 | } 7 | -------------------------------------------------------------------------------- /rz-hbase/src/main/java/com/rick/scaffold/hbase/delegate/HbaseService.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.hbase.delegate; 2 | 3 | import com.rick.scaffold.soa.hbase.HbaseResult; 4 | 5 | import java.io.IOException; 6 | import java.util.List; 7 | 8 | /** 9 | * Created by user on 16/3/18. 10 | */ 11 | public interface HbaseService { 12 | 13 | void createTable(String tableName, String[] cols) throws IOException; 14 | 15 | void deleteTable(String tableName) throws IOException; 16 | 17 | void insertRow(String tableName, String rowkey, String colFamily, String col, String val) throws IOException; 18 | 19 | List getData(String tableName, String rowkey, String colFamily, String col) throws IOException; 20 | 21 | List scanData(String tableName, String startRow, String stopRow) throws IOException; 22 | 23 | void deleRow(String tableName, String rowkey, String colFamily, String col) throws IOException; 24 | } 25 | -------------------------------------------------------------------------------- /rz-hbase/src/main/java/com/rick/scaffold/hbase/module/goods/GoodsHbaseImpl.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.hbase.module.goods; 2 | 3 | import com.rick.scaffold.hbase.HbaseConstants; 4 | import com.rick.scaffold.hbase.delegate.HbaseService; 5 | import com.rick.scaffold.soa.hbase.HbaseResult; 6 | import com.rick.scaffold.soa.hbase.service.GoodsHbase; 7 | import org.apache.log4j.Logger; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.stereotype.Service; 10 | 11 | import javax.annotation.PostConstruct; 12 | import java.io.IOException; 13 | import java.util.List; 14 | 15 | /** 16 | * Created by user on 16/3/18. 17 | */ 18 | @Service("goodsHbaseService") 19 | public class GoodsHbaseImpl implements GoodsHbase { 20 | 21 | private static Logger logger = Logger.getLogger(GoodsHbaseImpl.class); 22 | 23 | @Autowired 24 | private HbaseService service; 25 | 26 | @Override 27 | @PostConstruct 28 | public void createTable() { 29 | String[] cols = {"goods", "order"}; 30 | try { 31 | service.createTable(HbaseConstants.DBNAME, cols); 32 | } catch (Exception e) { 33 | logger.error("Create table fail.", e); 34 | } 35 | 36 | } 37 | 38 | @Override 39 | public void deleteTable() { 40 | try { 41 | service.deleteTable(HbaseConstants.DBNAME); 42 | } catch (Exception e) { 43 | logger.error("Delete table fail.", e); 44 | } 45 | } 46 | 47 | @Override 48 | public void insertDescription(String rowkey, String val) { 49 | try { 50 | service.insertRow(HbaseConstants.DBNAME, rowkey, "goods", "description", val); 51 | } catch (IOException e) { 52 | logger.error("Insert goods description fail.", e); 53 | } 54 | } 55 | 56 | @Override 57 | public List getDescription(String rowkey) { 58 | try { 59 | return service.getData(HbaseConstants.DBNAME, rowkey, "goods", "description"); 60 | } catch (IOException e) { 61 | logger.error("Get goods description fail.", e); 62 | return null; 63 | } 64 | } 65 | 66 | @Override 67 | public List scanData(String startRow, String stopRow) { 68 | try { 69 | return service.scanData(HbaseConstants.DBNAME, startRow, stopRow); 70 | } catch (IOException e) { 71 | logger.error("Scan goods description fail.", e); 72 | return null; 73 | } 74 | } 75 | 76 | @Override 77 | public void delDescription(String rowkey) throws IOException { 78 | try { 79 | service.deleRow(HbaseConstants.DBNAME, rowkey, "goods", "description"); 80 | } catch (IOException e) { 81 | logger.error("Get goods description fail.", e); 82 | } 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /rz-hbase/src/main/java/com/rick/scaffold/hbase/utils/HbaseClient.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.hbase.utils; 2 | 3 | import org.apache.hadoop.conf.Configuration; 4 | import org.apache.hadoop.hbase.HBaseConfiguration; 5 | import org.apache.hadoop.hbase.client.Admin; 6 | import org.apache.hadoop.hbase.client.Connection; 7 | import org.apache.hadoop.hbase.client.ConnectionFactory; 8 | import org.apache.log4j.Logger; 9 | 10 | import javax.annotation.PreDestroy; 11 | import java.io.IOException; 12 | 13 | /** 14 | * Created by user on 16/3/18. 15 | */ 16 | public class HbaseClient { 17 | 18 | private static Logger logger = Logger.getLogger(HbaseClient.class); 19 | 20 | private Configuration configuration; 21 | 22 | private Connection connection; 23 | 24 | private Admin admin; 25 | 26 | 27 | private HbaseClient(String host, String port) { 28 | if(configuration == null) { 29 | init(host, port); 30 | } 31 | } 32 | 33 | public synchronized void init(String host, String port) { 34 | if(configuration == null) { 35 | configuration = HBaseConfiguration.create(); 36 | configuration.set("hbase.zookeeper.quorum", host); 37 | configuration.set("hbase.zookeeper.property.clientPort", port); 38 | // configuration.set("zookeeper.znode.parent", "/hbase"); 39 | try { 40 | connection = ConnectionFactory.createConnection(configuration); 41 | admin = connection.getAdmin(); 42 | } catch (IOException e) { 43 | logger.error("Connect to hbase fail.", e); 44 | } 45 | } 46 | 47 | } 48 | 49 | @PreDestroy 50 | public void close() { 51 | try { 52 | if (null != admin) admin.close(); 53 | if (null != connection) connection.close(); 54 | } catch (IOException e) { 55 | logger.error("Can't close hbase client.", e); 56 | } 57 | } 58 | 59 | public Configuration getConfiguration() { 60 | return configuration; 61 | } 62 | 63 | public Connection getConnection() { 64 | return connection; 65 | } 66 | 67 | public Admin getAdmin() { 68 | return admin; 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /rz-hbase/src/main/java/com/rick/scaffold/soa/hbase/HbaseResult.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.soa.hbase; 2 | 3 | import java.io.Serializable; 4 | 5 | /** 6 | * Created by user on 16/3/18. 7 | */ 8 | public class HbaseResult implements Serializable { 9 | 10 | private static final long serialVersionUID = 1L; 11 | 12 | private String rowKey; 13 | 14 | private Long timestamp; 15 | 16 | private String colFamily; 17 | 18 | private String colName; 19 | 20 | private String value; 21 | 22 | public String getRowKey() { 23 | return rowKey; 24 | } 25 | 26 | public void setRowKey(String rowKey) { 27 | this.rowKey = rowKey; 28 | } 29 | 30 | public Long getTimestamp() { 31 | return timestamp; 32 | } 33 | 34 | public void setTimestamp(Long timestamp) { 35 | this.timestamp = timestamp; 36 | } 37 | 38 | public String getColFamily() { 39 | return colFamily; 40 | } 41 | 42 | public void setColFamily(String colFamily) { 43 | this.colFamily = colFamily; 44 | } 45 | 46 | public String getColName() { 47 | return colName; 48 | } 49 | 50 | public void setColName(String colName) { 51 | this.colName = colName; 52 | } 53 | 54 | public String getValue() { 55 | return value; 56 | } 57 | 58 | public void setValue(String value) { 59 | this.value = value; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /rz-hbase/src/main/java/com/rick/scaffold/soa/hbase/service/GoodsHbase.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.soa.hbase.service; 2 | 3 | import com.rick.scaffold.soa.hbase.HbaseResult; 4 | 5 | import java.io.IOException; 6 | import java.util.List; 7 | 8 | /** 9 | * Created by user on 16/3/18. 10 | */ 11 | public interface GoodsHbase { 12 | 13 | void createTable(); 14 | 15 | void deleteTable(); 16 | 17 | void insertDescription(String rowkey, String val); 18 | 19 | List getDescription(String rowkey); 20 | 21 | List scanData(String startRow, String stopRow); 22 | 23 | void delDescription(String rowkey) throws IOException; 24 | } 25 | -------------------------------------------------------------------------------- /rz-hbase/src/main/resources/config/spring/spring-hbase-soa.xml: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /rz-hbase/src/main/resources/config/spring/spring-hbase.xml: -------------------------------------------------------------------------------- 1 | 2 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /rz-hbase/src/main/resources/log4j.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /rz-hbase/src/test/java/com/rick/scaffold/base/BaseTest.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.base; 2 | 3 | import org.junit.runner.RunWith; 4 | import org.springframework.test.context.ContextConfiguration; 5 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 6 | 7 | 8 | @RunWith(SpringJUnit4ClassRunner.class) 9 | @ContextConfiguration(locations = "classpath:test-spring-hbase.xml") 10 | public abstract class BaseTest { 11 | 12 | } 13 | -------------------------------------------------------------------------------- /rz-hbase/src/test/java/com/rick/scaffold/hbase/TestHbase.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.hbase; 2 | 3 | import com.rick.scaffold.base.BaseTest; 4 | import com.rick.scaffold.hbase.utils.HbaseClient; 5 | import com.rick.scaffold.soa.hbase.HbaseResult; 6 | import com.rick.scaffold.soa.hbase.service.GoodsHbase; 7 | import org.apache.hadoop.hbase.TableName; 8 | import org.junit.Test; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | 11 | import java.util.List; 12 | 13 | /** 14 | * Created by user on 16/3/18. 15 | */ 16 | public class TestHbase extends BaseTest { 17 | 18 | @Autowired 19 | private HbaseClient client; 20 | 21 | @Autowired 22 | private GoodsHbase gh; 23 | 24 | @Test 25 | public void testConnection() throws Exception { 26 | System.out.println(client.getAdmin().getMasterInfoPort()); 27 | } 28 | 29 | @Test 30 | public void testCreateTable() throws Exception { 31 | gh.createTable(); 32 | TableName tableName = TableName.valueOf(HbaseConstants.DBNAME); 33 | System.out.println(client.getAdmin().tableExists(tableName)); 34 | } 35 | 36 | @Test 37 | public void testDeleteTable() throws Exception { 38 | gh.deleteTable(); 39 | TableName tableName = TableName.valueOf(HbaseConstants.DBNAME); 40 | System.out.println(client.getAdmin().tableExists(tableName)); 41 | } 42 | 43 | @Test 44 | public void testInsertGoodsDescription() throws Exception { 45 | gh.insertDescription("1-4", "Rick帅的一比"); 46 | } 47 | 48 | @Test 49 | public void testGetData() throws Exception { 50 | List hrs = gh.getDescription("1-4"); 51 | for(HbaseResult hr: hrs) { 52 | System.out.println(hr.getValue()); 53 | } 54 | System.out.println(hrs.size()); 55 | } 56 | 57 | @Test 58 | public void testScanData() throws Exception { 59 | List hrs = gh.scanData("1-4", "1-5"); 60 | for(HbaseResult hr: hrs) { 61 | System.out.println(hr.getValue()); 62 | } 63 | System.out.println(hrs.size()); 64 | } 65 | 66 | @Test 67 | public void testDeleteRow() throws Exception { 68 | gh.delDescription("1-4"); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /rz-hbase/src/test/resources/test-spring-hbase.xml: -------------------------------------------------------------------------------- 1 | 2 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /rz-search/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | -------------------------------------------------------------------------------- /rz-search/maven-eclipse.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /rz-search/src/main/java/com/rick/scaffold/search/SearchConstants.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.search; 2 | 3 | public interface SearchConstants { 4 | 5 | String INDICE = "scaffold"; 6 | String KEYWORD = "keyword"; 7 | } 8 | -------------------------------------------------------------------------------- /rz-search/src/main/java/com/rick/scaffold/search/services/RZEntry.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.search.services; 2 | 3 | public class RZEntry { 4 | 5 | private String name; 6 | private int count; 7 | 8 | public String getName() { 9 | return name; 10 | } 11 | 12 | public void setName(String name) { 13 | this.name = name; 14 | } 15 | 16 | public int getCount() { 17 | return count; 18 | } 19 | 20 | public void setCount(int count) { 21 | this.count = count; 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /rz-search/src/main/java/com/rick/scaffold/search/services/RZFacet.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.search.services; 2 | 3 | import java.util.List; 4 | 5 | public class RZFacet { 6 | 7 | private String name; 8 | private List entries; 9 | 10 | public String getName() { 11 | return name; 12 | } 13 | 14 | public void setName(String name) { 15 | this.name = name; 16 | } 17 | 18 | public List getEntries() { 19 | return entries; 20 | } 21 | 22 | public void setEntries(List entries) { 23 | this.entries = entries; 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /rz-search/src/main/java/com/rick/scaffold/search/services/RZGetResponse.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.search.services; 2 | 3 | import java.util.List; 4 | import java.util.Map; 5 | 6 | import com.rick.scaffold.common.jsontool.JsonMapper; 7 | import org.elasticsearch.action.get.GetResponse; 8 | import org.elasticsearch.index.get.GetField; 9 | 10 | public class RZGetResponse { 11 | 12 | private GetResponse response; 13 | 14 | public RZGetResponse(GetResponse r) { 15 | response = r; 16 | } 17 | 18 | public String getResponseAsString() { 19 | return JsonMapper.toJsonString(this.getFields()); 20 | } 21 | 22 | public Map getFields() { 23 | return response.getSource(); 24 | } 25 | 26 | public List getField(String key) { 27 | GetField f = response.getFields().get(key); 28 | if (f != null) { 29 | return f.getValues(); 30 | } 31 | return null; 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /rz-search/src/main/java/com/rick/scaffold/search/services/RZIndexKeywordRequest.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.search.services; 2 | 3 | import java.io.Serializable; 4 | import java.util.ArrayList; 5 | import java.util.Collection; 6 | 7 | import com.rick.scaffold.search.services.field.RZField; 8 | 9 | public class RZIndexKeywordRequest implements Serializable { 10 | 11 | private static final long serialVersionUID = 1L; 12 | 13 | private Long id; 14 | private String key; 15 | 16 | private Collection filters = new ArrayList(); 17 | 18 | public Collection getFilters() { 19 | return filters; 20 | } 21 | 22 | public void setFilters(Collection filters) { 23 | this.filters = filters; 24 | } 25 | 26 | public Long getId() { 27 | return id; 28 | } 29 | 30 | public void setId(Long id) { 31 | this.id = id; 32 | } 33 | 34 | public String getKey() { 35 | return key; 36 | } 37 | 38 | public void setKey(String key) { 39 | this.key = key; 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /rz-search/src/main/java/com/rick/scaffold/search/services/RZSearchField.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.search.services; 2 | 3 | public class RZSearchField { 4 | 5 | private String field; 6 | 7 | public String getField() { 8 | return field; 9 | } 10 | 11 | public void setField(String field) { 12 | this.field = field; 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /rz-search/src/main/java/com/rick/scaffold/search/services/RZSearchHit.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.search.services; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | import org.elasticsearch.search.SearchHit; 7 | import org.elasticsearch.search.highlight.HighlightField; 8 | 9 | public class RZSearchHit { 10 | 11 | private String id; 12 | private String index; 13 | private float score; 14 | private Map metaEntries = new HashMap(); 15 | 16 | public Map getMetaEntries() { 17 | return metaEntries; 18 | } 19 | 20 | public RZSearchHit(SearchHit searchit) { 21 | 22 | this.id = searchit.getId(); 23 | this.score = searchit.getScore(); 24 | this.index = searchit.getIndex(); 25 | metaEntries.put("source", searchit.getSource()); 26 | 27 | if (searchit.getHighlightFields() != null 28 | && searchit.getHighlightFields().size() > 0) { 29 | metaEntries.put("highlightFields", searchit.getHighlightFields()); 30 | } 31 | 32 | } 33 | 34 | @SuppressWarnings("unchecked") 35 | public Map getSource() { 36 | return (Map) metaEntries.get("source"); 37 | } 38 | 39 | public String getId() { 40 | return id; 41 | } 42 | 43 | public String getIndex() { 44 | return index; 45 | } 46 | 47 | public float getScore() { 48 | return score; 49 | } 50 | 51 | @SuppressWarnings("unchecked") 52 | public Map getHighlightFields() { 53 | return (Map) metaEntries.get("highlightFields"); 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /rz-search/src/main/java/com/rick/scaffold/search/services/RZSearchRequest.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.search.services; 2 | 3 | 4 | public class RZSearchRequest { 5 | 6 | private String index; 7 | private String type; 8 | private String json; 9 | private int size = -1; 10 | private int start = 0; 11 | 12 | public String getIndex() { 13 | return index; 14 | } 15 | 16 | public void setIndex(String index) { 17 | this.index = index; 18 | } 19 | 20 | public String getType() { 21 | return type; 22 | } 23 | 24 | public void setType(String type) { 25 | this.type = type; 26 | } 27 | 28 | public int getSize() { 29 | return size; 30 | } 31 | 32 | public void setSize(int size) { 33 | this.size = size; 34 | } 35 | 36 | public String getJson() { 37 | return json; 38 | } 39 | 40 | public void setJson(String json) { 41 | this.json = json; 42 | } 43 | 44 | public int getStart() { 45 | return start; 46 | } 47 | 48 | public void setStart(int start) { 49 | this.start = start; 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /rz-search/src/main/java/com/rick/scaffold/search/services/RZSearchResponse.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.search.services; 2 | 3 | import java.util.Collection; 4 | import java.util.Map; 5 | 6 | /** 7 | * Object used for autocomplete and regular search 8 | * 9 | * @author Carl Samson 10 | * 11 | */ 12 | public class RZSearchResponse { 13 | 14 | private String inputSearchJson; 15 | private Collection ids; 16 | private int count; 17 | private String[] inlineSearchList; 18 | private Collection searchHits; 19 | private Map facets; 20 | 21 | public Map getFacets() { 22 | return facets; 23 | } 24 | 25 | public void setFacets(Map facets) { 26 | this.facets = facets; 27 | } 28 | 29 | public String[] getInlineSearchList() { 30 | return inlineSearchList; 31 | } 32 | 33 | public void setInlineSearchList(String[] inlineSearchList) { 34 | this.inlineSearchList = inlineSearchList; 35 | } 36 | 37 | public Collection getSearchHits() { 38 | return searchHits; 39 | } 40 | 41 | public void setSearchHits(Collection searchHits) { 42 | this.searchHits = searchHits; 43 | } 44 | 45 | public String getInputSearchJson() { 46 | return inputSearchJson; 47 | } 48 | 49 | public void setInputSearchJson(String inputSearchJson) { 50 | this.inputSearchJson = inputSearchJson; 51 | } 52 | 53 | public Collection getIds() { 54 | return ids; 55 | } 56 | 57 | public void setIds(Collection ids) { 58 | this.ids = ids; 59 | } 60 | 61 | public int getCount() { 62 | return count; 63 | } 64 | 65 | public void setCount(int count) { 66 | this.count = count; 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /rz-search/src/main/java/com/rick/scaffold/search/services/delegate/SearchDelegate.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.search.services.delegate; 2 | 3 | import java.util.Collection; 4 | import java.util.Set; 5 | 6 | import com.rick.scaffold.search.services.RZGetResponse; 7 | import com.rick.scaffold.search.services.RZIndexKeywordRequest; 8 | import com.rick.scaffold.search.services.RZSearchRequest; 9 | import com.rick.scaffold.search.services.RZSearchResponse; 10 | 11 | public interface SearchDelegate { 12 | 13 | boolean indexExist(String indexName) throws Exception; 14 | 15 | boolean typeExist(String index, String type) throws Exception; 16 | 17 | void createIndice(String mappingJson, String settingsJson, String indice, String type) throws Exception; 18 | 19 | void createType(String mappingJson, String settingsJson, String indice, String type) throws Exception; 20 | 21 | void index(String json, String index, String type, String id); 22 | 23 | void delete(String index, String type, String id) throws Exception; 24 | 25 | void bulkDeleteIndex(String index, String type, Collection ids) throws Exception; 26 | 27 | void bulkIndexKeywords(Collection bulks, String index, String type) throws Exception; 28 | 29 | RZGetResponse getObject(String index, String type, String id) throws Exception; 30 | 31 | RZSearchResponse search(RZSearchRequest request) throws Exception; 32 | 33 | Set searchAutoComplete(String index, String json, String type, int size) throws Exception; 34 | 35 | } -------------------------------------------------------------------------------- /rz-search/src/main/java/com/rick/scaffold/search/services/field/RZBooleanField.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.search.services.field; 2 | 3 | public class RZBooleanField extends RZField { 4 | 5 | public Boolean getValue() { 6 | return (Boolean)super.getValue(); 7 | } 8 | 9 | } 10 | -------------------------------------------------------------------------------- /rz-search/src/main/java/com/rick/scaffold/search/services/field/RZDateField.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.search.services.field; 2 | 3 | import java.util.Date; 4 | 5 | public class RZDateField extends RZField { 6 | 7 | public Date getValue() { 8 | return (Date)super.getValue(); 9 | } 10 | 11 | } 12 | -------------------------------------------------------------------------------- /rz-search/src/main/java/com/rick/scaffold/search/services/field/RZDoubleField.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.search.services.field; 2 | 3 | public class RZDoubleField extends RZField { 4 | 5 | 6 | public Double getValue() { 7 | return (Double)super.getValue(); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /rz-search/src/main/java/com/rick/scaffold/search/services/field/RZField.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.search.services.field; 2 | 3 | public abstract class RZField { 4 | 5 | private String name; 6 | private Object object; 7 | 8 | public String getName() { 9 | return name; 10 | } 11 | 12 | public void setName(String name) { 13 | this.name = name; 14 | } 15 | 16 | public void setValue(Object o) { 17 | this.object = o; 18 | } 19 | 20 | protected Object getValue() { 21 | return object; 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /rz-search/src/main/java/com/rick/scaffold/search/services/field/RZIntegerField.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.search.services.field; 2 | 3 | public class RZIntegerField extends RZField { 4 | 5 | public Integer getValue() { 6 | return (Integer)super.getValue(); 7 | } 8 | 9 | } 10 | -------------------------------------------------------------------------------- /rz-search/src/main/java/com/rick/scaffold/search/services/field/RZListField.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.search.services.field; 2 | 3 | import java.util.List; 4 | 5 | public class RZListField extends RZField { 6 | 7 | @SuppressWarnings("unchecked") 8 | public List getValue() { 9 | return (List)super.getValue(); 10 | } 11 | 12 | } 13 | -------------------------------------------------------------------------------- /rz-search/src/main/java/com/rick/scaffold/search/services/field/RZLongField.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.search.services.field; 2 | 3 | public class RZLongField extends RZField { 4 | 5 | public Long getValue() { 6 | return (Long)super.getValue(); 7 | } 8 | 9 | } 10 | -------------------------------------------------------------------------------- /rz-search/src/main/java/com/rick/scaffold/search/services/field/RZStringField.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.search.services.field; 2 | 3 | public class RZStringField extends RZField { 4 | public String getValue() { 5 | return (String)super.getValue(); 6 | } 7 | 8 | } 9 | -------------------------------------------------------------------------------- /rz-search/src/main/java/com/rick/scaffold/search/services/worker/DeleteKeywordsImpl.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.search.services.worker; 2 | 3 | import java.util.Collection; 4 | import java.util.List; 5 | 6 | import com.rick.scaffold.search.SearchConstants; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | 9 | import com.rick.scaffold.search.services.RZSearchRequest; 10 | import com.rick.scaffold.search.services.RZSearchResponse; 11 | import com.rick.scaffold.search.services.delegate.SearchDelegate; 12 | import com.rick.scaffold.search.utils.CustomIndexConfiguration; 13 | import com.rick.scaffold.search.utils.SearchClient; 14 | 15 | public class DeleteKeywordsImpl implements DeleteObjectWorker { 16 | 17 | private List indexConfigurations = null; 18 | 19 | public List getIndexConfigurations() { 20 | return indexConfigurations; 21 | } 22 | 23 | public void setIndexConfigurations( 24 | List indexConfigurations) { 25 | this.indexConfigurations = indexConfigurations; 26 | } 27 | 28 | @Autowired 29 | private SearchDelegate searchDelegate; 30 | 31 | @Override 32 | public void deleteObject(SearchClient client, String index, String type, Long id) throws Exception { 33 | String keywordType = SearchConstants.KEYWORD + "_" + type; 34 | if (searchDelegate.indexExist(index)) { 35 | String query = new StringBuilder() 36 | .append("{\"query\":{\"term\" : {\"dbid\" : \"").append(id) 37 | .append("\" }}}").toString(); 38 | RZSearchRequest sr = new RZSearchRequest(); 39 | sr.setIndex(index); 40 | sr.setType(keywordType); 41 | sr.setJson(query); 42 | RZSearchResponse r = searchDelegate.search(sr); 43 | if (r != null) { 44 | Collection ids = r.getIds(); 45 | searchDelegate.bulkDeleteIndex(index, keywordType, ids); 46 | } 47 | } 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /rz-search/src/main/java/com/rick/scaffold/search/services/worker/DeleteObjectImpl.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.search.services.worker; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | 5 | import com.rick.scaffold.search.services.delegate.SearchDelegate; 6 | import com.rick.scaffold.search.utils.SearchClient; 7 | 8 | public class DeleteObjectImpl implements DeleteObjectWorker { 9 | 10 | @Autowired 11 | private SearchDelegate searchDelegate; 12 | 13 | @Override 14 | public void deleteObject(SearchClient client, String index, 15 | String type, Long id) throws Exception { 16 | searchDelegate.delete(index, type, id.toString()); 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /rz-search/src/main/java/com/rick/scaffold/search/services/worker/DeleteObjectWorker.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.search.services.worker; 2 | 3 | import com.rick.scaffold.search.utils.SearchClient; 4 | 5 | 6 | /** 7 | * Deletes an object from the index 8 | * @author Carl Samson 9 | * 10 | */ 11 | public interface DeleteObjectWorker { 12 | 13 | public void deleteObject(SearchClient client, String index, String type, Long id) throws Exception; 14 | 15 | } 16 | -------------------------------------------------------------------------------- /rz-search/src/main/java/com/rick/scaffold/search/services/worker/IndexWorker.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.search.services.worker; 2 | 3 | import com.rick.scaffold.search.utils.SearchClient; 4 | 5 | 6 | public interface IndexWorker { 7 | 8 | void init(SearchClient client); 9 | void execute(SearchClient client, String json, String index, String type, Long id) throws Exception; 10 | 11 | } 12 | -------------------------------------------------------------------------------- /rz-search/src/main/java/com/rick/scaffold/search/services/worker/KeywordSearchWorker.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.search.services.worker; 2 | 3 | import com.rick.scaffold.search.services.RZSearchResponse; 4 | import com.rick.scaffold.search.utils.SearchClient; 5 | 6 | 7 | public interface KeywordSearchWorker { 8 | 9 | RZSearchResponse execute(SearchClient client,String index,String json, String type, int size) throws Exception; 10 | 11 | } 12 | -------------------------------------------------------------------------------- /rz-search/src/main/java/com/rick/scaffold/search/services/worker/KeywordSearchWorkerImpl.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.search.services.worker; 2 | 3 | import java.util.Collection; 4 | 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | 7 | import com.rick.scaffold.search.services.RZSearchResponse; 8 | import com.rick.scaffold.search.services.delegate.SearchDelegate; 9 | import com.rick.scaffold.search.utils.SearchClient; 10 | 11 | public class KeywordSearchWorkerImpl implements KeywordSearchWorker { 12 | 13 | @Autowired 14 | private SearchDelegate searchDelegate; 15 | 16 | @Override 17 | public RZSearchResponse execute(SearchClient client, String index, 18 | String json, String type, int size) throws Exception { 19 | 20 | Collection hits = searchDelegate.searchAutoComplete(index, 21 | json, type, size); 22 | RZSearchResponse resp = new RZSearchResponse(); 23 | 24 | String[] array = (String[]) hits.toArray(new String[hits.size()]); 25 | 26 | resp.setInlineSearchList(array); 27 | if (array.length > 0) { 28 | resp.setCount(array.length); 29 | } 30 | 31 | return resp; 32 | 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /rz-search/src/main/java/com/rick/scaffold/search/services/worker/SearchWorker.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.search.services.worker; 2 | 3 | import com.rick.scaffold.search.services.RZSearchRequest; 4 | import com.rick.scaffold.search.services.RZSearchResponse; 5 | import com.rick.scaffold.search.utils.SearchClient; 6 | 7 | public interface SearchWorker { 8 | 9 | RZSearchResponse execute(SearchClient client, RZSearchRequest request) throws Exception; 10 | 11 | } 12 | -------------------------------------------------------------------------------- /rz-search/src/main/java/com/rick/scaffold/search/services/worker/SearchWorkerImpl.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.search.services.worker; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | 5 | import com.rick.scaffold.search.services.RZSearchRequest; 6 | import com.rick.scaffold.search.services.RZSearchResponse; 7 | import com.rick.scaffold.search.services.delegate.SearchDelegate; 8 | import com.rick.scaffold.search.utils.SearchClient; 9 | 10 | public class SearchWorkerImpl implements SearchWorker { 11 | 12 | @Autowired 13 | private SearchDelegate searchDelegate; 14 | 15 | @Override 16 | public RZSearchResponse execute(SearchClient client, RZSearchRequest request) throws Exception { 17 | RZSearchResponse response = searchDelegate.search(request); 18 | response.setInputSearchJson(request.getJson()); 19 | return response; 20 | 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /rz-search/src/main/java/com/rick/scaffold/search/services/workflow/DeleteObjectWorkflow.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.search.services.workflow; 2 | 3 | import java.util.List; 4 | 5 | import com.rick.scaffold.search.services.worker.DeleteObjectWorker; 6 | 7 | public class DeleteObjectWorkflow extends Workflow{ 8 | 9 | private List deleteObjectWorkflow; 10 | 11 | public List getDeleteObjectWorkflow() { 12 | return deleteObjectWorkflow; 13 | } 14 | 15 | 16 | public void setDeleteObjectWorkflow(List deleteObjectWorkflow) { 17 | this.deleteObjectWorkflow = deleteObjectWorkflow; 18 | } 19 | 20 | 21 | public void deleteObject(String index, String type, Long id) throws Exception { 22 | if(deleteObjectWorkflow!=null) { 23 | for(DeleteObjectWorker iw : deleteObjectWorkflow) { 24 | iw.deleteObject(super.getSearchClient(), index, type, id); 25 | } 26 | } 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /rz-search/src/main/java/com/rick/scaffold/search/services/workflow/GetWorkflow.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.search.services.workflow; 2 | 3 | 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | 6 | import com.rick.scaffold.search.services.RZGetResponse; 7 | import com.rick.scaffold.search.services.delegate.SearchDelegate; 8 | 9 | 10 | public class GetWorkflow extends Workflow { 11 | 12 | @Autowired 13 | private SearchDelegate searchDelegate; 14 | public RZGetResponse getObject(String index, String type, String id) throws Exception { 15 | 16 | return searchDelegate.getObject(index, type, id); 17 | 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /rz-search/src/main/java/com/rick/scaffold/search/services/workflow/ImportWorkflow.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.search.services.workflow; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.beans.factory.annotation.Value; 8 | 9 | import com.rick.scaffold.common.http.HttpService; 10 | import com.rick.scaffold.common.jsontool.JsonMapper; 11 | 12 | public class ImportWorkflow extends Workflow { 13 | 14 | @Value("${es.host1}") 15 | private String esHost; 16 | 17 | @Value("${db.url}") 18 | private String dbUrl; 19 | 20 | @Value("${db.user}") 21 | private String dbUser; 22 | 23 | @Value("${db.password}") 24 | private String dbPass; 25 | 26 | @Autowired 27 | private HttpService httpService; 28 | 29 | public void importFromDB(String sql, String index, String type, String river) throws Exception { 30 | String url = "http://" + esHost + ":9200/_river/"+river+"/_meta"; 31 | Map jdbcMap = new HashMap(); 32 | jdbcMap.put("url", dbUrl); 33 | jdbcMap.put("user", dbUser); 34 | jdbcMap.put("password", dbPass); 35 | jdbcMap.put("sql", sql); 36 | jdbcMap.put("index", index); 37 | jdbcMap.put("type", type); 38 | Map params = new HashMap(); 39 | params.put("type", "jdbc"); 40 | params.put("jdbc", jdbcMap); 41 | httpService.put(url, JsonMapper.toJsonString(params)); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /rz-search/src/main/java/com/rick/scaffold/search/services/workflow/IndexWorkflow.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.search.services.workflow; 2 | 3 | import java.util.List; 4 | 5 | import org.apache.commons.lang3.StringUtils; 6 | import org.apache.log4j.Logger; 7 | 8 | import com.rick.scaffold.common.jsontool.JsonMapper; 9 | import com.rick.scaffold.search.services.worker.IndexWorker; 10 | import com.rick.scaffold.soa.search.IndexObject; 11 | 12 | 13 | public class IndexWorkflow extends Workflow { 14 | 15 | private static Logger log = Logger.getLogger(IndexWorkflow.class); 16 | 17 | private List indexWorkflow; 18 | 19 | public List getIndexWorkflow() { 20 | return indexWorkflow; 21 | } 22 | 23 | public void setIndexWorkflow(List indexWorkflow) { 24 | this.indexWorkflow = indexWorkflow; 25 | } 26 | 27 | public void index(IndexObject jsonObj, String index, String type) throws Exception { 28 | Long id = jsonObj.getId(); 29 | if(id == null || id.longValue() <= 0) { 30 | log.warn("No id exist for object."); 31 | throw new Exception("Invalid index object."); 32 | } 33 | String json = JsonMapper.toJsonString(jsonObj); 34 | if(indexWorkflow != null) { 35 | for(IndexWorker iw : indexWorkflow) { 36 | iw.execute(this.getSearchClient(), json, index, type, id); 37 | } 38 | } 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /rz-search/src/main/java/com/rick/scaffold/search/services/workflow/SearchWorkflow.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.search.services.workflow; 2 | 3 | import java.util.List; 4 | 5 | import com.rick.scaffold.search.SearchConstants; 6 | import com.rick.scaffold.search.services.RZSearchRequest; 7 | import com.rick.scaffold.search.services.RZSearchResponse; 8 | import com.rick.scaffold.search.services.worker.KeywordSearchWorker; 9 | import com.rick.scaffold.search.services.worker.SearchWorker; 10 | 11 | public class SearchWorkflow extends Workflow { 12 | 13 | private List searchFlow; 14 | private List searchKeywordWorkflow; 15 | 16 | public List getSearchKeywordWorkflow() { 17 | return searchKeywordWorkflow; 18 | } 19 | 20 | public void setSearchKeywordWorkflow(List searchKeywordWorkflow) { 21 | this.searchKeywordWorkflow = searchKeywordWorkflow; 22 | } 23 | 24 | public List getSearchFlow() { 25 | return searchFlow; 26 | } 27 | 28 | public void setSearchFlow(List searchFlow) { 29 | this.searchFlow = searchFlow; 30 | } 31 | 32 | public RZSearchResponse searchAutoComplete(String index, String json, String type, 33 | int size) throws Exception { 34 | RZSearchResponse response = null; 35 | if (searchKeywordWorkflow != null) { 36 | String keywordType = SearchConstants.KEYWORD + "_" + type; 37 | for (KeywordSearchWorker sw : searchKeywordWorkflow) { 38 | response = sw.execute(super.getSearchClient(), index, json, 39 | keywordType, size); 40 | } 41 | } 42 | return response; 43 | } 44 | 45 | public RZSearchResponse search(RZSearchRequest request) throws Exception { 46 | RZSearchResponse response = null; 47 | if (searchFlow != null) { 48 | for (SearchWorker sw : searchFlow) { 49 | response = sw.execute(super.getSearchClient(), request); 50 | } 51 | } 52 | return response; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /rz-search/src/main/java/com/rick/scaffold/search/services/workflow/Workflow.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.search.services.workflow; 2 | 3 | import com.rick.scaffold.search.utils.SearchClient; 4 | 5 | public abstract class Workflow { 6 | 7 | private SearchClient searchClient; 8 | 9 | public SearchClient getSearchClient() { 10 | return searchClient; 11 | } 12 | 13 | public void setSearchClient(SearchClient searchClient) { 14 | this.searchClient = searchClient; 15 | } 16 | 17 | public Workflow() { 18 | super(); 19 | } 20 | 21 | } -------------------------------------------------------------------------------- /rz-search/src/main/java/com/rick/scaffold/search/utils/CustomIndexConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.search.utils; 2 | 3 | import java.util.List; 4 | 5 | public class CustomIndexConfiguration extends IndexConfiguration { 6 | 7 | 8 | private String onType; 9 | private List fields; 10 | private List filters; 11 | 12 | public String getOnType() { 13 | return onType; 14 | } 15 | 16 | public void setOnType(String onType) { 17 | this.onType = onType; 18 | } 19 | 20 | public List getFields() { 21 | return fields; 22 | } 23 | 24 | public void setFields(List fields) { 25 | this.fields = fields; 26 | } 27 | 28 | public List getFilters() { 29 | return filters; 30 | } 31 | 32 | public void setFilters(List filters) { 33 | this.filters = filters; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /rz-search/src/main/java/com/rick/scaffold/search/utils/CustomIndexFieldConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.search.utils; 2 | 3 | public class CustomIndexFieldConfiguration { 4 | 5 | private String fieldName; 6 | private String fieldType; 7 | 8 | public String getFieldName() { 9 | return fieldName; 10 | } 11 | public void setFieldName(String fieldName) { 12 | this.fieldName = fieldName; 13 | } 14 | public String getFieldType() { 15 | return fieldType; 16 | } 17 | public void setFieldType(String fieldType) { 18 | this.fieldType = fieldType; 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /rz-search/src/main/java/com/rick/scaffold/search/utils/IndexConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.search.utils; 2 | 3 | /** 4 | * Configured from Spring 5 | * 6 | * @author Carl Samson 7 | * 8 | */ 9 | public class IndexConfiguration { 10 | 11 | private String indiceName; 12 | private String typeName; 13 | private String mappingFileName; 14 | private String settingsFileName; 15 | 16 | public String getIndiceName() { 17 | return indiceName; 18 | } 19 | public void setIndiceName(String indiceName) { 20 | this.indiceName = indiceName; 21 | } 22 | public String getTypeName() { 23 | return typeName; 24 | } 25 | public void setTypeName(String typeName) { 26 | this.typeName = typeName; 27 | } 28 | public String getMappingFileName() { 29 | return mappingFileName; 30 | } 31 | public void setMappingFileName(String mappingFileName) { 32 | this.mappingFileName = mappingFileName; 33 | } 34 | public String getSettingsFileName() { 35 | return settingsFileName; 36 | } 37 | public void setSettingsFileName(String settingsFileName) { 38 | this.settingsFileName = settingsFileName; 39 | } 40 | 41 | 42 | } 43 | -------------------------------------------------------------------------------- /rz-search/src/main/java/com/rick/scaffold/search/utils/SearchClient.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.search.utils; 2 | 3 | import static org.elasticsearch.node.NodeBuilder.nodeBuilder; 4 | 5 | import javax.annotation.PreDestroy; 6 | 7 | import org.apache.log4j.Logger; 8 | import org.elasticsearch.client.Client; 9 | import org.elasticsearch.client.transport.TransportClient; 10 | import org.elasticsearch.common.settings.ImmutableSettings; 11 | import org.elasticsearch.common.settings.Settings; 12 | import org.elasticsearch.common.transport.InetSocketTransportAddress; 13 | import org.elasticsearch.node.Node; 14 | 15 | /** 16 | * Singleton 17 | * 18 | * @author Carl Samson 19 | * 20 | */ 21 | public class SearchClient { 22 | 23 | private static Logger log = Logger.getLogger(SearchClient.class); 24 | 25 | private Client client = null; 26 | private Node node = null; 27 | private ServerConfiguration serverConfiguration = null; 28 | 29 | private SearchClient() { 30 | 31 | } 32 | 33 | public ServerConfiguration getServerConfiguration() { 34 | return serverConfiguration; 35 | } 36 | 37 | public void setServerConfiguration(ServerConfiguration serverConfiguration) { 38 | this.serverConfiguration = serverConfiguration; 39 | } 40 | 41 | public Client getClient() { 42 | if (client == null) { 43 | initClient(); 44 | } 45 | return client; 46 | } 47 | 48 | @PreDestroy 49 | public void stopClient() { 50 | if (client != null) { 51 | client.close(); 52 | } 53 | if (node != null) { 54 | node.close(); 55 | } 56 | } 57 | 58 | private synchronized void initClient() { 59 | if (client == null) { 60 | try { 61 | if (serverConfiguration.getMode().equalsIgnoreCase("remote")) { 62 | Settings s = ImmutableSettings 63 | .settingsBuilder() 64 | .put("cluster.name", serverConfiguration.getClusterName()) 65 | .build(); 66 | client = new TransportClient(s) 67 | .addTransportAddress(new InetSocketTransportAddress( 68 | serverConfiguration.getClusterHost(), 69 | serverConfiguration.getClusterPort())); 70 | } else { 71 | if(node == null) { 72 | node = nodeBuilder() 73 | .clusterName(serverConfiguration.getClusterName()) 74 | .local(true).node(); 75 | } 76 | client = node.client(); 77 | } 78 | log.debug("****** ES client ready ********"); 79 | } catch (Exception e) { 80 | log.error("Can't start ES client.", e); 81 | } 82 | } 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /rz-search/src/main/java/com/rick/scaffold/search/utils/ServerConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.search.utils; 2 | 3 | public class ServerConfiguration { 4 | 5 | private String clusterName; 6 | private String mode; 7 | private String clusterHost; 8 | private int clusterPort; 9 | 10 | public String getClusterName() { 11 | return clusterName; 12 | } 13 | 14 | public void setClusterName(String clusterName) { 15 | this.clusterName = clusterName; 16 | } 17 | 18 | public String getMode() { 19 | return mode; 20 | } 21 | 22 | public void setMode(String mode) { 23 | this.mode = mode; 24 | } 25 | 26 | public String getClusterHost() { 27 | return clusterHost; 28 | } 29 | 30 | public void setClusterHost(String clusterHost) { 31 | this.clusterHost = clusterHost; 32 | } 33 | 34 | public int getClusterPort() { 35 | return clusterPort; 36 | } 37 | 38 | public void setClusterPort(int clusterPort) { 39 | this.clusterPort = clusterPort; 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /rz-search/src/main/java/com/rick/scaffold/soa/search/IndexObject.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.soa.search; 2 | 3 | import com.fasterxml.jackson.annotation.JsonIgnore; 4 | 5 | import java.io.Serializable; 6 | 7 | public abstract class IndexObject implements Serializable { 8 | 9 | private static final long serialVersionUID = 1L; 10 | 11 | @JsonIgnore 12 | private Long id; 13 | 14 | public Long getId() { 15 | return id; 16 | } 17 | 18 | public void setId(Long id) { 19 | this.id = id; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /rz-search/src/main/java/com/rick/scaffold/soa/search/SearchEntry.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.soa.search; 2 | 3 | import java.io.Serializable; 4 | import java.util.List; 5 | 6 | public class SearchEntry implements Serializable { 7 | 8 | private static final long serialVersionUID = 1L; 9 | 10 | private IndexObject indexObject; 11 | private List highlights; 12 | 13 | public void setHighlights(List highlights) { 14 | this.highlights = highlights; 15 | } 16 | public List getHighlights() { 17 | return highlights; 18 | } 19 | public IndexObject getIndexObject() { 20 | return indexObject; 21 | } 22 | public void setIndexUser(IndexObject indexObject) { 23 | this.indexObject = indexObject; 24 | } 25 | 26 | 27 | 28 | } 29 | -------------------------------------------------------------------------------- /rz-search/src/main/java/com/rick/scaffold/soa/search/SearchFacet.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.soa.search; 2 | 3 | import java.io.Serializable; 4 | 5 | public class SearchFacet implements Serializable { 6 | 7 | private static final long serialVersionUID = 1L; 8 | 9 | private String name; 10 | private String key; 11 | private long count; 12 | 13 | public void setKey(String key) { 14 | this.key = key; 15 | } 16 | public String getKey() { 17 | return key; 18 | } 19 | public void setName(String name) { 20 | this.name = name; 21 | } 22 | public String getName() { 23 | return name; 24 | } 25 | public void setCount(long count) { 26 | this.count = count; 27 | } 28 | public long getCount() { 29 | return count; 30 | }; 31 | 32 | } 33 | -------------------------------------------------------------------------------- /rz-search/src/main/java/com/rick/scaffold/soa/search/SearchKeywords.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.soa.search; 2 | 3 | import java.io.Serializable; 4 | import java.util.List; 5 | 6 | public class SearchKeywords implements Serializable { 7 | 8 | private static final long serialVersionUID = 1L; 9 | 10 | private List keywords; 11 | 12 | public void setKeywords(List keywords) { 13 | this.keywords = keywords; 14 | } 15 | 16 | public List getKeywords() { 17 | return keywords; 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /rz-search/src/main/java/com/rick/scaffold/soa/search/SearchResult.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.soa.search; 2 | 3 | import java.io.Serializable; 4 | import java.util.List; 5 | import java.util.Map; 6 | 7 | public class SearchResult implements Serializable { 8 | 9 | private static final long serialVersionUID = 1L; 10 | 11 | private int totalCount = 0;//total number of entries 12 | private int entryCount = 0;//number of entries asked 13 | 14 | private List entries; 15 | private Map> facets;//facet key (example : category) & facet description (example : category code) 16 | 17 | public void setTotalCount(int totalCount) { 18 | this.totalCount = totalCount; 19 | } 20 | public int getTotalCount() { 21 | return totalCount; 22 | } 23 | public void setEntryCount(int entryCount) { 24 | this.entryCount = entryCount; 25 | } 26 | public int getEntryCount() { 27 | return entryCount; 28 | } 29 | public void setEntries(List entries) { 30 | this.entries = entries; 31 | } 32 | public List getEntries() { 33 | return entries; 34 | } 35 | public void setFacets(Map> facets) { 36 | this.facets = facets; 37 | } 38 | public Map> getFacets() { 39 | return facets; 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /rz-search/src/main/java/com/rick/scaffold/soa/search/model/IndexGoods.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.soa.search.model; 2 | 3 | import com.rick.scaffold.soa.search.IndexObject; 4 | 5 | 6 | public class IndexGoods extends IndexObject { 7 | 8 | private String name; 9 | 10 | private String sn; 11 | 12 | private Float shop_price; 13 | 14 | private Long shop_id; 15 | private Long cate_id; 16 | 17 | public String getName() { 18 | return name; 19 | } 20 | 21 | public void setName(String name) { 22 | this.name = name; 23 | } 24 | 25 | public String getSn() { 26 | return sn; 27 | } 28 | 29 | public void setSn(String sn) { 30 | this.sn = sn; 31 | } 32 | 33 | public Float getShop_price() { 34 | return shop_price; 35 | } 36 | 37 | public void setShop_price(Float shop_price) { 38 | this.shop_price = shop_price; 39 | } 40 | 41 | public Long getShop_id() { 42 | return shop_id; 43 | } 44 | 45 | public void setShop_id(Long shop_id) { 46 | this.shop_id = shop_id; 47 | } 48 | 49 | public Long getCate_id() { 50 | return cate_id; 51 | } 52 | 53 | public void setCate_id(Long cate_id) { 54 | this.cate_id = cate_id; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /rz-search/src/main/java/com/rick/scaffold/soa/search/service/GoodsSearch.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.soa.search.service; 2 | 3 | import com.rick.scaffold.soa.search.SearchKeywords; 4 | import com.rick.scaffold.soa.search.SearchResult; 5 | import com.rick.scaffold.soa.search.model.IndexGoods; 6 | 7 | public interface GoodsSearch { 8 | 9 | void importFromDB(String sql) throws Exception; 10 | 11 | void importKeywordFromDB(String sql) throws Exception; 12 | 13 | void createIndex(IndexGoods goods); 14 | 15 | void deleteIndex(Long id); 16 | 17 | SearchKeywords searchAutoComplete(String index, String type, String keyword, int entriesCount); 18 | 19 | SearchResult search(String jsonString, int startIndex, int entriesCount); 20 | } 21 | -------------------------------------------------------------------------------- /rz-search/src/main/resources/config/search/indice_mappings_goods.json: -------------------------------------------------------------------------------- 1 | { 2 | "goods": { 3 | "properties": { 4 | "name": { 5 | "type": "string", 6 | "index": "analyzed", 7 | "analyzer": "cn_analyzer" 8 | }, 9 | "sn": { 10 | "type": "string", 11 | "index": "not_analyzed" 12 | }, 13 | "shop_price": { 14 | "type": "float", 15 | "index": "not_analyzed" 16 | }, 17 | "shop_id": { 18 | "type": "long", 19 | "index": "not_analyzed" 20 | }, 21 | "cate_id": { 22 | "type": "long", 23 | "index": "not_analyzed" 24 | } 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /rz-search/src/main/resources/config/search/indice_settings_cn.json: -------------------------------------------------------------------------------- 1 | { 2 | "index": { 3 | "analysis": { 4 | "analyzer": { 5 | "cn_analyzer": { 6 | "type" : "custom", 7 | "tokenizer" : "ik" 8 | } 9 | } 10 | } 11 | } 12 | } -------------------------------------------------------------------------------- /rz-search/src/main/resources/config/spring/spring-search-soa.xml: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /rz-search/src/main/resources/log4j.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /rz-search/src/test/java/com/rick/scaffold/base/BaseTest.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.base; 2 | 3 | import org.junit.runner.RunWith; 4 | import org.springframework.test.context.ContextConfiguration; 5 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 6 | 7 | 8 | @RunWith(SpringJUnit4ClassRunner.class) 9 | @ContextConfiguration(locations = "classpath:test-spring-search.xml") 10 | public abstract class BaseTest { 11 | 12 | } 13 | -------------------------------------------------------------------------------- /rz-search/src/test/resources/complex_search.json: -------------------------------------------------------------------------------- 1 | { 2 | "query": { 3 | "term": { 4 | "name": "红牛" 5 | } 6 | }, 7 | "filter": { 8 | "bool": { 9 | "must": { 10 | "range": { 11 | "shop_price": {"lt": 100, "gte":6} 12 | } 13 | } 14 | } 15 | }, 16 | "sort": { 17 | "shop_price": {"order": "desc"} 18 | }, 19 | "facets": { 20 | "range1": { 21 | "range": { 22 | "field": "shop_price", 23 | "ranges": [ 24 | {"from": 1, "to": 3}, 25 | {"from": 3, "to": 10} 26 | ] 27 | } 28 | } 29 | 30 | } 31 | } -------------------------------------------------------------------------------- /rz-web/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | -------------------------------------------------------------------------------- /rz-web/src/main/java/com/rick/scaffold/common/listener/CorsFilter.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.common.listener; 2 | 3 | import java.io.IOException; 4 | 5 | import javax.servlet.FilterChain; 6 | import javax.servlet.ServletException; 7 | import javax.servlet.http.HttpServletRequest; 8 | import javax.servlet.http.HttpServletResponse; 9 | 10 | import org.springframework.web.filter.OncePerRequestFilter; 11 | 12 | public class CorsFilter extends OncePerRequestFilter { 13 | 14 | @Override 15 | protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { 16 | response.addHeader("Access-Control-Allow-Origin", "*"); 17 | if (request.getHeader("Access-Control-Request-Method") != null && "OPTIONS".equals(request.getMethod())) { 18 | response.addHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE"); 19 | response.addHeader("Access-Control-Allow-Headers", "Content-Type, Authorization"); 20 | response.addHeader("Access-Control-Max-Age", "1"); 21 | } 22 | 23 | filterChain.doFilter(request, response); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /rz-web/src/main/java/com/rick/scaffold/common/listener/WebContextListener.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.common.listener; 2 | 3 | import javax.servlet.ServletContext; 4 | 5 | import org.springframework.web.context.WebApplicationContext; 6 | 7 | import com.rick.scaffold.common.config.Global; 8 | 9 | public class WebContextListener extends org.springframework.web.context.ContextLoaderListener { 10 | 11 | @Override 12 | public WebApplicationContext initWebApplicationContext(ServletContext servletContext) { 13 | StringBuilder sb = new StringBuilder(); 14 | sb.append("\r\n======================================================================\r\n"); 15 | sb.append("\r\n 欢迎使用 "+ Global.getConfig("global.productName") + " - Powered By http://www.rick.com\r\n"); 16 | sb.append("\r\n======================================================================\r\n"); 17 | System.out.println(sb.toString()); 18 | return super.initWebApplicationContext(servletContext); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /rz-web/src/main/java/com/rick/scaffold/common/security/AuthenticationFilter.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.common.security; 2 | 3 | import javax.servlet.ServletRequest; 4 | import javax.servlet.ServletResponse; 5 | 6 | import org.apache.commons.lang3.StringUtils; 7 | import org.apache.shiro.authc.AuthenticationException; 8 | import org.apache.shiro.authc.AuthenticationToken; 9 | import org.apache.shiro.authc.IncorrectCredentialsException; 10 | import org.apache.shiro.authc.UnknownAccountException; 11 | import org.apache.shiro.authc.UsernamePasswordToken; 12 | import org.apache.shiro.web.filter.authc.FormAuthenticationFilter; 13 | import org.apache.shiro.web.util.WebUtils; 14 | import org.slf4j.Logger; 15 | import org.slf4j.LoggerFactory; 16 | 17 | public class AuthenticationFilter extends FormAuthenticationFilter { 18 | 19 | private Logger logger = LoggerFactory.getLogger(getClass()); 20 | 21 | protected AuthenticationToken createToken(ServletRequest request, ServletResponse response) { 22 | String username = getUsername(request); 23 | String password = getPassword(request); 24 | if (password==null){ 25 | password = ""; 26 | } 27 | boolean rememberMe = isRememberMe(request); 28 | return new UsernamePasswordToken(username, password, rememberMe); 29 | } 30 | 31 | /** 32 | * 登录成功之后跳转URL 33 | */ 34 | public String getSuccessUrl() { 35 | return super.getSuccessUrl(); 36 | } 37 | 38 | @Override 39 | protected void issueSuccessRedirect(ServletRequest request, 40 | ServletResponse response) throws Exception { 41 | // Principal p = UserUtils.getPrincipal(); 42 | // if (p != null && !p.isMobileLogin()){ 43 | WebUtils.issueRedirect(request, response, getSuccessUrl(), null, true); 44 | // }else{ 45 | // super.issueSuccessRedirect(request, response); 46 | // } 47 | } 48 | 49 | /** 50 | * 登录失败调用事件 51 | */ 52 | @Override 53 | protected boolean onLoginFailure(AuthenticationToken token, 54 | AuthenticationException e, ServletRequest request, ServletResponse response) { 55 | String className = e.getClass().getName(); 56 | String message = ""; 57 | if (IncorrectCredentialsException.class.getName().equals(className) 58 | || UnknownAccountException.class.getName().equals(className)){ 59 | message = "用户或密码错误, 请重试."; 60 | } 61 | else if (e.getMessage() != null && StringUtils.startsWith(e.getMessage(), "msg:")){ 62 | message = StringUtils.replace(e.getMessage(), "msg:", ""); 63 | } 64 | else{ 65 | message = "系统出现点问题,请稍后再试!"; 66 | e.printStackTrace(); // 输出到控制台 67 | } 68 | request.setAttribute(getFailureKeyAttribute(), className); 69 | request.setAttribute("message", message); 70 | return true; 71 | } 72 | 73 | } -------------------------------------------------------------------------------- /rz-web/src/main/java/com/rick/scaffold/common/security/AuthenticationInterceptor.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.common.security; 2 | 3 | import javax.servlet.http.HttpServletRequest; 4 | import javax.servlet.http.HttpServletResponse; 5 | 6 | import org.slf4j.Logger; 7 | import org.slf4j.LoggerFactory; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.util.StringUtils; 10 | import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; 11 | 12 | import com.rick.scaffold.common.Constants; 13 | import com.rick.scaffold.exception.APIException; 14 | 15 | public class AuthenticationInterceptor extends HandlerInterceptorAdapter { 16 | 17 | private static final Logger logger = LoggerFactory 18 | .getLogger(AuthenticationInterceptor.class); 19 | 20 | @Autowired 21 | private SecurityComponent securityComponent; 22 | 23 | @Override 24 | public boolean preHandle(HttpServletRequest request, 25 | HttpServletResponse response, Object handler) throws Exception { 26 | 27 | //TODO cache token 28 | String token = request.getHeader("Authorization"); 29 | if(StringUtils.isEmpty(token)) { 30 | logger.error("Has no token! " + request.getRequestURI()); 31 | throw new APIException("非法用户", 401); 32 | } else if(token.equals("guest")) { 33 | request.setAttribute("userId", 0L); 34 | request.setAttribute("userRole", "guest"); 35 | } else { 36 | String userInfo = securityComponent.decrypt(token); 37 | if(userInfo == null) { 38 | throw new APIException("非法用户", 401); 39 | } 40 | try { 41 | String[] s = userInfo.split(Constants.STRING_SEPERATOR); 42 | String userId = s[0]; 43 | String userRole = s[1]; 44 | request.setAttribute("userId", Long.valueOf(userId)); 45 | request.setAttribute("userRole", userRole); 46 | } catch (Exception e) { 47 | throw new APIException("非法用户", 401); 48 | } 49 | } 50 | return true; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /rz-web/src/main/java/com/rick/scaffold/exception/APIException.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.exception; 2 | 3 | public class APIException extends CommonException { 4 | 5 | private static final long serialVersionUID = 1L; 6 | 7 | private int errorCode; 8 | 9 | public APIException(String message) { 10 | super(message); 11 | this.errorCode = 500; 12 | } 13 | 14 | public APIException(String message, Throwable e) { 15 | super(message, e); 16 | this.errorCode = 500; 17 | } 18 | 19 | public APIException(String message, int errorCode) { 20 | super(message); 21 | this.errorCode = errorCode; 22 | } 23 | 24 | public APIException(String message, int errorCode, Throwable e) { 25 | super(message, e); 26 | this.errorCode = errorCode; 27 | } 28 | 29 | // use when test 30 | public APIException(String message, int errorCode, String trackId) { 31 | super(message); 32 | this.errorCode = errorCode; 33 | this.trackId = trackId; 34 | } 35 | 36 | // use when test 37 | public APIException(String message, int errorCode, String trackId, 38 | Throwable e) { 39 | super(message, e); 40 | this.errorCode = errorCode; 41 | this.trackId = trackId; 42 | } 43 | 44 | public int getErrorCode() { 45 | return errorCode; 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /rz-web/src/main/java/com/rick/scaffold/exception/CommonException.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.exception; 2 | 3 | import com.rick.scaffold.common.utils.ExceptionUtils; 4 | 5 | 6 | public abstract class CommonException extends Exception { 7 | 8 | /** 9 | * 10 | */ 11 | private static final long serialVersionUID = 1L; 12 | 13 | protected String trackId; 14 | 15 | public CommonException(String message) { 16 | super(message); 17 | this.trackId = ExceptionUtils.getTrackID(); 18 | } 19 | 20 | public CommonException(String message, Throwable e) { 21 | super(message, e); 22 | this.trackId = ExceptionUtils.getTrackID(); 23 | } 24 | 25 | public String getTrackId() { 26 | return trackId; 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /rz-web/src/main/java/com/rick/scaffold/soa/hbase/HbaseResult.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.soa.hbase; 2 | 3 | import java.io.Serializable; 4 | 5 | /** 6 | * Created by user on 16/3/18. 7 | */ 8 | public class HbaseResult implements Serializable { 9 | 10 | private static final long serialVersionUID = 1L; 11 | 12 | private String rowKey; 13 | 14 | private Long timestamp; 15 | 16 | private String colFamily; 17 | 18 | private String colName; 19 | 20 | private String value; 21 | 22 | public String getRowKey() { 23 | return rowKey; 24 | } 25 | 26 | public void setRowKey(String rowKey) { 27 | this.rowKey = rowKey; 28 | } 29 | 30 | public Long getTimestamp() { 31 | return timestamp; 32 | } 33 | 34 | public void setTimestamp(Long timestamp) { 35 | this.timestamp = timestamp; 36 | } 37 | 38 | public String getColFamily() { 39 | return colFamily; 40 | } 41 | 42 | public void setColFamily(String colFamily) { 43 | this.colFamily = colFamily; 44 | } 45 | 46 | public String getColName() { 47 | return colName; 48 | } 49 | 50 | public void setColName(String colName) { 51 | this.colName = colName; 52 | } 53 | 54 | public String getValue() { 55 | return value; 56 | } 57 | 58 | public void setValue(String value) { 59 | this.value = value; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /rz-web/src/main/java/com/rick/scaffold/soa/hbase/service/GoodsHbase.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.soa.hbase.service; 2 | 3 | import com.rick.scaffold.soa.hbase.HbaseResult; 4 | 5 | import java.io.IOException; 6 | import java.util.List; 7 | 8 | /** 9 | * Created by user on 16/3/18. 10 | */ 11 | public interface GoodsHbase { 12 | 13 | void insertDescription(String rowkey, String val); 14 | 15 | List getDescription(String rowkey); 16 | 17 | List scanData(String startRow, String stopRow); 18 | 19 | void delDescription(String rowkey) throws IOException; 20 | } 21 | -------------------------------------------------------------------------------- /rz-web/src/main/java/com/rick/scaffold/soa/search/IndexObject.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.soa.search; 2 | 3 | import java.io.Serializable; 4 | 5 | public abstract class IndexObject implements Serializable { 6 | 7 | private static final long serialVersionUID = 1L; 8 | 9 | private Long id; 10 | 11 | public Long getId() { 12 | return id; 13 | } 14 | 15 | public void setId(Long id) { 16 | this.id = id; 17 | } 18 | 19 | 20 | } 21 | -------------------------------------------------------------------------------- /rz-web/src/main/java/com/rick/scaffold/soa/search/SearchEntry.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.soa.search; 2 | 3 | import java.io.Serializable; 4 | import java.util.List; 5 | 6 | public class SearchEntry implements Serializable { 7 | 8 | private static final long serialVersionUID = 1L; 9 | 10 | private IndexObject indexObject; 11 | private List highlights; 12 | 13 | public void setHighlights(List highlights) { 14 | this.highlights = highlights; 15 | } 16 | public List getHighlights() { 17 | return highlights; 18 | } 19 | public IndexObject getIndexObject() { 20 | return indexObject; 21 | } 22 | public void setIndexUser(IndexObject indexObject) { 23 | this.indexObject = indexObject; 24 | } 25 | 26 | 27 | 28 | } 29 | -------------------------------------------------------------------------------- /rz-web/src/main/java/com/rick/scaffold/soa/search/SearchFacet.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.soa.search; 2 | 3 | import java.io.Serializable; 4 | 5 | public class SearchFacet implements Serializable { 6 | 7 | private static final long serialVersionUID = 1L; 8 | 9 | private String name; 10 | private String key; 11 | private long count; 12 | 13 | public void setKey(String key) { 14 | this.key = key; 15 | } 16 | public String getKey() { 17 | return key; 18 | } 19 | public void setName(String name) { 20 | this.name = name; 21 | } 22 | public String getName() { 23 | return name; 24 | } 25 | public void setCount(long count) { 26 | this.count = count; 27 | } 28 | public long getCount() { 29 | return count; 30 | }; 31 | 32 | } 33 | -------------------------------------------------------------------------------- /rz-web/src/main/java/com/rick/scaffold/soa/search/SearchKeywords.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.soa.search; 2 | 3 | import java.io.Serializable; 4 | import java.util.List; 5 | 6 | public class SearchKeywords implements Serializable{ 7 | 8 | private static final long serialVersionUID = 1L; 9 | private List keywords; 10 | 11 | public void setKeywords(List keywords) { 12 | this.keywords = keywords; 13 | } 14 | 15 | public List getKeywords() { 16 | return keywords; 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /rz-web/src/main/java/com/rick/scaffold/soa/search/SearchResult.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.soa.search; 2 | 3 | import java.io.Serializable; 4 | import java.util.List; 5 | import java.util.Map; 6 | 7 | public class SearchResult implements Serializable{ 8 | 9 | private static final long serialVersionUID = 1L; 10 | private int totalCount = 0;//total number of entries 11 | private int entryCount = 0;//number of entries asked 12 | 13 | private List entries; 14 | private Map> facets;//facet key (example : category) & facet description (example : category code) 15 | 16 | public void setTotalCount(int totalCount) { 17 | this.totalCount = totalCount; 18 | } 19 | public int getTotalCount() { 20 | return totalCount; 21 | } 22 | public void setEntryCount(int entryCount) { 23 | this.entryCount = entryCount; 24 | } 25 | public int getEntryCount() { 26 | return entryCount; 27 | } 28 | public void setEntries(List entries) { 29 | this.entries = entries; 30 | } 31 | public List getEntries() { 32 | return entries; 33 | } 34 | public void setFacets(Map> facets) { 35 | this.facets = facets; 36 | } 37 | public Map> getFacets() { 38 | return facets; 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /rz-web/src/main/java/com/rick/scaffold/soa/search/model/IndexGoods.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.soa.search.model; 2 | 3 | import com.rick.scaffold.soa.search.IndexObject; 4 | 5 | 6 | public class IndexGoods extends IndexObject { 7 | 8 | private String name; 9 | 10 | private String sn; 11 | 12 | private Float shop_price; 13 | 14 | private Long shop_id; 15 | private Long cate_id; 16 | 17 | public String getName() { 18 | return name; 19 | } 20 | 21 | public void setName(String name) { 22 | this.name = name; 23 | } 24 | 25 | public String getSn() { 26 | return sn; 27 | } 28 | 29 | public void setSn(String sn) { 30 | this.sn = sn; 31 | } 32 | 33 | public Float getShop_price() { 34 | return shop_price; 35 | } 36 | 37 | public void setShop_price(Float shop_price) { 38 | this.shop_price = shop_price; 39 | } 40 | 41 | public Long getShop_id() { 42 | return shop_id; 43 | } 44 | 45 | public void setShop_id(Long shop_id) { 46 | this.shop_id = shop_id; 47 | } 48 | 49 | public Long getCate_id() { 50 | return cate_id; 51 | } 52 | 53 | public void setCate_id(Long cate_id) { 54 | this.cate_id = cate_id; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /rz-web/src/main/java/com/rick/scaffold/soa/search/service/GoodsSearch.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.soa.search.service; 2 | 3 | import com.rick.scaffold.soa.search.SearchKeywords; 4 | import com.rick.scaffold.soa.search.SearchResult; 5 | import com.rick.scaffold.soa.search.model.IndexGoods; 6 | 7 | public interface GoodsSearch { 8 | 9 | void importFromDB(String sql) throws Exception; 10 | 11 | void importKeywordFromDB(String sql) throws Exception; 12 | 13 | void createIndex(IndexGoods goods); 14 | 15 | void deleteIndex(Long id); 16 | 17 | SearchKeywords searchAutoComplete(String index, String type, String keyword, int entriesCount); 18 | 19 | SearchResult search(String jsonString, int startIndex, int entriesCount); 20 | } 21 | -------------------------------------------------------------------------------- /rz-web/src/main/java/com/rick/scaffold/web/api/product/ProductAPI.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.web.api.product; 2 | 3 | import com.rick.scaffold.soa.search.service.GoodsSearch; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.http.ResponseEntity; 6 | import org.springframework.stereotype.Controller; 7 | import org.springframework.web.bind.annotation.RequestBody; 8 | import org.springframework.web.bind.annotation.RequestMapping; 9 | import org.springframework.web.bind.annotation.RequestMethod; 10 | import org.springframework.web.bind.annotation.ResponseBody; 11 | 12 | import com.fasterxml.jackson.databind.JsonNode; 13 | import com.rick.scaffold.exception.APIException; 14 | import com.rick.scaffold.soa.search.SearchKeywords; 15 | import com.rick.scaffold.web.api.generic.BaseAPI; 16 | 17 | @Controller("productApiV1") 18 | @RequestMapping(value="/api/v1/product",produces={"application/json;charset=UTF-8"}) 19 | public class ProductAPI extends BaseAPI{ 20 | 21 | @Autowired 22 | private GoodsSearch gs; 23 | 24 | @RequestMapping(value = "/typeAhead", method=RequestMethod.POST) 25 | @ResponseBody 26 | public ResponseEntity productTypeAhead(@RequestBody JsonNode node) throws APIException { 27 | String keyword = node.path("keyword").asText(); 28 | String index = "scaffold"; 29 | String type = "goods"; 30 | SearchKeywords sk = gs.searchAutoComplete(index, type, keyword, 10); 31 | System.out.println(sk.getKeywords().size()); 32 | return responseSuccess(sk.getKeywords()); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /rz-web/src/main/java/com/rick/scaffold/web/api/user/UserAPI.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.web.api.user; 2 | 3 | import java.util.List; 4 | import java.util.Map; 5 | 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.http.ResponseEntity; 8 | import org.springframework.stereotype.Controller; 9 | import org.springframework.web.bind.annotation.PathVariable; 10 | import org.springframework.web.bind.annotation.RequestMapping; 11 | import org.springframework.web.bind.annotation.RequestMethod; 12 | import org.springframework.web.bind.annotation.ResponseBody; 13 | 14 | import com.rick.scaffold.core.entity.user.FullUser; 15 | import com.rick.scaffold.core.service.user.UserService; 16 | import com.rick.scaffold.exception.APIException; 17 | import com.rick.scaffold.web.api.generic.BaseAPI; 18 | 19 | @Controller("userApiV1") 20 | @RequestMapping(value="/api/v1/user",produces={"application/json;charset=UTF-8"}) 21 | public class UserAPI extends BaseAPI{ 22 | 23 | @Autowired 24 | private UserService userService; 25 | 26 | @RequestMapping(value = "/{id}", method=RequestMethod.GET) 27 | @ResponseBody 28 | public ResponseEntity getUser(@PathVariable("id") String id) throws APIException { 29 | // Map users = userService.findAll1(); 30 | List users = userService.findLazy(56886380597248L); 31 | return responseSuccess(users); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /rz-web/src/main/java/com/rick/scaffold/web/bean/generic/FailBean.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.web.bean.generic; 2 | 3 | public class FailBean { 4 | 5 | private int code; 6 | private String status; 7 | private String message; 8 | private String trackId; 9 | 10 | public FailBean(int code, String status, String message, String trackId) { 11 | this.code = code; 12 | this.status = status; 13 | this.message = message; 14 | this.trackId = trackId; 15 | } 16 | 17 | public int getCode() { 18 | return code; 19 | } 20 | 21 | public String getStatus() { 22 | return status; 23 | } 24 | 25 | public String getMessage() { 26 | return message; 27 | } 28 | 29 | public String getTrackId() { 30 | return trackId; 31 | } 32 | 33 | 34 | 35 | } 36 | -------------------------------------------------------------------------------- /rz-web/src/main/java/com/rick/scaffold/web/bean/generic/SuccessBean.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.web.bean.generic; 2 | 3 | public class SuccessBean { 4 | 5 | private int code; 6 | private String status; 7 | private Object data; 8 | 9 | public SuccessBean(int code, String status, Object data) { 10 | this.code = code; 11 | this.status = status; 12 | this.data = data; 13 | } 14 | 15 | public int getCode() { 16 | return code; 17 | } 18 | 19 | public String getStatus() { 20 | return status; 21 | } 22 | 23 | public Object getData() { 24 | return data; 25 | } 26 | 27 | 28 | 29 | 30 | } 31 | -------------------------------------------------------------------------------- /rz-web/src/main/java/com/rick/scaffold/web/controller/AdminController.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.web.controller; 2 | 3 | import org.springframework.stereotype.Controller; 4 | import org.springframework.ui.Model; 5 | import org.springframework.web.bind.annotation.RequestMapping; 6 | import org.springframework.web.bind.annotation.RequestMethod; 7 | 8 | import com.rick.scaffold.common.config.Global; 9 | 10 | @Controller 11 | public class AdminController { 12 | 13 | @RequestMapping(value="/admin", method=RequestMethod.GET) 14 | public String displayLogin(Model model) { 15 | String staticDomain = Global.getConfig("global.staticDomain"); 16 | model.addAttribute("staticDomain", staticDomain); 17 | return "adminIndex"; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /rz-web/src/main/java/com/rick/scaffold/web/controller/LoginController.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.web.controller; 2 | 3 | import javax.servlet.http.HttpServletRequest; 4 | import javax.servlet.http.HttpServletResponse; 5 | 6 | import org.springframework.stereotype.Controller; 7 | import org.springframework.ui.Model; 8 | import org.springframework.web.bind.annotation.RequestMapping; 9 | import org.springframework.web.bind.annotation.RequestMethod; 10 | 11 | import com.rick.scaffold.common.config.Global; 12 | 13 | @Controller 14 | public class LoginController { 15 | 16 | @RequestMapping(value="/admin/login", method=RequestMethod.GET) 17 | public String displayLogin(HttpServletRequest request, Model model) { 18 | String productName = Global.getConfig("global.productName"); 19 | String version = Global.getConfig("global.version"); 20 | String staticDomain = Global.getConfig("global.staticDomain"); 21 | model.addAttribute("productName", productName); 22 | model.addAttribute("version", version); 23 | model.addAttribute("staticDomain", staticDomain); 24 | return "login"; 25 | } 26 | 27 | /** 28 | * 登录失败,真正登录的POST请求由Filter完成 29 | */ 30 | @RequestMapping(value = "/admin/login", method = RequestMethod.POST) 31 | public String loginFail(HttpServletRequest request, HttpServletResponse response, Model model) { 32 | String message = (String)request.getAttribute("message"); 33 | if (message == null){ 34 | return "redirect:/admin"; 35 | } else { 36 | String productName = Global.getConfig("global.productName"); 37 | String version = Global.getConfig("global.version"); 38 | String staticDomain = Global.getConfig("global.staticDomain"); 39 | model.addAttribute("productName", productName); 40 | model.addAttribute("version", version); 41 | model.addAttribute("staticDomain", staticDomain); 42 | return "login"; 43 | } 44 | 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /rz-web/src/main/resources/config/logger/log4j.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /rz-web/src/main/resources/config/spring/spring-shiro.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | Shiro Configuration 9 | 10 | 11 | 12 | 13 | 14 | /admin/login = authc 15 | /admin/logout = logout 16 | /admin/** = user 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /rz-web/src/main/resources/config/spring/spring-soa.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /rz-web/src/main/resources/config/spring/spring-web.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | Spring Web 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /rz-web/src/main/webapp/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Class-Path: 3 | 4 | -------------------------------------------------------------------------------- /rz-web/src/main/webapp/WEB-INF/.gitignore: -------------------------------------------------------------------------------- 1 | /classes 2 | -------------------------------------------------------------------------------- /rz-web/src/main/webapp/WEB-INF/views/adminIndex.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> 2 | 3 | 4 | 5 | 6 | scaffold管理平台 7 | 8 | 9 | 10 | 11 | 15 | 16 |
17 | 没有该商品 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /rz-web/src/main/webapp/WEB-INF/views/error/404.jsp: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 404 - 页面不存在 5 | 6 | 7 |
404 - 页面不存在
8 | 9 | -------------------------------------------------------------------------------- /rz-web/src/main/webapp/WEB-INF/views/error/500.jsp: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 500 - 系统内部错误 5 | 6 | 7 |
500 - 系统内部错误
8 | 9 | -------------------------------------------------------------------------------- /rz-web/src/main/webapp/static/css/jquery.validate.min.css: -------------------------------------------------------------------------------- 1 | label.error{background:url("images/unchecked.gif") no-repeat 0 0;padding-left:18px;padding-bottom:2px;font-weight:bold;color:#ea5200;margin-left:10px} -------------------------------------------------------------------------------- /rz-web/src/test/java/com/rick/scaffold/api/user/TestUser.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.api.user; 2 | 3 | import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; 4 | import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; 5 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; 6 | 7 | import org.junit.Test; 8 | import org.springframework.http.MediaType; 9 | 10 | import com.rick.scaffold.base.BaseApiTest; 11 | 12 | 13 | public class TestUser extends BaseApiTest { 14 | 15 | @Test 16 | public void testGetUserAPI() throws Exception { 17 | mockMvc.perform(get("/api/user/1").accept(MediaType.APPLICATION_JSON)). 18 | andDo(print()). 19 | andExpect(status().isOk()); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /rz-web/src/test/java/com/rick/scaffold/base/BaseApiTest.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.base; 2 | 3 | import org.junit.Before; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.test.context.web.WebAppConfiguration; 6 | import org.springframework.test.web.servlet.MockMvc; 7 | import org.springframework.test.web.servlet.setup.MockMvcBuilders; 8 | import org.springframework.web.context.WebApplicationContext; 9 | 10 | @WebAppConfiguration 11 | public abstract class BaseApiTest extends BaseTest { 12 | 13 | protected MockMvc mockMvc; 14 | 15 | @Autowired 16 | private WebApplicationContext wac; 17 | 18 | @Before 19 | public void setUp() { 20 | this.mockMvc = MockMvcBuilders.webAppContextSetup(this.wac).build(); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /rz-web/src/test/java/com/rick/scaffold/base/BaseTest.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.base; 2 | 3 | import org.junit.runner.RunWith; 4 | import org.springframework.test.context.ContextConfiguration; 5 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 6 | 7 | @RunWith(SpringJUnit4ClassRunner.class) 8 | @ContextConfiguration(locations = "classpath:test-applicationContext-all.xml") 9 | public abstract class BaseTest { 10 | 11 | } 12 | -------------------------------------------------------------------------------- /rz-web/src/test/java/com/rick/scaffold/service/goods/TestGoods.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.service.goods; 2 | 3 | import com.rick.scaffold.base.BaseTest; 4 | import com.rick.scaffold.common.jsontool.JsonMapper; 5 | import com.rick.scaffold.core.entity.goods.Goods; 6 | import com.rick.scaffold.core.service.goods.GoodsService; 7 | import com.rick.scaffold.soa.hbase.service.GoodsHbase; 8 | import org.junit.Test; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | 11 | /** 12 | * Created by user on 16/3/21. 13 | */ 14 | public class TestGoods extends BaseTest { 15 | 16 | @Autowired 17 | private GoodsService gs; 18 | 19 | @Autowired 20 | private GoodsHbase gh; 21 | 22 | @Test 23 | public void testGetGoods() { 24 | long goodsId = 4L; 25 | Goods g = gs.findOne(goodsId); 26 | g.setDescription(gh.getDescription(g.getShopId() + "-" + goodsId).get(0).getValue()); 27 | System.out.println(JsonMapper.toJsonString(g)); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /rz-web/src/test/java/com/rick/scaffold/service/goods/TestHbase.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.service.goods; 2 | 3 | import com.rick.scaffold.base.BaseTest; 4 | import com.rick.scaffold.soa.hbase.HbaseResult; 5 | import com.rick.scaffold.soa.hbase.service.GoodsHbase; 6 | import org.junit.Test; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | 9 | import java.util.List; 10 | 11 | /** 12 | * Created by user on 16/3/18. 13 | */ 14 | public class TestHbase extends BaseTest { 15 | 16 | @Autowired 17 | private GoodsHbase gh; 18 | 19 | @Test 20 | public void testInsertGoodsDescription() throws Exception { 21 | gh.insertDescription("1-4", "Rick帅的一比"); 22 | } 23 | 24 | @Test 25 | public void testGetData() throws Exception { 26 | List hrs = gh.getDescription("1-4"); 27 | for(HbaseResult hr: hrs) { 28 | System.out.println(hr.getValue()); 29 | } 30 | System.out.println(hrs.size()); 31 | } 32 | 33 | @Test 34 | public void testScanData() throws Exception { 35 | List hrs = gh.scanData("1-4", "1-5"); 36 | for(HbaseResult hr: hrs) { 37 | System.out.println(hr.getValue()); 38 | } 39 | System.out.println(hrs.size()); 40 | } 41 | 42 | @Test 43 | public void testDeleteRow() throws Exception { 44 | gh.delDescription("1-4"); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /rz-web/src/test/java/com/rick/scaffold/service/user/TestCompany.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.service.user; 2 | 3 | import org.junit.Test; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | 6 | import com.rick.scaffold.base.BaseTest; 7 | import com.rick.scaffold.core.entity.user.Company; 8 | import com.rick.scaffold.core.service.user.CompanyService; 9 | 10 | public class TestCompany extends BaseTest{ 11 | 12 | @Autowired 13 | private CompanyService cs; 14 | 15 | @Test 16 | public void testAddCompany() { 17 | Company c = new Company(); 18 | c.setName("yzl"); 19 | c.setPhone("12345"); 20 | cs.save(c); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /rz-web/src/test/java/com/rick/scaffold/service/user/TestES.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.service.user; 2 | 3 | import com.rick.scaffold.base.BaseTest; 4 | import com.rick.scaffold.common.utils.FileUtils; 5 | import com.rick.scaffold.soa.search.SearchEntry; 6 | import com.rick.scaffold.soa.search.SearchKeywords; 7 | import com.rick.scaffold.soa.search.SearchResult; 8 | import com.rick.scaffold.soa.search.model.IndexGoods; 9 | import com.rick.scaffold.soa.search.service.GoodsSearch; 10 | import org.junit.Test; 11 | import org.springframework.beans.factory.annotation.Autowired; 12 | 13 | public class TestES extends BaseTest { 14 | 15 | @Autowired 16 | private GoodsSearch gs; 17 | 18 | 19 | @Test 20 | public void testCreateIndex() { 21 | IndexGoods ig = new IndexGoods(); 22 | ig.setCate_id(1L); 23 | ig.setName("指南针6"); 24 | ig.setShop_id(1L); 25 | ig.setShop_price(20f); 26 | ig.setSn("123456"); 27 | ig.setId(200001L); 28 | gs.createIndex(ig); 29 | } 30 | 31 | @Test 32 | public void testDeleteIndex() { 33 | try { 34 | gs.deleteIndex(200001L); 35 | } catch (Exception e) { 36 | // TODO Auto-generated catch block 37 | e.printStackTrace(); 38 | } 39 | } 40 | 41 | @Test 42 | public void testSearchKeyWords() { 43 | String index = "scaffold"; 44 | String type = "goods"; 45 | SearchKeywords sk = gs.searchAutoComplete(index, type, "康师傅", 10); 46 | System.out.println(sk.getKeywords().size()); 47 | for(String s: sk.getKeywords()) { 48 | System.out.print(s + ","); 49 | } 50 | } 51 | 52 | @Test 53 | public void testSearch() { 54 | String json = FileUtils.readFileAsString("complex_search.json"); 55 | SearchResult sr = gs.search(json, 0, -1); 56 | for(SearchEntry se: sr.getEntries()) { 57 | IndexGoods goods = (IndexGoods)se.getIndexObject(); 58 | System.out.println(goods.getName()); 59 | } 60 | } 61 | 62 | 63 | } 64 | -------------------------------------------------------------------------------- /rz-web/src/test/java/com/rick/scaffold/service/user/TestPhoto.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.service.user; 2 | 3 | import org.junit.Test; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | 6 | import com.rick.scaffold.base.BaseTest; 7 | import com.rick.scaffold.core.entity.user.Photo; 8 | import com.rick.scaffold.core.service.user.PhotoService; 9 | 10 | public class TestPhoto extends BaseTest{ 11 | 12 | @Autowired 13 | private PhotoService ps; 14 | 15 | @Test 16 | public void testAddPhoto() { 17 | Photo p = new Photo(); 18 | p.setSize(102); 19 | p.setUrl("sina.com"); 20 | p.setUserId(56886380597248L); 21 | ps.save(p); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /rz-web/src/test/java/com/rick/scaffold/service/user/TestRedis.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.service.user; 2 | 3 | import java.util.List; 4 | 5 | import org.junit.Test; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | 8 | import com.rick.scaffold.base.BaseTest; 9 | import com.rick.scaffold.common.jsontool.JsonMapper; 10 | import com.rick.scaffold.common.utils.JedisUtils; 11 | import com.rick.scaffold.core.entity.user.User; 12 | import com.rick.scaffold.core.service.user.UserService; 13 | 14 | public class TestRedis extends BaseTest { 15 | 16 | @Autowired 17 | private UserService us; 18 | 19 | @Test 20 | public void testRedis() { 21 | JedisUtils.set("xx", "g", 0); 22 | JedisUtils.set("xx", "e", 0); 23 | String s = JedisUtils.get("xx"); 24 | List list = JedisUtils.getList("xx"); 25 | System.out.println(s); 26 | System.out.println(list == null); 27 | long res = JedisUtils.del("abc"); 28 | System.out.println(res); 29 | long res1 = JedisUtils.del("xx"); 30 | System.out.println(res1); 31 | } 32 | 33 | @Test 34 | public void testUS() { 35 | User user = us.findOne(111L); 36 | System.out.println(JsonMapper.toJsonString(user)); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /rz-web/src/test/java/com/rick/scaffold/service/user/TestUser.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.service.user; 2 | 3 | import java.util.List; 4 | import java.util.Map; 5 | 6 | import org.junit.Test; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | 9 | import com.google.common.base.Optional; 10 | import com.rick.scaffold.base.BaseTest; 11 | import com.rick.scaffold.common.jsontool.JsonMapper; 12 | import com.rick.scaffold.common.security.SecurityComponent; 13 | import com.rick.scaffold.common.utils.JedisUtils; 14 | import com.rick.scaffold.core.entity.user.FullUser; 15 | import com.rick.scaffold.core.entity.user.Photo; 16 | import com.rick.scaffold.core.entity.user.User; 17 | import com.rick.scaffold.core.service.user.PhotoService; 18 | import com.rick.scaffold.core.service.user.UserService; 19 | 20 | public class TestUser extends BaseTest{ 21 | 22 | @Autowired 23 | private UserService us; 24 | 25 | @Autowired 26 | private PhotoService ps; 27 | 28 | @Autowired 29 | private SecurityComponent sc; 30 | 31 | @Test 32 | public void testAddUser() { 33 | User user = new User(); 34 | user.setLoginName("Eros"); 35 | user.setPassword("password"); 36 | user.setName("zzh"); 37 | user.setCompanyId(54977938722816L); 38 | int res = us.saveAndCache(user); 39 | System.out.println(res); 40 | } 41 | 42 | @Test 43 | public void testAddUserWithPassword() { 44 | User user = new User(); 45 | user.setLoginName("zzh"); 46 | user.setPassword(sc.sha1Hash("password")); 47 | user.setName("zzh"); 48 | user.setCompanyId(54977938722816L); 49 | int res = us.save(user); 50 | System.out.println(res); 51 | } 52 | 53 | @Test 54 | public void testFindOne() { 55 | Long id = 56886380597248L; //cached 56 | // String id = "56077e0d6a8ad31d5fe33a63"; //uncached 57 | // String id = "56077e0d6a8ad31d5fe33a64"; //not exist 58 | User user = (User)Optional.fromNullable(JedisUtils.getObject(id.toString())).or(us.findOne(id)); 59 | System.out.println(JsonMapper.toJsonString(user)); 60 | } 61 | 62 | @Test 63 | public void testFindOne1() { 64 | User user = us.findOne1(); 65 | System.out.println(JsonMapper.toJsonString(user)); 66 | } 67 | 68 | @Test 69 | public void testFindAll1() { 70 | Map users = us.findAll1(); 71 | System.out.println(JsonMapper.toJsonString(users)); 72 | } 73 | 74 | @Test 75 | public void testFindCascade() { 76 | List user = us.findCascade(56886380597248L); 77 | System.out.println(JsonMapper.toJsonString(user)); 78 | } 79 | 80 | @Test 81 | public void testLazy() { 82 | List user = us.findLazy(56886380597248L); 83 | FullUser u = user.get(0); 84 | Photo p = u.getPhotos().get(0); 85 | p.setSize(1); 86 | ps.update(p); 87 | u.setEmail("testEmail"); 88 | us.update(u); 89 | System.out.println(JsonMapper.toJsonString(user)); 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /rz-web/src/test/java/com/rick/scaffold/service/user/TestUsers.java: -------------------------------------------------------------------------------- 1 | package com.rick.scaffold.service.user; 2 | 3 | import com.google.common.base.Optional; 4 | import com.rick.scaffold.base.BaseTest; 5 | import com.rick.scaffold.common.jsontool.JsonMapper; 6 | import com.rick.scaffold.common.security.SecurityComponent; 7 | import com.rick.scaffold.common.utils.JedisUtils; 8 | import com.rick.scaffold.core.entity.user.FullUser; 9 | import com.rick.scaffold.core.entity.user.Photo; 10 | import com.rick.scaffold.core.entity.user.User; 11 | import com.rick.scaffold.core.entity.user.Users; 12 | import com.rick.scaffold.core.service.user.PhotoService; 13 | import com.rick.scaffold.core.service.user.UserService; 14 | import com.rick.scaffold.core.service.user.UsersService; 15 | import org.junit.Test; 16 | import org.springframework.beans.factory.annotation.Autowired; 17 | 18 | import java.util.List; 19 | import java.util.Map; 20 | 21 | public class TestUsers extends BaseTest{ 22 | 23 | @Autowired 24 | private UsersService us; 25 | 26 | @Autowired 27 | private SecurityComponent sc; 28 | 29 | 30 | @Test 31 | public void testAddUserWithPassword() { 32 | Users user = new Users(); 33 | user.setUsername("zzh"); 34 | user.setPassword(sc.sha1Hash("password")); 35 | int res = us.save(user); 36 | System.out.println(res); 37 | } 38 | 39 | 40 | } 41 | -------------------------------------------------------------------------------- /rz-web/src/test/resources/complex_search.json: -------------------------------------------------------------------------------- 1 | { 2 | "query": { 3 | "term": { 4 | "name": "红牛" 5 | } 6 | }, 7 | "filter": { 8 | "bool": { 9 | "must": { 10 | "range": { 11 | "shop_price": {"lt": 100, "gte":6} 12 | } 13 | } 14 | } 15 | }, 16 | "sort": { 17 | "shop_price": {"order": "desc"} 18 | }, 19 | "facets": { 20 | "range1": { 21 | "range": { 22 | "field": "shop_price", 23 | "ranges": [ 24 | {"from": 1, "to": 3}, 25 | {"from": 3, "to": 10} 26 | ] 27 | } 28 | } 29 | 30 | } 31 | } -------------------------------------------------------------------------------- /rz-web/src/test/resources/test-spring-soa.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /rz-web/tomcat/conf/context.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 19 | 20 | 21 | 22 | WEB-INF/web.xml 23 | 24 | 25 | 28 | 29 | 31 | 34 | 35 | 40 | 41 | 46 | 47 | -------------------------------------------------------------------------------- /rz-web/tomcat/lib/commons-pool2-2.3.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ErosZZH/scaffold/ca1ac0d3f6c0272ed34dbafe8bb0967ce357f7b5/rz-web/tomcat/lib/commons-pool2-2.3.jar -------------------------------------------------------------------------------- /rz-web/tomcat/lib/jedis-2.7.2.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ErosZZH/scaffold/ca1ac0d3f6c0272ed34dbafe8bb0967ce357f7b5/rz-web/tomcat/lib/jedis-2.7.2.jar -------------------------------------------------------------------------------- /rz-web/tomcat/lib/redis-tomcat-0.0.1-SNAPSHOT.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ErosZZH/scaffold/ca1ac0d3f6c0272ed34dbafe8bb0967ce357f7b5/rz-web/tomcat/lib/redis-tomcat-0.0.1-SNAPSHOT.jar --------------------------------------------------------------------------------