|
@@ -1,83 +1,43 @@
|
|
|
package com.flow.delegate;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
|
|
-import com.flow.entity.Notify;
|
|
|
-import com.flow.entity.User;
|
|
|
-import com.flow.enums.NotifyEnum;
|
|
|
import com.flow.enums.NotifyTypeEnum;
|
|
|
import com.flow.flowable.utils.ProcessElementUtil;
|
|
|
-import com.flow.service.NotifyService;
|
|
|
-import com.flow.service.UserService;
|
|
|
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.engine.delegate.BpmnError;
|
|
|
import org.flowable.engine.delegate.DelegateExecution;
|
|
|
import org.flowable.engine.delegate.JavaDelegate;
|
|
|
-import org.flowable.engine.impl.cfg.ProcessEngineConfigurationImpl;
|
|
|
-import org.flowable.http.common.impl.ExpressionUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.beans.factory.annotation.Value;
|
|
|
-import org.springframework.mail.SimpleMailMessage;
|
|
|
-import org.springframework.mail.javamail.JavaMailSender;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
-import java.time.LocalDateTime;
|
|
|
-
|
|
|
|
|
|
@Slf4j
|
|
|
@Component
|
|
|
public class NotifyDelegate implements JavaDelegate {
|
|
|
@Autowired
|
|
|
- private JavaMailSender mailSender;
|
|
|
- @Value("${spring.mail.username}")
|
|
|
- private String from;
|
|
|
- @Autowired
|
|
|
- private NotifyService notifyService;
|
|
|
- @Autowired
|
|
|
- private UserService userService;
|
|
|
+ private SiteNotifyDelegate siteNotifyDelegate;
|
|
|
@Autowired
|
|
|
- private ProcessEngineConfigurationImpl processEngineConfiguration;
|
|
|
+ private MailNotifyDelegate mailNotifyDelegate;
|
|
|
|
|
|
@Override
|
|
|
public void execute(DelegateExecution execution) {
|
|
|
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)) {
|
|
|
+ if (StringUtils.isBlank(types)) {
|
|
|
throw new BpmnError("notify.error", "通知参数异常");
|
|
|
}
|
|
|
- ExpressionManager expressionManager = processEngineConfiguration.getExpressionManager();
|
|
|
- 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);
|
|
|
String[] typeArray = types.split(",");
|
|
|
for (String type : typeArray) {
|
|
|
NotifyTypeEnum typeEnum = NotifyTypeEnum.match(type);
|
|
|
switch (typeEnum) {
|
|
|
case SITE:
|
|
|
// 站内通知
|
|
|
- Notify notify = new Notify();
|
|
|
- notify.setSender("admin");
|
|
|
- notify.setType(NotifyEnum.SYSTEM);
|
|
|
- notify.setReceivingTime(LocalDateTime.now());
|
|
|
- notify.setReceiver(assignee);
|
|
|
- notify.setSubject(subject);
|
|
|
- notify.setContent(content);
|
|
|
- notifyService.notify(notify);
|
|
|
+ siteNotifyDelegate.execute(execution);
|
|
|
break;
|
|
|
case EMAIL:
|
|
|
// 邮件通知
|
|
|
- SimpleMailMessage message = new SimpleMailMessage();
|
|
|
- message.setFrom(this.from);
|
|
|
- message.setTo(user.getEmail());
|
|
|
- message.setSubject(subject);
|
|
|
- message.setText(content);
|
|
|
- mailSender.send(message);
|
|
|
+ mailNotifyDelegate.execute(execution);
|
|
|
break;
|
|
|
default:
|
|
|
break;
|