|
@@ -0,0 +1,138 @@
|
|
|
+package com.caimei365.tools.service.impl;
|
|
|
+
|
|
|
+import com.caimei365.tools.mapper.CmBehaviorRecordMapper;
|
|
|
+import com.caimei365.tools.model.po.CmBehaviorRecordPo;
|
|
|
+import com.caimei365.tools.model.po.IpSavePo;
|
|
|
+import com.caimei365.tools.service.CmBehaviorRecordService;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.lang.StringUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.io.UnsupportedEncodingException;
|
|
|
+import java.net.URLDecoder;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.TimeZone;
|
|
|
+
|
|
|
+/**
|
|
|
+ * Description
|
|
|
+ *
|
|
|
+ * @author : Charles
|
|
|
+ * @date : 2022/11/2
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+@Service
|
|
|
+public class CmBehaviorRecordServiceImpl implements CmBehaviorRecordService {
|
|
|
+
|
|
|
+ @Autowired private CmBehaviorRecordMapper recordMapper;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void insertRecord(IpSavePo ipSavePo) {
|
|
|
+ if ("/user/record/StatisticsPc".equals(ipSavePo.getRequestUrl().trim()) || "/user/record/StatisticsApp".equals(ipSavePo.getRequestUrl().trim())) {
|
|
|
+ log.info("用户行为记录=================》" + ipSavePo.getIp());
|
|
|
+ CmBehaviorRecordPo cmBehaviorRecordPo = new CmBehaviorRecordPo();
|
|
|
+ cmBehaviorRecordPo.setIp(ipSavePo.getIp());
|
|
|
+ if (StringUtils.isNotBlank(ipSavePo.getUserId())) {
|
|
|
+ cmBehaviorRecordPo.setUserId(ipSavePo.getUserId());
|
|
|
+ } else {
|
|
|
+ cmBehaviorRecordPo.setUserId("0");
|
|
|
+ }
|
|
|
+ if (ipSavePo.getParams().contains("userId") || ipSavePo.getParams().contains("productId")) {
|
|
|
+ String[] split = ipSavePo.getParams().split("&");
|
|
|
+ for (String s : split) {
|
|
|
+ // 页面路径
|
|
|
+ if (s.contains("pagePath") && s.contains("=")) {
|
|
|
+ String[] split1 = s.split("=");
|
|
|
+ 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");
|
|
|
+ if (decode.contains("%")) {
|
|
|
+ decode = java.net.URLDecoder.decode(decode, "UTF-8");
|
|
|
+ }
|
|
|
+ } catch (UnsupportedEncodingException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ cmBehaviorRecordPo.setPagePath(decode);
|
|
|
+ }
|
|
|
+ if (StringUtils.isEmpty(cmBehaviorRecordPo.getPagePath())) {
|
|
|
+ log.info("页面路径pagePath 值为====》" + trim);
|
|
|
+ return ;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 页面类型
|
|
|
+ if (s.contains("pageType") && s.contains("=")) {
|
|
|
+ String[] split1 = s.split("=");
|
|
|
+ if (split1.length > 1) {
|
|
|
+ String value = split1[1];
|
|
|
+ String trim = value.trim();
|
|
|
+ if (StringUtils.isNotBlank(trim)) {
|
|
|
+ int parseInt = Integer.parseInt(trim);
|
|
|
+
|
|
|
+ cmBehaviorRecordPo.setPageType(parseInt);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 页面标签
|
|
|
+ if (s.contains("pageLabel") && s.contains("=")) {
|
|
|
+ String[] split1 = s.split("=");
|
|
|
+ cmBehaviorRecordPo.setPageLabel("");
|
|
|
+ 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");
|
|
|
+ if (decode.contains("%")) {
|
|
|
+ decode = java.net.URLDecoder.decode(decode, "UTF-8");
|
|
|
+ }
|
|
|
+ } catch (UnsupportedEncodingException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ cmBehaviorRecordPo.setPageLabel(decode);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 商品ID
|
|
|
+ if (s.contains("productId") && s.contains("=")) {
|
|
|
+ String[] split1 = s.split("=");
|
|
|
+ if (split1.length > 1) {
|
|
|
+ String value = split1[1];
|
|
|
+ String trim = value.trim();
|
|
|
+ if (StringUtils.isNotBlank(trim)) {
|
|
|
+ cmBehaviorRecordPo.setProductId(trim);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 访问时长
|
|
|
+ if (s.contains("accessDuration") && s.contains("=")) {
|
|
|
+ String[] split1 = s.split("=");
|
|
|
+ if (split1.length > 1) {
|
|
|
+ String value = split1[1];
|
|
|
+ String trim = value.trim();
|
|
|
+ if (StringUtils.isNotBlank(trim)) {
|
|
|
+ cmBehaviorRecordPo.setAccessDuration(trim);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ Date date = new Date();
|
|
|
+ cmBehaviorRecordPo.setAccessTime(date);
|
|
|
+
|
|
|
+ SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+ String format = simpleDateFormat.format(date);
|
|
|
+ cmBehaviorRecordPo.setAccessDate(format);
|
|
|
+ recordMapper.insertRecord(cmBehaviorRecordPo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|