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

实体数据同步逻辑优化(remove)

上级 71269cc9
......@@ -90,8 +90,12 @@ public class RocketMQListenerProcessor implements MessageListenerOrderly {
<#assign inputAction=srfmethodname(dataSync.getInTestPSDEAction().codeName)>
if ("${dataSyncCodeName}".equalsIgnoreCase(tags)) {
${pub.getPKGCodeName()}.core.${dataEntity.getPSSystemModule().getCodeName()?lower_case}.domain.${entityName} domain = JSON.parseObject(new String(body),${pub.getPKGCodeName()}.core.${dataEntity.getPSSystemModule().getCodeName()?lower_case}.domain.${entityName}.class);
<#if inputAction.getCodeName()?lower_case == 'get' || inputAction.getCodeName()?lower_case == 'remove'>
${entityName}Service.${inputAction}(domain.get${srfcaseformat(keyfield.codeName,'l_u2lC')?cap_first}());
<#else>
${entityName}Service.${inputAction}(domain);
}
</#if>
<#else>
log.info("接收到[{}]消息,但未配置实体输入过滤行为,消息将被忽略。"+new String(msg.getBody()));
</#if>
......
......@@ -33,6 +33,9 @@ package ${pub.getPKGCodeName()}.util.aspect;
import lombok.extern.slf4j.Slf4j;
import ${pub.getPKGCodeName()}.util.domain.EntityBase;
import ${pub.getPKGCodeName()}.util.errors.BadRequestAlertException;
import ${pub.getPKGCodeName()}.util.helper.DEFieldCacheMap;
import java.lang.reflect.Method;
import com.alibaba.fastjson.JSON;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
......@@ -117,19 +120,51 @@ public class RocketMQAspect
* @return
*/
private Object getEntity(JoinPoint point) {
Object entity=null;
String action=point.getSignature().getName();
Object [] args = point.getArgs();
if(ObjectUtils.isEmpty(args) || args.length==0 || StringUtils.isEmpty(action)) {
return entity;
return null;
}
Object arg=args[0];
if(arg instanceof EntityBase || arg instanceof List) {
return arg;
}
else {
return null;
Object service = point.getTarget();
EntityBase entity = getEntity(service.getClass());
String id = DEFieldCacheMap.getDEKeyField(entity.getClass());
if(StringUtils.isEmpty(id)) {
log.debug("无法获取实体主键属性[{}]",entity.getClass().getSimpleName());
return null;
}
entity.set(id, arg);
return entity;
}
}
/**
* 获取实体
*
* @param service
* @return
*/
private EntityBase getEntity(Class service) {
Method[] methods = service.getDeclaredMethods();
for (Method method : methods) {
for (Class cls : method.getParameterTypes()) {
try {
Object arg = cls.newInstance();
if (arg instanceof EntityBase) {
return (EntityBase) arg;
}
} catch (Exception e) {
}
}
}
if(!ObjectUtils.isEmpty(service.getSuperclass()) && !service.getSuperclass().getName().equals(Object.class.getName())) {
return getEntity(service.getSuperclass());
}
throw new BadRequestAlertException("获取实体信息失败", "RocketMQAspect", "getEntity");
}
/**
......@@ -167,19 +202,19 @@ public class RocketMQAspect
<#assign isUpdate=updateArray?seq_contains(type)>
<#assign isDelete=deleteArray?seq_contains(type)>
<#if isCreate>
<#assign result="execution(* "+pub.getPKGCodeName()+".core.*.service.*"+dataEntity.codeName+"*.create*(..))">
<#assign result="execution(* "+pub.getPKGCodeName()+".core.*.service.I"+dataEntity.codeName+"Service.create*(..))">
</#if>
<#if isUpdate>
<#if result!="">
<#assign result=result+"||">
</#if>
<#assign result=result+"execution(* "+pub.getPKGCodeName()+".core.*.service.*"+dataEntity.codeName+"*.update*(..))">
<#assign result=result+"execution(* "+pub.getPKGCodeName()+".core.*.service.I"+dataEntity.codeName+"Service.update*(..))">
</#if>
<#if isDelete>
<#if result!="">
<#assign result=result+"||">
</#if>
<#assign result=result+"execution(* "+pub.getPKGCodeName()+".core.*.service.*"+dataEntity.codeName+"*.remove*(..))">
<#assign result=result+"execution(* "+pub.getPKGCodeName()+".core.*.service.I"+dataEntity.codeName+"Service.remove*(..))">
</#if>
</#if>
<#return "("+result+")">
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册