Commit 2809254a07f66446e4fb1c50a25f3b793b2d3354
1 parent
fe651b42
BPM 模型重构 7:增加任务分配规则的列表 UI 界面(增加部门的规则配置)
Showing
5 changed files
with
97 additions
and
4 deletions
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/definition/impl/BpmTaskAssignRuleServiceImpl.java
| @@ -12,8 +12,10 @@ import cn.iocoder.yudao.adminserver.modules.bpm.enums.definition.BpmTaskAssignRu | @@ -12,8 +12,10 @@ import cn.iocoder.yudao.adminserver.modules.bpm.enums.definition.BpmTaskAssignRu | ||
| 12 | import cn.iocoder.yudao.adminserver.modules.bpm.service.definition.BpmModelService; | 12 | import cn.iocoder.yudao.adminserver.modules.bpm.service.definition.BpmModelService; |
| 13 | import cn.iocoder.yudao.adminserver.modules.bpm.service.definition.BpmProcessDefinitionService; | 13 | import cn.iocoder.yudao.adminserver.modules.bpm.service.definition.BpmProcessDefinitionService; |
| 14 | import cn.iocoder.yudao.adminserver.modules.bpm.service.definition.BpmTaskAssignRuleService; | 14 | import cn.iocoder.yudao.adminserver.modules.bpm.service.definition.BpmTaskAssignRuleService; |
| 15 | +import cn.iocoder.yudao.adminserver.modules.system.service.dept.SysDeptService; | ||
| 15 | import cn.iocoder.yudao.adminserver.modules.system.service.permission.SysRoleService; | 16 | import cn.iocoder.yudao.adminserver.modules.system.service.permission.SysRoleService; |
| 16 | import cn.iocoder.yudao.framework.activiti.core.util.ActivitiUtils; | 17 | import cn.iocoder.yudao.framework.activiti.core.util.ActivitiUtils; |
| 18 | +import cn.iocoder.yudao.framework.common.util.object.ObjectUtils; | ||
| 17 | import lombok.extern.slf4j.Slf4j; | 19 | import lombok.extern.slf4j.Slf4j; |
| 18 | import org.activiti.bpmn.model.BpmnModel; | 20 | import org.activiti.bpmn.model.BpmnModel; |
| 19 | import org.activiti.bpmn.model.UserTask; | 21 | import org.activiti.bpmn.model.UserTask; |
| @@ -51,6 +53,8 @@ public class BpmTaskAssignRuleServiceImpl implements BpmTaskAssignRuleService { | @@ -51,6 +53,8 @@ public class BpmTaskAssignRuleServiceImpl implements BpmTaskAssignRuleService { | ||
| 51 | private BpmProcessDefinitionService processDefinitionService; | 53 | private BpmProcessDefinitionService processDefinitionService; |
| 52 | @Resource | 54 | @Resource |
| 53 | private SysRoleService roleService; | 55 | private SysRoleService roleService; |
| 56 | + @Resource | ||
| 57 | + private SysDeptService deptService; | ||
| 54 | 58 | ||
| 55 | @Override | 59 | @Override |
| 56 | public List<BpmTaskAssignRuleDO> getTaskAssignRuleListByProcessDefinitionId(String processDefinitionId, | 60 | public List<BpmTaskAssignRuleDO> getTaskAssignRuleListByProcessDefinitionId(String processDefinitionId, |
| @@ -141,7 +145,9 @@ public class BpmTaskAssignRuleServiceImpl implements BpmTaskAssignRuleService { | @@ -141,7 +145,9 @@ public class BpmTaskAssignRuleServiceImpl implements BpmTaskAssignRuleService { | ||
| 141 | private void validTaskAssignRuleOptions(Integer type, Set<Long> options) { | 145 | private void validTaskAssignRuleOptions(Integer type, Set<Long> options) { |
| 142 | if (Objects.equals(type, BpmTaskAssignRuleTypeEnum.ROLE.getType())) { | 146 | if (Objects.equals(type, BpmTaskAssignRuleTypeEnum.ROLE.getType())) { |
| 143 | roleService.validRoles(options); | 147 | roleService.validRoles(options); |
| 144 | - return; | 148 | + } else if (ObjectUtils.equalsAny(BpmTaskAssignRuleTypeEnum.DEPT.getType(), |
| 149 | + BpmTaskAssignRuleTypeEnum.DEPT_LEADER.getType())) { | ||
| 150 | + deptService.validDepts(options); | ||
| 145 | } | 151 | } |
| 146 | // TODO 其它的 | 152 | // TODO 其它的 |
| 147 | } | 153 | } |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/dept/SysDeptService.java
| @@ -93,4 +93,13 @@ public interface SysDeptService { | @@ -93,4 +93,13 @@ public interface SysDeptService { | ||
| 93 | */ | 93 | */ |
| 94 | List<SysDeptDO> getDeptsByParentIdFromCache(Long parentId, boolean recursive); | 94 | List<SysDeptDO> getDeptsByParentIdFromCache(Long parentId, boolean recursive); |
| 95 | 95 | ||
| 96 | + /** | ||
| 97 | + * 校验部门们是否有效。如下情况,视为无效: | ||
| 98 | + * 1. 部门编号不存在 | ||
| 99 | + * 2. 部门被禁用 | ||
| 100 | + * | ||
| 101 | + * @param ids 角色编号数组 | ||
| 102 | + */ | ||
| 103 | + void validDepts(Collection<Long> ids); | ||
| 104 | + | ||
| 96 | } | 105 | } |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/dept/impl/SysDeptServiceImpl.java
| 1 | package cn.iocoder.yudao.adminserver.modules.system.service.dept.impl; | 1 | package cn.iocoder.yudao.adminserver.modules.system.service.dept.impl; |
| 2 | 2 | ||
| 3 | import cn.hutool.core.collection.CollUtil; | 3 | import cn.hutool.core.collection.CollUtil; |
| 4 | +import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.permission.SysRoleDO; | ||
| 4 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | 5 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; |
| 5 | import cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil; | 6 | import cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil; |
| 7 | +import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; | ||
| 6 | import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; | 8 | import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; |
| 7 | import cn.iocoder.yudao.adminserver.modules.system.controller.dept.vo.dept.SysDeptCreateReqVO; | 9 | import cn.iocoder.yudao.adminserver.modules.system.controller.dept.vo.dept.SysDeptCreateReqVO; |
| 8 | import cn.iocoder.yudao.adminserver.modules.system.controller.dept.vo.dept.SysDeptListReqVO; | 10 | import cn.iocoder.yudao.adminserver.modules.system.controller.dept.vo.dept.SysDeptListReqVO; |
| @@ -26,6 +28,7 @@ import javax.annotation.Resource; | @@ -26,6 +28,7 @@ import javax.annotation.Resource; | ||
| 26 | import java.util.*; | 28 | import java.util.*; |
| 27 | 29 | ||
| 28 | import static cn.iocoder.yudao.adminserver.modules.system.enums.SysErrorCodeConstants.*; | 30 | import static cn.iocoder.yudao.adminserver.modules.system.enums.SysErrorCodeConstants.*; |
| 31 | +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | ||
| 29 | 32 | ||
| 30 | /** | 33 | /** |
| 31 | * 部门 Service 实现类 | 34 | * 部门 Service 实现类 |
| @@ -180,6 +183,26 @@ public class SysDeptServiceImpl implements SysDeptService { | @@ -180,6 +183,26 @@ public class SysDeptServiceImpl implements SysDeptService { | ||
| 180 | return result; | 183 | return result; |
| 181 | } | 184 | } |
| 182 | 185 | ||
| 186 | + @Override | ||
| 187 | + public void validDepts(Collection<Long> ids) { | ||
| 188 | + if (CollUtil.isEmpty(ids)) { | ||
| 189 | + return; | ||
| 190 | + } | ||
| 191 | + // 获得科室信息 | ||
| 192 | + List<SysDeptDO> depts = deptMapper.selectBatchIds(ids); | ||
| 193 | + Map<Long, SysDeptDO> deptMap = CollectionUtils.convertMap(depts, SysDeptDO::getId); | ||
| 194 | + // 校验 | ||
| 195 | + ids.forEach(id -> { | ||
| 196 | + SysDeptDO dept = deptMap.get(id); | ||
| 197 | + if (dept == null) { | ||
| 198 | + throw exception(DEPT_NOT_FOUND); | ||
| 199 | + } | ||
| 200 | + if (!CommonStatusEnum.ENABLE.getStatus().equals(dept.getStatus())) { | ||
| 201 | + throw exception(DEPT_NOT_ENABLE, dept.getName()); | ||
| 202 | + } | ||
| 203 | + }); | ||
| 204 | + } | ||
| 205 | + | ||
| 183 | /** | 206 | /** |
| 184 | * 递归获取所有的子部门,添加到 result 结果 | 207 | * 递归获取所有的子部门,添加到 result 结果 |
| 185 | * | 208 | * |
yudao-admin-ui/src/views/bpm/model/index.vue
| @@ -245,6 +245,10 @@ | @@ -245,6 +245,10 @@ | ||
| 245 | <el-option v-for="item in taskAssignRule.roleOptions" :key="parseInt(item.id)" :label="item.name" :value="parseInt(item.id)" /> | 245 | <el-option v-for="item in taskAssignRule.roleOptions" :key="parseInt(item.id)" :label="item.name" :value="parseInt(item.id)" /> |
| 246 | </el-select> | 246 | </el-select> |
| 247 | </el-form-item> | 247 | </el-form-item> |
| 248 | + <el-form-item v-if="taskAssignRule.form.type === 20 || taskAssignRule.form.type === 21" label="指定部门" prop="deptIds"> | ||
| 249 | + <treeselect v-model="taskAssignRule.form.deptIds" :options="taskAssignRule.deptTreeOptions" multiple flat :defaultExpandLevel="3" | ||
| 250 | + placeholder="请选择指定部门" :normalizer="normalizer"/> | ||
| 251 | + </el-form-item> | ||
| 248 | </el-form> | 252 | </el-form> |
| 249 | <div slot="footer" class="dialog-footer"> | 253 | <div slot="footer" class="dialog-footer"> |
| 250 | <el-button type="primary" @click="submitAssignRuleForm">确 定</el-button> | 254 | <el-button type="primary" @click="submitAssignRuleForm">确 定</el-button> |
| @@ -271,11 +275,16 @@ import Parser from '@/components/parser/Parser' | @@ -271,11 +275,16 @@ import Parser from '@/components/parser/Parser' | ||
| 271 | import {getBaseHeader} from "@/utils/request"; | 275 | import {getBaseHeader} from "@/utils/request"; |
| 272 | import {createTaskAssignRule, getTaskAssignRuleList, updateTaskAssignRule} from "@/api/bpm/taskAssignRule"; | 276 | import {createTaskAssignRule, getTaskAssignRuleList, updateTaskAssignRule} from "@/api/bpm/taskAssignRule"; |
| 273 | import {listSimpleRoles} from "@/api/system/role"; | 277 | import {listSimpleRoles} from "@/api/system/role"; |
| 278 | +import {listSimpleDepts} from "@/api/system/dept"; | ||
| 279 | + | ||
| 280 | +import Treeselect from "@riophae/vue-treeselect"; | ||
| 281 | +import "@riophae/vue-treeselect/dist/vue-treeselect.css"; | ||
| 274 | 282 | ||
| 275 | export default { | 283 | export default { |
| 276 | name: "model", | 284 | name: "model", |
| 277 | components: { | 285 | components: { |
| 278 | - Parser | 286 | + Parser, |
| 287 | + Treeselect | ||
| 279 | }, | 288 | }, |
| 280 | data() { | 289 | data() { |
| 281 | return { | 290 | return { |
| @@ -331,9 +340,12 @@ export default { | @@ -331,9 +340,12 @@ export default { | ||
| 331 | rules: { // 表单校验规则 | 340 | rules: { // 表单校验规则 |
| 332 | type: [{ required: true, message: "规则类型不能为空", trigger: "change" }], | 341 | type: [{ required: true, message: "规则类型不能为空", trigger: "change" }], |
| 333 | roleIds: [{required: true, message: "指定角色不能为空", trigger: "change" }], | 342 | roleIds: [{required: true, message: "指定角色不能为空", trigger: "change" }], |
| 343 | + deptIds: [{required: true, message: "指定部门不能为空", trigger: "change" }], | ||
| 334 | }, | 344 | }, |
| 335 | // 各种下拉框 | 345 | // 各种下拉框 |
| 336 | roleOptions: [], | 346 | roleOptions: [], |
| 347 | + deptOptions: [], | ||
| 348 | + deptTreeOptions: [], | ||
| 337 | }, | 349 | }, |
| 338 | 350 | ||
| 339 | // 流程导入参数 | 351 | // 流程导入参数 |
| @@ -460,9 +472,18 @@ export default { | @@ -460,9 +472,18 @@ export default { | ||
| 460 | } | 472 | } |
| 461 | // 创建 | 473 | // 创建 |
| 462 | createModel(this.form).then(response => { | 474 | createModel(this.form).then(response => { |
| 463 | - this.msgSuccess("新建流程成功"); | ||
| 464 | this.open = false; | 475 | this.open = false; |
| 465 | this.getList(); | 476 | this.getList(); |
| 477 | + this.$alert('<strong>新建模型成功!</strong>后续需要执行如下 4 个步骤:' + | ||
| 478 | + '<div>1. 点击【修改流程】按钮,配置流程的分类、表单信息</div>' + | ||
| 479 | + '<div>2. 点击【设计流程】按钮,绘制流程图</div>' + | ||
| 480 | + '<div>3. 点击【分配规则】按钮,设置每个用户任务的审批人</div>' + | ||
| 481 | + '<div>4. 点击【发布流程】按钮,完成流程的最终发布</div>' + | ||
| 482 | + '另外,每次流程修改后,都需要点击【发布流程】按钮,才能正式生效!!!', | ||
| 483 | + '重要提示', { | ||
| 484 | + dangerouslyUseHTMLString: true, | ||
| 485 | + type: 'success' | ||
| 486 | + }); | ||
| 466 | }); | 487 | }); |
| 467 | }); | 488 | }); |
| 468 | }, | 489 | }, |
| @@ -597,9 +618,16 @@ export default { | @@ -597,9 +618,16 @@ export default { | ||
| 597 | // 获得角色列表 | 618 | // 获得角色列表 |
| 598 | this.taskAssignRule.roleOptions = []; | 619 | this.taskAssignRule.roleOptions = []; |
| 599 | listSimpleRoles().then(response => { | 620 | listSimpleRoles().then(response => { |
| 600 | - // 处理 roleOptions 参数 | ||
| 601 | this.taskAssignRule.roleOptions.push(...response.data); | 621 | this.taskAssignRule.roleOptions.push(...response.data); |
| 602 | }); | 622 | }); |
| 623 | + // 获得部门列表 | ||
| 624 | + this.taskAssignRule.deptOptions = []; | ||
| 625 | + this.taskAssignRule.deptTreeOptions = []; | ||
| 626 | + listSimpleDepts().then(response => { | ||
| 627 | + // 处理 roleOptions 参数 | ||
| 628 | + this.taskAssignRule.deptOptions.push(...response.data); | ||
| 629 | + this.taskAssignRule.deptTreeOptions.push(...this.handleTree(response.data, "id")); | ||
| 630 | + }); | ||
| 603 | }, | 631 | }, |
| 604 | /** 处理修改任务分配规则的按钮操作 */ | 632 | /** 处理修改任务分配规则的按钮操作 */ |
| 605 | handleUpdateTaskAssignRule(row) { | 633 | handleUpdateTaskAssignRule(row) { |
| @@ -610,10 +638,13 @@ export default { | @@ -610,10 +638,13 @@ export default { | ||
| 610 | ...row, | 638 | ...row, |
| 611 | options: [], | 639 | options: [], |
| 612 | roleIds: [], | 640 | roleIds: [], |
| 641 | + deptIds: [], | ||
| 613 | }; | 642 | }; |
| 614 | // 将 options 赋值到对应的 roleIds 等选项 | 643 | // 将 options 赋值到对应的 roleIds 等选项 |
| 615 | if (row.type === 10) { | 644 | if (row.type === 10) { |
| 616 | this.taskAssignRule.form.roleIds.push(...row.options); | 645 | this.taskAssignRule.form.roleIds.push(...row.options); |
| 646 | + } else if (row.type === 20 || row.type === 21) { | ||
| 647 | + this.taskAssignRule.form.deptIds.push(...row.options); | ||
| 617 | } | 648 | } |
| 618 | this.taskAssignRule.open = true; | 649 | this.taskAssignRule.open = true; |
| 619 | }, | 650 | }, |
| @@ -629,8 +660,11 @@ export default { | @@ -629,8 +660,11 @@ export default { | ||
| 629 | // 将 roleIds 等选项赋值到 options 中 | 660 | // 将 roleIds 等选项赋值到 options 中 |
| 630 | if (form.type === 10) { | 661 | if (form.type === 10) { |
| 631 | form.options = form.roleIds; | 662 | form.options = form.roleIds; |
| 663 | + } else if (form.type === 20 || form.type === 21) { | ||
| 664 | + form.options = form.deptIds; | ||
| 632 | } | 665 | } |
| 633 | form.roleIds = undefined; | 666 | form.roleIds = undefined; |
| 667 | + form.deptIds = undefined; | ||
| 634 | // 新增 | 668 | // 新增 |
| 635 | if (!form.id) { | 669 | if (!form.id) { |
| 636 | form.modelId = this.taskAssignRule.row.id // 模型编号 | 670 | form.modelId = this.taskAssignRule.row.id // 模型编号 |
| @@ -668,8 +702,22 @@ export default { | @@ -668,8 +702,22 @@ export default { | ||
| 668 | return roleOption.name; | 702 | return roleOption.name; |
| 669 | } | 703 | } |
| 670 | } | 704 | } |
| 705 | + } else if (type === 20 || type === 21) { | ||
| 706 | + for (const deptOption of this.taskAssignRule.deptOptions) { | ||
| 707 | + if (deptOption.id === option) { | ||
| 708 | + return deptOption.name; | ||
| 709 | + } | ||
| 710 | + } | ||
| 671 | } | 711 | } |
| 672 | return '未知(' + option + ')'; | 712 | return '未知(' + option + ')'; |
| 713 | + }, | ||
| 714 | + // 格式化部门的下拉框 | ||
| 715 | + normalizer(node) { | ||
| 716 | + return { | ||
| 717 | + id: node.id, | ||
| 718 | + label: node.name, | ||
| 719 | + children: node.children | ||
| 720 | + } | ||
| 673 | } | 721 | } |
| 674 | } | 722 | } |
| 675 | }; | 723 | }; |
yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/object/ObjectUtils.java
| 1 | package cn.iocoder.yudao.framework.common.util.object; | 1 | package cn.iocoder.yudao.framework.common.util.object; |
| 2 | 2 | ||
| 3 | +import cn.hutool.core.util.ArrayUtil; | ||
| 3 | import cn.hutool.core.util.ObjectUtil; | 4 | import cn.hutool.core.util.ObjectUtil; |
| 4 | import cn.hutool.core.util.ReflectUtil; | 5 | import cn.hutool.core.util.ReflectUtil; |
| 5 | 6 | ||
| 6 | import java.lang.reflect.Field; | 7 | import java.lang.reflect.Field; |
| 8 | +import java.util.Arrays; | ||
| 9 | +import java.util.Objects; | ||
| 7 | import java.util.function.Consumer; | 10 | import java.util.function.Consumer; |
| 8 | 11 | ||
| 9 | /** | 12 | /** |
| @@ -53,4 +56,8 @@ public class ObjectUtils { | @@ -53,4 +56,8 @@ public class ObjectUtils { | ||
| 53 | return null; | 56 | return null; |
| 54 | } | 57 | } |
| 55 | 58 | ||
| 59 | + public static <T> boolean equalsAny(T obj, T... array) { | ||
| 60 | + return Arrays.asList(array).contains(obj); | ||
| 61 | + } | ||
| 62 | + | ||
| 56 | } | 63 | } |