Commit 01326fff by liuyu

Merge branch 'feature' into 'release'

2023年05/22 模板查询dubbo接口。当日模板记录清空。

See merge request !46
parents 0ed609f0 0924ec3f
package com.zhiwei.middleware.automatic.server.util;
import com.alibaba.fastjson.JSONObject;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import java.io.*;
import java.util.*;
......@@ -9,19 +11,19 @@ public class CosineSimilarity {
private static final List<String> BRAND_WORDS = new ArrayList<>();
private static final String path = "classpath:static/brandWords.json";
private static final String path = "static/brandWords.json";
static {
try {
InputStream inputStream = new FileInputStream(path);
String jsonStr = readJsonFile(inputStream);
Resource resource = new ClassPathResource(path);
String jsonStr = readJsonFile(resource.getInputStream());
if (null != jsonStr) {
List<List> array = JSONObject.parseArray(jsonStr, List.class);
for (List str : array) {
BRAND_WORDS.addAll(str);
}
}
} catch (FileNotFoundException e) {
} catch (IOException e) {
e.printStackTrace();
}
}
......
......@@ -13,6 +13,64 @@ public class Tools {
}
/**
* 排序多个标签,防止相同标签不同顺序,被认为是两种标签
*
* @param tag
* @return
*/
public static String sortTag(String tag) {
String[] tags = tag.split(",");
if (tags.length > 2) {
List<String> tempTagList = Arrays.asList(tags).subList(1, tags.length);
tempTagList.sort(Comparator.naturalOrder());
return "," + StringUtils.join(tempTagList, ",");
}
return tag;
}
/**
* 是否符合过滤规则
*
* @param tags 标签
* @return true:符合 false:不符合
*/
public static boolean filterTag(List<String> tags, String mtag) {
if (tags != null) {
for (String tag : tags) {
if (mtag.equals(Tools.sortTag(tag))) {
return true;
}
}
return tags.isEmpty() && "".equals(mtag);
}
return true;
}
/**
* 根据不同字段排序
*
* @param list
* @param orderField
* @param isAsc
*/
public static void sortByField(List<Map<String, Object>> list, String orderField, boolean isAsc) {
int ascNum = isAsc ? 1 : -1;
switch (orderField) {
case "templateTitle":
list.sort((o1, o2) -> ascNum * (((String) o1.get(orderField)).compareTo((String) o2.get(orderField))));
break;
case "createTime":
case "updateTime":
case "markSum":
list.sort((o1, o2) -> ascNum * (((Long) o1.get(orderField)).compareTo((Long) o2.get(orderField))));
break;
default:
break;
}
}
/**
* 返回组合K值
*
* @param keys
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment