101captain
2022-07-11 246e82c0f3749ed566a2324490949583f1dbddb0
导出不带截图接口
1个文件已修改
109 ■■■■■ 已修改文件
springcloud_k8s_panzhihuazhihuishequ/community_backstage/src/main/java/com/panzhihua/community_backstage/api/ComActAcidRecordApi.java 109 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
springcloud_k8s_panzhihuazhihuishequ/community_backstage/src/main/java/com/panzhihua/community_backstage/api/ComActAcidRecordApi.java
@@ -249,6 +249,115 @@
        return r;
    }
    @ApiOperation(value = "导出不带截图")
    @PostMapping("/exportNoImage")
    public R exportNoImage(@RequestBody ComActAcidRecordDTO comActAcidRecordDTO) {
        String name = "防疫登记信息导出"+System.currentTimeMillis()+".xlsx";
        String property = System.getProperty("user.dir");
        String sourceFile =property+File.separator+"acid"+File.separator+System.currentTimeMillis()+File.separator;
        String zipFile=property+File.separator+"zip"+File.separator;
        String ftpUrl = "/mnt/data/web/excel/";
        // 用户搜索了就下载搜索的用户否则下载所有用户
        if(StringUtils.isEmpty(comActAcidRecordDTO.getLocalCity())){
            comActAcidRecordDTO.setLocalCity(this.getLoginUserInfo().getName());
        }
        R r = communityService.exportComActAcidRecord(comActAcidRecordDTO);
        if (R.isOk(r)) {
            File directory=new File(sourceFile);
            if(!directory.exists()){
                directory.mkdirs();
            }
            List<ComActAcidRecordExcelVO> excelVOS=new ArrayList<>();
            List<ComActAcidRecordExcelReturn> list= JSONArray.parseArray(JSONArray.toJSONString(r.getData()), ComActAcidRecordExcelReturn.class);
            if(!CollectionUtils.isEmpty(list)){
                list.forEach(li->{
                    ComActAcidRecordExcelVO comActAcidRecordExcelVO=new ComActAcidRecordExcelVO();
                    BeanUtils.copyProperties(li,comActAcidRecordExcelVO);
//                    if(StringUtils.isNotEmpty(li.getTravelImage())){
//                        try {
//                            File image=new File(sourceFile+"/"+li.getName()+"行程码.jpg");
//                            FileUtils.copyURLToFile(new URL(li.getTravelImage()),image);
//                            //comActAcidRecordExcelVO.setAcidImage(new URL(li.getAcidImage()));
//                            //comActAcidRecordExcelVO.setTravelImage(new URL(li.getTravelImage()));
//                            //comActAcidRecordExcelVO.setVaccinationImage(new URL(li.getVaccinationImage()));
//                        } catch (Exception e) {
//                            e.printStackTrace();
//                        }
//                    }
//                    if(StringUtils.isNotEmpty(li.getColorImage())){
//                        try {
//                            File image=new File(sourceFile+"/"+li.getName()+"健康码.jpg");
//                            FileUtils.copyURLToFile(new URL(li.getColorImage()),image);
//                            //comActAcidRecordExcelVO.setAcidImage(new URL(li.getAcidImage()));
//                            //comActAcidRecordExcelVO.setColorImage(new URL(li.getColorImage()));
//                            //comActAcidRecordExcelVO.setVaccinationImage(new URL(li.getVaccinationImage()));
//                        } catch (Exception e) {
//                            e.printStackTrace();
//                        }
//                    }
//                    if(StringUtils.isNotEmpty(li.getAcidImage())&&li.getLocalCity().contains("仁和区")){
//                        try {
//                            File image=new File(sourceFile+"/"+li.getName()+"核酸截图.jpg");
//                            FileUtils.copyURLToFile(new URL(li.getAcidImage()),image);
//                            //comActAcidRecordExcelVO.setAcidImage(new URL(li.getAcidImage()));
//                            //comActAcidRecordExcelVO.setColorImage(new URL(li.getColorImage()));
//                            //comActAcidRecordExcelVO.setVaccinationImage(new URL(li.getVaccinationImage()));
//                        } catch (Exception e) {
//                            e.printStackTrace();
//                        }
//                    }
                    if(li.getCheckStatus()==0){
                        comActAcidRecordExcelVO.setCheckStatus("否");
                    }
                    else{
                        comActAcidRecordExcelVO.setCheckStatus("是");
                    }
                    excelVOS.add(comActAcidRecordExcelVO);
                });
            }
            try {
                SFTPUtil sftp = new SFTPUtil(userName, password, host, port);
                sftp.login();
                boolean existDir = sftp.isExistDir(ftpUrl + name);
                if (!existDir) {
                    String fileName = sourceFile + File.separator + name;
                    // 这里 需要指定写用哪个class去写
                    ExcelWriter excelWriter = null;
                    InputStream inputStream = null;
                    try {
                        excelWriter = EasyExcel.write(fileName, ComActAcidRecordExcelVO.class)
                                .registerWriteHandler(new LongestMatchColumnWidthStyleStrategy())
                                .registerWriteHandler(new CustomSheetWriteHandler()).build();
                        WriteSheet writeSheet = EasyExcel.writerSheet( "导出").build();
                        excelWriter.write(excelVOS, writeSheet);
                        excelWriter.finish();
                    } finally {
                        // 千万别忘记finish 会帮忙关闭流
                        if (inputStream != null) {
                            inputStream.close();
                        }
                        if (excelWriter != null) {
                            excelWriter.finish();
                        }
                    }
                }
                FileUtil.compressToZip(sourceFile,zipFile,"防疫登记信息.zip");
                String currentDateString = String.valueOf(System.currentTimeMillis());
                String zipName = "防疫登记信息_"+ currentDateString+".zip";
                InputStream input=new FileInputStream(zipFile+"防疫登记信息.zip");
                sftp.uploadMore(ftpUrl, zipName , input);
                sftp.logout();
                input.close();
                return R.ok(excelUrl + zipName);
            } catch (Exception e) {
                e.printStackTrace();
                log.error("文件传输失败【{}】", e.getMessage());
                return R.fail();
            }
        }
        return r;
    }
    /**
     * 5项常规统计