TaskStatisticsMapper.xml 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511
  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.signingTimeStart != null and vo.signingTimeStart!='' and vo.signingTimeEnd != null and vo.signingTimeEnd != ''">
  53. AND DATE_FORMAT(iac.signing_time, '%Y-%m-%d') BETWEEN DATE_FORMAT(#{vo.signingTimeStart}, '%Y-%m-%d') AND DATE_FORMAT(#{vo.signingTimeEnd}, '%Y-%m-%d')
  54. </if>
  55. <if test="vo.enterTimeStart != null and vo.enterTimeStart!='' and vo.enterTimeEnd != null and vo.enterTimeEnd != ''">
  56. AND DATE_FORMAT(iac.createtime, '%Y-%m-%d') BETWEEN DATE_FORMAT(#{vo.enterTimeStart}, '%Y-%m-%d') AND DATE_FORMAT(#{vo.enterTimeEnd}, '%Y-%m-%d')
  57. </if>
  58. <if test="vo.userIds !=null and vo.userIds!='' and vo.userIds.size()>0">
  59. and su.leader_id in
  60. <foreach collection="vo.userIds" item="item" open="(" separator="," close=")">
  61. #{item}
  62. </foreach>
  63. </if>
  64. </where>
  65. group by io.userid
  66. ) a on a.userId =su.id
  67. <where>
  68. 1=1
  69. <if test="vo.userId !=null and vo.userId!=''">
  70. and su.id=#{vo.userId}
  71. </if>
  72. <if test="vo.userName !=null and vo.userName!=''">
  73. and su.name=#{vo.userName}
  74. </if>
  75. <if test="vo.managementSource !=null and vo.managementSource!=''">
  76. and sd.management_source=#{vo.managementSource}
  77. </if>
  78. <if test="vo.userIds !=null and vo.userIds!='' and vo.userIds.size()>0">
  79. and su.leader_id in
  80. <foreach collection="vo.userIds" item="item" open="(" separator="," close=")">
  81. #{item}
  82. </foreach>
  83. </if>
  84. <choose>
  85. <when test='vo.managementSource == "2"'>
  86. and (sur.role_id = 20 or sur.role_id = 21)
  87. </when>
  88. <when test='vo.managementSource == "1"'>
  89. and (sur.role_id = 19 or sur.role_id = 21)
  90. </when>
  91. <otherwise>
  92. </otherwise>
  93. </choose>
  94. <if test="vo.deptIds != null and vo.deptIds != '' and vo.deptIds.size() > 0">
  95. AND sd.id in
  96. <foreach collection="vo.deptIds" item="item" open="(" separator="," close=")">
  97. #{item}
  98. </foreach>
  99. </if>
  100. <if test="vo.deptId !=null and vo.deptId!=''">
  101. and sd.id like concat('%',#{vo.deptId},'%')
  102. </if>
  103. </where>
  104. order by a.sumpremium desc ,su.id
  105. </select>
  106. <select id="getBusinessAgentDataTotal" resultType="java.lang.Long">
  107. select
  108. COUNT(0)
  109. from sys_user su
  110. left join sys_dept sd on sd.id =su.dept_id
  111. LEFT JOIN sys_user_role sur ON sur.user_id = su.id
  112. <where>
  113. 1=1
  114. <if test="vo.userId !=null and vo.userId!=''">
  115. and su.id=#{vo.userId}
  116. </if>
  117. <if test="vo.userIds !=null and vo.userIds!='' and vo.userIds.size()>0">
  118. and su.leader_id in
  119. <foreach collection="vo.userIds" item="item" open="(" separator="," close=")">
  120. #{item}
  121. </foreach>
  122. </if>
  123. <if test="vo.userName !=null and vo.userName!=''">
  124. and su.name=#{vo.userName}
  125. </if>
  126. <if test="vo.managementSource !=null and vo.managementSource!=''">
  127. and sd.management_source=#{vo.managementSource}
  128. </if>
  129. <if test="vo.deptIds != null and vo.deptIds != '' and vo.deptIds.size() > 0">
  130. AND sd.id in
  131. <foreach collection="vo.deptIds" item="item" open="(" separator="," close=")">
  132. #{item}
  133. </foreach>
  134. </if>
  135. <if test="vo.deptId !=null and vo.deptId!=''">
  136. and sd.id like concat('%',#{vo.deptId},'%')
  137. </if>
  138. <choose>
  139. <when test='vo.managementSource == "2"'>
  140. and (sur.role_id = 20 or sur.role_id = 21)
  141. </when>
  142. <when test='vo.managementSource == "1"'>
  143. and (sur.role_id = 19 or sur.role_id = 21)
  144. </when>
  145. <otherwise>
  146. </otherwise>
  147. </choose>
  148. </where>
  149. </select>
  150. <select id="getBusinessAgentDataTotalAdd" resultType="com.ydtech.modules.admin.model.vo.BusinessAgentData">
  151. select
  152. sum(IFNULL(jqpremium, 0) + IFNULL(sypremium, 0)+ IFNULL(jypremium, 0)) as "sumpremium",
  153. IFNULL(sum(jqpremium),0) as "jqpremium",
  154. IFNULL(sum(sypremium),0) as "sypremium",
  155. IFNULL(sum(taxamount),0) as "taxamount",
  156. IFNULL(sum(jypremium),0) as "jypremium",
  157. ROUND(sum(IFNULL(ifon.jq_costs_premiums,0) + IFNULL(ifon.sy_costs_premiums,0) + IFNULL
  158. (ifon.no_costs_premiums,0)),2) as "entranceAllFee",
  159. ROUND(sum(IFNULL(jq_export_other_costs_premiums,0) + IFNULL(jq_export_supervise_costs_premiums,0)
  160. +IFNULL(sy_export_other_costs_premiums,0) +IFNULL(sy_export_supervise_costs_premiums,0)
  161. +IFNULL(no_export_other_costs_premiums,0)+IFNULL(no_export_supervise_costs_premiums,0) ),2) as "exportAllFee"
  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. LEFT JOIN ins_fee_order_new ifon ON iac.id = ifon.ins_order_no
  167. <where>
  168. iac.orderstatus = '3'
  169. <if test="vo.signingTimeStart != null and vo.signingTimeStart!='' and vo.signingTimeEnd != null and vo.signingTimeEnd != ''">
  170. AND DATE_FORMAT(iac.signing_time, '%Y-%m-%d') BETWEEN DATE_FORMAT(#{vo.signingTimeStart}, '%Y-%m-%d') AND DATE_FORMAT(#{vo.signingTimeEnd}, '%Y-%m-%d')
  171. </if>
  172. <if test="vo.enterTimeStart != null and vo.enterTimeStart!='' and vo.enterTimeEnd != null and vo.enterTimeEnd != ''">
  173. AND DATE_FORMAT(iac.createtime, '%Y-%m-%d') BETWEEN DATE_FORMAT(#{vo.enterTimeStart}, '%Y-%m-%d') AND DATE_FORMAT(#{vo.enterTimeEnd}, '%Y-%m-%d')
  174. </if>
  175. <if test="vo.days !=null and vo.days !='' and vo.days != 0 ">
  176. and iac.createtime >= DATE_SUB(NOW(), INTERVAL #{vo.days} DAY)
  177. </if>
  178. <if test="vo.userName !=null and vo.userName!=''">
  179. and su.name=#{vo.userName}
  180. </if>
  181. <if test="vo.userId !=null and vo.userId!=''">
  182. and su.id=#{vo.userId}
  183. </if>
  184. <if test="vo.userIds !=null and vo.userIds!='' and vo.userIds.size()>0">
  185. and su.leader_id in
  186. <foreach collection="vo.userIds" item="item" open="(" separator="," close=")">
  187. #{item}
  188. </foreach>
  189. </if>
  190. <if test="vo.deptId !=null and vo.deptId!=''">
  191. and io.deptid like concat('%',#{vo.deptId},'%')
  192. </if>
  193. <if test="vo.managementSource !=null and vo.managementSource!=''">
  194. and sd.management_source=#{vo.managementSource}
  195. </if>
  196. <if test="vo.deptIds != null and vo.deptIds != '' and vo.deptIds.size() > 0">
  197. AND io.deptid in
  198. <foreach collection="vo.deptIds" item="item" open="(" separator="," close=")">
  199. #{item}
  200. </foreach>
  201. </if>
  202. </where>
  203. </select>
  204. <select id="getAllsumPremium" resultType="com.ydtech.modules.admin.model.vo.BusinessAgentData">
  205. select
  206. sum(IFNULL(iac.jqpremium, 0) + IFNULL(iac.sypremium, 0)+ IFNULL(iac.jypremium, 0)) as "sumpremium"
  207. from ins_area_company iac
  208. left join ins_orders io on io.orderno =iac.orderno
  209. left join sys_user su on io.userid =su.id
  210. left join sys_dept sd on sd.id =su.dept_id
  211. <where>
  212. 1=1
  213. and iac.orderstatus ='3'
  214. <if test="vo.signingTimeStart != null and vo.signingTimeStart!='' and vo.signingTimeEnd != null and vo.signingTimeEnd != ''">
  215. AND DATE_FORMAT(iac.signing_time, '%Y-%m-%d') BETWEEN DATE_FORMAT(#{vo.signingTimeStart}, '%Y-%m-%d') AND DATE_FORMAT(#{vo.signingTimeEnd}, '%Y-%m-%d')
  216. </if>
  217. <if test="vo.enterTimeStart != null and vo.enterTimeStart!='' and vo.enterTimeEnd != null and vo.enterTimeEnd != ''">
  218. AND DATE_FORMAT(iac.createtime, '%Y-%m-%d') BETWEEN DATE_FORMAT(#{vo.enterTimeStart}, '%Y-%m-%d') AND DATE_FORMAT(#{vo.enterTimeEnd}, '%Y-%m-%d')
  219. </if>
  220. <if test="vo.userName !=null and vo.userName!=''">
  221. and su.name=#{vo.userName}
  222. </if>
  223. <if test="vo.userId !=null and vo.userId!=''">
  224. and su.id=#{vo.userId}
  225. </if>
  226. <if test="vo.proportionUserIds !=null and vo.proportionUserIds!='' and vo.proportionUserIds.size()>0">
  227. and su.id in
  228. <foreach collection="vo.proportionUserIds" item="item" open="(" separator="," close=")">
  229. #{item}
  230. </foreach>
  231. </if>
  232. <!-- <if test="vo.userIds !=null and vo.userIds!='' and vo.userIds.size()>0">-->
  233. <!-- and su.leader_id in-->
  234. <!-- <foreach collection="vo.userIds" item="item" open="(" separator="," close=")">-->
  235. <!-- #{item}-->
  236. <!-- </foreach>-->
  237. <!-- </if>-->
  238. <!-- <if test="vo.managementSource !=null and vo.managementSource!=''">-->
  239. <!-- and sd.management_source=#{vo.managementSource}-->
  240. <!-- </if>-->
  241. <if test="vo.deptIds != null and vo.deptIds != '' and vo.deptIds.size() > 0">
  242. AND io.deptid in
  243. <foreach collection="vo.deptIds" item="item" open="(" separator="," close=")">
  244. #{item}
  245. </foreach>
  246. </if>
  247. </where>
  248. </select>
  249. <select id="getBusinessAgentDataDetails" resultType="com.ydtech.modules.admin.model.vo.BusinessAgentData">
  250. select
  251. a.insurance_company as "insuranceCompany",
  252. (IFNULL(a.jqpremium, 0) + IFNULL(a.sypremium, 0)+ IFNULL(a.jypremium, 0)) as "sumpremium",
  253. a.jqpremium as "jqpremium",
  254. a.sypremium as "sypremium",
  255. a.taxamount as "taxamount",
  256. a.jypremium as "jypremium",
  257. eic.namesimple as "partnerCompaniesName",
  258. eic.logo as "logo",
  259. a.userId as "userId",
  260. a.userName as "userName"
  261. from (select pa.insurance_company,
  262. pa.partner_companies_id,
  263. su.id as "userId",
  264. su.name as "userName",
  265. IFNULL(sum(sumpremium), 0) as "sumpremium",
  266. IFNULL(sum(jqpremium), 0) as "jqpremium",
  267. IFNULL(sum(sypremium), 0) as "sypremium",
  268. IFNULL(sum(taxamount), 0) as "taxamount",
  269. IFNULL(sum(jypremium), 0) as "jypremium"
  270. from ins_area_company iac
  271. left join ins_orders io on io.orderno = iac.orderno
  272. left join ptl_agreement pa on pa.id = iac.agreement_id
  273. left join sys_user su on io.userid =su.id
  274. left join sys_dept sd on sd.id =su.dept_id
  275. LEFT JOIN esm_ins_company eic on eic.id = pa.partner_companies_id
  276. <where>
  277. iac.orderstatus = '3'
  278. <if test="vo.userId !=null and vo.userId!=''">
  279. and su.id=#{vo.userId}
  280. </if>
  281. <if test="vo.signingTimeStart != null and vo.signingTimeStart!='' and vo.signingTimeEnd != null and vo.signingTimeEnd != ''">
  282. AND DATE_FORMAT(iac.signing_time, '%Y-%m-%d') BETWEEN DATE_FORMAT(#{vo.signingTimeStart}, '%Y-%m-%d') AND DATE_FORMAT(#{vo.signingTimeEnd}, '%Y-%m-%d')
  283. </if>
  284. <if test="vo.enterTimeStart != null and vo.enterTimeStart!='' and vo.enterTimeEnd != null and vo.enterTimeEnd != ''">
  285. AND DATE_FORMAT(iac.createtime, '%Y-%m-%d') BETWEEN DATE_FORMAT(#{vo.enterTimeStart}, '%Y-%m-%d') AND DATE_FORMAT(#{vo.enterTimeEnd}, '%Y-%m-%d')
  286. </if>
  287. <if test="vo.managementSource !=null and vo.managementSource!=''">
  288. and sd.management_source=#{vo.managementSource}
  289. </if>
  290. <if test="vo.userIds !=null and vo.userIds!='' and vo.userIds.size()>0">
  291. and su.id in
  292. <foreach collection="vo.userIds" item="item" open="(" separator="," close=")">
  293. #{item}
  294. </foreach>
  295. </if>
  296. </where>
  297. group by pa.insurance_company, pa.partner_companies_id ,su.id,su.name) a
  298. LEFT JOIN esm_ins_company eic ON eic.id = a.partner_companies_id
  299. </select>
  300. <select id="getBusinessAgentDataDetailsAdd" resultType="java.lang.Long">
  301. select
  302. count(0)
  303. from (select pa.insurance_company,
  304. pa.partner_companies_id
  305. from ins_area_company iac
  306. left join ins_orders io on io.orderno = iac.orderno
  307. left join ptl_agreement pa on pa.id = iac.agreement_id
  308. left join sys_user su on io.userid =su.id
  309. <where>
  310. iac.orderstatus = '3'
  311. <if test="vo.userId !=null and vo.userId!=''">
  312. and su.id=#{vo.userId}
  313. </if>
  314. <if test="vo.signingTimeStart != null and vo.signingTimeStart!='' and vo.signingTimeEnd != null and vo.signingTimeEnd != ''">
  315. AND DATE_FORMAT(iac.signing_time, '%Y-%m-%d') BETWEEN DATE_FORMAT(#{vo.signingTimeStart}, '%Y-%m-%d') AND DATE_FORMAT(#{vo.signingTimeEnd}, '%Y-%m-%d')
  316. </if>
  317. <if test="vo.enterTimeStart != null and vo.enterTimeStart!='' and vo.enterTimeEnd != null and vo.enterTimeEnd != ''">
  318. AND DATE_FORMAT(iac.createtime, '%Y-%m-%d') BETWEEN DATE_FORMAT(#{vo.enterTimeStart}, '%Y-%m-%d') AND DATE_FORMAT(#{vo.enterTimeEnd}, '%Y-%m-%d')
  319. </if>
  320. <if test="vo.managementSource !=null and vo.managementSource!=''">
  321. and sd.management_source=#{vo.managementSource}
  322. </if>
  323. </where>
  324. group by pa.insurance_company, pa.partner_companies_id) a
  325. </select>
  326. <select id="channelAgentDetails" resultType="com.ydtech.modules.admin.model.dto.TaskStatisticsDto">
  327. SELECT
  328. iac.inscompany,
  329. COUNT( CASE WHEN iot.order_status = '0' THEN 1 END ) AS qutationCount,
  330. COUNT( CASE WHEN iot.order_status = '2' THEN 1 END ) AS underwritingCount,
  331. COUNT( CASE WHEN iot.order_status = '3' THEN 1 END ) AS qutationInsureCount,
  332. COUNT( CASE WHEN iot.order_status = '4' THEN 1 END ) AS underwritingReturn,
  333. COUNT( CASE WHEN iot.order_status = '2' THEN 1 END ) / COUNT( CASE WHEN iot.order_status = '0' THEN 1 END ) AS "passingRate",
  334. 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",
  335. (COUNT( CASE WHEN iot.order_status = '3' THEN 1 END ) + COUNT( CASE WHEN iot.order_status = '2' THEN 1 END ))/ COUNT(
  336. CASE WHEN iot.order_status in ('0','1','2','3','4') THEN 1 END ) AS "contributionRate",
  337. 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",
  338. COUNT(CASE WHEN io.order_source = 0 and iot.order_status = '0' THEN 1 END) as "pcOrderSource",
  339. COUNT(CASE WHEN io.order_source = 1 and iot.order_status = '0' THEN 1 END) as "appOrderSource",
  340. COUNT( CASE WHEN iot.order_status = '1' THEN 1 END ) AS "auditOrder"
  341. FROM
  342. (
  343. select iot.suborder,iot.order_status from `ins_orders_track` iot
  344. GROUP BY iot.suborder ,iot.order_status
  345. ) iot
  346. left join ins_area_company iac ON iac.id = iot.suborder
  347. LEFT JOIN ins_orders io ON io.orderno = iac.orderno
  348. LEFT JOIN sys_dept sd ON sd.id = io.deptid
  349. <where>
  350. 1=1
  351. <if test="taskStatisticsVo.provinceId != null and taskStatisticsVo.provinceId != ''">
  352. and io.deptid like "${taskStatisticsVo.provinceId}%"
  353. </if>
  354. <if test="taskStatisticsVo.cityId != null and taskStatisticsVo.cityId != ''">
  355. and io.deptid like "${taskStatisticsVo.cityId}%"
  356. </if>
  357. <if test="taskStatisticsVo.countyId != null and taskStatisticsVo.countyId != ''">
  358. and io.deptid like "${taskStatisticsVo.countyId}%"
  359. </if>
  360. <if test="taskStatisticsVo.houseId != null and taskStatisticsVo.houseId != ''">
  361. and io.deptid like "${taskStatisticsVo.houseId}%"
  362. </if>
  363. <if test="taskStatisticsVo.userId != null and taskStatisticsVo.userId != ''">
  364. and io.userid =#{taskStatisticsVo.userId}
  365. </if>
  366. <if test="taskStatisticsVo.managementSource != null and taskStatisticsVo.managementSource != ''">
  367. and sd.management_source =#{taskStatisticsVo.managementSource}
  368. </if>
  369. <if test="taskStatisticsVo.createtimeStart !=null and taskStatisticsVo.createtimeStart != '' and taskStatisticsVo.createtimeEnd !=null and taskStatisticsVo.createtimeEnd != ''">
  370. AND DATE_FORMAT( ica.signing_time, '%Y-%m-%d') BETWEEN #{taskStatisticsVo.createtimeStart} AND
  371. #{taskStatisticsVo.createtimeEnd}
  372. </if>
  373. <if test="taskStatisticsVo.beginDate !=null and taskStatisticsVo.beginDate != '' and taskStatisticsVo.endDate !=null and taskStatisticsVo.endDate != ''">
  374. AND DATE_FORMAT( iac.createtime, '%Y-%m-%d') BETWEEN DATE_FORMAT( #{taskStatisticsVo.beginDate},
  375. '%Y-%m-%d') AND DATE_FORMAT( #{taskStatisticsVo.endDate}, '%Y-%m-%d')
  376. </if>
  377. </where>
  378. GROUP BY
  379. iac.inscompany
  380. </select>
  381. <resultMap id="OrderDataMap" type="com.ydtech.modules.admin.model.vo.BusinessOrderData">
  382. <result property="totalNumber" column="total"/>
  383. <result property="orderNo" column="order_no"/>
  384. <result property="carNum" column="car_num"/>
  385. <result property="sumPremium" column="sum_premium"/>
  386. <result property="jqPremium" column="jq_premium"/>
  387. <result property="syPremium" column="sy_premium"/>
  388. <result property="taxAmount" column="tax_amount"/>
  389. <result property="jyPremium" column="jy_premium"/>
  390. <result property="userId" column="user_id"/>
  391. <result property="userName" column="user_name"/>
  392. </resultMap>
  393. <sql id="BusinessOrderDataSQL">
  394. SELECT
  395. io.orderno AS "order_no",
  396. io.licenseno AS "car_num",
  397. su.id AS "user_id",
  398. su.name AS "user_name",
  399. IFNULL(SUM(iac.jqpremium), 0) AS "jq_premium",
  400. IFNULL(SUM(iac.sypremium), 0) AS "sy_premium",
  401. IFNULL(SUM(iac.taxamount), 0) AS "tax_amount",
  402. IFNULL(SUM(iac.jypremium), 0) AS "jy_premium",
  403. (IFNULL(SUM(iac.jqpremium), 0) + IFNULL(SUM(iac.sypremium), 0) + IFNULL(SUM(iac.jypremium), 0)) AS "sum_premium",
  404. SUM(IFNULL(ifon.jq_costs_premiums, 0) + IFNULL(ifon.sy_costs_premiums, 0) + IFNULL(ifon.no_costs_premiums, 0)) AS "entrance_all_fee",
  405. SUM(IFNULL(ifon.jq_export_other_costs_premiums, 0) + IFNULL(ifon.jq_export_supervise_costs_premiums, 0)
  406. + IFNULL(ifon.sy_export_other_costs_premiums, 0) + IFNULL(ifon.sy_export_supervise_costs_premiums, 0)
  407. + IFNULL(ifon.no_export_other_costs_premiums, 0) + IFNULL(ifon.no_export_supervise_costs_premiums, 0)) AS "export_all_fee"
  408. FROM ins_area_company iac
  409. LEFT JOIN ins_orders io ON io.orderno = iac.orderno
  410. LEFT JOIN sys_user su ON io.userid = su.id
  411. LEFT JOIN ins_fee_order_new ifon ON iac.id = ifon.ins_order_no
  412. </sql>
  413. <select id="getBusinessOrderDataDetails" resultMap="OrderDataMap">
  414. <include refid="BusinessOrderDataSQL"/>
  415. <where>
  416. iac.orderstatus = '3'
  417. <if test="vo.userId != null and vo.userId!=''">
  418. AND su.id = #{vo.userId}
  419. </if>
  420. <if test="vo.signingTimeStart != null and vo.signingTimeStart!='' and vo.signingTimeEnd != null and vo.signingTimeEnd != ''">
  421. AND DATE_FORMAT(iac.signing_time, '%Y-%m-%d') BETWEEN DATE_FORMAT(#{vo.signingTimeStart}, '%Y-%m-%d')
  422. AND DATE_FORMAT(#{vo.signingTimeEnd}, '%Y-%m-%d')
  423. </if>
  424. <if test="vo.enterTimeStart != null and vo.enterTimeStart!='' and vo.enterTimeEnd != null and vo.enterTimeEnd != ''">
  425. AND DATE_FORMAT(iac.createtime, '%Y-%m-%d') BETWEEN DATE_FORMAT(#{vo.enterTimeStart}, '%Y-%m-%d')
  426. AND DATE_FORMAT(#{vo.enterTimeEnd}, '%Y-%m-%d')
  427. </if>
  428. </where>
  429. GROUP BY
  430. io.orderno
  431. </select>
  432. <select id="getBusinessOrderDataTotal" resultMap="OrderDataMap">
  433. SELECT
  434. COUNT(*) AS `total`,
  435. IFNULL(SUM(a.jq_premium), 0) AS `jq_premium`,
  436. IFNULL(SUM(a.sy_premium), 0) AS `sy_premium`,
  437. IFNULL(SUM(a.jy_premium), 0) AS `jy_premium`,
  438. IFNULL(SUM(a.tax_amount), 0) AS `tax_amount`,
  439. SUM(IFNULL(a.jq_premium, 0) + IFNULL(a.sy_premium, 0) + IFNULL(a.jy_premium, 0)) AS `sum_premium`,
  440. ROUND(IFNULL(SUM(a.entrance_all_fee),0),2) AS `entrance_all_fee`,
  441. ROUND(IFNULL(SUM(a.export_all_fee),0),2) AS `export_all_fee`
  442. FROM (
  443. <include refid="BusinessOrderDataSQL"/>
  444. <where>
  445. iac.orderstatus = '3'
  446. <if test="vo.userId != null and vo.userId!=''">
  447. AND su.id = #{vo.userId}
  448. </if>
  449. <if test="vo.signingTimeStart != null and vo.signingTimeStart!='' and vo.signingTimeEnd != null and vo.signingTimeEnd != ''">
  450. AND DATE_FORMAT(iac.signing_time, '%Y-%m-%d') BETWEEN DATE_FORMAT(#{vo.signingTimeStart}, '%Y-%m-%d')
  451. AND DATE_FORMAT(#{vo.signingTimeEnd}, '%Y-%m-%d')
  452. </if>
  453. <if test="vo.enterTimeStart != null and vo.enterTimeStart!='' and vo.enterTimeEnd != null and vo.enterTimeEnd != ''">
  454. AND DATE_FORMAT(iac.createtime, '%Y-%m-%d') BETWEEN DATE_FORMAT(#{vo.enterTimeStart}, '%Y-%m-%d')
  455. AND DATE_FORMAT(#{vo.enterTimeEnd}, '%Y-%m-%d')
  456. </if>
  457. </where>
  458. GROUP BY
  459. io.orderno) a
  460. </select>
  461. </mapper>