Browse Source

用户行为优化1.0.5

huangzhiguo 1 year ago
parent
commit
02285c0ef8

+ 36 - 0
src/main/java/com/caimei/www/mapper/ShortLinkDao.java

@@ -1,5 +1,6 @@
 package com.caimei.www.mapper;
 
+import com.caimei.www.pojo.link.CmBehaviorInfoPo;
 import com.caimei.www.pojo.link.ShortLink;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
@@ -29,4 +30,39 @@ public interface ShortLinkDao {
     void updateOnClick(Integer markId);
 
     void updateShortLink(@Param("link")String link,@Param("ip") String ip);
+
+    /**
+     * 机构信息
+     * @param link
+     * @return
+     */
+    CmBehaviorInfoPo getClubSpId(@Param("link") String link);
+
+    /**
+     * 文章标签
+     * @param infoId
+     * @return
+     */
+    String getInfoLabels(@Param("indoId") Integer infoId);
+
+    /**
+     * 商品标签
+     * @param productId
+     * @return
+     */
+    String getProductLabels(@Param("productId") Integer productId);
+
+    /**
+     * 网页标签
+     * @param pageId
+     * @return
+     */
+    String getPageLabels(@Param("pageId") Integer pageId);
+
+    /**
+     * 保存行为记录
+     *
+     * @param behaviorInfo
+     */
+    void insertBehaviorInfo(CmBehaviorInfoPo behaviorInfo);
 }

+ 63 - 0
src/main/java/com/caimei/www/pojo/link/CmBehaviorInfoPo.java

@@ -0,0 +1,63 @@
+package com.caimei.www.pojo.link;
+
+import lombok.Data;
+
+/**
+ * Description
+ *
+ * @author : hzg
+ * @date : 2024/1/19
+ */
+@Data
+public class CmBehaviorInfoPo {
+    private Integer id;
+    /**
+     * 操作对象 1 机构 2 协销 3 客服 4 系统
+     */
+    private Integer operateObject;
+    /**
+     * 机构Id
+     */
+    private Integer clubId;
+    /**
+     * 协销Id
+     */
+    private Integer spId;
+    /**
+     * 1:日常访问; 2:推送访问(站内信); 3: 推送访问(短信); 4: 推送访问(微信模板消息):
+     * 5: 下单; 6: 收藏商品; 7: 加购物车; 8: 内容库访问; 9: 咨询记录,10: 分配协销
+     */
+    private Integer type;
+    /**
+     * 页面类型
+     */
+    private String pageType;
+    /**
+     * 标签
+     */
+    private String label;
+    /**
+     * 页面路径
+     */
+    private String pagePath;
+    /**
+     * 商品Id
+     */
+    private String productId;
+    /**
+     * 子订单Id, 多个使用逗号隔开
+     */
+    private String shopOrderId;
+    /**
+     * 分配人
+     */
+    private String allocation;
+    /**
+     * 添加时间
+     */
+    private String addTime;
+    /**
+     * 删除标记 0未删除 1已删除
+     */
+    private Integer delFlag;
+}

+ 87 - 0
src/main/java/com/caimei/www/service/link/impl/ShortLinkServiceImpl.java

@@ -1,11 +1,14 @@
 package com.caimei.www.service.link.impl;
 
 import com.caimei.www.mapper.ShortLinkDao;
+import com.caimei.www.pojo.link.CmBehaviorInfoPo;
 import com.caimei.www.pojo.link.ShortLink;
 import com.caimei.www.service.link.ShortLinkService;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
+import java.util.regex.Pattern;
 
 /**
  * Description
@@ -18,6 +21,9 @@ public class ShortLinkServiceImpl implements ShortLinkService {
     @Resource
     private ShortLinkDao shortLinkDao;
 
+    @Value("${caimei.wwwDomain}")
+    private String wwwDomain;
+
     @Override
     public String linkJump(String link, String ip) {
         ShortLink shortLink = shortLinkDao.findByShortLink(link);
@@ -27,6 +33,87 @@ public class ShortLinkServiceImpl implements ShortLinkService {
         }
         //修改点击数量
         shortLinkDao.updateOnClick(shortLink.getMarkId());
+        // 行为记录
+        try {
+            // 记录
+            CmBehaviorInfoPo behaviorInfo = shortLinkDao.getClubSpId(link);
+            link = wwwDomain + link;
+            setBehaviorInfo(behaviorInfo, link);
+            behaviorInfo.setOperateObject(1);
+            behaviorInfo.setType(2);
+            shortLinkDao.insertBehaviorInfo(behaviorInfo);
+
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
         return shortLink.getJumpLink();
     }
+
+    private void setBehaviorInfo(CmBehaviorInfoPo behaviorInfo, String link) {
+        Pattern compile = Pattern.compile("^[0-9]+$");
+        behaviorInfo.setPagePath(link);
+        String labels = "";
+        Integer id = 0;
+        // 文章详情
+        // https://www.caimei365.com/info/detail-7855-1.html
+        if (link.contains("info") && link.contains("detail")) {
+            behaviorInfo.setPageType("文章详情");
+            String[] split = link.split("-");
+            for (String s : split) {
+                if (compile.matcher(s).matches()) {
+                    id = Integer.parseInt(s);
+                }
+            }
+            // 获取文章标签
+            labels = shortLinkDao.getInfoLabels(id);
+        }
+        // 商品详情
+        id = 0;
+        if (link.contains("product")) {
+            behaviorInfo.setPageType("商品详情");
+            String[] split = link.split("-");
+            // https://www.caimei365.com/product-7729.html
+            if (split.length <= 2) {
+                for (String s : split) {
+                    String str = s.substring(0, s.lastIndexOf(".html"));
+                    if (compile.matcher(str).matches()) {
+                        id = Integer.parseInt(str);
+                    }
+                }
+            } else {
+                // https://www.caimei365.com/product-7729-1.html
+                for (String s : split) {
+                    if (compile.matcher(s).matches()) {
+                        id = Integer.parseInt(s);
+                    }
+                }
+            }
+            // 获取商品标签
+            labels = shortLinkDao.getProductLabels(id);
+        }
+        // 网页
+        id = 0;
+        // https://www.caimei365.com/page-375.html
+        if (link.contains("topic") || link.contains("equipment") || link.contains("page") || link.contains("product/type") || link.contains("product/activity")
+                || link.contains("product/beauty") || link.contains("quickOperation/operation") || link.contains("cmpage/info")) {
+            behaviorInfo.setPageType("网页列表");
+            String[] split = link.split("-");
+            if (split.length <= 2) {
+                for (String s : split) {
+                    String str = s.substring(0, s.lastIndexOf(".html"));
+                    if (compile.matcher(str).matches()) {
+                        id = Integer.parseInt(str);
+                    }
+                }
+            } else {
+                for (String s : split) {
+                    if (compile.matcher(s).matches()) {
+                        id = Integer.parseInt(s);
+                    }
+                }
+            }
+            labels = shortLinkDao.getPageLabels(id);
+        }
+        behaviorInfo.setLabel(labels);
+    }
 }

+ 57 - 1
src/main/resources/mapper/ShortLinkMapper.xml

@@ -24,4 +24,60 @@
           </if>
         where shortLink = #{link}
     </update>
-</mapper>
+
+    <select id="getClubSpId" resultType="com.caimei.www.pojo.link.CmBehaviorInfoPo">
+        SELECT
+            c.spId,
+            c.clubId
+        FROM club c
+                 LEFT JOIN USER u ON u.userId = c.userId
+                 LEFT JOIN cm_short_link csl ON csl.userId = c.userId
+        WHERE csl.jumpLink LIKE concat('%', #{link}, '%')
+    </select>
+
+    <select id="getInfoLabels" resultType="java.lang.String">
+        SELECT IFNULL(relatedLabels, "") as labels FROM info WHERE id = #{infoId}
+    </select>
+
+    <select id="getProductLabels" resultType="java.lang.String">
+        SELECT IFNULL(relatedLabels, "") as labels FROM product WHERE productId = #{productId}
+    </select>
+
+    <select id="getPageLabels" resultType="java.lang.String">
+        SELECT IFNULL(contentLabel, "") as labels FROM cm_page WHERE id = #{pageId}
+    </select>
+
+    <insert id="insertBehaviorInfo">
+        insert into cm_behavior_info(
+        operateObject,
+        clubId,
+        <if test="spId != null">
+            spId,
+        </if>
+        type,
+        <if test="pageType != null and pageType != ''">
+            pageType,
+        </if>
+        <if test="allocation != null and allocation != ''">
+            allocation,
+        </if>
+        addTime,
+        delFlag)
+        values(
+        #{operateObject},
+        #{clubId},
+        <if test="spId != null">
+            #{spId},
+        </if>
+        #{type},
+        <if test="pageType != null and pageType != ''">
+            #{pagetType},
+        </if>
+        <if test="allocation != null and allocation != ''">
+            #{allocation},
+        </if>
+        now(),
+        0
+        )
+    </insert>
+</mapper>