package com.highdatas.mdm.util.pool;
|
|
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSONObject;
|
import com.highdatas.mdm.service.ISysDispenseConfigService;
|
import com.highdatas.mdm.util.DbUtils;
|
import com.highdatas.mdm.util.HttpUtils;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
import org.springframework.http.HttpMethod;
|
import org.springframework.http.MediaType;
|
import org.springframework.stereotype.Component;
|
|
import java.util.Map;
|
|
@ConfigurationProperties(prefix = "mq")
|
@Component
|
public class MqClient {
|
|
@Value("${mq.url}")
|
String url;
|
@Autowired
|
ISysDispenseConfigService sysDispenseConfigService;
|
|
String prefix ;
|
|
private MqClient() {
|
this.prefix = "/api/datacvg/mqProducer/";
|
|
}
|
|
public MqResult syncProduce(MqEntity mqEntity) {
|
String url = this.url + prefix + "syncProduce";
|
MqResult mqResult = sendMqEntity(url, mqEntity);
|
return mqResult;
|
}
|
|
public MqResult oneWayProduce(MqEntity mqEntity) {
|
String url = this.url + prefix + "oneWayProduce";
|
MqResult mqResult = sendMqEntity(url, mqEntity);
|
return mqResult;
|
}
|
|
public MqResult asyncProduce(MqEntity mqEntity) {
|
String url = this.url + prefix + "asyncProduce";
|
MqResult mqResult = sendMqEntity(url, mqEntity);
|
return mqResult;
|
}
|
|
|
|
|
private MqResult sendMqEntity(String url, MqEntity mqEntity) {
|
JSONObject mqJsonObject = (JSONObject) JSON.toJSON(mqEntity);
|
JSONObject msgBody = mqJsonObject.getJSONObject("msgBody");
|
Map<String, Object> dataMap = DbUtils.JsonObjectToHashMap(mqJsonObject);
|
String bodyStr = JSONObject.toJSONString(msgBody);
|
dataMap.put("msgBody", bodyStr);
|
dataMap.remove("increment");
|
dataMap.remove("pageSize");
|
dataMap.remove("logId");
|
dataMap.remove("type");
|
dataMap.remove("userId");
|
dataMap.remove("maintainId");
|
dataMap.remove("pages");
|
dataMap.remove("dataId");
|
dataMap.remove("pageNo");
|
dataMap.remove("msgCode");
|
dataMap.remove("totalSize");
|
|
// dataMap.put("msgTagName", "datas");
|
String s = HttpUtils.HttpRestClientByObjectParams(url, HttpMethod.POST, dataMap,null, null,MediaType.APPLICATION_JSON);
|
MqResult mqResult = JSONObject.parseObject(s, MqResult.class);
|
return mqResult;
|
}
|
|
|
}
|