code style

This commit is contained in:
yulichang 2021-11-18 18:19:40 +08:00
parent 13ec6499e4
commit 181664ed42
3 changed files with 31 additions and 20 deletions

View File

@ -13,22 +13,14 @@ import java.util.List;
* @author yulichang
* @see AbstractMethod
*/
public abstract class MPJAbstractMethod extends AbstractMethod {
public abstract class MPJAbstractMethod extends AbstractMethod implements MPJBaseMethod {
/**
* 连表操作不考虑entity查询和逻辑删除
*/
@Override
protected String sqlWhereEntityWrapper(boolean newLine, TableInfo table) {
String sqlScript = SqlScriptUtils.convertIf(String.format("${%s}", WRAPPER_SQLSEGMENT),
String.format("%s != null and %s != '' and %s", WRAPPER_SQLSEGMENT, WRAPPER_SQLSEGMENT,
WRAPPER_NONEMPTYOFWHERE), true);
sqlScript = SqlScriptUtils.convertWhere(sqlScript) + NEWLINE;
sqlScript += SqlScriptUtils.convertIf(String.format(" ${%s}", WRAPPER_SQLSEGMENT),
String.format("%s != null and %s != '' and %s", WRAPPER_SQLSEGMENT, WRAPPER_SQLSEGMENT,
WRAPPER_EMPTYOFWHERE), true);
sqlScript = SqlScriptUtils.convertIf(sqlScript, String.format("%s != null", WRAPPER), true);
return newLine ? NEWLINE + sqlScript : sqlScript;
return whereEntityWrapper(newLine);
}
@Override

View File

@ -0,0 +1,26 @@
package com.github.yulichang.method;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.core.toolkit.sql.SqlScriptUtils;
/**
* 连表sql条件
*
* @author yulichang
* @since 1.2.0
*/
public interface MPJBaseMethod extends Constants {
default String whereEntityWrapper(boolean newLine) {
String sqlScript = SqlScriptUtils.convertIf(String.format("${%s}", WRAPPER_SQLSEGMENT),
String.format("%s != null and %s != '' and %s", WRAPPER_SQLSEGMENT, WRAPPER_SQLSEGMENT,
WRAPPER_NONEMPTYOFWHERE), true);
sqlScript = SqlScriptUtils.convertWhere(sqlScript) + NEWLINE;
sqlScript += SqlScriptUtils.convertIf(String.format(" ${%s}", WRAPPER_SQLSEGMENT),
String.format("%s != null and %s != '' and %s", WRAPPER_SQLSEGMENT, WRAPPER_SQLSEGMENT,
WRAPPER_EMPTYOFWHERE), true);
sqlScript = SqlScriptUtils.convertIf(sqlScript, String.format("%s != null", WRAPPER), true);
return newLine ? NEWLINE + sqlScript : sqlScript;
}
}

View File

@ -3,6 +3,7 @@ package com.github.yulichang.method.mp;
import com.baomidou.mybatisplus.core.metadata.TableInfo;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.core.toolkit.sql.SqlScriptUtils;
import com.github.yulichang.method.MPJBaseMethod;
import com.github.yulichang.toolkit.Constant;
/**
@ -11,7 +12,7 @@ import com.github.yulichang.toolkit.Constant;
* @author yulichang
* @since 1.2.0
*/
public interface TableAlias extends Constants {
public interface TableAlias extends Constants, MPJBaseMethod {
default String getTableName(TableInfo tableInfo) {
return tableInfo.getTableName() + SPACE + SqlScriptUtils.convertIf("${ew.alias}",
@ -38,15 +39,7 @@ public interface TableAlias extends Constants {
sqlScript = SqlScriptUtils.convertWhere(sqlScript);
return newLine ? NEWLINE + sqlScript : sqlScript;
} else {
String sqlScript = SqlScriptUtils.convertIf(String.format("${%s}", WRAPPER_SQLSEGMENT),
String.format("%s != null and %s != '' and %s", WRAPPER_SQLSEGMENT, WRAPPER_SQLSEGMENT,
WRAPPER_NONEMPTYOFWHERE), true);
sqlScript = SqlScriptUtils.convertWhere(sqlScript) + NEWLINE;
sqlScript += SqlScriptUtils.convertIf(String.format(" ${%s}", WRAPPER_SQLSEGMENT),
String.format("%s != null and %s != '' and %s", WRAPPER_SQLSEGMENT, WRAPPER_SQLSEGMENT,
WRAPPER_EMPTYOFWHERE), true);
sqlScript = SqlScriptUtils.convertIf(sqlScript, String.format("%s != null", WRAPPER), true);
return newLine ? NEWLINE + sqlScript : sqlScript;
return whereEntityWrapper(newLine);
}
}