|
@ -28,85 +28,91 @@ import java.util.Map; |
|
|
@Slf4j |
|
|
@Slf4j |
|
|
@Component |
|
|
@Component |
|
|
public class SendMqMsgUtils { |
|
|
public class SendMqMsgUtils { |
|
|
private static MqConfig mqConfig; |
|
|
private static MqConfig mqConfig; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* desc:发送mq消息 |
|
|
* desc:发送mq消息(如果失败重试1次) |
|
|
* |
|
|
* |
|
|
* @return |
|
|
* @return |
|
|
*/ |
|
|
*/ |
|
|
public static Result<String> sendMsg(MqBaseMsgDTO msg) { |
|
|
public static Result<String> sendMsg(MqBaseMsgDTO msg) { |
|
|
if (mqConfig == null) { |
|
|
if (mqConfig == null) { |
|
|
mqConfig = SpringContextUtils.getBean(MqConfig.class); |
|
|
mqConfig = SpringContextUtils.getBean(MqConfig.class); |
|
|
} |
|
|
} |
|
|
log.info("sendMsg param:{}", JSON.toJSONString(msg)); |
|
|
log.info("sendMsg param:{}", JSON.toJSONString(msg)); |
|
|
try { |
|
|
try { |
|
|
// TODO
|
|
|
// TODO
|
|
|
ValidatorUtils.validateEntity(msg, DefaultGroup.class); |
|
|
ValidatorUtils.validateEntity(msg, DefaultGroup.class); |
|
|
} catch (ValidateException e) { |
|
|
} catch (ValidateException e) { |
|
|
return new Result<String>().error(e.getMsg()); |
|
|
return new Result<String>().error(e.getMsg()); |
|
|
} |
|
|
} |
|
|
msg.setAppId(mqConfig.getAppId()); |
|
|
msg.setAppId(mqConfig.getAppId()); |
|
|
msg.setRequestUrl(mqConfig.getHost().concat(MqMethodPathEnum.SEND_MSG.getCode())); |
|
|
msg.setRequestUrl(mqConfig.getHost().concat(MqMethodPathEnum.SEND_MSG.getCode())); |
|
|
msg.setToken(mqConfig.getToken()); |
|
|
msg.setToken(mqConfig.getToken()); |
|
|
try { |
|
|
try { |
|
|
Result<String> result = HttpClientManager.getInstance().sendPostByHttps(msg.getRequestUrl(), JSON.toJSONString(msg)); |
|
|
int retryTime = 0; |
|
|
log.info("sendMsg result:{}", JSON.toJSONString(result)); |
|
|
Result<String> result = null; |
|
|
if (result.success()) { |
|
|
do { |
|
|
MqReturnBaseResult resultResult = JSON.parseObject(result.getData(), MqReturnBaseResult.class); |
|
|
retryTime++; |
|
|
if (resultResult.getErrCode().equals(NumConstant.ZERO)) { |
|
|
result = HttpClientManager.getInstance().sendPostByHttps(msg.getRequestUrl(), JSON.toJSONString(msg)); |
|
|
JSONObject jsonObject = JSON.parseObject(resultResult.getData()); |
|
|
log.info("sendMsg retryTime:{},result:{}", retryTime, JSON.toJSONString(result)); |
|
|
return new Result<String>().ok(jsonObject.getString("msgId")); |
|
|
} while ((!result.success()) && retryTime < 2); |
|
|
} else { |
|
|
|
|
|
log.error("sendMsg fail,resultData:{}", JSON.toJSONString(resultResult)); |
|
|
|
|
|
return new Result<String>().error(EpmetErrorCode.SERVER_ERROR.getCode(), resultResult.getErrMsg()); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
Result<String> resultResult = new Result<>(); |
|
|
|
|
|
resultResult.error(result.getCode(), result.getMsg()); |
|
|
|
|
|
resultResult.setInternalMsg(result.getInternalMsg()); |
|
|
|
|
|
return resultResult; |
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
log.error("sendMsg exception", e); |
|
|
|
|
|
return new Result<String>().error(EpmetErrorCode.SERVER_ERROR.getCode(), EpmetErrorCode.SERVER_ERROR.getMsg()); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (result.success()) { |
|
|
|
|
|
MqReturnBaseResult resultResult = JSON.parseObject(result.getData(), MqReturnBaseResult.class); |
|
|
|
|
|
if (resultResult.getErrCode().equals(NumConstant.ZERO)) { |
|
|
|
|
|
JSONObject jsonObject = JSON.parseObject(resultResult.getData()); |
|
|
|
|
|
return new Result<String>().ok(jsonObject.getString("msgId")); |
|
|
|
|
|
} else { |
|
|
|
|
|
log.error("sendMsg fail,resultData:{}", JSON.toJSONString(resultResult)); |
|
|
|
|
|
return new Result<String>().error(EpmetErrorCode.SERVER_ERROR.getCode(), resultResult.getErrMsg()); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
Result<String> resultResult = new Result<>(); |
|
|
|
|
|
resultResult.error(result.getCode(), result.getMsg()); |
|
|
|
|
|
resultResult.setInternalMsg(result.getInternalMsg()); |
|
|
|
|
|
return resultResult; |
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
log.error("sendMsg exception", e); |
|
|
|
|
|
return new Result<String>().error(EpmetErrorCode.SERVER_ERROR.getCode(), EpmetErrorCode.SERVER_ERROR.getMsg()); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* desc:发送mq消息 |
|
|
|
|
|
* |
|
|
|
|
|
* @return |
|
|
|
|
|
*/ |
|
|
|
|
|
public static Result<List<EventClassDto>> getEventClassList() { |
|
|
|
|
|
if (mqConfig == null) { |
|
|
|
|
|
mqConfig = SpringContextUtils.getBean(MqConfig.class); |
|
|
|
|
|
} |
|
|
|
|
|
Map<String, String> param = new HashMap<>(); |
|
|
|
|
|
param.put("appId", mqConfig.getAppId()); |
|
|
|
|
|
param.put("token", mqConfig.getToken()); |
|
|
|
|
|
String requestUrl = mqConfig.getHost().concat(MqMethodPathEnum.GET_EVENT_LIST.getCode()); |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
/** |
|
|
Result<String> result = HttpClientManager.getInstance().sendPostByHttps(requestUrl, JSON.toJSONString(param)); |
|
|
* desc:发送mq消息 |
|
|
log.info("getEventClassList result:{}", JSON.toJSONString(result)); |
|
|
* |
|
|
if (result.success()) { |
|
|
* @return |
|
|
MqReturnBaseResult resultResult = JSON.parseObject(result.getData(), MqReturnBaseResult.class); |
|
|
*/ |
|
|
if (resultResult.getErrCode().equals(NumConstant.ZERO)) { |
|
|
public static Result<List<EventClassDto>> getEventClassList() { |
|
|
List<EventClassDto> eventClassDto = JSON.parseArray(resultResult.getData(), EventClassDto.class); |
|
|
if (mqConfig == null) { |
|
|
return new Result<List<EventClassDto>>().ok(eventClassDto); |
|
|
mqConfig = SpringContextUtils.getBean(MqConfig.class); |
|
|
} else { |
|
|
} |
|
|
log.error("sendMsg fail,resultData:{}", JSON.toJSONString(resultResult)); |
|
|
Map<String, String> param = new HashMap<>(); |
|
|
return new Result<List<EventClassDto>>().error(EpmetErrorCode.SERVER_ERROR.getCode(), resultResult.getErrMsg()); |
|
|
param.put("appId", mqConfig.getAppId()); |
|
|
} |
|
|
param.put("token", mqConfig.getToken()); |
|
|
} |
|
|
String requestUrl = mqConfig.getHost().concat(MqMethodPathEnum.GET_EVENT_LIST.getCode()); |
|
|
Result<List<EventClassDto>> resultResult = new Result<>(); |
|
|
|
|
|
resultResult.error(result.getCode(), result.getMsg()); |
|
|
try { |
|
|
resultResult.setInternalMsg(result.getInternalMsg()); |
|
|
Result<String> result = HttpClientManager.getInstance().sendPostByHttps(requestUrl, JSON.toJSONString(param)); |
|
|
return resultResult; |
|
|
log.info("getEventClassList result:{}", JSON.toJSONString(result)); |
|
|
} catch (Exception e) { |
|
|
if (result.success()) { |
|
|
log.error("sendMsg exception", e); |
|
|
MqReturnBaseResult resultResult = JSON.parseObject(result.getData(), MqReturnBaseResult.class); |
|
|
return new Result<List<EventClassDto>>().error(EpmetErrorCode.SERVER_ERROR.getCode(), EpmetErrorCode.SERVER_ERROR.getMsg()); |
|
|
if (resultResult.getErrCode().equals(NumConstant.ZERO)) { |
|
|
} |
|
|
List<EventClassDto> eventClassDto = JSON.parseArray(resultResult.getData(), EventClassDto.class); |
|
|
} |
|
|
return new Result<List<EventClassDto>>().ok(eventClassDto); |
|
|
|
|
|
} else { |
|
|
|
|
|
log.error("sendMsg fail,resultData:{}", JSON.toJSONString(resultResult)); |
|
|
|
|
|
return new Result<List<EventClassDto>>().error(EpmetErrorCode.SERVER_ERROR.getCode(), resultResult.getErrMsg()); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
Result<List<EventClassDto>> resultResult = new Result<>(); |
|
|
|
|
|
resultResult.error(result.getCode(), result.getMsg()); |
|
|
|
|
|
resultResult.setInternalMsg(result.getInternalMsg()); |
|
|
|
|
|
return resultResult; |
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
log.error("sendMsg exception", e); |
|
|
|
|
|
return new Result<List<EventClassDto>>().error(EpmetErrorCode.SERVER_ERROR.getCode(), EpmetErrorCode.SERVER_ERROR.getMsg()); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|