ExamInfoMapper.xml 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!DOCTYPE mapper
  3. PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  4. "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  5. <mapper namespace="com.miaxis.exam.mapper.ExamInfoMapper">
  6. <resultMap type="ExamInfo" id="ExamInfoResult">
  7. <result property="id" column="id" />
  8. <result property="name" column="name" />
  9. <result property="image" column="image" />
  10. <result property="provinceId" column="province_id" />
  11. <result property="province" column="province" />
  12. <result property="cityId" column="city_id" />
  13. <result property="city" column="city" />
  14. <result property="price" column="price" />
  15. <result property="createTime" column="create_time" />
  16. <result property="updateTime" column="update_time" />
  17. </resultMap>
  18. <select id="selectExamInfoList" parameterType="ExamInfo" resultMap="ExamInfoResult">
  19. select * from exam_info
  20. <where>
  21. <if test="name != null and name != ''"> and name like concat('%', #{name}, '%')</if>
  22. <if test="image != null and image != ''"> and image = #{image}</if>
  23. <if test="provinceId != null and provinceId != ''"> and province_id = #{provinceId}</if>
  24. <if test="province != null and province != ''"> and province = #{province}</if>
  25. <if test="cityId != null and cityId != ''"> and city_id = #{cityId}</if>
  26. <if test="city != null and city != ''"> and city = #{city}</if>
  27. </where>
  28. </select>
  29. <sql id="selectExamInfoVo">
  30. select *,(select count(1) from vip_exam_video v where v.exam_id = e.id) as video_count from exam_info e
  31. </sql>
  32. <select id="selectExamInfoList" parameterType="com.miaxis.exam.dto.ExamInfoDto" resultType="com.miaxis.exam.vo.ExamInfoVipVo">
  33. SELECT e.*,
  34. (SELECT COUNT(1) FROM vip_exam_video v WHERE v.exam_id = e.id) AS video_count,
  35. (SELECT expiration_time FROM vip_user_exam WHERE e.id = exam_id AND user_id = #{userId} AND NOW() <![CDATA[<=]]> expiration_time) AS expiration_time,
  36. (CASE WHEN NOW() <![CDATA[<=]]> (SELECT expiration_time FROM vip_user_exam WHERE e.id = exam_id AND user_id = #{userId}) THEN 1 ELSE 0 END) AS is_vip
  37. FROM exam_info e
  38. <where>
  39. <if test="province != null and province != ''" > AND e.province = #{province}</if>
  40. <if test="provinceId != null and provinceId != ''" > AND e.province_id = #{provinceId}</if>
  41. <if test="cityId != null and cityId != ''" > AND e.city_id = #{cityId}</if>
  42. <if test="city != null and city != ''" > AND e.city = #{city}</if>
  43. <if test="name != null and name != ''"> and e.name like concat('%', #{name}, '%')</if>
  44. </where>
  45. </select>
  46. <select id="selectMyExamInfoList" parameterType="com.miaxis.exam.dto.ExamInfoDto" resultType="com.miaxis.exam.vo.ExamInfoVipVo">
  47. SELECT e.*,
  48. (SELECT COUNT(1) FROM vip_exam_video v WHERE v.exam_id = e.id) AS video_count,
  49. (SELECT expiration_time FROM vip_user_exam WHERE e.id = exam_id AND user_id = #{userId} AND NOW() <![CDATA[<=]]> expiration_time) AS expiration_time,
  50. (CASE WHEN NOW() <![CDATA[<=]]> (SELECT expiration_time FROM vip_user_exam WHERE e.id = exam_id AND user_id = #{userId}) THEN 1 ELSE 0 END) AS is_vip
  51. FROM exam_info e join vip_user_exam vu on e.id = vu.exam_id
  52. <where>
  53. <if test="province != null and province != ''" > AND e.province = #{province}</if>
  54. <if test="provinceId != null and provinceId != ''" > AND e.province_id = #{provinceId}</if>
  55. <if test="cityId != null and cityId != ''" > AND e.city_id = #{cityId}</if>
  56. <if test="city != null and city != ''" > AND e.city = #{city}</if>
  57. <if test="name != null and name != ''"> and e.name like concat('%', #{name}, '%')</if>
  58. <if test="userId != null"> and vu.user_id = #{userId}</if>
  59. </where>
  60. </select>
  61. <!--
  62. <select id="selectExamInfoList" parameterType="ExamInfo" resultMap="ExamInfoResult">
  63. <include refid="selectExamInfoVo"/>
  64. <where>
  65. <if test="name != null and name != ''"> and name like concat('%', #{name}, '%')</if>
  66. <if test="image != null and image != ''"> and image = #{image}</if>
  67. <if test="provinceId != null and provinceId != ''"> and province_id = #{provinceId}</if>
  68. <if test="province != null and province != ''"> and province = #{province}</if>
  69. <if test="cityId != null and cityId != ''"> and city_id = #{cityId}</if>
  70. <if test="city != null and city != ''"> and city = #{city}</if>
  71. </where>
  72. </select>
  73. -->
  74. <select id="getProvice" resultType="com.miaxis.exam.vo.ExamInfoProviceVo">
  75. select province_id,province from exam_info group by province_id,province
  76. </select>
  77. <select id="getCity" resultType="com.miaxis.exam.vo.ExamInfoCityVo">
  78. select city_id,city from exam_info where province_id = #{provinceId}
  79. GROUP BY city_id,city
  80. </select>
  81. </mapper>