Skip to content

Commit 3bfb56b

Browse files
committed
update
1 parent e7fe306 commit 3bfb56b

19 files changed

+708
-6
lines changed

pom.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,16 @@
3636
<artifactId>spring-boot-starter-test</artifactId>
3737
<scope>test</scope>
3838
</dependency>
39+
40+
<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
41+
<dependency>
42+
<groupId>org.projectlombok</groupId>
43+
<artifactId>lombok</artifactId>
44+
<version>1.18.28</version>
45+
<scope>provided</scope>
46+
</dependency>
47+
48+
3949
</dependencies>
4050

4151
<build>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.hoangtien2k3.ticketbookingapi.entity;
2+
3+
import jakarta.persistence.*;
4+
import lombok.AllArgsConstructor;
5+
import lombok.Getter;
6+
import lombok.NoArgsConstructor;
7+
import lombok.Setter;
8+
9+
@Entity
10+
@AllArgsConstructor
11+
@NoArgsConstructor
12+
@Getter
13+
@Setter
14+
@Table(name = "booking")
15+
public class Book {
16+
@Id
17+
@GeneratedValue(strategy = GenerationType.AUTO)
18+
@Column(name = "booking_id")
19+
private int bookingId;
20+
@Column(name = "user_id")
21+
private int userId;
22+
@Column(name = "schedule_id")
23+
private int scheduleId;
24+
@Column(name = "seat_id")
25+
private int seatId;
26+
@Column(name = "price")
27+
private double price;
28+
@Column(name = "seat_status")
29+
private int seatStatus;
30+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.hoangtien2k3.ticketbookingapi.entity;
2+
3+
import jakarta.persistence.*;
4+
import lombok.AllArgsConstructor;
5+
import lombok.Getter;
6+
import lombok.NoArgsConstructor;
7+
import lombok.Setter;
8+
9+
@Entity
10+
@AllArgsConstructor
11+
@NoArgsConstructor
12+
@Getter
13+
@Setter
14+
@Table(name = "cinemas")
15+
public class Cinema {
16+
@Id
17+
@GeneratedValue(strategy = GenerationType.AUTO)
18+
@Column(name = "cinema_id")
19+
private int cinemaId;
20+
@Column(name = "cinema_name")
21+
private String cinemaName;
22+
@Column(name = "cinema_address")
23+
private String cinemaAddress;
24+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package com.hoangtien2k3.ticketbookingapi.entity;
2+
3+
import jakarta.persistence.*;
4+
import lombok.AllArgsConstructor;
5+
import lombok.Getter;
6+
import lombok.NoArgsConstructor;
7+
import lombok.Setter;
8+
9+
@Setter
10+
@Getter
11+
@NoArgsConstructor
12+
@AllArgsConstructor
13+
@Entity
14+
@Table(name = "movies")
15+
public class Movie {
16+
@Id
17+
@GeneratedValue(strategy = GenerationType.AUTO)
18+
@Column(name = "movie_id")
19+
private int movieId;
20+
@Column(name = "movie_name")
21+
private String movieName;
22+
@Column(name = "movie_description")
23+
private String movieDescription;
24+
@Column(name = "movie_trailer")
25+
private String movieTrailer;
26+
@Column(name = "movie_cens")
27+
private String movieCens;
28+
@Column(name = "movie_genres")
29+
private String movieGenres;
30+
@Column(name = "movie_release")
31+
private String movieRelease;
32+
@Column(name = "movie_lenght")
33+
private String movieLength;
34+
@Column(name = "movie_format")
35+
private String movieFormat;
36+
@Column(name = "movie_poster")
37+
private String moviePoster;
38+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.hoangtien2k3.ticketbookingapi.entity;
2+
3+
import jakarta.persistence.*;
4+
import lombok.AllArgsConstructor;
5+
import lombok.Getter;
6+
import lombok.NoArgsConstructor;
7+
import lombok.Setter;
8+
9+
@Setter
10+
@Getter
11+
@NoArgsConstructor
12+
@AllArgsConstructor
13+
@Entity
14+
@Table(name = "room")
15+
public class Room {
16+
@Id
17+
@GeneratedValue(strategy = GenerationType.AUTO)
18+
@Column(name = "room_id")
19+
private int roomId;
20+
@Column(name = "cinema_id")
21+
private int cinemaId;
22+
@Column(name = "room_name ")
23+
private String roomName;
24+
}
Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
1+
package com.hoangtien2k3.ticketbookingapi.entity;
2+
3+
import com.hoangtien2k3.ticketbookingapi.model.ResponseCinema;
4+
import com.hoangtien2k3.ticketbookingapi.model.ResponseFormat;
5+
import com.hoangtien2k3.ticketbookingapi.model.ResponseScheduleCinema;
6+
import com.hoangtien2k3.ticketbookingapi.model.ResponseScheduleTime;
7+
import jakarta.persistence.*;
8+
import lombok.AllArgsConstructor;
9+
import lombok.Getter;
10+
import lombok.NoArgsConstructor;
11+
import lombok.Setter;
12+
13+
14+
@SqlResultSetMappings({
15+
@SqlResultSetMapping(
16+
name = "ResponseScheduleTime",
17+
classes = @ConstructorResult(
18+
targetClass = ResponseScheduleTime.class,
19+
columns = {
20+
@ColumnResult(name = "schedule_id", type = Integer.class),
21+
@ColumnResult(name = "schedule_start", type = String.class)
22+
}
23+
)
24+
),
25+
@SqlResultSetMapping(
26+
name = "ResponseFormat",
27+
classes = @ConstructorResult(
28+
targetClass = ResponseFormat.class,
29+
columns = {
30+
@ColumnResult(name = "movie_format")
31+
}
32+
)
33+
),
34+
@SqlResultSetMapping(
35+
name = "ResponseCinema",
36+
classes = @ConstructorResult(
37+
targetClass = ResponseCinema.class,
38+
columns = {
39+
@ColumnResult(name = "cinema_id"),
40+
@ColumnResult(name = "cinema_name"),
41+
@ColumnResult(name = "cinema_address")
42+
}
43+
)
44+
),
45+
@SqlResultSetMapping(
46+
name = "showSchedule",
47+
classes = @ConstructorResult(
48+
targetClass = ResponseScheduleCinema.class,
49+
columns = {
50+
@ColumnResult(name = "cinema_id"),
51+
@ColumnResult(name = "cinema_name"),
52+
@ColumnResult(name = "cinema_data", type = String.class)
53+
}
54+
)
55+
)
56+
})
57+
58+
/*
59+
SELECT
60+
schedule.schedule_id, schedule.schedule_start
61+
FROM
62+
movies, schedule, room, cinemas
63+
WHERE
64+
movies.movie_id = schedule.movie_id
65+
AND schedule.room_id = room.room_id
66+
AND room.cinema_id = cinemas.cinema_id
67+
AND movies.movie_id = ?1
68+
AND schedule.schedule_date = ?2
69+
AND cinemas.cinema_id = ?3
70+
*/
71+
@NamedNativeQuery(name = "getScheduleTimeByFilm", resultSetMapping = "ResponseScheduleTime",
72+
query = "SELECT `schedule`.`schedule_id`, `schedule`.`schedule_start` " +
73+
"FROM `movies`,`schedule`,`room`,`cinemas` " +
74+
"WHERE `movies`.`movie_id` = `schedule`.`movie_id` AND `schedule`.`room_id` = `room`.`room_id`AND `room`.`cinema_id` = `cinemas`.`cinema_id` AND `movies`.`movie_id` = ?1 AND `schedule`.`schedule_date` = ?2 AND `cinemas`.`cinema_id` = ?3"
75+
)
76+
77+
/*
78+
SELECT
79+
movies.movie_format
80+
FROM
81+
movies, schedule, room, cinemas
82+
WHERE
83+
movies.movie_id = schedule.movie_id
84+
AND schedule.room_id = room.room_id
85+
AND room.cinema_id = cinemas.cinema_id
86+
AND movies.movie_id = ?1
87+
AND schedule.schedule_date = ?2
88+
AND cinemas.cinema_id = ?3
89+
GROUP BY
90+
movies.movie_format
91+
*/
92+
@NamedNativeQuery(name = "getScheduleFormat", resultSetMapping = "ResponseFormat",
93+
query = "SELECT `movies`.`movie_format` " +
94+
"FROM `movies`,`schedule`,`room`,`cinemas` " +
95+
"WHERE `movies`.`movie_id` = `schedule`.`movie_id` AND `schedule`.`room_id` = `room`.`room_id`AND `room`.`cinema_id` = `cinemas`.`cinema_id` AND `movies`.`movie_id` = ?1 AND `schedule`.`schedule_date` = ?2 AND `cinemas`.`cinema_id` = ?3 " +
96+
"GROUP BY `movies`.`movie_format`"
97+
)
98+
99+
/*
100+
SELECT
101+
cinemas.*
102+
FROM
103+
cinemas,
104+
schedule,
105+
room
106+
WHERE
107+
schedule.room_id = room.room_id
108+
AND room.cinema_id = cinemas.cinema_id
109+
AND schedule.movie_id = ?1
110+
AND schedule.schedule_date = ?2
111+
*/
112+
@NamedNativeQuery(name = "getResponseCinema", resultSetMapping = "ResponseCinema",
113+
query = "SELECT `cinemas`.* " +
114+
"FROM `cinemas`, `schedule`, `room` " +
115+
"WHERE `schedule`.`room_id` = `room`.`room_id` AND `room`.`cinema_id` = `cinemas`.`cinema_id` AND `schedule`.`movie_id` = ?1 AND `schedule`.`schedule_date` = ?2"
116+
)
117+
118+
/*
119+
SELECT
120+
d.cinema_id,
121+
d.cinema_name,
122+
JSON_ARRAYAGG(
123+
JSON_OBJECT(
124+
'schedule_id', d.schedule_id,
125+
'schedule_start', TIME_FORMAT(schedule_start, '%H:%i'),
126+
'seat_empty', d.seatempty
127+
)
128+
) as cinema_data
129+
FROM (
130+
SELECT
131+
sdl.schedule_id,
132+
sdl.schedule_start,
133+
cinemas.cinema_id,
134+
cinemas.cinema_name,
135+
(
136+
SELECT
137+
COUNT(seats.seat_id)
138+
FROM
139+
seats
140+
WHERE
141+
seats.room_id = room.room_id
142+
AND seats.seat_id NOT IN (
143+
SELECT
144+
booking.seat_id
145+
FROM
146+
booking
147+
WHERE
148+
booking.schedule_id = sdl.schedule_id
149+
)
150+
) as seatempty
151+
FROM
152+
schedule sdl
153+
INNER JOIN room room ON sdl.room_id = room.room_id
154+
INNER JOIN cinemas cinemas ON cinemas.cinema_id = room.cinema_id
155+
WHERE
156+
sdl.movie_id = ?1
157+
AND sdl.schedule_date = ?2
158+
) d
159+
GROUP BY
160+
d.cinema_id,
161+
d.cinema_name
162+
*/
163+
@NamedNativeQuery(name = "showSchedule", resultSetMapping = "showSchedule",
164+
query = "SELECT d.cinema_id, d.cinema_name, (JSON_ARRAYAGG(JSON_OBJECT('schedule_id', d.schedule_id, 'schedule_start', TIME_FORMAT(schedule_start, '%H:%i'), 'seat_empty', d.seatempty))) as cinema_data " +
165+
"FROM ( " +
166+
"SELECT sdl.schedule_id, sdl.schedule_start, cinemas.cinema_id, cinemas.cinema_name, (SELECT COUNT(seats.seat_id) slots FROM seats seats WHERE seats.room_id = room.room_id AND seats.seat_id NOT IN (SELECT booking.seat_id FROM booking booking WHERE booking.schedule_id = sdl.schedule_id)) as seatempty FROM schedule sdl INNER JOIN room room ON sdl.room_id = room.room_id INNER JOIN cinemas cinemas ON cinemas.cinema_id = room.cinema_id WHERE sdl.movie_id = ?1 AND sdl.schedule_date = ?2) d " +
167+
"GROUP BY d.cinema_id, d.cinema_name"
168+
)
169+
170+
@Setter
171+
@Getter
172+
@NoArgsConstructor
173+
@AllArgsConstructor
174+
@Entity
175+
@Table(name = "schedule")
176+
public class Schedule {
177+
@Id
178+
@GeneratedValue(strategy = GenerationType.AUTO)
179+
@Column(name = "schedule_id")
180+
private int scheduleId;
181+
182+
@Column(name = "movie_id")
183+
private int movieId;
184+
185+
@Column(name = "room_id")
186+
private int roomId;
187+
188+
@Column(name = "schedule_date")
189+
private String scheduleDate;
190+
191+
@Column(name = "schedule_start")
192+
private String scheduleStart;
193+
194+
@Column(name = "schedule_end")
195+
private String scheduleEnd;
196+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package com.hoangtien2k3.ticketbookingapi.entity;
2+
3+
import com.hoangtien2k3.ticketbookingapi.model.ResponseSeat;
4+
import jakarta.persistence.*;
5+
import lombok.AllArgsConstructor;
6+
import lombok.Getter;
7+
import lombok.NoArgsConstructor;
8+
import lombok.Setter;
9+
10+
@SqlResultSetMappings({
11+
@SqlResultSetMapping(
12+
name = "ResponseSeatEmpty",
13+
classes = @ConstructorResult(
14+
targetClass = ResponseSeat.class,
15+
columns = {
16+
@ColumnResult(name = "row"),
17+
@ColumnResult(name = "seats", type = String.class)
18+
}
19+
)
20+
)
21+
})
22+
@NamedNativeQuery(name = "getSeatEmpty", resultSetMapping = "ResponseSeatEmpty",
23+
query = "SELECT d.seat_row as row, JSON_ARRAYAGG(JSON_OBJECT('seat_id', d.seat_id, 'seat_type', d.seat_type, 'number', d.seat_number, 'seat_status', d.seat_status)) seats " +
24+
"FROM (" +
25+
"SELECT `seats`.`seat_id`, `seats`.`seat_type`,`seats`.`seat_row`, `seats`.`seat_number`, `booking`.`seat_status` FROM `schedule`, `seats` " +
26+
"LEFT JOIN `booking` ON `seats`.`seat_id` = `booking`.`seat_id` " +
27+
"WHERE `schedule`.`room_id` = `seats`.`room_id` AND `schedule`.`schedule_id` = ?1) d GROUP BY d.seat_row"
28+
)
29+
30+
@Setter
31+
@Getter
32+
@NoArgsConstructor
33+
@AllArgsConstructor
34+
@Entity
35+
@Table(name = "seats")
36+
public class Seat {
37+
@Id
38+
@GeneratedValue(strategy = GenerationType.AUTO)
39+
@Column(name = "seat_id")
40+
private int seatId;
41+
@Column(name = "seat_type")
42+
private int seatType;
43+
@Column(name = "room_id")
44+
private int roomId;
45+
@Column(name = "seat_row")
46+
private String seatRow;
47+
@Column(name = "seat_number")
48+
private int seatNumber;
49+
}

0 commit comments

Comments
 (0)