Prechádzať zdrojové kódy

1、材料缴交下载文件和打包下载
2、数据看板bug提交

dzx 2 mesiacov pred
rodič
commit
1435fbb15b

+ 54 - 0
src/main/java/com/xjrsoft/module/databoard/controller/DataboardController.java

@@ -19,6 +19,7 @@ import com.xjrsoft.module.databoard.vo.HealthStatisticsVo;
 import com.xjrsoft.module.databoard.vo.MeetingStatisticsVo;
 import com.xjrsoft.module.databoard.vo.PersonStatisticsVo;
 import com.xjrsoft.module.databoard.vo.ProcessStatisticsVo;
+import com.xjrsoft.module.databoard.vo.ReimbursementStatisticsVo;
 import com.xjrsoft.module.databoard.vo.VisitorStatisticsVo;
 import com.xjrsoft.module.outint.entity.VisitorOutInRecord;
 import com.xjrsoft.module.outint.service.IVisitorOutInRecordService;
@@ -149,6 +150,9 @@ public class DataboardController {
         if(startTime != null && endTime != null){
             sql += " and meeting_apply_date between '" + startTime.format(formatter) + "' and '" + endTime.format(formatter) + "'";
         }
+        if(dto.getUserId() != null){
+            sql += " and FIND_IN_SET(" + dto.getUserId() +", meeting_apply_participants)";
+        }
         List<Map<String, Object>> list = SqlRunnerAdapter.db().selectList(sql);
         MeetingStatisticsVo result = new MeetingStatisticsVo();
         result.setAllCount(list.size());
@@ -359,5 +363,55 @@ public class DataboardController {
         return RT.ok(result);
     }
 
+    @GetMapping(value = "/reimbursement-statistics")
+    @ApiOperation(value="会议统计")
+    @SaCheckPermission("databoard:detail")
+    public RT<ReimbursementStatisticsVo> reimbursementStatistics(@Valid StatisticsDetailDto dto){
+        LocalDateTime startTime = null;
+        LocalDateTime endTime = null;
+        if(dto.getStartDate() != null){
+            startTime = dto.getStartDate().atStartOfDay();
+        }
+        if(dto.getEndDate() != null){
+            endTime = dto.getEndDate().atStartOfDay().plusDays(1).plusNanos(-1);
+        }
+        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
+
+        String sql = "SELECT * FROM billing_reimbursement where 1 = 1";
+        if(startTime != null && endTime != null){
+            sql += " and aply_time between '" + startTime.format(formatter) + "' and '" + endTime.format(formatter) + "'";
+        }
+        if(dto.getUserId() != null){
+            sql += " and applicant_id = " + dto.getUserId();
+        }
+        List<Map<String, Object>> list = SqlRunnerAdapter.db().selectList(sql);
+        ReimbursementStatisticsVo result = new ReimbursementStatisticsVo();
+        result.setAllCount(list.size());
+        int completeCount = 0;
+        int uncompleteCount = 0;
+
+        int cityIn = 0;
+        int cityOut = 0;
+        for (Map<String, Object> objectMap : list) {
+            Object statusObj = objectMap.get("status");
+            if(statusObj == null){
+                uncompleteCount ++;
+            }else{
+                completeCount ++;
+            }
+
+            Object cityInObj = objectMap.get("city_in");
+            if(cityInObj != null && Integer.parseInt(cityInObj.toString()) == 1){
+
+            }
+        }
+        result.setCompleteCount(completeCount);
+        result.setUncompleteCount(uncompleteCount);
+
+
+
+
+        return RT.ok(result);
+    }
 
 }

+ 30 - 0
src/main/java/com/xjrsoft/module/databoard/vo/ReimbursementStatisticsVo.java

@@ -0,0 +1,30 @@
+package com.xjrsoft.module.databoard.vo;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.util.List;
+
+/**
+* @title: 数据看板-差旅费报销申请统计出参
+* @Author dzx
+* @Date: 2024年9月2日
+* @Version 1.0
+*/
+@Data
+public class ReimbursementStatisticsVo {
+
+
+    @ApiModelProperty("申请总次数")
+    private Integer allCount;
+
+    @ApiModelProperty("完成总数")
+    private Integer completeCount;
+
+    @ApiModelProperty("未完成总数")
+    private Integer uncompleteCount;
+
+    @ApiModelProperty("申请")
+    private List<ItemCountVo> amountList;
+
+}

+ 15 - 2
src/main/java/com/xjrsoft/module/material/controller/MaterialTaskController.java

@@ -49,6 +49,8 @@ import org.springframework.web.multipart.MultipartFile;
 import javax.validation.Valid;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
+import java.time.LocalDate;
+import java.time.format.DateTimeFormatter;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -181,7 +183,7 @@ public class MaterialTaskController {
         return RT.ok(result);
     }
 
-    @GetMapping("/export")
+    @PostMapping("/export-query")
     @ApiOperation(value = "导出")
     public ResponseEntity<byte[]> exportData(@Valid MaterialTaskPageDto dto, @RequestParam(defaultValue = "false") Boolean isTemplate) {
         List<MaterialTaskPageVo> customerList = isTemplate != null && isTemplate ? new ArrayList<>() : ((PageOutput<MaterialTaskPageVo>) page(dto).getData()).getList();
@@ -266,10 +268,21 @@ public class MaterialTaskController {
         }}));
     }
 
-    @GetMapping("/form-data-export-query")
+    @PostMapping("/form-data-export-query")
     @ApiOperation(value = "表单缴交数据条件导出")
     public ResponseEntity<byte[]> formDataExportQuery(@Valid @RequestBody FormDataExportQueryDto dto) {
         ByteArrayOutputStream bot = materialTaskService.formDataExportQuery(dto);
         return RT.fileStream(bot.toByteArray(), "MaterialFormData" + ExcelTypeEnum.XLSX.getValue());
     }
+
+    @PostMapping("/download-file")
+    @ApiOperation(value = "下载附件(zip压缩包)")
+    public ResponseEntity<byte[]> downloadFile(@Valid MaterialTaskAssignListDto dto) {
+        MaterialTask materialTask = materialTaskService.getById(dto.getMaterialTaskId());
+
+        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy年MM月dd日");
+
+        byte[] bytes = materialTaskService.downloadFile(dto);
+        return RT.fileStream(bytes, materialTask.getName() + "【" + LocalDate.now().format(formatter) + "】" + ".zip");
+    }
 }

+ 2 - 0
src/main/java/com/xjrsoft/module/material/service/IMaterialTaskService.java

@@ -58,4 +58,6 @@ public interface IMaterialTaskService extends MPJBaseService<MaterialTask> {
     List<MaterialTaskAssignListVo> assignList(MaterialTaskAssignListDto dto);
 
     ByteArrayOutputStream formDataExportQuery(FormDataExportQueryDto dto);
+
+    byte[] downloadFile(MaterialTaskAssignListDto dto);
 }

+ 65 - 12
src/main/java/com/xjrsoft/module/material/service/impl/MaterialTaskServiceImpl.java

@@ -6,6 +6,7 @@ import cn.hutool.extra.spring.SpringUtil;
 import cn.hutool.json.JSONUtil;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.fasterxml.jackson.core.type.TypeReference;
 import com.github.yulichang.base.MPJBaseServiceImpl;
@@ -15,6 +16,7 @@ import com.xjrsoft.common.enums.DeleteMark;
 import com.xjrsoft.common.enums.MaterialCategoryEnum;
 import com.xjrsoft.common.exception.MyException;
 import com.xjrsoft.common.model.generator.ComponentConfig;
+import com.xjrsoft.common.utils.FileZipUtil;
 import com.xjrsoft.common.utils.RedisUtil;
 import com.xjrsoft.common.utils.VoToColumnUtil;
 import com.xjrsoft.module.concat.service.IXjrUserService;
@@ -50,6 +52,8 @@ import com.xjrsoft.module.organization.service.IUserService;
 import com.xjrsoft.module.organization.service.IWeChatService;
 import com.xjrsoft.module.student.entity.BaseStudentSchoolRoll;
 import com.xjrsoft.module.system.entity.DictionaryDetail;
+import com.xjrsoft.module.system.entity.File;
+import com.xjrsoft.module.system.service.IFileService;
 import com.xjrsoft.module.teacher.entity.XjrUser;
 import com.xjrsoft.module.teacher.vo.XjrUserVo;
 import lombok.AllArgsConstructor;
@@ -57,6 +61,10 @@ import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
 import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.net.URLConnection;
 import java.time.LocalDate;
 import java.util.*;
 import java.util.concurrent.CompletableFuture;
@@ -74,7 +82,7 @@ public class MaterialTaskServiceImpl extends MPJBaseServiceImpl<MaterialTaskMapp
     private final MaterialTaskMapper materialTaskMaterialTaskMapper;
 
     private final MaterialTaskAssignMapper materialTaskMaterialTaskAssignMapper;
-    private final MaterialTaskAppendixMapper materialTaskMaterialTaskAppendixMapper;
+    private final MaterialTaskAppendixMapper appendixMapper;
 
     private final IMaterialTypeService materialTypeService;
     private final IWeChatService weChatService;
@@ -82,6 +90,8 @@ public class MaterialTaskServiceImpl extends MPJBaseServiceImpl<MaterialTaskMapp
     private final IFormExecuteService formExecuteService;
 
     private final FormTemplateMapper formTemplateMapper;
+    private final IFileService fileService;
+    private final IUserService userService;
 
     @Override
     @Transactional(rollbackFor = Exception.class)
@@ -219,7 +229,7 @@ public class MaterialTaskServiceImpl extends MPJBaseServiceImpl<MaterialTaskMapp
         //********************************* MaterialTaskAppendix  增删改  开始 *******************************************/
         {
             // 查出所有子级的id
-            List<MaterialTaskAppendix> materialTaskAppendixList = materialTaskMaterialTaskAppendixMapper.selectList(Wrappers.lambdaQuery(MaterialTaskAppendix.class).eq(MaterialTaskAppendix::getMaterialTaskId, materialTask.getId()).select(MaterialTaskAppendix::getId));
+            List<MaterialTaskAppendix> materialTaskAppendixList = appendixMapper.selectList(Wrappers.lambdaQuery(MaterialTaskAppendix.class).eq(MaterialTaskAppendix::getMaterialTaskId, materialTask.getId()).select(MaterialTaskAppendix::getId));
             List<Long> materialTaskAppendixIds = materialTaskAppendixList.stream().map(MaterialTaskAppendix::getId).collect(Collectors.toList());
             //原有子表单 没有被删除的主键
             List<Long> materialTaskAppendixOldIds = materialTask.getMaterialTaskAppendixList().stream().map(MaterialTaskAppendix::getId).filter(Objects::nonNull).collect(Collectors.toList());
@@ -229,18 +239,18 @@ public class MaterialTaskServiceImpl extends MPJBaseServiceImpl<MaterialTaskMapp
             for (MaterialTaskAppendix materialTaskAppendix : materialTask.getMaterialTaskAppendixList()) {
                 //如果不等于空则修改
                 if (materialTaskAppendix.getId() != null) {
-                    materialTaskMaterialTaskAppendixMapper.updateById(materialTaskAppendix);
+                    appendixMapper.updateById(materialTaskAppendix);
                 }
                 //如果等于空 则新增
                 else {
                     //已经不存在的id 删除
                     materialTaskAppendix.setMaterialTaskId(materialTask.getId());
-                    materialTaskMaterialTaskAppendixMapper.insert(materialTaskAppendix);
+                    appendixMapper.insert(materialTaskAppendix);
                 }
             }
             //已经不存在的id 删除
             if (materialTaskAppendixRemoveIds.size() > 0) {
-                materialTaskMaterialTaskAppendixMapper.deleteBatchIds(materialTaskAppendixRemoveIds);
+                appendixMapper.deleteBatchIds(materialTaskAppendixRemoveIds);
             }
         }
         //********************************* MaterialTaskAppendix  增删改  结束 *******************************************/
@@ -253,7 +263,7 @@ public class MaterialTaskServiceImpl extends MPJBaseServiceImpl<MaterialTaskMapp
     public Boolean delete(List<Long> ids) {
         materialTaskMaterialTaskMapper.deleteBatchIds(ids);
         materialTaskMaterialTaskAssignMapper.delete(Wrappers.lambdaQuery(MaterialTaskAssign.class).in(MaterialTaskAssign::getMaterialTaskId, ids));
-        materialTaskMaterialTaskAppendixMapper.delete(Wrappers.lambdaQuery(MaterialTaskAppendix.class).in(MaterialTaskAppendix::getMaterialTaskId, ids));
+        appendixMapper.delete(Wrappers.lambdaQuery(MaterialTaskAppendix.class).in(MaterialTaskAppendix::getMaterialTaskId, ids));
 
         return true;
     }
@@ -289,14 +299,14 @@ public class MaterialTaskServiceImpl extends MPJBaseServiceImpl<MaterialTaskMapp
                 materialTaskMaterialTaskAssignMapper.updateById(materialTaskAssign);
 
                 if (oldStatus == 4) { // 重做删除原来的
-                    materialTaskMaterialTaskAppendixMapper.delete(Wrappers.lambdaQuery(MaterialTaskAppendix.class).eq(MaterialTaskAppendix::getMaterialTaskId, materialTaskAssignAppendixDto.getMaterialTaskAssignId()));
+                    appendixMapper.delete(Wrappers.lambdaQuery(MaterialTaskAppendix.class).eq(MaterialTaskAppendix::getMaterialTaskId, materialTaskAssignAppendixDto.getMaterialTaskAssignId()));
                 }
 
                 for (AddMaterialTaskAppendixDto materialTaskAppendixDto : materialTaskAssignAppendixDto.getMaterialTaskAppendixList()) {
                     MaterialTaskAppendix materialTaskAppendix = new MaterialTaskAppendix();
                     materialTaskAppendix.setMaterialTaskId(materialTaskAssignAppendixDto.getMaterialTaskAssignId());
                     materialTaskAppendix.setFileId(materialTaskAppendixDto.getFileId());
-                    materialTaskMaterialTaskAppendixMapper.insert(materialTaskAppendix);
+                    appendixMapper.insert(materialTaskAppendix);
                 }
             }
         }
@@ -329,7 +339,7 @@ public class MaterialTaskServiceImpl extends MPJBaseServiceImpl<MaterialTaskMapp
                 materialTaskMaterialTaskAssignMapper.updateById(materialTaskAssign);
 
                 if (oldStatus == 4) { // 重做删除原来的
-                    materialTaskMaterialTaskAppendixMapper.delete(Wrappers.lambdaQuery(MaterialTaskAppendix.class).eq(MaterialTaskAppendix::getMaterialTaskId, materialTaskAssignAppendixDto.getMaterialTaskAssignId()));
+                    appendixMapper.delete(Wrappers.lambdaQuery(MaterialTaskAppendix.class).eq(MaterialTaskAppendix::getMaterialTaskId, materialTaskAssignAppendixDto.getMaterialTaskAssignId()));
                 }
 
                 long id = formExecuteService.addByTemplateId(new FormExecuteAddOrUpdateDto(){{
@@ -340,7 +350,7 @@ public class MaterialTaskServiceImpl extends MPJBaseServiceImpl<MaterialTaskMapp
                 MaterialTaskAppendix materialTaskAppendix = new MaterialTaskAppendix();
                 materialTaskAppendix.setMaterialTaskId(materialTaskAssignAppendixDto.getMaterialTaskAssignId());
                 materialTaskAppendix.setFileId(id);
-                materialTaskMaterialTaskAppendixMapper.insert(materialTaskAppendix);
+                appendixMapper.insert(materialTaskAppendix);
             }
         }
         return true;
@@ -466,8 +476,11 @@ public class MaterialTaskServiceImpl extends MPJBaseServiceImpl<MaterialTaskMapp
 
         List<MaterialTaskAssignListVo> pageOutput = materialTaskMaterialTaskAssignMapper.selectJoinList(MaterialTaskAssignListVo.class, queryWrapper);
 
-        for (MaterialTaskAssignListVo materialTaskAssignListVo : pageOutput){
-            materialTypeService.handleFileAndTemplate(materialTaskAssignListVo, materialTaskAssignListVo.getMaterialCategory());
+        for (MaterialTaskAssignListVo el : pageOutput){
+            materialTypeService.handleFileAndTemplate(el, el.getMaterialCategory());
+
+            List<File> fileList = fileService.list(Wrappers.<File>query().lambda().eq(File::getFolderId, el.getFolderId()));
+            el.setFiles(fileList);
         }
 
         return pageOutput;
@@ -509,6 +522,46 @@ public class MaterialTaskServiceImpl extends MPJBaseServiceImpl<MaterialTaskMapp
         return null;
     }
 
+    @Override
+    public byte[] downloadFile(MaterialTaskAssignListDto dto) {
+        List<MaterialTaskAppendix> appendices = appendixMapper.selectList(
+                new QueryWrapper<MaterialTaskAppendix>().lambda()
+                        .eq(MaterialTaskAppendix::getMaterialTaskId, dto.getMaterialTaskId())
+        );
+        List<Long> userIds = appendices.stream().map(MaterialTaskAppendix::getCreateUserId).collect(Collectors.toList());
+        List<User> userList = userService.listByIds(userIds);
+        Map<Long, User> userMap = userList.stream().collect(Collectors.toMap(User::getId, x -> x));
+
+        Map<String, byte[]> byteAryMap = new HashMap<>();
+        MaterialTask task = this.getById(dto.getMaterialTaskId());
+
+        for (MaterialTaskAppendix appendix : appendices) {
+            List<File> fileList = fileService.list(Wrappers.<File>query().lambda().eq(File::getFolderId, appendix.getFileId()));
+            User user = userMap.get(appendix.getCreateUserId());
+            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(user.getName() + "-" + user.getUserName() + "-" + task.getName() + fileList.get(i).getFileType(), byteArray);
+                    in.close();
+                    outputStream.close();
+                } catch (IOException e) {
+                    throw new MyException("文件下载失败", e);
+                }
+            }
+        }
+
+        return FileZipUtil.byteAryMap2Zip(byteAryMap);
+    }
+
     private void sendMessageUtil(MaterialTask materialTask ) {
         IUserService userService = SpringUtil.getBean(IUserService.class);
         RedisUtil redisUtil = SpringUtil.getBean(RedisUtil.class);

+ 4 - 0
src/main/java/com/xjrsoft/module/system/service/IFileService.java

@@ -3,6 +3,8 @@ package com.xjrsoft.module.system.service;
 import com.github.yulichang.base.MPJBaseService;
 import com.xjrsoft.module.system.entity.File;
 
+import java.util.List;
+
 /**
  * <p>
  * 文件关联关系表 服务类
@@ -16,4 +18,6 @@ public interface IFileService extends MPJBaseService<File> {
     boolean deleteFile(String encode);
 
     byte[] downloadFileByZip(Long folderId);
+
+    byte[] downloadFileByZip(List<Long> folderIds);
 }

+ 37 - 0
src/main/java/com/xjrsoft/module/system/service/impl/FileServiceImpl.java

@@ -64,6 +64,43 @@ public class FileServiceImpl extends MPJBaseServiceImpl<FileMapper, File> implem
 //                    System.err.println(byteArray.length);
 //                    outputStream.writeTo(fos);
 
+//                System.out.println("File downloaded successfully.");
+                in.close();
+                outputStream.close();
+            } catch (IOException e) {
+                throw new RuntimeException(e);
+            }
+        }
+        //执行下面这段代码就可以拿到压缩之后的byte数组
+        return FileZipUtil.byteAryMap2Zip(byteAryMap);
+    }
+
+    @Override
+    public byte[] downloadFileByZip(List<Long> folderIds) {
+        List<File> fileList = this.list(Wrappers.<File>query().lambda().in(File::getFolderId, folderIds));
+
+        //声明一个Map,将所有文件装进去,map的key是完整的文件名
+        Map<String, byte[]> byteAryMap = new HashMap<>();
+
+        for (int i = 0; i < fileList.size(); i++) {
+//            String localFilePath = "C:\\Users\\大数据与最优化研究所\\Downloads\\" + fileList.get(i).getFileName() + fileList.get(i).getFileType();
+//            System.err.println(localFilePath);
+            try {
+                URL url = new URL(fileList.get(i).getFileUrl());
+                URLConnection conn = url.openConnection();
+                InputStream in = conn.getInputStream();
+//                        FileOutputStream fos = new FileOutputStream(localFilePath)
+                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(fileList.get(i).getFileName() + fileList.get(i).getFileType(), byteArray);
+//                    System.err.println(byteArray.length);
+//                    outputStream.writeTo(fos);
+
 //                System.out.println("File downloaded successfully.");
                 in.close();
                 outputStream.close();