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

版本检查

上级 dabcd458
...@@ -26,7 +26,7 @@ import java.util.Map; ...@@ -26,7 +26,7 @@ import java.util.Map;
* 实体属性默认值切面,只有新建(Create)时才会填充默认值 * 实体属性默认值切面,只有新建(Create)时才会填充默认值
*/ */
@Aspect @Aspect
@Order(0) @Order(50)
@Component @Component
public class DEFieldDefaultValueAspect public class DEFieldDefaultValueAspect
{ {
......
...@@ -4,7 +4,6 @@ TARGET=PSSYSTEM ...@@ -4,7 +4,6 @@ TARGET=PSSYSTEM
package ${pub.getPKGCodeName()}.util.aspect; package ${pub.getPKGCodeName()}.util.aspect;
import lombok.SneakyThrows; import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import ${pub.getPKGCodeName()}.util.annotation.VersionCheck; import ${pub.getPKGCodeName()}.util.annotation.VersionCheck;
import ${pub.getPKGCodeName()}.util.domain.EntityBase; import ${pub.getPKGCodeName()}.util.domain.EntityBase;
import ${pub.getPKGCodeName()}.util.errors.BadRequestAlertException; import ${pub.getPKGCodeName()}.util.errors.BadRequestAlertException;
...@@ -27,7 +26,7 @@ import java.lang.reflect.Field; ...@@ -27,7 +26,7 @@ import java.lang.reflect.Field;
* 数据库版本检查 * 数据库版本检查
*/ */
@Aspect @Aspect
@Order(0) @Order(50)
@Component @Component
public class VersionCheckAspect public class VersionCheckAspect
{ {
...@@ -36,22 +35,40 @@ public class VersionCheckAspect ...@@ -36,22 +35,40 @@ public class VersionCheckAspect
@SneakyThrows @SneakyThrows
@Before("execution(* ${pub.getPKGCodeName()}.*.rest.*.update(..)) && @annotation(versionCheck)") @Before("execution(* ${pub.getPKGCodeName()}.*.rest.*.update(..)) && @annotation(versionCheck)")
public void BeforeUpdate(JoinPoint point, VersionCheck versionCheck){ public void BeforeUpdate(JoinPoint point, VersionCheck versionCheck){
EvaluationContext context = new StandardEvaluationContext();
Object[] args = point.getArgs(); Object[] args = point.getArgs();
Object id=args[0]; Object id=args[0];
Object dto=args[1]; Object dto=args[1];
if(ObjectUtils.isEmpty(id) || ObjectUtils.isEmpty(dto)) if(ObjectUtils.isEmpty(id) || ObjectUtils.isEmpty(dto))
return; return;
String versionField=versionCheck.versionfield(); String versionField=versionCheck.versionfield();
if(StringUtils.isEmpty(versionCheck)) if(StringUtils.isEmpty(versionField))
return;
versionCheck(versionCheck,point.getTarget(),dto,id);
}
@SneakyThrows
@Before("execution(* ${pub.getPKGCodeName()}.*.rest.*.updateBy*(..)) && @annotation(versionCheck)")
public void BeforeUpdateBy(JoinPoint point, VersionCheck versionCheck){
Object[] args = point.getArgs();
Object id=args[1];
Object dto=args[2];
if(ObjectUtils.isEmpty(id) || ObjectUtils.isEmpty(dto))
return;
String versionField=versionCheck.versionfield();
if(StringUtils.isEmpty(versionField))
return; return;
versionCheck(versionCheck,point.getTarget(),dto,id);
}
private void versionCheck(VersionCheck versionCheck,Object resource,Object dto,Object id ){
EvaluationContext context = new StandardEvaluationContext();
context.setVariable("dto",dto); context.setVariable("dto",dto);
Expression newExp = parser.parseExpression(String.format("#dto.%s",versionField)); Expression newExp = parser.parseExpression(String.format("#dto.%s",versionCheck.versionfield()));
Object newVersion=newExp.getValue(context); Object newVersion=newExp.getValue(context);
if(ObjectUtils.isEmpty(newVersion)) if(ObjectUtils.isEmpty(newVersion))
return; return;
//进行版本检查 //进行版本检查
Object oldVersion =getDBVersion(versionCheck,getService(point.getTarget(),versionCheck.entity()),id); Object oldVersion =getDBVersion(versionCheck,getService(resource,versionCheck.entity()),id);
if(!ObjectUtils.isEmpty(oldVersion)){ if(!ObjectUtils.isEmpty(oldVersion)){
if(RuleUtils.gt(newVersion,oldVersion)) if(RuleUtils.gt(newVersion,oldVersion))
throw new BadRequestAlertException("数据已变更,可能后台数据已被修改,请重新加载数据","VersionCheckAspect","versionCheck"); throw new BadRequestAlertException("数据已变更,可能后台数据已被修改,请重新加载数据","VersionCheckAspect","versionCheck");
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册