|
@@ -1,6 +1,5 @@
|
|
|
package com.flow.delegate;
|
|
|
|
|
|
-import com.flow.common.core.util.StrUtil;
|
|
|
import com.flow.entity.FlowDefine;
|
|
|
import com.flow.entity.Notify;
|
|
|
import com.flow.entity.User;
|
|
@@ -11,8 +10,10 @@ import com.flow.service.FlowDefineService;
|
|
|
import com.flow.service.NotifyService;
|
|
|
import com.flow.service.UserService;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.flowable.common.engine.impl.el.ExpressionManager;
|
|
|
import org.flowable.engine.delegate.DelegateExecution;
|
|
|
import org.flowable.engine.delegate.JavaDelegate;
|
|
|
+import org.flowable.engine.impl.cfg.ProcessEngineConfigurationImpl;
|
|
|
import org.flowable.engine.impl.persistence.entity.ExecutionEntityImpl;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
@@ -21,9 +22,7 @@ import org.springframework.mail.javamail.JavaMailSender;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
import java.time.LocalDateTime;
|
|
|
-import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
|
|
|
|
|
|
@Slf4j
|
|
@@ -39,46 +38,43 @@ public class NotifyDelegate implements JavaDelegate {
|
|
|
private NotifyService notifyService;
|
|
|
@Autowired
|
|
|
private UserService userService;
|
|
|
-
|
|
|
+ @Autowired
|
|
|
+ private ProcessEngineConfigurationImpl processEngineConfiguration;
|
|
|
|
|
|
@Override
|
|
|
public void execute(DelegateExecution execution) {
|
|
|
ExecutionEntityImpl entity = (ExecutionEntityImpl) execution;
|
|
|
String activityId = execution.getCurrentActivityId();
|
|
|
- Map<String, Object> variables = execution.getVariables();
|
|
|
FlowDefine define = flowDefineService.getDefine(entity.getProcessDefinitionId());
|
|
|
NotifyNode notifyNode = define.getNode(execution.getCurrentActivityId(), NotifyNode.class);
|
|
|
List<NotifyTypeEnum> typeEnums = notifyNode.getTypes();
|
|
|
+ ExpressionManager expressionManager = processEngineConfiguration.getExpressionManager();
|
|
|
+ String content = (String) expressionManager.createExpression(notifyNode.getContent()).getValue(execution);
|
|
|
+ String subject = (String) expressionManager.createExpression(notifyNode.getSubject()).getValue(execution);
|
|
|
// 通知
|
|
|
- ArrayList<String> assignees = execution.getVariable(String.format("%sCollection", activityId), ArrayList.class);
|
|
|
- List<User> userList = userService.lambdaQuery()
|
|
|
- .in(User::getUsername, assignees)
|
|
|
- .list();
|
|
|
+ String assignee = execution.getVariableLocal(String.format("%sItem", activityId), String.class);
|
|
|
+ User user = userService.getByUsername(assignee);
|
|
|
for (NotifyTypeEnum typeEnum : typeEnums) {
|
|
|
switch (typeEnum) {
|
|
|
case SITE:
|
|
|
// 站内通知
|
|
|
- for (User assignee : userList) {
|
|
|
- Notify notify = new Notify();
|
|
|
- notify.setSender("admin");
|
|
|
- notify.setType(NotifyEnum.SYSTEM);
|
|
|
- notify.setReceivingTime(LocalDateTime.now());
|
|
|
- notify.setReceiver(assignee.getUsername());
|
|
|
- notify.setSubject(StrUtil.format(notifyNode.getSubject(), variables));
|
|
|
- notify.setContent(StrUtil.format(notifyNode.getContent(), variables));
|
|
|
- notifyService.notify(notify);
|
|
|
- }
|
|
|
+ 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);
|
|
|
break;
|
|
|
case EMAIL:
|
|
|
// 邮件通知
|
|
|
- for (User assignee : userList) {
|
|
|
- SimpleMailMessage message = new SimpleMailMessage();
|
|
|
- message.setFrom(this.from);
|
|
|
- message.setTo(assignee.getEmail());
|
|
|
- message.setSubject(StrUtil.format(notifyNode.getSubject(), variables));
|
|
|
- message.setText(StrUtil.format(notifyNode.getContent(), variables));
|
|
|
- mailSender.send(message);
|
|
|
- }
|
|
|
+ SimpleMailMessage message = new SimpleMailMessage();
|
|
|
+ message.setFrom(this.from);
|
|
|
+ message.setTo(user.getEmail());
|
|
|
+ message.setSubject(subject);
|
|
|
+ message.setText(content);
|
|
|
+ mailSender.send(message);
|
|
|
break;
|
|
|
default:
|
|
|
break;
|