Forráskód Böngészése

电影总票房数据

jacksenma 7 éve
szülő
commit
da99d5d2e6

+ 6 - 0
src/main/java/com/example/cinema/bl/StatisticsService.java

@@ -15,4 +15,10 @@ public interface StatisticsService {
      * @return
      */
     ResponseVO getScheduleRateByDate(Date date);
+
+    /**
+     * 获取所有电影的累计票房(降序排序,且包含已下架的电影)
+     * @return
+     */
+    ResponseVO getTotalBoxOffice();
 }

+ 10 - 0
src/main/java/com/example/cinema/blImpl/StatisticsServiceImpl.java

@@ -41,6 +41,16 @@ public class StatisticsServiceImpl implements StatisticsService {
         }
     }
 
+    @Override
+    public ResponseVO getTotalBoxOffice() {
+        try {
+            return ResponseVO.buildSuccess(statisticsMapper.selectMovieTotalBoxOffice());
+        }catch (Exception e){
+            e.printStackTrace();
+            return ResponseVO.buildFailure("失败");
+        }
+    }
+
 
     /**
      * 获得num天后的日期

+ 7 - 0
src/main/java/com/example/cinema/controller/StatisticsController.java

@@ -24,4 +24,11 @@ public class StatisticsController {
         //此处date为非必填参数,若不填则默认为当天
         return statisticsService.getScheduleRateByDate(date);
     }
+
+    @RequestMapping(value = "statistics/boxOffice/total", method = RequestMethod.GET)
+    public ResponseVO getTotalBoxOffice(){
+        return statisticsService.getTotalBoxOffice();
+    }
+
+
 }

+ 9 - 1
src/main/java/com/example/cinema/data/StatisticsMapper.java

@@ -1,6 +1,8 @@
 package com.example.cinema.data;
 
 import com.example.cinema.vo.MovieScheduleTimeVO;
+import com.example.cinema.vo.MovieTotalBoxOfficeVO;
+import com.example.cinema.vo.ResponseVO;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
 
@@ -14,9 +16,15 @@ import java.util.List;
 @Mapper
 public interface StatisticsMapper {
     /**
-     *
+     * 查询date日期每部电影的排片次数
      * @param date
      * @return
      */
     List<MovieScheduleTimeVO> selectMovieScheduleTimes(@Param("date") Date date, @Param("nextDate") Date nextDate);
+
+    /**
+     * 查询所有电影的总票房(包括已经下架的,降序排列)
+     * @return
+     */
+    List<MovieTotalBoxOfficeVO> selectMovieTotalBoxOffice();
 }

+ 10 - 0
src/main/java/com/example/cinema/data/StatisticsMapper.xml

@@ -6,4 +6,14 @@
               (select * from schedule where start_time between #{date} and #{nextDate}) s,
               movie where s.movie_id = movie.id group by movieId
     </select>
+
+    <select id="selectMovieTotalBoxOffice" resultType="com.example.cinema.vo.MovieTotalBoxOfficeVO">
+        select movieId, boxOffice,name from
+            (select movie_id as movieId,sum(fare) as boxOffice from schedule
+            right join
+            (select schedule_id from ticket where state = 1) t
+            on schedule.id = t.schedule_id group by movie_id) s,movie
+        where movieId = movie.id
+        order by boxOffice desc
+    </select>
 </mapper>

+ 38 - 0
src/main/java/com/example/cinema/vo/MovieTotalBoxOfficeVO.java

@@ -0,0 +1,38 @@
+package com.example.cinema.vo;
+
+/**
+ * @author fjj
+ * @date 2019/4/21 1:42 PM
+ */
+public class MovieTotalBoxOfficeVO {
+    private Integer movieId;
+    /**
+     * 票房(单位:元),(PS:如果后续数据量大,可自行处理单位,如改成单位:万元)
+     */
+    private Integer boxOffice;
+    private String name;
+
+    public Integer getMovieId() {
+        return movieId;
+    }
+
+    public void setMovieId(Integer movieId) {
+        this.movieId = movieId;
+    }
+
+    public Integer getBoxOffice() {
+        return boxOffice;
+    }
+
+    public void setBoxOffice(Integer boxOffice) {
+        this.boxOffice = boxOffice;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+}

+ 1 - 1
src/main/java/com/example/cinema/vo/MovieVO.java

@@ -57,7 +57,7 @@ public class MovieVO {
      */
     private String description;
     /**
-     * 电影状态,0:未上映,1:上映中,2:已结束
+     * 电影状态,0:上架状态,1:下架状态
      */
     private Integer status;
     /**