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

支持es,修复相关bug

上级 9fcd6ac8
......@@ -14,7 +14,7 @@ import java.sql.Timestamp;
import lombok.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 {
private static final long serialVersionUID = 1L;
......
......@@ -16,13 +16,13 @@ import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import java.util.List;
import java.util.Optional;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import java.util.Collection;
/**
* 实体[${item.getLogicName()}] 服务对象接口实现
*/
@Slf4j
@Service
public class ${item.getCodeName()}ESServiceImpl implements I${de.getCodeName()}ESService {
@Autowired
......
......@@ -317,7 +317,7 @@ public class ${itemCodeName}Resource {
<@DataQuerySecurityAnnotation deds/>
@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")
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) ;
List<${itemCodeName}DTO> list = ${itemCodeNameLC}Mapping.toDto(esMapping.toDomain(domains.getContent()));
return ResponseEntity.status(${statusCode})
......@@ -345,7 +345,7 @@ public class ${itemCodeName}Resource {
<@SecurityAnnotation deaction/>
@ApiOperation(value = "获取${deLogicName}", tags = {"${deLogicName}" }, notes = "获取${deLogicName}")
@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});
${itemCodeName}DTO dto = ${itemCodeNameLC}Mapping.toDto(esMapping.toDomain(domain));
return ResponseEntity.status(HttpStatus.OK).body(dto);
......
<#ibiztemplate>
TARGET=PSSYSTEM
</#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;
import lombok.SneakyThrows;
......@@ -44,7 +51,7 @@ public class AuditAspect
* 实体数据建立切面,在成功创建数据后将新增数据内容记录审计日志内(审计明细【AuditInfo】中只记录审计属性变化情况,审计属性在平台属性中配置)
* @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
public void create(JoinPoint point){
HttpServletRequest request=null;
......@@ -57,6 +64,7 @@ public class AuditAspect
return;
Object serviceParam =args[0];
if(serviceParam instanceof EntityBase){
EntityBase entity=(EntityBase)serviceParam;//创建数据
Map<String, Audit> auditFields= DEFieldCacheMap.getAuditFields(entity.getClass());
if(auditFields.size()==0)//是否有审计属性
......@@ -69,7 +77,7 @@ public class AuditAspect
}
//记录审计日志
dataAuditService.createAudit(request,entity,idValue,auditFields);
return;
}
}
/**
......@@ -77,7 +85,7 @@ public class AuditAspect
* 使用环切【@Around】获取到更新前后的实体数据并进行差异比较,并将差异内容记入审计日志内
* @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 {
HttpServletRequest request=null;
RequestAttributes requestAttributes= RequestContextHolder.getRequestAttributes();
......@@ -91,6 +99,7 @@ public class AuditAspect
return point.proceed();
Object arg=args[0];
if(arg instanceof EntityBase){
EntityBase entity= (EntityBase) arg;
Map<String, Audit> auditFields= DEFieldCacheMap.getAuditFields(entity.getClass());
......@@ -113,6 +122,8 @@ public class AuditAspect
dataAuditService.updateAudit(request,beforeEntity,serviceObj,idValue,auditFields);
return true;
}
return point.proceed();
}
/**
* 实体数据更新切面,在成功更新数据后将新增数据内容记录审计日志内(审计明细【AuditInfo】中只记录审计属性变化情况,审计属性在平台属性中配置)
......@@ -121,7 +132,7 @@ public class AuditAspect
* @return
* @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 {
HttpServletRequest request=null;
RequestAttributes requestAttributes= RequestContextHolder.getRequestAttributes();
......
......@@ -44,7 +44,7 @@ public class ESAspect
* 实体[${dataEntity.codeName}]es切面
* @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
public void Sync${dataEntity.codeName?lower_case?cap_first}(JoinPoint point){
syncSaveESData(point,"${dataEntity.codeName}");
......@@ -87,16 +87,28 @@ public class ESAspect
exDomainCtx.setVariable("arg",arg);
Expression esDomainExp = parser.parseExpression("#mapping.toESDomain(#arg)");
arg=esDomainExp.getValue(exDomainCtx);
executeESMethod(exService,action,arg);
}
else if ("remove".equals(action) || "removeBatch".equals(action)){
executeESMethod(exService,action,arg);
}
} catch (Exception 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);
}
} catch (Exception e) {
log.error("保存[{}]实体全文检索数据失败,{}",deName,e);
}
}
}
</#if>
\ No newline at end of file
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册