|
@@ -1,20 +1,22 @@
|
|
package com.flow.delegate;
|
|
package com.flow.delegate;
|
|
|
|
|
|
-import com.flow.entity.FlowDefine;
|
|
|
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
|
import com.flow.entity.Notify;
|
|
import com.flow.entity.Notify;
|
|
import com.flow.entity.User;
|
|
import com.flow.entity.User;
|
|
-import com.flow.entity.node.NotifyNode;
|
|
|
|
import com.flow.enums.NotifyEnum;
|
|
import com.flow.enums.NotifyEnum;
|
|
import com.flow.enums.NotifyTypeEnum;
|
|
import com.flow.enums.NotifyTypeEnum;
|
|
-import com.flow.service.FlowDefineService;
|
|
|
|
|
|
+import com.flow.flowable.utils.ProcessElementUtil;
|
|
import com.flow.service.NotifyService;
|
|
import com.flow.service.NotifyService;
|
|
import com.flow.service.UserService;
|
|
import com.flow.service.UserService;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
+import org.flowable.bpmn.model.MultiInstanceLoopCharacteristics;
|
|
|
|
+import org.flowable.bpmn.model.ServiceTask;
|
|
import org.flowable.common.engine.impl.el.ExpressionManager;
|
|
import org.flowable.common.engine.impl.el.ExpressionManager;
|
|
|
|
+import org.flowable.engine.delegate.BpmnError;
|
|
import org.flowable.engine.delegate.DelegateExecution;
|
|
import org.flowable.engine.delegate.DelegateExecution;
|
|
import org.flowable.engine.delegate.JavaDelegate;
|
|
import org.flowable.engine.delegate.JavaDelegate;
|
|
import org.flowable.engine.impl.cfg.ProcessEngineConfigurationImpl;
|
|
import org.flowable.engine.impl.cfg.ProcessEngineConfigurationImpl;
|
|
-import org.flowable.engine.impl.persistence.entity.ExecutionEntityImpl;
|
|
|
|
|
|
+import org.flowable.http.common.impl.ExpressionUtils;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.mail.SimpleMailMessage;
|
|
import org.springframework.mail.SimpleMailMessage;
|
|
@@ -22,14 +24,11 @@ import org.springframework.mail.javamail.JavaMailSender;
|
|
import org.springframework.stereotype.Component;
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
import java.time.LocalDateTime;
|
|
import java.time.LocalDateTime;
|
|
-import java.util.List;
|
|
|
|
|
|
|
|
|
|
|
|
@Slf4j
|
|
@Slf4j
|
|
@Component
|
|
@Component
|
|
public class NotifyDelegate implements JavaDelegate {
|
|
public class NotifyDelegate implements JavaDelegate {
|
|
- @Autowired
|
|
|
|
- private FlowDefineService flowDefineService;
|
|
|
|
@Autowired
|
|
@Autowired
|
|
private JavaMailSender mailSender;
|
|
private JavaMailSender mailSender;
|
|
@Value("${spring.mail.username}")
|
|
@Value("${spring.mail.username}")
|
|
@@ -43,18 +42,22 @@ public class NotifyDelegate implements JavaDelegate {
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public void execute(DelegateExecution execution) {
|
|
public void execute(DelegateExecution execution) {
|
|
- ExecutionEntityImpl entity = (ExecutionEntityImpl) execution;
|
|
|
|
- String activityId = execution.getCurrentActivityId();
|
|
|
|
- FlowDefine define = flowDefineService.getDefine(entity.getProcessDefinitionId());
|
|
|
|
- NotifyNode notifyNode = define.getNode(execution.getCurrentActivityId(), NotifyNode.class);
|
|
|
|
- List<NotifyTypeEnum> typeEnums = notifyNode.getTypes();
|
|
|
|
|
|
+ ServiceTask notifyServiceTask = (ServiceTask) execution.getCurrentFlowElement();
|
|
|
|
+ String types = ProcessElementUtil.getFieldExtensionValue(notifyServiceTask, "types");
|
|
|
|
+ String subject = ProcessElementUtil.getFieldExtensionExpression(notifyServiceTask, "subject");
|
|
|
|
+ String content = ProcessElementUtil.getFieldExtensionExpression(notifyServiceTask, "content");
|
|
|
|
+ if (StringUtils.isBlank(types) || StringUtils.isBlank(subject) || StringUtils.isBlank(content)) {
|
|
|
|
+ throw new BpmnError("notify.error", "通知参数异常");
|
|
|
|
+ }
|
|
ExpressionManager expressionManager = processEngineConfiguration.getExpressionManager();
|
|
ExpressionManager expressionManager = processEngineConfiguration.getExpressionManager();
|
|
- String content = (String) expressionManager.createExpression(notifyNode.getContent()).getValue(execution);
|
|
|
|
- String subject = (String) expressionManager.createExpression(notifyNode.getSubject()).getValue(execution);
|
|
|
|
- // 通知
|
|
|
|
- String assignee = execution.getVariableLocal(String.format("%sItem", activityId), String.class);
|
|
|
|
|
|
+ subject = ExpressionUtils.getStringFromField(expressionManager.createExpression(subject), execution);
|
|
|
|
+ content = ExpressionUtils.getStringFromField(expressionManager.createExpression(content), execution);
|
|
|
|
+ MultiInstanceLoopCharacteristics loopCharacteristics = notifyServiceTask.getLoopCharacteristics();
|
|
|
|
+ String assignee = execution.getVariableLocal(loopCharacteristics.getElementVariable(), String.class);
|
|
User user = userService.getByUsername(assignee);
|
|
User user = userService.getByUsername(assignee);
|
|
- for (NotifyTypeEnum typeEnum : typeEnums) {
|
|
|
|
|
|
+ String[] typeArray = types.split(",");
|
|
|
|
+ for (String type : typeArray) {
|
|
|
|
+ NotifyTypeEnum typeEnum = NotifyTypeEnum.match(type);
|
|
switch (typeEnum) {
|
|
switch (typeEnum) {
|
|
case SITE:
|
|
case SITE:
|
|
// 站内通知
|
|
// 站内通知
|