Commit edfb9051 by 孙喜旺

修复回调方法报错问题

1 parent 973c6e7c
...@@ -2,6 +2,7 @@ package com.linkwechat.wecom.aspectj; ...@@ -2,6 +2,7 @@ package com.linkwechat.wecom.aspectj;
import com.linkwechat.common.core.domain.BaseEntity; import com.linkwechat.common.core.domain.BaseEntity;
import com.linkwechat.common.exception.CustomException;
import com.linkwechat.common.utils.SecurityUtils; import com.linkwechat.common.utils.SecurityUtils;
import org.aspectj.lang.JoinPoint; import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Aspect;
...@@ -50,8 +51,9 @@ public class InsertAndUpdateAspect { ...@@ -50,8 +51,9 @@ public class InsertAndUpdateAspect {
private void isInsertBaseEntity(Object arg) { private void isInsertBaseEntity(Object arg) {
if (arg instanceof BaseEntity) { if (arg instanceof BaseEntity) {
BaseEntity next1 = (BaseEntity) arg; BaseEntity next1 = (BaseEntity) arg;
next1.setCreateBy(SecurityUtils.getUsername()); String userName = getUserName();
next1.setUpdateBy(SecurityUtils.getUsername()); next1.setCreateBy(userName);
next1.setUpdateBy(userName);
Date date = new Date(); Date date = new Date();
if (next1.getCreateTime() == null) { if (next1.getCreateTime() == null) {
next1.setCreateTime(date); next1.setCreateTime(date);
...@@ -62,6 +64,16 @@ public class InsertAndUpdateAspect { ...@@ -62,6 +64,16 @@ public class InsertAndUpdateAspect {
} }
} }
private String getUserName() {
String userName;
try {
userName = SecurityUtils.getUsername();
} catch (CustomException e){
userName = "admin";
}
return userName;
}
@Before(value = "executeUpdate()") @Before(value = "executeUpdate()")
public void updateHandle(JoinPoint joinPoint) { public void updateHandle(JoinPoint joinPoint) {
Object[] args = joinPoint.getArgs(); Object[] args = joinPoint.getArgs();
...@@ -73,7 +85,7 @@ public class InsertAndUpdateAspect { ...@@ -73,7 +85,7 @@ public class InsertAndUpdateAspect {
for (Object next : collection) { for (Object next : collection) {
if (next instanceof BaseEntity) { if (next instanceof BaseEntity) {
BaseEntity next1 = (BaseEntity) next; BaseEntity next1 = (BaseEntity) next;
next1.setUpdateBy(SecurityUtils.getUsername()); next1.setUpdateBy(getUserName());
Date date = new Date(); Date date = new Date();
if (next1.getUpdateTime() == null) { if (next1.getUpdateTime() == null) {
next1.setUpdateTime(date); next1.setUpdateTime(date);
...@@ -82,7 +94,7 @@ public class InsertAndUpdateAspect { ...@@ -82,7 +94,7 @@ public class InsertAndUpdateAspect {
} }
} else if (arg instanceof BaseEntity) { } else if (arg instanceof BaseEntity) {
BaseEntity arg1 = (BaseEntity) arg; BaseEntity arg1 = (BaseEntity) arg;
arg1.setUpdateBy(SecurityUtils.getUsername()); arg1.setUpdateBy(getUserName());
Date date = new Date(); Date date = new Date();
if (arg1.getUpdateTime() == null) { if (arg1.getUpdateTime() == null) {
arg1.setUpdateTime(date); arg1.setUpdateTime(date);
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!