├── pic ├── er.png ├── kk.png ├── kk.vsdx ├── shw.vsdx ├── jiagou.png ├── shw_msg.png ├── shw消息系统.vsdx ├── yanzheng.png └── shw_login.png ├── shw-eureka ├── .mvn │ └── wrapper │ │ ├── maven-wrapper.jar │ │ └── maven-wrapper.properties ├── src │ ├── main │ │ ├── resources │ │ │ └── application.properties │ │ └── java │ │ │ └── top │ │ │ └── itning │ │ │ └── server │ │ │ └── shweureka │ │ │ └── ShwEurekaApplication.java │ └── test │ │ └── java │ │ └── top │ │ └── itning │ │ └── server │ │ └── shweureka │ │ └── ShwEurekaApplicationTests.java ├── .gitignore └── pom.xml ├── shw-file ├── .mvn │ └── wrapper │ │ ├── maven-wrapper.jar │ │ └── maven-wrapper.properties ├── src │ ├── main │ │ ├── resources │ │ │ └── application.properties │ │ └── java │ │ │ └── top │ │ │ └── itning │ │ │ └── server │ │ │ └── shwfile │ │ │ ├── ShwFileApplication.java │ │ │ ├── stream │ │ │ ├── UploadMessage.java │ │ │ └── UploadStreamReceiver.java │ │ │ ├── config │ │ │ └── BeansConfig.java │ │ │ ├── client │ │ │ ├── WorkClient.java │ │ │ ├── SecurityClient.java │ │ │ ├── UploadClient.java │ │ │ └── entity │ │ │ │ ├── Student.java │ │ │ │ └── Work.java │ │ │ ├── persistence │ │ │ └── FilePersistence.java │ │ │ ├── service │ │ │ └── FileService.java │ │ │ ├── pojo │ │ │ └── FileUploadMetaData.java │ │ │ └── controller │ │ │ └── FileController.java │ └── test │ │ └── java │ │ └── top │ │ └── itning │ │ └── server │ │ └── shwfile │ │ ├── ShwFileApplicationTests.java │ │ └── client │ │ └── UploadClientTest.java └── .gitignore ├── shw-group ├── .mvn │ └── wrapper │ │ ├── maven-wrapper.jar │ │ └── maven-wrapper.properties ├── src │ ├── main │ │ ├── resources │ │ │ └── application.properties │ │ └── java │ │ │ └── top │ │ │ └── itning │ │ │ └── server │ │ │ └── shwgroup │ │ │ ├── repository │ │ │ └── GroupRepository.java │ │ │ ├── ShwGroupApplication.java │ │ │ ├── stream │ │ │ └── DelGroupMessage.java │ │ │ ├── exception │ │ │ ├── JsonHttpMessageWriter.java │ │ │ ├── GlobalErrorAttributes.java │ │ │ └── GlobalErrorWebExceptionHandler.java │ │ │ ├── service │ │ │ └── GroupService.java │ │ │ ├── router │ │ │ └── GroupRouters.java │ │ │ └── handler │ │ │ └── GroupHandler.java │ └── test │ │ └── java │ │ └── top │ │ └── itning │ │ └── server │ │ └── shwgroup │ │ ├── ShwGroupApplicationTests.java │ │ ├── util │ │ └── ReactiveMongoHelperTest.java │ │ ├── repository │ │ └── GroupRepositoryTest.java │ │ └── service │ │ └── GroupServiceTest.java └── .gitignore ├── shw-notice ├── .mvn │ └── wrapper │ │ ├── maven-wrapper.jar │ │ └── maven-wrapper.properties ├── src │ ├── main │ │ ├── resources │ │ │ └── application.properties │ │ └── java │ │ │ └── top │ │ │ └── itning │ │ │ └── server │ │ │ └── shwnotice │ │ │ ├── repository │ │ │ └── NoticeRepository.java │ │ │ ├── service │ │ │ ├── NoticeService.java │ │ │ └── impl │ │ │ │ └── NoticeServiceImpl.java │ │ │ ├── ShwNoticeApplication.java │ │ │ ├── router │ │ │ └── NoticeRouters.java │ │ │ ├── handler │ │ │ └── NoticeHandler.java │ │ │ └── exception │ │ │ ├── JsonHttpMessageWriter.java │ │ │ ├── GlobalErrorAttributes.java │ │ │ └── GlobalErrorWebExceptionHandler.java │ └── test │ │ └── java │ │ └── top │ │ └── itning │ │ └── server │ │ └── shwnotice │ │ └── ShwNoticeApplicationTests.java └── .gitignore ├── shw-upload ├── .mvn │ └── wrapper │ │ ├── maven-wrapper.jar │ │ └── maven-wrapper.properties ├── src │ ├── main │ │ ├── resources │ │ │ └── application.properties │ │ └── java │ │ │ └── top │ │ │ └── itning │ │ │ └── server │ │ │ └── shwupload │ │ │ ├── repository │ │ │ └── UploadRepository.java │ │ │ ├── stream │ │ │ ├── UploadMessage.java │ │ │ ├── StudentGroupMessage.java │ │ │ ├── DelWorkMessage.java │ │ │ └── StreamReceiver.java │ │ │ ├── ShwUploadApplication.java │ │ │ ├── client │ │ │ └── WorkClient.java │ │ │ ├── handler │ │ │ └── UploadHandler.java │ │ │ ├── service │ │ │ └── UploadService.java │ │ │ ├── exception │ │ │ ├── JsonHttpMessageWriter.java │ │ │ ├── GlobalErrorAttributes.java │ │ │ └── GlobalErrorWebExceptionHandler.java │ │ │ └── router │ │ │ └── UploadRouters.java │ └── test │ │ └── java │ │ └── top │ │ └── itning │ │ └── server │ │ └── shwupload │ │ ├── ShwUploadApplicationTests.java │ │ ├── repository │ │ └── UploadRepositoryTest.java │ │ └── service │ │ └── UploadServiceTest.java └── .gitignore ├── shw-work ├── .mvn │ └── wrapper │ │ ├── maven-wrapper.jar │ │ └── maven-wrapper.properties ├── src │ ├── main │ │ ├── resources │ │ │ └── application.properties │ │ └── java │ │ │ └── top │ │ │ └── itning │ │ │ └── server │ │ │ └── shwwork │ │ │ ├── repository │ │ │ └── WorkRepository.java │ │ │ ├── config │ │ │ ├── BeansConfig.java │ │ │ └── ModelMapperConfig.java │ │ │ ├── ShwWorkApplication.java │ │ │ ├── stream │ │ │ ├── DelWorkMessage.java │ │ │ ├── DelGroupMessage.java │ │ │ └── StreamReceiver.java │ │ │ ├── util │ │ │ ├── Tuple.java │ │ │ └── Tuple3.java │ │ │ ├── client │ │ │ ├── SecurityClient.java │ │ │ ├── UploadClient.java │ │ │ ├── entity │ │ │ │ ├── Student.java │ │ │ │ ├── StudentGroup.java │ │ │ │ └── Group.java │ │ │ ├── StudentGroupClient.java │ │ │ └── GroupClient.java │ │ │ ├── dto │ │ │ ├── WorkDetailsDTO.java │ │ │ └── WorkDTO.java │ │ │ ├── exception │ │ │ ├── JsonHttpMessageWriter.java │ │ │ ├── GlobalErrorAttributes.java │ │ │ └── GlobalErrorWebExceptionHandler.java │ │ │ └── router │ │ │ └── WorkRouters.java │ └── test │ │ └── java │ │ └── top │ │ └── itning │ │ └── server │ │ └── shwwork │ │ ├── ShwWorkApplicationTests.java │ │ ├── TestJava.java │ │ ├── client │ │ └── UploadClientTest.java │ │ ├── repository │ │ └── WorkRepositoryTest.java │ │ └── service │ │ └── WorkServiceTest.java └── .gitignore ├── shw-gateway ├── .mvn │ └── wrapper │ │ ├── maven-wrapper.jar │ │ └── maven-wrapper.properties ├── src │ ├── main │ │ ├── resources │ │ │ └── application.properties │ │ └── java │ │ │ └── top │ │ │ └── itning │ │ │ └── server │ │ │ └── shwgateway │ │ │ ├── ShwGatewayApplication.java │ │ │ ├── config │ │ │ └── CustomWebMvcConfig.java │ │ │ ├── handler │ │ │ └── ErrorHandler.java │ │ │ ├── filter │ │ │ ├── ErrorFilter.java │ │ │ └── CorsFilter.java │ │ │ └── util │ │ │ └── JwtUtils.java │ └── test │ │ └── java │ │ └── top │ │ └── itning │ │ └── server │ │ └── shwgateway │ │ ├── ShwGatewayApplicationTests.java │ │ └── util │ │ └── JwtUtilsTest.java ├── .gitignore └── pom.xml ├── shw-security ├── .mvn │ └── wrapper │ │ ├── maven-wrapper.jar │ │ └── maven-wrapper.properties ├── src │ ├── main │ │ ├── resources │ │ │ └── application.properties │ │ └── java │ │ │ └── top │ │ │ └── itning │ │ │ └── server │ │ │ └── shwsecurity │ │ │ ├── repository │ │ │ └── StudentRepository.java │ │ │ ├── ShwSecurityApplication.java │ │ │ ├── config │ │ │ └── BeansConfig.java │ │ │ ├── entity │ │ │ └── Student.java │ │ │ ├── router │ │ │ └── LoginRouters.java │ │ │ ├── exception │ │ │ ├── JsonHttpMessageWriter.java │ │ │ ├── GlobalErrorAttributes.java │ │ │ └── GlobalErrorWebExceptionHandler.java │ │ │ └── util │ │ │ └── JwtUtils.java │ └── test │ │ └── java │ │ └── top │ │ └── itning │ │ └── server │ │ └── shwsecurity │ │ └── ShwSecurityApplicationTests.java └── .gitignore ├── shw-studentgroup ├── .mvn │ └── wrapper │ │ ├── maven-wrapper.jar │ │ └── maven-wrapper.properties ├── src │ ├── main │ │ ├── resources │ │ │ └── application.properties │ │ └── java │ │ │ └── top │ │ │ └── itning │ │ │ └── server │ │ │ └── shwstudentgroup │ │ │ ├── repository │ │ │ └── StudentGroupRepository.java │ │ │ ├── config │ │ │ └── BeansConfig.java │ │ │ ├── ShwStudentgroupApplication.java │ │ │ ├── stream │ │ │ ├── StudentGroupMessage.java │ │ │ ├── DelGroupMessage.java │ │ │ └── StreamReceiver.java │ │ │ ├── util │ │ │ └── Tuple.java │ │ │ ├── client │ │ │ ├── GroupClient.java │ │ │ └── entrty │ │ │ │ └── Group.java │ │ │ ├── exception │ │ │ ├── JsonHttpMessageWriter.java │ │ │ ├── GlobalErrorAttributes.java │ │ │ └── GlobalErrorWebExceptionHandler.java │ │ │ ├── service │ │ │ └── StudentGroupService.java │ │ │ ├── handler │ │ │ └── StudentGroupHandler.java │ │ │ ├── dto │ │ │ └── StudentGroupDTO.java │ │ │ ├── entity │ │ │ └── StudentGroup.java │ │ │ └── router │ │ │ └── StudentGroupRouters.java │ └── test │ │ └── java │ │ └── top │ │ └── itning │ │ └── server │ │ └── shwstudentgroup │ │ ├── ShwStudentgroupApplicationTests.java │ │ ├── repository │ │ └── StudentGroupRepositoryTest.java │ │ └── service │ │ └── StudentGroupServiceTest.java └── .gitignore ├── shw-hystrix-dashboard ├── .mvn │ └── wrapper │ │ ├── maven-wrapper.jar │ │ └── maven-wrapper.properties ├── src │ ├── main │ │ ├── resources │ │ │ └── application.properties │ │ └── java │ │ │ └── top │ │ │ └── itning │ │ │ └── server │ │ │ └── shwhystrixdashboard │ │ │ └── ShwHystrixDashboardApplication.java │ └── test │ │ └── java │ │ └── top │ │ └── itning │ │ └── server │ │ └── shwhystrixdashboard │ │ └── ShwHystrixDashboardApplicationTests.java ├── .gitignore └── pom.xml ├── .gitignore └── shw-common └── src └── main └── java └── top └── itning └── server └── common ├── exception ├── FileException.java ├── CasException.java ├── RoleException.java ├── NullFiledException.java ├── PermissionsException.java ├── NoSuchFiledValueException.java └── BaseException.java └── util └── Preconditions.java /pic/er.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itning/shw_server/v2/pic/er.png -------------------------------------------------------------------------------- /pic/kk.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itning/shw_server/v2/pic/kk.png -------------------------------------------------------------------------------- /pic/kk.vsdx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itning/shw_server/v2/pic/kk.vsdx -------------------------------------------------------------------------------- /pic/shw.vsdx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itning/shw_server/v2/pic/shw.vsdx -------------------------------------------------------------------------------- /pic/jiagou.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itning/shw_server/v2/pic/jiagou.png -------------------------------------------------------------------------------- /pic/shw_msg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itning/shw_server/v2/pic/shw_msg.png -------------------------------------------------------------------------------- /pic/shw消息系统.vsdx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itning/shw_server/v2/pic/shw消息系统.vsdx -------------------------------------------------------------------------------- /pic/yanzheng.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itning/shw_server/v2/pic/yanzheng.png -------------------------------------------------------------------------------- /pic/shw_login.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itning/shw_server/v2/pic/shw_login.png -------------------------------------------------------------------------------- /shw-eureka/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itning/shw_server/v2/shw-eureka/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /shw-file/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itning/shw_server/v2/shw-file/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /shw-group/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itning/shw_server/v2/shw-group/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /shw-notice/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itning/shw_server/v2/shw-notice/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /shw-upload/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itning/shw_server/v2/shw-upload/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /shw-work/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itning/shw_server/v2/shw-work/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /shw-gateway/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itning/shw_server/v2/shw-gateway/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /shw-security/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itning/shw_server/v2/shw-security/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /shw-studentgroup/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itning/shw_server/v2/shw-studentgroup/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /shw-file/src/main/resources/application.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itning/shw_server/v2/shw-file/src/main/resources/application.properties -------------------------------------------------------------------------------- /shw-group/src/main/resources/application.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itning/shw_server/v2/shw-group/src/main/resources/application.properties -------------------------------------------------------------------------------- /shw-work/src/main/resources/application.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itning/shw_server/v2/shw-work/src/main/resources/application.properties -------------------------------------------------------------------------------- /shw-eureka/src/main/resources/application.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itning/shw_server/v2/shw-eureka/src/main/resources/application.properties -------------------------------------------------------------------------------- /shw-gateway/src/main/resources/application.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itning/shw_server/v2/shw-gateway/src/main/resources/application.properties -------------------------------------------------------------------------------- /shw-hystrix-dashboard/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itning/shw_server/v2/shw-hystrix-dashboard/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /shw-notice/src/main/resources/application.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itning/shw_server/v2/shw-notice/src/main/resources/application.properties -------------------------------------------------------------------------------- /shw-upload/src/main/resources/application.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itning/shw_server/v2/shw-upload/src/main/resources/application.properties -------------------------------------------------------------------------------- /shw-security/src/main/resources/application.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itning/shw_server/v2/shw-security/src/main/resources/application.properties -------------------------------------------------------------------------------- /shw-eureka/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.0/apache-maven-3.6.0-bin.zip 2 | -------------------------------------------------------------------------------- /shw-file/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.0/apache-maven-3.6.0-bin.zip 2 | -------------------------------------------------------------------------------- /shw-group/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.0/apache-maven-3.6.0-bin.zip 2 | -------------------------------------------------------------------------------- /shw-notice/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.0/apache-maven-3.6.0-bin.zip 2 | -------------------------------------------------------------------------------- /shw-studentgroup/src/main/resources/application.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itning/shw_server/v2/shw-studentgroup/src/main/resources/application.properties -------------------------------------------------------------------------------- /shw-upload/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.0/apache-maven-3.6.0-bin.zip 2 | -------------------------------------------------------------------------------- /shw-work/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.0/apache-maven-3.6.0-bin.zip 2 | -------------------------------------------------------------------------------- /shw-gateway/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.0/apache-maven-3.6.0-bin.zip 2 | -------------------------------------------------------------------------------- /shw-security/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.0/apache-maven-3.6.0-bin.zip 2 | -------------------------------------------------------------------------------- /shw-hystrix-dashboard/src/main/resources/application.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itning/shw_server/v2/shw-hystrix-dashboard/src/main/resources/application.properties -------------------------------------------------------------------------------- /shw-studentgroup/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.0/apache-maven-3.6.0-bin.zip 2 | -------------------------------------------------------------------------------- /shw-hystrix-dashboard/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.0/apache-maven-3.6.0-bin.zip 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | .sts4-cache 12 | 13 | ### IntelliJ IDEA ### 14 | .idea 15 | *.iws 16 | *.iml 17 | *.ipr 18 | 19 | ### NetBeans ### 20 | /nbproject/private/ 21 | /build/ 22 | /nbbuild/ 23 | /dist/ 24 | /nbdist/ 25 | /.nb-gradle/ -------------------------------------------------------------------------------- /shw-common/src/main/java/top/itning/server/common/exception/FileException.java: -------------------------------------------------------------------------------- 1 | package top.itning.server.common.exception; 2 | 3 | import org.springframework.http.HttpStatus; 4 | 5 | /** 6 | * 文件异常 7 | * 8 | * @author itning 9 | */ 10 | public class FileException extends BaseException { 11 | public FileException(String msg, HttpStatus code) { 12 | super(msg, code); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /shw-common/src/main/java/top/itning/server/common/exception/CasException.java: -------------------------------------------------------------------------------- 1 | package top.itning.server.common.exception; 2 | 3 | import org.springframework.http.HttpStatus; 4 | 5 | /** 6 | * Cas Exception 7 | * 8 | * @author itning 9 | */ 10 | public class CasException extends BaseException { 11 | public CasException(String msg, HttpStatus code) { 12 | super(msg, code); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /shw-common/src/main/java/top/itning/server/common/exception/RoleException.java: -------------------------------------------------------------------------------- 1 | package top.itning.server.common.exception; 2 | 3 | import org.springframework.http.HttpStatus; 4 | 5 | /** 6 | * 用户角色异常 7 | * 8 | * @author itning 9 | */ 10 | public class RoleException extends BaseException { 11 | public RoleException(String msg, HttpStatus code) { 12 | super(msg, code); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /shw-common/src/main/java/top/itning/server/common/exception/NullFiledException.java: -------------------------------------------------------------------------------- 1 | package top.itning.server.common.exception; 2 | 3 | import org.springframework.http.HttpStatus; 4 | 5 | /** 6 | * 空属性异常 7 | * 8 | * @author itning 9 | */ 10 | public class NullFiledException extends BaseException { 11 | public NullFiledException(String msg, HttpStatus code) { 12 | super(msg, code); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /shw-common/src/main/java/top/itning/server/common/exception/PermissionsException.java: -------------------------------------------------------------------------------- 1 | package top.itning.server.common.exception; 2 | 3 | import org.springframework.http.HttpStatus; 4 | 5 | /** 6 | * 权限异常 7 | * 8 | * @author itning 9 | */ 10 | public class PermissionsException extends BaseException { 11 | public PermissionsException(String msg) { 12 | super(msg, HttpStatus.FORBIDDEN); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /shw-common/src/main/java/top/itning/server/common/exception/NoSuchFiledValueException.java: -------------------------------------------------------------------------------- 1 | package top.itning.server.common.exception; 2 | 3 | import org.springframework.http.HttpStatus; 4 | 5 | /** 6 | * 属性值不存在 7 | * 8 | * @author itning 9 | */ 10 | public class NoSuchFiledValueException extends BaseException { 11 | public NoSuchFiledValueException(String msg, HttpStatus code) { 12 | super(msg, code); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /shw-eureka/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | .sts4-cache 12 | 13 | ### IntelliJ IDEA ### 14 | .idea 15 | *.iws 16 | *.iml 17 | *.ipr 18 | 19 | ### NetBeans ### 20 | /nbproject/private/ 21 | /nbbuild/ 22 | /dist/ 23 | /nbdist/ 24 | /.nb-gradle/ 25 | /build/ 26 | 27 | ### VS Code ### 28 | .vscode/ 29 | -------------------------------------------------------------------------------- /shw-file/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | .sts4-cache 12 | 13 | ### IntelliJ IDEA ### 14 | .idea 15 | *.iws 16 | *.iml 17 | *.ipr 18 | 19 | ### NetBeans ### 20 | /nbproject/private/ 21 | /nbbuild/ 22 | /dist/ 23 | /nbdist/ 24 | /.nb-gradle/ 25 | /build/ 26 | 27 | ### VS Code ### 28 | .vscode/ 29 | -------------------------------------------------------------------------------- /shw-gateway/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | .sts4-cache 12 | 13 | ### IntelliJ IDEA ### 14 | .idea 15 | *.iws 16 | *.iml 17 | *.ipr 18 | 19 | ### NetBeans ### 20 | /nbproject/private/ 21 | /nbbuild/ 22 | /dist/ 23 | /nbdist/ 24 | /.nb-gradle/ 25 | /build/ 26 | 27 | ### VS Code ### 28 | .vscode/ 29 | -------------------------------------------------------------------------------- /shw-group/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | .sts4-cache 12 | 13 | ### IntelliJ IDEA ### 14 | .idea 15 | *.iws 16 | *.iml 17 | *.ipr 18 | 19 | ### NetBeans ### 20 | /nbproject/private/ 21 | /nbbuild/ 22 | /dist/ 23 | /nbdist/ 24 | /.nb-gradle/ 25 | /build/ 26 | 27 | ### VS Code ### 28 | .vscode/ 29 | -------------------------------------------------------------------------------- /shw-upload/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | .sts4-cache 12 | 13 | ### IntelliJ IDEA ### 14 | .idea 15 | *.iws 16 | *.iml 17 | *.ipr 18 | 19 | ### NetBeans ### 20 | /nbproject/private/ 21 | /nbbuild/ 22 | /dist/ 23 | /nbdist/ 24 | /.nb-gradle/ 25 | /build/ 26 | 27 | ### VS Code ### 28 | .vscode/ 29 | -------------------------------------------------------------------------------- /shw-work/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | .sts4-cache 12 | 13 | ### IntelliJ IDEA ### 14 | .idea 15 | *.iws 16 | *.iml 17 | *.ipr 18 | 19 | ### NetBeans ### 20 | /nbproject/private/ 21 | /nbbuild/ 22 | /dist/ 23 | /nbdist/ 24 | /.nb-gradle/ 25 | /build/ 26 | 27 | ### VS Code ### 28 | .vscode/ 29 | -------------------------------------------------------------------------------- /shw-work/src/main/java/top/itning/server/shwwork/repository/WorkRepository.java: -------------------------------------------------------------------------------- 1 | package top.itning.server.shwwork.repository; 2 | 3 | import org.springframework.data.mongodb.repository.ReactiveMongoRepository; 4 | import top.itning.server.shwwork.entity.Work; 5 | 6 | /** 7 | * 作业存储库 8 | * 9 | * @author itning 10 | * @date 2019/5/1 9:50 11 | */ 12 | public interface WorkRepository extends ReactiveMongoRepository { 13 | } 14 | -------------------------------------------------------------------------------- /shw-security/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | .sts4-cache 12 | 13 | ### IntelliJ IDEA ### 14 | .idea 15 | *.iws 16 | *.iml 17 | *.ipr 18 | 19 | ### NetBeans ### 20 | /nbproject/private/ 21 | /nbbuild/ 22 | /dist/ 23 | /nbdist/ 24 | /.nb-gradle/ 25 | /build/ 26 | 27 | ### VS Code ### 28 | .vscode/ 29 | -------------------------------------------------------------------------------- /shw-studentgroup/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | .sts4-cache 12 | 13 | ### IntelliJ IDEA ### 14 | .idea 15 | *.iws 16 | *.iml 17 | *.ipr 18 | 19 | ### NetBeans ### 20 | /nbproject/private/ 21 | /nbbuild/ 22 | /dist/ 23 | /nbdist/ 24 | /.nb-gradle/ 25 | /build/ 26 | 27 | ### VS Code ### 28 | .vscode/ 29 | -------------------------------------------------------------------------------- /shw-group/src/main/java/top/itning/server/shwgroup/repository/GroupRepository.java: -------------------------------------------------------------------------------- 1 | package top.itning.server.shwgroup.repository; 2 | 3 | import org.springframework.data.mongodb.repository.ReactiveMongoRepository; 4 | import top.itning.server.shwgroup.entity.Group; 5 | 6 | /** 7 | * 群组存储库 8 | * 9 | * @author itning 10 | * @date 2019/4/29 11:42 11 | */ 12 | public interface GroupRepository extends ReactiveMongoRepository { 13 | } 14 | -------------------------------------------------------------------------------- /shw-hystrix-dashboard/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | .sts4-cache 12 | 13 | ### IntelliJ IDEA ### 14 | .idea 15 | *.iws 16 | *.iml 17 | *.ipr 18 | 19 | ### NetBeans ### 20 | /nbproject/private/ 21 | /nbbuild/ 22 | /dist/ 23 | /nbdist/ 24 | /.nb-gradle/ 25 | /build/ 26 | 27 | ### VS Code ### 28 | .vscode/ 29 | -------------------------------------------------------------------------------- /shw-notice/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | /target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | 5 | ### STS ### 6 | .apt_generated 7 | .classpath 8 | .factorypath 9 | .project 10 | .settings 11 | .springBeans 12 | .sts4-cache 13 | 14 | ### IntelliJ IDEA ### 15 | .idea 16 | *.iws 17 | *.iml 18 | *.ipr 19 | 20 | ### NetBeans ### 21 | /nbproject/private/ 22 | /nbbuild/ 23 | /dist/ 24 | /nbdist/ 25 | /.nb-gradle/ 26 | /build/ 27 | 28 | ### VS Code ### 29 | .vscode/ 30 | -------------------------------------------------------------------------------- /shw-notice/src/main/java/top/itning/server/shwnotice/repository/NoticeRepository.java: -------------------------------------------------------------------------------- 1 | package top.itning.server.shwnotice.repository; 2 | 3 | import org.springframework.data.mongodb.repository.ReactiveMongoRepository; 4 | import top.itning.server.shwnotice.entity.Notice; 5 | 6 | /** 7 | * 通知存储库 8 | * 9 | * @author itning 10 | * @date 2019/5/4 17:05 11 | */ 12 | public interface NoticeRepository extends ReactiveMongoRepository { 13 | } 14 | -------------------------------------------------------------------------------- /shw-upload/src/main/java/top/itning/server/shwupload/repository/UploadRepository.java: -------------------------------------------------------------------------------- 1 | package top.itning.server.shwupload.repository; 2 | 3 | import org.springframework.data.mongodb.repository.ReactiveMongoRepository; 4 | import top.itning.server.shwupload.entity.Upload; 5 | 6 | /** 7 | * 上传存储库 8 | * 9 | * @author itning 10 | * @date 2019/4/29 11:42 11 | */ 12 | public interface UploadRepository extends ReactiveMongoRepository { 13 | } 14 | -------------------------------------------------------------------------------- /shw-security/src/main/java/top/itning/server/shwsecurity/repository/StudentRepository.java: -------------------------------------------------------------------------------- 1 | package top.itning.server.shwsecurity.repository; 2 | 3 | import org.springframework.data.mongodb.repository.ReactiveMongoRepository; 4 | import top.itning.server.shwsecurity.entity.Student; 5 | 6 | /** 7 | * 学生存储库 8 | * 9 | * @author itning 10 | * @date 2019/4/30 13:10 11 | */ 12 | public interface StudentRepository extends ReactiveMongoRepository { 13 | } 14 | -------------------------------------------------------------------------------- /shw-file/src/test/java/top/itning/server/shwfile/ShwFileApplicationTests.java: -------------------------------------------------------------------------------- 1 | package top.itning.server.shwfile; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class ShwFileApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /shw-work/src/test/java/top/itning/server/shwwork/ShwWorkApplicationTests.java: -------------------------------------------------------------------------------- 1 | package top.itning.server.shwwork; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class ShwWorkApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /shw-group/src/test/java/top/itning/server/shwgroup/ShwGroupApplicationTests.java: -------------------------------------------------------------------------------- 1 | package top.itning.server.shwgroup; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class ShwGroupApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /shw-eureka/src/test/java/top/itning/server/shweureka/ShwEurekaApplicationTests.java: -------------------------------------------------------------------------------- 1 | package top.itning.server.shweureka; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class ShwEurekaApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /shw-notice/src/test/java/top/itning/server/shwnotice/ShwNoticeApplicationTests.java: -------------------------------------------------------------------------------- 1 | package top.itning.server.shwnotice; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class ShwNoticeApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /shw-upload/src/test/java/top/itning/server/shwupload/ShwUploadApplicationTests.java: -------------------------------------------------------------------------------- 1 | package top.itning.server.shwupload; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class ShwUploadApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /shw-gateway/src/test/java/top/itning/server/shwgateway/ShwGatewayApplicationTests.java: -------------------------------------------------------------------------------- 1 | package top.itning.server.shwgateway; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class ShwGatewayApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /shw-studentgroup/src/main/java/top/itning/server/shwstudentgroup/repository/StudentGroupRepository.java: -------------------------------------------------------------------------------- 1 | package top.itning.server.shwstudentgroup.repository; 2 | 3 | import org.springframework.data.mongodb.repository.ReactiveMongoRepository; 4 | import top.itning.server.shwstudentgroup.entity.StudentGroup; 5 | 6 | /** 7 | * 学生群组存储库 8 | * 9 | * @author itning 10 | * @date 2019/4/29 11:42 11 | */ 12 | public interface StudentGroupRepository extends ReactiveMongoRepository { 13 | } 14 | -------------------------------------------------------------------------------- /shw-security/src/test/java/top/itning/server/shwsecurity/ShwSecurityApplicationTests.java: -------------------------------------------------------------------------------- 1 | package top.itning.server.shwsecurity; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class ShwSecurityApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /shw-work/src/main/java/top/itning/server/shwwork/config/BeansConfig.java: -------------------------------------------------------------------------------- 1 | package top.itning.server.shwwork.config; 2 | 3 | import org.modelmapper.ModelMapper; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.Configuration; 6 | 7 | /** 8 | * Beans Config 9 | * 10 | * @author itning 11 | */ 12 | @Configuration 13 | public class BeansConfig { 14 | @Bean 15 | public ModelMapper modelMapper() { 16 | return new ModelMapper(); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /shw-studentgroup/src/test/java/top/itning/server/shwstudentgroup/ShwStudentgroupApplicationTests.java: -------------------------------------------------------------------------------- 1 | package top.itning.server.shwstudentgroup; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class ShwStudentgroupApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /shw-studentgroup/src/main/java/top/itning/server/shwstudentgroup/config/BeansConfig.java: -------------------------------------------------------------------------------- 1 | package top.itning.server.shwstudentgroup.config; 2 | 3 | import org.modelmapper.ModelMapper; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.Configuration; 6 | 7 | /** 8 | * Beans Config 9 | * 10 | * @author itning 11 | */ 12 | @Configuration 13 | public class BeansConfig { 14 | @Bean 15 | public ModelMapper modelMapper() { 16 | return new ModelMapper(); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /shw-notice/src/main/java/top/itning/server/shwnotice/service/NoticeService.java: -------------------------------------------------------------------------------- 1 | package top.itning.server.shwnotice.service; 2 | 3 | import reactor.core.publisher.Flux; 4 | import top.itning.server.shwnotice.entity.Notice; 5 | 6 | /** 7 | * 通知服务 8 | * 9 | * @author itning 10 | * @date 2019/5/4 17:00 11 | */ 12 | public interface NoticeService { 13 | /** 14 | * 根据学生学号获取所有通知 15 | * 16 | * @param studentId 学号 17 | * @return 所有通知 18 | */ 19 | Flux getAllNoticeByStudentId(String studentId); 20 | } 21 | -------------------------------------------------------------------------------- /shw-hystrix-dashboard/src/test/java/top/itning/server/shwhystrixdashboard/ShwHystrixDashboardApplicationTests.java: -------------------------------------------------------------------------------- 1 | package top.itning.server.shwhystrixdashboard; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class ShwHystrixDashboardApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /shw-file/src/main/java/top/itning/server/shwfile/ShwFileApplication.java: -------------------------------------------------------------------------------- 1 | package top.itning.server.shwfile; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.cloud.client.SpringCloudApplication; 5 | import org.springframework.cloud.openfeign.EnableFeignClients; 6 | 7 | /** 8 | * @author itning 9 | */ 10 | @SpringCloudApplication 11 | @EnableFeignClients 12 | public class ShwFileApplication { 13 | 14 | public static void main(String[] args) { 15 | SpringApplication.run(ShwFileApplication.class, args); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /shw-work/src/main/java/top/itning/server/shwwork/ShwWorkApplication.java: -------------------------------------------------------------------------------- 1 | package top.itning.server.shwwork; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.cloud.client.SpringCloudApplication; 5 | import org.springframework.cloud.openfeign.EnableFeignClients; 6 | 7 | /** 8 | * @author itning 9 | */ 10 | @SpringCloudApplication 11 | @EnableFeignClients 12 | public class ShwWorkApplication { 13 | 14 | public static void main(String[] args) { 15 | SpringApplication.run(ShwWorkApplication.class, args); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /shw-group/src/main/java/top/itning/server/shwgroup/ShwGroupApplication.java: -------------------------------------------------------------------------------- 1 | package top.itning.server.shwgroup; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.cloud.client.SpringCloudApplication; 5 | import org.springframework.cloud.openfeign.EnableFeignClients; 6 | 7 | /** 8 | * @author itning 9 | */ 10 | @SpringCloudApplication 11 | @EnableFeignClients 12 | public class ShwGroupApplication { 13 | 14 | public static void main(String[] args) { 15 | SpringApplication.run(ShwGroupApplication.class, args); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /shw-upload/src/main/java/top/itning/server/shwupload/stream/UploadMessage.java: -------------------------------------------------------------------------------- 1 | package top.itning.server.shwupload.stream; 2 | 3 | import org.springframework.cloud.stream.annotation.Output; 4 | import org.springframework.messaging.MessageChannel; 5 | 6 | /** 7 | * 上传消息 8 | * 9 | * @author itning 10 | * @date 2019/5/3 12:20 11 | */ 12 | public interface UploadMessage { 13 | String DELETE = "file_delete"; 14 | 15 | /** 16 | * 上传删除消息 17 | * 18 | * @return {@link MessageChannel} 19 | */ 20 | @Output(DELETE) 21 | MessageChannel delOutput(); 22 | } 23 | -------------------------------------------------------------------------------- /shw-work/src/main/java/top/itning/server/shwwork/stream/DelWorkMessage.java: -------------------------------------------------------------------------------- 1 | package top.itning.server.shwwork.stream; 2 | 3 | import org.springframework.cloud.stream.annotation.Output; 4 | import org.springframework.messaging.MessageChannel; 5 | 6 | /** 7 | * 删除作业消息 8 | * 9 | * @author itning 10 | * @date 2019/5/4 13:42 11 | */ 12 | public interface DelWorkMessage { 13 | String DELETE = "work_delete"; 14 | 15 | /** 16 | * 作业删除消息 17 | * 18 | * @return {@link MessageChannel} 19 | */ 20 | @Output(DELETE) 21 | MessageChannel delOutput(); 22 | } 23 | -------------------------------------------------------------------------------- /shw-file/src/main/java/top/itning/server/shwfile/stream/UploadMessage.java: -------------------------------------------------------------------------------- 1 | package top.itning.server.shwfile.stream; 2 | 3 | import org.springframework.cloud.stream.annotation.Input; 4 | import org.springframework.messaging.SubscribableChannel; 5 | 6 | /** 7 | * 上传消息 8 | * 9 | * @author itning 10 | * @date 2019/5/3 12:20 11 | */ 12 | public interface UploadMessage { 13 | String DELETE = "file_delete"; 14 | 15 | /** 16 | * 删除文件消息接收 17 | * 18 | * @return {@link SubscribableChannel} 19 | */ 20 | @Input(DELETE) 21 | SubscribableChannel input(); 22 | } 23 | -------------------------------------------------------------------------------- /shw-group/src/main/java/top/itning/server/shwgroup/stream/DelGroupMessage.java: -------------------------------------------------------------------------------- 1 | package top.itning.server.shwgroup.stream; 2 | 3 | import org.springframework.cloud.stream.annotation.Output; 4 | import org.springframework.messaging.MessageChannel; 5 | 6 | /** 7 | * 删除群组消息 8 | * 9 | * @author itning 10 | * @date 2019/5/4 14:19 11 | */ 12 | public interface DelGroupMessage { 13 | String DELETE = "group_delete"; 14 | 15 | /** 16 | * 群组删除消息 17 | * 18 | * @return {@link MessageChannel} 19 | */ 20 | @Output(DELETE) 21 | MessageChannel delOutput(); 22 | } 23 | -------------------------------------------------------------------------------- /shw-notice/src/main/java/top/itning/server/shwnotice/ShwNoticeApplication.java: -------------------------------------------------------------------------------- 1 | package top.itning.server.shwnotice; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.cloud.client.SpringCloudApplication; 5 | import org.springframework.cloud.openfeign.EnableFeignClients; 6 | 7 | /** 8 | * @author itning 9 | */ 10 | @SpringCloudApplication 11 | @EnableFeignClients 12 | public class ShwNoticeApplication { 13 | 14 | public static void main(String[] args) { 15 | SpringApplication.run(ShwNoticeApplication.class, args); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /shw-upload/src/main/java/top/itning/server/shwupload/ShwUploadApplication.java: -------------------------------------------------------------------------------- 1 | package top.itning.server.shwupload; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.cloud.client.SpringCloudApplication; 5 | import org.springframework.cloud.openfeign.EnableFeignClients; 6 | 7 | /** 8 | * @author itning 9 | */ 10 | @SpringCloudApplication 11 | @EnableFeignClients 12 | public class ShwUploadApplication { 13 | 14 | public static void main(String[] args) { 15 | SpringApplication.run(ShwUploadApplication.class, args); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /shw-eureka/src/main/java/top/itning/server/shweureka/ShwEurekaApplication.java: -------------------------------------------------------------------------------- 1 | package top.itning.server.shweureka; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer; 6 | 7 | /** 8 | * @author itning 9 | */ 10 | @SpringBootApplication 11 | @EnableEurekaServer 12 | public class ShwEurekaApplication { 13 | 14 | public static void main(String[] args) { 15 | SpringApplication.run(ShwEurekaApplication.class, args); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /shw-security/src/main/java/top/itning/server/shwsecurity/ShwSecurityApplication.java: -------------------------------------------------------------------------------- 1 | package top.itning.server.shwsecurity; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.cloud.client.SpringCloudApplication; 5 | import org.springframework.cloud.openfeign.EnableFeignClients; 6 | 7 | /** 8 | * @author itning 9 | */ 10 | @SpringCloudApplication 11 | @EnableFeignClients 12 | public class ShwSecurityApplication { 13 | 14 | public static void main(String[] args) { 15 | SpringApplication.run(ShwSecurityApplication.class, args); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /shw-studentgroup/src/main/java/top/itning/server/shwstudentgroup/ShwStudentgroupApplication.java: -------------------------------------------------------------------------------- 1 | package top.itning.server.shwstudentgroup; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.cloud.client.SpringCloudApplication; 5 | import org.springframework.cloud.openfeign.EnableFeignClients; 6 | 7 | /** 8 | * @author itning 9 | */ 10 | @SpringCloudApplication 11 | @EnableFeignClients 12 | public class ShwStudentgroupApplication { 13 | 14 | public static void main(String[] args) { 15 | SpringApplication.run(ShwStudentgroupApplication.class, args); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /shw-upload/src/main/java/top/itning/server/shwupload/stream/StudentGroupMessage.java: -------------------------------------------------------------------------------- 1 | package top.itning.server.shwupload.stream; 2 | 3 | import org.springframework.cloud.stream.annotation.Input; 4 | import org.springframework.messaging.SubscribableChannel; 5 | 6 | /** 7 | * 学生群组消息 8 | * 9 | * @author itning 10 | * @date 2019/5/4 12:04 11 | */ 12 | public interface StudentGroupMessage { 13 | String DROP_STUDENT_GROUP = "drop_student_group"; 14 | 15 | /** 16 | * 学生退出群消息接收 17 | * 18 | * @return {@link SubscribableChannel} 19 | */ 20 | @Input(DROP_STUDENT_GROUP) 21 | SubscribableChannel input(); 22 | } 23 | -------------------------------------------------------------------------------- /shw-upload/src/main/java/top/itning/server/shwupload/stream/DelWorkMessage.java: -------------------------------------------------------------------------------- 1 | package top.itning.server.shwupload.stream; 2 | 3 | import org.springframework.cloud.stream.annotation.Input; 4 | import org.springframework.messaging.MessageChannel; 5 | import org.springframework.messaging.SubscribableChannel; 6 | 7 | /** 8 | * 删除作业消息 9 | * 10 | * @author itning 11 | * @date 2019/5/4 13:42 12 | */ 13 | public interface DelWorkMessage { 14 | String DELETE = "work_delete"; 15 | 16 | /** 17 | * 作业删除消息 18 | * 19 | * @return {@link MessageChannel} 20 | */ 21 | @Input(DELETE) 22 | SubscribableChannel input(); 23 | } 24 | -------------------------------------------------------------------------------- /shw-work/src/main/java/top/itning/server/shwwork/stream/DelGroupMessage.java: -------------------------------------------------------------------------------- 1 | package top.itning.server.shwwork.stream; 2 | 3 | import org.springframework.cloud.stream.annotation.Input; 4 | import org.springframework.messaging.MessageChannel; 5 | import org.springframework.messaging.SubscribableChannel; 6 | 7 | /** 8 | * 删除群组消息 9 | * 10 | * @author itning 11 | * @date 2019/5/4 14:19 12 | */ 13 | public interface DelGroupMessage { 14 | String DELETE = "group_delete"; 15 | 16 | /** 17 | * 群组删除消息 18 | * 19 | * @return {@link MessageChannel} 20 | */ 21 | @Input(DELETE) 22 | SubscribableChannel input(); 23 | } 24 | -------------------------------------------------------------------------------- /shw-studentgroup/src/main/java/top/itning/server/shwstudentgroup/stream/StudentGroupMessage.java: -------------------------------------------------------------------------------- 1 | package top.itning.server.shwstudentgroup.stream; 2 | 3 | import org.springframework.cloud.stream.annotation.Output; 4 | import org.springframework.messaging.MessageChannel; 5 | 6 | /** 7 | * 学生群组消息 8 | * 9 | * @author itning 10 | * @date 2019/5/4 12:04 11 | */ 12 | public interface StudentGroupMessage { 13 | String DROP_STUDENT_GROUP = "drop_student_group"; 14 | 15 | /** 16 | * 学生退出群组消息 17 | * 18 | * @return {@link MessageChannel} 19 | */ 20 | @Output(DROP_STUDENT_GROUP) 21 | MessageChannel dropOutStudentGroupOutput(); 22 | } 23 | -------------------------------------------------------------------------------- /shw-studentgroup/src/main/java/top/itning/server/shwstudentgroup/stream/DelGroupMessage.java: -------------------------------------------------------------------------------- 1 | package top.itning.server.shwstudentgroup.stream; 2 | 3 | import org.springframework.cloud.stream.annotation.Input; 4 | import org.springframework.messaging.MessageChannel; 5 | import org.springframework.messaging.SubscribableChannel; 6 | 7 | /** 8 | * 删除群组消息 9 | * 10 | * @author itning 11 | * @date 2019/5/4 14:19 12 | */ 13 | public interface DelGroupMessage { 14 | String DELETE = "group_delete"; 15 | 16 | /** 17 | * 群组删除消息 18 | * 19 | * @return {@link MessageChannel} 20 | */ 21 | @Input(DELETE) 22 | SubscribableChannel input(); 23 | } 24 | -------------------------------------------------------------------------------- /shw-file/src/test/java/top/itning/server/shwfile/client/UploadClientTest.java: -------------------------------------------------------------------------------- 1 | package top.itning.server.shwfile.client; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.boot.test.context.SpringBootTest; 7 | import org.springframework.test.context.junit4.SpringRunner; 8 | 9 | @SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection") 10 | @RunWith(SpringRunner.class) 11 | @SpringBootTest 12 | public class UploadClientTest { 13 | @Autowired 14 | private UploadClient uploadClient; 15 | 16 | @Test 17 | public void testSave() { 18 | 19 | } 20 | } -------------------------------------------------------------------------------- /shw-gateway/src/main/java/top/itning/server/shwgateway/ShwGatewayApplication.java: -------------------------------------------------------------------------------- 1 | package top.itning.server.shwgateway; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.netflix.eureka.EnableEurekaClient; 6 | import org.springframework.cloud.netflix.zuul.EnableZuulProxy; 7 | 8 | /** 9 | * @author itning 10 | */ 11 | @SpringBootApplication 12 | @EnableEurekaClient 13 | @EnableZuulProxy 14 | public class ShwGatewayApplication { 15 | 16 | public static void main(String[] args) { 17 | SpringApplication.run(ShwGatewayApplication.class, args); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /shw-work/src/main/java/top/itning/server/shwwork/util/Tuple.java: -------------------------------------------------------------------------------- 1 | package top.itning.server.shwwork.util; 2 | 3 | import reactor.util.annotation.NonNull; 4 | 5 | import java.util.Objects; 6 | 7 | /** 8 | * 包含两个对象的Tuple 9 | * 10 | * @author itning 11 | * @date 2019/4/30 21:47 12 | */ 13 | public class Tuple { 14 | @NonNull 15 | final T1 t1; 16 | @NonNull 17 | final T2 t2; 18 | 19 | public Tuple(T1 t1, T2 t2) { 20 | this.t1 = Objects.requireNonNull(t1, "t1"); 21 | this.t2 = Objects.requireNonNull(t2, "t2"); 22 | } 23 | 24 | public T1 getT1() { 25 | return t1; 26 | } 27 | 28 | public T2 getT2() { 29 | return t2; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /shw-studentgroup/src/main/java/top/itning/server/shwstudentgroup/util/Tuple.java: -------------------------------------------------------------------------------- 1 | package top.itning.server.shwstudentgroup.util; 2 | 3 | import reactor.util.annotation.NonNull; 4 | 5 | import java.util.Objects; 6 | 7 | /** 8 | * 包含两个对象的Tuple 9 | * 10 | * @author itning 11 | * @date 2019/4/30 21:47 12 | */ 13 | public class Tuple { 14 | @NonNull 15 | final T1 t1; 16 | @NonNull 17 | final T2 t2; 18 | 19 | public Tuple(T1 t1, T2 t2) { 20 | this.t1 = Objects.requireNonNull(t1, "t1"); 21 | this.t2 = Objects.requireNonNull(t2, "t2"); 22 | } 23 | 24 | public T1 getT1() { 25 | return t1; 26 | } 27 | 28 | public T2 getT2() { 29 | return t2; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /shw-work/src/test/java/top/itning/server/shwwork/TestJava.java: -------------------------------------------------------------------------------- 1 | package top.itning.server.shwwork; 2 | 3 | import org.junit.Test; 4 | import top.itning.server.shwwork.entity.Work; 5 | 6 | /** 7 | * @author itning 8 | * @date 2019/5/1 10:52 9 | */ 10 | public class TestJava { 11 | @Test 12 | public void test() { 13 | Work work = new Work(); 14 | work.setGroupId("1"); 15 | work.setEnabled(true); 16 | System.out.println(work); 17 | 18 | Work clones = work.clones(); 19 | System.out.println(clones); 20 | 21 | work.setEnabled(false); 22 | work.setGroupId("2"); 23 | 24 | System.out.println(clones); 25 | System.out.println(work); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /shw-hystrix-dashboard/src/main/java/top/itning/server/shwhystrixdashboard/ShwHystrixDashboardApplication.java: -------------------------------------------------------------------------------- 1 | package top.itning.server.shwhystrixdashboard; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard; 6 | import org.springframework.cloud.netflix.turbine.EnableTurbine; 7 | 8 | /** 9 | * @author itning 10 | */ 11 | @SpringBootApplication 12 | @EnableHystrixDashboard 13 | @EnableTurbine 14 | public class ShwHystrixDashboardApplication { 15 | 16 | public static void main(String[] args) { 17 | SpringApplication.run(ShwHystrixDashboardApplication.class, args); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /shw-file/src/main/java/top/itning/server/shwfile/config/BeansConfig.java: -------------------------------------------------------------------------------- 1 | package top.itning.server.shwfile.config; 2 | 3 | import org.springframework.boot.web.servlet.MultipartConfigFactory; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.Configuration; 6 | 7 | import javax.servlet.MultipartConfigElement; 8 | 9 | /** 10 | * Beans Config 11 | * 12 | * @author itning 13 | */ 14 | @Configuration 15 | public class BeansConfig { 16 | @Bean 17 | MultipartConfigElement multipartConfigElement() { 18 | MultipartConfigFactory factory = new MultipartConfigFactory(); 19 | factory.setLocation(System.getProperty("java.io.tmpdir")); 20 | return factory.createMultipartConfig(); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /shw-gateway/src/main/java/top/itning/server/shwgateway/config/CustomWebMvcConfig.java: -------------------------------------------------------------------------------- 1 | package top.itning.server.shwgateway.config; 2 | 3 | import org.springframework.context.annotation.Configuration; 4 | import org.springframework.web.servlet.config.annotation.CorsRegistry; 5 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; 6 | 7 | /** 8 | * MVC参数配置 9 | * 10 | * @author itning 11 | */ 12 | @Configuration 13 | public class CustomWebMvcConfig implements WebMvcConfigurer { 14 | @Override 15 | public void addCorsMappings(CorsRegistry registry) { 16 | registry.addMapping("/**") 17 | .allowedOrigins("*") 18 | .allowCredentials(true) 19 | .allowedMethods("GET", "POST", "DELETE", "PUT", "PATCH") 20 | .maxAge(86400); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /shw-file/src/main/java/top/itning/server/shwfile/client/WorkClient.java: -------------------------------------------------------------------------------- 1 | package top.itning.server.shwfile.client; 2 | 3 | import org.springframework.cloud.openfeign.FeignClient; 4 | import org.springframework.stereotype.Component; 5 | import org.springframework.web.bind.annotation.GetMapping; 6 | import org.springframework.web.bind.annotation.PathVariable; 7 | import top.itning.server.shwfile.client.entity.Work; 8 | 9 | import java.util.Optional; 10 | 11 | /** 12 | * 作业服务远程调用接口 13 | * 14 | * @author itning 15 | * @date 2019/5/5 19:47 16 | */ 17 | @FeignClient(name = "work") 18 | @Component 19 | public interface WorkClient { 20 | /** 21 | * 获取一个作业信息 22 | * 23 | * @param id 作业ID 24 | * @return 作业信息 25 | */ 26 | @GetMapping("/internal/getOneWorkById/{id}") 27 | Optional getOneWorkById(@PathVariable String id); 28 | } 29 | -------------------------------------------------------------------------------- /shw-common/src/main/java/top/itning/server/common/exception/BaseException.java: -------------------------------------------------------------------------------- 1 | package top.itning.server.common.exception; 2 | 3 | import org.springframework.http.HttpStatus; 4 | 5 | /** 6 | * 异常基类 7 | * 8 | * @author itning 9 | */ 10 | public abstract class BaseException extends RuntimeException { 11 | private String msg; 12 | private HttpStatus code; 13 | 14 | public BaseException(String msg, HttpStatus code) { 15 | super(msg); 16 | this.msg = msg; 17 | this.code = code; 18 | } 19 | 20 | public String getMsg() { 21 | return msg; 22 | } 23 | 24 | public void setMsg(String msg) { 25 | this.msg = msg; 26 | } 27 | 28 | public HttpStatus getCode() { 29 | return code; 30 | } 31 | 32 | public void setCode(HttpStatus code) { 33 | this.code = code; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /shw-upload/src/main/java/top/itning/server/shwupload/client/WorkClient.java: -------------------------------------------------------------------------------- 1 | package top.itning.server.shwupload.client; 2 | 3 | import org.springframework.cloud.openfeign.FeignClient; 4 | import org.springframework.stereotype.Component; 5 | import org.springframework.web.bind.annotation.GetMapping; 6 | import org.springframework.web.bind.annotation.PathVariable; 7 | import top.itning.server.shwupload.client.entity.Work; 8 | 9 | import java.util.List; 10 | 11 | /** 12 | * 作业远程调用 13 | * 14 | * @author itning 15 | * @date 2019/5/4 12:42 16 | */ 17 | @FeignClient(name = "work") 18 | @Component 19 | public interface WorkClient { 20 | /** 21 | * 根据群组ID获取所有作业信息 22 | * 23 | * @param id 群组ID 24 | * @return 作业 25 | */ 26 | @GetMapping("/internal/getAllWorkInfoByGroupId/{id}") 27 | List getAllWorkInfoByGroupId(@PathVariable String id); 28 | } 29 | -------------------------------------------------------------------------------- /shw-work/src/main/java/top/itning/server/shwwork/client/SecurityClient.java: -------------------------------------------------------------------------------- 1 | package top.itning.server.shwwork.client; 2 | 3 | import org.springframework.cloud.openfeign.FeignClient; 4 | import org.springframework.stereotype.Component; 5 | import org.springframework.web.bind.annotation.GetMapping; 6 | import org.springframework.web.bind.annotation.PathVariable; 7 | import top.itning.server.shwwork.client.entity.Student; 8 | 9 | import java.util.Optional; 10 | 11 | /** 12 | * Security远程调用 13 | * 14 | * @author itning 15 | * @date 2019/5/3 15:57 16 | */ 17 | @FeignClient(name = "security") 18 | @Component 19 | public interface SecurityClient { 20 | /** 21 | * 根据学号查询学生信息 22 | * 23 | * @param id 学号 24 | * @return 学生信息 25 | */ 26 | @GetMapping("/internal/findStudentById/{id}") 27 | Optional findStudentById(@PathVariable String id); 28 | } 29 | -------------------------------------------------------------------------------- /shw-file/src/main/java/top/itning/server/shwfile/client/SecurityClient.java: -------------------------------------------------------------------------------- 1 | package top.itning.server.shwfile.client; 2 | 3 | import org.springframework.cloud.openfeign.FeignClient; 4 | import org.springframework.stereotype.Component; 5 | import org.springframework.web.bind.annotation.GetMapping; 6 | import org.springframework.web.bind.annotation.PathVariable; 7 | import top.itning.server.shwfile.client.entity.Student; 8 | 9 | import java.util.Optional; 10 | 11 | /** 12 | * Security服务远程接口 13 | * 14 | * @author itning 15 | * @date 2019/5/5 19:33 16 | */ 17 | @FeignClient(name = "security") 18 | @Component 19 | public interface SecurityClient { 20 | /** 21 | * 根据学号查询学生信息 22 | * 23 | * @param id 学号 24 | * @return 学生信息 25 | */ 26 | @GetMapping("/internal/findStudentById/{id}") 27 | Optional findStudentById(@PathVariable String id); 28 | } 29 | -------------------------------------------------------------------------------- /shw-work/src/main/java/top/itning/server/shwwork/util/Tuple3.java: -------------------------------------------------------------------------------- 1 | package top.itning.server.shwwork.util; 2 | 3 | import reactor.util.annotation.NonNull; 4 | 5 | import java.util.Objects; 6 | 7 | /** 8 | * 包含三个对象的Tuple 9 | * 10 | * @author itning 11 | * @date 2019/4/30 21:47 12 | */ 13 | public class Tuple3 { 14 | @NonNull 15 | final T1 t1; 16 | @NonNull 17 | final T2 t2; 18 | @NonNull 19 | final T3 t3; 20 | 21 | public Tuple3(T1 t1, T2 t2, T3 t3) { 22 | this.t1 = Objects.requireNonNull(t1, "t1"); 23 | this.t2 = Objects.requireNonNull(t2, "t2"); 24 | this.t3 = Objects.requireNonNull(t3, "t3"); 25 | } 26 | 27 | public T1 getT1() { 28 | return t1; 29 | } 30 | 31 | public T2 getT2() { 32 | return t2; 33 | } 34 | 35 | public T3 getT3() { 36 | return t3; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /shw-studentgroup/src/main/java/top/itning/server/shwstudentgroup/client/GroupClient.java: -------------------------------------------------------------------------------- 1 | package top.itning.server.shwstudentgroup.client; 2 | 3 | import org.springframework.cloud.openfeign.FeignClient; 4 | import org.springframework.stereotype.Component; 5 | import org.springframework.web.bind.annotation.GetMapping; 6 | import org.springframework.web.bind.annotation.PathVariable; 7 | import top.itning.server.shwstudentgroup.client.entrty.Group; 8 | 9 | import java.util.Optional; 10 | 11 | /** 12 | * 群组远程调用 13 | * 14 | * @author itning 15 | * @date 2019/4/30 18:20 16 | */ 17 | @FeignClient(name = "group") 18 | @Component 19 | public interface GroupClient { 20 | /** 21 | * 获取某个群组信息 22 | * 23 | * @param id 群组ID 24 | * @return 群组 25 | */ 26 | @GetMapping("/internal/findOneGroupById/{id}") 27 | Optional findOneGroupById(@PathVariable String id); 28 | } 29 | -------------------------------------------------------------------------------- /shw-work/src/test/java/top/itning/server/shwwork/client/UploadClientTest.java: -------------------------------------------------------------------------------- 1 | package top.itning.server.shwwork.client; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.boot.test.context.SpringBootTest; 7 | import org.springframework.test.context.junit4.SpringRunner; 8 | import top.itning.server.shwwork.client.entity.Upload; 9 | 10 | import java.util.Optional; 11 | 12 | import static org.junit.Assert.*; 13 | 14 | @SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection") 15 | @RunWith(SpringRunner.class) 16 | @SpringBootTest 17 | public class UploadClientTest { 18 | @Autowired 19 | private UploadClient uploadClient; 20 | 21 | @Test 22 | public void testFindOneById() { 23 | Optional uploadOptional = uploadClient.findOneById("1"); 24 | System.out.println(uploadOptional.isPresent()); 25 | } 26 | } -------------------------------------------------------------------------------- /shw-studentgroup/src/test/java/top/itning/server/shwstudentgroup/repository/StudentGroupRepositoryTest.java: -------------------------------------------------------------------------------- 1 | package top.itning.server.shwstudentgroup.repository; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.boot.test.context.SpringBootTest; 7 | import org.springframework.test.context.junit4.SpringRunner; 8 | import top.itning.server.shwstudentgroup.entity.StudentGroup; 9 | 10 | import java.util.UUID; 11 | 12 | @SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection") 13 | @RunWith(SpringRunner.class) 14 | @SpringBootTest 15 | public class StudentGroupRepositoryTest { 16 | @Autowired 17 | private StudentGroupRepository studentGroupRepository; 18 | 19 | @Test 20 | public void testSave() { 21 | StudentGroup studentGroup = new StudentGroup(UUID.randomUUID().toString(), UUID.randomUUID().toString()); 22 | studentGroupRepository.save(studentGroup).block(); 23 | } 24 | } -------------------------------------------------------------------------------- /shw-upload/src/test/java/top/itning/server/shwupload/repository/UploadRepositoryTest.java: -------------------------------------------------------------------------------- 1 | package top.itning.server.shwupload.repository; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.boot.test.context.SpringBootTest; 7 | import org.springframework.test.context.junit4.SpringRunner; 8 | import top.itning.server.shwupload.entity.Upload; 9 | 10 | @SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection") 11 | @RunWith(SpringRunner.class) 12 | @SpringBootTest 13 | public class UploadRepositoryTest { 14 | @Autowired 15 | private UploadRepository uploadRepository; 16 | 17 | @Test 18 | public void testSave() { 19 | uploadRepository.save( 20 | new Upload("201601010317", 21 | "769ca1696d9941c39b44033c34a6689a", 22 | "text/html", 23 | ".html", 24 | 200L)).block(); 25 | } 26 | } -------------------------------------------------------------------------------- /shw-studentgroup/src/test/java/top/itning/server/shwstudentgroup/service/StudentGroupServiceTest.java: -------------------------------------------------------------------------------- 1 | package top.itning.server.shwstudentgroup.service; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.boot.test.context.SpringBootTest; 7 | import org.springframework.test.context.junit4.SpringRunner; 8 | 9 | @SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection") 10 | @RunWith(SpringRunner.class) 11 | @SpringBootTest 12 | public class StudentGroupServiceTest { 13 | @Autowired 14 | private StudentGroupService studentGroupService; 15 | 16 | @Test 17 | public void testJoinGroup() { 18 | studentGroupService.joinGroup("2a867ab2efc04d5f912b0e9cd25f0c85", "").block(); 19 | } 20 | 21 | @Test 22 | public void testFindGroupIdByStudentNumber() { 23 | studentGroupService.findGroupIdByStudentNumber("201601010317").collectList().block().forEach(System.out::println); 24 | } 25 | } -------------------------------------------------------------------------------- /shw-work/src/main/java/top/itning/server/shwwork/stream/StreamReceiver.java: -------------------------------------------------------------------------------- 1 | package top.itning.server.shwwork.stream; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.cloud.stream.annotation.EnableBinding; 5 | import org.springframework.cloud.stream.annotation.StreamListener; 6 | import org.springframework.stereotype.Component; 7 | import top.itning.server.shwwork.service.WorkService; 8 | 9 | /** 10 | * 消息接收 11 | * 12 | * @author itning 13 | */ 14 | @Component 15 | @EnableBinding({DelWorkMessage.class, DelGroupMessage.class}) 16 | public class StreamReceiver { 17 | private final WorkService workService; 18 | 19 | @Autowired 20 | public StreamReceiver(WorkService workService) { 21 | this.workService = workService; 22 | } 23 | 24 | /** 25 | * 教师删除群组消息接收 26 | * 27 | * @param groupId 群组ID 28 | */ 29 | @StreamListener(DelGroupMessage.DELETE) 30 | public void receiverDelGroupMessage(String groupId) { 31 | workService.teacherDelGroupFromMessage(groupId).block(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /shw-work/src/main/java/top/itning/server/shwwork/client/UploadClient.java: -------------------------------------------------------------------------------- 1 | package top.itning.server.shwwork.client; 2 | 3 | import org.springframework.cloud.openfeign.FeignClient; 4 | import org.springframework.stereotype.Component; 5 | import org.springframework.web.bind.annotation.GetMapping; 6 | import org.springframework.web.bind.annotation.PathVariable; 7 | import top.itning.server.shwwork.client.entity.Upload; 8 | 9 | import java.util.Optional; 10 | 11 | /** 12 | * 上传远程调用 13 | * 14 | * @author itning 15 | * @date 2019/5/3 14:27 16 | */ 17 | @FeignClient(name = "upload") 18 | @Component 19 | public interface UploadClient { 20 | /** 21 | * 根据作业ID查询上传是否存在 22 | * 23 | * @param id 作业ID 24 | * @return 存在返回true 25 | */ 26 | @GetMapping("/internal/existsById/{id}") 27 | Boolean existsById(@PathVariable String id); 28 | 29 | /** 30 | * 根据ID查询上传信息 31 | * 32 | * @param id 上传信息ID 33 | * @return 上传信息 34 | */ 35 | @GetMapping("/internal/findOneById/{id}") 36 | Optional findOneById(@PathVariable String id); 37 | } 38 | -------------------------------------------------------------------------------- /shw-gateway/src/test/java/top/itning/server/shwgateway/util/JwtUtilsTest.java: -------------------------------------------------------------------------------- 1 | package top.itning.server.shwgateway.util; 2 | 3 | import com.fasterxml.jackson.core.JsonProcessingException; 4 | import org.junit.Test; 5 | import top.itning.server.common.model.LoginUser; 6 | 7 | import static org.junit.Assert.*; 8 | 9 | public class JwtUtilsTest { 10 | 11 | @Test 12 | public void buildJwt() throws JsonProcessingException { 13 | LoginUser loginUser = new LoginUser(); 14 | loginUser.setId("1"); 15 | loginUser.setNo("2"); 16 | loginUser.setLoginName("3"); 17 | loginUser.setUserType("13"); 18 | loginUser.setName("5"); 19 | loginUser.setPhone("6"); 20 | loginUser.setEmail("7"); 21 | loginUser.setMobile("8"); 22 | loginUser.setLoginIp("9"); 23 | loginUser.setRemarks("0"); 24 | loginUser.setRoleId("11"); 25 | loginUser.setDormId("12"); 26 | loginUser.setClazzId("13"); 27 | loginUser.setCompanyId("14"); 28 | loginUser.setOfficeId("15"); 29 | String s = JwtUtils.buildJwt(loginUser); 30 | System.out.println(s); 31 | } 32 | } -------------------------------------------------------------------------------- /shw-notice/src/main/java/top/itning/server/shwnotice/service/impl/NoticeServiceImpl.java: -------------------------------------------------------------------------------- 1 | package top.itning.server.shwnotice.service.impl; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.data.domain.Example; 5 | import org.springframework.stereotype.Service; 6 | import reactor.core.publisher.Flux; 7 | import top.itning.server.shwnotice.entity.Notice; 8 | import top.itning.server.shwnotice.repository.NoticeRepository; 9 | import top.itning.server.shwnotice.service.NoticeService; 10 | 11 | /** 12 | * 通知服务实现 13 | * 14 | * @author itning 15 | * @date 2019/5/4 17:04 16 | */ 17 | @Service 18 | public class NoticeServiceImpl implements NoticeService { 19 | private final NoticeRepository noticeRepository; 20 | 21 | @Autowired 22 | public NoticeServiceImpl(NoticeRepository noticeRepository) { 23 | this.noticeRepository = noticeRepository; 24 | } 25 | 26 | @Override 27 | public Flux getAllNoticeByStudentId(String studentId) { 28 | Notice notice = new Notice(); 29 | notice.setReceiveId(studentId); 30 | return noticeRepository.findAll(Example.of(notice)); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /shw-studentgroup/src/main/java/top/itning/server/shwstudentgroup/stream/StreamReceiver.java: -------------------------------------------------------------------------------- 1 | package top.itning.server.shwstudentgroup.stream; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.cloud.stream.annotation.EnableBinding; 5 | import org.springframework.cloud.stream.annotation.StreamListener; 6 | import org.springframework.stereotype.Component; 7 | import top.itning.server.shwstudentgroup.service.StudentGroupService; 8 | 9 | /** 10 | * 消息接收 11 | * 12 | * @author itning 13 | */ 14 | @Component 15 | @EnableBinding({DelGroupMessage.class, StudentGroupMessage.class}) 16 | public class StreamReceiver { 17 | private final StudentGroupService studentGroupService; 18 | 19 | @Autowired 20 | public StreamReceiver(StudentGroupService studentGroupService) { 21 | this.studentGroupService = studentGroupService; 22 | } 23 | 24 | /** 25 | * 教师删除群组消息接收 26 | * 27 | * @param groupId 群组ID 28 | */ 29 | @StreamListener(DelGroupMessage.DELETE) 30 | public void receiverDelGroupMessage(String groupId) { 31 | studentGroupService.teacherDelGroupMessage(groupId).block(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /shw-notice/src/main/java/top/itning/server/shwnotice/router/NoticeRouters.java: -------------------------------------------------------------------------------- 1 | package top.itning.server.shwnotice.router; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.web.reactive.function.server.RouterFunction; 6 | import org.springframework.web.reactive.function.server.ServerResponse; 7 | import top.itning.server.shwnotice.handler.NoticeHandler; 8 | 9 | import static org.springframework.web.reactive.function.server.RequestPredicates.all; 10 | import static org.springframework.web.reactive.function.server.RouterFunctions.nest; 11 | import static org.springframework.web.reactive.function.server.RouterFunctions.route; 12 | 13 | /** 14 | * 通知路由 15 | * 16 | * @author itning 17 | * @date 2019/5/4 17:08 18 | */ 19 | @Configuration 20 | public class NoticeRouters { 21 | @Bean 22 | RouterFunction userRouter(NoticeHandler noticeHandler) { 23 | return nest( 24 | all(), 25 | route() 26 | 27 | .GET("/", noticeHandler::getAllNotices) 28 | .build() 29 | ); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /shw-security/src/main/java/top/itning/server/shwsecurity/config/BeansConfig.java: -------------------------------------------------------------------------------- 1 | package top.itning.server.shwsecurity.config; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.Configuration; 6 | import org.springframework.http.client.SimpleClientHttpRequestFactory; 7 | import org.springframework.web.client.RestTemplate; 8 | 9 | /** 10 | * Beans Config 11 | * 12 | * @author itning 13 | * @date 2019/4/30 12:23 14 | */ 15 | @Configuration 16 | public class BeansConfig { 17 | private final CasProperties casProperties; 18 | 19 | @Autowired 20 | public BeansConfig(CasProperties casProperties) { 21 | this.casProperties = casProperties; 22 | } 23 | 24 | @Bean 25 | public RestTemplate restTemplate() { 26 | SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory(); 27 | //ms 28 | factory.setReadTimeout(casProperties.getRequestReadTimeout()); 29 | //ms 30 | factory.setConnectTimeout(casProperties.getRequestConnectTimeout()); 31 | return new RestTemplate(factory); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /shw-notice/src/main/java/top/itning/server/shwnotice/handler/NoticeHandler.java: -------------------------------------------------------------------------------- 1 | package top.itning.server.shwnotice.handler; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.lang.NonNull; 5 | import org.springframework.stereotype.Component; 6 | import org.springframework.web.reactive.function.server.ServerRequest; 7 | import org.springframework.web.reactive.function.server.ServerResponse; 8 | import reactor.core.publisher.Mono; 9 | import top.itning.server.shwnotice.service.NoticeService; 10 | 11 | import static top.itning.server.common.model.RestModel.ok; 12 | import static top.itning.server.common.util.Preconditions.getNo; 13 | import static top.itning.server.common.util.Preconditions.mustStudentLogin; 14 | 15 | /** 16 | * 通知处理器 17 | * 18 | * @author itning 19 | * @date 2019/5/4 17:08 20 | */ 21 | @Component 22 | public class NoticeHandler { 23 | private final NoticeService noticeService; 24 | 25 | @Autowired 26 | public NoticeHandler(NoticeService noticeService) { 27 | this.noticeService = noticeService; 28 | } 29 | 30 | @NonNull 31 | public Mono getAllNotices(ServerRequest request) { 32 | mustStudentLogin(request); 33 | return ok(noticeService.getAllNoticeByStudentId(getNo(request)).collectList()); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /shw-file/src/main/java/top/itning/server/shwfile/persistence/FilePersistence.java: -------------------------------------------------------------------------------- 1 | package top.itning.server.shwfile.persistence; 2 | 3 | import org.springframework.web.multipart.MultipartFile; 4 | 5 | import java.io.File; 6 | import java.util.List; 7 | import java.util.Optional; 8 | 9 | /** 10 | * 文件持久化接口 11 | * 12 | * @author itning 13 | * @date 2019/5/3 11:54 14 | */ 15 | public interface FilePersistence { 16 | /** 17 | * 将文件持久化 18 | * 19 | * @param file {@link MultipartFile} 20 | * @param workId 作业ID 21 | * @param studentNumber 学生学号 22 | * @return 持久化成功返回true 23 | */ 24 | boolean file2disk(MultipartFile file, String workId, String studentNumber); 25 | 26 | /** 27 | * 删除文件 28 | * 29 | * @param workId 作业ID 30 | * @param studentNumber 学生学号 31 | * @return 删除成功返回true 32 | */ 33 | boolean fileDel(String workId, String studentNumber); 34 | 35 | /** 36 | * 查找一个文件 37 | * 38 | * @param workId 作业ID 39 | * @param studentNumber 学生学号 40 | * @return 文件 41 | */ 42 | Optional getFile(String workId, String studentNumber); 43 | 44 | /** 45 | * 查找所有文件 46 | * 47 | * @param workId 作业ID 48 | * @return 文件集合 49 | */ 50 | List getFiles(String workId); 51 | } 52 | -------------------------------------------------------------------------------- /shw-file/src/main/java/top/itning/server/shwfile/service/FileService.java: -------------------------------------------------------------------------------- 1 | package top.itning.server.shwfile.service; 2 | 3 | import org.springframework.web.multipart.MultipartFile; 4 | 5 | import javax.servlet.http.HttpServletResponse; 6 | 7 | /** 8 | * 文件服务接口 9 | * 10 | * @author itning 11 | * @date 2019/5/3 11:16 12 | */ 13 | public interface FileService { 14 | /** 15 | * 上传文件 16 | * 17 | * @param file {@link MultipartFile} 18 | * @param studentNumber 学号 19 | * @param workId 作业ID 20 | */ 21 | void uploadFile(MultipartFile file, String studentNumber, String workId); 22 | 23 | /** 24 | * 删除文件 25 | * 26 | * @param studentNumber 学号 27 | * @param workId 作业ID 28 | */ 29 | void delFile(String studentNumber, String workId); 30 | 31 | /** 32 | * 下载文件 33 | * 34 | * @param studentNumber 学号 35 | * @param workId 作业ID 36 | * @param range {@link org.springframework.http.HttpHeaders#RANGE} 37 | * @param response {@link HttpServletResponse} 38 | */ 39 | void downFile(String studentNumber, String workId, String range, HttpServletResponse response); 40 | 41 | /** 42 | * 下载所有作业 43 | * 44 | * @param workId 作业ID 45 | * @param response {@link HttpServletResponse} 46 | */ 47 | void downFiles(String workId, HttpServletResponse response); 48 | } 49 | -------------------------------------------------------------------------------- /shw-file/src/main/java/top/itning/server/shwfile/stream/UploadStreamReceiver.java: -------------------------------------------------------------------------------- 1 | package top.itning.server.shwfile.stream; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.cloud.stream.annotation.EnableBinding; 7 | import org.springframework.cloud.stream.annotation.StreamListener; 8 | import org.springframework.stereotype.Component; 9 | import top.itning.server.shwfile.service.FileService; 10 | 11 | /** 12 | * 消息接收 13 | * 14 | * @author itning 15 | */ 16 | @Component 17 | @EnableBinding(UploadMessage.class) 18 | public class UploadStreamReceiver { 19 | private static final Logger logger = LoggerFactory.getLogger(UploadStreamReceiver.class); 20 | private static final int ID_SPLIT_LENGTH = 2; 21 | private final FileService fileService; 22 | 23 | @Autowired 24 | public UploadStreamReceiver(FileService fileService) { 25 | this.fileService = fileService; 26 | } 27 | 28 | /** 29 | * 删除文件消息接收 30 | * 31 | * @param id ID 32 | */ 33 | @StreamListener(UploadMessage.DELETE) 34 | public void receiver(String id) { 35 | String[] split = id.split("\\|"); 36 | if (ID_SPLIT_LENGTH == split.length) { 37 | fileService.delFile(split[0], split[1]); 38 | } else { 39 | logger.warn("get message error: message body is {}", id); 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /shw-file/src/main/java/top/itning/server/shwfile/client/UploadClient.java: -------------------------------------------------------------------------------- 1 | package top.itning.server.shwfile.client; 2 | 3 | import org.springframework.cloud.openfeign.FeignClient; 4 | import org.springframework.stereotype.Component; 5 | import org.springframework.web.bind.annotation.GetMapping; 6 | import org.springframework.web.bind.annotation.PathVariable; 7 | import org.springframework.web.bind.annotation.PostMapping; 8 | import org.springframework.web.bind.annotation.RequestBody; 9 | import top.itning.server.shwfile.client.entity.Upload; 10 | import top.itning.server.shwfile.pojo.FileUploadMetaData; 11 | 12 | import java.util.List; 13 | import java.util.Optional; 14 | 15 | /** 16 | * 上传服务远程接口 17 | * 18 | * @author itning 19 | * @date 2019/5/4 10:38 20 | */ 21 | @FeignClient(name = "upload") 22 | @Component 23 | public interface UploadClient { 24 | /** 25 | * 保存上传信息 26 | * 27 | * @param upload {@link FileUploadMetaData} 28 | */ 29 | @PostMapping("/internal") 30 | void saveOne(@RequestBody FileUploadMetaData upload); 31 | 32 | /** 33 | * 根据上传ID查询上传信息 34 | * 35 | * @param id 上传ID 36 | * @return 上传信息 37 | */ 38 | @GetMapping("/internal/findOneById/{id}") 39 | Optional findOneById(@PathVariable String id); 40 | 41 | /** 42 | * 根据作业ID查询所有上传信息 43 | * 44 | * @param id 作业ID 45 | * @return 上传信息 46 | */ 47 | @GetMapping("/internal/getAllUploadByWorkId/{id}") 48 | List getAllUploadByWorkId(@PathVariable String id); 49 | } 50 | -------------------------------------------------------------------------------- /shw-file/src/main/java/top/itning/server/shwfile/client/entity/Student.java: -------------------------------------------------------------------------------- 1 | package top.itning.server.shwfile.client.entity; 2 | 3 | /** 4 | * 学生信息 5 | * 6 | * @author itning 7 | * @date 2019/4/30 13:08 8 | */ 9 | public class Student { 10 | /** 11 | * 学号 12 | */ 13 | private String no; 14 | /** 15 | * 登录名 16 | */ 17 | private String loginName; 18 | /** 19 | * 姓名 20 | */ 21 | private String name; 22 | /** 23 | * 班级 24 | */ 25 | private String clazzId; 26 | 27 | public String getNo() { 28 | return no; 29 | } 30 | 31 | public void setNo(String no) { 32 | this.no = no; 33 | } 34 | 35 | public String getLoginName() { 36 | return loginName; 37 | } 38 | 39 | public void setLoginName(String loginName) { 40 | this.loginName = loginName; 41 | } 42 | 43 | public String getName() { 44 | return name; 45 | } 46 | 47 | public void setName(String name) { 48 | this.name = name; 49 | } 50 | 51 | public String getClazzId() { 52 | return clazzId; 53 | } 54 | 55 | public void setClazzId(String clazzId) { 56 | this.clazzId = clazzId; 57 | } 58 | 59 | @Override 60 | public String toString() { 61 | return "Student{" + 62 | "no='" + no + '\'' + 63 | ", loginName='" + loginName + '\'' + 64 | ", name='" + name + '\'' + 65 | ", clazzId='" + clazzId + '\'' + 66 | '}'; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /shw-work/src/main/java/top/itning/server/shwwork/client/entity/Student.java: -------------------------------------------------------------------------------- 1 | package top.itning.server.shwwork.client.entity; 2 | 3 | /** 4 | * 学生 5 | * 6 | * @author itning 7 | * @date 2019/4/30 13:08 8 | */ 9 | public class Student { 10 | /** 11 | * 学号 12 | */ 13 | private String no; 14 | /** 15 | * 登录名 16 | */ 17 | private String loginName; 18 | /** 19 | * 姓名 20 | */ 21 | private String name; 22 | /** 23 | * 班级 24 | */ 25 | private String clazzId; 26 | 27 | public String getNo() { 28 | return no; 29 | } 30 | 31 | public void setNo(String no) { 32 | this.no = no; 33 | } 34 | 35 | public String getLoginName() { 36 | return loginName; 37 | } 38 | 39 | public void setLoginName(String loginName) { 40 | this.loginName = loginName; 41 | } 42 | 43 | public String getName() { 44 | return name; 45 | } 46 | 47 | public void setName(String name) { 48 | this.name = name; 49 | } 50 | 51 | public String getClazzId() { 52 | return clazzId; 53 | } 54 | 55 | public void setClazzId(String clazzId) { 56 | this.clazzId = clazzId; 57 | } 58 | 59 | @Override 60 | public String toString() { 61 | return "Student{" + 62 | "no='" + no + '\'' + 63 | ", loginName='" + loginName + '\'' + 64 | ", name='" + name + '\'' + 65 | ", clazzId='" + clazzId + '\'' + 66 | '}'; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /shw-work/src/main/java/top/itning/server/shwwork/client/StudentGroupClient.java: -------------------------------------------------------------------------------- 1 | package top.itning.server.shwwork.client; 2 | 3 | import org.springframework.cloud.openfeign.FeignClient; 4 | import org.springframework.stereotype.Component; 5 | import org.springframework.web.bind.annotation.GetMapping; 6 | import org.springframework.web.bind.annotation.PathVariable; 7 | import top.itning.server.shwwork.client.entity.StudentGroup; 8 | 9 | import java.util.List; 10 | 11 | /** 12 | * 学生群组远程调用 13 | * 14 | * @author itning 15 | * @date 2019/5/1 9:51 16 | */ 17 | @FeignClient(name = "student-group") 18 | @Component 19 | public interface StudentGroupClient { 20 | /** 21 | * 根据学号查询学生群组中的群组ID信息 22 | * 23 | * @param studentNumber 学号 24 | * @return 群组ID集合 25 | */ 26 | @GetMapping("/internal/findGroupIdByStudentNumber/{studentNumber}") 27 | List findGroupIdByStudentNumber(@PathVariable String studentNumber); 28 | 29 | /** 30 | * 根据群ID查所有学生群组 31 | * 32 | * @param groupId 群ID 33 | * @param page 页码 34 | * @param size 每页数量 35 | * @return 学生集合 36 | */ 37 | @GetMapping("/internal/findAllByGroupID/{groupId}/{page}/{size}") 38 | List findAllByGroupID(@PathVariable String groupId, @PathVariable int page, @PathVariable int size); 39 | 40 | /** 41 | * 根据群ID计算数量 42 | * 43 | * @param groupId 群ID 44 | * @return 数量 45 | */ 46 | @GetMapping("/internal/countAllByGroupID/{groupId}") 47 | long countAllByGroupID(@PathVariable String groupId); 48 | } 49 | -------------------------------------------------------------------------------- /shw-work/src/main/java/top/itning/server/shwwork/client/GroupClient.java: -------------------------------------------------------------------------------- 1 | package top.itning.server.shwwork.client; 2 | 3 | import org.springframework.cloud.openfeign.FeignClient; 4 | import org.springframework.stereotype.Component; 5 | import org.springframework.web.bind.annotation.GetMapping; 6 | import org.springframework.web.bind.annotation.PathVariable; 7 | import top.itning.server.shwwork.client.entity.Group; 8 | 9 | import java.util.List; 10 | import java.util.Optional; 11 | 12 | /** 13 | * 群组远程调用 14 | * 15 | * @author itning 16 | * @date 2019/5/1 14:23 17 | */ 18 | @FeignClient(name = "group") 19 | @Component 20 | public interface GroupClient { 21 | /** 22 | * 通过教师ID查询群组 23 | * 24 | * @param id 教师ID 25 | * @return 群组 26 | */ 27 | @GetMapping("/internal/findByTeacherNumber/{id}") 28 | List findByTeacherNumber(@PathVariable String id); 29 | 30 | /** 31 | * 获取某个群组信息 32 | * 33 | * @param id 群组ID 34 | * @return 群组 35 | */ 36 | @GetMapping("/internal/findOneGroupById/{id}") 37 | Optional findOneGroupById(@PathVariable String id); 38 | 39 | 40 | /** 41 | * 根据群ID查询群名称 42 | * 43 | * @param id 群ID 44 | * @return 群名称 45 | */ 46 | @GetMapping("/internal/findGroupNameByGroupId/{id}") 47 | String findGroupNameByGroupId(@PathVariable String id); 48 | 49 | /** 50 | * 根据群ID查询群 51 | * 52 | * @param id 群ID 53 | * @return 教师名 54 | */ 55 | @GetMapping("/internal/findTeacherNameById/{id}") 56 | String findTeacherNameById(@PathVariable String id); 57 | } 58 | -------------------------------------------------------------------------------- /shw-work/src/test/java/top/itning/server/shwwork/repository/WorkRepositoryTest.java: -------------------------------------------------------------------------------- 1 | package top.itning.server.shwwork.repository; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.boot.test.context.SpringBootTest; 7 | import org.springframework.data.domain.Example; 8 | import org.springframework.data.domain.ExampleMatcher; 9 | import org.springframework.test.context.junit4.SpringRunner; 10 | import top.itning.server.shwwork.entity.Work; 11 | 12 | import java.util.List; 13 | 14 | import static org.junit.Assert.*; 15 | 16 | @SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection") 17 | @RunWith(SpringRunner.class) 18 | @SpringBootTest 19 | public class WorkRepositoryTest { 20 | @Autowired 21 | private WorkRepository workRepository; 22 | 23 | @Test 24 | public void testSave() { 25 | Work work = new Work("2a867ab2efc04d5f912b0e9cd25f0c85", "作业名", true, ""); 26 | workRepository.save(work).block(); 27 | 28 | Work work1 = new Work("2a867ab2efc04d5f912b0e9cd25f0c85", "未开启作业名", false, ""); 29 | workRepository.save(work1).block(); 30 | } 31 | 32 | @Test 33 | public void testFindAll() { 34 | Work w = new Work(); 35 | w.setGroupId("2a867ab2efc04d5f912b0e9cd25f0c85"); 36 | ExampleMatcher matcher = ExampleMatcher.matching().withIgnorePaths("is_enabled"); 37 | List workList = workRepository.findAll(Example.of(w,matcher)).collectList().block(); 38 | workList.forEach(System.out::println); 39 | } 40 | } -------------------------------------------------------------------------------- /shw-group/src/test/java/top/itning/server/shwgroup/util/ReactiveMongoHelperTest.java: -------------------------------------------------------------------------------- 1 | package top.itning.server.shwgroup.util; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.boot.test.context.SpringBootTest; 7 | import org.springframework.test.context.junit4.SpringRunner; 8 | import top.itning.server.shwgroup.entity.Group; 9 | 10 | import java.util.Collections; 11 | 12 | import static org.junit.Assert.assertNotNull; 13 | 14 | @SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection") 15 | @RunWith(SpringRunner.class) 16 | @SpringBootTest 17 | public class ReactiveMongoHelperTest { 18 | @Autowired 19 | private ReactiveMongoHelper reactiveMongoHelper; 20 | 21 | @Test 22 | public void getAllWithCriteriaByPagination() { 23 | } 24 | 25 | @Test 26 | public void getAllWithCriteriaAndDescSortByPagination() { 27 | } 28 | 29 | @Test 30 | public void getAllByPagination() { 31 | } 32 | 33 | @Test 34 | public void getAllWithDescSortByPagination() { 35 | } 36 | 37 | @Test 38 | public void getPage() { 39 | } 40 | 41 | @Test 42 | public void find() { 43 | } 44 | 45 | @Test 46 | public void findOne() { 47 | } 48 | 49 | @Test 50 | public void findOneFieldsByQuery() { 51 | Group group = reactiveMongoHelper.findOneFieldsByQuery(Collections.singletonMap("id", "2a867ab2efc04d5f912b0e9cd25f0c85"), Group.class, "groupName").block(); 52 | assertNotNull(group); 53 | System.out.println(group); 54 | } 55 | 56 | @Test 57 | public void findFieldsByQuery() { 58 | } 59 | 60 | @Test 61 | public void findFieldsByQuery1() { 62 | } 63 | } -------------------------------------------------------------------------------- /shw-gateway/src/main/java/top/itning/server/shwgateway/handler/ErrorHandler.java: -------------------------------------------------------------------------------- 1 | package top.itning.server.shwgateway.handler; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.boot.web.servlet.error.ErrorAttributes; 5 | import org.springframework.boot.web.servlet.error.ErrorController; 6 | import org.springframework.http.MediaType; 7 | import org.springframework.web.bind.annotation.RequestMapping; 8 | import org.springframework.web.bind.annotation.RestController; 9 | import org.springframework.web.context.request.ServletWebRequest; 10 | import org.springframework.web.context.request.WebRequest; 11 | 12 | import javax.servlet.http.HttpServletRequest; 13 | import java.util.Map; 14 | 15 | /** 16 | * 错误处理器 17 | * 18 | * @author itning 19 | * @date 2019/5/2 18:49 20 | */ 21 | @RestController 22 | public class ErrorHandler implements ErrorController { 23 | private final ErrorAttributes errorAttributes; 24 | 25 | @Autowired 26 | public ErrorHandler(ErrorAttributes errorAttributes) { 27 | this.errorAttributes = errorAttributes; 28 | } 29 | 30 | @Override 31 | public String getErrorPath() { 32 | return "/error"; 33 | } 34 | 35 | @RequestMapping(value = "/error", produces = MediaType.APPLICATION_JSON_UTF8_VALUE) 36 | public String error(HttpServletRequest request) { 37 | WebRequest webRequest = new ServletWebRequest(request); 38 | Map errorAttributes = this.errorAttributes.getErrorAttributes(webRequest, true); 39 | String msg = errorAttributes.getOrDefault("error", "not found").toString(); 40 | String code = errorAttributes.getOrDefault("status", 404).toString(); 41 | return "{\"code\":" + code + ",\"msg\":\"" + msg + "\",\"data\":\"\"}"; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /shw-upload/src/main/java/top/itning/server/shwupload/stream/StreamReceiver.java: -------------------------------------------------------------------------------- 1 | package top.itning.server.shwupload.stream; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.cloud.stream.annotation.EnableBinding; 7 | import org.springframework.cloud.stream.annotation.StreamListener; 8 | import org.springframework.stereotype.Component; 9 | import top.itning.server.shwupload.service.UploadService; 10 | 11 | /** 12 | * 消息接收 13 | * 14 | * @author itning 15 | */ 16 | @Component 17 | @EnableBinding({UploadMessage.class, StudentGroupMessage.class, DelWorkMessage.class}) 18 | public class StreamReceiver { 19 | private static final Logger logger = LoggerFactory.getLogger(StreamReceiver.class); 20 | private static final int ID_SPLIT_LENGTH = 2; 21 | 22 | private final UploadService uploadService; 23 | 24 | @Autowired 25 | public StreamReceiver(UploadService uploadService) { 26 | this.uploadService = uploadService; 27 | } 28 | 29 | /** 30 | * 学生退出群组消息接收 31 | * 32 | * @param id studentId + "|" + groupId 33 | */ 34 | @StreamListener(StudentGroupMessage.DROP_STUDENT_GROUP) 35 | public void receiverDropStudentGroupMessage(String id) { 36 | String[] split = id.split("\\|"); 37 | if (ID_SPLIT_LENGTH == split.length) { 38 | uploadService.studentDropGroupFromMessage(split[0], split[1]).block(); 39 | } else { 40 | logger.warn("get message error: message body is {}", id); 41 | } 42 | } 43 | 44 | /** 45 | * 教师删除作业消息接收 46 | * 47 | * @param workId 作业ID 48 | */ 49 | @StreamListener(DelWorkMessage.DELETE) 50 | public void receiverDelWorkMessage(String workId) { 51 | uploadService.teacherDelWorkFromMessage(workId).block(); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /shw-file/src/main/java/top/itning/server/shwfile/pojo/FileUploadMetaData.java: -------------------------------------------------------------------------------- 1 | package top.itning.server.shwfile.pojo; 2 | 3 | /** 4 | * 文件上传元数据 5 | * 6 | * @author itning 7 | * @date 2019/5/3 11:15 8 | */ 9 | public class FileUploadMetaData { 10 | /** 11 | * 学生学号 12 | */ 13 | private String studentId; 14 | /** 15 | * 上传的文件所属的作业ID 16 | */ 17 | private String workId; 18 | /** 19 | * 文件MIME类型 20 | */ 21 | private String mime; 22 | /** 23 | * 扩展名 24 | */ 25 | private String extensionName; 26 | /** 27 | * 大小 28 | */ 29 | private long size; 30 | 31 | public String getStudentId() { 32 | return studentId; 33 | } 34 | 35 | public void setStudentId(String studentId) { 36 | this.studentId = studentId; 37 | } 38 | 39 | public String getWorkId() { 40 | return workId; 41 | } 42 | 43 | public void setWorkId(String workId) { 44 | this.workId = workId; 45 | } 46 | 47 | public String getMime() { 48 | return mime; 49 | } 50 | 51 | public void setMime(String mime) { 52 | this.mime = mime; 53 | } 54 | 55 | public String getExtensionName() { 56 | return extensionName; 57 | } 58 | 59 | public void setExtensionName(String extensionName) { 60 | this.extensionName = extensionName; 61 | } 62 | 63 | public long getSize() { 64 | return size; 65 | } 66 | 67 | public void setSize(long size) { 68 | this.size = size; 69 | } 70 | 71 | @Override 72 | public String toString() { 73 | return "FileUploadMetaData{" + 74 | "studentId='" + studentId + '\'' + 75 | ", workId='" + workId + '\'' + 76 | ", mime='" + mime + '\'' + 77 | ", extensionName='" + extensionName + '\'' + 78 | ", size=" + size + 79 | '}'; 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /shw-security/src/main/java/top/itning/server/shwsecurity/entity/Student.java: -------------------------------------------------------------------------------- 1 | package top.itning.server.shwsecurity.entity; 2 | 3 | import org.springframework.data.annotation.Id; 4 | import org.springframework.data.mongodb.core.index.Indexed; 5 | import org.springframework.data.mongodb.core.mapping.Document; 6 | import org.springframework.data.mongodb.core.mapping.Field; 7 | 8 | /** 9 | * 学生实体 10 | * 11 | * @author itning 12 | * @date 2019/4/30 13:08 13 | */ 14 | @Document(collection = "student") 15 | public class Student { 16 | /** 17 | * 学号 18 | */ 19 | @Id 20 | private String no; 21 | /** 22 | * 登录名 23 | */ 24 | @Field("login_name") 25 | private String loginName; 26 | /** 27 | * 姓名 28 | */ 29 | @Field("name") 30 | @Indexed 31 | private String name; 32 | /** 33 | * 班级 34 | */ 35 | @Field("clazz_id") 36 | private String clazzId; 37 | 38 | public String getNo() { 39 | return no; 40 | } 41 | 42 | public void setNo(String no) { 43 | this.no = no; 44 | } 45 | 46 | public String getLoginName() { 47 | return loginName; 48 | } 49 | 50 | public void setLoginName(String loginName) { 51 | this.loginName = loginName; 52 | } 53 | 54 | public String getName() { 55 | return name; 56 | } 57 | 58 | public void setName(String name) { 59 | this.name = name; 60 | } 61 | 62 | public String getClazzId() { 63 | return clazzId; 64 | } 65 | 66 | public void setClazzId(String clazzId) { 67 | this.clazzId = clazzId; 68 | } 69 | 70 | @Override 71 | public String toString() { 72 | return "Student{" + 73 | "no='" + no + '\'' + 74 | ", loginName='" + loginName + '\'' + 75 | ", name='" + name + '\'' + 76 | ", clazzId='" + clazzId + '\'' + 77 | '}'; 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /shw-work/src/main/java/top/itning/server/shwwork/config/ModelMapperConfig.java: -------------------------------------------------------------------------------- 1 | package top.itning.server.shwwork.config; 2 | 3 | import org.modelmapper.AbstractConverter; 4 | import org.modelmapper.ModelMapper; 5 | import org.modelmapper.PropertyMap; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.stereotype.Component; 8 | import top.itning.server.shwwork.client.GroupClient; 9 | import top.itning.server.shwwork.dto.WorkDTO; 10 | import top.itning.server.shwwork.entity.Work; 11 | 12 | /** 13 | * ModelMapper Config 14 | * 15 | * @author itning 16 | */ 17 | @Component 18 | public class ModelMapperConfig { 19 | private final ModelMapper modelMapper; 20 | 21 | private final GroupClient groupClient; 22 | 23 | @Autowired 24 | public ModelMapperConfig(ModelMapper modelMapper, GroupClient groupClient) { 25 | this.modelMapper = modelMapper; 26 | this.groupClient = groupClient; 27 | addWorkMappings(); 28 | } 29 | 30 | /** 31 | * 作业映射 32 | */ 33 | private void addWorkMappings() { 34 | modelMapper.addMappings(new PropertyMap() { 35 | @Override 36 | protected void configure() { 37 | using(new AbstractConverter() { 38 | @Override 39 | protected String convert(String source) { 40 | return groupClient.findGroupNameByGroupId(source); 41 | } 42 | }).map(source.getGroupId(), destination.getGroupName()); 43 | 44 | using(new AbstractConverter() { 45 | @Override 46 | protected String convert(String source) { 47 | return groupClient.findTeacherNameById(source); 48 | } 49 | }).map(source.getGroupId(), destination.getTeacherName()); 50 | } 51 | }); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /shw-work/src/main/java/top/itning/server/shwwork/dto/WorkDetailsDTO.java: -------------------------------------------------------------------------------- 1 | package top.itning.server.shwwork.dto; 2 | 3 | import top.itning.server.shwwork.client.entity.Student; 4 | import top.itning.server.shwwork.client.entity.Upload; 5 | 6 | import java.io.Serializable; 7 | 8 | /** 9 | * 作业详情DTO 10 | * 11 | * @author itning 12 | */ 13 | public class WorkDetailsDTO implements Serializable { 14 | /** 15 | * 作业名 16 | */ 17 | private String workName; 18 | /** 19 | * 群组名 20 | */ 21 | private String groupName; 22 | /** 23 | * 学生信息 24 | */ 25 | private Student student; 26 | /** 27 | * 上传信息 28 | */ 29 | private Upload upload; 30 | /** 31 | * 是否上传 32 | */ 33 | private boolean up; 34 | 35 | public String getWorkName() { 36 | return workName; 37 | } 38 | 39 | public void setWorkName(String workName) { 40 | this.workName = workName; 41 | } 42 | 43 | public String getGroupName() { 44 | return groupName; 45 | } 46 | 47 | public void setGroupName(String groupName) { 48 | this.groupName = groupName; 49 | } 50 | 51 | public Student getStudent() { 52 | return student; 53 | } 54 | 55 | public void setStudent(Student student) { 56 | this.student = student; 57 | } 58 | 59 | public Upload getUpload() { 60 | return upload; 61 | } 62 | 63 | public void setUpload(Upload upload) { 64 | this.upload = upload; 65 | } 66 | 67 | public boolean isUp() { 68 | return up; 69 | } 70 | 71 | public void setUp(boolean up) { 72 | this.up = up; 73 | } 74 | 75 | @Override 76 | public String toString() { 77 | return "WorkDetailsModel{" + 78 | "workName='" + workName + '\'' + 79 | ", groupName='" + groupName + '\'' + 80 | ", student=" + student + 81 | ", upload=" + upload + 82 | ", up=" + up + 83 | '}'; 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /shw-upload/src/test/java/top/itning/server/shwupload/service/UploadServiceTest.java: -------------------------------------------------------------------------------- 1 | package top.itning.server.shwupload.service; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.boot.test.context.SpringBootTest; 7 | import org.springframework.test.context.junit4.SpringRunner; 8 | import top.itning.server.common.exception.NoSuchFiledValueException; 9 | import top.itning.server.shwupload.entity.Upload; 10 | 11 | import static org.junit.Assert.assertNotNull; 12 | 13 | @SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection") 14 | @RunWith(SpringRunner.class) 15 | @SpringBootTest 16 | public class UploadServiceTest { 17 | @Autowired 18 | private UploadService uploadService; 19 | 20 | @Test 21 | public void getUploadInfoByWorkId() { 22 | Upload upload = uploadService.getUploadInfoByWorkId("201601010317", "b62f93d695a74420852f3f0a8aabfd60").block(); 23 | assertNotNull(upload); 24 | System.out.println(upload); 25 | } 26 | 27 | @Test 28 | public void delUploadInfoByWorkId() { 29 | String studentId = "201601010317"; 30 | String workId = "b62f93d695a74420852f3f0a8aabfd60"; 31 | uploadService.delUploadInfoByWorkId(studentId, workId).block(); 32 | try { 33 | uploadService.getUploadInfoByWorkId(studentId, workId).block(); 34 | } catch (NoSuchFiledValueException e) { 35 | return; 36 | } 37 | throw new RuntimeException("error"); 38 | } 39 | 40 | @Test 41 | public void reviewWork() { 42 | String studentId = "201601010317"; 43 | String workId = "b62f93d695a74420852f3f0a8aabfd60"; 44 | String s = uploadService.reviewWork(studentId, workId).block(); 45 | assertNotNull(s); 46 | System.out.println(s); 47 | } 48 | 49 | @Test 50 | public void testFindOneById() { 51 | Upload upload = uploadService.findOneById("1").block(); 52 | System.out.println(upload); 53 | } 54 | } -------------------------------------------------------------------------------- /shw-security/src/main/java/top/itning/server/shwsecurity/router/LoginRouters.java: -------------------------------------------------------------------------------- 1 | package top.itning.server.shwsecurity.router; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.web.reactive.function.server.RouterFunction; 6 | import org.springframework.web.reactive.function.server.ServerResponse; 7 | import top.itning.server.shwsecurity.entity.Student; 8 | import top.itning.server.shwsecurity.handler.LoginHandler; 9 | import top.itning.server.shwsecurity.repository.StudentRepository; 10 | 11 | import static org.springframework.web.reactive.function.server.RequestPredicates.all; 12 | import static org.springframework.web.reactive.function.server.RequestPredicates.path; 13 | import static org.springframework.web.reactive.function.server.RouterFunctions.nest; 14 | import static org.springframework.web.reactive.function.server.RouterFunctions.route; 15 | 16 | /** 17 | * 登陆路由 18 | * 19 | * @author itning 20 | * @date 2019/4/30 12:02 21 | */ 22 | @Configuration 23 | public class LoginRouters { 24 | private final StudentRepository studentRepository; 25 | 26 | public LoginRouters(StudentRepository studentRepository) { 27 | this.studentRepository = studentRepository; 28 | } 29 | 30 | @Bean 31 | RouterFunction userRouter(LoginHandler loginHandler) { 32 | return nest( 33 | all(), 34 | route() 35 | .GET("/", loginHandler::ticket) 36 | .GET("/login", loginHandler::login) 37 | .GET("/logout", loginHandler::logout) 38 | .build()) 39 | .andNest( 40 | path("/internal"), 41 | route() 42 | .GET("/findStudentById/{id}", serverRequest -> ServerResponse.ok().body(studentRepository.findById(serverRequest.pathVariable("id")), Student.class)) 43 | .build() 44 | ); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /shw-upload/src/main/java/top/itning/server/shwupload/handler/UploadHandler.java: -------------------------------------------------------------------------------- 1 | package top.itning.server.shwupload.handler; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.lang.NonNull; 5 | import org.springframework.stereotype.Component; 6 | import org.springframework.web.reactive.function.server.ServerRequest; 7 | import org.springframework.web.reactive.function.server.ServerResponse; 8 | import reactor.core.publisher.Mono; 9 | import top.itning.server.shwupload.service.UploadService; 10 | 11 | import static top.itning.server.common.model.RestModel.noContent; 12 | import static top.itning.server.common.model.RestModel.ok; 13 | import static top.itning.server.common.util.Preconditions.*; 14 | 15 | /** 16 | * 上传处理器 17 | * 18 | * @author itning 19 | * @date 2019/5/2 16:53 20 | */ 21 | @Component 22 | public class UploadHandler { 23 | private final UploadService uploadService; 24 | 25 | @Autowired 26 | public UploadHandler(UploadService uploadService) { 27 | this.uploadService = uploadService; 28 | } 29 | 30 | @NonNull 31 | public Mono getUpLoadInfoByWorkId(ServerRequest request) { 32 | mustStudentLogin(request); 33 | return ok(uploadService.getUploadInfoByWorkId(getNo(request), request.pathVariable("workId"))); 34 | } 35 | 36 | @NonNull 37 | public Mono deleteUploadWork(ServerRequest request) { 38 | mustStudentLogin(request); 39 | return uploadService.delUploadInfoByWorkId(getNo(request), request.pathVariable("workId")).thenReturn(noContent()).flatMap(s -> s); 40 | } 41 | 42 | @NonNull 43 | public Mono getReviewInfoByWorkId(ServerRequest request) { 44 | String studentId; 45 | try { 46 | studentId = request.pathVariable("studentId"); 47 | mustTeacherLogin(request); 48 | } catch (IllegalArgumentException e) { 49 | studentId = getNo(request); 50 | mustStudentLogin(request); 51 | } 52 | return ok(uploadService.reviewWork(studentId, request.pathVariable("workId"))); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /shw-eureka/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | org.springframework.boot 7 | spring-boot-starter-parent 8 | 2.3.0.RELEASE 9 | 10 | 11 | top.itning.server 12 | shw-eureka 13 | 0.0.1-SNAPSHOT 14 | shw-eureka 15 | Demo project for Spring Boot 16 | 17 | 18 | 1.8 19 | Hoxton.SR4 20 | 21 | 22 | 23 | 24 | org.springframework.cloud 25 | spring-cloud-starter-netflix-eureka-server 26 | 27 | 28 | 29 | org.springframework.boot 30 | spring-boot-starter-test 31 | test 32 | 33 | 34 | 35 | 36 | 37 | 38 | org.springframework.cloud 39 | spring-cloud-dependencies 40 | ${spring-cloud.version} 41 | pom 42 | import 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | org.springframework.boot 51 | spring-boot-maven-plugin 52 | 53 | 54 | 55 | 56 | 57 | -------------------------------------------------------------------------------- /shw-work/src/test/java/top/itning/server/shwwork/service/WorkServiceTest.java: -------------------------------------------------------------------------------- 1 | package top.itning.server.shwwork.service; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.boot.test.context.SpringBootTest; 7 | import org.springframework.data.domain.Page; 8 | import org.springframework.test.context.junit4.SpringRunner; 9 | import top.itning.server.shwwork.dto.WorkDTO; 10 | 11 | @SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection") 12 | @RunWith(SpringRunner.class) 13 | @SpringBootTest 14 | public class WorkServiceTest { 15 | @Autowired 16 | private WorkService workService; 17 | 18 | @Test 19 | public void testGetStudentUnDoneWork() { 20 | Page workDTOPage = workService.getStudentUnDoneWork("201601010317", 0, 10).block(); 21 | System.out.println(workDTOPage.getTotalElements()); 22 | System.out.println(workDTOPage.getTotalPages()); 23 | workDTOPage.getContent().forEach(System.out::println); 24 | } 25 | 26 | @Test 27 | public void testGetStudentDoneWork() { 28 | Page workDTOPage = workService.getStudentDoneWork("201601010317", 0, 10).block(); 29 | System.out.println(workDTOPage.getTotalElements()); 30 | System.out.println(workDTOPage.getTotalPages()); 31 | workDTOPage.getContent().forEach(System.out::println); 32 | } 33 | 34 | @Test 35 | public void testGetTeacherAllWork() { 36 | Page workDTOPage = workService.getTeacherAllWork("0002", 0, 10).block(); 37 | System.out.println(workDTOPage.getTotalElements()); 38 | System.out.println(workDTOPage.getTotalPages()); 39 | workDTOPage.getContent().forEach(System.out::println); 40 | } 41 | 42 | @Test 43 | public void testGetTeacherWork() { 44 | Page workDTOPage = workService.getTeacherWork("0002", "2a867ab2efc04d5f912b0e9cd25f0c85", 0, 10).block(); 45 | System.out.println(workDTOPage.getTotalElements()); 46 | System.out.println(workDTOPage.getTotalPages()); 47 | workDTOPage.getContent().forEach(System.out::println); 48 | } 49 | } -------------------------------------------------------------------------------- /shw-upload/src/main/java/top/itning/server/shwupload/service/UploadService.java: -------------------------------------------------------------------------------- 1 | package top.itning.server.shwupload.service; 2 | 3 | import reactor.core.publisher.Flux; 4 | import reactor.core.publisher.Mono; 5 | import top.itning.server.shwupload.entity.Upload; 6 | 7 | /** 8 | * 上传服务 9 | * 10 | * @author itning 11 | * @date 2019/5/2 16:53 12 | */ 13 | public interface UploadService { 14 | /** 15 | * 根据作业ID获取上传信息 16 | * 17 | * @param studentId 学生学号 18 | * @param workId 作业ID 19 | * @return 上传 20 | */ 21 | Mono getUploadInfoByWorkId(String studentId, String workId); 22 | 23 | /** 24 | * 根据作业ID 删除作业 25 | * 作业必须是开启状态 26 | * 27 | * @param studentId 学生学号 28 | * @param workId 作业ID 29 | * @return 操作完成后的信号 30 | */ 31 | Mono delUploadInfoByWorkId(String studentId, String workId); 32 | 33 | /** 34 | * 获取批阅信息 35 | * 36 | * @param workId 作业ID 37 | * @param studentId 学生ID 38 | * @return 批阅信息 39 | */ 40 | Mono reviewWork(String studentId, String workId); 41 | 42 | /** 43 | * 根据作业ID查询上传是否存在 44 | * 45 | * @param uploadId ID 46 | * @return 存在返回true 47 | */ 48 | Mono existsById(String uploadId); 49 | 50 | /** 51 | * 根据ID查询上传信息 52 | * 53 | * @param uploadId 上传信息ID 54 | * @return 上传信息 55 | */ 56 | Mono findOneById(String uploadId); 57 | 58 | /** 59 | * 保存上传信息 60 | * 61 | * @param upload {@link Upload} 62 | * @return 被保存的上传信息 63 | */ 64 | Mono save(Upload upload); 65 | 66 | /** 67 | * 学生退出群组消息 68 | * 69 | * @param studentId 学生学号 70 | * @param groupId 群组ID 71 | * @return 操作完成后的信号 72 | */ 73 | Mono studentDropGroupFromMessage(String studentId, String groupId); 74 | 75 | /** 76 | * 教师删除作业消息 77 | * 78 | * @param workId 作业ID 79 | * @return 操作完成后的信号 80 | */ 81 | Mono teacherDelWorkFromMessage(String workId); 82 | 83 | /** 84 | * 根据作业ID查询所有上传信息 85 | * 86 | * @param workId 作业ID 87 | * @return 上传信息 88 | */ 89 | Flux getAllUploadByWorkId(String workId); 90 | } 91 | -------------------------------------------------------------------------------- /shw-work/src/main/java/top/itning/server/shwwork/exception/JsonHttpMessageWriter.java: -------------------------------------------------------------------------------- 1 | package top.itning.server.shwwork.exception; 2 | 3 | import org.reactivestreams.Publisher; 4 | import org.springframework.core.ResolvableType; 5 | import org.springframework.http.MediaType; 6 | import org.springframework.http.ReactiveHttpOutputMessage; 7 | import org.springframework.http.codec.HttpMessageWriter; 8 | import org.springframework.lang.NonNull; 9 | import org.springframework.stereotype.Component; 10 | import reactor.core.publisher.Mono; 11 | 12 | import java.util.Collections; 13 | import java.util.List; 14 | import java.util.Map; 15 | 16 | /** 17 | * JSON格式消息写入器 18 | * 该类解析MAP将其转换为JSON 19 | * 20 | * @author itning 21 | * @date 2019/4/29 19:07 22 | */ 23 | @Component 24 | public class JsonHttpMessageWriter implements HttpMessageWriter> { 25 | @NonNull 26 | @Override 27 | public List getWritableMediaTypes() { 28 | return Collections.singletonList(MediaType.APPLICATION_JSON_UTF8); 29 | } 30 | 31 | @Override 32 | public boolean canWrite(@NonNull ResolvableType elementType, MediaType mediaType) { 33 | return MediaType.APPLICATION_JSON.includes(mediaType); 34 | } 35 | 36 | @NonNull 37 | @Override 38 | public Mono write(@NonNull Publisher> inputStream, 39 | @NonNull ResolvableType elementType, 40 | MediaType mediaType, 41 | @NonNull ReactiveHttpOutputMessage message, 42 | @NonNull Map hints) { 43 | return Mono.from(inputStream).flatMap(m -> message.writeWith(Mono.just(message.bufferFactory().wrap(transform2Json(m).getBytes())))); 44 | } 45 | 46 | private String transform2Json(Map sourceMap) { 47 | return "{" + 48 | "\"code\":" + 49 | sourceMap.getOrDefault("code", 500) + 50 | "," + 51 | "\"msg\":\"" + 52 | sourceMap.getOrDefault("msg", "") + 53 | "\"," + 54 | "\"data\":\"" + 55 | sourceMap.getOrDefault("data", "") + 56 | "\"}"; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /shw-gateway/src/main/java/top/itning/server/shwgateway/filter/ErrorFilter.java: -------------------------------------------------------------------------------- 1 | package top.itning.server.shwgateway.filter; 2 | 3 | import com.netflix.zuul.ZuulFilter; 4 | import com.netflix.zuul.context.RequestContext; 5 | import com.netflix.zuul.exception.ZuulException; 6 | import org.springframework.http.MediaType; 7 | import org.springframework.stereotype.Component; 8 | 9 | import javax.servlet.http.HttpServletResponse; 10 | import java.io.IOException; 11 | import java.io.PrintWriter; 12 | 13 | import static org.springframework.cloud.netflix.zuul.filters.support.FilterConstants.ERROR_TYPE; 14 | import static org.springframework.cloud.netflix.zuul.filters.support.FilterConstants.SEND_ERROR_FILTER_ORDER; 15 | 16 | /** 17 | * 错误信息过滤 18 | * 19 | * @author itning 20 | * @date 2019/4/30 2:53 21 | */ 22 | @Component 23 | public class ErrorFilter extends ZuulFilter { 24 | @Override 25 | public String filterType() { 26 | return ERROR_TYPE; 27 | } 28 | 29 | @Override 30 | public int filterOrder() { 31 | return SEND_ERROR_FILTER_ORDER - 1; 32 | } 33 | 34 | @Override 35 | public boolean shouldFilter() { 36 | RequestContext ctx = RequestContext.getCurrentContext(); 37 | return ctx.getThrowable() != null; 38 | } 39 | 40 | @Override 41 | public Object run() throws ZuulException { 42 | RequestContext ctx = RequestContext.getCurrentContext(); 43 | Throwable throwable = ctx.getThrowable(); 44 | String msg = throwable.getMessage(); 45 | Throwable cause = throwable.getCause(); 46 | if (cause != null) { 47 | msg = cause.getMessage(); 48 | } 49 | ctx.setSendZuulResponse(false); 50 | ctx.setResponseStatusCode(500); 51 | HttpServletResponse response = ctx.getResponse(); 52 | response.setContentType(MediaType.APPLICATION_JSON_UTF8_VALUE); 53 | try (PrintWriter writer = response.getWriter()) { 54 | writer.write("{\"code\":500,\"msg\":\"" + msg + "\",\"data\":\"\"}"); 55 | writer.flush(); 56 | ctx.setResponse(response); 57 | } catch (IOException e) { 58 | throw new ZuulException(e.getMessage(), 500, ""); 59 | } 60 | return null; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /shw-group/src/main/java/top/itning/server/shwgroup/exception/JsonHttpMessageWriter.java: -------------------------------------------------------------------------------- 1 | package top.itning.server.shwgroup.exception; 2 | 3 | import org.reactivestreams.Publisher; 4 | import org.springframework.core.ResolvableType; 5 | import org.springframework.http.MediaType; 6 | import org.springframework.http.ReactiveHttpOutputMessage; 7 | import org.springframework.http.codec.HttpMessageWriter; 8 | import org.springframework.lang.NonNull; 9 | import org.springframework.stereotype.Component; 10 | import reactor.core.publisher.Mono; 11 | 12 | import java.util.Collections; 13 | import java.util.List; 14 | import java.util.Map; 15 | 16 | /** 17 | * JSON格式消息写入器 18 | * 该类解析MAP将其转换为JSON 19 | * 20 | * @author itning 21 | * @date 2019/4/29 19:07 22 | */ 23 | @Component 24 | public class JsonHttpMessageWriter implements HttpMessageWriter> { 25 | @NonNull 26 | @Override 27 | public List getWritableMediaTypes() { 28 | return Collections.singletonList(MediaType.APPLICATION_JSON_UTF8); 29 | } 30 | 31 | @Override 32 | public boolean canWrite(@NonNull ResolvableType elementType, MediaType mediaType) { 33 | return MediaType.APPLICATION_JSON.includes(mediaType); 34 | } 35 | 36 | @NonNull 37 | @Override 38 | public Mono write(@NonNull Publisher> inputStream, 39 | @NonNull ResolvableType elementType, 40 | MediaType mediaType, 41 | @NonNull ReactiveHttpOutputMessage message, 42 | @NonNull Map hints) { 43 | return Mono.from(inputStream).flatMap(m -> message.writeWith(Mono.just(message.bufferFactory().wrap(transform2Json(m).getBytes())))); 44 | } 45 | 46 | private String transform2Json(Map sourceMap) { 47 | return "{" + 48 | "\"code\":" + 49 | sourceMap.getOrDefault("code", 500) + 50 | "," + 51 | "\"msg\":\"" + 52 | sourceMap.getOrDefault("msg", "") + 53 | "\"," + 54 | "\"data\":\"" + 55 | sourceMap.getOrDefault("data", "") + 56 | "\"}"; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /shw-notice/src/main/java/top/itning/server/shwnotice/exception/JsonHttpMessageWriter.java: -------------------------------------------------------------------------------- 1 | package top.itning.server.shwnotice.exception; 2 | 3 | import org.reactivestreams.Publisher; 4 | import org.springframework.core.ResolvableType; 5 | import org.springframework.http.MediaType; 6 | import org.springframework.http.ReactiveHttpOutputMessage; 7 | import org.springframework.http.codec.HttpMessageWriter; 8 | import org.springframework.lang.NonNull; 9 | import org.springframework.stereotype.Component; 10 | import reactor.core.publisher.Mono; 11 | 12 | import java.util.Collections; 13 | import java.util.List; 14 | import java.util.Map; 15 | 16 | /** 17 | * JSON格式消息写入器 18 | * 该类解析MAP将其转换为JSON 19 | * 20 | * @author itning 21 | * @date 2019/4/29 19:07 22 | */ 23 | @Component 24 | public class JsonHttpMessageWriter implements HttpMessageWriter> { 25 | @NonNull 26 | @Override 27 | public List getWritableMediaTypes() { 28 | return Collections.singletonList(MediaType.APPLICATION_JSON_UTF8); 29 | } 30 | 31 | @Override 32 | public boolean canWrite(@NonNull ResolvableType elementType, MediaType mediaType) { 33 | return MediaType.APPLICATION_JSON.includes(mediaType); 34 | } 35 | 36 | @NonNull 37 | @Override 38 | public Mono write(@NonNull Publisher> inputStream, 39 | @NonNull ResolvableType elementType, 40 | MediaType mediaType, 41 | @NonNull ReactiveHttpOutputMessage message, 42 | @NonNull Map hints) { 43 | return Mono.from(inputStream).flatMap(m -> message.writeWith(Mono.just(message.bufferFactory().wrap(transform2Json(m).getBytes())))); 44 | } 45 | 46 | private String transform2Json(Map sourceMap) { 47 | return "{" + 48 | "\"code\":" + 49 | sourceMap.getOrDefault("code", 500) + 50 | "," + 51 | "\"msg\":\"" + 52 | sourceMap.getOrDefault("msg", "") + 53 | "\"," + 54 | "\"data\":\"" + 55 | sourceMap.getOrDefault("data", "") + 56 | "\"}"; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /shw-upload/src/main/java/top/itning/server/shwupload/exception/JsonHttpMessageWriter.java: -------------------------------------------------------------------------------- 1 | package top.itning.server.shwupload.exception; 2 | 3 | import org.reactivestreams.Publisher; 4 | import org.springframework.core.ResolvableType; 5 | import org.springframework.http.MediaType; 6 | import org.springframework.http.ReactiveHttpOutputMessage; 7 | import org.springframework.http.codec.HttpMessageWriter; 8 | import org.springframework.lang.NonNull; 9 | import org.springframework.stereotype.Component; 10 | import reactor.core.publisher.Mono; 11 | 12 | import java.util.Collections; 13 | import java.util.List; 14 | import java.util.Map; 15 | 16 | /** 17 | * JSON格式消息写入器 18 | * 该类解析MAP将其转换为JSON 19 | * 20 | * @author itning 21 | * @date 2019/4/29 19:07 22 | */ 23 | @Component 24 | public class JsonHttpMessageWriter implements HttpMessageWriter> { 25 | @NonNull 26 | @Override 27 | public List getWritableMediaTypes() { 28 | return Collections.singletonList(MediaType.APPLICATION_JSON_UTF8); 29 | } 30 | 31 | @Override 32 | public boolean canWrite(@NonNull ResolvableType elementType, MediaType mediaType) { 33 | return MediaType.APPLICATION_JSON.includes(mediaType); 34 | } 35 | 36 | @NonNull 37 | @Override 38 | public Mono write(@NonNull Publisher> inputStream, 39 | @NonNull ResolvableType elementType, 40 | MediaType mediaType, 41 | @NonNull ReactiveHttpOutputMessage message, 42 | @NonNull Map hints) { 43 | return Mono.from(inputStream).flatMap(m -> message.writeWith(Mono.just(message.bufferFactory().wrap(transform2Json(m).getBytes())))); 44 | } 45 | 46 | private String transform2Json(Map sourceMap) { 47 | return "{" + 48 | "\"code\":" + 49 | sourceMap.getOrDefault("code", 500) + 50 | "," + 51 | "\"msg\":\"" + 52 | sourceMap.getOrDefault("msg", "") + 53 | "\"," + 54 | "\"data\":\"" + 55 | sourceMap.getOrDefault("data", "") + 56 | "\"}"; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /shw-group/src/main/java/top/itning/server/shwgroup/exception/GlobalErrorAttributes.java: -------------------------------------------------------------------------------- 1 | package top.itning.server.shwgroup.exception; 2 | 3 | 4 | import org.springframework.boot.web.reactive.error.DefaultErrorAttributes; 5 | import org.springframework.stereotype.Component; 6 | import org.springframework.web.reactive.function.server.ServerRequest; 7 | import org.springframework.web.server.ResponseStatusException; 8 | import top.itning.server.common.exception.BaseException; 9 | 10 | import java.util.LinkedHashMap; 11 | import java.util.Map; 12 | 13 | /** 14 | * 错误信息属性填充 15 | * 该类扩展{@link DefaultErrorAttributes}将错误信息封装在MAP中 16 | * 17 | * @author itning 18 | * @date 2019/4/29 18:11 19 | */ 20 | @Component 21 | public class GlobalErrorAttributes extends DefaultErrorAttributes { 22 | @Override 23 | public Map getErrorAttributes(ServerRequest request, boolean includeStackTrace) { 24 | Throwable error = getError(request); 25 | if (error instanceof BaseException) { 26 | BaseException baseException = (BaseException) error; 27 | Map errorAttributes = new LinkedHashMap<>(); 28 | errorAttributes.put("code", baseException.getCode().value()); 29 | errorAttributes.put("msg", baseException.getMsg()); 30 | errorAttributes.put("data", ""); 31 | return errorAttributes; 32 | } else if (error instanceof ResponseStatusException) { 33 | ResponseStatusException responseStatusException = (ResponseStatusException) error; 34 | Map errorAttributes = new LinkedHashMap<>(); 35 | errorAttributes.put("code", responseStatusException.getStatus().value()); 36 | errorAttributes.put("msg", responseStatusException.getMessage()); 37 | errorAttributes.put("data", ""); 38 | return errorAttributes; 39 | } else { 40 | Map errorAttributes = super.getErrorAttributes(request, includeStackTrace); 41 | errorAttributes.put("code", errorAttributes.getOrDefault("status", 404)); 42 | errorAttributes.put("msg", error.getMessage()); 43 | errorAttributes.put("data", ""); 44 | return errorAttributes; 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /shw-security/src/main/java/top/itning/server/shwsecurity/exception/JsonHttpMessageWriter.java: -------------------------------------------------------------------------------- 1 | package top.itning.server.shwsecurity.exception; 2 | 3 | import org.reactivestreams.Publisher; 4 | import org.springframework.core.ResolvableType; 5 | import org.springframework.http.MediaType; 6 | import org.springframework.http.ReactiveHttpOutputMessage; 7 | import org.springframework.http.codec.HttpMessageWriter; 8 | import org.springframework.lang.NonNull; 9 | import org.springframework.stereotype.Component; 10 | import reactor.core.publisher.Mono; 11 | 12 | import java.util.Collections; 13 | import java.util.List; 14 | import java.util.Map; 15 | 16 | /** 17 | * JSON格式消息写入器 18 | * 该类解析MAP将其转换为JSON 19 | * 20 | * @author itning 21 | * @date 2019/4/29 19:07 22 | */ 23 | @Component 24 | public class JsonHttpMessageWriter implements HttpMessageWriter> { 25 | @NonNull 26 | @Override 27 | public List getWritableMediaTypes() { 28 | return Collections.singletonList(MediaType.APPLICATION_JSON_UTF8); 29 | } 30 | 31 | @Override 32 | public boolean canWrite(@NonNull ResolvableType elementType, MediaType mediaType) { 33 | return MediaType.APPLICATION_JSON.includes(mediaType); 34 | } 35 | 36 | @NonNull 37 | @Override 38 | public Mono write(@NonNull Publisher> inputStream, 39 | @NonNull ResolvableType elementType, 40 | MediaType mediaType, 41 | @NonNull ReactiveHttpOutputMessage message, 42 | @NonNull Map hints) { 43 | return Mono.from(inputStream).flatMap(m -> message.writeWith(Mono.just(message.bufferFactory().wrap(transform2Json(m).getBytes())))); 44 | } 45 | 46 | private String transform2Json(Map sourceMap) { 47 | return "{" + 48 | "\"code\":" + 49 | sourceMap.getOrDefault("code", 500) + 50 | "," + 51 | "\"msg\":\"" + 52 | sourceMap.getOrDefault("msg", "") + 53 | "\"," + 54 | "\"data\":\"" + 55 | sourceMap.getOrDefault("data", "") + 56 | "\"}"; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /shw-work/src/main/java/top/itning/server/shwwork/exception/GlobalErrorAttributes.java: -------------------------------------------------------------------------------- 1 | package top.itning.server.shwwork.exception; 2 | 3 | 4 | import org.springframework.boot.web.reactive.error.DefaultErrorAttributes; 5 | import org.springframework.stereotype.Component; 6 | import org.springframework.web.reactive.function.server.ServerRequest; 7 | import org.springframework.web.server.ResponseStatusException; 8 | import top.itning.server.common.exception.BaseException; 9 | 10 | import java.util.LinkedHashMap; 11 | import java.util.Map; 12 | 13 | /** 14 | * 错误信息属性填充 15 | * 该类扩展{@link DefaultErrorAttributes}将错误信息封装在MAP中 16 | * 17 | * @author itning 18 | * @date 2019/4/29 18:11 19 | */ 20 | @Component 21 | public class GlobalErrorAttributes extends DefaultErrorAttributes { 22 | @Override 23 | public Map getErrorAttributes(ServerRequest request, boolean includeStackTrace) { 24 | Throwable error = getError(request); 25 | if (error instanceof BaseException) { 26 | BaseException baseException = (BaseException) error; 27 | Map errorAttributes = new LinkedHashMap<>(); 28 | errorAttributes.put("code", baseException.getCode().value()); 29 | errorAttributes.put("msg", baseException.getMsg()); 30 | errorAttributes.put("data", ""); 31 | return errorAttributes; 32 | } else if (error instanceof ResponseStatusException) { 33 | ResponseStatusException responseStatusException = (ResponseStatusException) error; 34 | Map errorAttributes = new LinkedHashMap<>(); 35 | errorAttributes.put("code", responseStatusException.getStatus().value()); 36 | errorAttributes.put("msg", responseStatusException.getMessage()); 37 | errorAttributes.put("data", ""); 38 | return errorAttributes; 39 | } else { 40 | Map errorAttributes = super.getErrorAttributes(request, includeStackTrace); 41 | errorAttributes.put("code", errorAttributes.getOrDefault("status", 404)); 42 | errorAttributes.put("msg", error.getMessage()); 43 | errorAttributes.put("data", ""); 44 | return errorAttributes; 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /shw-notice/src/main/java/top/itning/server/shwnotice/exception/GlobalErrorAttributes.java: -------------------------------------------------------------------------------- 1 | package top.itning.server.shwnotice.exception; 2 | 3 | 4 | import org.springframework.boot.web.reactive.error.DefaultErrorAttributes; 5 | import org.springframework.stereotype.Component; 6 | import org.springframework.web.reactive.function.server.ServerRequest; 7 | import org.springframework.web.server.ResponseStatusException; 8 | import top.itning.server.common.exception.BaseException; 9 | 10 | import java.util.LinkedHashMap; 11 | import java.util.Map; 12 | 13 | /** 14 | * 错误信息属性填充 15 | * 该类扩展{@link DefaultErrorAttributes}将错误信息封装在MAP中 16 | * 17 | * @author itning 18 | * @date 2019/4/29 18:11 19 | */ 20 | @Component 21 | public class GlobalErrorAttributes extends DefaultErrorAttributes { 22 | @Override 23 | public Map getErrorAttributes(ServerRequest request, boolean includeStackTrace) { 24 | Throwable error = getError(request); 25 | if (error instanceof BaseException) { 26 | BaseException baseException = (BaseException) error; 27 | Map errorAttributes = new LinkedHashMap<>(); 28 | errorAttributes.put("code", baseException.getCode().value()); 29 | errorAttributes.put("msg", baseException.getMsg()); 30 | errorAttributes.put("data", ""); 31 | return errorAttributes; 32 | } else if (error instanceof ResponseStatusException) { 33 | ResponseStatusException responseStatusException = (ResponseStatusException) error; 34 | Map errorAttributes = new LinkedHashMap<>(); 35 | errorAttributes.put("code", responseStatusException.getStatus().value()); 36 | errorAttributes.put("msg", responseStatusException.getMessage()); 37 | errorAttributes.put("data", ""); 38 | return errorAttributes; 39 | } else { 40 | Map errorAttributes = super.getErrorAttributes(request, includeStackTrace); 41 | errorAttributes.put("code", errorAttributes.getOrDefault("status", 404)); 42 | errorAttributes.put("msg", error.getMessage()); 43 | errorAttributes.put("data", ""); 44 | return errorAttributes; 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /shw-upload/src/main/java/top/itning/server/shwupload/exception/GlobalErrorAttributes.java: -------------------------------------------------------------------------------- 1 | package top.itning.server.shwupload.exception; 2 | 3 | 4 | import org.springframework.boot.web.reactive.error.DefaultErrorAttributes; 5 | import org.springframework.stereotype.Component; 6 | import org.springframework.web.reactive.function.server.ServerRequest; 7 | import org.springframework.web.server.ResponseStatusException; 8 | import top.itning.server.common.exception.BaseException; 9 | 10 | import java.util.LinkedHashMap; 11 | import java.util.Map; 12 | 13 | /** 14 | * 错误信息属性填充 15 | * 该类扩展{@link DefaultErrorAttributes}将错误信息封装在MAP中 16 | * 17 | * @author itning 18 | * @date 2019/4/29 18:11 19 | */ 20 | @Component 21 | public class GlobalErrorAttributes extends DefaultErrorAttributes { 22 | @Override 23 | public Map getErrorAttributes(ServerRequest request, boolean includeStackTrace) { 24 | Throwable error = getError(request); 25 | if (error instanceof BaseException) { 26 | BaseException baseException = (BaseException) error; 27 | Map errorAttributes = new LinkedHashMap<>(); 28 | errorAttributes.put("code", baseException.getCode().value()); 29 | errorAttributes.put("msg", baseException.getMsg()); 30 | errorAttributes.put("data", ""); 31 | return errorAttributes; 32 | } else if (error instanceof ResponseStatusException) { 33 | ResponseStatusException responseStatusException = (ResponseStatusException) error; 34 | Map errorAttributes = new LinkedHashMap<>(); 35 | errorAttributes.put("code", responseStatusException.getStatus().value()); 36 | errorAttributes.put("msg", responseStatusException.getMessage()); 37 | errorAttributes.put("data", ""); 38 | return errorAttributes; 39 | } else { 40 | Map errorAttributes = super.getErrorAttributes(request, includeStackTrace); 41 | errorAttributes.put("code", errorAttributes.getOrDefault("status", 404)); 42 | errorAttributes.put("msg", error.getMessage()); 43 | errorAttributes.put("data", ""); 44 | return errorAttributes; 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /shw-security/src/main/java/top/itning/server/shwsecurity/exception/GlobalErrorAttributes.java: -------------------------------------------------------------------------------- 1 | package top.itning.server.shwsecurity.exception; 2 | 3 | 4 | import org.springframework.boot.web.reactive.error.DefaultErrorAttributes; 5 | import org.springframework.stereotype.Component; 6 | import org.springframework.web.reactive.function.server.ServerRequest; 7 | import org.springframework.web.server.ResponseStatusException; 8 | import top.itning.server.common.exception.BaseException; 9 | 10 | import java.util.LinkedHashMap; 11 | import java.util.Map; 12 | 13 | /** 14 | * 错误信息属性填充 15 | * 该类扩展{@link DefaultErrorAttributes}将错误信息封装在MAP中 16 | * 17 | * @author itning 18 | * @date 2019/4/29 18:11 19 | */ 20 | @Component 21 | public class GlobalErrorAttributes extends DefaultErrorAttributes { 22 | @Override 23 | public Map getErrorAttributes(ServerRequest request, boolean includeStackTrace) { 24 | Throwable error = getError(request); 25 | if (error instanceof BaseException) { 26 | BaseException baseException = (BaseException) error; 27 | Map errorAttributes = new LinkedHashMap<>(); 28 | errorAttributes.put("code", baseException.getCode().value()); 29 | errorAttributes.put("msg", baseException.getMsg()); 30 | errorAttributes.put("data", ""); 31 | return errorAttributes; 32 | } else if (error instanceof ResponseStatusException) { 33 | ResponseStatusException responseStatusException = (ResponseStatusException) error; 34 | Map errorAttributes = new LinkedHashMap<>(); 35 | errorAttributes.put("code", responseStatusException.getStatus().value()); 36 | errorAttributes.put("msg", responseStatusException.getMessage()); 37 | errorAttributes.put("data", ""); 38 | return errorAttributes; 39 | } else { 40 | Map errorAttributes = super.getErrorAttributes(request, includeStackTrace); 41 | errorAttributes.put("code", errorAttributes.getOrDefault("status", 404)); 42 | errorAttributes.put("msg", error.getMessage()); 43 | errorAttributes.put("data", ""); 44 | return errorAttributes; 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /shw-studentgroup/src/main/java/top/itning/server/shwstudentgroup/exception/JsonHttpMessageWriter.java: -------------------------------------------------------------------------------- 1 | package top.itning.server.shwstudentgroup.exception; 2 | 3 | import org.reactivestreams.Publisher; 4 | import org.springframework.core.ResolvableType; 5 | import org.springframework.http.MediaType; 6 | import org.springframework.http.ReactiveHttpOutputMessage; 7 | import org.springframework.http.codec.HttpMessageWriter; 8 | import org.springframework.lang.NonNull; 9 | import org.springframework.stereotype.Component; 10 | import reactor.core.publisher.Mono; 11 | 12 | import java.util.Collections; 13 | import java.util.List; 14 | import java.util.Map; 15 | 16 | /** 17 | * JSON格式消息写入器 18 | * 该类解析MAP将其转换为JSON 19 | * 20 | * @author itning 21 | * @date 2019/4/29 19:07 22 | */ 23 | @Component 24 | public class JsonHttpMessageWriter implements HttpMessageWriter> { 25 | @NonNull 26 | @Override 27 | public List getWritableMediaTypes() { 28 | return Collections.singletonList(MediaType.APPLICATION_JSON_UTF8); 29 | } 30 | 31 | @Override 32 | public boolean canWrite(@NonNull ResolvableType elementType, MediaType mediaType) { 33 | return MediaType.APPLICATION_JSON.includes(mediaType); 34 | } 35 | 36 | @NonNull 37 | @Override 38 | public Mono write(@NonNull Publisher> inputStream, 39 | @NonNull ResolvableType elementType, 40 | MediaType mediaType, 41 | @NonNull ReactiveHttpOutputMessage message, 42 | @NonNull Map hints) { 43 | return Mono.from(inputStream).flatMap(m -> message.writeWith(Mono.just(message.bufferFactory().wrap(transform2Json(m).getBytes())))); 44 | } 45 | 46 | private String transform2Json(Map sourceMap) { 47 | return "{" + 48 | "\"code\":" + 49 | sourceMap.getOrDefault("code", 500) + 50 | "," + 51 | "\"msg\":\"" + 52 | sourceMap.getOrDefault("msg", "") + 53 | "\"," + 54 | "\"data\":\"" + 55 | sourceMap.getOrDefault("data", "") + 56 | "\"}"; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /shw-work/src/main/java/top/itning/server/shwwork/exception/GlobalErrorWebExceptionHandler.java: -------------------------------------------------------------------------------- 1 | package top.itning.server.shwwork.exception; 2 | 3 | import org.springframework.boot.autoconfigure.web.ResourceProperties; 4 | import org.springframework.boot.autoconfigure.web.reactive.error.AbstractErrorWebExceptionHandler; 5 | import org.springframework.boot.web.reactive.error.ErrorAttributes; 6 | import org.springframework.context.ApplicationContext; 7 | import org.springframework.core.annotation.Order; 8 | import org.springframework.http.MediaType; 9 | import org.springframework.stereotype.Component; 10 | import org.springframework.web.reactive.function.BodyInserters; 11 | import org.springframework.web.reactive.function.server.*; 12 | import reactor.core.publisher.Mono; 13 | 14 | import java.util.Collections; 15 | import java.util.Map; 16 | 17 | /** 18 | * 全局错误异常处理器 19 | * 20 | * @author itning 21 | * @date 2019/4/29 18:13 22 | */ 23 | @Component 24 | @Order(-2) 25 | public class GlobalErrorWebExceptionHandler extends AbstractErrorWebExceptionHandler { 26 | public GlobalErrorWebExceptionHandler(JsonHttpMessageWriter jsonHttpMessageWriter, 27 | ErrorAttributes errorAttributes, 28 | ResourceProperties resourceProperties, 29 | ApplicationContext applicationContext) { 30 | super(errorAttributes, resourceProperties, applicationContext); 31 | setMessageWriters(Collections.singletonList(jsonHttpMessageWriter)); 32 | } 33 | 34 | @Override 35 | protected RouterFunction getRoutingFunction(ErrorAttributes errorAttributes) { 36 | return RouterFunctions.route( 37 | RequestPredicates.all(), this::renderErrorResponse); 38 | } 39 | 40 | private Mono renderErrorResponse( 41 | ServerRequest request) { 42 | Map errorPropertiesMap = getErrorAttributes(request, false); 43 | return ServerResponse 44 | .status(Integer.valueOf(errorPropertiesMap.getOrDefault("code", 500).toString())) 45 | .contentType(MediaType.APPLICATION_JSON_UTF8) 46 | .body(BodyInserters.fromObject(errorPropertiesMap)); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /shw-group/src/main/java/top/itning/server/shwgroup/exception/GlobalErrorWebExceptionHandler.java: -------------------------------------------------------------------------------- 1 | package top.itning.server.shwgroup.exception; 2 | 3 | import org.springframework.boot.autoconfigure.web.ResourceProperties; 4 | import org.springframework.boot.autoconfigure.web.reactive.error.AbstractErrorWebExceptionHandler; 5 | import org.springframework.boot.web.reactive.error.ErrorAttributes; 6 | import org.springframework.context.ApplicationContext; 7 | import org.springframework.core.annotation.Order; 8 | import org.springframework.http.MediaType; 9 | import org.springframework.stereotype.Component; 10 | import org.springframework.web.reactive.function.BodyInserters; 11 | import org.springframework.web.reactive.function.server.*; 12 | import reactor.core.publisher.Mono; 13 | 14 | import java.util.Collections; 15 | import java.util.Map; 16 | 17 | /** 18 | * 全局错误异常处理器 19 | * 20 | * @author itning 21 | * @date 2019/4/29 18:13 22 | */ 23 | @Component 24 | @Order(-2) 25 | public class GlobalErrorWebExceptionHandler extends AbstractErrorWebExceptionHandler { 26 | public GlobalErrorWebExceptionHandler(JsonHttpMessageWriter jsonHttpMessageWriter, 27 | ErrorAttributes errorAttributes, 28 | ResourceProperties resourceProperties, 29 | ApplicationContext applicationContext) { 30 | super(errorAttributes, resourceProperties, applicationContext); 31 | setMessageWriters(Collections.singletonList(jsonHttpMessageWriter)); 32 | } 33 | 34 | @Override 35 | protected RouterFunction getRoutingFunction(ErrorAttributes errorAttributes) { 36 | return RouterFunctions.route( 37 | RequestPredicates.all(), this::renderErrorResponse); 38 | } 39 | 40 | private Mono renderErrorResponse( 41 | ServerRequest request) { 42 | Map errorPropertiesMap = getErrorAttributes(request, false); 43 | return ServerResponse 44 | .status(Integer.valueOf(errorPropertiesMap.getOrDefault("code", 500).toString())) 45 | .contentType(MediaType.APPLICATION_JSON_UTF8) 46 | .body(BodyInserters.fromObject(errorPropertiesMap)); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /shw-notice/src/main/java/top/itning/server/shwnotice/exception/GlobalErrorWebExceptionHandler.java: -------------------------------------------------------------------------------- 1 | package top.itning.server.shwnotice.exception; 2 | 3 | import org.springframework.boot.autoconfigure.web.ResourceProperties; 4 | import org.springframework.boot.autoconfigure.web.reactive.error.AbstractErrorWebExceptionHandler; 5 | import org.springframework.boot.web.reactive.error.ErrorAttributes; 6 | import org.springframework.context.ApplicationContext; 7 | import org.springframework.core.annotation.Order; 8 | import org.springframework.http.MediaType; 9 | import org.springframework.stereotype.Component; 10 | import org.springframework.web.reactive.function.BodyInserters; 11 | import org.springframework.web.reactive.function.server.*; 12 | import reactor.core.publisher.Mono; 13 | 14 | import java.util.Collections; 15 | import java.util.Map; 16 | 17 | /** 18 | * 全局错误异常处理器 19 | * 20 | * @author itning 21 | * @date 2019/4/29 18:13 22 | */ 23 | @Component 24 | @Order(-2) 25 | public class GlobalErrorWebExceptionHandler extends AbstractErrorWebExceptionHandler { 26 | public GlobalErrorWebExceptionHandler(JsonHttpMessageWriter jsonHttpMessageWriter, 27 | ErrorAttributes errorAttributes, 28 | ResourceProperties resourceProperties, 29 | ApplicationContext applicationContext) { 30 | super(errorAttributes, resourceProperties, applicationContext); 31 | setMessageWriters(Collections.singletonList(jsonHttpMessageWriter)); 32 | } 33 | 34 | @Override 35 | protected RouterFunction getRoutingFunction(ErrorAttributes errorAttributes) { 36 | return RouterFunctions.route( 37 | RequestPredicates.all(), this::renderErrorResponse); 38 | } 39 | 40 | private Mono renderErrorResponse( 41 | ServerRequest request) { 42 | Map errorPropertiesMap = getErrorAttributes(request, false); 43 | return ServerResponse 44 | .status(Integer.valueOf(errorPropertiesMap.getOrDefault("code", 500).toString())) 45 | .contentType(MediaType.APPLICATION_JSON_UTF8) 46 | .body(BodyInserters.fromObject(errorPropertiesMap)); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /shw-upload/src/main/java/top/itning/server/shwupload/exception/GlobalErrorWebExceptionHandler.java: -------------------------------------------------------------------------------- 1 | package top.itning.server.shwupload.exception; 2 | 3 | import org.springframework.boot.autoconfigure.web.ResourceProperties; 4 | import org.springframework.boot.autoconfigure.web.reactive.error.AbstractErrorWebExceptionHandler; 5 | import org.springframework.boot.web.reactive.error.ErrorAttributes; 6 | import org.springframework.context.ApplicationContext; 7 | import org.springframework.core.annotation.Order; 8 | import org.springframework.http.MediaType; 9 | import org.springframework.stereotype.Component; 10 | import org.springframework.web.reactive.function.BodyInserters; 11 | import org.springframework.web.reactive.function.server.*; 12 | import reactor.core.publisher.Mono; 13 | 14 | import java.util.Collections; 15 | import java.util.Map; 16 | 17 | /** 18 | * 全局错误异常处理器 19 | * 20 | * @author itning 21 | * @date 2019/4/29 18:13 22 | */ 23 | @Component 24 | @Order(-2) 25 | public class GlobalErrorWebExceptionHandler extends AbstractErrorWebExceptionHandler { 26 | public GlobalErrorWebExceptionHandler(JsonHttpMessageWriter jsonHttpMessageWriter, 27 | ErrorAttributes errorAttributes, 28 | ResourceProperties resourceProperties, 29 | ApplicationContext applicationContext) { 30 | super(errorAttributes, resourceProperties, applicationContext); 31 | setMessageWriters(Collections.singletonList(jsonHttpMessageWriter)); 32 | } 33 | 34 | @Override 35 | protected RouterFunction getRoutingFunction(ErrorAttributes errorAttributes) { 36 | return RouterFunctions.route( 37 | RequestPredicates.all(), this::renderErrorResponse); 38 | } 39 | 40 | private Mono renderErrorResponse( 41 | ServerRequest request) { 42 | Map errorPropertiesMap = getErrorAttributes(request, false); 43 | return ServerResponse 44 | .status(Integer.valueOf(errorPropertiesMap.getOrDefault("code", 500).toString())) 45 | .contentType(MediaType.APPLICATION_JSON_UTF8) 46 | .body(BodyInserters.fromObject(errorPropertiesMap)); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /shw-security/src/main/java/top/itning/server/shwsecurity/exception/GlobalErrorWebExceptionHandler.java: -------------------------------------------------------------------------------- 1 | package top.itning.server.shwsecurity.exception; 2 | 3 | import org.springframework.boot.autoconfigure.web.ResourceProperties; 4 | import org.springframework.boot.autoconfigure.web.reactive.error.AbstractErrorWebExceptionHandler; 5 | import org.springframework.boot.web.reactive.error.ErrorAttributes; 6 | import org.springframework.context.ApplicationContext; 7 | import org.springframework.core.annotation.Order; 8 | import org.springframework.http.MediaType; 9 | import org.springframework.stereotype.Component; 10 | import org.springframework.web.reactive.function.BodyInserters; 11 | import org.springframework.web.reactive.function.server.*; 12 | import reactor.core.publisher.Mono; 13 | 14 | import java.util.Collections; 15 | import java.util.Map; 16 | 17 | /** 18 | * 全局错误异常处理器 19 | * 20 | * @author itning 21 | * @date 2019/4/29 18:13 22 | */ 23 | @Component 24 | @Order(-2) 25 | public class GlobalErrorWebExceptionHandler extends AbstractErrorWebExceptionHandler { 26 | public GlobalErrorWebExceptionHandler(JsonHttpMessageWriter jsonHttpMessageWriter, 27 | ErrorAttributes errorAttributes, 28 | ResourceProperties resourceProperties, 29 | ApplicationContext applicationContext) { 30 | super(errorAttributes, resourceProperties, applicationContext); 31 | setMessageWriters(Collections.singletonList(jsonHttpMessageWriter)); 32 | } 33 | 34 | @Override 35 | protected RouterFunction getRoutingFunction(ErrorAttributes errorAttributes) { 36 | return RouterFunctions.route( 37 | RequestPredicates.all(), this::renderErrorResponse); 38 | } 39 | 40 | private Mono renderErrorResponse( 41 | ServerRequest request) { 42 | Map errorPropertiesMap = getErrorAttributes(request, false); 43 | return ServerResponse 44 | .status(Integer.valueOf(errorPropertiesMap.getOrDefault("code", 500).toString())) 45 | .contentType(MediaType.APPLICATION_JSON_UTF8) 46 | .body(BodyInserters.fromObject(errorPropertiesMap)); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /shw-studentgroup/src/main/java/top/itning/server/shwstudentgroup/exception/GlobalErrorAttributes.java: -------------------------------------------------------------------------------- 1 | package top.itning.server.shwstudentgroup.exception; 2 | 3 | 4 | import org.springframework.boot.web.reactive.error.DefaultErrorAttributes; 5 | import org.springframework.stereotype.Component; 6 | import org.springframework.web.reactive.function.server.ServerRequest; 7 | import org.springframework.web.server.ResponseStatusException; 8 | import top.itning.server.common.exception.BaseException; 9 | 10 | import java.util.LinkedHashMap; 11 | import java.util.Map; 12 | 13 | /** 14 | * 错误信息属性填充 15 | * 该类扩展{@link DefaultErrorAttributes}将错误信息封装在MAP中 16 | * 17 | * @author itning 18 | * @date 2019/4/29 18:11 19 | */ 20 | @Component 21 | public class GlobalErrorAttributes extends DefaultErrorAttributes { 22 | @Override 23 | public Map getErrorAttributes(ServerRequest request, boolean includeStackTrace) { 24 | Throwable error = getError(request); 25 | if (error instanceof BaseException) { 26 | BaseException baseException = (BaseException) error; 27 | Map errorAttributes = new LinkedHashMap<>(); 28 | errorAttributes.put("code", baseException.getCode().value()); 29 | errorAttributes.put("msg", baseException.getMsg()); 30 | errorAttributes.put("data", ""); 31 | return errorAttributes; 32 | } else if (error instanceof ResponseStatusException) { 33 | ResponseStatusException responseStatusException = (ResponseStatusException) error; 34 | Map errorAttributes = new LinkedHashMap<>(); 35 | errorAttributes.put("code", responseStatusException.getStatus().value()); 36 | errorAttributes.put("msg", responseStatusException.getMessage()); 37 | errorAttributes.put("data", ""); 38 | return errorAttributes; 39 | } else { 40 | Map errorAttributes = super.getErrorAttributes(request, includeStackTrace); 41 | errorAttributes.put("code", errorAttributes.getOrDefault("status", 404)); 42 | errorAttributes.put("msg", error.getMessage()); 43 | errorAttributes.put("data", ""); 44 | return errorAttributes; 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /shw-studentgroup/src/main/java/top/itning/server/shwstudentgroup/exception/GlobalErrorWebExceptionHandler.java: -------------------------------------------------------------------------------- 1 | package top.itning.server.shwstudentgroup.exception; 2 | 3 | import org.springframework.boot.autoconfigure.web.ResourceProperties; 4 | import org.springframework.boot.autoconfigure.web.reactive.error.AbstractErrorWebExceptionHandler; 5 | import org.springframework.boot.web.reactive.error.ErrorAttributes; 6 | import org.springframework.context.ApplicationContext; 7 | import org.springframework.core.annotation.Order; 8 | import org.springframework.http.MediaType; 9 | import org.springframework.stereotype.Component; 10 | import org.springframework.web.reactive.function.BodyInserters; 11 | import org.springframework.web.reactive.function.server.*; 12 | import reactor.core.publisher.Mono; 13 | 14 | import java.util.Collections; 15 | import java.util.Map; 16 | 17 | /** 18 | * 全局错误异常处理器 19 | * 20 | * @author itning 21 | * @date 2019/4/29 18:13 22 | */ 23 | @Component 24 | @Order(-2) 25 | public class GlobalErrorWebExceptionHandler extends AbstractErrorWebExceptionHandler { 26 | public GlobalErrorWebExceptionHandler(JsonHttpMessageWriter jsonHttpMessageWriter, 27 | ErrorAttributes errorAttributes, 28 | ResourceProperties resourceProperties, 29 | ApplicationContext applicationContext) { 30 | super(errorAttributes, resourceProperties, applicationContext); 31 | setMessageWriters(Collections.singletonList(jsonHttpMessageWriter)); 32 | } 33 | 34 | @Override 35 | protected RouterFunction getRoutingFunction(ErrorAttributes errorAttributes) { 36 | return RouterFunctions.route( 37 | RequestPredicates.all(), this::renderErrorResponse); 38 | } 39 | 40 | private Mono renderErrorResponse( 41 | ServerRequest request) { 42 | Map errorPropertiesMap = getErrorAttributes(request, false); 43 | return ServerResponse 44 | .status(Integer.valueOf(errorPropertiesMap.getOrDefault("code", 500).toString())) 45 | .contentType(MediaType.APPLICATION_JSON_UTF8) 46 | .body(BodyInserters.fromObject(errorPropertiesMap)); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /shw-common/src/main/java/top/itning/server/common/util/Preconditions.java: -------------------------------------------------------------------------------- 1 | package top.itning.server.common.util; 2 | 3 | import org.springframework.http.HttpStatus; 4 | import org.springframework.web.reactive.function.server.ServerRequest; 5 | import top.itning.server.common.exception.PermissionsException; 6 | import top.itning.server.common.exception.RoleException; 7 | import top.itning.server.common.model.LoginUser; 8 | 9 | /** 10 | * 前置条件 11 | * 12 | * @author itning 13 | * @date 2019/4/30 10:36 14 | */ 15 | public class Preconditions { 16 | /** 17 | * 必须是学生身份 18 | * 19 | * @param request {@link ServerRequest} 20 | * @throws PermissionsException 如果角色为空 21 | * @throws RoleException 如果身份验证不通过 22 | */ 23 | public static void mustStudentLogin(ServerRequest request) { 24 | String userType = request.queryParam("userType").orElseThrow(() -> new PermissionsException("角色为空")); 25 | if (!userType.equals(LoginUser.STUDENT_USER)) { 26 | throw new RoleException("FORBIDDEN", HttpStatus.FORBIDDEN); 27 | } 28 | } 29 | 30 | /** 31 | * 必须是教师身份 32 | * 33 | * @param request {@link ServerRequest} 34 | * @throws PermissionsException 如果角色为空 35 | * @throws RoleException 如果身份验证不通过 36 | */ 37 | public static void mustTeacherLogin(ServerRequest request) { 38 | String userType = request.queryParam("userType").orElseThrow(() -> new PermissionsException("角色为空")); 39 | if (userType.equals(LoginUser.STUDENT_USER)) { 40 | throw new RoleException("FORBIDDEN", HttpStatus.FORBIDDEN); 41 | } 42 | } 43 | 44 | /** 45 | * 获取身份ID 46 | * 47 | * @param request {@link ServerRequest} 48 | * @return 身份ID 49 | * @throws PermissionsException 如果获取失败 50 | */ 51 | public static String getNo(ServerRequest request) { 52 | return request.queryParam("no").orElseThrow(() -> new PermissionsException("no is null")); 53 | } 54 | 55 | /** 56 | * 获取姓名 57 | * 58 | * @param request {@link ServerRequest} 59 | * @return 姓名 60 | * @throws PermissionsException 如果获取失败 61 | */ 62 | public static String getName(ServerRequest request) { 63 | return request.queryParam("name").orElseThrow(() -> new PermissionsException("name is null")); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /shw-studentgroup/src/main/java/top/itning/server/shwstudentgroup/service/StudentGroupService.java: -------------------------------------------------------------------------------- 1 | package top.itning.server.shwstudentgroup.service; 2 | 3 | import org.springframework.data.domain.Page; 4 | import reactor.core.publisher.Flux; 5 | import reactor.core.publisher.Mono; 6 | import top.itning.server.shwstudentgroup.dto.StudentGroupDTO; 7 | import top.itning.server.shwstudentgroup.entity.StudentGroup; 8 | 9 | import java.util.List; 10 | 11 | /** 12 | * 学生群组服务 13 | * 14 | * @author itning 15 | * @date 2019/4/30 18:14 16 | */ 17 | public interface StudentGroupService { 18 | /** 19 | * 学生加群 20 | * 21 | * @param code 邀请码 22 | * @param studentNumber 学号 23 | * @return 加入的群组 24 | */ 25 | Mono joinGroup(String code, String studentNumber); 26 | 27 | /** 28 | * 学生退出群组 29 | * 30 | * @param groupId 要退出的群组ID 31 | * @param studentId 学生ID 32 | * @return 操作完成后的信号 33 | */ 34 | Mono dropOutGroup(String groupId, String studentId); 35 | 36 | /** 37 | * 获取学生所在的所有群组 38 | * 39 | * @param studentNumber 学生学号 40 | * @param page 页码 41 | * @param size 每页数量 42 | * @return 群组分页信息 43 | */ 44 | Mono> findStudentAllGroups(String studentNumber, int page, int size); 45 | 46 | /** 47 | * 检查学生是否有群组 48 | * 49 | * @param studentNumber 学号 50 | * @return 如果有返回true 51 | */ 52 | Mono isHaveGroup(String studentNumber); 53 | 54 | /** 55 | * 根据学号查询学生群组中的群组ID信息 56 | * 57 | * @param studentNumber 学号 58 | * @return 群组ID集合 59 | */ 60 | Flux findGroupIdByStudentNumber(String studentNumber); 61 | 62 | /** 63 | * 根据GroupID查询群组内学生 64 | * 65 | * @param groupId 群组ID 66 | * @param page 页码 67 | * @param size 每页数量 68 | * @return 学生集合 69 | */ 70 | Mono> findAllByGroupID(String groupId, int page, int size); 71 | 72 | /** 73 | * 根据群ID计算数量 74 | * 75 | * @param groupId 群ID 76 | * @return 数量 77 | */ 78 | Mono countAllByGroupID(String groupId); 79 | 80 | /** 81 | * 教师删除群组 82 | * 83 | * @param groupId 群组ID 84 | * @return 操作完成后的信号 85 | */ 86 | Mono teacherDelGroupMessage(String groupId); 87 | } 88 | -------------------------------------------------------------------------------- /shw-work/src/main/java/top/itning/server/shwwork/client/entity/StudentGroup.java: -------------------------------------------------------------------------------- 1 | package top.itning.server.shwwork.client.entity; 2 | 3 | import java.util.Date; 4 | 5 | /** 6 | * 学生群组 7 | * 8 | * @author itning 9 | * @date 2019/4/30 17:47 10 | */ 11 | public class StudentGroup { 12 | /** 13 | * studentNumber|groupID 14 | */ 15 | private String id; 16 | /** 17 | * StudentGroup ID 18 | */ 19 | private String studentNumber; 20 | /** 21 | * Group ID 22 | */ 23 | private String groupID; 24 | /** 25 | * 创建时间 26 | */ 27 | private Date gmtCreate; 28 | /** 29 | * 更新时间 30 | */ 31 | private Date gmtModified; 32 | 33 | public StudentGroup() { 34 | } 35 | 36 | public StudentGroup(String studentNumber, String groupID) { 37 | this.id = studentNumber + "|" + groupID; 38 | this.studentNumber = studentNumber; 39 | this.groupID = groupID; 40 | Date date = new Date(); 41 | this.gmtCreate = date; 42 | this.gmtModified = date; 43 | } 44 | 45 | public String getId() { 46 | return id; 47 | } 48 | 49 | public void setId(String id) { 50 | this.id = id; 51 | } 52 | 53 | public String getStudentNumber() { 54 | return studentNumber; 55 | } 56 | 57 | public void setStudentNumber(String studentNumber) { 58 | this.studentNumber = studentNumber; 59 | } 60 | 61 | public String getGroupID() { 62 | return groupID; 63 | } 64 | 65 | public void setGroupID(String groupID) { 66 | this.groupID = groupID; 67 | } 68 | 69 | public Date getGmtCreate() { 70 | return gmtCreate; 71 | } 72 | 73 | public void setGmtCreate(Date gmtCreate) { 74 | this.gmtCreate = gmtCreate; 75 | } 76 | 77 | public Date getGmtModified() { 78 | return gmtModified; 79 | } 80 | 81 | public void setGmtModified(Date gmtModified) { 82 | this.gmtModified = gmtModified; 83 | } 84 | 85 | @Override 86 | public String toString() { 87 | return "StudentGroup{" + 88 | "id='" + id + '\'' + 89 | ", studentNumber='" + studentNumber + '\'' + 90 | ", groupID='" + groupID + '\'' + 91 | ", gmtCreate=" + gmtCreate + 92 | ", gmtModified=" + gmtModified + 93 | '}'; 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /shw-group/src/test/java/top/itning/server/shwgroup/repository/GroupRepositoryTest.java: -------------------------------------------------------------------------------- 1 | package top.itning.server.shwgroup.repository; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.boot.test.context.SpringBootTest; 7 | import org.springframework.http.HttpStatus; 8 | import org.springframework.test.context.junit4.SpringRunner; 9 | import reactor.core.publisher.Mono; 10 | import top.itning.server.common.exception.NoSuchFiledValueException; 11 | import top.itning.server.shwgroup.entity.Group; 12 | 13 | import java.util.Date; 14 | import java.util.UUID; 15 | 16 | import static org.junit.Assert.assertEquals; 17 | import static org.junit.Assert.assertNotNull; 18 | 19 | @SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection") 20 | @RunWith(SpringRunner.class) 21 | @SpringBootTest 22 | public class GroupRepositoryTest { 23 | @Autowired 24 | private GroupRepository groupRepository; 25 | 26 | @Test 27 | public void testSave() { 28 | String s = UUID.randomUUID().toString(); 29 | Group group = new Group(); 30 | group.setId(s); 31 | group.setGroupName("setGroupName"); 32 | group.setTeacherName("setTeacherName"); 33 | group.setTeacherNumber("setTeacherNumber"); 34 | group.setCode("setCode"); 35 | group.setGmtCreate(new Date()); 36 | group.setGmtModified(new Date()); 37 | Mono save = groupRepository.save(group); 38 | Group block = save.block(); 39 | assertNotNull(block); 40 | assertEquals(block.getId(), s); 41 | System.out.println(save.block()); 42 | } 43 | 44 | @Test 45 | public void testDel() { 46 | groupRepository.deleteAll().block(); 47 | Long block = groupRepository.findAll().count().block(); 48 | assertNotNull(block); 49 | long count = block; 50 | assertEquals(count, 0L); 51 | } 52 | 53 | @Test 54 | public void testUpOne() { 55 | groupRepository.findById("aa8d328832-3e1c-4423-810d-4e1f789d5548") 56 | .switchIfEmpty(Mono.error(new NoSuchFiledValueException("123", HttpStatus.ACCEPTED))) 57 | .flatMap(group -> { 58 | System.out.println(1); 59 | group.setGroupName("11"); 60 | return groupRepository.save(group); 61 | }) 62 | .block(); 63 | } 64 | } -------------------------------------------------------------------------------- /shw-gateway/src/main/java/top/itning/server/shwgateway/filter/CorsFilter.java: -------------------------------------------------------------------------------- 1 | package top.itning.server.shwgateway.filter; 2 | 3 | import com.netflix.zuul.ZuulFilter; 4 | import com.netflix.zuul.context.RequestContext; 5 | import com.netflix.zuul.exception.ZuulException; 6 | import org.springframework.http.HttpMethod; 7 | import org.springframework.stereotype.Component; 8 | 9 | import javax.servlet.http.HttpServletRequest; 10 | import javax.servlet.http.HttpServletResponse; 11 | 12 | import static org.springframework.cloud.netflix.zuul.filters.support.FilterConstants.PRE_DECORATION_FILTER_ORDER; 13 | import static org.springframework.cloud.netflix.zuul.filters.support.FilterConstants.PRE_TYPE; 14 | import static org.springframework.http.HttpHeaders.*; 15 | 16 | /** 17 | * 跨域请求过滤器 18 | * 该过滤器过滤{@link HttpMethod#OPTIONS}方法 19 | * 返回准许跨域的响应 20 | * 21 | * @author itning 22 | * @date 2019/5/2 19:57 23 | */ 24 | @Component 25 | public class CorsFilter extends ZuulFilter { 26 | @Override 27 | public String filterType() { 28 | return PRE_TYPE; 29 | } 30 | 31 | @Override 32 | public int filterOrder() { 33 | return PRE_DECORATION_FILTER_ORDER - 2; 34 | } 35 | 36 | @Override 37 | public boolean shouldFilter() { 38 | RequestContext requestContext = RequestContext.getCurrentContext(); 39 | HttpServletRequest request = requestContext.getRequest(); 40 | return HttpMethod.OPTIONS.matches(request.getMethod()); 41 | } 42 | 43 | @Override 44 | public Object run() throws ZuulException { 45 | RequestContext requestContext = RequestContext.getCurrentContext(); 46 | allowCors(requestContext.getResponse(), requestContext.getRequest()); 47 | requestContext.setSendZuulResponse(false); 48 | return null; 49 | } 50 | 51 | /** 52 | * 允许跨域(不管客户端地址是什么,全部允许) 53 | * 54 | * @param resp {@link HttpServletResponse} 55 | * @param req {@link HttpServletRequest} 56 | */ 57 | private void allowCors(HttpServletResponse resp, HttpServletRequest req) { 58 | String origin = req.getHeader(ORIGIN); 59 | resp.setHeader(ACCESS_CONTROL_ALLOW_CREDENTIALS, "true"); 60 | resp.setHeader(ACCESS_CONTROL_ALLOW_ORIGIN, origin); 61 | resp.setHeader(ACCESS_CONTROL_ALLOW_METHODS, "POST,GET,OPTIONS,DELETE,PUT,PATCH"); 62 | resp.setHeader(ACCESS_CONTROL_ALLOW_HEADERS, req.getHeader(ACCESS_CONTROL_REQUEST_HEADERS)); 63 | resp.setIntHeader(ACCESS_CONTROL_MAX_AGE, 2592000); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /shw-group/src/main/java/top/itning/server/shwgroup/service/GroupService.java: -------------------------------------------------------------------------------- 1 | package top.itning.server.shwgroup.service; 2 | 3 | import org.springframework.data.domain.Page; 4 | import reactor.core.publisher.Flux; 5 | import reactor.core.publisher.Mono; 6 | import top.itning.server.common.exception.NoSuchFiledValueException; 7 | import top.itning.server.shwgroup.entity.Group; 8 | 9 | /** 10 | * 群组服务 11 | * 12 | * @author itning 13 | * @date 2019/4/29 12:27 14 | */ 15 | public interface GroupService { 16 | /** 17 | * 创建新群组 18 | * 19 | * @param groupName 新建群组名 20 | * @param teacherId 教师ID 21 | * @param teacherName 教师姓名 22 | * @return 返回创建后群组 23 | */ 24 | Mono createGroup(String groupName, String teacherName, String teacherId); 25 | 26 | /** 27 | * 删除已有群组 28 | * 29 | * @param teacherId 教师ID 30 | * @param groupId 群组ID 31 | * @return 操作完成后的信号 32 | * @throws NoSuchFiledValueException 当教师或者群组不存在时 33 | */ 34 | Mono deleteGroup(String teacherId, String groupId); 35 | 36 | /** 37 | * 修改已有群组名 38 | * 39 | * @param teacherId 教师ID 40 | * @param groupId 需要修改的群组ID 41 | * @param newName 新群组名 42 | * @return 修改后的群组 43 | * @throws NoSuchFiledValueException Id不存在 44 | */ 45 | Mono updateGroupName(String teacherId, String groupId, String newName); 46 | 47 | /** 48 | * 检查教师是否有群组 49 | * 50 | * @param teacherNumber 教师ID 51 | * @return 有返回true 52 | */ 53 | Mono isHaveAnyGroup(String teacherNumber); 54 | 55 | /** 56 | * 分页获取教师群组 57 | * 58 | * @param teacherNumber 教师ID 59 | * @param page 页码 60 | * @param size 每页数量 61 | * @return 教师群组 62 | */ 63 | Mono> findTeacherAllGroups(String teacherNumber, int page, int size); 64 | 65 | /** 66 | * 获取某个群组信息 67 | * 68 | * @param groupId 群组ID 69 | * @return 群组 70 | */ 71 | Mono findOneGroupById(String groupId); 72 | 73 | /** 74 | * 通过教师ID查询群组 75 | * 76 | * @param teacherNumber 教师ID 77 | * @return 群组 78 | */ 79 | Flux findByTeacherNumber(String teacherNumber); 80 | 81 | /** 82 | * 根据群ID查询群名称 83 | * 84 | * @param groupId 群ID 85 | * @return 群名称 86 | */ 87 | Mono findGroupNameByGroupId(String groupId); 88 | 89 | /** 90 | * 根据群ID查询群 91 | * 92 | * @param groupId 群ID 93 | * @return 教师名 94 | */ 95 | Mono findTeacherNameById(String groupId); 96 | } 97 | -------------------------------------------------------------------------------- /shw-hystrix-dashboard/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | org.springframework.boot 7 | spring-boot-starter-parent 8 | 2.3.0.RELEASE 9 | 10 | 11 | top.itning.server 12 | shw-hystrix-dashboard 13 | 0.0.1-SNAPSHOT 14 | shw-hystrix-dashboard 15 | Demo project for Spring Boot 16 | 17 | 18 | 1.8 19 | Hoxton.SR4 20 | 21 | 22 | 23 | 24 | org.springframework.boot 25 | spring-boot-starter-actuator 26 | 27 | 28 | org.springframework.cloud 29 | spring-cloud-starter-netflix-hystrix-dashboard 30 | 31 | 32 | org.springframework.cloud 33 | spring-cloud-starter-netflix-turbine 34 | 35 | 36 | 37 | org.springframework.boot 38 | spring-boot-starter-test 39 | test 40 | 41 | 42 | 43 | 44 | 45 | 46 | org.springframework.cloud 47 | spring-cloud-dependencies 48 | ${spring-cloud.version} 49 | pom 50 | import 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | org.springframework.boot 59 | spring-boot-maven-plugin 60 | 61 | 62 | 63 | 64 | 65 | -------------------------------------------------------------------------------- /shw-studentgroup/src/main/java/top/itning/server/shwstudentgroup/handler/StudentGroupHandler.java: -------------------------------------------------------------------------------- 1 | package top.itning.server.shwstudentgroup.handler; 2 | 3 | import org.apache.commons.lang.math.NumberUtils; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.http.HttpStatus; 6 | import org.springframework.lang.NonNull; 7 | import org.springframework.stereotype.Component; 8 | import org.springframework.web.reactive.function.server.ServerRequest; 9 | import org.springframework.web.reactive.function.server.ServerResponse; 10 | import reactor.core.publisher.Mono; 11 | import top.itning.server.common.exception.NullFiledException; 12 | import top.itning.server.shwstudentgroup.service.StudentGroupService; 13 | 14 | import static top.itning.server.common.model.RestModel.*; 15 | import static top.itning.server.common.util.Preconditions.getNo; 16 | import static top.itning.server.common.util.Preconditions.mustStudentLogin; 17 | 18 | /** 19 | * 学生群组处理器 20 | * 21 | * @author itning 22 | * @date 2019/4/30 19:37 23 | */ 24 | @Component 25 | public class StudentGroupHandler { 26 | private final StudentGroupService studentGroupService; 27 | 28 | @Autowired 29 | public StudentGroupHandler(StudentGroupService studentGroupService) { 30 | this.studentGroupService = studentGroupService; 31 | } 32 | 33 | @NonNull 34 | public Mono addGroup(ServerRequest request) { 35 | mustStudentLogin(request); 36 | return request.formData().flatMap(m -> Mono.justOrEmpty(m.getFirst("code"))) 37 | .switchIfEmpty(Mono.error(new NullFiledException("邀请码不能为空", HttpStatus.BAD_REQUEST))) 38 | .flatMap(s -> created(studentGroupService.joinGroup(s, getNo(request)), "加入成功")); 39 | } 40 | 41 | @NonNull 42 | public Mono dropOutGroup(ServerRequest request) { 43 | mustStudentLogin(request); 44 | String groupId = request.pathVariable("groupId"); 45 | return studentGroupService.dropOutGroup(groupId, getNo(request)).thenReturn(noContent()).flatMap(s -> s); 46 | } 47 | 48 | @NonNull 49 | public Mono getAllGroups(ServerRequest request) { 50 | mustStudentLogin(request); 51 | int page = NumberUtils.toInt(request.queryParam("page").orElse("0")); 52 | int size = NumberUtils.toInt(request.queryParam("size").orElse("20"), 1); 53 | return ok(studentGroupService.findStudentAllGroups(getNo(request), page, size)); 54 | } 55 | 56 | @NonNull 57 | public Mono isStudentJoinAnyStudentGroup(ServerRequest request) { 58 | mustStudentLogin(request); 59 | return ok(studentGroupService.isHaveGroup(getNo(request))); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /shw-studentgroup/src/main/java/top/itning/server/shwstudentgroup/dto/StudentGroupDTO.java: -------------------------------------------------------------------------------- 1 | package top.itning.server.shwstudentgroup.dto; 2 | 3 | import java.util.Date; 4 | 5 | /** 6 | * 群组群组DTO 7 | * 8 | * @author itning 9 | * @date 2019/4/30 20:59 10 | */ 11 | public class StudentGroupDTO { 12 | /** 13 | * 群组ID 14 | */ 15 | private String id; 16 | /** 17 | * 群组名 18 | */ 19 | private String groupName; 20 | /** 21 | * 教师名 22 | */ 23 | private String teacherName; 24 | /** 25 | * 教师序号 26 | */ 27 | private String teacherNumber; 28 | /** 29 | * 邀请码 30 | */ 31 | private String code; 32 | /** 33 | * 创建时间 34 | */ 35 | private Date gmtCreate; 36 | /** 37 | * 更新时间 38 | */ 39 | private Date gmtModified; 40 | 41 | public String getId() { 42 | return id; 43 | } 44 | 45 | public void setId(String id) { 46 | this.id = id; 47 | } 48 | 49 | public String getGroupName() { 50 | return groupName; 51 | } 52 | 53 | public void setGroupName(String groupName) { 54 | this.groupName = groupName; 55 | } 56 | 57 | public String getTeacherName() { 58 | return teacherName; 59 | } 60 | 61 | public void setTeacherName(String teacherName) { 62 | this.teacherName = teacherName; 63 | } 64 | 65 | public String getTeacherNumber() { 66 | return teacherNumber; 67 | } 68 | 69 | public void setTeacherNumber(String teacherNumber) { 70 | this.teacherNumber = teacherNumber; 71 | } 72 | 73 | public String getCode() { 74 | return code; 75 | } 76 | 77 | public void setCode(String code) { 78 | this.code = code; 79 | } 80 | 81 | public Date getGmtCreate() { 82 | return gmtCreate; 83 | } 84 | 85 | public void setGmtCreate(Date gmtCreate) { 86 | this.gmtCreate = gmtCreate; 87 | } 88 | 89 | public Date getGmtModified() { 90 | return gmtModified; 91 | } 92 | 93 | public void setGmtModified(Date gmtModified) { 94 | this.gmtModified = gmtModified; 95 | } 96 | 97 | @Override 98 | public String toString() { 99 | return "StudentGroupDTO{" + 100 | "id='" + id + '\'' + 101 | ", groupName='" + groupName + '\'' + 102 | ", teacherName='" + teacherName + '\'' + 103 | ", teacherNumber='" + teacherNumber + '\'' + 104 | ", code='" + code + '\'' + 105 | ", gmtCreate=" + gmtCreate + 106 | ", gmtModified=" + gmtModified + 107 | '}'; 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /shw-work/src/main/java/top/itning/server/shwwork/router/WorkRouters.java: -------------------------------------------------------------------------------- 1 | package top.itning.server.shwwork.router; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.Configuration; 6 | import org.springframework.web.reactive.function.server.RouterFunction; 7 | import org.springframework.web.reactive.function.server.ServerResponse; 8 | import top.itning.server.shwwork.entity.Work; 9 | import top.itning.server.shwwork.handler.WorkHandler; 10 | import top.itning.server.shwwork.service.WorkService; 11 | 12 | import static org.springframework.web.reactive.function.server.RequestPredicates.all; 13 | import static org.springframework.web.reactive.function.server.RequestPredicates.path; 14 | import static org.springframework.web.reactive.function.server.RouterFunctions.nest; 15 | import static org.springframework.web.reactive.function.server.RouterFunctions.route; 16 | 17 | /** 18 | * 作业路由 19 | * 20 | * @author itning 21 | * @date 2019/5/1 9:42 22 | */ 23 | @Configuration 24 | public class WorkRouters { 25 | private final WorkService workService; 26 | 27 | @Autowired 28 | public WorkRouters(WorkService workService) { 29 | this.workService = workService; 30 | } 31 | 32 | @Bean 33 | RouterFunction userRouter(WorkHandler workHandler) { 34 | return nest( 35 | all(), 36 | route() 37 | .GET("/un_done", workHandler::getAllUnDoneWorks) 38 | .GET("/done", workHandler::getAllDoneWorks) 39 | .GET("/works", workHandler::getTeacherWorks) 40 | .GET("/{groupId}", workHandler::getTeacherWork) 41 | .GET("/detail/{workId}", workHandler::getTeacherWorkDetails) 42 | .POST("/", workHandler::addWork) 43 | .PATCH("/enabled/{workId}/{enabled}", workHandler::updateWorkEnabled) 44 | .PATCH("/name/{workId}/{workName}", workHandler::updateWorkName) 45 | .DELETE("/{workId}", workHandler::deleteWork) 46 | .build()) 47 | .andNest( 48 | path("/internal"), 49 | route() 50 | .GET("/getAllWorkInfoByGroupId/{id}", serverRequest -> ServerResponse.ok().body(workService.getAllWorkInfoByGroupId(serverRequest.pathVariable("id")), Work.class)) 51 | .GET("/getOneWorkById/{id}", serverRequest -> ServerResponse.ok().body(workService.getOneWorkById(serverRequest.pathVariable("id")), Work.class)) 52 | .build() 53 | ); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /shw-file/src/main/java/top/itning/server/shwfile/controller/FileController.java: -------------------------------------------------------------------------------- 1 | package top.itning.server.shwfile.controller; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.http.HttpStatus; 5 | import org.springframework.http.ResponseEntity; 6 | import org.springframework.web.bind.annotation.*; 7 | import org.springframework.web.multipart.MultipartFile; 8 | import top.itning.server.common.exception.RoleException; 9 | import top.itning.server.common.model.LoginUser; 10 | import top.itning.server.shwfile.service.FileService; 11 | 12 | import javax.servlet.http.HttpServletResponse; 13 | 14 | /** 15 | * 文件控制器 16 | * 17 | * @author itning 18 | * @date 2019/5/3 11:14 19 | */ 20 | @RestController 21 | public class FileController { 22 | private final FileService fileService; 23 | 24 | @Autowired 25 | public FileController(FileService fileService) { 26 | this.fileService = fileService; 27 | } 28 | 29 | /** 30 | * 学生上传作业 31 | * 32 | * @param workId 作业ID 33 | * @param file 文件 34 | * @return ResponseEntity 35 | */ 36 | @PostMapping("/up/{workId}") 37 | public ResponseEntity uploadWork(@RequestParam("no") String studentNumber, 38 | @RequestParam("userType") String userType, 39 | @PathVariable String workId, 40 | @RequestParam("file") MultipartFile file) { 41 | if (!userType.equals(LoginUser.STUDENT_USER)) { 42 | throw new RoleException("FORBIDDEN", HttpStatus.FORBIDDEN); 43 | } 44 | fileService.uploadFile(file, studentNumber, workId); 45 | return ResponseEntity.status(HttpStatus.CREATED).build(); 46 | } 47 | 48 | /** 49 | * 学生作业下载 50 | * 51 | * @param range 请求头 52 | * @param studentNumber 学号 53 | * @param workId 作业ID 54 | * @param response {@link HttpServletResponse} 55 | */ 56 | @GetMapping("/down/{studentNumber}/{workId}") 57 | public void downloadFile(@RequestHeader(required = false) String range, 58 | @PathVariable String studentNumber, 59 | @PathVariable String workId, 60 | HttpServletResponse response) { 61 | fileService.downFile(studentNumber, workId, range, response); 62 | } 63 | 64 | 65 | /** 66 | * 直接下载所有 67 | * 68 | * @param workId 作业ID 69 | * @param response {@link HttpServletResponse} 70 | */ 71 | @GetMapping("/down_now/{workId}") 72 | public void downloadAllFileNow(@PathVariable String workId, 73 | HttpServletResponse response) { 74 | fileService.downFiles(workId, response); 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /shw-group/src/main/java/top/itning/server/shwgroup/router/GroupRouters.java: -------------------------------------------------------------------------------- 1 | package top.itning.server.shwgroup.router; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.Configuration; 6 | import org.springframework.web.reactive.function.server.RouterFunction; 7 | import org.springframework.web.reactive.function.server.ServerResponse; 8 | import top.itning.server.shwgroup.entity.Group; 9 | import top.itning.server.shwgroup.handler.GroupHandler; 10 | import top.itning.server.shwgroup.service.GroupService; 11 | 12 | import static org.springframework.web.reactive.function.server.RequestPredicates.all; 13 | import static org.springframework.web.reactive.function.server.RequestPredicates.path; 14 | import static org.springframework.web.reactive.function.server.RouterFunctions.nest; 15 | import static org.springframework.web.reactive.function.server.RouterFunctions.route; 16 | 17 | /** 18 | * 群组路由 19 | * 20 | * @author itning 21 | * @date 2019/4/29 14:26 22 | */ 23 | @Configuration 24 | public class GroupRouters { 25 | private final GroupService groupService; 26 | 27 | @Autowired 28 | public GroupRouters(GroupService groupService) { 29 | this.groupService = groupService; 30 | } 31 | 32 | @Bean 33 | RouterFunction userRouter(GroupHandler groupHandler) { 34 | return nest( 35 | all(), 36 | route() 37 | .POST("/", groupHandler::addGroup) 38 | .GET("/", groupHandler::getTeacherCreateGroups) 39 | .GET("/exist", groupHandler::isTeacherHaveAnyGroup) 40 | .DELETE("/{id}", groupHandler::deleteGroup) 41 | .PATCH("/{id}/{name}", groupHandler::updateGroupName) 42 | .build() 43 | ) 44 | .andNest( 45 | path("/internal"), 46 | route() 47 | .GET("/findOneGroupById/{id}", serverRequest -> ServerResponse.ok().body(groupService.findOneGroupById(serverRequest.pathVariable("id")), Group.class)) 48 | .GET("/findByTeacherNumber/{id}", serverRequest -> ServerResponse.ok().body(groupService.findByTeacherNumber(serverRequest.pathVariable("id")), Group.class)) 49 | .GET("/findGroupNameByGroupId/{id}", serverRequest -> ServerResponse.ok().body(groupService.findGroupNameByGroupId(serverRequest.pathVariable("id")), String.class)) 50 | .GET("/findTeacherNameById/{id}", serverRequest -> ServerResponse.ok().body(groupService.findTeacherNameById(serverRequest.pathVariable("id")), String.class)) 51 | .build() 52 | ); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /shw-upload/src/main/java/top/itning/server/shwupload/router/UploadRouters.java: -------------------------------------------------------------------------------- 1 | package top.itning.server.shwupload.router; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.Configuration; 6 | import org.springframework.http.HttpStatus; 7 | import org.springframework.web.reactive.function.server.RouterFunction; 8 | import org.springframework.web.reactive.function.server.ServerResponse; 9 | import top.itning.server.shwupload.entity.Upload; 10 | import top.itning.server.shwupload.handler.UploadHandler; 11 | import top.itning.server.shwupload.service.UploadService; 12 | 13 | import static org.springframework.web.reactive.function.server.RequestPredicates.all; 14 | import static org.springframework.web.reactive.function.server.RequestPredicates.path; 15 | import static org.springframework.web.reactive.function.server.RouterFunctions.nest; 16 | import static org.springframework.web.reactive.function.server.RouterFunctions.route; 17 | 18 | /** 19 | * 上传路由 20 | * 21 | * @author itning 22 | * @date 2019/5/2 16:53 23 | */ 24 | @Configuration 25 | public class UploadRouters { 26 | private final UploadService uploadService; 27 | 28 | @Autowired 29 | public UploadRouters(UploadService uploadService) { 30 | this.uploadService = uploadService; 31 | } 32 | 33 | @Bean 34 | RouterFunction userRouter(UploadHandler uploadHandler) { 35 | return nest( 36 | all(), 37 | route() 38 | .GET("/{workId}", uploadHandler::getUpLoadInfoByWorkId) 39 | .DELETE("/{workId}", uploadHandler::deleteUploadWork) 40 | .GET("/review/{studentId}/{workId}", uploadHandler::getReviewInfoByWorkId) 41 | .GET("/review/{workId}", uploadHandler::getReviewInfoByWorkId) 42 | .build()) 43 | .andNest( 44 | path("/internal"), 45 | route() 46 | .GET("/existsById/{id}", serverRequest -> ServerResponse.ok().body(uploadService.existsById(serverRequest.pathVariable("id")), Boolean.class)) 47 | .GET("/findOneById/{id}", serverRequest -> ServerResponse.ok().body(uploadService.findOneById(serverRequest.pathVariable("id")), Upload.class)) 48 | .GET("/getAllUploadByWorkId/{id}", serverRequest -> ServerResponse.ok().body(uploadService.getAllUploadByWorkId(serverRequest.pathVariable("id")), Upload.class)) 49 | .POST("/", serverRequest -> ServerResponse.status(HttpStatus.CREATED).body(serverRequest.bodyToMono(Upload.class).flatMap(uploadService::save), Upload.class)) 50 | .build() 51 | ); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /shw-gateway/src/main/java/top/itning/server/shwgateway/util/JwtUtils.java: -------------------------------------------------------------------------------- 1 | package top.itning.server.shwgateway.util; 2 | 3 | import com.fasterxml.jackson.core.JsonProcessingException; 4 | import com.fasterxml.jackson.databind.ObjectMapper; 5 | import io.jsonwebtoken.*; 6 | import org.springframework.http.HttpStatus; 7 | import top.itning.server.common.exception.CasException; 8 | import top.itning.server.common.model.LoginUser; 9 | 10 | import java.util.Date; 11 | 12 | /** 13 | * Jwt 工具类 14 | * 15 | * @author itning 16 | */ 17 | public final class JwtUtils { 18 | private static final String PRIVATE_KEY = "hxcshw"; 19 | private static final String LOGIN_USER = "loginUser"; 20 | private static final String DEFAULT_STR = "null"; 21 | private static final ObjectMapper MAPPER = new ObjectMapper(); 22 | 23 | private JwtUtils() { 24 | 25 | } 26 | 27 | public static String buildJwt(Object o) throws JsonProcessingException { 28 | return Jwts.builder() 29 | //SECRET_KEY是加密算法对应的密钥,这里使用额是HS256加密算法 30 | .signWith(SignatureAlgorithm.HS256, PRIVATE_KEY) 31 | //expTime是过期时间 32 | .setExpiration(new Date(System.currentTimeMillis() + 60 * 60 * 1000)) 33 | .claim(LOGIN_USER, MAPPER.writeValueAsString(o)) 34 | //令牌的发行者 35 | .setIssuer("itning") 36 | .compact(); 37 | } 38 | 39 | public static LoginUser getLoginUser(String jwt) { 40 | if (DEFAULT_STR.equals(jwt)) { 41 | throw new CasException("请先登陆", HttpStatus.UNAUTHORIZED); 42 | } 43 | try { 44 | //解析JWT字符串中的数据,并进行最基础的验证 45 | Claims claims = Jwts.parser() 46 | //SECRET_KEY是加密算法对应的密钥,jjwt可以自动判断机密算法 47 | .setSigningKey(PRIVATE_KEY) 48 | //jwt是JWT字符串 49 | .parseClaimsJws(jwt) 50 | .getBody(); 51 | //获取自定义字段key 52 | String loginUserJson = claims.get(LOGIN_USER, String.class); 53 | LoginUser loginUser = MAPPER.readValue(loginUserJson, LoginUser.class); 54 | //判断自定义字段是否正确 55 | if (loginUser == null) { 56 | throw new CasException("登陆失败", HttpStatus.UNAUTHORIZED); 57 | } else { 58 | return loginUser; 59 | } 60 | //在解析JWT字符串时,如果密钥不正确,将会解析失败,抛出SignatureException异常,说明该JWT字符串是伪造的 61 | //在解析JWT字符串时,如果‘过期时间字段’已经早于当前时间,将会抛出ExpiredJwtException异常,说明本次请求已经失效 62 | } catch (ExpiredJwtException e) { 63 | throw new CasException("登陆超时", HttpStatus.UNAUTHORIZED); 64 | } catch (SignatureException e) { 65 | throw new CasException("凭据错误", HttpStatus.BAD_REQUEST); 66 | } catch (Exception e) { 67 | throw new CasException("登陆失败", HttpStatus.UNAUTHORIZED); 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /shw-group/src/test/java/top/itning/server/shwgroup/service/GroupServiceTest.java: -------------------------------------------------------------------------------- 1 | package top.itning.server.shwgroup.service; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.boot.test.context.SpringBootTest; 7 | import org.springframework.data.domain.Page; 8 | import org.springframework.test.context.junit4.SpringRunner; 9 | import reactor.core.publisher.Mono; 10 | import top.itning.server.shwgroup.entity.Group; 11 | 12 | import java.util.UUID; 13 | 14 | import static org.junit.Assert.*; 15 | 16 | @SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection") 17 | @RunWith(SpringRunner.class) 18 | @SpringBootTest 19 | public class GroupServiceTest { 20 | @Autowired 21 | private GroupService groupService; 22 | 23 | @Test 24 | public void testCreateGroup() { 25 | Mono group = groupService.createGroup("测试创建群组1", "测试教师名1", "0002"); 26 | Group block = group.block(); 27 | assertNotNull(block); 28 | assertEquals(block.getGroupName(), "测试创建群组1"); 29 | assertEquals(block.getTeacherName(), "测试教师名1"); 30 | assertEquals(block.getTeacherNumber(), "0002"); 31 | } 32 | 33 | @Test 34 | public void testDeleteGroup() { 35 | boolean no = true; 36 | try { 37 | groupService.deleteGroup("0001", "bc960acc2dc9423ea40f66ec1d21f5dc").block(); 38 | groupService.deleteGroup("0002", UUID.randomUUID().toString()).block(); 39 | } catch (Exception e) { 40 | System.out.println(e.getMessage()); 41 | no = false; 42 | } 43 | assertFalse(no); 44 | } 45 | 46 | @Test 47 | public void testUpGroupName() { 48 | groupService.updateGroupName("setTeacherNumber", "a8d328832-3e1c-4423-810d-4e1f789d5548", "新群组名").block(); 49 | } 50 | 51 | @Test 52 | public void testIsHaveAnyGroup() { 53 | assertTrue(groupService.isHaveAnyGroup("setTeacherNumber").block()); 54 | assertFalse(groupService.isHaveAnyGroup(UUID.randomUUID().toString()).block()); 55 | } 56 | 57 | @Test 58 | public void testFindTeacherAllGroups() { 59 | Mono> pageMono = groupService.findTeacherAllGroups("0002", 0, 1); 60 | Page page = pageMono.block(); 61 | System.out.println(page.getTotalElements()); 62 | System.out.println(page.getTotalPages()); 63 | System.out.println(page.getNumber()); 64 | System.out.println(page.getNumberOfElements()); 65 | System.out.println(page.getSize()); 66 | page.getContent().forEach(System.out::println); 67 | } 68 | 69 | @Test 70 | public void testFindGroupNameByGroupId() { 71 | String groupId = groupService.findGroupNameByGroupId("2a867ab2efc04d5f912b0e9cd25f0c85").block(); 72 | System.out.println(groupId); 73 | } 74 | } -------------------------------------------------------------------------------- /shw-security/src/main/java/top/itning/server/shwsecurity/util/JwtUtils.java: -------------------------------------------------------------------------------- 1 | package top.itning.server.shwsecurity.util; 2 | 3 | import com.fasterxml.jackson.core.JsonProcessingException; 4 | import com.fasterxml.jackson.databind.ObjectMapper; 5 | import io.jsonwebtoken.*; 6 | import org.springframework.http.HttpStatus; 7 | import top.itning.server.common.exception.CasException; 8 | import top.itning.server.common.model.LoginUser; 9 | 10 | import java.util.Date; 11 | 12 | /** 13 | * Jwt 工具类 14 | * 15 | * @author itning 16 | */ 17 | public final class JwtUtils { 18 | private static final String PRIVATE_KEY = "hxcshw"; 19 | private static final String LOGIN_USER = "loginUser"; 20 | private static final String DEFAULT_STR = "null"; 21 | private static final ObjectMapper MAPPER = new ObjectMapper(); 22 | 23 | private JwtUtils() { 24 | 25 | } 26 | 27 | public static String buildJwt(Object o) throws JsonProcessingException { 28 | return Jwts.builder() 29 | //SECRET_KEY是加密算法对应的密钥,这里使用额是HS256加密算法 30 | .signWith(SignatureAlgorithm.HS256, PRIVATE_KEY) 31 | //expTime是过期时间 32 | .setExpiration(new Date(System.currentTimeMillis() + 60 * 60 * 1000)) 33 | .claim(LOGIN_USER, MAPPER.writeValueAsString(o)) 34 | //令牌的发行者 35 | .setIssuer("itning") 36 | .compact(); 37 | } 38 | 39 | public static LoginUser getLoginUser(String jwt) { 40 | if (DEFAULT_STR.equals(jwt)) { 41 | throw new CasException("请先登陆", HttpStatus.UNAUTHORIZED); 42 | } 43 | try { 44 | //解析JWT字符串中的数据,并进行最基础的验证 45 | Claims claims = Jwts.parser() 46 | //SECRET_KEY是加密算法对应的密钥,jjwt可以自动判断机密算法 47 | .setSigningKey(PRIVATE_KEY) 48 | //jwt是JWT字符串 49 | .parseClaimsJws(jwt) 50 | .getBody(); 51 | //获取自定义字段key 52 | String loginUserJson = claims.get(LOGIN_USER, String.class); 53 | LoginUser loginUser = MAPPER.readValue(loginUserJson, LoginUser.class); 54 | //判断自定义字段是否正确 55 | if (loginUser == null) { 56 | throw new CasException("登陆失败", HttpStatus.UNAUTHORIZED); 57 | } else { 58 | return loginUser; 59 | } 60 | //在解析JWT字符串时,如果密钥不正确,将会解析失败,抛出SignatureException异常,说明该JWT字符串是伪造的 61 | //在解析JWT字符串时,如果‘过期时间字段’已经早于当前时间,将会抛出ExpiredJwtException异常,说明本次请求已经失效 62 | } catch (ExpiredJwtException e) { 63 | throw new CasException("登陆超时", HttpStatus.UNAUTHORIZED); 64 | } catch (SignatureException e) { 65 | throw new CasException("凭据错误", HttpStatus.BAD_REQUEST); 66 | } catch (Exception e) { 67 | throw new CasException("登陆失败", HttpStatus.UNAUTHORIZED); 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /shw-studentgroup/src/main/java/top/itning/server/shwstudentgroup/entity/StudentGroup.java: -------------------------------------------------------------------------------- 1 | package top.itning.server.shwstudentgroup.entity; 2 | 3 | import org.springframework.data.annotation.Id; 4 | import org.springframework.data.mongodb.core.index.Indexed; 5 | import org.springframework.data.mongodb.core.mapping.Document; 6 | import org.springframework.data.mongodb.core.mapping.Field; 7 | 8 | import java.util.Date; 9 | 10 | /** 11 | * 学生群组 12 | * 13 | * @author itning 14 | * @date 2019/4/30 17:47 15 | */ 16 | @Document(collection = "student_group") 17 | public class StudentGroup { 18 | /** 19 | * studentNumber|groupID 20 | */ 21 | @Id 22 | private String id; 23 | /** 24 | * StudentGroup ID 25 | */ 26 | @Indexed 27 | @Field("student_number") 28 | private String studentNumber; 29 | /** 30 | * Group ID 31 | */ 32 | @Indexed 33 | @Field("group_id") 34 | private String groupID; 35 | /** 36 | * 创建时间 37 | */ 38 | @Field("gmt_create") 39 | private Date gmtCreate; 40 | /** 41 | * 更新时间 42 | */ 43 | @Field("gmt_modified") 44 | private Date gmtModified; 45 | 46 | public StudentGroup() { 47 | } 48 | 49 | public StudentGroup(String studentNumber, String groupID) { 50 | this.id = studentNumber + "|" + groupID; 51 | this.studentNumber = studentNumber; 52 | this.groupID = groupID; 53 | Date date = new Date(); 54 | this.gmtCreate = date; 55 | this.gmtModified = date; 56 | } 57 | 58 | public String getId() { 59 | return id; 60 | } 61 | 62 | public void setId(String id) { 63 | this.id = id; 64 | } 65 | 66 | public String getStudentNumber() { 67 | return studentNumber; 68 | } 69 | 70 | public void setStudentNumber(String studentNumber) { 71 | this.studentNumber = studentNumber; 72 | } 73 | 74 | public String getGroupID() { 75 | return groupID; 76 | } 77 | 78 | public void setGroupID(String groupID) { 79 | this.groupID = groupID; 80 | } 81 | 82 | public Date getGmtCreate() { 83 | return gmtCreate; 84 | } 85 | 86 | public void setGmtCreate(Date gmtCreate) { 87 | this.gmtCreate = gmtCreate; 88 | } 89 | 90 | public Date getGmtModified() { 91 | return gmtModified; 92 | } 93 | 94 | public void setGmtModified(Date gmtModified) { 95 | this.gmtModified = gmtModified; 96 | } 97 | 98 | @Override 99 | public String toString() { 100 | return "StudentGroup{" + 101 | "id='" + id + '\'' + 102 | ", studentNumber='" + studentNumber + '\'' + 103 | ", groupID='" + groupID + '\'' + 104 | ", gmtCreate=" + gmtCreate + 105 | ", gmtModified=" + gmtModified + 106 | '}'; 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /shw-group/src/main/java/top/itning/server/shwgroup/handler/GroupHandler.java: -------------------------------------------------------------------------------- 1 | package top.itning.server.shwgroup.handler; 2 | 3 | import org.apache.commons.lang.math.NumberUtils; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.http.HttpStatus; 6 | import org.springframework.lang.NonNull; 7 | import org.springframework.stereotype.Component; 8 | import org.springframework.web.reactive.function.server.ServerRequest; 9 | import org.springframework.web.reactive.function.server.ServerResponse; 10 | import reactor.core.publisher.Mono; 11 | import top.itning.server.common.exception.NullFiledException; 12 | import top.itning.server.shwgroup.entity.Group; 13 | import top.itning.server.shwgroup.service.GroupService; 14 | 15 | import static top.itning.server.common.model.RestModel.noContent; 16 | import static top.itning.server.common.model.RestModel.ok; 17 | import static top.itning.server.common.util.Preconditions.*; 18 | 19 | /** 20 | * 群组请求处理器 21 | * 22 | * @author itning 23 | * @date 2019/4/29 14:08 24 | */ 25 | @Component 26 | public class GroupHandler { 27 | private final GroupService groupService; 28 | 29 | @Autowired 30 | public GroupHandler(GroupService groupService) { 31 | this.groupService = groupService; 32 | } 33 | 34 | @NonNull 35 | public Mono addGroup(ServerRequest request) { 36 | mustTeacherLogin(request); 37 | return request.formData() 38 | .flatMap(m -> Mono.justOrEmpty(m.getFirst("groupName"))) 39 | .switchIfEmpty(Mono.error(new NullFiledException("群组名不能为空", HttpStatus.BAD_REQUEST))) 40 | .flatMap(s -> ServerResponse.status(HttpStatus.CREATED).body(groupService.createGroup(s, getName(request), getNo(request)), Group.class)); 41 | } 42 | 43 | @NonNull 44 | public Mono isTeacherHaveAnyGroup(ServerRequest request) { 45 | mustTeacherLogin(request); 46 | return ok(groupService.isHaveAnyGroup(getNo(request))); 47 | } 48 | 49 | @NonNull 50 | public Mono deleteGroup(ServerRequest request) { 51 | mustTeacherLogin(request); 52 | return groupService.deleteGroup(getNo(request), request.pathVariable("id")).thenReturn(noContent()).flatMap(s -> s); 53 | } 54 | 55 | @NonNull 56 | public Mono updateGroupName(ServerRequest request) { 57 | mustTeacherLogin(request); 58 | return groupService.updateGroupName(getNo(request), request.pathVariable("id"), request.pathVariable("name")).thenReturn(noContent()).flatMap(s -> s); 59 | } 60 | 61 | @NonNull 62 | public Mono getTeacherCreateGroups(ServerRequest request) { 63 | mustTeacherLogin(request); 64 | int page = NumberUtils.toInt(request.queryParam("page").orElse("0")); 65 | int size = NumberUtils.toInt(request.queryParam("size").orElse("20"), 1); 66 | return ok(groupService.findTeacherAllGroups(getNo(request), page, size)); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /shw-gateway/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | org.springframework.boot 7 | spring-boot-starter-parent 8 | 2.3.0.RELEASE 9 | 10 | 11 | top.itning.server 12 | shw-gateway 13 | 0.0.1-SNAPSHOT 14 | shw-gateway 15 | Demo project for Spring Boot 16 | 17 | 18 | 1.8 19 | Hoxton.SR4 20 | 0.9.1 21 | 22 | 23 | 24 | 25 | org.springframework.cloud 26 | spring-cloud-starter-netflix-eureka-client 27 | 28 | 29 | org.springframework.cloud 30 | spring-cloud-starter-netflix-zuul 31 | 32 | 33 | org.springframework.boot 34 | spring-boot-starter-actuator 35 | 36 | 37 | 38 | io.jsonwebtoken 39 | jjwt 40 | ${jjwt.version} 41 | 42 | 43 | 44 | top.itning.server 45 | shw-common 46 | 1.0-SNAPSHOT 47 | 48 | 49 | 50 | org.springframework.boot 51 | spring-boot-starter-test 52 | test 53 | 54 | 55 | 56 | 57 | 58 | 59 | org.springframework.cloud 60 | spring-cloud-dependencies 61 | ${spring-cloud.version} 62 | pom 63 | import 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | org.springframework.boot 72 | spring-boot-maven-plugin 73 | 74 | 75 | 76 | 77 | 78 | -------------------------------------------------------------------------------- /shw-studentgroup/src/main/java/top/itning/server/shwstudentgroup/client/entrty/Group.java: -------------------------------------------------------------------------------- 1 | package top.itning.server.shwstudentgroup.client.entrty; 2 | 3 | import java.util.Date; 4 | 5 | /** 6 | * 群组 7 | * 8 | * @author itning 9 | * @date 2019/4/29 11:43 10 | */ 11 | public class Group { 12 | /** 13 | * 群组ID 14 | */ 15 | private String id; 16 | /** 17 | * 群组名 18 | */ 19 | private String groupName; 20 | /** 21 | * 教师名 22 | */ 23 | private String teacherName; 24 | /** 25 | * 教师序号 26 | */ 27 | private String teacherNumber; 28 | /** 29 | * 邀请码 30 | */ 31 | private String code; 32 | /** 33 | * 创建时间 34 | */ 35 | private Date gmtCreate; 36 | /** 37 | * 更新时间 38 | */ 39 | private Date gmtModified; 40 | 41 | public Group() { 42 | } 43 | 44 | public Group(String id, String groupName, String teacherName, String teacherNumber, String code, Date gmtCreate, Date gmtModified) { 45 | this.id = id; 46 | this.groupName = groupName; 47 | this.teacherName = teacherName; 48 | this.teacherNumber = teacherNumber; 49 | this.code = code; 50 | this.gmtCreate = gmtCreate; 51 | this.gmtModified = gmtModified; 52 | } 53 | 54 | public String getId() { 55 | return id; 56 | } 57 | 58 | public void setId(String id) { 59 | this.id = id; 60 | } 61 | 62 | public String getGroupName() { 63 | return groupName; 64 | } 65 | 66 | public void setGroupName(String groupName) { 67 | this.groupName = groupName; 68 | } 69 | 70 | public String getTeacherName() { 71 | return teacherName; 72 | } 73 | 74 | public void setTeacherName(String teacherName) { 75 | this.teacherName = teacherName; 76 | } 77 | 78 | public String getTeacherNumber() { 79 | return teacherNumber; 80 | } 81 | 82 | public void setTeacherNumber(String teacherNumber) { 83 | this.teacherNumber = teacherNumber; 84 | } 85 | 86 | public String getCode() { 87 | return code; 88 | } 89 | 90 | public void setCode(String code) { 91 | this.code = code; 92 | } 93 | 94 | public Date getGmtCreate() { 95 | return gmtCreate; 96 | } 97 | 98 | public void setGmtCreate(Date gmtCreate) { 99 | this.gmtCreate = gmtCreate; 100 | } 101 | 102 | public Date getGmtModified() { 103 | return gmtModified; 104 | } 105 | 106 | public void setGmtModified(Date gmtModified) { 107 | this.gmtModified = gmtModified; 108 | } 109 | 110 | @Override 111 | public String toString() { 112 | return "Group{" + 113 | "id='" + id + '\'' + 114 | ", groupName='" + groupName + '\'' + 115 | ", teacherName='" + teacherName + '\'' + 116 | ", teacherNumber='" + teacherNumber + '\'' + 117 | ", code='" + code + '\'' + 118 | ", gmtCreate=" + gmtCreate + 119 | ", gmtModified=" + gmtModified + 120 | '}'; 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /shw-work/src/main/java/top/itning/server/shwwork/client/entity/Group.java: -------------------------------------------------------------------------------- 1 | package top.itning.server.shwwork.client.entity; 2 | 3 | import java.util.Date; 4 | import java.util.UUID; 5 | 6 | /** 7 | * 群组 8 | * 9 | * @author itning 10 | * @date 2019/4/29 11:43 11 | */ 12 | public class Group { 13 | /** 14 | * 群组ID 15 | */ 16 | private String id; 17 | /** 18 | * 群组名 19 | */ 20 | private String groupName; 21 | /** 22 | * 教师名 23 | */ 24 | private String teacherName; 25 | /** 26 | * 教师序号 27 | */ 28 | private String teacherNumber; 29 | /** 30 | * 邀请码 31 | */ 32 | private String code; 33 | /** 34 | * 创建时间 35 | */ 36 | private Date gmtCreate; 37 | /** 38 | * 更新时间 39 | */ 40 | private Date gmtModified; 41 | 42 | public Group() { 43 | } 44 | 45 | public Group(String groupName, String teacherName, String teacherNumber) { 46 | String id = UUID.randomUUID().toString().replace("-", ""); 47 | this.id = id; 48 | this.groupName = groupName; 49 | this.teacherName = teacherName; 50 | this.teacherNumber = teacherNumber; 51 | this.code = id; 52 | Date date = new Date(); 53 | this.gmtCreate = date; 54 | this.gmtModified = date; 55 | } 56 | 57 | public String getId() { 58 | return id; 59 | } 60 | 61 | public void setId(String id) { 62 | this.id = id; 63 | } 64 | 65 | public String getGroupName() { 66 | return groupName; 67 | } 68 | 69 | public void setGroupName(String groupName) { 70 | this.groupName = groupName; 71 | } 72 | 73 | public String getTeacherName() { 74 | return teacherName; 75 | } 76 | 77 | public void setTeacherName(String teacherName) { 78 | this.teacherName = teacherName; 79 | } 80 | 81 | public String getTeacherNumber() { 82 | return teacherNumber; 83 | } 84 | 85 | public void setTeacherNumber(String teacherNumber) { 86 | this.teacherNumber = teacherNumber; 87 | } 88 | 89 | public String getCode() { 90 | return code; 91 | } 92 | 93 | public void setCode(String code) { 94 | this.code = code; 95 | } 96 | 97 | public Date getGmtCreate() { 98 | return gmtCreate; 99 | } 100 | 101 | public void setGmtCreate(Date gmtCreate) { 102 | this.gmtCreate = gmtCreate; 103 | } 104 | 105 | public Date getGmtModified() { 106 | return gmtModified; 107 | } 108 | 109 | public void setGmtModified(Date gmtModified) { 110 | this.gmtModified = gmtModified; 111 | } 112 | 113 | @Override 114 | public String toString() { 115 | return "Group{" + 116 | "id='" + id + '\'' + 117 | ", groupName='" + groupName + '\'' + 118 | ", teacherName='" + teacherName + '\'' + 119 | ", teacherNumber='" + teacherNumber + '\'' + 120 | ", code='" + code + '\'' + 121 | ", gmtCreate=" + gmtCreate + 122 | ", gmtModified=" + gmtModified + 123 | '}'; 124 | } 125 | } 126 | -------------------------------------------------------------------------------- /shw-work/src/main/java/top/itning/server/shwwork/dto/WorkDTO.java: -------------------------------------------------------------------------------- 1 | package top.itning.server.shwwork.dto; 2 | 3 | import java.util.Date; 4 | 5 | /** 6 | * 作业DTO 7 | * 8 | * @author itning 9 | * @date 2019/5/1 9:47 10 | */ 11 | public class WorkDTO { 12 | /** 13 | * 作业ID,标识唯一作业 14 | */ 15 | private String id; 16 | /** 17 | * 群组ID,该作业所属群 18 | */ 19 | private String groupId; 20 | /** 21 | * 作业名 22 | */ 23 | private String workName; 24 | /** 25 | * 作业启用状态 26 | */ 27 | private Boolean enabled = true; 28 | /** 29 | * 文件名规范 30 | */ 31 | private String fileNameFormat; 32 | /** 33 | * 创建时间 34 | */ 35 | private Date gmtCreate; 36 | /** 37 | * 更新时间 38 | */ 39 | private Date gmtModified; 40 | /** 41 | * 群组名 42 | */ 43 | private String groupName; 44 | /** 45 | * 教师名 46 | */ 47 | private String teacherName; 48 | 49 | public String getId() { 50 | return id; 51 | } 52 | 53 | public void setId(String id) { 54 | this.id = id; 55 | } 56 | 57 | public String getGroupId() { 58 | return groupId; 59 | } 60 | 61 | public void setGroupId(String groupId) { 62 | this.groupId = groupId; 63 | } 64 | 65 | public String getWorkName() { 66 | return workName; 67 | } 68 | 69 | public void setWorkName(String workName) { 70 | this.workName = workName; 71 | } 72 | 73 | public Boolean getEnabled() { 74 | return enabled; 75 | } 76 | 77 | public void setEnabled(Boolean enabled) { 78 | this.enabled = enabled; 79 | } 80 | 81 | public String getFileNameFormat() { 82 | return fileNameFormat; 83 | } 84 | 85 | public void setFileNameFormat(String fileNameFormat) { 86 | this.fileNameFormat = fileNameFormat; 87 | } 88 | 89 | public Date getGmtCreate() { 90 | return gmtCreate; 91 | } 92 | 93 | public void setGmtCreate(Date gmtCreate) { 94 | this.gmtCreate = gmtCreate; 95 | } 96 | 97 | public Date getGmtModified() { 98 | return gmtModified; 99 | } 100 | 101 | public void setGmtModified(Date gmtModified) { 102 | this.gmtModified = gmtModified; 103 | } 104 | 105 | public String getGroupName() { 106 | return groupName; 107 | } 108 | 109 | public void setGroupName(String groupName) { 110 | this.groupName = groupName; 111 | } 112 | 113 | public String getTeacherName() { 114 | return teacherName; 115 | } 116 | 117 | public void setTeacherName(String teacherName) { 118 | this.teacherName = teacherName; 119 | } 120 | 121 | @Override 122 | public String toString() { 123 | return "WorkDTO{" + 124 | "id='" + id + '\'' + 125 | ", groupId='" + groupId + '\'' + 126 | ", workName='" + workName + '\'' + 127 | ", enabled=" + enabled + 128 | ", fileNameFormat='" + fileNameFormat + '\'' + 129 | ", gmtCreate=" + gmtCreate + 130 | ", gmtModified=" + gmtModified + 131 | ", groupName='" + groupName + '\'' + 132 | ", teacherName='" + teacherName + '\'' + 133 | '}'; 134 | } 135 | } 136 | -------------------------------------------------------------------------------- /shw-studentgroup/src/main/java/top/itning/server/shwstudentgroup/router/StudentGroupRouters.java: -------------------------------------------------------------------------------- 1 | package top.itning.server.shwstudentgroup.router; 2 | 3 | import org.apache.commons.lang.math.NumberUtils; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.context.annotation.Bean; 6 | import org.springframework.context.annotation.Configuration; 7 | import org.springframework.core.ParameterizedTypeReference; 8 | import org.springframework.web.reactive.function.server.RouterFunction; 9 | import org.springframework.web.reactive.function.server.ServerResponse; 10 | import top.itning.server.shwstudentgroup.entity.StudentGroup; 11 | import top.itning.server.shwstudentgroup.handler.StudentGroupHandler; 12 | import top.itning.server.shwstudentgroup.service.StudentGroupService; 13 | 14 | import java.util.List; 15 | 16 | import static org.springframework.web.reactive.function.server.RequestPredicates.all; 17 | import static org.springframework.web.reactive.function.server.RequestPredicates.path; 18 | import static org.springframework.web.reactive.function.server.RouterFunctions.nest; 19 | import static org.springframework.web.reactive.function.server.RouterFunctions.route; 20 | 21 | /** 22 | * 学生群组路由 23 | * 24 | * @author itning 25 | * @date 2019/4/30 19:38 26 | */ 27 | @Configuration 28 | public class StudentGroupRouters { 29 | private final StudentGroupService studentGroupService; 30 | 31 | @Autowired 32 | public StudentGroupRouters(StudentGroupService studentGroupService) { 33 | this.studentGroupService = studentGroupService; 34 | } 35 | 36 | @Bean 37 | RouterFunction userRouter(StudentGroupHandler studentGroupHandler) { 38 | return nest( 39 | all(), 40 | route() 41 | .POST("/", studentGroupHandler::addGroup) 42 | .DELETE("/{groupId}", studentGroupHandler::dropOutGroup) 43 | .GET("/", studentGroupHandler::getAllGroups) 44 | .GET("/exist", studentGroupHandler::isStudentJoinAnyStudentGroup) 45 | .build()) 46 | .andNest( 47 | path("/internal"), 48 | route() 49 | .GET("/findGroupIdByStudentNumber/{studentNumber}", serverRequest -> ServerResponse.ok().body(studentGroupService.findGroupIdByStudentNumber(serverRequest.pathVariable("studentNumber")).collectList(), new ParameterizedTypeReference>() { 50 | })) 51 | .GET("/findAllByGroupID/{groupId}/{page}/{size}", serverRequest -> { 52 | int page = NumberUtils.toInt(serverRequest.pathVariable("page")); 53 | int size = NumberUtils.toInt(serverRequest.pathVariable("size"), 1); 54 | return ServerResponse.ok().body(studentGroupService.findAllByGroupID(serverRequest.pathVariable("groupId"), page, size), new ParameterizedTypeReference>() { 55 | }); 56 | }) 57 | .GET("/countAllByGroupID/{groupId}", serverRequest -> ServerResponse.ok().body(studentGroupService.countAllByGroupID(serverRequest.pathVariable("groupId")), Long.class)) 58 | .build() 59 | ); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /shw-file/src/main/java/top/itning/server/shwfile/client/entity/Work.java: -------------------------------------------------------------------------------- 1 | package top.itning.server.shwfile.client.entity; 2 | 3 | import java.util.Date; 4 | import java.util.UUID; 5 | 6 | /** 7 | * 作业信息 8 | * 9 | * @author itning 10 | * @date 2019/5/1 9:36 11 | */ 12 | public class Work implements Cloneable { 13 | /** 14 | * 作业ID,标识唯一作业 15 | */ 16 | private String id; 17 | /** 18 | * 群组ID,该作业所属群 19 | */ 20 | private String groupId; 21 | /** 22 | * 作业名 23 | */ 24 | private String workName; 25 | /** 26 | * 作业启用状态 27 | */ 28 | private boolean enabled = true; 29 | /** 30 | * 文件名规范 31 | */ 32 | private String fileNameFormat; 33 | /** 34 | * 创建时间 35 | */ 36 | private Date gmtCreate; 37 | /** 38 | * 更新时间 39 | */ 40 | private Date gmtModified; 41 | 42 | public Work() { 43 | } 44 | 45 | public Work(String groupId, String workName, boolean enabled, String fileNameFormat) { 46 | this.id = UUID.randomUUID().toString().replace("-", ""); 47 | this.groupId = groupId; 48 | this.workName = workName; 49 | this.enabled = enabled; 50 | this.fileNameFormat = fileNameFormat; 51 | Date date = new Date(); 52 | this.gmtCreate = date; 53 | this.gmtModified = date; 54 | } 55 | 56 | public String getId() { 57 | return id; 58 | } 59 | 60 | public void setId(String id) { 61 | this.id = id; 62 | } 63 | 64 | public String getGroupId() { 65 | return groupId; 66 | } 67 | 68 | public void setGroupId(String groupId) { 69 | this.groupId = groupId; 70 | } 71 | 72 | public String getWorkName() { 73 | return workName; 74 | } 75 | 76 | public void setWorkName(String workName) { 77 | this.workName = workName; 78 | } 79 | 80 | public boolean isEnabled() { 81 | return enabled; 82 | } 83 | 84 | public void setEnabled(boolean enabled) { 85 | this.enabled = enabled; 86 | } 87 | 88 | public String getFileNameFormat() { 89 | return fileNameFormat; 90 | } 91 | 92 | public void setFileNameFormat(String fileNameFormat) { 93 | this.fileNameFormat = fileNameFormat; 94 | } 95 | 96 | public Date getGmtCreate() { 97 | return gmtCreate; 98 | } 99 | 100 | public void setGmtCreate(Date gmtCreate) { 101 | this.gmtCreate = gmtCreate; 102 | } 103 | 104 | public Date getGmtModified() { 105 | return gmtModified; 106 | } 107 | 108 | public void setGmtModified(Date gmtModified) { 109 | this.gmtModified = gmtModified; 110 | } 111 | 112 | @Override 113 | public String toString() { 114 | return "Work{" + 115 | "id='" + id + '\'' + 116 | ", groupId='" + groupId + '\'' + 117 | ", workName='" + workName + '\'' + 118 | ", enabled=" + enabled + 119 | ", fileNameFormat='" + fileNameFormat + '\'' + 120 | ", gmtCreate=" + gmtCreate + 121 | ", gmtModified=" + gmtModified + 122 | '}'; 123 | } 124 | 125 | public Work clones() { 126 | try { 127 | return (Work) this.clone(); 128 | } catch (CloneNotSupportedException e) { 129 | e.printStackTrace(); 130 | return new Work(); 131 | } 132 | } 133 | } 134 | --------------------------------------------------------------------------------