|
|
@ -4,14 +4,21 @@ import com.alibaba.fastjson.JSON; |
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
import com.epmet.commons.tools.config.MqConfig; |
|
|
|
import com.epmet.commons.tools.constant.NumConstant; |
|
|
|
import com.epmet.commons.tools.dto.form.mq.EventClassDto; |
|
|
|
import com.epmet.commons.tools.dto.form.mq.MqBaseMsgDTO; |
|
|
|
import com.epmet.commons.tools.dto.form.mq.MqReturnBaseResult; |
|
|
|
import com.epmet.commons.tools.enums.MqMethodPathEnum; |
|
|
|
import com.epmet.commons.tools.exception.EpmetErrorCode; |
|
|
|
import com.epmet.commons.tools.exception.ValidateException; |
|
|
|
import com.epmet.commons.tools.validator.ValidatorUtils; |
|
|
|
import com.epmet.commons.tools.validator.group.DefaultGroup; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.springframework.stereotype.Component; |
|
|
|
|
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
/** |
|
|
|
* 发送亿联云消息工具类 |
|
|
|
* |
|
|
@ -21,7 +28,7 @@ import org.springframework.stereotype.Component; |
|
|
|
@Slf4j |
|
|
|
@Component |
|
|
|
public class SendMqMsgUtils { |
|
|
|
private static MqConfig mqStaticConfig; |
|
|
|
private static MqConfig mqConfig; |
|
|
|
|
|
|
|
/** |
|
|
|
* desc:发送mq消息 |
|
|
@ -29,19 +36,19 @@ public class SendMqMsgUtils { |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
public static Result<String> sendMsg(MqBaseMsgDTO msg) { |
|
|
|
if (mqStaticConfig == null) { |
|
|
|
mqStaticConfig = SpringContextUtils.getBean(MqConfig.class); |
|
|
|
if (mqConfig == null) { |
|
|
|
mqConfig = SpringContextUtils.getBean(MqConfig.class); |
|
|
|
} |
|
|
|
log.debug("sendMsg param:{}", JSON.toJSONString(msg)); |
|
|
|
try { |
|
|
|
// TODO
|
|
|
|
//ValidatorUtils.validateEntity(msg, null);
|
|
|
|
ValidatorUtils.validateEntity(msg, DefaultGroup.class); |
|
|
|
} catch (ValidateException e) { |
|
|
|
return new Result<String>().error(e.getMsg()); |
|
|
|
} |
|
|
|
msg.setAppId(mqStaticConfig.getAppId()); |
|
|
|
msg.setRequestUrl(mqStaticConfig.getHost().concat(MqMethodPathEnum.SEND_MSG.getCode())); |
|
|
|
msg.setToken(mqStaticConfig.getToken()); |
|
|
|
msg.setAppId(mqConfig.getAppId()); |
|
|
|
msg.setRequestUrl(mqConfig.getHost().concat(MqMethodPathEnum.SEND_MSG.getCode())); |
|
|
|
msg.setToken(mqConfig.getToken()); |
|
|
|
try { |
|
|
|
Result<String> result = HttpClientManager.getInstance().sendPostByHttps(msg.getRequestUrl(), JSON.toJSONString(msg)); |
|
|
|
log.debug("sendMsg result:{}", JSON.toJSONString(result)); |
|
|
@ -66,4 +73,42 @@ public class SendMqMsgUtils { |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* 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)); |
|
|
|
log.debug("getEventClassList result:{}", JSON.toJSONString(result)); |
|
|
|
if (result.success()) { |
|
|
|
MqReturnBaseResult resultResult = JSON.parseObject(result.getData(), MqReturnBaseResult.class); |
|
|
|
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.debug("sendMsg exception", e); |
|
|
|
return new Result<List<EventClassDto>>().error(EpmetErrorCode.SERVER_ERROR.getCode(), EpmetErrorCode.SERVER_ERROR.getMsg()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|