kimi42345
2020-03-22 d0451fdd55195901e65e5c4b3b64028a86f9e669
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
71
72
73
74
75
76
package com.highdatas.mdm.util;
 
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.http.HttpMethod;
import org.springframework.stereotype.Component;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.util.StringUtils;
 
@ConfigurationProperties(prefix = "mask")
@Component
public class MaskClient {
 
    @Value("${mask.url}")
    String maskUrl;
 
    String prefix ;
 
    private MaskClient() {
        this.prefix = "/api/datacvg/redis/";
    }
    public  boolean putRedisVal(String key, String value) {
        String url = maskUrl + prefix + "put";
        MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
        params.set("key",key);
        params.set("value",value);
        params.set("type",Constant.MainData);
        String s = HttpUtils.HttpRestClient(url, HttpMethod.POST, params);
        JSONObject result = (JSONObject) JSON.parse(s);
        String sucess = result.getString(Constant.Success);
        if (StringUtils.isEmpty(sucess) || !Boolean.valueOf(sucess)) {
            return false;
        }else {
            return true;
        }
    }
 
    public String getRedisVal(String key) {
        try {
            String url =  maskUrl + prefix + "get";
            MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
            params.set("key",key);
            params.set("type",Constant.MainData);
            String s = HttpUtils.HttpRestClient(url, HttpMethod.POST, params);
            JSONObject result = (JSONObject) JSON.parse(s);
            String sucess = result.getString(Constant.Success);
            if (StringUtils.isEmpty(sucess) || !Boolean.valueOf(sucess)) {
                return null;
            }else {
                return result.getString(Constant.Data);
            }
        }catch (Exception e){
            e.printStackTrace();
            return null;
        }
 
    }
 
    public boolean deleteRedisVal(String key) {
        String url =  maskUrl + prefix + "delete";
        MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
        params.set("key",key);
        params.set("type",Constant.MainData);
        String s = HttpUtils.HttpRestClient(url, HttpMethod.POST, params);
        JSONObject result = (JSONObject) JSON.parse(s);
        String sucess = result.getString(Constant.Success);
        if (StringUtils.isEmpty(sucess) || !Boolean.valueOf(sucess)) {
            return false;
        }else {
            return true;
        }
    }
}