浏览代码

上月数据接口-添加filter条件处理

wangxingwang 6 年之前
父节点
当前提交
753693b876
共有 1 个文件被更改,包括 16 次插入1 次删除
  1. 16 1
      src/main/java/com/yihu/quota/service/quota/BaseStatistsService.java

+ 16 - 1
src/main/java/com/yihu/quota/service/quota/BaseStatistsService.java

@ -1891,6 +1891,7 @@ public class BaseStatistsService {
    public String filtersExchangeHandle(String filters, EsConfig esConfig) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        String otherFilter = "";
        Calendar lastDate = Calendar.getInstance();
        lastDate.set(Calendar.DAY_OF_MONTH, 1); // 设置为1号,当前日期既为本月第一天
        String firstDay = sdf.format(lastDate.getTime());
@ -1901,7 +1902,17 @@ public class BaseStatistsService {
        String preMonthFirstDay = sdf.format(lastDate.getTime());
        lastDate.set(Calendar.DAY_OF_MONTH, lastDate.getActualMaximum(Calendar.DAY_OF_MONTH));
        String preMonthLastDay = sdf.format(lastDate.getTime());
        // 如果有时间过滤条件,则按时间条件计算
        if (StringUtils.isNotEmpty(filters)) {
            String[] split = filters.split(";");
            for (String s : split) {
                // 拼接非quotaDate的过滤条件
                if (!s.contains(quotaDateField)) {
                    otherFilter += s + " and ";
                }
            }
        }
        // 如果有时间过滤条件,则计算时间条件计算
        if (StringUtils.isNotEmpty(filters) && filters.contains(quotaDateField)) {
            Calendar cal = Calendar.getInstance();
            boolean b = filters.indexOf("'") > -1;
@ -1932,6 +1943,10 @@ public class BaseStatistsService {
        if (StringUtils.isNotEmpty(esConfig.getFilter())) {
            filters += " and " + esConfig.getFilter();
        }
        if (StringUtils.isNotEmpty(otherFilter)) {
            filters = otherFilter + filters;
        }
        return filters;
    }
}