企业中有自己的业务系统,审批都在业务系统中审批,如何结合移动办公的开放平台实现统一审批至关重要。
场景很简单,自己的系统中可以审批,钉钉上也可以审批,使用H5来适配,统一待办任务
目标:flowable创建任务能推送到钉钉待办任务
实现flowable钉钉相互之间可以创建待办,更新待办,删除待办@Slf4j
@Component
public class ProdGlobalTaskCreateListener extends AbstractFlowableEngineEventListener {
@Autowired
private ITaskListenerService taskListenerService;
@Autowired
protected IProcessStatusService processStatusService;
@Autowired
private FlowMessageService flowMessageService;
@Override
protected void taskCreated(FlowableEngineEntityEvent event) {
FlowableEntityEventImpl flowableEntityEvent = (FlowableEntityEventImpl) event;
TaskEntity entity = (TaskEntity) flowableEntityEvent.getEntity();
flowMessageService.createTaskToMq(entity, entity.getAssignee());
推送的逻辑
public boolean sendTaskMessage(ProcessInstance processInstance, TaskEntity entity, OperationTypeEnum operationType) {
boolean flag = false;
PlatformDingtalkTaskVo platformTask = new PlatformDingtalkTaskVo();
platformTask.setOperationType(operationType.getCode());
platformTask.setBussinessKey(processInstance.getBusinessKey());
platformTask.setFlowableProInstId(processInstance.getProcessInstanceId());
platformTask.setSubject(processInstance.getName());
if (entity != null) {
platformTask.setFlowableTaskId(entity.getId());
ApplyerVo applyerVo = prodFlowTaskService.getApplyerVoByTaskId(entity.getId());
if (applyerVo != null) {
List<String> thirdUnionIds = new ArrayList<>();
if (applyerVo.getApplyer() != null) {
thirdUnionIds.add(applyerVo.getApplyer().getThirdUnionId());
platformTask.setUnionId(applyerVo.getApplyer().getThirdUnionId());
platformTask.setCreatorId(applyerVo.getApplyer().getThirdUnionId());
platformTask.setOperatorId(applyerVo.getApplyer().getThirdUnionId());
platformTask.setMobile(applyerVo.getApplyer().getMobile());
flag = true;
}
if (CollectionUtils.isNotEmpty(applyerVo.getExecutors())) {
applyerVo.getExecutors().forEach(personal -> thirdUnionIds.add(personal.getThirdUnionId()));
flag = true;
}
platformTask.setExecutorIds(thirdUnionIds);
platformTask.setFlowableTaskName(entity.getName());
platformTask.setDingNotify("1");
platformTask.setPriority(20);
platformTask.setDueTime(DateUtil.addDate(new Date(), 1).getTime());
platformTask.setIsOnlyShowExecutor(true);
platformTask.setAppSn(processInstance.getTenantId());
//TODO 组装成查看审批页面的url
platformTask.setAppUrl("https://www.dingtalk.com");
platformTask.setPcUrl("https://www.dingtalk.com");
String json = JSON.toJSONString(platformTask);
try {
if (!flag) {
log.error("未查询到审批的人信息,请确认!参数:" + json);
} else {
log.info("任务开始推送MQ......");
if (ProdflowConstant.pushMsgAppSns.contains(processInstance.getTenantId())) {
redisTemplate.convertAndSend(ProdflowConstant.FLOWABLE_TASK_MESSAGE_QUEUE, json);
}
}
} catch (Exception e) {
e.printStackTrace();
log.error("推送到MQ异常!原因:" + e.getMessage());
}
}
}
return flag;
}
接受消息
public void onMessage(Message message, byte[] pattern) {
RedisSerializer<String> valueSerializer = redisTemplate.getStringSerializer();
String datas = valueSerializer.deserialize(message.getBody());
log.info("收到的mq消息===========================================" + datas);
String platformType = platformProperties.getPlatformType();
if (platformProperties.getEnabled()) {
switch (platformType) {
case "dingtalk":
PlatformDingtalkTaskVo dingtalkTaskVo = FastJsonUtils.jsonToObject(datas, PlatformDingtalkTaskVo.class);
messageDingtalkService.sendTaskMessage(dingtalkTaskVo);
break;
推送钉钉待办
public void sendTaskMessage(PlatformDingtalkTaskVo params) {
String operationType = params.getOperationType();
switch (operationType) {
case "create":
CreateTodoTaskRequest taskParams = this.createDingtalkTask(params);
CreateTodoTaskResponse taskResponse = dingtalkSdkService.createTask(params.getUnionId(), taskParams);
PlatformDingtalkTask pdt = new PlatformDingtalkTask();
BeanUtils.copyProperties(params, pdt);
if (CollectionUtils.isNotEmpty(params.getExecutorIds())) {
pdt.setExecutorIds(FastJsonUtils.objectToJson(params.getExecutorIds()));
}
if (CollectionUtils.isNotEmpty(params.getParticipantIds())) {
pdt.setParticipantIds(FastJsonUtils.objectToJson(params.getParticipantIds()));
}
pdt.setTaskId(taskResponse.getBody().getId());
pdt.setDone(false);
pdt.setCreateTime(new Date());
pdt.setDelFlag(1);
platformDingtalkTaskService.save(pdt);
break;