提交 de7914a6 编写于 作者: ibizdev's avatar ibizdev

zhouweidong@lab.ibiz5.com 发布系统代码

上级 69f576c2
...@@ -68,8 +68,6 @@ public interface IIBZEmployeeService extends IService<IBZEmployee>{ ...@@ -68,8 +68,6 @@ public interface IIBZEmployeeService extends IService<IBZEmployee>{
List<IBZEmployee> getIbzemployeeByIds(List<String> ids) ; List<IBZEmployee> getIbzemployeeByIds(List<String> ids) ;
List<IBZEmployee> getIbzemployeeByEntities(List<IBZEmployee> entities) ; List<IBZEmployee> getIbzemployeeByEntities(List<IBZEmployee> entities) ;
} }
...@@ -23,7 +23,7 @@ import java.util.Map; ...@@ -23,7 +23,7 @@ import java.util.Map;
* 实体属性默认值切面,只有新建(Create)时才会填充默认值 * 实体属性默认值切面,只有新建(Create)时才会填充默认值
*/ */
@Aspect @Aspect
@Order(0) @Order(50)
@Component @Component
public class DEFieldDefaultValueAspect public class DEFieldDefaultValueAspect
{ {
......
package cn.ibizlab.util.aspect; package cn.ibizlab.util.aspect;
import lombok.SneakyThrows; import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import cn.ibizlab.util.annotation.VersionCheck; import cn.ibizlab.util.annotation.VersionCheck;
import cn.ibizlab.util.domain.EntityBase; import cn.ibizlab.util.domain.EntityBase;
import cn.ibizlab.util.errors.BadRequestAlertException; import cn.ibizlab.util.errors.BadRequestAlertException;
...@@ -24,7 +23,7 @@ import java.lang.reflect.Field; ...@@ -24,7 +23,7 @@ import java.lang.reflect.Field;
* 数据库版本检查 * 数据库版本检查
*/ */
@Aspect @Aspect
@Order(0) @Order(50)
@Component @Component
public class VersionCheckAspect public class VersionCheckAspect
{ {
...@@ -33,22 +32,40 @@ public class VersionCheckAspect ...@@ -33,22 +32,40 @@ public class VersionCheckAspect
@SneakyThrows @SneakyThrows
@Before("execution(* cn.ibizlab.*.rest.*.update(..)) && @annotation(versionCheck)") @Before("execution(* cn.ibizlab.*.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(* cn.ibizlab.*.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 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册