mirror of https://gitee.com/stylefeng/roses
【7.0.4】更新异常提示,修改validator相关sql
parent
bf49e42d9f
commit
d4dd1e545a
|
@ -83,7 +83,12 @@ public enum ValidatorExceptionEnum implements AbstractExceptionEnum {
|
|||
/**
|
||||
* 验证码错误
|
||||
*/
|
||||
CAPTCHA_ERROR(RuleConstants.USER_OPERATION_ERROR_TYPE_CODE + ValidatorConstants.VALIDATOR_EXCEPTION_STEP_CODE + "09", "验证码错误");
|
||||
CAPTCHA_ERROR(RuleConstants.USER_OPERATION_ERROR_TYPE_CODE + ValidatorConstants.VALIDATOR_EXCEPTION_STEP_CODE + "09", "验证码错误"),
|
||||
|
||||
/**
|
||||
* 数据库唯一性校验错误,sql执行错误
|
||||
*/
|
||||
UNIQUE_VALIDATE_SQL_ERROR(RuleConstants.USER_OPERATION_ERROR_TYPE_CODE + ValidatorConstants.VALIDATOR_EXCEPTION_STEP_CODE + "10", "数据库唯一性校验错误,sql执行错误,具体信息:{}");
|
||||
|
||||
/**
|
||||
* 错误编码
|
||||
|
|
|
@ -46,7 +46,14 @@ public class TableUniqueValueService {
|
|||
* @date 2020/11/4 15:08
|
||||
*/
|
||||
public static boolean getFiledUniqueFlag(UniqueValidateParam uniqueValidateParam) {
|
||||
try {
|
||||
return doValidate(uniqueValidateParam);
|
||||
} catch (Exception exception) {
|
||||
throw new ParamValidateException(ValidatorExceptionEnum.UNIQUE_VALIDATE_SQL_ERROR, exception.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean doValidate(UniqueValidateParam uniqueValidateParam) {
|
||||
DbOperatorApi dbOperatorApi = DbOperatorContext.me();
|
||||
|
||||
int resultCount = 0;
|
||||
|
@ -65,7 +72,7 @@ public class TableUniqueValueService {
|
|||
// 不排除当前记录,排除逻辑删除的内容
|
||||
if (!uniqueValidateParam.getExcludeCurrentRecord()
|
||||
&& uniqueValidateParam.getExcludeLogicDeleteItems()) {
|
||||
String sqlTemplate = "select count(*) from {} where {} = {0} and ({} is null || {} <> '{}')";
|
||||
String sqlTemplate = "select count(*) from {} where {} = {0} and ({} is null or {} <> '{}')";
|
||||
String finalSql = StrUtil.format(sqlTemplate,
|
||||
uniqueValidateParam.getTableName(),
|
||||
uniqueValidateParam.getColumnName(),
|
||||
|
@ -94,7 +101,7 @@ public class TableUniqueValueService {
|
|||
// id判空
|
||||
paramIdValidate(uniqueValidateParam);
|
||||
|
||||
String sqlTemplate = "select count(*) from {} where {} = {0} and {} <> {1} and ({} is null || {} <> '{}')";
|
||||
String sqlTemplate = "select count(*) from {} where {} = {0} and {} <> {1} and ({} is null or {} <> '{}')";
|
||||
String finalSql = StrUtil.format(sqlTemplate,
|
||||
uniqueValidateParam.getTableName(),
|
||||
uniqueValidateParam.getColumnName(),
|
||||
|
@ -107,10 +114,9 @@ public class TableUniqueValueService {
|
|||
|
||||
// 如果大于0,代表不是唯一的当前校验的值
|
||||
return resultCount <= 0;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 几个参数的为空校验
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue