Skip to content

Commit

Permalink
add random functions
Browse files Browse the repository at this point in the history
  • Loading branch information
millerbinbin committed Oct 30, 2017
1 parent abbc255 commit 386b517
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package com.jd.logistics.cloud.data.domain;

import lombok.Data;

import java.io.Serializable;

/**
* Created by GIN on 2017/10/30.
*/
@Data
public class Function implements Serializable{
public enum FuncType {
BOX(0), CHART(1), FREE(2);
private int index;
FuncType(int index) {
this.index = index;
}
public static FuncType getFuncType(int index) {
switch (index) {
case 0:
return FuncType.BOX;
case 1:
return FuncType.CHART;
case 2:
return FuncType.FREE;
}
return FuncType.BOX;
}
}
private String funcName;
private FuncType funcType;

public Function(String funcName, FuncType funcType) {
this.funcName = funcName;
this.funcType = funcType;
}

public String getFuncName() {
return funcName;
}

public void setFuncName(String funcName) {
this.funcName = funcName;
}

public FuncType getFuncType() {
return funcType;
}

public void setFuncType(FuncType funcType) {
this.funcType = funcType;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.jd.logistics.cloud.data.service;

import com.jd.logistics.cloud.data.domain.Function;
import com.jd.logistics.cloud.data.domain.Stat;

import java.text.SimpleDateFormat;
Expand All @@ -14,17 +15,29 @@ public class GenStatService {
private final static int rec_num = 32;
private final static Random r = new Random(rec_num);
public static List<Stat> statList = new ArrayList<>();
public static List<Function> functionList = new ArrayList<>();
static {
gen(rec_num);
}
private static void gen(int num){
Calendar date = Calendar.getInstance();
date.setTime(new Date());
String[] functions = {"接收订单量",
"Sku准确率",
"调拨入库单数",
"发出订单量",
"在库Sku",
"人效-DO",
"成本效率","测试1","测试2"};
for (int i = 0; i < num; i++) {
date.set(Calendar.DATE, date.get(Calendar.DATE) + 1);
String tmp_date = new SimpleDateFormat("YYYY-MM-dd").format(date.getTime());
statList.add(new Stat(tmp_date, r.nextInt(20), 20+r.nextInt(50), 50+r.nextInt(100), 100+r.nextInt(200)));
}
for(String function : functions) {
int index = r.nextInt(3);
functionList.add(new Function(function, Function.FuncType.getFuncType(index)));
}
}

public static List<Stat> getStatList(int limit, int offset){
Expand All @@ -36,5 +49,9 @@ public static List<Stat> getStatList(int limit, int offset){
return tmpList;
}

public static List<Function> getFunctionList(){
return functionList;
}

public static int count = statList.size();
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,6 @@ public interface StatService {
List<BoxRes> getBoxes();

List<ChartRes> getCharts();

List<Function> getFunctions(String type);
}
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,16 @@ public List<ChartRes> getCharts() {
return tmp;
}

@Override
public List<Function> getFunctions(String type) {
return GenStatService.getFunctionList();
}

public static void main(String[] args) {
StatServiceImpl ss = new StatServiceImpl();
System.out.println(ss.getPeriods());
System.out.println(ss.getCharts().get(0));
System.out.println(ss.getFunctions(""));
//System.out.println(GenStatService.statList);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,9 @@ public interface StatApi {
method = RequestMethod.GET)
List<ChartRes> getCharts();

@RequestMapping(value = "/func/{type}",
produces = { "application/json" },
method = RequestMethod.GET)
List<Function> getFunction(@PathVariable("type") String type);

}
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,9 @@ public List<ChartRes> getCharts() {
return statService.getCharts();
}

@Override
public List<Function> getFunction(@PathVariable("type") String type) {
return statService.getFunctions(type);
}

}
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@

<build>
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
Expand Down

0 comments on commit 386b517

Please sign in to comment.