Commit 7fc8afcb authored by linruibiao's avatar linruibiao

接口编写

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