DataEntity.java 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /**
  2. * Copyright &copy; 2012-2014 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
  3. */
  4. package com.thinkgem.jeesite.common.persistence;
  5. import java.util.Date;
  6. import com.thinkgem.jeesite.common.utils.IdGen;
  7. import org.apache.commons.lang3.StringUtils;
  8. import org.hibernate.validator.constraints.Length;
  9. import com.fasterxml.jackson.annotation.JsonFormat;
  10. import com.fasterxml.jackson.annotation.JsonIgnore;
  11. import com.thinkgem.jeesite.modules.sys.entity.User;
  12. import com.thinkgem.jeesite.modules.sys.utils.UserUtils;
  13. /**
  14. * 数据Entity类
  15. * @author ThinkGem
  16. * @version 2014-05-16
  17. */
  18. public abstract class DataEntity<T> extends BaseEntity<T> {
  19. private static final long serialVersionUID = 1L;
  20. protected String remarks; // 备注
  21. protected User createBy; // 创建者
  22. protected Date createDate; // 创建日期
  23. protected User updateBy; // 更新者
  24. protected Date updateDate; // 更新日期
  25. protected String delFlag; // 删除标记(0:正常;1:删除;2:审核)
  26. protected String enabledStatus; // 启用/禁用状态
  27. public DataEntity() {
  28. super();
  29. this.delFlag = DEL_FLAG_NORMAL;
  30. }
  31. public DataEntity(String id) {
  32. super(id);
  33. }
  34. /**
  35. * 插入之前执行方法,需要手动调用
  36. */
  37. @Override
  38. public void preInsert(){
  39. // 不限制ID为UUID,调用setIsNewRecord()使用自定义ID
  40. // if (!this.isNewRecord){
  41. // setId(IdGen.uuid());
  42. // }
  43. //这里设置数据库id为自增
  44. User user = UserUtils.getUser();
  45. if (StringUtils.isNotBlank(user.getId())){
  46. this.updateBy = user;
  47. this.createBy = user;
  48. }
  49. this.updateDate = new Date();
  50. this.createDate = this.updateDate;
  51. }
  52. /**
  53. * 更新之前执行方法,需要手动调用
  54. */
  55. @Override
  56. public void preUpdate(){
  57. User user = UserUtils.getUser();
  58. if (StringUtils.isNotBlank(user.getId())){
  59. this.updateBy = user;
  60. }
  61. this.updateDate = new Date();
  62. }
  63. @Length(min=0, max=255)
  64. public String getRemarks() {
  65. return remarks;
  66. }
  67. public void setRemarks(String remarks) {
  68. this.remarks = remarks;
  69. }
  70. @JsonIgnore
  71. public User getCreateBy() {
  72. return createBy;
  73. }
  74. public void setCreateBy(User createBy) {
  75. this.createBy = createBy;
  76. }
  77. @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
  78. public Date getCreateDate() {
  79. return createDate;
  80. }
  81. public void setCreateDate(Date createDate) {
  82. this.createDate = createDate;
  83. }
  84. @JsonIgnore
  85. public User getUpdateBy() {
  86. return updateBy;
  87. }
  88. public void setUpdateBy(User updateBy) {
  89. this.updateBy = updateBy;
  90. }
  91. @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
  92. public Date getUpdateDate() {
  93. return updateDate;
  94. }
  95. public void setUpdateDate(Date updateDate) {
  96. this.updateDate = updateDate;
  97. }
  98. @JsonIgnore
  99. @Length(min=1, max=1)
  100. public String getDelFlag() {
  101. return delFlag;
  102. }
  103. public void setDelFlag(String delFlag) {
  104. this.delFlag = delFlag;
  105. }
  106. public String getEnabledStatus() {
  107. return enabledStatus;
  108. }
  109. public void setEnabledStatus(String enabledStatus) {
  110. this.enabledStatus = enabledStatus;
  111. }
  112. }