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

修复oracle数据库时间精度为毫秒导致版本检查异常问题

上级 c58c7c18
...@@ -21,6 +21,9 @@ import org.springframework.stereotype.Component; ...@@ -21,6 +21,9 @@ import org.springframework.stereotype.Component;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map; import java.util.Map;
/** /**
...@@ -112,7 +115,8 @@ public class VersionCheckAspect ...@@ -112,7 +115,8 @@ public class VersionCheckAspect
*/ */
@SneakyThrows @SneakyThrows
private Object getDBVersion(VersionCheck versionCheck,Object service,Object id){ private Object getDBVersion(VersionCheck versionCheck,Object service,Object id){
Object dbVersion=null; SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Timestamp dbVersion=null;
String versionField=versionCheck.versionfield(); String versionField=versionCheck.versionfield();
if(!ObjectUtils.isEmpty(service)){ if(!ObjectUtils.isEmpty(service)){
EvaluationContext oldContext = new StandardEvaluationContext(); EvaluationContext oldContext = new StandardEvaluationContext();
...@@ -120,7 +124,12 @@ public class VersionCheckAspect ...@@ -120,7 +124,12 @@ public class VersionCheckAspect
oldContext.setVariable("id",id); oldContext.setVariable("id",id);
Expression oldExp = parser.parseExpression("#service.get(#id)"); Expression oldExp = parser.parseExpression("#service.get(#id)");
EntityBase oldEntity =oldExp.getValue(oldContext, EntityBase.class); EntityBase oldEntity =oldExp.getValue(oldContext, EntityBase.class);
return oldEntity.get(versionField); Object oldDate=oldEntity.get(versionField);
if(oldDate!=null && oldDate instanceof Timestamp){
Timestamp db_time= (Timestamp) oldDate;
Date db_date = sdf.parse(sdf.format(db_time));
dbVersion=new Timestamp(db_date.getTime());
}
} }
return dbVersion; return dbVersion;
} }
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册