作者 王勇

前端发送消息,成功

@@ -140,7 +140,7 @@ public class MessageNoteController { @@ -140,7 +140,7 @@ public class MessageNoteController {
140 * @return {@link ResultJson} 140 * @return {@link ResultJson}
141 */ 141 */
142 @PostMapping("/insert") 142 @PostMapping("/insert")
143 - public ResultJson insertMessageNote(@RequestBody @NotNull MessageNote messageNote) 143 + public ResultJson insertMessageNote(@RequestBody @NotNull MessageNote messageNote) throws Exception
144 { 144 {
145 return messageNoteService.insertSelective(messageNote) > 0 145 return messageNoteService.insertSelective(messageNote) > 0
146 ? new ResultJson<>("200", "编辑-消息收发记录,成功") 146 ? new ResultJson<>("200", "编辑-消息收发记录,成功")
@@ -29,11 +29,11 @@ public interface MessageNoteService { @@ -29,11 +29,11 @@ public interface MessageNoteService {
29 29
30 /** 30 /**
31 * 新增,选择性 31 * 新增,选择性
32 - *  
33 * @param record the record 32 * @param record the record
34 * @return insert count 33 * @return insert count
  34 + * @throws Exception 异常
35 */ 35 */
36 - int insertSelective(MessageNote record); 36 + int insertSelective(MessageNote record) throws Exception;
37 37
38 /** 38 /**
39 * 查询,根据主键 39 * 查询,根据主键
@@ -107,4 +107,6 @@ public class AsyncTaskService { @@ -107,4 +107,6 @@ public class AsyncTaskService {
107 // 删除相关配置关系 107 // 删除相关配置关系
108 userMessageBindingService.deleteByQueueId(busQueue.getId()); 108 userMessageBindingService.deleteByQueueId(busQueue.getId());
109 } 109 }
  110 +
  111 +
110 } 112 }
@@ -5,6 +5,7 @@ import com.github.pagehelper.PageInfo; @@ -5,6 +5,7 @@ import com.github.pagehelper.PageInfo;
5 import com.sunyo.wlpt.message.bus.service.domain.*; 5 import com.sunyo.wlpt.message.bus.service.domain.*;
6 import com.sunyo.wlpt.message.bus.service.mapper.MessageNoteMapper; 6 import com.sunyo.wlpt.message.bus.service.mapper.MessageNoteMapper;
7 import com.sunyo.wlpt.message.bus.service.mapper.UserMessageBindingMapper; 7 import com.sunyo.wlpt.message.bus.service.mapper.UserMessageBindingMapper;
  8 +import com.sunyo.wlpt.message.bus.service.rabbit.utils.DirectUtils;
8 import com.sunyo.wlpt.message.bus.service.service.*; 9 import com.sunyo.wlpt.message.bus.service.service.*;
9 import com.sunyo.wlpt.message.bus.service.utils.IdUtils; 10 import com.sunyo.wlpt.message.bus.service.utils.IdUtils;
10 import lombok.extern.slf4j.Slf4j; 11 import lombok.extern.slf4j.Slf4j;
@@ -47,6 +48,9 @@ public class MessageNoteServiceImpl implements MessageNoteService { @@ -47,6 +48,9 @@ public class MessageNoteServiceImpl implements MessageNoteService {
47 @Resource 48 @Resource
48 private MessageNoteMapper messageNoteMapper; 49 private MessageNoteMapper messageNoteMapper;
49 50
  51 + @Resource
  52 + private DirectUtils directUtils;
  53 +
50 @Override 54 @Override
51 @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED) 55 @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
52 public int deleteByPrimaryKey(String id) 56 public int deleteByPrimaryKey(String id)
@@ -80,7 +84,7 @@ public class MessageNoteServiceImpl implements MessageNoteService { @@ -80,7 +84,7 @@ public class MessageNoteServiceImpl implements MessageNoteService {
80 } 84 }
81 85
82 @Override 86 @Override
83 - public int insertSelective(MessageNote record) 87 + public int insertSelective(MessageNote record) throws Exception
84 { 88 {
85 return validateNoteAndFill(record); 89 return validateNoteAndFill(record);
86 } 90 }
@@ -164,15 +168,15 @@ public class MessageNoteServiceImpl implements MessageNoteService { @@ -164,15 +168,15 @@ public class MessageNoteServiceImpl implements MessageNoteService {
164 messageNote.setId(IdUtils.generateId()); 168 messageNote.setId(IdUtils.generateId());
165 169
166 // 填充,用户名称 170 // 填充,用户名称
167 - UserInfo userInfo = userInfoService.selectByPrimaryKey(messageNote.getUserId());  
168 - messageNote.setUsername(userInfo.getUsername()); 171 +// UserInfo userInfo = userInfoService.selectByPrimaryKey(messageNote.getUserId());
  172 +// messageNote.setUsername(userInfo.getUsername());
169 173
170 // 填充,发送内容(编辑 or 新增) 174 // 填充,发送内容(编辑 or 新增)
171 messageNote.setSendContent(messageNote.getAlias_sendContent().getBytes()); 175 messageNote.setSendContent(messageNote.getAlias_sendContent().getBytes());
172 176
173 // 填充,服务器名称 177 // 填充,服务器名称
174 - BusServer busServer = busServerService.selectByPrimaryKey(messageNote.getServerId());  
175 - messageNote.setServerName(busServer.getServerName()); 178 +// BusServer busServer = busServerService.selectByPrimaryKey(messageNote.getServerId());
  179 +// messageNote.setServerName(busServer.getServerName());
176 180
177 // 填充,虚拟主机名称 181 // 填充,虚拟主机名称
178 VirtualHost virtualHost = virtualHostService.selectByPrimaryKey(messageNote.getVirtualHostId()); 182 VirtualHost virtualHost = virtualHostService.selectByPrimaryKey(messageNote.getVirtualHostId());
@@ -205,9 +209,35 @@ public class MessageNoteServiceImpl implements MessageNoteService { @@ -205,9 +209,35 @@ public class MessageNoteServiceImpl implements MessageNoteService {
205 * @param messageNote {@link MessageNote} 209 * @param messageNote {@link MessageNote}
206 * @return 发送信息记录的条数 210 * @return 发送信息记录的条数
207 */ 211 */
208 - public int validateNoteAndFill(MessageNote messageNote) 212 + public int validateNoteAndFill(MessageNote messageNote) throws Exception
209 { 213 {
210 - return validateNote(messageNote) ? messageNoteMapper.insertSelective(note_fillName(messageNote)) : 0; 214 + if (validateNote(messageNote)) {
  215 + // 填充,用户名称
  216 + UserInfo userInfo = userInfoService.selectByPrimaryKey(messageNote.getUserId());
  217 + messageNote.setUsername(userInfo.getUsername());
  218 + // 填充,服务器名称
  219 + BusServer busServer = busServerService.selectByPrimaryKey(messageNote.getServerId());
  220 + messageNote.setServerName(busServer.getServerName());
  221 +
  222 + MessageNote note = note_fillName(messageNote);
  223 + // 发送到MQ服务器
  224 + XmlData xmlData = XmlData.builder()
  225 + .sender(note.getUsername())
  226 + .password(userInfo.getPassword())
  227 + .sendContent(note.getAlias_sendContent())
  228 + .sendDateTime(note.getSendTime())
  229 + .exchangeName(note.getExchangeName())
  230 + .routingKeyName(note.getRoutingKeyName())
  231 + .virtualHostName(note.getVirtualHostName())
  232 + .serverName(note.getServerName())
  233 + .serverIp(busServer.getServerIp())
  234 + .serverPort(busServer.getServerPort())
  235 + .build();
  236 + directUtils.sendMessage(xmlData);
  237 + return messageNoteMapper.insertSelective(note);
  238 + } else {
  239 + return 0;
  240 + }
211 } 241 }
212 } 242 }
213 243