|
|
@@ -117,7 +117,7 @@ public class OperationMessageService {
|
|
|
* @return
|
|
|
*/
|
|
|
public ResultContent addOperationMessage(OperationMessage entity) {
|
|
|
- entity.setTime(DateUtils.paresTime(System.currentTimeMillis(), DateUtils.FORMAT_LONG));
|
|
|
+ entity.setTime(DateUtils.paresTime(System.currentTimeMillis(), DateUtils.patternyyyySSS));
|
|
|
entity.setTtl(new Date(System.currentTimeMillis() + ttlMill));
|
|
|
operationMessageDao.save(entity);
|
|
|
// 处理消息
|
|
|
@@ -133,35 +133,46 @@ public class OperationMessageService {
|
|
|
*/
|
|
|
public ResultContent handleOperationMessage(OperationMessage entity) {
|
|
|
boolean isTimeOut = entity.getIsTimeOut();
|
|
|
-
|
|
|
String event = entity.getEvent();
|
|
|
- String data = (String) entity.getData();
|
|
|
- JSONObject json = JSONUtil.parseObj(data);
|
|
|
+ JSONObject json = (JSONObject) entity.getData();
|
|
|
if (json.containsKey("data")) {
|
|
|
Object result = null;
|
|
|
String dataStr = json.getStr("data");
|
|
|
|
|
|
+ boolean isHandleSuccess = true;
|
|
|
+ String handleMsg = "处理成功";
|
|
|
try {
|
|
|
// 判断那个业务处理
|
|
|
if (event.equals("consum")) {
|
|
|
ConsumTransactionsModel model = JSONUtil.toBean(dataStr, ConsumTransactionsModel.class);
|
|
|
-
|
|
|
ResultContent<Object> resultContent = hxzService.consumTransactions(model);
|
|
|
if (resultContent.isSuccess()) {
|
|
|
result = resultContent.getContent();
|
|
|
+ }else {
|
|
|
+ isHandleSuccess = false;
|
|
|
+ handleMsg = resultContent.getMsg();
|
|
|
}
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
- entity.setReIsSuccess(Boolean.FALSE);
|
|
|
- entity.setReMsg(String.format("业务出错出错:%S", e.getMessage()));
|
|
|
+ e.printStackTrace();
|
|
|
+ isHandleSuccess = false;
|
|
|
+ handleMsg = String.format("业务处理出错:%S", e.getMessage());
|
|
|
+ }
|
|
|
+ // 返回结果
|
|
|
+ entity.setResultData(result);
|
|
|
+ // 业务处理失败
|
|
|
+ entity.setIsHandleSuccess(isHandleSuccess);
|
|
|
+ entity.setHandleMsg(handleMsg);
|
|
|
+
|
|
|
+ if (isHandleSuccess) {
|
|
|
+ // 处理成功,返回响应
|
|
|
+ responseMessage(entity);
|
|
|
+ }else {
|
|
|
entity.setReTime(System.currentTimeMillis());
|
|
|
entity.setReTimeStr(DateUtils.paresTime(System.currentTimeMillis(), DateUtils.patternyyyySSS));
|
|
|
operationMessageDao.save(entity);
|
|
|
- return ResultContent.buildFail(e.getMessage());
|
|
|
+ return ResultContent.buildFail(handleMsg);
|
|
|
}
|
|
|
- // 返回结果
|
|
|
- entity.setResultData(result);
|
|
|
- responseMessage(entity);
|
|
|
}
|
|
|
return ResultContent.buildSuccess();
|
|
|
}
|
|
|
@@ -173,30 +184,30 @@ public class OperationMessageService {
|
|
|
* @return
|
|
|
*/
|
|
|
public ResultContent responseMessage(OperationMessage entity) {
|
|
|
- JSONObject jsonObject = new JSONObject();
|
|
|
-
|
|
|
- jsonObject.append("id", entity.getDataId());
|
|
|
+ com.alibaba.fastjson.JSONObject jsonObject = new com.alibaba.fastjson.JSONObject();
|
|
|
+ jsonObject.put("id", entity.getDataId());
|
|
|
Object data = entity.getResultData();
|
|
|
JSONObject object = new JSONObject();
|
|
|
if (ObjectUtils.isNotEmpty(data)) {
|
|
|
String _str = JSONUtil.toJsonStr(data);
|
|
|
object = JSONUtil.parseObj(_str);
|
|
|
}
|
|
|
- jsonObject.append("data", object);
|
|
|
- jsonObject.append("time", System.currentTimeMillis());
|
|
|
- jsonObject.append("ttl", entity.getTtlTime());
|
|
|
- jsonObject.append("event", entity.getEvent());
|
|
|
+ jsonObject.put("data", object);
|
|
|
+ jsonObject.put("time", System.currentTimeMillis());
|
|
|
+ jsonObject.put("ttl", entity.getTtlTime());
|
|
|
+ jsonObject.put("event", entity.getEvent());
|
|
|
String reTopic = String.format("%s/reply", entity.getTopic());
|
|
|
|
|
|
String reMsg = "响应成功";
|
|
|
Boolean reIsSuccess = Boolean.TRUE;
|
|
|
try {
|
|
|
- mqClient.sendObject(reTopic, jsonObject);
|
|
|
+ mqClient.sendObject(reTopic, JSONUtil.toJsonStr(jsonObject));
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
reIsSuccess = Boolean.FALSE;
|
|
|
- reMsg = "响应出错:" + e.getMessage();
|
|
|
+ reMsg = "mqtt响应出错:" + e.getMessage();
|
|
|
}
|
|
|
+ entity.setIsResult(Boolean.TRUE);
|
|
|
entity.setReIsSuccess(reIsSuccess);
|
|
|
entity.setReMsg(reMsg);
|
|
|
entity.setReTime(System.currentTimeMillis());
|