| | |
| | | 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; |
| | |
| | | @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())){ |
| | |
| | | } |
| | | 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)){ |
| | |
| | | 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(); |
| | | } |
| | | } |
| | |
| | | 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; |
| | |
| | | .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) { |
| | |
| | | } |
| | | } |
| | | } |
| | | 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()); |