TaskStatisticsMapper.xml 15 KB

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