Vacity 7 years ago
parent
commit
3dd613c944

+ 8 - 2
.idea/dataSources.local.xml

@@ -2,8 +2,14 @@
 <project version="4">
   <component name="dataSourceStorageLocal">
     <data-source name="cinema@47.101.183.63" uuid="56491842-8c26-426b-a604-02dce7d52d03">
-      <database-info product="" version="" jdbc-version="" driver-name="" driver-version="" dbms="MYSQL" exact-version="0" />
-      <introspection-schemas>*:@</introspection-schemas>
+      <database-info product="MySQL" version="5.7.24" jdbc-version="4.0" driver-name="MySQL Connector Java" driver-version="mysql-connector-java-5.1.46 ( Revision: 9cc87a48e75c2d2e87c1a293b2862ce651cb256e )" family="MYSQL" exact-version="5.7.24">
+        <extra-name-characters>#@</extra-name-characters>
+        <identifier-quote-string>`</identifier-quote-string>
+      </database-info>
+      <case-sensitivity plain-identifiers="exact" quoted-identifiers="exact" />
+      <secret-storage>master_key</secret-storage>
+      <user-name>root</user-name>
+      <introspection-schemas>*:cinema</introspection-schemas>
     </data-source>
   </component>
 </project>

+ 1 - 1
.idea/dataSources/56491842-8c26-426b-a604-02dce7d52d03.xml

@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <dataSource name="cinema@47.101.183.63">
-  <database-model serializer="dbm" dbms="MYSQL" family-id="MYSQL" format-version="4.14">
+  <database-model serializer="dbm" rdbms="MYSQL" format-version="4.11">
     <root id="1">
       <ServerVersion>5.7.24</ServerVersion>
       <DefaultEngine>InnoDB</DefaultEngine>

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

@@ -2,6 +2,7 @@ package com.example.cinema.bl;
 
 import com.example.cinema.vo.ResponseVO;
 import com.example.cinema.vo.ScheduleForm;
+import com.example.cinema.vo.ScheduleSearchForm;
 
 /**
  * @author fjj
@@ -14,4 +15,11 @@ public interface ScheduleService {
      * @return
      */
     ResponseVO addSchedule(ScheduleForm scheduleForm);
+
+    /**
+     * 查询包括从起始时间开始的7天排片计划
+     * @param scheduleSearchForm
+     * @return
+     */
+    ResponseVO searchScheduleSevenDays(ScheduleSearchForm scheduleSearchForm);
 }

+ 49 - 2
src/main/java/com/example/cinema/bl/ScheduleServiceImpl.java

@@ -1,11 +1,18 @@
 package com.example.cinema.bl;
 
 import com.example.cinema.data.ScheduleMapper;
-import com.example.cinema.vo.ResponseVO;
-import com.example.cinema.vo.ScheduleForm;
+import com.example.cinema.vo.*;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.List;
+import java.util.concurrent.CopyOnWriteArrayList;
+
 /**
  * @author fjj
  * @date 2019/4/11 4:14 PM
@@ -27,4 +34,44 @@ public class ScheduleServiceImpl implements ScheduleService {
             return ResponseVO.buildFailure("失败");
         }
     }
+
+    @Override
+    public ResponseVO searchScheduleSevenDays(ScheduleSearchForm scheduleSearchForm) {
+        try {
+            // 处理查询表单的起止时间
+            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
+            Date startDate = simpleDateFormat.parse(simpleDateFormat.format(scheduleSearchForm.getStartDate()));
+            scheduleSearchForm.setStartDate(startDate);
+
+            Calendar calendarStartDate = Calendar.getInstance();
+            calendarStartDate.setTime(startDate);
+            calendarStartDate.add(Calendar.DAY_OF_YEAR, 7);
+            scheduleSearchForm.setEndDate(calendarStartDate.getTime());
+
+            // 按照日期整理ScheduleItem
+            List<ScheduleItem> scheduleItemList = scheduleMapper.selectSchedule(scheduleSearchForm);
+            List<ScheduleVO> scheduleVOList = new ArrayList<>();
+
+            for(int i = 0; i < 7; i++){
+                calendarStartDate.setTime(startDate);
+                calendarStartDate.add(Calendar.DAY_OF_YEAR, i);
+                Date date = calendarStartDate.getTime();
+                ScheduleVO scheduleVO = new ScheduleVO();
+                scheduleVO.setDate(date);
+                List<ScheduleItem> scheduleItems = new ArrayList<>();
+                for(ScheduleItem scheduleItem : scheduleItemList){
+                    Date startTime = simpleDateFormat.parse(simpleDateFormat.format(scheduleItem.getStartTime()));
+                    if(date.equals(startTime)){
+                        scheduleItems.add(scheduleItem);
+                    }
+                }
+                scheduleVO.setScheduleItemList(scheduleItems);
+                scheduleVOList.add(scheduleVO);
+            }
+            return ResponseVO.buildSuccess(scheduleVOList);
+        } catch (ParseException e) {
+            e.printStackTrace();
+            return ResponseVO.buildFailure("失败");
+        }
+    }
 }

+ 1 - 1
src/main/java/com/example/cinema/controller/HallController.java

@@ -7,7 +7,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
 import org.springframework.web.bind.annotation.RestController;
 
-/**
+/**影厅管理
  * @author fjj
  * @date 2019/4/12 1:59 PM
  */

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

@@ -6,7 +6,7 @@ import com.example.cinema.vo.ResponseVO;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
-/**
+/**电影管理
  * @author fjj
  * @date 2019/3/12 6:17 PM
  */

+ 9 - 1
src/main/java/com/example/cinema/controller/ScheduleController.java

@@ -3,13 +3,14 @@ package com.example.cinema.controller;
 import com.example.cinema.bl.ScheduleService;
 import com.example.cinema.vo.ResponseVO;
 import com.example.cinema.vo.ScheduleForm;
+import com.example.cinema.vo.ScheduleSearchForm;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
 import org.springframework.web.bind.annotation.RestController;
 
-/**
+/**排片管理
  * @author fjj
  * @date 2019/4/11 4:13 PM
  */
@@ -23,4 +24,11 @@ public class ScheduleController {
         return scheduleService.addSchedule(scheduleForm);
     }
 
+    @RequestMapping(value = "/schedule/search", method = RequestMethod.POST)
+    public ResponseVO searchSchedule(@RequestBody ScheduleSearchForm scheduleSearchForm){
+        return scheduleService.searchScheduleSevenDays(scheduleSearchForm);
+    }
+
+
+
 }

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

@@ -1,13 +1,28 @@
 package com.example.cinema.data;
 
 import com.example.cinema.vo.ScheduleForm;
+import com.example.cinema.vo.ScheduleItem;
+import com.example.cinema.vo.ScheduleSearchForm;
 import org.apache.ibatis.annotations.Mapper;
 
+import java.util.List;
+
 /**
  * @author fjj
  * @date 2019/4/11 4:18 PM
  */
 @Mapper
 public interface ScheduleMapper {
+    /**
+     * 插入一条排片信息
+     * @param scheduleForm
+     * @return
+     */
     int insertOneSchedule(ScheduleForm scheduleForm);
+
+    /**
+     * 查询排片信息
+     * @return
+     */
+    List<ScheduleItem> selectSchedule(ScheduleSearchForm scheduleSearchForm);
 }

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

@@ -7,7 +7,20 @@
         values(#{hallId}, #{movieId}, #{startTime}, #{endTime}, #{fare})
     </insert>
 
-    <resultMap id="Hall" type="com.example.cinema.vo.HallVO">
+    <select id="selectSchedule" resultMap="ScheduleItem">
+        select * from
+        (select * from schedule where hall_id = #{hallId} and start_time between #{startDate} and #{endDate}) s,
+        (select name, id as movie_id from movie) m,
+        (select name, id as hall_id from hall) h
+        where s.movie_id = m.movie_id and s.hall_id = h.hall_id
+    </select>
+
+    <resultMap id="ScheduleItem" type="com.example.cinema.vo.ScheduleItem">
+        <id column="id" property="id"></id>
+        <result column="hall_id" property="hallId"></result>
+        <result column="movie_id" property="movieId"></result>
+        <result column="start_time" property="startTime"></result>
+        <result column="end_time" property="endTime"></result>
     </resultMap>
 
 </mapper>

+ 82 - 0
src/main/java/com/example/cinema/vo/ScheduleItem.java

@@ -0,0 +1,82 @@
+package com.example.cinema.vo;
+
+import java.util.Date;
+
+/**
+ * @author fjj
+ * @date 2019/4/12 3:34 PM
+ */
+public class ScheduleItem {
+    private Integer id;
+    private Integer hallId;
+    private String hallName;
+    private Integer movieId;
+    private String movieName;
+    private Date startTime;
+    private Date endTime;
+    private double fare;
+
+    public Integer getId() {
+        return id;
+    }
+
+    public void setId(Integer id) {
+        this.id = id;
+    }
+
+    public Integer getHallId() {
+        return hallId;
+    }
+
+    public void setHallId(Integer hallId) {
+        this.hallId = hallId;
+    }
+
+    public String getHallName() {
+        return hallName;
+    }
+
+    public void setHallName(String hallName) {
+        this.hallName = hallName;
+    }
+
+    public Integer getMovieId() {
+        return movieId;
+    }
+
+    public void setMovieId(Integer movieId) {
+        this.movieId = movieId;
+    }
+
+    public String getMovieName() {
+        return movieName;
+    }
+
+    public void setMovieName(String movieName) {
+        this.movieName = movieName;
+    }
+
+    public Date getStartTime() {
+        return startTime;
+    }
+
+    public void setStartTime(Date startTime) {
+        this.startTime = startTime;
+    }
+
+    public Date getEndTime() {
+        return endTime;
+    }
+
+    public void setEndTime(Date endTime) {
+        this.endTime = endTime;
+    }
+
+    public double getFare() {
+        return fare;
+    }
+
+    public void setFare(double fare) {
+        this.fare = fare;
+    }
+}

+ 47 - 0
src/main/java/com/example/cinema/vo/ScheduleSearchForm.java

@@ -0,0 +1,47 @@
+package com.example.cinema.vo;
+
+import java.util.Date;
+
+/**
+ * @author fjj
+ * @date 2019/4/12 2:21 PM
+ */
+public class ScheduleSearchForm {
+    /**
+     * 影厅id
+     */
+    private Integer hallId;
+    /**
+     * 查询排片计划的起始日期
+     */
+    private Date startDate;
+
+    /**
+     * 查询排片计划的结束日期(当前默认结束日期和起始时间相差7天)
+     */
+    private Date endDate;
+
+    public Integer getHallId() {
+        return hallId;
+    }
+
+    public void setHallId(Integer hallId) {
+        this.hallId = hallId;
+    }
+
+    public Date getStartDate() {
+        return startDate;
+    }
+
+    public void setStartDate(Date startDate) {
+        this.startDate = startDate;
+    }
+
+    public Date getEndDate() {
+        return endDate;
+    }
+
+    public void setEndDate(Date endDate) {
+        this.endDate = endDate;
+    }
+}

+ 29 - 0
src/main/java/com/example/cinema/vo/ScheduleVO.java

@@ -0,0 +1,29 @@
+package com.example.cinema.vo;
+
+import java.util.Date;
+import java.util.List;
+
+/**
+ * @author fjj
+ * @date 2019/4/12 4:05 PM
+ */
+public class ScheduleVO {
+    private Date date;
+    private List<ScheduleItem> scheduleItemList;
+
+    public Date getDate() {
+        return date;
+    }
+
+    public void setDate(Date date) {
+        this.date = date;
+    }
+
+    public List<ScheduleItem> getScheduleItemList() {
+        return scheduleItemList;
+    }
+
+    public void setScheduleItemList(List<ScheduleItem> scheduleItemList) {
+        this.scheduleItemList = scheduleItemList;
+    }
+}

+ 33 - 0
src/test/java/com/example/cinema/bl/ScheduleServiceImplTest.java

@@ -0,0 +1,33 @@
+package com.example.cinema.bl;
+import java.util.Date;
+
+import com.example.cinema.CinemaApplication;
+import com.example.cinema.vo.ScheduleSearchForm;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.junit4.SpringRunner;
+
+import static org.junit.Assert.*;
+
+/**
+ * @author fjj
+ * @date 2019/4/12 3:21 PM
+ */
+@RunWith(SpringRunner.class)
+@SpringBootTest
+public class ScheduleServiceImplTest {
+
+    @Autowired
+    private ScheduleService scheduleService;
+
+    @Test
+    public void searchScheduleSevenDays() {
+        ScheduleSearchForm scheduleSearchForm = new ScheduleSearchForm();
+        scheduleSearchForm.setHallId(2);
+        scheduleSearchForm.setStartDate(new Date());
+        scheduleService.searchScheduleSevenDays(scheduleSearchForm);
+    }
+}

BIN
target/classes/com/example/cinema/bl/ScheduleService.class


BIN
target/classes/com/example/cinema/bl/ScheduleServiceImpl.class


BIN
target/classes/com/example/cinema/controller/ScheduleController.class


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


+ 14 - 1
target/classes/com/example/cinema/data/ScheduleMapper.xml

@@ -7,7 +7,20 @@
         values(#{hallId}, #{movieId}, #{startTime}, #{endTime}, #{fare})
     </insert>
 
-    <resultMap id="Hall" type="com.example.cinema.vo.HallVO">
+    <select id="selectSchedule" resultMap="ScheduleItem">
+        select * from
+        (select * from schedule where hall_id = #{hallId} and start_time between #{startDate} and #{endDate}) s,
+        (select name, id as movie_id from movie) m,
+        (select name, id as hall_id from hall) h
+        where s.movie_id = m.movie_id and s.hall_id = h.hall_id
+    </select>
+
+    <resultMap id="ScheduleItem" type="com.example.cinema.vo.ScheduleItem">
+        <id column="id" property="id"></id>
+        <result column="hall_id" property="hallId"></result>
+        <result column="movie_id" property="movieId"></result>
+        <result column="start_time" property="startTime"></result>
+        <result column="end_time" property="endTime"></result>
     </resultMap>
 
 </mapper>