DeptBalanceMapper.xml 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  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. GROUP BY
  30. io.deptid
  31. ) b ON b.deptId = sd.id
  32. LEFT JOIN (
  33. SELECT
  34. sum( safa.history_fee ) AS "sumHistoryFee",
  35. safa.user_id AS "userId"
  36. FROM
  37. sys_agency_fee_approval_record safa
  38. WHERE
  39. safa.`status` = '1'
  40. GROUP BY
  41. safa.user_id
  42. ) c ON c.userId = sa.user_id
  43. <where>
  44. 1=1
  45. <if test="vo.provinceId != null and vo.provinceId != ''">
  46. and sd.id like concat('%',#{vo.provinceId},'%')
  47. </if>
  48. <if test="vo.cityId != null and vo.cityId != ''">
  49. and sd.id like concat('%',#{vo.cityId},'%')
  50. </if>
  51. <if test="vo.countyId != null and vo.countyId != ''">
  52. and sd.id like concat('%',#{vo.countyId},'%')
  53. </if>
  54. <if test="vo.houseId != null and vo.houseId != ''">
  55. and sd.id like concat('%',#{vo.houseId},'%')
  56. </if>
  57. </where>
  58. </select>
  59. <select id="queryPartnerStatistics" resultType="com.ydtech.modules.admin.model.dto.SysPartnerConsoleDto">
  60. select
  61. sp.id as "id",
  62. sp.user_id as "userId",
  63. sp.user_name as "userName",
  64. sp.proportional as "proportional",
  65. sp.suggest_id as "suggestId",
  66. sp.suggest_name as "suggestName",
  67. sp.create_time as "createTime",
  68. sp.create_by as "createBy",
  69. sp.del_flag as "delFlag",
  70. sd.name as "deptName"
  71. from sys_partner sp
  72. left join sys_user su on su.id = sp.user_id
  73. left join sys_dept sd on sd.id= su.dept_id
  74. <where>
  75. sp.del_flag='0'
  76. <if test="vo.userId !=null and vo.userId!='' ">
  77. and sp.user_id =#{vo.userId}
  78. </if>
  79. <if test="vo.userIdList !=null and vo.userIdList!='' and vo.userIdList .size() >0">
  80. and a.user_id IN
  81. <foreach item="item" index="index" collection="userIdList" open="(" separator="," close=")">
  82. #{item}
  83. </foreach>
  84. </if>
  85. </where>
  86. </select>
  87. <select id="getByDeptId" resultType="java.util.HashMap">
  88. SELECT
  89. sum(IFNULL(iac.jqpremium,0) + IFNULL(iac.sypremium,0) + IFNULL(iac.jypremium,0)) as
  90. "totalIncome",
  91. sum(IFNULL(iac.jqpremium,0) + IFNULL(iac.sypremium,0) + IFNULL(iac.jypremium,0)) as
  92. "deptManagementFee"
  93. FROM
  94. ins_area_company iac
  95. left join ins_orders io on iac.orderno = io.orderno
  96. <where>
  97. iac.orderstatus ='3'
  98. <if test="deptId != null and deptId !=''">
  99. and io.deptid like CONCAT( #{deptId}, '%' )
  100. </if>
  101. <if test="createTime != null and createTime !=''">
  102. and io.createtime >= #{createTime}
  103. </if>
  104. <if test="beginDate !=null and beginDate != '' and endDate !=null and endDate != ''">
  105. AND iac.signing_time BETWEEN #{beginDate} AND #{endDate}
  106. </if>
  107. </where>
  108. </select>
  109. <select id="getWalletAgent" resultType="com.ydtech.modules.admin.model.dto.SysPartnerConsoleDto">
  110. select
  111. su.id as "userId",
  112. su.name as "userName",
  113. sd.id as "deptId",
  114. sd.name as "deptName",
  115. inf.url as "filePath",
  116. suif.sex as "sex",
  117. sur.role_id as "roleId",
  118. sd.management_source as managementSource
  119. from sys_user su
  120. left join sys_dept sd on sd.id=su.dept_id
  121. LEFT JOIN ins_upload_files inf on su.head_sculpture =inf.id
  122. LEFT JOIN sys_user_info suif on suif.id =su.id
  123. LEFT JOIN sys_user_role sur ON sur.user_id = su.id
  124. <where>
  125. 1=1
  126. and su.id LIKE '%M%'
  127. and su.status ='1'
  128. <if test="vo.managementSource !=null and vo.managementSource !=''">
  129. and sd.management_source =#{vo.managementSource}
  130. </if>
  131. <choose>
  132. <when test='vo.managementSource == "2"'>
  133. and (sur.role_id = 20 or sur.role_id = 21)
  134. </when>
  135. <when test='vo.managementSource == "1"'>
  136. and (sur.role_id = 19 or sur.role_id = 21)
  137. </when>
  138. <otherwise>
  139. </otherwise>
  140. </choose>
  141. <if test="vo.deptId !=null and vo.deptId !=''">
  142. and sd.id like concat('%',#{vo.deptId},'%')
  143. </if>
  144. <if test="vo.phoneNumber !=null and vo.phoneNumber !=''">
  145. and su.mobile =#{vo.phoneNumber}
  146. </if>
  147. <if test="vo.name !=null and vo.name !=''">
  148. and su.name =#{vo.name}
  149. </if>
  150. <if test="vo.userCode !=null and vo.userCode !=''">
  151. and su.id= #{vo.userCode}
  152. </if>
  153. <if test="vo.deptIds != null and vo.deptIds != '' and vo.deptIds.size() > 0">
  154. AND sd.id in
  155. <foreach collection="vo.deptIds" item="item" open="(" separator="," close=")">
  156. #{item}
  157. </foreach>
  158. </if>
  159. <if test="vo.userIds != null and vo.userIds != '' and vo.userIds.size() > 0">
  160. AND su.id in
  161. <foreach collection="vo.userIds" item="item" open="(" separator="," close=")">
  162. #{item}
  163. </foreach>
  164. </if>
  165. </where>
  166. </select>
  167. <select id="getWalletAgentAmount" resultType="java.util.HashMap">
  168. SELECT
  169. sum(IFNULL(iac.jqpremium,0) + IFNULL(iac.sypremium,0) + IFNULL(iac.jypremium,0)) as "totalIncome"
  170. FROM
  171. ins_orders io
  172. left join ins_area_company iac on iac.orderno =io.orderno
  173. <where>
  174. iac.orderstatus ='3'
  175. <if test="userId != null and userId !=''">
  176. and io.userid =#{userId}
  177. </if>
  178. <if test="beginDate !=null and beginDate != '' and endDate !=null and endDate != ''">
  179. AND DATE_FORMAT( iac.createtime, '%Y-%m-%d') BETWEEN DATE_FORMAT( #{beginDate}, '%Y-%m-%d') AND DATE_FORMAT( #{endDate}, '%Y-%m-%d')
  180. </if>
  181. </where>
  182. </select>
  183. <select id="getDxWalletAgentAmount" resultType="java.math.BigDecimal">
  184. SELECT
  185. sum(IFNULL(iac.jqpremium,0) + IFNULL(iac.sypremium,0) + IFNULL(iac.jypremium,0)) as "totalIncome"
  186. FROM
  187. ins_orders io
  188. left join ins_area_company iac on iac.orderno =io.orderno
  189. <where>
  190. iac.orderstatus ='3'
  191. <if test="ids != null and ids.size()>0 != null">
  192. and io.userid IN
  193. <foreach collection="ids" item="id" index="index" open="(" close=")" separator=",">
  194. #{id}
  195. </foreach>
  196. </if>
  197. <if test="beginDate !=null and beginDate != '' and endDate !=null and endDate != ''">
  198. AND iac.signing_time BETWEEN #{beginDate} AND #{endDate}
  199. </if>
  200. </where>
  201. </select>
  202. <select id="getIncomeIndication" resultType="java.util.HashMap">
  203. select ifnull(sum(a.amount) ,0) as "totalAmount"
  204. from (
  205. SELECT
  206. his.amount as "amount"
  207. FROM
  208. sys_user_account_history his
  209. LEFT JOIN ins_area_company ins ON his.suborder = ins.id
  210. LEFT JOIN ins_orders o ON o.orderno = ins.orderno
  211. left join sys_amount_auditing saa on saa.id =his.auditiing_id
  212. left join sys_user su on su.id =his.user_id
  213. WHERE
  214. his.property in('4','3')
  215. AND his.documentary = '2'
  216. and (ins.del_flag = '1' or o.del_flag IS NULL or o.del_flag = 1)
  217. <if test="beginDate !=null and beginDate != '' and endDate !=null and endDate != '' ">
  218. AND date(his.create_time) BETWEEN #{beginDate} AND #{endDate}
  219. </if>
  220. <if test="userId !=null and userId!=''">
  221. AND his.user_id IN ( SELECT id FROM sys_user WHERE manager_id = #{userId} OR id= #{userId} )
  222. </if>
  223. <if test="phoneNumber !=null and phoneNumber !=''">
  224. and su.mobile =#{phoneNumber}
  225. </if>
  226. order by his.create_time desc
  227. ) a
  228. </select>
  229. </mapper>