Commit c95c3992 authored by lin's avatar lin

bi接口

parent dae1d392
...@@ -89,7 +89,7 @@ public class VariableController extends BaseRestController{ ...@@ -89,7 +89,7 @@ public class VariableController extends BaseRestController{
@GetMapping("/real-time") @GetMapping("/real-time")
@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>>> getVariableRealTimeDataList(HttpServletRequest request,@PathVariable String appId, public R<List<Map<String,List<Map<String,Object>>>>> getVariableRealTimeDataList(HttpServletRequest request,@PathVariable String appId,
VariableRealTimeDTO variableDTO) { VariableRealTimeDTO 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
* 实时变量DTO * 实时变量DTO
...@@ -15,14 +17,17 @@ import lombok.Data; ...@@ -15,14 +17,17 @@ import lombok.Data;
public class VariableRealTimeDTO { public class VariableRealTimeDTO {
@ApiModelProperty(value = "所属设备", required = true) @ApiModelProperty(value = "所属设备", required = true)
private String deviceId; private String deviceId;
@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)
private String endTime; private String endTime;
@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;
} }
...@@ -47,7 +47,7 @@ public interface VariableService { ...@@ -47,7 +47,7 @@ public interface VariableService {
* @param user * @param user
* @return * @return
*/ */
List<Map<String,Object>> getVariableRealTimeDataList(@NonNull String uri,VariableRealTimeDTO variableDTO,CurrentUser user); List<Map<String,List<Map<String,Object>>>> getVariableRealTimeDataList(@NonNull String uri,VariableRealTimeDTO variableDTO,CurrentUser user);
/** /**
* 获取历史数据 * 获取历史数据
......
...@@ -119,15 +119,19 @@ public class VariableServiceImpl implements VariableService { ...@@ -119,15 +119,19 @@ public class VariableServiceImpl implements VariableService {
} }
@Override @Override
public List<Map<String,Object>> getVariableRealTimeDataList(@NonNull String uri,VariableRealTimeDTO variableDTO,CurrentUser user) { public List<Map<String,List<Map<String,Object>>>> getVariableRealTimeDataList(@NonNull String uri,VariableRealTimeDTO variableDTO,CurrentUser user) {
if(StringUtils.isBlank(uri)){ if(StringUtils.isBlank(uri)){
throw new SysException("请传入uri"); throw new SysException("请传入uri");
} }
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("请传入结束时间");
...@@ -140,7 +144,7 @@ public class VariableServiceImpl implements VariableService { ...@@ -140,7 +144,7 @@ public class VariableServiceImpl implements VariableService {
} }
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