mirror of https://gitee.com/stylefeng/roses
【validator】更新校验表中唯一编码的问题
parent
a5fc70e51b
commit
079884ec94
|
@ -39,7 +39,7 @@ public @interface TableUniqueValue {
|
|||
String columnName();
|
||||
|
||||
/**
|
||||
* 主键id的字段名,默认为字段名为:id
|
||||
* 数据库主键id的字段名,例如 user_id
|
||||
*/
|
||||
String idFieldName() default "id";
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@ package cn.stylefeng.roses.kernel.validator.validators.unique;
|
|||
|
||||
import cn.hutool.core.lang.Dict;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.stylefeng.roses.kernel.rule.pojo.request.BaseRequest;
|
||||
import cn.stylefeng.roses.kernel.validator.context.RequestGroupContext;
|
||||
import cn.stylefeng.roses.kernel.validator.context.RequestParamContext;
|
||||
|
@ -117,13 +118,16 @@ public class TableUniqueValueValidator implements ConstraintValidator<TableUniqu
|
|||
// 获取请求字段中id的值
|
||||
Dict requestParam = RequestParamContext.get();
|
||||
|
||||
// 获取id字段的驼峰命名法
|
||||
String camelCaseIdFieldName = StrUtil.toCamelCase(idFieldName);
|
||||
|
||||
return UniqueValidateParam.builder()
|
||||
.tableName(tableName)
|
||||
.columnName(columnName)
|
||||
.value(fieldValue)
|
||||
.idFieldName(idFieldName)
|
||||
.excludeCurrentRecord(Boolean.TRUE)
|
||||
.id(requestParam.getLong(idFieldName))
|
||||
.id(requestParam.getLong(camelCaseIdFieldName))
|
||||
.excludeLogicDeleteItems(excludeLogicDeleteItems)
|
||||
.logicDeleteFieldName(logicDeleteFieldName)
|
||||
.logicDeleteValue(logicDeleteValue).build();
|
||||
|
|
|
@ -42,7 +42,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 || {} <> '{}')";
|
||||
String finalSql = StrUtil.format(sqlTemplate,
|
||||
uniqueValidateParam.getTableName(),
|
||||
uniqueValidateParam.getColumnName(),
|
||||
|
@ -71,7 +71,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 || {} <> '{}')";
|
||||
String finalSql = StrUtil.format(sqlTemplate,
|
||||
uniqueValidateParam.getTableName(),
|
||||
uniqueValidateParam.getColumnName(),
|
||||
|
|
Loading…
Reference in New Issue