作者 王勇

版本迭代,收发消息,与mysql断开联系

@@ -44,12 +44,12 @@ public class RabbitController { @@ -44,12 +44,12 @@ public class RabbitController {
44 @Resource 44 @Resource
45 private AsyncTaskService asyncTaskService; 45 private AsyncTaskService asyncTaskService;
46 46
47 - @PostMapping("/product/old")  
48 - public ResultJson productOld(String xmlStr) 47 + @PostMapping("/product_old")
  48 + public ResultJson productOld(String xmlMessage)
49 { 49 {
50 try { 50 try {
51 // 1、解析 xml 文件,获取数据 51 // 1、解析 xml 文件,获取数据
52 - XmlData xmlData = xmlUtils.parsingMessage(xmlStr); 52 + XmlData xmlData = xmlUtils.parsingMessage(xmlMessage);
53 String SNDR = xmlData.getSender(); 53 String SNDR = xmlData.getSender();
54 String RCVR = xmlData.getQueueName(); 54 String RCVR = xmlData.getQueueName();
55 Date DDTM = xmlData.getSendDateTime() == null ? new Date() : xmlData.getSendDateTime(); 55 Date DDTM = xmlData.getSendDateTime() == null ? new Date() : xmlData.getSendDateTime();
@@ -67,7 +67,7 @@ public class RabbitController { @@ -67,7 +67,7 @@ public class RabbitController {
67 } 67 }
68 } 68 }
69 69
70 - @PostMapping("/product/new") 70 + @PostMapping("/product_new")
71 public ResultJson productNew(@RequestParam(value = "SNDR") String SNDR, 71 public ResultJson productNew(@RequestParam(value = "SNDR") String SNDR,
72 @RequestParam(value = "RCVR", required = false) String RCVR, 72 @RequestParam(value = "RCVR", required = false) String RCVR,
73 @DateTimeFormat(pattern = "yyyyMMddHHmmss") 73 @DateTimeFormat(pattern = "yyyyMMddHHmmss")
@@ -78,7 +78,7 @@ public class RabbitController { @@ -78,7 +78,7 @@ public class RabbitController {
78 @RequestParam(value = "SEQN", required = false) String SEQN, 78 @RequestParam(value = "SEQN", required = false) String SEQN,
79 @RequestParam(value = "VSHT") String VSHT, 79 @RequestParam(value = "VSHT") String VSHT,
80 @RequestParam(value = "SERV") String SERV, 80 @RequestParam(value = "SERV") String SERV,
81 - @RequestParam(value = "content") String content) 81 + @RequestParam(value = "MSG") String MSG)
82 { 82 {
83 try { 83 try {
84 // 1、获取数据 84 // 1、获取数据
@@ -92,13 +92,14 @@ public class RabbitController { @@ -92,13 +92,14 @@ public class RabbitController {
92 .sequence(SEQN) 92 .sequence(SEQN)
93 .virtualHostName(VSHT) 93 .virtualHostName(VSHT)
94 .serverName(SERV) 94 .serverName(SERV)
95 - .sendContent(content) 95 + .sendContent(MSG)
96 .build(); 96 .build();
97 // 2、校验格式、数据 97 // 2、校验格式、数据
98 ResultJson resultJson = xmlUtils.checkFormatAndData(xmlData); 98 ResultJson resultJson = xmlUtils.checkFormatAndData(xmlData);
99 if (!"200".equals(resultJson.getCode())) { 99 if (!"200".equals(resultJson.getCode())) {
100 return resultJson; 100 return resultJson;
101 } 101 }
  102 + log.info(""+xmlData);
102 XmlData sentData = (XmlData) resultJson.getData(); 103 XmlData sentData = (XmlData) resultJson.getData();
103 // 3、通过格式校验之后,进行配置校验 104 // 3、通过格式校验之后,进行配置校验
104 Boolean binding = userMessageBindingService.validateXmlBinding(sentData); 105 Boolean binding = userMessageBindingService.validateXmlBinding(sentData);
@@ -7,7 +7,7 @@ package com.sunyo.wlpt.message.bus.service.exception; @@ -7,7 +7,7 @@ package com.sunyo.wlpt.message.bus.service.exception;
7 */ 7 */
8 8
9 public enum CustomExceptionType { 9 public enum CustomExceptionType {
10 - MESSAGE_SUCCESS("10200", "消息发送成功"), 10 + MESSAGE_SUCCESS("10200", "发送消息,成功!"),
11 RECEIVE_SUCCESS("20200", "接收消息,成功!"), 11 RECEIVE_SUCCESS("20200", "接收消息,成功!"),
12 12
13 RECEIVE_SERVER_EXCEPTION("20500", "服务器异常,接收消息失败!请联系管理员处理"), 13 RECEIVE_SERVER_EXCEPTION("20500", "服务器异常,接收消息失败!请联系管理员处理"),
@@ -172,10 +172,11 @@ public class ElasticsearchService { @@ -172,10 +172,11 @@ public class ElasticsearchService {
172 * 172 *
173 * @param messageNote {@link MessageNote} 173 * @param messageNote {@link MessageNote}
174 */ 174 */
175 - public void saveOrUpdateMessageNote(MessageNote messageNote) 175 + public Boolean saveOrUpdateMessageNote(MessageNote messageNote)
176 { 176 {
177 // id,存在即是更新;id不存在即是保存 177 // id,存在即是更新;id不存在即是保存
178 - messageNoteRepository.save(messageNote); 178 + MessageNote save = messageNoteRepository.save(messageNote);
  179 + return save != null ? true : false;
179 } 180 }
180 181
181 /** 182 /**
@@ -67,18 +67,18 @@ public class MessageNoteServiceImpl implements MessageNoteService { @@ -67,18 +67,18 @@ public class MessageNoteServiceImpl implements MessageNoteService {
67 if (id.contains(splitItem)) { 67 if (id.contains(splitItem)) {
68 String[] split = id.split(splitItem); 68 String[] split = id.split(splitItem);
69 for (int i = 0; i < split.length; i++) { 69 for (int i = 0; i < split.length; i++) {
70 - MessageNote messageNote = messageNoteMapper.selectByPrimaryKey(split[i]);  
71 - if (messageNote != null) {  
72 - messageNoteMapper.deleteByPrimaryKey(split[i]);  
73 - } 70 +// MessageNote messageNote = messageNoteMapper.selectByPrimaryKey(split[i]);
  71 +// if (messageNote != null) {
  72 +// messageNoteMapper.deleteByPrimaryKey(split[i]);
  73 +// }
74 elasticsearchService.deleteMessageNoteById(split[i]); 74 elasticsearchService.deleteMessageNoteById(split[i]);
75 } 75 }
76 return 2; 76 return 2;
77 } else { 77 } else {
78 - MessageNote messageNote = messageNoteMapper.selectByPrimaryKey(id);  
79 - if (messageNote != null) {  
80 - messageNoteMapper.deleteByPrimaryKey(id);  
81 - } 78 +// MessageNote messageNote = messageNoteMapper.selectByPrimaryKey(id);
  79 +// if (messageNote != null) {
  80 +// messageNoteMapper.deleteByPrimaryKey(id);
  81 +// }
82 elasticsearchService.deleteMessageNoteById(id); 82 elasticsearchService.deleteMessageNoteById(id);
83 return 2; 83 return 2;
84 } 84 }
@@ -163,10 +163,9 @@ public class MessageNoteServiceImpl implements MessageNoteService { @@ -163,10 +163,9 @@ public class MessageNoteServiceImpl implements MessageNoteService {
163 .description(description) 163 .description(description)
164 .build(); 164 .build();
165 MessageNote note = note_fillId(messageNote); 165 MessageNote note = note_fillId(messageNote);
166 - int num = messageNoteMapper.insertSelective(note); 166 +// int num = messageNoteMapper.insertSelective(note);
167 // ES没有事务,故先执行SQL 167 // ES没有事务,故先执行SQL
168 - insertMessageToES(note);  
169 - return num; 168 + return insertMessageToES(note) ? 1 : 0;
170 } 169 }
171 170
172 /** 171 /**
@@ -262,10 +261,9 @@ public class MessageNoteServiceImpl implements MessageNoteService { @@ -262,10 +261,9 @@ public class MessageNoteServiceImpl implements MessageNoteService {
262 .superPassword(busServer.getSuperPassword()) 261 .superPassword(busServer.getSuperPassword())
263 .build(); 262 .build();
264 directUtils.sendMessage(xmlData); 263 directUtils.sendMessage(xmlData);
265 - int num = messageNoteMapper.insertSelective(note); 264 +// int num = messageNoteMapper.insertSelective(note);
266 // ES没有事务,故先执行SQL 265 // ES没有事务,故先执行SQL
267 - insertMessageToES(note);  
268 - return num; 266 + return insertMessageToES(note) ? 1 : 0;
269 } else { 267 } else {
270 return 0; 268 return 0;
271 } 269 }
@@ -277,9 +275,9 @@ public class MessageNoteServiceImpl implements MessageNoteService { @@ -277,9 +275,9 @@ public class MessageNoteServiceImpl implements MessageNoteService {
277 * 275 *
278 * @param note 消息 276 * @param note 消息
279 */ 277 */
280 - public void insertMessageToES(MessageNote note) 278 + public Boolean insertMessageToES(MessageNote note)
281 { 279 {
282 - elasticsearchService.saveOrUpdateMessageNote(note); 280 + return elasticsearchService.saveOrUpdateMessageNote(note);
283 } 281 }
284 } 282 }
285 283
@@ -56,9 +56,10 @@ public class XmlUtils { @@ -56,9 +56,10 @@ public class XmlUtils {
56 Element msg = document.getRootElement(); 56 Element msg = document.getRootElement();
57 Element meta = msg.element("META"); 57 Element meta = msg.element("META");
58 Date sendDateTime = DateUtils.strToDateLong(meta.elementText("DDTM")); 58 Date sendDateTime = DateUtils.strToDateLong(meta.elementText("DDTM"));
  59 + // msg.elementText("BODY");
59 60
60 XmlData xmlData = XmlData.builder() 61 XmlData xmlData = XmlData.builder()
61 - .sendContent(msg.elementText("BODY")) 62 + .sendContent(xmlStr)
62 .sender(meta.elementText("SNDR")) 63 .sender(meta.elementText("SNDR"))
63 .queueName(meta.elementText("RCVR")) 64 .queueName(meta.elementText("RCVR"))
64 .sendTime(meta.elementText("DDTM")) 65 .sendTime(meta.elementText("DDTM"))
@@ -201,7 +202,7 @@ public class XmlUtils { @@ -201,7 +202,7 @@ public class XmlUtils {
201 if (!virtualHost.getId().equals(busQueue.getVirtualHostId())) { 202 if (!virtualHost.getId().equals(busQueue.getVirtualHostId())) {
202 return ResultJson.error(CustomExceptionType.RECEIVE_HOST_QUEUE_ERROR); 203 return ResultJson.error(CustomExceptionType.RECEIVE_HOST_QUEUE_ERROR);
203 } 204 }
204 - if(busQueueService.validateByUserNameAndQueueName(receiver,queueName).size()==0){ 205 + if (busQueueService.validateByUserNameAndQueueName(receiver, queueName).size() == 0) {
205 return ResultJson.error(CustomExceptionType.RECEIVE_USER_QUEUE_ERROR); 206 return ResultJson.error(CustomExceptionType.RECEIVE_USER_QUEUE_ERROR);
206 } 207 }
207 208