|
@@ -31,7 +31,8 @@ import java.util.*;
|
|
|
@Service
|
|
|
public class CmBehaviorRecordServiceImpl implements CmBehaviorRecordService {
|
|
|
|
|
|
- @Autowired private CmBehaviorRecordMapper recordMapper;
|
|
|
+ @Autowired
|
|
|
+ private CmBehaviorRecordMapper recordMapper;
|
|
|
|
|
|
@Override
|
|
|
public void insertRecord(IpSavePo ipSavePo) {
|
|
@@ -51,14 +52,14 @@ public class CmBehaviorRecordServiceImpl implements CmBehaviorRecordService {
|
|
|
String str = s.trim();
|
|
|
// 页面路径
|
|
|
if (str.startsWith("pagePath") && str.contains("=")) {
|
|
|
- String[] split1 = str.split(str.substring(str.indexOf("="),str.indexOf("=")+1),2);
|
|
|
+ String[] split1 = str.split(str.substring(str.indexOf("="), str.indexOf("=") + 1), 2);
|
|
|
if (split1.length > 1) {
|
|
|
String value = split1[1];
|
|
|
String trim = value.trim();
|
|
|
if (StringUtils.isNotBlank(trim)) {
|
|
|
String decode = null;
|
|
|
try {
|
|
|
- decode = java.net.URLDecoder.decode(trim,"UTF-8");
|
|
|
+ decode = java.net.URLDecoder.decode(trim, "UTF-8");
|
|
|
if (decode.contains("%")) {
|
|
|
decode = java.net.URLDecoder.decode(decode, "UTF-8");
|
|
|
}
|
|
@@ -69,7 +70,7 @@ public class CmBehaviorRecordServiceImpl implements CmBehaviorRecordService {
|
|
|
}
|
|
|
if (StringUtils.isEmpty(cmBehaviorRecordPo.getPagePath())) {
|
|
|
log.info("页面路径pagePath 值为====》" + trim);
|
|
|
- return ;
|
|
|
+ return;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -192,7 +193,7 @@ public class CmBehaviorRecordServiceImpl implements CmBehaviorRecordService {
|
|
|
String value = split1[1];
|
|
|
String trim = value.trim();
|
|
|
if (StringUtils.isNotBlank(trim)) {
|
|
|
- log.info("userAgent============》"+trim);
|
|
|
+ log.info("userAgent============》" + trim);
|
|
|
// 浏览器userAgent
|
|
|
cmBehaviorRecordPo.setUserAgent(trim);
|
|
|
if (boolReptiles(trim)) {
|
|
@@ -265,13 +266,13 @@ public class CmBehaviorRecordServiceImpl implements CmBehaviorRecordService {
|
|
|
cmBehaviorRecordPo.setAccessDate(format);
|
|
|
// 当天访问系统ip和userID
|
|
|
List<CmBehaviorRecordPo> recordPos = recordMapper.toDateRecode(cmBehaviorRecordPo);
|
|
|
- for (CmBehaviorRecordPo behaviorRecordPo: recordPos) {
|
|
|
+ for (CmBehaviorRecordPo behaviorRecordPo : recordPos) {
|
|
|
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
// 当前时间
|
|
|
String timeEnd = dateFormat.format(date);
|
|
|
// 一小时前时间
|
|
|
Calendar c = Calendar.getInstance();
|
|
|
- c.set(Calendar.HOUR_OF_DAY,(c.get(Calendar.HOUR_OF_DAY) - 1));
|
|
|
+ c.set(Calendar.HOUR_OF_DAY, (c.get(Calendar.HOUR_OF_DAY) - 1));
|
|
|
String timeStart = dateFormat.format(c.getTime());
|
|
|
|
|
|
behaviorRecordPo.setStartTime(timeStart);
|
|
@@ -281,10 +282,10 @@ public class CmBehaviorRecordServiceImpl implements CmBehaviorRecordService {
|
|
|
if (recordPoList.size() <= 0) {
|
|
|
continue;
|
|
|
}
|
|
|
- for (int i = 0; i < recordPoList.size() ; i++) {
|
|
|
+ for (int i = 0; i < recordPoList.size(); i++) {
|
|
|
if (i != recordPoList.size() - 1) {
|
|
|
t1 = recordPoList.get(i).getAccessTime().getTime();
|
|
|
- t2 = recordPoList.get(i+1).getAccessTime().getTime();
|
|
|
+ t2 = recordPoList.get(i + 1).getAccessTime().getTime();
|
|
|
duration = t2 - t1;
|
|
|
// 修改实际访问时长
|
|
|
cmBehaviorRecord.setRecordID(recordPoList.get(i).getRecordID());
|
|
@@ -298,9 +299,9 @@ public class CmBehaviorRecordServiceImpl implements CmBehaviorRecordService {
|
|
|
|
|
|
@Override
|
|
|
public void setIpAddress(Integer startId, Integer endId) throws IOException {
|
|
|
- List<CmUserPo> list = recordMapper.findList(startId,endId);
|
|
|
+ List<CmUserPo> list = recordMapper.findList(startId, endId);
|
|
|
String region = "";
|
|
|
- for (CmUserPo user: list) {
|
|
|
+ for (CmUserPo user : list) {
|
|
|
try {
|
|
|
// 获取ip所在地
|
|
|
region = recordIp(user.getRegisterIP());
|
|
@@ -319,13 +320,13 @@ public class CmBehaviorRecordServiceImpl implements CmBehaviorRecordService {
|
|
|
Date date = new Date();
|
|
|
Calendar calendar = Calendar.getInstance();
|
|
|
calendar.setTime(date);
|
|
|
- calendar.add(Calendar.DAY_OF_MONTH,-1);
|
|
|
+ calendar.add(Calendar.DAY_OF_MONTH, -1);
|
|
|
Date time = calendar.getTime();
|
|
|
String format = dateFormat.format(time);
|
|
|
// 前一天数据身份中是否只有 机构-游客、供应商-游客
|
|
|
List<CmBehaviorRecordPo> countNumList = recordMapper.countNum(format);
|
|
|
if (countNumList.size() != 0 && countNumList != null) {
|
|
|
- for (CmBehaviorRecordPo countNum: countNumList) {
|
|
|
+ for (CmBehaviorRecordPo countNum : countNumList) {
|
|
|
if (countNum.getCount() == 2) {
|
|
|
// 查询机构/供应商ip、userID,用于调整游客数据
|
|
|
CmBehaviorRecordPo recordPo = recordMapper.userIdAcc(countNum.getIP(), format);
|
|
@@ -350,7 +351,7 @@ public class CmBehaviorRecordServiceImpl implements CmBehaviorRecordService {
|
|
|
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
Calendar calendar = Calendar.getInstance();
|
|
|
calendar.setTime(new Date());
|
|
|
- calendar.add(Calendar.DAY_OF_MONTH,-1);
|
|
|
+ calendar.add(Calendar.DAY_OF_MONTH, -1);
|
|
|
Date time = calendar.getTime();
|
|
|
String format = dateFormat.format(time);
|
|
|
|
|
@@ -400,12 +401,12 @@ public class CmBehaviorRecordServiceImpl implements CmBehaviorRecordService {
|
|
|
int id = 1;
|
|
|
// 所有用户供应商数据
|
|
|
List<CmBehaviorRecordPo> selDataList = recordMapper.selDataList(format);
|
|
|
- for (CmBehaviorRecordPo data: todayData ){
|
|
|
+ for (CmBehaviorRecordPo data : todayData) {
|
|
|
ArrayList<String> item = new ArrayList();
|
|
|
ArrayList<String> shopNames = new ArrayList();
|
|
|
int num = 0;
|
|
|
data.setRecordID(id);
|
|
|
- id ++;
|
|
|
+ id++;
|
|
|
for (CmBehaviorRecordPo recordPo : selDataList) {
|
|
|
if (recordPo.getIP().equals(data.getIP()) && recordPo.getUserId().equals(data.getUserId())) {
|
|
|
// 标签信息
|
|
@@ -436,22 +437,22 @@ public class CmBehaviorRecordServiceImpl implements CmBehaviorRecordService {
|
|
|
String text = "";
|
|
|
String line = "";
|
|
|
String region = "";
|
|
|
- String urlStr = "http://whois.pconline.com.cn/ipJson.jsp?ip="+ip+"&json=true";
|
|
|
+ String urlStr = "http://whois.pconline.com.cn/ipJson.jsp?ip=" + ip + "&json=true";
|
|
|
try {
|
|
|
url = new URL(urlStr);
|
|
|
- connection = (HttpURLConnection) url.openConnection(); //新建链接实例
|
|
|
- connection.setConnectTimeout(20000); //设置链接超时时间,单位毫秒
|
|
|
- connection.setReadTimeout(20000); //设置读取数据超时时间,单位毫秒
|
|
|
- connection.setDoOutput(true); //是否打开输出流true|false
|
|
|
- connection.setDoInput(true); //是否打开输入流true|false
|
|
|
- connection.setRequestMethod("GET"); // 提交方式get|post
|
|
|
- connection.setUseCaches(false); // 是否加入缓存true|false
|
|
|
- connection.connect(); //打开链接端口
|
|
|
+ connection = (HttpURLConnection) url.openConnection(); //新建链接实例
|
|
|
+ connection.setConnectTimeout(20000); //设置链接超时时间,单位毫秒
|
|
|
+ connection.setReadTimeout(20000); //设置读取数据超时时间,单位毫秒
|
|
|
+ connection.setDoOutput(true); //是否打开输出流true|false
|
|
|
+ connection.setDoInput(true); //是否打开输入流true|false
|
|
|
+ connection.setRequestMethod("GET"); // 提交方式get|post
|
|
|
+ connection.setUseCaches(false); // 是否加入缓存true|false
|
|
|
+ connection.connect(); //打开链接端口
|
|
|
|
|
|
- BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream(), encoding)); // 往对端写完数据对端服务器返回数据。以BufferedReader流来读取
|
|
|
+ BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream(), encoding)); // 往对端写完数据对端服务器返回数据。以BufferedReader流来读取
|
|
|
|
|
|
while ((line = reader.readLine()) != null) {
|
|
|
- text += line+"\n";
|
|
|
+ text += line + "\n";
|
|
|
}
|
|
|
reader.close();
|
|
|
|
|
@@ -461,7 +462,7 @@ public class CmBehaviorRecordServiceImpl implements CmBehaviorRecordService {
|
|
|
e.printStackTrace();
|
|
|
} finally {
|
|
|
if (connection != null) {
|
|
|
- connection.disconnect(); //关闭连接
|
|
|
+ connection.disconnect(); //关闭连接
|
|
|
}
|
|
|
}
|
|
|
return region;
|
|
@@ -497,10 +498,11 @@ public class CmBehaviorRecordServiceImpl implements CmBehaviorRecordService {
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
+
|
|
|
private boolean boolReptiles(String userAgent) {
|
|
|
if (userAgent.contains("serpstatbot") || userAgent.contains("spider") || userAgent.contains("Googlebot") || userAgent.contains("bingbot")
|
|
|
- || userAgent.contains("SeznamBot") || userAgent.contains("YisouSpider") || userAgent.contains("petalbot") || userAgent.contains("YandexBot")
|
|
|
- || userAgent.contains("AhrefsBot")) {
|
|
|
+ || userAgent.contains("SeznamBot") || userAgent.contains("YisouSpider") || userAgent.contains("petalbot") || userAgent.contains("YandexBot")
|
|
|
+ || userAgent.contains("AhrefsBot")) {
|
|
|
return true;
|
|
|
}
|
|
|
return false;
|