BaseController.java 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. package com.dk.common.controller;
  2. import com.dk.common.model.pojo.PageList;
  3. import com.dk.common.response.ResponseResultVO;
  4. import com.dk.common.service.BaseService;
  5. import com.dk.common.util.ExcelUtils;
  6. import io.swagger.annotations.ApiOperation;
  7. import org.springframework.web.bind.annotation.*;
  8. import org.springframework.web.multipart.MultipartFile;
  9. import javax.servlet.http.HttpServletResponse;
  10. import javax.validation.Valid;
  11. import java.lang.reflect.ParameterizedType;
  12. import java.util.List;
  13. @CrossOrigin(origins = "*", allowCredentials = "true")
  14. public abstract class BaseController<T> {
  15. public abstract BaseService<T> getService();
  16. /**
  17. * @date_time 2021-10-11 15:47
  18. * @author H_x_d
  19. * @description insert 新建
  20. * @param [t]
  21. * @return com.dongke.base.response.ResponseResultVO<java.lang.Boolean>
  22. */
  23. @ApiOperation(value = "新建",notes = "新建")
  24. @PostMapping("insert")
  25. public ResponseResultVO<?> insert(@Valid @RequestBody T t) {
  26. return this.getService().insert(t);
  27. }
  28. /**
  29. * @date_time 2021-10-11 16:34
  30. * @author H_x_d
  31. * @description update 根据id更新
  32. * @param [t]
  33. * @return com.dongke.base.response.ResponseResultVO<java.lang.Boolean>
  34. */
  35. @ApiOperation(value = "根据id更新",notes = "根据id更新")
  36. @PostMapping("update")
  37. public ResponseResultVO<Boolean> update(@Valid @RequestBody T t) {
  38. return this.getService().update(t);
  39. }
  40. /**
  41. * @date_time 2021-10-11 16:36
  42. * @author H_x_d
  43. * @description delete 删除 (逻辑删)
  44. * @param [id]
  45. * @return com.dongke.base.response.ResponseResultVO<java.lang.Boolean>
  46. */
  47. @ApiOperation(value = "删除 (逻辑删)",notes = "删除 (逻辑删)")
  48. @PostMapping("delete/{id}")
  49. public ResponseResultVO<Boolean> delete(@PathVariable Long id) {
  50. return this.getService().delete(id);
  51. }
  52. /**
  53. * @date_time 2021-10-12 09:16
  54. * @author H_x_d
  55. * @description disable 停用
  56. * @param [id]
  57. * @return com.dongke.base.response.ResponseResultVO<java.lang.Boolean>
  58. */
  59. @ApiOperation(value = "停用",notes = "停用")
  60. @PostMapping("disable/{id}")
  61. public ResponseResultVO<Boolean> disable(@PathVariable String id) {
  62. return this.getService().disable(id);
  63. }
  64. /**
  65. * @date_time 2021-10-12 09:16
  66. * @author H_x_d
  67. * @description enable 启用
  68. * @param [id]
  69. * @return com.dongke.base.response.ResponseResultVO<java.lang.Boolean>
  70. */
  71. @ApiOperation(value = "启用",notes = "启用")
  72. @PostMapping("enable/{id}")
  73. public ResponseResultVO<Boolean> enable(@PathVariable String id) {
  74. return this.getService().enable(id);
  75. }
  76. /**
  77. * @date_time 2021-10-12 09:26
  78. * @author H_x_d
  79. * @description insertBatch 批量新建
  80. * rewriteBatchedStatements=true
  81. * @param [list]
  82. * @return com.dongke.base.response.ResponseResultVO<java.lang.Boolean>
  83. */
  84. @ApiOperation(value = "批量新建",notes = "批量新建")
  85. @PostMapping("insert_batch")
  86. public ResponseResultVO<Boolean> insertBatch(@Valid @RequestBody List<T> list) {
  87. return this.getService().insertBatch(list);
  88. }
  89. /**
  90. * @date_time 2021-10-12 09:26
  91. * @author H_x_d
  92. * @description updateBatch 批量更新
  93. * MySQL 的URL配置添加 allowMultiQueries=true 否则无法支持批量修改语句??
  94. * @param [list]
  95. * @return com.dongke.base.response.ResponseResultVO<java.lang.Boolean>
  96. */
  97. @ApiOperation(value = "批量更新",notes = "批量更新")
  98. @PostMapping("update_batch")
  99. public ResponseResultVO<Boolean> updateBatch(@Valid @RequestBody List<T> list) {
  100. return this.getService().updateBatch(list);
  101. }
  102. /**
  103. * @date_time 2021-10-12 11:07
  104. * @author H_x_d
  105. * @description deleteBatch 批量删除
  106. * @param [list]
  107. * @return com.dongke.base.response.ResponseResultVO<java.lang.Boolean>
  108. */
  109. @ApiOperation(value = "批量删除",notes = "批量删除")
  110. @PostMapping("delete_batch")
  111. public ResponseResultVO<Boolean> deleteBatch(@RequestBody List<Long> list) {
  112. return this.getService().deleteBatch(list);
  113. }
  114. /**
  115. * @date_time 2021-10-12 11:45
  116. * @author H_x_d
  117. * @description disableBatch 批量停用
  118. * @param [ids]
  119. * @return com.dongke.base.response.ResponseResultVO<java.lang.Boolean>
  120. */
  121. @ApiOperation(value = "批量停用",notes = "批量停用")
  122. @PostMapping("disable_batch")
  123. public ResponseResultVO<Boolean> disableBatch(@RequestBody List<Long> ids) {
  124. return this.getService().disableBatch(ids);
  125. }
  126. /**
  127. * @date_time 2021-10-12 11:45
  128. * @author H_x_d
  129. * @description enableBatch 批量启用
  130. * @param [ids]
  131. * @return com.dongke.base.response.ResponseResultVO<java.lang.Boolean>
  132. */
  133. @ApiOperation(value = "批量启用",notes = "批量启用")
  134. @PostMapping("enable_batch")
  135. public ResponseResultVO<Boolean> enableBatch(@RequestBody List<Long> ids) {
  136. return this.getService().enableBatch(ids);
  137. }
  138. /**
  139. * @date_time 2021-10-12 13:20
  140. * @author H_x_d
  141. * @description importList 导入
  142. * @param [file]
  143. * @return com.dongke.base.response.ResponseResultVO<java.lang.Boolean>
  144. */
  145. @ApiOperation(value = "导入",notes = "导入")
  146. @PostMapping("import")
  147. public ResponseResultVO<Boolean> importList(MultipartFile file) {
  148. Class<T> entityClass = (Class<T>) ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0];
  149. List<T> list = ExcelUtils.importExcel(file, 1, 1, entityClass);
  150. return this.getService().importList(list);
  151. }
  152. /**
  153. * @date_time 2021-10-12 13:27
  154. * @author H_x_d
  155. * @description exportList 导出
  156. * @param [response, t]
  157. * @return void
  158. */
  159. @ApiOperation(value = "导出",notes = "导出")
  160. @GetMapping("export")
  161. public void exportList(HttpServletResponse response, T t) {
  162. this.getService().exportList(response, t);
  163. }
  164. /**
  165. * @date_time 2021-10-12 13:32
  166. * @author H_x_d
  167. * @description selectByCond 分页、关联、条件查询
  168. * @param [t]
  169. * @return com.dongke.base.response.ResponseResultVO<com.dongke.base.model.pojo.PageList < T>>
  170. */
  171. @ApiOperation(value = "分页、关联、条件查询",notes = "分页、关联、条件查询")
  172. @PostMapping("list_by")
  173. public ResponseResultVO<PageList<T>> selectByCond(@RequestBody T t) {
  174. return this.getService().selectByCond(t);
  175. }
  176. /**
  177. * @date_time 2021-10-12 13:33
  178. * @author H_x_d
  179. * @description countByCond 分页、关联、条件查询数量
  180. * @param [t]
  181. * @return com.dongke.base.response.ResponseResultVO<java.lang.Long>
  182. */
  183. @ApiOperation(value = "分页、关联、条件查询数量",notes = "分页、关联、条件查询数量")
  184. @PostMapping("count_by")
  185. public ResponseResultVO<Long> countByCond(@RequestBody T t) {
  186. return this.getService().countByCond(t);
  187. }
  188. /**
  189. * @date_time 2021-10-12 13:56
  190. * @author H_x_d
  191. * @description selectAll 全量查询
  192. * @param []
  193. * @return com.dongke.base.response.ResponseResultVO<java.util.List < T>>
  194. */
  195. @ApiOperation(value = "全量查询",notes = "全量查询")
  196. @PostMapping("all")
  197. public ResponseResultVO<List<T>> selectAll() {
  198. return this.getService().selectAll();
  199. }
  200. /**
  201. * @date_time 2021-10-12 13:56
  202. * @author H_x_d
  203. * @description countAll 全量查询数量
  204. * @param []
  205. * @return com.dongke.base.response.ResponseResultVO<java.lang.Long>
  206. */
  207. @ApiOperation(value = "全量查询数量",notes = "全量查询数量")
  208. @PostMapping("total")
  209. public ResponseResultVO<Long> countAll() {
  210. return this.getService().countAll();
  211. }
  212. /**
  213. * @date_time 2021-10-12 14:08
  214. * @author H_x_d
  215. * @description selectById 根据id查询
  216. * @param [id]
  217. * @return com.dongke.base.response.ResponseResultVO<T>
  218. */
  219. @ApiOperation(value = "根据id查询",notes = "根据id查询")
  220. @PostMapping("{id}")
  221. public ResponseResultVO<T> selectById(@PathVariable String id) {
  222. return this.getService().selectById(id);
  223. }
  224. }