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

调整报表

上级 ef9f2ef9
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
padding: 10px 0; padding: 10px 0;
> .vue-treeselect { > .vue-treeselect {
width: 14%; width: 300px;
> .vue-treeselect__control { > .vue-treeselect__control {
height: 40px; height: 40px;
...@@ -32,7 +32,7 @@ ...@@ -32,7 +32,7 @@
} }
> .el-select { > .el-select {
width: 9%; width: 150px;
} }
} }
......
package cn.ibizlab.core.extensions.domain; package cn.ibizlab.core.extensions.domain;
import cn.ibizlab.core.lite.extensions.domain.ModelObj; import cn.ibizlab.core.lite.extensions.domain.ModelObj;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data; import lombok.Data;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
...@@ -9,6 +12,7 @@ import java.math.BigDecimal; ...@@ -9,6 +12,7 @@ import java.math.BigDecimal;
import java.math.BigInteger; import java.math.BigInteger;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet;
import java.util.List; import java.util.List;
@Data @Data
...@@ -30,6 +34,8 @@ public class BaseRequest ...@@ -30,6 +34,8 @@ public class BaseRequest
'}'; '}';
} }
@JsonIgnore
@JSONField(serialize = false)
public String toString2() { public String toString2() {
return "BaseRequest{" + return "BaseRequest{" +
"id='" + id + '\'' + "id='" + id + '\'' +
...@@ -42,6 +48,7 @@ public class BaseRequest ...@@ -42,6 +48,7 @@ public class BaseRequest
} }
private List<ModelObj> datas; private List<ModelObj> datas;
private String modelId;
private String model; private String model;
private String engineId; private String engineId;
private String resultDataSource; private String resultDataSource;
...@@ -50,17 +57,26 @@ public class BaseRequest ...@@ -50,17 +57,26 @@ public class BaseRequest
private List<String> rules; private List<String> rules;
private List<String> ruleIds; private List<String> ruleIds;
private SimpleDateFormat format =new SimpleDateFormat("yyyyMMddHHmmss"); private HashSet<String> fillpropertys;
public String getBatch() public String getBatch()
{ {
if(batch==null || batch.equals("")) if(batch==null || batch.equals(""))
{ {
batch= format.format(new java.util.Date())+"["+model+"]"; batch= new SimpleDateFormat("yyyyMMddHHmmss").format(new java.util.Date())+"["+model+"]";
} }
return this.batch; return this.batch;
} }
public BaseRequest copy(boolean reset)
{
BaseRequest baseRequest = JSON.parseObject(JSON.toJSONString(this),BaseRequest.class);
return baseRequest;
}
} }
...@@ -30,10 +30,15 @@ import java.util.*; ...@@ -30,10 +30,15 @@ import java.util.*;
@Accessors(chain = true) @Accessors(chain = true)
public class FetchParam { public class FetchParam {
@JsonIgnore
@JSONField(serialize = false)
private String id;
@JsonIgnore @JsonIgnore
@JSONField(serialize = false) @JSONField(serialize = false)
public String getId() { public String getId() {
if(StringUtils.isEmpty(id))
{
String str = "FetchParam{" + String str = "FetchParam{" +
"reportId='" + reportId + '\'' + "reportId='" + reportId + '\'' +
", chartId='" + chartId + '\'' + ", chartId='" + chartId + '\'' +
...@@ -52,13 +57,16 @@ public class FetchParam { ...@@ -52,13 +57,16 @@ public class FetchParam {
", total=" + total + ", total=" + total +
", group='" + group + '\'' + ", group='" + group + '\'' +
'}'; '}';
return DigestUtils.md5DigestAsHex(str.getBytes()); id = DigestUtils.md5DigestAsHex(str.getBytes());
}
return id;
} }
private String reportId; private String reportId;
private String chartId; private String chartId;
private String buildId; private String buildId;
private String title;
// 表格展示类型:1. default(维度数据以行的形式展示),2. LIST_BOX(维度数据以列的形式展示) // 表格展示类型:1. default(维度数据以行的形式展示),2. LIST_BOX(维度数据以列的形式展示)
private String displayType = "default"; private String displayType = "default";
......
...@@ -3,6 +3,7 @@ package cn.ibizlab.core.extensions.dto; ...@@ -3,6 +3,7 @@ package cn.ibizlab.core.extensions.dto;
import cn.ibizlab.core.analysis.domain.DAMetric; import cn.ibizlab.core.analysis.domain.DAMetric;
import cn.ibizlab.util.dict.Catalog; import cn.ibizlab.util.dict.Catalog;
import cn.ibizlab.util.dict.CodeItem; import cn.ibizlab.util.dict.CodeItem;
import cn.ibizlab.util.dict.Option;
import cn.ibizlab.util.helper.DataObject; import cn.ibizlab.util.helper.DataObject;
import com.alibaba.fastjson.annotation.JSONField; import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonFormat;
...@@ -30,6 +31,8 @@ public class FetchResult { ...@@ -30,6 +31,8 @@ public class FetchResult {
// 表格展示类型:1. default(维度数据以行的形式展示),2. LIST_BOX(维度数据以列的形式展示) // 表格展示类型:1. default(维度数据以行的形式展示),2. LIST_BOX(维度数据以列的形式展示)
private String displayType = "default"; private String displayType = "default";
private String title;
private List<FetchItem> rows; private List<FetchItem> rows;
private List<VMConfig> headers; private List<VMConfig> headers;
...@@ -38,8 +41,8 @@ public class FetchResult { ...@@ -38,8 +41,8 @@ public class FetchResult {
if(headers==null) if(headers==null)
{ {
headers = new ArrayList<>(); headers = new ArrayList<>();
headers.add(new VMConfig().setHeaderName("序号").setEntity("item").setField("no").setPinned("left")); headers.add(new VMConfig().setHeaderName("序号").setEntity("item").setWidth(50).setField("no").setPinned("left"));
headers.add(new VMConfig().setHeaderName(getGroup()).setEntity("item").setField("itemName").setPinned("left")); headers.add(new VMConfig().setHeaderName(getGroup()).setEntity("item").setWidth(250).setField("itemName").setPinned("left"));
if(vmConfigs!=null) if(vmConfigs!=null)
headers.addAll(vmConfigs); headers.addAll(vmConfigs);
} }
...@@ -104,14 +107,17 @@ public class FetchResult { ...@@ -104,14 +107,17 @@ public class FetchResult {
@JSONField(serialize = false) @JSONField(serialize = false)
private List<VMConfig> vmConfigs; private List<VMConfig> vmConfigs;
@JsonIgnore
@JSONField(serialize = false)
private String group; private String group;
private Catalog dict; private Catalog dict;
private String selectValue; private String selectValue;
@JsonIgnore
@JSONField(serialize = false)
private Option selectDimItem;
@JsonFormat(pattern = "yyyy-MM-dd", locale = "zh", timezone = "GMT+8") @JsonFormat(pattern = "yyyy-MM-dd", locale = "zh", timezone = "GMT+8")
@JSONField(name = "startTime", format = "yyyy-MM-dd") @JSONField(name = "startTime", format = "yyyy-MM-dd")
private Timestamp startTime; private Timestamp startTime;
...@@ -119,6 +125,12 @@ public class FetchResult { ...@@ -119,6 +125,12 @@ public class FetchResult {
@JSONField(name = "endTime", format = "yyyy-MM-dd") @JSONField(name = "endTime", format = "yyyy-MM-dd")
private Timestamp endTime; private Timestamp endTime;
private String snapId;
@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;
public static FetchResult from(FetchParam fetchParam) public static FetchResult from(FetchParam fetchParam)
{ {
FetchResult fetchResult=new FetchResult(); FetchResult fetchResult=new FetchResult();
...@@ -129,7 +141,8 @@ public class FetchResult { ...@@ -129,7 +141,8 @@ public class FetchResult {
fetchResult.setVmConfigs(fetchParam.getVmConfigs()); fetchResult.setVmConfigs(fetchParam.getVmConfigs());
} }
fetchResult.setGroup(StringUtils.isEmpty(fetchParam.getGroup())?"分项":fetchParam.getGroup()); fetchResult.setGroup(StringUtils.isEmpty(fetchParam.getGroup())?"分项":fetchParam.getGroup());
fetchResult.setDict(fetchParam.getDict()).setSelectValue(fetchParam.getDimValue()).setStartTime(fetchParam.getStartTime()).setEndTime(fetchParam.getEndTime()); fetchResult.setTitle(fetchParam.getTitle()).setDict(fetchParam.getDict()).setSelectValue(fetchParam.getDimValue()).setStartTime(fetchParam.getStartTime()).setEndTime(fetchParam.getEndTime()).setSelectDimItem(fetchParam.getDimItem());
return fetchResult; return fetchResult;
} }
......
...@@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONArray; ...@@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.annotation.JSONField; import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Getter; import lombok.Getter;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
...@@ -18,10 +19,18 @@ import java.util.*; ...@@ -18,10 +19,18 @@ import java.util.*;
@Getter @Getter
@Setter @Setter
@NoArgsConstructor @NoArgsConstructor
@JsonInclude(JsonInclude.Include.NON_EMPTY)
@Accessors(chain = true) @Accessors(chain = true)
public class VMConfig { public class VMConfig {
private String headerName; private String headerName;
private Integer width; private Integer width;
public Integer getWidth() {
if(width==null&&(!StringUtils.isEmpty(field)))
return 100;
return width;
}
@JSONField(name = "entity") @JSONField(name = "entity")
@JsonProperty("entity") @JsonProperty("entity")
private String entity; private String entity;
...@@ -29,8 +38,16 @@ public class VMConfig { ...@@ -29,8 +38,16 @@ public class VMConfig {
@JsonProperty("field") @JsonProperty("field")
private String field; private String field;
private String pinned; private String pinned;
private Boolean hide;
private List<VMConfig> children; private List<VMConfig> children;
@JsonIgnore
@JSONField(serialize = false)
public boolean isHide()
{
return hide!=null&&hide;
}
public void setChildren(List<VMConfig> children) { public void setChildren(List<VMConfig> children) {
if(children!=null) if(children!=null)
children.forEach(item->{ children.forEach(item->{
......
...@@ -10,15 +10,19 @@ import cn.ibizlab.core.analysis.service.impl.DAReportServiceImpl; ...@@ -10,15 +10,19 @@ import cn.ibizlab.core.analysis.service.impl.DAReportServiceImpl;
import cn.ibizlab.core.dict.extensions.service.DictDstService; import cn.ibizlab.core.dict.extensions.service.DictDstService;
import cn.ibizlab.core.extensions.cql.ExecResultRepository; import cn.ibizlab.core.extensions.cql.ExecResultRepository;
import cn.ibizlab.core.extensions.dto.*; import cn.ibizlab.core.extensions.dto.*;
import cn.ibizlab.core.extensions.util.ExcelTool;
import cn.ibizlab.core.rule.domain.ExecResult; import cn.ibizlab.core.rule.domain.ExecResult;
import cn.ibizlab.core.rule.service.IExecResultService; import cn.ibizlab.core.rule.service.IExecResultService;
import cn.ibizlab.util.dict.Catalog; import cn.ibizlab.util.dict.Catalog;
import cn.ibizlab.util.dict.CodeItem; import cn.ibizlab.util.dict.CodeItem;
import cn.ibizlab.util.dict.CodeList; import cn.ibizlab.util.dict.CodeList;
import cn.ibizlab.util.dict.Option; import cn.ibizlab.util.dict.Option;
import cn.ibizlab.util.helper.DataObject;
import cn.ibizlab.util.helper.Setting; import cn.ibizlab.util.helper.Setting;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder; import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.datastax.driver.core.PagingState; import com.datastax.driver.core.PagingState;
import com.datastax.driver.core.ResultSet; import com.datastax.driver.core.ResultSet;
...@@ -36,8 +40,12 @@ import org.springframework.util.Assert; ...@@ -36,8 +40,12 @@ import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
import java.io.File;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.*; import java.util.*;
import static com.datastax.driver.core.querybuilder.QueryBuilder.lte; import static com.datastax.driver.core.querybuilder.QueryBuilder.lte;
...@@ -82,6 +90,10 @@ public class BuildResultService { ...@@ -82,6 +90,10 @@ public class BuildResultService {
@Lazy @Lazy
private ExecResultExService execResultExService; private ExecResultExService execResultExService;
@Autowired
@Lazy
BuildResultService proxy;
@Value("${defaultResultDataSource:default}") @Value("${defaultResultDataSource:default}")
private String Default_ResultDataSource; private String Default_ResultDataSource;
...@@ -89,7 +101,7 @@ public class BuildResultService { ...@@ -89,7 +101,7 @@ public class BuildResultService {
private String Default_ResultTableName; private String Default_ResultTableName;
private void prepareFetchParam(FetchParam fetchParam) public void prepareFetchParam(FetchParam fetchParam)
{ {
if(fetchParam.isFilled()) if(fetchParam.isFilled())
return; return;
...@@ -109,6 +121,7 @@ public class BuildResultService { ...@@ -109,6 +121,7 @@ public class BuildResultService {
if(!StringUtils.isEmpty(daReport.getGroup())) if(!StringUtils.isEmpty(daReport.getGroup()))
fetchParam.setGroup(daReport.getGroup()); fetchParam.setGroup(daReport.getGroup());
fetchParam.setTitle(daReport.getReportName());
} }
} }
else if(!StringUtils.isEmpty(fetchParam.getChartId())) else if(!StringUtils.isEmpty(fetchParam.getChartId()))
...@@ -123,6 +136,8 @@ public class BuildResultService { ...@@ -123,6 +136,8 @@ public class BuildResultService {
if(!StringUtils.isEmpty(daChart.getGroup())) if(!StringUtils.isEmpty(daChart.getGroup()))
fetchParam.setGroup(daChart.getGroup()); fetchParam.setGroup(daChart.getGroup());
fetchParam.setTitle(daChart.getChartName());
} }
} }
...@@ -201,6 +216,7 @@ public class BuildResultService { ...@@ -201,6 +216,7 @@ public class BuildResultService {
dimValues.add(codeItem.getValue().toString()); dimValues.add(codeItem.getValue().toString());
}); });
} }
if(dimValues.size()==0)
dimValues.add(fetchParam.getDimValue()); dimValues.add(fetchParam.getDimValue());
fetchParam.setDimValues(dimValues); fetchParam.setDimValues(dimValues);
} }
...@@ -473,7 +489,7 @@ public class BuildResultService { ...@@ -473,7 +489,7 @@ public class BuildResultService {
else else
bcalsum=true; bcalsum=true;
sumobj.setNo(no).setDimId(fetchParam.getDimValue()).setDimName("合计"); sumobj.setNo(no).setDimId(fetchParam.getDimValue()).setDimName((bcalsum||fetchParam.getDimItem()==null)?"合计":fetchParam.getDimItem().getLabel());
for(DAMetric metric:fetchParam.getMetrics().values()) for(DAMetric metric:fetchParam.getMetrics().values())
{ {
sumobj.setVal(metric.getMetricId(),BigDecimal.ZERO); sumobj.setVal(metric.getMetricId(),BigDecimal.ZERO);
...@@ -701,12 +717,18 @@ public class BuildResultService { ...@@ -701,12 +717,18 @@ public class BuildResultService {
} }
@Cacheable( value="dataAnalyse",key="'rows:cg:'+#p0.getId()")
public FetchResult getReportConfig(FetchParam fetchParam)
{
prepareFetchParam(fetchParam);
return FetchResult.from(fetchParam);
}
@Cacheable( value="dataAnalyse",key="'rows:ar:'+#p0.getId()") @Cacheable( value="dataAnalyse",key="'rows:ar:'+#p0.getId()")
public FetchResult getAnalyseResult(FetchParam fetchParam) public FetchResult getAnalyseResult(FetchParam fetchParam)
{ {
List<FetchItem> rows = this.getResult(fetchParam); List<FetchItem> rows = this.getResult(fetchParam);
return FetchResult.from(fetchParam).setRows(rows); return FetchResult.from(fetchParam).setRows(rows).setSnapId(fetchParam.getId()).setSnapTime(new Timestamp(System.currentTimeMillis()));
} }
@CacheEvict( value = "dataAnalyse",allEntries = true) @CacheEvict( value = "dataAnalyse",allEntries = true)
...@@ -714,4 +736,80 @@ public class BuildResultService { ...@@ -714,4 +736,80 @@ public class BuildResultService {
{ {
} }
public File exportExcel(FetchParam fetchParam) {
FetchResult result=proxy.getAnalyseResult(fetchParam);
Assert.notNull(result,"报表数据查询失败");
Map<String, Object> resultDataMap = new HashMap<String, Object>();
String headname = result.getTitle();// 报表名称
Timestamp starttime = result.getStartTime();// 查询开始时间
Timestamp endtime = result.getEndTime();// 查询结束时间
List<Map<String,String>> titleList = new ArrayList<Map<String,String>>();
{
Map<String, String> titleMap = new HashMap<String, String>();
titleMap.put("id", "report");
titleMap.put("pid", "0");
titleMap.put("content", headname);
titleMap.put("fieldName", "report");
titleList.add(titleMap);
}
{
Map<String, String> titleMap = new HashMap<String, String>();
titleMap.put("id", "filter");
titleMap.put("pid", "report");
titleMap.put("content", DataObject.dayFormat.format(result.getStartTime()).concat("到").concat(DataObject.dayFormat.format(result.getEndTime())));
titleMap.put("fieldName", "filter");
titleList.add(titleMap);
this.onHandleColumn(result.getHeaders(),titleList,"filter");
}
return this.onCreateExcelFile(titleList, result.getRows(), headname, headname+fetchParam.getId(), starttime, endtime);
}
public List<Map<String,String>> onHandleColumn(List<VMConfig> headers,List<Map<String,String>> columnDataList,String pid) {
if(columnDataList==null) columnDataList = new ArrayList<Map<String,String>>();
if(StringUtils.isEmpty(pid)) pid="0";
for(VMConfig col:headers){
Map<String,String> titleMap = new HashMap<String,String>();
String field = StringUtils.isEmpty(col.getField())? IdWorker.get32UUID():col.getField();
if(col.isHide()) continue;
titleMap.put("id", field);
titleMap.put("pid", pid);
titleMap.put("content",col.getHeaderName());
titleMap.put("fieldName", field);
columnDataList.add(titleMap);
if(!ObjectUtils.isEmpty(col.getChildren()))
onHandleColumn(col.getChildren(),columnDataList,field);
}
return columnDataList;
}
public File onCreateExcelFile(List<Map<String,String>> titleList, List<FetchItem> rowList, String headName, String fileName, Timestamp startTime, Timestamp endTime) {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
Date date = new Date();
String strNowDate = simpleDateFormat.format(date);
String dirPath=System.getProperty("java.io.tmpdir") +"reportExcel" + File.separator + strNowDate + File.separator;
File dir=new File(dirPath);
if(!dir.exists())
dir.mkdirs();
String strFilePath = dirPath +fileName + ".xls";
ExcelTool excelTool = new ExcelTool("报表", 20, 20);
try {
excelTool.exportExcel(excelTool.columnTransformer(titleList, "id", "pid", "content", "fieldName", "0"), rowList, strFilePath, true, false);
} catch (Exception exception) {
exception.printStackTrace();
}
File file=new File(strFilePath);
if(file.exists())
return file;
return null;
}
} }
...@@ -15,6 +15,7 @@ import cn.ibizlab.core.lite.extensions.service.LiteDataCallback; ...@@ -15,6 +15,7 @@ import cn.ibizlab.core.lite.extensions.service.LiteDataCallback;
import cn.ibizlab.core.lite.extensions.service.LiteDataService; import cn.ibizlab.core.lite.extensions.service.LiteDataService;
import cn.ibizlab.core.lite.extensions.service.LiteModelService; import cn.ibizlab.core.lite.extensions.service.LiteModelService;
import cn.ibizlab.core.rule.domain.ExecLog; import cn.ibizlab.core.rule.domain.ExecLog;
import cn.ibizlab.core.rule.domain.RuleEngine;
import cn.ibizlab.core.rule.domain.RuleItem; import cn.ibizlab.core.rule.domain.RuleItem;
import cn.ibizlab.core.rule.service.IExecLogService; import cn.ibizlab.core.rule.service.IExecLogService;
import cn.ibizlab.core.rule.service.IRuleItemService; import cn.ibizlab.core.rule.service.IRuleItemService;
...@@ -35,6 +36,7 @@ import org.springframework.context.annotation.Lazy; ...@@ -35,6 +36,7 @@ import org.springframework.context.annotation.Lazy;
import org.springframework.context.annotation.Primary; import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
import java.io.File; import java.io.File;
...@@ -123,10 +125,6 @@ public class DABuildExService extends DABuildServiceImpl { ...@@ -123,10 +125,6 @@ public class DABuildExService extends DABuildServiceImpl {
* @return * @return
*/ */
@Override @Override
@Caching( evict = {
@CacheEvict(value ={"dabuild","dabuilddims"}, key = "'row:'+#p0.buildId"),
@CacheEvict( value="dataAnalyse",allEntries = true)
})
public DABuild run(DABuild et) { public DABuild run(DABuild et) {
if(!StringUtils.isEmpty(et.getBuildId())) if(!StringUtils.isEmpty(et.getBuildId()))
{ {
...@@ -179,14 +177,53 @@ public class DABuildExService extends DABuildServiceImpl { ...@@ -179,14 +177,53 @@ public class DABuildExService extends DABuildServiceImpl {
public void processData(EngineMQMsg engineMQMsg){ public void processData(EngineMQMsg engineMQMsg){
DABuild et = get(engineMQMsg.getEngineId());
try{ try{
BaseRequest msg=new BaseRequest(); BaseRequest msg=proxy.getRequest(engineMQMsg.getEngineId(),engineMQMsg.getBatch()).copy(true);
msg.setId(IdWorker.getIdStr()); msg.setId(IdWorker.getIdStr());
ExecLog execlog=new ExecLog();
execlog.setId(msg.getId());
execlog.setName(msg.getBatch());
execlog.setKeyValueField(msg.getModel());
execlog.setSystemId(msg.getSystemid());
ruExecLogService.create(execlog);
msg.setDatas(liteDataService.getModelObjs(msg.getModelId(),msg.getFillpropertys(),engineMQMsg.getDatas()));
analyseEntityServiceImpl.processAll(msg);
}catch (Exception ex){
log.error(String.format("构建数据错误:%1$s", ex.getMessage()));
ex.printStackTrace();
}
String updateSql = "UPDATE ibzdabuild SET processed=(CASE WHEN processed is null then 0 else processed end+#{et.count}),lastruntime=CASE WHEN total <= processed THEN #{et.runtime} ELSE lastruntime END," +
"BUILDSTATE=CASE WHEN total <= processed THEN 'FINISH' ELSE BUILDSTATE END WHERE buildid = #{et.engineId}";
HashMap<String, Object> param = new HashMap<>();
param.put("count", engineMQMsg.getCount());
param.put("runtime", engineMQMsg.getRunTime());
param.put("engineId", engineMQMsg.getEngineId());
this.execute(updateSql, param);
if(this.count(Wrappers.<DABuild>lambdaQuery().eq(DABuild::getBuildId,engineMQMsg.getEngineId()).eq(DABuild::getState,"FINISH"))==1)
{
proxy.resetRequest(engineMQMsg.getEngineId(),engineMQMsg.getBatch());
proxy.resetBuild(engineMQMsg.getEngineId());
proxy.resetDataAnalyseResult();
}
}
@Cacheable(value ="dabuild", key = "'batch:'+#p0+#p1")
public BaseRequest getRequest(String id,String batch)
{
DABuild et = get(id);
BaseRequest msg=new BaseRequest();
msg.setModelId(et.getModelId());
msg.setModel(et.getModelName()); msg.setModel(et.getModelName());
msg.setBatch(engineMQMsg.getBatch()); msg.setBatch(batch);
msg.setSystemid(et.getSystemId()); msg.setSystemid(et.getSystemId());
msg.setEngineId(engineMQMsg.getEngineId()); msg.setEngineId(id);
String resultDataSource = Setting.getValue(et.getExtParams(), "resultDataSource"); String resultDataSource = Setting.getValue(et.getExtParams(), "resultDataSource");
String resultTableName = Setting.getValue(et.getExtParams(), "resultTableName"); String resultTableName = Setting.getValue(et.getExtParams(), "resultTableName");
if(StringUtils.isEmpty(resultDataSource)){ if(StringUtils.isEmpty(resultDataSource)){
...@@ -198,12 +235,6 @@ public class DABuildExService extends DABuildServiceImpl { ...@@ -198,12 +235,6 @@ public class DABuildExService extends DABuildServiceImpl {
msg.setResultDataSource(resultDataSource); msg.setResultDataSource(resultDataSource);
msg.setResultTableName(resultTableName); msg.setResultTableName(resultTableName);
ExecLog execlog=new ExecLog();
execlog.setId(msg.getId());
execlog.setName(msg.getBatch());
execlog.setKeyValueField(msg.getModel());
execlog.setSystemId(msg.getSystemid());
ruExecLogService.create(execlog);
List<String> ruleIds = new ArrayList<>(); List<String> ruleIds = new ArrayList<>();
List<String> rulePaths = new ArrayList<>(); List<String> rulePaths = new ArrayList<>();
...@@ -216,10 +247,8 @@ public class DABuildExService extends DABuildServiceImpl { ...@@ -216,10 +247,8 @@ public class DABuildExService extends DABuildServiceImpl {
metrics.add(daMetric.getMetricId()); metrics.add(daMetric.getMetricId());
}); });
if(metrics.size() == 0){
log.error(String.format("构建数据失败:未配置指标")); Assert.notEmpty(metrics,"构建数据失败:未配置指标");
return;
}
ruleItemService.list(Wrappers.<RuleItem>lambdaQuery().in(RuleItem::getRuleId, metrics)) ruleItemService.list(Wrappers.<RuleItem>lambdaQuery().in(RuleItem::getRuleId, metrics))
.forEach(ruleItem -> { .forEach(ruleItem -> {
...@@ -238,10 +267,8 @@ public class DABuildExService extends DABuildServiceImpl { ...@@ -238,10 +267,8 @@ public class DABuildExService extends DABuildServiceImpl {
fillpropertys.addAll(JSON.toJavaObject(JSON.parseArray(ruleItem.getCond()), LinkedHashSet.class)); fillpropertys.addAll(JSON.toJavaObject(JSON.parseArray(ruleItem.getCond()), LinkedHashSet.class));
}); });
if(ruleIds.size() == 0){ Assert.notEmpty(ruleIds,"构建数据失败:无有效规则");
log.error(String.format("构建数据失败:无有效规则"));
return;
}
dataModel.getAllProperty().forEach(prop->{ dataModel.getAllProperty().forEach(prop->{
if(fillpropertys.contains(prop.getPropertyName())) if(fillpropertys.contains(prop.getPropertyName()))
...@@ -255,26 +282,33 @@ public class DABuildExService extends DABuildServiceImpl { ...@@ -255,26 +282,33 @@ public class DABuildExService extends DABuildServiceImpl {
} }
}); });
msg.setFillpropertys(fillpropertys);
msg.setRuleIds(ruleIds); msg.setRuleIds(ruleIds);
msg.setRules(rulePaths); msg.setRules(rulePaths);
msg.setDatas(liteDataService.getModelObjs(et.getModelId(),fillpropertys,engineMQMsg.getDatas())); return msg;
}
analyseEntityServiceImpl.processAll(msg); @CacheEvict(value ="dabuild", key = "'batch:'+#p0+#p1")
public void resetRequest(String id,String batch)
{
}catch (Exception ex){
log.error(String.format("构建数据错误:%1$s", ex.getMessage()));
ex.printStackTrace();
} }
String updateSql = "UPDATE ibzdabuild SET processed=(CASE WHEN processed is null then 0 else processed end+#{et.count}),lastruntime=CASE WHEN total <= processed THEN #{et.runtime} ELSE lastruntime END," + @CacheEvict( value="dataAnalyse",allEntries = true)
"BUILDSTATE=CASE WHEN total <= processed THEN 'FINISH' ELSE BUILDSTATE END WHERE buildid = #{et.engineId}"; public void resetDataAnalyseResult()
HashMap<String, Object> param = new HashMap<>(); {
param.put("count", engineMQMsg.getCount());
param.put("runtime", engineMQMsg.getRunTime()); }
param.put("engineId", engineMQMsg.getEngineId());
this.execute(updateSql, param); @CacheEvict(value ={"dabuild","dabuilddims"}, key = "'row:'+#p0")
public void resetBuild(String id)
{
} }
@Autowired
@Lazy
DABuildExService proxy;
@Cacheable(value ="dabuilddims", key = "'row:'+#p0") @Cacheable(value ="dabuilddims", key = "'row:'+#p0")
public List<DADimension> getDims(String id) public List<DADimension> getDims(String id)
...@@ -282,6 +316,7 @@ public class DABuildExService extends DABuildServiceImpl { ...@@ -282,6 +316,7 @@ public class DABuildExService extends DABuildServiceImpl {
return this.get(id).getDadimension(); return this.get(id).getDadimension();
} }
@Override @Override
@Transactional @Transactional
@CacheEvict(value ={"dabuild","dabuilddims"}, key = "'row:'+#p0.buildId") @CacheEvict(value ={"dabuild","dabuilddims"}, key = "'row:'+#p0.buildId")
......
...@@ -23,6 +23,8 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers; ...@@ -23,6 +23,8 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.context.annotation.Lazy; import org.springframework.context.annotation.Lazy;
import org.springframework.context.annotation.Primary; import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -133,14 +135,53 @@ public class RuleEngineExService extends RuleEngineServiceImpl { ...@@ -133,14 +135,53 @@ public class RuleEngineExService extends RuleEngineServiceImpl {
protected IExecLogService ruExecLogService; protected IExecLogService ruExecLogService;
public void processData(EngineMQMsg engineMQMsg){ public void processData(EngineMQMsg engineMQMsg){
RuleEngine et = get(engineMQMsg.getEngineId());
try{ try{
BaseRequest msg=new BaseRequest(); BaseRequest msg=proxy.getRequest(engineMQMsg.getEngineId(),engineMQMsg.getBatch()).copy(true);
msg.setId(IdWorker.getIdStr()); msg.setId(IdWorker.getIdStr());
ExecLog execlog=new ExecLog();
execlog.setId(msg.getId());
execlog.setName(msg.getBatch());
execlog.setKeyValueField(msg.getModel());
execlog.setSystemId(msg.getSystemid());
ruExecLogService.create(execlog);
msg.setDatas(liteDataService.getModelObjs(msg.getModelId(),msg.getFillpropertys(),engineMQMsg.getDatas()));
baseEntityService.processAll(msg);
}catch (Exception ex){
log.error(String.format("构建数据错误:%1$s", ex.getMessage()));
ex.printStackTrace();
}
String updateSql = "UPDATE ibzruleengine SET processed=(CASE WHEN processed is null then 0 else processed end+#{et.count}),lastruntime=CASE WHEN total <= processed THEN #{et.runtime} ELSE lastruntime END," +
"EXECSTATE=CASE WHEN total <= processed THEN 'FINISH' ELSE EXECSTATE END WHERE engineid = #{et.engineId}";
HashMap<String, Object> param = new HashMap<>();
param.put("count", engineMQMsg.getCount());
param.put("runtime", engineMQMsg.getRunTime());
param.put("engineId", engineMQMsg.getEngineId());
this.execute(updateSql, param);
if(this.count(Wrappers.<RuleEngine>lambdaQuery().eq(RuleEngine::getEngineId,engineMQMsg.getEngineId()).eq(RuleEngine::getState,"FINISH"))==1)
{
proxy.resetRequest(engineMQMsg.getEngineId(),engineMQMsg.getBatch());
}
}
@Autowired
@Lazy
RuleEngineExService proxy;
@Cacheable(value ="ruleengine", key = "'batch:'+#p0+#p1")
public BaseRequest getRequest(String id,String batch)
{
RuleEngine et = get(id);
BaseRequest msg=new BaseRequest();
msg.setModelId(et.getModelId());
msg.setModel(et.getModelName()); msg.setModel(et.getModelName());
msg.setBatch(engineMQMsg.getBatch()); msg.setBatch(batch);
msg.setSystemid(et.getSystemId()); msg.setSystemid(et.getSystemId());
msg.setEngineId(engineMQMsg.getEngineId()); msg.setEngineId(id);
String resultDataSource = Setting.getValue(et.getExtParams(), "resultDataSource"); String resultDataSource = Setting.getValue(et.getExtParams(), "resultDataSource");
String resultTableName = Setting.getValue(et.getExtParams(), "resultTableName"); String resultTableName = Setting.getValue(et.getExtParams(), "resultTableName");
if(StringUtils.isEmpty(resultDataSource)){ if(StringUtils.isEmpty(resultDataSource)){
...@@ -151,14 +192,6 @@ public class RuleEngineExService extends RuleEngineServiceImpl { ...@@ -151,14 +192,6 @@ public class RuleEngineExService extends RuleEngineServiceImpl {
} }
msg.setResultDataSource(resultDataSource); msg.setResultDataSource(resultDataSource);
msg.setResultTableName(resultTableName); msg.setResultTableName(resultTableName);
ExecLog execlog=new ExecLog();
execlog.setId(msg.getId());
execlog.setName(msg.getBatch());
execlog.setKeyValueField(msg.getModel());
execlog.setSystemId(msg.getSystemid());
ruExecLogService.create(execlog);
List<String> rules = new ArrayList<>(); List<String> rules = new ArrayList<>();
DataModel dataModel=liteModelService.getDataModel(et.getModelId()); DataModel dataModel=liteModelService.getDataModel(et.getModelId());
HashSet<String> fillpropertys=new HashSet<>(); HashSet<String> fillpropertys=new HashSet<>();
...@@ -179,7 +212,6 @@ public class RuleEngineExService extends RuleEngineServiceImpl { ...@@ -179,7 +212,6 @@ public class RuleEngineExService extends RuleEngineServiceImpl {
if((!StringUtils.isEmpty(ruleItem.getCond()))&&ruleItem.getCond().startsWith("[")) if((!StringUtils.isEmpty(ruleItem.getCond()))&&ruleItem.getCond().startsWith("["))
fillpropertys.addAll(JSON.toJavaObject(JSON.parseArray(ruleItem.getCond()),LinkedHashSet.class)); fillpropertys.addAll(JSON.toJavaObject(JSON.parseArray(ruleItem.getCond()),LinkedHashSet.class));
}); });
dataModel.getAllProperty().forEach(prop->{ dataModel.getAllProperty().forEach(prop->{
if(fillpropertys.contains(prop.getPropertyName())) if(fillpropertys.contains(prop.getPropertyName()))
{ {
...@@ -191,25 +223,17 @@ public class RuleEngineExService extends RuleEngineServiceImpl { ...@@ -191,25 +223,17 @@ public class RuleEngineExService extends RuleEngineServiceImpl {
} }
} }
}); });
msg.setRules(rules); msg.setRules(rules);
msg.setDatas(liteDataService.getModelObjs(et.getModelId(),fillpropertys,engineMQMsg.getDatas())); msg.setFillpropertys(fillpropertys);
return msg;
}
baseEntityService.processAll(msg); @CacheEvict(value ="ruleengine", key = "'batch:'+#p0+#p1")
public void resetRequest(String id,String batch)
{
}catch (Exception ex){
log.error(String.format("构建数据错误:%1$s", ex.getMessage()));
ex.printStackTrace();
} }
String updateSql = "UPDATE ibzruleengine SET processed=(CASE WHEN processed is null then 0 else processed end+#{et.count}),lastruntime=CASE WHEN total <= processed THEN #{et.runtime} ELSE lastruntime END," +
"EXECSTATE=CASE WHEN total <= processed THEN 'FINISH' ELSE EXECSTATE END WHERE engineid = #{et.engineId}";
HashMap<String, Object> param = new HashMap<>();
param.put("count", engineMQMsg.getCount());
param.put("runtime", engineMQMsg.getRunTime());
param.put("engineId", engineMQMsg.getEngineId());
this.execute(updateSql, param);
}
/** /**
* [Check:校验] 行为扩展 * [Check:校验] 行为扩展
* @param et * @param et
......
...@@ -9,6 +9,7 @@ import cn.ibizlab.core.extensions.dto.FetchParam; ...@@ -9,6 +9,7 @@ import cn.ibizlab.core.extensions.dto.FetchParam;
import cn.ibizlab.core.extensions.dto.FetchResult; import cn.ibizlab.core.extensions.dto.FetchResult;
import cn.ibizlab.core.extensions.service.BuildResultService; import cn.ibizlab.core.extensions.service.BuildResultService;
import cn.ibizlab.core.extensions.service.DACoreService; import cn.ibizlab.core.extensions.service.DACoreService;
import cn.ibizlab.util.errors.BadRequestAlertException;
import cn.ibizlab.util.helper.DataObject; import cn.ibizlab.util.helper.DataObject;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
...@@ -24,6 +25,8 @@ import org.springframework.http.ResponseEntity; ...@@ -24,6 +25,8 @@ import org.springframework.http.ResponseEntity;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.util.List; import java.util.List;
...@@ -42,16 +45,7 @@ public class DAGridCoreResource { ...@@ -42,16 +45,7 @@ public class DAGridCoreResource {
@Lazy @Lazy
private DictOptionServiceImpl dictOptionService; private DictOptionServiceImpl dictOptionService;
@Autowired
private BuildResultService buildResultService;
@RequestMapping(method = RequestMethod.GET, value = {"/dst/report/{reportId}/{dimValue}","/dst/report/{reportId}"})
public ResponseEntity<FetchResult> getReportdatas(@PathVariable(name = "reportId") String reportId, @PathVariable(name = "dimValue",required = false) String dimValue,
@RequestParam(name = "startTime",required = false) String startTime,
@RequestParam(name = "endTime",required = false) String endTime) {
FetchParam param=new FetchParam().setReportId(reportId).setDimValue(dimValue).setStartTime(DataObject.getTimestampValue(startTime,null)).setEndTime(DataObject.getTimestampValue(endTime,null));
return ResponseEntity.ok(buildResultService.getAnalyseResult(param));
}
@RequestMapping(method = RequestMethod.POST, value = "/ibizutil/reportdatas") @RequestMapping(method = RequestMethod.POST, value = "/ibizutil/reportdatas")
public ResponseEntity<JSONObject> getReportdatas(@RequestBody JSONObject data) { public ResponseEntity<JSONObject> getReportdatas(@RequestBody JSONObject data) {
......
package cn.ibizlab.api.rest.extensions; package cn.ibizlab.api.rest.extensions;
import cn.ibizlab.core.dict.extensions.service.DictDstService; 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.service.BuildResultService;
import cn.ibizlab.core.lite.domain.DstSystem; import cn.ibizlab.core.lite.domain.DstSystem;
import cn.ibizlab.core.lite.domain.MetaEntity; import cn.ibizlab.core.lite.domain.MetaEntity;
import cn.ibizlab.core.lite.domain.MetaField; import cn.ibizlab.core.lite.domain.MetaField;
...@@ -16,12 +19,15 @@ import cn.ibizlab.core.lite.service.IMetaFieldService; ...@@ -16,12 +19,15 @@ import cn.ibizlab.core.lite.service.IMetaFieldService;
import cn.ibizlab.util.dict.CodeItem; import cn.ibizlab.util.dict.CodeItem;
import cn.ibizlab.util.dict.CodeList; import cn.ibizlab.util.dict.CodeList;
import cn.ibizlab.util.dict.Option; import cn.ibizlab.util.dict.Option;
import cn.ibizlab.util.errors.BadRequestAlertException;
import cn.ibizlab.util.filter.QueryFilter; import cn.ibizlab.util.filter.QueryFilter;
import cn.ibizlab.util.helper.DataObject;
import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.context.annotation.Lazy; import org.springframework.context.annotation.Lazy;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
...@@ -29,6 +35,8 @@ import org.springframework.util.StringUtils; ...@@ -29,6 +35,8 @@ import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -279,4 +287,74 @@ public class DstCoreResource { ...@@ -279,4 +287,74 @@ public class DstCoreResource {
} }
@Autowired
private BuildResultService buildResultService;
@RequestMapping(method = RequestMethod.GET, value = {"/dst/report/{reportId}/{dimValue}/config","/dst/report/{reportId}/config",
"/lite/report/{reportId}/{dimValue}/config","/lite/report/{reportId}/config"})
public ResponseEntity<FetchResult> getReportViews(@PathVariable(name = "reportId") String reportId, @PathVariable(name = "dimValue",required = false) String dimValue,
@RequestParam(name = "startTime",required = false) String startTime,
@RequestParam(name = "endTime",required = false) String endTime) {
FetchParam param=new FetchParam().setReportId(reportId).setDimValue(dimValue).setStartTime(DataObject.getTimestampValue(startTime,null)).setEndTime(DataObject.getTimestampValue(endTime,null));
return ResponseEntity.ok(buildResultService.getReportConfig(param));
}
@RequestMapping(method = RequestMethod.GET, value = {"/dst/report/{reportId}/{dimValue}","/dst/report/{reportId}",
"/lite/report/{reportId}/{dimValue}","/lite/report/{reportId}"})
public ResponseEntity<FetchResult> getReportdatas(@PathVariable(name = "reportId") String reportId, @PathVariable(name = "dimValue",required = false) String dimValue,
@RequestParam(name = "startTime",required = false) String startTime,
@RequestParam(name = "endTime",required = false) String endTime) {
FetchParam param=new FetchParam().setReportId(reportId).setDimValue(dimValue).setStartTime(DataObject.getTimestampValue(startTime,null)).setEndTime(DataObject.getTimestampValue(endTime,null));
return ResponseEntity.ok(buildResultService.getAnalyseResult(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,
@RequestParam(name = "startTime",required = false) String startTime,
@RequestParam(name = "endTime",required = false) String endTime, HttpServletResponse response) {
FetchParam param=new FetchParam().setReportId(reportId).setDimValue(dimValue).setStartTime(DataObject.getTimestampValue(startTime,null)).setEndTime(DataObject.getTimestampValue(endTime,null));
File file = buildResultService.exportExcel(param);
if(file==null)
throw new BadRequestAlertException("导出报表失败","Report",reportId);
try {
response.setHeader("Content-Disposition", "attachment;filename="+new String(file.getName().getBytes("utf-8"),"iso8859-1"));//防止中文乱码
}
catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
BufferedInputStream bis = null;
BufferedOutputStream bos = null;
try {
bis = new BufferedInputStream(new FileInputStream(file));
bos = new BufferedOutputStream(response.getOutputStream());
byte[] buff = new byte[2048];
int bytesRead;
while (-1 != (bytesRead = bis.read(buff, 0, buff.length))) {
bos.write(buff, 0, bytesRead);
}
}
catch (Exception e) {
//throw e;
}
finally {
if (bis != null) {
try {
bis.close();
}
catch (IOException e) {
}
}
if (bos != null) {
try {
bos.close();
}
catch (IOException e) {
}
}
}
}
} }
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册