ExamOrganizationRelationMapper.xml 13 KB

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