提交 db56e1b7 编写于 作者: hebao@lab.ibiz5.com's avatar hebao@lab.ibiz5.com

报表指标类型支持COUNT_DISTINCT_EXT1(根据Ext1Field的值去重计数)

上级 38895eca
......@@ -20,6 +20,7 @@ public interface ExecResultExMapper extends BaseMapper<EntityObj>{
List<ExecResult> sumResult(@Param("resultTableName") String tableName, @Param("ruleids")List<String> ruleids, @Param("dimfields")List<String> dimfields, @Param("domainsfields")List<String> domainsfields, @Param("from")Timestamp from,@Param("to")Timestamp to);
List<ExecResult> avgResult(@Param("resultTableName") String tableName, @Param("ruleids")List<String> ruleids, @Param("dimfields")List<String> dimfields, @Param("domainsfields")List<String> domainsfields, @Param("from")Timestamp from,@Param("to")Timestamp to);
List<ExecResult> countDistExt1Result(@Param("resultTableName") String tableName, @Param("ruleids")List<String> ruleids, @Param("dimfields")List<String> dimfields, @Param("domainsfields")List<String> domainsfields, @Param("from")Timestamp from,@Param("to")Timestamp to);
Page<ExecResult> lookupResult(IPage page, @Param("resultTableName") String tableName, @Param("columns")String columns,@Param("ruleid")String ruleid, @Param("dimfield")String dimfield, @Param("domainsfields")List<String> domainsfields, @Param("from")Timestamp from, @Param("to")Timestamp to);
......
......@@ -286,7 +286,7 @@ public class BuildResultService {
{
subMetricIds=new LinkedHashSet<>();
for(DAMetric item:fetchParam.getMetrics().values()){
if(!"AVG".equals(item.getMetricType()))
if(!"AVG".equals(item.getMetricType()) && !"COUNT_DISTINCT_EXT1".equals(item.getMetricType()))
subMetricIds.add(item.getMetricId());
}
}
......@@ -387,6 +387,59 @@ public class BuildResultService {
}
public List<BuildResult> countDistExt1(FetchParam fetchParam,Set<String> subMetricIds,Timestamp start,Timestamp end) {
List<BuildResult> ret = new ArrayList<>();
Timestamp startTime=(start==null)?fetchParam.getStartTime():start;
Timestamp endTime=(end==null)?fetchParam.getEndTime():end;
if(subMetricIds==null)
{
subMetricIds=new LinkedHashSet<>();
for(DAMetric item:fetchParam.getMetrics().values()){
if("COUNT_DISTINCT_EXT1".equals(item.getMetricType()))
subMetricIds.add(item.getMetricId());
}
}
if(!StringUtils.isEmpty(cassandraHost))
{
List<cn.ibizlab.core.extensions.cql.ExecResult> list=execResultRepository.sum(subMetricIds,1,fetchParam.getDimValues(),startTime,endTime);
list.forEach(item->{
ret.add(new BuildResult().setCqlResult(item));
});
}
else
{
//prepareFetchParam(fetchParam);
Map<String,Set<String>> tab = fetchParam.getDimTables();
for(String key:tab.keySet()){
String[] args = key.split("\\|");
String dsName = args[0];
String tableName = args[1];
Set<String> tmpSet=new LinkedHashSet<>();
for(String id:tab.get(key))
{
if(subMetricIds.contains(id))
tmpSet.add(id);
}
if(tmpSet.size()>0)
{
List<ExecResult> list = execResultExService.countDistExt1Result(dsName,tableName,new ArrayList<>(tmpSet),fetchParam.getDimValues(),fetchParam.getDomains(),startTime,endTime);
list.forEach(item->{
ret.add(new BuildResult().setSqlResult(item));
});
}
}
}
return ret;
}
@Cacheable( value="dataAnalyse",key="'rows:lookup:'+#p0.getId()")
public LookupResult lookup(FetchParam fetchParam) {
prepareFetchParam(fetchParam);
......@@ -453,6 +506,7 @@ public class BuildResultService {
Set<String> sum=new LinkedHashSet<>();
Set<String> avg=new LinkedHashSet<String>();
Set<String> countDistExt1=new LinkedHashSet<String>();
Set<String> sum_yoy=new LinkedHashSet<>();
Set<String> sum_mom=new LinkedHashSet<>();
......@@ -464,6 +518,11 @@ public class BuildResultService {
Set<String> avg_y3=new LinkedHashSet<>();
List<DAMetric> avg_per=new ArrayList<>();
Set<String> countDistExt1_yoy=new LinkedHashSet<>();
Set<String> countDistExt1_mom=new LinkedHashSet<>();
Set<String> countDistExt1_y3=new LinkedHashSet<>();
List<DAMetric> countDistExt1_per=new ArrayList<>();
for(DAMetric metric:fetchParam.getMetrics().values())
{
......@@ -479,6 +538,19 @@ public class BuildResultService {
else if("PER".equals(metric.getExtOp()) || "PER_ORI".equals(metric.getExtOp()))
avg_per.add(metric);
}
else if("COUNT_DISTINCT_EXT1".equals(metric.getMetricType()))
{
countDistExt1.add(metric.getMetricId());
if("YOY".equals(metric.getExtOp()))
countDistExt1_yoy.add(metric.getMetricId());
else if("MOM".equals(metric.getExtOp()))
countDistExt1_mom.add(metric.getMetricId());
else if("Y3".equals(metric.getExtOp()))
countDistExt1_y3.add(metric.getMetricId());
else if("PER".equals(metric.getExtOp()) || "PER_ORI".equals(metric.getExtOp()))
countDistExt1_per.add(metric);
}
else
{
......@@ -547,7 +619,11 @@ public class BuildResultService {
List<BuildResult> listavg = avg(fetchParam, avg, null, null);
list.addAll(listavg);
}
if(countDistExt1.size()>0)
{
List<BuildResult> listcountDistExt1 = countDistExt1(fetchParam, countDistExt1, null, null);
list.addAll(listcountDistExt1);
}
for(BuildResult res:list)
{
if(!dimsSet.containsKey(res.getDimField()))
......@@ -584,6 +660,11 @@ public class BuildResultService {
List<BuildResult> listavg=avg(fetchParam, avg_yoy, FetchParam.getLastYear(fetchParam.getStartTime()), FetchParam.getLastYear(fetchParam.getEndTime()));
list_yoy.addAll(listavg);
}
if(countDistExt1_yoy.size()>0)
{
List<BuildResult> temp=countDistExt1(fetchParam, countDistExt1_yoy, FetchParam.getLastYear(fetchParam.getStartTime()), FetchParam.getLastYear(fetchParam.getEndTime()));
list_yoy.addAll(temp);
}
for(BuildResult res:list_yoy)
{
......@@ -659,6 +740,11 @@ public class BuildResultService {
List<BuildResult> listavg=avg(fetchParam, avg_mom, FetchParam.getLastMonth(fetchParam.getStartTime()), FetchParam.getLastMonth(fetchParam.getEndTime()));
list_mom.addAll(listavg);
}
if(countDistExt1_mom.size()>0)
{
List<BuildResult> temp=countDistExt1(fetchParam, countDistExt1_mom, FetchParam.getLastMonth(fetchParam.getStartTime()), FetchParam.getLastMonth(fetchParam.getEndTime()));
list_mom.addAll(temp);
}
for(BuildResult res:list_mom)
{
......@@ -723,6 +809,7 @@ public class BuildResultService {
//占比
sum_per.addAll(avg_per);
sum_per.addAll(countDistExt1_per);
for(DAMetric res:sum_per)
{
......
......@@ -326,6 +326,27 @@ public class ExecResultExService extends ExecResultServiceImpl {
return result;
}
public List<ExecResult> countDistExt1Result(String dsName ,String tableName, List<String> ruleids, List<String> dimfields, List<String> domainsfields, Timestamp from, Timestamp to)
{
List<ExecResult> result = null;
try {
if(!Default_ResultDataSource.equalsIgnoreCase(dsName)){
dstDataSourceService.initDataSource(dsName);
DynamicDataSourceContextHolder.push(dsName);
}
result = execResultExMapper.countDistExt1Result(tableName,ruleids,dimfields,domainsfields,from,to);
} catch (Exception ex) {
result = new ArrayList<>();
log.error("存储规则结果发生异常,详细错误信息:" + ex.getMessage());
} finally {
if(!Default_ResultDataSource.equalsIgnoreCase(dsName)) {
DynamicDataSourceContextHolder.poll();
}
}
return result;
}
public Page<ExecResult> lookupResult(int current, int size, String dsName, String tableName, String columns,String ruleid, String dimfield, List<String> domainsfields, Timestamp from, Timestamp to) {
if(StringUtils.isEmpty(columns))
columns="*";
......
......@@ -154,6 +154,26 @@
</select>
<select id="countDistExt1Result" resultType="cn.ibizlab.core.rule.domain.ExecResult" >
select ruleid, 1 as retvalue,dimfield,count(distinct(ext1field)) as metricfield from ${resultTableName} where ruleid in
<foreach item="id" index="index" collection="ruleids" open="(" separator="," close=")">
#{id}
</foreach>
and RETVALUE=1 and DIMFIELD in
<foreach item="id" index="index" collection="dimfields" open="(" separator="," close=")">
#{id}
</foreach>
<choose><when test="domainsfields != null">
and DOMAINSFIELD in
<foreach item="id" index="index" collection="domainsfields" open="(" separator="," close=")">
#{id}
</foreach>
</when></choose>
and TIMEFIELD<![CDATA[ >= ]]>#{from} and TIMEFIELD<![CDATA[ <= ]]>#{to}
group by ruleid,dimfield
</select>
<select id="lookupResult" resultType="cn.ibizlab.core.rule.domain.ExecResult" >
select ${columns} from ${resultTableName} where ruleid = #{ruleid}
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册