haogh 8 mēneši atpakaļ
vecāks
revīzija
2f94c4c1d6

+ 9 - 0
src/main/java/com/qmth/exam/reserve/bean/student/StudentVO.java

@@ -29,4 +29,13 @@ public class StudentVO implements IModel {
     @ApiModelProperty(value = "可预约次数")
     private Integer applyNumber;
 
+    @ApiModelProperty(value = "科目代码")
+    private String courseCode;
+
+    @ApiModelProperty(value = "科目名称")
+    private String courseName;
+
+    @ApiModelProperty(value = "考生照片地址")
+    private String photoPath;
+
 }

+ 2 - 2
src/main/java/com/qmth/exam/reserve/controller/admin/StudentAdminController.java

@@ -42,9 +42,9 @@ public class StudentAdminController extends BaseController {
 
     @ApiOperation(value = "删除考生")
     @PostMapping(value = "/delete")
-    public void delete(@ApiParam("考生ID") @RequestParam Long id) {
+    public void delete(@ApiParam("考生ID") @RequestParam Long[] ids) {
         LoginUser loginUser = this.curLoginUser();
-        studentService.delete(id, loginUser.getId());
+        studentService.delete(ids, loginUser);
     }
 
     @ApiOperation(value = "修改考生可预约次数")

+ 2 - 0
src/main/java/com/qmth/exam/reserve/service/StudentCourseService.java

@@ -10,4 +10,6 @@ public interface StudentCourseService extends IService<StudentCourseEntity> {
 
     List<CourseVO> getStudentCourses(Long studentId);
 
+    void removeStudentCourses(Long studentId, String courseCode);
+
 }

+ 2 - 1
src/main/java/com/qmth/exam/reserve/service/StudentService.java

@@ -2,6 +2,7 @@ package com.qmth.exam.reserve.service;
 
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.qmth.boot.core.collection.PageResult;
+import com.qmth.exam.reserve.bean.login.LoginUser;
 import com.qmth.exam.reserve.bean.stdapply.CategoryVO;
 import com.qmth.exam.reserve.bean.student.StudentInfo;
 import com.qmth.exam.reserve.bean.student.StudentReq;
@@ -35,7 +36,7 @@ public interface StudentService extends IService<StudentEntity> {
 
     PageResult<StudentVO> pageStudent(StudentReq req);
 
-    void delete(Long studentId, Long operateId);
+    void delete(Long[] studentIds, LoginUser loginUser);
 
     void modifyApplyNumber(Long studentId, Long operateId, Integer applyNumber);
 

+ 11 - 0
src/main/java/com/qmth/exam/reserve/service/impl/StudentCourseServiceImpl.java

@@ -7,7 +7,9 @@ import com.qmth.exam.reserve.dao.StudentCourseDao;
 import com.qmth.exam.reserve.entity.StudentCourseEntity;
 import com.qmth.exam.reserve.service.StudentCourseService;
 import org.apache.commons.collections4.CollectionUtils;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 
 import java.util.ArrayList;
 import java.util.Collections;
@@ -37,4 +39,13 @@ public class StudentCourseServiceImpl extends ServiceImpl<StudentCourseDao, Stud
         return courses;
     }
 
+    @Override
+    @Transactional
+    public void removeStudentCourses(Long studentId, String courseCode) {
+        LambdaQueryWrapper<StudentCourseEntity> wrapper = new LambdaQueryWrapper<>();
+        wrapper.eq(StudentCourseEntity::getStudentId, studentId);
+        wrapper.eq(StringUtils.isNotEmpty(courseCode), StudentCourseEntity::getCourseCode, courseCode);
+        this.remove(wrapper);
+    }
+
 }

+ 57 - 9
src/main/java/com/qmth/exam/reserve/service/impl/StudentServiceImpl.java

@@ -8,18 +8,23 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.qmth.boot.core.collection.PageResult;
 import com.qmth.boot.core.exception.StatusException;
 import com.qmth.boot.core.fss.store.FileStore;
+import com.qmth.exam.reserve.bean.applytask.CurrentApplyTaskVO;
+import com.qmth.exam.reserve.bean.login.LoginUser;
 import com.qmth.exam.reserve.bean.stdapply.CategoryVO;
 import com.qmth.exam.reserve.bean.student.StudentInfo;
 import com.qmth.exam.reserve.bean.student.StudentReq;
 import com.qmth.exam.reserve.bean.student.StudentVO;
 import com.qmth.exam.reserve.bean.student.WechatBindReq;
+import com.qmth.exam.reserve.cache.impl.ApplyTaskCacheService;
 import com.qmth.exam.reserve.cache.impl.CategoryCacheService;
+import com.qmth.exam.reserve.config.SysProperty;
 import com.qmth.exam.reserve.dao.StudentDao;
 import com.qmth.exam.reserve.entity.ApplyTaskEntity;
 import com.qmth.exam.reserve.entity.StudentApplyEntity;
 import com.qmth.exam.reserve.entity.StudentEntity;
 import com.qmth.exam.reserve.enums.AsyncTaskType;
 import com.qmth.exam.reserve.enums.EventType;
+import com.qmth.exam.reserve.enums.Role;
 import com.qmth.exam.reserve.service.*;
 import com.qmth.exam.reserve.template.execute.StudentPhotoUploadService;
 import com.qmth.exam.reserve.util.FileUtil;
@@ -35,6 +40,7 @@ import org.springframework.web.multipart.MultipartFile;
 
 import java.io.File;
 import java.io.IOException;
+import java.util.Arrays;
 import java.util.List;
 import java.util.Map;
 
@@ -64,6 +70,15 @@ public class StudentServiceImpl extends ServiceImpl<StudentDao, StudentEntity> i
     @Autowired
     private StudentPhotoUploadService studentPhotoUploadService;
 
+    @Autowired
+    private ApplyTaskCacheService applyTaskCacheService;
+
+    @Autowired
+    private SysProperty sysProperty;
+
+    @Autowired
+    private StudentCourseService studentCourseService;
+
     @Override
     public StudentEntity findByStudentCode(Long applyTaskId, String studentCode) {
         if (StringUtils.isEmpty(studentCode)) {
@@ -185,24 +200,57 @@ public class StudentServiceImpl extends ServiceImpl<StudentDao, StudentEntity> i
     @Override
     public PageResult<StudentVO> pageStudent(StudentReq req) {
         if(req.getTaskId() == null) {
-            return new PageResult<>();
+            CurrentApplyTaskVO curApplyTask = applyTaskCacheService.currentApplyTask(null);
+            if(curApplyTask == null) {
+                return new PageResult<>();
+            } else {
+                req.setTaskId(curApplyTask.getTaskId());
+            }
         }
+
         IPage<StudentVO> iPage = baseMapper.pageStudent(new Page<>(req.getPageNumber(), req.getPageSize()), req);
+        List<StudentVO> recordList = iPage.getRecords();
+        for (StudentVO student : recordList) {
+            //添加图片访问前缀
+            student.setPhotoPath(sysProperty.getServer() + File.separator + student.getPhotoPath());
+        }
         return PageUtil.of(iPage);
     }
 
     @Override
-    public void delete(Long studentId, Long operateId) {
-        List<StudentApplyEntity> studentApplyList = getStudentApplyList(studentId);
-        if (CollectionUtils.isNotEmpty(studentApplyList)) {
-            log.warn("[考生删除] 删除失败,存在预约信息,student_id:{}", studentId);
-            throw new StatusException("考生存在预约信息,无法删除");
+    @Transactional
+    public void delete(Long[] studentIds, LoginUser loginUser) {
+        for(Long studentId : studentIds) {
+            List<StudentApplyEntity> studentApplyList = getStudentApplyList(studentId);
+            if (CollectionUtils.isNotEmpty(studentApplyList)) {
+                log.warn("[考生删除] 删除失败,存在预约信息,student_id:{}", studentId);
+                throw new StatusException("考生存在预约信息,无法删除");
+            }
+
+            StudentEntity studentEntity = this.getById(studentId);
+            if (studentEntity == null) {
+                log.warn("[考生删除] 考生不存在,student_id:{}", studentId);
+                throw new StatusException("考生不存在,无法删除");
+            }
+
+            //教学点管理员
+            if (loginUser.getRole().equals(Role.TEACHING)) {
+                Long studentCategoryId = studentEntity.getCategoryId();
+                Long loginUserCategoryId = loginUser.getCategoryId();
+                if (!studentCategoryId.equals(loginUserCategoryId)) {
+                    log.warn("[考生删除] student_id:{}, 所在教学点{},登录用户的教学点:{} ", studentId, studentCategoryId, loginUserCategoryId);
+                    throw new StatusException("不能删除其他教学点的考生");
+                }
+            }
+
+            //删除考生信息
+            this.removeById(studentId);
+            //删除考生科目
+            studentCourseService.removeStudentCourses(studentId, null);
         }
 
-        this.removeById(studentId);
-
         //写入日志
-        operateLogService.insertOperateLog(operateId, EventType.DELETE_STUDENT, studentId.toString());
+        operateLogService.insertOperateLog(loginUser.getId(), EventType.DELETE_STUDENT, Arrays.toString(studentIds));
     }
 
     private List<StudentApplyEntity> getStudentApplyList(Long studentId) {

+ 7 - 2
src/main/resources/mapper/StudentMapper.xml

@@ -58,12 +58,17 @@
         s.identity_number identityNumber,
         s.student_code studentCode,
         c.NAME teachingName,
-        s.apply_number applyNumber
+        s.apply_number applyNumber,
+        sc.course_name courseName,
+        sc.course_code courseCode,
+        s.photo_path photoPath
         FROM
         t_student s,
-        t_category c
+        t_category c,
+        t_student_course sc
         WHERE
         s.category_id = c.id
+        and sc.student_id=s.id
         <if test="req.taskId != null">
             and s.apply_task_id=#{req.taskId}
         </if>