PaymentCollectionMapper.xml 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. <select id="page" parameterType="com.dayou.vo.PaymentCollectionVO" resultType="com.dayou.vo.PaymentCollectionVO">
  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. order by pc.payment_date DESC
  57. </select>
  58. <sql id="itemPaymentList">
  59. SELECT
  60. i.id,
  61. i.business_no,
  62. i.oa_no,
  63. i.NAME,
  64. i.client_unit,
  65. u.name as client_manager,
  66. i.sign_date,
  67. i.amount,
  68. ifnull(( SELECT sum( amount ) FROM payment_collection WHERE item_id = i.id AND deleted = 0 ), 0 ) AS payedAmount,
  69. (
  70. i.amount -(
  71. ifnull(( SELECT sum( amount ) FROM payment_collection WHERE item_id = i.id AND deleted = 0 ), 0 ))) AS NotPayedAmount
  72. FROM
  73. item i left join user u on u.id = i.user_id
  74. WHERE
  75. i.deleted =0
  76. <if test="dto!=null and dto.itemName!=null and dto.itemName!=''">
  77. and i.name like concat ('%',#{dto.itemName},'%')
  78. </if>
  79. <if test="dto!=null and dto.userIds!=null and dto.userIds.size!=0">
  80. and i.user_id in
  81. <foreach collection="dto.userIds" open="(" close=")" separator="," item="userId">
  82. #{userId}
  83. </foreach>
  84. </if>
  85. order by i.id DESC
  86. </sql>
  87. <select id="getItemPayment" parameterType="com.dayou.vo.PaymentCollectionVO" resultType="com.dayou.vo.ItemPaymentVO">
  88. <include refid="itemPaymentList"/>
  89. </select>
  90. <select id="getDeleted" parameterType="java.lang.Long" resultType="com.dayou.entity.PaymentCollection">
  91. select * from payment_collection where id = #{id} and deleted = 1
  92. </select>
  93. <select id="getPaymentDetailListByItemId" resultType="com.dayou.dto.PaymentDetailDTO">
  94. SELECT
  95. i.id AS itemId,
  96. pc.id AS paymentId,
  97. pc.amount AS paymentAmount,
  98. i.upload_date
  99. FROM
  100. `payment_collection` pc
  101. LEFT JOIN item i ON i.id = pc.item_id
  102. LEFT JOIN brokerage_variable bv ON bv.payment_id = pc.id
  103. WHERE
  104. pc.payment_date &gt;= concat( YEAR ( now())- 1, '-12-23' )
  105. AND pc.payment_date &lt;= concat( YEAR ( now()), '-12-22' )
  106. AND i.id = #{itemId}
  107. AND NOT EXISTS(select * from brokerage_variable where user_id = #{userId} and payment_id= pc.id and deleted = 0)
  108. AND pc.deleted = 0
  109. AND i.deleted = 0
  110. </select>
  111. <select id="getList" parameterType="com.dayou.vo.PaymentCollectionVO" resultType="com.dayou.dto.PaymentExportDTO">
  112. <include refid="itemPaymentList"/>
  113. </select>
  114. </mapper>