Skip to content

Commit

Permalink
reformat code
Browse files Browse the repository at this point in the history
Signed-off-by: hubin6 <[email protected]>
  • Loading branch information
hubin6 committed Nov 7, 2017
1 parent 1475350 commit 669865c
Show file tree
Hide file tree
Showing 41 changed files with 398 additions and 383 deletions.
4 changes: 0 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,10 @@ target/
.settings/
lib/
logs/
target/
bin/
.DS_Store
.metadata
*.log
*.log.*
.idea/
*.iml
.vagrant/
.#*
config_center_client.log
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ public void setPageSize(int pageSize) {
}

public long getOffset() {
return (long)(this.page - 1) * (long)this.pageSize;
return (long) (this.page - 1) * (long) this.pageSize;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public void setField(String field) {
this.field = field;
}
}

private List<Error> errors = new ArrayList();

public Errors() {
Expand Down
43 changes: 14 additions & 29 deletions dashboard-domain-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,17 @@
<type>pom</type>
<scope>import</scope>
</dependency>
<!--<dependency>-->
<!--<groupId>com.jd.spring.boot</groupId>-->
<!--<artifactId>jd-spring-boot-dependencies</artifactId>-->
<!--<version>1.0-SNAPSHOT</version>-->
<!--<type>pom</type>-->
<!--<scope>import</scope>-->
<!--</dependency>-->
</dependencies>
</dependencyManagement>

<dependencies>

<dependency>
<groupId>com.jd.logistics.cloud.data</groupId>
<artifactId>dashboard-commons</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>

<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
Expand All @@ -57,6 +56,7 @@
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.4.196</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>mysql</groupId>
Expand All @@ -68,10 +68,6 @@
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.3.1</version>
</dependency>
<!--<dependency>-->
<!--<groupId>org.springframework.boot</groupId>-->
<!--<artifactId>spring-boot-starter-jdbc</artifactId>-->
<!--</dependency>-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
Expand Down Expand Up @@ -106,28 +102,17 @@
<artifactId>groovy-all</artifactId>
</dependency>

<dependency>
<groupId>com.jd.logistics.cloud.data</groupId>
<artifactId>dashboard-commons</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>

<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.7</version>
</dependency>
<!--<dependency>-->
<!--<groupId>com.fresh.commons</groupId>-->
<!--<artifactId>fresh-commons-data</artifactId>-->
<!--<version>1.0.1-SNAPSHOT</version>-->
<!--</dependency>-->

<!--<dependency>-->
<!--<groupId>com.fresh.commons</groupId>-->
<!--<artifactId>fresh-commons-exception</artifactId>-->
<!--<version>1.0.1-SNAPSHOT</version>-->
<!--</dependency>-->
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>RELEASE</version>
</dependency>
</dependencies>

<build>
Expand Down Expand Up @@ -158,8 +143,8 @@
<goals>
<goal>generateStubs</goal>
<goal>compile</goal>
<!-- <goal>testGenerateStubs</goal>
<goal>testCompile</goal>-->
<!-- <goal>testGenerateStubs</goal>
<goal>testCompile</goal>-->
</goals>
</execution>
</executions>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.jd.logistics.cloud.data.service;
package com.jd.logistics.cloud.data.commons;

/**
* @Author hubin
* @Description:
* @Date 2017/11/7 9:32
*/
public class Constant {
public class Constants {
public static final String TEMPLATE_PARENT_FOLDER = "metrics";
public static final String CHART_OPTION_SUFFIX = ".chart.json";
public static final String CHART_TEMPLATE_SUFFIX = "chart.html";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.jd.logistics.cloud.data.service;
package com.jd.logistics.cloud.data.commons;

import com.jd.logistics.cloud.data.domain.Function;
import com.jd.logistics.cloud.data.domain.Stat;
Expand All @@ -16,10 +16,12 @@ public class GenStatService {
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){

private static void gen(int num) {
Calendar date = Calendar.getInstance();
date.setTime(new Date());
String[] functions = {
Expand All @@ -31,16 +33,16 @@ private static void gen(int num){
"人效-DO",
"成本效率"
};
String [] warehouses = {
String[] warehouses = {
"全部仓库",
"上海1仓",
"上海2仓",
"上海3仓"
};
Map<String, String[]> dateCycleIndexMap = new HashMap<> ();
dateCycleIndexMap.put("日维度", new String[]{"昨日全天","上周同日","日环比","周同比"});
dateCycleIndexMap.put("周维度", new String[]{"整周数据","去年同周","周环比","年同比"});
dateCycleIndexMap.put("月维度", new String[]{"整月数据","去年同月","月环比","年同比"});
Map<String, String[]> dateCycleIndexMap = new HashMap<>();
dateCycleIndexMap.put("日维度", new String[]{"昨日全天", "上周同日", "日环比", "周同比"});
dateCycleIndexMap.put("周维度", new String[]{"整周数据", "去年同周", "周环比", "年同比"});
dateCycleIndexMap.put("月维度", new String[]{"整月数据", "去年同月", "月环比", "年同比"});
// 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());
Expand All @@ -49,22 +51,22 @@ private static void gen(int num){
for (int i = 0; i < 20; i++) {
date.set(Calendar.DATE, date.get(Calendar.DATE) - 1);
String tmp_date = new SimpleDateFormat("YYYY/MM/dd").format(date.getTime());
for(String function: functions) {
for(String warehouse: warehouses) {
for(Map.Entry<String, String[]> item : dateCycleIndexMap.entrySet()){
for (String function : functions) {
for (String warehouse : warehouses) {
for (Map.Entry<String, String[]> item : dateCycleIndexMap.entrySet()) {
int idx = 0;
double funcValue;
if (function.equalsIgnoreCase("Sku准确率") ||
function.equalsIgnoreCase("人效-DO") ||
function.equalsIgnoreCase("成本效率"))
funcValue = (double)((int)((r.nextDouble()+1)*50))/100;
funcValue = (double) ((int) ((r.nextDouble() + 1) * 50)) / 100;
else
funcValue = 20000 + r.nextInt(3000) - 1500;
for(String index: item.getValue()) {
for (String index : item.getValue()) {
double indexValue;
if(idx<=1) indexValue = funcValue * (r.nextDouble()+0.45);
else indexValue = (double)((int)((r.nextDouble()-0.25)*1000))/100;
System.out.println(function+','+warehouse+','+item.getKey()+','+tmp_date+','+funcValue+','+index+','+indexValue);
if (idx <= 1) indexValue = funcValue * (r.nextDouble() + 0.45);
else indexValue = (double) ((int) ((r.nextDouble() - 0.25) * 1000)) / 100;
System.out.println(function + ',' + warehouse + ',' + item.getKey() + ',' + tmp_date + ',' + funcValue + ',' + index + ',' + indexValue);
idx++;
}
}
Expand All @@ -75,7 +77,7 @@ private static void gen(int num){

}

public static List<Stat> getStatList(int limit, int offset){
public static List<Stat> getStatList(int limit, int offset) {
List<Stat> tmpList = new ArrayList<>();
for (int i = offset; i < offset + limit; i++) {
if (i > count - 1) break;
Expand All @@ -84,7 +86,7 @@ public static List<Stat> getStatList(int limit, int offset){
return tmpList;
}

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

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
package com.jd.logistics.cloud.data.commons;

import com.alibaba.fastjson.JSON;
import com.google.common.io.Resources;
import com.jd.logistics.cloud.data.domain.BaseModel;
import com.jd.logistics.cloud.data.domain.ChartModel;
import com.jd.logistics.cloud.data.domain.CommonRes;
import com.jd.logistics.cloud.data.domain.ValueModel;
import org.jetbrains.annotations.NotNull;
import org.springframework.jdbc.support.rowset.SqlRowSet;
import org.springframework.jdbc.support.rowset.SqlRowSetMetaData;

import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
* @Author hubin
* @Description:
* @Date 2017/11/7 9:28
*/
public class Helper {
@NotNull
public static String InputStream2String(InputStream in) {
StringBuffer out = new StringBuffer();
byte[] b = new byte[4096];
try {
for (int n; (n = in.read(b)) != -1; ) {
out.append(new String(b, 0, n));
}
} catch (IOException e) {
e.printStackTrace();
}
return out.toString();
}

@NotNull
public static String getStringFromResourcePath(String filePath) {
InputStream in = null;
try {
in = Resources.getResource(filePath).openStream();
} catch (IOException e) {
e.printStackTrace();
}
return Helper.InputStream2String(in);
}

public static Map<String, String> getFuncSqlByType(String funcName, ShowType type) {
String json = Helper.getStringFromResourcePath(Constants.TEMPLATE_PARENT_FOLDER + "/" +
funcName + "/" + Constants.TEMPLATE_MODEL_FILE);
BaseModel bm = JSON.parseObject(json, BaseModel.class);
Map<String, String> sqlList = new HashMap<>();
if (type == ShowType.CHART) {
for (ChartModel model : bm.getCharts()) {
sqlList.put(model.getName(), Helper.getStringFromResourcePath(Constants.TEMPLATE_PARENT_FOLDER + "/" +
funcName + "/" + model.getSql()));
}
} else if (type == ShowType.VALUE) {
for (ValueModel model : bm.getValues()) {
sqlList.put(model.getName(), Helper.getStringFromResourcePath(Constants.TEMPLATE_PARENT_FOLDER + "/" +
funcName + "/" + model.getSql()));
}
}
return sqlList;
}

public static Map<String, List<Object>> RowSet2ArrayRes(SqlRowSet rowSet) {
SqlRowSetMetaData metaData = rowSet.getMetaData();
String[] colNames = metaData.getColumnNames();
CommonRes cr = new CommonRes();
while (rowSet.next()) {
for (String col : colNames) {
String c = col.toLowerCase();
cr.addItem(c, rowSet.getObject(col));
}
}
return cr.getArrayResult();
}


public static Map<String, Object> RowSet2SingleRes(SqlRowSet rowSet) {
SqlRowSetMetaData metaData = rowSet.getMetaData();
String[] colNames = metaData.getColumnNames();
CommonRes cr = new CommonRes();
rowSet.next();
for (String col : colNames) {
String c = col.toLowerCase();
cr.putItem(c, rowSet.getObject(col));
}
return cr.getSingleResult();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.jd.logistics.cloud.data.commons;

/**
* @Author hubin
* @Description:
* @Date 2017/11/7 12:30
*/
public enum ShowType {
CHART, VALUE
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* Created by GIN on 2017/10/30.
*/
@Data
public class Function implements Serializable{
public class Function implements Serializable {
private static final long serialVersionUID = -3908221732001318230L;
// public enum FuncType {
// BOX(0), CHART(1), FREE(2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* @Date 2017/10/31 15:50
*/
@Data
public class GenericRes implements Serializable{
public class GenericRes implements Serializable {
private static final long serialVersionUID = 1902248647108008231L;
private String funcName;
private double funcValue;
Expand Down Expand Up @@ -43,15 +43,16 @@ public class GenericRes implements Serializable{
private List<String> p;
private List<Double> v1;
private List<Double> v2;

public String getFuncFormatValue() {
DecimalFormat df = new DecimalFormat("###,##0");
DecimalFormat df2 = new DecimalFormat("###,##0.00");
double tmp = funcValue;
if (tmp / 100000 >=1)
funcFormatValue = df.format(tmp/1000) + "K";
if (tmp / 100000 >= 1)
funcFormatValue = df.format(tmp / 1000) + "K";
else if ((tmp * 10) % 10 == 0) // integer
funcFormatValue = df.format(tmp);
else if (tmp <= 1 ) // 百分比
else if (tmp <= 1) // 百分比
funcFormatValue = df2.format(tmp * 100) + "%";
else funcFormatValue = df2.format(tmp);
return funcFormatValue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* Created by yanhua on 2017/1/5.
*/
@Data
public class User implements Serializable{
public class User implements Serializable {
private static final long serialVersionUID = 3619539590826838447L;
@ApiModelProperty(value = "", required = true)
private long id;
Expand All @@ -26,6 +26,7 @@ public long getId() {
public String getUsername() {
return username;
}

public String getPassword() {
return password;
}
Expand Down
Loading

0 comments on commit 669865c

Please sign in to comment.