提交 5b8015a6 编写于 作者: zhouweidong's avatar zhouweidong

优化错误信息

上级 9011e277
......@@ -74,40 +74,36 @@ public class DupCheckAspect {
Map<String, DEField> deFields = DEFieldCacheMap.getDEFields(entity.getClass());
for (Map.Entry<String, DEField> deField : deFields.entrySet()) {
String fieldName = deField.getKey();
try {
DEField fieldAnnotation = deField.getValue();
DupCheck dupCheck = fieldAnnotation.dupCheck();
String dupCheckField=fieldAnnotation.dupCheckField();
if (dupCheck == DupCheck.ALL) {
Object newValue =getDEFieldValue(entity,fieldName);
//获取searchContext
EvaluationContext searchContextCtx = new StandardEvaluationContext();
searchContextCtx.setVariable("service", service);
Expression searchContextExp = parser.parseExpression("#service.getSearchContext()");
SearchContextBase searchContext = searchContextExp.getValue(searchContextCtx, SearchContextBase.class);
DEField fieldAnnotation = deField.getValue();
DupCheck dupCheck = fieldAnnotation.dupCheck();
String dupCheckField=fieldAnnotation.dupCheckField();
if (dupCheck == DupCheck.ALL) {
Object newValue =getDEFieldValue(entity,fieldName);
//获取searchContext
EvaluationContext searchContextCtx = new StandardEvaluationContext();
searchContextCtx.setVariable("service", service);
Expression searchContextExp = parser.parseExpression("#service.getSearchContext()");
SearchContextBase searchContext = searchContextExp.getValue(searchContextCtx, SearchContextBase.class);
//设置检查属性值
QueryFilter filter = new QueryFilter();
setValue(entity,filter,fieldName,newValue);
//设置检查属性值
QueryFilter filter = new QueryFilter();
setValue(entity,filter,fieldName,newValue);
//设定重复值检查范围
if(!StringUtils.isEmpty(dupCheckField)){
Object dupFieldValue=getDEFieldValue(entity,dupCheckField);
setValue(entity,filter,dupCheckField,dupFieldValue);
}
searchContext.setFilter(filter);
//使用当前值到数据库中进行查询,判断是否重复
EvaluationContext oldValueMappingCtx = new StandardEvaluationContext();
oldValueMappingCtx.setVariable("service", service);
oldValueMappingCtx.setVariable("searchContext", searchContext);
Expression oldValueMappingExp = parser.parseExpression(String.format("#service.%s(#searchContext)",defaultDS));
Page oldData = oldValueMappingExp.getValue(oldValueMappingCtx, Page.class);
if (!ObjectUtils.isEmpty(oldData) && !ObjectUtils.isEmpty(oldData.getContent()) && oldData.getContent().size() > 1) {
throw new BadRequestAlertException(String.format("属性[%s]已存在[%s]值!", fieldName, newValue), "DupCheckAspect", "check");
}
//设定重复值检查范围
if(!StringUtils.isEmpty(dupCheckField)){
Object dupFieldValue=getDEFieldValue(entity,dupCheckField);
setValue(entity,filter,dupCheckField,dupFieldValue);
}
searchContext.setFilter(filter);
//使用当前值到数据库中进行查询,判断是否重复
EvaluationContext oldValueMappingCtx = new StandardEvaluationContext();
oldValueMappingCtx.setVariable("service", service);
oldValueMappingCtx.setVariable("searchContext", searchContext);
Expression oldValueMappingExp = parser.parseExpression(String.format("#service.%s(#searchContext)",defaultDS));
Page oldData = oldValueMappingExp.getValue(oldValueMappingCtx, Page.class);
if (!ObjectUtils.isEmpty(oldData) && !ObjectUtils.isEmpty(oldData.getContent()) && oldData.getContent().size() > 1) {
throw new BadRequestAlertException(String.format("数据保存失败,属性[%s]:值[%s]已存在!", fieldName, newValue), "DupCheckAspect", "check");
}
} catch (Exception e) {
throw new BadRequestAlertException(String.format("实体属性[%s]重复值检查失败,%s",fieldName,e),"DupCheckAspect","check");
}
}
}
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册