SubjectMapper.xml 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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.SubjectDao">
  8. <resultMap type="com.keao.edu.user.entity.Subject" id="Subject">
  9. <result column="id_" property="id"/>
  10. <result column="name_" property="name"/>
  11. <result column="code_" property="code"/>
  12. <result column="parent_subject_id_" property="parentSubjectId"/>
  13. <result column="parent_name_" property="parentName"/>
  14. <result column="img_" property="img"/>
  15. <result column="create_time_" property="createTime"/>
  16. <result column="update_time_" property="updateTime"/>
  17. <result column="del_flag_" property="delFlag"/>
  18. <result column="tenant_id_" property="tenantId"/>
  19. </resultMap>
  20. <!-- 根据主键查询一条记录 -->
  21. <select id="get" resultMap="Subject">
  22. SELECT * FROM subject WHERE id_ = #{id}
  23. </select>
  24. <!-- 全查询 -->
  25. <select id="findAll" resultMap="Subject">
  26. SELECT * FROM subject WHERE tenant_id_ = #{tenantId} ORDER BY id_
  27. </select>
  28. <!-- 向数据库增加一条记录 -->
  29. <insert id="insert" parameterType="com.keao.edu.user.entity.Subject" useGeneratedKeys="true" keyColumn="id"
  30. keyProperty="id">
  31. INSERT INTO subject (id_,name_,code_,parent_subject_id_,img_,create_time_,update_time_,tenant_id_)
  32. VALUES(#{id},#{name},#{code},#{parentSubjectId},#{img},now(),now(),#{tenantId})
  33. </insert>
  34. <!-- 根据主键查询一条记录 -->
  35. <update id="update" parameterType="com.keao.edu.user.entity.Subject">
  36. UPDATE subject
  37. <set>
  38. <if test="delFlag != null">
  39. del_flag_ = #{delFlag},
  40. </if>
  41. <if test="parentSubjectId != null">
  42. parent_subject_id_ = #{parentSubjectId},
  43. </if>
  44. <if test="code != null">
  45. code_ = #{code},
  46. </if>
  47. <if test="img != null">
  48. img_ = #{img},
  49. </if>
  50. <if test="updateTime != null">
  51. update_time_ = NOW(),
  52. </if>
  53. <if test="name != null">
  54. name_ = #{name},
  55. </if>
  56. <if test="tenantId!=null">
  57. tenant_id_ = #{tenantId},
  58. </if>
  59. </set>
  60. WHERE id_ = #{id}
  61. </update>
  62. <!-- 根据主键删除一条记录 -->
  63. <update id="delete">
  64. UPDATE `subject` SET del_flag_ = 1 WHERE id_ = #{id} OR parent_subject_id_ = #{id}
  65. </update>
  66. <!-- 分页查询 -->
  67. <select id="queryPage" resultMap="Subject" parameterType="map">
  68. SELECT s.*,sp.name_ parent_name_ FROM subject s
  69. LEFT JOIN `subject` sp ON s.parent_subject_id_ = sp.id_
  70. <include refid="querySubPageSql"/>
  71. ORDER BY s.id_
  72. <include refid="global.limit"/>
  73. </select>
  74. <!-- 查询当前表的总记录数 -->
  75. <select id="queryCount" resultType="int">
  76. SELECT COUNT(*) FROM subject s <include refid="querySubPageSql"/>
  77. </select>
  78. <select id="findByParentId" resultMap="Subject">
  79. SELECT * FROM subject s <include refid="querySubPageSql"/>
  80. </select>
  81. <select id="findBySubIds" resultType="string">
  82. SELECT name_ FROM `subject` WHERE del_flag_ = 0 AND FIND_IN_SET (id_,#{subIds})
  83. </select>
  84. <select id="queryNameByIds" resultType="java.util.Map">
  85. select id_ `key`,name_ `value` FROM `subject` s
  86. WHERE FIND_IN_SET(s.id_,#{subjectIds}) AND s.del_flag_ = 0
  87. AND tenant_id_ = #{tenantId}
  88. </select>
  89. <select id="findSubSubjects" resultMap="Subject">
  90. SELECT * FROM `subject`
  91. WHERE parent_subject_id_ != 0 AND del_flag_ = 0
  92. <if test="tenantId != null and tenantId != 0">
  93. AND tenant_id_ = #{tenantId}
  94. </if>
  95. </select>
  96. <sql id="querySubPageSql">
  97. <where>
  98. <if test="tenantId != null and tenantId != 0">
  99. AND s.tenant_id_ = #{tenantId}
  100. </if>
  101. <if test="parentId != null">
  102. AND s.parent_subject_id_ = #{parentId}
  103. </if>
  104. <if test="parentId == null">
  105. AND s.parent_subject_id_ != 0
  106. </if>
  107. <if test="delFlag != null">
  108. AND s.del_flag_ = #{delFlag}
  109. </if>
  110. </where>
  111. </sql>
  112. <select id="findBySubjectByIdList" resultMap="Subject">
  113. SELECT * FROM `subject` WHERE del_flag_ = 0 AND FIND_IN_SET(id_,#{subjectIdList})
  114. </select>
  115. <select id="findNames" resultType="java.lang.String">
  116. SELECT GROUP_CONCAT(DISTINCT s.name_) FROM `subject` s WHERE FIND_IN_SET(s.id_,#{subjectIdList})
  117. </select>
  118. <select id="findBySubjectIds" resultMap="Subject">
  119. SELECT * FROM subject WHERE id_ IN
  120. <foreach collection="subjectIds" item="subjectId" separator="," open="(" close=")">
  121. #{subjectId}
  122. </foreach>
  123. </select>
  124. <select id="countExamSubject" resultType="java.lang.Integer">
  125. SELECT COUNT(0) FROM exam_subject es
  126. WHERE es.subject_id_ IN (SELECT s.id_ FROM `subject` s WHERE s.id_ = #{id});
  127. </select>
  128. </mapper>