ScheduleMapper.xml 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  3. <mapper namespace="com.example.cinema.data.ScheduleMapper">
  4. <insert id="insertOneSchedule" parameterType="com.example.cinema.vo.ScheduleForm"
  5. useGeneratedKeys="true" keyProperty="id">
  6. insert into schedule(hall_id, movie_id, start_time, end_time, fare)
  7. values(#{hallId}, #{movieId}, #{startTime}, #{endTime}, #{fare})
  8. </insert>
  9. <select id="selectSchedule" resultMap="ScheduleItem">
  10. select * from
  11. (select * from schedule where hall_id = #{hallId} and start_time between #{startDate} and #{endDate}) s,
  12. (select name as movie_name, id as movie_id from movie) m,
  13. (select name as hall_name, id as hall_id from hall) h
  14. where s.movie_id = m.movie_id and s.hall_id = h.hall_id
  15. </select>
  16. <select id="selectScheduleConflictByHallIdAndTime" resultMap="ScheduleItem">
  17. select * from schedule
  18. where hall_id = #{hallId}
  19. <if test="#{id} != null">
  20. and id != #{id}
  21. </if>
  22. and ((#{startTime} between start_time and end_time)
  23. or (#{endTime} between start_time and end_time)
  24. or (start_time between #{startTime} and #{endTime}))
  25. </select>
  26. <select id="selectScheduleByMovieIdList" resultMap="ScheduleItem" parameterType="java.util.List">
  27. select * from schedule where movie_id in
  28. <foreach collection="list" index="index" item="item" open="(" close=")" separator=",">
  29. #{item}
  30. </foreach>
  31. </select>
  32. <insert id="insertOneView" parameterType="com.example.cinema.vo.ScheduleViewForm"
  33. useGeneratedKeys="true" keyProperty="id">
  34. insert into view(day) values(#{day})
  35. </insert>
  36. <update id="updateOneView" parameterType="com.example.cinema.vo.ScheduleViewForm">
  37. update view set day = #{day}
  38. </update>
  39. <select id="selectViewCount" resultType="int">
  40. select count(*) as num from view
  41. </select>
  42. <delete id="deleteScheduleBatch" parameterType="java.util.List">
  43. delete from schedule where id in
  44. <foreach collection="list" index="index" item="item" open="(" close=")" separator=",">
  45. #{item}
  46. </foreach>
  47. </delete>
  48. <select id="selectScheduleBatch" parameterType="java.util.List" resultMap="ScheduleItem">
  49. select * from schedule where id in
  50. <foreach collection="list" index="index" item="item" open="(" close=")" separator=",">
  51. #{item}
  52. </foreach>
  53. </select>
  54. <select id="selectView" resultType="int">
  55. select day from view limit 1
  56. </select>
  57. <update id="updateScheduleById" parameterType="com.example.cinema.vo.ScheduleForm">
  58. update schedule set hall_id = #{hallId}, movie_id = #{movieId}, start_time = #{startTime},
  59. end_time = #{endTime}, fare = #{fare}
  60. where id = #{id}
  61. </update>
  62. <select id="selectScheduleById" resultMap="ScheduleItem">
  63. select * from
  64. (select * from schedule where id = #{id}) s,
  65. (select name as movie_name, id as movie_id from movie) m,
  66. (select name as hall_name, id as hall_id from hall) h
  67. where s.movie_id = m.movie_id and s.hall_id = h.hall_id
  68. </select>
  69. <resultMap id="ScheduleItem" type="com.example.cinema.vo.ScheduleItem">
  70. <id column="id" property="id"></id>
  71. <result column="hall_id" property="hallId"></result>
  72. <result column="movie_id" property="movieId"></result>
  73. <result column="start_time" property="startTime"></result>
  74. <result column="end_time" property="endTime"></result>
  75. <result column="movie_name" property="movieName"></result>
  76. <result column="hall_name" property="hallName"></result>
  77. </resultMap>
  78. </mapper>