Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package cn.iocoder.yudao.module.bpm.controller.admin.base.dept;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

@Schema(description = "部门精简信息 VO")
@Data
public class DeptSimpleBaseVO {
@Schema(description = "部门编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
private Long id;
@Schema(description = "部门名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋艿")
private String name;
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import cn.iocoder.yudao.module.bpm.service.definition.BpmFormService;
import cn.iocoder.yudao.module.bpm.service.definition.BpmModelService;
import cn.iocoder.yudao.module.bpm.service.definition.BpmProcessDefinitionService;
import cn.iocoder.yudao.module.system.api.dept.DeptApi;
import cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO;
import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
import io.swagger.v3.oas.annotations.Operation;
Expand Down Expand Up @@ -53,6 +55,8 @@ public class BpmModelController {

@Resource
private AdminUserApi adminUserApi;
@Resource
private DeptApi deptApi;

@GetMapping("/list")
@Operation(summary = "获得模型分页")
Expand Down Expand Up @@ -85,8 +89,14 @@ public CommonResult<List<BpmModelRespVO>> getModelList(@RequestParam(value = "na
return metaInfo != null ? metaInfo.getStartUserIds().stream() : Stream.empty();
});
Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(userIds);
// 获得 Dept Map
Set<Long> deptIds = convertSetByFlatMap(list, model -> {
BpmModelMetaInfoVO metaInfo = BpmModelConvert.INSTANCE.parseMetaInfo(model);
return metaInfo != null && metaInfo.getStartDeptIds() != null ? metaInfo.getStartDeptIds().stream() : Stream.empty();
});
Map<Long, DeptRespDTO> deptMap = deptApi.getDeptMap(deptIds);
return success(BpmModelConvert.INSTANCE.buildModelList(list,
formMap, categoryMap, deploymentMap, processDefinitionMap, userMap));
formMap, categoryMap, deploymentMap, processDefinitionMap, userMap, deptMap));
}

@GetMapping("/get")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ public class BpmModelMetaInfoVO {
@Schema(description = "可发起用户编号数组", example = "[1,2,3]")
private List<Long> startUserIds;

@Schema(description = "可发起部门编号数组")
private List<Long> startDeptIds;

@Schema(description = "可管理用户编号数组", requiredMode = Schema.RequiredMode.REQUIRED, example = "[2,4,6]")
@NotEmpty(message = "可管理用户编号数组不能为空")
private List<Long> managerUserIds;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model;

import cn.iocoder.yudao.module.bpm.controller.admin.base.dept.DeptSimpleBaseVO;
import cn.iocoder.yudao.module.bpm.controller.admin.base.user.UserSimpleBaseVO;
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.simple.BpmSimpleModelNodeVO;
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.process.BpmProcessDefinitionRespVO;
Expand Down Expand Up @@ -39,6 +40,9 @@ public class BpmModelRespVO extends BpmModelMetaInfoVO {
@Schema(description = "可发起的用户数组")
private List<UserSimpleBaseVO> startUsers;

@Schema(description = "可发起的部门数组")
private List<DeptSimpleBaseVO> startDepts;

@Schema(description = "BPMN XML")
private String bpmnXml;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import cn.iocoder.yudao.framework.common.util.date.DateUtils;
import cn.iocoder.yudao.framework.common.util.json.JsonUtils;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.bpm.controller.admin.base.dept.DeptSimpleBaseVO;
import cn.iocoder.yudao.module.bpm.controller.admin.base.user.UserSimpleBaseVO;
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.BpmModelMetaInfoVO;
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.BpmModelRespVO;
Expand All @@ -13,6 +14,7 @@
import cn.iocoder.yudao.module.bpm.dal.dataobject.definition.BpmCategoryDO;
import cn.iocoder.yudao.module.bpm.dal.dataobject.definition.BpmFormDO;
import cn.iocoder.yudao.module.bpm.framework.flowable.core.util.BpmnModelUtils;
import cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO;
import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
import org.flowable.common.engine.impl.db.SuspensionState;
import org.flowable.engine.repository.Deployment;
Expand Down Expand Up @@ -43,7 +45,8 @@ default List<BpmModelRespVO> buildModelList(List<Model> list,
Map<String, BpmCategoryDO> categoryMap,
Map<String, Deployment> deploymentMap,
Map<String, ProcessDefinition> processDefinitionMap,
Map<Long, AdminUserRespDTO> userMap) {
Map<Long, AdminUserRespDTO> userMap,
Map<Long, DeptRespDTO> deptMap) {
List<BpmModelRespVO> result = convertList(list, model -> {
BpmModelMetaInfoVO metaInfo = parseMetaInfo(model);
BpmFormDO form = metaInfo != null ? formMap.get(metaInfo.getFormId()) : null;
Expand All @@ -52,7 +55,8 @@ default List<BpmModelRespVO> buildModelList(List<Model> list,
ProcessDefinition processDefinition = model.getDeploymentId() != null ?
processDefinitionMap.get(model.getDeploymentId()) : null;
List<AdminUserRespDTO> startUsers = metaInfo != null ? convertList(metaInfo.getStartUserIds(), userMap::get) : null;
return buildModel0(model, metaInfo, form, category, deployment, processDefinition, startUsers);
List<DeptRespDTO> startDepts = metaInfo != null ? convertList(metaInfo.getStartDeptIds(), deptMap::get) : null;
return buildModel0(model, metaInfo, form, category, deployment, processDefinition, startUsers, startDepts);
});
// 排序
result.sort(Comparator.comparing(BpmModelMetaInfoVO::getSort));
Expand All @@ -61,7 +65,7 @@ default List<BpmModelRespVO> buildModelList(List<Model> list,

default BpmModelRespVO buildModel(Model model, byte[] bpmnBytes, BpmSimpleModelNodeVO simpleModel) {
BpmModelMetaInfoVO metaInfo = parseMetaInfo(model);
BpmModelRespVO modelVO = buildModel0(model, metaInfo, null, null, null, null, null);
BpmModelRespVO modelVO = buildModel0(model, metaInfo, null, null, null, null, null, null);
if (ArrayUtil.isNotEmpty(bpmnBytes)) {
modelVO.setBpmnXml(BpmnModelUtils.getBpmnXml(bpmnBytes));
}
Expand All @@ -72,7 +76,8 @@ default BpmModelRespVO buildModel(Model model, byte[] bpmnBytes, BpmSimpleModelN
default BpmModelRespVO buildModel0(Model model,
BpmModelMetaInfoVO metaInfo, BpmFormDO form, BpmCategoryDO category,
Deployment deployment, ProcessDefinition processDefinition,
List<AdminUserRespDTO> startUsers) {
List<AdminUserRespDTO> startUsers,
List<DeptRespDTO> startDepts) {
BpmModelRespVO modelRespVO = new BpmModelRespVO().setId(model.getId()).setName(model.getName())
.setKey(model.getKey()).setCategory(model.getCategory())
.setCreateTime(DateUtils.of(model.getCreateTime()));
Expand All @@ -96,6 +101,8 @@ default BpmModelRespVO buildModel0(Model model,
}
// User
modelRespVO.setStartUsers(BeanUtils.toBean(startUsers, UserSimpleBaseVO.class));
// Dept
modelRespVO.setStartDepts(BeanUtils.toBean(startDepts, DeptSimpleBaseVO.class));
return modelRespVO;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,14 @@ public class BpmProcessDefinitionInfoDO extends BaseDO {
@TableField(typeHandler = LongListTypeHandler.class) // 为了可以使用 find_in_set 进行过滤
private List<Long> startUserIds;

/**
* 可发起部门编号数组
*
* 关联 {@link AdminUserRespDTO#getId()} 字段的数组
*/
@TableField(typeHandler = LongListTypeHandler.class)
private List<Long> startDeptIds;

/**
* 可管理用户编号数组
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import cn.iocoder.yudao.module.bpm.dal.mysql.definition.BpmProcessDefinitionInfoMapper;
import cn.iocoder.yudao.module.bpm.framework.flowable.core.enums.BpmnModelConstants;
import cn.iocoder.yudao.module.bpm.framework.flowable.core.util.FlowableUtils;
import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.flowable.bpmn.model.BpmnModel;
Expand Down Expand Up @@ -49,6 +51,8 @@ public class BpmProcessDefinitionServiceImpl implements BpmProcessDefinitionServ

@Resource
private BpmProcessDefinitionInfoMapper processDefinitionMapper;
@Resource
private AdminUserApi adminUserApi;

@Override
public ProcessDefinition getProcessDefinition(String id) {
Expand Down Expand Up @@ -88,12 +92,23 @@ public boolean canUserStartProcessDefinition(BpmProcessDefinitionInfoDO processD
if (processDefinition == null) {
return false;
}
// 为空,则所有人都可以发起
if (CollUtil.isEmpty(processDefinition.getStartUserIds())) {
return true;

// 获取用户所在部门
AdminUserRespDTO user = adminUserApi.getUser(userId);
Long userDeptId = user != null ? user.getDeptId() : null;

// 校验用户是否在允许发起的用户列表中
if (!CollUtil.isEmpty(processDefinition.getStartUserIds())) {
return processDefinition.getStartUserIds().contains(userId);
}

// 校验用户是否在允许发起的部门列表中
if (!CollUtil.isEmpty(processDefinition.getStartDeptIds()) && userDeptId != null) {
return processDefinition.getStartDeptIds().contains(userDeptId);
}
// 不为空,则需要存在里面
return processDefinition.getStartUserIds().contains(userId);

// 都为空,则所有人都可以发起
return true;
}

@Override
Expand Down