瀏覽代碼

用户行为优化1.0.5

huangzhiguo 1 年之前
父節點
當前提交
cc33ebc1c9

+ 9 - 0
src/main/java/com/caimei365/user/controller/LoginApi.java

@@ -315,6 +315,15 @@ public class LoginApi {
 
     }
 
+    @ApiOperation(("机构站内消息点击统计"))
+    @GetMapping("/clubBehaviorInfo")
+    public ResponseJson clubBehaviorInfo(Integer userId, String link) {
+        if (null == userId) {
+            return ResponseJson.error(-1, "用户Id不能为空", null);
+        }
+        return loginService.clubBehaviorInfo(userId, link);
+    }
+
     @ApiOperation("供应商站内消息列表")
     @GetMapping("/auth/shopMessageList")
     public ResponseJson<PageInfo<MessageCenter>> shopMessageList(Integer commonId,

+ 36 - 4
src/main/java/com/caimei365/user/mapper/ClubMapper.java

@@ -2,10 +2,7 @@ package com.caimei365.user.mapper;
 
 import com.caimei365.user.model.dto.ClubUpdateDto;
 import com.caimei365.user.model.dto.CmPortraitDto;
-import com.caimei365.user.model.po.ClubRemarksPo;
-import com.caimei365.user.model.po.NewOrderPo;
-import com.caimei365.user.model.po.OperationalLogsPo;
-import com.caimei365.user.model.po.UserPo;
+import com.caimei365.user.model.po.*;
 import com.caimei365.user.model.vo.*;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
@@ -407,4 +404,39 @@ public interface ClubMapper {
     Integer getSpIdRAND();
 
     Integer getSpUserId(@Param("spId") Integer spId);
+
+    /**
+     * 机构信息
+     * @param userId
+     * @return
+     */
+    CmBehaviorInfoPo getClubSpId(@Param("userId") Integer userId);
+
+    /**
+     * 文章标签
+     * @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/caimei365/user/model/po/CmBehaviorInfoPo.java

@@ -0,0 +1,63 @@
+package com.caimei365.user.model.po;
+
+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;
+}

+ 8 - 0
src/main/java/com/caimei365/user/service/LoginService.java

@@ -89,6 +89,14 @@ public interface LoginService {
     ResponseJson<PageInfo<MessageCenter>> SpMessageList(Integer commonId,Integer messageType,Integer source, int pageNum, int pageSize);
     ResponseJson<PageInfo<MessageCenter>> ClubMessageList(Integer commonId,Integer messageType,Integer source, int pageNum, int pageSize);
 
+    /**
+     * 推送访问(站内信) 记录
+     * @param userId
+     * @param link
+     * @return
+     */
+    ResponseJson clubBehaviorInfo(Integer userId, String link);
+
     ResponseJson<PageInfo<MessageCenter>> shopMessageList(Integer commonId,Integer messageType,Integer source, int pageNum, int pageSize);
 
     ResponseJson<PageInfo<MessageCenter>> messageList(Integer commonId,Integer messageType,Integer userType, int pageNum, int pageSize);

+ 12 - 0
src/main/java/com/caimei365/user/service/impl/ClubServiceImpl.java

@@ -1310,6 +1310,18 @@ public class ClubServiceImpl implements ClubService {
         if (StringUtils.isNotBlank(linkMan)) {
             clubMapper.inProvider(spId, clubId, linkMan, 3);
         }
+        // 行为记录
+        try {
+            CmBehaviorInfoPo behaviorInfo = new CmBehaviorInfoPo();
+            behaviorInfo.setOperateObject(2);
+            behaviorInfo.setClubId(clubId);
+            behaviorInfo.setSpId(spId);
+            behaviorInfo.setAllocation("协销管理员");
+            behaviorInfo.setType(10);
+            clubMapper.insertBehaviorInfo(behaviorInfo);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
         return ResponseJson.success();
     }
 

+ 99 - 0
src/main/java/com/caimei365/user/service/impl/LoginServiceImpl.java

@@ -8,6 +8,7 @@ import com.caimei365.user.components.WeChatService;
 import com.caimei365.user.mapper.*;
 import com.caimei365.user.model.ResponseJson;
 import com.caimei365.user.model.dto.*;
+import com.caimei365.user.model.po.CmBehaviorInfoPo;
 import com.caimei365.user.model.po.OperationPo;
 import com.caimei365.user.model.po.SuperVipPo;
 import com.caimei365.user.model.vo.MessageCenter;
@@ -31,6 +32,7 @@ import javax.annotation.Resource;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.util.*;
+import java.util.regex.Pattern;
 
 /**
  * Description
@@ -64,6 +66,8 @@ public class LoginServiceImpl implements LoginService {
     private MessageCenterMapper messageCenterMapper;
     @Resource
     private RemoteCallService remoteCallService;
+    @Resource
+    private ClubMapper clubMapper;
 
 
     /**
@@ -708,6 +712,33 @@ public class LoginServiceImpl implements LoginService {
         return ResponseJson.success(pageData);
     }
 
+    /**
+     * 推送访问(站内信) 记录
+     *
+     * @param userId
+     * @param link
+     * @return
+     */
+    @Override
+    public ResponseJson clubBehaviorInfo(Integer userId, String link) {
+        // 行为记录
+        try {
+            if (null == userId) {
+                return ResponseJson.error(-1, "用户数据异常", null);
+            } else {
+                // 记录
+                CmBehaviorInfoPo behaviorInfo = clubMapper.getClubSpId(userId);
+                setBehaviorInfo(behaviorInfo, link);
+                behaviorInfo.setOperateObject(1);
+                behaviorInfo.setType(2);
+                clubMapper.insertBehaviorInfo(behaviorInfo);
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return ResponseJson.success();
+    }
+
     @Override
     public ResponseJson<PageInfo<MessageCenter>> shopMessageList(Integer commonId, Integer messageType, Integer source, int pageNum, int pageSize) {
         PageHelper.startPage(pageNum, pageSize);
@@ -1695,4 +1726,72 @@ public class LoginServiceImpl implements LoginService {
         return map;
     }
 
+    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 = clubMapper.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 = clubMapper.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 = clubMapper.getPageLabels(id);
+        }
+        behaviorInfo.setLabel(labels);
+    }
+
 }

+ 14 - 0
src/main/java/com/caimei365/user/service/impl/RegisterServiceImpl.java

@@ -408,6 +408,20 @@ public class RegisterServiceImpl implements RegisterService {
         beansHistory.setPushStatus(0);
         beansHistory.setAddTime(date);
         registerMapper.insertBeansHistory(beansHistory);
+        // 行为记录
+        try {
+            if (spId != 1342) {
+                CmBehaviorInfoPo behaviorInfo = new CmBehaviorInfoPo();
+                behaviorInfo.setOperateObject(4);
+                behaviorInfo.setClubId(club.getClubId());
+                behaviorInfo.setSpId(spId);
+                behaviorInfo.setAllocation("系统自动分配");
+                behaviorInfo.setType(10);
+                clubMapper.insertBehaviorInfo(behaviorInfo);
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
         return ResponseJson.success("机构注册成功", null);
     }
 

+ 51 - 1
src/main/resources/mapper/ClubMapper.xml

@@ -977,7 +977,7 @@
         WHERE s.serviceProviderID = #{serviceProviderId}
     </select>
 
-    <select id="getCmRemarksList" resultType="java.util.Map">
+    <select id="getCmRemarksList" resultType="java.lang.String">
         SELECT keyword as label
         FROM cm_user_search_frequency
         WHERE keyword like concat('%', #{keyword}, '%')
@@ -1324,4 +1324,54 @@
         insert into cm_provider_record (spId, clubId, operator, isOneself, createTime)
         values (#{spId}, #{clubId}, #{operator}, #{isOneself}, now())
     </insert>
+
+    <select id="getClubSpId" resultType="com.caimei365.user.model.po.CmBehaviorInfoPo">
+        select c.spId, c.clubId from club c left join user u on u.userId = c.userId where u.userId = #{userId}
+    </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>