TaskStatisticsMapper.xml 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE mapper
  3. PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  4. "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  5. <mapper namespace="com.ydtech.modules.admin.dao.TaskStatisticsMapper">
  6. <select id="getBusinessAgentData" resultType="com.ydtech.modules.admin.model.vo.BusinessAgentData">
  7. select
  8. su.id as "userId",
  9. su.name as "userName",
  10. sd.id as "deptId",
  11. su.leader_name as "leaderName",
  12. IFNULL(a.sumpremium,0) as "sumpremium",
  13. IFNULL(a.jqpremium,0) as "jqpremium",
  14. IFNULL(a.sypremium,0) as "sypremium",
  15. IFNULL(a.taxamount,0) as "taxamount",
  16. IFNULL(a.jypremium,0) as "jypremium",
  17. IFNULL(a.riskCodeJs,0) as "riskCodeJs",
  18. IFNULL(a.riskCodeDj,0) as "riskCodeDj" ,
  19. IFNULL(a.riskCodeJshang,0) as "riskCodeJshang",
  20. IFNULL(a.riskCodeDs,0) as "riskCodeDs",
  21. IFNULL(a.riskCodeDsan,0) as "riskCodeDsan",
  22. sd.management_source as "managementSource",
  23. IFNULL(IFNULL(a.entranceAllFee,0) -IFNULL(a.exportAllFee,0),0) as "distributionAmount",
  24. (IFNULL(IFNULL(a.entranceAllFee,0) -IFNULL(a.exportAllFee,0),0)) / a.sumpremium as "distributionAmountRate"
  25. from sys_user su
  26. left join sys_dept sd on sd.id =su.dept_id
  27. LEFT JOIN sys_user_role sur ON sur.user_id = su.id
  28. left join (
  29. select
  30. io.userid as "userId",
  31. sum(IFNULL(jqpremium, 0) + IFNULL(sypremium, 0)+ IFNULL(jypremium, 0)) as "sumpremium",
  32. IFNULL(sum(jqpremium),0) as "jqpremium",
  33. IFNULL(sum(sypremium),0) as "sypremium",
  34. IFNULL(sum(taxamount),0) as "taxamount",
  35. IFNULL(sum(jypremium),0) as "jypremium",
  36. COUNT( CASE WHEN iac.product = '交三' THEN 1 END ) AS "riskCodeJs",
  37. COUNT( CASE WHEN iac.product = '单交' THEN 1 END ) AS "riskCodeDj",
  38. COUNT( CASE WHEN iac.product = '交商' THEN 1 END ) AS "riskCodeJshang",
  39. COUNT( CASE WHEN iac.product = '单商' THEN 1 END ) AS "riskCodeDs",
  40. COUNT( CASE WHEN iac.product = '单三' THEN 1 END ) AS "riskCodeDsan",
  41. ROUND(sum(IFNULL(ifon.jq_costs_premiums,0) + IFNULL(ifon.sy_costs_premiums,0) + IFNULL
  42. (ifon.no_costs_premiums,0)),2) as "entranceAllFee",
  43. ROUND(sum(IFNULL(jq_export_other_costs_premiums,0) + IFNULL(jq_export_supervise_costs_premiums,0)
  44. +IFNULL(sy_export_other_costs_premiums,0) +IFNULL(sy_export_supervise_costs_premiums,0)
  45. +IFNULL(no_export_other_costs_premiums,0)+IFNULL(no_export_supervise_costs_premiums,0) ),2) as "exportAllFee"
  46. from ins_area_company iac
  47. left join ins_orders io on io.orderno =iac.orderno
  48. left join sys_user su on su.id =io.userid
  49. LEFT JOIN ins_fee_order_new ifon ON iac.id = ifon.ins_order_no
  50. <where>
  51. iac.orderstatus = '3'
  52. <if test="vo.createtimeStart != null and vo.createtimeStart!='' and vo.createtimeEnd != null and vo.createtimeEnd!=''">
  53. AND DATE_FORMAT( iac.signing_time, '%Y-%m-%d') BETWEEN DATE_FORMAT( #{vo.createtimeStart}, '%Y-%m-%d')
  54. AND DATE_FORMAT( #{vo.createtimeEnd}, '%Y-%m-%d')
  55. </if>
  56. <if test="vo.userIds !=null and vo.userIds!='' and vo.userIds.size()>0">
  57. and su.leader_id in
  58. <foreach collection="vo.userIds" item="item" open="(" separator="," close=")">
  59. #{item}
  60. </foreach>
  61. </if>
  62. </where>
  63. group by io.userid
  64. ) a on a.userId =su.id
  65. <where>
  66. 1=1
  67. <if test="vo.userId !=null and vo.userId!=''">
  68. and su.id=#{vo.userId}
  69. </if>
  70. <if test="vo.userName !=null and vo.userName!=''">
  71. and su.name=#{vo.userName}
  72. </if>
  73. <if test="vo.managementSource !=null and vo.managementSource!=''">
  74. and sd.management_source=#{vo.managementSource}
  75. </if>
  76. <if test="vo.userIds !=null and vo.userIds!='' and vo.userIds.size()>0">
  77. and su.leader_id in
  78. <foreach collection="vo.userIds" item="item" open="(" separator="," close=")">
  79. #{item}
  80. </foreach>
  81. </if>
  82. <choose>
  83. <when test='vo.managementSource == "2"'>
  84. and (sur.role_id = 20 or sur.role_id = 21)
  85. </when>
  86. <when test='vo.managementSource == "1"'>
  87. and (sur.role_id = 19 or sur.role_id = 21)
  88. </when>
  89. <otherwise>
  90. </otherwise>
  91. </choose>
  92. <if test="vo.deptIds != null and vo.deptIds != '' and vo.deptIds.size() > 0">
  93. AND sd.id in
  94. <foreach collection="vo.deptIds" item="item" open="(" separator="," close=")">
  95. #{item}
  96. </foreach>
  97. </if>
  98. <if test="vo.deptId !=null and vo.deptId!=''">
  99. and sd.id like concat('%',#{vo.deptId},'%')
  100. </if>
  101. </where>
  102. order by a.sumpremium desc ,su.id
  103. </select>
  104. <select id="getBusinessAgentDataTotal" resultType="java.lang.Long">
  105. select
  106. COUNT(0)
  107. from sys_user su
  108. left join sys_dept sd on sd.id =su.dept_id
  109. LEFT JOIN sys_user_role sur ON sur.user_id = su.id
  110. <where>
  111. 1=1
  112. <if test="vo.userId !=null and vo.userId!=''">
  113. and su.id=#{vo.userId}
  114. </if>
  115. <if test="vo.userIds !=null and vo.userIds!='' and vo.userIds.size()>0">
  116. and su.leader_id in
  117. <foreach collection="vo.userIds" item="item" open="(" separator="," close=")">
  118. #{item}
  119. </foreach>
  120. </if>
  121. <if test="vo.userName !=null and vo.userName!=''">
  122. and su.name=#{vo.userName}
  123. </if>
  124. <if test="vo.managementSource !=null and vo.managementSource!=''">
  125. and sd.management_source=#{vo.managementSource}
  126. </if>
  127. <if test="vo.deptIds != null and vo.deptIds != '' and vo.deptIds.size() > 0">
  128. AND sd.id in
  129. <foreach collection="vo.deptIds" item="item" open="(" separator="," close=")">
  130. #{item}
  131. </foreach>
  132. </if>
  133. <if test="vo.deptId !=null and vo.deptId!=''">
  134. and sd.id like concat('%',#{vo.deptId},'%')
  135. </if>
  136. <choose>
  137. <when test='vo.managementSource == "2"'>
  138. and (sur.role_id = 20 or sur.role_id = 21)
  139. </when>
  140. <when test='vo.managementSource == "1"'>
  141. and (sur.role_id = 19 or sur.role_id = 21)
  142. </when>
  143. <otherwise>
  144. </otherwise>
  145. </choose>
  146. </where>
  147. </select>
  148. <select id="getBusinessAgentDataTotalAdd" resultType="com.ydtech.modules.admin.model.vo.BusinessAgentData">
  149. select
  150. sum(IFNULL(jqpremium, 0) + IFNULL(sypremium, 0)+ IFNULL(jypremium, 0)) as "sumpremium",
  151. IFNULL(sum(jqpremium),0) as "jqpremium",
  152. IFNULL(sum(sypremium),0) as "sypremium",
  153. IFNULL(sum(taxamount),0) as "taxamount",
  154. IFNULL(sum(jypremium),0) as "jypremium",
  155. ROUND(sum(IFNULL(ifon.jq_costs_premiums,0) + IFNULL(ifon.sy_costs_premiums,0) + IFNULL
  156. (ifon.no_costs_premiums,0)),2) as "entranceAllFee",
  157. ROUND(sum(IFNULL(jq_export_other_costs_premiums,0) + IFNULL(jq_export_supervise_costs_premiums,0)
  158. +IFNULL(sy_export_other_costs_premiums,0) +IFNULL(sy_export_supervise_costs_premiums,0)
  159. +IFNULL(no_export_other_costs_premiums,0)+IFNULL(no_export_supervise_costs_premiums,0) ),2) as "exportAllFee"
  160. from ins_area_company iac
  161. left join ins_orders io on io.orderno =iac.orderno
  162. left join sys_user su on io.userid =su.id
  163. left join sys_dept sd on sd.id =su.dept_id
  164. LEFT JOIN ins_fee_order_new ifon ON iac.id = ifon.ins_order_no
  165. <where>
  166. iac.orderstatus = '3'
  167. <if test="vo.createtimeStart != null and vo.createtimeStart!='' and vo.createtimeEnd != null and vo.createtimeEnd!=''">
  168. AND DATE_FORMAT( iac.signing_time, '%Y-%m-%d') BETWEEN DATE_FORMAT( #{vo.createtimeStart}, '%Y-%m-%d') AND
  169. DATE_FORMAT( #{vo.createtimeEnd}, '%Y-%m-%d')
  170. </if>
  171. <if test="vo.days !=null and vo.days !='' and vo.days != 0 ">
  172. and iac.createtime >= DATE_SUB(NOW(), INTERVAL #{vo.days} DAY)
  173. </if>
  174. <if test="vo.userName !=null and vo.userName!=''">
  175. and su.name=#{vo.userName}
  176. </if>
  177. <if test="vo.userId !=null and vo.userId!=''">
  178. and su.id=#{vo.userId}
  179. </if>
  180. <if test="vo.userIds !=null and vo.userIds!='' and vo.userIds.size()>0">
  181. and su.leader_id in
  182. <foreach collection="vo.userIds" item="item" open="(" separator="," close=")">
  183. #{item}
  184. </foreach>
  185. </if>
  186. <if test="vo.deptId !=null and vo.deptId!=''">
  187. and io.deptid like concat('%',#{vo.deptId},'%')
  188. </if>
  189. <if test="vo.managementSource !=null and vo.managementSource!=''">
  190. and sd.management_source=#{vo.managementSource}
  191. </if>
  192. <if test="vo.deptIds != null and vo.deptIds != '' and vo.deptIds.size() > 0">
  193. AND io.deptid in
  194. <foreach collection="vo.deptIds" item="item" open="(" separator="," close=")">
  195. #{item}
  196. </foreach>
  197. </if>
  198. </where>
  199. </select>
  200. <select id="getAllsumPremium" resultType="com.ydtech.modules.admin.model.vo.BusinessAgentData">
  201. select
  202. sum(IFNULL(iac.jqpremium, 0) + IFNULL(iac.sypremium, 0)+ IFNULL(iac.jypremium, 0)) as "sumpremium"
  203. from ins_area_company iac
  204. left join ins_orders io on io.orderno =iac.orderno
  205. left join sys_user su on io.userid =su.id
  206. left join sys_dept sd on sd.id =su.dept_id
  207. <where>
  208. 1=1
  209. <if test="vo.createtimeStart != null and vo.createtimeStart!='' and vo.createtimeEnd != null and vo.createtimeEnd!=''">
  210. AND DATE_FORMAT( iac.signing_time, '%Y-%m-%d') BETWEEN DATE_FORMAT( #{vo.createtimeStart}, '%Y-%m-%d') AND
  211. DATE_FORMAT( #{vo.createtimeEnd}, '%Y-%m-%d')
  212. </if>
  213. <if test="vo.userName !=null and vo.userName!=''">
  214. and su.name=#{vo.userName}
  215. </if>
  216. <if test="vo.userId !=null and vo.userId!=''">
  217. and su.id=#{vo.userId}
  218. </if>
  219. <if test="vo.proportionUserIds !=null and vo.proportionUserIds!='' and vo.proportionUserIds.size()>0">
  220. and su.id in
  221. <foreach collection="vo.proportionUserIds" item="item" open="(" separator="," close=")">
  222. #{item}
  223. </foreach>
  224. </if>
  225. <if test="vo.userIds !=null and vo.userIds!='' and vo.userIds.size()>0">
  226. and su.leader_id in
  227. <foreach collection="vo.userIds" item="item" open="(" separator="," close=")">
  228. #{item}
  229. </foreach>
  230. </if>
  231. <if test="vo.managementSource !=null and vo.managementSource!=''">
  232. and sd.management_source=#{vo.managementSource}
  233. </if>
  234. <if test="vo.deptIds != null and vo.deptIds != '' and vo.deptIds.size() > 0">
  235. AND io.deptid in
  236. <foreach collection="vo.deptIds" item="item" open="(" separator="," close=")">
  237. #{item}
  238. </foreach>
  239. </if>
  240. </where>
  241. </select>
  242. <select id="getBusinessAgentDataDetails" resultType="com.ydtech.modules.admin.model.vo.BusinessAgentData">
  243. select
  244. a.insurance_company as "insuranceCompany",
  245. (IFNULL(a.jqpremium, 0) + IFNULL(a.sypremium, 0)+ IFNULL(a.jypremium, 0)) as "sumpremium",
  246. a.jqpremium as "jqpremium",
  247. a.sypremium as "sypremium",
  248. a.taxamount as "taxamount",
  249. a.jypremium as "jypremium",
  250. eic.namesimple as "partnerCompaniesName",
  251. eic.logo as "logo",
  252. a.userId as "userId",
  253. a.userName as "userName"
  254. from (select pa.insurance_company,
  255. pa.partner_companies_id,
  256. su.id as "userId",
  257. su.name as "userName",
  258. IFNULL(sum(sumpremium), 0) as "sumpremium",
  259. IFNULL(sum(jqpremium), 0) as "jqpremium",
  260. IFNULL(sum(sypremium), 0) as "sypremium",
  261. IFNULL(sum(taxamount), 0) as "taxamount",
  262. IFNULL(sum(jypremium), 0) as "jypremium"
  263. from ins_area_company iac
  264. left join ins_orders io on io.orderno = iac.orderno
  265. left join ptl_agreement pa on pa.id = iac.agreement_id
  266. left join sys_user su on io.userid =su.id
  267. left join sys_dept sd on sd.id =su.dept_id
  268. LEFT JOIN esm_ins_company eic on eic.id = pa.partner_companies_id
  269. <where>
  270. iac.orderstatus = '3'
  271. and io.orderstatus = '3'
  272. <if test="vo.userId !=null and vo.userId!=''">
  273. and su.id=#{vo.userId}
  274. </if>
  275. <if test="vo.createtimeStart != null and vo.createtimeStart!='' and vo.createtimeEnd != null and vo.createtimeEnd!=''">
  276. AND DATE_FORMAT( iac.signing_time, '%Y-%m-%d') BETWEEN DATE_FORMAT( #{vo.createtimeStart}, '%Y-%m-%d') AND
  277. DATE_FORMAT( #{vo.createtimeEnd}, '%Y-%m-%d')
  278. </if>
  279. <if test="vo.managementSource !=null and vo.managementSource!=''">
  280. and sd.management_source=#{vo.managementSource}
  281. </if>
  282. <if test="vo.userIds !=null and vo.userIds!='' and vo.userIds.size()>0">
  283. and su.id in
  284. <foreach collection="vo.userIds" item="item" open="(" separator="," close=")">
  285. #{item}
  286. </foreach>
  287. </if>
  288. </where>
  289. group by pa.insurance_company, pa.partner_companies_id ,su.id,su.name) a
  290. LEFT JOIN esm_ins_company eic ON eic.id = a.partner_companies_id
  291. </select>
  292. <select id="getBusinessAgentDataDetailsAdd" resultType="java.lang.Long">
  293. select
  294. count(0)
  295. from (select pa.insurance_company,
  296. pa.partner_companies_id
  297. from ins_area_company iac
  298. left join ins_orders io on io.orderno = iac.orderno
  299. left join ptl_agreement pa on pa.id = iac.agreement_id
  300. left join sys_user su on io.userid =su.id
  301. <where>
  302. iac.orderstatus = '3'
  303. and io.orderstatus = '3'
  304. <if test="vo.userId !=null and vo.userId!=''">
  305. and su.id=#{vo.userId}
  306. </if>
  307. <if test="vo.createtimeStart != null and vo.createtimeStart!='' and vo.createtimeEnd != null and vo.createtimeEnd!=''">
  308. AND DATE_FORMAT( iac.signing_time, '%Y-%m-%d') BETWEEN DATE_FORMAT( #{vo.createtimeStart}, '%Y-%m-%d') AND
  309. DATE_FORMAT( #{vo.createtimeEnd}, '%Y-%m-%d')
  310. </if>
  311. <if test="vo.managementSource !=null and vo.managementSource!=''">
  312. and sd.management_source=#{vo.managementSource}
  313. </if>
  314. </where>
  315. group by pa.insurance_company, pa.partner_companies_id) a
  316. </select>
  317. <select id="channelAgentDetails" resultType="com.ydtech.modules.admin.model.dto.TaskStatisticsDto">
  318. SELECT
  319. iac.inscompany,
  320. COUNT( CASE WHEN iot.order_status = '0' THEN 1 END ) AS qutationCount,
  321. COUNT( CASE WHEN iot.order_status = '2' THEN 1 END ) AS underwritingCount,
  322. COUNT( CASE WHEN iot.order_status = '3' THEN 1 END ) AS qutationInsureCount,
  323. COUNT( CASE WHEN iot.order_status = '4' THEN 1 END ) AS underwritingReturn,
  324. COUNT( CASE WHEN iot.order_status = '2' THEN 1 END ) / COUNT( CASE WHEN iot.order_status = '0' THEN 1 END ) AS "passingRate",
  325. COUNT( CASE WHEN iot.order_status = '3' THEN 1 END ) / COUNT( CASE WHEN iot.order_status in ('0','1','2','3','4') THEN 1 END ) AS "closeRate",
  326. (COUNT( CASE WHEN iot.order_status = '3' THEN 1 END ) + COUNT( CASE WHEN iot.order_status = '2' THEN 1 END ))/ COUNT(
  327. CASE WHEN iot.order_status in ('0','1','2','3','4') THEN 1 END ) AS "contributionRate",
  328. COUNT( CASE WHEN iot.order_status = '0' THEN 1 END ) / COUNT( CASE WHEN iot.order_status in ('0','1','2','3','4') THEN 1 END ) AS "quotationRate",
  329. COUNT(CASE WHEN io.order_source = 0 and iot.order_status = '0' THEN 1 END) as "pcOrderSource",
  330. COUNT(CASE WHEN io.order_source = 1 and iot.order_status = '0' THEN 1 END) as "appOrderSource",
  331. COUNT( CASE WHEN iot.order_status = '1' THEN 1 END ) AS "auditOrder"
  332. FROM
  333. (
  334. select iot.suborder,iot.order_status from `ins_orders_track` iot
  335. GROUP BY iot.suborder ,iot.order_status
  336. ) iot
  337. left join ins_area_company iac ON iac.id = iot.suborder
  338. LEFT JOIN ins_orders io ON io.orderno = iac.orderno
  339. LEFT JOIN sys_dept sd ON sd.id = io.deptid
  340. <where>
  341. 1=1
  342. <if test="taskStatisticsVo.provinceId != null and taskStatisticsVo.provinceId != ''">
  343. and io.deptid like "${taskStatisticsVo.provinceId}%"
  344. </if>
  345. <if test="taskStatisticsVo.cityId != null and taskStatisticsVo.cityId != ''">
  346. and io.deptid like "${taskStatisticsVo.cityId}%"
  347. </if>
  348. <if test="taskStatisticsVo.countyId != null and taskStatisticsVo.countyId != ''">
  349. and io.deptid like "${taskStatisticsVo.countyId}%"
  350. </if>
  351. <if test="taskStatisticsVo.houseId != null and taskStatisticsVo.houseId != ''">
  352. and io.deptid like "${taskStatisticsVo.houseId}%"
  353. </if>
  354. <if test="taskStatisticsVo.userId != null and taskStatisticsVo.userId != ''">
  355. and io.userid =#{taskStatisticsVo.userId}
  356. </if>
  357. <if test="taskStatisticsVo.managementSource != null and taskStatisticsVo.managementSource != ''">
  358. and sd.management_source =#{taskStatisticsVo.managementSource}
  359. </if>
  360. <if test="taskStatisticsVo.createtimeStart !=null and taskStatisticsVo.createtimeStart != '' and taskStatisticsVo.createtimeEnd !=null and taskStatisticsVo.createtimeEnd != ''">
  361. AND DATE_FORMAT( ica.signing_time, '%Y-%m-%d') BETWEEN #{taskStatisticsVo.createtimeStart} AND
  362. #{taskStatisticsVo.createtimeEnd}
  363. </if>
  364. <if test="taskStatisticsVo.beginDate !=null and taskStatisticsVo.beginDate != '' and taskStatisticsVo.endDate !=null and taskStatisticsVo.endDate != ''">
  365. AND DATE_FORMAT( iac.signing_time, '%Y-%m-%d') BETWEEN DATE_FORMAT( #{taskStatisticsVo.beginDate},
  366. '%Y-%m-%d') AND DATE_FORMAT( #{taskStatisticsVo.endDate}, '%Y-%m-%d')
  367. </if>
  368. </where>
  369. GROUP BY
  370. iac.inscompany
  371. </select>
  372. </mapper>