AbstractService.java 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. package com.fdkankan.common.base;
  2. import java.io.Serializable;
  3. import java.util.LinkedHashMap;
  4. import java.util.List;
  5. public abstract class AbstractService<T extends Serializable> implements IServiceOperations<T> {
  6. protected abstract IOperations<T> getMapper();
  7. protected String tableName = "";
  8. public abstract void setTableName(String tableName);
  9. protected String getTableName() {
  10. return this.tableName;
  11. }
  12. @Override
  13. public void insert(T entity) {
  14. getMapper().insert(entity, this.getTableName());
  15. }
  16. @Override
  17. public int insertByBatch(List<T> list) {
  18. return getMapper().insertByBatch(list, this.getTableName());
  19. }
  20. @Override
  21. public int update(List<T> list) {
  22. return getMapper().update(list, this.getTableName());
  23. }
  24. @Override
  25. public int updateByBatch(LinkedHashMap<String, String> condition, String field) {
  26. return getMapper().updateByBatch(condition, field, this.getTableName());
  27. }
  28. @Override
  29. public T getById(int id) {
  30. return getMapper().getById(id, this.getTableName());
  31. }
  32. @Override
  33. public T getOne(LinkedHashMap<String, String> condition) {
  34. String field = null;
  35. return this.getOne(condition, field, this.getTableName());
  36. }
  37. @Override
  38. public T getOne(LinkedHashMap<String, String> condition, String field) {
  39. return getMapper().getOne(condition, field, this.getTableName());
  40. }
  41. @Override
  42. public int getCount(LinkedHashMap<String, String> condition, String field) {
  43. return getMapper().getCount(condition, field, this.getTableName());
  44. }
  45. @Override
  46. public List<T> getList(LinkedHashMap<String, String> condition, int pageNo, int pageSize, String order, String field) {
  47. int offset = (pageNo - 1) * pageSize;
  48. int limit = pageSize;
  49. return getMapper().getList(condition, offset, limit, order, field, this.getTableName());
  50. }
  51. @Override
  52. public List<T> getAllList(LinkedHashMap<String, String> condition) {
  53. return this.getAllList(condition, null);
  54. }
  55. @Override
  56. public List<T> getAllList(LinkedHashMap<String, String> condition, String order) {
  57. if(order == null || order.trim().length() == 0) {
  58. order = null;
  59. }
  60. return getMapper().getList(condition, 0, 0, order, null, this.getTableName());
  61. }
  62. @Override
  63. public List<T> getList(int pageNo, int pageSize) {
  64. String order = null;
  65. return this.getList(pageNo, pageSize, order);
  66. }
  67. @Override
  68. public List<T> getList(int pageNo, int pageSize, String order) {
  69. String field = null;
  70. return this.getList(pageNo, pageSize, order, field);
  71. }
  72. @Override
  73. public List<T> getList(int pageNo, int pageSize, String order, String field) {
  74. LinkedHashMap<String, String> condition = new LinkedHashMap<String, String>();
  75. return this.getList(condition, pageNo, pageSize, order, field);
  76. }
  77. @Override
  78. public List<T> getList(LinkedHashMap<String, String> condition, int pageNo, int pageSize) {
  79. String order = null;
  80. return this.getList(condition, pageNo, pageSize, order);
  81. }
  82. @Override
  83. public List<T> getList(LinkedHashMap<String, String> condition, int pageNo, int pageSize, String order) {
  84. String field = null;
  85. return this.getList(condition, pageNo, pageSize, order, field);
  86. }
  87. @Override
  88. public int existTable(String tableName) {
  89. return getMapper().existTable(tableName);
  90. }
  91. @Override
  92. public int createTable(String tableName) {
  93. return getMapper().createTable(tableName);
  94. }
  95. // 以下暂时没有场景用到,留在这里,需要时候根据实际情况进行修改即可。
  96. @Override
  97. public void insert(T entity, String tableName) {
  98. this.getMapper().insert(entity, tableName);
  99. }
  100. @Override
  101. public int insertByBatch(List<T> list, String tableName) {
  102. return this.getMapper().insertByBatch(list, tableName);
  103. }
  104. @Override
  105. public int update(List<T> list, String tableName) {
  106. return this.update(list, tableName);
  107. }
  108. @Override
  109. public int updateByBatch(LinkedHashMap<String, String> condition, String field, String tableName) {
  110. return this.getMapper().updateByBatch(condition, field, this.getTableName());
  111. }
  112. @Override
  113. public T getById(int id, String tableName) {
  114. return this.getMapper().getById(id, tableName);
  115. }
  116. @Override
  117. public T getOne(LinkedHashMap<String, String> condition, String field, String tableName) {
  118. return this.getMapper().getOne(condition, field, tableName);
  119. }
  120. @Override
  121. public int getCount(LinkedHashMap<String, String> condition, String field, String tableName) {
  122. return this.getMapper().getCount(condition, field, tableName);
  123. }
  124. @Override
  125. public List<T> getList(LinkedHashMap<String, String> condition, int offset, int limit, String order, String field, String tableName) {
  126. return this.getMapper().getList(condition, offset, limit, order, field, tableName);
  127. }
  128. }