forked from I3-YF/i3plus-mes-pcn-yfai
条码履历和加工单履历
parent
74d5cb101b
commit
b53ab28e86
@ -0,0 +1,11 @@
|
||||
package cn.estsh.i3plus.ext.mes.pcn.apiservice.aspect;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Target(ElementType.METHOD)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface MonitorLog {
|
||||
}
|
@ -0,0 +1,73 @@
|
||||
package cn.estsh.i3plus.ext.mes.pcn.apiservice.aspect;
|
||||
|
||||
import cn.estsh.i3plus.ext.mes.pcn.api.base.IMesPojoVersionService;
|
||||
import cn.estsh.i3plus.platform.common.tool.TimeTool;
|
||||
import cn.estsh.i3plus.pojo.base.bean.BaseBean;
|
||||
import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil;
|
||||
import org.aspectj.lang.JoinPoint;
|
||||
import org.aspectj.lang.annotation.After;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.annotation.Before;
|
||||
import org.aspectj.lang.annotation.Pointcut;
|
||||
import org.aspectj.lang.reflect.MethodSignature;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Description :
|
||||
* @Reference :
|
||||
* @Author : zxw
|
||||
* @CreateDate :
|
||||
* @Modify:
|
||||
**/
|
||||
@ConditionalOnExpression("'${pcn.aspect.repository:true}' == 'true'")
|
||||
@Aspect
|
||||
@Configuration
|
||||
public class PcnPojoAspect {
|
||||
|
||||
@Pointcut("@annotation(cn.estsh.i3plus.ext.mes.pcn.apiservice.aspect.MonitorLog)")
|
||||
public void controllerPointcut() {}
|
||||
|
||||
@Autowired
|
||||
private IMesPojoVersionService pojoVersionService;
|
||||
|
||||
@After("controllerPointcut()")
|
||||
public void after(JoinPoint joinPoint){
|
||||
|
||||
Object[] objs = joinPoint.getArgs();
|
||||
String methodName = joinPoint.getSignature().getName();
|
||||
if (methodName.startsWith("save") || methodName.startsWith("update")) {
|
||||
Object[] args = joinPoint.getArgs();
|
||||
List<Object> list = new ArrayList<>();
|
||||
for (Object arg : args) {
|
||||
if (arg.getClass().isArray()) {
|
||||
int len = Array.getLength(arg);
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Object item = Array.get(arg, i);
|
||||
if (BaseBean.class.isAssignableFrom(item.getClass())) {
|
||||
pojoVersionService.savePojoVersion((BaseBean)item, item.getClass());
|
||||
}
|
||||
}
|
||||
} else if (BaseBean.class.isAssignableFrom(arg.getClass())) {
|
||||
pojoVersionService.savePojoVersion((BaseBean)arg, arg.getClass());
|
||||
}
|
||||
}
|
||||
|
||||
} else if (methodName.startsWith("insert")) {
|
||||
Object[] args = joinPoint.getArgs();
|
||||
if (args.length > 0) {
|
||||
Object item = args[0];
|
||||
if (BaseBean.class.isAssignableFrom(item.getClass())) {
|
||||
pojoVersionService.insertPojoVersion((BaseBean) item, item.getClass());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,127 @@
|
||||
package cn.estsh.i3plus.ext.mes.pcn.apiservice.aspect;
|
||||
|
||||
import cn.estsh.i3plus.platform.common.tool.TimeTool;
|
||||
import cn.estsh.i3plus.pojo.base.bean.BaseBean;
|
||||
import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil;
|
||||
import org.aspectj.lang.JoinPoint;
|
||||
import org.aspectj.lang.annotation.After;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.annotation.Before;
|
||||
import org.aspectj.lang.annotation.Pointcut;
|
||||
import org.aspectj.lang.reflect.MethodSignature;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Description : 同步状态和时间更新
|
||||
* @Reference :
|
||||
* @Author : zxw
|
||||
* @CreateDate :
|
||||
* @Modify:
|
||||
**/
|
||||
@ConditionalOnExpression("'${pcn.aspect.repository:true}' == 'true'")
|
||||
@Aspect
|
||||
@Configuration
|
||||
public class PcnRepositoryAspect {
|
||||
|
||||
@Before("controllerPointcut()")
|
||||
public void before(JoinPoint joinPoint){
|
||||
String methodName = joinPoint.getSignature().getName();
|
||||
if (methodName.equals("save") || methodName.equals("update")) {
|
||||
Object[] args = joinPoint.getArgs();
|
||||
for (Object arg : args) {
|
||||
if (arg.getClass().isArray()) {
|
||||
int len = Array.getLength(arg);
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Object item = Array.get(arg, i);
|
||||
if (BaseBean.class.isAssignableFrom(item.getClass())) {
|
||||
updateBeanSync((BaseBean)item);
|
||||
}
|
||||
}
|
||||
} else if (BaseBean.class.isAssignableFrom(arg.getClass())) {
|
||||
updateBeanSync((BaseBean)arg);
|
||||
}
|
||||
}
|
||||
} else if (methodName.equals("insert")) {
|
||||
Object[] args = joinPoint.getArgs();
|
||||
if (args.length > 0) {
|
||||
Object item = args[0];
|
||||
if (BaseBean.class.isAssignableFrom(item.getClass())) {
|
||||
updateBeanSync((BaseBean)item);
|
||||
}
|
||||
}
|
||||
} else if (methodName.equals("saveAll")) {
|
||||
Object[] args = joinPoint.getArgs();
|
||||
if (args.length > 0) {
|
||||
Object arg = args[0];
|
||||
if (arg instanceof List) {
|
||||
List<Object> items = (List<Object>) arg;
|
||||
for (Object item : items) {
|
||||
if (BaseBean.class.isAssignableFrom(item.getClass())) {
|
||||
updateBeanSync((BaseBean)item);
|
||||
}
|
||||
}
|
||||
} else if (BaseBean.class.isAssignableFrom(arg.getClass())) {
|
||||
updateBeanSync((BaseBean)arg);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Pointcut("execution(* cn.estsh.*..*.repository.*..*(..))")
|
||||
public void controllerPointcut() {}
|
||||
|
||||
@After("controllerPointcut()")
|
||||
public void after(JoinPoint joinPoint) {
|
||||
String methodName = joinPoint.getSignature().getName();
|
||||
if (methodName.startsWith("updateByProperties")) {
|
||||
try {
|
||||
Object[] args = joinPoint.getArgs();
|
||||
Method method = ((MethodSignature)joinPoint.getSignature()).getMethod();
|
||||
if (args.length == 4) {
|
||||
if (args[2].getClass().isArray()) {
|
||||
method.invoke(joinPoint.getTarget(), args[0], args[1], new String[]{"modifyDatetime", "systemSyncStatus"},
|
||||
new Object[]{TimeTool.getNowTime(true), CommonEnumUtil.FALSE});
|
||||
} else {
|
||||
method.invoke(joinPoint.getTarget(), args[0], args[1], "systemSyncStatus", CommonEnumUtil.FALSE);
|
||||
}
|
||||
} else if (args.length == 3) {
|
||||
if (args[0].getClass().isArray()) {
|
||||
method.invoke(joinPoint.getTarget(), new String[]{ "systemSyncStatus"},
|
||||
new Object[]{ CommonEnumUtil.FALSE}, args[2]);
|
||||
} else {
|
||||
method.invoke(joinPoint.getTarget(), "systemSyncStatus", CommonEnumUtil.FALSE, args[2]);
|
||||
}
|
||||
}
|
||||
} catch (IllegalAccessException | InvocationTargetException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
} else if (methodName.equals("updateByHqlWhere")) {
|
||||
Object[] args = joinPoint.getArgs();
|
||||
try {
|
||||
if (args.length == 3) {
|
||||
Method method = ((MethodSignature)joinPoint.getSignature()).getMethod();
|
||||
if (args[1].getClass().isArray()) {
|
||||
method.invoke(joinPoint.getTarget(), args[0], new String[]{"systemSyncStatus"},
|
||||
new Object[]{ CommonEnumUtil.FALSE});
|
||||
} else {
|
||||
method.invoke(joinPoint.getTarget(), TimeTool.getNowTime(true), args[2]);
|
||||
method.invoke(joinPoint.getTarget(), "systemSyncStatus", CommonEnumUtil.FALSE, args[2]);
|
||||
}
|
||||
}
|
||||
} catch (IllegalAccessException | InvocationTargetException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void updateBeanSync(BaseBean bean) {
|
||||
bean.setSystemSyncStatus(CommonEnumUtil.FALSE);
|
||||
bean.setModifyDatetime(TimeTool.getNowTime(true));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue