|
@@ -1,32 +1,37 @@
|
|
package com.xjrsoft.module.teacher.controller;
|
|
package com.xjrsoft.module.teacher.controller;
|
|
|
|
|
|
import cn.dev33.satoken.annotation.SaCheckPermission;
|
|
import cn.dev33.satoken.annotation.SaCheckPermission;
|
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
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.exception.MyException;
|
|
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.FileZipUtil;
|
|
import com.xjrsoft.common.utils.VoToColumnUtil;
|
|
import com.xjrsoft.common.utils.VoToColumnUtil;
|
|
|
|
+import com.xjrsoft.module.system.entity.File;
|
|
import com.xjrsoft.module.system.service.IFileService;
|
|
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;
|
|
import com.xjrsoft.module.teacher.entity.XjrUser;
|
|
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.TeacherAwardDetailExcelVo;
|
|
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;
|
|
import io.swagger.annotations.ApiOperation;
|
|
import io.swagger.annotations.ApiOperation;
|
|
import lombok.AllArgsConstructor;
|
|
import lombok.AllArgsConstructor;
|
|
|
|
+import me.zhyd.oauth.log.Log;
|
|
import org.springframework.http.ResponseEntity;
|
|
import org.springframework.http.ResponseEntity;
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
@@ -40,12 +45,10 @@ import java.io.IOException;
|
|
import java.io.InputStream;
|
|
import java.io.InputStream;
|
|
import java.net.URL;
|
|
import java.net.URL;
|
|
import java.net.URLConnection;
|
|
import java.net.URLConnection;
|
|
-import java.time.LocalDateTime;
|
|
|
|
-import java.time.format.DateTimeFormatter;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
import java.util.HashMap;
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
-import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
* @title: 教师奖项
|
|
* @title: 教师奖项
|
|
@@ -107,50 +110,111 @@ public class TeacherAwardController {
|
|
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);
|
|
|
|
|
|
- List<Long> userIds = list.stream().map(TeacherAwardStatisticsPageVo::getId).collect(Collectors.toList());
|
|
|
|
- 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));
|
|
|
|
|
|
+ ByteArrayOutputStream bot = new ByteArrayOutputStream();
|
|
|
|
+ EasyExcel.write(bot, TeacherAwardStatisticsExcelVo.class).automaticMergeHead(false).excelType(ExcelTypeEnum.XLSX).sheet().doWrite(list);
|
|
|
|
|
|
- //声明一个Map,将所有文件装进去,map的key是完整的文件名
|
|
|
|
- Map<String, byte[]> byteAryMap = new HashMap<>();
|
|
|
|
|
|
+ return RT.fileStream(bot.toByteArray(), "教师获奖登记" + ExcelTypeEnum.XLSX.getValue());
|
|
|
|
+ }
|
|
|
|
|
|
- for (TeacherAwardStatisticsPageVo el : list) {
|
|
|
|
- List<TeacherAwardFileListVo> fileList = filesMap.get(el.getId());
|
|
|
|
- if(fileList == null){
|
|
|
|
- continue;
|
|
|
|
- }
|
|
|
|
- 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);
|
|
|
|
|
|
+
|
|
|
|
+ @PostMapping(value = "/detail-export-query")
|
|
|
|
+ @ApiOperation(value="教师获奖详情页")
|
|
|
|
+ @SaCheckPermission("teacheraward:detail")
|
|
|
|
+ public ResponseEntity<byte[]> detailExportQuery(@Valid @RequestBody TeacherAwardDetailPageDto dto){
|
|
|
|
+ try {
|
|
|
|
+ MPJLambdaWrapper<TeacherAward> teacherAwardMPJLambdaWrapper = new MPJLambdaWrapper<>();
|
|
|
|
+ teacherAwardMPJLambdaWrapper
|
|
|
|
+ .disableSubLogicDel()
|
|
|
|
+ .selectAs(TeacherAwardItem::getIsThesis, TeacherAwardDetailPageVo::getIsThesis)
|
|
|
|
+ .selectAs(XjrUser::getName, TeacherAwardDetailPageVo::getApplicantUserIdCn)
|
|
|
|
+ .select(TeacherAward.class,x -> VoToColumnUtil.fieldsToColumns(TeacherAwardDetailPageVo.class).contains(x.getProperty()))
|
|
|
|
+ .leftJoin(TeacherAwardItem.class, TeacherAwardItem::getId, TeacherAward::getTeacherAwardItemId)
|
|
|
|
+ .leftJoin(XjrUser.class, XjrUser::getId, TeacherAward::getApplicantUserId)
|
|
|
|
+ .eq(dto.getApplicantUserId() != null && dto.getApplicantUserId() > 0,TeacherAward::getApplicantUserId, dto.getApplicantUserId())
|
|
|
|
+ .eq(dto.getIsThesis() != null,TeacherAwardItem::getIsThesis, dto.getIsThesis())
|
|
|
|
+ .like(dto.getApplicantUserIdCn() != null && !dto.getApplicantUserIdCn().equals(""), XjrUser::getName, dto.getApplicantUserIdCn())
|
|
|
|
+ .like(dto.getWholeCompetitionName() != null && !dto.getWholeCompetitionName().equals(""),TeacherAward::getWholeCompetitionName, dto.getWholeCompetitionName())
|
|
|
|
+ .eq(TeacherAward::getStatus, 1)
|
|
|
|
+ .orderByDesc(TeacherAward::getCreateDate)
|
|
|
|
+ ;
|
|
|
|
+ List<TeacherAwardDetailPageVo> list = teacherAwardService.selectJoinList(TeacherAwardDetailPageVo.class, teacherAwardMPJLambdaWrapper);
|
|
|
|
+ List<TeacherAwardDetailExcelVo> excelList = new ArrayList<>();
|
|
|
|
+ int index = 1;
|
|
|
|
+ Map<String, byte[]> byteAryMap = new HashMap<>();
|
|
|
|
+ String folderName = "附件材料";
|
|
|
|
+ for (TeacherAwardDetailPageVo el : list) {
|
|
|
|
+ TeacherAwardDetailExcelVo rowData = BeanUtil.toBean(el, TeacherAwardDetailExcelVo.class);
|
|
|
|
+ if(el.getIsThesis() == 1){
|
|
|
|
+ rowData.setIsThesis("是");
|
|
|
|
+ }else if(el.getIsThesis() == 0){
|
|
|
|
+ rowData.setIsThesis("否");
|
|
|
|
+ }
|
|
|
|
+ List<File> fileList = fileService.list(
|
|
|
|
+ new QueryWrapper<File>().lambda()
|
|
|
|
+ .eq(File::getFolderId, el.getFileId())
|
|
|
|
+ .eq(File::getDeleteMark, DeleteMark.NODELETE.getCode())
|
|
|
|
+ );
|
|
|
|
+
|
|
|
|
+ if(fileList.isEmpty()){
|
|
|
|
+ excelList.add(rowData);
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ String fileName = "佐证材料" + index;
|
|
|
|
+ if(fileList.size() == 1){
|
|
|
|
+ try {
|
|
|
|
+ File file = fileList.get(0);
|
|
|
|
+ URL url = new URL(file.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(folderName + "\\" + fileName + file.getFileType(), byteArray);
|
|
|
|
+ in.close();
|
|
|
|
+ outputStream.close();
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ throw new RuntimeException(e);
|
|
|
|
+ }
|
|
|
|
+ }else{
|
|
|
|
+ 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(folderName + "\\" + fileName + "\\佐证材料" + (i + 1) + fileList.get(i).getFileType(), byteArray);
|
|
|
|
+ in.close();
|
|
|
|
+ outputStream.close();
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ throw new RuntimeException(e);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- 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();
|
|
|
|
- EasyExcel.write(bot, TeacherAwardStatisticsExcelVo.class).automaticMergeHead(false).excelType(ExcelTypeEnum.XLSX).sheet().doWrite(list);
|
|
|
|
- byteAryMap.put("教师获奖登记" + ExcelTypeEnum.XLSX.getValue(), bot.toByteArray());
|
|
|
|
|
|
+ rowData.setFileName(fileName);
|
|
|
|
+ excelList.add(rowData);
|
|
|
|
+ index ++;
|
|
|
|
+ }
|
|
|
|
|
|
- byte[] bytes = FileZipUtil.byteAryMap2Zip(byteAryMap);
|
|
|
|
- LocalDateTime now = LocalDateTime.now();
|
|
|
|
- String timeStr = now.format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss"));
|
|
|
|
|
|
+ ByteArrayOutputStream bot = new ByteArrayOutputStream();
|
|
|
|
+ EasyExcel.write(bot, TeacherAwardDetailExcelVo.class).automaticMergeHead(false).excelType(ExcelTypeEnum.XLSX).sheet().doWrite(excelList);
|
|
|
|
+ byteAryMap.put("教师获奖登记" + ExcelTypeEnum.XLSX.getValue(), bot.toByteArray());
|
|
|
|
|
|
- return RT.fileStream(bytes, "教师获奖登记" + timeStr + ".zip");
|
|
|
|
|
|
+ byte[] bytes = FileZipUtil.byteAryMap2Zip(byteAryMap);
|
|
|
|
+ return RT.fileStream(bytes, "detailExportQuery.zip");
|
|
|
|
+ }catch (Exception e){
|
|
|
|
+ Log.error(e.getMessage(), e);
|
|
|
|
+ throw new MyException("导出出错,请联系管理员");
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|