| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 |
- package org.dromara.${module}.${submodule}.controller;
- import cn.dev33.satoken.annotation.SaCheckPermission;
- import jakarta.servlet.http.HttpServletResponse;
- import jakarta.validation.constraints.NotEmpty;
- import jakarta.validation.constraints.NotNull;
- import lombok.RequiredArgsConstructor;
- import org.dromara.${module}.${submodule}.domain.bo.${ClassName}Bo;
- import org.dromara.${module}.${submodule}.domain.vo.${ClassName}Vo;
- import org.dromara.${module}.${submodule}.listener.${ClassName}ImportListener;
- import org.dromara.${module}.${submodule}.service.I${ClassName}Service;
- import org.dromara.common.core.domain.R;
- import org.dromara.common.core.validate.AddGroup;
- import org.dromara.common.core.validate.EditGroup;
- import org.dromara.common.excel.core.ExcelResult;
- import org.dromara.common.excel.utils.ExcelUtil;
- import org.dromara.common.idempotent.annotation.RepeatSubmit;
- import org.dromara.common.log.annotation.Log;
- import org.dromara.common.log.enums.BusinessType;
- import org.dromara.common.mybatis.core.page.PageQuery;
- import org.dromara.common.mybatis.core.page.TableDataInfo;
- import org.dromara.common.web.core.BaseController;
- import org.springframework.http.MediaType;
- import org.springframework.validation.annotation.Validated;
- import org.springframework.web.bind.annotation.*;
- import org.springframework.web.multipart.MultipartFile;
- import java.util.ArrayList;
- import java.util.List;
- /**
- * ${tableComment}
- * 前端访问路由地址为:/${submodule}/${businessName}
- *
- * @author ${author}
- * @date ${date}
- */
- @Validated
- @RequiredArgsConstructor
- @RestController
- @RequestMapping("/${submodule}/${businessName}")
- public class ${ClassName}Controller extends BaseController {
- private final I${ClassName}Service ${className}Service;
- /**
- * 查询${tableComment}列表
- */
- @SaCheckPermission("${submodule}:${businessName}:list")
- @GetMapping("/list")
- public TableDataInfo<${ClassName}Vo> list(${ClassName}Bo bo, PageQuery pageQuery) {
- return ${className}Service.queryPageList(bo, pageQuery);
- }
- /**
- * 导出${tableComment}列表
- */
- @SaCheckPermission("${submodule}:${businessName}:export")
- @Log(title = "${tableComment}", businessType = BusinessType.EXPORT)
- @PostMapping("/export")
- public void export(${ClassName}Bo bo, HttpServletResponse response) {
- List<${ClassName}Vo> list = ${className}Service.queryList(bo);
- ExcelUtil.exportExcel(list, "${tableComment}", ${ClassName}Vo.class, response);
- }
- /**
- * 获取${tableComment}详细信息
- *
- * @param ${pkField} 主键
- */
- @SaCheckPermission("${submodule}:${businessName}:query")
- @GetMapping("/{${pkField}}")
- public R<${ClassName}Vo> getInfo(@NotNull(message = "主键不能为空")
- @PathVariable ${pkType} ${pkField}) {
- return R.ok(${className}Service.queryById(${pkField}));
- }
- /**
- * 新增${tableComment}
- */
- @SaCheckPermission("${submodule}:${businessName}:add")
- @Log(title = "${tableComment}", businessType = BusinessType.INSERT)
- @RepeatSubmit()
- @PostMapping()
- public R<Void> add(@Validated(AddGroup.class) @RequestBody ${ClassName}Bo bo) {
- return toAjax(${className}Service.insertByBo(bo));
- }
- /**
- * 修改${tableComment}
- */
- @SaCheckPermission("${submodule}:${businessName}:edit")
- @Log(title = "${tableComment}", businessType = BusinessType.UPDATE)
- @RepeatSubmit()
- @PutMapping()
- public R<Void> edit(@Validated(EditGroup.class) @RequestBody ${ClassName}Bo bo) {
- return toAjax(${className}Service.updateByBo(bo));
- }
- /**
- * 删除${tableComment}
- *
- * @param ${pkField}s 主键串
- */
- @SaCheckPermission("${submodule}:${businessName}:remove")
- @Log(title = "${tableComment}", businessType = BusinessType.DELETE)
- @DeleteMapping("/{${pkField}s}")
- public R<Void> remove(@NotEmpty(message = "主键不能为空")
- @PathVariable ${pkType}[] ${pkField}s) {
- return toAjax(${className}Service.deleteWithValidByIds(List.of(${pkField}s), true));
- }
- /**
- * 导出${tableComment}导入模板
- */
- @SaCheckPermission("${submodule}:${businessName}:export")
- @Log(title = "${tableComment}导入模板", businessType = BusinessType.EXPORT)
- @PostMapping("/exportTemplate")
- public void exportTemplate(HttpServletResponse response) {
- List<${ClassName}ImportVo> list = new ArrayList<>();
- ExcelUtil.exportExcel(list, "${tableComment}导入模板", ${ClassName}ImportVo.class, response);
- }
- /**
- * 导入${tableComment}数据
- *
- * @param file Excel文件
- * @param updateSupport 是否更新已存在数据
- */
- @SaCheckPermission("${submodule}:${businessName}:import")
- @Log(title = "${tableComment}导入", businessType = BusinessType.IMPORT)
- @PostMapping(value = "/importData", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
- public R<Void> importData(@RequestPart("file") MultipartFile file, boolean updateSupport) throws Exception {
- ExcelResult<${ClassName}ImportVo> result = ExcelUtil.importExcel(
- file.getInputStream(),
- ${ClassName}ImportVo.class,
- new ${ClassName}ImportListener(updateSupport)
- );
- return R.ok(result.getAnalysis());
- }
- }
|