DeptBalanceMapper.xml 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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.parent_id = sa.dept_id
  18. LEFT JOIN (
  19. SELECT
  20. io.deptid AS "deptId",
  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.deptid
  32. ) b ON b.deptId = sd.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)) as
  91. "totalIncome",
  92. sum(IFNULL(iac.jqpremium,0) + IFNULL(iac.sypremium,0) + IFNULL(iac.jypremium,0)) as
  93. "deptManagementFee"
  94. FROM
  95. ins_area_company iac
  96. left join ins_orders io on iac.orderno = io.orderno
  97. <where>
  98. iac.orderstatus ='3'
  99. <if test="deptId != null and deptId !=''">
  100. and io.deptid like CONCAT( #{deptId}, '%' )
  101. </if>
  102. <if test="createTime != null and createTime !=''">
  103. and io.createtime >= #{createTime}
  104. </if>
  105. <if test="beginDate !=null and beginDate != '' and endDate !=null and endDate != ''">
  106. AND iac.signing_time BETWEEN #{beginDate} AND #{endDate}
  107. </if>
  108. </where>
  109. </select>
  110. <select id="getWalletAgent" resultType="com.ydtech.modules.admin.model.dto.SysPartnerConsoleDto">
  111. select
  112. su.id as "userId",
  113. su.name as "userName",
  114. sd.id as "deptId",
  115. sd.name as "deptName",
  116. inf.url as "filePath",
  117. suif.sex as "sex",
  118. sur.role_id as "roleId",
  119. sd.management_source as managementSource
  120. from sys_user su
  121. left join sys_dept sd on sd.id=su.dept_id
  122. LEFT JOIN ins_upload_files inf on su.head_sculpture =inf.id
  123. LEFT JOIN sys_user_info suif on suif.id =su.id
  124. LEFT JOIN sys_user_role sur ON sur.user_id = su.id
  125. <where>
  126. 1=1
  127. and su.id LIKE '%M%'
  128. and su.status ='1'
  129. <if test="vo.managementSource !=null and vo.managementSource !=''">
  130. and sd.management_source =#{vo.managementSource}
  131. </if>
  132. <choose>
  133. <when test='vo.managementSource == "2"'>
  134. and (sur.role_id = 20 or sur.role_id = 21)
  135. </when>
  136. <when test='vo.managementSource == "1"'>
  137. and (sur.role_id = 19 or sur.role_id = 21)
  138. </when>
  139. <otherwise>
  140. </otherwise>
  141. </choose>
  142. <if test="vo.deptId !=null and vo.deptId !=''">
  143. and sd.id like concat('%',#{vo.deptId},'%')
  144. </if>
  145. <if test="vo.phoneNumber !=null and vo.phoneNumber !=''">
  146. and su.mobile =#{vo.phoneNumber}
  147. </if>
  148. <if test="vo.name !=null and vo.name !=''">
  149. and su.name =#{vo.name}
  150. </if>
  151. <if test="vo.userCode !=null and vo.userCode !=''">
  152. and su.id= #{vo.userCode}
  153. </if>
  154. <if test="vo.deptIds != null and vo.deptIds != '' and vo.deptIds.size() > 0">
  155. AND sd.id in
  156. <foreach collection="vo.deptIds" item="item" open="(" separator="," close=")">
  157. #{item}
  158. </foreach>
  159. </if>
  160. <if test="vo.userIds != null and vo.userIds != '' and vo.userIds.size() > 0">
  161. AND su.id in
  162. <foreach collection="vo.userIds" item="item" open="(" separator="," close=")">
  163. #{item}
  164. </foreach>
  165. </if>
  166. </where>
  167. </select>
  168. <select id="getWalletAgentAmount" resultType="java.util.HashMap">
  169. SELECT
  170. sum(IFNULL(iac.jqpremium,0) + IFNULL(iac.sypremium,0) + IFNULL(iac.jypremium,0)) as "totalIncome"
  171. FROM
  172. ins_orders io
  173. left join ins_area_company iac on iac.orderno =io.orderno
  174. <where>
  175. iac.orderstatus ='3'
  176. <if test="userId != null and userId !=''">
  177. and io.userid =#{userId}
  178. </if>
  179. <if test="beginDate !=null and beginDate != '' and endDate !=null and endDate != ''">
  180. AND iac.signing_time BETWEEN #{beginDate} AND #{endDate}
  181. </if>
  182. </where>
  183. </select>
  184. <select id="getDxWalletAgentAmount" resultType="java.math.BigDecimal">
  185. SELECT
  186. sum(IFNULL(iac.jqpremium,0) + IFNULL(iac.sypremium,0) + IFNULL(iac.jypremium,0)) as "totalIncome"
  187. FROM
  188. ins_orders io
  189. left join ins_area_company iac on iac.orderno =io.orderno
  190. <where>
  191. iac.orderstatus ='3'
  192. <if test="ids != null and ids.size()>0 != null">
  193. and io.userid IN
  194. <foreach collection="ids" item="id" index="index" open="(" close=")" separator=",">
  195. #{id}
  196. </foreach>
  197. </if>
  198. <if test="beginDate !=null and beginDate != '' and endDate !=null and endDate != ''">
  199. AND iac.signing_time BETWEEN #{beginDate} AND #{endDate}
  200. </if>
  201. </where>
  202. </select>
  203. </mapper>