Bläddra i källkod

bugfix:为前后端做修改

白白 2 år sedan
förälder
incheckning
fc2e0862df

+ 5 - 5
.drone.yml

@@ -21,7 +21,7 @@ steps:
       password:
         from_secret: docker-password
       registry: registry.cn-hangzhou.aliyuncs.com
-      repo: registry.cn-hangzhou.aliyuncs.com/english-ai/eai-backend
+      repo: registry.cn-hangzhou.aliyuncs.com/english_ai/eai_backend
       tags: latest
       dockerfile: Dockerfile
 
@@ -35,13 +35,13 @@ steps:
       DOCKER_PASSWORD:
         from_secret: docker-password
       DOCKER_REGISTRY: registry.cn-hangzhou.aliyuncs.com
-      IMAGE_NAME: english-ai/eai-backend
+      IMAGE_NAME: english_ai/eai_backend
       IMAGE_TAG: latest
     settings:
-      host: 47.111.23.171
+      host: 8.130.126.86
       username: root
       password:
-        from_secret: server-password
+        from_secret: ssh_password
       port: 22
       envs: [DOCKER_USERNAME,DOCKER_PASSWORD,DOCKER_REGISTRY,CONTAINER_NAME,IMAGE_NAME,IMAGE_TAG]
       script:
@@ -58,4 +58,4 @@ volumes:
 
 trigger:
   branch:
-    - main
+    - master

+ 6 - 1
README.md

@@ -1 +1,6 @@
-# EAI-Backend
+<<<<<<< HEAD
+# EAI-Backend
+EAI专业英语写作系统
+=======
+# EAI-Backend
+>>>>>>> f196f99 (feat:完整代码提交)

+ 7 - 0
pom.xml

@@ -186,6 +186,13 @@
                     </excludes>
                 </configuration>
             </plugin>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-surefire-plugin</artifactId>
+                <configuration>
+                    <testFailureIgnore>true</testFailureIgnore>
+                </configuration>
+            </plugin>
         </plugins>
     </build>
 

+ 6 - 0
src/main/java/com/njuzr/eaibackend/EaiBackendApplication.java

@@ -1,9 +1,15 @@
 package com.njuzr.eaibackend;
 
+import com.njuzr.eaibackend.config.OssConfig;
+import org.apache.ibatis.annotations.Mapper;
+import org.mybatis.spring.annotation.MapperScan;
 import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 
 @SpringBootApplication
+//@EnableAutoConfiguration
+//@MapperScan("com.njuzr.eaibackend.mapper")
 public class EaiBackendApplication {
 
     public static void main(String[] args) {

+ 3 - 3
src/main/java/com/njuzr/eaibackend/config/OssConfig.java

@@ -14,13 +14,13 @@ import org.springframework.context.annotation.Configuration;
 
 @Configuration
 public class OssConfig {
-    @Value("${aliyun.oss.endpoint}")
+    @Value("oss-cn-shanghai.aliyuncs.com")
     private String endpoint;
 
-    @Value("${aliyun.oss.accessKeyId}")
+    @Value("LTAI5tKsfJJKByjVqNKCvRR3")
     private String accessKeyId;
 
-    @Value("${aliyun.oss.accessKeySecret}")
+    @Value("fckFhhxhG234aOZfjIAxZZuFA3RCkH")
     private String accessKeySecret;
 
     @Bean

+ 3 - 1
src/main/java/com/njuzr/eaibackend/config/WebConfig.java

@@ -14,7 +14,9 @@ public class WebConfig implements WebMvcConfigurer {
     //设置允许访问的来源
     String[] origins = new String[]{
             "http://localhost:3000",
-            "http://localhost:3001"
+            "http://localhost:3001",
+            "http://127.0.0.1:4000",
+            "http://127.0.0.1:4001",
     };
 
     @Override

+ 15 - 1
src/main/java/com/njuzr/eaibackend/controller/AssignmentController.java

@@ -7,6 +7,7 @@ import com.njuzr.eaibackend.dto.AssignmentUpdateDTO;
 import com.njuzr.eaibackend.dto.CorrectDTO;
 import com.njuzr.eaibackend.enums.AssignmentCompletionStatus;
 import com.njuzr.eaibackend.po.Assignment;
+import com.njuzr.eaibackend.po.Engagement;
 import com.njuzr.eaibackend.po.MyUserDetails;
 import com.njuzr.eaibackend.service.AIDialogueService;
 import com.njuzr.eaibackend.service.AssignmentService;
@@ -54,7 +55,8 @@ public class AssignmentController {
     }
 
 
-    @GetMapping
+    // TODO:Get改Post
+    @PostMapping("/query")
     public MyResponse findAssignmentPage(
             @RequestParam(value = "page", defaultValue = "1") int currentPage,
             @RequestParam(value = "size", defaultValue = "10") int pageSize,
@@ -132,6 +134,18 @@ public class AssignmentController {
         return MyResponse.success(assignmentService.getEngagement(studentId, assignmentId));
     }
 
+    // TODO: (柏琪) 新增接口
+    @PostMapping("/engage/query")
+    public MyResponse findEngagementPage(
+            @RequestParam(value = "page", defaultValue = "1") int currentPage,
+            @RequestParam(value = "size", defaultValue = "10") int pageSize,
+            @RequestParam Long assignmentId
+
+    ) {
+        Page<Engagement> page = new Page<>(currentPage, pageSize);
+        return MyResponse.success(assignmentService.findEngagementPage(page, assignmentId));
+    }
+
     @GetMapping("/engage/detail")
     public MyResponse getDetailEngagement(
             @RequestParam Long studentId,

+ 2 - 4
src/main/java/com/njuzr/eaibackend/controller/AuthenticationController.java

@@ -15,10 +15,7 @@ import org.springframework.security.authentication.UsernamePasswordAuthenticatio
 import org.springframework.security.core.Authentication;
 import org.springframework.security.core.context.SecurityContextHolder;
 import org.springframework.security.core.userdetails.UsernameNotFoundException;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 
 /**
  * @author: Leonezhurui
@@ -28,6 +25,7 @@ import org.springframework.web.bind.annotation.RestController;
 
 @Slf4j
 @RestController
+@CrossOrigin
 @RequestMapping("/api/user")
 public class AuthenticationController {
 

+ 4 - 2
src/main/java/com/njuzr/eaibackend/controller/CourseController.java

@@ -55,8 +55,10 @@ public class CourseController {
      * @param courseQueryDTO
      * @return
      */
-    @PreAuthorize("hasRole('ADMIN')")
-    @GetMapping
+    // TODO:权限修改
+    // @PreAuthorize("hasRole('ADMIN')")
+    // TODO: Get改为Post,因为有@RequestBody
+    @PostMapping("/query")
     public MyResponse findCoursePage(
             @RequestParam(value = "page", defaultValue = "1") int currentPage,
             @RequestParam(value = "size", defaultValue = "10") int pageSize,

+ 2 - 1
src/main/java/com/njuzr/eaibackend/controller/UserController.java

@@ -85,8 +85,9 @@ public class UserController {
      * @param id
      * @return
      */
+    // TODO: 学生端也要根据id查询课程老师姓名
     @GetMapping()
-    @PreAuthorize("hasRole('ROLE_ADMIN') or hasRole('ROLE_TEACHER')")
+//    @PreAuthorize("hasRole('ROLE_ADMIN') or hasRole('ROLE_TEACHER')")
     public MyResponse searchUsers(
             @RequestParam(value = "page", defaultValue = "1") int currentPage,
             @RequestParam(value = "size", defaultValue = "10") int pageSize,

+ 4 - 0
src/main/java/com/njuzr/eaibackend/mapper/StudentAssignmentMapper.java

@@ -1,6 +1,7 @@
 package com.njuzr.eaibackend.mapper;
 
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.njuzr.eaibackend.po.Engagement;
 import org.apache.ibatis.annotations.Mapper;
 
@@ -13,4 +14,7 @@ import org.apache.ibatis.annotations.Mapper;
 @Mapper
 public interface StudentAssignmentMapper extends BaseMapper<Engagement> {
     Engagement findEngagementByStudentIdAndAssignmentId(Long studentId, Long assignmentId);
+
+    // TODO:(柏琪)
+    Page<Engagement> findEngagementByAssignmentId(Page<Engagement> page, Long assignmentId);
 }

+ 2 - 0
src/main/java/com/njuzr/eaibackend/service/AssignmentService.java

@@ -35,6 +35,8 @@ public interface AssignmentService {
 
     EngagementVO getEngagement(Long studentId, Long assignmentId);
 
+    IPage<EngagementVO> findEngagementPage(Page<Engagement> page, Long assignmentId);
+
     EngagementDetailVO getDetailEngagement(Long studentId, Long assignmentId);
 
     void engagementSubmit(Long studentId, Long assignmentId);

+ 12 - 5
src/main/java/com/njuzr/eaibackend/service/impl/AssignmentServiceImpl.java

@@ -11,10 +11,7 @@ import com.njuzr.eaibackend.enums.AssignmentCompletionStatus;
 import com.njuzr.eaibackend.enums.AssignmentStatus;
 import com.njuzr.eaibackend.enums.Role;
 import com.njuzr.eaibackend.exception.MyException;
-import com.njuzr.eaibackend.mapper.AssignmentMapper;
-import com.njuzr.eaibackend.mapper.CourseMapper;
-import com.njuzr.eaibackend.mapper.StudentAssignmentMapper;
-import com.njuzr.eaibackend.mapper.UserMapper;
+import com.njuzr.eaibackend.mapper.*;
 import com.njuzr.eaibackend.po.*;
 import com.njuzr.eaibackend.service.AssignmentService;
 import com.njuzr.eaibackend.utils.*;
@@ -44,6 +41,7 @@ public class AssignmentServiceImpl implements AssignmentService {
 
     private final AssignmentMapper assignmentMapper;
     private final CourseMapper courseMapper;
+    private final EngagementMapper engagementMapper;
 
     private final StudentAssignmentMapper studentAssignmentMapper;
 
@@ -53,9 +51,10 @@ public class AssignmentServiceImpl implements AssignmentService {
 
     private final FileUtil fileUtil = new FileUtil();
 
-    public AssignmentServiceImpl(AssignmentMapper assignmentMapper, CourseMapper courseMapper, StudentAssignmentMapper studentAssignmentMapper, UserMapper userMapper, OssUtil ossUtil) {
+    public AssignmentServiceImpl(AssignmentMapper assignmentMapper, CourseMapper courseMapper, EngagementMapper engagementMapper, StudentAssignmentMapper studentAssignmentMapper, UserMapper userMapper, OssUtil ossUtil) {
         this.assignmentMapper = assignmentMapper;
         this.courseMapper = courseMapper;
+        this.engagementMapper = engagementMapper;
         this.studentAssignmentMapper = studentAssignmentMapper;
         this.userMapper = userMapper;
         this.ossUtil = ossUtil;
@@ -216,6 +215,14 @@ public class AssignmentServiceImpl implements AssignmentService {
         return convertToVO(engagement);
     }
 
+    @Override
+    public IPage<EngagementVO> findEngagementPage(Page<Engagement> page, Long assignmentId) {
+
+        IPage<Engagement> engagements = studentAssignmentMapper.findEngagementByAssignmentId(page, assignmentId);
+
+        return PageMapperUtil.convert(engagements, this::convertToVO);
+    }
+
 
     @Override
     public EngagementDetailVO getDetailEngagement(Long studentId, Long assignmentId) {

+ 1 - 0
src/main/java/com/njuzr/eaibackend/service/impl/CourseServiceImpl.java

@@ -78,6 +78,7 @@ public class CourseServiceImpl implements CourseService {
 
     @Override
     public IPage<CourseVO> findCoursesPage(Page<Course> page, CourseQueryDTO courseQueryDTO) {
+        log.info(courseQueryDTO.toString());
         QueryWrapper<Course> wrapper = getCourseQueryWrapper(courseQueryDTO);
 
         IPage<Course> courses = courseMapper.selectPage(page, wrapper);

+ 4 - 4
src/main/resources/application-dev.yaml

@@ -5,8 +5,8 @@ spring:
   datasource:
     driver-class-name: com.mysql.cj.jdbc.Driver
     username: root
-    password: Zr200012
-    url: jdbc:mysql://localhost:3306/EAI?useSSL=false&serverTimezone=UTC&useUnicode=true&characterEncoding=utf8
+    password: 123321123b
+    url: jdbc:mysql://localhost:3306/eai?useSSL=false&serverTimezone=UTC&useUnicode=true&characterEncoding=utf8
   data:
     mongodb:
       uri: mongodb://admin:admin@localhost:27017/eai?authSource=admin
@@ -34,8 +34,8 @@ jwt:
 aliyun:
   oss:
     endpoint: oss-cn-shanghai.aliyuncs.com
-    accessKeyId: LTAI5tKsfJJKByjVqNKCvRR3
-    accessKeySecret: fckFhhxhG234aOZfjIAxZZuFA3RCkH
+    accessKeyId: LTAI5tAbkw8rkreiJbfcY1jZ
+    accessKeySecret: 2yvtVYE1qAZEgm0ChvdMqhp0LhB5Lj
     bucketName: eai-files
 
 logging:

+ 2 - 2
src/main/resources/application-prod.yaml

@@ -6,10 +6,10 @@ spring:
     driver-class-name: com.mysql.cj.jdbc.Driver
     username: root
     password: eai123456
-    url: jdbc:mysql://47.111.23.171:3306/eai?useSSL=false&serverTimezone=UTC&useUnicode=true&characterEncoding=utf8&allowPublicKeyRetrieval=true
+    url: jdbc:mysql://8.130.126.86:3306/eai?useSSL=false&serverTimezone=UTC&useUnicode=true&characterEncoding=utf8&allowPublicKeyRetrieval=true
   data:
     mongodb:
-      uri: mongodb://root:eai123456@47.111.23.171:27017/eai?authSource=admin
+      uri: mongodb://root:eai123456@8.130.126.86:27017/eai?authSource=admin
       authentication-database: admin
   mail:
     host: smtp.163.com

+ 8 - 0
src/main/resources/mapper/StudentAssignmentMapper.xml

@@ -6,4 +6,12 @@
         FROM student_assignment
         WHERE student_id = #{studentId} AND assignment_id = #{assignmentId}
     </select>
+
+<!--  TODO:(柏琪)通过assignmentID查找  -->
+    <select id="findEngagementByAssignmentId" resultType="Engagement">
+        SELECT *
+        FROM student_assignment
+        WHERE assignment_id = #{assignmentId}
+    </select>
+
 </mapper>

+ 2 - 2
src/main/resources/mapper/UserMapper.xml

@@ -1,13 +1,13 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.njuzr.eaibackend.mapper.UserMapper">
-    <select id="selectByOfficialNumber" resultType="User">
+    <select id="selectByOfficialNumber" resultType="com.njuzr.eaibackend.po.User">
         select *
         from users
         where official_number = #{officialNumber}
     </select>
 
-    <update id="updateUser" parameterType="User">
+    <update id="updateUser" parameterType="com.njuzr.eaibackend.po.User">
         UPDATE users
         <set>
             <if test="name != null">name=#{name},</if>