From d716bb81655ba81e54515c30eec91a7386f3a393 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cno-bug-is-great=E2=80=9D?= <“804257656@qq.com> Date: Thu, 7 Jul 2022 16:36:29 +0800 Subject: [PATCH] ads_keyword --- .../com/example/sugar/SugarApplication.java | 2 + .../main/java/com/example/sugar/bean/Kw.java | 14 +++++ .../sugar/bean/TrafficVisitorTypeStats.java | 44 ++++++++++++++++ .../example/sugar/controller/Controller.java | 16 ------ .../sugar/controller/SugarController.java | 51 +++++++++++++++++++ .../com/example/sugar/mapper/TradeMapper.java | 30 +++++++++++ .../example/sugar/service/TradeService.java | 14 +++++ .../sugar/service/TradeServiceImpl.java | 28 ++++++++++ 8 files changed, 183 insertions(+), 16 deletions(-) create mode 100644 sugar/src/main/java/com/example/sugar/bean/Kw.java create mode 100644 sugar/src/main/java/com/example/sugar/bean/TrafficVisitorTypeStats.java delete mode 100644 sugar/src/main/java/com/example/sugar/controller/Controller.java create mode 100644 sugar/src/main/java/com/example/sugar/controller/SugarController.java create mode 100644 sugar/src/main/java/com/example/sugar/mapper/TradeMapper.java create mode 100644 sugar/src/main/java/com/example/sugar/service/TradeService.java create mode 100644 sugar/src/main/java/com/example/sugar/service/TradeServiceImpl.java diff --git a/sugar/src/main/java/com/example/sugar/SugarApplication.java b/sugar/src/main/java/com/example/sugar/SugarApplication.java index d5df8bb..55d1d0d 100644 --- a/sugar/src/main/java/com/example/sugar/SugarApplication.java +++ b/sugar/src/main/java/com/example/sugar/SugarApplication.java @@ -1,9 +1,11 @@ package com.example.sugar; +import org.mybatis.spring.annotation.MapperScan; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication +@MapperScan(basePackages = "com.example.sugar.mapper") public class SugarApplication { public static void main(String[] args) { diff --git a/sugar/src/main/java/com/example/sugar/bean/Kw.java b/sugar/src/main/java/com/example/sugar/bean/Kw.java new file mode 100644 index 0000000..23ae65a --- /dev/null +++ b/sugar/src/main/java/com/example/sugar/bean/Kw.java @@ -0,0 +1,14 @@ +package com.example.sugar.bean; + + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +@AllArgsConstructor +public class Kw { + private String keyword; + private long score; +} diff --git a/sugar/src/main/java/com/example/sugar/bean/TrafficVisitorTypeStats.java b/sugar/src/main/java/com/example/sugar/bean/TrafficVisitorTypeStats.java new file mode 100644 index 0000000..01d689f --- /dev/null +++ b/sugar/src/main/java/com/example/sugar/bean/TrafficVisitorTypeStats.java @@ -0,0 +1,44 @@ +package com.example.sugar.bean; + +import lombok.AllArgsConstructor; +import lombok.Data; + +@Data +@AllArgsConstructor +public class TrafficVisitorTypeStats { + // 新老访客状态标记 + String isNew; + // 独立访客数 + Long uvCt; + // 页面浏览数 + Long pvCt; + // 会话数 + Long svCt; + // 跳出会话数 + Long ujCt; + // 累计访问时长 + Long durSum; + // 跳出率 + public Double getUjRate(){ + if(svCt == 0) { + return 0.0; + } + return (double)ujCt/(double)svCt; + } + // 会话平均在线时长(秒) + public Double getAvgDurSum() { + if(svCt == 0) { + return 0.0; + } + return (double)durSum/(double) svCt / 1000; + } + // 会话平均访问页面数 + public Double getAvgPvCt(){ + if(svCt == 0) { + return 0.0; + } + return (double)pvCt / (double) svCt; + } + + +} diff --git a/sugar/src/main/java/com/example/sugar/controller/Controller.java b/sugar/src/main/java/com/example/sugar/controller/Controller.java deleted file mode 100644 index 1c0d948..0000000 --- a/sugar/src/main/java/com/example/sugar/controller/Controller.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.example.sugar.controller; - -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - - -@RestController -public class Controller { - - @RequestMapping("/sugar/gmv") - public String gmv(int date) { - System.out.println(date); - - return "ok"; - } -} \ No newline at end of file diff --git a/sugar/src/main/java/com/example/sugar/controller/SugarController.java b/sugar/src/main/java/com/example/sugar/controller/SugarController.java new file mode 100644 index 0000000..78345a7 --- /dev/null +++ b/sugar/src/main/java/com/example/sugar/controller/SugarController.java @@ -0,0 +1,51 @@ +package com.example.sugar.controller; + +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import com.example.sugar.bean.Kw; +import com.example.sugar.service.TradeService; +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 +public class SugarController { + + // 会自动创建这个类的对象 + @Autowired + TradeService tradeService; + + @RequestMapping("/sugar/gmv") + public String gmv(int date) { + System.out.println(date); + + return "ok"; + } + + @RequestMapping("/sugar/kw") + public String kw(int date) { + System.out.println(date); + + List list = tradeService.statsKw(date); + + JSONObject result = new JSONObject(); + result.put("status",0); + result.put("msg",""); + + JSONArray data = new JSONArray(); + + for (Kw kw : list) { + JSONObject obj = new JSONObject(); + obj.put("name",kw.getKeyword()); + obj.put("value",kw.getScore()); + + data.add(obj); + } + + result.put("data",data); + return result.toJSONString(); + } +} \ No newline at end of file diff --git a/sugar/src/main/java/com/example/sugar/mapper/TradeMapper.java b/sugar/src/main/java/com/example/sugar/mapper/TradeMapper.java new file mode 100644 index 0000000..da9bb10 --- /dev/null +++ b/sugar/src/main/java/com/example/sugar/mapper/TradeMapper.java @@ -0,0 +1,30 @@ +package com.example.sugar.mapper; + +import com.example.sugar.bean.Kw; +import com.example.sugar.bean.TrafficVisitorTypeStats; +import org.apache.ibatis.annotations.Select; + +import java.util.List; + +public interface TradeMapper { + + @Select("SELECT \n" + + " keyword,\n" + + " sum(keyword_count)\n" + + "FROM dws_traffic_source_keyword_page_view_window\n" + + "WHERE toYYYYMMDD(stt) = #{date}\n" + + "GROUP BY keyword") + List statsKw(int date); + + @Select("SELECT \n" + + " is_new,\n" + + " sum(uv_ct) AS uv_ct,\n" + + " sum(pv_ct) AS pv_ct,\n" + + " sum(sv_ct) AS sv_ct,\n" + + " sum(uj_ct) AS uj_ct,\n" + + " sum(dur_sum) AS dur_sum\n" + + "FROM dws_traffic_rc_vc_ch_ar_is_new_page_view_window\n" + + "WHERE toYYYYMMDD(stt) = #{date}\n" + + "GROUP BY is_new") + List statsTrafficVisitorTypeStats(int date); +} diff --git a/sugar/src/main/java/com/example/sugar/service/TradeService.java b/sugar/src/main/java/com/example/sugar/service/TradeService.java new file mode 100644 index 0000000..15ff42a --- /dev/null +++ b/sugar/src/main/java/com/example/sugar/service/TradeService.java @@ -0,0 +1,14 @@ +package com.example.sugar.service; + +import com.example.sugar.bean.Kw; +import com.example.sugar.bean.TrafficVisitorTypeStats; + +import java.util.List; + +public interface TradeService { + //Double gmv(int date); + + + List statsTrafficVisitorTypeStats(int date); + List statsKw(int date); +} diff --git a/sugar/src/main/java/com/example/sugar/service/TradeServiceImpl.java b/sugar/src/main/java/com/example/sugar/service/TradeServiceImpl.java new file mode 100644 index 0000000..4de9f78 --- /dev/null +++ b/sugar/src/main/java/com/example/sugar/service/TradeServiceImpl.java @@ -0,0 +1,28 @@ +package com.example.sugar.service; + +import com.example.sugar.bean.Kw; +import com.example.sugar.bean.TrafficVisitorTypeStats; +import com.example.sugar.mapper.TradeMapper; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; + +@Service +public class TradeServiceImpl implements TradeService { + + @Autowired + TradeMapper tradeMapper; + + @Override + public List statsTrafficVisitorTypeStats(int date) { + return tradeMapper.statsTrafficVisitorTypeStats(date); + } + + @Override + public List statsKw(int date) { + return tradeMapper.statsKw(date); + } + + +} -- Gitee