任务生成封版
parent
ca9cdafe4b
commit
2d7aca22d2
@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"properties": [
|
||||||
|
{
|
||||||
|
"name": "spring.datasource.druid.db-type",
|
||||||
|
"type": "java.lang.String",
|
||||||
|
"description": "Description for spring.datasource.druid.db-type."
|
||||||
|
}
|
||||||
|
] }
|
@ -0,0 +1,158 @@
|
|||||||
|
package me.zhengjie;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.RandomUtil;
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
|
import me.zhengjie.utils.FileUtil;
|
||||||
|
import me.zhengjie.utils.StringUtils;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
import java.nio.file.StandardOpenOption;
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import static java.util.stream.Collectors.toList;
|
||||||
|
|
||||||
|
public class FileTest {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// 去重
|
||||||
|
// 按长度分开
|
||||||
|
// 去掉“
|
||||||
|
// 去11位手机号
|
||||||
|
// 打乱,平均分15个包
|
||||||
|
@Test
|
||||||
|
public void testMerge() throws IOException {
|
||||||
|
// 读取文件
|
||||||
|
String path1 = "K:\\253.txt";
|
||||||
|
String path2 = "K:\\254.txt";
|
||||||
|
List<String> stringList = Files.readAllLines(Paths.get(path2));
|
||||||
|
List<String> list1 = new ArrayList<>();
|
||||||
|
List<String> list2 = new ArrayList<>();
|
||||||
|
stringList.forEach(
|
||||||
|
one->{
|
||||||
|
one = StringUtils.replace(one, "\"","");
|
||||||
|
if (one.length() == 32){
|
||||||
|
list1.add(one);
|
||||||
|
}else if (one.length() == 24){
|
||||||
|
list2.add(one);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
Files.write(Paths.get("K:\\merge1.txt"),list1, StandardOpenOption.APPEND);
|
||||||
|
Files.write(Paths.get("K:\\merge2.txt"),list2, StandardOpenOption.APPEND);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSplit() throws IOException {
|
||||||
|
String path = "K:\\merge1.txt";
|
||||||
|
List<String> stringList = Files.readAllLines(Paths.get(path));
|
||||||
|
|
||||||
|
List<String> list1 = Lists.newArrayList();
|
||||||
|
List<String> list2 = Lists.newArrayList();
|
||||||
|
List<String> list3 = Lists.newArrayList();
|
||||||
|
List<String> list4 = Lists.newArrayList();
|
||||||
|
List<String> list5 = Lists.newArrayList();
|
||||||
|
List<String> list6 = Lists.newArrayList();
|
||||||
|
List<String> list7 = Lists.newArrayList();
|
||||||
|
List<String> list8 = Lists.newArrayList();
|
||||||
|
List<String> list9 = Lists.newArrayList();
|
||||||
|
List<String> list10 = Lists.newArrayList();
|
||||||
|
|
||||||
|
Map<Integer, List<String>> map = new HashMap<>();
|
||||||
|
map.put(0,list1);
|
||||||
|
map.put(1,list2);
|
||||||
|
map.put(2,list3);
|
||||||
|
map.put(3,list4);
|
||||||
|
map.put(4,list5);
|
||||||
|
map.put(5,list6);
|
||||||
|
map.put(6,list7);
|
||||||
|
map.put(7,list8);
|
||||||
|
map.put(8,list9);
|
||||||
|
map.put(9,list10);
|
||||||
|
|
||||||
|
// 随机加入到list中
|
||||||
|
stringList.forEach(
|
||||||
|
one->{
|
||||||
|
int i = RandomUtil.randomInt(10);
|
||||||
|
List<String> stringList1 = map.get(i);
|
||||||
|
stringList1.add(one);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
for (int i = 0; i < 10; i++) {
|
||||||
|
List<String> resultList = map.get(i);
|
||||||
|
Files.write(Paths.get("K:\\result"+i),resultList,StandardOpenOption.CREATE);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void splitEachFile() throws IOException {
|
||||||
|
List<String> list = Files.readAllLines(Paths.get("J:\\111.6w.csv"));
|
||||||
|
List<KVBean> objects = Lists.newArrayList();
|
||||||
|
list.forEach(
|
||||||
|
one ->{
|
||||||
|
String[] split = StringUtils.split(one, ",");
|
||||||
|
if (split.length == 2){
|
||||||
|
KVBean kvBean = new KVBean();
|
||||||
|
kvBean.setK(split[0].trim().replaceAll("\"",""));
|
||||||
|
kvBean.setV(split[1].trim().replaceAll("\"",""));
|
||||||
|
objects.add(kvBean);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
Map<String, Set<String>> collect = objects.stream()
|
||||||
|
.collect(Collectors.groupingBy(KVBean::getK, Collectors.mapping(KVBean::getV, Collectors.toSet())));
|
||||||
|
|
||||||
|
collect.forEach(
|
||||||
|
(key,value)->{
|
||||||
|
try {
|
||||||
|
Files.write(Paths.get("J:\\" + key), value, StandardOpenOption.CREATE);
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testFilterTwoList(){
|
||||||
|
|
||||||
|
List<String> list1 = new ArrayList<>();
|
||||||
|
list1.add("1");
|
||||||
|
list1.add("2");
|
||||||
|
list1.add("3");
|
||||||
|
list1.add("5");
|
||||||
|
list1.add("6");
|
||||||
|
|
||||||
|
List<String> list2 = new ArrayList<>();
|
||||||
|
list2.add("2");
|
||||||
|
list2.add("3");
|
||||||
|
list2.add("7");
|
||||||
|
list2.add("8");
|
||||||
|
|
||||||
|
|
||||||
|
// 并集
|
||||||
|
List<String> listAll = list1.parallelStream().collect(toList());
|
||||||
|
List<String> listAll2 = list2.parallelStream().collect(toList());
|
||||||
|
listAll.addAll(listAll2);
|
||||||
|
/* System.out.println("---得到并集 listAll---");
|
||||||
|
listAll.parallelStream().forEach(System.out :: println);*/
|
||||||
|
// 去重并集
|
||||||
|
List<String> listAllDistinct = listAll.stream().distinct().collect(toList());
|
||||||
|
System.out.println("---得到去重并集 listAllDistinct---");
|
||||||
|
listAllDistinct.parallelStream().forEachOrdered(System.out :: println);
|
||||||
|
|
||||||
|
System.out.println("---原来的List1---");
|
||||||
|
list1.parallelStream().forEachOrdered(System.out :: println);
|
||||||
|
System.out.println("---原来的List2---");
|
||||||
|
list2.parallelStream().forEachOrdered(System.out :: println);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,37 @@
|
|||||||
|
package me.zhengjie;
|
||||||
|
|
||||||
|
import cn.hutool.json.JSON;
|
||||||
|
import cn.hutool.json.JSONArray;
|
||||||
|
import cn.hutool.json.JSONObject;
|
||||||
|
import cn.hutool.json.JSONUtil;
|
||||||
|
import me.zhengjie.modules.buildrecord.task.convert.BuildTaskQueryParamJsonConvert;
|
||||||
|
import org.assertj.core.util.Lists;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class JsonTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testJsonPase(){
|
||||||
|
BuildTaskQueryParamJsonConvert convert = new BuildTaskQueryParamJsonConvert();
|
||||||
|
convert.setCityCode(Lists.newArrayList(1,2));
|
||||||
|
convert.setStuGrade(Lists.newArrayList(1,3));
|
||||||
|
convert.setRange(2);
|
||||||
|
convert.setLocalCode("5.0,5.0");
|
||||||
|
JSON parse = JSONUtil.parse(convert);
|
||||||
|
System.out.println(parse.toString());
|
||||||
|
|
||||||
|
|
||||||
|
String str = "{\"cityCode\":[1,2],\"range\":2,\"localCode\":\"5.0,5.0\",\"stuGrade\":[1,3]}";
|
||||||
|
JSONObject jsonObject1 = JSONUtil.parseObj(str);
|
||||||
|
System.out.println(jsonObject1);
|
||||||
|
BuildTaskQueryParamJsonConvert convert1 = JSONUtil.toBean(jsonObject1, BuildTaskQueryParamJsonConvert.class);
|
||||||
|
System.out.println(convert1);
|
||||||
|
// JSONArray objects = JSONUtil.parseArray(str);
|
||||||
|
// System.out.println(objects);
|
||||||
|
//
|
||||||
|
// JSONObject jsonObject = JSONUtil.parseObj(str);
|
||||||
|
// System.out.println(jsonObject);
|
||||||
|
// BuildTaskQueryParamJsonConvert convert1 = JSONUtil.toBean(jsonObject, BuildTaskQueryParamJsonConvert.class);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,10 @@
|
|||||||
|
package me.zhengjie;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class KVBean {
|
||||||
|
private String k;
|
||||||
|
|
||||||
|
private String v;
|
||||||
|
}
|
Loading…
Reference in New Issue