Commit b33da8f3 authored by 梁光意's avatar 梁光意

Merge remote-tracking branch 'remotes/origin/develop' into develop-fix

# Conflicts: # src/main/java/com/syc/slm/slmbi/service/impl/VariableServiceImpl.java
parents 4f66e3f4 9cc636c1
......@@ -53,6 +53,11 @@ public class BaseRestController {
protected String businessFiledData;
@Value("${dc_client.interfaces.variableHistoryDataList}")
protected String variableHistoryDataList;
@Value("${dc_client.interfaces.variableRealTimeDataList}")
protected String variableRealTimeDataList;
......
......@@ -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);
});
}
}
......@@ -87,9 +87,14 @@ public class VariableController extends BaseRestController{
@GetMapping("/real-time")
@ApiOperation("获取变量实时数据")
@ApiImplicitParam(name = "appId", value = "租户id", required = true,dataTypeClass = String.class)
public R<Map<String, List<Map<String, RealTimeVariableVo>>>> getVariableRealTimeDataList(@PathVariable String appId,
VariableDataDTO variableDTO) {
return call(()->(variableService.getVariableRealTimeDataList(variableDTO)));
public R<Map<String, List<Map<String, Object>>>> getVariableRealTimeDataList(HttpServletRequest request,@PathVariable String appId,
VariableRealTimeDTO variableDTO) {
return call(() -> {
CurrentUser currentUser = getCurrentUser(request);
return variableService.getVariableRealTimeDataList(dcClientHost + variableRealTimeDataList,
variableDTO,
currentUser);
});
}
@GetMapping("/source")
......@@ -112,8 +117,14 @@ 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,
VariableHistoryDataDTO 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;
}
package com.syc.slm.slmbi.dto;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* slm-bi
* 实时变量DTO
* @author : lin
* @date : 2021-03-30 15:05
**/
@ApiModel("变量DTO")
@Data
public class VariableHistoryDataDTO {
@ApiModelProperty(value = "所属设备", required = true)
private String deviceId;
@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 startTime;
@ApiModelProperty(value = "结束时间(时间戳)", required = true)
private String endTime;
@ApiModelProperty(value = "统计维度,如果是时间填time,如果是变量填variableCode", required = true)
private String x;
@ApiModelProperty(value = "统计维度如果是时间,请填时间格式如(yyyy-MM-dd HH:mm:ss),非时间为空", required = true)
private String format;
}
......@@ -4,7 +4,6 @@ import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* slm-bi
* 实时变量DTO
......@@ -13,11 +12,9 @@ import lombok.Data;
**/
@ApiModel("变量DTO")
@Data
public class VariableDataDTO {
public class VariableRealTimeDTO {
@ApiModelProperty(value = "所属设备", required = true)
private String deviceId;
@ApiModelProperty(value = "统计类型,代表(合计值(sum),平均值(avg),最大值(max),最小值(min) 中位数(middle))", required = true)
private String statisticsType;
@ApiModelProperty(value = "变量id", required = true)
private String variableId;
@ApiModelProperty(value = "变量Code", required = true)
......@@ -26,4 +23,6 @@ public class VariableDataDTO {
private String startTime;
@ApiModelProperty(value = "结束时间(时间戳)", required = true)
private String endTime;
@ApiModelProperty(value = "请填时间格式如(yyyy-MM-dd HH:mm:ss)", required = true)
private String format;
}
package com.syc.slm.slmbi.enums;
import javax.crypto.interfaces.PBEKey;
/**
* 统计类型
*
......@@ -24,7 +26,7 @@ public enum StatisticsType {
MAX("max"),
/**
* 最小值
* 最小值
*/
MIN("min"),
......@@ -37,9 +39,10 @@ public enum StatisticsType {
* 原值
*/
ORIGINAL("original");
private String value;
StatisticsType(String v){
value=v;
public String value;
StatisticsType(String v) {
value = v;
}
}
......@@ -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);
}
package com.syc.slm.slmbi.service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.syc.slm.slmbi.dto.QueryPageDTO;
import com.syc.slm.slmbi.dto.VariableDataDTO;
import com.syc.slm.slmbi.dto.VariableDTO;
import com.syc.slm.slmbi.dto.VariableSendDTO;
import com.syc.slm.slmbi.dto.*;
import com.syc.slm.slmbi.entity.CurrentUser;
import com.syc.slm.slmbi.vo.*;
import lombok.NonNull;
import java.util.List;
import java.util.Map;
......@@ -44,22 +42,28 @@ public interface VariableService {
/**
* 获取实时数据
* @param uri
* @param variableDTO
* @param user
* @return
*/
Map<String, List<Map<String, RealTimeVariableVo>>> getVariableRealTimeDataList(VariableDataDTO variableDTO);
Map<String, List<Map<String, Object>>> getVariableRealTimeDataList(@NonNull String uri,VariableRealTimeDTO variableDTO,CurrentUser user);
/**
* 获取历史数据
* @param uri
* @param variableDTO
* @param currentUser
* @return
*/
Map<String, List<Map<String, HistoryVariableVo>>> getVariableHistoryDataList(VariableDataDTO variableDTO);
List<Map<String, Object>> getVariableHistoryDataList(@NonNull String uri,
VariableHistoryDataDTO variableDTO,CurrentUser currentUser);
/**
* 下发
* @param sendDTO
* @param currentUser
* @param uri
*/
void send(VariableSendDTO sendDTO, CurrentUser currentUser,String uri);
}
......@@ -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();
}
}
......@@ -13,9 +13,11 @@ import com.syc.slm.common.core.util.RestTemplateUtils;
import com.syc.slm.slmbi.dto.*;
import com.syc.slm.slmbi.entity.CurrentUser;
import com.syc.slm.slmbi.enums.AccessType;
import com.syc.slm.slmbi.enums.StatisticsType;
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;
......@@ -51,8 +53,10 @@ public class VariableServiceImpl implements VariableService {
p.put("isCustomer",null);
p.put("current",variableDTO.getCurrent()+"");
p.put("size",variableDTO.getSize()+"");
Map<String,String> heads = Maps.newHashMap();
heads.put("X-Token",token);
R<Map<String, Object>> result = RestTemplateUtils.get(uri, new TypeToken<R<Map<String, Object>>>() {
R<Map<String, Object>> result = RestTemplateUtils.get(uri, heads, new TypeToken<R<Map<String, Object>>>() {
}.getType(), p);
Map<String, Object> detach = result.detach();
if (CollectionUtils.isNotEmpty(detach)) {
......@@ -100,7 +104,9 @@ public class VariableServiceImpl implements VariableService {
p.put("warranty_status", null);
p.put("page_num", queryPageDTO.getCurrent() + "");
p.put("page_size", queryPageDTO.getSize() + "");
R<Map<String, Object>> result = RestTemplateUtils.get(uri, new TypeToken<R<Map<String, Object>>>() {
Map<String, String> heads = Maps.newHashMap();
heads.put("X-Token", token);
R<Map<String, Object>> result = RestTemplateUtils.get(uri, heads, new TypeToken<R<Map<String, Object>>>() {
}.getType(), p);
Map<String, Object> detach = result.detach();
if (CollectionUtils.isNotEmpty(detach)) {
......@@ -115,14 +121,79 @@ public class VariableServiceImpl implements VariableService {
}
@Override
public Map<String, List<Map<String, RealTimeVariableVo>>> getVariableRealTimeDataList(VariableDataDTO variableDTO) {
return null;
public Map<String, List<Map<String, Object>>> getVariableRealTimeDataList(@NonNull String uri,VariableRealTimeDTO variableDTO,CurrentUser user) {
if(StringUtils.isBlank(uri)){
throw new SysException("请传入uri");
}
if(StringUtils.isBlank(variableDTO.getDeviceId())){
throw new SysException("请传入设备id");
}
if(StringUtils.isBlank(variableDTO.getVariableCode())){
throw new SysException("请传入变量code");
}
if(StringUtils.isBlank(variableDTO.getEndTime())){
throw new SysException("请传入结束时间");
}
if(StringUtils.isBlank(variableDTO.getStartTime())){
throw new SysException("请传入开始时间");
}
if(StringUtils.isBlank(variableDTO.getFormat())) {
throw new SysException(" 请填入时间格式");
}
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<Map<String, List<Map<String, Object>>>> result = RestTemplateUtils.get(uri, heads, new TypeToken<R<Map<String, List<Map<String, Object>>>>>() {}.getType(), uriVariables);
return result.detach();
}
@Override
public Map<String, List<Map<String, HistoryVariableVo>>> getVariableHistoryDataList(VariableDataDTO variableDTO) {
return null;
public List<Map<String, Object>> getVariableHistoryDataList(@NonNull String uri,
VariableHistoryDataDTO variableDTO,CurrentUser user) {
if(StringUtils.isBlank(uri)){
throw new SysException("请传入uri");
}
if(StringUtils.isBlank(variableDTO.getDeviceId())){
throw new SysException("请传入设备id");
}
if(StringUtils.isBlank(variableDTO.getVariableCode())){
throw new SysException("请传入变量code");
}
if(StringUtils.isBlank(variableDTO.getEndTime())){
throw new SysException("请传入结束时间");
}
if(StringUtils.isBlank(variableDTO.getStartTime())){
throw new SysException("请传入开始时间");
}
if(StringUtils.isBlank(variableDTO.getStatisticsType())){
throw new SysException("请传入统计类型");
}else{
if(!StatisticsType.SUM.value.equals(variableDTO.getStatisticsType()) &&
!StatisticsType.AVG.value.equals(variableDTO.getStatisticsType()) &&
!StatisticsType.MAX.value.equals(variableDTO.getStatisticsType()) &&
!StatisticsType.MIN.value.equals(variableDTO.getStatisticsType()) &&
!StatisticsType.MIDDLE.value.equals(variableDTO.getStatisticsType()) &&
!StatisticsType.ORIGINAL.value.equals(variableDTO.getStatisticsType())){
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> 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
......@@ -189,9 +260,11 @@ public class VariableServiceImpl implements VariableService {
}
private R<Map<String,String>> setDeptAndRole(CurrentUser user,String uri){
Map<String,String> heads = Maps.newHashMap();
heads.put("X-Token",user.getToken());
Map<String,String> uriVariables =Maps.newHashMap();
uriVariables.put("appId",user.getAppId());
return RestTemplateUtils.get(uri, new TypeToken<R<Map<String,String>>>() {}.getType(), uriVariables);
return RestTemplateUtils.get(uri, heads, new TypeToken<R<Map<String,String>>>() {}.getType(), uriVariables);
}
......
......@@ -23,6 +23,4 @@ public class BusinessConfigVo {
private String nameCn;
@ApiModelProperty(value = "表字段属性")
private String field;
@ApiModelProperty(value = "表字段时间属性")
private String fieldTime;
}
......@@ -12,4 +12,6 @@ dc_client:
variableList : /{appId}/variables/slm/tag/list?token={token}&from={from}&varType={varType}&type={type}&equipmentId={equipmentId}&customerId={customerId}&name={name}&desc={desc}&unit={unit}&keyword={keyword}&isCustomer={isCustomer}&current={current}&size={size}
deviceList : /{appId}/variables/device?token={token}&equipment_info_id={equipment_info_id}&q_name={q_name}&search_code={search_code}&warranty_status={warranty_status}&page_num={page_num}&page_size={page_size}
deptsRoles : /{appId}/users/depts-roles
businessFiledData : /{appId}/business/filed
\ No newline at end of file
businessFiledData : /{appId}/business/filed
variableHistoryDataList: /{appId}/variables/history?deviceId={deviceId}&endTime={endTime}&startTime={startTime}&statisticsType={statisticsType}&variableCode={variableCode}&variableId={variableId}&x={x}&format={format}
variableRealTimeDataList: /{appId}/variables/real-time?deviceId={deviceId}&endTime={endTime}&startTime={startTime}&variableCode={variableCode}&variableId={variableId}&format={format}
\ No newline at end of file
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