Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
489 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
apollo-biz/src/main/java/com/ctrip/apollo/biz/entity/Audit.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package com.ctrip.apollo.biz.entity; | ||
|
||
import javax.persistence.Column; | ||
import javax.persistence.Entity; | ||
import javax.persistence.Table; | ||
|
||
import org.hibernate.annotations.SQLDelete; | ||
import org.hibernate.annotations.Where; | ||
|
||
@Entity | ||
@Table(name = "Audit") | ||
@SQLDelete(sql = "Update Audit set isDeleted = 1 where id = ?") | ||
@Where(clause = "isDeleted = 0") | ||
public class Audit extends BaseEntity { | ||
|
||
public enum OP { | ||
INSERT, UPDATE, DELETE | ||
} | ||
|
||
@Column(name = "EntityName", nullable = false) | ||
private String entityName; | ||
|
||
@Column(name="EntityId") | ||
private Long entityId; | ||
|
||
@Column(name = "OpName", nullable = false) | ||
private String opName; | ||
|
||
@Column(name = "Comment") | ||
private String comment; | ||
|
||
public String getComment() { | ||
return comment; | ||
} | ||
|
||
public Long getEntityId() { | ||
return entityId; | ||
} | ||
|
||
public String getEntityName() { | ||
return entityName; | ||
} | ||
|
||
public String getOpName() { | ||
return opName; | ||
} | ||
|
||
public void setComment(String comment) { | ||
this.comment = comment; | ||
} | ||
|
||
public void setEntityId(Long entityId) { | ||
this.entityId = entityId; | ||
} | ||
|
||
public void setEntityName(String entityName) { | ||
this.entityName = entityName; | ||
} | ||
|
||
public void setOpName(String opName) { | ||
this.opName = opName; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
apollo-biz/src/main/java/com/ctrip/apollo/biz/repository/AuditRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.ctrip.apollo.biz.repository; | ||
|
||
import java.util.List; | ||
|
||
import org.springframework.data.jpa.repository.Query; | ||
import org.springframework.data.repository.PagingAndSortingRepository; | ||
import org.springframework.data.repository.query.Param; | ||
|
||
import com.ctrip.apollo.biz.entity.Audit; | ||
|
||
public interface AuditRepository extends PagingAndSortingRepository<Audit, Long> { | ||
|
||
@Query("SELECT a from Audit a WHERE a.dataChangeCreatedBy = :owner") | ||
List<Audit> findByOwner(@Param("owner") String owner); | ||
|
||
@Query("SELECT a from Audit a WHERE a.dataChangeCreatedBy = :owner AND a.entityName =:entity AND a.opName = :op") | ||
List<Audit> findAudits(@Param("owner") String owner, @Param("entity") String entity, | ||
@Param("op") String op); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
apollo-biz/src/main/java/com/ctrip/apollo/biz/service/AuditService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.ctrip.apollo.biz.service; | ||
|
||
import java.util.List; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import com.ctrip.apollo.biz.entity.Audit; | ||
import com.ctrip.apollo.biz.repository.AuditRepository; | ||
|
||
@Service | ||
public class AuditService { | ||
|
||
@Autowired | ||
private AuditRepository auditRepository; | ||
|
||
List<Audit> findByOwner(String owner) { | ||
return auditRepository.findByOwner(owner); | ||
} | ||
|
||
List<Audit> find(String owner, String entity, String op) { | ||
return auditRepository.findAudits(owner, entity, op); | ||
} | ||
|
||
@Transactional | ||
void audit(String entityName, Long entityId, Audit.OP op, String owner) { | ||
Audit audit = new Audit(); | ||
audit.setEntityName(entityName); | ||
audit.setEntityId(entityId); | ||
audit.setOpName(op.name()); | ||
audit.setDataChangeCreatedBy(owner); | ||
auditRepository.save(audit); | ||
} | ||
|
||
@Transactional | ||
void audit(Audit audit){ | ||
auditRepository.save(audit); | ||
} | ||
} |
Oops, something went wrong.