Browse Source

用户行为优化1.0.2

huangzhiguo 1 year ago
parent
commit
7becfc038f

+ 4 - 4
src/main/java/com/caimei365/tools/controller/BaseApi.java

@@ -61,20 +61,20 @@ public class BaseApi {
     /**
     /**
      * 用户活跃
      * 用户活跃
      */
      */
-    /*@GetMapping("/record/update")
+    @GetMapping("/record/update")
     public void svipCoupon() throws IOException {
     public void svipCoupon() throws IOException {
 //        cmVipCouponService.openCoupon();
 //        cmVipCouponService.openCoupon();
 //        cmBehaviorRecordService.updateClubAddress(startId, endId);
 //        cmBehaviorRecordService.updateClubAddress(startId, endId);
         cmOrganValueSystemService.insertOrgan();
         cmOrganValueSystemService.insertOrgan();
-    }*/
+    }
 
 
     /**
     /**
      * 用户价值
      * 用户价值
      */
      */
-    /*@GetMapping("/record/getData")
+    @GetMapping("/record/getData")
     public void getData(){
     public void getData(){
         cmOrganValueSystemService.insertcustomer();
         cmOrganValueSystemService.insertcustomer();
-    }*/
+    }
 
 
     /**
     /**
      * 合并ip
      * 合并ip

+ 34 - 2
src/main/java/com/caimei365/tools/mapper/CmBehaviorRecordMapper.java

@@ -15,9 +15,41 @@ import java.util.Map;
  */
  */
 @Mapper
 @Mapper
 public interface CmBehaviorRecordMapper {
 public interface CmBehaviorRecordMapper {
-
+    /**
+     * 获取供应商名称
+     * @param shopId
+     * @return
+     */
     String getShopName(@Param("shopId") Integer shopId);
     String getShopName(@Param("shopId") Integer shopId);
 
 
+    /**
+     * 获取页面默认标签
+     * @param type
+     * @return
+     */
+    String getPageLabel(@Param("type") Integer type);
+
+    /**
+     * 获取商品详情标签
+     * @param productId
+     * @return
+     */
+    String getProductPageLabel(@Param("productId") Integer productId);
+
+    /**
+     * 获取文章详情标签
+     * @param infoId
+     * @return
+     */
+    String getInfoPageLabel(@Param("Id") Integer infoId);
+
+    /**
+     * 采美百科标签
+     * @param id
+     * @return
+     */
+    String getBaiKePageLabel(@Param("Id") Integer id);
+
     /**
     /**
      * 用户行为记录
      * 用户行为记录
      * @param cmBehaviorRecordPo
      * @param cmBehaviorRecordPo
@@ -250,7 +282,7 @@ public interface CmBehaviorRecordMapper {
      */
      */
     Integer selShopId(@Param("shopId") Integer ShopId);
     Integer selShopId(@Param("shopId") Integer ShopId);
     /**
     /**
-     * 添加惯量供应商
+     * 添加关联供应商
      * @param recordId 用户行为记录id
      * @param recordId 用户行为记录id
      * @param shopId 供应商id
      * @param shopId 供应商id
      */
      */

+ 111 - 31
src/main/java/com/caimei365/tools/service/impl/CmBehaviorRecordServiceImpl.java

@@ -47,8 +47,10 @@ public class CmBehaviorRecordServiceImpl implements CmBehaviorRecordService {
             } else {
             } else {
                 cmBehaviorRecordPo.setUserId("0");
                 cmBehaviorRecordPo.setUserId("0");
             }
             }
+            boolean flag = true;
             if (ipSavePo.getParams().contains("userId") || ipSavePo.getParams().contains("productId")) {
             if (ipSavePo.getParams().contains("userId") || ipSavePo.getParams().contains("productId")) {
                 String[] split = ipSavePo.getParams().split("&");
                 String[] split = ipSavePo.getParams().split("&");
+
                 for (String s : split) {
                 for (String s : split) {
                     String str = s.trim();
                     String str = s.trim();
                     // 页面路径
                     // 页面路径
@@ -113,9 +115,7 @@ public class CmBehaviorRecordServiceImpl implements CmBehaviorRecordService {
                             }
                             }
                         }
                         }
                     }
                     }
-                    if (StringUtils.isBlank(cmBehaviorRecordPo.getPageLabel()) || StringUtils.isEmpty(cmBehaviorRecordPo.getPageLabel())) {
-                        cmBehaviorRecordPo.setPageLabel(" ");
-                    }
+
                     // 用户行为记录 or roos页面统计
                     // 用户行为记录 or roos页面统计
                     if (str.startsWith("behaviorType") && str.contains("=")) {
                     if (str.startsWith("behaviorType") && str.contains("=")) {
                         String[] split1 = str.split("=");
                         String[] split1 = str.split("=");
@@ -207,7 +207,8 @@ public class CmBehaviorRecordServiceImpl implements CmBehaviorRecordService {
                             if (StringUtils.isNotBlank(trim)) {
                             if (StringUtils.isNotBlank(trim)) {
                                 // 浏览器userAgent
                                 // 浏览器userAgent
                                 cmBehaviorRecordPo.setUserAgent(trim);
                                 cmBehaviorRecordPo.setUserAgent(trim);
-                                if (boolReptiles(trim)) {
+                                flag = boolReptiles(trim);
+                                if (flag) {
                                     cmBehaviorRecordPo.setDelFlag("1");
                                     cmBehaviorRecordPo.setDelFlag("1");
                                 }
                                 }
                             }
                             }
@@ -242,8 +243,85 @@ public class CmBehaviorRecordServiceImpl implements CmBehaviorRecordService {
                     }
                     }
 
 
                 }
                 }
+                // 处理页面标签为空
+                if (StringUtils.isBlank(cmBehaviorRecordPo.getPageLabel()) || StringUtils.isEmpty(cmBehaviorRecordPo.getPageLabel())) {
+                    String pageLabel = "";
+                    if (6 == cmBehaviorRecordPo.getPageType()) {
+                        // 商品详情
+                        String productId = "";
+                        if ("0".equals(cmBehaviorRecordPo.getAccessClient())) {
+                            // 网站访问
+                            String[] labelPath = cmBehaviorRecordPo.getPagePath().split("-");
+                            if (labelPath[1].contains(".html")) {
+                                // http://localhost:8009/product-1017.html
+                                productId = labelPath[1].substring(0, labelPath[1].lastIndexOf(".html"));
+                            } else {
+                                // http://localhost:8009/product-7425-5.html
+                                productId = labelPath[1];
+                            }
+                        } else {
+                            // 小程序访问
+                            if (cmBehaviorRecordPo.getPagePath().contains("id=")) {
+                                if (cmBehaviorRecordPo.getPagePath().contains("&typeId")) {
+                                    // /pages/goods/product?id=7425&typeId=5
+                                    productId = cmBehaviorRecordPo.getPagePath().substring(cmBehaviorRecordPo.getPagePath().indexOf("id="), cmBehaviorRecordPo.getPagePath().lastIndexOf("&typeId"));
+                                } else {
+                                    // /pages/goods/product?id=1017
+                                    productId = cmBehaviorRecordPo.getPagePath().substring(cmBehaviorRecordPo.getPagePath().indexOf("id=")+3);
+                                }
+                            }
+                        }
+                        try {
+                            pageLabel = recordMapper.getProductPageLabel(Integer.parseInt(productId.trim()));
+                        } catch (Exception e) {
+                            e.printStackTrace();
+                        }
+                    } else if (11 == cmBehaviorRecordPo.getPageType()) {
+                        String infoId = "";
+                        // 文章详情
+                        if ("0".equals(cmBehaviorRecordPo.getAccessClient())) {
+                            // 网站
+                            // https://www.caimei365.com/info/detail-5555-1.html
+                            String[] labelPath = cmBehaviorRecordPo.getPagePath().split("-");
+                            if (labelPath[1].contains(".html")) {
+                                // 暂无该情况
+                                infoId = labelPath[1].substring(0, labelPath[1].lastIndexOf(".html"));
+                            }else {
+                                infoId = labelPath[1];
+                            }
+                        }
+                        try {
+                            pageLabel = recordMapper.getInfoPageLabel(Integer.parseInt(infoId.trim()));
+                        } catch (Exception e) {
+                            e.printStackTrace();
+                        }
+                    } else if (12 == cmBehaviorRecordPo.getPageType()){
+                        String baikeId = "";
+                        // 采美百科
+                        if ("0".equals(cmBehaviorRecordPo.getAccessClient())) {
+                            // 网站
+                            // https://www.caimei365.com/encyclopedia/instrument-10.html
+                            String[] labelPath = cmBehaviorRecordPo.getPagePath().split("-");
+                            if (labelPath[1].contains(".html")) {
+                                baikeId = labelPath[1].substring(0, labelPath[1].lastIndexOf(".html"));
+                            }else {
+                                // 暂无该情况
+                                baikeId = labelPath[1];
+                            }
+                        }
+                        try {
+                            pageLabel = recordMapper.getBaiKePageLabel(Integer.parseInt(baikeId.trim()));
+                        } catch (Exception e) {
+                            e.printStackTrace();
+                        }
+                    }
+                    if (StringUtils.isBlank(pageLabel) || StringUtils.isEmpty(pageLabel)) {
+                        // 为空查询页面标签、或者使用初始默认数据
+                        pageLabel = recordMapper.getPageLabel(cmBehaviorRecordPo.getPageType());
+                    }
+                    cmBehaviorRecordPo.setPageLabel(pageLabel);
+                }
             }
             }
-
             Date date = new Date();
             Date date = new Date();
             cmBehaviorRecordPo.setAccessTime(date);
             cmBehaviorRecordPo.setAccessTime(date);
             cmBehaviorRecordPo.setAccessDuration("5000");
             cmBehaviorRecordPo.setAccessDuration("5000");
@@ -259,37 +337,39 @@ public class CmBehaviorRecordServiceImpl implements CmBehaviorRecordService {
                 e.printStackTrace();
                 e.printStackTrace();
             }
             }
             cmBehaviorRecordPo.setRegion(region);
             cmBehaviorRecordPo.setRegion(region);
-            recordMapper.insertRecord(cmBehaviorRecordPo);
-
-            int recordId = cmBehaviorRecordPo.getRecordID();
-            if (cmBehaviorRecordPo.getShopId() != null) {
-                if (14 != cmBehaviorRecordPo.getPageType()) {
-                    if (StringUtils.isNotBlank(cmBehaviorRecordPo.getPageLabel())) {
-                        List<String> strList = new ArrayList<>();
-                        // 页面标签在含有多个,包含 , 是可分割,进行分割作为关键词
-                        if (cmBehaviorRecordPo.getPageLabel().contains(",")) {
-                            String[] split = cmBehaviorRecordPo.getPageLabel().split(",");
-                            for (String s : split) {
-                                strList.add(s);
+            // if (flag) {
+                recordMapper.insertRecord(cmBehaviorRecordPo);
+
+                int recordId = cmBehaviorRecordPo.getRecordID();
+                if (cmBehaviorRecordPo.getShopId() != null) {
+                    if (14 != cmBehaviorRecordPo.getPageType()) {
+                        if (StringUtils.isNotBlank(cmBehaviorRecordPo.getPageLabel())) {
+                            List<String> strList = new ArrayList<>();
+                            // 页面标签在含有多个,包含 , 是可分割,进行分割作为关键词
+                            if (cmBehaviorRecordPo.getPageLabel().contains(",")) {
+                                String[] split = cmBehaviorRecordPo.getPageLabel().split(",");
+                                for (String s : split) {
+                                    strList.add(s);
+                                }
+                            } else {
+                                strList.add(cmBehaviorRecordPo.getPageLabel());
                             }
                             }
-                        } else {
-                            strList.add(cmBehaviorRecordPo.getPageLabel());
-                        }
-                        // 供应商id
-                        List<Integer> shopIds = recordMapper.shopIds(strList);
-                        if (shopIds.size() > 0) {
-                            for (Integer shopId : shopIds) {
-                                recordMapper.insertShopId(recordId, shopId);
+                            // 供应商id
+                            List<Integer> shopIds = recordMapper.shopIds(strList);
+                            if (shopIds.size() > 0) {
+                                for (Integer shopId : shopIds) {
+                                    recordMapper.insertShopId(recordId, shopId);
+                                }
                             }
                             }
                         }
                         }
-                    }
-                } else {
-                    Integer id = recordMapper.selShopId(cmBehaviorRecordPo.getShopId());
-                    if (id != null) {
-                        recordMapper.insertShopId(recordId, cmBehaviorRecordPo.getShopId());
+                    } else {
+                        Integer id = recordMapper.selShopId(cmBehaviorRecordPo.getShopId());
+                        if (id != null) {
+                            recordMapper.insertShopId(recordId, cmBehaviorRecordPo.getShopId());
+                        }
                     }
                     }
                 }
                 }
-            }
+            //}
         }
         }
     }
     }
 
 

+ 16 - 0
src/main/resources/mapper/CmBehaviorRecordMapper.xml

@@ -6,6 +6,22 @@
         select name from shop where shopId = #{shopId}
         select name from shop where shopId = #{shopId}
     </select>
     </select>
 
 
+    <select id="getPageLabel" resultType="java.lang.String">
+        select pageType from cm_page_type where id = #{type}
+    </select>
+
+    <select id="getProductPageLabel" resultType="java.lang.String">
+        SELECT relatedLabels FROM product WHERE productId = #{productId}
+    </select>
+
+    <select id="getInfoPageLabel" resultType="java.lang.String">
+        SELECT relatedLabels FROM info WHERE id = #{Id}
+    </select>
+
+    <select id="getBaiKePageLabel" resultType="java.lang.String">
+        SELECT relatedLabels FROM cm_baike_product WHERE id = #{Id}
+    </select>
+
     <insert id="insertRecord" parameterType="com.caimei365.tools.model.po.CmBehaviorRecordPo" useGeneratedKeys="true" keyProperty="recordID">
     <insert id="insertRecord" parameterType="com.caimei365.tools.model.po.CmBehaviorRecordPo" useGeneratedKeys="true" keyProperty="recordID">
         INSERT INTO cm_behavior_record (IP, userID, touristId, pagePath, pageType, pageLabel, behaviorType, productID, accessTime,
         INSERT INTO cm_behavior_record (IP, userID, touristId, pagePath, pageType, pageLabel, behaviorType, productID, accessTime,
                                         accessDuration, accessDate, referer, accessSource, accessClient, isReckon, region, userAgent, openId, delFlag)
                                         accessDuration, accessDate, referer, accessSource, accessClient, isReckon, region, userAgent, openId, delFlag)