|
@@ -6,6 +6,7 @@ import java.time.LocalDate;
|
|
|
import java.time.format.DateTimeFormatter;
|
|
import java.time.format.DateTimeFormatter;
|
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
import java.util.function.Consumer;
|
|
import java.util.function.Consumer;
|
|
|
|
|
+import java.util.regex.Pattern;
|
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
import cn.hutool.core.collection.ListUtil;
|
|
import cn.hutool.core.collection.ListUtil;
|
|
@@ -136,6 +137,17 @@ public class FsStoreProductScrmServiceImpl implements IFsStoreProductScrmService
|
|
|
|
|
|
|
|
private final static String CZT = "纯正堂";
|
|
private final static String CZT = "纯正堂";
|
|
|
|
|
|
|
|
|
|
+ private static final Pattern BRACKET_ALL_CONTENT_PATTERN = Pattern.compile("[((].*?[))]");
|
|
|
|
|
+
|
|
|
|
|
+ private static final Pattern SPECIAL_CHAR_PATTERN = Pattern.compile(
|
|
|
|
|
+ "[\\p{Punct}\\u0021-\\u002F\\u003A-\\u0040\\u005B-\\u0060\\u007B-\\u007E\\uFF01-\\uFF0F\\uFF1A-\\uFF20\\uFF3B-\\uFF40\\uFF5B-\\uFF65\\u3000\\u00A0]"
|
|
|
|
|
+ );
|
|
|
|
|
+ private static final Pattern WHITESPACE_PATTERN = Pattern.compile("\\s+");
|
|
|
|
|
+
|
|
|
|
|
+ private static final String BRACKET_NUM_EN = "(数字)";
|
|
|
|
|
+ private static final String BRACKET_NUM_CN = "(数字)";
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 商品关键字检查,这里需要用一些关键字匹配
|
|
* 商品关键字检查,这里需要用一些关键字匹配
|
|
@@ -147,16 +159,48 @@ public class FsStoreProductScrmServiceImpl implements IFsStoreProductScrmService
|
|
|
public SelectForbiddenKeywordsVo selectForbiddenKeywords(String keyWords){
|
|
public SelectForbiddenKeywordsVo selectForbiddenKeywords(String keyWords){
|
|
|
SelectForbiddenKeywordsVo result = new SelectForbiddenKeywordsVo();
|
|
SelectForbiddenKeywordsVo result = new SelectForbiddenKeywordsVo();
|
|
|
List<ForbiddenOnlineMedicine> forbiddenOnlineMedicines = fsStoreProductMapper.selectForbiddenKeywords();
|
|
List<ForbiddenOnlineMedicine> forbiddenOnlineMedicines = fsStoreProductMapper.selectForbiddenKeywords();
|
|
|
-// 将forbiddenOnlineMedicines转换为set
|
|
|
|
|
- Set<String> forbiddenKeywords = forbiddenOnlineMedicines.stream().filter(b-> b.getForbiddenKeywords() != null).map(ForbiddenOnlineMedicine::getForbiddenKeywords).collect(Collectors.toSet());
|
|
|
|
|
|
|
+ //提示语Map
|
|
|
|
|
+ Map<String,String> promptWordsMap = new HashMap<>();
|
|
|
|
|
+ // 将forbiddenOnlineMedicines转换为set,转换关键字去除(数字)
|
|
|
|
|
+ Set<String> forbiddenKeywords = new HashSet<>((int) (forbiddenOnlineMedicines.size() * 2 / 0.75) + 1);
|
|
|
|
|
+ for (ForbiddenOnlineMedicine medicine : forbiddenOnlineMedicines) {
|
|
|
|
|
+ String originalKey = medicine.getForbiddenKeywords();
|
|
|
|
|
+ String originalIngredient = medicine.getMedicineIngredient();
|
|
|
|
|
+ if (originalKey == null && originalIngredient == null) {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ String processedKey = null;
|
|
|
|
|
+ if (originalKey != null) {
|
|
|
|
|
+ processedKey = originalKey.replace(BRACKET_NUM_EN, "").replace(BRACKET_NUM_CN, "");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (processedKey != null) {
|
|
|
|
|
+ String processedChange = cleanKeyword(processedKey);
|
|
|
|
|
+ forbiddenKeywords.add(processedChange);
|
|
|
|
|
+ promptWordsMap.put(processedChange, medicine.getForbiddenKeywords());
|
|
|
|
|
+ }
|
|
|
|
|
+ String processedIngredient = null;
|
|
|
|
|
+ if (originalIngredient != null) {
|
|
|
|
|
+ processedIngredient = originalIngredient.replace(BRACKET_NUM_EN, "").replace(BRACKET_NUM_CN, "");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (processedIngredient != null && !Objects.equals(processedKey, processedIngredient)) {
|
|
|
|
|
+ String medicineIngredientChange = cleanKeyword(processedIngredient);
|
|
|
|
|
+ forbiddenKeywords.add(medicineIngredientChange);
|
|
|
|
|
+ promptWordsMap.put(medicineIngredientChange, medicine.getMedicineIngredient());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
DrugComponentAnalyzer.CheckResult checkResult = DrugComponentAnalyzer.checkForbiddenComponents(forbiddenKeywords, keyWords);
|
|
DrugComponentAnalyzer.CheckResult checkResult = DrugComponentAnalyzer.checkForbiddenComponents(forbiddenKeywords, keyWords);
|
|
|
boolean forbidden = checkResult.isForbidden();
|
|
boolean forbidden = checkResult.isForbidden();
|
|
|
if(!forbidden){
|
|
if(!forbidden){
|
|
|
//二次-匹配到关键词
|
|
//二次-匹配到关键词
|
|
|
StringBuilder msg = new StringBuilder();
|
|
StringBuilder msg = new StringBuilder();
|
|
|
- for (String keyword : forbiddenKeywords){
|
|
|
|
|
- if(keyWords.contains(keyword)){
|
|
|
|
|
- msg.append(keyword).append(",");
|
|
|
|
|
|
|
+ int lenght = keyWords.length();//原始长度
|
|
|
|
|
+ keyWords = cleanKeyword(keyWords);
|
|
|
|
|
+ for (String keyword: forbiddenKeywords){
|
|
|
|
|
+ if(!keyword.equals("")){
|
|
|
|
|
+ //验证是否包含数字
|
|
|
|
|
+ if(keyWords.contains(keyword) || (lenght >= 2 && keyword.contains(keyWords))){
|
|
|
|
|
+ msg.append(promptWordsMap.get(keyword)).append(",");
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
if(msg.length() > 0){
|
|
if(msg.length() > 0){
|
|
@@ -1581,4 +1625,20 @@ public class FsStoreProductScrmServiceImpl implements IFsStoreProductScrmService
|
|
|
}
|
|
}
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 清理括号+(所有符号)
|
|
|
|
|
+ * @param originalStr
|
|
|
|
|
+ * @return 清理后的字符串
|
|
|
|
|
+ */
|
|
|
|
|
+ public static String cleanKeyword(String originalStr) {
|
|
|
|
|
+ if (originalStr == null || originalStr.isEmpty()) {
|
|
|
|
|
+ return originalStr;
|
|
|
|
|
+ }
|
|
|
|
|
+ String cleaned = originalStr;
|
|
|
|
|
+ cleaned = BRACKET_ALL_CONTENT_PATTERN.matcher(cleaned).replaceAll("");
|
|
|
|
|
+ cleaned = SPECIAL_CHAR_PATTERN.matcher(cleaned).replaceAll("");
|
|
|
|
|
+ cleaned = WHITESPACE_PATTERN.matcher(cleaned).replaceAll("");
|
|
|
|
|
+ return cleaned;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|