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

支持es,修复相关bug

上级 9fcd6ac8
...@@ -14,7 +14,7 @@ import java.sql.Timestamp; ...@@ -14,7 +14,7 @@ import java.sql.Timestamp;
import lombok.Data; import lombok.Data;
@Data @Data
@Document(indexName = "${sys.codeName}", type = "${item.codeName}", shards = 5, replicas = 1) @Document(indexName = "${sys.codeName?lower_case}", type = "${item.codeName?lower_case}", shards = 5, replicas = 1)
public class ${item.codeName} implements Serializable { public class ${item.codeName} implements Serializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
......
...@@ -16,13 +16,13 @@ import org.springframework.data.domain.Page; ...@@ -16,13 +16,13 @@ import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.PageImpl;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service;
import java.util.Collection; import java.util.Collection;
/** /**
* 实体[${item.getLogicName()}] 服务对象接口实现 * 实体[${item.getLogicName()}] 服务对象接口实现
*/ */
@Slf4j @Service
public class ${item.getCodeName()}ESServiceImpl implements I${de.getCodeName()}ESService { public class ${item.getCodeName()}ESServiceImpl implements I${de.getCodeName()}ESService {
@Autowired @Autowired
......
...@@ -317,7 +317,7 @@ public class ${itemCodeName}Resource { ...@@ -317,7 +317,7 @@ public class ${itemCodeName}Resource {
<@DataQuerySecurityAnnotation deds/> <@DataQuerySecurityAnnotation deds/>
@ApiOperation(value = "获取${deds.getLogicName()}", tags = {"${deLogicName}" } ,notes = "获取${deds.getLogicName()}") @ApiOperation(value = "获取${deds.getLogicName()}", tags = {"${deLogicName}" } ,notes = "获取${deds.getLogicName()}")
@RequestMapping(method= RequestMethod.${reqMtd} , value="${fullPath}/fetch<#if (deds.getName()=='DEFAULT')>${deds.getCodeName()?lower_case}<#else>${deds.getCodeName()?lower_case}</#if>/es") @RequestMapping(method= RequestMethod.${reqMtd} , value="${fullPath}/fetch<#if (deds.getName()=='DEFAULT')>${deds.getCodeName()?lower_case}<#else>${deds.getCodeName()?lower_case}</#if>/es")
public ResponseEntity<List<${itemCodeName}DTO>> ESFetch<#if (deds.getName()=='DEFAULT')>${deds.getCodeName()}<#else>${deds.getCodeName()}</#if>(${deCodeName}SearchContext context) { public ResponseEntity<List<${itemCodeName}DTO>> esFetch<#if (deds.getName()=='DEFAULT')>${deds.getCodeName()}<#else>${deds.getCodeName()}</#if>(${deCodeName}SearchContext context) {
Page<${pub.getPKGCodeName()}.core.es.domain.${item.codeName}> domains = esService.search${deds.getCodeName()}(context) ; Page<${pub.getPKGCodeName()}.core.es.domain.${item.codeName}> domains = esService.search${deds.getCodeName()}(context) ;
List<${itemCodeName}DTO> list = ${itemCodeNameLC}Mapping.toDto(esMapping.toDomain(domains.getContent())); List<${itemCodeName}DTO> list = ${itemCodeNameLC}Mapping.toDto(esMapping.toDomain(domains.getContent()));
return ResponseEntity.status(${statusCode}) return ResponseEntity.status(${statusCode})
...@@ -345,7 +345,7 @@ public class ${itemCodeName}Resource { ...@@ -345,7 +345,7 @@ public class ${itemCodeName}Resource {
<@SecurityAnnotation deaction/> <@SecurityAnnotation deaction/>
@ApiOperation(value = "获取${deLogicName}", tags = {"${deLogicName}" }, notes = "获取${deLogicName}") @ApiOperation(value = "获取${deLogicName}", tags = {"${deLogicName}" }, notes = "获取${deLogicName}")
@RequestMapping(method = RequestMethod.GET, value = "${fullPath}/{${itemCodeNameLC + keyCNLC}}/es") @RequestMapping(method = RequestMethod.GET, value = "${fullPath}/{${itemCodeNameLC + keyCNLC}}/es")
public ResponseEntity<${itemCodeName}DTO> ESGet(${idParams}) { public ResponseEntity<${itemCodeName}DTO> esGet(${idParams}) {
${pub.getPKGCodeName()}.core.es.domain.${item.codeName} domain = esService.get(${itemCodeNameLC + keyCNLC}); ${pub.getPKGCodeName()}.core.es.domain.${item.codeName} domain = esService.get(${itemCodeNameLC + keyCNLC});
${itemCodeName}DTO dto = ${itemCodeNameLC}Mapping.toDto(esMapping.toDomain(domain)); ${itemCodeName}DTO dto = ${itemCodeNameLC}Mapping.toDto(esMapping.toDomain(domain));
return ResponseEntity.status(HttpStatus.OK).body(dto); return ResponseEntity.status(HttpStatus.OK).body(dto);
......
<#ibiztemplate> <#ibiztemplate>
TARGET=PSSYSTEM TARGET=PSSYSTEM
</#ibiztemplate> </#ibiztemplate>
<#assign hasESEntity=false>
<#list sys.getAllPSDataEntities() as dataEntity>
<#if dataEntity.getUserTag()?? && dataEntity.getUserTag()=='elasticsearch'>
<#assign hasESEntity=true>
<#break>
</#if>
</#list>
package ${pub.getPKGCodeName()}.util.aspect; package ${pub.getPKGCodeName()}.util.aspect;
import lombok.SneakyThrows; import lombok.SneakyThrows;
...@@ -44,7 +51,7 @@ public class AuditAspect ...@@ -44,7 +51,7 @@ public class AuditAspect
* 实体数据建立切面,在成功创建数据后将新增数据内容记录审计日志内(审计明细【AuditInfo】中只记录审计属性变化情况,审计属性在平台属性中配置) * 实体数据建立切面,在成功创建数据后将新增数据内容记录审计日志内(审计明细【AuditInfo】中只记录审计属性变化情况,审计属性在平台属性中配置)
* @param point * @param point
*/ */
@AfterReturning(value = "execution(* ${pub.getPKGCodeName()}.core.*.service.*.create(..))") @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;
...@@ -57,19 +64,20 @@ public class AuditAspect ...@@ -57,19 +64,20 @@ public class AuditAspect
return; return;
Object serviceParam =args[0]; Object serviceParam =args[0];
EntityBase entity=(EntityBase)serviceParam;//创建数据 if(serviceParam instanceof EntityBase){
Map<String, Audit> auditFields= DEFieldCacheMap.getAuditFields(entity.getClass()); EntityBase entity=(EntityBase)serviceParam;//创建数据
if(auditFields.size()==0)//是否有审计属性 Map<String, Audit> auditFields= DEFieldCacheMap.getAuditFields(entity.getClass());
return; if(auditFields.size()==0)//是否有审计属性
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);
return;
} }
/** /**
...@@ -77,7 +85,7 @@ public class AuditAspect ...@@ -77,7 +85,7 @@ public class AuditAspect
* 使用环切【@Around】获取到更新前后的实体数据并进行差异比较,并将差异内容记入审计日志内 * 使用环切【@Around】获取到更新前后的实体数据并进行差异比较,并将差异内容记入审计日志内
* @param point * @param point
*/ */
@Around("execution(* ${pub.getPKGCodeName()}.core.*.service.*.update(..))") @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();
...@@ -91,27 +99,30 @@ public class AuditAspect ...@@ -91,27 +99,30 @@ public class AuditAspect
return point.proceed(); return point.proceed();
Object arg=args[0]; Object arg=args[0];
EntityBase entity= (EntityBase) arg; if(arg instanceof EntityBase){
Map<String, Audit> auditFields= DEFieldCacheMap.getAuditFields(entity.getClass()); EntityBase entity= (EntityBase) arg;
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();
} }
/** /**
...@@ -121,7 +132,7 @@ public class AuditAspect ...@@ -121,7 +132,7 @@ public class AuditAspect
* @return * @return
* @throws Throwable * @throws Throwable
*/ */
@Around("execution(* ${pub.getPKGCodeName()}.core.*.service.*.remove(..))") @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();
......
...@@ -44,7 +44,7 @@ public class ESAspect ...@@ -44,7 +44,7 @@ public class ESAspect
* 实体[${dataEntity.codeName}]es切面 * 实体[${dataEntity.codeName}]es切面
* @param point * @param point
*/ */
@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.es.service.*.create*(..)) && !execution(* ${pub.getPKGCodeName()}.core.es.service.*.update*(..)) && !execution(* ${pub.getPKGCodeName()}.core.es.service.*.save*(..))") @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}");
...@@ -87,16 +87,28 @@ public class ESAspect ...@@ -87,16 +87,28 @@ public class ESAspect
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);
EvaluationContext esContext = new StandardEvaluationContext(); }
esContext.setVariable("exService",exService); else if ("remove".equals(action) || "removeBatch".equals(action)){
esContext.setVariable("arg",arg); executeESMethod(exService,action,arg);
Expression exExp = parser.parseExpression(String.format("#exService.%s(#arg)",action));
exExp.getValue(esContext);
} }
} catch (Exception e) { } catch (Exception e) {
log.error("保存[{}]实体全文检索数据失败,{}",deName,e); log.error("同步[{}]实体全文检索数据失败,{}",deName,e);
} }
} }
/**
* 执行es方法
* @param exService
* @param action
* @param arg
*/
private void executeESMethod(Object exService,Object action,Object arg){
EvaluationContext esContext = new StandardEvaluationContext();
esContext.setVariable("exService",exService);
esContext.setVariable("arg",arg);
Expression exExp = parser.parseExpression(String.format("#exService.%s(#arg)",action));
exExp.getValue(esContext);
}
} }
</#if> </#if>
\ No newline at end of file
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册