haogh 8 månader sedan
förälder
incheckning
5ee635f528

+ 28 - 10
src/main/java/com/qmth/exam/reserve/bean/stdapply/StudentApplyExport.java

@@ -1,12 +1,13 @@
 package com.qmth.exam.reserve.bean.stdapply;
 
-import com.qmth.boot.tools.excel.annotation.ExcelColumn;
+import com.alibaba.excel.annotation.ExcelProperty;
+import com.alibaba.excel.annotation.write.style.ColumnWidth;
+import com.alibaba.excel.annotation.write.style.HeadFontStyle;
+import com.alibaba.excel.annotation.write.style.HeadStyle;
 import com.qmth.exam.reserve.bean.IModel;
 import lombok.Getter;
 import lombok.Setter;
 
-import java.io.Serializable;
-
 /**
  * @Description 已预约考生的预约详情
  * @Author haoguanghui
@@ -14,21 +15,38 @@ import java.io.Serializable;
  */
 @Getter
 @Setter
+@ColumnWidth(value = 30)
+@HeadStyle(fillForegroundColor = 44)
+@HeadFontStyle(color = 1)
 public class StudentApplyExport implements IModel {
 
-    @ExcelColumn(name = "学号", index = 0)
-    private String studentCode;
+    private static final long serialVersionUID = 6970573750958765854L;
 
-    @ExcelColumn(name = "考生姓名", index = 1)
+    @ExcelProperty(value = "考生姓名")
     private String studentName;
 
-    @ExcelColumn(name = "证件号码", index = 2)
+    @ExcelProperty(value = "证件号码")
     private String identityNumber;
 
-    @ExcelColumn(name = "预约的考点", index = 3)
-    private String siteName;
+    @ExcelProperty(value = "学号")
+    private String studentCode;
+
+    @ExcelProperty(value = "教学点代码")
+    private String teachingCode;
+
+    @ExcelProperty(value = "教学点名称")
+    private String teachingName;
+
+    @ExcelProperty(value = "所预约教学点")
+    private String applyTeachingName;
+
+    @ExcelProperty(value = "考点代码")
+    private String examSiteCode;
+
+    @ExcelProperty(value = "预约的考点")
+    private String examSiteName;
 
-    @ExcelColumn(name = "预约的时段", index = 4)
+    @ExcelProperty(value = "预约的时段")
     private String timePeriod;
 
 }

+ 12 - 19
src/main/java/com/qmth/exam/reserve/controller/admin/StudentApplyController.java

@@ -210,28 +210,21 @@ public class StudentApplyController extends BaseController {
     }
 
     @ApiOperation(value = "导出考生预约的详情信息")
-    @PostMapping(value = "/export/std/detail")
-    public void exportHaveApplyStudent(@ApiParam("教学点ID") @RequestParam Long teachingId, HttpServletResponse response) {
-        try {
-            String fileName = URLEncoder.encode("考生预约详情信息表", "UTF-8");
-            response.setHeader("Content-Disposition", "inline; filename=" + fileName + ".xlsx");
-            response.setContentType("application/vnd.ms-excel");
-            ExcelWriter writer = ExcelWriter.create(ExcelType.XLSX);
-            List<StudentApplyExport> applyList = studentApplyService.listStudentApplyExport(teachingId);
-            if(CollectionUtils.isEmpty(applyList)) {
-                throw new StatusException("教学点下还没有考生预约");
-            }
-            writer.writeObjects("考生预约详情", null, StudentApplyExport.class, applyList.iterator());
-            writer.output(response.getOutputStream());
-        } catch (IOException e) {
-            throw new StatusException(e.getMessage());
+    @PostMapping(value = "/export/std/apply")
+    public String exportStudentApplyDetail(@ApiParam("教学点ID") @RequestParam(required = false) Long teachingId) {
+        LoginUser user = curLoginUser();
+        if (Role.TEACHING.equals(user.getRole())) {
+            teachingId = user.getCategoryId();
         }
+        studentApplyService.exportStudentApplyDetail(teachingId, user.getId());
+        return Constants.ASYNC_TIPS;
     }
 
-    @ApiOperation(value = "导出未预约的考生")
-    @GetMapping(value = "/export/std/noApply")
-    public String exportNoApplyStudent(@ApiParam("教学点ID") @RequestParam Long teachingId, HttpServletResponse response) {
-       /* try {
+    @ApiOperation(value = "导出未预约的考生-异步执行")
+    @PostMapping(value = "/export/std/noApply")
+    public String exportNoApplyStudent(@ApiParam("教学点ID") @RequestParam Long teachingId) {
+       /*  同步执行
+       try {
             String fileName = URLEncoder.encode("未完成预约考生信息表", "UTF-8");
             response.setHeader("Content-Disposition", "inline; filename=" + fileName + ".xlsx");
             response.setContentType("application/vnd.ms-excel");

+ 2 - 1
src/main/java/com/qmth/exam/reserve/dao/StudentApplyDao.java

@@ -8,7 +8,6 @@ import com.qmth.exam.reserve.bean.apply.TicketInfo;
 import com.qmth.exam.reserve.bean.stdapply.*;
 import com.qmth.exam.reserve.entity.StudentApplyEntity;
 import org.apache.ibatis.annotations.Param;
-import org.bouncycastle.its.asn1.IValue;
 
 import java.util.List;
 
@@ -41,4 +40,6 @@ public interface StudentApplyDao extends BaseMapper<StudentApplyEntity> {
     List<StudentApplyExport> listStudentApplyExport(@Param("teachingId") Long teachingId, @Param("taskId") Long taskId);
 
     List<StudentExport> listStudentNoApply(@Param("teachingId") Long teachingId,@Param("taskId") Long taskId, String teachingName);
+
+    List<StudentApplyExport> listStudentApplyDetail(@Param("teachingId") Long teachingId, @Param("taskId") Long taskId);
 }

+ 3 - 1
src/main/java/com/qmth/exam/reserve/service/StudentApplyService.java

@@ -31,9 +31,11 @@ public interface StudentApplyService extends IService<StudentApplyEntity> {
 
     List<String[]> listExamSiteAvailable(List<CategoryVO> examSiteList);
 
-    List<StudentApplyExport> listStudentApplyExport(Long teachingId);
+    List<StudentApplyExport> listStudentApplyDetail(Long teachingId);
 
     List<StudentExport> listStudentNoApply(Long teachingId);
 
     void exportNoApplyStudent(Long teachingId, Long id);
+
+    void exportStudentApplyDetail(Long teachingId, Long operateId);
 }

+ 26 - 2
src/main/java/com/qmth/exam/reserve/service/impl/StudentApplyServiceImpl.java

@@ -28,6 +28,7 @@ import com.qmth.exam.reserve.enums.CategoryLevel;
 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.StudentApplyDetailExportService;
 import com.qmth.exam.reserve.template.execute.StudentApplyNoFinishExportService;
 import com.qmth.exam.reserve.util.DateUtil;
 import com.qmth.exam.reserve.util.JsonHelper;
@@ -110,6 +111,11 @@ public class StudentApplyServiceImpl extends ServiceImpl<StudentApplyDao, Studen
     @Autowired
     private StudentApplyNoFinishExportService studentApplyNoFinishExportService;
 
+    @Autowired
+    private ApplyTaskCacheService applyTaskCacheService;
+
+    @Autowired
+    private StudentApplyDetailExportService studentApplyDetailExportService;
 
     @Override
     public PageResult<StudentApplyVO> page(StudentApplyReq req) {
@@ -908,8 +914,12 @@ public class StudentApplyServiceImpl extends ServiceImpl<StudentApplyDao, Studen
     }
 
     @Override
-    public List<StudentApplyExport> listStudentApplyExport(Long teachingId) {
-        return Collections.emptyList();
+    public List<StudentApplyExport> listStudentApplyDetail(Long teachingId) {
+        CurrentApplyTaskVO curApplyTask = applyTaskCacheService.currentApplyTask(null);
+        if (curApplyTask == null) {
+            return Collections.emptyList();
+        }
+        return baseMapper.listStudentApplyDetail(teachingId, curApplyTask.getTaskId());
     }
 
     @Override
@@ -931,4 +941,18 @@ public class StudentApplyServiceImpl extends ServiceImpl<StudentApplyDao, Studen
         }
     }
 
+    @Override
+    public void exportStudentApplyDetail(Long teachingId, Long operateId) {
+        //写入异步任务
+        Map<String, Object> taskMap = asyncTaskService.saveAsyncTask(AsyncTaskType.STUDENT_APPLY_EXPORT,
+                operateId);
+        taskMap.computeIfAbsent("teachingId", v -> teachingId);
+        taskMap.computeIfAbsent("operateId", v -> operateId);
+        try {
+            studentApplyDetailExportService.exportTask(taskMap);
+        } catch (Exception e) {
+            throw new StatusException(e.getMessage());
+        }
+    }
+
 }

+ 110 - 0
src/main/java/com/qmth/exam/reserve/template/execute/StudentApplyDetailExportService.java

@@ -0,0 +1,110 @@
+package com.qmth.exam.reserve.template.execute;
+
+import com.alibaba.excel.EasyExcel;
+import com.qmth.boot.tools.uuid.FastUUID;
+import com.qmth.exam.reserve.bean.Constants;
+import com.qmth.exam.reserve.bean.stdapply.StudentApplyExport;
+import com.qmth.exam.reserve.entity.AsyncTaskEntity;
+import com.qmth.exam.reserve.enums.AsyncTaskResult;
+import com.qmth.exam.reserve.enums.AsyncTaskStatus;
+import com.qmth.exam.reserve.enums.AsyncTaskType;
+import com.qmth.exam.reserve.enums.FileUploadType;
+import com.qmth.exam.reserve.service.AsyncTaskService;
+import com.qmth.exam.reserve.service.FileUploadService;
+import com.qmth.exam.reserve.service.StudentApplyService;
+import com.qmth.exam.reserve.template.export.AsyncExportTaskTemplate;
+import com.qmth.exam.reserve.util.DateUtil;
+import com.qmth.exam.reserve.util.FileUtil;
+import org.apache.commons.collections4.CollectionUtils;
+import org.apache.commons.lang3.time.DateFormatUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.io.File;
+import java.io.IOException;
+import java.text.MessageFormat;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+import java.util.StringJoiner;
+
+/**
+ * @Description 考生预约详情导出异步执行类
+ */
+@Service
+public class StudentApplyDetailExportService extends AsyncExportTaskTemplate {
+
+    private final static Logger log = LoggerFactory.getLogger(StudentApplyDetailExportService.class);
+
+    public static final String OBJ_TITLE = "考生预约详情";
+
+    @Autowired
+    private AsyncTaskService asyncTaskService;
+
+    @Autowired
+    private StudentApplyService studentApplyService;
+
+    @Autowired
+    private FileUploadService fileUploadService;
+
+    @Override
+    public void exportTask(Map<String, Object> map) {
+        AsyncTaskEntity task = (AsyncTaskEntity) map.get(Constants.ASYNC_TASK);
+        StringJoiner summary = new StringJoiner("\n").add(
+                MessageFormat.format("{0}{1}{2}", DateFormatUtils.format(new Date(), DateUtil.LongDateString), BEGIN_TITLE, OBJ_TITLE));
+        task.setStatus(AsyncTaskStatus.RUNNING);
+        task.setSummary(summary.toString());
+        asyncTaskService.updateById(task);
+
+        try {
+            Long teachingId = null;
+            if (map.get("teachingId") != null) {
+                teachingId = Long.parseLong(map.get("teachingId").toString());
+            }
+            List<StudentApplyExport> studentApplyDetailList = studentApplyService.listStudentApplyDetail(teachingId);
+            String url = createExportFile(studentApplyDetailList);
+
+            //设置导出的条数
+            summary.add(MessageFormat.format("{0}{1}{2}{3}", DateFormatUtils.format(new Date(), DateUtil.LongDateString), FINISH_TITLE,
+                    !CollectionUtils.isEmpty(studentApplyDetailList) ? studentApplyDetailList.size() : 0, FINISH_SIZE));
+
+            //更新异步任务状态
+            task.setSummary(summary.toString());
+            task.setExportFilePath(url);
+            task.setImportFileName(AsyncTaskType.STUDENT_APPLY_EXPORT.getTitle());
+            task.setResult(AsyncTaskResult.SUCCESS);
+        } catch (Exception e) {
+            log.error(e.getMessage(), e);
+            task.setResult(AsyncTaskResult.ERROR);
+            summary.add(MessageFormat.format("{0}{1}{2}{3}", DateFormatUtils.format(new Date(), DateUtil.LongDateString),
+                    EXCEPTION_CREATE_TXT_TITLE, EXCEPTION_DATA, e.getMessage()));
+            task.setSummary(summary.toString());
+        } finally {
+            task.setStatus(AsyncTaskStatus.FINISH);
+            asyncTaskService.updateById(task);
+        }
+
+    }
+
+    private String createExportFile(List<StudentApplyExport> studentExportList) throws IOException {
+        File fileTemp = null;
+        try {
+            fileTemp = FileUtil.getFileTemp(Constants.XLSX_PREFIX);
+            EasyExcel.write(fileTemp, StudentApplyExport.class).sheet("考生预约详情").doWrite(studentExportList);
+            String fileName = FastUUID.get();
+            StringJoiner stringJoiner = FileUtil.getDirName(FileUploadType.UPLOAD, true).add(fileName).add(Constants.XLSX_PREFIX);
+            String path = stringJoiner.toString().replaceAll("\\\\", "/");
+            fileUploadService.uploadFile(path, fileTemp);
+            return path;
+        } finally {
+            if (fileTemp != null) {
+                boolean deleted = fileTemp.delete();
+                if (!deleted) {
+                    log.warn("[考生预约详情导出] 临时文件删除失败,tempFileName:{}", fileTemp.getAbsolutePath());
+                }
+            }
+        }
+    }
+}

+ 35 - 0
src/main/resources/mapper/StudentApplyMapper.xml

@@ -237,5 +237,40 @@
           AND stu.apply_number - ifNUll( rr.nums, 0 ) > 0
         ORDER BY stu.student_code
     </select>
+    <select id="listStudentApplyDetail" resultType="com.qmth.exam.reserve.bean.stdapply.StudentApplyExport" parameterType="java.lang.Long">
+        SELECT
+            s.NAME studentName,
+            s.identity_number identityNumber,
+            s.student_code studentCode,
+            c.CODE teachingCode,
+            c.NAME teachingName,
+            ct.NAME applyTeachingName,
+            es.CODE examSiteCode,
+            es.NAME examSiteName,
+            concat(
+                    date_format( FROM_UNIXTIME( SUBSTR( tp.start_time, 1, 10 )), '%Y-%m-%d %H:%i' ),
+                    date_format( FROM_UNIXTIME( SUBSTR( tp.end_time, 1, 10 )), '-%H:%i' )
+            ) timePeriod
+        FROM
+            t_student s,
+            t_student_apply sa,
+            t_category c,
+            t_exam_site es,
+            t_category ct,
+            t_time_period tp
+        WHERE
+            s.id = sa.student_id
+          AND s.category_id = c.id
+          AND sa.exam_site_id = es.id
+          AND es.category_id = ct.id
+          AND tp.id = sa.time_period_id
+          AND sa.cancel = 0
+          AND s.apply_task_id = #{taskId}
+          <if test="teachingId != null">
+              AND s.category_id= #{teachingId}
+          </if>
+        ORDER BY
+            tp.start_time
+    </select>
 
 </mapper>