BusinessIncomeMapper.xml 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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.BusinessIncomeMapper">
  4. <select id="myMajorIncome" parameterType="com.dayou.vo.UserCommissionProdVO" resultType="com.dayou.vo.UserCommissionProdVO">
  5. SELECT
  6. mpa.id,
  7. fc.claim_amount as realAmount,
  8. mp.report_no,
  9. IF
  10. ( fc.claim_datetime > mp.save_file_date, fc.claim_datetime, mp.save_file_date ) AS settleDate,
  11. mp.NAME,
  12. mp.created,
  13. dd.NAME AS businessCate,
  14. bcr.min_ratio AS ratio,
  15. mpa.user_id,
  16. mpa.ratio AS allotRatio,
  17. ( fc.claim_amount * ( bcr.min_ratio / 100 )* mpa.ratio ) AS commissionAmount,
  18. ( fc.claim_amount * ( bcr.min_ratio / 100 ) ) AS totalAmount,
  19. u.name as userName,
  20. (case mpa.user_type when 'EVALUATE' then '评估人员' else '市场人员' end) as userType
  21. FROM
  22. (
  23. SELECT
  24. claim_amount,
  25. order_fund_id,
  26. production_fund_id,
  27. claim_datetime
  28. FROM
  29. finance_claim
  30. WHERE
  31. deleted = 0
  32. AND production_fund_id IS NOT NULL
  33. AND claim_datetime &gt;= #{vo.startDate}
  34. AND claim_datetime &lt;= #{vo.endDate}
  35. UNION ALL
  36. SELECT
  37. allot_amount AS claim_amount,
  38. order_fund_id,
  39. production_fund_id,
  40. created AS claim_datetime
  41. FROM
  42. order_fund_allot
  43. WHERE
  44. deleted = 0
  45. AND created &gt;= #{vo.startDate}
  46. AND created &lt;= #{vo.endDate}
  47. ) fc
  48. INNER JOIN ( SELECT id,order_fund_id, business_id, production_no FROM production_fund WHERE business_type = 'MAJOR_BUSINESS' AND deleted = 0 ) pf ON ( pf.id = fc.production_fund_id AND pf.order_fund_id = fc.order_fund_id )
  49. INNER JOIN ( SELECT id, major_id, NAME, report_no, production, save_file_date, delivery_date,created FROM major_production WHERE deleted = 0 ) mp ON mp.report_no = pf.production_no
  50. LEFT JOIN major m ON m.id = mp.major_id
  51. INNER JOIN ( SELECT id,business_id, production_id, business_type ,commission_rate_id FROM commission_declare WHERE deleted = 0 AND declare_result = '审核通过' ) cd ON (
  52. cd.business_id = m.id
  53. AND ( cd.production_id IS NULL OR cd.production_id = mp.id ))
  54. LEFT JOIN business_commission_rate bcr ON bcr.id = cd.commission_rate_id
  55. LEFT JOIN dict_data dd ON dd.id = bcr.business_cate_id
  56. LEFT JOIN ( SELECT id,major_id,user_type, major_production_id, user_id, ratio ,declare_id FROM major_production_allot WHERE deleted = 0 ) mpa
  57. ON ( mpa.major_id = m.id and (mpa.major_production_id is null or mpa.major_production_id = mp.id )
  58. and if(mpa.user_type='MARKET','COMMISSION_DECLARE_MAJOR_MARKET','COMMISSION_DECLARE_MAJOR_EVALUATE') = cd.business_type
  59. )
  60. and if(mpa.user_type='MARKET',mp.delivery_date is not null,mp.save_file_date is not null)
  61. left join user u on u.id = mpa.user_id
  62. WHERE
  63. u.id= #{vo.userId}
  64. order by settleDate DESC
  65. </select>
  66. <!--资产业务我的提成-->
  67. <select id="myAssetsIncome" resultType="com.dayou.vo.UserCommissionProdVO">
  68. SELECT
  69. bpd.id,
  70. fc.claim_amount as realAmount,
  71. ap.production_no,
  72. IF ( fc.claim_datetime > ap.save_file_date, fc.claim_datetime, ap.save_file_date ) AS settleDate,
  73. ap.created,
  74. dd.NAME AS businessCate,
  75. cd.ratio AS ratio,
  76. bpd.member_id,
  77. bpd.performance_distribution AS allotRatio,
  78. IF ( bcr.low_limit_amount > fc.claim_amount, fc.claim_amount * ( cd.ratio / 100 ) * bpd.performance_distribution, bcr.low_limit_amount * ( cd.ratio / 100 ) * bpd.performance_distribution) AS commissionAmount,
  79. IF ( bcr.low_limit_amount > fc.claim_amount, fc.claim_amount * ( cd.ratio / 100 ), bcr.low_limit_amount * ( cd.ratio / 100 )) AS commissionAmount,
  80. u.name as userName,
  81. (case bpd.user_type when 'EVALUATE' then '评估人员' else '市场人员' end) as userType
  82. FROM
  83. (
  84. SELECT
  85. claim_amount,
  86. order_fund_id,
  87. production_fund_id,
  88. claim_datetime
  89. FROM
  90. finance_claim
  91. WHERE
  92. deleted = 0
  93. AND production_fund_id IS NOT NULL
  94. AND claim_datetime &gt;= #{vo.startDate}
  95. AND claim_datetime &lt;= #{vo.endDate}
  96. UNION ALL
  97. SELECT
  98. allot_amount AS claim_amount,
  99. order_fund_id,
  100. production_fund_id,
  101. created AS claim_datetime
  102. FROM
  103. order_fund_allot
  104. WHERE
  105. deleted = 0
  106. AND created &gt;= #{vo.startDate}
  107. AND created &lt;= #{vo.endDate}
  108. ) fc
  109. INNER JOIN ( SELECT id,order_fund_id, business_id, production_no FROM production_fund WHERE business_type = 'ASSET_BUSINESS' AND deleted = 0 ) pf ON ( pf.id = fc.production_fund_id AND pf.order_fund_id = fc.order_fund_id )
  110. INNER JOIN ( SELECT id, business_id, production_no, production_type, save_file_date, delivery,created FROM assets_production WHERE deleted = 0 ) ap ON ap.production_no = pf.production_no
  111. LEFT JOIN assets a ON a.id = ap.business_id
  112. INNER JOIN ( SELECT id,business_id, production_id, business_type ,commission_rate_id, ratio FROM commission_declare WHERE deleted = 0 AND declare_result = '审核通过' ) cd ON (
  113. cd.business_id = a.id
  114. AND ( cd.production_id IS NULL OR cd.production_id = ap.id ))
  115. LEFT JOIN business_commission_rate bcr ON bcr.id = cd.commission_rate_id
  116. LEFT JOIN dict_data dd ON dd.id = bcr.business_cate_id
  117. LEFT JOIN ( SELECT id,business_id,user_type, report_no, member_id, performance_distribution ,declare_id FROM business_performance_distribution WHERE deleted = 0 ) bpd
  118. ON ( bpd.business_id = a.id and (bpd.report_no is null or bpd.report_no = ap.id )
  119. and if(bpd.user_type='MARKET','COMMISSION_DECLARE_ASSET_MARKET','COMMISSION_DECLARE_ASSET_EVALUATE') = cd.business_type
  120. )
  121. and if(bpd.user_type='MARKET',ap.delivery = true, ap.save_file_date is not null)
  122. left join user u on u.id = bpd.member_id
  123. WHERE
  124. u.id= #{vo.userId}
  125. order by settleDate DESC
  126. </select>
  127. </mapper>