diff --git a/eladmin-system/pom.xml b/eladmin-system/pom.xml index 9ad3b09..fc66362 100644 --- a/eladmin-system/pom.xml +++ b/eladmin-system/pom.xml @@ -63,6 +63,12 @@ 1.1.0 + + com.google.guava + guava + 22.0 + + io.jsonwebtoken diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/uploadnew/service/impl/TbUploadFileNewServiceImpl.java b/eladmin-system/src/main/java/me/zhengjie/modules/uploadnew/service/impl/TbUploadFileNewServiceImpl.java index 7e38ded..6474d18 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/uploadnew/service/impl/TbUploadFileNewServiceImpl.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/uploadnew/service/impl/TbUploadFileNewServiceImpl.java @@ -189,7 +189,7 @@ public class TbUploadFileNewServiceImpl implements TbUploadFileNewService { break; case FileConstant.CSV_FILE_SUB_NAME: fileFormat = "csv文件"; - count = ToolExcelUtils.countSizeByUrl(eachFilePath); + count = ToolExcelUtils.countSizeByCsv(eachFilePath); break; default: } diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/uploadnew/task/SaveToFileNewTask.java b/eladmin-system/src/main/java/me/zhengjie/modules/uploadnew/task/SaveToFileNewTask.java index 7289fb1..3fd8fc1 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/uploadnew/task/SaveToFileNewTask.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/uploadnew/task/SaveToFileNewTask.java @@ -152,11 +152,11 @@ public class SaveToFileNewTask { private int handleEachFileContent(String filePath, TbUploadFileNewDto tbUploadFileNewDto) { List phoneList = Lists.newArrayList(); - + String fileFormat = tbUploadFileNewDto.getFileFormat(); //根据文件类型进行解析 - List listT = tbUploadFileNewDto.getFileFormat().contains(FileConstant.TXT_FILE_SUB_NAME) ? - TxtUtils.txtParseListVyUrl(filePath) : - ToolExcelUtils.excelParseListByUrl(filePath); + List listT = fileFormat.contains(FileConstant.TXT_FILE_SUB_NAME) ? + TxtUtils.txtParseListVyUrl(filePath) : fileFormat.contains(FileConstant.CSV_FILE_SUB_NAME) + ? ToolExcelUtils.csvParseListByUrl(filePath) : ToolExcelUtils.excelParseListByUrl(filePath); Map> preEncryptNumMap = listT.stream().filter (phone -> phone.trim().getBytes(StandardCharsets.UTF_8).length == DefaultConstant.ELEVEN_NUMBER) @@ -164,7 +164,7 @@ public class SaveToFileNewTask { if (CollectionUtil.isNotEmpty(preEncryptNumMap)) { // 分批调用接口进行加密 List list = preEncryptNumMap.get(PRE_SEND_NUM_LENGTH); - phoneList = Lists.newArrayList(Sets.newHashSet(list)); + phoneList = Lists.newArrayList(Sets.newHashSet(list)); if (CollectionUtil.isNotEmpty(phoneList)) { batchSendToEncrypt(filePath, phoneList); } diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/uploadnew/task/SendMessageTask.java b/eladmin-system/src/main/java/me/zhengjie/modules/uploadnew/task/SendMessageTask.java index fd7376d..78afe63 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/uploadnew/task/SendMessageTask.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/uploadnew/task/SendMessageTask.java @@ -93,8 +93,8 @@ public class SendMessageTask { String fileFormat, SmsConfigurationDto smsConfigurationDto) { //根据文件类型进行解析 List list = fileFormat.contains(FileConstant.TXT_FILE_SUB_NAME) ? - TxtUtils.txtParseListVyUrl(filePath) : - ToolExcelUtils.excelParseListByUrl(filePath); + TxtUtils.txtParseListVyUrl(filePath) : fileFormat.contains(FileConstant.CSV_FILE_SUB_NAME) + ? ToolExcelUtils.csvParseListByUrl(filePath) : ToolExcelUtils.excelParseListByUrl(filePath); if (!CollectionUtils.isEmpty(list)) { List stringList = list.stream().filter diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/uploadnew/util/ToolExcelUtils.java b/eladmin-system/src/main/java/me/zhengjie/modules/uploadnew/util/ToolExcelUtils.java index 0094d42..17a6933 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/uploadnew/util/ToolExcelUtils.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/uploadnew/util/ToolExcelUtils.java @@ -1,8 +1,11 @@ package me.zhengjie.modules.uploadnew.util; -import cn.hutool.core.util.StrUtil; +import cn.hutool.core.text.csv.CsvData; +import cn.hutool.core.text.csv.CsvReader; +import cn.hutool.core.text.csv.CsvUtil; import cn.hutool.poi.excel.ExcelReader; import cn.hutool.poi.excel.ExcelUtil; +import com.google.common.collect.Lists; import lombok.extern.slf4j.Slf4j; import me.zhengjie.modules.constant.DefaultConstant; import org.apache.commons.collections4.CollectionUtils; @@ -42,4 +45,28 @@ public class ToolExcelUtils { return DefaultConstant.ZERO_NUMBER; } + + public static int countSizeByCsv(String fileUrl) { + CsvReader reader = CsvUtil.getReader(); + // 解析文件 + CsvData data = reader.read(cn.hutool.core.io.FileUtil.file(fileUrl)); + if (CollectionUtils.isNotEmpty(data.getRows())) { + return data.getRows().size(); + } + return DefaultConstant.ZERO_NUMBER; + } + + + public static List csvParseListByUrl(String fileUrl) { + List list = Lists.newArrayList(); + CsvReader reader = CsvUtil.getReader(); + // 解析文件 + CsvData data = reader.read(cn.hutool.core.io.FileUtil.file(fileUrl)); + if (CollectionUtils.isNotEmpty(data.getRows())) { + data.getRows().forEach(clue -> list.add + (clue.get(DefaultConstant.ZERO_NUMBER))); + } + return list; + } + } diff --git a/eladmin-system/src/test/java/me/zhengjie/CategorizeTest.java b/eladmin-system/src/test/java/me/zhengjie/CategorizeTest.java new file mode 100644 index 0000000..1bba59d --- /dev/null +++ b/eladmin-system/src/test/java/me/zhengjie/CategorizeTest.java @@ -0,0 +1,70 @@ +package me.zhengjie; + +import cn.hutool.poi.excel.ExcelUtil; +import cn.hutool.poi.excel.ExcelWriter; +import com.google.common.collect.Lists; +import com.google.common.collect.Sets; +import me.zhengjie.modules.constant.DefaultConstant; +import me.zhengjie.modules.uploadnew.util.ExcelUtils; +import me.zhengjie.modules.uploadnew.util.ToolExcelUtils; +import me.zhengjie.modules.uploadnew.util.TxtUtils; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +/** + * @author Enzo + * @date : 2022/5/5 + */ +public class CategorizeTest { + public static List getAllFile(String directoryPath,boolean isAddDirectory) { + List list = new ArrayList(); + File baseFile = new File(directoryPath); + if (baseFile.isFile() || !baseFile.exists()) { + return list; + } + File[] files = baseFile.listFiles(); + for (File file : files) { + if (file.isDirectory() && !file.getAbsolutePath().equals("xyk")) { + + list.addAll(getAllFile(file.getAbsolutePath(),isAddDirectory)); + } else { + list.add(file.getAbsolutePath()); + } + } + return list; + } + public static void main(String[] args) throws IOException { + List allFile = getAllFile("F:\\新建文件夹\\电销名单", true); + + List resultList = Lists.newArrayList(); + + for (String value : allFile) { + if (value.endsWith("xls") || value.endsWith("xlsx") ){ + List strings = ToolExcelUtils.excelParseListByUrl(value); + resultList.addAll(strings); + } + } + List strings = Lists.newArrayList(Sets.newHashSet(resultList)); + + int i = strings.size() / 600000; + + for (int j = 0; j < i + 1; j++) { + // 通过工具类创建writer + ExcelWriter chinaWriter = ExcelUtil.getBigWriter("C:\\Users\\a\\Desktop\\号码" + (j + 1) + ".xlsx"); + + //todo 设置自动换行(时间) + chinaWriter.setColumnWidth(4, 25); + // 一次性写出内容,使用默认样式,强制输出标题 + chinaWriter.write(strings.subList(j * 600000, Math.min((j + 1) * 600000, strings.size())), true); + // 关闭writer,释放内存 + chinaWriter.close(); + } + + } + +} diff --git a/eladmin-system/src/test/java/me/zhengjie/DemoTest.java b/eladmin-system/src/test/java/me/zhengjie/DemoTest.java index a10cac4..e5b9130 100644 --- a/eladmin-system/src/test/java/me/zhengjie/DemoTest.java +++ b/eladmin-system/src/test/java/me/zhengjie/DemoTest.java @@ -1,18 +1,63 @@ package me.zhengjie; import cn.hutool.core.util.RandomUtil; +import cn.hutool.poi.excel.ExcelReader; +import cn.hutool.poi.excel.ExcelUtil; +import cn.hutool.poi.excel.ExcelWriter; +import me.zhengjie.modules.constant.DefaultConstant; +import me.zhengjie.modules.uploadnew.util.ExcelUtils; +import me.zhengjie.modules.uploadnew.util.ToolExcelUtils; import me.zhengjie.utils.FileUtil; +import org.apache.commons.collections4.CollectionUtils; import org.junit.After; import org.junit.Before; import org.junit.Test; import java.io.File; +import java.util.ArrayList; import java.util.HashSet; +import java.util.List; import java.util.Set; +import java.util.regex.Pattern; public class DemoTest { + public static void main(String[] args) { + List list = new ArrayList<>(); + String s = "C:\\Users\\a\\Desktop\\客户信息2(1)(1).xlsx"; + ExcelReader reader = ExcelUtil.getReader(cn.hutool.core.io.FileUtil.file(s)); + + if (CollectionUtils.isNotEmpty(reader.read())) { + for (List objects : reader.read()) { + String phone = objects.toString(); + if (phone.indexOf("1") > -1 && phone.indexOf("1") + 11 < phone.length()) { + String substring = phone.substring(phone.indexOf("1"), phone.indexOf("1") + 11); + if (isNumeric(substring)) { + list.add(substring); + } + } + } + } + // 通过工具类创建writer + ExcelWriter unicomWriter = ExcelUtil.getBigWriter("C:\\Users\\a\\Desktop\\号码.xlsx"); + + //todo 设置自动换行(时间) + unicomWriter.setColumnWidth(4, 25); + // 一次性写出内容,使用默认样式,强制输出标题 + unicomWriter.write(list, true); + // 关闭writer,释放内存 + unicomWriter.close(); + + } + + public static boolean isNumeric(String str){ + + Pattern pattern = Pattern.compile("[0-9]*"); + + return pattern.matcher(str).matches(); + + } @Before public void be(){ // TODO: 2021/5/7 0007 dc1 dc2 ... diff --git a/eladmin-system/src/test/java/me/zhengjie/EladminSystemApplicationTests.java b/eladmin-system/src/test/java/me/zhengjie/EladminSystemApplicationTests.java index 45d5212..a983cf4 100644 --- a/eladmin-system/src/test/java/me/zhengjie/EladminSystemApplicationTests.java +++ b/eladmin-system/src/test/java/me/zhengjie/EladminSystemApplicationTests.java @@ -1,10 +1,22 @@ package me.zhengjie; +import cn.hutool.poi.excel.ExcelUtil; +import cn.hutool.poi.excel.ExcelWriter; +import com.google.common.collect.Sets; +import me.zhengjie.modules.constant.DefaultConstant; +import me.zhengjie.modules.uploadnew.util.CheckPhone; +import me.zhengjie.modules.uploadnew.util.TxtUtils; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; + @RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) public class EladminSystemApplicationTests { @@ -13,7 +25,82 @@ public class EladminSystemApplicationTests { public void contextLoads() { } - public static void main(String[] args) { + + + + + public static void main(String[] args) throws IOException { + List list = new ArrayList<>(); + list.add("C:\\Users\\a\\Desktop\\202011.txt"); + List resultList = new ArrayList<>(); + for (String value : list) { + List strings = TxtUtils.txtParseListVyUrl(value); + for (String phone : strings) { + if (phone.length() > DefaultConstant.ELEVEN_NUMBER) { + if (phone.length() == DefaultConstant.THIRTEEN_NUMBER) { + resultList.add(phone.substring(DefaultConstant.ONE_NUMBER, DefaultConstant.TWELVE_NUMBER)); + } + if (phone.length() > 16 && phone.indexOf("1") > 0 && phone.indexOf("1") + 11 < phone.length() - 1) { + resultList.add(phone.substring(phone.indexOf("1"), phone.indexOf("1") + 11)); + } + } + } + } + HashSet strings = Sets.newHashSet(resultList); + + List china = new ArrayList<>(); + List unicom = new ArrayList<>(); + List telecommunications = new ArrayList<>(); + for (String s : strings) { + if (s.length() == 11) { + if (CheckPhone.isChinaMobilePhoneNum(s)) { + china.add(s); + } + if (CheckPhone.isChinaUnicomPhoneNum(s)) { + unicom.add(s); + } + if (CheckPhone.isChinaTelecomPhoneNum(s)) { + telecommunications.add(s); + } + } + } + + int i = china.size() / 600000; + + for (int j = 0; j < i + 1; j++) { + // 通过工具类创建writer + ExcelWriter chinaWriter = ExcelUtil.getBigWriter("C:\\Users\\a\\Desktop\\移动" + (j + 1) + ".xlsx"); + + //todo 设置自动换行(时间) + chinaWriter.setColumnWidth(4, 25); + // 一次性写出内容,使用默认样式,强制输出标题 + chinaWriter.write(china.subList(j * 600000, Math.min((j + 1) * 600000, china.size())), true); + // 关闭writer,释放内存 + chinaWriter.close(); + } + + + + // 通过工具类创建writer + ExcelWriter unicomWriter = ExcelUtil.getBigWriter("C:\\Users\\a\\Desktop\\联通.xlsx"); + + //todo 设置自动换行(时间) + unicomWriter.setColumnWidth(4, 25); + // 一次性写出内容,使用默认样式,强制输出标题 + unicomWriter.write(unicom, true); + // 关闭writer,释放内存 + unicomWriter.close(); + + + // 通过工具类创建writer + ExcelWriter telecommunicationsWriter = ExcelUtil.getBigWriter("C:\\Users\\a\\Desktop\\电信.xlsx"); + + //todo 设置自动换行(时间) + telecommunicationsWriter.setColumnWidth(4, 25); + // 一次性写出内容,使用默认样式,强制输出标题 + telecommunicationsWriter.write(telecommunications, true); + // 关闭writer,释放内存 + telecommunicationsWriter.close(); } } diff --git a/eladmin-system/src/test/java/me/zhengjie/SimpleTest.java b/eladmin-system/src/test/java/me/zhengjie/SimpleTest.java index d55dd0a..f6f62da 100644 --- a/eladmin-system/src/test/java/me/zhengjie/SimpleTest.java +++ b/eladmin-system/src/test/java/me/zhengjie/SimpleTest.java @@ -7,7 +7,12 @@ import cn.hutool.extra.ssh.JschUtil; import cn.hutool.extra.ssh.Sftp; import cn.hutool.http.HttpRequest; import cn.hutool.http.HttpResponse; +import cn.hutool.poi.excel.ExcelReader; +import cn.hutool.poi.excel.ExcelUtil; +import com.alipay.api.domain.Person; import com.jcraft.jsch.Session; +import me.zhengjie.modules.uploadnew.util.ExcelUtils; +import me.zhengjie.modules.uploadnew.util.ToolExcelUtils; import me.zhengjie.utils.DateUtil; import me.zhengjie.utils.FileUtil; import me.zhengjie.utils.StringUtils; @@ -177,10 +182,12 @@ public class SimpleTest { public static void main(String[] args) { - /*SimpleTest simpleTest = new SimpleTest(); - for (int i = 0; i < 5; i++) { - simpleTest.testFtpTransDownload(i); - }*/ + List strings = ToolExcelUtils.excelParseListByUrl("F:\\新建文件夹\\电销名单\\123456\\123123\\chenlei1\\萧山\\恒园公寓(萧山经济开发区)1266 (1).xlsx"); + + for (String string : strings) { + System.out.println(string); + } + } diff --git a/eladmin-system/src/test/java/me/zhengjie/TestEncryptInter.java b/eladmin-system/src/test/java/me/zhengjie/TestEncryptInter.java index 1aa19dd..7fd33b0 100644 --- a/eladmin-system/src/test/java/me/zhengjie/TestEncryptInter.java +++ b/eladmin-system/src/test/java/me/zhengjie/TestEncryptInter.java @@ -9,8 +9,7 @@ import cn.hutool.http.HttpUtil; import cn.hutool.json.JSONUtil; import com.alibaba.fastjson.JSON; import lombok.extern.slf4j.Slf4j; -import me.zhengjie.constant.SmsConstant; -import me.zhengjie.modules.sms.dto.ShortLinkUrlDto; +import me.zhengjie.modules.system.domain.sms.dto.ShortLinkUrlDto; import me.zhengjie.modules.upload.task.model.SendEncryptJsonContent; import me.zhengjie.utils.DateUtil; import me.zhengjie.utils.StringUtils; @@ -120,15 +119,9 @@ public class TestEncryptInter { @Test public void sendSms() { Map map = new HashMap<>(2); - map.put("baseUrlAddr", "https://www.xueersi.com/wx.php?source=594699300&site_id=5421&adsite_id=14838328"); - List list = new ArrayList(); - list.add("13586541001"); - map.put("variableList", list); - for (int i = 0; i < 10; i++) { - ShortLinkUrlDto urlDto = JSONUtil.toBean(HttpUtil.post(SmsConstant.SHORT_GENERATION_LINK, JSON.toJSONString(map)), ShortLinkUrlDto.class); - System.out.println(JSON.toJSONString(urlDto)); - - } + map.put("baseUrlAddr", "http://zw.juqianfw.com/"); + ShortLinkUrlDto urlDto = JSONUtil.toBean(HttpUtil.post("s.z48.cn/trans", JSON.toJSONString(map)), ShortLinkUrlDto.class); + System.out.println(JSON.toJSONString(urlDto)); } @Test diff --git a/eladmin-system/src/test/java/me/zhengjie/TxtDemo.java b/eladmin-system/src/test/java/me/zhengjie/TxtDemo.java new file mode 100644 index 0000000..c71fd75 --- /dev/null +++ b/eladmin-system/src/test/java/me/zhengjie/TxtDemo.java @@ -0,0 +1,43 @@ +package me.zhengjie; + +import cn.hutool.poi.excel.ExcelReader; +import cn.hutool.poi.excel.ExcelUtil; +import com.google.common.collect.Lists; +import com.google.common.collect.Sets; +import lombok.extern.slf4j.Slf4j; +import me.zhengjie.modules.uploadnew.util.TxtUtils; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; + +/** + * @author Enzo + * @date : 2022/4/11 + */ +@Slf4j +public class TxtDemo { + public static void main(String[] args) { + String s = "C:\\Users\\a\\Desktop\\正装.txt"; + + try { + List strings = TxtUtils.txtParseListVyUrl(s); + HashSet strings1 = Sets.newHashSet(strings); + + List list = Lists.newArrayList(); + strings1.forEach(phone ->{ + System.out.println("the phone length as {}"+phone.length()); + + if (phone.length() == 11) { + list.add(phone); + } + }); + System.out.println(list.size()); + } catch (IOException e) { + e.printStackTrace(); + } + + + } +}