| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245 |
- package com.dk.common.controller;
- import com.dk.common.model.pojo.PageList;
- import com.dk.common.response.ResponseResultVO;
- import com.dk.common.service.BaseService;
- import com.dk.common.util.ExcelUtils;
- import io.swagger.annotations.ApiOperation;
- import org.springframework.web.bind.annotation.*;
- import org.springframework.web.multipart.MultipartFile;
- import javax.servlet.http.HttpServletResponse;
- import javax.validation.Valid;
- import java.lang.reflect.ParameterizedType;
- import java.util.List;
- @CrossOrigin(origins = "*", allowCredentials = "true")
- public abstract class BaseController<T> {
- public abstract BaseService<T> getService();
- /**
- * @date_time 2021-10-11 15:47
- * @author H_x_d
- * @description insert 新建
- * @param [t]
- * @return com.dongke.base.response.ResponseResultVO<java.lang.Boolean>
- */
- @ApiOperation(value = "新建",notes = "新建")
- @PostMapping("insert")
- public ResponseResultVO<?> insert(@Valid @RequestBody T t) {
- return this.getService().insert(t);
- }
- /**
- * @date_time 2021-10-11 16:34
- * @author H_x_d
- * @description update 根据id更新
- * @param [t]
- * @return com.dongke.base.response.ResponseResultVO<java.lang.Boolean>
- */
- @ApiOperation(value = "根据id更新",notes = "根据id更新")
- @PostMapping("update")
- public ResponseResultVO<Boolean> update(@Valid @RequestBody T t) {
- return this.getService().update(t);
- }
- /**
- * @date_time 2021-10-11 16:36
- * @author H_x_d
- * @description delete 删除 (逻辑删)
- * @param [id]
- * @return com.dongke.base.response.ResponseResultVO<java.lang.Boolean>
- */
- @ApiOperation(value = "删除 (逻辑删)",notes = "删除 (逻辑删)")
- @PostMapping("delete/{id}")
- public ResponseResultVO<Boolean> delete(@PathVariable Long id) {
- return this.getService().delete(id);
- }
- /**
- * @date_time 2021-10-12 09:16
- * @author H_x_d
- * @description disable 停用
- * @param [id]
- * @return com.dongke.base.response.ResponseResultVO<java.lang.Boolean>
- */
- @ApiOperation(value = "停用",notes = "停用")
- @PostMapping("disable/{id}")
- public ResponseResultVO<Boolean> disable(@PathVariable String id) {
- return this.getService().disable(id);
- }
- /**
- * @date_time 2021-10-12 09:16
- * @author H_x_d
- * @description enable 启用
- * @param [id]
- * @return com.dongke.base.response.ResponseResultVO<java.lang.Boolean>
- */
- @ApiOperation(value = "启用",notes = "启用")
- @PostMapping("enable/{id}")
- public ResponseResultVO<Boolean> enable(@PathVariable String id) {
- return this.getService().enable(id);
- }
- /**
- * @date_time 2021-10-12 09:26
- * @author H_x_d
- * @description insertBatch 批量新建
- * rewriteBatchedStatements=true
- * @param [list]
- * @return com.dongke.base.response.ResponseResultVO<java.lang.Boolean>
- */
- @ApiOperation(value = "批量新建",notes = "批量新建")
- @PostMapping("insert_batch")
- public ResponseResultVO<Boolean> insertBatch(@Valid @RequestBody List<T> list) {
- return this.getService().insertBatch(list);
- }
- /**
- * @date_time 2021-10-12 09:26
- * @author H_x_d
- * @description updateBatch 批量更新
- * MySQL 的URL配置添加 allowMultiQueries=true 否则无法支持批量修改语句??
- * @param [list]
- * @return com.dongke.base.response.ResponseResultVO<java.lang.Boolean>
- */
- @ApiOperation(value = "批量更新",notes = "批量更新")
- @PostMapping("update_batch")
- public ResponseResultVO<Boolean> updateBatch(@Valid @RequestBody List<T> list) {
- return this.getService().updateBatch(list);
- }
- /**
- * @date_time 2021-10-12 11:07
- * @author H_x_d
- * @description deleteBatch 批量删除
- * @param [list]
- * @return com.dongke.base.response.ResponseResultVO<java.lang.Boolean>
- */
- @ApiOperation(value = "批量删除",notes = "批量删除")
- @PostMapping("delete_batch")
- public ResponseResultVO<Boolean> deleteBatch(@RequestBody List<Long> list) {
- return this.getService().deleteBatch(list);
- }
- /**
- * @date_time 2021-10-12 11:45
- * @author H_x_d
- * @description disableBatch 批量停用
- * @param [ids]
- * @return com.dongke.base.response.ResponseResultVO<java.lang.Boolean>
- */
- @ApiOperation(value = "批量停用",notes = "批量停用")
- @PostMapping("disable_batch")
- public ResponseResultVO<Boolean> disableBatch(@RequestBody List<Long> ids) {
- return this.getService().disableBatch(ids);
- }
- /**
- * @date_time 2021-10-12 11:45
- * @author H_x_d
- * @description enableBatch 批量启用
- * @param [ids]
- * @return com.dongke.base.response.ResponseResultVO<java.lang.Boolean>
- */
- @ApiOperation(value = "批量启用",notes = "批量启用")
- @PostMapping("enable_batch")
- public ResponseResultVO<Boolean> enableBatch(@RequestBody List<Long> ids) {
- return this.getService().enableBatch(ids);
- }
- /**
- * @date_time 2021-10-12 13:20
- * @author H_x_d
- * @description importList 导入
- * @param [file]
- * @return com.dongke.base.response.ResponseResultVO<java.lang.Boolean>
- */
- @ApiOperation(value = "导入",notes = "导入")
- @PostMapping("import")
- public ResponseResultVO<Boolean> importList(MultipartFile file) {
- Class<T> entityClass = (Class<T>) ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0];
- List<T> list = ExcelUtils.importExcel(file, 1, 1, entityClass);
- return this.getService().importList(list);
- }
- /**
- * @date_time 2021-10-12 13:27
- * @author H_x_d
- * @description exportList 导出
- * @param [response, t]
- * @return void
- */
- @ApiOperation(value = "导出",notes = "导出")
- @GetMapping("export")
- public void exportList(HttpServletResponse response, T t) {
- this.getService().exportList(response, t);
- }
- /**
- * @date_time 2021-10-12 13:32
- * @author H_x_d
- * @description selectByCond 分页、关联、条件查询
- * @param [t]
- * @return com.dongke.base.response.ResponseResultVO<com.dongke.base.model.pojo.PageList < T>>
- */
- @ApiOperation(value = "分页、关联、条件查询",notes = "分页、关联、条件查询")
- @PostMapping("list_by")
- public ResponseResultVO<PageList<T>> selectByCond(@RequestBody T t) {
- return this.getService().selectByCond(t);
- }
- /**
- * @date_time 2021-10-12 13:33
- * @author H_x_d
- * @description countByCond 分页、关联、条件查询数量
- * @param [t]
- * @return com.dongke.base.response.ResponseResultVO<java.lang.Long>
- */
- @ApiOperation(value = "分页、关联、条件查询数量",notes = "分页、关联、条件查询数量")
- @PostMapping("count_by")
- public ResponseResultVO<Long> countByCond(@RequestBody T t) {
- return this.getService().countByCond(t);
- }
- /**
- * @date_time 2021-10-12 13:56
- * @author H_x_d
- * @description selectAll 全量查询
- * @param []
- * @return com.dongke.base.response.ResponseResultVO<java.util.List < T>>
- */
- @ApiOperation(value = "全量查询",notes = "全量查询")
- @PostMapping("all")
- public ResponseResultVO<List<T>> selectAll() {
- return this.getService().selectAll();
- }
- /**
- * @date_time 2021-10-12 13:56
- * @author H_x_d
- * @description countAll 全量查询数量
- * @param []
- * @return com.dongke.base.response.ResponseResultVO<java.lang.Long>
- */
- @ApiOperation(value = "全量查询数量",notes = "全量查询数量")
- @PostMapping("total")
- public ResponseResultVO<Long> countAll() {
- return this.getService().countAll();
- }
- /**
- * @date_time 2021-10-12 14:08
- * @author H_x_d
- * @description selectById 根据id查询
- * @param [id]
- * @return com.dongke.base.response.ResponseResultVO<T>
- */
- @ApiOperation(value = "根据id查询",notes = "根据id查询")
- @PostMapping("{id}")
- public ResponseResultVO<T> selectById(@PathVariable String id) {
- return this.getService().selectById(id);
- }
- }
|