提交 ba976042 编写于 作者: sq3536's avatar sq3536

反查逻辑

上级 be285ae8
package cn.ibizlab.core.extensions.dto;
import cn.ibizlab.core.analysis.domain.DAMetric;
import cn.ibizlab.util.dict.Catalog;
import cn.ibizlab.util.dict.Option;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.Accessors;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@JsonIgnoreProperties(ignoreUnknown = true)
@Getter
@Setter
@NoArgsConstructor
@Accessors(chain = true)
public class LookupResult {
private List<String> keys;
private String metricId;
private String dimValue;
private DAMetric metric;
public String getField()
{
if(metric!=null&&(!StringUtils.isEmpty(metric.getFieldSet())))
{
JSONObject jo= JSON.parseObject(metric.getFieldSet());
String keyvaluefield="";
if(jo.containsKey("keyvaluefield"))
keyvaluefield = jo.getString("keyvaluefield");
if(StringUtils.isEmpty(keyvaluefield)&&(jo.containsKey("metricfield")))
keyvaluefield = jo.getString("metricfield");
return keyvaluefield;
}
return null;
}
@JsonFormat(pattern = "yyyy-MM-dd", locale = "zh", timezone = "GMT+8")
@JSONField(name = "startTime", format = "yyyy-MM-dd")
private Timestamp startTime;
@JsonFormat(pattern = "yyyy-MM-dd", locale = "zh", timezone = "GMT+8")
@JSONField(name = "endTime", format = "yyyy-MM-dd")
private Timestamp endTime;
private Integer page = 0;
private Integer size = 1000;
private Integer total = 0;
public Integer getTotalPages() {
return this.getSize() == 0 ? 1 : (int)Math.ceil((double)this.total / (double)this.getSize());
}
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", locale = "zh", timezone = "GMT+8")
@JSONField(name = "snapTime", format = "yyyy-MM-dd HH:mm:ss")
private Timestamp snapTime;
}
......@@ -364,7 +364,15 @@ public class BuildResultService {
}
@Cacheable( value="dataAnalyse",key="'rows:lookup:'+#p0.getId()")
public List<String> lookup(FetchParam fetchParam) {
public LookupResult lookup(FetchParam fetchParam) {
prepareFetchParam(fetchParam);
LookupResult lookupResult=new LookupResult();
lookupResult.setDimValue(fetchParam.getDimValue());
lookupResult.setMetricId(fetchParam.getMetricId());
if(fetchParam.getMetrics()!=null)
lookupResult.setMetric(fetchParam.getMetrics().get(fetchParam.getMetricId()));
lookupResult.setPage(fetchParam.getPage()).setSize(fetchParam.getSize()).setTotal(fetchParam.getTotal()).setStartTime(fetchParam.getStartTime()).setEndTime(fetchParam.getEndTime());
List<String> ret = new ArrayList<>();
if(!StringUtils.isEmpty(cassandraHost))
{
......@@ -389,7 +397,7 @@ public class BuildResultService {
}
else
{
//prepareFetchParam(fetchParam);
Map<String,Set<String>> tab = fetchParam.getDimTables();
tab.keySet().forEach(key->{
String[] args = key.split("\\|");
......@@ -397,6 +405,8 @@ public class BuildResultService {
String tableName = args[1];
Page<ExecResult> page = execResultExService.lookupResult(fetchParam.getPage(), fetchParam.getSize(), dsName, tableName, "keyvaluefield", fetchParam.getMetricId(), fetchParam.getDimValue(), fetchParam.getStartTime(), fetchParam.getEndTime());
if(lookupResult.getTotal()==0||lookupResult.getTotal()==null)
lookupResult.setTotal((int)page.getTotalElements());
page.getContent().forEach(item->{
ret.add(item.getKeyValueField());
});
......@@ -405,7 +415,9 @@ public class BuildResultService {
}
return ret;
lookupResult.setKeys(ret);
lookupResult.setSnapTime(new Timestamp(System.currentTimeMillis()));
return lookupResult;
}
......
......@@ -131,7 +131,7 @@
</select>
<select id="lookupResult" >
<select id="lookupResult" resultType="cn.ibizlab.core.rule.domain.ExecResult" >
select ${columns} from ${resultTableName} where ruleid = #{ruleid}
and RETVALUE=1 and DIMFIELD = #{dimfield}
......
......@@ -3,6 +3,7 @@ package cn.ibizlab.api.rest.extensions;
import cn.ibizlab.core.dict.extensions.service.DictDstService;
import cn.ibizlab.core.extensions.dto.FetchParam;
import cn.ibizlab.core.extensions.dto.FetchResult;
import cn.ibizlab.core.extensions.dto.LookupResult;
import cn.ibizlab.core.extensions.service.BuildResultService;
import cn.ibizlab.core.lite.domain.DstSystem;
import cn.ibizlab.core.lite.domain.MetaEntity;
......@@ -342,6 +343,26 @@ public class DstCoreResource
return ResponseEntity.ok(buildResultService.getAnalyseResult(param));
}
@RequestMapping(method = RequestMethod.GET, value = {"/dst/lookup/{metricId}/{dimValue}",
"/lite/lookup/{metricId}/{dimValue}"})
public ResponseEntity<LookupResult> lookup(@PathVariable(name = "metricId") String metricId, @PathVariable(name = "dimValue") String dimValue,
@RequestParam(name = "startTime",required = false) String startTime,
@RequestParam(name = "endTime",required = false) String endTime,
@RequestParam(name = "page",required = false) Integer page,
@RequestParam(name = "size",required = false) Integer size,
@RequestParam(name = "total",required = false) Integer total) {
FetchParam param=new FetchParam().setMetricId(metricId).setDimValue(dimValue)
.setStartTime(DataObject.getTimestampValue(startTime,null)).setEndTime(DataObject.getTimestampValue(endTime,null));
if(page!=null)
param.setPage(page);
if(size!=null)
param.setSize(size);
if(total!=null)
param.setTotal(total);
return ResponseEntity.ok(buildResultService.lookup(param));
}
@RequestMapping(method = RequestMethod.GET, value = {"/dst/report/{reportId}/{dimValue}.xls","/dst/report/{reportId}.xls",
"/lite/report/{reportId}/{dimValue}.xls","/lite/report/{reportId}.xls"})
public void exportReportdatas(@PathVariable(name = "reportId") String reportId, @PathVariable(name = "dimValue",required = false) String dimValue,
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册