InsAreaCompanyMapper.xml 66 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509
  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. <result property="fileStatus" column="fileStatus" jdbcType="VARCHAR"/>
  78. </resultMap>
  79. <sql id="Base_Column_List">
  80. id,orderno,inscompany,
  81. reqtxt,reptxt,jqapplyno,
  82. jqpolicyno,syapplyno,sypolicyno,
  83. riskinfo,kindinfo,jqpremium,
  84. sypremium,taxamount,sumpremium,
  85. jqdiscountrate,sydiscountrate,feerate,
  86. disrate,auditid,auditname,
  87. audittime,auditopinion,jqappoint,
  88. syappoint,createtime,payment_link
  89. </sql>
  90. <select id="selectByOrderNo" resultMap="InsAreaCompanyQueryDto">
  91. SELECT iac.*, pa.agreement_name,
  92. (select IF(count(0)>0,'true','false') from pingan_sh_uploafile where sub_order_no=iac.id AND status=0) as fileStatus
  93. FROM ins_area_company as iac
  94. left join ptl_agreement as pa on pa.id = iac.agreement_id
  95. INNER JOIN (SELECT company_id, max(createtime) AS max_createtime
  96. FROM ins_area_company
  97. WHERE orderno = #{orderNo}
  98. GROUP BY company_id) t ON t.company_id = iac.company_id
  99. AND t.max_createtime = iac.createtime
  100. WHERE iac.orderno = #{orderNo}
  101. </select>
  102. <select id="selectAcceptInsurance" resultMap="InsAreaCompanyQueryDto">
  103. SELECT iac.*, pa.agreement_name,io.is_external,
  104. (select IF(count(0)>0,'true','false') from pingan_sh_uploafile where sub_order_no=iac.id AND status=0) as fileStatus
  105. FROM ins_area_company as iac
  106. left join ptl_agreement as pa on pa.id = iac.agreement_id
  107. left join ins_orders io on iac.orderno=io.orderno
  108. WHERE iac.orderstatus = 3
  109. and iac.orderno = #{orderNo};
  110. </select>
  111. <select id="queryLatestStatus" resultType="java.lang.String">
  112. SELECT iac.orderstatus
  113. FROM ins_area_company as iac
  114. INNER JOIN (SELECT company_id, max(createtime) AS max_createtime
  115. FROM ins_area_company
  116. WHERE orderno = #{orderNo}
  117. GROUP BY company_id) t ON t.company_id = iac.company_id
  118. AND t.max_createtime = iac.createtime
  119. WHERE iac.orderno = #{orderNo}
  120. ORDER BY orderstatus DESC
  121. LIMIT 1
  122. </select>
  123. <select id="getorDerIds" resultType="com.ydtech.modules.order.entity.InsAreaCompany">
  124. SELECT a.id as "id",
  125. a.orderno as "orderno"
  126. FROM ins_area_company a
  127. LEFT JOIN ins_fee_order_new b ON a.id = b.ins_order_no
  128. WHERE a.orderstatus = '3'
  129. or a.orderstatus = '2'
  130. and b.id is not null
  131. </select>
  132. <select id="getAuditOrders" resultType="com.ydtech.modules.order.entity.InsOrders">
  133. SELECT
  134. iac.id as orderno,
  135. io.quoteno,
  136. io.orderstatus,
  137. io.company_id,
  138. io.ins_company,
  139. io.carinfo,
  140. io.userid,
  141. io.username,
  142. io.deptid,
  143. io.deptname,
  144. io.agreeid,
  145. iac.productid,
  146. iac.product,
  147. iac.createtime,
  148. io.frameno,
  149. io.licenseno,
  150. io.insuredname,
  151. io.is_external,
  152. iac.jq_start_date as jqstartdate,
  153. iac.jq_end_date as jqenddate,
  154. iac.sy_start_date as systartdate,
  155. iac.sy_end_date as syenddate,
  156. io.vehicle_and_vessel_tax,
  157. io.operatorid,
  158. iac.operator_name,
  159. sd.management_source,
  160. iac.problem_order,
  161. CASE ifa.audituser
  162. WHEN '自动审核' THEN ifa.audituser
  163. ELSE su2.name END
  164. AS auditUser,
  165. ifa.audittime as auditTime,
  166. ifa.auditstatus as auditStatus,
  167. eic.namesimple as partnerCompaniesName,
  168. iac.id as subOrderId,
  169. iac.signing_time as signingTime,
  170. iac.pay_date as payDate,
  171. pa.agreement_code as agreementCode,
  172. pa.agreement_name as agreementName,
  173. io.entry_status
  174. FROM
  175. ins_fee_audit ifa
  176. LEFT JOIN ins_orders io ON io.orderno = ifa.orderno
  177. LEFT JOIN ins_area_company iac ON iac.orderno = io.orderno
  178. AND iac.orderstatus = 3
  179. LEFT JOIN sys_user su ON su.id = io.userid
  180. LEFT JOIN sys_dept sd ON sd.id = su.dept_id
  181. LEFT JOIN sys_user su2 ON ifa.audituser = su2.id
  182. LEFT JOIN ptl_agreement pa ON pa.id = iac.agreement_id
  183. LEFT JOIN esm_ins_company eic ON eic.id = pa.partner_companies_id
  184. WHERE
  185. iac.id = ifa.ins_order_no
  186. AND iac.orderstatus = 3
  187. <if test="params.auditStatus != null and params.auditStatus != ''">
  188. and ifa.auditstatus = #{params.auditStatus}
  189. </if>
  190. <if test="params.quoteStartDateStr != null and params.quoteStartDateStr != '' and params.quoteEndDateStr != null and params.quoteEndDateStr != ''">
  191. and DATE_FORMAT(iac.createtime, '%Y-%m-%d') between #{params.quoteStartDateStr} AND
  192. #{params.quoteEndDateStr}
  193. </if>
  194. <if test="params.orderNo != null and params.orderNo != ''">
  195. AND iac.id= #{params.orderNo}
  196. </if>
  197. <if test="params.licenseNo != null and params.licenseNo != ''">
  198. AND io.licenseno = #{params.licenseNo}
  199. </if>
  200. <if test="params.frameNo != null and params.frameNo != ''">
  201. AND io.frameno = #{params.frameNo}
  202. </if>
  203. <if test="params.insuredName != null and params.insuredName != ''">
  204. AND io.insuredname = #{params.insuredName}
  205. </if>
  206. <if test="params.companyId != null and params.companyId != ''">
  207. AND io.company_id = #{params.companyId}
  208. </if>
  209. <if test="params.engineNo != null and params.engineNo != ''">
  210. and JSON_EXTRACT( io.carinfo, '$.engineNo' ) = #{params.engineNo}
  211. </if>
  212. <if test="params.riskCode != null and params.riskCode != ''">
  213. and iac.product = #{params.riskCode}
  214. </if>
  215. <if test="params.attachStartDateStr != null and params.attachStartDateStr != '' and params.attachStartDateStr != null and params.attachStartDateStr != '' ">
  216. and ((
  217. DATE_FORMAT(iac.jq_start_date, '%Y-%m-%d') BETWEEN #{params.attachStartDateStr}
  218. AND #{params.attachEndDateStr}
  219. )
  220. OR ( DATE_FORMAT(iac.sy_start_date, '%Y-%m-%d') BETWEEN #{params.attachStartDateStr} AND
  221. #{params.attachEndDateStr} )
  222. )
  223. </if>
  224. <if test="params.provinceId != null and params.provinceId != ''">
  225. and io.deptid like "${params.provinceId}%"
  226. </if>
  227. <if test="params.problemOrder != null and params.problemOrder != ''">
  228. and iac.problem_order like "${params.problemOrder}%"
  229. </if>
  230. <if test="params.cityId != null and params.cityId != ''">
  231. and io.deptid like "${params.cityId}%"
  232. </if>
  233. <if test="params.countyId != null and params.countyId != ''">
  234. and io.deptid like "${params.countyId}%"
  235. </if>
  236. <if test="params.houseId != null and params.houseId != ''">
  237. and io.deptid like "${params.houseId}%"
  238. </if>
  239. <if test="params.operatorId != null and params.operatorId != ''">
  240. and io.userid = #{params.operatorId}
  241. </if>
  242. <if test="params.operatorName != null and params.operatorName != ''">
  243. and io.username = #{params.operatorName}
  244. </if>
  245. <if test="params.auditId != null and params.auditId != ''">
  246. and iac.new_operator_id = #{params.auditId}
  247. </if>
  248. <if test="params.agreeId != null and params.agreeId != ''">
  249. and iac.agreement_id = #{params.agreeId}
  250. </if>
  251. <if test="params.managementSource != null and params.managementSource != ''">
  252. and sd.management_source = #{params.managementSource}
  253. </if>
  254. <if test="params.signStartDateStr != null and params.signStartDateStr != '' and params.signEndDateStr != null and params.signEndDateStr != ''">
  255. and DATE_FORMAT(iac.signing_time, '%Y-%m-%d') between #{params.signStartDateStr} AND
  256. #{params.signEndDateStr}
  257. </if>
  258. <if test="params.payStartDateStr != null and params.payStartDateStr != '' and params.payEndDateStr != null and params.payEndDateStr != ''">
  259. and DATE_FORMAT(iac.pay_date, '%Y-%m-%d') between #{params.payStartDateStr} AND #{params.payEndDateStr}
  260. </if>
  261. <if test="params.isExternal != null and params.isExternal != ''">
  262. and io.is_external = #{params.isExternal}
  263. </if>
  264. <if test="params.jqPolicyNo != null and params.jqPolicyNo != ''">
  265. and iac.jqpolicyno = #{params.jqPolicyNo}
  266. </if>
  267. <if test="params.syPolicyNo != null and params.syPolicyNo != ''">
  268. and iac.sypolicyno = #{params.syPolicyNo}
  269. </if>
  270. <if test="params.noPolicyNo != null and params.noPolicyNo != ''">
  271. and iac.cross_insurance like concat('%', #{params.noPolicyNo}, '%')
  272. </if>
  273. order by iac.createtime desc
  274. </select>
  275. <select id="getByUserId" resultType="com.ydtech.modules.order.entity.InsOrders">
  276. SELECT
  277. io.*,
  278. sd.management_source
  279. FROM
  280. ins_orders io left join sys_user su on su.id = io.userid left join sys_dept sd on sd.id = su.dept_id
  281. WHERE
  282. orderno IN (
  283. SELECT
  284. orderno
  285. FROM
  286. ins_area_company
  287. WHERE
  288. id IN ( SELECT ins_order_no FROM ins_fee_order_new WHERE id NOT IN ( SELECT ins_order_no FROM ins_fee_audit ) )
  289. AND orderstatus = 3
  290. )
  291. AND
  292. io.orderstatus= 3
  293. <if test="orderNo != null and orderNo != ''">
  294. AND orderno = #{orderNo}
  295. </if>
  296. <if test="licenseNo != null and licenseNo != ''">
  297. AND licenseno = #{licenseNo}
  298. </if>
  299. <if test="frameNo != null and frameNo != ''">
  300. AND frameno = #{frameNo}
  301. </if>
  302. <if test="userId != null and userId != ''">
  303. AND userid = #{userId}
  304. </if>
  305. <if test="insuredname != null and insuredname != ''">
  306. AND insuredname = #{insuredname}
  307. </if>
  308. <if test="startDateStr != null and startDateStr != ''">
  309. AND createtime BETWEEN #{startDateStr} and #{endDateStr}
  310. </if>
  311. </select>
  312. <select id="selectFirstPromotionBy" resultType="com.ydtech.modules.order.entity.InsOrders">
  313. SELECT
  314. sum(a.first_detail_premiums) as "willFirstPremiums"
  315. FROM
  316. ins_fee_order_new a
  317. LEFT JOIN ins_area_company iac on iac.id=a.ins_order_no
  318. left join ins_fee_audit iff on a.ins_order_no=iff.ins_order_no
  319. WHERE
  320. iff.auditstatus=0
  321. AND iac.orderstatus =3
  322. <if test="firstUserId != null and firstUserId != ''">
  323. AND a.first_level_user_id = #{firstUserId}
  324. </if>
  325. <if test="secondUserId != null and secondUserId != ''">
  326. AND a.two_level_user_id = #{secondUserId}
  327. </if>
  328. <if test="thirdUserId != null and thirdUserId != ''">
  329. AND a.three_level_user_id = #{thirdUserId}
  330. </if>
  331. <if test="id != null and id != ''">
  332. AND a.id = #{id}
  333. </if>
  334. </select>
  335. <select id="selectSecondPromotionBy" resultType="com.ydtech.modules.order.entity.InsOrders">
  336. SELECT
  337. sum( fee.p ) as "willFirstPremiums"
  338. FROM
  339. (
  340. SELECT
  341. sum( a.first_detail_premiums ) AS p
  342. FROM
  343. ins_fee_order_new a
  344. LEFT JOIN ins_area_company iac ON iac.id = a.ins_order_no
  345. left join ins_fee_audit iff on a.ins_order_no=iff.ins_order_no
  346. <where>
  347. iff.auditstatus=0
  348. and iac.orderstatus = '3'
  349. <if test="userId!=null and userId!= ''">
  350. AND a.first_level_user_id = #{userId}
  351. </if>
  352. <if test="id != null and id!=''">
  353. AND a.id =#{id}
  354. </if>
  355. </where>
  356. UNION
  357. SELECT
  358. sum( a.third_detail_premiums ) AS p
  359. FROM
  360. ins_fee_order_new a
  361. LEFT JOIN ins_area_company iac ON iac.id = a.ins_order_no
  362. left join ins_fee_audit iff on a.ins_order_no=iff.ins_order_no
  363. <where>
  364. iff.auditstatus=0
  365. and iac.orderstatus = '3'
  366. <if test="userId!=null and userId!= ''">
  367. AND a.three_level_user_id = #{userId}
  368. </if>
  369. <if test="id != null and id!=''">
  370. AND a.id =#{id}
  371. </if>
  372. </where>
  373. UNION
  374. SELECT
  375. sum( a.second_detail_premiums ) AS p
  376. FROM
  377. ins_fee_order_new a
  378. LEFT JOIN ins_area_company iac ON iac.id = a.ins_order_no
  379. left join ins_fee_audit iff on a.ins_order_no=iff.ins_order_no
  380. <where>
  381. iff.auditstatus=0
  382. and iac.orderstatus = '3'
  383. <if test="userId!=null and userId!= ''">
  384. AND a.two_level_user_id = #{userId}
  385. </if>
  386. <if test="id != null and id!=''">
  387. AND a.id =#{id}
  388. </if>
  389. </where>
  390. ) AS fee
  391. </select>
  392. <select id="selectThirdPromotionBy" resultType="com.ydtech.modules.order.entity.InsOrders">
  393. SELECT
  394. sum(a.third_detail_premiums) as "willThreePremiums"
  395. FROM
  396. ins_fee_order_new a
  397. LEFT JOIN ins_area_company iac on iac.id=a.ins_order_no
  398. left join ins_fee_audit iff on a.ins_order_no=iff.ins_order_no
  399. WHERE
  400. iff.auditstatus=0
  401. AND iac.orderstatus =3
  402. <if test="firstUserId != null and firstUserId != ''">
  403. AND a.first_level_user_id = #{firstUserId}
  404. </if>
  405. <if test="secondUserId != null and secondUserId != ''">
  406. AND a.two_level_user_id = #{secondUserId}
  407. </if>
  408. <if test="thirdUserId != null and thirdUserId != ''">
  409. AND a.three_level_user_id = #{thirdUserId}
  410. </if>
  411. <if test="id != null and id != ''">
  412. AND a.id = #{id}
  413. </if>
  414. </select>
  415. <select id="getAlreadyAuditOrders" resultType="com.ydtech.modules.order.entity.InsOrders">
  416. SELECT
  417. io.*,
  418. sd.management_source,
  419. su2.name AS auditUser,
  420. ifa.audittime as auditTime
  421. FROM
  422. ins_orders io
  423. LEFT JOIN ins_fee_audit ifa ON ifa.orderno = io.orderno
  424. LEFT JOIN sys_user su ON su.id = io.userid
  425. LEFT JOIN sys_dept sd ON sd.id = su.dept_id
  426. LEFT JOIN sys_user su2 on ifa.audituser = su2.id
  427. WHERE
  428. io.orderno IN (
  429. SELECT
  430. orderno
  431. FROM
  432. ins_area_company
  433. WHERE
  434. id IN (
  435. SELECT
  436. ifon.ins_order_no
  437. FROM
  438. ins_fee_order_new ifon
  439. RIGHT JOIN ins_fee_audit ifa ON ifon.ins_order_no = ifa.ins_order_no
  440. WHERE
  441. ifa.auditstatus = #{params.auditStatus}
  442. )
  443. )
  444. AND orderstatus = 3
  445. <!-- <if test="params.orderNo != null and params.orderNo != ''">-->
  446. <!-- AND orderno = #{params.orderNo}-->
  447. <!-- </if>-->
  448. <if test="params.licenseNo != null and params.licenseNo != ''">
  449. AND licenseno = #{params.licenseNo}
  450. </if>
  451. <if test="params.frameNo != null and params.frameNo != ''">
  452. AND frameno = #{params.frameNo}
  453. </if>
  454. <if test="params.insuredName != null and params.insuredName != ''">
  455. AND insuredname = #{params.insuredName}
  456. </if>
  457. <if test="params.companyId != null and params.companyId != ''">
  458. AND company_id = #{params.companyId}
  459. </if>
  460. <if test="params.startDateStr != null and params.startDateStr != ''">
  461. AND createtime BETWEEN #{params.startDateStr} and #{params.endDateStr}
  462. </if>
  463. </select>
  464. <select id="selectListByDateStr" resultType="com.ydtech.modules.order.entity.InsAreaCompany">
  465. -- 查询订单信息
  466. SELECT
  467. iac.*
  468. FROM
  469. ins_area_company iac
  470. left JOIN ins_orders AS io ON io.orderno = iac.orderno
  471. WHERE
  472. 1=1
  473. <if test="dateStr != null and dateStr != ''">
  474. AND DATE_FORMAT(io.createtime, '%Y-%m') =#{dateStr}
  475. </if>
  476. </select>
  477. <select id="selectListById" resultMap="BaseResultMap">
  478. SELECT
  479. iac.*
  480. FROM
  481. ins_area_company iac
  482. WHERE
  483. 1=1
  484. <if test="id != null and id != ''">
  485. AND iac.id =#{id}
  486. </if>
  487. </select>
  488. <select id="selectSecondPromotionByNew" resultType="com.ydtech.modules.order.entity.InsOrders">
  489. SELECT
  490. sum( fee.p ) as "willFirstPremiums"
  491. FROM
  492. (
  493. SELECT
  494. sum( a.first_detail_premiums ) AS p
  495. FROM
  496. ins_fee_order_new a
  497. LEFT JOIN ins_area_company iac ON iac.id = a.ins_order_no
  498. left join ins_fee_audit iff on a.ins_order_no=iff.ins_order_no
  499. <where>
  500. <choose>
  501. <when test='type == "1"'>
  502. iff.auditstatus=0
  503. </when>
  504. <otherwise>
  505. iff.auditstatus=1
  506. </otherwise>
  507. </choose>
  508. and iac.orderstatus = '3'
  509. <if test="userId!=null and userId!= ''">
  510. AND a.first_level_user_id = #{userId}
  511. </if>
  512. <if test="id != null and id!=''">
  513. AND a.id =#{id}
  514. </if>
  515. </where>
  516. UNION
  517. SELECT
  518. sum( a.third_detail_premiums ) AS p
  519. FROM
  520. ins_fee_order_new a
  521. LEFT JOIN ins_area_company iac ON iac.id = a.ins_order_no
  522. left join ins_fee_audit iff on a.ins_order_no=iff.ins_order_no
  523. <where>
  524. <choose>
  525. <when test='type == "1"'>
  526. iff.auditstatus=0
  527. </when>
  528. <otherwise>
  529. iff.auditstatus=1
  530. </otherwise>
  531. </choose>
  532. and iac.orderstatus = '3'
  533. <if test="userId!=null and userId!= ''">
  534. AND a.three_level_user_id = #{userId}
  535. </if>
  536. <if test="id != null and id!=''">
  537. AND a.id =#{id}
  538. </if>
  539. </where>
  540. UNION
  541. SELECT
  542. sum( a.second_detail_premiums ) AS p
  543. FROM
  544. ins_fee_order_new a
  545. LEFT JOIN ins_area_company iac ON iac.id = a.ins_order_no
  546. left join ins_fee_audit iff on a.ins_order_no=iff.ins_order_no
  547. <where>
  548. <choose>
  549. <when test='type == "1"'>
  550. iff.auditstatus=0
  551. </when>
  552. <otherwise>
  553. iff.auditstatus=1
  554. </otherwise>
  555. </choose>
  556. and iac.orderstatus = '3'
  557. <if test="userId!=null and userId!= ''">
  558. AND a.two_level_user_id = #{userId}
  559. </if>
  560. <if test="id != null and id!=''">
  561. AND a.id =#{id}
  562. </if>
  563. </where>
  564. ) AS fee
  565. </select>
  566. <select id="getSubOrderDetails" resultType="com.ydtech.modules.admin.model.vo.SubOrder">
  567. SELECT
  568. iac.id as subOrderId,
  569. iac.signing_time as signingTime,
  570. iac.jqpremium as jqpremium,
  571. iac.sypremium as sypremium,
  572. iac.jypremium as jypremium,
  573. io.licenseno as licenseno,
  574. io.userid as userId
  575. FROM
  576. ins_area_company iac
  577. LEFT JOIN ins_orders AS io ON io.orderno = iac.orderno
  578. WHERE
  579. iac.id=#{subOrderId}
  580. </select>
  581. <select id="premiumReportYear" resultType="com.ydtech.modules.admin.model.dto.PremiumReportDto">
  582. SELECT
  583. CONCAT(YEAR(iac.createtime),'-',LPAD(MONTH(iac.createtime), 2, '0')) reportDate,
  584. sum(jqpremium) jqpremium,
  585. sum(sypremium) sypremium,
  586. sum(sumpremium) sumpremium
  587. FROM
  588. ins_area_company iac left join ins_orders io on iac.orderno=io.orderno
  589. WHERE
  590. iac.orderstatus = 3 and
  591. iac.createtime &gt;= #{beginTime} and iac.createtime &lt;= #{endTime}
  592. and io.userid=#{userId}
  593. GROUP BY CONCAT(YEAR(iac.createtime),'-',LPAD(MONTH(iac.createtime), 2, '0'))
  594. </select>
  595. <select id="premiumReportMonth" resultType="com.ydtech.modules.admin.model.dto.PremiumReportDto">
  596. SELECT
  597. CONCAT(YEAR(iac.createtime),'-',LPAD(MONTH(iac.createtime), 2, '0'),'-',LPAD(Day(iac.createtime), 2, '0')) reportDate,
  598. sum(jqpremium) jqpremium,
  599. sum(sypremium) sypremium,
  600. sum(sumpremium) sumpremium
  601. FROM
  602. ins_area_company iac left join ins_orders io on iac.orderno=io.orderno
  603. WHERE
  604. iac.orderstatus = 3 and
  605. iac.createtime &gt;= #{beginTime} and iac.createtime &lt;= #{endTime}
  606. and io.userid=#{userId}
  607. GROUP BY CONCAT(YEAR(iac.createtime),'-',LPAD(MONTH(iac.createtime), 2, '0'),'-',LPAD(Day(iac.createtime), 2, '0'))
  608. </select>
  609. <select id="premiumReportDay" resultType="com.ydtech.modules.admin.model.dto.PremiumReportDto">
  610. SELECT
  611. CONCAT(YEAR ( iac.createtime ),'-',LPAD( MONTH ( iac.createtime ), 2, '0' ),'-',LPAD( DAY ( iac.createtime ), 2, '0' ),' ',LPAD( HOUR ( iac.createtime ), 2, '0' ))
  612. reportDate,
  613. sum( jqpremium ) jqpremium,
  614. sum( sypremium ) sypremium,
  615. sum( sumpremium ) sumpremium
  616. FROM
  617. ins_area_company iac left join ins_orders io on iac.orderno=io.orderno
  618. WHERE
  619. iac.orderstatus = 3 and
  620. iac.createtime &gt;= #{beginTime} and iac.createtime &lt;= #{endTime}
  621. and io.userid=#{userId}
  622. GROUP BY CONCAT(YEAR ( iac.createtime ),'-',LPAD( MONTH ( iac.createtime ), 2, '0' ),'-',LPAD( DAY ( iac.createtime ), 2, '0' ),' ',LPAD( HOUR ( iac.createtime ), 2, '0' ))
  623. </select>
  624. <select id="getAllpremium" resultType="com.ydtech.modules.admin.model.dto.AllpremiumDto">
  625. SELECT
  626. ifnull(sum( iac.jqpremium + iac.sypremium + iac.jypremium ),0) as sumPremium,
  627. count( 0 ) as sumCount
  628. FROM
  629. ins_area_company iac left join ins_orders io on iac.orderno=io.orderno
  630. WHERE
  631. iac.orderstatus = 3
  632. and io.userid=#{userId}
  633. AND YEAR (iac.createtime) = #{year}
  634. </select>
  635. <select id="getRejectOrder" resultType="com.ydtech.modules.order.entity.InsAreaCompany">
  636. select
  637. iac.id,
  638. iac.orderno,
  639. iac.agreement_id,
  640. iac.jqpremium,
  641. iac.sypremium,
  642. iac.jypremium,
  643. iac.taxamount,
  644. iac.sumpremium,
  645. io.licenseno,
  646. ifa.audittime,
  647. ifa.audituser as auditname,
  648. ifa.rejectinfo,
  649. "1" as orderExternalStatus
  650. FROM
  651. ins_fee_audit ifa
  652. LEFT JOIN
  653. ins_area_company iac on iac.id = ifa.ins_order_no
  654. LEFT JOIN
  655. ins_orders io on iac.orderno = io.orderno
  656. left join
  657. sys_user su on su.id= ifa.audituser
  658. WHERE
  659. iac.operator_id = #{userId}
  660. AND
  661. ifa.auditstatus = 2
  662. <if test="vo.id != null and vo.id!=''">
  663. and iac.id = #{vo.id}
  664. </if>
  665. <if test="vo.licenseno != null and vo.licenseno!='' ">
  666. and io.licenseno like CONCAT('%', #{vo.licenseno}, '%')
  667. </if>
  668. <if test="vo.auditname != null and vo.auditname!='' ">
  669. and su.name like CONCAT('%', #{vo.auditname}, '%')
  670. </if>
  671. </select>
  672. <select id="queryBusinessDataPage"
  673. resultType="com.ydtech.modules.admin.model.report.opetationData.BusinessDataDto">
  674. SELECT
  675. <if test="flag != null and flag!='' and flag='1'">
  676. o.userid as userId,
  677. o.username as userName,
  678. </if>
  679. sum( iac.sumpremium ) as signeSumPremiumAmount,
  680. sum( iac.jqpremium ) as jqPremiumAmount,
  681. sum( iac.sypremium ) as syPremiumAmount,
  682. sum( iac.taxamount ) as taxAmount,
  683. sum( ion.no_premium ) as fcFeeAmount
  684. FROM
  685. ins_area_company iac
  686. LEFT JOIN ins_orders o ON iac.orderno = o.orderno
  687. LEFT JOIN ins_fee_order_new ion ON iac.id = ion.ins_order_no
  688. where iac.orderstatus = 3 and ion.id is not null
  689. <if test="userList != null and userList.size()>0 ">
  690. and o.userid IN
  691. <foreach item="item" collection="userList" open="(" separator="," close=")">
  692. #{item}
  693. </foreach>
  694. </if>
  695. <if test="flag != null and flag!='' and flag='1'">
  696. group by o.userid,o.username
  697. </if>
  698. </select>
  699. <select id="queryQuotationSubOrderCountDataPage"
  700. resultType="com.ydtech.modules.admin.model.report.opetationData.QuotationCountDataDto">
  701. SELECT
  702. <if test="flag != null and flag!='' and flag='1'">
  703. o.userid as userId,
  704. o.username as userName,
  705. </if>
  706. iac.orderstatus as orderStatus
  707. FROM
  708. ins_area_company iac
  709. LEFT JOIN ins_orders o ON iac.orderno = o.orderno
  710. where (iac.orderstatus = 0 or iac.orderstatus = 2 or iac.orderstatus = 3 )
  711. <if test="userList != null and userList.size()>0 ">
  712. and o.userid IN
  713. <foreach item="item" collection="userList" open="(" separator="," close=")">
  714. #{item}
  715. </foreach>
  716. </if>
  717. <if test="flag != null and flag!='' and flag='1'">
  718. group by o.userid,o.username,iac.orderstatus
  719. </if>
  720. </select>
  721. <select id="queryQuotationOrderCountDataPage"
  722. resultType="com.ydtech.modules.admin.model.report.opetationData.QuotationCountDataDto">
  723. SELECT
  724. a.userId as userId,
  725. a.userName as userName,
  726. b.qutationCount AS insOrderQutationCount,
  727. b.qutationInsureCount as insOrderQutationInsureCount,
  728. b.closeRate AS insOrderCloseRate as insOrderCloseRate,
  729. a.qutationCount as subOrderQutationCount,
  730. a.underwritingCount as subOrderUnderwritingCount,
  731. a.qutationInsureCount as subOrderQutationInsureCount,
  732. a.passRate as subOrderCloseRate,
  733. a.closeRate as subOrderPassRate,
  734. a.contributionRate as subOrderContributionRate
  735. FROM
  736. (
  737. SELECT
  738. inso.userid AS userId,
  739. inso.username AS userName,
  740. COUNT( CASE WHEN iac.orderstatus = 0 THEN 1 END ) AS qutationCount,
  741. COUNT( CASE WHEN iac.orderstatus = 2 THEN 1 END ) AS underwritingCount,
  742. COUNT( CASE WHEN iac.orderstatus = 3 THEN 1 END ) AS qutationInsureCount,
  743. COUNT( CASE WHEN iac.orderstatus = 0 THEN 1 END )/ count( iac.orderstatus ) AS passRate,
  744. COUNT( CASE WHEN iac.orderstatus = 3 THEN 1 END )/ count( iac.orderstatus ) AS closeRate,
  745. COUNT( CASE WHEN iac.orderstatus = 3 THEN 1 END )/ COUNT( CASE WHEN iac.orderstatus = 2 THEN 1 END ) AS contributionRate
  746. FROM
  747. ins_area_company iac
  748. LEFT JOIN ins_orders inso ON iac.orderno = inso.orderno
  749. <where>
  750. <if test="userList != null and userList.size()>0 ">
  751. and o.userid IN
  752. <foreach item="item" collection="userList" open="(" separator="," close=")">
  753. #{item}
  754. </foreach>
  755. </if>
  756. </where>
  757. GROUP BY
  758. inso.userid,
  759. inso.username
  760. ) a
  761. LEFT JOIN (
  762. SELECT
  763. inso.userid AS userId,
  764. inso.username AS userName,
  765. count( inso.orderstatus ) AS qutationCount,
  766. count( CASE WHEN inso.orderstatus = 3 THEN 1 END ) AS qutationInsureCount,
  767. COUNT( CASE WHEN inso.orderstatus = 3 THEN 1 END )/ count( inso.orderstatus ) AS closeRate
  768. FROM
  769. ins_orders inso
  770. <where>
  771. <if test="userList != null and userList.size()>0 ">
  772. and o.userid IN
  773. <foreach item="item" collection="userList" open="(" separator="," close=")">
  774. #{item}
  775. </foreach>
  776. </if>
  777. </where>
  778. GROUP BY
  779. inso.userid,
  780. inso.username
  781. ) b ON a.userId = b.userId
  782. </select>
  783. <select id="queryCompanyPremiumDataPage"
  784. resultType="com.ydtech.modules.admin.model.report.company.CompanyPremiumDataDto">
  785. SELECT
  786. agree.insurance_company_id AS companyId,
  787. agree.insurance_company AS companyName,
  788. agree.partner_companies_id AS parterCompanyId,
  789. ins.NAME AS parterCompanyName,
  790. sum( iac.sumpremium ) AS signeSumPremiumAmount
  791. FROM
  792. ins_area_company iac
  793. LEFT JOIN ptl_agreement agree ON iac.agreement_id = agree.id
  794. LEFT JOIN esm_ins_company ins ON agree.partner_companies_id = ins.id
  795. WHERE
  796. iac.orderstatus = 3
  797. and
  798. agree.id is not null
  799. <if test="vo.companyId != null and vo.companyId!='' ">
  800. agree.insurance_company_id = #{vo.companyId}
  801. </if>
  802. <if test="vo.parterCompanyId != null and vo.parterCompanyId!='' ">
  803. agree.insurance_company_id = #{vo.parterCompanyId}
  804. </if>
  805. GROUP BY
  806. agree.insurance_company_id,
  807. agree.insurance_company,
  808. agree.partner_companies_id,
  809. ins.NAME
  810. </select>
  811. <select id="queryCompanyQutationCountDataPage"
  812. resultType="com.ydtech.modules.admin.model.report.company.CompanyQutationCountDataDto">
  813. SELECT
  814. agree.insurance_company_id AS companyId,
  815. agree.insurance_company AS companyName,
  816. agree.partner_companies_id AS parterCompanyId,
  817. ins.NAME AS parterCompanyName,
  818. count(iac.orderstatus) AS qutationCount,
  819. '-' as bigQutationCount,
  820. '-' as bigUnderwritingCount,
  821. '-' as bigCloseRate,
  822. COUNT( CASE WHEN iac.orderstatus = 2 THEN 1 END ) AS underwritingCount,
  823. COUNT( CASE WHEN iac.orderstatus = 3 THEN 1 END ) AS qutationInsureCount,
  824. COUNT( CASE WHEN iac.orderstatus = 0 THEN 1 END )/ count(iac.orderstatus) AS passRate,
  825. COUNT( CASE WHEN iac.orderstatus = 3 THEN 1 END )/ count(iac.orderstatus) AS closeRate,
  826. COUNT( CASE WHEN iac.orderstatus = 3 THEN 1 END )/ COUNT( CASE WHEN iac.orderstatus = 2 THEN 1 END ) AS contributionRate
  827. FROM
  828. ins_area_company iac
  829. LEFT JOIN ptl_agreement agree ON iac.agreement_id = agree.id
  830. LEFT JOIN esm_ins_company ins ON agree.partner_companies_id = ins.id
  831. LEFT JOIN ins_orders io on iac.orderno = io.orderno
  832. LEFT JOIN sys_dept sd on sd.id = io.deptid
  833. WHERE
  834. agree.id IS NOT NULL
  835. <if test="vo.companyId != null and vo.companyId!='' ">
  836. agree.insurance_company_id = #{vo.companyId}
  837. </if>
  838. <if test="vo.parterCompanyId != null and vo.parterCompanyId!='' ">
  839. agree.partner_companies_id = #{vo.parterCompanyId}
  840. </if>
  841. <if test="vo.beginDate != null and vo.beginDate!='' and vo.endDate != null and vo.endDate!=''">
  842. AND iac.signing_time BETWEEN #{vo.beginDate} AND #{vo.endDate}
  843. </if>
  844. <if test="vo.managementSource != null and vo.managementSource!=''">
  845. AND sd.management_source =#{vo.managementSource}
  846. </if>
  847. GROUP BY
  848. agree.insurance_company_id,
  849. agree.insurance_company,
  850. agree.partner_companies_id,
  851. ins.NAME
  852. </select>
  853. <select id="getStageOrder" resultType="com.ydtech.modules.order.entity.InsAreaCompany">
  854. select
  855. iac.id,
  856. iac.orderno,
  857. iac.agreement_id,
  858. iac.jqpremium,
  859. iac.sypremium,
  860. iac.jypremium,
  861. iac.taxamount,
  862. iac.sumpremium,
  863. io.licenseno,
  864. iac.createtime,
  865. "0" as orderExternalStatus
  866. FROM
  867. ins_area_company iac
  868. LEFT JOIN
  869. ins_orders io on iac.orderno = io.orderno
  870. left join ptl_agreement agree on iac.agreement_id =agree.id
  871. WHERE
  872. iac.operator_id = #{userId}
  873. AND
  874. iac.orderstatus = 0
  875. and agree.is_external =1
  876. <if test="vo.id != null and vo.id!='' ">
  877. and iac.id = #{vo.id}
  878. </if>
  879. <if test="vo.licenseno != null and vo.licenseno!='' ">
  880. and io.licenseno like CONCAT('%', #{vo.licenseno}, '%')
  881. </if>
  882. </select>
  883. <select id="queryPageTaskStatistics" resultType="com.ydtech.modules.admin.model.dto.TaskStatisticsDto">
  884. select a.*,(select name from sys_user where id =a.userId) as "userName"
  885. from (
  886. SELECT
  887. sd.NAME AS "deptName",
  888. io.userid AS "userId",
  889. COUNT( CASE WHEN iac.orderstatus = 0 THEN 1 END ) AS qutationCount,
  890. COUNT( CASE WHEN iac.orderstatus = 2 THEN 1 END ) AS underwritingCount,
  891. COUNT( CASE WHEN iac.orderstatus = 3 THEN 1 END ) AS qutationInsureCount,
  892. COUNT( CASE WHEN iac.orderstatus = 4 THEN 1 END ) AS underwritingReturn,
  893. COUNT( CASE WHEN iac.orderstatus = 2 THEN 1 END ) / COUNT( CASE WHEN iac.orderstatus = 0 THEN 1 END ) AS "passingRate",
  894. COUNT( CASE WHEN iac.orderstatus = 3 THEN 1 END ) / COUNT( CASE WHEN iac.orderstatus = 0 THEN 1 END ) AS "closeRate",
  895. COUNT( CASE WHEN iac.orderstatus = 3 THEN 1 END ) / COUNT( CASE WHEN iac.orderstatus = 2 THEN 1 END ) AS "contributionRate",
  896. COUNT( CASE WHEN iac.orderstatus = 0 THEN 1 END ) / COUNT( iac.orderstatus ) AS "quotationRate",
  897. COUNT( CASE WHEN ifa.auditstatus = '0' THEN 1 END ) AS "auditOrder"
  898. FROM
  899. ins_area_company iac
  900. LEFT JOIN ins_orders io ON io.orderno = iac.orderno
  901. LEFT JOIN sys_dept sd ON sd.id = io.deptid
  902. LEFT JOIN ins_fee_audit ifa ON ifa.ins_order_no = iac.id
  903. <where>
  904. sd.management_source = '1'
  905. <if test="taskStatisticsVo.provinceId != null and taskStatisticsVo.provinceId != ''">
  906. and io.deptid like "${taskStatisticsVo.provinceId}%"
  907. </if>
  908. <if test="taskStatisticsVo.cityId != null and taskStatisticsVo.cityId != ''">
  909. and io.deptid like "${taskStatisticsVo.cityId}%"
  910. </if>
  911. <if test="taskStatisticsVo.countyId != null and taskStatisticsVo.countyId != ''">
  912. and io.deptid like "${taskStatisticsVo.countyId}%"
  913. </if>
  914. <if test="taskStatisticsVo.houseId != null and taskStatisticsVo.houseId != ''">
  915. and io.deptid like "${taskStatisticsVo.houseId}%"
  916. </if>
  917. <if test="taskStatisticsVo.createtimeStart !=null and taskStatisticsVo.createtimeStart != '' and taskStatisticsVo.createtimeEnd !=null and taskStatisticsVo.createtimeEnd != ''">
  918. AND DATE_FORMAT( io.createtime, '%Y-%m-%d') BETWEEN #{taskStatisticsVo.createtimeStart} AND #{taskStatisticsVo.createtimeEnd}
  919. </if>
  920. <if test="taskStatisticsVo.days !=null and taskStatisticsVo.days !='' ">
  921. <choose>
  922. <when test="taskStatisticsVo.days =='1'">
  923. and io.createtime >= DATE_SUB(NOW(), INTERVAL 1 DAY)
  924. </when>
  925. <when test="taskStatisticsVo.days =='7'">
  926. and io.createtime >= DATE_SUB(NOW(), INTERVAL 7 DAY)
  927. </when>
  928. <when test="taskStatisticsVo.days =='30'">
  929. and io.createtime >= DATE_SUB(NOW(), INTERVAL 30 DAY)
  930. </when>
  931. </choose>
  932. </if>
  933. </where>
  934. GROUP BY
  935. io.userid,
  936. sd.NAME
  937. ) a
  938. </select>
  939. <select id="queryPageTaskStatisticsTotal" resultType="java.lang.Long">
  940. select count(0) from (
  941. SELECT
  942. io.userid
  943. FROM
  944. ins_area_company iac
  945. LEFT JOIN ins_orders io ON io.orderno = iac.orderno
  946. LEFT JOIN sys_dept sd ON sd.id = io.deptid
  947. <where>
  948. sd.management_source = '1'
  949. <if test="taskStatisticsVo.provinceId != null and taskStatisticsVo.provinceId != ''">
  950. and io.deptid like "${taskStatisticsVo.provinceId}%"
  951. </if>
  952. <if test="taskStatisticsVo.cityId != null and taskStatisticsVo.cityId != ''">
  953. and io.deptid like "${taskStatisticsVo.cityId}%"
  954. </if>
  955. <if test="taskStatisticsVo.countyId != null and taskStatisticsVo.countyId != ''">
  956. and io.deptid like "${taskStatisticsVo.countyId}%"
  957. </if>
  958. <if test="taskStatisticsVo.houseId != null and taskStatisticsVo.houseId != ''">
  959. and io.deptid like "${taskStatisticsVo.houseId}%"
  960. </if>
  961. <if test="taskStatisticsVo.createtimeStart !=null and taskStatisticsVo.createtimeStart != '' and taskStatisticsVo.createtimeEnd !=null and taskStatisticsVo.createtimeEnd != ''">
  962. AND DATE_FORMAT( io.createtime, '%Y-%m-%d') BETWEEN #{taskStatisticsVo.createtimeStart} AND
  963. #{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. io.userid
  981. ) a
  982. </select>
  983. <select id="insuranceCompanyQueryPage" resultType="com.ydtech.modules.admin.model.dto.TaskStatisticsDto">
  984. SELECT
  985. a.*,
  986. ( SELECT eic.namesimple FROM esm_ins_company eic WHERE eic.id = a.partner_companies_id ) AS "namesimple"
  987. FROM
  988. (
  989. SELECT
  990. pa.insurance_company_id,
  991. pa.partner_companies_id,
  992. pa.insurance_company AS "insuranceCompanyName",
  993. COUNT( CASE WHEN iac.orderstatus = 0 THEN 1 END ) AS qutationCount,
  994. COUNT( CASE WHEN iac.orderstatus = 2 THEN 1 END ) AS underwritingCount,
  995. COUNT( CASE WHEN iac.orderstatus = 3 THEN 1 END ) AS qutationInsureCount,
  996. COUNT( CASE WHEN iac.orderstatus = 4 THEN 1 END ) AS underwritingReturn,
  997. COUNT( CASE WHEN iac.orderstatus = 2 THEN 1 END ) / COUNT( CASE WHEN iac.orderstatus = 0 THEN 1 END ) AS "passingRate",
  998. COUNT( CASE WHEN iac.orderstatus = 3 THEN 1 END ) / COUNT( CASE WHEN iac.orderstatus = 0 THEN 1 END ) AS "closeRate",
  999. COUNT( CASE WHEN iac.orderstatus = 3 THEN 1 END ) / COUNT( CASE WHEN iac.orderstatus = 2 THEN 1 END ) AS "contributionRate",
  1000. COUNT( CASE WHEN iac.orderstatus = 0 THEN 1 END ) / COUNT( iac.orderstatus ) AS "quotationRate",
  1001. COUNT( CASE WHEN ifa.auditstatus = '0' THEN 1 END ) AS "auditOrder"
  1002. FROM
  1003. ins_area_company iac
  1004. LEFT JOIN ins_fee_audit ifa ON ifa.ins_order_no = iac.id
  1005. LEFT JOIN ptl_agreement pa ON pa.id = iac.agreement_id
  1006. <where>
  1007. pa.insurance_company_id IS NOT NULL
  1008. <if test="taskStatisticsVo.provinceId != null and taskStatisticsVo.provinceId != ''">
  1009. and io.deptid like "${taskStatisticsVo.provinceId}%"
  1010. </if>
  1011. <if test="taskStatisticsVo.cityId != null and taskStatisticsVo.cityId != ''">
  1012. and io.deptid like "${taskStatisticsVo.cityId}%"
  1013. </if>
  1014. <if test="taskStatisticsVo.countyId != null and taskStatisticsVo.countyId != ''">
  1015. and io.deptid like "${taskStatisticsVo.countyId}%"
  1016. </if>
  1017. <if test="taskStatisticsVo.houseId != null and taskStatisticsVo.houseId != ''">
  1018. and io.deptid like "${taskStatisticsVo.houseId}%"
  1019. </if>
  1020. <if test="taskStatisticsVo.createtimeStart !=null and taskStatisticsVo.createtimeStart != '' and taskStatisticsVo.createtimeEnd !=null and taskStatisticsVo.createtimeEnd != ''">
  1021. AND DATE_FORMAT( io.createtime, '%Y-%m-%d') BETWEEN #{taskStatisticsVo.createtimeStart} AND #{taskStatisticsVo.createtimeEnd}
  1022. </if>
  1023. <if test="taskStatisticsVo.days !=null and taskStatisticsVo.days !='' ">
  1024. <choose>
  1025. <when test="taskStatisticsVo.days =='1'">
  1026. and io.createtime >= DATE_SUB(NOW(), INTERVAL 1 DAY)
  1027. </when>
  1028. <when test="taskStatisticsVo.days =='7'">
  1029. and io.createtime >= DATE_SUB(NOW(), INTERVAL 7 DAY)
  1030. </when>
  1031. <when test="taskStatisticsVo.days =='30'">
  1032. and io.createtime >= DATE_SUB(NOW(), INTERVAL 30 DAY)
  1033. </when>
  1034. </choose>
  1035. </if>
  1036. </where>
  1037. GROUP BY
  1038. pa.insurance_company_id,
  1039. pa.partner_companies_id,
  1040. pa.insurance_company
  1041. ) a
  1042. </select>
  1043. <select id="insuranceCompanyQueryTotal" resultType="java.lang.Long">
  1044. SELECT
  1045. COUNT(0)
  1046. FROM
  1047. (
  1048. SELECT
  1049. pa.insurance_company_id,
  1050. pa.partner_companies_id
  1051. FROM
  1052. ins_area_company iac
  1053. LEFT JOIN ins_fee_audit ifa ON ifa.ins_order_no = iac.id
  1054. LEFT JOIN ptl_agreement pa ON pa.id = iac.agreement_id
  1055. <where>
  1056. pa.insurance_company_id IS NOT NULL
  1057. <if test="taskStatisticsVo.provinceId != null and taskStatisticsVo.provinceId != ''">
  1058. and io.deptid like "${taskStatisticsVo.provinceId}%"
  1059. </if>
  1060. <if test="taskStatisticsVo.cityId != null and taskStatisticsVo.cityId != ''">
  1061. and io.deptid like "${taskStatisticsVo.cityId}%"
  1062. </if>
  1063. <if test="taskStatisticsVo.countyId != null and taskStatisticsVo.countyId != ''">
  1064. and io.deptid like "${taskStatisticsVo.countyId}%"
  1065. </if>
  1066. <if test="taskStatisticsVo.houseId != null and taskStatisticsVo.houseId != ''">
  1067. and io.deptid like "${taskStatisticsVo.houseId}%"
  1068. </if>
  1069. <if test="taskStatisticsVo.createtimeStart !=null and taskStatisticsVo.createtimeStart != '' and taskStatisticsVo.createtimeEnd !=null and taskStatisticsVo.createtimeEnd != ''">
  1070. AND DATE_FORMAT( io.createtime, '%Y-%m-%d') BETWEEN #{taskStatisticsVo.createtimeStart} AND #{taskStatisticsVo.createtimeEnd}
  1071. </if>
  1072. <if test="taskStatisticsVo.days !=null and taskStatisticsVo.days !='' ">
  1073. <choose>
  1074. <when test="taskStatisticsVo.days =='1'">
  1075. and io.createtime >= DATE_SUB(NOW(), INTERVAL 1 DAY)
  1076. </when>
  1077. <when test="taskStatisticsVo.days =='7'">
  1078. and io.createtime >= DATE_SUB(NOW(), INTERVAL 7 DAY)
  1079. </when>
  1080. <when test="taskStatisticsVo.days =='30'">
  1081. and io.createtime >= DATE_SUB(NOW(), INTERVAL 30 DAY)
  1082. </when>
  1083. </choose>
  1084. </if>
  1085. </where>
  1086. GROUP BY
  1087. pa.insurance_company_id,
  1088. pa.partner_companies_id
  1089. ) total
  1090. </select>
  1091. <select id="agentStatisticsQueryPage" resultType="com.ydtech.modules.admin.model.dto.TaskStatisticsDto">
  1092. SELECT
  1093. sd.name as "deptName",
  1094. su.name as "userName",
  1095. io.userid as "userId",
  1096. COUNT( CASE WHEN iac.orderstatus = 0 THEN 1 END ) AS qutationCount,
  1097. COUNT( CASE WHEN iac.orderstatus = 2 THEN 1 END ) AS underwritingCount,
  1098. COUNT( CASE WHEN iac.orderstatus = 3 THEN 1 END ) AS qutationInsureCount,
  1099. COUNT( CASE WHEN iac.orderstatus = 4 THEN 1 END ) AS underwritingReturn,
  1100. COUNT( CASE WHEN iac.orderstatus = 2 THEN 1 END ) / COUNT( CASE WHEN iac.orderstatus = 0 THEN 1 END ) as "passingRate",
  1101. COUNT( CASE WHEN iac.orderstatus = 3 THEN 1 END ) / COUNT( CASE WHEN iac.orderstatus = 0 THEN 1 END ) as "closeRate",
  1102. COUNT( CASE WHEN iac.orderstatus = 3 THEN 1 END ) / COUNT( CASE WHEN iac.orderstatus = 2 THEN 1 END ) as "contributionRate",
  1103. COUNT( CASE WHEN iac.orderstatus = 0 THEN 1 END ) / COUNT(iac.orderstatus) as "quotationRate",
  1104. COUNT( CASE WHEN ifa.auditstatus = '0' THEN 1 END ) as "auditOrder"
  1105. FROM
  1106. ins_area_company iac
  1107. left join ins_orders io on io.orderno = iac.orderno
  1108. left join sys_dept sd on sd.id=io.deptid
  1109. left join sys_user su on su.id=io.userid
  1110. left join ins_fee_audit ifa on ifa .ins_order_no =iac.id
  1111. <where>
  1112. sd.management_source = '2'
  1113. <if test="taskStatisticsVo.provinceId != null and taskStatisticsVo.provinceId != ''">
  1114. and io.deptid like "${taskStatisticsVo.provinceId}%"
  1115. </if>
  1116. <if test="taskStatisticsVo.cityId != null and taskStatisticsVo.cityId != ''">
  1117. and io.deptid like "${taskStatisticsVo.cityId}%"
  1118. </if>
  1119. <if test="taskStatisticsVo.countyId != null and taskStatisticsVo.countyId != ''">
  1120. and io.deptid like "${taskStatisticsVo.countyId}%"
  1121. </if>
  1122. <if test="taskStatisticsVo.houseId != null and taskStatisticsVo.houseId != ''">
  1123. and io.deptid like "${taskStatisticsVo.houseId}%"
  1124. </if>
  1125. <if test="taskStatisticsVo.createtimeStart !=null and taskStatisticsVo.createtimeStart != '' and taskStatisticsVo.createtimeEnd !=null and taskStatisticsVo.createtimeEnd != ''">
  1126. AND DATE_FORMAT( io.createtime, '%Y-%m-%d') BETWEEN #{taskStatisticsVo.createtimeStart} AND #{taskStatisticsVo.createtimeEnd}
  1127. </if>
  1128. <if test="taskStatisticsVo.days !=null and taskStatisticsVo.days !='' ">
  1129. <choose>
  1130. <when test="taskStatisticsVo.days =='1'">
  1131. and io.createtime >= DATE_SUB(NOW(), INTERVAL 1 DAY)
  1132. </when>
  1133. <when test="taskStatisticsVo.days =='7'">
  1134. and io.createtime >= DATE_SUB(NOW(), INTERVAL 7 DAY)
  1135. </when>
  1136. <when test="taskStatisticsVo.days =='30'">
  1137. and io.createtime >= DATE_SUB(NOW(), INTERVAL 30 DAY)
  1138. </when>
  1139. </choose>
  1140. </if>
  1141. </where>
  1142. GROUP BY io.userid , su.name, sd.id , sd.name
  1143. </select>
  1144. <select id="costCenter" resultType="com.ydtech.modules.admin.model.dto.TaskStatisticsDto">
  1145. SELECT
  1146. iac.company_id,
  1147. iac.inscompany as "insuranceCompanyName",
  1148. COUNT( CASE WHEN ifa.auditstatus = 1 THEN 1 END ) AS "auditstatusOrders",
  1149. COUNT( CASE WHEN ifa.auditstatus = 0 THEN 1 END ) AS "auditOrder",
  1150. COUNT( CASE WHEN pa.audit_type = 1 AND ifa.auditstatus = 1 THEN 1 END ) AS "persionAudit",
  1151. COUNT( CASE WHEN pa.audit_type = 2 AND ifa.auditstatus = 1 THEN 1 END ) AS "automaticAudit"
  1152. FROM
  1153. ins_fee_audit ifa
  1154. LEFT JOIN ins_area_company iac ON iac.id = ifa.ins_order_no
  1155. LEFT JOIN ptl_agreement pa ON pa.id = iac.agreement_id
  1156. LEFT JOIN ins_fee_order_new ion ON ion.ins_order_no = iac.id
  1157. <where>
  1158. 1=1
  1159. <if test="taskStatisticsVo.createtimeStart !=null and taskStatisticsVo.createtimeStart != '' and taskStatisticsVo.createtimeEnd !=null and taskStatisticsVo.createtimeEnd != ''">
  1160. AND DATE_FORMAT( ifa.audittime, '%Y-%m-%d') BETWEEN #{taskStatisticsVo.createtimeStart} AND #{taskStatisticsVo.createtimeEnd}
  1161. </if>
  1162. <if test="taskStatisticsVo.days !=null and taskStatisticsVo.days !='' ">
  1163. <choose>
  1164. <when test="taskStatisticsVo.days =='1'">
  1165. and ifa.audittime >= DATE_SUB(NOW(), INTERVAL 1 DAY)
  1166. </when>
  1167. <when test="taskStatisticsVo.days =='7'">
  1168. and ifa.audittime >= DATE_SUB(NOW(), INTERVAL 7 DAY)
  1169. </when>
  1170. <when test="taskStatisticsVo.days =='30'">
  1171. and ifa.audittime >= DATE_SUB(NOW(), INTERVAL 30 DAY)
  1172. </when>
  1173. </choose>
  1174. </if>
  1175. <if test="taskStatisticsVo.riskCode != null and taskStatisticsVo.riskCode != ''">
  1176. and iac.product = #{taskStatisticsVo.riskCode}
  1177. </if>
  1178. </where>
  1179. GROUP BY
  1180. iac.company_id,
  1181. iac.inscompany
  1182. </select>
  1183. <select id="getOrderManpower" resultType="com.ydtech.modules.admin.model.dto.QxFrontlineAgentDto">
  1184. SELECT
  1185. count( a.numberUserId ) as "orderManpower",
  1186. sum( a.orderAmount ) as "totalPremium",
  1187. sum( a.orderAmount )/ count( a.numberUserId ) as "averagePremium"
  1188. FROM
  1189. (
  1190. SELECT
  1191. count( io.userid ) AS "numberUserId",
  1192. SUM(IFNULL(iac.jqpremium, 0)) +
  1193. SUM(IFNULL(iac.sypremium, 0)) +
  1194. SUM(IFNULL(iac.jypremium, 0)) AS "orderAmount"
  1195. FROM
  1196. `ins_area_company` iac
  1197. LEFT JOIN ins_orders io ON io.orderno = iac.orderno
  1198. <where>
  1199. iac.orderstatus = '3'
  1200. <if test="ids != null and ids.size()>0 ">
  1201. AND io.userid IN
  1202. <foreach item="item" collection="ids" open="(" separator="," close=")">
  1203. #{item}
  1204. </foreach>
  1205. </if>
  1206. </where>
  1207. GROUP BY
  1208. io.userid
  1209. ) a
  1210. </select>
  1211. <select id="getOrderManpowerNew" resultType="com.ydtech.modules.admin.model.dto.QxFrontlineAgentDto">
  1212. SELECT
  1213. count( a.numberUserId ) as "orderManpower",
  1214. sum( a.orderAmount ) as "totalPremium",
  1215. sum( a.orderAmount )/ count( a.numberUserId ) as "averagePremium"
  1216. FROM
  1217. (
  1218. SELECT
  1219. count( io.userid ) AS "numberUserId",
  1220. SUM(IFNULL(iac.jqpremium, 0)) +
  1221. SUM(IFNULL(iac.sypremium, 0)) +
  1222. SUM(IFNULL(iac.jypremium, 0)) AS "orderAmount"
  1223. FROM
  1224. `ins_area_company` iac
  1225. LEFT JOIN ins_orders io ON io.orderno = iac.orderno
  1226. <where>
  1227. iac.orderstatus = '3'
  1228. <if test="vo.ids != null and vo.ids.size()>0 ">
  1229. AND io.userid IN
  1230. <foreach item="item" collection="vo.ids" open="(" separator="," close=")">
  1231. #{item}
  1232. </foreach>
  1233. </if>
  1234. <if test="vo.createtimeStart != null and vo.createtimeStart!='' and vo.createtimeEnd != null and vo.createtimeEnd!=''">
  1235. AND iac.signing_time BETWEEN #{vo.createtimeStart} AND #{vo.createtimeEnd}
  1236. </if>
  1237. </where>
  1238. GROUP BY
  1239. io.userid
  1240. ) a
  1241. </select>
  1242. <select id="NumberQuotations" resultType="com.ydtech.modules.admin.model.dto.TaskStatisticsDto">
  1243. SELECT
  1244. count(iac.id) as "orderNumber",
  1245. COUNT( CASE WHEN iac.orderstatus = 2 THEN 1 END ) AS underwritingCount,
  1246. COUNT( CASE WHEN iac.orderstatus = 3 THEN 1 END ) AS qutationInsureCount,
  1247. sum( CASE WHEN iac.orderstatus = 3 THEN iac.sumpremium END ) AS totalPremium
  1248. FROM
  1249. ins_area_company iac
  1250. left join ins_orders io on io.orderno = iac.orderno
  1251. left join sys_dept sd on sd.id=io.deptid
  1252. left join sys_user su on su.id=io.userid
  1253. left join ins_fee_audit ifa on ifa .ins_order_no =iac.id
  1254. <where>
  1255. sd.management_source = '2'
  1256. <if test="userId !=null and userId !=''">
  1257. and io.userId =#{userId}
  1258. </if>
  1259. </where>
  1260. </select>
  1261. <select id="totalQuotation" resultType="com.ydtech.modules.admin.model.dto.TaskStatisticsDto">
  1262. SELECT
  1263. agree.insurance_company_id AS companyId,
  1264. agree.insurance_company AS companyName,
  1265. agree.partner_companies_id AS parterCompanyId,
  1266. ins.namesimple AS parterCompanyName,
  1267. count(iac.orderstatus) AS orderNumber,
  1268. '-' as bigQutationCount,
  1269. '-' as bigUnderwritingCount,
  1270. '-' as bigCloseRate,
  1271. COUNT( CASE WHEN iac.orderstatus = 2 THEN 1 END ) AS underwritingCount,
  1272. COUNT( CASE WHEN iac.orderstatus = 3 THEN 1 END ) AS qutationInsureCount,
  1273. COUNT( CASE WHEN iac.orderstatus = 0 THEN 1 END )/ count(iac.orderstatus) AS passRate,
  1274. COUNT( CASE WHEN iac.orderstatus = 2 THEN 1 END )/ count(iac.orderstatus) AS underwritingCountRate,
  1275. COUNT( CASE WHEN iac.orderstatus = 3 THEN 1 END )/ count(iac.orderstatus) AS closeRate,
  1276. COUNT( CASE WHEN iac.orderstatus = 3 THEN 1 END )/ COUNT( CASE WHEN iac.orderstatus = 2 THEN 1 END ) AS
  1277. contributionRate
  1278. FROM
  1279. ins_area_company iac
  1280. LEFT JOIN ptl_agreement agree ON iac.agreement_id = agree.id
  1281. LEFT JOIN ins_orders io on io.orderno = iac.orderno
  1282. LEFT JOIN esm_ins_company ins ON agree.partner_companies_id = ins.id
  1283. WHERE
  1284. agree.id IS NOT NULL
  1285. <if test="vo.companyId != null and vo.companyId!='' ">
  1286. agree.insurance_company_id = #{vo.companyId}
  1287. </if>
  1288. <if test="vo.parterCompanyId != null and vo.parterCompanyId!='' ">
  1289. agree.partner_companies_id = #{vo.parterCompanyId}
  1290. </if>
  1291. <if test="vo.beginDate != null and vo.beginDate!='' and vo.endDate != null and vo.endDate!=''">
  1292. AND iac.createtime BETWEEN #{vo.beginDate} AND #{vo.endDate}
  1293. </if>
  1294. <if test="vo.provinceId != null and vo.provinceId != ''">
  1295. and io.deptid like "${vo.provinceId}%"
  1296. </if>
  1297. <if test="vo.cityId != null and vo.cityId != ''">
  1298. and io.deptid like "${vo.cityId}%"
  1299. </if>
  1300. <if test="vo.countyId != null and vo.countyId != ''">
  1301. and io.deptid like "${vo.countyId}%"
  1302. </if>
  1303. <if test="taskStatisticsVo.houseId != null and vo.houseId != ''">
  1304. and io.deptid like "${vo.houseId}%"
  1305. </if>
  1306. GROUP BY
  1307. agree.insurance_company_id,
  1308. agree.insurance_company,
  1309. agree.partner_companies_id,
  1310. ins.NAME
  1311. </select>
  1312. <select id="getBusinessData" resultType="com.ydtech.modules.admin.model.dto.TaskStatisticsDto">
  1313. select
  1314. a.companyId as "companyId",
  1315. a.insuranceCompanyName as "insuranceCompanyName",
  1316. a.parterCompanyId as "parterCompanyId",
  1317. a.partnerCompaniesName as "partnerCompaniesName",
  1318. a.totalPremium as "totalPremium",
  1319. a.qutationInsureCount as "qutationInsureCount",
  1320. a.averagePremium as "averagePremium",
  1321. a.userNumber as "userNumber",
  1322. a.perCapitaAmount as "perCapitaAmount",
  1323. b.logo as "logo"
  1324. from (
  1325. SELECT
  1326. agree.insurance_company_id AS "companyId",
  1327. agree.insurance_company AS "insuranceCompanyName",
  1328. agree.partner_companies_id AS "parterCompanyId",
  1329. ins.namesimple AS "partnerCompaniesName",
  1330. sum(iac.sumpremium) as "totalPremium",
  1331. COUNT(0 ) AS "qutationInsureCount",
  1332. sum(iac.sumpremium) / COUNT(0 ) AS "averagePremium",
  1333. COUNT(DISTINCT io.userId) AS "userNumber",
  1334. sum(iac.sumpremium) / COUNT(DISTINCT io.userId) as "perCapitaAmount"
  1335. FROM
  1336. ins_area_company iac
  1337. LEFT JOIN ptl_agreement agree ON iac.agreement_id = agree.id
  1338. LEFT JOIN ins_orders io on io.orderno = iac.orderno
  1339. LEFT JOIN esm_ins_company ins ON agree.partner_companies_id = ins.id
  1340. WHERE
  1341. agree.id IS NOT NULL
  1342. and iac.orderstatus = '3'
  1343. <if test="vo.companyId != null and vo.companyId!='' ">
  1344. and agree.insurance_company_id = #{vo.companyId}
  1345. </if>
  1346. <if test="vo.parterCompanyId != null and vo.parterCompanyId!='' ">
  1347. and agree.partner_companies_id = #{vo.parterCompanyId}
  1348. </if>
  1349. <if test="vo.createtimeStart != null and vo.createtimeStart!='' and vo.createtimeEnd != null and vo.createtimeEnd!=''">
  1350. AND iac.signing_time BETWEEN #{vo.createtimeStart} AND #{vo.createtimeStart}
  1351. </if>
  1352. <if test="vo.provinceId != null and vo.provinceId != ''">
  1353. and io.deptid like "${vo.provinceId}%"
  1354. </if>
  1355. <if test="vo.cityId != null and vo.cityId != ''">
  1356. and io.deptid like "${vo.cityId}%"
  1357. </if>
  1358. <if test="vo.countyId != null and vo.countyId != ''">
  1359. and io.deptid like "${vo.countyId}%"
  1360. </if>
  1361. <if test="vo.houseId != null and vo.houseId != ''">
  1362. and io.deptid like "${vo.houseId}%"
  1363. </if>
  1364. GROUP BY
  1365. agree.insurance_company_id,
  1366. agree.insurance_company,
  1367. agree.partner_companies_id
  1368. <choose>
  1369. <when test="vo.orderSort != null and vo.orderSort != '' and vo.userNumberSort == null ">
  1370. order by
  1371. sum(sumpremium) ${vo.orderSort == 'asc' ? 'asc' : 'desc'}
  1372. </when>
  1373. <when test="vo.userNumberSort != null and vo.userNumberSort != '' and vo.orderSort == null ">
  1374. order by
  1375. COUNT(DISTINCT io.userId) ${vo.userNumberSort == 'asc' ? 'asc' : 'desc'}
  1376. </when>
  1377. <when test="vo.userNumberSort != null and vo.userNumberSort != '' and vo.orderSort != null and vo.orderSort != '' ">
  1378. order by
  1379. COUNT(DISTINCT io.userId) ${vo.userNumberSort == 'asc' ? 'asc' : 'desc'}, sum(sumpremium) ${vo.orderSort == 'asc' ? 'asc' : 'desc'}
  1380. </when>
  1381. </choose>
  1382. ) a
  1383. left join esm_ins_company b on b.id =a.companyId
  1384. </select>
  1385. <select id="getDistribution" resultType="com.ydtech.modules.admin.model.dto.TaskStatisticsDto">
  1386. SELECT
  1387. agree.insurance_company_id AS "companyId",
  1388. agree.insurance_company AS "insuranceCompanyName",
  1389. agree.partner_companies_id AS "parterCompanyId",
  1390. ins.namesimple AS "partnerCompaniesName",
  1391. sum(sumpremium) as "totalPremium",
  1392. COUNT(0) AS "qutationInsureCount",
  1393. sum(sumpremium) / COUNT(0) AS "averagePremium",
  1394. COUNT(DISTINCT io.userId) AS "userNumber",
  1395. sum(sumpremium) / COUNT(DISTINCT io.userId) as "perCapitaAmount"
  1396. FROM
  1397. ins_area_company iac
  1398. LEFT JOIN ptl_agreement agree ON iac.agreement_id = agree.id
  1399. LEFT JOIN ins_orders io on io.orderno = iac.orderno
  1400. LEFT JOIN esm_ins_company ins ON agree.partner_companies_id = ins.id
  1401. WHERE
  1402. agree.id IS NOT NULL
  1403. <if test="vo.companyId != null and vo.companyId!='' ">
  1404. and agree.insurance_company_id = #{vo.companyId}
  1405. </if>
  1406. <if test="vo.parterCompanyId != null and vo.parterCompanyId!='' ">
  1407. and agree.partner_companies_id = #{vo.parterCompanyId}
  1408. </if>
  1409. <if test="vo.createtimeStart != null and vo.createtimeStart!='' and vo.createtimeEnd != null and vo.createtimeEnd!=''">
  1410. AND iac.signing_time BETWEEN #{vo.createtimeStart} AND #{vo.createtimeStart}
  1411. </if>
  1412. <if test="vo.provinceId != null and vo.provinceId != ''">
  1413. and io.deptid like "${vo.provinceId}%"
  1414. </if>
  1415. <if test="vo.cityId != null and vo.cityId != ''">
  1416. and io.deptid like "${vo.cityId}%"
  1417. </if>
  1418. <if test="vo.countyId != null and vo.countyId != ''">
  1419. and io.deptid like "${vo.countyId}%"
  1420. </if>
  1421. <if test="vo.houseId != null and vo.houseId != ''">
  1422. and io.deptid like "${vo.houseId}%"
  1423. </if>
  1424. <if test="vo.quotationStatus != null and vo.quotationStatus != ''">
  1425. and iac.orderstatus =#{vo.quotationStatus}
  1426. </if>
  1427. GROUP BY
  1428. agree.insurance_company_id,
  1429. agree.insurance_company,
  1430. agree.partner_companies_id,
  1431. ins.namesimple
  1432. </select>
  1433. </mapper>