1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package com.highdatas.mdm.util.pool;
 
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) {
        Map<String, Object> dataMap = DbUtils.beanToMap(mqEntity);
        Object msgBody = dataMap.get("msgBody");
        String bodyStr = JSONObject.toJSONString(msgBody);
        dataMap.put("msgBody", bodyStr);
        dataMap.remove("increment");
        dataMap.remove("pageSize");
        dataMap.remove("type");
        dataMap.remove("userId");
        dataMap.remove("maintainId");
        dataMap.remove("pages");
        dataMap.remove("dataId");
        dataMap.remove("pageNo");
        dataMap.remove("msgCode");
        String s = HttpUtils.HttpRestClientByObjectParams(url, HttpMethod.POST, dataMap,null, null,MediaType.APPLICATION_JSON);
        MqResult mqResult = JSONObject.parseObject(s, MqResult.class);
        return mqResult;
    }
 
 
}