Commit 09d9128e authored by 丁强's avatar 丁强

提交模拟数据代码

parent 7a48441d
Pipeline #518 canceled with stages
*.class
# Package Files #
*.jar
*.war
*.ear
build/*
target/*
**/build/*
**/target/*
out/*
**/out/*
**/.idea/workspace.xml
**/.idea/tasks.xml
### Intellij ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm
*.iml
.idea/**
## File-based project format:
*.ipr
*.iws
### 建议使用本地gradle,服务器环境中也需要安装gradle
**/.gradle/*
**/gradle/*
gradlew*
**/target/**
**/._.DS_Store
**/*.bak
**/*.log
!/lib/*.jar
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>cn.quantgroup</groupId>
<artifactId>mock-neo4j-data</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
</properties>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.2.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-io</artifactId>
<version>1.3.2</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
package cn.quantgroup;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
This diff is collapsed.
package cn.quantgroup.mock;
import org.apache.commons.io.IOUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
import java.io.File;
import java.io.FileOutputStream;
import java.util.*;
/**
* @author Aladdin(qiang.ding)
* @date 2020/4/16
*/
@Component
public class MockData {
@Value("${header.user}")
private String userHeader;
@Value("${header.order}")
private String orderHeader;
@Value("${path.data}")
private String dataPath;
@Value("${totalCount}")
private int totalCount;
private static final List<String> PHONE_SET = new ArrayList<>(1000000);
static {
for (int i = 1000000; i < 2000000; i++) {
PHONE_SET.add("1512" + i);
}
}
@PostConstruct
public void mockData() {
try {
File user = new File(dataPath + "user.csv");
FileOutputStream userOutputStream = new FileOutputStream(user, true);
IOUtils.write(userHeader, userOutputStream);
IOUtils.write("\n", userOutputStream);
IOUtils.writeLines(PHONE_SET, null, userOutputStream);
File order = new File(dataPath + "order.csv");
FileOutputStream orderOutputStream = new FileOutputStream(order, true);
IOUtils.write(orderHeader, orderOutputStream);
IOUtils.write("\n", orderOutputStream);
List<String> orders = new LinkedList<>();
Random ran = new Random();
for (int i = 0; i < totalCount; i++) {
String orderPhone = PHONE_SET.get(i % PHONE_SET.size());
String receiverPhone = PHONE_SET.get(ran.nextInt(PHONE_SET.size()));
String orderId = UUID.randomUUID().toString();
long t = ran.nextInt((int)(DateUtil.ONE_YEAR / 1000)) * 1000L + 1555171200000L;
String orderTime = DateUtil.format(new Date(t));
String orderStatus = i % 3 + "";
orders.add(orderPhone + "," + receiverPhone + "," + orderId + "," + orderTime + "," + orderStatus);
}
IOUtils.writeLines(orders, null, orderOutputStream);
System.out.println("数据生成完毕。");
System.exit(0);
} catch (Exception e) {
e.printStackTrace();
System.exit(1);
}
}
}
mvn clean package --offline
scp target/remote-hdfs-1.0-SNAPSHOT.jar sysapp@172.18.3.97:~/
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment