Browse Source

渠道看板、产品看板、会员看板停留时长

pengyg 4 tháng trước cách đây
mục cha
commit
c3026131bf

+ 8 - 0
suishenbang-admin/src/main/resources/templates/system/magnetLog/magnetLog.html

@@ -134,6 +134,14 @@
                     field : 'createTime',
                     title : '访问时间'
                 },
+                {
+                    field : 'stayDuration',
+                    title : '停留时长(单位:秒)'
+                },
+                {
+                    field : 'whatEndStr',
+                    title : '移动端/电脑端'
+                },
                 {
                     title: '操作',
                     align: 'center',

+ 95 - 52
suishenbang-system/src/main/java/com/dgtly/system/domain/SysMagnetLog.java

@@ -57,45 +57,43 @@ public class SysMagnetLog extends BaseEntity
     @Excel(name = "访问时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
     private Date createTime;
 
-    public void setId(Long id) 
-    {
-        this.id = id;
-    }
+    /** 创建时间 */
+    @Excel(name = "结束访问时间(仅渠道看板、产品看板、会员看板)", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
+    private Date updateTime;
+
+    /** 停留时长 */
+    @Excel(name = "停留时长(单位:秒)")
+    private Long stayDuration;
 
-    public Long getId() 
-    {
+    /** 移动端/电脑端 */
+    private Long whatEnd;
+
+    /** 移动端/电脑端 */
+    @Excel(name = "移动端/电脑端")
+    private String whatEndStr;
+
+    public Long getId() {
         return id;
     }
-    public void setUserId(Long userId) 
-    {
-        this.userId = userId;
+
+    public void setId(Long id) {
+        this.id = id;
     }
 
-    public Long getUserId() 
-    {
+    public Long getUserId() {
         return userId;
     }
-    public void setUserName(String userName) 
-    {
-        this.userName = userName;
+
+    public void setUserId(Long userId) {
+        this.userId = userId;
     }
 
-    public String getUserName() 
-    {
+    public String getUserName() {
         return userName;
     }
-    public void setOrgCode(String orgCode) 
-    {
-        this.orgCode = orgCode;
-    }
 
-    public String getOrgCode() 
-    {
-        return orgCode;
-    }
-    public void setOrgName(String orgName) 
-    {
-        this.orgName = orgName;
+    public void setUserName(String userName) {
+        this.userName = userName;
     }
 
     public String getLoginName() {
@@ -114,29 +112,38 @@ public class SysMagnetLog extends BaseEntity
         this.sapEmployeeId = sapEmployeeId;
     }
 
-    public String getOrgName()
-    {
+    public String getOrgCode() {
+        return orgCode;
+    }
+
+    public void setOrgCode(String orgCode) {
+        this.orgCode = orgCode;
+    }
+
+    public String getOrgName() {
         return orgName;
     }
-    public void setLevel(String level) 
-    {
-        this.level = level;
+
+    public void setOrgName(String orgName) {
+        this.orgName = orgName;
     }
 
-    public String getLevel() 
-    {
+    public String getLevel() {
         return level;
     }
-    public void setMagnetName(String magnetName) 
-    {
-        this.magnetName = magnetName;
+
+    public void setLevel(String level) {
+        this.level = level;
     }
 
-    public String getMagnetName() 
-    {
+    public String getMagnetName() {
         return magnetName;
     }
 
+    public void setMagnetName(String magnetName) {
+        this.magnetName = magnetName;
+    }
+
     @Override
     public Date getCreateTime() {
         return createTime;
@@ -147,20 +154,56 @@ public class SysMagnetLog extends BaseEntity
         this.createTime = createTime;
     }
 
+    @Override
+    public Date getUpdateTime() {
+        return updateTime;
+    }
+
+    @Override
+    public void setUpdateTime(Date updateTime) {
+        this.updateTime = updateTime;
+    }
+
+    public Long getStayDuration() {
+        return stayDuration;
+    }
+
+    public void setStayDuration(Long stayDuration) {
+        this.stayDuration = stayDuration;
+    }
+
+    public Long getWhatEnd() {
+        return whatEnd;
+    }
+
+    public void setWhatEnd(Long whatEnd) {
+        this.whatEnd = whatEnd;
+    }
+
+    public String getWhatEndStr() {
+        return whatEndStr;
+    }
+
+    public void setWhatEndStr(String whatEndStr) {
+        this.whatEndStr = whatEndStr;
+    }
+
     @Override
     public String toString() {
-        return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
-            .append("id", getId())
-            .append("userId", getUserId())
-            .append("userName", getUserName())
-            .append("orgCode", getOrgCode())
-            .append("orgName", getOrgName())
-            .append("level", getLevel())
-            .append("magnetName", getMagnetName())
-            .append("createBy", getCreateBy())
-            .append("createTime", getCreateTime())
-            .append("updateBy", getUpdateBy())
-            .append("updateTime", getUpdateTime())
-            .toString();
+        return "SysMagnetLog{" +
+                "id=" + id +
+                ", userId=" + userId +
+                ", userName='" + userName + '\'' +
+                ", loginName='" + loginName + '\'' +
+                ", sapEmployeeId='" + sapEmployeeId + '\'' +
+                ", orgCode='" + orgCode + '\'' +
+                ", orgName='" + orgName + '\'' +
+                ", level='" + level + '\'' +
+                ", magnetName='" + magnetName + '\'' +
+                ", createTime=" + createTime +
+                ", updateTime=" + updateTime +
+                ", stayDuration=" + stayDuration +
+                ", whatEnd=" + whatEnd +
+                '}';
     }
 }

+ 8 - 0
suishenbang-system/src/main/java/com/dgtly/system/mapper/SysMagnetLogMapper.java

@@ -58,4 +58,12 @@ public interface SysMagnetLogMapper
      * @return 结果
      */
     public int deleteSysMagnetLogByIds(String[] ids);
+
+    /**
+     * 根据用户id,移动端、电脑端,查询最近一点的埋点记录
+     *
+     * @param sysMagnetLog 磁铁日志
+     * @return 磁铁日志
+     */
+    public SysMagnetLog selectOneByCondition(SysMagnetLog sysMagnetLog);
 }

+ 25 - 0
suishenbang-system/src/main/java/com/dgtly/system/service/impl/SysMagnetLogServiceImpl.java

@@ -1,5 +1,6 @@
 package com.dgtly.system.service.impl;
 
+import java.util.Calendar;
 import java.util.List;
 import com.dgtly.common.utils.DateUtils;
 import com.dgtly.system.domain.SysUser;
@@ -63,6 +64,30 @@ public class SysMagnetLogServiceImpl implements ISysMagnetLogService
         sysMagnetLog.setLoginName(user.getLoginName());
         sysMagnetLog.setSapEmployeeId(user.getSysUserExt().getSapEmployeeId());
         sysMagnetLog.setCreateTime(DateUtils.getNowDate());
+        //计算渠道看板、产品看板、会员看板的停留时长
+        //本次是主页、渠道看板、产品看板、会员看板、关闭随身邦
+        if("主页".equals(sysMagnetLog.getMagnetName()) || "渠道看板".equals(sysMagnetLog.getMagnetName()) || "产品看板".equals(sysMagnetLog.getMagnetName()) || "会员看板".equals(sysMagnetLog.getMagnetName()) || "关闭随身邦".equals(sysMagnetLog.getMagnetName())){
+            //查询最近的上次埋点
+            SysMagnetLog sysMagnetLogLast = sysMagnetLogMapper.selectOneByCondition(sysMagnetLog);
+            if(sysMagnetLogLast!=null && sysMagnetLogLast.getUpdateTime()==null && ("渠道看板".equals(sysMagnetLogLast.getMagnetName()) || "产品看板".equals(sysMagnetLogLast.getMagnetName()) || "会员看板".equals(sysMagnetLogLast.getMagnetName()))){
+                //记录结束访问时间(仅渠道看板、产品看板、会员看板)
+                sysMagnetLogLast.setUpdateTime(sysMagnetLog.getCreateTime());
+                //记录上次的停留时间
+                Calendar startCal = Calendar.getInstance();
+                startCal.setTime(sysMagnetLogLast.getCreateTime());
+                Calendar endCal = Calendar.getInstance();
+                endCal.setTime(sysMagnetLogLast.getUpdateTime());
+                long milliseconds = endCal.getTimeInMillis() - startCal.getTimeInMillis();
+                long seconds = milliseconds / 1000;
+                //停留时间超过24小时,就不再存停留时间了,只保存离开时间
+                if(seconds<86400){
+                    sysMagnetLogLast.setStayDuration(seconds);
+                }
+                //保存上次记录
+                sysMagnetLogMapper.updateSysMagnetLog(sysMagnetLogLast);
+            }
+
+        }
         return sysMagnetLogMapper.insertSysMagnetLog(sysMagnetLog);
     }
 

+ 27 - 5
suishenbang-system/src/main/resources/mapper/system/SysMagnetLogMapper.xml

@@ -16,16 +16,25 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         <result property="createTime"    column="create_time"    />
         <result property="updateBy"    column="update_by"    />
         <result property="updateTime"    column="update_time"    />
+        <result property="stayDuration"    column="stay_duration"    />
+        <result property="whatEnd"    column="what_end"    />
+        <result property="whatEndStr"    column="whatEndStr"    />
         <result property="loginName"    column="login_name"    />
         <result property="sapEmployeeId"    column="sap_employee_id"    />
     </resultMap>
 
     <sql id="selectSysMagnetLogVo">
-        select id, user_id, user_name, login_name,sap_employee_id,org_code, org_name, level, magnet_name, create_by, create_time, update_by, update_time from sys_magnet_log
+        select id, user_id, user_name, login_name,sap_employee_id,org_code, org_name, level, magnet_name, create_by, create_time, update_by, update_time,stay_duration,what_end from sys_magnet_log
     </sql>
 
     <select id="selectSysMagnetLogList" parameterType="SysMagnetLog" resultMap="SysMagnetLogResult">
-        select a.id, a.user_id, a.user_name,a.login_name,a.sap_employee_id, b.org_code, b.org_name, b.sales_level level, a.magnet_name, a.create_time
+        select a.id, a.user_id, a.user_name,a.login_name,a.sap_employee_id, b.org_code, b.org_name, b.sales_level level, a.magnet_name, a.create_time,
+               a.update_time,a.stay_duration,
+               case a.what_end
+                   when 0 then '移动端'
+                   when 1 then '电脑端'
+                   else ''
+                end as whatEndStr
         from sys_magnet_log a left join sys_user_ext b on a.user_id=b.user_id
         <where>
             <if test="userId != null "> and a.user_id = #{userId}</if>
@@ -66,6 +75,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="createTime != null ">create_time,</if>
             <if test="updateBy != null  and updateBy != ''">update_by,</if>
             <if test="updateTime != null ">update_time,</if>
+            <if test="stayDuration != null">stay_duration,</if>
+            <if test="whatEnd != null ">what_end,</if>
          </trim>
         <trim prefix="values (" suffix=")" suffixOverrides=",">
             <if test="userId != null ">#{userId},</if>
@@ -78,8 +89,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="magnetName != null  and magnetName != ''">#{magnetName},</if>
             <if test="createBy != null  and createBy != ''">#{createBy},</if>
             <if test="createTime != null ">#{createTime},</if>
-            <if test="updateBy != null  and updateBy != ''">#{updateBy},</if>
-            <if test="updateTime != null ">#{updateTime},</if>
+            <if test="stayDuration != null">#{stayDuration},</if>
+            <if test="whatEnd != null ">#{whatEnd},</if>
          </trim>
     </insert>
 
@@ -98,6 +109,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="createTime != null ">create_time = #{createTime},</if>
             <if test="updateBy != null  and updateBy != ''">update_by = #{updateBy},</if>
             <if test="updateTime != null ">update_time = #{updateTime},</if>
+            <if test="stayDuration != null">stay_duration=#{stayDuration},</if>
+            <if test="whatEnd != null ">what_end=#{whatEnd},</if>
         </trim>
         where id = #{id}
     </update>
@@ -112,5 +125,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             #{id}
         </foreach>
     </delete>
-    
+
+    <select id="selectOneByCondition" parameterType="SysMagnetLog" resultMap="SysMagnetLogResult">
+        <include refid="selectSysMagnetLogVo"/>
+        <where>
+            <if test="userId != null "> and user_id = #{userId}</if>
+            <if test="whatEnd != null "> and what_end = #{whatEnd}</if>
+            and magnet_name in ('渠道看板','产品看板','会员看板')
+        </where>
+         order by create_time desc limit 1
+    </select>
 </mapper>

+ 3 - 2
suishenbang-wxportal/suishenbang-wxportal-api/src/main/java/com/dgtly/wxportal/controller/WxPortalController.java

@@ -108,7 +108,7 @@ public class WxPortalController extends ApiBaseController {
     /**
      * 新增保存磁铁日志
      */
-    @ApiOperation(value = "新增磁铁访问日志",notes = "参数:{userId,userName,orgCode,orgName,level,magnetName}")
+    @ApiOperation(value = "新增磁铁访问日志",notes = "参数:{userId,userName,orgCode,orgName,level,magnetName,whatEnd}")
     @ApiImplicitParams({
             @ApiImplicitParam(name = "params" , paramType = "body")
     })
@@ -117,7 +117,7 @@ public class WxPortalController extends ApiBaseController {
     public AjaxResult magnetLogAdd()
     {
         ParameterObject obj = getParameterObject();
-        obj.checkParameterNotNull("userId,userName,level,magnetName");
+        obj.checkParameterNotNull("userId,userName,level,magnetName,whatEnd");
         SysMagnetLog sysMagnetLog = new SysMagnetLog();
         sysMagnetLog.setUserId(obj.getLong("userId"));
         sysMagnetLog.setUserName(obj.getString("userName"));
@@ -125,6 +125,7 @@ public class WxPortalController extends ApiBaseController {
         sysMagnetLog.setOrgName(obj.getString("orgName"));
         sysMagnetLog.setLevel(obj.getString("level"));
         sysMagnetLog.setMagnetName(obj.getString("magnetName"));
+        sysMagnetLog.setWhatEnd(obj.getLong("whatEnd"));
         return toAjax(sysMagnetLogService.insertSysMagnetLog(sysMagnetLog));
     }