mirror of https://github.com/elunez/eladmin
parent
da006624a4
commit
b0db5ca3bb
|
@ -1,14 +1,20 @@
|
||||||
package me.zhengjie.base;
|
package me.zhengjie.base;
|
||||||
|
|
||||||
import lombok.*;
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||||
import org.hibernate.annotations.CreationTimestamp;
|
import org.hibernate.annotations.CreationTimestamp;
|
||||||
import org.hibernate.annotations.UpdateTimestamp;
|
import org.hibernate.annotations.UpdateTimestamp;
|
||||||
|
import org.springframework.data.annotation.CreatedBy;
|
||||||
|
import org.springframework.data.annotation.LastModifiedBy;
|
||||||
|
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
|
||||||
|
|
||||||
import javax.persistence.Column;
|
import javax.persistence.Column;
|
||||||
|
import javax.persistence.EntityListeners;
|
||||||
import javax.persistence.MappedSuperclass;
|
import javax.persistence.MappedSuperclass;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.sql.Timestamp;
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
|
import java.sql.Timestamp;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Zheng Jie
|
* @author Zheng Jie
|
||||||
|
@ -17,18 +23,39 @@ import java.lang.reflect.Field;
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
@MappedSuperclass
|
@MappedSuperclass
|
||||||
|
@EntityListeners(AuditingEntityListener.class)
|
||||||
public class BaseEntity implements Serializable {
|
public class BaseEntity implements Serializable {
|
||||||
|
|
||||||
/** 删除标识 **/
|
/** 删除标识 **/
|
||||||
@Column(name = "is_delete", columnDefinition = "bit default 0")
|
@Column(name = "is_delete", columnDefinition = "bit default 0")
|
||||||
private Boolean isDelete = false;
|
private Boolean isDelete = false;
|
||||||
|
|
||||||
@Column(name = "create_time")
|
/**
|
||||||
|
* 创建人
|
||||||
|
*/
|
||||||
|
@CreatedBy
|
||||||
|
@Column(name = "create_by", updatable = false)
|
||||||
|
private String createdBy;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建时间
|
||||||
|
*/
|
||||||
@CreationTimestamp
|
@CreationTimestamp
|
||||||
|
@Column(name = "create_time", updatable = false)
|
||||||
private Timestamp createTime;
|
private Timestamp createTime;
|
||||||
|
|
||||||
@Column(name = "update_time")
|
/**
|
||||||
|
* 更新人
|
||||||
|
*/
|
||||||
|
@LastModifiedBy
|
||||||
|
@Column(name = "update_by")
|
||||||
|
private String updatedBy;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新时间
|
||||||
|
*/
|
||||||
@UpdateTimestamp
|
@UpdateTimestamp
|
||||||
|
@Column(name = "update_time")
|
||||||
private Timestamp updateTime;
|
private Timestamp updateTime;
|
||||||
|
|
||||||
public @interface Update {}
|
public @interface Update {}
|
||||||
|
|
|
@ -7,6 +7,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
|
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
|
||||||
import org.springframework.boot.web.servlet.server.ServletWebServerFactory;
|
import org.springframework.boot.web.servlet.server.ServletWebServerFactory;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
|
||||||
import org.springframework.scheduling.annotation.EnableAsync;
|
import org.springframework.scheduling.annotation.EnableAsync;
|
||||||
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
@ -18,6 +19,8 @@ import org.springframework.web.bind.annotation.RestController;
|
||||||
*/
|
*/
|
||||||
@EnableAsync
|
@EnableAsync
|
||||||
@RestController
|
@RestController
|
||||||
|
/** 开启审计功能 */
|
||||||
|
@EnableJpaAuditing(auditorAwareRef = "auditorAware")
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
@EnableTransactionManagement
|
@EnableTransactionManagement
|
||||||
public class AppRun {
|
public class AppRun {
|
||||||
|
|
|
@ -0,0 +1,28 @@
|
||||||
|
package me.zhengjie.config;
|
||||||
|
|
||||||
|
import me.zhengjie.utils.SecurityUtils;
|
||||||
|
import org.springframework.data.domain.AuditorAware;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @描述 : 设置审计
|
||||||
|
* @作者 : Dong ZhaoYang
|
||||||
|
* @日期 : 2019/10/28
|
||||||
|
* @时间 : 10:29
|
||||||
|
*/
|
||||||
|
@Component("auditorAware")
|
||||||
|
public class AuditorConfig implements AuditorAware<String> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 返回操作员标志信息
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Optional<String> getCurrentAuditor() {
|
||||||
|
// 这里应根据实际业务情况获取具体信息
|
||||||
|
return Optional.of(SecurityUtils.getUsername());
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue