├── .gitignore ├── README.md ├── img ├── .keep ├── image-20240614165450210.png ├── image-20240614165656746.png ├── image-20240614165945228.png ├── image-20240614180043158.png ├── image-20240614180123585.png ├── image-20240614180736332.png ├── image-20240614201845944.png ├── image-20240614202044813.png ├── image-20240614202617706.png ├── image-20240614202810543.png ├── image-20240614203033979.png ├── image-20240614203330284.png ├── image-20240614204047720.png ├── image-20240614204238429.png ├── image-20240614204436457.png ├── image-20240614204633520.png └── special1.png ├── pom.xml ├── replay_pid16600.log ├── sql └── video.sql ├── tools └── Redis-x64-3.0.504.zip ├── video-admin ├── .gitignore ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── zhu │ │ │ ├── VideoAdminApplication.java │ │ │ ├── annotate │ │ │ └── Dict.java │ │ │ ├── aop │ │ │ └── DictAspect.java │ │ │ ├── config │ │ │ ├── ControllerResponseAdvice.java │ │ │ ├── ReloadMessageConfig.java │ │ │ └── SecurityConfig.java │ │ │ ├── constant │ │ │ └── DataConstant.java │ │ │ ├── controller │ │ │ ├── AuthController.java │ │ │ ├── CommentController.java │ │ │ ├── DictController.java │ │ │ ├── DictDataController.java │ │ │ ├── MenuController.java │ │ │ ├── TypeController.java │ │ │ ├── UserController.java │ │ │ └── VideoController.java │ │ │ ├── exception │ │ │ ├── CaptchaException.java │ │ │ ├── GlobalException.java │ │ │ ├── JwtException.java │ │ │ └── SecurityException.java │ │ │ ├── listener │ │ │ └── AuthenticationFailureListener.java │ │ │ ├── mapper │ │ │ ├── DictDataMapper.java │ │ │ ├── DictMapper.java │ │ │ ├── MenuMapper.java │ │ │ └── UserMapper.java │ │ │ ├── model │ │ │ ├── entity │ │ │ │ ├── Base.java │ │ │ │ ├── Dict.java │ │ │ │ ├── DictData.java │ │ │ │ ├── Menu.java │ │ │ │ ├── Role.java │ │ │ │ └── User.java │ │ │ └── vo │ │ │ │ ├── CaptchaVo.java │ │ │ │ ├── DictTypeVo.java │ │ │ │ ├── DictVo.java │ │ │ │ ├── MenuVo.java │ │ │ │ └── PasswordVo.java │ │ │ ├── query │ │ │ ├── MenuQuery.java │ │ │ └── UserQuery.java │ │ │ ├── security │ │ │ ├── CaptchaFilter.java │ │ │ ├── JwtAccessDeniedHandler.java │ │ │ ├── JwtAuthenticationEntryPoint.java │ │ │ ├── JwtFilter.java │ │ │ ├── JwtLogoutSuccessHandler.java │ │ │ ├── LoginFailureHandler.java │ │ │ ├── LoginSuccessHandler.java │ │ │ ├── UserDetail.java │ │ │ └── UserDetailServiceImpl.java │ │ │ ├── service │ │ │ ├── IDictDataService.java │ │ │ ├── IDictService.java │ │ │ ├── IMenuService.java │ │ │ ├── IUserService.java │ │ │ └── impl │ │ │ │ ├── DictDataServiceImpl.java │ │ │ │ ├── DictServiceImpl.java │ │ │ │ ├── MenuServiceImpl.java │ │ │ │ └── UserServiceImpl.java │ │ │ └── utils │ │ │ ├── IpUtil.java │ │ │ ├── JwtUtils.java │ │ │ ├── ObjConvertUtils.java │ │ │ └── UUIDUtils.java │ └── resources │ │ ├── application.yml │ │ └── mapper │ │ ├── DictDataMapper.xml │ │ ├── DictMapper.xml │ │ ├── MenuMapper.xml │ │ └── UserMapper.xml │ └── test │ └── java │ └── com │ └── zhu │ └── VideoAdminApplicationTests.java ├── video-framework ├── .gitignore ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── zhu │ │ │ ├── annotation │ │ │ └── AuthCheck.java │ │ │ ├── aop │ │ │ └── AuthInterceptor.java │ │ │ ├── common │ │ │ ├── CommonEntity.java │ │ │ ├── IdRequest.java │ │ │ └── PageRequest.java │ │ │ ├── config │ │ │ ├── CorsConfig.java │ │ │ ├── MessageConfig.java │ │ │ ├── MyBatisPlusConfig.java │ │ │ ├── RabbitMQConfig.java │ │ │ ├── RedisConfiguration.java │ │ │ ├── ScheduleHandler.java │ │ │ ├── TimeHandle.java │ │ │ ├── WebSocket.java │ │ │ └── WebSocketConfig.java │ │ │ ├── constant │ │ │ ├── CommentConstant.java │ │ │ ├── CommonConstant.java │ │ │ ├── FileConstant.java │ │ │ ├── MQConstant.java │ │ │ ├── MessageConstant.java │ │ │ ├── RedisConstant.java │ │ │ └── UserConstant.java │ │ │ ├── customer │ │ │ ├── ESCustomer.java │ │ │ └── MessageCustomer.java │ │ │ ├── datasource │ │ │ ├── DataSource.java │ │ │ ├── DataSourceRegister.java │ │ │ ├── UserDataSource.java │ │ │ └── VideoDataSource.java │ │ │ ├── exception │ │ │ ├── ErrorException.java │ │ │ └── GlobalException.java │ │ │ ├── handler │ │ │ ├── VideoBrowseHandler.java │ │ │ ├── VideoFavourHandler.java │ │ │ ├── VideoHandler.java │ │ │ ├── VideoHandlerRegister.java │ │ │ ├── VideoStarHandler.java │ │ │ └── VideoWorksHandler.java │ │ │ ├── mapper │ │ │ ├── CommentFavourMapper.java │ │ │ ├── CommentMapper.java │ │ │ ├── DanmuMapper.java │ │ │ ├── MessageMapper.java │ │ │ ├── TypeMapper.java │ │ │ ├── UserBrowseMapper.java │ │ │ ├── UserFollowMapper.java │ │ │ ├── UserMapper.java │ │ │ ├── UserRatingMapper.java │ │ │ ├── VideoFavourMapper.java │ │ │ ├── VideoInfoMapper.java │ │ │ └── VideoStarMapper.java │ │ │ ├── model │ │ │ ├── dto │ │ │ │ ├── comment │ │ │ │ │ ├── CommentAddRequest.java │ │ │ │ │ ├── CommentLikesRequest.java │ │ │ │ │ └── CommentReplyRequest.java │ │ │ │ ├── danmu │ │ │ │ │ └── DanmuAddRequest.java │ │ │ │ ├── message │ │ │ │ │ ├── MessageQueryRequest.java │ │ │ │ │ └── MessageUpdateRequest.java │ │ │ │ ├── search │ │ │ │ │ └── SearchRequest.java │ │ │ │ ├── user │ │ │ │ │ ├── UserEditRequest.java │ │ │ │ │ ├── UserFollowFansRequest.java │ │ │ │ │ ├── UserFollowRequest.java │ │ │ │ │ ├── UserInfoRequest.java │ │ │ │ │ ├── UserLoginRequest.java │ │ │ │ │ ├── UserRegisterRequest.java │ │ │ │ │ └── UserVideoRequest.java │ │ │ │ └── video │ │ │ │ │ ├── VideoAddRequest.java │ │ │ │ │ ├── VideoBrowseRequest.java │ │ │ │ │ ├── VideoEsDTO.java │ │ │ │ │ ├── VideoFavourRequest.java │ │ │ │ │ ├── VideoRecommendRequest.java │ │ │ │ │ ├── VideoStarRequest.java │ │ │ │ │ └── VideoTypeRequest.java │ │ │ ├── entity │ │ │ │ ├── Comment.java │ │ │ │ ├── CommentFavour.java │ │ │ │ ├── Danmu.java │ │ │ │ ├── Message.java │ │ │ │ ├── Type.java │ │ │ │ ├── User.java │ │ │ │ ├── UserBrowse.java │ │ │ │ ├── UserFollow.java │ │ │ │ ├── UserRating.java │ │ │ │ ├── VideoFavour.java │ │ │ │ ├── VideoInfo.java │ │ │ │ └── VideoStar.java │ │ │ └── enums │ │ │ │ ├── MessageTypeEnums.java │ │ │ │ ├── SearchTypeEnums.java │ │ │ │ ├── SortTypeEnums.java │ │ │ │ ├── TimeScopeEnum.java │ │ │ │ └── VideoTypeEnums.java │ │ │ ├── recommend │ │ │ ├── core │ │ │ │ ├── CoreMath.java │ │ │ │ ├── ItemCF.java │ │ │ │ ├── UserBasedRecommend.java │ │ │ │ └── UserCF.java │ │ │ └── service │ │ │ │ └── RecommendService.java │ │ │ ├── result │ │ │ ├── RespBean.java │ │ │ └── RespBeanEnum.java │ │ │ ├── service │ │ │ ├── ICommentFavourService.java │ │ │ ├── ICommentService.java │ │ │ ├── IDanmuService.java │ │ │ ├── IMessageService.java │ │ │ ├── ITypeService.java │ │ │ ├── IUserBrowseService.java │ │ │ ├── IUserFollowService.java │ │ │ ├── IUserRatingService.java │ │ │ ├── IUserService.java │ │ │ ├── IVideoFavourService.java │ │ │ ├── IVideoInfoService.java │ │ │ ├── IVideoStarService.java │ │ │ └── impl │ │ │ │ ├── CommentFavourServiceImpl.java │ │ │ │ ├── CommentServiceImpl.java │ │ │ │ ├── DanmuServiceImpl.java │ │ │ │ ├── MessageServiceImpl.java │ │ │ │ ├── TypeServiceImpl.java │ │ │ │ ├── UserBrowseServiceImpl.java │ │ │ │ ├── UserFollowServiceImpl.java │ │ │ │ ├── UserRatingServiceImpl.java │ │ │ │ ├── UserServiceImpl.java │ │ │ │ ├── VideoFavourServiceImpl.java │ │ │ │ ├── VideoInfoServiceImpl.java │ │ │ │ └── VideoStarServiceImpl.java │ │ │ ├── utils │ │ │ ├── AddressUtils.java │ │ │ ├── BeanCopeUtils.java │ │ │ ├── IpUtil.java │ │ │ ├── MessageUtils.java │ │ │ ├── RedisUtils.java │ │ │ ├── VideoCoverUtils.java │ │ │ └── WhisperUtils.java │ │ │ └── vo │ │ │ ├── AuthorInfoVo.java │ │ │ ├── CommentVo.java │ │ │ ├── LoginUserVo.java │ │ │ ├── MessageTypeVo.java │ │ │ ├── MessageVideoVo.java │ │ │ ├── MessageVo.java │ │ │ ├── ReplyVo.java │ │ │ ├── SearchVo.java │ │ │ ├── UserVo.java │ │ │ └── VideoVo.java │ └── resources │ │ └── mapper │ │ ├── CommentFavourMapper.xml │ │ ├── CommentMapper.xml │ │ ├── DanmuMapper.xml │ │ ├── MessageMapper.xml │ │ ├── TypeMapper.xml │ │ ├── UserBrowseMapper.xml │ │ ├── UserFollowMapper.xml │ │ ├── UserMapper.xml │ │ ├── UserRatingMapper.xml │ │ ├── VideoFavourMapper.xml │ │ ├── VideoInfoMapper.xml │ │ └── VideoStarMapper.xml │ └── test │ └── java │ └── com │ └── zhu │ └── VideoFrameworkApplicationTests.java └── video ├── .gitignore ├── pom.xml └── src └── main ├── java └── com │ └── zhu │ ├── VideoApplication.java │ ├── config │ ├── LoginInterceptor.java │ └── WebConfig.java │ ├── controller │ ├── CommentController.java │ ├── DanmuController.java │ ├── MainTest.java │ ├── MessageController.java │ ├── RecommendController.java │ ├── SearchController.java │ ├── TypeController.java │ ├── UserController.java │ ├── UserFollowController.java │ ├── VideoFavourController.java │ ├── VideoInfoController.java │ └── VideoStarController.java │ ├── recommend │ ├── FileDataSource.java │ └── RecommendUtils.java │ ├── spark │ ├── SparkManager.java │ ├── SparkService.java │ └── XingHuoConfig.java │ └── utils │ └── QiNiuUtils.java └── resources ├── application.yml └── data ├── DVideo.data └── video.data /.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 | -------------------------------------------------------------------------------- /img/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tiancheng2002/pig-video/798851820f73f68eacd6e13e3919107d462ab24f/img/.keep -------------------------------------------------------------------------------- /img/image-20240614165450210.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tiancheng2002/pig-video/798851820f73f68eacd6e13e3919107d462ab24f/img/image-20240614165450210.png -------------------------------------------------------------------------------- /img/image-20240614165656746.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tiancheng2002/pig-video/798851820f73f68eacd6e13e3919107d462ab24f/img/image-20240614165656746.png -------------------------------------------------------------------------------- /img/image-20240614165945228.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tiancheng2002/pig-video/798851820f73f68eacd6e13e3919107d462ab24f/img/image-20240614165945228.png -------------------------------------------------------------------------------- /img/image-20240614180043158.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tiancheng2002/pig-video/798851820f73f68eacd6e13e3919107d462ab24f/img/image-20240614180043158.png -------------------------------------------------------------------------------- /img/image-20240614180123585.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tiancheng2002/pig-video/798851820f73f68eacd6e13e3919107d462ab24f/img/image-20240614180123585.png -------------------------------------------------------------------------------- /img/image-20240614180736332.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tiancheng2002/pig-video/798851820f73f68eacd6e13e3919107d462ab24f/img/image-20240614180736332.png -------------------------------------------------------------------------------- /img/image-20240614201845944.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tiancheng2002/pig-video/798851820f73f68eacd6e13e3919107d462ab24f/img/image-20240614201845944.png -------------------------------------------------------------------------------- /img/image-20240614202044813.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tiancheng2002/pig-video/798851820f73f68eacd6e13e3919107d462ab24f/img/image-20240614202044813.png -------------------------------------------------------------------------------- /img/image-20240614202617706.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tiancheng2002/pig-video/798851820f73f68eacd6e13e3919107d462ab24f/img/image-20240614202617706.png -------------------------------------------------------------------------------- /img/image-20240614202810543.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tiancheng2002/pig-video/798851820f73f68eacd6e13e3919107d462ab24f/img/image-20240614202810543.png -------------------------------------------------------------------------------- /img/image-20240614203033979.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tiancheng2002/pig-video/798851820f73f68eacd6e13e3919107d462ab24f/img/image-20240614203033979.png -------------------------------------------------------------------------------- /img/image-20240614203330284.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tiancheng2002/pig-video/798851820f73f68eacd6e13e3919107d462ab24f/img/image-20240614203330284.png -------------------------------------------------------------------------------- /img/image-20240614204047720.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tiancheng2002/pig-video/798851820f73f68eacd6e13e3919107d462ab24f/img/image-20240614204047720.png -------------------------------------------------------------------------------- /img/image-20240614204238429.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tiancheng2002/pig-video/798851820f73f68eacd6e13e3919107d462ab24f/img/image-20240614204238429.png -------------------------------------------------------------------------------- /img/image-20240614204436457.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tiancheng2002/pig-video/798851820f73f68eacd6e13e3919107d462ab24f/img/image-20240614204436457.png -------------------------------------------------------------------------------- /img/image-20240614204633520.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tiancheng2002/pig-video/798851820f73f68eacd6e13e3919107d462ab24f/img/image-20240614204633520.png -------------------------------------------------------------------------------- /img/special1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tiancheng2002/pig-video/798851820f73f68eacd6e13e3919107d462ab24f/img/special1.png -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.zhu 7 | video-backend 8 | 0.0.1 9 | pom 10 | 11 | 12 | video 13 | video-framework 14 | video-admin 15 | 16 | 17 | 18 | UTF-8 19 | 1.8 20 | 21 | 22 | 23 | 24 | 25 | org.springframework.boot 26 | spring-boot-dependencies 27 | 2.7.5 28 | pom 29 | import 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | org.apache.maven.plugins 38 | maven-compiler-plugin 39 | 3.1 40 | 41 | ${java.version} 42 | ${java.version} 43 | ${project.build.sourceEncoding} 44 | 45 | 46 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /tools/Redis-x64-3.0.504.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tiancheng2002/pig-video/798851820f73f68eacd6e13e3919107d462ab24f/tools/Redis-x64-3.0.504.zip -------------------------------------------------------------------------------- /video-admin/.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 | -------------------------------------------------------------------------------- /video-admin/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.zhu 7 | video-backend 8 | 0.0.1 9 | 10 | com.zhu 11 | video-admin 12 | 0.0.1 13 | video-admin 14 | 15 | 16 | 1.8 17 | 18 | 19 | 20 | com.zhu 21 | video-framework 22 | 0.0.1 23 | 24 | 25 | org.springframework.boot 26 | spring-boot-starter-security 27 | 28 | 29 | org.springframework.security 30 | spring-security-test 31 | test 32 | 33 | 34 | com.github.whvcse 35 | easy-captcha 36 | 1.6.2 37 | 38 | 39 | io.jsonwebtoken 40 | jjwt 41 | 0.9.1 42 | 43 | 44 | org.springframework.boot 45 | spring-boot-starter-test 46 | test 47 | 48 | 49 | org.projectlombok 50 | lombok 51 | 52 | 53 | org.springframework.boot 54 | spring-boot-starter-aop 55 | 56 | 57 | 58 | 59 | 60 | 61 | org.springframework.boot 62 | spring-boot-maven-plugin 63 | 64 | 65 | 66 | 67 | 68 | -------------------------------------------------------------------------------- /video-admin/src/main/java/com/zhu/VideoAdminApplication.java: -------------------------------------------------------------------------------- 1 | package com.zhu; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class VideoAdminApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(VideoAdminApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /video-admin/src/main/java/com/zhu/annotate/Dict.java: -------------------------------------------------------------------------------- 1 | package com.zhu.annotate; 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.FIELD) 9 | @Retention(RetentionPolicy.RUNTIME) 10 | public @interface Dict { 11 | 12 | //表示对应的字典编码 13 | String code(); 14 | 15 | //表示转义后的文本 16 | String dicText() default ""; 17 | 18 | } 19 | -------------------------------------------------------------------------------- /video-admin/src/main/java/com/zhu/config/ControllerResponseAdvice.java: -------------------------------------------------------------------------------- 1 | package com.zhu.config; 2 | 3 | import com.alibaba.fastjson.JSONObject; 4 | import com.zhu.result.RespBean; 5 | import org.springframework.core.MethodParameter; 6 | import org.springframework.http.MediaType; 7 | import org.springframework.http.converter.HttpMessageConverter; 8 | import org.springframework.http.server.ServerHttpRequest; 9 | import org.springframework.http.server.ServerHttpResponse; 10 | import org.springframework.web.bind.annotation.RestControllerAdvice; 11 | import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice; 12 | 13 | @RestControllerAdvice(basePackages = {"com.zhu.controller"}) 14 | public class ControllerResponseAdvice implements ResponseBodyAdvice { 15 | 16 | 17 | @Override 18 | public boolean supports(MethodParameter returnType, Class> converterType) { 19 | return true; 20 | } 21 | 22 | @Override 23 | public Object beforeBodyWrite(Object body, MethodParameter returnType, MediaType selectedContentType, Class> selectedConverterType, ServerHttpRequest request, ServerHttpResponse response) { 24 | if(body instanceof String){ 25 | return JSONObject.toJSONString(RespBean.success(body)); 26 | } 27 | return RespBean.success(body); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /video-admin/src/main/java/com/zhu/config/ReloadMessageConfig.java: -------------------------------------------------------------------------------- 1 | package com.zhu.config; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.context.support.ReloadableResourceBundleMessageSource; 6 | 7 | @Configuration 8 | public class ReloadMessageConfig { 9 | @Bean 10 | public ReloadableResourceBundleMessageSource messageSource() { 11 | ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource(); 12 | // 将提示文件指定为中文的提示 13 | messageSource.setBasename("classpath:org/springframework/security/messages_zh_CN"); 14 | return messageSource; 15 | } 16 | } -------------------------------------------------------------------------------- /video-admin/src/main/java/com/zhu/constant/DataConstant.java: -------------------------------------------------------------------------------- 1 | package com.zhu.constant; 2 | 3 | public class DataConstant { 4 | 5 | public static String DICT_TEXT_SUFFIX = "Text"; 6 | 7 | //登录成功 8 | public static Integer SUCCESS_STATUS = 0; 9 | 10 | //登录失败 11 | public static Integer FAIL_STATUS = 1; 12 | 13 | //登录成功信息 14 | public static String SUCCESS_TEXT = "登录成功"; 15 | 16 | } 17 | -------------------------------------------------------------------------------- /video-admin/src/main/java/com/zhu/controller/AuthController.java: -------------------------------------------------------------------------------- 1 | package com.zhu.controller; 2 | 3 | import com.wf.captcha.ArithmeticCaptcha; 4 | import com.zhu.model.vo.CaptchaVo; 5 | import com.zhu.utils.JwtUtils; 6 | import com.zhu.utils.RedisUtils; 7 | import com.zhu.utils.UUIDUtils; 8 | import lombok.extern.slf4j.Slf4j; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.beans.factory.annotation.Qualifier; 11 | import org.springframework.data.redis.core.RedisTemplate; 12 | import org.springframework.security.access.prepost.PreAuthorize; 13 | import org.springframework.security.authentication.InternalAuthenticationServiceException; 14 | import org.springframework.web.bind.annotation.RequestMapping; 15 | import org.springframework.web.bind.annotation.RequestParam; 16 | import org.springframework.web.bind.annotation.RestController; 17 | 18 | import javax.annotation.Resource; 19 | import javax.servlet.http.HttpServletRequest; 20 | import javax.servlet.http.HttpServletResponse; 21 | import java.util.concurrent.TimeUnit; 22 | 23 | @RestController 24 | @Slf4j 25 | public class AuthController { 26 | 27 | @Resource 28 | private RedisUtils redisUtils; 29 | 30 | @Resource 31 | private JwtUtils jwtUtils; 32 | 33 | @RequestMapping("/captcha") 34 | public CaptchaVo captcha(@RequestParam(value = "key", required = false) String key, HttpServletRequest request, HttpServletResponse response) { 35 | if (key != null) { 36 | redisUtils.remove("captcha:" + key); 37 | } 38 | //获取验证码 39 | response.setContentType("image/jpg"); 40 | response.setHeader("Pargam", "No-cache"); 41 | response.setHeader("cache-Control", "no-cache"); 42 | response.setDateHeader("Expires", 0); 43 | //生成验证码,将验证码放入redis当中 44 | ArithmeticCaptcha captch = new ArithmeticCaptcha(110, 38, 3); 45 | //随机生成一个UUID,然后将UUID和验证码进行绑定存储到Redis当中,并把UUID返回到前端中 46 | String uuid = UUIDUtils.getUUID(); 47 | // String ip = IpUtil.getIpAddr(request); 48 | redisUtils.set("captcha:" + uuid, captch.text(), 300); 49 | // captch.out(response.getOutputStream()); 50 | String base64 = captch.toBase64(); 51 | return new CaptchaVo(base64, uuid); 52 | } 53 | 54 | // @RequestMapping("/login") 55 | // public String doLogin(HttpServletResponse response){ 56 | // String jwt = jwtUtils.generateToken("abc"); 57 | // response.setHeader("jwt",jwt); 58 | // return jwt; 59 | // } 60 | 61 | @PreAuthorize("hasAuthority('sys:user:list')") 62 | @RequestMapping("/test01") 63 | public String test01() { 64 | return "test01"; 65 | } 66 | 67 | @PreAuthorize("hasAuthority('sys:user:app')") 68 | @RequestMapping("/test02") 69 | public String test02() { 70 | return "test02"; 71 | } 72 | 73 | @RequestMapping("/test") 74 | public void test() { 75 | throw new InternalAuthenticationServiceException("错误"); 76 | } 77 | 78 | } 79 | -------------------------------------------------------------------------------- /video-admin/src/main/java/com/zhu/controller/CommentController.java: -------------------------------------------------------------------------------- 1 | package com.zhu.controller; 2 | 3 | import com.zhu.model.entity.Comment; 4 | import com.zhu.result.RespBean; 5 | import com.zhu.service.ICommentService; 6 | import org.springframework.web.bind.annotation.GetMapping; 7 | import org.springframework.web.bind.annotation.RequestMapping; 8 | import org.springframework.web.bind.annotation.RestController; 9 | 10 | import javax.annotation.Resource; 11 | import java.util.List; 12 | 13 | @RestController 14 | @RequestMapping("/admin/comment") 15 | public class CommentController { 16 | 17 | @Resource 18 | private ICommentService commentService; 19 | 20 | @GetMapping("/all") 21 | public List getComment(){ 22 | //获取全部评论 23 | return null; 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /video-admin/src/main/java/com/zhu/controller/DictDataController.java: -------------------------------------------------------------------------------- 1 | package com.zhu.controller; 2 | 3 | import org.springframework.stereotype.Controller; 4 | import org.springframework.web.bind.annotation.RequestMapping; 5 | 6 | /** 7 | *

8 | * 前端控制器 9 | *

10 | * 11 | * @author xiaozhu 12 | * @since 2022-08-28 13 | */ 14 | @Controller 15 | @RequestMapping("/admin/dictData") 16 | public class DictDataController { 17 | 18 | } 19 | -------------------------------------------------------------------------------- /video-admin/src/main/java/com/zhu/controller/MenuController.java: -------------------------------------------------------------------------------- 1 | package com.zhu.controller; 2 | 3 | import com.zhu.model.entity.Menu; 4 | import com.zhu.model.vo.MenuVo; 5 | import com.zhu.query.MenuQuery; 6 | import com.zhu.service.IMenuService; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.web.bind.annotation.*; 9 | 10 | import java.util.List; 11 | 12 | /** 13 | *

14 | * 前端控制器 15 | *

16 | * 17 | * @author xiaozhu 18 | * @since 2022-09-02 19 | */ 20 | @RestController 21 | @RequestMapping("/admin/menu") 22 | public class MenuController { 23 | 24 | @Autowired 25 | private IMenuService menuService; 26 | 27 | /* 28 | 返回所有的菜单信息 29 | */ 30 | // @RequestMapping("/all") 31 | // public List getMenu(@RequestParam(value = "menuId",required = false,defaultValue = "0") Integer menuId){ 32 | // return menuService.getMenu(menuId); 33 | // } 34 | 35 | @RequestMapping("/all") 36 | public List getMenu(MenuQuery menuQuery){ 37 | List menus = menuService.getMenu(menuQuery); 38 | return menus; 39 | } 40 | 41 | /* 42 | 根据id查找对应菜单信息 43 | */ 44 | @RequestMapping("/detail") 45 | public Menu getMenuDetail(@RequestParam("menuId") Integer menuId){ 46 | return menuService.getById(menuId); 47 | } 48 | 49 | /* 50 | 添加或修改对应菜单信息 51 | */ 52 | @PostMapping("/action") 53 | public String actionMenu(@RequestBody Menu menu){ 54 | if(menu.getMenuId()!=null){ 55 | menuService.updateById(menu); 56 | }else{ 57 | menuService.save(menu); 58 | } 59 | return "ok"; 60 | } 61 | 62 | /* 63 | 删除对应菜单信息 64 | */ 65 | @PostMapping("/del") 66 | public String delMenu(@RequestBody List idList){ 67 | menuService.removeTree(idList); 68 | return "ok"; 69 | } 70 | 71 | } 72 | -------------------------------------------------------------------------------- /video-admin/src/main/java/com/zhu/controller/TypeController.java: -------------------------------------------------------------------------------- 1 | package com.zhu.controller; 2 | 3 | import org.springframework.web.bind.annotation.RequestMapping; 4 | import org.springframework.web.bind.annotation.RestController; 5 | 6 | @RestController 7 | @RequestMapping("/admin/type") 8 | public class TypeController { 9 | } 10 | -------------------------------------------------------------------------------- /video-admin/src/main/java/com/zhu/controller/VideoController.java: -------------------------------------------------------------------------------- 1 | package com.zhu.controller; 2 | 3 | import org.springframework.web.bind.annotation.RequestMapping; 4 | import org.springframework.web.bind.annotation.RestController; 5 | 6 | @RestController 7 | @RequestMapping("/admin/video") 8 | public class VideoController { 9 | } 10 | -------------------------------------------------------------------------------- /video-admin/src/main/java/com/zhu/exception/CaptchaException.java: -------------------------------------------------------------------------------- 1 | package com.zhu.exception; 2 | 3 | import org.springframework.security.core.AuthenticationException; 4 | 5 | public class CaptchaException extends AuthenticationException { 6 | 7 | public CaptchaException(String msg) { 8 | super(msg); 9 | } 10 | 11 | } 12 | -------------------------------------------------------------------------------- /video-admin/src/main/java/com/zhu/exception/GlobalException.java: -------------------------------------------------------------------------------- 1 | package com.zhu.exception; 2 | 3 | import com.zhu.result.RespBean; 4 | import com.zhu.result.RespBeanEnum; 5 | import org.springframework.web.bind.annotation.ExceptionHandler; 6 | import org.springframework.web.bind.annotation.RestControllerAdvice; 7 | 8 | import java.sql.SQLIntegrityConstraintViolationException; 9 | 10 | @RestControllerAdvice 11 | public class GlobalException { 12 | 13 | @ExceptionHandler({SQLIntegrityConstraintViolationException.class}) 14 | public RespBean uniqueData(SQLIntegrityConstraintViolationException e){ 15 | if(e.getMessage().contains("Duplicate entry")){ 16 | String[] result = e.getMessage().split(" "); 17 | return RespBean.error(RespBeanEnum.ERROR,result[2]+"已存在"); 18 | } 19 | return RespBean.error(RespBeanEnum.ERROR); 20 | } 21 | 22 | @ExceptionHandler({ErrorException.class}) 23 | public RespBean error(ErrorException e){ 24 | return RespBean.error(e.getRespBeanEnum()); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /video-admin/src/main/java/com/zhu/exception/JwtException.java: -------------------------------------------------------------------------------- 1 | package com.zhu.exception; 2 | 3 | import com.zhu.result.RespBeanEnum; 4 | import org.springframework.security.core.AuthenticationException; 5 | 6 | public class JwtException extends AuthenticationException { 7 | 8 | RespBeanEnum respBeanEnum; 9 | 10 | public JwtException(String msg) { 11 | super(msg); 12 | } 13 | 14 | public JwtException(String msg, RespBeanEnum respBeanEnum) { 15 | super(msg); 16 | this.respBeanEnum = respBeanEnum; 17 | } 18 | 19 | public RespBeanEnum getRespBeanEnum() { 20 | return respBeanEnum; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /video-admin/src/main/java/com/zhu/exception/SecurityException.java: -------------------------------------------------------------------------------- 1 | package com.zhu.exception; 2 | 3 | import com.zhu.result.RespBeanEnum; 4 | import org.springframework.security.core.AuthenticationException; 5 | 6 | public class SecurityException extends AuthenticationException { 7 | 8 | RespBeanEnum respBeanEnum; 9 | 10 | public SecurityException(String msg) { 11 | super(msg); 12 | } 13 | 14 | public SecurityException(RespBeanEnum respBeanEnum) { 15 | super(respBeanEnum.getMsg()); 16 | this.respBeanEnum = respBeanEnum; 17 | } 18 | 19 | public SecurityException(String msg, RespBeanEnum respBeanEnum) { 20 | super(msg); 21 | this.respBeanEnum = respBeanEnum; 22 | } 23 | 24 | public RespBeanEnum getRespBeanEnum() { 25 | return respBeanEnum; 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /video-admin/src/main/java/com/zhu/listener/AuthenticationFailureListener.java: -------------------------------------------------------------------------------- 1 | package com.zhu.listener; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.springframework.context.ApplicationListener; 5 | import org.springframework.security.authentication.event.AuthenticationFailureBadCredentialsEvent; 6 | import org.springframework.stereotype.Component; 7 | 8 | @Slf4j 9 | @Component 10 | public class AuthenticationFailureListener implements ApplicationListener { 11 | 12 | @Override 13 | public void onApplicationEvent(AuthenticationFailureBadCredentialsEvent event) { 14 | log.error("用户登录失败"); 15 | System.out.println(event); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /video-admin/src/main/java/com/zhu/mapper/DictDataMapper.java: -------------------------------------------------------------------------------- 1 | package com.zhu.mapper; 2 | 3 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 4 | import com.zhu.model.entity.DictData; 5 | import org.apache.ibatis.annotations.Mapper; 6 | import org.springframework.stereotype.Repository; 7 | 8 | /** 9 | *

10 | * Mapper 接口 11 | *

12 | * 13 | * @author xiaozhu 14 | * @since 2022-08-28 15 | */ 16 | @Mapper 17 | @Repository 18 | public interface DictDataMapper extends BaseMapper { 19 | 20 | } 21 | -------------------------------------------------------------------------------- /video-admin/src/main/java/com/zhu/mapper/DictMapper.java: -------------------------------------------------------------------------------- 1 | package com.zhu.mapper; 2 | 3 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 4 | import com.zhu.model.entity.Dict; 5 | import com.zhu.model.vo.DictTypeVo; 6 | import com.zhu.model.vo.DictVo; 7 | import org.apache.ibatis.annotations.Mapper; 8 | import org.apache.ibatis.annotations.Param; 9 | import org.springframework.stereotype.Repository; 10 | 11 | import java.util.List; 12 | 13 | /** 14 | *

15 | * Mapper 接口 16 | *

17 | * 18 | * @author xiaozhu 19 | * @since 2022-08-28 20 | */ 21 | @Mapper 22 | @Repository 23 | public interface DictMapper extends BaseMapper { 24 | 25 | List getDictDetail(); 26 | 27 | List getDictByCode(@Param("dictCode") String dictCode); 28 | 29 | List getDict(Dict dict); 30 | 31 | } 32 | -------------------------------------------------------------------------------- /video-admin/src/main/java/com/zhu/mapper/MenuMapper.java: -------------------------------------------------------------------------------- 1 | package com.zhu.mapper; 2 | 3 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 4 | import com.zhu.model.entity.Menu; 5 | import com.zhu.model.vo.MenuVo; 6 | import org.apache.ibatis.annotations.Mapper; 7 | import org.apache.ibatis.annotations.Param; 8 | import org.springframework.stereotype.Repository; 9 | 10 | import java.util.List; 11 | 12 | /** 13 | *

14 | * Mapper 接口 15 | *

16 | * 17 | * @author xiaozhu 18 | * @since 2022-09-02 19 | */ 20 | @Mapper 21 | @Repository 22 | public interface MenuMapper extends BaseMapper { 23 | 24 | List getMenu(@Param("menuId") Long menuId, @Param("menuName") String menuName, @Param("myStatus") Integer status); 25 | 26 | } 27 | -------------------------------------------------------------------------------- /video-admin/src/main/java/com/zhu/mapper/UserMapper.java: -------------------------------------------------------------------------------- 1 | package com.zhu.mapper; 2 | 3 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 4 | import com.zhu.query.UserQuery; 5 | import com.zhu.model.entity.User; 6 | import org.apache.ibatis.annotations.Mapper; 7 | import org.springframework.stereotype.Repository; 8 | 9 | import java.util.List; 10 | 11 | /** 12 | *

13 | * Mapper 接口 14 | *

15 | * 16 | * @author xiaozhu 17 | * @since 2022-08-29 18 | */ 19 | @Mapper 20 | @Repository 21 | public interface UserMapper extends BaseMapper { 22 | 23 | List userSearch(UserQuery userQuery); 24 | 25 | } 26 | -------------------------------------------------------------------------------- /video-admin/src/main/java/com/zhu/model/entity/Base.java: -------------------------------------------------------------------------------- 1 | package com.zhu.model.entity; 2 | 3 | import com.baomidou.mybatisplus.annotation.FieldFill; 4 | import com.baomidou.mybatisplus.annotation.TableField; 5 | import lombok.AllArgsConstructor; 6 | import lombok.Data; 7 | import lombok.NoArgsConstructor; 8 | 9 | import java.util.Date; 10 | 11 | @Data 12 | @AllArgsConstructor 13 | @NoArgsConstructor 14 | public class Base { 15 | 16 | @TableField(fill = FieldFill.INSERT) 17 | private Date createTime; 18 | 19 | @TableField(fill = FieldFill.INSERT_UPDATE) 20 | private Date updateTime; 21 | 22 | private String remark; 23 | 24 | } 25 | -------------------------------------------------------------------------------- /video-admin/src/main/java/com/zhu/model/entity/Dict.java: -------------------------------------------------------------------------------- 1 | package com.zhu.model.entity; 2 | 3 | import com.baomidou.mybatisplus.annotation.IdType; 4 | import com.baomidou.mybatisplus.annotation.TableId; 5 | import com.baomidou.mybatisplus.annotation.TableName; 6 | import lombok.AllArgsConstructor; 7 | import lombok.Data; 8 | import lombok.NoArgsConstructor; 9 | 10 | import java.io.Serializable; 11 | 12 | /** 13 | *

14 | * 15 | *

16 | * 17 | * @author xiaozhu 18 | * @since 2022-08-28 19 | */ 20 | @TableName("sys_dict") 21 | @Data 22 | @AllArgsConstructor 23 | @NoArgsConstructor 24 | public class Dict extends Base implements Serializable { 25 | 26 | private static final long serialVersionUID = 1L; 27 | 28 | @TableId(value = "id", type = IdType.AUTO) 29 | private Long id; 30 | 31 | private String dictCode; 32 | 33 | private String dictName; 34 | 35 | private Integer status; 36 | 37 | } 38 | -------------------------------------------------------------------------------- /video-admin/src/main/java/com/zhu/model/entity/DictData.java: -------------------------------------------------------------------------------- 1 | package com.zhu.model.entity; 2 | 3 | import com.baomidou.mybatisplus.annotation.IdType; 4 | import com.baomidou.mybatisplus.annotation.TableId; 5 | import com.baomidou.mybatisplus.annotation.TableName; 6 | import lombok.AllArgsConstructor; 7 | import lombok.Data; 8 | import lombok.NoArgsConstructor; 9 | 10 | import java.io.Serializable; 11 | 12 | /** 13 | *

14 | * 15 | *

16 | * 17 | * @author xiaozhu 18 | * @since 2022-08-28 19 | */ 20 | @TableName("sys_dict_data") 21 | @Data 22 | @AllArgsConstructor 23 | @NoArgsConstructor 24 | public class DictData extends Base implements Serializable { 25 | 26 | private static final long serialVersionUID = 1L; 27 | 28 | @TableId(value = "id", type = IdType.AUTO) 29 | private Long id; 30 | 31 | private Long dictId; 32 | 33 | private String label; 34 | 35 | private String value; 36 | 37 | } 38 | -------------------------------------------------------------------------------- /video-admin/src/main/java/com/zhu/model/entity/Menu.java: -------------------------------------------------------------------------------- 1 | package com.zhu.model.entity; 2 | 3 | import com.baomidou.mybatisplus.annotation.IdType; 4 | import com.baomidou.mybatisplus.annotation.TableField; 5 | import com.baomidou.mybatisplus.annotation.TableId; 6 | import com.baomidou.mybatisplus.annotation.TableName; 7 | import lombok.AllArgsConstructor; 8 | import lombok.Data; 9 | import lombok.NoArgsConstructor; 10 | import lombok.ToString; 11 | 12 | import java.io.Serializable; 13 | 14 | /** 15 | *

16 | * 17 | *

18 | * 19 | * @author xiaozhu 20 | * @since 2022-09-02 21 | */ 22 | @TableName("sys_menu") 23 | @Data 24 | @AllArgsConstructor 25 | @NoArgsConstructor 26 | @ToString 27 | public class Menu extends Base implements Serializable { 28 | 29 | private static final long serialVersionUID = 1L; 30 | 31 | @TableId(value = "menu_id", type = IdType.AUTO) 32 | private Long menuId; 33 | 34 | private String name; 35 | 36 | private Long parentId; 37 | 38 | private String path; 39 | 40 | private String component; 41 | 42 | private String perms; 43 | 44 | private String icon; 45 | 46 | private Integer type; 47 | 48 | private Boolean isExternal; 49 | 50 | @TableField(value = "orderNum") 51 | private Integer orderNum; 52 | 53 | private Integer status; 54 | 55 | } 56 | -------------------------------------------------------------------------------- /video-admin/src/main/java/com/zhu/model/entity/Role.java: -------------------------------------------------------------------------------- 1 | package com.zhu.model.entity; 2 | 3 | import com.baomidou.mybatisplus.annotation.IdType; 4 | import com.baomidou.mybatisplus.annotation.TableId; 5 | import com.baomidou.mybatisplus.annotation.TableName; 6 | import lombok.AllArgsConstructor; 7 | import lombok.Data; 8 | import lombok.NoArgsConstructor; 9 | 10 | import java.io.Serializable; 11 | 12 | /** 13 | *

14 | * 15 | *

16 | * 17 | * @author xiaozhu 18 | * @since 2022-09-03 19 | */ 20 | @TableName("sys_role") 21 | @Data 22 | @AllArgsConstructor 23 | @NoArgsConstructor 24 | public class Role extends Base implements Serializable { 25 | 26 | private static final long serialVersionUID = 1L; 27 | 28 | @TableId(value = "roleId",type = IdType.AUTO) 29 | private Long roleId; 30 | 31 | private String name; 32 | 33 | private String authority; 34 | 35 | private Integer status; 36 | 37 | } 38 | -------------------------------------------------------------------------------- /video-admin/src/main/java/com/zhu/model/entity/User.java: -------------------------------------------------------------------------------- 1 | package com.zhu.model.entity; 2 | 3 | import com.baomidou.mybatisplus.annotation.IdType; 4 | import com.baomidou.mybatisplus.annotation.TableField; 5 | import com.baomidou.mybatisplus.annotation.TableId; 6 | import com.baomidou.mybatisplus.annotation.TableName; 7 | import com.zhu.annotate.Dict; 8 | import lombok.AllArgsConstructor; 9 | import lombok.Data; 10 | import lombok.NoArgsConstructor; 11 | import lombok.ToString; 12 | 13 | import java.io.Serializable; 14 | 15 | /** 16 | *

17 | * 18 | *

19 | * 20 | * @author xiaozhu 21 | * @since 2022-08-22 22 | */ 23 | @TableName("sys_user") 24 | @Data 25 | @AllArgsConstructor 26 | @NoArgsConstructor 27 | @ToString 28 | public class User extends Base implements Serializable { 29 | 30 | private static final long serialVersionUID = 1L; 31 | 32 | @TableId(value = "uid", type = IdType.AUTO) 33 | private Integer uid; 34 | 35 | private String username; 36 | 37 | private String password; 38 | 39 | private String head; 40 | 41 | @Dict(code = "user_gender") 42 | private Integer sex; 43 | 44 | private String phone; 45 | 46 | private String email; 47 | 48 | @Dict(code = "user_status") 49 | private Integer status; 50 | 51 | @TableField(value = "roleId") 52 | private Long roleId; 53 | 54 | } 55 | -------------------------------------------------------------------------------- /video-admin/src/main/java/com/zhu/model/vo/CaptchaVo.java: -------------------------------------------------------------------------------- 1 | package com.zhu.model.vo; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | @Data 8 | @AllArgsConstructor 9 | @NoArgsConstructor 10 | public class CaptchaVo { 11 | 12 | private String img; 13 | 14 | private String key; 15 | 16 | } 17 | -------------------------------------------------------------------------------- /video-admin/src/main/java/com/zhu/model/vo/DictTypeVo.java: -------------------------------------------------------------------------------- 1 | package com.zhu.model.vo; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | import lombok.ToString; 7 | 8 | @Data 9 | @AllArgsConstructor 10 | @NoArgsConstructor 11 | @ToString 12 | public class DictTypeVo { 13 | 14 | private String label; 15 | 16 | private String value; 17 | 18 | } 19 | -------------------------------------------------------------------------------- /video-admin/src/main/java/com/zhu/model/vo/DictVo.java: -------------------------------------------------------------------------------- 1 | package com.zhu.model.vo; 2 | 3 | import com.zhu.model.entity.DictData; 4 | import lombok.AllArgsConstructor; 5 | import lombok.Data; 6 | import lombok.NoArgsConstructor; 7 | import lombok.ToString; 8 | 9 | import java.util.List; 10 | 11 | @Data 12 | @AllArgsConstructor 13 | @NoArgsConstructor 14 | @ToString 15 | public class DictVo { 16 | 17 | private String code; 18 | 19 | private List dictDataList; 20 | 21 | } 22 | -------------------------------------------------------------------------------- /video-admin/src/main/java/com/zhu/model/vo/MenuVo.java: -------------------------------------------------------------------------------- 1 | package com.zhu.model.vo; 2 | 3 | import com.zhu.model.entity.Menu; 4 | import lombok.AllArgsConstructor; 5 | import lombok.Data; 6 | import lombok.NoArgsConstructor; 7 | import lombok.ToString; 8 | 9 | import java.util.List; 10 | 11 | @Data 12 | @AllArgsConstructor 13 | @NoArgsConstructor 14 | @ToString 15 | public class MenuVo extends Menu { 16 | 17 | private List children; 18 | 19 | } 20 | -------------------------------------------------------------------------------- /video-admin/src/main/java/com/zhu/model/vo/PasswordVo.java: -------------------------------------------------------------------------------- 1 | package com.zhu.model.vo; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | @Data 8 | @AllArgsConstructor 9 | @NoArgsConstructor 10 | public class PasswordVo { 11 | 12 | private String username; 13 | 14 | private String oldPassword; 15 | 16 | private String newPassword; 17 | 18 | } 19 | -------------------------------------------------------------------------------- /video-admin/src/main/java/com/zhu/query/MenuQuery.java: -------------------------------------------------------------------------------- 1 | package com.zhu.query; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | 6 | @Data 7 | @AllArgsConstructor 8 | public class MenuQuery { 9 | 10 | private Long menuId; 11 | 12 | private String menuName; 13 | 14 | private Integer status; 15 | 16 | public MenuQuery(){ 17 | this.menuId = 0L; 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /video-admin/src/main/java/com/zhu/query/UserQuery.java: -------------------------------------------------------------------------------- 1 | package com.zhu.query; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | @Data 8 | @AllArgsConstructor 9 | @NoArgsConstructor 10 | public class UserQuery { 11 | 12 | private String username; 13 | 14 | private String phone; 15 | 16 | private Integer sex; 17 | 18 | } -------------------------------------------------------------------------------- /video-admin/src/main/java/com/zhu/security/CaptchaFilter.java: -------------------------------------------------------------------------------- 1 | package com.zhu.security; 2 | 3 | import com.zhu.exception.SecurityException; 4 | import com.zhu.result.RespBeanEnum; 5 | import com.zhu.utils.IpUtil; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.beans.factory.annotation.Qualifier; 8 | import org.springframework.data.redis.core.RedisTemplate; 9 | import org.springframework.stereotype.Component; 10 | import org.springframework.web.filter.OncePerRequestFilter; 11 | 12 | import javax.servlet.FilterChain; 13 | import javax.servlet.ServletException; 14 | import javax.servlet.http.HttpServletRequest; 15 | import javax.servlet.http.HttpServletResponse; 16 | import java.io.IOException; 17 | 18 | @Component 19 | public class CaptchaFilter extends OncePerRequestFilter { 20 | 21 | @Autowired 22 | @Qualifier("myRedisTemplate") 23 | private RedisTemplate redisTemplate; 24 | 25 | @Autowired 26 | private LoginFailureHandler loginFailureHandler; 27 | 28 | @Override 29 | protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { 30 | String url = request.getRequestURI(); 31 | 32 | try { 33 | if(url.equals("/login")&&request.getMethod().equals("POST")){ 34 | 35 | ValidatedCaptcha(request); 36 | } 37 | }catch (SecurityException e){ 38 | loginFailureHandler.onAuthenticationFailure(request,response,e); 39 | return; 40 | } 41 | 42 | filterChain.doFilter(request,response); 43 | } 44 | 45 | private void ValidatedCaptcha(HttpServletRequest request) { 46 | String code = request.getParameter("captcha"); 47 | String key = request.getParameter("key"); 48 | String ip = IpUtil.getIpAddr(request); 49 | 50 | // if(StringUtils.isBlank(code)){ 51 | // throw new CaptchaException("验证码错误"); 52 | // } 53 | 54 | //从Redis缓存当中获取对应的验证码 55 | String captcha = (String) redisTemplate.opsForValue().get("captcha:" + key); 56 | if(captcha==null){ 57 | throw new SecurityException(RespBeanEnum.Captcha_OVER); 58 | } 59 | 60 | if(!code.equals(captcha)){ 61 | throw new SecurityException(RespBeanEnum.Captcha_ERROR); 62 | } 63 | 64 | redisTemplate.delete("captcha:"+ip); 65 | 66 | } 67 | 68 | } 69 | -------------------------------------------------------------------------------- /video-admin/src/main/java/com/zhu/security/JwtAccessDeniedHandler.java: -------------------------------------------------------------------------------- 1 | package com.zhu.security; 2 | 3 | import com.alibaba.fastjson.JSON; 4 | import com.zhu.result.RespBean; 5 | import com.zhu.result.RespBeanEnum; 6 | import org.springframework.security.access.AccessDeniedException; 7 | import org.springframework.security.web.access.AccessDeniedHandler; 8 | import org.springframework.stereotype.Component; 9 | 10 | import javax.servlet.ServletException; 11 | import javax.servlet.ServletOutputStream; 12 | import javax.servlet.http.HttpServletRequest; 13 | import javax.servlet.http.HttpServletResponse; 14 | import java.io.IOException; 15 | 16 | //用来解决认证过的用户访问去权限资源的异常 17 | @Component 18 | public class JwtAccessDeniedHandler implements AccessDeniedHandler { 19 | 20 | @Override 21 | public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException accessDeniedException) throws IOException, ServletException { 22 | 23 | response.setContentType("application/json;charset=UTF-8"); 24 | response.setStatus(HttpServletResponse.SC_FORBIDDEN); 25 | // RespBean respBean = new RespBean(); 26 | // respBean.setCode(HttpServletResponse.SC_FORBIDDEN); 27 | // respBean.setMsg("权限不足"); 28 | ServletOutputStream outputStream = response.getOutputStream(); 29 | 30 | outputStream.write(JSON.toJSONString(RespBean.error(RespBeanEnum.FORBIDDEN)).getBytes("UTF-8")); 31 | outputStream.flush(); 32 | outputStream.close(); 33 | 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /video-admin/src/main/java/com/zhu/security/JwtAuthenticationEntryPoint.java: -------------------------------------------------------------------------------- 1 | package com.zhu.security; 2 | 3 | import com.alibaba.fastjson.JSON; 4 | import com.zhu.result.RespBean; 5 | import com.zhu.result.RespBeanEnum; 6 | import org.springframework.security.core.AuthenticationException; 7 | import org.springframework.security.web.AuthenticationEntryPoint; 8 | import org.springframework.stereotype.Component; 9 | 10 | import javax.servlet.ServletException; 11 | import javax.servlet.ServletOutputStream; 12 | import javax.servlet.http.HttpServletRequest; 13 | import javax.servlet.http.HttpServletResponse; 14 | import java.io.IOException; 15 | 16 | //用来解决匿名用户访问无权限资源时的异常 17 | @Component 18 | public class JwtAuthenticationEntryPoint implements AuthenticationEntryPoint { 19 | 20 | @Override 21 | public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException, ServletException { 22 | 23 | response.setContentType("application/json;charset=UTF-8"); 24 | response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); 25 | ServletOutputStream outputStream = response.getOutputStream(); 26 | // RespBean respBean = new RespBean(); 27 | // respBean.setCode(HttpServletResponse.SC_UNAUTHORIZED); 28 | // respBean.setMsg("请先登录"); 29 | 30 | // outputStream.write(JSON.toJSONString(RespBean.error(RespBeanEnum.ERROR,"请先登录")).getBytes("UTF-8")); 31 | outputStream.write(JSON.toJSONString(RespBean.error(RespBeanEnum.UNAUTHORIZED,"请先登录")).getBytes("UTF-8")); 32 | outputStream.flush(); 33 | outputStream.close(); 34 | 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /video-admin/src/main/java/com/zhu/security/JwtLogoutSuccessHandler.java: -------------------------------------------------------------------------------- 1 | package com.zhu.security; 2 | 3 | import com.alibaba.fastjson.JSON; 4 | import com.zhu.result.RespBean; 5 | import com.zhu.utils.JwtUtils; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.security.core.Authentication; 8 | import org.springframework.security.web.authentication.logout.LogoutSuccessHandler; 9 | import org.springframework.security.web.authentication.logout.SecurityContextLogoutHandler; 10 | import org.springframework.stereotype.Component; 11 | 12 | import javax.servlet.ServletException; 13 | import javax.servlet.ServletOutputStream; 14 | import javax.servlet.http.HttpServletRequest; 15 | import javax.servlet.http.HttpServletResponse; 16 | import java.io.IOException; 17 | 18 | @Component 19 | public class JwtLogoutSuccessHandler implements LogoutSuccessHandler { 20 | 21 | @Autowired 22 | private JwtUtils jwtUtils; 23 | 24 | @Override 25 | public void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException { 26 | 27 | if(authentication!=null){ 28 | new SecurityContextLogoutHandler().logout(request,response,authentication); 29 | } 30 | 31 | response.setContentType("application/json;charset=UTF-8"); 32 | ServletOutputStream outputStream = response.getOutputStream(); 33 | 34 | //因为前端获取不到我们自定义的header,所以需要设置前端想要获取的header 35 | // response.setHeader("Access-Control-Expose-Headers",jwtUtils.getHeader()); 36 | // response.setHeader(jwtUtils.getHeader(),""); 37 | // System.out.println(jwt); 38 | 39 | outputStream.write(JSON.toJSONString(RespBean.success("退出成功")).getBytes("UTF-8")); 40 | outputStream.flush(); 41 | outputStream.close(); 42 | 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /video-admin/src/main/java/com/zhu/security/LoginFailureHandler.java: -------------------------------------------------------------------------------- 1 | package com.zhu.security; 2 | 3 | import com.zhu.exception.SecurityException; 4 | import com.alibaba.fastjson.JSON; 5 | import com.zhu.result.RespBean; 6 | import com.zhu.result.RespBeanEnum; 7 | import org.springframework.security.authentication.BadCredentialsException; 8 | import org.springframework.security.core.AuthenticationException; 9 | import org.springframework.security.core.userdetails.UsernameNotFoundException; 10 | import org.springframework.security.web.authentication.AuthenticationFailureHandler; 11 | import org.springframework.stereotype.Component; 12 | 13 | import javax.servlet.ServletException; 14 | import javax.servlet.ServletOutputStream; 15 | import javax.servlet.http.HttpServletRequest; 16 | import javax.servlet.http.HttpServletResponse; 17 | import java.io.IOException; 18 | 19 | @Component 20 | public class LoginFailureHandler implements AuthenticationFailureHandler { 21 | 22 | @Override 23 | public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) throws IOException, ServletException { 24 | response.setContentType("application/json;charset=UTF-8"); 25 | ServletOutputStream outputStream = response.getOutputStream(); 26 | 27 | RespBean result; 28 | if (exception instanceof BadCredentialsException || exception instanceof UsernameNotFoundException) { 29 | result = RespBean.error(RespBeanEnum.USERNAME_PASSWORD, exception.getMessage()); 30 | } else { 31 | SecurityException securityException = (SecurityException) exception; 32 | result = RespBean.error(securityException.getRespBeanEnum(), securityException.getMessage()); 33 | } 34 | 35 | outputStream.write(JSON.toJSONString(result).getBytes("UTF-8")); 36 | outputStream.flush(); 37 | outputStream.close(); 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /video-admin/src/main/java/com/zhu/security/LoginSuccessHandler.java: -------------------------------------------------------------------------------- 1 | package com.zhu.security; 2 | 3 | import com.alibaba.fastjson.JSON; 4 | import com.zhu.model.entity.User; 5 | import com.zhu.result.RespBean; 6 | import com.zhu.service.IUserService; 7 | import com.zhu.utils.JwtUtils; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.beans.factory.annotation.Qualifier; 10 | import org.springframework.data.redis.core.RedisTemplate; 11 | import org.springframework.security.core.Authentication; 12 | import org.springframework.security.web.authentication.AuthenticationSuccessHandler; 13 | import org.springframework.stereotype.Component; 14 | 15 | import javax.servlet.ServletException; 16 | import javax.servlet.ServletOutputStream; 17 | import javax.servlet.http.HttpServletRequest; 18 | import javax.servlet.http.HttpServletResponse; 19 | import java.io.IOException; 20 | 21 | @Component 22 | public class LoginSuccessHandler implements AuthenticationSuccessHandler { 23 | 24 | @Autowired 25 | private JwtUtils jwtUtils; 26 | 27 | @Autowired 28 | @Qualifier("myRedisTemplate") 29 | private RedisTemplate redisTemplate; 30 | 31 | @Autowired 32 | private IUserService userService; 33 | 34 | @Override 35 | public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException { 36 | response.setContentType("application/json;charset=UTF-8"); 37 | ServletOutputStream outputStream = response.getOutputStream(); 38 | 39 | //登录成功之后会将生成的jwt字符串返回出去,并存储到Redis当中 40 | String jwt = jwtUtils.generateToken(authentication.getName()); 41 | redisTemplate.opsForValue().set("token:" + authentication.getName(), jwt); 42 | //因为前端获取不到我们自定义的header,所以需要设置前端想要获取的header 43 | response.setHeader("Access-Control-Expose-Headers", jwtUtils.getHeader()); 44 | response.setHeader(jwtUtils.getHeader(), jwt); 45 | // System.out.println(jwt); 46 | 47 | //获取到对应用户的信息并返回给前端 48 | User user = userService.userByName(authentication.getName()); 49 | 50 | outputStream.write(JSON.toJSONString(RespBean.success(user)).getBytes("UTF-8")); 51 | outputStream.flush(); 52 | outputStream.close(); 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /video-admin/src/main/java/com/zhu/security/UserDetail.java: -------------------------------------------------------------------------------- 1 | package com.zhu.security; 2 | 3 | import org.springframework.security.core.GrantedAuthority; 4 | import org.springframework.security.core.userdetails.UserDetails; 5 | import org.springframework.util.Assert; 6 | 7 | import java.util.Collection; 8 | 9 | public class UserDetail implements UserDetails { 10 | 11 | private Integer userId; 12 | 13 | private String password; 14 | 15 | private final String username; 16 | 17 | private final Collection authorities; 18 | 19 | private final boolean accountNonExpired; 20 | 21 | private final boolean accountNonLocked; 22 | 23 | private final boolean credentialsNonExpired; 24 | 25 | private final boolean enabled; 26 | 27 | public UserDetail(Integer userId, String username, String password, Collection authorities) { 28 | this(userId, username, password, true, true, true, true, authorities); 29 | } 30 | 31 | public UserDetail(Integer userId, String username, String password, boolean enabled, boolean accountNonExpired, boolean credentialsNonExpired, boolean accountNonLocked, Collection authorities) { 32 | Assert.isTrue(username != null && !"".equals(username) && password != null, "Cannot pass null or empty values to constructor"); 33 | this.userId = userId; 34 | this.username = username; 35 | this.password = password; 36 | this.enabled = enabled; 37 | this.accountNonExpired = accountNonExpired; 38 | this.credentialsNonExpired = credentialsNonExpired; 39 | this.accountNonLocked = accountNonLocked; 40 | this.authorities = authorities; 41 | } 42 | 43 | @Override 44 | public Collection getAuthorities() { 45 | return this.authorities; 46 | } 47 | 48 | @Override 49 | public String getPassword() { 50 | return this.password; 51 | } 52 | 53 | @Override 54 | public String getUsername() { 55 | return this.username; 56 | } 57 | 58 | @Override 59 | public boolean isAccountNonExpired() { 60 | return this.accountNonExpired; 61 | } 62 | 63 | @Override 64 | public boolean isAccountNonLocked() { 65 | return this.accountNonLocked; 66 | } 67 | 68 | @Override 69 | public boolean isCredentialsNonExpired() { 70 | return this.credentialsNonExpired; 71 | } 72 | 73 | @Override 74 | public boolean isEnabled() { 75 | return this.enabled; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /video-admin/src/main/java/com/zhu/security/UserDetailServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.zhu.security; 2 | 3 | import com.alibaba.fastjson.JSONArray; 4 | import com.zhu.model.entity.User; 5 | import com.zhu.result.RespBeanEnum; 6 | import com.zhu.service.IUserService; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.beans.factory.annotation.Qualifier; 9 | import org.springframework.data.redis.core.RedisTemplate; 10 | import org.springframework.security.core.authority.AuthorityUtils; 11 | import org.springframework.security.core.userdetails.UserDetails; 12 | import org.springframework.security.core.userdetails.UserDetailsService; 13 | import org.springframework.security.core.userdetails.UsernameNotFoundException; 14 | import org.springframework.stereotype.Service; 15 | 16 | @Service 17 | public class UserDetailServiceImpl implements UserDetailsService { 18 | 19 | @Autowired 20 | private IUserService userService; 21 | 22 | @Autowired 23 | @Qualifier("myRedisTemplate") 24 | private RedisTemplate redisTemplate; 25 | 26 | @Override 27 | public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { 28 | User user = userService.userByName(username); 29 | if(user==null){ 30 | throw new UsernameNotFoundException(RespBeanEnum.USERNAME_PASSWORD.getMsg()); 31 | } 32 | System.out.println(user); 33 | return new UserDetail(user.getUid(),user.getUsername(),user.getPassword(), AuthorityUtils.commaSeparatedStringToAuthorityList(JSONArray.parseArray("[\"sys:manage\",\"sys:user:list\",\"sys:user:add\",\"sys:user:edit\",\"sys:user:del\",\"sys:user:query\",\"sys:role:list\",\"sys:role:add\",\"sys:role:edit\",\"sys:role:del\",\"sys:role:query\",\"sys:post:list\",\"sys:post:add\",\"sys:post:edit\",\"sys:post:del\",\"sys:post:query\",\"sys:dept:list\",\"sys:dept:add\",\"sys:dept:edit\",\"sys:dept:del\",\"sys:dept:query\",\"sys:dict:list\",\"sys:dict:add\",\"sys:dict:edit\",\"sys:dict:del\",\"sys:dict:query\",\"sys:dict:cache\",\"sys:menu:list\",\"sys:menu:add\",\"sys:menu:edit\",\"sys:menu:del\",\"sys:menu:query\",\"sys:monitor\",\"sys:server:list\",\"sys:app:setting\"]", String.class).toString().replace("[", "").replace("]", ""))); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /video-admin/src/main/java/com/zhu/service/IDictDataService.java: -------------------------------------------------------------------------------- 1 | package com.zhu.service; 2 | 3 | import com.baomidou.mybatisplus.extension.service.IService; 4 | import com.zhu.model.entity.DictData; 5 | 6 | /** 7 | *

8 | * 服务类 9 | *

10 | * 11 | * @author xiaozhu 12 | * @since 2022-08-28 13 | */ 14 | public interface IDictDataService extends IService { 15 | 16 | } 17 | -------------------------------------------------------------------------------- /video-admin/src/main/java/com/zhu/service/IDictService.java: -------------------------------------------------------------------------------- 1 | package com.zhu.service; 2 | 3 | import com.baomidou.mybatisplus.extension.service.IService; 4 | import com.zhu.model.entity.Dict; 5 | import com.zhu.model.vo.DictTypeVo; 6 | import com.zhu.model.vo.DictVo; 7 | 8 | import java.util.List; 9 | 10 | /** 11 | *

12 | * 服务类 13 | *

14 | * 15 | * @author xiaozhu 16 | * @since 2022-08-28 17 | */ 18 | public interface IDictService extends IService { 19 | 20 | List getDictDetail(); 21 | 22 | List getDictByCode(String dictCode); 23 | 24 | List getDict(Dict dict); 25 | } 26 | -------------------------------------------------------------------------------- /video-admin/src/main/java/com/zhu/service/IMenuService.java: -------------------------------------------------------------------------------- 1 | package com.zhu.service; 2 | 3 | import com.baomidou.mybatisplus.extension.service.IService; 4 | import com.zhu.model.entity.Menu; 5 | import com.zhu.model.vo.MenuVo; 6 | import com.zhu.query.MenuQuery; 7 | 8 | import java.util.List; 9 | 10 | /** 11 | *

12 | * 服务类 13 | *

14 | * 15 | * @author xiaozhu 16 | * @since 2022-09-02 17 | */ 18 | public interface IMenuService extends IService { 19 | 20 | List getMenu(MenuQuery menuQuery); 21 | 22 | void removeTree(List idList); 23 | } 24 | -------------------------------------------------------------------------------- /video-admin/src/main/java/com/zhu/service/IUserService.java: -------------------------------------------------------------------------------- 1 | package com.zhu.service; 2 | 3 | import com.baomidou.mybatisplus.extension.service.IService; 4 | import com.zhu.query.UserQuery; 5 | import com.zhu.model.entity.User; 6 | 7 | import java.util.List; 8 | 9 | /** 10 | *

11 | * 服务类 12 | *

13 | * 14 | * @author xiaozhu 15 | * @since 2022-08-29 16 | */ 17 | public interface IUserService extends IService { 18 | 19 | List userSearch(UserQuery userQuery); 20 | 21 | User userByName(String username); 22 | 23 | } 24 | -------------------------------------------------------------------------------- /video-admin/src/main/java/com/zhu/service/impl/DictDataServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.zhu.service.impl; 2 | 3 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 4 | import com.zhu.mapper.DictDataMapper; 5 | import com.zhu.model.entity.DictData; 6 | import com.zhu.service.IDictDataService; 7 | import org.springframework.stereotype.Service; 8 | 9 | /** 10 | *

11 | * 服务实现类 12 | *

13 | * 14 | * @author xiaozhu 15 | * @since 2022-08-28 16 | */ 17 | @Service 18 | public class DictDataServiceImpl extends ServiceImpl implements IDictDataService { 19 | 20 | } 21 | -------------------------------------------------------------------------------- /video-admin/src/main/java/com/zhu/service/impl/DictServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.zhu.service.impl; 2 | 3 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 4 | import com.zhu.mapper.DictMapper; 5 | import com.zhu.model.entity.Dict; 6 | import com.zhu.model.vo.DictTypeVo; 7 | import com.zhu.model.vo.DictVo; 8 | import com.zhu.service.IDictService; 9 | import org.springframework.stereotype.Service; 10 | 11 | import java.util.List; 12 | 13 | /** 14 | *

15 | * 服务实现类 16 | *

17 | * 18 | * @author xiaozhu 19 | * @since 2022-08-28 20 | */ 21 | @Service 22 | public class DictServiceImpl extends ServiceImpl implements IDictService { 23 | 24 | @Override 25 | public List getDictDetail() { 26 | return baseMapper.getDictDetail(); 27 | } 28 | 29 | @Override 30 | public List getDictByCode(String dictCode) { 31 | return baseMapper.getDictByCode(dictCode); 32 | } 33 | 34 | @Override 35 | public List getDict(Dict dict) { 36 | return baseMapper.getDict(dict); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /video-admin/src/main/java/com/zhu/service/impl/MenuServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.zhu.service.impl; 2 | 3 | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; 4 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 5 | import com.zhu.mapper.MenuMapper; 6 | import com.zhu.model.entity.Menu; 7 | import com.zhu.model.vo.MenuVo; 8 | import com.zhu.query.MenuQuery; 9 | import com.zhu.service.IMenuService; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.stereotype.Service; 12 | 13 | import java.util.List; 14 | import java.util.stream.Collectors; 15 | 16 | /** 17 | *

18 | * 服务实现类 19 | *

20 | * 21 | * @author xiaozhu 22 | * @since 2022-09-02 23 | */ 24 | @Service 25 | public class MenuServiceImpl extends ServiceImpl implements IMenuService { 26 | 27 | @Autowired 28 | private MenuMapper menuMapper; 29 | 30 | @Override 31 | public List getMenu(MenuQuery menuQuery) { 32 | List menuVoList = menuMapper.getMenu(menuQuery.getMenuId(),menuQuery.getMenuName(),menuQuery.getStatus()); 33 | List menuVos = menuVoList; 34 | for (MenuVo menuVo:menuVoList){ 35 | menuVos = menuVos.stream().filter(v->v.getParentId()!=menuVo.getMenuId()).collect(Collectors.toList()); 36 | } 37 | return menuVos; 38 | } 39 | 40 | @Override 41 | public void removeTree(List idList) { 42 | //获取该id下的所有子数据的id 43 | selectChildren(idList.get(0),idList); 44 | System.out.println(idList); 45 | //将所有的子数据以及本身都删除 46 | // baseMapper.deleteBatchIds(idList); 47 | } 48 | 49 | public void selectChildren(Long did,List idList){ 50 | //根据pid获取到下等级的子数据 51 | List deptList = baseMapper.selectList(new QueryWrapper().eq("parent_id", did).select("menu_id")); 52 | //遍历子数据,将id添加到集合当中,并且递归的获取 53 | deptList.forEach(item->{ 54 | idList.add(item.getMenuId()); 55 | selectChildren(item.getMenuId(),idList); 56 | }); 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /video-admin/src/main/java/com/zhu/service/impl/UserServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.zhu.service.impl; 2 | 3 | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; 4 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 5 | import com.zhu.mapper.UserMapper; 6 | import com.zhu.query.UserQuery; 7 | import com.zhu.model.entity.User; 8 | import com.zhu.service.IUserService; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.stereotype.Service; 11 | 12 | import java.util.List; 13 | 14 | /** 15 | *

16 | * 服务实现类 17 | *

18 | * 19 | * @author xiaozhu 20 | * @since 2022-08-29 21 | */ 22 | @Service 23 | public class UserServiceImpl extends ServiceImpl implements IUserService { 24 | 25 | @Autowired 26 | private UserMapper userMapper; 27 | 28 | @Override 29 | public List userSearch(UserQuery userQuery) { 30 | return userMapper.userSearch(userQuery); 31 | } 32 | 33 | @Override 34 | public User userByName(String username) { 35 | return getOne(new QueryWrapper().eq("username", username)); 36 | } 37 | 38 | } 39 | 40 | -------------------------------------------------------------------------------- /video-admin/src/main/java/com/zhu/utils/JwtUtils.java: -------------------------------------------------------------------------------- 1 | package com.zhu.utils; 2 | 3 | import io.jsonwebtoken.Claims; 4 | import io.jsonwebtoken.Jwts; 5 | import io.jsonwebtoken.SignatureAlgorithm; 6 | import lombok.Data; 7 | import org.springframework.boot.context.properties.ConfigurationProperties; 8 | import org.springframework.stereotype.Component; 9 | 10 | import java.util.Date; 11 | 12 | @Data 13 | @Component 14 | @ConfigurationProperties(prefix = "pig.jwt") 15 | public class JwtUtils { 16 | 17 | private long expire; 18 | 19 | private String secret; 20 | 21 | private String header; 22 | 23 | //生成jwt 24 | public String generateToken(String username){ 25 | 26 | Date nowDate = new Date(); 27 | Date expireDate = new Date(nowDate.getTime() + 1000 * expire); 28 | 29 | return Jwts.builder() 30 | .setHeaderParam("typ","JWT") 31 | .setSubject(username) 32 | .setIssuedAt(nowDate) 33 | .setExpiration(expireDate) 34 | .signWith(SignatureAlgorithm.HS512,secret) 35 | .compact(); 36 | } 37 | 38 | //解析jwt 39 | public Claims claimsToken(String jwt){ 40 | try { 41 | return Jwts.parser() 42 | .setSigningKey(secret) 43 | .parseClaimsJws(jwt) 44 | .getBody(); 45 | }catch (Exception e){ 46 | return null; 47 | } 48 | } 49 | 50 | 51 | //判断jwt是否过期 52 | public boolean isTokenExpire(Claims claims){ 53 | return claims.getExpiration().before(new Date()); 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /video-admin/src/main/java/com/zhu/utils/ObjConvertUtils.java: -------------------------------------------------------------------------------- 1 | package com.zhu.utils; 2 | 3 | import java.lang.reflect.Field; 4 | import java.util.ArrayList; 5 | import java.util.Arrays; 6 | import java.util.List; 7 | 8 | @SuppressWarnings("ALL") 9 | public class ObjConvertUtils { 10 | 11 | /** 12 | * 获取类的所有属性,包括父类 13 | * 14 | * @param object 15 | * @return 16 | */ 17 | public static Field[] getAllFields(Object object) { 18 | Class clazz = object.getClass(); 19 | List fieldList = new ArrayList<>(); 20 | while (clazz != null) { 21 | fieldList.addAll(new ArrayList<>(Arrays.asList(clazz.getDeclaredFields()))); 22 | clazz = clazz.getSuperclass(); 23 | } 24 | Field[] fields = new Field[fieldList.size()]; 25 | fieldList.toArray(fields); 26 | return fields; 27 | } 28 | 29 | public static boolean isEmpty(Object object) { 30 | if (object == null) { 31 | return (true); 32 | } 33 | if ("".equals(object)) { 34 | return (true); 35 | } 36 | if ("null".equals(object)) { 37 | return (true); 38 | } 39 | return (false); 40 | } 41 | } -------------------------------------------------------------------------------- /video-admin/src/main/java/com/zhu/utils/UUIDUtils.java: -------------------------------------------------------------------------------- 1 | package com.zhu.utils; 2 | 3 | import java.util.UUID; 4 | 5 | public class UUIDUtils { 6 | 7 | public static String getUUID() { 8 | return UUID.randomUUID().toString().replace("-", ""); 9 | } 10 | 11 | 12 | } 13 | -------------------------------------------------------------------------------- /video-admin/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8082 3 | 4 | mybatis-plus: 5 | mapper-locations: classpath:/mapper/*.xml 6 | type-aliases-package: com.zhu.model.entity 7 | # configuration: 8 | # log-impl: org.apache.ibatis.logging.stdout.StdOutImpl 9 | spring: 10 | datasource: 11 | driver-class-name: com.mysql.cj.jdbc.Driver 12 | url: jdbc:mysql://localhost:3306/video?useUnicode=utf-8&useSSL=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai 13 | username: root 14 | password: 12345678 15 | redis: 16 | host: 127.0.0.1 17 | port: 6379 18 | jedis: 19 | pool: 20 | max-active: 8 21 | max-wait: -1 22 | max-idle: 8 23 | min-idle: 0 24 | timeout: 5000 25 | jackson: 26 | date-format: yyyy-MM-dd HH:mm:ss 27 | time-zone: GMT+8 28 | mvc: 29 | pathmatch: 30 | matching-strategy: ant_path_matcher 31 | # security: 32 | # user: 33 | # password: 123 34 | pig: 35 | jwt: 36 | header: Authorization 37 | expire: 604800 38 | secret: zhusjd1d48534d5d5d463d1d5d8tge95 39 | -------------------------------------------------------------------------------- /video-admin/src/main/resources/mapper/DictDataMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /video-admin/src/main/resources/mapper/DictMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 16 | 17 | 20 | 21 | 24 | 25 | 26 | 27 | 29 | 30 | 31 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /video-admin/src/main/resources/mapper/MenuMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /video-admin/src/main/resources/mapper/UserMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /video-admin/src/test/java/com/zhu/VideoAdminApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.zhu; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class VideoAdminApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /video-framework/.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 | -------------------------------------------------------------------------------- /video-framework/src/main/java/com/zhu/annotation/AuthCheck.java: -------------------------------------------------------------------------------- 1 | package com.zhu.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 | /** 9 | * 权限校验 10 | * 11 | */ 12 | @Target(ElementType.METHOD) 13 | @Retention(RetentionPolicy.RUNTIME) 14 | public @interface AuthCheck { 15 | 16 | //必须要登录后才能进行接口调用 17 | 18 | } -------------------------------------------------------------------------------- /video-framework/src/main/java/com/zhu/aop/AuthInterceptor.java: -------------------------------------------------------------------------------- 1 | package com.zhu.aop; 2 | 3 | import com.zhu.annotation.AuthCheck; 4 | import com.zhu.constant.UserConstant; 5 | import com.zhu.exception.ErrorException; 6 | import com.zhu.result.RespBeanEnum; 7 | import com.zhu.service.IUserService; 8 | import com.zhu.vo.LoginUserVo; 9 | import org.aspectj.lang.ProceedingJoinPoint; 10 | import org.aspectj.lang.annotation.Around; 11 | import org.aspectj.lang.annotation.Aspect; 12 | import org.springframework.stereotype.Component; 13 | import org.springframework.web.context.request.RequestAttributes; 14 | import org.springframework.web.context.request.RequestContextHolder; 15 | import org.springframework.web.context.request.ServletRequestAttributes; 16 | 17 | import javax.annotation.Resource; 18 | import javax.servlet.http.HttpServletRequest; 19 | 20 | /** 21 | * 权限校验 AOP 22 | * 23 | */ 24 | @Aspect 25 | @Component 26 | public class AuthInterceptor { 27 | 28 | @Resource 29 | private IUserService userService; 30 | 31 | /** 32 | * 执行拦截 33 | * 34 | * @param joinPoint 35 | * @param authCheck 36 | * @return 37 | */ 38 | @Around("@annotation(authCheck)") 39 | public Object doInterceptor(ProceedingJoinPoint joinPoint, AuthCheck authCheck) throws Throwable { 40 | RequestAttributes requestAttributes = RequestContextHolder.currentRequestAttributes(); 41 | HttpServletRequest request = ((ServletRequestAttributes) requestAttributes).getRequest(); 42 | // 当前登录用户 43 | LoginUserVo loginUser = userService.getLoginUser(request); 44 | // 必须有该权限才通过 45 | if(loginUser==null){ 46 | throw new ErrorException(RespBeanEnum.USER_NO_AUTH); 47 | } 48 | //如果账号为封禁状态也不允许访问 49 | if(loginUser.getUserRole()== UserConstant.BAN_ROLE){ 50 | throw new ErrorException(RespBeanEnum.FORBIDDEN); 51 | } 52 | // 通过权限校验,放行 53 | return joinPoint.proceed(); 54 | } 55 | } 56 | 57 | -------------------------------------------------------------------------------- /video-framework/src/main/java/com/zhu/common/CommonEntity.java: -------------------------------------------------------------------------------- 1 | package com.zhu.common; 2 | 3 | import com.baomidou.mybatisplus.annotation.FieldFill; 4 | import com.baomidou.mybatisplus.annotation.TableField; 5 | import lombok.Data; 6 | 7 | import java.io.Serializable; 8 | import java.util.Date; 9 | 10 | @Data 11 | public class CommonEntity implements Serializable { 12 | 13 | @TableField(fill = FieldFill.INSERT) 14 | private Date createTime; 15 | 16 | @TableField(fill = FieldFill.INSERT_UPDATE) 17 | private Date updateTime; 18 | 19 | } 20 | -------------------------------------------------------------------------------- /video-framework/src/main/java/com/zhu/common/IdRequest.java: -------------------------------------------------------------------------------- 1 | package com.zhu.common; 2 | 3 | import lombok.Data; 4 | 5 | import java.io.Serializable; 6 | 7 | @Data 8 | public class IdRequest implements Serializable { 9 | 10 | private Long id; 11 | 12 | } 13 | -------------------------------------------------------------------------------- /video-framework/src/main/java/com/zhu/common/PageRequest.java: -------------------------------------------------------------------------------- 1 | package com.zhu.common; 2 | 3 | import com.zhu.constant.CommonConstant; 4 | import lombok.Data; 5 | 6 | /** 7 | * 分页公共请求 8 | * 9 | */ 10 | @Data 11 | public class PageRequest { 12 | 13 | /** 14 | * 当前页号 15 | */ 16 | private long current = 1; 17 | 18 | /** 19 | * 页面大小 20 | */ 21 | private long pageSize = 10; 22 | 23 | /** 24 | * 排序字段 25 | */ 26 | private String sortField; 27 | 28 | /** 29 | * 排序顺序(默认升序) 30 | */ 31 | private String sortOrder = CommonConstant.SORT_ORDER_ASC; 32 | } 33 | -------------------------------------------------------------------------------- /video-framework/src/main/java/com/zhu/config/CorsConfig.java: -------------------------------------------------------------------------------- 1 | package com.zhu.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 | import org.springframework.web.servlet.config.annotation.CorsRegistry; 9 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; 10 | 11 | @Configuration 12 | public class CorsConfig implements WebMvcConfigurer { 13 | 14 | @Bean 15 | public CorsFilter corsFilter() { 16 | final UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); 17 | final CorsConfiguration corsConfiguration = new CorsConfiguration(); 18 | corsConfiguration.setAllowCredentials(true); 19 | corsConfiguration.addAllowedHeader("*"); 20 | corsConfiguration.addAllowedOriginPattern("*"); 21 | corsConfiguration.addAllowedMethod("*"); 22 | source.registerCorsConfiguration("/**", corsConfiguration); 23 | return new CorsFilter(source); 24 | } 25 | 26 | @Override 27 | public void addCorsMappings(CorsRegistry registry) { 28 | registry.addMapping("/**") 29 | .allowedOriginPatterns("*") 30 | .allowedMethods("GET","POST","PUT","DELETE","HEAD","OPTIONS") 31 | .allowCredentials(true) 32 | .maxAge(3600) 33 | .allowedHeaders("*"); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /video-framework/src/main/java/com/zhu/config/MessageConfig.java: -------------------------------------------------------------------------------- 1 | package com.zhu.config; 2 | 3 | import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter; 4 | import org.springframework.amqp.support.converter.MessageConverter; 5 | import org.springframework.context.annotation.Bean; 6 | import org.springframework.context.annotation.Configuration; 7 | 8 | @Configuration 9 | public class MessageConfig { 10 | 11 | @Bean 12 | public MessageConverter jsonMessageConverter(){ 13 | return new Jackson2JsonMessageConverter(); 14 | } 15 | 16 | } -------------------------------------------------------------------------------- /video-framework/src/main/java/com/zhu/config/MyBatisPlusConfig.java: -------------------------------------------------------------------------------- 1 | package com.zhu.config; 2 | 3 | import com.baomidou.mybatisplus.annotation.DbType; 4 | import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor; 5 | import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor; 6 | import org.mybatis.spring.annotation.MapperScan; 7 | import org.springframework.context.annotation.Bean; 8 | import org.springframework.context.annotation.Configuration; 9 | 10 | /** 11 | * MyBatis Plus 配置 12 | * 13 | */ 14 | @Configuration 15 | @MapperScan("com.zhu.mapper") 16 | public class MyBatisPlusConfig { 17 | 18 | /** 19 | * 拦截器配置 20 | * 21 | * @return 22 | */ 23 | @Bean 24 | public MybatisPlusInterceptor mybatisPlusInterceptor() { 25 | MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor(); 26 | // 分页插件 27 | interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL)); 28 | return interceptor; 29 | } 30 | } -------------------------------------------------------------------------------- /video-framework/src/main/java/com/zhu/config/RabbitMQConfig.java: -------------------------------------------------------------------------------- 1 | package com.zhu.config; 2 | 3 | import com.zhu.constant.MQConstant; 4 | import org.springframework.amqp.core.*; 5 | import org.springframework.context.annotation.Bean; 6 | import org.springframework.context.annotation.Configuration; 7 | 8 | @Configuration 9 | public class RabbitMQConfig { 10 | 11 | @Bean 12 | public TopicExchange videoTopic(){ 13 | return new TopicExchange(MQConstant.VIDEO_TOPIC); 14 | } 15 | 16 | @Bean 17 | public Queue messageQueue(){ 18 | return new Queue(MQConstant.MESSAGE_QUEUE); 19 | } 20 | 21 | @Bean 22 | public Queue elasticSearchQueue(){ 23 | return new Queue(MQConstant.ES_QUEUE); 24 | } 25 | 26 | @Bean 27 | public Binding DLBinding(){ 28 | return BindingBuilder.bind(messageQueue()).to(videoTopic()).with("video.message.#"); 29 | } 30 | 31 | @Bean 32 | public Binding ESBinding(){ 33 | return BindingBuilder.bind(elasticSearchQueue()).to(videoTopic()).with("video.elasticSearch.#"); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /video-framework/src/main/java/com/zhu/config/RedisConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.zhu.config; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.data.redis.connection.RedisConnectionFactory; 6 | import org.springframework.data.redis.core.RedisTemplate; 7 | import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer; 8 | import org.springframework.data.redis.serializer.StringRedisSerializer; 9 | 10 | //Redis配置类 11 | @Configuration 12 | public class RedisConfiguration { 13 | 14 | //配置Redis的字符串序列化,默认的为jdk本身的序列化,存储时会乱码 15 | @Bean("myRedisTemplate") 16 | @SuppressWarnings("all") 17 | public RedisTemplate redisTemplate(RedisConnectionFactory factory){ 18 | RedisTemplate template = new RedisTemplate<>(); 19 | 20 | //key序列化 21 | template.setKeySerializer(new StringRedisSerializer()); 22 | //value序列化 23 | template.setValueSerializer(new GenericJackson2JsonRedisSerializer()); 24 | //hash的key序列化 25 | template.setHashKeySerializer(new StringRedisSerializer()); 26 | //hash的value序列化 27 | template.setHashValueSerializer(new GenericJackson2JsonRedisSerializer()); 28 | 29 | template.setConnectionFactory(factory); 30 | return template; 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /video-framework/src/main/java/com/zhu/config/ScheduleHandler.java: -------------------------------------------------------------------------------- 1 | package com.zhu.config; 2 | 3 | import com.zhu.constant.RedisConstant; 4 | import com.zhu.model.entity.VideoInfo; 5 | import com.zhu.service.IVideoInfoService; 6 | import com.zhu.utils.RedisUtils; 7 | import org.springframework.context.annotation.Configuration; 8 | import org.springframework.scheduling.annotation.EnableScheduling; 9 | import org.springframework.scheduling.annotation.Scheduled; 10 | 11 | import javax.annotation.Resource; 12 | import java.util.ArrayList; 13 | import java.util.Iterator; 14 | import java.util.List; 15 | import java.util.Map; 16 | 17 | @Configuration 18 | @EnableScheduling 19 | public class ScheduleHandler { 20 | 21 | @Resource 22 | private RedisUtils redisUtils; 23 | 24 | @Resource 25 | private IVideoInfoService videoInfoService; 26 | 27 | @Scheduled(cron = "0 0/1 * * * ?") 28 | private void updatePlayNum(){ 29 | //每一分钟更新一次浏览量 30 | Map playNums = redisUtils.hmget(RedisConstant.VideoPlayNumKey); 31 | Iterator> iterator =playNums.entrySet().iterator(); 32 | List videoInfos = new ArrayList<>(); 33 | while (iterator.hasNext()) { 34 | Map.Entry item = iterator.next(); 35 | VideoInfo videoInfo = new VideoInfo(); 36 | videoInfo.setVideoId(Long.parseLong((String) item.getKey())); 37 | videoInfo.setPlayNum(Long.parseLong(String.valueOf(item.getValue()))); 38 | videoInfos.add(videoInfo); 39 | } 40 | videoInfoService.updateBatchById(videoInfos); 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /video-framework/src/main/java/com/zhu/config/TimeHandle.java: -------------------------------------------------------------------------------- 1 | package com.zhu.config; 2 | 3 | import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler; 4 | import org.apache.ibatis.reflection.MetaObject; 5 | import org.springframework.stereotype.Component; 6 | 7 | import java.util.Date; 8 | 9 | /** 10 | * Mybatis-Plus自动填充时间 11 | */ 12 | @Component 13 | public class TimeHandle implements MetaObjectHandler { 14 | 15 | @Override 16 | public void insertFill(MetaObject metaObject) { 17 | this.strictInsertFill(metaObject, "createTime", Date.class, new Date()); 18 | this.strictInsertFill(metaObject, "updateTime", Date.class, new Date()); 19 | this.strictInsertFill(metaObject, "browseTime", Date.class, new Date()); 20 | } 21 | 22 | @Override 23 | public void updateFill(MetaObject metaObject) { 24 | this.strictInsertFill(metaObject, "updateTime", Date.class, new Date()); 25 | this.strictInsertFill(metaObject, "browseTime", Date.class, new Date()); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /video-framework/src/main/java/com/zhu/config/WebSocketConfig.java: -------------------------------------------------------------------------------- 1 | package com.zhu.config; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.web.socket.server.standard.ServerEndpointExporter; 6 | 7 | @Configuration 8 | public class WebSocketConfig { 9 | /** 10 | * 注入ServerEndpointExporter, 11 | * 这个bean会自动注册使用了@ServerEndpoint注解声明的Websocket endpoint 12 | */ 13 | @Bean 14 | public ServerEndpointExporter serverEndpointExporter() { 15 | return new ServerEndpointExporter(); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /video-framework/src/main/java/com/zhu/constant/CommentConstant.java: -------------------------------------------------------------------------------- 1 | package com.zhu.constant; 2 | 3 | public interface CommentConstant { 4 | 5 | /** 6 | * AI小助手ID 7 | */ 8 | Long AIUserCommentID = 111111L; 9 | 10 | /** 11 | * 一级评论parentId 12 | */ 13 | Long headParentId = 0L; 14 | 15 | } 16 | -------------------------------------------------------------------------------- /video-framework/src/main/java/com/zhu/constant/CommonConstant.java: -------------------------------------------------------------------------------- 1 | package com.zhu.constant; 2 | 3 | /** 4 | * 排序常量 5 | * 6 | */ 7 | public interface CommonConstant { 8 | 9 | /** 10 | * 升序 11 | */ 12 | String SORT_ORDER_ASC = "ascend"; 13 | 14 | /** 15 | * 降序 16 | */ 17 | String SORT_ORDER_DESC = " descend"; 18 | 19 | /** 20 | * 只获取作者信息 21 | */ 22 | boolean ONLY_AUTHOR_INFO = true; 23 | 24 | /** 25 | * 获取用户信息以及登录用户点赞、收藏信息 26 | */ 27 | boolean NOT_ONLY_AUTHOR = false; 28 | 29 | } 30 | -------------------------------------------------------------------------------- /video-framework/src/main/java/com/zhu/constant/FileConstant.java: -------------------------------------------------------------------------------- 1 | package com.zhu.constant; 2 | 3 | public interface FileConstant { 4 | 5 | /** 6 | * 文件上传地址 7 | */ 8 | String ImageUrl = "https://image.xiaozhu02.top/video/"; 9 | 10 | /** 11 | * 视频上传文件地址前缀 12 | */ 13 | String FILE_VIDEO = "video"; 14 | 15 | /** 16 | * 图片上传文件地址前缀 17 | */ 18 | String FILE_PICTURE = "picture"; 19 | 20 | } 21 | -------------------------------------------------------------------------------- /video-framework/src/main/java/com/zhu/constant/MQConstant.java: -------------------------------------------------------------------------------- 1 | package com.zhu.constant; 2 | 3 | public interface MQConstant { 4 | 5 | //视频项目总的交换机 6 | String VIDEO_TOPIC = "videoTopic"; 7 | 8 | //消息推动队列 9 | String MESSAGE_QUEUE = "video.message"; 10 | 11 | //ElasticSearch搜索引擎消息队列 12 | String ES_QUEUE = "video.elasticSearch"; 13 | 14 | } 15 | -------------------------------------------------------------------------------- /video-framework/src/main/java/com/zhu/constant/MessageConstant.java: -------------------------------------------------------------------------------- 1 | package com.zhu.constant; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | public interface MessageConstant { 7 | 8 | String MessageKey = "message_unRead"; 9 | 10 | //点赞消息 11 | Integer MESSAGE_FAVOUR = 1; 12 | 13 | //收藏消息 14 | Integer MESSAGE_STAR = 2; 15 | 16 | //评论消息 17 | Integer MESSAGE_COMMENT = 3; 18 | 19 | //评论点赞消息 20 | Integer MESSAGE_COMMENT_FAVOUR = 4; 21 | 22 | //被回复消息 23 | Integer MESSAGE_COMMENT_REPLY = 5; 24 | 25 | //关注消息 26 | Integer MESSAGE_FOLLOW = 6; 27 | 28 | //第一类消息(评论和被回复) 29 | Integer[] comments = {MESSAGE_COMMENT,MESSAGE_COMMENT_REPLY}; 30 | 31 | //第二类消息(点赞和收藏) 32 | Integer[] likes = {MESSAGE_FAVOUR,MESSAGE_STAR,MESSAGE_COMMENT_FAVOUR}; 33 | 34 | //第三类消息(关注) 35 | Integer[] follows = {MESSAGE_FOLLOW}; 36 | 37 | //消息Map集合 38 | Map messageMap = new HashMap() {{ 39 | put("comments", comments); 40 | put("likes", likes); 41 | put("follows", follows); 42 | }}; 43 | 44 | } 45 | -------------------------------------------------------------------------------- /video-framework/src/main/java/com/zhu/constant/RedisConstant.java: -------------------------------------------------------------------------------- 1 | package com.zhu.constant; 2 | 3 | public interface RedisConstant { 4 | 5 | //视频播放量 6 | String VideoPlayNumKey = "videoPlayNum"; 7 | 8 | //自增加一 9 | Integer incrNum = 1; 10 | 11 | //自增减一 12 | Integer decrNum = -1; 13 | 14 | } 15 | -------------------------------------------------------------------------------- /video-framework/src/main/java/com/zhu/constant/UserConstant.java: -------------------------------------------------------------------------------- 1 | package com.zhu.constant; 2 | 3 | /** 4 | * 用户常量 5 | * 6 | */ 7 | public interface UserConstant { 8 | 9 | /** 10 | * 用户登录态键 11 | */ 12 | String USER_LOGIN_STATE = "user_login"; 13 | 14 | /** 15 | * 默认角色 16 | */ 17 | String DEFAULT_ROLE = "user"; 18 | 19 | /** 20 | * 管理员角色 21 | */ 22 | String ADMIN_ROLE = "admin"; 23 | 24 | /** 25 | * 被封号 26 | */ 27 | String BAN_ROLE = "ban"; 28 | 29 | } 30 | -------------------------------------------------------------------------------- /video-framework/src/main/java/com/zhu/customer/ESCustomer.java: -------------------------------------------------------------------------------- 1 | package com.zhu.customer; 2 | 3 | import com.zhu.constant.MQConstant; 4 | import com.zhu.model.dto.video.VideoEsDTO; 5 | import com.zhu.model.entity.VideoInfo; 6 | import org.springframework.amqp.rabbit.annotation.RabbitListener; 7 | import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate; 8 | import org.springframework.stereotype.Component; 9 | 10 | import javax.annotation.Resource; 11 | 12 | @Component 13 | public class ESCustomer { 14 | 15 | @Resource 16 | private ElasticsearchRestTemplate elasticsearchRestTemplate; 17 | 18 | @RabbitListener(queues = MQConstant.ES_QUEUE) 19 | public void updateESData(VideoInfo videoInfo){ 20 | //异步更新ES当中的数据,并且需要保证消息要被消费成功,也就是ES中的消息必须得到同步 21 | VideoEsDTO videoEsDTO = VideoEsDTO.objToDto(videoInfo); 22 | elasticsearchRestTemplate.save(videoEsDTO); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /video-framework/src/main/java/com/zhu/customer/MessageCustomer.java: -------------------------------------------------------------------------------- 1 | package com.zhu.customer; 2 | 3 | import com.alibaba.fastjson2.JSON; 4 | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; 5 | import com.zhu.config.WebSocket; 6 | import com.zhu.constant.MQConstant; 7 | import com.zhu.constant.MessageConstant; 8 | import com.zhu.model.entity.Message; 9 | import com.zhu.service.IMessageService; 10 | import com.zhu.service.IUserService; 11 | import com.zhu.utils.BeanCopeUtils; 12 | import com.zhu.utils.RedisUtils; 13 | import com.zhu.vo.MessageVo; 14 | import org.springframework.amqp.rabbit.annotation.RabbitListener; 15 | import org.springframework.stereotype.Component; 16 | 17 | import javax.annotation.Resource; 18 | 19 | @Component 20 | public class MessageCustomer { 21 | 22 | @Resource 23 | private IMessageService messageService; 24 | 25 | @Resource 26 | private IUserService userService; 27 | 28 | @Resource 29 | private WebSocket webSocket; 30 | 31 | @Resource 32 | private RedisUtils redisUtils; 33 | 34 | @RabbitListener(queues = MQConstant.MESSAGE_QUEUE) 35 | public void videoMessage(Message message){ 36 | //用户收到消息之后先去数据库中判断是否有对应的消息已经存入 37 | //如果有的话那么就不在会发送消息和将消息添加到数据库中 38 | //并且发送消息的时候还会判断用户是否在线,如果离线就先将消息存入到redis当中,当用户上线的时候会去扫描redis中是否有消息未读 39 | //会获取到发送消息的用户信息,以便在前端能够很好的展示 40 | Long receiverId = message.getReceiverId(); 41 | Long senderId = message.getSenderId(); 42 | QueryWrapper messageQueryWrapper = new QueryWrapper<>(); 43 | messageQueryWrapper.eq("message_type",message.getMessageType()); 44 | messageQueryWrapper.eq("sender_id",senderId); 45 | messageQueryWrapper.eq("receiver_id",receiverId); 46 | Message messageData = messageService.getOne(messageQueryWrapper); 47 | if(messageData==null){ 48 | //先假设在线,后面需判断是否在线 49 | if(!webSocket.isOnline(String.valueOf(receiverId))){ 50 | redisUtils.hincr(MessageConstant.MessageKey,String.valueOf(receiverId),1); 51 | message.setIsDelivered(false); 52 | }else{ 53 | //如果用户在线,直接给用户发送对应消息 54 | message.setIsDelivered(true); 55 | MessageVo messageVo = BeanCopeUtils.copyBean(message, MessageVo.class); 56 | messageVo.setUser(userService.getUserBasicInfo(senderId)); 57 | webSocket.sendOneMessage(String.valueOf(receiverId), JSON.toJSONString(messageVo)); 58 | } 59 | messageService.save(message); 60 | } 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /video-framework/src/main/java/com/zhu/datasource/DataSource.java: -------------------------------------------------------------------------------- 1 | package com.zhu.datasource; 2 | 3 | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; 4 | import com.zhu.model.dto.search.SearchRequest; 5 | 6 | import javax.servlet.http.HttpServletRequest; 7 | 8 | public interface DataSource { 9 | 10 | /** 11 | * 根据关键词查找不同类型数据 12 | * @param searchRequest 13 | * @return 14 | */ 15 | Page doSearch(SearchRequest searchRequest, HttpServletRequest request); 16 | 17 | } 18 | -------------------------------------------------------------------------------- /video-framework/src/main/java/com/zhu/datasource/DataSourceRegister.java: -------------------------------------------------------------------------------- 1 | package com.zhu.datasource; 2 | 3 | import com.zhu.model.enums.SearchTypeEnums; 4 | import org.springframework.stereotype.Component; 5 | 6 | import javax.annotation.PostConstruct; 7 | import javax.annotation.Resource; 8 | import java.util.HashMap; 9 | import java.util.Map; 10 | 11 | @Component 12 | public class DataSourceRegister { 13 | 14 | @Resource 15 | private UserDataSource userDataSource; 16 | 17 | @Resource 18 | private VideoDataSource videoDataSource; 19 | 20 | private Map DatasourceHandlerMap; 21 | 22 | @PostConstruct 23 | public void doInit() { 24 | DatasourceHandlerMap = new HashMap() {{ 25 | put(SearchTypeEnums.SEARCH_VIDEO.getValue(), videoDataSource); 26 | put(SearchTypeEnums.SEARCH_USER.getValue(), userDataSource); 27 | }}; 28 | } 29 | 30 | public DataSource getDataSourceByType(String type) { 31 | if (DatasourceHandlerMap == null) { 32 | return null; 33 | } 34 | return DatasourceHandlerMap.get(type); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /video-framework/src/main/java/com/zhu/datasource/UserDataSource.java: -------------------------------------------------------------------------------- 1 | package com.zhu.datasource; 2 | 3 | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; 4 | import com.zhu.model.dto.search.SearchRequest; 5 | import com.zhu.model.entity.User; 6 | import com.zhu.service.IUserService; 7 | import com.zhu.vo.UserVo; 8 | import org.springframework.stereotype.Service; 9 | 10 | import javax.annotation.Resource; 11 | import javax.servlet.http.HttpServletRequest; 12 | 13 | @Service 14 | public class UserDataSource implements DataSource { 15 | 16 | @Resource 17 | private IUserService userService; 18 | 19 | @Override 20 | public Page doSearch(SearchRequest searchRequest, HttpServletRequest request) { 21 | //根据用户名或用户简介来查找指定的用户 22 | String searchKey = searchRequest.getSearchKey(); 23 | long current = searchRequest.getCurrent(); 24 | long pageSize = searchRequest.getPageSize(); 25 | Page userVoPage = userService.searchUser(searchKey,current,pageSize); 26 | return userVoPage; 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /video-framework/src/main/java/com/zhu/datasource/VideoDataSource.java: -------------------------------------------------------------------------------- 1 | package com.zhu.datasource; 2 | 3 | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; 4 | import com.zhu.constant.CommonConstant; 5 | import com.zhu.model.dto.search.SearchRequest; 6 | import com.zhu.model.entity.VideoInfo; 7 | import com.zhu.service.IVideoInfoService; 8 | import com.zhu.vo.VideoVo; 9 | import org.springframework.stereotype.Service; 10 | 11 | import javax.annotation.Resource; 12 | import javax.servlet.http.HttpServletRequest; 13 | 14 | @Service 15 | public class VideoDataSource implements DataSource { 16 | 17 | @Resource 18 | private IVideoInfoService videoInfoService; 19 | 20 | @Override 21 | public Page doSearch(SearchRequest searchRequest,HttpServletRequest request) { 22 | Page videoInfoPage = videoInfoService.searchFromES(searchRequest); 23 | // ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); 24 | // HttpServletRequest request = servletRequestAttributes.getRequest(); 25 | return videoInfoService.getVideoVoOther(videoInfoPage, CommonConstant.NOT_ONLY_AUTHOR,request); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /video-framework/src/main/java/com/zhu/exception/ErrorException.java: -------------------------------------------------------------------------------- 1 | package com.zhu.exception; 2 | 3 | import com.zhu.result.RespBeanEnum; 4 | import lombok.AllArgsConstructor; 5 | import lombok.Data; 6 | import lombok.NoArgsConstructor; 7 | 8 | @Data 9 | @AllArgsConstructor 10 | @NoArgsConstructor 11 | public class ErrorException extends RuntimeException { 12 | 13 | RespBeanEnum respBeanEnum; 14 | 15 | } 16 | -------------------------------------------------------------------------------- /video-framework/src/main/java/com/zhu/exception/GlobalException.java: -------------------------------------------------------------------------------- 1 | package com.zhu.exception; 2 | 3 | import com.zhu.result.RespBean; 4 | import com.zhu.result.RespBeanEnum; 5 | import org.springframework.web.bind.annotation.ExceptionHandler; 6 | import org.springframework.web.bind.annotation.RestControllerAdvice; 7 | 8 | import java.sql.SQLIntegrityConstraintViolationException; 9 | 10 | @RestControllerAdvice 11 | public class GlobalException { 12 | 13 | @ExceptionHandler({SQLIntegrityConstraintViolationException.class}) 14 | public RespBean uniqueData(SQLIntegrityConstraintViolationException e){ 15 | return RespBean.error(RespBeanEnum.EMAIL_EXIST); 16 | } 17 | 18 | @ExceptionHandler({ErrorException.class}) 19 | public RespBean handleError(ErrorException e){ 20 | return RespBean.error(e.getRespBeanEnum()); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /video-framework/src/main/java/com/zhu/handler/VideoBrowseHandler.java: -------------------------------------------------------------------------------- 1 | package com.zhu.handler; 2 | 3 | import com.baomidou.mybatisplus.core.metadata.IPage; 4 | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; 5 | import com.zhu.mapper.UserBrowseMapper; 6 | import com.zhu.model.entity.VideoInfo; 7 | import org.springframework.stereotype.Component; 8 | 9 | import javax.annotation.Resource; 10 | 11 | @Component 12 | public class VideoBrowseHandler implements VideoHandler { 13 | 14 | @Resource 15 | private UserBrowseMapper userBrowseMapper; 16 | 17 | @Override 18 | public Page videoHandler(IPage videoInfoIPage,Long uid) { 19 | Page videoPageList = userBrowseMapper.listBrowseVideoByPage(videoInfoIPage, uid); 20 | return videoPageList; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /video-framework/src/main/java/com/zhu/handler/VideoFavourHandler.java: -------------------------------------------------------------------------------- 1 | package com.zhu.handler; 2 | 3 | import com.baomidou.mybatisplus.core.metadata.IPage; 4 | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; 5 | import com.zhu.mapper.VideoFavourMapper; 6 | import com.zhu.model.entity.VideoInfo; 7 | import org.springframework.stereotype.Component; 8 | 9 | import javax.annotation.Resource; 10 | 11 | @Component 12 | public class VideoFavourHandler implements VideoHandler { 13 | 14 | @Resource 15 | private VideoFavourMapper videoFavourMapper; 16 | 17 | @Override 18 | public Page videoHandler(IPage videoInfoIPage,Long uid) { 19 | Page videoPageList = videoFavourMapper.listFavourVideoByPage(videoInfoIPage, uid); 20 | // List videoInfoList = videoFavourService.getUserFavourVideo(uid); 21 | return videoPageList; 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /video-framework/src/main/java/com/zhu/handler/VideoHandler.java: -------------------------------------------------------------------------------- 1 | package com.zhu.handler; 2 | 3 | import com.baomidou.mybatisplus.core.metadata.IPage; 4 | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; 5 | import com.zhu.model.entity.VideoInfo; 6 | 7 | public interface VideoHandler { 8 | 9 | Page videoHandler(IPage videoInfoIPage, Long uid); 10 | 11 | } 12 | -------------------------------------------------------------------------------- /video-framework/src/main/java/com/zhu/handler/VideoHandlerRegister.java: -------------------------------------------------------------------------------- 1 | package com.zhu.handler; 2 | 3 | import com.zhu.model.enums.VideoTypeEnums; 4 | import org.springframework.stereotype.Component; 5 | 6 | import javax.annotation.PostConstruct; 7 | import javax.annotation.Resource; 8 | import java.util.HashMap; 9 | import java.util.Map; 10 | 11 | @Component 12 | public class VideoHandlerRegister { 13 | 14 | @Resource 15 | private VideoWorksHandler videoWorksHandler; 16 | 17 | @Resource 18 | private VideoFavourHandler videoFavourHandler; 19 | 20 | @Resource 21 | private VideoStarHandler videoStarHandler; 22 | 23 | @Resource 24 | private VideoBrowseHandler videoBrowseHandler; 25 | 26 | private Map typeHandlerMap; 27 | 28 | @PostConstruct 29 | public void doInit() { 30 | typeHandlerMap = new HashMap() {{ 31 | put(VideoTypeEnums.VIDEO_USER.getValue(), videoWorksHandler); 32 | put(VideoTypeEnums.VIDEO_FAVOUR.getValue(), videoFavourHandler); 33 | put(VideoTypeEnums.VIDEO_STAR.getValue(), videoStarHandler); 34 | put(VideoTypeEnums.VIDEO_HISTORY.getValue(),videoBrowseHandler); 35 | }}; 36 | } 37 | 38 | public VideoHandler getDataSourceByType(String type) { 39 | if (typeHandlerMap == null) { 40 | return null; 41 | } 42 | return typeHandlerMap.get(type); 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /video-framework/src/main/java/com/zhu/handler/VideoStarHandler.java: -------------------------------------------------------------------------------- 1 | package com.zhu.handler; 2 | 3 | import com.baomidou.mybatisplus.core.metadata.IPage; 4 | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; 5 | import com.zhu.mapper.VideoStarMapper; 6 | import com.zhu.model.entity.VideoInfo; 7 | import org.springframework.stereotype.Component; 8 | 9 | import javax.annotation.Resource; 10 | 11 | @Component 12 | public class VideoStarHandler implements VideoHandler { 13 | 14 | @Resource 15 | private VideoStarMapper videoStarMapper; 16 | 17 | @Override 18 | public Page videoHandler(IPage videoInfoIPage, Long uid) { 19 | Page videoInfoPage = videoStarMapper.listStarVideoByPage(videoInfoIPage, uid); 20 | // List userStarVideo = videoStarService.getUserStarVideo(uid); 21 | return videoInfoPage; 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /video-framework/src/main/java/com/zhu/handler/VideoWorksHandler.java: -------------------------------------------------------------------------------- 1 | package com.zhu.handler; 2 | 3 | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; 4 | import com.baomidou.mybatisplus.core.metadata.IPage; 5 | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; 6 | import com.zhu.model.entity.VideoInfo; 7 | import com.zhu.service.IVideoInfoService; 8 | import org.springframework.stereotype.Component; 9 | 10 | import javax.annotation.Resource; 11 | 12 | @Component 13 | public class VideoWorksHandler implements VideoHandler { 14 | 15 | @Resource 16 | private IVideoInfoService videoInfoService; 17 | 18 | @Override 19 | public Page videoHandler(IPage videoInfoIPage, Long uid) { 20 | QueryWrapper videoInfoQueryWrapper = new QueryWrapper<>(); 21 | videoInfoQueryWrapper.eq("uid",uid); 22 | Page videoPageList = (Page) videoInfoService.page(videoInfoIPage, videoInfoQueryWrapper); 23 | // List videoInfos = videoInfoService.list(videoInfoQueryWrapper); 24 | // return CollectionUtils.isEmpty(videoInfos)? Collections.EMPTY_LIST:videoInfos; 25 | return videoPageList; 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /video-framework/src/main/java/com/zhu/mapper/CommentFavourMapper.java: -------------------------------------------------------------------------------- 1 | package com.zhu.mapper; 2 | 3 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 4 | import com.zhu.model.entity.CommentFavour; 5 | 6 | /** 7 | *

8 | * Mapper 接口 9 | *

10 | * 11 | * @author xiaozhu 12 | * @since 2023-10-31 13 | */ 14 | public interface CommentFavourMapper extends BaseMapper { 15 | 16 | } 17 | -------------------------------------------------------------------------------- /video-framework/src/main/java/com/zhu/mapper/CommentMapper.java: -------------------------------------------------------------------------------- 1 | package com.zhu.mapper; 2 | 3 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 4 | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; 5 | import com.zhu.model.entity.Comment; 6 | import com.zhu.vo.CommentVo; 7 | import org.apache.ibatis.annotations.Param; 8 | 9 | import java.util.List; 10 | 11 | /** 12 | *

13 | * Mapper 接口 14 | *

15 | * 16 | * @author xiaozhu 17 | * @since 2023-10-27 18 | */ 19 | public interface CommentMapper extends BaseMapper { 20 | 21 | List getVideoComment(@Param("videoId") Long videoId); 22 | 23 | Page getReply(Page page, @Param("id") Long id); 24 | 25 | } 26 | -------------------------------------------------------------------------------- /video-framework/src/main/java/com/zhu/mapper/DanmuMapper.java: -------------------------------------------------------------------------------- 1 | package com.zhu.mapper; 2 | 3 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 4 | import com.zhu.model.entity.Danmu; 5 | 6 | /** 7 | *

8 | * Mapper 接口 9 | *

10 | * 11 | * @author xiaozhu 12 | * @since 2023-11-14 13 | */ 14 | public interface DanmuMapper extends BaseMapper { 15 | 16 | } 17 | -------------------------------------------------------------------------------- /video-framework/src/main/java/com/zhu/mapper/MessageMapper.java: -------------------------------------------------------------------------------- 1 | package com.zhu.mapper; 2 | 3 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 4 | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; 5 | import com.zhu.model.entity.Message; 6 | import com.zhu.vo.MessageVo; 7 | import org.apache.ibatis.annotations.Param; 8 | 9 | /** 10 | *

11 | * Mapper 接口 12 | *

13 | * 14 | * @author xiaozhu 15 | * @since 2023-11-13 16 | */ 17 | public interface MessageMapper extends BaseMapper { 18 | 19 | Page getMessageVoList(Page messagePage,@Param("messageTypes") Integer[] messageTypes,@Param("receiverId") Long receiverId); 20 | 21 | } 22 | -------------------------------------------------------------------------------- /video-framework/src/main/java/com/zhu/mapper/TypeMapper.java: -------------------------------------------------------------------------------- 1 | package com.zhu.mapper; 2 | 3 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 4 | import com.zhu.model.entity.Type; 5 | 6 | /** 7 | *

8 | * Mapper 接口 9 | *

10 | * 11 | * @author xiaozhu 12 | * @since 2023-10-29 13 | */ 14 | public interface TypeMapper extends BaseMapper { 15 | 16 | } 17 | -------------------------------------------------------------------------------- /video-framework/src/main/java/com/zhu/mapper/UserBrowseMapper.java: -------------------------------------------------------------------------------- 1 | package com.zhu.mapper; 2 | 3 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 4 | import com.baomidou.mybatisplus.core.metadata.IPage; 5 | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; 6 | import com.zhu.model.entity.UserBrowse; 7 | import com.zhu.model.entity.VideoInfo; 8 | import org.apache.ibatis.annotations.Param; 9 | 10 | /** 11 | *

12 | * Mapper 接口 13 | *

14 | * 15 | * @author xiaozhu 16 | * @since 2023-12-04 17 | */ 18 | public interface UserBrowseMapper extends BaseMapper { 19 | 20 | Page listBrowseVideoByPage(IPage videoInfoIPage, @Param("uid") long uid); 21 | 22 | } 23 | -------------------------------------------------------------------------------- /video-framework/src/main/java/com/zhu/mapper/UserFollowMapper.java: -------------------------------------------------------------------------------- 1 | package com.zhu.mapper; 2 | 3 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 4 | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; 5 | import com.zhu.model.entity.User; 6 | import com.zhu.model.entity.UserFollow; 7 | import org.apache.ibatis.annotations.Param; 8 | 9 | /** 10 | *

11 | * Mapper 接口 12 | *

13 | * 14 | * @author xiaozhu 15 | * @since 2023-11-02 16 | */ 17 | public interface UserFollowMapper extends BaseMapper { 18 | 19 | Page gerUserFollowFans(Page userPage, @Param("searchText") String searchText,@Param("type") String type,@Param("uid") Long uid); 20 | 21 | } 22 | -------------------------------------------------------------------------------- /video-framework/src/main/java/com/zhu/mapper/UserMapper.java: -------------------------------------------------------------------------------- 1 | package com.zhu.mapper; 2 | 3 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 4 | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; 5 | import com.zhu.model.entity.User; 6 | import com.zhu.vo.AuthorInfoVo; 7 | import com.zhu.vo.UserVo; 8 | import org.apache.ibatis.annotations.Param; 9 | 10 | /** 11 | *

12 | * Mapper 接口 13 | *

14 | * 15 | * @author xiaozhu 16 | * @since 2023-10-25 17 | */ 18 | public interface UserMapper extends BaseMapper { 19 | 20 | Page getUserVOList(Page userVoPage, @Param("searchKey") String searchKey); 21 | 22 | AuthorInfoVo getUserInfo(Long uid); 23 | 24 | } 25 | -------------------------------------------------------------------------------- /video-framework/src/main/java/com/zhu/mapper/UserRatingMapper.java: -------------------------------------------------------------------------------- 1 | package com.zhu.mapper; 2 | 3 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 4 | import com.zhu.model.entity.UserRating; 5 | import org.apache.ibatis.annotations.MapKey; 6 | 7 | import java.util.Map; 8 | 9 | /** 10 | *

11 | * Mapper 接口 12 | *

13 | * 14 | * @author xiaozhu 15 | * @since 2023-12-05 16 | */ 17 | public interface UserRatingMapper extends BaseMapper { 18 | 19 | @MapKey("uid") 20 | Map> getUserRatings(); 21 | 22 | } 23 | -------------------------------------------------------------------------------- /video-framework/src/main/java/com/zhu/mapper/VideoFavourMapper.java: -------------------------------------------------------------------------------- 1 | package com.zhu.mapper; 2 | 3 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 4 | import com.baomidou.mybatisplus.core.metadata.IPage; 5 | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; 6 | import com.zhu.model.entity.VideoFavour; 7 | import com.zhu.model.entity.VideoInfo; 8 | import org.apache.ibatis.annotations.Param; 9 | 10 | /** 11 | *

12 | * Mapper 接口 13 | *

14 | * 15 | * @author xiaozhu 16 | * @since 2023-10-31 17 | */ 18 | public interface VideoFavourMapper extends BaseMapper { 19 | 20 | Page listFavourVideoByPage(IPage videoInfoIPage, @Param("uid") long uid); 21 | 22 | } 23 | -------------------------------------------------------------------------------- /video-framework/src/main/java/com/zhu/mapper/VideoInfoMapper.java: -------------------------------------------------------------------------------- 1 | package com.zhu.mapper; 2 | 3 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 4 | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; 5 | import com.zhu.model.entity.VideoInfo; 6 | import com.zhu.vo.VideoVo; 7 | import org.apache.ibatis.annotations.Param; 8 | 9 | /** 10 | *

11 | * Mapper 接口 12 | *

13 | * 14 | * @author xiaozhu 15 | * @since 2023-10-24 16 | */ 17 | public interface VideoInfoMapper extends BaseMapper { 18 | 19 | Page getVideoData(Page videoVoPage, @Param("type") Long type); 20 | 21 | VideoVo getVideoById(@Param("videoId") Long videoId); 22 | 23 | Page randomVideo(Page videoInfoPage); 24 | 25 | Page getVideoByFollow(Page videoInfoPage, @Param("uid") Long uid); 26 | 27 | } 28 | -------------------------------------------------------------------------------- /video-framework/src/main/java/com/zhu/mapper/VideoStarMapper.java: -------------------------------------------------------------------------------- 1 | package com.zhu.mapper; 2 | 3 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 4 | import com.baomidou.mybatisplus.core.metadata.IPage; 5 | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; 6 | import com.zhu.model.entity.VideoInfo; 7 | import com.zhu.model.entity.VideoStar; 8 | import org.apache.ibatis.annotations.Param; 9 | 10 | /** 11 | *

12 | * Mapper 接口 13 | *

14 | * 15 | * @author xiaozhu 16 | * @since 2023-10-27 17 | */ 18 | public interface VideoStarMapper extends BaseMapper { 19 | 20 | Page listStarVideoByPage(IPage videoInfoIPage, @Param("uid") long uid); 21 | 22 | } 23 | -------------------------------------------------------------------------------- /video-framework/src/main/java/com/zhu/model/dto/comment/CommentAddRequest.java: -------------------------------------------------------------------------------- 1 | package com.zhu.model.dto.comment; 2 | 3 | import lombok.Data; 4 | 5 | import java.io.Serializable; 6 | 7 | @Data 8 | public class CommentAddRequest implements Serializable { 9 | 10 | private Long parentId; 11 | 12 | private String respondentName; 13 | 14 | private String address; 15 | 16 | private String content; 17 | 18 | private Long uid; 19 | 20 | private Long receiverId; 21 | 22 | private Long videoId; 23 | 24 | } 25 | -------------------------------------------------------------------------------- /video-framework/src/main/java/com/zhu/model/dto/comment/CommentLikesRequest.java: -------------------------------------------------------------------------------- 1 | package com.zhu.model.dto.comment; 2 | 3 | import lombok.Data; 4 | 5 | import java.io.Serializable; 6 | 7 | @Data 8 | public class CommentLikesRequest implements Serializable { 9 | 10 | private static final long serialVersionUID = 1L; 11 | 12 | private Long videoId; 13 | 14 | } 15 | -------------------------------------------------------------------------------- /video-framework/src/main/java/com/zhu/model/dto/comment/CommentReplyRequest.java: -------------------------------------------------------------------------------- 1 | package com.zhu.model.dto.comment; 2 | 3 | import lombok.Data; 4 | 5 | @Data 6 | public class CommentReplyRequest { 7 | 8 | private Long parentId; 9 | 10 | private Long current; 11 | 12 | private Long pageSize; 13 | 14 | } 15 | -------------------------------------------------------------------------------- /video-framework/src/main/java/com/zhu/model/dto/danmu/DanmuAddRequest.java: -------------------------------------------------------------------------------- 1 | package com.zhu.model.dto.danmu; 2 | 3 | import lombok.Data; 4 | 5 | import java.io.Serializable; 6 | 7 | @Data 8 | public class DanmuAddRequest implements Serializable { 9 | 10 | private Long uid; 11 | 12 | private Long videoId; 13 | 14 | private String content; 15 | 16 | private Float createTime; 17 | 18 | } 19 | -------------------------------------------------------------------------------- /video-framework/src/main/java/com/zhu/model/dto/message/MessageQueryRequest.java: -------------------------------------------------------------------------------- 1 | package com.zhu.model.dto.message; 2 | 3 | import com.zhu.common.PageRequest; 4 | import lombok.Data; 5 | 6 | import java.io.Serializable; 7 | 8 | @Data 9 | public class MessageQueryRequest extends PageRequest implements Serializable { 10 | 11 | private String type; 12 | 13 | } 14 | -------------------------------------------------------------------------------- /video-framework/src/main/java/com/zhu/model/dto/message/MessageUpdateRequest.java: -------------------------------------------------------------------------------- 1 | package com.zhu.model.dto.message; 2 | 3 | import lombok.Data; 4 | 5 | import java.io.Serializable; 6 | 7 | @Data 8 | public class MessageUpdateRequest implements Serializable { 9 | 10 | private String type; 11 | 12 | } 13 | -------------------------------------------------------------------------------- /video-framework/src/main/java/com/zhu/model/dto/search/SearchRequest.java: -------------------------------------------------------------------------------- 1 | package com.zhu.model.dto.search; 2 | 3 | import com.zhu.common.PageRequest; 4 | import lombok.Data; 5 | 6 | import java.io.Serializable; 7 | 8 | @Data 9 | public class SearchRequest extends PageRequest implements Serializable { 10 | 11 | private String searchKey; 12 | 13 | private Long typeId; 14 | 15 | private String type; 16 | 17 | private Integer publishTime; 18 | 19 | private Integer sortType; 20 | 21 | } 22 | -------------------------------------------------------------------------------- /video-framework/src/main/java/com/zhu/model/dto/user/UserEditRequest.java: -------------------------------------------------------------------------------- 1 | package com.zhu.model.dto.user; 2 | 3 | import lombok.Data; 4 | 5 | import java.io.Serializable; 6 | 7 | @Data 8 | public class UserEditRequest implements Serializable { 9 | 10 | private static final long serialVersionUID = 1L; 11 | 12 | private Long uid; 13 | 14 | private String userAvatar; 15 | 16 | private String userNickname; 17 | 18 | private String userProfile; 19 | 20 | } 21 | -------------------------------------------------------------------------------- /video-framework/src/main/java/com/zhu/model/dto/user/UserFollowFansRequest.java: -------------------------------------------------------------------------------- 1 | package com.zhu.model.dto.user; 2 | 3 | import lombok.Data; 4 | 5 | /** 6 | * 用户关注或者粉丝用户列表请求类 7 | */ 8 | @Data 9 | public class UserFollowFansRequest { 10 | 11 | private String searchText; 12 | 13 | private String type; 14 | 15 | private long current; 16 | 17 | private long pageSize; 18 | 19 | } 20 | -------------------------------------------------------------------------------- /video-framework/src/main/java/com/zhu/model/dto/user/UserFollowRequest.java: -------------------------------------------------------------------------------- 1 | package com.zhu.model.dto.user; 2 | 3 | import lombok.Data; 4 | 5 | import java.io.Serializable; 6 | 7 | @Data 8 | public class UserFollowRequest implements Serializable { 9 | 10 | private static final long serialVersionUID = 1L; 11 | 12 | private Long followId; 13 | 14 | } 15 | -------------------------------------------------------------------------------- /video-framework/src/main/java/com/zhu/model/dto/user/UserInfoRequest.java: -------------------------------------------------------------------------------- 1 | package com.zhu.model.dto.user; 2 | 3 | import lombok.Data; 4 | 5 | import java.io.Serializable; 6 | 7 | @Data 8 | public class UserInfoRequest implements Serializable { 9 | 10 | private static final long serialVersionUID = 1L; 11 | 12 | private Long uid; 13 | 14 | } 15 | -------------------------------------------------------------------------------- /video-framework/src/main/java/com/zhu/model/dto/user/UserLoginRequest.java: -------------------------------------------------------------------------------- 1 | package com.zhu.model.dto.user; 2 | 3 | import lombok.Data; 4 | 5 | import java.io.Serializable; 6 | 7 | @Data 8 | public class UserLoginRequest implements Serializable { 9 | 10 | private static final long serialVersionUID = 1L; 11 | 12 | private String userEmail; 13 | 14 | private String userPassword; 15 | 16 | } 17 | -------------------------------------------------------------------------------- /video-framework/src/main/java/com/zhu/model/dto/user/UserRegisterRequest.java: -------------------------------------------------------------------------------- 1 | package com.zhu.model.dto.user; 2 | 3 | import lombok.Data; 4 | 5 | import java.io.Serializable; 6 | 7 | @Data 8 | public class UserRegisterRequest implements Serializable { 9 | 10 | private static final long serialVersionUID = 1L; 11 | 12 | private String userEmail; 13 | 14 | private String userPassword; 15 | 16 | private String userNickname; 17 | 18 | private String confirmPassword; 19 | 20 | private String keyCode; 21 | 22 | } 23 | -------------------------------------------------------------------------------- /video-framework/src/main/java/com/zhu/model/dto/user/UserVideoRequest.java: -------------------------------------------------------------------------------- 1 | package com.zhu.model.dto.user; 2 | 3 | import lombok.Data; 4 | 5 | @Data 6 | public class UserVideoRequest { 7 | 8 | private Long uid; 9 | 10 | private String type; 11 | 12 | private Long current; 13 | 14 | private Long pageSize; 15 | 16 | } 17 | -------------------------------------------------------------------------------- /video-framework/src/main/java/com/zhu/model/dto/video/VideoAddRequest.java: -------------------------------------------------------------------------------- 1 | package com.zhu.model.dto.video; 2 | 3 | import lombok.Data; 4 | 5 | import java.io.Serializable; 6 | 7 | @Data 8 | public class VideoAddRequest implements Serializable { 9 | 10 | private static final long serialVersionUID = 1L; 11 | 12 | private Long videoId; 13 | 14 | private String description; 15 | 16 | private String videoUrl; 17 | 18 | private String videoPic; 19 | 20 | private String videoName; 21 | 22 | private Long typeId; 23 | 24 | private Long uid; 25 | 26 | } 27 | -------------------------------------------------------------------------------- /video-framework/src/main/java/com/zhu/model/dto/video/VideoBrowseRequest.java: -------------------------------------------------------------------------------- 1 | package com.zhu.model.dto.video; 2 | 3 | import lombok.Data; 4 | 5 | @Data 6 | public class VideoBrowseRequest { 7 | 8 | private Long videoId; 9 | 10 | } 11 | -------------------------------------------------------------------------------- /video-framework/src/main/java/com/zhu/model/dto/video/VideoEsDTO.java: -------------------------------------------------------------------------------- 1 | package com.zhu.model.dto.video; 2 | 3 | import com.zhu.model.entity.VideoInfo; 4 | import lombok.Data; 5 | import org.springframework.beans.BeanUtils; 6 | import org.springframework.data.annotation.Id; 7 | import org.springframework.data.elasticsearch.annotations.Document; 8 | import org.springframework.data.elasticsearch.annotations.Field; 9 | import org.springframework.data.elasticsearch.annotations.FieldType; 10 | 11 | import java.util.Date; 12 | 13 | @Data 14 | @Document(indexName = "video") 15 | public class VideoEsDTO { 16 | 17 | private static final String DATE_TIME_PATTERN = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"; 18 | 19 | @Id 20 | private Long videoId; 21 | 22 | 23 | private String description; 24 | 25 | @Field(type = FieldType.Long) 26 | private Long favourNum; 27 | 28 | @Field(type = FieldType.Long) 29 | private Long starNum; 30 | 31 | @Field(type = FieldType.Long) 32 | private Long typeId; 33 | 34 | @Field(type = FieldType.Long) 35 | private Long uid; 36 | 37 | @Field(type = FieldType.Integer) 38 | private Integer status; 39 | 40 | @Field(index = false, store = true, type = FieldType.Date, format = {}, pattern = DATE_TIME_PATTERN) 41 | private Date createTime; 42 | 43 | @Field(index = false, store = true, type = FieldType.Date, format = {}, pattern = DATE_TIME_PATTERN) 44 | private Date updateTime; 45 | 46 | private static final long serialVersionUID = 1L; 47 | 48 | /** 49 | * 对象转包装类 50 | * 51 | * @param videoInfo 52 | * @return 53 | */ 54 | public static VideoEsDTO objToDto(VideoInfo videoInfo) { 55 | if (videoInfo == null) { 56 | return null; 57 | } 58 | VideoEsDTO postEsDTO = new VideoEsDTO(); 59 | BeanUtils.copyProperties(videoInfo, postEsDTO); 60 | return postEsDTO; 61 | } 62 | 63 | /** 64 | * 包装类转对象 65 | * 66 | * @param videoEsDTO 67 | * @return 68 | */ 69 | public static VideoInfo dtoToObj(VideoEsDTO videoEsDTO) { 70 | if (videoEsDTO == null) { 71 | return null; 72 | } 73 | VideoInfo post = new VideoInfo(); 74 | BeanUtils.copyProperties(videoEsDTO, post); 75 | return post; 76 | } 77 | 78 | } 79 | -------------------------------------------------------------------------------- /video-framework/src/main/java/com/zhu/model/dto/video/VideoFavourRequest.java: -------------------------------------------------------------------------------- 1 | package com.zhu.model.dto.video; 2 | 3 | import lombok.Data; 4 | 5 | import java.io.Serializable; 6 | 7 | @Data 8 | public class VideoFavourRequest implements Serializable { 9 | 10 | private Long videoId; 11 | 12 | private static final long serialVersionUID = 1L; 13 | 14 | } 15 | -------------------------------------------------------------------------------- /video-framework/src/main/java/com/zhu/model/dto/video/VideoRecommendRequest.java: -------------------------------------------------------------------------------- 1 | package com.zhu.model.dto.video; 2 | 3 | import com.zhu.common.PageRequest; 4 | import lombok.Data; 5 | 6 | import java.io.Serializable; 7 | 8 | @Data 9 | public class VideoRecommendRequest extends PageRequest implements Serializable { 10 | } 11 | -------------------------------------------------------------------------------- /video-framework/src/main/java/com/zhu/model/dto/video/VideoStarRequest.java: -------------------------------------------------------------------------------- 1 | package com.zhu.model.dto.video; 2 | 3 | import lombok.Data; 4 | 5 | import java.io.Serializable; 6 | 7 | @Data 8 | public class VideoStarRequest implements Serializable { 9 | 10 | private Long videoId; 11 | 12 | private static final long serialVersionUID = 1L; 13 | 14 | } 15 | -------------------------------------------------------------------------------- /video-framework/src/main/java/com/zhu/model/dto/video/VideoTypeRequest.java: -------------------------------------------------------------------------------- 1 | package com.zhu.model.dto.video; 2 | 3 | import lombok.Data; 4 | 5 | @Data 6 | public class VideoTypeRequest { 7 | 8 | private Long type; 9 | 10 | private long current; 11 | 12 | private long pageSize; 13 | 14 | } 15 | -------------------------------------------------------------------------------- /video-framework/src/main/java/com/zhu/model/entity/Comment.java: -------------------------------------------------------------------------------- 1 | package com.zhu.model.entity; 2 | 3 | import com.baomidou.mybatisplus.annotation.*; 4 | import lombok.AllArgsConstructor; 5 | import lombok.Data; 6 | import lombok.NoArgsConstructor; 7 | 8 | import java.io.Serializable; 9 | import java.util.Date; 10 | 11 | /** 12 | *

13 | * 14 | *

15 | * 16 | * @author xiaozhu 17 | * @since 2023-10-27 18 | */ 19 | @TableName("t_comment") 20 | @Data 21 | @AllArgsConstructor 22 | @NoArgsConstructor 23 | public class Comment implements Serializable { 24 | 25 | private static final long serialVersionUID = 1L; 26 | 27 | @TableId(value = "id", type = IdType.AUTO) 28 | private Long id; 29 | 30 | private Long parentId; 31 | 32 | private String respondentName; 33 | 34 | private String address; 35 | 36 | private String content; 37 | 38 | private Long likes; 39 | 40 | private Long uid; 41 | 42 | private Long videoId; 43 | 44 | @TableField(fill = FieldFill.INSERT) 45 | private Date createTime; 46 | 47 | private Integer isDelete; 48 | 49 | } 50 | -------------------------------------------------------------------------------- /video-framework/src/main/java/com/zhu/model/entity/CommentFavour.java: -------------------------------------------------------------------------------- 1 | package com.zhu.model.entity; 2 | 3 | import com.baomidou.mybatisplus.annotation.IdType; 4 | import com.baomidou.mybatisplus.annotation.TableId; 5 | import com.baomidou.mybatisplus.annotation.TableName; 6 | import com.zhu.common.CommonEntity; 7 | import lombok.AllArgsConstructor; 8 | import lombok.Data; 9 | import lombok.NoArgsConstructor; 10 | 11 | import java.io.Serializable; 12 | 13 | /** 14 | *

15 | * 16 | *

17 | * 18 | * @author xiaozhu 19 | * @since 2023-10-31 20 | */ 21 | @TableName("t_comment_favour") 22 | @Data 23 | @AllArgsConstructor 24 | @NoArgsConstructor 25 | public class CommentFavour extends CommonEntity implements Serializable { 26 | 27 | private static final long serialVersionUID = 1L; 28 | 29 | @TableId(value = "id", type = IdType.AUTO) 30 | private Long id; 31 | 32 | private Long commentId; 33 | 34 | private Long uid; 35 | 36 | private Long videoId; 37 | 38 | } 39 | -------------------------------------------------------------------------------- /video-framework/src/main/java/com/zhu/model/entity/Danmu.java: -------------------------------------------------------------------------------- 1 | package com.zhu.model.entity; 2 | 3 | import com.baomidou.mybatisplus.annotation.IdType; 4 | import com.baomidou.mybatisplus.annotation.TableId; 5 | import com.baomidou.mybatisplus.annotation.TableName; 6 | import lombok.AllArgsConstructor; 7 | import lombok.Data; 8 | import lombok.NoArgsConstructor; 9 | 10 | import java.io.Serializable; 11 | import java.util.Date; 12 | 13 | /** 14 | *

15 | * 16 | *

17 | * 18 | * @author xiaozhu 19 | * @since 2023-11-14 20 | */ 21 | @TableName("t_danmu") 22 | @Data 23 | @AllArgsConstructor 24 | @NoArgsConstructor 25 | public class Danmu implements Serializable { 26 | 27 | private static final long serialVersionUID = 1L; 28 | 29 | @TableId(value = "id", type = IdType.AUTO) 30 | private Long id; 31 | 32 | private Long uid; 33 | 34 | private Long videoId; 35 | 36 | private String content; 37 | 38 | private Integer status; 39 | 40 | private Float createTime; 41 | 42 | } 43 | -------------------------------------------------------------------------------- /video-framework/src/main/java/com/zhu/model/entity/Message.java: -------------------------------------------------------------------------------- 1 | package com.zhu.model.entity; 2 | 3 | import com.baomidou.mybatisplus.annotation.*; 4 | import com.fasterxml.jackson.annotation.JsonFormat; 5 | import lombok.AllArgsConstructor; 6 | import lombok.Data; 7 | import lombok.NoArgsConstructor; 8 | 9 | import java.io.Serializable; 10 | import java.util.Date; 11 | 12 | /** 13 | *

14 | * 15 | *

16 | * 17 | * @author xiaozhu 18 | * @since 2023-11-13 19 | */ 20 | @TableName("t_message") 21 | @Data 22 | @AllArgsConstructor 23 | @NoArgsConstructor 24 | public class Message implements Serializable { 25 | 26 | private static final long serialVersionUID = 1L; 27 | 28 | @TableId(value = "id", type = IdType.AUTO) 29 | private Long id; 30 | 31 | private Integer messageType; 32 | 33 | private Long videoId; 34 | 35 | private String messageContent; 36 | 37 | @JsonFormat(shape = JsonFormat.Shape.STRING) 38 | private Long senderId; 39 | 40 | @JsonFormat(shape = JsonFormat.Shape.STRING) 41 | private Long receiverId; 42 | 43 | private Boolean isDelivered; 44 | 45 | @TableField(fill = FieldFill.INSERT) 46 | private Date createTime; 47 | 48 | } 49 | -------------------------------------------------------------------------------- /video-framework/src/main/java/com/zhu/model/entity/Type.java: -------------------------------------------------------------------------------- 1 | package com.zhu.model.entity; 2 | 3 | import com.baomidou.mybatisplus.annotation.IdType; 4 | import com.baomidou.mybatisplus.annotation.TableId; 5 | import com.baomidou.mybatisplus.annotation.TableName; 6 | import com.zhu.common.CommonEntity; 7 | import lombok.AllArgsConstructor; 8 | import lombok.Data; 9 | import lombok.NoArgsConstructor; 10 | 11 | import java.io.Serializable; 12 | 13 | /** 14 | *

15 | * 16 | *

17 | * 18 | * @author xiaozhu 19 | * @since 2023-10-29 20 | */ 21 | @TableName("t_type") 22 | @Data 23 | @AllArgsConstructor 24 | @NoArgsConstructor 25 | public class Type extends CommonEntity implements Serializable { 26 | 27 | private static final long serialVersionUID = 1L; 28 | 29 | @TableId(value = "type_id", type = IdType.AUTO) 30 | private Long typeId; 31 | 32 | private String typeName; 33 | 34 | private Integer status; 35 | 36 | } 37 | -------------------------------------------------------------------------------- /video-framework/src/main/java/com/zhu/model/entity/User.java: -------------------------------------------------------------------------------- 1 | package com.zhu.model.entity; 2 | 3 | import com.baomidou.mybatisplus.annotation.IdType; 4 | import com.baomidou.mybatisplus.annotation.TableField; 5 | import com.baomidou.mybatisplus.annotation.TableId; 6 | import com.baomidou.mybatisplus.annotation.TableName; 7 | import com.fasterxml.jackson.annotation.JsonFormat; 8 | import com.zhu.common.CommonEntity; 9 | import lombok.AllArgsConstructor; 10 | import lombok.Data; 11 | import lombok.NoArgsConstructor; 12 | 13 | import java.io.Serializable; 14 | 15 | /** 16 | *

17 | * 18 | *

19 | * 20 | * @author xiaozhu 21 | * @since 2023-10-25 22 | */ 23 | @TableName("t_user") 24 | @Data 25 | @AllArgsConstructor 26 | @NoArgsConstructor 27 | public class User extends CommonEntity implements Serializable { 28 | 29 | private static final long serialVersionUID = 1L; 30 | 31 | @TableId(type = IdType.ASSIGN_ID) 32 | @JsonFormat(shape = JsonFormat.Shape.STRING) 33 | private Long uid; 34 | 35 | private String userEmail; 36 | 37 | private String userPassword; 38 | 39 | private String userNickname; 40 | 41 | private String userAvatar; 42 | 43 | private String userProfile; 44 | 45 | private Integer sex; 46 | 47 | private String userRole; 48 | 49 | @TableField(value = "is_hiddenFavour") 50 | private Boolean isHiddenFavour; 51 | 52 | } 53 | -------------------------------------------------------------------------------- /video-framework/src/main/java/com/zhu/model/entity/UserBrowse.java: -------------------------------------------------------------------------------- 1 | package com.zhu.model.entity; 2 | 3 | import com.baomidou.mybatisplus.annotation.*; 4 | import lombok.AllArgsConstructor; 5 | import lombok.Data; 6 | import lombok.NoArgsConstructor; 7 | 8 | import java.io.Serializable; 9 | import java.util.Date; 10 | 11 | /** 12 | *

13 | * 14 | *

15 | * 16 | * @author xiaozhu 17 | * @since 2023-12-04 18 | */ 19 | @TableName("t_user_browse") 20 | @Data 21 | @AllArgsConstructor 22 | @NoArgsConstructor 23 | public class UserBrowse implements Serializable { 24 | 25 | private static final long serialVersionUID = 1L; 26 | 27 | @TableId(value = "id", type = IdType.AUTO) 28 | private Long id; 29 | 30 | private Long videoId; 31 | 32 | private Long uid; 33 | 34 | @TableField(fill = FieldFill.INSERT_UPDATE) 35 | private Date browseTime; 36 | 37 | } 38 | -------------------------------------------------------------------------------- /video-framework/src/main/java/com/zhu/model/entity/UserFollow.java: -------------------------------------------------------------------------------- 1 | package com.zhu.model.entity; 2 | 3 | import com.baomidou.mybatisplus.annotation.*; 4 | import lombok.AllArgsConstructor; 5 | import lombok.Data; 6 | import lombok.NoArgsConstructor; 7 | 8 | import java.io.Serializable; 9 | import java.util.Date; 10 | 11 | /** 12 | *

13 | * 14 | *

15 | * 16 | * @author xiaozhu 17 | * @since 2023-11-02 18 | */ 19 | @TableName("t_user_follow") 20 | @Data 21 | @AllArgsConstructor 22 | @NoArgsConstructor 23 | public class UserFollow implements Serializable { 24 | 25 | private static final long serialVersionUID = 1L; 26 | 27 | @TableId(value = "id", type = IdType.AUTO) 28 | private Long id; 29 | 30 | private Long userId; 31 | 32 | private Long followUserId; 33 | 34 | @TableField(fill = FieldFill.INSERT) 35 | private Date createTime; 36 | 37 | } 38 | -------------------------------------------------------------------------------- /video-framework/src/main/java/com/zhu/model/entity/UserRating.java: -------------------------------------------------------------------------------- 1 | package com.zhu.model.entity; 2 | 3 | import com.baomidou.mybatisplus.annotation.FieldFill; 4 | import com.baomidou.mybatisplus.annotation.TableField; 5 | import com.baomidou.mybatisplus.annotation.TableName; 6 | import io.swagger.annotations.ApiModel; 7 | import lombok.AllArgsConstructor; 8 | import lombok.Data; 9 | import lombok.NoArgsConstructor; 10 | 11 | import java.io.Serializable; 12 | import java.time.LocalDateTime; 13 | import java.util.Date; 14 | 15 | /** 16 | *

17 | * 18 | *

19 | * 20 | * @author xiaozhu 21 | * @since 2023-12-05 22 | */ 23 | @TableName("t_user_rating") 24 | @Data 25 | @AllArgsConstructor 26 | @NoArgsConstructor 27 | public class UserRating implements Serializable { 28 | 29 | private static final long serialVersionUID = 1L; 30 | 31 | private Long uid; 32 | 33 | private Long videoId; 34 | 35 | private Integer rate; 36 | 37 | public UserRating(Long uid, Long videoId, Integer rate) { 38 | this.uid = uid; 39 | this.videoId = videoId; 40 | this.rate = rate; 41 | } 42 | 43 | @TableField(fill = FieldFill.INSERT_UPDATE) 44 | private Date rateTime; 45 | 46 | } 47 | -------------------------------------------------------------------------------- /video-framework/src/main/java/com/zhu/model/entity/VideoFavour.java: -------------------------------------------------------------------------------- 1 | package com.zhu.model.entity; 2 | 3 | import com.baomidou.mybatisplus.annotation.IdType; 4 | import com.baomidou.mybatisplus.annotation.TableId; 5 | import com.baomidou.mybatisplus.annotation.TableName; 6 | import com.zhu.common.CommonEntity; 7 | import lombok.AllArgsConstructor; 8 | import lombok.Data; 9 | import lombok.NoArgsConstructor; 10 | 11 | import java.io.Serializable; 12 | import java.util.Date; 13 | 14 | /** 15 | *

16 | * 17 | *

18 | * 19 | * @author xiaozhu 20 | * @since 2023-10-31 21 | */ 22 | @TableName("t_video_favour") 23 | @Data 24 | @AllArgsConstructor 25 | @NoArgsConstructor 26 | public class VideoFavour extends CommonEntity implements Serializable { 27 | 28 | private static final long serialVersionUID = 1L; 29 | 30 | @TableId(value = "id", type = IdType.AUTO) 31 | private Long id; 32 | 33 | private Long videoId; 34 | 35 | private Long uid; 36 | 37 | } 38 | -------------------------------------------------------------------------------- /video-framework/src/main/java/com/zhu/model/entity/VideoInfo.java: -------------------------------------------------------------------------------- 1 | package com.zhu.model.entity; 2 | 3 | import com.baomidou.mybatisplus.annotation.IdType; 4 | import com.baomidou.mybatisplus.annotation.TableId; 5 | import com.baomidou.mybatisplus.annotation.TableName; 6 | import com.zhu.common.CommonEntity; 7 | import lombok.AllArgsConstructor; 8 | import lombok.Data; 9 | import lombok.NoArgsConstructor; 10 | 11 | import java.io.Serializable; 12 | 13 | /** 14 | *

15 | * 16 | *

17 | * 18 | * @author xiaozhu 19 | * @since 2023-10-24 20 | */ 21 | @TableName("t_video_info") 22 | @Data 23 | @AllArgsConstructor 24 | @NoArgsConstructor 25 | public class VideoInfo extends CommonEntity implements Serializable { 26 | 27 | private static final long serialVersionUID = 1L; 28 | 29 | @TableId(value = "video_id", type = IdType.AUTO) 30 | private Long videoId; 31 | 32 | private String description; 33 | 34 | private String videoUrl; 35 | 36 | private String videoPic; 37 | 38 | private Long typeId; 39 | 40 | // private Boolean isDraft; 41 | 42 | private Long playNum; 43 | 44 | private Long favourNum; 45 | 46 | private Long starNum; 47 | 48 | private Long commentNum; 49 | 50 | private Long shareNum; 51 | 52 | private Integer status; 53 | 54 | private Long uid; 55 | 56 | } 57 | -------------------------------------------------------------------------------- /video-framework/src/main/java/com/zhu/model/entity/VideoStar.java: -------------------------------------------------------------------------------- 1 | package com.zhu.model.entity; 2 | 3 | import com.baomidou.mybatisplus.annotation.IdType; 4 | import com.baomidou.mybatisplus.annotation.TableId; 5 | import com.baomidou.mybatisplus.annotation.TableName; 6 | import com.zhu.common.CommonEntity; 7 | import lombok.AllArgsConstructor; 8 | import lombok.Data; 9 | import lombok.NoArgsConstructor; 10 | 11 | import java.io.Serializable; 12 | import java.util.Date; 13 | 14 | /** 15 | *

16 | * 17 | *

18 | * 19 | * @author xiaozhu 20 | * @since 2023-10-27 21 | */ 22 | @TableName("t_video_star") 23 | @Data 24 | @AllArgsConstructor 25 | @NoArgsConstructor 26 | public class VideoStar extends CommonEntity implements Serializable { 27 | 28 | private static final long serialVersionUID = 1L; 29 | 30 | @TableId(value = "id", type = IdType.AUTO) 31 | private Long id; 32 | 33 | private Long videoId; 34 | 35 | private Long uid; 36 | 37 | 38 | } 39 | -------------------------------------------------------------------------------- /video-framework/src/main/java/com/zhu/model/enums/MessageTypeEnums.java: -------------------------------------------------------------------------------- 1 | package com.zhu.model.enums; 2 | 3 | import com.zhu.constant.MessageConstant; 4 | 5 | public enum MessageTypeEnums { 6 | 7 | FAVOUR("赞了你的视频",MessageConstant.MESSAGE_FAVOUR), 8 | STAR("收藏了你的视频",MessageConstant.MESSAGE_STAR), 9 | COMMENT("评论了你的视频",MessageConstant.MESSAGE_COMMENT), 10 | COMMENT_FAVOUR("点赞了你的评论",MessageConstant.MESSAGE_COMMENT_FAVOUR), 11 | COMMENT_REPLY("回复了你的评论",MessageConstant.MESSAGE_COMMENT_REPLY), 12 | FOLLOW("关注你了",MessageConstant.MESSAGE_FOLLOW); 13 | 14 | private String text; 15 | 16 | private Integer value; 17 | 18 | MessageTypeEnums(String text, Integer value) { 19 | this.text = text; 20 | this.value = value; 21 | } 22 | 23 | public Integer getValue() { 24 | return value; 25 | } 26 | 27 | public String getText() { 28 | return text; 29 | } 30 | 31 | public static MessageTypeEnums setCommentText(MessageTypeEnums messageTypeEnums, String text) { 32 | messageTypeEnums.text = text; 33 | return messageTypeEnums; 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /video-framework/src/main/java/com/zhu/model/enums/SearchTypeEnums.java: -------------------------------------------------------------------------------- 1 | package com.zhu.model.enums; 2 | 3 | import org.springframework.util.ObjectUtils; 4 | 5 | import java.util.Arrays; 6 | import java.util.List; 7 | import java.util.stream.Collectors; 8 | 9 | public enum SearchTypeEnums { 10 | 11 | SEARCH_all("综合","all"), 12 | SEARCH_USER("用户","user"), 13 | SEARCH_VIDEO("视频","video"); 14 | 15 | private final String text; 16 | 17 | private final String value; 18 | 19 | SearchTypeEnums(String text, String value) { 20 | this.text = text; 21 | this.value = value; 22 | } 23 | 24 | /** 25 | * 获取值列表 26 | * 27 | * @return 28 | */ 29 | public static List getValues() { 30 | return Arrays.stream(values()).map(item -> item.value).collect(Collectors.toList()); 31 | } 32 | 33 | /** 34 | * 根据 value 获取枚举 35 | * 36 | * @param value 37 | * @return 38 | */ 39 | public static SearchTypeEnums getEnumByValue(String value) { 40 | if (ObjectUtils.isEmpty(value)) { 41 | return null; 42 | } 43 | for (SearchTypeEnums anEnum : SearchTypeEnums.values()) { 44 | if (anEnum.value.equals(value)) { 45 | return anEnum; 46 | } 47 | } 48 | return null; 49 | } 50 | 51 | public String getValue() { 52 | return value; 53 | } 54 | 55 | public String getText() { 56 | return text; 57 | } 58 | 59 | 60 | } 61 | -------------------------------------------------------------------------------- /video-framework/src/main/java/com/zhu/model/enums/SortTypeEnums.java: -------------------------------------------------------------------------------- 1 | package com.zhu.model.enums; 2 | 3 | import org.springframework.util.ObjectUtils; 4 | 5 | import java.util.Arrays; 6 | import java.util.List; 7 | import java.util.stream.Collectors; 8 | 9 | public enum SortTypeEnums { 10 | 11 | SORT_COMPREHENSIVE("",0), 12 | SORT_PUBLISH_TIME("createTime",1), 13 | SORT_FAVOUR_NUM("favourNum",2); 14 | 15 | private final String text; 16 | 17 | private final Integer value; 18 | 19 | SortTypeEnums(String text, Integer value) { 20 | this.text = text; 21 | this.value = value; 22 | } 23 | 24 | /** 25 | * 获取值列表 26 | * 27 | * @return 28 | */ 29 | public static List getValues() { 30 | return Arrays.stream(values()).map(item -> item.value).collect(Collectors.toList()); 31 | } 32 | 33 | /** 34 | * 根据 value 获取枚举 35 | * 36 | * @param value 37 | * @return 38 | */ 39 | public static SortTypeEnums getEnumByValue(Integer value) { 40 | if (ObjectUtils.isEmpty(value)) { 41 | return null; 42 | } 43 | for (SortTypeEnums anEnum : SortTypeEnums.values()) { 44 | if (anEnum.value==value) { 45 | return anEnum; 46 | } 47 | } 48 | return null; 49 | } 50 | 51 | public Integer getValue() { 52 | return value; 53 | } 54 | 55 | public String getText() { 56 | return text; 57 | } 58 | 59 | 60 | } 61 | -------------------------------------------------------------------------------- /video-framework/src/main/java/com/zhu/model/enums/TimeScopeEnum.java: -------------------------------------------------------------------------------- 1 | package com.zhu.model.enums; 2 | 3 | import org.springframework.util.ObjectUtils; 4 | 5 | import java.util.Arrays; 6 | import java.util.List; 7 | import java.util.stream.Collectors; 8 | 9 | public enum TimeScopeEnum { 10 | 11 | TIME_ALL(0,0), 12 | TIME_ONE_DAY(-1,1), 13 | TIME_SEVEN_DAYS(-7,2), 14 | TIME_HALF_YEAR(-180,3); 15 | 16 | private final Integer time; 17 | 18 | private final Integer value; 19 | 20 | TimeScopeEnum(Integer time, Integer value) { 21 | this.time = time; 22 | this.value = value; 23 | } 24 | 25 | /** 26 | * 获取值列表 27 | * 28 | * @return 29 | */ 30 | public static List getValues() { 31 | return Arrays.stream(values()).map(item -> item.value).collect(Collectors.toList()); 32 | } 33 | 34 | /** 35 | * 根据 value 获取枚举 36 | * 37 | * @param value 38 | * @return 39 | */ 40 | public static TimeScopeEnum getEnumByValue(Integer value) { 41 | if (ObjectUtils.isEmpty(value)) { 42 | return null; 43 | } 44 | for (TimeScopeEnum anEnum : TimeScopeEnum.values()) { 45 | if (anEnum.value==value) { 46 | return anEnum; 47 | } 48 | } 49 | return null; 50 | } 51 | 52 | public Integer getValue() { 53 | return value; 54 | } 55 | 56 | public Integer getTime() { 57 | return time; 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /video-framework/src/main/java/com/zhu/model/enums/VideoTypeEnums.java: -------------------------------------------------------------------------------- 1 | package com.zhu.model.enums; 2 | 3 | import org.springframework.util.ObjectUtils; 4 | 5 | import java.util.Arrays; 6 | import java.util.List; 7 | import java.util.stream.Collectors; 8 | 9 | public enum VideoTypeEnums { 10 | 11 | VIDEO_STAR("收藏","star"), 12 | VIDEO_FAVOUR("喜欢","favour"), 13 | VIDEO_USER("作品","video"), 14 | VIDEO_HISTORY("浏览历史","history"); 15 | 16 | private final String text; 17 | 18 | private final String value; 19 | 20 | VideoTypeEnums(String text, String value) { 21 | this.text = text; 22 | this.value = value; 23 | } 24 | 25 | /** 26 | * 获取值列表 27 | * 28 | * @return 29 | */ 30 | public static List getValues() { 31 | return Arrays.stream(values()).map(item -> item.value).collect(Collectors.toList()); 32 | } 33 | 34 | /** 35 | * 根据 value 获取枚举 36 | * 37 | * @param value 38 | * @return 39 | */ 40 | public static VideoTypeEnums getEnumByValue(String value) { 41 | if (ObjectUtils.isEmpty(value)) { 42 | return null; 43 | } 44 | for (VideoTypeEnums anEnum : VideoTypeEnums.values()) { 45 | if (anEnum.value.equals(value)) { 46 | return anEnum; 47 | } 48 | } 49 | return null; 50 | } 51 | 52 | public String getValue() { 53 | return value; 54 | } 55 | 56 | public String getText() { 57 | return text; 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /video-framework/src/main/java/com/zhu/recommend/core/CoreMath.java: -------------------------------------------------------------------------------- 1 | package com.zhu.recommend.core; 2 | 3 | import com.zhu.model.entity.UserRating; 4 | 5 | import java.util.*; 6 | import java.util.stream.IntStream; 7 | 8 | /** 9 | * 核心算法 10 | * 11 | * @author tarzan 12 | * @version 1.0 13 | * @date 2020/7/31$ 15:21$ 14 | * @since JDK1.8 15 | */ 16 | public class CoreMath { 17 | 18 | 19 | 20 | /** 21 | * 计算相关系数并排序 22 | * @param key 23 | * @param map 24 | * @return Map 25 | */ 26 | public static Map computeNeighbor(Long key, Map> map, int type) { 27 | Map distMap = new TreeMap<>(); 28 | List userItems=map.get(key); 29 | map.forEach((k,v)->{ 30 | //排除此用户 31 | if(!k.equals(key)){ 32 | //关系系数 33 | double coefficient = relateDist(v,userItems,type); 34 | //关系距离 35 | // double distance=Math.abs(coefficient); 36 | distMap.put(k,coefficient); 37 | } 38 | }); 39 | return distMap; 40 | } 41 | 42 | 43 | /** 44 | * 计算两个序列间的相关系数 45 | * 46 | * @param xList 47 | * @param yList 48 | * @param type 类型0基于用户推荐 1基于物品推荐 49 | * @return double 50 | */ 51 | private static double relateDist(List xList, List yList, int type) { 52 | List xs= new ArrayList<>(); 53 | List ys= new ArrayList<>(); 54 | xList.forEach(x->{ 55 | yList.forEach(y->{ 56 | if(type==0){ 57 | if(x.getVideoId().equals(y.getVideoId())){ 58 | xs.add(x.getRate()); 59 | ys.add(y.getRate()); 60 | } 61 | }else{ 62 | if(x.getUid().equals(y.getUid())){ 63 | xs.add(x.getRate()); 64 | ys.add(y.getRate()); 65 | } 66 | } 67 | }); 68 | }); 69 | return getRelate(xs,ys); 70 | } 71 | 72 | /** 73 | * 方法描述: 皮尔森(pearson)相关系数计算 74 | * 75 | * @param xs x集合 76 | * @param ys y集合 77 | * @Return {@link double} 78 | * @author tarzan 79 | * @date 2020年07月31日 17:03:20 80 | */ 81 | public static double getRelate(List xs, List ys){ 82 | int n=xs.size(); 83 | //至少有两个元素 84 | if (n<2) { 85 | return 0D; 86 | } 87 | double Ex= xs.stream().mapToDouble(x->x).sum(); 88 | double Ey=ys.stream().mapToDouble(y->y).sum(); 89 | double Ex2=xs.stream().mapToDouble(x-> Math.pow(x,2)).sum(); 90 | double Ey2=ys.stream().mapToDouble(y-> Math.pow(y,2)).sum(); 91 | double Exy= IntStream.range(0,n).mapToDouble(i->xs.get(i)*ys.get(i)).sum(); 92 | double numerator=Exy-Ex*Ey/n; 93 | double denominator= Math.sqrt((Ex2- Math.pow(Ex,2)/n)*(Ey2- Math.pow(Ey,2)/n)); 94 | if (denominator==0) { 95 | return 0D; 96 | } 97 | return numerator/denominator; 98 | } 99 | 100 | } 101 | -------------------------------------------------------------------------------- /video-framework/src/main/java/com/zhu/recommend/core/ItemCF.java: -------------------------------------------------------------------------------- 1 | package com.zhu.recommend.core; 2 | 3 | import com.zhu.model.entity.UserRating; 4 | 5 | import java.util.Collections; 6 | import java.util.List; 7 | import java.util.Map; 8 | import java.util.stream.Collectors; 9 | 10 | /** 11 | * 核心算法 12 | * 13 | * @author tarzan 14 | * @version 1.0 15 | * @date 2020/7/31$ 15:21$ 16 | * @since JDK1.8 17 | */ 18 | public class ItemCF { 19 | 20 | /** 21 | * 方法描述: 推荐电影id列表 22 | * 23 | * @param itemId 当前电影id 24 | * @param list 用户电影评分数据 25 | * @return {@link List < Integer >} 26 | * @date 2023年02月02日 14:51:42 27 | */ 28 | public static List recommend(Long itemId, List list) { 29 | //按物品分组 30 | Map> itemMap=list.stream().collect(Collectors.groupingBy(UserRating::getVideoId)); 31 | //获取其他物品与当前物品的关系值 32 | Map itemDisMap = CoreMath.computeNeighbor(itemId, itemMap,1); 33 | //获取关系最近物品 34 | double maxValue= Collections.max(itemDisMap.values()); 35 | return itemDisMap.entrySet().stream().filter(e->e.getValue()==maxValue).map(Map.Entry::getKey).collect(Collectors.toList()); 36 | } 37 | 38 | 39 | } 40 | -------------------------------------------------------------------------------- /video-framework/src/main/java/com/zhu/recommend/core/UserCF.java: -------------------------------------------------------------------------------- 1 | package com.zhu.recommend.core; 2 | 3 | import com.zhu.model.entity.UserRating; 4 | 5 | import java.util.Collections; 6 | import java.util.List; 7 | import java.util.Map; 8 | import java.util.Set; 9 | import java.util.stream.Collectors; 10 | 11 | /** 12 | * 核心算法 13 | * 14 | * @author tarzan 15 | * @version 1.0 16 | * @date 2020/7/31$ 15:21$ 17 | * @since JDK1.8 18 | */ 19 | public class UserCF { 20 | 21 | /** 22 | * 方法描述: 推荐电影id列表 23 | * 24 | * @param userId 当前用户 25 | * @param list 用户电影评分数据 26 | * @return {@link List < Integer >} 27 | * @date 2023年02月02日 14:51:42 28 | */ 29 | public static List recommend(Long userId, List list) { 30 | //按用户分组 31 | Map> userMap=list.stream().collect(Collectors.groupingBy(UserRating::getUid)); 32 | //获取其他用户与当前用户的关系值 33 | Map userDisMap = CoreMath.computeNeighbor(userId, userMap,0); 34 | //获取关系最近的用户 35 | double maxValue= Collections.max(userDisMap.values()); 36 | Set userIds=userDisMap.entrySet().stream().filter(e->e.getValue()==maxValue).map(Map.Entry::getKey).collect(Collectors.toSet()); 37 | //取关系最近的用户 38 | Long nearestUserId = userIds.stream().findAny().orElse(null); 39 | if(nearestUserId==null){ 40 | return Collections.emptyList(); 41 | } 42 | //最近邻用户看过电影列表 43 | List neighborItems = userMap.get(nearestUserId).stream().map(UserRating::getVideoId).collect(Collectors.toList()); 44 | //指定用户看过电影列表 45 | List userItems = userMap.get(userId).stream().map(UserRating::getVideoId).collect(Collectors.toList()); 46 | //找到最近邻看过,但是该用户没看过的电影 47 | neighborItems.removeAll(userItems); 48 | return neighborItems; 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /video-framework/src/main/java/com/zhu/result/RespBean.java: -------------------------------------------------------------------------------- 1 | package com.zhu.result; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | @Data 8 | @AllArgsConstructor 9 | @NoArgsConstructor 10 | public class RespBean { 11 | 12 | private Integer code; 13 | 14 | private String msg; 15 | 16 | private Object obj; 17 | 18 | public static RespBean success(Object data) { 19 | return new RespBean(RespBeanEnum.SUCCESS.getCode(), RespBeanEnum.SUCCESS.getMsg(), data); 20 | } 21 | 22 | public static RespBean error(RespBeanEnum respBeanEnum, Object data) { 23 | return new RespBean(respBeanEnum.getCode(), respBeanEnum.getMsg(), data); 24 | } 25 | 26 | public static RespBean error(RespBeanEnum respBeanEnum) { 27 | return new RespBean(respBeanEnum.getCode(), respBeanEnum.getMsg(), null); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /video-framework/src/main/java/com/zhu/result/RespBeanEnum.java: -------------------------------------------------------------------------------- 1 | package com.zhu.result; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Getter; 5 | 6 | @Getter 7 | @AllArgsConstructor 8 | public enum RespBeanEnum { 9 | 10 | SUCCESS(200, "success"), 11 | ERROR(500, "服务器异常"), 12 | ACTION_ERROR(600, "操作失败"), 13 | 14 | Login_ERROR(400, "登录失败"), 15 | 16 | FORBIDDEN(403, "权限不足"), 17 | UNAUTHORIZED(401, ""), 18 | 19 | TOKEN_OVER(10010, "token已过期"), 20 | PARAM_ERROR(10011,"参数错误"), 21 | 22 | Captcha_OVER(10020, "验证码过期"), 23 | Captcha_ERROR(10021, "验证码错误"), 24 | 25 | USERNAME_PASSWORD(10030, "用户名或密码不正确"), 26 | PASSWORD(10031, "原密码错误"), 27 | USER_NO(10032, "用户不存在"), 28 | PASSWORD_NO_MATCH(10033,"两次密码不一致"), 29 | EMAIL_NO_REGISTER(10034,"该邮箱未注册"), 30 | USER_STATUS_PROHIBIT(10036,"该账号已被封禁"), 31 | USER_UN_LOGIN(10037,"未登录"), 32 | USER_NO_AUTH(10038,"未登录,无权限访问"), 33 | USER_NEED_LOGIN(10039,"登录查看更多内容"), 34 | 35 | EMAIL_EXIST(10034,"该邮箱已注册"), 36 | 37 | QUESTION_NO_EXIST(10051,"该提问不存在"), 38 | 39 | TYPE_EXIST(10061,"该标签已存在"), 40 | 41 | FILE_NOT_EXIST(10071,"文件不存在"), 42 | 43 | TestACTION_ERROR(666, "演示环境,不允许操作"); 44 | 45 | private final Integer code; 46 | 47 | private final String msg; 48 | 49 | } 50 | -------------------------------------------------------------------------------- /video-framework/src/main/java/com/zhu/service/ICommentFavourService.java: -------------------------------------------------------------------------------- 1 | package com.zhu.service; 2 | 3 | import com.baomidou.mybatisplus.extension.service.IService; 4 | import com.zhu.model.entity.CommentFavour; 5 | 6 | /** 7 | *

8 | * 服务类 9 | *

10 | * 11 | * @author xiaozhu 12 | * @since 2023-10-31 13 | */ 14 | public interface ICommentFavourService extends IService { 15 | 16 | } 17 | -------------------------------------------------------------------------------- /video-framework/src/main/java/com/zhu/service/ICommentService.java: -------------------------------------------------------------------------------- 1 | package com.zhu.service; 2 | 3 | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; 4 | import com.baomidou.mybatisplus.extension.service.IService; 5 | import com.zhu.model.dto.comment.CommentAddRequest; 6 | import com.zhu.model.dto.comment.CommentReplyRequest; 7 | import com.zhu.model.entity.Comment; 8 | import com.zhu.model.entity.CommentFavour; 9 | import com.zhu.vo.CommentVo; 10 | 11 | import javax.servlet.http.HttpServletRequest; 12 | import java.util.List; 13 | 14 | /** 15 | *

16 | * 服务类 17 | *

18 | * 19 | * @author xiaozhu 20 | * @since 2023-10-27 21 | */ 22 | public interface ICommentService extends IService { 23 | 24 | List getVideoComment(Long videoId); 25 | 26 | Page getMoreReply(CommentReplyRequest commentReplyRequest); 27 | 28 | int doFavour(CommentFavour commentFavour); 29 | 30 | List getCommentLikesList(Long videoId, Long uid); 31 | 32 | int doCommentFavourInner(CommentFavour commentFavour,Long authorId); 33 | 34 | Comment addComment(CommentAddRequest commentAddRequest, HttpServletRequest request, Long uid); 35 | 36 | int delComment(Comment comment, Long delCommentId); 37 | 38 | } 39 | -------------------------------------------------------------------------------- /video-framework/src/main/java/com/zhu/service/IDanmuService.java: -------------------------------------------------------------------------------- 1 | package com.zhu.service; 2 | 3 | import com.baomidou.mybatisplus.extension.service.IService; 4 | import com.zhu.model.entity.Danmu; 5 | 6 | /** 7 | *

8 | * 服务类 9 | *

10 | * 11 | * @author xiaozhu 12 | * @since 2023-11-14 13 | */ 14 | public interface IDanmuService extends IService { 15 | 16 | } 17 | -------------------------------------------------------------------------------- /video-framework/src/main/java/com/zhu/service/IMessageService.java: -------------------------------------------------------------------------------- 1 | package com.zhu.service; 2 | 3 | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; 4 | import com.baomidou.mybatisplus.extension.service.IService; 5 | import com.zhu.model.entity.Message; 6 | import com.zhu.vo.MessageTypeVo; 7 | import com.zhu.vo.MessageVo; 8 | 9 | /** 10 | *

11 | * 服务类 12 | *

13 | * 14 | * @author xiaozhu 15 | * @since 2023-11-13 16 | */ 17 | public interface IMessageService extends IService { 18 | 19 | int updateDelivered(Long uid, String type); 20 | 21 | int getUnReadNumber(Long uid); 22 | 23 | Page getMessageVoList(Page messagePage,Integer[] messageTypes,Long receiverId); 24 | 25 | MessageTypeVo getUnReadMessageByType(Long uid); 26 | 27 | } 28 | -------------------------------------------------------------------------------- /video-framework/src/main/java/com/zhu/service/ITypeService.java: -------------------------------------------------------------------------------- 1 | package com.zhu.service; 2 | 3 | import com.baomidou.mybatisplus.extension.service.IService; 4 | import com.zhu.model.entity.Type; 5 | 6 | /** 7 | *

8 | * 服务类 9 | *

10 | * 11 | * @author xiaozhu 12 | * @since 2023-10-29 13 | */ 14 | public interface ITypeService extends IService { 15 | 16 | } 17 | -------------------------------------------------------------------------------- /video-framework/src/main/java/com/zhu/service/IUserBrowseService.java: -------------------------------------------------------------------------------- 1 | package com.zhu.service; 2 | 3 | import com.baomidou.mybatisplus.extension.service.IService; 4 | import com.zhu.model.entity.UserBrowse; 5 | 6 | /** 7 | *

8 | * 服务类 9 | *

10 | * 11 | * @author xiaozhu 12 | * @since 2023-12-04 13 | */ 14 | public interface IUserBrowseService extends IService { 15 | 16 | int actionBrowse(Long videoId,Long uid); 17 | 18 | } 19 | -------------------------------------------------------------------------------- /video-framework/src/main/java/com/zhu/service/IUserFollowService.java: -------------------------------------------------------------------------------- 1 | package com.zhu.service; 2 | 3 | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; 4 | import com.baomidou.mybatisplus.extension.service.IService; 5 | import com.zhu.model.dto.user.UserFollowFansRequest; 6 | import com.zhu.model.entity.User; 7 | import com.zhu.model.entity.UserFollow; 8 | 9 | import java.util.List; 10 | import java.util.Map; 11 | 12 | /** 13 | *

14 | * 服务类 15 | *

16 | * 17 | * @author xiaozhu 18 | * @since 2023-11-02 19 | */ 20 | public interface IUserFollowService extends IService { 21 | 22 | int doFollow(Long followId, Long uid); 23 | 24 | Map> getUserFollowIds(Long uid); 25 | 26 | List getUserFansIds(Long uid); 27 | 28 | Page getUserFollowFans(UserFollowFansRequest userFollowFansRequest, Long uid); 29 | 30 | } 31 | -------------------------------------------------------------------------------- /video-framework/src/main/java/com/zhu/service/IUserRatingService.java: -------------------------------------------------------------------------------- 1 | package com.zhu.service; 2 | 3 | import com.baomidou.mybatisplus.extension.service.IService; 4 | import com.zhu.model.entity.UserRating; 5 | 6 | /** 7 | *

8 | * 服务类 9 | *

10 | * 11 | * @author xiaozhu 12 | * @since 2023-12-05 13 | */ 14 | public interface IUserRatingService extends IService { 15 | 16 | } 17 | -------------------------------------------------------------------------------- /video-framework/src/main/java/com/zhu/service/IUserService.java: -------------------------------------------------------------------------------- 1 | package com.zhu.service; 2 | 3 | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; 4 | import com.baomidou.mybatisplus.extension.service.IService; 5 | import com.zhu.model.dto.user.UserLoginRequest; 6 | import com.zhu.model.dto.user.UserRegisterRequest; 7 | import com.zhu.model.entity.User; 8 | import com.zhu.vo.AuthorInfoVo; 9 | import com.zhu.vo.LoginUserVo; 10 | import com.zhu.vo.UserVo; 11 | 12 | import javax.servlet.http.HttpServletRequest; 13 | 14 | /** 15 | *

16 | * 服务类 17 | *

18 | * 19 | * @author xiaozhu 20 | * @since 2023-10-25 21 | */ 22 | public interface IUserService extends IService { 23 | 24 | LoginUserVo login(UserLoginRequest userLoginRequest, HttpServletRequest request); 25 | 26 | LoginUserVo getLoginUser(HttpServletRequest request); 27 | 28 | Long register(UserRegisterRequest userRegisterRequest); 29 | 30 | void sendCaptcha(String toEmail); 31 | 32 | Page searchUser(String searchText, long pageNum, long pageSize); 33 | 34 | AuthorInfoVo getUserInfo(Long uid); 35 | 36 | User getUserBasicInfo(Long uid); 37 | 38 | boolean userLogout(HttpServletRequest request); 39 | 40 | } 41 | -------------------------------------------------------------------------------- /video-framework/src/main/java/com/zhu/service/IVideoFavourService.java: -------------------------------------------------------------------------------- 1 | package com.zhu.service; 2 | 3 | import com.baomidou.mybatisplus.extension.service.IService; 4 | import com.zhu.model.entity.VideoFavour; 5 | import com.zhu.model.entity.VideoInfo; 6 | 7 | import java.util.List; 8 | 9 | /** 10 | *

11 | * 服务类 12 | *

13 | * 14 | * @author xiaozhu 15 | * @since 2023-10-31 16 | */ 17 | public interface IVideoFavourService extends IService { 18 | 19 | int doVideoFavour(Long videoId,Long uid); 20 | 21 | int doVideoFavourInner(Long videoId,Long uid,Long authorId); 22 | 23 | List getUserFavourVideo(Long uid); 24 | 25 | } 26 | -------------------------------------------------------------------------------- /video-framework/src/main/java/com/zhu/service/IVideoInfoService.java: -------------------------------------------------------------------------------- 1 | package com.zhu.service; 2 | 3 | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; 4 | import com.baomidou.mybatisplus.extension.service.IService; 5 | import com.zhu.model.dto.search.SearchRequest; 6 | import com.zhu.model.dto.video.VideoRecommendRequest; 7 | import com.zhu.model.dto.video.VideoTypeRequest; 8 | import com.zhu.model.entity.VideoInfo; 9 | import com.zhu.vo.VideoVo; 10 | 11 | import javax.servlet.http.HttpServletRequest; 12 | 13 | /** 14 | *

15 | * 服务类 16 | *

17 | * 18 | * @author xiaozhu 19 | * @since 2023-10-24 20 | */ 21 | public interface IVideoInfoService extends IService { 22 | 23 | Page getVideoVoListByType(VideoTypeRequest videoTypeRequest, HttpServletRequest request); 24 | 25 | Page searchFromES(SearchRequest searchRequest); 26 | 27 | Page getVideoVoOther(Page videoVoPage,boolean isOnlyAuthorInfo, HttpServletRequest request); 28 | 29 | VideoVo getVideoVo(VideoInfo videoInfo, HttpServletRequest request); 30 | 31 | Page getVideoByRandom(VideoRecommendRequest videoRecommendRequest, HttpServletRequest request); 32 | 33 | Page getHotVideoWithTopK(int k, HttpServletRequest request); 34 | 35 | Page getVideoByFollow(Long uid, HttpServletRequest request); 36 | 37 | } 38 | -------------------------------------------------------------------------------- /video-framework/src/main/java/com/zhu/service/IVideoStarService.java: -------------------------------------------------------------------------------- 1 | package com.zhu.service; 2 | 3 | import com.baomidou.mybatisplus.extension.service.IService; 4 | import com.zhu.model.entity.VideoInfo; 5 | import com.zhu.model.entity.VideoStar; 6 | 7 | import java.util.List; 8 | 9 | /** 10 | *

11 | * 服务类 12 | *

13 | * 14 | * @author xiaozhu 15 | * @since 2023-10-27 16 | */ 17 | public interface IVideoStarService extends IService { 18 | 19 | int doVideoStar(Long videoId, Long uid); 20 | 21 | int doVideoStarInner(Long videoId, Long uid, Long authorId); 22 | 23 | List getUserStarVideo(Long uid); 24 | 25 | } 26 | -------------------------------------------------------------------------------- /video-framework/src/main/java/com/zhu/service/impl/CommentFavourServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.zhu.service.impl; 2 | 3 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 4 | import com.zhu.mapper.CommentFavourMapper; 5 | import com.zhu.model.entity.CommentFavour; 6 | import com.zhu.service.ICommentFavourService; 7 | import org.springframework.stereotype.Service; 8 | 9 | /** 10 | *

11 | * 服务实现类 12 | *

13 | * 14 | * @author xiaozhu 15 | * @since 2023-10-31 16 | */ 17 | @Service 18 | public class CommentFavourServiceImpl extends ServiceImpl implements ICommentFavourService { 19 | 20 | } 21 | -------------------------------------------------------------------------------- /video-framework/src/main/java/com/zhu/service/impl/DanmuServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.zhu.service.impl; 2 | 3 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 4 | import com.zhu.mapper.DanmuMapper; 5 | import com.zhu.model.entity.Danmu; 6 | import com.zhu.service.IDanmuService; 7 | import org.springframework.stereotype.Service; 8 | 9 | /** 10 | *

11 | * 服务实现类 12 | *

13 | * 14 | * @author xiaozhu 15 | * @since 2023-11-14 16 | */ 17 | @Service 18 | public class DanmuServiceImpl extends ServiceImpl implements IDanmuService { 19 | 20 | } 21 | -------------------------------------------------------------------------------- /video-framework/src/main/java/com/zhu/service/impl/TypeServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.zhu.service.impl; 2 | 3 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 4 | import com.zhu.mapper.TypeMapper; 5 | import com.zhu.model.entity.Type; 6 | import com.zhu.service.ITypeService; 7 | import org.springframework.stereotype.Service; 8 | 9 | /** 10 | *

11 | * 服务实现类 12 | *

13 | * 14 | * @author xiaozhu 15 | * @since 2023-10-29 16 | */ 17 | @Service 18 | public class TypeServiceImpl extends ServiceImpl implements ITypeService { 19 | 20 | } 21 | -------------------------------------------------------------------------------- /video-framework/src/main/java/com/zhu/service/impl/UserBrowseServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.zhu.service.impl; 2 | 3 | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; 4 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 5 | import com.zhu.constant.RedisConstant; 6 | import com.zhu.mapper.UserBrowseMapper; 7 | import com.zhu.model.entity.UserBrowse; 8 | import com.zhu.service.IUserBrowseService; 9 | import com.zhu.utils.RedisUtils; 10 | import org.springframework.stereotype.Service; 11 | 12 | import javax.annotation.Resource; 13 | import java.util.Date; 14 | 15 | /** 16 | *

17 | * 服务实现类 18 | *

19 | * 20 | * @author xiaozhu 21 | * @since 2023-12-04 22 | */ 23 | @Service 24 | public class UserBrowseServiceImpl extends ServiceImpl implements IUserBrowseService { 25 | 26 | @Resource 27 | private RedisUtils redisUtils; 28 | 29 | @Override 30 | public int actionBrowse(Long videoId, Long uid) { 31 | QueryWrapper userBrowseQueryWrapper = new QueryWrapper<>(); 32 | userBrowseQueryWrapper.eq("video_id",videoId); 33 | userBrowseQueryWrapper.eq("uid",uid); 34 | UserBrowse userBrowse = getOne(userBrowseQueryWrapper); 35 | boolean result; 36 | if(userBrowse!=null){ 37 | userBrowse.setBrowseTime(new Date()); 38 | result = updateById(userBrowse); 39 | }else{ 40 | userBrowse = new UserBrowse(); 41 | userBrowse.setVideoId(videoId); 42 | userBrowse.setUid(uid); 43 | result = save(userBrowse); 44 | } 45 | //将该视频浏览量加一,并且需要更新浏览记录 46 | redisUtils.hincr(RedisConstant.VideoPlayNumKey,String.valueOf(videoId), RedisConstant.incrNum); 47 | return result?1:0; 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /video-framework/src/main/java/com/zhu/service/impl/UserRatingServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.zhu.service.impl; 2 | 3 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 4 | import com.zhu.mapper.UserRatingMapper; 5 | import com.zhu.model.entity.UserRating; 6 | import com.zhu.service.IUserRatingService; 7 | import org.springframework.stereotype.Service; 8 | 9 | /** 10 | *

11 | * 服务实现类 12 | *

13 | * 14 | * @author xiaozhu 15 | * @since 2023-12-05 16 | */ 17 | @Service 18 | public class UserRatingServiceImpl extends ServiceImpl implements IUserRatingService { 19 | 20 | } 21 | -------------------------------------------------------------------------------- /video-framework/src/main/java/com/zhu/utils/AddressUtils.java: -------------------------------------------------------------------------------- 1 | package com.zhu.utils; 2 | 3 | import com.fasterxml.jackson.databind.ObjectMapper; 4 | import lombok.extern.slf4j.Slf4j; 5 | import okhttp3.OkHttpClient; 6 | import okhttp3.Request; 7 | import okhttp3.Response; 8 | 9 | import java.util.Map; 10 | 11 | @Slf4j 12 | public class AddressUtils { 13 | 14 | public static Map getAddress(String ip) { 15 | OkHttpClient httpClient = new OkHttpClient(); 16 | // String ip = "172.24.99.10"; 17 | Map resultMap = null; 18 | String url = "http://whois.pconline.com.cn/ipJson.jsp?ip=" + ip + "&json=true"; 19 | Request request = new Request.Builder() 20 | .url(url) 21 | .build(); 22 | try { 23 | Response response = httpClient.newCall(request).execute(); 24 | String result = response.body().string(); 25 | ObjectMapper objectMapper = new ObjectMapper(); 26 | resultMap = objectMapper.readValue(result, Map.class); 27 | // System.out.println("ip信息:" + resultMap); 28 | } catch (Exception e) { 29 | e.printStackTrace(); 30 | } 31 | return resultMap; 32 | } 33 | 34 | public static void main(String[] args) { 35 | System.out.println(getAddress("125.117.20.94")); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /video-framework/src/main/java/com/zhu/utils/BeanCopeUtils.java: -------------------------------------------------------------------------------- 1 | package com.zhu.utils; 2 | 3 | import org.springframework.beans.BeanUtils; 4 | 5 | import java.util.List; 6 | import java.util.stream.Collectors; 7 | 8 | //拷贝bean的工具类 9 | public class BeanCopeUtils { 10 | private BeanCopeUtils() {} 11 | 12 | //单个类拷贝 13 | public static V copyBean(Object source,Class clazz) { 14 | 15 | //创建目标对象 16 | V result = null; 17 | try { 18 | result = clazz.newInstance(); 19 | //实现属性copy 20 | BeanUtils.copyProperties(source, result); 21 | } catch (Exception e) { 22 | e.printStackTrace(); 23 | } 24 | //返回结果 25 | return result; 26 | } 27 | 28 | //集合拷贝 29 | public static List copyBeanList(List list,Class clazz){ 30 | return list.stream() 31 | .map(o -> copyBean(o, clazz)) 32 | .collect(Collectors.toList()); 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /video-framework/src/main/java/com/zhu/utils/MessageUtils.java: -------------------------------------------------------------------------------- 1 | package com.zhu.utils; 2 | 3 | import com.zhu.constant.MQConstant; 4 | import com.zhu.model.entity.Message; 5 | import com.zhu.model.entity.VideoInfo; 6 | import com.zhu.model.enums.MessageTypeEnums; 7 | import org.springframework.amqp.rabbit.core.RabbitTemplate; 8 | import org.springframework.stereotype.Component; 9 | 10 | import javax.annotation.Resource; 11 | 12 | @Component 13 | public class MessageUtils { 14 | 15 | @Resource 16 | private RabbitTemplate rabbitTemplate; 17 | 18 | public void sendMessageToUser(Long senderId,Long receiverId,Long videoId,MessageTypeEnums messageTypeEnums){ 19 | //如果发送方和接受方的id一致,那么就不需要发送互动消息提示 20 | if(!receiverId.equals(senderId)){ 21 | Message message = handlerMessage(senderId, receiverId, videoId, messageTypeEnums); 22 | rabbitTemplate.convertAndSend(MQConstant.VIDEO_TOPIC,MQConstant.MESSAGE_QUEUE,message); 23 | } 24 | } 25 | 26 | public void updateESData(VideoInfo videoInfo){ 27 | rabbitTemplate.convertAndSend(MQConstant.VIDEO_TOPIC,MQConstant.ES_QUEUE,videoInfo); 28 | } 29 | 30 | /** 31 | * 处理传递过来的参数,将他转换成一个实体类 32 | * @param senderId 33 | * @param receiverId 34 | * @param messageTypeEnums 35 | * @return 36 | */ 37 | public static Message handlerMessage(Long senderId,Long receiverId,Long videoId,MessageTypeEnums messageTypeEnums){ 38 | Message message = new Message(); 39 | message.setMessageType(messageTypeEnums.getValue()); 40 | message.setSenderId(senderId); 41 | message.setReceiverId(receiverId); 42 | message.setVideoId(videoId); 43 | message.setMessageContent(messageTypeEnums.getText()); 44 | return message; 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /video-framework/src/main/java/com/zhu/vo/AuthorInfoVo.java: -------------------------------------------------------------------------------- 1 | package com.zhu.vo; 2 | 3 | import lombok.Data; 4 | 5 | import java.io.Serializable; 6 | 7 | @Data 8 | public class AuthorInfoVo extends UserVo implements Serializable { 9 | 10 | private static final long serialVersionUID = 1L; 11 | 12 | //是否隐藏喜欢列表 13 | private Boolean isHiddenFavour; 14 | 15 | //发布作品数量 16 | private Long worksNum; 17 | 18 | //喜欢作品数量 19 | private Long favoursNum; 20 | 21 | } 22 | -------------------------------------------------------------------------------- /video-framework/src/main/java/com/zhu/vo/CommentVo.java: -------------------------------------------------------------------------------- 1 | package com.zhu.vo; 2 | 3 | import com.zhu.model.entity.Comment; 4 | import com.zhu.model.entity.User; 5 | import lombok.Data; 6 | 7 | import java.util.List; 8 | 9 | @Data 10 | public class CommentVo extends Comment { 11 | 12 | private boolean isFold; 13 | 14 | private User user; 15 | 16 | private List likeList; 17 | 18 | private ReplyVo replyVo; 19 | 20 | } 21 | -------------------------------------------------------------------------------- /video-framework/src/main/java/com/zhu/vo/LoginUserVo.java: -------------------------------------------------------------------------------- 1 | package com.zhu.vo; 2 | 3 | import com.fasterxml.jackson.annotation.JsonFormat; 4 | import lombok.Data; 5 | 6 | import java.io.Serializable; 7 | import java.util.Date; 8 | 9 | @Data 10 | public class LoginUserVo implements Serializable { 11 | 12 | @JsonFormat(shape = JsonFormat.Shape.STRING) 13 | private Long uid; 14 | 15 | private String userNickname; 16 | 17 | private String userAvatar; 18 | 19 | private Integer sex; 20 | 21 | private String userRole; 22 | 23 | private Date createTime; 24 | 25 | private Date updateTime; 26 | 27 | } 28 | -------------------------------------------------------------------------------- /video-framework/src/main/java/com/zhu/vo/MessageTypeVo.java: -------------------------------------------------------------------------------- 1 | package com.zhu.vo; 2 | 3 | import lombok.Data; 4 | 5 | import java.io.Serializable; 6 | 7 | @Data 8 | public class MessageTypeVo implements Serializable { 9 | 10 | private boolean hasCommentsMessage; 11 | 12 | private boolean hasLikesMessage; 13 | 14 | private boolean hasFollowsMessage; 15 | 16 | } 17 | -------------------------------------------------------------------------------- /video-framework/src/main/java/com/zhu/vo/MessageVideoVo.java: -------------------------------------------------------------------------------- 1 | package com.zhu.vo; 2 | 3 | import lombok.Data; 4 | 5 | import java.io.Serializable; 6 | 7 | @Data 8 | public class MessageVideoVo implements Serializable { 9 | 10 | private Long videoId; 11 | 12 | private String description; 13 | 14 | private String videoPic; 15 | 16 | } 17 | -------------------------------------------------------------------------------- /video-framework/src/main/java/com/zhu/vo/MessageVo.java: -------------------------------------------------------------------------------- 1 | package com.zhu.vo; 2 | 3 | import com.zhu.model.entity.Message; 4 | import com.zhu.model.entity.User; 5 | import lombok.Data; 6 | 7 | import java.io.Serializable; 8 | 9 | @Data 10 | public class MessageVo extends Message implements Serializable { 11 | 12 | private static final long serialVersionUID = 1L; 13 | 14 | private User user; 15 | 16 | private MessageVideoVo messageVideo; 17 | 18 | } 19 | -------------------------------------------------------------------------------- /video-framework/src/main/java/com/zhu/vo/ReplyVo.java: -------------------------------------------------------------------------------- 1 | package com.zhu.vo; 2 | 3 | import com.zhu.model.entity.Comment; 4 | import lombok.Data; 5 | 6 | import java.util.Collections; 7 | import java.util.List; 8 | 9 | @Data 10 | public class ReplyVo { 11 | 12 | private Long id; 13 | 14 | private Integer total; 15 | 16 | private List replies = Collections.EMPTY_LIST; 17 | 18 | } 19 | -------------------------------------------------------------------------------- /video-framework/src/main/java/com/zhu/vo/SearchVo.java: -------------------------------------------------------------------------------- 1 | package com.zhu.vo; 2 | 3 | import lombok.Data; 4 | 5 | import java.io.Serializable; 6 | import java.util.List; 7 | 8 | @Data 9 | public class SearchVo implements Serializable { 10 | 11 | private List userList; 12 | 13 | private List videoList; 14 | 15 | private List dataList; 16 | 17 | private static final long serialVersionUID = 1L; 18 | 19 | } 20 | -------------------------------------------------------------------------------- /video-framework/src/main/java/com/zhu/vo/UserVo.java: -------------------------------------------------------------------------------- 1 | package com.zhu.vo; 2 | 3 | import com.fasterxml.jackson.annotation.JsonFormat; 4 | import lombok.Data; 5 | 6 | import java.io.Serializable; 7 | 8 | @Data 9 | public class UserVo implements Serializable { 10 | 11 | private static final long serialVersionUID = 1L; 12 | 13 | @JsonFormat(shape = JsonFormat.Shape.STRING) 14 | private Long uid; 15 | 16 | private String userEmail; 17 | 18 | private String userNickname; 19 | 20 | private String userAvatar; 21 | 22 | private String userProfile; 23 | 24 | private Integer sex; 25 | 26 | private Long follows; 27 | 28 | private Long fans; 29 | 30 | private Long favourTotal; 31 | 32 | private String userRole; 33 | 34 | } 35 | -------------------------------------------------------------------------------- /video-framework/src/main/java/com/zhu/vo/VideoVo.java: -------------------------------------------------------------------------------- 1 | package com.zhu.vo; 2 | 3 | import com.zhu.model.entity.User; 4 | import com.zhu.model.entity.VideoInfo; 5 | import lombok.Data; 6 | 7 | @Data 8 | public class VideoVo extends VideoInfo { 9 | 10 | private boolean isStar; 11 | 12 | private boolean isFavour; 13 | 14 | private User user; 15 | 16 | @Override 17 | public String toString() { 18 | return "VideoVo{" + 19 | "isStar=" + isStar + 20 | ", isFavour=" + isFavour + 21 | ", user=" + user + 22 | "} " + super.toString(); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /video-framework/src/main/resources/mapper/CommentFavourMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /video-framework/src/main/resources/mapper/CommentMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 11 | 12 | 17 | 18 | 24 | 25 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /video-framework/src/main/resources/mapper/DanmuMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /video-framework/src/main/resources/mapper/MessageMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 14 | 15 | 20 | 21 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /video-framework/src/main/resources/mapper/TypeMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /video-framework/src/main/resources/mapper/UserBrowseMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /video-framework/src/main/resources/mapper/UserFollowMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /video-framework/src/main/resources/mapper/UserMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 9 | 10 | 14 | 15 | 19 | 20 | 24 | 25 | 29 | 30 | 34 | 35 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | -------------------------------------------------------------------------------- /video-framework/src/main/resources/mapper/UserRatingMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 8 | 9 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /video-framework/src/main/resources/mapper/VideoFavourMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /video-framework/src/main/resources/mapper/VideoInfoMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 12 | 13 | 17 | 18 | 19 | 24 | 25 | 26 | 29 | 30 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 51 | 52 | 53 | -------------------------------------------------------------------------------- /video-framework/src/main/resources/mapper/VideoStarMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /video-framework/src/test/java/com/zhu/VideoFrameworkApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.zhu; 2 | 3 | import cn.hutool.core.util.RandomUtil; 4 | import com.zhu.model.entity.User; 5 | import com.zhu.service.IUserService; 6 | import org.junit.jupiter.api.Test; 7 | import org.springframework.boot.test.context.SpringBootTest; 8 | 9 | import javax.annotation.Resource; 10 | import java.util.ArrayList; 11 | import java.util.List; 12 | 13 | @SpringBootTest 14 | class VideoFrameworkApplicationTests { 15 | 16 | // @Resource 17 | // private IUserService userService; 18 | // 19 | // @Test 20 | // void contextLoads() { 21 | // List users = new ArrayList<>(); 22 | // for (int i=0;i<2000;i++){ 23 | // User user = new User(); 24 | // user.setUserEmail("184953"+(1000+i)+"@qq.com"); 25 | // user.setUserPassword("4532a9efe7f7028cca653d9f462ae526"); 26 | // user.setUserNickname(RandomUtil.randomString(8)); 27 | // user.setUserAvatar("https://p3-pc.douyinpic.com/aweme/100x100/aweme-avatar/tos-cn-avt-0015_0a69114a5280102312f509a571b00783.jpeg?from=2956013662"); 28 | // users.add(user); 29 | // } 30 | // userService.saveBatch(users); 31 | // } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /video/.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 | -------------------------------------------------------------------------------- /video/src/main/java/com/zhu/VideoApplication.java: -------------------------------------------------------------------------------- 1 | package com.zhu; 2 | 3 | import org.mybatis.spring.annotation.MapperScan; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | import org.springframework.context.annotation.EnableAspectJAutoProxy; 7 | 8 | @SpringBootApplication 9 | @MapperScan("com.zhu.mapper") 10 | //@EnableAspectJAutoProxy(proxyTargetClass = true, exposeProxy = true) 11 | public class VideoApplication { 12 | 13 | public static void main(String[] args) { 14 | SpringApplication.run(VideoApplication.class, args); 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /video/src/main/java/com/zhu/config/LoginInterceptor.java: -------------------------------------------------------------------------------- 1 | //package com.zhu.config; 2 | // 3 | //import com.zhu.constant.UserConstant; 4 | //import com.zhu.vo.LoginUserVo; 5 | //import org.springframework.stereotype.Component; 6 | //import org.springframework.web.servlet.HandlerInterceptor; 7 | // 8 | //import javax.servlet.http.HttpServletRequest; 9 | //import javax.servlet.http.HttpServletResponse; 10 | // 11 | //@Component 12 | //public class LoginInterceptor implements HandlerInterceptor { 13 | // 14 | // @Override 15 | // public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { 16 | // System.out.println(request.getRequestURI()); 17 | // LoginUserVo loginUserVo = (LoginUserVo) request.getSession().getAttribute(UserConstant.USER_LOGIN_STATE); 18 | //// System.out.println(loginUserVo); 19 | // return true; 20 | // } 21 | // 22 | //} 23 | -------------------------------------------------------------------------------- /video/src/main/java/com/zhu/config/WebConfig.java: -------------------------------------------------------------------------------- 1 | //package com.zhu.config; 2 | // 3 | //import org.springframework.context.annotation.Configuration; 4 | //import org.springframework.web.servlet.config.annotation.InterceptorRegistry; 5 | //import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport; 6 | // 7 | //import javax.annotation.Resource; 8 | // 9 | //@Configuration 10 | //public class WebConfig extends WebMvcConfigurationSupport { 11 | // 12 | // @Resource 13 | // private LoginInterceptor loginInterceptor; 14 | // 15 | // @Override 16 | // protected void addInterceptors(InterceptorRegistry registry) { 17 | // // 添加自定义拦截器,设置路径 18 | // registry.addInterceptor(loginInterceptor) 19 | // // 拦截小程序请求 20 | // .addPathPatterns("/**"); 21 | // // 排除登陆请求 22 | //// .excludePathPatterns("/api/user/weixin/wxLogin/*"); 23 | // super.addInterceptors(registry); 24 | // } 25 | //} 26 | -------------------------------------------------------------------------------- /video/src/main/java/com/zhu/controller/DanmuController.java: -------------------------------------------------------------------------------- 1 | package com.zhu.controller; 2 | 3 | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; 4 | import com.zhu.annotation.AuthCheck; 5 | import com.zhu.exception.ErrorException; 6 | import com.zhu.model.dto.danmu.DanmuAddRequest; 7 | import com.zhu.model.entity.Danmu; 8 | import com.zhu.model.entity.VideoInfo; 9 | import com.zhu.result.RespBean; 10 | import com.zhu.result.RespBeanEnum; 11 | import com.zhu.service.IDanmuService; 12 | import com.zhu.service.IUserService; 13 | import com.zhu.service.IVideoInfoService; 14 | import com.zhu.utils.BeanCopeUtils; 15 | import com.zhu.vo.LoginUserVo; 16 | import org.springframework.web.bind.annotation.*; 17 | 18 | import javax.annotation.Resource; 19 | import javax.servlet.http.HttpServletRequest; 20 | import java.util.List; 21 | 22 | /** 23 | *

24 | * 前端控制器 25 | *

26 | * 27 | * @author xiaozhu 28 | * @since 2023-11-14 29 | */ 30 | @RestController 31 | @RequestMapping("/danmu") 32 | public class DanmuController { 33 | 34 | @Resource 35 | private IDanmuService danmuService; 36 | 37 | @Resource 38 | private IVideoInfoService videoInfoService; 39 | 40 | @Resource 41 | private IUserService userService; 42 | 43 | @GetMapping("/list") 44 | public RespBean getVideoDanmu(Long videoId){ 45 | QueryWrapper danmuQueryWrapper = new QueryWrapper<>(); 46 | danmuQueryWrapper.eq("video_id",videoId); 47 | List danmus = danmuService.list(danmuQueryWrapper); 48 | return RespBean.success(danmus); 49 | } 50 | 51 | @PostMapping("/add") 52 | @AuthCheck 53 | public RespBean addDanmu(@RequestBody DanmuAddRequest danmuAddRequest, HttpServletRequest request){ 54 | if(danmuAddRequest==null){ 55 | throw new ErrorException(RespBeanEnum.PARAM_ERROR); 56 | } 57 | LoginUserVo loginUser = userService.getLoginUser(request); 58 | Long videoId = danmuAddRequest.getVideoId(); 59 | VideoInfo video = videoInfoService.getById(videoId); 60 | if(video==null){ 61 | throw new ErrorException(RespBeanEnum.PARAM_ERROR); 62 | } 63 | Danmu danmu = BeanCopeUtils.copyBean(danmuAddRequest, Danmu.class); 64 | danmu.setUid(loginUser.getUid()); 65 | danmuService.save(danmu); 66 | return RespBean.success(danmu); 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /video/src/main/java/com/zhu/controller/RecommendController.java: -------------------------------------------------------------------------------- 1 | package com.zhu.controller; 2 | 3 | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; 4 | import com.zhu.exception.ErrorException; 5 | import com.zhu.model.dto.video.VideoRecommendRequest; 6 | import com.zhu.recommend.core.UserBasedRecommend; 7 | import com.zhu.recommend.service.RecommendService; 8 | import com.zhu.result.RespBean; 9 | import com.zhu.result.RespBeanEnum; 10 | import com.zhu.service.IUserRatingService; 11 | import com.zhu.service.IUserService; 12 | import com.zhu.vo.LoginUserVo; 13 | import com.zhu.vo.VideoVo; 14 | import io.swagger.annotations.ApiOperation; 15 | import org.springframework.web.bind.annotation.*; 16 | 17 | import javax.annotation.Resource; 18 | import javax.servlet.http.HttpServletRequest; 19 | import java.util.List; 20 | 21 | @RestController 22 | @RequestMapping("/recommend") 23 | public class RecommendController { 24 | 25 | @Resource 26 | private RecommendService recommendService; 27 | 28 | @Resource 29 | private IUserService userService; 30 | 31 | @Resource 32 | private IUserRatingService userRatingService; 33 | 34 | @GetMapping("/rate") 35 | public RespBean getRating(){ 36 | UserBasedRecommend userBasedRecommend = new UserBasedRecommend(userRatingService.list(),1717008431916822529L); 37 | List longs = userBasedRecommend.recommendForUser(); 38 | return RespBean.success(longs); 39 | } 40 | 41 | @PostMapping("/") 42 | @ApiOperation(value = "个性化视频推荐") 43 | public RespBean recommendVideo(@RequestBody VideoRecommendRequest videoRecommendRequest, HttpServletRequest request) { 44 | // todo 还可以基于类型进行推荐,比如说看某个类型的视频多一点,就多推荐点该类型的视频 45 | LoginUserVo loginUser = userService.getLoginUser(request); 46 | long pageSize = videoRecommendRequest.getPageSize(); 47 | Page videoVoPage; 48 | if(loginUser!=null){ 49 | //登录用户按照个性化推荐 50 | // todo 如果评分表中没有该用户数据的话就会报错,没有评分数据按照随机推荐 51 | videoVoPage = recommendService.videoRecommend(loginUser.getUid(),request); 52 | // videoVoPage = recommendService.recommend(videoRecommendRequest,loginUser.getUid(),request); 53 | }else{ 54 | //没登录用户随机推荐视频 55 | //todo 并且只给显示20个视频,登录后可查看更多视频 56 | if(pageSize>20){ 57 | throw new ErrorException(RespBeanEnum.USER_NEED_LOGIN); 58 | } 59 | videoVoPage = recommendService.randomRecommend(videoRecommendRequest, request); 60 | } 61 | return RespBean.success(videoVoPage); 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /video/src/main/java/com/zhu/controller/TypeController.java: -------------------------------------------------------------------------------- 1 | package com.zhu.controller; 2 | 3 | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; 4 | import com.zhu.model.entity.Type; 5 | import com.zhu.result.RespBean; 6 | import com.zhu.service.ITypeService; 7 | import org.springframework.web.bind.annotation.GetMapping; 8 | import org.springframework.web.bind.annotation.RequestMapping; 9 | import org.springframework.web.bind.annotation.RestController; 10 | 11 | import javax.annotation.Resource; 12 | import java.util.List; 13 | 14 | /** 15 | *

16 | * 前端控制器 17 | *

18 | * 19 | * @author xiaozhu 20 | * @since 2023-10-29 21 | */ 22 | @RestController 23 | @RequestMapping("/type") 24 | public class TypeController { 25 | 26 | @Resource 27 | private ITypeService typeService; 28 | 29 | /** 30 | * 获取所有分类数据 31 | * @return 32 | */ 33 | @GetMapping("/list") 34 | public RespBean getListType(){ 35 | List typeList = typeService.list(new QueryWrapper().eq("status", 0)); 36 | return RespBean.success(typeList); 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /video/src/main/java/com/zhu/controller/VideoFavourController.java: -------------------------------------------------------------------------------- 1 | package com.zhu.controller; 2 | 3 | import com.zhu.annotation.AuthCheck; 4 | import com.zhu.exception.ErrorException; 5 | import com.zhu.model.dto.video.VideoFavourRequest; 6 | import com.zhu.result.RespBean; 7 | import com.zhu.result.RespBeanEnum; 8 | import com.zhu.service.IUserService; 9 | import com.zhu.service.IVideoFavourService; 10 | import com.zhu.vo.LoginUserVo; 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 javax.annotation.Resource; 17 | import javax.servlet.http.HttpServletRequest; 18 | 19 | /** 20 | *

21 | * 前端控制器 22 | *

23 | * 24 | * @author xiaozhu 25 | * @since 2023-10-31 26 | */ 27 | @RestController 28 | @RequestMapping("/videoFavour") 29 | public class VideoFavourController { 30 | 31 | @Resource 32 | private IVideoFavourService videoFavourService; 33 | 34 | @Resource 35 | private IUserService userService; 36 | 37 | /** 38 | * 用户点赞视频操作 39 | * @param videoFavourRequest 40 | * @return 41 | */ 42 | @PostMapping("/") 43 | @AuthCheck 44 | public RespBean doVideoFavour(@RequestBody VideoFavourRequest videoFavourRequest, HttpServletRequest request){ 45 | if(videoFavourRequest==null){ 46 | throw new ErrorException(RespBeanEnum.PARAM_ERROR); 47 | } 48 | LoginUserVo loginUser = userService.getLoginUser(request); 49 | Long videoId = videoFavourRequest.getVideoId(); 50 | int result = videoFavourService.doVideoFavour(videoId, loginUser.getUid()); 51 | return RespBean.success(result); 52 | } 53 | 54 | 55 | } 56 | -------------------------------------------------------------------------------- /video/src/main/java/com/zhu/controller/VideoStarController.java: -------------------------------------------------------------------------------- 1 | package com.zhu.controller; 2 | 3 | import com.zhu.annotation.AuthCheck; 4 | import com.zhu.exception.ErrorException; 5 | import com.zhu.model.dto.video.VideoStarRequest; 6 | import com.zhu.result.RespBean; 7 | import com.zhu.result.RespBeanEnum; 8 | import com.zhu.service.IUserService; 9 | import com.zhu.service.IVideoStarService; 10 | import com.zhu.vo.LoginUserVo; 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 javax.annotation.Resource; 17 | import javax.servlet.http.HttpServletRequest; 18 | 19 | /** 20 | *

21 | * 前端控制器 22 | *

23 | * 24 | * @author xiaozhu 25 | * @since 2023-10-31 26 | */ 27 | @RestController 28 | @RequestMapping("/videoStar") 29 | public class VideoStarController { 30 | 31 | @Resource 32 | private IVideoStarService videoStarService; 33 | 34 | @Resource 35 | private IUserService userService; 36 | 37 | @PostMapping("/") 38 | @AuthCheck 39 | public RespBean doVideoStar(@RequestBody VideoStarRequest videoStarRequest, HttpServletRequest request){ 40 | if(videoStarRequest==null){ 41 | throw new ErrorException(RespBeanEnum.PARAM_ERROR); 42 | } 43 | LoginUserVo loginUser = userService.getLoginUser(request); 44 | Long videoId = videoStarRequest.getVideoId(); 45 | int result = videoStarService.doVideoStar(videoId, loginUser.getUid()); 46 | return RespBean.success(result); 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /video/src/main/java/com/zhu/recommend/FileDataSource.java: -------------------------------------------------------------------------------- 1 | package com.zhu.recommend; 2 | 3 | import cn.hutool.core.util.RandomUtil; 4 | import com.zhu.model.entity.User; 5 | import com.zhu.model.entity.VideoInfo; 6 | import lombok.Data; 7 | import lombok.extern.slf4j.Slf4j; 8 | import org.assertj.core.util.Lists; 9 | 10 | import java.io.BufferedReader; 11 | import java.io.FileInputStream; 12 | import java.io.IOException; 13 | import java.io.InputStreamReader; 14 | import java.nio.charset.StandardCharsets; 15 | import java.util.List; 16 | import java.util.Objects; 17 | 18 | /** 19 | * @author tarzan 20 | */ 21 | @Data 22 | @Slf4j 23 | public class FileDataSource { 24 | 25 | 26 | public static String folderPath; 27 | static { 28 | folderPath= Objects.requireNonNull(FileDataSource.class.getResource("/data")).getPath(); 29 | } 30 | 31 | 32 | /** 33 | * 方法描述: 读取基础数据 34 | * 35 | * @author tarzan 36 | * @date 2020年07月31日 16:53:40 37 | */ 38 | public static List getData(List userList) { 39 | List relateList = Lists.newArrayList(); 40 | try { 41 | FileInputStream out = new FileInputStream("D:\\tool\\recommend_system-master\\recommend_system-master\\target\\classes\\ml-100k\\DVideo.data"); 42 | InputStreamReader reader = new InputStreamReader(out, StandardCharsets.UTF_8); 43 | BufferedReader in = new BufferedReader(reader); 44 | String line; 45 | while ((line = in.readLine()) != null) { 46 | String newline = line.replaceAll("[\t]", " "); 47 | String[] ht = newline.split(" "); 48 | String content = ht[0]; 49 | String videoUrl = ht[1]; 50 | String videoPic = ht[2]; 51 | VideoInfo videoInfo = new VideoInfo(); 52 | videoInfo.setDescription(content); 53 | videoInfo.setVideoUrl(videoUrl); 54 | videoInfo.setVideoPic(videoPic); 55 | videoInfo.setTypeId(RandomUtil.randomLong(2,9)); 56 | videoInfo.setUid(userList.get(RandomUtil.randomInt(0,userList.size()/8)).getUid()); 57 | videoInfo.setStatus(1); 58 | System.out.println(videoInfo); 59 | relateList.add(videoInfo); 60 | } 61 | } catch (IOException e) { 62 | log.error(e.getMessage()); 63 | } 64 | return relateList; 65 | } 66 | 67 | } 68 | 69 | -------------------------------------------------------------------------------- /video/src/main/java/com/zhu/spark/SparkManager.java: -------------------------------------------------------------------------------- 1 | package com.zhu.spark; 2 | 3 | import io.github.briqt.spark4j.SparkClient; 4 | import io.github.briqt.spark4j.constant.SparkApiVersion; 5 | import io.github.briqt.spark4j.model.SparkMessage; 6 | import io.github.briqt.spark4j.model.SparkSyncChatResponse; 7 | import io.github.briqt.spark4j.model.request.SparkRequest; 8 | import lombok.extern.slf4j.Slf4j; 9 | import org.springframework.stereotype.Component; 10 | 11 | import javax.annotation.Resource; 12 | import java.util.ArrayList; 13 | import java.util.List; 14 | 15 | @Component 16 | @Slf4j 17 | public class SparkManager { 18 | 19 | @Resource 20 | private SparkClient sparkClient; 21 | 22 | /** 23 | * AI生成问题的预设条件 24 | */ 25 | public static final String PRECONDITION = "您将获得一段视频内容的文本,您的任务是给出2个简体中文句子来总结视频。\n" + 26 | "下面是视频文本内容: \n" + 27 | "{视频文本内容的每一行包含两部分,前一部分表示视频时间段,由[]组成,后面表示该时间段的视频内容}"; 28 | 29 | /** 30 | * 向星火AI发送请求 31 | * 32 | * @param content 33 | * @return 34 | */ 35 | public String sendMesToAIUseXingHuo(final String content) { 36 | // 消息列表,可以在此列表添加历史对话记录 37 | List messages = new ArrayList<>(); 38 | messages.add(SparkMessage.systemContent(PRECONDITION)); 39 | messages.add(SparkMessage.userContent(content)); 40 | // 构造请求 41 | SparkRequest sparkRequest = SparkRequest.builder() 42 | // 消息列表 43 | .messages(messages) 44 | // 模型回答的tokens的最大长度,非必传,默认为2048 45 | .maxTokens(2048) 46 | // 结果随机性,取值越高随机性越强,即相同的问题得到的不同答案的可能性越高,非必传,取值为[0,1],默认为0.5 47 | .temperature(0.2) 48 | // 指定请求版本 49 | .apiVersion(SparkApiVersion.V3_5) 50 | .build(); 51 | // 同步调用 52 | SparkSyncChatResponse chatResponse = sparkClient.chatSync(sparkRequest); 53 | String responseContent = chatResponse.getContent(); 54 | log.info("星火AI返回的结果{}", responseContent); 55 | return responseContent; 56 | } 57 | 58 | } 59 | 60 | -------------------------------------------------------------------------------- /video/src/main/java/com/zhu/spark/SparkService.java: -------------------------------------------------------------------------------- 1 | package com.zhu.spark; 2 | 3 | import com.zhu.constant.CommentConstant; 4 | import com.zhu.model.entity.Comment; 5 | import com.zhu.service.ICommentService; 6 | import com.zhu.utils.WhisperUtils; 7 | import org.springframework.stereotype.Service; 8 | 9 | import javax.annotation.Resource; 10 | 11 | @Service 12 | public class SparkService { 13 | 14 | @Resource 15 | private SparkManager sparkManager; 16 | 17 | @Resource 18 | private ICommentService commentService; 19 | 20 | /** 21 | * todo 1、发布成功后对长视频进行拆分,拆分成每个视频最长为30秒的视频 22 | * 2、用whisper模型对拆分的视频进行并行音频文字识别 23 | * 3、整理识别结果,用星火大模型将识别内容进行总结 24 | * 4、获取视频总结,添加到对应视频的评论列表中 25 | * @return 26 | */ 27 | public void videoSummaryWithAI(String audioPath, Long videoId){ 28 | // File file = new File(audioPath); 29 | // if(!file.exists()){ 30 | // System.out.println("文件不存在"); 31 | // throw new ErrorException(RespBeanEnum.FILE_NOT_EXIST); 32 | // } 33 | // System.out.println("文件存在"); 34 | String videoText = WhisperUtils.doWhisper(audioPath); 35 | System.out.println("完成文字识别"); 36 | //todo 如果识别出来的文字过少,那么就不调用星火大模型 37 | String aiSummary = sparkManager.sendMesToAIUseXingHuo(videoText); 38 | //将AI出来的总结添加到评论 39 | //todo 可以定义一个常量接口,里面放入官方的用户信息 40 | Comment comment = new Comment(); 41 | comment.setContent(aiSummary); 42 | comment.setUid(CommentConstant.AIUserCommentID); 43 | comment.setVideoId(videoId); 44 | commentService.save(comment); 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /video/src/main/java/com/zhu/spark/XingHuoConfig.java: -------------------------------------------------------------------------------- 1 | package com.zhu.spark; 2 | 3 | import io.github.briqt.spark4j.SparkClient; 4 | import lombok.Data; 5 | import org.springframework.boot.context.properties.ConfigurationProperties; 6 | import org.springframework.context.annotation.Bean; 7 | import org.springframework.context.annotation.Configuration; 8 | 9 | @Configuration 10 | @ConfigurationProperties(prefix = "xunfei.client") 11 | @Data 12 | public class XingHuoConfig { 13 | private String appid; 14 | private String apiSecret; 15 | private String apiKey; 16 | 17 | @Bean 18 | public SparkClient sparkClient() { 19 | SparkClient sparkClient = new SparkClient(); 20 | sparkClient.apiKey = apiKey; 21 | sparkClient.apiSecret = apiSecret; 22 | sparkClient.appid = appid; 23 | return sparkClient; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /video/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 7519 3 | 4 | mybatis-plus: 5 | mapper-locations: classpath:/mapper/*.xml 6 | type-aliases-package: com.zhu.model.entity 7 | # configuration: 8 | # log-impl: org.apache.ibatis.logging.stdout.StdOutImpl 9 | spring: 10 | datasource: 11 | driver-class-name: com.mysql.cj.jdbc.Driver 12 | url: jdbc:mysql://localhost:3306/video?useUnicode=utf-8&useSSL=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai 13 | username: root 14 | password: 12345678 15 | jackson: 16 | date-format: yyyy-MM-dd HH:mm:ss 17 | time-zone: GMT+8 18 | session: 19 | timeout: 86400 20 | store-type: redis 21 | redis: 22 | host: 127.0.0.1 23 | port: 6379 24 | jedis: 25 | pool: 26 | max-active: 8 27 | max-wait: -1 28 | max-idle: 8 29 | min-idle: 0 30 | timeout: 5000 31 | mvc: 32 | pathmatch: 33 | matching-strategy: ant_path_matcher 34 | elasticsearch: 35 | uris: http://localhost:9200 36 | mail: 37 | username: xxx@qq.com 38 | password: 39 | host: smtp.qq.com 40 | properties: 41 | mail: 42 | smtp: 43 | ssl: 44 | enable: true 45 | servlet: 46 | multipart: 47 | max-file-size: 100MB 48 | max-request-size: 1000MB 49 | rabbitmq: 50 | port: 5672 51 | virtual-host: / 52 | host: 127.0.0.1 53 | username: guest 54 | password: guest 55 | listener: 56 | simple: 57 | prefetch: 1 58 | publisher-confirm-type: correlated #获取confirm方法 59 | publisher-returns: true #开启publish-return功能 60 | template: 61 | mandatory: true #定义消息路由失败策略,如果设置为false,则直接丢弃消息 62 | 63 | 64 | qiniuyun: 65 | #accessKey密钥 66 | accessKey: 67 | #secretKey密钥 68 | secretKey: 69 | #存储空间名称 70 | bucket: 71 | #外链域名,即空间的默认域名 72 | qiniu-image-domain: 73 | #链接过期时间,单位为秒,-1表示不过期 74 | expire-in-seconds: -1 75 | xunfei: 76 | client: 77 | appid: 78 | apiSecret: 79 | apiKey: 80 | --------------------------------------------------------------------------------