zhijiezhao il y a 2 mois
Parent
commit
9a2a88cb72

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

@@ -1,9 +1,6 @@
 package com.caimei365.manager.controller.caimei.user;
 
-import cn.hutool.poi.excel.ExcelUtil;
 import com.alibaba.excel.EasyExcel;
-import com.alibaba.excel.ExcelWriter;
-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;
@@ -13,26 +10,20 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
 import javax.servlet.http.HttpServletResponse;
-import javax.swing.filechooser.FileSystemView;
-import java.io.File;
 import java.net.URLEncoder;
 import java.util.List;
 import java.util.Map;
 
-/**
- * Description
- *
- * @author : Charles
- * @date : 2023/3/15
- */
 @RestController
 @RequestMapping("/user/behavior")
 public class CmBehaviorRecordApi {
 
-    @Autowired private CmBehaviorRecordService recordService;
+    @Autowired
+    private CmBehaviorRecordService recordService;
 
     /**
      * 获取父标签
+     *
      * @param keyword
      * @return
      */
@@ -44,30 +35,31 @@ public class CmBehaviorRecordApi {
 
     /**
      * 获取页面类型
+     *
      * @param pageLabels
      * @return
      */
     @GetMapping("/getPageType")
     public ResponseJson<List<CmPageType>> getPageType(String pageLabels) {
-
         return recordService.getPageType(pageLabels);
     }
 
     /**
      * 用户行为记录列表数据
+     *
      * @param cmBehaviorRecord 参数
      * @return 返回
      */
     @GetMapping("/record/list")
     public ResponseJson<PaginationVo<CmBehaviorRecord>> list(CmBehaviorRecord cmBehaviorRecord,
                                                              @RequestParam(value = "pageNum", defaultValue = "1") int pageNum,
-                                                             @RequestParam(value = "pageSize",defaultValue = "20") int pageSize) {
-
+                                                             @RequestParam(value = "pageSize", defaultValue = "20") int pageSize) {
         return recordService.list(cmBehaviorRecord, pageNum, pageSize);
     }
 
     /**
      * 今日数据导出
+     *
      * @param cmBehaviorRecord
      * @param response
      * @return
@@ -77,7 +69,6 @@ public class CmBehaviorRecordApi {
         String name = "今日数据";
         try {
             List<CmBehaviorRecord> RecordList = recordService.exportExcel(cmBehaviorRecord);
-
             response.setContentType("application/vnd.ms-excel");
             response.setCharacterEncoding("utf-8");
             // 这里URLEncoder.encode可以防止中文乱码 当然和easyexcel没有关系
@@ -91,25 +82,40 @@ public class CmBehaviorRecordApi {
 
     /**
      * 查看详情
+     *
      * @param cmBehaviorRecord 参数
-     * @param pageNum 页码
-     * @param pageSize 页面数据数
+     * @param pageNum          页码
+     * @param pageSize         页面数据数
      * @return 返回
      */
     @GetMapping("/record/recordList")
-    public ResponseJson<Map<String, Object>> recordList (CmBehaviorRecord cmBehaviorRecord,
-                                                                        @RequestParam(value = "pageNum", defaultValue = "1") int pageNum,
-                                                                        @RequestParam(value = "pageSize",defaultValue = "20")int pageSize) {
+    public ResponseJson<Map<String, Object>> recordList(CmBehaviorRecord cmBehaviorRecord,
+                                                        @RequestParam(value = "pageNum", defaultValue = "1") int pageNum,
+                                                        @RequestParam(value = "pageSize", defaultValue = "20") int pageSize) {
         return recordService.recordList(cmBehaviorRecord, pageNum, pageSize);
     }
 
+    @GetMapping("/record/product/count")
+    public ResponseJson<PaginationVo<CmBehaviorRecord>> prodcutCount(Integer productId, String beginTime, String endTime,
+                                                                     @RequestParam(value = "pageNum", defaultValue = "1") int pageNum,
+                                                                     @RequestParam(value = "pageSize", defaultValue = "20") int pageSize) {
+        return recordService.prodcutCount(productId, beginTime, endTime, pageNum, pageSize);
+    }
+
+    @GetMapping("/record/count/detail")
+    public ResponseJson<PaginationVo<CmBehaviorRecord>> prodcutCountDetail(Integer productId,
+                                                                           @RequestParam(value = "pageNum", defaultValue = "1") int pageNum,
+                                                                           @RequestParam(value = "pageSize", defaultValue = "20") int pageSize) {
+        return recordService.prodcutCountDetail(productId, pageNum, pageSize);
+    }
+
     /**
      * 标签库数据
+     *
      * @return 返回
      */
     @GetMapping("/searchList")
-    public ResponseJson searchList () {
-
+    public ResponseJson searchList() {
         return recordService.searchList();
     }
 }

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

@@ -18,6 +18,7 @@ import java.util.List;
 public interface CmBehaviorRecordDao {
     /**
      * 获取父标签
+     *
      * @param keyword
      * @return
      */
@@ -25,6 +26,7 @@ public interface CmBehaviorRecordDao {
 
     /**
      * 页面标签
+     *
      * @param pageLabels
      * @return
      */
@@ -32,6 +34,7 @@ public interface CmBehaviorRecordDao {
 
     /**
      * 昨日数据
+     *
      * @param cmBehaviorRecord 参数
      * @return 返回
      */
@@ -39,6 +42,7 @@ public interface CmBehaviorRecordDao {
 
     /**
      * 今日数据
+     *
      * @param cmBehaviorRecord 参数
      * @return 返回
      */
@@ -46,11 +50,14 @@ public interface CmBehaviorRecordDao {
 
     /**
      * 访问来源
+     *
      * @return 返回
      */
     List<CmBehaviorRecord> selRegion(@Param("accessDate") String accessDate);
+
     /**
      * 查询单条详情
+     *
      * @param cmBehaviorRecord 参数
      * @return 返回
      */
@@ -58,13 +65,19 @@ public interface CmBehaviorRecordDao {
 
     /**
      * 标签库
+     *
      * @return 返回
      */
     List<ReturnEntity> searchList();
 
     /**
      * 供应商信息
+     *
      * @return
      */
     List<CmBehaviorRecord> behaviorShopNameList();
+
+    List<CmBehaviorRecord> getProductCountList(@Param("productId") Integer productId, @Param("beginTime") String beginTime, @Param("endTime") String endTime);
+
+    List<CmBehaviorRecord> getProductCountDetail(@Param("productId") Integer productId);
 }

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

@@ -281,4 +281,9 @@ public class CmBehaviorRecord {
      */
     @ExcelIgnore
     private String productArchiveId;
+    /**
+     * 浏览次数
+     */
+    @ExcelIgnore
+    private Integer productCount;
 }

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

@@ -58,4 +58,8 @@ public interface CmBehaviorRecordService {
      * @return 返回
      */
     ResponseJson searchList();
+
+    ResponseJson<PaginationVo<CmBehaviorRecord>> prodcutCount(Integer productId, String beginTime, String endTime, int pageNum, int pageSize);
+
+    ResponseJson<PaginationVo<CmBehaviorRecord>> prodcutCountDetail(Integer productId, int pageNum, int pageSize);
 }

+ 27 - 1
src/main/java/com/caimei365/manager/service/caimei/user/impl/CmBehaviorRecordServiceImpl.java

@@ -162,7 +162,7 @@ public class CmBehaviorRecordServiceImpl implements CmBehaviorRecordService {
     }
 
     /**
-     * 查看详情
+     * 查看详情 todo 跟list共用接口,要拆分
      * @param cmBehaviorRecord
      * @param pageNum
      * @param pageSize
@@ -271,6 +271,32 @@ public class CmBehaviorRecordServiceImpl implements CmBehaviorRecordService {
         return ResponseJson.success(cmBehaviorRecordDao.searchList());
     }
 
+    @Override
+    public ResponseJson<PaginationVo<CmBehaviorRecord>> prodcutCount(Integer productId, String beginTime, String endTime, int pageNum, int pageSize) {
+        PageHelper.startPage(pageNum, pageSize);
+        List<CmBehaviorRecord> records = cmBehaviorRecordDao.getProductCountList(productId,beginTime,endTime);
+        records.forEach(r->{
+            r.setProductImage(AppUtils.getImageURL("product", r.getProductImage(), 0, ""));
+            if (!r.getProductImage().contains("https")) {
+                r.setProductImage("https://admin.caimei365.com/" + r.getProductImage());
+            }
+        });
+        PaginationVo<CmBehaviorRecord> pageData = new PaginationVo<>(records);
+        return ResponseJson.success(pageData);
+    }
+
+    @Override
+    public ResponseJson<PaginationVo<CmBehaviorRecord>> prodcutCountDetail(Integer productId, int pageNum, int pageSize) {
+        PageHelper.startPage(pageNum, pageSize);
+        List<CmBehaviorRecord> records = cmBehaviorRecordDao.getProductCountDetail(productId);
+        for (CmBehaviorRecord record : records) {
+            String time = calculationTime(record.getAccessDuration());
+            record.setAccessDuration(time);
+        }
+        PaginationVo<CmBehaviorRecord> pageData = new PaginationVo<>(records);
+        return ResponseJson.success(pageData);
+    }
+
     /**
      * 时间计算
      * @param recordTime

+ 63 - 19
src/main/resources/mapper/CmBehaciorRecordDao.xml

@@ -15,8 +15,8 @@
 
     <select id="getkeyword" resultType="com.caimei365.manager.entity.caimei.ReturnEntity">
         select
-            id,
-            keyword as value
+        id,
+        keyword as value
         from cm_keyword_info
         where parentLabel = 1
         and delFlag = 1
@@ -27,8 +27,8 @@
 
     <select id="getPageType" resultType="com.caimei365.manager.entity.caimei.CmPageType">
         select
-            id,
-            pageType
+        id,
+        pageType
         from cm_page_type
         <where>
             <if test="pageLabels != null and pageLabels != ''">
@@ -76,7 +76,8 @@
                 AND cbri.IP = #{ip}
             </if>
             <if test="corporateName != null and corporateName != ''">
-                AND (cbri.corporateName like concat('%',#{corporateName},'%') OR cbri.consultName LIKE concat('%',#{corporateName},'%') or cbri.contacts like concat('%',#{corporateName},'%'))
+                AND (cbri.corporateName like concat('%',#{corporateName},'%') OR cbri.consultName LIKE
+                concat('%',#{corporateName},'%') or cbri.contacts like concat('%',#{corporateName},'%'))
             </if>
             <if test="companyType != null and companyType != ''">
                 AND cbri.companyType = #{companyType}
@@ -85,7 +86,8 @@
                 AND cbri.accessClient =#{accessClient}
             </if>
             <if test="contacts != null and contacts != ''">
-                AND (cbri.corporateName like concat('%',#{contacts},'%') or cbri.contacts like concat('%',#{contacts},'%'))
+                AND (cbri.corporateName like concat('%',#{contacts},'%') or cbri.contacts like
+                concat('%',#{contacts},'%'))
             </if>
             <if test="phoneNumber != null and phoneNumber != ''">
                 AND cbri.phoneNumber = #{phoneNumber}
@@ -101,10 +103,10 @@
             </if>
             <if test="relevanceShop != null and relevanceShop != ''">
                 AND (cbri.relevanceShop like concat('%',#{relevanceShop},'%')
-                    <if test="behaviorType == 2">
-                        or cbri.behaviorType = #{behaviorType}
-                    </if>
-                    )
+                <if test="behaviorType == 2">
+                    or cbri.behaviorType = #{behaviorType}
+                </if>
+                )
             </if>
             <if test="labels != null and labels.size > 0">
                 AND
@@ -115,7 +117,7 @@
             <if test="pageLabels != null and pageLabels != ''">
                 AND cbri.pageLabels like concat('%', #{pageLabels}, '%')
             </if>
-                <if test="pageTypes != null and pageTypes != ''">
+            <if test="pageTypes != null and pageTypes != ''">
                 AND cbri.pageTypes like concat('%', #{pageTypes}, '%')
             </if>
             <if test="startTime != null and startTime != '' and endTime != null and endTime != ''">
@@ -170,7 +172,8 @@
                 AND cbrt.IP = #{ip}
             </if>
             <if test="corporateName != null and corporateName != ''">
-                AND (cbrt.corporateName like concat('%',#{corporateName},'%') OR cbrt.consultName LIKE concat('%',#{corporateName},'%') or cbrt.contacts like concat('%',#{corporateName},'%'))
+                AND (cbrt.corporateName like concat('%',#{corporateName},'%') OR cbrt.consultName LIKE
+                concat('%',#{corporateName},'%') or cbrt.contacts like concat('%',#{corporateName},'%'))
             </if>
             <if test="companyType != null and companyType != ''">
                 AND cbrt.companyType = #{companyType}
@@ -179,7 +182,8 @@
                 AND cbrt.accessClient =#{accessClient}
             </if>
             <if test="contacts != null and contacts != ''">
-                AND (cbrt.corporateName like concat('%',#{contacts},'%') or cbrt.contacts like concat('%',#{contacts},'%'))
+                AND (cbrt.corporateName like concat('%',#{contacts},'%') or cbrt.contacts like
+                concat('%',#{contacts},'%'))
             </if>
             <if test="phoneNumber != null and phoneNumber != ''">
                 AND cbrt.phoneNumber = #{phoneNumber}
@@ -221,7 +225,9 @@
         ORDER BY cbrt.accessTime DESC
     </select>
     <select id="selRegion" resultType="com.caimei365.manager.entity.caimei.CmBehaviorRecord">
-        SELECT * FROM cm_behavior_record_ref where accessTime like concat('%',#{accessDate},'%')
+        SELECT *
+        FROM cm_behavior_record_ref
+        where accessTime like concat('%', #{accessDate}, '%')
     </select>
     <select id="recordList" resultType="com.caimei365.manager.entity.caimei.CmBehaviorRecord">
         SELECT
@@ -247,7 +253,7 @@
         LEFT JOIN product p ON b.productID = p.productID
         LEFT JOIN cm_page_type pt ON b.pageType = pt.id
         <where>
-            b.accessDate = #{accessDate}  AND b.IP != '106.55.202.118' AND b.delFlag = 0
+            b.accessDate = #{accessDate} AND b.IP != '106.55.202.118' AND b.delFlag = 0
             <if test="userId != null">
                 AND b.userID = #{userId} AND b.IP = #{ip}
             </if>
@@ -255,15 +261,53 @@
         ORDER BY accessTime DESC
     </select>
     <select id="searchList" resultType="com.caimei365.manager.entity.caimei.ReturnEntity">
-        SELECT cusf.id , cusf.keyword AS VALUE
+        SELECT cusf.id, cusf.keyword AS VALUE
         FROM cm_user_search_frequency cusf
-         LEFT JOIN cm_shop_label csl ON csl.keywordId = cusf.id
-         LEFT JOIN cm_shop_relevance csr ON csr.id = csl.relevanceId
+                 LEFT JOIN cm_shop_label csl ON csl.keywordId = cusf.id
+                 LEFT JOIN cm_shop_relevance csr ON csr.id = csl.relevanceId
         WHERE cusf.trueStatus = 1
           AND csl.delFlag = 0
           AND csr.delFlag = 0
     </select>
     <select id="behaviorShopNameList" resultType="com.caimei365.manager.entity.caimei.CmBehaviorRecord">
-        SELECT cbs.recordID, cbs.shopID, s.name FROM cm_behavior_shopId cbs LEFT JOIN shop s ON cbs.shopID = s.shopID
+        SELECT cbs.recordID, cbs.shopID, s.name
+        FROM cm_behavior_shopId cbs
+                 LEFT JOIN shop s ON cbs.shopID = s.shopID
+    </select>
+    <select id="getProductCountList" resultType="com.caimei365.manager.entity.caimei.CmBehaviorRecord">
+        SELECT cbr.productId,COUNT(cbr.productId) AS productCount,p.mainImage as productImage,p.name as productName
+        FROM cm_behavior_record_index cbr
+        LEFT JOIN product p ON cbr.productId = p.productId
+        WHERE cbr.productId > 0
+        <if test="productId != null">
+            AND cbr.productId = #{productId}
+        </if>
+        <if test="beginTime != null and beginTime != '' and endTime != null and endTime != ''">
+            AND cbr.accessDate between #{beginTime} and #{endTime}
+        </if>
+        GROUP BY cbr.productId
+        ORDER BY productCount DESC
+    </select>
+    <select id="getProductCountDetail" resultType="com.caimei365.manager.entity.caimei.CmBehaviorRecord">
+        SELECT cbr.ip,
+               IF(userId = 0, '', cbr.region) AS region,
+               cbr.userId,
+               cbr.contacts,
+               cbr.phoneNumber,
+               cbr.spName,
+               cbr.lastAccessTime,
+               cbr.accessDate,
+               cbr.corporateName,
+               (CASE
+                    WHEN cbr.accessClient = 1 THEN '小程序'
+                    ELSE '网站' END)            AS accessClient,
+               (CASE
+                    WHEN cbr.companyType = 1 THEN '游客'
+                    WHEN cbr.companyType = 2 THEN '机构'
+                    ELSE '供应商' END)           AS companyType,
+               SUM(cbr.accessDuration)        AS accessDuration
+        FROM cm_behavior_record_index cbr
+        WHERE cbr.productId = #{productId}
+        GROUP BY cbr.userId
     </select>
 </mapper>