CreateTaskMessage.java
1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package com.huaheng.pc.task.taskHeader.service;
import com.alibaba.fastjson.JSON;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.huaheng.common.constant.Constants;
import com.huaheng.common.exception.BusinessException;
import com.huaheng.common.exception.service.ServiceException;
import com.huaheng.common.utils.DateUtils;
import com.huaheng.pc.monitor.message.domain.Messages;
import com.huaheng.pc.monitor.message.service.MessagesService;
import com.huaheng.pc.task.taskHeader.domain.TaskHeader;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.Date;
/**
* Created by Enzo Cotter on 2020/4/20.
*/
@Service
public class CreateTaskMessage {
@Resource
private MessagesService messagesService;
@Resource
private RabbitTaskSender rabbitTaskSender;
public void createTask(TaskHeader taskHeader){
Messages messages = new Messages();
messages.setMsgType("任务");
messages.setMsgSubType(String.valueOf(taskHeader.getTaskType()));
messages.setMsgFrom("WMS");
messages.setMsgTo("WCS");
messages.setMsgSubject("");
messages.setMsgBody(JSON.toJSONString(taskHeader));
messages.setEnable(Constants.SEND_SUCCESS);
messages.setTryCount(0);
messages.setCreated(new Date());
messages.setCreatedBy(taskHeader.getCreatedBy());;
messages.setQueue("task");
messages.setRoutingKey("task.Issued");
messages.setNextRetry(DateUtils.addMinutes(messages.getCreated(), Constants.ORDER_TIMEOUT));
messages.setUpdateTime(new Date());
if (messagesService.save(messages)) {
rabbitTaskSender.sendTask(messages);
} else {
throw new ServiceException("消息发送失败");
}
}
}