JiangChongBo 2 年之前
父节点
当前提交
53be3a6e4d

+ 1 - 1
src/main/java/com/caimei/modules/product/dao/KeywordFrequencyDao.java

@@ -30,5 +30,5 @@ public interface KeywordFrequencyDao extends CrudDao<SearchFrequency> {
     List<SearchFrequencyVo> getvalueList(@Param("keyword") String keyword);
     SearchFrequency getKeyById(Integer id);
 
-//    List<String> verificationKeword(@Param("keyword")String keyword);
+    List<String> verificationKeword(@Param("keyword")String keyword);
 }

+ 9 - 10
src/main/java/com/caimei/modules/product/service/KeywordFrequencyService.java

@@ -64,19 +64,18 @@ public class KeywordFrequencyService extends CrudService<KeywordFrequencyDao, Se
         return "加入关键词库成功";
     }
     /**
-     * 加入关键词库
+     * 验证关键词是否存在
      * @param keyword
      * @return
      */
-//    @Transactional(readOnly = false)
-//    public boolean verificationKeword(String keyword){
-//        List<String> keyList = keywordFrequencyDao.verificationKeword(keyword);
-//        if(null !=keyList&&keyList.size()>0){
-//            return true;
-//        }else{
-//            return false;
-//        }
-//    }
+    public boolean verificationKeword(String keyword){
+        List<String> keyList = keywordFrequencyDao.verificationKeword(keyword);
+        if(null !=keyList&&keyList.size()>0){
+            return true;
+        }else{
+            return false;
+        }
+    }
     /**
      * 删除关键词
      * @param id

+ 14 - 14
src/main/java/com/caimei/modules/product/web/KeywordFrequencyController.java

@@ -111,27 +111,27 @@ public class KeywordFrequencyController extends BaseController {
      * @return
      */
     @RequestMapping("/addKeyWordList")
-    public String addKeyWordList(String ids,RedirectAttributes redirectAttributes){
+    @ResponseBody
+    public String addKeyWordList(String ids,Model model){
         keywordFrequencyService.addKeyWordList(ids);
-        addMessage(redirectAttributes, "已加入关键词库");
-        return "redirect:"+Global.getAdminPath()+"/product/keywordFrequency/getKeyInfo";
+        return "success";
     }
     /**
      * 验证关键词库是该否存在关键词
      * @param keyword
      * @return
      */
-//    @RequestMapping("/verificationKeword")
-//    public String verificationKeword(String keyword,Model model){
-//        boolean b = keywordFrequencyService.verificationKeword(keyword);
-//        if(b){
-//            model.addAttribute("flag","-1");
-//        }else{
-//            model.addAttribute("flag","0");
-//        }
-//        return "redirect:"+Global.getAdminPath()+"/product/keywordFrequency/getKeyInfo";
-//
-//    }
+    @RequestMapping("/verificationKeword")
+    @ResponseBody
+    public String verificationKeword(String keyword,Model model){
+        boolean b = keywordFrequencyService.verificationKeword(keyword);
+        if(b){
+            return "-1";
+        }else{
+            return "0";
+        }
+
+    }
     /**
      * 删除关键词
      * status 区分是关键词界面还是关键词库界面 (1关键词;2关键词库)

+ 8 - 8
src/main/resources/mappings/modules/product/SearchFrequencyMapper.xml

@@ -149,12 +149,12 @@
         and keyword is not null
         and id=#{id}
     </select>
-<!--    <select id="verificationKeword" resultType="java.lang.String">-->
-<!--        select-->
-<!--            keyword-->
-<!--        from cm_user_search_frequency-->
-<!--        where trueStatus=1-->
-<!--          and   delStatus=1-->
-<!--          and keyword =#{keyword}-->
-<!--    </select>-->
+    <select id="verificationKeword" resultType="java.lang.String">
+        select
+            keyword
+        from cm_user_search_frequency
+        where trueStatus=1
+          and   delStatus=1
+          and keyword =#{keyword}
+    </select>
 </mapper>

+ 82 - 16
src/main/webapp/WEB-INF/views/modules/product/keywordFrequency.jsp

@@ -139,24 +139,89 @@
            function exportKeyword(ids){
                 window.location.href = "${ctx}/product/keywordFrequency/export?ids=" + ids;
            }
+
         <%--function verification(key){--%>
-        <%--    $.ajax({--%>
-        <%--        //几个参数需要注意一下--%>
-        <%--        type: "get",//方法类型--%>
-        <%--        dataType:"json",--%>
-        <%--        url: "${ctx}/product/keywordFrequency/verificationKeword?keyword="+key ,//url--%>
-        <%--        success: function (data) {--%>
-        <%--            if(data=="-1"){--%>
-        <%--                return confirmx("关键词已经存在");--%>
-        <%--            }else{--%>
-        <%--                return true;--%>
+        <%--    return new Promise(function(resolve, reject){--%>
+        <%--        $.ajax({--%>
+        <%--            //几个参数需要注意一下--%>
+        <%--            type: "get",//方法类型--%>
+        <%--            dataType:"json",--%>
+        <%--            url: "${ctx}/product/keywordFrequency/verificationKeword?keyword="+key ,//url--%>
+        <%--            success: function (data) {--%>
+        <%--                resolve('ok')--%>
+        <%--                if(data=="-1"){--%>
+        <%--                    reject('关键词已存在')--%>
+        <%--                }else{--%>
+        <%--                    resolve()--%>
+        <%--                }--%>
+        <%--            },--%>
+        <%--            error : function() {--%>
+        <%--                alert("服务异常!");--%>
         <%--            }--%>
-        <%--        },--%>
-        <%--        error : function() {--%>
-        <%--            alert("服务异常!");--%>
-        <%--        }--%>
-        <%--    });--%>
+        <%--        });--%>
+        <%--    })--%>
         <%--}--%>
+
+        function verification(key){
+            return new Promise(function(resolve, reject){
+                $.ajax({
+                    //几个参数需要注意一下
+                    type: "get",//方法类型
+                    dataType:"json",
+                    url: "${ctx}/product/keywordFrequency/verificationKeword?keyword="+key ,//url
+                    success: function (data) {
+                        console.log('verification', data)
+                        if(data=="-1"){
+                            resolve('faild')
+                        }else{
+                            resolve('ok')
+                        }
+                    },
+                    error : function() {
+                        reject('服务器异常')
+                    }
+                });
+            })
+        }
+
+        function joinKeywordLibrary(keyId){
+            <%--return new Promise(function(resolve, reject){--%>
+            <%--    $.ajax({--%>
+            <%--        //几个参数需要注意一下--%>
+            <%--        type: "get",//方法类型--%>
+            <%--        dataType:"json",--%>
+            <%--        url: "${ctx}/product/keywordFrequency/addKeyWordList?ids=" + keyId ,//url--%>
+            <%--        success: function (data) {--%>
+            <%--            console.log('joinKeywordLibrary', data)--%>
+            <%--            resolve()--%>
+            <%--        },--%>
+            <%--        error : function() {--%>
+            <%--            reject('加入关键词库失败')--%>
+            <%--        }--%>
+            <%--    });--%>
+            <%--})--%>
+
+        }
+
+        async  function onJoinKeywordLibrary(keyId, key){
+            try{
+                const result = await verification(key)
+                if(result !== 'ok'){
+                    return confirm('该关键词在关键键词词库已存在!')
+                }
+                const confirmRes = confirm('确认将关键词加入关键词库吗?')
+                console.log('confirmRes', confirmRes)
+                if(!confirmRes){
+                    return
+                }
+                // await joinKeywordLibrary(keyId)
+                await fetch("${ctx}/product/keywordFrequency/addKeyWordList?ids=" + keyId)
+                top.$.jBox.tip('添加成功', 'success');
+                window.location.href = '${ctx}/product/keywordFrequency/getKeyInfo/' ;
+            }catch (e){
+                alert(e)
+            }
+        }
     </script>
 </head>
 <body>
@@ -231,7 +296,8 @@
 <%--                    <c:if test="${newCmSp.status eq 90 || newCmSp.status eq 91}">--%>
 <%--                        onclick="updatePwd(${newCmSp.serviceProviderID})"--%>
 <%--                        <a onclick="updateEnabledStatus('${newCmSp.keyId}')">加入关键词库</a>--%>
-                        <a href="${ctx}/product/keywordFrequency/addKeyWordList?ids=${newCmSp.keyId}" onclick="return confirmx('确认将关键词加入关键词库吗?', this.href)">加入关键词库</a>
+<%--                        <a href="${ctx}/product/keywordFrequency/addKeyWordList?ids=${newCmSp.keyId}" onclick="return confirmx('确认将关键词加入关键词库吗?', this.href)">加入关键词库</a>--%>
+                            <a href="javascript:void(0);" onclick="onJoinKeywordLibrary(${newCmSp.keyId},'${newCmSp.keyword}')">加入关键词库</a>
 <%--                         <a href="${ctx}/product/keywordFrequency/addKeyWordList?ids=${newCmSp.keyId}" onclick="verification('${newCmSp.keyword}')">加入关键词库</a>--%>
 
 <%--                        href="${ctx}/new/user/cmSp/cmSpEdit?id=${newCmSp.serviceProviderID}"--%>