Skip to content

Commit

Permalink
Merge branch 'master-jdk17' of https://gitee.com/zhijiantianya/yudao-…
Browse files Browse the repository at this point in the history
…cloud

# Conflicts:
#	yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/controller/admin/definition/vo/model/BpmModelSaveReqVO.java
#	yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmProcessInstanceServiceImpl.java
#	yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageUserService.java
#	yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeCouponOrderHandler.java
#	yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/point/MemberPointRecordServiceImpl.java
  • Loading branch information
YunaiV committed Dec 27, 2024
2 parents 527a635 + e5c036a commit 7c3dacc
Show file tree
Hide file tree
Showing 43 changed files with 341 additions and 100 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package cn.iocoder.yudao.framework.common.pojo;

import cn.hutool.core.lang.Assert;
import cn.iocoder.yudao.framework.common.exception.ErrorCode;
import cn.iocoder.yudao.framework.common.exception.ServiceException;
import cn.iocoder.yudao.framework.common.exception.enums.GlobalErrorCodeConstants;
import cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;
import org.springframework.util.Assert;

import java.io.Serializable;
import java.util.Objects;
Expand Down Expand Up @@ -41,21 +42,29 @@ public class CommonResult<T> implements Serializable {
* 因为 A 方法返回的 CommonResult 对象,不满足调用其的 B 方法的返回,所以需要进行转换。
*
* @param result 传入的 result 对象
* @param <T> 返回的泛型
* @param <T> 返回的泛型
* @return 新的 CommonResult 对象
*/
public static <T> CommonResult<T> error(CommonResult<?> result) {
return error(result.getCode(), result.getMsg());
}

public static <T> CommonResult<T> error(Integer code, String message) {
Assert.isTrue(!GlobalErrorCodeConstants.SUCCESS.getCode().equals(code), "code 必须是错误的!");
Assert.notEquals(GlobalErrorCodeConstants.SUCCESS.getCode(), code, "code 必须是错误的!");
CommonResult<T> result = new CommonResult<>();
result.code = code;
result.msg = message;
return result;
}

public static <T> CommonResult<T> error(ErrorCode errorCode, Object... params) {
Assert.notEquals(GlobalErrorCodeConstants.SUCCESS.getCode(), errorCode.getCode(), "code 必须是错误的!");
CommonResult<T> result = new CommonResult<>();
result.code = errorCode.getCode();
result.msg = ServiceExceptionUtil.doFormat(errorCode.getCode(), errorCode.getMsg(), params);
return result;
}

public static <T> CommonResult<T> error(ErrorCode errorCode) {
return error(errorCode.getCode(), errorCode.getMsg());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ public CommonResult<BpmModelRespVO> getModel(@RequestParam("id") String id) {
return null;
}
byte[] bpmnBytes = modelService.getModelBpmnXML(id);
return success(BpmModelConvert.INSTANCE.buildModel(model, bpmnBytes));
BpmSimpleModelNodeVO simpleModel = modelService.getSimpleModel(id);
return success(BpmModelConvert.INSTANCE.buildModel(model, bpmnBytes, simpleModel));
}

@PostMapping("/create")
Expand All @@ -109,7 +110,6 @@ public CommonResult<String> createModel(@Valid @RequestBody BpmModelSaveReqVO cr
return success(modelService.createModel(createRetVO));
}


@PutMapping("/update")
@Operation(summary = "修改模型")
@PreAuthorize("@ss.hasPermission('bpm:model:update')")
Expand Down Expand Up @@ -143,6 +143,7 @@ public CommonResult<Boolean> updateModelState(@Valid @RequestBody BpmModelUpdate
return success(true);
}

@Deprecated
@PutMapping("/update-bpmn")
@Operation(summary = "修改模型的 BPMN")
@PreAuthorize("@ss.hasPermission('bpm:model:update')")
Expand All @@ -169,6 +170,7 @@ public CommonResult<BpmSimpleModelNodeVO> getSimpleModel(@RequestParam("id") Str
return success(modelService.getSimpleModel(modelId));
}

@Deprecated
@PostMapping("/simple/update")
@Operation(summary = "保存仿钉钉流程设计模型")
@PreAuthorize("@ss.hasPermission('bpm:model:update')")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model;

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;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
Expand Down Expand Up @@ -35,12 +36,15 @@ public class BpmModelRespVO extends BpmModelMetaInfoVO {
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
private LocalDateTime createTime;

@Schema(description = "BPMN XML", requiredMode = Schema.RequiredMode.REQUIRED)
private String bpmnXml;

@Schema(description = "可发起的用户数组")
private List<UserSimpleBaseVO> startUsers;

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

@Schema(description = "仿钉钉流程设计模型对象")
private BpmSimpleModelNodeVO simpleModel;

/**
* 最新部署的流程定义
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model;

import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.simple.BpmSimpleModelNodeVO;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotEmpty;
import lombok.Data;

import javax.validation.constraints.NotEmpty;

@Schema(description = "管理后台 - 流程模型的保存 Request VO")
@Data
public class BpmModelSaveReqVO extends BpmModelMetaInfoVO {
Expand All @@ -23,4 +24,11 @@ public class BpmModelSaveReqVO extends BpmModelMetaInfoVO {
@Schema(description = "流程分类", example = "1")
private String category;

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

@Schema(description = "仿钉钉流程设计模型对象")
@Valid
private BpmSimpleModelNodeVO simpleModel;

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ public class BpmTaskPageReqVO extends PageParam {
@Schema(description = "流程任务名", example = "芋道")
private String name;

@Schema(description = "流程分类", example = "1")
private String category;

@Schema(description = "创建时间")
@DateTimeFormat(pattern = DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private LocalDateTime[] createTime;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.BpmModelMetaInfoVO;
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.BpmModelRespVO;
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.BpmModelSaveReqVO;
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;
import cn.iocoder.yudao.module.bpm.dal.dataobject.definition.BpmCategoryDO;
import cn.iocoder.yudao.module.bpm.dal.dataobject.definition.BpmFormDO;
Expand Down Expand Up @@ -58,12 +59,13 @@ default List<BpmModelRespVO> buildModelList(List<Model> list,
return result;
}

default BpmModelRespVO buildModel(Model model, byte[] bpmnBytes) {
default BpmModelRespVO buildModel(Model model, byte[] bpmnBytes, BpmSimpleModelNodeVO simpleModel) {
BpmModelMetaInfoVO metaInfo = parseMetaInfo(model);
BpmModelRespVO modelVO = buildModel0(model, metaInfo, null, null, null, null, null);
if (ArrayUtil.isNotEmpty(bpmnBytes)) {
modelVO.setBpmnXml(BpmnModelUtils.getBpmnXml(bpmnBytes));
}
modelVO.setSimpleModel(simpleModel);
return modelVO;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,18 @@ default List<BpmTaskRespVO> buildTaskListByParentTaskId(List<Task> taskList,
}

default BpmTaskRespVO buildTodoTask(Task todoTask, List<Task> childrenTasks,
Map<Integer, BpmTaskRespVO.OperationButtonSetting> buttonsSetting) {
return BeanUtils.toBean(todoTask, BpmTaskRespVO.class)
Map<Integer, BpmTaskRespVO.OperationButtonSetting> buttonsSetting,
BpmFormDO form) {
BpmTaskRespVO bpmTaskRespVO = BeanUtils.toBean(todoTask, BpmTaskRespVO.class)
.setStatus(FlowableUtils.getTaskStatus(todoTask)).setReason(FlowableUtils.getTaskReason(todoTask))
.setButtonsSetting(buttonsSetting)
.setChildren(convertList(childrenTasks, childTask -> BeanUtils.toBean(childTask, BpmTaskRespVO.class)
.setStatus(FlowableUtils.getTaskStatus(childTask))));
if (form != null) {
bpmTaskRespVO.setFormId(form.getId()).setFormName(form.getName())
.setFormConf(form.getConf()).setFormFields(form.getFields());
}
return bpmTaskRespVO;
}

default BpmMessageSendWhenTaskCreatedReqDTO convert(ProcessInstance processInstance, AdminUserRespDTO startUser,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ protected int resolveNrOfInstances(DelegateExecution execution) {
Set<Long> assigneeUserIds = (Set<Long>) execution.getVariable(super.collectionVariable, Set.class);
if (assigneeUserIds == null) {
assigneeUserIds = taskCandidateInvoker.calculateUsersByTask(execution);
execution.setVariable(super.collectionVariable, assigneeUserIds);
if (CollUtil.isEmpty(assigneeUserIds)) {
// 特殊:如果没有处理人的情况下,至少有一个 null 空元素,避免自动通过!
// 这样,保证在 BpmUserTaskActivityBehavior 至少创建出一个 Task 任务
// 用途:1)审批人为空时;2)审批类型为自动通过、自动拒绝时
assigneeUserIds = SetUtils.asSet((Long) null);
}
execution.setVariableLocal(super.collectionVariable, assigneeUserIds);
}
return assigneeUserIds.size();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,18 @@ protected int resolveNrOfInstances(DelegateExecution execution) {
super.collectionElementVariable = FlowableUtils.formatExecutionCollectionElementVariable(execution.getCurrentActivityId());

// 第二步,获取任务的所有处理人
// 不使用 execution.getVariable 原因:目前依次审批任务回退后 collectionVariable 变量没有清理, 如果重新进入该任务不会重新分配审批人
@SuppressWarnings("unchecked")
Set<Long> assigneeUserIds = (Set<Long>) execution.getVariable(super.collectionVariable, Set.class);
Set<Long> assigneeUserIds = (Set<Long>) execution.getVariableLocal(super.collectionVariable, Set.class);
if (assigneeUserIds == null) {
assigneeUserIds = taskCandidateInvoker.calculateUsersByTask(execution);
execution.setVariable(super.collectionVariable, assigneeUserIds);
if (CollUtil.isEmpty(assigneeUserIds)) {
// 特殊:如果没有处理人的情况下,至少有一个 null 空元素,避免自动通过!
// 这样,保证在 BpmUserTaskActivityBehavior 至少创建出一个 Task 任务
// 用途:1)审批人为空时;2)审批类型为自动通过、自动拒绝时
assigneeUserIds = SetUtils.asSet((Long) null);
}
execution.setVariableLocal(super.collectionVariable, assigneeUserIds);
}
return assigneeUserIds.size();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* @author jason
*/
@Component
public class BpmTaskCandidateFormSDeptLeaderStrategy extends AbstractBpmTaskCandidateDeptLeaderStrategy {
public class BpmTaskCandidateFormDeptLeaderStrategy extends AbstractBpmTaskCandidateDeptLeaderStrategy {

@Override
public BpmTaskCandidateStrategyEnum getStrategy() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@
import cn.iocoder.yudao.module.bpm.framework.flowable.core.candidate.BpmTaskCandidateStrategy;
import cn.iocoder.yudao.module.bpm.framework.flowable.core.enums.BpmTaskCandidateStrategyEnum;
import cn.iocoder.yudao.module.bpm.framework.flowable.core.util.FlowableUtils;
import com.google.common.collect.Sets;
import lombok.extern.slf4j.Slf4j;
import org.flowable.bpmn.model.BpmnModel;
import org.flowable.common.engine.api.FlowableException;
import org.flowable.engine.delegate.DelegateExecution;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

Expand All @@ -17,6 +21,7 @@
* @author 芋道源码
*/
@Component
@Slf4j
public class BpmTaskCandidateExpressionStrategy implements BpmTaskCandidateStrategy {

@Override
Expand All @@ -38,8 +43,16 @@ public Set<Long> calculateUsersByTask(DelegateExecution execution, String param)
@Override
public Set<Long> calculateUsersByActivity(BpmnModel bpmnModel, String activityId, String param,
Long startUserId, String processDefinitionId, Map<String, Object> processVariables) {
Object result = FlowableUtils.getExpressionValue(processVariables, param);
return Convert.toSet(Long.class, result);
Map<String, Object> variables = processVariables == null ? new HashMap<>() : processVariables;
try {
Object result = FlowableUtils.getExpressionValue(variables, param);
return Convert.toSet(Long.class, result);
} catch (FlowableException ex) {
// 预测未运行的节点时候,表达式如果包含 execution 或者不存在的流程变量会抛异常,
log.warn("[calculateUsersByActivity][表达式({}) 变量({}) 解析报错", param, variables, ex);
// 不能预测候选人,返回空列表, 避免流程无法进行
return Sets.newHashSet();
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ public static void addExtensionElement(FlowElement element, String name, Map<Str
extensionElement.setName(name);
attributes.forEach((key, value) -> {
ExtensionAttribute extensionAttribute = new ExtensionAttribute(key, value);
extensionAttribute.setNamespace(FLOWABLE_EXTENSIONS_NAMESPACE);
extensionElement.addAttribute(extensionAttribute);
});
element.addExtensionElement(extensionElement);
Expand Down Expand Up @@ -278,8 +277,8 @@ public static Map<String, String> parseFormFieldsPermission(BpmnModel bpmnModel,
}
Map<String, String> fieldsPermission = MapUtil.newHashMap();
extensionElements.forEach(element -> {
String field = element.getAttributeValue(FLOWABLE_EXTENSIONS_NAMESPACE, FORM_FIELD_PERMISSION_ELEMENT_FIELD_ATTRIBUTE);
String permission = element.getAttributeValue(FLOWABLE_EXTENSIONS_NAMESPACE, FORM_FIELD_PERMISSION_ELEMENT_PERMISSION_ATTRIBUTE);
String field = element.getAttributeValue(null, FORM_FIELD_PERMISSION_ELEMENT_FIELD_ATTRIBUTE);
String permission = element.getAttributeValue(null, FORM_FIELD_PERMISSION_ELEMENT_PERMISSION_ATTRIBUTE);
if (StrUtil.isNotEmpty(field) && StrUtil.isNotEmpty(permission)) {
fieldsPermission.put(field, permission);
}
Expand Down Expand Up @@ -321,9 +320,9 @@ public static Map<Integer, BpmTaskRespVO.OperationButtonSetting> parseButtonsSet
}
Map<Integer, BpmTaskRespVO.OperationButtonSetting> buttonSettings = Maps.newHashMapWithExpectedSize(extensionElements.size());
extensionElements.forEach(element -> {
String id = element.getAttributeValue(FLOWABLE_EXTENSIONS_NAMESPACE, BUTTON_SETTING_ELEMENT_ID_ATTRIBUTE);
String displayName = element.getAttributeValue(FLOWABLE_EXTENSIONS_NAMESPACE, BUTTON_SETTING_ELEMENT_DISPLAY_NAME_ATTRIBUTE);
String enable = element.getAttributeValue(FLOWABLE_EXTENSIONS_NAMESPACE, BUTTON_SETTING_ELEMENT_ENABLE_ATTRIBUTE);
String id = element.getAttributeValue(null, BUTTON_SETTING_ELEMENT_ID_ATTRIBUTE);
String displayName = element.getAttributeValue(null, BUTTON_SETTING_ELEMENT_DISPLAY_NAME_ATTRIBUTE);
String enable = element.getAttributeValue(null, BUTTON_SETTING_ELEMENT_ENABLE_ATTRIBUTE);
if (StrUtil.isNotEmpty(id)) {
BpmTaskRespVO.OperationButtonSetting setting = new BpmTaskRespVO.OperationButtonSetting();
buttonSettings.put(Integer.valueOf(id), setting.setDisplayName(displayName).setEnable(Boolean.parseBoolean(enable)));
Expand Down Expand Up @@ -720,7 +719,7 @@ private static void simulateNextFlowElements(FlowElement currentElement, Map<Str
&& evalConditionExpress(variables, flow.getConditionExpression()));
if (matchSequenceFlow == null) {
matchSequenceFlow = CollUtil.findOne(gateway.getOutgoingFlows(),
flow -> ObjUtil.notEqual(gateway.getDefaultFlow(), flow.getId()));
flow -> ObjUtil.equal(gateway.getDefaultFlow(), flow.getId()));
// 特殊:没有默认的情况下,并且只有 1 个条件,则认为它是默认的
if (matchSequenceFlow == null && gateway.getOutgoingFlows().size() == 1) {
matchSequenceFlow = gateway.getOutgoingFlows().get(0);
Expand All @@ -742,7 +741,7 @@ private static void simulateNextFlowElements(FlowElement currentElement, Map<Str
&& evalConditionExpress(variables, flow.getConditionExpression()));
if (CollUtil.isEmpty(matchSequenceFlows)) {
matchSequenceFlows = CollUtil.filterNew(gateway.getOutgoingFlows(),
flow -> ObjUtil.notEqual(gateway.getDefaultFlow(), flow.getId()));
flow -> ObjUtil.equal(gateway.getDefaultFlow(), flow.getId()));
// 特殊:没有默认的情况下,并且只有 1 个条件,则认为它是默认的
if (CollUtil.isEmpty(matchSequenceFlows) && gateway.getOutgoingFlows().size() == 1) {
matchSequenceFlows = gateway.getOutgoingFlows();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public static BpmnModel buildBpmnModel(String processId, String processName, Bpm

private static BpmSimpleModelNodeVO buildStartNode() {
return new BpmSimpleModelNodeVO().setId(START_EVENT_NODE_ID)
.setName(BpmSimpleModelNodeType.START_USER_NODE.getName())
.setName(BpmSimpleModelNodeType.START_NODE.getName())
.setType(BpmSimpleModelNodeType.START_NODE.getType());
}

Expand Down
Loading

0 comments on commit 7c3dacc

Please sign in to comment.