MusicGroupCalenderRefundPeriodMapper.xml 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  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="order_nos_" property="orderNos" />
  12. <result column="cooperation_organ_id_" property="cooperationOrganId" />
  13. <result column="calender_id_" property="calenderId" />
  14. <result column="refund_date_" property="refundDate" />
  15. <result column="refund_amount_" property="refundAmount" />
  16. <result column="income_" property="income" />
  17. <result column="sub_refund_amount_" property="subRefundAmount" />
  18. <result column="refund_flag_" property="refundFlag" />
  19. <result column="create_time_" property="createTime" />
  20. <result column="update_time_" property="updateTime" />
  21. </resultMap>
  22. <update id="batchUpdate">
  23. <foreach collection="refundPeriods" item="bean" index="index" open="" close="" separator=";">
  24. UPDATE music_group_calender_refund_period <set>
  25. <if test="bean.orderNos != null and bean.orderNos != ''">
  26. order_nos_ = #{bean.orderNos},
  27. </if>
  28. <if test="bean.subRefundAmount != null">
  29. sub_refund_amount_ = #{bean.subRefundAmount},
  30. </if>
  31. <if test="bean.income != null">
  32. income_ = #{bean.income},
  33. </if>
  34. <if test="bean.refundFlag != null">
  35. refund_flag_ = #{bean.refundFlag},
  36. </if>
  37. update_time_ = #{bean.updateTime}
  38. </set> WHERE id_ = #{bean.id}
  39. </foreach>
  40. </update>
  41. <delete id="deleteByCalenderId">
  42. DELETE FROM music_group_calender_refund_period WHERE calender_id_ = #{calenderId}
  43. </delete>
  44. <!-- 全查询 -->
  45. <select id="findAll" resultMap="MusicGroupCalenderRefundPeriod">
  46. SELECT * FROM music_group_calender_refund_period
  47. </select>
  48. <!-- 向数据库增加一条记录 -->
  49. <insert id="insert" parameterType="com.ym.mec.biz.dal.entity.MusicGroupCalenderRefundPeriod" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
  50. INSERT INTO music_group_calender_refund_period (organ_id_,cooperation_organ_id_,calender_id_,
  51. refund_date_,refund_amount_,sub_refund_amount_,income_,refund_flag_,order_nos_,create_time_,update_time_)
  52. VALUES(#{organId},#{cooperationOrganId},#{calenderId},#{refundDate},#{refundAmount},#{subRefundAmount},#{income},#{refundFlag},#{orderNos},NOW(),NOW())
  53. </insert>
  54. <insert id="batchInsert">
  55. INSERT INTO music_group_calender_refund_period (organ_id_,cooperation_organ_id_,calender_id_,
  56. refund_date_,refund_amount_,sub_refund_amount_,income_,refund_flag_,order_nos_,create_time_,update_time_)
  57. VALUES
  58. <foreach collection="refundPeriods" separator="," item="bean">
  59. (#{bean.organId},#{bean.cooperationOrganId},#{bean.calenderId},#{bean.refundDate},
  60. #{bean.refundAmount},#{bean.subRefundAmount},#{bean.income},#{bean.refundFlag},#{bean.orderNos},#{bean.createTime},#{bean.updateTime})
  61. </foreach>
  62. </insert>
  63. <update id="update" parameterType="com.ym.mec.biz.dal.entity.MusicGroupCalenderRefundPeriod">
  64. UPDATE music_group_calender_refund_period <set>
  65. <if test="orderNos != null and orderNos != ''">
  66. order_nos_ = #{orderNos},
  67. </if>
  68. <if test="subRefundAmount != null">
  69. sub_refund_amount_ = #{subRefundAmount},
  70. </if>
  71. <if test="income != null">
  72. income_ = #{income},
  73. </if>
  74. <if test="refundFlag != null">
  75. refund_flag_ = #{refundFlag},
  76. </if>
  77. update_time_ = NOW()
  78. </set> WHERE id_ = #{id}
  79. </update>
  80. <!-- 分页查询 -->
  81. <select id="queryPage" resultMap="MusicGroupCalenderRefundPeriod" parameterType="map">
  82. SELECT * FROM music_group_calender_refund_period <include refid="global.limit"/>
  83. </select>
  84. <!-- 查询当前表的总记录数 -->
  85. <select id="queryCount" resultType="int">
  86. SELECT COUNT(*) FROM music_group_calender_refund_period
  87. </select>
  88. <select id="findByCalenderId" resultMap="MusicGroupCalenderRefundPeriod">
  89. SELECT * FROM music_group_calender_refund_period where calender_id_ = #{calenderId} ORDER BY refund_date_
  90. </select>
  91. <resultMap id="CooperationRefundDto" type="com.ym.mec.biz.dal.dto.CooperationRefundDto">
  92. <result property="organId" column="organ_id_"/>
  93. <result property="cooperationOrganId" column="cooperation_organ_id_"/>
  94. <result property="cooperationOrganName" column="cooperation_organ_name_"/>
  95. <result property="receivable" column="receivable_"/>
  96. <result property="prepaidFee" column="prepaidFee"/>
  97. <result property="educationUserId" column="education_user_id_"/>
  98. </resultMap>
  99. <sql id="queryCoopRefundSql">
  100. <where>
  101. mgpc.status_ IN ('OPEN','OVER','PAID')
  102. <if test="errorType != null and errorType != ''">
  103. <if test="errorType == 'COOPERATION_PAYMENT_ERROR'">
  104. AND TIMESTAMPDIFF(DAY,crp.refund_date_,DATE_FORMAT(NOW(),'%Y-%m-%d')) >= 1
  105. </if>
  106. <if test="errorType == 'COOPERATION_PAYMENT_ALERT'">
  107. AND TIMESTAMPDIFF(DAY,crp.refund_date_,DATE_FORMAT(NOW(),'%Y-%m-%d')) BETWEEN -2 AND 0
  108. </if>
  109. </if>
  110. <if test="organId != null and organId != ''">
  111. AND FIND_IN_SET(crp.organ_id_,#{organId})
  112. </if>
  113. <if test="search != null and search != ''">
  114. AND (co.name_ LIKE CONCAT('%',#{search},'%') OR co.id_ = #{search})
  115. </if>
  116. </where>
  117. </sql>
  118. <select id="countCoopRefund" resultType="java.lang.Integer">
  119. select COUNT(DISTINCT crp.cooperation_organ_id_)
  120. from music_group_calender_refund_period crp
  121. left join cooperation_organ co ON co.id_ = crp.cooperation_organ_id_
  122. left join music_group_payment_calender mgpc ON mgpc.id_ = crp.calender_id_
  123. <include refid="queryCoopRefundSql"/>
  124. </select>
  125. <select id="queryCoopRefund" resultMap="CooperationRefundDto">
  126. select co.organ_id_,crp.cooperation_organ_id_,co.name_ cooperation_organ_name_,
  127. SUM(refund_amount_) receivable_,SUM(sub_refund_amount_) prepaidFee,co.education_user_id_
  128. from music_group_calender_refund_period crp
  129. left join cooperation_organ co ON co.id_ = crp.cooperation_organ_id_
  130. left join music_group_payment_calender mgpc ON mgpc.id_ = crp.calender_id_
  131. <include refid="queryCoopRefundSql"/>
  132. group by crp.cooperation_organ_id_
  133. order by crp.id_ DESC
  134. </select>
  135. <resultMap id="CooperationCalenderRefundDto" type="com.ym.mec.biz.dal.dto.CooperationCalenderRefundDto">
  136. <result property="calenderId" column="calender_id_"/>
  137. <result property="batchNo" column="batch_no_"/>
  138. <result property="paymentType" column="payment_type_"/>
  139. <result property="musicGroupId" column="music_group_id_"/>
  140. <result property="musicGroupName" column="music_group_name_"/>
  141. <result property="calenderFeeType" column="calender_fee_type_"/>
  142. <result property="receivable" column="receivable_"/>
  143. <result property="prepaidFee" column="prepaidFee"/>
  144. <result property="nextRefundDate" column="nextRefundDate"/>
  145. <result property="refundStatus" column="refundStatus"/>
  146. <result property="contractUrl" column="contract_url_"/>
  147. </resultMap>
  148. <sql id="queryCoopCalenderSql">
  149. <where>
  150. <if test="cooperationId != null">
  151. AND crp.cooperation_organ_id_ = #{cooperationId}
  152. </if>
  153. <if test="calenderId != null">
  154. AND crp.calender_id_ = #{calenderId}
  155. </if>
  156. <if test="refundStartDate != null and refundStartDate != ''">
  157. AND crp.refund_date_ BETWEEN #{refundStartDate} AND #{refundEndDate}
  158. </if>
  159. <if test="search != null and search != ''">
  160. AND (mg.name_ LIKE CONCAT('%',#{search},'%') OR mg.id_ = #{search})
  161. </if>
  162. </where>
  163. </sql>
  164. <sql id="queryCoopCalenderHavingSql">
  165. <if test="refundStatus != null and refundStatus != ''">
  166. <if test="refundStatus == 'ING'">
  167. HAVING SUM(crp.sub_refund_amount_) > 0
  168. </if>
  169. <if test="refundStatus == 'END'">
  170. HAVING SUM(crp.sub_refund_amount_) = 0
  171. </if>
  172. </if>
  173. </sql>
  174. <select id="queryCoopCalender" resultMap="CooperationCalenderRefundDto">
  175. select crp.calender_id_,mgpc.music_group_id_,mg.name_ music_group_name_,mgpc.batch_no_,mgpc.payment_type_,mgpc.calender_fee_type_,
  176. SUM(crp.refund_amount_) receivable_,SUM(crp.sub_refund_amount_) prepaidFee,
  177. MIN(CASE WHEN crp.refund_flag_ = 0 THEN crp.refund_date_ ELSE NULL END) nextRefundDate,crp.organ_id_,mgpc.contract_url_
  178. from music_group_calender_refund_period crp
  179. left join music_group_payment_calender mgpc ON mgpc.id_ = crp.calender_id_
  180. left join music_group mg ON mg.id_ = mgpc.music_group_id_
  181. <include refid="queryCoopCalenderSql"/>
  182. group by crp.calender_id_
  183. <include refid="queryCoopCalenderHavingSql"/>
  184. </select>
  185. <select id="countCoopCalender" resultType="java.lang.Integer">
  186. select COUNT(calender_id_) from (select crp.calender_id_
  187. from music_group_calender_refund_period crp
  188. left join music_group_payment_calender mgpc ON mgpc.id_ = crp.calender_id_
  189. left join music_group mg ON mg.id_ = mgpc.music_group_id_
  190. <include refid="queryCoopCalenderSql"/>
  191. group by crp.calender_id_
  192. <include refid="queryCoopCalenderHavingSql"/>)crp
  193. </select>
  194. <select id="sumCoopRefund" resultType="java.math.BigDecimal">
  195. select CASE WHEN crp.id_ IS NULL THEN 0 ELSE SUM(sub_refund_amount_) END from music_group_calender_refund_period crp
  196. left join cooperation_organ co ON co.id_ = crp.cooperation_organ_id_
  197. left join music_group_payment_calender mgpc ON mgpc.id_ = crp.calender_id_
  198. <include refid="queryCoopRefundSql"/>
  199. </select>
  200. </mapper>