|
|
@ -9,13 +9,18 @@ import com.hnac.hzims.middle.processflow.service.WorkflowOperationLogService; |
|
|
|
import com.hnac.hzims.middle.processflow.strategy.entity.WorkflowQueue; |
|
|
|
import com.hnac.hzims.middle.processflow.strategy.entity.WorkflowQueue; |
|
|
|
import com.hnac.hzims.middle.processflow.strategy.service.ProcessService; |
|
|
|
import com.hnac.hzims.middle.processflow.strategy.service.ProcessService; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
|
|
|
|
import org.springblade.core.log.exception.ServiceException; |
|
|
|
|
|
|
|
import org.springblade.core.tool.utils.BeanUtil; |
|
|
|
|
|
|
|
import org.springblade.core.tool.utils.Func; |
|
|
|
import org.springblade.queue.annotation.RedisQueue; |
|
|
|
import org.springblade.queue.annotation.RedisQueue; |
|
|
|
import org.springblade.queue.consume.IQueueConsume; |
|
|
|
import org.springblade.queue.consume.IQueueConsume; |
|
|
|
import org.springframework.beans.BeanUtils; |
|
|
|
import org.springframework.beans.BeanUtils; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
import org.springframework.util.Assert; |
|
|
|
|
|
|
|
|
|
|
|
import java.util.List; |
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
import java.util.Optional; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 监听数据的 |
|
|
|
* 监听数据的 |
|
|
@ -30,7 +35,6 @@ import java.util.List; |
|
|
|
@Slf4j |
|
|
|
@Slf4j |
|
|
|
public class StandardWorkTicketConsumer implements IQueueConsume { |
|
|
|
public class StandardWorkTicketConsumer implements IQueueConsume { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
@Autowired |
|
|
|
private List<ProcessService> ticketServiceList; |
|
|
|
private List<ProcessService> ticketServiceList; |
|
|
|
|
|
|
|
|
|
|
@ -39,42 +43,39 @@ public class StandardWorkTicketConsumer implements IQueueConsume { |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void handlerMessage(String message) { |
|
|
|
public void handlerMessage(String message) { |
|
|
|
log.info("监听到数据:{}", message); |
|
|
|
|
|
|
|
ProcessWorkFlowResponse response = JSONObject.parseObject(message, ProcessWorkFlowResponse.class); |
|
|
|
|
|
|
|
String taskDefinitionKey = response.getProcessDefinitionKey(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//记录操作日志
|
|
|
|
|
|
|
|
WorkflowOperationLog regularWorkflowOperationLog = new WorkflowOperationLog(); |
|
|
|
|
|
|
|
BeanUtils.copyProperties(response, regularWorkflowOperationLog); |
|
|
|
|
|
|
|
if (ObjectUtils.isNotEmpty(regularWorkflowOperationLog)) { |
|
|
|
|
|
|
|
regularWorkflowOperationLog.setVariables(JSON.toJSONString(response.getVariables())); |
|
|
|
|
|
|
|
regularWorkflowOperationLog.setTakeId(response.getTaskId()); |
|
|
|
|
|
|
|
regularWorkflowOperationLog.setTakeName(response.getTaskName()); |
|
|
|
|
|
|
|
regularWorkflowOperationLog.setIsOperationLog(true); |
|
|
|
|
|
|
|
regularWorkflowOperationLog.setProcessInstanceKey(response.getProcessInstanceId()); |
|
|
|
|
|
|
|
log.info("正在记录操作日志WorkflowOperationLog.... :{}", regularWorkflowOperationLog); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
try { |
|
|
|
try { |
|
|
|
WorkflowQueue ticker = new WorkflowQueue(); |
|
|
|
ProcessWorkFlowResponse response = JSONObject.parseObject(message, ProcessWorkFlowResponse.class); |
|
|
|
ticker.setProcessDefinitionKey(taskDefinitionKey); |
|
|
|
Assert.isTrue(Func.isNotEmpty(response),() -> { |
|
|
|
//判断执行具体的实现类
|
|
|
|
throw new ServiceException("消息转换失败,消息内容为:" + message); |
|
|
|
ProcessService processService = |
|
|
|
}); |
|
|
|
ticketServiceList.stream().filter(item -> item.isWorkflowProcess(ticker)).findFirst().orElse(null); |
|
|
|
// 保存日志
|
|
|
|
if (ObjectUtils.isNotEmpty(processService)) { |
|
|
|
WorkflowOperationLog log = BeanUtil.copy(response, WorkflowOperationLog.class); |
|
|
|
//执行业务方法
|
|
|
|
log.setVariables(JSON.toJSONString(response.getVariables())); |
|
|
|
|
|
|
|
log.setIsOperationLog(true); |
|
|
|
|
|
|
|
log.setProcessInstanceKey(response.getProcessInstanceId()); |
|
|
|
|
|
|
|
workflowOperationLogService.save(log); |
|
|
|
|
|
|
|
WorkflowQueue queue = WorkflowQueue.builder().processDefinitionKey(response.getProcessDefinitionKey()).build(); |
|
|
|
|
|
|
|
Optional<ProcessService> serviceOptional = ticketServiceList.stream().filter(processService -> processService.isWorkflowProcess(queue)).findFirst(); |
|
|
|
|
|
|
|
if(serviceOptional.isPresent()) { |
|
|
|
try { |
|
|
|
try { |
|
|
|
processService.calculate(response); |
|
|
|
serviceOptional.get().calculate(response); |
|
|
|
} catch (Exception e) { |
|
|
|
} |
|
|
|
|
|
|
|
catch (Exception e) { |
|
|
|
|
|
|
|
log.setFaultLog(e.getMessage()); |
|
|
|
|
|
|
|
log.setIsOperationLog(false); |
|
|
|
|
|
|
|
workflowOperationLogService.updateById(log); |
|
|
|
e.printStackTrace(); |
|
|
|
e.printStackTrace(); |
|
|
|
//todo 业务出错误 做补偿
|
|
|
|
|
|
|
|
log.error("业务出错,StandardWorkTicketConsumer: {}", e.getMessage()); |
|
|
|
|
|
|
|
log.error("业务出错,StandardWorkTicketConsumer: {} ", response); |
|
|
|
|
|
|
|
regularWorkflowOperationLog.setIsOperationLog(false);//调用消费方抛出异常
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} finally { |
|
|
|
else { |
|
|
|
workflowOperationLogService.save(regularWorkflowOperationLog); |
|
|
|
log.setFaultLog("未获取到相关执行方法,key值为:" + response.getProcessDefinitionKey()); |
|
|
|
|
|
|
|
log.setIsOperationLog(false); |
|
|
|
|
|
|
|
workflowOperationLogService.updateById(log); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
catch(Exception e) { |
|
|
|
|
|
|
|
log.error("消息消费失败,消息体为:{}",JSON.toJSONString(message)); |
|
|
|
|
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|