ExamOrganizationRelationMapper.xml 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  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.ExamOrganizationRelationDao">
  8. <resultMap type="com.keao.edu.user.entity.ExamOrganizationRelation" id="ExamOrganizationRelation">
  9. <result column="id_" property="id" />
  10. <result column="examination_basic_id_" property="examinationBasicId" />
  11. <result column="organ_id_" property="organId" />
  12. <result column="settlement_type_" property="settlementType" typeHandler="com.keao.edu.common.dal.CustomEnumTypeHandler" />
  13. <result column="share_profit_amount_" property="shareProfitAmount" />
  14. <result column="total_registration_student_num_" property="totalRegistrationStudentNum"/>
  15. <result column="total_payment_amount_" property="totalPaymentAmount"/>
  16. <result column="url_" property="url" />
  17. <result column="send_url_flag_" property="sendUrlFlag" typeHandler="com.keao.edu.common.dal.CustomEnumTypeHandler" />
  18. <result column="is_allow_arrange_exam_" property="isAllowArrangeExam" typeHandler="com.keao.edu.common.dal.CustomEnumTypeHandler" />
  19. <result column="create_time_" property="createTime" />
  20. <result column="update_time_" property="updateTime" />
  21. <result column="tenant_id_" property="tenantId" />
  22. </resultMap>
  23. <resultMap id="ExamOrganizationRelationExtraDto" type="com.keao.edu.user.dto.ExamOrganizationRelationExtraDto" extends="ExamOrganizationRelation">
  24. <result column="organ_name_" property="organizationName"/>
  25. </resultMap>
  26. <!-- 根据主键查询一条记录 -->
  27. <select id="get" resultMap="ExamOrganizationRelation" >
  28. SELECT * FROM exam_organization_relation WHERE id_ = #{id}
  29. </select>
  30. <!-- 全查询 -->
  31. <select id="findAll" resultMap="ExamOrganizationRelation">
  32. SELECT * FROM exam_organization_relation WHERE tenant_id_#{tenantId} ORDER BY id_
  33. </select>
  34. <!-- 向数据库增加一条记录 -->
  35. <insert id="insert" parameterType="com.keao.edu.user.entity.ExamOrganizationRelation" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
  36. INSERT INTO exam_organization_relation (examination_basic_id_,organ_id_,settlement_type_,share_profit_amount_,total_registration_student_num_,total_payment_amount_,url_,send_url_flag_,is_allow_arrange_exam_,create_time_,update_time_,tenant_id_)
  37. VALUES(#{examinationBasicId},#{organId},#{settlementType,typeHandler=com.keao.edu.common.dal.CustomEnumTypeHandler},#{shareProfitAmount},#{totalRegistrationStudentNum},#{totalPaymentAmount},#{url},#{sendUrlFlag,typeHandler=com.keao.edu.common.dal.CustomEnumTypeHandler},#{isAllowArrangeExam,typeHandler=com.keao.edu.common.dal.CustomEnumTypeHandler},NOW(),NOW(),#{tenantId})
  38. </insert>
  39. <insert id="batchInsert" parameterType="com.keao.edu.user.entity.ExamOrganizationRelation" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
  40. INSERT INTO exam_organization_relation (examination_basic_id_,organ_id_,settlement_type_,share_profit_amount_,total_registration_student_num_,total_payment_amount_,url_,send_url_flag_,is_allow_arrange_exam_,create_time_,update_time_,tenant_id_)
  41. VALUES
  42. <foreach collection="examOrganizationRelations" item="examOrganizationRelation" separator=",">
  43. (#{examOrganizationRelation.examinationBasicId},#{examOrganizationRelation.organId},#{examOrganizationRelation.settlementType,typeHandler=com.keao.edu.common.dal.CustomEnumTypeHandler},#{examOrganizationRelation.shareProfitAmount},#{examOrganizationRelation.totalRegistrationStudentNum},#{examOrganizationRelation.totalPaymentAmount},#{examOrganizationRelation.url},#{examOrganizationRelation.sendUrlFlag,typeHandler=com.keao.edu.common.dal.CustomEnumTypeHandler},#{examOrganizationRelation.isAllowArrangeExam,typeHandler=com.keao.edu.common.dal.CustomEnumTypeHandler},NOW(),NOW(),#{examOrganizationRelation.tenantId})
  44. </foreach>
  45. </insert>
  46. <!-- 根据主键查询一条记录 -->
  47. <update id="update" parameterType="com.keao.edu.user.entity.ExamOrganizationRelation">
  48. UPDATE exam_organization_relation
  49. <set>
  50. <if test="examinationBasicId != null">
  51. examination_basic_id_ = #{examinationBasicId},
  52. </if>
  53. <if test="id != null">
  54. id_ = #{id},
  55. </if>
  56. <if test="sendUrlFlag != null">
  57. send_url_flag_ = #{sendUrlFlag,typeHandler=com.keao.edu.common.dal.CustomEnumTypeHandler},
  58. </if>
  59. <if test="isAllowArrangeExam != null">
  60. is_allow_arrange_exam_ = #{isAllowArrangeExam,typeHandler=com.keao.edu.common.dal.CustomEnumTypeHandler},
  61. </if>
  62. <if test="url != null">
  63. url_ = #{url},
  64. </if>
  65. <if test="tenantId != null">
  66. tenant_id_ = #{tenantId},
  67. </if>
  68. <if test="shareProfitAmount != null">
  69. share_profit_amount_ = #{shareProfitAmount},
  70. </if>
  71. <if test="totalRegistrationStudentNum != null">
  72. total_registration_student_num_ = #{totalRegistrationStudentNum},
  73. </if>
  74. <if test="totalPaymentAmount != null">
  75. total_payment_amount_ = #{totalPaymentAmount},
  76. </if>
  77. <if test="organId != null">
  78. organ_id_ = #{organId},
  79. </if>
  80. <if test="settlementType != null">
  81. settlement_type_ = #{settlementType,typeHandler=com.keao.edu.common.dal.CustomEnumTypeHandler},
  82. </if>
  83. update_time_ = NOW()
  84. </set> WHERE id_ = #{id}
  85. </update>
  86. <update id="batchUpdate" parameterType="com.keao.edu.user.entity.ExamOrganizationRelation">
  87. <foreach collection="examOrganizationRelations" item="eo" separator=";">
  88. UPDATE exam_organization_relation
  89. <set>
  90. <if test="eo.examinationBasicId != null">
  91. examination_basic_id_ = #{eo.examinationBasicId},
  92. </if>
  93. <if test="eo.sendUrlFlag != null">
  94. send_url_flag_ = #{eo.sendUrlFlag,typeHandler=com.keao.edu.common.dal.CustomEnumTypeHandler},
  95. </if>
  96. <if test="eo.isAllowArrangeExam != null">
  97. is_allow_arrange_exam_ = #{eo.isAllowArrangeExam,typeHandler=com.keao.edu.common.dal.CustomEnumTypeHandler},
  98. </if>
  99. <if test="eo.url != null">
  100. url_ = #{eo.url},
  101. </if>
  102. <if test="eo.tenantId != null">
  103. tenant_id_ = #{eo.tenantId},
  104. </if>
  105. <if test="eo.shareProfitAmount != null">
  106. share_profit_amount_ = #{eo.shareProfitAmount},
  107. </if>
  108. <if test="eo.totalRegistrationStudentNum != null">
  109. total_registration_student_num_ = #{eo.totalRegistrationStudentNum},
  110. </if>
  111. <if test="eo.totalPaymentAmount != null">
  112. total_payment_amount_ = #{eo.totalPaymentAmount},
  113. </if>
  114. <if test="eo.organId != null">
  115. organ_id_ = #{eo.organId},
  116. </if>
  117. <if test="eo.settlementType != null">
  118. settlement_type_ = #{eo.settlementType,typeHandler=com.keao.edu.common.dal.CustomEnumTypeHandler},
  119. </if>
  120. update_time_ = NOW()
  121. </set> WHERE id_ = #{eo.id}
  122. </foreach>
  123. </update>
  124. <update id="batchUpdateSendUrlFlag">
  125. UPDATE exam_organization_relation SET send_url_flag_=#{sendUrlFlag,typeHandler=com.keao.edu.common.dal.CustomEnumTypeHandler}
  126. WHERE examination_basic_id_=#{examId}
  127. <if test="organIds!=null">
  128. AND organ_id_ IN
  129. <foreach collection="organIds" item="organId" separator="," open="(" close=")">
  130. #{organId}
  131. </foreach>
  132. </if>
  133. </update>
  134. <!-- 根据主键删除一条记录 -->
  135. <delete id="delete" >
  136. DELETE FROM exam_organization_relation WHERE id_ = #{id}
  137. </delete>
  138. <sql id="queryCondition">
  139. <where>
  140. ear.tenant_id_=#{tenantId}
  141. AND ear.examination_basic_id_=#{examId}
  142. <if test="organIds!=null">
  143. AND ear.organ_id_ IN
  144. <foreach collection="organIds" item="organId" separator="," open="(" close=")">
  145. #{organId}
  146. </foreach>
  147. </if>
  148. <if test="settlementType!=null">
  149. AND ear.settlement_type_=#{settlementType,typeHandler=com.keao.edu.common.dal.CustomEnumTypeHandler}
  150. </if>
  151. <if test="isAllowArrangeExam!=null">
  152. AND ear.is_allow_arrange_exam_ = #{isAllowArrangeExam}
  153. </if>
  154. <if test="search!=null">
  155. AND (ear.organ_id_=#{search} OR a.name_ LIKE CONCAT(#{search}, '%'))
  156. </if>
  157. </where>
  158. </sql>
  159. <!-- 分页查询 -->
  160. <select id="queryPage" resultMap="ExamOrganizationRelationExtraDto" parameterType="map">
  161. SELECT
  162. ear.*,
  163. a.name_ organ_name_
  164. FROM exam_organization_relation ear
  165. LEFT JOIN organization a ON ear.organ_id_=a.id_
  166. <include refid="queryCondition"/>
  167. ORDER BY id_ <include refid="global.limit"/>
  168. </select>
  169. <!-- 查询当前表的总记录数 -->
  170. <select id="queryCount" resultType="int">
  171. SELECT COUNT(*) FROM exam_organization_relation ear
  172. LEFT JOIN organization a ON ear.organ_id_=a.id_
  173. <include refid="queryCondition"/>
  174. </select>
  175. <select id="queryExamOrgans" resultMap="ExamOrganizationRelationExtraDto" parameterType="map">
  176. SELECT
  177. ear.*,
  178. a.name_ organ_name_
  179. FROM exam_organization_relation ear
  180. LEFT JOIN organization a ON ear.organ_id_=a.id_
  181. <include refid="queryCondition"/>
  182. ORDER BY id_ <include refid="global.limit"/>
  183. </select>
  184. <select id="countExamOrgans" resultType="int">
  185. SELECT COUNT(*) FROM exam_organization_relation ear
  186. LEFT JOIN organization a ON ear.organ_id_=a.id_
  187. <include refid="queryCondition"/>
  188. </select>
  189. <select id="getWithExam" resultMap="ExamOrganizationRelation">
  190. SELECT * FROM exam_organization_relation WHERE examination_basic_id_=#{examId}
  191. </select>
  192. <select id="getOrganIdsWithExam" resultType="int">
  193. SELECT organ_id_ FROM exam_organization_relation WHERE examination_basic_id_=#{examId} FOR UPDATE
  194. </select>
  195. <select id="getWithExams" resultMap="ExamOrganizationRelation">
  196. SELECT * FROM exam_organization_relation WHERE examination_basic_id_ IN
  197. <foreach collection="examIds" item="examId" separator="," open="(" close=")">
  198. #{examId}
  199. </foreach>
  200. </select>
  201. <select id="countExamOrganStudentAndPayment" resultMap="ExamOrganizationRelation">
  202. SELECT
  203. o.id_ organ_id_,
  204. SUM(eor.total_registration_student_num_) total_registration_student_num_,
  205. SUM(eor.total_payment_amount_) total_payment_amount_
  206. FROM
  207. organization o
  208. LEFT JOIN (
  209. SELECT
  210. eor1.id_,
  211. eor1.organ_id_,
  212. eor1.total_payment_amount_,
  213. eor1.total_registration_student_num_,
  214. o1.parent_organ_id_tag_
  215. FROM
  216. exam_organization_relation eor1
  217. LEFT JOIN organization o1 ON o1.id_ = eor1.organ_id_
  218. WHERE eor1.examination_basic_id_=#{examId}
  219. ) eor ON eor.parent_organ_id_tag_ LIKE CONCAT( o.parent_organ_id_tag_, '%' )
  220. <if test="organIds!=null">
  221. WHERE
  222. o.id_ IN
  223. <foreach collection="organIds" item="organId" separator="," open="(" close=")">
  224. #{organId}
  225. </foreach>
  226. </if>
  227. GROUP BY o.id_
  228. </select>
  229. <select id="findByOrganId" resultType="java.lang.Integer">
  230. SELECT COUNT(DISTINCT id_) FROM exam_organization_relation WHERE organ_id_ = #{organId}
  231. </select>
  232. <sql id="queryUnRelatedOrgansCondition">
  233. <where>
  234. o.tenant_id_ = #{tenantId}
  235. <if test="organIds!=null">
  236. o.id_ IN
  237. <foreach collection="organIds" item="organId" separator="," open="(" close=")">
  238. #{organId}
  239. </foreach>
  240. </if>
  241. AND NOT EXISTS ( SELECT organ_id_ FROM exam_organization_relation WHERE examination_basic_id_ = #{examId} AND organ_id_ = o.id_ )
  242. </where>
  243. </sql>
  244. <select id="queryUnRelatedOrgans" resultMap="com.keao.edu.user.dao.OrganizationDao.Organization">
  245. SELECT
  246. *
  247. FROM
  248. organization o
  249. <include refid="queryUnRelatedOrgansCondition"/>
  250. ORDER BY o.id_
  251. <include refid="global.limit"/>
  252. </select>
  253. <select id="countUnRelatedOrgans" resultType="int">
  254. SELECT
  255. COUNT(o.id_)
  256. FROM
  257. organization o
  258. <include refid="queryUnRelatedOrgansCondition"/>
  259. </select>
  260. <!-- 获取项目合作机构关联信息 -->
  261. <select id="getExamOrganizationRelation" resultMap="ExamOrganizationRelation">
  262. SELECT * FROM exam_organization_relation WHERE examination_basic_id_=#{examId} AND organ_id_=#{OrganId} FOR UPDATE
  263. </select>
  264. </mapper>