Forráskód Böngészése

加入关键词库按钮,和添加关键词功能bugfix

JiangChongBo 2 éve
szülő
commit
ffcb86be59

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

@@ -31,4 +31,6 @@ public interface KeywordFrequencyDao extends CrudDao<SearchFrequency> {
     SearchFrequency getKeyById(Integer id);
 
     List<String> verificationKeword(@Param("keyword")String keyword);
+    List<String> verificationKewords(@Param("keywords")String[] keywords);
+
 }

+ 14 - 0
src/main/java/com/caimei/modules/product/service/KeywordFrequencyService.java

@@ -76,6 +76,20 @@ public class KeywordFrequencyService extends CrudService<KeywordFrequencyDao, Se
             return false;
         }
     }
+    /**
+     * 验证关键词是否存在
+     * @param keywords
+     * @return
+     */
+    public boolean verificationKewords(String keywords){
+        String[] keys = keywords.split(",");
+        List<String> keyList = keywordFrequencyDao.verificationKewords(keys);
+        if(null !=keyList&&keyList.size()>0){
+            return true;
+        }else{
+            return false;
+        }
+    }
     /**
      * 删除关键词
      * @param id

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

@@ -11,6 +11,7 @@ import com.github.pagehelper.PageInfo;
 import com.thinkgem.jeesite.common.config.Global;
 import com.thinkgem.jeesite.common.persistence.Page;
 import com.thinkgem.jeesite.common.utils.DateUtils;
+import com.thinkgem.jeesite.common.utils.StringUtils;
 import com.thinkgem.jeesite.common.utils.excel.ImportExcel;
 import com.thinkgem.jeesite.common.web.BaseController;
 import org.apache.poi.hssf.usermodel.HSSFDateUtil;
@@ -131,6 +132,22 @@ public class KeywordFrequencyController extends BaseController {
             return "0";
         }
 
+    }
+    /**
+     * 验证关键词库是该否存在关键词
+     * @param keywords
+     * @return
+     */
+    @RequestMapping("/verificationKewords")
+    @ResponseBody
+    public String verificationKewords(String keywords,Model model){
+        boolean b = keywordFrequencyService.verificationKewords(keywords);
+        if(b){
+            return "-1";
+        }else{
+            return "0";
+        }
+
     }
     /**
      * 删除关键词
@@ -272,6 +289,10 @@ public class KeywordFrequencyController extends BaseController {
             addMessage(redirectAttributes,"请选择需要导入的关键词文件");
             return "redirect:"+Global.getAdminPath()+"/product/keywordFrequency/getKeywordThesaurusInfo";
         }
+        int sum=0;//总数量
+        int falseNum=0;//已存在数量
+        int successNum=0;
+        String falseKeys="";//已存在关键词
         try {
             //根据路径获取这个操作excel的实例
             HSSFWorkbook wb = new HSSFWorkbook(file.getInputStream());
@@ -280,23 +301,44 @@ public class KeywordFrequencyController extends BaseController {
             HSSFRow row = null;
             //循环sesheet页中数据从第二行开始,第一行是标题
             List<SearchFrequency> searchFrequencyList=new ArrayList<>();
-            for(int i=1;i<sheet.getPhysicalNumberOfRows()-1;i++){
+             sum=sheet.getPhysicalNumberOfRows()-1;
+            for(int i=1;i<=sheet.getPhysicalNumberOfRows()-1;i++){
                 row = sheet.getRow(i);
                 SearchFrequency searchFrequency=new SearchFrequency();
+                //关键词
                 if(null !=row.getCell(1)){
                 searchFrequency.setKeyword(row.getCell(1).toString());
+                    boolean b = keywordFrequencyService.verificationKeword(row.getCell(1).toString());
+                    if(b){//判断关键词是否已存在
+                        falseNum+=1;
+                        if(StringUtils.isNotEmpty(falseKeys)){
+                            falseKeys=falseKeys+","+row.getCell(1).toString();
+                        }else{
+                            falseKeys+=row.getCell(1).toString();
+                        }
+                        continue;
+                    }
                 }else{
                     continue;
                 }
-                if(null != row.getCell(2)){
-                    if("首页搜索".equals(row.getCell(2).toString())){
-                        searchFrequency.setFromSearch(1);
-                    }else if("信息中心搜索".equals(row.getCell(2).toString())){
-                        searchFrequency.setFromSearch(2);
-                    }else if("管理员添加".equals(row.getCell(2).toString())){
-                        searchFrequency.setFromSearch(6);
-                    }
+                //联动次数
+                if(null !=row.getCell(2)){
+                   String linkageFrequency= row.getCell(2).toString();
+                   if(linkageFrequency.indexOf(".")>0){
+                       linkageFrequency=linkageFrequency.replace(".","");
+                   }
+                    searchFrequency.setLinkageFrequency(Integer.valueOf(linkageFrequency));
                 }
+//                if(null != row.getCell(2)){
+//                    if("首页搜索".equals(row.getCell(2).toString())){
+//                        searchFrequency.setFromSearch(1);
+//                    }else if("信息中心搜索".equals(row.getCell(2).toString())){
+//                        searchFrequency.setFromSearch(2);
+//                    }else if("管理员添加".equals(row.getCell(2).toString())){
+//                        searchFrequency.setFromSearch(6);
+//                    }
+//                }
+                //添加时间
                 if(null != row.getCell(3)){
                     searchFrequency.setSearchTime(new java.sql.Timestamp(row.getCell(3).getDateCellValue().getTime()));
                 }
@@ -304,6 +346,7 @@ public class KeywordFrequencyController extends BaseController {
                 searchFrequency.setTrueStatus(1);
                 searchFrequencyList.add(searchFrequency);
             }
+             successNum=sum-falseNum;
             //保存文件数据
             keywordFrequencyService.importKeyword(searchFrequencyList);
             //保存后重置关键词redis缓存
@@ -312,7 +355,7 @@ public class KeywordFrequencyController extends BaseController {
         } catch (IOException  e) {//| ParseException
             e.printStackTrace();
         }
-        addMessage(redirectAttributes,"导入关键词成功");
+        addMessage(redirectAttributes,"导入关键词成功:总数: "+sum+" 条  其中成功 " +successNum+"  条"+";   关键词库已存在: "+falseNum+" 条( "+falseKeys+" )");
         return "redirect:"+Global.getAdminPath()+"/product/keywordFrequency/getKeywordThesaurusInfo";
     }
 }

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

@@ -157,4 +157,15 @@
           and   delStatus=1
           and keyword =#{keyword}
     </select>
+    <select id="verificationKewords" resultType="java.lang.String">
+        select
+            keyword
+        from cm_user_search_frequency
+        where trueStatus=1
+          and   delStatus=1
+          and keyword in
+        <foreach collection="keywords" open="(" separator="," close=")" item="reId">
+            #{reId,jdbcType=VARCHAR}
+        </foreach>
+    </select>
 </mapper>

+ 35 - 5
src/main/webapp/WEB-INF/views/modules/product/keywordFrequency.jsp

@@ -77,11 +77,15 @@
             }
         }
         //加入关键词库
-        function updateEnabledStatus(ids){
+        async function updateEnabledStatus(ids,keys){
             var msg='确定加入关键词库?';
             // if('0'==status){
             //     msg='确定停用?';
             // }
+            const result = await verifications(keys)
+            if(result !== 'ok'){
+                return confirm('选中的关键词中部分在关键键词词库已存在!')
+            }else{
             top.$.jBox.confirm(msg,'系统提示',function(v){
                 if(v=='ok'){
                     $.post("${ctx}/product/keywordFrequency/addKeyWordList",{'ids':ids}, function(data) {
@@ -90,9 +94,12 @@
                 }
                 top.$.jBox.tip('加入关键词库成功', 'success');
                 // window.location.reload();
-                window.location.href = "${ctx}/product/keywordFrequency/getKeyInfo";
+                <%--window.location.href = "${ctx}/product/keywordFrequency/getKeyInfo";--%>
+                window.location.href = '${ctx}/product/keywordFrequency/getKeyInfo/' ;
+
                 return;
             });
+            }
         }
         //删除关键词
         function delEnabledStatus(ids){
@@ -114,14 +121,17 @@
         function updateStatus(){
             var items = new Array();
             $items=$('.check-item:checked');
+            var keyitems = new Array();
             if(0==$items.length){
                 top.$.jBox.tip('请选择需要加入关键词库的数据', 'error');
                 return;
             }
             $items.each(function(i){
                 items.push($(this).parents(".item-info").attr("id"));
+                keyitems.push($(this).parents(".item-info").attr("name"));
             });
-            updateEnabledStatus(items.toString());
+            console.log(keyitems);
+            updateEnabledStatus(items.toString(),keyitems.toString());
         }
         function getSelectKeywords(){
             var items = new Array();
@@ -183,7 +193,27 @@
                 });
             })
         }
-
+        function verifications(key){
+            return new Promise(function(resolve, reject){
+                $.ajax({
+                    //几个参数需要注意一下
+                    type: "get",//方法类型
+                    dataType:"json",
+                    url: "${ctx}/product/keywordFrequency/verificationKewords?keywords="+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({--%>
@@ -267,7 +297,7 @@
     </thead>
     <tbody>
     <c:forEach items="${keyInfo.list}" var="newCmSp" varStatus="status">
-        <tr class="item-info" id="${newCmSp.keyId}">
+        <tr class="item-info" id="${newCmSp.keyId}" name="${newCmSp.keyword}">
             <td><input class="check-item" type="checkbox" id="checkbox" value="" onclick="checkfun(this)"/></td>
             <td>${status.index+1}</td>
                 <%--<td>${newCmSp.name}</td>--%>

+ 41 - 9
src/main/webapp/WEB-INF/views/modules/product/upkeyword.jsp

@@ -5,15 +5,47 @@
     <title>关键词更新</title>
     <meta name="decorator" content="default"/>
     <script type="text/javascript">
-        $(document).ready(function() {
-            //$("#name").focus();
-            $("#inputForm").validate({
-                submitHandler: function(form){
-                    loading('正在提交,请稍等...');
-                    form.submit();
+        // $(document).ready(function() {
+        //     $("#name").focus();
+        //     $("#inputForm").validate({
+        //         submitHandler: function(form){
+        //             loading('正在提交,请稍等...');
+        //             form.submit();
+        //         },
+        //     });
+        // });
+        function checkForm(){
+            var status=${searchFrequency.status}//词库列表编辑,不需要验证
+            if(1===status){
+                return true;
+            }
+            var key = document.getElementById("keyword").value;
+            var flag=false;
+            $.ajax({
+                //几个参数需要注意一下
+                type: "get",//方法类型
+                dataType:"json",
+                async:false,
+                url: "${ctx}/product/keywordFrequency/verificationKewords?keywords="+key ,//url
+                success: function (data) {
+                    if(data=="-1"){
+                        top.$.jBox.tip('该关键词在关键键词词库已存在', 'error');
+                        flag =false;
+                        console.log(flag)
+                    }else{
+                        console.log("flag")
+                        flag=true;
+                        // console.log(flag)
+                    }
                 },
+                error : function() {
+                    reject('服务器异常')
+                }
             });
-        });
+            console.log(flag)
+            return flag;
+        }
+
     </script>
 </head>
 <body>
@@ -28,13 +60,13 @@
 <%--    <li class="active"><a href="${ctx}/order/cmAuthorizedConsignment/form?id=${cmAuthorizedConsignment.id}"><shiro:hasPermission name="order:cmAuthorizedConsignment:edit">${not empty cmAuthorizedConsignment.id?'编辑':'添加'}</shiro:hasPermission><shiro:lacksPermission name="order:cmAuthorizedConsignment:edit">查看</shiro:lacksPermission></a></li>--%>
     <li class="active"><a href="${ctx}/product/keywordFrequency/form?keyId=${searchFrequency.keyId}&status=${searchFrequency.status}"><shiro:hasPermission name="order:cmAuthorizedConsignment:edit">${not empty searchFrequency.keyId?'编辑':'添加'}</shiro:hasPermission><shiro:lacksPermission name="order:cmAuthorizedConsignment:edit">查看</shiro:lacksPermission></a></li>
 </ul><br/>
-<form:form id="inputForm" modelAttribute="searchFrequency" action="${ctx}/product/keywordFrequency/save?status=${searchFrequency.status}" method="post" class="form-horizontal">
+<form:form id="inputForm" modelAttribute="searchFrequency" action="${ctx}/product/keywordFrequency/save?status=${searchFrequency.status}" method="post" onsubmit="return checkForm()" class="form-horizontal">
     <form:hidden path="keyId"/>
     <sys:message content="${message}"/>
     <div class="control-group">
         <label class="control-label"><font color="red">*</font>关键词:</label>
         <div class="controls">
-            <form:input path="keyword" htmlEscape="false" maxlength="20" class="input-xlarge required" value="${searchFrequency.keyword}"/>
+            <form:input id="keyword" path="keyword" htmlEscape="false" maxlength="20" class="input-xlarge required" value="${searchFrequency.keyword}"/>
         </div>
     </div>
     <div class="form-actions">