diff --git a/sugar/src/main/java/com/example/sugar/bean/TrafficDurPerSession.java b/sugar/src/main/java/com/example/sugar/bean/TrafficDurPerSession.java new file mode 100644 index 0000000000000000000000000000000000000000..866e81284e2d8c8cbaa6f91640da1837a2af3cb9 --- /dev/null +++ b/sugar/src/main/java/com/example/sugar/bean/TrafficDurPerSession.java @@ -0,0 +1,18 @@ +package com.example.sugar.bean; + +import lombok.AllArgsConstructor; +import lombok.Data; + +@Data +@AllArgsConstructor +public class TrafficDurPerSession { + // 来源 + String sc; + // 来源网站 + String sourceSite; + // 来源网址 + String sourceUrl; + + // 各会话页面访问时长 + Double durPerSession; +} \ No newline at end of file diff --git a/sugar/src/main/java/com/example/sugar/bean/TrafficPvPerSession.java b/sugar/src/main/java/com/example/sugar/bean/TrafficPvPerSession.java new file mode 100644 index 0000000000000000000000000000000000000000..af8fee8b211923cef97eddf9e2aa778fd1829057 --- /dev/null +++ b/sugar/src/main/java/com/example/sugar/bean/TrafficPvPerSession.java @@ -0,0 +1,19 @@ +package com.example.sugar.bean; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@AllArgsConstructor +public class TrafficPvPerSession { + // 来源 + String sc; + // 来源网站 + String sourceSite; + // 来源网址 + String sourceUrl; + + // 各会话页面浏览数 + Double pvPerSession; +} \ No newline at end of file diff --git a/sugar/src/main/java/com/example/sugar/bean/TrafficSvCt.java b/sugar/src/main/java/com/example/sugar/bean/TrafficSvCt.java new file mode 100644 index 0000000000000000000000000000000000000000..bb9ba51ff8bc81fa3f2e38614bbb554890d7abf4 --- /dev/null +++ b/sugar/src/main/java/com/example/sugar/bean/TrafficSvCt.java @@ -0,0 +1,19 @@ +package com.example.sugar.bean; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@AllArgsConstructor +public class TrafficSvCt { + // 来源 + String sc; + // 来源网站 + String sourceSite; + // 来源网址 + String sourceUrl; + + // 会话数 + Integer svCt; +} \ No newline at end of file diff --git a/sugar/src/main/java/com/example/sugar/bean/TrafficUjRate.java b/sugar/src/main/java/com/example/sugar/bean/TrafficUjRate.java new file mode 100644 index 0000000000000000000000000000000000000000..8c74e2574be6ee48d9f3738e2b95e950e3076c21 --- /dev/null +++ b/sugar/src/main/java/com/example/sugar/bean/TrafficUjRate.java @@ -0,0 +1,18 @@ +package com.example.sugar.bean; + +import lombok.AllArgsConstructor; +import lombok.Data; + +@Data +@AllArgsConstructor +public class TrafficUjRate { + // 来源 + String sc; + // 来源网站 + String sourceSite; + // 来源网址 + String sourceUrl; + + // 跳出率 + Double ujRate; +} \ No newline at end of file diff --git a/sugar/src/main/java/com/example/sugar/bean/TrafficUvCt.java b/sugar/src/main/java/com/example/sugar/bean/TrafficUvCt.java new file mode 100644 index 0000000000000000000000000000000000000000..34f602595dc3b1232867762338ad1f5a3f6b1b87 --- /dev/null +++ b/sugar/src/main/java/com/example/sugar/bean/TrafficUvCt.java @@ -0,0 +1,19 @@ +package com.example.sugar.bean; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@AllArgsConstructor +public class TrafficUvCt { + // 来源 + String sc; + // 来源网站 + String sourceSite; + // 来源网址 + String sourceUrl; + + // 独立访客数 + Integer uvCt; +} \ No newline at end of file diff --git a/sugar/src/main/java/com/example/sugar/bean/TrafficVisitorStatsPerHour.java b/sugar/src/main/java/com/example/sugar/bean/TrafficVisitorStatsPerHour.java new file mode 100644 index 0000000000000000000000000000000000000000..3e9c26890101ceeb2be5e55776905099bf55970b --- /dev/null +++ b/sugar/src/main/java/com/example/sugar/bean/TrafficVisitorStatsPerHour.java @@ -0,0 +1,17 @@ +package com.example.sugar.bean; + +import lombok.AllArgsConstructor; +import lombok.Data; + +@Data +@AllArgsConstructor +public class TrafficVisitorStatsPerHour { + // 小时 + Integer hr; + // 独立访客数 + Long uvCt; + // 页面浏览数 + Long pvCt; + // 会话平均浏览页面数 + Double pvPerSession; +} \ No newline at end of file diff --git a/sugar/src/main/java/com/example/sugar/controller/TrafficController.java b/sugar/src/main/java/com/example/sugar/controller/TrafficController.java new file mode 100644 index 0000000000000000000000000000000000000000..089589e8927496906f91e17f80b93e240d307c4b --- /dev/null +++ b/sugar/src/main/java/com/example/sugar/controller/TrafficController.java @@ -0,0 +1,240 @@ +package com.example.sugar.controller; + +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import com.example.sugar.bean.*; +import com.example.sugar.service.TrafficSourceStatsService; +import com.example.sugar.service.TrafficVisitorStatsService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; + +@RestController +@RequestMapping("/sugar/traffic") +public class TrafficController { + + // 自动装载渠道流量统计服务实现类 + @Autowired + private TrafficSourceStatsService trafficSourceStatsService; + // 自动装载访客状态统计服务实现类 + @Autowired + private TrafficVisitorStatsService trafficVisitorStatsService; + + // 访客状态分时统计请求拦截方法 + @RequestMapping("/visitorPerHr") + public String getVisitorPerHr(int date) { + JSONObject result = new JSONObject(); + List<TrafficVisitorStatsPerHour> list = trafficVisitorStatsService.getVisitorPerHrStats(date); + result.put("status", 0); + result.put("msg", ""); + JSONObject data = new JSONObject(); + JSONArray categories = new JSONArray(); + JSONArray series = new JSONArray(); + + JSONObject one = new JSONObject(); + one.put("name", "独立访客数"); + JSONArray data1 = new JSONArray(); + + JSONObject two = new JSONObject(); + two.put("name", "页面浏览数"); + JSONArray data2 = new JSONArray(); + + JSONObject three = new JSONObject(); + three.put("name", "会话平均浏览页面数"); + JSONArray data3 = new JSONArray(); + + for (TrafficVisitorStatsPerHour visitorStatsPerHour : list) { + categories.add(visitorStatsPerHour.getHr()); + data1.add(visitorStatsPerHour.getUvCt()); + data2.add(visitorStatsPerHour.getPvCt()); + data3.add(visitorStatsPerHour.getPvPerSession()); + } + + one.put("data", data1); + two.put("data", data2); + three.put("data", data3); + + series.add(one); + series.add(two); + series.add(three); + + data.put("categories", categories); + data.put("series", series); + + result.put("data", data); + return result.toJSONString(); + } + + + // 1. 独立访客请求拦截方法 + @RequestMapping("/uvCt") + public String getUvCt(int date) { + + List<TrafficUvCt> trafficUvCtList = trafficSourceStatsService.getUvCt(date); + + JSONObject result = new JSONObject(); + result.put("status", 0); + result.put("msg", ""); + + JSONObject data = new JSONObject(); + JSONArray categories = new JSONArray(); + JSONArray data1 = new JSONArray(); + for (TrafficUvCt trafficUvCt : trafficUvCtList) { + categories.add(trafficUvCt.getSourceSite()); + data1.add(trafficUvCt.getUvCt()); + } + data.put("categories", categories); + + JSONArray series = new JSONArray(); + JSONObject one = new JSONObject(); + + one.put("name", "独立访客数"); + one.put("data", data1); + + series.add(one); + + data.put("series",series); + + result.put("data", data); + return result.toJSONString(); + } + + // 2. 会话数请求拦截方法 + @RequestMapping("/svCt") + public String getPvCt(int date) { + List<TrafficSvCt> svCtList = trafficSourceStatsService.getSvCt(date); + + JSONObject result = new JSONObject(); + result.put("status", 0); + result.put("msg", ""); + + JSONObject data = new JSONObject(); + JSONArray categories = new JSONArray(); + JSONArray data1 = new JSONArray(); + + for (TrafficSvCt svCt : svCtList) { + categories.add(svCt.getSourceSite()); + data1.add(svCt.getSvCt()); + } + + data.put("categories", categories); + + JSONArray series = new JSONArray(); + JSONObject one = new JSONObject(); + series.add(one); + + one.put("name", "会话数"); + one.put("data", data1); + + data.put("series",series); + + result.put("data", data); + return result.toJSONString(); + } + + // 3. 各会话浏览页面数请求拦截方法 + @RequestMapping("/pvPerSession") + public String getPvPerSession(int date) { + + List<TrafficPvPerSession> list = trafficSourceStatsService.getPvPerSession(date); + + JSONObject result = new JSONObject(); + result.put("status", 0); + result.put("msg", ""); + + JSONObject data = new JSONObject(); + JSONArray categories = new JSONArray(); + JSONArray data1 = new JSONArray(); + for (TrafficPvPerSession pvPerSession : list) { + categories.add(pvPerSession.getSourceSite()); + data1.add(pvPerSession.getPvPerSession()); + } + + data.put("categories", categories); + + JSONArray series = new JSONArray(); + JSONObject one = new JSONObject(); + + one.put("name", "会话平均页面浏览数"); + one.put("data", data1); + + series.add(one); + + data.put("series",series); + + result.put("data", data); + return result.toJSONString(); + } + + // 4. 各会话累计访问时长请求拦截方法 + @RequestMapping("/durPerSession") + public String getDurPerSession(int date) { + + List<TrafficDurPerSession> list = trafficSourceStatsService.getDurPerSession(date); + + JSONObject result = new JSONObject(); + result.put("status", 0); + result.put("msg", ""); + + JSONObject data = new JSONObject(); + JSONArray categories = new JSONArray(); + JSONArray data1 = new JSONArray(); + for (TrafficDurPerSession durPerSession : list) { + categories.add(durPerSession.getSourceSite()); + data1.add(durPerSession.getDurPerSession()); + } + + data.put("categories", categories); + + JSONArray series = new JSONArray(); + JSONObject one = new JSONObject(); + + one.put("name", "会话平均页面访问时长"); + one.put("data", data1); + + series.add(one); + + data.put("series",series); + + result.put("data", data); + return result.toJSONString(); + } + + @RequestMapping("/ujRate") + public String getUjRate(int date) { + + List<TrafficUjRate> list = trafficSourceStatsService.getUjRate(date); + + JSONObject result = new JSONObject(); + result.put("status", 0); + result.put("msg", ""); + + JSONObject data = new JSONObject(); + JSONArray categories = new JSONArray(); + JSONArray data1 = new JSONArray(); + + for (TrafficUjRate ujRate : list) { + categories.add(ujRate.getSourceSite()); + data1.add(ujRate.getUjRate()); + } + + data.put("categories", categories); + + JSONArray series = new JSONArray(); + JSONObject one = new JSONObject(); + + one.put("name", "跳出率"); + one.put("data", data1); + + series.add(one); + + data.put("series",series); + + result.put("data", data); + return result.toJSONString(); + } + + +} \ No newline at end of file diff --git a/sugar/src/main/java/com/example/sugar/mapper/TrafficSourceStatsMapper.java b/sugar/src/main/java/com/example/sugar/mapper/TrafficSourceStatsMapper.java new file mode 100644 index 0000000000000000000000000000000000000000..144442ab23556046d60034d425686c44d2a392e5 --- /dev/null +++ b/sugar/src/main/java/com/example/sugar/mapper/TrafficSourceStatsMapper.java @@ -0,0 +1,69 @@ +package com.example.sugar.mapper; + +import com.example.sugar.bean.*; +import org.apache.ibatis.annotations.Param; +import org.apache.ibatis.annotations.Select; + +import java.util.List; + +public interface TrafficSourceStatsMapper { + // 1. 获取各来源独立访客数 + @Select("select sc, \n" + + " source_site, \n" + + " source_url, \n" + + " sum(uv_ct) uv_ct \n" + + "from dws_traffic_rc_vc_ch_ar_is_new_page_view_window \n" + + "where toYYYYMMDD(stt) = #{date} \n" + + "group by toYYYYMMDD(stt), sc,source_site,source_url \n" + + "order by uv_ct desc") + List<TrafficUvCt> selectUvCt(@Param("date")Integer date); + + // 2. 获取各来源会话数 + @Select("SELECT\n" + + " sc,\n" + + " source_site,\n" + + " source_url,\n" + + " sum(sv_ct) AS sv_ct\n" + + "FROM dws_traffic_rc_vc_ch_ar_is_new_page_view_window\n" + + "WHERE toYYYYMMDD(stt) = #{date}\n" + + "GROUP BY\n" + + " toYYYYMMDD(stt),\n" + + " sc,\n" + + " source_site,\n" + + " source_url\n" + + "ORDER BY sv_ct DESC") + List<TrafficSvCt> selectSvCt(@Param("date")Integer date); + + // 3. 获取各来源会话平均页面浏览数 + @Select("select sc,\n" + + " source_site," + + " source_url," + + " sum(pv_ct) / sum(sv_ct) pv_per_session\n" + + "from dws_traffic_rc_vc_ch_ar_is_new_page_view_window\n" + + "where toYYYYMMDD(stt) = #{date}\n" + + "group by toYYYYMMDD(stt), sc, source_site,source_url\n" + + "order by pv_per_session desc") + List<TrafficPvPerSession> selectPvPerSession(@Param("date")Integer date); + + // 4. 获取各来源会话平均页面访问时长 + @Select("select sc,\n" + + " source_site," + + " source_url," + + " sum(dur_sum) / sum(sv_ct) dur_per_session\n" + + "from dws_traffic_rc_vc_ch_ar_is_new_page_view_window\n" + + "where toYYYYMMDD(stt) = #{date}\n" + + "group by toYYYYMMDD(stt), sc, source_site,source_url\n" + + "order by dur_per_session desc") + List<TrafficDurPerSession> selectDurPerSession(@Param("date")Integer date); + + // 5. 获取各来源跳出率 + @Select("select sc,\n" + + " source_site," + + " source_url," + + " sum(uj_ct) / sum(sv_ct) uj_rate\n" + + "from dws_traffic_rc_vc_ch_ar_is_new_page_view_window\n" + + "where toYYYYMMDD(stt) = #{date}\n" + + "group by toYYYYMMDD(stt), sc, source_site,source_url\n" + + "order by uj_rate desc") + List<TrafficUjRate> selectUjRate(@Param("date")Integer date); +} \ No newline at end of file diff --git a/sugar/src/main/java/com/example/sugar/mapper/TrafficVisitorStatsMapper.java b/sugar/src/main/java/com/example/sugar/mapper/TrafficVisitorStatsMapper.java new file mode 100644 index 0000000000000000000000000000000000000000..9373f6070d8b53c5a9e70debbc6d056133192159 --- /dev/null +++ b/sugar/src/main/java/com/example/sugar/mapper/TrafficVisitorStatsMapper.java @@ -0,0 +1,28 @@ +package com.example.sugar.mapper; + +import com.example.sugar.bean.TrafficVisitorStatsPerHour; +import org.apache.ibatis.annotations.Select; + +import java.util.List; + +public interface TrafficVisitorStatsMapper { + +// 分时流量数据查询 + @Select("SELECT\n" + + " t1.hr,\n" + + " sum(t1.uv_ct) AS uv_ct,\n" + + " sum(t1.pv_ct) AS pv_ct,\n" + + " sum(t1.pv_ct) / sum(t1.sv_ct) AS pv_per_session\n" + + "FROM\n" + + "(\n" + + " SELECT\n" + + " toHour(stt) AS hr,\n" + + " uv_ct,\n" + + " pv_ct,\n" + + " sv_ct\n" + + " FROM dws_traffic_rc_vc_ch_ar_is_new_page_view_window\n" + + " WHERE toYYYYMMDD(stt) = #{date}\n" + + ") AS t1\n" + + "GROUP BY t1.hr") + List<TrafficVisitorStatsPerHour> selectVisitorStatsPerHr(Integer date); +} \ No newline at end of file diff --git a/sugar/src/main/java/com/example/sugar/service/TrafficSourceStatsService.java b/sugar/src/main/java/com/example/sugar/service/TrafficSourceStatsService.java new file mode 100644 index 0000000000000000000000000000000000000000..aaf1ccbda62f098837402876edce585a39ae8e5c --- /dev/null +++ b/sugar/src/main/java/com/example/sugar/service/TrafficSourceStatsService.java @@ -0,0 +1,22 @@ +package com.example.sugar.service; + +import com.example.sugar.bean.*; + +import java.util.List; + +public interface TrafficSourceStatsService { + // 1. 获取各渠道独立访客数 + List<TrafficUvCt> getUvCt(Integer date); + + // 2. 获取各渠道会话数 + List<TrafficSvCt> getSvCt(Integer date); + + // 3. 获取各渠道会话平均页面浏览数 + List<TrafficPvPerSession> getPvPerSession(Integer date); + + // 4. 获取各渠道会话平均页面访问时长 + List<TrafficDurPerSession> getDurPerSession(Integer date); + + // 5. 获取各渠道跳出率 + List<TrafficUjRate> getUjRate(Integer date); +} \ No newline at end of file diff --git a/sugar/src/main/java/com/example/sugar/service/TrafficSourceStatsServiceImpl.java b/sugar/src/main/java/com/example/sugar/service/TrafficSourceStatsServiceImpl.java new file mode 100644 index 0000000000000000000000000000000000000000..e389fa007570ce610125a15e6369f5cc7af35f38 --- /dev/null +++ b/sugar/src/main/java/com/example/sugar/service/TrafficSourceStatsServiceImpl.java @@ -0,0 +1,47 @@ +package com.example.sugar.service; + + +import com.example.sugar.bean.*; +import com.example.sugar.mapper.TrafficSourceStatsMapper; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; + +@Service +public class TrafficSourceStatsServiceImpl implements TrafficSourceStatsService { + + // 自动装载 Mapper 接口实现类 + @Autowired + TrafficSourceStatsMapper trafficSourceStatsMapper; + + // 1. 获取各来源独立访客数 + @Override + public List<TrafficUvCt> getUvCt(Integer date) { + return trafficSourceStatsMapper.selectUvCt(date); +} + + // 2. 获取各来源会话数 + @Override + public List<TrafficSvCt> getSvCt(Integer date) { + return trafficSourceStatsMapper.selectSvCt(date); + } + + // 3. 获取各来源会话平均页面浏览数 + @Override + public List<TrafficPvPerSession> getPvPerSession(Integer date) { + return trafficSourceStatsMapper.selectPvPerSession(date); + } + + // 4. 获取各来源会话平均页面访问时长 + @Override + public List<TrafficDurPerSession> getDurPerSession(Integer date) { + return trafficSourceStatsMapper.selectDurPerSession(date); + } + + // 5. 获取各来源跳出率 + @Override + public List<TrafficUjRate> getUjRate(Integer date) { + return trafficSourceStatsMapper.selectUjRate(date); + } +} \ No newline at end of file diff --git a/sugar/src/main/java/com/example/sugar/service/TrafficVisitorStatsService.java b/sugar/src/main/java/com/example/sugar/service/TrafficVisitorStatsService.java new file mode 100644 index 0000000000000000000000000000000000000000..69e3c8344cb3cd8a194c212b8a889e38435e613f --- /dev/null +++ b/sugar/src/main/java/com/example/sugar/service/TrafficVisitorStatsService.java @@ -0,0 +1,10 @@ +package com.example.sugar.service; + +import com.example.sugar.bean.TrafficVisitorStatsPerHour; + +import java.util.List; + +public interface TrafficVisitorStatsService { + // 获取分时流量数据 + List<TrafficVisitorStatsPerHour> getVisitorPerHrStats(Integer date); +} \ No newline at end of file diff --git a/sugar/src/main/java/com/example/sugar/service/TrafficVisitorStatsServiceImpl.java b/sugar/src/main/java/com/example/sugar/service/TrafficVisitorStatsServiceImpl.java new file mode 100644 index 0000000000000000000000000000000000000000..13b644cd6610f6d2022491ae2df91e66ecfdf4b6 --- /dev/null +++ b/sugar/src/main/java/com/example/sugar/service/TrafficVisitorStatsServiceImpl.java @@ -0,0 +1,21 @@ +package com.example.sugar.service; + +import com.example.sugar.bean.TrafficVisitorStatsPerHour; +import com.example.sugar.mapper.TrafficVisitorStatsMapper; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; + +@Service +public class TrafficVisitorStatsServiceImpl implements TrafficVisitorStatsService { + + @Autowired + private TrafficVisitorStatsMapper trafficVisitorStatsMapper; + + // 获取分时流量统计数据 + @Override + public List<TrafficVisitorStatsPerHour> getVisitorPerHrStats(Integer date) { + return trafficVisitorStatsMapper.selectVisitorStatsPerHr(date); + } +} \ No newline at end of file