Skip to content

Commit

Permalink
refine code
Browse files Browse the repository at this point in the history
Signed-off-by: hubin6 <[email protected]>
  • Loading branch information
hubin6 committed Nov 10, 2017
1 parent daf5da4 commit 5ec528f
Show file tree
Hide file tree
Showing 52 changed files with 1,042 additions and 109 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@

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 com.jd.logistics.cloud.data.domain.*;
import org.jetbrains.annotations.NotNull;
import org.springframework.jdbc.support.rowset.SqlRowSet;
import org.springframework.jdbc.support.rowset.SqlRowSetMetaData;
Expand Down Expand Up @@ -47,20 +44,31 @@ public static String getStringFromResourcePath(String filePath) {
return Helper.InputStream2String(in);
}

public static Map<String, String> getFuncSqlByType(String funcName, ShowType type) {
public static Map<String, String> getDesc(String funcId) {
String json = Helper.getStringFromResourcePath(Constants.TEMPLATE_PARENT_FOLDER + "/" +
funcName + "/" + Constants.TEMPLATE_MODEL_FILE);
funcId + "/" + Constants.TEMPLATE_MODEL_FILE);
BaseModel bm = JSON.parseObject(json, BaseModel.class);
Map<String, String> descList = new HashMap<>();
for (Description desc: bm.getDescriptions()) {
descList.put(desc.getName(), desc.getText());
}
return descList;
}

public static Map<String, String> getFuncSqlByType(String funcId, ShowType type) {
String json = Helper.getStringFromResourcePath(Constants.TEMPLATE_PARENT_FOLDER + "/" +
funcId + "/" + 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()));
funcId + "/" + 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()));
funcId + "/" + model.getSql()));
}
}
return sqlList;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.jd.logistics.cloud.data.domain;

import lombok.Data;
import org.apache.ibatis.javassist.runtime.Desc;

import java.io.Serializable;
import java.util.List;
Expand All @@ -13,9 +14,15 @@
@Data
public class BaseModel implements Serializable {
private static final long serialVersionUID = 7593767886021869685L;
private String id;
private String name;
private List<ChartModel> charts;
private List<ValueModel> values;
private List<Description> descriptions;

public String getId() {
return id;
}

public String getName() {
return name;
Expand All @@ -28,4 +35,8 @@ public List<ChartModel> getCharts() {
public List<ValueModel> getValues() {
return values;
}

public List<Description> getDescriptions() {
return descriptions;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.jd.logistics.cloud.data.domain;

import lombok.Data;

import java.io.Serializable;

/**
* @Author hubin
* @Description:
* @Date 2017/11/10 10:10
*/
@Data
public class Description implements Serializable {
private static final long serialVersionUID = -8617270101773389965L;
private String name;
private String text;

public String getName() {
return name;
}

public String getText() {
return text;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,25 @@ public class Function implements Serializable {
// return FuncType.BOX;
// }
// }
private int id;
private String id;
private String funcName;
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;
// }
//
public String getId() {
return id;
}

public String getFuncName() {
return funcName;
}

public int getFuncType() {
return funcType;
}

public int getSeq() {
return seq;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ public class ChartServiceImpl implements ChartService {
JdbcTemplate jdbcTemplate;

@Override
public Map getFuncChart(String funcName) {
Map<String, String> sqlList = Helper.getFuncSqlByType(funcName, ShowType.CHART);
public Map getFuncChart(String funcId) {
Map<String, String> sqlList = Helper.getFuncSqlByType(funcId, ShowType.CHART);
Map res = new HashMap<>();
for (Map.Entry<String, String> e : sqlList.entrySet()) {
String sql = e.getValue();
Expand All @@ -35,8 +35,8 @@ public Map getFuncChart(String funcName) {
}

@Override
public String getFuncChartOption(String funcName, String chartId) {
public String getFuncChartOption(String funcId, String chartId) {
return Helper.getStringFromResourcePath(Constants.TEMPLATE_PARENT_FOLDER + "/" +
funcName + "/" + chartId + Constants.CHART_OPTION_SUFFIX);
funcId + "/" + chartId + Constants.CHART_OPTION_SUFFIX);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,9 @@ public List<Function> getAllFunc() {
public void updateFuncType(Function func) {
funcRepository.update(func);
}

@Override
public String getFuncNameById(String funcId) {
return funcRepository.getFuncNameById(funcId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import com.jd.logistics.cloud.data.commons.Constants;
import com.jd.logistics.cloud.data.commons.Helper;
import com.jd.logistics.cloud.data.service.FuncService;
import com.jd.logistics.cloud.data.service.ModelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
Expand All @@ -15,6 +17,8 @@
*/
@Service
public class ModelServiceImpl implements ModelService {
@Autowired
FuncService funcService;
private String getFuncChartFormat(String funcName) {
return Helper.getStringFromResourcePath(Constants.TEMPLATE_PARENT_FOLDER + "/" +
funcName + "/" + Constants.CHART_TEMPLATE_SUFFIX);
Expand All @@ -26,13 +30,22 @@ private String getFuncValueFormat(String funcName) {
}

@Override
public Map getFuncModel(String funcName) {
String chartTemplate = getFuncChartFormat(funcName);
String numberTemplate = getFuncValueFormat(funcName);
public Map getFuncModel(String funcId) {
String chartTemplate = getFuncChartFormat(funcId);
String numberTemplate = getFuncValueFormat(funcId);
Map res = new HashMap<>();
res.put("name", funcName);
res.put("id", funcId);
res.put("name", funcService.getFuncNameById(funcId));
res.put("chartTemplate", chartTemplate);
res.put("numberTemplate", numberTemplate);
return res;
}

@Override
public Map getFuncDesc(String funcId) {
Map res = Helper.getDesc(funcId);
res.put("id", funcId);
res.put("name", funcService.getFuncNameById(funcId));
return res;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ public class ValueServiceImpl implements ValueService {
JdbcTemplate jdbcTemplate;

@Override
public Map getFuncValues(String funcName) {
Map<String, String> sqlList = Helper.getFuncSqlByType(funcName, ShowType.VALUE);
public Map getFuncValues(String funcId) {
Map<String, String> sqlList = Helper.getFuncSqlByType(funcId, ShowType.VALUE);
Map res = new HashMap<>();
for (Map.Entry<String, String> e : sqlList.entrySet()) {
String sql = e.getValue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,15 @@
@Mapper
public interface FuncRepository {

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

@Select("SELECT id, func_name as funcName, func_type_id as funcType, seq FROM T_FUNCTION order by seq")
@Select("SELECT concat('sample',id) as id, func_name as funcName, func_type_id as funcType, seq FROM T_FUNCTION order by seq")
List<Function> getAll();

@Update("UPDATE T_FUNCTION SET func_type_id=#{func.funcType}, seq=#{func.seq} WHERE func_name=#{func.funcName}")
void update(@Param("func") Function func);

@Select("SELECT func_name as funcName FROM T_FUNCTION where concat('sample',id)=#{funcId}")
String getFuncNameById(@Param("funcId") String funcId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* @Date 2017/11/7 9:22
*/
public interface ChartService {
Map getFuncChart(String funcName);
Map getFuncChart(String funcId);

String getFuncChartOption(String funcName, String chartId);
String getFuncChartOption(String funcId, String chartId);
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@ public interface FuncService {
List<Function> getAllFunc();

void updateFuncType(Function func);

String getFuncNameById(String funcId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@
* @Date 2017/11/7 9:35
*/
public interface ModelService {
Map getFuncModel(String funcName);
Map getFuncModel(String funcId);
Map getFuncDesc(String funcId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
* @Date 2017/11/7 9:22
*/
public interface ValueService {
Map getFuncValues(String funcName);
Map getFuncValues(String funcId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
*/
@RequestMapping(value = "/api")
public interface ChartApi {
@RequestMapping(value = "/chart/{funcName}",
@RequestMapping(value = "/chart/{funcId}",
produces = {"application/json"},
method = RequestMethod.GET)
Map getFuncChart(@PathVariable("funcName") String funcName);
Map getFuncChart(@PathVariable("funcId") String funcId);

@RequestMapping(value = "/chartOption/{funcName}/{chartName}",
@RequestMapping(value = "/chartOption/{funcId}/{chartId}",
produces = {"application/json"},
method = RequestMethod.GET)
String getFuncChartOption(@PathVariable("funcName") String funcName, @PathVariable("chartName") String chartName);
String getFuncChartOption(@PathVariable("funcId") String funcId, @PathVariable("chartId") String chartId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,18 @@
*/
@RequestMapping(value = "/api")
public interface ModelApi {
@RequestMapping(value = "/model/{funcName}",
@RequestMapping(value = "/model/{funcId}",
produces = {"application/json"},
method = RequestMethod.GET)
Map getFuncModel(@PathVariable("funcName") String funcName);
Map getFuncModel(@PathVariable("funcId") String funcId);

@RequestMapping(value = "/models",
produces = {"application/json"},
method = RequestMethod.GET)
List<Map> getModels();

@RequestMapping(value = "/desc",
produces = {"application/json"},
method = RequestMethod.GET)
List<Map> getDesc();
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
*/
@RequestMapping(value = "/api/value")
public interface ValueApi {
@RequestMapping(value = "/{funcName}",
@RequestMapping(value = "/{funcId}",
produces = {"application/json"},
method = RequestMethod.GET)
Map getFuncValues(@PathVariable("funcName") String funcName);
Map getFuncValues(@PathVariable("funcId") String funcId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ public class ChartRestController implements ChartApi {
ChartService chartService;

@Override
public Map getFuncChart(@PathVariable("funcName") String funcName) {
return chartService.getFuncChart(funcName);
public Map getFuncChart(@PathVariable("funcId") String funcId) {
return chartService.getFuncChart(funcId);
}

@Override
public String getFuncChartOption(@PathVariable("funcName") String funcName, @PathVariable("chartName") String chartName) {
return chartService.getFuncChartOption(funcName, chartName);
public String getFuncChartOption(@PathVariable("funcId") String funcId, @PathVariable("chartId") String chartId) {
return chartService.getFuncChartOption(funcId, chartId);
}
}
Loading

0 comments on commit 5ec528f

Please sign in to comment.