浏览代码

Merge remote-tracking branch 'origin/developer' into developer

kaick 1 年之前
父节点
当前提交
5cdf649859

+ 90 - 12
src/main/java/com/caimei365/manager/controller/caimei/keyword/KeyWordApi.java

@@ -1,13 +1,16 @@
 package com.caimei365.manager.controller.caimei.keyword;
 
 import com.alibaba.excel.EasyExcel;
+import com.caimei365.manager.dao.KeyWordDao;
 import com.caimei365.manager.entity.PaginationVo;
 import com.caimei365.manager.entity.ResponseJson;
+import com.caimei365.manager.entity.caimei.CmKeywordInfo;
 import com.caimei365.manager.entity.caimei.CmPriorKeyword;
 import com.caimei365.manager.entity.caimei.KeyWord;
 import com.caimei365.manager.entity.caimei.cmUser.ServiceProviderModel;
 import com.caimei365.manager.service.caimei.KeyWordService;
 import com.caimei365.manager.service.caimei.listener.KeywordListener;
+import com.caimei365.manager.service.caimei.listener.LabelListener;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
@@ -16,6 +19,7 @@ import javax.annotation.Resource;
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.List;
+import java.util.Map;
 
 
 /**
@@ -32,6 +36,9 @@ public class KeyWordApi {
     @Resource
     private KeywordListener keywordListener;
 
+    @Resource
+    private LabelListener labelListener;
+
     /**
      * 关键词列表
      * keyword 关键词
@@ -142,32 +149,103 @@ public class KeyWordApi {
     public ResponseJson<List<ServiceProviderModel>> getServiceList() { return keyWordService.getServiceList(); }
 
     /**
-     * 静态标签列表
+     * 动态/静态标签列表
+     * dynamicStatus 动态静态标记 0:动态标签;1:静态标签
+     * parentLabel 父标签标记  父标签 0 否 1 是
      * keyword 关键词
      * beginTime  自定义时间查询起始时间
      * endTime    自定义时间查询终止时间
-     * labelStatus  标签库状态 0未添加 1已添加 传1即是标签列表
      * fromSearch 标签库数据来源(1:手动添加;2:用户关键词统计;3:导入 4:协销填写)
+     * serviceProviderId 协销id
      */
     @GetMapping("/statekeyword/list")
-    public ResponseJson<PaginationVo<KeyWord>> getStateKeyWordList(String keyword, String beginTime, String endTime,
-                                                                   Integer fromSearch,  Integer serviceProviderId,
-                                                              @RequestParam(value = "pageNum", defaultValue = "1") int pageNum,
-                                                              @RequestParam(value = "pageSize", defaultValue = "20") int pageSize) {
-        return keyWordService.getStateKeyWordList(keyword, fromSearch, beginTime, endTime, serviceProviderId, pageNum, pageSize);
+    public ResponseJson<PaginationVo<CmKeywordInfo>> getStateKeyWordList(Integer dynamicStatus, Integer parentLabel,
+                                                                         String keyword, String beginTime, String endTime,
+                                                                         Integer fromSearch, Integer serviceProviderId,
+                                                                         @RequestParam(value = "pageNum", defaultValue = "1") int pageNum,
+                                                                         @RequestParam(value = "pageSize", defaultValue = "20") int pageSize) {
+        if (null == dynamicStatus) {
+            return ResponseJson.error(-1, "类型不能为空", null);
+        }
+        return keyWordService.getStateKeyWordList(dynamicStatus, parentLabel, keyword, fromSearch, beginTime, endTime, serviceProviderId, pageNum, pageSize);
     }
 
     /**
-     * 保存静态标签
+     * 动态标签编辑回显
+     * @param id
+     * @return
+     */
+    @GetMapping("/editKeyword")
+    public ResponseJson<CmKeywordInfo> editKeyword(Integer id) {
+        if (null == id) {
+            return  ResponseJson.error(-1, "id不能为空", null);
+        }
+        return keyWordService.editKeyword(id);
+    }
+
+    /**
+     * 获取子标签
      * @param keyword
+     * @param pageNum
+     * @param pageSize
+     * @return
+     */
+    @GetMapping("/getSubtagKeyword")
+    public ResponseJson<PaginationVo<CmKeywordInfo>> getSubtagKeyword(String keyword,
+                                                                      @RequestParam(value = "pageNum", defaultValue = "1") int pageNum,
+                                                                      @RequestParam(value = "pageSize", defaultValue = "20") int pageSize) {
+
+        return keyWordService.getSubtagKeyword(keyword, pageNum, pageSize);
+    }
+
+    /**
+     * 保存 动态/静态标签
+     * @param cmKeywordInfo
      * @return
      */
-    @GetMapping("/saveLabelByState")
-    public ResponseJson saveLabelByState(String keyword) {
-        if (StringUtils.isBlank(keyword)) {
+    @PostMapping("/saveLabelByState")
+    public ResponseJson saveLabelByState(@RequestBody CmKeywordInfo cmKeywordInfo) {
+        if (null == cmKeywordInfo) {
+            return ResponseJson.error(-1, "参数错误", null);
+        }
+        if (StringUtils.isBlank(cmKeywordInfo.getKeyword())) {
             return ResponseJson.error(-1, "标签不能为空", null);
         }
-        return keyWordService.insertLabelByState(keyword);
+        if (null == cmKeywordInfo.getDynamicStatus()) {
+            return ResponseJson.error(-1, "标签归属类型不能为空", null);
+        }
+        return keyWordService.insertKeywordInfo(cmKeywordInfo);
+    }
+
+    /**
+     * 删除动态/静态标签
+     *
+     * @param id
+     * @return
+     */
+    @GetMapping("/delete/TrendsLabel")
+    public ResponseJson delTrendsLabel(String id) {
+        if (StringUtils.isBlank(id)) {
+            return ResponseJson.error(-1, "id不能为空", null);
+        }
+        return keyWordService.deleteTrendsLabel(id);
+    }
+
+    /**
+     * 导入动态标签
+     *
+     * @param keywordFile
+     * @return
+     */
+    @PostMapping("/import/keywordLabel")
+    public ResponseJson doKeywordImport(MultipartFile keywordFile) {
+        try {
+            InputStream inputStream = keywordFile.getInputStream();
+            EasyExcel.read(inputStream, CmKeywordInfo.class, labelListener).sheet().doRead();
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+        return ResponseJson.success();
     }
 
     /**

+ 23 - 0
src/main/java/com/caimei365/manager/controller/caimei/user/CmBehaviorRecordApi.java

@@ -7,6 +7,7 @@ import com.alibaba.excel.write.metadata.WriteSheet;
 import com.caimei365.manager.entity.PaginationVo;
 import com.caimei365.manager.entity.ResponseJson;
 import com.caimei365.manager.entity.caimei.CmBehaviorRecord;
+import com.caimei365.manager.entity.caimei.CmPageType;
 import com.caimei365.manager.service.caimei.user.CmBehaviorRecordService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
@@ -29,6 +30,28 @@ public class CmBehaviorRecordApi {
 
     @Autowired private CmBehaviorRecordService recordService;
 
+    /**
+     * 获取父标签
+     * @param keyword
+     * @return
+     */
+    @GetMapping("/getKeyword")
+    public ResponseJson getKeyword(String keyword) {
+
+        return recordService.getKeyword(keyword);
+    }
+
+    /**
+     * 获取页面类型
+     * @param pageLabels
+     * @return
+     */
+    @GetMapping("/getPageType")
+    public ResponseJson<List<CmPageType>> getPageType(String pageLabels) {
+
+        return recordService.getPageType(pageLabels);
+    }
+
     /**
      * 用户行为记录列表数据
      * @param cmBehaviorRecord 参数

+ 58 - 3
src/main/java/com/caimei365/manager/dao/KeyWordDao.java

@@ -1,5 +1,7 @@
 package com.caimei365.manager.dao;
 
+import com.caimei365.manager.entity.caimei.CmKeywordInfo;
+import com.caimei365.manager.entity.caimei.CmKeywordSubtag;
 import com.caimei365.manager.entity.caimei.CmPriorKeyword;
 import com.caimei365.manager.entity.caimei.KeyWord;
 import com.caimei365.manager.entity.caimei.cmUser.ServiceProviderModel;
@@ -29,6 +31,13 @@ public interface KeyWordDao {
 
     Integer findKeywordExist(String keyword);
 
+    /**
+     * 是否已存在
+     * @param keyword
+     * @return
+     */
+    Integer getKeywordByName(String keyword);
+
     Map<String, String> findLinkageStatus(String id);
 
     void updateDelFlag(String id);
@@ -43,6 +52,8 @@ public interface KeyWordDao {
 
     /**
      * 静态标签列表
+     * @param dynamicStatus
+     * @param parentLabel
      * @param keyword
      * @param fromSearch
      * @param beginTime
@@ -50,14 +61,58 @@ public interface KeyWordDao {
      * @param serviceProviderId
      * @return
      */
-    List<KeyWord> getStateKeyWordList(String keyword, Integer fromSearch, String beginTime, String endTime, Integer serviceProviderId);
+    List<CmKeywordInfo> getStateKeyWordList(Integer dynamicStatus, Integer parentLabel, String keyword, Integer fromSearch, String beginTime, String endTime, Integer serviceProviderId);
+
+    /**
+     * 动态标签编辑
+     * @param id
+     * @return
+     */
+    CmKeywordInfo getkeywordById(@Param("id") Integer id);
+
+    /**
+     * 动态标签子标签集合
+     * @param id
+     * @return
+     */
+    List<CmKeywordSubtag> getkeywordSubtag(@Param("id") Integer id);
 
     /**
-     * 插入静态标签
+     * 获取所有子标签
      * @param keyword
+     * @return
+     */
+    List<CmKeywordInfo> getKeyword(@Param("keyword") String keyword);
+
+    /**
+     * 插入 动态/静态标签
+     * @param cmKeywordInfo
      */
-    void insertLabelByState(String keyword);
+    void insertKeywordInfo(CmKeywordInfo cmKeywordInfo);
 
+    /**
+     * 修改标签数据
+     * @param cmKeywordInfo
+     */
+    void updateKeyword(CmKeywordInfo cmKeywordInfo);
+
+    /**
+     * 添加子标签与父标签的关联
+     * @param subtag
+     */
+    void insertKeywordSubtag(CmKeywordSubtag subtag);
+
+    /**
+     * 删除与父标签的关联
+     * @param keywordId
+     * @param ids
+     */
+    void updateKeywordSubtag(@Param("keywordId") Integer keywordId, @Param("ids") List<Integer> ids);
+    /**
+     * 删除动态/静态标签
+     * @param id
+     */
+    void updateKeywordInfo(@Param("id") String id);
     /**
      * 优先展示标签
      * @param keyword

+ 14 - 0
src/main/java/com/caimei365/manager/dao/user/CmBehaviorRecordDao.java

@@ -1,6 +1,7 @@
 package com.caimei365.manager.dao.user;
 
 import com.caimei365.manager.entity.caimei.CmBehaviorRecord;
+import com.caimei365.manager.entity.caimei.CmPageType;
 import com.caimei365.manager.entity.caimei.RetuenEntity;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
@@ -15,6 +16,19 @@ import java.util.List;
  */
 @Mapper
 public interface CmBehaviorRecordDao {
+    /**
+     * 获取父标签
+     * @param keyword
+     * @return
+     */
+    List<RetuenEntity> getkeyword(@Param("keyword") String keyword);
+
+    /**
+     * 页面标签
+     * @param pageLabels
+     * @return
+     */
+    List<CmPageType> getPageType(@Param("pageLabels") String pageLabels);
 
     /**
      * 昨日数据

+ 5 - 0
src/main/java/com/caimei365/manager/entity/caimei/CmBehaviorRecord.java

@@ -249,4 +249,9 @@ public class CmBehaviorRecord {
      */
     @ExcelIgnore
     private Integer exportType;
+    /**
+     * 父标签查询
+     */
+    @ExcelIgnore
+    private String pageLabels;
 }

+ 56 - 0
src/main/java/com/caimei365/manager/entity/caimei/CmKeywordInfo.java

@@ -0,0 +1,56 @@
+package com.caimei365.manager.entity.caimei;
+
+import com.alibaba.excel.annotation.ExcelProperty;
+import lombok.Data;
+
+import java.util.Date;
+import java.util.List;
+
+/**
+ * Description
+ *
+ * @author : hzg
+ * @date : 2023/11/28
+ */
+@Data
+public class CmKeywordInfo {
+
+    private Integer id;
+    /**
+     * 标签库数据来源(1:手动添加;4:协销填写)
+     */
+    private Integer fromSearch;
+    /**
+     * 协销Id 当 fromSearch 为 4的时候有值
+     */
+    private Integer serviceProviderId;
+    /**
+     * 标签
+     */
+    @ExcelProperty("标签名")
+    private String keyword;
+    /**
+     * 子标签
+     */
+    private List<CmKeywordSubtag> subtag;
+    /**
+     * 0:动态标签;1:静态标签
+     */
+    private Integer dynamicStatus;
+    /**
+     * 父标签 0 否 1 是
+     */
+    private Integer parentLabel;
+    /**
+     * 添加时间
+     */
+    private Date addTime;
+    /**
+     * 联动搜索状态:0未启用,1已启用
+     */
+    private Integer linkageStatus;
+    /**
+     * 0:已删除;1未删除
+     */
+    private Integer delFlag;
+}

+ 36 - 0
src/main/java/com/caimei365/manager/entity/caimei/CmKeywordSubtag.java

@@ -0,0 +1,36 @@
+package com.caimei365.manager.entity.caimei;
+
+import lombok.Data;
+
+import java.util.List;
+
+/**
+ * Description
+ *
+ * @author : hzg
+ * @date : 2023/11/29
+ */
+@Data
+public class CmKeywordSubtag {
+    private Integer id;
+    /**
+     * 父标签id
+     */
+    private Integer keywordId;
+    /**
+     * 子标签Id
+     */
+    private Integer subtagId;
+    /**
+     * 子标签名
+     */
+    private String keyword;
+    /**
+     * 添加时间
+     */
+    private String addTime;
+    /**
+     * 删除标记 0 未删除 1 已删除
+     */
+    private Integer delFlag;
+}

+ 21 - 0
src/main/java/com/caimei365/manager/entity/caimei/CmPageType.java

@@ -0,0 +1,21 @@
+package com.caimei365.manager.entity.caimei;
+
+import lombok.Data;
+
+/**
+ * Description
+ *
+ * @author : hzg
+ * @date : 2023/12/1
+ */
+@Data
+public class CmPageType {
+    /**
+     * id
+     */
+    private Integer id;
+    /**
+     * 页面类型
+     */
+    private String pageType;
+}

+ 29 - 4
src/main/java/com/caimei365/manager/service/caimei/KeyWordService.java

@@ -2,11 +2,13 @@ package com.caimei365.manager.service.caimei;
 
 import com.caimei365.manager.entity.PaginationVo;
 import com.caimei365.manager.entity.ResponseJson;
+import com.caimei365.manager.entity.caimei.CmKeywordInfo;
 import com.caimei365.manager.entity.caimei.CmPriorKeyword;
 import com.caimei365.manager.entity.caimei.KeyWord;
 import com.caimei365.manager.entity.caimei.cmUser.ServiceProviderModel;
 
 import java.util.List;
+import java.util.Map;
 
 /**
  * @author zzj
@@ -33,7 +35,9 @@ public interface KeyWordService {
     ResponseJson<List<ServiceProviderModel>> getServiceList();
 
     /**
-     * 静态标签列表
+     * 动态/静态标签列表
+     * @param dynamicStatus
+     * @param parentLabel
      * @param keyword
      * @param fromSearch
      * @param beginTime
@@ -42,15 +46,36 @@ public interface KeyWordService {
      * @param pageSize
      * @return
      */
-    ResponseJson<PaginationVo<KeyWord>> getStateKeyWordList(String keyword, Integer fromSearch, String beginTime, String endTime, Integer serviceProviderId, int pageNum, int pageSize);
+    ResponseJson<PaginationVo<CmKeywordInfo>> getStateKeyWordList(Integer dynamicStatus, Integer parentLabel, String keyword, Integer fromSearch, String beginTime, String endTime, Integer serviceProviderId, int pageNum, int pageSize);
 
     /**
-     * 插入静态标签
+     * 动态标签编辑回显
+     * @param id
+     * @return
+     */
+    ResponseJson<CmKeywordInfo> editKeyword(Integer id);
+
+    /**
+     * 选择子标签
      * @param keyword
+     * @param pageNum
+     * @param pageSize
      * @return
      */
-    ResponseJson insertLabelByState(String keyword);
+    ResponseJson<PaginationVo<CmKeywordInfo>> getSubtagKeyword(String keyword,  int pageNum, int pageSize);
+    /**
+     * 保存 动态/静态标签
+     * @param cmKeywordInfo
+     * @return
+     */
+    ResponseJson insertKeywordInfo(CmKeywordInfo cmKeywordInfo);
 
+    /**
+     * 删除动态标签
+     * @param id
+     * @return
+     */
+    ResponseJson deleteTrendsLabel(String id);
     /**
      * 优先展示标签列表
      * @param keyword

+ 109 - 11
src/main/java/com/caimei365/manager/service/caimei/impl/KeyWordServiceImpl.java

@@ -5,6 +5,8 @@ import com.caimei.utils.StringUtils;
 import com.caimei365.manager.dao.KeyWordDao;
 import com.caimei365.manager.entity.PaginationVo;
 import com.caimei365.manager.entity.ResponseJson;
+import com.caimei365.manager.entity.caimei.CmKeywordInfo;
+import com.caimei365.manager.entity.caimei.CmKeywordSubtag;
 import com.caimei365.manager.entity.caimei.CmPriorKeyword;
 import com.caimei365.manager.entity.caimei.KeyWord;
 import com.caimei365.manager.entity.caimei.cmUser.ServiceProviderModel;
@@ -17,6 +19,7 @@ import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.Date;
 import java.util.List;
 import java.util.Map;
@@ -175,7 +178,9 @@ public class KeyWordServiceImpl implements KeyWordService {
     }
 
     /**
-     * 静态标签列表
+     * 动态/静态标签列表
+     * @param dynamicStatus
+     * @param parentLabel
      * @param keyword
      * @param fromSearch
      * @param beginTime
@@ -186,28 +191,121 @@ public class KeyWordServiceImpl implements KeyWordService {
      * @return
      */
     @Override
-    public ResponseJson<PaginationVo<KeyWord>> getStateKeyWordList(String keyword, Integer fromSearch, String beginTime, String endTime, Integer serviceProviderId, int pageNum, int pageSize) {
+    public ResponseJson<PaginationVo<CmKeywordInfo>> getStateKeyWordList(Integer dynamicStatus, Integer parentLabel, String keyword, Integer fromSearch, String beginTime, String endTime, Integer serviceProviderId, int pageNum, int pageSize) {
         PageHelper.startPage(pageNum, pageSize);
-        List<KeyWord> keyWords = keyWordDao.getStateKeyWordList(keyword, fromSearch, beginTime, endTime, serviceProviderId);
-        PaginationVo<KeyWord> pageData = new PaginationVo<>(keyWords);
+        List<CmKeywordInfo> keyWords = keyWordDao.getStateKeyWordList(dynamicStatus, parentLabel, keyword, fromSearch, beginTime, endTime, serviceProviderId);
+        PaginationVo<CmKeywordInfo> pageData = new PaginationVo<>(keyWords);
         return ResponseJson.success(pageData);
     }
 
     /**
-     * 插入静态标签
+     * 动态标签编辑回显
+     *
+     * @param id
+     * @return
+     */
+    @Override
+    public ResponseJson<CmKeywordInfo> editKeyword(Integer id) {
+        // 标签数据
+        CmKeywordInfo cmKeywordInfo = keyWordDao.getkeywordById(id);
+        if (null != cmKeywordInfo) {
+            // 前端要求默认 【】
+            cmKeywordInfo.setSubtag(new ArrayList<>());
+            // 若为父标签,获取子标签返回
+            if (1 == cmKeywordInfo.getParentLabel()) {
+                List<CmKeywordSubtag> cmKeywordSubtags = keyWordDao.getkeywordSubtag(id);
+                cmKeywordInfo.setSubtag(null == cmKeywordSubtags ? new ArrayList<>() : cmKeywordSubtags);
+            }
+        } else {
+            return ResponseJson.error(-1, "标签数据异常", null);
+        }
+        return ResponseJson.success(cmKeywordInfo);
+    }
+
+    /**
+     * 选择子标签
      *
      * @param keyword
+     * @param pageNum
+     * @param pageSize
+     * @return
+     */
+    @Override
+    public ResponseJson<PaginationVo<CmKeywordInfo>> getSubtagKeyword(String keyword, int pageNum, int pageSize) {
+        PageHelper.startPage(pageNum, pageSize);
+        List<CmKeywordInfo> keywordList = keyWordDao.getKeyword(keyword);
+        PaginationVo<CmKeywordInfo> page = new PaginationVo<>(keywordList);
+        return ResponseJson.success(page);
+    }
+
+    /**
+     * 保存 动态/静态标签
+     *
+     * @param cmKeywordInfo
      * @return
      */
     @Override
-    public ResponseJson insertLabelByState(String keyword) {
-        Integer keywordExist = keyWordDao.findKeywordExist(keyword);
-        if (null == keywordExist) {
-            keyWordDao.insertLabelByState(keyword);
-            return ResponseJson.success();
+    public ResponseJson insertKeywordInfo(CmKeywordInfo cmKeywordInfo) {
+        List<Integer> ids = new ArrayList<>();
+        if (null == cmKeywordInfo.getId()) {
+            // 添加
+            Integer key = keyWordDao.getKeywordByName(cmKeywordInfo.getKeyword());
+            // 添加标签
+            if (null == key) {
+                keyWordDao.insertKeywordInfo(cmKeywordInfo);
+            } else {
+                return ResponseJson.error(-1, "标签已存在", null);
+            }
         } else {
-            return ResponseJson.error(-1, "关键词已存在", null);
+            // 修改
+            keyWordDao.updateKeyword(cmKeywordInfo);
+        }
+        // 有子标签时将子标签与父标签关联
+        if (null != cmKeywordInfo.getSubtag() && cmKeywordInfo.getSubtag().size() > 0) {
+            for (CmKeywordSubtag subtag : cmKeywordInfo.getSubtag()) {
+                if (null == subtag.getId()) {
+                    return ResponseJson.error(-1, "子标签id不能为空", null);
+                }
+                subtag.setKeywordId(cmKeywordInfo.getId());
+                subtag.setSubtagId(subtag.getSubtagId());
+                keyWordDao.insertKeywordSubtag(subtag);
+                ids.add(subtag.getId());
+            }
+            if (null != ids && ids.size() >0) {
+                // 删除与父标签关联
+                keyWordDao.updateKeywordSubtag(cmKeywordInfo.getId(), ids);
+            }
+        }
+        return ResponseJson.success();
+    }
+
+    /**
+     * 删除动态标签
+     *
+     * @param id
+     * @return
+     */
+    @Override
+    public ResponseJson deleteTrendsLabel(String id) {
+        if (id.contains(",")) {
+            String[] split = id.split(",");
+            for (String s : split) {
+                // 删除动态/静态标签
+                keyWordDao.updateKeywordInfo(s);
+                // 删除有限展示标签
+                keyWordDao.delPriorKeywordById(Integer.parseInt(s));
+                // 删除子标签
+                keyWordDao.updateKeywordSubtag(Integer.parseInt(s), new ArrayList<>());
+            }
+        } else {
+            // 删除动态/静态标签
+            keyWordDao.updateKeywordInfo(id);
+            // 删除有限展示标签
+            keyWordDao.delPriorKeywordById(Integer.parseInt(id));
+            // 删除子标签
+            keyWordDao.updateKeywordSubtag(Integer.parseInt(id), new ArrayList<>());
         }
+        return ResponseJson.success();
     }
 
     /**

+ 62 - 0
src/main/java/com/caimei365/manager/service/caimei/listener/LabelListener.java

@@ -0,0 +1,62 @@
+package com.caimei365.manager.service.caimei.listener;
+
+import com.alibaba.excel.context.AnalysisContext;
+import com.alibaba.excel.event.AnalysisEventListener;
+import com.alibaba.fastjson.JSON;
+import com.caimei365.manager.dao.KeyWordDao;
+import com.caimei365.manager.entity.caimei.CmKeywordInfo;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.Resource;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Description
+ *
+ * @author : hzg
+ * @date : 2023/11/28
+ */
+@Slf4j
+@Service
+public class LabelListener extends AnalysisEventListener<CmKeywordInfo> {
+
+    @Resource
+    private KeyWordDao keyWordDao;
+
+    /**
+     * 批处理阈值
+     */
+    private static final int BATCH_COUNT = 20;
+
+    List<CmKeywordInfo> list = new ArrayList<>(BATCH_COUNT);
+
+    @Override
+    public void invoke(CmKeywordInfo data, AnalysisContext analysisContext) {
+        log.info("解析一条数据====" + JSON.toJSONString(data));
+        list.add(data);
+        if (list.size() >= BATCH_COUNT) {
+            save(list);
+            list.clear();
+        }
+    }
+
+    @Override
+    public void doAfterAllAnalysed(AnalysisContext analysisContext) {
+        save(list);
+        log.info("数据解析完成");
+    }
+
+    public void save(List<CmKeywordInfo> infoList) {
+        infoList.forEach(info -> {
+            Integer keywordId = keyWordDao.getKeywordByName(info.getKeyword());
+            if (null == keywordId) {
+                info.setDynamicStatus(0);
+                info.setParentLabel(0);
+                keyWordDao.insertKeywordInfo(info);
+            }
+        });
+    }
+}

+ 14 - 0
src/main/java/com/caimei365/manager/service/caimei/user/CmBehaviorRecordService.java

@@ -3,6 +3,7 @@ package com.caimei365.manager.service.caimei.user;
 import com.caimei365.manager.entity.PaginationVo;
 import com.caimei365.manager.entity.ResponseJson;
 import com.caimei365.manager.entity.caimei.CmBehaviorRecord;
+import com.caimei365.manager.entity.caimei.CmPageType;
 
 import java.util.List;
 
@@ -13,6 +14,19 @@ import java.util.List;
  * @date : 2023/3/15
  */
 public interface CmBehaviorRecordService {
+    /**
+     * 获取父标签
+     * @param keyword
+     * @return
+     */
+    ResponseJson getKeyword(String keyword);
+
+    /**
+     * 获取页面标签
+     * @param pageLabels
+     * @return
+     */
+    ResponseJson<List<CmPageType>> getPageType(String pageLabels);
     /**
      * 用户行为列表
      * @param cmBehaviorRecord

+ 24 - 0
src/main/java/com/caimei365/manager/service/caimei/user/impl/CmBehaviorRecordServiceImpl.java

@@ -6,6 +6,7 @@ import com.caimei365.manager.dao.user.CmBehaviorRecordDao;
 import com.caimei365.manager.entity.PaginationVo;
 import com.caimei365.manager.entity.ResponseJson;
 import com.caimei365.manager.entity.caimei.CmBehaviorRecord;
+import com.caimei365.manager.entity.caimei.CmPageType;
 import com.caimei365.manager.service.caimei.user.CmBehaviorRecordService;
 import com.github.pagehelper.PageHelper;
 import lombok.extern.slf4j.Slf4j;
@@ -31,6 +32,29 @@ public class CmBehaviorRecordServiceImpl implements CmBehaviorRecordService {
     @Resource
     private CmBehaviorRecordDao cmBehaviorRecordDao;
 
+    /**
+     * 获取父标签
+     *
+     * @param keyword
+     * @return
+     */
+    @Override
+    public ResponseJson getKeyword(String keyword) {
+        return ResponseJson.success(cmBehaviorRecordDao.getkeyword(keyword));
+    }
+
+    /**
+     * 获取页面标签
+     *
+     * @param pageLabels
+     * @return
+     */
+    @Override
+    public ResponseJson<List<CmPageType>> getPageType(String pageLabels) {
+        return ResponseJson.success(cmBehaviorRecordDao.getPageType(pageLabels));
+    }
+
+
     /**
      * 用户行为列表
      * @param cmBehaviorRecord

+ 37 - 0
src/main/resources/mapper/CmBehaciorRecordDao.xml

@@ -12,6 +12,31 @@
         b.accessTime,
         b.accessDate
     </sql>
+
+    <select id="getkeyword" resultType="com.caimei365.manager.entity.caimei.RetuenEntity">
+        select
+            id,
+            keyword as value
+        from cm_keyword_info
+        where parentLabel = 1
+        and delFlag = 1
+        <if test="keyword != null and keyword != ''">
+            and keyword like concat('%',#{keyword},'%')
+        </if>
+    </select>
+
+    <select id="getPageType" resultType="com.caimei365.manager.entity.caimei.CmPageType">
+        select
+            id,
+            pageType
+        from cm_page_type
+        <where>
+            <if test="pageLabels != null and pageLabels != ''">
+                pageType like concat('%',#{pageLabels},'%')
+            </if>
+        </where>
+    </select>
+
     <select id="findList" resultType="com.caimei365.manager.entity.caimei.CmBehaviorRecord">
         SELECT
         IP as ip,
@@ -72,6 +97,12 @@
                     label like concat('%',#{label},'%')
                 </foreach>
             </if>
+            <if test="pageLabels != null and pageLabels != ''">
+                AND pageLabels like concat('%', #{pageLabels}, '%')
+            </if>
+                <if test="pageTypes != null and pageTypes != ''">
+                AND pageTypes like concat('%', #{pageTypes}, '%')
+            </if>
             <if test="startTime != null and startTime != '' and endTime != null and endTime != ''">
                 AND accessDate between #{startTime} and #{endTime}
             </if>
@@ -135,6 +166,12 @@
                     label like concat('%',#{label},'%')
                 </foreach>
             </if>
+            <if test="pageLabels != null and pageLabels != ''">
+                AND pageLabels like concat('%', #{pageLabels}, '%')
+            </if>
+            <if test="pageTypes != null and pageTypes != ''">
+                AND pageTypes like concat('%', #{pageTypes}, '%')
+            </if>
             <if test="startTime != null and startTime != '' and endTime != null and endTime != ''">
                 AND accessDate between #{startTime} and #{endTime}
             </if>

+ 139 - 41
src/main/resources/mapper/KeyWordDao.xml

@@ -130,6 +130,14 @@
         limit 1
     </select>
 
+    <select id="getKeywordByName" resultType="java.lang.Integer">
+        select id
+        from cm_keyword_info
+        where keyword = #{keyword}
+          and delFlag = 1
+        limit 1
+    </select>
+
     <select id="getServiceList" resultType="com.caimei365.manager.entity.caimei.cmUser.ServiceProviderModel">
         SELECT
             ser.serviceProviderID AS serviceProviderId,
@@ -140,70 +148,160 @@
         order by ser.addTime asc
     </select>
 
-    <select id="getStateKeyWordList" resultType="com.caimei365.manager.entity.caimei.KeyWord">
-        SELECT cusf.id AS id, cusf.frequency, cusf.keyword as keyword, cusf.addTime,
-        cusf.searchTime as searchTime,cusf.trueStatus as labelStatus,cusf.fromSearch as fromSearch,
-        cusf.serviceProviderId, cusf.dynamicStatus, s.linkMan as name
-        FROM cm_user_search_frequency cusf
-        left join serviceprovider s on cusf.serviceProviderId = s.serviceProviderID
-        WHERE cusf.delStatus = 1 AND cusf.dynamicStatus = 1
-        <if test="beginTime !=null and beginTime !=''">
-            AND (cusf.searchTime BETWEEN #{beginTime} AND #{endTime} or cusf.searchTime IS NULL)
-        </if>
-        <if test="keyword !=null and keyword !=''">
-            AND cusf.keyword LIKE CONCAT('%',#{keyword},'%')
-        </if>
-        <if test="fromSearch != null">
-            AND cusf.fromSearch = #{fromSearch}
-        </if>
-        <if test="serviceProviderId != null">
-            AND cusf.serviceProviderID = #{serviceProviderId}
-        </if>
-        ORDER BY cusf.addTime DESC
+    <select id="getStateKeyWordList" resultType="com.caimei365.manager.entity.caimei.CmKeywordInfo">
+        SELECT cki.id AS id,
+        cki.keyword AS keyword,
+        cki.fromSearch AS fromSearch,
+        cki.serviceProviderId,
+        cki.dynamicStatus,
+        cki.parentLabel,
+        cki.addTime,
+        s.linkMan AS NAME
+        FROM cm_keyword_info cki
+        LEFT JOIN serviceprovider s ON cki.serviceProviderId = s.serviceProviderID
+        <where>
+            cki.delFlag = 1
+            <if test="dynamicStatus != null">
+               AND cki.dynamicStatus = #{dynamicStatus}
+            </if>
+            <if test="parentLabel != null">
+                AND cki.parentLabel = #{parentLabel}
+            </if>
+            <if test="beginTime !=null and beginTime !=''">
+                AND (cki.addTime BETWEEN #{beginTime} AND #{endTime} or cki.addTime IS NULL)
+            </if>
+            <if test="keyword !=null and keyword !=''">
+                AND cki.keyword LIKE CONCAT('%',#{keyword},'%')
+            </if>
+            <if test="fromSearch != null">
+                AND cki.fromSearch = #{fromSearch}
+            </if>
+            <if test="serviceProviderId != null">
+                AND cki.serviceProviderId = #{serviceProviderId}
+            </if>
+        </where>
+        ORDER BY cki.addTime DESC
     </select>
 
-    <insert id="insertLabelByState">
-        insert into cm_user_search_frequency(fromSearch, keyword, frequency, trueStatus, dynamicStatus, addTime)
-        values (1, #{keyword}, 0, 0, 1, now())
+    <select id="getkeywordById" resultType="com.caimei365.manager.entity.caimei.CmKeywordInfo">
+        SELECT
+            id AS id,
+            keyword AS keyword,
+            ifnull(parentLabel, 0) as parentLabel,
+            fromSearch AS fromSearch,
+            serviceProviderId,
+            dynamicStatus,
+            addTime
+        FROM cm_keyword_info
+        where delFlag = 1 and id = #{id}
+    </select>
+
+    <select id="getkeywordSubtag" resultType="com.caimei365.manager.entity.caimei.CmKeywordSubtag">
+        SELECT
+            cks.id AS id,
+            cki.keyword AS keyword,
+            cks.addTime
+        FROM cm_keyword_subtag cks
+        left join cm_keyword_info cki on cks.subtagId = cki.id
+        where cki.delFlag = 1 and cks.delFlag = 0 and cks.keywordId = #{id}
+    </select>
+
+    <select id="getKeyword" resultType="com.caimei365.manager.entity.caimei.CmKeywordInfo">
+        SELECT
+            id AS id,
+            keyword AS keyword,
+            parentLabel,
+            fromSearch AS fromSearch,
+            serviceProviderId,
+            dynamicStatus,
+            addTime
+        FROM cm_keyword_info
+        <where>
+            delFlag = 1 and parentLabel = 0
+            <if test="keyword != null and keyword != ''">
+                and keyword like concat ('%', #{keyword} , '%')
+            </if>
+        </where>
+        order by addTime desc
+    </select>
+
+    <insert id="insertKeywordInfo" keyProperty="id" keyColumn="id" useGeneratedKeys="true">
+        insert into cm_keyword_info(fromSearch, keyword, dynamicStatus, parentLabel, addTime, linkageStatus, delFlag)
+        values (1, #{keyword}, #{dynamicStatus}, #{parentLabel}, now(), 0, 0)
+    </insert>
+
+    <update id="updateKeyword">
+        update cm_keyword_info
+        set keyword = #{keyword},
+            parentLabel = #{parentLabel}
+        where id = #{id}
+    </update>
+
+    <insert id="insertKeywordSubtag" keyProperty="subtagId" keyColumn="id" useGeneratedKeys="true">
+        insert into cm_keyword_subtag(keywordId, subtagId, addTime, delFlag)
+        values (#{keywordId}, #{subtagId}, now(), 0)
     </insert>
 
+    <update id="updateKeywordSubtag">
+        update cm_keyword_subtag
+        set delFlag = 1
+        where keywordId = #{keywordId}
+          <if test="ids.size()>0">
+            and id not in
+            <foreach collection="ids" item="id" open="(" separator="," close=")">
+                #{id}
+            </foreach>
+          </if>
+    </update>
+
+    <update id="updateKeywordInfo">
+        update cm_keyword_info
+        set delFlag = 0
+        where id = #{id}
+    </update>
+
     <select id="getPriorKeywordList" resultType="com.caimei365.manager.entity.caimei.CmPriorKeyword">
         select
-            cpk.id, cpk.searchId AS searchId ,cusf.fromSearch as fromSearch, cusf.keyword as keyword, cusf.dynamicStatus,
-            cusf.serviceProviderId, cpk.addTime, s.linkMan as name
+            cpk.id, cpk.searchId AS searchId ,cki.fromSearch as fromSearch, cki.keyword as keyword, cki.dynamicStatus,
+            cki.serviceProviderId, cpk.addTime, s.linkMan as name
         from cm_prior_keyword cpk
-        left join cm_user_search_frequency cusf on cpk.searchId = cusf.id
-        left join serviceprovider s on cusf.serviceProviderId = s.serviceProviderID
-        WHERE cpk.delFlag = 0 AND cusf.delStatus = 1
+        left join cm_keyword_info cki on cpk.searchId = cki.id
+        left join serviceprovider s on cki.serviceProviderId = s.serviceProviderID
+        WHERE cpk.delFlag = 0 AND cki.delFlag = 1
         <if test="keyword !=null and keyword !=''">
-            AND cusf.keyword LIKE CONCAT('%',#{keyword},'%')
+            AND cki.keyword LIKE CONCAT('%',#{keyword},'%')
         </if>
         <if test="fromSearch != null">
-            AND cusf.fromSearch = #{fromSearch}
+            AND cki.fromSearch = #{fromSearch}
         </if>
         <if test="dynamicStatus != null">
-            AND cusf.dynamicStatus = #{dynamicStatus}
+            AND cki.dynamicStatus = #{dynamicStatus}
         </if>
         order by cpk.addTime desc
     </select>
 
     <select id="getPickKeyword" resultType="com.caimei365.manager.entity.caimei.KeyWord">
-        SELECT cusf.id AS id, cusf.frequency, cusf.keyword as keyword, cusf.addTime,
-        cusf.searchTime as searchTime,cusf.trueStatus as labelStatus,cusf.fromSearch as fromSearch,
-        cusf.serviceProviderId, cusf.dynamicStatus, s.linkMan as name
-        FROM cm_user_search_frequency cusf
-        left join serviceprovider s on cusf.serviceProviderId = s.serviceProviderID
-        WHERE cusf.delStatus = 1
+        SELECT
+               cki.id AS id,
+               cki.keyword as keyword,
+               cki.addTime,
+               cki.fromSearch as fromSearch,
+               cki.serviceProviderId,
+               cki.dynamicStatus,
+               s.linkMan as name
+        FROM cm_keyword_info cki
+        left join serviceprovider s on cki.serviceProviderId = s.serviceProviderID
+        WHERE cki.delFlag = 1
         <if test="keyword !=null and keyword !=''">
-            AND cusf.keyword LIKE CONCAT('%',#{keyword},'%')
+            AND cki.keyword LIKE CONCAT('%',#{keyword},'%')
         </if>
         <if test="fromSearch != null">
-            AND cusf.fromSearch = #{fromSearch}
+            AND cki.fromSearch = #{fromSearch}
         </if>
         <if test="dynamicStatus != null">
-            AND cusf.dynamicStatus = #{dynamicStatus}
+            AND cki.dynamicStatus = #{dynamicStatus}
         </if>
-        ORDER BY cusf.addTime DESC
+        ORDER BY cki.addTime DESC
     </select>
 
     <select id="getPriorCount" resultType="java.lang.Integer">