haogh 7 месяцев назад
Родитель
Сommit
7db3fed93f

+ 39 - 0
src/main/java/com/qmth/exam/reserve/bean/student/StudentExportVO.java

@@ -0,0 +1,39 @@
+package com.qmth.exam.reserve.bean.student;
+
+import com.qmth.boot.tools.excel.annotation.ExcelColumn;
+import com.qmth.exam.reserve.bean.IModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Getter;
+import lombok.Setter;
+
+@Getter
+@Setter
+public class StudentExportVO implements IModel {
+
+    private static final long serialVersionUID = 1L;
+
+    @ApiModelProperty(value = "考生姓名")
+    @ExcelColumn(name = "姓名", index = 0)
+    private String name;
+
+    @ApiModelProperty(value = "证件号")
+    @ExcelColumn(name = "证件号", index = 1)
+    private String identityNumber;
+
+    @ApiModelProperty(value = "学号")
+    @ExcelColumn(name = "学号", index = 2)
+    private String studentCode;
+
+    @ApiModelProperty(value = "教学点")
+    @ExcelColumn(name = "教学点", index = 3)
+    private String teachingName;
+
+    @ApiModelProperty(value = "科目名称")
+    @ExcelColumn(name = "科目", index = 4)
+    private String courseName;
+
+    @ApiModelProperty(value = "科目代码")
+    @ExcelColumn(name = "科目代码", index = 5)
+    private String courseCode;
+
+}

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

@@ -4,8 +4,11 @@ import com.qmth.boot.api.annotation.Aac;
 import com.qmth.boot.api.constant.ApiConstant;
 import com.qmth.boot.core.collection.PageResult;
 import com.qmth.boot.core.exception.StatusException;
+import com.qmth.boot.tools.excel.ExcelWriter;
+import com.qmth.boot.tools.excel.enums.ExcelType;
 import com.qmth.exam.reserve.bean.Constants;
 import com.qmth.exam.reserve.bean.login.LoginUser;
+import com.qmth.exam.reserve.bean.student.StudentExportVO;
 import com.qmth.exam.reserve.bean.student.StudentReq;
 import com.qmth.exam.reserve.bean.student.StudentVO;
 import com.qmth.exam.reserve.controller.BaseController;
@@ -14,11 +17,16 @@ import com.qmth.exam.reserve.service.StudentService;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import io.swagger.annotations.ApiParam;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
 
+import javax.servlet.http.HttpServletResponse;
 import java.io.IOException;
+import java.net.URLEncoder;
+import java.util.List;
 import java.util.Objects;
 
 @RestController
@@ -27,6 +35,8 @@ import java.util.Objects;
 @Aac(strict = false, auth = true)
 public class StudentAdminController extends BaseController {
 
+    private static final Logger log = LoggerFactory.getLogger(StudentAdminController.class);
+
     @Autowired
     private StudentService studentService;
 
@@ -88,5 +98,29 @@ public class StudentAdminController extends BaseController {
         return Constants.ASYNC_TIPS;
     }
 
+    @ApiOperation(value = "导出考生")
+    @PostMapping(value = "/export")
+    public void exportExceptionMessage(@RequestBody StudentReq req, HttpServletResponse response) {
+        LoginUser loginUser = this.curLoginUser();
+        if (loginUser.getRole().equals(Role.TEACHING)) {
+            req.setTeachingId(loginUser.getCategoryId());
+        }
+        try {
+            String fileName = URLEncoder.encode(System.currentTimeMillis() + "", "UTF-8");
+            response.setHeader("Content-Disposition", "inline; filename=" + fileName + ".xlsx");
+            response.setContentType("application/vnd.ms-excel");
+            ExcelWriter writer = ExcelWriter.create(ExcelType.XLSX);
+            List<StudentExportVO> exportList = studentService.exportPage(req);
+            if (exportList == null || exportList.isEmpty()) {
+                throw new StatusException("无考生信息");
+            }
+            writer.writeObjects("考生信息", null, StudentExportVO.class, exportList.iterator());
+            writer.output(response.getOutputStream());
+        } catch (IOException e) {
+            log.error(e.getMessage());
+        }
+
+    }
+
 
 }

+ 3 - 0
src/main/java/com/qmth/exam/reserve/dao/StudentDao.java

@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.qmth.exam.reserve.bean.stdapply.CategoryVO;
+import com.qmth.exam.reserve.bean.student.StudentExportVO;
 import com.qmth.exam.reserve.bean.student.StudentInfo;
 import com.qmth.exam.reserve.bean.student.StudentReq;
 import com.qmth.exam.reserve.bean.student.StudentVO;
@@ -23,4 +24,6 @@ public interface StudentDao extends BaseMapper<StudentEntity> {
     IPage<StudentVO> pageStudent(Page<StudentVO> page, @Param("req") StudentReq req);
 
     void updateStudentApplyNumber(@Param("studentId") Long studentId);
+
+    List<StudentExportVO> listStudent(@Param("req") StudentReq req);
 }

+ 3 - 4
src/main/java/com/qmth/exam/reserve/service/StudentService.java

@@ -4,10 +4,7 @@ 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;
-import com.qmth.exam.reserve.bean.student.StudentVO;
-import com.qmth.exam.reserve.bean.student.WechatBindReq;
+import com.qmth.exam.reserve.bean.student.*;
 import com.qmth.exam.reserve.entity.StudentEntity;
 import org.springframework.web.multipart.MultipartFile;
 
@@ -45,4 +42,6 @@ public interface StudentService extends IService<StudentEntity> {
     void updateStudentApplyNumber(Long studentId);
 
     void uploadStudentPhoto(Long operateId, MultipartFile file);
+
+    List<StudentExportVO> exportPage(StudentReq req);
 }

+ 18 - 8
src/main/java/com/qmth/exam/reserve/service/impl/StudentServiceImpl.java

@@ -13,10 +13,7 @@ import com.qmth.exam.reserve.bean.applytask.CurrentApplyTaskVO;
 import com.qmth.exam.reserve.bean.login.LoginUser;
 import com.qmth.exam.reserve.bean.org.OrgInfo;
 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.bean.student.*;
 import com.qmth.exam.reserve.cache.impl.ApplyTaskCacheService;
 import com.qmth.exam.reserve.cache.impl.CategoryCacheService;
 import com.qmth.exam.reserve.cache.impl.OrgCacheService;
@@ -47,10 +44,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;
-import java.util.StringJoiner;
+import java.util.*;
 import java.util.stream.Collectors;
 
 @Service
@@ -379,4 +373,20 @@ public class StudentServiceImpl extends ServiceImpl<StudentDao, StudentEntity> i
         this.update(null, updateWrapper);
     }
 
+    @Override
+    public List<StudentExportVO> exportPage(StudentReq req) {
+        // 获取当前任务
+        if (req.getTaskId() == null) {
+            OrgInfo org = orgCacheService.currentOrg();
+            CurrentApplyTaskVO curApplyTask = applyTaskCacheService.currentApplyTask(org.getOrgId());
+            if (curApplyTask == null) {
+                return Collections.emptyList();
+            } else {
+                req.setTaskId(curApplyTask.getTaskId());
+            }
+        }
+        //根据条件获取考生列表
+        return baseMapper.listStudent(req);
+    }
+
 }

+ 33 - 0
src/main/resources/mapper/StudentMapper.xml

@@ -95,4 +95,37 @@
         order by s.update_time desc
     </select>
 
+    <select id="listStudent" resultType="com.qmth.exam.reserve.bean.student.StudentExportVO"  parameterType="com.qmth.exam.reserve.bean.student.StudentReq">
+        SELECT
+        s.NAME,
+        s.identity_number identityNumber,
+        s.student_code studentCode,
+        c.NAME teachingName,
+        sc.course_name courseName,
+        sc.course_code courseCode
+        FROM
+        t_student s,
+        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>
+        <if test="req.teachingId != null ">
+            and s.category_id=#{req.teachingId}
+        </if>
+        <if test="req.name != null and req.name !=''">
+            and s.name like concat('%', #{req.name}, '%')
+        </if>
+        <if test="req.identityNumber != null and req.identityNumber !=''">
+            and s.identity_number like concat('%', #{req.identityNumber}, '%')
+        </if>
+        <if test="req.studentCode != null and req.studentCode !=''">
+            and s.student_code like concat('%', #{req.studentCode}, '%')
+        </if>
+        order by s.update_time desc
+    </select>
+
 </mapper>