Przeglądaj źródła

用户行为优化1.0.5

huangzhiguo 1 rok temu
rodzic
commit
e7d7d158f6

+ 21 - 0
src/main/java/com/caimei365/commodity/mapper/UserLikeMapper.java

@@ -1,5 +1,7 @@
 package com.caimei365.commodity.mapper;
 package com.caimei365.commodity.mapper;
 
 
+import com.caimei365.commodity.model.po.CmBehaviorInfoPo;
+import com.caimei365.commodity.model.vo.ProductDetailVo;
 import com.caimei365.commodity.model.vo.ProductItemVo;
 import com.caimei365.commodity.model.vo.ProductItemVo;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
 import org.apache.ibatis.annotations.Param;
@@ -58,5 +60,24 @@ public interface UserLikeMapper {
      */
      */
     List<ProductItemVo> findLikeList(@Param("organizeId") Integer organizeId, @Param("userId") Integer userId);
     List<ProductItemVo> findLikeList(@Param("organizeId") Integer organizeId, @Param("userId") Integer userId);
 
 
+    /**
+     * 商品信息
+     * @param productId
+     * @return
+     */
+    ProductDetailVo getProductInfo(@Param("productId") Integer productId);
+
+    /**
+     * 机构协销Id
+     * @param userId
+     * @return
+     */
+    CmBehaviorInfoPo getClubSpId(@Param("userId") Integer userId);
+
+    /**
+     * 保存行为记录
+     * @param behaviorInfo
+     */
+    void insertBehaviorInfo(CmBehaviorInfoPo behaviorInfo);
 
 
 }
 }

+ 63 - 0
src/main/java/com/caimei365/commodity/model/po/CmBehaviorInfoPo.java

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

+ 19 - 0
src/main/java/com/caimei365/commodity/service/impl/UserLikeServiceImpl.java

@@ -4,11 +4,14 @@ import com.aliyun.opensearch.sdk.dependencies.com.google.common.collect.Lists;
 import com.caimei365.commodity.components.PriceUtilService;
 import com.caimei365.commodity.components.PriceUtilService;
 import com.caimei365.commodity.mapper.UserLikeMapper;
 import com.caimei365.commodity.mapper.UserLikeMapper;
 import com.caimei365.commodity.model.ResponseJson;
 import com.caimei365.commodity.model.ResponseJson;
+import com.caimei365.commodity.model.po.CmBehaviorInfoPo;
 import com.caimei365.commodity.model.vo.PaginationVo;
 import com.caimei365.commodity.model.vo.PaginationVo;
+import com.caimei365.commodity.model.vo.ProductDetailVo;
 import com.caimei365.commodity.model.vo.ProductItemVo;
 import com.caimei365.commodity.model.vo.ProductItemVo;
 import com.caimei365.commodity.service.PageService;
 import com.caimei365.commodity.service.PageService;
 import com.caimei365.commodity.service.UserLikeService;
 import com.caimei365.commodity.service.UserLikeService;
 import com.github.pagehelper.PageHelper;
 import com.github.pagehelper.PageHelper;
+import org.apache.commons.lang.StringUtils;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
 
 
 import javax.annotation.Resource;
 import javax.annotation.Resource;
@@ -44,6 +47,22 @@ public class UserLikeServiceImpl implements UserLikeService {
         }
         }
         if (flag.equals(0)) {
         if (flag.equals(0)) {
             likeMapper.like(userId, productId, 1);
             likeMapper.like(userId, productId, 1);
+            // 行为记录
+            try {
+                // 获取商品信息
+                ProductDetailVo productInfo = likeMapper.getProductInfo(productId);
+                if (null != productInfo) {
+                    // 机构协销Id
+                    CmBehaviorInfoPo behaviorInfo = likeMapper.getClubSpId(userId);
+                    behaviorInfo.setOperateObject(1);
+                    behaviorInfo.setType(6);
+                    behaviorInfo.setProductId(null != productInfo.getProductId() ? productInfo.getProductId().toString() : "");
+                    behaviorInfo.setLabel(StringUtils.isNotBlank(productInfo.getRelatedLabels()) ? productInfo.getRelatedLabels() : "");
+                    likeMapper.insertBehaviorInfo(behaviorInfo);
+                }
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
             return ResponseJson.success("收藏成功");
             return ResponseJson.success("收藏成功");
         }
         }
         return ResponseJson.error("收藏失败");
         return ResponseJson.error("收藏失败");

+ 38 - 0
src/main/resources/mapper/UserLikeMapper.xml

@@ -68,4 +68,42 @@
           AND cpu.userID = #{userId}
           AND cpu.userID = #{userId}
         ORDER BY cpu.likeTime DESC
         ORDER BY cpu.likeTime DESC
     </select>
     </select>
+
+    <select id="getProductInfo" resultType="com.caimei365.commodity.model.vo.ProductDetailVo">
+        select productId, name, relatedLabels from product where productId =  #{productId}
+    </select>
+
+    <select id="getClubSpId" resultType="com.caimei365.commodity.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>
+
+    <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>
+        label,
+        addTime,
+        delFlag)
+        values(
+        #{operateObject},
+        #{clubId},
+        <if test="spId != null">
+            #{spId},
+        </if>
+        #{type},
+        <if test="pageType != null and pageType != ''">
+            #{pagetType},
+        </if>
+        #{label},
+        now(),
+        0
+        )
+    </insert>
 </mapper>
 </mapper>