TaskStatisticsMapper.xml 17 KB

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