TreeEntity.java 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /**
  2. * Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
  3. */
  4. package com.jeeplus.common.persistence;
  5. import javax.validation.constraints.NotNull;
  6. import org.hibernate.validator.constraints.Length;
  7. import com.fasterxml.jackson.annotation.JsonBackReference;
  8. import com.jeeplus.common.utils.Reflections;
  9. import com.jeeplus.common.utils.StringUtils;
  10. /**
  11. * 数据Entity类
  12. * @author jeeplus
  13. * @version 2014-05-16
  14. */
  15. public abstract class TreeEntity<T> extends DataEntity<T> {
  16. private static final long serialVersionUID = 1L;
  17. protected T parent; // 父级编号
  18. protected transient String parentIds; // 所有父级编号
  19. protected transient String name; // 机构名称
  20. protected Integer sort; // 排序
  21. public TreeEntity() {
  22. super();
  23. this.sort = 30;
  24. }
  25. public TreeEntity(String id) {
  26. super(id);
  27. }
  28. /**
  29. * 父对象,只能通过子类实现,父类实现mybatis无法读取
  30. * @return
  31. */
  32. @JsonBackReference
  33. @NotNull
  34. public abstract T getParent();
  35. /**
  36. * 父对象,只能通过子类实现,父类实现mybatis无法读取
  37. * @return
  38. */
  39. public abstract void setParent(T parent);
  40. @Length(min=1, max=2000)
  41. public String getParentIds() {
  42. return parentIds;
  43. }
  44. public void setParentIds(String parentIds) {
  45. this.parentIds = parentIds;
  46. }
  47. @Length(min=1, max=100)
  48. public String getName() {
  49. return name;
  50. }
  51. public void setName(String name) {
  52. this.name = name;
  53. }
  54. public Integer getSort() {
  55. return sort;
  56. }
  57. public void setSort(Integer sort) {
  58. this.sort = sort;
  59. }
  60. public String getParentId() {
  61. String id = null;
  62. if (parent != null){
  63. id = (String)Reflections.getFieldValue(parent, "id");
  64. }
  65. return StringUtils.isNotBlank(id) ? id : "0";
  66. }
  67. }