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 { public abstract BaseService getService(); /** * @date_time 2021-10-11 15:47 * @author H_x_d * @description insert 新建 * @param [t] * @return com.dongke.base.response.ResponseResultVO */ @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 */ @ApiOperation(value = "根据id更新",notes = "根据id更新") @PostMapping("update") public ResponseResultVO 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 */ @ApiOperation(value = "删除 (逻辑删)",notes = "删除 (逻辑删)") @PostMapping("delete/{id}") public ResponseResultVO 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 */ @ApiOperation(value = "停用",notes = "停用") @PostMapping("disable/{id}") public ResponseResultVO 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 */ @ApiOperation(value = "启用",notes = "启用") @PostMapping("enable/{id}") public ResponseResultVO 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 */ @ApiOperation(value = "批量新建",notes = "批量新建") @PostMapping("insert_batch") public ResponseResultVO insertBatch(@Valid @RequestBody List 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 */ @ApiOperation(value = "批量更新",notes = "批量更新") @PostMapping("update_batch") public ResponseResultVO updateBatch(@Valid @RequestBody List 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 */ @ApiOperation(value = "批量删除",notes = "批量删除") @PostMapping("delete_batch") public ResponseResultVO deleteBatch(@RequestBody List 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 */ @ApiOperation(value = "批量停用",notes = "批量停用") @PostMapping("disable_batch") public ResponseResultVO disableBatch(@RequestBody List 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 */ @ApiOperation(value = "批量启用",notes = "批量启用") @PostMapping("enable_batch") public ResponseResultVO enableBatch(@RequestBody List 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 */ @ApiOperation(value = "导入",notes = "导入") @PostMapping("import") public ResponseResultVO importList(MultipartFile file) { Class entityClass = (Class) ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0]; List 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> */ @ApiOperation(value = "分页、关联、条件查询",notes = "分页、关联、条件查询") @PostMapping("list_by") public ResponseResultVO> 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 */ @ApiOperation(value = "分页、关联、条件查询数量",notes = "分页、关联、条件查询数量") @PostMapping("count_by") public ResponseResultVO 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> */ @ApiOperation(value = "全量查询",notes = "全量查询") @PostMapping("all") public ResponseResultVO> 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 */ @ApiOperation(value = "全量查询数量",notes = "全量查询数量") @PostMapping("total") public ResponseResultVO 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 */ @ApiOperation(value = "根据id查询",notes = "根据id查询") @PostMapping("{id}") public ResponseResultVO selectById(@PathVariable String id) { return this.getService().selectById(id); } }