MusicGroupCalenderRefundPeriodMapper.xml 10 KB

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