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

合并分支 'dev' 到 '2020.08.10【669】'

Dev

查看合并请求 !32
# **iBiz4j Spring R7 Template ChangeLog**
## [v2020.10.17]
- 支持es查询加速:开启查询加速的实体,在完成标准实体存储之外,还会将一份数据存入es中,用于后续在es中进行检索。
- 兼容虚拟主键、多个联合键值属性类型不统一的问题。
- 补充联合主键中出现时间类型属性处理(时间类型属性默认按照yyyyMMddHHmmss格式处理)。
- 修复程序异常时,L1缓存值为空的问题。
## [v2020.09.22]
- 处理逻辑:支持处理逻辑中启动工作流
......
......@@ -22,6 +22,7 @@ import ${pub.getPKGCodeName()}.util.domain.EntityBase;
import ${pub.getPKGCodeName()}.util.annotation.DEField;
import ${pub.getPKGCodeName()}.util.enums.DEPredefinedFieldType;
import ${pub.getPKGCodeName()}.util.enums.DEFieldDefaultValueType;
import ${pub.getPKGCodeName()}.util.helper.DataObject;
import java.io.Serializable;
import lombok.*;
import org.springframework.data.annotation.Transient;
......@@ -313,7 +314,7 @@ public class ${item.getCodeName()} extends EntityMP implements Serializable {
<#list item.getUnionKeyValuePSDEFields() as defield>
<#assign unionKeyPrivateCodeName = srfcaseformat(defield.getCodeName(),'l_u2lC') >
<#assign unionKeyPublicCodeName = unionKeyPrivateCodeName?cap_first >
this.set${unionKeyPublicCodeName}(args[${defield_index}]);
this.set("${unionKeyPrivateCodeName}",args[${defield_index}]);
</#list>
}
}
......@@ -942,13 +943,19 @@ public class ${item.getCodeName()} extends EntityBase implements Serializable {
<#assign formatKey="">
<#assign formatValue="">
<#list item.getUnionKeyValuePSDEFields() as defield>
<#assign dataType = (defield.getDataType())!"">
<#assign unionKeyPrivateCodeName = srfcaseformat(defield.getCodeName(),'l_u2lC') >
<#assign unionKeyPublicCodeName = unionKeyPrivateCodeName?cap_first >
<#assign formatKey=formatKey+"%s">
<#if defield_has_next>
<#assign formatKey=formatKey+"||">
</#if>
<#assign formatValue=formatValue+"this.get"+unionKeyPublicCodeName+"()">
<#comment>补充联合键值中出现时间类型属性的处理</#comment>
<#if dataType=="DATETIME" || dataType=="DATE" || dataType=="TIME">
<#assign formatValue=formatValue+"DataObject.datetimeFormat.format(this.get"+unionKeyPublicCodeName+"())">
<#else>
<#assign formatValue=formatValue+"this.get"+unionKeyPublicCodeName+"()">
</#if>
<#if defield_has_next>
<#assign formatValue=formatValue+",">
</#if>
......
......@@ -18,6 +18,9 @@ import com.alibaba.fastjson.annotation.JSONField;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
<#if de.getUserTag()?? && de.getUserTag()=='elasticsearch'>
import org.elasticsearch.index.query.QueryBuilders;
</#if>
<#comment>SQL存储-Mybatis</#comment>
<#if de.getStorageMode()==1>
......@@ -91,6 +94,8 @@ public class ${item.codeName}SearchContext extends QueryWrapperContext<${item.co
<#assign valueSeparator=getInCondSeparator(formitem)>
this.getSearchCond().notIn("${formitem.getPSDEField().getName()?lower_case}",this.${formitem.getName()?lower_case}.split("${valueSeparator}"));
</#if>
<#comment>构造es查询条件</#comment>
<@esqueryCond formitem/>
}
}
</#if>
......@@ -203,6 +208,8 @@ public class ${item.codeName}SearchContext extends QueryBuildContext {
<#assign valueSeparator=getInCondSeparator(formitem)>
this.getSearchCond().and("${formitem.getPSDEField().getName()?lower_case}").notIn(this.${formitem.getName()?lower_case}.split("${valueSeparator}")));
</#if>
<#comment>构造es查询条件</#comment>
<@esqueryCond formitem/>
}
}
</#if>
......@@ -319,4 +326,34 @@ public class ${item.codeName}SearchContext extends SearchContextBase {
<#return valueSeparator/>
</#function>
<#comment>构造es查询条件</#comment>
<#macro esqueryCond formitem>
<#if de.getUserTag()?? && de.getUserTag()=='elasticsearch'>
<#if formitem.getValueOp() == "LIKE">
this.getEsCond().must(QueryBuilders.wildcardQuery("${formitem.getPSDEField().getName()?lower_case}", String.format("*%s*",${formitem.getName()?lower_case})));
<#elseif formitem.getValueOp() == "LEFTLIKE">
this.getEsCond().must(QueryBuilders.wildcardQuery("${formitem.getPSDEField().getName()?lower_case}", String.format("%s*",${formitem.getName()?lower_case})));
<#elseif formitem.getValueOp() == "RIGHTLIKE">
this.getEsCond().must(QueryBuilders.wildcardQuery("${formitem.getPSDEField().getName()?lower_case}", String.format("*%s",${formitem.getName()?lower_case})));
<#elseif formitem.getValueOp() == "EQ">
this.getEsCond().must(QueryBuilders.termQuery("${formitem.getPSDEField().getName()?lower_case}", ${formitem.getName()?lower_case}));
<#elseif formitem.getValueOp() == "NOTEQ">
this.getEsCond().mustNot(QueryBuilders.termQuery("${formitem.getPSDEField().getName()?lower_case}", ${formitem.getName()?lower_case}));
<#elseif formitem.getValueOp() == "GT">
this.getEsCond().must(QueryBuilders.rangeQuery("${formitem.getPSDEField().getName()?lower_case}").gt(${formitem.getName()?lower_case}));
<#elseif formitem.getValueOp() == "GTANDEQ">
this.getEsCond().must(QueryBuilders.rangeQuery("${formitem.getPSDEField().getName()?lower_case}").gte(${formitem.getName()?lower_case}));
<#elseif formitem.getValueOp() == "LT">
this.getEsCond().must(QueryBuilders.rangeQuery("${formitem.getPSDEField().getName()?lower_case}").lt(${formitem.getName()?lower_case}));
<#elseif formitem.getValueOp() == "LTANDEQ">
this.getEsCond().must(QueryBuilders.rangeQuery("${formitem.getPSDEField().getName()?lower_case}").lte(${formitem.getName()?lower_case}));
<#elseif formitem.getValueOp() == "ISNOTNULL">
this.getEsCond().mustNot(QueryBuilders.existsQuery("${formitem.getPSDEField().getName()?lower_case}"));
<#elseif formitem.getValueOp() == "ISNULL">
this.getEsCond().must(QueryBuilders.existsQuery("${formitem.getPSDEField().getName()?lower_case}"));
<#elseif formitem.getValueOp() == "IN">
<#elseif formitem.getValueOp() == "NOTIN">
</#if>
</#if>
</#macro>
<#ibiztemplate>
TARGET=PSDATAENTITY
</#ibiztemplate>
<#if de.getUserTag()?? && de.getUserTag()=='elasticsearch'>
package ${pub.getPKGCodeName()}.core.${de.getPSSystemModule().codeName?lower_case}.mapping;
import ${pub.getPKGCodeName()}.core.${de.getPSSystemModule().codeName?lower_case}.domain.${item.codeName};
import org.mapstruct.Mapper;
import org.mapstruct.NullValueCheckStrategy;
import org.mapstruct.NullValuePropertyMappingStrategy;
import java.util.List;
@Mapper(componentModel = "spring", uses = {},
nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE,
nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS)
public interface ${item.codeName}ESMapping{
${item.codeName} toDomain(${pub.getPKGCodeName()}.core.es.domain.${item.codeName} esEntity);
${pub.getPKGCodeName()}.core.es.domain.${item.codeName} toESDomain(${item.codeName} entity);
List<${item.codeName}> toDomain(List<${pub.getPKGCodeName()}.core.es.domain.${item.codeName}> esEntityList);
List<${pub.getPKGCodeName()}.core.es.domain.${item.codeName}> toESDomain(List<${item.codeName}> entityList);
}
</#if>
......@@ -954,6 +954,9 @@ public class ${item.getCodeName()}ServiceImpl extends ServiceImpl<${de.getCodeNa
return true;
}
</#if>
<#comment>发布es服务对象</#comment>
<@esAnno/>
}
<#comment>NOSQL存储</#comment>
......@@ -1444,6 +1447,9 @@ public class ${item.getCodeName()}ServiceImpl implements I${de.getCodeName()}Ser
<#comment>实体数据导入</#comment>
<@deImportData/>
<#comment>发布es服务对象</#comment>
<@esAnno/>
}
......@@ -2814,4 +2820,33 @@ public class ${item.getCodeName()}ServiceImpl implements I${de.getCodeName()}Ser
<#return unionKeyResult>
</#function>
<#comment>发布es对象</#comment>
<#macro esAnno>
<#if de.getUserTag()?? && de.getUserTag()=='elasticsearch'>
@Autowired
@Lazy
${pub.getPKGCodeName()}.core.es.service.I${de.codeName}ESService esService;
@Autowired
@Lazy
${pub.getPKGCodeName()}.core.${de.getPSSystemModule().codeName?lower_case}.mapping.${de.codeName}ESMapping esMapping;
/**
* 获取es service
* @return
*/
public ${pub.getPKGCodeName()}.core.es.service.I${de.codeName}ESService getESService(){
return esService;
}
/**
* 获取es mapping
* @return
*/
public ${pub.getPKGCodeName()}.core.${de.getPSSystemModule().codeName?lower_case}.mapping.${de.codeName}ESMapping getESMapping(){
return esMapping;
}
</#if>
</#macro>
</#if>
<#ibiztemplate>
TARGET=PSDATAENTITY
</#ibiztemplate>
<#if de.getUserTag()?? && de.getUserTag()=='elasticsearch'>
package ${pub.getPKGCodeName()}.core.es.dao;
import ${pub.getPKGCodeName()}.core.es.domain.${item.getCodeName()};
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
import org.springframework.stereotype.Repository;
/**
* 实体[${item.getLogicName()}]
*/
@Repository
public interface ${item.getCodeName()}ESRepository extends ElasticsearchRepository<${item.getCodeName()}, String>{
}
</#if>
<#ibiztemplate>
TARGET=PSDATAENTITY
</#ibiztemplate>
<#if de.getUserTag()?? && de.getUserTag()=='elasticsearch'>
package ${pub.getPKGCodeName()}.core.es.domain;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;
import org.springframework.data.annotation.Id;
import java.io.Serializable;
import java.math.BigDecimal;
import java.sql.Timestamp;
import lombok.Data;
@Data
@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;
<#if de.getPSDEFields()??>
<#comment>输出实体属性</#comment>
<#list de.getPSDEFields() as defield>
<#if defield.isPhisicalDEField()==true>
<#assign privateCodeName = srfcaseformat(defield.getCodeName(),'l_u2lC') >
<#assign javaType=srfr7javatype(defield.getStdDataType())>
<#assign esType="FieldType.Text">
<#if javaType=='Long'>
<#assign esType="FieldType.Long">
<#elseif javaType=='Integer'>
<#assign esType="FieldType.Integer">
<#elseif javaType=='Double'|| javaType=='BigDecimal'>
<#assign esType="FieldType.Double">
<#elseif javaType=='Timestamp'>
<#assign esType="FieldType.Date">
</#if>
<#if defield.isKeyDEField()==true>
@Id
<#else>
@Field(type = ${esType})
</#if>
private ${javaType} ${privateCodeName};
</#if>
</#list>
</#if>
}
</#if>
<#ibiztemplate>
TARGET=PSDATAENTITY
</#ibiztemplate>
<#if de.getUserTag()?? && de.getUserTag()=='elasticsearch'>
package ${pub.getPKGCodeName()}.core.es.service;
import ${pub.getPKGCodeName()}.core.es.domain.${item.codeName};
import ${pub.getPKGCodeName()}.core.${de.getPSSystemModule().getCodeName()?lower_case}.filter.${item.codeName}SearchContext;
import org.springframework.data.domain.Page;
import java.util.Collection;
import java.util.List;
/**
* 实体[${item.codeName}] 服务对象接口
*/
public interface I${item.codeName}ESService{
<@addIDESerivceBody />
}
<#macro addIDESerivceBody >
<#comment>实体接口主体内容</#comment>
<#assign keyfield=item.getKeyPSDEField()>
<#if item.getAllPSDEActions()??>
<#list item.getAllPSDEActions() as deaction>
<#if deaction.isEnableBackend()>
<#if deaction.codeName?lower_case == 'get'>
${item.codeName} get(${srfr7javatype(keyfield.stdDataType)} key) ;
<#elseif deaction.codeName?lower_case == "create">
boolean create(${item.codeName} et) ;
void createBatch(List<${item.codeName}> list) ;
<#elseif deaction.codeName?lower_case == "update">
boolean update(${item.codeName} et) ;
void updateBatch(List<${item.codeName}> list) ;
<#elseif deaction.codeName?lower_case == "remove">
boolean remove(${srfr7javatype(keyfield.stdDataType)} key) ;
void removeBatch(Collection<${srfr7javatype(keyfield.stdDataType)}> idList) ;
<#elseif deaction.codeName?lower_case == "save">
boolean save(${item.codeName} et) ;
void saveBatch(List<${item.codeName}> list) ;
</#if>
</#if>
</#list>
</#if>
<#if item.getAllPSDEDataSets()??>
<#list item.getAllPSDEDataSets() as dedataset>
Page<${item.getCodeName()}> search${dedataset.getCodeName()}(${item.codeName}SearchContext context) ;
</#list>
</#if>
</#macro>
</#if>
\ No newline at end of file
<#ibiztemplate>
TARGET=PSDATAENTITY
</#ibiztemplate>
<#if de.getUserTag()?? && de.getUserTag()=='elasticsearch'>
package ${pub.getPKGCodeName()}.core.es.service.impl;
import com.google.common.collect.Lists;
import ${pub.getPKGCodeName()}.core.es.dao.${item.getCodeName()}ESRepository;
import ${pub.getPKGCodeName()}.core.es.domain.${item.getCodeName()};
import ${pub.getPKGCodeName()}.core.es.service.I${item.getCodeName()}ESService;
import ${pub.getPKGCodeName()}.core.valuerule.filter.${item.getCodeName()}SearchContext;
import ${pub.getPKGCodeName()}.util.helper.CachedBeanCopier;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import java.util.List;
import java.util.Optional;
import org.springframework.stereotype.Service;
import java.util.Collection;
/**
* 实体[${item.getLogicName()}] 服务对象接口实现
*/
@Service
public class ${item.getCodeName()}ESServiceImpl implements I${de.getCodeName()}ESService {
@Autowired
@Lazy
${item.getCodeName()}ESRepository repository;
<#assign keyfield=de.getKeyPSDEField()>
<#comment>输出实体行为</#comment>
<#if item.getAllPSDEActions()??>
<#list item.getAllPSDEActions() as deaction>
<#if deaction.getCodeName()?lower_case == 'get'>
@Override
public ${item.getCodeName()} get(${srfr7javatype(keyfield.stdDataType)} key) {
Optional<${item.getCodeName()}> result = repository.findById(key);
if(!result.isPresent()){
${item.getCodeName()} et=new ${item.getCodeName()}();
et.set${srfcaseformat(keyfield.codeName,'l_u2lC')?cap_first}(key);
return et;
}
else{
${item.getCodeName()} et=result.get();
return et;
}
}
<#elseif deaction.getCodeName()?lower_case == "create">
@Override
public boolean create(${item.getCodeName()} et) {
repository.save(et);
CachedBeanCopier.copy(get(et.get${srfcaseformat(keyfield.codeName,'l_u2lC')?cap_first}()),et);
return true;
}
@Override
public void createBatch(List<${item.getCodeName()}> list) {
}
<#elseif deaction.getCodeName()?lower_case == "update">
@Override
public boolean update(${item.getCodeName()} et) {
repository.save(et);
CachedBeanCopier.copy(get(et.get${srfcaseformat(keyfield.codeName,'l_u2lC')?cap_first}()),et);
return true;
}
@Override
public void updateBatch(List<${item.getCodeName()}> list) {
}
<#elseif deaction.getCodeName()?lower_case == "save">
@Override
public boolean save(${item.getCodeName()} et) {
repository.save(et);
CachedBeanCopier.copy(get(et.get${srfcaseformat(keyfield.codeName,'l_u2lC')?cap_first}()),et);
return true;
}
@Override
public void saveBatch(List<${item.getCodeName()}> list) {
}
<#elseif deaction.getCodeName()?lower_case == "remove">
@Override
public boolean remove(${srfr7javatype(keyfield.stdDataType)} key) {
repository.deleteById(key);
return true;
}
@Override
public void removeBatch(Collection<${srfr7javatype(keyfield.stdDataType)}> idList) {
}
</#if>
</#list>
</#if>
<#comment>输出实体数据集</#comment>
<#if item.getAllPSDEDataSets()??>
<#list item.getAllPSDEDataSets() as dedataset>
public Page<${item.getCodeName()}> search${dedataset.getCodeName()}(${item.codeName}SearchContext context){
Iterable<${item.getCodeName()}> list= repository.search(context.getEsCond());
List<${item.getCodeName()}> entities = Lists.newArrayList(list);
return new PageImpl<${item.getCodeName()}>(entities,context.getPageable(),entities.size());
}
</#list>
</#if>
}
</#if>
\ No newline at end of file
......@@ -8,6 +8,13 @@ TARGET=PSSYSTEM
<#break>
</#if>
</#list>
<#assign hasESEntity=false>
<#list sys.getAllPSDataEntities() as dataEntity>
<#if dataEntity.getUserTag()?? && dataEntity.getUserTag()=='elasticsearch'>
<#assign hasESEntity=true>
<#break>
</#if>
</#list>
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
......@@ -422,6 +429,12 @@ TARGET=PSSYSTEM
</dependency>
</#if>
<#if hasESEntity>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-elasticsearch</artifactId>
</dependency>
</#if>
</dependencies>
</project>
......@@ -312,9 +312,46 @@ public class ${itemCodeName}Resource {
.body(new PageImpl(${itemCodeNameLC}Mapping.toDto(domains.getContent()), context.getPageable(), domains.getTotalElements()));
</#if>
}
<#if de.getUserTag()?? && de.getUserTag()=='elasticsearch'>
<@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) {
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})
.header("x-page", String.valueOf(context.getPageable().getPageNumber()))
.header("x-per-page", String.valueOf(context.getPageable().getPageSize()))
.header("x-total", String.valueOf(domains.getTotalElements()))
.body(list);
}
</#if>
</#if>
</#list>
</#if>
<#comment>es get行为</#comment>
<#if de.getUserTag()?? && de.getUserTag()=='elasticsearch'>
@Autowired
@Lazy
${pub.getPKGCodeName()}.core.es.service.I${de.codeName}ESService esService;
@Autowired
@Lazy
${pub.getPKGCodeName()}.core.${de.getPSSystemModule().codeName?lower_case}.mapping.${de.codeName}ESMapping esMapping;
<@SecurityAnnotation deaction/>
@ApiOperation(value = "获取${deLogicName}", tags = {"${deLogicName}" }, notes = "获取${deLogicName}")
@RequestMapping(method = RequestMethod.GET, value = "${fullPath}/{${itemCodeNameLC + keyCNLC}}/es")
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);
}
</#if>
</#if>
<#-- 主接口 end -->
<#-- 关系接口 start -->
......
<#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,19 +64,20 @@ public class AuditAspect
return;
Object serviceParam =args[0];
EntityBase entity=(EntityBase)serviceParam;//创建数据
Map<String, Audit> auditFields= DEFieldCacheMap.getAuditFields(entity.getClass());
if(auditFields.size()==0)//是否有审计属性
return;
if(serviceParam instanceof EntityBase){
EntityBase entity=(EntityBase)serviceParam;//创建数据
Map<String, Audit> auditFields= DEFieldCacheMap.getAuditFields(entity.getClass());
if(auditFields.size()==0)//是否有审计属性
return;
String idField=DEFieldCacheMap.getDEKeyField(entity.getClass());
Object idValue="";
if(!StringUtils.isEmpty(idField)){
idValue=entity.get(idField);
String idField=DEFieldCacheMap.getDEKeyField(entity.getClass());
Object idValue="";
if(!StringUtils.isEmpty(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
* 使用环切【@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,27 +99,30 @@ public class AuditAspect
return point.proceed();
Object arg=args[0];
EntityBase entity= (EntityBase) arg;
Map<String, Audit> auditFields= DEFieldCacheMap.getAuditFields(entity.getClass());
if(arg instanceof EntityBase){
EntityBase entity= (EntityBase) arg;
Map<String, Audit> auditFields= DEFieldCacheMap.getAuditFields(entity.getClass());
//是否有审计属性
if(auditFields.size()==0)
return point.proceed();
String idField=DEFieldCacheMap.getDEKeyField(entity.getClass());
Object idValue="";
if(!StringUtils.isEmpty(idField)){
idValue=entity.get(idField);
}
if(ObjectUtils.isEmpty(idValue))
return point.proceed();
//是否有审计属性
if(auditFields.size()==0)
return point.proceed();
String idField=DEFieldCacheMap.getDEKeyField(entity.getClass());
Object idValue="";
if(!StringUtils.isEmpty(idField)){
idValue=entity.get(idField);
}
if(ObjectUtils.isEmpty(idValue))
return point.proceed();
//获取更新前实体
EntityBase beforeEntity=getEntity(serviceObj,idValue);
//执行更新操作
point.proceed();
//记录审计日志
dataAuditService.updateAudit(request,beforeEntity,serviceObj,idValue,auditFields);
return true;
//获取更新前实体
EntityBase beforeEntity=getEntity(serviceObj,idValue);
//执行更新操作
point.proceed();
//记录审计日志
dataAuditService.updateAudit(request,beforeEntity,serviceObj,idValue,auditFields);
return true;
}
return point.proceed();
}
/**
......@@ -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();
......
<#ibiztemplate>
TARGET=PSDATAENTITY
</#ibiztemplate>
<#assign hasESEntity=false>
<#list sys.getAllPSDataEntities() as dataEntity>
<#if dataEntity.getUserTag()?? && dataEntity.getUserTag()=='elasticsearch'>
<#assign hasESEntity=true>
<#break>
</#if>
</#list>
<#if hasESEntity==true>
package ${pub.getPKGCodeName()}.util.es.aspect;
import lombok.extern.slf4j.Slf4j;
import ${pub.getPKGCodeName()}.util.domain.EntityBase;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.expression.EvaluationContext;
import org.springframework.expression.Expression;
import org.springframework.expression.ExpressionParser;
import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.springframework.expression.spel.support.StandardEvaluationContext;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
import java.util.List;
/**
* es同步数据切面
*/
@Aspect
@Component
@Slf4j
public class ESAspect
{
private final ExpressionParser parser = new SpelExpressionParser();
<#list sys.getAllPSDataEntities() as dataEntity>
<#if dataEntity.getUserTag()?? && dataEntity.getUserTag()=='elasticsearch'>
/**
* 实体[${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.*.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}");
}
</#if>
</#list>
/**
* 异步往es中保存数据
* @param point
*/
public void syncSaveESData(JoinPoint point,String deName){
try {
Object service=point.getTarget();
String action=point.getSignature().getName();
Object [] args = point.getArgs();
if(ObjectUtils.isEmpty(args) || args.length==0 || StringUtils.isEmpty(action))
return;
EvaluationContext exServiceCtx = new StandardEvaluationContext();
exServiceCtx.setVariable("service",service);
Expression esServiceExp = parser.parseExpression("#service.getESService()");
Object exService=esServiceExp.getValue(exServiceCtx);
if(ObjectUtils.isEmpty(exService)){
log.error("获取[{}]实体全文检索服务对象失败",deName);
return;
}
Object arg=args[0];
if(arg instanceof EntityBase || arg instanceof List){
EvaluationContext exMappingCtx = new StandardEvaluationContext();
exMappingCtx.setVariable("service",service);
Expression esMappingExp = parser.parseExpression("#service.getESMapping()");
Object exMapping=esMappingExp.getValue(exMappingCtx);
if(ObjectUtils.isEmpty(exMapping)){
log.error("获取[{}]实体全文检索映射对象失败",deName);
return;
}
EvaluationContext exDomainCtx = new StandardEvaluationContext();
exDomainCtx.setVariable("mapping",exMapping);
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);
}
}
</#if>
\ No newline at end of file
......@@ -14,6 +14,7 @@ import java.util.Map;
import java.util.concurrent.Callable;
import ${pub.getPKGCodeName()}.util.cache.listener.RedisPublisher;
import ${pub.getPKGCodeName()}.util.enums.RedisChannelTopic;
import org.springframework.util.ObjectUtils;
/**
* 缓存分层类
......@@ -61,11 +62,16 @@ public class LayeringCache extends AbstractValueAdaptingCache {
@Override
public ValueWrapper get(Object key) {
ValueWrapper wrapper = caffeineCache.get(key);
log.debug("查询一级缓存 key:{},value:{}", key,wrapper);
if (wrapper == null) {
Object value=ObjectUtils.isEmpty(wrapper)?null:wrapper.get();
log.debug("查询一级缓存 key:{} ,value:{}", key,value);
if (ObjectUtils.isEmpty(value)) {
wrapper = redisCache.get(key);
caffeineCache.put(key, wrapper == null ? null : wrapper.get());
log.debug("查询二级缓存,并将数据放到一级缓存。 key:{}", key);
value=ObjectUtils.isEmpty(wrapper)?null:wrapper.get();
log.debug("查询二级缓存 key:{} ,value:{}", key,value);
if(!ObjectUtils.isEmpty(value)){
caffeineCache.put(key, value);
log.debug("查询二级缓存,并将数据放到一级缓存。 key:{} ,value:{}", key,value);
}
}
return wrapper;
}
......
<#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.filter;
import ${pub.getPKGCodeName()}.util.security.AuthenticationUser;
......@@ -16,6 +23,9 @@ import org.springframework.data.domain.Sort;
import org.springframework.util.StringUtils;
import org.springframework.util.ObjectUtils;
import java.util.*;
<#if hasESEntity>
import org.elasticsearch.index.query.BoolQueryBuilder;
</#if>
@Slf4j
@Data
......@@ -70,7 +80,12 @@ public class SearchContextBase implements ISearchContext{
* 工作流流程标识
*/
public String processDefinitionKey;
<#if hasESEntity>
/**
* es查询条件
*/
public BoolQueryBuilder esCond=new BoolQueryBuilder();
</#if>
/**
* 获取工作流步骤标识
*/
......
......@@ -41,7 +41,7 @@ public class SimpleFileService implements FileService {
FileCopyUtils.copy(multipartFile.getInputStream(),Files.newOutputStream(file.toPath()));
item=new FileItem(fileid,fileName,fileid,fileName,(int)multipartFile.getSize(),extname);
} catch (IOException e) {
throw new InternalServerErrorException("文件上传失败");
throw new InternalServerErrorException("文件上传失败,"+e);
}
return item;
}
......
......@@ -26,7 +26,13 @@ TARGET=PSSYSTEM
<#break>
</#if>
</#list>
<#assign hasESEntity=false>
<#list sys.getAllPSDataEntities() as dataEntity>
<#if dataEntity.getUserTag()?? && dataEntity.getUserTag()=='elasticsearch'>
<#assign hasESEntity=true>
<#break>
</#if>
</#list>
<#assign TcServerCluster="default">
<#assign seataServerName="seata-server">
<#assign nacosAddress="localhost">
......@@ -219,6 +225,11 @@ spring:
mongodb:
uri: ${mongodbUri}
</#if>
<#if hasESEntity>
elasticsearch:
repositories:
enabled: true
</#if>
<#if bDynamicDS>
<@dynamicDatasourceConfig/>
<#else>
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册