TaskStatisticsMapper.xml 17 KB

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