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

代码规范检查

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