101captain
2022-06-14 6e64546a2a165e4aecb020cca7cc1d8d58871d85
bug修改
1个文件已修改
43 ■■■■■ 已修改文件
springcloud_k8s_panzhihuazhihuishequ/community_backstage/src/main/java/com/panzhihua/community_backstage/api/ComActAcidRecordApi.java 43 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
springcloud_k8s_panzhihuazhihuishequ/community_backstage/src/main/java/com/panzhihua/community_backstage/api/ComActAcidRecordApi.java
@@ -17,12 +17,14 @@
import com.panzhihua.common.model.vos.community.reserve.FiveCount;
import com.panzhihua.common.model.vos.community.warehouse.ComActWarehouseApplyExcelVO;
import com.panzhihua.common.service.community.CommunityService;
import com.panzhihua.common.utlis.FileUtil;
import com.panzhihua.common.utlis.SFTPUtil;
import com.panzhihua.common.utlis.StringUtils;
import com.panzhihua.community_backstage.excel.CustomSheetWriteHandler;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.FileUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.util.CollectionUtils;
@@ -137,6 +139,9 @@
    @PostMapping("/export")
    public R export(@RequestBody ComActAcidRecordDTO comActAcidRecordDTO) {
        String name = "防疫登记信息导出.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())){
@@ -144,6 +149,10 @@
        }
        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)){
@@ -152,28 +161,34 @@
                    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 (MalformedURLException e) {
                        } 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 (MalformedURLException e) {
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                    if(StringUtils.isNotEmpty(li.getAcidImage())){
                        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 (MalformedURLException e) {
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
@@ -191,8 +206,7 @@
                sftp.login();
                boolean existDir = sftp.isExistDir(ftpUrl + name);
                if (!existDir) {
                    String property = System.getProperty("user.dir");
                    String fileName = property + File.separator + name;
                    String fileName = sourceFile + File.separator + name;
                    // 这里 需要指定写用哪个class去写
                    ExcelWriter excelWriter = null;
                    InputStream inputStream = null;
@@ -202,17 +216,7 @@
                                .registerWriteHandler(new CustomSheetWriteHandler()).build();
                        WriteSheet writeSheet = EasyExcel.writerSheet( "导出").build();
                        excelWriter.write(excelVOS, writeSheet);
                        excelWriter.finish();
                        File file = new File(fileName);
                        inputStream = new FileInputStream(file);
                        sftp.uploadMore(ftpUrl, name, inputStream);
                        sftp.logout();
                        inputStream.close();
                        String absolutePath = file.getAbsolutePath();
                        boolean delete = file.delete();
                        log.info("删除excel【{}】结果【{}】", absolutePath, delete);
                    } finally {
                        // 千万别忘记finish 会帮忙关闭流
                        if (inputStream != null) {
@@ -223,7 +227,14 @@
                        }
                    }
                }
                return R.ok(excelUrl + name);
                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());