PaymentCollectionMapper.xml 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. <mapper namespace="com.dayou.mapper.PaymentCollectionMapper">
  4. <!-- 通用查询映射结果 -->
  5. <resultMap id="BaseResultMap" type="com.dayou.entity.PaymentCollection">
  6. <result column="id" property="id" />
  7. <result column="deleted" property="deleted" />
  8. <result column="created" property="created" />
  9. <result column="modified" property="modified" />
  10. <result column="item_id" property="itemId" />
  11. <result column="name" property="name" />
  12. <result column="amount" property="amount" />
  13. <result column="payment_date" property="paymentDate" />
  14. </resultMap>
  15. <!-- 通用查询结果列 -->
  16. <sql id="Base_Column_List">
  17. pc.id,
  18. pc.deleted,
  19. pc.created,
  20. pc.modified,
  21. pc.item_id, pc.name, pc.amount, pc.payment_date
  22. </sql>
  23. <sql id="paymentCollectionSql">
  24. select <include refid="Base_Column_List"/>,i.name as itemName
  25. from payment_collection pc left join item i on pc.item_id = i.id
  26. where i.deleted = 0 and pc.deleted = 0
  27. <if test="dto!=null and dto.itemId!=null">
  28. and pc.item_id = #{dto.itemId}
  29. </if>
  30. <if test="dto!=null and dto.itemName!=null and dto.itemName!=''">
  31. and i.name like concat ('%',#{dto.itemName},'%')
  32. </if>
  33. <if test="dto!=null and dto.name!=null and dto.name!=''">
  34. and pc.name like concat ('%',#{dto.name},'%')
  35. </if>
  36. <if test="dto!=null and dto.isCurYear!=null and dto.isCurYear==true">
  37. AND pc.payment_date &gt;= concat( YEAR ( now())- 1, '-12-23' )
  38. AND pc.payment_date &lt;= concat( YEAR ( now()), '-12-22' )
  39. </if>
  40. <if test="dto!=null and dto.isCurMonth!=null and dto.isCurMonth==true">
  41. AND pc.payment_date &gt;= #{dto.lastMonth23}
  42. AND pc.payment_date &lt;= concat( date_format( LAST_DAY( now()), '%Y-%m-' ), '22' )
  43. </if>
  44. <if test="dto!=null and dto.year!=null">
  45. and DATE_FORMAT(pc.payment_date,'%Y') = #{dto.year}
  46. </if>
  47. <if test="dto!=null and dto.month!=null">
  48. and DATE_FORMAT(pc.payment_date,'%c') = #{dto.month}
  49. </if>
  50. <if test="dto!=null and dto.userIds!=null and dto.userIds.size!=0">
  51. and i.user_id in
  52. <foreach collection="dto.userIds" open="(" close=")" separator="," item="userId">
  53. #{userId}
  54. </foreach>
  55. </if>
  56. <if test="dto!=null and dto.startDate!=null and dto.endDate!=null">
  57. AND pc.created BETWEEN #{dto.startDate} AND #{dto.endDate}
  58. </if>
  59. order by pc.payment_date DESC
  60. </sql>
  61. <select id="page" parameterType="com.dayou.vo.PaymentCollectionVO" resultType="com.dayou.vo.PaymentCollectionVO">
  62. <include refid="paymentCollectionSql"/>
  63. </select>
  64. <select id="exportPaymentCollection" resultType="com.dayou.vo.PaymentCollectionVO">
  65. <include refid="paymentCollectionSql"/>
  66. </select>
  67. <sql id="itemPaymentList">
  68. SELECT
  69. i.id,
  70. i.business_no,
  71. i.oa_no,
  72. i.NAME,
  73. i.client_unit,
  74. u.name as client_manager,
  75. i.sign_date,
  76. i.amount,
  77. off.id as orderFundId,
  78. ifnull(( SELECT sum( amount ) FROM payment_collection WHERE item_id = i.id AND deleted = 0 ), 0 ) AS payedAmount,
  79. (
  80. i.amount -(
  81. ifnull(( SELECT sum( amount ) FROM payment_collection WHERE item_id = i.id AND deleted = 0 ), 0 ))) AS NotPayedAmount
  82. FROM
  83. item i
  84. left join (select id,business_id from order_fund where business_type='ITEM_BUSINESS' AND deleted = 0) off on off.business_id = i.id
  85. left join user u on u.id = i.user_id
  86. WHERE
  87. i.deleted =0
  88. <if test="dto!=null and dto.itemName!=null and dto.itemName!=''">
  89. and i.name like concat ('%',#{dto.itemName},'%')
  90. </if>
  91. <if test="dto!=null and dto.userIds!=null and dto.userIds.size!=0">
  92. and i.user_id in
  93. <foreach collection="dto.userIds" open="(" close=")" separator="," item="userId">
  94. #{userId}
  95. </foreach>
  96. </if>
  97. order by i.id DESC
  98. </sql>
  99. <select id="getItemPayment" parameterType="com.dayou.vo.PaymentCollectionVO" resultType="com.dayou.vo.ItemPaymentVO">
  100. <include refid="itemPaymentList"/>
  101. </select>
  102. <select id="getDeleted" parameterType="java.lang.Long" resultType="com.dayou.entity.PaymentCollection">
  103. select * from payment_collection where id = #{id} and deleted = 1
  104. </select>
  105. <select id="getPaymentDetailListByItemId" resultType="com.dayou.dto.PaymentDetailDTO">
  106. SELECT
  107. i.id AS itemId,
  108. pc.id AS paymentId,
  109. pc.amount AS paymentAmount,
  110. i.upload_date
  111. FROM
  112. `payment_collection` pc
  113. LEFT JOIN item i ON i.id = pc.item_id
  114. LEFT JOIN brokerage_variable bv ON bv.payment_id = pc.id
  115. WHERE
  116. pc.payment_date &gt;= concat( YEAR ( now())- 1, '-12-23' )
  117. AND pc.payment_date &lt;= concat( YEAR ( now()), '-12-22' )
  118. AND i.id = #{itemId}
  119. AND NOT EXISTS(select * from brokerage_variable where user_id = #{userId} and payment_id= pc.id and deleted = 0)
  120. AND pc.deleted = 0
  121. AND i.deleted = 0
  122. </select>
  123. <select id="getList" parameterType="com.dayou.vo.PaymentCollectionVO" resultType="com.dayou.dto.PaymentExportDTO">
  124. <include refid="itemPaymentList"/>
  125. </select>
  126. </mapper>