文件阅览详情界面浏览时长监控代码
This commit is contained in:
parent
34bb69598d
commit
dcc65b6ad4
Binary file not shown.
@ -7,23 +7,14 @@ import java.io.IOException;
|
|||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.sql.Timestamp;
|
import java.sql.Timestamp;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Comparator;
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.Set;
|
|
||||||
import javax.imageio.ImageIO;
|
import javax.imageio.ImageIO;
|
||||||
|
|
||||||
import com.actionsoft.apps.coe.pal.pal.repository.cache.*;
|
import com.actionsoft.apps.coe.pal.pal.repository.cache.*;
|
||||||
import com.actionsoft.bpms.util.*;
|
import com.actionsoft.bpms.util.*;
|
||||||
|
|
||||||
|
import com.actionsoft.bpms.util.Base64;
|
||||||
import org.apache.commons.collections.CollectionUtils;
|
import org.apache.commons.collections.CollectionUtils;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.apache.poi.hssf.usermodel.HSSFCell;
|
import org.apache.poi.hssf.usermodel.HSSFCell;
|
||||||
@ -3448,7 +3439,8 @@ public class CoeDesignerWeb extends ActionWeb {
|
|||||||
PALRepositoryQueryAPIManager.getInstance().UpDatePublishCount(plModel);
|
PALRepositoryQueryAPIManager.getInstance().UpDatePublishCount(plModel);
|
||||||
}
|
}
|
||||||
/********************描述************************/
|
/********************描述************************/
|
||||||
|
//增加浏览器唯一id
|
||||||
|
macroLibraries.put("browserId", generateRandom());
|
||||||
if (plModel.getMethodId().equals("process.evc")) {
|
if (plModel.getMethodId().equals("process.evc")) {
|
||||||
return HtmlPageTemplate.merge(CoEConstant.APP_ID, "pal.pl.repository.designer.view.portal.framework.html", macroLibraries);
|
return HtmlPageTemplate.merge(CoEConstant.APP_ID, "pal.pl.repository.designer.view.portal.framework.html", macroLibraries);
|
||||||
} else {
|
} else {
|
||||||
@ -3458,6 +3450,14 @@ public class CoeDesignerWeb extends ActionWeb {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static String generateRandom() {
|
||||||
|
// 使用UUID生成唯一随机数,然后转换为16进制
|
||||||
|
UUID uuid = UUID.randomUUID();
|
||||||
|
return Long.toHexString(uuid.getMostSignificantBits()) +
|
||||||
|
Long.toHexString(uuid.getLeastSignificantBits());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -252,7 +252,6 @@
|
|||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
var sid = "<#sid>";
|
var sid = "<#sid>";
|
||||||
var appId = '<#appId>';
|
var appId = '<#appId>';
|
||||||
var userId = "<#userId>";
|
|
||||||
var userName = "<#userName>";
|
var userName = "<#userName>";
|
||||||
var userNameAlias = "<#userNameAlias>";
|
var userNameAlias = "<#userNameAlias>";
|
||||||
var siteId = "<#siteId>";
|
var siteId = "<#siteId>";
|
||||||
@ -313,6 +312,7 @@
|
|||||||
var showReplyNum = "<#showReplyNum>";
|
var showReplyNum = "<#showReplyNum>";
|
||||||
var boId = "";
|
var boId = "";
|
||||||
var portalUrl = "<#portalUrl>";
|
var portalUrl = "<#portalUrl>";
|
||||||
|
var browserId = "<#browserId>";
|
||||||
|
|
||||||
|
|
||||||
// 国际化
|
// 国际化
|
||||||
@ -758,6 +758,98 @@
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// 页面停留时间统计
|
||||||
|
class PageStayTimeTracker {
|
||||||
|
constructor() {
|
||||||
|
this.startTime = null;
|
||||||
|
this.lastReportTime = null;
|
||||||
|
this.reportInterval = 10000; // 60秒报告一次
|
||||||
|
this.isPageVisible = true; // 默认页面是可见的
|
||||||
|
this.visibilityBound = false; // 是否已绑定可见性事件
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// 开始跟踪
|
||||||
|
startTracking() {
|
||||||
|
if (this.isActive) return;
|
||||||
|
|
||||||
|
this.startTime = new Date();
|
||||||
|
this.lastReportTime = this.startTime;
|
||||||
|
this.isActive = true;
|
||||||
|
|
||||||
|
// 设置定时器
|
||||||
|
this.intervalId = setInterval(() => {
|
||||||
|
if (this.isPageVisible) {
|
||||||
|
this.reportStayTime();
|
||||||
|
}
|
||||||
|
}, this.reportInterval);
|
||||||
|
|
||||||
|
// 页面卸载前发送剩余时间
|
||||||
|
window.addEventListener('beforeunload', this.finalReport.bind(this));
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// 报告停留时间
|
||||||
|
reportStayTime() {
|
||||||
|
this.sendStayTimeToServer(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 最终报告
|
||||||
|
finalReport() {
|
||||||
|
if (!this.isActive) return;
|
||||||
|
if (this.isPageVisible) {
|
||||||
|
const now = new Date();
|
||||||
|
const elapsed = now - this.lastReportTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
this.sendStayTimeToServer(false);
|
||||||
|
this.cleanUp();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// 发送数据到服务器
|
||||||
|
sendStayTimeToServer(isActive) {
|
||||||
|
$.ajax({
|
||||||
|
type : "POST",
|
||||||
|
url : "./w?sid=" + encodeURIComponent($('#sid').val()) + "&cmd=com.awspaas.user.apps.browsing_data.service.insertReadingLog",
|
||||||
|
data : "userId="+user+"&userName="+userName+"&ruuid="+ruuid+"&fileName="+fileName+"&startTime="+new Date(this.startTime).getTime()+"¤tTime="+new Date().getTime()+"&browserId="+browserId+"&isActive="+isActive,
|
||||||
|
success : function(msg) {
|
||||||
|
if (msg.result == "error") {
|
||||||
|
$.simpleAlert("新增失败", "error");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// 清理资源
|
||||||
|
cleanUp() {
|
||||||
|
clearInterval(this.intervalId);
|
||||||
|
window.removeEventListener('beforeunload', this.finalReport);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 使用示例
|
||||||
|
const tracker = new PageStayTimeTracker();
|
||||||
|
tracker.startTracking();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//渲染评论内容
|
//渲染评论内容
|
||||||
function initPl() {
|
function initPl() {
|
||||||
$(".message-detial-reply").empty();
|
$(".message-detial-reply").empty();
|
||||||
|
|||||||
Binary file not shown.
@ -45,6 +45,10 @@ public class InsertReadingLogService extends ActionWeb
|
|||||||
Long begintime=Long.valueOf(params.get("startTime"));
|
Long begintime=Long.valueOf(params.get("startTime"));
|
||||||
Long endtime=Long.valueOf(params.get("currentTime"));
|
Long endtime=Long.valueOf(params.get("currentTime"));
|
||||||
|
|
||||||
|
String isActive=params.get("isActive");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
long time =endtime - begintime;
|
long time =endtime - begintime;
|
||||||
long diffSeconds = time / 1000 % 60;
|
long diffSeconds = time / 1000 % 60;
|
||||||
long diffMinutes = time / (60 * 1000) % 60;
|
long diffMinutes = time / (60 * 1000) % 60;
|
||||||
@ -66,10 +70,9 @@ public class InsertReadingLogService extends ActionWeb
|
|||||||
String beginDate = sdf.format(begintime);
|
String beginDate = sdf.format(begintime);
|
||||||
String endDate = sdf.format(endtime);
|
String endDate = sdf.format(endtime);
|
||||||
|
|
||||||
|
|
||||||
BO insertReadingLog=SDK.getBOAPI().query("BO_EU_READING_DURATION").addQuery("BROWSERID=",params.get("browserId")).addQuery("ISACTIVE=","true").detail();
|
BO insertReadingLog=SDK.getBOAPI().query("BO_EU_READING_DURATION").addQuery("BROWSERID=",params.get("browserId")).addQuery("ISACTIVE=","true").detail();
|
||||||
if(insertReadingLog==null){
|
if(insertReadingLog==null){
|
||||||
BO bo=new BO();
|
BO bo=new BO();
|
||||||
bo.set("USERID",params.get("userId"));
|
bo.set("USERID",params.get("userId"));
|
||||||
bo.set("USERNAME",params.get("userName"));
|
bo.set("USERNAME",params.get("userName"));
|
||||||
bo.set("MODELID",params.get("ruuid"));
|
bo.set("MODELID",params.get("ruuid"));
|
||||||
@ -83,6 +86,7 @@ public class InsertReadingLogService extends ActionWeb
|
|||||||
.createBOProcessInstance("obj_9af2004d87b3472da210b43dc1ca32ab", uc.getUID(), "浏览数据监听");
|
.createBOProcessInstance("obj_9af2004d87b3472da210b43dc1ca32ab", uc.getUID(), "浏览数据监听");
|
||||||
SDK.getBOAPI().create("BO_EU_READING_DURATION",bo,processInstance.getId(),uc.getUID());
|
SDK.getBOAPI().create("BO_EU_READING_DURATION",bo,processInstance.getId(),uc.getUID());
|
||||||
|
|
||||||
|
|
||||||
}else{
|
}else{
|
||||||
insertReadingLog.set("USERID",params.get("userId"));
|
insertReadingLog.set("USERID",params.get("userId"));
|
||||||
insertReadingLog.set("USERNAME",params.get("userName"));
|
insertReadingLog.set("USERNAME",params.get("userName"));
|
||||||
@ -90,6 +94,7 @@ public class InsertReadingLogService extends ActionWeb
|
|||||||
insertReadingLog.set("READING_END_TIME",endDate);
|
insertReadingLog.set("READING_END_TIME",endDate);
|
||||||
insertReadingLog.set("CUMULATIVE_DURATION_STAY",remainTime);
|
insertReadingLog.set("CUMULATIVE_DURATION_STAY",remainTime);
|
||||||
insertReadingLog.set("BROWSERID",params.get("browserId"));
|
insertReadingLog.set("BROWSERID",params.get("browserId"));
|
||||||
|
insertReadingLog.set("ISACTIVE",isActive);
|
||||||
SDK.getBOAPI().update("BO_EU_READING_DURATION",insertReadingLog);
|
SDK.getBOAPI().update("BO_EU_READING_DURATION",insertReadingLog);
|
||||||
}
|
}
|
||||||
ro.put("result", "ok");
|
ro.put("result", "ok");
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user