ApplicationTest.java 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. //package com.simuwang;
  2. //
  3. //import cn.hutool.core.collection.ListUtil;
  4. //import cn.hutool.core.date.DateUtil;
  5. //import com.itextpdf.text.Image;
  6. //import com.itextpdf.text.pdf.PdfWriter;
  7. //import com.simuwang.base.common.conts.DateConst;
  8. //import com.simuwang.base.pojo.dto.MailboxInfoDTO;
  9. //import com.simuwang.daq.service.EmailParseApiService;
  10. //import com.simuwang.daq.service.EmailParseService;
  11. //import org.apache.pdfbox.pdmodel.PDDocument;
  12. //import org.apache.pdfbox.rendering.ImageType;
  13. //import org.apache.pdfbox.rendering.PDFRenderer;
  14. //import org.jasypt.util.text.BasicTextEncryptor;
  15. //import org.apache.pdfbox.Loader;
  16. //import org.junit.jupiter.api.Test;
  17. //import org.springframework.beans.factory.annotation.Autowired;
  18. //import org.springframework.boot.test.context.SpringBootTest;
  19. //import com.itextpdf.text.*;
  20. //import javax.imageio.ImageIO;
  21. //import java.awt.*;
  22. //import java.awt.image.BufferedImage;
  23. //import java.io.File;
  24. //import java.io.FileNotFoundException;
  25. //import java.io.FileOutputStream;
  26. //import java.io.IOException;
  27. //import java.util.*;
  28. //import java.util.List;
  29. //
  30. //
  31. //@SpringBootTest(classes = Application.class)
  32. //public class ApplicationTest {
  33. //
  34. // @Autowired
  35. // private EmailParseService emailParseService;
  36. //
  37. // @Autowired
  38. // private EmailParseApiService emailParseApiService;
  39. //
  40. // @Test
  41. // public void test() {
  42. // MailboxInfoDTO emailInfoDTO = this.buildMailbox("", "");
  43. ////
  44. //// emailInfoDTO.setAccount("jjpj_test");
  45. //// emailInfoDTO.setPassword("shzq#919");
  46. //// emailInfoDTO.setHost("mail.shzq.com");
  47. //// emailInfoDTO.setPort("993");
  48. //// emailInfoDTO.setProtocol("imap");
  49. //
  50. // Date startDate = DateUtil.parse("2024-10-10 15:00:00", DateConst.YYYY_MM_DD_HH_MM_SS);
  51. // Date endDate = DateUtil.parse("2024-10-10 16:40:00", DateConst.YYYY_MM_DD_HH_MM_SS);
  52. // try {
  53. // emailParseService.parseEmail(emailInfoDTO, startDate, endDate);
  54. // } catch (Exception e) {
  55. // throw new RuntimeException(e);
  56. // }
  57. // }
  58. //
  59. // @Test
  60. // public void reportTest() {
  61. // MailboxInfoDTO emailInfoDTO = this.buildMailbox("x", "x");
  62. // Date startDate = DateUtil.parse("2024-10-15 15:10:30", DateConst.YYYY_MM_DD_HH_MM_SS);
  63. // Date endDate = DateUtil.parse("2024-10-15 17:50:30", DateConst.YYYY_MM_DD_HH_MM_SS);
  64. // try {
  65. // emailParseService.parseEmail(emailInfoDTO, startDate, endDate);
  66. // } catch (Exception e) {
  67. // throw new RuntimeException(e);
  68. // }
  69. // }
  70. //
  71. // @Test
  72. // public void testReparseEmail() {
  73. // emailParseApiService.reparseEmail(593);
  74. // }
  75. //
  76. // @Test
  77. // public void testReparseFile() {
  78. // emailParseApiService.reparseFile(ListUtil.toList(40, 43));
  79. // }
  80. //
  81. // @Test
  82. // public void testDateFormat() {
  83. // String input = "Smppw@2024";
  84. // BasicTextEncryptor textEncryptor = new BasicTextEncryptor();
  85. // textEncryptor.setPassword("qwertyuiopasdfghjklzxcvbnm1234567890qwertyuiopasdfghjklzxcvbnm12"); // 用您自己的密钥替换"yourSecretKey"
  86. // String encryptedString = textEncryptor.encrypt(input);
  87. // String decrypt = textEncryptor.decrypt(encryptedString);
  88. // System.out.println("加密后的字符串为: " + encryptedString);
  89. // System.out.println("解密后的字符串为: " + decrypt);
  90. // }
  91. //
  92. // private MailboxInfoDTO buildMailbox(String account, String pwd) {
  93. // MailboxInfoDTO emailInfoDTO = new MailboxInfoDTO();
  94. // emailInfoDTO.setUserId(1);
  95. // emailInfoDTO.setAccount(account);
  96. // emailInfoDTO.setPassword(pwd);
  97. // emailInfoDTO.setHost("imap.exmail.qq.com");
  98. // emailInfoDTO.setPort("993");
  99. // emailInfoDTO.setProtocol("imap");
  100. // return emailInfoDTO;
  101. // }
  102. //
  103. // @Test
  104. // public void testPdfRemoveWatermark() {
  105. // pdfRemoveWatermark("D:/pdf/东华期货奔牛1号7.29-8.2基金净值表.pdf");
  106. // }
  107. //
  108. // public void pdfRemoveWatermark(String filePath) {
  109. // try {
  110. // //PDF转图片
  111. // pdfToImage(filePath);
  112. // List<String> fileNames = getFileNames("D:/pdf/pdfToImage");
  113. // List<File> fileList = new ArrayList<>();
  114. // for (String fileName : fileNames) {
  115. // fileList.add(new File("D:/pdf/pdfToImage/"+fileName));
  116. // }
  117. // //去除PDF水印
  118. // removePdfWatermark(fileList);
  119. // //去除水印后的图片转PDF
  120. // List<Integer> fileNamesInteger = new ArrayList<>();
  121. // List<String> allFiles = new ArrayList<>();
  122. // for (String fileName : fileNames) {
  123. // if(fileName.endsWith(".png")){
  124. // String str = fileName.substring(0, fileName.indexOf(".png"));
  125. // fileNamesInteger.add(Integer.valueOf(str));
  126. // }
  127. // }
  128. // Collections.sort(fileNamesInteger);
  129. // for (Integer fileName : fileNamesInteger) {
  130. // String str ="D:/pdf/pdfToImage/"+ fileName+".png";
  131. // allFiles.add(str);
  132. // }
  133. // String fileName = filePath.substring(filePath.lastIndexOf("/")+1);
  134. // //图片转PDF
  135. // imgOfPdf("D:/pdf/imgToPdf/"+fileName, allFiles);
  136. //
  137. // } catch (IOException e) {
  138. // e.printStackTrace();
  139. // }
  140. // }
  141. //
  142. // private void pdfToImage(String filePath) throws IOException {
  143. // File file = new File(filePath);
  144. // PDDocument doc = Loader.loadPDF(file);
  145. // PDFRenderer renderer = new PDFRenderer(doc);
  146. // int pageCount = doc.getNumberOfPages();
  147. // BufferedImage merge = null;
  148. // int curY = 0;
  149. // for (int i = 0; i < pageCount; i++) {
  150. // try {
  151. // BufferedImage image = renderer.renderImage(i, 2, ImageType.RGB);
  152. // ImageIO.write(image, "png", new File("D:/pdf/pdfToImage/" + i + ".png"));
  153. //// BufferedImage bufferedImage = renderer.renderImage(i, 2, ImageType.RGB);
  154. //// if (Objects.isNull(merge)) {
  155. //// merge = new BufferedImage(bufferedImage.getWidth(), bufferedImage.getHeight() * i, BufferedImage.TYPE_INT_ARGB);
  156. //// }
  157. //// merge.getGraphics().drawImage(bufferedImage, 0, curY, null);
  158. //// curY += bufferedImage.getHeight();
  159. // } catch (IOException e) {
  160. // e.printStackTrace();
  161. // }
  162. // }
  163. // }
  164. // /**
  165. // * 得到文件名称
  166. // *
  167. // * @param path 路径
  168. // * @return {@link List}<{@link String}>
  169. // */
  170. // private static List<String> getFileNames(String path) {
  171. // File file = new File(path);
  172. // if (!file.exists()) {
  173. // return null;
  174. // }
  175. // List<String> fileNames = new ArrayList<>();
  176. // return getFileNames(file, fileNames);
  177. // }
  178. //
  179. // /**
  180. // * 得到文件名称
  181. // *
  182. // * @param file 文件
  183. // * @param fileNames 文件名
  184. // * @return {@link List}<{@link String}>
  185. // */
  186. // private static List<String> getFileNames(File file, List<String> fileNames) {
  187. // File[] files = file.listFiles();
  188. // for (File f : files) {
  189. // if (f.isDirectory()) {
  190. // getFileNames(f, fileNames);
  191. // } else {
  192. // fileNames.add(f.getName());
  193. // }
  194. // }
  195. // return fileNames;
  196. // }
  197. // /**
  198. // * 去除文件列表里图片的水印并替换
  199. // *
  200. // * @Param fileList 文件列表
  201. // */
  202. // public static void removePdfWatermark(List<File> fileList) {
  203. // try {
  204. // for (File file : fileList) {
  205. // if (!file.getName().endsWith("png") && !file.getName().endsWith("jpg")) {
  206. // continue;
  207. // }
  208. // //用ImageIO流读取像素块
  209. // BufferedImage bi = ImageIO.read(file);
  210. // if (bi != null) {
  211. // removeWatermark(bi);
  212. // //生成的图片格式
  213. // String formatName = file.getName().substring(file.getName().lastIndexOf(".") + 1);
  214. // //用ImageIO流生成的处理图替换原图片
  215. // ImageIO.write(bi, formatName, file);
  216. // }
  217. // }
  218. // } catch (IOException e) {
  219. // e.printStackTrace();
  220. // }
  221. // }
  222. // /**
  223. // * 去除水印
  224. // */
  225. // private static void removeWatermark(BufferedImage bi) {
  226. // Color wColor = new Color(254, 254, 254);
  227. // Color hColor = new Color(197, 196, 191);
  228. // //白底水印
  229. // for (int i = 0; i < bi.getWidth(); i++) {
  230. // for (int j = 0; j < bi.getHeight(); j++) {
  231. // int color = bi.getRGB(i, j);
  232. // Color oriColor = new Color(color);
  233. // int red = oriColor.getRed();
  234. // int greed = oriColor.getGreen();
  235. // int blue = oriColor.getBlue();
  236. // if (red == 254 && greed == 254 && blue == 254) {
  237. // continue;
  238. // }
  239. // if (red > 220 && greed > 180 && blue > 80) {
  240. // bi.setRGB(i, j, wColor.getRGB());
  241. // }
  242. // if (red <= 240 && greed >= 200 && blue >= 150) {
  243. // bi.setRGB(i, j, wColor.getRGB());
  244. // }
  245. // }
  246. // }
  247. // }
  248. // public static void imgOfPdf(String filepath, List<String> imgUrl) {
  249. //
  250. // try {
  251. // //输出pdf文件路径
  252. // String pdfUrl = filepath;
  253. // //生成pdf
  254. // File file = Pdf(imgUrl, pdfUrl);
  255. // file.createNewFile();
  256. // } catch (IOException e) {
  257. // e.printStackTrace();
  258. // }
  259. // }
  260. // public static File Pdf(List<String> imageUrllist, String mOutputPdfFileName) {
  261. // //new一个pdf文档
  262. // Document doc = new Document(PageSize.A4, 0, 0, 0, 0);
  263. // try {
  264. // //pdf写入
  265. // PdfWriter.getInstance(doc, new FileOutputStream(mOutputPdfFileName));
  266. // //打开文档
  267. // doc.open();
  268. // //循环图片List,将图片加入到pdf中
  269. // for (int i = 0; i < imageUrllist.size(); i++) {
  270. // //在pdf创建一页
  271. // doc.newPage();
  272. // //通过文件路径获取image
  273. // Image png1 = Image.getInstance(imageUrllist.get(i));
  274. // float height = png1.getHeight();
  275. // float width = png1.getWidth();
  276. // int percent = getPercent2(height, width);
  277. // png1.setAlignment(Image.MIDDLE);
  278. // // 表示是原来图像的比例;
  279. // png1.scalePercent(percent + 3);
  280. // doc.add(png1);
  281. // }
  282. // doc.close();
  283. // } catch (FileNotFoundException e) {
  284. // e.printStackTrace();
  285. // } catch (DocumentException e) {
  286. // e.printStackTrace();
  287. // } catch (IOException e) {
  288. // e.printStackTrace();
  289. // }
  290. // //输出流
  291. // File mOutputPdfFile = new File(mOutputPdfFileName);
  292. // if (!mOutputPdfFile.exists()) {
  293. // mOutputPdfFile.deleteOnExit();
  294. // return null;
  295. // }
  296. // //反回文件输出流
  297. // return mOutputPdfFile;
  298. // }
  299. // public static int getPercent2(float h, float w) {
  300. // int p = 0;
  301. // float p2 = 0.0f;
  302. // p2 = 450 / w * 100;
  303. // p = Math.round(p2);
  304. // return p;
  305. // }
  306. //}