修改csv格式

master
bynt 2 years ago
parent 2cb96e3f5a
commit 6896f83855

@ -63,6 +63,12 @@
<version>1.1.0</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>22.0</version>
</dependency>
<!-- jwt -->
<dependency>
<groupId>io.jsonwebtoken</groupId>

@ -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:
}

@ -152,11 +152,11 @@ public class SaveToFileNewTask {
private int handleEachFileContent(String filePath, TbUploadFileNewDto tbUploadFileNewDto) {
List<String> phoneList = Lists.newArrayList();
String fileFormat = tbUploadFileNewDto.getFileFormat();
//根据文件类型进行解析
List<String> listT = tbUploadFileNewDto.getFileFormat().contains(FileConstant.TXT_FILE_SUB_NAME) ?
TxtUtils.txtParseListVyUrl(filePath) :
ToolExcelUtils.excelParseListByUrl(filePath);
List<String> 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<Integer, List<String>> preEncryptNumMap = listT.stream().filter
(phone -> phone.trim().getBytes(StandardCharsets.UTF_8).length == DefaultConstant.ELEVEN_NUMBER)

@ -93,8 +93,8 @@ public class SendMessageTask {
String fileFormat, SmsConfigurationDto smsConfigurationDto) {
//根据文件类型进行解析
List<String> 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<String> stringList = list.stream().filter

@ -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<String> csvParseListByUrl(String fileUrl) {
List<String> 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;
}
}

@ -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<String> getAllFile(String directoryPath,boolean isAddDirectory) {
List<String> list = new ArrayList<String>();
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<String> allFile = getAllFile("F:\\新建文件夹\\电销名单", true);
List<String> resultList = Lists.newArrayList();
for (String value : allFile) {
if (value.endsWith("xls") || value.endsWith("xlsx") ){
List<String> strings = ToolExcelUtils.excelParseListByUrl(value);
resultList.addAll(strings);
}
}
List<String> 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();
}
}
}

@ -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<String> 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<Object> 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 ...

@ -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<String> list = new ArrayList<>();
list.add("C:\\Users\\a\\Desktop\\202011.txt");
List<String> resultList = new ArrayList<>();
for (String value : list) {
List<String> 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<String> strings = Sets.newHashSet(resultList);
List<String> china = new ArrayList<>();
List<String> unicom = new ArrayList<>();
List<String> 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();
}
}

@ -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<String> strings = ToolExcelUtils.excelParseListByUrl("F:\\新建文件夹\\电销名单\\123456\\123123\\chenlei1\\萧山\\恒园公寓萧山经济开发区1266 (1).xlsx");
for (String string : strings) {
System.out.println(string);
}
}

@ -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<String, Object> map = new HashMap<>(2);
map.put("baseUrlAddr", "https://www.xueersi.com/wx.php?source=594699300&site_id=5421&adsite_id=14838328");
List<String> 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);
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

@ -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<String> strings = TxtUtils.txtParseListVyUrl(s);
HashSet<String> strings1 = Sets.newHashSet(strings);
List<String> 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();
}
}
}
Loading…
Cancel
Save