瀏覽代碼

对比药品成分是否禁售,商品名称成分关键字查询。

Guos 1 天之前
父節點
當前提交
62fe1f7501

+ 5 - 6
fs-admin/src/main/java/com/fs/hisStore/controller/FsStoreProductScrmController.java

@@ -71,20 +71,19 @@ public class FsStoreProductScrmController extends BaseController {
     /**
      * 商品关键字检查
      * 只要商品成分的关键字在数据库中存在,就不允许添加商品。
-     * @param fsStoreProductScrm
+     * @param vo
      * @return
      */
     @PostMapping("/selectForbiddenKeywords")
-    public R selectForbiddenKeywords(@RequestBody FsStoreProductScrm fsStoreProductScrm) {
-        if(org.apache.commons.lang3.StringUtils.isEmpty(fsStoreProductScrm.getIngredient()))return R.ok().put("data", true);
-        String ingredient = fsStoreProductScrm.getIngredient();
-        SelectForbiddenKeywordsVo selectForbiddenKeywordsVo = fsStoreProductService.selectForbiddenKeywords(ingredient);
+    public R selectForbiddenKeywords(@RequestBody ForbiddenKeywordsVO vo) {
+        if(org.apache.commons.lang3.StringUtils.isEmpty(vo.getKeywords()))return R.ok().put("data", true);
+        String keywords = vo.getKeywords();
+        SelectForbiddenKeywordsVo selectForbiddenKeywordsVo = fsStoreProductService.selectForbiddenKeywords(keywords);
         if(ObjectUtils.isEmpty(selectForbiddenKeywordsVo)){
             return R.ok().put("data", true);
         }else{
             return R.ok().put("data", false).put("msg", selectForbiddenKeywordsVo.getMsg());
         }
-
     }
 
     /**

+ 29 - 36
fs-service/src/main/java/com/fs/hisStore/util/DrugComponentAnalyzer.java

@@ -17,7 +17,7 @@ import java.util.*;
 import java.util.stream.Collectors;
 
 /**
- * @description:
+ * @description: 文件地址可以配置到yml中,避免线上线下不一致
  * @author: Guos
  * @time: 2025/12/5 下午3:07
  */
@@ -27,6 +27,7 @@ public class DrugComponentAnalyzer {
     private static final Set<String> FORBIDDEN_COMPONENTS = new HashSet<>(Arrays.asList(
             "罂粟壳", "吗啡", "海洛因", "可卡因", "芬太尼","罂粟","洋地黄毒苷"
     ));
+
     // 停用词集合
 //    private static Set<String> STOP_WORDS = new HashSet<>(Arrays.asList(
 //            "洋地黄毒苷"
@@ -37,10 +38,10 @@ public class DrugComponentAnalyzer {
 
     // 词典文件绝对路径(核心:直接指向服务器本地文件)
     private static final String DRUG_FILE_PATH = "C:\\Tools\\jar\\drug.txt";
+
     // 词典数据集合
     private static final Set<String> DRUG_DICT = new HashSet<>();
 
-    // 整合后的静态代码块:一次性完成「加载WordDictionary」+「读取DRUG_DICT」
     static {
         try {
             // 1. 校验文件是否存在
@@ -48,27 +49,19 @@ public class DrugComponentAnalyzer {
             if (!drugFile.exists()) {
                 throw new FileNotFoundException("词典文件不存在:" + DRUG_FILE_PATH);
             }
-
             // 2. 核心逻辑:给 WordDictionary 加载词典文件(依赖 Path)
             Path path = drugFile.toPath();
             WordDictionary.getInstance().loadUserDict(path);
-
-
+            //这个是线下的使用方式
+//            ClassPathResource resource = new ClassPathResource("drug.txt");
+//            System.out.println("文件路径:"+resource.getFile().getPath());
+//            Path linePath = resource.getFile().toPath();
+//            WordDictionary.getInstance().loadUserDict(linePath);
         } catch (Exception e) {
-            // 统一抛出异常,包含完整错误信息
             throw new RuntimeException("加载词典失败(路径:" + DRUG_FILE_PATH + ")", e);
         }
     }
 
-    // 对外提供文件路径的方法(兼容原有依赖path的逻辑)
-    public static String getDrugFilePath() {
-        return DRUG_FILE_PATH;
-    }
-
-    // 可选:对外提供词典集合(如果业务需要)
-    public static Set<String> getDrugDict() {
-        return DRUG_DICT;
-    }
     /**
      * 拆分药品成分(过滤停用词,仅保留有效成分)
      */
@@ -130,26 +123,26 @@ public class DrugComponentAnalyzer {
         public boolean isForbidden() { return isForbidden; }
     }
 
-    public static void main(String[] args) {
-        // 测试文本1:含禁售成分
-        String text1 = "洋地黄毒苷,左啡诺";
-        CheckResult result1 = checkForbiddenComponents(FORBIDDEN_COMPONENTS, text1);
-        System.out.println("文本1拆分成分:" + result1.getAllComponents());
-        System.out.println("文本1禁售成分:" + result1.getForbiddenComponents());
-        System.out.println("文本1是否禁售:" + result1.isForbidden());
-        // 输出:
-        // 文本1拆分成分:[对乙酰氨基酚, 罂粟壳, 淀粉]
-        // 文本1禁售成分:[罂粟壳]
-        // 文本1是否禁售:true
-
-        // 测试文本2:无禁售成分
-        String text2 = "阿莫西林克拉维酸钾分散片,辅料为硬脂酸镁";
-        CheckResult result2 = checkForbiddenComponents(FORBIDDEN_COMPONENTS, text2);
-        System.out.println("\n文本2拆分成分:" + result2.getAllComponents());
-        System.out.println("文本2是否禁售:" + result2.isForbidden());
-        // 输出:
-        // 文本2拆分成分:[阿莫西林克拉维酸钾, 硬脂酸镁]
-        // 文本2是否禁售:false
-    }
+//    public static void main(String[] args) {
+//        // 测试文本1:含禁售成分
+//        String text1 = "洋地黄毒苷,左啡诺";
+//        CheckResult result1 = checkForbiddenComponents(FORBIDDEN_COMPONENTS, text1);
+//        System.out.println("文本1拆分成分:" + result1.getAllComponents());
+//        System.out.println("文本1禁售成分:" + result1.getForbiddenComponents());
+//        System.out.println("文本1是否禁售:" + result1.isForbidden());
+//        // 输出:
+//        // 文本1拆分成分:[对乙酰氨基酚, 罂粟壳, 淀粉]
+//        // 文本1禁售成分:[罂粟壳]
+//        // 文本1是否禁售:true
+//
+//        // 测试文本2:无禁售成分
+//        String text2 = "阿莫西林克拉维酸钾分散片,辅料为硬脂酸镁";
+//        CheckResult result2 = checkForbiddenComponents(FORBIDDEN_COMPONENTS, text2);
+//        System.out.println("\n文本2拆分成分:" + result2.getAllComponents());
+//        System.out.println("文本2是否禁售:" + result2.isForbidden());
+//        // 输出:
+//        // 文本2拆分成分:[阿莫西林克拉维酸钾, 硬脂酸镁]
+//        // 文本2是否禁售:false
+//    }
 
 }

+ 15 - 0
fs-service/src/main/java/com/fs/hisStore/vo/ForbiddenKeywordsVO.java

@@ -0,0 +1,15 @@
+package com.fs.hisStore.vo;
+
+import lombok.Data;
+
+/**
+ * @description:
+ * @author: Guos
+ * @time: 2025/12/8 上午10:41
+ */
+@Data
+public class ForbiddenKeywordsVO {
+
+    private String keywords;
+
+}

+ 6 - 5
fs-store/src/main/java/com/fs/hisStore/controller/store/FsStoreProductScrmController.java

@@ -18,6 +18,7 @@ import com.fs.hisStore.service.IFsStoreProductAttrScrmService;
 import com.fs.hisStore.service.IFsStoreProductScrmService;
 import com.fs.hisStore.utils.StoreAuditLogUtil;
 import com.fs.hisStore.utils.UserUtil;
+import com.fs.hisStore.vo.ForbiddenKeywordsVO;
 import com.fs.hisStore.vo.FsStoreProductListVO;
 import com.fs.hisStore.vo.SelectForbiddenKeywordsVo;
 import com.fs.store.vo.FsStoreProductStoreExcelVO;
@@ -57,14 +58,14 @@ public class FsStoreProductScrmController extends BaseController
     /**
      * 商品关键字检查
      * 只要商品关键字在数据库中存在,就不允许添加商品。
-     * @param fsStoreProductScrm
+     * @param vo
      * @return
      */
     @PostMapping("/selectForbiddenKeywords")
-    public R selectForbiddenKeywords(@RequestBody FsStoreProductScrm fsStoreProductScrm) {
-        if(org.apache.commons.lang3.StringUtils.isEmpty(fsStoreProductScrm.getIngredient()))return R.ok().put("data", true);
-        String ingredient = fsStoreProductScrm.getIngredient();
-        SelectForbiddenKeywordsVo selectForbiddenKeywordsVo = fsStoreProductService.selectForbiddenKeywords(ingredient);
+    public R selectForbiddenKeywords(@RequestBody ForbiddenKeywordsVO vo) {
+        if(org.apache.commons.lang3.StringUtils.isEmpty(vo.getKeywords()))return R.ok().put("data", true);
+        String keywords = vo.getKeywords();
+        SelectForbiddenKeywordsVo selectForbiddenKeywordsVo = fsStoreProductService.selectForbiddenKeywords(keywords);
         if(ObjectUtils.isEmpty(selectForbiddenKeywordsVo)){
             return R.ok().put("data", true);
         }else{