package cn.iocoder.yudao.module.bpm.controller.admin.definition;
|
|
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
|
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
|
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.category.BpmCategoryImportExcelVO;
|
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.category.BpmCategoryImportReqVO;
|
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.category.BpmCategoryImportRespVO;
|
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.category.BpmCategoryPageReqVO;
|
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.category.BpmCategoryRespVO;
|
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.category.BpmCategorySaveReqVO;
|
import cn.iocoder.yudao.module.bpm.dal.dataobject.definition.BpmCategoryDO;
|
import cn.iocoder.yudao.module.bpm.service.definition.BpmCategoryService;
|
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Parameter;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
import jakarta.annotation.Resource;
|
import jakarta.servlet.http.HttpServletResponse;
|
import jakarta.validation.Valid;
|
import org.springframework.security.access.prepost.PreAuthorize;
|
import org.springframework.validation.annotation.Validated;
|
import org.springframework.web.bind.annotation.*;
|
|
import java.io.IOException;
|
import java.util.Arrays;
|
import java.util.Comparator;
|
import java.util.List;
|
|
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
|
|
@Tag(name = "管理后台 - BPM 流程分类")
|
@RestController
|
@RequestMapping("/bpm/category")
|
@Validated
|
public class BpmCategoryController {
|
|
@Resource
|
private BpmCategoryService categoryService;
|
|
@PostMapping("/create")
|
@Operation(summary = "创建流程分类")
|
@PreAuthorize("@ss.hasPermission('bpm:category:create')")
|
public CommonResult<Long> createCategory(@Valid @RequestBody BpmCategorySaveReqVO createReqVO) {
|
return success(categoryService.createCategory(createReqVO));
|
}
|
|
@PutMapping("/update")
|
@Operation(summary = "更新流程分类")
|
@PreAuthorize("@ss.hasPermission('bpm:category:update')")
|
public CommonResult<Boolean> updateCategory(@Valid @RequestBody BpmCategorySaveReqVO updateReqVO) {
|
categoryService.updateCategory(updateReqVO);
|
return success(true);
|
}
|
|
@PutMapping("/update-sort-batch")
|
@Operation(summary = "批量更新流程分类的排序")
|
@Parameter(name = "ids", description = "分类编号列表", required = true, example = "1,2,3")
|
@PreAuthorize("@ss.hasPermission('bpm:category:update')")
|
public CommonResult<Boolean> updateCategorySortBatch(@RequestParam("ids") List<Long> ids) {
|
categoryService.updateCategorySortBatch(ids);
|
return success(true);
|
}
|
|
@DeleteMapping("/delete")
|
@Operation(summary = "删除流程分类")
|
@Parameter(name = "id", description = "编号", required = true)
|
@PreAuthorize("@ss.hasPermission('bpm:category:delete')")
|
public CommonResult<Boolean> deleteCategory(@RequestParam("id") Long id) {
|
categoryService.deleteCategory(id);
|
return success(true);
|
}
|
|
@GetMapping("/get")
|
@Operation(summary = "获得流程分类")
|
@Parameter(name = "id", description = "编号", required = true, example = "1024")
|
@PreAuthorize("@ss.hasPermission('bpm:category:query')")
|
public CommonResult<BpmCategoryRespVO> getCategory(@RequestParam("id") Long id) {
|
BpmCategoryDO category = categoryService.getCategory(id);
|
return success(BeanUtils.toBean(category, BpmCategoryRespVO.class));
|
}
|
|
@GetMapping("/page")
|
@Operation(summary = "获得流程分类分页")
|
@PreAuthorize("@ss.hasPermission('bpm:category:query')")
|
public CommonResult<PageResult<BpmCategoryRespVO>> getCategoryPage(@Valid BpmCategoryPageReqVO pageReqVO) {
|
PageResult<BpmCategoryDO> pageResult = categoryService.getCategoryPage(pageReqVO);
|
return success(BeanUtils.toBean(pageResult, BpmCategoryRespVO.class));
|
}
|
|
@GetMapping("/simple-list")
|
@Operation(summary = "获取流程分类的精简信息列表", description = "只包含被开启的分类,主要用于前端的下拉选项")
|
public CommonResult<List<BpmCategoryRespVO>> getCategorySimpleList() {
|
List<BpmCategoryDO> list = categoryService.getCategoryListByStatus(CommonStatusEnum.ENABLE.getStatus());
|
list.sort(Comparator.comparingInt(BpmCategoryDO::getSort));
|
return success(convertList(list, category -> new BpmCategoryRespVO().setId(category.getId())
|
.setName(category.getName()).setCode(category.getCode())));
|
}
|
|
@GetMapping("/get-import-template")
|
@Operation(summary = "获得导入流程分类模板")
|
public void importTemplate(HttpServletResponse response) throws IOException {
|
// 手动创建导出 demo
|
List<BpmCategoryImportExcelVO> list = Arrays.asList(
|
BpmCategoryImportExcelVO.builder().name("示例分类").code("example")
|
.description("示例流程分类").status(CommonStatusEnum.ENABLE.getStatus()).sort(1).build()
|
);
|
// 输出
|
ExcelUtils.write(response, "流程分类导入模板.xls", "流程分类列表", BpmCategoryImportExcelVO.class, list);
|
}
|
|
@PostMapping("/import")
|
@Operation(summary = "导入流程分类")
|
@PreAuthorize("@ss.hasPermission('bpm:category:import')")
|
public CommonResult<BpmCategoryImportRespVO> importExcel(@Valid BpmCategoryImportReqVO importReqVO)
|
throws Exception {
|
List<BpmCategoryImportExcelVO> list = ExcelUtils.read(importReqVO.getFile(), BpmCategoryImportExcelVO.class);
|
return success(categoryService.importCategoryList(list, importReqVO));
|
}
|
|
}
|