├── README.md ├── nawoj-backend ├── .DS_Store ├── .gitignore ├── .mvn │ └── wrapper │ │ └── maven-wrapper.properties ├── Dockerfile ├── doc │ └── swagger.png ├── mvnw ├── mvnw.cmd ├── pom.xml ├── sql │ ├── create_table.sql │ └── post_es_mapping.json └── src │ ├── .DS_Store │ ├── main │ ├── java │ │ └── com │ │ │ └── yupi │ │ │ └── nawoj_backend │ │ │ ├── MainApplication.java │ │ │ ├── annotation │ │ │ ├── AuthCheck.java │ │ │ ├── Prevent.java │ │ │ └── PreventStrategy.java │ │ │ ├── aop │ │ │ ├── AuthInterceptor.java │ │ │ ├── LogInterceptor.java │ │ │ └── PreventAop.java │ │ │ ├── common │ │ │ ├── BaseResponse.java │ │ │ ├── DeleteRequest.java │ │ │ ├── PageRequest.java │ │ │ ├── ResultUtils.java │ │ │ └── enums │ │ │ │ ├── ErrorCode.java │ │ │ │ └── JudgeInfoMessageEnum.java │ │ │ ├── config │ │ │ ├── AliyunConfig.java │ │ │ ├── CorsConfig.java │ │ │ ├── CosClientConfig.java │ │ │ ├── FastJsonRedisSerializer.java │ │ │ ├── JsonConfig.java │ │ │ ├── MyBatisPlusConfig.java │ │ │ ├── RedisConfig.java │ │ │ └── WxOpenConfig.java │ │ │ ├── constant │ │ │ ├── CommonConstant.java │ │ │ ├── FileConstant.java │ │ │ └── UserConstant.java │ │ │ ├── controller │ │ │ ├── FileController.java │ │ │ ├── PostController.java │ │ │ ├── PostFavourController.java │ │ │ ├── PostThumbController.java │ │ │ ├── QuestionController.java │ │ │ ├── QuestionSubmitController.java │ │ │ ├── UserController.java │ │ │ └── WxMpController.java │ │ │ ├── esdao │ │ │ └── PostEsDao.java │ │ │ ├── exception │ │ │ ├── BusinessException.java │ │ │ ├── GlobalExceptionHandler.java │ │ │ └── ThrowUtils.java │ │ │ ├── interceptor │ │ │ └── GlobalInterceptor.java │ │ │ ├── job │ │ │ ├── cycle │ │ │ │ └── IncSyncPostToEs.java │ │ │ └── once │ │ │ │ └── FullSyncPostToEs.java │ │ │ ├── manager │ │ │ ├── AliManager.java │ │ │ └── CosManager.java │ │ │ ├── mapper │ │ │ ├── PostFavourMapper.java │ │ │ ├── PostMapper.java │ │ │ ├── PostThumbMapper.java │ │ │ ├── QuestionMapper.java │ │ │ ├── QuestionSubmitMapper.java │ │ │ └── UserMapper.java │ │ │ ├── model │ │ │ ├── dto │ │ │ │ ├── file │ │ │ │ │ └── UploadFileRequest.java │ │ │ │ ├── post │ │ │ │ │ ├── PostAddRequest.java │ │ │ │ │ ├── PostEditRequest.java │ │ │ │ │ ├── PostEsDTO.java │ │ │ │ │ ├── PostQueryRequest.java │ │ │ │ │ └── PostUpdateRequest.java │ │ │ │ ├── postfavour │ │ │ │ │ ├── PostFavourAddRequest.java │ │ │ │ │ └── PostFavourQueryRequest.java │ │ │ │ ├── postthumb │ │ │ │ │ └── PostThumbAddRequest.java │ │ │ │ ├── question │ │ │ │ │ ├── QuestionAddRequest.java │ │ │ │ │ ├── QuestionEditRequest.java │ │ │ │ │ ├── QuestionJudgeCase.java │ │ │ │ │ ├── QuestionJudgeConfig.java │ │ │ │ │ ├── QuestionJudgeDescription.java │ │ │ │ │ ├── QuestionQueryRequest.java │ │ │ │ │ └── QuestionUpdateRequest.java │ │ │ │ ├── questionsubmit │ │ │ │ │ ├── QuestionJudgeInfo.java │ │ │ │ │ ├── QuestionSubmitAddRequest.java │ │ │ │ │ └── QuestionSubmitQueryRequest.java │ │ │ │ └── user │ │ │ │ │ ├── UserAddRequest.java │ │ │ │ │ ├── UserLoginRequest.java │ │ │ │ │ ├── UserQueryRequest.java │ │ │ │ │ ├── UserRegisterRequest.java │ │ │ │ │ ├── UserUpdateMyRequest.java │ │ │ │ │ └── UserUpdateRequest.java │ │ │ ├── entity │ │ │ │ ├── Post.java │ │ │ │ ├── PostFavour.java │ │ │ │ ├── PostThumb.java │ │ │ │ ├── Question.java │ │ │ │ ├── QuestionSubmit.java │ │ │ │ └── User.java │ │ │ ├── enums │ │ │ │ ├── AppHttpCodeEnum.java │ │ │ │ ├── FileUploadBizEnum.java │ │ │ │ ├── JudgeInfoMessageEnum.java │ │ │ │ ├── QuestionSubmitLanguageEnum.java │ │ │ │ ├── QuestionSubmitStatusEnum.java │ │ │ │ └── UserRoleEnum.java │ │ │ └── vo │ │ │ │ ├── LoginUserVO.java │ │ │ │ ├── PostVO.java │ │ │ │ ├── QuestionVO.java │ │ │ │ └── UserVO.java │ │ │ ├── service │ │ │ ├── PostFavourService.java │ │ │ ├── PostService.java │ │ │ ├── PostThumbService.java │ │ │ ├── QuestionService.java │ │ │ ├── QuestionSubmitService.java │ │ │ ├── UserService.java │ │ │ └── impl │ │ │ │ ├── PostFavourServiceImpl.java │ │ │ │ ├── PostServiceImpl.java │ │ │ │ ├── PostThumbServiceImpl.java │ │ │ │ ├── QuestionServiceImpl.java │ │ │ │ ├── QuestionSubmitServiceImpl.java │ │ │ │ └── UserServiceImpl.java │ │ │ ├── utils │ │ │ ├── NetUtils.java │ │ │ ├── SpringContextUtils.java │ │ │ └── SqlUtils.java │ │ │ └── wxmp │ │ │ ├── WxMpConstant.java │ │ │ ├── WxMpMsgRouter.java │ │ │ └── handler │ │ │ ├── EventHandler.java │ │ │ ├── MessageHandler.java │ │ │ └── SubscribeHandler.java │ └── resources │ │ ├── META-INF │ │ └── additional-spring-configuration-metadata.json │ │ ├── application-prod.yml │ │ ├── application-test.yml │ │ ├── application.yml │ │ ├── banner.txt │ │ └── mapper │ │ ├── PostFavourMapper.xml │ │ ├── PostMapper.xml │ │ ├── PostThumbMapper.xml │ │ ├── QuestionMapper.xml │ │ ├── QuestionSubmitMapper.xml │ │ └── UserMapper.xml │ └── test │ ├── .DS_Store │ └── java │ └── com │ └── yupi │ └── nawoj_backend │ ├── MainApplicationTests.java │ ├── esdao │ └── PostEsDaoTest.java │ ├── manager │ └── CosManagerTest.java │ ├── mapper │ ├── PostFavourMapperTest.java │ └── PostMapperTest.java │ ├── service │ ├── PostFavourServiceTest.java │ ├── PostServiceTest.java │ ├── PostThumbServiceTest.java │ └── UserServiceTest.java │ └── utils │ └── EasyExcelTest.java └── nawoj-frontend ├── .browserslistrc ├── .eslintrc.js ├── .gitignore ├── README.md ├── babel.config.js ├── package-lock.json ├── package.json ├── public ├── favicon.ico └── index.html ├── src ├── App.vue ├── access │ ├── accessEnum.ts │ ├── checkAccess.ts │ └── index.ts ├── assets │ ├── init.css │ └── logo.png ├── components │ └── NavBar.vue ├── generated │ ├── core │ │ ├── ApiError.ts │ │ ├── ApiRequestOptions.ts │ │ ├── ApiResult.ts │ │ ├── CancelablePromise.ts │ │ ├── OpenAPI.ts │ │ └── request.ts │ ├── index.ts │ ├── models │ │ ├── BaseResponse_LoginUserVO_.ts │ │ ├── BaseResponse_Page_PostVO_.ts │ │ ├── BaseResponse_Page_QuestionSubmitVO_.ts │ │ ├── BaseResponse_Page_QuestionVO_.ts │ │ ├── BaseResponse_Page_Question_.ts │ │ ├── BaseResponse_Page_UserVO_.ts │ │ ├── BaseResponse_Page_User_.ts │ │ ├── BaseResponse_PostVO_.ts │ │ ├── BaseResponse_QuestionVO_.ts │ │ ├── BaseResponse_Question_.ts │ │ ├── BaseResponse_UserVO_.ts │ │ ├── BaseResponse_User_.ts │ │ ├── BaseResponse_boolean_.ts │ │ ├── BaseResponse_int_.ts │ │ ├── BaseResponse_long_.ts │ │ ├── BaseResponse_string_.ts │ │ ├── DeleteRequest.ts │ │ ├── JudgeCase.ts │ │ ├── JudgeConfig.ts │ │ ├── JudgeInfo.ts │ │ ├── LoginUserVO.ts │ │ ├── OrderItem.ts │ │ ├── Page_PostVO_.ts │ │ ├── Page_QuestionSubmitVO_.ts │ │ ├── Page_QuestionVO_.ts │ │ ├── Page_Question_.ts │ │ ├── Page_UserVO_.ts │ │ ├── Page_User_.ts │ │ ├── PostAddRequest.ts │ │ ├── PostEditRequest.ts │ │ ├── PostFavourAddRequest.ts │ │ ├── PostFavourQueryRequest.ts │ │ ├── PostQueryRequest.ts │ │ ├── PostThumbAddRequest.ts │ │ ├── PostUpdateRequest.ts │ │ ├── PostVO.ts │ │ ├── Question.ts │ │ ├── QuestionAddRequest.ts │ │ ├── QuestionEditRequest.ts │ │ ├── QuestionQueryRequest.ts │ │ ├── QuestionSubmitAddRequest.ts │ │ ├── QuestionSubmitQueryRequest.ts │ │ ├── QuestionSubmitVO.ts │ │ ├── QuestionUpdateRequest.ts │ │ ├── QuestionVO.ts │ │ ├── User.ts │ │ ├── UserAddRequest.ts │ │ ├── UserLoginRequest.ts │ │ ├── UserQueryRequest.ts │ │ ├── UserRegisterRequest.ts │ │ ├── UserUpdateMyRequest.ts │ │ ├── UserUpdateRequest.ts │ │ └── UserVO.ts │ └── services │ │ ├── FileControllerService.ts │ │ ├── PostControllerService.ts │ │ ├── PostFavourControllerService.ts │ │ ├── PostThumbControllerService.ts │ │ ├── QuestionControllerService.ts │ │ ├── UserControllerService.ts │ │ └── WxMpControllerService.ts ├── layouts │ └── BasicLayout.vue ├── main.ts ├── router │ ├── index.ts │ └── routes.ts ├── shims-vue.d.ts ├── store │ ├── index.ts │ └── user.ts ├── types │ └── user.ts ├── utils │ └── request.ts └── views │ ├── AboutView.vue │ ├── HomeView.vue │ ├── NotFoundView.vue │ ├── UserLoginView.vue │ └── UserRegisterView.vue ├── tsconfig.json └── vue.config.js /README.md: -------------------------------------------------------------------------------- 1 | # 项目名称 ⭐ 2 | 3 | 该项目是一个基于 Vue 和 Spring Cloud 的在线判题系统(Open Judge)系统 4 | 5 | ## 技术栈 6 | 7 | - **后端**: 8 | - 🚀 Spring Cloud:用于构建微服务架构,提供服务注册、配置中心等功能。 9 | - 🚀 Redis:用作缓存系统,提高系统性能和并发处理能力。 10 | - 🚀 MongoDB:用作非结构化数据存储,例如用户提交的代码、评测记录等。 11 | - 🚀 Docker:用于容器化部署,简化开发、测试和部署流程。同时作为远程Code Sand Box编译用户代码。 12 | - 🚀 MySQL:作为关系型数据库,用于存储用户信息、题目信息等。 13 | 14 | - **前端**: 15 | - Vue 3:用于构建用户界面,实现前端页面的交互和展示。 16 | - Typescript 17 | - ByteMd 18 | - TinyMCE 19 | - Vite 20 | - Websocket 21 | 22 | 23 | ## 功能特性 24 | 25 | - 用户注册与登录:用户可以注册新账号并登录系统。 26 | - 游戏管理:管理员可以添加、编辑和删除编程游戏。 27 | - Post模块:负责作为平台的社交属性,并且会对上传的东西进行多次本地的以及远程的内容检测(ALIYUN GREEN)。 28 | - 代码评测:用户可以提交代码进行评测,系统会根据评测结果给出相应的反馈,通过docker sand box controller远程调用返回代码运行结果。 29 | 🔔 使用本地运行以及远程docker沙箱实现,目前支持语言:cpp,python,java 30 | 🔔 本地运行语言为java,采用Process类搭建 31 | - 对局回放:可以通过类似查看video的方式查看对局记录。 32 | - 参加比赛:玩家可以参加管理员办理的比赛,在时间内上传指定代码,比赛开始后后台使用代码自动比赛。 33 | - 代码分享:用户可以分享自己的解题代码,与他人交流学习。 34 | 35 | 36 | ## 如何运行 37 | 38 | 1. 克隆项目到本地: 39 | 40 | ```bash 41 | git clone https://github.com/fujiwarazz/nawoj 42 | ``` 43 | 2. 前端: 44 | ```bash 45 | npm install 46 | npm run serve 47 | ``` 48 | -------------------------------------------------------------------------------- /nawoj-backend/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fujiwarazz/nawoj/4709f31ffe7f1e214b8c085a719504383219fea8/nawoj-backend/.DS_Store -------------------------------------------------------------------------------- /nawoj-backend/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.1/apache-maven-3.8.1-bin.zip 2 | wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar 3 | -------------------------------------------------------------------------------- /nawoj-backend/Dockerfile: -------------------------------------------------------------------------------- 1 | # Docker 镜像构建 2 | # @author 程序员鱼皮 3 | # @from 编程导航知识星球 4 | FROM maven:3.8.1-jdk-8-slim as builder 5 | 6 | # Copy local code to the container image. 7 | WORKDIR /app 8 | COPY pom.xml . 9 | COPY src ./src 10 | 11 | # Build a release artifact. 12 | RUN mvn package -DskipTests 13 | 14 | # Run the web service on container startup. 15 | CMD ["java","-jar","/app/target/nawoj_backend-0.0.1-SNAPSHOT.jar","--spring.profiles.active=prod"] -------------------------------------------------------------------------------- /nawoj-backend/doc/swagger.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fujiwarazz/nawoj/4709f31ffe7f1e214b8c085a719504383219fea8/nawoj-backend/doc/swagger.png -------------------------------------------------------------------------------- /nawoj-backend/sql/post_es_mapping.json: -------------------------------------------------------------------------------- 1 | { 2 | "aliases": { 3 | "post": {} 4 | }, 5 | "mappings": { 6 | "properties": { 7 | "title": { 8 | "type": "text", 9 | "analyzer": "ik_max_word", 10 | "search_analyzer": "ik_smart", 11 | "fields": { 12 | "keyword": { 13 | "type": "keyword", 14 | "ignore_above": 256 15 | } 16 | } 17 | }, 18 | "content": { 19 | "type": "text", 20 | "analyzer": "ik_max_word", 21 | "search_analyzer": "ik_smart", 22 | "fields": { 23 | "keyword": { 24 | "type": "keyword", 25 | "ignore_above": 256 26 | } 27 | } 28 | }, 29 | "tags": { 30 | "type": "keyword" 31 | }, 32 | "thumbNum": { 33 | "type": "long" 34 | }, 35 | "favourNum": { 36 | "type": "long" 37 | }, 38 | "userId": { 39 | "type": "keyword" 40 | }, 41 | "createTime": { 42 | "type": "date" 43 | }, 44 | "updateTime": { 45 | "type": "date" 46 | }, 47 | "isDelete": { 48 | "type": "keyword" 49 | } 50 | } 51 | } 52 | } -------------------------------------------------------------------------------- /nawoj-backend/src/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fujiwarazz/nawoj/4709f31ffe7f1e214b8c085a719504383219fea8/nawoj-backend/src/.DS_Store -------------------------------------------------------------------------------- /nawoj-backend/src/main/java/com/yupi/nawoj_backend/MainApplication.java: -------------------------------------------------------------------------------- 1 | package com.yupi.nawoj_backend; 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.boot.autoconfigure.data.redis.RedisAutoConfiguration; 7 | import org.springframework.context.annotation.EnableAspectJAutoProxy; 8 | import org.springframework.scheduling.annotation.EnableScheduling; 9 | import springfox.documentation.swagger2.annotations.EnableSwagger2; 10 | 11 | /** 12 | * 主类(项目启动入口) 13 | * 14 | * @author 程序员鱼皮 15 | * @from 编程导航知识星球 16 | */ 17 | // todo 如需开启 Redis,须移除 exclude 中的内容 18 | @SpringBootApplication 19 | @MapperScan("com.yupi.nawoj_backend.mapper") 20 | @EnableScheduling 21 | @EnableSwagger2 22 | @EnableAspectJAutoProxy(proxyTargetClass = true, exposeProxy = true) 23 | public class MainApplication { 24 | 25 | public static void main(String[] args) { 26 | SpringApplication.run(MainApplication.class, args); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /nawoj-backend/src/main/java/com/yupi/nawoj_backend/annotation/AuthCheck.java: -------------------------------------------------------------------------------- 1 | package com.yupi.nawoj_backend.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 | * @author 程序员鱼皮 12 | * @from 编程导航知识星球 13 | */ 14 | @Target(ElementType.METHOD) 15 | @Retention(RetentionPolicy.RUNTIME) 16 | public @interface AuthCheck { 17 | 18 | /** 19 | * 必须有某个角色 20 | * 21 | * @return 22 | */ 23 | String mustRole() default ""; 24 | 25 | } 26 | 27 | -------------------------------------------------------------------------------- /nawoj-backend/src/main/java/com/yupi/nawoj_backend/annotation/Prevent.java: -------------------------------------------------------------------------------- 1 | package com.yupi.nawoj_backend.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 | * @Author peelsannaw 10 | * @create 19/12/2022 下午4:27 11 | * 接口防刷,默认60s一次 12 | */ 13 | @Retention(RetentionPolicy.RUNTIME) 14 | @Target(ElementType.METHOD) 15 | public @interface Prevent { 16 | 17 | /** 18 | * 限制时间 19 | * @return 20 | */ 21 | String value() default "60"; 22 | 23 | /** 24 | * 提示信息 25 | * @return 26 | */ 27 | String message() default "请稍后再试!"; 28 | 29 | PreventStrategy strategy() default PreventStrategy.DEFAULT; 30 | } 31 | -------------------------------------------------------------------------------- /nawoj-backend/src/main/java/com/yupi/nawoj_backend/annotation/PreventStrategy.java: -------------------------------------------------------------------------------- 1 | package com.yupi.nawoj_backend.annotation; 2 | 3 | /** 4 | * @Author peelsannaw 5 | * @create 19/12/2022 下午4:32 6 | */ 7 | public enum PreventStrategy { 8 | 9 | DEFAULT(0); 10 | 11 | 12 | Integer code; 13 | 14 | PreventStrategy(Integer code) { 15 | this.code = code; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /nawoj-backend/src/main/java/com/yupi/nawoj_backend/aop/AuthInterceptor.java: -------------------------------------------------------------------------------- 1 | package com.yupi.nawoj_backend.aop; 2 | 3 | import com.yupi.nawoj_backend.annotation.AuthCheck; 4 | import com.yupi.nawoj_backend.common.enums.ErrorCode; 5 | import com.yupi.nawoj_backend.exception.BusinessException; 6 | import com.yupi.nawoj_backend.model.entity.User; 7 | import com.yupi.nawoj_backend.model.enums.UserRoleEnum; 8 | import com.yupi.nawoj_backend.service.UserService; 9 | import javax.annotation.Resource; 10 | import javax.servlet.http.HttpServletRequest; 11 | import org.apache.commons.lang3.StringUtils; 12 | import org.aspectj.lang.ProceedingJoinPoint; 13 | import org.aspectj.lang.annotation.Around; 14 | import org.aspectj.lang.annotation.Aspect; 15 | import org.springframework.stereotype.Component; 16 | import org.springframework.web.context.request.RequestAttributes; 17 | import org.springframework.web.context.request.RequestContextHolder; 18 | import org.springframework.web.context.request.ServletRequestAttributes; 19 | 20 | /** 21 | * 权限校验 AOP 22 | * 23 | * @author 程序员鱼皮 24 | * @from 编程导航知识星球 25 | */ 26 | @Aspect 27 | @Component 28 | public class AuthInterceptor { 29 | 30 | @Resource 31 | private UserService userService; 32 | 33 | /** 34 | * 执行拦截 35 | * 36 | * @param joinPoint 37 | * @param authCheck 38 | * @return 39 | */ 40 | @Around("@annotation(authCheck)") 41 | public Object doInterceptor(ProceedingJoinPoint joinPoint, AuthCheck authCheck) throws Throwable { 42 | String mustRole = authCheck.mustRole(); 43 | RequestAttributes requestAttributes = RequestContextHolder.currentRequestAttributes(); 44 | HttpServletRequest request = ((ServletRequestAttributes) requestAttributes).getRequest(); 45 | // 当前登录用户 46 | User loginUser = userService.getLoginUser(request); 47 | // 必须有该权限才通过 48 | if (StringUtils.isNotBlank(mustRole)) { 49 | UserRoleEnum mustUserRoleEnum = UserRoleEnum.getEnumByValue(mustRole); 50 | if (mustUserRoleEnum == null) { 51 | throw new BusinessException(ErrorCode.NO_AUTH_ERROR); 52 | } 53 | String userRole = loginUser.getUserRole(); 54 | 55 | // 如果被封号,直接拒绝 56 | if (UserRoleEnum.BAN.equals(mustUserRoleEnum)) { 57 | throw new BusinessException(ErrorCode.NO_AUTH_ERROR); 58 | } 59 | // 必须有管理员权限 60 | if (UserRoleEnum.ADMIN.equals(mustUserRoleEnum)) { 61 | if (!mustRole.equals(userRole)) { 62 | throw new BusinessException(ErrorCode.NO_AUTH_ERROR); 63 | } 64 | } 65 | } 66 | // 通过权限校验,放行 67 | return joinPoint.proceed(); 68 | } 69 | } 70 | 71 | -------------------------------------------------------------------------------- /nawoj-backend/src/main/java/com/yupi/nawoj_backend/aop/LogInterceptor.java: -------------------------------------------------------------------------------- 1 | package com.yupi.nawoj_backend.aop; 2 | 3 | import java.util.UUID; 4 | import javax.servlet.http.HttpServletRequest; 5 | import lombok.extern.slf4j.Slf4j; 6 | import org.apache.commons.lang3.StringUtils; 7 | import org.aspectj.lang.ProceedingJoinPoint; 8 | import org.aspectj.lang.annotation.Around; 9 | import org.aspectj.lang.annotation.Aspect; 10 | import org.springframework.stereotype.Component; 11 | import org.springframework.util.StopWatch; 12 | import org.springframework.web.context.request.RequestAttributes; 13 | import org.springframework.web.context.request.RequestContextHolder; 14 | import org.springframework.web.context.request.ServletRequestAttributes; 15 | 16 | /** 17 | * 请求响应日志 AOP 18 | * 19 | * @author 程序员鱼皮 20 | * @from 编程导航知识星球 21 | **/ 22 | @Aspect 23 | @Component 24 | @Slf4j 25 | public class LogInterceptor { 26 | 27 | /** 28 | * 执行拦截 29 | */ 30 | @Around("execution(* com.yupi.nawoj_backend.controller.*.*(..))") 31 | public Object doInterceptor(ProceedingJoinPoint point) throws Throwable { 32 | // 计时 33 | StopWatch stopWatch = new StopWatch(); 34 | stopWatch.start(); 35 | // 获取请求路径 36 | RequestAttributes requestAttributes = RequestContextHolder.currentRequestAttributes(); 37 | HttpServletRequest httpServletRequest = ((ServletRequestAttributes) requestAttributes).getRequest(); 38 | // 生成请求唯一 id 39 | String requestId = UUID.randomUUID().toString(); 40 | String url = httpServletRequest.getRequestURI(); 41 | // 获取请求参数 42 | Object[] args = point.getArgs(); 43 | String reqParam = "[" + StringUtils.join(args, ", ") + "]"; 44 | // 输出请求日志 45 | log.info("request start,id: {}, path: {}, ip: {}, params: {}", requestId, url, 46 | httpServletRequest.getRemoteHost(), reqParam); 47 | // 执行原方法 48 | Object result = point.proceed(); 49 | // 输出响应日志 50 | stopWatch.stop(); 51 | long totalTimeMillis = stopWatch.getTotalTimeMillis(); 52 | log.info("request end, id: {}, cost: {}ms", requestId, totalTimeMillis); 53 | return result; 54 | } 55 | } 56 | 57 | -------------------------------------------------------------------------------- /nawoj-backend/src/main/java/com/yupi/nawoj_backend/aop/PreventAop.java: -------------------------------------------------------------------------------- 1 | package com.yupi.nawoj_backend.aop; 2 | 3 | import cn.hutool.json.JSON; 4 | import cn.hutool.json.JSONUtil; 5 | import com.google.gson.JsonObject; 6 | import com.yupi.nawoj_backend.annotation.Prevent; 7 | import com.yupi.nawoj_backend.annotation.PreventStrategy; 8 | import lombok.extern.slf4j.Slf4j; 9 | import org.aspectj.lang.JoinPoint; 10 | import org.aspectj.lang.annotation.Aspect; 11 | import org.aspectj.lang.annotation.Before; 12 | import org.aspectj.lang.annotation.Pointcut; 13 | import org.aspectj.lang.reflect.MethodSignature; 14 | import org.springframework.data.redis.core.StringRedisTemplate; 15 | import org.springframework.stereotype.Component; 16 | 17 | import javax.annotation.Resource; 18 | import java.lang.reflect.Method; 19 | import java.nio.charset.StandardCharsets; 20 | import java.util.Base64; 21 | import java.util.concurrent.TimeUnit; 22 | 23 | /** 24 | * @Author peelsannaw 25 | * @create 19/12/2022 下午4:35 26 | */ 27 | @Aspect 28 | @Component 29 | @Slf4j 30 | 31 | public class PreventAop { 32 | 33 | @Resource 34 | StringRedisTemplate stringRedisTemplate; 35 | 36 | @Pointcut("@annotation(com.yupi.nawoj_backend.annotation.Prevent)") 37 | public void pt() { 38 | 39 | } 40 | 41 | @Before("pt()") 42 | public void joinPoint(JoinPoint joinPoint) throws Exception { 43 | //获取请求 44 | String reqStr = JSONUtil.toJsonStr(joinPoint.getArgs()[0]); 45 | if (reqStr.length() == 0) { 46 | throw new RuntimeException("[防刷]入参不为空!"); 47 | } 48 | MethodSignature signature = (MethodSignature) joinPoint.getSignature(); 49 | Method method = joinPoint.getTarget().getClass().getMethod(signature.getName(), signature.getParameterTypes()); 50 | 51 | Prevent preventAnno = method.getAnnotation(Prevent.class); 52 | String methodFullName = method.getDeclaringClass().getName() + method.getName(); 53 | 54 | entrance(preventAnno, reqStr, methodFullName); 55 | 56 | } 57 | 58 | @SuppressWarnings("all") 59 | private void entrance(Prevent preventAnno, String reqStr, String methodFullName) { 60 | PreventStrategy strategy = preventAnno.strategy(); 61 | switch (strategy) { 62 | case DEFAULT: 63 | defaultHandle(reqStr, preventAnno, methodFullName); 64 | break; 65 | default: 66 | log.info("[invalid strategy]"); 67 | throw new RuntimeException("invalid strategy"); 68 | } 69 | } 70 | 71 | private void defaultHandle(String reqStr, Prevent preventAnno, String methodFullName) { 72 | String base64Str= Base64.getEncoder().encodeToString(reqStr.getBytes(StandardCharsets.UTF_8)); 73 | long expire = Long.parseLong(preventAnno.value()); 74 | 75 | String resp = stringRedisTemplate.opsForValue().get(methodFullName + base64Str); 76 | if (resp == null || resp.length() == 0) { 77 | stringRedisTemplate.opsForValue().set(methodFullName +base64Str, reqStr, expire, TimeUnit.SECONDS); 78 | } else { 79 | String msg = preventAnno.message() == null || preventAnno.message().length() == 0 80 | ? expire + "秒内不允许重复请求!" : preventAnno.message(); 81 | throw new RuntimeException(msg); 82 | } 83 | } 84 | 85 | } 86 | -------------------------------------------------------------------------------- /nawoj-backend/src/main/java/com/yupi/nawoj_backend/common/BaseResponse.java: -------------------------------------------------------------------------------- 1 | package com.yupi.nawoj_backend.common; 2 | 3 | import java.io.Serializable; 4 | 5 | import com.yupi.nawoj_backend.common.enums.ErrorCode; 6 | import lombok.Data; 7 | 8 | /** 9 | * 通用返回类 10 | * 11 | * @param 12 | * @author 程序员鱼皮 13 | * @from 编程导航知识星球 14 | */ 15 | @Data 16 | public class BaseResponse implements Serializable { 17 | 18 | private int code; 19 | 20 | private T data; 21 | 22 | private String message; 23 | 24 | public BaseResponse(int code, T data, String message) { 25 | this.code = code; 26 | this.data = data; 27 | this.message = message; 28 | } 29 | 30 | public BaseResponse(int code, T data) { 31 | this(code, data, ""); 32 | } 33 | 34 | public BaseResponse(ErrorCode errorCode) { 35 | this(errorCode.getCode(), null, errorCode.getMessage()); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /nawoj-backend/src/main/java/com/yupi/nawoj_backend/common/DeleteRequest.java: -------------------------------------------------------------------------------- 1 | package com.yupi.nawoj_backend.common; 2 | 3 | import java.io.Serializable; 4 | import lombok.Data; 5 | 6 | /** 7 | * 删除请求 8 | * 9 | * @author 程序员鱼皮 10 | * @from 编程导航知识星球 11 | */ 12 | @Data 13 | public class DeleteRequest implements Serializable { 14 | 15 | /** 16 | * id 17 | */ 18 | private Long id; 19 | 20 | private static final long serialVersionUID = 1L; 21 | } -------------------------------------------------------------------------------- /nawoj-backend/src/main/java/com/yupi/nawoj_backend/common/PageRequest.java: -------------------------------------------------------------------------------- 1 | package com.yupi.nawoj_backend.common; 2 | 3 | import com.yupi.nawoj_backend.constant.CommonConstant; 4 | import lombok.Data; 5 | 6 | /** 7 | * 分页请求 8 | * 9 | * @author 程序员鱼皮 10 | * @from 编程导航知识星球 11 | */ 12 | @Data 13 | public class PageRequest { 14 | 15 | /** 16 | * 当前页号 17 | */ 18 | private long current = 1; 19 | 20 | /** 21 | * 页面大小 22 | */ 23 | private long pageSize = 10; 24 | 25 | /** 26 | * 排序字段 27 | */ 28 | private String sortField; 29 | 30 | /** 31 | * 排序顺序(默认升序) 32 | */ 33 | private String sortOrder = CommonConstant.SORT_ORDER_ASC; 34 | } 35 | -------------------------------------------------------------------------------- /nawoj-backend/src/main/java/com/yupi/nawoj_backend/common/ResultUtils.java: -------------------------------------------------------------------------------- 1 | package com.yupi.nawoj_backend.common; 2 | 3 | import com.yupi.nawoj_backend.common.enums.ErrorCode; 4 | 5 | /** 6 | * 返回工具类 7 | * 8 | * @author 程序员鱼皮 9 | * @from 编程导航知识星球 10 | */ 11 | public class ResultUtils { 12 | 13 | /** 14 | * 成功 15 | * 16 | * @param data 17 | * @param 18 | * @return 19 | */ 20 | public static BaseResponse success(T data) { 21 | return new BaseResponse<>(0, data, "ok"); 22 | } 23 | 24 | /** 25 | * 失败 26 | * 27 | * @param errorCode 28 | * @return 29 | */ 30 | public static BaseResponse error(ErrorCode errorCode) { 31 | return new BaseResponse<>(errorCode); 32 | } 33 | 34 | /** 35 | * 失败 36 | * 37 | * @param code 38 | * @param message 39 | * @return 40 | */ 41 | public static BaseResponse error(int code, String message) { 42 | return new BaseResponse(code, null, message); 43 | } 44 | 45 | /** 46 | * 失败 47 | * 48 | * @param errorCode 49 | * @return 50 | */ 51 | public static BaseResponse error(ErrorCode errorCode, String message) { 52 | return new BaseResponse(errorCode.getCode(), null, message); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /nawoj-backend/src/main/java/com/yupi/nawoj_backend/common/enums/ErrorCode.java: -------------------------------------------------------------------------------- 1 | package com.yupi.nawoj_backend.common.enums; 2 | 3 | /** 4 | * 自定义错误码 5 | * 6 | * @author 程序员鱼皮 7 | * @from 编程导航知识星球 8 | */ 9 | public enum ErrorCode { 10 | 11 | SUCCESS(0, "ok"), 12 | PARAMS_ERROR(40000, "请求参数错误"), 13 | NOT_LOGIN_ERROR(40100, "未登录"), 14 | NO_AUTH_ERROR(40101, "无权限"), 15 | NOT_FOUND_ERROR(40400, "请求数据不存在"), 16 | FORBIDDEN_ERROR(40300, "禁止访问"), 17 | SYSTEM_ERROR(50000, "系统内部异常"), 18 | OPERATION_ERROR(50001, "操作失败"); 19 | 20 | /** 21 | * 状态码 22 | */ 23 | private final int code; 24 | 25 | /** 26 | * 信息 27 | */ 28 | private final String message; 29 | 30 | ErrorCode(int code, String message) { 31 | this.code = code; 32 | this.message = message; 33 | } 34 | 35 | public int getCode() { 36 | return code; 37 | } 38 | 39 | public String getMessage() { 40 | return message; 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /nawoj-backend/src/main/java/com/yupi/nawoj_backend/common/enums/JudgeInfoMessageEnum.java: -------------------------------------------------------------------------------- 1 | package com.yupi.nawoj_backend.common.enums; 2 | 3 | import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; 4 | 5 | import java.util.Arrays; 6 | import java.util.List; 7 | import java.util.stream.Collectors; 8 | 9 | /** 10 | * @Author peelsannaw 11 | * @create 31/12/2023 15:28 12 | */ 13 | public enum JudgeInfoMessageEnum { 14 | 15 | ACCEPTED("Accepted", "成功"), 16 | WRONG_ANSWER("Wrong Answer", "答案错误"), 17 | COMPILE_ERROR("Compile Error", "编译错误"), 18 | MEMORY_LIMIT_EXCEEDED("Memory Limit Exceeded", "内存溢出"), 19 | TIME_LIMIT_EXCEEDED("Time Limit Exceeded", "超时"), 20 | PRESENTATION_ERROR("Presentation Error", "展示错误"), 21 | WAITING("Waiting", "等待中"), 22 | OUTPUT_LIMIT_EXCEEDED("Output Limit Exceeded", "输出溢出"), 23 | DANGEROUS_OPERATION("Dangerous Operation", "危险操作"), 24 | RUNTIME_ERROR("Runtime Error", "运行错误"), 25 | SYSTEM_ERROR("System Error", "系统错误"); 26 | 27 | private final String text; 28 | 29 | private final String value; 30 | 31 | JudgeInfoMessageEnum(String text, String value) { 32 | this.text = text; 33 | this.value = value; 34 | } 35 | 36 | /** 37 | * 获取值列表 38 | * 39 | * @return 40 | */ 41 | public static List getValues() { 42 | return Arrays.stream(values()).map(item -> item.value).collect(Collectors.toList()); 43 | } 44 | 45 | /** 46 | * 根据 value 获取枚举 47 | * 48 | * @param value 49 | * @return 50 | */ 51 | public static JudgeInfoMessageEnum getEnumByValue(String value) { 52 | if (ObjectUtils.isEmpty(value)) { 53 | return null; 54 | } 55 | for (JudgeInfoMessageEnum anEnum : JudgeInfoMessageEnum.values()) { 56 | if (anEnum.value.equals(value)) { 57 | return anEnum; 58 | } 59 | } 60 | return null; 61 | } 62 | 63 | public String getValue() { 64 | return value; 65 | } 66 | 67 | public String getText() { 68 | return text; 69 | } 70 | 71 | } 72 | -------------------------------------------------------------------------------- /nawoj-backend/src/main/java/com/yupi/nawoj_backend/config/AliyunConfig.java: -------------------------------------------------------------------------------- 1 | package com.yupi.nawoj_backend.config; 2 | 3 | import org.springframework.beans.factory.InitializingBean; 4 | import org.springframework.beans.factory.annotation.Value; 5 | import org.springframework.stereotype.Component; 6 | 7 | /** 8 | * @author peelsannaw 9 | */ 10 | @Component 11 | public class AliyunConfig implements InitializingBean { 12 | 13 | @Value("${aliyun.oss.avatar.endpoint}") 14 | public String endPoint; 15 | @Value("${aliyun.oss.avatar.keyid}") 16 | public String keyId; 17 | @Value("${aliyun.oss.avatar.keysecret}") 18 | public String keySecret; 19 | @Value("${aliyun.oss.avatar.bucketname}") 20 | 21 | public String bucketName; 22 | 23 | public static String END_POINT; 24 | public static String KEY_ID; 25 | public static String KEY_SECRET; 26 | public static String BUCKET_NAME; 27 | 28 | 29 | @Override 30 | public void afterPropertiesSet() throws Exception { 31 | END_POINT = this.endPoint; 32 | KEY_ID = this.keyId; 33 | KEY_SECRET = this.keySecret; 34 | BUCKET_NAME = this.bucketName; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /nawoj-backend/src/main/java/com/yupi/nawoj_backend/config/CorsConfig.java: -------------------------------------------------------------------------------- 1 | package com.yupi.nawoj_backend.config; 2 | 3 | import com.yupi.nawoj_backend.interceptor.GlobalInterceptor; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.web.servlet.config.annotation.CorsRegistry; 6 | import org.springframework.web.servlet.config.annotation.InterceptorRegistry; 7 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; 8 | 9 | import javax.annotation.Resource; 10 | 11 | /** 12 | * 全局跨域配置 13 | * 14 | * @author 程序员鱼皮 15 | * @from 编程导航知识星球 16 | */ 17 | @Configuration 18 | public class CorsConfig implements WebMvcConfigurer { 19 | @Resource 20 | private GlobalInterceptor globalInterceptor; 21 | 22 | @Override 23 | public void addInterceptors(InterceptorRegistry registry) { 24 | registry.addInterceptor(globalInterceptor).addPathPatterns("/**"); 25 | 26 | } 27 | @Override 28 | public void addCorsMappings(CorsRegistry registry) { 29 | // 覆盖所有请求 30 | registry.addMapping("/**") 31 | // 允许发送 Cookie 32 | .allowCredentials(true) 33 | // 放行哪些域名(必须用 patterns,否则 * 会和 allowCredentials 冲突) 34 | .allowedOriginPatterns("*") 35 | .allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS") 36 | .allowedHeaders("*"); 37 | // .exposedHeaders("*"); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /nawoj-backend/src/main/java/com/yupi/nawoj_backend/config/CosClientConfig.java: -------------------------------------------------------------------------------- 1 | package com.yupi.nawoj_backend.config; 2 | 3 | import com.qcloud.cos.COSClient; 4 | import com.qcloud.cos.ClientConfig; 5 | import com.qcloud.cos.auth.BasicCOSCredentials; 6 | import com.qcloud.cos.auth.COSCredentials; 7 | import com.qcloud.cos.region.Region; 8 | import lombok.Data; 9 | import org.springframework.boot.context.properties.ConfigurationProperties; 10 | import org.springframework.context.annotation.Bean; 11 | import org.springframework.context.annotation.Configuration; 12 | 13 | /** 14 | * 腾讯云对象存储客户端 15 | * 16 | * @author 程序员鱼皮 17 | * @from 编程导航知识星球 18 | */ 19 | @Configuration 20 | @ConfigurationProperties(prefix = "cos.client") 21 | @Data 22 | public class CosClientConfig { 23 | 24 | /** 25 | * accessKey 26 | */ 27 | private String accessKey; 28 | 29 | /** 30 | * secretKey 31 | */ 32 | private String secretKey; 33 | 34 | /** 35 | * 区域 36 | */ 37 | private String region; 38 | 39 | /** 40 | * 桶名 41 | */ 42 | private String bucket; 43 | 44 | @Bean 45 | public COSClient cosClient() { 46 | // 初始化用户身份信息(secretId, secretKey) 47 | COSCredentials cred = new BasicCOSCredentials(accessKey, secretKey); 48 | // 设置bucket的区域, COS地域的简称请参照 https://www.qcloud.com/document/product/436/6224 49 | ClientConfig clientConfig = new ClientConfig(new Region(region)); 50 | // 生成cos客户端 51 | return new COSClient(cred, clientConfig); 52 | } 53 | } -------------------------------------------------------------------------------- /nawoj-backend/src/main/java/com/yupi/nawoj_backend/config/FastJsonRedisSerializer.java: -------------------------------------------------------------------------------- 1 | package com.yupi.nawoj_backend.config; 2 | 3 | import com.alibaba.fastjson.JSON; 4 | import com.alibaba.fastjson.parser.ParserConfig; 5 | import com.alibaba.fastjson.serializer.SerializerFeature; 6 | import com.fasterxml.jackson.databind.JavaType; 7 | import com.fasterxml.jackson.databind.type.TypeFactory; 8 | import org.springframework.data.redis.serializer.RedisSerializer; 9 | import org.springframework.data.redis.serializer.SerializationException; 10 | 11 | import java.nio.charset.Charset; 12 | 13 | /** 14 | * Redis使用FastJson序列化 15 | * 16 | * @author sg 17 | */ 18 | public class FastJsonRedisSerializer implements RedisSerializer 19 | { 20 | 21 | public static final Charset DEFAULT_CHARSET = Charset.forName("UTF-8"); 22 | 23 | private Class clazz; 24 | 25 | static 26 | { 27 | ParserConfig.getGlobalInstance().setAutoTypeSupport(true); 28 | } 29 | 30 | public FastJsonRedisSerializer(Class clazz) 31 | { 32 | super(); 33 | this.clazz = clazz; 34 | } 35 | 36 | @Override 37 | public byte[] serialize(T t) throws SerializationException 38 | { 39 | if (t == null) 40 | { 41 | return new byte[0]; 42 | } 43 | return JSON.toJSONString(t, SerializerFeature.WriteClassName).getBytes(DEFAULT_CHARSET); 44 | } 45 | 46 | @Override 47 | public T deserialize(byte[] bytes) throws SerializationException 48 | { 49 | if (bytes == null || bytes.length <= 0) 50 | { 51 | return null; 52 | } 53 | String str = new String(bytes, DEFAULT_CHARSET); 54 | 55 | return JSON.parseObject(str, clazz); 56 | } 57 | 58 | 59 | protected JavaType getJavaType(Class> clazz) 60 | { 61 | return TypeFactory.defaultInstance().constructType(clazz); 62 | } 63 | } -------------------------------------------------------------------------------- /nawoj-backend/src/main/java/com/yupi/nawoj_backend/config/JsonConfig.java: -------------------------------------------------------------------------------- 1 | package com.yupi.nawoj_backend.config; 2 | 3 | import com.fasterxml.jackson.databind.ObjectMapper; 4 | import com.fasterxml.jackson.databind.module.SimpleModule; 5 | import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; 6 | import org.springframework.boot.jackson.JsonComponent; 7 | import org.springframework.context.annotation.Bean; 8 | import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder; 9 | 10 | /** 11 | * Spring MVC Json 配置 12 | * 13 | * @author 程序员鱼皮 14 | * @from 编程导航知识星球 15 | */ 16 | @JsonComponent 17 | public class JsonConfig { 18 | 19 | /** 20 | * 添加 Long 转 json 精度丢失的配置 21 | */ 22 | @Bean 23 | public ObjectMapper jacksonObjectMapper(Jackson2ObjectMapperBuilder builder) { 24 | ObjectMapper objectMapper = builder.createXmlMapper(false).build(); 25 | SimpleModule module = new SimpleModule(); 26 | module.addSerializer(Long.class, ToStringSerializer.instance); 27 | module.addSerializer(Long.TYPE, ToStringSerializer.instance); 28 | objectMapper.registerModule(module); 29 | return objectMapper; 30 | } 31 | } -------------------------------------------------------------------------------- /nawoj-backend/src/main/java/com/yupi/nawoj_backend/config/MyBatisPlusConfig.java: -------------------------------------------------------------------------------- 1 | package com.yupi.nawoj_backend.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 | * @author https://github.com/liyupi 14 | */ 15 | @Configuration 16 | @MapperScan("com.yupi.nawoj_backend.mapper") 17 | public class MyBatisPlusConfig { 18 | 19 | /** 20 | * 拦截器配置 21 | * 22 | * @return 23 | */ 24 | @Bean 25 | public MybatisPlusInterceptor mybatisPlusInterceptor() { 26 | MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor(); 27 | // 分页插件 28 | interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL)); 29 | return interceptor; 30 | } 31 | } -------------------------------------------------------------------------------- /nawoj-backend/src/main/java/com/yupi/nawoj_backend/config/WxOpenConfig.java: -------------------------------------------------------------------------------- 1 | package com.yupi.nawoj_backend.config; 2 | 3 | import lombok.Data; 4 | import lombok.extern.slf4j.Slf4j; 5 | import me.chanjar.weixin.mp.api.WxMpService; 6 | import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl; 7 | import me.chanjar.weixin.mp.config.impl.WxMpDefaultConfigImpl; 8 | import org.springframework.boot.context.properties.ConfigurationProperties; 9 | import org.springframework.context.annotation.Configuration; 10 | 11 | /** 12 | * 微信开放平台配置 13 | * 14 | * @author 程序员鱼皮 15 | * @from 编程导航知识星球 16 | */ 17 | @Slf4j 18 | @Configuration 19 | @ConfigurationProperties(prefix = "wx.open") 20 | @Data 21 | public class WxOpenConfig { 22 | 23 | private String appId; 24 | 25 | private String appSecret; 26 | 27 | private WxMpService wxMpService; 28 | 29 | /** 30 | * 单例模式(不用 @Bean 是为了防止和公众号的 service 冲突) 31 | * 32 | * @return 33 | */ 34 | public WxMpService getWxMpService() { 35 | if (wxMpService != null) { 36 | return wxMpService; 37 | } 38 | synchronized (this) { 39 | if (wxMpService != null) { 40 | return wxMpService; 41 | } 42 | WxMpDefaultConfigImpl config = new WxMpDefaultConfigImpl(); 43 | config.setAppId(appId); 44 | config.setSecret(appSecret); 45 | WxMpService service = new WxMpServiceImpl(); 46 | service.setWxMpConfigStorage(config); 47 | wxMpService = service; 48 | return wxMpService; 49 | } 50 | } 51 | } -------------------------------------------------------------------------------- /nawoj-backend/src/main/java/com/yupi/nawoj_backend/constant/CommonConstant.java: -------------------------------------------------------------------------------- 1 | package com.yupi.nawoj_backend.constant; 2 | 3 | /** 4 | * 通用常量 5 | * 6 | * @author 程序员鱼皮 7 | * @from 编程导航知识星球 8 | */ 9 | public interface CommonConstant { 10 | 11 | /** 12 | * 升序 13 | */ 14 | String SORT_ORDER_ASC = "ascend"; 15 | 16 | /** 17 | * 降序 18 | */ 19 | String SORT_ORDER_DESC = " descend"; 20 | 21 | } 22 | -------------------------------------------------------------------------------- /nawoj-backend/src/main/java/com/yupi/nawoj_backend/constant/FileConstant.java: -------------------------------------------------------------------------------- 1 | package com.yupi.nawoj_backend.constant; 2 | 3 | /** 4 | * 文件常量 5 | * 6 | * @author 程序员鱼皮 7 | * @from 编程导航知识星球 8 | */ 9 | public interface FileConstant { 10 | 11 | /** 12 | * COS 访问地址 13 | * todo 需替换配置 14 | */ 15 | String COS_HOST = "https://yupi.icu"; 16 | } 17 | -------------------------------------------------------------------------------- /nawoj-backend/src/main/java/com/yupi/nawoj_backend/constant/UserConstant.java: -------------------------------------------------------------------------------- 1 | package com.yupi.nawoj_backend.constant; 2 | 3 | /** 4 | * 用户常量 5 | * 6 | * @author 程序员鱼皮 7 | * @from 编程导航知识星球 8 | */ 9 | public interface UserConstant { 10 | 11 | /** 12 | * 用户登录态键 13 | */ 14 | String USER_LOGIN_STATE = "user_login"; 15 | 16 | // region 权限 17 | 18 | /** 19 | * 默认角色 20 | */ 21 | String DEFAULT_ROLE = "user"; 22 | 23 | /** 24 | * 管理员角色 25 | */ 26 | String ADMIN_ROLE = "admin"; 27 | 28 | /** 29 | * 被封号 30 | */ 31 | String BAN_ROLE = "ban"; 32 | 33 | // endregion 34 | } 35 | -------------------------------------------------------------------------------- /nawoj-backend/src/main/java/com/yupi/nawoj_backend/controller/PostThumbController.java: -------------------------------------------------------------------------------- 1 | package com.yupi.nawoj_backend.controller; 2 | 3 | import com.yupi.nawoj_backend.common.BaseResponse; 4 | import com.yupi.nawoj_backend.common.enums.ErrorCode; 5 | import com.yupi.nawoj_backend.common.ResultUtils; 6 | import com.yupi.nawoj_backend.exception.BusinessException; 7 | import com.yupi.nawoj_backend.model.dto.postthumb.PostThumbAddRequest; 8 | import com.yupi.nawoj_backend.model.entity.User; 9 | import com.yupi.nawoj_backend.service.PostThumbService; 10 | import com.yupi.nawoj_backend.service.UserService; 11 | import javax.annotation.Resource; 12 | import javax.servlet.http.HttpServletRequest; 13 | import lombok.extern.slf4j.Slf4j; 14 | import org.springframework.web.bind.annotation.PostMapping; 15 | import org.springframework.web.bind.annotation.RequestBody; 16 | import org.springframework.web.bind.annotation.RequestMapping; 17 | import org.springframework.web.bind.annotation.RestController; 18 | 19 | /** 20 | * 帖子点赞接口 21 | * 22 | * @author 程序员鱼皮 23 | * @from 编程导航知识星球 24 | */ 25 | @RestController 26 | @RequestMapping("/post_thumb") 27 | @Slf4j 28 | public class PostThumbController { 29 | 30 | @Resource 31 | private PostThumbService postThumbService; 32 | 33 | @Resource 34 | private UserService userService; 35 | 36 | /** 37 | * 点赞 / 取消点赞 38 | * 39 | * @param postThumbAddRequest 40 | * @param request 41 | * @return resultNum 本次点赞变化数 42 | */ 43 | @PostMapping("/") 44 | public BaseResponse doThumb(@RequestBody PostThumbAddRequest postThumbAddRequest, 45 | HttpServletRequest request) { 46 | if (postThumbAddRequest == null || postThumbAddRequest.getPostId() <= 0) { 47 | throw new BusinessException(ErrorCode.PARAMS_ERROR); 48 | } 49 | // 登录才能点赞 50 | final User loginUser = userService.getLoginUser(request); 51 | long postId = postThumbAddRequest.getPostId(); 52 | int result = postThumbService.doPostThumb(postId, loginUser); 53 | return ResultUtils.success(result); 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /nawoj-backend/src/main/java/com/yupi/nawoj_backend/controller/QuestionSubmitController.java: -------------------------------------------------------------------------------- 1 | package com.yupi.nawoj_backend.controller; 2 | 3 | import com.yupi.nawoj_backend.common.BaseResponse; 4 | import com.yupi.nawoj_backend.common.enums.ErrorCode; 5 | import com.yupi.nawoj_backend.common.ResultUtils; 6 | import com.yupi.nawoj_backend.exception.BusinessException; 7 | import com.yupi.nawoj_backend.model.dto.questionsubmit.QuestionSubmitAddRequest; 8 | import com.yupi.nawoj_backend.model.entity.User; 9 | import com.yupi.nawoj_backend.service.QuestionSubmitService; 10 | import com.yupi.nawoj_backend.service.UserService; 11 | import javax.annotation.Resource; 12 | import javax.servlet.http.HttpServletRequest; 13 | import lombok.extern.slf4j.Slf4j; 14 | import org.springframework.web.bind.annotation.PostMapping; 15 | import org.springframework.web.bind.annotation.RequestBody; 16 | import org.springframework.web.bind.annotation.RequestMapping; 17 | import org.springframework.web.bind.annotation.RestController; 18 | 19 | /** 20 | * 问题提交接口 21 | * 22 | * @author 程序员鱼皮 23 | * @from 编程导航知识星球 24 | */ 25 | @RestController 26 | @RequestMapping("/question_submit") 27 | @Slf4j 28 | public class QuestionSubmitController { 29 | 30 | @Resource 31 | private QuestionSubmitService QuestionSubmitService; 32 | 33 | @Resource 34 | private UserService userService; 35 | 36 | /** 37 | * 提交题目 38 | * 39 | * @param request 40 | * @return resultNum 本次点赞变化数 41 | */ 42 | @PostMapping("/") 43 | public BaseResponse doSubmit(@RequestBody QuestionSubmitAddRequest questionSubmitAddRequest, 44 | HttpServletRequest request) { 45 | if (questionSubmitAddRequest == null || questionSubmitAddRequest.getQuestionId() <= 0) { 46 | throw new BusinessException(ErrorCode.PARAMS_ERROR); 47 | } 48 | // 登录才能点赞 49 | final User loginUser = userService.getLoginUser(request); 50 | Long submitId = QuestionSubmitService.doQuestionSubmit(questionSubmitAddRequest, loginUser); 51 | return ResultUtils.success(submitId); 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /nawoj-backend/src/main/java/com/yupi/nawoj_backend/esdao/PostEsDao.java: -------------------------------------------------------------------------------- 1 | package com.yupi.nawoj_backend.esdao; 2 | 3 | import com.yupi.nawoj_backend.model.dto.post.PostEsDTO; 4 | import java.util.List; 5 | import org.springframework.data.elasticsearch.repository.ElasticsearchRepository; 6 | 7 | /** 8 | * 帖子 ES 操作 9 | * 10 | * @author 程序员鱼皮 11 | * @from 编程导航知识星球 12 | */ 13 | public interface PostEsDao extends ElasticsearchRepository { 14 | 15 | List findByUserId(Long userId); 16 | } -------------------------------------------------------------------------------- /nawoj-backend/src/main/java/com/yupi/nawoj_backend/exception/BusinessException.java: -------------------------------------------------------------------------------- 1 | package com.yupi.nawoj_backend.exception; 2 | 3 | import com.yupi.nawoj_backend.common.enums.ErrorCode; 4 | 5 | /** 6 | * 自定义异常类 7 | * 8 | * @author 程序员鱼皮 9 | * @from 编程导航知识星球 10 | */ 11 | public class BusinessException extends RuntimeException { 12 | 13 | /** 14 | * 错误码 15 | */ 16 | private final int code; 17 | 18 | public BusinessException(int code, String message) { 19 | super(message); 20 | this.code = code; 21 | } 22 | 23 | public BusinessException(ErrorCode errorCode) { 24 | super(errorCode.getMessage()); 25 | this.code = errorCode.getCode(); 26 | } 27 | 28 | public BusinessException(ErrorCode errorCode, String message) { 29 | super(message); 30 | this.code = errorCode.getCode(); 31 | } 32 | 33 | public int getCode() { 34 | return code; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /nawoj-backend/src/main/java/com/yupi/nawoj_backend/exception/GlobalExceptionHandler.java: -------------------------------------------------------------------------------- 1 | package com.yupi.nawoj_backend.exception; 2 | 3 | import com.yupi.nawoj_backend.common.BaseResponse; 4 | import com.yupi.nawoj_backend.common.enums.ErrorCode; 5 | import com.yupi.nawoj_backend.common.ResultUtils; 6 | import lombok.extern.slf4j.Slf4j; 7 | import org.springframework.web.bind.annotation.ExceptionHandler; 8 | import org.springframework.web.bind.annotation.RestControllerAdvice; 9 | 10 | /** 11 | * 全局异常处理器 12 | * 13 | * @author 程序员鱼皮 14 | * @from 编程导航知识星球 15 | */ 16 | @RestControllerAdvice 17 | @Slf4j 18 | public class GlobalExceptionHandler { 19 | 20 | @ExceptionHandler(BusinessException.class) 21 | public BaseResponse> businessExceptionHandler(BusinessException e) { 22 | log.error("BusinessException", e); 23 | return ResultUtils.error(e.getCode(), e.getMessage()); 24 | } 25 | 26 | @ExceptionHandler(RuntimeException.class) 27 | public BaseResponse> runtimeExceptionHandler(RuntimeException e) { 28 | log.error("RuntimeException", e); 29 | return ResultUtils.error(ErrorCode.SYSTEM_ERROR, "系统错误"); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /nawoj-backend/src/main/java/com/yupi/nawoj_backend/exception/ThrowUtils.java: -------------------------------------------------------------------------------- 1 | package com.yupi.nawoj_backend.exception; 2 | 3 | import com.yupi.nawoj_backend.common.enums.ErrorCode; 4 | 5 | /** 6 | * 抛异常工具类 7 | * 8 | * @author 程序员鱼皮 9 | * @from 编程导航知识星球 10 | */ 11 | public class ThrowUtils { 12 | 13 | /** 14 | * 条件成立则抛异常 15 | * 16 | * @param condition 17 | * @param runtimeException 18 | */ 19 | public static void throwIf(boolean condition, RuntimeException runtimeException) { 20 | if (condition) { 21 | throw runtimeException; 22 | } 23 | } 24 | 25 | /** 26 | * 条件成立则抛异常 27 | * 28 | * @param condition 29 | * @param errorCode 30 | */ 31 | public static void throwIf(boolean condition, ErrorCode errorCode) { 32 | throwIf(condition, new BusinessException(errorCode)); 33 | } 34 | 35 | /** 36 | * 条件成立则抛异常 37 | * 38 | * @param condition 39 | * @param errorCode 40 | * @param message 41 | */ 42 | public static void throwIf(boolean condition, ErrorCode errorCode, String message) { 43 | throwIf(condition, new BusinessException(errorCode, message)); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /nawoj-backend/src/main/java/com/yupi/nawoj_backend/interceptor/GlobalInterceptor.java: -------------------------------------------------------------------------------- 1 | package com.yupi.nawoj_backend.interceptor; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.web.servlet.HandlerInterceptor; 6 | 7 | import javax.servlet.http.HttpServletRequest; 8 | import javax.servlet.http.HttpServletResponse; 9 | 10 | /** 11 | * @Author peelsannaw 12 | * @create 31/12/2023 11:02 13 | */ 14 | @Configuration 15 | @Slf4j 16 | public class GlobalInterceptor implements HandlerInterceptor { 17 | 18 | @Override 19 | public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { 20 | // if("OPTIONS".equals(request.getMethod())){ 21 | // return true; 22 | // } 23 | log.info("请求路径:{}",request.getRequestURL()); 24 | log.info("请求方法:{}",request.getMethod()); 25 | return true; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /nawoj-backend/src/main/java/com/yupi/nawoj_backend/job/cycle/IncSyncPostToEs.java: -------------------------------------------------------------------------------- 1 | package com.yupi.nawoj_backend.job.cycle; 2 | 3 | import com.yupi.nawoj_backend.esdao.PostEsDao; 4 | import com.yupi.nawoj_backend.mapper.PostMapper; 5 | import com.yupi.nawoj_backend.model.dto.post.PostEsDTO; 6 | import com.yupi.nawoj_backend.model.entity.Post; 7 | import java.util.Date; 8 | import java.util.List; 9 | import java.util.stream.Collectors; 10 | import javax.annotation.Resource; 11 | import lombok.extern.slf4j.Slf4j; 12 | import cn.hutool.core.collection.CollUtil; 13 | import org.springframework.scheduling.annotation.Scheduled; 14 | 15 | /** 16 | * 增量同步帖子到 es 17 | * 18 | * @author 程序员鱼皮 19 | * @from 编程导航知识星球 20 | */ 21 | // todo 取消注释开启任务 22 | //@Component 23 | @Slf4j 24 | public class IncSyncPostToEs { 25 | 26 | @Resource 27 | private PostMapper postMapper; 28 | 29 | @Resource 30 | private PostEsDao postEsDao; 31 | 32 | /** 33 | * 每分钟执行一次 34 | */ 35 | @Scheduled(fixedRate = 60 * 1000) 36 | public void run() { 37 | // 查询近 5 分钟内的数据 38 | Date fiveMinutesAgoDate = new Date(new Date().getTime() - 5 * 60 * 1000L); 39 | List postList = postMapper.listPostWithDelete(fiveMinutesAgoDate); 40 | if (CollUtil.isEmpty(postList)) { 41 | log.info("no inc post"); 42 | return; 43 | } 44 | List postEsDTOList = postList.stream() 45 | .map(PostEsDTO::objToDto) 46 | .collect(Collectors.toList()); 47 | final int pageSize = 500; 48 | int total = postEsDTOList.size(); 49 | log.info("IncSyncPostToEs start, total {}", total); 50 | for (int i = 0; i < total; i += pageSize) { 51 | int end = Math.min(i + pageSize, total); 52 | log.info("sync from {} to {}", i, end); 53 | postEsDao.saveAll(postEsDTOList.subList(i, end)); 54 | } 55 | log.info("IncSyncPostToEs end, total {}", total); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /nawoj-backend/src/main/java/com/yupi/nawoj_backend/job/once/FullSyncPostToEs.java: -------------------------------------------------------------------------------- 1 | package com.yupi.nawoj_backend.job.once; 2 | 3 | import com.yupi.nawoj_backend.esdao.PostEsDao; 4 | import com.yupi.nawoj_backend.model.dto.post.PostEsDTO; 5 | import com.yupi.nawoj_backend.model.entity.Post; 6 | import com.yupi.nawoj_backend.service.PostService; 7 | import java.util.List; 8 | import java.util.stream.Collectors; 9 | import javax.annotation.Resource; 10 | import lombok.extern.slf4j.Slf4j; 11 | import cn.hutool.core.collection.CollUtil; 12 | import org.springframework.boot.CommandLineRunner; 13 | 14 | /** 15 | * 全量同步帖子到 es 16 | * 17 | * @author 程序员鱼皮 18 | * @from 编程导航知识星球 19 | */ 20 | // todo 取消注释开启任务 21 | //@Component 22 | @Slf4j 23 | public class FullSyncPostToEs implements CommandLineRunner { 24 | 25 | @Resource 26 | private PostService postService; 27 | 28 | @Resource 29 | private PostEsDao postEsDao; 30 | 31 | @Override 32 | public void run(String... args) { 33 | List postList = postService.list(); 34 | if (CollUtil.isEmpty(postList)) { 35 | return; 36 | } 37 | List postEsDTOList = postList.stream().map(PostEsDTO::objToDto).collect(Collectors.toList()); 38 | final int pageSize = 500; 39 | int total = postEsDTOList.size(); 40 | log.info("FullSyncPostToEs start, total {}", total); 41 | for (int i = 0; i < total; i += pageSize) { 42 | int end = Math.min(i + pageSize, total); 43 | log.info("sync from {} to {}", i, end); 44 | postEsDao.saveAll(postEsDTOList.subList(i, end)); 45 | } 46 | log.info("FullSyncPostToEs end, total {}", total); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /nawoj-backend/src/main/java/com/yupi/nawoj_backend/manager/AliManager.java: -------------------------------------------------------------------------------- 1 | package com.yupi.nawoj_backend.manager; 2 | 3 | import cn.hutool.core.lang.UUID; 4 | import com.aliyun.oss.OSS; 5 | import com.aliyun.oss.OSSClientBuilder; 6 | import com.yupi.nawoj_backend.config.AliyunConfig; 7 | import com.yupi.nawoj_backend.model.enums.AppHttpCodeEnum; 8 | import org.joda.time.DateTime; 9 | import org.springframework.stereotype.Component; 10 | import org.springframework.web.multipart.MultipartFile; 11 | 12 | import java.io.InputStream; 13 | 14 | /** 15 | * @Author peelsannaw 16 | * @create 29/12/2023 15:09 17 | */ 18 | @Component 19 | public class AliManager { 20 | 21 | private static final String endpoint = AliyunConfig.END_POINT; 22 | private static final String accessKeyId = AliyunConfig.KEY_ID; 23 | private static final String accessKeySecret = AliyunConfig.KEY_SECRET; 24 | private static final String bucketName = AliyunConfig.BUCKET_NAME; 25 | 26 | public String uploadImg(MultipartFile file){ 27 | try { 28 | // 创建OSS实例。 29 | OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret); 30 | 31 | //获取上传文件输入流 32 | InputStream inputStream = file.getInputStream(); 33 | //获取文件名称 34 | String fileName = file.getOriginalFilename(); 35 | 36 | //1 在文件名称里面添加随机唯一的值 37 | String uuid = UUID.randomUUID().toString().replaceAll("-",""); 38 | // yuy76t5rew01.jpg 39 | fileName = uuid+fileName; 40 | 41 | //2 把文件按照日期进行分类 42 | //获取当前日期 43 | String datePath = new DateTime().toString("yyyy/MM/dd"); 44 | //拼接 45 | fileName = datePath+"/"+fileName; 46 | 47 | //调用oss方法实现上传 48 | //第一个参数 Bucket名称 49 | //第二个参数 上传到oss文件路径和文件名称 aa/bb/1.jpg 50 | //第三个参数 上传文件输入流 51 | ossClient.putObject(bucketName,fileName , inputStream); 52 | 53 | // 关闭OSSClient。 54 | ossClient.shutdown(); 55 | 56 | return "https://"+bucketName+"."+endpoint+"/"+fileName; 57 | }catch(Exception e) { 58 | e.printStackTrace(); 59 | throw new RuntimeException(AppHttpCodeEnum.PARAM_IMAGE_FORMAT_ERROR.getErrorMessage()); 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /nawoj-backend/src/main/java/com/yupi/nawoj_backend/manager/CosManager.java: -------------------------------------------------------------------------------- 1 | package com.yupi.nawoj_backend.manager; 2 | 3 | import com.qcloud.cos.COSClient; 4 | import com.qcloud.cos.model.PutObjectRequest; 5 | import com.qcloud.cos.model.PutObjectResult; 6 | import com.yupi.nawoj_backend.config.CosClientConfig; 7 | import java.io.File; 8 | import javax.annotation.Resource; 9 | import org.springframework.stereotype.Component; 10 | 11 | /** 12 | * Cos 对象存储操作 13 | * 14 | * @author 程序员鱼皮 15 | * @from 编程导航知识星球 16 | */ 17 | @Component 18 | public class CosManager { 19 | 20 | @Resource 21 | private CosClientConfig cosClientConfig; 22 | 23 | @Resource 24 | private COSClient cosClient; 25 | 26 | /** 27 | * 上传对象 28 | * 29 | * @param key 唯一键 30 | * @param localFilePath 本地文件路径 31 | * @return 32 | */ 33 | public PutObjectResult putObject(String key, String localFilePath) { 34 | PutObjectRequest putObjectRequest = new PutObjectRequest(cosClientConfig.getBucket(), key, 35 | new File(localFilePath)); 36 | return cosClient.putObject(putObjectRequest); 37 | } 38 | 39 | /** 40 | * 上传对象 41 | * 42 | * @param key 唯一键 43 | * @param file 文件 44 | * @return 45 | */ 46 | public PutObjectResult putObject(String key, File file) { 47 | PutObjectRequest putObjectRequest = new PutObjectRequest(cosClientConfig.getBucket(), key, 48 | file); 49 | return cosClient.putObject(putObjectRequest); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /nawoj-backend/src/main/java/com/yupi/nawoj_backend/mapper/PostFavourMapper.java: -------------------------------------------------------------------------------- 1 | package com.yupi.nawoj_backend.mapper; 2 | 3 | import com.baomidou.mybatisplus.core.conditions.Wrapper; 4 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 5 | import com.baomidou.mybatisplus.core.metadata.IPage; 6 | import com.baomidou.mybatisplus.core.toolkit.Constants; 7 | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; 8 | 9 | import com.yupi.nawoj_backend.model.entity.Post; 10 | import com.yupi.nawoj_backend.model.entity.PostFavour; 11 | import org.apache.ibatis.annotations.Mapper; 12 | import org.apache.ibatis.annotations.Param; 13 | 14 | /** 15 | * 帖子收藏数据库操作 16 | * 17 | * @author 程序员鱼皮 18 | * @from 编程导航知识星球 19 | */ 20 | @Mapper 21 | 22 | public interface PostFavourMapper extends BaseMapper { 23 | 24 | /** 25 | * 分页查询收藏帖子列表 26 | * 27 | * @param page 28 | * @param queryWrapper 29 | * @param favourUserId 30 | * @return 31 | */ 32 | Page listFavourPostByPage(IPage page, @Param(Constants.WRAPPER) Wrapper queryWrapper, 33 | long favourUserId); 34 | 35 | } 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /nawoj-backend/src/main/java/com/yupi/nawoj_backend/mapper/PostMapper.java: -------------------------------------------------------------------------------- 1 | package com.yupi.nawoj_backend.mapper; 2 | 3 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 4 | import com.yupi.nawoj_backend.model.entity.Post; 5 | import org.apache.ibatis.annotations.Mapper; 6 | 7 | import java.util.Date; 8 | import java.util.List; 9 | 10 | /** 11 | * 帖子数据库操作 12 | * 13 | * @author 程序员鱼皮 14 | * @from 编程导航知识星球 15 | */ 16 | @Mapper 17 | 18 | public interface PostMapper extends BaseMapper { 19 | 20 | /** 21 | * 查询帖子列表(包括已被删除的数据) 22 | */ 23 | List listPostWithDelete(Date minUpdateTime); 24 | 25 | } 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /nawoj-backend/src/main/java/com/yupi/nawoj_backend/mapper/PostThumbMapper.java: -------------------------------------------------------------------------------- 1 | package com.yupi.nawoj_backend.mapper; 2 | 3 | 4 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 5 | import com.yupi.nawoj_backend.model.entity.PostThumb; 6 | import org.apache.ibatis.annotations.Mapper; 7 | 8 | /** 9 | * 帖子点赞数据库操作 10 | * 11 | * @author 程序员鱼皮 12 | * @from 编程导航知识星球 13 | */ 14 | @Mapper 15 | 16 | public interface PostThumbMapper extends BaseMapper { 17 | 18 | } 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /nawoj-backend/src/main/java/com/yupi/nawoj_backend/mapper/QuestionMapper.java: -------------------------------------------------------------------------------- 1 | package com.yupi.nawoj_backend.mapper; 2 | 3 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 4 | import com.yupi.nawoj_backend.model.entity.Question; 5 | import org.apache.ibatis.annotations.Mapper; 6 | 7 | /** 8 | * @author 李鱼皮 9 | * @description 针对表【question(题目)】的数据库操作Mapper 10 | * @createDate 2023-08-07 20:58:00 11 | * @Entity com.yupi.yuoj.model.entity.Question 12 | */ 13 | @Mapper 14 | 15 | public interface QuestionMapper extends BaseMapper { 16 | 17 | } 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /nawoj-backend/src/main/java/com/yupi/nawoj_backend/mapper/QuestionSubmitMapper.java: -------------------------------------------------------------------------------- 1 | package com.yupi.nawoj_backend.mapper; 2 | 3 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 4 | import com.yupi.nawoj_backend.model.entity.QuestionSubmit; 5 | import org.apache.ibatis.annotations.Mapper; 6 | 7 | /** 8 | * @author 李鱼皮 9 | * @description 针对表【question_submit(题目提交)】的数据库操作Mapper 10 | * @createDate 2023-08-07 20:58:53 11 | * @Entity com.yupi.yuoj.model.entity.QuestionSubmit 12 | */ 13 | @Mapper 14 | public interface QuestionSubmitMapper extends BaseMapper { 15 | 16 | } 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /nawoj-backend/src/main/java/com/yupi/nawoj_backend/mapper/UserMapper.java: -------------------------------------------------------------------------------- 1 | package com.yupi.nawoj_backend.mapper; 2 | 3 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 4 | import com.yupi.nawoj_backend.model.entity.User; 5 | import org.apache.ibatis.annotations.Mapper; 6 | 7 | /** 8 | * 用户数据库操作 9 | * 10 | * @author 程序员鱼皮 11 | * @from 编程导航知识星球 12 | */ 13 | @Mapper 14 | 15 | public interface UserMapper extends BaseMapper { 16 | 17 | } 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /nawoj-backend/src/main/java/com/yupi/nawoj_backend/model/dto/file/UploadFileRequest.java: -------------------------------------------------------------------------------- 1 | package com.yupi.nawoj_backend.model.dto.file; 2 | 3 | import java.io.Serializable; 4 | import lombok.Data; 5 | 6 | /** 7 | * 文件上传请求 8 | * 9 | * @author 程序员鱼皮 10 | * @from 编程导航知识星球 11 | */ 12 | @Data 13 | public class UploadFileRequest implements Serializable { 14 | 15 | /** 16 | * 业务 17 | */ 18 | private String biz; 19 | 20 | private static final long serialVersionUID = 1L; 21 | } -------------------------------------------------------------------------------- /nawoj-backend/src/main/java/com/yupi/nawoj_backend/model/dto/post/PostAddRequest.java: -------------------------------------------------------------------------------- 1 | package com.yupi.nawoj_backend.model.dto.post; 2 | 3 | import java.io.Serializable; 4 | import java.util.List; 5 | import lombok.Data; 6 | 7 | /** 8 | * 创建请求 9 | * 10 | * @author 程序员鱼皮 11 | * @from 编程导航知识星球 12 | */ 13 | @Data 14 | public class PostAddRequest implements Serializable { 15 | 16 | /** 17 | * 标题 18 | */ 19 | private String title; 20 | 21 | /** 22 | * 内容 23 | */ 24 | private String content; 25 | 26 | /** 27 | * 标签列表 28 | */ 29 | private List tags; 30 | 31 | private static final long serialVersionUID = 1L; 32 | } -------------------------------------------------------------------------------- /nawoj-backend/src/main/java/com/yupi/nawoj_backend/model/dto/post/PostEditRequest.java: -------------------------------------------------------------------------------- 1 | package com.yupi.nawoj_backend.model.dto.post; 2 | 3 | import java.io.Serializable; 4 | import java.util.List; 5 | import lombok.Data; 6 | 7 | /** 8 | * 编辑请求 9 | * 10 | * @author 程序员鱼皮 11 | * @from 编程导航知识星球 12 | */ 13 | @Data 14 | public class PostEditRequest implements Serializable { 15 | 16 | /** 17 | * id 18 | */ 19 | private Long id; 20 | 21 | /** 22 | * 标题 23 | */ 24 | private String title; 25 | 26 | /** 27 | * 内容 28 | */ 29 | private String content; 30 | 31 | /** 32 | * 标签列表 33 | */ 34 | private List tags; 35 | 36 | private static final long serialVersionUID = 1L; 37 | } -------------------------------------------------------------------------------- /nawoj-backend/src/main/java/com/yupi/nawoj_backend/model/dto/post/PostQueryRequest.java: -------------------------------------------------------------------------------- 1 | package com.yupi.nawoj_backend.model.dto.post; 2 | import java.io.Serializable; 3 | import java.util.List; 4 | 5 | import com.yupi.nawoj_backend.common.PageRequest; 6 | import lombok.Data; 7 | import lombok.EqualsAndHashCode; 8 | 9 | /** 10 | * 查询请求 11 | * 12 | * @author 程序员鱼皮 13 | * @from 编程导航知识星球 14 | */ 15 | @EqualsAndHashCode(callSuper = true) 16 | @Data 17 | public class PostQueryRequest extends PageRequest implements Serializable { 18 | 19 | /** 20 | * id 21 | */ 22 | private Long id; 23 | 24 | /** 25 | * id 26 | */ 27 | private Long notId; 28 | 29 | /** 30 | * 搜索词 31 | */ 32 | private String searchText; 33 | 34 | /** 35 | * 标题 36 | */ 37 | private String title; 38 | 39 | /** 40 | * 内容 41 | */ 42 | private String content; 43 | 44 | /** 45 | * 标签列表 46 | */ 47 | private List tags; 48 | 49 | /** 50 | * 至少有一个标签 51 | */ 52 | private List orTags; 53 | 54 | /** 55 | * 创建用户 id 56 | */ 57 | private Long userId; 58 | 59 | /** 60 | * 收藏用户 id 61 | */ 62 | private Long favourUserId; 63 | 64 | private static final long serialVersionUID = 1L; 65 | } -------------------------------------------------------------------------------- /nawoj-backend/src/main/java/com/yupi/nawoj_backend/model/dto/post/PostUpdateRequest.java: -------------------------------------------------------------------------------- 1 | package com.yupi.nawoj_backend.model.dto.post; 2 | 3 | import java.io.Serializable; 4 | import java.util.List; 5 | import lombok.Data; 6 | 7 | /** 8 | * 更新请求 9 | * 10 | * @author 程序员鱼皮 11 | * @from 编程导航知识星球 12 | */ 13 | @Data 14 | public class PostUpdateRequest implements Serializable { 15 | 16 | /** 17 | * id 18 | */ 19 | private Long id; 20 | 21 | /** 22 | * 标题 23 | */ 24 | private String title; 25 | 26 | /** 27 | * 内容 28 | */ 29 | private String content; 30 | 31 | /** 32 | * 标签列表 33 | */ 34 | private List tags; 35 | 36 | private static final long serialVersionUID = 1L; 37 | } -------------------------------------------------------------------------------- /nawoj-backend/src/main/java/com/yupi/nawoj_backend/model/dto/postfavour/PostFavourAddRequest.java: -------------------------------------------------------------------------------- 1 | package com.yupi.nawoj_backend.model.dto.postfavour; 2 | 3 | import java.io.Serializable; 4 | import lombok.Data; 5 | 6 | /** 7 | * 帖子收藏 / 取消收藏请求 8 | * 9 | * @author 程序员鱼皮 10 | * @from 编程导航知识星球 11 | */ 12 | @Data 13 | public class PostFavourAddRequest implements Serializable { 14 | 15 | /** 16 | * 帖子 id 17 | */ 18 | private Long postId; 19 | 20 | private static final long serialVersionUID = 1L; 21 | } -------------------------------------------------------------------------------- /nawoj-backend/src/main/java/com/yupi/nawoj_backend/model/dto/postfavour/PostFavourQueryRequest.java: -------------------------------------------------------------------------------- 1 | package com.yupi.nawoj_backend.model.dto.postfavour; 2 | 3 | import java.io.Serializable; 4 | 5 | import com.yupi.nawoj_backend.common.PageRequest; 6 | import com.yupi.nawoj_backend.model.dto.post.PostQueryRequest; 7 | import lombok.Data; 8 | import lombok.EqualsAndHashCode; 9 | 10 | /** 11 | * 帖子收藏查询请求 12 | * 13 | * @author 程序员鱼皮 14 | * @from 编程导航知识星球 15 | */ 16 | @Data 17 | @EqualsAndHashCode(callSuper = true) 18 | public class PostFavourQueryRequest extends PageRequest implements Serializable { 19 | 20 | /** 21 | * 帖子查询请求 22 | */ 23 | private PostQueryRequest postQueryRequest; 24 | 25 | /** 26 | * 用户 id 27 | */ 28 | private Long userId; 29 | 30 | private static final long serialVersionUID = 1L; 31 | } -------------------------------------------------------------------------------- /nawoj-backend/src/main/java/com/yupi/nawoj_backend/model/dto/postthumb/PostThumbAddRequest.java: -------------------------------------------------------------------------------- 1 | package com.yupi.nawoj_backend.model.dto.postthumb; 2 | 3 | import java.io.Serializable; 4 | import lombok.Data; 5 | 6 | /** 7 | * 帖子点赞请求 8 | * 9 | * @author 程序员鱼皮 10 | * @from 编程导航知识星球 11 | */ 12 | @Data 13 | public class PostThumbAddRequest implements Serializable { 14 | 15 | /** 16 | * 帖子 id 17 | */ 18 | private Long postId; 19 | 20 | private static final long serialVersionUID = 1L; 21 | } -------------------------------------------------------------------------------- /nawoj-backend/src/main/java/com/yupi/nawoj_backend/model/dto/question/QuestionAddRequest.java: -------------------------------------------------------------------------------- 1 | package com.yupi.nawoj_backend.model.dto.question; 2 | 3 | import lombok.Data; 4 | 5 | import java.io.Serializable; 6 | import java.util.List; 7 | 8 | /** 9 | * 创建请求 10 | * 11 | * @author 程序员鱼皮 12 | * @from 编程导航知识星球 13 | */ 14 | @Data 15 | public class QuestionAddRequest implements Serializable { 16 | 17 | /** 18 | * 标题 19 | */ 20 | private String title; 21 | 22 | /** 23 | * 内容 24 | */ 25 | private String content; 26 | 27 | /** 28 | * 标签列表 29 | */ 30 | private List tags; 31 | 32 | /** 33 | * 题目答案 34 | */ 35 | private String answer; 36 | 37 | /** 38 | * 判题用例 39 | */ 40 | private List judgeCase; 41 | 42 | /** 43 | * 判题配置 44 | */ 45 | private QuestionJudgeConfig judgeConfig; 46 | 47 | /** 48 | * 判题描述 49 | */ 50 | private QuestionJudgeDescription judgeDescription; 51 | 52 | 53 | private static final long serialVersionUID = 1L; 54 | } -------------------------------------------------------------------------------- /nawoj-backend/src/main/java/com/yupi/nawoj_backend/model/dto/question/QuestionEditRequest.java: -------------------------------------------------------------------------------- 1 | package com.yupi.nawoj_backend.model.dto.question; 2 | 3 | import lombok.Data; 4 | 5 | import java.io.Serializable; 6 | import java.util.List; 7 | 8 | /** 9 | * 编辑请求 10 | * 11 | * @author 程序员鱼皮 12 | * @from 编程导航知识星球 13 | */ 14 | @Data 15 | public class QuestionEditRequest implements Serializable { 16 | 17 | /** 18 | * id 19 | */ 20 | private Long id; 21 | 22 | /** 23 | * 标题 24 | */ 25 | private String title; 26 | 27 | /** 28 | * 内容 29 | */ 30 | private String content; 31 | 32 | /** 33 | * 标签列表 34 | */ 35 | private List tags; 36 | 37 | /** 38 | * 题目答案 39 | */ 40 | private String answer; 41 | 42 | /** 43 | * 判题用例 44 | */ 45 | private List judgeCase; 46 | 47 | /** 48 | * 判题描述 49 | */ 50 | private QuestionJudgeDescription judgeDescription; 51 | 52 | /** 53 | * 判题配置 54 | */ 55 | private QuestionJudgeConfig judgeConfig; 56 | 57 | private static final long serialVersionUID = 1L; 58 | } -------------------------------------------------------------------------------- /nawoj-backend/src/main/java/com/yupi/nawoj_backend/model/dto/question/QuestionJudgeCase.java: -------------------------------------------------------------------------------- 1 | package com.yupi.nawoj_backend.model.dto.question; 2 | 3 | import lombok.Data; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * 题目用例 9 | */ 10 | @Data 11 | public class QuestionJudgeCase { 12 | 13 | /** 14 | * 输入用例 15 | */ 16 | private String input; 17 | 18 | /** 19 | * 输出用例 20 | */ 21 | private String output; 22 | } 23 | -------------------------------------------------------------------------------- /nawoj-backend/src/main/java/com/yupi/nawoj_backend/model/dto/question/QuestionJudgeConfig.java: -------------------------------------------------------------------------------- 1 | package com.yupi.nawoj_backend.model.dto.question; 2 | 3 | import lombok.Data; 4 | 5 | /** 6 | * 题目配置 7 | */ 8 | @Data 9 | public class QuestionJudgeConfig { 10 | 11 | /** 12 | * 时间限制(ms) 13 | */ 14 | private Long timeLimit; 15 | 16 | /** 17 | * 内存限制(KB) 18 | */ 19 | private Long memoryLimit; 20 | 21 | /** 22 | * 堆栈限制(KB) 23 | */ 24 | private Long stackLimit; 25 | } 26 | -------------------------------------------------------------------------------- /nawoj-backend/src/main/java/com/yupi/nawoj_backend/model/dto/question/QuestionJudgeDescription.java: -------------------------------------------------------------------------------- 1 | package com.yupi.nawoj_backend.model.dto.question; 2 | 3 | import lombok.Data; 4 | 5 | /** 6 | * @Author peelsannaw 7 | * @create 06/01/2024 18:21 8 | * 问题输入输出描述 势力 9 | */ 10 | 11 | @Data 12 | public class QuestionJudgeDescription { 13 | //输入格式 14 | String inputFormat; 15 | 16 | //输出格式 17 | String outputFormat; 18 | 19 | //数据范围 20 | String dataRange; 21 | 22 | } 23 | -------------------------------------------------------------------------------- /nawoj-backend/src/main/java/com/yupi/nawoj_backend/model/dto/question/QuestionQueryRequest.java: -------------------------------------------------------------------------------- 1 | package com.yupi.nawoj_backend.model.dto.question; 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.yupi.nawoj_backend.common.PageRequest; 7 | import lombok.Data; 8 | import lombok.EqualsAndHashCode; 9 | 10 | import java.io.Serializable; 11 | import java.util.Date; 12 | import java.util.List; 13 | 14 | /** 15 | * 查询请求 16 | * 17 | * @author 程序员鱼皮 18 | * @from 编程导航知识星球 19 | */ 20 | @EqualsAndHashCode(callSuper = true) 21 | @Data 22 | public class QuestionQueryRequest extends PageRequest implements Serializable { 23 | 24 | /** 25 | * id 26 | */ 27 | private Long id; 28 | 29 | /** 30 | * 标题 31 | */ 32 | private String title; 33 | 34 | /** 35 | * 内容 36 | */ 37 | private String content; 38 | 39 | /** 40 | * 标签列表 41 | */ 42 | private List tags; 43 | 44 | // /** 45 | // * 题目答案 46 | // */ 47 | // private String answer; 48 | private String userName; 49 | /** 50 | * 创建用户 id 51 | */ 52 | private Long userId; 53 | 54 | private static final long serialVersionUID = 1L; 55 | } -------------------------------------------------------------------------------- /nawoj-backend/src/main/java/com/yupi/nawoj_backend/model/dto/question/QuestionUpdateRequest.java: -------------------------------------------------------------------------------- 1 | package com.yupi.nawoj_backend.model.dto.question; 2 | 3 | import lombok.Data; 4 | 5 | import java.io.Serializable; 6 | import java.util.List; 7 | 8 | /** 9 | * 更新请求 10 | * 11 | * @author 程序员鱼皮 12 | * @from 编程导航知识星球 13 | */ 14 | @Data 15 | public class QuestionUpdateRequest implements Serializable { 16 | 17 | 18 | /** 19 | * id 20 | */ 21 | private Long id; 22 | 23 | /** 24 | * 标题 25 | */ 26 | private String title; 27 | 28 | /** 29 | * 内容 30 | */ 31 | private String content; 32 | 33 | /** 34 | * 标签列表 35 | */ 36 | private List tags; 37 | 38 | /** 39 | * 题目答案 40 | */ 41 | private String answer; 42 | 43 | /** 44 | * 判题用例 45 | */ 46 | private List judgeCase; 47 | 48 | /** 49 | * 判题配置 50 | */ 51 | private QuestionJudgeConfig judgeConfig; 52 | 53 | /** 54 | * 题目描述 55 | */ 56 | private QuestionJudgeDescription judgeDescription; 57 | 58 | 59 | private static final long serialVersionUID = 1L; 60 | } -------------------------------------------------------------------------------- /nawoj-backend/src/main/java/com/yupi/nawoj_backend/model/dto/questionsubmit/QuestionJudgeInfo.java: -------------------------------------------------------------------------------- 1 | package com.yupi.nawoj_backend.model.dto.questionsubmit; 2 | 3 | import lombok.Data; 4 | 5 | /** 6 | * @Author peelsannaw 7 | * @create 31/12/2023 23:05 8 | * 判题信息 9 | */ 10 | @Data 11 | public class QuestionJudgeInfo { 12 | 13 | /** 14 | * 程序执行信息 15 | */ 16 | private String message; 17 | 18 | /** 19 | * 内存消耗(KB) 20 | */ 21 | private Long memoryLimit; 22 | 23 | /** 24 | * 栈消耗(KB) 25 | */ 26 | private Long stackLimit; 27 | } 28 | -------------------------------------------------------------------------------- /nawoj-backend/src/main/java/com/yupi/nawoj_backend/model/dto/questionsubmit/QuestionSubmitAddRequest.java: -------------------------------------------------------------------------------- 1 | package com.yupi.nawoj_backend.model.dto.questionsubmit; 2 | 3 | import lombok.Data; 4 | 5 | import java.io.Serializable; 6 | 7 | /** 8 | * 创建请求 9 | * 10 | * @author 程序员鱼皮 11 | * @from 编程导航知识星球 12 | */ 13 | @Data 14 | public class QuestionSubmitAddRequest implements Serializable { 15 | 16 | //用户ID存放于Session中 17 | 18 | /** 19 | * 编程语言 20 | */ 21 | private String language; 22 | 23 | /** 24 | * 用户代码 25 | */ 26 | private String code; 27 | 28 | /** 29 | * 题目 id 30 | */ 31 | private Long questionId; 32 | 33 | 34 | private static final long serialVersionUID = 1L; 35 | } -------------------------------------------------------------------------------- /nawoj-backend/src/main/java/com/yupi/nawoj_backend/model/dto/questionsubmit/QuestionSubmitQueryRequest.java: -------------------------------------------------------------------------------- 1 | package com.yupi.nawoj_backend.model.dto.questionsubmit; 2 | 3 | 4 | import com.yupi.nawoj_backend.common.PageRequest; 5 | import lombok.Data; 6 | import lombok.EqualsAndHashCode; 7 | 8 | import java.io.Serializable; 9 | 10 | /** 11 | * 查询请求 12 | * 13 | * @author 程序员鱼皮 14 | * @from 编程导航知识星球 15 | */ 16 | @Data 17 | @EqualsAndHashCode(callSuper = true) 18 | public class QuestionSubmitQueryRequest extends PageRequest implements Serializable { 19 | 20 | /** 21 | * 编程语言 22 | */ 23 | private String language; 24 | 25 | /** 26 | * 提交状态 27 | */ 28 | private Integer status; 29 | 30 | /** 31 | * 题目 id 32 | */ 33 | private Long questionId; 34 | 35 | 36 | /** 37 | * 用户 id 38 | */ 39 | private Long userId; 40 | 41 | private static final long serialVersionUID = 1L; 42 | } -------------------------------------------------------------------------------- /nawoj-backend/src/main/java/com/yupi/nawoj_backend/model/dto/user/UserAddRequest.java: -------------------------------------------------------------------------------- 1 | package com.yupi.nawoj_backend.model.dto.user; 2 | 3 | import java.io.Serializable; 4 | import lombok.Data; 5 | 6 | /** 7 | * 用户创建请求 8 | * 9 | * @author 程序员鱼皮 10 | * @from 编程导航知识星球 11 | */ 12 | @Data 13 | public class UserAddRequest implements Serializable { 14 | 15 | /** 16 | * 用户昵称 17 | */ 18 | private String userName; 19 | 20 | /** 21 | * 账号 22 | */ 23 | private String userAccount; 24 | 25 | /** 26 | * 用户头像 27 | */ 28 | private String userAvatar; 29 | 30 | /** 31 | * 用户角色: user, admin 32 | */ 33 | private String userRole; 34 | 35 | private static final long serialVersionUID = 1L; 36 | } -------------------------------------------------------------------------------- /nawoj-backend/src/main/java/com/yupi/nawoj_backend/model/dto/user/UserLoginRequest.java: -------------------------------------------------------------------------------- 1 | package com.yupi.nawoj_backend.model.dto.user; 2 | 3 | import java.io.Serializable; 4 | import lombok.Data; 5 | 6 | /** 7 | * 用户登录请求 8 | * 9 | * @author 程序员鱼皮 10 | * @from 编程导航知识星球 11 | */ 12 | @Data 13 | public class UserLoginRequest implements Serializable { 14 | 15 | private static final long serialVersionUID = 3191241716373120793L; 16 | 17 | private String userAccount; 18 | 19 | private String userPassword; 20 | } 21 | -------------------------------------------------------------------------------- /nawoj-backend/src/main/java/com/yupi/nawoj_backend/model/dto/user/UserQueryRequest.java: -------------------------------------------------------------------------------- 1 | package com.yupi.nawoj_backend.model.dto.user; 2 | 3 | import com.yupi.nawoj_backend.common.PageRequest; 4 | import java.io.Serializable; 5 | import lombok.Data; 6 | import lombok.EqualsAndHashCode; 7 | 8 | /** 9 | * 用户查询请求 10 | * 11 | * @author 程序员鱼皮 12 | * @from 编程导航知识星球 13 | */ 14 | @EqualsAndHashCode(callSuper = true) 15 | @Data 16 | public class UserQueryRequest extends PageRequest implements Serializable { 17 | /** 18 | * id 19 | */ 20 | private Long id; 21 | 22 | /** 23 | * 开放平台id 24 | */ 25 | private String unionId; 26 | 27 | /** 28 | * 公众号openId 29 | */ 30 | private String mpOpenId; 31 | 32 | /** 33 | * 用户昵称 34 | */ 35 | private String userName; 36 | 37 | /** 38 | * 简介 39 | */ 40 | private String userProfile; 41 | 42 | /** 43 | * 用户角色:user/admin/ban 44 | */ 45 | private String userRole; 46 | 47 | private static final long serialVersionUID = 1L; 48 | } -------------------------------------------------------------------------------- /nawoj-backend/src/main/java/com/yupi/nawoj_backend/model/dto/user/UserRegisterRequest.java: -------------------------------------------------------------------------------- 1 | package com.yupi.nawoj_backend.model.dto.user; 2 | 3 | import java.io.Serializable; 4 | import lombok.Data; 5 | 6 | /** 7 | * 用户注册请求体 8 | * 9 | * @author 程序员鱼皮 10 | * @from 编程导航知识星球 11 | */ 12 | @Data 13 | public class UserRegisterRequest implements Serializable { 14 | 15 | private static final long serialVersionUID = 3191241716373120793L; 16 | 17 | private String userAccount; 18 | 19 | private String userPassword; 20 | 21 | private String checkPassword; 22 | 23 | private String userAvatar; 24 | } 25 | -------------------------------------------------------------------------------- /nawoj-backend/src/main/java/com/yupi/nawoj_backend/model/dto/user/UserUpdateMyRequest.java: -------------------------------------------------------------------------------- 1 | package com.yupi.nawoj_backend.model.dto.user; 2 | 3 | import java.io.Serializable; 4 | import lombok.Data; 5 | 6 | /** 7 | * 用户更新个人信息请求 8 | * 9 | * @author 程序员鱼皮 10 | * @from 编程导航知识星球 11 | */ 12 | @Data 13 | public class UserUpdateMyRequest implements Serializable { 14 | 15 | /** 16 | * 用户昵称 17 | */ 18 | private String userName; 19 | 20 | /** 21 | * 用户头像 22 | */ 23 | private String userAvatar; 24 | 25 | /** 26 | * 简介 27 | */ 28 | private String userProfile; 29 | 30 | private static final long serialVersionUID = 1L; 31 | } -------------------------------------------------------------------------------- /nawoj-backend/src/main/java/com/yupi/nawoj_backend/model/dto/user/UserUpdateRequest.java: -------------------------------------------------------------------------------- 1 | package com.yupi.nawoj_backend.model.dto.user; 2 | 3 | import java.io.Serializable; 4 | import lombok.Data; 5 | 6 | /** 7 | * 用户更新请求 8 | * 9 | * @author 程序员鱼皮 10 | * @from 编程导航知识星球 11 | */ 12 | @Data 13 | public class UserUpdateRequest implements Serializable { 14 | /** 15 | * id 16 | */ 17 | private Long id; 18 | 19 | /** 20 | * 用户昵称 21 | */ 22 | private String userName; 23 | 24 | /** 25 | * 用户头像 26 | */ 27 | private String userAvatar; 28 | 29 | /** 30 | * 简介 31 | */ 32 | private String userProfile; 33 | 34 | /** 35 | * 用户角色:user/admin/ban 36 | */ 37 | private String userRole; 38 | 39 | private static final long serialVersionUID = 1L; 40 | } -------------------------------------------------------------------------------- /nawoj-backend/src/main/java/com/yupi/nawoj_backend/model/entity/Post.java: -------------------------------------------------------------------------------- 1 | package com.yupi.nawoj_backend.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.TableLogic; 7 | import com.baomidou.mybatisplus.annotation.TableName; 8 | import java.io.Serializable; 9 | import java.util.Date; 10 | import lombok.Data; 11 | 12 | /** 13 | * 帖子 14 | * 15 | * @author 程序员鱼皮 16 | * @from 编程导航知识星球 17 | */ 18 | @TableName(value = "post") 19 | @Data 20 | public class Post implements Serializable { 21 | 22 | /** 23 | * id 24 | */ 25 | @TableId(type = IdType.ASSIGN_ID) 26 | private Long id; 27 | 28 | /** 29 | * 标题 30 | */ 31 | private String title; 32 | 33 | /** 34 | * 内容 35 | */ 36 | private String content; 37 | 38 | /** 39 | * 标签列表 json 40 | */ 41 | private String tags; 42 | 43 | /** 44 | * 点赞数 45 | */ 46 | private Integer thumbNum; 47 | 48 | /** 49 | * 收藏数 50 | */ 51 | private Integer favourNum; 52 | 53 | /** 54 | * 创建用户 id 55 | */ 56 | private Long userId; 57 | 58 | /** 59 | * 创建时间 60 | */ 61 | private Date createTime; 62 | 63 | /** 64 | * 更新时间 65 | */ 66 | private Date updateTime; 67 | 68 | /** 69 | * 是否删除 70 | */ 71 | @TableLogic 72 | private Integer isDelete; 73 | 74 | @TableField(exist = false) 75 | private static final long serialVersionUID = 1L; 76 | } -------------------------------------------------------------------------------- /nawoj-backend/src/main/java/com/yupi/nawoj_backend/model/entity/PostFavour.java: -------------------------------------------------------------------------------- 1 | package com.yupi.nawoj_backend.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 java.io.Serializable; 8 | import java.util.Date; 9 | import lombok.Data; 10 | 11 | /** 12 | * 帖子收藏 13 | * 14 | * @author 程序员鱼皮 15 | * @from 编程导航知识星球 16 | **/ 17 | @TableName(value = "post_favour") 18 | @Data 19 | public class PostFavour implements Serializable { 20 | 21 | /** 22 | * id 23 | */ 24 | @TableId(type = IdType.AUTO) 25 | private Long id; 26 | 27 | /** 28 | * 帖子 id 29 | */ 30 | private Long postId; 31 | 32 | /** 33 | * 创建用户 id 34 | */ 35 | private Long userId; 36 | 37 | /** 38 | * 创建时间 39 | */ 40 | private Date createTime; 41 | 42 | /** 43 | * 更新时间 44 | */ 45 | private Date updateTime; 46 | 47 | @TableField(exist = false) 48 | private static final long serialVersionUID = 1L; 49 | } -------------------------------------------------------------------------------- /nawoj-backend/src/main/java/com/yupi/nawoj_backend/model/entity/PostThumb.java: -------------------------------------------------------------------------------- 1 | package com.yupi.nawoj_backend.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 java.io.Serializable; 8 | import java.util.Date; 9 | import lombok.Data; 10 | 11 | /** 12 | * 帖子点赞 13 | * 14 | * @author 程序员鱼皮 15 | * @from 编程导航知识星球 16 | */ 17 | @TableName(value = "post_thumb") 18 | @Data 19 | public class PostThumb implements Serializable { 20 | 21 | /** 22 | * id 23 | */ 24 | @TableId(type = IdType.AUTO) 25 | private Long id; 26 | 27 | /** 28 | * 帖子 id 29 | */ 30 | private Long postId; 31 | 32 | /** 33 | * 创建用户 id 34 | */ 35 | private Long userId; 36 | 37 | /** 38 | * 创建时间 39 | */ 40 | private Date createTime; 41 | 42 | /** 43 | * 更新时间 44 | */ 45 | private Date updateTime; 46 | 47 | @TableField(exist = false) 48 | private static final long serialVersionUID = 1L; 49 | } -------------------------------------------------------------------------------- /nawoj-backend/src/main/java/com/yupi/nawoj_backend/model/entity/Question.java: -------------------------------------------------------------------------------- 1 | package com.yupi.nawoj_backend.model.entity; 2 | 3 | import cn.hutool.core.bean.BeanUtil; 4 | import com.alibaba.fastjson.JSON; 5 | import com.baomidou.mybatisplus.annotation.*; 6 | 7 | import java.io.Serializable; 8 | import java.util.Date; 9 | import java.util.List; 10 | 11 | import com.google.gson.reflect.TypeToken; 12 | import com.yupi.nawoj_backend.model.vo.PostVO; 13 | import com.yupi.nawoj_backend.model.vo.QuestionVO; 14 | import lombok.Data; 15 | import org.springframework.beans.BeanUtils; 16 | 17 | /** 18 | * 题目 19 | * @TableName question 20 | */ 21 | @TableName(value ="question") 22 | @Data 23 | public class Question implements Serializable { 24 | /** 25 | * id 26 | */ 27 | @TableId(type = IdType.ASSIGN_ID) 28 | private Long id; 29 | 30 | /** 31 | * 标题 32 | */ 33 | private String title; 34 | 35 | /** 36 | * 内容 37 | */ 38 | private String content; 39 | 40 | /** 41 | * 标签列表(json 数组) 42 | */ 43 | private String tags; 44 | 45 | /** 46 | * 题目答案 47 | */ 48 | private String answer; 49 | 50 | /** 51 | * 题目提交数 52 | */ 53 | private Integer submitNum; 54 | 55 | /** 56 | * 题目通过数 57 | */ 58 | private Integer acceptedNum; 59 | 60 | /** 61 | * 判题用例(json 数组) 62 | */ 63 | private String judgeCase; 64 | 65 | /** 66 | * 判题配置(json 对象) 67 | */ 68 | private String judgeConfig; 69 | 70 | /** 71 | * 判题描述 (json 对象) 72 | */ 73 | private String judgeDescription; 74 | 75 | /** 76 | * 点赞数 77 | */ 78 | private Integer thumbNum; 79 | 80 | /** 81 | * 收藏数 82 | */ 83 | private Integer favourNum; 84 | 85 | /** 86 | * 创建用户 id 87 | */ 88 | private Long userId; 89 | 90 | /** 91 | * 创建时间 92 | */ 93 | private Date createTime; 94 | 95 | /** 96 | * 更新时间 97 | */ 98 | private Date updateTime; 99 | 100 | /** 101 | * 是否删除 102 | */ 103 | @TableLogic 104 | private Integer isDelete; 105 | 106 | @TableField(exist = false) 107 | private static final long serialVersionUID = 1L; 108 | 109 | 110 | } -------------------------------------------------------------------------------- /nawoj-backend/src/main/java/com/yupi/nawoj_backend/model/entity/QuestionSubmit.java: -------------------------------------------------------------------------------- 1 | package com.yupi.nawoj_backend.model.entity; 2 | 3 | import com.baomidou.mybatisplus.annotation.*; 4 | 5 | import java.io.Serializable; 6 | import java.util.Date; 7 | import lombok.Data; 8 | 9 | /** 10 | * 题目提交 11 | * @TableName question_submit 12 | */ 13 | @TableName(value ="question_submit") 14 | @Data 15 | public class QuestionSubmit implements Serializable { 16 | /** 17 | * id 18 | */ 19 | @TableId(type = IdType.ASSIGN_ID) 20 | private Long id; 21 | 22 | /** 23 | * 编程语言 24 | */ 25 | private String language; 26 | 27 | /** 28 | * 用户代码 29 | */ 30 | private String code; 31 | 32 | /** 33 | * 判题信息(json 对象) 34 | */ 35 | private String judgeInfo; 36 | 37 | /** 38 | * 判题状态(0 - 待判题、1 - 判题中、2 - 成功、3 - 失败) 39 | */ 40 | private Integer status; 41 | 42 | /** 43 | * 题目 id 44 | */ 45 | private Long questionId; 46 | 47 | /** 48 | * 创建用户 id 49 | */ 50 | private Long userId; 51 | 52 | /** 53 | * 创建时间 54 | */ 55 | private Date createTime; 56 | 57 | /** 58 | * 更新时间 59 | */ 60 | private Date updateTime; 61 | 62 | /** 63 | * 是否删除 64 | */ 65 | @TableLogic 66 | private Integer isDelete; 67 | 68 | @TableField(exist = false) 69 | private static final long serialVersionUID = 1L; 70 | } -------------------------------------------------------------------------------- /nawoj-backend/src/main/java/com/yupi/nawoj_backend/model/entity/User.java: -------------------------------------------------------------------------------- 1 | package com.yupi.nawoj_backend.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.TableLogic; 7 | import com.baomidou.mybatisplus.annotation.TableName; 8 | import java.io.Serializable; 9 | import java.util.Date; 10 | import lombok.Data; 11 | 12 | /** 13 | * 用户 14 | * 15 | * @author 程序员鱼皮 16 | * @from 编程导航知识星球 17 | */ 18 | @TableName(value = "user") 19 | @Data 20 | public class User implements Serializable { 21 | 22 | /** 23 | * id 24 | */ 25 | @TableId(type = IdType.ASSIGN_ID) 26 | private Long id; 27 | 28 | /** 29 | * 用户账号 30 | */ 31 | private String userAccount; 32 | 33 | /** 34 | * 用户密码 35 | */ 36 | private String userPassword; 37 | 38 | /** 39 | * 开放平台id 40 | */ 41 | private String unionId; 42 | 43 | /** 44 | * 公众号openId 45 | */ 46 | private String mpOpenId; 47 | 48 | /** 49 | * 用户昵称 50 | */ 51 | private String userName; 52 | 53 | /** 54 | * 用户头像 55 | */ 56 | private String userAvatar; 57 | 58 | /** 59 | * 用户简介 60 | */ 61 | private String userProfile; 62 | 63 | /** 64 | * 用户角色:user/admin/ban 65 | */ 66 | private String userRole; 67 | 68 | /** 69 | * 创建时间 70 | */ 71 | private Date createTime; 72 | 73 | /** 74 | * 更新时间 75 | */ 76 | private Date updateTime; 77 | 78 | /** 79 | * 是否删除 80 | */ 81 | @TableLogic 82 | private Integer isDelete; 83 | 84 | @TableField(exist = false) 85 | private static final long serialVersionUID = 1L; 86 | } -------------------------------------------------------------------------------- /nawoj-backend/src/main/java/com/yupi/nawoj_backend/model/enums/AppHttpCodeEnum.java: -------------------------------------------------------------------------------- 1 | package com.yupi.nawoj_backend.model.enums; 2 | 3 | import com.baomidou.mybatisplus.annotation.EnumValue; 4 | 5 | public enum AppHttpCodeEnum { 6 | 7 | // 成功段0 8 | SUCCESS(200,"操作成功"), 9 | // 登录段1~50 10 | NEED_LOGIN(1,"需要登录后操作"), 11 | LOGIN_PASSWORD_ERROR(2,"密码错误"), 12 | LOGIN_PARAMS_ERROR(3,"缺少参数"), 13 | // TOKEN50~100 14 | TOKEN_INVALID(50,"无效的TOKEN"), 15 | TOKEN_EXPIRE(51,"TOKEN已过期"), 16 | TOKEN_REQUIRE(52,"TOKEN是必须的"), 17 | 18 | // 参数错误 500~1000 19 | PARAM_REQUIRE(500,"缺少参数"), 20 | PARAM_INVALID(501,"无效参数"), 21 | PARAM_IMAGE_FORMAT_ERROR(502,"图片格式有误"), 22 | SERVER_ERROR(503,"服务器内部错误"), 23 | // 数据错误 1000~2000 24 | DATA_EXIST(1000,"数据已经存在"), 25 | DATA_NOT_EXIST(1002,"数据不存在"), 26 | // 数据错误 3000~3500 27 | NO_OPERATOR_AUTH(3000,"无权限操作"), 28 | NEED_ADMIN(3001,"需要管理员权限"); 29 | 30 | 31 | @EnumValue 32 | final int code; 33 | 34 | @EnumValue 35 | final String errorMessage; 36 | 37 | AppHttpCodeEnum(int code, String errorMessage){ 38 | this.code = code; 39 | this.errorMessage = errorMessage; 40 | } 41 | 42 | public int getCode() { 43 | return code; 44 | } 45 | 46 | public String getErrorMessage() { 47 | return errorMessage; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /nawoj-backend/src/main/java/com/yupi/nawoj_backend/model/enums/FileUploadBizEnum.java: -------------------------------------------------------------------------------- 1 | package com.yupi.nawoj_backend.model.enums; 2 | 3 | import java.util.Arrays; 4 | import java.util.List; 5 | import java.util.stream.Collectors; 6 | import org.apache.commons.lang3.ObjectUtils; 7 | 8 | /** 9 | * 文件上传业务类型枚举 10 | * 11 | * @author 程序员鱼皮 12 | * @from 编程导航知识星球 13 | */ 14 | public enum FileUploadBizEnum { 15 | 16 | USER_AVATAR("用户头像", "user_avatar"); 17 | 18 | private final String text; 19 | 20 | private final String value; 21 | 22 | FileUploadBizEnum(String text, String value) { 23 | this.text = text; 24 | this.value = value; 25 | } 26 | 27 | /** 28 | * 获取值列表 29 | * 30 | * @return 31 | */ 32 | public static List getValues() { 33 | return Arrays.stream(values()).map(item -> item.value).collect(Collectors.toList()); 34 | } 35 | 36 | /** 37 | * 根据 value 获取枚举 38 | * 39 | * @param value 40 | * @return 41 | */ 42 | public static FileUploadBizEnum getEnumByValue(String value) { 43 | if (ObjectUtils.isEmpty(value)) { 44 | return null; 45 | } 46 | for (FileUploadBizEnum anEnum : FileUploadBizEnum.values()) { 47 | if (anEnum.value.equals(value)) { 48 | return anEnum; 49 | } 50 | } 51 | return null; 52 | } 53 | 54 | public String getValue() { 55 | return value; 56 | } 57 | 58 | public String getText() { 59 | return text; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /nawoj-backend/src/main/java/com/yupi/nawoj_backend/model/enums/JudgeInfoMessageEnum.java: -------------------------------------------------------------------------------- 1 | package com.yupi.nawoj_backend.model.enums; 2 | 3 | import org.apache.commons.lang3.ObjectUtils; 4 | 5 | import java.util.Arrays; 6 | import java.util.List; 7 | import java.util.stream.Collectors; 8 | 9 | /** 10 | * 判题信息消息枚举 11 | * 12 | * @author 程序员鱼皮 13 | * @from 编程导航知识星球 14 | */ 15 | public enum JudgeInfoMessageEnum { 16 | 17 | ACCEPTED("成功", "Accepted"), 18 | WRONG_ANSWER("答案错误", "Wrong Answer"), 19 | COMPILE_ERROR("Compile Error", "编译错误"), 20 | MEMORY_LIMIT_EXCEEDED("", "内存溢出"), 21 | TIME_LIMIT_EXCEEDED("Time Limit Exceeded", "超时"), 22 | PRESENTATION_ERROR("Presentation Error", "展示错误"), 23 | WAITING("Waiting", "等待中"), 24 | OUTPUT_LIMIT_EXCEEDED("Output Limit Exceeded", "输出溢出"), 25 | DANGEROUS_OPERATION("Dangerous Operation", "危险操作"), 26 | RUNTIME_ERROR("Runtime Error", "运行错误"), 27 | SYSTEM_ERROR("System Error", "系统错误"); 28 | 29 | private final String text; 30 | 31 | private final String value; 32 | 33 | JudgeInfoMessageEnum(String text, String value) { 34 | this.text = text; 35 | this.value = value; 36 | } 37 | 38 | /** 39 | * 获取值列表 40 | * 41 | * @return 42 | */ 43 | public static List getValues() { 44 | return Arrays.stream(values()).map(item -> item.value).collect(Collectors.toList()); 45 | } 46 | 47 | /** 48 | * 根据 value 获取枚举 49 | * 50 | * @param value 51 | * @return 52 | */ 53 | public static JudgeInfoMessageEnum getEnumByValue(String value) { 54 | if (ObjectUtils.isEmpty(value)) { 55 | return null; 56 | } 57 | for (JudgeInfoMessageEnum anEnum : JudgeInfoMessageEnum.values()) { 58 | if (anEnum.value.equals(value)) { 59 | return anEnum; 60 | } 61 | } 62 | return null; 63 | } 64 | 65 | public String getValue() { 66 | return value; 67 | } 68 | 69 | public String getText() { 70 | return text; 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /nawoj-backend/src/main/java/com/yupi/nawoj_backend/model/enums/QuestionSubmitLanguageEnum.java: -------------------------------------------------------------------------------- 1 | package com.yupi.nawoj_backend.model.enums; 2 | 3 | import org.apache.commons.lang3.ObjectUtils; 4 | 5 | import java.util.Arrays; 6 | import java.util.List; 7 | import java.util.stream.Collectors; 8 | 9 | /** 10 | * 题目提交编程语言枚举 11 | * 12 | * @author 程序员鱼皮 13 | * @from 编程导航知识星球 14 | */ 15 | public enum QuestionSubmitLanguageEnum { 16 | 17 | JAVA("java", "java"), 18 | CPLUSPLUS("cpp", "cpp"), 19 | GOLANG("go", "go"); 20 | 21 | private final String text; 22 | 23 | private final String value; 24 | 25 | QuestionSubmitLanguageEnum(String text, String value) { 26 | this.text = text; 27 | this.value = value; 28 | } 29 | 30 | /** 31 | * 获取值列表 32 | * 33 | * @return 34 | */ 35 | public static List getValues() { 36 | return Arrays.stream(values()).map(item -> item.value).collect(Collectors.toList()); 37 | } 38 | 39 | /** 40 | * 根据 value 获取枚举 41 | * 42 | * @param value 43 | * @return 44 | */ 45 | public static QuestionSubmitLanguageEnum getEnumByValue(String value) { 46 | if (ObjectUtils.isEmpty(value)) { 47 | return null; 48 | } 49 | for (QuestionSubmitLanguageEnum anEnum : QuestionSubmitLanguageEnum.values()) { 50 | if (anEnum.value.equals(value)) { 51 | return anEnum; 52 | } 53 | } 54 | return null; 55 | } 56 | 57 | public String getValue() { 58 | return value; 59 | } 60 | 61 | public String getText() { 62 | return text; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /nawoj-backend/src/main/java/com/yupi/nawoj_backend/model/enums/QuestionSubmitStatusEnum.java: -------------------------------------------------------------------------------- 1 | package com.yupi.nawoj_backend.model.enums; 2 | 3 | import org.apache.commons.lang3.ObjectUtils; 4 | 5 | import java.util.Arrays; 6 | import java.util.List; 7 | import java.util.stream.Collectors; 8 | 9 | /** 10 | * 题目提交枚举 11 | * 12 | * @author 程序员鱼皮 13 | * @from 编程导航知识星球 14 | */ 15 | public enum QuestionSubmitStatusEnum { 16 | 17 | // 0 - 待判题、1 - 判题中、2 - 成功、3 - 失败 18 | WAITING("等待中", 0), 19 | RUNNING("判题中", 1), 20 | SUCCEED("成功", 2), 21 | FAILED("失败", 3); 22 | 23 | private final String text; 24 | 25 | private final Integer value; 26 | 27 | QuestionSubmitStatusEnum(String text, Integer value) { 28 | this.text = text; 29 | this.value = value; 30 | } 31 | 32 | /** 33 | * 获取值列表 34 | * 35 | * @return 36 | */ 37 | public static List getValues() { 38 | return Arrays.stream(values()).map(item -> item.value).collect(Collectors.toList()); 39 | } 40 | 41 | /** 42 | * 根据 value 获取枚举 43 | * 44 | * @param value 45 | * @return 46 | */ 47 | public static QuestionSubmitStatusEnum getEnumByValue(Integer value) { 48 | if (ObjectUtils.isEmpty(value)) { 49 | return null; 50 | } 51 | 52 | for (QuestionSubmitStatusEnum anEnum : QuestionSubmitStatusEnum.values()) { 53 | if (anEnum.value.equals(value)) { 54 | return anEnum; 55 | } 56 | } 57 | return null; 58 | } 59 | 60 | public Integer getValue() { 61 | return value; 62 | } 63 | 64 | public String getText() { 65 | return text; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /nawoj-backend/src/main/java/com/yupi/nawoj_backend/model/enums/UserRoleEnum.java: -------------------------------------------------------------------------------- 1 | package com.yupi.nawoj_backend.model.enums; 2 | 3 | import java.util.Arrays; 4 | import java.util.List; 5 | import java.util.stream.Collectors; 6 | import org.apache.commons.lang3.ObjectUtils; 7 | 8 | /** 9 | * 用户角色枚举 10 | * 11 | * @author 程序员鱼皮 12 | * @from 编程导航知识星球 13 | */ 14 | public enum UserRoleEnum { 15 | 16 | GUEST("游客","guest"), 17 | USER("用户", "user"), 18 | ADMIN("管理员", "admin"), 19 | BAN("被封号", "ban"); 20 | 21 | private final String text; 22 | 23 | private final String value; 24 | 25 | 26 | 27 | UserRoleEnum(String text, String value) { 28 | this.text = text; 29 | this.value = value; 30 | } 31 | 32 | /** 33 | * 获取值列表 34 | * 35 | * @return 36 | */ 37 | public static List getValues() { 38 | return Arrays.stream(values()).map(item -> item.value).collect(Collectors.toList()); 39 | } 40 | 41 | /** 42 | * 根据 value 获取枚举 43 | * 44 | * @param value 45 | * @return 46 | */ 47 | public static UserRoleEnum getEnumByValue(String value) { 48 | if (ObjectUtils.isEmpty(value)) { 49 | return null; 50 | } 51 | for (UserRoleEnum anEnum : UserRoleEnum.values()) { 52 | if (anEnum.value.equals(value)) { 53 | return anEnum; 54 | } 55 | } 56 | return null; 57 | } 58 | 59 | public static Integer getUserRoleCodeByValue(String userRole) { 60 | switch (userRole){ 61 | case "guest": return 0; 62 | case "user": return 1; 63 | case "admin": return 2; 64 | default: return -1; 65 | } 66 | } 67 | 68 | public String getValue() { 69 | return value; 70 | } 71 | 72 | public String getText() { 73 | return text; 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /nawoj-backend/src/main/java/com/yupi/nawoj_backend/model/vo/LoginUserVO.java: -------------------------------------------------------------------------------- 1 | package com.yupi.nawoj_backend.model.vo; 2 | 3 | import java.io.Serializable; 4 | import java.util.Date; 5 | import lombok.Data; 6 | 7 | /** 8 | * 已登录用户视图(脱敏) 9 | * 10 | * @author 程序员鱼皮 11 | * @from 编程导航知识星球 12 | **/ 13 | @Data 14 | public class LoginUserVO implements Serializable { 15 | 16 | /** 17 | * 用户 id 18 | */ 19 | private Long id; 20 | 21 | /** 22 | * 用户昵称 23 | */ 24 | private String userName; 25 | 26 | /** 27 | * 用户头像 28 | */ 29 | private String userAvatar; 30 | 31 | /** 32 | * 用户简介 33 | */ 34 | private String userProfile; 35 | 36 | /** 37 | * 用户角色:user/admin/ban 38 | */ 39 | private String userRole; 40 | 41 | /** 42 | * 用户角色: guest:0 user:1 admin:2 ban:-1 43 | */ 44 | private Integer access; 45 | 46 | /** 47 | * 创建时间 48 | */ 49 | private Date createTime; 50 | 51 | /** 52 | * 更新时间 53 | */ 54 | private Date updateTime; 55 | 56 | private static final long serialVersionUID = 1L; 57 | } -------------------------------------------------------------------------------- /nawoj-backend/src/main/java/com/yupi/nawoj_backend/model/vo/PostVO.java: -------------------------------------------------------------------------------- 1 | package com.yupi.nawoj_backend.model.vo; 2 | 3 | import com.google.gson.Gson; 4 | import com.google.gson.reflect.TypeToken; 5 | import java.io.Serializable; 6 | import java.util.Date; 7 | import java.util.List; 8 | 9 | import com.yupi.nawoj_backend.model.entity.Post; 10 | import lombok.Data; 11 | import org.springframework.beans.BeanUtils; 12 | 13 | /** 14 | * 帖子视图 15 | * 16 | * @author 程序员鱼皮 17 | * @from 编程导航知识星球 18 | */ 19 | @Data 20 | public class PostVO implements Serializable { 21 | 22 | private final static Gson GSON = new Gson(); 23 | 24 | /** 25 | * id 26 | */ 27 | private Long id; 28 | 29 | /** 30 | * 标题 31 | */ 32 | private String title; 33 | 34 | /** 35 | * 内容 36 | */ 37 | private String content; 38 | 39 | /** 40 | * 点赞数 41 | */ 42 | private Integer thumbNum; 43 | 44 | /** 45 | * 收藏数 46 | */ 47 | private Integer favourNum; 48 | 49 | /** 50 | * 创建用户 id 51 | */ 52 | private Long userId; 53 | 54 | /** 55 | * 创建时间 56 | */ 57 | private Date createTime; 58 | 59 | /** 60 | * 更新时间 61 | */ 62 | private Date updateTime; 63 | 64 | /** 65 | * 标签列表 66 | */ 67 | private List tagList; 68 | 69 | /** 70 | * 创建人信息 71 | */ 72 | private UserVO user; 73 | 74 | /** 75 | * 是否已点赞 76 | */ 77 | private Boolean hasThumb; 78 | 79 | /** 80 | * 是否已收藏 81 | */ 82 | private Boolean hasFavour; 83 | 84 | /** 85 | * 包装类转对象 86 | * 87 | * @param postVO 88 | * @return 89 | */ 90 | public static Post voToObj(PostVO postVO) { 91 | if (postVO == null) { 92 | return null; 93 | } 94 | Post post = new Post(); 95 | BeanUtils.copyProperties(postVO, post); 96 | List tagList = postVO.getTagList(); 97 | if (tagList != null) { 98 | post.setTags(GSON.toJson(tagList)); 99 | } 100 | return post; 101 | } 102 | 103 | /** 104 | * 对象转包装类 105 | * 106 | * @param post 107 | * @return 108 | */ 109 | public static PostVO objToVo(Post post) { 110 | if (post == null) { 111 | return null; 112 | } 113 | PostVO postVO = new PostVO(); 114 | BeanUtils.copyProperties(post, postVO); 115 | postVO.setTagList(GSON.fromJson(post.getTags(), new TypeToken>() { 116 | }.getType())); 117 | return postVO; 118 | } 119 | } 120 | -------------------------------------------------------------------------------- /nawoj-backend/src/main/java/com/yupi/nawoj_backend/model/vo/UserVO.java: -------------------------------------------------------------------------------- 1 | package com.yupi.nawoj_backend.model.vo; 2 | 3 | import java.io.Serializable; 4 | import java.util.Date; 5 | import lombok.Data; 6 | 7 | /** 8 | * 用户视图(脱敏) 9 | * 10 | * @author 程序员鱼皮 11 | * @from 编程导航知识星球 12 | */ 13 | @Data 14 | public class UserVO implements Serializable { 15 | 16 | /** 17 | * id 18 | */ 19 | private Long id; 20 | 21 | /** 22 | * 用户昵称 23 | */ 24 | private String userName; 25 | 26 | /** 27 | * 用户头像 28 | */ 29 | private String userAvatar; 30 | 31 | /** 32 | * 用户简介 33 | */ 34 | private String userProfile; 35 | 36 | /** 37 | * 用户角色:user/admin/ban 38 | */ 39 | private String userRole; 40 | 41 | /** 42 | * 创建时间 43 | */ 44 | private Date createTime; 45 | 46 | private static final long serialVersionUID = 1L; 47 | } -------------------------------------------------------------------------------- /nawoj-backend/src/main/java/com/yupi/nawoj_backend/service/PostFavourService.java: -------------------------------------------------------------------------------- 1 | package com.yupi.nawoj_backend.service; 2 | 3 | import com.baomidou.mybatisplus.core.conditions.Wrapper; 4 | import com.baomidou.mybatisplus.core.metadata.IPage; 5 | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; 6 | import com.baomidou.mybatisplus.extension.service.IService; 7 | import com.yupi.nawoj_backend.model.entity.Post; 8 | import com.yupi.nawoj_backend.model.entity.PostFavour; 9 | import com.yupi.nawoj_backend.model.entity.User; 10 | 11 | /** 12 | * 帖子收藏服务 13 | * 14 | * @author 程序员鱼皮 15 | * @from 编程导航知识星球 16 | */ 17 | public interface PostFavourService extends IService { 18 | 19 | /** 20 | * 帖子收藏 21 | * 22 | * @param postId 23 | * @param loginUser 24 | * @return 25 | */ 26 | int doPostFavour(long postId, User loginUser); 27 | 28 | /** 29 | * 分页获取用户收藏的帖子列表 30 | * 31 | * @param page 32 | * @param queryWrapper 33 | * @param favourUserId 34 | * @return 35 | */ 36 | Page listFavourPostByPage(IPage page, Wrapper queryWrapper, 37 | long favourUserId); 38 | 39 | /** 40 | * 帖子收藏(内部服务) 41 | * 42 | * @param userId 43 | * @param postId 44 | * @return 45 | */ 46 | int doPostFavourInner(long userId, long postId); 47 | } 48 | -------------------------------------------------------------------------------- /nawoj-backend/src/main/java/com/yupi/nawoj_backend/service/PostService.java: -------------------------------------------------------------------------------- 1 | package com.yupi.nawoj_backend.service; 2 | 3 | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; 4 | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; 5 | import com.baomidou.mybatisplus.extension.service.IService; 6 | import com.yupi.nawoj_backend.model.dto.post.PostQueryRequest; 7 | import com.yupi.nawoj_backend.model.entity.Post; 8 | import com.yupi.nawoj_backend.model.vo.PostVO; 9 | import javax.servlet.http.HttpServletRequest; 10 | 11 | /** 12 | * 帖子服务 13 | * 14 | * @author 程序员鱼皮 15 | * @from 编程导航知识星球 16 | */ 17 | public interface PostService extends IService { 18 | 19 | /** 20 | * 校验 21 | * 22 | * @param post 23 | * @param add 24 | */ 25 | void validPost(Post post, boolean add); 26 | 27 | /** 28 | * 获取查询条件 29 | * 30 | * @param postQueryRequest 31 | * @return 32 | */ 33 | QueryWrapper getQueryWrapper(PostQueryRequest postQueryRequest); 34 | 35 | /** 36 | * 从 ES 查询 37 | * 38 | * @param postQueryRequest 39 | * @return 40 | */ 41 | Page searchFromEs(PostQueryRequest postQueryRequest); 42 | 43 | /** 44 | * 获取帖子封装 45 | * 46 | * @param post 47 | * @param request 48 | * @return 49 | */ 50 | PostVO getPostVO(Post post, HttpServletRequest request); 51 | 52 | /** 53 | * 分页获取帖子封装 54 | * 55 | * @param postPage 56 | * @param request 57 | * @return 58 | */ 59 | Page getPostVOPage(Page postPage, HttpServletRequest request); 60 | } 61 | -------------------------------------------------------------------------------- /nawoj-backend/src/main/java/com/yupi/nawoj_backend/service/PostThumbService.java: -------------------------------------------------------------------------------- 1 | package com.yupi.nawoj_backend.service; 2 | 3 | import com.yupi.nawoj_backend.model.entity.PostThumb; 4 | import com.baomidou.mybatisplus.extension.service.IService; 5 | import com.yupi.nawoj_backend.model.entity.User; 6 | 7 | /** 8 | * 帖子点赞服务 9 | * 10 | * @author 程序员鱼皮 11 | * @from 编程导航知识星球 12 | */ 13 | public interface PostThumbService extends IService { 14 | 15 | /** 16 | * 点赞 17 | * 18 | * @param postId 19 | * @param loginUser 20 | * @return 21 | */ 22 | int doPostThumb(long postId, User loginUser); 23 | 24 | /** 25 | * 帖子点赞(内部服务) 26 | * 27 | * @param userId 28 | * @param postId 29 | * @return 30 | */ 31 | int doPostThumbInner(long userId, long postId); 32 | } 33 | -------------------------------------------------------------------------------- /nawoj-backend/src/main/java/com/yupi/nawoj_backend/service/QuestionService.java: -------------------------------------------------------------------------------- 1 | package com.yupi.nawoj_backend.service; 2 | 3 | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; 4 | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; 5 | import com.baomidou.mybatisplus.extension.service.IService; 6 | 7 | import com.yupi.nawoj_backend.model.dto.question.QuestionQueryRequest; 8 | import com.yupi.nawoj_backend.model.entity.Question; 9 | import com.yupi.nawoj_backend.model.entity.Question; 10 | import com.yupi.nawoj_backend.model.entity.User; 11 | import com.yupi.nawoj_backend.model.vo.QuestionVO; 12 | 13 | import javax.servlet.http.HttpServletRequest; 14 | 15 | /** 16 | * @Author peelsannaw 17 | * @create 31/12/2023 17:34 18 | */ 19 | public interface QuestionService extends IService { 20 | 21 | 22 | /** 23 | * 校验 24 | * 25 | * @param Question 26 | * @param add 27 | */ 28 | void validQuestion(Question Question, boolean add); 29 | 30 | /** 31 | * 获取查询条件 32 | * 33 | * @param QuestionQueryRequest 34 | * @return 35 | */ 36 | QueryWrapper getQueryWrapper(QuestionQueryRequest QuestionQueryRequest); 37 | 38 | 39 | 40 | /** 41 | * 获取帖子封装 42 | * 43 | * @param Question 44 | * @param request 45 | * @return 46 | */ 47 | QuestionVO getQuestionVO(Question Question, HttpServletRequest request); 48 | 49 | /** 50 | * 分页获取帖子封装 51 | * 52 | * @param QuestionPage 53 | * @param request 54 | * @return 55 | */ 56 | Page getQuestionVOPage(Page QuestionPage, HttpServletRequest request); 57 | } 58 | -------------------------------------------------------------------------------- /nawoj-backend/src/main/java/com/yupi/nawoj_backend/service/QuestionSubmitService.java: -------------------------------------------------------------------------------- 1 | package com.yupi.nawoj_backend.service; 2 | 3 | import com.baomidou.mybatisplus.extension.service.IService; 4 | import com.yupi.nawoj_backend.model.dto.questionsubmit.QuestionSubmitAddRequest; 5 | import com.yupi.nawoj_backend.model.entity.Question; 6 | import com.yupi.nawoj_backend.model.entity.QuestionSubmit; 7 | import com.yupi.nawoj_backend.model.entity.User; 8 | 9 | /** 10 | * @Author peelsannaw 11 | * @create 31/12/2023 17:34 12 | */ 13 | public interface QuestionSubmitService extends IService { 14 | 15 | /** 16 | * 外部提交题目 17 | * @param questionId 18 | * @param loginUser 19 | * @return 20 | */ 21 | Long doQuestionSubmit(QuestionSubmitAddRequest questionSubmitAddRequest, User loginUser); 22 | 23 | Long doQuestionSubmitInner(Long userId, QuestionSubmitAddRequest questionSubmitAddRequest); 24 | 25 | 26 | 27 | } 28 | -------------------------------------------------------------------------------- /nawoj-backend/src/main/java/com/yupi/nawoj_backend/service/UserService.java: -------------------------------------------------------------------------------- 1 | package com.yupi.nawoj_backend.service; 2 | 3 | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; 4 | import com.baomidou.mybatisplus.extension.service.IService; 5 | import com.yupi.nawoj_backend.model.dto.user.UserQueryRequest; 6 | import com.yupi.nawoj_backend.model.entity.User; 7 | import com.yupi.nawoj_backend.model.vo.LoginUserVO; 8 | import com.yupi.nawoj_backend.model.vo.UserVO; 9 | import java.util.List; 10 | import javax.servlet.http.HttpServletRequest; 11 | import me.chanjar.weixin.common.bean.WxOAuth2UserInfo; 12 | 13 | /** 14 | * 用户服务 15 | * 16 | * @author 程序员鱼皮 17 | * @from 编程导航知识星球 18 | */ 19 | public interface UserService extends IService { 20 | 21 | /** 22 | * 用户注册 23 | * 24 | * @param userAccount 用户账户 25 | * @param userPassword 用户密码 26 | * @param checkPassword 校验密码 27 | * @return 新用户 id 28 | */ 29 | long userRegister(String userAccount, String userPassword, String checkPassword,String userAvatar); 30 | 31 | /** 32 | * 用户登录 33 | * 34 | * @param userAccount 用户账户 35 | * @param userPassword 用户密码 36 | * @param request 37 | * @return 脱敏后的用户信息 38 | */ 39 | LoginUserVO userLogin(String userAccount, String userPassword, HttpServletRequest request); 40 | 41 | /** 42 | * 用户登录(微信开放平台) 43 | * 44 | * @param wxOAuth2UserInfo 从微信获取的用户信息 45 | * @param request 46 | * @return 脱敏后的用户信息 47 | */ 48 | LoginUserVO userLoginByMpOpen(WxOAuth2UserInfo wxOAuth2UserInfo, HttpServletRequest request); 49 | 50 | /** 51 | * 获取当前登录用户 52 | * 53 | * @param request 54 | * @return 55 | */ 56 | User getLoginUser(HttpServletRequest request); 57 | 58 | /** 59 | * 获取当前登录用户(允许未登录) 60 | * 61 | * @param request 62 | * @return 63 | */ 64 | User getLoginUserPermitNull(HttpServletRequest request); 65 | 66 | /** 67 | * 是否为管理员 68 | * 69 | * @param request 70 | * @return 71 | */ 72 | boolean isAdmin(HttpServletRequest request); 73 | 74 | /** 75 | * 是否为管理员 76 | * 77 | * @param user 78 | * @return 79 | */ 80 | boolean isAdmin(User user); 81 | 82 | /** 83 | * 用户注销 84 | * 85 | * @param request 86 | * @return 87 | */ 88 | boolean userLogout(HttpServletRequest request); 89 | 90 | /** 91 | * 获取脱敏的已登录用户信息 92 | * 93 | * @return 94 | */ 95 | LoginUserVO getLoginUserVO(User user); 96 | 97 | /** 98 | * 获取脱敏的用户信息 99 | * 100 | * @param user 101 | * @return 102 | */ 103 | UserVO getUserVO(User user); 104 | 105 | /** 106 | * 获取脱敏的用户信息 107 | * 108 | * @param userList 109 | * @return 110 | */ 111 | List getUserVO(List userList); 112 | 113 | /** 114 | * 获取查询条件 115 | * 116 | * @param userQueryRequest 117 | * @return 118 | */ 119 | QueryWrapper getQueryWrapper(UserQueryRequest userQueryRequest); 120 | 121 | } 122 | -------------------------------------------------------------------------------- /nawoj-backend/src/main/java/com/yupi/nawoj_backend/utils/NetUtils.java: -------------------------------------------------------------------------------- 1 | package com.yupi.nawoj_backend.utils; 2 | 3 | import java.net.InetAddress; 4 | import javax.servlet.http.HttpServletRequest; 5 | 6 | /** 7 | * 网络工具类 8 | * 9 | * @author 程序员鱼皮 10 | * @from 编程导航知识星球 11 | */ 12 | public class NetUtils { 13 | 14 | /** 15 | * 获取客户端 IP 地址 16 | * 17 | * @param request 18 | * @return 19 | */ 20 | public static String getIpAddress(HttpServletRequest request) { 21 | String ip = request.getHeader("x-forwarded-for"); 22 | if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { 23 | ip = request.getHeader("Proxy-Client-IP"); 24 | } 25 | if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { 26 | ip = request.getHeader("WL-Proxy-Client-IP"); 27 | } 28 | if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { 29 | ip = request.getRemoteAddr(); 30 | if (ip.equals("127.0.0.1")) { 31 | // 根据网卡取本机配置的 IP 32 | InetAddress inet = null; 33 | try { 34 | inet = InetAddress.getLocalHost(); 35 | } catch (Exception e) { 36 | e.printStackTrace(); 37 | } 38 | if (inet != null) { 39 | ip = inet.getHostAddress(); 40 | } 41 | } 42 | } 43 | // 多个代理的情况,第一个IP为客户端真实IP,多个IP按照','分割 44 | if (ip != null && ip.length() > 15) { 45 | if (ip.indexOf(",") > 0) { 46 | ip = ip.substring(0, ip.indexOf(",")); 47 | } 48 | } 49 | if (ip == null) { 50 | return "127.0.0.1"; 51 | } 52 | return ip; 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /nawoj-backend/src/main/java/com/yupi/nawoj_backend/utils/SpringContextUtils.java: -------------------------------------------------------------------------------- 1 | package com.yupi.nawoj_backend.utils; 2 | 3 | import org.jetbrains.annotations.NotNull; 4 | import org.springframework.beans.BeansException; 5 | import org.springframework.context.ApplicationContext; 6 | import org.springframework.context.ApplicationContextAware; 7 | import org.springframework.stereotype.Component; 8 | 9 | /** 10 | * Spring 上下文获取工具 11 | * 12 | * @author 程序员鱼皮 13 | * @from 编程导航知识星球 14 | */ 15 | @Component 16 | public class SpringContextUtils implements ApplicationContextAware { 17 | 18 | private static ApplicationContext applicationContext; 19 | 20 | @Override 21 | public void setApplicationContext(@NotNull ApplicationContext applicationContext) throws BeansException { 22 | SpringContextUtils.applicationContext = applicationContext; 23 | } 24 | 25 | /** 26 | * 通过名称获取 Bean 27 | * 28 | * @param beanName 29 | * @return 30 | */ 31 | public static Object getBean(String beanName) { 32 | return applicationContext.getBean(beanName); 33 | } 34 | 35 | /** 36 | * 通过 class 获取 Bean 37 | * 38 | * @param beanClass 39 | * @param 40 | * @return 41 | */ 42 | public static T getBean(Class beanClass) { 43 | return applicationContext.getBean(beanClass); 44 | } 45 | 46 | /** 47 | * 通过名称和类型获取 Bean 48 | * 49 | * @param beanName 50 | * @param beanClass 51 | * @param 52 | * @return 53 | */ 54 | public static T getBean(String beanName, Class beanClass) { 55 | return applicationContext.getBean(beanName, beanClass); 56 | } 57 | } -------------------------------------------------------------------------------- /nawoj-backend/src/main/java/com/yupi/nawoj_backend/utils/SqlUtils.java: -------------------------------------------------------------------------------- 1 | package com.yupi.nawoj_backend.utils; 2 | 3 | import org.apache.commons.lang3.StringUtils; 4 | 5 | /** 6 | * SQL 工具 7 | * 8 | * @author 程序员鱼皮 9 | * @from 编程导航知识星球 10 | */ 11 | public class SqlUtils { 12 | 13 | /** 14 | * 校验排序字段是否合法(防止 SQL 注入) 15 | * 16 | * @param sortField 17 | * @return 18 | */ 19 | public static boolean validSortField(String sortField) { 20 | if (StringUtils.isBlank(sortField)) { 21 | return false; 22 | } 23 | return !StringUtils.containsAny(sortField, "=", "(", ")", " "); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /nawoj-backend/src/main/java/com/yupi/nawoj_backend/wxmp/WxMpConstant.java: -------------------------------------------------------------------------------- 1 | package com.yupi.nawoj_backend.wxmp; 2 | 3 | /** 4 | * 微信公众号相关常量 5 | * 6 | * @author 程序员鱼皮 7 | * @from 编程导航知识星球 8 | **/ 9 | public class WxMpConstant { 10 | 11 | /** 12 | * 点击菜单 key 13 | */ 14 | public static final String CLICK_MENU_KEY = "CLICK_MENU_KEY"; 15 | 16 | } 17 | -------------------------------------------------------------------------------- /nawoj-backend/src/main/java/com/yupi/nawoj_backend/wxmp/WxMpMsgRouter.java: -------------------------------------------------------------------------------- 1 | package com.yupi.nawoj_backend.wxmp; 2 | 3 | import com.yupi.nawoj_backend.wxmp.handler.EventHandler; 4 | import com.yupi.nawoj_backend.wxmp.handler.MessageHandler; 5 | import com.yupi.nawoj_backend.wxmp.handler.SubscribeHandler; 6 | import javax.annotation.Resource; 7 | import me.chanjar.weixin.common.api.WxConsts.EventType; 8 | import me.chanjar.weixin.common.api.WxConsts.XmlMsgType; 9 | import me.chanjar.weixin.mp.api.WxMpMessageRouter; 10 | import me.chanjar.weixin.mp.api.WxMpService; 11 | import org.springframework.context.annotation.Bean; 12 | import org.springframework.context.annotation.Configuration; 13 | 14 | /** 15 | * 微信公众号路由 16 | * 17 | * @author 程序员鱼皮 18 | * @from 编程导航知识星球 19 | */ 20 | @Configuration 21 | public class WxMpMsgRouter { 22 | 23 | @Resource 24 | private WxMpService wxMpService; 25 | 26 | @Resource 27 | private EventHandler eventHandler; 28 | 29 | @Resource 30 | private MessageHandler messageHandler; 31 | 32 | @Resource 33 | private SubscribeHandler subscribeHandler; 34 | 35 | @Bean 36 | public WxMpMessageRouter getWxMsgRouter() { 37 | WxMpMessageRouter router = new WxMpMessageRouter(wxMpService); 38 | // 消息 39 | router.rule() 40 | .async(false) 41 | .msgType(XmlMsgType.TEXT) 42 | .handler(messageHandler) 43 | .end(); 44 | // 关注 45 | router.rule() 46 | .async(false) 47 | .msgType(XmlMsgType.EVENT) 48 | .event(EventType.SUBSCRIBE) 49 | .handler(subscribeHandler) 50 | .end(); 51 | // 点击按钮 52 | router.rule() 53 | .async(false) 54 | .msgType(XmlMsgType.EVENT) 55 | .event(EventType.CLICK) 56 | .eventKey(WxMpConstant.CLICK_MENU_KEY) 57 | .handler(eventHandler) 58 | .end(); 59 | return router; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /nawoj-backend/src/main/java/com/yupi/nawoj_backend/wxmp/handler/EventHandler.java: -------------------------------------------------------------------------------- 1 | package com.yupi.nawoj_backend.wxmp.handler; 2 | 3 | import java.util.Map; 4 | import me.chanjar.weixin.common.error.WxErrorException; 5 | import me.chanjar.weixin.common.session.WxSessionManager; 6 | import me.chanjar.weixin.mp.api.WxMpMessageHandler; 7 | import me.chanjar.weixin.mp.api.WxMpService; 8 | import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage; 9 | import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage; 10 | import org.springframework.stereotype.Component; 11 | 12 | /** 13 | * 事件处理器 14 | * 15 | * @author 程序员鱼皮 16 | * @from 编程导航知识星球 17 | **/ 18 | @Component 19 | public class EventHandler implements WxMpMessageHandler { 20 | 21 | @Override 22 | public WxMpXmlOutMessage handle(WxMpXmlMessage wxMpXmlMessage, Map map, WxMpService wxMpService, 23 | WxSessionManager wxSessionManager) throws WxErrorException { 24 | final String content = "您点击了菜单"; 25 | // 调用接口,返回验证码 26 | return WxMpXmlOutMessage.TEXT().content(content) 27 | .fromUser(wxMpXmlMessage.getToUser()) 28 | .toUser(wxMpXmlMessage.getFromUser()) 29 | .build(); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /nawoj-backend/src/main/java/com/yupi/nawoj_backend/wxmp/handler/MessageHandler.java: -------------------------------------------------------------------------------- 1 | package com.yupi.nawoj_backend.wxmp.handler; 2 | 3 | import java.util.Map; 4 | import me.chanjar.weixin.common.error.WxErrorException; 5 | import me.chanjar.weixin.common.session.WxSessionManager; 6 | import me.chanjar.weixin.mp.api.WxMpMessageHandler; 7 | import me.chanjar.weixin.mp.api.WxMpService; 8 | import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage; 9 | import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage; 10 | import org.springframework.stereotype.Component; 11 | 12 | /** 13 | * 消息处理器 14 | * 15 | * @author 程序员鱼皮 16 | * @from 编程导航知识星球 17 | **/ 18 | @Component 19 | public class MessageHandler implements WxMpMessageHandler { 20 | 21 | @Override 22 | public WxMpXmlOutMessage handle(WxMpXmlMessage wxMpXmlMessage, Map map, 23 | WxMpService wxMpService, WxSessionManager wxSessionManager) throws WxErrorException { 24 | String content = "我是复读机:" + wxMpXmlMessage.getContent(); 25 | return WxMpXmlOutMessage.TEXT().content(content) 26 | .fromUser(wxMpXmlMessage.getToUser()) 27 | .toUser(wxMpXmlMessage.getFromUser()) 28 | .build(); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /nawoj-backend/src/main/java/com/yupi/nawoj_backend/wxmp/handler/SubscribeHandler.java: -------------------------------------------------------------------------------- 1 | package com.yupi.nawoj_backend.wxmp.handler; 2 | 3 | import java.util.Map; 4 | import me.chanjar.weixin.common.error.WxErrorException; 5 | import me.chanjar.weixin.common.session.WxSessionManager; 6 | import me.chanjar.weixin.mp.api.WxMpMessageHandler; 7 | import me.chanjar.weixin.mp.api.WxMpService; 8 | import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage; 9 | import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage; 10 | import org.springframework.stereotype.Component; 11 | 12 | /** 13 | * 关注处理器 14 | * 15 | * @author 程序员鱼皮 16 | * @from 编程导航知识星球 17 | **/ 18 | @Component 19 | public class SubscribeHandler implements WxMpMessageHandler { 20 | 21 | @Override 22 | public WxMpXmlOutMessage handle(WxMpXmlMessage wxMpXmlMessage, Map map, 23 | WxMpService wxMpService, WxSessionManager wxSessionManager) throws WxErrorException { 24 | final String content = "感谢关注"; 25 | // 调用接口,返回验证码 26 | return WxMpXmlOutMessage.TEXT().content(content) 27 | .fromUser(wxMpXmlMessage.getToUser()) 28 | .toUser(wxMpXmlMessage.getFromUser()) 29 | .build(); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /nawoj-backend/src/main/resources/META-INF/additional-spring-configuration-metadata.json: -------------------------------------------------------------------------------- 1 | { 2 | "properties": [ 3 | { 4 | "name": "cos.client.accessKey", 5 | "type": "java.lang.String", 6 | "description": "Description for cos.client.accessKey." 7 | }, 8 | { 9 | "name": "cos.client.secretKey", 10 | "type": "java.lang.String", 11 | "description": "Description for cos.client.secretKey." 12 | }, 13 | { 14 | "name": "cos.client.region", 15 | "type": "java.lang.String", 16 | "description": "Description for cos.client.region." 17 | }, 18 | { 19 | "name": "cos.client.bucket", 20 | "type": "java.lang.String", 21 | "description": "Description for cos.client.bucket." 22 | }, 23 | { 24 | "name": "wx.open.appId", 25 | "type": "java.lang.String", 26 | "description": "Description for wx.open.appId." 27 | }, 28 | { 29 | "name": "wx.open.appSecret", 30 | "type": "java.lang.String", 31 | "description": "Description for wx.open.appSecret." 32 | } 33 | ] 34 | } -------------------------------------------------------------------------------- /nawoj-backend/src/main/resources/application-prod.yml: -------------------------------------------------------------------------------- 1 | # 线上配置文件 2 | # @author 程序员鱼皮 3 | # @from 编程导航知识星球 4 | server: 5 | port: 8101 6 | spring: 7 | # 数据库配置 8 | # todo 需替换配置 9 | datasource: 10 | driver-class-name: com.mysql.cj.jdbc.Driver 11 | url: jdbc:mysql://localhost:3306/kob?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf-8 12 | username: root 13 | password: Zzhzzhzzh1 14 | # Redis 配置 15 | # todo 需替换配置 16 | redis: 17 | database: 1 18 | host: localhost 19 | port: 6379 20 | timeout: 5000 21 | password: 123456 22 | # Elasticsearch 配置 23 | # todo 需替换配置 24 | elasticsearch: 25 | uris: http://localhost:9200 26 | username: root 27 | password: 123456 28 | mybatis-plus: 29 | configuration: 30 | # 生产环境关闭日志 31 | log-impl: '' 32 | # 接口文档的配置 33 | springdoc: 34 | group-configs: 35 | - group: 'default' 36 | packages-to-scan: com.yupi.springbootinit.controller 37 | # knife4j的增强配置,不需要增强可以不配 38 | knife4j: 39 | # 开启增强配置 40 | enable: true 41 | # 开启生产环境屏蔽 42 | production: true 43 | # 开启Swagger的Basic认证功能,默认是false 44 | basic: 45 | enable: true 46 | # Basic认证用户名 47 | username: root 48 | # Basic认证密码 49 | password: 123456 -------------------------------------------------------------------------------- /nawoj-backend/src/main/resources/application-test.yml: -------------------------------------------------------------------------------- 1 | # 测试配置文件 2 | # @author 程序员鱼皮 3 | # @from 编程导航知识星球 4 | server: 5 | port: 8101 6 | spring: 7 | # 数据库配置 8 | # todo 需替换配置 9 | datasource: 10 | driver-class-name: com.mysql.cj.jdbc.Driver 11 | url: jdbc:mysql://localhost:3306/kob?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf-8 12 | username: root 13 | password: Zzhzzhzzh1 14 | # Redis 配置 15 | # todo 需替换配置 16 | redis: 17 | database: 1 18 | host: localhost 19 | port: 6379 20 | timeout: 5000 21 | password: 123456 22 | # Elasticsearch 配置 23 | # todo 需替换配置 24 | elasticsearch: 25 | uris: http://localhost:9200 26 | username: root 27 | password: 123456 -------------------------------------------------------------------------------- /nawoj-backend/src/main/resources/mapper/PostFavourMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | id,postId,userId, 19 | createTime,updateTime 20 | 21 | 22 | 24 | select p.* 25 | from post p 26 | join (select postId from post_favour where userId = #{favourUserId}) pf 27 | on p.id = pf.postId ${ew.customSqlSegment} 28 | 29 | 30 | -------------------------------------------------------------------------------- /nawoj-backend/src/main/resources/mapper/PostMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | id,title,content,tags, 24 | thumbNum,favourNum,userId, 25 | createTime,updateTime,isDelete 26 | 27 | 28 | 29 | select * 30 | from post 31 | where updateTime >= #{minUpdateTime} 32 | 33 | 34 | -------------------------------------------------------------------------------- /nawoj-backend/src/main/resources/mapper/PostThumbMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | id,postId, 19 | userId,createTime,updateTime 20 | 21 | 22 | -------------------------------------------------------------------------------- /nawoj-backend/src/main/resources/mapper/QuestionMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | id,title,content, 29 | tags,answer,submitNum, 30 | acceptedNum,judgeCase,judgeConfig,judgeDescription, 31 | thumbNum,favourNum,userId, 32 | createTime,updateTime,isDelete 33 | 34 | 35 | -------------------------------------------------------------------------------- /nawoj-backend/src/main/resources/mapper/QuestionSubmitMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | id,language,code, 22 | judgeInfo,status,questionId, 23 | userId,createTime,updateTime, 24 | isDelete 25 | 26 | 27 | -------------------------------------------------------------------------------- /nawoj-backend/src/main/resources/mapper/UserMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /nawoj-backend/src/test/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fujiwarazz/nawoj/4709f31ffe7f1e214b8c085a719504383219fea8/nawoj-backend/src/test/.DS_Store -------------------------------------------------------------------------------- /nawoj-backend/src/test/java/com/yupi/nawoj_backend/MainApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.yupi.nawoj_backend; 2 | 3 | import com.yupi.nawoj_backend.config.WxOpenConfig; 4 | import javax.annotation.Resource; 5 | import org.junit.jupiter.api.Test; 6 | import org.springframework.boot.test.context.SpringBootTest; 7 | 8 | /** 9 | * 主类测试 10 | * 11 | * @author 程序员鱼皮 12 | * @from 编程导航知识星球 13 | */ 14 | @SpringBootTest 15 | class MainApplicationTests { 16 | 17 | @Resource 18 | private WxOpenConfig wxOpenConfig; 19 | 20 | @Test 21 | void contextLoads() { 22 | System.out.println(wxOpenConfig); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /nawoj-backend/src/test/java/com/yupi/nawoj_backend/esdao/PostEsDaoTest.java: -------------------------------------------------------------------------------- 1 | package com.yupi.nawoj_backend.esdao; 2 | 3 | import com.yupi.nawoj_backend.model.dto.post.PostEsDTO; 4 | import com.yupi.nawoj_backend.model.dto.post.PostQueryRequest; 5 | import com.yupi.nawoj_backend.model.entity.Post; 6 | import com.yupi.nawoj_backend.service.PostService; 7 | import java.util.Arrays; 8 | import java.util.Date; 9 | import java.util.List; 10 | import java.util.Optional; 11 | import javax.annotation.Resource; 12 | import org.junit.jupiter.api.Test; 13 | import org.springframework.boot.test.context.SpringBootTest; 14 | import org.springframework.data.domain.Page; 15 | import org.springframework.data.domain.PageRequest; 16 | import org.springframework.data.domain.Sort; 17 | 18 | /** 19 | * 帖子 ES 操作测试 20 | * 21 | * @author 程序员鱼皮 22 | * @from 编程导航知识星球 23 | */ 24 | @SpringBootTest 25 | public class PostEsDaoTest { 26 | 27 | @Resource 28 | private PostEsDao postEsDao; 29 | 30 | @Resource 31 | private PostService postService; 32 | 33 | @Test 34 | void test() { 35 | PostQueryRequest postQueryRequest = new PostQueryRequest(); 36 | com.baomidou.mybatisplus.extension.plugins.pagination.Page page = 37 | postService.searchFromEs(postQueryRequest); 38 | System.out.println(page); 39 | } 40 | 41 | @Test 42 | void testSelect() { 43 | System.out.println(postEsDao.count()); 44 | Page PostPage = postEsDao.findAll( 45 | PageRequest.of(0, 5, Sort.by("createTime"))); 46 | List postList = PostPage.getContent(); 47 | System.out.println(postList); 48 | } 49 | 50 | @Test 51 | void testAdd() { 52 | PostEsDTO postEsDTO = new PostEsDTO(); 53 | postEsDTO.setId(1L); 54 | postEsDTO.setTitle("test"); 55 | postEsDTO.setContent("test"); 56 | postEsDTO.setTags(Arrays.asList("java", "python")); 57 | postEsDTO.setThumbNum(1); 58 | postEsDTO.setFavourNum(1); 59 | postEsDTO.setUserId(1L); 60 | postEsDTO.setCreateTime(new Date()); 61 | postEsDTO.setUpdateTime(new Date()); 62 | postEsDTO.setIsDelete(0); 63 | postEsDao.save(postEsDTO); 64 | System.out.println(postEsDTO.getId()); 65 | } 66 | 67 | @Test 68 | void testFindById() { 69 | Optional postEsDTO = postEsDao.findById(1L); 70 | System.out.println(postEsDTO); 71 | } 72 | 73 | @Test 74 | void testCount() { 75 | System.out.println(postEsDao.count()); 76 | } 77 | 78 | @Test 79 | void testFindByCategory() { 80 | List postEsDaoTestList = postEsDao.findByUserId(1L); 81 | System.out.println(postEsDaoTestList); 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /nawoj-backend/src/test/java/com/yupi/nawoj_backend/manager/CosManagerTest.java: -------------------------------------------------------------------------------- 1 | package com.yupi.nawoj_backend.manager; 2 | 3 | import javax.annotation.Resource; 4 | import org.junit.jupiter.api.Test; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | 7 | /** 8 | * Cos 操作测试 9 | * 10 | * @author 程序员鱼皮 11 | * @from 编程导航知识星球 12 | */ 13 | @SpringBootTest 14 | class CosManagerTest { 15 | 16 | @Resource 17 | private CosManager cosManager; 18 | 19 | @Test 20 | void putObject() { 21 | cosManager.putObject("test", "test.json"); 22 | } 23 | } -------------------------------------------------------------------------------- /nawoj-backend/src/test/java/com/yupi/nawoj_backend/mapper/PostFavourMapperTest.java: -------------------------------------------------------------------------------- 1 | package com.yupi.nawoj_backend.mapper; 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.yupi.nawoj_backend.model.entity.Post; 7 | import javax.annotation.Resource; 8 | import org.junit.jupiter.api.Assertions; 9 | import org.junit.jupiter.api.Test; 10 | import org.springframework.boot.test.context.SpringBootTest; 11 | 12 | /** 13 | * 帖子收藏数据库操作测试 14 | * 15 | * @author 程序员鱼皮 16 | * @from 编程导航知识星球 17 | */ 18 | @SpringBootTest 19 | class PostFavourMapperTest { 20 | 21 | @Resource 22 | private PostFavourMapper postFavourMapper; 23 | 24 | @Test 25 | void listUserFavourPostByPage() { 26 | IPage page = new Page<>(2, 1); 27 | QueryWrapper queryWrapper = new QueryWrapper<>(); 28 | queryWrapper.eq("id", 1); 29 | queryWrapper.like("content", "a"); 30 | IPage result = postFavourMapper.listFavourPostByPage(page, queryWrapper, 1); 31 | Assertions.assertNotNull(result); 32 | } 33 | } -------------------------------------------------------------------------------- /nawoj-backend/src/test/java/com/yupi/nawoj_backend/mapper/PostMapperTest.java: -------------------------------------------------------------------------------- 1 | package com.yupi.nawoj_backend.mapper; 2 | 3 | import com.yupi.nawoj_backend.model.entity.Post; 4 | import java.util.Date; 5 | import java.util.List; 6 | import javax.annotation.Resource; 7 | import org.junit.jupiter.api.Assertions; 8 | import org.junit.jupiter.api.Test; 9 | import org.springframework.boot.test.context.SpringBootTest; 10 | 11 | /** 12 | * 帖子数据库操作测试 13 | * 14 | * @author 程序员鱼皮 15 | * @from 编程导航知识星球 16 | */ 17 | @SpringBootTest 18 | class PostMapperTest { 19 | 20 | @Resource 21 | private PostMapper postMapper; 22 | 23 | @Test 24 | void listPostWithDelete() { 25 | List postList = postMapper.listPostWithDelete(new Date()); 26 | Assertions.assertNotNull(postList); 27 | } 28 | } -------------------------------------------------------------------------------- /nawoj-backend/src/test/java/com/yupi/nawoj_backend/service/PostFavourServiceTest.java: -------------------------------------------------------------------------------- 1 | package com.yupi.nawoj_backend.service; 2 | 3 | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; 4 | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; 5 | import com.yupi.nawoj_backend.model.entity.Post; 6 | import com.yupi.nawoj_backend.model.entity.User; 7 | import javax.annotation.Resource; 8 | import org.junit.jupiter.api.Assertions; 9 | import org.junit.jupiter.api.BeforeAll; 10 | import org.junit.jupiter.api.Test; 11 | import org.springframework.boot.test.context.SpringBootTest; 12 | 13 | /** 14 | * 帖子收藏服务测试 15 | * 16 | * @author 程序员鱼皮 17 | * @from 编程导航知识星球 18 | */ 19 | @SpringBootTest 20 | class PostFavourServiceTest { 21 | 22 | @Resource 23 | private PostFavourService postFavourService; 24 | 25 | private static final User loginUser = new User(); 26 | 27 | @BeforeAll 28 | static void setUp() { 29 | loginUser.setId(1L); 30 | } 31 | 32 | @Test 33 | void doPostFavour() { 34 | int i = postFavourService.doPostFavour(1L, loginUser); 35 | Assertions.assertTrue(i >= 0); 36 | } 37 | 38 | @Test 39 | void listFavourPostByPage() { 40 | QueryWrapper postQueryWrapper = new QueryWrapper<>(); 41 | postQueryWrapper.eq("id", 1L); 42 | postFavourService.listFavourPostByPage(Page.of(0, 1), postQueryWrapper, loginUser.getId()); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /nawoj-backend/src/test/java/com/yupi/nawoj_backend/service/PostServiceTest.java: -------------------------------------------------------------------------------- 1 | package com.yupi.nawoj_backend.service; 2 | 3 | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; 4 | import com.yupi.nawoj_backend.model.dto.post.PostQueryRequest; 5 | import com.yupi.nawoj_backend.model.entity.Post; 6 | import javax.annotation.Resource; 7 | import org.junit.jupiter.api.Assertions; 8 | import org.junit.jupiter.api.Test; 9 | import org.springframework.boot.test.context.SpringBootTest; 10 | 11 | /** 12 | * 帖子服务测试 13 | * 14 | * @author 程序员鱼皮 15 | * @from 编程导航知识星球 16 | */ 17 | @SpringBootTest 18 | class PostServiceTest { 19 | 20 | @Resource 21 | private PostService postService; 22 | 23 | @Test 24 | void searchFromEs() { 25 | PostQueryRequest postQueryRequest = new PostQueryRequest(); 26 | postQueryRequest.setUserId(1L); 27 | Page postPage = postService.searchFromEs(postQueryRequest); 28 | Assertions.assertNotNull(postPage); 29 | } 30 | 31 | } -------------------------------------------------------------------------------- /nawoj-backend/src/test/java/com/yupi/nawoj_backend/service/PostThumbServiceTest.java: -------------------------------------------------------------------------------- 1 | package com.yupi.nawoj_backend.service; 2 | 3 | import com.yupi.nawoj_backend.model.entity.User; 4 | import javax.annotation.Resource; 5 | import org.junit.jupiter.api.Assertions; 6 | import org.junit.jupiter.api.BeforeAll; 7 | import org.junit.jupiter.api.Test; 8 | import org.springframework.boot.test.context.SpringBootTest; 9 | 10 | /** 11 | * 帖子点赞服务测试 12 | * 13 | * @author 程序员鱼皮 14 | * @from 编程导航知识星球 15 | */ 16 | @SpringBootTest 17 | class PostThumbServiceTest { 18 | 19 | @Resource 20 | private PostThumbService postThumbService; 21 | 22 | private static final User loginUser = new User(); 23 | 24 | @BeforeAll 25 | static void setUp() { 26 | loginUser.setId(1L); 27 | } 28 | 29 | @Test 30 | void doPostThumb() { 31 | int i = postThumbService.doPostThumb(1L, loginUser); 32 | Assertions.assertTrue(i >= 0); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /nawoj-backend/src/test/java/com/yupi/nawoj_backend/service/UserServiceTest.java: -------------------------------------------------------------------------------- 1 | package com.yupi.nawoj_backend.service; 2 | 3 | import javax.annotation.Resource; 4 | import org.junit.jupiter.api.Assertions; 5 | import org.junit.jupiter.api.Test; 6 | import org.springframework.boot.test.context.SpringBootTest; 7 | 8 | /** 9 | * 用户服务测试 10 | * 11 | * @author 程序员鱼皮 12 | * @from 编程导航知识星球 13 | */ 14 | @SpringBootTest 15 | public class UserServiceTest { 16 | 17 | @Resource 18 | private UserService userService; 19 | 20 | 21 | 22 | } 23 | -------------------------------------------------------------------------------- /nawoj-backend/src/test/java/com/yupi/nawoj_backend/utils/EasyExcelTest.java: -------------------------------------------------------------------------------- 1 | package com.yupi.nawoj_backend.utils; 2 | 3 | import com.alibaba.excel.EasyExcel; 4 | import com.alibaba.excel.support.ExcelTypeEnum; 5 | import org.junit.jupiter.api.Test; 6 | import org.springframework.boot.test.context.SpringBootTest; 7 | import org.springframework.util.ResourceUtils; 8 | 9 | import java.io.File; 10 | import java.io.FileNotFoundException; 11 | import java.util.List; 12 | import java.util.Map; 13 | 14 | /** 15 | * EasyExcel 测试 16 | * 17 | * @author 程序员鱼皮 18 | * @from 编程导航知识星球 19 | */ 20 | @SpringBootTest 21 | public class EasyExcelTest { 22 | 23 | @Test 24 | public void doImport() throws FileNotFoundException { 25 | File file = ResourceUtils.getFile("classpath:test_excel.xlsx"); 26 | List> list = EasyExcel.read(file) 27 | .excelType(ExcelTypeEnum.XLSX) 28 | .sheet() 29 | .headRowNumber(0) 30 | .doReadSync(); 31 | System.out.println(list); 32 | } 33 | 34 | } -------------------------------------------------------------------------------- /nawoj-frontend/.browserslistrc: -------------------------------------------------------------------------------- 1 | last 2 versions 2 | not dead 3 | not ie 11 4 | -------------------------------------------------------------------------------- /nawoj-frontend/.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | root: true, 3 | env: { 4 | node: true, 5 | }, 6 | extends: [ 7 | "plugin:vue/vue3-essential", 8 | "eslint:recommended", 9 | "@vue/typescript/recommended", 10 | "plugin:prettier/recommended", 11 | ], 12 | parserOptions: { 13 | ecmaVersion: 2020, 14 | }, 15 | rules: { 16 | "no-console": process.env.NODE_ENV === "production" ? "warn" : "off", 17 | "no-debugger": process.env.NODE_ENV === "production" ? "warn" : "off", 18 | "prettier/prettier": "off" 19 | }, 20 | }; 21 | -------------------------------------------------------------------------------- /nawoj-frontend/.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules 3 | /dist 4 | 5 | 6 | # local env files 7 | .env.local 8 | .env.*.local 9 | 10 | # Log files 11 | npm-debug.log* 12 | yarn-debug.log* 13 | yarn-error.log* 14 | pnpm-debug.log* 15 | 16 | # Editor directories and files 17 | .idea 18 | .vscode 19 | *.suo 20 | *.ntvs* 21 | *.njsproj 22 | *.sln 23 | *.sw? 24 | -------------------------------------------------------------------------------- /nawoj-frontend/README.md: -------------------------------------------------------------------------------- 1 | # nawoj-frontend 2 | 3 | ## Project setup 4 | ``` 5 | npm install 6 | ``` 7 | 8 | ### Compiles and hot-reloads for development 9 | ``` 10 | npm run serve 11 | ``` 12 | 13 | ### Compiles and minifies for production 14 | ``` 15 | npm run build 16 | ``` 17 | 18 | ### Lints and fixes files 19 | ``` 20 | npm run lint 21 | ``` 22 | 23 | ### Customize configuration 24 | See [Configuration Reference](https://cli.vuejs.org/config/). 25 | -------------------------------------------------------------------------------- /nawoj-frontend/babel.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | presets: ["@vue/cli-plugin-babel/preset"], 3 | }; 4 | -------------------------------------------------------------------------------- /nawoj-frontend/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "nawoj-frontend", 3 | "version": "0.1.0", 4 | "private": true, 5 | "scripts": { 6 | "serve": "vue-cli-service serve", 7 | "build": "vue-cli-service build", 8 | "lint": "vue-cli-service lint" 9 | }, 10 | "dependencies": { 11 | "axios": "^1.6.3", 12 | "core-js": "^3.8.3", 13 | "nprogress": "^0.2.0", 14 | "vue": "^3.2.13", 15 | "vue-router": "^4.0.3", 16 | "vuex": "^4.0.0" 17 | }, 18 | "devDependencies": { 19 | "@arco-design/web-vue": "^2.53.3", 20 | "@types/nprogress": "^0.2.3", 21 | "@typescript-eslint/eslint-plugin": "^5.4.0", 22 | "@typescript-eslint/parser": "^5.4.0", 23 | "@vue/cli-plugin-babel": "~5.0.0", 24 | "@vue/cli-plugin-eslint": "~5.0.0", 25 | "@vue/cli-plugin-router": "~5.0.0", 26 | "@vue/cli-plugin-typescript": "~5.0.0", 27 | "@vue/cli-plugin-vuex": "~5.0.0", 28 | "@vue/cli-service": "~5.0.0", 29 | "@vue/eslint-config-typescript": "^9.1.0", 30 | "eslint": "^7.32.0", 31 | "eslint-config-prettier": "^8.3.0", 32 | "eslint-plugin-prettier": "^4.0.0", 33 | "eslint-plugin-vue": "^8.0.3", 34 | "openapi-typescript-codegen": "^0.25.0", 35 | "prettier": "^2.4.1", 36 | "typescript": "~4.5.5" 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /nawoj-frontend/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fujiwarazz/nawoj/4709f31ffe7f1e214b8c085a719504383219fea8/nawoj-frontend/public/favicon.ico -------------------------------------------------------------------------------- /nawoj-frontend/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | <%= htmlWebpackPlugin.options.title %> 9 | 10 | 11 | 12 | We're sorry but <%= htmlWebpackPlugin.options.title %> doesn't work properly without JavaScript enabled. Please enable it to continue. 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /nawoj-frontend/src/App.vue: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 27 | 28 | -------------------------------------------------------------------------------- /nawoj-frontend/src/access/accessEnum.ts: -------------------------------------------------------------------------------- 1 | 2 | 3 | const ACCESS_ENUM={ 4 | BAN:-1, 5 | NOT_LOGIN:0, 6 | NORMAL_USER:1, 7 | ADMIN:2 8 | } 9 | 10 | export default { 11 | ACCESS_ENUM 12 | } -------------------------------------------------------------------------------- /nawoj-frontend/src/access/checkAccess.ts: -------------------------------------------------------------------------------- 1 | 2 | 3 | /** 4 | * check loginUser has the access 5 | * @param loginUser now login user 6 | * @param needAccess 7 | */ 8 | import { useRoute, useRouter } from "vue-router"; 9 | import { useStore } from "vuex"; 10 | import { Modal } from "@arco-design/web-vue"; 11 | import ACCESS_ENUM from './accessEnum' 12 | const router = useRouter(); 13 | const route = useRoute(); 14 | const store = useStore(); 15 | 16 | const checkAccess = (loginUser:any, needAccess = ACCESS_ENUM.ACCESS_ENUM.NOT_LOGIN) => { 17 | 18 | const loginUserAcess = loginUser?.access ?? ACCESS_ENUM.ACCESS_ENUM.NOT_LOGIN 19 | if (needAccess === ACCESS_ENUM.ACCESS_ENUM.NOT_LOGIN) { 20 | return true; 21 | } 22 | if (needAccess === ACCESS_ENUM.ACCESS_ENUM.NORMAL_USER) { 23 | if (loginUserAcess === ACCESS_ENUM.ACCESS_ENUM.NOT_LOGIN) { 24 | return false; 25 | } 26 | } 27 | if (needAccess === ACCESS_ENUM.ACCESS_ENUM.ADMIN) { 28 | if (loginUserAcess < ACCESS_ENUM.ACCESS_ENUM.NOT_LOGIN) { 29 | return false; 30 | } 31 | } 32 | return true; 33 | 34 | } 35 | 36 | 37 | -------------------------------------------------------------------------------- /nawoj-frontend/src/access/index.ts: -------------------------------------------------------------------------------- 1 | 2 | import { Modal } from "@arco-design/web-vue"; 3 | import router from "@/router"; 4 | import store from "@/store"; 5 | import accessEnum from "./accessEnum"; 6 | 7 | 8 | 9 | 10 | router.beforeEach(async (to, from, next) => { 11 | 12 | const cacheLoginUser = JSON.parse(localStorage.getItem("loginUser") || "{}"); 13 | 14 | if (cacheLoginUser!=null) { 15 | 16 | 17 | await store.dispatch("user/getLoginUser", { 18 | userName: cacheLoginUser.userName, 19 | access: cacheLoginUser.access, 20 | userAvatar: cacheLoginUser.userAvatar, 21 | userProfile: cacheLoginUser.userProfile, 22 | id: cacheLoginUser.id 23 | }) 24 | } 25 | 26 | const loginUser = store.state.user.loginUser 27 | 28 | if (!loginUser || loginUser.access === accessEnum.ACCESS_ENUM.NOT_LOGIN) { 29 | await store.dispatch('user/getLoginUser') 30 | console.log('auto login') 31 | } 32 | 33 | if(loginUser.access>accessEnum.ACCESS_ENUM.NOT_LOGIN){ 34 | if(to.path=='/user/login' || to.path =='/user/register'){ 35 | router.push('/home') 36 | } 37 | } 38 | 39 | 40 | const needAccess: number = to.meta.access as number 41 | 42 | // console.log("test",loginUser?.access) 43 | 44 | 45 | if (loginUser?.access === -1) { 46 | // 47 | Modal.error({ 48 | title: "错误提醒", 49 | content: "您的账号已被封禁 :(", 50 | }); 51 | next(`/user/login?redirect=${to.fullPath}`) 52 | } 53 | //不需要登陆 54 | if (needAccess === 0) { 55 | next(); 56 | } 57 | else if (needAccess > 0) { 58 | if (loginUser?.access >= needAccess) { 59 | next(); 60 | } else if (loginUser?.access == accessEnum.ACCESS_ENUM.NOT_LOGIN ) { 61 | console.log('not login') 62 | next(`/user/login?redirect=${to.fullPath}`) 63 | } else { 64 | 65 | Modal.error({ 66 | title: "错误提醒", 67 | // content: "权限不足 :(", 68 | content: `${loginUser?.access}` 69 | }); 70 | next(`/user/login?redirect=${to.fullPath}`) 71 | } 72 | } 73 | }); 74 | -------------------------------------------------------------------------------- /nawoj-frontend/src/assets/init.css: -------------------------------------------------------------------------------- 1 | @charset "UTF-8"; 2 | /*css 初始化 */ 3 | html, body, ul, li, ol, dl, dd, dt, p, h1, h2, h3, h4, h5, h6, form, fieldset, legend, img { 4 | margin: 0; 5 | padding: 0; 6 | } 7 | 8 | fieldset, img, input, button { /*fieldset组合表单中的相关元素*/ 9 | border: none; 10 | padding: 0; 11 | margin: 0; 12 | outline-style: none; 13 | } 14 | 15 | ul, ol { 16 | list-style: none; /*清除列表风格*/ 17 | } 18 | 19 | input { 20 | padding-top: 0; 21 | padding-bottom: 0; 22 | font-family: "SimSun", "宋体"; 23 | } 24 | 25 | select, input { 26 | vertical-align: middle; 27 | } 28 | 29 | select, input, textarea { 30 | font-size: 12px; 31 | margin: 0; 32 | } 33 | 34 | textarea { 35 | resize: none; 36 | } 37 | 38 | /*防止多行文本框拖动*/ 39 | img { 40 | border: 0; 41 | vertical-align: middle; 42 | } 43 | 44 | /* 去掉图片低测默认的3像素空白缝隙*/ 45 | table { 46 | border-collapse: collapse; /*合并外边线*/ 47 | } 48 | 49 | 50 | body { 51 | font: 12px/150% Arial, Verdana, "\5b8b\4f53"; /*宋体,Unicode,统一码*/ 52 | color: #666; 53 | background: #fff 54 | } 55 | 56 | .clearfix:before, .clearfix:after { 57 | content: ""; 58 | display: table; 59 | } 60 | 61 | .clearfix:after { 62 | clear: both; 63 | } 64 | 65 | 66 | a { 67 | color: #666; 68 | text-decoration: none; 69 | } 70 | 71 | a:hover { 72 | color: #C81623; 73 | } 74 | 75 | h1, h2, h3, h4, h5, h6 { 76 | text-decoration: none; 77 | font-weight: normal; 78 | font-size: 100%; 79 | } 80 | 81 | s, i, em { 82 | font-style: normal; 83 | text-decoration: none; 84 | } 85 | 86 | .col-red { 87 | color: #C81623 !important; 88 | } 89 | -------------------------------------------------------------------------------- /nawoj-frontend/src/assets/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fujiwarazz/nawoj/4709f31ffe7f1e214b8c085a719504383219fea8/nawoj-frontend/src/assets/logo.png -------------------------------------------------------------------------------- /nawoj-frontend/src/generated/core/ApiError.ts: -------------------------------------------------------------------------------- 1 | /* generated using openapi-typescript-codegen -- do no edit */ 2 | /* istanbul ignore file */ 3 | /* tslint:disable */ 4 | /* eslint-disable */ 5 | import type { ApiRequestOptions } from './ApiRequestOptions'; 6 | import type { ApiResult } from './ApiResult'; 7 | 8 | export class ApiError extends Error { 9 | public readonly url: string; 10 | public readonly status: number; 11 | public readonly statusText: string; 12 | public readonly body: any; 13 | public readonly request: ApiRequestOptions; 14 | 15 | constructor(request: ApiRequestOptions, response: ApiResult, message: string) { 16 | super(message); 17 | 18 | this.name = 'ApiError'; 19 | this.url = response.url; 20 | this.status = response.status; 21 | this.statusText = response.statusText; 22 | this.body = response.body; 23 | this.request = request; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /nawoj-frontend/src/generated/core/ApiRequestOptions.ts: -------------------------------------------------------------------------------- 1 | /* generated using openapi-typescript-codegen -- do no edit */ 2 | /* istanbul ignore file */ 3 | /* tslint:disable */ 4 | /* eslint-disable */ 5 | export type ApiRequestOptions = { 6 | readonly method: 'GET' | 'PUT' | 'POST' | 'DELETE' | 'OPTIONS' | 'HEAD' | 'PATCH'; 7 | readonly url: string; 8 | readonly path?: Record; 9 | readonly cookies?: Record; 10 | readonly headers?: Record; 11 | readonly query?: Record; 12 | readonly formData?: Record; 13 | readonly body?: any; 14 | readonly mediaType?: string; 15 | readonly responseHeader?: string; 16 | readonly errors?: Record; 17 | }; 18 | -------------------------------------------------------------------------------- /nawoj-frontend/src/generated/core/ApiResult.ts: -------------------------------------------------------------------------------- 1 | /* generated using openapi-typescript-codegen -- do no edit */ 2 | /* istanbul ignore file */ 3 | /* tslint:disable */ 4 | /* eslint-disable */ 5 | export type ApiResult = { 6 | readonly url: string; 7 | readonly ok: boolean; 8 | readonly status: number; 9 | readonly statusText: string; 10 | readonly body: any; 11 | }; 12 | -------------------------------------------------------------------------------- /nawoj-frontend/src/generated/core/OpenAPI.ts: -------------------------------------------------------------------------------- 1 | /* generated using openapi-typescript-codegen -- do no edit */ 2 | /* istanbul ignore file */ 3 | /* tslint:disable */ 4 | /* eslint-disable */ 5 | import type { ApiRequestOptions } from './ApiRequestOptions'; 6 | 7 | type Resolver = (options: ApiRequestOptions) => Promise; 8 | type Headers = Record; 9 | 10 | export type OpenAPIConfig = { 11 | BASE: string; 12 | VERSION: string; 13 | WITH_CREDENTIALS: boolean; 14 | CREDENTIALS: 'include' | 'omit' | 'same-origin'; 15 | TOKEN?: string | Resolver | undefined; 16 | USERNAME?: string | Resolver | undefined; 17 | PASSWORD?: string | Resolver | undefined; 18 | HEADERS?: Headers | Resolver | undefined; 19 | ENCODE_PATH?: ((path: string) => string) | undefined; 20 | }; 21 | 22 | export const OpenAPI: OpenAPIConfig = { 23 | BASE: 'http://localhost:8121', 24 | VERSION: '1.0', 25 | WITH_CREDENTIALS: true, 26 | CREDENTIALS: 'include', 27 | TOKEN: undefined, 28 | USERNAME: undefined, 29 | PASSWORD: undefined, 30 | HEADERS: undefined, 31 | ENCODE_PATH: undefined, 32 | }; 33 | -------------------------------------------------------------------------------- /nawoj-frontend/src/generated/models/BaseResponse_LoginUserVO_.ts: -------------------------------------------------------------------------------- 1 | /* generated using openapi-typescript-codegen -- do no edit */ 2 | /* istanbul ignore file */ 3 | /* tslint:disable */ 4 | /* eslint-disable */ 5 | 6 | import type { LoginUserVO } from './LoginUserVO'; 7 | 8 | export type BaseResponse_LoginUserVO_ = { 9 | code?: number; 10 | data?: LoginUserVO; 11 | message?: string; 12 | }; 13 | -------------------------------------------------------------------------------- /nawoj-frontend/src/generated/models/BaseResponse_Page_PostVO_.ts: -------------------------------------------------------------------------------- 1 | /* generated using openapi-typescript-codegen -- do no edit */ 2 | /* istanbul ignore file */ 3 | /* tslint:disable */ 4 | /* eslint-disable */ 5 | 6 | import type { Page_PostVO_ } from './Page_PostVO_'; 7 | 8 | export type BaseResponse_Page_PostVO_ = { 9 | code?: number; 10 | data?: Page_PostVO_; 11 | message?: string; 12 | }; 13 | -------------------------------------------------------------------------------- /nawoj-frontend/src/generated/models/BaseResponse_Page_QuestionSubmitVO_.ts: -------------------------------------------------------------------------------- 1 | /* generated using openapi-typescript-codegen -- do no edit */ 2 | /* istanbul ignore file */ 3 | /* tslint:disable */ 4 | /* eslint-disable */ 5 | 6 | import type { Page_QuestionSubmitVO_ } from './Page_QuestionSubmitVO_'; 7 | 8 | export type BaseResponse_Page_QuestionSubmitVO_ = { 9 | code?: number; 10 | data?: Page_QuestionSubmitVO_; 11 | message?: string; 12 | }; 13 | -------------------------------------------------------------------------------- /nawoj-frontend/src/generated/models/BaseResponse_Page_QuestionVO_.ts: -------------------------------------------------------------------------------- 1 | /* generated using openapi-typescript-codegen -- do no edit */ 2 | /* istanbul ignore file */ 3 | /* tslint:disable */ 4 | /* eslint-disable */ 5 | 6 | import type { Page_QuestionVO_ } from './Page_QuestionVO_'; 7 | 8 | export type BaseResponse_Page_QuestionVO_ = { 9 | code?: number; 10 | data?: Page_QuestionVO_; 11 | message?: string; 12 | }; 13 | -------------------------------------------------------------------------------- /nawoj-frontend/src/generated/models/BaseResponse_Page_Question_.ts: -------------------------------------------------------------------------------- 1 | /* generated using openapi-typescript-codegen -- do no edit */ 2 | /* istanbul ignore file */ 3 | /* tslint:disable */ 4 | /* eslint-disable */ 5 | 6 | import type { Page_Question_ } from './Page_Question_'; 7 | 8 | export type BaseResponse_Page_Question_ = { 9 | code?: number; 10 | data?: Page_Question_; 11 | message?: string; 12 | }; 13 | -------------------------------------------------------------------------------- /nawoj-frontend/src/generated/models/BaseResponse_Page_UserVO_.ts: -------------------------------------------------------------------------------- 1 | /* generated using openapi-typescript-codegen -- do no edit */ 2 | /* istanbul ignore file */ 3 | /* tslint:disable */ 4 | /* eslint-disable */ 5 | 6 | import type { Page_UserVO_ } from './Page_UserVO_'; 7 | 8 | export type BaseResponse_Page_UserVO_ = { 9 | code?: number; 10 | data?: Page_UserVO_; 11 | message?: string; 12 | }; 13 | -------------------------------------------------------------------------------- /nawoj-frontend/src/generated/models/BaseResponse_Page_User_.ts: -------------------------------------------------------------------------------- 1 | /* generated using openapi-typescript-codegen -- do no edit */ 2 | /* istanbul ignore file */ 3 | /* tslint:disable */ 4 | /* eslint-disable */ 5 | 6 | import type { Page_User_ } from './Page_User_'; 7 | 8 | export type BaseResponse_Page_User_ = { 9 | code?: number; 10 | data?: Page_User_; 11 | message?: string; 12 | }; 13 | -------------------------------------------------------------------------------- /nawoj-frontend/src/generated/models/BaseResponse_PostVO_.ts: -------------------------------------------------------------------------------- 1 | /* generated using openapi-typescript-codegen -- do no edit */ 2 | /* istanbul ignore file */ 3 | /* tslint:disable */ 4 | /* eslint-disable */ 5 | 6 | import type { PostVO } from './PostVO'; 7 | 8 | export type BaseResponse_PostVO_ = { 9 | code?: number; 10 | data?: PostVO; 11 | message?: string; 12 | }; 13 | -------------------------------------------------------------------------------- /nawoj-frontend/src/generated/models/BaseResponse_QuestionVO_.ts: -------------------------------------------------------------------------------- 1 | /* generated using openapi-typescript-codegen -- do no edit */ 2 | /* istanbul ignore file */ 3 | /* tslint:disable */ 4 | /* eslint-disable */ 5 | 6 | import type { QuestionVO } from './QuestionVO'; 7 | 8 | export type BaseResponse_QuestionVO_ = { 9 | code?: number; 10 | data?: QuestionVO; 11 | message?: string; 12 | }; 13 | -------------------------------------------------------------------------------- /nawoj-frontend/src/generated/models/BaseResponse_Question_.ts: -------------------------------------------------------------------------------- 1 | /* generated using openapi-typescript-codegen -- do no edit */ 2 | /* istanbul ignore file */ 3 | /* tslint:disable */ 4 | /* eslint-disable */ 5 | 6 | import type { Question } from './Question'; 7 | 8 | export type BaseResponse_Question_ = { 9 | code?: number; 10 | data?: Question; 11 | message?: string; 12 | }; 13 | -------------------------------------------------------------------------------- /nawoj-frontend/src/generated/models/BaseResponse_UserVO_.ts: -------------------------------------------------------------------------------- 1 | /* generated using openapi-typescript-codegen -- do no edit */ 2 | /* istanbul ignore file */ 3 | /* tslint:disable */ 4 | /* eslint-disable */ 5 | 6 | import type { UserVO } from './UserVO'; 7 | 8 | export type BaseResponse_UserVO_ = { 9 | code?: number; 10 | data?: UserVO; 11 | message?: string; 12 | }; 13 | -------------------------------------------------------------------------------- /nawoj-frontend/src/generated/models/BaseResponse_User_.ts: -------------------------------------------------------------------------------- 1 | /* generated using openapi-typescript-codegen -- do no edit */ 2 | /* istanbul ignore file */ 3 | /* tslint:disable */ 4 | /* eslint-disable */ 5 | 6 | import type { User } from './User'; 7 | 8 | export type BaseResponse_User_ = { 9 | code?: number; 10 | data?: User; 11 | message?: string; 12 | }; 13 | -------------------------------------------------------------------------------- /nawoj-frontend/src/generated/models/BaseResponse_boolean_.ts: -------------------------------------------------------------------------------- 1 | /* generated using openapi-typescript-codegen -- do no edit */ 2 | /* istanbul ignore file */ 3 | /* tslint:disable */ 4 | /* eslint-disable */ 5 | 6 | export type BaseResponse_boolean_ = { 7 | code?: number; 8 | data?: boolean; 9 | message?: string; 10 | }; 11 | -------------------------------------------------------------------------------- /nawoj-frontend/src/generated/models/BaseResponse_int_.ts: -------------------------------------------------------------------------------- 1 | /* generated using openapi-typescript-codegen -- do no edit */ 2 | /* istanbul ignore file */ 3 | /* tslint:disable */ 4 | /* eslint-disable */ 5 | 6 | export type BaseResponse_int_ = { 7 | code?: number; 8 | data?: number; 9 | message?: string; 10 | }; 11 | -------------------------------------------------------------------------------- /nawoj-frontend/src/generated/models/BaseResponse_long_.ts: -------------------------------------------------------------------------------- 1 | /* generated using openapi-typescript-codegen -- do no edit */ 2 | /* istanbul ignore file */ 3 | /* tslint:disable */ 4 | /* eslint-disable */ 5 | 6 | export type BaseResponse_long_ = { 7 | code?: number; 8 | data?: number; 9 | message?: string; 10 | }; 11 | -------------------------------------------------------------------------------- /nawoj-frontend/src/generated/models/BaseResponse_string_.ts: -------------------------------------------------------------------------------- 1 | /* generated using openapi-typescript-codegen -- do no edit */ 2 | /* istanbul ignore file */ 3 | /* tslint:disable */ 4 | /* eslint-disable */ 5 | 6 | export type BaseResponse_string_ = { 7 | code?: number; 8 | data?: string; 9 | message?: string; 10 | }; 11 | -------------------------------------------------------------------------------- /nawoj-frontend/src/generated/models/DeleteRequest.ts: -------------------------------------------------------------------------------- 1 | /* generated using openapi-typescript-codegen -- do no edit */ 2 | /* istanbul ignore file */ 3 | /* tslint:disable */ 4 | /* eslint-disable */ 5 | 6 | export type DeleteRequest = { 7 | id?: number; 8 | }; 9 | -------------------------------------------------------------------------------- /nawoj-frontend/src/generated/models/JudgeCase.ts: -------------------------------------------------------------------------------- 1 | /* generated using openapi-typescript-codegen -- do no edit */ 2 | /* istanbul ignore file */ 3 | /* tslint:disable */ 4 | /* eslint-disable */ 5 | 6 | export type JudgeCase = { 7 | input?: string; 8 | output?: string; 9 | }; 10 | -------------------------------------------------------------------------------- /nawoj-frontend/src/generated/models/JudgeConfig.ts: -------------------------------------------------------------------------------- 1 | /* generated using openapi-typescript-codegen -- do no edit */ 2 | /* istanbul ignore file */ 3 | /* tslint:disable */ 4 | /* eslint-disable */ 5 | 6 | export type JudgeConfig = { 7 | memoryLimit?: number; 8 | stackLimit?: number; 9 | timeLimit?: number; 10 | }; 11 | -------------------------------------------------------------------------------- /nawoj-frontend/src/generated/models/JudgeInfo.ts: -------------------------------------------------------------------------------- 1 | /* generated using openapi-typescript-codegen -- do no edit */ 2 | /* istanbul ignore file */ 3 | /* tslint:disable */ 4 | /* eslint-disable */ 5 | 6 | export type JudgeInfo = { 7 | memory?: number; 8 | message?: string; 9 | time?: number; 10 | }; 11 | -------------------------------------------------------------------------------- /nawoj-frontend/src/generated/models/LoginUserVO.ts: -------------------------------------------------------------------------------- 1 | /* generated using openapi-typescript-codegen -- do no edit */ 2 | /* istanbul ignore file */ 3 | /* tslint:disable */ 4 | /* eslint-disable */ 5 | 6 | export type LoginUserVO = { 7 | createTime?: string; 8 | id?: number; 9 | updateTime?: string; 10 | userAvatar?: string; 11 | userName?: string; 12 | userProfile?: string; 13 | userRole?: string; 14 | }; 15 | -------------------------------------------------------------------------------- /nawoj-frontend/src/generated/models/OrderItem.ts: -------------------------------------------------------------------------------- 1 | /* generated using openapi-typescript-codegen -- do no edit */ 2 | /* istanbul ignore file */ 3 | /* tslint:disable */ 4 | /* eslint-disable */ 5 | 6 | export type OrderItem = { 7 | asc?: boolean; 8 | column?: string; 9 | }; 10 | -------------------------------------------------------------------------------- /nawoj-frontend/src/generated/models/Page_PostVO_.ts: -------------------------------------------------------------------------------- 1 | /* generated using openapi-typescript-codegen -- do no edit */ 2 | /* istanbul ignore file */ 3 | /* tslint:disable */ 4 | /* eslint-disable */ 5 | 6 | import type { OrderItem } from './OrderItem'; 7 | import type { PostVO } from './PostVO'; 8 | 9 | export type Page_PostVO_ = { 10 | countId?: string; 11 | current?: number; 12 | maxLimit?: number; 13 | optimizeCountSql?: boolean; 14 | orders?: Array; 15 | pages?: number; 16 | records?: Array; 17 | searchCount?: boolean; 18 | size?: number; 19 | total?: number; 20 | }; 21 | -------------------------------------------------------------------------------- /nawoj-frontend/src/generated/models/Page_QuestionSubmitVO_.ts: -------------------------------------------------------------------------------- 1 | /* generated using openapi-typescript-codegen -- do no edit */ 2 | /* istanbul ignore file */ 3 | /* tslint:disable */ 4 | /* eslint-disable */ 5 | 6 | import type { OrderItem } from './OrderItem'; 7 | import type { QuestionSubmitVO } from './QuestionSubmitVO'; 8 | 9 | export type Page_QuestionSubmitVO_ = { 10 | countId?: string; 11 | current?: number; 12 | maxLimit?: number; 13 | optimizeCountSql?: boolean; 14 | orders?: Array; 15 | pages?: number; 16 | records?: Array; 17 | searchCount?: boolean; 18 | size?: number; 19 | total?: number; 20 | }; 21 | -------------------------------------------------------------------------------- /nawoj-frontend/src/generated/models/Page_QuestionVO_.ts: -------------------------------------------------------------------------------- 1 | /* generated using openapi-typescript-codegen -- do no edit */ 2 | /* istanbul ignore file */ 3 | /* tslint:disable */ 4 | /* eslint-disable */ 5 | 6 | import type { OrderItem } from './OrderItem'; 7 | import type { QuestionVO } from './QuestionVO'; 8 | 9 | export type Page_QuestionVO_ = { 10 | countId?: string; 11 | current?: number; 12 | maxLimit?: number; 13 | optimizeCountSql?: boolean; 14 | orders?: Array; 15 | pages?: number; 16 | records?: Array; 17 | searchCount?: boolean; 18 | size?: number; 19 | total?: number; 20 | }; 21 | -------------------------------------------------------------------------------- /nawoj-frontend/src/generated/models/Page_Question_.ts: -------------------------------------------------------------------------------- 1 | /* generated using openapi-typescript-codegen -- do no edit */ 2 | /* istanbul ignore file */ 3 | /* tslint:disable */ 4 | /* eslint-disable */ 5 | 6 | import type { OrderItem } from './OrderItem'; 7 | import type { Question } from './Question'; 8 | 9 | export type Page_Question_ = { 10 | countId?: string; 11 | current?: number; 12 | maxLimit?: number; 13 | optimizeCountSql?: boolean; 14 | orders?: Array; 15 | pages?: number; 16 | records?: Array; 17 | searchCount?: boolean; 18 | size?: number; 19 | total?: number; 20 | }; 21 | -------------------------------------------------------------------------------- /nawoj-frontend/src/generated/models/Page_UserVO_.ts: -------------------------------------------------------------------------------- 1 | /* generated using openapi-typescript-codegen -- do no edit */ 2 | /* istanbul ignore file */ 3 | /* tslint:disable */ 4 | /* eslint-disable */ 5 | 6 | import type { OrderItem } from './OrderItem'; 7 | import type { UserVO } from './UserVO'; 8 | 9 | export type Page_UserVO_ = { 10 | countId?: string; 11 | current?: number; 12 | maxLimit?: number; 13 | optimizeCountSql?: boolean; 14 | orders?: Array; 15 | pages?: number; 16 | records?: Array; 17 | searchCount?: boolean; 18 | size?: number; 19 | total?: number; 20 | }; 21 | -------------------------------------------------------------------------------- /nawoj-frontend/src/generated/models/Page_User_.ts: -------------------------------------------------------------------------------- 1 | /* generated using openapi-typescript-codegen -- do no edit */ 2 | /* istanbul ignore file */ 3 | /* tslint:disable */ 4 | /* eslint-disable */ 5 | 6 | import type { OrderItem } from './OrderItem'; 7 | import type { User } from './User'; 8 | 9 | export type Page_User_ = { 10 | countId?: string; 11 | current?: number; 12 | maxLimit?: number; 13 | optimizeCountSql?: boolean; 14 | orders?: Array; 15 | pages?: number; 16 | records?: Array; 17 | searchCount?: boolean; 18 | size?: number; 19 | total?: number; 20 | }; 21 | -------------------------------------------------------------------------------- /nawoj-frontend/src/generated/models/PostAddRequest.ts: -------------------------------------------------------------------------------- 1 | /* generated using openapi-typescript-codegen -- do no edit */ 2 | /* istanbul ignore file */ 3 | /* tslint:disable */ 4 | /* eslint-disable */ 5 | 6 | export type PostAddRequest = { 7 | content?: string; 8 | tags?: Array; 9 | title?: string; 10 | }; 11 | -------------------------------------------------------------------------------- /nawoj-frontend/src/generated/models/PostEditRequest.ts: -------------------------------------------------------------------------------- 1 | /* generated using openapi-typescript-codegen -- do no edit */ 2 | /* istanbul ignore file */ 3 | /* tslint:disable */ 4 | /* eslint-disable */ 5 | 6 | export type PostEditRequest = { 7 | content?: string; 8 | id?: number; 9 | tags?: Array; 10 | title?: string; 11 | }; 12 | -------------------------------------------------------------------------------- /nawoj-frontend/src/generated/models/PostFavourAddRequest.ts: -------------------------------------------------------------------------------- 1 | /* generated using openapi-typescript-codegen -- do no edit */ 2 | /* istanbul ignore file */ 3 | /* tslint:disable */ 4 | /* eslint-disable */ 5 | 6 | export type PostFavourAddRequest = { 7 | postId?: number; 8 | }; 9 | -------------------------------------------------------------------------------- /nawoj-frontend/src/generated/models/PostFavourQueryRequest.ts: -------------------------------------------------------------------------------- 1 | /* generated using openapi-typescript-codegen -- do no edit */ 2 | /* istanbul ignore file */ 3 | /* tslint:disable */ 4 | /* eslint-disable */ 5 | 6 | import type { PostQueryRequest } from './PostQueryRequest'; 7 | 8 | export type PostFavourQueryRequest = { 9 | current?: number; 10 | pageSize?: number; 11 | postQueryRequest?: PostQueryRequest; 12 | sortField?: string; 13 | sortOrder?: string; 14 | userId?: number; 15 | }; 16 | -------------------------------------------------------------------------------- /nawoj-frontend/src/generated/models/PostQueryRequest.ts: -------------------------------------------------------------------------------- 1 | /* generated using openapi-typescript-codegen -- do no edit */ 2 | /* istanbul ignore file */ 3 | /* tslint:disable */ 4 | /* eslint-disable */ 5 | 6 | export type PostQueryRequest = { 7 | content?: string; 8 | current?: number; 9 | favourUserId?: number; 10 | id?: number; 11 | notId?: number; 12 | orTags?: Array; 13 | pageSize?: number; 14 | searchText?: string; 15 | sortField?: string; 16 | sortOrder?: string; 17 | tags?: Array; 18 | title?: string; 19 | userId?: number; 20 | }; 21 | -------------------------------------------------------------------------------- /nawoj-frontend/src/generated/models/PostThumbAddRequest.ts: -------------------------------------------------------------------------------- 1 | /* generated using openapi-typescript-codegen -- do no edit */ 2 | /* istanbul ignore file */ 3 | /* tslint:disable */ 4 | /* eslint-disable */ 5 | 6 | export type PostThumbAddRequest = { 7 | postId?: number; 8 | }; 9 | -------------------------------------------------------------------------------- /nawoj-frontend/src/generated/models/PostUpdateRequest.ts: -------------------------------------------------------------------------------- 1 | /* generated using openapi-typescript-codegen -- do no edit */ 2 | /* istanbul ignore file */ 3 | /* tslint:disable */ 4 | /* eslint-disable */ 5 | 6 | export type PostUpdateRequest = { 7 | content?: string; 8 | id?: number; 9 | tags?: Array; 10 | title?: string; 11 | }; 12 | -------------------------------------------------------------------------------- /nawoj-frontend/src/generated/models/PostVO.ts: -------------------------------------------------------------------------------- 1 | /* generated using openapi-typescript-codegen -- do no edit */ 2 | /* istanbul ignore file */ 3 | /* tslint:disable */ 4 | /* eslint-disable */ 5 | 6 | import type { UserVO } from './UserVO'; 7 | 8 | export type PostVO = { 9 | content?: string; 10 | createTime?: string; 11 | favourNum?: number; 12 | hasFavour?: boolean; 13 | hasThumb?: boolean; 14 | id?: number; 15 | tagList?: Array; 16 | thumbNum?: number; 17 | title?: string; 18 | updateTime?: string; 19 | user?: UserVO; 20 | userId?: number; 21 | }; 22 | -------------------------------------------------------------------------------- /nawoj-frontend/src/generated/models/Question.ts: -------------------------------------------------------------------------------- 1 | /* generated using openapi-typescript-codegen -- do no edit */ 2 | /* istanbul ignore file */ 3 | /* tslint:disable */ 4 | /* eslint-disable */ 5 | 6 | export type Question = { 7 | acceptedNum?: number; 8 | answer?: string; 9 | content?: string; 10 | createTime?: string; 11 | favourNum?: number; 12 | id?: number; 13 | isDelete?: number; 14 | judgeCase?: string; 15 | judgeConfig?: string; 16 | submitNum?: number; 17 | tags?: string; 18 | thumbNum?: number; 19 | title?: string; 20 | updateTime?: string; 21 | userId?: number; 22 | }; 23 | -------------------------------------------------------------------------------- /nawoj-frontend/src/generated/models/QuestionAddRequest.ts: -------------------------------------------------------------------------------- 1 | /* generated using openapi-typescript-codegen -- do no edit */ 2 | /* istanbul ignore file */ 3 | /* tslint:disable */ 4 | /* eslint-disable */ 5 | 6 | import type { JudgeCase } from './JudgeCase'; 7 | import type { JudgeConfig } from './JudgeConfig'; 8 | 9 | export type QuestionAddRequest = { 10 | answer?: string; 11 | content?: string; 12 | judgeCase?: Array; 13 | judgeConfig?: JudgeConfig; 14 | tags?: Array; 15 | title?: string; 16 | }; 17 | -------------------------------------------------------------------------------- /nawoj-frontend/src/generated/models/QuestionEditRequest.ts: -------------------------------------------------------------------------------- 1 | /* generated using openapi-typescript-codegen -- do no edit */ 2 | /* istanbul ignore file */ 3 | /* tslint:disable */ 4 | /* eslint-disable */ 5 | 6 | import type { JudgeCase } from './JudgeCase'; 7 | import type { JudgeConfig } from './JudgeConfig'; 8 | 9 | export type QuestionEditRequest = { 10 | answer?: string; 11 | content?: string; 12 | id?: number; 13 | judgeCase?: Array; 14 | judgeConfig?: JudgeConfig; 15 | tags?: Array; 16 | title?: string; 17 | }; 18 | -------------------------------------------------------------------------------- /nawoj-frontend/src/generated/models/QuestionQueryRequest.ts: -------------------------------------------------------------------------------- 1 | /* generated using openapi-typescript-codegen -- do no edit */ 2 | /* istanbul ignore file */ 3 | /* tslint:disable */ 4 | /* eslint-disable */ 5 | 6 | export type QuestionQueryRequest = { 7 | answer?: string; 8 | content?: string; 9 | current?: number; 10 | id?: number; 11 | pageSize?: number; 12 | sortField?: string; 13 | sortOrder?: string; 14 | tags?: Array; 15 | title?: string; 16 | userId?: number; 17 | }; 18 | -------------------------------------------------------------------------------- /nawoj-frontend/src/generated/models/QuestionSubmitAddRequest.ts: -------------------------------------------------------------------------------- 1 | /* generated using openapi-typescript-codegen -- do no edit */ 2 | /* istanbul ignore file */ 3 | /* tslint:disable */ 4 | /* eslint-disable */ 5 | 6 | export type QuestionSubmitAddRequest = { 7 | code?: string; 8 | language?: string; 9 | questionId?: number; 10 | }; 11 | -------------------------------------------------------------------------------- /nawoj-frontend/src/generated/models/QuestionSubmitQueryRequest.ts: -------------------------------------------------------------------------------- 1 | /* generated using openapi-typescript-codegen -- do no edit */ 2 | /* istanbul ignore file */ 3 | /* tslint:disable */ 4 | /* eslint-disable */ 5 | 6 | export type QuestionSubmitQueryRequest = { 7 | current?: number; 8 | language?: string; 9 | pageSize?: number; 10 | questionId?: number; 11 | sortField?: string; 12 | sortOrder?: string; 13 | status?: number; 14 | userId?: number; 15 | }; 16 | -------------------------------------------------------------------------------- /nawoj-frontend/src/generated/models/QuestionSubmitVO.ts: -------------------------------------------------------------------------------- 1 | /* generated using openapi-typescript-codegen -- do no edit */ 2 | /* istanbul ignore file */ 3 | /* tslint:disable */ 4 | /* eslint-disable */ 5 | 6 | import type { JudgeInfo } from './JudgeInfo'; 7 | import type { QuestionVO } from './QuestionVO'; 8 | import type { UserVO } from './UserVO'; 9 | 10 | export type QuestionSubmitVO = { 11 | code?: string; 12 | createTime?: string; 13 | id?: number; 14 | judgeInfo?: JudgeInfo; 15 | language?: string; 16 | questionId?: number; 17 | questionVO?: QuestionVO; 18 | status?: number; 19 | updateTime?: string; 20 | userId?: number; 21 | userVO?: UserVO; 22 | }; 23 | -------------------------------------------------------------------------------- /nawoj-frontend/src/generated/models/QuestionUpdateRequest.ts: -------------------------------------------------------------------------------- 1 | /* generated using openapi-typescript-codegen -- do no edit */ 2 | /* istanbul ignore file */ 3 | /* tslint:disable */ 4 | /* eslint-disable */ 5 | 6 | import type { JudgeCase } from './JudgeCase'; 7 | import type { JudgeConfig } from './JudgeConfig'; 8 | 9 | export type QuestionUpdateRequest = { 10 | answer?: string; 11 | content?: string; 12 | id?: number; 13 | judgeCase?: Array; 14 | judgeConfig?: JudgeConfig; 15 | tags?: Array; 16 | title?: string; 17 | }; 18 | -------------------------------------------------------------------------------- /nawoj-frontend/src/generated/models/QuestionVO.ts: -------------------------------------------------------------------------------- 1 | /* generated using openapi-typescript-codegen -- do no edit */ 2 | /* istanbul ignore file */ 3 | /* tslint:disable */ 4 | /* eslint-disable */ 5 | 6 | import type { JudgeConfig } from './JudgeConfig'; 7 | import type { UserVO } from './UserVO'; 8 | 9 | export type QuestionVO = { 10 | acceptedNum?: number; 11 | content?: string; 12 | createTime?: string; 13 | favourNum?: number; 14 | id?: number; 15 | judgeConfig?: JudgeConfig; 16 | submitNum?: number; 17 | tags?: Array; 18 | thumbNum?: number; 19 | title?: string; 20 | updateTime?: string; 21 | userId?: number; 22 | userVO?: UserVO; 23 | }; 24 | -------------------------------------------------------------------------------- /nawoj-frontend/src/generated/models/User.ts: -------------------------------------------------------------------------------- 1 | /* generated using openapi-typescript-codegen -- do no edit */ 2 | /* istanbul ignore file */ 3 | /* tslint:disable */ 4 | /* eslint-disable */ 5 | 6 | export type User = { 7 | createTime?: string; 8 | id?: number; 9 | isDelete?: number; 10 | mpOpenId?: string; 11 | unionId?: string; 12 | updateTime?: string; 13 | userAccount?: string; 14 | userAvatar?: string; 15 | userName?: string; 16 | userPassword?: string; 17 | userProfile?: string; 18 | userRole?: string; 19 | }; 20 | -------------------------------------------------------------------------------- /nawoj-frontend/src/generated/models/UserAddRequest.ts: -------------------------------------------------------------------------------- 1 | /* generated using openapi-typescript-codegen -- do no edit */ 2 | /* istanbul ignore file */ 3 | /* tslint:disable */ 4 | /* eslint-disable */ 5 | 6 | export type UserAddRequest = { 7 | userAccount?: string; 8 | userAvatar?: string; 9 | userName?: string; 10 | userRole?: string; 11 | }; 12 | -------------------------------------------------------------------------------- /nawoj-frontend/src/generated/models/UserLoginRequest.ts: -------------------------------------------------------------------------------- 1 | /* generated using openapi-typescript-codegen -- do no edit */ 2 | /* istanbul ignore file */ 3 | /* tslint:disable */ 4 | /* eslint-disable */ 5 | 6 | export type UserLoginRequest = { 7 | userAccount?: string; 8 | userPassword?: string; 9 | }; 10 | -------------------------------------------------------------------------------- /nawoj-frontend/src/generated/models/UserQueryRequest.ts: -------------------------------------------------------------------------------- 1 | /* generated using openapi-typescript-codegen -- do no edit */ 2 | /* istanbul ignore file */ 3 | /* tslint:disable */ 4 | /* eslint-disable */ 5 | 6 | export type UserQueryRequest = { 7 | current?: number; 8 | id?: number; 9 | mpOpenId?: string; 10 | pageSize?: number; 11 | sortField?: string; 12 | sortOrder?: string; 13 | unionId?: string; 14 | userName?: string; 15 | userProfile?: string; 16 | userRole?: string; 17 | }; 18 | -------------------------------------------------------------------------------- /nawoj-frontend/src/generated/models/UserRegisterRequest.ts: -------------------------------------------------------------------------------- 1 | /* generated using openapi-typescript-codegen -- do no edit */ 2 | /* istanbul ignore file */ 3 | /* tslint:disable */ 4 | /* eslint-disable */ 5 | 6 | export type UserRegisterRequest = { 7 | checkPassword?: string; 8 | userAccount?: string; 9 | userPassword?: string; 10 | }; 11 | -------------------------------------------------------------------------------- /nawoj-frontend/src/generated/models/UserUpdateMyRequest.ts: -------------------------------------------------------------------------------- 1 | /* generated using openapi-typescript-codegen -- do no edit */ 2 | /* istanbul ignore file */ 3 | /* tslint:disable */ 4 | /* eslint-disable */ 5 | 6 | export type UserUpdateMyRequest = { 7 | userAvatar?: string; 8 | userName?: string; 9 | userProfile?: string; 10 | }; 11 | -------------------------------------------------------------------------------- /nawoj-frontend/src/generated/models/UserUpdateRequest.ts: -------------------------------------------------------------------------------- 1 | /* generated using openapi-typescript-codegen -- do no edit */ 2 | /* istanbul ignore file */ 3 | /* tslint:disable */ 4 | /* eslint-disable */ 5 | 6 | export type UserUpdateRequest = { 7 | id?: number; 8 | userAvatar?: string; 9 | userName?: string; 10 | userProfile?: string; 11 | userRole?: string; 12 | }; 13 | -------------------------------------------------------------------------------- /nawoj-frontend/src/generated/models/UserVO.ts: -------------------------------------------------------------------------------- 1 | /* generated using openapi-typescript-codegen -- do no edit */ 2 | /* istanbul ignore file */ 3 | /* tslint:disable */ 4 | /* eslint-disable */ 5 | 6 | export type UserVO = { 7 | createTime?: string; 8 | id?: number; 9 | userAvatar?: string; 10 | userName?: string; 11 | userProfile?: string; 12 | userRole?: string; 13 | }; 14 | -------------------------------------------------------------------------------- /nawoj-frontend/src/generated/services/FileControllerService.ts: -------------------------------------------------------------------------------- 1 | /* generated using openapi-typescript-codegen -- do no edit */ 2 | /* istanbul ignore file */ 3 | /* tslint:disable */ 4 | /* eslint-disable */ 5 | import type { BaseResponse_string_ } from '../models/BaseResponse_string_'; 6 | 7 | import type { CancelablePromise } from '../core/CancelablePromise'; 8 | import { OpenAPI } from '../core/OpenAPI'; 9 | import { request as __request } from '../core/request'; 10 | 11 | export class FileControllerService { 12 | 13 | /** 14 | * uploadFile 15 | * @param biz 16 | * @param file 17 | * @returns BaseResponse_string_ OK 18 | * @returns any Created 19 | * @throws ApiError 20 | */ 21 | public static uploadFileUsingPost( 22 | biz?: string, 23 | file?: Blob, 24 | ): CancelablePromise { 25 | return __request(OpenAPI, { 26 | method: 'POST', 27 | url: '/api/file/upload', 28 | query: { 29 | 'biz': biz, 30 | }, 31 | formData: { 32 | 'file': file, 33 | }, 34 | errors: { 35 | 401: `Unauthorized`, 36 | 403: `Forbidden`, 37 | 404: `Not Found`, 38 | }, 39 | }); 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /nawoj-frontend/src/generated/services/PostFavourControllerService.ts: -------------------------------------------------------------------------------- 1 | /* generated using openapi-typescript-codegen -- do no edit */ 2 | /* istanbul ignore file */ 3 | /* tslint:disable */ 4 | /* eslint-disable */ 5 | import type { BaseResponse_int_ } from '../models/BaseResponse_int_'; 6 | import type { BaseResponse_Page_PostVO_ } from '../models/BaseResponse_Page_PostVO_'; 7 | import type { PostFavourAddRequest } from '../models/PostFavourAddRequest'; 8 | import type { PostFavourQueryRequest } from '../models/PostFavourQueryRequest'; 9 | import type { PostQueryRequest } from '../models/PostQueryRequest'; 10 | 11 | import type { CancelablePromise } from '../core/CancelablePromise'; 12 | import { OpenAPI } from '../core/OpenAPI'; 13 | import { request as __request } from '../core/request'; 14 | 15 | export class PostFavourControllerService { 16 | 17 | /** 18 | * doPostFavour 19 | * @param postFavourAddRequest postFavourAddRequest 20 | * @returns BaseResponse_int_ OK 21 | * @returns any Created 22 | * @throws ApiError 23 | */ 24 | public static doPostFavourUsingPost( 25 | postFavourAddRequest: PostFavourAddRequest, 26 | ): CancelablePromise { 27 | return __request(OpenAPI, { 28 | method: 'POST', 29 | url: '/api/post_favour/', 30 | body: postFavourAddRequest, 31 | errors: { 32 | 401: `Unauthorized`, 33 | 403: `Forbidden`, 34 | 404: `Not Found`, 35 | }, 36 | }); 37 | } 38 | 39 | /** 40 | * listFavourPostByPage 41 | * @param postFavourQueryRequest postFavourQueryRequest 42 | * @returns BaseResponse_Page_PostVO_ OK 43 | * @returns any Created 44 | * @throws ApiError 45 | */ 46 | public static listFavourPostByPageUsingPost( 47 | postFavourQueryRequest: PostFavourQueryRequest, 48 | ): CancelablePromise { 49 | return __request(OpenAPI, { 50 | method: 'POST', 51 | url: '/api/post_favour/list/page', 52 | body: postFavourQueryRequest, 53 | errors: { 54 | 401: `Unauthorized`, 55 | 403: `Forbidden`, 56 | 404: `Not Found`, 57 | }, 58 | }); 59 | } 60 | 61 | /** 62 | * listMyFavourPostByPage 63 | * @param postQueryRequest postQueryRequest 64 | * @returns BaseResponse_Page_PostVO_ OK 65 | * @returns any Created 66 | * @throws ApiError 67 | */ 68 | public static listMyFavourPostByPageUsingPost( 69 | postQueryRequest: PostQueryRequest, 70 | ): CancelablePromise { 71 | return __request(OpenAPI, { 72 | method: 'POST', 73 | url: '/api/post_favour/my/list/page', 74 | body: postQueryRequest, 75 | errors: { 76 | 401: `Unauthorized`, 77 | 403: `Forbidden`, 78 | 404: `Not Found`, 79 | }, 80 | }); 81 | } 82 | 83 | } 84 | -------------------------------------------------------------------------------- /nawoj-frontend/src/generated/services/PostThumbControllerService.ts: -------------------------------------------------------------------------------- 1 | /* generated using openapi-typescript-codegen -- do no edit */ 2 | /* istanbul ignore file */ 3 | /* tslint:disable */ 4 | /* eslint-disable */ 5 | import type { BaseResponse_int_ } from '../models/BaseResponse_int_'; 6 | import type { PostThumbAddRequest } from '../models/PostThumbAddRequest'; 7 | 8 | import type { CancelablePromise } from '../core/CancelablePromise'; 9 | import { OpenAPI } from '../core/OpenAPI'; 10 | import { request as __request } from '../core/request'; 11 | 12 | export class PostThumbControllerService { 13 | 14 | /** 15 | * doThumb 16 | * @param postThumbAddRequest postThumbAddRequest 17 | * @returns BaseResponse_int_ OK 18 | * @returns any Created 19 | * @throws ApiError 20 | */ 21 | public static doThumbUsingPost( 22 | postThumbAddRequest: PostThumbAddRequest, 23 | ): CancelablePromise { 24 | return __request(OpenAPI, { 25 | method: 'POST', 26 | url: '/api/post_thumb/', 27 | body: postThumbAddRequest, 28 | errors: { 29 | 401: `Unauthorized`, 30 | 403: `Forbidden`, 31 | 404: `Not Found`, 32 | }, 33 | }); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /nawoj-frontend/src/generated/services/WxMpControllerService.ts: -------------------------------------------------------------------------------- 1 | /* generated using openapi-typescript-codegen -- do no edit */ 2 | /* istanbul ignore file */ 3 | /* tslint:disable */ 4 | /* eslint-disable */ 5 | import type { CancelablePromise } from '../core/CancelablePromise'; 6 | import { OpenAPI } from '../core/OpenAPI'; 7 | import { request as __request } from '../core/request'; 8 | 9 | export class WxMpControllerService { 10 | 11 | /** 12 | * check 13 | * @param echostr echostr 14 | * @param nonce nonce 15 | * @param signature signature 16 | * @param timestamp timestamp 17 | * @returns string OK 18 | * @throws ApiError 19 | */ 20 | public static checkUsingGet( 21 | echostr?: string, 22 | nonce?: string, 23 | signature?: string, 24 | timestamp?: string, 25 | ): CancelablePromise { 26 | return __request(OpenAPI, { 27 | method: 'GET', 28 | url: '/api/', 29 | query: { 30 | 'echostr': echostr, 31 | 'nonce': nonce, 32 | 'signature': signature, 33 | 'timestamp': timestamp, 34 | }, 35 | errors: { 36 | 401: `Unauthorized`, 37 | 403: `Forbidden`, 38 | 404: `Not Found`, 39 | }, 40 | }); 41 | } 42 | 43 | /** 44 | * receiveMessage 45 | * @returns any OK 46 | * @throws ApiError 47 | */ 48 | public static receiveMessageUsingPost(): CancelablePromise { 49 | return __request(OpenAPI, { 50 | method: 'POST', 51 | url: '/api/', 52 | errors: { 53 | 401: `Unauthorized`, 54 | 403: `Forbidden`, 55 | 404: `Not Found`, 56 | }, 57 | }); 58 | } 59 | 60 | /** 61 | * setMenu 62 | * @returns string OK 63 | * @throws ApiError 64 | */ 65 | public static setMenuUsingGet(): CancelablePromise { 66 | return __request(OpenAPI, { 67 | method: 'GET', 68 | url: '/api/setMenu', 69 | errors: { 70 | 401: `Unauthorized`, 71 | 403: `Forbidden`, 72 | 404: `Not Found`, 73 | }, 74 | }); 75 | } 76 | 77 | } 78 | -------------------------------------------------------------------------------- /nawoj-frontend/src/layouts/BasicLayout.vue: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | Power By Peelsannaw 18 | 19 | 20 | 21 | 22 | 23 | 27 | 28 | 53 | -------------------------------------------------------------------------------- /nawoj-frontend/src/main.ts: -------------------------------------------------------------------------------- 1 | import { createApp } from "vue"; 2 | import App from "./App.vue"; 3 | import router from "./router"; 4 | import store from "./store"; 5 | import ArcoVue from '@arco-design/web-vue'; 6 | import '@arco-design/web-vue/dist/arco.css'; 7 | import "../src/utils/request.ts" 8 | import "@/access/index.ts" 9 | import ArcoVueIcon from '@arco-design/web-vue/es/icon'; 10 | 11 | 12 | 13 | createApp(App).use(store).use(router).use(ArcoVue).use(ArcoVueIcon).mount("#app"); 14 | -------------------------------------------------------------------------------- /nawoj-frontend/src/router/index.ts: -------------------------------------------------------------------------------- 1 | import { createRouter, createWebHistory } from "vue-router"; 2 | import { routes } from'./routes' 3 | 4 | 5 | const router = createRouter({ 6 | history: createWebHistory(process.env.BASE_URL), 7 | routes, 8 | }); 9 | 10 | export default router; 11 | -------------------------------------------------------------------------------- /nawoj-frontend/src/router/routes.ts: -------------------------------------------------------------------------------- 1 | import { RouteRecordRaw } from "vue-router"; 2 | import HomeView from "../views/HomeView.vue"; 3 | import AboutViewVue from "@/views/AboutView.vue"; 4 | import notFound from "@/views/NotFoundView.vue" 5 | import UserLoginViewVue from "@/views/UserLoginView.vue"; 6 | import UserRegisterView from '@/views/UserRegisterView.vue' 7 | /* 8 | 0:游客 9 | 1:普通用户 10 | 2:管理员 11 | */ 12 | export const routes: Array = [ 13 | { 14 | path: "/home", 15 | name: "主页", 16 | component: HomeView, 17 | meta: { 18 | access: 0, 19 | hide:true 20 | }, 21 | 22 | }, 23 | 24 | { 25 | path: "/problem", 26 | name: "问题", 27 | component: AboutViewVue, 28 | meta: { 29 | access: 0 as number 30 | }, 31 | }, 32 | { 33 | path: "/status", 34 | name: "状态", 35 | component: AboutViewVue, 36 | meta: { 37 | access: 0 as number 38 | }, 39 | }, 40 | { 41 | path: "/ranking", 42 | name: "排名", 43 | component: AboutViewVue, 44 | meta: { 45 | access: 0 as number 46 | }, 47 | }, 48 | { 49 | path: "/notification", 50 | name: "公告", 51 | component: AboutViewVue, 52 | meta: { 53 | access: 1 as number 54 | }, 55 | }, 56 | { 57 | path: "/statistics", 58 | name: "统计", 59 | component: AboutViewVue, 60 | meta: { 61 | access: 2 as number 62 | }, 63 | }, 64 | { 65 | path: '/404', 66 | name: 'not found', 67 | component: notFound, 68 | meta: { 69 | access: 0 as number, 70 | hide:true 71 | }, 72 | }, 73 | { 74 | path: "/user/login", 75 | name: "登录", 76 | component: UserLoginViewVue, 77 | meta: { 78 | access: 0 as number, 79 | hide:true 80 | }, 81 | }, 82 | { 83 | path: "/user/register", 84 | name: "注册", 85 | component: UserRegisterView, 86 | meta: { 87 | access: 0 as number, 88 | hide:true 89 | }, 90 | }, 91 | { 92 | path: "/user/profile", 93 | name: "用户中心", 94 | component: AboutViewVue, 95 | meta: { 96 | access: 1 as number, 97 | hide:true 98 | 99 | }, 100 | }, 101 | { 102 | path: '/:catchAll(.*)', 103 | redirect: '404' 104 | } 105 | ]; 106 | 107 | -------------------------------------------------------------------------------- /nawoj-frontend/src/shims-vue.d.ts: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | declare module '*.vue' { 3 | import type { DefineComponent } from 'vue' 4 | const component: DefineComponent<{}, {}, any> 5 | export default component 6 | } 7 | -------------------------------------------------------------------------------- /nawoj-frontend/src/store/index.ts: -------------------------------------------------------------------------------- 1 | import { createStore } from "vuex"; 2 | import user from './user' 3 | export default createStore({ 4 | 5 | state: {}, 6 | 7 | getters: {}, 8 | 9 | mutations: {}, 10 | 11 | actions: {}, 12 | 13 | modules: { 14 | user 15 | }, 16 | }); 17 | -------------------------------------------------------------------------------- /nawoj-frontend/src/store/user.ts: -------------------------------------------------------------------------------- 1 | import accessEnum from "@/access/accessEnum" 2 | import { UserControllerService } from "@/generated" 3 | 4 | import { StoreOptions } from "vuex" 5 | 6 | 7 | export default { 8 | namespaced:true, 9 | state: () => ({ 10 | loginUser: { 11 | userName: '未登录', 12 | access:accessEnum.ACCESS_ENUM.NOT_LOGIN, 13 | userAvatar:'https://cdn-mii.accounts.nintendo.com/2.0.0/mii_images/bea740be86a52acc/f78ed1356367c2f2bd6da2c0f68511c9e88ebdfb.png?type=face&width=140&bgColor=DFDFDFFF', 14 | userProfile:'', 15 | id:-1 16 | }, 17 | }), 18 | 19 | getters : {}, 20 | 21 | //async 22 | actions:{ 23 | async getLoginUser({ commit,state}, payload) { 24 | const res = await UserControllerService.getLoginUserUsingGet(); 25 | console.log(res) 26 | if(res.code===0){ 27 | commit("updateUser", res.data) 28 | }else{ 29 | commit("updateUser",{ 30 | ...state.loginUser, 31 | access:accessEnum.ACCESS_ENUM.NOT_LOGIN 32 | }) 33 | 34 | } 35 | } 36 | }, 37 | 38 | //sync 39 | mutations: { 40 | updateUser(state, payload) { 41 | state.loginUser = payload 42 | 43 | } 44 | }, 45 | 46 | 47 | 48 | 49 | } as StoreOptions -------------------------------------------------------------------------------- /nawoj-frontend/src/types/user.ts: -------------------------------------------------------------------------------- 1 | 2 | type userLoginDto = { 3 | userName: string, 4 | password: string, 5 | avatar: string, 6 | } 7 | type userVo = { 8 | userName: string, 9 | nickName: string, 10 | avatar: string, 11 | email: string 12 | } 13 | export { 14 | userLoginDto, 15 | userVo, 16 | 17 | } -------------------------------------------------------------------------------- /nawoj-frontend/src/utils/request.ts: -------------------------------------------------------------------------------- 1 | import axios from "axios"; 2 | 3 | axios.defaults.withCredentials = true; 4 | 5 | axios.interceptors.request.use( 6 | function (config) { 7 | // Do something before request is sent 8 | return config; 9 | }, 10 | function (error) { 11 | // Do something with request error 12 | return Promise.reject(error); 13 | } 14 | ); 15 | 16 | // Add a response interceptor 17 | axios.interceptors.response.use( 18 | function (response) { 19 | console.log("响应", response.data); 20 | // Any status code that lie within the range of 2xx cause this function to trigger 21 | // Do something with response data 22 | return response; 23 | }, 24 | function (error) { 25 | // Any status codes that falls outside the range of 2xx cause this function to trigger 26 | // Do something with response error 27 | return Promise.reject(error); 28 | } 29 | ); 30 | -------------------------------------------------------------------------------- /nawoj-frontend/src/views/AboutView.vue: -------------------------------------------------------------------------------- 1 | 2 | 3 | This is an about page 4 | 5 | 6 | -------------------------------------------------------------------------------- /nawoj-frontend/src/views/HomeView.vue: -------------------------------------------------------------------------------- 1 | 2 | This is a home page 3 | This is a home page 4 | This is a home page 5 | This is a home page 6 | This is a home page 7 | This is a home page 8 | This is a home page 9 | This is a home page 10 | This is a home page 11 | This is a home page 12 | 13 | 14 | 20 | -------------------------------------------------------------------------------- /nawoj-frontend/src/views/NotFoundView.vue: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 将在 {{ leftTime }} 后返回主页 6 | 7 | 8 | 9 | 10 | 11 | 36 | -------------------------------------------------------------------------------- /nawoj-frontend/src/views/UserLoginView.vue: -------------------------------------------------------------------------------- 1 | 2 | 3 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 保存登录信息 36 | 37 | 38 | 提交 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 83 | 84 | 90 | -------------------------------------------------------------------------------- /nawoj-frontend/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "esnext", 4 | "module": "esnext", 5 | "strict": true, 6 | "jsx": "preserve", 7 | "moduleResolution": "node", 8 | "skipLibCheck": true, 9 | "esModuleInterop": true, 10 | "allowSyntheticDefaultImports": true, 11 | "forceConsistentCasingInFileNames": true, 12 | "useDefineForClassFields": true, 13 | "sourceMap": true, 14 | "baseUrl": ".", 15 | "types": [ 16 | "webpack-env" 17 | ], 18 | "paths": { 19 | "@/*": [ 20 | "src/*" 21 | ] 22 | }, 23 | "lib": [ 24 | "esnext", 25 | "dom", 26 | "dom.iterable", 27 | "scripthost" 28 | ] 29 | }, 30 | "include": [ 31 | "src/**/*.ts", 32 | "src/**/*.tsx", 33 | "src/**/*.vue", 34 | "tests/**/*.ts", 35 | "tests/**/*.tsx" 36 | ], 37 | "exclude": [ 38 | "node_modules" 39 | ] 40 | } 41 | -------------------------------------------------------------------------------- /nawoj-frontend/vue.config.js: -------------------------------------------------------------------------------- 1 | const { defineConfig } = require("@vue/cli-service"); 2 | module.exports = defineConfig({ 3 | transpileDependencies: true, 4 | }); 5 | --------------------------------------------------------------------------------