ExamOrganizationRelationMapper.xml 13 KB

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