SchoolMapper.xml 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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.ym.mec.biz.dal.dao.SchoolDao">
  8. <resultMap type="com.ym.mec.biz.dal.entity.School" id="School">
  9. <result column="id_" property="id"/>
  10. <result column="user_id_" property="userId"/>
  11. <result column="name_" property="name"/>
  12. <result column="organ_id_" property="organId"/>
  13. <result column="address_" property="address"/>
  14. <result column="contact_phone_" property="contactPhone"/>
  15. <result column="create_time_" property="createTime"/>
  16. <result column="update_time_" property="updateTime"/>
  17. <result column="del_flag_" property="delFlag"/>
  18. <result column="contact_name_" property="contactName"/>
  19. <result column="longitude_latitude_" property="longitudeLatitude"/>
  20. <result column="subsidy_" property="subsidy"/>
  21. <result column="cooperation_organ_id_" property="cooperationOrganId"/>
  22. <result column="remark_" property="remark"/>
  23. </resultMap>
  24. <!-- 根据主键查询一条记录 -->
  25. <select id="get" resultMap="School">
  26. SELECT * FROM school WHERE id_ = #{id}
  27. </select>
  28. <!-- 全查询 -->
  29. <select id="findAll" resultMap="School">
  30. SELECT * FROM school ORDER BY id_
  31. </select>
  32. <!-- 向数据库增加一条记录 -->
  33. <insert id="insert" parameterType="com.ym.mec.biz.dal.entity.School" useGeneratedKeys="true" keyColumn="id"
  34. keyProperty="id">
  35. INSERT INTO school
  36. (id_,user_id_,name_,organ_id_,address_,contact_phone_,create_time_,update_time_,contact_name_,longitude_latitude_,subsidy_,cooperation_organ_id_,remark_)
  37. VALUES(#{id},#{userId},#{name},#{organId},#{address},#{contactPhone},now(),now(),#{contactName},#{longitudeLatitude},#{subsidy},#{cooperationOrganId},#{remark})
  38. </insert>
  39. <!-- 根据主键查询一条记录 -->
  40. <update id="update" parameterType="com.ym.mec.biz.dal.entity.School">
  41. UPDATE school
  42. <set>
  43. <if test="delFlag != null">
  44. del_flag_ = #{delFlag},
  45. </if>
  46. <if test="organId != null">
  47. organ_id_ = #{organId},
  48. </if>
  49. <if test="userId != null">
  50. user_id_ = #{userId},
  51. </if>
  52. <if test="updateTime != null">
  53. update_time_ = NOW(),
  54. </if>
  55. <if test="contactPhone != null">
  56. contact_phone_ = #{contactPhone},
  57. </if>
  58. <if test="longitudeLatitude != null">
  59. longitude_latitude_ = #{longitudeLatitude},
  60. </if>
  61. <if test="address != null">
  62. address_ = #{address},
  63. </if>
  64. <if test="contactName != null">
  65. contact_name_ = #{contactName},
  66. </if>
  67. <if test="name != null">
  68. name_ = #{name},
  69. </if>
  70. <if test="subsidy != null">
  71. subsidy_ = #{subsidy},
  72. </if>
  73. <if test="cooperationOrganId != null">
  74. cooperation_organ_id_ = #{cooperationOrganId},
  75. </if>
  76. <if test="remark != null">
  77. remark_ = #{remark},
  78. </if>
  79. </set>
  80. WHERE id_ = #{id}
  81. </update>
  82. <!-- 根据主键删除一条记录 -->
  83. <delete id="delete">
  84. UPDATE school SET del_flag_ = 1 WHERE id_ = #{id}
  85. </delete>
  86. <!-- 分页查询 -->
  87. <select id="queryPage" resultMap="School" parameterType="map">
  88. SELECT * FROM school where del_flag_ != 1
  89. <if test="cooperationOrganId != null">
  90. AND cooperation_organ_id_ = #{cooperationOrganId}
  91. </if>
  92. <if test="organId != null">
  93. AND FIND_IN_SET(organ_id_,#{organId})
  94. </if>
  95. <if test="search != null">
  96. AND (name_ LIKE CONCAT('%',#{search},'%') OR id_ LIKE CONCAT('%',#{search},'%'))
  97. </if>
  98. ORDER BY id_
  99. <include refid="global.limit"/>
  100. </select>
  101. <!-- 查询当前表的总记录数 -->
  102. <select id="queryCount" resultType="int">
  103. SELECT COUNT(*) FROM school where del_flag_ != 1
  104. <if test="cooperationOrganId != null">
  105. AND cooperation_organ_id_ = #{cooperationOrganId}
  106. </if>
  107. <if test="organId != null">
  108. AND FIND_IN_SET(organ_id_,#{organId})
  109. </if>
  110. <if test="search != null">
  111. AND (name_ LIKE CONCAT('%',#{search},'%') OR id_ LIKE CONCAT('%',#{search},'%'))
  112. </if>
  113. </select>
  114. <select id="queryByOrganId" resultMap="School">
  115. SELECT * FROM school
  116. <where>
  117. del_flag_ = 0 and user_id_ is null
  118. <if test="organId != null">
  119. AND FIND_IN_SET(organ_id_,#{organId})
  120. </if>
  121. </where>
  122. </select>
  123. <select id="queryNameByIds" resultType="java.util.Map" >
  124. select id_ `key`,name_ `value` FROM school s WHERE FIND_IN_SET(id_,#{schoolIds}) AND s.del_flag_ != 1
  125. </select>
  126. <select id="findByUserId" resultMap="School">
  127. select * from school where del_flag_ != 1 and user_id_ = #{userId}
  128. </select>
  129. <select id="findVipSchoolByUserId" resultMap="School">
  130. SELECT * FROM school WHERE del_flag_ != 1
  131. <if test="organId != null">
  132. AND ((FIND_IN_SET(organ_id_,#{organId}) and user_id_ is NULL) or user_id_ = #{userId})
  133. </if>
  134. </select>
  135. <select id="findVipSchoolByUserId2" resultMap="School">
  136. SELECT * FROM school WHERE del_flag_ != 1
  137. AND FIND_IN_SET(organ_id_,#{organId}) AND user_id_ = #{userId}
  138. </select>
  139. <select id="getSchools" resultMap="School">
  140. SELECT * FROM school WHERE id_ IN
  141. <foreach collection="schoolIds" item="schoolId" open="(" close=")" separator=",">
  142. #{schoolId}
  143. </foreach>
  144. </select>
  145. </mapper>