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

提交

上级 cb3a98b0
......@@ -10,6 +10,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.stereotype.Repository;
import java.sql.Timestamp;
import java.util.Collection;
import java.util.List;
import java.util.UUID;
......@@ -125,7 +126,7 @@ public class ExecResultRepository {
public List<ExecResult> sum(List<String> ruleids, Integer retValue, List<String> dims, Timestamp start, Timestamp end) {
public List<ExecResult> sum(Collection<String> ruleids, Integer retValue, List<String> dims, Timestamp start, Timestamp end) {
LocalDate st = ExecResult.time2LocalDate(start);
LocalDate ed = ExecResult.time2LocalDate(end);
final ResultSet result = session.execute(select().column("ruleid").column("retvalue").column("dimfield").sum("metricfield").as("metricfield").
......@@ -137,7 +138,7 @@ public class ExecResultRepository {
return mapper.map(result).all();
}
public List<ExecResult> avg(List<String> ruleids, Integer retValue, List<String> dims, Timestamp start, Timestamp end) {
public List<ExecResult> avg(Collection<String> ruleids, Integer retValue, List<String> dims, Timestamp start, Timestamp end) {
LocalDate st = ExecResult.time2LocalDate(start);
LocalDate ed = ExecResult.time2LocalDate(end);
final ResultSet result = session.execute(select().column("ruleid").column("retvalue").column("dimfield").avg("metricfield").as("metricfield").
......@@ -149,7 +150,7 @@ public class ExecResultRepository {
return mapper.map(result).all();
}
public List<ExecResult> group(List<String> ruleids, Integer retValue, List<String> dims, String type, Timestamp start, Timestamp end) {
public List<ExecResult> group(Collection<String> ruleids, Integer retValue, List<String> dims, String type, Timestamp start, Timestamp end) {
if (type.equalsIgnoreCase("avg"))
return avg(ruleids, retValue, dims, start, end);
else
......
package cn.ibizlab.core.extensions.dto;
import cn.ibizlab.core.lite.extensions.domain.DataObj;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import java.math.BigDecimal;
@JsonIgnoreProperties(ignoreUnknown = true)
public class FetchItem extends DataObj {
// 表格展示类型:1. default(维度数据以行的形式展示),2. LIST_BOX(维度数据以列的形式展示)
public String getDisplayType() {
return this.getStringValue("displayType","default");
}
public FetchItem setDisplayType(String displayType) {
this.put("displayType", displayType);
return this;
}
public int getNo() {
return this.getIntegerValue("no",1);
}
public FetchItem setNo(int no) {
this.put("no",no);
return this;
}
public String getDimId() {
return this.getStringValue("dimId");
}
public FetchItem setDimId(String dimId) {
this.put("dimId", dimId);
this.put("itemId",dimId);
return this;
}
public String getDimName() {
return this.getStringValue("dimName");
}
public FetchItem setDimName(String dimName) {
this.put("dimName",dimName);
this.put("itemName",dimName);
return this;
}
public String getMetricId1() {
return this.getStringValue("metricId");
}
public FetchItem setMetricId(String metricId) {
this.put("metricId",metricId);
this.put("itemId",metricId);
return this;
}
public String getMetricName() {
return this.getStringValue("metricName");
}
public FetchItem setMetricName(String metricName) {
this.put("metricName",metricName);
this.put("itemName",metricName);
return this;
}
public BigDecimal getVal(String colId) {
return this.getBigDecimalValue(colId,BigDecimal.ZERO);
}
public FetchItem setVal(String colId, BigDecimal val) {
if(val==null)
val=BigDecimal.ZERO;
this.put(colId,val);
return this;
}
}
package cn.ibizlab.core.extensions.dto;
import cn.ibizlab.core.analysis.domain.DAMetric;
import cn.ibizlab.util.dict.CodeItem;
import cn.ibizlab.util.helper.DataObject;
import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
......@@ -12,10 +15,10 @@ import lombok.experimental.Accessors;
import org.springframework.util.StringUtils;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
@JsonIgnoreProperties(ignoreUnknown = true)
@Getter
......@@ -52,6 +55,8 @@ public class FetchParam {
private int page = 0;
private int size = 100;
private boolean filled = false;
public List<String> getDimValues()
{
if(dimValues == null&&(!includeChild)&&(!StringUtils.isEmpty(dimValue)))
......@@ -75,10 +80,28 @@ public class FetchParam {
@JsonIgnore
@JSONField(serialize = false)
private Map<String,List<String>> dimTables;
private CodeItem dimItem;
@JsonIgnore
@JSONField(serialize = false)
public CodeItem getDimItem()
{
return dimItem;
}
@JsonIgnore
@JSONField(serialize = false)
public FetchParam setDimItem(CodeItem dimItem)
{
this.dimItem = dimItem;
return this;
}
@JsonIgnore
@JSONField(serialize = false)
private Map<String,Set<String>> dimTables;
@JsonIgnore
@JSONField(serialize = false)
public Map<String,List<String>> getDimTables()
public Map<String,Set<String>> getDimTables()
{
if(dimTables==null)
dimTables = new LinkedHashMap<>();
......@@ -86,10 +109,125 @@ public class FetchParam {
}
@JsonIgnore
@JSONField(serialize = false)
public FetchParam getDimTables(Map<String,List<String>> dimTables)
public FetchParam setDimTables(Map<String, Set<String>> dimTables)
{
this.dimTables = dimTables;
return this;
}
@JsonIgnore
@JSONField(serialize = false)
private Map<String, DAMetric> metrics;
@JsonIgnore
@JSONField(serialize = false)
public Map<String,DAMetric> getMetrics()
{
if(metrics==null)
metrics = new LinkedHashMap<>();
return metrics;
}
@JsonIgnore
@JSONField(serialize = false)
public FetchParam setMetrics(Map<String,DAMetric> metrics)
{
this.metrics = metrics;
return this;
}
public Timestamp getStartTime() {
if(startTime!=null)
{
try {
return new Timestamp(DataObject.dayFormat.parse(DataObject.dayFormat.format(startTime)).getTime());
} catch (Exception exception) {
}
}
return getDefaultStartTimestamp();
}
public Timestamp getEndTime() {
if(endTime!=null)
{
try {
return new Timestamp(DataObject.dayFormat.parse(DataObject.dayFormat.format(endTime)+" 23:59:59").getTime());
} catch (Exception exception) {
}
}
return getDefaultEndTimestamp();
}
@JsonIgnore
@JSONField(serialize = false)
private List<VMConfig> vmConfigs;
@JsonIgnore
@JSONField(serialize = false)
private String group;
public static Timestamp getDefaultStartTimestamp() {
Calendar c = Calendar.getInstance();
Date d=new Date();
try {
d = DataObject.dayFormat.parse(DataObject.dayFormat.format(d));
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
c.setTime(d);
c.add(Calendar.MONTH, -1);
c.set(Calendar.DAY_OF_MONTH, 1);
return new Timestamp(c.getTime().getTime());
}
public static Timestamp getDefaultEndTimestamp() {
Calendar c = Calendar.getInstance();
Date d=new Date();
try {
d = DataObject.dayFormat.parse(DataObject.dayFormat.format(d)+" 23:59:59");
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
c.setTime(d);
int month=c.get(Calendar.MONTH);
c.set(Calendar.MONTH, month-1);
c.set(Calendar.DAY_OF_MONTH, c.getActualMaximum(Calendar.DAY_OF_MONTH));
return new Timestamp(c.getTime().getTime());
}
public static Timestamp getLastYear(Timestamp time)
{
Date date=new Date(time.getTime());
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
// 设置为当前时间
calendar.set(Calendar.YEAR, calendar.get(Calendar.YEAR) - 1);
// 设置为上一年
date = calendar.getTime();
Timestamp rt=new Timestamp(date.getTime());
return rt;
}
public static Timestamp getLastMonth(Timestamp time)
{
Date date=new Date(time.getTime());
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
// 设置为当前时间
calendar.set(Calendar.MONTH, calendar.get(Calendar.MONTH) - 1);
// 设置为上一个月
date = calendar.getTime();
Timestamp rt=new Timestamp(date.getTime());
return rt;
}
}
package cn.ibizlab.core.extensions.dto;
import cn.ibizlab.core.analysis.domain.DAMetric;
import cn.ibizlab.util.dict.CodeItem;
import cn.ibizlab.util.helper.DataObject;
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.StringUtils;
import java.sql.Timestamp;
import java.text.ParseException;
import java.util.*;
@JsonIgnoreProperties(ignoreUnknown = true)
@Getter
@Setter
@NoArgsConstructor
@Accessors(chain = true)
public class FetchResult {
// 表格展示类型:1. default(维度数据以行的形式展示),2. LIST_BOX(维度数据以列的形式展示)
private String displayType = "default";
private List<FetchItem> rows;
private List<VMConfig> headers;
public List<VMConfig> getHeaders() {
if(headers==null)
{
headers = new ArrayList<>();
headers.add(new VMConfig().setHeaderName("序号").setEntity("item").setField("no").setPinned("left"));
headers.add(new VMConfig().setHeaderName(getGroup()).setEntity("item").setField("itemName").setPinned("left"));
if(vmConfigs!=null)
headers.addAll(vmConfigs);
}
return headers;
}
public FetchResult trans2ListBox()
{
FetchResult listBox=new FetchResult();
List<VMConfig> vms=new ArrayList<>();
rows.forEach(row->{
VMConfig config=new VMConfig();
config.setHeaderName(row.getDimName()).setEntity("item").setField(row.getDimId()).setWidth(80);
vms.add(config);
});
this.setVmConfigs(vms);
return listBox;
}
@JsonIgnore
@JSONField(serialize = false)
private List<VMConfig> vmConfigs;
@JsonIgnore
@JSONField(serialize = false)
private String group;
public static FetchResult from(FetchParam fetchParam)
{
FetchResult fetchResult=new FetchResult();
fetchResult.setDisplayType(fetchParam.getDisplayType());
if(fetchParam.getVmConfigs()!=null)
{
fetchResult.setVmConfigs(fetchParam.getVmConfigs());
}
fetchResult.setGroup(StringUtils.isEmpty(fetchParam.getGroup())?"分项":fetchParam.getGroup());
return fetchResult;
}
}
......@@ -3,6 +3,7 @@ package cn.ibizlab.core.extensions.dto;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Getter;
import lombok.NoArgsConstructor;
......@@ -13,19 +14,21 @@ import org.springframework.util.StringUtils;
import java.util.*;
@JsonIgnoreProperties(ignoreUnknown = true)
@Getter
@Setter
@NoArgsConstructor
@Accessors(chain = true)
public class VMConfig {
private String headerName;
private String width;
private Integer width;
@JSONField(name = "entity")
@JsonProperty("entity")
private String buildId;
private String entity;
@JSONField(name = "field")
@JsonProperty("field")
private String metricId;
private String field;
private String pinned;
private List<VMConfig> children;
public Map<String, Set<String>> getBuilds(Map<String,Set<String>> builds)
......@@ -34,17 +37,17 @@ public class VMConfig {
{
builds = new LinkedHashMap<>();
}
if((!StringUtils.isEmpty(buildId)) && (!StringUtils.isEmpty(metricId)))
if((!StringUtils.isEmpty(entity)) && (!StringUtils.isEmpty(field)))
{
if(builds.containsKey(buildId))
if(builds.containsKey(entity))
{
builds.get(buildId).add(metricId);
builds.get(entity).add(field);
}
else
{
Set<String> metricIds = new LinkedHashSet<>();
metricIds.add(metricId);
builds.put(buildId,metricIds);
metricIds.add(field);
builds.put(entity,metricIds);
}
}
if(!ObjectUtils.isEmpty(children))
......
......@@ -20,6 +20,7 @@ import cn.ibizlab.core.rule.service.IExecLogService;
import cn.ibizlab.core.rule.service.IRuleItemService;
import cn.ibizlab.util.errors.BadRequestAlertException;
import cn.ibizlab.util.helper.CachedBeanCopier;
import cn.ibizlab.util.helper.Setting;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
......@@ -174,6 +175,14 @@ public class DABuildExService extends DABuildServiceImpl {
msg.setBatch(engineMQMsg.getBatch());
msg.setSystemid(et.getSystemId());
msg.setEngineId(engineMQMsg.getEngineId());
String resultDataSource = Setting.getValue(et.getExtParams(), "resultDataSource");
String resultTableName = Setting.getValue(et.getExtParams(), "resultTableName");
if(!StringUtils.isEmpty(resultDataSource)){
msg.setResultDataSource(resultDataSource);
}
if(!StringUtils.isEmpty(resultTableName)){
msg.setResultTableName(resultTableName);
}
ExecLog execlog=new ExecLog();
execlog.setId(msg.getId());
......
......@@ -238,20 +238,20 @@ public class DataObject {
}
try {
if(objValue instanceof BigDecimal){
return (BigDecimal)(objValue);
return ((BigDecimal)(objValue)).stripTrailingZeros();
}
if(objValue instanceof Double){
return BigDecimal.valueOf((Double)objValue);
return BigDecimal.valueOf((Double)objValue).stripTrailingZeros();
}
if(objValue instanceof Long){
return BigDecimal.valueOf((Long)objValue);
return BigDecimal.valueOf((Long)objValue).stripTrailingZeros();
}
String strValue = objValue.toString();
if(StringUtils.isEmpty(strValue)) {
return fDefault;
}
strValue = strValue.replace(",", "");
return BigDecimal.valueOf(Double.parseDouble(strValue));
return BigDecimal.valueOf(Double.parseDouble(strValue)).stripTrailingZeros();
} catch (Exception ex) {
return fDefault;
}
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册