Vacity 7 éve
szülő
commit
1c893bf1bf

+ 14 - 0
src/main/java/com/example/cinema/bl/MovieService.java

@@ -1,5 +1,6 @@
 package com.example.cinema.bl;
 package com.example.cinema.bl;
 
 
+import com.example.cinema.vo.MovieBatchOffForm;
 import com.example.cinema.vo.MovieForm;
 import com.example.cinema.vo.MovieForm;
 import com.example.cinema.vo.ResponseVO;
 import com.example.cinema.vo.ResponseVO;
 
 
@@ -67,4 +68,17 @@ public interface MovieService {
      */
      */
     ResponseVO getLikeNumsGroupByDate(int movieId);
     ResponseVO getLikeNumsGroupByDate(int movieId);
 
 
+    /**
+     * 批量下架电影
+     * @param movieBatchOffForm
+     * @return
+     */
+    ResponseVO pullOfBatchOfMovie(MovieBatchOffForm movieBatchOffForm);
+
+    /**
+     * 更新电影信息
+     * @param updateMovieForm
+     * @return
+     */
+    ResponseVO updateMovie(MovieForm updateMovieForm);
 }
 }

+ 64 - 0
src/main/java/com/example/cinema/blImpl/MovieServiceImpl.java

@@ -5,11 +5,21 @@ import com.example.cinema.data.AccountMapper;
 import com.example.cinema.data.MovieLikeMapper;
 import com.example.cinema.data.MovieLikeMapper;
 import com.example.cinema.data.MovieMapper;
 import com.example.cinema.data.MovieMapper;
 
 
+import com.example.cinema.data.ScheduleMapper;
+import com.example.cinema.vo.MovieBatchOffForm;
 import com.example.cinema.vo.MovieForm;
 import com.example.cinema.vo.MovieForm;
 import com.example.cinema.vo.ResponseVO;
 import com.example.cinema.vo.ResponseVO;
+import com.example.cinema.vo.ScheduleItem;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
 
 
+import javax.swing.plaf.synth.SynthScrollBarUI;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Date;
+import java.util.List;
+
 /**
 /**
  * @author fjj
  * @author fjj
  * @date 2019/3/12 6:43 PM
  * @date 2019/3/12 6:43 PM
@@ -21,6 +31,7 @@ public class MovieServiceImpl implements MovieService {
     private static final String UNLIKE_ERROR_MESSAGE = "用户未标记该电影为想看";
     private static final String UNLIKE_ERROR_MESSAGE = "用户未标记该电影为想看";
     private static final String USER_NOT_EXIST_ERROR_MESSAGE = "用户不存在";
     private static final String USER_NOT_EXIST_ERROR_MESSAGE = "用户不存在";
     private static final String MOVIE_NOT_EXIST_ERROR_MESSAGE = "电影不存在";
     private static final String MOVIE_NOT_EXIST_ERROR_MESSAGE = "电影不存在";
+    private static final String SCHEDULE_ERROR_MESSAGE = "有电影后续仍有排片或已有观众购票且未使用";
 
 
     @Autowired
     @Autowired
     private MovieMapper movieMapper;
     private MovieMapper movieMapper;
@@ -28,6 +39,8 @@ public class MovieServiceImpl implements MovieService {
     private MovieLikeMapper movieLikeMapper;
     private MovieLikeMapper movieLikeMapper;
     @Autowired
     @Autowired
     private AccountMapper accountMapper;
     private AccountMapper accountMapper;
+    @Autowired
+    private ScheduleMapper scheduleMapper;
 
 
     @Override
     @Override
     public ResponseVO addMovie(MovieForm addMovieForm) {
     public ResponseVO addMovie(MovieForm addMovieForm) {
@@ -121,6 +134,57 @@ public class MovieServiceImpl implements MovieService {
         }
         }
     }
     }
 
 
+    @Override
+    public ResponseVO pullOfBatchOfMovie(MovieBatchOffForm movieBatchOffForm) {
+        try {
+            List<Integer> movieIdList =  movieBatchOffForm.getMovieIdList();
+            ResponseVO responseVO = preCheck(movieIdList);
+            if(!responseVO.getSuccess()){
+                return responseVO;
+            }
+            movieMapper.updateMovieStatusBatch(movieIdList);
+            return ResponseVO.buildSuccess();
+
+        } catch (Exception e) {
+            e.printStackTrace();
+            return ResponseVO.buildFailure("失败");
+        }
+    }
+
+    @Override
+    public ResponseVO updateMovie(MovieForm updateMovieForm) {
+        try {
+            ResponseVO responseVO = preCheck(Arrays.asList(updateMovieForm.getId()));
+            if(!responseVO.getSuccess()){
+                return responseVO;
+            }
+            movieMapper.updateMovie(updateMovieForm);
+            return ResponseVO.buildSuccess();
+        }catch (Exception e) {
+            e.printStackTrace();
+            return ResponseVO.buildFailure("失败");
+        }
+    }
+
+    /**
+     * 下架和修改电影的前置检查
+     * @param movieIdList
+     * @return
+     */
+    public ResponseVO preCheck(List<Integer> movieIdList){
+        Date thisTime = new Date();
+        List<ScheduleItem> scheduleItems = scheduleMapper.selectScheduleByMovieIdList(movieIdList);
+
+        // 检查是否有电影后续有排片及是否有观众购票未使用
+        for(ScheduleItem s : scheduleItems){
+            if(s.getEndTime().after(thisTime)){
+                return ResponseVO.buildFailure(SCHEDULE_ERROR_MESSAGE);
+            }
+        }
+        return ResponseVO.buildSuccess();
+    }
+
+
     private boolean userLikeTheMovie(int userId, int movieId) {
     private boolean userLikeTheMovie(int userId, int movieId) {
         return movieLikeMapper.selectLikeMovie(movieId, userId) == 0 ? false : true;
         return movieLikeMapper.selectLikeMovie(movieId, userId) == 0 ? false : true;
     }
     }

+ 22 - 5
src/main/java/com/example/cinema/blImpl/StatisticsServiceImpl.java

@@ -4,14 +4,19 @@ import com.example.cinema.bl.StatisticsService;
 import com.example.cinema.data.StatisticsMapper;
 import com.example.cinema.data.StatisticsMapper;
 import com.example.cinema.po.MovieScheduleTime;
 import com.example.cinema.po.MovieScheduleTime;
 import com.example.cinema.vo.ResponseVO;
 import com.example.cinema.vo.ResponseVO;
+import com.example.cinema.vo.ScheduleRateVO;
+import org.omg.PortableInterceptor.SYSTEM_EXCEPTION;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
 
 
+import java.text.DecimalFormat;
 import java.text.ParseException;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.text.SimpleDateFormat;
+import java.util.ArrayList;
 import java.util.Calendar;
 import java.util.Calendar;
 import java.util.Date;
 import java.util.Date;
 import java.util.List;
 import java.util.List;
+import java.util.stream.Collectors;
 
 
 /**
 /**
  * @author fjj
  * @author fjj
@@ -26,13 +31,25 @@ public class StatisticsServiceImpl implements StatisticsService {
         try{
         try{
             Date requireDate = date;
             Date requireDate = date;
             if(requireDate == null){
             if(requireDate == null){
-                SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
-                requireDate = simpleDateFormat.parse(simpleDateFormat.format(new Date()));
+                requireDate = new Date();
             }
             }
+            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
+            requireDate = simpleDateFormat.parse(simpleDateFormat.format(requireDate));
+
             Date nextDate = getNumDayAfterDate(requireDate, 1);
             Date nextDate = getNumDayAfterDate(requireDate, 1);
-            List<MovieScheduleTime> movieScheduleTime = statisticsMapper.selectMovieScheduleTimes(date, nextDate);
-            System.out.println(movieScheduleTime.size());
-            return ResponseVO.buildSuccess();
+            List<MovieScheduleTime> movieScheduleTimes = statisticsMapper.selectMovieScheduleTimes(requireDate, nextDate);
+
+            //统计该天总排片数
+            int totalTimes = movieScheduleTimes.stream().mapToInt(mst -> mst.getTime()).sum();
+            List<ScheduleRateVO> scheduleRateVOList = new ArrayList<>();
+            for(MovieScheduleTime movieScheduleTime: movieScheduleTimes){
+                ScheduleRateVO scheduleRateVO = new ScheduleRateVO();
+                scheduleRateVO.setMovieId(movieScheduleTime.getMovieId());
+                scheduleRateVO.setRate(Double.parseDouble(String.format("%.2f",(double)movieScheduleTime.getTime() / totalTimes)));
+                scheduleRateVO.setName(movieScheduleTime.getName());
+                scheduleRateVOList.add(scheduleRateVO);
+            }
+            return ResponseVO.buildSuccess(scheduleRateVOList);
 
 
         }catch (Exception e){
         }catch (Exception e){
             e.printStackTrace();
             e.printStackTrace();

+ 15 - 0
src/main/java/com/example/cinema/controller/MovieController.java

@@ -1,5 +1,6 @@
 package com.example.cinema.controller;
 package com.example.cinema.controller;
 
 
+import com.example.cinema.vo.MovieBatchOffForm;
 import com.example.cinema.vo.MovieForm;
 import com.example.cinema.vo.MovieForm;
 import com.example.cinema.bl.MovieService;
 import com.example.cinema.bl.MovieService;
 import com.example.cinema.vo.ResponseVO;
 import com.example.cinema.vo.ResponseVO;
@@ -53,4 +54,18 @@ public class MovieController {
     public ResponseVO getMovieByKeyword(@RequestParam String keyword){
     public ResponseVO getMovieByKeyword(@RequestParam String keyword){
         return movieService.getMovieByKeyword(keyword);
         return movieService.getMovieByKeyword(keyword);
     }
     }
+
+    @RequestMapping(value = "/movie/off/batch",method = RequestMethod.POST)
+    public ResponseVO pullOfBatchOfMovie(@RequestBody MovieBatchOffForm movieBatchOffForm){
+        return movieService.pullOfBatchOfMovie(movieBatchOffForm);
+    }
+
+    @RequestMapping(value = "/movie/update",method = RequestMethod.POST)
+    public ResponseVO updateMovie(@RequestBody MovieForm updateMovieForm){
+        return movieService.updateMovie(updateMovieForm);
+    }
+
+
+
+
 }
 }

+ 14 - 0
src/main/java/com/example/cinema/data/MovieMapper.java

@@ -47,4 +47,18 @@ public interface MovieMapper {
      * @return
      * @return
      */
      */
     List<MovieVO> selectMovieByKeyword(@Param("keyword") String keyword);
     List<MovieVO> selectMovieByKeyword(@Param("keyword") String keyword);
+
+    /**
+     * 批量更新电影状态
+     * @param movieIdList
+     * @return
+     */
+    int updateMovieStatusBatch(List<Integer> movieIdList);
+
+    /**
+     * 修改电影
+     * @param updateMovieForm
+     * @return
+     */
+    int updateMovie(MovieForm updateMovieForm);
 }
 }

+ 15 - 1
src/main/java/com/example/cinema/data/MovieMapper.xml

@@ -4,7 +4,7 @@
     <insert id="insertOneMovie" parameterType="com.example.cinema.vo.MovieForm"
     <insert id="insertOneMovie" parameterType="com.example.cinema.vo.MovieForm"
             useGeneratedKeys="true" keyProperty="id">
             useGeneratedKeys="true" keyProperty="id">
         insert into movie(name, poster_url, director, screen_writer, starring, type, country, language, length, start_date, description, status)
         insert into movie(name, poster_url, director, screen_writer, starring, type, country, language, length, start_date, description, status)
-        values(#{name}, #{posterUrl}, #{director},  #{screenWriter}, #{starring}, #{type}, #{country}, #{language}, #{length}, #{startDate}, #{description},#{status})
+        values(#{name}, #{posterUrl}, #{director},  #{screenWriter}, #{starring}, #{type}, #{country}, #{language}, #{length}, #{startDate}, #{description}, 0)
     </insert>
     </insert>
 
 
     <select id="selectMovieById" resultMap="Movie">
     <select id="selectMovieById" resultMap="Movie">
@@ -25,6 +25,20 @@
         like concat('%',#{keyword},'%');
         like concat('%',#{keyword},'%');
     </select>
     </select>
 
 
+    <update id="updateMovieStatusBatch" parameterType="java.util.List">
+        update movie set status = 1 where id in
+        <foreach collection="list" index="index" item="item" open="(" close=")" separator=",">
+            #{item}
+        </foreach>
+    </update>
+
+    <update id="updateMovie" parameterType="com.example.cinema.vo.MovieForm">
+        update movie set poster_url = #{posterUrl}, director = #{director}, screen_writer = #{screenWriter},
+        starring = #{starring}, type = #{type}, country = #{country}, language = #{language},
+        length = #{length}, start_date = #{startDate}, name = #{name}, description = #{description}
+        where id = #{id}
+    </update>
+
     <resultMap id="Movie" type="com.example.cinema.vo.MovieVO">
     <resultMap id="Movie" type="com.example.cinema.vo.MovieVO">
         <id column="id" property="id"></id>
         <id column="id" property="id"></id>
         <result column="poster_url" property="posterUrl"></result>
         <result column="poster_url" property="posterUrl"></result>

+ 7 - 1
src/main/java/com/example/cinema/data/ScheduleMapper.java

@@ -1,7 +1,6 @@
 package com.example.cinema.data;
 package com.example.cinema.data;
 
 
 
 
-import com.example.cinema.vo.ResponseVO;
 import com.example.cinema.vo.ScheduleForm;
 import com.example.cinema.vo.ScheduleForm;
 import com.example.cinema.vo.ScheduleItem;
 import com.example.cinema.vo.ScheduleItem;
 import com.example.cinema.vo.ScheduleViewForm;
 import com.example.cinema.vo.ScheduleViewForm;
@@ -97,4 +96,11 @@ public interface ScheduleMapper {
      * @return
      * @return
      */
      */
     ScheduleItem selectScheduleById(int id);
     ScheduleItem selectScheduleById(int id);
+
+    /**
+     * 查询所有涉及到movieIdList中电影的排片信息
+     * @param movieIdList
+     * @return
+     */
+    List<ScheduleItem> selectScheduleByMovieIdList(List<Integer> movieIdList);
 }
 }

+ 7 - 0
src/main/java/com/example/cinema/data/ScheduleMapper.xml

@@ -26,6 +26,13 @@
           or (start_time between #{startTime} and #{endTime}))
           or (start_time between #{startTime} and #{endTime}))
     </select>
     </select>
 
 
+    <select id="selectScheduleByMovieIdList" resultMap="ScheduleItem" parameterType="java.util.List">
+        select * from schedule where movie_id in
+        <foreach collection="list" index="index" item="item" open="(" close=")" separator=",">
+            #{item}
+        </foreach>
+    </select>
+
     <insert id="insertOneView" parameterType="com.example.cinema.vo.ScheduleViewForm"
     <insert id="insertOneView" parameterType="com.example.cinema.vo.ScheduleViewForm"
             useGeneratedKeys="true" keyProperty="id">
             useGeneratedKeys="true" keyProperty="id">
         insert into view(day) values(#{day})
         insert into view(day) values(#{day})

+ 22 - 0
src/main/java/com/example/cinema/vo/MovieBatchOffForm.java

@@ -0,0 +1,22 @@
+package com.example.cinema.vo;
+
+import java.util.List;
+
+/**
+ * @author fjj
+ * @date 2019/4/16 9:51 PM
+ */
+public class MovieBatchOffForm {
+    /**
+     * 要下架的电影id列表
+     */
+    private List<Integer> movieIdList;
+
+    public List<Integer> getMovieIdList() {
+        return movieIdList;
+    }
+
+    public void setMovieIdList(List<Integer> movieIdList) {
+        this.movieIdList = movieIdList;
+    }
+}

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

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

+ 35 - 0
src/main/java/com/example/cinema/vo/ScheduleRateVO.java

@@ -0,0 +1,35 @@
+package com.example.cinema.vo;
+
+/**
+ * @author fjj
+ * @date 2019/4/16 3:48 PM
+ */
+public class ScheduleRateVO {
+    private Integer movieId;
+    private Double rate;
+    private String name;
+
+    public Integer getMovieId() {
+        return movieId;
+    }
+
+    public void setMovieId(Integer movieId) {
+        this.movieId = movieId;
+    }
+
+    public Double getRate() {
+        return rate;
+    }
+
+    public void setRate(Double rate) {
+        this.rate = rate;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+}

+ 31 - 0
src/test/java/com/example/cinema/blImpl/MovieServiceImplTest.java

@@ -0,0 +1,31 @@
+package com.example.cinema.blImpl;
+
+import com.example.cinema.bl.MovieService;
+import com.example.cinema.vo.MovieBatchOffForm;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.junit4.SpringRunner;
+
+import java.util.Arrays;
+
+import static org.junit.Assert.*;
+
+/**
+ * @author fjj
+ * @date 2019/4/16 10:06 PM
+ */
+@RunWith(SpringRunner.class)
+@SpringBootTest
+public class MovieServiceImplTest {
+
+    @Autowired
+    private MovieService movieService;
+//    @Test
+//    public void pullOfBatchOfMovie() {
+//        MovieBatchOffForm movieBatchOffForm = new MovieBatchOffForm();
+//        movieBatchOffForm.setMovieIdList(Arrays.asList(10));
+//        movieService.pullOfBatchOfMovie(movieBatchOffForm);
+//    }
+}

+ 5 - 5
src/test/java/com/example/cinema/blImpl/StatisticsServiceImplTest.java

@@ -22,11 +22,11 @@ import static org.junit.Assert.*;
 public class StatisticsServiceImplTest {
 public class StatisticsServiceImplTest {
     @Autowired
     @Autowired
     private StatisticsService statisticsService;
     private StatisticsService statisticsService;
-    @Test
-    public void getScheduleRateByDate() throws ParseException {
-        System.out.println(getNumDayBeforeDate(new Date(),-5));
-        statisticsService.getScheduleRateByDate(getNumDayBeforeDate(new Date(),-5));
-    }
+//    @Test
+//    public void getScheduleRateByDate() throws ParseException {
+//        System.out.println(getNumDayBeforeDate(new Date(),-5));
+//        statisticsService.getScheduleRateByDate(getNumDayBeforeDate(new Date(),-5));
+//    }
 
 
     /**
     /**
      * 获得num天后的日期
      * 获得num天后的日期

BIN
target/classes/com/example/cinema/data/ScheduleMapper.class


+ 7 - 0
target/classes/com/example/cinema/data/ScheduleMapper.xml

@@ -26,6 +26,13 @@
           or (start_time between #{startTime} and #{endTime}))
           or (start_time between #{startTime} and #{endTime}))
     </select>
     </select>
 
 
+    <select id="selectScheduleByMovieIdList" resultMap="ScheduleItem" parameterType="java.util.List">
+        select * from schedule where movie_id in
+        <foreach collection="list" index="index" item="item" open="(" close=")" separator=",">
+            #{item}
+        </foreach>
+    </select>
+
     <insert id="insertOneView" parameterType="com.example.cinema.vo.ScheduleViewForm"
     <insert id="insertOneView" parameterType="com.example.cinema.vo.ScheduleViewForm"
             useGeneratedKeys="true" keyProperty="id">
             useGeneratedKeys="true" keyProperty="id">
         insert into view(day) values(#{day})
         insert into view(day) values(#{day})