ExamOrganizationRelationMapper.xml 15 KB

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