瀏覽代碼

Merge remote-tracking branch 'origin/developerD' into developerA

zhijiezhao 2 年之前
父節點
當前提交
cb9f7face0

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

@@ -61,11 +61,11 @@ public class BaseApi {
     /**
      * 临时接口
      */
-    /*@GetMapping("/record/update")
-    public void svipCoupon(Integer startId, Integer endId) throws IOException {
+    @GetMapping("/record/update")
+    public void svipCoupon() throws IOException {
 
-        cmBehaviorRecordService.setIpAddress(startId, endId);
-    }*/
+        cmBehaviorRecordService.insertTodayData();
+    }
 
     /**
      * 数据ip地址

+ 46 - 1
src/main/java/com/caimei365/tools/mapper/CmBehaviorRecordMapper.java

@@ -83,6 +83,51 @@ public interface CmBehaviorRecordMapper {
 
     void updateBehavior(CmBehaviorRecordPo cmBehaviorRecordPo);
 
-    void selYesterdayList( @Param("accessDate") String accessDate);
+    List<CmBehaviorRecordPo> selYesterdayList(@Param("accessDate") String accessDate);
+
+    /**
+     * 插入昨日数据
+     * @param cmBehaviorRecordPo
+     */
+    void insertYesterdayList(CmBehaviorRecordPo cmBehaviorRecordPo);
+
+    /**
+     * 查询今日所有用户行为数据
+     * @param accessDate
+     * @return
+     */
+    List<CmBehaviorRecordPo> selTodayData(@Param("accessDate") String accessDate);
+
+    /**
+     * 关联供应商数据
+     * @param accessDate
+     * @return
+     */
+    List<CmBehaviorRecordPo> selDataList(@Param("accessDate") String accessDate);
+
+    /**
+     * 将今日数据存储到今日数据表
+     * @param cmBehaviorRecordPo 参数
+     */
+    void inBehaviorToday(CmBehaviorRecordPo cmBehaviorRecordPo);
+
+    /**
+     * 清除今日用户数据数据
+     */
+    void delTodayData();
+
+    /**
+     * 查询供应商id
+     * @param strList 页面标签
+     * @return 返回
+     */
+    List<Integer> shopIds(@Param("strList") List<String> strList);
+
+    /**
+     * 添加惯量供应商
+     * @param recordId 用户行为记录id
+     * @param shopId 供应商id
+     */
+    void insertShopId(@Param("recordId") Integer recordId, @Param("shopId") Integer shopId);
 }
 

+ 57 - 0
src/main/java/com/caimei365/tools/model/po/CmBehaviorRecordPo.java

@@ -22,6 +22,14 @@ public class CmBehaviorRecordPo {
      * 用户id、0为游客
      */
     private String userId;
+    /**
+     * 机构Id
+     */
+    private String clubId;
+    /**
+     * 供应商Id
+     */
+    private Integer shopId;
     /**
      * 页面路径
      */
@@ -102,4 +110,53 @@ public class CmBehaviorRecordPo {
      * 统计数
      */
     private Integer count;
+
+    /**
+     * 最后访问时间
+     */
+    private String lastAccessTime;
+    /**
+     * 公司类型
+     */
+    private String companyType;
+    /**
+     * 公司名称
+     */
+    private String corporateName;
+    /**
+     * 联系人
+     */
+    private String contacts;
+    /**
+     * 手机号码
+     */
+    private String phoneNumber;
+    /**
+     * 所属协销
+     */
+    private String spName;
+    /**
+     * 访问页面数量
+     */
+    private String number;
+    /**
+     * 咨询人姓名
+     */
+    private String consultName;
+    /**
+     * 咨询手机号码
+     */
+    private String consultMobile;
+    /**
+     * 注册时间
+     */
+    private String addTime;
+    /**
+     * 关联供应商
+     */
+    private String relevanceShop;
+    /**
+     * 标签
+     */
+    private String label;
 }

+ 2 - 0
src/main/java/com/caimei365/tools/service/CmBehaviorRecordService.java

@@ -21,4 +21,6 @@ public interface CmBehaviorRecordService {
     void updateBehaviorUser();
 
     void insertBehaviorUser();
+
+    void insertTodayData();
 }

+ 110 - 5
src/main/java/com/caimei365/tools/service/impl/CmBehaviorRecordServiceImpl.java

@@ -19,10 +19,7 @@ import java.net.HttpURLConnection;
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.text.SimpleDateFormat;
-import java.util.Calendar;
-import java.util.Date;
-import java.util.List;
-import java.util.TimeZone;
+import java.util.*;
 
 /**
  * Description
@@ -131,6 +128,22 @@ public class CmBehaviorRecordServiceImpl implements CmBehaviorRecordService {
                             }
                         }
                     }
+                    // 供应商Id
+                    if (str.startsWith("shopId") && str.contains("=")) {
+                        String[] split1 = str.split("=");
+                        cmBehaviorRecordPo.setShopId(null);
+                        if (split1.length > 1) {
+                            String value = split1[1];
+                            String trim = value.trim();
+                            if (StringUtils.isNotBlank(trim)) {
+                                if (!trim.equals("null")) {
+                                    cmBehaviorRecordPo.setShopId(Integer.parseInt(trim));
+                                } else {
+                                    cmBehaviorRecordPo.setShopId(null);
+                                }
+                            }
+                        }
+                    }
                     // 商品ID
                     if (str.startsWith("productId") && str.contains("=")) {
                         String[] split1 = str.split("=");
@@ -207,6 +220,33 @@ public class CmBehaviorRecordServiceImpl implements CmBehaviorRecordService {
             }
             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);
+                            }
+                        } else {
+                            strList.add(cmBehaviorRecordPo.getPageLabel());
+                        }
+                        // 供应商id
+                        List<Integer> shopIds = recordMapper.shopIds(strList);
+                        if (shopIds.size() > 0) {
+                            for (Integer shopId : shopIds) {
+                                recordMapper.insertShopId(recordId, shopId);
+                            }
+                        }
+                    }
+                } else {
+                    recordMapper.insertShopId(recordId, cmBehaviorRecordPo.getShopId());
+                }
+            }
         }
     }
 
@@ -315,10 +355,75 @@ public class CmBehaviorRecordServiceImpl implements CmBehaviorRecordService {
         String format = dateFormat.format(time);
 
         // 获取昨天数据
-        recordMapper.selYesterdayList(format);
+        List<CmBehaviorRecordPo> yesterdayList = recordMapper.selYesterdayList(format);
+        // 详细数据
+        List<CmBehaviorRecordPo> selDataList = recordMapper.selDataList(format);
+        for (CmBehaviorRecordPo data : yesterdayList) {
+            ArrayList<String> item = new ArrayList();
+            ArrayList<String> shopNames = new ArrayList();
+            int num = 0;
+            for (CmBehaviorRecordPo recordPo : selDataList) {
+                if (recordPo.getIP().equals(data.getIP()) && recordPo.getUserId().equals(data.getUserId())) {
+                    if (num < 5) {
+                        if (!item.contains(recordPo.getPageLabel())) {
+                            item.add(recordPo.getPageLabel());
+                            num++;
+                        }
+                    }
+                    if (StringUtils.isNotBlank(recordPo.getRelevanceShop()) && !shopNames.contains(recordPo.getRelevanceShop())) {
+                        shopNames.add(recordPo.getRelevanceShop());
+                    }
+                }
+            }
+            data.setLabel(StringUtils.strip(item.toString(), "[]"));
+            data.setRelevanceShop(StringUtils.strip(shopNames.toString(), "[]"));
+            // 数据插入
+            recordMapper.insertYesterdayList(data);
+        }
         log.info("====昨日用户行为列表数据已生成====");
     }
 
+    /**
+     * 生成用户行为今日列表数据 数据一小时覆盖
+     */
+    @Override
+    public void insertTodayData() {
+        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
+        String format = dateFormat.format(new Date());
+
+
+        // 今日用户行为数据
+        List<CmBehaviorRecordPo> todayData = recordMapper.selTodayData(format);
+        // 清除今日用户行为记录
+        recordMapper.delTodayData();
+        // 生成今日用户行为记录
+        int id = 1;
+        List<CmBehaviorRecordPo> selDataList = recordMapper.selDataList(format);
+        for (CmBehaviorRecordPo data: todayData ){
+            ArrayList<String> item = new ArrayList();
+            ArrayList<String> shopNames = new ArrayList();
+            int num = 0;
+            data.setRecordID(id);
+            id ++;
+            for (CmBehaviorRecordPo recordPo : selDataList) {
+                if (recordPo.getIP().equals(data.getIP()) && recordPo.getUserId().equals(data.getUserId())) {
+                    if (num < 5) {
+                        if (!item.contains(recordPo.getPageLabel())) {
+                            item.add(recordPo.getPageLabel());
+                            num++;
+                        }
+                    }
+                    if (StringUtils.isNotBlank(recordPo.getRelevanceShop()) && !shopNames.contains(recordPo.getRelevanceShop())) {
+                        shopNames.add(recordPo.getRelevanceShop());
+                    }
+                }
+            }
+            data.setLabel(StringUtils.strip(item.toString(), "[]"));
+            data.setRelevanceShop(StringUtils.strip(shopNames.toString(), "[]"));
+            recordMapper.inBehaviorToday(data);
+        }
+    }
+
 
     // 获取IP对应地址 ---- 太平洋
     public static String recordIp(String ip) throws IOException {

+ 6 - 0
src/main/java/com/caimei365/tools/task/CmOrganValueSystemTask.java

@@ -63,4 +63,10 @@ public class CmOrganValueSystemTask {
     public void svipCoupon() {
         cmVipCouponService.openCoupon();
     }
+
+    /**
+     * 生成今日用户行为数据
+     */
+    @Scheduled(cron = "0 0 * * * ?")
+    public void insertBehaviorToday() { cmBehaviorRecordService.insertTodayData();}
 }

+ 218 - 49
src/main/resources/mapper/CmBehaviorRecordMapper.xml

@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="UTF-8" ?>
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.caimei365.tools.mapper.CmBehaviorRecordMapper">
-    <insert id="insertRecord">
+    <insert id="insertRecord" parameterType="com.caimei365.tools.model.po.CmBehaviorRecordPo" useGeneratedKeys="true" keyProperty="recordID">
         INSERT INTO cm_behavior_record (IP, userID, pagePath, pageType, pageLabel, behaviorType, productID, accessTime, accessDuration, accessDate,referer,accessSource,accessClient,isReckon,region,userAgent,delFlag)
         VALUES(#{IP},#{userId},#{pagePath},#{pageType},#{pageLabel},#{behaviorType},#{productId},#{accessTime},#{accessDuration},#{accessDate},#{referer},#{accessSource},#{accessClient},#{isReckon},#{region},#{userAgent},#{delFlag})
     </insert>
@@ -186,58 +186,227 @@
         userID = #{userId}
         WHERE recordID = #{recordID}
     </update>
-    <select id="selYesterdayList">
-        INSERT INTO cm_behavior_record_index (IP, userID, clubID, lastAccessTime, companyType, corporateName,
-        contacts, phoneNumber, spName, number, consultName, consultMobile, behaviorType, productID, accessTime, accessDuration, accessDate, accessClient, region, delFlag)
+    <select id="selYesterdayList" resultType="com.caimei365.tools.model.po.CmBehaviorRecordPo">
         SELECT
-        b.IP,
-        b.userID,
-        c.clubID,
-        MAX(b.accessTime) AS lastAccessTime,
-        (
-        CASE WHEN u.userIdentity = 2 THEN 2
-        WHEN u.userIdentity = 4 THEN 2
-        WHEN u.userIdentity = 3 THEN 3
-        WHEN b.userID = 0 THEN 1
-        END)AS companyType,
-        (
-        CASE WHEN b.userID = 0 THEN ''
-        WHEN u.userIdentity = 2 THEN c.name
-        when u.userIdentity = 3 then s.name
-        WHEN u.userIdentity = 4 THEN IF(c.name != u.userName,c.name,'')
-        END)AS corporateName,
-        (
-        CASE WHEN b.userID = 0 THEN ''
-         WHEN u.userIdentity = 2 THEN c.linkMan
-         WHEN u.userIdentity = 3 THEN s.linkMan
-         WHEN u.userIdentity = 4 THEN c.linkMan
-        END)AS contacts,
-        (CASE WHEN u.userIdentity = 2 THEN c.contractMobile
-        WHEN u.userIdentity = 4 THEN c.contractMobile
-        WHEN u.userIdentity = 3 THEN s.contractMobile
-        END)AS phoneNumber,
-        (SELECT CASE STATUS WHEN 91 THEN '采美默认协销经理(官方账号)' ELSE linkMan END FROM serviceprovider WHERE serviceProviderID = c.spID) AS spName,
-        COUNT(b.IP) AS numbers,
-        (SELECT consultName
-        FROM cm_roos_information
-        WHERE IP = b.IP AND createTime LIKE CONCAT('%',b.accessDate,'%') AND (consultName IS NOT NULL OR consultName = '') LIMIT 1) AS consultName,
-        (SELECT consultMobile
-        FROM cm_roos_information
-        WHERE IP = b.IP AND createTime LIKE CONCAT('%',b.accessDate,'%') AND (consultName IS NOT NULL OR consultName = '') LIMIT 1) AS consultMobile,
-        b.behaviorType,
-        b.productID,
-        b.accessTime,
-        SUM(b.accessDuration) AS accessDuration,
-        b.accessDate,
-        b.accessClient,
-        b.region AS region,
-        b.delFlag
+            b.IP,
+            b.userID,
+            c.clubID,
+            MAX(b.accessTime) AS lastAccessTime,
+            (
+                CASE WHEN u.userIdentity = 2 THEN 2
+                     WHEN u.userIdentity = 4 THEN 2
+                     WHEN u.userIdentity = 3 THEN 3
+                     WHEN b.userID = 0 THEN 1
+                    END)AS companyType,
+            (
+                CASE WHEN b.userID = 0 THEN ''
+                     WHEN u.userIdentity = 2 THEN c.name
+                     when u.userIdentity = 3 then s.name
+                     WHEN u.userIdentity = 4 THEN IF(c.name != u.userName,c.name,'')
+                    END)AS corporateName,
+            (
+                CASE WHEN b.userID = 0 THEN ''
+                     WHEN u.userIdentity = 2 THEN c.linkMan
+                     WHEN u.userIdentity = 3 THEN s.linkMan
+                     WHEN u.userIdentity = 4 THEN c.linkMan
+                    END)AS contacts,
+            (CASE WHEN u.userIdentity = 2 THEN c.contractMobile
+                  WHEN u.userIdentity = 4 THEN c.contractMobile
+                  WHEN u.userIdentity = 3 THEN s.contractMobile
+                END)AS phoneNumber,
+            (SELECT CASE STATUS WHEN 91 THEN '采美默认协销经理(官方账号)' ELSE linkMan END FROM serviceprovider WHERE serviceProviderID = c.spID) AS spName,
+            COUNT(b.IP) AS numbers,
+            (SELECT consultName
+             FROM cm_roos_information
+             WHERE IP = b.IP AND createTime LIKE CONCAT('%',b.accessDate,'%') AND (consultName IS NOT NULL OR consultName = '') LIMIT 1) AS consultName,
+            (SELECT consultMobile
+             FROM cm_roos_information
+             WHERE IP = b.IP AND createTime LIKE CONCAT('%',b.accessDate,'%') AND (consultName IS NOT NULL OR consultName = '') LIMIT 1) AS consultMobile,
+            b.behaviorType,
+            b.productID,
+            b.accessTime,
+            SUM(b.accessDuration) AS accessDuration,
+            b.accessDate,
+            b.accessClient,
+            b.region AS region,
+            u.registerTime AS addTime,
+            b.delFlag
         FROM cm_behavior_record b
-        LEFT JOIN USER u ON b.userID = u.userID
-        LEFT JOIN club c ON b.userID = c.userID
-        LEFT JOIN shop s ON b.userID = s.userID
+                 LEFT JOIN USER u ON b.userID = u.userID
+                 LEFT JOIN club c ON b.userID = c.userID
+                 LEFT JOIN shop s ON b.userID = s.userID
         WHERE  b.IP != '106.55.202.118' AND b.delFlag = 0  AND b.accessDate = #{accessDate}
         GROUP BY b.IP, b.accessDate,b.userID, b.behaviorType ORDER BY b.accessTime DESC
     </select>
+    <select id="insertYesterdayList">
+        INSERT INTO cm_behavior_record_index (
+              IP,
+              userID,
+              clubID,
+              lastAccessTime,
+              companyType,
+              corporateName,
+              contacts,
+              phoneNumber,
+              spName,
+              number,
+              consultName,
+              consultMobile,
+              accessTime,
+              accessDuration,
+              accessDate,
+              accessClient,
+              region,
+              relevanceShop,
+              label,
+              addTime,
+              delFlag
+            ) values (
+                   #{IP},
+                   #{userId},
+                   #{clubId},
+                   #{lastAccessTime},
+                   #{companyType},
+                   #{corporateName},
+                   #{contacts},
+                   #{phoneNumber},
+                   #{spName},
+                   #{number},
+                   #{consultName},
+                   #{consultMobile},
+                   #{accessTime},
+                   #{accessDuration},
+                   #{accessDate},
+                   #{accessClient},
+                   #{region},
+                   #{relevanceShop},
+                   #{label},
+                   #{addTime},
+                   '0'
+               )
+    </select>
+    <select id="selTodayData" resultType="com.caimei365.tools.model.po.CmBehaviorRecordPo">
+        SELECT
+            b.IP,
+            b.userID,
+            c.clubID,
+            MAX(b.accessTime) AS lastAccessTime,
+            (
+            CASE WHEN u.userIdentity = 2 THEN 2
+                 WHEN u.userIdentity = 4 THEN 2
+                 WHEN u.userIdentity = 3 THEN 3
+                 WHEN b.userID = 0 THEN 1
+                END)AS companyType,
+            (
+            CASE WHEN b.userID = 0 THEN ''
+                 WHEN u.userIdentity = 2 THEN c.name
+                 WHEN u.userIdentity = 3 THEN s.name
+                 WHEN u.userIdentity = 4 THEN c.name -- IF(c.name != u.userName,c.name,'')
+                END)AS corporateName,
+            (
+            CASE WHEN b.userID = 0 THEN ''
+                 WHEN u.userIdentity = 2 THEN c.linkMan
+                 WHEN u.userIdentity = 3 THEN s.linkMan
+                 WHEN u.userIdentity = 4 THEN c.linkMan
+                END)AS contacts,
+            (
+            CASE WHEN u.userIdentity = 2 THEN c.contractMobile
+                  WHEN u.userIdentity = 4 THEN c.contractMobile
+                  WHEN u.userIdentity = 3 THEN s.contractMobile
+                END)AS phoneNumber,
+            (SELECT CASE STATUS WHEN 91 THEN '采美默认协销经理(官方账号)' ELSE linkMan END FROM serviceprovider WHERE serviceProviderID = c.spID) AS spName,
+            COUNT(b.IP) AS number,
+            (SELECT consultName
+             FROM cm_roos_information
+             WHERE IP = b.IP AND createTime LIKE CONCAT('%',b.accessDate,'%') AND (consultName IS NOT NULL OR consultName = '') LIMIT 1) AS consultName,
+            (SELECT consultMobile
+             FROM cm_roos_information
+             WHERE IP = b.IP AND createTime LIKE CONCAT('%',b.accessDate,'%') AND (consultName IS NOT NULL OR consultName = '') LIMIT 1) AS consultMobile,
+            b.accessTime,
+            SUM(b.accessDuration) AS accessDuration,
+            b.accessDate,
+            b.accessClient,
+            b.region AS region,
+            u.registerTime AS addTime
+        FROM cm_behavior_record b
+                 LEFT JOIN USER u ON b.userID = u.userID
+                 LEFT JOIN club c ON b.userID = c.userID
+                 LEFT JOIN shop s ON b.userID = s.userID
+        WHERE  b.IP != '106.55.202.118' AND b.delFlag = 0  AND b.accessDate = #{accessDate}
+        GROUP BY b.IP, b.accessDate,b.userID ORDER BY b.accessTime DESC
+    </select>
+    <select id="selDataList" resultType="com.caimei365.tools.model.po.CmBehaviorRecordPo">
+        SELECT s.name AS relevanceShop, cbs.userID, cbs.IP, cbs.pageLabel
+        FROM cm_behavior_record cbs
+        LEFT JOIN cm_behavior_shopid cbr ON cbs.recordID = cbr.recordID
+        LEFT JOIN shop s ON s.shopID = cbr.shopID
+        where cbs.accessDate = #{accessDate}
+        order by cbs.accessTime
+    </select>
+    <insert id="inBehaviorToday">
+        INSERT INTO cm_behavior_record_today (
+                id,
+                IP,
+                userId,
+                clubId,
+                lastAccessTime,
+                companyType,
+                corporateName,
+                contacts,
+                phoneNumber,
+                spName,
+                number,
+                consultName,
+                consultMobile,
+                accessTime,
+                accessDuration,
+                accessDate,
+                accessClient,
+                region,
+                relevanceShop,
+                label,
+                addTime
+            ) values (
+                #{recordID},
+                #{IP},
+                #{userId},
+                #{clubId},
+                #{lastAccessTime},
+                #{companyType},
+                #{corporateName},
+                #{contacts},
+                #{phoneNumber},
+                #{spName},
+                #{number},
+                #{consultName},
+                #{consultMobile},
+                #{accessTime},
+                #{accessDuration},
+                #{accessDate},
+                #{accessClient},
+                #{region},
+                #{relevanceShop},
+                #{label},
+                #{addTime}
+            )
+    </insert>
+    <delete id="delTodayData">
+        TRUNCATE TABLE cm_behavior_record_today
+    </delete>
+    <select id="shopIds" resultType="java.lang.Integer">
+        SELECT DISTINCT csr.shopID FROM cm_shop_relevance csr
+            LEFT JOIN cm_shop_label csl ON csr.id = csl.relevanceId
+            LEFT JOIN cm_user_search_frequency cusf ON csl.keywordId = cusf.id
+        <where>
+            <if test="strList != null and strList.size > 0">
+                <foreach collection="strList" item="keyword" open="(" close=")" separator="or">
+                    cusf.keyword like concat('%',#{keyword},'%')
+                </foreach>
+            </if>
+        </where>
+    </select>
+    <insert id="insertShopId">
+        insert into cm_behavior_shopId (recordID, shopID) values (#{recordId}, #{shopId})
+    </insert>
 </mapper>