ExamSubjectMapper.xml 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. <!--
  4. 这个文件是自动生成的。
  5. 不要修改此文件。所有改动将在下次重新自动生成时丢失。
  6. -->
  7. <mapper namespace="com.keao.edu.user.dao.ExamSubjectDao">
  8. <resultMap type="com.keao.edu.user.entity.ExamSubject" id="ExamSubject">
  9. <result column="id_" property="id" />
  10. <result column="examination_basic_id_" property="examinationBasicId" />
  11. <result column="subject_id_" property="subjectId" />
  12. <result column="create_time_" property="createTime" />
  13. <result column="update_time_" property="updateTime" />
  14. <result column="tenant_id_" property="tenantId" />
  15. </resultMap>
  16. <!-- 根据主键查询一条记录 -->
  17. <select id="get" resultMap="ExamSubject" >
  18. SELECT * FROM exam_subject WHERE id_ = #{id}
  19. </select>
  20. <!-- 全查询 -->
  21. <select id="findAll" resultMap="ExamSubject">
  22. SELECT * FROM exam_subject ORDER BY id_
  23. </select>
  24. <!-- 向数据库增加一条记录 -->
  25. <insert id="insert" parameterType="com.keao.edu.user.entity.ExamSubject" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
  26. INSERT INTO exam_subject (id_,examination_basic_id_,subject_id_,create_time_,update_time_,tenant_id_)
  27. VALUES(#{id},#{examinationBasicId},#{subjectId},NOW(),NOW(),#{tenantId})
  28. </insert>
  29. <insert id="batchInsert">
  30. INSERT INTO exam_subject (examination_basic_id_,subject_id_,create_time_,update_time_,tenant_id_)
  31. VALUES
  32. <foreach collection="examSubjects" item="examSubject" separator=",">
  33. (#{examSubject.examinationBasicId},#{examSubject.subjectId},NOW(),NOW(),#{examSubject.tenantId})
  34. </foreach>
  35. </insert>
  36. <!-- 根据主键查询一条记录 -->
  37. <update id="update" parameterType="com.keao.edu.user.entity.ExamSubject">
  38. UPDATE exam_subject <set>
  39. <if test="examinationBasicId != null">
  40. examination_basic_id_ = #{examinationBasicId},
  41. </if>
  42. <if test="subjectId != null">
  43. subject_id_ = #{subjectId},
  44. </if>
  45. <if test="id != null">
  46. id_ = #{id},
  47. </if>
  48. <if test="tenantId != null and tenantId != 0">
  49. tenant_id_ = #{tenantId},
  50. </if>
  51. update_time_ = NOW()
  52. </set> WHERE id_ = #{id}
  53. </update>
  54. <!-- 根据主键删除一条记录 -->
  55. <delete id="delete" >
  56. DELETE FROM exam_subject WHERE id_ = #{id}
  57. </delete>
  58. <delete id="deleteWithExamSubject">
  59. DELETE FROM exam_subject WHERE examination_basic_id_=#{examId} AND subject_id_=#{subjectId}
  60. </delete>
  61. <!-- 分页查询 -->
  62. <select id="queryPage" resultMap="ExamSubject" parameterType="map">
  63. SELECT * FROM exam_subject ORDER BY id_
  64. <include refid="global.limit"/>
  65. </select>
  66. <!-- 查询当前表的总记录数 -->
  67. <select id="queryCount" resultType="int">
  68. SELECT COUNT(*) FROM exam_subject
  69. </select>
  70. <select id="getWithTenant" resultMap="ExamSubject">
  71. SELECT * FROM exam_subject WHERE examination_basic_id_=#{examId}
  72. </select>
  73. <resultMap id="ExamSubjectDto" type="com.keao.edu.user.dto.ExamSubjectDto" extends="com.keao.edu.user.dao.SubjectDao.Subject" >
  74. <result column="exam_subject_id_" property="examSubjectId" />
  75. </resultMap>
  76. <select id="getSubjectWithExamId" resultMap="ExamSubjectDto">
  77. SELECT es.id_ exam_subject_id_ ,s.* FROM exam_subject es
  78. LEFT JOIN subject s on es.subject_id_ = s.id_ WHERE examination_basic_id_ = #{examId}
  79. </select>
  80. <select id="getUnRelatedWithExamSubjects" resultMap="com.keao.edu.user.dao.SubjectDao.Subject">
  81. SELECT
  82. *
  83. FROM
  84. `subject` s
  85. WHERE
  86. s.parent_subject_id_ != 0
  87. AND s.del_flag_ = 0
  88. AND s.tenant_id_ = #{tenantId}
  89. AND NOT EXISTS (SELECT subject_id_ FROM exam_subject WHERE examination_basic_id_=#{examId} AND subject_id_=s.id_)
  90. </select>
  91. </mapper>