Skip to content

Commit

Permalink
add sth
Browse files Browse the repository at this point in the history
  • Loading branch information
hubin6 committed Oct 31, 2017
1 parent 386b517 commit 507e4fa
Show file tree
Hide file tree
Showing 19 changed files with 419 additions and 124 deletions.
10 changes: 5 additions & 5 deletions dashboard-domain-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@
<artifactId>h2</artifactId>
<version>1.4.196</version>
</dependency>
<!--<dependency>-->
<!--<groupId>mysql</groupId>-->
<!--<artifactId>mysql-connector-java</artifactId>-->
<!--<version>5.1.24</version>-->
<!--</dependency>-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.24</version>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.jd.logistics.cloud.data.domain;

import lombok.Data;

import java.io.Serializable;

/**
* @Author hubin
* @Description:
* @Date 2017/10/31 15:39
*/
@Data
public class DimQuery implements Serializable {
private static final long serialVersionUID = -946299281247438489L;
private String funcName;
private String warehouse;
private String dateCycle;
private String dateStart;
private String dateEnd;
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,45 +9,44 @@
*/
@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 static final long serialVersionUID = -3908221732001318230L;
// 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 int id;
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;
}
private int funcType; // BOX(0), CHART(1), FREE(2);
private int seq;

// public String getFuncName() {
// return funcName;
// }
//
// public void setFuncName(String funcName) {
// this.funcName = funcName;
// }
//
// public int getFuncType() {
// return funcType;
// }
//
// public void setFuncType(int funcType) {
// this.funcType = funcType;
// }
//
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.jd.logistics.cloud.data.domain;

import lombok.Data;

import java.io.Serializable;
import java.text.DecimalFormat;
import java.util.List;

/**
* @Author hubin
* @Description:
* @Date 2017/10/31 15:50
*/
@Data
public class GenericRes implements Serializable{
private static final long serialVersionUID = 1902248647108008231L;
private String funcName;
private String funcValue;
private String idxName1;
private double idxValue1;
private String idxName2;
private double idxValue2;
private String idxName3;
private double idxValue3;
private String idxName4;
private double idxValue4;
private String statDate;

public String getFuncValue() {
DecimalFormat df = new DecimalFormat("###,##0");
DecimalFormat df2 = new DecimalFormat("###,##0.00");
double tmp = Double.parseDouble(funcValue);
if (tmp / 100000 >=1)
funcValue = df.format(tmp/1000) + "K";
else if ((tmp * 10) % 10 == 0) // integer
funcValue = df.format(tmp);
else if (tmp <= 1 ) // 百分比
funcValue = df2.format(tmp * 100) + "%";
else funcValue = df2.format(tmp);
return funcValue;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.jd.logistics.cloud.data.repository;

import com.jd.logistics.cloud.data.domain.Dim;
import com.jd.logistics.cloud.data.domain.DimQuery;
import com.jd.logistics.cloud.data.domain.Function;
import com.jd.logistics.cloud.data.domain.GenericRes;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
* @Author hubin
* @Description:
* @Date 2017/10/30 9:22
*/
@Mapper
public interface DimRepository {
@Select("SELECT * FROM T_WAREHOUSE")
List<Dim> getWarehouses();

@Select("SELECT * FROM T_DATECYCLE")
List<Dim> getDateCycles();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.jd.logistics.cloud.data.repository;

import com.jd.logistics.cloud.data.domain.Function;
import com.jd.logistics.cloud.data.domain.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
* @Author hubin
* @Description:
* @Date 2017/10/30 9:22
*/
@Mapper
public interface FuncRepository {

@Select("SELECT id, name as funcName, type as funcType, seq FROM T_FUNCTION where type=#{type}order by seq")
List<Function> getByType(@Param("type") int type);

@Select("SELECT id, name as funcName, type as funcType, seq FROM T_FUNCTION order by seq")
List<Function> getAll();

@Update("UPDATE T_FUNCTION SET type=#{func.funcType}, seq=#{func.seq} WHERE name=#{func.funcName}")
void update(@Param("func") Function func);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.jd.logistics.cloud.data.repository;

import com.jd.logistics.cloud.data.domain.DimQuery;
import com.jd.logistics.cloud.data.domain.GenericRes;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
* @Author hubin
* @Description:
* @Date 2017/10/31 17:41
*/
@Mapper
public interface StatRepository {
@Select("<script>" +
"SELECT FUNC_NAME as funcName, FUNC_VALUE as funcValue, STAT_DATE as statDate, " +
" '日环比' as idxName1," +
" MAX(CASE WHEN IDX_NAME='日环比' then IDX_VALUE else NULL END) as idxValue1," +
" '周同比' as idxName2," +
" MAX(CASE WHEN IDX_NAME='周同比' then IDX_VALUE else NULL END) as idxValue2," +
" '上周同日' as idxName3," +
" MAX(CASE WHEN IDX_NAME='上周同日' then IDX_VALUE else NULL END) as idxValue3," +
" '昨日全天' as idxName4," +
" MAX(CASE WHEN IDX_NAME='昨日全天' then IDX_VALUE else NULL END) as idxValue4" +
" FROM T_RESULT where 1=1" +
"<if test='query.warehouse != null'> AND WAREHOUSE_NAME=#{query.warehouse}</if>" +
"<if test='query.funcName != null'> AND FUNC_NAME=#{query.funcName}</if>" +
"<if test='query.dateCycle != null'> AND DATE_CYCLE=#{query.dateCycle}</if>" +
"<if test='query.dateStart != null and query.dateEnd != null'> AND STAT_DATE between #{query.dateStart} and #{query.dateEnd}</if>" +
" GROUP BY FUNC_NAME, FUNC_VALUE, STAT_DATE" +
"</script>"
)
List<GenericRes> getRes(@Param("query")DimQuery query);
}
Original file line number Diff line number Diff line change
@@ -1,27 +1,23 @@
package com.jd.logistics.cloud.data.repository;

import com.jd.logistics.cloud.data.domain.DimQuery;
import com.jd.logistics.cloud.data.domain.GenericRes;
import com.jd.logistics.cloud.data.domain.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
* @Author hubin
* @Description:
* @Date 2017/10/30 9:22
*/
@Mapper
public interface UserRepository {
@Insert("INSERT into T_USER (name,age,addr) VALUES(#{name}, #{age}, #{addr})")
void add(User user);

@Select("SELECT * FROM T_USER WHERE id = #{id}")
User getById(@Param("id") Long id);

@Select("SELECT * FROM T_USER WHERE name = #{name}")
User getByName(@Param("name") String name);

@Update("UPDATE T_USER SET name=#{user.name}, age=#{user.age}, addr=#{user.addr} WHERE id=#{user.id}")
void update(@Param("user") User user);
@Select("SELECT * FROM T_USER WHERE username = #{username}")
User getByName(@Param("username") String username);

@Delete("DELETE FROM T_USER WHERE id =#{id}")
void delete(@Param("id") Long id);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.jd.logistics.cloud.data.service;

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

import java.util.List;

/**
* @Author hubin
* @Description:
* @Date 2017/10/31 10:17
*/
public interface FuncService {
List<Function> getFuncByType(int type);
List<Function> getAllFunc();
void updateFuncType(Function func);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.jd.logistics.cloud.data.service;

import com.jd.logistics.cloud.data.domain.Function;
import com.jd.logistics.cloud.data.repository.FuncRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @Author hubin
* @Description:
* @Date 2017/10/31 10:17
*/
@Service
public class FuncServiceImpl implements FuncService {
@Autowired
FuncRepository funcRepository;
@Override
public List<Function> getFuncByType(int type) {
return funcRepository.getByType(type);
}

@Override
public List<Function> getAllFunc() {
return funcRepository.getAll();
}

@Override
public void updateFuncType(Function func) {
funcRepository.update(func);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,23 @@ public class GenStatService {
private static void gen(int num){
Calendar date = Calendar.getInstance();
date.setTime(new Date());
String[] functions = {"接收订单量",
String[] functions = {
"接收订单量",
"Sku准确率",
"调拨入库单数",
"发出订单量",
"在库Sku",
"人效-DO",
"成本效率","测试1","测试2"};
"成本效率",
"测试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 Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,9 @@ public interface StatService {

List<List<Double>> getColumns();

User getUser(long id);

List<BoxRes> getBoxes();

List<ChartRes> getCharts();

List<Function> getFunctions(String type);
List<GenericRes> getRes(DimQuery query);
}
Loading

0 comments on commit 507e4fa

Please sign in to comment.