TaskStatisticsMapper.xml 25 KB

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