ScheduleMapper.xml 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. and (#{startTime} between start_time and end_time)
  20. or (#{endTime} between start_time and end_time)
  21. or (start_time between #{startTime} and #{endTime})
  22. </select>
  23. <insert id="insertOneView" parameterType="com.example.cinema.vo.ScheduleViewForm"
  24. useGeneratedKeys="true" keyProperty="id">
  25. insert into view(day) values(#{day})
  26. </insert>
  27. <update id="updateOneView" parameterType="com.example.cinema.vo.ScheduleViewForm">
  28. update view set day = #{day}
  29. </update>
  30. <select id="selectViewCount" resultType="int">
  31. select count(*) as num from view
  32. </select>
  33. <delete id="deleteScheduleBatch" parameterType="java.util.List">
  34. delete from schedule where id in
  35. <foreach collection="list" index="index" item="item" open="(" close=")" separator=",">
  36. #{item}
  37. </foreach>
  38. </delete>
  39. <select id="selectScheduleBatch" parameterType="java.util.List" resultMap="ScheduleItem">
  40. select * from schedule where id in
  41. <foreach collection="list" index="index" item="item" open="(" close=")" separator=",">
  42. #{item}
  43. </foreach>
  44. </select>
  45. <select id="selectView" resultType="int">
  46. select day from view limit 1
  47. </select>
  48. <update id="updateScheduleById" parameterType="com.example.cinema.vo.ScheduleForm">
  49. update schedule set hall_id = #{hallId}, movie_id = #{movieId}, start_time = #{startTime},
  50. end_time = #{endTime}, fare = #{fare}
  51. where id = #{id}
  52. </update>
  53. <resultMap id="ScheduleItem" type="com.example.cinema.vo.ScheduleItem">
  54. <id column="id" property="id"></id>
  55. <result column="hall_id" property="hallId"></result>
  56. <result column="movie_id" property="movieId"></result>
  57. <result column="start_time" property="startTime"></result>
  58. <result column="end_time" property="endTime"></result>
  59. <result column="movie_name" property="movieName"></result>
  60. <result column="hall_name" property="hallName"></result>
  61. </resultMap>
  62. </mapper>