ItemBrokerageTechnicistDeductionMapper.xml 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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.ItemBrokerageTechnicistDeductionMapper">
  4. <!-- 通用查询映射结果 -->
  5. <resultMap id="BaseResultMap" type="com.dayou.entity.ItemBrokerageTechnicistDeduction">
  6. <result column="id" property="id" />
  7. <result column="created" property="created" />
  8. <result column="brokerage_technicist_id" property="brokerageTechnicistId" />
  9. <result column="brokerage_sequence_id" property="brokerageSequenceId" />
  10. <result column="deduction_amount" property="deductionAmount" />
  11. </resultMap>
  12. <resultMap id="deductionRecordsMap" type="com.dayou.vo.TechDeductionVO">
  13. <result column="id" property="id" />
  14. <result column="userId" property="userId" />
  15. <result column="userName" property="userName"/>
  16. <result column="year" property="year"/>
  17. <result column="month" property="month"/>
  18. <result column="brokerageAmount" property="brokerageAmount"/>
  19. <result column="cate" property="cate"/>
  20. <result column="created" property="created"/>
  21. <result column="notDeductionAmount" property="notDeductionAmount"/>
  22. <collection property="deductionRecords" ofType="com.dayou.vo.DeductionVO" select="selectDeductionRecords" column="id"/>
  23. </resultMap>
  24. <!-- 通用查询结果列 -->
  25. <sql id="Base_Column_List">
  26. id,
  27. created,
  28. brokerage_technicist_id, brokerage_sequence_id,deduction_amount
  29. </sql>
  30. <select id="notDeductionDefaultSettle" parameterType="java.lang.Long" resultType="com.dayou.dto.DeductionDTO">
  31. SELECT
  32. ibs.id as sequenceId,
  33. ibs.brokerage_amount as totalAmount,
  34. (ibs.brokerage_amount- ifnull(ibtd.deduDone,0)) as notDeduAmount
  35. FROM
  36. item_brokerage_sequence ibs
  37. LEFT JOIN (select brokerage_sequence_id,sum(deduction_amount) as deduDone from item_brokerage_technicist_deduction GROUP BY brokerage_sequence_id) ibtd ON ibtd.brokerage_sequence_id = ibs.id
  38. WHERE
  39. ibs.user_id = #{userId} and ibs.cate = 'DEFAULT_AHEAD' and
  40. ifnull(ibtd.deduDone,0) &lt; ibs.brokerage_amount
  41. order by ibs.id ASC
  42. </select>
  43. <select id="xPage" parameterType="com.dayou.vo.TechDeductionVO" resultMap="deductionRecordsMap">
  44. SELECT
  45. ibs.id,
  46. u.id AS userId,
  47. u.NAME AS userName,
  48. ibs.YEAR,
  49. ibs.MONTH,
  50. ibs.cate,
  51. ibs.brokerage_amount AS brokerageAmount,
  52. ibs.created,
  53. (ibs.brokerage_amount - ifnull( ibtd.deduDone, 0 )) AS notDeductionAmount
  54. FROM
  55. item_brokerage_sequence ibs
  56. LEFT JOIN ( SELECT brokerage_sequence_id, sum( deduction_amount ) AS deduDone FROM item_brokerage_technicist_deduction WHERE deleted = 0 GROUP BY brokerage_sequence_id ) ibtd ON ibtd.brokerage_sequence_id = ibs.id
  57. LEFT JOIN user u ON u.id = ibs.user_id
  58. WHERE
  59. ibs.user_id = #{vo.userId} and ibs.deleted = 0 and ibs.cate = 'DEFAULT_AHEAD'
  60. <if test="vo.cate!=null and vo.cate!='' ">
  61. and ibs.cate = #{vo.cate}
  62. </if>
  63. <if test="vo.year!=null ">
  64. and ibs.year = #{vo.year}
  65. </if>
  66. <if test="vo.month!=null ">
  67. and ibs.month = #{vo.month}
  68. </if>
  69. order by ibs.id DESC
  70. </select>
  71. <select id="selectDeductionRecords" parameterType="java.lang.Long" resultType="com.dayou.vo.DeductionVO">
  72. SELECT
  73. ibtd.deduction_amount,
  74. ibtd.created ,
  75. ibt.amount as settleAmount,
  76. i.name as itemName,
  77. i.id as itemId,
  78. ibs.year,
  79. ibs.month,
  80. ibs.cate as settleCate
  81. FROM
  82. item_brokerage_technicist_deduction ibtd
  83. LEFT JOIN item_brokerage_technicist ibt on ibtd.brokerage_technicist_id = ibt.id
  84. left join item i on i.id = ibt.item_id
  85. left join item_brokerage_sequence ibs on ibs.id = ibt.sequence_id
  86. where ibtd.deleted = 0 and ibt.deleted =0 and ibs.deleted = 0 and ibtd.brokerage_sequence_id = #{id}
  87. order by ibtd.id DESC
  88. </select>
  89. <select id="poolResidueAmount" parameterType="java.lang.Long" resultType="java.math.BigDecimal">
  90. SELECT
  91. (
  92. ( SELECT ifnull( sum( residue_amount ), 0 ) FROM `item_brokerage_technicist` WHERE user_id = #{userId} AND deleted = 0 ) -(
  93. SELECT
  94. ifnull( sum( ibs.brokerage_amount ), 0 ) - ifnull(sum( ibtd.deductionAmount ),0)
  95. FROM
  96. item_brokerage_sequence ibs
  97. LEFT JOIN ( SELECT brokerage_sequence_id AS seId, sum( deduction_amount ) AS deductionAmount FROM item_brokerage_technicist_deduction GROUP BY brokerage_sequence_id ) ibtd ON ibs.id = ibtd.seId
  98. WHERE
  99. ibs.user_id = #{userId}
  100. AND ibs.cate = 'DEFAULT_AHEAD'
  101. AND ibs.deleted = 0
  102. )
  103. ) AS poolResidueAmount;
  104. </select>
  105. </mapper>