Commit dae1d392 authored by lin's avatar lin

bi接口

parent fd0b993e
...@@ -119,7 +119,7 @@ public class VariableController extends BaseRestController{ ...@@ -119,7 +119,7 @@ public class VariableController extends BaseRestController{
@GetMapping("/history") @GetMapping("/history")
@ApiOperation("获取变量历史数据") @ApiOperation("获取变量历史数据")
@ApiImplicitParam(name = "appId", value = "租户id", required = true,dataTypeClass = String.class) @ApiImplicitParam(name = "appId", value = "租户id", required = true,dataTypeClass = String.class)
public R< List<Map<String, Object>> > getVariableHistoryDataList(HttpServletRequest request,@PathVariable String appId, public R<List<Map<String,List<Map<String,Object>>>>> getVariableHistoryDataList(HttpServletRequest request,@PathVariable String appId,
VariableHistoryDataDTO variableDTO) { VariableHistoryDataDTO variableDTO) {
return call(() -> { return call(() -> {
CurrentUser currentUser = getCurrentUser(request); CurrentUser currentUser = getCurrentUser(request);
......
...@@ -4,6 +4,8 @@ import io.swagger.annotations.ApiModel; ...@@ -4,6 +4,8 @@ import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
import java.util.Map;
/** /**
* slm-bi * slm-bi
...@@ -16,12 +18,12 @@ import lombok.Data; ...@@ -16,12 +18,12 @@ import lombok.Data;
public class VariableHistoryDataDTO { public class VariableHistoryDataDTO {
@ApiModelProperty(value = "所属设备", required = true) @ApiModelProperty(value = "所属设备", required = true)
private String deviceId; private String deviceId;
@ApiModelProperty(value = "统计类型,代表(合计值(sum),平均值(avg),最大值(max),最小值(min) 中位数(middle),原值 original)", required = true) @ApiModelProperty(value = "(x轴为变量时,统计类型必填)统计类型,代表(合计值(sum),平均值(avg),最大值(max),最小值(min) 中位数(middle),原值 original)", required = true)
private String statisticsType; private String statisticsType;
@ApiModelProperty(value = "变量id", required = true) // @ApiModelProperty(value = "变量id", required = true)
private String variableId; // private String variableId;
@ApiModelProperty(value = "变量Code", required = true) // @ApiModelProperty(value = "变量Code", required = true)
private String variableCode; // private String variableCode;
@ApiModelProperty(value = "开始时间(时间戳)",required = true) @ApiModelProperty(value = "开始时间(时间戳)",required = true)
private String startTime; private String startTime;
@ApiModelProperty(value = "结束时间(时间戳)", required = true) @ApiModelProperty(value = "结束时间(时间戳)", required = true)
...@@ -31,4 +33,7 @@ public class VariableHistoryDataDTO { ...@@ -31,4 +33,7 @@ public class VariableHistoryDataDTO {
private String x; private String x;
@ApiModelProperty(value = "统计维度如果是时间,请填时间格式如(yyyy-MM-dd HH:mm:ss),非时间为空", required = true) @ApiModelProperty(value = "统计维度如果是时间,请填时间格式如(yyyy-MM-dd HH:mm:ss),非时间为空", required = true)
private String format; private String format;
@ApiModelProperty(value = "key 为变量id value 为变量名称", required = true)
Map<String,String> variables;
} }
...@@ -56,7 +56,7 @@ public interface VariableService { ...@@ -56,7 +56,7 @@ public interface VariableService {
* @param currentUser * @param currentUser
* @return * @return
*/ */
List<Map<String, Object>> getVariableHistoryDataList(@NonNull String uri, List<Map<String,List<Map<String,Object>>>> getVariableHistoryDataList(@NonNull String uri,
VariableHistoryDataDTO variableDTO,CurrentUser currentUser); VariableHistoryDataDTO variableDTO,CurrentUser currentUser);
/** /**
......
...@@ -145,7 +145,7 @@ public class VariableServiceImpl implements VariableService { ...@@ -145,7 +145,7 @@ public class VariableServiceImpl implements VariableService {
} }
@Override @Override
public List<Map<String, Object>> getVariableHistoryDataList(@NonNull String uri, public List<Map<String,List<Map<String,Object>>>> getVariableHistoryDataList(@NonNull String uri,
VariableHistoryDataDTO variableDTO,CurrentUser user) { VariableHistoryDataDTO variableDTO,CurrentUser user) {
if(StringUtils.isBlank(uri)){ if(StringUtils.isBlank(uri)){
throw new SysException("请传入uri"); throw new SysException("请传入uri");
...@@ -153,15 +153,30 @@ public class VariableServiceImpl implements VariableService { ...@@ -153,15 +153,30 @@ public class VariableServiceImpl implements VariableService {
if(StringUtils.isBlank(variableDTO.getDeviceId())){ if(StringUtils.isBlank(variableDTO.getDeviceId())){
throw new SysException("请传入设备id"); throw new SysException("请传入设备id");
} }
if(StringUtils.isBlank(variableDTO.getVariableCode())){ if(CollectionUtils.isEmpty(variableDTO.getVariables())){
throw new SysException("请传入变量code"); throw new SysException("请传入变量");
}else{
if(variableDTO.getVariables().values().stream().anyMatch(StringUtils::isBlank)) {
throw new SysException("变量名字不能为空");
} }
}
if(StringUtils.isBlank(variableDTO.getEndTime())){ if(StringUtils.isBlank(variableDTO.getEndTime())){
throw new SysException("请传入结束时间"); throw new SysException("请传入结束时间");
} }
if(StringUtils.isBlank(variableDTO.getStartTime())){ if(StringUtils.isBlank(variableDTO.getStartTime())){
throw new SysException("请传入开始时间"); throw new SysException("请传入开始时间");
} }
if(StringUtils.isBlank(variableDTO.getX())){
throw new SysException("请传入统计维度");
}
if("time".equals(variableDTO.getX())){
if(StringUtils.isBlank(variableDTO.getFormat())) {
throw new SysException("统计维度为时间,请填入时间格式");
}
}else{
if(StringUtils.isBlank(variableDTO.getStatisticsType())){ if(StringUtils.isBlank(variableDTO.getStatisticsType())){
throw new SysException("请传入统计类型"); throw new SysException("请传入统计类型");
}else{ }else{
...@@ -174,19 +189,11 @@ public class VariableServiceImpl implements VariableService { ...@@ -174,19 +189,11 @@ public class VariableServiceImpl implements VariableService {
throw new SysException("没有对应匹配的统计类型"); throw new SysException("没有对应匹配的统计类型");
} }
} }
if(StringUtils.isBlank(variableDTO.getX())){
throw new SysException("请传入统计维度");
}
if("time".equals(variableDTO.getX())){
if(StringUtils.isBlank(variableDTO.getFormat())) {
throw new SysException("统计维度为时间,请填入时间格式");
}
} }
Map<String, String> uriVariables =SlmConstants.gson.fromJson(SlmConstants.gson.toJson(variableDTO),new TypeToken<Map<String,String>>(){}.getType()); Map<String, String> uriVariables =SlmConstants.gson.fromJson(SlmConstants.gson.toJson(variableDTO),new TypeToken<Map<String,String>>(){}.getType());
uriVariables.put("appId",user.getAppId()); uriVariables.put("appId",user.getAppId());
R<List<Map<String, Object>>> result = RestTemplateUtils.get(uri, new TypeToken<R<List<Map<String, Object>>>>() {}.getType(), uriVariables); R<List<Map<String,List<Map<String,Object>>>>> result = RestTemplateUtils.get(uri, new TypeToken<R<List<Map<String,List<Map<String,Object>>>>>>() {}.getType(), uriVariables);
return result.detach(); return result.detach();
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment