MusicGroupCalenderRefundPeriodMapper.xml 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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.MusicGroupCalenderRefundPeriodDao">
  8. <resultMap type="com.ym.mec.biz.dal.entity.MusicGroupCalenderRefundPeriod" id="MusicGroupCalenderRefundPeriod">
  9. <result column="id_" property="id" />
  10. <result column="organ_id_" property="organId" />
  11. <result column="cooperation_organ_id_" property="cooperationOrganId" />
  12. <result column="calender_id_" property="calenderId" />
  13. <result column="refund_date_" property="refundDate" />
  14. <result column="refund_amount_" property="refundAmount" />
  15. <result column="sub_refund_amount_" property="subRefundAmount" />
  16. <result column="create_time_" property="createTime" />
  17. <result column="update_time_" property="updateTime" />
  18. </resultMap>
  19. <delete id="deleteByCalenderId">
  20. DELETE FROM music_group_calender_refund_period WHERE calender_id_ = #{calenderId}
  21. </delete>
  22. <!-- 全查询 -->
  23. <select id="findAll" resultMap="MusicGroupCalenderRefundPeriod">
  24. SELECT * FROM music_group_calender_refund_period
  25. </select>
  26. <!-- 向数据库增加一条记录 -->
  27. <insert id="insert" parameterType="com.ym.mec.biz.dal.entity.MusicGroupCalenderRefundPeriod" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
  28. INSERT INTO music_group_calender_refund_period (organ_id_,cooperation_organ_id_,calender_id_,
  29. refund_date_,refund_amount_,sub_refund_amount_,create_time_,update_time_)
  30. VALUES(#{organId},#{cooperationOrganId},#{calenderId},#{refundDate},#{refundAmount},#{subRefundAmount},NOW(),NOW())
  31. </insert>
  32. <insert id="batchInsert">
  33. INSERT INTO music_group_calender_refund_period (organ_id_,cooperation_organ_id_,calender_id_,
  34. refund_date_,refund_amount_,sub_refund_amount_,create_time_,update_time_)
  35. VALUES
  36. <foreach collection="refundPeriods" separator="," item="bean">
  37. (#{bean.organId},#{bean.cooperationOrganId},#{bean.calenderId},#{bean.refundDate},
  38. #{bean.refundAmount},#{bean.subRefundAmount},#{bean.createTime},#{bean.updateTime})
  39. </foreach>
  40. </insert>
  41. <!-- 分页查询 -->
  42. <select id="queryPage" resultMap="MusicGroupCalenderRefundPeriod" parameterType="map">
  43. SELECT * FROM music_group_calender_refund_period <include refid="global.limit"/>
  44. </select>
  45. <!-- 查询当前表的总记录数 -->
  46. <select id="queryCount" resultType="int">
  47. SELECT COUNT(*) FROM music_group_calender_refund_period
  48. </select>
  49. <select id="findByCalenderId" resultMap="MusicGroupCalenderRefundPeriod">
  50. SELECT * FROM music_group_calender_refund_period where calender_id_ = #{calenderId} ORDER BY refund_date_
  51. </select>
  52. <resultMap id="CooperationRefundDto" type="com.ym.mec.biz.dal.dto.CooperationRefundDto">
  53. <result property="organId" column="organ_id_"/>
  54. <result property="cooperationOrganId" column="cooperation_organ_id_"/>
  55. <result property="cooperationOrganName" column="cooperation_organ_name_"/>
  56. <result property="receivable" column="receivable_"/>
  57. <result property="prepaidFee" column="prepaidFee"/>
  58. <result property="educationUserId" column="education_user_id_"/>
  59. </resultMap>
  60. <sql id="queryCoopRefundSql">
  61. <where>
  62. <if test="organId != null and organId != ''">
  63. AND FIND_IN_SET(co.organ_id_,#{organId})
  64. </if>
  65. <if test="search != null and search != ''">
  66. AND (co.name_ LIKE CONCAT('%',#{search},'%') OR co.id_ = #{search})
  67. </if>
  68. </where>
  69. </sql>
  70. <select id="countCoopRefund" resultType="java.lang.Integer">
  71. select COUNT(DISTINCT crp.cooperation_organ_id_)
  72. from music_group_calender_refund_period crp
  73. left join cooperation_organ co ON co.id_ = crp.cooperation_organ_id_
  74. <include refid="queryCoopRefundSql"/>
  75. </select>
  76. <select id="queryCoopRefund" resultMap="CooperationRefundDto">
  77. select co.organ_id_,crp.cooperation_organ_id_,co.name_ cooperation_organ_name_,
  78. SUM(refund_amount_) receivable_,SUM(sub_refund_amount_) prepaidFee,co.education_user_id_
  79. from music_group_calender_refund_period crp
  80. left join cooperation_organ co ON co.id_ = crp.cooperation_organ_id_
  81. <include refid="queryCoopRefundSql"/>
  82. group by crp.cooperation_organ_id_
  83. order by crp.id_ DESC
  84. </select>
  85. <resultMap id="CooperationCalenderRefundDto" type="com.ym.mec.biz.dal.dto.CooperationCalenderRefundDto">
  86. <result property="calenderId" column="calender_id_"/>
  87. <result property="batchNo" column="batch_no_"/>
  88. <result property="paymentType" column="payment_type_"/>
  89. <result property="musicGroupId" column="music_group_id_"/>
  90. <result property="musicGroupName" column="music_group_name_"/>
  91. <result property="calenderFeeType" column="calender_fee_type_"/>
  92. <result property="receivable" column="receivable_"/>
  93. <result property="prepaidFee" column="prepaidFee"/>
  94. <result property="nextRefundDate" column="nextRefundDate"/>
  95. <result property="refundStatus" column="refundStatus"/>
  96. </resultMap>
  97. <sql id="queryCoopCalenderSql">
  98. <if test="calenderId != null">
  99. AND crp.calender_id_
  100. </if>
  101. <if test="refundStartDate != null and refundStartDate != ''">
  102. AND crp.refund_date_ BETWEEN #{refundStartDate} AND #{refundEndDate}
  103. </if>
  104. <if test="search != '' and search != ''">
  105. AND (mg.name_ LIKE CONCAT('%',#{search},'%') OR mg.id_ = #{search})
  106. </if>
  107. </sql>
  108. <sql id="queryCoopCalenderHavingSql">
  109. <if test="refundStatus != null and refundStatus != ''">
  110. <if test="refundStatus = 'ING'">
  111. HAVING SUM(crp.sub_refund_amount_) > 0
  112. </if>
  113. <if test="refundStatus = 'END'">
  114. HAVING SUM(crp.sub_refund_amount_) = 0
  115. </if>
  116. </if>
  117. </sql>
  118. <select id="queryCoopCalender" resultMap="CooperationCalenderRefundDto">
  119. select crp.calender_id_,mgpc.music_group_id_,mg.name_ music_group_name_,mgpc.batch_no_,mgpc.payment_type_,mgpc.calender_fee_type_,
  120. SUM(crp.refund_amount_) receivable_,SUM(crp.sub_refund_amount_) prepaidFee,
  121. MIN(CASE WHEN crp.refund_flag_ = 0 THEN crp.refund_date_ ELSE NULL END) nextRefundDate
  122. from music_group_calender_refund_period crp
  123. left join music_group_payment_calender mgpc ON mgpc.id_ = crp.calender_id_
  124. left join music_group mg ON mg.id_ = mgpc.music_group_id_
  125. <include refid="queryCoopCalenderSql"/>
  126. group by crp.calender_id_
  127. <include refid="queryCoopCalenderHavingSql"/>
  128. </select>
  129. <select id="countCoopCalender" resultType="java.lang.Integer">
  130. select COUNT(calender_id_) from (select crp.calender_id_
  131. from music_group_calender_refund_period crp
  132. left join music_group_payment_calender mgpc ON mgpc.id_ = crp.calender_id_
  133. left join music_group mg ON mg.id_ = mgpc.music_group_id_
  134. <include refid="queryCoopCalenderSql"/>
  135. group by crp.calender_id_
  136. <include refid="queryCoopCalenderHavingSql"/>)crp
  137. </select>
  138. <select id="sumCoopRefund" resultType="java.math.BigDecimal">
  139. select CASE WHEN crp.id_ IS NULL THEN 0 ELSE SUM(refund_amount_) - SUM(sub_refund_amount_) END from music_group_calender_refund_period crp
  140. left join cooperation_organ co ON co.id_ = crp.cooperation_organ_id_
  141. <include refid="queryCoopRefundSql"/>
  142. </select>
  143. </mapper>