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

调整报表

上级 ef9f2ef9
......@@ -24,7 +24,7 @@
padding: 10px 0;
> .vue-treeselect {
width: 14%;
width: 300px;
> .vue-treeselect__control {
height: 40px;
......@@ -32,7 +32,7 @@
}
> .el-select {
width: 9%;
width: 150px;
}
}
......
package cn.ibizlab.core.extensions.domain;
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 org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
......@@ -9,6 +12,7 @@ import java.math.BigDecimal;
import java.math.BigInteger;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
@Data
......@@ -30,6 +34,8 @@ public class BaseRequest
'}';
}
@JsonIgnore
@JSONField(serialize = false)
public String toString2() {
return "BaseRequest{" +
"id='" + id + '\'' +
......@@ -42,6 +48,7 @@ public class BaseRequest
}
private List<ModelObj> datas;
private String modelId;
private String model;
private String engineId;
private String resultDataSource;
......@@ -50,17 +57,26 @@ public class BaseRequest
private List<String> rules;
private List<String> ruleIds;
private SimpleDateFormat format =new SimpleDateFormat("yyyyMMddHHmmss");
private HashSet<String> fillpropertys;
public String getBatch()
{
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;
}
public BaseRequest copy(boolean reset)
{
BaseRequest baseRequest = JSON.parseObject(JSON.toJSONString(this),BaseRequest.class);
return baseRequest;
}
}
......@@ -30,35 +30,43 @@ import java.util.*;
@Accessors(chain = true)
public class FetchParam {
@JsonIgnore
@JSONField(serialize = false)
private String id;
@JsonIgnore
@JSONField(serialize = false)
public String getId() {
String str = "FetchParam{" +
"reportId='" + reportId + '\'' +
", chartId='" + chartId + '\'' +
", buildId='" + buildId + '\'' +
", displayType='" + displayType + '\'' +
", dimDict='" + dimDict + '\'' +
", dimValues=" + dimValues +
", dimValue='" + dimValue + '\'' +
", includeChild=" + includeChild +
", metricIds=" + metricIds +
", metricId='" + metricId + '\'' +
", startTime=" + startTime +
", endTime=" + endTime +
", page=" + page +
", size=" + size +
", total=" + total +
", group='" + group + '\'' +
'}';
return DigestUtils.md5DigestAsHex(str.getBytes());
if(StringUtils.isEmpty(id))
{
String str = "FetchParam{" +
"reportId='" + reportId + '\'' +
", chartId='" + chartId + '\'' +
", buildId='" + buildId + '\'' +
", displayType='" + displayType + '\'' +
", dimDict='" + dimDict + '\'' +
", dimValues=" + dimValues +
", dimValue='" + dimValue + '\'' +
", includeChild=" + includeChild +
", metricIds=" + metricIds +
", metricId='" + metricId + '\'' +
", startTime=" + startTime +
", endTime=" + endTime +
", page=" + page +
", size=" + size +
", total=" + total +
", group='" + group + '\'' +
'}';
id = DigestUtils.md5DigestAsHex(str.getBytes());
}
return id;
}
private String reportId;
private String chartId;
private String buildId;
private String title;
// 表格展示类型:1. default(维度数据以行的形式展示),2. LIST_BOX(维度数据以列的形式展示)
private String displayType = "default";
......
......@@ -3,6 +3,7 @@ package cn.ibizlab.core.extensions.dto;
import cn.ibizlab.core.analysis.domain.DAMetric;
import cn.ibizlab.util.dict.Catalog;
import cn.ibizlab.util.dict.CodeItem;
import cn.ibizlab.util.dict.Option;
import cn.ibizlab.util.helper.DataObject;
import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonFormat;
......@@ -30,6 +31,8 @@ public class FetchResult {
// 表格展示类型:1. default(维度数据以行的形式展示),2. LIST_BOX(维度数据以列的形式展示)
private String displayType = "default";
private String title;
private List<FetchItem> rows;
private List<VMConfig> headers;
......@@ -38,8 +41,8 @@ public class FetchResult {
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"));
headers.add(new VMConfig().setHeaderName("序号").setEntity("item").setWidth(50).setField("no").setPinned("left"));
headers.add(new VMConfig().setHeaderName(getGroup()).setEntity("item").setWidth(250).setField("itemName").setPinned("left"));
if(vmConfigs!=null)
headers.addAll(vmConfigs);
}
......@@ -104,14 +107,17 @@ public class FetchResult {
@JSONField(serialize = false)
private List<VMConfig> vmConfigs;
@JsonIgnore
@JSONField(serialize = false)
private String group;
private Catalog dict;
private String selectValue;
@JsonIgnore
@JSONField(serialize = false)
private Option selectDimItem;
@JsonFormat(pattern = "yyyy-MM-dd", locale = "zh", timezone = "GMT+8")
@JSONField(name = "startTime", format = "yyyy-MM-dd")
private Timestamp startTime;
......@@ -119,6 +125,12 @@ public class FetchResult {
@JSONField(name = "endTime", format = "yyyy-MM-dd")
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)
{
FetchResult fetchResult=new FetchResult();
......@@ -129,7 +141,8 @@ public class FetchResult {
fetchResult.setVmConfigs(fetchParam.getVmConfigs());
}
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;
}
......
......@@ -4,6 +4,7 @@ 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.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Getter;
import lombok.NoArgsConstructor;
......@@ -18,10 +19,18 @@ import java.util.*;
@Getter
@Setter
@NoArgsConstructor
@JsonInclude(JsonInclude.Include.NON_EMPTY)
@Accessors(chain = true)
public class VMConfig {
private String headerName;
private Integer width;
public Integer getWidth() {
if(width==null&&(!StringUtils.isEmpty(field)))
return 100;
return width;
}
@JSONField(name = "entity")
@JsonProperty("entity")
private String entity;
......@@ -29,8 +38,16 @@ public class VMConfig {
@JsonProperty("field")
private String field;
private String pinned;
private Boolean hide;
private List<VMConfig> children;
@JsonIgnore
@JSONField(serialize = false)
public boolean isHide()
{
return hide!=null&&hide;
}
public void setChildren(List<VMConfig> children) {
if(children!=null)
children.forEach(item->{
......
......@@ -10,15 +10,19 @@ import cn.ibizlab.core.analysis.service.impl.DAReportServiceImpl;
import cn.ibizlab.core.dict.extensions.service.DictDstService;
import cn.ibizlab.core.extensions.cql.ExecResultRepository;
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.service.IExecResultService;
import cn.ibizlab.util.dict.Catalog;
import cn.ibizlab.util.dict.CodeItem;
import cn.ibizlab.util.dict.CodeList;
import cn.ibizlab.util.dict.Option;
import cn.ibizlab.util.helper.DataObject;
import cn.ibizlab.util.helper.Setting;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.datastax.driver.core.PagingState;
import com.datastax.driver.core.ResultSet;
......@@ -36,8 +40,12 @@ import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
import java.io.File;
import java.math.BigDecimal;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.*;
import static com.datastax.driver.core.querybuilder.QueryBuilder.lte;
......@@ -82,6 +90,10 @@ public class BuildResultService {
@Lazy
private ExecResultExService execResultExService;
@Autowired
@Lazy
BuildResultService proxy;
@Value("${defaultResultDataSource:default}")
private String Default_ResultDataSource;
......@@ -89,7 +101,7 @@ public class BuildResultService {
private String Default_ResultTableName;
private void prepareFetchParam(FetchParam fetchParam)
public void prepareFetchParam(FetchParam fetchParam)
{
if(fetchParam.isFilled())
return;
......@@ -109,6 +121,7 @@ public class BuildResultService {
if(!StringUtils.isEmpty(daReport.getGroup()))
fetchParam.setGroup(daReport.getGroup());
fetchParam.setTitle(daReport.getReportName());
}
}
else if(!StringUtils.isEmpty(fetchParam.getChartId()))
......@@ -123,6 +136,8 @@ public class BuildResultService {
if(!StringUtils.isEmpty(daChart.getGroup()))
fetchParam.setGroup(daChart.getGroup());
fetchParam.setTitle(daChart.getChartName());
}
}
......@@ -201,7 +216,8 @@ public class BuildResultService {
dimValues.add(codeItem.getValue().toString());
});
}
dimValues.add(fetchParam.getDimValue());
if(dimValues.size()==0)
dimValues.add(fetchParam.getDimValue());
fetchParam.setDimValues(dimValues);
}
......@@ -473,7 +489,7 @@ public class BuildResultService {
else
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())
{
sumobj.setVal(metric.getMetricId(),BigDecimal.ZERO);
......@@ -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()")
public FetchResult getAnalyseResult(FetchParam 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)
......@@ -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;
import cn.ibizlab.core.lite.extensions.service.LiteDataService;
import cn.ibizlab.core.lite.extensions.service.LiteModelService;
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.service.IExecLogService;
import cn.ibizlab.core.rule.service.IRuleItemService;
......@@ -35,6 +36,7 @@ import org.springframework.context.annotation.Lazy;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
import java.io.File;
......@@ -123,10 +125,6 @@ public class DABuildExService extends DABuildServiceImpl {
* @return
*/
@Override
@Caching( evict = {
@CacheEvict(value ={"dabuild","dabuilddims"}, key = "'row:'+#p0.buildId"),
@CacheEvict( value="dataAnalyse",allEntries = true)
})
public DABuild run(DABuild et) {
if(!StringUtils.isEmpty(et.getBuildId()))
{
......@@ -179,24 +177,10 @@ public class DABuildExService extends DABuildServiceImpl {
public void processData(EngineMQMsg engineMQMsg){
DABuild et = get(engineMQMsg.getEngineId());
try{
BaseRequest msg=new BaseRequest();
BaseRequest msg=proxy.getRequest(engineMQMsg.getEngineId(),engineMQMsg.getBatch()).copy(true);
msg.setId(IdWorker.getIdStr());
msg.setModel(et.getModelName());
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)){
resultDataSource=Default_ResultDataSource;
}
if(StringUtils.isEmpty(resultTableName)){
resultTableName=Default_ResultTableName;
}
msg.setResultDataSource(resultDataSource);
msg.setResultTableName(resultTableName);
ExecLog execlog=new ExecLog();
execlog.setId(msg.getId());
......@@ -205,59 +189,7 @@ public class DABuildExService extends DABuildServiceImpl {
execlog.setSystemId(msg.getSystemid());
ruExecLogService.create(execlog);
List<String> ruleIds = new ArrayList<>();
List<String> rulePaths = new ArrayList<>();
DataModel dataModel=liteModelService.getDataModel(et.getModelId());
HashSet<String> fillpropertys=new HashSet<>();
List<String> metrics = new ArrayList<>();
idaMetricService.list(Wrappers.<DAMetric>lambdaQuery().eq(DAMetric::getBuildId,et.getBuildId()))
.forEach(daMetric -> {
metrics.add(daMetric.getMetricId());
});
if(metrics.size() == 0){
log.error(String.format("构建数据失败:未配置指标"));
return;
}
ruleItemService.list(Wrappers.<RuleItem>lambdaQuery().in(RuleItem::getRuleId, metrics))
.forEach(ruleItem -> {
String path=rulePath + ruleItem.getGroup() + File.separator + ruleItem.getRuleId() + ".drl";
File file=new File(path);
if(!file.exists())
{
ruleItemService.buildRuleFile(ruleItem);
}
if(file.exists())
{
rulePaths.add(path);
ruleIds.add(ruleItem.getRuleId());
}
if((!StringUtils.isEmpty(ruleItem.getCond()))&&ruleItem.getCond().startsWith("["))
fillpropertys.addAll(JSON.toJavaObject(JSON.parseArray(ruleItem.getCond()), LinkedHashSet.class));
});
if(ruleIds.size() == 0){
log.error(String.format("构建数据失败:无有效规则"));
return;
}
dataModel.getAllProperty().forEach(prop->{
if(fillpropertys.contains(prop.getPropertyName()))
{
DataModel p=prop.getOwnerDataModel().getParentDataModel();
while (p!=null)
{
fillpropertys.add(p.getFactPorperty().getPropertyName());
p=p.getParentDataModel();
}
}
});
msg.setRuleIds(ruleIds);
msg.setRules(rulePaths);
msg.setDatas(liteDataService.getModelObjs(et.getModelId(),fillpropertys,engineMQMsg.getDatas()));
msg.setDatas(liteDataService.getModelObjs(msg.getModelId(),msg.getFillpropertys(),engineMQMsg.getDatas()));
analyseEntityServiceImpl.processAll(msg);
......@@ -273,8 +205,110 @@ public class DABuildExService extends DABuildServiceImpl {
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.setBatch(batch);
msg.setSystemid(et.getSystemId());
msg.setEngineId(id);
String resultDataSource = Setting.getValue(et.getExtParams(), "resultDataSource");
String resultTableName = Setting.getValue(et.getExtParams(), "resultTableName");
if(StringUtils.isEmpty(resultDataSource)){
resultDataSource=Default_ResultDataSource;
}
if(StringUtils.isEmpty(resultTableName)){
resultTableName=Default_ResultTableName;
}
msg.setResultDataSource(resultDataSource);
msg.setResultTableName(resultTableName);
List<String> ruleIds = new ArrayList<>();
List<String> rulePaths = new ArrayList<>();
DataModel dataModel=liteModelService.getDataModel(et.getModelId());
HashSet<String> fillpropertys=new HashSet<>();
List<String> metrics = new ArrayList<>();
idaMetricService.list(Wrappers.<DAMetric>lambdaQuery().eq(DAMetric::getBuildId,et.getBuildId()))
.forEach(daMetric -> {
metrics.add(daMetric.getMetricId());
});
Assert.notEmpty(metrics,"构建数据失败:未配置指标");
ruleItemService.list(Wrappers.<RuleItem>lambdaQuery().in(RuleItem::getRuleId, metrics))
.forEach(ruleItem -> {
String path=rulePath + ruleItem.getGroup() + File.separator + ruleItem.getRuleId() + ".drl";
File file=new File(path);
if(!file.exists())
{
ruleItemService.buildRuleFile(ruleItem);
}
if(file.exists())
{
rulePaths.add(path);
ruleIds.add(ruleItem.getRuleId());
}
if((!StringUtils.isEmpty(ruleItem.getCond()))&&ruleItem.getCond().startsWith("["))
fillpropertys.addAll(JSON.toJavaObject(JSON.parseArray(ruleItem.getCond()), LinkedHashSet.class));
});
Assert.notEmpty(ruleIds,"构建数据失败:无有效规则");
dataModel.getAllProperty().forEach(prop->{
if(fillpropertys.contains(prop.getPropertyName()))
{
DataModel p=prop.getOwnerDataModel().getParentDataModel();
while (p!=null)
{
fillpropertys.add(p.getFactPorperty().getPropertyName());
p=p.getParentDataModel();
}
}
});
msg.setFillpropertys(fillpropertys);
msg.setRuleIds(ruleIds);
msg.setRules(rulePaths);
return msg;
}
@CacheEvict(value ="dabuild", key = "'batch:'+#p0+#p1")
public void resetRequest(String id,String batch)
{
}
@CacheEvict( value="dataAnalyse",allEntries = true)
public void resetDataAnalyseResult()
{
}
@CacheEvict(value ={"dabuild","dabuilddims"}, key = "'row:'+#p0")
public void resetBuild(String id)
{
}
@Autowired
@Lazy
DABuildExService proxy;
@Cacheable(value ="dabuilddims", key = "'row:'+#p0")
public List<DADimension> getDims(String id)
......@@ -282,6 +316,7 @@ public class DABuildExService extends DABuildServiceImpl {
return this.get(id).getDadimension();
}
@Override
@Transactional
@CacheEvict(value ={"dabuild","dabuilddims"}, key = "'row:'+#p0.buildId")
......
......@@ -23,6 +23,8 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
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.Primary;
import org.springframework.stereotype.Service;
......@@ -133,24 +135,10 @@ public class RuleEngineExService extends RuleEngineServiceImpl {
protected IExecLogService ruExecLogService;
public void processData(EngineMQMsg engineMQMsg){
RuleEngine et = get(engineMQMsg.getEngineId());
try{
BaseRequest msg=new BaseRequest();
BaseRequest msg=proxy.getRequest(engineMQMsg.getEngineId(),engineMQMsg.getBatch()).copy(true);
msg.setId(IdWorker.getIdStr());
msg.setModel(et.getModelName());
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)){
resultDataSource=Default_ResultDataSource;
}
if(StringUtils.isEmpty(resultTableName)){
resultTableName=Default_ResultTableName;
}
msg.setResultDataSource(resultDataSource);
msg.setResultTableName(resultTableName);
ExecLog execlog=new ExecLog();
execlog.setId(msg.getId());
......@@ -158,43 +146,7 @@ public class RuleEngineExService extends RuleEngineServiceImpl {
execlog.setKeyValueField(msg.getModel());
execlog.setSystemId(msg.getSystemid());
ruExecLogService.create(execlog);
List<String> rules = new ArrayList<>();
DataModel dataModel=liteModelService.getDataModel(et.getModelId());
HashSet<String> fillpropertys=new HashSet<>();
ruleItemService.list(Wrappers.<RuleItem>lambdaQuery()
.eq(RuleItem::getModelId,et.getModelId()).ne(RuleItem::getGroup,"REP").like(RuleItem::getGroup,et.getGroup()))
.forEach(ruleItem -> {
String path=rulePath + et.getGroup() + File.separator + ruleItem.getRuleId() + ".drl";
File file=new File(path);
if(!file.exists())
{
ruleItemService.buildRuleFile(ruleItem);
}
if(file.exists())
{
rules.add(path);
}
if((!StringUtils.isEmpty(ruleItem.getCond()))&&ruleItem.getCond().startsWith("["))
fillpropertys.addAll(JSON.toJavaObject(JSON.parseArray(ruleItem.getCond()),LinkedHashSet.class));
});
dataModel.getAllProperty().forEach(prop->{
if(fillpropertys.contains(prop.getPropertyName()))
{
DataModel p=prop.getOwnerDataModel().getParentDataModel();
while (p!=null)
{
fillpropertys.add(p.getFactPorperty().getPropertyName());
p=p.getParentDataModel();
}
}
});
msg.setRules(rules);
msg.setDatas(liteDataService.getModelObjs(et.getModelId(),fillpropertys,engineMQMsg.getDatas()));
msg.setDatas(liteDataService.getModelObjs(msg.getModelId(),msg.getFillpropertys(),engineMQMsg.getDatas()));
baseEntityService.processAll(msg);
}catch (Exception ex){
......@@ -209,7 +161,79 @@ public class RuleEngineExService extends RuleEngineServiceImpl {
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.setBatch(batch);
msg.setSystemid(et.getSystemId());
msg.setEngineId(id);
String resultDataSource = Setting.getValue(et.getExtParams(), "resultDataSource");
String resultTableName = Setting.getValue(et.getExtParams(), "resultTableName");
if(StringUtils.isEmpty(resultDataSource)){
resultDataSource=Default_ResultDataSource;
}
if(StringUtils.isEmpty(resultTableName)){
resultTableName=Default_ResultTableName;
}
msg.setResultDataSource(resultDataSource);
msg.setResultTableName(resultTableName);
List<String> rules = new ArrayList<>();
DataModel dataModel=liteModelService.getDataModel(et.getModelId());
HashSet<String> fillpropertys=new HashSet<>();
ruleItemService.list(Wrappers.<RuleItem>lambdaQuery()
.eq(RuleItem::getModelId,et.getModelId()).ne(RuleItem::getGroup,"REP").like(RuleItem::getGroup,et.getGroup()))
.forEach(ruleItem -> {
String path=rulePath + et.getGroup() + File.separator + ruleItem.getRuleId() + ".drl";
File file=new File(path);
if(!file.exists())
{
ruleItemService.buildRuleFile(ruleItem);
}
if(file.exists())
{
rules.add(path);
}
if((!StringUtils.isEmpty(ruleItem.getCond()))&&ruleItem.getCond().startsWith("["))
fillpropertys.addAll(JSON.toJavaObject(JSON.parseArray(ruleItem.getCond()),LinkedHashSet.class));
});
dataModel.getAllProperty().forEach(prop->{
if(fillpropertys.contains(prop.getPropertyName()))
{
DataModel p=prop.getOwnerDataModel().getParentDataModel();
while (p!=null)
{
fillpropertys.add(p.getFactPorperty().getPropertyName());
p=p.getParentDataModel();
}
}
});
msg.setRules(rules);
msg.setFillpropertys(fillpropertys);
return msg;
}
@CacheEvict(value ="ruleengine", key = "'batch:'+#p0+#p1")
public void resetRequest(String id,String batch)
{
}
/**
* [Check:校验] 行为扩展
* @param et
......
......@@ -9,6 +9,7 @@ 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.extensions.service.DACoreService;
import cn.ibizlab.util.errors.BadRequestAlertException;
import cn.ibizlab.util.helper.DataObject;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
......@@ -24,6 +25,8 @@ import org.springframework.http.ResponseEntity;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.sql.Timestamp;
import java.util.List;
......@@ -42,16 +45,7 @@ public class DAGridCoreResource {
@Lazy
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")
public ResponseEntity<JSONObject> getReportdatas(@RequestBody JSONObject data) {
......
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.service.BuildResultService;
import cn.ibizlab.core.lite.domain.DstSystem;
import cn.ibizlab.core.lite.domain.MetaEntity;
import cn.ibizlab.core.lite.domain.MetaField;
......@@ -16,12 +19,15 @@ import cn.ibizlab.core.lite.service.IMetaFieldService;
import cn.ibizlab.util.dict.CodeItem;
import cn.ibizlab.util.dict.CodeList;
import cn.ibizlab.util.dict.Option;
import cn.ibizlab.util.errors.BadRequestAlertException;
import cn.ibizlab.util.filter.QueryFilter;
import cn.ibizlab.util.helper.DataObject;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.context.annotation.Lazy;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
......@@ -29,6 +35,8 @@ import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
......@@ -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 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册