├── README.md ├── WechatIMG304.jpeg ├── account-sevice ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── simplemall │ │ │ └── account │ │ │ ├── AccountServApplication.java │ │ │ ├── config │ │ │ ├── DataSourceProperties.java │ │ │ ├── DruidDataSourceConfig.java │ │ │ └── SqlSessionFactoryConfig.java │ │ │ ├── controller │ │ │ ├── AccountController.java │ │ │ └── AddressController.java │ │ │ ├── dal │ │ │ ├── AccAddressMapper.java │ │ │ └── AccountMapper.java │ │ │ ├── service │ │ │ ├── IAccountService.java │ │ │ └── impl │ │ │ │ └── AccountServiceImpl.java │ │ │ └── web │ │ │ └── ComputeController.java │ └── resources │ │ ├── application.properties │ │ ├── bootstrap.properties │ │ ├── logback.xml │ │ └── mapper │ │ ├── AccAddressMapper.xml │ │ └── AccountMapper.xml │ └── test │ ├── java │ └── com │ │ └── simplemall │ │ └── account │ │ └── test │ │ ├── AccountControllerTest.java │ │ └── Jasyptest.java │ └── resources │ └── generatorConfig.xml ├── base-service ├── admin-server │ ├── pom.xml │ ├── src │ │ └── main │ │ │ ├── java │ │ │ └── com │ │ │ │ └── simplemall │ │ │ │ └── micro │ │ │ │ └── serv │ │ │ │ └── base │ │ │ │ └── admin │ │ │ │ ├── AdminServerApplicaton.java │ │ │ │ └── config │ │ │ │ └── SecurityConfig.java │ │ │ └── resources │ │ │ ├── application.properties │ │ │ ├── banner.txt │ │ │ └── logback.xml │ └── target │ │ └── classes │ │ └── application.properties ├── conf-server │ ├── README.md │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── com │ │ │ └── simplemall │ │ │ └── micro │ │ │ └── serv │ │ │ └── config │ │ │ └── ConfigServerApplication.java │ │ └── resources │ │ └── application.properties ├── eureka-server │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── com │ │ │ └── simplemall │ │ │ └── micro │ │ │ └── serv │ │ │ └── eureka │ │ │ └── EurekaServerApplication.java │ │ └── resources │ │ └── application.properties ├── hystrix-dashboard │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── com │ │ │ └── simplemall │ │ │ └── micro │ │ │ └── serv │ │ │ └── base │ │ │ └── hystrix │ │ │ └── HystrixDashboardApplication.java │ │ └── resources │ │ └── application.properties ├── pom.xml ├── sleuth-server │ ├── README.md │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── com │ │ │ └── simplemall │ │ │ └── micro │ │ │ └── serv │ │ │ └── base │ │ │ └── zipkin │ │ │ └── SleuthServerApplicaton.java │ │ └── resources │ │ ├── application.properties │ │ ├── bootstrap.properties │ │ ├── logback.xml │ │ └── sql │ │ └── mysql.sql ├── turbine-server │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── com │ │ │ └── simplemall │ │ │ └── micro │ │ │ └── serv │ │ │ └── base │ │ │ └── turbine │ │ │ └── TurbineApplication.java │ │ └── resources │ │ └── application.properties └── zuul-server │ ├── README.md │ ├── pom.xml │ └── src │ └── main │ ├── java │ └── com │ │ └── simplemall │ │ └── micro │ │ └── serv │ │ └── zuul │ │ ├── ZuulServerApplication.java │ │ └── filter │ │ ├── AccessTokenFilter.java │ │ ├── ErrorFilter.java │ │ ├── PostFilter.java │ │ └── RoutingFitler.java │ └── resources │ ├── application.properties │ └── logback.xml ├── common-module ├── pom.xml └── src │ └── main │ └── java │ └── com │ └── simplemall │ └── micro │ └── serv │ └── common │ ├── bean │ ├── RestAPIResult.java │ ├── account │ │ ├── AccAddress.java │ │ ├── AccAddressCriteria.java │ │ ├── Account.java │ │ └── AccountCriteria.java │ ├── order │ │ ├── OrderDTO.java │ │ ├── OrderInfo.java │ │ ├── OrderInfoCriteria.java │ │ ├── OrderProduct.java │ │ ├── OrderProductCriteria.java │ │ ├── OrderState.java │ │ └── OrderStateCriteria.java │ └── product │ │ ├── PrdExtend.java │ │ ├── PrdExtendCriteria.java │ │ ├── PrdInfo.java │ │ └── PrdInfoCriteria.java │ ├── constant │ └── SystemConstants.java │ ├── service │ ├── JedisUtil.java │ ├── RedisConfig.java │ ├── RedisDemo.java │ └── SerializeUtil.java │ ├── util │ ├── SnowflakeIdWorker.java │ └── UUIDUtils.java │ └── utils.java ├── front-app ├── README.md ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── simplemall │ │ └── micro │ │ └── serv │ │ └── page │ │ ├── FrontAPPClientApplication.java │ │ ├── HystrixConfiguration.java │ │ ├── Swagger2Config.java │ │ ├── aop │ │ └── APISecurityCheck.java │ │ ├── api │ │ ├── APIAccountController.java │ │ ├── APIOrderController.java │ │ ├── APIPayMentController.java │ │ └── APIProductController.java │ │ ├── client │ │ ├── AccountFeignClient.java │ │ ├── OrderFeignClient.java │ │ ├── ProductFeignClient.java │ │ └── hystrix │ │ │ ├── OrderFeignClientHystrix.java │ │ │ └── ProductFeignClientHystrix.java │ │ ├── security │ │ └── JWTUtils.java │ │ ├── service │ │ ├── IShoppingService.java │ │ └── impl │ │ │ └── ShopingServiceImpl.java │ │ ├── start │ │ └── StartUpLoading.java │ │ └── web │ │ └── AccountController.java │ └── resources │ ├── application.properties │ ├── bootstrap.properties │ ├── logback.xml │ └── public │ ├── bootstrap-3.3.7-dist │ ├── .DS_Store │ ├── css │ │ ├── bootstrap-theme.css │ │ ├── bootstrap-theme.css.map │ │ ├── bootstrap-theme.min.css │ │ ├── bootstrap-theme.min.css.map │ │ ├── bootstrap.css │ │ ├── bootstrap.css.map │ │ ├── bootstrap.min.css │ │ └── bootstrap.min.css.map │ ├── fonts │ │ ├── glyphicons-halflings-regular.eot │ │ ├── glyphicons-halflings-regular.svg │ │ ├── glyphicons-halflings-regular.ttf │ │ ├── glyphicons-halflings-regular.woff │ │ └── glyphicons-halflings-regular.woff2 │ └── js │ │ ├── bootstrap.js │ │ ├── bootstrap.min.js │ │ └── npm.js │ ├── checkout.html │ ├── index.html │ ├── js │ ├── jquery-3.2.1.min.js │ ├── vue-resource.min.js │ ├── vue-router.js │ └── vue.min.js │ ├── login.html │ ├── my.html │ ├── order_detail.html │ ├── order_list.html │ ├── pay.html │ ├── product_detail.html │ ├── products.html │ └── signup.html ├── getqrcode.jpeg ├── msg-service ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── simplemall │ │ └── micro │ │ └── serv │ │ └── msg │ │ ├── MsgServApplication.java │ │ ├── bean │ │ ├── MsgNotice.java │ │ └── MsgNoticeCriteria.java │ │ ├── config │ │ ├── DataSourceProperties.java │ │ ├── DruidDataSourceConfig.java │ │ └── SqlSessionFactoryConfig.java │ │ ├── controller │ │ └── MsgController.java │ │ ├── mapper │ │ └── MsgNoticeMapper.java │ │ └── service │ │ ├── IMsgService.java │ │ └── impl │ │ └── MsgServiceImpl.java │ └── resources │ ├── application.properties │ ├── banner.txt │ ├── bootstrap.properties │ ├── logback.xml │ └── mapper │ └── MsgNoticeMapper.xml ├── order-service ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── simplemall │ │ │ └── micro │ │ │ └── serv │ │ │ └── order │ │ │ ├── OrderServApplication.java │ │ │ ├── config │ │ │ ├── DataSourceProperties.java │ │ │ ├── DruidDataSourceConfig.java │ │ │ └── SqlSessionFactoryConfig.java │ │ │ ├── controller │ │ │ └── OrderController.java │ │ │ ├── mapper │ │ │ ├── OrderInfoMapper.java │ │ │ ├── OrderProductMapper.java │ │ │ └── OrderStateMapper.java │ │ │ └── service │ │ │ ├── IOrderService.java │ │ │ └── impl │ │ │ └── OrderServiceImpl.java │ └── resources │ │ ├── application.properties │ │ ├── bootstrap.properties │ │ ├── logback.xml │ │ └── mapper │ │ ├── OrderInfoMapper.xml │ │ ├── OrderProductMapper.xml │ │ └── OrderStateMapper.xml │ └── test │ └── java │ └── com │ └── test │ └── OrderDtoJsonTest.java ├── payment-service ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── simplemall │ │ │ └── pay │ │ │ ├── PaymentServApplication.java │ │ │ ├── bean │ │ │ ├── PayRecord.java │ │ │ └── PayRecordCriteria.java │ │ │ ├── config │ │ │ ├── DataSourceProperties.java │ │ │ ├── DruidDataSourceConfig.java │ │ │ └── SqlSessionFactoryConfig.java │ │ │ ├── controller │ │ │ └── PayController.java │ │ │ ├── dal │ │ │ └── PayRecordMapper.java │ │ │ └── service │ │ │ ├── IPayService.java │ │ │ └── impl │ │ │ └── PayServiceImpl.java │ └── resources │ │ ├── application.properties │ │ ├── bootstrap.properties │ │ ├── logback.xml │ │ └── mapper │ │ └── PayRecordMapper.xml │ └── test │ └── resources │ └── generatorConfig.xml ├── pom.xml ├── product-service ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── simplemall │ │ │ └── micro │ │ │ └── serv │ │ │ └── prd │ │ │ ├── ProductServApplication.java │ │ │ ├── config │ │ │ ├── DataSourceProperties.java │ │ │ ├── DruidDataSourceConfig.java │ │ │ └── SqlSessionFactoryConfig.java │ │ │ ├── controller │ │ │ └── PorudctController.java │ │ │ ├── mapper │ │ │ ├── PrdExtendMapper.java │ │ │ └── PrdInfoMapper.java │ │ │ └── service │ │ │ ├── IPrdService.java │ │ │ └── impl │ │ │ └── PrdServiceImpl.java │ └── resources │ │ ├── application.properties │ │ ├── bootstrap.properties │ │ ├── logback.xml │ │ └── mapper │ │ ├── PrdExtendMapper.xml │ │ └── PrdInfoMapper.xml │ └── test │ └── resources │ └── generatorConfig.xml ├── shopping flow.jpg └── sql ├── micro_account.sql ├── micro_msg.sql ├── micro_order.sql ├── micro_payment.sql └── micro_product.sql /README.md: -------------------------------------------------------------------------------- 1 | ## Stargazers over time 2 | 3 | [![Stargazers over time](https://starcharts.herokuapp.com/backkoms/simplemall.svg)](https://starcharts.herokuapp.com/backkoms/simplemall) 4 | 5 | # QuickStart 6 | 基于SpringCloud体系实现,简单购物流程实现,满足基本功能:注册、登录、商品列表展示、商品详情展示、订单创建、详情查看、订单支付、库存更新等等。 7 | 8 | 每个业务服务采用独立的MYSQL数据库,初期考虑用到如下组件: 9 | 1. 服务注册、发现: eureka 10 | 2. 配置管理:spring config , spring security 11 | 3. 集群容错: hystrix 12 | 4. API网关: zuul 13 | 5. 服务负载:feign+ribbon 14 | 6. api文档输出:swagger2 15 | 7. 代码简化:lombok 16 | 8. 消息队列:rabbitmq 17 | 9. 分布式锁: redis (待实现) 18 | 10. 链路跟踪:spring cloud sletuh ->zipkin 19 | 11. 安全认证:oauth2/JWT(通过JWT轻量级的实现) 20 | 12. 服务监控:spring-boot-admin 21 | 22 | 23 | # 各模块介绍 24 | 25 | | 模块名称 | 端口 | 简介 | 26 | | -------- | -----: | :----: | 27 | | admin-server | 9002 | 服务监控中心,监控所有服务模块 | 28 | | conf-server | 9004 | 分布式配置中心,结合spring-security/rabbitmq同时使用 | 29 | | eureka-server | 9003 | 服务注册中心,提供服务注册、发现功能 | 30 | | sleuth-server | 9001 | SpringCloud实现的一种分布式追踪解决方案,兼容Zipkin | 31 | | zuul-server | 9005 | API网关模块 | 32 | | account-service | 8080 | 用户服务,提供注册、登录、地址等服务 | 33 | | product-service | 8081 | 商品服务,提供商品列表、详情、库存更新等服务 | 34 | | payment-service | 8082 | 支付服务,支付记录 | 35 | | order-service | 8083 | 订单服务,提供订单创建、详情、状态变更 | 36 | | msg-service | 8084 | 消息处理服务 | 37 | | front-app       |   8088   | 前端服务,结合swagger2提供API管理(有小问题,swagger页面无法点击单个接口,可通过展开功能打开,待解决) | 38 | 39 | 40 | # 快速上手 41 | - 0、基础软件依赖,rabbitmq\redis 42 | - 1、先启动admin-server,eureka-server,conf-server三个基础服务 43 | - 2、再依次启动payment/order/product/account基础业务服务 44 | - 3、最后启动front-app服务,打开浏览器,输入http://localhost:8088/swagger-ui.html ,根据流程API依次可使用功能[swagger主界面存在bug,不能选择某个api展开收缩,可通过全部展开/收缩的形式使用] 45 | - 4、后续有时间再提供页面,基于VUE2+BOOTSTRAP,将流程串起来 46 | 47 | # 相关测试 48 | 1、启动基础eureka/config两个服务后,直接启动front-app服务,通过swagger测试商品列表或详情功能来测试hystrix的功能 49 | 1.1、启动hystrix-dashboard服务,输入监控地址http://localhost:8088/hystrix.stream可以查看监控视图 50 | 2、输入http://localhost:9005/account-service/acc/login?phone=123123&password=123123查看返回结果 51 | 52 | # 关注公众号,获取更多内容 53 | ![image](https://github.com/backkoms/backkoms.github.io/blob/master/qrcode_for_gh_28fb95c9c24c_258.jpg?raw=true) 54 | 55 | 个人主页:[https://backkoms.github.io](https://backkoms.github.io) 56 | 57 | 58 | # 基于SpringBoot+Dubbo微服务开发实战基础框架 59 | 60 | github:[https://github.com/backkoms/web-service-demo](https://github.com/backkoms/web-service-demo) 61 | 62 | github:[https://github.com/backkoms/web-api-demo](https://github.com/backkoms/web-api-demo) 63 | 64 | 65 | ### 我的知识星球,内容:个人心得体会分享(阅读、写作、职业规划、职业困惑、个人成长、技术提升)、问题提问 66 | ![](https://imgkr.cn-bj.ufileos.com/75ab2d42-80b1-4164-9ac5-c23de5f522e6.png) 67 | 68 | ### 个人微信,欢迎骚扰 69 | ![](https://imgkr.cn-bj.ufileos.com/e37c25c2-d2a4-4174-953b-07adbd0f9b56.jpeg) 70 | 71 | ### 微服务开发实战专栏(SpringCloud、SpringCloudAlibaba、Apache Dubbo) 72 | [基于商场停车收费场景的微服务开发实战专栏地址:https://xiaozhuanlan.com/msa-practice](https://xiaozhuanlan.com/msa-practice) 73 | ![](https://imgkr.cn-bj.ufileos.com/227bc922-220f-4f68-b114-132bcbd53436.jpg) 74 | -------------------------------------------------------------------------------- /WechatIMG304.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maventalker/simplemall/12c5070c4dc0abbae4d78d723c5e51cb43442dd6/WechatIMG304.jpeg -------------------------------------------------------------------------------- /account-sevice/src/main/java/com/simplemall/account/AccountServApplication.java: -------------------------------------------------------------------------------- 1 | package com.simplemall.account; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; 6 | import org.springframework.cloud.netflix.hystrix.EnableHystrix; 7 | 8 | /** 9 | * 启动类 10 | * 11 | * @author guooo 12 | * 13 | */ 14 | @SpringBootApplication 15 | @EnableDiscoveryClient 16 | @EnableHystrix 17 | public class AccountServApplication { 18 | 19 | public static void main(String[] args) { 20 | SpringApplication.run(AccountServApplication.class, args); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /account-sevice/src/main/java/com/simplemall/account/config/DruidDataSourceConfig.java: -------------------------------------------------------------------------------- 1 | package com.simplemall.account.config; 2 | 3 | import com.alibaba.druid.pool.DruidDataSource; 4 | import org.slf4j.Logger; 5 | import org.slf4j.LoggerFactory; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.boot.context.properties.EnableConfigurationProperties; 8 | import org.springframework.context.annotation.Bean; 9 | import org.springframework.context.annotation.Configuration; 10 | import org.springframework.context.annotation.Primary; 11 | 12 | import javax.sql.DataSource; 13 | import java.sql.SQLException; 14 | 15 | @Configuration 16 | @EnableConfigurationProperties(DataSourceProperties.class) 17 | public class DruidDataSourceConfig { 18 | 19 | private static Logger logger = LoggerFactory.getLogger(DruidDataSourceConfig.class); 20 | 21 | @Autowired 22 | private DataSourceProperties dataSourceProperties; 23 | 24 | @Bean 25 | @Primary 26 | public DataSource druidDataSource(){ 27 | DruidDataSource datasource = new DruidDataSource(); 28 | 29 | datasource.setUrl(dataSourceProperties.getUrl()); 30 | datasource.setUsername(dataSourceProperties.getUsername()); 31 | datasource.setPassword(dataSourceProperties.getPassword()); 32 | datasource.setDriverClassName(dataSourceProperties.getDriverClassName()); 33 | datasource.setInitialSize(dataSourceProperties.getInitialSize()); 34 | datasource.setMinIdle(dataSourceProperties.getMinIdle()); 35 | datasource.setMaxActive(dataSourceProperties.getMaxActive()); 36 | datasource.setMaxWait(dataSourceProperties.getMaxWait()); 37 | datasource.setTimeBetweenEvictionRunsMillis(dataSourceProperties.getTimeBetweenEvictionRunsMillis()); 38 | datasource.setMinEvictableIdleTimeMillis(dataSourceProperties.getMinEvictableIdleTimeMillis()); 39 | datasource.setValidationQuery(dataSourceProperties.getValidationQuery()); 40 | datasource.setTestWhileIdle(dataSourceProperties.isTestWhileIdle()); 41 | datasource.setTestOnBorrow(dataSourceProperties.isTestOnBorrow()); 42 | datasource.setTestOnReturn(dataSourceProperties.isTestOnReturn()); 43 | datasource.setPoolPreparedStatements(dataSourceProperties.isPoolPreparedStatements()); 44 | try { 45 | datasource.setFilters(dataSourceProperties.getFilters()); 46 | } catch (SQLException e) { 47 | logger.error("Druid configuration initialization filter error.", e); 48 | } 49 | return datasource; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /account-sevice/src/main/java/com/simplemall/account/config/SqlSessionFactoryConfig.java: -------------------------------------------------------------------------------- 1 | package com.simplemall.account.config; 2 | 3 | import javax.sql.DataSource; 4 | 5 | import org.apache.ibatis.session.SqlSessionFactory; 6 | import org.mybatis.spring.SqlSessionFactoryBean; 7 | import org.mybatis.spring.SqlSessionTemplate; 8 | import org.mybatis.spring.annotation.MapperScan; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.context.annotation.Bean; 11 | import org.springframework.context.annotation.Configuration; 12 | import org.springframework.core.io.support.PathMatchingResourcePatternResolver; 13 | import org.springframework.jdbc.datasource.DataSourceTransactionManager; 14 | import org.springframework.transaction.PlatformTransactionManager; 15 | import org.springframework.transaction.annotation.EnableTransactionManagement; 16 | import org.springframework.transaction.annotation.TransactionManagementConfigurer; 17 | 18 | @Configuration 19 | @EnableTransactionManagement 20 | @MapperScan("com.simplemall.account.dal") 21 | public class SqlSessionFactoryConfig implements TransactionManagementConfigurer { 22 | 23 | @Autowired 24 | private DataSource dataSource; 25 | 26 | @Autowired 27 | private DataSourceProperties dataSourceProperties; 28 | 29 | /** 30 | * 创建sqlSessionFactoryBean 31 | * @return 32 | * @throws Exception 33 | */ 34 | @Bean(name = "sqlSessionFactory") 35 | public SqlSessionFactory createSqlSessionFactoryBean() throws Exception { 36 | SqlSessionFactoryBean bean = new SqlSessionFactoryBean(); 37 | bean.setDataSource(dataSource); 38 | bean.setTypeAliasesPackage(dataSourceProperties.getTypeAliasPackage()); 39 | 40 | PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(); 41 | bean.setMapperLocations(resolver.getResources(dataSourceProperties.getMapperLocations())); 42 | 43 | return bean.getObject(); 44 | } 45 | 46 | @Bean 47 | public SqlSessionTemplate sqlSessionTemplate(SqlSessionFactory sqlSessionFactory) { 48 | return new SqlSessionTemplate(sqlSessionFactory); 49 | } 50 | 51 | @Bean 52 | @Override 53 | public PlatformTransactionManager annotationDrivenTransactionManager() { 54 | return new DataSourceTransactionManager(dataSource); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /account-sevice/src/main/java/com/simplemall/account/controller/AccountController.java: -------------------------------------------------------------------------------- 1 | package com.simplemall.account.controller; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.web.bind.annotation.RequestMapping; 5 | import org.springframework.web.bind.annotation.RequestMethod; 6 | import org.springframework.web.bind.annotation.RequestParam; 7 | import org.springframework.web.bind.annotation.RestController; 8 | 9 | import com.simplemall.account.service.IAccountService; 10 | import com.simplemall.micro.serv.common.bean.account.Account; 11 | import com.simplemall.micro.serv.common.constant.SystemConstants; 12 | 13 | /** 14 | * 个人账户 15 | * 16 | * @author guooo 17 | * 18 | */ 19 | @RestController 20 | @RequestMapping("/acc") 21 | public class AccountController { 22 | 23 | @Autowired 24 | IAccountService accountService; 25 | 26 | /** 27 | * 登陆 28 | * 29 | * @param phone 30 | * @param password 31 | * @return 32 | */ 33 | @RequestMapping(value = "login", method = {RequestMethod.GET,RequestMethod.POST}) 34 | public Account login(@RequestParam("phone") String phone, @RequestParam("password") String password) { 35 | Account result = accountService.login(phone, password); 36 | return result; 37 | } 38 | 39 | /** 40 | * 注册 41 | * 42 | * @param phone 43 | * @param password 44 | * @return 45 | */ 46 | @RequestMapping(value = "signup", method = RequestMethod.GET) 47 | public String signup(String phone, String password) { 48 | boolean result = accountService.signup(phone, password); 49 | return result ? SystemConstants.Code.SUCCESS : SystemConstants.Code.FAIL; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /account-sevice/src/main/java/com/simplemall/account/controller/AddressController.java: -------------------------------------------------------------------------------- 1 | package com.simplemall.account.controller; 2 | 3 | import java.util.List; 4 | 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.web.bind.annotation.PathVariable; 7 | import org.springframework.web.bind.annotation.RequestMapping; 8 | import org.springframework.web.bind.annotation.RequestParam; 9 | import org.springframework.web.bind.annotation.RestController; 10 | 11 | import com.simplemall.account.service.IAccountService; 12 | import com.simplemall.micro.serv.common.bean.account.AccAddress; 13 | 14 | @RestController 15 | @RequestMapping("/address") 16 | public class AddressController { 17 | 18 | @Autowired 19 | IAccountService accountService; 20 | 21 | @RequestMapping("list/{accountTid}") 22 | public List getList(@RequestParam(required = true) @PathVariable("accountTid") String accountTid,String jwtToken) { 23 | List list = accountService.getAddressList(accountTid); 24 | return list; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /account-sevice/src/main/java/com/simplemall/account/dal/AccAddressMapper.java: -------------------------------------------------------------------------------- 1 | package com.simplemall.account.dal; 2 | 3 | import java.util.List; 4 | 5 | import org.apache.ibatis.annotations.Param; 6 | 7 | import com.simplemall.micro.serv.common.bean.account.AccAddress; 8 | import com.simplemall.micro.serv.common.bean.account.AccAddressCriteria; 9 | 10 | public interface AccAddressMapper { 11 | /** 12 | * 根据条件计数 13 | * 14 | * @param example 15 | */ 16 | int countByExample(AccAddressCriteria example); 17 | 18 | /** 19 | * 20 | * @param example 21 | */ 22 | int deleteByExample(AccAddressCriteria example); 23 | 24 | /** 25 | * 根据主键删除数据库的记录 26 | * 27 | * @param tid 28 | */ 29 | int deleteByPrimaryKey(String tid); 30 | 31 | /** 32 | * 插入数据库记录 33 | * 34 | * @param record 35 | */ 36 | int insert(AccAddress record); 37 | 38 | /** 39 | * 插入数据库记录 40 | * 41 | * @param record 42 | */ 43 | int insertSelective(AccAddress record); 44 | 45 | /** 46 | * 根据条件查询列表 47 | * 48 | * @param example 49 | */ 50 | List selectByExample(AccAddressCriteria example); 51 | 52 | /** 53 | * 根据主键获取一条数据库记录 54 | * 55 | * @param tid 56 | */ 57 | AccAddress selectByPrimaryKey(String tid); 58 | 59 | /** 60 | * 选择性更新数据库记录 61 | * 62 | * @param record 63 | * @param example 64 | */ 65 | int updateByExampleSelective(@Param("record") AccAddress record, @Param("example") AccAddressCriteria example); 66 | 67 | /** 68 | * 选择性更新数据库记录 69 | * 70 | * @param record 71 | * @param example 72 | */ 73 | int updateByExample(@Param("record") AccAddress record, @Param("example") AccAddressCriteria example); 74 | 75 | /** 76 | * 根据主键来更新部分数据库记录 77 | * 78 | * @param record 79 | */ 80 | int updateByPrimaryKeySelective(AccAddress record); 81 | 82 | /** 83 | * 根据主键来更新数据库记录 84 | * 85 | * @param record 86 | */ 87 | int updateByPrimaryKey(AccAddress record); 88 | } -------------------------------------------------------------------------------- /account-sevice/src/main/java/com/simplemall/account/dal/AccountMapper.java: -------------------------------------------------------------------------------- 1 | package com.simplemall.account.dal; 2 | 3 | import java.util.List; 4 | 5 | import org.apache.ibatis.annotations.Param; 6 | 7 | import com.simplemall.micro.serv.common.bean.account.Account; 8 | import com.simplemall.micro.serv.common.bean.account.AccountCriteria; 9 | 10 | public interface AccountMapper { 11 | /** 12 | * 根据条件计数 13 | * 14 | * @param example 15 | */ 16 | int countByExample(AccountCriteria example); 17 | 18 | /** 19 | * 20 | * @param example 21 | */ 22 | int deleteByExample(AccountCriteria example); 23 | 24 | /** 25 | * 根据主键删除数据库的记录 26 | * 27 | * @param tid 28 | */ 29 | int deleteByPrimaryKey(String tid); 30 | 31 | /** 32 | * 插入数据库记录 33 | * 34 | * @param record 35 | */ 36 | int insert(Account record); 37 | 38 | /** 39 | * 插入数据库记录 40 | * 41 | * @param record 42 | */ 43 | int insertSelective(Account record); 44 | 45 | /** 46 | * 根据条件查询列表 47 | * 48 | * @param example 49 | */ 50 | List selectByExample(AccountCriteria example); 51 | 52 | /** 53 | * 根据主键获取一条数据库记录 54 | * 55 | * @param tid 56 | */ 57 | Account selectByPrimaryKey(String tid); 58 | 59 | /** 60 | * 选择性更新数据库记录 61 | * 62 | * @param record 63 | * @param example 64 | */ 65 | int updateByExampleSelective(@Param("record") Account record, @Param("example") AccountCriteria example); 66 | 67 | /** 68 | * 选择性更新数据库记录 69 | * 70 | * @param record 71 | * @param example 72 | */ 73 | int updateByExample(@Param("record") Account record, @Param("example") AccountCriteria example); 74 | 75 | /** 76 | * 根据主键来更新部分数据库记录 77 | * 78 | * @param record 79 | */ 80 | int updateByPrimaryKeySelective(Account record); 81 | 82 | /** 83 | * 根据主键来更新数据库记录 84 | * 85 | * @param record 86 | */ 87 | int updateByPrimaryKey(Account record); 88 | } -------------------------------------------------------------------------------- /account-sevice/src/main/java/com/simplemall/account/service/IAccountService.java: -------------------------------------------------------------------------------- 1 | package com.simplemall.account.service; 2 | 3 | import java.util.List; 4 | 5 | import com.simplemall.micro.serv.common.bean.account.AccAddress; 6 | import com.simplemall.micro.serv.common.bean.account.Account; 7 | 8 | public interface IAccountService { 9 | 10 | /** 11 | * @param phone 12 | * @param password 13 | * @return 14 | */ 15 | Account login(String phone, String password); 16 | 17 | /** 18 | * @param phone 19 | * @param password 20 | * @return 21 | */ 22 | boolean signup(String phone, String password); 23 | 24 | /** 25 | * @param tid 26 | * @return 27 | */ 28 | AccAddress getAccAddress(String tid); 29 | 30 | /** 31 | * @param accountId 32 | * @return 33 | */ 34 | List getAddressList(String accountId); 35 | } 36 | -------------------------------------------------------------------------------- /account-sevice/src/main/java/com/simplemall/account/service/impl/AccountServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.simplemall.account.service.impl; 2 | 3 | import java.util.List; 4 | 5 | import org.apache.commons.collections.CollectionUtils; 6 | import org.slf4j.Logger; 7 | import org.slf4j.LoggerFactory; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.stereotype.Service; 10 | 11 | import com.simplemall.account.dal.AccAddressMapper; 12 | import com.simplemall.account.dal.AccountMapper; 13 | import com.simplemall.account.service.IAccountService; 14 | import com.simplemall.micro.serv.common.bean.account.AccAddress; 15 | import com.simplemall.micro.serv.common.bean.account.AccAddressCriteria; 16 | import com.simplemall.micro.serv.common.bean.account.Account; 17 | import com.simplemall.micro.serv.common.bean.account.AccountCriteria; 18 | 19 | @Service 20 | public class AccountServiceImpl implements IAccountService { 21 | 22 | private Logger logger = LoggerFactory.getLogger(AccountServiceImpl.class); 23 | 24 | @Autowired 25 | AccountMapper accountMapper; 26 | 27 | @Autowired 28 | AccAddressMapper addressMapper; 29 | 30 | @Override 31 | public AccAddress getAccAddress(String tid) { 32 | return null; 33 | } 34 | 35 | @Override 36 | public Account login(String phone, String password) { 37 | AccountCriteria criteria = new AccountCriteria(); 38 | criteria.createCriteria().andPhoneEqualTo(phone).andPasswordEqualTo(password); 39 | List list = accountMapper.selectByExample(criteria); 40 | logger.info("{}登陆成功!",phone); 41 | return CollectionUtils.isNotEmpty(list)?list.get(0):new Account(); 42 | } 43 | 44 | @Override 45 | public boolean signup(String phone, String password) { 46 | Account account = new Account(); 47 | account.setPhone(phone); 48 | account.setPassword(password); 49 | AccountCriteria example = new AccountCriteria(); 50 | example.createCriteria().andPhoneEqualTo(phone); 51 | List list = accountMapper.selectByExample(example); 52 | if (CollectionUtils.isNotEmpty(list)) { 53 | logger.warn("{}-用户已存在,请选择其它用户名!",phone); 54 | return false; 55 | } 56 | int result = accountMapper.insertSelective(account); 57 | logger.info("{}注册成功!",phone); 58 | return result > 0 ? true : false; 59 | } 60 | 61 | @Override 62 | public List getAddressList(String accountId) { 63 | AccAddressCriteria criteria = new AccAddressCriteria(); 64 | criteria.createCriteria().andAccountIdEqualTo(accountId); 65 | List list = addressMapper.selectByExample(criteria); 66 | return list; 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /account-sevice/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | server.port=8080 2 | spring.application.name=account-service 3 | 4 | #base serv cofig 5 | eureka.client.serviceUrl.defaultZone=http://localhost:9003/eureka/ 6 | spring.zipkin.base-url=http://localhost:9001 7 | spring.boot.admin.url=http://localhost:9002 8 | 9 | #Error: {"timestamp":1502748955345,"status":401,"error":"Unauthorized","message":"Full authentication is required to access this resource.","path":"/env"} 10 | #Error: {"timestamp":1502748975573,"status":401,"error":"Unauthorized","message":"Full authentication is required to access this resource.","path":"/metrics"} 11 | #resolved up problems 12 | management.security.enabled=false 13 | 14 | #mysql database config 15 | spring.datasource.url=jdbc:mysql://localhost:3306/micro_account?useUnicode=true&characterEncoding=UTF-8&characterSetResults=UTF-8&zeroDateTimeBehavior=convertToNull 16 | #use jasypt to encrypt username/password 17 | spring.datasource.username=ENC(BnBr3/idF0PH9nd20A9BXw==) 18 | spring.datasource.password=ENC(BnBr3/idF0PH9nd20A9BXw==) 19 | spring.datasource.driverClassName=com.mysql.jdbc.Driver 20 | spring.datasource.initialSize=1 21 | spring.datasource.minIdle=1 22 | spring.datasource.maxIdle=5 23 | spring.datasource.maxActive=50 24 | spring.datasource.maxWait=10000 25 | spring.datasource.timeBetweenEvictionRunsMillis=10000 26 | spring.datasource.minEvictableIdleTimeMillis=300000 27 | spring.datasource.validationQuery=select 'x' 28 | spring.datasource.testWhileIdle=true 29 | spring.datasource.testOnBorrow=false 30 | spring.datasource.testOnReturn=false 31 | jasypt.encryptor.password=EbfYkitulv73I2p0mXI50JMXoaxZTKJ7 32 | spring.datasource.poolPreparedStatements=true 33 | spring.datasource.maxOpenPreparedStatements=20 34 | spring.datasource.filters=stat 35 | 36 | spring.datasource.mapperLocations=classpath:mapper/*.xml 37 | spring.datasource.typeAliasPackage=com.simplemall.account.bean 38 | 39 | #pagehelper 40 | pagehelper.helperDialect=mysql 41 | pagehelper.reasonable=false 42 | pagehelper.supportMethodsArguments=true 43 | pagehelper.params=count=countSql -------------------------------------------------------------------------------- /account-sevice/src/main/resources/bootstrap.properties: -------------------------------------------------------------------------------- 1 | spring.rabbitmq.host=localhost 2 | spring.rabbitmq.port=5672 3 | spring.rabbitmq.username=guest 4 | spring.rabbitmq.password=guest -------------------------------------------------------------------------------- /account-sevice/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | ${LOG_HOME}/${LOG_PREFIX}-info.log 14 | 15 | 16 | ${LOG_HOME}/${LOG_PREFIX}-info-%d{yyyyMMdd}.log.%i 17 | 18 | 100MB 19 | 30 20 | 20GB 21 | 22 | 23 | 24 | %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} -%msg%n 25 | 26 | 27 | 28 | 29 | 30 | 31 | ERROR 32 | 33 | ${LOG_HOME}/${LOG_PREFIX}-error.log 34 | 35 | 36 | ${LOG_HOME}/${LOG_PREFIX}-error-%d{yyyyMMdd}.log.%i 37 | 38 | 100MB 39 | 30 40 | 20GB 41 | 42 | 43 | 44 | %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} -%msg%n 45 | 46 | 47 | 48 | 49 | 50 | 51 | %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /account-sevice/src/test/java/com/simplemall/account/test/AccountControllerTest.java: -------------------------------------------------------------------------------- 1 | package com.simplemall.account.test; 2 | 3 | import org.junit.Assert; 4 | import org.junit.Before; 5 | import org.junit.Test; 6 | import org.junit.runner.RunWith; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.boot.test.context.SpringBootTest; 9 | import org.springframework.test.annotation.Rollback; 10 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 11 | import org.springframework.test.context.web.WebAppConfiguration; 12 | 13 | import com.simplemall.account.AccountServApplication; 14 | import com.simplemall.account.dal.AccountMapper; 15 | import com.simplemall.account.service.IAccountService; 16 | import com.simplemall.micro.serv.common.bean.account.Account; 17 | 18 | @RunWith(SpringJUnit4ClassRunner.class) 19 | @WebAppConfiguration 20 | @SpringBootTest(classes = AccountServApplication.class) 21 | public class AccountControllerTest { 22 | 23 | @Autowired 24 | private IAccountService accountService; 25 | 26 | @Autowired 27 | AccountMapper accountMapper; 28 | @Before 29 | public void setUp() throws Exception { 30 | } 31 | 32 | @Test 33 | @Rollback 34 | public void test() { 35 | String phone = "14534343434"; 36 | String password = "23123123"; 37 | Account account = new Account(); 38 | account.setPhone(phone); 39 | account.setPassword(password); 40 | int apiResult = accountMapper.insertSelective(account); 41 | Assert.assertTrue(apiResult>0); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /account-sevice/src/test/java/com/simplemall/account/test/Jasyptest.java: -------------------------------------------------------------------------------- 1 | package com.simplemall.account.test; 2 | 3 | import org.jasypt.encryption.StringEncryptor; 4 | import org.junit.Assert; 5 | import org.junit.Test; 6 | import org.junit.runner.RunWith; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.boot.test.context.SpringBootTest; 9 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 10 | import org.springframework.test.context.web.WebAppConfiguration; 11 | 12 | import com.simplemall.account.AccountServApplication; 13 | 14 | 15 | @RunWith(SpringJUnit4ClassRunner.class) 16 | @WebAppConfiguration 17 | @SpringBootTest(classes = AccountServApplication.class) 18 | public class Jasyptest { 19 | 20 | @Autowired 21 | StringEncryptor encryptor; 22 | 23 | @Test 24 | public void getPass() { 25 | String result = encryptor.encrypt("root"); 26 | System.out.println(result+"----------------"); 27 | Assert.assertTrue(result.length() > 0); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /account-sevice/src/test/resources/generatorConfig.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 8 | 9 | 10 | 11 | 12 | 13 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 25 | 26 | 27 | 29 | 30 | 31 | 32 | 33 | 34 | 36 | 37 | 38 | 39 | 40 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 |
50 |
51 |
-------------------------------------------------------------------------------- /base-service/admin-server/src/main/java/com/simplemall/micro/serv/base/admin/AdminServerApplicaton.java: -------------------------------------------------------------------------------- 1 | package com.simplemall.micro.serv.base.admin; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | import de.codecentric.boot.admin.config.EnableAdminServer; 7 | import org.springframework.boot.autoconfigure.security.SecurityAutoConfiguration; 8 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; 9 | import org.springframework.context.annotation.Configuration; 10 | 11 | 12 | @SpringBootApplication(exclude = {SecurityAutoConfiguration.class }) 13 | @EnableAdminServer 14 | @Configuration 15 | @EnableAutoConfiguration 16 | @EnableDiscoveryClient 17 | public class AdminServerApplicaton { 18 | 19 | public static void main(String[] args) { 20 | SpringApplication.run(AdminServerApplicaton.class, args); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /base-service/admin-server/src/main/java/com/simplemall/micro/serv/base/admin/config/SecurityConfig.java: -------------------------------------------------------------------------------- 1 | package com.simplemall.micro.serv.base.admin.config; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; 6 | import org.springframework.security.config.annotation.web.builders.HttpSecurity; 7 | import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; 8 | 9 | @Configuration 10 | public class SecurityConfig extends WebSecurityConfigurerAdapter { 11 | @Override 12 | protected void configure(HttpSecurity http) throws Exception { 13 | // Page with login form is served as /login.html and does a POST on /login 14 | http.formLogin().loginPage("/login.html").loginProcessingUrl("/login").permitAll(); 15 | // The UI does a POST on /logout on logout 16 | http.logout().logoutUrl("/logout"); 17 | // The ui currently doesn't support csrf 18 | http.csrf().disable(); 19 | 20 | // Requests for the login page and the static assets are allowed 21 | http.authorizeRequests() 22 | .antMatchers("/**/login.html", "/**/*.css", "/img/**", "/third-party/**") 23 | .permitAll(); 24 | // http.authorizeRequests().antMatchers("/api/**").hasIpAddress(Netutil) 25 | // ... and any other request needs to be authorized 26 | http.authorizeRequests().antMatchers("/**").authenticated(); 27 | 28 | // Enable so that the clients can authenticate via HTTP basic for registering 29 | http.httpBasic(); 30 | } 31 | 32 | @Autowired 33 | public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception { 34 | auth 35 | .inMemoryAuthentication() 36 | .withUser("admin").password("$769!").roles("USER"); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /base-service/admin-server/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | server.port=9002 2 | logging.level.tk.mybatis=TRACE 3 | 4 | spring.application.name=SpringBootAdminServer 5 | #spring.boot.admin.url=http://localhost:9002 6 | #spring.jackson.serialization.indent_output=true 7 | #endpoints.health.sensitive=false 8 | 9 | #spring.mvc.view.prefix=/templates/ 10 | #spring.mvc.view.suffix=.ftl 11 | #spring.freemarker.cache=false 12 | #spring.freemarker.request-context-attribute=request 13 | 14 | eureka.instance.lease-renewal-interval-in-seconds=30 15 | eureka.client.registry-fetch-interval-seconds=15 16 | eureka.client.service-url.defaultZone= http://localhost:9003/eureka/ 17 | 18 | #\u63A7\u5236\u53F0\u5F69\u8272\u8F93\u51FA 19 | spring.output.ansi.enabled=ALWAYS 20 | spring.boot.admin.turbine.clusters=default 21 | spring.boot.admin.turbine.url=http://localhost:8031/turbine.stream 22 | spring.boot.admin.routes.endpoints=env,metrics,trace,dump,jolokia,info,configprops,trace,logfile,refresh,flyway,liquibase,heapdump,activiti 23 | -------------------------------------------------------------------------------- /base-service/admin-server/src/main/resources/banner.txt: -------------------------------------------------------------------------------- 1 | ${AnsiColor.BLACK} 2 | .__ __ .__ 3 | ____ |__|/ |_ | |__ __ ________ 4 | / ___\| \ __\ | | \| | \____ \ 5 | / /_/ > || | | Y \ | / |_> > 6 | \___ /|__||__| |___| /____/| __/ 7 | /_____/ \/ |__| 8 | 9 | ${AnsiColor.BRIGHT_BLUE} 10 | ::: ${application.title} (${application.version}) ::: \(^O^)/ Spring-Boot ${spring-boot.version} 11 | -------------------------------------------------------------------------------- /base-service/admin-server/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | ${LOG_HOME}/${LOG_PREFIX}-info.log 14 | 15 | 16 | ${LOG_HOME}/${LOG_PREFIX}-info-%d{yyyyMMdd}.log.%i 17 | 18 | 100MB 19 | 30 20 | 20GB 21 | 22 | 23 | 24 | %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} -%msg%n 25 | 26 | 27 | 28 | 29 | 30 | 31 | ERROR 32 | 33 | ${LOG_HOME}/${LOG_PREFIX}-error.log 34 | 35 | 36 | ${LOG_HOME}/${LOG_PREFIX}-error-%d{yyyyMMdd}.log.%i 37 | 38 | 100MB 39 | 30 40 | 20GB 41 | 42 | 43 | 44 | %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} -%msg%n 45 | 46 | 47 | 48 | 49 | 50 | 51 | %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /base-service/admin-server/target/classes/application.properties: -------------------------------------------------------------------------------- 1 | server.port=9002 2 | logging.level.tk.mybatis=TRACE 3 | 4 | spring.application.name=SpringBootAdminServer 5 | #spring.boot.admin.url=http://localhost:9002 6 | #spring.jackson.serialization.indent_output=true 7 | #endpoints.health.sensitive=false 8 | 9 | #spring.mvc.view.prefix=/templates/ 10 | #spring.mvc.view.suffix=.ftl 11 | #spring.freemarker.cache=false 12 | #spring.freemarker.request-context-attribute=request 13 | 14 | eureka.instance.lease-renewal-interval-in-seconds=30 15 | eureka.client.registry-fetch-interval-seconds=15 16 | eureka.client.service-url.defaultZone= http://localhost:9003/eureka/ 17 | 18 | #\u63A7\u5236\u53F0\u5F69\u8272\u8F93\u51FA 19 | spring.output.ansi.enabled=ALWAYS 20 | spring.boot.admin.turbine.clusters=default 21 | spring.boot.admin.turbine.url=http://localhost:8031/turbine.stream 22 | spring.boot.admin.routes.endpoints=env,metrics,trace,dump,jolokia,info,configprops,trace,logfile,refresh,flyway,liquibase,heapdump,activiti 23 | -------------------------------------------------------------------------------- /base-service/conf-server/README.md: -------------------------------------------------------------------------------- 1 | #ReadMe 2 | 1、config-client项目的pom中加入spring-boot-starter-actuator,依赖其监控机制,来刷新config-server中配置的变化,config-client客户端中增加@RefreshScope,来手动修正配置荐的变化。但不能有效的将config-server中变化的信息实时的更新到客户端,是个弊端。 3 | 4 | 2、引入bus来修复上一阶段产生的不能实时更新消息的bug 5 | 6 | 7 | http://www.cnblogs.com/unqiang/p/5166770.html kafaka setup documents 8 | ##其它组件 9 | 百度的Disconf,360的QConf,taobao的Diamond,自己能过zookeeper实现的配置中心 -------------------------------------------------------------------------------- /base-service/conf-server/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | com.simplemall.micro.serv.base 6 | base-serv 7 | 0.0.1-SNAPSHOT 8 | 9 | com.simplemall.micro.serv.base.conf 10 | conf-server 11 | configServer 12 | 13 | 14 | UTF-8 15 | 1.7 16 | 17 | 18 | 19 | 20 | org.springframework.boot 21 | spring-boot-starter-test 22 | test 23 | 24 | 25 | org.springframework.cloud 26 | spring-cloud-starter-eureka-server 27 | 28 | 29 | org.springframework.cloud 30 | spring-cloud-config-server 31 | 32 | 33 | org.springframework.boot 34 | spring-boot-starter-security 35 | 36 | 37 | org.springframework.cloud 38 | spring-cloud-starter-bus-amqp 39 | 40 | 41 | org.springframework.boot 42 | spring-boot-starter-actuator 43 | 44 | 45 | 46 | 47 | 48 | 49 | org.springframework.cloud 50 | spring-cloud-dependencies 51 | Camden.SR5 52 | pom 53 | import 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | org.springframework.boot 62 | spring-boot-maven-plugin 63 | 64 | 65 | 66 | -------------------------------------------------------------------------------- /base-service/conf-server/src/main/java/com/simplemall/micro/serv/config/ConfigServerApplication.java: -------------------------------------------------------------------------------- 1 | package com.simplemall.micro.serv.config; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; 6 | import org.springframework.cloud.config.server.EnableConfigServer; 7 | 8 | /** 9 | * spring config server 10 | * 11 | * @author guooo 12 | * 13 | */ 14 | @SpringBootApplication 15 | @EnableConfigServer 16 | @EnableDiscoveryClient 17 | public class ConfigServerApplication { 18 | 19 | // FIXME encrypt配置文件 20 | public static void main(String[] args) { 21 | SpringApplication.run(ConfigServerApplication.class, args); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /base-service/conf-server/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | server.port=9004 2 | logging.level.tk.mybatis=TRACE 3 | 4 | spring.application.name=config-server 5 | 6 | spring.cloud.config.server.git.uri=https://github.com/backkoms/spring-cloud-repo 7 | spring.cloud.config.server.git.searchPaths=repo 8 | spring.cloud.config.label=master 9 | 10 | eureka.client.serviceUrl.defaultZone=http://localhost:9003/eureka/ 11 | spring.boot.admin.url=http://localhost:9002 12 | management.security.enabled=false 13 | 14 | #enforce config-service security 15 | security.user.name=user 16 | security.user.password=yourPW 17 | 18 | spring.rabbitmq.host=localhost 19 | spring.rabbitmq.port=5672 20 | spring.rabbitmq.username=guest 21 | spring.rabbitmq.password=guest 22 | -------------------------------------------------------------------------------- /base-service/eureka-server/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | com.simplemall.micro.serv.base 6 | base-serv 7 | 0.0.1-SNAPSHOT 8 | 9 | com.simplemall.micro.serv.base.eureka 10 | eureka-server 11 | eurekaServer 12 | 13 | 14 | UTF-8 15 | 1.7 16 | 17 | 18 | 19 | 20 | de.codecentric 21 | spring-boot-admin-starter-client 22 | 1.4.6 23 | 24 | 25 | org.springframework.boot 26 | spring-boot-starter-test 27 | test 28 | 29 | 30 | org.springframework.cloud 31 | spring-cloud-starter-eureka-server 32 | 33 | 34 | 35 | 36 | 37 | 38 | org.springframework.cloud 39 | spring-cloud-dependencies 40 | Camden.SR5 41 | pom 42 | import 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | org.springframework.boot 51 | spring-boot-maven-plugin 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /base-service/eureka-server/src/main/java/com/simplemall/micro/serv/eureka/EurekaServerApplication.java: -------------------------------------------------------------------------------- 1 | package com.simplemall.micro.serv.eureka; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer; 6 | 7 | 8 | @SpringBootApplication 9 | @EnableEurekaServer 10 | public class EurekaServerApplication { 11 | 12 | /** 13 | * @param args 14 | */ 15 | public static void main(String[] args) { 16 | SpringApplication.run(EurekaServerApplication.class, args); 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /base-service/eureka-server/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | server.port=9003 2 | 3 | spring.application.name=eureka-server 4 | 5 | eureka.client.register-with-eureka=false 6 | eureka.client.fetch-registry=false 7 | eureka.client.serviceUrl.defaultZone=http://localhost:${server.port}/eureka/ 8 | spring.boot.admin.url=http://localhost:9002 9 | 10 | # \u8BBE\u4E3Afalse\uFF0C\u5173\u95ED\u81EA\u6211\u4FDD\u62A4 11 | eureka.server.enable-self-preservation=false 12 | 13 | 14 | #Error: {"timestamp":1502748955345,"status":401,"error":"Unauthorized","message":"Full authentication is required to access this resource.","path":"/env"} 15 | #Error: {"timestamp":1502748975573,"status":401,"error":"Unauthorized","message":"Full authentication is required to access this resource.","path":"/metrics"} 16 | #resolved up problems 17 | management.security.enabled=false -------------------------------------------------------------------------------- /base-service/hystrix-dashboard/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | com.simplemall.micro.serv.base 6 | base-serv 7 | 0.0.1-SNAPSHOT 8 | 9 | com.simplemall.micro.serv.base.hystrix.dashboard 10 | hystrix-dashboard 11 | 12 | 13 | 14 | 15 | org.springframework.cloud 16 | spring-cloud-starter-hystrix 17 | 18 | 19 | org.springframework.cloud 20 | spring-cloud-starter-hystrix-dashboard 21 | 22 | 23 | org.springframework.boot 24 | spring-boot-starter-actuator 25 | 26 | 27 | 28 | 29 | 30 | 31 | org.springframework.cloud 32 | spring-cloud-dependencies 33 | Camden.SR5 34 | pom 35 | import 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | org.springframework.boot 44 | spring-boot-maven-plugin 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /base-service/hystrix-dashboard/src/main/java/com/simplemall/micro/serv/base/hystrix/HystrixDashboardApplication.java: -------------------------------------------------------------------------------- 1 | package com.simplemall.micro.serv.base.hystrix; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard; 6 | 7 | /** 8 | * main class 9 | * 10 | * @author Guooo 2017年9月3日 下午8:33:39 11 | */ 12 | @SpringBootApplication 13 | @EnableHystrixDashboard 14 | public class HystrixDashboardApplication { 15 | 16 | public static void main(String[] args) { 17 | SpringApplication.run(HystrixDashboardApplication.class, args); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /base-service/hystrix-dashboard/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.application.name=hystrix-dashboard 2 | server.port=9006 -------------------------------------------------------------------------------- /base-service/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | 4 | com.simplemall.micro.serv 5 | simplemall-proj 6 | 0.0.1-SNAPSHOT 7 | 8 | com.simplemall.micro.serv.base 9 | base-serv 10 | pom 11 | 12 | eureka-server 13 | conf-server 14 | zuul-server 15 | sleuth-server 16 | admin-server 17 | hystrix-dashboard 18 | turbine-server 19 | 20 | -------------------------------------------------------------------------------- /base-service/sleuth-server/README.md: -------------------------------------------------------------------------------- 1 | ## 存储方式 2 | in-momery 3 | mysql 4 | es 5 | cassandra 6 | 每种方式依赖的jar不同 7 | ## 跟踪方式 8 | 一种采用原生的sleuth,是http方式。zipkin是其中一种实现方式 9 | 一种采用异步的方式,结合kafaka/rabbitmq等第三方中间件实现,提高效率 10 | 11 | ## Brave 12 | Brave 是用来装备 Java 程序的类库,提供了面向标准Servlet、Spring MVC、Http Client、JAX RS、Jersey、Resteasy 和 MySQL 等接口的装备能力,可以通过编写简单的配置和代码,让基于这些框架构建的应用可以向 Zipkin 报告数据。同时 Brave 也提供了非常简单且标准化的接口,在以上封装无法满足要求的时候可以方便扩展与定制。 13 | 14 | 虽然Brave提供了默认的实现,结合项目实际情况,基本上是需要定制才能满足要求的,本文针对默认实现就不再啰嗦,直接针对定制进行讲解。 15 | 16 | 由于项目中用到SpringMvc,HttpClient,Jprotobuf-Rpc-Socket,本文主要介绍针对SpringMvc,HttpClient,Jprotobuf-Rpc-Socket的扩展与定制。 17 | 18 | -------------------------------------------------------------------------------- /base-service/sleuth-server/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | com.simplemall.micro.serv.base 6 | base-serv 7 | 0.0.1-SNAPSHOT 8 | 9 | com.simplemall.micro.serv.base.zipkin 10 | sleuth-server 11 | sleuthServer 12 | 链路跟踪服务 13 | 14 | 15 | 16 | org.springframework.cloud 17 | spring-cloud-starter-eureka 18 | 19 | 20 | org.springframework.boot 21 | spring-boot-starter-test 22 | test 23 | 24 | 25 | org.springframework.boot 26 | spring-boot-starter-web 27 | 28 | 29 | 33 | 34 | 35 | 36 | org.springframework.cloud 37 | spring-cloud-sleuth-zipkin-stream 38 | 39 | 40 | org.springframework.cloud 41 | spring-cloud-starter-stream-rabbit 42 | 43 | 44 | 45 | io.zipkin.java 46 | zipkin-autoconfigure-ui 47 | runtime 48 | 49 | 50 | 51 | 52 | io.zipkin.java 53 | zipkin-autoconfigure-storage-mysql 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 67 | 68 | mysql 69 | mysql-connector-java 70 | 71 | 72 | org.springframework.boot 73 | spring-boot-starter-jdbc 74 | 75 | 76 | 77 | de.codecentric 78 | spring-boot-admin-starter-client 79 | 1.4.6 80 | 81 | 82 | 83 | 84 | 85 | 86 | org.springframework.cloud 87 | spring-cloud-dependencies 88 | Camden.SR5 89 | pom 90 | import 91 | 92 | 93 | 94 | -------------------------------------------------------------------------------- /base-service/sleuth-server/src/main/java/com/simplemall/micro/serv/base/zipkin/SleuthServerApplicaton.java: -------------------------------------------------------------------------------- 1 | package com.simplemall.micro.serv.base.zipkin; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; 6 | import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration; 7 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; 8 | import org.springframework.cloud.sleuth.zipkin.stream.EnableZipkinStreamServer; 9 | 10 | /** 11 | * 两种方式实现链式跟踪,一种使用http的方式接受消息,一种采用消息中间件的形式来跟踪信息 12 | * 下方注释掉的注解为http方式,与Pom.xml配置中io.zipkin.java/zipkin-server配套使用 13 | * 目前代码采用的是mq异步消息方式跟踪信息 14 | * 15 | * 16 | * 提供多种信息跟踪信息的存储方式,本示例采用的是in-memory方式,服务关掉之后数据即消失,仅用于测试 17 | * mysql方式存储,脚本地址:https://github.com/openzipkin/zipkin/blob/master/zipkin-storage/mysql/src/main/resources/mysql.sql 与zipkin-autoconfigure-storage-mysql配合使用 18 | * es方式存储,与zipkin-autoconfigure-storage-elasticsearch-http配合使用 19 | * 20 | * 21 | * @author Guooo 2017年10月5日 上午6:55:59 Cannot determine embedded database driver 22 | * class for database type NONE 23 | */ 24 | //@SpringBootApplication 25 | @SpringBootApplication(exclude={DataSourceAutoConfiguration.class,HibernateJpaAutoConfiguration.class}) 26 | // @EnableZipkinServer //使用Stream方式启动ZipkinServer 27 | @EnableZipkinStreamServer 28 | @EnableDiscoveryClient 29 | public class SleuthServerApplicaton { 30 | 31 | public static void main(String[] args) { 32 | SpringApplication.run(SleuthServerApplicaton.class, args); 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /base-service/sleuth-server/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | server.port=9001 2 | spring.application.name=sleuth-server 3 | 4 | 5 | spring.boot.admin.url=http://localhost:9002 6 | 7 | #Error: {"timestamp":1502748955345,"status":401,"error":"Unauthorized","message":"Full authentication is required to access this resource.","path":"/env"} 8 | #Error: {"timestamp":1502748975573,"status":401,"error":"Unauthorized","message":"Full authentication is required to access this resource.","path":"/metrics"} 9 | #resolved up problems 10 | management.security.enabled=false 11 | 12 | #elasticsearch config 13 | #zipkin.storage.type=elasticsearch 14 | #zipkin.storage.elasticsearch.hosts=127.0.0.1:9200 15 | #zipkin.storage.elasticsearch.cluster=elasticsearch 16 | #zipkin.storage.elasticsearch.index=zipkin 17 | #zipkin.storage.elasticsearch.index-shards=5 18 | #zipkin.storage.elasticsearch.index-replicas=1 19 | 20 | #mysql config 21 | #zipkin.storage.type=mysql 22 | #spring.datasource.schema=classpath:/mysql.sql 23 | #spring.datasource.url=jdbc:mysql://${MYSQL_HOST:localhost}:3306/test 24 | #spring.datasource.username=root 25 | #spring.datasource.password=123 26 | #spring.datasource.initialize=true 27 | #spring.datasource.continueOnError=true 28 | #spring.sleuth.enabled=false -------------------------------------------------------------------------------- /base-service/sleuth-server/src/main/resources/bootstrap.properties: -------------------------------------------------------------------------------- 1 | #rabbit config 2 | spring.rabbitmq.host=localhost 3 | spring.rabbitmq.port=5672 4 | spring.rabbitmq.username=guest 5 | spring.rabbitmq.password=guest -------------------------------------------------------------------------------- /base-service/sleuth-server/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | ${LOG_HOME}/${LOG_PREFIX}-info.log 14 | 15 | 16 | ${LOG_HOME}/${LOG_PREFIX}-info-%d{yyyyMMdd}.log.%i 17 | 18 | 100MB 19 | 30 20 | 20GB 21 | 22 | 23 | 24 | %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} -%msg%n 25 | 26 | 27 | 28 | 29 | 30 | 31 | ERROR 32 | 33 | ${LOG_HOME}/${LOG_PREFIX}-error.log 34 | 35 | 36 | ${LOG_HOME}/${LOG_PREFIX}-error-%d{yyyyMMdd}.log.%i 37 | 38 | 100MB 39 | 30 40 | 20GB 41 | 42 | 43 | 44 | %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} -%msg%n 45 | 46 | 47 | 48 | 49 | 50 | 51 | %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /base-service/sleuth-server/src/main/resources/sql/mysql.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE IF NOT EXISTS zipkin_spans ( 2 | `trace_id_high` BIGINT NOT NULL DEFAULT 0 COMMENT 'If non zero, this means the trace uses 128 bit traceIds instead of 64 bit', 3 | `trace_id` BIGINT NOT NULL, 4 | `id` BIGINT NOT NULL, 5 | `name` VARCHAR(255) NOT NULL, 6 | `parent_id` BIGINT, 7 | `debug` BIT(1), 8 | `start_ts` BIGINT COMMENT 'Span.timestamp(): epoch micros used for endTs query and to implement TTL', 9 | `duration` BIGINT COMMENT 'Span.duration(): micros used for minDuration and maxDuration query' 10 | ) ENGINE=InnoDB ROW_FORMAT=COMPRESSED CHARACTER SET=utf8 COLLATE utf8_general_ci; 11 | 12 | ALTER TABLE zipkin_spans ADD UNIQUE KEY(`trace_id_high`, `trace_id`, `id`) COMMENT 'ignore insert on duplicate'; 13 | ALTER TABLE zipkin_spans ADD INDEX(`trace_id_high`, `trace_id`, `id`) COMMENT 'for joining with zipkin_annotations'; 14 | ALTER TABLE zipkin_spans ADD INDEX(`trace_id_high`, `trace_id`) COMMENT 'for getTracesByIds'; 15 | ALTER TABLE zipkin_spans ADD INDEX(`name`) COMMENT 'for getTraces and getSpanNames'; 16 | ALTER TABLE zipkin_spans ADD INDEX(`start_ts`) COMMENT 'for getTraces ordering and range'; 17 | 18 | CREATE TABLE IF NOT EXISTS zipkin_annotations ( 19 | `trace_id_high` BIGINT NOT NULL DEFAULT 0 COMMENT 'If non zero, this means the trace uses 128 bit traceIds instead of 64 bit', 20 | `trace_id` BIGINT NOT NULL COMMENT 'coincides with zipkin_spans.trace_id', 21 | `span_id` BIGINT NOT NULL COMMENT 'coincides with zipkin_spans.id', 22 | `a_key` VARCHAR(255) NOT NULL COMMENT 'BinaryAnnotation.key or Annotation.value if type == -1', 23 | `a_value` BLOB COMMENT 'BinaryAnnotation.value(), which must be smaller than 64KB', 24 | `a_type` INT NOT NULL COMMENT 'BinaryAnnotation.type() or -1 if Annotation', 25 | `a_timestamp` BIGINT COMMENT 'Used to implement TTL; Annotation.timestamp or zipkin_spans.timestamp', 26 | `endpoint_ipv4` INT COMMENT 'Null when Binary/Annotation.endpoint is null', 27 | `endpoint_ipv6` BINARY(16) COMMENT 'Null when Binary/Annotation.endpoint is null, or no IPv6 address', 28 | `endpoint_port` SMALLINT COMMENT 'Null when Binary/Annotation.endpoint is null', 29 | `endpoint_service_name` VARCHAR(255) COMMENT 'Null when Binary/Annotation.endpoint is null' 30 | ) ENGINE=InnoDB ROW_FORMAT=COMPRESSED CHARACTER SET=utf8 COLLATE utf8_general_ci; 31 | 32 | ALTER TABLE zipkin_annotations ADD UNIQUE KEY(`trace_id_high`, `trace_id`, `span_id`, `a_key`, `a_timestamp`) COMMENT 'Ignore insert on duplicate'; 33 | ALTER TABLE zipkin_annotations ADD INDEX(`trace_id_high`, `trace_id`, `span_id`) COMMENT 'for joining with zipkin_spans'; 34 | ALTER TABLE zipkin_annotations ADD INDEX(`trace_id_high`, `trace_id`) COMMENT 'for getTraces/ByIds'; 35 | ALTER TABLE zipkin_annotations ADD INDEX(`endpoint_service_name`) COMMENT 'for getTraces and getServiceNames'; 36 | ALTER TABLE zipkin_annotations ADD INDEX(`a_type`) COMMENT 'for getTraces'; 37 | ALTER TABLE zipkin_annotations ADD INDEX(`a_key`) COMMENT 'for getTraces'; 38 | ALTER TABLE zipkin_annotations ADD INDEX(`trace_id`, `span_id`, `a_key`) COMMENT 'for dependencies job'; 39 | 40 | CREATE TABLE IF NOT EXISTS zipkin_dependencies ( 41 | `day` DATE NOT NULL, 42 | `parent` VARCHAR(255) NOT NULL, 43 | `child` VARCHAR(255) NOT NULL, 44 | `call_count` BIGINT, 45 | `error_count` BIGINT 46 | ) ENGINE=InnoDB ROW_FORMAT=COMPRESSED CHARACTER SET=utf8 COLLATE utf8_general_ci; 47 | 48 | ALTER TABLE zipkin_dependencies ADD UNIQUE KEY(`day`, `parent`, `child`); -------------------------------------------------------------------------------- /base-service/turbine-server/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | com.simplemall.micro.serv.base 6 | base-serv 7 | 0.0.1-SNAPSHOT 8 | 9 | com.simplemall.micro.serv.base.turbine 10 | turbine-server 11 | 12 | 13 | 14 | org.springframework.cloud 15 | spring-cloud-starter-turbine 16 | 17 | 18 | org.springframework.boot 19 | spring-boot-starter-actuator 20 | 21 | 22 | 23 | 24 | 25 | 26 | org.springframework.cloud 27 | spring-cloud-dependencies 28 | Camden.SR5 29 | pom 30 | import 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | org.springframework.boot 39 | spring-boot-maven-plugin 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /base-service/turbine-server/src/main/java/com/simplemall/micro/serv/base/turbine/TurbineApplication.java: -------------------------------------------------------------------------------- 1 | package com.simplemall.micro.serv.base.turbine; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; 6 | import org.springframework.cloud.netflix.turbine.EnableTurbine; 7 | 8 | /** 9 | * 集群监控,必须引入acutor组件。 10 | * 11 | * TODO 可以依赖turbine-amqp,由rabbitmq作数据中转 12 | * 13 | * @author Guooo 2017年10月3日 上午10:22:53 14 | */ 15 | @SpringBootApplication 16 | @EnableTurbine 17 | @EnableDiscoveryClient 18 | public class TurbineApplication { 19 | 20 | public static void main(String[] args) { 21 | SpringApplication.run(TurbineApplication.class, args); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /base-service/turbine-server/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | server.port=9007 2 | spring.application.name=turbine-server 3 | 4 | turbine.app-config=eureka-consumer-ribbon-hystrix 5 | turbine.cluster-name-expression="default" 6 | turbine.combine-host-port=true 7 | 8 | #must dependent eureka server , it used be as service cluster monitor 9 | eureka.client.serviceUrl.defaultZone=http://localhost:9003/eureka/ 10 | -------------------------------------------------------------------------------- /base-service/zuul-server/README.md: -------------------------------------------------------------------------------- 1 | ## 动态路由 2 | 使用eureka的自动服务发现,自动映射到后端对应的服务,免去了手动映射的麻烦。 -------------------------------------------------------------------------------- /base-service/zuul-server/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | com.simplemall.micro.serv.base 6 | base-serv 7 | 0.0.1-SNAPSHOT 8 | 9 | com.simplemall.micro.serv.base.zuul 10 | zuul-server 11 | zuulServer 12 | 13 | 14 | UTF-8 15 | 1.7 16 | 17 | 18 | 19 | 20 | org.springframework.cloud 21 | spring-cloud-starter-zuul 22 | 23 | 24 | de.codecentric 25 | spring-boot-admin-starter-client 26 | 1.4.6 27 | 28 | 29 | org.springframework.boot 30 | spring-boot-starter-test 31 | test 32 | 33 | 34 | org.springframework.cloud 35 | spring-cloud-starter-eureka 36 | 37 | 38 | 39 | 40 | 41 | 42 | org.springframework.cloud 43 | spring-cloud-dependencies 44 | Camden.SR5 45 | pom 46 | import 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | org.springframework.boot 55 | spring-boot-maven-plugin 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /base-service/zuul-server/src/main/java/com/simplemall/micro/serv/zuul/ZuulServerApplication.java: -------------------------------------------------------------------------------- 1 | package com.simplemall.micro.serv.zuul; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; 6 | import org.springframework.cloud.netflix.zuul.EnableZuulProxy; 7 | 8 | /** 9 | * API Gateway 10 | * TODO 与zuul实现同样的功能还有kong,官网地址:https://getkong.org 11 | * 12 | * @author guooo 13 | * 14 | */ 15 | @EnableZuulProxy 16 | @EnableDiscoveryClient 17 | @SpringBootApplication 18 | public class ZuulServerApplication { 19 | 20 | public static void main(String[] args) { 21 | SpringApplication.run(ZuulServerApplication.class, args); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /base-service/zuul-server/src/main/java/com/simplemall/micro/serv/zuul/filter/AccessTokenFilter.java: -------------------------------------------------------------------------------- 1 | package com.simplemall.micro.serv.zuul.filter; 2 | 3 | import javax.servlet.http.HttpServletRequest; 4 | 5 | import org.slf4j.Logger; 6 | import org.slf4j.LoggerFactory; 7 | import org.springframework.stereotype.Component; 8 | 9 | import com.netflix.zuul.ZuulFilter; 10 | import com.netflix.zuul.context.RequestContext; 11 | 12 | /** 13 | * token过滤器,校验token必输项方法,token不能为空 14 | * 15 | * @author guooo 16 | * 17 | */ 18 | @Component 19 | public class AccessTokenFilter extends ZuulFilter { 20 | 21 | private static Logger log = LoggerFactory.getLogger(AccessTokenFilter.class); 22 | 23 | /* 24 | * 过滤器的具体逻辑。可用很复杂,包括查sql,nosql去判断该请求到底有没有权限访问。 25 | * 26 | * @see com.netflix.zuul.IZuulFilter#run() 27 | */ 28 | @Override 29 | public Object run() { 30 | //TODO 可将Front-app服务中的APISecurityCheck中针对accessToken的校验迁移至此,提前验证 31 | RequestContext ctx = RequestContext.getCurrentContext(); 32 | HttpServletRequest request = ctx.getRequest(); 33 | log.info(String.format("%s >>> %s", request.getMethod(), request.getRequestURL().toString())); 34 | Object accessToken = request.getParameter("accessToken"); 35 | if(accessToken == null) { 36 | log.warn("token is empty"); 37 | ctx.setSendZuulResponse(false); 38 | ctx.setResponseStatusCode(401); 39 | try { 40 | ctx.getResponse().getWriter().write("token is empty"); 41 | }catch (Exception e){} 42 | 43 | return null; 44 | } 45 | log.info("ok"); 46 | return null; 47 | } 48 | 49 | /* 50 | * 这里可以写逻辑判断,是否要过滤,本文true,永远过滤。 51 | * 52 | * @see com.netflix.zuul.IZuulFilter#shouldFilter() 53 | */ 54 | @Override 55 | public boolean shouldFilter() { 56 | return true; 57 | } 58 | 59 | @Override 60 | public int filterOrder() { 61 | return 0; 62 | } 63 | 64 | /* 65 | * (non-Javadoc) pre:路由之前 routing:路由之时 post: 路由之后 error:发送错误调用 66 | * 67 | * @see com.netflix.zuul.ZuulFilter#filterType() 68 | */ 69 | @Override 70 | public String filterType() { 71 | return "pre"; 72 | } 73 | 74 | } 75 | -------------------------------------------------------------------------------- /base-service/zuul-server/src/main/java/com/simplemall/micro/serv/zuul/filter/ErrorFilter.java: -------------------------------------------------------------------------------- 1 | package com.simplemall.micro.serv.zuul.filter; 2 | 3 | import com.netflix.zuul.ZuulFilter; 4 | 5 | public class ErrorFilter extends ZuulFilter { 6 | 7 | @Override 8 | public Object run() { 9 | return null; 10 | } 11 | 12 | @Override 13 | public boolean shouldFilter() { 14 | return true; 15 | } 16 | 17 | @Override 18 | public int filterOrder() { 19 | return 0; 20 | } 21 | 22 | @Override 23 | public String filterType() { 24 | return "err"; 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /base-service/zuul-server/src/main/java/com/simplemall/micro/serv/zuul/filter/PostFilter.java: -------------------------------------------------------------------------------- 1 | package com.simplemall.micro.serv.zuul.filter; 2 | 3 | import com.netflix.zuul.ZuulFilter; 4 | 5 | public class PostFilter extends ZuulFilter { 6 | 7 | @Override 8 | public Object run() { 9 | // TODO Auto-generated method stub 10 | return null; 11 | } 12 | 13 | @Override 14 | public boolean shouldFilter() { 15 | // TODO Auto-generated method stub 16 | return false; 17 | } 18 | 19 | @Override 20 | public int filterOrder() { 21 | // TODO Auto-generated method stub 22 | return 0; 23 | } 24 | 25 | @Override 26 | public String filterType() { 27 | // TODO Auto-generated method stub 28 | return "post"; 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /base-service/zuul-server/src/main/java/com/simplemall/micro/serv/zuul/filter/RoutingFitler.java: -------------------------------------------------------------------------------- 1 | package com.simplemall.micro.serv.zuul.filter; 2 | 3 | import com.netflix.zuul.ZuulFilter; 4 | 5 | public class RoutingFitler extends ZuulFilter { 6 | 7 | @Override 8 | public Object run() { 9 | // TODO Auto-generated method stub 10 | return null; 11 | } 12 | 13 | @Override 14 | public boolean shouldFilter() { 15 | // TODO Auto-generated method stub 16 | return true; 17 | } 18 | 19 | @Override 20 | public int filterOrder() { 21 | return 0; 22 | } 23 | 24 | @Override 25 | public String filterType() { 26 | // TODO Auto-generated method stub 27 | return "routing"; 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /base-service/zuul-server/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | server.port=9005 2 | spring.application.name=zuul-server 3 | 4 | eureka.client.serviceUrl.defaultZone=http://localhost:9003/eureka/ 5 | 6 | spring.boot.admin.url=http://localhost:9002 7 | 8 | #Error: {"timestamp":1502748955345,"status":401,"error":"Unauthorized","message":"Full authentication is required to access this resource.","path":"/env"} 9 | #Error: {"timestamp":1502748975573,"status":401,"error":"Unauthorized","message":"Full authentication is required to access this resource.","path":"/metrics"} 10 | #resolved up problems 11 | management.security.enabled=false 12 | 13 | 14 | # routes to serviceId,simple cases,wo usually use eureka client to discovery the service instead of to configure it like down below 15 | #zuul.routes.account.path=/acc/** 16 | #zuul.routes.account.serviceId=ACCOUNT-SERVICE 17 | 18 | #zuul.routes.product.path=/prd/** 19 | #zuul.routes.product.serviceId=product-service 20 | 21 | #zuul.routes.pay.path=/pay/** 22 | #zuul.routes.pay.serviceId=payment-service 23 | 24 | #zuul.routes.order.path=/order/** 25 | #zuul.routes.order.serviceId=order-service -------------------------------------------------------------------------------- /base-service/zuul-server/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | ${LOG_HOME}/${LOG_PREFIX}-info.log 14 | 15 | 16 | ${LOG_HOME}/${LOG_PREFIX}-info-%d{yyyyMMdd}.log.%i 17 | 18 | 100MB 19 | 30 20 | 20GB 21 | 22 | 23 | 24 | %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} -%msg%n 25 | 26 | 27 | 28 | 29 | 30 | 31 | ERROR 32 | 33 | ${LOG_HOME}/${LOG_PREFIX}-error.log 34 | 35 | 36 | ${LOG_HOME}/${LOG_PREFIX}-error-%d{yyyyMMdd}.log.%i 37 | 38 | 100MB 39 | 30 40 | 20GB 41 | 42 | 43 | 44 | %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} -%msg%n 45 | 46 | 47 | 48 | 49 | 50 | 51 | %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /common-module/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | com.simplemall.micro.serv 6 | simplemall-proj 7 | 0.0.1-SNAPSHOT 8 | 9 | com.simplemall.micro.serv.common 10 | common-module 11 | 12 | 13 | 14 | org.mybatis.spring.boot 15 | mybatis-spring-boot-starter 16 | 1.2.0 17 | 18 | 19 | com.github.pagehelper 20 | pagehelper-spring-boot-starter 21 | 1.1.0 22 | 23 | 24 | com.alibaba 25 | druid 26 | 1.0.28 27 | 28 | 29 | 30 | org.projectlombok 31 | lombok 32 | 33 | 34 | 35 | com.alibaba 36 | fastjson 37 | 1.2.7 38 | 39 | 40 | 41 | org.slf4j 42 | slf4j-api 43 | 44 | 45 | 46 | 47 | redis.clients 48 | jedis 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /common-module/src/main/java/com/simplemall/micro/serv/common/bean/order/OrderDTO.java: -------------------------------------------------------------------------------- 1 | package com.simplemall.micro.serv.common.bean.order; 2 | 3 | import java.util.List; 4 | 5 | import lombok.Data; 6 | 7 | @Data 8 | public class OrderDTO { 9 | 10 | OrderInfo baseInfo; 11 | 12 | List products; 13 | 14 | List stateChanges; 15 | } 16 | -------------------------------------------------------------------------------- /common-module/src/main/java/com/simplemall/micro/serv/common/constant/SystemConstants.java: -------------------------------------------------------------------------------- 1 | package com.simplemall.micro.serv.common.constant; 2 | 3 | /** 4 | * 系统常量 5 | * 6 | * @author guooo 7 | * 8 | */ 9 | public interface SystemConstants { 10 | public static final String API_KEY = "9223a431a6e24355901e95a521bb3455"; 11 | 12 | public static final class Code { 13 | public static final String SUCCESS = "1"; 14 | 15 | public static final String FAIL = "0"; 16 | /** 17 | * @Fields ok : 成功 18 | */ 19 | public static final int success = 1; 20 | /** 21 | * @Fields error : 失败 22 | */ 23 | public static final int error = 0; 24 | } 25 | 26 | /** 27 | * 订单状态 28 | * 29 | * @author guooo 30 | * 31 | */ 32 | public static final class STATE { 33 | 34 | /** 35 | * 创建 36 | */ 37 | public static final String CREATE = "CREATE"; 38 | 39 | /** 40 | * 配送中 41 | */ 42 | public static final String SHIPPING = "SHIPPING"; 43 | 44 | /** 45 | * 关闭 46 | */ 47 | public static final String CLOSED = "CLOSED"; 48 | 49 | /** 50 | * 完成 51 | */ 52 | public static final String FINISHED = "FINISHED"; 53 | } 54 | 55 | /** 56 | * 支付状态 57 | * 58 | * @author guooo 59 | * 60 | */ 61 | public static final class PAY_STATUS { 62 | 63 | /** 64 | * 未支付 65 | */ 66 | public static final String UNPAY = "UNPAY"; 67 | 68 | /** 69 | * 已支付 70 | */ 71 | public static final String PAID = "PAID"; 72 | 73 | } 74 | 75 | /** 76 | * 支付类型 77 | * 78 | * @author guooo 79 | * 80 | */ 81 | public static final class PAY_TYPE { 82 | 83 | /** 84 | * 支付宝 85 | */ 86 | public static final String ALIPAY = "ALIPAY"; 87 | 88 | /** 89 | * 财富通 90 | */ 91 | public static final String TENPAY = "TENPAY"; 92 | 93 | /** 94 | * 银行卡 95 | */ 96 | public static final String CARD = "CARD"; 97 | 98 | } 99 | 100 | /** 101 | * 配送方式 102 | * 103 | * @author xingxing 104 | * 105 | */ 106 | public static final class SHIP_WAY { 107 | public static final String FEDEX = "FEDEX"; 108 | public static final String UPS = "UPS"; 109 | public static final String DHL = "DHL"; 110 | } 111 | 112 | /** 113 | * redis中存储的需要校验token的uri的前缀 114 | */ 115 | public static final String URL_NEED_CHECK_KEY = "URL2CHK"; 116 | } 117 | -------------------------------------------------------------------------------- /common-module/src/main/java/com/simplemall/micro/serv/common/service/RedisConfig.java: -------------------------------------------------------------------------------- 1 | package com.simplemall.micro.serv.common.service; 2 | 3 | /** 4 | * 配置信息 5 | * 6 | * @author guooo 7 | * 8 | */ 9 | public class RedisConfig { 10 | 11 | public static final String REDIS_IP = "192.168.1.102"; 12 | 13 | public static final String AUTH = "a588a026b91c424cb7fa13267eb80e96"; 14 | 15 | public static final int PORT = 6379; 16 | 17 | public static final boolean TEST_ON_BORROW = true; 18 | 19 | public static final boolean TEST_ON_RETURN = true; 20 | 21 | public static final int MAX_ACTIVE = 1024; 22 | 23 | public static final int MAX_IDLE = 200; 24 | 25 | public static final int MAX_WAIT = 1000; 26 | 27 | 28 | 29 | } 30 | -------------------------------------------------------------------------------- /common-module/src/main/java/com/simplemall/micro/serv/common/service/RedisDemo.java: -------------------------------------------------------------------------------- 1 | package com.simplemall.micro.serv.common.service; 2 | 3 | public class RedisDemo { 4 | 5 | public static void main(String args[]){ 6 | //以key为键,value为值,插入redis数据库,并取出key的值(默认为0号数据库) 7 | JedisUtil.STRINGS.set("key", "value"); 8 | System.out.println(JedisUtil.STRINGS.get("key")); 9 | 10 | ///以key为键,value为值,插入redis的15号数据库,并从15号数据库取出值 11 | JedisUtil.STRINGS.set("key", "value", 15); 12 | JedisUtil.STRINGS.get("key", 15); 13 | 14 | //判断redis数据库中是否存在名字为“key”的键,默认从0号数据库中查找,也可以指定数据库编号 15 | JedisUtil.KEYS.exists("key"); 16 | JedisUtil.KEYS.exists("key", 15); 17 | 18 | //设置“key”键的超时时间,默认设置0号数据库中的键,也可以指定数据库 19 | JedisUtil.KEYS.expired("key", 500); 20 | JedisUtil.KEYS.expired("key", 500, 15); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /common-module/src/main/java/com/simplemall/micro/serv/common/service/SerializeUtil.java: -------------------------------------------------------------------------------- 1 | package com.simplemall.micro.serv.common.service; 2 | 3 | import java.io.ByteArrayInputStream; 4 | import java.io.ByteArrayOutputStream; 5 | import java.io.ObjectInputStream; 6 | import java.io.ObjectOutputStream; 7 | 8 | public class SerializeUtil { 9 | /** 10 | * 序列化 11 | * 12 | * @param object 13 | * @return 14 | */ 15 | public static byte[] serialize(Object object) { 16 | ObjectOutputStream oos = null; 17 | ByteArrayOutputStream baos = null; 18 | try { 19 | // 序列化 20 | baos = new ByteArrayOutputStream(); 21 | oos = new ObjectOutputStream(baos); 22 | oos.writeObject(object); 23 | byte[] bytes = baos.toByteArray(); 24 | return bytes; 25 | } catch (Exception e) { 26 | e.printStackTrace(); 27 | } 28 | return null; 29 | } 30 | 31 | /** 32 | * 反序列化 33 | * 34 | * @param bytes 35 | * @return 36 | */ 37 | public static Object unserialize(byte[] bytes) { 38 | ByteArrayInputStream bais = null; 39 | try { 40 | // 反序列化 41 | bais = new ByteArrayInputStream(bytes); 42 | ObjectInputStream ois = new ObjectInputStream(bais); 43 | return ois.readObject(); 44 | } catch (Exception e) { 45 | e.printStackTrace(); 46 | } 47 | return null; 48 | } 49 | } -------------------------------------------------------------------------------- /common-module/src/main/java/com/simplemall/micro/serv/common/util/UUIDUtils.java: -------------------------------------------------------------------------------- 1 | package com.simplemall.micro.serv.common.util; 2 | 3 | import java.util.UUID; 4 | 5 | /** uuid utils 6 | * @author Guooo 7 | * 2017年8月23日 上午6:17:01 8 | */ 9 | public class UUIDUtils { 10 | 11 | public static String getUUID() { 12 | return UUID.randomUUID().toString().replaceAll("-", ""); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /common-module/src/main/java/com/simplemall/micro/serv/common/utils.java: -------------------------------------------------------------------------------- 1 | package com.simplemall.micro.serv.common; 2 | 3 | public class utils { 4 | 5 | } 6 | -------------------------------------------------------------------------------- /front-app/src/main/java/com/simplemall/micro/serv/page/FrontAPPClientApplication.java: -------------------------------------------------------------------------------- 1 | 2 | package com.simplemall.micro.serv.page; 3 | 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; 7 | import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration; 8 | import org.springframework.cloud.client.loadbalancer.LoadBalanced; 9 | import org.springframework.cloud.netflix.eureka.EnableEurekaClient; 10 | import org.springframework.cloud.netflix.feign.EnableFeignClients; 11 | import org.springframework.cloud.netflix.hystrix.EnableHystrix; 12 | import org.springframework.context.annotation.Bean; 13 | import org.springframework.context.annotation.ComponentScan; 14 | import org.springframework.web.client.RestTemplate; 15 | 16 | import com.netflix.loadbalancer.IRule; 17 | import com.netflix.loadbalancer.RandomRule; 18 | 19 | @ComponentScan 20 | @EnableFeignClients 21 | @EnableEurekaClient 22 | @EnableHystrix 23 | @SpringBootApplication(exclude = { DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration.class }) 24 | public class FrontAPPClientApplication { 25 | 26 | public static void main(String[] args) { 27 | SpringApplication.run(FrontAPPClientApplication.class, args); 28 | } 29 | 30 | @Bean 31 | @LoadBalanced 32 | RestTemplate restTemplate() { 33 | return new RestTemplate(); 34 | } 35 | 36 | /** 37 | * ribbon loadBalance algorithm 38 | * 39 | * @return 40 | */ 41 | @Bean 42 | public IRule ribbonRule() { 43 | return new RandomRule(); 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /front-app/src/main/java/com/simplemall/micro/serv/page/HystrixConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.simplemall.micro.serv.page; 2 | 3 | import org.springframework.boot.web.servlet.ServletRegistrationBean; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.Configuration; 6 | 7 | import com.netflix.hystrix.contrib.javanica.aop.aspectj.HystrixCommandAspect; 8 | import com.netflix.hystrix.contrib.metrics.eventstream.HystrixMetricsStreamServlet; 9 | 10 | @Configuration 11 | public class HystrixConfiguration { 12 | 13 | //注册Hystrix框架的拦截器,使得框架的注解能够生效 14 | @Bean 15 | public HystrixCommandAspect hystrixAspect() { 16 | return new HystrixCommandAspect(); 17 | } 18 | 19 | //注入servlet,拦截url="/hystrix.stream" 20 | //测试git dev commit 21 | @Bean 22 | public ServletRegistrationBean hystrixMetricsStreamServlet() { 23 | ServletRegistrationBean registration = new ServletRegistrationBean(new HystrixMetricsStreamServlet()); 24 | registration.addUrlMappings("/hystrix.stream"); 25 | return registration; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /front-app/src/main/java/com/simplemall/micro/serv/page/Swagger2Config.java: -------------------------------------------------------------------------------- 1 | package com.simplemall.micro.serv.page; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | 6 | import io.swagger.annotations.ApiOperation; 7 | import springfox.documentation.builders.ApiInfoBuilder; 8 | import springfox.documentation.builders.PathSelectors; 9 | import springfox.documentation.builders.RequestHandlerSelectors; 10 | import springfox.documentation.service.ApiInfo; 11 | import springfox.documentation.spi.DocumentationType; 12 | import springfox.documentation.spring.web.plugins.Docket; 13 | import springfox.documentation.swagger2.annotations.EnableSwagger2; 14 | 15 | /** 16 | * swagger2 configuration 17 | * 18 | * @author guooo 19 | * 20 | */ 21 | @Configuration 22 | @EnableSwagger2 23 | public class Swagger2Config { 24 | 25 | @Bean 26 | public Docket createRestApi() { 27 | return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()).select() 28 | .apis(RequestHandlerSelectors.basePackage("com.simplemall.micro.serv.page.api")) 29 | .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class)) 30 | .paths(PathSelectors.any()) 31 | .build(); 32 | } 33 | 34 | private ApiInfo apiInfo() { 35 | return new ApiInfoBuilder().title("Front app Swagger apis").description("For micro-service 's app to use") 36 | .version("V1.0").build(); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /front-app/src/main/java/com/simplemall/micro/serv/page/aop/APISecurityCheck.java: -------------------------------------------------------------------------------- 1 | package com.simplemall.micro.serv.page.aop; 2 | 3 | import java.util.Iterator; 4 | import java.util.Map; 5 | 6 | import javax.servlet.http.HttpServletRequest; 7 | 8 | import org.apache.log4j.spi.LoggerFactory; 9 | import org.aspectj.lang.JoinPoint; 10 | import org.aspectj.lang.annotation.Aspect; 11 | import org.aspectj.lang.annotation.Before; 12 | import org.slf4j.Logger; 13 | import org.springframework.core.annotation.Order; 14 | import org.springframework.stereotype.Component; 15 | import org.springframework.web.context.request.RequestAttributes; 16 | import org.springframework.web.context.request.RequestContextHolder; 17 | import org.springframework.web.context.request.ServletRequestAttributes; 18 | 19 | import com.simplemall.micro.serv.common.service.JedisUtil; 20 | import com.simplemall.micro.serv.page.security.JWTUtils; 21 | 22 | import io.jsonwebtoken.ExpiredJwtException; 23 | import io.jsonwebtoken.MalformedJwtException; 24 | import io.jsonwebtoken.SignatureException; 25 | import io.jsonwebtoken.UnsupportedJwtException; 26 | 27 | @Aspect 28 | @Order(0) 29 | @Component 30 | public class APISecurityCheck { 31 | 32 | private Logger logger = org.slf4j.LoggerFactory.getLogger(getClass()); 33 | 34 | /** 35 | * 客户端给出的签名字段 36 | */ 37 | private static final String access_token = "accessToken"; 38 | 39 | /** 40 | * 前置通知:所有接口在执行业务之前,需要先进行参数合法性校验 执行顺序为1 41 | * 42 | * @param joinPoint 43 | * @throws Exception 44 | * @throws BusinessException 45 | */ 46 | @Before("execution(public * com.simplemall.micro.serv.page.api.*.* (..))") 47 | public void doBeforeInService(JoinPoint joinPoint) throws Exception { 48 | RequestAttributes ra = RequestContextHolder.getRequestAttributes(); 49 | ServletRequestAttributes sra = (ServletRequestAttributes) ra; 50 | HttpServletRequest request = sra.getRequest(); 51 | // 需要过滤URI的请求,有些不需要token的地方直接跳过不再校验 52 | String requestPath = request.getRequestURI(); // 请求的URL 53 | logger.info("request path = " + requestPath); 54 | Map inputParamMap = request.getParameterMap(); 55 | Iterator keyIter = inputParamMap.keySet().iterator(); 56 | while (keyIter.hasNext()) { 57 | String currKey = keyIter.next(); 58 | String value = ((String[]) inputParamMap.get(currKey))[0].toString(); 59 | if (access_token.equals(currKey)) { 60 | //验证此jwt是否已经被注销,由于jwt在有效期均有效,本案例借助redis实现注销机制 61 | if(JedisUtil.KEYS.exists(value)){ 62 | throw new Exception("token已注销,请勿重复使用!"); 63 | } 64 | try { 65 | JWTUtils.parseJWT(value); 66 | } catch (ExpiredJwtException | UnsupportedJwtException | MalformedJwtException | SignatureException 67 | | IllegalArgumentException exception) { 68 | throw new Exception("token校验失败!"); 69 | } 70 | } 71 | System.out.println("---" + currKey + "------------" + value + "--------"); 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /front-app/src/main/java/com/simplemall/micro/serv/page/api/APIPayMentController.java: -------------------------------------------------------------------------------- 1 | package com.simplemall.micro.serv.page.api; 2 | 3 | import java.math.BigDecimal; 4 | 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.cloud.client.loadbalancer.LoadBalancerClient; 7 | import org.springframework.util.LinkedMultiValueMap; 8 | import org.springframework.util.MultiValueMap; 9 | import org.springframework.web.bind.annotation.RequestMapping; 10 | import org.springframework.web.bind.annotation.RequestMethod; 11 | import org.springframework.web.bind.annotation.RequestParam; 12 | import org.springframework.web.bind.annotation.RestController; 13 | import org.springframework.web.client.RestTemplate; 14 | 15 | import com.simplemall.micro.serv.common.bean.RestAPIResult; 16 | import com.simplemall.micro.serv.common.constant.SystemConstants; 17 | 18 | import io.swagger.annotations.Api; 19 | import io.swagger.annotations.ApiOperation; 20 | 21 | @Api(value = "支付服务", tags = "支付服务接口") 22 | @RestController 23 | @RequestMapping("/payment") 24 | public class APIPayMentController { 25 | 26 | private final static String PAY_SERVICE_URL = "http://PAYMENT-SERVICE:8082"; 27 | 28 | private final static String ORDER_SERVICE_URL = "http://ORDER-SERVICE:8083"; 29 | 30 | @Autowired 31 | LoadBalancerClient loadBalancerClient; 32 | 33 | @Autowired 34 | RestTemplate restTemplate; 35 | 36 | @ApiOperation(value = "支付") 37 | @RequestMapping(value = "pay", method = RequestMethod.POST) 38 | public RestAPIResult pay(@RequestParam("serialNo") String serialNo, 39 | @RequestParam("payType") String payType, @RequestParam("price") BigDecimal price, String accessToken) { 40 | // this.loadBalancerClient.choose(PAY_SERVICE); 41 | // 采用微服务的事件驱动机制,不在此直接调用两个服务 42 | RestAPIResult restAPIResult = new RestAPIResult<>(); 43 | MultiValueMap uriVariable = new LinkedMultiValueMap<>(); 44 | uriVariable.add("serialNo", serialNo); 45 | uriVariable.add("payType", payType); 46 | uriVariable.add("price", price); 47 | int payResult = restTemplate.postForObject(PAY_SERVICE_URL + "/payment/pay", uriVariable, Integer.class); 48 | if (SystemConstants.Code.success == payResult) { 49 | // notice order system to update order state 50 | MultiValueMap uriNoticeVariable = new LinkedMultiValueMap<>(); 51 | uriNoticeVariable.add("serialNo", serialNo); 52 | uriNoticeVariable.add("payStatus", SystemConstants.PAY_STATUS.PAID); 53 | uriNoticeVariable.add("orderStatus", SystemConstants.STATE.SHIPPING); 54 | int update = restTemplate.postForObject(ORDER_SERVICE_URL + "/order/state/change", uriNoticeVariable, 55 | Integer.class); 56 | // FIXME 存在数据一致性问题,后期待优化 57 | if ((payResult + update) < 1) { 58 | restAPIResult = new RestAPIResult<>("支付失败,请稍后重试!"); 59 | } 60 | } 61 | return restAPIResult; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /front-app/src/main/java/com/simplemall/micro/serv/page/api/APIProductController.java: -------------------------------------------------------------------------------- 1 | package com.simplemall.micro.serv.page.api; 2 | 3 | import java.util.List; 4 | 5 | import org.slf4j.Logger; 6 | import org.slf4j.LoggerFactory; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.web.bind.annotation.PathVariable; 9 | import org.springframework.web.bind.annotation.RequestMapping; 10 | import org.springframework.web.bind.annotation.RequestMethod; 11 | import org.springframework.web.bind.annotation.RestController; 12 | 13 | import com.simplemall.micro.serv.common.bean.RestAPIResult; 14 | import com.simplemall.micro.serv.common.bean.product.PrdInfo; 15 | import com.simplemall.micro.serv.page.client.ProductFeignClient; 16 | 17 | import io.swagger.annotations.Api; 18 | import io.swagger.annotations.ApiOperation; 19 | 20 | @Api(value = "商品服务", tags = "商品服务") 21 | @RestController 22 | @RequestMapping("/prd") 23 | public class APIProductController { 24 | 25 | private Logger logger = LoggerFactory.getLogger(APIProductController.class); 26 | 27 | @Autowired 28 | ProductFeignClient feignClient; 29 | 30 | @ApiOperation(value = "获取商品详情") 31 | @RequestMapping(value = "detail/{prdId}", method = RequestMethod.POST) 32 | // 必须采用pathvariable的方式引入参数 33 | public RestAPIResult getProductById(@PathVariable("prdId") String prdId) { 34 | RestAPIResult restAPIResult = new RestAPIResult<>(); 35 | logger.info("begin invoke product service"); 36 | PrdInfo info = feignClient.getPorudctById(prdId); 37 | restAPIResult.setRespData(info); 38 | return restAPIResult; 39 | } 40 | 41 | @ApiOperation(value = "商品列表展示") 42 | @RequestMapping(value = "list", method = RequestMethod.POST) 43 | public RestAPIResult> list() { 44 | RestAPIResult> restAPIResult = new RestAPIResult<>(); 45 | List products = feignClient.list(); 46 | restAPIResult.setRespData(products); 47 | return restAPIResult; 48 | } 49 | 50 | /** 51 | * @param prdId 52 | * @return 53 | */ 54 | @ApiOperation(value = "购买商品,前提是先登陆") 55 | @RequestMapping(value = "buy/{prdId}", method = RequestMethod.POST) 56 | public RestAPIResult buyProduct(String prdId, String jwt) { 57 | RestAPIResult restAPIResult = new RestAPIResult<>(); 58 | if (!checkAccountOnLine(jwt)) { 59 | restAPIResult = new RestAPIResult<>("未登陆"); 60 | } 61 | // 登陆后,跳转到结算页面,录入收货地址、支付方式、收货方式等等 62 | return restAPIResult; 63 | } 64 | 65 | /** 66 | * 校验用户是否登陆 67 | * 68 | * @param request 69 | * @return 70 | */ 71 | // FIXME 安全验证待完善 72 | private boolean checkAccountOnLine(String jwt) { 73 | // if (session.getAttribute(WebSecurityConfig.SESSION_KEY) != null) 74 | // return true; 75 | return false; 76 | } 77 | 78 | } 79 | -------------------------------------------------------------------------------- /front-app/src/main/java/com/simplemall/micro/serv/page/client/AccountFeignClient.java: -------------------------------------------------------------------------------- 1 | package com.simplemall.micro.serv.page.client; 2 | 3 | import java.util.List; 4 | 5 | import org.springframework.cloud.netflix.feign.FeignClient; 6 | import org.springframework.web.bind.annotation.PathVariable; 7 | import org.springframework.web.bind.annotation.RequestMapping; 8 | import org.springframework.web.bind.annotation.RequestParam; 9 | 10 | import com.simplemall.micro.serv.common.bean.account.AccAddress; 11 | import com.simplemall.micro.serv.common.bean.account.Account; 12 | 13 | /** 14 | * feign与@RequestParam配合使用时,一定要写value值。 15 | * feign方法的@RequestMapping,务必与服务端方法保持一致,请求类型,请求参数,返回值等等 16 | * 17 | * TODO 可以从服务端定义一个接口层,服务实现层实现接口,调用方扩展此接口,即可完成接口定义的复用,而无须在此重新复制一次。 18 | * 但此举会导致服务端接口变动后,调用方就会直接受影响,建议事先约定好规则 19 | * 20 | * @author guooo 21 | * 22 | */ 23 | @FeignClient(name = "ACCOUNT-SERVICE") 24 | public interface AccountFeignClient { 25 | 26 | /** 27 | * 登录 28 | * 29 | * @param phone 30 | * @param password 31 | * @return 32 | */ 33 | @RequestMapping("/acc/login") 34 | public Account login(@RequestParam("phone") String phone, @RequestParam("password") String password); 35 | 36 | /** 37 | * 注册 38 | * 39 | * @param phone 40 | * @param password 41 | * @return 42 | */ 43 | @RequestMapping("/acc/signup") 44 | public String signup(@RequestParam("phone") String phone, @RequestParam("password") String password); 45 | 46 | /** 47 | * get address list 48 | * 49 | * @param accountTid 50 | * @return 51 | */ 52 | @RequestMapping("/address/list/{accountTid}") 53 | public List getList( 54 | @RequestParam(value = "accountTid", required = true) @PathVariable("accountTid") String accountTid); 55 | } 56 | -------------------------------------------------------------------------------- /front-app/src/main/java/com/simplemall/micro/serv/page/client/OrderFeignClient.java: -------------------------------------------------------------------------------- 1 | package com.simplemall.micro.serv.page.client; 2 | 3 | import org.springframework.cloud.netflix.feign.FeignClient; 4 | import org.springframework.web.bind.annotation.RequestMapping; 5 | import org.springframework.web.bind.annotation.RequestMethod; 6 | import org.springframework.web.bind.annotation.RequestParam; 7 | 8 | import com.simplemall.micro.serv.page.client.hystrix.OrderFeignClientHystrix; 9 | 10 | @FeignClient(name = "ORDER-SERVICE" ,fallback = OrderFeignClientHystrix.class) 11 | public interface OrderFeignClient { 12 | 13 | /** 14 | * 创建订单 15 | * 16 | * @param orderJsonStr 17 | * @return 18 | */ 19 | @RequestMapping(value = "/order/create", method = RequestMethod.POST) 20 | public String createOrder(@RequestParam(value = "orderJsonStr", required = true) String orderJsonStr); 21 | } 22 | -------------------------------------------------------------------------------- /front-app/src/main/java/com/simplemall/micro/serv/page/client/ProductFeignClient.java: -------------------------------------------------------------------------------- 1 | package com.simplemall.micro.serv.page.client; 2 | 3 | import java.util.List; 4 | 5 | import org.springframework.cloud.netflix.feign.FeignClient; 6 | import org.springframework.web.bind.annotation.PathVariable; 7 | import org.springframework.web.bind.annotation.RequestMapping; 8 | import org.springframework.web.bind.annotation.RequestMethod; 9 | import org.springframework.web.bind.annotation.RequestParam; 10 | 11 | import com.simplemall.micro.serv.common.bean.product.PrdInfo; 12 | import com.simplemall.micro.serv.page.client.hystrix.ProductFeignClientHystrix; 13 | 14 | /** 15 | * get product detail info 16 | * 17 | * @author guooo 18 | * 19 | */ 20 | @FeignClient(name = "PRODUCT-SERVICE",fallback = ProductFeignClientHystrix.class) 21 | public interface ProductFeignClient { 22 | 23 | @RequestMapping(value = "/prd/{prdId}",method = RequestMethod.POST) 24 | public PrdInfo getPorudctById(@RequestParam(value = "prdId",required= true) @PathVariable("prdId") String prdId); 25 | 26 | @RequestMapping(value = "/prd/list",method = RequestMethod.POST) 27 | public List list(); 28 | } 29 | -------------------------------------------------------------------------------- /front-app/src/main/java/com/simplemall/micro/serv/page/client/hystrix/OrderFeignClientHystrix.java: -------------------------------------------------------------------------------- 1 | package com.simplemall.micro.serv.page.client.hystrix; 2 | 3 | import org.springframework.stereotype.Component; 4 | 5 | import com.simplemall.micro.serv.page.client.OrderFeignClient; 6 | 7 | @Component 8 | public class OrderFeignClientHystrix implements OrderFeignClient { 9 | 10 | @Override 11 | public String createOrder(String orderJsonStr) { 12 | return "create failed!"; 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /front-app/src/main/java/com/simplemall/micro/serv/page/client/hystrix/ProductFeignClientHystrix.java: -------------------------------------------------------------------------------- 1 | package com.simplemall.micro.serv.page.client.hystrix; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import org.springframework.stereotype.Component; 7 | 8 | import com.simplemall.micro.serv.common.bean.product.PrdInfo; 9 | import com.simplemall.micro.serv.page.client.ProductFeignClient; 10 | 11 | /** 12 | * 生成空对象,防止出现Null,对调用方造成其他问题 13 | * 14 | * @author Guooo 2017年9月3日 下午10:02:55 15 | */ 16 | @Component 17 | public class ProductFeignClientHystrix implements ProductFeignClient { 18 | 19 | @Override 20 | public PrdInfo getPorudctById(String prdId) { 21 | return new PrdInfo(); 22 | } 23 | 24 | @Override 25 | public List list() { 26 | return new ArrayList<>(); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /front-app/src/main/java/com/simplemall/micro/serv/page/security/JWTUtils.java: -------------------------------------------------------------------------------- 1 | 2 | package com.simplemall.micro.serv.page.security; 3 | 4 | import java.util.Date; 5 | 6 | import javax.crypto.SecretKey; 7 | import javax.crypto.spec.SecretKeySpec; 8 | 9 | import org.apache.commons.codec.binary.Base64; 10 | 11 | import com.simplemall.micro.serv.common.util.UUIDUtils; 12 | 13 | import io.jsonwebtoken.Claims; 14 | import io.jsonwebtoken.ExpiredJwtException; 15 | import io.jsonwebtoken.JwtBuilder; 16 | import io.jsonwebtoken.Jwts; 17 | import io.jsonwebtoken.MalformedJwtException; 18 | import io.jsonwebtoken.SignatureAlgorithm; 19 | import io.jsonwebtoken.SignatureException; 20 | import io.jsonwebtoken.UnsupportedJwtException; 21 | 22 | /** 23 | * ClassName: JWTUtils
24 | * Function:Json Web Token的java实现
25 | * date: 2017年9月4日 下午5:26:01
26 | * 27 | * @author guooo 28 | * @version 29 | * @since JDK 1.6 30 | */ 31 | public class JWTUtils { 32 | 33 | static String SECRETKEY = "OVlpXYjNwaFJYUllVbXhXTkZaR1pEQlNiVkYzWTBac1YxWkZXbE"; 34 | 35 | /** 36 | * 由字符串生成加密key 37 | * 38 | * @return 39 | */ 40 | public static SecretKey generalKey(String stringKey) { 41 | byte[] encodedKey = Base64.decodeBase64(stringKey); 42 | SecretKey key = new SecretKeySpec(encodedKey, 0, encodedKey.length, "AES"); 43 | return key; 44 | } 45 | 46 | /** 47 | * createJWT: 创建jwt
48 | * 49 | * @author guooo 50 | * @param id 51 | * 唯一id,uuid即可 52 | * @param subject 53 | * json形式字符串或字符串,增加用户非敏感信息存储,如user tid,与token解析后进行对比,防止乱用 54 | * @param ttlMillis 55 | * 有效期 56 | * @param stringKey 57 | * @return jwt token 58 | * @throws Exception 59 | * @since JDK 1.6 60 | */ 61 | public static String createJWT(String id, String subject, long ttlMillis) throws Exception { 62 | SignatureAlgorithm signatureAlgorithm = SignatureAlgorithm.HS256; 63 | long nowMillis = System.currentTimeMillis(); 64 | Date now = new Date(nowMillis); 65 | SecretKey key = generalKey(SECRETKEY); 66 | JwtBuilder builder = Jwts.builder().setIssuer("").setId(id).setIssuedAt(now).setSubject(subject) 67 | .signWith(signatureAlgorithm, key); 68 | if (ttlMillis >= 0) { 69 | long expMillis = nowMillis + ttlMillis; 70 | Date exp = new Date(expMillis); 71 | builder.setExpiration(exp); 72 | } 73 | return builder.compact(); 74 | } 75 | 76 | /** 77 | * parseJWT: 解密jwt
78 | * 79 | * @author guooo 80 | * @param jwt 81 | * @param stringKey 82 | * @return 83 | * @throws ExpiredJwtException 84 | * @throws UnsupportedJwtException 85 | * @throws MalformedJwtException 86 | * @throws SignatureException 87 | * @throws IllegalArgumentException 88 | * @since JDK 1.6 89 | */ 90 | public static Claims parseJWT(String jwt) throws ExpiredJwtException, UnsupportedJwtException, 91 | MalformedJwtException, SignatureException, IllegalArgumentException { 92 | SecretKey key = generalKey(SECRETKEY); 93 | Claims claims = Jwts.parser().setSigningKey(key).parseClaimsJws(jwt).getBody(); 94 | return claims; 95 | } 96 | 97 | public static void main(String[] args) { 98 | try { 99 | String token = createJWT(UUIDUtils.getUUID(), "", 20000); 100 | System.out.println(token); 101 | Claims claims = parseJWT(token); 102 | System.out.println(claims.getExpiration()+"///"+claims.getExpiration().getTime()); 103 | } catch (Exception e) { 104 | e.printStackTrace(); 105 | } 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /front-app/src/main/java/com/simplemall/micro/serv/page/service/IShoppingService.java: -------------------------------------------------------------------------------- 1 | package com.simplemall.micro.serv.page.service; 2 | 3 | /** 4 | * 购物服务的实现 5 | * 6 | * @author guooo 7 | * 8 | */ 9 | public interface IShoppingService { 10 | 11 | } 12 | -------------------------------------------------------------------------------- /front-app/src/main/java/com/simplemall/micro/serv/page/service/impl/ShopingServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.simplemall.micro.serv.page.service.impl; 2 | 3 | import org.springframework.stereotype.Service; 4 | 5 | import com.simplemall.micro.serv.page.service.IShoppingService; 6 | 7 | @Service 8 | public class ShopingServiceImpl implements IShoppingService{ 9 | 10 | } 11 | -------------------------------------------------------------------------------- /front-app/src/main/java/com/simplemall/micro/serv/page/start/StartUpLoading.java: -------------------------------------------------------------------------------- 1 | package com.simplemall.micro.serv.page.start; 2 | 3 | import java.util.Date; 4 | import java.util.HashSet; 5 | import java.util.Set; 6 | 7 | import org.slf4j.Logger; 8 | import org.slf4j.LoggerFactory; 9 | import org.springframework.boot.CommandLineRunner; 10 | import org.springframework.stereotype.Component; 11 | 12 | import com.simplemall.micro.serv.common.constant.SystemConstants; 13 | import com.simplemall.micro.serv.common.service.JedisUtil; 14 | 15 | /** 16 | * 启动后就加载数据 17 | * 18 | * @author guooo 19 | * 20 | */ 21 | @Component 22 | public class StartUpLoading implements CommandLineRunner { 23 | private Logger logger = LoggerFactory.getLogger(StartUpLoading.class); 24 | 25 | @Override 26 | public void run(String... arg0) throws Exception { 27 | logger.info("--->>>开始初始化加载数据{}", new Date()); 28 | // 加载需要token拦截的URI,能过配置文件或比较便捷的方式,不建议在代码中配置,此处仅为方便演示 29 | Set uris = new HashSet<>(); 30 | uris.add("/order/create"); 31 | uris.add("/order/view"); 32 | uris.add("/order/state/change"); 33 | uris.add("/payment/pay"); 34 | 35 | for (String uri : uris) { 36 | JedisUtil.SETS.sadd(SystemConstants.URL_NEED_CHECK_KEY, uri); 37 | } 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /front-app/src/main/java/com/simplemall/micro/serv/page/web/AccountController.java: -------------------------------------------------------------------------------- 1 | package com.simplemall.micro.serv.page.web; 2 | 3 | import org.slf4j.Logger; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.web.bind.annotation.RequestMapping; 6 | import org.springframework.web.bind.annotation.RequestMethod; 7 | import org.springframework.web.bind.annotation.RequestParam; 8 | import org.springframework.web.bind.annotation.RestController; 9 | import org.springframework.web.client.RestTemplate; 10 | 11 | import com.simplemall.micro.serv.common.bean.RestAPIResult; 12 | 13 | import io.swagger.annotations.ApiParam; 14 | 15 | /** 16 | * 传统方式调用服务 17 | * 18 | * @author guooo 19 | * 20 | */ 21 | @RestController 22 | @RequestMapping("/account") 23 | public class AccountController { 24 | 25 | private Logger logger = org.slf4j.LoggerFactory.getLogger(AccountController.class); 26 | 27 | @Autowired 28 | private RestTemplate restTemplate; 29 | 30 | @RequestMapping(value = "login", method = { RequestMethod.POST, RequestMethod.GET }) 31 | public RestAPIResult login(@ApiParam(value = "手机号") @RequestParam(required = true) String phone, 32 | @ApiParam(value = "密码") @RequestParam(required = true) String password) { 33 | RestAPIResult restAPIResult = new RestAPIResult<>(); 34 | String result = this.restTemplate 35 | .getForObject("http://guooo-PC:8080/acc/login?phone=" + phone + "&password=" + password, String.class); 36 | logger.info("login result = {}", result); 37 | return restAPIResult; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /front-app/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | server.port=8088 2 | logging.level.tk.mybatis=TRACE 3 | spring.application.name=front-app 4 | 5 | eureka.client.serviceUrl.defaultZone=http://localhost:9003/eureka/ 6 | spring.boot.admin.url=http://localhost:9002 7 | 8 | management.security.enabled=false 9 | 10 | account-service.ribbon.NFLoadBalancerRuleClassName=com.netflix.loadbalancer.RandomRule 11 | 12 | feign.hystrix.enabled=true 13 | hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds=5000 14 | -------------------------------------------------------------------------------- /front-app/src/main/resources/bootstrap.properties: -------------------------------------------------------------------------------- 1 | spring.cloud.config.name=front-app 2 | spring.cloud.config.label=master 3 | spring.cloud.config.profile=dev 4 | spring.cloud.config.uri= http://localhost:9004/ 5 | spring.cloud.config.username=user 6 | spring.cloud.config.password=yourPW 7 | 8 | #https://springcloud.cc/spring-cloud-config-zhcn.html#config-client-fail-fast 9 | #new spring-retry,spring-cloud-starter-aop 10 | spring.cloud.config.failFast=true 11 | 12 | spring.rabbitmq.host=localhost 13 | spring.rabbitmq.port=5672 14 | spring.rabbitmq.username=guest 15 | spring.rabbitmq.password=guest -------------------------------------------------------------------------------- /front-app/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | ${LOG_HOME}/${LOG_PREFIX}-info.log 14 | 15 | 16 | ${LOG_HOME}/${LOG_PREFIX}-info-%d{yyyyMMdd}.log.%i 17 | 18 | 100MB 19 | 30 20 | 20GB 21 | 22 | 23 | 24 | %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} -%msg%n 25 | 26 | 27 | 28 | 29 | 30 | 31 | ERROR 32 | 33 | ${LOG_HOME}/${LOG_PREFIX}-error.log 34 | 35 | 36 | ${LOG_HOME}/${LOG_PREFIX}-error-%d{yyyyMMdd}.log.%i 37 | 38 | 100MB 39 | 30 40 | 20GB 41 | 42 | 43 | 44 | %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} -%msg%n 45 | 46 | 47 | 48 | 49 | 50 | 51 | %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /front-app/src/main/resources/public/bootstrap-3.3.7-dist/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maventalker/simplemall/12c5070c4dc0abbae4d78d723c5e51cb43442dd6/front-app/src/main/resources/public/bootstrap-3.3.7-dist/.DS_Store -------------------------------------------------------------------------------- /front-app/src/main/resources/public/bootstrap-3.3.7-dist/fonts/glyphicons-halflings-regular.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maventalker/simplemall/12c5070c4dc0abbae4d78d723c5e51cb43442dd6/front-app/src/main/resources/public/bootstrap-3.3.7-dist/fonts/glyphicons-halflings-regular.eot -------------------------------------------------------------------------------- /front-app/src/main/resources/public/bootstrap-3.3.7-dist/fonts/glyphicons-halflings-regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maventalker/simplemall/12c5070c4dc0abbae4d78d723c5e51cb43442dd6/front-app/src/main/resources/public/bootstrap-3.3.7-dist/fonts/glyphicons-halflings-regular.ttf -------------------------------------------------------------------------------- /front-app/src/main/resources/public/bootstrap-3.3.7-dist/fonts/glyphicons-halflings-regular.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maventalker/simplemall/12c5070c4dc0abbae4d78d723c5e51cb43442dd6/front-app/src/main/resources/public/bootstrap-3.3.7-dist/fonts/glyphicons-halflings-regular.woff -------------------------------------------------------------------------------- /front-app/src/main/resources/public/bootstrap-3.3.7-dist/fonts/glyphicons-halflings-regular.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maventalker/simplemall/12c5070c4dc0abbae4d78d723c5e51cb43442dd6/front-app/src/main/resources/public/bootstrap-3.3.7-dist/fonts/glyphicons-halflings-regular.woff2 -------------------------------------------------------------------------------- /front-app/src/main/resources/public/bootstrap-3.3.7-dist/js/npm.js: -------------------------------------------------------------------------------- 1 | // This file is autogenerated via the `commonjs` Grunt task. You can require() this file in a CommonJS environment. 2 | require('../../js/transition.js') 3 | require('../../js/alert.js') 4 | require('../../js/button.js') 5 | require('../../js/carousel.js') 6 | require('../../js/collapse.js') 7 | require('../../js/dropdown.js') 8 | require('../../js/modal.js') 9 | require('../../js/tooltip.js') 10 | require('../../js/popover.js') 11 | require('../../js/scrollspy.js') 12 | require('../../js/tab.js') 13 | require('../../js/affix.js') -------------------------------------------------------------------------------- /front-app/src/main/resources/public/checkout.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SimpleMall Signup 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 20 |
21 | 22 |
Choose Shipping Address
23 |
24 |
    25 |
    26 | 30 |
    31 |
32 |
33 |
34 |
35 |
Choose Pay Way
36 |
37 | 43 |
44 |
45 |
46 |
Choose Shipping Way
47 |
48 | 54 |
55 |
56 |

57 | 58 |

59 |
60 | 95 | 96 | 97 | 98 | -------------------------------------------------------------------------------- /front-app/src/main/resources/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SimpleMall Signup 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 |

Hello, world!

15 |

This is a Simple Mall unit, based on micro-service architecture 16 | used Spring Cloud ! GitHub : https://github.com/backkoms/simplemall

17 |

18 | Learn 20 | more 21 |

22 |
{{ message }}
23 | 31 |
32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /front-app/src/main/resources/public/login.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SimpleMall login 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 |
15 | 18 |
19 |
20 | 23 |
24 | 25 | 26 | 28 |
29 | 57 | 58 | -------------------------------------------------------------------------------- /front-app/src/main/resources/public/my.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SimpleMall Signup 6 | 7 | 8 | 9 | 10 |
11 |
12 | 15 |
16 |
17 | 20 |
21 | 22 |
23 | 24 | -------------------------------------------------------------------------------- /front-app/src/main/resources/public/order_detail.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SimpleMall Signup 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /front-app/src/main/resources/public/order_list.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SimpleMall Signup 6 | 7 | 8 | 9 | 10 |
11 |
12 | 15 |
16 |
17 | 20 |
21 | 22 |
23 | 24 | -------------------------------------------------------------------------------- /front-app/src/main/resources/public/pay.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SimpleMall Signup 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 21 | 23 |
24 | 38 | 39 | -------------------------------------------------------------------------------- /front-app/src/main/resources/public/product_detail.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SimpleMall Signup 6 | 7 | 8 | 9 | 10 |
11 |
12 | 15 |
16 |
17 | 20 |
21 | 22 |
23 | 24 | -------------------------------------------------------------------------------- /front-app/src/main/resources/public/products.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SimpleMall product list 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 |
Product NameShortDescPriceAction 28 |
{{item.labelName}}{{item.shortDesc}}¥{{item.price}}
39 |
40 | 74 | 75 | -------------------------------------------------------------------------------- /front-app/src/main/resources/public/signup.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SimpleMall Signup 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 |
15 | 17 |
18 |
19 | 22 |
23 | 24 | 26 |
27 | 52 | 53 | -------------------------------------------------------------------------------- /getqrcode.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maventalker/simplemall/12c5070c4dc0abbae4d78d723c5e51cb43442dd6/getqrcode.jpeg -------------------------------------------------------------------------------- /msg-service/src/main/java/com/simplemall/micro/serv/msg/MsgServApplication.java: -------------------------------------------------------------------------------- 1 | package com.simplemall.micro.serv.msg; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; 6 | 7 | @EnableDiscoveryClient 8 | @SpringBootApplication 9 | public class MsgServApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(MsgServApplication.class, args); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /msg-service/src/main/java/com/simplemall/micro/serv/msg/config/DruidDataSourceConfig.java: -------------------------------------------------------------------------------- 1 | package com.simplemall.micro.serv.msg.config; 2 | 3 | import com.alibaba.druid.pool.DruidDataSource; 4 | import org.slf4j.Logger; 5 | import org.slf4j.LoggerFactory; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.boot.context.properties.EnableConfigurationProperties; 8 | import org.springframework.context.annotation.Bean; 9 | import org.springframework.context.annotation.Configuration; 10 | import org.springframework.context.annotation.Primary; 11 | 12 | import javax.sql.DataSource; 13 | import java.sql.SQLException; 14 | 15 | @Configuration 16 | @EnableConfigurationProperties(DataSourceProperties.class) 17 | public class DruidDataSourceConfig { 18 | 19 | private static Logger logger = LoggerFactory.getLogger(DruidDataSourceConfig.class); 20 | 21 | @Autowired 22 | private DataSourceProperties dataSourceProperties; 23 | 24 | @Bean 25 | @Primary 26 | public DataSource druidDataSource(){ 27 | DruidDataSource datasource = new DruidDataSource(); 28 | 29 | datasource.setUrl(dataSourceProperties.getUrl()); 30 | datasource.setUsername(dataSourceProperties.getUsername()); 31 | datasource.setPassword(dataSourceProperties.getPassword()); 32 | datasource.setDriverClassName(dataSourceProperties.getDriverClassName()); 33 | datasource.setInitialSize(dataSourceProperties.getInitialSize()); 34 | datasource.setMinIdle(dataSourceProperties.getMinIdle()); 35 | datasource.setMaxActive(dataSourceProperties.getMaxActive()); 36 | datasource.setMaxWait(dataSourceProperties.getMaxWait()); 37 | datasource.setTimeBetweenEvictionRunsMillis(dataSourceProperties.getTimeBetweenEvictionRunsMillis()); 38 | datasource.setMinEvictableIdleTimeMillis(dataSourceProperties.getMinEvictableIdleTimeMillis()); 39 | datasource.setValidationQuery(dataSourceProperties.getValidationQuery()); 40 | datasource.setTestWhileIdle(dataSourceProperties.isTestWhileIdle()); 41 | datasource.setTestOnBorrow(dataSourceProperties.isTestOnBorrow()); 42 | datasource.setTestOnReturn(dataSourceProperties.isTestOnReturn()); 43 | datasource.setPoolPreparedStatements(dataSourceProperties.isPoolPreparedStatements()); 44 | try { 45 | datasource.setFilters(dataSourceProperties.getFilters()); 46 | } catch (SQLException e) { 47 | logger.error("Druid configuration initialization filter error.", e); 48 | } 49 | return datasource; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /msg-service/src/main/java/com/simplemall/micro/serv/msg/config/SqlSessionFactoryConfig.java: -------------------------------------------------------------------------------- 1 | package com.simplemall.micro.serv.msg.config; 2 | 3 | import javax.sql.DataSource; 4 | 5 | import org.apache.ibatis.session.SqlSessionFactory; 6 | import org.mybatis.spring.SqlSessionFactoryBean; 7 | import org.mybatis.spring.SqlSessionTemplate; 8 | import org.mybatis.spring.annotation.MapperScan; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.context.annotation.Bean; 11 | import org.springframework.context.annotation.Configuration; 12 | import org.springframework.core.io.support.PathMatchingResourcePatternResolver; 13 | import org.springframework.jdbc.datasource.DataSourceTransactionManager; 14 | import org.springframework.transaction.PlatformTransactionManager; 15 | import org.springframework.transaction.annotation.EnableTransactionManagement; 16 | import org.springframework.transaction.annotation.TransactionManagementConfigurer; 17 | 18 | @Configuration 19 | @EnableTransactionManagement 20 | @MapperScan("com.simplemall.micro.serv.msg.mapper") 21 | public class SqlSessionFactoryConfig implements TransactionManagementConfigurer { 22 | 23 | @Autowired 24 | private DataSource dataSource; 25 | 26 | @Autowired 27 | private DataSourceProperties dataSourceProperties; 28 | 29 | /** 30 | * 创建sqlSessionFactoryBean 31 | * @return 32 | * @throws Exception 33 | */ 34 | @Bean(name = "sqlSessionFactory") 35 | public SqlSessionFactory createSqlSessionFactoryBean() throws Exception { 36 | SqlSessionFactoryBean bean = new SqlSessionFactoryBean(); 37 | bean.setDataSource(dataSource); 38 | bean.setTypeAliasesPackage(dataSourceProperties.getTypeAliasPackage()); 39 | 40 | PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(); 41 | bean.setMapperLocations(resolver.getResources(dataSourceProperties.getMapperLocations())); 42 | 43 | return bean.getObject(); 44 | } 45 | 46 | @Bean 47 | public SqlSessionTemplate sqlSessionTemplate(SqlSessionFactory sqlSessionFactory) { 48 | return new SqlSessionTemplate(sqlSessionFactory); 49 | } 50 | 51 | @Bean 52 | @Override 53 | public PlatformTransactionManager annotationDrivenTransactionManager() { 54 | return new DataSourceTransactionManager(dataSource); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /msg-service/src/main/java/com/simplemall/micro/serv/msg/controller/MsgController.java: -------------------------------------------------------------------------------- 1 | package com.simplemall.micro.serv.msg.controller; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.web.bind.annotation.RequestMapping; 5 | import org.springframework.web.bind.annotation.RequestMethod; 6 | import org.springframework.web.bind.annotation.RestController; 7 | 8 | import com.simplemall.micro.serv.common.bean.RestAPIResult; 9 | import com.simplemall.micro.serv.msg.service.IMsgService; 10 | 11 | @RestController 12 | @RequestMapping("/msg") 13 | public class MsgController { 14 | 15 | @Autowired 16 | IMsgService msgService; 17 | 18 | /** 19 | * 添加一条消息 20 | * 21 | * @param serialNo 22 | * @param msgType 23 | * @param target 24 | * @param content 25 | * @return 26 | */ 27 | @RequestMapping(value = "add", method = RequestMethod.POST) 28 | public RestAPIResult addMsg(String serialNo, String msgType, String target, String content) { 29 | RestAPIResult apiResult = new RestAPIResult(); 30 | int result = msgService.addMsg(serialNo, msgType, target, content); 31 | apiResult.setRespData(result); 32 | return apiResult; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /msg-service/src/main/java/com/simplemall/micro/serv/msg/mapper/MsgNoticeMapper.java: -------------------------------------------------------------------------------- 1 | package com.simplemall.micro.serv.msg.mapper; 2 | 3 | import java.util.List; 4 | 5 | import org.apache.ibatis.annotations.Param; 6 | 7 | import com.simplemall.micro.serv.msg.bean.MsgNotice; 8 | import com.simplemall.micro.serv.msg.bean.MsgNoticeCriteria; 9 | 10 | public interface MsgNoticeMapper { 11 | /** 12 | * 根据条件计数 13 | * 14 | * @param example 15 | */ 16 | int countByExample(MsgNoticeCriteria example); 17 | 18 | /** 19 | * 20 | * @param example 21 | */ 22 | int deleteByExample(MsgNoticeCriteria example); 23 | 24 | /** 25 | * 根据主键删除数据库的记录 26 | * 27 | * @param tid 28 | */ 29 | int deleteByPrimaryKey(String tid); 30 | 31 | /** 32 | * 插入数据库记录 33 | * 34 | * @param record 35 | */ 36 | int insert(MsgNotice record); 37 | 38 | /** 39 | * 插入数据库记录 40 | * 41 | * @param record 42 | */ 43 | int insertSelective(MsgNotice record); 44 | 45 | /** 46 | * 根据条件查询列表 47 | * 48 | * @param example 49 | */ 50 | List selectByExample(MsgNoticeCriteria example); 51 | 52 | /** 53 | * 根据主键获取一条数据库记录 54 | * 55 | * @param tid 56 | */ 57 | MsgNotice selectByPrimaryKey(String tid); 58 | 59 | /** 60 | * 选择性更新数据库记录 61 | * 62 | * @param record 63 | * @param example 64 | */ 65 | int updateByExampleSelective(@Param("record") MsgNotice record, @Param("example") MsgNoticeCriteria example); 66 | 67 | /** 68 | * 选择性更新数据库记录 69 | * 70 | * @param record 71 | * @param example 72 | */ 73 | int updateByExample(@Param("record") MsgNotice record, @Param("example") MsgNoticeCriteria example); 74 | 75 | /** 76 | * 根据主键来更新部分数据库记录 77 | * 78 | * @param record 79 | */ 80 | int updateByPrimaryKeySelective(MsgNotice record); 81 | 82 | /** 83 | * 根据主键来更新数据库记录 84 | * 85 | * @param record 86 | */ 87 | int updateByPrimaryKey(MsgNotice record); 88 | } -------------------------------------------------------------------------------- /msg-service/src/main/java/com/simplemall/micro/serv/msg/service/IMsgService.java: -------------------------------------------------------------------------------- 1 | package com.simplemall.micro.serv.msg.service; 2 | 3 | public interface IMsgService { 4 | 5 | /** 6 | * add a new message 7 | * 8 | * @param serialNo 9 | * @param msgType 10 | * @param target 11 | * @param content 12 | * @return 13 | */ 14 | int addMsg(String serialNo, String msgType, String target, String content); 15 | } 16 | -------------------------------------------------------------------------------- /msg-service/src/main/java/com/simplemall/micro/serv/msg/service/impl/MsgServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.simplemall.micro.serv.msg.service.impl; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.stereotype.Service; 5 | 6 | import com.simplemall.micro.serv.msg.bean.MsgNotice; 7 | import com.simplemall.micro.serv.msg.mapper.MsgNoticeMapper; 8 | import com.simplemall.micro.serv.msg.service.IMsgService; 9 | 10 | @Service 11 | public class MsgServiceImpl implements IMsgService { 12 | 13 | @Autowired 14 | MsgNoticeMapper msgNoticeMapper; 15 | 16 | @Override 17 | public int addMsg(String serialNo, String msgType, String target, String content) { 18 | MsgNotice notice = new MsgNotice(); 19 | notice.setSerialNo(serialNo); 20 | notice.setTargetAddress(target); 21 | notice.setTargetType(msgType); 22 | notice.setContent(content); 23 | int rtn = msgNoticeMapper.insertSelective(notice); 24 | return rtn; 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /msg-service/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | server.port=8084 2 | spring.application.name=msg-service 3 | 4 | eureka.client.serviceUrl.defaultZone=http://localhost:9003/eureka/ 5 | spring.zipkin.base-url=http://localhost:9001 6 | spring.boot.admin.url=http://localhost:9002 7 | 8 | management.security.enabled=false 9 | 10 | #mysql database config 11 | spring.datasource.url=jdbc:mysql://localhost:3306/micro_msg?useUnicode=true&characterEncoding=UTF-8&characterSetResults=UTF-8&zeroDateTimeBehavior=convertToNull 12 | spring.datasource.username=root 13 | spring.datasource.password=root 14 | spring.datasource.driverClassName=com.mysql.jdbc.Driver 15 | spring.datasource.initialSize=1 16 | spring.datasource.minIdle=1 17 | spring.datasource.maxIdle=5 18 | spring.datasource.maxActive=50 19 | spring.datasource.maxWait=10000 20 | spring.datasource.timeBetweenEvictionRunsMillis=10000 21 | spring.datasource.minEvictableIdleTimeMillis=300000 22 | spring.datasource.validationQuery=select 'x' 23 | spring.datasource.testWhileIdle=true 24 | spring.datasource.testOnBorrow=false 25 | spring.datasource.testOnReturn=false 26 | spring.datasource.poolPreparedStatements=true 27 | spring.datasource.maxOpenPreparedStatements=20 28 | spring.datasource.filters=stat 29 | 30 | spring.datasource.mapperLocations=classpath:mapper/*.xml 31 | spring.datasource.typeAliasPackage=com.simplemall.micro.serv.prd.bean 32 | 33 | #pagehelper 34 | pagehelper.helperDialect=mysql 35 | pagehelper.reasonable=false 36 | pagehelper.supportMethodsArguments=true 37 | pagehelper.params=count=countSql -------------------------------------------------------------------------------- /msg-service/src/main/resources/banner.txt: -------------------------------------------------------------------------------- 1 | /$$ /$$ /$$ /$$ 2 | |__/ |__/ | $$ | $$ 3 | /$$$$$$ /$$ /$$ /$$$$$$ /$$$$$$ /$$$$$$ /$$$$$$ /$$$$$$/$$$$ /$$ /$$$$$$$ /$$$$$$ /$$$$$$ /$$$$$$$ /$$$$$$ /$$$$$$ /$$ /$$ /$$ /$$$$$$$ /$$$$$$ /$$$$$$ /$$$$$$ /$$$$$$$ /$$$$$$ 4 | /$$__ $$| $$ | $$ /$$__ $$ /$$__ $$ /$$__ $$ /$$__ $$ | $$_ $$_ $$| $$ /$$_____/ /$$__ $$ /$$__ $$ /$$$$$$ /$$_____/ /$$__ $$ /$$__ $$| $$ /$$/| $$ /$$_____/ /$$__ $$ |_ $$_/ /$$__ $$ /$$_____/|_ $$_/ 5 | | $$ \ $$| $$ | $$| $$ \ $$| $$ \ $$| $$ \ $$| $$ \ $$ | $$ \ $$ \ $$| $$| $$ | $$ \__/| $$ \ $$|______/| $$$$$$ | $$$$$$$$| $$ \__/ \ $$/$$/ | $$| $$ | $$$$$$$$ | $$ | $$$$$$$$| $$$$$$ | $$ 6 | | $$ | $$| $$ | $$| $$ | $$| $$ | $$| $$ | $$| $$ | $$ | $$ | $$ | $$| $$| $$ | $$ | $$ | $$ \____ $$| $$_____/| $$ \ $$$/ | $$| $$ | $$_____/ | $$ /$$| $$_____/ \____ $$ | $$ /$$ 7 | | $$$$$$$| $$$$$$/| $$$$$$/| $$$$$$/| $$$$$$/| $$$$$$/ | $$ | $$ | $$| $$| $$$$$$$| $$ | $$$$$$/ /$$$$$$$/| $$$$$$$| $$ \ $/ | $$| $$$$$$$| $$$$$$$ | $$$$/| $$$$$$$ /$$$$$$$/ | $$$$/ 8 | \____ $$ \______/ \______/ \______/ \______/ \______/ |__/ |__/ |__/|__/ \_______/|__/ \______/ |_______/ \_______/|__/ \_/ |__/ \_______/ \_______/ \___/ \_______/|_______/ \___/ 9 | /$$ \ $$ 10 | | $$$$$$/ 11 | \______/ -------------------------------------------------------------------------------- /msg-service/src/main/resources/bootstrap.properties: -------------------------------------------------------------------------------- 1 | spring.rabbitmq.host=localhost 2 | spring.rabbitmq.port=5672 3 | spring.rabbitmq.username=guest 4 | spring.rabbitmq.password=guest -------------------------------------------------------------------------------- /msg-service/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | ${LOG_HOME}/${LOG_PREFIX}-info.log 14 | 15 | 16 | ${LOG_HOME}/${LOG_PREFIX}-info-%d{yyyyMMdd}.log.%i 17 | 18 | 100MB 19 | 30 20 | 20GB 21 | 22 | 23 | 24 | %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} -%msg%n 25 | 26 | 27 | 28 | 29 | 30 | 31 | ERROR 32 | 33 | ${LOG_HOME}/${LOG_PREFIX}-error.log 34 | 35 | 36 | ${LOG_HOME}/${LOG_PREFIX}-error-%d{yyyyMMdd}.log.%i 37 | 38 | 100MB 39 | 30 40 | 20GB 41 | 42 | 43 | 44 | %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} -%msg%n 45 | 46 | 47 | 48 | 49 | 50 | 51 | %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /order-service/src/main/java/com/simplemall/micro/serv/order/OrderServApplication.java: -------------------------------------------------------------------------------- 1 | package com.simplemall.micro.serv.order; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.netflix.eureka.EnableEurekaClient; 6 | import org.springframework.transaction.annotation.EnableTransactionManagement; 7 | 8 | @EnableEurekaClient 9 | @SpringBootApplication 10 | @EnableTransactionManagement 11 | public class OrderServApplication { 12 | 13 | public static void main(String[] args) { 14 | SpringApplication.run(OrderServApplication.class, args); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /order-service/src/main/java/com/simplemall/micro/serv/order/config/DruidDataSourceConfig.java: -------------------------------------------------------------------------------- 1 | package com.simplemall.micro.serv.order.config; 2 | 3 | import com.alibaba.druid.pool.DruidDataSource; 4 | import org.slf4j.Logger; 5 | import org.slf4j.LoggerFactory; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.boot.context.properties.EnableConfigurationProperties; 8 | import org.springframework.context.annotation.Bean; 9 | import org.springframework.context.annotation.Configuration; 10 | import org.springframework.context.annotation.Primary; 11 | 12 | import javax.sql.DataSource; 13 | import java.sql.SQLException; 14 | 15 | @Configuration 16 | @EnableConfigurationProperties(DataSourceProperties.class) 17 | public class DruidDataSourceConfig { 18 | 19 | private static Logger logger = LoggerFactory.getLogger(DruidDataSourceConfig.class); 20 | 21 | @Autowired 22 | private DataSourceProperties dataSourceProperties; 23 | 24 | @Bean 25 | @Primary 26 | public DataSource druidDataSource(){ 27 | DruidDataSource datasource = new DruidDataSource(); 28 | 29 | datasource.setUrl(dataSourceProperties.getUrl()); 30 | datasource.setUsername(dataSourceProperties.getUsername()); 31 | datasource.setPassword(dataSourceProperties.getPassword()); 32 | datasource.setDriverClassName(dataSourceProperties.getDriverClassName()); 33 | datasource.setInitialSize(dataSourceProperties.getInitialSize()); 34 | datasource.setMinIdle(dataSourceProperties.getMinIdle()); 35 | datasource.setMaxActive(dataSourceProperties.getMaxActive()); 36 | datasource.setMaxWait(dataSourceProperties.getMaxWait()); 37 | datasource.setTimeBetweenEvictionRunsMillis(dataSourceProperties.getTimeBetweenEvictionRunsMillis()); 38 | datasource.setMinEvictableIdleTimeMillis(dataSourceProperties.getMinEvictableIdleTimeMillis()); 39 | datasource.setValidationQuery(dataSourceProperties.getValidationQuery()); 40 | datasource.setTestWhileIdle(dataSourceProperties.isTestWhileIdle()); 41 | datasource.setTestOnBorrow(dataSourceProperties.isTestOnBorrow()); 42 | datasource.setTestOnReturn(dataSourceProperties.isTestOnReturn()); 43 | datasource.setPoolPreparedStatements(dataSourceProperties.isPoolPreparedStatements()); 44 | try { 45 | datasource.setFilters(dataSourceProperties.getFilters()); 46 | } catch (SQLException e) { 47 | logger.error("Druid configuration initialization filter error.", e); 48 | } 49 | return datasource; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /order-service/src/main/java/com/simplemall/micro/serv/order/config/SqlSessionFactoryConfig.java: -------------------------------------------------------------------------------- 1 | package com.simplemall.micro.serv.order.config; 2 | 3 | import javax.sql.DataSource; 4 | 5 | import org.apache.ibatis.session.SqlSessionFactory; 6 | import org.mybatis.spring.SqlSessionFactoryBean; 7 | import org.mybatis.spring.SqlSessionTemplate; 8 | import org.mybatis.spring.annotation.MapperScan; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.context.annotation.Bean; 11 | import org.springframework.context.annotation.Configuration; 12 | import org.springframework.core.io.support.PathMatchingResourcePatternResolver; 13 | import org.springframework.jdbc.datasource.DataSourceTransactionManager; 14 | import org.springframework.transaction.PlatformTransactionManager; 15 | import org.springframework.transaction.annotation.EnableTransactionManagement; 16 | import org.springframework.transaction.annotation.TransactionManagementConfigurer; 17 | 18 | @Configuration 19 | @EnableTransactionManagement 20 | @MapperScan("com.simplemall.micro.serv.order.mapper") 21 | public class SqlSessionFactoryConfig implements TransactionManagementConfigurer { 22 | 23 | @Autowired 24 | private DataSource dataSource; 25 | 26 | @Autowired 27 | private DataSourceProperties dataSourceProperties; 28 | 29 | /** 30 | * 创建sqlSessionFactoryBean 31 | * @return 32 | * @throws Exception 33 | */ 34 | @Bean(name = "sqlSessionFactory") 35 | public SqlSessionFactory createSqlSessionFactoryBean() throws Exception { 36 | SqlSessionFactoryBean bean = new SqlSessionFactoryBean(); 37 | bean.setDataSource(dataSource); 38 | bean.setTypeAliasesPackage(dataSourceProperties.getTypeAliasPackage()); 39 | 40 | PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(); 41 | bean.setMapperLocations(resolver.getResources(dataSourceProperties.getMapperLocations())); 42 | 43 | return bean.getObject(); 44 | } 45 | 46 | @Bean 47 | public SqlSessionTemplate sqlSessionTemplate(SqlSessionFactory sqlSessionFactory) { 48 | return new SqlSessionTemplate(sqlSessionFactory); 49 | } 50 | 51 | @Bean 52 | @Override 53 | public PlatformTransactionManager annotationDrivenTransactionManager() { 54 | return new DataSourceTransactionManager(dataSource); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /order-service/src/main/java/com/simplemall/micro/serv/order/controller/OrderController.java: -------------------------------------------------------------------------------- 1 | package com.simplemall.micro.serv.order.controller; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.web.bind.annotation.RequestMapping; 5 | import org.springframework.web.bind.annotation.RequestMethod; 6 | import org.springframework.web.bind.annotation.RequestParam; 7 | import org.springframework.web.bind.annotation.RestController; 8 | 9 | import com.simplemall.micro.serv.common.bean.order.OrderDTO; 10 | import com.simplemall.micro.serv.common.constant.SystemConstants; 11 | import com.simplemall.micro.serv.order.service.IOrderService; 12 | 13 | /** 14 | * 订单控制类 15 | * 16 | * @author guooo 17 | * 18 | */ 19 | @RestController 20 | @RequestMapping("/order") 21 | public class OrderController { 22 | 23 | @Autowired 24 | IOrderService orderService; 25 | 26 | /** 27 | * 创建 28 | * 29 | * @param orderJsonStr 30 | * @return 31 | */ 32 | @RequestMapping(value = "create", method = {RequestMethod.POST,RequestMethod.GET}) 33 | public String createOrder(String orderJsonStr) { 34 | boolean result = orderService.create(orderJsonStr); 35 | return result ? SystemConstants.Code.SUCCESS : SystemConstants.Code.FAIL; 36 | } 37 | 38 | /** 39 | * 查看订单,确保查看人与订单所有人为同一人 40 | * 41 | * @param serialNo 42 | * @param accountId 43 | */ 44 | @RequestMapping(value = "view", method = RequestMethod.POST) 45 | public OrderDTO viewOrder(@RequestParam(required = true) String serialNo, 46 | @RequestParam(required = true) String accountId,String jwtToken) { 47 | return orderService.view(serialNo, accountId); 48 | } 49 | 50 | /** 51 | * 状态变更,主要供后台人员使用便于前端消费者跟踪订单状况 52 | * 53 | * @param serialNo 54 | * @param state 55 | * @return 56 | */ 57 | @RequestMapping(value = "state/change", method = RequestMethod.POST) 58 | public Boolean changeOrderState(String serialNo, String payStatus,String orderStatus) { 59 | return orderService.changeOrderState(serialNo, payStatus,orderStatus); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /order-service/src/main/java/com/simplemall/micro/serv/order/mapper/OrderInfoMapper.java: -------------------------------------------------------------------------------- 1 | package com.simplemall.micro.serv.order.mapper; 2 | 3 | import java.util.List; 4 | 5 | import org.apache.ibatis.annotations.Param; 6 | 7 | import com.simplemall.micro.serv.common.bean.order.OrderInfo; 8 | import com.simplemall.micro.serv.common.bean.order.OrderInfoCriteria; 9 | 10 | public interface OrderInfoMapper { 11 | /** 12 | * 根据条件计数 13 | * 14 | * @param example 15 | */ 16 | int countByExample(OrderInfoCriteria example); 17 | 18 | /** 19 | * 20 | * @param example 21 | */ 22 | int deleteByExample(OrderInfoCriteria example); 23 | 24 | /** 25 | * 根据主键删除数据库的记录 26 | * 27 | * @param tid 28 | */ 29 | int deleteByPrimaryKey(String tid); 30 | 31 | /** 32 | * 插入数据库记录 33 | * 34 | * @param record 35 | */ 36 | int insert(OrderInfo record); 37 | 38 | /** 39 | * 插入数据库记录 40 | * 41 | * @param record 42 | */ 43 | int insertSelective(OrderInfo record); 44 | 45 | /** 46 | * 根据条件查询列表 47 | * 48 | * @param example 49 | */ 50 | List selectByExample(OrderInfoCriteria example); 51 | 52 | /** 53 | * 根据主键获取一条数据库记录 54 | * 55 | * @param tid 56 | */ 57 | OrderInfo selectByPrimaryKey(String tid); 58 | 59 | /** 60 | * 选择性更新数据库记录 61 | * 62 | * @param record 63 | * @param example 64 | */ 65 | int updateByExampleSelective(@Param("record") OrderInfo record, @Param("example") OrderInfoCriteria example); 66 | 67 | /** 68 | * 选择性更新数据库记录 69 | * 70 | * @param record 71 | * @param example 72 | */ 73 | int updateByExample(@Param("record") OrderInfo record, @Param("example") OrderInfoCriteria example); 74 | 75 | /** 76 | * 根据主键来更新部分数据库记录 77 | * 78 | * @param record 79 | */ 80 | int updateByPrimaryKeySelective(OrderInfo record); 81 | 82 | /** 83 | * 根据主键来更新数据库记录 84 | * 85 | * @param record 86 | */ 87 | int updateByPrimaryKey(OrderInfo record); 88 | } -------------------------------------------------------------------------------- /order-service/src/main/java/com/simplemall/micro/serv/order/mapper/OrderProductMapper.java: -------------------------------------------------------------------------------- 1 | package com.simplemall.micro.serv.order.mapper; 2 | 3 | import java.util.List; 4 | 5 | import org.apache.ibatis.annotations.Param; 6 | 7 | import com.simplemall.micro.serv.common.bean.order.OrderProduct; 8 | import com.simplemall.micro.serv.common.bean.order.OrderProductCriteria; 9 | 10 | public interface OrderProductMapper { 11 | /** 12 | * 根据条件计数 13 | * 14 | * @param example 15 | */ 16 | int countByExample(OrderProductCriteria example); 17 | 18 | /** 19 | * 20 | * @param example 21 | */ 22 | int deleteByExample(OrderProductCriteria example); 23 | 24 | /** 25 | * 根据主键删除数据库的记录 26 | * 27 | * @param tid 28 | */ 29 | int deleteByPrimaryKey(String tid); 30 | 31 | /** 32 | * 插入数据库记录 33 | * 34 | * @param record 35 | */ 36 | int insert(OrderProduct record); 37 | 38 | /** 39 | * 插入数据库记录 40 | * 41 | * @param record 42 | */ 43 | int insertSelective(OrderProduct record); 44 | 45 | /** 46 | * 根据条件查询列表 47 | * 48 | * @param example 49 | */ 50 | List selectByExample(OrderProductCriteria example); 51 | 52 | /** 53 | * 根据主键获取一条数据库记录 54 | * 55 | * @param tid 56 | */ 57 | OrderProduct selectByPrimaryKey(String tid); 58 | 59 | /** 60 | * 选择性更新数据库记录 61 | * 62 | * @param record 63 | * @param example 64 | */ 65 | int updateByExampleSelective(@Param("record") OrderProduct record, @Param("example") OrderProductCriteria example); 66 | 67 | /** 68 | * 选择性更新数据库记录 69 | * 70 | * @param record 71 | * @param example 72 | */ 73 | int updateByExample(@Param("record") OrderProduct record, @Param("example") OrderProductCriteria example); 74 | 75 | /** 76 | * 根据主键来更新部分数据库记录 77 | * 78 | * @param record 79 | */ 80 | int updateByPrimaryKeySelective(OrderProduct record); 81 | 82 | /** 83 | * 根据主键来更新数据库记录 84 | * 85 | * @param record 86 | */ 87 | int updateByPrimaryKey(OrderProduct record); 88 | } -------------------------------------------------------------------------------- /order-service/src/main/java/com/simplemall/micro/serv/order/mapper/OrderStateMapper.java: -------------------------------------------------------------------------------- 1 | package com.simplemall.micro.serv.order.mapper; 2 | 3 | import java.util.List; 4 | 5 | import org.apache.ibatis.annotations.Param; 6 | 7 | import com.simplemall.micro.serv.common.bean.order.OrderState; 8 | import com.simplemall.micro.serv.common.bean.order.OrderStateCriteria; 9 | 10 | public interface OrderStateMapper { 11 | /** 12 | * 根据条件计数 13 | * 14 | * @param example 15 | */ 16 | int countByExample(OrderStateCriteria example); 17 | 18 | /** 19 | * 20 | * @param example 21 | */ 22 | int deleteByExample(OrderStateCriteria example); 23 | 24 | /** 25 | * 根据主键删除数据库的记录 26 | * 27 | * @param tid 28 | */ 29 | int deleteByPrimaryKey(String tid); 30 | 31 | /** 32 | * 插入数据库记录 33 | * 34 | * @param record 35 | */ 36 | int insert(OrderState record); 37 | 38 | /** 39 | * 插入数据库记录 40 | * 41 | * @param record 42 | */ 43 | int insertSelective(OrderState record); 44 | 45 | /** 46 | * 根据条件查询列表 47 | * 48 | * @param example 49 | */ 50 | List selectByExample(OrderStateCriteria example); 51 | 52 | /** 53 | * 根据主键获取一条数据库记录 54 | * 55 | * @param tid 56 | */ 57 | OrderState selectByPrimaryKey(String tid); 58 | 59 | /** 60 | * 选择性更新数据库记录 61 | * 62 | * @param record 63 | * @param example 64 | */ 65 | int updateByExampleSelective(@Param("record") OrderState record, @Param("example") OrderStateCriteria example); 66 | 67 | /** 68 | * 选择性更新数据库记录 69 | * 70 | * @param record 71 | * @param example 72 | */ 73 | int updateByExample(@Param("record") OrderState record, @Param("example") OrderStateCriteria example); 74 | 75 | /** 76 | * 根据主键来更新部分数据库记录 77 | * 78 | * @param record 79 | */ 80 | int updateByPrimaryKeySelective(OrderState record); 81 | 82 | /** 83 | * 根据主键来更新数据库记录 84 | * 85 | * @param record 86 | */ 87 | int updateByPrimaryKey(OrderState record); 88 | } -------------------------------------------------------------------------------- /order-service/src/main/java/com/simplemall/micro/serv/order/service/IOrderService.java: -------------------------------------------------------------------------------- 1 | package com.simplemall.micro.serv.order.service; 2 | 3 | import com.simplemall.micro.serv.common.bean.order.OrderDTO; 4 | 5 | /** 6 | * 订单服务类 7 | * 8 | * @author guooo 9 | * 10 | */ 11 | public interface IOrderService { 12 | 13 | /** 14 | * 创建 15 | * 16 | * @param orderJsonStr 17 | * 订单json串 18 | * @return 19 | */ 20 | boolean create(String orderJsonStr); 21 | 22 | /** 23 | * 查看 24 | * 25 | * @param serialNo 26 | * @param accountId 27 | * @return 28 | */ 29 | OrderDTO view(String serialNo, String accountId); 30 | 31 | /** 32 | * 订单状态变更 33 | * 34 | * @param serialNo 35 | * @param state 36 | * @param orderStatus 37 | * @return 38 | */ 39 | boolean changeOrderState(String serialNo, String state, String orderStatus); 40 | } 41 | -------------------------------------------------------------------------------- /order-service/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | server.port=8083 2 | 3 | spring.application.name=order-service 4 | 5 | eureka.client.serviceUrl.defaultZone=http://localhost:9003/eureka/ 6 | spring.zipkin.base-url=http://localhost:9001 7 | spring.boot.admin.url=http://localhost:9002 8 | 9 | #Error: {"timestamp":1502748955345,"status":401,"error":"Unauthorized","message":"Full authentication is required to access this resource.","path":"/env"} 10 | #Error: {"timestamp":1502748975573,"status":401,"error":"Unauthorized","message":"Full authentication is required to access this resource.","path":"/metrics"} 11 | #resolved up problems 12 | management.security.enabled=false 13 | 14 | 15 | #mysql database config 16 | spring.datasource.url=jdbc:mysql://localhost:3306/micro_order?useUnicode=true&characterEncoding=UTF-8&characterSetResults=UTF-8&zeroDateTimeBehavior=convertToNull 17 | spring.datasource.username=ENC(BnBr3/idF0PH9nd20A9BXw==) 18 | spring.datasource.password=ENC(BnBr3/idF0PH9nd20A9BXw==) 19 | spring.datasource.driverClassName=com.mysql.jdbc.Driver 20 | spring.datasource.initialSize=1 21 | spring.datasource.minIdle=1 22 | spring.datasource.maxIdle=5 23 | spring.datasource.maxActive=50 24 | spring.datasource.maxWait=10000 25 | spring.datasource.timeBetweenEvictionRunsMillis=10000 26 | spring.datasource.minEvictableIdleTimeMillis=300000 27 | spring.datasource.validationQuery=select 'x' 28 | spring.datasource.testWhileIdle=true 29 | spring.datasource.testOnBorrow=false 30 | spring.datasource.testOnReturn=false 31 | spring.datasource.poolPreparedStatements=true 32 | spring.datasource.maxOpenPreparedStatements=20 33 | spring.datasource.filters=stat 34 | 35 | spring.datasource.mapperLocations=classpath:mapper/*.xml 36 | spring.datasource.typeAliasPackage=com.simplemall.micro.serv.order.bean 37 | 38 | #pagehelper 39 | pagehelper.helperDialect=mysql 40 | pagehelper.reasonable=false 41 | pagehelper.supportMethodsArguments=true 42 | pagehelper.params=count=countSql 43 | 44 | jasypt.encryptor.password=EbfYkitulv73I2p0mXI50JMXoaxZTKJ7 -------------------------------------------------------------------------------- /order-service/src/main/resources/bootstrap.properties: -------------------------------------------------------------------------------- 1 | spring.rabbitmq.host=localhost 2 | spring.rabbitmq.port=5672 3 | spring.rabbitmq.username=guest 4 | spring.rabbitmq.password=guest -------------------------------------------------------------------------------- /order-service/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | ${LOG_HOME}/${LOG_PREFIX}-info.log 14 | 15 | 16 | ${LOG_HOME}/${LOG_PREFIX}-info-%d{yyyyMMdd}.log.%i 17 | 18 | 100MB 19 | 30 20 | 20GB 21 | 22 | 23 | 24 | %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} -%msg%n 25 | 26 | 27 | 28 | 29 | 30 | 31 | ERROR 32 | 33 | ${LOG_HOME}/${LOG_PREFIX}-error.log 34 | 35 | 36 | ${LOG_HOME}/${LOG_PREFIX}-error-%d{yyyyMMdd}.log.%i 37 | 38 | 100MB 39 | 30 40 | 20GB 41 | 42 | 43 | 44 | %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} -%msg%n 45 | 46 | 47 | 48 | 49 | 50 | 51 | %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /order-service/src/test/java/com/test/OrderDtoJsonTest.java: -------------------------------------------------------------------------------- 1 | package com.test; 2 | 3 | import java.math.BigDecimal; 4 | import java.util.ArrayList; 5 | import java.util.List; 6 | 7 | import org.junit.Assert; 8 | import org.junit.Test; 9 | import org.junit.runner.RunWith; 10 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 11 | 12 | import com.alibaba.fastjson.JSONObject; 13 | import com.simplemall.micro.serv.common.bean.order.OrderDTO; 14 | import com.simplemall.micro.serv.common.bean.order.OrderInfo; 15 | import com.simplemall.micro.serv.common.bean.order.OrderProduct; 16 | import com.simplemall.micro.serv.common.constant.SystemConstants; 17 | import com.simplemall.micro.serv.common.util.SnowflakeIdWorker; 18 | 19 | 20 | @RunWith(SpringJUnit4ClassRunner.class) 21 | public class OrderDtoJsonTest { 22 | 23 | @Test 24 | public void jsonMain() { 25 | String string = "{baseInfo:{tid:'21312312',serialNo:'vvvvv'},products:[{tid:'111111'},{tid:'22222'}]}"; 26 | JSONObject object = JSONObject.parseObject(string); 27 | OrderDTO dto = JSONObject.toJavaObject(object, OrderDTO.class); 28 | Assert.assertTrue("111111".equals(dto.getProducts().get(0).getTid())); 29 | 30 | } 31 | 32 | @Test 33 | public void test() { 34 | OrderDTO orderDTO = new OrderDTO(); 35 | //base info 36 | OrderInfo info = new OrderInfo(); 37 | info.setSerialNo(String.valueOf(SnowflakeIdWorker.generateSerialNos())); 38 | info.setPayStatus(SystemConstants.PAY_STATUS.UNPAY); 39 | info.setPayType(SystemConstants.PAY_TYPE.ALIPAY); 40 | info.setPostFee(BigDecimal.valueOf(23.45)); 41 | info.setPostWay(SystemConstants.SHIP_WAY.FEDEX); 42 | info.setPrice(BigDecimal.valueOf(3400)); 43 | info.setShippingAccount("Guooo"); 44 | info.setShippingAddress("Tianxin District,ChangSha,China"); 45 | info.setShippingPhone("176737388866"); 46 | orderDTO.setBaseInfo(info); 47 | 48 | //product info 49 | OrderProduct product = new OrderProduct(); 50 | product.setPrdName("一加手机5 (A5000) 8GB+128GB 星辰黑 全网通 双卡双待 移动联通电信4G手机"); 51 | product.setPrdPrice(BigDecimal.valueOf(3400)); 52 | // product.setSerialNo("");在添加工程中,自动添加进去 53 | product.setPrdQty(1); 54 | List products = new ArrayList<>(); 55 | products.add(product); 56 | orderDTO.setProducts(products); 57 | 58 | String jsonObject = JSONObject.toJSONString(orderDTO); 59 | System.out.println(jsonObject); 60 | 61 | Assert.assertTrue(true); 62 | 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /payment-service/src/main/java/com/simplemall/pay/PaymentServApplication.java: -------------------------------------------------------------------------------- 1 | package com.simplemall.pay; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; 6 | 7 | @SpringBootApplication 8 | @EnableDiscoveryClient 9 | public class PaymentServApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(PaymentServApplication.class, args); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /payment-service/src/main/java/com/simplemall/pay/config/DruidDataSourceConfig.java: -------------------------------------------------------------------------------- 1 | package com.simplemall.pay.config; 2 | 3 | import com.alibaba.druid.pool.DruidDataSource; 4 | import org.slf4j.Logger; 5 | import org.slf4j.LoggerFactory; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.boot.context.properties.EnableConfigurationProperties; 8 | import org.springframework.context.annotation.Bean; 9 | import org.springframework.context.annotation.Configuration; 10 | import org.springframework.context.annotation.Primary; 11 | 12 | import javax.sql.DataSource; 13 | import java.sql.SQLException; 14 | 15 | @Configuration 16 | @EnableConfigurationProperties(DataSourceProperties.class) 17 | public class DruidDataSourceConfig { 18 | 19 | private static Logger logger = LoggerFactory.getLogger(DruidDataSourceConfig.class); 20 | 21 | @Autowired 22 | private DataSourceProperties dataSourceProperties; 23 | 24 | @Bean 25 | @Primary 26 | public DataSource druidDataSource(){ 27 | DruidDataSource datasource = new DruidDataSource(); 28 | 29 | datasource.setUrl(dataSourceProperties.getUrl()); 30 | datasource.setUsername(dataSourceProperties.getUsername()); 31 | datasource.setPassword(dataSourceProperties.getPassword()); 32 | datasource.setDriverClassName(dataSourceProperties.getDriverClassName()); 33 | datasource.setInitialSize(dataSourceProperties.getInitialSize()); 34 | datasource.setMinIdle(dataSourceProperties.getMinIdle()); 35 | datasource.setMaxActive(dataSourceProperties.getMaxActive()); 36 | datasource.setMaxWait(dataSourceProperties.getMaxWait()); 37 | datasource.setTimeBetweenEvictionRunsMillis(dataSourceProperties.getTimeBetweenEvictionRunsMillis()); 38 | datasource.setMinEvictableIdleTimeMillis(dataSourceProperties.getMinEvictableIdleTimeMillis()); 39 | datasource.setValidationQuery(dataSourceProperties.getValidationQuery()); 40 | datasource.setTestWhileIdle(dataSourceProperties.isTestWhileIdle()); 41 | datasource.setTestOnBorrow(dataSourceProperties.isTestOnBorrow()); 42 | datasource.setTestOnReturn(dataSourceProperties.isTestOnReturn()); 43 | datasource.setPoolPreparedStatements(dataSourceProperties.isPoolPreparedStatements()); 44 | try { 45 | datasource.setFilters(dataSourceProperties.getFilters()); 46 | } catch (SQLException e) { 47 | logger.error("Druid configuration initialization filter error.", e); 48 | } 49 | return datasource; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /payment-service/src/main/java/com/simplemall/pay/config/SqlSessionFactoryConfig.java: -------------------------------------------------------------------------------- 1 | package com.simplemall.pay.config; 2 | 3 | import javax.sql.DataSource; 4 | 5 | import org.apache.ibatis.session.SqlSessionFactory; 6 | import org.mybatis.spring.SqlSessionFactoryBean; 7 | import org.mybatis.spring.SqlSessionTemplate; 8 | import org.mybatis.spring.annotation.MapperScan; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.context.annotation.Bean; 11 | import org.springframework.context.annotation.Configuration; 12 | import org.springframework.core.io.support.PathMatchingResourcePatternResolver; 13 | import org.springframework.jdbc.datasource.DataSourceTransactionManager; 14 | import org.springframework.transaction.PlatformTransactionManager; 15 | import org.springframework.transaction.annotation.EnableTransactionManagement; 16 | import org.springframework.transaction.annotation.TransactionManagementConfigurer; 17 | 18 | @Configuration 19 | @EnableTransactionManagement 20 | @MapperScan("com.simplemall.pay.dal") 21 | public class SqlSessionFactoryConfig implements TransactionManagementConfigurer { 22 | 23 | @Autowired 24 | private DataSource dataSource; 25 | 26 | @Autowired 27 | private DataSourceProperties dataSourceProperties; 28 | 29 | /** 30 | * 创建sqlSessionFactoryBean 31 | * @return 32 | * @throws Exception 33 | */ 34 | @Bean(name = "sqlSessionFactory") 35 | public SqlSessionFactory createSqlSessionFactoryBean() throws Exception { 36 | SqlSessionFactoryBean bean = new SqlSessionFactoryBean(); 37 | bean.setDataSource(dataSource); 38 | bean.setTypeAliasesPackage(dataSourceProperties.getTypeAliasPackage()); 39 | 40 | PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(); 41 | bean.setMapperLocations(resolver.getResources(dataSourceProperties.getMapperLocations())); 42 | 43 | return bean.getObject(); 44 | } 45 | 46 | @Bean 47 | public SqlSessionTemplate sqlSessionTemplate(SqlSessionFactory sqlSessionFactory) { 48 | return new SqlSessionTemplate(sqlSessionFactory); 49 | } 50 | 51 | @Bean 52 | @Override 53 | public PlatformTransactionManager annotationDrivenTransactionManager() { 54 | return new DataSourceTransactionManager(dataSource); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /payment-service/src/main/java/com/simplemall/pay/controller/PayController.java: -------------------------------------------------------------------------------- 1 | package com.simplemall.pay.controller; 2 | 3 | import java.math.BigDecimal; 4 | 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.web.bind.annotation.RequestMapping; 7 | import org.springframework.web.bind.annotation.RequestMethod; 8 | import org.springframework.web.bind.annotation.RequestParam; 9 | import org.springframework.web.bind.annotation.RestController; 10 | 11 | import com.simplemall.pay.service.IPayService; 12 | 13 | @RestController 14 | @RequestMapping("/payment") 15 | public class PayController { 16 | 17 | @Autowired 18 | IPayService payService; 19 | 20 | /** 21 | * pay 22 | * 23 | * @param serialNo 24 | * @param payType 25 | * @return 26 | */ 27 | @RequestMapping(value = "pay", method = RequestMethod.POST) 28 | public Integer pay(@RequestParam(value = "serialNo") String serialNo, @RequestParam(value = "payType") String payType, 29 | @RequestParam(value = "price") BigDecimal price,String jwtToken) { 30 | int result = payService.pay(serialNo, payType, price); 31 | return result; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /payment-service/src/main/java/com/simplemall/pay/dal/PayRecordMapper.java: -------------------------------------------------------------------------------- 1 | package com.simplemall.pay.dal; 2 | 3 | import java.util.List; 4 | 5 | import org.apache.ibatis.annotations.Param; 6 | 7 | import com.simplemall.pay.bean.PayRecord; 8 | import com.simplemall.pay.bean.PayRecordCriteria; 9 | 10 | public interface PayRecordMapper { 11 | /** 12 | * 根据条件计数 13 | * 14 | * @param example 15 | */ 16 | int countByExample(PayRecordCriteria example); 17 | 18 | /** 19 | * 20 | * @param example 21 | */ 22 | int deleteByExample(PayRecordCriteria example); 23 | 24 | /** 25 | * 根据主键删除数据库的记录 26 | * 27 | * @param tid 28 | */ 29 | int deleteByPrimaryKey(String tid); 30 | 31 | /** 32 | * 插入数据库记录 33 | * 34 | * @param record 35 | */ 36 | int insert(PayRecord record); 37 | 38 | /** 39 | * 插入数据库记录 40 | * 41 | * @param record 42 | */ 43 | int insertSelective(PayRecord record); 44 | 45 | /** 46 | * 根据条件查询列表 47 | * 48 | * @param example 49 | */ 50 | List selectByExample(PayRecordCriteria example); 51 | 52 | /** 53 | * 根据主键获取一条数据库记录 54 | * 55 | * @param tid 56 | */ 57 | PayRecord selectByPrimaryKey(String tid); 58 | 59 | /** 60 | * 选择性更新数据库记录 61 | * 62 | * @param record 63 | * @param example 64 | */ 65 | int updateByExampleSelective(@Param("record") PayRecord record, @Param("example") PayRecordCriteria example); 66 | 67 | /** 68 | * 选择性更新数据库记录 69 | * 70 | * @param record 71 | * @param example 72 | */ 73 | int updateByExample(@Param("record") PayRecord record, @Param("example") PayRecordCriteria example); 74 | 75 | /** 76 | * 根据主键来更新部分数据库记录 77 | * 78 | * @param record 79 | */ 80 | int updateByPrimaryKeySelective(PayRecord record); 81 | 82 | /** 83 | * 根据主键来更新数据库记录 84 | * 85 | * @param record 86 | */ 87 | int updateByPrimaryKey(PayRecord record); 88 | } -------------------------------------------------------------------------------- /payment-service/src/main/java/com/simplemall/pay/service/IPayService.java: -------------------------------------------------------------------------------- 1 | package com.simplemall.pay.service; 2 | 3 | import java.math.BigDecimal; 4 | 5 | public interface IPayService { 6 | 7 | /** 8 | * @param serialNo 9 | * @param payType 10 | * @param price 11 | * @return 12 | */ 13 | int pay(String serialNo,String payType,BigDecimal price); 14 | } 15 | -------------------------------------------------------------------------------- /payment-service/src/main/java/com/simplemall/pay/service/impl/PayServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.simplemall.pay.service.impl; 2 | 3 | import java.math.BigDecimal; 4 | 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.stereotype.Service; 7 | 8 | import com.simplemall.micro.serv.common.constant.SystemConstants; 9 | import com.simplemall.pay.bean.PayRecord; 10 | import com.simplemall.pay.dal.PayRecordMapper; 11 | import com.simplemall.pay.service.IPayService; 12 | 13 | @Service 14 | public class PayServiceImpl implements IPayService { 15 | 16 | @Autowired 17 | PayRecordMapper recordMapper; 18 | 19 | @Override 20 | public int pay(String serialNo, String payType,BigDecimal price) { 21 | PayRecord record = new PayRecord(); 22 | record.setPrice(Float.valueOf(String.valueOf(price))); 23 | record.setSerialNo(serialNo); 24 | record.setType(payType); 25 | record.setStatus(SystemConstants.PAY_STATUS.PAID); 26 | return recordMapper.insertSelective(record); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /payment-service/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | server.port=8082 2 | logging.level.tk.mybatis=TRACE 3 | spring.application.name=payment-service 4 | eureka.client.serviceUrl.defaultZone=http://localhost:9003/eureka/ 5 | spring.zipkin.base-url=http://localhost:9001 6 | spring.boot.admin.url=http://localhost:9002 7 | 8 | #Error: {"timestamp":1502748955345,"status":401,"error":"Unauthorized","message":"Full authentication is required to access this resource.","path":"/env"} 9 | #Error: {"timestamp":1502748975573,"status":401,"error":"Unauthorized","message":"Full authentication is required to access this resource.","path":"/metrics"} 10 | #resolved up problems 11 | management.security.enabled=false 12 | 13 | #mysql database config 14 | spring.datasource.url=jdbc:mysql://localhost:3306/micro_payment?useUnicode=true&characterEncoding=UTF-8&characterSetResults=UTF-8&zeroDateTimeBehavior=convertToNull 15 | spring.datasource.username=ENC(BnBr3/idF0PH9nd20A9BXw==) 16 | spring.datasource.password=ENC(BnBr3/idF0PH9nd20A9BXw==) 17 | spring.datasource.driverClassName=com.mysql.jdbc.Driver 18 | spring.datasource.initialSize=1 19 | spring.datasource.minIdle=1 20 | spring.datasource.maxIdle=5 21 | spring.datasource.maxActive=50 22 | spring.datasource.maxWait=10000 23 | spring.datasource.timeBetweenEvictionRunsMillis=10000 24 | spring.datasource.minEvictableIdleTimeMillis=300000 25 | spring.datasource.validationQuery=select 'x' 26 | spring.datasource.testWhileIdle=true 27 | spring.datasource.testOnBorrow=false 28 | spring.datasource.testOnReturn=false 29 | spring.datasource.poolPreparedStatements=true 30 | spring.datasource.maxOpenPreparedStatements=20 31 | spring.datasource.filters=stat 32 | 33 | spring.datasource.mapperLocations=classpath:mapper/*.xml 34 | spring.datasource.typeAliasPackage=com.simplemall.pay.bean 35 | 36 | jasypt.encryptor.password=EbfYkitulv73I2p0mXI50JMXoaxZTKJ7 37 | 38 | #pagehelper 39 | pagehelper.helperDialect=mysql 40 | pagehelper.reasonable=false 41 | pagehelper.supportMethodsArguments=true 42 | pagehelper.params=count=countSql -------------------------------------------------------------------------------- /payment-service/src/main/resources/bootstrap.properties: -------------------------------------------------------------------------------- 1 | spring.rabbitmq.host=localhost 2 | spring.rabbitmq.port=5672 3 | spring.rabbitmq.username=guest 4 | spring.rabbitmq.password=guest -------------------------------------------------------------------------------- /payment-service/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | ${LOG_HOME}/${LOG_PREFIX}-info.log 14 | 15 | 16 | ${LOG_HOME}/${LOG_PREFIX}-info-%d{yyyyMMdd}.log.%i 17 | 18 | 100MB 19 | 30 20 | 20GB 21 | 22 | 23 | 24 | %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} -%msg%n 25 | 26 | 27 | 28 | 29 | 30 | 31 | ERROR 32 | 33 | ${LOG_HOME}/${LOG_PREFIX}-error.log 34 | 35 | 36 | ${LOG_HOME}/${LOG_PREFIX}-error-%d{yyyyMMdd}.log.%i 37 | 38 | 100MB 39 | 30 40 | 20GB 41 | 42 | 43 | 44 | %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} -%msg%n 45 | 46 | 47 | 48 | 49 | 50 | 51 | %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /payment-service/src/test/resources/generatorConfig.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 8 | 9 | 10 | 11 | 12 | 13 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 25 | 26 | 27 | 29 | 30 | 31 | 32 | 33 | 34 | 36 | 37 | 38 | 39 | 40 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 |
50 | 51 |
52 |
-------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | com.simplemall.micro.serv 5 | simplemall-proj 6 | 0.0.1-SNAPSHOT 7 | pom 8 | 9 | 10 | org.springframework.boot 11 | spring-boot-starter-parent 12 | 1.5.2.RELEASE 13 | 14 | 15 | 16 | base-serv 17 | account-sevice 18 | product-service 19 | order-service 20 | payment-service 21 | msg-service 22 | front-app 23 | common-module 24 | 25 | 26 | update pom next time 36 | 37 | -------------------------------------------------------------------------------- /product-service/src/main/java/com/simplemall/micro/serv/prd/ProductServApplication.java: -------------------------------------------------------------------------------- 1 | package com.simplemall.micro.serv.prd; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.netflix.eureka.EnableEurekaClient; 6 | 7 | @EnableEurekaClient 8 | @SpringBootApplication 9 | public class ProductServApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(ProductServApplication.class, args); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /product-service/src/main/java/com/simplemall/micro/serv/prd/config/DruidDataSourceConfig.java: -------------------------------------------------------------------------------- 1 | package com.simplemall.micro.serv.prd.config; 2 | 3 | import com.alibaba.druid.pool.DruidDataSource; 4 | import org.slf4j.Logger; 5 | import org.slf4j.LoggerFactory; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.boot.context.properties.EnableConfigurationProperties; 8 | import org.springframework.context.annotation.Bean; 9 | import org.springframework.context.annotation.Configuration; 10 | import org.springframework.context.annotation.Primary; 11 | 12 | import javax.sql.DataSource; 13 | import java.sql.SQLException; 14 | 15 | @Configuration 16 | @EnableConfigurationProperties(DataSourceProperties.class) 17 | public class DruidDataSourceConfig { 18 | 19 | private static Logger logger = LoggerFactory.getLogger(DruidDataSourceConfig.class); 20 | 21 | @Autowired 22 | private DataSourceProperties dataSourceProperties; 23 | 24 | @Bean 25 | @Primary 26 | public DataSource druidDataSource(){ 27 | DruidDataSource datasource = new DruidDataSource(); 28 | 29 | datasource.setUrl(dataSourceProperties.getUrl()); 30 | datasource.setUsername(dataSourceProperties.getUsername()); 31 | datasource.setPassword(dataSourceProperties.getPassword()); 32 | datasource.setDriverClassName(dataSourceProperties.getDriverClassName()); 33 | datasource.setInitialSize(dataSourceProperties.getInitialSize()); 34 | datasource.setMinIdle(dataSourceProperties.getMinIdle()); 35 | datasource.setMaxActive(dataSourceProperties.getMaxActive()); 36 | datasource.setMaxWait(dataSourceProperties.getMaxWait()); 37 | datasource.setTimeBetweenEvictionRunsMillis(dataSourceProperties.getTimeBetweenEvictionRunsMillis()); 38 | datasource.setMinEvictableIdleTimeMillis(dataSourceProperties.getMinEvictableIdleTimeMillis()); 39 | datasource.setValidationQuery(dataSourceProperties.getValidationQuery()); 40 | datasource.setTestWhileIdle(dataSourceProperties.isTestWhileIdle()); 41 | datasource.setTestOnBorrow(dataSourceProperties.isTestOnBorrow()); 42 | datasource.setTestOnReturn(dataSourceProperties.isTestOnReturn()); 43 | datasource.setPoolPreparedStatements(dataSourceProperties.isPoolPreparedStatements()); 44 | try { 45 | datasource.setFilters(dataSourceProperties.getFilters()); 46 | } catch (SQLException e) { 47 | logger.error("Druid configuration initialization filter error.", e); 48 | } 49 | return datasource; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /product-service/src/main/java/com/simplemall/micro/serv/prd/config/SqlSessionFactoryConfig.java: -------------------------------------------------------------------------------- 1 | package com.simplemall.micro.serv.prd.config; 2 | 3 | import javax.sql.DataSource; 4 | 5 | import org.apache.ibatis.session.SqlSessionFactory; 6 | import org.mybatis.spring.SqlSessionFactoryBean; 7 | import org.mybatis.spring.SqlSessionTemplate; 8 | import org.mybatis.spring.annotation.MapperScan; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.context.annotation.Bean; 11 | import org.springframework.context.annotation.Configuration; 12 | import org.springframework.core.io.support.PathMatchingResourcePatternResolver; 13 | import org.springframework.jdbc.datasource.DataSourceTransactionManager; 14 | import org.springframework.transaction.PlatformTransactionManager; 15 | import org.springframework.transaction.annotation.EnableTransactionManagement; 16 | import org.springframework.transaction.annotation.TransactionManagementConfigurer; 17 | 18 | @Configuration 19 | @EnableTransactionManagement 20 | @MapperScan("com.simplemall.micro.serv.prd.mapper") 21 | public class SqlSessionFactoryConfig implements TransactionManagementConfigurer { 22 | 23 | @Autowired 24 | private DataSource dataSource; 25 | 26 | @Autowired 27 | private DataSourceProperties dataSourceProperties; 28 | 29 | /** 30 | * 创建sqlSessionFactoryBean 31 | * @return 32 | * @throws Exception 33 | */ 34 | @Bean(name = "sqlSessionFactory") 35 | public SqlSessionFactory createSqlSessionFactoryBean() throws Exception { 36 | SqlSessionFactoryBean bean = new SqlSessionFactoryBean(); 37 | bean.setDataSource(dataSource); 38 | bean.setTypeAliasesPackage(dataSourceProperties.getTypeAliasPackage()); 39 | 40 | PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(); 41 | bean.setMapperLocations(resolver.getResources(dataSourceProperties.getMapperLocations())); 42 | 43 | return bean.getObject(); 44 | } 45 | 46 | @Bean 47 | public SqlSessionTemplate sqlSessionTemplate(SqlSessionFactory sqlSessionFactory) { 48 | return new SqlSessionTemplate(sqlSessionFactory); 49 | } 50 | 51 | @Bean 52 | @Override 53 | public PlatformTransactionManager annotationDrivenTransactionManager() { 54 | return new DataSourceTransactionManager(dataSource); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /product-service/src/main/java/com/simplemall/micro/serv/prd/controller/PorudctController.java: -------------------------------------------------------------------------------- 1 | package com.simplemall.micro.serv.prd.controller; 2 | 3 | import java.util.List; 4 | 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.web.bind.annotation.RequestMapping; 7 | import org.springframework.web.bind.annotation.RequestMethod; 8 | import org.springframework.web.bind.annotation.RestController; 9 | 10 | import com.simplemall.micro.serv.common.bean.product.PrdInfo; 11 | import com.simplemall.micro.serv.prd.service.IPrdService; 12 | 13 | @RestController 14 | @RequestMapping("/prd") 15 | public class PorudctController { 16 | 17 | @Autowired 18 | IPrdService prdService; 19 | 20 | /** 21 | * get a product info 22 | * 23 | * @param prdId 24 | * @return 25 | */ 26 | @RequestMapping(value = "{prdId}", method = RequestMethod.POST) 27 | public PrdInfo getPorudctById(String prdId) { 28 | return prdService.getProductById(prdId); 29 | } 30 | 31 | /** 32 | * 获取商品列表 33 | * 34 | * @return 35 | */ 36 | @RequestMapping(value = "list", method = RequestMethod.POST) 37 | public List list() { 38 | return prdService.queryPrdList(); 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /product-service/src/main/java/com/simplemall/micro/serv/prd/mapper/PrdExtendMapper.java: -------------------------------------------------------------------------------- 1 | package com.simplemall.micro.serv.prd.mapper; 2 | 3 | import java.util.List; 4 | 5 | import org.apache.ibatis.annotations.Param; 6 | 7 | import com.simplemall.micro.serv.common.bean.product.PrdExtend; 8 | import com.simplemall.micro.serv.common.bean.product.PrdExtendCriteria; 9 | 10 | public interface PrdExtendMapper { 11 | /** 12 | * 根据条件计数 13 | * 14 | * @param example 15 | */ 16 | int countByExample(PrdExtendCriteria example); 17 | 18 | /** 19 | * 20 | * @param example 21 | */ 22 | int deleteByExample(PrdExtendCriteria example); 23 | 24 | /** 25 | * 根据主键删除数据库的记录 26 | * 27 | * @param tid 28 | */ 29 | int deleteByPrimaryKey(String tid); 30 | 31 | /** 32 | * 插入数据库记录 33 | * 34 | * @param record 35 | */ 36 | int insert(PrdExtend record); 37 | 38 | /** 39 | * 插入数据库记录 40 | * 41 | * @param record 42 | */ 43 | int insertSelective(PrdExtend record); 44 | 45 | /** 46 | * 根据条件查询列表 47 | * 48 | * @param example 49 | */ 50 | List selectByExample(PrdExtendCriteria example); 51 | 52 | /** 53 | * 根据主键获取一条数据库记录 54 | * 55 | * @param tid 56 | */ 57 | PrdExtend selectByPrimaryKey(String tid); 58 | 59 | /** 60 | * 选择性更新数据库记录 61 | * 62 | * @param record 63 | * @param example 64 | */ 65 | int updateByExampleSelective(@Param("record") PrdExtend record, @Param("example") PrdExtendCriteria example); 66 | 67 | /** 68 | * 选择性更新数据库记录 69 | * 70 | * @param record 71 | * @param example 72 | */ 73 | int updateByExample(@Param("record") PrdExtend record, @Param("example") PrdExtendCriteria example); 74 | 75 | /** 76 | * 根据主键来更新部分数据库记录 77 | * 78 | * @param record 79 | */ 80 | int updateByPrimaryKeySelective(PrdExtend record); 81 | 82 | /** 83 | * 根据主键来更新数据库记录 84 | * 85 | * @param record 86 | */ 87 | int updateByPrimaryKey(PrdExtend record); 88 | } -------------------------------------------------------------------------------- /product-service/src/main/java/com/simplemall/micro/serv/prd/mapper/PrdInfoMapper.java: -------------------------------------------------------------------------------- 1 | package com.simplemall.micro.serv.prd.mapper; 2 | 3 | import java.util.List; 4 | 5 | import org.apache.ibatis.annotations.Param; 6 | 7 | import com.simplemall.micro.serv.common.bean.product.PrdInfo; 8 | import com.simplemall.micro.serv.common.bean.product.PrdInfoCriteria; 9 | 10 | public interface PrdInfoMapper { 11 | /** 12 | * 根据条件计数 13 | * 14 | * @param example 15 | */ 16 | int countByExample(PrdInfoCriteria example); 17 | 18 | /** 19 | * 20 | * @param example 21 | */ 22 | int deleteByExample(PrdInfoCriteria example); 23 | 24 | /** 25 | * 根据主键删除数据库的记录 26 | * 27 | * @param tid 28 | */ 29 | int deleteByPrimaryKey(String tid); 30 | 31 | /** 32 | * 插入数据库记录 33 | * 34 | * @param record 35 | */ 36 | int insert(PrdInfo record); 37 | 38 | /** 39 | * 插入数据库记录 40 | * 41 | * @param record 42 | */ 43 | int insertSelective(PrdInfo record); 44 | 45 | /** 46 | * 根据条件查询列表 47 | * 48 | * @param example 49 | */ 50 | List selectByExample(PrdInfoCriteria example); 51 | 52 | /** 53 | * 根据主键获取一条数据库记录 54 | * 55 | * @param tid 56 | */ 57 | PrdInfo selectByPrimaryKey(String tid); 58 | 59 | /** 60 | * 选择性更新数据库记录 61 | * 62 | * @param record 63 | * @param example 64 | */ 65 | int updateByExampleSelective(@Param("record") PrdInfo record, @Param("example") PrdInfoCriteria example); 66 | 67 | /** 68 | * 选择性更新数据库记录 69 | * 70 | * @param record 71 | * @param example 72 | */ 73 | int updateByExample(@Param("record") PrdInfo record, @Param("example") PrdInfoCriteria example); 74 | 75 | /** 76 | * 根据主键来更新部分数据库记录 77 | * 78 | * @param record 79 | */ 80 | int updateByPrimaryKeySelective(PrdInfo record); 81 | 82 | /** 83 | * 根据主键来更新数据库记录 84 | * 85 | * @param record 86 | */ 87 | int updateByPrimaryKey(PrdInfo record); 88 | } -------------------------------------------------------------------------------- /product-service/src/main/java/com/simplemall/micro/serv/prd/service/IPrdService.java: -------------------------------------------------------------------------------- 1 | package com.simplemall.micro.serv.prd.service; 2 | 3 | import java.util.List; 4 | 5 | import com.simplemall.micro.serv.common.bean.product.PrdInfo; 6 | 7 | public interface IPrdService { 8 | 9 | /** 10 | * 商品详情 11 | * 12 | * @param prdId 13 | * @return 14 | */ 15 | PrdInfo getProductById(String prdId); 16 | 17 | /** 18 | * 获取商品列表 19 | * 20 | * @return 21 | */ 22 | List queryPrdList(); 23 | } 24 | -------------------------------------------------------------------------------- /product-service/src/main/java/com/simplemall/micro/serv/prd/service/impl/PrdServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.simplemall.micro.serv.prd.service.impl; 2 | 3 | import java.util.List; 4 | 5 | import org.slf4j.Logger; 6 | import org.slf4j.LoggerFactory; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.stereotype.Service; 9 | 10 | import com.simplemall.micro.serv.common.bean.product.PrdInfo; 11 | import com.simplemall.micro.serv.common.bean.product.PrdInfoCriteria; 12 | import com.simplemall.micro.serv.prd.mapper.PrdInfoMapper; 13 | import com.simplemall.micro.serv.prd.service.IPrdService; 14 | 15 | @Service 16 | public class PrdServiceImpl implements IPrdService { 17 | private Logger logger = LoggerFactory.getLogger(PrdServiceImpl.class); 18 | 19 | 20 | @Autowired 21 | PrdInfoMapper prdInfoMapper; 22 | 23 | @Override 24 | public PrdInfo getProductById(String prdId) { 25 | PrdInfo info = prdInfoMapper.selectByPrimaryKey(prdId); 26 | logger.info("获取商品详情{}成功!",prdId); 27 | return info; 28 | } 29 | 30 | @Override 31 | public List queryPrdList() { 32 | return prdInfoMapper.selectByExample(new PrdInfoCriteria()); 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /product-service/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | server.port=8081 2 | logging.level.tk.mybatis=TRACE 3 | spring.application.name=product-service 4 | 5 | eureka.client.serviceUrl.defaultZone=http://localhost:9003/eureka/ 6 | spring.zipkin.base-url=http://localhost:9001 7 | spring.boot.admin.url=http://localhost:9002 8 | 9 | #Error: {"timestamp":1502748955345,"status":401,"error":"Unauthorized","message":"Full authentication is required to access this resource.","path":"/env"} 10 | #Error: {"timestamp":1502748975573,"status":401,"error":"Unauthorized","message":"Full authentication is required to access this resource.","path":"/metrics"} 11 | #resolved up problems 12 | management.security.enabled=false 13 | 14 | #mysql database config 15 | spring.datasource.url=jdbc:mysql://localhost:3306/micro_product?useUnicode=true&characterEncoding=UTF-8&characterSetResults=UTF-8&zeroDateTimeBehavior=convertToNull 16 | spring.datasource.username=root 17 | spring.datasource.password=root 18 | spring.datasource.driverClassName=com.mysql.jdbc.Driver 19 | spring.datasource.initialSize=1 20 | spring.datasource.minIdle=1 21 | spring.datasource.maxIdle=5 22 | spring.datasource.maxActive=50 23 | spring.datasource.maxWait=10000 24 | spring.datasource.timeBetweenEvictionRunsMillis=10000 25 | spring.datasource.minEvictableIdleTimeMillis=300000 26 | spring.datasource.validationQuery=select 'x' 27 | spring.datasource.testWhileIdle=true 28 | spring.datasource.testOnBorrow=false 29 | spring.datasource.testOnReturn=false 30 | spring.datasource.poolPreparedStatements=true 31 | spring.datasource.maxOpenPreparedStatements=20 32 | spring.datasource.filters=stat 33 | 34 | spring.datasource.mapperLocations=classpath:mapper/*.xml 35 | spring.datasource.typeAliasPackage=com.simplemall.micro.serv.prd.bean 36 | 37 | #pagehelper 38 | pagehelper.helperDialect=mysql 39 | pagehelper.reasonable=false 40 | pagehelper.supportMethodsArguments=true 41 | pagehelper.params=count=countSql -------------------------------------------------------------------------------- /product-service/src/main/resources/bootstrap.properties: -------------------------------------------------------------------------------- 1 | spring.rabbitmq.host=localhost 2 | spring.rabbitmq.port=5672 3 | spring.rabbitmq.username=guest 4 | spring.rabbitmq.password=guest -------------------------------------------------------------------------------- /product-service/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | ${LOG_HOME}/${LOG_PREFIX}-info.log 14 | 15 | 16 | ${LOG_HOME}/${LOG_PREFIX}-info-%d{yyyyMMdd}.log.%i 17 | 18 | 100MB 19 | 30 20 | 20GB 21 | 22 | 23 | 24 | %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} -%msg%n 25 | 26 | 27 | 28 | 29 | 30 | 31 | ERROR 32 | 33 | ${LOG_HOME}/${LOG_PREFIX}-error.log 34 | 35 | 36 | ${LOG_HOME}/${LOG_PREFIX}-error-%d{yyyyMMdd}.log.%i 37 | 38 | 100MB 39 | 30 40 | 20GB 41 | 42 | 43 | 44 | %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} -%msg%n 45 | 46 | 47 | 48 | 49 | 50 | 51 | %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /product-service/src/test/resources/generatorConfig.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 8 | 9 | 10 | 11 | 12 | 13 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 25 | 26 | 27 | 29 | 30 | 31 | 32 | 33 | 34 | 36 | 37 | 38 | 39 | 40 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 |
50 | 51 | 52 | 53 |
54 |
55 |
-------------------------------------------------------------------------------- /shopping flow.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maventalker/simplemall/12c5070c4dc0abbae4d78d723c5e51cb43442dd6/shopping flow.jpg -------------------------------------------------------------------------------- /sql/micro_msg.sql: -------------------------------------------------------------------------------- 1 | /* 2 | SQLyog Ultimate v11.24 (32 bit) 3 | MySQL - 5.7.13 : Database - micro_msg 4 | ********************************************************************* 5 | */ 6 | 7 | /*!40101 SET NAMES utf8 */; 8 | 9 | /*!40101 SET SQL_MODE=''*/; 10 | 11 | /*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; 12 | /*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; 13 | /*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; 14 | /*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; 15 | CREATE DATABASE /*!32312 IF NOT EXISTS*/`micro_msg` /*!40100 DEFAULT CHARACTER SET utf8 */; 16 | 17 | USE `micro_msg`; 18 | 19 | /*Table structure for table `tb_msg_notice` */ 20 | 21 | DROP TABLE IF EXISTS `tb_msg_notice`; 22 | 23 | CREATE TABLE `tb_msg_notice` ( 24 | `tid` varchar(32) NOT NULL, 25 | `serial_no` varchar(16) DEFAULT NULL COMMENT '流水号', 26 | `target_type` char(5) DEFAULT NULL COMMENT '目标类型SMS|EMAIL', 27 | `target_address` varchar(50) DEFAULT NULL COMMENT '目标地址', 28 | `content` varchar(30) DEFAULT NULL COMMENT '消息详情', 29 | `create_date` datetime DEFAULT CURRENT_TIMESTAMP, 30 | `update_by` varchar(32) DEFAULT NULL, 31 | `update_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, 32 | `remark` varchar(1000) DEFAULT NULL, 33 | `version` int(2) DEFAULT '0', 34 | `state` int(2) DEFAULT '1', 35 | PRIMARY KEY (`tid`) 36 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='消息通知,短信/邮件'; 37 | 38 | /*Data for the table `tb_msg_notice` */ 39 | 40 | LOCK TABLES `tb_msg_notice` WRITE; 41 | 42 | UNLOCK TABLES; 43 | 44 | /*!40101 SET SQL_MODE=@OLD_SQL_MODE */; 45 | /*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; 46 | /*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; 47 | /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; 48 | -------------------------------------------------------------------------------- /sql/micro_payment.sql: -------------------------------------------------------------------------------- 1 | /* 2 | SQLyog Ultimate v11.24 (32 bit) 3 | MySQL - 5.7.13 : Database - micro_payment 4 | ********************************************************************* 5 | */ 6 | 7 | 8 | /*!40101 SET NAMES utf8 */; 9 | 10 | /*!40101 SET SQL_MODE=''*/; 11 | 12 | /*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; 13 | /*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; 14 | /*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; 15 | /*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; 16 | CREATE DATABASE /*!32312 IF NOT EXISTS*/`micro_payment` /*!40100 DEFAULT CHARACTER SET utf8 */; 17 | 18 | USE `micro_payment`; 19 | 20 | /*Table structure for table `tb_pay_record` */ 21 | 22 | DROP TABLE IF EXISTS `tb_pay_record`; 23 | 24 | CREATE TABLE `tb_pay_record` ( 25 | `tid` varchar(32) NOT NULL, 26 | `serial_no` varchar(32) DEFAULT NULL COMMENT '流水号', 27 | `type` char(10) DEFAULT NULL COMMENT '支付方式,Alipay|Wechat|Card', 28 | `status` varchar(30) DEFAULT NULL COMMENT '支付状态', 29 | `create_date` datetime DEFAULT CURRENT_TIMESTAMP, 30 | `update_by` varchar(32) DEFAULT NULL, 31 | `update_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, 32 | `remark` varchar(1000) DEFAULT NULL, 33 | `version` int(2) DEFAULT '0', 34 | `state` int(2) DEFAULT '1', 35 | PRIMARY KEY (`tid`) 36 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='交易支付记录'; 37 | 38 | /*Data for the table `tb_pay_record` */ 39 | 40 | LOCK TABLES `tb_pay_record` WRITE; 41 | 42 | UNLOCK TABLES; 43 | 44 | /*!40101 SET SQL_MODE=@OLD_SQL_MODE */; 45 | /*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; 46 | /*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; 47 | /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; 48 | --------------------------------------------------------------------------------