|
@@ -1,139 +1,161 @@
|
|
|
-//package com.simuwang;
|
|
|
-//import cn.hutool.core.collection.ListUtil;
|
|
|
-//import cn.hutool.core.date.DateUtil;
|
|
|
-//import com.simuwang.base.common.conts.DateConst;
|
|
|
-//import com.simuwang.base.pojo.dto.MailboxInfoDTO;
|
|
|
-//import com.simuwang.daq.service.EmailParseApiService;
|
|
|
-//import com.simuwang.daq.service.EmailParseService;
|
|
|
-//import org.jasypt.util.text.BasicTextEncryptor;
|
|
|
-//import org.junit.jupiter.api.Test;
|
|
|
-//import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-//import org.springframework.boot.test.context.SpringBootTest;
|
|
|
-//import java.io.File;
|
|
|
-//import java.util.*;
|
|
|
-//import java.util.List;
|
|
|
-//import java.util.regex.Matcher;
|
|
|
-//import java.util.regex.Pattern;
|
|
|
+package com.simuwang;
|
|
|
+import cn.hutool.core.collection.ListUtil;
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
|
+import com.simuwang.base.common.conts.DateConst;
|
|
|
+import com.simuwang.base.pojo.dto.MailboxInfoDTO;
|
|
|
+import com.simuwang.daq.service.EmailParseApiService;
|
|
|
+import com.simuwang.daq.service.EmailParseService;
|
|
|
+import org.jasypt.encryption.StringEncryptor;
|
|
|
+import org.jasypt.encryption.pbe.PooledPBEStringEncryptor;
|
|
|
+import org.jasypt.encryption.pbe.StandardPBEByteEncryptor;
|
|
|
+import org.jasypt.encryption.pbe.StandardPBEStringEncryptor;
|
|
|
+import org.jasypt.iv.RandomIvGenerator;
|
|
|
+import org.jasypt.util.text.BasicTextEncryptor;
|
|
|
+import org.junit.jupiter.api.Test;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.boot.test.context.SpringBootTest;
|
|
|
+import java.io.File;
|
|
|
+import java.nio.charset.StandardCharsets;
|
|
|
+import java.util.*;
|
|
|
+import java.util.List;
|
|
|
+import java.util.regex.Matcher;
|
|
|
+import java.util.regex.Pattern;
|
|
|
+
|
|
|
+
|
|
|
+@SpringBootTest(classes = Application.class)
|
|
|
+public class ApplicationTest {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private EmailParseService emailParseService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private EmailParseApiService emailParseApiService;
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void test() {
|
|
|
+ MailboxInfoDTO emailInfoDTO = this.buildMailbox("", "");
|
|
|
//
|
|
|
-//
|
|
|
-//@SpringBootTest(classes = Application.class)
|
|
|
-//public class ApplicationTest {
|
|
|
-//
|
|
|
-// @Autowired
|
|
|
-// private EmailParseService emailParseService;
|
|
|
-//
|
|
|
-// @Autowired
|
|
|
-// private EmailParseApiService emailParseApiService;
|
|
|
-//
|
|
|
-// @Test
|
|
|
-// public void test() {
|
|
|
-// MailboxInfoDTO emailInfoDTO = this.buildMailbox("", "");
|
|
|
-////
|
|
|
-//// emailInfoDTO.setAccount("jjpj_test");
|
|
|
-//// emailInfoDTO.setPassword("shzq#919");
|
|
|
-//// emailInfoDTO.setHost("mail.shzq.com");
|
|
|
-//// emailInfoDTO.setPort("993");
|
|
|
-//// emailInfoDTO.setProtocol("imap");
|
|
|
-//
|
|
|
-// Date startDate = DateUtil.parse("2024-10-10 15:00:00", DateConst.YYYY_MM_DD_HH_MM_SS);
|
|
|
-// Date endDate = DateUtil.parse("2024-10-10 16:40:00", DateConst.YYYY_MM_DD_HH_MM_SS);
|
|
|
-// try {
|
|
|
-// emailParseService.parseEmail(emailInfoDTO, startDate, endDate);
|
|
|
-// } catch (Exception e) {
|
|
|
-// throw new RuntimeException(e);
|
|
|
-// }
|
|
|
-// }
|
|
|
-//
|
|
|
-// @Test
|
|
|
-// public void reportTest() {
|
|
|
-// MailboxInfoDTO emailInfoDTO = this.buildMailbox("x", "x");
|
|
|
-// Date startDate = DateUtil.parse("2024-10-15 15:10:30", DateConst.YYYY_MM_DD_HH_MM_SS);
|
|
|
-// Date endDate = DateUtil.parse("2024-10-15 17:50:30", DateConst.YYYY_MM_DD_HH_MM_SS);
|
|
|
-// try {
|
|
|
-// emailParseService.parseEmail(emailInfoDTO, startDate, endDate);
|
|
|
-// } catch (Exception e) {
|
|
|
-// throw new RuntimeException(e);
|
|
|
-// }
|
|
|
-// }
|
|
|
-//
|
|
|
-// @Test
|
|
|
-// public void testReparseEmail() {
|
|
|
-// String regexp = ".*【(.*?基金)】.*";
|
|
|
-// String fileName = "【国恩回报61号私募证券投资基金】投资经理变更通知.pdf";
|
|
|
-// Pattern pattern = Pattern.compile(regexp);
|
|
|
-// Matcher matcher = pattern.matcher(fileName);
|
|
|
-// if(matcher.find()){
|
|
|
-// System.out.println(matcher.group(1));
|
|
|
-// }
|
|
|
-// }
|
|
|
-//
|
|
|
-// @Test
|
|
|
-// public void testReparseFile() {
|
|
|
-// emailParseApiService.reparseFile(ListUtil.toList(40, 43));
|
|
|
-// }
|
|
|
-//
|
|
|
-// @Test
|
|
|
-// public void testDateFormat() {
|
|
|
-// String input = "Smppw@2024";
|
|
|
-// BasicTextEncryptor textEncryptor = new BasicTextEncryptor();
|
|
|
-// textEncryptor.setPassword("qwertyuiopasdfghjklzxcvbnm1234567890qwertyuiopasdfghjklzxcvbnm12"); // 用您自己的密钥替换"yourSecretKey"
|
|
|
-// String encryptedString = textEncryptor.encrypt(input);
|
|
|
-// String decrypt = textEncryptor.decrypt(encryptedString);
|
|
|
-// System.out.println("加密后的字符串为: " + encryptedString);
|
|
|
-// System.out.println("解密后的字符串为: " + decrypt);
|
|
|
-// }
|
|
|
-//
|
|
|
-// private MailboxInfoDTO buildMailbox(String account, String pwd) {
|
|
|
-// MailboxInfoDTO emailInfoDTO = new MailboxInfoDTO();
|
|
|
-// emailInfoDTO.setUserId(1);
|
|
|
-// emailInfoDTO.setAccount(account);
|
|
|
-// emailInfoDTO.setPassword(pwd);
|
|
|
-// emailInfoDTO.setHost("imap.exmail.qq.com");
|
|
|
+// emailInfoDTO.setAccount("jjpj_test");
|
|
|
+// emailInfoDTO.setPassword("shzq#919");
|
|
|
+// emailInfoDTO.setHost("mail.shzq.com");
|
|
|
// emailInfoDTO.setPort("993");
|
|
|
// emailInfoDTO.setProtocol("imap");
|
|
|
-// return emailInfoDTO;
|
|
|
-// }
|
|
|
+
|
|
|
+ Date startDate = DateUtil.parse("2024-10-10 15:00:00", DateConst.YYYY_MM_DD_HH_MM_SS);
|
|
|
+ Date endDate = DateUtil.parse("2024-10-10 16:40:00", DateConst.YYYY_MM_DD_HH_MM_SS);
|
|
|
+ try {
|
|
|
+ emailParseService.parseEmail(emailInfoDTO, startDate, endDate);
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void reportTest() {
|
|
|
+ MailboxInfoDTO emailInfoDTO = this.buildMailbox("x", "x");
|
|
|
+ Date startDate = DateUtil.parse("2024-10-15 15:10:30", DateConst.YYYY_MM_DD_HH_MM_SS);
|
|
|
+ Date endDate = DateUtil.parse("2024-10-15 17:50:30", DateConst.YYYY_MM_DD_HH_MM_SS);
|
|
|
+ try {
|
|
|
+ emailParseService.parseEmail(emailInfoDTO, startDate, endDate);
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testReparseEmail() {
|
|
|
+ String regexp = ".*【(.*?基金)】.*";
|
|
|
+ String fileName = "【国恩回报61号私募证券投资基金】投资经理变更通知.pdf";
|
|
|
+ Pattern pattern = Pattern.compile(regexp);
|
|
|
+ Matcher matcher = pattern.matcher(fileName);
|
|
|
+ if(matcher.find()){
|
|
|
+ System.out.println(matcher.group(1));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testReparseFile() {
|
|
|
+ emailParseApiService.reparseFile(ListUtil.toList(40, 43));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testDateFormat() {
|
|
|
+ String input = "Smppw@2024";
|
|
|
+ BasicTextEncryptor textEncryptor = new BasicTextEncryptor();
|
|
|
+ textEncryptor.setPassword("qwertyuiopasdfghjklzxcvbnm1234567890qwertyuiopasdfghjklzxcvbnm12"); // 用您自己的密钥替换"yourSecretKey"
|
|
|
+ String encryptedString = textEncryptor.encrypt(input);
|
|
|
+ String decrypt = textEncryptor.decrypt(encryptedString);
|
|
|
+ System.out.println("加密后的字符串为: " + encryptedString);
|
|
|
+ System.out.println("解密后的字符串为: " + decrypt);
|
|
|
+ }
|
|
|
+
|
|
|
+ private MailboxInfoDTO buildMailbox(String account, String pwd) {
|
|
|
+ MailboxInfoDTO emailInfoDTO = new MailboxInfoDTO();
|
|
|
+ emailInfoDTO.setUserId(1);
|
|
|
+ emailInfoDTO.setAccount(account);
|
|
|
+ emailInfoDTO.setPassword(pwd);
|
|
|
+ emailInfoDTO.setHost("imap.exmail.qq.com");
|
|
|
+ emailInfoDTO.setPort("993");
|
|
|
+ emailInfoDTO.setProtocol("imap");
|
|
|
+ return emailInfoDTO;
|
|
|
+ }
|
|
|
//
|
|
|
-//
|
|
|
-// /**
|
|
|
-// * 得到文件名称
|
|
|
-// *
|
|
|
-// * @param path 路径
|
|
|
-// * @return {@link List}<{@link String}>
|
|
|
-// */
|
|
|
-// private static List<String> getFileNames(String path) {
|
|
|
-// File file = new File(path);
|
|
|
-// if (!file.exists()) {
|
|
|
-// return null;
|
|
|
-// }
|
|
|
-// List<String> fileNames = new ArrayList<>();
|
|
|
-// return getFileNames(file, fileNames);
|
|
|
-// }
|
|
|
-//
|
|
|
-// /**
|
|
|
-// * 得到文件名称
|
|
|
-// *
|
|
|
-// * @param file 文件
|
|
|
-// * @param fileNames 文件名
|
|
|
-// * @return {@link List}<{@link String}>
|
|
|
-// */
|
|
|
-// private static List<String> getFileNames(File file, List<String> fileNames) {
|
|
|
-// File[] files = file.listFiles();
|
|
|
-// for (File f : files) {
|
|
|
-// if (f.isDirectory()) {
|
|
|
-// getFileNames(f, fileNames);
|
|
|
-// } else {
|
|
|
-// fileNames.add(f.getName());
|
|
|
-// }
|
|
|
-// }
|
|
|
-// return fileNames;
|
|
|
-// }
|
|
|
-//
|
|
|
-// public static int getPercent2(float h, float w) {
|
|
|
-// int p = 0;
|
|
|
-// float p2 = 0.0f;
|
|
|
-// p2 = 450 / w * 100;
|
|
|
-// p = Math.round(p2);
|
|
|
-// return p;
|
|
|
-// }
|
|
|
-//}
|
|
|
+// @Autowired
|
|
|
+// private StringEncryptor stringEncryptor;
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void encrypt() {
|
|
|
+ StandardPBEStringEncryptor stringEncryptor = new StandardPBEStringEncryptor();
|
|
|
+ stringEncryptor.setAlgorithm("PBEWithMD5AndDES");
|
|
|
+ stringEncryptor.setPassword("123456qwertyasdfghzxcvbn");
|
|
|
+ stringEncryptor.setIvGenerator(new RandomIvGenerator());
|
|
|
+ String name = stringEncryptor.encrypt("PPW_EMAIL");
|
|
|
+ String password = stringEncryptor.encrypt("Dmppw2024");
|
|
|
+ System.out.println("database username: " + name);
|
|
|
+ System.out.println("database password: " + password);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 得到文件名称
|
|
|
+ *
|
|
|
+ * @param path 路径
|
|
|
+ * @return {@link List}<{@link String}>
|
|
|
+ */
|
|
|
+ private static List<String> getFileNames(String path) {
|
|
|
+ File file = new File(path);
|
|
|
+ if (!file.exists()) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ List<String> fileNames = new ArrayList<>();
|
|
|
+ return getFileNames(file, fileNames);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 得到文件名称
|
|
|
+ *
|
|
|
+ * @param file 文件
|
|
|
+ * @param fileNames 文件名
|
|
|
+ * @return {@link List}<{@link String}>
|
|
|
+ */
|
|
|
+ private static List<String> getFileNames(File file, List<String> fileNames) {
|
|
|
+ File[] files = file.listFiles();
|
|
|
+ for (File f : files) {
|
|
|
+ if (f.isDirectory()) {
|
|
|
+ getFileNames(f, fileNames);
|
|
|
+ } else {
|
|
|
+ fileNames.add(f.getName());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return fileNames;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static int getPercent2(float h, float w) {
|
|
|
+ int p = 0;
|
|
|
+ float p2 = 0.0f;
|
|
|
+ p2 = 450 / w * 100;
|
|
|
+ p = Math.round(p2);
|
|
|
+ return p;
|
|
|
+ }
|
|
|
+}
|