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

审计

上级 eedfa55f
...@@ -14,6 +14,8 @@ import org.springframework.cloud.openfeign.EnableFeignClients; ...@@ -14,6 +14,8 @@ import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.web.method.support.HandlerMethodArgumentResolver; import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.ComponentScan;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import java.util.List; import java.util.List;
@Slf4j @Slf4j
...@@ -43,6 +45,8 @@ import java.util.List; ...@@ -43,6 +45,8 @@ import java.util.List;
@Import({ @Import({
org.springframework.cloud.openfeign.FeignClientsConfiguration.class org.springframework.cloud.openfeign.FeignClientsConfiguration.class
}) })
@EnableAsync
@EnableScheduling
public class DevBootApplication extends WebMvcConfigurerAdapter{ public class DevBootApplication extends WebMvcConfigurerAdapter{
public static void main(String[] args) { public static void main(String[] args) {
......
...@@ -16,6 +16,8 @@ import org.mybatis.spring.annotation.MapperScan; ...@@ -16,6 +16,8 @@ import org.mybatis.spring.annotation.MapperScan;
import org.springframework.web.method.support.HandlerMethodArgumentResolver; import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.cloud.openfeign.EnableFeignClients; import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import java.util.List; import java.util.List;
@Slf4j @Slf4j
...@@ -48,6 +50,8 @@ import java.util.List; ...@@ -48,6 +50,8 @@ import java.util.List;
org.springframework.cloud.openfeign.FeignClientsConfiguration.class org.springframework.cloud.openfeign.FeignClientsConfiguration.class
}) })
@EnableFeignClients(basePackages = {"${pub.getPKGCodeName()}" }) @EnableFeignClients(basePackages = {"${pub.getPKGCodeName()}" })
@EnableAsync
@EnableScheduling
public class ${sys.codeName}${item.codeName}Application extends WebMvcConfigurerAdapter{ public class ${sys.codeName}${item.codeName}Application extends WebMvcConfigurerAdapter{
public static void main(String[] args) { public static void main(String[] args) {
......
...@@ -32,19 +32,15 @@ import java.util.*; ...@@ -32,19 +32,15 @@ import java.util.*;
*/ */
@Service @Service
@Slf4j @Slf4j
public class SimpleAuditService extends ServiceImpl<IBZDataAuditMapper, IBZDataAudit> implements IBZDataAuditService { public class SimpleAuditServiceImpl extends ServiceImpl<IBZDataAuditMapper, IBZDataAudit> implements IBZDataAuditService {
private final ExpressionParser parser = new SpelExpressionParser(); private final ExpressionParser parser = new SpelExpressionParser();
private static List cacheMap = Collections.synchronizedList(new ArrayList()); private static List cacheMap = Collections.synchronizedList(new ArrayList());
@Override /**
public boolean save(IBZDataAudit entity) { * 定时保存审计记录
cacheMap.add(entity); */
log.info(String.format("当前待保存审计集合数量为[%S]",cacheMap.size()));
return false;
}
@Scheduled(fixedRate = 10000) @Scheduled(fixedRate = 10000)
public void saveAudit() { public void saveAudit() {
if(cacheMap.size()>0){ if(cacheMap.size()>0){
...@@ -80,7 +76,7 @@ public class SimpleAuditService extends ServiceImpl<IBZDataAuditMapper, IBZDataA ...@@ -80,7 +76,7 @@ public class SimpleAuditService extends ServiceImpl<IBZDataAuditMapper, IBZDataA
dataAudit.setIpaddress(getIpAddress(request, AuthenticationUser.getAuthenticationUser())); dataAudit.setIpaddress(getIpAddress(request, AuthenticationUser.getAuthenticationUser()));
dataAudit.setAuditinfo(getCreateAuditInfo(entity,auditFields)); dataAudit.setAuditinfo(getCreateAuditInfo(entity,auditFields));
dataAudit.setIsdatachanged(1); dataAudit.setIsdatachanged(1);
save(dataAudit); cacheMap.add(dataAudit);
} }
/** /**
...@@ -93,8 +89,6 @@ public class SimpleAuditService extends ServiceImpl<IBZDataAuditMapper, IBZDataA ...@@ -93,8 +89,6 @@ public class SimpleAuditService extends ServiceImpl<IBZDataAuditMapper, IBZDataA
*/ */
@SneakyThrows @SneakyThrows
public void updateAudit(HttpServletRequest request, EntityBase beforeEntity, Object serviceObj, Object idValue, Map<String, Audit> auditFields){ public void updateAudit(HttpServletRequest request, EntityBase beforeEntity, Object serviceObj, Object idValue, Map<String, Audit> auditFields){
System.out.println("updateAudit--开始休眠");
Thread.sleep(10000);
//获取更新后的实体 //获取更新后的实体
EntityBase afterEntity=getEntity(serviceObj,idValue); EntityBase afterEntity=getEntity(serviceObj,idValue);
//获取更新后的审计内容 //获取更新后的审计内容
...@@ -114,8 +108,7 @@ public class SimpleAuditService extends ServiceImpl<IBZDataAuditMapper, IBZDataA ...@@ -114,8 +108,7 @@ public class SimpleAuditService extends ServiceImpl<IBZDataAuditMapper, IBZDataA
dataAudit.setIpaddress(getIpAddress(request, AuthenticationUser.getAuthenticationUser())); dataAudit.setIpaddress(getIpAddress(request, AuthenticationUser.getAuthenticationUser()));
dataAudit.setAuditinfo(auditInfo); dataAudit.setAuditinfo(auditInfo);
dataAudit.setIsdatachanged(isDataChanged); dataAudit.setIsdatachanged(isDataChanged);
save(dataAudit); cacheMap.add(dataAudit);
System.out.println("updateAudit--结束休眠");
} }
/** /**
...@@ -137,7 +130,7 @@ public class SimpleAuditService extends ServiceImpl<IBZDataAuditMapper, IBZDataA ...@@ -137,7 +130,7 @@ public class SimpleAuditService extends ServiceImpl<IBZDataAuditMapper, IBZDataA
dataAudit.setIpaddress(getIpAddress(request, AuthenticationUser.getAuthenticationUser())); dataAudit.setIpaddress(getIpAddress(request, AuthenticationUser.getAuthenticationUser()));
dataAudit.setAuditinfo(getRemoveAuditInfo(entity,auditFields)); dataAudit.setAuditinfo(getRemoveAuditInfo(entity,auditFields));
dataAudit.setIsdatachanged(1); dataAudit.setIsdatachanged(1);
save(dataAudit); cacheMap.add(dataAudit);
} }
/** /**
...@@ -198,10 +191,10 @@ public class SimpleAuditService extends ServiceImpl<IBZDataAuditMapper, IBZDataA ...@@ -198,10 +191,10 @@ public class SimpleAuditService extends ServiceImpl<IBZDataAuditMapper, IBZDataA
newValue=dataTransfer(newValue,auditAnnotation.fieldType(),auditAnnotation.format());//属性值转换 newValue=dataTransfer(newValue,auditAnnotation.fieldType(),auditAnnotation.format());//属性值转换
JSONObject auditFieldObj=new JSONObject(); JSONObject auditFieldObj=new JSONObject();
auditFieldObj.put("field",fieldLogicName); auditFieldObj.put("field",fieldLogicName);
auditFieldObj.put("source",oldValue); auditFieldObj.put("before",oldValue);
auditFieldObj.put("target",newValue); auditFieldObj.put("after",newValue);
if(!StringUtils.isEmpty(auditAnnotation.dictName())){ if(!StringUtils.isEmpty(auditAnnotation.dictName())){
auditFieldObj.put("dictName",auditAnnotation.dictName()); auditFieldObj.put("dict",auditAnnotation.dictName());
} }
auditFieldArray.add(auditFieldObj); auditFieldArray.add(auditFieldObj);
} }
...@@ -235,7 +228,7 @@ public class SimpleAuditService extends ServiceImpl<IBZDataAuditMapper, IBZDataA ...@@ -235,7 +228,7 @@ public class SimpleAuditService extends ServiceImpl<IBZDataAuditMapper, IBZDataA
auditFieldObj.put("field",fieldLogicName); auditFieldObj.put("field",fieldLogicName);
auditFieldObj.put("value",value); auditFieldObj.put("value",value);
if(!StringUtils.isEmpty(auditAnnotation.dictName())){ if(!StringUtils.isEmpty(auditAnnotation.dictName())){
auditFieldObj.put("dictName",auditAnnotation.dictName()); auditFieldObj.put("dict",auditAnnotation.dictName());
} }
auditFieldArray.add(auditFieldObj); auditFieldArray.add(auditFieldObj);
} }
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册