package cn.com.victorysoft.business.analyze.service.condition;

import cn.com.victorysoft.business.analyze.entity.CstTableIndicator;
import cn.com.victorysoft.business.util.StringUtils;

/**
 * 日期-范围选择类型
 */
public class DateCondition implements Condition {
    @Override
    public String buildSql(CstTableIndicator indicator, String... value) {
        String value1 = value[0];
        String value2 = value[1];
        String sql = "";
        if (StringUtils.isNotEmpty(value1)) {
            String column = indicator.getLabelColumn();
            sql += " and " + indicator.getTableId() + "." + column + " >= to_date('" + value1 + "', 'yyyy-mm-dd')";
        }
        if (StringUtils.isNotEmpty(value2)) {
            String column = indicator.getLabelColumn();
            sql += " and " + indicator.getTableId() + "." + column + " < to_date('" + value2 + "', 'yyyy-mm-dd') + 1";
        }
        return "".equals(sql) ? null : sql;
    }
}
