| | |
| | | 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.config.MinioUtil; |
| | | import com.panzhihua.community_backstage.excel.CustomSheetWriteHandler; |
| | | import com.sun.imageio.plugins.common.ImageUtil; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.io.FileUtils; |
| | | import org.apache.commons.io.IOUtils; |
| | | import org.apache.poi.ss.util.ImageUtils; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.util.CollectionUtils; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.io.File; |
| | | import java.io.FileInputStream; |
| | | import java.io.InputStream; |
| | | import java.net.MalformedURLException; |
| | | import java.net.URL; |
| | | import java.io.*; |
| | | import java.net.*; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | |
| | | // FTP 端口 |
| | | @Value("${ftp.port}") |
| | | private int port; |
| | | @Resource |
| | | private MinioUtil minioUtil; |
| | | |
| | | /** |
| | | * 分页查询所有数据 |
| | |
| | | @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()); |
| | |
| | | public R statics(@RequestParam("date")String date){ |
| | | return this.communityService.comActAcidRecordStatics(date); |
| | | } |
| | | |
| | | public String downloadPicture(String urlString, String fileName,String dir) throws Exception { |
| | | // 构造URL |
| | | URL url = new URL(urlString); |
| | | // 打开连接 |
| | | URLConnection con = url.openConnection(); |
| | | // 输入流 |
| | | InputStream is = con.getInputStream(); |
| | | // 1K的数据缓冲 |
| | | byte[] bs = new byte[1024]; |
| | | // 读取到的数据长度 |
| | | int len; |
| | | // 输出的文件流 |
| | | String filename = dir + fileName + ".jpg"; // 下载路径及下载图片名称 |
| | | File file = new File(filename); |
| | | FileOutputStream os = new FileOutputStream(file, true); |
| | | // 开始读取 |
| | | while ((len = is.read(bs)) != -1) { |
| | | os.write(bs, 0, len); |
| | | } |
| | | // 完毕,关闭所有链接 |
| | | os.close(); |
| | | is.close(); |
| | | return filename; |
| | | } |
| | | } |