├── .gitignore
├── README.md
├── msns-admin
├── msns-admin-interface
│ ├── pom.xml
│ └── src
│ │ └── main
│ │ └── java
│ │ └── com
│ │ └── dxg
│ │ └── msns
│ │ └── admin
│ │ └── pojo
│ │ └── Admin.java
├── msns-admin-service
│ ├── pom.xml
│ └── src
│ │ └── main
│ │ ├── java
│ │ └── com
│ │ │ └── dxg
│ │ │ └── msns
│ │ │ └── admin
│ │ │ ├── MSNSAdminServiceApplication.java
│ │ │ ├── controller
│ │ │ └── AdminController.java
│ │ │ ├── mapper
│ │ │ └── AdminMapper.java
│ │ │ ├── properties
│ │ │ └── AdminJwtProperties.java
│ │ │ └── service
│ │ │ ├── AdminService.java
│ │ │ └── impl
│ │ │ └── AdminServiceImpl.java
│ │ └── resources
│ │ └── application.yml
└── pom.xml
├── msns-auth
├── msns-auth-common
│ ├── pom.xml
│ └── src
│ │ ├── main
│ │ └── java
│ │ │ └── com
│ │ │ └── dxg
│ │ │ └── msns
│ │ │ └── auth
│ │ │ ├── entity
│ │ │ └── UserInfo.java
│ │ │ └── utils
│ │ │ ├── CookieUtils.java
│ │ │ ├── JwtConstans.java
│ │ │ ├── JwtUtils.java
│ │ │ ├── ObjectUtils.java
│ │ │ └── RsaUtils.java
│ │ └── test
│ │ └── java
│ │ └── com
│ │ └── dxg
│ │ └── msns
│ │ └── auth
│ │ └── test
│ │ └── JwtTest.java
├── msns-auth-service
│ ├── pom.xml
│ └── src
│ │ └── main
│ │ ├── java
│ │ └── com
│ │ │ └── dxg
│ │ │ └── msns
│ │ │ └── auth
│ │ │ ├── MSNSAuthApplication.java
│ │ │ ├── client
│ │ │ └── UserClient.java
│ │ │ ├── controller
│ │ │ └── AuthController.java
│ │ │ ├── properties
│ │ │ └── JwtProperties.java
│ │ │ └── service
│ │ │ ├── AuthService.java
│ │ │ └── impl
│ │ │ └── AuthServiceImpl.java
│ │ └── resources
│ │ └── application.yml
└── pom.xml
├── msns-comment
├── msns-comment-interface
│ ├── pom.xml
│ └── src
│ │ └── main
│ │ ├── java
│ │ └── com
│ │ │ └── dxg
│ │ │ └── msns
│ │ │ └── comment
│ │ │ ├── api
│ │ │ └── CommentApi.java
│ │ │ └── pojo
│ │ │ └── Comment.java
│ │ └── resources
│ │ └── application.yml
├── msns-comment-service
│ ├── pom.xml
│ └── src
│ │ └── main
│ │ ├── java
│ │ └── com
│ │ │ └── dxg
│ │ │ └── msns
│ │ │ └── comment
│ │ │ ├── MSNSCommentServiceApplication.java
│ │ │ ├── controller
│ │ │ └── CommentController.java
│ │ │ ├── mapper
│ │ │ └── CommentMapper.java
│ │ │ └── service
│ │ │ ├── CommentService.java
│ │ │ └── impl
│ │ │ └── CommentServiceImpl.java
│ │ └── resources
│ │ └── application.yml
└── pom.xml
├── msns-common
├── pom.xml
└── src
│ └── main
│ ├── java
│ └── com
│ │ └── dxg
│ │ └── msns
│ │ └── common
│ │ ├── pojo
│ │ └── PageResult.java
│ │ └── util
│ │ ├── BatchExampleProvider.java
│ │ ├── CodecUtils.java
│ │ ├── NumberUtils.java
│ │ ├── UUIDUtils.java
│ │ ├── UnderlineHump.java
│ │ └── UpdateBatchByPrimaryKeySelectiveMapper.java
│ └── resources
│ └── application.yml
├── msns-dynamic
├── msns-dynamic-interface
│ ├── pom.xml
│ ├── src
│ │ └── main
│ │ │ └── java
│ │ │ └── com
│ │ │ └── dxg
│ │ │ └── msns
│ │ │ └── dynamic
│ │ │ ├── api
│ │ │ ├── DynamicApi.java
│ │ │ └── DynamicTypeApi.java
│ │ │ └── pojo
│ │ │ ├── Comment.java
│ │ │ ├── Dynamic.java
│ │ │ ├── DynamicType.java
│ │ │ └── Report.java
│ └── target
│ │ └── classes
│ │ └── com
│ │ └── dxg
│ │ └── msns
│ │ └── dynamic
│ │ └── pojo
│ │ ├── Dynamic.class
│ │ ├── DynamicType.class
│ │ └── Report.class
├── msns-dynamic-service
│ ├── pom.xml
│ ├── src
│ │ └── main
│ │ │ ├── java
│ │ │ └── com
│ │ │ │ └── dxg
│ │ │ │ └── msns
│ │ │ │ └── dynamic
│ │ │ │ ├── MSNSDynamicServiceApplication.java
│ │ │ │ ├── controller
│ │ │ │ ├── DynamicController.java
│ │ │ │ ├── DynamicTypeController.java
│ │ │ │ └── ReportController.java
│ │ │ │ ├── mapper
│ │ │ │ ├── DynamicMapper.java
│ │ │ │ ├── DynamicTypeMapper.java
│ │ │ │ └── ReportMapper.java
│ │ │ │ └── service
│ │ │ │ ├── DynamicService.java
│ │ │ │ ├── DynamicTypeService.java
│ │ │ │ ├── ReportService.java
│ │ │ │ └── impl
│ │ │ │ ├── DynamicServiceImpl.java
│ │ │ │ ├── DynamicTypeServiceImpl.java
│ │ │ │ └── ReportServiceImpl.java
│ │ │ └── resources
│ │ │ └── application.yml
│ └── target
│ │ └── classes
│ │ ├── META-INF
│ │ └── msns-dynamic-service.kotlin_module
│ │ ├── application.yml
│ │ └── com
│ │ └── dxg
│ │ └── msns
│ │ └── dynamic
│ │ ├── MSNSDynamicServiceApplication.class
│ │ ├── controller
│ │ ├── DynamicController.class
│ │ ├── DynamicTypeController.class
│ │ └── ReportController.class
│ │ ├── mapper
│ │ ├── DynamicMapper.class
│ │ ├── DynamicTypeMapper.class
│ │ └── ReportMapper.class
│ │ └── service
│ │ ├── DynamicService.class
│ │ ├── DynamicTypeService.class
│ │ ├── ReportService.class
│ │ └── impl
│ │ ├── DynamicServiceImpl.class
│ │ ├── DynamicTypeServiceImpl.class
│ │ └── ReportServiceImpl.class
└── pom.xml
├── msns-favor
├── msns-favor-interface
│ ├── pom.xml
│ └── src
│ │ └── main
│ │ └── java
│ │ └── com
│ │ └── dxg
│ │ └── msns
│ │ └── favor
│ │ ├── api
│ │ ├── DynamicFavorApi.java
│ │ └── MusicFavorApi.java
│ │ └── pojo
│ │ ├── DynamicFavor.java
│ │ └── MusicFavor.java
├── msns-favor-service
│ ├── pom.xml
│ └── src
│ │ └── main
│ │ ├── java
│ │ └── com
│ │ │ └── dxg
│ │ │ └── msns
│ │ │ └── favor
│ │ │ ├── MSNSFavorServiceApplication.java
│ │ │ ├── controller
│ │ │ ├── DynamicFavorController.java
│ │ │ └── MusicFavorController.java
│ │ │ ├── mapper
│ │ │ ├── DynamicFavorMapper.java
│ │ │ └── MusicFavorMapper.java
│ │ │ └── service
│ │ │ ├── DynamicFavorService.java
│ │ │ ├── MusicFavorService.java
│ │ │ └── impl
│ │ │ ├── DynamicFavorServiceImpl.java
│ │ │ └── MusicFavorServiceImpl.java
│ │ └── resources
│ │ └── application.yml
└── pom.xml
├── msns-gateway
├── pom.xml
└── src
│ └── main
│ ├── java
│ └── com
│ │ └── dxg
│ │ └── msns
│ │ ├── MSNSGatewayApplication.java
│ │ └── gateway
│ │ ├── config
│ │ ├── FilterProperties.java
│ │ ├── JwtProperties.java
│ │ └── MSNSCorsConfig.java
│ │ └── filter
│ │ └── LoginFilter.java
│ └── resources
│ └── application.yml
├── msns-image
├── image-20200412090346912.png
├── image-20200412091302795.png
├── image-20200412092428566.png
├── image-20200412092845719.png
├── image-20200412092922922.png
├── image-20200412094815633.png
├── image-20200412094932437.png
├── image-20200412095021861.png
├── image-20200412095058713.png
├── image-20200412095431929.png
├── image-20200412095443036.png
├── image-20200412095445446.png
├── image-20200412095904105.png
├── image-20200412095916716.png
├── image-20200412095929359.png
├── image-20200412100040462.png
├── image-20200412100150061.png
├── image-20200412100228769.png
├── image-20200412100315683.png
├── image-20200412100402177.png
├── image-20200412100947905.png
├── image-20200412101108681.png
├── image-20200412101125828.png
├── image-20200412101139438.png
├── image-20200412101202512.png
├── image-20200412101230197.png
├── image-20200412101302412.png
├── image-20200412101342999.png
├── image-20200412101537509.png
├── image-20200412101602321.png
├── image-20200412101603971.png
├── image-20200412101635931.png
├── image-20200412101701964.png
├── image-20200412101703368.png
├── image-20200412101726016.png
├── image-20200412101806656.png
├── image-20200412101839411.png
├── image-20200412101920506.png
├── image-20200412102056128.png
└── image-20200412205503555.png
├── msns-like
├── msns-like-interface
│ ├── pom.xml
│ └── src
│ │ └── main
│ │ └── java
│ │ └── com
│ │ └── dxg
│ │ └── msns
│ │ └── like
│ │ ├── api
│ │ └── LikeApi.java
│ │ └── pojo
│ │ └── Like.java
├── msns-like-service
│ ├── pom.xml
│ └── src
│ │ └── main
│ │ ├── java
│ │ └── com
│ │ │ └── dxg
│ │ │ └── msns
│ │ │ └── like
│ │ │ ├── MSNSLikeServiceApplication.java
│ │ │ ├── controller
│ │ │ └── LikeController.java
│ │ │ ├── mapper
│ │ │ └── LikeMapper.java
│ │ │ └── service
│ │ │ ├── LikeService.java
│ │ │ └── impl
│ │ │ └── LikeServiceImpl.java
│ │ └── resources
│ │ └── application.yml
└── pom.xml
├── msns-music
├── msns-music-interface
│ ├── pom.xml
│ ├── src
│ │ └── main
│ │ │ └── java
│ │ │ └── com
│ │ │ └── dxg
│ │ │ └── msns
│ │ │ └── music
│ │ │ ├── api
│ │ │ ├── MusicApi.java
│ │ │ └── MusicTypeApi.java
│ │ │ └── pojo
│ │ │ ├── Music.java
│ │ │ ├── MusicType.java
│ │ │ └── TypeStatistics.java
│ └── target
│ │ └── classes
│ │ └── com
│ │ └── dxg
│ │ └── msns
│ │ └── music
│ │ └── pojo
│ │ ├── Music.class
│ │ ├── MusicType.class
│ │ └── TypeStatistics.class
├── msns-music-service
│ ├── pom.xml
│ ├── src
│ │ └── main
│ │ │ ├── java
│ │ │ └── com
│ │ │ │ └── dxg
│ │ │ │ └── msns
│ │ │ │ └── music
│ │ │ │ ├── MSNSMusicServiceApplication.java
│ │ │ │ ├── controller
│ │ │ │ ├── MusicController.java
│ │ │ │ └── MusicTypeController.java
│ │ │ │ ├── mapper
│ │ │ │ ├── MusicMapper.java
│ │ │ │ └── MusicTypeMapper.java
│ │ │ │ └── service
│ │ │ │ ├── MusicService.java
│ │ │ │ ├── MusicTypeService.java
│ │ │ │ └── impl
│ │ │ │ ├── MusicServiceImpl.java
│ │ │ │ └── MusicTypeServiceImpl.java
│ │ │ └── resources
│ │ │ └── application.yml
│ └── target
│ │ └── classes
│ │ ├── META-INF
│ │ └── msns-music-service.kotlin_module
│ │ ├── application.yml
│ │ └── com
│ │ └── dxg
│ │ └── msns
│ │ └── music
│ │ ├── MSNSMusicServiceApplication.class
│ │ ├── controller
│ │ ├── MusicController.class
│ │ └── MusicTypeController.class
│ │ ├── mapper
│ │ ├── MusicMapper.class
│ │ └── MusicTypeMapper.class
│ │ └── service
│ │ ├── MusicService.class
│ │ ├── MusicTypeService.class
│ │ └── impl
│ │ ├── MusicServiceImpl.class
│ │ └── MusicTypeServiceImpl.class
└── pom.xml
├── msns-registry
├── pom.xml
└── src
│ └── main
│ ├── java
│ └── com
│ │ └── dxg
│ │ └── msns
│ │ └── MSNSRegistryApplication.java
│ └── resources
│ └── application.yml
├── msns-search
├── pom.xml
└── src
│ ├── main
│ ├── java
│ │ └── com
│ │ │ └── dxg
│ │ │ └── msns
│ │ │ └── search
│ │ │ ├── MSNSSearchServiceApplication.java
│ │ │ ├── client
│ │ │ ├── CommentClient.java
│ │ │ ├── DynamicFavorClient.java
│ │ │ ├── DynamicTypeClient.java
│ │ │ ├── DynamicsClient.java
│ │ │ ├── FollowClient.java
│ │ │ ├── LikeClient.java
│ │ │ ├── MusicClient.java
│ │ │ ├── MusicFavorClient.java
│ │ │ ├── MusicTypeClient.java
│ │ │ └── UserClient.java
│ │ │ ├── controller
│ │ │ ├── DynamicSearchController.java
│ │ │ ├── MusicSearchController.java
│ │ │ └── UserSearchController.java
│ │ │ ├── listener
│ │ │ ├── DynamicListener.java
│ │ │ └── MusicListener.java
│ │ │ ├── pojo
│ │ │ ├── Dynamics.java
│ │ │ ├── Musics.java
│ │ │ └── SearchRequst.java
│ │ │ ├── reponsitory
│ │ │ ├── DynamicsRepository.java
│ │ │ └── MusicRepository.java
│ │ │ └── service
│ │ │ ├── DynamicSearchService.java
│ │ │ ├── MusicSearchService.java
│ │ │ ├── UserSearchService.java
│ │ │ └── impl
│ │ │ ├── DynamicSearchServiceImpl.java
│ │ │ ├── MusicSearchServiceImpl.java
│ │ │ └── UserSearchServiceImpl.java
│ └── resources
│ │ └── application.yml
│ └── test
│ └── java
│ └── com
│ └── dxg
│ └── msns
│ └── search
│ └── client
│ ├── DynamicTypeClientTest.java
│ └── ElasticSearchTest.java
├── msns-sms
├── msns-sms-service
│ ├── pom.xml
│ └── src
│ │ └── main
│ │ ├── java
│ │ └── com
│ │ │ └── dxg
│ │ │ └── msns
│ │ │ └── sms
│ │ │ ├── MSNSSMSApplication.java
│ │ │ ├── listener
│ │ │ ├── SmsEmailListener.java
│ │ │ └── SmsListener.java
│ │ │ ├── service
│ │ │ ├── SmsService.java
│ │ │ └── impl
│ │ │ │ └── SmsServiceImpl.java
│ │ │ └── util
│ │ │ └── SmsUtils.java
│ │ └── resources
│ │ └── application.yml
└── pom.xml
├── msns-upload
├── pom.xml
└── src
│ └── main
│ ├── java
│ └── com
│ │ └── dxg
│ │ └── msns
│ │ └── upload
│ │ ├── MSNSUploadApplication.java
│ │ ├── config
│ │ ├── FastClientImporter.java
│ │ └── MSNSCorsConfig.java
│ │ ├── controller
│ │ └── UploadController.java
│ │ ├── service
│ │ ├── UploadService.java
│ │ └── impl
│ │ │ └── UploadServiceImpl.java
│ │ └── utils
│ │ └── GetMusicInfo.java
│ └── resources
│ └── application.yml
├── msns-user
├── msns-user-interface
│ ├── pom.xml
│ └── src
│ │ └── main
│ │ └── java
│ │ └── com
│ │ └── dxg
│ │ └── msns
│ │ └── user
│ │ ├── api
│ │ ├── FollowApi.java
│ │ └── UserApi.java
│ │ └── pojo
│ │ ├── Follow.java
│ │ ├── User.java
│ │ └── UserCountInfo.java
├── msns-user-service
│ ├── pom.xml
│ └── src
│ │ └── main
│ │ ├── java
│ │ └── com
│ │ │ └── dxg
│ │ │ └── msns
│ │ │ └── user
│ │ │ ├── MSNSUserServiceApplication.java
│ │ │ ├── controller
│ │ │ ├── FollowController.java
│ │ │ └── UserController.java
│ │ │ ├── mapper
│ │ │ ├── FollowMapper.java
│ │ │ └── UserMapper.java
│ │ │ └── service
│ │ │ ├── FollowService.java
│ │ │ ├── UserService.java
│ │ │ └── impl
│ │ │ ├── FollowServiceImpl.java
│ │ │ └── UserServiceImpl.java
│ │ └── resources
│ │ └── application.yml
└── pom.xml
├── msns.sql
└── pom.xml
/.gitignore:
--------------------------------------------------------------------------------
1 | # Created by .ignore support plugin (hsz.mobi)
2 | /target
3 | /out
4 | /classes
5 | /checkouts
6 | /.lein-*
7 | /.env
8 | *.iml
9 | .idea
10 | .DS_Store
11 | */target
12 | .svn
13 | .project
14 | .settings
15 | .classpath
16 | logs
17 | /log
18 | /tmp
19 | hotspot.log
20 |
--------------------------------------------------------------------------------
/msns-admin/msns-admin-interface/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | msns-admin
7 | com.dxg.msns.admin
8 | 1.0-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | msns-admin-interface
13 |
14 |
15 |
16 | javax.persistence
17 | persistence-api
18 | 1.0
19 |
20 |
21 | com.fasterxml.jackson.core
22 | jackson-annotations
23 |
24 |
25 |
--------------------------------------------------------------------------------
/msns-admin/msns-admin-service/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | msns-admin
7 | com.dxg.msns.admin
8 | 1.0-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | msns-admin-service
13 |
14 |
15 |
16 |
17 | org.springframework.boot
18 | spring-boot-starter-web
19 |
20 |
21 |
22 | org.springframework.cloud
23 | spring-cloud-starter-netflix-eureka-client
24 |
25 |
26 |
27 | org.mybatis.spring.boot
28 | mybatis-spring-boot-starter
29 |
30 |
31 |
32 | tk.mybatis
33 | mapper-spring-boot-starter
34 |
35 |
36 |
37 | com.github.pagehelper
38 | pagehelper-spring-boot-starter
39 |
40 |
41 |
42 | org.springframework.boot
43 | spring-boot-starter-jdbc
44 |
45 |
46 |
47 | mysql
48 | mysql-connector-java
49 |
50 |
51 |
52 |
53 | org.springframework.boot
54 | spring-boot-starter-actuator
55 |
56 |
57 |
58 | com.dxg.msns.admin
59 | msns-admin-interface
60 | 1.0-SNAPSHOT
61 |
62 |
63 | com.dxg.msns.common
64 | msns-common
65 | 1.0-SNAPSHOT
66 | compile
67 |
68 |
69 | com.dxg.msns.auth
70 | msns-auth-common
71 | 1.0-SNAPSHOT
72 | compile
73 |
74 |
75 |
--------------------------------------------------------------------------------
/msns-admin/msns-admin-service/src/main/java/com/dxg/msns/admin/MSNSAdminServiceApplication.java:
--------------------------------------------------------------------------------
1 | package com.dxg.msns.admin;
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 | @SpringBootApplication
9 | @EnableDiscoveryClient
10 | @MapperScan("com.dxg.msns.admin.mapper")
11 | public class MSNSAdminServiceApplication {
12 | public static void main(String[] args) {
13 | SpringApplication.run(MSNSAdminServiceApplication.class);
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/msns-admin/msns-admin-service/src/main/java/com/dxg/msns/admin/mapper/AdminMapper.java:
--------------------------------------------------------------------------------
1 | package com.dxg.msns.admin.mapper;
2 |
3 | import com.dxg.msns.admin.pojo.Admin;
4 | import org.apache.ibatis.annotations.Param;
5 | import tk.mybatis.mapper.common.Mapper;
6 |
7 | import java.util.List;
8 |
9 | /**
10 | * (Admin)表数据库访问层
11 | *
12 | * @author makejava
13 | * @since 2020-03-10 10:54:35
14 | */
15 | public interface AdminMapper extends Mapper {
16 | }
--------------------------------------------------------------------------------
/msns-admin/msns-admin-service/src/main/java/com/dxg/msns/admin/service/AdminService.java:
--------------------------------------------------------------------------------
1 | package com.dxg.msns.admin.service;
2 |
3 | import com.dxg.msns.admin.pojo.Admin;
4 | import com.dxg.msns.auth.entity.UserInfo;
5 | import com.dxg.msns.common.pojo.PageResult;
6 |
7 | import java.util.List;
8 |
9 | /**
10 | * (Admin)表服务接口
11 | *
12 | * @author makejava
13 | * @since 2020-03-10 10:54:36
14 | */
15 | public interface AdminService {
16 |
17 | /**
18 | * 分页查询数据
19 | * @param key
20 | * @param page
21 | * @param rows
22 | * @param sortBy
23 | * @param desc
24 | * @param isAll
25 | * @return
26 | */
27 | PageResult queryAdminsByPage(String key, Integer page, Integer rows, String[] sortBy, Boolean[] desc, Boolean isAll);
28 |
29 | /**
30 | * 更新管理员
31 | * @param admin
32 | */
33 | void updateAdmin(Admin admin);
34 |
35 | /**
36 | * 删除管理员
37 | * @param admin
38 | */
39 | void deleteAdmin(Admin admin);
40 |
41 | /**
42 | * 根据昵称查找管理员
43 | * @param admin
44 | * @return
45 | */
46 | boolean findAdminByName(Admin admin);
47 |
48 | /**
49 | * 新增管理员
50 | * @param admin
51 | */
52 | void saveAdmin(Admin admin);
53 |
54 | /**
55 | * 验证用户名和密码
56 | * @param aname
57 | * @param apassword
58 | * @return
59 | */
60 | String authentication(String aname, String apassword);
61 |
62 | /**
63 | * 根据用户信息查询管理员是否存在
64 | * @param userInfo
65 | * @return
66 | */
67 | Admin getAdmin(UserInfo userInfo);
68 | }
--------------------------------------------------------------------------------
/msns-admin/msns-admin-service/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 | server:
2 | port: 8084
3 | spring:
4 | application:
5 | name: admin-service
6 | datasource:
7 | url: jdbc:mysql:///msns?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC
8 | username: root
9 | password: root
10 | driver-class-name: com.mysql.jdbc.Driver
11 | hikari:
12 | max-lifetime: 28830000 # 一个连接的生命时长(毫秒),超时而且没被使用则被释放(retired),缺省:30分钟,建议设置比数据库超时时长少30秒,参考MySQL wait_timeout参数(show variables like '%timeout%';)
13 | maximum-pool-size: 9 # 连接池中允许的最大连接数。缺省值:10;推荐的公式:((core_count * 2) + effective_spindle_count)
14 | eureka:
15 | client:
16 | service-url:
17 | defaultZone: http://127.0.0.1:10086/eureka
18 | instance:
19 | lease-expiration-duration-in-seconds: 10 #10秒不发送就过期
20 | lease-renewal-interval-in-seconds: 5 #5秒发送一次心跳
21 | logging:
22 | level:
23 | root: DEBUG
24 | msns:
25 | admin:
26 | jwt:
27 | secret: msns@Login(Auth}*^31)&Dxg% #登录校验的密钥
28 | pubKeyPath: D:\\tmp\\rsa\\rsa.pub # 公钥地址
29 | priKeyPath: D:\\tmp\\rsa\\rsa.pri # 私钥地址
30 | expire: 1440 # 过期时间,1天
31 | cookieName: MSNS_ADMIN_TOKEN
32 | cookieMaxAge: 86400 #cookie生存时间1天
--------------------------------------------------------------------------------
/msns-admin/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | msns
7 | com.dxg.msns.parent
8 | 1.0-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | com.dxg.msns.admin
13 | msns-admin
14 | pom
15 |
16 | msns-admin-interface
17 | msns-admin-service
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/msns-auth/msns-auth-common/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | msns-auth
7 | com.dxg.msns.auth
8 | 1.0-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | com.dxg.msns.auth
13 | msns-auth-common
14 |
15 |
16 | org.apache.commons
17 | commons-lang3
18 |
19 |
20 | io.jsonwebtoken
21 | jjwt
22 | 0.9.0
23 |
24 |
25 | joda-time
26 | joda-time
27 |
28 |
29 | junit
30 | junit
31 | test
32 |
33 |
34 | javax.xml.bind
35 | jaxb-api
36 | 2.3.0
37 |
38 |
39 | com.sun.xml.bind
40 | jaxb-impl
41 | 2.3.0
42 |
43 |
44 | com.sun.xml.bind
45 | jaxb-core
46 | 2.3.0
47 |
48 |
49 | javax.activation
50 | activation
51 | 1.1.1
52 |
53 |
54 | org.slf4j
55 | slf4j-api
56 |
57 |
58 | org.apache.tomcat.embed
59 | tomcat-embed-core
60 |
61 |
62 |
63 |
64 |
65 |
--------------------------------------------------------------------------------
/msns-auth/msns-auth-common/src/main/java/com/dxg/msns/auth/entity/UserInfo.java:
--------------------------------------------------------------------------------
1 | package com.dxg.msns.auth.entity;
2 |
3 | public class UserInfo {
4 | private Integer id;
5 | private String uid;
6 | private String uname;
7 | private String avatarUrl;
8 |
9 | public UserInfo() {
10 | }
11 |
12 | public UserInfo(Integer id, String uname) {
13 | this.id = id;
14 | this.uname = uname;
15 | }
16 |
17 | public UserInfo(Integer id, String uid, String uname) {
18 | this.id = id;
19 | this.uid = uid;
20 | this.uname = uname;
21 | }
22 |
23 | public UserInfo(Integer id, String uid, String uname, String avatarUrl) {
24 | this.id = id;
25 | this.uid = uid;
26 | this.uname = uname;
27 | this.avatarUrl = avatarUrl;
28 | }
29 |
30 | public Integer getId() {
31 | return id;
32 | }
33 |
34 | public void setId(Integer id) {
35 | this.id = id;
36 | }
37 |
38 | public String getUid() {
39 | return uid;
40 | }
41 |
42 | public void setUid(String uid) {
43 | this.uid = uid;
44 | }
45 |
46 | public String getUname() {
47 | return uname;
48 | }
49 |
50 | public void setUname(String uname) {
51 | this.uname = uname;
52 | }
53 |
54 | public String getAvatarUrl() {
55 | return avatarUrl;
56 | }
57 |
58 | public void setAvatarUrl(String avatarUrl) {
59 | this.avatarUrl = avatarUrl;
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/msns-auth/msns-auth-common/src/main/java/com/dxg/msns/auth/utils/JwtConstans.java:
--------------------------------------------------------------------------------
1 | package com.dxg.msns.auth.utils;
2 |
3 | public abstract class JwtConstans {
4 | public static final String JWT_KEY_ID = "id";
5 | public static final String JWT_KEY_UID = "uid";
6 | public static final String JWT_KEY_AVATAR_URL = "avatarUrl";
7 | public static final String JWT_KEY_USER_NAME = "uname";
8 |
9 | }
--------------------------------------------------------------------------------
/msns-auth/msns-auth-common/src/main/java/com/dxg/msns/auth/utils/ObjectUtils.java:
--------------------------------------------------------------------------------
1 | package com.dxg.msns.auth.utils;
2 |
3 | import org.apache.commons.lang3.StringUtils;
4 |
5 | /**
6 | * 从jwt解析得到的数据是Object类型,转换为具体类型可能出现空指针,
7 | * 这个工具类进行了一些转换
8 | */
9 | public class ObjectUtils {
10 |
11 | public static String toString(Object obj) {
12 | if (obj == null) {
13 | return null;
14 | }
15 | return obj.toString();
16 | }
17 |
18 | public static Long toLong(Object obj) {
19 | if (obj == null) {
20 | return 0L;
21 | }
22 | if (obj instanceof Double || obj instanceof Float) {
23 | return Long.valueOf(StringUtils.substringBefore(obj.toString(), "."));
24 | }
25 | if (obj instanceof Number) {
26 | return Long.valueOf(obj.toString());
27 | }
28 | if (obj instanceof String) {
29 | return Long.valueOf(obj.toString());
30 | } else {
31 | return 0L;
32 | }
33 | }
34 |
35 | public static Integer toInt(Object obj) {
36 | return toLong(obj).intValue();
37 | }
38 | }
--------------------------------------------------------------------------------
/msns-auth/msns-auth-common/src/test/java/com/dxg/msns/auth/test/JwtTest.java:
--------------------------------------------------------------------------------
1 | package com.dxg.msns.auth.test;
2 |
3 | import com.dxg.msns.auth.entity.UserInfo;
4 | import com.dxg.msns.auth.utils.JwtUtils;
5 | import com.dxg.msns.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 |
12 |
13 | public class JwtTest {
14 |
15 | private static final String pubKeyPath = "D:\\tmp\\rsa\\rsa.pub";
16 |
17 | private static final String priKeyPath = "D:\\tmp\\rsa\\rsa.pri";
18 |
19 | private PublicKey publicKey;
20 |
21 | private PrivateKey privateKey;
22 |
23 | @org.junit.Test
24 | public void testRsa() throws Exception {
25 | RsaUtils.generateKey(pubKeyPath, priKeyPath, "234");
26 | }
27 |
28 | @Before
29 | public void testGetRsa() throws Exception {
30 | this.publicKey = RsaUtils.getPublicKey(pubKeyPath);
31 | this.privateKey = RsaUtils.getPrivateKey(priKeyPath);
32 | }
33 |
34 | @Test
35 | public void testGenerateToken() throws Exception {
36 | // 生成token
37 | String token = JwtUtils.generateToken(new UserInfo(20, "01","jack"), privateKey, 5);
38 | System.out.println("token = " + token);
39 | }
40 |
41 | @Test
42 | public void testParseToken() throws Exception {
43 | String token = "eyJhbGciOiJSUzI1NiJ9.eyJpZCI6MjAsInVuYW1lIjoiamFjayIsInVpZCI6IjAxIiwiZXhwIjoxNTg0NjAyOTIyfQ.FRYlKLKekYPfpDzz5LpyMzepkWqVLBANbiL_o8GeWwJXzCkDdTR5JJRazEzeQZuzFuvxMfKLQM17ZvVjJlmJPAzn7EtAqt6co4yt3IIa1iMz4JRJ_IUgRJ1vctjAYH61r4bhbjZgtlKsAu-bIxmfaqhO5AxmC-rQXF4npPnl9V0";
44 |
45 | // 解析token
46 | UserInfo user = JwtUtils.getInfoFromToken(token, publicKey);
47 | System.out.println("id: " + user.getId());
48 | System.out.println("uid:"+user.getUid());
49 | System.out.println("userName: " + user.getUname());
50 | }
51 | }
--------------------------------------------------------------------------------
/msns-auth/msns-auth-service/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | msns-auth
7 | com.dxg.msns.auth
8 | 1.0-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | com.dxg.msns.auth
13 | msns-auth-service
14 |
15 |
16 |
17 | org.springframework.cloud
18 | spring-cloud-starter-netflix-eureka-client
19 |
20 |
21 | org.springframework.cloud
22 | spring-cloud-starter-openfeign
23 |
24 |
25 | org.springframework.boot
26 | spring-boot-starter-web
27 |
28 |
29 | com.dxg.msns.common
30 | msns-common
31 | 1.0-SNAPSHOT
32 |
33 |
34 | com.dxg.msns.auth
35 | msns-auth-common
36 | 1.0-SNAPSHOT
37 |
38 |
39 | org.springframework.boot
40 | spring-boot-starter-test
41 |
42 |
43 | org.apache.tomcat.embed
44 | tomcat-embed-core
45 |
46 |
47 | com.dxg.msns.user
48 | msns-user-interface
49 | 1.0-SNAPSHOT
50 |
51 |
52 |
--------------------------------------------------------------------------------
/msns-auth/msns-auth-service/src/main/java/com/dxg/msns/auth/MSNSAuthApplication.java:
--------------------------------------------------------------------------------
1 | package com.dxg.msns.auth;
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 | import org.springframework.cloud.openfeign.FeignClient;
9 |
10 | @SpringBootApplication(exclude= {DataSourceAutoConfiguration.class})
11 | @EnableDiscoveryClient
12 | @EnableFeignClients
13 | public class MSNSAuthApplication {
14 | public static void main(String[] args) {
15 | SpringApplication.run(MSNSAuthApplication.class,args);
16 | }
17 | }
18 |
19 |
--------------------------------------------------------------------------------
/msns-auth/msns-auth-service/src/main/java/com/dxg/msns/auth/client/UserClient.java:
--------------------------------------------------------------------------------
1 | package com.dxg.msns.auth.client;
2 |
3 | import com.dxg.msns.user.api.UserApi;
4 | import org.springframework.cloud.openfeign.FeignClient;
5 |
6 | @FeignClient("user-service")
7 | public interface UserClient extends UserApi {
8 | }
9 |
--------------------------------------------------------------------------------
/msns-auth/msns-auth-service/src/main/java/com/dxg/msns/auth/service/AuthService.java:
--------------------------------------------------------------------------------
1 | package com.dxg.msns.auth.service;
2 |
3 | import com.dxg.msns.auth.entity.UserInfo;
4 | import com.dxg.msns.user.pojo.User;
5 |
6 | public interface AuthService {
7 | /**
8 | * 验证用户,返回token
9 | * @param uname
10 | * @param upassword
11 | * @return
12 | */
13 | String authentication(String uname, String upassword);
14 |
15 | /**
16 | * 根据token中的用户信息获取用户详细信息
17 | * @param userInfo
18 | * @return
19 | */
20 | User getUser(UserInfo userInfo);
21 |
22 | /**
23 | * 修改密码
24 | * @param upassword
25 | * @param newPassword
26 | * @param id
27 | */
28 | void changePwd(String upassword, String newPassword, Integer id);
29 | }
30 |
--------------------------------------------------------------------------------
/msns-auth/msns-auth-service/src/main/java/com/dxg/msns/auth/service/impl/AuthServiceImpl.java:
--------------------------------------------------------------------------------
1 | package com.dxg.msns.auth.service.impl;
2 |
3 | import com.dxg.msns.auth.client.UserClient;
4 | import com.dxg.msns.auth.entity.UserInfo;
5 | import com.dxg.msns.auth.properties.JwtProperties;
6 | import com.dxg.msns.auth.service.AuthService;
7 | import com.dxg.msns.auth.utils.JwtUtils;
8 | import com.dxg.msns.user.pojo.User;
9 | import org.springframework.beans.factory.annotation.Autowired;
10 | import org.springframework.stereotype.Service;
11 |
12 | @Service
13 | public class AuthServiceImpl implements AuthService {
14 | @Autowired
15 | private UserClient userClient;
16 |
17 | @Autowired
18 | private JwtProperties jwtProperties;
19 |
20 | @Override
21 | public String authentication(String uname, String upassword) {
22 | //如果有查询结果
23 | try {
24 | User user = this.userClient.login(uname, upassword);
25 | //如果查询为空,直接返回为null
26 | if (user == null) {
27 | return null;
28 | }
29 | String token = JwtUtils.generateToken(new UserInfo(user.getId(), user.getUid(), user.getUname(),user.getAvatarUrl()), jwtProperties.getPrivateKey(), jwtProperties.getExpire());
30 | return token;
31 | } catch (Exception e) {
32 | e.printStackTrace();
33 | return null;
34 | }
35 | }
36 |
37 | /**
38 | * 根据token中的用户信息获取用户详细信息
39 | *
40 | * @param userInfo
41 | * @return
42 | */
43 | @Override
44 | public User getUser(UserInfo userInfo) {
45 | User user = userClient.queryById(userInfo.getId());
46 | return user;
47 | }
48 |
49 | /**
50 | * 修改密码
51 | *
52 | * @param upassword
53 | * @param newPassword
54 | * @param id
55 | */
56 | @Override
57 | public void changePwd(String upassword, String newPassword, Integer id) {
58 | this.userClient.changePwdById(id,upassword,newPassword);
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/msns-auth/msns-auth-service/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 | server:
2 | port: 8090
3 | spring:
4 | application:
5 | name: auth-service
6 | eureka:
7 | client:
8 | service-url:
9 | defaultZone: http://127.0.0.1:10086/eureka
10 | registry-fetch-interval-seconds: 10
11 | instance:
12 | lease-expiration-duration-in-seconds: 10
13 | lease-renewal-interval-in-seconds: 5
14 | msns:
15 | jwt:
16 | secret: msns@Login(Auth}*^31)&Dxg% #登录校验的密钥
17 | pubKeyPath: D:\\tmp\\rsa\\rsa.pub # 公钥地址
18 | priKeyPath: D:\\tmp\\rsa\\rsa.pri # 私钥地址
19 | expire: 1440 # 过期时间,1天
20 | cookieName: MSNS_TOKEN
21 | cookieMaxAge: 86400 #cookie生存时间1天
22 | logging:
23 | level:
24 | root: DEBUG
--------------------------------------------------------------------------------
/msns-auth/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | msns
7 | com.dxg.msns.parent
8 | 1.0-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | com.dxg.msns.auth
13 | msns-auth
14 |
15 | pom
16 |
17 | msns-auth-common
18 | msns-auth-service
19 |
20 |
--------------------------------------------------------------------------------
/msns-comment/msns-comment-interface/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | msns-comment
7 | com.dxg.msns.comment
8 | 1.0-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | msns-comment-interface
13 |
14 |
15 | org.springframework
16 | spring-web
17 |
18 |
19 | javax.persistence
20 | persistence-api
21 | 1.0
22 |
23 |
24 | com.fasterxml.jackson.core
25 | jackson-annotations
26 |
27 |
28 | com.dxg.msns.common
29 | msns-common
30 | 1.0-SNAPSHOT
31 | compile
32 |
33 |
34 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/msns-comment/msns-comment-interface/src/main/java/com/dxg/msns/comment/api/CommentApi.java:
--------------------------------------------------------------------------------
1 | package com.dxg.msns.comment.api;
2 |
3 | import org.springframework.http.ResponseEntity;
4 | import org.springframework.web.bind.annotation.PathVariable;
5 | import org.springframework.web.bind.annotation.RequestMapping;
6 |
7 | import java.util.Date;
8 |
9 | public interface CommentApi {
10 | @RequestMapping("counts/{id}")
11 | public Integer queryCountsByDynamicId(@PathVariable("id")Integer dynamicId);
12 | @RequestMapping("recent/{id}")
13 | public Date queryRecentCreateDateByDynamicId(@PathVariable("id")Integer dynamicId);
14 | }
15 |
--------------------------------------------------------------------------------
/msns-comment/msns-comment-interface/src/main/resources/application.yml:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dodudo/msns/beccf0fd921e001c51fb82b00adcd9297a6008ac/msns-comment/msns-comment-interface/src/main/resources/application.yml
--------------------------------------------------------------------------------
/msns-comment/msns-comment-service/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | msns-comment
7 | com.dxg.msns.comment
8 | 1.0-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | msns-comment-service
13 |
14 |
15 |
16 |
17 | org.springframework.boot
18 | spring-boot-starter-web
19 |
20 |
21 |
22 | org.springframework.cloud
23 | spring-cloud-starter-netflix-eureka-client
24 |
25 |
26 |
27 | org.mybatis.spring.boot
28 | mybatis-spring-boot-starter
29 |
30 |
31 |
32 | tk.mybatis
33 | mapper-spring-boot-starter
34 |
35 |
36 |
37 | com.github.pagehelper
38 | pagehelper-spring-boot-starter
39 |
40 |
41 |
42 | org.springframework.boot
43 | spring-boot-starter-jdbc
44 |
45 |
46 |
47 | mysql
48 | mysql-connector-java
49 |
50 |
51 |
52 |
53 | org.springframework.boot
54 | spring-boot-starter-actuator
55 |
56 |
57 | com.dxg.msns.comment
58 | msns-comment-interface
59 | 1.0-SNAPSHOT
60 |
61 |
62 | com.dxg.msns.common
63 | msns-common
64 | 1.0-SNAPSHOT
65 | compile
66 |
67 |
68 | org.springframework.boot
69 | spring-boot-starter-amqp
70 |
71 |
72 |
--------------------------------------------------------------------------------
/msns-comment/msns-comment-service/src/main/java/com/dxg/msns/comment/MSNSCommentServiceApplication.java:
--------------------------------------------------------------------------------
1 | package com.dxg.msns.comment;
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 | @SpringBootApplication
9 | @EnableDiscoveryClient
10 | @MapperScan("com.dxg.msns.comment.mapper")
11 | public class MSNSCommentServiceApplication {
12 | public static void main(String[] args) {
13 | SpringApplication.run(MSNSCommentServiceApplication.class);
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/msns-comment/msns-comment-service/src/main/java/com/dxg/msns/comment/mapper/CommentMapper.java:
--------------------------------------------------------------------------------
1 | package com.dxg.msns.comment.mapper;
2 |
3 | import com.dxg.msns.comment.pojo.Comment;
4 | import org.apache.commons.lang.ArrayUtils;
5 | import org.apache.ibatis.annotations.Param;
6 | import org.apache.ibatis.annotations.Select;
7 | import org.apache.ibatis.annotations.Update;
8 | import org.apache.ibatis.annotations.UpdateProvider;
9 | import tk.mybatis.mapper.common.Mapper;
10 |
11 | import java.util.Date;
12 | import java.util.Map;
13 |
14 | public interface CommentMapper extends Mapper {
15 | @Select("select max(comment_date) from comment where status = '1' and dynamic_id = #{dynamic_id} group by dynamic_id")
16 | Date queryRecentCreateDateByDynamicId(@Param("dynamic_id") Integer dynamicId);
17 |
18 | /**
19 | * 根据id改变状态(删除)
20 | *
21 | * @param id
22 | */
23 | @Update("update comment set status = '-1' where id = #{id}")
24 | void updateDeleteStateById(@Param("id") Long id);
25 |
26 | /**
27 | * 根据ids修改状态
28 | *
29 | * @param ids
30 | * @param status
31 | */
32 | @UpdateProvider(type = Provider.class, method = "batchUpdate")
33 | void updateStateByIds(Long[] ids, String status,String respondentId);
34 |
35 | class Provider {
36 | //批量修改
37 | public String batchUpdate(Map map) {
38 | Long[] ids = (Long[]) map.get("param1");
39 | String status = (String) map.get("param2");
40 | String respondentId = (String) map.get("param3");
41 | StringBuilder sb = new StringBuilder();
42 | if (ArrayUtils.isEmpty(ids)) {
43 | sb.append("update comment set status = '" + status + "' where respondent_id = '"+respondentId+"' and status != '-1' and status != '0'");
44 | } else {
45 | sb.append("update comment set status = '" + status + "' where respondent_id = '"+respondentId+"' and status != '-1' and status != '0' and id in (");
46 | for (int i = 0; i < ids.length; i++) {
47 | sb.append(ids[i]);
48 | if (i < ids.length - 1) {
49 | sb.append(",");
50 | }
51 | }
52 | sb.append(")");
53 | }
54 | return sb.toString();
55 | }
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/msns-comment/msns-comment-service/src/main/java/com/dxg/msns/comment/service/CommentService.java:
--------------------------------------------------------------------------------
1 | package com.dxg.msns.comment.service;
2 |
3 | import com.dxg.msns.comment.pojo.Comment;
4 | import com.dxg.msns.common.pojo.PageResult;
5 |
6 | import java.util.Date;
7 | import java.util.List;
8 |
9 | public interface CommentService {
10 | /**
11 | * 根据动态id查询评论
12 | * @param dynamicId
13 | * @return
14 | */
15 | List queryByDynamicId(Integer dynamicId);
16 |
17 | /**
18 | * 根据动态id查询评论数
19 | * @param dynamicId
20 | * @return
21 | */
22 | Integer queryCountsByDynamicId(Integer dynamicId);
23 |
24 | /**
25 | * 根据动态id查询最新发布评论
26 | * @param dynamicId
27 | * @return
28 | */
29 | Date queryRecentCreateDateByDynamicId(Integer dynamicId);
30 |
31 | /**
32 | * 根据用户id查询评论
33 | * @param uid
34 | * @return
35 | */
36 | List queryByUid(String uid);
37 |
38 | /**
39 | * 根据分页查询
40 | * @param key
41 | * @param page
42 | * @param rows
43 | * @param sortBy
44 | * @param desc
45 | * @param isAll
46 | * @param comment
47 | * @return
48 | */
49 | PageResult queryByPage(String key, Integer page, Integer rows, String[] sortBy, Boolean[] desc, Boolean isAll, Comment comment);
50 |
51 | /**
52 | * 添加评论
53 | * @param comment
54 | */
55 | Comment add(Comment comment);
56 |
57 | /**
58 | * 根据id查询评论
59 | * @param id
60 | * @return
61 | */
62 | Comment queryById(Integer id);
63 |
64 |
65 | /**
66 | * 根据id修改状态
67 | * @param id
68 | */
69 | void updateDeleteStateById(Long id,Integer dynamicId);
70 |
71 | /**
72 | * 根据id批量修改状态,已读
73 | * @param ids
74 | */
75 | void updateStateByIds(Long[] ids,String status,String respondentId);
76 |
77 | /**
78 | * 根据回复者id查询目前用户未读消息次数
79 | * @param respondentId
80 | * @return
81 | */
82 | Integer queryCountsByRespondentId(String respondentId);
83 | }
84 |
--------------------------------------------------------------------------------
/msns-comment/msns-comment-service/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 | server:
2 | port: 8086
3 | spring:
4 | application:
5 | name: comment-service
6 | datasource:
7 | url: jdbc:mysql:///msns?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC
8 | username: root
9 | password: root
10 | driver-class-name: com.mysql.jdbc.Driver
11 | hikari:
12 | max-lifetime: 28830000 # 一个连接的生命时长(毫秒),超时而且没被使用则被释放(retired),缺省:30分钟,建议设置比数据库超时时长少30秒,参考MySQL wait_timeout参数(show variables like '%timeout%';)
13 | maximum-pool-size: 9 # 连接池中允许的最大连接数。缺省值:10;推荐的公式:((core_count * 2) + effective_spindle_count)
14 | rabbitmq:
15 | username: msns
16 | password: msns
17 | virtual-host: /msns
18 | template:
19 | exchange: msns.dynamic.exchange
20 | publisher-confirms: true #生产者确认机制,确保消息会正确发送,如果发送失败会有错误回执,从而触发重
21 | eureka:
22 | client:
23 | service-url:
24 | defaultZone: http://127.0.0.1:10086/eureka
25 | instance:
26 | lease-expiration-duration-in-seconds: 10 #10秒不发送就过期
27 | lease-renewal-interval-in-seconds: 5 #5秒发送一次心跳
28 | logging:
29 | level:
30 | root: DEBUG
--------------------------------------------------------------------------------
/msns-comment/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | msns
7 | com.dxg.msns.parent
8 | 1.0-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | com.dxg.msns.comment
13 | msns-comment
14 | pom
15 |
16 | msns-comment-interface
17 | msns-comment-service
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/msns-common/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | msns
7 | com.dxg.msns.parent
8 | 1.0-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | com.dxg.msns.common
13 | msns-common
14 |
15 |
16 |
17 |
18 | tk.mybatis
19 | mapper-spring-boot-starter
20 |
21 |
22 | commons-codec
23 | commons-codec
24 |
25 |
26 | org.apache.commons
27 | commons-lang3
28 |
29 |
30 |
--------------------------------------------------------------------------------
/msns-common/src/main/java/com/dxg/msns/common/pojo/PageResult.java:
--------------------------------------------------------------------------------
1 | package com.dxg.msns.common.pojo;
2 |
3 | import java.util.List;
4 |
5 | public class PageResult {
6 | private Long total; //总条数
7 | private Integer totalPage; //总页数
8 | private List items; //当前页数据
9 |
10 | public PageResult() {
11 | }
12 |
13 | public PageResult(Long total, List items) {
14 | this.total = total;
15 | this.items = items;
16 | }
17 |
18 | public PageResult(Long total, Integer totalPage, List items) {
19 | this.total = total;
20 | this.totalPage = totalPage;
21 | this.items = items;
22 | }
23 |
24 | public Long getTotal() {
25 | return total;
26 | }
27 |
28 | public void setTotal(Long total) {
29 | this.total = total;
30 | }
31 |
32 | public Integer getTotalPage() {
33 | return totalPage;
34 | }
35 |
36 | public void setTotalPage(Integer totalPage) {
37 | this.totalPage = totalPage;
38 | }
39 |
40 | public List getItems() {
41 | return items;
42 | }
43 |
44 | public void setItems(List items) {
45 | this.items = items;
46 | }
47 |
48 | @Override
49 | public String toString() {
50 | return "PageResult{" +
51 | "total=" + total +
52 | ", totalPage=" + totalPage +
53 | ", items=" + items +
54 | '}';
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/msns-common/src/main/java/com/dxg/msns/common/util/BatchExampleProvider.java:
--------------------------------------------------------------------------------
1 | package com.dxg.msns.common.util;
2 |
3 | import org.apache.ibatis.mapping.MappedStatement;
4 | import tk.mybatis.mapper.entity.EntityColumn;
5 | import tk.mybatis.mapper.mapperhelper.EntityHelper;
6 | import tk.mybatis.mapper.mapperhelper.MapperHelper;
7 | import tk.mybatis.mapper.mapperhelper.SqlHelper;
8 | import tk.mybatis.mapper.provider.ExampleProvider;
9 |
10 | import java.util.Set;
11 |
12 | /**
13 | * 批量更新的sqlProvider
14 | */
15 | public class BatchExampleProvider extends ExampleProvider {
16 | public BatchExampleProvider(Class> mapperClass, MapperHelper mapperHelper) {
17 | super(mapperClass, mapperHelper);
18 | }
19 | /**
20 | * 拼update sql, 使用case when方式,id为主键
21 | *
22 | * @param ms
23 | * @return
24 | */
25 | public String updateBatchByPrimaryKeySelective(MappedStatement ms) {
26 | final Class> entityClass = getEntityClass(ms);
27 | //开始拼sql
28 | StringBuilder sql = new StringBuilder();
29 | sql.append(SqlHelper.updateTable(entityClass, tableName(entityClass)));
30 | sql.append("");
31 |
32 | //获取全部列
33 | Set columnList = EntityHelper.getColumns(entityClass);
34 | for (EntityColumn column : columnList) {
35 | if (!column.isId() && column.isUpdatable()) {
36 | sql.append(" ");
37 | sql.append(" ");
38 | sql.append(" ");
39 | sql.append(" when id=#{i.id} then #{i."+column.getEntityField().getName()+"}");
40 | sql.append(" ");
41 | sql.append(" ");
42 | sql.append(" ");
43 | }
44 | }
45 |
46 | sql.append("");
47 | sql.append("WHERE");
48 | sql.append(" id IN ");
49 | sql.append("");
50 | sql.append("");
51 | sql.append("#{i.id}");
52 | sql.append("");
53 | sql.append("");
54 |
55 | return sql.toString();
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/msns-common/src/main/java/com/dxg/msns/common/util/CodecUtils.java:
--------------------------------------------------------------------------------
1 | package com.dxg.msns.common.util;
2 |
3 | import org.apache.commons.codec.digest.DigestUtils;
4 | import org.apache.commons.lang3.StringUtils;
5 |
6 | import java.util.UUID;
7 |
8 | public class CodecUtils {
9 |
10 |
11 |
12 | public static String md5Hex(String data,String salt) {
13 | if (StringUtils.isBlank(salt)) {
14 | salt = data.hashCode() + "";
15 | }
16 | return DigestUtils.md5Hex(salt + DigestUtils.md5Hex(data));
17 | }
18 |
19 | public static String shaHex(String data, String salt) {
20 | if (StringUtils.isBlank(salt)) {
21 | salt = data.hashCode() + "";
22 | }
23 | return DigestUtils.sha512Hex(salt + DigestUtils.sha512Hex(data));
24 | }
25 |
26 | public static String generateSalt(){
27 | return StringUtils.replace(UUID.randomUUID().toString(), "-", "");
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/msns-common/src/main/java/com/dxg/msns/common/util/NumberUtils.java:
--------------------------------------------------------------------------------
1 | package com.dxg.msns.common.util;
2 |
3 | import java.util.Random;
4 |
5 | public class NumberUtils {
6 | public static String generateCode(int len){
7 | len = Math.min(len,6);
8 | int min = Double.valueOf(Math.pow(10,len-1)).intValue();
9 | int num = new Random().nextInt(Double.valueOf(Math.pow(10,len+1)).intValue()-1)+min;
10 | return String.valueOf(num).substring(0,len);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/msns-common/src/main/java/com/dxg/msns/common/util/UUIDUtils.java:
--------------------------------------------------------------------------------
1 | package com.dxg.msns.common.util;
2 |
3 | import java.util.UUID;
4 |
5 | public class UUIDUtils {
6 | public static String getUUID(){
7 | return UUID.randomUUID().toString().replace("-", "").toLowerCase();
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/msns-common/src/main/java/com/dxg/msns/common/util/UnderlineHump.java:
--------------------------------------------------------------------------------
1 | package com.dxg.msns.common.util;
2 |
3 | public class UnderlineHump {
4 | /***
5 | * 下划线命名转为驼峰命名
6 | *
7 | * @param para
8 | * 下划线命名的字符串
9 | */
10 |
11 | public static String UnderlineToHump(String para){
12 | StringBuilder result=new StringBuilder();
13 | String a[]=para.split("_");
14 | for(String s:a){
15 | if (!para.contains("_")) {
16 | result.append(s);
17 | continue;
18 | }
19 | if(result.length()==0){
20 | result.append(s);
21 | }else{
22 | result.append(s.substring(0, 1).toUpperCase());
23 | result.append(s.substring(1));
24 | }
25 | }
26 | return result.toString();
27 | }
28 |
29 |
30 |
31 | /***
32 | * 驼峰命名转为下划线命名
33 | *
34 | * @param para
35 | * 驼峰命名的字符串
36 | */
37 |
38 | public static String HumpToUnderline(String para){
39 | StringBuilder sb=new StringBuilder(para);
40 | int temp=0;//定位
41 | if (!para.contains("_")) {
42 | for(int i=0;i {
10 | /**
11 | * 根据Example条件批量更新实体`record`包含的不是null的属性值
12 | *
13 | * @return
14 | */
15 | @UpdateProvider(type = BatchExampleProvider.class, method = "dynamicSQL")
16 | Integer updateBatchByPrimaryKeySelective(List extends T> recordList);
17 | }
18 |
--------------------------------------------------------------------------------
/msns-common/src/main/resources/application.yml:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dodudo/msns/beccf0fd921e001c51fb82b00adcd9297a6008ac/msns-common/src/main/resources/application.yml
--------------------------------------------------------------------------------
/msns-dynamic/msns-dynamic-interface/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | msns-dynamic
7 | com.dxg.msns.dynamic
8 | 1.0-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | msns-dynamic-interface
13 |
14 |
15 | org.springframework
16 | spring-web
17 |
18 |
19 | javax.persistence
20 | persistence-api
21 | 1.0
22 |
23 |
24 | com.fasterxml.jackson.core
25 | jackson-annotations
26 |
27 |
28 | com.dxg.msns.common
29 | msns-common
30 | 1.0-SNAPSHOT
31 | compile
32 |
33 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/msns-dynamic/msns-dynamic-interface/src/main/java/com/dxg/msns/dynamic/api/DynamicApi.java:
--------------------------------------------------------------------------------
1 | package com.dxg.msns.dynamic.api;
2 |
3 | import com.dxg.msns.common.pojo.PageResult;
4 | import com.dxg.msns.dynamic.pojo.Dynamic;
5 | import org.springframework.http.ResponseEntity;
6 | import org.springframework.web.bind.annotation.GetMapping;
7 | import org.springframework.web.bind.annotation.PathVariable;
8 | import org.springframework.web.bind.annotation.RequestMapping;
9 | import org.springframework.web.bind.annotation.RequestParam;
10 |
11 | import javax.persistence.EntityResult;
12 |
13 |
14 | public interface DynamicApi {
15 | /**
16 | * 分页查询所有分类
17 | * @param key
18 | * @param page
19 | * @param rows
20 | * @param sortBy
21 | * @param desc
22 | * @return
23 | */
24 | @RequestMapping("page")
25 | public PageResult queryDynamicsByPage(
26 | @RequestParam(value = "key",required = false)String key,
27 | @RequestParam(value = "page",defaultValue = "1")Integer page,
28 | @RequestParam(value = "rows",defaultValue = "5")Integer rows,
29 | @RequestParam(value = "sortBy",required = false)String sortBy[],
30 | @RequestParam(value = "desc",required = false)Boolean desc[],
31 | @RequestParam(value = "isAll",required = false)Boolean isAll,
32 | @RequestParam(value = "uids",required = false)String[] uids,
33 | @RequestParam(value = "ids",required = false)Integer[] ids
34 | );
35 | /**
36 | * 根据id查找
37 | * @param id
38 | * @return
39 | */
40 | @RequestMapping("/queryById/{id}")
41 | public Dynamic queryById(@PathVariable("id") Integer id);
42 |
43 | /**
44 | * 根据用户id统计该用户发的动态数量
45 | * @param uid
46 | * @return
47 | */
48 | @RequestMapping("/countByUid/{uid}")
49 | public Integer queryCountByUid(@PathVariable("uid") String uid);
50 | }
51 |
--------------------------------------------------------------------------------
/msns-dynamic/msns-dynamic-interface/src/main/java/com/dxg/msns/dynamic/api/DynamicTypeApi.java:
--------------------------------------------------------------------------------
1 | package com.dxg.msns.dynamic.api;
2 |
3 | import org.springframework.http.ResponseEntity;
4 | import org.springframework.web.bind.annotation.PathVariable;
5 | import org.springframework.web.bind.annotation.RequestMapping;
6 |
7 | import java.util.List;
8 |
9 | @RequestMapping("category")
10 | public interface DynamicTypeApi {
11 | /**
12 | * 查询所有分类名
13 | * @return
14 | */
15 | @RequestMapping("names")
16 | List queryAllDynamiTypeNames();
17 | /**
18 | * 根据id查询名称
19 | * @param id
20 | * @return
21 | */
22 | @RequestMapping("queryNameById/{id}")
23 | public String queryNameById(@PathVariable("id") Integer id);
24 | }
25 |
--------------------------------------------------------------------------------
/msns-dynamic/msns-dynamic-interface/src/main/java/com/dxg/msns/dynamic/pojo/Comment.java:
--------------------------------------------------------------------------------
1 | package com.dxg.msns.dynamic.pojo;
2 |
3 | import java.util.Date;
4 |
5 | public class Comment {
6 | private Long id;
7 | private Long pid;
8 | private String dynamicId;
9 | private String author;
10 | private String replyId;
11 | private String respondentId;
12 | private Date commentDate;
13 | private String commentContent;
14 | private String status;
15 |
16 |
17 | public Long getId() {
18 | return id;
19 | }
20 |
21 | public void setId(Long id) {
22 | this.id = id;
23 | }
24 |
25 | public Long getPid() {
26 | return pid;
27 | }
28 |
29 | public void setPid(Long pid) {
30 | this.pid = pid;
31 | }
32 |
33 | public String getDynamicId() {
34 | return dynamicId;
35 | }
36 |
37 | public void setDynamicId(String dynamicId) {
38 | this.dynamicId = dynamicId;
39 | }
40 |
41 | public String getAuthor() {
42 | return author;
43 | }
44 |
45 | public void setAuthor(String author) {
46 | this.author = author;
47 | }
48 |
49 | public String getReplyId() {
50 | return replyId;
51 | }
52 |
53 | public void setReplyId(String replyId) {
54 | this.replyId = replyId;
55 | }
56 |
57 | public String getRespondentId() {
58 | return respondentId;
59 | }
60 |
61 | public void setRespondentId(String respondentId) {
62 | this.respondentId = respondentId;
63 | }
64 |
65 | public Date getCommentDate() {
66 | return commentDate;
67 | }
68 |
69 | public void setCommentDate(Date commentDate) {
70 | this.commentDate = commentDate;
71 | }
72 |
73 | public String getCommentContent() {
74 | return commentContent;
75 | }
76 |
77 | public void setCommentContent(String commentContent) {
78 | this.commentContent = commentContent;
79 | }
80 |
81 | public String getStatus() {
82 | return status;
83 | }
84 |
85 | public void setStatus(String status) {
86 | this.status = status;
87 | }
88 |
89 | @Override
90 | public String toString() {
91 | return "Comment{" +
92 | "id=" + id +
93 | ", pid=" + pid +
94 | ", dynamicId='" + dynamicId + '\'' +
95 | ", author='" + author + '\'' +
96 | ", replyId='" + replyId + '\'' +
97 | ", respondentId='" + respondentId + '\'' +
98 | ", commentDate=" + commentDate +
99 | ", commentContent='" + commentContent + '\'' +
100 | ", status='" + status + '\'' +
101 | '}';
102 | }
103 | }
104 |
--------------------------------------------------------------------------------
/msns-dynamic/msns-dynamic-interface/src/main/java/com/dxg/msns/dynamic/pojo/DynamicType.java:
--------------------------------------------------------------------------------
1 | package com.dxg.msns.dynamic.pojo;
2 |
3 | import javax.persistence.*;
4 | import java.io.Serializable;
5 |
6 | @Table(name = "dynamic_type")
7 | public class DynamicType implements Serializable {
8 | @Id
9 | @GeneratedValue(strategy = GenerationType.IDENTITY)
10 | private Integer id;
11 | private String typeName;
12 | private String typeStatus;
13 | @Transient
14 | private Boolean typeStatusBoolean;
15 |
16 | public Boolean getTypeStatusBoolean() {
17 | if (typeStatusBoolean == null){
18 | if (this.typeStatus != null){
19 | if (this.typeStatus.equals("0")){
20 | this.typeStatusBoolean = false;
21 | }else if (this.typeStatus.equals("1")){
22 | this.typeStatusBoolean = true;
23 | }else {
24 | this.typeStatusBoolean = false;
25 | }
26 | }
27 | }
28 | return typeStatusBoolean;
29 | }
30 |
31 | public void setTypeStatusBoolean(Boolean typeStatusBoolean) {
32 |
33 | this.typeStatusBoolean = typeStatusBoolean;
34 | }
35 |
36 | public Integer getId() {
37 | return id;
38 | }
39 |
40 | public void setId(Integer id) {
41 | this.id = id;
42 | }
43 |
44 | public String getTypeName() {
45 | return typeName;
46 | }
47 |
48 | public void setTypeName(String typeName) {
49 | this.typeName = typeName;
50 | }
51 |
52 | public String getTypeStatus() {
53 | return typeStatus;
54 | }
55 |
56 | public void setTypeStatus(String typeStatus) {
57 | this.typeStatus = typeStatus;
58 | }
59 |
60 | @Override
61 | public String toString() {
62 | return "DynamicType{" +
63 | "id=" + id +
64 | ", typeName='" + typeName + '\'' +
65 | ", typeStatus='" + typeStatus + '\'' +
66 | ", typeStatusBoolean=" + typeStatusBoolean +
67 | '}';
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/msns-dynamic/msns-dynamic-interface/src/main/java/com/dxg/msns/dynamic/pojo/Report.java:
--------------------------------------------------------------------------------
1 | package com.dxg.msns.dynamic.pojo;
2 |
3 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
4 |
5 | import javax.persistence.GeneratedValue;
6 | import javax.persistence.GenerationType;
7 | import javax.persistence.Id;
8 | import javax.persistence.Table;
9 | import java.io.Serializable;
10 |
11 | @Table(name = "report")
12 | @JsonIgnoreProperties(value={"hibernateLazyInitializer","handler","fieldHandler"})
13 | public class Report implements Serializable {
14 | @Id
15 | @GeneratedValue(strategy = GenerationType.IDENTITY)
16 | private Integer id;
17 | private String dynamicId;
18 | private String reason;
19 |
20 | public Integer getId() {
21 | return id;
22 | }
23 |
24 | public void setId(Integer id) {
25 | this.id = id;
26 | }
27 |
28 | public String getDynamicId() {
29 | return dynamicId;
30 | }
31 |
32 | public void setDynamicId(String dynamicId) {
33 | this.dynamicId = dynamicId;
34 | }
35 |
36 | public String getReason() {
37 | return reason;
38 | }
39 |
40 | public void setReason(String reason) {
41 | this.reason = reason;
42 | }
43 |
44 | @Override
45 | public String toString() {
46 | return "Report{" +
47 | "id=" + id +
48 | ", dynamicId='" + dynamicId + '\'' +
49 | ", reason='" + reason + '\'' +
50 | '}';
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/msns-dynamic/msns-dynamic-interface/target/classes/com/dxg/msns/dynamic/pojo/Dynamic.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dodudo/msns/beccf0fd921e001c51fb82b00adcd9297a6008ac/msns-dynamic/msns-dynamic-interface/target/classes/com/dxg/msns/dynamic/pojo/Dynamic.class
--------------------------------------------------------------------------------
/msns-dynamic/msns-dynamic-interface/target/classes/com/dxg/msns/dynamic/pojo/DynamicType.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dodudo/msns/beccf0fd921e001c51fb82b00adcd9297a6008ac/msns-dynamic/msns-dynamic-interface/target/classes/com/dxg/msns/dynamic/pojo/DynamicType.class
--------------------------------------------------------------------------------
/msns-dynamic/msns-dynamic-interface/target/classes/com/dxg/msns/dynamic/pojo/Report.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dodudo/msns/beccf0fd921e001c51fb82b00adcd9297a6008ac/msns-dynamic/msns-dynamic-interface/target/classes/com/dxg/msns/dynamic/pojo/Report.class
--------------------------------------------------------------------------------
/msns-dynamic/msns-dynamic-service/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | msns-dynamic
7 | com.dxg.msns.dynamic
8 | 1.0-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | msns-dynamic-service
13 |
14 |
15 |
16 |
17 | org.springframework.boot
18 | spring-boot-starter-web
19 |
20 |
21 |
22 | org.springframework.cloud
23 | spring-cloud-starter-netflix-eureka-client
24 |
25 |
26 |
27 | org.mybatis.spring.boot
28 | mybatis-spring-boot-starter
29 |
30 |
31 |
32 | tk.mybatis
33 | mapper-spring-boot-starter
34 |
35 |
36 |
37 | com.github.pagehelper
38 | pagehelper-spring-boot-starter
39 |
40 |
41 |
42 | org.springframework.boot
43 | spring-boot-starter-jdbc
44 |
45 |
46 |
47 | mysql
48 | mysql-connector-java
49 |
50 |
51 | org.springframework.boot
52 | spring-boot-starter-amqp
53 |
54 |
55 |
56 | org.springframework.boot
57 | spring-boot-starter-actuator
58 |
59 |
60 |
61 | com.dxg.msns.dynamic
62 | msns-dynamic-interface
63 | 1.0-SNAPSHOT
64 | compile
65 |
66 |
67 | com.dxg.msns.common
68 | msns-common
69 | 1.0-SNAPSHOT
70 | compile
71 |
72 |
73 |
74 |
--------------------------------------------------------------------------------
/msns-dynamic/msns-dynamic-service/src/main/java/com/dxg/msns/dynamic/MSNSDynamicServiceApplication.java:
--------------------------------------------------------------------------------
1 | package com.dxg.msns.dynamic;
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 | @SpringBootApplication
9 | @EnableDiscoveryClient
10 | @MapperScan("com.dxg.msns.dynamic.mapper")
11 | public class MSNSDynamicServiceApplication {
12 | public static void main(String[] args) {
13 | SpringApplication.run(MSNSDynamicServiceApplication.class);
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/msns-dynamic/msns-dynamic-service/src/main/java/com/dxg/msns/dynamic/controller/ReportController.java:
--------------------------------------------------------------------------------
1 | package com.dxg.msns.dynamic.controller;
2 |
3 | import com.dxg.msns.common.pojo.PageResult;
4 | import com.dxg.msns.dynamic.pojo.Dynamic;
5 | import com.dxg.msns.dynamic.service.ReportService;
6 | import org.springframework.beans.factory.annotation.Autowired;
7 | import org.springframework.http.ResponseEntity;
8 | import org.springframework.web.bind.annotation.GetMapping;
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 |
13 | @RestController
14 | @RequestMapping("report")
15 | public class ReportController {
16 | @Autowired
17 | private ReportService reportService;
18 | /**
19 | * 查询所有分类
20 | * @param key
21 | * @param page
22 | * @param rows
23 | * @param sortBy
24 | * @param desc
25 | * @return
26 | */
27 | @GetMapping("page")
28 | public ResponseEntity> queryReportsByPage(
29 | @RequestParam(value = "key",defaultValue = "")String key,
30 | @RequestParam(value = "page",defaultValue = "1")Integer page,
31 | @RequestParam(value = "rows",defaultValue = "5")Integer rows,
32 | @RequestParam(value = "sortBy",defaultValue = "id")String sortBy[],
33 | @RequestParam(value = "desc",defaultValue = "true")Boolean desc[],
34 | @RequestParam(value = "isAll",required = false)Boolean isAll
35 | ){
36 | if (page<0 ||rows<0){
37 | return ResponseEntity.badRequest().build();
38 | }
39 | PageResult result = this.reportService.queryReportsByPage(key,page,rows,sortBy,desc,isAll);
40 |
41 | return ResponseEntity.ok(result);
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/msns-dynamic/msns-dynamic-service/src/main/java/com/dxg/msns/dynamic/mapper/DynamicMapper.java:
--------------------------------------------------------------------------------
1 | package com.dxg.msns.dynamic.mapper;
2 |
3 | import com.dxg.msns.dynamic.pojo.Dynamic;
4 | import org.apache.ibatis.annotations.*;
5 | import org.apache.ibatis.mapping.FetchType;
6 | import tk.mybatis.mapper.common.Mapper;
7 | import tk.mybatis.mapper.entity.Example;
8 |
9 | import java.util.List;
10 |
11 | public interface DynamicMapper extends Mapper {
12 |
13 | /**
14 | * 查询所有被举报的
15 | * @param key
16 | * @param sortBy
17 | * @param isDesc
18 | * @return
19 | */
20 | @Select("select * from dynamic where status <> '-1' and dynamic_content like #{key} order by ${sortBy} ${isDesc} ")
21 | @Results(id = "dynamicMap",
22 | value = {
23 | @Result(id = true,column = "id",property = "id"),
24 | @Result(column = "dynamic_id",property = "dynamicId"),
25 | @Result(column = "dynamic_content",property = "dynamicContent"),
26 | @Result(column = "uname",property = "uname"),
27 | @Result(column = "publish_date",property = "publishDate"),
28 | @Result(column = "report_count",property = "reportCount"),
29 | @Result(column = "dynamic_id",property = "reports",many = @Many(
30 | select = "com.dxg.msns.dynamic.mapper.ReportMapper.findById"
31 | ))
32 | })
33 | List selectAllReports(String key, String sortBy, String isDesc);
34 |
35 | /**
36 | * 计算举报量插入动态reports字段
37 | */
38 | @Update("update dynamic set report_count = #{reportCount} where dynamic_id = #{dynamicId}")
39 | @ResultMap(value = "dynamicMap")
40 | void insertReportCount(String dynamicId,Integer reportCount);
41 |
42 | }
43 |
--------------------------------------------------------------------------------
/msns-dynamic/msns-dynamic-service/src/main/java/com/dxg/msns/dynamic/mapper/DynamicTypeMapper.java:
--------------------------------------------------------------------------------
1 | package com.dxg.msns.dynamic.mapper;
2 |
3 | import com.dxg.msns.dynamic.pojo.DynamicType;
4 | import org.apache.ibatis.annotations.Select;
5 | import tk.mybatis.mapper.common.Mapper;
6 |
7 | import java.util.List;
8 |
9 | public interface DynamicTypeMapper extends Mapper {
10 | @Select("select type_name from dynamic_type where type_status='1' ")
11 | List queryAllDynamiTypeNames();
12 | }
13 |
--------------------------------------------------------------------------------
/msns-dynamic/msns-dynamic-service/src/main/java/com/dxg/msns/dynamic/mapper/ReportMapper.java:
--------------------------------------------------------------------------------
1 | package com.dxg.msns.dynamic.mapper;
2 |
3 | import com.dxg.msns.dynamic.pojo.Report;
4 | import org.apache.ibatis.annotations.Param;
5 | import org.apache.ibatis.annotations.Result;
6 | import org.apache.ibatis.annotations.Results;
7 | import org.apache.ibatis.annotations.Select;
8 |
9 | import java.util.List;
10 |
11 | public interface ReportMapper {
12 | @Select("select * from report where dynamic_id = #{dynamicId}")
13 | @Results(id = "reportMap",value = {
14 | @Result(id = true,column = "id",property = "id"),
15 | @Result(column = "dynamic_id",property = "dynamicId"),
16 | @Result(column = "reason",property = "reason")
17 | })
18 | List findById(@Param("dynamicId") String dynamicId);
19 | }
20 |
--------------------------------------------------------------------------------
/msns-dynamic/msns-dynamic-service/src/main/java/com/dxg/msns/dynamic/service/DynamicService.java:
--------------------------------------------------------------------------------
1 | package com.dxg.msns.dynamic.service;
2 |
3 | import com.dxg.msns.common.pojo.PageResult;
4 | import com.dxg.msns.dynamic.pojo.Dynamic;
5 | import com.dxg.msns.dynamic.pojo.DynamicType;
6 | import org.springframework.stereotype.Service;
7 |
8 |
9 | public interface DynamicService {
10 | /**
11 | * 查询所有动态
12 | * @param key
13 | * @param page
14 | * @param rows
15 | * @param sortBy
16 | * @param desc
17 | * @param isAll
18 | * @return
19 | */
20 | PageResult queryDynamicsByPage(String key, Integer page, Integer rows, String[] sortBy, Boolean[] desc, Boolean isAll,String[] uids,Integer[] ids);
21 |
22 | /**
23 | * 更新动态
24 | * @param dynamic
25 | */
26 | void updateDynamic(Dynamic dynamic);
27 |
28 | /**
29 | * 删除动态
30 | * @param dynamic
31 | */
32 | void deleteDynamic(Dynamic dynamic);
33 |
34 | /**
35 | * 根据id查找动态
36 | * @param id
37 | * @return
38 | */
39 | Dynamic queryById(Integer id);
40 |
41 | /**
42 | * 根据用户id查询条数
43 | * @param uid
44 | * @return
45 | */
46 | Integer queryCountByUid(String uid);
47 |
48 | /**
49 | * 新增动态
50 | * @param dynamic
51 | */
52 | void addDynamic(Dynamic dynamic);
53 | }
54 |
--------------------------------------------------------------------------------
/msns-dynamic/msns-dynamic-service/src/main/java/com/dxg/msns/dynamic/service/DynamicTypeService.java:
--------------------------------------------------------------------------------
1 | package com.dxg.msns.dynamic.service;
2 |
3 | import com.dxg.msns.common.pojo.PageResult;
4 | import com.dxg.msns.dynamic.pojo.DynamicType;
5 | import org.springframework.stereotype.Service;
6 |
7 | import java.util.List;
8 |
9 |
10 | public interface DynamicTypeService {
11 | PageResult queryDynamicTypesByPage(String key, Integer page, Integer rows, String sortBy[], Boolean desc[],Boolean isAll);
12 |
13 | /**
14 | * 新增分类
15 | * @param dynamicType
16 | */
17 | void addType(DynamicType dynamicType);
18 |
19 | /**
20 | * 根据id更新分类
21 | * @param dynamicType
22 | */
23 | void updateType(DynamicType dynamicType);
24 |
25 | /**
26 | * 删除类型
27 | * @param dynamicType
28 | */
29 | void deleteType(DynamicType dynamicType);
30 |
31 | /**
32 | * 查询所有分类名
33 | * @return
34 | */
35 | List queryAllDynamiTypeNames();
36 |
37 | /**
38 | * 根据id查询分类名
39 | * @param id
40 | * @return
41 | */
42 | String queryNameById(Integer id);
43 | }
44 |
--------------------------------------------------------------------------------
/msns-dynamic/msns-dynamic-service/src/main/java/com/dxg/msns/dynamic/service/ReportService.java:
--------------------------------------------------------------------------------
1 | package com.dxg.msns.dynamic.service;
2 |
3 | import com.dxg.msns.common.pojo.PageResult;
4 | import com.dxg.msns.dynamic.pojo.Dynamic;
5 |
6 | public interface ReportService {
7 | public PageResult queryReportsByPage(String key, Integer page, Integer rows, String[] sortBy, Boolean[] desc, Boolean isAll);
8 | }
9 |
--------------------------------------------------------------------------------
/msns-dynamic/msns-dynamic-service/src/main/java/com/dxg/msns/dynamic/service/impl/ReportServiceImpl.java:
--------------------------------------------------------------------------------
1 | package com.dxg.msns.dynamic.service.impl;
2 |
3 | import com.dxg.msns.common.pojo.PageResult;
4 | import com.dxg.msns.common.util.UnderlineHump;
5 | import com.dxg.msns.dynamic.mapper.DynamicMapper;
6 | import com.dxg.msns.dynamic.pojo.Dynamic;
7 | import com.dxg.msns.dynamic.pojo.DynamicType;
8 | import com.dxg.msns.dynamic.service.ReportService;
9 | import com.github.pagehelper.PageHelper;
10 | import com.github.pagehelper.PageInfo;
11 | import org.apache.commons.lang.ArrayUtils;
12 | import org.apache.commons.lang.StringUtils;
13 | import org.springframework.beans.factory.annotation.Autowired;
14 | import org.springframework.stereotype.Service;
15 | import tk.mybatis.mapper.entity.Example;
16 |
17 | import java.util.List;
18 |
19 | @Service
20 | public class ReportServiceImpl implements ReportService {
21 | @Autowired
22 | private DynamicMapper dynamicMapper;
23 | @Override
24 | public PageResult queryReportsByPage(String key, Integer page, Integer rows, String[] sortBy, Boolean[] desc, Boolean isAll) {
25 | //添加分页条件
26 | PageHelper.startPage(page, rows);
27 | String isDesc = "desc";
28 | key = "%"+key+"%";
29 |
30 | //添加排序条件
31 | if (ArrayUtils.isNotEmpty(sortBy)) {
32 | isDesc = desc[0] ? "desc" : "asc";
33 | }
34 | List dynamics = this.dynamicMapper.selectAllReports(key,UnderlineHump.HumpToUnderline(sortBy[0]),isDesc);
35 | for (int i = 0; i < dynamics.size(); i++) {
36 | if (!dynamics.get(i).getReports().isEmpty()){
37 | dynamicMapper.insertReportCount(dynamics.get(i).getDynamicId(),dynamics.get(i).getReports().size());
38 | }
39 | }
40 | PageInfo dynamicPageInfo = new PageInfo<>(dynamics);
41 | return new PageResult<>(dynamicPageInfo.getTotal(), dynamicPageInfo.getList());
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/msns-dynamic/msns-dynamic-service/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 | server:
2 | port: 8081
3 | spring:
4 | application:
5 | name: dynamic-service
6 | datasource:
7 | url: jdbc:mysql:///msns?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC
8 | username: root
9 | password: root
10 | driver-class-name: com.mysql.jdbc.Driver
11 | hikari:
12 | max-lifetime: 28830000 # 一个连接的生命时长(毫秒),超时而且没被使用则被释放(retired),缺省:30分钟,建议设置比数据库超时时长少30秒,参考MySQL wait_timeout参数(show variables like '%timeout%';)
13 | maximum-pool-size: 9 # 连接池中允许的最大连接数。缺省值:10;推荐的公式:((core_count * 2) + effective_spindle_count)
14 | rabbitmq:
15 | host: 127.0.0.1
16 | port: 5672
17 | username: msns
18 | password: msns
19 | virtual-host: /msns
20 | template:
21 | exchange: msns.dynamic.exchange
22 | publisher-confirms: true #生产者确认机制,确保消息会正确发送,如果发送失败会有错误回执,从而触发重试
23 |
24 | eureka:
25 | client:
26 | service-url:
27 | defaultZone: http://127.0.0.1:10086/eureka
28 | instance:
29 | lease-expiration-duration-in-seconds: 10 #10秒不发送就过期
30 | lease-renewal-interval-in-seconds: 5 #5秒发送一次心跳
31 | logging:
32 | level:
33 | root: DEBUG
--------------------------------------------------------------------------------
/msns-dynamic/msns-dynamic-service/target/classes/META-INF/msns-dynamic-service.kotlin_module:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/msns-dynamic/msns-dynamic-service/target/classes/application.yml:
--------------------------------------------------------------------------------
1 | server:
2 | port: 8081
3 | spring:
4 | application:
5 | name: dynamic-service
6 | datasource:
7 | url: jdbc:mysql:///msns?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC
8 | username: root
9 | password: root
10 | driver-class-name: com.mysql.jdbc.Driver
11 | hikari:
12 | max-lifetime: 28830000 # 一个连接的生命时长(毫秒),超时而且没被使用则被释放(retired),缺省:30分钟,建议设置比数据库超时时长少30秒,参考MySQL wait_timeout参数(show variables like '%timeout%';)
13 | maximum-pool-size: 9 # 连接池中允许的最大连接数。缺省值:10;推荐的公式:((core_count * 2) + effective_spindle_count)
14 | rabbitmq:
15 | host: 127.0.0.1
16 | port: 5672
17 | username: msns
18 | password: msns
19 | virtual-host: /msns
20 | template:
21 | exchange: msns.dynamic.exchange
22 | publisher-confirms: true #生产者确认机制,确保消息会正确发送,如果发送失败会有错误回执,从而触发重试
23 |
24 | eureka:
25 | client:
26 | service-url:
27 | defaultZone: http://127.0.0.1:10086/eureka
28 | instance:
29 | lease-expiration-duration-in-seconds: 10 #10秒不发送就过期
30 | lease-renewal-interval-in-seconds: 5 #5秒发送一次心跳
31 | logging:
32 | level:
33 | root: DEBUG
--------------------------------------------------------------------------------
/msns-dynamic/msns-dynamic-service/target/classes/com/dxg/msns/dynamic/MSNSDynamicServiceApplication.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dodudo/msns/beccf0fd921e001c51fb82b00adcd9297a6008ac/msns-dynamic/msns-dynamic-service/target/classes/com/dxg/msns/dynamic/MSNSDynamicServiceApplication.class
--------------------------------------------------------------------------------
/msns-dynamic/msns-dynamic-service/target/classes/com/dxg/msns/dynamic/controller/DynamicController.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dodudo/msns/beccf0fd921e001c51fb82b00adcd9297a6008ac/msns-dynamic/msns-dynamic-service/target/classes/com/dxg/msns/dynamic/controller/DynamicController.class
--------------------------------------------------------------------------------
/msns-dynamic/msns-dynamic-service/target/classes/com/dxg/msns/dynamic/controller/DynamicTypeController.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dodudo/msns/beccf0fd921e001c51fb82b00adcd9297a6008ac/msns-dynamic/msns-dynamic-service/target/classes/com/dxg/msns/dynamic/controller/DynamicTypeController.class
--------------------------------------------------------------------------------
/msns-dynamic/msns-dynamic-service/target/classes/com/dxg/msns/dynamic/controller/ReportController.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dodudo/msns/beccf0fd921e001c51fb82b00adcd9297a6008ac/msns-dynamic/msns-dynamic-service/target/classes/com/dxg/msns/dynamic/controller/ReportController.class
--------------------------------------------------------------------------------
/msns-dynamic/msns-dynamic-service/target/classes/com/dxg/msns/dynamic/mapper/DynamicMapper.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dodudo/msns/beccf0fd921e001c51fb82b00adcd9297a6008ac/msns-dynamic/msns-dynamic-service/target/classes/com/dxg/msns/dynamic/mapper/DynamicMapper.class
--------------------------------------------------------------------------------
/msns-dynamic/msns-dynamic-service/target/classes/com/dxg/msns/dynamic/mapper/DynamicTypeMapper.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dodudo/msns/beccf0fd921e001c51fb82b00adcd9297a6008ac/msns-dynamic/msns-dynamic-service/target/classes/com/dxg/msns/dynamic/mapper/DynamicTypeMapper.class
--------------------------------------------------------------------------------
/msns-dynamic/msns-dynamic-service/target/classes/com/dxg/msns/dynamic/mapper/ReportMapper.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dodudo/msns/beccf0fd921e001c51fb82b00adcd9297a6008ac/msns-dynamic/msns-dynamic-service/target/classes/com/dxg/msns/dynamic/mapper/ReportMapper.class
--------------------------------------------------------------------------------
/msns-dynamic/msns-dynamic-service/target/classes/com/dxg/msns/dynamic/service/DynamicService.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dodudo/msns/beccf0fd921e001c51fb82b00adcd9297a6008ac/msns-dynamic/msns-dynamic-service/target/classes/com/dxg/msns/dynamic/service/DynamicService.class
--------------------------------------------------------------------------------
/msns-dynamic/msns-dynamic-service/target/classes/com/dxg/msns/dynamic/service/DynamicTypeService.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dodudo/msns/beccf0fd921e001c51fb82b00adcd9297a6008ac/msns-dynamic/msns-dynamic-service/target/classes/com/dxg/msns/dynamic/service/DynamicTypeService.class
--------------------------------------------------------------------------------
/msns-dynamic/msns-dynamic-service/target/classes/com/dxg/msns/dynamic/service/ReportService.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dodudo/msns/beccf0fd921e001c51fb82b00adcd9297a6008ac/msns-dynamic/msns-dynamic-service/target/classes/com/dxg/msns/dynamic/service/ReportService.class
--------------------------------------------------------------------------------
/msns-dynamic/msns-dynamic-service/target/classes/com/dxg/msns/dynamic/service/impl/DynamicServiceImpl.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dodudo/msns/beccf0fd921e001c51fb82b00adcd9297a6008ac/msns-dynamic/msns-dynamic-service/target/classes/com/dxg/msns/dynamic/service/impl/DynamicServiceImpl.class
--------------------------------------------------------------------------------
/msns-dynamic/msns-dynamic-service/target/classes/com/dxg/msns/dynamic/service/impl/DynamicTypeServiceImpl.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dodudo/msns/beccf0fd921e001c51fb82b00adcd9297a6008ac/msns-dynamic/msns-dynamic-service/target/classes/com/dxg/msns/dynamic/service/impl/DynamicTypeServiceImpl.class
--------------------------------------------------------------------------------
/msns-dynamic/msns-dynamic-service/target/classes/com/dxg/msns/dynamic/service/impl/ReportServiceImpl.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dodudo/msns/beccf0fd921e001c51fb82b00adcd9297a6008ac/msns-dynamic/msns-dynamic-service/target/classes/com/dxg/msns/dynamic/service/impl/ReportServiceImpl.class
--------------------------------------------------------------------------------
/msns-dynamic/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | msns
7 | com.dxg.msns.parent
8 | 1.0-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | com.dxg.msns.dynamic
13 | msns-dynamic
14 |
15 |
16 | pom
17 |
18 | msns-dynamic-interface
19 | msns-dynamic-service
20 |
21 |
--------------------------------------------------------------------------------
/msns-favor/msns-favor-interface/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | msns-favor
7 | com.dxg.msns.favor
8 | 1.0-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | msns-favor-interface
13 |
14 |
15 | org.springframework
16 | spring-web
17 |
18 |
19 | javax.persistence
20 | persistence-api
21 | 1.0
22 |
23 |
24 | com.fasterxml.jackson.core
25 | jackson-annotations
26 |
27 |
28 | com.dxg.msns.common
29 | msns-common
30 | 1.0-SNAPSHOT
31 | compile
32 |
33 |
34 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/msns-favor/msns-favor-interface/src/main/java/com/dxg/msns/favor/api/DynamicFavorApi.java:
--------------------------------------------------------------------------------
1 | package com.dxg.msns.favor.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 |
8 | @RequestMapping("dynamic")
9 | public interface DynamicFavorApi {
10 | /**
11 | * 查询动态的收藏数
12 | *
13 | */
14 | @GetMapping("queryByDynamicId/{id}")
15 | public Integer queryByDynamicId(@PathVariable("id") Integer dynamicId);
16 |
17 | /**
18 | * 查询用户收藏动态的收藏数
19 | *
20 | */
21 | @GetMapping("queryByUid/{uid}")
22 | public Integer queryByUid(@PathVariable("uid") String uid);
23 | }
24 |
--------------------------------------------------------------------------------
/msns-favor/msns-favor-interface/src/main/java/com/dxg/msns/favor/api/MusicFavorApi.java:
--------------------------------------------------------------------------------
1 | package com.dxg.msns.favor.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 |
8 | @RequestMapping("music")
9 | public interface MusicFavorApi {
10 | /**
11 | * 查询用户音乐的收藏数
12 | *
13 | */
14 | @GetMapping("queryCountByUid/{id}")
15 | public Integer queryCountByUid(@PathVariable("id") String uid);
16 |
17 | /**
18 | * 根据用户id查询该用户收藏音乐的id
19 | */
20 | @GetMapping("queryByUid/{id}")
21 | public Integer[] queryByUid(@PathVariable("id") String uid);
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/msns-favor/msns-favor-interface/src/main/java/com/dxg/msns/favor/pojo/DynamicFavor.java:
--------------------------------------------------------------------------------
1 | package com.dxg.msns.favor.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.util.Date;
8 | import java.io.Serializable;
9 |
10 | /**
11 | * (DynamicFavor)实体类
12 | *
13 | * @author makejava
14 | * @since 2020-03-13 20:43:30
15 | */
16 | @Table(name = "dynamic_favor")
17 | public class DynamicFavor implements Serializable {
18 | private static final long serialVersionUID = 889485348889726487L;
19 | /**
20 | * 自增主键id
21 | */
22 | @Id
23 | @GeneratedValue(strategy = GenerationType.IDENTITY)
24 | private Integer id;
25 | /**
26 | * 动态id
27 | */
28 | private Integer dynamicId;
29 | /**
30 | * 收藏者id
31 | */
32 | private String collectorId;
33 | /**
34 | * 收藏时间
35 | */
36 | private Date favorDate;
37 | /**
38 | * 状态
39 | */
40 | private String status;
41 |
42 |
43 | public Integer getId() {
44 | return id;
45 | }
46 |
47 | public void setId(Integer id) {
48 | this.id = id;
49 | }
50 |
51 | public Integer getDynamicId() {
52 | return dynamicId;
53 | }
54 |
55 | public void setDynamicId(Integer dynamicId) {
56 | this.dynamicId = dynamicId;
57 | }
58 |
59 | public String getCollectorId() {
60 | return collectorId;
61 | }
62 |
63 | public void setCollectorId(String collectorId) {
64 | this.collectorId = collectorId;
65 | }
66 |
67 | public Date getFavorDate() {
68 | return favorDate;
69 | }
70 |
71 | public void setFavorDate(Date favorDate) {
72 | this.favorDate = favorDate;
73 | }
74 |
75 | public String getStatus() {
76 | return status;
77 | }
78 |
79 | public void setStatus(String status) {
80 | this.status = status;
81 | }
82 |
83 | @Override
84 | public String toString() {
85 | return "DynamicFavor{" +
86 | "id=" + id +
87 | ", dynamicId='" + dynamicId + '\'' +
88 | ", collectorId='" + collectorId + '\'' +
89 | ", favorDate=" + favorDate +
90 | ", status='" + status + '\'' +
91 | '}';
92 | }
93 | }
--------------------------------------------------------------------------------
/msns-favor/msns-favor-interface/src/main/java/com/dxg/msns/favor/pojo/MusicFavor.java:
--------------------------------------------------------------------------------
1 | package com.dxg.msns.favor.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.util.Date;
8 | import java.io.Serializable;
9 |
10 | /**
11 | * (MusicFavor)实体类
12 | *
13 | * @author makejava
14 | * @since 2020-03-13 20:44:45
15 | */
16 | @Table(name = "music_favor")
17 | public class MusicFavor implements Serializable {
18 | private static final long serialVersionUID = -37616566427231476L;
19 | /**
20 | * 主键自增
21 | */
22 | @Id
23 | @GeneratedValue(strategy = GenerationType.IDENTITY)
24 | private Integer id;
25 | /**
26 | * 音乐id
27 | */
28 | private Integer musicId;
29 | /**
30 | * 收藏者id
31 | */
32 | private String collectorId;
33 | /**
34 | * 收藏时间
35 | */
36 | private Date favorDate;
37 |
38 |
39 | public Integer getId() {
40 | return id;
41 | }
42 |
43 | public void setId(Integer id) {
44 | this.id = id;
45 | }
46 |
47 | public Integer getMusicId() {
48 | return musicId;
49 | }
50 |
51 | public void setMusicId(Integer musicId) {
52 | this.musicId = musicId;
53 | }
54 |
55 | public String getCollectorId() {
56 | return collectorId;
57 | }
58 |
59 | public void setCollectorId(String collectorId) {
60 | this.collectorId = collectorId;
61 | }
62 |
63 | public Date getFavorDate() {
64 | return favorDate;
65 | }
66 |
67 | public void setFavorDate(Date favorDate) {
68 | this.favorDate = favorDate;
69 | }
70 |
71 | @Override
72 | public String toString() {
73 | return "MusicFavor{" +
74 | "id=" + id +
75 | ", musicId='" + musicId + '\'' +
76 | ", collectorId='" + collectorId + '\'' +
77 | ", favorDate=" + favorDate +
78 | '}';
79 | }
80 | }
--------------------------------------------------------------------------------
/msns-favor/msns-favor-service/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | msns-favor
7 | com.dxg.msns.favor
8 | 1.0-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | msns-favor-service
13 |
14 |
15 |
16 |
17 | org.springframework.boot
18 | spring-boot-starter-web
19 |
20 |
21 |
22 | org.springframework.cloud
23 | spring-cloud-starter-netflix-eureka-client
24 |
25 |
26 |
27 | org.mybatis.spring.boot
28 | mybatis-spring-boot-starter
29 |
30 |
31 |
32 | tk.mybatis
33 | mapper-spring-boot-starter
34 |
35 |
36 |
37 | com.github.pagehelper
38 | pagehelper-spring-boot-starter
39 |
40 |
41 |
42 | org.springframework.boot
43 | spring-boot-starter-jdbc
44 |
45 |
46 |
47 | mysql
48 | mysql-connector-java
49 |
50 |
51 | org.springframework.boot
52 | spring-boot-starter-amqp
53 |
54 |
55 |
56 | org.springframework.boot
57 | spring-boot-starter-actuator
58 |
59 |
60 | com.dxg.msns.common
61 | msns-common
62 | 1.0-SNAPSHOT
63 | compile
64 |
65 |
66 | com.dxg.msns.favor
67 | msns-favor-interface
68 | 1.0-SNAPSHOT
69 |
70 |
71 |
--------------------------------------------------------------------------------
/msns-favor/msns-favor-service/src/main/java/com/dxg/msns/favor/MSNSFavorServiceApplication.java:
--------------------------------------------------------------------------------
1 | package com.dxg.msns.favor;
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 | @SpringBootApplication
9 | @EnableDiscoveryClient
10 | @MapperScan("com.dxg.msns.favor.mapper")
11 | public class MSNSFavorServiceApplication {
12 | public static void main(String[] args) {
13 | SpringApplication.run(MSNSFavorServiceApplication.class);
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/msns-favor/msns-favor-service/src/main/java/com/dxg/msns/favor/controller/MusicFavorController.java:
--------------------------------------------------------------------------------
1 | package com.dxg.msns.favor.controller;
2 |
3 | import com.dxg.msns.favor.pojo.MusicFavor;
4 | import com.dxg.msns.favor.service.MusicFavorService;
5 | import org.apache.commons.lang.ArrayUtils;
6 | import org.springframework.beans.factory.annotation.Autowired;
7 | import org.springframework.http.HttpStatus;
8 | import org.springframework.http.ResponseEntity;
9 | import org.springframework.web.bind.annotation.*;
10 |
11 | import javax.annotation.Resource;
12 |
13 | /**
14 | * (MusicFavor)表控制层
15 | *
16 | * @author makejava
17 | * @since 2020-03-13 20:46:05
18 | */
19 | @RestController
20 | @RequestMapping("music")
21 | public class MusicFavorController {
22 | /**
23 | * 服务对象
24 | */
25 | @Autowired
26 | private MusicFavorService musicFavorService;
27 |
28 |
29 | /**
30 | * 查询用户音乐的收藏数
31 | *
32 | */
33 | @GetMapping("queryCountByUid/{id}")
34 | public ResponseEntity queryCountByUid(@PathVariable("id") String uid) {
35 | Integer counts = this.musicFavorService.queryCountByUid(uid);
36 | if (counts == null){
37 | return ResponseEntity.notFound().build();
38 | }
39 | return ResponseEntity.ok(counts);
40 | }
41 |
42 | /**
43 | * 根据用户id查询该用户收藏音乐的id
44 | */
45 | @GetMapping("queryByUid/{id}")
46 | public ResponseEntity queryByUid(@PathVariable("id") String uid) {
47 | Integer[] ids = this.musicFavorService.queryByUid(uid);
48 | if (ArrayUtils.isEmpty(ids)){
49 | return ResponseEntity.notFound().build();
50 | }
51 | return ResponseEntity.ok(ids);
52 | }
53 |
54 | /**
55 | * 删除收藏信息
56 | *
57 | * @return
58 | */
59 | @RequestMapping(method = RequestMethod.DELETE)
60 | public ResponseEntity deleteFavor(@RequestParam("collectorId")String collectorId,
61 | @RequestParam("musicId")Integer musicId) {
62 | MusicFavor musicFavor = new MusicFavor();
63 | musicFavor.setCollectorId(collectorId);
64 | musicFavor.setMusicId(musicId);
65 | this.musicFavorService.deleteFavor(musicFavor);
66 | return ResponseEntity.status(HttpStatus.CREATED).build();
67 | }
68 |
69 | /**
70 | * 新增关注
71 | *
72 | * @return
73 | */
74 | @PostMapping
75 | public ResponseEntity addFavor(@RequestParam("collectorId")String collectorId,
76 | @RequestParam("musicId")Integer musicId) {
77 | MusicFavor musicFavor = new MusicFavor();
78 | musicFavor.setCollectorId(collectorId);
79 | musicFavor.setMusicId(musicId);
80 | musicFavorService.addFavor(musicFavor);
81 | return ResponseEntity.status(HttpStatus.CREATED).build();
82 | }
83 | }
--------------------------------------------------------------------------------
/msns-favor/msns-favor-service/src/main/java/com/dxg/msns/favor/mapper/DynamicFavorMapper.java:
--------------------------------------------------------------------------------
1 | package com.dxg.msns.favor.mapper;
2 |
3 | import com.dxg.msns.favor.pojo.DynamicFavor;
4 | import tk.mybatis.mapper.common.Mapper;
5 |
6 | public interface DynamicFavorMapper extends Mapper {
7 | }
8 |
--------------------------------------------------------------------------------
/msns-favor/msns-favor-service/src/main/java/com/dxg/msns/favor/mapper/MusicFavorMapper.java:
--------------------------------------------------------------------------------
1 | package com.dxg.msns.favor.mapper;
2 |
3 | import com.dxg.msns.favor.pojo.MusicFavor;
4 | import tk.mybatis.mapper.common.Mapper;
5 |
6 | public interface MusicFavorMapper extends Mapper {
7 | }
8 |
--------------------------------------------------------------------------------
/msns-favor/msns-favor-service/src/main/java/com/dxg/msns/favor/service/DynamicFavorService.java:
--------------------------------------------------------------------------------
1 | package com.dxg.msns.favor.service;
2 |
3 | import com.dxg.msns.favor.pojo.DynamicFavor;
4 | import org.springframework.http.ResponseEntity;
5 |
6 | import java.util.List;
7 |
8 | public interface DynamicFavorService {
9 | /**
10 | * 查询动态的收藏数
11 | * @param dynamicId
12 | * @return
13 | */
14 | Integer queryByDynamicId(Integer dynamicId);
15 |
16 | /**
17 | * 查询用户收藏动态的数量
18 | * @param uid
19 | * @return
20 | */
21 | Integer queryByUid(String uid);
22 |
23 | /**
24 | * 查询用户关注的所有动态id
25 | * @param uid
26 | * @return
27 | */
28 | Integer[] queryFavorByUid(String uid);
29 |
30 | /**
31 | * 查询是否收藏
32 | * @param dynamicIds
33 | * @param uid
34 | * @return
35 | */
36 | List queryIsFavor(Integer[] dynamicIds, String uid);
37 |
38 | /**
39 | * 删除收藏
40 | * @param dynamicFavor
41 | */
42 | void deleteFavor(DynamicFavor dynamicFavor);
43 |
44 | /**
45 | * 新增收藏
46 | * @param dynamicFavor
47 | */
48 | void addFavor(DynamicFavor dynamicFavor);
49 | }
50 |
--------------------------------------------------------------------------------
/msns-favor/msns-favor-service/src/main/java/com/dxg/msns/favor/service/MusicFavorService.java:
--------------------------------------------------------------------------------
1 | package com.dxg.msns.favor.service;
2 |
3 | import com.dxg.msns.favor.pojo.MusicFavor;
4 |
5 | public interface MusicFavorService {
6 |
7 | /**
8 | * 查询用户搜藏音乐的总数
9 | * @param uid
10 | * @return
11 | */
12 | Integer queryCountByUid(String uid);
13 |
14 | /**
15 | *根据用户id查询该用户收藏音乐的id
16 | * @param uid
17 | * @return
18 | */
19 | Integer[] queryByUid(String uid);
20 |
21 | /**
22 | * 删除收藏
23 | * @param musicFavor
24 | */
25 | void deleteFavor(MusicFavor musicFavor);
26 |
27 | /**
28 | * 添加收藏
29 | * @param musicFavor
30 | */
31 | void addFavor(MusicFavor musicFavor);
32 | }
33 |
--------------------------------------------------------------------------------
/msns-favor/msns-favor-service/src/main/java/com/dxg/msns/favor/service/impl/MusicFavorServiceImpl.java:
--------------------------------------------------------------------------------
1 | package com.dxg.msns.favor.service.impl;
2 |
3 | import com.dxg.msns.favor.mapper.MusicFavorMapper;
4 | import com.dxg.msns.favor.pojo.DynamicFavor;
5 | import com.dxg.msns.favor.pojo.MusicFavor;
6 | import com.dxg.msns.favor.service.MusicFavorService;
7 | import org.springframework.beans.factory.annotation.Autowired;
8 | import org.springframework.stereotype.Service;
9 | import tk.mybatis.mapper.entity.Example;
10 |
11 | import java.util.ArrayList;
12 | import java.util.Date;
13 | import java.util.List;
14 |
15 | @Service
16 | public class MusicFavorServiceImpl implements MusicFavorService {
17 | @Autowired
18 | private MusicFavorMapper musicFavorMapper;
19 | /**
20 | * 查询用户搜藏音乐的总数
21 | *
22 | * @param uid
23 | * @return
24 | */
25 | @Override
26 | public Integer queryCountByUid(String uid) {
27 | Example example = new Example(DynamicFavor.class);
28 | Example.Criteria criteria = example.createCriteria();
29 | criteria.andEqualTo("collectorId",uid);
30 | Integer counts = musicFavorMapper.selectCountByExample(example);
31 | return counts;
32 | }
33 |
34 | /**
35 | * 根据用户id查询该用户收藏音乐的id
36 | *
37 | * @param uid
38 | * @return
39 | */
40 | @Override
41 | public Integer[] queryByUid(String uid) {
42 | Example example = new Example(DynamicFavor.class);
43 | Example.Criteria criteria = example.createCriteria();
44 | criteria.andEqualTo("collectorId",uid);
45 | List musicFavors = musicFavorMapper.selectByExample(example);
46 | List ids = new ArrayList<>();
47 | for (MusicFavor musicFavor : musicFavors) {
48 | ids.add(musicFavor.getMusicId());
49 | }
50 | Integer[] idsInt = ids.toArray(new Integer[ids.size()]);
51 | return idsInt;
52 | }
53 |
54 | /**
55 | * 删除收藏
56 | *
57 | * @param musicFavor
58 | */
59 | @Override
60 | public void deleteFavor(MusicFavor musicFavor) {
61 | // Example example = new Example(MusicFavor.class);
62 | // Example.Criteria criteria = example.createCriteria();
63 | // criteria.andEqualTo("collectorId",musicFavor.getCollectorId()).andEqualTo("musicId()",musicFavor.getMusicId());
64 | this.musicFavorMapper.delete(musicFavor);
65 | }
66 |
67 | /**
68 | * 添加收藏
69 | *
70 | * @param musicFavor
71 | */
72 | @Override
73 | public void addFavor(MusicFavor musicFavor) {
74 | Date date = new Date();
75 | musicFavor.setFavorDate(date);
76 | this.musicFavorMapper.insertSelective(musicFavor);
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/msns-favor/msns-favor-service/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 | server:
2 | port: 8087
3 | spring:
4 | application:
5 | name: favor-service
6 | datasource:
7 | url: jdbc:mysql:///msns?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC
8 | username: root
9 | password: root
10 | driver-class-name: com.mysql.jdbc.Driver
11 | hikari:
12 | max-lifetime: 28830000 # 一个连接的生命时长(毫秒),超时而且没被使用则被释放(retired),缺省:30分钟,建议设置比数据库超时时长少30秒,参考MySQL wait_timeout参数(show variables like '%timeout%';)
13 | maximum-pool-size: 9 # 连接池中允许的最大连接数。缺省值:10;推荐的公式:((core_count * 2) + effective_spindle_count)
14 | rabbitmq:
15 | port: 5672
16 | username: msns
17 | password: msns
18 | virtual-host: /msns
19 | template:
20 | exchange: msns.dynamic.exchange
21 | publisher-confirms: true
22 | eureka:
23 | client:
24 | service-url:
25 | defaultZone: http://127.0.0.1:10086/eureka
26 | instance:
27 | lease-expiration-duration-in-seconds: 10 #10秒不发送就过期
28 | lease-renewal-interval-in-seconds: 5 #5秒发送一次心跳
29 | logging:
30 | level:
31 | root: DEBUG
--------------------------------------------------------------------------------
/msns-favor/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | msns
7 | com.dxg.msns.parent
8 | 1.0-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | com.dxg.msns.favor
13 | msns-favor
14 | pom
15 |
16 | msns-favor-interface
17 | msns-favor-service
18 |
19 |
--------------------------------------------------------------------------------
/msns-gateway/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | msns
7 | com.dxg.msns.parent
8 | 1.0-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | com.dxg.msns.common
13 | msns-gateway
14 |
15 |
16 |
17 | org.springframework.cloud
18 | spring-cloud-starter-netflix-eureka-client
19 |
20 |
21 | org.springframework.cloud
22 | spring-cloud-starter-netflix-zuul
23 |
24 |
25 | com.dxg.msns.common
26 | msns-common
27 | 1.0-SNAPSHOT
28 |
29 |
30 | com.dxg.msns.auth
31 | msns-auth-common
32 | 1.0-SNAPSHOT
33 |
34 |
35 |
--------------------------------------------------------------------------------
/msns-gateway/src/main/java/com/dxg/msns/MSNSGatewayApplication.java:
--------------------------------------------------------------------------------
1 | package com.dxg.msns;
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.netflix.zuul.EnableZuulProxy;
8 |
9 | @SpringBootApplication(exclude= {DataSourceAutoConfiguration.class})
10 | @EnableDiscoveryClient
11 | @EnableZuulProxy
12 | public class MSNSGatewayApplication {
13 | public static void main(String[] args) {
14 | SpringApplication.run(MSNSGatewayApplication.class);
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/msns-gateway/src/main/java/com/dxg/msns/gateway/config/FilterProperties.java:
--------------------------------------------------------------------------------
1 | package com.dxg.msns.gateway.config;
2 |
3 | import org.springframework.boot.context.properties.ConfigurationProperties;
4 | import org.springframework.boot.context.properties.EnableConfigurationProperties;
5 |
6 | import java.util.List;
7 |
8 | @ConfigurationProperties(prefix = "msns.filter")
9 | public class FilterProperties {
10 | private List allowPaths;
11 |
12 | public List getAllowPaths() {
13 | return allowPaths;
14 | }
15 |
16 | public void setAllowPaths(List allowPaths) {
17 | this.allowPaths = allowPaths;
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/msns-gateway/src/main/java/com/dxg/msns/gateway/config/JwtProperties.java:
--------------------------------------------------------------------------------
1 | package com.dxg.msns.gateway.config;
2 |
3 | import com.dxg.msns.auth.utils.RsaUtils;
4 | import org.springframework.boot.context.properties.ConfigurationProperties;
5 |
6 | import javax.annotation.PostConstruct;
7 | import java.security.PublicKey;
8 |
9 | @ConfigurationProperties(prefix = "msns.jwt")
10 | public class JwtProperties {
11 | private String pubKeyPath; //公钥
12 | private PublicKey publicKey;
13 | private String cookieName;
14 |
15 | @PostConstruct
16 | public void init(){
17 | try {
18 | this.publicKey = RsaUtils.getPublicKey(pubKeyPath);
19 | } catch (Exception e) {
20 | e.printStackTrace();
21 | throw new RuntimeException();
22 | }
23 | }
24 |
25 | public String getPubKeyPath() {
26 | return pubKeyPath;
27 | }
28 |
29 | public void setPubKeyPath(String pubKeyPath) {
30 | this.pubKeyPath = pubKeyPath;
31 | }
32 |
33 | public PublicKey getPublicKey() {
34 | return publicKey;
35 | }
36 |
37 | public void setPublicKey(PublicKey publicKey) {
38 | this.publicKey = publicKey;
39 | }
40 |
41 | public String getCookieName() {
42 | return cookieName;
43 | }
44 |
45 | public void setCookieName(String cookieName) {
46 | this.cookieName = cookieName;
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/msns-gateway/src/main/java/com/dxg/msns/gateway/config/MSNSCorsConfig.java:
--------------------------------------------------------------------------------
1 | package com.dxg.msns.gateway.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 | @Configuration
10 | public class MSNSCorsConfig {
11 | @Bean
12 | public CorsFilter corsFilter(){
13 | //添加cors配置信息
14 | CorsConfiguration config = new CorsConfiguration();
15 | //添加允许的域,不要写“*”,否则cookie无法使用
16 | config.addAllowedOrigin("http://127.0.0.1:8080");
17 | config.addAllowedOrigin("http://localhost:8080");
18 | //是否发送cookie信息
19 | config.setAllowCredentials(true);
20 | //添加允许的请求方式
21 | config.addAllowedMethod("OPTIONS");
22 | config.addAllowedMethod("HEAD");
23 | config.addAllowedMethod("GET");
24 | config.addAllowedMethod("PUT");
25 | config.addAllowedMethod("POST");
26 | config.addAllowedMethod("DELETE");
27 | config.addAllowedMethod("PATCH");
28 | //允许的头信息
29 | config.addAllowedHeader("*");
30 |
31 | //添加映射路径,我们拦截一切请求
32 | UrlBasedCorsConfigurationSource configSource = new UrlBasedCorsConfigurationSource();
33 | configSource.registerCorsConfiguration("/**", config);
34 |
35 | //返回新的CorsFilter.
36 | return new CorsFilter(configSource);
37 |
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/msns-gateway/src/main/java/com/dxg/msns/gateway/filter/LoginFilter.java:
--------------------------------------------------------------------------------
1 | package com.dxg.msns.gateway.filter;
2 |
3 | import com.dxg.msns.auth.utils.CookieUtils;
4 | import com.dxg.msns.auth.utils.JwtUtils;
5 | import com.dxg.msns.gateway.config.FilterProperties;
6 | import com.dxg.msns.gateway.config.JwtProperties;
7 | import com.netflix.zuul.ZuulFilter;
8 | import com.netflix.zuul.context.RequestContext;
9 | import com.netflix.zuul.exception.ZuulException;
10 | import org.springframework.beans.factory.annotation.Autowired;
11 | import org.springframework.boot.context.properties.EnableConfigurationProperties;
12 | import org.springframework.http.HttpStatus;
13 | import org.springframework.stereotype.Component;
14 |
15 | import javax.servlet.http.HttpServletRequest;
16 |
17 | @Component
18 | @EnableConfigurationProperties({JwtProperties.class, FilterProperties.class})
19 | public class LoginFilter extends ZuulFilter {
20 | @Autowired
21 | private JwtProperties jwtProperties;
22 |
23 | @Autowired
24 | private FilterProperties filterProperties;
25 | @Override
26 | public String filterType() {
27 | return "pre";
28 | }
29 |
30 | @Override
31 | public int filterOrder() {
32 | return 5;
33 | }
34 |
35 | @Override
36 | public boolean shouldFilter() {
37 | // 获取上下文
38 | RequestContext currentContext = RequestContext.getCurrentContext();
39 | // 获取request
40 | HttpServletRequest request = currentContext.getRequest();
41 | // 获取路径
42 | String requestURI = request.getRequestURI();
43 | // 判断白名单
44 | // 遍历允许访问的路径
45 | for (String path : this.filterProperties.getAllowPaths()) {
46 | // 然后判断是否是符合
47 | if(requestURI.startsWith(path)){
48 | return false;
49 | }
50 | }
51 | return true;
52 | }
53 |
54 | @Override
55 | public Object run() throws ZuulException {
56 | //获取上下文
57 | RequestContext currentContext = RequestContext.getCurrentContext();
58 | HttpServletRequest request = currentContext.getRequest();
59 | String token = CookieUtils.getCookieValue(request, jwtProperties.getCookieName());
60 | try {
61 | JwtUtils.getInfoFromToken(token,this.jwtProperties.getPublicKey());
62 | } catch (Exception e) {
63 | // 校验出现异常,返回403
64 | currentContext.setSendZuulResponse(false);
65 | currentContext.setResponseStatusCode(HttpStatus.FORBIDDEN.value());
66 | }
67 | return null;
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/msns-gateway/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 | server:
2 | port: 10010
3 | spring:
4 | application:
5 | name: msns-gateway
6 | eureka:
7 | client:
8 | service-url:
9 | defaultZone: http://127.0.0.1:10086/eureka
10 | zuul:
11 | prefix: /api
12 | routes:
13 | dynamic-service: /dynamic/**
14 | music-service: /music/**
15 | user-service: /user/**
16 | admin-service: /admin/**
17 | comment-service: /comment/**
18 | favor-service: /favor/**
19 | like-service: /like/**
20 | search-service: /search/**
21 | auth-service: /auth/**
22 | ignored-services:
23 | - upload-service
24 | add-host-header: true
25 | sensitive-headers:
26 | msns:
27 | jwt:
28 | pubKeyPath: D:\\tmp\\rsa\\rsa.pub # 公钥地址
29 | cookieName: MSNS_TOKEN #cookie名称
30 | filter:
31 | allowPaths:
32 | - /api/auth
33 | - /api/search
34 | - /api/user/register
35 | - /api/user
36 | - /api/music
37 | - /api/comment
38 | - /api/favor
39 | - /api/like
40 | - /api/dynamic
41 | - /api/admin
42 | logging:
43 | level:
44 | root: DEBUG
--------------------------------------------------------------------------------
/msns-image/image-20200412090346912.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dodudo/msns/beccf0fd921e001c51fb82b00adcd9297a6008ac/msns-image/image-20200412090346912.png
--------------------------------------------------------------------------------
/msns-image/image-20200412091302795.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dodudo/msns/beccf0fd921e001c51fb82b00adcd9297a6008ac/msns-image/image-20200412091302795.png
--------------------------------------------------------------------------------
/msns-image/image-20200412092428566.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dodudo/msns/beccf0fd921e001c51fb82b00adcd9297a6008ac/msns-image/image-20200412092428566.png
--------------------------------------------------------------------------------
/msns-image/image-20200412092845719.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dodudo/msns/beccf0fd921e001c51fb82b00adcd9297a6008ac/msns-image/image-20200412092845719.png
--------------------------------------------------------------------------------
/msns-image/image-20200412092922922.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dodudo/msns/beccf0fd921e001c51fb82b00adcd9297a6008ac/msns-image/image-20200412092922922.png
--------------------------------------------------------------------------------
/msns-image/image-20200412094815633.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dodudo/msns/beccf0fd921e001c51fb82b00adcd9297a6008ac/msns-image/image-20200412094815633.png
--------------------------------------------------------------------------------
/msns-image/image-20200412094932437.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dodudo/msns/beccf0fd921e001c51fb82b00adcd9297a6008ac/msns-image/image-20200412094932437.png
--------------------------------------------------------------------------------
/msns-image/image-20200412095021861.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dodudo/msns/beccf0fd921e001c51fb82b00adcd9297a6008ac/msns-image/image-20200412095021861.png
--------------------------------------------------------------------------------
/msns-image/image-20200412095058713.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dodudo/msns/beccf0fd921e001c51fb82b00adcd9297a6008ac/msns-image/image-20200412095058713.png
--------------------------------------------------------------------------------
/msns-image/image-20200412095431929.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dodudo/msns/beccf0fd921e001c51fb82b00adcd9297a6008ac/msns-image/image-20200412095431929.png
--------------------------------------------------------------------------------
/msns-image/image-20200412095443036.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dodudo/msns/beccf0fd921e001c51fb82b00adcd9297a6008ac/msns-image/image-20200412095443036.png
--------------------------------------------------------------------------------
/msns-image/image-20200412095445446.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dodudo/msns/beccf0fd921e001c51fb82b00adcd9297a6008ac/msns-image/image-20200412095445446.png
--------------------------------------------------------------------------------
/msns-image/image-20200412095904105.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dodudo/msns/beccf0fd921e001c51fb82b00adcd9297a6008ac/msns-image/image-20200412095904105.png
--------------------------------------------------------------------------------
/msns-image/image-20200412095916716.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dodudo/msns/beccf0fd921e001c51fb82b00adcd9297a6008ac/msns-image/image-20200412095916716.png
--------------------------------------------------------------------------------
/msns-image/image-20200412095929359.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dodudo/msns/beccf0fd921e001c51fb82b00adcd9297a6008ac/msns-image/image-20200412095929359.png
--------------------------------------------------------------------------------
/msns-image/image-20200412100040462.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dodudo/msns/beccf0fd921e001c51fb82b00adcd9297a6008ac/msns-image/image-20200412100040462.png
--------------------------------------------------------------------------------
/msns-image/image-20200412100150061.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dodudo/msns/beccf0fd921e001c51fb82b00adcd9297a6008ac/msns-image/image-20200412100150061.png
--------------------------------------------------------------------------------
/msns-image/image-20200412100228769.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dodudo/msns/beccf0fd921e001c51fb82b00adcd9297a6008ac/msns-image/image-20200412100228769.png
--------------------------------------------------------------------------------
/msns-image/image-20200412100315683.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dodudo/msns/beccf0fd921e001c51fb82b00adcd9297a6008ac/msns-image/image-20200412100315683.png
--------------------------------------------------------------------------------
/msns-image/image-20200412100402177.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dodudo/msns/beccf0fd921e001c51fb82b00adcd9297a6008ac/msns-image/image-20200412100402177.png
--------------------------------------------------------------------------------
/msns-image/image-20200412100947905.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dodudo/msns/beccf0fd921e001c51fb82b00adcd9297a6008ac/msns-image/image-20200412100947905.png
--------------------------------------------------------------------------------
/msns-image/image-20200412101108681.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dodudo/msns/beccf0fd921e001c51fb82b00adcd9297a6008ac/msns-image/image-20200412101108681.png
--------------------------------------------------------------------------------
/msns-image/image-20200412101125828.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dodudo/msns/beccf0fd921e001c51fb82b00adcd9297a6008ac/msns-image/image-20200412101125828.png
--------------------------------------------------------------------------------
/msns-image/image-20200412101139438.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dodudo/msns/beccf0fd921e001c51fb82b00adcd9297a6008ac/msns-image/image-20200412101139438.png
--------------------------------------------------------------------------------
/msns-image/image-20200412101202512.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dodudo/msns/beccf0fd921e001c51fb82b00adcd9297a6008ac/msns-image/image-20200412101202512.png
--------------------------------------------------------------------------------
/msns-image/image-20200412101230197.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dodudo/msns/beccf0fd921e001c51fb82b00adcd9297a6008ac/msns-image/image-20200412101230197.png
--------------------------------------------------------------------------------
/msns-image/image-20200412101302412.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dodudo/msns/beccf0fd921e001c51fb82b00adcd9297a6008ac/msns-image/image-20200412101302412.png
--------------------------------------------------------------------------------
/msns-image/image-20200412101342999.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dodudo/msns/beccf0fd921e001c51fb82b00adcd9297a6008ac/msns-image/image-20200412101342999.png
--------------------------------------------------------------------------------
/msns-image/image-20200412101537509.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dodudo/msns/beccf0fd921e001c51fb82b00adcd9297a6008ac/msns-image/image-20200412101537509.png
--------------------------------------------------------------------------------
/msns-image/image-20200412101602321.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dodudo/msns/beccf0fd921e001c51fb82b00adcd9297a6008ac/msns-image/image-20200412101602321.png
--------------------------------------------------------------------------------
/msns-image/image-20200412101603971.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dodudo/msns/beccf0fd921e001c51fb82b00adcd9297a6008ac/msns-image/image-20200412101603971.png
--------------------------------------------------------------------------------
/msns-image/image-20200412101635931.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dodudo/msns/beccf0fd921e001c51fb82b00adcd9297a6008ac/msns-image/image-20200412101635931.png
--------------------------------------------------------------------------------
/msns-image/image-20200412101701964.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dodudo/msns/beccf0fd921e001c51fb82b00adcd9297a6008ac/msns-image/image-20200412101701964.png
--------------------------------------------------------------------------------
/msns-image/image-20200412101703368.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dodudo/msns/beccf0fd921e001c51fb82b00adcd9297a6008ac/msns-image/image-20200412101703368.png
--------------------------------------------------------------------------------
/msns-image/image-20200412101726016.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dodudo/msns/beccf0fd921e001c51fb82b00adcd9297a6008ac/msns-image/image-20200412101726016.png
--------------------------------------------------------------------------------
/msns-image/image-20200412101806656.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dodudo/msns/beccf0fd921e001c51fb82b00adcd9297a6008ac/msns-image/image-20200412101806656.png
--------------------------------------------------------------------------------
/msns-image/image-20200412101839411.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dodudo/msns/beccf0fd921e001c51fb82b00adcd9297a6008ac/msns-image/image-20200412101839411.png
--------------------------------------------------------------------------------
/msns-image/image-20200412101920506.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dodudo/msns/beccf0fd921e001c51fb82b00adcd9297a6008ac/msns-image/image-20200412101920506.png
--------------------------------------------------------------------------------
/msns-image/image-20200412102056128.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dodudo/msns/beccf0fd921e001c51fb82b00adcd9297a6008ac/msns-image/image-20200412102056128.png
--------------------------------------------------------------------------------
/msns-image/image-20200412205503555.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dodudo/msns/beccf0fd921e001c51fb82b00adcd9297a6008ac/msns-image/image-20200412205503555.png
--------------------------------------------------------------------------------
/msns-like/msns-like-interface/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | msns-like
7 | com.dxg.msns.like
8 | 1.0-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | msns-like-interface
13 |
14 |
15 | org.springframework
16 | spring-web
17 |
18 |
19 | javax.persistence
20 | persistence-api
21 | 1.0
22 |
23 |
24 | com.fasterxml.jackson.core
25 | jackson-annotations
26 |
27 |
28 | com.dxg.msns.common
29 | msns-common
30 | 1.0-SNAPSHOT
31 | compile
32 |
33 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/msns-like/msns-like-interface/src/main/java/com/dxg/msns/like/api/LikeApi.java:
--------------------------------------------------------------------------------
1 | package com.dxg.msns.like.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 |
7 | public interface LikeApi {
8 | /**
9 | * 查询动态的点赞数
10 | *
11 | */
12 | @GetMapping("queryCountsByDynamicId/{id}")
13 | public Integer queryCountsByDynamicId(@PathVariable("id") Integer dynamicId);
14 | }
15 |
--------------------------------------------------------------------------------
/msns-like/msns-like-interface/src/main/java/com/dxg/msns/like/pojo/Like.java:
--------------------------------------------------------------------------------
1 | package com.dxg.msns.like.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.util.Date;
8 | import java.io.Serializable;
9 |
10 | /**
11 | * (Like)实体类
12 | *
13 | * @author makejava
14 | * @since 2020-03-13 21:05:21
15 | */
16 | @Table(name = "dynamic_like")
17 | public class Like implements Serializable {
18 | private static final long serialVersionUID = 102615283971963257L;
19 | /**
20 | * 主键id自增
21 | */
22 | @Id
23 | @GeneratedValue(strategy = GenerationType.IDENTITY)
24 | private Integer id;
25 | /**
26 | * 点赞者id
27 | */
28 | private String likerId;
29 | /**
30 | * 动态id
31 | */
32 | private Integer dynamicId;
33 | /**
34 | * 文章发布者id
35 | */
36 | private String dynamicAuthorid;
37 | /**
38 | * 点赞时间
39 | */
40 | private Date likeDate;
41 |
42 | /**
43 | * 状态
44 | */
45 | private String status;
46 |
47 | public Integer getId() {
48 | return id;
49 | }
50 |
51 | public void setId(Integer id) {
52 | this.id = id;
53 | }
54 |
55 | public String getLikerId() {
56 | return likerId;
57 | }
58 |
59 | public void setLikerId(String likerId) {
60 | this.likerId = likerId;
61 | }
62 |
63 | public Integer getDynamicId() {
64 | return dynamicId;
65 | }
66 |
67 | public void setDynamicId(Integer dynamicId) {
68 | this.dynamicId = dynamicId;
69 | }
70 |
71 | public String getDynamicAuthorid() {
72 | return dynamicAuthorid;
73 | }
74 |
75 | public void setDynamicAuthorid(String dynamicAuthorid) {
76 | this.dynamicAuthorid = dynamicAuthorid;
77 | }
78 |
79 | public Date getLikeDate() {
80 | return likeDate;
81 | }
82 |
83 | public void setLikeDate(Date likeDate) {
84 | this.likeDate = likeDate;
85 | }
86 |
87 | public String getStatus() {
88 | return status;
89 | }
90 |
91 | public void setStatus(String status) {
92 | this.status = status;
93 | }
94 |
95 | @Override
96 | public String toString() {
97 | return "Like{" +
98 | "id=" + id +
99 | ", likerId='" + likerId + '\'' +
100 | ", dynamicId=" + dynamicId +
101 | ", dynamicAuthorid='" + dynamicAuthorid + '\'' +
102 | ", likeDate=" + likeDate +
103 | ", status='" + status + '\'' +
104 | '}';
105 | }
106 | }
--------------------------------------------------------------------------------
/msns-like/msns-like-service/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | msns-like
7 | com.dxg.msns.like
8 | 1.0-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | msns-like-service
13 |
14 |
15 |
16 |
17 | org.springframework.boot
18 | spring-boot-starter-web
19 |
20 |
21 |
22 | org.springframework.cloud
23 | spring-cloud-starter-netflix-eureka-client
24 |
25 |
26 |
27 | org.mybatis.spring.boot
28 | mybatis-spring-boot-starter
29 |
30 |
31 |
32 | tk.mybatis
33 | mapper-spring-boot-starter
34 |
35 |
36 |
37 | com.github.pagehelper
38 | pagehelper-spring-boot-starter
39 |
40 |
41 |
42 | org.springframework.boot
43 | spring-boot-starter-jdbc
44 |
45 |
46 |
47 | mysql
48 | mysql-connector-java
49 |
50 |
51 | org.springframework.boot
52 | spring-boot-starter-amqp
53 |
54 |
55 |
56 |
57 | org.springframework.boot
58 | spring-boot-starter-actuator
59 |
60 |
61 |
62 | com.dxg.msns.like
63 | msns-like-interface
64 | 1.0-SNAPSHOT
65 |
66 |
67 | com.dxg.msns.common
68 | msns-common
69 | 1.0-SNAPSHOT
70 | compile
71 |
72 |
73 |
74 |
--------------------------------------------------------------------------------
/msns-like/msns-like-service/src/main/java/com/dxg/msns/like/MSNSLikeServiceApplication.java:
--------------------------------------------------------------------------------
1 | package com.dxg.msns.like;
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 | @SpringBootApplication
9 | @EnableDiscoveryClient
10 | @MapperScan("com.dxg.msns.like.mapper")
11 | public class MSNSLikeServiceApplication {
12 | public static void main(String[] args) {
13 | SpringApplication.run(MSNSLikeServiceApplication.class);
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/msns-like/msns-like-service/src/main/java/com/dxg/msns/like/mapper/LikeMapper.java:
--------------------------------------------------------------------------------
1 | package com.dxg.msns.like.mapper;
2 |
3 | import com.dxg.msns.like.pojo.Like;
4 | import org.apache.commons.lang.ArrayUtils;
5 | import org.apache.ibatis.annotations.UpdateProvider;
6 | import tk.mybatis.mapper.common.Mapper;
7 |
8 | import java.util.Map;
9 |
10 | public interface LikeMapper extends Mapper {
11 | /**
12 | * 根据ids修改状态
13 | *
14 | * @param ids
15 | * @param status
16 | */
17 | @UpdateProvider(type = Provider.class, method = "batchUpdate")
18 | void updateStateByIds(Integer[] ids, String status,String dynamicAuthorid);
19 |
20 | class Provider {
21 | //批量修改
22 | public String batchUpdate(Map map) {
23 | Integer[] ids = (Integer []) map.get("param1");
24 | String status = (String) map.get("param2");
25 | String dynamicAuthorid = (String) map.get("param3");
26 | StringBuilder sb = new StringBuilder();
27 | if (ArrayUtils.isEmpty(ids)) { //全选
28 | sb.append("update dynamic_like set status = '" + status + "' where dynamic_authorId = '"+dynamicAuthorid+"' and status != '-1' and status != '0'");
29 | } else {
30 | sb.append("update dynamic_like set status = '" + status + "' where dynamic_authorId = '"+dynamicAuthorid+"' and status != '-1' and status != '0' and id in (");
31 | for (int i = 0; i < ids.length; i++) {
32 | sb.append(ids[i]);
33 | if (i < ids.length - 1) {
34 | sb.append(",");
35 | }
36 | }
37 | sb.append(")");
38 | }
39 | return sb.toString();
40 | }
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/msns-like/msns-like-service/src/main/java/com/dxg/msns/like/service/LikeService.java:
--------------------------------------------------------------------------------
1 | package com.dxg.msns.like.service;
2 |
3 | import com.dxg.msns.common.pojo.PageResult;
4 | import com.dxg.msns.like.pojo.Like;
5 |
6 | import java.util.List;
7 |
8 | public interface LikeService {
9 | /**
10 | * 查询动态点赞数
11 | * @param dynamicId
12 | * @return
13 | */
14 | Integer queryCountsByDynamicId(Integer dynamicId);
15 |
16 | /**
17 | * 添加点赞信息
18 | * @param like
19 | */
20 | void addLike(Like like);
21 |
22 | /**
23 | * 根据动态id和点赞者id查询该用户是否点赞
24 | * @param dynamicIds
25 | * @param likerId
26 | * @return
27 | */
28 | List queryIsLike(Integer[] dynamicIds, String likerId);
29 |
30 | /**
31 | * 删除点赞信息
32 | * @param like
33 | */
34 | void deleteLike(Like like);
35 |
36 | /**
37 | * 分页查询
38 | * @param page
39 | * @param rows
40 | * @param sortBy
41 | * @param desc
42 | * @param like
43 | * @return
44 | */
45 | PageResult queryByPage( Integer page, Integer rows, String[] sortBy, Boolean[] desc, Like like);
46 |
47 | /**
48 | * 根据id修改状态
49 | * @param ids
50 | * @param status
51 | */
52 | void updateStateByIds(Integer[] ids, String status,String dynamicAuthorid);
53 |
54 | /**
55 | * 查询未读消息次数
56 | * @param dynamicAuthorid
57 | * @return
58 | */
59 | Integer queryCountsByDynamicAuthorid(String dynamicAuthorid);
60 | }
61 |
--------------------------------------------------------------------------------
/msns-like/msns-like-service/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 | server:
2 | port: 8088
3 | spring:
4 | application:
5 | name: like-service
6 | datasource:
7 | url: jdbc:mysql:///msns?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC
8 | username: root
9 | password: root
10 | driver-class-name: com.mysql.jdbc.Driver
11 | hikari:
12 | max-lifetime: 28830000 # 一个连接的生命时长(毫秒),超时而且没被使用则被释放(retired),缺省:30分钟,建议设置比数据库超时时长少30秒,参考MySQL wait_timeout参数(show variables like '%timeout%';)
13 | maximum-pool-size: 9 # 连接池中允许的最大连接数。缺省值:10;推荐的公式:((core_count * 2) + effective_spindle_count)
14 | rabbitmq:
15 | port: 5672
16 | username: msns
17 | password: msns
18 | virtual-host: /msns
19 | template:
20 | exchange: msns.dynamic.exchange
21 | publisher-confirms: true
22 | eureka:
23 | client:
24 | service-url:
25 | defaultZone: http://127.0.0.1:10086/eureka
26 | instance:
27 | lease-expiration-duration-in-seconds: 10 #10秒不发送就过期
28 | lease-renewal-interval-in-seconds: 5 #5秒发送一次心跳
29 | logging:
30 | level:
31 | root: DEBUG
--------------------------------------------------------------------------------
/msns-like/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | msns
7 | com.dxg.msns.parent
8 | 1.0-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | com.dxg.msns.like
13 | msns-like
14 | pom
15 |
16 | msns-like-interface
17 | msns-like-service
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/msns-music/msns-music-interface/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | msns-music
7 | com.dxg.msns.music
8 | 1.0-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | msns-music-interface
13 |
14 |
15 |
16 | javax.persistence
17 | persistence-api
18 | 1.0
19 |
20 |
21 | com.fasterxml.jackson.core
22 | jackson-annotations
23 |
24 |
25 | org.springframework
26 | spring-web
27 |
28 |
29 | com.dxg.msns.common
30 | msns-common
31 | 1.0-SNAPSHOT
32 | compile
33 |
34 |
35 |
--------------------------------------------------------------------------------
/msns-music/msns-music-interface/src/main/java/com/dxg/msns/music/api/MusicApi.java:
--------------------------------------------------------------------------------
1 | package com.dxg.msns.music.api;
2 |
3 | import com.dxg.msns.common.pojo.PageResult;
4 | import com.dxg.msns.music.pojo.Music;
5 | import org.springframework.http.ResponseEntity;
6 | import org.springframework.web.bind.annotation.PathVariable;
7 | import org.springframework.web.bind.annotation.RequestMapping;
8 | import org.springframework.web.bind.annotation.RequestParam;
9 |
10 | public interface MusicApi {
11 | /**
12 | * 根据id查找音乐
13 | * @param id
14 | * @return
15 | */
16 | @RequestMapping("queryById/{id}")
17 | public Music queryMusicById(@PathVariable("id") Integer id);
18 |
19 | /**
20 | * 根据音乐id查找音乐
21 | * @param musicId
22 | * @return
23 | */
24 | @RequestMapping("queryByMusicId/{id}")
25 | public Music queryMusicByMusicId(@PathVariable("id") String musicId);
26 |
27 | /**
28 | * 查询所有音乐结果,分页
29 | * @param key
30 | * @param page
31 | * @param rows
32 | * @param sortBy
33 | * @param desc
34 | * @param isAll
35 | * @return
36 | */
37 | @RequestMapping("page")
38 | public PageResult queryMusicsByPage(
39 | @RequestParam(value = "key",required = false)String key,
40 | @RequestParam(value = "page",defaultValue = "1")Integer page,
41 | @RequestParam(value = "rows",defaultValue = "5")Integer rows,
42 | @RequestParam(value = "sortBy",required = false)String sortBy[],
43 | @RequestParam(value = "desc",required = false)Boolean desc[],
44 | @RequestParam(value = "isAll",required = false)Boolean isAll
45 | );
46 | }
47 |
--------------------------------------------------------------------------------
/msns-music/msns-music-interface/src/main/java/com/dxg/msns/music/api/MusicTypeApi.java:
--------------------------------------------------------------------------------
1 | package com.dxg.msns.music.api;
2 |
3 | import com.dxg.msns.music.pojo.MusicType;
4 | import org.springframework.http.ResponseEntity;
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 | @RequestMapping("type")
10 | public interface MusicTypeApi {
11 | @RequestMapping("queryById/{id}")
12 | public MusicType queryById(@PathVariable("id")Integer id);
13 | }
14 |
--------------------------------------------------------------------------------
/msns-music/msns-music-interface/src/main/java/com/dxg/msns/music/pojo/MusicType.java:
--------------------------------------------------------------------------------
1 | package com.dxg.msns.music.pojo;
2 |
3 | import javax.persistence.GeneratedValue;
4 | import javax.persistence.GenerationType;
5 | import javax.persistence.Id;
6 | import javax.persistence.Table;
7 |
8 | @Table(name = "music_type")
9 | public class MusicType {
10 | @Id
11 | @GeneratedValue(strategy = GenerationType.IDENTITY)
12 | private Integer id;
13 | private String typeName;
14 | private String typeStatus;
15 |
16 | public Integer getId() {
17 | return id;
18 | }
19 |
20 | public void setId(Integer id) {
21 | this.id = id;
22 | }
23 |
24 | public String getTypeName() {
25 | return typeName;
26 | }
27 |
28 | public void setTypeName(String typeName) {
29 | this.typeName = typeName;
30 | }
31 |
32 | public String getTypeStatus() {
33 | return typeStatus;
34 | }
35 |
36 | public void setTypeStatus(String typeStatus) {
37 | this.typeStatus = typeStatus;
38 | }
39 |
40 | @Override
41 | public String toString() {
42 | return "MusicType{" +
43 | "id=" + id +
44 | ", typeName='" + typeName + '\'' +
45 | ", typeStatus='" + typeStatus + '\'' +
46 | '}';
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/msns-music/msns-music-interface/src/main/java/com/dxg/msns/music/pojo/TypeStatistics.java:
--------------------------------------------------------------------------------
1 | package com.dxg.msns.music.pojo;
2 |
3 | public class TypeStatistics {
4 | private String typeName;
5 | private Integer musicCount;
6 |
7 | public String getTypeName() {
8 | return typeName;
9 | }
10 |
11 | public void setTypeName(String typeName) {
12 | this.typeName = typeName;
13 | }
14 |
15 | public Integer getMusicCount() {
16 | return musicCount;
17 | }
18 |
19 | public void setMusicCount(Integer musicCount) {
20 | this.musicCount = musicCount;
21 | }
22 |
23 | @Override
24 | public String toString() {
25 | return "TypeStatistics{" +
26 | "typeName='" + typeName + '\'' +
27 | ", musicCount=" + musicCount +
28 | '}';
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/msns-music/msns-music-interface/target/classes/com/dxg/msns/music/pojo/Music.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dodudo/msns/beccf0fd921e001c51fb82b00adcd9297a6008ac/msns-music/msns-music-interface/target/classes/com/dxg/msns/music/pojo/Music.class
--------------------------------------------------------------------------------
/msns-music/msns-music-interface/target/classes/com/dxg/msns/music/pojo/MusicType.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dodudo/msns/beccf0fd921e001c51fb82b00adcd9297a6008ac/msns-music/msns-music-interface/target/classes/com/dxg/msns/music/pojo/MusicType.class
--------------------------------------------------------------------------------
/msns-music/msns-music-interface/target/classes/com/dxg/msns/music/pojo/TypeStatistics.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dodudo/msns/beccf0fd921e001c51fb82b00adcd9297a6008ac/msns-music/msns-music-interface/target/classes/com/dxg/msns/music/pojo/TypeStatistics.class
--------------------------------------------------------------------------------
/msns-music/msns-music-service/src/main/java/com/dxg/msns/music/MSNSMusicServiceApplication.java:
--------------------------------------------------------------------------------
1 | package com.dxg.msns.music;
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 | @SpringBootApplication
9 | @EnableDiscoveryClient
10 | @MapperScan("com.dxg.msns.music.mapper")
11 | public class MSNSMusicServiceApplication {
12 | public static void main(String[] args) {
13 | SpringApplication.run(MSNSMusicServiceApplication.class);
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/msns-music/msns-music-service/src/main/java/com/dxg/msns/music/controller/MusicTypeController.java:
--------------------------------------------------------------------------------
1 | package com.dxg.msns.music.controller;
2 |
3 | import com.dxg.msns.music.pojo.MusicType;
4 | import com.dxg.msns.music.service.MusicTypeService;
5 | import org.springframework.beans.factory.annotation.Autowired;
6 | import org.springframework.http.ResponseEntity;
7 | import org.springframework.web.bind.annotation.PathVariable;
8 | import org.springframework.web.bind.annotation.RequestBody;
9 | import org.springframework.web.bind.annotation.RequestMapping;
10 | import org.springframework.web.bind.annotation.RestController;
11 |
12 | import java.util.List;
13 |
14 | @RestController
15 | @RequestMapping("type")
16 | public class MusicTypeController {
17 | @Autowired
18 | private MusicTypeService musicTypeService;
19 |
20 | @RequestMapping("all")
21 | public ResponseEntity> queryAllTypes(){
22 | List musicTypes = musicTypeService.queryAllTypes();
23 | return ResponseEntity.ok(musicTypes);
24 | }
25 | @RequestMapping("queryById/{id}")
26 | public ResponseEntity queryById(@PathVariable("id")Integer id){
27 | MusicType musicType = musicTypeService.queryById(id);
28 | return ResponseEntity.ok(musicType);
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/msns-music/msns-music-service/src/main/java/com/dxg/msns/music/mapper/MusicMapper.java:
--------------------------------------------------------------------------------
1 | package com.dxg.msns.music.mapper;
2 |
3 | import com.dxg.msns.music.pojo.Music;
4 | import com.dxg.msns.music.pojo.TypeStatistics;
5 | import org.apache.ibatis.annotations.Result;
6 | import org.apache.ibatis.annotations.Results;
7 | import org.apache.ibatis.annotations.Select;
8 | import tk.mybatis.mapper.common.Mapper;
9 |
10 | import java.util.List;
11 |
12 | public interface MusicMapper extends Mapper {
13 | @Select("select type_name,count(*) as music_count from music as m left join music_type as mt on m.music_type_id = mt.id GROUP BY type_name")
14 | @Results(id = "typeStatisticsMap",value = {
15 | @Result(column = "type_name",property = "typeName"),
16 | @Result(column = "music_count",property = "musicCount")
17 | })
18 | List queryTypeStatistics();
19 |
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/msns-music/msns-music-service/src/main/java/com/dxg/msns/music/mapper/MusicTypeMapper.java:
--------------------------------------------------------------------------------
1 | package com.dxg.msns.music.mapper;
2 |
3 | import com.dxg.msns.music.pojo.MusicType;
4 | import tk.mybatis.mapper.common.Mapper;
5 |
6 | public interface MusicTypeMapper extends Mapper {
7 | }
8 |
--------------------------------------------------------------------------------
/msns-music/msns-music-service/src/main/java/com/dxg/msns/music/service/MusicService.java:
--------------------------------------------------------------------------------
1 | package com.dxg.msns.music.service;
2 |
3 | import com.dxg.msns.common.pojo.PageResult;
4 | import com.dxg.msns.music.pojo.Music;
5 | import com.dxg.msns.music.pojo.TypeStatistics;
6 |
7 | import java.util.List;
8 |
9 | public interface MusicService {
10 | /**
11 | * 查询所有音乐分类
12 | * @param key
13 | * @param page
14 | * @param rows
15 | * @param sortBy
16 | * @param desc
17 | * @param isAll
18 | * @return
19 | */
20 | public PageResult queryMusicsByPage(String key, Integer page, Integer rows, String[] sortBy, Boolean[] desc, Boolean isAll);
21 |
22 | /**
23 | * 查询音乐分类统计
24 | * @return
25 | */
26 | List queryTypeStatistics();
27 |
28 | /**
29 | * 修改音乐
30 | * @param music
31 | */
32 | void updateMusic(Music music);
33 |
34 | /**
35 | * 添加音乐
36 | * @param music
37 | */
38 | void saveMusic(Music music);
39 |
40 |
41 | /**
42 | * 查找是否有相同音乐
43 | * @param music
44 | * @return
45 | */
46 | boolean findMusicByInfo(Music music);
47 |
48 | /**
49 | * 删除音乐
50 | * @param music
51 | */
52 | void deleteMusic(Music music);
53 |
54 | /**
55 | * 根据id查找音乐
56 | * @param id
57 | * @return
58 | */
59 | Music queryMusicById(Integer id);
60 |
61 | /**
62 | * 根据音乐id查找音乐
63 | * @param musicId
64 | * @return
65 | */
66 | Music queryMusicByMusicId(String musicId);
67 | }
68 |
--------------------------------------------------------------------------------
/msns-music/msns-music-service/src/main/java/com/dxg/msns/music/service/MusicTypeService.java:
--------------------------------------------------------------------------------
1 | package com.dxg.msns.music.service;
2 |
3 | import com.dxg.msns.music.pojo.MusicType;
4 | import org.springframework.http.ResponseEntity;
5 |
6 | import java.util.List;
7 |
8 | public interface MusicTypeService {
9 | List queryAllTypes();
10 |
11 | /**
12 | * 根据id查询
13 | * @param id
14 | * @return
15 | */
16 | MusicType queryById(Integer id);
17 | }
18 |
--------------------------------------------------------------------------------
/msns-music/msns-music-service/src/main/java/com/dxg/msns/music/service/impl/MusicTypeServiceImpl.java:
--------------------------------------------------------------------------------
1 | package com.dxg.msns.music.service.impl;
2 |
3 | import com.dxg.msns.music.mapper.MusicTypeMapper;
4 | import com.dxg.msns.music.pojo.MusicType;
5 | import com.dxg.msns.music.service.MusicTypeService;
6 | import org.springframework.beans.factory.annotation.Autowired;
7 | import org.springframework.http.ResponseEntity;
8 | import org.springframework.stereotype.Service;
9 |
10 | import java.util.List;
11 | @Service
12 | public class MusicTypeServiceImpl implements MusicTypeService {
13 | @Autowired
14 | private MusicTypeMapper musicTypeMapper;
15 | @Override
16 | public List queryAllTypes() {
17 | return musicTypeMapper.selectAll();
18 | }
19 |
20 | /**
21 | * 根据id查询
22 | *
23 | * @param id
24 | * @return
25 | */
26 | @Override
27 | public MusicType queryById(Integer id) {
28 | MusicType musicType = this.musicTypeMapper.selectByPrimaryKey(id);
29 | return musicType;
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/msns-music/msns-music-service/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 | server:
2 | port: 8082
3 | spring:
4 | application:
5 | name: music-service
6 | datasource:
7 | url: jdbc:mysql:///msns?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC
8 | username: root
9 | password: root
10 | driver-class-name: com.mysql.jdbc.Driver
11 | hikari:
12 | max-lifetime: 28830000 # 一个连接的生命时长(毫秒),超时而且没被使用则被释放(retired),缺省:30分钟,建议设置比数据库超时时长少30秒,参考MySQL wait_timeout参数(show variables like '%timeout%';)
13 | maximum-pool-size: 9 # 连接池中允许的最大连接数。缺省值:10;推荐的公式:((core_count * 2) + effective_spindle_count)
14 | rabbitmq:
15 | host: 127.0.0.1
16 | port: 5672
17 | username: msns
18 | password: msns
19 | virtual-host: /msns
20 | template:
21 | exchange: msns.music.exchange
22 | publisher-confirms: true #生产者确认机制,确保消息会正确发送,如果发送失败会有错误回执,从而触发重试
23 | eureka:
24 | client:
25 | service-url:
26 | defaultZone: http://127.0.0.1:10086/eureka
27 | instance:
28 | lease-expiration-duration-in-seconds: 10 #10秒不发送就过期
29 | lease-renewal-interval-in-seconds: 5 #5秒发送一次心跳
30 | logging:
31 | level:
32 | root: DEBUG
33 |
--------------------------------------------------------------------------------
/msns-music/msns-music-service/target/classes/META-INF/msns-music-service.kotlin_module:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/msns-music/msns-music-service/target/classes/application.yml:
--------------------------------------------------------------------------------
1 | server:
2 | port: 8082
3 | spring:
4 | application:
5 | name: music-service
6 | datasource:
7 | url: jdbc:mysql:///msns?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC
8 | username: root
9 | password: root
10 | driver-class-name: com.mysql.jdbc.Driver
11 | hikari:
12 | max-lifetime: 28830000 # 一个连接的生命时长(毫秒),超时而且没被使用则被释放(retired),缺省:30分钟,建议设置比数据库超时时长少30秒,参考MySQL wait_timeout参数(show variables like '%timeout%';)
13 | maximum-pool-size: 9 # 连接池中允许的最大连接数。缺省值:10;推荐的公式:((core_count * 2) + effective_spindle_count)
14 | rabbitmq:
15 | host: 127.0.0.1
16 | port: 5672
17 | username: msns
18 | password: msns
19 | virtual-host: /msns
20 | template:
21 | exchange: msns.music.exchange
22 | publisher-confirms: true #生产者确认机制,确保消息会正确发送,如果发送失败会有错误回执,从而触发重试
23 | eureka:
24 | client:
25 | service-url:
26 | defaultZone: http://127.0.0.1:10086/eureka
27 | instance:
28 | lease-expiration-duration-in-seconds: 10 #10秒不发送就过期
29 | lease-renewal-interval-in-seconds: 5 #5秒发送一次心跳
30 | logging:
31 | level:
32 | root: DEBUG
33 |
--------------------------------------------------------------------------------
/msns-music/msns-music-service/target/classes/com/dxg/msns/music/MSNSMusicServiceApplication.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dodudo/msns/beccf0fd921e001c51fb82b00adcd9297a6008ac/msns-music/msns-music-service/target/classes/com/dxg/msns/music/MSNSMusicServiceApplication.class
--------------------------------------------------------------------------------
/msns-music/msns-music-service/target/classes/com/dxg/msns/music/controller/MusicController.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dodudo/msns/beccf0fd921e001c51fb82b00adcd9297a6008ac/msns-music/msns-music-service/target/classes/com/dxg/msns/music/controller/MusicController.class
--------------------------------------------------------------------------------
/msns-music/msns-music-service/target/classes/com/dxg/msns/music/controller/MusicTypeController.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dodudo/msns/beccf0fd921e001c51fb82b00adcd9297a6008ac/msns-music/msns-music-service/target/classes/com/dxg/msns/music/controller/MusicTypeController.class
--------------------------------------------------------------------------------
/msns-music/msns-music-service/target/classes/com/dxg/msns/music/mapper/MusicMapper.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dodudo/msns/beccf0fd921e001c51fb82b00adcd9297a6008ac/msns-music/msns-music-service/target/classes/com/dxg/msns/music/mapper/MusicMapper.class
--------------------------------------------------------------------------------
/msns-music/msns-music-service/target/classes/com/dxg/msns/music/mapper/MusicTypeMapper.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dodudo/msns/beccf0fd921e001c51fb82b00adcd9297a6008ac/msns-music/msns-music-service/target/classes/com/dxg/msns/music/mapper/MusicTypeMapper.class
--------------------------------------------------------------------------------
/msns-music/msns-music-service/target/classes/com/dxg/msns/music/service/MusicService.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dodudo/msns/beccf0fd921e001c51fb82b00adcd9297a6008ac/msns-music/msns-music-service/target/classes/com/dxg/msns/music/service/MusicService.class
--------------------------------------------------------------------------------
/msns-music/msns-music-service/target/classes/com/dxg/msns/music/service/MusicTypeService.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dodudo/msns/beccf0fd921e001c51fb82b00adcd9297a6008ac/msns-music/msns-music-service/target/classes/com/dxg/msns/music/service/MusicTypeService.class
--------------------------------------------------------------------------------
/msns-music/msns-music-service/target/classes/com/dxg/msns/music/service/impl/MusicServiceImpl.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dodudo/msns/beccf0fd921e001c51fb82b00adcd9297a6008ac/msns-music/msns-music-service/target/classes/com/dxg/msns/music/service/impl/MusicServiceImpl.class
--------------------------------------------------------------------------------
/msns-music/msns-music-service/target/classes/com/dxg/msns/music/service/impl/MusicTypeServiceImpl.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dodudo/msns/beccf0fd921e001c51fb82b00adcd9297a6008ac/msns-music/msns-music-service/target/classes/com/dxg/msns/music/service/impl/MusicTypeServiceImpl.class
--------------------------------------------------------------------------------
/msns-music/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | msns
7 | com.dxg.msns.parent
8 | 1.0-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | com.dxg.msns.music
13 | msns-music
14 | pom
15 |
16 | msns-music-interface
17 | msns-music-service
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/msns-registry/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | msns
7 | com.dxg.msns.parent
8 | 1.0-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | com.dxg.msns.common
13 | msns-registry
14 |
15 |
16 |
17 | org.springframework.cloud
18 | spring-cloud-starter-netflix-eureka-server
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/msns-registry/src/main/java/com/dxg/msns/MSNSRegistryApplication.java:
--------------------------------------------------------------------------------
1 | package com.dxg.msns;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
6 | import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
7 |
8 | @SpringBootApplication
9 | @EnableEurekaServer
10 | public class MSNSRegistryApplication {
11 | public static void main(String[] args) {
12 | SpringApplication.run(MSNSRegistryApplication.class,args);
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/msns-registry/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 | server:
2 | port: 10086
3 | spring:
4 | application:
5 | name: msns-registry
6 | eureka:
7 | client:
8 | service-url:
9 | defaultZone: http://127.0.0.1:${server.port}/eureka
10 | register-with-eureka: false #把自己注册到eureka服务列表
11 | fetch-registry: false #拉取eureka服务信息
12 | server:
13 | enable-self-preservation: false #关闭自我保护
14 | eviction-interval-timer-in-ms: 5000 #每隔5秒,进行一次服务列表的清理
--------------------------------------------------------------------------------
/msns-search/src/main/java/com/dxg/msns/search/MSNSSearchServiceApplication.java:
--------------------------------------------------------------------------------
1 | package com.dxg.msns.search;
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 | @SpringBootApplication(exclude = DataSourceAutoConfiguration.class)
10 | @EnableDiscoveryClient
11 | @EnableFeignClients
12 | public class MSNSSearchServiceApplication {
13 | public static void main(String[] args) {
14 | SpringApplication.run(MSNSSearchServiceApplication.class);
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/msns-search/src/main/java/com/dxg/msns/search/client/CommentClient.java:
--------------------------------------------------------------------------------
1 | package com.dxg.msns.search.client;
2 |
3 | import com.dxg.msns.comment.api.CommentApi;
4 | import org.springframework.cloud.openfeign.FeignClient;
5 |
6 | @FeignClient("comment-service")
7 | public interface CommentClient extends CommentApi {
8 | }
9 |
--------------------------------------------------------------------------------
/msns-search/src/main/java/com/dxg/msns/search/client/DynamicFavorClient.java:
--------------------------------------------------------------------------------
1 | package com.dxg.msns.search.client;
2 |
3 | import com.dxg.msns.favor.api.DynamicFavorApi;
4 | import org.springframework.cloud.openfeign.FeignClient;
5 |
6 | @FeignClient("favor-service")
7 | public interface DynamicFavorClient extends DynamicFavorApi {
8 | }
9 |
--------------------------------------------------------------------------------
/msns-search/src/main/java/com/dxg/msns/search/client/DynamicTypeClient.java:
--------------------------------------------------------------------------------
1 | package com.dxg.msns.search.client;
2 |
3 | import com.dxg.msns.dynamic.api.DynamicTypeApi;
4 | import org.springframework.cloud.openfeign.FeignClient;
5 |
6 | @FeignClient("dynamic-service")
7 | public interface DynamicTypeClient extends DynamicTypeApi {
8 | }
9 |
--------------------------------------------------------------------------------
/msns-search/src/main/java/com/dxg/msns/search/client/DynamicsClient.java:
--------------------------------------------------------------------------------
1 | package com.dxg.msns.search.client;
2 |
3 | import com.dxg.msns.dynamic.api.DynamicApi;
4 | import org.springframework.cloud.openfeign.FeignClient;
5 |
6 | @FeignClient("dynamic-service")
7 | public interface DynamicsClient extends DynamicApi {
8 | }
9 |
--------------------------------------------------------------------------------
/msns-search/src/main/java/com/dxg/msns/search/client/FollowClient.java:
--------------------------------------------------------------------------------
1 | package com.dxg.msns.search.client;
2 |
3 | import com.dxg.msns.user.api.FollowApi;
4 | import org.springframework.cloud.openfeign.FeignClient;
5 |
6 | @FeignClient("user-service")
7 | public interface FollowClient extends FollowApi {
8 | }
9 |
--------------------------------------------------------------------------------
/msns-search/src/main/java/com/dxg/msns/search/client/LikeClient.java:
--------------------------------------------------------------------------------
1 | package com.dxg.msns.search.client;
2 |
3 | import com.dxg.msns.like.api.LikeApi;
4 | import org.springframework.cloud.openfeign.FeignClient;
5 |
6 | @FeignClient("like-service")
7 | public interface LikeClient extends LikeApi {
8 | }
9 |
--------------------------------------------------------------------------------
/msns-search/src/main/java/com/dxg/msns/search/client/MusicClient.java:
--------------------------------------------------------------------------------
1 | package com.dxg.msns.search.client;
2 |
3 | import com.dxg.msns.music.api.MusicApi;
4 | import org.springframework.cloud.openfeign.FeignClient;
5 |
6 | @FeignClient("music-service")
7 | public interface MusicClient extends MusicApi {
8 | }
9 |
--------------------------------------------------------------------------------
/msns-search/src/main/java/com/dxg/msns/search/client/MusicFavorClient.java:
--------------------------------------------------------------------------------
1 | package com.dxg.msns.search.client;
2 |
3 | import com.dxg.msns.favor.api.MusicFavorApi;
4 | import org.springframework.cloud.openfeign.FeignClient;
5 |
6 | @FeignClient("favor-service")
7 | public interface MusicFavorClient extends MusicFavorApi {
8 | }
9 |
--------------------------------------------------------------------------------
/msns-search/src/main/java/com/dxg/msns/search/client/MusicTypeClient.java:
--------------------------------------------------------------------------------
1 | package com.dxg.msns.search.client;
2 |
3 | import com.dxg.msns.music.api.MusicTypeApi;
4 | import org.springframework.cloud.openfeign.FeignClient;
5 |
6 | @FeignClient("music-service")
7 | public interface MusicTypeClient extends MusicTypeApi {
8 | }
9 |
--------------------------------------------------------------------------------
/msns-search/src/main/java/com/dxg/msns/search/client/UserClient.java:
--------------------------------------------------------------------------------
1 | package com.dxg.msns.search.client;
2 |
3 | import com.dxg.msns.user.api.UserApi;
4 | import org.springframework.cloud.openfeign.FeignClient;
5 |
6 | @FeignClient("user-service")
7 | public interface UserClient extends UserApi {
8 | }
9 |
--------------------------------------------------------------------------------
/msns-search/src/main/java/com/dxg/msns/search/controller/DynamicSearchController.java:
--------------------------------------------------------------------------------
1 | package com.dxg.msns.search.controller;
2 |
3 | import com.dxg.msns.common.pojo.PageResult;
4 | import com.dxg.msns.search.pojo.Dynamics;
5 | import com.dxg.msns.search.pojo.SearchRequst;
6 | import com.dxg.msns.search.service.DynamicSearchService;
7 | import org.springframework.beans.factory.annotation.Autowired;
8 | import org.springframework.http.HttpStatus;
9 | import org.springframework.http.ResponseEntity;
10 | import org.springframework.stereotype.Controller;
11 | import org.springframework.web.bind.annotation.*;
12 |
13 | @RestController
14 | @RequestMapping("dynamic")
15 | public class DynamicSearchController {
16 | @Autowired
17 | private DynamicSearchService dynamicSearchService;
18 |
19 | @PostMapping("dynamicPage")
20 | public ResponseEntity> searchDynamic(@RequestBody SearchRequst request){
21 | PageResult result = this.dynamicSearchService.searchDynamics(request);
22 | if (result == null){
23 | return new ResponseEntity<>(HttpStatus.NOT_FOUND);
24 | }
25 | return ResponseEntity.ok(result);
26 | }
27 |
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/msns-search/src/main/java/com/dxg/msns/search/controller/MusicSearchController.java:
--------------------------------------------------------------------------------
1 | package com.dxg.msns.search.controller;
2 |
3 | import com.dxg.msns.common.pojo.PageResult;
4 | import com.dxg.msns.music.pojo.Music;
5 | import com.dxg.msns.search.pojo.Dynamics;
6 | import com.dxg.msns.search.pojo.Musics;
7 | import com.dxg.msns.search.pojo.SearchRequst;
8 | import com.dxg.msns.search.service.DynamicSearchService;
9 | import com.dxg.msns.search.service.MusicSearchService;
10 | import org.springframework.beans.factory.annotation.Autowired;
11 | import org.springframework.http.HttpStatus;
12 | import org.springframework.http.ResponseEntity;
13 | import org.springframework.web.bind.annotation.PostMapping;
14 | import org.springframework.web.bind.annotation.RequestBody;
15 | import org.springframework.web.bind.annotation.RequestMapping;
16 | import org.springframework.web.bind.annotation.RestController;
17 |
18 | @RestController
19 | @RequestMapping("music")
20 | public class MusicSearchController {
21 | @Autowired
22 | private MusicSearchService musicSearchService;
23 |
24 | @PostMapping("page")
25 | public ResponseEntity> searchMusic(@RequestBody SearchRequst request){
26 | System.out.println("request:::::"+request);
27 | PageResult result = this.musicSearchService.searchMusic(request);
28 | if (result == null){
29 | return new ResponseEntity<>(HttpStatus.NOT_FOUND);
30 | }
31 | return ResponseEntity.ok(result);
32 | }
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/msns-search/src/main/java/com/dxg/msns/search/controller/UserSearchController.java:
--------------------------------------------------------------------------------
1 | package com.dxg.msns.search.controller;
2 |
3 | import com.dxg.msns.search.service.UserSearchService;
4 | import com.dxg.msns.user.pojo.UserCountInfo;
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.PathVariable;
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 |
13 | @RestController
14 | @RequestMapping("user")
15 | public class UserSearchController {
16 | @Autowired
17 | private UserSearchService userSearchService;
18 |
19 | /**
20 | * 根据用户id查询用户的一些统计信息
21 | * @param uid
22 | * @return
23 | */
24 | @RequestMapping("userCountInfo/{uid}")
25 | public ResponseEntity userCountInfo(@PathVariable("uid")String uid){
26 | UserCountInfo userCountInfo = userSearchService.userCountInfo(uid);
27 | if (userCountInfo == null){
28 | return new ResponseEntity<>(HttpStatus.NOT_FOUND);
29 | }
30 | return ResponseEntity.ok(userCountInfo);
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/msns-search/src/main/java/com/dxg/msns/search/listener/DynamicListener.java:
--------------------------------------------------------------------------------
1 | package com.dxg.msns.search.listener;
2 |
3 | import com.dxg.msns.search.service.DynamicSearchService;
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 | @Component
13 | public class DynamicListener {
14 | @Autowired
15 | private DynamicSearchService dynamicSearchService;
16 |
17 | /**处理insert和update的信息
18 | *
19 | * @param id
20 | */
21 | @RabbitListener(bindings = @QueueBinding(
22 | value = @Queue(value = "msns.create.index.queue",durable = "true"),
23 | exchange = @Exchange(
24 | value = "msns.dynamic.exchange",
25 | ignoreDeclarationExceptions = "true",
26 | type = ExchangeTypes.TOPIC
27 | ),
28 | key = {"dynamic.insert","dynamic.update"}
29 | ))
30 | public void listenCreate(Integer id)throws Exception{
31 | if (id == null){
32 | return;
33 | }
34 | this.dynamicSearchService.createDynamicIndex(id);
35 | }
36 |
37 | /**
38 | * 处理delete信息
39 | * @param id
40 | * @throws Exception
41 | */
42 | @RabbitListener(bindings = @QueueBinding(
43 | value = @Queue(value = "msns.delete.index.queue",durable = "true"),
44 | exchange = @Exchange(
45 | value = "msns.dynamic.exchange",
46 | ignoreDeclarationExceptions = "true",
47 | type = ExchangeTypes.TOPIC
48 | ),
49 | key = {"dynamic.delete"}
50 | ))
51 | public void listenDelete(Integer id)throws Exception{
52 | if (id == null){
53 | return;
54 | }
55 | this.dynamicSearchService.deleteDynamicIndex(id);
56 | }
57 |
58 | }
59 |
--------------------------------------------------------------------------------
/msns-search/src/main/java/com/dxg/msns/search/listener/MusicListener.java:
--------------------------------------------------------------------------------
1 | package com.dxg.msns.search.listener;
2 |
3 | import com.dxg.msns.search.service.DynamicSearchService;
4 | import com.dxg.msns.search.service.MusicSearchService;
5 | import org.springframework.amqp.core.ExchangeTypes;
6 | import org.springframework.amqp.rabbit.annotation.Exchange;
7 | import org.springframework.amqp.rabbit.annotation.Queue;
8 | import org.springframework.amqp.rabbit.annotation.QueueBinding;
9 | import org.springframework.amqp.rabbit.annotation.RabbitListener;
10 | import org.springframework.beans.factory.annotation.Autowired;
11 | import org.springframework.stereotype.Component;
12 |
13 | @Component
14 | public class MusicListener {
15 | @Autowired
16 | private MusicSearchService musicSearchService;
17 |
18 | /**处理insert和update的信息
19 | *
20 | * @param id
21 | */
22 | @RabbitListener(bindings = @QueueBinding(
23 | value = @Queue(value = "msns.music.create.index.queue",durable = "true"),
24 | exchange = @Exchange(
25 | value = "msns.music.exchange",
26 | ignoreDeclarationExceptions = "true",
27 | type = ExchangeTypes.TOPIC
28 | ),
29 | key = {"music.insert","music.update"}
30 | ))
31 | public void listenCreate(Integer id)throws Exception{
32 | if (id == null){
33 | return;
34 | }
35 | this.musicSearchService.createMusicIndex(id);
36 | }
37 |
38 | /**
39 | * 处理delete信息
40 | * @param id
41 | * @throws Exception
42 | */
43 | @RabbitListener(bindings = @QueueBinding(
44 | value = @Queue(value = "msns.music.delete.index.queue",durable = "true"),
45 | exchange = @Exchange(
46 | value = "msns.music.exchange",
47 | ignoreDeclarationExceptions = "true",
48 | type = ExchangeTypes.TOPIC
49 | ),
50 | key = {"music.delete"}
51 | ))
52 | public void listenDelete(Integer id)throws Exception{
53 | if (id == null){
54 | return;
55 | }
56 | this.musicSearchService.deleteMusicIndex(id);
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/msns-search/src/main/java/com/dxg/msns/search/pojo/SearchRequst.java:
--------------------------------------------------------------------------------
1 | package com.dxg.msns.search.pojo;
2 |
3 | import java.util.Arrays;
4 |
5 | public class SearchRequst {
6 | private String key;
7 | private Integer page;
8 | private String sortBy;
9 | private Boolean desc; //是否降序
10 | private String[] uids; //查询用户id
11 | private Integer[] ids;
12 | private Integer typeId;
13 | private Integer size;
14 | private static final Integer DEFAULT_SIZE = 5;
15 | private static final Integer DEFAULT_PAGE = 1;
16 |
17 | public String getKey() {
18 | return key;
19 | }
20 |
21 | public void setKey(String key) {
22 | this.key = key;
23 | }
24 |
25 | public Integer getTypeId() {
26 | return typeId;
27 | }
28 |
29 | public void setTypeId(Integer typeId) {
30 | this.typeId = typeId;
31 | }
32 |
33 | public Integer getPage() {
34 | if(page == null){
35 | return DEFAULT_PAGE;
36 | }
37 | // 获取页码时做一些校验,不能小于1
38 | return Math.max(DEFAULT_PAGE, page);
39 | }
40 |
41 | public void setPage(Integer page) {
42 | this.page = page;
43 | }
44 |
45 | public String getSortBy() {
46 | return sortBy;
47 | }
48 |
49 | public void setSortBy(String sortBy) {
50 | this.sortBy = sortBy;
51 | }
52 |
53 | public Boolean getDesc() {
54 | return desc;
55 | }
56 |
57 | public void setDesc(Boolean desc) {
58 | this.desc = desc;
59 | }
60 |
61 | public Integer getSize() {
62 | if (this.size == null || this.size<=0){
63 | return DEFAULT_SIZE;
64 | }
65 | return size;
66 | }
67 |
68 | public void setSize(Integer size) {
69 | this.size = size;
70 | }
71 |
72 | public String[] getUids() {
73 | return uids;
74 | }
75 |
76 | public void setUids(String[] uids) {
77 | this.uids = uids;
78 | }
79 |
80 | public Integer[] getIds() {
81 | return ids;
82 | }
83 |
84 | public void setIds(Integer[] ids) {
85 | this.ids = ids;
86 | }
87 |
88 | @Override
89 | public String toString() {
90 | return "SearchRequst{" +
91 | "key='" + key + '\'' +
92 | ", page=" + page +
93 | ", sortBy='" + sortBy + '\'' +
94 | ", desc=" + desc +
95 | ", uids=" + Arrays.toString(uids) +
96 | ", ids=" + Arrays.toString(ids) +
97 | ", typeId=" + typeId +
98 | '}';
99 | }
100 | }
101 |
--------------------------------------------------------------------------------
/msns-search/src/main/java/com/dxg/msns/search/reponsitory/DynamicsRepository.java:
--------------------------------------------------------------------------------
1 | package com.dxg.msns.search.reponsitory;
2 |
3 | import com.dxg.msns.search.pojo.Dynamics;
4 | import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
5 |
6 | public interface DynamicsRepository extends ElasticsearchRepository {
7 | }
8 |
--------------------------------------------------------------------------------
/msns-search/src/main/java/com/dxg/msns/search/reponsitory/MusicRepository.java:
--------------------------------------------------------------------------------
1 | package com.dxg.msns.search.reponsitory;
2 |
3 | import com.dxg.msns.search.pojo.Musics;
4 | import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
5 |
6 | public interface MusicRepository extends ElasticsearchRepository {
7 | }
8 |
--------------------------------------------------------------------------------
/msns-search/src/main/java/com/dxg/msns/search/service/DynamicSearchService.java:
--------------------------------------------------------------------------------
1 | package com.dxg.msns.search.service;
2 |
3 | import com.dxg.msns.common.pojo.PageResult;
4 | import com.dxg.msns.dynamic.pojo.Dynamic;
5 | import com.dxg.msns.search.pojo.Dynamics;
6 | import com.dxg.msns.search.pojo.SearchRequst;
7 |
8 | public interface DynamicSearchService {
9 | public Dynamics buildDynamics(Dynamic dynamic);
10 |
11 | /**
12 | * 根据条件查找动态
13 | * @param requst
14 | * @return
15 | */
16 | PageResult searchDynamics(SearchRequst requst);
17 |
18 | /**
19 | * 修改索引
20 | * @param id
21 | */
22 | void createDynamicIndex(Integer id);
23 |
24 | /**
25 | * 删除索引
26 | * @param id
27 | */
28 | void deleteDynamicIndex(Integer id);
29 | }
30 |
--------------------------------------------------------------------------------
/msns-search/src/main/java/com/dxg/msns/search/service/MusicSearchService.java:
--------------------------------------------------------------------------------
1 | package com.dxg.msns.search.service;
2 |
3 | import com.dxg.msns.common.pojo.PageResult;
4 | import com.dxg.msns.music.pojo.Music;
5 | import com.dxg.msns.search.pojo.Musics;
6 | import com.dxg.msns.search.pojo.SearchRequst;
7 |
8 | public interface MusicSearchService {
9 |
10 | /**
11 | * 构建Musics
12 | * @param music
13 | * @return
14 | */
15 | public Musics buildMusic(Music music);
16 |
17 | /**
18 | * 查询音乐
19 | * @param request
20 | * @return
21 | */
22 | public PageResult searchMusic(SearchRequst request);
23 |
24 | /**
25 | * 新增修改音乐
26 | * @param id
27 | */
28 | void createMusicIndex(Integer id);
29 |
30 | /**
31 | * 删除音乐索引
32 | * @param id
33 | */
34 | void deleteMusicIndex(Integer id);
35 | }
36 |
--------------------------------------------------------------------------------
/msns-search/src/main/java/com/dxg/msns/search/service/UserSearchService.java:
--------------------------------------------------------------------------------
1 | package com.dxg.msns.search.service;
2 |
3 | import com.dxg.msns.user.pojo.UserCountInfo;
4 |
5 | public interface UserSearchService {
6 | /**
7 | * 根据用户id查询用户的一些统计信息
8 | * @param uid
9 | * @return
10 | */
11 | UserCountInfo userCountInfo(String uid);
12 | }
13 |
--------------------------------------------------------------------------------
/msns-search/src/main/java/com/dxg/msns/search/service/impl/UserSearchServiceImpl.java:
--------------------------------------------------------------------------------
1 | package com.dxg.msns.search.service.impl;
2 |
3 | import com.dxg.msns.search.client.*;
4 | import com.dxg.msns.search.reponsitory.DynamicsRepository;
5 | import com.dxg.msns.search.service.UserSearchService;
6 | import com.dxg.msns.user.pojo.UserCountInfo;
7 | import org.springframework.beans.factory.annotation.Autowired;
8 | import org.springframework.stereotype.Service;
9 |
10 | @Service
11 | public class UserSearchServiceImpl implements UserSearchService {
12 | @Autowired
13 | private DynamicsClient dynamicsClient;
14 |
15 | @Autowired
16 | private DynamicTypeClient dynamicTypeClient;
17 |
18 | @Autowired
19 | private UserClient userClient;
20 |
21 | @Autowired
22 | private MusicClient musicClient;
23 |
24 | @Autowired
25 | private CommentClient commentClient;
26 |
27 | @Autowired
28 | private DynamicFavorClient dynamicFavorClient;
29 | @Autowired
30 | private MusicFavorClient musicFavorClient;
31 | @Autowired
32 | private FollowClient followClient;
33 |
34 | /**
35 | * 根据用户id查询用户的一些统计信息
36 | *
37 | * @param uid
38 | * @return
39 | */
40 | @Override
41 | public UserCountInfo userCountInfo(String uid) {
42 | UserCountInfo userCountInfo = new UserCountInfo();
43 | //用户动态收藏数
44 | userCountInfo.setCollectDynamicCount(dynamicFavorClient.queryByUid(uid));
45 | //用户音乐收藏数
46 | userCountInfo.setCollectMusicCount(musicFavorClient.queryCountByUid(uid));
47 | //用户动态数
48 | userCountInfo.setDynamicCount(dynamicsClient.queryCountByUid(uid));
49 | //用户关注数
50 | userCountInfo.setFanCount(followClient.fanCountByUid(uid));
51 | //用户粉丝数
52 | userCountInfo.setFavorCount(followClient.followCountByUid(uid));
53 | return userCountInfo;
54 | }
55 |
56 |
57 | }
58 |
--------------------------------------------------------------------------------
/msns-search/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 | server:
2 | port: 8085
3 | spring:
4 | data:
5 | elasticsearch:
6 | cluster-name: elasticsearch
7 | cluster-nodes: 127.0.0.1:9300
8 | application:
9 | name: search-service
10 | rabbitmq:
11 | username: msns
12 | password: msns
13 | virtual-host: /msns
14 | port: 5672
15 | host: 127.0.0.1
16 | main:
17 | allow-bean-definition-overriding: true #//解决Feign远程调用服务因为业务需求出现在不同在接口上使用相同的服务名而引起报错
18 | eureka:
19 | client:
20 | service-url:
21 | defaultZone: http://127.0.0.1:10086/eureka
22 | instance:
23 | lease-renewal-interval-in-seconds: 5 # 每隔5秒发送一次心跳
24 | lease-expiration-duration-in-seconds: 10 # 10秒不发送就过期
25 | logging:
26 | level:
27 | root: DEBUG
--------------------------------------------------------------------------------
/msns-search/src/test/java/com/dxg/msns/search/client/DynamicTypeClientTest.java:
--------------------------------------------------------------------------------
1 | package com.dxg.msns.search.client;
2 |
3 | import com.dxg.msns.common.pojo.PageResult;
4 | import com.dxg.msns.dynamic.pojo.Dynamic;
5 | import com.dxg.msns.search.MSNSSearchServiceApplication;
6 | import com.dxg.msns.search.pojo.Dynamics;
7 | import com.dxg.msns.search.service.DynamicSearchService;
8 | import org.junit.jupiter.api.Test;
9 | import org.junit.runner.RunWith;
10 | import org.springframework.beans.factory.annotation.Autowired;
11 | import org.springframework.boot.test.context.SpringBootTest;
12 | import org.springframework.test.context.junit4.SpringRunner;
13 |
14 | import java.util.List;
15 |
16 | @RunWith(SpringRunner.class)
17 | @SpringBootTest(classes = MSNSSearchServiceApplication.class)
18 | class DynamicTypeClientTest {
19 | @Autowired
20 | private DynamicTypeClient dynamicTypeClient;
21 |
22 | @Autowired
23 | private DynamicsClient dynamicsClient;
24 | @Autowired
25 | private DynamicSearchService dynamicSearchService;
26 | @Test
27 | public void testSelectTypeName(){
28 | List names = this.dynamicTypeClient.queryAllDynamiTypeNames();
29 | names.forEach(System.out::println);
30 | }
31 | @Test
32 | public void testBuildDynamics(){
33 | PageResult dynamicPageResult = dynamicsClient.queryDynamicsByPage("", 1, 100, null, null, true,null,null);
34 | List items = dynamicPageResult.getItems();
35 | System.out.println(items.get(0));
36 | Dynamics dynamics = dynamicSearchService.buildDynamics(items.get(0));
37 | System.out.println(dynamics);
38 | }
39 | }
--------------------------------------------------------------------------------
/msns-sms/msns-sms-service/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | msns-sms
7 | com.dxg.msns.sms
8 | 1.0-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | com.dxg.msns.sms
13 | msns-sms-service
14 |
15 |
16 |
17 | org.springframework.boot
18 | spring-boot-starter-web
19 |
20 |
21 | org.springframework.boot
22 | spring-boot-starter-amqp
23 |
24 |
25 | org.springframework.boot
26 | spring-boot-starter-mail
27 |
28 |
29 | com.fasterxml.jackson.core
30 | jackson-databind
31 | 2.9.4
32 |
33 |
34 |
35 |
36 | com.fasterxml.jackson.core
37 | jackson-core
38 | 2.9.4
39 |
40 |
41 |
42 |
43 | com.fasterxml.jackson.core
44 | jackson-annotations
45 | 2.9.4
46 |
47 |
48 |
--------------------------------------------------------------------------------
/msns-sms/msns-sms-service/src/main/java/com/dxg/msns/sms/MSNSSMSApplication.java:
--------------------------------------------------------------------------------
1 | package com.dxg.msns.sms;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class MSNSSMSApplication {
8 | public static void main(String[] args) {
9 | SpringApplication.run(MSNSSMSApplication.class,args);
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/msns-sms/msns-sms-service/src/main/java/com/dxg/msns/sms/listener/SmsEmailListener.java:
--------------------------------------------------------------------------------
1 | package com.dxg.msns.sms.listener;
2 |
3 | import com.dxg.msns.sms.service.SmsService;
4 | import org.springframework.amqp.rabbit.annotation.Exchange;
5 | import org.springframework.amqp.rabbit.annotation.Queue;
6 | import org.springframework.amqp.rabbit.annotation.QueueBinding;
7 | import org.springframework.amqp.rabbit.annotation.RabbitListener;
8 | import org.springframework.beans.factory.annotation.Autowired;
9 | import org.springframework.stereotype.Component;
10 | import org.springframework.util.StringUtils;
11 |
12 | import java.util.Map;
13 |
14 | @Component
15 | public class SmsEmailListener {
16 | @Autowired
17 | private SmsService smsService;
18 |
19 | @RabbitListener(bindings = @QueueBinding(
20 | value = @Queue(value = "msns.sms.email.queue",durable = "true"),
21 | exchange = @Exchange(value = "msns.sms.email.exchange",ignoreDeclarationExceptions = "true"),
22 | key = {"sms.verify.code"}
23 | ))
24 | public void listenSms(Map msg){
25 | if (msg == null || msg.size()<=0){
26 | return;
27 | }
28 | String email = msg.get("email");
29 | String code = msg.get("code");
30 | if (StringUtils.isEmpty(email)||StringUtils.isEmpty(code)){
31 | return;
32 | }
33 | Boolean success = smsService.sendMail(email, code);
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/msns-sms/msns-sms-service/src/main/java/com/dxg/msns/sms/listener/SmsListener.java:
--------------------------------------------------------------------------------
1 | package com.dxg.msns.sms.listener;
2 |
3 | import org.springframework.amqp.core.ExchangeTypes;
4 | import org.springframework.amqp.rabbit.annotation.Exchange;
5 | import org.springframework.amqp.rabbit.annotation.Queue;
6 | import org.springframework.amqp.rabbit.annotation.QueueBinding;
7 | import org.springframework.amqp.rabbit.annotation.RabbitListener;
8 | import org.springframework.stereotype.Component;
9 |
10 | @Component
11 | public class SmsListener {
12 | /**
13 | * 处理来自exchange为sms的信息,新建队列
14 | *
15 | * @param id
16 | */
17 | @RabbitListener(bindings = @QueueBinding(
18 | value = @Queue(value = "msns.sms.create.queue", durable = "true"),
19 | exchange = @Exchange(
20 | value = "msns.sms.exchange",
21 | ignoreDeclarationExceptions = "true",
22 | type = ExchangeTypes.TOPIC
23 | ),
24 | key = {"sms.*"}
25 | ))
26 | public void listenCreate(String id) throws Exception {
27 | if (id == null) {
28 | return;
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/msns-sms/msns-sms-service/src/main/java/com/dxg/msns/sms/service/SmsService.java:
--------------------------------------------------------------------------------
1 | package com.dxg.msns.sms.service;
2 |
3 | public interface SmsService {
4 | Boolean sendMail(String toAddress,String code);
5 | }
6 |
--------------------------------------------------------------------------------
/msns-sms/msns-sms-service/src/main/java/com/dxg/msns/sms/service/impl/SmsServiceImpl.java:
--------------------------------------------------------------------------------
1 | package com.dxg.msns.sms.service.impl;
2 |
3 | import com.dxg.msns.sms.service.SmsService;
4 | import com.dxg.msns.sms.util.SmsUtils;
5 | import org.springframework.beans.factory.annotation.Autowired;
6 | import org.springframework.mail.MailException;
7 | import org.springframework.mail.SimpleMailMessage;
8 | import org.springframework.mail.javamail.JavaMailSender;
9 | import org.springframework.stereotype.Service;
10 |
11 | @Service
12 | public class SmsServiceImpl implements SmsService {
13 | @Autowired
14 | private SmsUtils smsUtils;
15 | @Autowired
16 | JavaMailSender javaMailSender;
17 | @Override
18 | public Boolean sendMail(String toAddress, String code) {
19 | SimpleMailMessage simpleMailMessage = smsUtils.mailModule(toAddress, code);
20 | try {
21 | javaMailSender.send(simpleMailMessage);
22 | } catch (MailException e) {
23 | e.printStackTrace();
24 | return false;
25 | }
26 | return true;
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/msns-sms/msns-sms-service/src/main/java/com/dxg/msns/sms/util/SmsUtils.java:
--------------------------------------------------------------------------------
1 | package com.dxg.msns.sms.util;
2 |
3 | import org.springframework.mail.SimpleMailMessage;
4 | import org.springframework.stereotype.Component;
5 |
6 | @Component
7 | public class SmsUtils {
8 | /**
9 | * 发送邮箱模板
10 | * @param toAddress
11 | * @param code
12 | * @return
13 | */
14 | public SimpleMailMessage mailModule(String toAddress,String code){
15 | SimpleMailMessage simpleMailMessage = new SimpleMailMessage();
16 | //设置标题
17 | simpleMailMessage.setSubject("【MSNS-音乐社交网站】"+toAddress+";欢迎您注册本音乐社交网站!");
18 | //设置发送者邮箱
19 | simpleMailMessage.setFrom("18384354901@163.com");
20 | //设置发送目标邮箱
21 | simpleMailMessage.setTo(toAddress);
22 | //设置验证码
23 | simpleMailMessage.setText("【MSNS-音乐社交网站】"+toAddress+",您的验证码为:"+code+";验证码五分钟内有效!");
24 | return simpleMailMessage;
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/msns-sms/msns-sms-service/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 | server:
2 | port: 8089
3 | spring:
4 | application:
5 | name: sms-service
6 | rabbitmq:
7 | username: msns
8 | password: msns
9 | virtual-host: /msns
10 | mail:
11 | username: 18384354901@163.com
12 | password: TUJIEQFHRJMMEPPM
13 | host: smtp.163.com
14 | default-encoding: UTF-8
15 | properties:
16 | smtp:
17 | ssl:
18 | enable: true #开启ssl安全连接。
--------------------------------------------------------------------------------
/msns-sms/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | msns
7 | com.dxg.msns.parent
8 | 1.0-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | com.dxg.msns.sms
13 | msns-sms
14 | pom
15 |
16 | msns-sms-service
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/msns-upload/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | msns
7 | com.dxg.msns.parent
8 | 1.0-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | com.dxg.msns.upload
13 | msns-upload
14 |
15 |
16 |
17 | org.springframework.cloud
18 | spring-cloud-starter-netflix-eureka-client
19 |
20 |
21 | org.springframework.boot
22 | spring-boot-starter-web
23 |
24 |
25 | org.springframework.boot
26 | spring-boot-starter-test
27 |
28 |
29 | com.github.tobato
30 | fastdfs-client
31 |
32 |
33 |
34 | org
35 | jaudiotagger
36 | 2.0.3
37 |
38 |
39 | com.dxg.msns.music
40 | msns-music-interface
41 | 1.0-SNAPSHOT
42 | compile
43 |
44 |
45 | com.dxg.msns.auth
46 | msns-auth-common
47 | 1.0-SNAPSHOT
48 | compile
49 |
50 |
51 |
--------------------------------------------------------------------------------
/msns-upload/src/main/java/com/dxg/msns/upload/MSNSUploadApplication.java:
--------------------------------------------------------------------------------
1 | package com.dxg.msns.upload;
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 |
8 | @SpringBootApplication(exclude = DataSourceAutoConfiguration.class)
9 | @EnableDiscoveryClient
10 | public class MSNSUploadApplication {
11 | public static void main(String[] args) {
12 | SpringApplication.run(MSNSUploadApplication.class);
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/msns-upload/src/main/java/com/dxg/msns/upload/config/FastClientImporter.java:
--------------------------------------------------------------------------------
1 | package com.dxg.msns.upload.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 | // 解决jmx重复注册bean的问题
12 | @EnableMBeanExport(registration = RegistrationPolicy.IGNORE_EXISTING)
13 | public class FastClientImporter {
14 | }
15 |
--------------------------------------------------------------------------------
/msns-upload/src/main/java/com/dxg/msns/upload/config/MSNSCorsConfig.java:
--------------------------------------------------------------------------------
1 | package com.dxg.msns.upload.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 | @Configuration
10 | public class MSNSCorsConfig {
11 | @Bean
12 | public CorsFilter corsFilter(){
13 | //添加cors配置信息
14 | CorsConfiguration config = new CorsConfiguration();
15 | //添加允许的域,不要写“*”,否则cookie无法使用
16 | config.addAllowedOrigin("http://localhost:8080");
17 | config.addAllowedOrigin("http://127.0.0.1:8080");
18 | //是否发送cookie信息
19 | config.setAllowCredentials(true);
20 | //添加允许的请求方式
21 | config.addAllowedMethod("OPTIONS");
22 | config.addAllowedMethod("HEAD");
23 | config.addAllowedMethod("GET");
24 | config.addAllowedMethod("PUT");
25 | config.addAllowedMethod("POST");
26 | config.addAllowedMethod("DELETE");
27 | config.addAllowedMethod("PATCH");
28 | //允许的头信息
29 | config.addAllowedHeader("*");
30 |
31 | //添加映射路径,我们拦截一切请求
32 | UrlBasedCorsConfigurationSource configSource = new UrlBasedCorsConfigurationSource();
33 | configSource.registerCorsConfiguration("/**", config);
34 |
35 | //返回新的CorsFilter.
36 | return new CorsFilter(configSource);
37 |
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/msns-upload/src/main/java/com/dxg/msns/upload/controller/UploadController.java:
--------------------------------------------------------------------------------
1 | package com.dxg.msns.upload.controller;
2 |
3 | import com.dxg.msns.auth.entity.UserInfo;
4 | import com.dxg.msns.auth.utils.CookieUtils;
5 | import com.dxg.msns.auth.utils.JwtUtils;
6 | import com.dxg.msns.music.pojo.Music;
7 | import com.dxg.msns.upload.service.UploadService;
8 | import org.apache.commons.lang.StringUtils;
9 | import org.springframework.beans.factory.annotation.Autowired;
10 | import org.springframework.http.HttpHeaders;
11 | import org.springframework.http.HttpStatus;
12 | import org.springframework.http.ResponseEntity;
13 | import org.springframework.stereotype.Controller;
14 | import org.springframework.web.bind.annotation.*;
15 | import org.springframework.web.multipart.MultipartFile;
16 |
17 | import javax.servlet.http.HttpServletRequest;
18 | import javax.servlet.http.HttpServletResponse;
19 |
20 | @Controller
21 | @CrossOrigin(origins = "*",maxAge = 3600)
22 | @RequestMapping("upload")
23 | public class UploadController {
24 | @Autowired
25 | private UploadService uploadService;
26 |
27 | @PostMapping("image")
28 | public ResponseEntity uploadImage( @RequestParam("file") MultipartFile[] file, HttpServletRequest request,HttpServletResponse response){
29 | String url = this.uploadService.upload(file);
30 | if (StringUtils.isBlank(url)) {
31 | return ResponseEntity.badRequest().build();
32 | }
33 | // CookieUtils.setCookie(request,response,"MSNS_TOKEN",token,30,null,true);
34 | return ResponseEntity.ok(url);
35 | }
36 |
37 | @PostMapping("music")
38 | public ResponseEntity uploadMusic(@RequestParam("file") MultipartFile file, HttpServletRequest request,HttpServletResponse response){
39 | Music music = this.uploadService.uploadMusic(file);
40 | if (music==null) {
41 | return ResponseEntity.badRequest().build();
42 | }
43 | // CookieUtils.setCookie(request,response,"MSNS_TOKEN",token,30,null,true);
44 |
45 | return ResponseEntity.ok(music);
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/msns-upload/src/main/java/com/dxg/msns/upload/service/UploadService.java:
--------------------------------------------------------------------------------
1 | package com.dxg.msns.upload.service;
2 |
3 | import com.dxg.msns.music.pojo.Music;
4 | import org.springframework.web.multipart.MultipartFile;
5 |
6 | public interface UploadService {
7 | String upload(MultipartFile[] file);
8 |
9 | Music uploadMusic(MultipartFile file);
10 | }
11 |
--------------------------------------------------------------------------------
/msns-upload/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 | server:
2 | port: 10000
3 | spring:
4 | application:
5 | name: upload-service
6 | servlet:
7 | multipart:
8 | max-file-size: 100MB
9 | max-request-size: 100MB
10 | mvc:
11 | static-path-pattern: /file/**
12 | resources: #配置静态资源拦截方式和静态资源路径
13 | static-locations: classpath:/META-INF/resources/,classpath:/resources/,classpath:/static/,classpath:/public/,file:${filePath}
14 | eureka:
15 | client:
16 | service-url:
17 | defaultZone: http://127.0.0.1:10086/eureka
18 | instance:
19 | lease-renewal-interval-in-seconds: 5 # 每隔5秒发送一次心跳
20 | lease-expiration-duration-in-seconds: 10 # 10秒不发送就过期
21 | #配置本地资源路径,必须以/结尾
22 | filePath: d:/msns/
23 | #fdfs:
24 | # so-timeout: 1501 # 超时时间
25 | # connect-timeout: 601 # 连接超时时间
26 | # thumb-image: # 缩略图
27 | # width: 60
28 | # height: 60
29 | # tracker-list: # tracker地址:虚拟机服务器地址+端口(默认是22122)
30 | # - 192.168.12.18:22122
31 | logging:
32 | level:
33 | root: DEBUG
34 |
--------------------------------------------------------------------------------
/msns-user/msns-user-interface/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | msns-user
7 | com.dxg.msns.user
8 | 1.0-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | msns-user-interface
13 |
14 |
15 | javax.persistence
16 | persistence-api
17 | 1.0
18 |
19 |
20 | com.fasterxml.jackson.core
21 | jackson-annotations
22 |
23 |
24 | org.springframework
25 | spring-web
26 |
27 |
28 | org.hibernate.validator
29 | hibernate-validator
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/msns-user/msns-user-interface/src/main/java/com/dxg/msns/user/api/FollowApi.java:
--------------------------------------------------------------------------------
1 | package com.dxg.msns.user.api;
2 |
3 | import org.springframework.http.ResponseEntity;
4 | import org.springframework.web.bind.annotation.PathVariable;
5 | import org.springframework.web.bind.annotation.RequestMapping;
6 |
7 | @RequestMapping("follow")
8 | public interface FollowApi {
9 | /**
10 | * 根据用户id查询该用户关注别人的数
11 | *
12 | * @param uid
13 | * @return
14 | */
15 | @RequestMapping("followCountByUid/{uid}")
16 | public Integer followCountByUid(@PathVariable("uid") String uid);
17 |
18 | /**
19 | * 根据用户id查询该用户粉丝数
20 | *
21 | * @param uid
22 | * @return
23 | */
24 | @RequestMapping("fanCountByUid/{uid}")
25 | public Integer fanCountByUid(@PathVariable("uid") String uid);
26 |
27 | /**
28 | * 根据用户id查询该用户关注用户的uid
29 | *
30 | * @param uid
31 | * @return
32 | */
33 | @RequestMapping("queryFollowerIdsByUid/{uid}")
34 | public String[] queryFollowerIdByUid(@PathVariable("uid") String uid);
35 |
36 | /**
37 | * 根据用户id查询该用户粉丝的uid
38 | *
39 | * @param uid
40 | * @return
41 | */
42 | @RequestMapping("queryFanIdsByUid/{uid}")
43 | public String[] queryFanIdByUid(@PathVariable("uid") String uid);
44 | }
45 |
--------------------------------------------------------------------------------
/msns-user/msns-user-interface/src/main/java/com/dxg/msns/user/api/UserApi.java:
--------------------------------------------------------------------------------
1 | package com.dxg.msns.user.api;
2 |
3 | import com.dxg.msns.user.pojo.User;
4 | import org.springframework.http.ResponseEntity;
5 | import org.springframework.web.bind.annotation.GetMapping;
6 | import org.springframework.web.bind.annotation.PathVariable;
7 | import org.springframework.web.bind.annotation.RequestMapping;
8 | import org.springframework.web.bind.annotation.RequestParam;
9 |
10 | public interface UserApi {
11 | /**
12 | * 根据id查找用户头像和昵称
13 | * @param uid
14 | * @return
15 | */
16 | @RequestMapping("queryNameAvatarById/{id}")
17 | public User queryNameAvatarById(@PathVariable("id") String uid);
18 | /**
19 | * 登录,根据用户名密码查询用户
20 | * @return
21 | */
22 | @GetMapping("login")
23 | public User login(@RequestParam("uname")String uname, @RequestParam("upassword")String upassword);
24 |
25 | /**
26 | * 根据id查询用户
27 | * @param id
28 | * @return
29 | */
30 | @RequestMapping("queryById/{id}")
31 | public User queryById(@PathVariable("id")Integer id);
32 |
33 | /**
34 | * 根据id修改密码
35 | * @param id
36 | * @return
37 | */
38 | @GetMapping("changePwdById")
39 | public Void changePwdById(@RequestParam("id")Integer id,
40 | @RequestParam("upassword") String upassword,
41 | @RequestParam("newPassword") String newPassword);
42 | }
43 |
--------------------------------------------------------------------------------
/msns-user/msns-user-interface/src/main/java/com/dxg/msns/user/pojo/Follow.java:
--------------------------------------------------------------------------------
1 | package com.dxg.msns.user.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.util.Date;
8 | @Table(name = "follow")
9 | public class Follow {
10 | @Id
11 | @GeneratedValue(strategy = GenerationType.IDENTITY)
12 | private Integer id;
13 | private String followersId;
14 | private String befollowersId;
15 | private Date followerDate;
16 |
17 | public Integer getId() {
18 | return id;
19 | }
20 |
21 | public void setId(Integer id) {
22 | this.id = id;
23 | }
24 |
25 | public String getFollowersId() {
26 | return followersId;
27 | }
28 |
29 | public void setFollowersId(String followersId) {
30 | this.followersId = followersId;
31 | }
32 |
33 | public String getBefollowersId() {
34 | return befollowersId;
35 | }
36 |
37 | public void setBefollowersId(String befollowersId) {
38 | this.befollowersId = befollowersId;
39 | }
40 |
41 | public Date getFollowerDate() {
42 | return followerDate;
43 | }
44 |
45 | public void setFollowerDate(Date followerDate) {
46 | this.followerDate = followerDate;
47 | }
48 |
49 | @Override
50 | public String toString() {
51 | return "Follow{" +
52 | "id=" + id +
53 | ", followersId='" + followersId + '\'' +
54 | ", befollowersId='" + befollowersId + '\'' +
55 | ", followerDate=" + followerDate +
56 | '}';
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/msns-user/msns-user-interface/src/main/java/com/dxg/msns/user/pojo/UserCountInfo.java:
--------------------------------------------------------------------------------
1 | package com.dxg.msns.user.pojo;
2 |
3 | public class UserCountInfo {
4 | private Integer favorCount; //关注数
5 | private Integer fanCount; //粉丝数
6 | private Integer dynamicCount; //动态数
7 | private Integer collectDynamicCount; //收藏动态数
8 | private Integer collectMusicCount; //收藏音乐数
9 |
10 | public Integer getFavorCount() {
11 | return favorCount;
12 | }
13 |
14 | public void setFavorCount(Integer favorCount) {
15 | this.favorCount = favorCount;
16 | }
17 |
18 | public Integer getFanCount() {
19 | return fanCount;
20 | }
21 |
22 | public void setFanCount(Integer fanCount) {
23 | this.fanCount = fanCount;
24 | }
25 |
26 | public Integer getDynamicCount() {
27 | return dynamicCount;
28 | }
29 |
30 | public void setDynamicCount(Integer dynamicCount) {
31 | this.dynamicCount = dynamicCount;
32 | }
33 |
34 | public Integer getCollectDynamicCount() {
35 | return collectDynamicCount;
36 | }
37 |
38 | public void setCollectDynamicCount(Integer collectDynamicCount) {
39 | this.collectDynamicCount = collectDynamicCount;
40 | }
41 |
42 | public Integer getCollectMusicCount() {
43 | return collectMusicCount;
44 | }
45 |
46 | public void setCollectMusicCount(Integer collectMusicCount) {
47 | this.collectMusicCount = collectMusicCount;
48 | }
49 |
50 | @Override
51 | public String toString() {
52 | return "UserCountInfo{" +
53 | "favorCount=" + favorCount +
54 | ", fanCount=" + fanCount +
55 | ", dynamicCount=" + dynamicCount +
56 | ", collectDynamicCount=" + collectDynamicCount +
57 | ", collectMusicCount=" + collectMusicCount +
58 | '}';
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/msns-user/msns-user-service/src/main/java/com/dxg/msns/user/MSNSUserServiceApplication.java:
--------------------------------------------------------------------------------
1 | package com.dxg.msns.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 | @SpringBootApplication
9 | @EnableDiscoveryClient
10 | @MapperScan("com.dxg.msns.user.mapper")
11 | public class MSNSUserServiceApplication {
12 | public static void main(String[] args) {
13 | SpringApplication.run(MSNSUserServiceApplication.class);
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/msns-user/msns-user-service/src/main/java/com/dxg/msns/user/mapper/FollowMapper.java:
--------------------------------------------------------------------------------
1 | package com.dxg.msns.user.mapper;
2 |
3 | import com.dxg.msns.user.pojo.Follow;
4 | import tk.mybatis.mapper.common.Mapper;
5 |
6 | public interface FollowMapper extends Mapper {
7 |
8 | }
9 |
--------------------------------------------------------------------------------
/msns-user/msns-user-service/src/main/java/com/dxg/msns/user/mapper/UserMapper.java:
--------------------------------------------------------------------------------
1 | package com.dxg.msns.user.mapper;
2 |
3 | import com.dxg.msns.user.pojo.User;
4 | import org.apache.ibatis.annotations.*;
5 | import tk.mybatis.mapper.common.Mapper;
6 |
7 | public interface UserMapper extends Mapper {
8 | @Select("select uid,uname,avatar_url from user where uid = #{uid}")
9 | @Results(id = "userMap",
10 | value = {
11 | @Result(id = true,column = "uid",property = "uid"),
12 | @Result(column = "uname",property = "uname"),
13 | @Result(column = "avatar_url",property = "avatarUrl"),
14 | })
15 | User queryNameAvatarById(@Param("uid") String uid);
16 |
17 | /**
18 | * 修改密码
19 | * @param id
20 | * @param newPwd
21 | * @param salt
22 | */
23 | @Update("update user set upassword = #{newPwd} , salt = #{salt} where id=#{id}")
24 | void changePwdById(@Param("id") Integer id, @Param("newPwd") String newPwd,@Param("salt") String salt);
25 |
26 | /**
27 | * 修改头像
28 | * @param id
29 | * @param avatarUrl
30 | */
31 | @Update("update user set avatar_url = #{avatarUrl} where id = #{id}")
32 | @ResultMap("userMap")
33 | void changeAvatar(@Param("id")Integer id,@Param("avatarUrl") String avatarUrl);
34 | }
35 |
--------------------------------------------------------------------------------
/msns-user/msns-user-service/src/main/java/com/dxg/msns/user/service/FollowService.java:
--------------------------------------------------------------------------------
1 | package com.dxg.msns.user.service;
2 |
3 | import com.dxg.msns.user.pojo.Follow;
4 |
5 | public interface FollowService {
6 | /**
7 | * 根据用户id查询该用户的关注数
8 | * @param uid
9 | * @return
10 | */
11 | Integer followCountByUid(String uid);
12 |
13 | /**
14 | * 根据用户id查询该用户粉丝数
15 | * @param uid
16 | * @return
17 | */
18 | Integer fanCountByUid(String uid);
19 |
20 | /**
21 | *根据用户id查询该用户粉丝的uid
22 | * @param uid
23 | * @return
24 | */
25 | String[] queryFanIdByUid(String uid);
26 |
27 | /**
28 | * 根据用户id查询该用户关注用户的uid
29 | * @param uid
30 | * @return
31 | */
32 | String[] queryFollowerIdByUid(String uid);
33 | /**
34 | * 根据用户id查询该用户和粉丝是否互相关注
35 | * @param uids
36 | * @return
37 | */
38 | String[] queryIsMutual(String[] uids,String currentUid);
39 | /**
40 | * 删除关注信息
41 | * @param followerId
42 | * @param beFollowerId
43 | * @return
44 | */
45 | void deleteFollow(String followerId, String beFollowerId);
46 |
47 | /**
48 | * 新增关注
49 | * @param follow
50 | */
51 | void addFollow(Follow follow);
52 | }
53 |
--------------------------------------------------------------------------------
/msns-user/msns-user-service/src/main/java/com/dxg/msns/user/service/UserService.java:
--------------------------------------------------------------------------------
1 | package com.dxg.msns.user.service;
2 |
3 | import com.dxg.msns.common.pojo.PageResult;
4 | import com.dxg.msns.user.pojo.User;
5 | import com.fasterxml.jackson.databind.util.ObjectBuffer;
6 | import org.springframework.web.bind.annotation.RequestParam;
7 |
8 | import java.util.Map;
9 |
10 | public interface UserService {
11 | /**
12 | * 分页查询用户
13 | * @param key
14 | * @param page
15 | * @param rows
16 | * @param sortBy
17 | * @param desc
18 | * @param isAll
19 | * @return
20 | */
21 | PageResult queryUsersByPage(String key, Integer page, Integer rows, String[] sortBy, Boolean[] desc, Boolean isAll,String[] uids);
22 |
23 | /**
24 | * 根据用户名查询用户
25 | * @param user
26 | * @return
27 | */
28 | boolean findUserByName(User user);
29 |
30 | /**
31 | * 新增用户
32 | * @param user
33 | */
34 | void saveUser(User user);
35 |
36 | /**
37 | * 修改用户
38 | * @param user
39 | */
40 | void updateUser(User user);
41 |
42 | /**
43 | * 删除用户
44 | * @param user
45 | */
46 | void deleteUser(User user);
47 |
48 | /**
49 | * 查询用户数据是否可用
50 | * @param data
51 | * @param type
52 | * @return
53 | */
54 | Boolean checkUserData(String data, Integer type);
55 |
56 | /**
57 | * 根据id查找用户
58 | * @param uid
59 | * @return
60 | */
61 | User queryNameAvatarById(String uid);
62 |
63 | /**
64 | * 发送验证码
65 | * @param email
66 | * @return
67 | */
68 | Boolean sendVerifyCode(String email);
69 |
70 | /**
71 | * 注册
72 | * @param user
73 | * @param code
74 | * @return
75 | */
76 | Map register(User user, String code);
77 |
78 | /**
79 | * 根据用户名和密码查询用户
80 | * @param uname
81 | * @param upassword
82 | * @return
83 | */
84 | User queryUser(String uname, String upassword);
85 |
86 |
87 | /**
88 | * 根据id查找用户
89 | * @param id
90 | * @return
91 | */
92 | User queryById(Integer id);
93 |
94 | /**
95 | * 修改密码
96 | * @param id
97 | * @param newPwd
98 | */
99 | void changePwdById(Integer id, String newPwd);
100 |
101 | /**
102 | * 修改头像
103 | * @param id
104 | * @param avatarUrl
105 | */
106 | void changeAvatar(Integer id, String avatarUrl);
107 | }
108 |
--------------------------------------------------------------------------------
/msns-user/msns-user-service/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 | server:
2 | port: 8083
3 | spring:
4 | application:
5 | name: user-service
6 | datasource:
7 | url: jdbc:mysql:///msns?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC
8 | username: root
9 | password: root
10 | driver-class-name: com.mysql.jdbc.Driver
11 | hikari:
12 | max-lifetime: 28830000 # 一个连接的生命时长(毫秒),超时而且没被使用则被释放(retired),缺省:30分钟,建议设置比数据库超时时长少30秒,参考MySQL wait_timeout参数(show variables like '%timeout%';)
13 | maximum-pool-size: 9 # 连接池中允许的最大连接数。缺省值:10;推荐的公式:((core_count * 2) + effective_spindle_count)
14 | rabbitmq:
15 | username: msns
16 | password: msns
17 | virtual-host: /msns
18 | eureka:
19 | client:
20 | service-url:
21 | defaultZone: http://127.0.0.1:10086/eureka
22 | instance:
23 | lease-expiration-duration-in-seconds: 10 #10秒不发送就过期
24 | lease-renewal-interval-in-seconds: 5 #5秒发送一次心跳
25 | logging:
26 | level:
27 | root: DEBUG
--------------------------------------------------------------------------------
/msns-user/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | msns
7 | com.dxg.msns.parent
8 | 1.0-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | com.dxg.msns.user
13 | msns-user
14 | pom
15 |
16 | msns-user-interface
17 | msns-user-service
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------