Browse Source

关键词1.0版本功能开发
删除关键词时同时删除缓存中的数据

JiangChongBo 2 years ago
parent
commit
7b542332dc

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

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

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

@@ -6,6 +6,7 @@ import com.caimei.modules.product.entity.SearchFrequency;
 import com.caimei.modules.product.entity.SearchFrequencyVo;
 import com.thinkgem.jeesite.common.persistence.Page;
 import com.thinkgem.jeesite.common.service.CrudService;
+import com.thinkgem.jeesite.common.utils.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
@@ -71,6 +72,22 @@ public class KeywordFrequencyService extends CrudService<KeywordFrequencyDao, Se
     @Transactional(readOnly = false)
     public String delKeyWordById(Integer id){
         keywordFrequencyDao.delKeyWordById(id);
+        //删除缓存中的数据
+        SearchFrequency keyById = keywordFrequencyDao.getKeyById(id);
+        //根据key值获取数据,如果只有一条则直接删除,大于一条则删除后重新缓存
+        if(keyById!=null&& StringUtils.isNoneEmpty(keyById.getKeyword())){
+            String str=keyById.getKeyword();
+            String key="";
+            for(int i=0;i<str.length();i++){
+                key+=str.charAt(i);
+                redisService.remove(key);
+                List<SearchFrequencyVo> searchFrequencyVos = keywordFrequencyDao.getvalueList(key);
+                if(null !=searchFrequencyVos&& searchFrequencyVos.size()>0){
+                    String keyword = JSONObject.toJSONString(searchFrequencyVos);//有值的字段才转
+                    redisService.set(key,keyword,60L * 60 * 24 * 30);
+                }
+            }
+        }
         return "删除关键词成功";
     }
     @Transactional(readOnly = false)

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

@@ -126,4 +126,13 @@
             and keyword like concat(#{keyword},'%')
         </if>
     </select>
+    <select id="getKeyById" resultType="com.caimei.modules.product.entity.SearchFrequency">
+        select
+        keyword
+        from cm_user_search_frequency
+        where trueStatus=1
+        and   delStatus=0
+        and keyword is not null
+        and id=#{id}
+    </select>
 </mapper>

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

@@ -82,7 +82,7 @@
             // if('0'==status){
             //     msg='确定停用?';
             // }
-            top.$.jBox.confirm(msg,'系统提示',function(v,h,f){
+            top.$.jBox.confirm(msg,'系统提示',function(v){
                 if(v=='ok'){
                     $.post("${ctx}/product/keywordFrequency/addKeyWordList",{'ids':ids}, function(data) {
                         $("#searchForm").submit();
@@ -92,7 +92,7 @@
                 // window.location.reload();
                 window.location.href = "${ctx}/product/keywordFrequency/getKeyInfo";
                 return;
-            },{buttonsFocus:1,persistent: true});
+            });
         }
         //删除关键词
         function delEnabledStatus(ids){