Jelajahi Sumber

两个getById

jacksenma 7 tahun lalu
induk
melakukan
5f6f19dec3

+ 8 - 0
src/main/java/com/example/cinema/bl/management/HallService.java

@@ -1,5 +1,6 @@
 package com.example.cinema.bl.management;
 
+import com.example.cinema.vo.HallVO;
 import com.example.cinema.vo.ResponseVO;
 
 /**
@@ -12,4 +13,11 @@ public interface HallService {
      * @return
      */
     ResponseVO searchAllHall();
+
+    /**
+     * 搜索影厅
+     * @param id
+     * @return
+     */
+    HallVO getHallById(int id);
 }

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

@@ -2,7 +2,9 @@ package com.example.cinema.bl.management;
 
 import com.example.cinema.vo.MovieBatchOffForm;
 import com.example.cinema.vo.MovieForm;
+import com.example.cinema.vo.MovieVO;
 import com.example.cinema.vo.ResponseVO;
+import org.apache.ibatis.annotations.Param;
 
 /**
  * @author fjj
@@ -87,4 +89,11 @@ public interface MovieService {
      * @return
      */
     ResponseVO updateMovie(MovieForm updateMovieForm);
+
+    /**
+     * 根据id查找电影
+     * @param id
+     * @return
+     */
+    MovieVO getMovieById(int id);
 }

+ 12 - 0
src/main/java/com/example/cinema/blImpl/management/HallServiceImpl.java

@@ -2,6 +2,7 @@ package com.example.cinema.blImpl.management;
 
 import com.example.cinema.bl.management.HallService;
 import com.example.cinema.data.management.HallMapper;
+import com.example.cinema.vo.HallVO;
 import com.example.cinema.vo.ResponseVO;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -23,4 +24,15 @@ public class HallServiceImpl implements HallService {
             return ResponseVO.buildFailure("失败");
         }
     }
+
+    @Override
+    public HallVO getHallById(int id) {
+        try {
+            return hallMapper.selectHallById(id);
+        } catch (Exception e) {
+            e.printStackTrace();
+            return null;
+        }
+
+    }
 }

+ 12 - 4
src/main/java/com/example/cinema/blImpl/management/MovieServiceImpl.java

@@ -6,10 +6,7 @@ import com.example.cinema.data.statistics.MovieLikeMapper;
 import com.example.cinema.data.management.MovieMapper;
 
 import com.example.cinema.data.management.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 com.example.cinema.vo.*;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
@@ -173,6 +170,17 @@ public class MovieServiceImpl implements MovieService {
         }
     }
 
+    @Override
+    public MovieVO getMovieById(int id) {
+        try {
+            return movieMapper.selectMovieById(id);
+        }catch (Exception e){
+            e.printStackTrace();
+            return null;
+        }
+
+    }
+
     /**
      * 下架和修改电影的前置检查
      * @param movieIdList

+ 7 - 6
src/main/java/com/example/cinema/blImpl/management/ScheduleServiceImpl.java

@@ -1,8 +1,8 @@
 package com.example.cinema.blImpl.management;
 
+import com.example.cinema.bl.management.HallService;
+import com.example.cinema.bl.management.MovieService;
 import com.example.cinema.bl.management.ScheduleService;
-import com.example.cinema.data.management.HallMapper;
-import com.example.cinema.data.management.MovieMapper;
 import com.example.cinema.data.management.ScheduleMapper;
 import com.example.cinema.vo.*;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -33,9 +33,10 @@ public class ScheduleServiceImpl implements ScheduleService {
     @Autowired
     private ScheduleMapper scheduleMapper;
     @Autowired
-    private MovieMapper movieMapper;
+    private MovieService movieService;
     @Autowired
-    private HallMapper hallMapper;
+    private HallService hallService;
+
 
     @Override
     public ResponseVO addSchedule(ScheduleForm scheduleForm) {
@@ -219,12 +220,12 @@ public class ScheduleServiceImpl implements ScheduleService {
             }
 
             //检查影厅是否存在
-            if(hallMapper.selectHallById(scheduleForm.getHallId()) == null){
+            if(hallService.getHallById(scheduleForm.getHallId()) == null){
                 return ResponseVO.buildFailure(HALL_NOT_EXIST_ERROR_MESSAGE);
             }
 
             // 检查电影是否存在
-            MovieVO movieVO = movieMapper.selectMovieById(scheduleForm.getMovieId());
+            MovieVO movieVO = movieService.getMovieById(scheduleForm.getMovieId());
             if(movieVO == null){
                 return ResponseVO.buildFailure(MOVIE_NOT_EXIST_ERROR_MESSAGE);
             }

+ 2 - 2
src/main/resources/application.yml

@@ -1,8 +1,8 @@
 spring:
   datasource:
-     url: jdbc:mysql://localhost:3306/cinema?serverTimezone=CTT&characterEncoding=UTF-8
+     url: jdbc:mysql://47.101.183.63:3306/cinema?serverTimezone=CTT&characterEncoding=UTF-8
      username: root
-     password: root
+     password: Yuantu123
      driver-class-name: com.mysql.cj.jdbc.Driver
      max-active: 200
      max-idle: 20