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

代码规范检查

上级 a50405f7
...@@ -45,7 +45,7 @@ import com.baomidou.mybatisplus.core.toolkit.IdWorker; ...@@ -45,7 +45,7 @@ import com.baomidou.mybatisplus.core.toolkit.IdWorker;
@Setter @Setter
@NoArgsConstructor @NoArgsConstructor
@JsonIgnoreProperties(value = "handler") @JsonIgnoreProperties(value = "handler")
@TableName(value = "${item.getTableName()}",resultMap = "${item.codeName}ResultMap") @TableName(value = "${item.getTableName()}", resultMap = "${item.codeName}ResultMap")
public class ${item.getCodeName()} extends EntityMP implements Serializable { public class ${item.getCodeName()} extends EntityMP implements Serializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
...@@ -141,11 +141,11 @@ public class ${item.getCodeName()} extends EntityMP implements Serializable { ...@@ -141,11 +141,11 @@ public class ${item.getCodeName()} extends EntityMP implements Serializable {
<#comment>主键</#comment> <#comment>主键</#comment>
<#if defield.isKeyDEField()==true && defield.isPhisicalDEField()==true> <#if defield.isKeyDEField()==true && defield.isPhisicalDEField()==true>
<#if defield.getDataType() == "ACID"> <#if defield.getDataType() == "ACID">
@TableId(value= "${columnname}",type=IdType.AUTO) @TableId(value= "${columnname}", type = IdType.AUTO)
<#elseif defield.getDataType() == "BIGINT"> <#elseif defield.getDataType() == "BIGINT">
@TableId(value= "${columnname}",type=IdType.ASSIGN_ID) @TableId(value= "${columnname}", type = IdType.ASSIGN_ID)
<#else> <#else>
@TableId(value= "${columnname}",type=IdType.ASSIGN_UUID) @TableId(value= "${columnname}", type = IdType.ASSIGN_UUID)
</#if> </#if>
<#elseif defield.isPhisicalDEField()==false> <#elseif defield.isPhisicalDEField()==false>
@TableField(exist = false) @TableField(exist = false)
...@@ -242,7 +242,7 @@ public class ${item.getCodeName()} extends EntityMP implements Serializable { ...@@ -242,7 +242,7 @@ public class ${item.getCodeName()} extends EntityMP implements Serializable {
*/ */
public void set${srfcaseformat(listcode,'l_u2lC')?cap_first}(List<${pub.getPKGCodeName()}.core.${der.getMinorPSDataEntity().getPSSystemModule().getCodeName()?lower_case}.domain.${der.getMinorPSDataEntity().getCodeName()}> ${srfcaseformat(listcode,'l_u2lC')}) { public void set${srfcaseformat(listcode,'l_u2lC')?cap_first}(List<${pub.getPKGCodeName()}.core.${der.getMinorPSDataEntity().getPSSystemModule().getCodeName()?lower_case}.domain.${der.getMinorPSDataEntity().getCodeName()}> ${srfcaseformat(listcode,'l_u2lC')}) {
this.${srfcaseformat(listcode,'l_u2lC')} = ${srfcaseformat(listcode,'l_u2lC')} ; this.${srfcaseformat(listcode,'l_u2lC')} = ${srfcaseformat(listcode,'l_u2lC')} ;
this.modify("${columnname}",(${srfcaseformat(listcode,'l_u2lC')}!=null)?${srfcaseformat(listcode,'l_u2lC')}:(new ArrayList())); this.modify("${columnname}", (${srfcaseformat(listcode,'l_u2lC')}!=null)?${srfcaseformat(listcode,'l_u2lC')}:(new ArrayList()));
} }
</#if> </#if>
</#if> </#if>
...@@ -267,7 +267,7 @@ public class ${item.getCodeName()} extends EntityMP implements Serializable { ...@@ -267,7 +267,7 @@ public class ${item.getCodeName()} extends EntityMP implements Serializable {
*/ */
public void set${publicCodeName}(${srfr7javatype(defield.getStdDataType())} ${prvateCodeName}) { public void set${publicCodeName}(${srfr7javatype(defield.getStdDataType())} ${prvateCodeName}) {
this.${prvateCodeName} = ${prvateCodeName} ; this.${prvateCodeName} = ${prvateCodeName} ;
this.modify("${columnname}",${prvateCodeName}); this.modify("${columnname}", ${prvateCodeName});
} }
<#if defDataType == "DATETIME" || ((defDataType=='PICKUPDATA'||defDataType=='INHERIT') && srfdatatype(defield.getStdDataType())== "DATETIME" && defield.getValueFormat()=="%1$tY-%1$tm-%1$td %1$tH:%1$tM:%1$tS")> <#if defDataType == "DATETIME" || ((defDataType=='PICKUPDATA'||defDataType=='INHERIT') && srfdatatype(defield.getStdDataType())== "DATETIME" && defield.getValueFormat()=="%1$tY-%1$tm-%1$td %1$tH:%1$tM:%1$tS")>
...@@ -327,7 +327,7 @@ public class ${item.getCodeName()} extends EntityMP implements Serializable { ...@@ -327,7 +327,7 @@ public class ${item.getCodeName()} extends EntityMP implements Serializable {
<#list item.getUnionKeyValuePSDEFields() as defield> <#list item.getUnionKeyValuePSDEFields() as defield>
<#assign unionKeyPrivateCodeName = srfcaseformat(defield.getCodeName(),'l_u2lC') > <#assign unionKeyPrivateCodeName = srfcaseformat(defield.getCodeName(),'l_u2lC') >
<#assign unionKeyPublicCodeName = unionKeyPrivateCodeName?cap_first > <#assign unionKeyPublicCodeName = unionKeyPrivateCodeName?cap_first >
this.set("${unionKeyPrivateCodeName}",args[${defield_index}]); this.set("${unionKeyPrivateCodeName}", args[${defield_index}]);
</#list> </#list>
} }
} }
......
...@@ -26,7 +26,7 @@ import com.alibaba.fastjson.JSONObject; ...@@ -26,7 +26,7 @@ import com.alibaba.fastjson.JSONObject;
@com.baomidou.dynamic.datasource.annotation.DS("${item.getDSLink()?lower_case}") @com.baomidou.dynamic.datasource.annotation.DS("${item.getDSLink()?lower_case}")
</#if> </#if>
</#if> </#if>
public interface ${item.getCodeName()}Mapper extends BaseMapper<${item.getCodeName()}>{ public interface ${item.getCodeName()}Mapper extends BaseMapper<${item.getCodeName()}> {
<#if item.getAllPSDEDataSets()??> <#if item.getAllPSDEDataSets()??>
<#list item.getAllPSDEDataSets() as dedataset> <#list item.getAllPSDEDataSets() as dedataset>
...@@ -36,17 +36,17 @@ public interface ${item.getCodeName()}Mapper extends BaseMapper<${item.getCodeNa ...@@ -36,17 +36,17 @@ public interface ${item.getCodeName()}Mapper extends BaseMapper<${item.getCodeNa
<#assign keyfieldCodeName=item.getKeyPSDEField().codeName?lower_case> <#assign keyfieldCodeName=item.getKeyPSDEField().codeName?lower_case>
@Override @Override
<#if item.isEnableEntityCache()==true> <#if item.isEnableEntityCache()==true>
@Cacheable( value="${item.codeName?lower_case}",key = "'row:'+#p0") @Cacheable(value="${item.codeName?lower_case}",key = "'row:'+#p0")
</#if> </#if>
${item.getCodeName()} selectById(Serializable id); ${item.getCodeName()} selectById(Serializable id);
@Override @Override
<#if item.isEnableEntityCache()==true> <#if item.isEnableEntityCache()==true>
@CacheEvict( value="${item.codeName?lower_case}",key = "'row:'+#p0.${keyfieldCodeName}") @CacheEvict(value="${item.codeName?lower_case}",key = "'row:'+#p0.${keyfieldCodeName}")
</#if> </#if>
int insert(${item.getCodeName()} entity); int insert(${item.getCodeName()} entity);
@Override @Override
<#if item.isEnableEntityCache()==true> <#if item.isEnableEntityCache()==true>
@CacheEvict( value="${item.codeName?lower_case}",key = "'row:'+#p0.${keyfieldCodeName}") @CacheEvict(value="${item.codeName?lower_case}",key = "'row:'+#p0.${keyfieldCodeName}")
</#if> </#if>
int updateById(@Param(Constants.ENTITY) ${item.getCodeName()} entity); int updateById(@Param(Constants.ENTITY) ${item.getCodeName()} entity);
@Override @Override
...@@ -56,16 +56,16 @@ public interface ${item.getCodeName()}Mapper extends BaseMapper<${item.getCodeNa ...@@ -56,16 +56,16 @@ public interface ${item.getCodeName()}Mapper extends BaseMapper<${item.getCodeNa
int update(@Param(Constants.ENTITY) ${item.getCodeName()} entity, @Param("ew") Wrapper<${item.codeName}> updateWrapper); int update(@Param(Constants.ENTITY) ${item.getCodeName()} entity, @Param("ew") Wrapper<${item.codeName}> updateWrapper);
@Override @Override
<#if item.isEnableEntityCache()==true> <#if item.isEnableEntityCache()==true>
@CacheEvict( value="${item.codeName?lower_case}",key = "'row:'+#p0") @CacheEvict(value="${item.codeName?lower_case}",key = "'row:'+#p0")
</#if> </#if>
int deleteById(Serializable id); int deleteById(Serializable id);
/** /**
* 自定义查询SQL * 自定义查询SQL
* @param sql * @param sql
* @return * @return
*/ */
@Select("${r'${sql}'}") @Select("${r'${sql}'}")
List<JSONObject> selectBySQL(@Param("sql") String sql, @Param("et")Map param); List<JSONObject> selectBySQL(@Param("sql") String sql, @Param("et")Map param);
/** /**
* 自定义更新SQL * 自定义更新SQL
......
...@@ -44,7 +44,7 @@ import com.baomidou.mybatisplus.extension.service.IService; ...@@ -44,7 +44,7 @@ import com.baomidou.mybatisplus.extension.service.IService;
/** /**
* 实体[${item.codeName}] 服务对象接口 * 实体[${item.codeName}] 服务对象接口
*/ */
public interface I${item.codeName}Service extends IService<${item.codeName}>{ public interface I${item.codeName}Service extends IService<${item.codeName}> {
<@addIDESerivceBody /> <@addIDESerivceBody />
/** /**
......
...@@ -15,7 +15,7 @@ import ${pubPkgCodeName}.${itemSysApiCodeNameLC}.dto.${item.getCodeName()}DTO; ...@@ -15,7 +15,7 @@ import ${pubPkgCodeName}.${itemSysApiCodeNameLC}.dto.${item.getCodeName()}DTO;
import ${pub.getPKGCodeName()}.util.domain.MappingBase; import ${pub.getPKGCodeName()}.util.domain.MappingBase;
import org.mapstruct.factory.Mappers; import org.mapstruct.factory.Mappers;
@Mapper(componentModel = "spring", uses = {},implementationName="${mappingName}", @Mapper(componentModel = "spring", uses = {}, implementationName = "${mappingName}",
nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE, nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE,
nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS) nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS)
public interface ${item.getCodeName()}Mapping extends MappingBase<${item.codeName}DTO, ${de.codeName}> { public interface ${item.getCodeName()}Mapping extends MappingBase<${item.codeName}DTO, ${de.codeName}> {
......
...@@ -53,32 +53,31 @@ public class AuditAspect ...@@ -53,32 +53,31 @@ public class AuditAspect
*/ */
@AfterReturning(value = "execution(* ${pub.getPKGCodeName()}.core.*.service.*.create(..))<#if hasESEntity>&& !execution(* ${pub.getPKGCodeName()}.core.es.service.*.create*(..))</#if>") @AfterReturning(value = "execution(* ${pub.getPKGCodeName()}.core.*.service.*.create(..))<#if hasESEntity>&& !execution(* ${pub.getPKGCodeName()}.core.es.service.*.create*(..))</#if>")
@SneakyThrows @SneakyThrows
public void create(JoinPoint point){ public void create(JoinPoint point) {
HttpServletRequest request=null; HttpServletRequest request = null;
RequestAttributes requestAttributes= RequestContextHolder.getRequestAttributes(); RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
if(requestAttributes!=null){ if(requestAttributes!=null) {
request=((ServletRequestAttributes)requestAttributes).getRequest(); request = ((ServletRequestAttributes)requestAttributes).getRequest();
} }
Object [] args = point.getArgs(); Object [] args = point.getArgs();
if(ObjectUtils.isEmpty(args) || args.length==0) { if(ObjectUtils.isEmpty(args) || args.length==0) {
return; return;
} }
Object serviceParam =args[0]; Object serviceParam = args[0];
if(serviceParam instanceof EntityBase){ if(serviceParam instanceof EntityBase) {
EntityBase entity=(EntityBase)serviceParam; EntityBase entity = (EntityBase)serviceParam;
Map<String, Audit> auditFields= DEFieldCacheMap.getAuditFields(entity.getClass()); Map<String, Audit> auditFields = DEFieldCacheMap.getAuditFields(entity.getClass());
//是否有审计属性 //是否有审计属性
if(auditFields.size()==0) { if(auditFields.size()==0) {
return; return;
} }
String idField = DEFieldCacheMap.getDEKeyField(entity.getClass());
String idField=DEFieldCacheMap.getDEKeyField(entity.getClass()); Object idValue = "";
Object idValue=""; if(!StringUtils.isEmpty(idField)) {
if(!StringUtils.isEmpty(idField)){
idValue=entity.get(idField); idValue=entity.get(idField);
} }
//记录审计日志 //记录审计日志
dataAuditService.createAudit(request,entity,idValue,auditFields); dataAuditService.createAudit(request, entity, idValue, auditFields);
} }
} }
...@@ -89,42 +88,38 @@ public class AuditAspect ...@@ -89,42 +88,38 @@ public class AuditAspect
*/ */
@Around("execution(* ${pub.getPKGCodeName()}.core.*.service.*.update(..))<#if hasESEntity>&& !execution(* ${pub.getPKGCodeName()}.core.es.service.*.update*(..))</#if>") @Around("execution(* ${pub.getPKGCodeName()}.core.*.service.*.update(..))<#if hasESEntity>&& !execution(* ${pub.getPKGCodeName()}.core.es.service.*.update*(..))</#if>")
public Object update(ProceedingJoinPoint point) throws Throwable { public Object update(ProceedingJoinPoint point) throws Throwable {
HttpServletRequest request=null; HttpServletRequest request = null;
RequestAttributes requestAttributes= RequestContextHolder.getRequestAttributes(); RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
if(requestAttributes!=null){ if(requestAttributes!=null) {
request=((ServletRequestAttributes)requestAttributes).getRequest(); request=((ServletRequestAttributes)requestAttributes).getRequest();
} }
Object serviceObj=point.getTarget(); Object serviceObj = point.getTarget();
Object args[]=point.getArgs(); Object args[] = point.getArgs();
if(ObjectUtils.isEmpty(args) || args.length==0) { if(ObjectUtils.isEmpty(args) || args.length==0) {
return point.proceed(); return point.proceed();
} }
Object arg = args[0];
Object arg=args[0]; if(arg instanceof EntityBase) {
if(arg instanceof EntityBase){ EntityBase entity = (EntityBase) arg;
EntityBase entity= (EntityBase) arg; Map<String, Audit> auditFields = DEFieldCacheMap.getAuditFields(entity.getClass());
Map<String, Audit> auditFields= DEFieldCacheMap.getAuditFields(entity.getClass());
//是否有审计属性 //是否有审计属性
if(auditFields.size()==0) { if(auditFields.size()==0) {
return point.proceed(); return point.proceed();
} }
String idField=DEFieldCacheMap.getDEKeyField(entity.getClass()); String idField = DEFieldCacheMap.getDEKeyField(entity.getClass());
Object idValue=""; Object idValue = "";
if(!StringUtils.isEmpty(idField)){ if(!StringUtils.isEmpty(idField)){
idValue=entity.get(idField); idValue = entity.get(idField);
} }
if(ObjectUtils.isEmpty(idValue)) { if(ObjectUtils.isEmpty(idValue)) {
return point.proceed(); return point.proceed();
} }
//获取更新前实体 //获取更新前实体
EntityBase beforeEntity=getEntity(serviceObj,idValue); EntityBase beforeEntity = getEntity(serviceObj, idValue);
//执行更新操作 //执行更新操作
point.proceed(); point.proceed();
//记录审计日志 //记录审计日志
dataAuditService.updateAudit(request,beforeEntity,serviceObj,idValue,auditFields); dataAuditService.updateAudit(request, beforeEntity, serviceObj, idValue, auditFields);
return true; return true;
} }
return point.proceed(); return point.proceed();
...@@ -139,29 +134,27 @@ public class AuditAspect ...@@ -139,29 +134,27 @@ public class AuditAspect
*/ */
@Around("execution(* ${pub.getPKGCodeName()}.core.*.service.*.remove(..))<#if hasESEntity>&& !execution(* ${pub.getPKGCodeName()}.core.es.service.*.remove*(..))</#if>") @Around("execution(* ${pub.getPKGCodeName()}.core.*.service.*.remove(..))<#if hasESEntity>&& !execution(* ${pub.getPKGCodeName()}.core.es.service.*.remove*(..))</#if>")
public Object remove(ProceedingJoinPoint point) throws Throwable { public Object remove(ProceedingJoinPoint point) throws Throwable {
HttpServletRequest request=null; HttpServletRequest request = null;
RequestAttributes requestAttributes= RequestContextHolder.getRequestAttributes(); RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
if(requestAttributes!=null){ if(requestAttributes!= null) {
request=((ServletRequestAttributes)requestAttributes).getRequest(); request = ((ServletRequestAttributes)requestAttributes).getRequest();
} }
Object serviceObj=point.getTarget(); Object serviceObj = point.getTarget();
Object args[]=point.getArgs(); Object args[] = point.getArgs();
if(ObjectUtils.isEmpty(args) || args.length==0) { if(ObjectUtils.isEmpty(args) || args.length==0) {
return point.proceed(); return point.proceed();
} }
Object idValue = args[0];
Object idValue=args[0]; EntityBase entity = getEntity(serviceObj, idValue);
EntityBase entity=getEntity(serviceObj,idValue); Map<String, Audit> auditFields = DEFieldCacheMap.getAuditFields(entity.getClass());
Map<String, Audit> auditFields= DEFieldCacheMap.getAuditFields(entity.getClass()); if(auditFields.size()==0) {
if(auditFields.size()==0){
return point.proceed(); return point.proceed();
} }
else{ else{
//执行删除操作 //执行删除操作
point.proceed(); point.proceed();
//记录审计日志 //记录审计日志
dataAuditService.removeAudit(request,entity,idValue,auditFields); dataAuditService.removeAudit(request, entity, idValue, auditFields);
return true; return true;
} }
} }
...@@ -173,12 +166,12 @@ public class AuditAspect ...@@ -173,12 +166,12 @@ public class AuditAspect
* @return * @return
*/ */
@SneakyThrows @SneakyThrows
private EntityBase getEntity(Object service, Object id){ private EntityBase getEntity(Object service, Object id) {
EntityBase entity=null; EntityBase entity = null;
if(!ObjectUtils.isEmpty(service)){ if(!ObjectUtils.isEmpty(service)) {
EvaluationContext oldContext = new StandardEvaluationContext(); EvaluationContext oldContext = new StandardEvaluationContext();
oldContext.setVariable("service",service); oldContext.setVariable("service", service);
oldContext.setVariable("id",id); oldContext.setVariable("id", id);
Expression oldExp = parser.parseExpression("#service.get(#id)"); Expression oldExp = parser.parseExpression("#service.get(#id)");
return oldExp.getValue(oldContext, EntityBase.class); return oldExp.getValue(oldContext, EntityBase.class);
} }
......
...@@ -85,19 +85,19 @@ public class DupCheckAspect { ...@@ -85,19 +85,19 @@ public class DupCheckAspect {
//设置检查属性值 //设置检查属性值
QueryFilter filter = new QueryFilter(); QueryFilter filter = new QueryFilter();
setValue(entity,filter,fieldName,newValue); setValue(entity, filter, fieldName, newValue);
//设定重复值检查范围 //设定重复值检查范围
if(!StringUtils.isEmpty(dupCheckField)){ if(!StringUtils.isEmpty(dupCheckField)) {
Object dupFieldValue=getDEFieldValue(entity,dupCheckField); Object dupFieldValue=getDEFieldValue(entity,dupCheckField);
setValue(entity,filter,dupCheckField,dupFieldValue); setValue(entity, filter, dupCheckField, dupFieldValue);
} }
searchContext.setFilter(filter); searchContext.setFilter(filter);
//使用当前值到数据库中进行查询,判断是否重复 //使用当前值到数据库中进行查询,判断是否重复
EvaluationContext oldValueMappingCtx = new StandardEvaluationContext(); EvaluationContext oldValueMappingCtx = new StandardEvaluationContext();
oldValueMappingCtx.setVariable("service", service); oldValueMappingCtx.setVariable("service", service);
oldValueMappingCtx.setVariable("searchContext", searchContext); oldValueMappingCtx.setVariable("searchContext", searchContext);
Expression oldValueMappingExp = parser.parseExpression(String.format("#service.%s(#searchContext)",defaultDS)); Expression oldValueMappingExp = parser.parseExpression(String.format("#service.%s(#searchContext)", defaultDS));
Page oldData = oldValueMappingExp.getValue(oldValueMappingCtx, Page.class); Page oldData = oldValueMappingExp.getValue(oldValueMappingCtx, Page.class);
if (!ObjectUtils.isEmpty(oldData) && !ObjectUtils.isEmpty(oldData.getContent()) && oldData.getContent().size() > 1) { if (!ObjectUtils.isEmpty(oldData) && !ObjectUtils.isEmpty(oldData.getContent()) && oldData.getContent().size() > 1) {
throw new BadRequestAlertException(String.format("数据保存失败,属性[%s]:值[%s]已存在!", fieldName, newValue), "DupCheckAspect", "DupCheck"); throw new BadRequestAlertException(String.format("数据保存失败,属性[%s]:值[%s]已存在!", fieldName, newValue), "DupCheckAspect", "DupCheck");
...@@ -113,7 +113,7 @@ public class DupCheckAspect { ...@@ -113,7 +113,7 @@ public class DupCheckAspect {
* @param fieldName * @param fieldName
* @return * @return
*/ */
private Object getDEFieldValue(Object entity, String fieldName){ private Object getDEFieldValue(Object entity, String fieldName) {
EvaluationContext exMappingCtx = new StandardEvaluationContext(); EvaluationContext exMappingCtx = new StandardEvaluationContext();
exMappingCtx.setVariable("entity", entity); exMappingCtx.setVariable("entity", entity);
Expression esMappingExp = parser.parseExpression(String.format("#entity.get(\"%s\")", fieldName)); Expression esMappingExp = parser.parseExpression(String.format("#entity.get(\"%s\")", fieldName));
...@@ -131,7 +131,7 @@ public class DupCheckAspect { ...@@ -131,7 +131,7 @@ public class DupCheckAspect {
filter.isnull(DEFieldCacheMap.getFieldColumnName(entity.getClass(), fieldName)); filter.isnull(DEFieldCacheMap.getFieldColumnName(entity.getClass(), fieldName));
} }
else { else {
filter.eq(DEFieldCacheMap.getFieldColumnName(entity.getClass(), fieldName),value); filter.eq(DEFieldCacheMap.getFieldColumnName(entity.getClass(), fieldName), value);
} }
} }
} }
......
...@@ -46,7 +46,7 @@ public class ESAspect ...@@ -46,7 +46,7 @@ public class ESAspect
*/ */
@AfterReturning(value = "(execution(* ${pub.getPKGCodeName()}.core.*.service.*${dataEntity.codeName}*.create*(..))||execution(* ${pub.getPKGCodeName()}.core.*.service.*${dataEntity.codeName}*.update*(..))||execution(* ${pub.getPKGCodeName()}.core.*.service.*${dataEntity.codeName}*.save*(..)) ||execution(* ${pub.getPKGCodeName()}.core.*.service.*${dataEntity.codeName}*.remove*(..))) && !execution(* ${pub.getPKGCodeName()}.core.es.service.*.create*(..)) && !execution(* ${pub.getPKGCodeName()}.core.es.service.*.update*(..)) && !execution(* ${pub.getPKGCodeName()}.core.es.service.*.save*(..)) && !execution(* ${pub.getPKGCodeName()}.core.es.service.*.remove*(..))") @AfterReturning(value = "(execution(* ${pub.getPKGCodeName()}.core.*.service.*${dataEntity.codeName}*.create*(..))||execution(* ${pub.getPKGCodeName()}.core.*.service.*${dataEntity.codeName}*.update*(..))||execution(* ${pub.getPKGCodeName()}.core.*.service.*${dataEntity.codeName}*.save*(..)) ||execution(* ${pub.getPKGCodeName()}.core.*.service.*${dataEntity.codeName}*.remove*(..))) && !execution(* ${pub.getPKGCodeName()}.core.es.service.*.create*(..)) && !execution(* ${pub.getPKGCodeName()}.core.es.service.*.update*(..)) && !execution(* ${pub.getPKGCodeName()}.core.es.service.*.save*(..)) && !execution(* ${pub.getPKGCodeName()}.core.es.service.*.remove*(..))")
@Async @Async
public void Sync${dataEntity.codeName?lower_case?cap_first}(JoinPoint point){ public void Sync${dataEntity.codeName?lower_case?cap_first}(JoinPoint point) {
syncSaveESData(point,"${dataEntity.codeName}"); syncSaveESData(point,"${dataEntity.codeName}");
} }
</#if> </#if>
...@@ -56,7 +56,7 @@ public class ESAspect ...@@ -56,7 +56,7 @@ public class ESAspect
* 异步往es中保存数据 * 异步往es中保存数据
* @param point * @param point
*/ */
public void syncSaveESData(JoinPoint point,String deName){ public void syncSaveESData(JoinPoint point, String deName) {
try { try {
Object service=point.getTarget(); Object service=point.getTarget();
String action=point.getSignature().getName(); String action=point.getSignature().getName();
...@@ -66,35 +66,35 @@ public class ESAspect ...@@ -66,35 +66,35 @@ public class ESAspect
} }
EvaluationContext exServiceCtx = new StandardEvaluationContext(); EvaluationContext exServiceCtx = new StandardEvaluationContext();
exServiceCtx.setVariable("service",service); exServiceCtx.setVariable("service", service);
Expression esServiceExp = parser.parseExpression("#service.getESService()"); Expression esServiceExp = parser.parseExpression("#service.getESService()");
Object exService=esServiceExp.getValue(exServiceCtx); Object exService=esServiceExp.getValue(exServiceCtx);
if(ObjectUtils.isEmpty(exService)){ if(ObjectUtils.isEmpty(exService)) {
log.error("获取[{}]实体全文检索服务对象失败",deName); log.error("获取[{}]实体全文检索服务对象失败",deName);
return; return;
} }
Object arg=args[0]; Object arg=args[0];
if ("remove".equals(action) || "removeBatch".equals(action)){ if ("remove".equals(action) || "removeBatch".equals(action)) {
executeESMethod(exService,action,arg); executeESMethod(exService, action, arg);
} }
else if(arg instanceof EntityBase || arg instanceof List){ else if(arg instanceof EntityBase || arg instanceof List) {
EvaluationContext exMappingCtx = new StandardEvaluationContext(); EvaluationContext exMappingCtx = new StandardEvaluationContext();
exMappingCtx.setVariable("service",service); exMappingCtx.setVariable("service", service);
Expression esMappingExp = parser.parseExpression("#service.getESMapping()"); Expression esMappingExp = parser.parseExpression("#service.getESMapping()");
Object exMapping=esMappingExp.getValue(exMappingCtx); Object exMapping=esMappingExp.getValue(exMappingCtx);
if(ObjectUtils.isEmpty(exMapping)){ if(ObjectUtils.isEmpty(exMapping)) {
log.error("获取[{}]实体全文检索映射对象失败",deName); log.error("获取[{}]实体全文检索映射对象失败", deName);
return; return;
} }
EvaluationContext exDomainCtx = new StandardEvaluationContext(); EvaluationContext exDomainCtx = new StandardEvaluationContext();
exDomainCtx.setVariable("mapping",exMapping); exDomainCtx.setVariable("mapping", exMapping);
exDomainCtx.setVariable("arg",arg); exDomainCtx.setVariable("arg", arg);
Expression esDomainExp = parser.parseExpression("#mapping.toESDomain(#arg)"); Expression esDomainExp = parser.parseExpression("#mapping.toESDomain(#arg)");
arg=esDomainExp.getValue(exDomainCtx); arg=esDomainExp.getValue(exDomainCtx);
executeESMethod(exService,action,arg); executeESMethod(exService, action, arg);
} }
} catch (Exception e) { } catch (Exception e) {
log.error("同步[{}]实体全文检索数据失败,{}",deName,e); log.error("同步[{}]实体全文检索数据失败,{}", deName, e);
} }
} }
...@@ -104,11 +104,11 @@ public class ESAspect ...@@ -104,11 +104,11 @@ public class ESAspect
* @param action * @param action
* @param arg * @param arg
*/ */
private void executeESMethod(Object exService,Object action,Object arg){ private void executeESMethod(Object exService, Object action, Object arg) {
EvaluationContext esContext = new StandardEvaluationContext(); EvaluationContext esContext = new StandardEvaluationContext();
esContext.setVariable("exService",exService); esContext.setVariable("exService", exService);
esContext.setVariable("arg",arg); esContext.setVariable("arg", arg);
Expression exExp = parser.parseExpression(String.format("#exService.%s(#arg)",action)); Expression exExp = parser.parseExpression(String.format("#exService.%s(#arg)", action));
exExp.getValue(esContext); exExp.getValue(esContext);
} }
} }
......
...@@ -59,12 +59,12 @@ public class RocketMQAspect ...@@ -59,12 +59,12 @@ public class RocketMQAspect
@AfterReturning(value = "(execution(* ${pub.getPKGCodeName()}.core.*.service.*${dataEntity.codeName}*.create*(..))||execution(* ${pub.getPKGCodeName()}.core.*.service.*${dataEntity.codeName}*.update*(..))||execution(* ${pub.getPKGCodeName()}.core.*.service.*${dataEntity.codeName}*.save*(..)) ||execution(* ${pub.getPKGCodeName()}.core.*.service.*${dataEntity.codeName}*.remove*(..))) && !execution(* ${pub.getPKGCodeName()}.core.es.service.*.create*(..)) && !execution(* ${pub.getPKGCodeName()}.core.es.service.*.update*(..)) && !execution(* ${pub.getPKGCodeName()}.core.es.service.*.save*(..)) && !execution(* ${pub.getPKGCodeName()}.core.es.service.*.remove*(..))") @AfterReturning(value = "(execution(* ${pub.getPKGCodeName()}.core.*.service.*${dataEntity.codeName}*.create*(..))||execution(* ${pub.getPKGCodeName()}.core.*.service.*${dataEntity.codeName}*.update*(..))||execution(* ${pub.getPKGCodeName()}.core.*.service.*${dataEntity.codeName}*.save*(..)) ||execution(* ${pub.getPKGCodeName()}.core.*.service.*${dataEntity.codeName}*.remove*(..))) && !execution(* ${pub.getPKGCodeName()}.core.es.service.*.create*(..)) && !execution(* ${pub.getPKGCodeName()}.core.es.service.*.update*(..)) && !execution(* ${pub.getPKGCodeName()}.core.es.service.*.save*(..)) && !execution(* ${pub.getPKGCodeName()}.core.es.service.*.remove*(..))")
@Async @Async
public void ${srfmethodname(producer)}(JoinPoint point){ public void ${srfmethodname(producer)}(JoinPoint point) {
<#if dataSync.getOutTestPSDEAction?? && dataSync.getOutTestPSDEAction()??> <#if dataSync.getOutTestPSDEAction?? && dataSync.getOutTestPSDEAction()??>
<#assign actionName=srfmethodname(dataSync.getOutTestPSDEAction().codeName)> <#assign actionName=srfmethodname(dataSync.getOutTestPSDEAction().codeName)>
outputAction(point,"${actionName}"); outputAction(point, "${actionName}");
</#if> </#if>
sendMsg(${producer},"${dataSync.codeName}","${dataSync.codeName}",getEntity(point)); sendMsg(${producer}, "${dataSync.codeName}", "${dataSync.codeName}", getEntity(point));
} }
</#if> </#if>
</#list> </#list>
...@@ -76,16 +76,17 @@ public class RocketMQAspect ...@@ -76,16 +76,17 @@ public class RocketMQAspect
* @param point * @param point
* @param actionName * @param actionName
*/ */
private void outputAction(JoinPoint point,String actionName){ private void outputAction(JoinPoint point,String actionName) {
Object [] args = point.getArgs(); Object [] args = point.getArgs();
if(ObjectUtils.isEmpty(args) || args.length==0) if(ObjectUtils.isEmpty(args) || args.length==0) {
return ; return;
Object arg=args[0]; }
Object service=point.getTarget(); Object arg = args[0];
Object service = point.getTarget();
EvaluationContext serviceCtx = new StandardEvaluationContext(); EvaluationContext serviceCtx = new StandardEvaluationContext();
serviceCtx.setVariable("service",service); serviceCtx.setVariable("service", service);
serviceCtx.setVariable("arg",arg); serviceCtx.setVariable("arg", arg);
Expression serviceExp = parser.parseExpression(String.format("#service.%s(#arg)",actionName)); Expression serviceExp = parser.parseExpression(String.format("#service.%s(#arg)", actionName));
serviceExp.getValue(serviceCtx); serviceExp.getValue(serviceCtx);
} }
...@@ -94,7 +95,7 @@ public class RocketMQAspect ...@@ -94,7 +95,7 @@ public class RocketMQAspect
* @param point * @param point
* @return * @return
*/ */
private Object getEntity(JoinPoint point){ private Object getEntity(JoinPoint point) {
Object entity=null; Object entity=null;
String action=point.getSignature().getName(); String action=point.getSignature().getName();
Object [] args = point.getArgs(); Object [] args = point.getArgs();
...@@ -117,10 +118,10 @@ public class RocketMQAspect ...@@ -117,10 +118,10 @@ public class RocketMQAspect
* @param tag * @param tag
* @param body * @param body
*/ */
private void sendMsg(DefaultMQProducer producer ,String topic ,String tag ,Object body){ private void sendMsg(DefaultMQProducer producer, String topic, String tag, Object body) {
if(ObjectUtils.isEmpty(body)){ if(ObjectUtils.isEmpty(body)) {
log.error("发送消息失败,无法获取到要发送的消息内容!"); log.error("发送消息失败,无法获取到要发送的消息内容!");
return ; return;
} }
try { try {
producer.start(); producer.start();
......
...@@ -35,61 +35,61 @@ import java.util.Map; ...@@ -35,61 +35,61 @@ import java.util.Map;
public class VersionCheckAspect public class VersionCheckAspect
{ {
private final ExpressionParser parser = new SpelExpressionParser(); private final ExpressionParser parser = new SpelExpressionParser();
private final String IgnoreField="ignoreversioncheck"; private final String IgnoreField = "ignoreversioncheck";
@SneakyThrows @SneakyThrows
@Before("execution(* ${pub.getPKGCodeName()}.*.rest.*.update(..)) && @annotation(versionCheck)") @Before("execution(* ${pub.getPKGCodeName()}.*.rest.*.update(..)) && @annotation(versionCheck)")
public void BeforeUpdate(JoinPoint point, VersionCheck versionCheck){ public void BeforeUpdate(JoinPoint point, VersionCheck versionCheck) {
Object[] args = point.getArgs(); Object[] args = point.getArgs();
Object id=args[0]; Object id = args[0];
Object dto=args[1]; Object dto = args[1];
if(ObjectUtils.isEmpty(id) || ObjectUtils.isEmpty(dto)) { if(ObjectUtils.isEmpty(id) || ObjectUtils.isEmpty(dto)) {
return; return;
} }
String versionField=versionCheck.versionfield(); String versionField = versionCheck.versionfield();
if(StringUtils.isEmpty(versionField)) { if(StringUtils.isEmpty(versionField)) {
return; return;
} }
versionCheck(versionCheck,point.getTarget(),dto,id); versionCheck(versionCheck,point.getTarget(), dto, id);
} }
@SneakyThrows @SneakyThrows
@Before("execution(* ${pub.getPKGCodeName()}.*.rest.*.updateBy*(..)) && @annotation(versionCheck)") @Before("execution(* ${pub.getPKGCodeName()}.*.rest.*.updateBy*(..)) && @annotation(versionCheck)")
public void BeforeUpdateBy(JoinPoint point, VersionCheck versionCheck){ public void BeforeUpdateBy(JoinPoint point, VersionCheck versionCheck) {
Object[] args = point.getArgs(); Object[] args = point.getArgs();
if(args.length>=2){ if(args.length>=2) {
Object id=args[args.length-2]; Object id = args[args.length-2];
Object dto=args[args.length-1]; Object dto = args[args.length-1];
if(ObjectUtils.isEmpty(id) || ObjectUtils.isEmpty(dto)) { if(ObjectUtils.isEmpty(id) || ObjectUtils.isEmpty(dto)) {
return; return;
} }
String versionField=versionCheck.versionfield(); String versionField = versionCheck.versionfield();
if(StringUtils.isEmpty(versionField)) { if(StringUtils.isEmpty(versionField)) {
return; return;
} }
versionCheck(versionCheck,point.getTarget(),dto,id); versionCheck(versionCheck, point.getTarget(), dto, id);
} }
} }
private void versionCheck(VersionCheck versionCheck,Object resource,Object dto,Object id ){ private void versionCheck(VersionCheck versionCheck, Object resource, Object dto, Object id) {
EvaluationContext context = new StandardEvaluationContext(); EvaluationContext context = new StandardEvaluationContext();
context.setVariable("dto",dto); context.setVariable("dto", dto);
//忽略版本检查 //忽略版本检查
Expression dtoParamsExp = parser.parseExpression("#dto.extensionparams"); Expression dtoParamsExp = parser.parseExpression("#dto.extensionparams");
Map dtoParam=dtoParamsExp.getValue(context, Map.class); Map dtoParam = dtoParamsExp.getValue(context, Map.class);
if(!ObjectUtils.isEmpty(dtoParam) && !ObjectUtils.isEmpty(dtoParam.get(IgnoreField)) && dtoParam.get(IgnoreField).equals(1)) { if(!ObjectUtils.isEmpty(dtoParam) && !ObjectUtils.isEmpty(dtoParam.get(IgnoreField)) && dtoParam.get(IgnoreField).equals(1)) {
return; return;
} }
Expression newExp = parser.parseExpression(String.format("#dto.%s",versionCheck.versionfield())); Expression newExp = parser.parseExpression(String.format("#dto.%s", versionCheck.versionfield()));
Object newVersion=newExp.getValue(context); Object newVersion = newExp.getValue(context);
if(ObjectUtils.isEmpty(newVersion)) { if(ObjectUtils.isEmpty(newVersion)) {
return; return;
} }
//进行版本检查 //进行版本检查
Object oldVersion =getDBVersion(versionCheck,getService(resource,versionCheck.entity()),id); Object oldVersion = getDBVersion(versionCheck,getService(resource, versionCheck.entity()), id);
if(!ObjectUtils.isEmpty(oldVersion)){ if(!ObjectUtils.isEmpty(oldVersion)) {
if(RuleUtils.gt(newVersion,oldVersion)) { if(RuleUtils.gt(newVersion, oldVersion)) {
throw new BadRequestAlertException("数据已变更,可能后台数据已被修改,请重新加载数据","VersionCheckAspect","versionCheck"); throw new BadRequestAlertException("数据已变更,可能后台数据已被修改,请重新加载数据", "VersionCheckAspect", "versionCheck");
} }
} }
} }
...@@ -101,12 +101,12 @@ public class VersionCheckAspect ...@@ -101,12 +101,12 @@ public class VersionCheckAspect
* @return * @return
*/ */
@SneakyThrows @SneakyThrows
private Object getService(Object resource,String entity){ private Object getService(Object resource, String entity) {
Object service = null; Object service = null;
Field[] fields= resource.getClass().getDeclaredFields(); Field[] fields = resource.getClass().getDeclaredFields();
for(Field field : fields){ for(Field field : fields) {
if(field.getModifiers()==1 && field.getName().equalsIgnoreCase(String.format("%sService",entity))){ if(field.getModifiers()==1 && field.getName().equalsIgnoreCase(String.format("%sService",entity))) {
service=field.get(resource); service = field.get(resource);
break; break;
} }
} }
...@@ -121,21 +121,21 @@ public class VersionCheckAspect ...@@ -121,21 +121,21 @@ public class VersionCheckAspect
* @return * @return
*/ */
@SneakyThrows @SneakyThrows
private Object getDBVersion(VersionCheck versionCheck,Object service,Object id){ private Object getDBVersion(VersionCheck versionCheck, Object service, Object id) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Timestamp dbVersion=null; 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();
oldContext.setVariable("service",service); oldContext.setVariable("service", service);
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);
Object oldDate=oldEntity.get(versionField); Object oldDate = oldEntity.get(versionField);
if(oldDate!=null && oldDate instanceof Timestamp){ if(oldDate!=null && oldDate instanceof Timestamp) {
Timestamp db_time= (Timestamp) oldDate; Timestamp db_time = (Timestamp) oldDate;
Date db_date = sdf.parse(sdf.format(db_time)); Date db_date = sdf.parse(sdf.format(db_time));
dbVersion=new Timestamp(db_date.getTime()); dbVersion = new Timestamp(db_date.getTime());
} }
} }
return dbVersion; return dbVersion;
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册