InsAreaCompanyMapper.xml 50 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134
  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.order.dao.InsAreaCompanyMapper">
  6. <resultMap id="BaseResultMap" type="com.ydtech.modules.order.entity.InsAreaCompany">
  7. <id property="id" column="id" jdbcType="VARCHAR"/>
  8. <result property="reqtxt" column="reqtxt" javaType="com.alibaba.fastjson.JSONObject"
  9. typeHandler="com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler" jdbcType="VARCHAR"/>
  10. <result property="reptxt" column="reptxt" javaType="com.alibaba.fastjson.JSONObject"
  11. typeHandler="com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler" jdbcType="VARCHAR"/>
  12. <result property="riskinfo" column="riskinfo" javaType="com.alibaba.fastjson.JSONArray"
  13. typeHandler="com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler" jdbcType="VARCHAR"/>
  14. <result property="kindinfo" column="kindinfo" javaType="com.alibaba.fastjson.JSONArray"
  15. typeHandler="com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler" jdbcType="VARCHAR"/>
  16. <result property="accidentInfo" column="accident_info" javaType="com.alibaba.fastjson.JSONArray"
  17. typeHandler="com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler" jdbcType="VARCHAR"/>
  18. <result property="taxArrears" column="tax_arrears" javaType="com.alibaba.fastjson.JSONArray"
  19. typeHandler="com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler" jdbcType="VARCHAR"/>
  20. <result property="crossInsurance" column="cross_insurance" javaType="com.alibaba.fastjson.JSONArray"
  21. typeHandler="com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler" jdbcType="VARCHAR"/>
  22. <result property="orderno" column="orderno" jdbcType="VARCHAR"/>
  23. <result property="agreementId" column="agreement_id" jdbcType="BIGINT"/>
  24. <result property="apiType" column="api_type" jdbcType="TINYINT"/>
  25. <result property="orderstatus" column="orderstatus" jdbcType="VARCHAR"/>
  26. <result property="companyId" column="company_id" jdbcType="VARCHAR"/>
  27. <result property="inscompany" column="inscompany" jdbcType="VARCHAR"/>
  28. <result property="jqapplyno" column="jqapplyno" jdbcType="VARCHAR"/>
  29. <result property="jqpolicyno" column="jqpolicyno" jdbcType="VARCHAR"/>
  30. <result property="syapplyno" column="syapplyno" jdbcType="VARCHAR"/>
  31. <result property="sypolicyno" column="sypolicyno" jdbcType="VARCHAR"/>
  32. <result property="jqpremium" column="jqpremium" jdbcType="DECIMAL"/>
  33. <result property="sypremium" column="sypremium" jdbcType="DECIMAL"/>
  34. <result property="jypremium" column="jypremium" jdbcType="DECIMAL"/>
  35. <result property="sumpremium" column="sumpremium" jdbcType="DECIMAL"/>
  36. <result property="taxamount" column="taxamount" jdbcType="DECIMAL"/>
  37. <result property="jqdiscountrate" column="jqdiscountrate" jdbcType="DOUBLE"/>
  38. <result property="sydiscountrate" column="sydiscountrate" jdbcType="DOUBLE"/>
  39. <result property="feerate" column="feerate" jdbcType="DOUBLE"/>
  40. <result property="disrate" column="disrate" jdbcType="DOUBLE"/>
  41. <result property="auditid" column="auditid" jdbcType="VARCHAR"/>
  42. <result property="auditname" column="auditname" jdbcType="VARCHAR"/>
  43. <result property="audittime" column="audittime" jdbcType="TIMESTAMP"/>
  44. <result property="auditopinion" column="auditopinion" jdbcType="VARCHAR"/>
  45. <result property="jqappoint" column="jqappoint" jdbcType="VARCHAR"/>
  46. <result property="syappoint" column="syappoint" jdbcType="VARCHAR"/>
  47. <result property="createtime" column="createtime" jdbcType="TIMESTAMP"/>
  48. <result property="payDate" column="pay_date" jdbcType="TIMESTAMP"/>
  49. <result property="paymentLink" column="payment_link" jdbcType="VARCHAR"/>
  50. <result property="insOrderNo" column="ins_order_no" jdbcType="VARCHAR"/>
  51. <result property="attributionId" column="attribution_id" jdbcType="VARCHAR"/>
  52. <result property="jqStartDate" column="jq_start_date" jdbcType="VARCHAR"/>
  53. <result property="jqEndDate" column="jq_end_date" jdbcType="VARCHAR"/>
  54. <result property="syStartDate" column="sy_start_date" jdbcType="VARCHAR"/>
  55. <result property="syEndDate" column="sy_end_date" jdbcType="VARCHAR"/>
  56. <result property="accidentStrInfo" column="accident_str_info" jdbcType="VARCHAR"/>
  57. <result property="score" column="score" jdbcType="VARCHAR"/>
  58. <result property="jqScore" column="jq_score" jdbcType="VARCHAR"/>
  59. <result property="syScore" column="sy_score" jdbcType="VARCHAR"/>
  60. <result property="lossRation" column="loss_ration" jdbcType="DOUBLE"/>
  61. <result property="jqLossRation" column="jq_loss_ration" jdbcType="DOUBLE"/>
  62. <result property="syLossRation" column="sy_loss_ration" jdbcType="DOUBLE"/>
  63. <result property="totalAdjustRate" column="total_adjust_rate" jdbcType="DOUBLE"/>
  64. <result property="jqAdjustRate" column="jq_adjust_rate" jdbcType="DOUBLE"/>
  65. <result property="syAdjustRate" column="sy_adjust_rate" jdbcType="DOUBLE"/>
  66. <result property="insideOrderStatus" column="inside_order_status" jdbcType="TINYINT"/>
  67. <result property="insidePayTime" column="inside_pay_time" jdbcType="TIMESTAMP"/>
  68. <result property="signingTime" column="signing_time" jdbcType="TIMESTAMP"/>
  69. <result property="jqRenewal" column="jq_renewal" jdbcType="VARCHAR"/>
  70. <result property="syRenewal" column="sy_renewal" jdbcType="VARCHAR"/>
  71. <result property="jqClaims" column="jq_claims" jdbcType="VARCHAR"/>
  72. <result property="syClaims" column="sy_claims" jdbcType="VARCHAR"/>
  73. </resultMap>
  74. <resultMap id="InsAreaCompanyQueryDto" type="com.ydtech.modules.order.entity.dto.InsAreaCompanyQueryDto"
  75. extends="BaseResultMap">
  76. <result property="agreementName" column="agreement_name" jdbcType="VARCHAR"/>
  77. </resultMap>
  78. <sql id="Base_Column_List">
  79. id,orderno,inscompany,
  80. reqtxt,reptxt,jqapplyno,
  81. jqpolicyno,syapplyno,sypolicyno,
  82. riskinfo,kindinfo,jqpremium,
  83. sypremium,taxamount,sumpremium,
  84. jqdiscountrate,sydiscountrate,feerate,
  85. disrate,auditid,auditname,
  86. audittime,auditopinion,jqappoint,
  87. syappoint,createtime,payment_link
  88. </sql>
  89. <select id="selectByOrderNo" resultMap="InsAreaCompanyQueryDto">
  90. SELECT iac.*, pa.agreement_name
  91. FROM ins_area_company as iac
  92. left join ptl_agreement as pa on pa.id = iac.agreement_id
  93. INNER JOIN (SELECT company_id, max(createtime) AS max_createtime
  94. FROM ins_area_company
  95. WHERE orderno = #{orderNo}
  96. GROUP BY company_id) t ON t.company_id = iac.company_id
  97. AND t.max_createtime = iac.createtime
  98. WHERE iac.orderno = #{orderNo}
  99. </select>
  100. <select id="selectAcceptInsurance" resultMap="InsAreaCompanyQueryDto">
  101. SELECT iac.*, pa.agreement_name,io.is_external
  102. FROM ins_area_company as iac
  103. left join ptl_agreement as pa on pa.id = iac.agreement_id
  104. left join ins_orders io on iac.orderno=io.orderno
  105. WHERE iac.orderstatus = 3
  106. and iac.orderno = #{orderNo};
  107. </select>
  108. <select id="queryLatestStatus" resultType="java.lang.String">
  109. SELECT iac.orderstatus
  110. FROM ins_area_company as iac
  111. INNER JOIN (SELECT company_id, max(createtime) AS max_createtime
  112. FROM ins_area_company
  113. WHERE orderno = #{orderNo}
  114. GROUP BY company_id) t ON t.company_id = iac.company_id
  115. AND t.max_createtime = iac.createtime
  116. WHERE iac.orderno = #{orderNo}
  117. ORDER BY orderstatus DESC
  118. LIMIT 1
  119. </select>
  120. <select id="getorDerIds" resultType="com.ydtech.modules.order.entity.InsAreaCompany">
  121. SELECT a.id as "id",
  122. a.orderno as "orderno"
  123. FROM ins_area_company a
  124. LEFT JOIN ins_fee_order_new b ON a.id = b.ins_order_no
  125. WHERE a.orderstatus = '3'
  126. or a.orderstatus = '2'
  127. and b.id is not null
  128. </select>
  129. <select id="getAuditOrders" resultType="com.ydtech.modules.order.entity.InsOrders">
  130. SELECT
  131. iac.id as orderno,
  132. io.quoteno,
  133. io.orderstatus,
  134. io.company_id,
  135. io.ins_company,
  136. io.carinfo,
  137. io.userid,
  138. io.username,
  139. io.deptid,
  140. io.deptname,
  141. io.agreeid,
  142. iac.productid,
  143. iac.product,
  144. iac.createtime,
  145. io.frameno,
  146. io.licenseno,
  147. io.insuredname,
  148. io.is_external,
  149. iac.jq_start_date as jqstartdate,
  150. iac.jq_end_date as jqenddate,
  151. iac.sy_start_date as systartdate,
  152. iac.sy_end_date as syenddate,
  153. io.vehicle_and_vessel_tax,
  154. io.operatorid,
  155. iac.operator_name,
  156. sd.management_source,
  157. iac.problem_order,
  158. CASE ifa.audituser
  159. WHEN '自动审核' THEN ifa.audituser
  160. ELSE su2.name END
  161. AS auditUser,
  162. ifa.audittime as auditTime,
  163. ifa.auditstatus as auditStatus,
  164. eic.namesimple as partnerCompaniesName,
  165. iac.id as subOrderId,
  166. iac.signing_time as signingTime,
  167. iac.pay_date as payDate,
  168. pa.agreement_code as agreementCode,
  169. pa.agreement_name as agreementName
  170. FROM
  171. ins_fee_audit ifa
  172. LEFT JOIN ins_orders io ON io.orderno = ifa.orderno
  173. LEFT JOIN ins_area_company iac ON iac.orderno = io.orderno
  174. AND iac.orderstatus = 3
  175. LEFT JOIN sys_user su ON su.id = io.userid
  176. LEFT JOIN sys_dept sd ON sd.id = su.dept_id
  177. LEFT JOIN sys_user su2 ON ifa.audituser = su2.id
  178. LEFT JOIN ptl_agreement pa ON pa.id = iac.agreement_id
  179. LEFT JOIN esm_ins_company eic ON eic.id = pa.partner_companies_id
  180. WHERE
  181. iac.id = ifa.ins_order_no
  182. AND iac.orderstatus = 3
  183. <if test="params.auditStatus != null and params.auditStatus != ''">
  184. and ifa.auditstatus = #{params.auditStatus}
  185. </if>
  186. <if test="params.quoteStartDateStr != null and params.quoteStartDateStr != '' and params.quoteEndDateStr != null and params.quoteEndDateStr != ''">
  187. and DATE_FORMAT(iac.createtime, '%Y-%m-%d') between #{params.quoteStartDateStr} AND
  188. #{params.quoteEndDateStr}
  189. </if>
  190. <if test="params.orderNo != null and params.orderNo != ''">
  191. AND iac.id= #{params.orderNo}
  192. </if>
  193. <if test="params.licenseNo != null and params.licenseNo != ''">
  194. AND io.licenseno = #{params.licenseNo}
  195. </if>
  196. <if test="params.frameNo != null and params.frameNo != ''">
  197. AND io.frameno = #{params.frameNo}
  198. </if>
  199. <if test="params.insuredName != null and params.insuredName != ''">
  200. AND io.insuredname = #{params.insuredName}
  201. </if>
  202. <if test="params.companyId != null and params.companyId != ''">
  203. AND io.company_id = #{params.companyId}
  204. </if>
  205. <if test="params.engineNo != null and params.engineNo != ''">
  206. and JSON_EXTRACT( io.carinfo, '$.engineNo' ) = #{params.engineNo}
  207. </if>
  208. <if test="params.riskCode != null and params.riskCode != ''">
  209. and iac.product = #{params.riskCode}
  210. </if>
  211. <if test="params.attachStartDateStr != null and params.attachStartDateStr != '' and params.attachStartDateStr != null and params.attachStartDateStr != '' ">
  212. and ((
  213. DATE_FORMAT(iac.jq_start_date, '%Y-%m-%d') BETWEEN #{params.attachStartDateStr}
  214. AND #{params.attachEndDateStr}
  215. )
  216. OR ( DATE_FORMAT(iac.sy_start_date, '%Y-%m-%d') BETWEEN #{params.attachStartDateStr} AND
  217. #{params.attachEndDateStr} )
  218. )
  219. </if>
  220. <if test="params.provinceId != null and params.provinceId != ''">
  221. and io.deptid like "${params.provinceId}%"
  222. </if>
  223. <if test="params.problemOrder != null and params.problemOrder != ''">
  224. and iac.problem_order like "${params.problemOrder}%"
  225. </if>
  226. <if test="params.cityId != null and params.cityId != ''">
  227. and io.deptid like "${params.cityId}%"
  228. </if>
  229. <if test="params.countyId != null and params.countyId != ''">
  230. and io.deptid like "${params.countyId}%"
  231. </if>
  232. <if test="params.houseId != null and params.houseId != ''">
  233. and io.deptid like "${params.houseId}%"
  234. </if>
  235. <if test="params.operatorId != null and params.operatorId != ''">
  236. and io.userid = #{params.operatorId}
  237. </if>
  238. <if test="params.operatorName != null and params.operatorName != ''">
  239. and io.username = #{params.operatorName}
  240. </if>
  241. <if test="params.auditId != null and params.auditId != ''">
  242. and iac.new_operator_id = #{params.auditId}
  243. </if>
  244. <if test="params.agreeId != null and params.agreeId != ''">
  245. and iac.agreement_id = #{params.agreeId}
  246. </if>
  247. <if test="params.managementSource != null and params.managementSource != ''">
  248. and sd.management_source = #{params.managementSource}
  249. </if>
  250. <if test="params.signStartDateStr != null and params.signStartDateStr != '' and params.signEndDateStr != null and params.signEndDateStr != ''">
  251. and DATE_FORMAT(iac.signing_time, '%Y-%m-%d') between #{params.signStartDateStr} AND
  252. #{params.signEndDateStr}
  253. </if>
  254. <if test="params.payStartDateStr != null and params.payStartDateStr != '' and params.payEndDateStr != null and params.payEndDateStr != ''">
  255. and DATE_FORMAT(iac.pay_date, '%Y-%m-%d') between #{params.payStartDateStr} AND #{params.payEndDateStr}
  256. </if>
  257. <if test="params.isExternal != null and params.isExternal != ''">
  258. and io.is_external = #{params.isExternal}
  259. </if>
  260. <if test="params.jqPolicyNo != null and params.jqPolicyNo != ''">
  261. and iac.jqpolicyno = #{params.jqPolicyNo}
  262. </if>
  263. <if test="params.syPolicyNo != null and params.syPolicyNo != ''">
  264. and iac.sypolicyno = #{params.syPolicyNo}
  265. </if>
  266. <if test="params.noPolicyNo != null and params.noPolicyNo != ''">
  267. and iac.cross_insurance like concat('%', #{params.noPolicyNo}, '%')
  268. </if>
  269. order by iac.createtime desc
  270. </select>
  271. <select id="getByUserId" resultType="com.ydtech.modules.order.entity.InsOrders">
  272. SELECT
  273. io.*,
  274. sd.management_source
  275. FROM
  276. ins_orders io left join sys_user su on su.id = io.userid left join sys_dept sd on sd.id = su.dept_id
  277. WHERE
  278. orderno IN (
  279. SELECT
  280. orderno
  281. FROM
  282. ins_area_company
  283. WHERE
  284. id IN ( SELECT ins_order_no FROM ins_fee_order_new WHERE id NOT IN ( SELECT ins_order_no FROM ins_fee_audit ) )
  285. AND orderstatus = 3
  286. )
  287. AND
  288. io.orderstatus= 3
  289. <if test="orderNo != null and orderNo != ''">
  290. AND orderno = #{orderNo}
  291. </if>
  292. <if test="licenseNo != null and licenseNo != ''">
  293. AND licenseno = #{licenseNo}
  294. </if>
  295. <if test="frameNo != null and frameNo != ''">
  296. AND frameno = #{frameNo}
  297. </if>
  298. <if test="userId != null and userId != ''">
  299. AND userid = #{userId}
  300. </if>
  301. <if test="insuredname != null and insuredname != ''">
  302. AND insuredname = #{insuredname}
  303. </if>
  304. <if test="startDateStr != null and startDateStr != ''">
  305. AND createtime BETWEEN #{startDateStr} and #{endDateStr}
  306. </if>
  307. </select>
  308. <select id="selectFirstPromotionBy" resultType="com.ydtech.modules.order.entity.InsOrders">
  309. SELECT
  310. sum(a.first_detail_premiums) as "willFirstPremiums"
  311. FROM
  312. ins_fee_order_new a
  313. LEFT JOIN ins_area_company iac on iac.id=a.ins_order_no
  314. left join ins_fee_audit iff on a.ins_order_no=iff.ins_order_no
  315. WHERE
  316. iff.auditstatus=0
  317. AND iac.orderstatus =3
  318. <if test="firstUserId != null and firstUserId != ''">
  319. AND a.first_level_user_id = #{firstUserId}
  320. </if>
  321. <if test="secondUserId != null and secondUserId != ''">
  322. AND a.two_level_user_id = #{secondUserId}
  323. </if>
  324. <if test="thirdUserId != null and thirdUserId != ''">
  325. AND a.three_level_user_id = #{thirdUserId}
  326. </if>
  327. <if test="id != null and id != ''">
  328. AND a.id = #{id}
  329. </if>
  330. </select>
  331. <select id="selectSecondPromotionBy" resultType="com.ydtech.modules.order.entity.InsOrders">
  332. SELECT
  333. sum( fee.p ) as "willFirstPremiums"
  334. FROM
  335. (
  336. SELECT
  337. sum( a.first_detail_premiums ) AS p
  338. FROM
  339. ins_fee_order_new a
  340. LEFT JOIN ins_area_company iac ON iac.id = a.ins_order_no
  341. left join ins_fee_audit iff on a.ins_order_no=iff.ins_order_no
  342. <where>
  343. iff.auditstatus=0
  344. and iac.orderstatus = '3'
  345. <if test="userId!=null and userId!= ''">
  346. AND a.first_level_user_id = #{userId}
  347. </if>
  348. <if test="id != null and id!=''">
  349. AND a.id =#{id}
  350. </if>
  351. </where>
  352. UNION
  353. SELECT
  354. sum( a.third_detail_premiums ) AS p
  355. FROM
  356. ins_fee_order_new a
  357. LEFT JOIN ins_area_company iac ON iac.id = a.ins_order_no
  358. left join ins_fee_audit iff on a.ins_order_no=iff.ins_order_no
  359. <where>
  360. iff.auditstatus=0
  361. and iac.orderstatus = '3'
  362. <if test="userId!=null and userId!= ''">
  363. AND a.three_level_user_id = #{userId}
  364. </if>
  365. <if test="id != null and id!=''">
  366. AND a.id =#{id}
  367. </if>
  368. </where>
  369. UNION
  370. SELECT
  371. sum( a.second_detail_premiums ) AS p
  372. FROM
  373. ins_fee_order_new a
  374. LEFT JOIN ins_area_company iac ON iac.id = a.ins_order_no
  375. left join ins_fee_audit iff on a.ins_order_no=iff.ins_order_no
  376. <where>
  377. iff.auditstatus=0
  378. and iac.orderstatus = '3'
  379. <if test="userId!=null and userId!= ''">
  380. AND a.two_level_user_id = #{userId}
  381. </if>
  382. <if test="id != null and id!=''">
  383. AND a.id =#{id}
  384. </if>
  385. </where>
  386. ) AS fee
  387. </select>
  388. <select id="selectThirdPromotionBy" resultType="com.ydtech.modules.order.entity.InsOrders">
  389. SELECT
  390. sum(a.third_detail_premiums) as "willThreePremiums"
  391. FROM
  392. ins_fee_order_new a
  393. LEFT JOIN ins_area_company iac on iac.id=a.ins_order_no
  394. left join ins_fee_audit iff on a.ins_order_no=iff.ins_order_no
  395. WHERE
  396. iff.auditstatus=0
  397. AND iac.orderstatus =3
  398. <if test="firstUserId != null and firstUserId != ''">
  399. AND a.first_level_user_id = #{firstUserId}
  400. </if>
  401. <if test="secondUserId != null and secondUserId != ''">
  402. AND a.two_level_user_id = #{secondUserId}
  403. </if>
  404. <if test="thirdUserId != null and thirdUserId != ''">
  405. AND a.three_level_user_id = #{thirdUserId}
  406. </if>
  407. <if test="id != null and id != ''">
  408. AND a.id = #{id}
  409. </if>
  410. </select>
  411. <select id="getAlreadyAuditOrders" resultType="com.ydtech.modules.order.entity.InsOrders">
  412. SELECT
  413. io.*,
  414. sd.management_source,
  415. su2.name AS auditUser,
  416. ifa.audittime as auditTime
  417. FROM
  418. ins_orders io
  419. LEFT JOIN ins_fee_audit ifa ON ifa.orderno = io.orderno
  420. LEFT JOIN sys_user su ON su.id = io.userid
  421. LEFT JOIN sys_dept sd ON sd.id = su.dept_id
  422. LEFT JOIN sys_user su2 on ifa.audituser = su2.id
  423. WHERE
  424. io.orderno IN (
  425. SELECT
  426. orderno
  427. FROM
  428. ins_area_company
  429. WHERE
  430. id IN (
  431. SELECT
  432. ifon.ins_order_no
  433. FROM
  434. ins_fee_order_new ifon
  435. RIGHT JOIN ins_fee_audit ifa ON ifon.ins_order_no = ifa.ins_order_no
  436. WHERE
  437. ifa.auditstatus = #{params.auditStatus}
  438. )
  439. )
  440. AND orderstatus = 3
  441. <!-- <if test="params.orderNo != null and params.orderNo != ''">-->
  442. <!-- AND orderno = #{params.orderNo}-->
  443. <!-- </if>-->
  444. <if test="params.licenseNo != null and params.licenseNo != ''">
  445. AND licenseno = #{params.licenseNo}
  446. </if>
  447. <if test="params.frameNo != null and params.frameNo != ''">
  448. AND frameno = #{params.frameNo}
  449. </if>
  450. <if test="params.insuredName != null and params.insuredName != ''">
  451. AND insuredname = #{params.insuredName}
  452. </if>
  453. <if test="params.companyId != null and params.companyId != ''">
  454. AND company_id = #{params.companyId}
  455. </if>
  456. <if test="params.startDateStr != null and params.startDateStr != ''">
  457. AND createtime BETWEEN #{params.startDateStr} and #{params.endDateStr}
  458. </if>
  459. </select>
  460. <select id="selectListByDateStr" resultType="com.ydtech.modules.order.entity.InsAreaCompany">
  461. -- 查询订单信息
  462. SELECT
  463. iac.*
  464. FROM
  465. ins_area_company iac
  466. left JOIN ins_orders AS io ON io.orderno = iac.orderno
  467. WHERE
  468. 1=1
  469. <if test="dateStr != null and dateStr != ''">
  470. AND DATE_FORMAT(io.createtime, '%Y-%m') =#{dateStr}
  471. </if>
  472. </select>
  473. <select id="selectListById" resultMap="BaseResultMap">
  474. SELECT
  475. iac.*
  476. FROM
  477. ins_area_company iac
  478. WHERE
  479. 1=1
  480. <if test="id != null and id != ''">
  481. AND iac.id =#{id}
  482. </if>
  483. </select>
  484. <select id="selectSecondPromotionByNew" resultType="com.ydtech.modules.order.entity.InsOrders">
  485. SELECT
  486. sum( fee.p ) as "willFirstPremiums"
  487. FROM
  488. (
  489. SELECT
  490. sum( a.first_detail_premiums ) AS p
  491. FROM
  492. ins_fee_order_new a
  493. LEFT JOIN ins_area_company iac ON iac.id = a.ins_order_no
  494. left join ins_fee_audit iff on a.ins_order_no=iff.ins_order_no
  495. <where>
  496. <choose>
  497. <when test='type == "1"'>
  498. iff.auditstatus=0
  499. </when>
  500. <otherwise>
  501. iff.auditstatus=1
  502. </otherwise>
  503. </choose>
  504. and iac.orderstatus = '3'
  505. <if test="userId!=null and userId!= ''">
  506. AND a.first_level_user_id = #{userId}
  507. </if>
  508. <if test="id != null and id!=''">
  509. AND a.id =#{id}
  510. </if>
  511. </where>
  512. UNION
  513. SELECT
  514. sum( a.third_detail_premiums ) AS p
  515. FROM
  516. ins_fee_order_new a
  517. LEFT JOIN ins_area_company iac ON iac.id = a.ins_order_no
  518. left join ins_fee_audit iff on a.ins_order_no=iff.ins_order_no
  519. <where>
  520. <choose>
  521. <when test='type == "1"'>
  522. iff.auditstatus=0
  523. </when>
  524. <otherwise>
  525. iff.auditstatus=1
  526. </otherwise>
  527. </choose>
  528. and iac.orderstatus = '3'
  529. <if test="userId!=null and userId!= ''">
  530. AND a.three_level_user_id = #{userId}
  531. </if>
  532. <if test="id != null and id!=''">
  533. AND a.id =#{id}
  534. </if>
  535. </where>
  536. UNION
  537. SELECT
  538. sum( a.second_detail_premiums ) AS p
  539. FROM
  540. ins_fee_order_new a
  541. LEFT JOIN ins_area_company iac ON iac.id = a.ins_order_no
  542. left join ins_fee_audit iff on a.ins_order_no=iff.ins_order_no
  543. <where>
  544. <choose>
  545. <when test='type == "1"'>
  546. iff.auditstatus=0
  547. </when>
  548. <otherwise>
  549. iff.auditstatus=1
  550. </otherwise>
  551. </choose>
  552. and iac.orderstatus = '3'
  553. <if test="userId!=null and userId!= ''">
  554. AND a.two_level_user_id = #{userId}
  555. </if>
  556. <if test="id != null and id!=''">
  557. AND a.id =#{id}
  558. </if>
  559. </where>
  560. ) AS fee
  561. </select>
  562. <select id="getSubOrderDetails" resultType="com.ydtech.modules.admin.model.vo.SubOrder">
  563. SELECT
  564. iac.id as subOrderId,
  565. iac.signing_time as signingTime,
  566. iac.jqpremium as jqpremium,
  567. iac.sypremium as sypremium,
  568. iac.jypremium as jypremium,
  569. io.licenseno as licenseno,
  570. io.userid as userId
  571. FROM
  572. ins_area_company iac
  573. LEFT JOIN ins_orders AS io ON io.orderno = iac.orderno
  574. WHERE
  575. iac.id=#{subOrderId}
  576. </select>
  577. <select id="premiumReportYear" resultType="com.ydtech.modules.admin.model.dto.PremiumReportDto">
  578. SELECT
  579. CONCAT(YEAR(iac.createtime),'-',LPAD(MONTH(iac.createtime), 2, '0')) reportDate,
  580. sum(jqpremium) jqpremium,
  581. sum(sypremium) sypremium,
  582. sum(sumpremium) sumpremium
  583. FROM
  584. ins_area_company iac left join ins_orders io on iac.orderno=io.orderno
  585. WHERE
  586. iac.orderstatus = 3 and
  587. iac.createtime &gt;= #{beginTime} and iac.createtime &lt;= #{endTime}
  588. and io.userid=#{userId}
  589. GROUP BY CONCAT(YEAR(iac.createtime),'-',LPAD(MONTH(iac.createtime), 2, '0'))
  590. </select>
  591. <select id="premiumReportMonth" resultType="com.ydtech.modules.admin.model.dto.PremiumReportDto">
  592. SELECT
  593. CONCAT(YEAR(iac.createtime),'-',LPAD(MONTH(iac.createtime), 2, '0'),'-',LPAD(Day(iac.createtime), 2, '0')) reportDate,
  594. sum(jqpremium) jqpremium,
  595. sum(sypremium) sypremium,
  596. sum(sumpremium) sumpremium
  597. FROM
  598. ins_area_company iac left join ins_orders io on iac.orderno=io.orderno
  599. WHERE
  600. iac.orderstatus = 3 and
  601. iac.createtime &gt;= #{beginTime} and iac.createtime &lt;= #{endTime}
  602. and io.userid=#{userId}
  603. GROUP BY CONCAT(YEAR(iac.createtime),'-',LPAD(MONTH(iac.createtime), 2, '0'),'-',LPAD(Day(iac.createtime), 2, '0'))
  604. </select>
  605. <select id="premiumReportDay" resultType="com.ydtech.modules.admin.model.dto.PremiumReportDto">
  606. SELECT
  607. CONCAT(YEAR ( iac.createtime ),'-',LPAD( MONTH ( iac.createtime ), 2, '0' ),'-',LPAD( DAY ( iac.createtime ), 2, '0' ),' ',LPAD( HOUR ( iac.createtime ), 2, '0' ))
  608. reportDate,
  609. sum( jqpremium ) jqpremium,
  610. sum( sypremium ) sypremium,
  611. sum( sumpremium ) sumpremium
  612. FROM
  613. ins_area_company iac left join ins_orders io on iac.orderno=io.orderno
  614. WHERE
  615. iac.orderstatus = 3 and
  616. iac.createtime &gt;= #{beginTime} and iac.createtime &lt;= #{endTime}
  617. and io.userid=#{userId}
  618. GROUP BY CONCAT(YEAR ( iac.createtime ),'-',LPAD( MONTH ( iac.createtime ), 2, '0' ),'-',LPAD( DAY ( iac.createtime ), 2, '0' ),' ',LPAD( HOUR ( iac.createtime ), 2, '0' ))
  619. </select>
  620. <select id="getAllpremium" resultType="com.ydtech.modules.admin.model.dto.AllpremiumDto">
  621. SELECT
  622. ifnull(sum( iac.jqpremium + iac.sypremium + iac.jypremium ),0) as sumPremium,
  623. count( 0 ) as sumCount
  624. FROM
  625. ins_area_company iac left join ins_orders io on iac.orderno=io.orderno
  626. WHERE
  627. iac.orderstatus = 3
  628. and io.userid=#{userId}
  629. AND YEAR (iac.createtime) = #{year}
  630. </select>
  631. <select id="getRejectOrder" resultType="com.ydtech.modules.order.entity.InsAreaCompany">
  632. select
  633. iac.id,
  634. iac.orderno,
  635. iac.agreement_id,
  636. iac.jqpremium,
  637. iac.sypremium,
  638. iac.jypremium,
  639. iac.taxamount,
  640. iac.sumpremium,
  641. io.licenseno,
  642. ifa.audittime,
  643. ifa.audituser as auditname,
  644. ifa.rejectinfo,
  645. "1" as orderExternalStatus
  646. FROM
  647. ins_fee_audit ifa
  648. LEFT JOIN
  649. ins_area_company iac on iac.id = ifa.ins_order_no
  650. LEFT JOIN
  651. ins_orders io on iac.orderno = io.orderno
  652. left join
  653. sys_user su on su.id= ifa.audituser
  654. WHERE
  655. iac.operator_id = #{userId}
  656. AND
  657. ifa.auditstatus = 2
  658. <if test="vo.id != null and vo.id!=''">
  659. and iac.id = #{vo.id}
  660. </if>
  661. <if test="vo.licenseno != null and vo.licenseno!='' ">
  662. and io.licenseno like CONCAT('%', #{vo.licenseno}, '%')
  663. </if>
  664. <if test="vo.auditname != null and vo.auditname!='' ">
  665. and su.name like CONCAT('%', #{vo.auditname}, '%')
  666. </if>
  667. </select>
  668. <select id="queryBusinessDataPage"
  669. resultType="com.ydtech.modules.admin.model.report.opetationData.BusinessDataDto">
  670. SELECT
  671. <if test="flag != null and flag!='' and flag='1'">
  672. o.userid as userId,
  673. o.username as userName,
  674. </if>
  675. sum( iac.sumpremium ) as signeSumPremiumAmount,
  676. sum( iac.jqpremium ) as jqPremiumAmount,
  677. sum( iac.sypremium ) as syPremiumAmount,
  678. sum( iac.taxamount ) as taxAmount,
  679. sum( ion.no_premium ) as fcFeeAmount
  680. FROM
  681. ins_area_company iac
  682. LEFT JOIN ins_orders o ON iac.orderno = o.orderno
  683. LEFT JOIN ins_fee_order_new ion ON iac.id = ion.ins_order_no
  684. where iac.orderstatus = 3 and ion.id is not null
  685. <if test="userList != null and userList.size()>0 ">
  686. and o.userid IN
  687. <foreach item="item" collection="userList" open="(" separator="," close=")">
  688. #{item}
  689. </foreach>
  690. </if>
  691. <if test="flag != null and flag!='' and flag='1'">
  692. group by o.userid,o.username
  693. </if>
  694. </select>
  695. <select id="queryQuotationSubOrderCountDataPage"
  696. resultType="com.ydtech.modules.admin.model.report.opetationData.QuotationCountDataDto">
  697. SELECT
  698. <if test="flag != null and flag!='' and flag='1'">
  699. o.userid as userId,
  700. o.username as userName,
  701. </if>
  702. iac.orderstatus as orderStatus
  703. FROM
  704. ins_area_company iac
  705. LEFT JOIN ins_orders o ON iac.orderno = o.orderno
  706. where (iac.orderstatus = 0 or iac.orderstatus = 2 or iac.orderstatus = 3 )
  707. <if test="userList != null and userList.size()>0 ">
  708. and o.userid IN
  709. <foreach item="item" collection="userList" open="(" separator="," close=")">
  710. #{item}
  711. </foreach>
  712. </if>
  713. <if test="flag != null and flag!='' and flag='1'">
  714. group by o.userid,o.username,iac.orderstatus
  715. </if>
  716. </select>
  717. <select id="queryQuotationOrderCountDataPage"
  718. resultType="com.ydtech.modules.admin.model.report.opetationData.QuotationCountDataDto">
  719. SELECT
  720. a.userId as userId,
  721. a.userName as userName,
  722. b.qutationCount AS insOrderQutationCount,
  723. b.qutationInsureCount as insOrderQutationInsureCount,
  724. b.closeRate AS insOrderCloseRate as insOrderCloseRate,
  725. a.qutationCount as subOrderQutationCount,
  726. a.underwritingCount as subOrderUnderwritingCount,
  727. a.qutationInsureCount as subOrderQutationInsureCount,
  728. a.passRate as subOrderCloseRate,
  729. a.closeRate as subOrderPassRate,
  730. a.contributionRate as subOrderContributionRate
  731. FROM
  732. (
  733. SELECT
  734. inso.userid AS userId,
  735. inso.username AS userName,
  736. COUNT( CASE WHEN iac.orderstatus = 0 THEN 1 END ) AS qutationCount,
  737. COUNT( CASE WHEN iac.orderstatus = 2 THEN 1 END ) AS underwritingCount,
  738. COUNT( CASE WHEN iac.orderstatus = 3 THEN 1 END ) AS qutationInsureCount,
  739. COUNT( CASE WHEN iac.orderstatus = 0 THEN 1 END )/ count( iac.orderstatus ) AS passRate,
  740. COUNT( CASE WHEN iac.orderstatus = 3 THEN 1 END )/ count( iac.orderstatus ) AS closeRate,
  741. COUNT( CASE WHEN iac.orderstatus = 3 THEN 1 END )/ COUNT( CASE WHEN iac.orderstatus = 2 THEN 1 END ) AS contributionRate
  742. FROM
  743. ins_area_company iac
  744. LEFT JOIN ins_orders inso ON iac.orderno = inso.orderno
  745. <where>
  746. <if test="userList != null and userList.size()>0 ">
  747. and o.userid IN
  748. <foreach item="item" collection="userList" open="(" separator="," close=")">
  749. #{item}
  750. </foreach>
  751. </if>
  752. </where>
  753. GROUP BY
  754. inso.userid,
  755. inso.username
  756. ) a
  757. LEFT JOIN (
  758. SELECT
  759. inso.userid AS userId,
  760. inso.username AS userName,
  761. count( inso.orderstatus ) AS qutationCount,
  762. count( CASE WHEN inso.orderstatus = 3 THEN 1 END ) AS qutationInsureCount,
  763. COUNT( CASE WHEN inso.orderstatus = 3 THEN 1 END )/ count( inso.orderstatus ) AS closeRate
  764. FROM
  765. ins_orders inso
  766. <where>
  767. <if test="userList != null and userList.size()>0 ">
  768. and o.userid IN
  769. <foreach item="item" collection="userList" open="(" separator="," close=")">
  770. #{item}
  771. </foreach>
  772. </if>
  773. </where>
  774. GROUP BY
  775. inso.userid,
  776. inso.username
  777. ) b ON a.userId = b.userId
  778. </select>
  779. <select id="queryCompanyPremiumDataPage"
  780. resultType="com.ydtech.modules.admin.model.report.company.CompanyPremiumDataDto">
  781. SELECT
  782. agree.insurance_company_id AS companyId,
  783. agree.insurance_company AS companyName,
  784. agree.partner_companies_id AS parterCompanyId,
  785. ins.NAME AS parterCompanyName,
  786. sum( iac.sumpremium ) AS signeSumPremiumAmount
  787. FROM
  788. ins_area_company iac
  789. LEFT JOIN ptl_agreement agree ON iac.agreement_id = agree.id
  790. LEFT JOIN esm_ins_company ins ON agree.partner_companies_id = ins.id
  791. WHERE
  792. iac.orderstatus = 3
  793. and
  794. agree.id is not null
  795. <if test="vo.companyId != null and vo.companyId!='' ">
  796. agree.insurance_company_id = #{vo.companyId}
  797. </if>
  798. <if test="vo.parterCompanyId != null and vo.parterCompanyId!='' ">
  799. agree.insurance_company_id = #{vo.parterCompanyId}
  800. </if>
  801. GROUP BY
  802. agree.insurance_company_id,
  803. agree.insurance_company,
  804. agree.partner_companies_id,
  805. ins.NAME
  806. </select>
  807. <select id="queryCompanyQutationCountDataPage"
  808. resultType="com.ydtech.modules.admin.model.report.company.CompanyQutationCountDataDto">
  809. SELECT
  810. agree.insurance_company_id AS companyId,
  811. agree.insurance_company AS companyName,
  812. agree.partner_companies_id AS parterCompanyId,
  813. ins.NAME AS parterCompanyName,
  814. count(iac.orderstatus) AS qutationCount,
  815. '-' as bigQutationCount,
  816. '-' as bigUnderwritingCount,
  817. '-' as bigCloseRate,
  818. COUNT( CASE WHEN iac.orderstatus = 2 THEN 1 END ) AS underwritingCount,
  819. COUNT( CASE WHEN iac.orderstatus = 3 THEN 1 END ) AS qutationInsureCount,
  820. COUNT( CASE WHEN iac.orderstatus = 0 THEN 1 END )/ count(iac.orderstatus) AS passRate,
  821. COUNT( CASE WHEN iac.orderstatus = 3 THEN 1 END )/ count(iac.orderstatus) AS closeRate,
  822. COUNT( CASE WHEN iac.orderstatus = 3 THEN 1 END )/ COUNT( CASE WHEN iac.orderstatus = 2 THEN 1 END ) AS contributionRate
  823. FROM
  824. ins_area_company iac
  825. LEFT JOIN ptl_agreement agree ON iac.agreement_id = agree.id
  826. LEFT JOIN esm_ins_company ins ON agree.partner_companies_id = ins.id
  827. WHERE
  828. agree.id IS NOT NULL
  829. <if test="vo.companyId != null and vo.companyId!='' ">
  830. agree.insurance_company_id = #{vo.companyId}
  831. </if>
  832. <if test="vo.parterCompanyId != null and vo.parterCompanyId!='' ">
  833. agree.partner_companies_id = #{vo.parterCompanyId}
  834. </if>
  835. <if test="vo.beginDate != null and vo.beginDate!='' and vo.endDate != null and vo.endDate!=''">
  836. AND iac.createtime BETWEEN #{vo.beginDate} AND #{vo.endDate}
  837. </if>
  838. GROUP BY
  839. agree.insurance_company_id,
  840. agree.insurance_company,
  841. agree.partner_companies_id,
  842. ins.NAME
  843. </select>
  844. <select id="getStageOrder" resultType="com.ydtech.modules.order.entity.InsAreaCompany">
  845. select
  846. iac.id,
  847. iac.orderno,
  848. iac.agreement_id,
  849. iac.jqpremium,
  850. iac.sypremium,
  851. iac.jypremium,
  852. iac.taxamount,
  853. iac.sumpremium,
  854. io.licenseno,
  855. iac.createtime,
  856. "0" as orderExternalStatus
  857. FROM
  858. ins_area_company iac
  859. LEFT JOIN
  860. ins_orders io on iac.orderno = io.orderno
  861. left join ptl_agreement agree on iac.agreement_id =agree.id
  862. WHERE
  863. iac.operator_id = #{userId}
  864. AND
  865. iac.orderstatus = 0
  866. and agree.is_external =1
  867. <if test="vo.id != null and vo.id!='' ">
  868. and iac.id = #{vo.id}
  869. </if>
  870. <if test="vo.licenseno != null and vo.licenseno!='' ">
  871. and io.licenseno like CONCAT('%', #{vo.licenseno}, '%')
  872. </if>
  873. </select>
  874. <select id="queryPageTaskStatistics" resultType="com.ydtech.modules.admin.model.dto.TaskStatisticsDto">
  875. SELECT
  876. sd.name as "deptName",
  877. su.name as "userName",
  878. io.userid as "userId",
  879. COUNT( CASE WHEN iac.orderstatus = 0 THEN 1 END ) AS qutationCount,
  880. COUNT( CASE WHEN iac.orderstatus = 2 THEN 1 END ) AS underwritingCount,
  881. COUNT( CASE WHEN iac.orderstatus = 3 THEN 1 END ) AS qutationInsureCount,
  882. COUNT( CASE WHEN iac.orderstatus = 4 THEN 1 END ) AS underwritingReturn,
  883. COUNT( CASE WHEN iac.orderstatus = 2 THEN 1 END ) / COUNT( CASE WHEN iac.orderstatus = 0 THEN 1 END ) as "passingRate",
  884. COUNT( CASE WHEN iac.orderstatus = 3 THEN 1 END ) / COUNT( CASE WHEN iac.orderstatus = 0 THEN 1 END ) as "closeRate",
  885. COUNT( CASE WHEN iac.orderstatus = 3 THEN 1 END ) / COUNT( CASE WHEN iac.orderstatus = 2 THEN 1 END ) as "contributionRate",
  886. COUNT( CASE WHEN iac.orderstatus = 0 THEN 1 END ) / COUNT(iac.orderstatus) as "quotationRate",
  887. COUNT( CASE WHEN ifa.auditstatus = '0' THEN 1 END ) as "auditOrder"
  888. FROM
  889. ins_area_company iac
  890. left join ins_orders io on io.orderno = iac.orderno
  891. left join sys_dept sd on sd.id=io.deptid
  892. left join sys_user su on su.id=io.userid
  893. left join ins_fee_audit ifa on ifa .ins_order_no =iac.id
  894. <where>
  895. sd.management_source = '1'
  896. <if test="taskStatisticsVo.provinceId != null and taskStatisticsVo.provinceId != ''">
  897. and io.deptid like "${taskStatisticsVo.provinceId}%"
  898. </if>
  899. <if test="taskStatisticsVo.cityId != null and taskStatisticsVo.cityId != ''">
  900. and io.deptid like "${taskStatisticsVo.cityId}%"
  901. </if>
  902. <if test="taskStatisticsVo.countyId != null and taskStatisticsVo.countyId != ''">
  903. and io.deptid like "${taskStatisticsVo.countyId}%"
  904. </if>
  905. <if test="taskStatisticsVo.houseId != null and taskStatisticsVo.houseId != ''">
  906. and io.deptid like "${taskStatisticsVo.houseId}%"
  907. </if>
  908. <if test="taskStatisticsVo.createtimeStart !=null and taskStatisticsVo.createtimeStart != '' and taskStatisticsVo.createtimeEnd !=null and taskStatisticsVo.createtimeEnd != ''">
  909. AND DATE_FORMAT( io.createtime, '%Y-%m-%d') BETWEEN #{taskStatisticsVo.createtimeStart} AND #{taskStatisticsVo.createtimeEnd}
  910. </if>
  911. <if test="taskStatisticsVo.days !=null and taskStatisticsVo.days !='' ">
  912. <choose>
  913. <when test="taskStatisticsVo.days =='1'">
  914. and io.createtime >= DATE_SUB(NOW(), INTERVAL 1 DAY)
  915. </when>
  916. <when test="taskStatisticsVo.days =='7'">
  917. and io.createtime >= DATE_SUB(NOW(), INTERVAL 7 DAY)
  918. </when>
  919. <when test="taskStatisticsVo.days =='30'">
  920. and io.createtime >= DATE_SUB(NOW(), INTERVAL 30 DAY)
  921. </when>
  922. </choose>
  923. </if>
  924. </where>
  925. GROUP BY io.userid , su.name, sd.id , sd.name
  926. </select>
  927. <select id="insuranceCompanyQueryPage" resultType="com.ydtech.modules.admin.model.dto.TaskStatisticsDto">
  928. SELECT
  929. pa.insurance_company_id,
  930. pa.insurance_company as "insuranceCompanyName",
  931. eic.namesimple as "partnerCompaniesName",
  932. COUNT( CASE WHEN iac.orderstatus = 0 THEN 1 END ) AS qutationCount,
  933. COUNT( CASE WHEN iac.orderstatus = 2 THEN 1 END ) AS underwritingCount,
  934. COUNT( CASE WHEN iac.orderstatus = 3 THEN 1 END ) AS qutationInsureCount,
  935. COUNT( CASE WHEN iac.orderstatus = 4 THEN 1 END ) AS underwritingReturn,
  936. COUNT( CASE WHEN iac.orderstatus = 2 THEN 1 END ) / COUNT( CASE WHEN iac.orderstatus = 0 THEN 1 END ) AS "passingRate",
  937. COUNT( CASE WHEN iac.orderstatus = 3 THEN 1 END ) / COUNT( CASE WHEN iac.orderstatus = 0 THEN 1 END ) AS "closeRate",
  938. COUNT( CASE WHEN iac.orderstatus = 3 THEN 1 END ) / COUNT( CASE WHEN iac.orderstatus = 2 THEN 1 END ) AS "contributionRate",
  939. COUNT( CASE WHEN iac.orderstatus = 0 THEN 1 END ) / COUNT( iac.orderstatus ) AS "quotationRate",
  940. COUNT( CASE WHEN ifa.auditstatus = '0' THEN 1 END ) AS "auditOrder"
  941. FROM
  942. ins_area_company iac
  943. LEFT JOIN ins_orders io ON io.orderno = iac.orderno
  944. LEFT JOIN sys_dept sd ON sd.id = io.deptid
  945. LEFT JOIN ins_fee_audit ifa ON ifa.ins_order_no = iac.id
  946. LEFT JOIN ptl_agreement pa ON pa.id = iac.agreement_id
  947. LEFT JOIN esm_ins_company eic ON eic.id = pa.partner_companies_id
  948. <where>
  949. pa.insurance_company_id IS NOT NULL
  950. <if test="taskStatisticsVo.provinceId != null and taskStatisticsVo.provinceId != ''">
  951. and io.deptid like "${taskStatisticsVo.provinceId}%"
  952. </if>
  953. <if test="taskStatisticsVo.cityId != null and taskStatisticsVo.cityId != ''">
  954. and io.deptid like "${taskStatisticsVo.cityId}%"
  955. </if>
  956. <if test="taskStatisticsVo.countyId != null and taskStatisticsVo.countyId != ''">
  957. and io.deptid like "${taskStatisticsVo.countyId}%"
  958. </if>
  959. <if test="taskStatisticsVo.houseId != null and taskStatisticsVo.houseId != ''">
  960. and io.deptid like "${taskStatisticsVo.houseId}%"
  961. </if>
  962. <if test="taskStatisticsVo.createtimeStart !=null and taskStatisticsVo.createtimeStart != '' and taskStatisticsVo.createtimeEnd !=null and taskStatisticsVo.createtimeEnd != ''">
  963. AND DATE_FORMAT( io.createtime, '%Y-%m-%d') BETWEEN #{taskStatisticsVo.createtimeStart} AND #{taskStatisticsVo.createtimeEnd}
  964. </if>
  965. <if test="taskStatisticsVo.days !=null and taskStatisticsVo.days !='' ">
  966. <choose>
  967. <when test="taskStatisticsVo.days =='1'">
  968. and io.createtime >= DATE_SUB(NOW(), INTERVAL 1 DAY)
  969. </when>
  970. <when test="taskStatisticsVo.days =='7'">
  971. and io.createtime >= DATE_SUB(NOW(), INTERVAL 7 DAY)
  972. </when>
  973. <when test="taskStatisticsVo.days =='30'">
  974. and io.createtime >= DATE_SUB(NOW(), INTERVAL 30 DAY)
  975. </when>
  976. </choose>
  977. </if>
  978. </where>
  979. GROUP BY
  980. pa.insurance_company_id,
  981. pa.insurance_company,
  982. eic.namesimple,
  983. pa.insurance_company
  984. </select>
  985. <select id="agentStatisticsQueryPage" resultType="com.ydtech.modules.admin.model.dto.TaskStatisticsDto">
  986. SELECT
  987. sd.name as "deptName",
  988. su.name as "userName",
  989. io.userid as "userId",
  990. COUNT( CASE WHEN iac.orderstatus = 0 THEN 1 END ) AS qutationCount,
  991. COUNT( CASE WHEN iac.orderstatus = 2 THEN 1 END ) AS underwritingCount,
  992. COUNT( CASE WHEN iac.orderstatus = 3 THEN 1 END ) AS qutationInsureCount,
  993. COUNT( CASE WHEN iac.orderstatus = 4 THEN 1 END ) AS underwritingReturn,
  994. COUNT( CASE WHEN iac.orderstatus = 2 THEN 1 END ) / COUNT( CASE WHEN iac.orderstatus = 0 THEN 1 END ) as "passingRate",
  995. COUNT( CASE WHEN iac.orderstatus = 3 THEN 1 END ) / COUNT( CASE WHEN iac.orderstatus = 0 THEN 1 END ) as "closeRate",
  996. COUNT( CASE WHEN iac.orderstatus = 3 THEN 1 END ) / COUNT( CASE WHEN iac.orderstatus = 2 THEN 1 END ) as "contributionRate",
  997. COUNT( CASE WHEN iac.orderstatus = 0 THEN 1 END ) / COUNT(iac.orderstatus) as "quotationRate",
  998. COUNT( CASE WHEN ifa.auditstatus = '0' THEN 1 END ) as "auditOrder"
  999. FROM
  1000. ins_area_company iac
  1001. left join ins_orders io on io.orderno = iac.orderno
  1002. left join sys_dept sd on sd.id=io.deptid
  1003. left join sys_user su on su.id=io.userid
  1004. left join ins_fee_audit ifa on ifa .ins_order_no =iac.id
  1005. <where>
  1006. sd.management_source = '2'
  1007. <if test="taskStatisticsVo.provinceId != null and taskStatisticsVo.provinceId != ''">
  1008. and io.deptid like "${taskStatisticsVo.provinceId}%"
  1009. </if>
  1010. <if test="taskStatisticsVo.cityId != null and taskStatisticsVo.cityId != ''">
  1011. and io.deptid like "${taskStatisticsVo.cityId}%"
  1012. </if>
  1013. <if test="taskStatisticsVo.countyId != null and taskStatisticsVo.countyId != ''">
  1014. and io.deptid like "${taskStatisticsVo.countyId}%"
  1015. </if>
  1016. <if test="taskStatisticsVo.houseId != null and taskStatisticsVo.houseId != ''">
  1017. and io.deptid like "${taskStatisticsVo.houseId}%"
  1018. </if>
  1019. <if test="taskStatisticsVo.createtimeStart !=null and taskStatisticsVo.createtimeStart != '' and taskStatisticsVo.createtimeEnd !=null and taskStatisticsVo.createtimeEnd != ''">
  1020. AND DATE_FORMAT( io.createtime, '%Y-%m-%d') BETWEEN #{taskStatisticsVo.createtimeStart} AND #{taskStatisticsVo.createtimeEnd}
  1021. </if>
  1022. <if test="taskStatisticsVo.days !=null and taskStatisticsVo.days !='' ">
  1023. <choose>
  1024. <when test="taskStatisticsVo.days =='1'">
  1025. and io.createtime >= DATE_SUB(NOW(), INTERVAL 1 DAY)
  1026. </when>
  1027. <when test="taskStatisticsVo.days =='7'">
  1028. and io.createtime >= DATE_SUB(NOW(), INTERVAL 7 DAY)
  1029. </when>
  1030. <when test="taskStatisticsVo.days =='30'">
  1031. and io.createtime >= DATE_SUB(NOW(), INTERVAL 30 DAY)
  1032. </when>
  1033. </choose>
  1034. </if>
  1035. </where>
  1036. GROUP BY io.userid , su.name, sd.id , sd.name
  1037. </select>
  1038. <select id="costCenter" resultType="com.ydtech.modules.admin.model.dto.TaskStatisticsDto">
  1039. SELECT
  1040. iac.company_id,
  1041. iac.inscompany as "insuranceCompanyName",
  1042. COUNT( CASE WHEN ifa.auditstatus = 1 THEN 1 END ) AS "auditstatusOrders",
  1043. COUNT( CASE WHEN ifa.auditstatus = 0 THEN 1 END ) AS "auditOrder",
  1044. COUNT( CASE WHEN pa.audit_type = 1 AND ifa.auditstatus = 1 THEN 1 END ) AS "persionAudit",
  1045. COUNT( CASE WHEN pa.audit_type = 2 AND ifa.auditstatus = 1 THEN 1 END ) AS "automaticAudit"
  1046. FROM
  1047. ins_fee_audit ifa
  1048. LEFT JOIN ins_area_company iac ON iac.id = ifa.ins_order_no
  1049. LEFT JOIN ptl_agreement pa ON pa.id = iac.agreement_id
  1050. LEFT JOIN ins_fee_order_new ion ON ion.ins_order_no = iac.id
  1051. <where>
  1052. 1=1
  1053. <if test="taskStatisticsVo.createtimeStart !=null and taskStatisticsVo.createtimeStart != '' and taskStatisticsVo.createtimeEnd !=null and taskStatisticsVo.createtimeEnd != ''">
  1054. AND DATE_FORMAT( ifa.audittime, '%Y-%m-%d') BETWEEN #{taskStatisticsVo.createtimeStart} AND #{taskStatisticsVo.createtimeEnd}
  1055. </if>
  1056. <if test="taskStatisticsVo.days !=null and taskStatisticsVo.days !='' ">
  1057. <choose>
  1058. <when test="taskStatisticsVo.days =='1'">
  1059. and ifa.audittime >= DATE_SUB(NOW(), INTERVAL 1 DAY)
  1060. </when>
  1061. <when test="taskStatisticsVo.days =='7'">
  1062. and ifa.audittime >= DATE_SUB(NOW(), INTERVAL 7 DAY)
  1063. </when>
  1064. <when test="taskStatisticsVo.days =='30'">
  1065. and ifa.audittime >= DATE_SUB(NOW(), INTERVAL 30 DAY)
  1066. </when>
  1067. </choose>
  1068. </if>
  1069. <if test="taskStatisticsVo.riskCode != null and taskStatisticsVo.riskCode != ''">
  1070. and iac.product = #{taskStatisticsVo.riskCode}
  1071. </if>
  1072. </where>
  1073. GROUP BY
  1074. iac.company_id,
  1075. iac.inscompany
  1076. </select>
  1077. </mapper>