refactor(流程管理): 重构 流程分类,修复修改流程分类时,提示"分类编码"已存在bug

This commit is contained in:
konbai
2023-03-19 22:32:59 +08:00
parent 1293ad683f
commit 6707696cf9
7 changed files with 47 additions and 98 deletions

View File

@@ -8,12 +8,9 @@ import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.workflow.domain.bo.WfCategoryBo;
import com.ruoyi.workflow.domain.WfCategory;
import com.ruoyi.workflow.domain.vo.WfCategoryVo;
import com.ruoyi.workflow.service.IWfCategoryService;
import lombok.RequiredArgsConstructor;
@@ -45,8 +42,8 @@ public class WfCategoryController extends BaseController {
*/
@SaCheckPermission("workflow:category:list")
@GetMapping("/list")
public TableDataInfo<WfCategoryVo> list(@Validated(QueryGroup.class) WfCategoryBo bo, PageQuery pageQuery) {
return categoryService.queryPageList(bo, pageQuery);
public TableDataInfo<WfCategoryVo> list(WfCategory category, PageQuery pageQuery) {
return categoryService.queryPageList(category, pageQuery);
}
/**
@@ -54,8 +51,8 @@ public class WfCategoryController extends BaseController {
*/
@SaCheckLogin
@GetMapping("/listAll")
public R<List<WfCategoryVo>> listAll(@Validated(QueryGroup.class) WfCategoryBo bo) {
return R.ok(categoryService.queryList(bo));
public R<List<WfCategoryVo>> listAll(WfCategory category) {
return R.ok(categoryService.queryList(category));
}
/**
@@ -64,8 +61,8 @@ public class WfCategoryController extends BaseController {
@SaCheckPermission("workflow:category:export")
@Log(title = "流程分类", businessType = BusinessType.EXPORT)
@PostMapping("/export")
public void export(@Validated WfCategoryBo bo, HttpServletResponse response) {
List<WfCategoryVo> list = categoryService.queryList(bo);
public void export(@Validated WfCategory category, HttpServletResponse response) {
List<WfCategoryVo> list = categoryService.queryList(category);
ExcelUtil.exportExcel(list, "流程分类", WfCategoryVo.class, response);
}
@@ -86,11 +83,11 @@ public class WfCategoryController extends BaseController {
@Log(title = "流程分类", businessType = BusinessType.INSERT)
@RepeatSubmit()
@PostMapping()
public R<Void> add(@Validated(AddGroup.class) @RequestBody WfCategoryBo categoryBo) {
if (!categoryService.checkCategoryCodeUnique(categoryBo.getCode())) {
return R.fail("新增流程分类'" + categoryBo.getCategoryName() + "'失败,流程编码已存在");
public R<Void> add(@Validated @RequestBody WfCategory category) {
if (!categoryService.checkCategoryCodeUnique(category)) {
return R.fail("新增流程分类'" + category.getCategoryName() + "'失败,流程编码已存在");
}
return toAjax(categoryService.insertCategory(categoryBo));
return toAjax(categoryService.insertCategory(category));
}
/**
@@ -100,11 +97,11 @@ public class WfCategoryController extends BaseController {
@Log(title = "流程分类", businessType = BusinessType.UPDATE)
@RepeatSubmit()
@PutMapping()
public R<Void> edit(@Validated(EditGroup.class) @RequestBody WfCategoryBo categoryBo) {
if (!categoryService.checkCategoryCodeUnique(categoryBo.getCode())) {
return R.fail("修改流程分类'" + categoryBo.getCategoryName() + "'失败,流程编码已存在");
public R<Void> edit(@Validated @RequestBody WfCategory category) {
if (!categoryService.checkCategoryCodeUnique(category)) {
return R.fail("修改流程分类'" + category.getCategoryName() + "'失败,流程编码已存在");
}
return toAjax(categoryService.updateCategory(categoryBo));
return toAjax(categoryService.updateCategory(category));
}
/**

View File

@@ -12,7 +12,7 @@ import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.workflow.domain.bo.WfCategoryBo;
import com.ruoyi.workflow.domain.WfCategory;
import com.ruoyi.workflow.domain.bo.WfModelBo;
import com.ruoyi.workflow.domain.vo.WfCategoryVo;
import com.ruoyi.workflow.domain.vo.WfModelExportVo;
@@ -176,7 +176,7 @@ public class WfModelController extends BaseController {
public void export(WfModelBo modelBo, HttpServletResponse response) {
List<WfModelVo> list = modelService.list(modelBo);
List<WfModelExportVo> listVo = BeanUtil.copyToList(list, WfModelExportVo.class);
List<WfCategoryVo> categoryVos = categoryService.queryList(new WfCategoryBo());
List<WfCategoryVo> categoryVos = categoryService.queryList(new WfCategory());
Map<String, String> categoryMap = categoryVos.stream()
.collect(Collectors.toMap(WfCategoryVo::getCode, WfCategoryVo::getCategoryName));
for (WfModelExportVo exportVo : listVo) {

View File

@@ -7,6 +7,8 @@ import com.ruoyi.common.core.domain.BaseEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
import javax.validation.constraints.NotBlank;
/**
* 流程分类对象 wf_category
*
@@ -28,10 +30,12 @@ public class WfCategory extends BaseEntity {
/**
* 分类名称
*/
@NotBlank(message = "分类名称不能为空")
private String categoryName;
/**
* 分类编码
*/
@NotBlank(message = "分类编码不能为空")
private String code;
/**
* 备注

View File

@@ -1,48 +0,0 @@
package com.ruoyi.workflow.domain.bo;
import com.ruoyi.common.core.domain.BaseEntity;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import lombok.Data;
import lombok.EqualsAndHashCode;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
/**
* 流程分类业务对象
*
* @author KonBAI
* @date 2022-01-15
*/
@Data
@EqualsAndHashCode(callSuper = true)
public class WfCategoryBo extends BaseEntity {
/**
* 分类ID
*/
@NotNull(message = "分类ID不能为空", groups = { EditGroup.class })
private Long categoryId;
/**
* 分类名称
*/
@NotBlank(message = "分类名称不能为空", groups = { AddGroup.class, EditGroup.class })
private String categoryName;
/**
* 分类编码
*/
@NotBlank(message = "分类编码不能为空", groups = { AddGroup.class, EditGroup.class })
private String code;
/**
* 备注
*/
@NotBlank(message = "备注不能为空", groups = { AddGroup.class, EditGroup.class })
private String remark;
}

View File

@@ -2,7 +2,7 @@ package com.ruoyi.workflow.service;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.workflow.domain.bo.WfCategoryBo;
import com.ruoyi.workflow.domain.WfCategory;
import com.ruoyi.workflow.domain.vo.WfCategoryVo;
import java.util.Collection;
@@ -24,27 +24,27 @@ public interface IWfCategoryService {
/**
* 查询列表
*/
TableDataInfo<WfCategoryVo> queryPageList(WfCategoryBo bo, PageQuery pageQuery);
TableDataInfo<WfCategoryVo> queryPageList(WfCategory category, PageQuery pageQuery);
/**
* 查询列表
*/
List<WfCategoryVo> queryList(WfCategoryBo categoryBo);
List<WfCategoryVo> queryList(WfCategory category);
/**
* 新增流程分类
*
* @param categoryBo 流程分类信息
* @param category 流程分类信息
* @return 结果
*/
int insertCategory(WfCategoryBo categoryBo);
int insertCategory(WfCategory category);
/**
* 编辑流程分类
* @param categoryBo 流程分类信息
* @param category 流程分类信息
* @return 结果
*/
int updateCategory(WfCategoryBo categoryBo);
int updateCategory(WfCategory category);
/**
* 校验并删除数据
@@ -57,8 +57,8 @@ public interface IWfCategoryService {
/**
* 校验分类编码是否唯一
*
* @param code 分类编码
* @param category 流程分类
* @return 结果
*/
boolean checkCategoryCodeUnique(String code);
boolean checkCategoryCodeUnique(WfCategory category);
}

View File

@@ -1,6 +1,7 @@
package com.ruoyi.workflow.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@@ -8,7 +9,6 @@ import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.workflow.domain.WfCategory;
import com.ruoyi.workflow.domain.bo.WfCategoryBo;
import com.ruoyi.workflow.domain.vo.WfCategoryVo;
import com.ruoyi.workflow.mapper.WfCategoryMapper;
import com.ruoyi.workflow.service.IWfCategoryService;
@@ -37,34 +37,34 @@ public class WfCategoryServiceImpl implements IWfCategoryService {
}
@Override
public TableDataInfo<WfCategoryVo> queryPageList(WfCategoryBo categoryBo, PageQuery pageQuery) {
LambdaQueryWrapper<WfCategory> lqw = buildQueryWrapper(categoryBo);
public TableDataInfo<WfCategoryVo> queryPageList(WfCategory category, PageQuery pageQuery) {
LambdaQueryWrapper<WfCategory> lqw = buildQueryWrapper(category);
Page<WfCategoryVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
return TableDataInfo.build(result);
}
@Override
public List<WfCategoryVo> queryList(WfCategoryBo categoryBo) {
LambdaQueryWrapper<WfCategory> lqw = buildQueryWrapper(categoryBo);
public List<WfCategoryVo> queryList(WfCategory category) {
LambdaQueryWrapper<WfCategory> lqw = buildQueryWrapper(category);
return baseMapper.selectVoList(lqw);
}
private LambdaQueryWrapper<WfCategory> buildQueryWrapper(WfCategoryBo categoryBo) {
Map<String, Object> params = categoryBo.getParams();
private LambdaQueryWrapper<WfCategory> buildQueryWrapper(WfCategory category) {
Map<String, Object> params = category.getParams();
LambdaQueryWrapper<WfCategory> lqw = Wrappers.lambdaQuery();
lqw.like(StringUtils.isNotBlank(categoryBo.getCategoryName()), WfCategory::getCategoryName, categoryBo.getCategoryName());
lqw.eq(StringUtils.isNotBlank(categoryBo.getCode()), WfCategory::getCode, categoryBo.getCode());
lqw.like(StringUtils.isNotBlank(category.getCategoryName()), WfCategory::getCategoryName, category.getCategoryName());
lqw.eq(StringUtils.isNotBlank(category.getCode()), WfCategory::getCode, category.getCode());
return lqw;
}
@Override
public int insertCategory(WfCategoryBo categoryBo) {
public int insertCategory(WfCategory categoryBo) {
WfCategory add = BeanUtil.toBean(categoryBo, WfCategory.class);
return baseMapper.insert(add);
}
@Override
public int updateCategory(WfCategoryBo categoryBo) {
public int updateCategory(WfCategory categoryBo) {
WfCategory update = BeanUtil.toBean(categoryBo, WfCategory.class);
return baseMapper.updateById(update);
}
@@ -80,12 +80,14 @@ public class WfCategoryServiceImpl implements IWfCategoryService {
/**
* 校验分类编码是否唯一
*
* @param code 分类编码
* @param category 流程分类
* @return 结果
*/
@Override
public boolean checkCategoryCodeUnique(String code) {
boolean exist = baseMapper.exists(new LambdaQueryWrapper<WfCategory>().eq(WfCategory::getCode, code));
public boolean checkCategoryCodeUnique(WfCategory category) {
boolean exist = baseMapper.exists(new LambdaQueryWrapper<WfCategory>()
.eq(WfCategory::getCode, category.getCode())
.ne(ObjectUtil.isNotNull(category.getCategoryId()), WfCategory::getCategoryId, category.getCategoryId()));
return !exist;
}
}

View File

@@ -164,18 +164,12 @@ export default {
form: {},
// 表单校验
rules: {
categoryId: [
{ required: true, message: "分类ID不能为空", trigger: "blur" }
],
categoryName: [
{ required: true, message: "分类名称不能为空", trigger: "blur" }
],
code: [
{ required: true, message: "分类编码不能为空", trigger: "blur" }
],
remark: [
{ required: true, message: "备注不能为空", trigger: "blur" }
],
]
}
};
},