整个项目是仿照尚硅谷的电信项目案例的简化版,是由自己的编的代码,所以在代码的整体逻辑上比尚硅谷课程的代码差一些。不过可以有借鉴
整体项目的数据流
数据生产模块
生产数据模拟电信日志
数据列为:主叫,被叫,通话时间点,通话分钟数
数据生成代码
package com.sl;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
public class DateCreate
{
public static void main(String[] args) throws IOException
{
FileWriter fw = new FileWriter(new File("E:/a.txt"),true);
Num_book nb = new Num_book();
for (int i = 0; i < 60; i++)
{
String line = nb.getFirstNum()+"\t"+nb.getSecondNum()+"\t"+MyDate.getFirstTime()+"\t"+MyDate.getMin()+"\n";
System.out.println(line);
fw.append(line);
fw.flush();
}
fw.close();
}
}
class Num_book
{
int temp = -1;
String[] num = new String[20];
{
num[0] = "14036178412";
num[1] = "13242820024";
num[2] = "16386074226";
num[3] = "13943139492";
num[4] = "18714767399";
num[5] = "14733819877";
num[6] = "13351126401";
num[7] = "13017498589";
num[8] = "16058589347";
num[9] = "18949811796";
num[10] = "13558773808";
num[11] = "14343683320";
num[12] = "13242820024";
num[13] = "13465110157";
num[14] = "15382018060";
num[15] = "13231085347";
num[16] = "13938679959";
num[17] = "13779982232";
num[18] = "18144784030";
num[19] = "18637946280";
}
public int num_Random()
{
int num_Random =1;
num_Random= (int) (Math.random()*num.length);
return num_Random;
}
public String getFirstNum()
{
int firsNum = num_Random();
temp = firsNum;
return num[firsNum];
}
public String getSecondNum()
{
while(true)
{
int secondNum = num_Random();
if(secondNum!=temp)
{
temp = -1;
return num[secondNum];
}
}
}
}
class MyDate
{
static Date date = new Date();
static SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
static int time;
public static String getFirstTime()
{
time = (int)(Math.random()*50);
long t = (int)time;
date.setTime(System.currentTimeMillis()+t*24*60*60*1000+t*30*1000+(long)(Math.random()*50));
return dateFormat.format(date);
}
public static int getMin()
{
return time;
}
}