|
@@ -3,16 +3,17 @@ package com.xjrsoft.module.teacher.controller;
|
|
import cn.dev33.satoken.annotation.SaCheckPermission;
|
|
import cn.dev33.satoken.annotation.SaCheckPermission;
|
|
import com.alibaba.excel.EasyExcel;
|
|
import com.alibaba.excel.EasyExcel;
|
|
import com.alibaba.excel.support.ExcelTypeEnum;
|
|
import com.alibaba.excel.support.ExcelTypeEnum;
|
|
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
|
import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
|
-import com.xjrsoft.common.enums.DeleteMark;
|
|
|
|
import com.xjrsoft.common.model.result.RT;
|
|
import com.xjrsoft.common.model.result.RT;
|
|
import com.xjrsoft.common.page.ConventPage;
|
|
import com.xjrsoft.common.page.ConventPage;
|
|
import com.xjrsoft.common.page.PageOutput;
|
|
import com.xjrsoft.common.page.PageOutput;
|
|
|
|
+import com.xjrsoft.common.utils.FileZipUtil;
|
|
import com.xjrsoft.common.utils.VoToColumnUtil;
|
|
import com.xjrsoft.common.utils.VoToColumnUtil;
|
|
|
|
+import com.xjrsoft.module.system.service.IFileService;
|
|
import com.xjrsoft.module.teacher.dto.TeacherAwardDetailPageDto;
|
|
import com.xjrsoft.module.teacher.dto.TeacherAwardDetailPageDto;
|
|
|
|
+import com.xjrsoft.module.teacher.dto.TeacherAwardFileListDto;
|
|
import com.xjrsoft.module.teacher.dto.TeacherAwardStatisticsPageDto;
|
|
import com.xjrsoft.module.teacher.dto.TeacherAwardStatisticsPageDto;
|
|
import com.xjrsoft.module.teacher.entity.TeacherAward;
|
|
import com.xjrsoft.module.teacher.entity.TeacherAward;
|
|
import com.xjrsoft.module.teacher.entity.TeacherAwardItem;
|
|
import com.xjrsoft.module.teacher.entity.TeacherAwardItem;
|
|
@@ -20,6 +21,7 @@ import com.xjrsoft.module.teacher.entity.XjrUser;
|
|
import com.xjrsoft.module.teacher.service.ITeacherAwardItemService;
|
|
import com.xjrsoft.module.teacher.service.ITeacherAwardItemService;
|
|
import com.xjrsoft.module.teacher.service.ITeacherAwardService;
|
|
import com.xjrsoft.module.teacher.service.ITeacherAwardService;
|
|
import com.xjrsoft.module.teacher.vo.TeacherAwardDetailPageVo;
|
|
import com.xjrsoft.module.teacher.vo.TeacherAwardDetailPageVo;
|
|
|
|
+import com.xjrsoft.module.teacher.vo.TeacherAwardFileListVo;
|
|
import com.xjrsoft.module.teacher.vo.TeacherAwardStatisticsExcelVo;
|
|
import com.xjrsoft.module.teacher.vo.TeacherAwardStatisticsExcelVo;
|
|
import com.xjrsoft.module.teacher.vo.TeacherAwardStatisticsPageVo;
|
|
import com.xjrsoft.module.teacher.vo.TeacherAwardStatisticsPageVo;
|
|
import io.swagger.annotations.Api;
|
|
import io.swagger.annotations.Api;
|
|
@@ -34,7 +36,15 @@ import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
import javax.validation.Valid;
|
|
import javax.validation.Valid;
|
|
import java.io.ByteArrayOutputStream;
|
|
import java.io.ByteArrayOutputStream;
|
|
|
|
+import java.io.IOException;
|
|
|
|
+import java.io.InputStream;
|
|
|
|
+import java.net.URL;
|
|
|
|
+import java.net.URLConnection;
|
|
|
|
+import java.time.LocalDateTime;
|
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
|
+import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
+import java.util.Map;
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -54,6 +64,8 @@ public class TeacherAwardController {
|
|
|
|
|
|
private final ITeacherAwardService teacherAwardService;
|
|
private final ITeacherAwardService teacherAwardService;
|
|
|
|
|
|
|
|
+ private final IFileService fileService;
|
|
|
|
+
|
|
@GetMapping(value = "/statistics-page")
|
|
@GetMapping(value = "/statistics-page")
|
|
@ApiOperation(value="教师获奖统计")
|
|
@ApiOperation(value="教师获奖统计")
|
|
@SaCheckPermission("teacheraward:detail")
|
|
@SaCheckPermission("teacheraward:detail")
|
|
@@ -94,19 +106,51 @@ public class TeacherAwardController {
|
|
@SaCheckPermission("teacheraward:detail")
|
|
@SaCheckPermission("teacheraward:detail")
|
|
public ResponseEntity<byte[]> exportQuery(@Valid @RequestBody TeacherAwardStatisticsPageDto dto){
|
|
public ResponseEntity<byte[]> exportQuery(@Valid @RequestBody TeacherAwardStatisticsPageDto dto){
|
|
List<TeacherAwardStatisticsPageVo> list = teacherAwardItemService.getStatisticsList(dto);
|
|
List<TeacherAwardStatisticsPageVo> list = teacherAwardItemService.getStatisticsList(dto);
|
|
|
|
+ Map<Long, String> userMap = list.stream().collect(Collectors.toMap(TeacherAwardStatisticsPageVo::getId, TeacherAwardStatisticsPageVo::getName));
|
|
|
|
+
|
|
|
|
|
|
List<Long> userIds = list.stream().map(TeacherAwardStatisticsPageVo::getId).collect(Collectors.toList());
|
|
List<Long> userIds = list.stream().map(TeacherAwardStatisticsPageVo::getId).collect(Collectors.toList());
|
|
- List<TeacherAward> awardList = teacherAwardService.list(
|
|
|
|
- new QueryWrapper<TeacherAward>().lambda()
|
|
|
|
- .eq(TeacherAward::getDeleteMark, DeleteMark.NODELETE.getCode())
|
|
|
|
- .in(TeacherAward::getApplicantUserId, userIds)
|
|
|
|
- .orderByAsc(TeacherAward::getCreateDate)
|
|
|
|
- );
|
|
|
|
|
|
+ TeacherAwardFileListDto listDto = new TeacherAwardFileListDto();
|
|
|
|
+ listDto.setApplicantUserIds(userIds);
|
|
|
|
+ List<TeacherAwardFileListVo> awardList = teacherAwardService.getAwardFileList(listDto);
|
|
|
|
+ Map<Long, List<TeacherAwardFileListVo>> filesMap = awardList.stream().collect(Collectors.groupingBy(TeacherAwardFileListVo::getApplicantUserId));
|
|
|
|
+
|
|
|
|
+ //声明一个Map,将所有文件装进去,map的key是完整的文件名
|
|
|
|
+ Map<String, byte[]> byteAryMap = new HashMap<>();
|
|
|
|
+
|
|
|
|
+ for (TeacherAwardStatisticsPageVo el : list) {
|
|
|
|
+ List<TeacherAwardFileListVo> fileList = filesMap.get(el.getId());
|
|
|
|
+
|
|
|
|
+ for (int i = 0; i < fileList.size(); i++) {
|
|
|
|
+ try {
|
|
|
|
+ URL url = new URL(fileList.get(i).getFileUrl());
|
|
|
|
+ URLConnection conn = url.openConnection();
|
|
|
|
+ InputStream in = conn.getInputStream();
|
|
|
|
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
|
|
|
+ byte[] buffer = new byte[1024];
|
|
|
|
+ int bytesRead;
|
|
|
|
+ while ((bytesRead = in.read(buffer)) != -1) {
|
|
|
|
+ outputStream.write(buffer, 0, bytesRead);
|
|
|
|
+ }
|
|
|
|
+ byte[] byteArray = outputStream.toByteArray();
|
|
|
|
+ byteAryMap.put(el.getName() + "\\佐证材料" + (i + 1) + fileList.get(i).getFileType(), byteArray);
|
|
|
|
+ in.close();
|
|
|
|
+ outputStream.close();
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ throw new RuntimeException(e);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
ByteArrayOutputStream bot = new ByteArrayOutputStream();
|
|
ByteArrayOutputStream bot = new ByteArrayOutputStream();
|
|
EasyExcel.write(bot, TeacherAwardStatisticsExcelVo.class).automaticMergeHead(false).excelType(ExcelTypeEnum.XLSX).sheet().doWrite(list);
|
|
EasyExcel.write(bot, TeacherAwardStatisticsExcelVo.class).automaticMergeHead(false).excelType(ExcelTypeEnum.XLSX).sheet().doWrite(list);
|
|
|
|
+ byteAryMap.put("教师获奖登记" + ExcelTypeEnum.XLSX.getValue(), bot.toByteArray());
|
|
|
|
+
|
|
|
|
+ byte[] bytes = FileZipUtil.byteAryMap2Zip(byteAryMap);
|
|
|
|
+ LocalDateTime now = LocalDateTime.now();
|
|
|
|
+ String timeStr = now.format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss"));
|
|
|
|
|
|
- return RT.fileStream(bot.toByteArray(), "TeacherAward" + ExcelTypeEnum.XLSX.getValue());
|
|
|
|
|
|
+ return RT.fileStream(bytes, "教师获奖登记" + timeStr + ".zip");
|
|
}
|
|
}
|
|
}
|
|
}
|