From 5b0448628766ab268161cd3620440010d8f5328a Mon Sep 17 00:00:00 2001 From: lz <905769775@qq.com> Date: Fri, 8 Jul 2022 21:01:08 +0800 Subject: [PATCH] sugar --- .../atguigu/bean/TradeCourseOrderBean.java | 4 +- .../com/example/sugar/bean/TradeCategory.java | 16 ++ .../com/example/sugar/bean/TradeCourse.java | 16 ++ .../com/example/sugar/bean/TradeReview.java | 16 ++ .../com/example/sugar/bean/TradeSubject.java | 16 ++ .../sugar/controller/CourseController.java | 209 ++++++++++++++++++ .../example/sugar/mapper/CourseMapper.java | 65 ++++++ .../com/example/sugar/mapper/TradeMapper.java | 29 +-- .../example/sugar/service/CourseService.java | 15 ++ .../sugar/service/CourseServiceImpl.java | 39 ++++ .../example/sugar/service/TradeService.java | 2 + 11 files changed, 411 insertions(+), 16 deletions(-) create mode 100644 sugar/src/main/java/com/example/sugar/bean/TradeCategory.java create mode 100644 sugar/src/main/java/com/example/sugar/bean/TradeCourse.java create mode 100644 sugar/src/main/java/com/example/sugar/bean/TradeReview.java create mode 100644 sugar/src/main/java/com/example/sugar/bean/TradeSubject.java create mode 100644 sugar/src/main/java/com/example/sugar/controller/CourseController.java create mode 100644 sugar/src/main/java/com/example/sugar/mapper/CourseMapper.java create mode 100644 sugar/src/main/java/com/example/sugar/service/CourseService.java create mode 100644 sugar/src/main/java/com/example/sugar/service/CourseServiceImpl.java diff --git a/edu/src/main/java/com/atguigu/bean/TradeCourseOrderBean.java b/edu/src/main/java/com/atguigu/bean/TradeCourseOrderBean.java index 469f14d..1c8fd77 100644 --- a/edu/src/main/java/com/atguigu/bean/TradeCourseOrderBean.java +++ b/edu/src/main/java/com/atguigu/bean/TradeCourseOrderBean.java @@ -1,6 +1,6 @@ package com.atguigu.bean; -import com.atguigu.bean.NoSink; +import com.atguigu.annotation.NotSink; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; @@ -35,7 +35,7 @@ public class TradeCourseOrderBean { String categoryName; // 订单 ID - @NoSink + @NotSink @Builder.Default Set orderIdSet = new HashSet<>(); //用户ID diff --git a/sugar/src/main/java/com/example/sugar/bean/TradeCategory.java b/sugar/src/main/java/com/example/sugar/bean/TradeCategory.java new file mode 100644 index 0000000..68f1e44 --- /dev/null +++ b/sugar/src/main/java/com/example/sugar/bean/TradeCategory.java @@ -0,0 +1,16 @@ +package com.example.sugar.bean; + + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +@AllArgsConstructor +public class TradeCategory { + private String category_name; + private long order_count; + private long uu_count; + private double order_amount; +} diff --git a/sugar/src/main/java/com/example/sugar/bean/TradeCourse.java b/sugar/src/main/java/com/example/sugar/bean/TradeCourse.java new file mode 100644 index 0000000..1fb3c50 --- /dev/null +++ b/sugar/src/main/java/com/example/sugar/bean/TradeCourse.java @@ -0,0 +1,16 @@ +package com.example.sugar.bean; + + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +@AllArgsConstructor +public class TradeCourse { + private String course_name; + private long order_count; + private long uu_count; + private double order_amount; +} diff --git a/sugar/src/main/java/com/example/sugar/bean/TradeReview.java b/sugar/src/main/java/com/example/sugar/bean/TradeReview.java new file mode 100644 index 0000000..6b7fc3e --- /dev/null +++ b/sugar/src/main/java/com/example/sugar/bean/TradeReview.java @@ -0,0 +1,16 @@ +package com.example.sugar.bean; + + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +@AllArgsConstructor +public class TradeReview { + private String course_name; + private double avg_score; + private long uu_count; + private double favor_rate; +} diff --git a/sugar/src/main/java/com/example/sugar/bean/TradeSubject.java b/sugar/src/main/java/com/example/sugar/bean/TradeSubject.java new file mode 100644 index 0000000..28dba23 --- /dev/null +++ b/sugar/src/main/java/com/example/sugar/bean/TradeSubject.java @@ -0,0 +1,16 @@ +package com.example.sugar.bean; + + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +@AllArgsConstructor +public class TradeSubject { + private String subject_name; + private long order_count; + private long uu_count; + private double order_amount; +} diff --git a/sugar/src/main/java/com/example/sugar/controller/CourseController.java b/sugar/src/main/java/com/example/sugar/controller/CourseController.java new file mode 100644 index 0000000..fbd8083 --- /dev/null +++ b/sugar/src/main/java/com/example/sugar/controller/CourseController.java @@ -0,0 +1,209 @@ +package com.example.sugar.controller; + +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import com.example.sugar.bean.TradeCourse; +import com.example.sugar.bean.TradeReview; +import com.example.sugar.bean.TradeSubject; +import com.example.sugar.bean.TradeCategory; +import com.example.sugar.service.CourseService; +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 CourseController { + + @Autowired + CourseService courseService; + + @RequestMapping("/sugar/course") + public String tradeCourse(int date) { + + List list = courseService.tradeCourse(date); + + JSONObject result = new JSONObject(); + result.put("status",0); + result.put("msg",""); + + JSONObject data = new JSONObject(); + JSONArray columns = new JSONArray(); + JSONObject name = new JSONObject(); + JSONObject order = new JSONObject(); + JSONObject uu = new JSONObject(); + JSONObject amount = new JSONObject(); + name.put("name", "课程名称"); + name.put("id", "course_name"); + order.put("name", "下单次数"); + order.put("id", "order_count"); + uu.put("name", "下单人数"); + uu.put("id", "uu_count"); + amount.put("name", "下单金额"); + amount.put("id", "order_amount"); + columns.add(name); + columns.add(order); + columns.add(uu); + columns.add(amount); + + data.put("columns", columns); + + JSONArray rows = new JSONArray(); + + for (TradeCourse tc : list) { + JSONObject data1 = new JSONObject(); + rows.add(data1); + data1.put("course_name",tc.getCourse_name()); + data1.put("order_count",tc.getOrder_count()); + data1.put("uu_count",tc.getUu_count()); + data1.put("order_amount",tc.getOrder_amount()); + } + + data.put("rows",rows); + + result.put("data", data); + return result.toJSONString(); + } + + @RequestMapping("/sugar/subject") + public String tradeSubject(int date) { + + List list = courseService.tradeSubject(date); + + JSONObject result = new JSONObject(); + result.put("status", 0); + result.put("msg", ""); + + JSONObject data = new JSONObject(); + JSONArray columns = new JSONArray(); + JSONObject name = new JSONObject(); + JSONObject order = new JSONObject(); + JSONObject uu = new JSONObject(); + JSONObject amount = new JSONObject(); + name.put("name", "学科名称"); + name.put("id", "subject_name"); + order.put("name", "下单次数"); + order.put("id", "order_count"); + uu.put("name", "下单人数"); + uu.put("id", "uu_count"); + amount.put("name", "下单金额"); + amount.put("id", "order_amount"); + columns.add(name); + columns.add(order); + columns.add(uu); + columns.add(amount); + + data.put("columns", columns); + + JSONArray rows = new JSONArray(); + + for (TradeSubject tc : list) { + JSONObject data1 = new JSONObject(); + rows.add(data1); + data1.put("subject_name", tc.getSubject_name()); + data1.put("order_count", tc.getOrder_count()); + data1.put("uu_count", tc.getUu_count()); + data1.put("order_amount", tc.getOrder_amount()); + } + + data.put("rows", rows); + + result.put("data", data); + return result.toJSONString(); + } + + @RequestMapping("/sugar/category") + public String tradeCategory(int date) { + + List list = courseService.tradeCategory(date); + + JSONObject result = new JSONObject(); + result.put("status", 0); + result.put("msg", ""); + + JSONObject data = new JSONObject(); + JSONArray columns = new JSONArray(); + JSONObject name = new JSONObject(); + JSONObject order = new JSONObject(); + JSONObject uu = new JSONObject(); + JSONObject amount = new JSONObject(); + name.put("name", "类别名称"); + name.put("id", "category_name"); + order.put("name", "下单次数"); + order.put("id", "order_count"); + uu.put("name", "下单人数"); + uu.put("id", "uu_count"); + amount.put("name", "下单金额"); + amount.put("id", "order_amount"); + columns.add(name); + columns.add(order); + columns.add(uu); + columns.add(amount); + + data.put("columns", columns); + + JSONArray rows = new JSONArray(); + + for (TradeCategory tc : list) { + JSONObject data1 = new JSONObject(); + rows.add(data1); + data1.put("category_name", tc.getCategory_name()); + data1.put("order_count", tc.getOrder_count()); + data1.put("uu_count", tc.getUu_count()); + data1.put("order_amount", tc.getOrder_amount()); + } + + data.put("rows", rows); + + result.put("data", data); + return result.toJSONString(); + } + + @RequestMapping("/sugar/review") + public String tradeReview(int date) { + + List list = courseService.tradeReview(date); + + JSONObject result = new JSONObject(); + result.put("status", 0); + result.put("msg", ""); + + JSONObject data = new JSONObject(); + JSONArray columns = new JSONArray(); + JSONObject name = new JSONObject(); + JSONObject order = new JSONObject(); + JSONObject uu = new JSONObject(); + JSONObject amount = new JSONObject(); + name.put("name", "课程名称"); + name.put("id", "course_name"); + order.put("name", "用户平均评分"); + order.put("id", "avg_score"); + uu.put("name", "评价用户数"); + uu.put("id", "uu_count"); + amount.put("name", "好评率(百分比)"); + amount.put("id", "favor_rate"); + columns.add(name); + columns.add(order); + columns.add(uu); + columns.add(amount); + + data.put("columns", columns); + + JSONArray rows = new JSONArray(); + + for (TradeReview tc : list) { + JSONObject data1 = new JSONObject(); + rows.add(data1); + data1.put("course_name", tc.getCourse_name()); + data1.put("avg_score", tc.getAvg_score()); + data1.put("uu_count", tc.getUu_count()); + data1.put("favor_rate", tc.getFavor_rate()); + } + + data.put("rows", rows); + + result.put("data", data); + return result.toJSONString(); + } +} \ No newline at end of file diff --git a/sugar/src/main/java/com/example/sugar/mapper/CourseMapper.java b/sugar/src/main/java/com/example/sugar/mapper/CourseMapper.java new file mode 100644 index 0000000..1dc8954 --- /dev/null +++ b/sugar/src/main/java/com/example/sugar/mapper/CourseMapper.java @@ -0,0 +1,65 @@ +package com.example.sugar.mapper; + +import com.example.sugar.bean.TradeCourse; +import com.example.sugar.bean.TradeReview; +import com.example.sugar.bean.TradeSubject; +import com.example.sugar.bean.TradeCategory; +import org.apache.ibatis.annotations.Select; + +import java.util.List; + +public interface CourseMapper { + + @Select("select course_name,\n" + + " sum(order_count) order_count,\n" + + " count(user_id) uu_count,\n" + + " sum(order_amount) order_amount\n" + + "from dws_trade_course_order_window\n" + + "where toYYYYMMDD(stt) = #{date}\n" + + "group by course_id, course_name") + List tradeCourse(int date); + + @Select("select subject_name,\n" + + " sum(order_count) order_count,\n" + + " count(user_id) uu_count,\n" + + " sum(order_amount) order_amount\n" + + "from dws_trade_course_order_window\n" + + "where toYYYYMMDD(stt) = #{date}\n" + + "group by subject_id, subject_name") + List tradeSubject(int date); + + @Select("select category_name,\n" + + " sum(order_count) order_count,\n" + + " count(user_id) uu_count,\n" + + " sum(order_amount) order_amount\n" + + "from dws_trade_course_order_window\n" + + "where toYYYYMMDD(stt) = #{date}\n" + + "group by category_id, category_name") + List tradeCategory(int date); + + @Select("select course_name, \n" + + " round(avg_score,2) avg_score, \n" + + " uu_count, \n" + + " round(favor_user/uu_count*100,2) favor_rate\n" + + " from\n" + + " (select course_name, \n" + + " sum( toInt32(review_stars) )/count(user_id) avg_score, \n" + + " count(user_id) uu_count \n" + + " from \n" + + " dws_interaction_review_window\n" + + " where toYYYYMMDD(stt) = 20220704 \n" + + " group by course_name) t1\n" + + " join\n" + + " (\n" + + " select \n" + + " course_name,\n" + + " count(user_id) favor_user\n" + + " from dws_interaction_review_window\n" + + " where review_stars='5'\n" + + " and toYYYYMMDD(stt) = 20220704\n" + + " group by course_name\n" + + " ) t2\n" + + " on t1.course_name = t2.course_name") + List tradeReview(int date); + +} diff --git a/sugar/src/main/java/com/example/sugar/mapper/TradeMapper.java b/sugar/src/main/java/com/example/sugar/mapper/TradeMapper.java index da9bb10..3b68683 100644 --- a/sugar/src/main/java/com/example/sugar/mapper/TradeMapper.java +++ b/sugar/src/main/java/com/example/sugar/mapper/TradeMapper.java @@ -9,22 +9,23 @@ 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") + " 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") + " 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/CourseService.java b/sugar/src/main/java/com/example/sugar/service/CourseService.java new file mode 100644 index 0000000..2cc3bb2 --- /dev/null +++ b/sugar/src/main/java/com/example/sugar/service/CourseService.java @@ -0,0 +1,15 @@ +package com.example.sugar.service; + +import com.example.sugar.bean.TradeCourse; +import com.example.sugar.bean.TradeReview; +import com.example.sugar.bean.TradeSubject; +import com.example.sugar.bean.TradeCategory; +import java.util.List; + +public interface CourseService { + List tradeCourse(int date); + List tradeSubject(int date); + List tradeCategory(int date); + List tradeReview(int date); + +} diff --git a/sugar/src/main/java/com/example/sugar/service/CourseServiceImpl.java b/sugar/src/main/java/com/example/sugar/service/CourseServiceImpl.java new file mode 100644 index 0000000..5c12781 --- /dev/null +++ b/sugar/src/main/java/com/example/sugar/service/CourseServiceImpl.java @@ -0,0 +1,39 @@ +package com.example.sugar.service; + +import com.example.sugar.bean.TradeCourse; +import com.example.sugar.bean.TradeReview; +import com.example.sugar.bean.TradeSubject; +import com.example.sugar.bean.TradeCategory; +import com.example.sugar.mapper.CourseMapper; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; + +@Service +public class CourseServiceImpl implements CourseService { + + @Autowired + CourseMapper courseMapper; + + @Override + public List tradeCourse(int date) { + return courseMapper.tradeCourse(date); + } + + @Override + public List tradeSubject(int date) { + return courseMapper.tradeSubject(date); + } + + @Override + public List tradeCategory(int date) { + return courseMapper.tradeCategory(date); + } + + @Override + public List tradeReview(int date) { + return courseMapper.tradeReview(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 index 15ff42a..cda5d40 100644 --- a/sugar/src/main/java/com/example/sugar/service/TradeService.java +++ b/sugar/src/main/java/com/example/sugar/service/TradeService.java @@ -11,4 +11,6 @@ public interface TradeService { List statsTrafficVisitorTypeStats(int date); List statsKw(int date); + + } -- Gitee