DeptBalanceMapper.xml 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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.ydtech.modules.admin.dao.DeptBalanceMapper">
  4. <select id="queryDeptLeaderStatistics" resultType="com.ydtech.modules.admin.model.dto.DeptBalanceDto">
  5. SELECT
  6. sd.id as "deptId",
  7. sd.name as "deptName",
  8. sd.address as "deptAddress",
  9. sa.user_name as "userName",
  10. sd.comlevel as "comLevel",
  11. IFNULL(b.sumPremium,0) as "deptManagementFee",
  12. IFNULL(b.sumPremium,0) * IFNULL((sa.proportional /100),0) as "totalIncome",
  13. IFNULL(b.sumPremium,0) * IFNULL((sa.proportional /100),0) -IFNULL(c.sumHistoryFee,0) as "notWithdrawn",
  14. IFNULL(c.sumHistoryFee,0) as "withdrawn"
  15. FROM
  16. sys_agency_leader sa
  17. LEFT JOIN sys_dept sd ON sd.id = sa.dept_id
  18. LEFT JOIN (
  19. SELECT
  20. io.userid AS "userId",
  21. sum( IFNULL( iac.jqpremium, 0 ) )+ sum(
  22. IFNULL( sypremium, 0 )) + sum(
  23. IFNULL( jypremium, 0 )) AS "sumPremium"
  24. FROM
  25. ins_orders io
  26. LEFT JOIN ins_area_company iac ON iac.orderno = io.orderno
  27. WHERE
  28. iac.orderstatus = '3'
  29. AND io.orderstatus = '3'
  30. GROUP BY
  31. io.userid
  32. ) b ON b.userId = sa.user_id
  33. LEFT JOIN (
  34. SELECT
  35. sum( safa.history_fee ) AS "sumHistoryFee",
  36. safa.user_id AS "userId"
  37. FROM
  38. sys_agency_fee_approval_record safa
  39. WHERE
  40. safa.`status` = '1'
  41. GROUP BY
  42. safa.user_id
  43. ) c ON c.userId = sa.user_id
  44. <where>
  45. 1=1
  46. <if test="vo.provinceId != null and vo.provinceId != ''">
  47. and sd.id like concat('%',#{vo.provinceId},'%')
  48. </if>
  49. <if test="vo.cityId != null and vo.cityId != ''">
  50. and sd.id like concat('%',#{vo.cityId},'%')
  51. </if>
  52. <if test="vo.countyId != null and vo.countyId != ''">
  53. and sd.id like concat('%',#{vo.countyId},'%')
  54. </if>
  55. <if test="vo.houseId != null and vo.houseId != ''">
  56. and sd.id like concat('%',#{vo.houseId},'%')
  57. </if>
  58. </where>
  59. </select>
  60. <select id="queryPartnerStatistics" resultType="com.ydtech.modules.admin.model.dto.SysPartnerConsoleDto">
  61. select
  62. sp.id as "id",
  63. sp.user_id as "userId",
  64. sp.user_name as "userName",
  65. sp.proportional as "proportional",
  66. sp.suggest_id as "suggestId",
  67. sp.suggest_name as "suggestName",
  68. sp.create_time as "createTime",
  69. sp.create_by as "createBy",
  70. sp.del_flag as "delFlag",
  71. sd.name as "deptName"
  72. from sys_partner sp
  73. left join sys_user su on su.id = sp.user_id
  74. left join sys_dept sd on sd.id= su.dept_id
  75. <where>
  76. sp.del_flag='0'
  77. <if test="vo.userId !=null and vo.userId!='' ">
  78. and sp.user_id =#{vo.userId}
  79. </if>
  80. <if test="vo.userIdList !=null and vo.userIdList!='' and vo.userIdList .size() >0">
  81. and a.user_id IN
  82. <foreach item="item" index="index" collection="userIdList" open="(" separator="," close=")">
  83. #{item}
  84. </foreach>
  85. </if>
  86. </where>
  87. </select>
  88. <select id="getByDeptId" resultType="java.util.HashMap">
  89. SELECT
  90. sum(IFNULL(iac.jqpremium,0) + IFNULL(iac.sypremium,0) + IFNULL(iac.jypremium,0)) * (sal.proportional /100) as
  91. "totalIncome",
  92. sum(IFNULL(iac.jqpremium,0) + IFNULL(iac.sypremium,0) + IFNULL(iac.jypremium,0)) * (sal.proportional /100) as
  93. "deptManagementFee"
  94. FROM
  95. ins_orders io
  96. left join ins_area_company iac on iac.orderno =io.orderno
  97. left join sys_agency_leader sal on sal.dept_id = iac.deptid
  98. <where>
  99. io.orderstatus ='3'
  100. and iac.orderstatus ='3'
  101. and sal.del_flag ='1'
  102. <if test="deptId != null and deptId !=''">
  103. iac.deptid =#{deptId}
  104. </if>
  105. </where>
  106. </select>
  107. <select id="getWalletAgent" resultType="com.ydtech.modules.admin.model.dto.SysPartnerConsoleDto">
  108. select
  109. su.id as "userId",
  110. su.name as "userName",
  111. sd.id as "deptId",
  112. sd.name as "deptName",
  113. inf.file_path as "filePath",
  114. suif.sex as "sex"
  115. from sys_user su
  116. left join sys_dept sd on sd.id=su.dept_id
  117. LEFT JOIN ins_upload_files inf on su.head_sculpture =inf.id
  118. LEFT JOIN sys_user_info suif on suif.id =su.id
  119. <where>
  120. 1=1
  121. and su.id LIKE '%M%'
  122. <if test="vo.managementSource !=null and vo.managementSource !=''">
  123. and sd.management_source =#{vo.managementSource}
  124. </if>
  125. <if test="vo.deptId !=null and vo.deptId !=''">
  126. and sd.id like concat('%',#{vo.deptId},'%')
  127. </if>
  128. <if test="vo.phoneNumber !=null and vo.phoneNumber !=''">
  129. and su.mobile =#{vo.phoneNumber}
  130. </if>
  131. <if test="vo.name !=null and vo.name !=''">
  132. and su.name =#{vo.name}
  133. </if>
  134. <if test="vo.userCode !=null and vo.userCode !=''">
  135. and su.id= #{vo.userCode}
  136. </if>
  137. <if test="vo.days !=null and vo.days !='' ">
  138. and su.create_time >= DATE_SUB(NOW(), INTERVAL #{vo.days} DAY)
  139. </if>
  140. <if test="vo.beginDate !=null and vo.beginDate != '' and vo.endDate !=null and vo.endDate != ''">
  141. AND DATE_FORMAT( su.create_time, '%Y-%m-%d') BETWEEN #{vo.beginDate} AND #{vo.endDate}
  142. </if>
  143. </where>
  144. </select>
  145. <select id="getWalletAgentAmount" resultType="java.util.HashMap">
  146. SELECT
  147. sum(IFNULL(iac.jqpremium,0) + IFNULL(iac.sypremium,0) + IFNULL(iac.jypremium,0)) as "totalIncome"
  148. FROM
  149. ins_orders io
  150. left join ins_area_company iac on iac.orderno =io.orderno
  151. <where>
  152. io.orderstatus ='3'
  153. and iac.orderstatus ='3'
  154. <if test="userId != null and userId !=''">
  155. and io.userid =#{userId}
  156. </if>
  157. </where>
  158. </select>
  159. </mapper>