Merge branch 'dev'

This commit is contained in:
wangliwen 2022-08-03 15:09:55 +08:00
commit e2dde1c658
2 changed files with 45 additions and 77 deletions

View File

@ -94,9 +94,6 @@ public class ActivitiNoticeAspect {
case TaskListener.EVENTNAME_COMPLETE: // 节点执行完成 case TaskListener.EVENTNAME_COMPLETE: // 节点执行完成
task_complete_notice(delegateTask, activitiNoticeOperation); task_complete_notice(delegateTask, activitiNoticeOperation);
break; break;
case TaskListener.EVENTNAME_CREATE: // 节点被创建
task_create_notice(delegateTask, activitiNoticeOperation);
break;
default: default:
} }
}); });
@ -121,78 +118,6 @@ public class ActivitiNoticeAspect {
LOGGER.error("执行时长{} ms", time); LOGGER.error("执行时长{} ms", time);
} }
/**
* 特殊处理驳回
*
* @param delegateTask
* @param activitiNoticeOperation
*/
private void task_create_notice(final DelegateTask delegateTask, final ActivitiNoticeOperation activitiNoticeOperation) {
Map<String, Object> kv = delegateTask.getVariables();
LOGGER.error("表单:{}", JSON.toJSONString(kv));
final String workKey = TaskListener.EVENTNAME_CREATE + kv.get("id").toString();
if (work.contains(workKey)) {
LOGGER.error("------------出现重放------------");
return;
}
work.add(workKey);
String creator = null;
if (kv.containsKey("creator")) { // 表单存在创建者
creator = kv.get("creator").toString();
} else if (kv.containsKey("userId")) {
creator = kv.get("userId").toString();
}
if (StringUtils.isEmpty(creator)) {
work.remove(workKey);
return;
}
if (!"发起人录入表单".equals(activitiNoticeOperation.process())) { // 非驳回到录入表单
work.remove(workKey);
return;
}
try {
String result;
Boolean backToFirst = Boolean.valueOf(kv.get("backToFirst") != null ? kv.get("backToFirst").toString() : Boolean.FALSE.toString()); // 存在驳回
if (Boolean.TRUE.equals(backToFirst)) {
result = "被驳回";
} else {
work.remove(workKey);
return;
}
String finalCreator = creator;
String finalResult = result;
CompletableFuture.runAsync(() -> { // 发起人
SysUserDTO userDTO = sysUserService.get(Long.valueOf(finalCreator));
String content = "【通知】" + userDTO.getRealName() + ",您发起的流程 " + kv.getOrDefault("flowType", "") + finalResult;
SysNoticeDTO dto = new SysNoticeDTO();
dto.setType(2);
dto.setTitle("流程节点系统通知");
dto.setContent(content); // 通知内容
dto.setReceiverType(1);
dto.setReceiverTypeIds(finalCreator);
dto.setStatus(NoticeStatusEnum.SEND.value());
dto.setSenderName("流程系统");
dto.setSenderDate(new Date());
dto.setCreator(sysUserService.getByUsername("admin").getId());
dto.setCreateDate(new Date());
dto.setFrom("通知");
sysNoticeService.save(dto);
}, EXECUTOR);
} catch (Exception exception) {
LOGGER.error("发送通知消息异常", exception);
} finally {
// 防止重放
new Thread(() -> {
try {
Thread.sleep(200);
} catch (InterruptedException e) {
throw new RuntimeException(e);
} finally {
work.remove(workKey);
}
}).start();
}
}
/** /**
* 进行节点流转 * 进行节点流转

View File

@ -4,8 +4,12 @@ import com.google.gson.Gson;
import com.google.gson.GsonBuilder; import com.google.gson.GsonBuilder;
import com.google.gson.JsonDeserializer; import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement; import com.google.gson.JsonElement;
import io.renren.common.annotation.ActivitiNoticeOperation;
import io.renren.common.dto.AuditingBaseDTO; import io.renren.common.dto.AuditingBaseDTO;
import io.renren.modules.notice.dto.SysNoticeDTO;
import io.renren.modules.notice.enums.NoticeStatusEnum;
import io.renren.modules.notice.service.SysNoticeService;
import io.renren.modules.sys.dto.SysUserDTO;
import io.renren.modules.sys.service.SysUserService;
import org.activiti.engine.TaskService; import org.activiti.engine.TaskService;
import org.activiti.engine.delegate.DelegateTask; import org.activiti.engine.delegate.DelegateTask;
import org.activiti.engine.delegate.TaskListener; import org.activiti.engine.delegate.TaskListener;
@ -16,20 +20,28 @@ import org.springframework.stereotype.Component;
import java.util.Date; import java.util.Date;
import java.util.Map; import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
/** /**
* 流程发起人录入表单 * 流程发起人录入表单
*/ */
@Component @Component
public class InitiatorDataEntryListener implements TaskListener { public class InitiatorDataEntryListener implements TaskListener {
private static final Integer CPU_NUM = Runtime.getRuntime().availableProcessors();
private static final ExecutorService EXECUTOR = Executors.newFixedThreadPool(CPU_NUM * 3);
private static final Logger logger = LoggerFactory.getLogger(InitiatorDataEntryListener.class); private static final Logger logger = LoggerFactory.getLogger(InitiatorDataEntryListener.class);
@Autowired @Autowired
private TaskService taskService; private TaskService taskService;
@Autowired
private SysNoticeService sysNoticeService;
@Autowired
private SysUserService sysUserService;
@Override @Override
@ActivitiNoticeOperation(value = "任意流程", process = "发起人录入表单")
public void notify(DelegateTask delegateTask) { public void notify(DelegateTask delegateTask) {
logger.error("----------------------流程发起人录入表单节点---------------------------"); logger.error("----------------------流程发起人录入表单节点---------------------------");
logger.error("事件类型:{}", delegateTask.getEventName()); logger.error("事件类型:{}", delegateTask.getEventName());
@ -57,6 +69,36 @@ public class InitiatorDataEntryListener implements TaskListener {
AuditingBaseDTO auditingBaseDTO = gson.fromJson(jsonElement, AuditingBaseDTO.class); AuditingBaseDTO auditingBaseDTO = gson.fromJson(jsonElement, AuditingBaseDTO.class);
if (auditingBaseDTO.getBackToFirst() != null && auditingBaseDTO.getBackToFirst()) { if (auditingBaseDTO.getBackToFirst() != null && auditingBaseDTO.getBackToFirst()) {
logger.error("被驳回,需修改后重新提交"); logger.error("被驳回,需修改后重新提交");
String creator = null;
if (kv.containsKey("creator")) { // 表单存在创建者
creator = kv.get("creator").toString();
} else if (kv.containsKey("userId")) {
creator = kv.get("userId").toString();
}
try {
String result = "被驳回";
String finalCreator = creator;
String finalResult = result;
CompletableFuture.runAsync(() -> { // 发起人
SysUserDTO userDTO = sysUserService.get(Long.valueOf(finalCreator));
String content = "【通知】" + userDTO.getRealName() + ",您发起的流程 " + kv.getOrDefault("flowType", "") + finalResult;
SysNoticeDTO dto = new SysNoticeDTO();
dto.setType(2);
dto.setTitle("流程节点系统通知");
dto.setContent(content); // 通知内容
dto.setReceiverType(1);
dto.setReceiverTypeIds(finalCreator);
dto.setStatus(NoticeStatusEnum.SEND.value());
dto.setSenderName("流程系统");
dto.setSenderDate(new Date());
dto.setCreator(sysUserService.getByUsername("admin").getId());
dto.setCreateDate(new Date());
dto.setFrom("通知");
sysNoticeService.save(dto);
}, EXECUTOR);
} catch (Exception exception) {
logger.error("发送通知消息异常", exception);
}
} else { } else {
if (Boolean.TRUE.equals(auditingBaseDTO.getCompleteEntry())) { if (Boolean.TRUE.equals(auditingBaseDTO.getCompleteEntry())) {
taskService.addComment(delegateTask.getId(), delegateTask.getProcessInstanceId(), "完成申请提交"); taskService.addComment(delegateTask.getId(), delegateTask.getProcessInstanceId(), "完成申请提交");
@ -66,4 +108,5 @@ public class InitiatorDataEntryListener implements TaskListener {
} }
logger.error("----------完成录入表单-----------"); logger.error("----------完成录入表单-----------");
} }
} }