测试用户
2023-04-13 43393f2bb11cbf9e6af40077bbc5284660e8a754
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
package com.common.core.utils;
 
import java.util.*;
import java.util.stream.Collectors;
 
/**
 * @author : zhouxb
 * date: 2017-10-25 23:54
 */
public class StringUtils extends org.apache.commons.lang3.StringUtils {
 
    /**
     * SQL格式化表名和字段名加"`"
     *
     * @param fieldName
     * @return
     */
    public static String formatFieldNameColumn(String fieldName) {
        return new StringBuffer("`").append(fieldName).append("`").toString();
    }
 
    public static String formatStringFiledVal(String fieldName) {
        return new StringBuffer("'").append(fieldName).append("'").toString();
    }
 
    public static String formatFieldNameColumn4Rdb(String fieldName) {
        return new StringBuffer("\"").append(fieldName).append("\"").toString();
    }
 
    /**
     * 去掉字符串指定前缀部分
     *
     * @param source 字符串
     * @param prefix 前缀
     */
    public static String cutPrefix(String source, String prefix) {
        if (isNotBlank(source)) {
            if (isNotEmpty(prefix)) {
                if (source.startsWith(prefix)) {
                    int prefixLen = prefix.length();
                    source = source.substring(prefixLen);
                }
            }
        }
        return source;
    }
 
    /**
     * 去掉字符串指定后缀部分
     *
     * @param source 字符串
     * @param suffix 后缀
     */
    public static String cutSuffix(String source, String suffix) {
        if (isNotBlank(source)) {
            if (isNotEmpty(suffix)) {
                int suffixLen = suffix.length();
                source = source.substring(0, source.length() - suffixLen);
            }
        }
        return source;
    }
 
    /**
     * 去掉字符串中指定字符及其后面部分
     *
     * @param source    字符串
     * @param separator 指定字符
     */
    public static String cutLaterOfCharacter(String source, String separator) {
        if (isNotBlank(source)) {
            if (isNotEmpty(separator)) {
                int index = source.indexOf(separator);
                if (index > -1) {
                    source = source.substring(0, index);
                }
            }
        }
        return source;
    }
 
    /**
     * sql语句like部分
     * 增加对%转义
     *
     * @param in
     * @return
     */
    public static String sqlLike(String in) {
//        if (StringUtils.isNotEmpty(in) && in.contains("%")) {
//            in = in.replace("\\", "\\\\");
//            in = in.replace("%", "\\%");
//            in = in.replace("_", "\\_");
//        }
        return "%" + sqlLikeXML(in) + "%";
    }
 
    public static String sqlLikeXML(String in) {
        if (StringUtils.isNotEmpty(in) && (in.contains("%") || in.contains("_") || in.contains("\\"))) {
            in = in.replace("\\", "\\\\");
            in = in.replace("%", "\\%");
            in = in.replace("_", "\\_");
        }
        return in;
    }
 
    /**
     * 按指定分割符分割字符串,返回结果中不包含空字符串
     */
    public static String[] tokenizeToStringArray(String cs, String delimiters) {
        String[] csAry = org.springframework.util.StringUtils.tokenizeToStringArray(cs, delimiters);
        List<String> result = new ArrayList<>(csAry.length);
        for (String csa : csAry) {
            if (isNotBlank(csa)) {
                result.add(csa);
            }
        }
        return result.toArray(new String[result.size()]);
    }
 
    /**
     * 拆分token方法
     *
     * @param cs
     * @return
     */
    public static String[] tokenizeToStringArray(String cs) {
        return tokenizeToStringArray(cs, ",");
    }
 
    /**
     * 将集合用转换为指定分隔符连接的字符串
     *
     * @param coll
     * @param delimiter
     * @return
     */
    public static String collectionToDelimitedString(Collection<?> coll, String delimiter) {
        return org.springframework.util.StringUtils.collectionToDelimitedString(coll, delimiter);
    }
 
    /**
     * 将集合用","连接的字符串
     *
     * @param coll
     * @return
     */
    public static String collectionToDelimitedString(Collection<?> coll) {
        return collectionToDelimitedString(coll, ",");
    }
 
    /**
     * 将数组转换为用","连接的字符串
     *
     * @param ary
     * @return
     */
//    public static String arrayToCommaDelimitedString(Object[] ary) {
//        return arrayToDelimitedString(ary, ",");
//    }
//
//    /**
//     * 将数组转换为用指定分隔符连接的字符串
//     *
//     * @param ary
//     * @param delimiter
//     * @return
//     */
//    public static String arrayToDelimitedString(Object[] ary, String delimiter) {
//        if (ObjectUtils.isEmpty(ary)) {
//            return "";
//        }
//        if (ary.length == 1) {
//            return ObjectUtils.nullSafeToString(ary[0]);
//        }
//
//        StringBuilder sb = new StringBuilder();
//        for (int i = 0; i < ary.length; i++) {
//            if (i > 0) {
//                sb.append(delimiter);
//            }
//            sb.append(ary[i]);
//        }
//        return sb.toString();
//    }
 
    /**
     * 根据字段类型返回字段作为where条件查询判断字段时使用的分隔符
     *
     * @param type
     * @return
     */
    public static String getSeparator(String type) {
        if ("string".equalsIgnoreCase(type)) {
            return "'";
        } else {
            return "";
        }
    }
 
    /**
     * 返回隐藏信息的String
     *
     * @param input
     * @return
     */
    public static String getConcealStr(String input) {
        String ss = "*";
        String ds = "***";
        if (StringUtils.isNotBlank(input)) {
            if (input.length() <= 2) {
                int i = input.length() / 2;
                if (i == 0) {
                    return ss;
                } else {
                    return input.substring(0, i) + ss;
                }
            } else {
                int i = input.length() / 3;
                return input.substring(0, i) + ds + input.substring(input.length() - i);
            }
        }
        return null;
    }
 
    /**
     * 数据脱敏方法
     *
     * @param input
     * @return
     */
    public static String concealString(String input) {
        if (StringUtils.isEmpty(input)) {
            return input;
        }
 
        return StringUtils.collectionToDelimitedString(Arrays.stream(input.split(",")).map(e -> concealStringSingle(e)).collect(Collectors.toList()));
 
    }
 
    /**
     * 单个字符串数据脱敏方法
     *
     * @param input
     * @return
     */
    public static String concealStringSingle(String input) {
        if (input.startsWith("Untagged") || input.startsWith("Other tag")) {
            return input;
        }
        if (1 == input.length()) {
            return "*";
        }
 
        int i = (int) Math.ceil((double) input.length() / 3);
 
        int j = (int) Math.floor((double) input.length() / 3);
        StringBuffer sbf = new StringBuffer(input.substring(0, i));
        for (int x = 0; x < input.length() - i - j; x++) {
            sbf.append("*");
        }
 
        return sbf.append(input.substring(input.length() - j)).toString();
    }
 
 
//    public static String formatList2SqlInString(List<String> propertyList) {
//        if (CollectionUtils.isNotEmpty(propertyList)) {
//            return propertyList.stream().map(e -> new StringBuffer().append("'").append(e).append("'").toString()).collect(Collectors.joining(CommonSqlConst.F_COMMA));
//        }
//        return null;
//    }
 
//    public static String formatSqlFieldNotBlank(String fieldName) {
//        if (StringUtils.isNotBlank(fieldName)) {
//            return new StringBuffer().append(fieldName).append(" is not null ").append(CommonSqlConst.SQL_AND).append(fieldName).append(" !='' ").toString();
//        }
//        return null;
//    }
 
    public static String formatSqlCondition(String sql) {
        sql = sql.replace("&&", "and").replace("||", "or").replace("`", "");
 
        return sql;
    }
 
    public static String formatByMap(String content, Map<String, String> varValueMap) {
        for(Map.Entry<String,String> entry:varValueMap.entrySet()){
            content=content.replace("{"+entry.getKey()+"}",entry.getValue());
        }
        return content;
    }
}