Commit 7fc8afcb authored by linruibiao's avatar linruibiao

接口编写

parent 19d0d1a9
......@@ -54,6 +54,9 @@ public class BaseRestController {
protected String businessFiledData;
@Value("${dc_client.interfaces.variableHistoryDataList}")
protected String variableHistoryDataList;
......
......@@ -51,10 +51,10 @@ public class BusinessConfigController extends BaseRestController{
@PostMapping("/filed")
@ApiOperation("根据配置字段获取字段数据")
@ApiImplicitParam(name = "appId", value = "租户id", required = true,dataTypeClass = String.class)
public R<List<Map<String, Object>>> getBusinessData(HttpServletRequest request, @PathVariable String appId,@RequestBody BusinessDTO dto) {
public R<Map<String, Object>> getBusinessData(HttpServletRequest request, @PathVariable String appId,@RequestBody BusinessDTO dto) {
return call(()->{
CurrentUser currentUser = getCurrentUser(request);
return businessConfigService.getBusinessData(dto,businessFiledData,currentUser);
return businessConfigService.getBusinessData(dto,dcClientHost+businessFiledData,currentUser);
});
}
}
......@@ -112,8 +112,13 @@ public class VariableController extends BaseRestController{
@GetMapping("/history")
@ApiOperation("获取变量历史数据")
@ApiImplicitParam(name = "appId", value = "租户id", required = true,dataTypeClass = String.class)
public R<Map<String, List<Map<String, HistoryVariableVo>>>> getVariableHistoryDataList(@PathVariable String appId,VariableDataDTO variableDTO) {
return call(()->(variableService.getVariableHistoryDataList(variableDTO)));
public R< List<Map<String, Object>> > getVariableHistoryDataList(HttpServletRequest request,@PathVariable String appId,VariableDataDTO variableDTO) {
return call(() -> {
CurrentUser currentUser = getCurrentUser(request);
return variableService.getVariableHistoryDataList(dcClientHost + variableHistoryDataList,
variableDTO,
currentUser);
});
}
@PostMapping("/send")
......
......@@ -16,7 +16,7 @@ public class BusinessConditionDTO {
@ApiModelProperty(value = "区间配置字段", required = true)
private String key;
@ApiModelProperty(value = "字段对应的值,时间给对应时间戳", required = true)
private String value;
private Object value;
@ApiModelProperty(value = "查询类型(大于 gt, 小于 lt ,大于等于 gte ,小于等于 lte)", required = true)
private String queryType;
}
......@@ -5,6 +5,7 @@ import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.List;
import java.util.Map;
/**
* slm-bi
......@@ -21,8 +22,9 @@ public class BusinessDTO {
private String y;
@ApiModelProperty(value = "横轴纬度", required = true)
private String x;
@ApiModelProperty(value = "查询配置的时间区间(如果为空不要调用后台)", required = true)
List<BusinessConditionDTO> where;
@ApiModelProperty(value = "查询配置(如果为空不要调用后台)", required = true)
List<Map<String,List<BusinessConditionDTO>>> where;
@ApiModelProperty(value = "统计类型(平均值 avg ,合计值 sum, 最大值 max ,最小值 min,中位数 middle ,原值 original)", required = true)
private String statisticsType;
}
......@@ -16,12 +16,14 @@ import lombok.Data;
public class VariableDataDTO {
@ApiModelProperty(value = "所属设备", required = true)
private String deviceId;
@ApiModelProperty(value = "统计类型,代表(合计值(sum),平均值(avg),最大值(max),最小值(min) 中位数(middle))", required = true)
@ApiModelProperty(value = "统计类型,代表(合计值(sum),平均值(avg),最大值(max),最小值(min) 中位数(middle),原值 original)", required = true)
private String statisticsType;
@ApiModelProperty(value = "变量id", required = true)
private String variableId;
@ApiModelProperty(value = "变量Code", required = true)
private String variableCode;
@ApiModelProperty(value = "变量名称", required = true)
private String variableName;
@ApiModelProperty(value = "开始时间(时间戳)",required = true)
private String startTime;
@ApiModelProperty(value = "结束时间(时间戳)", required = true)
......
......@@ -36,5 +36,5 @@ public interface BusinessConfigService extends IService<BusinessConfig> {
* @param user
* @return
*/
List<Map<String,Object>> getBusinessData(BusinessDTO dto,String uri, CurrentUser user);
Map<String, Object> getBusinessData(BusinessDTO dto,String uri, CurrentUser user);
}
......@@ -7,6 +7,7 @@ import com.syc.slm.slmbi.dto.VariableDTO;
import com.syc.slm.slmbi.dto.VariableSendDTO;
import com.syc.slm.slmbi.entity.CurrentUser;
import com.syc.slm.slmbi.vo.*;
import lombok.NonNull;
import java.util.List;
import java.util.Map;
......@@ -54,7 +55,7 @@ public interface VariableService {
* @param variableDTO
* @return
*/
Map<String, List<Map<String, HistoryVariableVo>>> getVariableHistoryDataList(VariableDataDTO variableDTO);
List<Map<String, Object>> getVariableHistoryDataList(@NonNull String uri,VariableDataDTO variableDTO,CurrentUser currentUser);
/**
* 下发
......
......@@ -75,7 +75,7 @@ public class BusinessConfigServiceImpl extends ServiceImpl<BusinessConfigMapper,
@Override
@Transactional(readOnly = true)
public List<Map<String, Object>> getBusinessData(BusinessDTO dto,String uri, CurrentUser user) {
public Map<String, Object> getBusinessData(BusinessDTO dto,String uri, CurrentUser user) {
if(StringUtils.isBlank(dto.getTable())){
throw new SysException("请传入对应的表名");
}
......@@ -91,13 +91,23 @@ public class BusinessConfigServiceImpl extends ServiceImpl<BusinessConfigMapper,
if(CollectionUtils.isEmpty(dto.getWhere())){
throw new SysException("where 条件不能为空");
}
if(dto.getWhere().stream().anyMatch(x -> StringUtils.isBlank(x.getKey()))
|| dto.getWhere().stream().anyMatch(x -> StringUtils.isBlank(x.getValue())) || dto.getWhere().stream().anyMatch(x -> StringUtils.isBlank(x.getQueryType()))) {
throw new SysException("where 条件不能key value queryType 都不能为空");
}
dto.getWhere().forEach(x->{
if(CollectionUtils.isEmpty(x.keySet())){
throw new SysException("条件 and 或者or 都必须说明");
}
x.forEach((k,v)->{
if(v.stream().anyMatch(y -> StringUtils.isBlank(y.getKey()))
|| v.stream().anyMatch(y -> ObjectUtils.isNotEmpty(y.getValue()))
|| v.stream().anyMatch(y -> StringUtils.isBlank(y.getQueryType()))) {
throw new SysException("where 条件不能key value queryType 都不能为空");
}
});
});
Map<String, String> heads = Maps.newHashMap();
heads.put("X-Token", user.getToken());
R<List<Map<String, Object>>> result = RestTemplateUtils.post(uri, heads,dto, new TypeToken<R<List<Map<String, Object>>>>() {}.getType(), null);
Map<String, String> uriVariables = Maps.newHashMap();
uriVariables.put("appId", user.getAppId());
R<Map<String, Object>> result = RestTemplateUtils.post(uri, heads,dto, new TypeToken<R<Map<String, Object>>>() {}.getType(), uriVariables);
return result.detach();
}
}
......@@ -16,6 +16,7 @@ import com.syc.slm.slmbi.enums.AccessType;
import com.syc.slm.slmbi.exception.SysException;
import com.syc.slm.slmbi.service.VariableService;
import com.syc.slm.slmbi.vo.*;
import lombok.NonNull;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
......@@ -125,8 +126,14 @@ public class VariableServiceImpl implements VariableService {
}
@Override
public Map<String, List<Map<String, HistoryVariableVo>>> getVariableHistoryDataList(VariableDataDTO variableDTO) {
return null;
public List<Map<String, Object>> getVariableHistoryDataList(@NonNull String uri,VariableDataDTO variableDTO,CurrentUser user) {
Map<String, String> heads = Maps.newHashMap();
heads.put("X-Token", user.getToken());
Map<String, String> uriVariables =SlmConstants.gson.fromJson(SlmConstants.gson.toJson(variableDTO),new TypeToken<Map<String,String>>(){}.getType());
uriVariables.put("appId",user.getAppId());
R<List<Map<String, Object>>> result = RestTemplateUtils.get(uri, heads, new TypeToken<R<List<Map<String, Object>>>>() {}.getType(), uriVariables);
return result.detach();
}
@Override
......
......@@ -23,6 +23,4 @@ public class BusinessConfigVo {
private String nameCn;
@ApiModelProperty(value = "表字段属性")
private String field;
@ApiModelProperty(value = "表字段时间属性")
private String fieldTime;
}
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