更新系统同步标志

tags/yfai-mes-ext-v1.0
jun 11 months ago
parent 3720a134c5
commit 6160d3da6a

@ -0,0 +1,130 @@
package cn.estsh.i3plus.ext.mes.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 : junsheng.li
* @CreateDate 2024/6/27 10:10
* @Modify:
**/
@ConditionalOnExpression("'${mes.aspect.repository:false}' == 'true'")
@Aspect
@Configuration
public class MesRepositoryAspect {
@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], "modifyDatetime", TimeTool.getNowTime(true));
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[]{"modifyDatetime", "systemSyncStatus"},
new Object[]{TimeTool.getNowTime(true), CommonEnumUtil.FALSE}, args[2]);
} else {
method.invoke(joinPoint.getTarget(), "modifyDatetime", TimeTool.getNowTime(true), args[2]);
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[]{"modifyDatetime", "systemSyncStatus"},
new Object[]{TimeTool.getNowTime(true), CommonEnumUtil.FALSE});
} else {
method.invoke(joinPoint.getTarget(), "modifyDatetime", 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));
}
}

@ -70,4 +70,6 @@ huaweiobs.bucketName=mes-wms-obs
#访问的key
huaweiobs.ak=TPNXQ2LUMRHNYYOBO8QO
#访问的秘钥
huaweiobs.sk=ppTtbisjdBxQsU124mFnubSojUsB6Wvp9KSaUAeb
huaweiobs.sk=ppTtbisjdBxQsU124mFnubSojUsB6Wvp9KSaUAeb
#更新系统同步标识
mes.aspect.repository = true
Loading…
Cancel
Save