Browse Source

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

huangzhiguo 1 year ago
parent
commit
ade7ed3cf5

+ 5 - 1
src/main/java/com/caimei365/tools/mapper/BaseMapper.java

@@ -1,7 +1,6 @@
 package com.caimei365.tools.mapper;
 
 import com.caimei365.tools.model.bo.CouponDateBo;
-import com.caimei365.tools.model.bo.HeheCouponBo;
 import com.caimei365.tools.model.po.*;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
@@ -115,6 +114,11 @@ public interface BaseMapper {
 
     List<Map<String,Object>> getBehaviorRecordYesterday(@Param("accessTime") String accessTime);
 
+    List<Map<String,Object>> getBehaviorRecordMinute(@Param("accessTime") String accessTime);
+
+    List<Map<String,Object>> getBehaviorRecordClubMinute(@Param("accessTime") String accessTime);
+
+    String getBehaviorRecordMinutePageLabel(@Param("spId") Integer spId,@Param("clubId") Integer clubId,@Param("accessTime")String accessTime);
     String getBehaviorRecordYesterdayPageLabel(@Param("spId") Integer spId,@Param("clubId") Integer clubId,@Param("accessTime")String accessTime);
 
     void updateRecommend(List<Integer> ids);

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

@@ -187,4 +187,14 @@ public class CmBehaviorRecordPo {
      * 机构市Id
      */
     private Integer cityId;
+
+    /**
+     * 记录起始者userId
+     *
+     */
+    private String headUserId;
+    /**
+     * 商品资料库id
+     */
+    private String productArchiveId;
 }

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

@@ -4,7 +4,6 @@ import com.alibaba.fastjson.JSONObject;
 import com.caimei365.tools.mapper.CmBehaviorRecordMapper;
 import com.caimei365.tools.model.po.*;
 import com.caimei365.tools.service.CmBehaviorRecordService;
-import io.netty.util.internal.MathUtil;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -14,11 +13,9 @@ import java.io.BufferedReader;
 import java.io.IOException;
 import java.io.InputStreamReader;
 import java.io.UnsupportedEncodingException;
-import java.math.BigDecimal;
 import java.net.HttpURLConnection;
 import java.net.MalformedURLException;
 import java.net.URL;
-import java.text.DecimalFormat;
 import java.text.SimpleDateFormat;
 import java.util.*;
 import java.util.regex.Matcher;
@@ -45,6 +42,8 @@ public class CmBehaviorRecordServiceImpl implements CmBehaviorRecordService {
         if ("/user/record/Statistics".equals(ipSavePo.getRequestUrl().trim()) && !ipSavePo.getIp().equals("106.55.202.118")) {
             log.info("用户行为记录=================》" + ipSavePo.getIp());
             CmBehaviorRecordPo cmBehaviorRecordPo = new CmBehaviorRecordPo();
+            // 赋默认值
+            cmBehaviorRecordPo.setPageType(0);
             String region = "";
             String[] splitArray = ipSavePo.getIp().split(",");
             for (String split : splitArray) {
@@ -96,8 +95,6 @@ public class CmBehaviorRecordServiceImpl implements CmBehaviorRecordService {
                     // 页面类型
                     if (str.startsWith("pageType") && str.contains("=")) {
                         String[] split1 = str.split("=");
-                        // 赋默认值
-                        cmBehaviorRecordPo.setPageType(0);
                         if (split1.length > 1) {
                             String value = split1[1];
                             String trim = value.trim();
@@ -257,6 +254,30 @@ public class CmBehaviorRecordServiceImpl implements CmBehaviorRecordService {
                             }
                         }
                     }
+                    // headUserId
+                    if (str.startsWith("headUserId") && str.contains("=")) {
+                        String[] split1 = str.split("=");
+                        if (split1.length > 1) {
+                            String value = split1[1];
+                            String trim = value.trim();
+                            if (StringUtils.isNotBlank(trim)) {
+                                log.info("headUserId============》" + trim);
+                                 cmBehaviorRecordPo.setHeadUserId(trim);
+                            }
+                        }
+                    }
+                    // productArchiveId
+                    if (str.startsWith("productArchiveId") && str.contains("=")) {
+                        String[] split1 = str.split("=");
+                        if (split1.length > 1) {
+                            String value = split1[1];
+                            String trim = value.trim();
+                            if (StringUtils.isNotBlank(trim)) {
+                                log.info("productArchiveId============》" + trim);
+                                 cmBehaviorRecordPo.setProductArchiveId(trim);
+                            }
+                        }
+                    }
 
                 }
                 // 处理页面标签为空
@@ -1304,6 +1325,9 @@ public class CmBehaviorRecordServiceImpl implements CmBehaviorRecordService {
         if (link.contains("zzjtest.gz.aeert.com")) {
             return "0";
         }
+        if (link.contains("material")&&link.contains("caimei365.com")) { //https://material-b.caimei365.com
+            return "8";
+        }
         return null;
     }
 

+ 85 - 6
src/main/java/com/caimei365/tools/task/StatisticsTask.java

@@ -1,6 +1,5 @@
 package com.caimei365.tools.task;
 
-import com.alibaba.fastjson.JSONObject;
 import com.caimei365.tools.feign.CommodityFeign;
 import com.caimei365.tools.mapper.BaseMapper;
 import com.caimei365.tools.model.dto.message.InsideMessage;
@@ -11,12 +10,11 @@ import com.caimei365.tools.model.dto.message.enums.MessageType;
 import com.caimei365.tools.model.po.ClubPo;
 import com.caimei365.tools.model.po.CmUserPo;
 import com.caimei365.tools.service.MessageSender;
-import com.caimei365.tools.utils.RequestUtil;
 import com.caimei365.tools.utils.SmsUtil;
-import com.fasterxml.jackson.databind.ObjectMapper;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
+import org.apache.commons.lang3.time.DateFormatUtils;
 import org.springframework.context.annotation.Configuration;
 import org.springframework.data.redis.core.RedisCallback;
 import org.springframework.data.redis.core.RedisTemplate;
@@ -100,7 +98,7 @@ public class StatisticsTask {
      * ? 表示不指定值。
      */
     @Scheduled(cron = "0 30 9 * * ?")
-    public void countSpClubViews() {
+    public void recordYesterday() {
         try {
             // 获取昨天日期字符串
             Calendar calendar = Calendar.getInstance();
@@ -113,7 +111,7 @@ public class StatisticsTask {
             for (Map<String, Object> map : behaviorRecordYesterday) {
                 Integer spId = (Integer) map.get("spId");
                 String name = (String) map.get("name");
-                Integer count = Integer.valueOf(map.get("count").toString()) ;
+                Integer count =(Integer) map.get("count");
                 String pageLabel = baseMapper.getBehaviorRecordYesterdayPageLabel(spId, null, dateStr);
                 String openId = baseMapper.getWechatOpenId((String) map.get("unionId"));
                 //站内信 【协销前一天机构访问记录】
@@ -132,7 +130,7 @@ public class StatisticsTask {
                 messageSender.messageSend(insideMessageMessageModel);
                 //微信模板消息 【协销前一天机构访问记录】
                 ArrayList<String> keyWords = new ArrayList<>();
-                keyWords.add(name+"...等"+Integer.valueOf(String.valueOf(count))+"家机构客户");
+                keyWords.add(name+"...等"+count+"家机构客户");
                 keyWords.add(pageLabel);
                 keyWords.add(dateStr);
                 MessageModel<WechatTemplateMessage> wechatTemplateMessageMessageModel = new MessageModel<WechatTemplateMessage>()
@@ -166,4 +164,85 @@ public class StatisticsTask {
             log.error(">>>>>>>>>>>【定时任务】统计前一天针对机构访问商城形式的活跃行为失败:", e);
         }
     }
+
+
+    /**
+     * 每天五分钟执行一次统计统计内容库访问活跃行为
+     * <p>
+     * cron表达式语法:秒 分 小时 日 月 周
+     * 年可省略
+     * * 表示所有值。
+     * ? 表示不指定值。
+     */
+    @Scheduled(cron = "0 */5 * * * ?")
+    public void behaviorRecordMinute() {
+        try {
+            Calendar calendar = Calendar.getInstance();
+            String dateNewStr = new SimpleDateFormat("yyyy-MM-dd HH:mm:00").format(calendar.getTime());
+            calendar.add(Calendar.MINUTE, -5);
+            String dateStr = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(calendar.getTime());
+            List<Map<String, Object>> behaviorRecordClubMinute = baseMapper.getBehaviorRecordClubMinute(dateStr);
+            for (Map<String, Object> map : behaviorRecordClubMinute) {
+                Integer spId = Integer.valueOf(map.get("spId").toString());
+                String name = (String) map.get("name");
+                // String openId = baseMapper.getWechatOpenId((String) map.get("unionId"));
+                Integer clubID = Integer.valueOf(map.get("clubID").toString());
+                //站内信
+                MessageModel<InsideMessage> insideMessageMessageModel = new MessageModel<>();
+                insideMessageMessageModel.code(MessageType.WEB_INSIDE_MESSAGE)
+                        .mqInfo(new MqInfo().topic("MessageLine").delay(3).async(1))
+                        .info(new InsideMessage()
+                                .userType(3)
+                                .messageType(3)
+                                .shopTieredType(9)
+                                .name(name)
+                                .clubId(clubID)
+                                .thisId(spId)
+                        );
+                messageSender.messageSend(insideMessageMessageModel);
+            }
+            List<Map<String, Object>> behaviorRecordYesterday = baseMapper.getBehaviorRecordMinute(dateStr);
+            for (Map<String, Object> map : behaviorRecordYesterday) {
+                Integer spId = Integer.valueOf(map.get("spId").toString());
+                String name =  map.get("name").toString();
+                Integer count = Integer.valueOf(map.get("count").toString());
+                String openId = baseMapper.getWechatOpenId((String) map.get("unionId"));
+                String pageLabel = baseMapper.getBehaviorRecordMinutePageLabel(spId, null, dateStr);
+                //站内信
+                MessageModel<InsideMessage> insideMessageMessageModel = new MessageModel<>();
+                insideMessageMessageModel.code(MessageType.WEB_INSIDE_MESSAGE)
+                        .mqInfo(new MqInfo().topic("MessageLine").delay(3).async(1))
+                        .info(new InsideMessage()
+                                .userType(3)
+                                .messageType(3)
+                                .shopTieredType(10)
+                                .name(name)
+                                .content(pageLabel)
+                                .sum(count)
+                                .thisId(spId)
+                            );
+                    messageSender.messageSend(insideMessageMessageModel);
+                    //微信模板消息
+                    ArrayList<String> keyWords = new ArrayList<>();
+                    keyWords.add(name+"...等"+count+"家机构客户访问了您的内容库资料分享");
+                    keyWords.add(pageLabel);
+                    keyWords.add(DateFormatUtils.format(calendar.getTime(), "yyyy-MM-dd"));
+                    MessageModel<WechatTemplateMessage> wechatTemplateMessageMessageModel = new MessageModel<WechatTemplateMessage>()
+                            .code(MessageType.WECHAT_TEMPLATE_MESSAGE)
+                            .mqInfo(new MqInfo().topic("MessageLine").delay(3).async(1))
+                            .info(new WechatTemplateMessage()
+                                    .first("")
+                                    .openId(openId)
+                                    .appid("wxf3cd4ae0cdd11c36")
+                                    .templateId("Zd7ewJw9-bN-gIgra9flKW96W3YehikRPPkDXPfhmQ0")
+                                    .keyWords(keyWords)
+                                    .remark("为了更好给您服务,请及时联系采美客服!")
+                                    .pagePath("pages/seller/notice/service/Institutional_visits?type=1&spId="+spId+"&accDateTime="+dateNewStr));
+                    messageSender.messageSend(wechatTemplateMessageMessageModel);
+            }
+            log.info(">>>>>>>>>>>【定时任务】统计内容库访问活跃行为,统计成功");
+        } catch (Exception e) {
+            log.error(">>>>>>>>>>>【定时任务】统计内容库访问活跃行为活跃行为失败:", e);
+        }
+    }
 }

+ 44 - 0
src/main/resources/mapper/BaseMapper.xml

@@ -216,6 +216,50 @@
         GROUP BY c.spId
         ORDER BY count(c.clubId) DESC
     </select>
+    <select id="getBehaviorRecordMinute" resultType="java.util.HashMap">
+        SELECT sp.serviceProviderID as spId,
+               b.accessTime,
+               ifnull(c.name,'游客')as name,
+               c.clubID,
+               sp.unionId,
+               count(DISTINCT recordID) as count
+        FROM cm_behavior_record b
+        LEFT JOIN club c ON b.userID = c.userID
+        LEFT JOIN serviceprovider sp ON b.headUserId = sp.userID
+        WHERE  sp.status=90 and sp.serviceProviderID!=1342
+        and b.pageType in (69,70,71)
+        and b.accessTime >= #{accessTime}
+        GROUP BY sp.serviceProviderID
+        ORDER BY count(recordID) DESC
+    </select>
+    <select id="getBehaviorRecordClubMinute" resultType="java.util.HashMap">
+        SELECT sp.serviceProviderID as spId,
+               b.accessTime,
+               c.name,
+               c.clubID,
+               sp.unionId
+        FROM cm_behavior_record b
+        LEFT JOIN club c ON b.userID = c.userID
+        LEFT JOIN serviceprovider sp ON b.headUserId = sp.userID
+        WHERE  sp.status=90 and sp.serviceProviderID!=1342
+        and b.pageType =22
+        and b.accessTime >= #{accessTime}
+    </select>
+    <select id="getBehaviorRecordMinutePageLabel" resultType="string">
+        SELECT GROUP_CONCAT(a.pageLabel)
+        FROM (SELECT b.pageLabel
+              FROM cm_behavior_record b
+              LEFT JOIN club c ON b.userID = c.userID
+              LEFT JOIN serviceprovider sp ON b.headUserId = sp.userID
+        WHERE b.userId !=0
+              and sp.serviceProviderID=#{spId}
+              <if test="clubId != null">
+                AND c.clubId =#{clubId}
+              </if>
+              and b.pageType in (69,70,71)
+              and  b.accessTime >= #{accessTime}
+              GROUP BY b.pageLabel LIMIT 5) as a
+    </select>
     <select id="getBehaviorRecordYesterdayPageLabel" resultType="string">
         SELECT GROUP_CONCAT(a.pageLabel)
         FROM (SELECT b.pageLabel

+ 18 - 6
src/main/resources/mapper/CmBehaviorRecordMapper.xml

@@ -24,9 +24,9 @@
 
     <insert id="insertRecord" parameterType="com.caimei365.tools.model.po.CmBehaviorRecordPo" useGeneratedKeys="true" keyProperty="recordID">
         INSERT INTO cm_behavior_record (IP, userID, touristId, pagePath, pageType, pageLabel, behaviorType, productID, accessTime,
-                                        accessDuration, accessDate, referer, accessSource, accessClient, isReckon, region, userAgent, openId, delFlag)
+                                        accessDuration, accessDate, referer, accessSource, accessClient, isReckon, region, userAgent, openId, delFlag,headUserId,productArchiveId)
         VALUES(#{IP}, #{userId}, #{touristId}, #{pagePath}, #{pageType}, #{pageLabel}, #{behaviorType}, #{productId}, #{accessTime},
-               #{accessDuration}, #{accessDate}, #{referer}, #{accessSource}, #{accessClient}, #{isReckon}, #{region}, #{userAgent}, #{openId}, #{delFlag})
+               #{accessDuration}, #{accessDate}, #{referer}, #{accessSource}, #{accessClient}, #{isReckon}, #{region}, #{userAgent}, #{openId}, #{delFlag},#{headUserId},#{productArchiveId})
     </insert>
 
     <select id="toDateRecode" resultType="com.caimei365.tools.model.po.CmBehaviorRecordPo">
@@ -356,6 +356,8 @@
             SUM(b.accessDuration) AS accessDuration,
             b.accessDate,
             b.accessClient,
+            MAX(CASE WHEN b.headUserId IS NOT NULL THEN b.headUserId END) as headUserId,
+            MAX(CASE WHEN b.productArchiveId IS NOT NULL THEN b.productArchiveId END) as productArchiveId,
             b.region AS region,
             u.registerTime AS addTime,
             (SELECT touristId FROM cm_behavior_record WHERE accessDate = #{accessDate} and IP = b.IP ORDER BY accessTime DESC LIMIT 1) AS touristId,
@@ -393,7 +395,9 @@
               pageTypes,
               addTime,
               touristId,
-              delFlag
+              delFlag,
+              headUserId,
+              productArchiveId
             ) values (
                    #{IP},
                    #{userId},
@@ -418,7 +422,9 @@
                    #{pageTypes},
                    #{addTime},
                    #{touristId},
-                   '0'
+                   '0',
+                   #{headUserId},
+                   #{productArchiveId}
                )
     </select>
     <select id="selTodayData" resultType="com.caimei365.tools.model.po.CmBehaviorRecordPo">
@@ -462,6 +468,8 @@
             SUM(b.accessDuration) AS accessDuration,
             b.accessDate,
             b.accessClient,
+            MAX(CASE WHEN b.headUserId IS NOT NULL THEN b.headUserId END) as headUserId,
+            MAX(CASE WHEN b.productArchiveId IS NOT NULL THEN b.productArchiveId END) as productArchiveId,
             b.region AS region,
             u.registerTime AS addTime
         FROM cm_behavior_record b
@@ -516,7 +524,9 @@
                 label,
                 pageLabels,
                 pageTypes,
-                addTime
+                addTime,
+                headUserId,
+                productArchiveId
             ) values (
                 #{recordID},
                 #{IP},
@@ -540,7 +550,9 @@
                 #{label},
                 #{pageLabels},
                 #{pageTypes},
-                #{addTime}
+                #{addTime},
+                #{headUserId},
+                #{productArchiveId}
             )
     </insert>
     <delete id="delTodayData">