|
|
@@ -5,11 +5,21 @@ import com.example.cinema.data.AccountMapper;
|
|
|
import com.example.cinema.data.MovieLikeMapper;
|
|
|
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.ResponseVO;
|
|
|
+import com.example.cinema.vo.ScheduleItem;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
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
|
|
|
* @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 USER_NOT_EXIST_ERROR_MESSAGE = "用户不存在";
|
|
|
private static final String MOVIE_NOT_EXIST_ERROR_MESSAGE = "电影不存在";
|
|
|
+ private static final String SCHEDULE_ERROR_MESSAGE = "有电影后续仍有排片或已有观众购票且未使用";
|
|
|
|
|
|
@Autowired
|
|
|
private MovieMapper movieMapper;
|
|
|
@@ -28,6 +39,8 @@ public class MovieServiceImpl implements MovieService {
|
|
|
private MovieLikeMapper movieLikeMapper;
|
|
|
@Autowired
|
|
|
private AccountMapper accountMapper;
|
|
|
+ @Autowired
|
|
|
+ private ScheduleMapper scheduleMapper;
|
|
|
|
|
|
@Override
|
|
|
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) {
|
|
|
return movieLikeMapper.selectLikeMovie(movieId, userId) == 0 ? false : true;
|
|
|
}
|