潘志宝
2024-12-15 bbe7acfbe5a4c08d6edc91eaf81dcecf9d630e18
iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/ind/collection/utils/IndSqlUtils.java
@@ -50,6 +50,7 @@
        if (indItem == null) {
            return result;
        }
        result.setIndItemAtom(indItem);
        IndDataSetDTO dataSet = indDataSetService.getDet(indItem.getDataSet());
        if (dataSet == null) {
            return result;
@@ -94,14 +95,20 @@
        // 拼接SELECT
        StringBuilder selectSql = new StringBuilder();
        if (StringUtils.isNotBlank(indItem.getDimension())){
        if (StringUtils.isNotBlank(indItem.getDimension()) && StringUtils.isNotBlank(result.getIndItemAtom().getStatFunc())){
            selectSql.append(indItem.getDimension());
            selectSql.append(", ");
            selectSql.append(result.getSelectSql());
        }
        selectSql.append(result.getSelectSql());
        selectSql.append(", ");
        selectSql.append(indItem.getTimeLabel());
        selectSql.append(" data_time");
        else if(StringUtils.isBlank(indItem.getDimension()) && StringUtils.isNotBlank(result.getIndItemAtom().getStatFunc())){
            selectSql.append(result.getSelectSql());
        }
        else{
            selectSql.append(result.getSelectSql());
            selectSql.append(", ");
            selectSql.append(indItem.getTimeLabel());
            selectSql.append(" data_time");
        }
        result.setSelectSql(selectSql.toString());
        // 拼接WHERE
@@ -153,7 +160,9 @@
                whereSql.append(indItem.getTimeLabel());
                whereSql.append(" <= '");
                whereSql.append(DateUtils.format(calendar.getTime(), PATTERN_MON));
                whereSql.append("' AND >= '");
                whereSql.append("' AND '");
                whereSql.append(indItem.getTimeLabel());
                whereSql.append("' >= '");
                calendar.add(Calendar.MONTH, -12);
                whereSql.append(DateUtils.format(calendar.getTime(), PATTERN_MON));
                whereSql.append("'");
@@ -184,9 +193,9 @@
                whereSql.append(indItem.getTimeLabel());
                whereSql.append(" <= '");
                whereSql.append(DateUtils.format(indItem.getTimeEnd(), PATTERN_MON));
                whereSql.append("' AND '");
                whereSql.append("' AND ");
                whereSql.append(indItem.getTimeLabel());
                whereSql.append("' >= '");
                whereSql.append(" >= '");
                whereSql.append(DateUtils.format(indItem.getTimeStart(), PATTERN_MON));
                whereSql.append("'");
                break;
@@ -197,14 +206,17 @@
        // 拼接GROUP
        StringBuilder groupSql = new StringBuilder();
        groupSql.append(" GROUP BY ");
        groupSql.append(indItem.getDimension());
        if (StringUtils.isNotBlank(indItem.getDimension())){
            groupSql.append(indItem.getDimension());
        }
        result.setGroupSql(groupSql.toString());
        // 拼接ORDER
        StringBuilder orderBySql = new StringBuilder();
        orderBySql.append(indItem.getTimeLabel());
        result.setOrderBySql(orderBySql.toString());
        if (StringUtils.isNotBlank(indItem.getDimension()) && indItem.getDimension().equals(indItem.getTimeLabel())){
            orderBySql.append(indItem.getTimeLabel());
            result.setOrderBySql(orderBySql.toString());
        }
        return result;
    }