├── .idea ├── compiler.xml ├── encodings.xml ├── inspectionProfiles │ └── Project_Default.xml ├── misc.xml ├── modules.xml ├── uiDesigner.xml └── vcs.xml ├── LICENSE ├── README.md ├── leyou-api-gateway ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── leyou │ │ ├── LyApiGateway.java │ │ ├── config │ │ ├── FilterProperties.java │ │ ├── GlobalCorsConfig.java │ │ └── JwtProperties.java │ │ └── filter │ │ └── LoginFilter.java │ └── resources │ └── bootstrap.yml ├── leyou-authentication ├── leyou-authentication-common │ ├── pom.xml │ └── src │ │ ├── main │ │ └── java │ │ │ └── com │ │ │ └── leyou │ │ │ └── auth │ │ │ ├── entity │ │ │ └── UserInfo.java │ │ │ └── utils │ │ │ ├── JwtConstans.java │ │ │ ├── JwtUtils.java │ │ │ ├── ObjectUtils.java │ │ │ └── RsaUtils.java │ │ └── test │ │ └── java │ │ └── com │ │ └── leyou │ │ └── auth │ │ └── test │ │ └── JwtTest.java ├── leyou-authentication-service │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── com │ │ │ │ └── leyou │ │ │ │ └── auth │ │ │ │ ├── LyAuthApplication.java │ │ │ │ ├── client │ │ │ │ └── UserClient.java │ │ │ │ ├── controller │ │ │ │ └── AuthController.java │ │ │ │ ├── properties │ │ │ │ └── JwtProperties.java │ │ │ │ └── service │ │ │ │ ├── AuthService.java │ │ │ │ └── impl │ │ │ │ └── AuthServiceImpl.java │ │ └── resources │ │ │ └── bootstrap.yml │ │ └── test │ │ └── java │ │ └── TokenTest.java └── pom.xml ├── leyou-cart ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── leyou │ │ │ └── cart │ │ │ ├── LyCartApplication.java │ │ │ ├── client │ │ │ └── GoodsClient.java │ │ │ ├── config │ │ │ └── MvcConfig.java │ │ │ ├── controller │ │ │ └── CartController.java │ │ │ ├── filter │ │ │ └── CartFilter.java │ │ │ ├── interceptor │ │ │ └── LoginInterceptor.java │ │ │ ├── pojo │ │ │ └── Cart.java │ │ │ ├── properties │ │ │ └── JwtProperties.java │ │ │ └── service │ │ │ ├── CartService.java │ │ │ └── impl │ │ │ └── CartServiceImpl.java │ └── resources │ │ └── bootstrap.yml │ └── test │ └── java │ └── com │ └── leyou │ └── redis │ └── RedisTest.java ├── leyou-comments ├── leyou-comments-interface │ ├── pom.xml │ └── src │ │ └── main │ │ └── java │ │ └── com │ │ └── leyou │ │ └── comments │ │ └── pojo │ │ ├── Review.java │ │ └── Spit.java ├── leyou-comments-service │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── com │ │ │ │ └── leyou │ │ │ │ └── comments │ │ │ │ ├── LyCommentsApplication.java │ │ │ │ ├── bo │ │ │ │ └── CommentRequestParam.java │ │ │ │ ├── client │ │ │ │ └── OrderClient.java │ │ │ │ ├── config │ │ │ │ ├── IdWorkerConfig.java │ │ │ │ └── MvcConfig.java │ │ │ │ ├── controller │ │ │ │ └── CommentController.java │ │ │ │ ├── dao │ │ │ │ ├── CommentDao.java │ │ │ │ └── SpitDao.java │ │ │ │ ├── interceptor │ │ │ │ └── LoginInterceptor.java │ │ │ │ ├── listener │ │ │ │ └── CommentsListener.java │ │ │ │ ├── properties │ │ │ │ ├── IdWorkerProperties.java │ │ │ │ └── JwtProperties.java │ │ │ │ └── service │ │ │ │ ├── CommentService.java │ │ │ │ └── impl │ │ │ │ └── CommentServiceImpl.java │ │ └── resources │ │ │ └── bootstrap.yml │ │ └── test │ │ └── java │ │ ├── CommentsTest.java │ │ └── LeyouReviewServieApplicationTests.java └── pom.xml ├── leyou-common ├── pom.xml └── src │ └── main │ └── java │ └── com │ └── leyou │ ├── common │ └── pojo │ │ └── PageResult.java │ ├── myexception │ ├── LyException.java │ └── MyException.java │ ├── parameter │ └── pojo │ │ ├── BrandQueryByPageParameter.java │ │ └── SpuQueryByPageParameter.java │ ├── response │ ├── CodeMsg.java │ └── Result.java │ └── utils │ ├── CodecUtils.java │ ├── CookieUtils.java │ ├── IdWorker.java │ ├── JsonUtils.java │ ├── NumberUtils.java │ └── Test.java ├── leyou-config ├── pom.xml └── src │ └── main │ ├── java │ ├── com │ │ └── leyou │ │ │ └── config │ │ │ ├── LyConfigApplication.java │ │ │ └── myconfig │ │ │ └── MvcConfig.java │ └── come │ │ └── leyou │ │ └── config │ │ └── filter │ │ ├── CustometRequestWrapper.java │ │ └── MyFilter.java │ └── resources │ └── application.yml ├── leyou-goods-web ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── leyou │ │ │ ├── LyGoodsWebApplication.java │ │ │ ├── client │ │ │ ├── BrandClient.java │ │ │ ├── CategoryClient.java │ │ │ ├── GoodsClient.java │ │ │ ├── SpecClient.java │ │ │ └── SpuClient.java │ │ │ ├── controller │ │ │ └── GoodsController.java │ │ │ ├── listener │ │ │ └── GoodsListener.java │ │ │ ├── service │ │ │ ├── GoodsHtmlService.java │ │ │ ├── GoodsService.java │ │ │ └── impl │ │ │ │ ├── GoodsHtmlServiceImpl.java │ │ │ │ └── GoodsServiceImpl.java │ │ │ └── utils │ │ │ └── ThreadUtils.java │ └── resources │ │ ├── bootstrap.yml │ │ └── templates │ │ └── item.html │ └── test │ └── java │ └── RedisTest.java ├── leyou-item ├── leyou-item-interface │ ├── pom.xml │ └── src │ │ └── main │ │ └── java │ │ └── com │ │ └── leyou │ │ └── item │ │ ├── api │ │ ├── BrandApi.java │ │ ├── CategoryApi.java │ │ ├── GoodsApi.java │ │ ├── SpecApi.java │ │ └── SpuApi.java │ │ ├── bo │ │ ├── SeckillParameter.java │ │ └── SpuBo.java │ │ └── pojo │ │ ├── Brand.java │ │ ├── Category.java │ │ ├── SeckillGoods.java │ │ ├── Sku.java │ │ ├── Specification.java │ │ ├── Spu.java │ │ ├── SpuDetail.java │ │ └── Stock.java ├── leyou-item-service │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── com │ │ │ └── leyou │ │ │ ├── LyItemService.java │ │ │ └── item │ │ │ ├── controller │ │ │ ├── BrandController.java │ │ │ ├── CategoryController.java │ │ │ ├── GoodsController.java │ │ │ └── SpecificationController.java │ │ │ ├── mapper │ │ │ ├── BrandMapper.java │ │ │ ├── CategoryMapper.java │ │ │ ├── SeckillMapper.java │ │ │ ├── SkuMapper.java │ │ │ ├── SpecificationMapper.java │ │ │ ├── SpuDetailMapper.java │ │ │ ├── SpuMapper.java │ │ │ └── StockMapper.java │ │ │ └── service │ │ │ ├── BrandService.java │ │ │ ├── CategoryService.java │ │ │ ├── GoodsService.java │ │ │ ├── SpecificationService.java │ │ │ └── impl │ │ │ ├── BrandServiceImpl.java │ │ │ ├── CategoryServiceImpl.java │ │ │ ├── GoodsServiceImpl.java │ │ │ └── SpecificationServiceImpl.java │ │ └── resources │ │ └── bootstrap.yml └── pom.xml ├── leyou-order ├── leyou-order-interface │ ├── pom.xml │ └── src │ │ └── main │ │ └── java │ │ └── com │ │ └── leyou │ │ └── order │ │ ├── api │ │ └── OrderApi.java │ │ ├── pojo │ │ ├── Address.java │ │ ├── Order.java │ │ ├── OrderDetail.java │ │ ├── OrderStatus.java │ │ └── SeckillOrder.java │ │ └── vo │ │ ├── CommentsParameter.java │ │ └── OrderStatusMessage.java ├── leyou-order-service │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── com │ │ │ │ └── leyou │ │ │ │ └── order │ │ │ │ ├── LyOrderApplication.java │ │ │ │ ├── client │ │ │ │ └── GoodsClient.java │ │ │ │ ├── config │ │ │ │ ├── IdWorkerConfig.java │ │ │ │ ├── MvcConfig.java │ │ │ │ ├── PayConfig.java │ │ │ │ └── SwaggerConfig.java │ │ │ │ ├── controller │ │ │ │ ├── AddressController.java │ │ │ │ └── OrderController.java │ │ │ │ ├── interceptor │ │ │ │ └── LoginInterceptor.java │ │ │ │ ├── listener │ │ │ │ ├── SeckillListener.java │ │ │ │ └── UpdateOrderStatusListener.java │ │ │ │ ├── mapper │ │ │ │ ├── AddressMapper.java │ │ │ │ ├── OrderDetailMapper.java │ │ │ │ ├── OrderMapper.java │ │ │ │ ├── OrderStatusMapper.java │ │ │ │ ├── SeckillMapper.java │ │ │ │ ├── SeckillOrderMapper.java │ │ │ │ ├── SkuMapper.java │ │ │ │ └── StockMapper.java │ │ │ │ ├── properties │ │ │ │ ├── IdWorkerProperties.java │ │ │ │ ├── JwtProperties.java │ │ │ │ └── PayProperties.java │ │ │ │ ├── service │ │ │ │ ├── AddressService.java │ │ │ │ ├── OrderService.java │ │ │ │ ├── OrderStatusService.java │ │ │ │ └── impl │ │ │ │ │ ├── AddressServiceImpl.java │ │ │ │ │ ├── OrderServiceImpl.java │ │ │ │ │ └── OrderStatusServiceImpl.java │ │ │ │ └── utils │ │ │ │ ├── PayHelper.java │ │ │ │ └── PayState.java │ │ └── resources │ │ │ ├── bootstrap.yml │ │ │ └── mapper │ │ │ └── OrderMapper.xml │ │ └── test │ │ └── java │ │ └── com │ │ └── leyou │ │ └── rabbitmq │ │ └── test │ │ └── RabbitMQTest.java └── pom.xml ├── leyou-registry ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── leyou │ │ └── LyRegistry.java │ └── resources │ └── bootstrap.yml ├── leyou-search ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── leyou │ │ │ ├── LySearchService.java │ │ │ ├── bo │ │ │ └── SearchRequest.java │ │ │ ├── client │ │ │ ├── BrandClient.java │ │ │ ├── CategoryClient.java │ │ │ ├── GoodsClient.java │ │ │ ├── SpecClient.java │ │ │ └── SpuClient.java │ │ │ ├── controller │ │ │ └── SearchController.java │ │ │ ├── listener │ │ │ └── GoodsListener.java │ │ │ ├── pojo │ │ │ └── Goods.java │ │ │ ├── repository │ │ │ └── GoodsRepository.java │ │ │ ├── service │ │ │ ├── SearchService.java │ │ │ └── impl │ │ │ │ └── SearchServiceImpl.java │ │ │ └── vo │ │ │ └── SearchResult.java │ └── resources │ │ └── bootstrap.yml │ └── test │ └── java │ └── com │ └── leyou │ └── client │ ├── CategoryClientTest.java │ └── ElasticsearchTest.java ├── leyou-secskill ├── leyou-seckill-interface │ ├── pom.xml │ └── src │ │ └── main │ │ └── java │ │ └── com │ │ └── leyou │ │ └── seckill │ │ └── vo │ │ └── SeckillMessage.java ├── leyou-seckill-service │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── com │ │ │ │ └── leyou │ │ │ │ └── seckill │ │ │ │ ├── LySeckillApplication.java │ │ │ │ ├── access │ │ │ │ └── AccessLimit.java │ │ │ │ ├── client │ │ │ │ ├── GoodsClient.java │ │ │ │ └── OrderClient.java │ │ │ │ ├── config │ │ │ │ ├── MvcConfig.java │ │ │ │ └── OrderConfig.java │ │ │ │ ├── controller │ │ │ │ └── SeckillController.java │ │ │ │ ├── interceptor │ │ │ │ ├── AccessInterceptor.java │ │ │ │ └── LoginInterceptor.java │ │ │ │ ├── mapper │ │ │ │ ├── SeckillMapper.java │ │ │ │ ├── SeckillOrderMapper.java │ │ │ │ ├── SkuMapper.java │ │ │ │ └── StockMapper.java │ │ │ │ ├── properties │ │ │ │ └── JwtProperties.java │ │ │ │ └── service │ │ │ │ ├── SeckillService.java │ │ │ │ └── impl │ │ │ │ └── SeckillServiceImpl.java │ │ └── resources │ │ │ └── bootstrap.yml │ │ └── test │ │ └── java │ │ └── JsonTest.java └── pom.xml ├── leyou-sms ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── leyou │ │ └── sms │ │ ├── LySmsApplication.java │ │ ├── listener │ │ └── SmsListener.java │ │ ├── pojo │ │ └── SmsProperties.java │ │ └── utils │ │ └── SmsUtils.java │ └── resources │ └── bootstrap.yml ├── leyou-upload ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── leyou │ │ │ ├── LyUploadService.java │ │ │ ├── config │ │ │ ├── FastClientImporter.java │ │ │ └── GlobalCorsConfig.java │ │ │ └── upload │ │ │ ├── controller │ │ │ └── UploadController.java │ │ │ └── service │ │ │ ├── UploadService.java │ │ │ └── serviceimpl │ │ │ └── UploadServiceImpl.java │ └── resources │ │ └── bootstrap.yml │ └── test │ └── java │ └── com │ └── leyou │ └── test │ └── FdfsTest.java ├── leyou-user ├── leyou-user-interface │ ├── pom.xml │ └── src │ │ └── main │ │ └── java │ │ └── com │ │ └── leyou │ │ └── user │ │ ├── api │ │ └── UserApi.java │ │ └── pojo │ │ └── User.java ├── leyou-user-service │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── com │ │ │ │ └── leyou │ │ │ │ └── user │ │ │ │ ├── LyUserApplication.java │ │ │ │ ├── controller │ │ │ │ └── UserController.java │ │ │ │ ├── mapper │ │ │ │ └── UserMapper.java │ │ │ │ └── service │ │ │ │ ├── UserService.java │ │ │ │ └── impl │ │ │ │ └── UserServiceImpl.java │ │ └── resources │ │ │ └── bootstrap.yml │ │ └── test │ │ └── java │ │ ├── BCTest.java │ │ ├── RedisTest.java │ │ └── UserTest.java └── pom.xml ├── leyou.sql └── pom.xml /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /.idea/inspectionProfiles/Project_Default.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 43 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /leyou-api-gateway/src/main/java/com/leyou/LyApiGateway.java: -------------------------------------------------------------------------------- 1 | package com.leyou; 2 | 3 | /** 4 | * Author: 98050 5 | * Time: 2018-08-03 20:41 6 | * Feature: 7 | */ 8 | 9 | import org.springframework.boot.SpringApplication; 10 | import org.springframework.boot.autoconfigure.SpringBootApplication; 11 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; 12 | import org.springframework.cloud.netflix.zuul.EnableZuulProxy; 13 | 14 | /** 15 | * @author li 16 | * @time: 2018-08-03 20:41 17 | */ 18 | @SpringBootApplication 19 | @EnableDiscoveryClient 20 | @EnableZuulProxy 21 | public class LyApiGateway { 22 | public static void main(String[] args) { 23 | SpringApplication.run(LyApiGateway.class,args); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /leyou-api-gateway/src/main/java/com/leyou/config/FilterProperties.java: -------------------------------------------------------------------------------- 1 | package com.leyou.config; 2 | 3 | import org.springframework.beans.factory.annotation.Value; 4 | import org.springframework.boot.context.properties.ConfigurationProperties; 5 | import org.springframework.cloud.context.config.annotation.RefreshScope; 6 | import org.springframework.context.annotation.Configuration; 7 | import org.springframework.stereotype.Component; 8 | import org.springframework.stereotype.Controller; 9 | import org.springframework.stereotype.Repository; 10 | 11 | import java.util.List; 12 | 13 | /** 14 | * @Author: 98050 15 | * @Time: 2018-10-24 16:55 16 | * @Feature: 过滤白名单 17 | */ 18 | //@ConfigurationProperties(prefix = "leyou.filter") 19 | @Configuration 20 | @RefreshScope 21 | public class FilterProperties { 22 | 23 | @Value("${leyou.filter.allowPaths}") 24 | private String allowPaths; 25 | 26 | public String getAllowPaths() { 27 | return allowPaths; 28 | } 29 | 30 | public void setAllowPaths(String allowPaths) { 31 | this.allowPaths = allowPaths; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /leyou-api-gateway/src/main/java/com/leyou/config/GlobalCorsConfig.java: -------------------------------------------------------------------------------- 1 | package com.leyou.config; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.web.cors.CorsConfiguration; 6 | import org.springframework.web.cors.UrlBasedCorsConfigurationSource; 7 | import org.springframework.web.filter.CorsFilter; 8 | 9 | /** 10 | * @author li 11 | * @time:2018/8/7 12 | * 处理跨域请求的过滤器 13 | */ 14 | @Configuration 15 | public class GlobalCorsConfig { 16 | @Bean 17 | public CorsFilter corsFilter() { 18 | //1.添加CORS配置信息 19 | CorsConfiguration config = new CorsConfiguration(); 20 | 21 | //1) 允许的域,不要写*,否则cookie就无法使用了 22 | config.addAllowedOrigin("http://manage.leyou.com"); 23 | config.addAllowedOrigin("http://www.leyou.com"); 24 | //2) 是否发送Cookie信息 25 | config.setAllowCredentials(true); 26 | //3) 允许的请求方式 27 | config.addAllowedMethod("OPTIONS"); 28 | config.addAllowedMethod("HEAD"); 29 | config.addAllowedMethod("GET"); 30 | config.addAllowedMethod("PUT"); 31 | config.addAllowedMethod("POST"); 32 | config.addAllowedMethod("DELETE"); 33 | config.addAllowedMethod("PATCH"); 34 | // 4)允许的头信息 35 | config.addAllowedHeader("*"); 36 | 37 | //2.添加映射路径,我们拦截一切请求 38 | UrlBasedCorsConfigurationSource configSource = new UrlBasedCorsConfigurationSource(); 39 | configSource.registerCorsConfiguration("/**", config); 40 | 41 | //3.返回新的CorsFilter. 42 | return new CorsFilter(configSource); 43 | } 44 | } -------------------------------------------------------------------------------- /leyou-api-gateway/src/main/java/com/leyou/config/JwtProperties.java: -------------------------------------------------------------------------------- 1 | package com.leyou.config; 2 | 3 | import com.leyou.auth.utils.RsaUtils; 4 | import org.slf4j.Logger; 5 | import org.slf4j.LoggerFactory; 6 | import org.springframework.beans.factory.annotation.Value; 7 | import org.springframework.boot.context.properties.ConfigurationProperties; 8 | import org.springframework.cloud.context.config.annotation.RefreshScope; 9 | import org.springframework.context.annotation.Configuration; 10 | import org.springframework.stereotype.Component; 11 | 12 | import javax.annotation.PostConstruct; 13 | import java.io.File; 14 | import java.security.PublicKey; 15 | 16 | /** 17 | * @Author: 98050 18 | * @Time: 2018-10-24 16:12 19 | * @Feature: jwt属性 20 | */ 21 | //@ConfigurationProperties(prefix = "leyou.jwt") 22 | @Configuration 23 | @RefreshScope 24 | public class JwtProperties { 25 | /** 26 | * 公钥 27 | */ 28 | private PublicKey publicKey; 29 | 30 | /** 31 | * 公钥地址 32 | */ 33 | @Value("${leyou.jwt.pubKeyPath}") 34 | private String pubKeyPath; 35 | 36 | /** 37 | * cookie名字 38 | */ 39 | @Value("${leyou.jwt.cookieName}") 40 | private String cookieName; 41 | 42 | private static final Logger logger = LoggerFactory.getLogger(JwtProperties.class); 43 | 44 | public PublicKey getPublicKey() { 45 | return publicKey; 46 | } 47 | 48 | public void setPublicKey(PublicKey publicKey) { 49 | this.publicKey = publicKey; 50 | } 51 | 52 | public String getPubKeyPath() { 53 | return pubKeyPath; 54 | } 55 | 56 | public void setPubKeyPath(String pubKeyPath) { 57 | this.pubKeyPath = pubKeyPath; 58 | } 59 | 60 | public String getCookieName() { 61 | return cookieName; 62 | } 63 | 64 | public void setCookieName(String cookieName) { 65 | this.cookieName = cookieName; 66 | } 67 | 68 | public static Logger getLogger() { 69 | return logger; 70 | } 71 | 72 | /** 73 | * @PostConstruct :在构造方法执行之后执行该方法 74 | */ 75 | @PostConstruct 76 | public void init(){ 77 | try { 78 | // 获取公钥 79 | this.publicKey = RsaUtils.getPublicKey(pubKeyPath); 80 | } catch (Exception e) { 81 | logger.error("获取公钥失败!", e); 82 | throw new RuntimeException(); 83 | } 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /leyou-api-gateway/src/main/resources/bootstrap.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | cloud: 3 | config: 4 | name: gateway 5 | profile: dev 6 | label: master 7 | uri: http://127.0.0.1:10011 -------------------------------------------------------------------------------- /leyou-authentication/leyou-authentication-common/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | leyou-authentication 7 | com.leyou.authentication 8 | 1.0.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | com.leyou.authentication 13 | leyou-authentication-common 14 | 1.0.0-SNAPSHOT 15 | jar 16 | 17 | 18 | 19 | org.apache.commons 20 | commons-lang3 21 | 22 | 23 | 24 | io.jsonwebtoken 25 | jjwt 26 | 27 | 28 | 29 | joda-time 30 | joda-time 31 | 32 | 33 | 34 | org.springframework.boot 35 | spring-boot-starter-test 36 | 37 | 38 | 39 | 40 | 41 | 42 | org.springframework.boot 43 | spring-boot-maven-plugin 44 | 45 | com.xx.webapps.api.main.WebappsApiBidMain 46 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /leyou-authentication/leyou-authentication-common/src/main/java/com/leyou/auth/entity/UserInfo.java: -------------------------------------------------------------------------------- 1 | package com.leyou.auth.entity; 2 | 3 | /** 4 | * 用户信息 5 | */ 6 | public class UserInfo { 7 | 8 | private Long id; 9 | 10 | private String username; 11 | 12 | public UserInfo() { 13 | } 14 | 15 | public UserInfo(Long id, String username) { 16 | this.id = id; 17 | this.username = username; 18 | } 19 | 20 | public Long getId() { 21 | return this.id; 22 | } 23 | 24 | public void setId(Long id) { 25 | this.id = id; 26 | } 27 | 28 | public String getUsername() { 29 | return username; 30 | } 31 | 32 | public void setUsername(String username) { 33 | this.username = username; 34 | } 35 | } -------------------------------------------------------------------------------- /leyou-authentication/leyou-authentication-common/src/main/java/com/leyou/auth/utils/JwtConstans.java: -------------------------------------------------------------------------------- 1 | package com.leyou.auth.utils; 2 | 3 | public abstract class JwtConstans { 4 | public static final String JWT_KEY_ID = "id"; 5 | public static final String JWT_KEY_USER_NAME = "username"; 6 | } -------------------------------------------------------------------------------- /leyou-authentication/leyou-authentication-common/src/main/java/com/leyou/auth/utils/ObjectUtils.java: -------------------------------------------------------------------------------- 1 | package com.leyou.auth.utils; 2 | 3 | import org.apache.commons.lang3.StringUtils; 4 | 5 | public class ObjectUtils { 6 | 7 | public static String toString(Object obj) { 8 | if (obj == null) { 9 | return null; 10 | } 11 | return obj.toString(); 12 | } 13 | 14 | public static Long toLong(Object obj) { 15 | if (obj == null) { 16 | return 0L; 17 | } 18 | if (obj instanceof Double || obj instanceof Float) { 19 | return Long.valueOf(StringUtils.substringBefore(obj.toString(), ".")); 20 | } 21 | if (obj instanceof Number) { 22 | return Long.valueOf(obj.toString()); 23 | } 24 | if (obj instanceof String) { 25 | return Long.valueOf(obj.toString()); 26 | } else { 27 | return 0L; 28 | } 29 | } 30 | 31 | public static Integer toInt(Object obj) { 32 | return toLong(obj).intValue(); 33 | } 34 | } -------------------------------------------------------------------------------- /leyou-authentication/leyou-authentication-common/src/test/java/com/leyou/auth/test/JwtTest.java: -------------------------------------------------------------------------------- 1 | package com.leyou.auth.test; 2 | 3 | import com.leyou.auth.entity.UserInfo; 4 | import com.leyou.auth.utils.JwtUtils; 5 | import com.leyou.auth.utils.RsaUtils; 6 | import org.junit.Before; 7 | import org.junit.Test; 8 | 9 | import java.security.PrivateKey; 10 | import java.security.PublicKey; 11 | import java.util.Date; 12 | 13 | /** 14 | * @Author: 98050 15 | * @Time: 2018-10-23 20:58 16 | * @Feature: JWT测试 17 | */ 18 | public class JwtTest { 19 | 20 | private static final String pubKeyPath = "G:\\tmp\\rsa\\rsa.pub"; 21 | 22 | private static final String priKeyPath = "G:\\tmp\\rsa\\rsa.pri"; 23 | 24 | private PublicKey publicKey; 25 | 26 | private PrivateKey privateKey; 27 | 28 | @Test 29 | public void testRsa() throws Exception { 30 | RsaUtils.generateKey(pubKeyPath, priKeyPath, "234"); 31 | } 32 | 33 | @Before 34 | public void testGetRsa() throws Exception { 35 | this.publicKey = RsaUtils.getPublicKey(pubKeyPath); 36 | this.privateKey = RsaUtils.getPrivateKey(priKeyPath); 37 | } 38 | 39 | @Test 40 | public void testGenerateToken() throws Exception { 41 | // 生成token 42 | String token = JwtUtils.generateToken(new UserInfo(20L, "jack"), privateKey, 5); 43 | System.out.println("token = " + token); 44 | } 45 | 46 | @Test 47 | public void testParseToken() throws Exception { 48 | String token = "eyJhbGciOiJSUzI1NiJ9.eyJpZCI6MjAsInVzZXJuYW1lIjoiamFjayIsImV4cCI6MTU0MDMwMjU4MX0.KFGDe8V8TwLl5xGqM1brPV50JXf3Z6G4cXPIeYxsqaeeol06BnXNNsyLAbUSrFxloUf-hQqO41O1OrtERllU-JfZXs6MA6rTBSfpar2MJRSZyDGKqfBpPoRED3yZv8oFuzI_94GONqsipmGyQFqWUkhTf9k0tZ5LPRvvGl9tkvc"; 49 | 50 | // 解析token 51 | UserInfo user = JwtUtils.getInfoFromToken(token, publicKey); 52 | System.out.println("id: " + user.getId()); 53 | System.out.println("userName: " + user.getUsername()); 54 | } 55 | 56 | @Test 57 | public void date(){ 58 | System.out.println(new Date()); 59 | } 60 | } -------------------------------------------------------------------------------- /leyou-authentication/leyou-authentication-service/src/main/java/com/leyou/auth/LyAuthApplication.java: -------------------------------------------------------------------------------- 1 | package com.leyou.auth; 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.openfeign.EnableFeignClients; 7 | 8 | /** 9 | * @Author: 98050 10 | * @Time: 2018-10-23 20:11 11 | * @Feature: 授权服务启动器 12 | */ 13 | @SpringBootApplication 14 | @EnableDiscoveryClient 15 | @EnableFeignClients 16 | public class LyAuthApplication { 17 | public static void main(String[] args) { 18 | SpringApplication.run(LyAuthApplication.class,args); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /leyou-authentication/leyou-authentication-service/src/main/java/com/leyou/auth/client/UserClient.java: -------------------------------------------------------------------------------- 1 | package com.leyou.auth.client; 2 | 3 | import com.leyou.user.api.UserApi; 4 | import org.springframework.cloud.openfeign.FeignClient; 5 | 6 | /** 7 | * @Author: 98050 8 | * @Time: 2018-10-23 23:48 9 | * @Feature: 用户feignclient 10 | */ 11 | @FeignClient(value = "user-service") 12 | public interface UserClient extends UserApi { 13 | } 14 | -------------------------------------------------------------------------------- /leyou-authentication/leyou-authentication-service/src/main/java/com/leyou/auth/service/AuthService.java: -------------------------------------------------------------------------------- 1 | package com.leyou.auth.service; 2 | 3 | /** 4 | * @Author: 98050 5 | * @Time: 2018-10-23 22:46 6 | * @Feature: 7 | */ 8 | public interface AuthService { 9 | /** 10 | * 用户授权 11 | * @param username 12 | * @param password 13 | * @return 14 | */ 15 | String authentication(String username, String password); 16 | } 17 | -------------------------------------------------------------------------------- /leyou-authentication/leyou-authentication-service/src/main/java/com/leyou/auth/service/impl/AuthServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.leyou.auth.service.impl; 2 | 3 | import com.leyou.auth.client.UserClient; 4 | import com.leyou.auth.entity.UserInfo; 5 | import com.leyou.auth.properties.JwtProperties; 6 | import com.leyou.auth.service.AuthService; 7 | import com.leyou.auth.utils.JwtUtils; 8 | import com.leyou.user.pojo.User; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.stereotype.Service; 11 | 12 | /** 13 | * @Author: 98050 14 | * @Time: 2018-10-23 22:47 15 | * @Feature: 16 | */ 17 | @Service 18 | public class AuthServiceImpl implements AuthService { 19 | 20 | @Autowired 21 | private UserClient userClient; 22 | 23 | @Autowired 24 | private JwtProperties properties; 25 | 26 | /** 27 | * 用户授权 28 | * @param username 29 | * @param password 30 | * @return 31 | */ 32 | @Override 33 | public String authentication(String username, String password) { 34 | 35 | try{ 36 | //1.调用微服务查询用户信息 37 | User user = this.userClient.queryUser(username,password); 38 | //2.查询结果为空,则直接返回null 39 | if (user == null){ 40 | return null; 41 | } 42 | //3.查询结果不为空,则生成token 43 | String token = JwtUtils.generateToken(new UserInfo(user.getId(), user.getUsername()), 44 | properties.getPrivateKey(), properties.getExpire()); 45 | return token; 46 | 47 | }catch (Exception e){ 48 | e.printStackTrace(); 49 | return null; 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /leyou-authentication/leyou-authentication-service/src/main/resources/bootstrap.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | cloud: 3 | config: 4 | name: auth 5 | profile: dev 6 | label: master 7 | uri: http://127.0.0.1:10011 8 | -------------------------------------------------------------------------------- /leyou-authentication/leyou-authentication-service/src/test/java/TokenTest.java: -------------------------------------------------------------------------------- 1 | //import com.leyou.auth.LyAuthApplication; 2 | //import com.leyou.auth.service.AuthService; 3 | //import org.junit.Test; 4 | //import org.junit.runner.RunWith; 5 | //import org.springframework.beans.factory.annotation.Autowired; 6 | //import org.springframework.boot.test.context.SpringBootTest; 7 | //import org.springframework.test.context.junit4.SpringRunner; 8 | // 9 | //import java.io.*; 10 | // 11 | ///** 12 | // * @Author: 98050 13 | // * @Time: 2018-11-15 00:00 14 | // * @Feature: 获取5000用户的Token,写入文件中 15 | // */ 16 | //@RunWith(SpringRunner.class) 17 | //@SpringBootTest(classes = LyAuthApplication.class) 18 | //public class TokenTest { 19 | // 20 | // @Autowired 21 | // private AuthService authService; 22 | // 23 | // @Test 24 | // public void getToken() throws IOException { 25 | // File userInfo = new File("G:/userInfo.txt"); 26 | // if (userInfo.exists()){ 27 | // userInfo.delete(); 28 | // } 29 | // FileWriter fw = new FileWriter(userInfo, true); 30 | // BufferedWriter bw = new BufferedWriter(fw); 31 | // for (int i =0;i < 50 ; i++) { 32 | // String token = this.authService.authentication("username"+i,"abcdefg"+i); 33 | // bw.append("username"+i+","+token+"\r\n"); 34 | // } 35 | // bw.close(); 36 | // fw.close(); 37 | // 38 | // } 39 | // 40 | // @Test 41 | // public void getTokenCSV(){ 42 | // try { 43 | // File csv = new File("G://Token.csv");//CSV文件 44 | // BufferedWriter bw = new BufferedWriter(new FileWriter(csv, true)); 45 | // for (int i =0; i < 50; i++) { 46 | // //新增一行数据 47 | // String token = this.authService.authentication("username"+i,"abcdefg"+i); 48 | // bw.write("username"+i+","+token); 49 | // bw.newLine(); 50 | // } 51 | // bw.close(); 52 | // } catch (FileNotFoundException e) { 53 | // //捕获File对象生成时的异常 54 | // e.printStackTrace(); 55 | // } catch (IOException e) { 56 | // //捕获BufferedWriter对象关闭时的异常 57 | // e.printStackTrace(); 58 | // } 59 | // } 60 | //} 61 | -------------------------------------------------------------------------------- /leyou-authentication/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | leyou 7 | com.leyou.parent 8 | 1.0.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | com.leyou.authentication 13 | leyou-authentication 14 | pom 15 | 16 | leyou-authentication-common 17 | leyou-authentication-service 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /leyou-cart/src/main/java/com/leyou/cart/LyCartApplication.java: -------------------------------------------------------------------------------- 1 | package com.leyou.cart; 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.openfeign.EnableFeignClients; 7 | 8 | /** 9 | * @Author: 98050 10 | * @Time: 2018-10-24 20:46 11 | * @Feature:购物车启动器 12 | */ 13 | @SpringBootApplication 14 | @EnableDiscoveryClient 15 | @EnableFeignClients 16 | public class LyCartApplication { 17 | 18 | public static void main(String[] args) { 19 | SpringApplication.run(LyCartApplication.class,args); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /leyou-cart/src/main/java/com/leyou/cart/client/GoodsClient.java: -------------------------------------------------------------------------------- 1 | package com.leyou.cart.client; 2 | 3 | import com.leyou.item.api.GoodsApi; 4 | import org.springframework.cloud.openfeign.FeignClient; 5 | 6 | /** 7 | * @Author: 98050 8 | * @Time: 2018-10-25 21:03 9 | * @Feature: 商品FeignClient 10 | */ 11 | @FeignClient(value = "item-service") 12 | public interface GoodsClient extends GoodsApi { 13 | } 14 | -------------------------------------------------------------------------------- /leyou-cart/src/main/java/com/leyou/cart/config/MvcConfig.java: -------------------------------------------------------------------------------- 1 | package com.leyou.cart.config; 2 | 3 | import com.leyou.cart.interceptor.LoginInterceptor; 4 | import com.leyou.cart.properties.JwtProperties; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.boot.context.properties.EnableConfigurationProperties; 7 | import org.springframework.context.annotation.Bean; 8 | import org.springframework.context.annotation.Configuration; 9 | import org.springframework.web.servlet.config.annotation.InterceptorRegistry; 10 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; 11 | 12 | /** 13 | * @Author: 98050 14 | * @Time: 2018-10-25 19:48 15 | * @Feature: 配置过滤器 16 | */ 17 | @Configuration 18 | //@EnableConfigurationProperties(JwtProperties.class) 19 | public class MvcConfig implements WebMvcConfigurer { 20 | 21 | @Autowired 22 | private JwtProperties jwtProperties; 23 | 24 | @Bean 25 | public LoginInterceptor loginInterceptor(){ 26 | return new LoginInterceptor(jwtProperties); 27 | } 28 | 29 | @Override 30 | public void addInterceptors(InterceptorRegistry registry) { 31 | registry.addInterceptor(loginInterceptor()).addPathPatterns("/**"); 32 | } 33 | 34 | // @Bean 35 | // public FilterRegistrationBean someFilterRegistration1() { 36 | // //新建过滤器注册类 37 | // FilterRegistrationBean registration = new FilterRegistrationBean(); 38 | // // 添加我们写好的过滤器 39 | // registration.setFilter( new CartFilter()); 40 | // // 设置过滤器的URL模式 41 | // registration.addUrlPatterns("/*"); 42 | // return registration; 43 | // } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /leyou-cart/src/main/java/com/leyou/cart/controller/CartController.java: -------------------------------------------------------------------------------- 1 | package com.leyou.cart.controller; 2 | 3 | import com.leyou.cart.pojo.Cart; 4 | import com.leyou.cart.service.CartService; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.http.HttpStatus; 7 | import org.springframework.http.ResponseEntity; 8 | import org.springframework.stereotype.Controller; 9 | import org.springframework.web.bind.annotation.*; 10 | 11 | import java.util.List; 12 | 13 | /** 14 | * @Author: 98050 15 | * @Time: 2018-10-25 20:41 16 | * @Feature: 17 | */ 18 | @Controller 19 | public class CartController { 20 | 21 | @Autowired 22 | private CartService cartService; 23 | 24 | /** 25 | * 添加购物车 26 | * @param cart 27 | * @return 28 | */ 29 | @PostMapping 30 | public ResponseEntity addCart(@RequestBody Cart cart){ 31 | this.cartService.addCart(cart); 32 | return ResponseEntity.ok().build(); 33 | } 34 | 35 | /** 36 | * 查询购物车 37 | * @return 38 | */ 39 | @GetMapping 40 | public ResponseEntity> queryCartList(){ 41 | List carts = this.cartService.queryCartList(); 42 | if(carts == null){ 43 | return ResponseEntity.status(HttpStatus.NOT_FOUND).build(); 44 | } 45 | return ResponseEntity.ok(carts); 46 | } 47 | 48 | /** 49 | * 修改购物车中商品数量 50 | * @return 51 | */ 52 | @PutMapping 53 | public ResponseEntity updateNum(@RequestParam("skuId") Long skuId,@RequestParam("num") Integer num){ 54 | this.cartService.updateNum(skuId,num); 55 | return ResponseEntity.ok().build(); 56 | } 57 | 58 | /** 59 | * 删除购物车中的商品 60 | * @param skuId 61 | * @return 62 | */ 63 | @DeleteMapping("{skuId}") 64 | public ResponseEntity deleteCart(@PathVariable("skuId") String skuId){ 65 | this.cartService.deleteCart(skuId); 66 | return ResponseEntity.ok().build(); 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /leyou-cart/src/main/java/com/leyou/cart/filter/CartFilter.java: -------------------------------------------------------------------------------- 1 | package com.leyou.cart.filter; 2 | 3 | 4 | import javax.servlet.*; 5 | import javax.servlet.annotation.WebFilter; 6 | import java.io.IOException; 7 | 8 | /** 9 | * @Author: 98050 10 | * @Time: 2018-10-25 20:00 11 | * @Feature: 12 | */ 13 | //@WebFilter(filterName = "CartFilter",urlPatterns = {"/**"}) 14 | public class CartFilter implements Filter { 15 | @Override 16 | public void init(FilterConfig filterConfig) throws ServletException { 17 | System.out.println("过滤器初始化"); 18 | } 19 | 20 | @Override 21 | public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { 22 | System.out.println("具体过滤规则"); 23 | } 24 | 25 | @Override 26 | public void destroy() { 27 | System.out.println("销毁"); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /leyou-cart/src/main/java/com/leyou/cart/pojo/Cart.java: -------------------------------------------------------------------------------- 1 | package com.leyou.cart.pojo; 2 | 3 | /** 4 | * @Author: 98050 5 | * @Time: 2018-10-25 20:27 6 | * @Feature: 购物车实体类 7 | */ 8 | public class Cart { 9 | /** 10 | * 用户Id 11 | */ 12 | private Long userId; 13 | 14 | /** 15 | * 商品id 16 | */ 17 | private Long skuId; 18 | 19 | /** 20 | * 标题 21 | */ 22 | private String title; 23 | 24 | /** 25 | * 图片 26 | */ 27 | private String image; 28 | 29 | /** 30 | * 加入购物车时的价格 31 | */ 32 | private Long price; 33 | 34 | /** 35 | * 购买数量 36 | */ 37 | private Integer num; 38 | 39 | /** 40 | * 商品规格参数 41 | */ 42 | private String ownSpec; 43 | 44 | public Long getUserId() { 45 | return userId; 46 | } 47 | 48 | public void setUserId(Long userId) { 49 | this.userId = userId; 50 | } 51 | 52 | public Long getSkuId() { 53 | return skuId; 54 | } 55 | 56 | public void setSkuId(Long skuId) { 57 | this.skuId = skuId; 58 | } 59 | 60 | public String getTitle() { 61 | return title; 62 | } 63 | 64 | public void setTitle(String title) { 65 | this.title = title; 66 | } 67 | 68 | public String getImage() { 69 | return image; 70 | } 71 | 72 | public void setImage(String image) { 73 | this.image = image; 74 | } 75 | 76 | public Long getPrice() { 77 | return price; 78 | } 79 | 80 | public void setPrice(Long price) { 81 | this.price = price; 82 | } 83 | 84 | public Integer getNum() { 85 | return num; 86 | } 87 | 88 | public void setNum(Integer num) { 89 | this.num = num; 90 | } 91 | 92 | public String getOwnSpec() { 93 | return ownSpec; 94 | } 95 | 96 | public void setOwnSpec(String ownSpec) { 97 | this.ownSpec = ownSpec; 98 | } 99 | 100 | @Override 101 | public String toString() { 102 | return "Cart{" + 103 | "userId=" + userId + 104 | ", skuId=" + skuId + 105 | ", title='" + title + '\'' + 106 | ", image='" + image + '\'' + 107 | ", price=" + price + 108 | ", num=" + num + 109 | ", ownSpec='" + ownSpec + '\'' + 110 | '}'; 111 | } 112 | } 113 | -------------------------------------------------------------------------------- /leyou-cart/src/main/java/com/leyou/cart/properties/JwtProperties.java: -------------------------------------------------------------------------------- 1 | package com.leyou.cart.properties; 2 | 3 | import com.leyou.auth.utils.RsaUtils; 4 | import org.slf4j.Logger; 5 | import org.slf4j.LoggerFactory; 6 | import org.springframework.beans.factory.annotation.Value; 7 | import org.springframework.boot.context.properties.ConfigurationProperties; 8 | import org.springframework.cloud.context.config.annotation.RefreshScope; 9 | import org.springframework.context.annotation.Configuration; 10 | 11 | import javax.annotation.PostConstruct; 12 | import java.security.PublicKey; 13 | 14 | /** 15 | * @Author: 98050 16 | * @Time: 2018-10-25 16:12 17 | * @Feature: jwt属性 18 | */ 19 | //@ConfigurationProperties(prefix = "leyou.jwt") 20 | @Configuration 21 | @RefreshScope 22 | public class JwtProperties { 23 | /** 24 | * 公钥 25 | */ 26 | private PublicKey publicKey; 27 | 28 | /** 29 | * 公钥地址 30 | */ 31 | @Value("${leyou.jwt.pubKeyPath}") 32 | private String pubKeyPath; 33 | 34 | /** 35 | * cookie名字 36 | */ 37 | @Value("${leyou.jwt.cookieName}") 38 | private String cookieName; 39 | 40 | private static final Logger logger = LoggerFactory.getLogger(JwtProperties.class); 41 | 42 | public PublicKey getPublicKey() { 43 | return publicKey; 44 | } 45 | 46 | public void setPublicKey(PublicKey publicKey) { 47 | this.publicKey = publicKey; 48 | } 49 | 50 | public String getPubKeyPath() { 51 | return pubKeyPath; 52 | } 53 | 54 | public void setPubKeyPath(String pubKeyPath) { 55 | this.pubKeyPath = pubKeyPath; 56 | } 57 | 58 | public String getCookieName() { 59 | return cookieName; 60 | } 61 | 62 | public void setCookieName(String cookieName) { 63 | this.cookieName = cookieName; 64 | } 65 | 66 | public static Logger getLogger() { 67 | return logger; 68 | } 69 | 70 | /** 71 | * @PostConstruct :在构造方法执行之后执行该方法 72 | */ 73 | @PostConstruct 74 | public void init(){ 75 | try { 76 | // 获取公钥 77 | this.publicKey = RsaUtils.getPublicKey(pubKeyPath); 78 | } catch (Exception e) { 79 | logger.error("获取公钥失败!", e); 80 | throw new RuntimeException(); 81 | } 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /leyou-cart/src/main/java/com/leyou/cart/service/CartService.java: -------------------------------------------------------------------------------- 1 | package com.leyou.cart.service; 2 | 3 | import com.leyou.cart.pojo.Cart; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * @Author: 98050 9 | * @Time: 2018-10-25 20:47 10 | * @Feature: 11 | */ 12 | public interface CartService { 13 | /** 14 | * 添加购物车 15 | * @param cart 16 | */ 17 | void addCart(Cart cart); 18 | 19 | /** 20 | * 查询购物车 21 | * @return 22 | */ 23 | List queryCartList(); 24 | 25 | /** 26 | * 更新购物车中商品数量 27 | * @param skuId 28 | * @param num 29 | */ 30 | void updateNum(Long skuId, Integer num); 31 | 32 | /** 33 | * 删除购物车中的商品 34 | * @param skuId 35 | */ 36 | void deleteCart(String skuId); 37 | } 38 | -------------------------------------------------------------------------------- /leyou-cart/src/main/resources/bootstrap.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | cloud: 3 | config: 4 | name: cart 5 | profile: dev 6 | label: master 7 | uri: http://127.0.0.1:10011 -------------------------------------------------------------------------------- /leyou-cart/src/test/java/com/leyou/redis/RedisTest.java: -------------------------------------------------------------------------------- 1 | //package com.leyou.redis; 2 | // 3 | //import com.leyou.cart.LyCartApplication; 4 | //import org.junit.Test; 5 | //import org.junit.runner.RunWith; 6 | //import org.springframework.beans.factory.annotation.Autowired; 7 | //import org.springframework.boot.test.context.SpringBootTest; 8 | //import org.springframework.data.redis.core.BoundHashOperations; 9 | //import org.springframework.data.redis.core.RedisTemplate; 10 | //import org.springframework.data.redis.core.StringRedisTemplate; 11 | //import org.springframework.test.context.junit4.SpringRunner; 12 | // 13 | //import java.util.List; 14 | // 15 | ///** 16 | // * @Author: 98050 17 | // * @Time: 2018-10-25 22:58 18 | // * @Feature: 19 | // */ 20 | //@RunWith(SpringRunner.class) 21 | //@SpringBootTest(classes = LyCartApplication.class) 22 | //public class RedisTest { 23 | // 24 | // @Autowired 25 | // private StringRedisTemplate stringRedisTemplate; 26 | // 27 | // @Autowired 28 | // private RedisTemplate redisTemplate; 29 | // 30 | // @Test 31 | // public void test(){ 32 | // 33 | // BoundHashOperations boundHashOperations = this.redisTemplate.boundHashOps("test"); 34 | //// boundHashOperations.put("1", "test1"); 35 | //// boundHashOperations.put("2", "test2"); 36 | //// boundHashOperations.put("3", "test3"); 37 | // List result = boundHashOperations.values(); 38 | // for (Object o : result){ 39 | // System.out.println(o); 40 | // } 41 | // } 42 | // 43 | // @Test 44 | // public void test2(){ 45 | // 46 | // BoundHashOperations boundHashOperations = this.redisTemplate.boundHashOps("test"); 47 | //// boundHashOperations.put("1", "test1"); 48 | //// boundHashOperations.put("2", "test2"); 49 | //// boundHashOperations.put("3", "test3"); 50 | // List result = boundHashOperations.values(); 51 | // for (Object o : result){ 52 | // System.out.println(o); 53 | // } 54 | // } 55 | //} 56 | -------------------------------------------------------------------------------- /leyou-comments/leyou-comments-interface/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | leyou-comments 7 | com.leyou.parent 8 | 1.0.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | com.leyou.comments 13 | leyou-comments-interface 14 | jar 15 | 16 | 17 | 18 | javax.persistence 19 | persistence-api 20 | 21 | 22 | 23 | org.springframework 24 | spring-webmvc 25 | 26 | 27 | 28 | 29 | 30 | 31 | org.springframework.boot 32 | spring-boot-maven-plugin 33 | 34 | com.xx.webapps.api.main.WebappsApiBidMain 35 | 36 | 37 | 38 | 39 | repackage 40 | 41 | 42 | 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /leyou-comments/leyou-comments-interface/src/main/java/com/leyou/comments/pojo/Spit.java: -------------------------------------------------------------------------------- 1 | package com.leyou.comments.pojo; 2 | 3 | /** 4 | * @Author: 98050 5 | * @Time: 2018-11-26 16:46 6 | * @Feature: 7 | */ 8 | public class Spit { 9 | private String _id; 10 | 11 | private String content; 12 | 13 | private String userid; 14 | 15 | private String nickname; 16 | 17 | private Integer visits; 18 | 19 | public String get_id() { 20 | return _id; 21 | } 22 | 23 | public void set_id(String _id) { 24 | this._id = _id; 25 | } 26 | 27 | public String getContent() { 28 | return content; 29 | } 30 | 31 | public void setContent(String content) { 32 | this.content = content; 33 | } 34 | 35 | public String getUserid() { 36 | return userid; 37 | } 38 | 39 | public void setUserid(String userid) { 40 | this.userid = userid; 41 | } 42 | 43 | public String getNickname() { 44 | return nickname; 45 | } 46 | 47 | public void setNickname(String nickname) { 48 | this.nickname = nickname; 49 | } 50 | 51 | public Integer getVisits() { 52 | return visits; 53 | } 54 | 55 | public void setVisits(Integer visits) { 56 | this.visits = visits; 57 | } 58 | 59 | @Override 60 | public String toString() { 61 | return "Spit{" + 62 | "_id='" + _id + '\'' + 63 | ", content='" + content + '\'' + 64 | ", userid='" + userid + '\'' + 65 | ", nickname='" + nickname + '\'' + 66 | ", visits=" + visits + 67 | '}'; 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /leyou-comments/leyou-comments-service/src/main/java/com/leyou/comments/LyCommentsApplication.java: -------------------------------------------------------------------------------- 1 | package com.leyou.comments; 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.openfeign.EnableFeignClients; 7 | 8 | /** 9 | * @Author: 98050 10 | * @Time: 2018-11-29 15:41 11 | * @Feature: 开启feign 12 | */ 13 | @SpringBootApplication 14 | @EnableDiscoveryClient 15 | @EnableFeignClients 16 | public class LyCommentsApplication { 17 | public static void main(String[] args) { 18 | SpringApplication.run(LyCommentsApplication.class,args); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /leyou-comments/leyou-comments-service/src/main/java/com/leyou/comments/bo/CommentRequestParam.java: -------------------------------------------------------------------------------- 1 | package com.leyou.comments.bo; 2 | 3 | /** 4 | * @Author: 98050 5 | * @Time: 2018-11-26 21:40 6 | * @Feature: 7 | */ 8 | public class CommentRequestParam { 9 | /** 10 | * 商品id 11 | */ 12 | private Long spuId; 13 | 14 | /** 15 | * 当前页码 16 | */ 17 | private Integer page; 18 | 19 | /** 20 | * 每页大小,不从页面接收,而是固定大小 21 | */ 22 | private static final Integer DEFAULT_SIZE = 20; 23 | 24 | /** 25 | * 默认页 26 | */ 27 | private static final Integer DEFAULT_PAGE = 1; 28 | 29 | public Long getSpuId() { 30 | return spuId; 31 | } 32 | 33 | public void setSpuId(Long spuId) { 34 | this.spuId = spuId; 35 | } 36 | 37 | public Integer getPage() { 38 | if (page == null){ 39 | return DEFAULT_PAGE; 40 | } 41 | /** 42 | * 获取页码时做一些校验,不能小于1 43 | */ 44 | return Math.max(DEFAULT_PAGE,page); 45 | } 46 | 47 | public void setPage(Integer page) { 48 | this.page = page; 49 | } 50 | 51 | public Integer getDefaultSize() { 52 | return DEFAULT_SIZE; 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /leyou-comments/leyou-comments-service/src/main/java/com/leyou/comments/client/OrderClient.java: -------------------------------------------------------------------------------- 1 | package com.leyou.comments.client; 2 | 3 | import com.leyou.order.api.OrderApi; 4 | import org.springframework.cloud.openfeign.FeignClient; 5 | 6 | /** 7 | * @Author: 98050 8 | * @Time: 2018-11-12 15:19 9 | * @Feature: 订单接口 10 | */ 11 | @FeignClient(value = "order-service") 12 | public interface OrderClient extends OrderApi { 13 | } 14 | -------------------------------------------------------------------------------- /leyou-comments/leyou-comments-service/src/main/java/com/leyou/comments/config/IdWorkerConfig.java: -------------------------------------------------------------------------------- 1 | package com.leyou.comments.config; 2 | 3 | import com.leyou.comments.properties.IdWorkerProperties; 4 | import com.leyou.utils.IdWorker; 5 | import org.springframework.context.annotation.Bean; 6 | import org.springframework.context.annotation.Configuration; 7 | 8 | /** 9 | * @author: 98050 10 | * @create: 2018-10-27 11 | **/ 12 | @Configuration 13 | //@EnableConfigurationProperties(IdWorkerProperties.class) 14 | public class IdWorkerConfig { 15 | 16 | @Bean 17 | public IdWorker idWorker(IdWorkerProperties prop) { 18 | return new IdWorker(prop.getWorkerId(), prop.getDataCenterId()); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /leyou-comments/leyou-comments-service/src/main/java/com/leyou/comments/config/MvcConfig.java: -------------------------------------------------------------------------------- 1 | package com.leyou.comments.config; 2 | 3 | import com.fasterxml.jackson.databind.ObjectMapper; 4 | import com.fasterxml.jackson.databind.module.SimpleModule; 5 | import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; 6 | import com.leyou.comments.interceptor.LoginInterceptor; 7 | import com.leyou.comments.properties.JwtProperties; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.context.annotation.Bean; 10 | import org.springframework.context.annotation.Configuration; 11 | import org.springframework.http.converter.HttpMessageConverter; 12 | import org.springframework.http.converter.StringHttpMessageConverter; 13 | import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; 14 | import org.springframework.web.servlet.config.annotation.EnableWebMvc; 15 | import org.springframework.web.servlet.config.annotation.InterceptorRegistry; 16 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; 17 | 18 | import java.math.BigInteger; 19 | import java.nio.charset.Charset; 20 | import java.util.ArrayList; 21 | import java.util.List; 22 | 23 | /** 24 | * @author: 98050 25 | * @create: 2018-10-27 26 | **/ 27 | @Configuration 28 | @EnableWebMvc 29 | //@EnableConfigurationProperties(JwtProperties.class) 30 | public class MvcConfig implements WebMvcConfigurer { 31 | 32 | @Autowired 33 | private JwtProperties jwtProperties; 34 | 35 | @Bean 36 | public LoginInterceptor loginInterceptor() { 37 | return new LoginInterceptor(jwtProperties); 38 | } 39 | 40 | @Override 41 | public void addInterceptors(InterceptorRegistry registry) { 42 | 43 | List excludePath = new ArrayList<>(); 44 | excludePath.add("/list"); 45 | excludePath.add("/commentId/**"); 46 | excludePath.add("/comment"); 47 | excludePath.add("/visit/**"); 48 | registry.addInterceptor(loginInterceptor()) 49 | .addPathPatterns("/**").excludePathPatterns(excludePath); 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /leyou-comments/leyou-comments-service/src/main/java/com/leyou/comments/dao/CommentDao.java: -------------------------------------------------------------------------------- 1 | package com.leyou.comments.dao; 2 | 3 | 4 | import com.leyou.comments.pojo.Review; 5 | import org.springframework.data.domain.Page; 6 | import org.springframework.data.domain.Pageable; 7 | import org.springframework.data.mongodb.repository.MongoRepository; 8 | 9 | 10 | /** 11 | * @Author: 98050 12 | * @Time: 2018-11-26 20:51 13 | * @Feature: 14 | */ 15 | public interface CommentDao extends MongoRepository { 16 | 17 | /** 18 | * 分页查询 19 | * @param spuId 20 | * @param pageable 21 | * @return 22 | */ 23 | Page findReviewBySpuid(String spuId, Pageable pageable); 24 | } 25 | -------------------------------------------------------------------------------- /leyou-comments/leyou-comments-service/src/main/java/com/leyou/comments/dao/SpitDao.java: -------------------------------------------------------------------------------- 1 | package com.leyou.comments.dao; 2 | 3 | 4 | import com.leyou.comments.pojo.Spit; 5 | import org.springframework.data.mongodb.repository.MongoRepository; 6 | 7 | /** 8 | * @Author: 98050 9 | * @Time: 2018-11-26 20:47 10 | * @Feature: 11 | */ 12 | public interface SpitDao extends MongoRepository { 13 | } 14 | -------------------------------------------------------------------------------- /leyou-comments/leyou-comments-service/src/main/java/com/leyou/comments/properties/IdWorkerProperties.java: -------------------------------------------------------------------------------- 1 | package com.leyou.comments.properties; 2 | 3 | import org.springframework.beans.factory.annotation.Value; 4 | import org.springframework.cloud.context.config.annotation.RefreshScope; 5 | import org.springframework.context.annotation.Configuration; 6 | 7 | /** 8 | * @author: 98050 9 | * @create: 2018-10-27 10 | **/ 11 | //@ConfigurationProperties(prefix = "leyou.worker") 12 | @Configuration 13 | @RefreshScope 14 | public class IdWorkerProperties { 15 | 16 | /** 17 | * 当前机器id 18 | */ 19 | @Value("${leyou.worker.workerId}") 20 | private long workerId; 21 | 22 | /** 23 | * 序列号 24 | */ 25 | @Value("${leyou.worker.dataCenterId}") 26 | private long dataCenterId; 27 | 28 | public long getWorkerId() { 29 | return workerId; 30 | } 31 | 32 | public void setWorkerId(long workerId) { 33 | this.workerId = workerId; 34 | } 35 | 36 | public long getDataCenterId() { 37 | return dataCenterId; 38 | } 39 | 40 | public void setDataCenterId(long dataCenterId) { 41 | this.dataCenterId = dataCenterId; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /leyou-comments/leyou-comments-service/src/main/java/com/leyou/comments/properties/JwtProperties.java: -------------------------------------------------------------------------------- 1 | package com.leyou.comments.properties; 2 | 3 | import com.leyou.auth.utils.RsaUtils; 4 | import org.slf4j.Logger; 5 | import org.slf4j.LoggerFactory; 6 | import org.springframework.beans.factory.annotation.Value; 7 | import org.springframework.cloud.context.config.annotation.RefreshScope; 8 | import org.springframework.context.annotation.Configuration; 9 | 10 | import javax.annotation.PostConstruct; 11 | import java.security.PublicKey; 12 | 13 | /** 14 | * @author: 9805 15 | * @create: 2018-10-27 16 | **/ 17 | //@ConfigurationProperties(prefix = "leyou.jwt") 18 | @Configuration 19 | @RefreshScope 20 | public class JwtProperties { 21 | 22 | /** 23 | * 公钥地址 24 | */ 25 | @Value("${leyou.jwt.pubKeyPath}") 26 | private String pubKeyPath; 27 | 28 | /** 29 | * 公钥 30 | */ 31 | private PublicKey publicKey; 32 | 33 | @Value("${leyou.jwt.cookieName}") 34 | private String cookieName; 35 | 36 | private static final Logger logger = LoggerFactory.getLogger(JwtProperties.class); 37 | 38 | @PostConstruct 39 | public void init(){ 40 | try { 41 | // 获取公钥和私钥 42 | this.publicKey = RsaUtils.getPublicKey(pubKeyPath); 43 | } catch (Exception e) { 44 | logger.error("初始化公钥失败!", e); 45 | throw new RuntimeException(); 46 | } 47 | } 48 | 49 | public String getPubKeyPath() { 50 | return pubKeyPath; 51 | } 52 | 53 | public void setPubKeyPath(String pubKeyPath) { 54 | this.pubKeyPath = pubKeyPath; 55 | } 56 | 57 | public PublicKey getPublicKey() { 58 | return publicKey; 59 | } 60 | 61 | public void setPublicKey(PublicKey publicKey) { 62 | this.publicKey = publicKey; 63 | } 64 | 65 | public String getCookieName() { 66 | return cookieName; 67 | } 68 | 69 | public void setCookieName(String cookieName) { 70 | this.cookieName = cookieName; 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /leyou-comments/leyou-comments-service/src/main/java/com/leyou/comments/service/CommentService.java: -------------------------------------------------------------------------------- 1 | package com.leyou.comments.service; 2 | 3 | import com.leyou.comments.bo.CommentRequestParam; 4 | import com.leyou.comments.pojo.Review; 5 | import org.springframework.data.domain.Page; 6 | 7 | 8 | /** 9 | * @Author: 98050 10 | * @Time: 2018-11-26 15:40 11 | * @Feature: 12 | */ 13 | public interface CommentService { 14 | 15 | /** 16 | * 根据评论id查询 17 | * 18 | * @param id 19 | * @return 20 | */ 21 | Review findOne(String id); 22 | 23 | /** 24 | * 新增评论 25 | * @param review 26 | * @param orderId 27 | * @return 28 | */ 29 | boolean add(Long orderId,Review review); 30 | 31 | /** 32 | * 修改评论 33 | * 34 | * @param review 35 | */ 36 | void update(Review review); 37 | 38 | /** 39 | * 删除指定评论 40 | * 41 | * @param id 42 | */ 43 | void deleteById(String id); 44 | 45 | /** 46 | * 查询某一商品下的所有顶级评论 47 | * @param commentRequestParam 48 | * @return 49 | */ 50 | Page findReviewBySpuId(CommentRequestParam commentRequestParam); 51 | 52 | /** 53 | * 评论点赞 54 | * @param id 55 | */ 56 | boolean updateThumbup(String id); 57 | 58 | /** 59 | * 浏览量增1 60 | * @param id 61 | */ 62 | boolean updateVisits(String id); 63 | } 64 | -------------------------------------------------------------------------------- /leyou-comments/leyou-comments-service/src/main/resources/bootstrap.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | cloud: 3 | config: 4 | name: comments 5 | profile: dev 6 | label: master 7 | uri: http://127.0.0.1:10011 -------------------------------------------------------------------------------- /leyou-comments/leyou-comments-service/src/test/java/CommentsTest.java: -------------------------------------------------------------------------------- 1 | //import com.leyou.comments.LyCommentsApplication; 2 | //import com.leyou.comments.dao.CommentDao; 3 | //import com.leyou.comments.pojo.Review; 4 | //import com.leyou.comments.service.CommentService; 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.SpringRunner; 10 | // 11 | //import java.util.ArrayList; 12 | //import java.util.List; 13 | // 14 | ///** 15 | // * @Author: 98050 16 | // * @Time: 2018-12-09 20:37 17 | // * @Feature: 18 | // */ 19 | //@RunWith(SpringRunner.class) 20 | //@SpringBootTest(classes = LyCommentsApplication.class) 21 | //public class CommentsTest { 22 | // 23 | // @Autowired 24 | // private CommentService commentService; 25 | // 26 | // @Autowired 27 | // private CommentDao commentDao; 28 | // 29 | // /** 30 | // * 为spuId为2的商品添加100条评顶级论数据 31 | // */ 32 | // @Test 33 | // public void LoadData(){ 34 | // for (int i = 0; i < 100; i++) { 35 | // String spuId = "2"; 36 | // String content = "手机不错"+i; 37 | // String userId = (35 + i) + ""; 38 | // String nickname = "username"+i; 39 | // List images = new ArrayList<>(); 40 | // boolean iscomment = i % 2 == 0; 41 | // String parentId = 0 + ""; 42 | // boolean isparent = true; 43 | // int type = i % 5; 44 | // //Review review = new Review(spuId, content, userId, nickname, images, iscomment, parentId,isparent,type); 45 | // 46 | // //commentService.add(review); 47 | // } 48 | // } 49 | // 50 | // @Test 51 | // public void LoadOneData(){ 52 | // String spuId = "2"; 53 | // String content = "苹果手机不错"; 54 | // String userId = 36 + ""; 55 | // String nickname = "username1"; 56 | // List images = new ArrayList<>(); 57 | // boolean iscomment = true; 58 | // String parentId = "1071767095416725504"; 59 | // boolean isparent = false; 60 | // int type = 4; 61 | // //Review review = new Review(spuId, content, userId, nickname, images, iscomment, parentId,isparent,type); 62 | // 63 | // //commentService.add(review); 64 | // } 65 | // 66 | // @Test 67 | // public void delete(){ 68 | // commentDao.deleteAll(); 69 | // } 70 | //} 71 | -------------------------------------------------------------------------------- /leyou-comments/leyou-comments-service/src/test/java/LeyouReviewServieApplicationTests.java: -------------------------------------------------------------------------------- 1 | //import com.leyou.comments.LyCommentsApplication; 2 | //import com.leyou.comments.dao.SpitDao; 3 | //import com.leyou.comments.pojo.Spit; 4 | //import org.junit.Test; 5 | //import org.junit.runner.RunWith; 6 | //import org.springframework.beans.factory.annotation.Autowired; 7 | //import org.springframework.boot.test.context.SpringBootTest; 8 | //import org.springframework.data.mongodb.core.MongoTemplate; 9 | //import org.springframework.data.mongodb.core.query.Criteria; 10 | //import org.springframework.data.mongodb.core.query.Query; 11 | //import org.springframework.test.context.junit4.SpringRunner; 12 | // 13 | //import java.util.List; 14 | // 15 | //@RunWith(SpringRunner.class) 16 | //@SpringBootTest(classes = LyCommentsApplication.class) 17 | //public class LeyouReviewServieApplicationTests { 18 | // 19 | // @Autowired 20 | // private SpitDao spitDAO; 21 | // 22 | // @Autowired 23 | // private MongoTemplate mongoTemplate; 24 | // 25 | // @Test 26 | // public void contextLoads() { 27 | // Spit spit = new Spit(); 28 | // spit.set_id("5"); 29 | // spit.setContent("123123123"); 30 | // spit.setNickname("123123123"); 31 | // spit.setUserid("123121"); 32 | // spit.setVisits(1234); 33 | // spitDAO.save(spit); 34 | // } 35 | // 36 | // @Test 37 | // public void findTest(){ 38 | // Criteria criteria = new Criteria(); 39 | // criteria.andOperator(Criteria.where("_id").is("5"),Criteria.where("visits").is(1234)); 40 | // List spits = this.mongoTemplate.find(new Query(criteria),Spit.class); 41 | // System.out.println("数量:"+spits.size()); 42 | // for (Spit spit : spits){ 43 | // System.out.println(spit); 44 | // } 45 | // } 46 | //} 47 | -------------------------------------------------------------------------------- /leyou-comments/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | leyou 7 | com.leyou.parent 8 | 1.0.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | com.leyou.parent 13 | leyou-comments 14 | pom 15 | 16 | leyou-comments-service 17 | leyou-comments-interface 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /leyou-common/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | leyou 7 | com.leyou.parent 8 | 1.0.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | com.leyou.common 13 | leyou-common 14 | jar 15 | 16 | 17 | 18 | 19 | javax.servlet 20 | javax.servlet-api 21 | provided 22 | 23 | 24 | 25 | 26 | org.springframework.boot 27 | spring-boot-starter-logging 28 | 29 | 30 | 31 | 32 | com.fasterxml.jackson.core 33 | jackson-databind 34 | 35 | 36 | 37 | org.springframework.security 38 | spring-security-crypto 39 | compile 40 | 41 | 42 | 43 | org.apache.tomcat.embed 44 | tomcat-embed-core 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | org.springframework.boot 53 | spring-boot-maven-plugin 54 | 55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /leyou-common/src/main/java/com/leyou/common/pojo/PageResult.java: -------------------------------------------------------------------------------- 1 | package com.leyou.common.pojo; 2 | 3 | import java.util.List; 4 | 5 | /** 6 | * @author li 7 | * @param 8 | */ 9 | public class PageResult { 10 | 11 | /** 12 | * 总条数 13 | */ 14 | private Long total; 15 | /** 16 | * 总页数 17 | */ 18 | private Long totalPage; 19 | /** 20 | * 当前页数据 21 | */ 22 | private List items; 23 | 24 | public PageResult() { 25 | } 26 | 27 | public PageResult(Long total, List items) { 28 | this.total = total; 29 | this.items = items; 30 | } 31 | 32 | public PageResult(Long total, Long totalPage, List items) { 33 | this.total = total; 34 | this.totalPage = totalPage; 35 | this.items = items; 36 | } 37 | 38 | public Long getTotal() { 39 | return total; 40 | } 41 | 42 | public void setTotal(Long total) { 43 | this.total = total; 44 | } 45 | 46 | public List getItems() { 47 | return items; 48 | } 49 | 50 | public void setItems(List items) { 51 | this.items = items; 52 | } 53 | 54 | public Long getTotalPage() { 55 | return totalPage; 56 | } 57 | 58 | public void setTotalPage(Long totalPage) { 59 | this.totalPage = totalPage; 60 | } 61 | } -------------------------------------------------------------------------------- /leyou-common/src/main/java/com/leyou/myexception/LyException.java: -------------------------------------------------------------------------------- 1 | package com.leyou.myexception; 2 | 3 | /** 4 | * @Author: 98050 5 | * @Time: 2018-11-05 16:09 6 | * @Feature: 7 | */ 8 | public enum LyException { 9 | /** 10 | * 分类信息无法找到 11 | */ 12 | CATEGORY_NOT_FOUND, 13 | 14 | /** 15 | * 品牌信息无法找到 16 | */ 17 | BRAND_NOT_FOUND, 18 | } 19 | -------------------------------------------------------------------------------- /leyou-common/src/main/java/com/leyou/myexception/MyException.java: -------------------------------------------------------------------------------- 1 | package com.leyou.myexception; 2 | 3 | /** 4 | * @Author: 98050 5 | * @Time: 2018-11-05 16:07 6 | * @Feature: 7 | */ 8 | public class MyException extends RuntimeException { 9 | 10 | public MyException(LyException exception) { 11 | super(exception.toString()); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /leyou-common/src/main/java/com/leyou/parameter/pojo/BrandQueryByPageParameter.java: -------------------------------------------------------------------------------- 1 | package com.leyou.parameter.pojo; 2 | 3 | /** 4 | * @Author: 98050 5 | * Time: 2018-08-08 11:38 6 | * Feature: 7 | */ 8 | public class BrandQueryByPageParameter { 9 | 10 | /* 11 | * - page:当前页,int 12 | - rows:每页大小,int 13 | - sortBy:排序字段,String 14 | - desc:是否为降序,boolean 15 | - key:搜索关键词,String 16 | * */ 17 | 18 | private Integer page; 19 | private Integer rows; 20 | private String sortBy; 21 | private Boolean desc; 22 | private String key; 23 | 24 | public Integer getPage() { 25 | return page; 26 | } 27 | 28 | public void setPage(Integer page) { 29 | this.page = page; 30 | } 31 | 32 | public Integer getRows() { 33 | return rows; 34 | } 35 | 36 | public void setRows(Integer rows) { 37 | this.rows = rows; 38 | } 39 | 40 | public String getSortBy() { 41 | return sortBy; 42 | } 43 | 44 | public void setSortBy(String sortBy) { 45 | this.sortBy = sortBy; 46 | } 47 | 48 | public Boolean getDesc() { 49 | return desc; 50 | } 51 | 52 | public void setDesc(Boolean desc) { 53 | this.desc = desc; 54 | } 55 | 56 | public String getKey() { 57 | return key; 58 | } 59 | 60 | public void setKey(String key) { 61 | this.key = key; 62 | } 63 | 64 | public BrandQueryByPageParameter(Integer page, Integer rows, String sortBy, Boolean desc, String key) { 65 | this.page = page; 66 | this.rows = rows; 67 | this.sortBy = sortBy; 68 | this.desc = desc; 69 | this.key = key; 70 | } 71 | 72 | public BrandQueryByPageParameter(){ 73 | super(); 74 | } 75 | 76 | @Override 77 | public String toString() { 78 | return "BrandQueryByPageParameter{" + 79 | "page=" + page + 80 | ", rows=" + rows + 81 | ", sortBy='" + sortBy + '\'' + 82 | ", desc=" + desc + 83 | ", key='" + key + '\'' + 84 | '}'; 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /leyou-common/src/main/java/com/leyou/parameter/pojo/SpuQueryByPageParameter.java: -------------------------------------------------------------------------------- 1 | package com.leyou.parameter.pojo; 2 | 3 | /** 4 | * @Author: 98050 5 | * Time: 2018-08-14 22:19 6 | * Feature: 7 | */ 8 | public class SpuQueryByPageParameter extends BrandQueryByPageParameter{ 9 | /** 10 | * - page:当前页,int 11 | * - rows:每页大小,int 12 | * - sortBy:排序字段,String 13 | * - desc:是否为降序,boolean 14 | * - key:搜索关键词,String 15 | * - saleable: 是否上下架 16 | */ 17 | private Boolean saleable; 18 | 19 | public Boolean getSaleable() { 20 | return saleable; 21 | } 22 | 23 | public void setSaleable(Boolean saleable) { 24 | this.saleable = saleable; 25 | } 26 | 27 | public SpuQueryByPageParameter(Integer page, Integer rows, String sortBy, Boolean desc, String key, Boolean saleable) { 28 | super(page, rows, sortBy, desc, key); 29 | this.saleable = saleable; 30 | } 31 | 32 | public SpuQueryByPageParameter(Boolean saleable) { 33 | this.saleable = saleable; 34 | } 35 | 36 | @Override 37 | public String toString() { 38 | return "SpuQueryByPageParameter{" + 39 | "saleable=" + saleable + 40 | '}'; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /leyou-common/src/main/java/com/leyou/response/CodeMsg.java: -------------------------------------------------------------------------------- 1 | package com.leyou.response; 2 | 3 | /** 4 | * @Author: 98050 5 | * @Time: 2018-11-24 21:37 6 | * @Feature: 返回状态码 7 | */ 8 | public class CodeMsg { 9 | 10 | private int code; 11 | private String msg; 12 | 13 | 14 | /** 15 | * 通用的错误码 16 | */ 17 | public static CodeMsg SUCCESS = new CodeMsg(0, "success"); 18 | public static CodeMsg SERVER_ERROR = new CodeMsg(500100, "服务端异常"); 19 | public static CodeMsg BIND_ERROR = new CodeMsg(500101, "参数校验异常:%s"); 20 | public static CodeMsg REQUEST_ILLEGAL = new CodeMsg(500102, "请求非法"); 21 | public static CodeMsg ACCESS_LIMIT_REACHED= new CodeMsg(500104, "访问太频繁!"); 22 | 23 | /** 24 | * 登录模块 5002XX 25 | */ 26 | public static CodeMsg LOGIN_ERROR = new CodeMsg(500210, "用户未登录"); 27 | public static CodeMsg PASSWORD_EMPTY = new CodeMsg(500211, "登录密码不能为空"); 28 | public static CodeMsg MOBILE_EMPTY = new CodeMsg(500212, "手机号不能为空"); 29 | public static CodeMsg MOBILE_ERROR = new CodeMsg(500213, "手机号格式错误"); 30 | public static CodeMsg MOBILE_NOT_EXIST = new CodeMsg(500214, "手机号不存在"); 31 | public static CodeMsg PASSWORD_ERROR = new CodeMsg(500215, "密码错误"); 32 | 33 | 34 | //商品模块 5003XX 35 | 36 | 37 | /** 38 | * 订单模块 5004XX 39 | */ 40 | public static CodeMsg ORDER_NOT_EXIST = new CodeMsg(500400, "订单不存在"); 41 | 42 | /** 43 | * 秒杀模块 5005XX 44 | */ 45 | public static CodeMsg MIAO_SHA_OVER = new CodeMsg(500500, "商品已经秒杀完毕"); 46 | public static CodeMsg REPEATE_MIAOSHA = new CodeMsg(500501, "不能重复秒杀"); 47 | public static CodeMsg MIAOSHA_FAIL = new CodeMsg(500502, "秒杀失败"); 48 | 49 | 50 | private CodeMsg( ) { 51 | } 52 | 53 | private CodeMsg( int code,String msg ) { 54 | this.code = code; 55 | this.msg = msg; 56 | } 57 | 58 | public int getCode() { 59 | return code; 60 | } 61 | public void setCode(int code) { 62 | this.code = code; 63 | } 64 | public String getMsg() { 65 | return msg; 66 | } 67 | public void setMsg(String msg) { 68 | this.msg = msg; 69 | } 70 | 71 | public CodeMsg fillArgs(Object... args) { 72 | int code = this.code; 73 | String message = String.format(this.msg, args); 74 | return new CodeMsg(code, message); 75 | } 76 | 77 | @Override 78 | public String toString() { 79 | return "CodeMsg [code=" + code + ", msg=" + msg + "]"; 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /leyou-common/src/main/java/com/leyou/response/Result.java: -------------------------------------------------------------------------------- 1 | package com.leyou.response; 2 | 3 | /** 4 | * @Author: 98050 5 | * @Time: 2018-11-24 21:41 6 | * @Feature: 返回结果 7 | */ 8 | public class Result { 9 | 10 | private int code; 11 | private String msg; 12 | private T data; 13 | 14 | /** 15 | * 成功时候的调用 16 | * */ 17 | public static Result success(T data){ 18 | Result result = new Result(data); 19 | result.code = CodeMsg.SUCCESS.getCode(); 20 | return new Result(data); 21 | } 22 | 23 | /** 24 | * 失败时候的调用 25 | * */ 26 | public static Result error(CodeMsg codeMsg){ 27 | return new Result(codeMsg); 28 | } 29 | 30 | private Result(T data) { 31 | this.data = data; 32 | } 33 | 34 | private Result(int code, String msg) { 35 | this.code = code; 36 | this.msg = msg; 37 | } 38 | 39 | private Result(CodeMsg codeMsg) { 40 | if(codeMsg != null) { 41 | this.code = codeMsg.getCode(); 42 | this.msg = codeMsg.getMsg(); 43 | } 44 | } 45 | 46 | 47 | public int getCode() { 48 | return code; 49 | } 50 | public void setCode(int code) { 51 | this.code = code; 52 | } 53 | public String getMsg() { 54 | return msg; 55 | } 56 | public void setMsg(String msg) { 57 | this.msg = msg; 58 | } 59 | public T getData() { 60 | return data; 61 | } 62 | public void setData(T data) { 63 | this.data = data; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /leyou-common/src/main/java/com/leyou/utils/CodecUtils.java: -------------------------------------------------------------------------------- 1 | package com.leyou.utils; 2 | 3 | import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; 4 | 5 | /** 6 | * @Author: 98050 7 | * @Time: 2018-10-23 10:49 8 | * @Feature: 密码加密 9 | */ 10 | public class CodecUtils { 11 | 12 | public static String passwordBcryptEncode(String username,String password){ 13 | 14 | return new BCryptPasswordEncoder().encode(username + password); 15 | } 16 | 17 | public static Boolean passwordConfirm(String rawPassword,String encodePassword){ 18 | return new BCryptPasswordEncoder().matches(rawPassword,encodePassword); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /leyou-common/src/main/java/com/leyou/utils/JsonUtils.java: -------------------------------------------------------------------------------- 1 | package com.leyou.utils; 2 | 3 | import com.fasterxml.jackson.core.JsonProcessingException; 4 | import com.fasterxml.jackson.core.type.TypeReference; 5 | import com.fasterxml.jackson.databind.ObjectMapper; 6 | import com.sun.istack.internal.Nullable; 7 | import org.slf4j.Logger; 8 | import org.slf4j.LoggerFactory; 9 | 10 | import java.io.IOException; 11 | import java.util.List; 12 | import java.util.Map; 13 | 14 | /** 15 | * @author: li 16 | * @create: 2018-04-24 17:20 17 | **/ 18 | public class JsonUtils { 19 | 20 | public static final ObjectMapper mapper = new ObjectMapper(); 21 | 22 | private static final Logger logger = LoggerFactory.getLogger(JsonUtils.class); 23 | 24 | @Nullable 25 | public static String serialize(Object obj) { 26 | if (obj == null) { 27 | return null; 28 | } 29 | if (obj.getClass() == String.class) { 30 | return (String) obj; 31 | } 32 | try { 33 | return mapper.writeValueAsString(obj); 34 | } catch (JsonProcessingException e) { 35 | logger.error("json序列化出错:" + obj, e); 36 | return null; 37 | } 38 | } 39 | 40 | @Nullable 41 | public static T parse(String json, Class tClass) { 42 | try { 43 | return mapper.readValue(json, tClass); 44 | } catch (IOException e) { 45 | logger.error("json解析出错:" + json, e); 46 | return null; 47 | } 48 | } 49 | 50 | @Nullable 51 | public static List parseList(String json, Class eClass) { 52 | try { 53 | return mapper.readValue(json, mapper.getTypeFactory().constructCollectionType(List.class, eClass)); 54 | } catch (IOException e) { 55 | logger.error("json解析出错:" + json, e); 56 | return null; 57 | } 58 | } 59 | 60 | @Nullable 61 | public static Map parseMap(String json, Class kClass, Class vClass) { 62 | try { 63 | return mapper.readValue(json, mapper.getTypeFactory().constructMapType(Map.class, kClass, vClass)); 64 | } catch (IOException e) { 65 | logger.error("json解析出错:" + json, e); 66 | return null; 67 | } 68 | } 69 | 70 | @Nullable 71 | public static T nativeRead(String json, TypeReference type) { 72 | try { 73 | return mapper.readValue(json, type); 74 | } catch (IOException e) { 75 | logger.error("json解析出错:" + json, e); 76 | return null; 77 | } 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /leyou-common/src/main/java/com/leyou/utils/NumberUtils.java: -------------------------------------------------------------------------------- 1 | package com.leyou.utils; 2 | 3 | import java.math.BigDecimal; 4 | import java.math.RoundingMode; 5 | import java.util.ArrayList; 6 | import java.util.List; 7 | import java.util.Random; 8 | import java.util.regex.MatchResult; 9 | import java.util.regex.Matcher; 10 | import java.util.regex.Pattern; 11 | 12 | /** 13 | * @author: 98050 14 | * @create: 2018-04-25 09:13 15 | **/ 16 | public class NumberUtils { 17 | 18 | public static boolean isInt(Double num) { 19 | return num.intValue() == num; 20 | } 21 | 22 | /** 23 | * 判断字符串是否是数值格式 24 | * @param str 25 | * @return 26 | */ 27 | public static boolean isDigit(String str){ 28 | if(str == null || str.trim().equals("")){ 29 | return false; 30 | } 31 | return str.matches("^\\d+$"); 32 | } 33 | 34 | /** 35 | * 将一个小数精确到指定位数 36 | * @param num 37 | * @param scale 38 | * @return 39 | */ 40 | public static double scale(double num, int scale) { 41 | BigDecimal bd = new BigDecimal(num); 42 | return bd.setScale(scale, RoundingMode.HALF_UP).doubleValue(); 43 | } 44 | 45 | /** 46 | * 从字符串中根据正则表达式寻找,返回找到的数字数组 47 | * @param value 48 | * @param regex 49 | * @return 50 | */ 51 | public static Double[] searchNumber(String value, String regex){ 52 | List doubles = new ArrayList<>(); 53 | Pattern pattern = Pattern.compile(regex); 54 | Matcher matcher = pattern.matcher(value); 55 | if(matcher.find()) { 56 | MatchResult result = matcher.toMatchResult(); 57 | for (int i = 1; i <= result.groupCount(); i++) { 58 | doubles.add(Double.valueOf(result.group(i))); 59 | } 60 | } 61 | return doubles.toArray(new Double[doubles.size()]); 62 | } 63 | 64 | /** 65 | * 生成指定位数的随机数字 66 | * @param len 67 | * @return 68 | */ 69 | public static String generateCode(int len){ 70 | len = Math.min(len, 8); 71 | int min = Double.valueOf(Math.pow(10, len - 1)).intValue(); 72 | int num = new Random().nextInt(Double.valueOf(Math.pow(10, len + 1)).intValue() - 1) + min; 73 | return String.valueOf(num).substring(0,len); 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /leyou-common/src/main/java/com/leyou/utils/Test.java: -------------------------------------------------------------------------------- 1 | package com.leyou.utils; 2 | 3 | import java.util.Arrays; 4 | import java.util.List; 5 | 6 | /** 7 | * Author: 98050 8 | * Time: 2018-08-05 15:58 9 | * Feature: 10 | */ 11 | public class Test { 12 | public static void main(String[] args) { 13 | List lis = Arrays.asList(1, 2, 3); 14 | lis.forEach(num -> System.out.println(num)); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /leyou-config/src/main/java/com/leyou/config/LyConfigApplication.java: -------------------------------------------------------------------------------- 1 | package com.leyou.config; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.config.server.EnableConfigServer; 6 | 7 | /** 8 | * @Author: 98050 9 | * @Time: 2018-11-28 16:39 10 | * @Feature: 配置中心 11 | */ 12 | @EnableConfigServer 13 | @SpringBootApplication 14 | public class LyConfigApplication { 15 | 16 | public static void main(String[] args) { 17 | SpringApplication.run(LyConfigApplication.class,args); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /leyou-config/src/main/java/com/leyou/config/myconfig/MvcConfig.java: -------------------------------------------------------------------------------- 1 | package com.leyou.config.myconfig; 2 | 3 | import come.leyou.config.filter.MyFilter; 4 | import org.springframework.boot.web.servlet.FilterRegistrationBean; 5 | import org.springframework.context.annotation.Bean; 6 | import org.springframework.context.annotation.Configuration; 7 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; 8 | 9 | /** 10 | * @Author: 98050 11 | * @Time: 2018-11-30 20:56 12 | * @Feature: 13 | */ 14 | @Configuration 15 | public class MvcConfig implements WebMvcConfigurer { 16 | 17 | @Bean 18 | public FilterRegistrationBean someFilterRegistration1() { 19 | //新建过滤器注册类 20 | FilterRegistrationBean registration = new FilterRegistrationBean(); 21 | // 添加我们写好的过滤器 22 | registration.setFilter( new MyFilter()); 23 | // 设置过滤器的URL模式 24 | registration.addUrlPatterns("/*"); 25 | return registration; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /leyou-config/src/main/java/come/leyou/config/filter/CustometRequestWrapper.java: -------------------------------------------------------------------------------- 1 | package come.leyou.config.filter; 2 | 3 | import javax.servlet.ReadListener; 4 | import javax.servlet.ServletInputStream; 5 | import javax.servlet.http.HttpServletRequest; 6 | import javax.servlet.http.HttpServletRequestWrapper; 7 | import java.io.ByteArrayInputStream; 8 | import java.io.IOException; 9 | /** 10 | * @author 98050 11 | */ 12 | public class CustometRequestWrapper extends HttpServletRequestWrapper { 13 | public CustometRequestWrapper(HttpServletRequest request) { 14 | super(request); 15 | } 16 | 17 | @Override 18 | public ServletInputStream getInputStream() throws IOException { 19 | byte[] bytes = new byte[0]; 20 | ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(bytes); 21 | 22 | return new ServletInputStream() { 23 | @Override 24 | public boolean isFinished() { 25 | return byteArrayInputStream.read() == -1 ? true:false; 26 | } 27 | 28 | @Override 29 | public boolean isReady() { 30 | return false; 31 | } 32 | 33 | @Override 34 | public void setReadListener(ReadListener readListener) { 35 | 36 | } 37 | 38 | @Override 39 | public int read() throws IOException { 40 | return byteArrayInputStream.read(); 41 | } 42 | }; 43 | } 44 | } -------------------------------------------------------------------------------- /leyou-config/src/main/java/come/leyou/config/filter/MyFilter.java: -------------------------------------------------------------------------------- 1 | package come.leyou.config.filter; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | 6 | import javax.servlet.*; 7 | import javax.servlet.http.HttpServletRequest; 8 | import javax.servlet.http.HttpServletResponse; 9 | import java.io.IOException; 10 | 11 | /** 12 | * @Author: 98050 13 | * @Time: 2018-11-30 20:59 14 | * @Feature: 15 | */ 16 | public class MyFilter implements Filter { 17 | 18 | private Logger logger = LoggerFactory.getLogger(MyFilter.class); 19 | 20 | @Override 21 | public void init(FilterConfig filterConfig) throws ServletException { 22 | logger.info("过滤器启动"); 23 | } 24 | 25 | @Override 26 | public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { 27 | HttpServletRequest httpServletRequest = (HttpServletRequest) servletRequest; 28 | HttpServletResponse httpServletResponse = (HttpServletResponse) servletResponse; 29 | String url = httpServletRequest.getRequestURI(); 30 | 31 | //过滤/actuator/bus-refresh请求 32 | String suffix = "/bus-refresh"; 33 | if (!url.endsWith(suffix)){ 34 | filterChain.doFilter(servletRequest,servletResponse); 35 | return; 36 | } 37 | 38 | CustometRequestWrapper requestWrapper = new CustometRequestWrapper(httpServletRequest); 39 | filterChain.doFilter(requestWrapper,servletResponse); 40 | 41 | } 42 | 43 | @Override 44 | public void destroy() { 45 | logger.info("过滤器销毁"); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /leyou-config/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 10011 3 | spring: 4 | application: 5 | name: leyou-config 6 | cloud: 7 | config: 8 | server: 9 | git: 10 | uri: https://github.com/lyj8330328/leyou-config.git 11 | rabbitmq: 12 | host: 192.168.19.121 13 | username: /leyou 14 | password: leyou 15 | virtual-host: /leyou 16 | 17 | 18 | management: #暴露触发消息总线的地址 19 | endpoints: 20 | web: 21 | exposure: 22 | include: bus-refresh 23 | -------------------------------------------------------------------------------- /leyou-goods-web/src/main/java/com/leyou/LyGoodsWebApplication.java: -------------------------------------------------------------------------------- 1 | package com.leyou; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.boot.builder.SpringApplicationBuilder; 6 | import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; 7 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; 8 | import org.springframework.cloud.openfeign.EnableFeignClients; 9 | 10 | /** 11 | * @Author: 98050 12 | * Time: 2018-10-17 11:10 13 | * Feature: 商品详情微服务启动器,开启fegin功能 14 | */ 15 | @SpringBootApplication 16 | @EnableDiscoveryClient 17 | @EnableFeignClients 18 | public class LyGoodsWebApplication { 19 | public static void main(String[] args) { 20 | SpringApplication.run(LyGoodsWebApplication.class,args); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /leyou-goods-web/src/main/java/com/leyou/client/BrandClient.java: -------------------------------------------------------------------------------- 1 | package com.leyou.client; 2 | 3 | /** 4 | * @Author: 98050 5 | * Time: 2018-10-17 18:59 6 | * Feature:品牌FeignClient 7 | */ 8 | 9 | import com.leyou.item.api.BrandApi; 10 | import org.springframework.cloud.openfeign.FeignClient; 11 | 12 | @FeignClient(value = "item-service") 13 | public interface BrandClient extends BrandApi { 14 | } 15 | -------------------------------------------------------------------------------- /leyou-goods-web/src/main/java/com/leyou/client/CategoryClient.java: -------------------------------------------------------------------------------- 1 | package com.leyou.client; 2 | 3 | import com.leyou.item.api.CategoryApi; 4 | import org.springframework.cloud.openfeign.FeignClient; 5 | 6 | /** 7 | * @Author: 98050 8 | * Time: 2018-10-17 19:01 9 | * Feature:商品分类FeignClient 10 | */ 11 | @FeignClient(value = "item-service") 12 | public interface CategoryClient extends CategoryApi { 13 | } 14 | -------------------------------------------------------------------------------- /leyou-goods-web/src/main/java/com/leyou/client/GoodsClient.java: -------------------------------------------------------------------------------- 1 | package com.leyou.client; 2 | 3 | import com.leyou.item.api.GoodsApi; 4 | import org.springframework.cloud.openfeign.FeignClient; 5 | 6 | /** 7 | * @Author: 98050 8 | * Time: 2018-10-17 18:55 9 | * Feature:商品FeignClient 10 | */ 11 | @FeignClient(value = "item-service") 12 | public interface GoodsClient extends GoodsApi { 13 | } 14 | -------------------------------------------------------------------------------- /leyou-goods-web/src/main/java/com/leyou/client/SpecClient.java: -------------------------------------------------------------------------------- 1 | package com.leyou.client; 2 | 3 | import com.leyou.item.api.SpecApi; 4 | import org.springframework.cloud.openfeign.FeignClient; 5 | 6 | /** 7 | * @Author: 98050 8 | * Time: 2018-10-17 19:01 9 | * Feature:spec FeignClient 10 | */ 11 | @FeignClient(value = "item-service") 12 | public interface SpecClient extends SpecApi { 13 | } 14 | -------------------------------------------------------------------------------- /leyou-goods-web/src/main/java/com/leyou/client/SpuClient.java: -------------------------------------------------------------------------------- 1 | package com.leyou.client; 2 | 3 | import com.leyou.item.api.SpuApi; 4 | import org.springframework.cloud.openfeign.FeignClient; 5 | 6 | /** 7 | * @Author: 98050 8 | * Time: 2018-10-17 19:02 9 | * Feature: 10 | */ 11 | @FeignClient(value = "item-service") 12 | public interface SpuClient extends SpuApi { 13 | } 14 | -------------------------------------------------------------------------------- /leyou-goods-web/src/main/java/com/leyou/listener/GoodsListener.java: -------------------------------------------------------------------------------- 1 | package com.leyou.listener; 2 | 3 | import com.leyou.service.GoodsHtmlService; 4 | import org.springframework.amqp.core.ExchangeTypes; 5 | import org.springframework.amqp.rabbit.annotation.Exchange; 6 | import org.springframework.amqp.rabbit.annotation.Queue; 7 | import org.springframework.amqp.rabbit.annotation.QueueBinding; 8 | import org.springframework.amqp.rabbit.annotation.RabbitListener; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.stereotype.Component; 11 | 12 | /** 13 | * @Author: 98050 14 | * @Time: 2018-10-21 14:45 15 | * @Feature: mq监听器,消费者 16 | */ 17 | @Component 18 | public class GoodsListener { 19 | 20 | @Autowired 21 | private GoodsHtmlService goodsHtmlService; 22 | 23 | /** 24 | * 处理insert和update的消息 25 | * @param id 26 | * @throws Exception 27 | */ 28 | @RabbitListener(bindings = @QueueBinding( 29 | value = @Queue(value = "leyou.create.web.queue",durable = "true"), //队列持久化 30 | exchange = @Exchange( 31 | value = "leyou.item.exchange", 32 | ignoreDeclarationExceptions = "true", 33 | type = ExchangeTypes.TOPIC 34 | ), 35 | key = {"item.insert","item.update"} 36 | )) 37 | public void listenCreate(Long id) throws Exception{ 38 | if (id == null){ 39 | return; 40 | } 41 | //创建或更新索引 42 | this.goodsHtmlService.createHtml(id); 43 | } 44 | 45 | @RabbitListener(bindings = @QueueBinding( 46 | value = @Queue(value = "leyou.delete.web.queue",durable = "true"), //队列持久化 47 | exchange = @Exchange( 48 | value = "leyou.item.exchange", 49 | ignoreDeclarationExceptions = "true", 50 | type = ExchangeTypes.TOPIC 51 | ), 52 | key = {"item.delete"} 53 | )) 54 | public void listenDelete(Long id){ 55 | if (id == null){ 56 | return; 57 | } 58 | 59 | //删除索引 60 | this.goodsHtmlService.deleteHtml(id); 61 | } 62 | 63 | 64 | } 65 | -------------------------------------------------------------------------------- /leyou-goods-web/src/main/java/com/leyou/service/GoodsHtmlService.java: -------------------------------------------------------------------------------- 1 | package com.leyou.service; 2 | 3 | import java.util.concurrent.ExecutionException; 4 | 5 | /** 6 | * @Author: 98050 7 | * @Time: 2018-10-19 09:40 8 | * @Feature: 页面详情静态化接口 9 | */ 10 | public interface GoodsHtmlService { 11 | 12 | /** 13 | * 创建html页面 14 | * @param spuId 15 | */ 16 | void createHtml(Long spuId) throws InterruptedException, ExecutionException; 17 | 18 | /** 19 | * 新建线程处理页面静态化,Controller调用 20 | * @param spuId 21 | */ 22 | void asyncExecute(Long spuId); 23 | 24 | /** 25 | * 删除html页面 26 | * @param id 27 | */ 28 | void deleteHtml(Long id); 29 | } 30 | -------------------------------------------------------------------------------- /leyou-goods-web/src/main/java/com/leyou/service/GoodsService.java: -------------------------------------------------------------------------------- 1 | package com.leyou.service; 2 | 3 | import java.util.Map; 4 | import java.util.concurrent.ExecutionException; 5 | 6 | /** 7 | * @Author: 98050 8 | * Time: 2018-10-17 19:27 9 | * Feature:商品详情页后台 10 | */ 11 | public interface GoodsService { 12 | /** 13 | * 商品详细信息 14 | * @param spuId 15 | * @return 16 | */ 17 | Map loadModel(Long spuId) throws InterruptedException, ExecutionException; 18 | } 19 | -------------------------------------------------------------------------------- /leyou-goods-web/src/main/java/com/leyou/utils/ThreadUtils.java: -------------------------------------------------------------------------------- 1 | package com.leyou.utils; 2 | 3 | import java.util.concurrent.*; 4 | 5 | /** 6 | * @Author: 98050 7 | * @Time: 2018-10-19 10:19 8 | * @Feature: 线程工具 9 | */ 10 | public class ThreadUtils { 11 | 12 | private static final ExecutorService es = Executors.newFixedThreadPool(10); 13 | 14 | public static void execute(Runnable runnable){ 15 | es.submit(runnable); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /leyou-goods-web/src/main/resources/bootstrap.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | cloud: 3 | config: 4 | name: goodsweb 5 | profile: dev 6 | label: master 7 | uri: http://127.0.0.1:10011 8 | -------------------------------------------------------------------------------- /leyou-goods-web/src/test/java/RedisTest.java: -------------------------------------------------------------------------------- 1 | import com.leyou.LyGoodsWebApplication; 2 | import org.junit.Test; 3 | import org.junit.runner.RunWith; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.data.redis.core.BoundHashOperations; 7 | import org.springframework.data.redis.core.BoundValueOperations; 8 | import org.springframework.data.redis.core.RedisTemplate; 9 | import org.springframework.data.redis.core.StringRedisTemplate; 10 | import org.springframework.test.context.junit4.SpringRunner; 11 | 12 | import java.util.HashMap; 13 | import java.util.Map; 14 | 15 | /** 16 | * @Author: 98050 17 | * @Time: 2018-10-25 22:58 18 | * @Feature: 19 | */ 20 | @RunWith(SpringRunner.class) 21 | @SpringBootTest(classes = LyGoodsWebApplication.class) 22 | public class RedisTest { 23 | 24 | @Autowired 25 | private StringRedisTemplate stringRedisTemplate; 26 | 27 | @Autowired 28 | private RedisTemplate redisTemplate; 29 | 30 | private static final String KEY_PREFIX = "leyou:seckill:test"; 31 | 32 | @Test 33 | public void testRedisObj() { 34 | //redisTemplate.opsForValue().set("111111111","2222221231232222222"); 35 | //redisTemplate.opsForValue().set("key","1"); 36 | redisTemplate.opsForValue().increment("key",1); 37 | } 38 | 39 | 40 | @Test 41 | public void test(){ 42 | BoundHashOperations hashOperations = this.stringRedisTemplate.boundHashOps("leyou:goods:detail:1"); 43 | BoundValueOperations valueOperations = this.stringRedisTemplate.boundValueOps("leyou:goods:detail:1"); 44 | valueOperations.set("123", 1); 45 | //hashOperations.increment("123", 2); 46 | //hashOperations.expire(10, TimeUnit.SECONDS); 47 | } 48 | 49 | @Test 50 | public void redisTest(){ 51 | Map result = new HashMap<>(); 52 | BoundHashOperations hashOperations = this.stringRedisTemplate.boundHashOps(KEY_PREFIX); 53 | hashOperations.put("1", "22"); 54 | hashOperations.put("2", "22"); 55 | hashOperations.put("3", "22"); 56 | 57 | 58 | System.out.println("---------------------------------------------------------"); 59 | hashOperations.entries().forEach((m,n) ->{ 60 | System.out.println("key:" + m + "," + n); 61 | }); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /leyou-item/leyou-item-interface/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | leyou-item 7 | com.leyou.item 8 | 1.0.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | com.leyou.item.interface 13 | leyou-item-interface 14 | jar 15 | 16 | 17 | 18 | org.springframework 19 | spring-webmvc 20 | 21 | 22 | 23 | javax.persistence 24 | persistence-api 25 | 26 | 27 | 28 | com.leyou.common 29 | leyou-common 30 | 1.0.0-SNAPSHOT 31 | 32 | 33 | 34 | 35 | 36 | 37 | org.springframework.boot 38 | spring-boot-maven-plugin 39 | 40 | com.xx.webapps.api.main.WebappsApiBidMain 41 | 42 | 43 | 44 | 45 | repackage 46 | 47 | 48 | 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /leyou-item/leyou-item-interface/src/main/java/com/leyou/item/api/BrandApi.java: -------------------------------------------------------------------------------- 1 | package com.leyou.item.api; 2 | 3 | import com.leyou.item.pojo.Brand; 4 | import org.springframework.web.bind.annotation.GetMapping; 5 | import org.springframework.web.bind.annotation.RequestMapping; 6 | import org.springframework.web.bind.annotation.RequestParam; 7 | 8 | import java.util.List; 9 | 10 | /** 11 | * @Author: 98050 12 | * Time: 2018-10-11 20:04 13 | * Feature:品牌服务接口 14 | */ 15 | @RequestMapping("brand") 16 | public interface BrandApi { 17 | /** 18 | * 根据品牌id集合,查询品牌信息 19 | * @param ids 20 | * @return 21 | */ 22 | @GetMapping("list") 23 | List queryBrandByIds(@RequestParam("ids") List ids); 24 | } 25 | -------------------------------------------------------------------------------- /leyou-item/leyou-item-interface/src/main/java/com/leyou/item/api/CategoryApi.java: -------------------------------------------------------------------------------- 1 | package com.leyou.item.api; 2 | 3 | import com.leyou.item.pojo.Category; 4 | import org.springframework.http.ResponseEntity; 5 | import org.springframework.web.bind.annotation.GetMapping; 6 | import org.springframework.web.bind.annotation.RequestMapping; 7 | import org.springframework.web.bind.annotation.RequestParam; 8 | 9 | import java.util.List; 10 | 11 | /** 12 | * @Author: 98050 13 | * Time: 2018-10-11 20:05 14 | * Feature:商品分类服务接口 15 | */ 16 | @RequestMapping("category") 17 | public interface CategoryApi { 18 | 19 | /** 20 | * 根据id,查询分类名称 21 | * @param ids 22 | * @return 23 | */ 24 | @GetMapping("names") 25 | ResponseEntity> queryNameByIds(@RequestParam("ids")List ids); 26 | 27 | /** 28 | * 根据分类id集合查询分类名称 29 | * @param ids 30 | * @return 31 | */ 32 | @GetMapping("all") 33 | ResponseEntity> queryCategoryByIds(@RequestParam("ids")List ids); 34 | } 35 | -------------------------------------------------------------------------------- /leyou-item/leyou-item-interface/src/main/java/com/leyou/item/api/GoodsApi.java: -------------------------------------------------------------------------------- 1 | package com.leyou.item.api; 2 | 3 | import com.leyou.common.pojo.PageResult; 4 | import com.leyou.item.bo.SpuBo; 5 | import com.leyou.item.pojo.SeckillGoods; 6 | import com.leyou.item.pojo.Sku; 7 | import com.leyou.item.pojo.SpuDetail; 8 | import org.springframework.http.ResponseEntity; 9 | import org.springframework.web.bind.annotation.GetMapping; 10 | import org.springframework.web.bind.annotation.PathVariable; 11 | import org.springframework.web.bind.annotation.RequestMapping; 12 | import org.springframework.web.bind.annotation.RequestParam; 13 | 14 | import java.util.List; 15 | 16 | /** 17 | * @Author: 98050 18 | * Time: 2018-10-11 20:05 19 | * Feature:商品服务接口 20 | */ 21 | @RequestMapping("goods") 22 | public interface GoodsApi { 23 | 24 | /** 25 | * 分页查询 26 | * @param page 27 | * @param rows 28 | * @param sortBy 29 | * @param desc 30 | * @param key 31 | * @param saleable 32 | * @return 33 | */ 34 | @GetMapping("/spu/page") 35 | PageResult querySpuByPage( 36 | @RequestParam(value = "page", defaultValue = "1") Integer page, 37 | @RequestParam(value = "rows", defaultValue = "5") Integer rows, 38 | @RequestParam(value = "sortBy", required = false) String sortBy, 39 | @RequestParam(value = "desc", defaultValue = "false") Boolean desc, 40 | @RequestParam(value = "key", required = false) String key, 41 | @RequestParam(value = "saleable",defaultValue = "true") Boolean saleable); 42 | /** 43 | * 根据spu商品id查询详情 44 | * @param id 45 | * @return 46 | */ 47 | @GetMapping("/spu/detail/{id}") 48 | SpuDetail querySpuDetailBySpuId(@PathVariable("id") Long id); 49 | 50 | /** 51 | * 根据Spu的id查询其下所有的sku 52 | * @param id 53 | * @return 54 | */ 55 | @GetMapping("sku/list/{id}") 56 | List querySkuBySpuId(@PathVariable("id") Long id); 57 | 58 | /** 59 | * 根据id查询商品 60 | * @param id 61 | * @return 62 | */ 63 | @GetMapping("/spu/{id}") 64 | SpuBo queryGoodsById(@PathVariable("id") Long id); 65 | 66 | /** 67 | * 根据sku的id查询sku 68 | * @param id 69 | * @return 70 | */ 71 | @GetMapping("/sku/{id}") 72 | Sku querySkuById(@PathVariable("id") Long id); 73 | 74 | 75 | /** 76 | * 查询秒杀商品 77 | * @return 78 | */ 79 | @GetMapping("/seckill/list") 80 | ResponseEntity> querySeckillGoods(); 81 | } 82 | -------------------------------------------------------------------------------- /leyou-item/leyou-item-interface/src/main/java/com/leyou/item/api/SpecApi.java: -------------------------------------------------------------------------------- 1 | package com.leyou.item.api; 2 | 3 | import org.springframework.http.ResponseEntity; 4 | import org.springframework.web.bind.annotation.GetMapping; 5 | import org.springframework.web.bind.annotation.PathVariable; 6 | import org.springframework.web.bind.annotation.RequestMapping; 7 | import org.springframework.web.bind.annotation.RequestParam; 8 | 9 | /** 10 | * @Author: 98050 11 | * Time: 2018-10-11 20:05 12 | * Feature: 13 | */ 14 | @RequestMapping("spec") 15 | public interface SpecApi { 16 | /** 17 | * 查询商品分类对应的规格参数模板 18 | * @param id 19 | * @return 20 | */ 21 | @GetMapping("{id}") 22 | ResponseEntity querySpecificationByCategoryId(@PathVariable("id") Long id); 23 | } 24 | -------------------------------------------------------------------------------- /leyou-item/leyou-item-interface/src/main/java/com/leyou/item/api/SpuApi.java: -------------------------------------------------------------------------------- 1 | package com.leyou.item.api; 2 | 3 | import com.leyou.common.pojo.PageResult; 4 | import com.leyou.item.bo.SpuBo; 5 | import org.springframework.http.ResponseEntity; 6 | import org.springframework.web.bind.annotation.GetMapping; 7 | import org.springframework.web.bind.annotation.RequestMapping; 8 | import org.springframework.web.bind.annotation.RequestParam; 9 | 10 | /** 11 | * @Author: 98050 12 | * Time: 2018-10-11 20:06 13 | * Feature: 14 | */ 15 | @RequestMapping("spu") 16 | public interface SpuApi { 17 | /** 18 | * 分页查询 19 | * @param page 20 | * @param rows 21 | * @param desc 22 | * @param saleable 23 | * @return 24 | */ 25 | @GetMapping("page") 26 | ResponseEntity> querySpuByPage( 27 | @RequestParam(value = "page", defaultValue = "1") Integer page, 28 | @RequestParam(value = "rows", defaultValue = "5") Integer rows, 29 | @RequestParam(value = "desc", defaultValue = "false") Boolean desc, 30 | @RequestParam(value = "saleable",defaultValue = "true") Boolean saleable); 31 | } 32 | -------------------------------------------------------------------------------- /leyou-item/leyou-item-interface/src/main/java/com/leyou/item/bo/SeckillParameter.java: -------------------------------------------------------------------------------- 1 | package com.leyou.item.bo; 2 | 3 | 4 | /** 5 | * @Author: 98050 6 | * @Time: 2018-11-10 17:30 7 | * @Feature: 秒杀设置参数 8 | */ 9 | public class SeckillParameter { 10 | 11 | /** 12 | * 要秒杀的sku id 13 | */ 14 | private Long id; 15 | 16 | /** 17 | * 秒杀开始时间 18 | */ 19 | private String startTime; 20 | 21 | /** 22 | * 秒杀结束时间 23 | */ 24 | private String endTime; 25 | 26 | /** 27 | * 参与秒杀的商品数量 28 | */ 29 | private Integer count; 30 | 31 | /** 32 | * 折扣 33 | */ 34 | private double discount; 35 | 36 | public Long getId() { 37 | return id; 38 | } 39 | 40 | public void setId(Long id) { 41 | this.id = id; 42 | } 43 | 44 | public String getStartTime() { 45 | return startTime; 46 | } 47 | 48 | public void setStartTime(String startTime) { 49 | this.startTime = startTime; 50 | } 51 | 52 | public String getEndTime() { 53 | return endTime; 54 | } 55 | 56 | public void setEndTime(String endTime) { 57 | this.endTime = endTime; 58 | } 59 | 60 | public Integer getCount() { 61 | return count; 62 | } 63 | 64 | public void setCount(Integer count) { 65 | this.count = count; 66 | } 67 | 68 | public double getDiscount() { 69 | return discount; 70 | } 71 | 72 | public void setDiscount(double discount) { 73 | this.discount = discount; 74 | } 75 | 76 | @Override 77 | public String toString() { 78 | return "SeckillParameter{" + 79 | "id=" + id + 80 | ", startTime='" + startTime + '\'' + 81 | ", endTime='" + endTime + '\'' + 82 | ", count=" + count + 83 | ", discount=" + discount + 84 | '}'; 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /leyou-item/leyou-item-interface/src/main/java/com/leyou/item/bo/SpuBo.java: -------------------------------------------------------------------------------- 1 | package com.leyou.item.bo; 2 | 3 | import com.leyou.item.pojo.Spu; 4 | import com.leyou.item.pojo.SpuDetail; 5 | import com.leyou.item.pojo.Sku; 6 | 7 | import javax.persistence.Transient; 8 | import java.util.Date; 9 | import java.util.List; 10 | 11 | /** 12 | * @author: 98050 13 | * Time: 2018-08-14 22:10 14 | * Feature: 15 | */ 16 | public class SpuBo extends Spu { 17 | /** 18 | * 商品分类名称 19 | */ 20 | @Transient 21 | private String cname; 22 | /** 23 | * 品牌名称 24 | */ 25 | @Transient 26 | private String bname; 27 | 28 | /** 29 | * 商品详情 30 | */ 31 | @Transient 32 | private SpuDetail spuDetail; 33 | 34 | /** 35 | * sku列表 36 | */ 37 | @Transient 38 | private List skus; 39 | 40 | public String getCname() { 41 | return cname; 42 | } 43 | 44 | public void setCname(String cname) { 45 | this.cname = cname; 46 | } 47 | 48 | public String getBname() { 49 | return bname; 50 | } 51 | 52 | public void setBname(String bname) { 53 | this.bname = bname; 54 | } 55 | 56 | public SpuDetail getSpuDetail() { 57 | return spuDetail; 58 | } 59 | 60 | public void setSpuDetail(SpuDetail spuDetail) { 61 | this.spuDetail = spuDetail; 62 | } 63 | 64 | public List getSkus() { 65 | return skus; 66 | } 67 | 68 | public void setSkus(List skus) { 69 | this.skus = skus; 70 | } 71 | 72 | public SpuBo() { 73 | } 74 | 75 | public SpuBo(Long brandId, Long cid1, Long cid2, Long cid3, String title, String subTitle, Boolean saleable, Boolean valid, Date createTime, Date lastUpdateTime) { 76 | super(brandId, cid1, cid2, cid3, title, subTitle, saleable, valid, createTime, lastUpdateTime); 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /leyou-item/leyou-item-interface/src/main/java/com/leyou/item/pojo/Brand.java: -------------------------------------------------------------------------------- 1 | package com.leyou.item.pojo; 2 | 3 | import javax.persistence.GeneratedValue; 4 | import javax.persistence.GenerationType; 5 | import javax.persistence.Id; 6 | import javax.persistence.Table; 7 | import java.io.Serializable; 8 | 9 | @Table(name = "tb_brand") 10 | /** 11 | * @author:li 12 | * 13 | */ 14 | public class Brand implements Serializable { 15 | @Id 16 | @GeneratedValue(strategy = GenerationType.IDENTITY) 17 | private Long id; 18 | /** 19 | * 品牌名称 20 | */ 21 | private String name; 22 | /** 23 | * 品牌图片 24 | */ 25 | private String image; 26 | private Character letter; 27 | 28 | 29 | public Long getId() { 30 | return id; 31 | } 32 | 33 | public void setId(Long id) { 34 | this.id = id; 35 | } 36 | 37 | public String getName() { 38 | return name; 39 | } 40 | 41 | public void setName(String name) { 42 | this.name = name; 43 | } 44 | 45 | public String getImage() { 46 | return image; 47 | } 48 | 49 | public void setImage(String image) { 50 | this.image = image; 51 | } 52 | 53 | public Character getLetter() { 54 | return letter; 55 | } 56 | 57 | public void setLetter(Character letter) { 58 | this.letter = letter; 59 | } 60 | 61 | @Override 62 | public String toString() { 63 | return "Brand{" + 64 | "id=" + id + 65 | ", name='" + name + '\'' + 66 | ", image='" + image + '\'' + 67 | ", letter=" + letter + 68 | '}'; 69 | } 70 | } -------------------------------------------------------------------------------- /leyou-item/leyou-item-interface/src/main/java/com/leyou/item/pojo/Category.java: -------------------------------------------------------------------------------- 1 | package com.leyou.item.pojo; 2 | 3 | import javax.persistence.GeneratedValue; 4 | import javax.persistence.GenerationType; 5 | import javax.persistence.Id; 6 | import javax.persistence.Table; 7 | import java.io.Serializable; 8 | 9 | @Table(name="tb_category") 10 | /** 11 | * @author li 12 | * @time 2018/8/7 13 | * @feature: 商品分类对应的实体 14 | */ 15 | public class Category implements Serializable { 16 | @Id 17 | @GeneratedValue(strategy= GenerationType.IDENTITY) 18 | private Long id; 19 | private String name; 20 | private Long parentId; 21 | private Boolean isParent; 22 | /** 23 | * 排序指数,越小越靠前 24 | */ 25 | private Integer sort; 26 | 27 | public Long getId() { 28 | return id; 29 | } 30 | 31 | public void setId(Long id) { 32 | this.id = id; 33 | } 34 | 35 | public String getName() { 36 | return name; 37 | } 38 | 39 | public void setName(String name) { 40 | this.name = name; 41 | } 42 | 43 | public Long getParentId() { 44 | return parentId; 45 | } 46 | 47 | public void setParentId(Long parentId) { 48 | this.parentId = parentId; 49 | } 50 | 51 | public Boolean getIsParent() { 52 | return isParent; 53 | } 54 | 55 | public void setIsParent(Boolean parent) { 56 | isParent = parent; 57 | } 58 | 59 | public Integer getSort() { 60 | return sort; 61 | } 62 | 63 | public void setSort(Integer sort) { 64 | this.sort = sort; 65 | } 66 | 67 | @Override 68 | public String toString() { 69 | return "Category{" + 70 | "id=" + id + 71 | ", name='" + name + '\'' + 72 | ", parentId=" + parentId + 73 | ", isParent=" + isParent + 74 | ", sort=" + sort + 75 | '}'; 76 | } 77 | } -------------------------------------------------------------------------------- /leyou-item/leyou-item-interface/src/main/java/com/leyou/item/pojo/Specification.java: -------------------------------------------------------------------------------- 1 | package com.leyou.item.pojo; 2 | 3 | import javax.persistence.Id; 4 | import javax.persistence.Table; 5 | 6 | @Table(name = "tb_specification") 7 | public class Specification { 8 | 9 | @Id 10 | private Long categoryId; 11 | private String specifications; 12 | 13 | public Long getCategoryId() { 14 | return categoryId; 15 | } 16 | 17 | public void setCategoryId(Long categoryId) { 18 | this.categoryId = categoryId; 19 | } 20 | 21 | public String getSpecifications() { 22 | return specifications; 23 | } 24 | 25 | public void setSpecifications(String specifications) { 26 | this.specifications = specifications; 27 | } 28 | 29 | @Override 30 | public String toString() { 31 | return "Specification{" + 32 | "categoryId=" + categoryId + 33 | ", specifications='" + specifications + '\'' + 34 | '}'; 35 | } 36 | } -------------------------------------------------------------------------------- /leyou-item/leyou-item-interface/src/main/java/com/leyou/item/pojo/SpuDetail.java: -------------------------------------------------------------------------------- 1 | package com.leyou.item.pojo; 2 | 3 | import javax.persistence.Id; 4 | import javax.persistence.Table; 5 | 6 | /** 7 | * @author li 8 | */ 9 | @Table(name="tb_spu_detail") 10 | public class SpuDetail { 11 | @Id 12 | /** 13 | * 对应的SPU的id 14 | */ 15 | private Long spuId; 16 | /** 17 | * 商品描述 18 | */ 19 | private String description; 20 | /** 21 | * 商品特殊规格的名称及可选值模板 22 | */ 23 | private String specTemplate; 24 | /** 25 | * 商品的全局规格属性 26 | */ 27 | private String specifications; 28 | /** 29 | * 包装清单 30 | */ 31 | private String packingList; 32 | /** 33 | * 售后服务 34 | */ 35 | private String afterService; 36 | 37 | public Long getSpuId() { 38 | return spuId; 39 | } 40 | 41 | public void setSpuId(Long spuId) { 42 | this.spuId = spuId; 43 | } 44 | 45 | public String getDescription() { 46 | return description; 47 | } 48 | 49 | public void setDescription(String description) { 50 | this.description = description; 51 | } 52 | 53 | public String getSpecTemplate() { 54 | return specTemplate; 55 | } 56 | 57 | public void setSpecTemplate(String specTemplate) { 58 | this.specTemplate = specTemplate; 59 | } 60 | 61 | public String getSpecifications() { 62 | return specifications; 63 | } 64 | 65 | public void setSpecifications(String specifications) { 66 | this.specifications = specifications; 67 | } 68 | 69 | public String getPackingList() { 70 | return packingList; 71 | } 72 | 73 | public void setPackingList(String packingList) { 74 | this.packingList = packingList; 75 | } 76 | 77 | public String getAfterService() { 78 | return afterService; 79 | } 80 | 81 | public void setAfterService(String afterService) { 82 | this.afterService = afterService; 83 | } 84 | } -------------------------------------------------------------------------------- /leyou-item/leyou-item-interface/src/main/java/com/leyou/item/pojo/Stock.java: -------------------------------------------------------------------------------- 1 | package com.leyou.item.pojo; 2 | 3 | import javax.persistence.Id; 4 | import javax.persistence.Table; 5 | 6 | /** 7 | * @author li 8 | */ 9 | @Table(name = "tb_stock") 10 | public class Stock { 11 | 12 | @Id 13 | private Long skuId; 14 | /** 15 | * 秒杀可用库存 16 | */ 17 | private Integer seckillStock; 18 | /** 19 | * 已秒杀数量 20 | */ 21 | private Integer seckillTotal; 22 | /** 23 | * 正常库存 24 | */ 25 | private Long stock; 26 | 27 | public Long getSkuId() { 28 | return skuId; 29 | } 30 | 31 | public void setSkuId(Long skuId) { 32 | this.skuId = skuId; 33 | } 34 | 35 | public Integer getSeckillStock() { 36 | return seckillStock; 37 | } 38 | 39 | public void setSeckillStock(Integer seckillStock) { 40 | this.seckillStock = seckillStock; 41 | } 42 | 43 | public Integer getSeckillTotal() { 44 | return seckillTotal; 45 | } 46 | 47 | public void setSeckillTotal(Integer seckillTotal) { 48 | this.seckillTotal = seckillTotal; 49 | } 50 | 51 | public Long getStock() { 52 | return stock; 53 | } 54 | 55 | public void setStock(Long stock) { 56 | this.stock = stock; 57 | } 58 | 59 | @Override 60 | public String toString() { 61 | return "Stock{" + 62 | "skuId=" + skuId + 63 | ", seckillStock=" + seckillStock + 64 | ", seckillTotal=" + seckillTotal + 65 | ", stock=" + stock + 66 | '}'; 67 | } 68 | } -------------------------------------------------------------------------------- /leyou-item/leyou-item-service/src/main/java/com/leyou/LyItemService.java: -------------------------------------------------------------------------------- 1 | package com.leyou; 2 | 3 | /** 4 | * Author: 98050 5 | * Time: 2018-08-03 21:23 6 | * Feature: 7 | */ 8 | 9 | import org.springframework.boot.SpringApplication; 10 | import org.springframework.boot.autoconfigure.SpringBootApplication; 11 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; 12 | import org.springframework.transaction.annotation.EnableTransactionManagement; 13 | 14 | /** 15 | * @author li 16 | * @time 2018-08-03 21:23 17 | */ 18 | @SpringBootApplication 19 | @EnableDiscoveryClient 20 | @EnableTransactionManagement 21 | public class LyItemService { 22 | public static void main(String[] args) { 23 | SpringApplication.run(LyItemService.class,args); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /leyou-item/leyou-item-service/src/main/java/com/leyou/item/controller/SpecificationController.java: -------------------------------------------------------------------------------- 1 | package com.leyou.item.controller; 2 | 3 | import com.leyou.item.service.SpecificationService; 4 | import com.leyou.item.pojo.Specification; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.http.HttpStatus; 7 | import org.springframework.http.ResponseEntity; 8 | import org.springframework.web.bind.annotation.*; 9 | 10 | /** 11 | * @author li 12 | */ 13 | @RestController 14 | @RequestMapping("spec") 15 | public class SpecificationController { 16 | 17 | @Autowired 18 | private SpecificationService specificationService; 19 | 20 | /** 21 | * 查询商品分类对应的规格参数模板 22 | * @param id 23 | * @return 24 | */ 25 | @GetMapping("{id}") 26 | public ResponseEntity querySpecificationByCategoryId(@PathVariable("id") Long id){ 27 | Specification spec = this.specificationService.queryById(id); 28 | if (spec == null) { 29 | return new ResponseEntity<>(HttpStatus.NOT_FOUND); 30 | } 31 | return ResponseEntity.ok(spec.getSpecifications()); 32 | } 33 | 34 | /** 35 | * 保存一个规格参数模板 36 | * @param specification 37 | * @return 38 | */ 39 | @PostMapping 40 | public ResponseEntity saveSpecification(Specification specification){ 41 | this.specificationService.saveSpecification(specification); 42 | return ResponseEntity.status(HttpStatus.OK).build(); 43 | } 44 | 45 | /** 46 | * 修改一个规格参数模板 47 | * @param specification 48 | * @return 49 | */ 50 | @PutMapping 51 | public ResponseEntity updateSpecification(Specification specification){ 52 | this.specificationService.updateSpecification(specification); 53 | return ResponseEntity.status(HttpStatus.OK).build(); 54 | } 55 | 56 | @DeleteMapping("{id}") 57 | public ResponseEntity deleteSpecification(@PathVariable("id") Long id){ 58 | Specification specification = new Specification(); 59 | specification.setCategoryId(id); 60 | this.specificationService.deleteSpecification(specification); 61 | return ResponseEntity.status(HttpStatus.OK).build(); 62 | } 63 | } -------------------------------------------------------------------------------- /leyou-item/leyou-item-service/src/main/java/com/leyou/item/mapper/BrandMapper.java: -------------------------------------------------------------------------------- 1 | package com.leyou.item.mapper; 2 | 3 | import com.leyou.item.pojo.Brand; 4 | import org.apache.ibatis.annotations.*; 5 | import tk.mybatis.mapper.additional.idlist.SelectByIdListMapper; 6 | import tk.mybatis.mapper.common.Mapper; 7 | 8 | import java.util.List; 9 | 10 | /** 11 | * @Author: 98050 12 | * @Time: 2018-08-07 19:15 13 | * @Feature: 14 | */ 15 | @org.apache.ibatis.annotations.Mapper 16 | public interface BrandMapper extends Mapper, SelectByIdListMapper { 17 | /** 18 | * 新增商品分类和品牌中间表数据 19 | * @param cid 商品分类id 20 | * @param bid 品牌id 21 | * @return 22 | */ 23 | @Insert("INSERT INTO tb_category_brand (category_id, brand_id) VALUES (#{cid},#{bid})") 24 | void insertCategoryBrand(@Param("cid") Long cid, @Param("bid") Long bid); 25 | 26 | 27 | /** 28 | * 根据brand id删除中间表相关数据 29 | * @param bid 30 | */ 31 | @Delete("DELETE FROM tb_category_brand WHERE brand_id = #{bid}") 32 | void deleteByBrandIdInCategoryBrand(@Param("bid") Long bid); 33 | 34 | /** 35 | * 根据category id查询brand,左连接 36 | * @param cid 37 | * @return 38 | */ 39 | @Select("SELECT b.* FROM tb_brand b LEFT JOIN tb_category_brand cb ON b.id=cb.brand_id WHERE cb.category_id=#{cid}") 40 | List queryBrandByCategoryId(Long cid); 41 | } 42 | -------------------------------------------------------------------------------- /leyou-item/leyou-item-service/src/main/java/com/leyou/item/mapper/CategoryMapper.java: -------------------------------------------------------------------------------- 1 | package com.leyou.item.mapper; 2 | 3 | import com.leyou.item.pojo.Category; 4 | import org.apache.ibatis.annotations.Delete; 5 | import org.apache.ibatis.annotations.Param; 6 | import org.apache.ibatis.annotations.Select; 7 | import tk.mybatis.mapper.additional.idlist.SelectByIdListMapper; 8 | import tk.mybatis.mapper.common.Mapper; 9 | 10 | import java.util.List; 11 | 12 | /** 13 | * @Author: 98050 14 | * @Time: 2018-08-07 19:15 15 | * @Feature: 16 | */ 17 | @org.apache.ibatis.annotations.Mapper 18 | public interface CategoryMapper extends Mapper, SelectByIdListMapper { 19 | 20 | /** 21 | * 根据品牌id查询商品分类 22 | * @param bid 23 | * @return 24 | */ 25 | @Select("SELECT * FROM tb_category WHERE id IN (SELECT category_id FROM tb_category_brand WHERE brand_id = #{bid}) ") 26 | List queryByBrandId(@Param("bid") Long bid); 27 | 28 | 29 | /** 30 | * 根据category id删除中间表相关数据 31 | * @param cid 32 | */ 33 | @Delete("DELETE FROM tb_category_brand WHERE category_id = #{cid}") 34 | void deleteByCategoryIdInCategoryBrand(@Param("cid") Long cid); 35 | 36 | /** 37 | * 根据id查名字 38 | * @param id 39 | * @return 40 | */ 41 | @Select("SELECT name FROM tb_category WHERE id = #{id}") 42 | String queryNameById(Long id); 43 | 44 | /** 45 | * 查询最后一条数据 46 | * @return 47 | */ 48 | @Select("SELECT * FROM `tb_category` WHERE id = (SELECT MAX(id) FROM tb_category)") 49 | List selectLast(); 50 | } 51 | -------------------------------------------------------------------------------- /leyou-item/leyou-item-service/src/main/java/com/leyou/item/mapper/SeckillMapper.java: -------------------------------------------------------------------------------- 1 | package com.leyou.item.mapper; 2 | 3 | 4 | import com.leyou.item.pojo.SeckillGoods; 5 | import tk.mybatis.mapper.common.Mapper; 6 | 7 | /** 8 | * @Author: 98050 9 | * @Time: 2018-11-10 16:54 10 | * @Feature: 11 | */ 12 | @org.apache.ibatis.annotations.Mapper 13 | public interface SeckillMapper extends Mapper { 14 | } 15 | -------------------------------------------------------------------------------- /leyou-item/leyou-item-service/src/main/java/com/leyou/item/mapper/SkuMapper.java: -------------------------------------------------------------------------------- 1 | package com.leyou.item.mapper; 2 | 3 | import com.leyou.item.pojo.Sku; 4 | import org.apache.ibatis.annotations.Param; 5 | import org.apache.ibatis.annotations.Select; 6 | import tk.mybatis.mapper.common.Mapper; 7 | 8 | import java.util.List; 9 | 10 | /** 11 | * @Author: 98050 12 | * Time: 2018-08-17 15:59 13 | * Feature: 14 | */ 15 | @org.apache.ibatis.annotations.Mapper 16 | public interface SkuMapper extends Mapper { 17 | 18 | /** 19 | * 根据id查询sku信息 20 | * @param id 21 | * @return 22 | */ 23 | @Select("SELECT a.*,b.stock FROM tb_sku a,tb_stock b WHERE a.id=b.sku_id AND a.spu_id=#{id}") 24 | List queryById(@Param("id") Long id); 25 | 26 | 27 | } 28 | -------------------------------------------------------------------------------- /leyou-item/leyou-item-service/src/main/java/com/leyou/item/mapper/SpecificationMapper.java: -------------------------------------------------------------------------------- 1 | package com.leyou.item.mapper; 2 | 3 | import com.leyou.item.pojo.Specification; 4 | import tk.mybatis.mapper.common.Mapper; 5 | 6 | /** 7 | * @author li 8 | */ 9 | 10 | @org.apache.ibatis.annotations.Mapper 11 | public interface SpecificationMapper extends Mapper { 12 | } -------------------------------------------------------------------------------- /leyou-item/leyou-item-service/src/main/java/com/leyou/item/mapper/SpuDetailMapper.java: -------------------------------------------------------------------------------- 1 | package com.leyou.item.mapper; 2 | 3 | import com.leyou.item.pojo.SpuDetail; 4 | import tk.mybatis.mapper.common.Mapper; 5 | 6 | /** 7 | * @Author: 98050 8 | * Time: 2018-08-17 15:52 9 | * Feature: 10 | */ 11 | @org.apache.ibatis.annotations.Mapper 12 | public interface SpuDetailMapper extends Mapper { 13 | } 14 | -------------------------------------------------------------------------------- /leyou-item/leyou-item-service/src/main/java/com/leyou/item/mapper/SpuMapper.java: -------------------------------------------------------------------------------- 1 | package com.leyou.item.mapper; 2 | 3 | import com.leyou.item.pojo.Spu; 4 | import tk.mybatis.mapper.common.Mapper; 5 | 6 | /** 7 | * @Author: 98050 8 | * Time: 2018-08-14 22:14 9 | * Feature: 10 | */ 11 | @org.apache.ibatis.annotations.Mapper 12 | public interface SpuMapper extends Mapper { 13 | } 14 | -------------------------------------------------------------------------------- /leyou-item/leyou-item-service/src/main/java/com/leyou/item/mapper/StockMapper.java: -------------------------------------------------------------------------------- 1 | package com.leyou.item.mapper; 2 | 3 | import com.leyou.item.pojo.Stock; 4 | import tk.mybatis.mapper.additional.idlist.SelectByIdListMapper; 5 | import tk.mybatis.mapper.common.Mapper; 6 | 7 | /** 8 | * @Author: 98050 9 | * Time: 2018-08-17 16:10 10 | * Feature: 11 | */ 12 | @org.apache.ibatis.annotations.Mapper 13 | public interface StockMapper extends Mapper, SelectByIdListMapper { 14 | } 15 | -------------------------------------------------------------------------------- /leyou-item/leyou-item-service/src/main/java/com/leyou/item/service/BrandService.java: -------------------------------------------------------------------------------- 1 | package com.leyou.item.service; 2 | 3 | import com.leyou.common.pojo.PageResult; 4 | import com.leyou.item.pojo.Brand; 5 | import com.leyou.parameter.pojo.BrandQueryByPageParameter; 6 | 7 | import java.util.List; 8 | 9 | /** 10 | * @Author: 98050 11 | * Time: 2018-08-07 19:16 12 | * Feature: 分类的业务层 13 | */ 14 | 15 | public interface BrandService { 16 | 17 | /** 18 | * 分页查询 19 | * @param brandQueryByPageParameter 20 | * @return 21 | */ 22 | PageResult queryBrandByPage(BrandQueryByPageParameter brandQueryByPageParameter); 23 | 24 | /** 25 | * 新增brand,并且维护中间表 26 | * @param brand 27 | * @param cids 28 | */ 29 | void saveBrand(Brand brand, List cids); 30 | 31 | /** 32 | * 修改brand,并且维护中间表 33 | * @param brand 34 | * @param cids 35 | */ 36 | void updateBrand(Brand brand, List cids); 37 | 38 | /** 39 | * 删除brand,并且维护中间表 40 | * @param id 41 | */ 42 | void deleteBrand(Long id); 43 | 44 | 45 | /** 46 | * 根据brand Id 删除中间表中的数据 47 | * @param bid 48 | */ 49 | void deleteByBrandIdInCategoryBrand(Long bid); 50 | 51 | /** 52 | * 根据category id查询brand 53 | * @param cid 54 | * @return 55 | */ 56 | List queryBrandByCategoryId(Long cid); 57 | 58 | /** 59 | * 根据品牌id集合查询品牌信息 60 | * @param ids 61 | * @return 62 | */ 63 | List queryBrandByBrandIds(List ids); 64 | } 65 | -------------------------------------------------------------------------------- /leyou-item/leyou-item-service/src/main/java/com/leyou/item/service/CategoryService.java: -------------------------------------------------------------------------------- 1 | package com.leyou.item.service; 2 | 3 | import com.leyou.item.pojo.Category; 4 | import com.leyou.myexception.MyException; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | * @Author: 98050 10 | * Time: 2018-08-07 19:16 11 | * Feature: 分类的业务层 12 | */ 13 | public interface CategoryService { 14 | 15 | /** 16 | * 根据id查询分类 17 | * @param pid 18 | * @return 19 | */ 20 | List queryCategoryByPid(Long pid) throws MyException; 21 | 22 | /** 23 | * 根据brand id查询分类信息 24 | * @param bid 25 | * @return 26 | */ 27 | List queryByBrandId(Long bid); 28 | 29 | /** 30 | * 保存 31 | * @param category 32 | */ 33 | void saveCategory(Category category); 34 | 35 | /** 36 | * 更新 37 | * @param category 38 | */ 39 | void updateCategory(Category category); 40 | 41 | /** 42 | * 删除 43 | * @param id 44 | */ 45 | void deleteCategory(Long id); 46 | 47 | /** 48 | * 根据ids查询分类信息 49 | * @param asList 50 | * @return 51 | */ 52 | List queryNameByIds(List asList); 53 | 54 | /** 55 | * 查询当前数据库中最后一条数据 56 | * @return 57 | */ 58 | List queryLast(); 59 | 60 | /** 61 | * 根据分类id集合查询分类信息 62 | * @param ids 63 | * @return 64 | */ 65 | List queryCategoryByIds(List ids); 66 | 67 | /** 68 | * 根据cid3查询其所有层级分类 69 | * @param id 70 | * @return 71 | */ 72 | List queryAllCategoryLevelByCid3(Long id); 73 | } 74 | -------------------------------------------------------------------------------- /leyou-item/leyou-item-service/src/main/java/com/leyou/item/service/GoodsService.java: -------------------------------------------------------------------------------- 1 | package com.leyou.item.service; 2 | 3 | import com.leyou.common.pojo.PageResult; 4 | import com.leyou.item.bo.SeckillParameter; 5 | import com.leyou.item.pojo.SeckillGoods; 6 | import com.leyou.item.pojo.SpuDetail; 7 | import com.leyou.parameter.pojo.SpuQueryByPageParameter; 8 | import com.leyou.item.bo.SpuBo; 9 | import com.leyou.item.pojo.Sku; 10 | 11 | import java.text.ParseException; 12 | import java.util.List; 13 | 14 | /** 15 | * @Author: 98050 16 | * Time: 2018-08-14 22:14 17 | * Feature: 18 | */ 19 | public interface GoodsService { 20 | 21 | /** 22 | * 分页查询 23 | * @param spuQueryByPageParameter 24 | * @return 25 | */ 26 | PageResult querySpuByPageAndSort(SpuQueryByPageParameter spuQueryByPageParameter); 27 | 28 | /** 29 | * 保存商品 30 | * @param spu 31 | */ 32 | void saveGoods(SpuBo spu); 33 | 34 | /** 35 | * 根据id查询商品信息 36 | * @param id 37 | * @return 38 | */ 39 | SpuBo queryGoodsById(Long id); 40 | 41 | /** 42 | * 更新商品信息 43 | * @param spuBo 44 | */ 45 | void updateGoods(SpuBo spuBo); 46 | 47 | /** 48 | * 商品下架 49 | * @param id 50 | */ 51 | void goodsSoldOut(Long id); 52 | 53 | /** 54 | * 商品删除,单个多个二合一 55 | * @param id 56 | */ 57 | void deleteGoods(long id); 58 | 59 | /** 60 | * 根据spu商品id查询详细信息 61 | * @param id 62 | * @return 63 | */ 64 | SpuDetail querySpuDetailBySpuId(long id); 65 | 66 | /** 67 | * 根据Sku的id查询其下所有的sku 68 | * @param id 69 | * @return 70 | */ 71 | List querySkuBySpuId(Long id); 72 | 73 | /** 74 | * 发送校区到mq 75 | * @param id 76 | * @param type 77 | */ 78 | void sendMessage(Long id,String type); 79 | 80 | /** 81 | * 查询sku根据id 82 | * @param id 83 | * @return 84 | */ 85 | Sku querySkuById(Long id); 86 | 87 | /** 88 | * 查询秒杀商品 89 | * @return 90 | */ 91 | List querySeckillGoods(); 92 | 93 | /** 94 | * 添加秒杀商品 95 | * @param seckillParameter 96 | */ 97 | void addSeckillGoods(SeckillParameter seckillParameter) throws ParseException; 98 | } 99 | -------------------------------------------------------------------------------- /leyou-item/leyou-item-service/src/main/java/com/leyou/item/service/SpecificationService.java: -------------------------------------------------------------------------------- 1 | package com.leyou.item.service; 2 | 3 | import com.leyou.item.pojo.Specification; 4 | 5 | /** 6 | * @Author: 98050 7 | * Time: 2018-08-14 15:26 8 | * Feature: 9 | */ 10 | public interface SpecificationService { 11 | /** 12 | * 根据category id查询规格参数模板 13 | * @param id 14 | * @return 15 | */ 16 | Specification queryById(Long id); 17 | 18 | /** 19 | * 添加规格参数模板 20 | * @param specification 21 | */ 22 | void saveSpecification(Specification specification); 23 | 24 | /** 25 | * 修改规格参数模板 26 | * @param specification 27 | */ 28 | void updateSpecification(Specification specification); 29 | 30 | /** 31 | * 删除规格参数模板 32 | * @param specification 33 | */ 34 | void deleteSpecification(Specification specification); 35 | } 36 | -------------------------------------------------------------------------------- /leyou-item/leyou-item-service/src/main/java/com/leyou/item/service/impl/SpecificationServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.leyou.item.service.impl; 2 | 3 | import com.leyou.item.service.SpecificationService; 4 | import com.leyou.item.mapper.SpecificationMapper; 5 | import com.leyou.item.pojo.Specification; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.stereotype.Service; 8 | 9 | /** 10 | * @Author: 98050 11 | * Time: 2018-08-14 15:26 12 | * Feature: 13 | */ 14 | @Service 15 | public class SpecificationServiceImpl implements SpecificationService { 16 | 17 | @Autowired 18 | private SpecificationMapper specificationMapper; 19 | 20 | @Override 21 | public Specification queryById(Long id) { 22 | return this.specificationMapper.selectByPrimaryKey(id); 23 | } 24 | 25 | @Override 26 | public void saveSpecification(Specification specification) { 27 | this.specificationMapper.insert(specification); 28 | } 29 | 30 | @Override 31 | public void updateSpecification(Specification specification) { 32 | this.specificationMapper.updateByPrimaryKeySelective(specification); 33 | } 34 | 35 | @Override 36 | public void deleteSpecification(Specification specification) { 37 | this.specificationMapper.deleteByPrimaryKey(specification); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /leyou-item/leyou-item-service/src/main/resources/bootstrap.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | cloud: 3 | config: 4 | name: item 5 | profile: dev 6 | label: master 7 | uri: http://127.0.0.1:10011 8 | -------------------------------------------------------------------------------- /leyou-item/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | leyou 7 | com.leyou.parent 8 | 1.0.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | com.leyou.item 13 | leyou-item 14 | pom 15 | 16 | leyou-item-interface 17 | leyou-item-service 18 | 19 | 20 | -------------------------------------------------------------------------------- /leyou-order/leyou-order-interface/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | leyou-order 7 | com.leyou.order 8 | 1.0.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | com.leyou.order 13 | leyou-order-interface 14 | jar 15 | 16 | 17 | 18 | javax.persistence 19 | persistence-api 20 | 21 | 22 | 23 | org.hibernate.validator 24 | hibernate-validator 25 | 26 | 27 | 28 | org.springframework.boot 29 | spring-boot-starter-web 30 | 31 | 32 | com.leyou.authentication 33 | leyou-authentication-common 34 | 1.0.0-SNAPSHOT 35 | compile 36 | 37 | 38 | com.leyou.comments 39 | leyou-comments-interface 40 | 1.0.0-SNAPSHOT 41 | compile 42 | 43 | 44 | 45 | 46 | 47 | 48 | org.springframework.boot 49 | spring-boot-maven-plugin 50 | 51 | com.xx.webapps.api.main.WebappsApiBidMain 52 | 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /leyou-order/leyou-order-interface/src/main/java/com/leyou/order/api/OrderApi.java: -------------------------------------------------------------------------------- 1 | package com.leyou.order.api; 2 | 3 | import com.leyou.order.pojo.Order; 4 | import org.springframework.http.ResponseEntity; 5 | import org.springframework.web.bind.annotation.*; 6 | 7 | import javax.validation.Valid; 8 | import java.util.List; 9 | 10 | /** 11 | * @Author: 98050 12 | * @Time: 2018-11-12 15:13 13 | * @Feature: 订单服务接口 14 | */ 15 | @RequestMapping("order") 16 | public interface OrderApi { 17 | 18 | /** 19 | * 创建订单 20 | * @param seck 21 | * @param order 22 | * @return 23 | */ 24 | @PostMapping 25 | ResponseEntity> createOrder(@RequestParam("seck") String seck, @RequestBody @Valid Order order); 26 | 27 | 28 | /** 29 | * 修改订单状态 30 | * @param id 31 | * @param status 32 | * @return 33 | */ 34 | @PutMapping("{id}/{status}") 35 | ResponseEntity updateOrderStatus(@PathVariable("id") Long id,@PathVariable("status") Integer status); 36 | } 37 | -------------------------------------------------------------------------------- /leyou-order/leyou-order-interface/src/main/java/com/leyou/order/pojo/SeckillOrder.java: -------------------------------------------------------------------------------- 1 | package com.leyou.order.pojo; 2 | 3 | import javax.persistence.GeneratedValue; 4 | import javax.persistence.GenerationType; 5 | import javax.persistence.Id; 6 | import javax.persistence.Table; 7 | 8 | /** 9 | * @Author: 98050 10 | * @Time: 2018-11-15 15:42 11 | * @Feature: 秒杀订单 12 | */ 13 | @Table(name = "tb_seckill_order") 14 | public class SeckillOrder { 15 | 16 | @Id 17 | @GeneratedValue(strategy = GenerationType.IDENTITY) 18 | private Long id; 19 | 20 | private Long userId; 21 | 22 | private Long skuId; 23 | 24 | private Long orderId; 25 | 26 | public Long getId() { 27 | return id; 28 | } 29 | 30 | public void setId(Long id) { 31 | this.id = id; 32 | } 33 | 34 | public Long getUserId() { 35 | return userId; 36 | } 37 | 38 | public void setUserId(Long userId) { 39 | this.userId = userId; 40 | } 41 | 42 | public Long getSkuId() { 43 | return skuId; 44 | } 45 | 46 | public void setSkuId(Long skuId) { 47 | this.skuId = skuId; 48 | } 49 | 50 | public Long getOrderId() { 51 | return orderId; 52 | } 53 | 54 | public void setOrderId(Long orderId) { 55 | this.orderId = orderId; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /leyou-order/leyou-order-interface/src/main/java/com/leyou/order/vo/CommentsParameter.java: -------------------------------------------------------------------------------- 1 | package com.leyou.order.vo; 2 | 3 | import com.leyou.comments.pojo.Review; 4 | 5 | /** 6 | * @Author: 98050 7 | * @Time: 2018-12-12 11:43 8 | * @Feature: 新增评论消息对象 9 | */ 10 | public class CommentsParameter { 11 | 12 | private Long orderId; 13 | 14 | private Review review; 15 | 16 | public Long getOrderId() { 17 | return orderId; 18 | } 19 | 20 | public void setOrderId(Long orderId) { 21 | this.orderId = orderId; 22 | } 23 | 24 | public Review getReview() { 25 | return review; 26 | } 27 | 28 | public void setReview(Review review) { 29 | this.review = review; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /leyou-order/leyou-order-interface/src/main/java/com/leyou/order/vo/OrderStatusMessage.java: -------------------------------------------------------------------------------- 1 | package com.leyou.order.vo; 2 | 3 | /** 4 | * @Author: 98050 5 | * @Time: 2018-12-10 23:27 6 | * @Feature: 7 | */ 8 | public class OrderStatusMessage { 9 | /** 10 | * 订单id 11 | */ 12 | private Long orderId; 13 | 14 | /** 15 | * 用户id 16 | */ 17 | private Long userId; 18 | 19 | private String username; 20 | 21 | private Long spuId; 22 | 23 | /** 24 | * 消息类型:1(自动确认收货) 2(自动评论) 25 | */ 26 | private int type; 27 | 28 | 29 | public OrderStatusMessage() { 30 | } 31 | 32 | public OrderStatusMessage(Long orderId, Long userId, String username, Long spuId, int type) { 33 | this.orderId = orderId; 34 | this.userId = userId; 35 | this.username = username; 36 | this.spuId = spuId; 37 | this.type = type; 38 | } 39 | 40 | public String getUsername() { 41 | return username; 42 | } 43 | 44 | public void setUsername(String username) { 45 | this.username = username; 46 | } 47 | 48 | public Long getSpuId() { 49 | return spuId; 50 | } 51 | 52 | public void setSpuId(Long spuId) { 53 | this.spuId = spuId; 54 | } 55 | 56 | public Long getOrderId() { 57 | return orderId; 58 | } 59 | 60 | public void setOrderId(Long orderId) { 61 | this.orderId = orderId; 62 | } 63 | 64 | public Long getUserId() { 65 | return userId; 66 | } 67 | 68 | public void setUserId(Long userId) { 69 | this.userId = userId; 70 | } 71 | 72 | public int getType() { 73 | return type; 74 | } 75 | 76 | public void setType(int type) { 77 | this.type = type; 78 | } 79 | 80 | @Override 81 | public String toString() { 82 | return "OrderStatusMessage{" + 83 | "orderId=" + orderId + 84 | ", userId=" + userId + 85 | ", username='" + username + '\'' + 86 | ", spuId=" + spuId + 87 | ", type=" + type + 88 | '}'; 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /leyou-order/leyou-order-service/src/main/java/com/leyou/order/LyOrderApplication.java: -------------------------------------------------------------------------------- 1 | package com.leyou.order; 2 | 3 | 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; 7 | import org.springframework.cloud.openfeign.EnableFeignClients; 8 | import springfox.documentation.swagger2.annotations.EnableSwagger2; 9 | import tk.mybatis.spring.annotation.MapperScan; 10 | 11 | 12 | /** 13 | * @Author: 98050 14 | * @Time: 2018-10-27 11:36 15 | * @Feature: 订单服务启动器 16 | */ 17 | @SpringBootApplication 18 | @EnableDiscoveryClient 19 | @EnableFeignClients 20 | @EnableSwagger2 21 | @MapperScan(value = "com.leyou.order.mapper") 22 | public class LyOrderApplication { 23 | public static void main(String[] args) { 24 | SpringApplication.run(LyOrderApplication.class,args); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /leyou-order/leyou-order-service/src/main/java/com/leyou/order/client/GoodsClient.java: -------------------------------------------------------------------------------- 1 | package com.leyou.order.client; 2 | 3 | import com.leyou.item.api.GoodsApi; 4 | import org.springframework.cloud.openfeign.FeignClient; 5 | 6 | /** 7 | * @Author: 98050 8 | * Time: 2018-12-11 20:50 9 | * Feature:商品FeignClient 10 | */ 11 | @FeignClient(value = "item-service") 12 | public interface GoodsClient extends GoodsApi { 13 | } 14 | -------------------------------------------------------------------------------- /leyou-order/leyou-order-service/src/main/java/com/leyou/order/config/IdWorkerConfig.java: -------------------------------------------------------------------------------- 1 | package com.leyou.order.config; 2 | 3 | import com.leyou.order.properties.IdWorkerProperties; 4 | import com.leyou.utils.IdWorker; 5 | import org.springframework.boot.context.properties.EnableConfigurationProperties; 6 | import org.springframework.context.annotation.Bean; 7 | import org.springframework.context.annotation.Configuration; 8 | 9 | /** 10 | * @author: 98050 11 | * @create: 2018-10-27 12 | **/ 13 | @Configuration 14 | //@EnableConfigurationProperties(IdWorkerProperties.class) 15 | public class IdWorkerConfig { 16 | 17 | @Bean 18 | public IdWorker idWorker(IdWorkerProperties prop) { 19 | return new IdWorker(prop.getWorkerId(), prop.getDataCenterId()); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /leyou-order/leyou-order-service/src/main/java/com/leyou/order/config/PayConfig.java: -------------------------------------------------------------------------------- 1 | package com.leyou.order.config; 2 | 3 | import com.github.wxpay.sdk.WXPayConfig; 4 | import com.leyou.order.properties.PayProperties; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.boot.context.properties.EnableConfigurationProperties; 7 | import org.springframework.context.annotation.Configuration; 8 | 9 | import java.io.InputStream; 10 | 11 | /** 12 | * @author: 98050 13 | * @create: 2018-10-27 14 | **/ 15 | @Configuration 16 | //@EnableConfigurationProperties(PayProperties.class) 17 | public class PayConfig implements WXPayConfig { 18 | 19 | @Autowired 20 | private PayProperties payProperties; 21 | 22 | @Override 23 | public String getAppID() { 24 | return payProperties.getAppId(); 25 | } 26 | 27 | @Override 28 | public String getMchID() { 29 | return payProperties.getMchId(); 30 | } 31 | 32 | @Override 33 | public String getKey() { 34 | return payProperties.getKey(); 35 | } 36 | 37 | @Override 38 | public InputStream getCertStream() { 39 | return null; 40 | } 41 | 42 | @Override 43 | public int getHttpConnectTimeoutMs() { 44 | return payProperties.getConnectTimeoutMs(); 45 | } 46 | 47 | @Override 48 | public int getHttpReadTimeoutMs() { 49 | return payProperties.getReadTimeoutMs(); 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /leyou-order/leyou-order-service/src/main/java/com/leyou/order/config/SwaggerConfig.java: -------------------------------------------------------------------------------- 1 | package com.leyou.order.config; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | import springfox.documentation.builders.ApiInfoBuilder; 6 | import springfox.documentation.builders.PathSelectors; 7 | import springfox.documentation.builders.RequestHandlerSelectors; 8 | import springfox.documentation.service.ApiInfo; 9 | import springfox.documentation.spi.DocumentationType; 10 | import springfox.documentation.spring.web.plugins.Docket; 11 | import springfox.documentation.swagger2.annotations.EnableSwagger2; 12 | /** 13 | * @author 98050 14 | */ 15 | @Configuration 16 | public class SwaggerConfig { 17 | @Bean 18 | public Docket api() { 19 | return new Docket(DocumentationType.SWAGGER_2) 20 | .host("localhost:8089") 21 | .apiInfo(apiInfo()) 22 | .select() 23 | .apis(RequestHandlerSelectors.basePackage("com.leyou.order.controller")) 24 | .paths(PathSelectors.any()) 25 | .build(); 26 | } 27 | 28 | private ApiInfo apiInfo() { 29 | return new ApiInfoBuilder() 30 | .title("乐优商城订单系统") 31 | .description("乐优商城订单系统接口文档") 32 | .version("1.0") 33 | .build(); 34 | } 35 | } -------------------------------------------------------------------------------- /leyou-order/leyou-order-service/src/main/java/com/leyou/order/mapper/AddressMapper.java: -------------------------------------------------------------------------------- 1 | package com.leyou.order.mapper; 2 | 3 | import com.leyou.order.pojo.Address; 4 | import tk.mybatis.mapper.common.Mapper; 5 | 6 | /** 7 | * @Author: 98050 8 | * @Time: 2018-10-31 09:41 9 | * @Feature: 10 | */ 11 | public interface AddressMapper extends Mapper
{ 12 | } 13 | -------------------------------------------------------------------------------- /leyou-order/leyou-order-service/src/main/java/com/leyou/order/mapper/OrderDetailMapper.java: -------------------------------------------------------------------------------- 1 | package com.leyou.order.mapper; 2 | 3 | import com.leyou.order.pojo.OrderDetail; 4 | import tk.mybatis.mapper.common.Mapper; 5 | import tk.mybatis.mapper.common.special.InsertListMapper; 6 | 7 | import java.util.List; 8 | 9 | /** 10 | * @Author: 98050 11 | * @Time: 2018-10-27 16:33 12 | * @Feature: 13 | */ 14 | public interface OrderDetailMapper extends Mapper, InsertListMapper { 15 | 16 | } 17 | -------------------------------------------------------------------------------- /leyou-order/leyou-order-service/src/main/java/com/leyou/order/mapper/OrderMapper.java: -------------------------------------------------------------------------------- 1 | package com.leyou.order.mapper; 2 | 3 | import com.leyou.order.pojo.Order; 4 | import org.apache.ibatis.annotations.Param; 5 | import org.apache.ibatis.annotations.Select; 6 | import tk.mybatis.mapper.common.Mapper; 7 | 8 | import java.util.List; 9 | 10 | 11 | /** 12 | * @Author: 98050 13 | * @Time: 2018-10-27 16:31 14 | * @Feature: 15 | */ 16 | public interface OrderMapper extends Mapper { 17 | /** 18 | * 分页查询订单 19 | * @param userId 20 | * @param status 21 | * @return 22 | */ 23 | List queryOrderList(@Param("userId") Long userId, @Param("status") Integer status); 24 | } 25 | -------------------------------------------------------------------------------- /leyou-order/leyou-order-service/src/main/java/com/leyou/order/mapper/OrderStatusMapper.java: -------------------------------------------------------------------------------- 1 | package com.leyou.order.mapper; 2 | 3 | import com.leyou.order.pojo.OrderStatus; 4 | import tk.mybatis.mapper.common.Mapper; 5 | 6 | /** 7 | * @Author: 98050 8 | * @Time: 2018-10-27 16:31 9 | * @Feature: 10 | */ 11 | public interface OrderStatusMapper extends Mapper { 12 | } 13 | -------------------------------------------------------------------------------- /leyou-order/leyou-order-service/src/main/java/com/leyou/order/mapper/SeckillMapper.java: -------------------------------------------------------------------------------- 1 | package com.leyou.order.mapper; 2 | 3 | import com.leyou.item.pojo.SeckillGoods; 4 | import tk.mybatis.mapper.common.Mapper; 5 | 6 | /** 7 | * @Author: 98050 8 | * @Time: 2018-11-10 16:54 9 | * @Feature: 10 | */ 11 | public interface SeckillMapper extends Mapper { 12 | } 13 | -------------------------------------------------------------------------------- /leyou-order/leyou-order-service/src/main/java/com/leyou/order/mapper/SeckillOrderMapper.java: -------------------------------------------------------------------------------- 1 | package com.leyou.order.mapper; 2 | 3 | import com.leyou.order.pojo.SeckillOrder; 4 | import tk.mybatis.mapper.common.Mapper; 5 | 6 | /** 7 | * @Author: 98050 8 | * @Time: 2018-11-15 10:14 9 | * @Feature: 10 | */ 11 | public interface SeckillOrderMapper extends Mapper { 12 | } 13 | -------------------------------------------------------------------------------- /leyou-order/leyou-order-service/src/main/java/com/leyou/order/mapper/SkuMapper.java: -------------------------------------------------------------------------------- 1 | package com.leyou.order.mapper; 2 | 3 | import com.leyou.item.pojo.Sku; 4 | import tk.mybatis.mapper.common.Mapper; 5 | 6 | /** 7 | * @Author: 98050 8 | * @Time: 2018-11-15 21:12 9 | * @Feature: 10 | */ 11 | public interface SkuMapper extends Mapper { 12 | } 13 | -------------------------------------------------------------------------------- /leyou-order/leyou-order-service/src/main/java/com/leyou/order/mapper/StockMapper.java: -------------------------------------------------------------------------------- 1 | package com.leyou.order.mapper; 2 | 3 | import com.leyou.item.pojo.Stock; 4 | import org.apache.ibatis.annotations.Param; 5 | import org.apache.ibatis.annotations.Update; 6 | import tk.mybatis.mapper.common.Mapper; 7 | 8 | /** 9 | * @Author: 98050 10 | * @Time: 2018-11-10 17:58 11 | * @Feature: 12 | */ 13 | public interface StockMapper extends Mapper { 14 | 15 | 16 | /** 17 | * 更新对应商品的库存,且库存必须大于0,否则回滚。 18 | * @param skuId 19 | * @param num 20 | */ 21 | @Update("update tb_stock set stock = stock - #{num} where sku_id = #{skuId} and stock > 0") 22 | void reduceStock(@Param("skuId") Long skuId, @Param("num") Integer num); 23 | 24 | /** 25 | * 更新对应商品的秒杀库存,且库存必须大于0,否则回滚。 26 | * @param skuId 27 | * @param num 28 | */ 29 | @Update("update tb_stock set seckill_stock = seckill_stock - #{num} where sku_id = #{skuId} and seckill_stock > 0") 30 | void reduceSeckStock(@Param("skuId")Long skuId, @Param("num")Integer num); 31 | } 32 | -------------------------------------------------------------------------------- /leyou-order/leyou-order-service/src/main/java/com/leyou/order/properties/IdWorkerProperties.java: -------------------------------------------------------------------------------- 1 | package com.leyou.order.properties; 2 | 3 | import org.springframework.beans.factory.annotation.Value; 4 | import org.springframework.boot.context.properties.ConfigurationProperties; 5 | import org.springframework.cloud.context.config.annotation.RefreshScope; 6 | import org.springframework.context.annotation.Configuration; 7 | 8 | /** 9 | * @author: 98050 10 | * @create: 2018-10-27 11 | **/ 12 | //@ConfigurationProperties(prefix = "leyou.worker") 13 | @Configuration 14 | @RefreshScope 15 | public class IdWorkerProperties { 16 | 17 | /** 18 | * 当前机器id 19 | */ 20 | @Value("${leyou.worker.workerId}") 21 | private long workerId; 22 | 23 | /** 24 | * 序列号 25 | */ 26 | @Value("${leyou.worker.dataCenterId}") 27 | private long dataCenterId; 28 | 29 | public long getWorkerId() { 30 | return workerId; 31 | } 32 | 33 | public void setWorkerId(long workerId) { 34 | this.workerId = workerId; 35 | } 36 | 37 | public long getDataCenterId() { 38 | return dataCenterId; 39 | } 40 | 41 | public void setDataCenterId(long dataCenterId) { 42 | this.dataCenterId = dataCenterId; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /leyou-order/leyou-order-service/src/main/java/com/leyou/order/properties/JwtProperties.java: -------------------------------------------------------------------------------- 1 | package com.leyou.order.properties; 2 | 3 | import com.leyou.auth.utils.RsaUtils; 4 | import org.slf4j.Logger; 5 | import org.slf4j.LoggerFactory; 6 | import org.springframework.beans.factory.annotation.Value; 7 | import org.springframework.boot.context.properties.ConfigurationProperties; 8 | import org.springframework.cloud.context.config.annotation.RefreshScope; 9 | import org.springframework.context.annotation.Configuration; 10 | 11 | import javax.annotation.PostConstruct; 12 | import java.security.PublicKey; 13 | 14 | /** 15 | * @author: 9805 16 | * @create: 2018-10-27 17 | **/ 18 | //@ConfigurationProperties(prefix = "leyou.jwt") 19 | @Configuration 20 | @RefreshScope 21 | public class JwtProperties { 22 | 23 | /** 24 | * 公钥地址 25 | */ 26 | @Value("${leyou.jwt.pubKeyPath}") 27 | private String pubKeyPath; 28 | 29 | /** 30 | * 公钥 31 | */ 32 | private PublicKey publicKey; 33 | 34 | @Value("${leyou.jwt.cookieName}") 35 | private String cookieName; 36 | 37 | private static final Logger logger = LoggerFactory.getLogger(JwtProperties.class); 38 | 39 | @PostConstruct 40 | public void init(){ 41 | try { 42 | // 获取公钥和私钥 43 | this.publicKey = RsaUtils.getPublicKey(pubKeyPath); 44 | } catch (Exception e) { 45 | logger.error("初始化公钥失败!", e); 46 | throw new RuntimeException(); 47 | } 48 | } 49 | 50 | public String getPubKeyPath() { 51 | return pubKeyPath; 52 | } 53 | 54 | public void setPubKeyPath(String pubKeyPath) { 55 | this.pubKeyPath = pubKeyPath; 56 | } 57 | 58 | public PublicKey getPublicKey() { 59 | return publicKey; 60 | } 61 | 62 | public void setPublicKey(PublicKey publicKey) { 63 | this.publicKey = publicKey; 64 | } 65 | 66 | public String getCookieName() { 67 | return cookieName; 68 | } 69 | 70 | public void setCookieName(String cookieName) { 71 | this.cookieName = cookieName; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /leyou-order/leyou-order-service/src/main/java/com/leyou/order/properties/PayProperties.java: -------------------------------------------------------------------------------- 1 | package com.leyou.order.properties; 2 | 3 | import org.springframework.beans.factory.annotation.Value; 4 | import org.springframework.boot.context.properties.ConfigurationProperties; 5 | import org.springframework.cloud.context.config.annotation.RefreshScope; 6 | import org.springframework.context.annotation.Configuration; 7 | 8 | /** 9 | * @author: 98050 10 | * @create: 2018-10-27 11:38 11 | **/ 12 | //@ConfigurationProperties(prefix = "leyou.pay") 13 | @Configuration 14 | @RefreshScope 15 | public class PayProperties { 16 | 17 | /** 18 | * 公众账号ID 19 | */ 20 | @Value("${leyou.pay.appId}") 21 | private String appId; 22 | 23 | /** 24 | * 商户号 25 | */ 26 | @Value("${leyou.pay.mchId}") 27 | private String mchId; 28 | 29 | /** 30 | * 生成签名的密钥 31 | */ 32 | @Value("${leyou.pay.key}") 33 | private String key; 34 | 35 | /** 36 | * 连接超时时间 37 | */ 38 | @Value("${leyou.pay.connectTimeoutMs}") 39 | private int connectTimeoutMs; 40 | 41 | /** 42 | * 读取超时时间 43 | */ 44 | @Value("${leyou.pay.connectTimeoutMs}") 45 | private int readTimeoutMs; 46 | 47 | public String getAppId() { 48 | return appId; 49 | } 50 | 51 | public void setAppId(String appId) { 52 | this.appId = appId; 53 | } 54 | 55 | public String getMchId() { 56 | return mchId; 57 | } 58 | 59 | public void setMchId(String mchId) { 60 | this.mchId = mchId; 61 | } 62 | 63 | public String getKey() { 64 | return key; 65 | } 66 | 67 | public void setKey(String key) { 68 | this.key = key; 69 | } 70 | 71 | public int getConnectTimeoutMs() { 72 | return connectTimeoutMs; 73 | } 74 | 75 | public void setConnectTimeoutMs(int connectTimeoutMs) { 76 | this.connectTimeoutMs = connectTimeoutMs; 77 | } 78 | 79 | public int getReadTimeoutMs() { 80 | return readTimeoutMs; 81 | } 82 | 83 | public void setReadTimeoutMs(int readTimeoutMs) { 84 | this.readTimeoutMs = readTimeoutMs; 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /leyou-order/leyou-order-service/src/main/java/com/leyou/order/service/AddressService.java: -------------------------------------------------------------------------------- 1 | package com.leyou.order.service; 2 | 3 | import com.leyou.order.pojo.Address; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * @Author: 98050 9 | * @Time: 2018-10-31 09:43 10 | * @Feature: 11 | */ 12 | public interface AddressService { 13 | /** 14 | * 删除地址 15 | * @param addressId 16 | */ 17 | void deleteAddress(Long addressId); 18 | 19 | /** 20 | * 更新地址 21 | * @param address 22 | */ 23 | void updateAddressByUserId(Address address); 24 | 25 | /** 26 | * 查询地址 27 | * @return 28 | */ 29 | List
queryAddressByUserId(); 30 | 31 | /** 32 | * 新增收货地址 33 | * @param address 34 | */ 35 | void addAddressByUserId(Address address); 36 | 37 | /** 38 | * 根据地址id查询地址 39 | * @param addressId 40 | * @return 41 | */ 42 | Address queryAddressById(Long addressId); 43 | } 44 | -------------------------------------------------------------------------------- /leyou-order/leyou-order-service/src/main/java/com/leyou/order/service/OrderService.java: -------------------------------------------------------------------------------- 1 | package com.leyou.order.service; 2 | 3 | import com.leyou.common.pojo.PageResult; 4 | import com.leyou.order.pojo.Order; 5 | import com.leyou.order.pojo.OrderStatus; 6 | 7 | import java.util.List; 8 | 9 | /** 10 | * @Author: 98050 11 | * @Time: 2018-10-27 16:34 12 | * @Feature: 13 | */ 14 | public interface OrderService { 15 | /** 16 | * 订单创建 17 | * @param order 18 | * @return 19 | */ 20 | Long createOrder(Order order); 21 | 22 | /** 23 | * 根据订单号查询订单 24 | * @param id 25 | * @return 26 | */ 27 | Order queryOrderById(Long id); 28 | 29 | /** 30 | * 分页查询用户订单 31 | * @param page 32 | * @param rows 33 | * @param status 34 | * @return 35 | */ 36 | PageResult queryUserOrderList(Integer page, Integer rows, Integer status); 37 | 38 | /** 39 | * 更改订单状态 40 | * @param id 41 | * @param status 42 | * @return 43 | */ 44 | Boolean updateOrderStatus(Long id, Integer status); 45 | 46 | /** 47 | * 根据订单号查询商品id 48 | * @param id 49 | * @return 50 | */ 51 | List querySkuIdByOrderId(Long id); 52 | 53 | /** 54 | * 根据订单号查询订单状态 55 | * @param id 56 | * @return 57 | */ 58 | OrderStatus queryOrderStatusById(Long id); 59 | 60 | /** 61 | * 查询库存 62 | * @param order 63 | * @return 64 | */ 65 | List queryStock(Order order); 66 | } 67 | -------------------------------------------------------------------------------- /leyou-order/leyou-order-service/src/main/java/com/leyou/order/service/OrderStatusService.java: -------------------------------------------------------------------------------- 1 | package com.leyou.order.service; 2 | 3 | import com.leyou.order.vo.CommentsParameter; 4 | import com.leyou.order.vo.OrderStatusMessage; 5 | 6 | /** 7 | * @Author: 98050 8 | * @Time: 2018-12-10 23:17 9 | * @Feature: 发送延时消息和评论消息 10 | */ 11 | public interface OrderStatusService { 12 | 13 | 14 | /** 15 | * 发送消息到延时队列 16 | * @param orderStatusMessage 17 | */ 18 | void sendMessage(OrderStatusMessage orderStatusMessage); 19 | 20 | /** 21 | * 发送评论信息 22 | * @param commentsParameter 23 | */ 24 | void sendComments(CommentsParameter commentsParameter); 25 | } 26 | -------------------------------------------------------------------------------- /leyou-order/leyou-order-service/src/main/java/com/leyou/order/service/impl/OrderStatusServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.leyou.order.service.impl; 2 | 3 | import com.leyou.order.service.OrderStatusService; 4 | import com.leyou.order.vo.CommentsParameter; 5 | import com.leyou.order.vo.OrderStatusMessage; 6 | import com.leyou.utils.JsonUtils; 7 | import org.slf4j.Logger; 8 | import org.slf4j.LoggerFactory; 9 | import org.springframework.amqp.core.*; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.stereotype.Service; 12 | 13 | /** 14 | * @Author: 98050 15 | * @Time: 2018-12-10 23:24 16 | * @Feature: 17 | */ 18 | @Service 19 | public class OrderStatusServiceImpl implements OrderStatusService { 20 | 21 | @Autowired 22 | private AmqpTemplate amqpTemplate; 23 | 24 | private static final Logger LOGGER = LoggerFactory.getLogger(OrderStatusServiceImpl.class); 25 | 26 | 27 | /** 28 | * 发送延时消息到延时队列中 29 | * @param orderStatusMessage 30 | */ 31 | @Override 32 | public void sendMessage(OrderStatusMessage orderStatusMessage) { 33 | String json = JsonUtils.serialize(orderStatusMessage); 34 | MessageProperties properties; 35 | if (orderStatusMessage.getType() == 1){ 36 | // 持久性 non-persistent (1) or persistent (2) 37 | properties = MessagePropertiesBuilder.newInstance().setExpiration("60000").setDeliveryMode(MessageDeliveryMode.PERSISTENT).build(); 38 | }else { 39 | properties = MessagePropertiesBuilder.newInstance().setExpiration("90000").setDeliveryMode(MessageDeliveryMode.PERSISTENT).build(); 40 | } 41 | 42 | Message message = MessageBuilder.withBody(json.getBytes()).andProperties(properties).build(); 43 | //发送消息 44 | try { 45 | this.amqpTemplate.convertAndSend("", "leyou.order.delay.queue", message); 46 | }catch (Exception e){ 47 | LOGGER.error("延时消息发送异常,订单号为:id:{},用户id为:{}",orderStatusMessage.getOrderId(),orderStatusMessage.getUserId(),e); 48 | } 49 | } 50 | 51 | /** 52 | * 将评论发送到消息队列中 53 | * @param commentsParameter 54 | */ 55 | @Override 56 | public void sendComments(CommentsParameter commentsParameter) { 57 | String json = JsonUtils.serialize(commentsParameter); 58 | try { 59 | this.amqpTemplate.convertAndSend("leyou.comments.exchange","user.comments", json); 60 | }catch (Exception e){ 61 | LOGGER.error("评论消息发送异常,订单id:{}",commentsParameter.getOrderId(),e); 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /leyou-order/leyou-order-service/src/main/java/com/leyou/order/utils/PayState.java: -------------------------------------------------------------------------------- 1 | package com.leyou.order.utils; 2 | 3 | /** 4 | * @author: HuYi.Zhang 5 | * @create: 2018-06-07 17:44 6 | **/ 7 | public enum PayState { 8 | /** 9 | * 未支付0 10 | * 支付成功1 11 | * 支付失败2 12 | */ 13 | NOT_PAY(0),SUCCESS(1),FAIL(2); 14 | 15 | PayState(int value) { 16 | this.value = value; 17 | } 18 | 19 | int value; 20 | 21 | public int getValue() { 22 | return value; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /leyou-order/leyou-order-service/src/main/resources/bootstrap.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | cloud: 3 | config: 4 | name: order 5 | profile: dev 6 | label: master 7 | uri: http://127.0.0.1:10011 8 | -------------------------------------------------------------------------------- /leyou-order/leyou-order-service/src/main/resources/mapper/OrderMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 18 | -------------------------------------------------------------------------------- /leyou-order/leyou-order-service/src/test/java/com/leyou/rabbitmq/test/RabbitMQTest.java: -------------------------------------------------------------------------------- 1 | //package com.leyou.rabbitmq.test; 2 | // 3 | //import com.leyou.order.LyOrderApplication; 4 | //import com.leyou.order.service.OrderStatusService; 5 | //import com.leyou.order.vo.OrderStatusMessage; 6 | //import org.junit.Test; 7 | //import org.junit.runner.RunWith; 8 | //import org.springframework.beans.factory.annotation.Autowired; 9 | //import org.springframework.boot.test.context.SpringBootTest; 10 | //import org.springframework.test.context.junit4.SpringRunner; 11 | // 12 | ///** 13 | // * @Author: 98050 14 | // * @Time: 2018-12-11 10:54 15 | // * @Feature: 16 | // */ 17 | //@RunWith(SpringRunner.class) 18 | //@SpringBootTest(classes = LyOrderApplication.class) 19 | //public class RabbitMQTest { 20 | // 21 | // @Autowired 22 | // private OrderStatusService orderStatusService; 23 | // 24 | // @Test 25 | // public void sendMessage(){ 26 | // OrderStatusMessage orderStatusMessage = new OrderStatusMessage(); 27 | // orderStatusMessage.setOrderId(123L); 28 | // orderStatusMessage.setType(1); 29 | // orderStatusMessage.setUserId(111L); 30 | // orderStatusService.sendMessage(orderStatusMessage); 31 | // } 32 | //} 33 | -------------------------------------------------------------------------------- /leyou-order/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | leyou 7 | com.leyou.parent 8 | 1.0.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | com.leyou.order 13 | leyou-order 14 | pom 15 | 16 | leyou-order-service 17 | leyou-order-interface 18 | 19 | 20 | -------------------------------------------------------------------------------- /leyou-registry/src/main/java/com/leyou/LyRegistry.java: -------------------------------------------------------------------------------- 1 | package com.leyou; 2 | 3 | /** 4 | * Author: 98050 5 | * Time: 2018-08-03 20:29 6 | * Feature: 7 | */ 8 | 9 | import org.springframework.boot.SpringApplication; 10 | import org.springframework.boot.autoconfigure.SpringBootApplication; 11 | import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer; 12 | 13 | /** 14 | * @author li 15 | * @time 2018-08-03 20:29 16 | */ 17 | @SpringBootApplication 18 | @EnableEurekaServer 19 | public class LyRegistry { 20 | public static void main(String[] args){ 21 | SpringApplication.run(LyRegistry.class,args); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /leyou-registry/src/main/resources/bootstrap.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | cloud: 3 | config: 4 | name: registry 5 | profile: dev 6 | label: master 7 | uri: http://127.0.0.1:10011 -------------------------------------------------------------------------------- /leyou-search/src/main/java/com/leyou/LySearchService.java: -------------------------------------------------------------------------------- 1 | package com.leyou; 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.cloud.client.discovery.EnableDiscoveryClient; 7 | import org.springframework.cloud.openfeign.EnableFeignClients; 8 | 9 | /** 10 | * @Author: 98050 11 | * Time: 2018-10-11 16:43 12 | * Feature: 启动器,开启fegin功能 13 | */ 14 | @SpringBootApplication 15 | @EnableDiscoveryClient 16 | @EnableFeignClients 17 | public class LySearchService { 18 | public static void main(String[] args) { 19 | SpringApplication.run(LySearchService.class,args); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /leyou-search/src/main/java/com/leyou/bo/SearchRequest.java: -------------------------------------------------------------------------------- 1 | package com.leyou.bo; 2 | 3 | import java.util.Map; 4 | 5 | /** 6 | * @Author: 98050 7 | * Time: 2018-10-12 20:08 8 | * Feature: 搜索业务对象 9 | */ 10 | public class SearchRequest { 11 | 12 | /** 13 | * 搜索条件 14 | */ 15 | private String key; 16 | 17 | /** 18 | * 当前页 19 | */ 20 | private Integer page; 21 | 22 | /** 23 | * 排序字段 24 | */ 25 | private String sortBy; 26 | 27 | /** 28 | * 是否降序 29 | */ 30 | private Boolean descending; 31 | 32 | /** 33 | * 过滤字段 34 | */ 35 | private Map filter; 36 | 37 | /** 38 | * 每页大小,不从页面接收,而是固定大小 39 | */ 40 | private static final Integer DEFAULT_SIZE = 20; 41 | 42 | /** 43 | * 默认页 44 | */ 45 | private static final Integer DEFAULT_PAGE = 1; 46 | 47 | 48 | public Map getFilter() { 49 | return filter; 50 | } 51 | 52 | public void setFilter(Map filter) { 53 | this.filter = filter; 54 | } 55 | 56 | 57 | public String getKey() { 58 | return key; 59 | } 60 | 61 | public void setKey(String key) { 62 | this.key = key; 63 | } 64 | 65 | public Integer getPage() { 66 | if (page == null){ 67 | return DEFAULT_PAGE; 68 | } 69 | /** 70 | * 获取页码时做一些校验,不能小于1 71 | */ 72 | return Math.max(DEFAULT_PAGE,page); 73 | } 74 | 75 | public void setPage(Integer page) { 76 | this.page = page; 77 | } 78 | 79 | public Integer getDefaultSize() { 80 | return DEFAULT_SIZE; 81 | } 82 | 83 | public String getSortBy() { 84 | return sortBy; 85 | } 86 | 87 | public void setSortBy(String sortBy) { 88 | this.sortBy = sortBy; 89 | } 90 | 91 | public Boolean getDescending() { 92 | return descending; 93 | } 94 | 95 | public void setDescending(Boolean descending) { 96 | this.descending = descending; 97 | } 98 | 99 | @Override 100 | public String toString() { 101 | return "SearchRequest{" + 102 | "key='" + key + '\'' + 103 | ", page=" + page + 104 | ", sortBy='" + sortBy + '\'' + 105 | ", descending=" + descending + 106 | ", filter=" + filter + 107 | '}'; 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /leyou-search/src/main/java/com/leyou/client/BrandClient.java: -------------------------------------------------------------------------------- 1 | package com.leyou.client; 2 | 3 | import com.leyou.item.api.BrandApi; 4 | import org.springframework.cloud.openfeign.FeignClient; 5 | 6 | /** 7 | * @Author: 98050 8 | * Time: 2018-10-11 20:49 9 | * Feature:品牌FeignClient 10 | */ 11 | @FeignClient(value = "item-service") 12 | public interface BrandClient extends BrandApi { 13 | } 14 | -------------------------------------------------------------------------------- /leyou-search/src/main/java/com/leyou/client/CategoryClient.java: -------------------------------------------------------------------------------- 1 | package com.leyou.client; 2 | 3 | import com.leyou.item.api.CategoryApi; 4 | import org.springframework.cloud.openfeign.FeignClient; 5 | 6 | /** 7 | * @Author: 98050 8 | * Time: 2018-10-11 20:49 9 | * Feature:商品分类FeignClient 10 | */ 11 | @FeignClient(value = "item-service") 12 | public interface CategoryClient extends CategoryApi { 13 | } 14 | -------------------------------------------------------------------------------- /leyou-search/src/main/java/com/leyou/client/GoodsClient.java: -------------------------------------------------------------------------------- 1 | package com.leyou.client; 2 | 3 | import com.leyou.item.api.GoodsApi; 4 | import org.springframework.cloud.openfeign.FeignClient; 5 | 6 | /** 7 | * @Author: 98050 8 | * Time: 2018-10-11 20:50 9 | * Feature:商品FeignClient 10 | */ 11 | @FeignClient(value = "item-service") 12 | public interface GoodsClient extends GoodsApi { 13 | } 14 | -------------------------------------------------------------------------------- /leyou-search/src/main/java/com/leyou/client/SpecClient.java: -------------------------------------------------------------------------------- 1 | package com.leyou.client; 2 | 3 | import com.leyou.item.api.SpecApi; 4 | import org.springframework.cloud.openfeign.FeignClient; 5 | 6 | /** 7 | * @Author: 98050 8 | * Time: 2018-10-11 20:50 9 | * Feature:特有属性FeignClient 10 | */ 11 | @FeignClient(value = "item-service") 12 | public interface SpecClient extends SpecApi { 13 | } 14 | -------------------------------------------------------------------------------- /leyou-search/src/main/java/com/leyou/client/SpuClient.java: -------------------------------------------------------------------------------- 1 | package com.leyou.client; 2 | 3 | import com.leyou.item.api.SpuApi; 4 | import org.springframework.cloud.openfeign.FeignClient; 5 | 6 | /** 7 | * @Author: 98050 8 | * Time: 2018-10-11 20:50 9 | * Feature:spu FeignClient 10 | */ 11 | @FeignClient(value = "item-service") 12 | public interface SpuClient extends SpuApi { 13 | } 14 | -------------------------------------------------------------------------------- /leyou-search/src/main/java/com/leyou/listener/GoodsListener.java: -------------------------------------------------------------------------------- 1 | package com.leyou.listener; 2 | 3 | import com.leyou.client.GoodsClient; 4 | import com.leyou.item.bo.SpuBo; 5 | import com.leyou.service.SearchService; 6 | import org.springframework.amqp.core.ExchangeTypes; 7 | import org.springframework.amqp.rabbit.annotation.Exchange; 8 | import org.springframework.amqp.rabbit.annotation.Queue; 9 | import org.springframework.amqp.rabbit.annotation.QueueBinding; 10 | import org.springframework.amqp.rabbit.annotation.RabbitListener; 11 | import org.springframework.beans.factory.annotation.Autowired; 12 | import org.springframework.stereotype.Component; 13 | 14 | /** 15 | * @Author: 98050 16 | * @Time: 2018-10-21 12:57 17 | * @Feature: mq监听器,消费者 18 | */ 19 | @Component 20 | public class GoodsListener { 21 | 22 | @Autowired 23 | private SearchService searchService; 24 | 25 | /** 26 | * 处理insert和update的消息 27 | * @param id 28 | * @throws Exception 29 | */ 30 | @RabbitListener(bindings = @QueueBinding( 31 | value = @Queue(value = "leyou.create.index.queue",durable = "true"), //队列持久化 32 | exchange = @Exchange( 33 | value = "leyou.item.exchange", 34 | ignoreDeclarationExceptions = "true", 35 | type = ExchangeTypes.TOPIC 36 | ), 37 | key = {"item.insert","item.update"} 38 | )) 39 | public void listenCreate(Long id) throws Exception{ 40 | if (id == null){ 41 | return; 42 | } 43 | //创建或更新索引 44 | this.searchService.createIndex(id); 45 | } 46 | 47 | @RabbitListener(bindings = @QueueBinding( 48 | value = @Queue(value = "leyou.delete.index.queue",durable = "true"), //队列持久化 49 | exchange = @Exchange( 50 | value = "leyou.item.exchange", 51 | ignoreDeclarationExceptions = "true", 52 | type = ExchangeTypes.TOPIC 53 | ), 54 | key = {"item.delete"} 55 | )) 56 | public void listenDelete(Long id){ 57 | if (id == null){ 58 | return; 59 | } 60 | 61 | //删除索引 62 | this.searchService.deleteIndex(id); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /leyou-search/src/main/java/com/leyou/repository/GoodsRepository.java: -------------------------------------------------------------------------------- 1 | package com.leyou.repository; 2 | 3 | import com.leyou.pojo.Goods; 4 | import org.springframework.data.elasticsearch.repository.ElasticsearchRepository; 5 | 6 | /** 7 | * @Author: 98050 8 | * Time: 2018-10-11 22:17 9 | * Feature:文档操作 10 | */ 11 | public interface GoodsRepository extends ElasticsearchRepository { 12 | } 13 | -------------------------------------------------------------------------------- /leyou-search/src/main/java/com/leyou/service/SearchService.java: -------------------------------------------------------------------------------- 1 | package com.leyou.service; 2 | 3 | import com.leyou.bo.SearchRequest; 4 | import com.leyou.item.pojo.Spu; 5 | import com.leyou.pojo.Goods; 6 | import com.leyou.vo.SearchResult; 7 | 8 | import java.io.IOException; 9 | 10 | /** 11 | * @Author: 98050 12 | * Time: 2018-10-17 19:33 13 | * Feature: 搜索功能 14 | */ 15 | public interface SearchService { 16 | 17 | /** 18 | * 查询商品信息 19 | * @param spu 20 | * @return 21 | * @throws IOException 22 | */ 23 | Goods buildGoods(Spu spu) throws IOException; 24 | 25 | /** 26 | * 商品搜索 27 | * @param searchRequest 28 | * @return 29 | */ 30 | SearchResult search(SearchRequest searchRequest); 31 | 32 | 33 | /** 34 | * 根据goods的id创建相应的索引 35 | * @param id 36 | * @throws IOException 37 | */ 38 | void createIndex(Long id) throws IOException; 39 | 40 | /** 41 | * 根据goods的id删除相应的索引 42 | * @param id 43 | */ 44 | void deleteIndex(Long id); 45 | } 46 | -------------------------------------------------------------------------------- /leyou-search/src/main/java/com/leyou/vo/SearchResult.java: -------------------------------------------------------------------------------- 1 | package com.leyou.vo; 2 | 3 | import com.leyou.common.pojo.PageResult; 4 | import com.leyou.item.pojo.Category; 5 | import com.leyou.item.pojo.Brand; 6 | 7 | import java.util.List; 8 | import java.util.Map; 9 | 10 | /** 11 | * @Author: 98050 12 | * Time: 2018-10-12 21:06 13 | * Feature: 搜索结果存储对象 14 | */ 15 | public class SearchResult extends PageResult { 16 | 17 | /** 18 | * 分类的集合 19 | */ 20 | private List categories; 21 | 22 | /** 23 | * 品牌的集合 24 | */ 25 | private List brands; 26 | 27 | /** 28 | * 规格参数的过滤条件 29 | */ 30 | private List> specs; 31 | 32 | public List getCategories() { 33 | return categories; 34 | } 35 | 36 | public void setCategories(List categories) { 37 | this.categories = categories; 38 | } 39 | 40 | public List getBrands() { 41 | return brands; 42 | } 43 | 44 | public void setBrands(List brands) { 45 | this.brands = brands; 46 | } 47 | 48 | public List> getSpecs() { 49 | return specs; 50 | } 51 | 52 | public void setSpecs(List> specs) { 53 | this.specs = specs; 54 | } 55 | 56 | public SearchResult(List categories, List brands, List> specs){ 57 | this.categories = categories; 58 | this.brands = brands; 59 | this.specs = specs; 60 | } 61 | 62 | public SearchResult(Long total, List item,List categories, List brands, List> specs){ 63 | super(total,item); 64 | this.categories = categories; 65 | this.brands = brands; 66 | this.specs = specs; 67 | } 68 | 69 | public SearchResult(Long total,Long totalPage, List item,List categories, List brands){ 70 | super(total,totalPage,item); 71 | this.categories = categories; 72 | this.brands = brands; 73 | } 74 | 75 | public SearchResult(Long total,Long totalPage, List item,List categories, 76 | List brands, List> specs){ 77 | super(total,totalPage,item); 78 | this.categories = categories; 79 | this.brands = brands; 80 | this.specs = specs; 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /leyou-search/src/main/resources/bootstrap.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | cloud: 3 | config: 4 | name: search 5 | profile: dev 6 | label: master 7 | uri: http://127.0.0.1:10011 8 | -------------------------------------------------------------------------------- /leyou-search/src/test/java/com/leyou/client/CategoryClientTest.java: -------------------------------------------------------------------------------- 1 | //package com.leyou.client; 2 | // 3 | //import com.leyou.LySearchService; 4 | //import org.junit.Test; 5 | //import org.junit.runner.RunWith; 6 | //import org.springframework.beans.factory.annotation.Autowired; 7 | //import org.springframework.boot.test.context.SpringBootTest; 8 | //import org.springframework.test.context.junit4.SpringRunner; 9 | // 10 | //import java.util.Arrays; 11 | //import java.util.List; 12 | // 13 | ///** 14 | // * Author: 98050 15 | // * Time: 2018-10-11 21:15 16 | // * Feature: 17 | // */ 18 | //@RunWith(SpringRunner.class) 19 | //@SpringBootTest(classes = LySearchService.class) 20 | //public class CategoryClientTest { 21 | // 22 | // @Autowired 23 | // private CategoryClient categoryClient; 24 | // 25 | // @Test 26 | // public void testQueryCategories() { 27 | // List names = this.categoryClient.queryNameByIds(Arrays.asList(1L, 2L, 3L)).getBody(); 28 | // names.forEach(System.out::println); 29 | // } 30 | //} -------------------------------------------------------------------------------- /leyou-secskill/leyou-seckill-interface/src/main/java/com/leyou/seckill/vo/SeckillMessage.java: -------------------------------------------------------------------------------- 1 | package com.leyou.seckill.vo; 2 | 3 | import com.leyou.auth.entity.UserInfo; 4 | import com.leyou.item.pojo.SeckillGoods; 5 | 6 | /** 7 | * @Author: 98050 8 | * @Time: 2018-11-15 20:19 9 | * @Feature: 秒杀信息 10 | */ 11 | public class SeckillMessage { 12 | /** 13 | * 用户信息 14 | */ 15 | private UserInfo userInfo; 16 | 17 | /** 18 | * 秒杀商品 19 | */ 20 | private SeckillGoods seckillGoods; 21 | 22 | public SeckillMessage() { 23 | } 24 | 25 | public SeckillMessage(UserInfo userInfo, SeckillGoods seckillGoods) { 26 | this.userInfo = userInfo; 27 | this.seckillGoods = seckillGoods; 28 | } 29 | 30 | public UserInfo getUserInfo() { 31 | return userInfo; 32 | } 33 | 34 | public void setUserInfo(UserInfo userInfo) { 35 | this.userInfo = userInfo; 36 | } 37 | 38 | public SeckillGoods getSeckillGoods() { 39 | return seckillGoods; 40 | } 41 | 42 | public void setSeckillGoods(SeckillGoods seckillGoods) { 43 | this.seckillGoods = seckillGoods; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /leyou-secskill/leyou-seckill-service/src/main/java/com/leyou/seckill/LySeckillApplication.java: -------------------------------------------------------------------------------- 1 | package com.leyou.seckill; 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.openfeign.EnableFeignClients; 7 | import tk.mybatis.spring.annotation.MapperScan; 8 | 9 | /** 10 | * @Author: 98050 11 | * @Time: 2018-11-10 10:57 12 | * @Feature: 13 | */ 14 | @SpringBootApplication 15 | @EnableFeignClients 16 | @EnableDiscoveryClient 17 | @MapperScan("com.leyou.seckill.mapper") 18 | public class LySeckillApplication { 19 | public static void main(String[] args) { 20 | SpringApplication.run(LySeckillApplication.class,args); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /leyou-secskill/leyou-seckill-service/src/main/java/com/leyou/seckill/access/AccessLimit.java: -------------------------------------------------------------------------------- 1 | package com.leyou.seckill.access; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | /** 9 | * @Author: 98050 10 | * @Time: 2018-11-23 23:38 11 | * @Feature: 接口限流注解 12 | */ 13 | @Retention(RetentionPolicy.RUNTIME) 14 | @Target(ElementType.METHOD) 15 | public @interface AccessLimit { 16 | 17 | /** 18 | * 限流时间 19 | * @return 20 | */ 21 | int seconds(); 22 | 23 | /** 24 | * 最大请求次数 25 | * @return 26 | */ 27 | int maxCount(); 28 | 29 | /** 30 | * 是否需要登录 31 | * @return 32 | */ 33 | boolean needLogin() default true; 34 | } 35 | -------------------------------------------------------------------------------- /leyou-secskill/leyou-seckill-service/src/main/java/com/leyou/seckill/client/GoodsClient.java: -------------------------------------------------------------------------------- 1 | package com.leyou.seckill.client; 2 | 3 | import com.leyou.item.api.GoodsApi; 4 | import org.springframework.cloud.openfeign.FeignClient; 5 | 6 | /** 7 | * @Author: 98050 8 | * Time: 2018-10-11 20:50 9 | * Feature:商品FeignClient 10 | */ 11 | @FeignClient(value = "item-service") 12 | public interface GoodsClient extends GoodsApi { 13 | } 14 | -------------------------------------------------------------------------------- /leyou-secskill/leyou-seckill-service/src/main/java/com/leyou/seckill/client/OrderClient.java: -------------------------------------------------------------------------------- 1 | package com.leyou.seckill.client; 2 | 3 | import com.leyou.order.api.OrderApi; 4 | import com.leyou.seckill.config.OrderConfig; 5 | import org.springframework.cloud.openfeign.FeignClient; 6 | 7 | /** 8 | * @Author: 98050 9 | * @Time: 2018-11-12 15:19 10 | * @Feature: 订单接口 11 | */ 12 | @FeignClient(value = "order-service",configuration = OrderConfig.class) 13 | public interface OrderClient extends OrderApi { 14 | } 15 | -------------------------------------------------------------------------------- /leyou-secskill/leyou-seckill-service/src/main/java/com/leyou/seckill/config/OrderConfig.java: -------------------------------------------------------------------------------- 1 | package com.leyou.seckill.config; 2 | 3 | 4 | import feign.Feign; 5 | 6 | import org.springframework.context.annotation.Bean; 7 | import org.springframework.context.annotation.Configuration; 8 | import org.springframework.web.context.request.RequestContextHolder; 9 | import org.springframework.web.context.request.ServletRequestAttributes; 10 | 11 | import javax.servlet.http.HttpServletRequest; 12 | import java.util.Enumeration; 13 | 14 | 15 | /** 16 | * @Author: 98050 17 | * @Time: 2018-11-13 22:39 18 | * @Feature: order服务配置,转发header 19 | */ 20 | @Configuration 21 | public class OrderConfig { 22 | @Bean 23 | public Feign.Builder feignBuilder(){ 24 | return Feign.builder().requestInterceptor(requestTemplate -> { 25 | ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); 26 | HttpServletRequest request = attributes.getRequest(); 27 | Enumeration headerNames = request.getHeaderNames(); 28 | if (headerNames != null) { 29 | while (headerNames.hasMoreElements()) { 30 | String name = headerNames.nextElement(); 31 | String values = request.getHeader(name); 32 | requestTemplate.header(name, values); 33 | } 34 | } 35 | }); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /leyou-secskill/leyou-seckill-service/src/main/java/com/leyou/seckill/mapper/SeckillMapper.java: -------------------------------------------------------------------------------- 1 | package com.leyou.seckill.mapper; 2 | 3 | import com.leyou.item.pojo.SeckillGoods; 4 | import tk.mybatis.mapper.common.Mapper; 5 | 6 | /** 7 | * @Author: 98050 8 | * @Time: 2018-11-10 16:54 9 | * @Feature: 10 | */ 11 | public interface SeckillMapper extends Mapper { 12 | } 13 | -------------------------------------------------------------------------------- /leyou-secskill/leyou-seckill-service/src/main/java/com/leyou/seckill/mapper/SeckillOrderMapper.java: -------------------------------------------------------------------------------- 1 | package com.leyou.seckill.mapper; 2 | 3 | import com.leyou.order.pojo.SeckillOrder; 4 | import tk.mybatis.mapper.common.Mapper; 5 | 6 | /** 7 | * @Author: 98050 8 | * @Time: 2018-11-19 00:20 9 | * @Feature: 10 | */ 11 | public interface SeckillOrderMapper extends Mapper { 12 | } 13 | -------------------------------------------------------------------------------- /leyou-secskill/leyou-seckill-service/src/main/java/com/leyou/seckill/mapper/SkuMapper.java: -------------------------------------------------------------------------------- 1 | package com.leyou.seckill.mapper; 2 | 3 | import com.leyou.item.pojo.Sku; 4 | import tk.mybatis.mapper.common.Mapper; 5 | 6 | /** 7 | * @Author: 98050 8 | * @Time: 2018-11-12 16:21 9 | * @Feature: 10 | */ 11 | public interface SkuMapper extends Mapper { 12 | } 13 | -------------------------------------------------------------------------------- /leyou-secskill/leyou-seckill-service/src/main/java/com/leyou/seckill/mapper/StockMapper.java: -------------------------------------------------------------------------------- 1 | package com.leyou.seckill.mapper; 2 | 3 | import com.leyou.item.pojo.Stock; 4 | import tk.mybatis.mapper.common.Mapper; 5 | 6 | /** 7 | * @Author: 98050 8 | * @Time: 2018-11-10 17:58 9 | * @Feature: 10 | */ 11 | public interface StockMapper extends Mapper { 12 | } 13 | -------------------------------------------------------------------------------- /leyou-secskill/leyou-seckill-service/src/main/java/com/leyou/seckill/properties/JwtProperties.java: -------------------------------------------------------------------------------- 1 | package com.leyou.seckill.properties; 2 | 3 | import com.leyou.auth.utils.RsaUtils; 4 | import org.slf4j.Logger; 5 | import org.slf4j.LoggerFactory; 6 | import org.springframework.beans.factory.annotation.Value; 7 | import org.springframework.boot.context.properties.ConfigurationProperties; 8 | import org.springframework.cloud.context.config.annotation.RefreshScope; 9 | import org.springframework.context.annotation.Configuration; 10 | 11 | import javax.annotation.PostConstruct; 12 | import java.security.PublicKey; 13 | 14 | /** 15 | * @author: 9805 16 | * @create: 2018-10-27 17 | **/ 18 | //@ConfigurationProperties(prefix = "leyou.jwt") 19 | @Configuration 20 | @RefreshScope 21 | public class JwtProperties { 22 | 23 | /** 24 | * 公钥地址 25 | */ 26 | @Value("${leyou.jwt.pubKeyPath}") 27 | private String pubKeyPath; 28 | 29 | /** 30 | * 公钥 31 | */ 32 | private PublicKey publicKey; 33 | 34 | /** 35 | * cookie名字 36 | */ 37 | @Value("${leyou.jwt.cookieName}") 38 | private String cookieName; 39 | 40 | private static final Logger logger = LoggerFactory.getLogger(JwtProperties.class); 41 | 42 | @PostConstruct 43 | public void init(){ 44 | try { 45 | // 获取公钥和私钥 46 | this.publicKey = RsaUtils.getPublicKey(pubKeyPath); 47 | } catch (Exception e) { 48 | logger.error("初始化公钥失败!", e); 49 | throw new RuntimeException(); 50 | } 51 | } 52 | 53 | public String getPubKeyPath() { 54 | return pubKeyPath; 55 | } 56 | 57 | public void setPubKeyPath(String pubKeyPath) { 58 | this.pubKeyPath = pubKeyPath; 59 | } 60 | 61 | public PublicKey getPublicKey() { 62 | return publicKey; 63 | } 64 | 65 | public void setPublicKey(PublicKey publicKey) { 66 | this.publicKey = publicKey; 67 | } 68 | 69 | public String getCookieName() { 70 | return cookieName; 71 | } 72 | 73 | public void setCookieName(String cookieName) { 74 | this.cookieName = cookieName; 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /leyou-secskill/leyou-seckill-service/src/main/java/com/leyou/seckill/service/SeckillService.java: -------------------------------------------------------------------------------- 1 | package com.leyou.seckill.service; 2 | 3 | 4 | import com.leyou.item.pojo.SeckillGoods; 5 | import com.leyou.seckill.vo.SeckillMessage; 6 | 7 | /** 8 | * @Author: 98050 9 | * @Time: 2018-11-10 16:56 10 | * @Feature: 11 | */ 12 | public interface SeckillService { 13 | 14 | /** 15 | * 创建订单 16 | * @param seckillGoods 17 | * @return 18 | */ 19 | Long createOrder(SeckillGoods seckillGoods); 20 | 21 | 22 | /** 23 | * 检查库存 24 | * @param skuId 25 | * @return 26 | */ 27 | boolean queryStock(Long skuId); 28 | 29 | /** 30 | * 发送秒杀信息到队列当中 31 | * @param seckillMessage 32 | */ 33 | void sendMessage(SeckillMessage seckillMessage); 34 | 35 | /** 36 | * 根据用户id查询秒杀订单 37 | * @param userId 38 | * @return 39 | */ 40 | Long checkSeckillOrder(Long userId); 41 | 42 | 43 | /** 44 | * 创建秒杀地址 45 | * @param goodsId 46 | * @param id 47 | * @return 48 | */ 49 | String createPath(Long goodsId, Long id); 50 | 51 | /** 52 | * 验证秒杀地址 53 | * @param goodsId 54 | * @param id 55 | * @param path 56 | * @return 57 | */ 58 | boolean checkSeckillPath(Long goodsId, Long id, String path); 59 | 60 | } 61 | -------------------------------------------------------------------------------- /leyou-secskill/leyou-seckill-service/src/main/resources/bootstrap.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | cloud: 3 | config: 4 | name: seckill 5 | profile: dev 6 | label: master 7 | uri: http://127.0.0.1:10011 8 | -------------------------------------------------------------------------------- /leyou-secskill/leyou-seckill-service/src/test/java/JsonTest.java: -------------------------------------------------------------------------------- 1 | //import com.leyou.item.bo.SeckillParameter; 2 | // 3 | //import com.leyou.item.pojo.SeckillGoods; 4 | //import com.leyou.utils.JsonUtils; 5 | //import org.junit.Test; 6 | //import org.springframework.beans.factory.annotation.Autowired; 7 | //import org.springframework.data.redis.core.BoundHashOperations; 8 | //import org.springframework.data.redis.core.StringRedisTemplate; 9 | // 10 | //import java.util.Date; 11 | //import java.util.HashMap; 12 | //import java.util.List; 13 | //import java.util.Map; 14 | // 15 | ///** 16 | // * @Author: 98050 17 | // * @Time: 2018-11-13 21:36 18 | // * @Feature: 19 | // */ 20 | //public class JsonTest { 21 | // 22 | //} 23 | -------------------------------------------------------------------------------- /leyou-secskill/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | leyou 7 | com.leyou.parent 8 | 1.0.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | com.leyou.seckill 13 | leyou-secskill 14 | pom 15 | 16 | leyou-seckill-interface 17 | leyou-seckill-service 18 | 19 | 20 | -------------------------------------------------------------------------------- /leyou-sms/src/main/java/com/leyou/sms/LySmsApplication.java: -------------------------------------------------------------------------------- 1 | package com.leyou.sms; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | /** 7 | * @Author: 98050 8 | * @Time: 2018-10-22 18:08 9 | * @Feature: 短信服务启动器 10 | */ 11 | @SpringBootApplication 12 | public class LySmsApplication { 13 | public static void main(String[] args) { 14 | SpringApplication.run(LySmsApplication.class,args); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /leyou-sms/src/main/java/com/leyou/sms/listener/SmsListener.java: -------------------------------------------------------------------------------- 1 | package com.leyou.sms.listener; 2 | 3 | import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse; 4 | import com.aliyuncs.exceptions.ClientException; 5 | import com.leyou.sms.pojo.SmsProperties; 6 | import com.leyou.sms.utils.SmsUtils; 7 | import org.apache.commons.lang3.StringUtils; 8 | import org.springframework.amqp.rabbit.annotation.Exchange; 9 | import org.springframework.amqp.rabbit.annotation.Queue; 10 | import org.springframework.amqp.rabbit.annotation.QueueBinding; 11 | import org.springframework.amqp.rabbit.annotation.RabbitListener; 12 | import org.springframework.beans.factory.annotation.Autowired; 13 | import org.springframework.stereotype.Component; 14 | 15 | import java.util.Map; 16 | 17 | /** 18 | * @Author: 98050 19 | * @Time: 2018-10-22 19:21 20 | * @Feature:短信服务监听器 21 | */ 22 | @Component 23 | public class SmsListener { 24 | 25 | @Autowired 26 | private SmsUtils smsUtils; 27 | 28 | @Autowired 29 | private SmsProperties smsProperties; 30 | 31 | @RabbitListener(bindings = @QueueBinding( 32 | value = @Queue(value = "leyou.sms.queue",durable = "true"), 33 | exchange = @Exchange(value = "leyou.sms.exchange",ignoreDeclarationExceptions = "true"), 34 | key = {"sms.verify.code"} 35 | )) 36 | public void listenSms(Map msg){ 37 | if (msg == null || msg.size() <= 0){ 38 | //不做处理 39 | return; 40 | } 41 | String phone = msg.get("phone"); 42 | String code = msg.get("code"); 43 | 44 | if (StringUtils.isNotBlank(phone) && StringUtils.isNotBlank(code)){ 45 | //发送消息 46 | try { 47 | SendSmsResponse response = this.smsUtils.sendSms(phone, code, smsProperties.getSignName(), smsProperties.getVerifyCodeTemplate()); 48 | }catch (ClientException e){ 49 | return; 50 | } 51 | }else { 52 | //不做处理 53 | return; 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /leyou-sms/src/main/java/com/leyou/sms/pojo/SmsProperties.java: -------------------------------------------------------------------------------- 1 | package com.leyou.sms.pojo; 2 | 3 | import org.springframework.beans.factory.annotation.Value; 4 | import org.springframework.boot.context.properties.ConfigurationProperties; 5 | import org.springframework.cloud.context.config.annotation.RefreshScope; 6 | import org.springframework.context.annotation.Configuration; 7 | 8 | /** 9 | * @Author: 98050 10 | * @Time: 2018-10-22 18:34 11 | * @Feature: 短信服务实体类 12 | */ 13 | //@ConfigurationProperties(prefix = "leyou.sms") 14 | @Configuration 15 | @RefreshScope 16 | public class SmsProperties { 17 | 18 | @Value("${leyou.sms.accessKeyId}") 19 | private String accessKeyId; 20 | 21 | @Value("${leyou.sms.accessKeySecret}") 22 | private String accessKeySecret; 23 | 24 | @Value("${leyou.sms.signName}") 25 | private String signName; 26 | 27 | @Value("${leyou.sms.verifyCodeTemplate}") 28 | private String verifyCodeTemplate; 29 | 30 | public String getAccessKeyId() { 31 | return accessKeyId; 32 | } 33 | 34 | public void setAccessKeyId(String accessKeyId) { 35 | this.accessKeyId = accessKeyId; 36 | } 37 | 38 | public String getAccessKeySecret() { 39 | return accessKeySecret; 40 | } 41 | 42 | public void setAccessKeySecret(String accessKeySecret) { 43 | this.accessKeySecret = accessKeySecret; 44 | } 45 | 46 | public String getSignName() { 47 | return signName; 48 | } 49 | 50 | public void setSignName(String signName) { 51 | this.signName = signName; 52 | } 53 | 54 | public String getVerifyCodeTemplate() { 55 | return verifyCodeTemplate; 56 | } 57 | 58 | public void setVerifyCodeTemplate(String verifyCodeTemplate) { 59 | this.verifyCodeTemplate = verifyCodeTemplate; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /leyou-sms/src/main/resources/bootstrap.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | cloud: 3 | config: 4 | name: sms 5 | profile: dev 6 | label: master 7 | uri: http://127.0.0.1:10011 8 | -------------------------------------------------------------------------------- /leyou-upload/src/main/java/com/leyou/LyUploadService.java: -------------------------------------------------------------------------------- 1 | package com.leyou; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; 6 | 7 | /** 8 | * @Author: 98050 9 | * Time: 2018-08-09 14:12 10 | * Feature: 11 | */ 12 | @SpringBootApplication 13 | @EnableDiscoveryClient 14 | public class LyUploadService { 15 | public static void main(String[] args) { 16 | SpringApplication.run(LyUploadService.class, args); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /leyou-upload/src/main/java/com/leyou/config/FastClientImporter.java: -------------------------------------------------------------------------------- 1 | package com.leyou.config; 2 | 3 | import com.github.tobato.fastdfs.FdfsClientConfig; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.context.annotation.EnableMBeanExport; 6 | import org.springframework.context.annotation.Import; 7 | import org.springframework.jmx.support.RegistrationPolicy; 8 | 9 | @Configuration 10 | @Import(FdfsClientConfig.class) 11 | /** 12 | * @author li 13 | * 解决jmx重复注册bean的问题 14 | */ 15 | @EnableMBeanExport(registration = RegistrationPolicy.IGNORE_EXISTING) 16 | public class FastClientImporter { 17 | } -------------------------------------------------------------------------------- /leyou-upload/src/main/java/com/leyou/config/GlobalCorsConfig.java: -------------------------------------------------------------------------------- 1 | package com.leyou.config; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.web.cors.CorsConfiguration; 6 | import org.springframework.web.cors.UrlBasedCorsConfigurationSource; 7 | import org.springframework.web.filter.CorsFilter; 8 | 9 | /** 10 | * @author li 11 | * @time:2018/8/9 12 | * 处理跨域请求的过滤器 13 | */ 14 | @Configuration 15 | public class GlobalCorsConfig { 16 | @Bean 17 | public CorsFilter corsFilter() { 18 | //1.添加CORS配置信息 19 | CorsConfiguration config = new CorsConfiguration(); 20 | //1) 允许的域,不要写*,否则cookie就无法使用了 21 | config.addAllowedOrigin("http://manage.leyou.com"); 22 | //2) 是否发送Cookie信息 23 | config.setAllowCredentials(false); 24 | //3) 允许的请求方式 25 | config.addAllowedMethod("OPTIONS"); 26 | config.addAllowedMethod("POST"); 27 | config.addAllowedHeader("*"); 28 | 29 | //2.添加映射路径,我们拦截一切请求 30 | UrlBasedCorsConfigurationSource configSource = new UrlBasedCorsConfigurationSource(); 31 | configSource.registerCorsConfiguration("/**", config); 32 | 33 | //3.返回新的CorsFilter. 34 | return new CorsFilter(configSource); 35 | } 36 | } -------------------------------------------------------------------------------- /leyou-upload/src/main/java/com/leyou/upload/controller/UploadController.java: -------------------------------------------------------------------------------- 1 | package com.leyou.upload.controller; 2 | 3 | import com.leyou.upload.service.serviceimpl.UploadServiceImpl; 4 | import org.apache.commons.lang3.StringUtils; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.http.HttpStatus; 7 | import org.springframework.http.ResponseEntity; 8 | import org.springframework.web.bind.annotation.PostMapping; 9 | import org.springframework.web.bind.annotation.RequestMapping; 10 | import org.springframework.web.bind.annotation.RequestParam; 11 | import org.springframework.web.bind.annotation.RestController; 12 | import org.springframework.web.multipart.MultipartFile; 13 | 14 | /** 15 | * @Author: 98050 16 | * Time: 2018-08-09 14:36 17 | * Feature: 18 | */ 19 | @RestController 20 | @RequestMapping("upload") 21 | public class UploadController { 22 | @Autowired 23 | private UploadServiceImpl uploadServiceImpl; 24 | 25 | /** 26 | * 图片上传 27 | * @param file 28 | * @return 29 | */ 30 | @PostMapping("image") 31 | public ResponseEntity uploadImage(@RequestParam("file")MultipartFile file){ 32 | String url= this.uploadServiceImpl.upload(file); 33 | if(StringUtils.isBlank(url)){ 34 | //url为空,证明上传失败 35 | return ResponseEntity.status(HttpStatus.BAD_REQUEST).build(); 36 | } 37 | return ResponseEntity.ok(url); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /leyou-upload/src/main/java/com/leyou/upload/service/UploadService.java: -------------------------------------------------------------------------------- 1 | package com.leyou.upload.service; 2 | 3 | import org.springframework.web.multipart.MultipartFile; 4 | 5 | /** 6 | * @Author: 98050 7 | * Time: 2018-08-09 14:44 8 | * Feature: 9 | */ 10 | public interface UploadService { 11 | /** 12 | * 文件上传 13 | * @param file 14 | * @return 15 | */ 16 | String upload(MultipartFile file); 17 | } 18 | -------------------------------------------------------------------------------- /leyou-upload/src/main/resources/bootstrap.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | cloud: 3 | config: 4 | name: upload 5 | profile: dev 6 | label: master 7 | uri: http://127.0.0.1:10011 8 | -------------------------------------------------------------------------------- /leyou-upload/src/test/java/com/leyou/test/FdfsTest.java: -------------------------------------------------------------------------------- 1 | //package com.leyou.test; 2 | // 3 | //import com.github.tobato.fastdfs.domain.StorePath; 4 | //import com.github.tobato.fastdfs.domain.ThumbImageConfig; 5 | //import com.github.tobato.fastdfs.service.FastFileStorageClient; 6 | //import com.leyou.LyUploadService; 7 | //import org.junit.Test; 8 | //import org.junit.runner.RunWith; 9 | //import org.springframework.beans.factory.annotation.Autowired; 10 | //import org.springframework.boot.test.context.SpringBootTest; 11 | //import org.springframework.test.context.junit4.SpringRunner; 12 | // 13 | //import java.io.File; 14 | //import java.io.FileInputStream; 15 | //import java.io.FileNotFoundException; 16 | // 17 | //@RunWith(SpringRunner.class) 18 | //@SpringBootTest(classes = LyUploadService.class) 19 | //public class FdfsTest { 20 | // 21 | // @Autowired 22 | // private FastFileStorageClient storageClient; 23 | // 24 | // @Autowired 25 | // private ThumbImageConfig thumbImageConfig; 26 | // 27 | // @Test 28 | // public void testUpload() throws FileNotFoundException { 29 | // File file = new File("G:\\LeYou\\upload\\spitter_logo_50.png"); 30 | // // 上传 31 | // StorePath storePath = this.storageClient.uploadFile( 32 | // new FileInputStream(file), file.length(), "png", null); 33 | // // 带分组的路径 34 | // System.out.println(storePath.getFullPath()); 35 | // // 不带分组的路径 36 | // System.out.println(storePath.getPath()); 37 | // } 38 | // 39 | // @Test 40 | // public void testUploadAndCreateThumb() throws FileNotFoundException { 41 | // File file = new File("G:\\LeYou\\upload\\spitter_logo_50.png"); 42 | // // 上传并且生成缩略图 43 | // StorePath storePath = this.storageClient.uploadImageAndCrtThumbImage( 44 | // new FileInputStream(file), file.length(), "png", null); 45 | // // 带分组的路径 46 | // System.out.println(storePath.getFullPath()); 47 | // // 不带分组的路径 48 | // System.out.println(storePath.getPath()); 49 | // // 获取缩略图路径 50 | // String path = thumbImageConfig.getThumbImagePath(storePath.getPath()); 51 | // System.out.println(path); 52 | // } 53 | //} -------------------------------------------------------------------------------- /leyou-user/leyou-user-interface/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | leyou-user 7 | com.leyou.user 8 | 1.0.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | com.leyou.user 13 | leyou-user-interface 14 | jar 15 | 16 | 17 | 18 | 19 | org.hibernate.validator 20 | hibernate-validator 21 | 22 | 23 | 24 | javax.persistence 25 | persistence-api 26 | 27 | 28 | 29 | org.springframework 30 | spring-webmvc 31 | 32 | 33 | 34 | com.fasterxml.jackson.core 35 | jackson-annotations 36 | compile 37 | 38 | 39 | 40 | 41 | 42 | 43 | org.springframework.boot 44 | spring-boot-maven-plugin 45 | 46 | com.xx.webapps.api.main.WebappsApiBidMain 47 | 48 | 49 | 50 | 51 | repackage 52 | 53 | 54 | 55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /leyou-user/leyou-user-interface/src/main/java/com/leyou/user/api/UserApi.java: -------------------------------------------------------------------------------- 1 | package com.leyou.user.api; 2 | 3 | import com.leyou.user.pojo.User; 4 | import org.springframework.web.bind.annotation.GetMapping; 5 | import org.springframework.web.bind.annotation.RequestParam; 6 | 7 | /** 8 | * @Author: 98050 9 | * @Time: 2018-10-23 23:50 10 | * @Feature: 用户服务接口 11 | */ 12 | public interface UserApi { 13 | /** 14 | * 用户验证 15 | * @param username 16 | * @param password 17 | * @return 18 | */ 19 | @GetMapping("query") 20 | User queryUser(@RequestParam("username")String username, @RequestParam("password")String password); 21 | } 22 | -------------------------------------------------------------------------------- /leyou-user/leyou-user-interface/src/main/java/com/leyou/user/pojo/User.java: -------------------------------------------------------------------------------- 1 | package com.leyou.user.pojo; 2 | 3 | import com.fasterxml.jackson.annotation.JsonIgnore; 4 | import org.hibernate.validator.constraints.Length; 5 | 6 | import javax.persistence.GeneratedValue; 7 | import javax.persistence.GenerationType; 8 | import javax.persistence.Id; 9 | import javax.persistence.Table; 10 | import javax.validation.constraints.Pattern; 11 | import java.util.Date; 12 | 13 | /** 14 | * @Author: 98050 15 | * @Time: 2018-10-21 18:42 16 | * @Feature: 用户实体类 17 | */ 18 | @Table(name = "tb_user") 19 | public class User { 20 | 21 | @Id 22 | @GeneratedValue(strategy = GenerationType.IDENTITY) 23 | private Long id; 24 | 25 | /** 26 | * 用户名 27 | */ 28 | @Length(min = 4,max = 15,message = "用户名只能在4~15位之间") 29 | private String username; 30 | 31 | /** 32 | * 密码 33 | */ 34 | //@JsonIgnore 35 | @Length(min = 6,max = 25,message = "密码只能在6~25位之间") 36 | private String password; 37 | 38 | /** 39 | * 电话 40 | */ 41 | @Pattern(regexp = "^1[35678]\\d{9}$", message = "手机号格式不正确") 42 | private String phone; 43 | 44 | /** 45 | * 创建时间 46 | */ 47 | private Date created; 48 | 49 | public Long getId() { 50 | return id; 51 | } 52 | 53 | public void setId(Long id) { 54 | this.id = id; 55 | } 56 | 57 | public String getUsername() { 58 | return username; 59 | } 60 | 61 | public void setUsername(String username) { 62 | this.username = username; 63 | } 64 | 65 | public String getPassword() { 66 | return password; 67 | } 68 | 69 | public void setPassword(String password) { 70 | this.password = password; 71 | } 72 | 73 | public String getPhone() { 74 | return phone; 75 | } 76 | 77 | public void setPhone(String phone) { 78 | this.phone = phone; 79 | } 80 | 81 | public Date getCreated() { 82 | return created; 83 | } 84 | 85 | public void setCreated(Date created) { 86 | this.created = created; 87 | } 88 | 89 | @Override 90 | public String toString() { 91 | return "User{" + 92 | "id=" + id + 93 | ", username='" + username + '\'' + 94 | ", password='" + password + '\'' + 95 | ", phone='" + phone + '\'' + 96 | ", created=" + created + 97 | '}'; 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /leyou-user/leyou-user-service/src/main/java/com/leyou/user/LyUserApplication.java: -------------------------------------------------------------------------------- 1 | package com.leyou.user; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; 6 | import tk.mybatis.spring.annotation.MapperScan; 7 | 8 | /** 9 | * @Author: 98050 10 | * @Time: 2018-10-21 17:29 11 | * @Feature: 用户中心启动器 12 | */ 13 | @SpringBootApplication 14 | @EnableDiscoveryClient 15 | @MapperScan("com.leyou.user.mapper") 16 | public class LyUserApplication { 17 | public static void main(String[] args) { 18 | SpringApplication.run(LyUserApplication.class,args); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /leyou-user/leyou-user-service/src/main/java/com/leyou/user/mapper/UserMapper.java: -------------------------------------------------------------------------------- 1 | package com.leyou.user.mapper; 2 | 3 | import com.leyou.user.pojo.User; 4 | import tk.mybatis.mapper.common.Mapper; 5 | 6 | /** 7 | * @Author: 98050 8 | * @Time: 2018-10-21 18:40 9 | * @Feature: 10 | */ 11 | public interface UserMapper extends Mapper { 12 | } 13 | -------------------------------------------------------------------------------- /leyou-user/leyou-user-service/src/main/java/com/leyou/user/service/UserService.java: -------------------------------------------------------------------------------- 1 | package com.leyou.user.service; 2 | 3 | import com.leyou.user.pojo.User; 4 | 5 | /** 6 | * @Author: 98050 7 | * @Time: 2018-10-21 18:41 8 | * @Feature: 9 | */ 10 | public interface UserService { 11 | /** 12 | * 检查用户名和手机号是否可用 13 | * @param data 14 | * @param type 15 | * @return 16 | */ 17 | Boolean checkData(String data, Integer type); 18 | 19 | /** 20 | * 发送手机验证码 21 | * @param phone 22 | * @return 23 | */ 24 | Boolean sendVerifyCode(String phone); 25 | 26 | /** 27 | * 用户注册 28 | * @param user 29 | * @param code 30 | * @return 31 | */ 32 | Boolean register(User user, String code); 33 | 34 | /** 35 | * 用户验证 36 | * @param username 37 | * @param password 38 | * @return 39 | */ 40 | User queryUser(String username, String password); 41 | 42 | /** 43 | * 根据用户名修改密码 44 | * @param username 45 | * @param newPassword 46 | * @return 47 | */ 48 | boolean updatePassword(String username,String oldPassword,String newPassword); 49 | } 50 | -------------------------------------------------------------------------------- /leyou-user/leyou-user-service/src/main/resources/bootstrap.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | cloud: 3 | config: 4 | name: user 5 | profile: dev 6 | label: master 7 | uri: http://127.0.0.1:10011 8 | -------------------------------------------------------------------------------- /leyou-user/leyou-user-service/src/test/java/BCTest.java: -------------------------------------------------------------------------------- 1 | //import org.junit.Test; 2 | //import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; 3 | // 4 | ///** 5 | // * @Author: 98050 6 | // * @Time: 2018-11-06 15:13 7 | // * @Feature: BCryptPasswordEncoder测试 8 | // */ 9 | //public class BCTest { 10 | // 11 | // @Test 12 | // public void BcTest(){ 13 | // BCryptPasswordEncoder bCryptPasswordEncoder = new BCryptPasswordEncoder(); 14 | // String password = "123123"; 15 | // System.out.println("加密前:" + password); 16 | // //System.out.println("加密后:" + bCryptPasswordEncoder.encode(password)); 17 | // System.out.println("密码匹配" + bCryptPasswordEncoder.matches(password,"$2a$10$sqKOb9/8gSCAG2kJeZ3Ts.tW2JGtD8sbx00GyknYjSuWbBiMjUuOi")); 18 | // } 19 | //} 20 | -------------------------------------------------------------------------------- /leyou-user/leyou-user-service/src/test/java/RedisTest.java: -------------------------------------------------------------------------------- 1 | //import com.leyou.user.LyUserApplication; 2 | //import org.junit.Test; 3 | //import org.junit.runner.RunWith; 4 | //import org.springframework.beans.factory.annotation.Autowired; 5 | //import org.springframework.boot.test.context.SpringBootTest; 6 | //import org.springframework.data.redis.core.BoundHashOperations; 7 | //import org.springframework.data.redis.core.StringRedisTemplate; 8 | //import org.springframework.test.context.junit4.SpringRunner; 9 | // 10 | //import java.util.Map; 11 | //import java.util.concurrent.TimeUnit; 12 | // 13 | //@RunWith(SpringRunner.class) 14 | //@SpringBootTest(classes = LyUserApplication.class) 15 | //public class RedisTest { 16 | // 17 | // @Autowired 18 | // private StringRedisTemplate redisTemplate; 19 | // 20 | // @Test 21 | // public void testRedis() { 22 | // // 存储数据 23 | // this.redisTemplate.opsForValue().set("key1", "value1"); 24 | // // 获取数据 25 | // String val = this.redisTemplate.opsForValue().get("key1"); 26 | // System.out.println("val = " + val); 27 | // } 28 | // 29 | // @Test 30 | // public void testRedis2() { 31 | // // 存储数据,并指定剩余生命时间,5小时 32 | // this.redisTemplate.opsForValue().set("key2", "value2", 33 | // 5, TimeUnit.HOURS); 34 | // } 35 | // 36 | // @Test 37 | // public void testHash(){ 38 | // BoundHashOperations hashOps = 39 | // this.redisTemplate.boundHashOps("user"); 40 | // // 操作hash数据 41 | // hashOps.put("name", "jack"); 42 | // hashOps.put("age", "21"); 43 | // 44 | // // 获取单个数据 45 | // Object name = hashOps.get("name"); 46 | // System.out.println("name = " + name); 47 | // 48 | // // 获取所有数据 49 | // Map map = hashOps.entries(); 50 | // for (Map.Entry me : map.entrySet()) { 51 | // System.out.println(me.getKey() + " : " + me.getValue()); 52 | // } 53 | // } 54 | //} -------------------------------------------------------------------------------- /leyou-user/leyou-user-service/src/test/java/UserTest.java: -------------------------------------------------------------------------------- 1 | import com.leyou.user.LyUserApplication; 2 | import com.leyou.user.mapper.UserMapper; 3 | import com.leyou.user.pojo.User; 4 | import com.leyou.utils.CodecUtils; 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.SpringRunner; 10 | 11 | import java.util.Date; 12 | 13 | 14 | /** 15 | * @Author: 98050 16 | * @Time: 2018-11-14 23:31 17 | * @Feature: 18 | */ 19 | @RunWith(SpringRunner.class) 20 | @SpringBootTest(classes = LyUserApplication.class) 21 | public class UserTest { 22 | 23 | @Autowired 24 | private UserMapper userMapper; 25 | 26 | /** 27 | * 注册5000个用户 28 | */ 29 | @Test 30 | public void addUser(){ 31 | User user = new User(); 32 | for (int i = 1; i < 5000; i ++){ 33 | user.setId(null); 34 | user.setCreated(new Date()); 35 | user.setPhone("1883482"+String.format("%04d",i)); 36 | user.setUsername("username"+i); 37 | user.setPassword("abcdefg"+i); 38 | String encodePassword = CodecUtils.passwordBcryptEncode(user.getUsername().trim(),user.getPassword().trim()); 39 | user.setPassword(encodePassword); 40 | this.userMapper.insertSelective(user); 41 | } 42 | } 43 | 44 | /** 45 | * 添加后台管理人员 46 | */ 47 | @Test 48 | public void addAdmin(){ 49 | User user = new User(); 50 | user.setCreated(new Date()); 51 | user.setPhone("88888888"); 52 | user.setUsername("admin"); 53 | user.setPassword("admin"); 54 | String encodePassword = CodecUtils.passwordBcryptEncode(user.getUsername().trim(),user.getPassword().trim()); 55 | user.setPassword(encodePassword); 56 | this.userMapper.insertSelective(user); 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /leyou-user/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | leyou 7 | com.leyou.parent 8 | 1.0.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | com.leyou.user 13 | leyou-user 14 | pom 15 | 16 | leyou-user-interface 17 | leyou-user-service 18 | 19 | 20 | 21 | --------------------------------------------------------------------------------