Browse Source

教师获奖统计导出

dzx 1 week ago
parent
commit
7bd1725e9d

+ 53 - 9
src/main/java/com/xjrsoft/module/teacher/controller/TeacherAwardController.java

@@ -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");
     }
     }
 }
 }

+ 22 - 0
src/main/java/com/xjrsoft/module/teacher/dto/TeacherAwardFileListDto.java

@@ -0,0 +1,22 @@
+package com.xjrsoft.module.teacher.dto;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+import java.util.List;
+
+
+/**
+* @title: 教师奖项分页查询入参
+* @Author dzx
+* @Date: 2024-06-04
+* @Version 1.0
+*/
+@Data
+@EqualsAndHashCode(callSuper = false)
+public class TeacherAwardFileListDto {
+
+    @ApiModelProperty("申请人ids")
+    private List<Long> applicantUserIds;
+}

+ 4 - 0
src/main/java/com/xjrsoft/module/teacher/mapper/TeacherAwardItemMapper.java

@@ -2,8 +2,10 @@ package com.xjrsoft.module.teacher.mapper;
 
 
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.github.yulichang.base.MPJBaseMapper;
 import com.github.yulichang.base.MPJBaseMapper;
+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.TeacherAwardItem;
 import com.xjrsoft.module.teacher.entity.TeacherAwardItem;
+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 org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Mapper;
@@ -23,4 +25,6 @@ public interface TeacherAwardItemMapper extends MPJBaseMapper<TeacherAwardItem>
     Page<TeacherAwardStatisticsPageVo> getStatisticsPage(Page<TeacherAwardStatisticsPageVo> page, @Param("dto") TeacherAwardStatisticsPageDto dto);
     Page<TeacherAwardStatisticsPageVo> getStatisticsPage(Page<TeacherAwardStatisticsPageVo> page, @Param("dto") TeacherAwardStatisticsPageDto dto);
 
 
     List<TeacherAwardStatisticsPageVo> getStatisticsList(@Param("dto") TeacherAwardStatisticsPageDto dto);
     List<TeacherAwardStatisticsPageVo> getStatisticsList(@Param("dto") TeacherAwardStatisticsPageDto dto);
+
+    List<TeacherAwardFileListVo> getAwardFileList(@Param("dto") TeacherAwardFileListDto dto);
 }
 }

+ 7 - 0
src/main/java/com/xjrsoft/module/teacher/service/ITeacherAwardService.java

@@ -1,7 +1,12 @@
 package com.xjrsoft.module.teacher.service;
 package com.xjrsoft.module.teacher.service;
 
 
 import com.github.yulichang.base.MPJBaseService;
 import com.github.yulichang.base.MPJBaseService;
+import com.xjrsoft.module.teacher.dto.TeacherAwardFileListDto;
 import com.xjrsoft.module.teacher.entity.TeacherAward;
 import com.xjrsoft.module.teacher.entity.TeacherAward;
+import com.xjrsoft.module.teacher.vo.TeacherAwardFileListVo;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
 
 
 /**
 /**
 * @title: 教师获奖登记
 * @title: 教师获奖登记
@@ -18,4 +23,6 @@ public interface ITeacherAwardService extends MPJBaseService<TeacherAward> {
      * @return
      * @return
      */
      */
     Boolean dataHandleAddTeacherAwardNode(Long dataId);
     Boolean dataHandleAddTeacherAwardNode(Long dataId);
+
+    List<TeacherAwardFileListVo> getAwardFileList(TeacherAwardFileListDto dto);
 }
 }

+ 7 - 0
src/main/java/com/xjrsoft/module/teacher/service/impl/TeacherAwardServiceImpl.java

@@ -4,11 +4,13 @@ import cn.hutool.core.bean.BeanUtil;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.github.yulichang.base.MPJBaseServiceImpl;
 import com.github.yulichang.base.MPJBaseServiceImpl;
 import com.xjrsoft.common.utils.VoToColumnUtil;
 import com.xjrsoft.common.utils.VoToColumnUtil;
+import com.xjrsoft.module.teacher.dto.TeacherAwardFileListDto;
 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.mapper.TeacherAwardItemMapper;
 import com.xjrsoft.module.teacher.mapper.TeacherAwardItemMapper;
 import com.xjrsoft.module.teacher.mapper.TeacherAwardMapper;
 import com.xjrsoft.module.teacher.mapper.TeacherAwardMapper;
 import com.xjrsoft.module.teacher.service.ITeacherAwardService;
 import com.xjrsoft.module.teacher.service.ITeacherAwardService;
+import com.xjrsoft.module.teacher.vo.TeacherAwardFileListVo;
 import com.xjrsoft.module.teacher.vo.TeacherAwardItemPageVo;
 import com.xjrsoft.module.teacher.vo.TeacherAwardItemPageVo;
 import com.xjrsoft.module.teacher.vo.TeacherAwardItemVo;
 import com.xjrsoft.module.teacher.vo.TeacherAwardItemVo;
 import lombok.AllArgsConstructor;
 import lombok.AllArgsConstructor;
@@ -68,6 +70,11 @@ public class TeacherAwardServiceImpl extends MPJBaseServiceImpl<TeacherAwardMapp
         return this.updateById(updateTeacherAward);
         return this.updateById(updateTeacherAward);
     }
     }
 
 
+    @Override
+    public List<TeacherAwardFileListVo> getAwardFileList(TeacherAwardFileListDto dto) {
+        return teacherAwardItemMapper.getAwardFileList(dto);
+    }
+
     private List<TeacherAwardItemVo> findAncestors(List<TeacherAwardItemVo> itemVos, Long targetId) {
     private List<TeacherAwardItemVo> findAncestors(List<TeacherAwardItemVo> itemVos, Long targetId) {
         List<TeacherAwardItemVo> ancestors = new ArrayList<>();
         List<TeacherAwardItemVo> ancestors = new ArrayList<>();
         Map<Long, TeacherAwardItemVo> itemMap = itemVos.stream()
         Map<Long, TeacherAwardItemVo> itemMap = itemVos.stream()

+ 28 - 0
src/main/java/com/xjrsoft/module/teacher/vo/TeacherAwardFileListVo.java

@@ -0,0 +1,28 @@
+package com.xjrsoft.module.teacher.vo;
+
+import com.alibaba.excel.annotation.ExcelProperty;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+/**
+* @title: 教师奖项分页列表出参
+* @Author dzx
+* @Date: 2024-06-04
+* @Version 1.0
+*/
+@Data
+public class TeacherAwardFileListVo {
+
+    @ApiModelProperty("用户id")
+    private Long applicantUserId;
+
+    @ApiModelProperty("文件名字")
+    private String fileName;
+
+    @ApiModelProperty("文件类型")
+    private String fileType;
+
+    @ApiModelProperty("文件路径")
+    private String fileUrl;
+
+}

+ 8 - 2
src/main/resources/mapper/teacher/TeacherAwardItemMapper.xml

@@ -54,10 +54,16 @@
         </if>
         </if>
     </select>
     </select>
 
 
-    <select id="getAwardFileList" parameterType="com.xjrsoft.module.teacher.dto.TeacherAwardStatisticsPageDto" resultType="com.xjrsoft.module.teacher.vo.TeacherAwardStatisticsPageVo">
-        SELECT t1.applicant_user_id,t3.file_name,t3.file_suffiex,t3.file_url FROM teacher_award t1
+    <select id="getAwardFileList" parameterType="com.xjrsoft.module.teacher.dto.TeacherAwardFileListDto" resultType="com.xjrsoft.module.teacher.vo.TeacherAwardFileListVo">
+        SELECT t1.applicant_user_id,t3.file_name,t3.filt_type,t3.file_url FROM teacher_award t1
         INNER JOIN xjr_workflow_form_relation t2 ON t1.id = t2.form_key_value
         INNER JOIN xjr_workflow_form_relation t2 ON t1.id = t2.form_key_value
         INNER JOIN xjr_file t3 ON t1.file_id = t3.folder_id
         INNER JOIN xjr_file t3 ON t1.file_id = t3.folder_id
         WHERE t1.delete_mark = 0 AND t2.current_state = 'COMPLETED'
         WHERE t1.delete_mark = 0 AND t2.current_state = 'COMPLETED'
+        <if test="dto.applicantUserIds != null and dto.applicantUserIds.size() > 0">
+            and t1.applicant_user_id in
+            <foreach item="userId" index="index" collection="dto.applicantUserIds" open="(" separator="," close=")">
+                #{userId}
+            </foreach>
+        </if>
     </select>
     </select>
 </mapper>
 </mapper>