package cn.axzo.workflow.core.common.utils;

/**
 * @author wangli
 * @since 2023/10/9 15:10
 */
public class BpmnNativeQueryUtil {

    public static String sqlConnectors(StringBuilder stringBuilder) {
        if (stringBuilder.indexOf("ON") < 0 && stringBuilder.indexOf("WHERE") < 0) {
            return " WHERE";
        } else if (stringBuilder.indexOf("JOIN") >= 0 && stringBuilder.indexOf("ON") < 0) {
            return " ON";
        }
        return " AND";
    }

    public static String countSql(StringBuilder stringBuilder) {
        int start;
        if ((start = stringBuilder.indexOf("SELECT")) < 0) {
            return stringBuilder.toString();
        }
        if (stringBuilder.indexOf("JOIN") < 0) {
            return stringBuilder.replace(start + 7, 8, "count(1)").toString();
        } else {
            return stringBuilder.replace(start + 7, 10, "count(1)").toString();
        }
    }
}
