├── .gitignore ├── .mvn └── wrapper │ ├── MavenWrapperDownloader.java │ ├── maven-wrapper.jar │ └── maven-wrapper.properties ├── README.md ├── image └── login.png ├── log ├── error │ ├── error.2020-08-12.log │ ├── error.2020-08-13.log │ ├── error.2020-08-14.log │ ├── error.2020-08-15.log │ ├── error.2020-08-16.log │ ├── error.2020-08-22.log │ ├── error.2020-08-23.log │ ├── error.2020-08-24.log │ ├── error.2020-08-25.log │ ├── error.2020-08-26.log │ ├── error.2020-08-27.log │ ├── error.2020-09-01.log │ ├── error.2020-09-13.log │ ├── error.2020-09-14.log │ ├── error.2020-09-15.log │ ├── error.2020-09-16.log │ ├── error.2020-09-17.log │ ├── error.2020-09-18.log │ ├── error.2020-09-19.log │ ├── error.2020-09-20.log │ ├── error.2020-09-21.log │ ├── error.2020-09-22.log │ ├── error.2020-09-23.log │ ├── error.2020-09-24.log │ ├── error.2020-09-25.log │ ├── error.2020-09-27.log │ ├── error.2020-10-09.log │ ├── error.2020-10-10.log │ ├── error.2020-10-12.log │ ├── error.2020-10-13.log │ ├── error.2020-10-14.log │ ├── error.2020-10-15.log │ ├── error.2020-10-16.log │ ├── error.2020-10-19.log │ ├── error.2020-10-20.log │ ├── error.2020-10-21.log │ ├── error.2020-10-29.log │ └── error.2020-11-30.log └── info │ ├── info.2020-08-12.log │ ├── info.2020-08-13.log │ ├── info.2020-08-14.log │ ├── info.2020-08-15.log │ ├── info.2020-08-16.log │ ├── info.2020-08-22.log │ ├── info.2020-08-23.log │ ├── info.2020-08-24.log │ ├── info.2020-08-25.log │ ├── info.2020-08-26.log │ ├── info.2020-08-27.log │ ├── info.2020-09-01.log │ ├── info.2020-09-13.log │ ├── info.2020-09-14.log │ ├── info.2020-09-15.log │ ├── info.2020-09-16.log │ ├── info.2020-09-17.log │ ├── info.2020-09-18.log │ ├── info.2020-09-19.log │ ├── info.2020-09-20.log │ ├── info.2020-09-21.log │ ├── info.2020-09-22.log │ ├── info.2020-09-23.log │ ├── info.2020-09-24.log │ ├── info.2020-09-25.log │ ├── info.2020-09-27.log │ ├── info.2020-10-09.log │ ├── info.2020-10-10.log │ ├── info.2020-10-12.log │ ├── info.2020-10-13.log │ ├── info.2020-10-14.log │ ├── info.2020-10-15.log │ ├── info.2020-10-16.log │ ├── info.2020-10-19.log │ ├── info.2020-10-20.log │ ├── info.2020-10-21.log │ ├── info.2020-10-29.log │ └── info.2020-11-30.log ├── mvnw ├── mvnw.cmd ├── pom.xml ├── spy.log ├── sql ├── codeworld-vue-system.sql └── codeworld_quartz.sql └── src └── main ├── docker └── Dockerfile ├── java └── com │ └── codeworld │ └── fc │ ├── CodeworldVueSystemApplication.java │ ├── common │ ├── annotation │ │ ├── ControllerEndpoint.java │ │ └── FcEndPoint.java │ ├── aspect │ │ ├── AspectSupport.java │ │ └── LogAspect.java │ ├── authority │ │ ├── GrantedAuthorityImpl.java │ │ ├── JWTToken.java │ │ ├── JWTUtil.java │ │ ├── JwtAuthenticationProvider.java │ │ ├── JwtAuthenticationToken.java │ │ ├── JwtUserDetails.java │ │ └── UserDetailServiceImpl.java │ ├── base │ │ └── PageQuery.java │ ├── config │ │ ├── FCCorsConfiguration.java │ │ ├── MyWebConfig.java │ │ ├── P6spySqlFormatConfigure.java │ │ ├── SecurityConfig.java │ │ └── SwaggerConfig.java │ ├── enums │ │ ├── HttpFcStatus.java │ │ ├── HttpMsg.java │ │ └── StatusEnum.java │ ├── exception │ │ └── FCException.java │ ├── handler │ │ └── ExceptionHand.java │ └── response │ │ ├── DataResponse.java │ │ └── FCResponse.java │ ├── job │ ├── config │ │ └── ScheduleConfigure.java │ ├── controller │ │ ├── JobController.java │ │ └── JobLogController.java │ ├── dto │ │ └── JobRequestDTO.java │ ├── entity │ │ ├── Job.java │ │ └── JobLog.java │ ├── mapper │ │ ├── JobLogMapper.java │ │ └── JobMapper.java │ ├── service │ │ ├── JobLogService.java │ │ ├── JobService.java │ │ └── impl │ │ │ ├── JobLogServiceImpl.java │ │ │ └── JobServiceImpl.java │ ├── task │ │ └── TestTask.java │ ├── util │ │ ├── ScheduleJob.java │ │ ├── ScheduleRunnable.java │ │ └── ScheduleUtils.java │ └── vo │ │ ├── JobLogSearchVO.java │ │ └── JobSearchVO.java │ ├── monitor │ ├── controller │ │ ├── ActiveUserController.java │ │ ├── HttpTraceController.java │ │ └── LoginLogController.java │ ├── endpoint │ │ ├── FcHttpTraceEndPoint.java │ │ └── RemoteHttpTraceRepository.java │ ├── entity │ │ ├── FcHttpTrace.java │ │ └── LoginLog.java │ ├── listener │ │ └── ActiveUserListener.java │ ├── mapper │ │ └── LoginLogMapper.java │ ├── service │ │ ├── ActiveUserService.java │ │ ├── HttpTraceService.java │ │ ├── LoginLogService.java │ │ └── impl │ │ │ ├── ActiveUserServiceImpl.java │ │ │ ├── HttpTraceServiceImpl.java │ │ │ └── LoginLogServiceImpl.java │ └── vo │ │ ├── HttpTraceSearchVO.java │ │ └── LoginLogSearchVO.java │ ├── system │ ├── dept │ │ ├── controller │ │ │ └── DeptController.java │ │ ├── dto │ │ │ ├── DeptRequestDTO.java │ │ │ └── DeptTreeNode.java │ │ ├── entity │ │ │ └── Dept.java │ │ ├── mapper │ │ │ └── DeptMapper.java │ │ └── service │ │ │ ├── DeptService.java │ │ │ └── impl │ │ │ └── DeptServiceImpl.java │ ├── log │ │ ├── controller │ │ │ └── LogController.java │ │ ├── entity │ │ │ └── Log.java │ │ ├── mapper │ │ │ └── LogMapper.java │ │ ├── service │ │ │ ├── LogService.java │ │ │ └── impl │ │ │ │ └── LogServiceImpl.java │ │ └── vo │ │ │ └── LogSearchVO.java │ ├── menu │ │ ├── controller │ │ │ └── MenuController.java │ │ ├── dto │ │ │ ├── MenuRequestDTO.java │ │ │ └── MenuTreeNode.java │ │ ├── entity │ │ │ ├── Menu.java │ │ │ └── RoleMenu.java │ │ ├── mapper │ │ │ └── MenuMapper.java │ │ └── service │ │ │ ├── MenuService.java │ │ │ └── impl │ │ │ └── MenuServiceImpl.java │ ├── role │ │ ├── controller │ │ │ └── RoleController.java │ │ ├── entity │ │ │ ├── Role.java │ │ │ └── UserRole.java │ │ ├── mapper │ │ │ └── RoleMapper.java │ │ ├── service │ │ │ ├── RoleService.java │ │ │ └── impl │ │ │ │ └── RoleServiceImpl.java │ │ └── vo │ │ │ ├── RoleAddRequest.java │ │ │ ├── RoleMenuRequest.java │ │ │ ├── RoleSearchVO.java │ │ │ └── RoleUpdateRequest.java │ └── user │ │ ├── controller │ │ ├── LoginController.java │ │ └── UserController.java │ │ ├── dto │ │ ├── UserDeptResponse.java │ │ └── UserInfoResponse.java │ │ ├── entity │ │ ├── User.java │ │ └── UserDept.java │ │ ├── mapper │ │ ├── UserDeptMapper.java │ │ └── UserMapper.java │ │ ├── service │ │ ├── LoginService.java │ │ ├── UserDeptService.java │ │ ├── UserService.java │ │ └── impl │ │ │ ├── LoginServiceImpl.java │ │ │ ├── UserDeptServiceImpl.java │ │ │ └── UserServiceImpl.java │ │ └── vo │ │ ├── ButtonVO.java │ │ ├── MenuVO.java │ │ ├── UserLoginOutRequest.java │ │ ├── UserLoginRequest.java │ │ ├── UserRegisterRequest.java │ │ ├── UserSearchRequest.java │ │ └── UserUpdateRequest.java │ └── utils │ ├── AddressUtil.java │ ├── CookieUtils.java │ ├── DateUtils.java │ ├── HttpContextUtil.java │ ├── IDGeneratorUtil.java │ ├── IPUtil.java │ ├── JsonUtils.java │ ├── SecurityUtils.java │ ├── SpringContextUtil.java │ ├── TreeBuilder.java │ ├── UserUtils.java │ └── ValidateUtil.java └── resources ├── application-dev.yml ├── application-test.yml ├── application.yml ├── ip2region └── ip2region.db ├── logback-spring.xml ├── mapper ├── DeptMapper.xml ├── JobLogMapper.xml ├── JobMapper.xml ├── LogMapper.xml ├── LoginLogMapper.xml ├── MenuMapper.xml ├── RoleMapper.xml ├── UserDeptMapper.xml └── UserMapper.xml ├── quartz.properties ├── rebel-remote.xml ├── rebel.xml └── spy.properties /.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/javaenigneer/codeworld-api-system/14f3d8b7cabe1e945f16429b571234d486b5861b/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.3/apache-maven-3.6.3-bin.zip 2 | wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar 3 | -------------------------------------------------------------------------------- /image/login.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/javaenigneer/codeworld-api-system/14f3d8b7cabe1e945f16429b571234d486b5861b/image/login.png -------------------------------------------------------------------------------- /log/error/error.2020-08-12.log: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/javaenigneer/codeworld-api-system/14f3d8b7cabe1e945f16429b571234d486b5861b/log/error/error.2020-08-12.log -------------------------------------------------------------------------------- /log/error/error.2020-08-14.log: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/javaenigneer/codeworld-api-system/14f3d8b7cabe1e945f16429b571234d486b5861b/log/error/error.2020-08-14.log -------------------------------------------------------------------------------- /log/error/error.2020-08-15.log: -------------------------------------------------------------------------------- 1 | 2020-08-15 13:01:17 ERROR main org.springframework.boot.diagnostics.LoggingFailureAnalysisReporter 2 | 3 | *************************** 4 | APPLICATION FAILED TO START 5 | *************************** 6 | 7 | Description: 8 | 9 | Failed to bind properties under 'spring.jackson.serialization' to java.util.Map: 10 | 11 | Reason: No converter found capable of converting from type [java.lang.Boolean] to type [java.util.Map] 12 | 13 | Action: 14 | 15 | Update your application's configuration 16 | 17 | -------------------------------------------------------------------------------- /log/error/error.2020-08-16.log: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/javaenigneer/codeworld-api-system/14f3d8b7cabe1e945f16429b571234d486b5861b/log/error/error.2020-08-16.log -------------------------------------------------------------------------------- /log/error/error.2020-08-24.log: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/javaenigneer/codeworld-api-system/14f3d8b7cabe1e945f16429b571234d486b5861b/log/error/error.2020-08-24.log -------------------------------------------------------------------------------- /log/error/error.2020-08-25.log: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/javaenigneer/codeworld-api-system/14f3d8b7cabe1e945f16429b571234d486b5861b/log/error/error.2020-08-25.log -------------------------------------------------------------------------------- /log/error/error.2020-08-26.log: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/javaenigneer/codeworld-api-system/14f3d8b7cabe1e945f16429b571234d486b5861b/log/error/error.2020-08-26.log -------------------------------------------------------------------------------- /log/error/error.2020-08-27.log: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/javaenigneer/codeworld-api-system/14f3d8b7cabe1e945f16429b571234d486b5861b/log/error/error.2020-08-27.log -------------------------------------------------------------------------------- /log/error/error.2020-09-01.log: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/javaenigneer/codeworld-api-system/14f3d8b7cabe1e945f16429b571234d486b5861b/log/error/error.2020-09-01.log -------------------------------------------------------------------------------- /log/error/error.2020-09-13.log: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/javaenigneer/codeworld-api-system/14f3d8b7cabe1e945f16429b571234d486b5861b/log/error/error.2020-09-13.log -------------------------------------------------------------------------------- /log/error/error.2020-09-14.log: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/javaenigneer/codeworld-api-system/14f3d8b7cabe1e945f16429b571234d486b5861b/log/error/error.2020-09-14.log -------------------------------------------------------------------------------- /log/error/error.2020-09-15.log: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/javaenigneer/codeworld-api-system/14f3d8b7cabe1e945f16429b571234d486b5861b/log/error/error.2020-09-15.log -------------------------------------------------------------------------------- /log/error/error.2020-09-16.log: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/javaenigneer/codeworld-api-system/14f3d8b7cabe1e945f16429b571234d486b5861b/log/error/error.2020-09-16.log -------------------------------------------------------------------------------- /log/error/error.2020-09-17.log: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/javaenigneer/codeworld-api-system/14f3d8b7cabe1e945f16429b571234d486b5861b/log/error/error.2020-09-17.log -------------------------------------------------------------------------------- /log/error/error.2020-09-21.log: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/javaenigneer/codeworld-api-system/14f3d8b7cabe1e945f16429b571234d486b5861b/log/error/error.2020-09-21.log -------------------------------------------------------------------------------- /log/error/error.2020-09-24.log: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/javaenigneer/codeworld-api-system/14f3d8b7cabe1e945f16429b571234d486b5861b/log/error/error.2020-09-24.log -------------------------------------------------------------------------------- /log/error/error.2020-10-12.log: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/javaenigneer/codeworld-api-system/14f3d8b7cabe1e945f16429b571234d486b5861b/log/error/error.2020-10-12.log -------------------------------------------------------------------------------- /log/error/error.2020-10-15.log: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/javaenigneer/codeworld-api-system/14f3d8b7cabe1e945f16429b571234d486b5861b/log/error/error.2020-10-15.log -------------------------------------------------------------------------------- /log/error/error.2020-10-20.log: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/javaenigneer/codeworld-api-system/14f3d8b7cabe1e945f16429b571234d486b5861b/log/error/error.2020-10-20.log -------------------------------------------------------------------------------- /log/error/error.2020-10-21.log: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/javaenigneer/codeworld-api-system/14f3d8b7cabe1e945f16429b571234d486b5861b/log/error/error.2020-10-21.log -------------------------------------------------------------------------------- /log/error/error.2020-10-29.log: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/javaenigneer/codeworld-api-system/14f3d8b7cabe1e945f16429b571234d486b5861b/log/error/error.2020-10-29.log -------------------------------------------------------------------------------- /spy.log: -------------------------------------------------------------------------------- 1 | 1597227845110|0|statement|connection 0|url jdbc:mysql://127.0.0.1:3306/codeworld-vue-system?useUnicode=true&characterEncoding=UTF-8&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT%2b8|select * from codeworld_user;|select * from codeworld_user; 2 | 1597227857366|0|statement|connection 1|url jdbc:mysql://127.0.0.1:3306/codeworld-vue-system?useUnicode=true&characterEncoding=UTF-8&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT%2b8|select * from codeworld_user;|select * from codeworld_user; 3 | 1597227960297|0|statement|connection 2|url jdbc:mysql://127.0.0.1:3306/codeworld-vue-system?useUnicode=true&characterEncoding=UTF-8&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT%2b8|select * from codeworld_user;|select * from codeworld_user; 4 | 1597228001737|1|statement|connection 0|url jdbc:mysql://127.0.0.1:3306/codeworld-vue-system?useUnicode=true&characterEncoding=UTF-8&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT%2b8|select * from codeworld_user;|select * from codeworld_user; 5 | 1597228092596|1|statement|connection 0|url jdbc:mysql://127.0.0.1:3306/codeworld-vue-system?useUnicode=true&characterEncoding=UTF-8&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT%2b8|select * from codeworld_user;|select * from codeworld_user; 6 | 1597228126863|0|statement|connection 0|url jdbc:mysql://127.0.0.1:3306/codeworld-vue-system?useUnicode=true&characterEncoding=UTF-8&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT%2b8|select * from codeworld_user;|select * from codeworld_user; 7 | 1597228159671|0|statement|connection 1|url jdbc:mysql://127.0.0.1:3306/codeworld-vue-system?useUnicode=true&characterEncoding=UTF-8&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT%2b8|select * from codeworld_user;|select * from codeworld_user; 8 | -------------------------------------------------------------------------------- /sql/codeworld_quartz.sql: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/javaenigneer/codeworld-api-system/14f3d8b7cabe1e945f16429b571234d486b5861b/sql/codeworld_quartz.sql -------------------------------------------------------------------------------- /src/main/docker/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM java:8 2 | #VOLUME /tmp 3 | ADD codeworld-vue-system-0.0.1.jar /demo.jar 4 | ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/demo.jar"] 5 | -------------------------------------------------------------------------------- /src/main/java/com/codeworld/fc/CodeworldVueSystemApplication.java: -------------------------------------------------------------------------------- 1 | package com.codeworld.fc; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class CodeworldVueSystemApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(CodeworldVueSystemApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/com/codeworld/fc/common/annotation/ControllerEndpoint.java: -------------------------------------------------------------------------------- 1 | package com.codeworld.fc.common.annotation; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Target(ElementType.METHOD) 9 | @Retention(RetentionPolicy.RUNTIME) 10 | public @interface ControllerEndpoint { 11 | 12 | String operation() default ""; 13 | 14 | String exceptionMessage() default ""; 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/com/codeworld/fc/common/annotation/FcEndPoint.java: -------------------------------------------------------------------------------- 1 | package com.codeworld.fc.common.annotation; 2 | 3 | import org.springframework.core.annotation.AliasFor; 4 | import org.springframework.stereotype.Component; 5 | 6 | import java.lang.annotation.*; 7 | 8 | @Component 9 | @Documented 10 | @Target({ElementType.TYPE}) 11 | @Retention(RetentionPolicy.RUNTIME) 12 | public @interface FcEndPoint { 13 | @AliasFor(annotation = Component.class) 14 | String value() default ""; 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/com/codeworld/fc/common/aspect/AspectSupport.java: -------------------------------------------------------------------------------- 1 | package com.codeworld.fc.common.aspect; 2 | 3 | import org.aspectj.lang.ProceedingJoinPoint; 4 | import org.aspectj.lang.reflect.MethodSignature; 5 | 6 | import java.lang.reflect.Method; 7 | 8 | public abstract class AspectSupport { 9 | 10 | Method resolveMethod(ProceedingJoinPoint point) { 11 | MethodSignature signature = (MethodSignature)point.getSignature(); 12 | Class targetClass = point.getTarget().getClass(); 13 | 14 | Method method = getDeclaredMethod(targetClass, signature.getName(), 15 | signature.getMethod().getParameterTypes()); 16 | if (method == null) { 17 | throw new IllegalStateException("无法解析目标方法: " + signature.getMethod().getName()); 18 | } 19 | return method; 20 | } 21 | 22 | private Method getDeclaredMethod(Class clazz, String name, Class... parameterTypes) { 23 | try { 24 | return clazz.getDeclaredMethod(name, parameterTypes); 25 | } catch (NoSuchMethodException e) { 26 | Class superClass = clazz.getSuperclass(); 27 | if (superClass != null) { 28 | return getDeclaredMethod(superClass, name, parameterTypes); 29 | } 30 | } 31 | return null; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/com/codeworld/fc/common/aspect/LogAspect.java: -------------------------------------------------------------------------------- 1 | package com.codeworld.fc.common.aspect; 2 | 3 | import com.codeworld.fc.common.annotation.ControllerEndpoint; 4 | import com.codeworld.fc.common.exception.FCException; 5 | import com.codeworld.fc.system.log.service.LogService; 6 | import com.codeworld.fc.utils.HttpContextUtil; 7 | import com.codeworld.fc.utils.ValidateUtil; 8 | import org.apache.commons.lang3.StringUtils; 9 | import org.aspectj.lang.ProceedingJoinPoint; 10 | import org.aspectj.lang.annotation.Around; 11 | import org.aspectj.lang.annotation.Aspect; 12 | import org.aspectj.lang.annotation.Pointcut; 13 | import org.slf4j.Logger; 14 | import org.slf4j.LoggerFactory; 15 | import org.springframework.beans.factory.annotation.Autowired; 16 | import org.springframework.stereotype.Component; 17 | 18 | import javax.servlet.http.HttpServletRequest; 19 | import java.lang.reflect.Method; 20 | 21 | /** 22 | * ClassName LogAspect 23 | * Description TODO 24 | * Author Lenovo 25 | * Date 2020/9/20 26 | * Version 1.0 27 | **/ 28 | @Component 29 | @Aspect 30 | public class LogAspect extends AspectSupport { 31 | 32 | @Autowired(required = false) 33 | private LogService logService; 34 | 35 | private static final Logger LOGGER = LoggerFactory.getLogger(LogAspect.class); 36 | 37 | /** 38 | * 定义切点 39 | */ 40 | @Pointcut("@annotation(com.codeworld.fc.common.annotation.ControllerEndpoint)") 41 | public void logPointCut() { 42 | } 43 | 44 | @Around("logPointCut()") 45 | public Object around(ProceedingJoinPoint point) throws FCException { 46 | Object result; 47 | Method targetMethod = resolveMethod(point); 48 | ControllerEndpoint annotation = targetMethod.getAnnotation(ControllerEndpoint.class); 49 | String operation = annotation.operation(); 50 | long start = System.currentTimeMillis(); 51 | try { 52 | result = point.proceed(); 53 | if (StringUtils.isNotBlank(operation)) { 54 | HttpServletRequest request = HttpContextUtil.getHttpServletRequest(); 55 | 56 | this.logService.addLog(point, targetMethod, request, operation, start); 57 | } 58 | return result; 59 | } catch (Throwable throwable) { 60 | String exceptionMessage = annotation.exceptionMessage(); 61 | String message = throwable.getMessage(); 62 | String error = ValidateUtil.containChinese(message) ? exceptionMessage + "," + message : exceptionMessage; 63 | throw new FCException(error); 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/main/java/com/codeworld/fc/common/authority/GrantedAuthorityImpl.java: -------------------------------------------------------------------------------- 1 | package com.codeworld.fc.common.authority; 2 | 3 | import org.springframework.security.core.GrantedAuthority; 4 | 5 | /** 6 | * ClassName GrantedAuthorityImpl 7 | * Description 权限封装 8 | * Author Lenovo 9 | * Date 2020/9/27 10 | * Version 1.0 11 | **/ 12 | public class GrantedAuthorityImpl implements GrantedAuthority { 13 | 14 | private static final long serialVersionUID = 1L; 15 | 16 | private String authority; 17 | 18 | public GrantedAuthorityImpl(String authority) { 19 | this.authority = authority; 20 | } 21 | 22 | public void setAuthority(String authority) { 23 | this.authority = authority; 24 | } 25 | 26 | @Override 27 | public String getAuthority() { 28 | return this.authority; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/com/codeworld/fc/common/authority/JWTToken.java: -------------------------------------------------------------------------------- 1 | package com.codeworld.fc.common.authority; 2 | 3 | import io.swagger.annotations.ApiModel; 4 | import io.swagger.annotations.ApiModelProperty; 5 | import lombok.Data; 6 | import org.apache.shiro.authc.AuthenticationToken; 7 | 8 | /** 9 | * ClassName JWTToken 10 | * Description JWTToken基本类 11 | * Author Lenovo 12 | * Date 2020/9/15 13 | * Version 1.0 14 | **/ 15 | @Data 16 | @ApiModel("JWTToken基本类") 17 | public class JWTToken implements AuthenticationToken { 18 | 19 | @ApiModelProperty("Token认证") 20 | private String token; 21 | 22 | @ApiModelProperty("过期时间") 23 | private String expireAt; 24 | 25 | 26 | @Override 27 | public Object getPrincipal() { 28 | return token; 29 | } 30 | 31 | @Override 32 | public Object getCredentials() { 33 | return token; 34 | } 35 | 36 | public JWTToken(String token) { 37 | this.token = token; 38 | } 39 | 40 | public JWTToken(String token, String expireAt) { 41 | this.token = token; 42 | this.expireAt = expireAt; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/com/codeworld/fc/common/authority/JWTUtil.java: -------------------------------------------------------------------------------- 1 | package com.codeworld.fc.common.authority; 2 | 3 | import com.auth0.jwt.JWT; 4 | import com.auth0.jwt.JWTVerifier; 5 | import com.auth0.jwt.algorithms.Algorithm; 6 | import com.auth0.jwt.interfaces.DecodedJWT; 7 | import com.codeworld.fc.utils.SecurityUtils; 8 | import io.jsonwebtoken.Claims; 9 | import io.jsonwebtoken.Jwts; 10 | import io.jsonwebtoken.SignatureAlgorithm; 11 | import org.apache.commons.lang3.StringUtils; 12 | import org.slf4j.Logger; 13 | import org.slf4j.LoggerFactory; 14 | import org.springframework.security.core.Authentication; 15 | 16 | import java.util.Date; 17 | import java.util.HashMap; 18 | import java.util.Map; 19 | 20 | /** 21 | * ClassName JWTUtil 22 | * Description JWT认证工具类 23 | * Author Lenovo 24 | * Date 2020/9/15 25 | * Version 1.0 26 | **/ 27 | public class JWTUtil { 28 | 29 | private static final Logger LOGGER = LoggerFactory.getLogger(JWTUtil.class); 30 | 31 | /** 32 | * 用户名称 33 | */ 34 | private static final String USERNAME = Claims.SUBJECT; 35 | /** 36 | * 创建时间 37 | */ 38 | private static final String CREATED = "created"; 39 | /** 40 | * 权限列表 41 | */ 42 | private static final String AUTHORITIES = "authorities"; 43 | /** 44 | * 密钥 45 | */ 46 | private static final String SECRET = "abcdefgh"; 47 | /** 48 | * 有效期12小时 49 | */ 50 | private static final long EXPIRE_TIME = 12 * 60 * 60 * 1000; 51 | 52 | 53 | /** 54 | * 生成token 55 | * @param authentication 56 | * @return 57 | */ 58 | public static String sign(Authentication authentication) { 59 | Map claims = new HashMap<>(3); 60 | claims.put(USERNAME, SecurityUtils.getUsername(authentication)); 61 | claims.put(CREATED, new Date()); 62 | claims.put(AUTHORITIES, authentication.getAuthorities()); 63 | return generateToken(claims); 64 | } 65 | 66 | /** 67 | * 从数据中生成token 68 | * @param claims 69 | * @return 70 | */ 71 | private static String generateToken(Map claims) { 72 | Date expirationDate = new Date(System.currentTimeMillis() + EXPIRE_TIME); 73 | return Jwts.builder().setClaims(claims).setExpiration(expirationDate).signWith(SignatureAlgorithm.HS512, SECRET).compact(); 74 | } 75 | 76 | 77 | /** 78 | * 根据Token获取用户名 79 | * 80 | * @param token 81 | * @return 82 | */ 83 | public static String getUserName(String token) { 84 | 85 | String username; 86 | try { 87 | Claims claims = getClaimsFromToken(token); 88 | username = claims.getSubject(); 89 | } catch (Exception e) { 90 | username = null; 91 | } 92 | return username; 93 | } 94 | 95 | /** 96 | * 从令牌中获取数据声明 97 | * 98 | * @param token 令牌 99 | * @return 数据声明 100 | */ 101 | private static Claims getClaimsFromToken(String token) { 102 | Claims claims; 103 | try { 104 | claims = Jwts.parser().setSigningKey(SECRET).parseClaimsJws(token).getBody(); 105 | } catch (Exception e) { 106 | claims = null; 107 | } 108 | return claims; 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /src/main/java/com/codeworld/fc/common/authority/JwtAuthenticationProvider.java: -------------------------------------------------------------------------------- 1 | package com.codeworld.fc.common.authority; 2 | 3 | import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; 4 | import org.springframework.security.authentication.dao.DaoAuthenticationProvider; 5 | import org.springframework.security.core.Authentication; 6 | import org.springframework.security.core.AuthenticationException; 7 | import org.springframework.security.core.userdetails.UserDetails; 8 | import org.springframework.security.core.userdetails.UserDetailsService; 9 | import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; 10 | 11 | /** 12 | * ClassName JwtAuthenticationProvider 13 | * Description 身份验证提供者 14 | * Author Lenovo 15 | * Date 2020/9/27 16 | * Version 1.0 17 | **/ 18 | public class JwtAuthenticationProvider extends DaoAuthenticationProvider { 19 | 20 | public JwtAuthenticationProvider(UserDetailsService userDetailsService) { 21 | setUserDetailsService(userDetailsService); 22 | setPasswordEncoder(new BCryptPasswordEncoder()); 23 | } 24 | 25 | @Override 26 | public Authentication authenticate(Authentication authentication) throws AuthenticationException { 27 | // 可以在此处覆写整个登录认证逻辑 28 | return super.authenticate(authentication); 29 | } 30 | 31 | @Override 32 | protected void additionalAuthenticationChecks(UserDetails userDetails, UsernamePasswordAuthenticationToken authentication) throws AuthenticationException { 33 | // 可以在此处覆写密码验证逻辑 34 | super.additionalAuthenticationChecks(userDetails, authentication); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/com/codeworld/fc/common/authority/JwtAuthenticationToken.java: -------------------------------------------------------------------------------- 1 | package com.codeworld.fc.common.authority; 2 | 3 | import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; 4 | import org.springframework.security.core.GrantedAuthority; 5 | 6 | import java.util.Collection; 7 | 8 | /** 9 | * ClassName JwtAuthenticatioToken 10 | * Description 自定义令牌对象 11 | * Author Lenovo 12 | * Date 2020/9/27 13 | * Version 1.0 14 | **/ 15 | public class JwtAuthenticationToken extends UsernamePasswordAuthenticationToken { 16 | 17 | private static final long serialVersionUID = 1L; 18 | 19 | private String token; 20 | 21 | public JwtAuthenticationToken(Object principal, Object credentials) { 22 | super(principal, credentials); 23 | } 24 | 25 | public JwtAuthenticationToken(Object principal, Object credentials, Collection authorities) { 26 | super(principal, credentials, authorities); 27 | } 28 | 29 | public void setToken(String token) { 30 | this.token = token; 31 | } 32 | 33 | public String getToken() { 34 | return token; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/com/codeworld/fc/common/authority/JwtUserDetails.java: -------------------------------------------------------------------------------- 1 | package com.codeworld.fc.common.authority; 2 | 3 | import org.springframework.security.core.GrantedAuthority; 4 | import org.springframework.security.core.userdetails.User; 5 | 6 | import java.util.Collection; 7 | 8 | /** 9 | * ClassName JwtUserDetails 10 | * Description 安全用户模型 11 | * Author Lenovo 12 | * Date 2020/9/27 13 | * Version 1.0 14 | **/ 15 | public class JwtUserDetails extends User { 16 | 17 | 18 | public JwtUserDetails(String username, String password, Collection authorities) { 19 | super(username, password, authorities); 20 | } 21 | 22 | public JwtUserDetails(String username, String password, boolean enabled, boolean accountNonExpired, boolean credentialsNonExpired, boolean accountNonLocked, Collection authorities) { 23 | super(username, password, enabled, accountNonExpired, credentialsNonExpired, accountNonLocked, authorities); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/com/codeworld/fc/common/authority/UserDetailServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.codeworld.fc.common.authority; 2 | 3 | import com.codeworld.fc.common.enums.StatusEnum; 4 | import com.codeworld.fc.common.exception.FCException; 5 | import com.codeworld.fc.common.response.FCResponse; 6 | import com.codeworld.fc.system.menu.entity.Menu; 7 | import com.codeworld.fc.system.menu.mapper.MenuMapper; 8 | import com.codeworld.fc.system.role.entity.Role; 9 | import com.codeworld.fc.system.role.mapper.RoleMapper; 10 | import com.codeworld.fc.system.user.entity.User; 11 | import com.codeworld.fc.system.user.mapper.UserMapper; 12 | import com.codeworld.fc.system.user.service.UserService; 13 | import org.slf4j.Logger; 14 | import org.slf4j.LoggerFactory; 15 | import org.springframework.beans.factory.annotation.Autowired; 16 | import org.springframework.context.annotation.Bean; 17 | import org.springframework.data.redis.core.StringRedisTemplate; 18 | import org.springframework.security.authentication.AuthenticationProvider; 19 | import org.springframework.security.authentication.DisabledException; 20 | import org.springframework.security.authentication.dao.DaoAuthenticationProvider; 21 | import org.springframework.security.core.GrantedAuthority; 22 | import org.springframework.security.core.userdetails.UserDetails; 23 | import org.springframework.security.core.userdetails.UserDetailsService; 24 | import org.springframework.security.core.userdetails.UsernameNotFoundException; 25 | import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; 26 | import org.springframework.stereotype.Service; 27 | import org.springframework.util.CollectionUtils; 28 | 29 | import java.util.HashSet; 30 | import java.util.List; 31 | import java.util.Set; 32 | import java.util.stream.Collectors; 33 | 34 | /** 35 | * ClassName UserDetailServiceImpl 36 | * Description 用户登录认证信息查询 37 | * Author Lenovo 38 | * Date 2020/9/27 39 | * Version 1.0 40 | **/ 41 | @Service 42 | public class UserDetailServiceImpl implements UserDetailsService { 43 | 44 | private static final Logger LOGGER = LoggerFactory.getLogger(UserDetailServiceImpl.class); 45 | 46 | @Autowired(required = false) 47 | private UserMapper userMapper; 48 | 49 | @Autowired(required = false) 50 | private RoleMapper roleMapper; 51 | 52 | @Autowired(required = false) 53 | private MenuMapper menuMapper; 54 | 55 | @Autowired(required = false) 56 | private StringRedisTemplate stringRedisTemplate; 57 | 58 | private final String USER_INFO = "USER_INFO:USER:ID:"; 59 | 60 | 61 | @Override 62 | public UserDetails loadUserByUsername(String username) { 63 | 64 | User user = this.userMapper.getUserByName(username); 65 | 66 | // 判断用户是否已登录 67 | if (this.stringRedisTemplate.hasKey(USER_INFO + user.getUserId())) { 68 | throw new FCException("用户已登录或下线中,请稍等20秒再登录"); 69 | } 70 | 71 | if (user == null) { 72 | throw new UsernameNotFoundException("用户名或密码错误"); 73 | } 74 | // 判断用户是否被禁用 75 | if (user.getUserStatus() == StatusEnum.USER_DISABLE) { 76 | throw new DisabledException("已禁用,请联系管理员"); 77 | } 78 | // 查询用户的权限 79 | // 查询用户角色 80 | Role role = this.roleMapper.getRoleById(user.getUserId()); 81 | if (role == null) { 82 | throw new UsernameNotFoundException("用户不存在角色"); 83 | } 84 | // 查询用户权限 85 | List menus = this.menuMapper.getMenuByRoleId(role.getRoleId()); 86 | if (CollectionUtils.isEmpty(menus)) { 87 | throw new UsernameNotFoundException("用户权限为空"); 88 | } 89 | Set permissions = new HashSet<>(); 90 | permissions = menus.stream().map(Menu::getResources).collect(Collectors.toSet()); 91 | List grantedAuthorities = permissions.stream().map(GrantedAuthorityImpl::new).collect(Collectors.toList()); 92 | return new JwtUserDetails(username, new BCryptPasswordEncoder().encode("123456"), grantedAuthorities); 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /src/main/java/com/codeworld/fc/common/base/PageQuery.java: -------------------------------------------------------------------------------- 1 | package com.codeworld.fc.common.base; 2 | 3 | import io.swagger.annotations.ApiModel; 4 | import io.swagger.annotations.ApiModelProperty; 5 | import lombok.Data; 6 | 7 | /** 8 | * ClassName PageQuery 9 | * Description 分页信息 10 | * Author Lenovo 11 | * Date 2020/9/21 12 | * Version 1.0 13 | **/ 14 | @Data 15 | @ApiModel("分页信息") 16 | public class PageQuery { 17 | 18 | @ApiModelProperty("页数") 19 | private Integer page; 20 | 21 | @ApiModelProperty("数量") 22 | private Integer limit; 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/com/codeworld/fc/common/config/FCCorsConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.codeworld.fc.common.config; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.web.cors.CorsConfiguration; 6 | import org.springframework.web.cors.UrlBasedCorsConfigurationSource; 7 | import org.springframework.web.filter.CorsFilter; 8 | 9 | /** 10 | * 跨域配置类 11 | * @author Lenovo 12 | */ 13 | @Configuration 14 | public class FCCorsConfiguration { 15 | 16 | @Bean 17 | public CorsFilter corsFilter() { 18 | 19 | // 初始化cors配置对象 20 | CorsConfiguration corsConfiguration = new CorsConfiguration(); 21 | 22 | // 设置跨域请求 23 | corsConfiguration.addAllowedOrigin("http://localhost:9572"); 24 | corsConfiguration.addAllowedOrigin("http://192.168.2.6:9572"); 25 | 26 | // 是否携带cookie 27 | corsConfiguration.setAllowCredentials(true); 28 | 29 | // 设置请求方法,*代表所有的请求方法--get、put、post 30 | corsConfiguration.addAllowedMethod("*"); 31 | 32 | // 设置携带任何头信息 33 | corsConfiguration.addAllowedHeader("*"); 34 | 35 | // 初始化cors源对象 36 | UrlBasedCorsConfigurationSource corsConfigurationSource = new UrlBasedCorsConfigurationSource(); 37 | 38 | // 设置跨域请求拦截 39 | corsConfigurationSource.registerCorsConfiguration("/**", corsConfiguration); 40 | 41 | // 返回corsFilter实例,参数为:cors配置源对象 42 | return new CorsFilter(corsConfigurationSource); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/com/codeworld/fc/common/config/MyWebConfig.java: -------------------------------------------------------------------------------- 1 | package com.codeworld.fc.common.config; 2 | 3 | import com.codeworld.fc.monitor.listener.ActiveUserListener; 4 | import org.springframework.boot.web.servlet.ServletListenerRegistrationBean; 5 | import org.springframework.context.annotation.Bean; 6 | import org.springframework.context.annotation.Configuration; 7 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; 8 | 9 | /** 10 | * ClassName MywebConfig 11 | * Description TODO 12 | * Author Lenovo 13 | * Date 2020/10/16 14 | * Version 1.0 15 | **/ 16 | @Configuration 17 | public class MyWebConfig implements WebMvcConfigurer { 18 | 19 | @Bean 20 | public ServletListenerRegistrationBean servletListenerRegistrationBean() { 21 | 22 | ServletListenerRegistrationBean servletListenerRegistrationBean = new ServletListenerRegistrationBean(); 23 | 24 | servletListenerRegistrationBean.setListener(new ActiveUserListener()); 25 | 26 | System.out.println("已监听"); 27 | return servletListenerRegistrationBean; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/codeworld/fc/common/config/P6spySqlFormatConfigure.java: -------------------------------------------------------------------------------- 1 | package com.codeworld.fc.common.config; 2 | 3 | 4 | import com.codeworld.fc.utils.DateUtils; 5 | import com.p6spy.engine.spy.appender.MessageFormattingStrategy; 6 | import org.apache.commons.lang3.StringUtils; 7 | 8 | import java.time.LocalDateTime; 9 | 10 | /** 11 | * 自定义 p6spy sql输出格式 12 | */ 13 | public class P6spySqlFormatConfigure implements MessageFormattingStrategy { 14 | 15 | /** 16 | * 过滤掉定时任务的 SQL 17 | */ 18 | @Override 19 | public String formatMessage(int connectionId, String now, long elapsed, String category, String prepared, String sql, String url) { 20 | return StringUtils.isNotBlank(sql) ? DateUtils.formatFullTime(LocalDateTime.now(), DateUtils.pattern_time) 21 | + " | 耗时 " + elapsed + " ms | SQL 语句:" + StringUtils.LF + sql.replaceAll("[\\s]+", StringUtils.SPACE) + ";" : StringUtils.EMPTY; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/com/codeworld/fc/common/config/SecurityConfig.java: -------------------------------------------------------------------------------- 1 | package com.codeworld.fc.common.config; 2 | 3 | import com.codeworld.fc.common.authority.JwtAuthenticationProvider; 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.http.HttpMethod; 8 | import org.springframework.security.authentication.AuthenticationManager; 9 | import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; 10 | import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; 11 | import org.springframework.security.config.annotation.web.builders.HttpSecurity; 12 | import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; 13 | import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; 14 | import org.springframework.security.core.userdetails.UserDetailsService; 15 | 16 | /** 17 | * ClassName SecurityConfig 18 | * Description SpringSecurity权限安全配置类 19 | * Author Lenovo 20 | * Date 2020/9/27 21 | * Version 1.0 22 | **/ 23 | @Configuration 24 | @EnableWebSecurity 25 | @EnableGlobalMethodSecurity(prePostEnabled = true) 26 | public class SecurityConfig extends WebSecurityConfigurerAdapter { 27 | 28 | @Autowired(required = false) 29 | private UserDetailsService userDetailsService; 30 | 31 | @Override 32 | protected void configure(AuthenticationManagerBuilder auth) throws Exception { 33 | // 使用自定义身份认证 34 | auth.authenticationProvider(new JwtAuthenticationProvider(userDetailsService)); 35 | } 36 | 37 | @Override 38 | protected void configure(HttpSecurity http) throws Exception { 39 | http.cors().and().csrf().disable() 40 | .authorizeRequests() 41 | .antMatchers(HttpMethod.OPTIONS, "/").permitAll() 42 | .antMatchers("/system-auth/user-login").permitAll() 43 | .antMatchers("/system-auth/user-loginOut").permitAll() 44 | // swagger 45 | .antMatchers("/swagger**/**").permitAll() 46 | .antMatchers("/webjars/**").permitAll() 47 | .antMatchers("/v2/**").permitAll() 48 | .anyRequest().authenticated(); 49 | http.logout().logoutUrl("/system-auth/user-loginOut"); 50 | } 51 | 52 | 53 | @Bean 54 | @Override 55 | public AuthenticationManager authenticationManager() throws Exception { 56 | return super.authenticationManager(); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/com/codeworld/fc/common/config/SwaggerConfig.java: -------------------------------------------------------------------------------- 1 | package com.codeworld.fc.common.config; 2 | 3 | import com.google.common.base.Function; 4 | import com.google.common.base.Optional; 5 | import com.google.common.base.Predicate; 6 | import org.springframework.context.annotation.Bean; 7 | import org.springframework.context.annotation.Configuration; 8 | import springfox.documentation.RequestHandler; 9 | import springfox.documentation.builders.ApiInfoBuilder; 10 | import springfox.documentation.builders.ParameterBuilder; 11 | import springfox.documentation.builders.PathSelectors; 12 | import springfox.documentation.builders.RequestHandlerSelectors; 13 | import springfox.documentation.schema.ModelRef; 14 | import springfox.documentation.service.ApiInfo; 15 | import springfox.documentation.service.Contact; 16 | import springfox.documentation.service.Parameter; 17 | import springfox.documentation.spi.DocumentationType; 18 | import springfox.documentation.spring.web.plugins.Docket; 19 | import springfox.documentation.swagger2.annotations.EnableSwagger2; 20 | 21 | import java.util.ArrayList; 22 | import java.util.List; 23 | 24 | /** 25 | * @author Lenovo 26 | */ 27 | @Configuration 28 | @EnableSwagger2 29 | public class SwaggerConfig { 30 | 31 | // 定义分隔符 32 | private static final String splitor = ";"; 33 | 34 | @Bean 35 | public Docket createRestApi(){ 36 | 37 | // 添加请求参数,我们这里把token作为请求头部参数传入后端 38 | ParameterBuilder parameterBuilder = new ParameterBuilder(); 39 | List parameters = new ArrayList(); 40 | parameterBuilder.name("Authorization").description("令牌").modelRef(new ModelRef("string")).parameterType("header") 41 | .required(false).build(); 42 | parameters.add(parameterBuilder.build()); 43 | return new Docket(DocumentationType.SWAGGER_2) 44 | .pathMapping("/") 45 | .select() 46 | .apis(basePackage("com.codeworld.fc.system.user.controller" 47 | + splitor + "com.codeworld.fc.system.role.controller" 48 | + splitor + "com.codeworld.fc.system.menu.controller" 49 | + splitor + "com.codeworld.fc.system.log.controller" 50 | + splitor + "com.codeworld.fc.job.controller")) 51 | .paths(PathSelectors.any()) 52 | .build().apiInfo(new ApiInfoBuilder() 53 | .title("CodeWorld-FC权限管理系统Api接口文档") 54 | .description("CodeWorld-FC是一个简单高效的权限管理系统") 55 | .version("9.0") 56 | .contact(new Contact("CodeWorld_-FC","http://feicheng.xyz","1692454247@qq.com")) 57 | .license("FC|收废铁") 58 | .licenseUrl("http://feicheng.xyz").build()).globalOperationParameters(parameters); 59 | } 60 | 61 | /** 62 | * 重写basePackage方法,使能够实现多包访问 63 | * @author jinhaoxun 64 | * @date 2019/1/26 65 | * @param 66 | */ 67 | public static Predicate basePackage(final String basePackage) { 68 | return input -> declaringClass(input).transform(handlerPackage(basePackage)).or(true); 69 | } 70 | 71 | private static Function, Boolean> handlerPackage(final String basePackage) { 72 | return input -> { 73 | // 循环判断匹配 74 | for (String strPackage : basePackage.split(splitor)) { 75 | boolean isMatch = input.getPackage().getName().startsWith(strPackage); 76 | if (isMatch) { 77 | return true; 78 | } 79 | } 80 | return false; 81 | }; 82 | } 83 | 84 | private static Optional> declaringClass(RequestHandler input) { 85 | return Optional.fromNullable(input.declaringClass()); 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /src/main/java/com/codeworld/fc/common/enums/HttpFcStatus.java: -------------------------------------------------------------------------------- 1 | package com.codeworld.fc.common.enums; 2 | /** 3 | * ClassName HttpFcStatus 4 | * Description 状态枚举类 5 | * Author Lenovo 6 | * Date 2020/8/12 7 | * Version 1.0 8 | **/ 9 | 10 | /** 11 | * 状态枚举类 12 | */ 13 | public enum HttpFcStatus { 14 | 15 | /** 16 | * 系统错误 17 | */ 18 | RUNTIMECODE(20001), 19 | 20 | /** 21 | * 验证错误 22 | */ 23 | VALIDATEFAILCODE(20002), 24 | 25 | /** 26 | * 验证成功 27 | */ 28 | VALIDATESUCCESSCODE(10002), 29 | 30 | /** 31 | * 认证错误 32 | */ 33 | AUTHFAILCODE(20003), 34 | 35 | /** 36 | * 认证成功 37 | */ 38 | AUTHSUCCESSCODE(10003), 39 | 40 | /** 41 | * 数据请求成功 42 | */ 43 | DATASUCCESSGET(20000), 44 | 45 | /** 46 | * 参数错误 47 | */ 48 | PARAMSERROR(40001), 49 | 50 | 51 | /** 52 | * 数据存在 53 | */ 54 | DATAEXIST(40000); 55 | 56 | private Integer code; 57 | 58 | HttpFcStatus(Integer code) { 59 | this.code = code; 60 | } 61 | 62 | public Integer getCode() { 63 | return code; 64 | } 65 | 66 | public void setCode(Integer code) { 67 | this.code = code; 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/main/java/com/codeworld/fc/common/enums/StatusEnum.java: -------------------------------------------------------------------------------- 1 | package com.codeworld.fc.common.enums; 2 | 3 | /** 4 | * ClassName StatusEnum 5 | * Author Lenovo 6 | * Date 2020/7/4 7 | * Version 1.0 8 | **/ 9 | public class StatusEnum { 10 | 11 | // 用户启用状态1 12 | public static final Integer USER_ENABLE = 1; 13 | 14 | // 用户被禁用 15 | public static final Integer USER_DISABLE = 0; 16 | 17 | // 用户下线 18 | public static final Integer USER_OFFLINE = -1; 19 | 20 | // 任务成功状态1 21 | public static final Integer JOB_SUCCESS = 1; 22 | 23 | // 任务失败状态0 24 | public static final Integer JOB_FAIL = 0; 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/com/codeworld/fc/common/exception/FCException.java: -------------------------------------------------------------------------------- 1 | package com.codeworld.fc.common.exception; 2 | 3 | /** 4 | *异常Exception 5 | * @author 16924 6 | */ 7 | public class FCException extends RuntimeException { 8 | 9 | private static final long serialVersionUID = -7140424953329380195L; 10 | 11 | public FCException(){ 12 | super(); 13 | } 14 | 15 | public FCException(String message){ 16 | 17 | super(message); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/com/codeworld/fc/common/handler/ExceptionHand.java: -------------------------------------------------------------------------------- 1 | package com.codeworld.fc.common.handler; 2 | 3 | 4 | import com.codeworld.fc.common.exception.FCException; 5 | import com.codeworld.fc.common.response.FCResponse; 6 | import org.springframework.security.authentication.DisabledException; 7 | import org.springframework.security.core.AuthenticationException; 8 | import org.springframework.security.core.userdetails.UsernameNotFoundException; 9 | import org.springframework.validation.ObjectError; 10 | import org.springframework.web.bind.MethodArgumentNotValidException; 11 | import org.springframework.web.bind.annotation.ExceptionHandler; 12 | import org.springframework.web.bind.annotation.ResponseBody; 13 | import org.springframework.web.bind.annotation.RestControllerAdvice; 14 | 15 | /** 16 | * 定义异常处理方法 17 | * @author 16924 18 | */ 19 | @RestControllerAdvice 20 | public class ExceptionHand { 21 | 22 | 23 | /** 24 | * 系统异常 25 | * 26 | * @param e 27 | * @return 28 | */ 29 | @ExceptionHandler(FCException.class) 30 | @ResponseBody 31 | public FCResponse fcExceptionHandle(FCException e) { 32 | 33 | return FCResponse.runtimeResponse(e.getMessage()); 34 | } 35 | 36 | /** 37 | * 参数校验失败 38 | * 39 | * @param exception 40 | * @return 41 | */ 42 | @ExceptionHandler(MethodArgumentNotValidException.class) 43 | @ResponseBody 44 | public FCResponse methodArgumentNotValidExceptionHandle(MethodArgumentNotValidException exception) { 45 | 46 | ObjectError objectError = exception.getBindingResult().getAllErrors().get(0); 47 | 48 | return FCResponse.validateErrorResponse(objectError.getDefaultMessage()); 49 | } 50 | 51 | /** 52 | * 认证失败异常 53 | * 54 | * @param exception 55 | * @return 56 | */ 57 | @ExceptionHandler(AuthenticationException.class) 58 | @ResponseBody 59 | public FCResponse authenticationException(AuthenticationException exception) { 60 | 61 | return FCResponse.authErrorResponse(exception.getMessage()); 62 | } 63 | 64 | 65 | } 66 | -------------------------------------------------------------------------------- /src/main/java/com/codeworld/fc/common/response/DataResponse.java: -------------------------------------------------------------------------------- 1 | package com.codeworld.fc.common.response; 2 | 3 | import io.swagger.annotations.ApiModel; 4 | import io.swagger.annotations.ApiModelProperty; 5 | import lombok.Data; 6 | 7 | /** 8 | * ClassName DataResponse 9 | * Description TODO 10 | * Author Lenovo 11 | * Date 2020/9/21 12 | * Version 1.0 13 | **/ 14 | @Data 15 | @ApiModel("数据响应信息") 16 | public class DataResponse { 17 | 18 | @ApiModelProperty("数据") 19 | private T data; 20 | 21 | @ApiModelProperty("总数") 22 | private Long total; 23 | 24 | public DataResponse(T data, Long total) { 25 | this.data = data; 26 | this.total = total; 27 | } 28 | 29 | /** 30 | * 数据响应--无数据 31 | * @param 32 | * @return 33 | */ 34 | public static DataResponse dataResponse(T data, Long total){ 35 | 36 | return new DataResponse<>(data, total); 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/com/codeworld/fc/common/response/FCResponse.java: -------------------------------------------------------------------------------- 1 | package com.codeworld.fc.common.response; 2 | 3 | import com.codeworld.fc.common.enums.HttpFcStatus; 4 | import lombok.Data; 5 | 6 | import java.io.Serializable; 7 | 8 | /** 9 | * ClassName FCResult 10 | * Description 请求数据响应 11 | * Author Lenovo 12 | * Date 2020/8/12 13 | * Version 1.0 14 | **/ 15 | @Data 16 | public class FCResponse implements Serializable { 17 | 18 | /** 19 | *状态码 20 | */ 21 | private Integer code; 22 | 23 | 24 | /** 25 | * 响应信息 26 | */ 27 | private String msg; 28 | 29 | 30 | /** 31 | * 响应数据 32 | */ 33 | private T data; 34 | 35 | public FCResponse(Integer code, String msg, T data){ 36 | 37 | this.code = code; 38 | 39 | this.msg = msg; 40 | 41 | this.data = data; 42 | } 43 | 44 | public FCResponse(Integer code, String msg){ 45 | 46 | this.code = code; 47 | 48 | this.msg = msg; 49 | } 50 | 51 | /** 52 | * 系统错误 53 | * @param msg 54 | * @param 55 | * @return 56 | */ 57 | public static FCResponse runtimeResponse(String msg){ 58 | 59 | return new FCResponse<>(HttpFcStatus.RUNTIMECODE.getCode(),msg); 60 | } 61 | 62 | /** 63 | * 认证错误 64 | * @param msg 65 | * @param 66 | * @return 67 | */ 68 | public static FCResponse authErrorResponse(String msg){ 69 | 70 | return new FCResponse<>(HttpFcStatus.AUTHFAILCODE.getCode(),msg); 71 | } 72 | 73 | /** 74 | * 数据响应--无数据 75 | * @param code 76 | * @param msg 77 | * @param 78 | * @return 79 | */ 80 | public static FCResponse dataResponse(Integer code, String msg){ 81 | 82 | return new FCResponse<>(code, msg); 83 | } 84 | 85 | /** 86 | * 数据响应--带数据 87 | * @param code 88 | * @param msg 89 | * @param data 90 | * @param 91 | * @return 92 | */ 93 | public static FCResponse dataResponse(Integer code, String msg, T data){ 94 | 95 | return new FCResponse<>(code, msg, data); 96 | } 97 | 98 | 99 | /** 100 | * 参数校验失败 101 | * @param msg 102 | * @param 103 | * @return 104 | */ 105 | public static FCResponse validateErrorResponse(String msg){ 106 | 107 | return new FCResponse<>(HttpFcStatus.PARAMSERROR.getCode(), msg); 108 | } 109 | 110 | } 111 | -------------------------------------------------------------------------------- /src/main/java/com/codeworld/fc/job/config/ScheduleConfigure.java: -------------------------------------------------------------------------------- 1 | package com.codeworld.fc.job.config; 2 | 3 | import com.baomidou.dynamic.datasource.DynamicRoutingDataSource; 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.scheduling.quartz.SchedulerFactoryBean; 8 | 9 | import javax.sql.DataSource; 10 | import java.util.Properties; 11 | 12 | /** 13 | * ClassName ScheduleConfigure 14 | * Description 定时任务配置 15 | * Author Lenovo 16 | * Date 2020/9/22 17 | * Version 1.0 18 | **/ 19 | @Configuration 20 | public class ScheduleConfigure { 21 | 22 | @Autowired(required = false) 23 | private DynamicRoutingDataSource dynamicRoutingDataSource; 24 | 25 | @Bean 26 | public SchedulerFactoryBean schedulerFactoryBean() { 27 | SchedulerFactoryBean factory = new SchedulerFactoryBean(); 28 | // 手动从多数据源中获取 quartz数据源 29 | DataSource quartz = dynamicRoutingDataSource.getDataSource("quartz"); 30 | factory.setDataSource(quartz); 31 | 32 | // quartz参数 33 | Properties prop = new Properties(); 34 | prop.put("org.quartz.scheduler.instanceName", "MyScheduler"); 35 | prop.put("org.quartz.scheduler.instanceId", "AUTO"); 36 | // 线程池配置 37 | prop.put("org.quartz.threadPool.class", "org.quartz.simpl.SimpleThreadPool"); 38 | prop.put("org.quartz.threadPool.threadCount", "20"); 39 | prop.put("org.quartz.threadPool.threadPriority", "5"); 40 | // JobStore配置 41 | prop.put("org.quartz.jobStore.class", "org.quartz.impl.jdbcjobstore.JobStoreTX"); 42 | // 集群配置 43 | prop.put("org.quartz.jobStore.isClustered", "true"); 44 | prop.put("org.quartz.jobStore.clusterCheckinInterval", "15000"); 45 | prop.put("org.quartz.jobStore.maxMisfiresToHandleAtATime", "1"); 46 | 47 | prop.put("org.quartz.jobStore.misfireThreshold", "12000"); 48 | prop.put("org.quartz.jobStore.tablePrefix", "QRTZ_"); 49 | factory.setQuartzProperties(prop); 50 | 51 | factory.setSchedulerName("FC_Scheduler"); 52 | // 延时启动 53 | factory.setStartupDelay(1); 54 | factory.setApplicationContextSchedulerContextKey("applicationContextKey"); 55 | // 启动时更新己存在的 Job 56 | factory.setOverwriteExistingJobs(true); 57 | // 设置自动启动,默认为 true 58 | factory.setAutoStartup(true); 59 | 60 | return factory; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/main/java/com/codeworld/fc/job/controller/JobController.java: -------------------------------------------------------------------------------- 1 | package com.codeworld.fc.job.controller; 2 | 3 | import com.codeworld.fc.common.annotation.ControllerEndpoint; 4 | import com.codeworld.fc.common.response.DataResponse; 5 | import com.codeworld.fc.common.response.FCResponse; 6 | import com.codeworld.fc.job.dto.JobRequestDTO; 7 | import com.codeworld.fc.job.entity.Job; 8 | import com.codeworld.fc.job.service.JobService; 9 | import com.codeworld.fc.job.vo.JobSearchVO; 10 | import io.swagger.annotations.Api; 11 | import io.swagger.annotations.ApiOperation; 12 | import org.springframework.beans.factory.annotation.Autowired; 13 | import org.springframework.security.access.prepost.PreAuthorize; 14 | import org.springframework.web.bind.annotation.*; 15 | 16 | import javax.validation.Valid; 17 | import java.util.List; 18 | 19 | /** 20 | * ClassName JobController 21 | * Description 任务调度管理接口 22 | * Author Lenovo 23 | * Date 2020/9/21 24 | * Version 1.0 25 | **/ 26 | @RestController 27 | @RequestMapping("system-job") 28 | @Api(tags = "任务调度管理接口") 29 | public class JobController { 30 | 31 | @Autowired(required = false) 32 | private JobService jobService; 33 | 34 | @PostMapping("get-all-job") 35 | @ApiOperation("获取全部任务") 36 | @PreAuthorize("hasAuthority('job')") 37 | @ControllerEndpoint(operation = "获取全部任务",exceptionMessage = "获取全部任务失败") 38 | public FCResponse>> getAllJob(@RequestBody JobSearchVO jobSearchVO){ 39 | return this.jobService.getAllJob(jobSearchVO); 40 | } 41 | 42 | @PostMapping("update-job-status") 43 | @ApiOperation("启用或停用任务") 44 | @ControllerEndpoint(operation = "启用或停用任务",exceptionMessage = "启用或停用任务失败") 45 | public FCResponse updateJobStatus(@RequestParam("jobId") Long jobId, 46 | @RequestParam("status") Integer status){ 47 | return this.jobService.updateJobStatus(jobId,status); 48 | } 49 | 50 | @PostMapping("delete-job") 51 | @ApiOperation("删除任务") 52 | @PreAuthorize("hasAuthority('job:delete')") 53 | @ControllerEndpoint(operation = "删除任务",exceptionMessage = "删除任务失败") 54 | public FCResponse deleteJob(@RequestParam("jobId") Long jobId){ 55 | return this.jobService.deleteJob(jobId); 56 | } 57 | 58 | @PostMapping("add-job") 59 | @ApiOperation("添加任务") 60 | @PreAuthorize("hasAuthority('job:add')") 61 | @ControllerEndpoint(operation = "添加任务",exceptionMessage = "添加任务失败") 62 | public FCResponse addJob(@RequestBody @Valid JobRequestDTO jobRequestDTO){ 63 | return this.jobService.addJob(jobRequestDTO); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/main/java/com/codeworld/fc/job/controller/JobLogController.java: -------------------------------------------------------------------------------- 1 | package com.codeworld.fc.job.controller; 2 | 3 | import com.codeworld.fc.common.annotation.ControllerEndpoint; 4 | import com.codeworld.fc.common.response.DataResponse; 5 | import com.codeworld.fc.common.response.FCResponse; 6 | import com.codeworld.fc.job.entity.JobLog; 7 | import com.codeworld.fc.job.service.JobLogService; 8 | import com.codeworld.fc.job.vo.JobLogSearchVO; 9 | import io.swagger.annotations.Api; 10 | import io.swagger.annotations.ApiOperation; 11 | import org.springframework.beans.factory.annotation.Autowired; 12 | import org.springframework.web.bind.annotation.*; 13 | 14 | import java.util.List; 15 | 16 | /** 17 | * ClassName JobLogController 18 | * Description 任务日志接口管理 19 | * Author Lenovo 20 | * Date 2020/9/25 21 | * Version 1.0 22 | **/ 23 | @RestController 24 | @RequestMapping("system-job-log") 25 | @Api(tags = "任务日志接口管理") 26 | public class JobLogController { 27 | 28 | @Autowired(required = false) 29 | private JobLogService jobLogService; 30 | 31 | @PostMapping("get-all-job-log") 32 | @ApiOperation("获取全部任务日志") 33 | @ControllerEndpoint(operation = "获取全部任务日志", exceptionMessage = "获取全部任务日志失败") 34 | public FCResponse>> getAllJobLog(@RequestBody JobLogSearchVO jobLogSearchVO) { 35 | return this.jobLogService.getAllJobLog(jobLogSearchVO); 36 | } 37 | 38 | @PostMapping("delete-job-log") 39 | @ApiOperation("删除任务日志") 40 | @ControllerEndpoint(operation = "删除任务日志",exceptionMessage = "删除任务日志失败") 41 | public FCResponse deleteJobLog(@RequestParam("id") Long id){ 42 | return this.jobLogService.deleteJobLog(id); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/com/codeworld/fc/job/dto/JobRequestDTO.java: -------------------------------------------------------------------------------- 1 | package com.codeworld.fc.job.dto; 2 | 3 | import io.swagger.annotations.ApiModel; 4 | import io.swagger.annotations.ApiModelProperty; 5 | import lombok.Data; 6 | 7 | import javax.validation.constraints.NotNull; 8 | 9 | /** 10 | * ClassName JobRequestDTO 11 | * Description 任务请求DTO 12 | * Author Lenovo 13 | * Date 2020/9/25 14 | * Version 1.0 15 | **/ 16 | @Data 17 | @ApiModel("任务请求DTO") 18 | public class JobRequestDTO { 19 | 20 | @ApiModelProperty("任务名称") 21 | @NotNull(message = "任务名称为空") 22 | private String beanName; 23 | 24 | @ApiModelProperty("参数名称") 25 | @NotNull(message = "参数名称为空") 26 | private String methodName; 27 | 28 | @ApiModelProperty("参数") 29 | @NotNull(message = "参数为空") 30 | private String params; 31 | 32 | @ApiModelProperty("cron表达式") 33 | @NotNull(message = "Cron表达式为空") 34 | private String cronExpression; 35 | 36 | @ApiModelProperty("状态") 37 | @NotNull(message = "状态错误") 38 | private String status; 39 | 40 | @ApiModelProperty("备注") 41 | @NotNull(message = "备注为空") 42 | private String remark; 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/com/codeworld/fc/job/entity/Job.java: -------------------------------------------------------------------------------- 1 | package com.codeworld.fc.job.entity; 2 | 3 | import com.fasterxml.jackson.annotation.JsonFormat; 4 | import io.swagger.annotations.ApiModel; 5 | import io.swagger.annotations.ApiModelProperty; 6 | import lombok.Data; 7 | 8 | import java.io.Serializable; 9 | import java.util.Date; 10 | 11 | /** 12 | * ClassName Job 13 | * Description 任务基本类 14 | * Author Lenovo 15 | * Date 2020/9/21 16 | * Version 1.0 17 | **/ 18 | @Data 19 | @ApiModel("任务基本类") 20 | public class Job implements Serializable { 21 | 22 | private static final long serialVersionUID = -4112400672553547303L; 23 | 24 | /** 25 | * 任务调度参数Key 26 | */ 27 | public static final String 28 | JOB_PARAM_KEY = "JOB_PARAM_KEY"; 29 | 30 | public enum ScheduleStatus { 31 | /** 32 | * 正常 33 | */ 34 | NORMAL("1"), 35 | /** 36 | * 暂停 37 | */ 38 | PAUSE("0"); 39 | 40 | private String value; 41 | 42 | ScheduleStatus(String value) { 43 | this.value = value; 44 | } 45 | 46 | public String getValue() { 47 | return value; 48 | } 49 | } 50 | 51 | @ApiModelProperty("任务调度主键Id") 52 | private Long jobId; 53 | 54 | @ApiModelProperty("任务名称") 55 | private String beanName; 56 | 57 | @ApiModelProperty("参数名称") 58 | private String methodName; 59 | 60 | @ApiModelProperty("参数") 61 | private String params; 62 | 63 | @ApiModelProperty("cron表达式") 64 | private String cronExpression; 65 | 66 | @ApiModelProperty("状态") 67 | private String status; 68 | 69 | @ApiModelProperty("备注") 70 | private String remark; 71 | 72 | @ApiModelProperty("创建时间") 73 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8") 74 | private Date createTime; 75 | 76 | @ApiModelProperty("更新时间") 77 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8") 78 | private Date updateTime; 79 | } 80 | -------------------------------------------------------------------------------- /src/main/java/com/codeworld/fc/job/entity/JobLog.java: -------------------------------------------------------------------------------- 1 | package com.codeworld.fc.job.entity; 2 | 3 | import com.fasterxml.jackson.annotation.JsonFormat; 4 | import io.swagger.annotations.ApiModel; 5 | import io.swagger.annotations.ApiModelProperty; 6 | import lombok.Data; 7 | 8 | import java.util.Date; 9 | 10 | /** 11 | * ClassName JobLog 12 | * Description 任务日志类 13 | * Author Lenovo 14 | * Date 2020/9/24 15 | * Version 1.0 16 | **/ 17 | @Data 18 | @ApiModel("任务日志类") 19 | public class JobLog { 20 | 21 | @ApiModelProperty("任务日志主键Id") 22 | private Long jobLogId; 23 | 24 | @ApiModelProperty("任务Id") 25 | private Long jobId; 26 | 27 | @ApiModelProperty("任务Bean名称") 28 | private String jobBeanName; 29 | 30 | @ApiModelProperty("任务方法名称") 31 | private String jobMethodName; 32 | 33 | @ApiModelProperty("任务参数") 34 | private String jobParams; 35 | 36 | @ApiModelProperty("任务状态") 37 | private Integer jobStatus; 38 | 39 | @ApiModelProperty("错误信息") 40 | private String jobLogError; 41 | 42 | @ApiModelProperty("任务耗时") 43 | private Long jobLogTime; 44 | 45 | @ApiModelProperty("创建时间") 46 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8") 47 | private Date jobLogCreateTime; 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/com/codeworld/fc/job/mapper/JobLogMapper.java: -------------------------------------------------------------------------------- 1 | package com.codeworld.fc.job.mapper; 2 | 3 | import com.codeworld.fc.job.entity.JobLog; 4 | import com.codeworld.fc.job.vo.JobLogSearchVO; 5 | import org.apache.ibatis.annotations.Mapper; 6 | import org.springframework.stereotype.Repository; 7 | 8 | import java.util.List; 9 | 10 | @Mapper 11 | @Repository 12 | public interface JobLogMapper { 13 | /** 14 | * 添加任务执行日志 15 | * @param jobLog 16 | */ 17 | void addJobLog(JobLog jobLog); 18 | 19 | /** 20 | * 获取全部的任务日志 21 | * @param jobLogSearchVO 22 | * @return 23 | */ 24 | List getAllJobLog(JobLogSearchVO jobLogSearchVO); 25 | 26 | /** 27 | * 手动删除任务日志 28 | * @param id 29 | */ 30 | void deleteJobLog(Long id); 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/com/codeworld/fc/job/mapper/JobMapper.java: -------------------------------------------------------------------------------- 1 | package com.codeworld.fc.job.mapper; 2 | 3 | import com.codeworld.fc.job.entity.Job; 4 | import com.codeworld.fc.job.vo.JobSearchVO; 5 | import org.apache.ibatis.annotations.Mapper; 6 | import org.springframework.stereotype.Repository; 7 | 8 | import java.util.List; 9 | 10 | @Mapper 11 | @Repository 12 | public interface JobMapper { 13 | /** 14 | * 获取所有任务 15 | * @param jobSearchVO 16 | * @return 17 | */ 18 | List getAllJob(JobSearchVO jobSearchVO); 19 | 20 | /** 21 | * 更新任务状态 22 | * @param job 23 | */ 24 | void updateJobStatus(Job job); 25 | 26 | /** 27 | * 根据Id获取任务 28 | * @param jobId 29 | * @return 30 | */ 31 | Job getJobById(Long jobId); 32 | 33 | /** 34 | * 删除任务 35 | * @param jobId 36 | */ 37 | void deleteJobById(Long jobId); 38 | 39 | /** 40 | * 添加任务 41 | * @param job 42 | */ 43 | void addJob(Job job); 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/com/codeworld/fc/job/service/JobLogService.java: -------------------------------------------------------------------------------- 1 | package com.codeworld.fc.job.service; 2 | 3 | import com.codeworld.fc.common.response.DataResponse; 4 | import com.codeworld.fc.common.response.FCResponse; 5 | import com.codeworld.fc.job.entity.JobLog; 6 | import com.codeworld.fc.job.vo.JobLogSearchVO; 7 | 8 | import java.util.List; 9 | 10 | public interface JobLogService { 11 | /** 12 | * 添加任务执行日志 13 | * @param jobLog 14 | */ 15 | void addJobLog(JobLog jobLog); 16 | 17 | /** 18 | * 获取全部任务日志 19 | * @param jobLogSearchVO 20 | * @return 21 | */ 22 | FCResponse>> getAllJobLog(JobLogSearchVO jobLogSearchVO); 23 | 24 | /** 25 | * 删除任务日志 26 | * @param id 27 | * @return 28 | */ 29 | FCResponse deleteJobLog(Long id); 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/com/codeworld/fc/job/service/JobService.java: -------------------------------------------------------------------------------- 1 | package com.codeworld.fc.job.service; 2 | 3 | import com.codeworld.fc.common.response.DataResponse; 4 | import com.codeworld.fc.common.response.FCResponse; 5 | import com.codeworld.fc.job.dto.JobRequestDTO; 6 | import com.codeworld.fc.job.entity.Job; 7 | import com.codeworld.fc.job.vo.JobSearchVO; 8 | 9 | import java.util.List; 10 | 11 | /** 12 | * ClassName JobService 13 | * Description TODO 14 | * Author Lenovo 15 | * Date 2020/9/21 16 | * Version 1.0 17 | **/ 18 | public interface JobService { 19 | /** 20 | * 获取全部任务 21 | * @return 22 | */ 23 | FCResponse>> getAllJob(JobSearchVO jobSearchVO); 24 | 25 | /** 26 | * 启用或停用任务 27 | * @param jobId 28 | * @param status 29 | * @return 30 | */ 31 | FCResponse updateJobStatus(Long jobId, Integer status); 32 | 33 | /** 34 | * 删除任务 35 | * @param jobId 36 | * @return 37 | */ 38 | FCResponse deleteJob(Long jobId); 39 | 40 | /** 41 | * 添加任务 42 | * @param jobRequestDTO 43 | * @return 44 | */ 45 | FCResponse addJob(JobRequestDTO jobRequestDTO); 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/com/codeworld/fc/job/service/impl/JobLogServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.codeworld.fc.job.service.impl; 2 | 3 | import com.codeworld.fc.common.enums.HttpFcStatus; 4 | import com.codeworld.fc.common.enums.HttpMsg; 5 | import com.codeworld.fc.common.exception.FCException; 6 | import com.codeworld.fc.common.response.DataResponse; 7 | import com.codeworld.fc.common.response.FCResponse; 8 | import com.codeworld.fc.job.entity.JobLog; 9 | import com.codeworld.fc.job.mapper.JobLogMapper; 10 | import com.codeworld.fc.job.service.JobLogService; 11 | import com.codeworld.fc.job.vo.JobLogSearchVO; 12 | import com.github.pagehelper.PageHelper; 13 | import com.github.pagehelper.PageInfo; 14 | import org.springframework.beans.factory.annotation.Autowired; 15 | import org.springframework.stereotype.Service; 16 | import org.springframework.util.CollectionUtils; 17 | 18 | import java.util.List; 19 | 20 | /** 21 | * ClassName JobLogServiceImpl 22 | * Description 23 | * Author Lenovo 24 | * Date 2020/9/25 25 | * Version 1.0 26 | **/ 27 | @Service 28 | public class JobLogServiceImpl implements JobLogService { 29 | 30 | @Autowired(required = false) 31 | private JobLogMapper jobLogMapper; 32 | 33 | /** 34 | * 添加任务执行日志 35 | * 36 | * @param jobLog 37 | */ 38 | @Override 39 | public void addJobLog(JobLog jobLog) { 40 | 41 | this.jobLogMapper.addJobLog(jobLog); 42 | } 43 | 44 | /** 45 | * 获取全部任务日志 46 | * 47 | * @param jobLogSearchVO 48 | * @return 49 | */ 50 | @Override 51 | public FCResponse>> getAllJobLog(JobLogSearchVO jobLogSearchVO) { 52 | PageHelper.startPage(jobLogSearchVO.getPage(), jobLogSearchVO.getLimit()); 53 | try { 54 | List jobLogs = this.jobLogMapper.getAllJobLog(jobLogSearchVO); 55 | if (CollectionUtils.isEmpty(jobLogs)) { 56 | return FCResponse.dataResponse(HttpFcStatus.DATASUCCESSGET.getCode(), HttpMsg.jobLog.JOB_LOG_DATA_EMPTY.getMsg(), DataResponse.dataResponse(jobLogs, 0L)); 57 | } 58 | PageInfo pageInfo = new PageInfo<>(jobLogs); 59 | return FCResponse.dataResponse(HttpFcStatus.DATASUCCESSGET.getCode(), HttpMsg.jobLog.JOB_LOG_DATA_SUCCESS.getMsg(), DataResponse.dataResponse(pageInfo.getList(), pageInfo.getTotal())); 60 | } catch (Exception e) { 61 | e.printStackTrace(); 62 | throw new FCException("系统错误"); 63 | } 64 | } 65 | 66 | /** 67 | * 删除任务日志 68 | * 69 | * @param id 70 | * @return 71 | */ 72 | @Override 73 | public FCResponse deleteJobLog(Long id) { 74 | 75 | if (id == null || id <= 0){ 76 | return FCResponse.dataResponse(HttpFcStatus.PARAMSERROR.getCode(),HttpMsg.jobLog.JOB_LOG_PARAMS_ERROR.getMsg()); 77 | } 78 | try { 79 | this.jobLogMapper.deleteJobLog(id); 80 | return FCResponse.dataResponse(HttpFcStatus.DATASUCCESSGET.getCode(),HttpMsg.jobLog.JOB_LOG_DELETE_SUCCESS.getMsg()); 81 | }catch (Exception e){ 82 | e.printStackTrace(); 83 | throw new FCException("系统错误"); 84 | } 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /src/main/java/com/codeworld/fc/job/task/TestTask.java: -------------------------------------------------------------------------------- 1 | package com.codeworld.fc.job.task; 2 | 3 | import com.codeworld.fc.system.log.mapper.LogMapper; 4 | import org.slf4j.Logger; 5 | import org.slf4j.LoggerFactory; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.stereotype.Component; 8 | 9 | /** 10 | * ClassName TestTask 11 | * Description TODO 12 | * Author Lenovo 13 | * Date 2020/9/22 14 | * Version 1.0 15 | **/ 16 | @Component 17 | public class TestTask { 18 | 19 | @Autowired(required = false) 20 | private LogMapper logMapper; 21 | 22 | private static final Logger LOGGER = LoggerFactory.getLogger(TestTask.class); 23 | 24 | public void test(String params) { 25 | LOGGER.info("我是带参数的test方法,正在被执行,参数为:{}" , params); 26 | } 27 | public void test1() { 28 | LOGGER.info("我是不带参数的test1方法,正在被执行"); 29 | } 30 | 31 | public void clearSystemLog(){ 32 | // 定时清理日志 33 | try { 34 | LOGGER.info("日志清理开始"); 35 | 36 | this.logMapper.deleteAllLog(); 37 | 38 | LOGGER.info("日志清理完成"); 39 | 40 | }catch (Exception e){ 41 | 42 | LOGGER.error("日志清理失败---系统错误"); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/com/codeworld/fc/job/util/ScheduleJob.java: -------------------------------------------------------------------------------- 1 | package com.codeworld.fc.job.util; 2 | 3 | import com.codeworld.fc.common.enums.StatusEnum; 4 | import com.codeworld.fc.job.entity.Job; 5 | import com.codeworld.fc.job.entity.JobLog; 6 | import com.codeworld.fc.job.service.JobLogService; 7 | import com.codeworld.fc.utils.IDGeneratorUtil; 8 | import com.codeworld.fc.utils.SpringContextUtil; 9 | import org.apache.commons.lang3.StringUtils; 10 | import org.quartz.JobExecutionContext; 11 | import org.quartz.JobExecutionException; 12 | import org.slf4j.Logger; 13 | import org.slf4j.LoggerFactory; 14 | import org.springframework.beans.factory.annotation.Autowired; 15 | import org.springframework.scheduling.quartz.QuartzJobBean; 16 | 17 | import java.util.Date; 18 | import java.util.concurrent.ExecutionException; 19 | import java.util.concurrent.ExecutorService; 20 | import java.util.concurrent.Executors; 21 | import java.util.concurrent.Future; 22 | 23 | /** 24 | * ClassName ScheduleJob 25 | * Description 定时任务 26 | * Author Lenovo 27 | * Date 2020/9/22 28 | * Version 1.0 29 | **/ 30 | public class ScheduleJob extends QuartzJobBean { 31 | 32 | private ExecutorService service = Executors.newSingleThreadExecutor(); 33 | 34 | private static final Logger LOGGER = LoggerFactory.getLogger(ScheduleJob.class); 35 | 36 | private JobLogService jobLogService = SpringContextUtil.getBean(JobLogService.class); 37 | 38 | 39 | /** 40 | * 执行任务 41 | * 42 | * @param jobExecutionContext 43 | * @throws JobExecutionException 44 | */ 45 | @Override 46 | protected void executeInternal(JobExecutionContext jobExecutionContext) { 47 | 48 | Job job = (Job) jobExecutionContext.getMergedJobDataMap().get(Job.JOB_PARAM_KEY); 49 | JobLog jobLog = new JobLog(); 50 | jobLog.setJobLogId(IDGeneratorUtil.getNextId()); 51 | jobLog.setJobId(job.getJobId()); 52 | jobLog.setJobBeanName(job.getBeanName()); 53 | jobLog.setJobMethodName(job.getMethodName()); 54 | jobLog.setJobParams(job.getParams()); 55 | jobLog.setJobLogCreateTime(new Date()); 56 | long startTime = System.currentTimeMillis(); 57 | try { 58 | LOGGER.info("任务准备执行,任务ID:{}", job.getJobId()); 59 | ScheduleRunnable scheduleRunnable = new ScheduleRunnable(job.getBeanName(), job.getMethodName(), job.getParams()); 60 | Future submit = service.submit(scheduleRunnable); 61 | submit.get(); 62 | long time = System.currentTimeMillis() - startTime; 63 | jobLog.setJobLogTime(time); 64 | // 任务状态 65 | jobLog.setJobStatus(StatusEnum.JOB_SUCCESS); 66 | LOGGER.info("任务执行完毕,任务ID:{} 总共耗时:{} 毫秒", job.getJobId(), time); 67 | } catch (Exception e) { 68 | LOGGER.info("任务执行失败,任务ID:{}, 失败原因:{}", job.getJobId(),StringUtils.substring(e.toString(), 0, 2000)); 69 | long time = System.currentTimeMillis() - startTime; 70 | jobLog.setJobLogTime(time); 71 | jobLog.setJobStatus(StatusEnum.JOB_FAIL); 72 | jobLog.setJobLogError(StringUtils.substring(e.toString(), 0, 2000)); 73 | } finally { 74 | this.jobLogService.addJobLog(jobLog); 75 | } 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/main/java/com/codeworld/fc/job/util/ScheduleRunnable.java: -------------------------------------------------------------------------------- 1 | package com.codeworld.fc.job.util; 2 | 3 | import com.codeworld.fc.utils.SpringContextUtil; 4 | import org.apache.commons.lang3.StringUtils; 5 | import org.slf4j.Logger; 6 | import org.slf4j.LoggerFactory; 7 | import org.springframework.util.ReflectionUtils; 8 | 9 | import java.lang.reflect.Method; 10 | 11 | /** 12 | * ClassName ScheduleRunnable 13 | * Description TODO 14 | * Author Lenovo 15 | * Date 2020/9/22 16 | * Version 1.0 17 | **/ 18 | public class ScheduleRunnable implements Runnable { 19 | 20 | private static final Logger LOGGER = LoggerFactory.getLogger(ScheduleRunnable.class); 21 | private Object target; 22 | private Method method; 23 | private String params; 24 | 25 | ScheduleRunnable(String beanName, String methodName, String params) throws NoSuchMethodException, SecurityException { 26 | this.target = SpringContextUtil.getBean(beanName); 27 | this.params = params; 28 | 29 | if (StringUtils.isNotBlank(params)) { 30 | this.method = target.getClass().getDeclaredMethod(methodName, String.class); 31 | } else { 32 | this.method = target.getClass().getDeclaredMethod(methodName); 33 | } 34 | } 35 | 36 | @Override 37 | public void run() { 38 | try { 39 | ReflectionUtils.makeAccessible(method); 40 | if (StringUtils.isNotBlank(params)) { 41 | method.invoke(target, params); 42 | } else { 43 | method.invoke(target); 44 | } 45 | } catch (Exception e) { 46 | LOGGER.error("执行定时任务失败", e); 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/com/codeworld/fc/job/vo/JobLogSearchVO.java: -------------------------------------------------------------------------------- 1 | package com.codeworld.fc.job.vo; 2 | 3 | import com.codeworld.fc.common.base.PageQuery; 4 | import com.fasterxml.jackson.annotation.JsonFormat; 5 | import io.swagger.annotations.ApiModel; 6 | import io.swagger.annotations.ApiModelProperty; 7 | import lombok.Data; 8 | 9 | import java.util.Date; 10 | 11 | /** 12 | * ClassName JobSearchVO 13 | * Description 任务日志搜索基本类 14 | * Author Lenovo 15 | * Date 2020/9/21 16 | * Version 1.0 17 | **/ 18 | @Data 19 | @ApiModel("任务日志搜索基本类") 20 | public class JobLogSearchVO extends PageQuery { 21 | 22 | @ApiModelProperty("任务名称") 23 | private String jobBeanName; 24 | 25 | @ApiModelProperty("参数名称") 26 | private String jobMethodName; 27 | 28 | @ApiModelProperty("状态") 29 | private Integer status; 30 | 31 | @ApiModelProperty("创建时间") 32 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8") 33 | private Date startTime; 34 | 35 | @ApiModelProperty("结束时间") 36 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8") 37 | private Date endTime; 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/com/codeworld/fc/job/vo/JobSearchVO.java: -------------------------------------------------------------------------------- 1 | package com.codeworld.fc.job.vo; 2 | 3 | import com.codeworld.fc.common.base.PageQuery; 4 | import com.fasterxml.jackson.annotation.JsonFormat; 5 | import io.swagger.annotations.ApiModel; 6 | import io.swagger.annotations.ApiModelProperty; 7 | import lombok.Data; 8 | 9 | import java.util.Date; 10 | 11 | /** 12 | * ClassName JobSearchVO 13 | * Description 任务搜索基本类 14 | * Author Lenovo 15 | * Date 2020/9/21 16 | * Version 1.0 17 | **/ 18 | @Data 19 | @ApiModel("任务搜索基本类") 20 | public class JobSearchVO extends PageQuery { 21 | 22 | @ApiModelProperty("任务名称") 23 | private String beanName; 24 | 25 | @ApiModelProperty("参数名称") 26 | private String methodName; 27 | 28 | @ApiModelProperty("状态") 29 | private Integer status; 30 | 31 | @ApiModelProperty("创建时间") 32 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8") 33 | private Date createTime; 34 | 35 | @ApiModelProperty("更新时间") 36 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8") 37 | private Date updateTime; 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/com/codeworld/fc/monitor/controller/ActiveUserController.java: -------------------------------------------------------------------------------- 1 | package com.codeworld.fc.monitor.controller; 2 | 3 | import com.codeworld.fc.common.annotation.ControllerEndpoint; 4 | import com.codeworld.fc.common.response.DataResponse; 5 | import com.codeworld.fc.common.response.FCResponse; 6 | import com.codeworld.fc.monitor.service.ActiveUserService; 7 | import com.codeworld.fc.system.user.dto.UserInfoResponse; 8 | import io.swagger.annotations.Api; 9 | import io.swagger.annotations.ApiOperation; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.web.bind.annotation.GetMapping; 12 | import org.springframework.web.bind.annotation.RequestMapping; 13 | import org.springframework.web.bind.annotation.RequestParam; 14 | import org.springframework.web.bind.annotation.RestController; 15 | 16 | import java.util.List; 17 | 18 | /** 19 | * ClassName ActiveUserController 20 | * Description 在线用户接口管理 21 | * Author Lenovo 22 | * Date 2020/10/16 23 | * Version 1.0 24 | **/ 25 | @RestController 26 | @RequestMapping("system-monitor") 27 | @Api(tags = "在线用户管理接口") 28 | public class ActiveUserController { 29 | 30 | @Autowired(required = false) 31 | private ActiveUserService activeUserService; 32 | 33 | 34 | @GetMapping("get-active-user-count") 35 | @ApiOperation("获取在线用户数量") 36 | @ControllerEndpoint(operation = "获取在线用户数量",exceptionMessage = "获取在线用户数量失败") 37 | public FCResponse getActiveUserCount(){ 38 | return this.activeUserService.getActiveUserCount(); 39 | } 40 | 41 | @GetMapping("get-all-active-user") 42 | @ApiOperation("获取全部在线用户信息") 43 | @ControllerEndpoint(operation = "获取全部在线用户信息",exceptionMessage = "获取全部在线用户信息失败") 44 | public FCResponse>> getAllActiveUser(){ 45 | return this.activeUserService.getAllActiveUser(); 46 | } 47 | 48 | @GetMapping("offline-user-id") 49 | @ApiOperation("剔除用户下线") 50 | @ControllerEndpoint(operation = "剔除用户下线",exceptionMessage = "剔除用户下线失败") 51 | public FCResponse offlineUser(@RequestParam("userId") Long userId){ 52 | return this.activeUserService.offlineUser(userId); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/com/codeworld/fc/monitor/controller/HttpTraceController.java: -------------------------------------------------------------------------------- 1 | package com.codeworld.fc.monitor.controller; 2 | 3 | import com.codeworld.fc.common.annotation.ControllerEndpoint; 4 | import com.codeworld.fc.common.response.FCResponse; 5 | import com.codeworld.fc.monitor.vo.HttpTraceSearchVO; 6 | import com.codeworld.fc.monitor.entity.FcHttpTrace; 7 | import com.codeworld.fc.monitor.service.HttpTraceService; 8 | import io.swagger.annotations.Api; 9 | import io.swagger.annotations.ApiOperation; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.web.bind.annotation.PostMapping; 12 | import org.springframework.web.bind.annotation.RequestBody; 13 | import org.springframework.web.bind.annotation.RequestMapping; 14 | import org.springframework.web.bind.annotation.RestController; 15 | 16 | import java.util.List; 17 | 18 | /** 19 | * ClassName HttpTraceController 20 | * Description 请求追踪接口管理 21 | * Author Lenovo 22 | * Date 2020/10/9 23 | * Version 1.0 24 | **/ 25 | @RestController 26 | @RequestMapping("system-monitor") 27 | @Api(tags = "请求追踪接口管理") 28 | public class HttpTraceController { 29 | 30 | @Autowired(required = false) 31 | private HttpTraceService httpTraceService; 32 | 33 | @PostMapping("get-http-trace") 34 | @ApiOperation("查询请求") 35 | @ControllerEndpoint(operation = "查询请求",exceptionMessage = "查询请求失败") 36 | public FCResponse> getHttpTrace(@RequestBody HttpTraceSearchVO httpTraceSearchVO){ 37 | return this.httpTraceService.getHttpTrace(httpTraceSearchVO); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/com/codeworld/fc/monitor/controller/LoginLogController.java: -------------------------------------------------------------------------------- 1 | package com.codeworld.fc.monitor.controller; 2 | 3 | import com.codeworld.fc.common.annotation.ControllerEndpoint; 4 | import com.codeworld.fc.common.response.DataResponse; 5 | import com.codeworld.fc.common.response.FCResponse; 6 | import com.codeworld.fc.monitor.entity.LoginLog; 7 | import com.codeworld.fc.monitor.service.LoginLogService; 8 | import com.codeworld.fc.monitor.vo.LoginLogSearchVO; 9 | import io.swagger.annotations.ApiOperation; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.web.bind.annotation.*; 12 | 13 | import java.util.List; 14 | 15 | /** 16 | * ClassName LoginLogControlller 17 | * Description 登录日志接口管理 18 | * Author Lenovo 19 | * Date 2020/10/10 20 | * Version 1.0 21 | **/ 22 | @RestController 23 | @RequestMapping("system-login-log") 24 | public class LoginLogController { 25 | 26 | @Autowired(required = false) 27 | private LoginLogService loginLogService; 28 | 29 | 30 | @PostMapping("get-all-login-log") 31 | @ApiOperation("获取登录日志") 32 | @ControllerEndpoint(operation = "获取登录日志",exceptionMessage = "获取登录日志失败") 33 | public FCResponse>> getAllLoginLog(@RequestBody LoginLogSearchVO loginLogSearchVO){ 34 | return this.loginLogService.getAllLoginLog(loginLogSearchVO); 35 | } 36 | 37 | @PostMapping("delete-login-log") 38 | @ApiOperation("删除登录日志") 39 | @ControllerEndpoint(operation = "删除登录日志",exceptionMessage = "删除登录日志失败") 40 | public FCResponse deleteLoginLog(@RequestParam("id") Long id){ 41 | return this.loginLogService.deleteLoginLog(id); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/com/codeworld/fc/monitor/endpoint/FcHttpTraceEndPoint.java: -------------------------------------------------------------------------------- 1 | package com.codeworld.fc.monitor.endpoint; 2 | 3 | import com.codeworld.fc.common.annotation.FcEndPoint; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.boot.actuate.trace.http.HttpTrace; 6 | 7 | import java.util.List; 8 | 9 | /** 10 | * ClassName FcHttpTraceEndPoint 11 | * Description TODO 12 | * Author Lenovo 13 | * Date 2020/10/9 14 | * Version 1.0 15 | **/ 16 | @FcEndPoint 17 | public class FcHttpTraceEndPoint { 18 | 19 | @Autowired(required = false) 20 | private RemoteHttpTraceRepository traceRepository; 21 | 22 | public FcHttpTraceEndPoint(RemoteHttpTraceRepository repository) { 23 | this.traceRepository = repository; 24 | } 25 | 26 | public FcHttpTraceDescriptor traces() { 27 | 28 | return new FcHttpTraceDescriptor(this.traceRepository.findAll()); 29 | } 30 | 31 | public static final class FcHttpTraceDescriptor { 32 | 33 | private final List traces; 34 | 35 | public FcHttpTraceDescriptor(List traces) { 36 | this.traces = traces; 37 | } 38 | 39 | public List getTraces() { 40 | 41 | return this.traces; 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/com/codeworld/fc/monitor/endpoint/RemoteHttpTraceRepository.java: -------------------------------------------------------------------------------- 1 | package com.codeworld.fc.monitor.endpoint; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.springframework.boot.actuate.trace.http.HttpTrace; 5 | import org.springframework.boot.actuate.trace.http.HttpTraceRepository; 6 | import org.springframework.stereotype.Component; 7 | 8 | import java.util.ArrayList; 9 | import java.util.Collections; 10 | import java.util.LinkedList; 11 | import java.util.List; 12 | 13 | /** 14 | * ClassName RemoteHttpTraceRepository 15 | * Description TODO 16 | * Author Lenovo 17 | * Date 2020/10/9 18 | * Version 1.0 19 | **/ 20 | @Component 21 | public class RemoteHttpTraceRepository implements HttpTraceRepository { 22 | 23 | 24 | private int capacity = 100; 25 | private boolean reverse = true; 26 | private final List traces = new LinkedList(); 27 | 28 | public RemoteHttpTraceRepository() { 29 | } 30 | 31 | public void setReverse(boolean reverse) { 32 | synchronized(this.traces) { 33 | this.reverse = reverse; 34 | } 35 | } 36 | 37 | public void setCapacity(int capacity) { 38 | synchronized(this.traces) { 39 | this.capacity = capacity; 40 | } 41 | } 42 | 43 | public List findAll() { 44 | synchronized(this.traces) { 45 | return Collections.unmodifiableList(new ArrayList(this.traces)); 46 | } 47 | } 48 | 49 | public void add(HttpTrace trace) { 50 | synchronized(this.traces) { 51 | while(this.traces.size() >= this.capacity) { 52 | this.traces.remove(this.reverse ? this.capacity - 1 : 0); 53 | } 54 | 55 | if (this.reverse) { 56 | this.traces.add(0, trace); 57 | } else { 58 | this.traces.add(trace); 59 | } 60 | 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/main/java/com/codeworld/fc/monitor/entity/FcHttpTrace.java: -------------------------------------------------------------------------------- 1 | package com.codeworld.fc.monitor.entity; 2 | 3 | import io.swagger.annotations.ApiModel; 4 | import io.swagger.annotations.ApiModelProperty; 5 | import lombok.Data; 6 | 7 | import java.net.URI; 8 | 9 | /** 10 | * ClassName FcHttpTrace 11 | * Description 请求追踪基本类 12 | * Author Lenovo 13 | * Date 2020/10/9 14 | * Version 1.0 15 | **/ 16 | @Data 17 | @ApiModel("请求追踪基本类") 18 | public class FcHttpTrace { 19 | 20 | @ApiModelProperty("请求时间") 21 | private String requestTime; 22 | 23 | @ApiModelProperty("请求方法") 24 | private String method; 25 | 26 | @ApiModelProperty("请求Url") 27 | private URI url; 28 | 29 | @ApiModelProperty("响应状态") 30 | private int status; 31 | 32 | @ApiModelProperty("请求耗时") 33 | private Long timeTaken; 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/com/codeworld/fc/monitor/listener/ActiveUserListener.java: -------------------------------------------------------------------------------- 1 | package com.codeworld.fc.monitor.listener; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | 6 | import javax.servlet.annotation.WebListener; 7 | import javax.servlet.http.HttpSessionBindingEvent; 8 | import javax.servlet.http.HttpSessionBindingListener; 9 | import javax.servlet.http.HttpSessionEvent; 10 | import javax.servlet.http.HttpSessionListener; 11 | import java.util.Date; 12 | import java.util.HashMap; 13 | import java.util.Vector; 14 | import java.util.concurrent.atomic.AtomicInteger; 15 | 16 | /** 17 | * ClassName ActiveUserListener 18 | * Description TODO 19 | * Author Lenovo 20 | * Date 2020/10/16 21 | * Version 1.0 22 | **/ 23 | public class ActiveUserListener implements HttpSessionListener { 24 | 25 | private static final Logger LOGGER = LoggerFactory.getLogger(ActiveUserListener.class); 26 | 27 | public static AtomicInteger userCount = new AtomicInteger(0); 28 | 29 | 30 | 31 | @Override 32 | public void sessionCreated(HttpSessionEvent se) { 33 | 34 | userCount.getAndIncrement(); 35 | } 36 | 37 | @Override 38 | public void sessionDestroyed(HttpSessionEvent se) { 39 | userCount.getAndDecrement(); 40 | } 41 | } 42 | 43 | -------------------------------------------------------------------------------- /src/main/java/com/codeworld/fc/monitor/mapper/LoginLogMapper.java: -------------------------------------------------------------------------------- 1 | package com.codeworld.fc.monitor.mapper; 2 | 3 | import com.codeworld.fc.monitor.entity.LoginLog; 4 | import com.codeworld.fc.monitor.vo.LoginLogSearchVO; 5 | import org.apache.ibatis.annotations.Mapper; 6 | import org.springframework.stereotype.Repository; 7 | 8 | import java.util.List; 9 | 10 | @Mapper 11 | @Repository 12 | public interface LoginLogMapper { 13 | 14 | /** 15 | * 保存登录日志 16 | * @param loginLog 17 | */ 18 | void addLoginLog(LoginLog loginLog); 19 | 20 | /** 21 | * 获取登录日志 22 | * @param loginLogSearchVO 23 | * @return 24 | */ 25 | List getAllLoginLog(LoginLogSearchVO loginLogSearchVO); 26 | 27 | /** 28 | * 删除登录日志 29 | * @param id 30 | */ 31 | void deleteLoginLog(Long id); 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/com/codeworld/fc/monitor/service/ActiveUserService.java: -------------------------------------------------------------------------------- 1 | package com.codeworld.fc.monitor.service; 2 | 3 | import com.codeworld.fc.common.response.DataResponse; 4 | import com.codeworld.fc.common.response.FCResponse; 5 | import com.codeworld.fc.system.user.dto.UserInfoResponse; 6 | 7 | import java.util.List; 8 | 9 | public interface ActiveUserService { 10 | /** 11 | * 获取在线用户数量 12 | * @return 13 | */ 14 | FCResponse getActiveUserCount(); 15 | 16 | /** 17 | * 获取全部在线用户信息 18 | * @return 19 | */ 20 | FCResponse>> getAllActiveUser(); 21 | 22 | /** 23 | * 剔除用户下线 24 | * @param userId 25 | * @return 26 | */ 27 | FCResponse offlineUser(Long userId); 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/com/codeworld/fc/monitor/service/HttpTraceService.java: -------------------------------------------------------------------------------- 1 | package com.codeworld.fc.monitor.service; 2 | 3 | import com.codeworld.fc.common.response.FCResponse; 4 | import com.codeworld.fc.monitor.vo.HttpTraceSearchVO; 5 | import com.codeworld.fc.monitor.entity.FcHttpTrace; 6 | 7 | import java.util.List; 8 | 9 | public interface HttpTraceService { 10 | /** 11 | * 获取请求追踪 12 | * @return 13 | */ 14 | FCResponse> getHttpTrace(HttpTraceSearchVO httpTraceSearchVO); 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/com/codeworld/fc/monitor/service/LoginLogService.java: -------------------------------------------------------------------------------- 1 | package com.codeworld.fc.monitor.service; 2 | 3 | import com.codeworld.fc.common.response.DataResponse; 4 | import com.codeworld.fc.common.response.FCResponse; 5 | import com.codeworld.fc.monitor.entity.LoginLog; 6 | import com.codeworld.fc.monitor.vo.LoginLogSearchVO; 7 | 8 | import java.util.List; 9 | 10 | public interface LoginLogService { 11 | 12 | /** 13 | * 添加登录日志 14 | * @param loginLog 15 | */ 16 | void addLoginLog(LoginLog loginLog); 17 | 18 | /** 19 | * 获取登录日志 20 | * @return 21 | */ 22 | FCResponse>> getAllLoginLog(LoginLogSearchVO loginLogSearchVO); 23 | 24 | /** 25 | * 删除登录日志 26 | * @param id 27 | * @return 28 | */ 29 | FCResponse deleteLoginLog(Long id); 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/com/codeworld/fc/monitor/service/impl/ActiveUserServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.codeworld.fc.monitor.service.impl; 2 | 3 | import com.codeworld.fc.common.enums.HttpFcStatus; 4 | import com.codeworld.fc.common.enums.HttpMsg; 5 | import com.codeworld.fc.common.enums.StatusEnum; 6 | import com.codeworld.fc.common.exception.FCException; 7 | import com.codeworld.fc.common.response.DataResponse; 8 | import com.codeworld.fc.common.response.FCResponse; 9 | import com.codeworld.fc.monitor.listener.ActiveUserListener; 10 | import com.codeworld.fc.monitor.service.ActiveUserService; 11 | import com.codeworld.fc.system.user.dto.UserInfoResponse; 12 | import com.codeworld.fc.utils.JsonUtils; 13 | import org.springframework.beans.factory.annotation.Autowired; 14 | import org.springframework.data.redis.core.StringRedisTemplate; 15 | import org.springframework.stereotype.Service; 16 | 17 | import java.util.ArrayList; 18 | import java.util.Iterator; 19 | import java.util.List; 20 | import java.util.Set; 21 | import java.util.concurrent.TimeUnit; 22 | import java.util.concurrent.atomic.AtomicInteger; 23 | 24 | /** 25 | * ClassName ActiveUserServiceImpl 26 | * Description TODO 27 | * Author Lenovo 28 | * Date 2020/10/16 29 | * Version 1.0 30 | **/ 31 | @Service 32 | public class ActiveUserServiceImpl implements ActiveUserService { 33 | 34 | @Autowired(required = false) 35 | private StringRedisTemplate stringRedisTemplate; 36 | 37 | private final String USER_INFO = "USER_INFO:USER:ID:"; 38 | 39 | /** 40 | * 获取在线用户数量 41 | * 42 | * @return 43 | */ 44 | @Override 45 | public FCResponse getActiveUserCount() { 46 | return FCResponse.dataResponse(HttpFcStatus.DATASUCCESSGET.getCode(), HttpMsg.activeUser.ACTIVE_USER_COUNT_GET_SUCCESS.getMsg(), ActiveUserListener.userCount.get()); 47 | } 48 | 49 | /** 50 | * 获取全部在线用户信息 51 | * 52 | * @return 53 | */ 54 | @Override 55 | public FCResponse>> getAllActiveUser() { 56 | 57 | List userInfoResponses = new ArrayList<>(10); 58 | try { 59 | Set keys = this.stringRedisTemplate.keys("*"); 60 | Iterator iterator = keys.iterator(); 61 | while (iterator.hasNext()) { 62 | String json = this.stringRedisTemplate.opsForValue().get(iterator.next()); 63 | UserInfoResponse userInfoResponse = JsonUtils.parse(json, UserInfoResponse.class); 64 | userInfoResponses.add(userInfoResponse); 65 | } 66 | return FCResponse.dataResponse(HttpFcStatus.DATASUCCESSGET.getCode(), HttpMsg.activeUser.ACTIVE_USER_GET_SUCCESS.getMsg(), DataResponse.dataResponse(userInfoResponses, (long) userInfoResponses.size())); 67 | } catch (Exception e) { 68 | e.printStackTrace(); 69 | throw new FCException("系统错误"); 70 | } 71 | } 72 | 73 | /** 74 | * 剔除用户下线 75 | * 76 | * @param userId 77 | * @return 78 | */ 79 | @Override 80 | public FCResponse offlineUser(Long userId) { 81 | 82 | if (userId == null || userId <= 0) { 83 | return FCResponse.dataResponse(HttpFcStatus.PARAMSERROR.getCode(), HttpMsg.user.USER_ID_ERROR.getMsg()); 84 | } 85 | // 修改用户在线状态 86 | if (!this.stringRedisTemplate.hasKey(USER_INFO + userId)) { 87 | return FCResponse.dataResponse(HttpFcStatus.VALIDATEFAILCODE.getCode(), HttpMsg.activeUser.ACTIVE_USER_OFFLINE.getMsg()); 88 | } 89 | try { 90 | String json = this.stringRedisTemplate.opsForValue().get(USER_INFO + userId); 91 | UserInfoResponse userInfoResponse = JsonUtils.parse(json, UserInfoResponse.class); 92 | userInfoResponse.setUserStatus(StatusEnum.USER_OFFLINE); 93 | json = JsonUtils.serialize(userInfoResponse); 94 | this.stringRedisTemplate.opsForValue().set(USER_INFO + userId, json, 20, TimeUnit.SECONDS); 95 | return FCResponse.dataResponse(HttpFcStatus.DATASUCCESSGET.getCode(), HttpMsg.activeUser.ACTIVE_USER_OFFLINE.getMsg()); 96 | } catch (Exception e) { 97 | e.printStackTrace(); 98 | throw new FCException("系统错误"); 99 | } 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /src/main/java/com/codeworld/fc/monitor/service/impl/HttpTraceServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.codeworld.fc.monitor.service.impl; 2 | 3 | import com.codeworld.fc.common.enums.HttpFcStatus; 4 | import com.codeworld.fc.common.enums.HttpMsg; 5 | import com.codeworld.fc.common.response.FCResponse; 6 | import com.codeworld.fc.monitor.vo.HttpTraceSearchVO; 7 | import com.codeworld.fc.monitor.endpoint.FcHttpTraceEndPoint; 8 | import com.codeworld.fc.monitor.entity.FcHttpTrace; 9 | import com.codeworld.fc.monitor.service.HttpTraceService; 10 | import com.codeworld.fc.utils.DateUtils; 11 | import org.apache.commons.lang3.StringUtils; 12 | import org.springframework.beans.factory.annotation.Autowired; 13 | import org.springframework.boot.actuate.trace.http.HttpTrace; 14 | import org.springframework.stereotype.Service; 15 | 16 | import java.util.ArrayList; 17 | import java.util.List; 18 | 19 | /** 20 | * ClassName HttpTraceServiceImpl 21 | * Description TODO 22 | * Author Lenovo 23 | * Date 2020/10/9 24 | * Version 1.0 25 | **/ 26 | @Service 27 | public class HttpTraceServiceImpl implements HttpTraceService { 28 | 29 | @Autowired(required = false) 30 | private FcHttpTraceEndPoint fcHttpTraceEndPoint; 31 | /** 32 | * 获取请求追踪 33 | * 34 | * @return 35 | */ 36 | @Override 37 | public FCResponse> getHttpTrace(HttpTraceSearchVO httpTraceSearchVO) { 38 | 39 | FcHttpTraceEndPoint.FcHttpTraceDescriptor traces = this.fcHttpTraceEndPoint.traces(); 40 | 41 | List httpTraceList = traces.getTraces(); 42 | 43 | List fcHttpTraceList = new ArrayList<>(); 44 | 45 | httpTraceList.forEach(httpTrace -> { 46 | 47 | // 创建对象 48 | FcHttpTrace fcHttpTrace = new FcHttpTrace(); 49 | 50 | fcHttpTrace.setRequestTime(DateUtils.formatInstant(httpTrace.getTimestamp(),"yyyy-MM-dd HH:mm:ss")); 51 | 52 | fcHttpTrace.setMethod(httpTrace.getRequest().getMethod()); 53 | 54 | fcHttpTrace.setStatus(httpTrace.getResponse().getStatus()); 55 | 56 | fcHttpTrace.setTimeTaken(httpTrace.getTimeTaken()); 57 | 58 | fcHttpTrace.setUrl(httpTrace.getRequest().getUri()); 59 | 60 | if (StringUtils.isNotBlank(httpTraceSearchVO.getMethod()) && StringUtils.isNotBlank(httpTraceSearchVO.getUrl())) { 61 | if (StringUtils.equalsIgnoreCase(httpTraceSearchVO.getMethod(), fcHttpTrace.getMethod()) 62 | && StringUtils.containsIgnoreCase(fcHttpTrace.getUrl().toString(), httpTraceSearchVO.getUrl())) 63 | fcHttpTraceList.add(fcHttpTrace); 64 | } else if (StringUtils.isNotBlank(httpTraceSearchVO.getMethod())) { 65 | if (StringUtils.equalsIgnoreCase(httpTraceSearchVO.getMethod(), fcHttpTrace.getMethod())) 66 | fcHttpTraceList.add(fcHttpTrace); 67 | } else if (StringUtils.isNotBlank(httpTraceSearchVO.getUrl())) { 68 | if (StringUtils.containsIgnoreCase(fcHttpTrace.getUrl().toString(), httpTraceSearchVO.getUrl())) 69 | fcHttpTraceList.add(fcHttpTrace); 70 | } else { 71 | fcHttpTraceList.add(fcHttpTrace); 72 | } 73 | }); 74 | 75 | return FCResponse.dataResponse(HttpFcStatus.DATASUCCESSGET.getCode(), HttpMsg.http.HTTP_DATA_SUCCESS.getMsg(),fcHttpTraceList); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/main/java/com/codeworld/fc/monitor/service/impl/LoginLogServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.codeworld.fc.monitor.service.impl; 2 | 3 | import com.codeworld.fc.common.enums.HttpFcStatus; 4 | import com.codeworld.fc.common.enums.HttpMsg; 5 | import com.codeworld.fc.common.exception.FCException; 6 | import com.codeworld.fc.common.response.DataResponse; 7 | import com.codeworld.fc.common.response.FCResponse; 8 | import com.codeworld.fc.monitor.entity.LoginLog; 9 | import com.codeworld.fc.monitor.mapper.LoginLogMapper; 10 | import com.codeworld.fc.monitor.service.LoginLogService; 11 | import com.codeworld.fc.monitor.vo.LoginLogSearchVO; 12 | import com.codeworld.fc.utils.AddressUtil; 13 | import com.codeworld.fc.utils.HttpContextUtil; 14 | import com.codeworld.fc.utils.IDGeneratorUtil; 15 | import com.codeworld.fc.utils.IPUtil; 16 | import com.github.pagehelper.PageHelper; 17 | import com.github.pagehelper.PageInfo; 18 | import org.springframework.beans.factory.annotation.Autowired; 19 | import org.springframework.stereotype.Service; 20 | import org.springframework.util.CollectionUtils; 21 | 22 | import javax.servlet.http.HttpServletRequest; 23 | import java.util.Date; 24 | import java.util.List; 25 | 26 | /** 27 | * ClassName LoginLogServiceImpl 28 | * Description TODO 29 | * Author Lenovo 30 | * Date 2020/10/10 31 | * Version 1.0 32 | **/ 33 | @Service 34 | public class LoginLogServiceImpl implements LoginLogService { 35 | 36 | @Autowired(required = false) 37 | private LoginLogMapper loginLogMapper; 38 | 39 | /** 40 | * 添加登录日志 41 | * 42 | * @param loginLog 43 | */ 44 | @Override 45 | public void addLoginLog(LoginLog loginLog) { 46 | // 补全参数 47 | loginLog.setLoginLogId(IDGeneratorUtil.getNextId()); 48 | 49 | loginLog.setLoginLogTime(new Date()); 50 | 51 | HttpServletRequest request = HttpContextUtil.getHttpServletRequest(); 52 | 53 | loginLog.setLoginLogIp(IPUtil.getIpAddr(request)); 54 | 55 | loginLog.setLoginLogLocation(AddressUtil.getCityInfo(IPUtil.getIpAddr(request))); 56 | 57 | this.loginLogMapper.addLoginLog(loginLog); 58 | } 59 | 60 | /** 61 | * 获取登录日志 62 | * 63 | * @return 64 | */ 65 | @Override 66 | public FCResponse>> getAllLoginLog(LoginLogSearchVO loginLogSearchVO) { 67 | 68 | PageHelper.startPage(loginLogSearchVO.getPage(), loginLogSearchVO.getLimit()); 69 | 70 | List loginLogs = this.loginLogMapper.getAllLoginLog(loginLogSearchVO); 71 | 72 | if (CollectionUtils.isEmpty(loginLogs)) { 73 | return FCResponse.dataResponse(HttpFcStatus.DATASUCCESSGET.getCode(), HttpMsg.loginLog.LOGIN_LOG_DATA_EMPTY.getMsg(), DataResponse.dataResponse(loginLogs, 0L)); 74 | 75 | } 76 | 77 | PageInfo pageInfo = new PageInfo<>(loginLogs); 78 | 79 | return FCResponse.dataResponse(HttpFcStatus.DATASUCCESSGET.getCode(), HttpMsg.loginLog.LOGIN_LOG_DATA_SUCCESS.getMsg(), DataResponse.dataResponse(pageInfo.getList(), pageInfo.getTotal())); 80 | } 81 | 82 | /** 83 | * 删除登录日志 84 | * 85 | * @param id 86 | * @return 87 | */ 88 | @Override 89 | public FCResponse deleteLoginLog(Long id) { 90 | 91 | try { 92 | if (id == null || id <= 0) { 93 | return FCResponse.dataResponse(HttpFcStatus.PARAMSERROR.getCode(), HttpMsg.loginLog.LOGIN_LOG_PARAMS_ERROR.getMsg()); 94 | 95 | } 96 | this.loginLogMapper.deleteLoginLog(id); 97 | 98 | return FCResponse.dataResponse(HttpFcStatus.DATASUCCESSGET.getCode(), HttpMsg.loginLog.LOGIN_LOG_DELETE_SUCCESS.getMsg()); 99 | } catch (Exception e) { 100 | e.printStackTrace(); 101 | throw new FCException("系统错误"); 102 | } 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /src/main/java/com/codeworld/fc/monitor/vo/HttpTraceSearchVO.java: -------------------------------------------------------------------------------- 1 | package com.codeworld.fc.monitor.vo; 2 | 3 | import com.codeworld.fc.common.base.PageQuery; 4 | import com.fasterxml.jackson.annotation.JsonFormat; 5 | import io.swagger.annotations.ApiModel; 6 | import io.swagger.annotations.ApiModelProperty; 7 | import lombok.Data; 8 | 9 | import java.util.Date; 10 | 11 | /** 12 | * ClassName HttpTraceSearchVO 13 | * Description 请求追踪搜索VO 14 | * Author Lenovo 15 | * Date 2020/10/10 16 | * Version 1.0 17 | **/ 18 | @Data 19 | @ApiModel("请求追踪搜索VO") 20 | public class HttpTraceSearchVO extends PageQuery { 21 | 22 | @ApiModelProperty("请求地址") 23 | private String url; 24 | 25 | @ApiModelProperty("请求方式") 26 | private String method; 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/com/codeworld/fc/monitor/vo/LoginLogSearchVO.java: -------------------------------------------------------------------------------- 1 | package com.codeworld.fc.monitor.vo; 2 | 3 | import com.codeworld.fc.common.base.PageQuery; 4 | import com.fasterxml.jackson.annotation.JsonFormat; 5 | import io.swagger.annotations.ApiModel; 6 | import io.swagger.annotations.ApiModelProperty; 7 | import lombok.Data; 8 | 9 | import java.util.Date; 10 | 11 | /** 12 | * ClassName LoginLogSearchVO 13 | * Description 登录日志搜索 14 | * Author Lenovo 15 | * Date 2020/10/10 16 | * Version 1.0 17 | **/ 18 | @Data 19 | @ApiModel("登录日志搜索") 20 | public class LoginLogSearchVO extends PageQuery { 21 | 22 | @ApiModelProperty("登录名") 23 | private String loginLogName; 24 | 25 | @ApiModelProperty("开始时间") 26 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8") 27 | private Date startTime; 28 | 29 | @ApiModelProperty("结束时间") 30 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8") 31 | private Date endTime; 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/com/codeworld/fc/system/dept/controller/DeptController.java: -------------------------------------------------------------------------------- 1 | package com.codeworld.fc.system.dept.controller; 2 | 3 | import com.codeworld.fc.common.annotation.ControllerEndpoint; 4 | import com.codeworld.fc.common.response.FCResponse; 5 | import com.codeworld.fc.system.dept.dto.DeptRequestDTO; 6 | import com.codeworld.fc.system.dept.service.DeptService; 7 | import io.swagger.annotations.Api; 8 | import io.swagger.annotations.ApiOperation; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.web.bind.annotation.PostMapping; 11 | import org.springframework.web.bind.annotation.RequestBody; 12 | import org.springframework.web.bind.annotation.RequestMapping; 13 | import org.springframework.web.bind.annotation.RestController; 14 | 15 | import javax.validation.Valid; 16 | 17 | /** 18 | * ClassName DeptController 19 | * Description 部门管理接口 20 | * Author Lenovo 21 | * Date 2020/10/13 22 | * Version 1.0 23 | **/ 24 | @RestController 25 | @RequestMapping("system-dept") 26 | @Api(tags = "部门管理接口") 27 | public class DeptController { 28 | 29 | @Autowired(required = false) 30 | private DeptService deptService; 31 | 32 | @PostMapping("tree-dept") 33 | @ApiOperation("获取部门树") 34 | @ControllerEndpoint(operation = "获取部门树",exceptionMessage = "获取部门树失败") 35 | public FCResponse treeDept(){ 36 | return this.deptService.treeDept(); 37 | } 38 | 39 | @PostMapping("add-dept") 40 | @ApiOperation("添加部门") 41 | @ControllerEndpoint(operation = "添加部门",exceptionMessage = "添加部门失败") 42 | public FCResponse addDept(@RequestBody @Valid DeptRequestDTO deptRequestDTO){ 43 | return this.deptService.addDept(deptRequestDTO); 44 | } 45 | 46 | @PostMapping("update-dept") 47 | @ApiOperation("修改部门") 48 | @ControllerEndpoint(operation = "修改部门",exceptionMessage = "修改部门失败") 49 | public FCResponse updateDept(@RequestBody @Valid DeptRequestDTO deptRequestDTO){ 50 | return this.deptService.updateDept(deptRequestDTO); 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/com/codeworld/fc/system/dept/dto/DeptRequestDTO.java: -------------------------------------------------------------------------------- 1 | package com.codeworld.fc.system.dept.dto; 2 | 3 | import io.swagger.annotations.ApiModel; 4 | import io.swagger.annotations.ApiModelProperty; 5 | import lombok.Data; 6 | 7 | import javax.validation.constraints.NotNull; 8 | 9 | /** 10 | * ClassName DeptRequestDTO 11 | * Description 部门添加修改信息 12 | * Author Lenovo 13 | * Date 2020/10/13 14 | * Version 1.0 15 | **/ 16 | @Data 17 | @ApiModel("部门添加修改信息") 18 | public class DeptRequestDTO { 19 | 20 | @ApiModelProperty("部门主键Id") 21 | private Long id; 22 | 23 | @ApiModelProperty("上级部门Id") 24 | @NotNull(message = "上级部门Id为空") 25 | private Long parentId; 26 | 27 | @ApiModelProperty("部门名称") 28 | @NotNull(message = "部门名称为空") 29 | private String title; 30 | 31 | @ApiModelProperty("部门简介") 32 | @NotNull(message = "部门简介为空") 33 | private String remarks; 34 | 35 | @ApiModelProperty("排序") 36 | @NotNull(message = "部门排序为空") 37 | private Integer sortNo; 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/com/codeworld/fc/system/dept/dto/DeptTreeNode.java: -------------------------------------------------------------------------------- 1 | package com.codeworld.fc.system.dept.dto; 2 | 3 | import com.codeworld.fc.system.dept.entity.Dept; 4 | import com.google.common.collect.Lists; 5 | import lombok.Data; 6 | 7 | import java.util.List; 8 | 9 | /** 10 | * ClassName DeptTreeNode 11 | * Description TODO 12 | * Author Lenovo 13 | * Date 2020/10/13 14 | * Version 1.0 15 | **/ 16 | @Data 17 | public class DeptTreeNode extends Dept { 18 | 19 | List children = Lists.newArrayList(); 20 | } 21 | 22 | -------------------------------------------------------------------------------- /src/main/java/com/codeworld/fc/system/dept/entity/Dept.java: -------------------------------------------------------------------------------- 1 | package com.codeworld.fc.system.dept.entity; 2 | 3 | import com.fasterxml.jackson.annotation.JsonFormat; 4 | import io.swagger.annotations.ApiModel; 5 | import io.swagger.annotations.ApiModelProperty; 6 | import lombok.Data; 7 | 8 | import java.util.Date; 9 | 10 | /** 11 | * ClassName Dept 12 | * Description 部门基本类 13 | * Author Lenovo 14 | * Date 2020/10/13 15 | * Version 1.0 16 | **/ 17 | @Data 18 | @ApiModel("部门基本类") 19 | public class Dept { 20 | 21 | @ApiModelProperty("部门主键Id") 22 | private Long id; 23 | 24 | @ApiModelProperty("上级部门Id") 25 | private Long parentId; 26 | 27 | @ApiModelProperty("部门名称") 28 | private String title; 29 | 30 | @ApiModelProperty("类型") 31 | private String type; 32 | 33 | @ApiModelProperty("部门简介") 34 | private String remarks; 35 | 36 | @ApiModelProperty("排序") 37 | private Integer sortNo; 38 | 39 | @ApiModelProperty("创建时间") 40 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8") 41 | private Date createTime; 42 | 43 | @ApiModelProperty("更新时间") 44 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") 45 | private Date updateTime; 46 | 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/com/codeworld/fc/system/dept/mapper/DeptMapper.java: -------------------------------------------------------------------------------- 1 | package com.codeworld.fc.system.dept.mapper; 2 | 3 | import com.codeworld.fc.system.dept.entity.Dept; 4 | import org.apache.ibatis.annotations.Mapper; 5 | import org.springframework.stereotype.Repository; 6 | 7 | import java.util.List; 8 | 9 | @Mapper 10 | @Repository 11 | public interface DeptMapper { 12 | /** 13 | * 获取全部部门 14 | * @return 15 | */ 16 | List getAllDept(); 17 | 18 | /** 19 | * 添加部门 20 | * @param dept 21 | */ 22 | void addDept(Dept dept); 23 | 24 | /** 25 | * 修改部门 26 | * @param dept 27 | */ 28 | void updateDept(Dept dept); 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/codeworld/fc/system/dept/service/DeptService.java: -------------------------------------------------------------------------------- 1 | package com.codeworld.fc.system.dept.service; 2 | 3 | import com.codeworld.fc.common.response.FCResponse; 4 | import com.codeworld.fc.system.dept.dto.DeptRequestDTO; 5 | 6 | public interface DeptService { 7 | /** 8 | * 获取部门树 9 | * @return 10 | */ 11 | FCResponse treeDept(); 12 | 13 | /** 14 | * 添加部门 15 | * @param deptRequestDTO 16 | */ 17 | FCResponse addDept(DeptRequestDTO deptRequestDTO); 18 | 19 | /** 20 | * 修改部门 21 | * @param deptRequestDTO 22 | * @return 23 | */ 24 | FCResponse updateDept(DeptRequestDTO deptRequestDTO); 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/com/codeworld/fc/system/dept/service/impl/DeptServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.codeworld.fc.system.dept.service.impl; 2 | 3 | import cn.hutool.core.bean.BeanUtil; 4 | import com.alibaba.fastjson.JSONObject; 5 | import com.codeworld.fc.common.enums.HttpFcStatus; 6 | import com.codeworld.fc.common.enums.HttpMsg; 7 | import com.codeworld.fc.common.exception.FCException; 8 | import com.codeworld.fc.common.response.FCResponse; 9 | import com.codeworld.fc.system.dept.dto.DeptRequestDTO; 10 | import com.codeworld.fc.system.dept.dto.DeptTreeNode; 11 | import com.codeworld.fc.system.dept.entity.Dept; 12 | import com.codeworld.fc.system.dept.mapper.DeptMapper; 13 | import com.codeworld.fc.system.dept.service.DeptService; 14 | import com.codeworld.fc.system.menu.dto.MenuTreeNode; 15 | import com.codeworld.fc.utils.IDGeneratorUtil; 16 | import com.codeworld.fc.utils.TreeBuilder; 17 | import com.google.common.collect.Lists; 18 | import org.springframework.beans.factory.annotation.Autowired; 19 | import org.springframework.stereotype.Service; 20 | import org.springframework.util.CollectionUtils; 21 | 22 | import java.util.Comparator; 23 | import java.util.Date; 24 | import java.util.List; 25 | import java.util.stream.Collectors; 26 | 27 | /** 28 | * ClassName DeptServiceImpl 29 | * Description TODO 30 | * Author Lenovo 31 | * Date 2020/10/13 32 | * Version 1.0 33 | **/ 34 | @Service 35 | public class DeptServiceImpl implements DeptService { 36 | 37 | @Autowired(required = false) 38 | private DeptMapper deptMapper; 39 | 40 | /** 41 | * 获取部门树 42 | * 43 | * @return 44 | */ 45 | @Override 46 | public FCResponse treeDept() { 47 | 48 | List depts = this.deptMapper.getAllDept(); 49 | 50 | List deptTreeNodeList = Lists.newArrayList(); 51 | 52 | if (!CollectionUtils.isEmpty(depts)){ 53 | depts.forEach(dept -> { 54 | DeptTreeNode deptTreeNode = new DeptTreeNode(); 55 | BeanUtil.copyProperties(dept,deptTreeNode); 56 | deptTreeNodeList.add(deptTreeNode); 57 | }); 58 | } 59 | 60 | List newDeptTreeNodeList = TreeBuilder.buildDeptTree(deptTreeNodeList); 61 | newDeptTreeNodeList.stream().sorted(Comparator.comparing(DeptTreeNode::getSortNo)).collect(Collectors.toList()); 62 | JSONObject jsonObject = new JSONObject(); 63 | jsonObject.put("deptList",depts); 64 | jsonObject.put("deptTree",newDeptTreeNodeList); 65 | return FCResponse.dataResponse(HttpFcStatus.DATASUCCESSGET.getCode(), HttpMsg.dept.DEPT_GET_SUCCESS.getMsg(),jsonObject); 66 | } 67 | 68 | /** 69 | * 添加部门 70 | * 71 | * @param deptRequestDTO 72 | */ 73 | @Override 74 | public FCResponse addDept(DeptRequestDTO deptRequestDTO) { 75 | 76 | try { 77 | Dept dept = new Dept(); 78 | BeanUtil.copyProperties(deptRequestDTO,dept); 79 | dept.setId(IDGeneratorUtil.getNextId()); 80 | dept.setCreateTime(new Date()); 81 | dept.setUpdateTime(dept.getCreateTime()); 82 | this.deptMapper.addDept(dept); 83 | return FCResponse.dataResponse(HttpFcStatus.DATASUCCESSGET.getCode(),HttpMsg.dept.DEPT_ADD_SUCCESS.getMsg()); 84 | }catch (Exception e){ 85 | e.printStackTrace(); 86 | throw new FCException("系统错误"); 87 | } 88 | } 89 | 90 | /** 91 | * 修改部门 92 | * 93 | * @param deptRequestDTO 94 | * @return 95 | */ 96 | @Override 97 | public FCResponse updateDept(DeptRequestDTO deptRequestDTO) { 98 | try { 99 | Dept dept = new Dept(); 100 | BeanUtil.copyProperties(deptRequestDTO,dept); 101 | dept.setUpdateTime(new Date()); 102 | this.deptMapper.updateDept(dept); 103 | return FCResponse.dataResponse(HttpFcStatus.DATASUCCESSGET.getCode(),HttpMsg.dept.DEPT_UPDATE_SUCCESS.getMsg()); 104 | }catch (Exception e){ 105 | e.printStackTrace(); 106 | throw new FCException("系统错误"); 107 | } 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /src/main/java/com/codeworld/fc/system/log/controller/LogController.java: -------------------------------------------------------------------------------- 1 | package com.codeworld.fc.system.log.controller; 2 | 3 | import com.codeworld.fc.common.annotation.ControllerEndpoint; 4 | import com.codeworld.fc.common.response.DataResponse; 5 | import com.codeworld.fc.common.response.FCResponse; 6 | import com.codeworld.fc.system.log.entity.Log; 7 | import com.codeworld.fc.system.log.service.LogService; 8 | import com.codeworld.fc.system.log.vo.LogSearchVO; 9 | import io.swagger.annotations.Api; 10 | import io.swagger.annotations.ApiOperation; 11 | import org.springframework.beans.factory.annotation.Autowired; 12 | import org.springframework.security.access.prepost.PreAuthorize; 13 | import org.springframework.web.bind.annotation.*; 14 | 15 | import java.util.List; 16 | 17 | /** 18 | * ClassName LogController 19 | * Description 日志接口管理 20 | * Author Lenovo 21 | * Date 2020/9/20 22 | * Version 1.0 23 | **/ 24 | @RestController 25 | @RequestMapping("system-log") 26 | @Api(tags = "日志接口管理") 27 | public class LogController { 28 | 29 | @Autowired(required = false) 30 | private LogService logService; 31 | 32 | @PostMapping("get-all-log") 33 | @ApiOperation("获取全部日志") 34 | @PreAuthorize("hasAuthority('log')") 35 | @ControllerEndpoint(operation = "获取全部日志",exceptionMessage = "日志获取失败") 36 | public FCResponse>> getAllLog(@RequestBody LogSearchVO logSearchVO){ 37 | return this.logService.getAllLog(logSearchVO); 38 | } 39 | 40 | @PostMapping("delete-log") 41 | @ApiOperation("删除日志") 42 | @ControllerEndpoint(operation = "删除日志",exceptionMessage = "删除日志失败") 43 | public FCResponse deleteLog(@RequestParam("id") Long id){ 44 | return this.logService.deleteLog(id); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/com/codeworld/fc/system/log/entity/Log.java: -------------------------------------------------------------------------------- 1 | package com.codeworld.fc.system.log.entity; 2 | 3 | import io.swagger.annotations.ApiModel; 4 | import io.swagger.annotations.ApiModelProperty; 5 | import lombok.Data; 6 | 7 | import java.util.Date; 8 | 9 | /** 10 | * ClassName Log 11 | * Description 日志基本类 12 | * Author Lenovo 13 | * Date 2020/9/20 14 | * Version 1.0 15 | **/ 16 | @Data 17 | @ApiModel("日志基本类") 18 | public class Log { 19 | 20 | @ApiModelProperty("日志Id") 21 | private Long logId; 22 | 23 | @ApiModelProperty("日志操作人") 24 | private String logOperationUserName; 25 | 26 | @ApiModelProperty("日志操作描述") 27 | private String logOperation; 28 | 29 | @ApiModelProperty("日志操作时间") 30 | private Long logTime; 31 | 32 | @ApiModelProperty("日志操作方法") 33 | private String logMethod; 34 | 35 | @ApiModelProperty("日志操作方法参数") 36 | private String logParams; 37 | 38 | @ApiModelProperty("日志操作IP") 39 | private String logIp; 40 | 41 | @ApiModelProperty("日志操作地点") 42 | private String logLocation; 43 | 44 | @ApiModelProperty("日志操作时间") 45 | private Date logCreateTime; 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/com/codeworld/fc/system/log/mapper/LogMapper.java: -------------------------------------------------------------------------------- 1 | package com.codeworld.fc.system.log.mapper; 2 | 3 | import com.codeworld.fc.system.log.entity.Log; 4 | import com.codeworld.fc.system.log.vo.LogSearchVO; 5 | import org.apache.ibatis.annotations.Mapper; 6 | import org.springframework.stereotype.Repository; 7 | 8 | import java.util.List; 9 | 10 | @Mapper 11 | @Repository 12 | public interface LogMapper { 13 | 14 | /** 15 | * 获取全部日志 16 | * @return 17 | */ 18 | List getAllLog(LogSearchVO logSearchVO); 19 | 20 | /** 21 | * 保存日志 22 | * @param log 23 | */ 24 | void addLog(Log log); 25 | 26 | /** 27 | * 删除全部日志 28 | */ 29 | void deleteAllLog(); 30 | 31 | /** 32 | * 删除日志 33 | * @param id 34 | */ 35 | void deleteLog(Long id); 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/com/codeworld/fc/system/log/service/LogService.java: -------------------------------------------------------------------------------- 1 | package com.codeworld.fc.system.log.service; 2 | 3 | import com.codeworld.fc.common.response.DataResponse; 4 | import com.codeworld.fc.common.response.FCResponse; 5 | import com.codeworld.fc.system.log.entity.Log; 6 | import com.codeworld.fc.system.log.vo.LogSearchVO; 7 | import org.aspectj.lang.ProceedingJoinPoint; 8 | 9 | import javax.servlet.http.HttpServletRequest; 10 | import java.lang.reflect.Method; 11 | import java.util.List; 12 | 13 | public interface LogService { 14 | /** 15 | * 获取全部日志 16 | * @param logSearchVO 17 | * @return 18 | */ 19 | FCResponse>> getAllLog(LogSearchVO logSearchVO); 20 | 21 | /** 22 | * 添加日志 23 | * @param point 24 | * @param targetMethod 25 | * @param request 26 | * @param operation 27 | * @param start 28 | */ 29 | void addLog(ProceedingJoinPoint point, Method targetMethod, HttpServletRequest request, String operation, long start); 30 | 31 | /** 32 | * 删除日志 33 | * @param id 34 | * @return 35 | */ 36 | FCResponse deleteLog(Long id); 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/com/codeworld/fc/system/log/vo/LogSearchVO.java: -------------------------------------------------------------------------------- 1 | package com.codeworld.fc.system.log.vo; 2 | 3 | import io.swagger.annotations.ApiModel; 4 | import io.swagger.annotations.ApiModelProperty; 5 | import lombok.Data; 6 | 7 | /** 8 | * ClassName LogSearchVO 9 | * Description 日志搜索信息 10 | * Author Lenovo 11 | * Date 2020/9/20 12 | * Version 1.0 13 | **/ 14 | @Data 15 | @ApiModel("日志搜索信息") 16 | public class LogSearchVO { 17 | 18 | @ApiModelProperty("页数") 19 | private Integer page; 20 | 21 | @ApiModelProperty("页数") 22 | private Integer limit; 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/com/codeworld/fc/system/menu/controller/MenuController.java: -------------------------------------------------------------------------------- 1 | package com.codeworld.fc.system.menu.controller; 2 | 3 | import com.codeworld.fc.common.response.FCResponse; 4 | import com.codeworld.fc.system.menu.dto.MenuRequestDTO; 5 | import com.codeworld.fc.system.menu.service.MenuService; 6 | import io.swagger.annotations.Api; 7 | import io.swagger.annotations.ApiOperation; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.security.access.prepost.PreAuthorize; 10 | import org.springframework.web.bind.annotation.*; 11 | 12 | import javax.validation.Valid; 13 | import java.util.List; 14 | import java.util.Map; 15 | 16 | /** 17 | * ClassName MenuController 18 | * Description 菜单接口管理 19 | * Author Lenovo 20 | * Date 2020/8/26 21 | * Version 1.0 22 | **/ 23 | @RestController 24 | @RequestMapping("system-menu") 25 | @Api(tags = "菜单接口管理") 26 | public class MenuController { 27 | 28 | @Autowired(required = false) 29 | private MenuService menuService; 30 | 31 | @PostMapping("tree-menu") 32 | @ApiOperation("获取菜单树") 33 | public FCResponse treeMenu() { 34 | return this.menuService.treeMenu(); 35 | } 36 | 37 | @PostMapping("update-menu") 38 | @ApiOperation("修改菜单") 39 | @PreAuthorize("hasAuthority('menu:edit')") 40 | public FCResponse updateMenu(@RequestBody @Valid MenuRequestDTO menuRequestDTO) { 41 | return this.menuService.updateMenu(menuRequestDTO); 42 | } 43 | 44 | @PostMapping("add-menu") 45 | @ApiOperation("添加菜单") 46 | @PreAuthorize("hasAuthority('menu:add')") 47 | public FCResponse addMenu(@RequestBody @Valid MenuRequestDTO menuRequestDTO) { 48 | return this.menuService.addMenu(menuRequestDTO); 49 | } 50 | 51 | @PostMapping("delete-menu") 52 | @ApiOperation("删除菜单") 53 | @PreAuthorize("hasAuthority('menu:delete')") 54 | public FCResponse deleteMenu(@RequestParam("id") Long id) { 55 | return this.menuService.deleteMenu(id); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/com/codeworld/fc/system/menu/dto/MenuRequestDTO.java: -------------------------------------------------------------------------------- 1 | package com.codeworld.fc.system.menu.dto; 2 | 3 | import io.swagger.annotations.ApiModel; 4 | import io.swagger.annotations.ApiModelProperty; 5 | import lombok.Data; 6 | 7 | import javax.validation.constraints.NotNull; 8 | 9 | /** 10 | * ClassName MenuRequestDTO 11 | * Description 菜单修改信息 12 | * Author Lenovo 13 | * Date 2020/9/18 14 | * Version 1.0 15 | **/ 16 | @Data 17 | @ApiModel("菜单修改信息") 18 | public class MenuRequestDTO { 19 | 20 | @ApiModelProperty("菜单Id") 21 | private Long id; 22 | 23 | @ApiModelProperty("上级Id") 24 | @NotNull(message = "父级Id为空") 25 | private Long parentId; 26 | 27 | @ApiModelProperty("菜单Url") 28 | @NotNull(message = "菜单URL为空") 29 | private String url; 30 | 31 | @ApiModelProperty("菜单名称") 32 | @NotNull(message = "菜单名称为空") 33 | private String title; 34 | 35 | @ApiModelProperty("菜单编码") 36 | @NotNull(message = "菜单编码为空") 37 | private String resources; 38 | 39 | @ApiModelProperty("类型") 40 | @NotNull(message = "菜单类型为空") 41 | private String type; 42 | 43 | @ApiModelProperty("菜单简介") 44 | private String remarks; 45 | 46 | @ApiModelProperty("排序") 47 | @NotNull(message = "菜单排序为空") 48 | private Integer sortNo; 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/com/codeworld/fc/system/menu/dto/MenuTreeNode.java: -------------------------------------------------------------------------------- 1 | package com.codeworld.fc.system.menu.dto; 2 | 3 | import com.codeworld.fc.system.menu.entity.Menu; 4 | 5 | import com.google.common.collect.Lists; 6 | import lombok.Data; 7 | 8 | import java.util.List; 9 | 10 | /** 11 | * ClassName MenuTreeNode 12 | * Description TODO 13 | * Author Lenovo 14 | * Date 2020/8/26 15 | * Version 1.0 16 | **/ 17 | @Data 18 | public class MenuTreeNode extends Menu { 19 | 20 | List children = Lists.newArrayList(); 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/com/codeworld/fc/system/menu/entity/Menu.java: -------------------------------------------------------------------------------- 1 | package com.codeworld.fc.system.menu.entity; 2 | 3 | import com.fasterxml.jackson.annotation.JsonFormat; 4 | import io.swagger.annotations.ApiModel; 5 | import io.swagger.annotations.ApiModelProperty; 6 | import lombok.Data; 7 | 8 | import java.util.Date; 9 | 10 | /** 11 | * ClassName Menu 12 | * Description 权限菜单类 13 | * Author Lenovo 14 | * Date 2020/8/26 15 | * Version 1.0 16 | **/ 17 | @Data 18 | @ApiModel("权限菜单类") 19 | public class Menu { 20 | 21 | @ApiModelProperty("菜单Id") 22 | private Long id; 23 | 24 | @ApiModelProperty("上级Id") 25 | private Long parentId; 26 | 27 | @ApiModelProperty("菜单Url") 28 | private String url; 29 | 30 | @ApiModelProperty("菜单名称") 31 | private String title; 32 | 33 | @ApiModelProperty("菜单编码") 34 | private String resources; 35 | 36 | @ApiModelProperty("类型") 37 | private String type; 38 | 39 | @ApiModelProperty("菜单简介") 40 | private String remarks; 41 | 42 | @ApiModelProperty("排序") 43 | private Integer sortNo; 44 | 45 | @ApiModelProperty("创建时间") 46 | @JsonFormat(pattern = "yyyy-MM-dd HH:ss:mm",timezone = "GTM+8") 47 | private Date createTime; 48 | 49 | @ApiModelProperty("更新时间") 50 | @JsonFormat(pattern = "yyyy-MM-dd HH:ss:mm",timezone = "GTM+8") 51 | private Date updateTime; 52 | 53 | 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/com/codeworld/fc/system/menu/entity/RoleMenu.java: -------------------------------------------------------------------------------- 1 | package com.codeworld.fc.system.menu.entity; 2 | 3 | import com.fasterxml.jackson.annotation.JsonFormat; 4 | import io.swagger.annotations.ApiModel; 5 | import io.swagger.annotations.ApiModelProperty; 6 | import lombok.Data; 7 | 8 | import java.util.Date; 9 | 10 | /** 11 | * ClassName RoleMenu 12 | * Description 角色菜单类 13 | * Author Lenovo 14 | * Date 2020/9/14 15 | * Version 1.0 16 | **/ 17 | @Data 18 | @ApiModel("角色菜单类") 19 | public class RoleMenu { 20 | 21 | @ApiModelProperty("角色菜单主键Id") 22 | private Long roleMenuId; 23 | 24 | @ApiModelProperty("角色Id") 25 | private Long roleId; 26 | 27 | @ApiModelProperty("菜单Id") 28 | private Long menuId; 29 | 30 | @ApiModelProperty("创建时间") 31 | @JsonFormat(pattern = "yyyy-MM-dd HH:ss:mm",timezone = "GTM+8") 32 | private Date createTime; 33 | 34 | @ApiModelProperty("更新时间") 35 | @JsonFormat(pattern = "yyyy-MM-dd HH:ss:mm",timezone = "GTM+8") 36 | private Date updateTime; 37 | } 38 | 39 | -------------------------------------------------------------------------------- /src/main/java/com/codeworld/fc/system/menu/mapper/MenuMapper.java: -------------------------------------------------------------------------------- 1 | package com.codeworld.fc.system.menu.mapper; 2 | 3 | import com.codeworld.fc.system.menu.entity.Menu; 4 | import com.codeworld.fc.system.menu.entity.RoleMenu; 5 | import org.apache.ibatis.annotations.Mapper; 6 | import org.springframework.stereotype.Repository; 7 | 8 | import java.util.List; 9 | import java.util.Map; 10 | 11 | @Mapper 12 | @Repository 13 | public interface MenuMapper { 14 | /** 15 | * 查询全部菜单 16 | * @return 17 | */ 18 | List getAllMenu(); 19 | 20 | /** 21 | * 根据角色Id获取菜单权限 22 | * @param roleId 23 | * @return 24 | */ 25 | List getMenuByRoleId(Long roleId); 26 | 27 | /** 28 | * 修改菜单 29 | * @param menu 30 | */ 31 | void updateMenu(Menu menu); 32 | 33 | /** 34 | * 添加菜单 35 | * @param menu 36 | */ 37 | void addMenu(Menu menu); 38 | 39 | /** 40 | * 根据菜单Id获取菜单信息 41 | * @param id 42 | * @return 43 | */ 44 | Menu getMenuById(Long id); 45 | 46 | /** 47 | * 根据Id获取子集菜单 48 | * @param id 49 | * @return 50 | */ 51 | List getChildMenuById(Long id); 52 | 53 | /** 54 | * 删除角色菜单信息 55 | * @param ids 56 | */ 57 | void deleteRoleMenu(List ids); 58 | 59 | /** 60 | * 删除菜单信息 61 | * @param id 62 | */ 63 | void deleteMenuById(Long id); 64 | 65 | /** 66 | * 删除子集菜单 67 | * @param id 68 | */ 69 | void deleteChildMenu(Long id); 70 | 71 | /** 72 | * 删除角色菜单 73 | * @param roleId 74 | */ 75 | void deleteRoleMenuByRoleId(Long roleId); 76 | 77 | /** 78 | * 设置角色菜单 79 | */ 80 | void addRoleMenu(RoleMenu roleMenu); 81 | } 82 | 83 | -------------------------------------------------------------------------------- /src/main/java/com/codeworld/fc/system/menu/service/MenuService.java: -------------------------------------------------------------------------------- 1 | package com.codeworld.fc.system.menu.service; 2 | 3 | import com.codeworld.fc.common.response.FCResponse; 4 | import com.codeworld.fc.system.menu.dto.MenuRequestDTO; 5 | 6 | public interface MenuService { 7 | /** 8 | * 获取菜单树 9 | * @return 10 | */ 11 | FCResponse treeMenu(); 12 | 13 | /** 14 | * 修改菜单 15 | * @param menuRequestDTO 16 | * @return 17 | */ 18 | FCResponse updateMenu(MenuRequestDTO menuRequestDTO); 19 | 20 | /** 21 | * 添加菜单 22 | * @param menuRequestDTO 23 | * @return 24 | */ 25 | FCResponse addMenu(MenuRequestDTO menuRequestDTO); 26 | 27 | /** 28 | * 删除菜单 29 | * @param id 30 | * @return 31 | */ 32 | FCResponse deleteMenu(Long id); 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/com/codeworld/fc/system/role/controller/RoleController.java: -------------------------------------------------------------------------------- 1 | package com.codeworld.fc.system.role.controller; 2 | 3 | import com.codeworld.fc.common.annotation.ControllerEndpoint; 4 | import com.codeworld.fc.common.response.DataResponse; 5 | import com.codeworld.fc.common.response.FCResponse; 6 | import com.codeworld.fc.system.menu.entity.RoleMenu; 7 | import com.codeworld.fc.system.role.entity.Role; 8 | import com.codeworld.fc.system.role.service.RoleService; 9 | import com.codeworld.fc.system.role.vo.RoleAddRequest; 10 | import com.codeworld.fc.system.role.vo.RoleMenuRequest; 11 | import com.codeworld.fc.system.role.vo.RoleSearchVO; 12 | import com.codeworld.fc.system.role.vo.RoleUpdateRequest; 13 | import io.swagger.annotations.Api; 14 | import io.swagger.annotations.ApiOperation; 15 | import org.springframework.beans.factory.annotation.Autowired; 16 | import org.springframework.security.access.prepost.PreAuthorize; 17 | import org.springframework.web.bind.annotation.*; 18 | 19 | import javax.validation.Valid; 20 | import java.util.List; 21 | 22 | /** 23 | * ClassName RoleController 24 | * Description 角色接口管理 25 | * Author Lenovo 26 | * Date 2020/9/16 27 | * Version 1.0 28 | **/ 29 | @RestController 30 | @RequestMapping("system-role") 31 | @Api(tags = "角色接口管理") 32 | public class RoleController { 33 | 34 | @Autowired(required = false) 35 | private RoleService roleService; 36 | 37 | @PostMapping("get-all-role") 38 | @ApiOperation("获取全部角色") 39 | @PreAuthorize("hasAuthority('role')") 40 | public FCResponse>> getAllRole(@RequestBody RoleSearchVO roleSearchVO) { 41 | return this.roleService.getAllRole(roleSearchVO); 42 | } 43 | 44 | @PostMapping("get-role-menu") 45 | @ApiOperation("获取角色菜单") 46 | public FCResponse> getRoleMenu(@RequestParam("roleId") Long roleId) { 47 | return this.roleService.getRoleMenu(roleId); 48 | } 49 | 50 | @PostMapping("update-role") 51 | @ApiOperation("修改角色") 52 | @PreAuthorize("hasAuthority('role:edit')") 53 | public FCResponse updateRole(@RequestBody @Valid RoleUpdateRequest roleUpdateRequest) { 54 | return this.roleService.updateRole(roleUpdateRequest); 55 | } 56 | 57 | @PostMapping("add-role-menu") 58 | @ApiOperation("设置角色菜单") 59 | public FCResponse addRoleMenu(@RequestBody RoleMenuRequest roleMenuRequest) { 60 | return this.roleService.addRoleMenu(roleMenuRequest); 61 | } 62 | 63 | @PostMapping("add-role") 64 | @ApiOperation("添加角色") 65 | @PreAuthorize("hasAuthority('role:add')") 66 | public FCResponse addRole(@RequestBody @Valid RoleAddRequest roleAddRequest) { 67 | return this.roleService.addRole(roleAddRequest); 68 | } 69 | 70 | @PostMapping("get-all-role-no-param") 71 | @ApiOperation("获取全部角色--无参数") 72 | public FCResponse> getAllRoleNoParam() { 73 | return this.roleService.getAllRoleNoParam(); 74 | } 75 | 76 | @PostMapping("delete-role") 77 | @ApiOperation("删除角色") 78 | @PreAuthorize("hasAuthority('role:delete')") 79 | @ControllerEndpoint(operation = "删除角色",exceptionMessage = "删除角色失败") 80 | public FCResponse deleteRole(@RequestParam("roleId") Long roleId){ 81 | return this.roleService.deleteRole(roleId); 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /src/main/java/com/codeworld/fc/system/role/entity/Role.java: -------------------------------------------------------------------------------- 1 | package com.codeworld.fc.system.role.entity; 2 | 3 | import com.fasterxml.jackson.annotation.JsonFormat; 4 | import io.swagger.annotations.ApiModel; 5 | import io.swagger.annotations.ApiModelProperty; 6 | import lombok.Data; 7 | 8 | import java.util.Date; 9 | 10 | /** 11 | * ClassName Role 12 | * Description 角色基本类 13 | * Author Lenovo 14 | * Date 2020/9/14 15 | * Version 1.0 16 | **/ 17 | @Data 18 | @ApiModel("角色基本类") 19 | public class Role { 20 | 21 | @ApiModelProperty("角色主键Id") 22 | private Long roleId; 23 | 24 | @ApiModelProperty("角色编码") 25 | private String roleCode; 26 | 27 | @ApiModelProperty("角色名称") 28 | private String roleName; 29 | 30 | @ApiModelProperty("角色描述") 31 | private String roleRemarks; 32 | 33 | @ApiModelProperty("创建时间") 34 | @JsonFormat(pattern = "yyyy-MM-dd HH:ss:mm",timezone = "GTM+8") 35 | private Date createTime; 36 | 37 | @ApiModelProperty("更新时间") 38 | @JsonFormat(pattern = "yyyy-MM-dd HH:ss:mm",timezone = "GTM+8") 39 | private Date updateTime; 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/com/codeworld/fc/system/role/entity/UserRole.java: -------------------------------------------------------------------------------- 1 | package com.codeworld.fc.system.role.entity; 2 | 3 | import com.fasterxml.jackson.annotation.JsonFormat; 4 | import io.swagger.annotations.ApiModel; 5 | import io.swagger.annotations.ApiModelProperty; 6 | import lombok.Data; 7 | 8 | import java.util.Date; 9 | 10 | /** 11 | * ClassName UserRole 12 | * Description 用户角色类 13 | * Author Lenovo 14 | * Date 2020/9/14 15 | * Version 1.0 16 | **/ 17 | @Data 18 | @ApiModel("用户角色类") 19 | public class UserRole { 20 | 21 | @ApiModelProperty("用户角色主键Id") 22 | private Long userRoleId; 23 | 24 | @ApiModelProperty("用户Id") 25 | private Long userId; 26 | 27 | @ApiModelProperty("角色Id") 28 | private Long roleId; 29 | 30 | @ApiModelProperty("创建时间") 31 | @JsonFormat(pattern = "yyyy-MM-dd HH:ss:mm") 32 | private Date createTime; 33 | 34 | @ApiModelProperty("更新时间") 35 | @JsonFormat(pattern = "yyyy-MM-dd HH:ss:mm") 36 | private Date updateTime; 37 | 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/com/codeworld/fc/system/role/mapper/RoleMapper.java: -------------------------------------------------------------------------------- 1 | package com.codeworld.fc.system.role.mapper; 2 | 3 | import com.codeworld.fc.common.response.FCResponse; 4 | import com.codeworld.fc.system.menu.entity.RoleMenu; 5 | import com.codeworld.fc.system.role.entity.Role; 6 | import com.codeworld.fc.system.role.entity.UserRole; 7 | import com.codeworld.fc.system.role.vo.RoleSearchVO; 8 | import org.apache.ibatis.annotations.Mapper; 9 | import org.springframework.stereotype.Repository; 10 | 11 | import java.util.List; 12 | 13 | @Mapper 14 | @Repository 15 | public interface RoleMapper { 16 | 17 | 18 | /** 19 | * 根据用户Id获取用户角色信息 20 | * @param userId 21 | * @return 22 | */ 23 | Role getRoleById(Long userId); 24 | 25 | /** 26 | * 获取全部角色信息 27 | * @param roleSearchVO 28 | * @return 29 | */ 30 | List getAllRole(RoleSearchVO roleSearchVO); 31 | 32 | /** 33 | * 获取角色菜单 34 | * @param roleId 35 | * @return 36 | */ 37 | List getRoleMenuByRoleId(Long roleId); 38 | 39 | /** 40 | * 修改角色 41 | * @param role 42 | */ 43 | void updateRole(Role role); 44 | 45 | /** 46 | * 添加角色 47 | * @param role 48 | */ 49 | void addRole(Role role); 50 | 51 | /** 52 | * 获取全部角色--无参数 53 | * @return 54 | */ 55 | List getAllRoleNoParam(); 56 | 57 | /** 58 | * 设置用户角色 59 | * @param userRole 60 | */ 61 | void addUserRole(UserRole userRole); 62 | 63 | /** 64 | * 删除用户关联的角色 65 | * @param userId 66 | */ 67 | void deleteUserRoleByUserId(Long userId); 68 | 69 | /** 70 | * 删除角色关联的用户 71 | * @param roleId 72 | */ 73 | void deleteUserRoleByRoleId(Long roleId); 74 | 75 | /** 76 | * 删除角色信息 77 | * @param roleId 78 | */ 79 | void deleteRoleByRoleId(Long roleId); 80 | } 81 | -------------------------------------------------------------------------------- /src/main/java/com/codeworld/fc/system/role/service/RoleService.java: -------------------------------------------------------------------------------- 1 | package com.codeworld.fc.system.role.service; 2 | 3 | import com.codeworld.fc.common.response.DataResponse; 4 | import com.codeworld.fc.common.response.FCResponse; 5 | import com.codeworld.fc.system.menu.entity.RoleMenu; 6 | import com.codeworld.fc.system.role.entity.Role; 7 | import com.codeworld.fc.system.role.vo.RoleAddRequest; 8 | import com.codeworld.fc.system.role.vo.RoleMenuRequest; 9 | import com.codeworld.fc.system.role.vo.RoleSearchVO; 10 | import com.codeworld.fc.system.role.vo.RoleUpdateRequest; 11 | 12 | import java.util.List; 13 | 14 | public interface RoleService { 15 | 16 | /** 17 | * 获取全部角色信息 18 | * @param roleSearchVO 19 | * @return 20 | */ 21 | FCResponse>> getAllRole(RoleSearchVO roleSearchVO); 22 | 23 | /** 24 | * 获取角色菜单 25 | * @param roleId 26 | * @return 27 | */ 28 | FCResponse> getRoleMenu(Long roleId); 29 | 30 | /** 31 | * 修改角色 32 | * @param roleUpdateRequest 33 | * @return 34 | */ 35 | FCResponse updateRole(RoleUpdateRequest roleUpdateRequest); 36 | 37 | /** 38 | * 设置角色菜单 39 | * @param roleMenuRequest 40 | * @return 41 | */ 42 | FCResponse addRoleMenu(RoleMenuRequest roleMenuRequest); 43 | 44 | /** 45 | * 添加角色 46 | * @param roleAddRequest 47 | * @return 48 | */ 49 | FCResponse addRole(RoleAddRequest roleAddRequest); 50 | 51 | /** 52 | * 获取全部角色--无参数 53 | * @return 54 | */ 55 | FCResponse> getAllRoleNoParam(); 56 | 57 | /** 58 | * 删除角色 59 | * @param roleId 60 | * @return 61 | */ 62 | FCResponse deleteRole(Long roleId); 63 | } 64 | -------------------------------------------------------------------------------- /src/main/java/com/codeworld/fc/system/role/vo/RoleAddRequest.java: -------------------------------------------------------------------------------- 1 | package com.codeworld.fc.system.role.vo; 2 | 3 | import io.swagger.annotations.ApiModel; 4 | import io.swagger.annotations.ApiModelProperty; 5 | import lombok.Data; 6 | 7 | import javax.validation.constraints.NotNull; 8 | 9 | /** 10 | * ClassName RoleUpdateRequest 11 | * Description 角色添加信息 12 | * Author Lenovo 13 | * Date 2020/9/19 14 | * Version 1.0 15 | **/ 16 | @Data 17 | @ApiModel("角色添加信息") 18 | public class RoleAddRequest { 19 | 20 | @ApiModelProperty("角色编码") 21 | @NotNull(message = "角色编码为空") 22 | private String roleCode; 23 | 24 | @ApiModelProperty("角色名称") 25 | @NotNull(message = "角色名称为空") 26 | private String roleName; 27 | 28 | @ApiModelProperty("角色描述") 29 | private String roleRemarks; 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/com/codeworld/fc/system/role/vo/RoleMenuRequest.java: -------------------------------------------------------------------------------- 1 | package com.codeworld.fc.system.role.vo; 2 | 3 | import io.swagger.annotations.ApiModel; 4 | import io.swagger.annotations.ApiModelProperty; 5 | import lombok.Data; 6 | 7 | import javax.validation.constraints.NotNull; 8 | 9 | /** 10 | * ClassName RoleMenuRequest 11 | * Description 角色菜单信息 12 | * Author Lenovo 13 | * Date 2020/9/19 14 | * Version 1.0 15 | **/ 16 | @Data 17 | @ApiModel("角色菜单信息") 18 | public class RoleMenuRequest { 19 | 20 | @ApiModelProperty("角色Id") 21 | @NotNull(message = "角色Id为空") 22 | private Long roleId; 23 | 24 | @ApiModelProperty("角色菜单") 25 | private String menuIds; 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/com/codeworld/fc/system/role/vo/RoleSearchVO.java: -------------------------------------------------------------------------------- 1 | package com.codeworld.fc.system.role.vo; 2 | 3 | import io.swagger.annotations.ApiModel; 4 | import io.swagger.annotations.ApiModelProperty; 5 | import lombok.Data; 6 | 7 | /** 8 | * ClassName RoleSearchVO 9 | * Description 角色搜索信息 10 | * Author Lenovo 11 | * Date 2020/9/18 12 | * Version 1.0 13 | **/ 14 | @Data 15 | @ApiModel("角色搜索信息") 16 | public class RoleSearchVO { 17 | 18 | @ApiModelProperty("页数") 19 | private Integer page; 20 | 21 | @ApiModelProperty("数量") 22 | private Integer limit; 23 | 24 | @ApiModelProperty("角色名称") 25 | private String roleName; 26 | 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/com/codeworld/fc/system/role/vo/RoleUpdateRequest.java: -------------------------------------------------------------------------------- 1 | package com.codeworld.fc.system.role.vo; 2 | 3 | import io.swagger.annotations.ApiModel; 4 | import io.swagger.annotations.ApiModelProperty; 5 | import lombok.Data; 6 | 7 | import javax.validation.constraints.NotNull; 8 | 9 | /** 10 | * ClassName RoleUpdateRequest 11 | * Description 角色修改信息 12 | * Author Lenovo 13 | * Date 2020/9/19 14 | * Version 1.0 15 | **/ 16 | @Data 17 | @ApiModel("角色修改信息") 18 | public class RoleUpdateRequest { 19 | 20 | @ApiModelProperty("角色主键Id") 21 | @NotNull(message = "角色主键Id为空") 22 | private Long roleId; 23 | 24 | @ApiModelProperty("角色编码") 25 | @NotNull(message = "角色编码为空") 26 | private String roleCode; 27 | 28 | @ApiModelProperty("角色名称") 29 | @NotNull(message = "角色名称为空") 30 | private String roleName; 31 | 32 | @ApiModelProperty("角色描述") 33 | @NotNull(message = "角色描述为空") 34 | private String roleRemarks; 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/com/codeworld/fc/system/user/controller/LoginController.java: -------------------------------------------------------------------------------- 1 | package com.codeworld.fc.system.user.controller; 2 | 3 | import com.codeworld.fc.common.annotation.ControllerEndpoint; 4 | import com.codeworld.fc.common.enums.HttpFcStatus; 5 | import com.codeworld.fc.common.response.FCResponse; 6 | import com.codeworld.fc.system.user.dto.UserInfoResponse; 7 | import com.codeworld.fc.system.user.service.LoginService; 8 | import com.codeworld.fc.system.user.service.UserService; 9 | import com.codeworld.fc.system.user.vo.UserLoginOutRequest; 10 | import com.codeworld.fc.system.user.vo.UserLoginRequest; 11 | import io.swagger.annotations.Api; 12 | import io.swagger.annotations.ApiOperation; 13 | import org.springframework.beans.factory.annotation.Autowired; 14 | import org.springframework.web.bind.annotation.*; 15 | 16 | import javax.servlet.http.HttpServletRequest; 17 | import javax.servlet.http.HttpServletResponse; 18 | import java.util.HashMap; 19 | import java.util.Map; 20 | 21 | /** 22 | * ClassName LoginConttoller 23 | * Description 登录接口管理 24 | * Author Lenovo 25 | * Date 2020/8/12 26 | * Version 1.0 27 | **/ 28 | @RestController 29 | @RequestMapping("system-auth") 30 | @Api(tags = "用户登录接口管理") 31 | public class LoginController { 32 | 33 | @Autowired(required = false) 34 | private LoginService loginService; 35 | @Autowired(required = false) 36 | private UserService userService; 37 | 38 | 39 | @PostMapping("user-login") 40 | @ApiOperation("用户登录") 41 | @ControllerEndpoint(operation = "用户登录",exceptionMessage = "登录失败") 42 | public FCResponse> login(@RequestBody UserLoginRequest userLoginRequest, 43 | HttpServletRequest request, 44 | HttpServletResponse response) { 45 | return this.loginService.login(userLoginRequest, request, response); 46 | } 47 | 48 | @PostMapping("user-login-out") 49 | @ApiOperation("退出登录") 50 | @ControllerEndpoint(operation = "退出登录",exceptionMessage = "退出登录失败") 51 | public FCResponse LoginOut(@RequestBody UserLoginOutRequest userLoginOutRequest){ 52 | return this.loginService.loginOut(userLoginOutRequest); 53 | } 54 | 55 | @PostMapping(value = "get-user-info",produces = "application/json;charset=utf-8") 56 | @ApiOperation("获取用户信息") 57 | @ControllerEndpoint(operation = "获取用户信息",exceptionMessage = "获取用户信息失败") 58 | public FCResponse getUserInfo(@RequestBody UserLoginRequest userLoginRequest, 59 | HttpServletRequest request, 60 | HttpServletResponse response) { 61 | return this.userService.getUserInfo(userLoginRequest,request,response); 62 | } 63 | 64 | 65 | } 66 | -------------------------------------------------------------------------------- /src/main/java/com/codeworld/fc/system/user/dto/UserDeptResponse.java: -------------------------------------------------------------------------------- 1 | package com.codeworld.fc.system.user.dto; 2 | 3 | import com.codeworld.fc.system.user.entity.User; 4 | import io.swagger.annotations.ApiModel; 5 | import io.swagger.annotations.ApiModelProperty; 6 | import lombok.Data; 7 | 8 | /** 9 | * ClassName UserDeptResponse 10 | * Description 用户部门信息DTO 11 | * Author Lenovo 12 | * Date 2020/10/14 13 | * Version 1.0 14 | **/ 15 | @Data 16 | @ApiModel("用户部门信息DTO") 17 | public class UserDeptResponse extends User { 18 | 19 | @ApiModelProperty("部门名称") 20 | private String deptName; 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/com/codeworld/fc/system/user/dto/UserInfoResponse.java: -------------------------------------------------------------------------------- 1 | package com.codeworld.fc.system.user.dto; 2 | 3 | import com.codeworld.fc.system.user.vo.ButtonVO; 4 | import com.codeworld.fc.system.user.vo.MenuVO; 5 | import com.fasterxml.jackson.annotation.JsonFormat; 6 | import com.google.common.collect.Sets; 7 | import io.swagger.annotations.ApiModel; 8 | import io.swagger.annotations.ApiModelProperty; 9 | import lombok.Data; 10 | import org.springframework.security.core.parameters.P; 11 | 12 | import java.util.Date; 13 | import java.util.Set; 14 | 15 | /** 16 | * ClassName UserInfoResponse 17 | * Description 用户信息 18 | * Author Lenovo 19 | * Date 2020/9/14 20 | * Version 1.0 21 | **/ 22 | @Data 23 | @ApiModel("用户信息") 24 | public class UserInfoResponse { 25 | 26 | @ApiModelProperty("用户Id") 27 | private Long userId; 28 | 29 | @ApiModelProperty("用户名") 30 | private String userName; 31 | 32 | @ApiModelProperty("用户邮箱") 33 | private String userEmail; 34 | 35 | @ApiModelProperty("用户状态") 36 | private Integer userStatus; 37 | 38 | @ApiModelProperty("登录Ip") 39 | private String loginIp; 40 | 41 | @ApiModelProperty("登录地址") 42 | private String loginLocation; 43 | 44 | @ApiModelProperty("登录时间") 45 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") 46 | private Date loginTime; 47 | 48 | @ApiModelProperty("角色集") 49 | private Set roles = Sets.newHashSet(); 50 | 51 | @ApiModelProperty("菜单集") 52 | private Set menus = Sets.newHashSet(); 53 | 54 | @ApiModelProperty("按钮集") 55 | private Set buttons = Sets.newHashSet(); 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/com/codeworld/fc/system/user/entity/User.java: -------------------------------------------------------------------------------- 1 | package com.codeworld.fc.system.user.entity; 2 | 3 | import com.fasterxml.jackson.annotation.JsonFormat; 4 | import io.swagger.annotations.Api; 5 | import io.swagger.annotations.ApiModel; 6 | import io.swagger.annotations.ApiModelProperty; 7 | import lombok.Data; 8 | 9 | import java.util.Date; 10 | 11 | /** 12 | * ClassName User 13 | * Description用户基本类 14 | * Author Lenovo 15 | * Date 2020/8/12 16 | * Version 1.0 17 | **/ 18 | @Data 19 | @ApiModel("用户基本类") 20 | public class User { 21 | 22 | @ApiModelProperty("主键Id") 23 | private Long userId; 24 | 25 | @ApiModelProperty("用户名") 26 | private String userName; 27 | 28 | @ApiModelProperty("用户邮箱") 29 | private String userEmail; 30 | 31 | @ApiModelProperty("用户手机") 32 | private String userPhone; 33 | 34 | @ApiModelProperty("用户状态") 35 | private Integer userStatus; 36 | 37 | @ApiModelProperty("创建时间") 38 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") 39 | private Date createTime; 40 | 41 | @ApiModelProperty("更新时间") 42 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") 43 | private Date updateTime; 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/com/codeworld/fc/system/user/entity/UserDept.java: -------------------------------------------------------------------------------- 1 | package com.codeworld.fc.system.user.entity; 2 | 3 | import com.fasterxml.jackson.annotation.JsonFormat; 4 | import io.swagger.annotations.ApiModel; 5 | import io.swagger.annotations.ApiModelProperty; 6 | import lombok.Data; 7 | 8 | import java.util.Date; 9 | 10 | /** 11 | * ClassName UserDept 12 | * Description 用户部门 13 | * Author Lenovo 14 | * Date 2020/10/14 15 | * Version 1.0 16 | **/ 17 | @Data 18 | @ApiModel("用户部门") 19 | public class UserDept { 20 | 21 | @ApiModelProperty("用户部门主键Id") 22 | private Long userDeptId; 23 | 24 | @ApiModelProperty("用户Id") 25 | private Long userId; 26 | 27 | @ApiModelProperty("部门Id") 28 | private Long deptId; 29 | 30 | @ApiModelProperty("创建时间") 31 | @JsonFormat(pattern = "yyyy-mm-dd HH:mm:ss",timezone = "GMT+8") 32 | private Date createTime; 33 | 34 | @ApiModelProperty("更新时间") 35 | @JsonFormat(pattern = "yyyy-mm-dd HH:mm:ss",timezone = "GMT+8") 36 | private Date updateTime; 37 | 38 | 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/com/codeworld/fc/system/user/mapper/UserDeptMapper.java: -------------------------------------------------------------------------------- 1 | package com.codeworld.fc.system.user.mapper; 2 | 3 | import com.codeworld.fc.system.user.entity.UserDept; 4 | import org.apache.ibatis.annotations.Mapper; 5 | import org.springframework.stereotype.Repository; 6 | 7 | import java.util.List; 8 | 9 | @Mapper 10 | @Repository 11 | public interface UserDeptMapper { 12 | 13 | /** 14 | * 添加用户部门 15 | * @param userDept 16 | */ 17 | void addUserDept(UserDept userDept); 18 | 19 | /** 20 | * 根据用户Id获取部门Id 21 | * @param userId 22 | * @return 23 | */ 24 | List getDeptIdByUserId(Long userId); 25 | 26 | /** 27 | * 根据用户Id删除用户部门 28 | * 29 | * @param userId 30 | */ 31 | void deleteUserDeptByUserId(Long userId); 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/com/codeworld/fc/system/user/mapper/UserMapper.java: -------------------------------------------------------------------------------- 1 | package com.codeworld.fc.system.user.mapper; 2 | 3 | import com.codeworld.fc.system.user.dto.UserDeptResponse; 4 | import com.codeworld.fc.system.user.entity.User; 5 | import com.codeworld.fc.system.user.vo.UserSearchRequest; 6 | import org.apache.ibatis.annotations.Mapper; 7 | import org.springframework.stereotype.Repository; 8 | 9 | import java.util.List; 10 | 11 | @Mapper 12 | @Repository 13 | public interface UserMapper { 14 | /** 15 | * 获取全部用户 16 | * @return 17 | */ 18 | List getAllUser(UserSearchRequest userSearchRequest); 19 | 20 | /** 21 | * 修改用户状态 22 | * @param user 23 | */ 24 | void updateUserStatus(User user); 25 | 26 | /** 27 | * 删除用户 28 | * @param userId 29 | */ 30 | void deleteUser(Long userId); 31 | 32 | /** 33 | * 添加用户 34 | * @param user 35 | */ 36 | void addUser(User user); 37 | 38 | /** 39 | * 根据用户名查询用户 40 | * @param userName 41 | * @return 42 | */ 43 | User getUserByName(String userName); 44 | 45 | /** 46 | * 更新用户信息 47 | * @param user 48 | */ 49 | void updateUser(User user); 50 | 51 | /** 52 | * 根据部门Id获取用户 53 | * @param deptId 54 | * @return 55 | */ 56 | List getUserByDeptId(Long deptId); 57 | 58 | /** 59 | * 获取用户全部数量 60 | * @return 61 | */ 62 | Long getAllUserCount(); 63 | } 64 | -------------------------------------------------------------------------------- /src/main/java/com/codeworld/fc/system/user/service/LoginService.java: -------------------------------------------------------------------------------- 1 | package com.codeworld.fc.system.user.service; 2 | 3 | import com.codeworld.fc.common.response.FCResponse; 4 | import com.codeworld.fc.system.user.vo.UserLoginOutRequest; 5 | import com.codeworld.fc.system.user.vo.UserLoginRequest; 6 | 7 | import javax.servlet.http.HttpServletRequest; 8 | import javax.servlet.http.HttpServletResponse; 9 | import java.util.Map; 10 | 11 | public interface LoginService { 12 | /** 13 | * 用户登录操作 14 | * 15 | * @param userLoginRequest 16 | * @return 17 | */ 18 | FCResponse> login(UserLoginRequest userLoginRequest, HttpServletRequest request, HttpServletResponse response); 19 | 20 | /** 21 | * 退出登录 22 | * @param userLoginOutRequest 23 | * @return 24 | */ 25 | FCResponse loginOut(UserLoginOutRequest userLoginOutRequest); 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/com/codeworld/fc/system/user/service/UserDeptService.java: -------------------------------------------------------------------------------- 1 | package com.codeworld.fc.system.user.service; 2 | 3 | import com.codeworld.fc.common.response.FCResponse; 4 | import com.codeworld.fc.system.user.entity.UserDept; 5 | 6 | import java.util.List; 7 | 8 | public interface UserDeptService { 9 | /** 10 | * 根据用户Id获取部门Id 11 | * 12 | * @param userId 13 | * @return 14 | */ 15 | FCResponse> getDeptIdByUserId(Long userId); 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/com/codeworld/fc/system/user/service/UserService.java: -------------------------------------------------------------------------------- 1 | package com.codeworld.fc.system.user.service; 2 | 3 | import com.codeworld.fc.common.response.DataResponse; 4 | import com.codeworld.fc.common.response.FCResponse; 5 | import com.codeworld.fc.system.user.dto.UserDeptResponse; 6 | import com.codeworld.fc.system.user.dto.UserInfoResponse; 7 | import com.codeworld.fc.system.user.entity.User; 8 | import com.codeworld.fc.system.user.vo.UserLoginRequest; 9 | import com.codeworld.fc.system.user.vo.UserRegisterRequest; 10 | import com.codeworld.fc.system.user.vo.UserSearchRequest; 11 | import com.codeworld.fc.system.user.vo.UserUpdateRequest; 12 | 13 | import javax.servlet.http.HttpServletRequest; 14 | import javax.servlet.http.HttpServletResponse; 15 | import java.util.List; 16 | 17 | public interface UserService { 18 | /** 19 | * 获取全部用户 20 | * 21 | * @return 22 | */ 23 | FCResponse>> getAllUser(UserSearchRequest userSearchRequest); 24 | 25 | /** 26 | * 修改用户状态 27 | * 28 | * @param userId 29 | * @param userStatus 30 | * @return 31 | */ 32 | FCResponse updateUserStatus(Long userId, Integer userStatus); 33 | 34 | /** 35 | * 删除用户 36 | * @param userId 37 | * @return 38 | */ 39 | FCResponse deleteUser(Long userId); 40 | 41 | /** 42 | * 添加用户 43 | * @param userRegisterRequest 44 | * @return 45 | */ 46 | FCResponse addUser(UserRegisterRequest userRegisterRequest); 47 | 48 | /** 49 | * 修改用户 50 | * @param userUpdateRequest 51 | * @return 52 | */ 53 | FCResponse updateUser(UserUpdateRequest userUpdateRequest); 54 | 55 | /** 56 | * 根据用户名获取用户 57 | * @param userName 58 | * @return 59 | */ 60 | FCResponse getUserByName(String userName); 61 | 62 | /** 63 | * 获取用户信息 64 | * @return 65 | */ 66 | FCResponse getUserInfo(UserLoginRequest userLoginRequest, HttpServletRequest request, HttpServletResponse response); 67 | 68 | /** 69 | * 根据部门Id获取用户 70 | * @param deptId 71 | * @return 72 | */ 73 | FCResponse> getUserByDeptId(Long deptId); 74 | 75 | /** 76 | * 获取全部用户数量 77 | * @return 78 | */ 79 | FCResponse getAllUserCount(); 80 | } 81 | -------------------------------------------------------------------------------- /src/main/java/com/codeworld/fc/system/user/service/impl/UserDeptServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.codeworld.fc.system.user.service.impl; 2 | 3 | import com.codeworld.fc.common.enums.HttpFcStatus; 4 | import com.codeworld.fc.common.enums.HttpMsg; 5 | import com.codeworld.fc.common.response.FCResponse; 6 | import com.codeworld.fc.system.user.entity.User; 7 | import com.codeworld.fc.system.user.entity.UserDept; 8 | import com.codeworld.fc.system.user.mapper.UserDeptMapper; 9 | import com.codeworld.fc.system.user.service.UserDeptService; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.stereotype.Service; 12 | 13 | import java.util.List; 14 | 15 | /** 16 | * ClassName UserDeptServiceImpl 17 | * Description TODO 18 | * Author Lenovo 19 | * Date 2020/10/14 20 | * Version 1.0 21 | **/ 22 | @Service 23 | public class UserDeptServiceImpl implements UserDeptService { 24 | 25 | @Autowired(required = false) 26 | private UserDeptMapper userDeptMapper; 27 | 28 | /** 29 | * 根据用户Id获取部门Id 30 | * 31 | * @param userId 32 | * @return 33 | */ 34 | @Override 35 | public FCResponse> getDeptIdByUserId(Long userId) { 36 | if (userId == null || userId <= 0){ 37 | return FCResponse.dataResponse(HttpFcStatus.PARAMSERROR.getCode(), HttpMsg.user.USER_ID_ERROR.getMsg(),null); 38 | } 39 | 40 | List userDepts = this.userDeptMapper.getDeptIdByUserId(userId); 41 | return FCResponse.dataResponse(HttpFcStatus.DATASUCCESSGET.getCode(),HttpMsg.dept.DEPT_GET_SUCCESS.getMsg(),userDepts); 42 | } 43 | 44 | 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/com/codeworld/fc/system/user/vo/ButtonVO.java: -------------------------------------------------------------------------------- 1 | package com.codeworld.fc.system.user.vo; 2 | 3 | import io.swagger.annotations.ApiModel; 4 | import io.swagger.annotations.ApiModelProperty; 5 | import lombok.Data; 6 | 7 | /** 8 | * ClassName ButtonVO 9 | * Description 按钮 10 | * Author Lenovo 11 | * Date 2020/9/14 12 | * Version 1.0 13 | **/ 14 | @Data 15 | @ApiModel("按钮") 16 | public class ButtonVO { 17 | 18 | @ApiModelProperty("主键Id") 19 | private Integer id; 20 | 21 | @ApiModelProperty("上级按钮Id") 22 | private String parentId; 23 | 24 | @ApiModelProperty("按钮编码") 25 | private String resources; 26 | 27 | @ApiModelProperty("按钮名称") 28 | private String title; 29 | 30 | @ApiModelProperty("类型") 31 | private String type; 32 | 33 | // @ApiModelProperty("按钮图标") 34 | // private String icon; 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/com/codeworld/fc/system/user/vo/MenuVO.java: -------------------------------------------------------------------------------- 1 | package com.codeworld.fc.system.user.vo; 2 | 3 | import com.google.common.collect.Lists; 4 | import io.swagger.annotations.ApiModel; 5 | import io.swagger.annotations.ApiModelProperty; 6 | import lombok.Data; 7 | 8 | import java.util.List; 9 | 10 | /** 11 | * ClassName MenuVO 12 | * Description 菜单VO 13 | * Author Lenovo 14 | * Date 2020/9/16 15 | * Version 1.0 16 | **/ 17 | @Data 18 | @ApiModel("菜单VO") 19 | public class MenuVO { 20 | 21 | @ApiModelProperty("菜单Id") 22 | private Integer id; 23 | 24 | @ApiModelProperty("上级菜单Id") 25 | private String parentId; 26 | 27 | @ApiModelProperty("菜单编码") 28 | private String resources; 29 | 30 | @ApiModelProperty("菜单名称") 31 | private String title; 32 | 33 | @ApiModelProperty("类型") 34 | private String type; 35 | 36 | // @ApiModelProperty("菜单图标") 37 | // private String icon; 38 | 39 | List children = Lists.newArrayList(); 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/com/codeworld/fc/system/user/vo/UserLoginOutRequest.java: -------------------------------------------------------------------------------- 1 | package com.codeworld.fc.system.user.vo; 2 | 3 | import lombok.Data; 4 | 5 | /** 6 | * ClassName UserLoginOutRequest 7 | * Description 用户退出 8 | * Author Lenovo 9 | * Date 2020/10/10 10 | * Version 1.0 11 | **/ 12 | @Data 13 | public class UserLoginOutRequest { 14 | 15 | private String token; 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/com/codeworld/fc/system/user/vo/UserLoginRequest.java: -------------------------------------------------------------------------------- 1 | package com.codeworld.fc.system.user.vo; 2 | 3 | import io.swagger.annotations.ApiModel; 4 | import io.swagger.annotations.ApiModelProperty; 5 | import lombok.Data; 6 | import javax.validation.constraints.NotNull; 7 | 8 | 9 | /** 10 | * ClassName UserLoginRequest 11 | * Description 用户登录请求数据 12 | * Author Lenovo 13 | * Date 2020/8/12 14 | * Version 1.0 15 | **/ 16 | @Data 17 | @ApiModel("用户登录请求数据") 18 | public class UserLoginRequest { 19 | 20 | @ApiModelProperty("用户名") 21 | @NotNull(message = "用户名为空") 22 | private String username; 23 | 24 | @ApiModelProperty("密码") 25 | @NotNull(message = "密码为空") 26 | private String password; 27 | 28 | @ApiModelProperty("Token验证") 29 | private String token; 30 | 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/com/codeworld/fc/system/user/vo/UserRegisterRequest.java: -------------------------------------------------------------------------------- 1 | package com.codeworld.fc.system.user.vo; 2 | 3 | import io.swagger.annotations.ApiModel; 4 | import io.swagger.annotations.ApiModelProperty; 5 | import lombok.Data; 6 | 7 | import javax.validation.constraints.Email; 8 | import javax.validation.constraints.NotNull; 9 | 10 | /** 11 | * ClassName UserRegisterRequest 12 | * Description 用户添加信息 13 | * Author Lenovo 14 | * Date 2020/8/14 15 | * Version 1.0 16 | **/ 17 | @Data 18 | @ApiModel("用户添加信息") 19 | public class UserRegisterRequest { 20 | 21 | @ApiModelProperty("用户名") 22 | @NotNull(message = "用户名为空") 23 | private String userName; 24 | 25 | @ApiModelProperty("用户邮箱") 26 | @Email(regexp = "^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(.[a-zA-Z0-9_-]+)+$", message = "邮箱格式错误") 27 | @NotNull(message = "邮箱格式错误") 28 | private String userEmail; 29 | 30 | @ApiModelProperty("用户手机") 31 | @NotNull(message = "用户手机为空") 32 | private String userPhone; 33 | 34 | @ApiModelProperty("用户状态") 35 | @NotNull(message = "状态为空") 36 | private Integer userStatus; 37 | 38 | @ApiModelProperty("用户类型") 39 | @NotNull(message = "类型为空") 40 | private Long roleType; 41 | 42 | @ApiModelProperty("用户部门") 43 | @NotNull(message = "用户部门为空") 44 | private Long deptIds; 45 | 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/com/codeworld/fc/system/user/vo/UserSearchRequest.java: -------------------------------------------------------------------------------- 1 | package com.codeworld.fc.system.user.vo; 2 | 3 | import com.fasterxml.jackson.annotation.JsonFormat; 4 | import io.swagger.annotations.ApiModel; 5 | import io.swagger.annotations.ApiModelProperty; 6 | import lombok.Data; 7 | 8 | import java.util.Date; 9 | 10 | /** 11 | * ClassName UserSearchRequest 12 | * Description 用户搜索Request 13 | * Author Lenovo 14 | * Date 2020/8/23 15 | * Version 1.0 16 | **/ 17 | @Data 18 | @ApiModel("用户搜索Request") 19 | public class UserSearchRequest { 20 | 21 | @ApiModelProperty("页数") 22 | private Integer page; 23 | 24 | @ApiModelProperty("数量") 25 | private Integer limit; 26 | 27 | @ApiModelProperty("用户名") 28 | private String userName; 29 | 30 | @ApiModelProperty("用户邮箱") 31 | private String userEmail; 32 | 33 | @ApiModelProperty("用户手机") 34 | private String userPhone; 35 | 36 | @ApiModelProperty("用户状态") 37 | private Integer userStatus; 38 | 39 | @ApiModelProperty("创建时间") 40 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8", locale = "zh") 41 | private Date createTime; 42 | 43 | @ApiModelProperty("更新时间") 44 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8", locale = "zh") 45 | private Date updateTime; 46 | 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/com/codeworld/fc/system/user/vo/UserUpdateRequest.java: -------------------------------------------------------------------------------- 1 | package com.codeworld.fc.system.user.vo; 2 | 3 | import com.alibaba.fastjson.annotation.JSONField; 4 | import com.fasterxml.jackson.annotation.JsonFormat; 5 | import io.swagger.annotations.ApiModel; 6 | import io.swagger.annotations.ApiModelProperty; 7 | import lombok.Data; 8 | import org.springframework.format.annotation.DateTimeFormat; 9 | 10 | import javax.validation.constraints.Email; 11 | import javax.validation.constraints.NotBlank; 12 | import javax.validation.constraints.NotNull; 13 | import java.util.Date; 14 | 15 | /** 16 | * ClassName UserUpdateRequest 17 | * Description 用户修改信息 18 | * Author Lenovo 19 | * Date 2020/8/15 20 | * Version 1.0 21 | **/ 22 | @Data 23 | @ApiModel("用户修改信息DTO") 24 | public class UserUpdateRequest { 25 | 26 | @ApiModelProperty("用户Id") 27 | @NotNull(message = "用户Id为空") 28 | private Long userId; 29 | 30 | @ApiModelProperty("用户名") 31 | @NotNull(message = "用户名为空") 32 | private String userName; 33 | 34 | @ApiModelProperty("用户邮箱") 35 | @Email(regexp = "^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(.[a-zA-Z0-9_-]+)+$", message = "邮箱格式错误") 36 | @NotNull(message = "邮箱为空") 37 | private String userEmail; 38 | 39 | @ApiModelProperty("用户手机") 40 | @NotBlank(message = "用户手机为空") 41 | private String userPhone; 42 | 43 | @ApiModelProperty("用户状态") 44 | @NotNull(message = "状态为空") 45 | private Integer userStatus; 46 | 47 | @ApiModelProperty("用户类型") 48 | @NotNull(message = "类型为空") 49 | private Long roleType; 50 | 51 | @ApiModelProperty("用户部门") 52 | @NotNull(message = "用户部门为空") 53 | private Long deptIds; 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/com/codeworld/fc/utils/AddressUtil.java: -------------------------------------------------------------------------------- 1 | package com.codeworld.fc.utils; 2 | 3 | import org.apache.commons.io.FileUtils; 4 | import org.apache.commons.lang3.StringUtils; 5 | import org.lionsoul.ip2region.DataBlock; 6 | import org.lionsoul.ip2region.DbConfig; 7 | import org.lionsoul.ip2region.DbSearcher; 8 | import org.lionsoul.ip2region.Util; 9 | import org.slf4j.Logger; 10 | import org.slf4j.LoggerFactory; 11 | 12 | import java.io.File; 13 | import java.io.IOException; 14 | import java.io.InputStream; 15 | import java.lang.reflect.Method; 16 | 17 | /** 18 | * 地点获取工具类 19 | */ 20 | public class AddressUtil { 21 | 22 | private static Logger log = LoggerFactory.getLogger(AddressUtil.class); 23 | 24 | public static String getCityInfo(String ip) { 25 | DbSearcher searcher = null; 26 | try { 27 | String dbPath = AddressUtil.class.getResource("/ip2region/ip2region.db").getPath(); 28 | File file = new File(dbPath); 29 | if (!file.exists()) { 30 | String tmpDir = System.getProperties().getProperty("java.io.tmpdir"); 31 | dbPath = tmpDir + "ip.db"; 32 | file = new File(dbPath); 33 | InputStream resourceAsStream = AddressUtil.class.getClassLoader().getResourceAsStream("classpath:ip2region/ip2region.db"); 34 | if (resourceAsStream != null) { 35 | FileUtils.copyInputStreamToFile(resourceAsStream, file); 36 | } 37 | } 38 | DbConfig config = new DbConfig(); 39 | searcher = new DbSearcher(config, file.getPath()); 40 | Method method = searcher.getClass().getMethod("btreeSearch", String.class); 41 | if (!Util.isIpAddress(ip)) { 42 | log.error("Error: Invalid ip address"); 43 | } 44 | DataBlock dataBlock = (DataBlock) method.invoke(searcher, ip); 45 | return dataBlock.getRegion(); 46 | } catch (Exception e) { 47 | log.error("获取地址信息异常,{}", e.getMessage()); 48 | return StringUtils.EMPTY; 49 | } finally { 50 | if (searcher != null) { 51 | try { 52 | searcher.close(); 53 | } catch (IOException e) { 54 | e.printStackTrace(); 55 | } 56 | } 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/com/codeworld/fc/utils/HttpContextUtil.java: -------------------------------------------------------------------------------- 1 | package com.codeworld.fc.utils; 2 | 3 | import org.springframework.web.context.request.RequestContextHolder; 4 | import org.springframework.web.context.request.ServletRequestAttributes; 5 | 6 | import javax.servlet.http.HttpServletRequest; 7 | import java.util.Objects; 8 | 9 | /** 10 | * @author MrBird 11 | */ 12 | public class HttpContextUtil { 13 | 14 | private HttpContextUtil(){ 15 | 16 | } 17 | public static HttpServletRequest getHttpServletRequest() { 18 | return ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest(); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/com/codeworld/fc/utils/IDGeneratorUtil.java: -------------------------------------------------------------------------------- 1 | package com.codeworld.fc.utils; 2 | 3 | import java.util.Random; 4 | 5 | /** 6 | * @author Lenovo 7 | */ 8 | public class IDGeneratorUtil { 9 | 10 | /** 11 | * 对象实例 12 | */ 13 | private static IDGeneratorUtil generateIdUtil = new IDGeneratorUtil(); 14 | 15 | /** 16 | * 随机数实例 17 | */ 18 | private static Random random = new Random(9); 19 | 20 | /** 21 | * @return GenerateIdUtil 22 | * @throws 23 | * @author chenly 24 | * getInstance 获得对象实例 25 | * @since 1.0.0 26 | */ 27 | public static IDGeneratorUtil getInstance() { 28 | return generateIdUtil; 29 | } 30 | 31 | /** 32 | * @return long 33 | * @throws 34 | * @author chenly 35 | * getNextId 返回一个当前时间的long类型数字 36 | * @since 1.0.0 37 | */ 38 | public static synchronized long getNextId() { 39 | 40 | 41 | //单纯时间同时保存多条记录时会造成主键冲突 modifed by liusp at 20130312 42 | Long id = System.currentTimeMillis() + random.nextInt(); 43 | 44 | String categoryId = String.valueOf(id); 45 | 46 | // 截取后面的6位数字 47 | categoryId = categoryId.substring(7); 48 | 49 | return Long.valueOf(categoryId); 50 | } 51 | 52 | /** 53 | * 生成用户Id主键 54 | * @return 55 | */ 56 | public static synchronized long getUserId(){ 57 | 58 | //单纯时间同时保存多条记录时会造成主键冲突 modifed by liusp at 20130312 59 | Long id = System.currentTimeMillis() + random.nextInt(); 60 | 61 | String userId = String.valueOf(id); 62 | 63 | // 截取后面的5位数字 64 | userId = userId.substring(6); 65 | 66 | return Long.valueOf(userId); 67 | } 68 | 69 | 70 | } 71 | -------------------------------------------------------------------------------- /src/main/java/com/codeworld/fc/utils/IPUtil.java: -------------------------------------------------------------------------------- 1 | package com.codeworld.fc.utils; 2 | 3 | import javax.servlet.http.HttpServletRequest; 4 | 5 | /** 6 | * IP工具类 7 | */ 8 | public class IPUtil { 9 | 10 | private static final String UNKNOWN = "unknown"; 11 | 12 | protected IPUtil(){ 13 | 14 | } 15 | 16 | /** 17 | * 获取 IP地址 18 | * 使用 Nginx等反向代理软件, 则不能通过 request.getRemoteAddr()获取 IP地址 19 | * 如果使用了多级反向代理的话,X-Forwarded-For的值并不止一个,而是一串IP地址, 20 | * X-Forwarded-For中第一个非 unknown的有效IP字符串,则为真实IP地址 21 | */ 22 | public static String getIpAddr(HttpServletRequest request) { 23 | String ip = request.getHeader("x-forwarded-for"); 24 | if (ip == null || ip.length() == 0 || UNKNOWN.equalsIgnoreCase(ip)) { 25 | ip = request.getHeader("Proxy-Client-IP"); 26 | } 27 | if (ip == null || ip.length() == 0 || UNKNOWN.equalsIgnoreCase(ip)) { 28 | ip = request.getHeader("WL-Proxy-Client-IP"); 29 | } 30 | if (ip == null || ip.length() == 0 || UNKNOWN.equalsIgnoreCase(ip)) { 31 | ip = request.getRemoteAddr(); 32 | } 33 | return "0:0:0:0:0:0:0:1".equals(ip) ? "127.0.0.1" : ip; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/com/codeworld/fc/utils/JsonUtils.java: -------------------------------------------------------------------------------- 1 | package com.codeworld.fc.utils; 2 | 3 | import com.fasterxml.jackson.core.JsonProcessingException; 4 | import com.fasterxml.jackson.core.type.TypeReference; 5 | import com.fasterxml.jackson.databind.ObjectMapper; 6 | import org.slf4j.Logger; 7 | import org.slf4j.LoggerFactory; 8 | import org.springframework.lang.Nullable; 9 | 10 | import java.io.IOException; 11 | import java.util.List; 12 | import java.util.Map; 13 | 14 | public class JsonUtils { 15 | 16 | public static final ObjectMapper mapper = new ObjectMapper(); 17 | 18 | private static final Logger logger = LoggerFactory.getLogger(JsonUtils.class); 19 | 20 | @Nullable 21 | public static String serialize(Object obj) { 22 | if (obj == null) { 23 | return null; 24 | } 25 | if (obj.getClass() == String.class) { 26 | return (String) obj; 27 | } 28 | try { 29 | return mapper.writeValueAsString(obj); 30 | } catch (JsonProcessingException e) { 31 | logger.error("json序列化出错:" + obj, e); 32 | return null; 33 | } 34 | } 35 | 36 | @Nullable 37 | public static T parse(String json, Class tClass) { 38 | try { 39 | return mapper.readValue(json, tClass); 40 | } catch (IOException e) { 41 | logger.error("json解析出错:" + json, e); 42 | return null; 43 | } 44 | } 45 | 46 | @Nullable 47 | public static List parseList(String json, Class eClass) { 48 | try { 49 | return mapper.readValue(json, mapper.getTypeFactory().constructCollectionType(List.class, eClass)); 50 | } catch (IOException e) { 51 | logger.error("json解析出错:" + json, e); 52 | return null; 53 | } 54 | } 55 | 56 | @Nullable 57 | public static Map parseMap(String json, Class kClass, Class vClass) { 58 | try { 59 | return mapper.readValue(json, mapper.getTypeFactory().constructMapType(Map.class, kClass, vClass)); 60 | } catch (IOException e) { 61 | logger.error("json解析出错:" + json, e); 62 | return null; 63 | } 64 | } 65 | 66 | @Nullable 67 | public static T nativeRead(String json, TypeReference type) { 68 | try { 69 | return mapper.readValue(json, type); 70 | } catch (IOException e) { 71 | logger.error("json解析出错:" + json, e); 72 | return null; 73 | } 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /src/main/java/com/codeworld/fc/utils/SecurityUtils.java: -------------------------------------------------------------------------------- 1 | package com.codeworld.fc.utils; 2 | 3 | import com.codeworld.fc.common.authority.JWTUtil; 4 | import com.codeworld.fc.common.authority.JwtAuthenticationToken; 5 | import com.codeworld.fc.system.user.vo.UserLoginRequest; 6 | import org.springframework.security.authentication.AuthenticationManager; 7 | import org.springframework.security.core.Authentication; 8 | import org.springframework.security.core.context.SecurityContextHolder; 9 | import org.springframework.security.core.userdetails.UserDetails; 10 | import org.springframework.security.web.authentication.WebAuthenticationDetailsSource; 11 | 12 | import javax.servlet.http.HttpServletRequest; 13 | 14 | /** 15 | * ClassName SecurityUtils 16 | * Description Security相关操作 17 | * Author Lenovo 18 | * Date 2020/9/27 19 | * Version 1.0 20 | **/ 21 | public class SecurityUtils { 22 | 23 | 24 | /** 25 | * 系统认证登录 26 | * @param request 27 | * @param userLoginRequest 28 | */ 29 | public static JwtAuthenticationToken login(HttpServletRequest request, UserLoginRequest userLoginRequest, AuthenticationManager authenticationManager) { 30 | 31 | JwtAuthenticationToken token = new JwtAuthenticationToken(userLoginRequest.getUsername(),userLoginRequest.getPassword()); 32 | token.setDetails(new WebAuthenticationDetailsSource().buildDetails(request)); 33 | // 执行登录过程 34 | Authentication authenticate = authenticationManager.authenticate(token); 35 | // 认证成功储存信息到上下文 36 | SecurityContextHolder.getContext().setAuthentication(authenticate); 37 | // 生成令牌返回给客户端 38 | token.setToken(JWTUtil.sign(authenticate)); 39 | return token; 40 | } 41 | 42 | 43 | /** 44 | * 获取用户名 45 | * @return 46 | */ 47 | public static String getUsername(Authentication authentication) { 48 | String username = null; 49 | if(authentication != null) { 50 | Object principal = authentication.getPrincipal(); 51 | if(principal != null && principal instanceof UserDetails) { 52 | username = ((UserDetails) principal).getUsername(); 53 | } 54 | } 55 | return username; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/com/codeworld/fc/utils/SpringContextUtil.java: -------------------------------------------------------------------------------- 1 | package com.codeworld.fc.utils; 2 | 3 | import org.springframework.beans.BeansException; 4 | import org.springframework.context.ApplicationContext; 5 | import org.springframework.context.ApplicationContextAware; 6 | import org.springframework.stereotype.Component; 7 | 8 | /** 9 | * ClassName SpringContextUtil 10 | * Description Spring Context 工具类 11 | * Author Lenovo 12 | * Date 2020/9/22 13 | * Version 1.0 14 | **/ 15 | @Component 16 | public class SpringContextUtil implements ApplicationContextAware { 17 | 18 | private static ApplicationContext applicationContext; 19 | 20 | @Override 21 | public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { 22 | SpringContextUtil.applicationContext = applicationContext; 23 | } 24 | 25 | public static Object getBean(String name) { 26 | return applicationContext.getBean(name); 27 | } 28 | public static T getBean(Class clazz){ 29 | return applicationContext.getBean(clazz); 30 | } 31 | 32 | public static T getBean(String name, Class requiredType) { 33 | return applicationContext.getBean(name, requiredType); 34 | } 35 | 36 | public static boolean containsBean(String name) { 37 | return applicationContext.containsBean(name); 38 | } 39 | 40 | public static boolean isSingleton(String name) { 41 | return applicationContext.isSingleton(name); 42 | } 43 | 44 | public static Class getType(String name) { 45 | return applicationContext.getType(name); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/com/codeworld/fc/utils/TreeBuilder.java: -------------------------------------------------------------------------------- 1 | package com.codeworld.fc.utils; 2 | 3 | import com.codeworld.fc.system.dept.dto.DeptTreeNode; 4 | import com.codeworld.fc.system.menu.dto.MenuTreeNode; 5 | import com.codeworld.fc.system.user.vo.MenuVO; 6 | import com.google.common.collect.Lists; 7 | 8 | import java.util.Comparator; 9 | import java.util.HashSet; 10 | import java.util.List; 11 | import java.util.Set; 12 | import java.util.stream.Collectors; 13 | 14 | /** 15 | * ClassName TreeBuilder 16 | * Description 树构造工具类 17 | * Author Lenovo 18 | * Date 2020/8/26 19 | * Version 1.0 20 | **/ 21 | public class TreeBuilder { 22 | 23 | public static List buildMenuTree(List allNodes) { 24 | // 根节点 25 | List root = Lists.newArrayList(); 26 | allNodes.forEach(node -> { 27 | if (node.getParentId() == 0) { 28 | root.add(node); 29 | } 30 | }); 31 | root.forEach(node -> { 32 | findMenuChildren(node, allNodes); 33 | }); 34 | 35 | //对根节点排序 36 | List sortedList = root.stream().sorted(Comparator.comparing(MenuTreeNode::getSortNo)).collect(Collectors.toList()); 37 | //先清空,在添加 38 | root.clear(); 39 | root.addAll(sortedList); 40 | return root; 41 | } 42 | 43 | /** 44 | * 递归查找子节点 45 | * 46 | * @param treeNodes 47 | * @return 48 | */ 49 | private static MenuTreeNode findMenuChildren(MenuTreeNode treeNode, List treeNodes) { 50 | for (MenuTreeNode it : treeNodes) { 51 | if (treeNode.getId().longValue() == it.getParentId().longValue()) { 52 | treeNode.getChildren().add(findMenuChildren(it, treeNodes)); 53 | } 54 | } 55 | //对子节点排序 56 | List childrenSorted = treeNode.getChildren().stream().sorted(Comparator.comparing(MenuTreeNode::getSortNo)).collect(Collectors.toList()); 57 | //先清空,在添加 58 | treeNode.getChildren().clear(); 59 | treeNode.getChildren().addAll(childrenSorted); 60 | return treeNode; 61 | } 62 | 63 | public static Set buildTree(Set allNodes) { 64 | // 根节点 65 | Set root = new HashSet<>(); 66 | allNodes.forEach(node -> { 67 | if (Integer.valueOf( node.getParentId() ) == 0) { 68 | root.add(node); 69 | } 70 | }); 71 | root.forEach(node -> { 72 | findChildren(node, allNodes); 73 | }); 74 | return root; 75 | } 76 | 77 | /** 78 | * 递归查找子节点 79 | * 80 | * @param treeNodes 81 | * @return 82 | */ 83 | private static MenuVO findChildren(MenuVO treeNode, Set treeNodes) { 84 | for (MenuVO it : treeNodes) { 85 | if (String.valueOf( treeNode.getId() ).equals(it.getParentId())) { 86 | treeNode.getChildren().add(findChildren(it, treeNodes)); 87 | } 88 | } 89 | return treeNode; 90 | } 91 | 92 | 93 | public static List buildDeptTree(List deptTreeNodeList) { 94 | 95 | // 根节点 96 | List root = Lists.newArrayList(); 97 | deptTreeNodeList.forEach(node -> { 98 | if (node.getParentId() == 0) { 99 | root.add(node); 100 | } 101 | }); 102 | root.forEach(node -> { 103 | findDeptChildren(node, deptTreeNodeList); 104 | }); 105 | 106 | //对根节点排序 107 | List sortedList = root.stream().sorted(Comparator.comparing(DeptTreeNode::getSortNo)).collect(Collectors.toList()); 108 | //先清空,在添加 109 | root.clear(); 110 | root.addAll(sortedList); 111 | return root; 112 | } 113 | 114 | /** 115 | * 递归查找子节点--部门 116 | * 117 | * @param treeNodes 118 | * @return 119 | */ 120 | private static DeptTreeNode findDeptChildren(DeptTreeNode treeNode, List treeNodes) { 121 | for (DeptTreeNode it : treeNodes) { 122 | if (treeNode.getId().longValue() == it.getParentId().longValue()) { 123 | treeNode.getChildren().add(findDeptChildren(it, treeNodes)); 124 | } 125 | } 126 | //对子节点排序 127 | List childrenSorted = treeNode.getChildren().stream().sorted(Comparator.comparing(DeptTreeNode::getSortNo)).collect(Collectors.toList()); 128 | //先清空,在添加 129 | treeNode.getChildren().clear(); 130 | treeNode.getChildren().addAll(childrenSorted); 131 | return treeNode; 132 | } 133 | } 134 | -------------------------------------------------------------------------------- /src/main/java/com/codeworld/fc/utils/UserUtils.java: -------------------------------------------------------------------------------- 1 | package com.codeworld.fc.utils; 2 | 3 | import com.codeworld.fc.system.user.dto.UserInfoResponse; 4 | 5 | /** 6 | * ClassName UserUtils 7 | * Description 存储/获取当前线程的用户信息工具类 8 | * Author Lenovo 9 | * Date 2020/10/19 10 | * Version 1.0 11 | **/ 12 | public class UserUtils { 13 | 14 | // 线程变量,存放User实体类信息,即使是静态的与其他线程也是隔离的 15 | private static ThreadLocal userInfoResponseThreadLocal = new ThreadLocal(); 16 | 17 | // 从当前线程变量中获取用户信息 18 | public static UserInfoResponse getCurrentUser(){ 19 | UserInfoResponse userInfoResponse = userInfoResponseThreadLocal.get(); 20 | return userInfoResponse; 21 | } 22 | 23 | // 获取当前用户的Id 24 | public static Long getUserId(){ 25 | UserInfoResponse userInfoResponse = userInfoResponseThreadLocal.get(); 26 | if (userInfoResponse != null && userInfoResponse.getUserId() != null && userInfoResponse.getUserId() > 0){ 27 | return userInfoResponse.getUserId(); 28 | } 29 | return null; 30 | } 31 | 32 | // 为当前线程变量赋值上用户信息 33 | public static void setLoginUser(UserInfoResponse userInfoResponse){ 34 | userInfoResponseThreadLocal.set(userInfoResponse); 35 | } 36 | 37 | // 清除线程变量 38 | public static void removeUser(){ 39 | userInfoResponseThreadLocal.remove(); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/com/codeworld/fc/utils/ValidateUtil.java: -------------------------------------------------------------------------------- 1 | package com.codeworld.fc.utils; 2 | 3 | import org.apache.commons.lang3.StringUtils; 4 | 5 | import java.util.regex.Matcher; 6 | import java.util.regex.Pattern; 7 | 8 | /** 9 | * 信息校验工具类 10 | */ 11 | public class ValidateUtil { 12 | 13 | /** 14 | * 邮箱校验规则 15 | */ 16 | private static final String emailRegex = "^([a-z0-9A-Z]+[-|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$"; 17 | 18 | /** 19 | * 校验参数有效性 20 | * @param params 21 | * @return 22 | */ 23 | public static boolean validateParams(String params){ 24 | 25 | if (StringUtils.isBlank(params)){ 26 | 27 | return false; 28 | } 29 | 30 | return true; 31 | } 32 | 33 | /** 34 | * 校验邮箱合法性 35 | * @param email 36 | * @return 37 | */ 38 | public static boolean validateEmailRegex(String email){ 39 | 40 | // 校验合格 41 | if (Pattern.matches(emailRegex,email)){ 42 | 43 | return true; 44 | } 45 | 46 | // 校验不合格 47 | return false; 48 | } 49 | 50 | 51 | /** 52 | * 判断是否包含中文 53 | * 54 | * @param value 内容 55 | * @return 结果 56 | */ 57 | public static boolean containChinese(String value) { 58 | Pattern p = Pattern.compile("[\u4e00-\u9fa5]"); 59 | Matcher m = p.matcher(value); 60 | return m.find(); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/main/resources/application-dev.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | datasource: 3 | dynamic: 4 | # 是否开启 SQL日志输出,生产环境建议关闭,有性能损耗 5 | p6spy: false 6 | hikari: 7 | connection-timeout: 30000 8 | max-lifetime: 1800000 9 | max-pool-size: 15 10 | min-idle: 5 11 | connection-test-query: select 1 12 | pool-name: FebsHikariCP 13 | # 配置默认数据源 14 | primary: base 15 | datasource: 16 | # 数据源-1,名称为 base 17 | base: 18 | username: root 19 | password: root 20 | driver-class-name: com.mysql.cj.jdbc.Driver 21 | url: jdbc:mysql://192.168.2.6:3306/codeworld-vue-system?useUnicode=true&characterEncoding=UTF-8&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT%2b8 22 | quartz: 23 | url: jdbc:mysql://192.168.2.6:3306/codeworld-quartz?useUnicode=true&characterEncoding=UTF-8&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT%2b8 24 | driver-class-name: com.mysql.jdbc.Driver 25 | username: root 26 | password: root 27 | #开启Aop 28 | aop: 29 | auto: true 30 | proxy-target-class: true 31 | redis: 32 | host: 192.168.2.6 33 | database: 0 34 | mybatis: 35 | mapper-locations: classpath:mapper/*.xml 36 | -------------------------------------------------------------------------------- /src/main/resources/application-test.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | datasource: 3 | dynamic: 4 | # 是否开启 SQL日志输出,生产环境建议关闭,有性能损耗 5 | p6spy: true 6 | hikari: 7 | connection-timeout: 30000 8 | max-lifetime: 1800000 9 | max-pool-size: 15 10 | min-idle: 5 11 | connection-test-query: select 1 12 | pool-name: FebsHikariCP 13 | # 配置默认数据源 14 | primary: base 15 | datasource: 16 | # 数据源-1,名称为 base 17 | base: 18 | username: root 19 | password: root 20 | driver-class-name: com.mysql.cj.jdbc.Driver 21 | url: jdbc:mysql://127.0.0.1:3306/codeworld-vue-system?useUnicode=true&characterEncoding=UTF-8&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT%2b8 22 | quartz: 23 | url: jdbc:mysql://127.0.0.1:3306/codeworld_quartz?useUnicode=true&characterEncoding=UTF-8&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT%2b8 24 | driver-class-name: com.mysql.jdbc.Driver 25 | username: root 26 | password: root 27 | 28 | #开启Aop 29 | aop: 30 | auto: true 31 | proxy-target-class: true 32 | jackson: 33 | time-zone: GMT+08:00 34 | date-format: yyyy-MM-dd HH:mm:ss 35 | mvc: 36 | format: 37 | date-time: yyyy-MM-dd HH:mm:ss 38 | redis: 39 | host: 192.168.2.4 40 | database: 0 41 | mybatis: 42 | mapper-locations: classpath:mapper/*.xml 43 | -------------------------------------------------------------------------------- /src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8888 3 | spring: 4 | profiles: 5 | active: test 6 | -------------------------------------------------------------------------------- /src/main/resources/ip2region/ip2region.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/javaenigneer/codeworld-api-system/14f3d8b7cabe1e945f16429b571234d486b5861b/src/main/resources/ip2region/ip2region.db -------------------------------------------------------------------------------- /src/main/resources/logback-spring.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | codeWorld-FC 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | ${log.colorPattern} 13 | 14 | 15 | 16 | 17 | 18 | 19 | ${log.path}/info/info.%d{yyyy-MM-dd}.log 20 | ${log.maxHistory} 21 | 22 | 23 | ${log.pattern} 24 | 25 | 26 | INFO 27 | ACCEPT 28 | DENY 29 | 30 | 31 | 32 | 33 | 34 | ${log.path}/error/error.%d{yyyy-MM-dd}.log 35 | 36 | 37 | ${log.pattern} 38 | 39 | 40 | ERROR 41 | ACCEPT 42 | DENY 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /src/main/resources/mapper/DeptMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 31 | 32 | 33 | 34 | 35 | insert into codeworld_dept 36 | (t_dept_id,t_parent_id,t_dept_name,t_dept_remarks,t_dept_sort_no,t_create_time,t_update_time) 37 | values (#{id},#{parentId},#{title},#{remarks},#{sortNo},#{createTime},#{updateTime}) 38 | 39 | 40 | 41 | 42 | 43 | update codeworld_dept set 44 | t_dept_name = #{title}, 45 | t_dept_remarks = #{remarks}, 46 | t_dept_sort_no = #{sortNo}, 47 | t_update_time = #{updateTime} 48 | where t_dept_id = #{id} 49 | 50 | 51 | -------------------------------------------------------------------------------- /src/main/resources/mapper/JobLogMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 65 | 66 | 67 | 68 | insert into codeworld_job_log 69 | ( 70 | t_job_log_id, 71 | t_job_id, 72 | t_job_bean_name, 73 | t_job_method_name, 74 | t_job_params, 75 | t_job_status, 76 | t_job_log_error, 77 | t_job_log_time, 78 | t_job_log_create_time 79 | ) values 80 | ( 81 | #{jobLogId}, 82 | #{jobId}, 83 | #{jobBeanName}, 84 | #{jobMethodName}, 85 | #{jobParams}, 86 | #{jobStatus}, 87 | #{jobLogError}, 88 | #{jobLogTime}, 89 | #{jobLogCreateTime} 90 | ); 91 | 92 | 93 | 94 | 95 | 96 | delete from codeworld_job_log where t_job_log_id = #{id} 97 | 98 | 99 | -------------------------------------------------------------------------------- /src/main/resources/mapper/JobMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 67 | 68 | 69 | 72 | 73 | 74 | 75 | 76 | update codeworld_job set t_job_status = #{status} where t_job_id = #{jobId} 77 | 78 | 79 | 80 | 81 | 82 | delete from codeworld_job where t_job_id = #{jobId} 83 | 84 | 85 | 86 | 87 | 88 | insert into codeworld_job 89 | ( 90 | t_job_id, 91 | t_job_bean_name, 92 | t_job_method_name, 93 | t_job_params, 94 | t_job_cron_expression, 95 | t_job_status, 96 | t_job_remark, 97 | t_job_create_time, 98 | t_job_update_time 99 | ) values 100 | ( 101 | #{jobId}, 102 | #{beanName}, 103 | #{methodName}, 104 | #{params}, 105 | #{cronExpression}, 106 | #{status}, 107 | #{remark}, 108 | #{createTime}, 109 | #{updateTime} 110 | ); 111 | 112 | 113 | 114 | -------------------------------------------------------------------------------- /src/main/resources/mapper/LogMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 34 | 35 | 36 | 37 | 38 | insert into codeworld_log (t_log_id, t_log_operation_username, t_log_operation, t_log_time, t_log_method, t_log_params, t_log_ip, t_log_location,t_log_create_time) values ( 39 | 40 | #{logId}, 41 | 42 | #{logOperationUserName}, 43 | 44 | #{logOperation}, 45 | 46 | #{logTime}, 47 | 48 | #{logMethod}, 49 | 50 | #{logParams}, 51 | 52 | #{logIp}, 53 | 54 | #{logLocation}, 55 | 56 | #{logCreateTime} 57 | 58 | ); 59 | 60 | 61 | 62 | 63 | 64 | delete from codeworld_log 65 | 66 | 67 | 68 | 69 | delete from codeworld_log where t_log_id = #{id} 70 | 71 | 72 | -------------------------------------------------------------------------------- /src/main/resources/mapper/LoginLogMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | insert into codeworld_login_log ( 30 | t_login_log_id, 31 | t_login_log_name, 32 | t_login_log_time, 33 | t_login_log_location, 34 | t_login_log_ip, 35 | t_login_log_system, 36 | t_login_log_browser 37 | ) values ( 38 | #{loginLogId}, 39 | #{loginLogName}, 40 | #{loginLogTime}, 41 | #{loginLogLocation}, 42 | #{loginLogIp}, 43 | #{loginLogSystem}, 44 | #{loginLogBrowser} 45 | ); 46 | 47 | 48 | 49 | 50 | 77 | 78 | 79 | 80 | 81 | delete from codeworld_login_log where t_login_log_id = #{id} 82 | 83 | 84 | 85 | -------------------------------------------------------------------------------- /src/main/resources/mapper/MenuMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 36 | 37 | 38 | 56 | 57 | 58 | 62 | 63 | 64 | 68 | 69 | 70 | 71 | 72 | 73 | update codeworld_menu 74 | set 75 | t_menu_url = #{url}, 76 | t_menu_resources = #{resources}, 77 | t_menu_name = #{title}, 78 | t_menu_type = #{type}, 79 | t_menu_remarks = #{remarks}, 80 | t_menu_sort_no = #{sortNo}, 81 | t_update_time = #{updateTime} 82 | where t_menu_id = #{id} 83 | 84 | 85 | 86 | 87 | 88 | insert into codeworld_menu ( 89 | t_menu_id, 90 | t_parent_id , 91 | t_menu_url , 92 | t_menu_resources, 93 | t_menu_name , 94 | t_menu_type, 95 | t_menu_remarks , 96 | t_menu_sort_no , 97 | t_create_time , 98 | t_update_time 99 | ) values (#{id},#{parentId},#{url},#{resources},#{title},#{type},#{remarks},#{sortNo},#{createTime},#{updateTime}); 100 | 101 | 102 | 103 | 104 | 105 | insert into codeworld_role_menu ( 106 | t_role_menu_id, 107 | t_role_id, 108 | t_menu_id, 109 | t_create_time, 110 | t_update_time 111 | ) values (#{roleMenuId},#{roleId},#{menuId},#{createTime},#{updateTime}); 112 | 113 | 114 | 115 | 116 | 117 | 118 | delete from codeworld_role_menu 119 | where t_menu_id in 120 | 121 | #{id} 122 | 123 | 124 | 125 | 126 | 127 | 128 | delete from codeworld_menu where t_menu_id = #{id} 129 | 130 | 131 | 132 | 133 | delete from codeworld_menu where t_parent_id = #{id} 134 | 135 | 136 | 137 | 138 | delete from codeworld_role_menu where t_role_id = #{roleId} 139 | 140 | 141 | -------------------------------------------------------------------------------- /src/main/resources/mapper/RoleMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 54 | 55 | 56 | 68 | 69 | 70 | 74 | 75 | 76 | 79 | 80 | 81 | 82 | 83 | update 84 | codeworld_role 85 | set 86 | t_role_code = #{roleCode}, 87 | t_role_name = #{roleName}, 88 | t_role_remarks = #{roleRemarks}, 89 | t_update_time = #{updateTime} 90 | where t_role_id = #{roleId} 91 | 92 | 93 | 94 | 95 | 96 | insert into codeworld_role (t_role_id,t_role_code,t_role_name,t_role_remarks,t_create_time,t_update_time) values ( 97 | #{roleId}, 98 | #{roleCode}, 99 | #{roleName}, 100 | #{roleRemarks}, 101 | #{createTime}, 102 | #{updateTime} 103 | ); 104 | 105 | 106 | 107 | 108 | insert into codeworld_user_role (t_user_role_id,t_user_id,t_role_id,t_create_time,t_update_time) values ( 109 | #{userRoleId}, 110 | #{userId}, 111 | #{roleId}, 112 | #{createTime}, 113 | #{updateTime} 114 | ); 115 | 116 | 117 | 118 | 119 | delete from codeworld_user_role where t_user_id = #{userId} 120 | 121 | 122 | 123 | 124 | delete from codeworld_user_role where t_role_id = #{roleId} 125 | 126 | 127 | 128 | 129 | delete from codeworld_role where t_role_id = #{roleId} 130 | 131 | 132 | -------------------------------------------------------------------------------- /src/main/resources/mapper/UserDeptMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 24 | 25 | 26 | 27 | 28 | insert into codeworld_user_dept 29 | (t_user_dept_id,t_user_id,t_dept_id,t_create_time,t_update_time) 30 | values 31 | (#{userDeptId},#{userId},#{deptId},#{createTime},#{updateTime}); 32 | 33 | 34 | 35 | 36 | 37 | delete from codeworld_user_dept where t_user_id = #{userId} 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /src/main/resources/mapper/UserMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 67 | 68 | 69 | 74 | 75 | 76 | 92 | 93 | 94 | 97 | 98 | 99 | 100 | update codeworld_user set t_user_status = #{userStatus} where t_user_id = #{userId} 101 | 102 | 103 | 104 | 105 | 106 | 107 | update codeworld_user set 108 | t_user_name = #{userName}, 109 | t_user_email = #{userEmail}, 110 | t_user_phone = #{userPhone}, 111 | t_user_status = #{userStatus}, 112 | t_update_time = #{updateTime} 113 | where t_user_id = #{userId} 114 | 115 | 116 | 117 | 118 | 119 | 120 | delete from codeworld_user where t_user_id = #{userId} 121 | 122 | 123 | 124 | 125 | 126 | 127 | insert into codeworld_user (t_user_id,t_user_name,t_user_email,t_user_phone,t_user_status,t_create_time,t_update_time) values ( 128 | 129 | #{userId}, 130 | #{userName}, 131 | #{userEmail}, 132 | #{userPhone}, 133 | #{userStatus}, 134 | #{createTime}, 135 | #{updateTime} 136 | ); 137 | 138 | 139 | 140 | 141 | 142 | -------------------------------------------------------------------------------- /src/main/resources/quartz.properties: -------------------------------------------------------------------------------- 1 | # 固定前缀org.quartz 2 | # 主要分为scheduler、threadPool、jobStore、plugin等部分 3 | # 4 | # 5 | org.quartz.scheduler.instanceName = DefaultQuartzScheduler 6 | org.quartz.scheduler.rmi.export = false 7 | org.quartz.scheduler.rmi.proxy = false 8 | org.quartz.scheduler.wrapJobExecutionInUserTransaction = false 9 | 10 | # 实例化ThreadPool时,使用的线程类为SimpleThreadPool 11 | org.quartz.threadPool.class = org.quartz.simpl.SimpleThreadPool 12 | 13 | # threadCount和threadPriority将以setter的形式注入ThreadPool实例 14 | # 并发个数 15 | org.quartz.threadPool.threadCount = 5 16 | # 优先级 17 | org.quartz.threadPool.threadPriority = 5 18 | org.quartz.threadPool.threadsInheritContextClassLoaderOfInitializingThread = true 19 | 20 | org.quartz.jobStore.misfireThreshold = 5000 21 | 22 | # 默认存储在内存中 23 | org.quartz.jobStore.class = org.quartz.simpl.RAMJobStore 24 | 25 | #持久化,数据源的链接方式 26 | #org.quartz.jobStore.class = org.quartz.impl.jdbcjobstore.JobStoreTX 27 | 28 | #org.quartz.jobStore.tablePrefix = QRTZ_ 29 | 30 | #org.quartz.jobStore.dataSource = qzDS 31 | 32 | #org.quartz.dataSource.qzDS.driver = com.mysql.jdbc.Driver 33 | 34 | #org.quartz.dataSource.qzDS.URL = 35 | 36 | #org.quartz.dataSource.qzDS.user = 37 | 38 | #org.quartz.dataSource.qzDS.password = 39 | 40 | #org.quartz.dataSource.qzDS.maxConnections = 10 41 | -------------------------------------------------------------------------------- /src/main/resources/rebel-remote.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | com.codeworld.fc.codeworld-vue-system 4 | 5 | -------------------------------------------------------------------------------- /src/main/resources/rebel.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /src/main/resources/spy.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/javaenigneer/codeworld-api-system/14f3d8b7cabe1e945f16429b571234d486b5861b/src/main/resources/spy.properties --------------------------------------------------------------------------------