InsAreaCompanyMapper.xml 116 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613
  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. JSON_UNQUOTE(json_extract(io.insureinfo, '$.name')) as 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. CASE ifa.audituser
  166. WHEN '自动审核' THEN '2'
  167. ELSE '1' END
  168. AS checkType,
  169. ifa.audittime as auditTime,
  170. ifa.auditstatus as auditStatus,
  171. eic.namesimple as partnerCompaniesName,
  172. iac.id as subOrderId,
  173. iac.signing_time as signingTime,
  174. iac.pay_date as payDate,
  175. pa.agreement_code as agreementCode,
  176. pa.agreement_name as agreementName,
  177. pa.business_description as businessDescription,
  178. pa.job_description as jobDescription,
  179. pa.agreement_title as agreementTitle,
  180. pa.docking_person as dockingPerson,
  181. io.entry_status
  182. FROM
  183. ins_fee_audit ifa
  184. LEFT JOIN ins_orders io ON io.orderno = ifa.orderno
  185. LEFT JOIN ins_area_company iac ON iac.orderno = io.orderno
  186. AND iac.orderstatus = 3
  187. LEFT JOIN sys_user su ON su.id = io.userid
  188. LEFT JOIN sys_dept sd ON sd.id = su.dept_id
  189. LEFT JOIN sys_user su2 ON ifa.audituser = su2.id
  190. LEFT JOIN ptl_agreement pa ON pa.id = iac.agreement_id
  191. LEFT JOIN esm_ins_company eic ON eic.id = pa.partner_companies_id
  192. WHERE
  193. iac.id = ifa.ins_order_no
  194. AND iac.orderstatus = 3
  195. <if test="params.auditStatus != null and params.auditStatus != ''">
  196. and ifa.auditstatus = #{params.auditStatus}
  197. </if>
  198. <if test="params.quoteStartDateStr != null and params.quoteStartDateStr != '' and params.quoteEndDateStr != null and params.quoteEndDateStr != ''">
  199. and DATE_FORMAT(iac.createtime, '%Y-%m-%d') between #{params.quoteStartDateStr} AND
  200. #{params.quoteEndDateStr}
  201. </if>
  202. <if test="params.orderNo != null and params.orderNo != ''">
  203. AND iac.id= #{params.orderNo}
  204. </if>
  205. <if test="params.licenseNo != null and params.licenseNo != ''">
  206. AND io.licenseno = #{params.licenseNo}
  207. </if>
  208. <if test="params.frameNo != null and params.frameNo != ''">
  209. AND io.frameno = #{params.frameNo}
  210. </if>
  211. <if test="params.insuredName != null and params.insuredName != ''">
  212. AND json_extract(io.insureinfo, '$.name') = #{params.insuredName}
  213. </if>
  214. <if test="params.companyId != null and params.companyId != ''">
  215. AND io.company_id = #{params.companyId}
  216. </if>
  217. <if test="params.engineNo != null and params.engineNo != ''">
  218. and JSON_EXTRACT( io.carinfo, '$.engineNo' ) = #{params.engineNo}
  219. </if>
  220. <if test="params.riskCode != null and params.riskCode != ''">
  221. and iac.product = #{params.riskCode}
  222. </if>
  223. <if test="params.attachStartDateStr != null and params.attachStartDateStr != '' and params.attachStartDateStr != null and params.attachStartDateStr != '' ">
  224. and ((
  225. DATE_FORMAT(iac.jq_start_date, '%Y-%m-%d') BETWEEN #{params.attachStartDateStr}
  226. AND #{params.attachEndDateStr}
  227. )
  228. OR ( DATE_FORMAT(iac.sy_start_date, '%Y-%m-%d') BETWEEN #{params.attachStartDateStr} AND
  229. #{params.attachEndDateStr} )
  230. )
  231. </if>
  232. <if test="params.provinceId != null and params.provinceId != ''">
  233. and io.deptid like "${params.provinceId}%"
  234. </if>
  235. <if test="params.problemOrder != null and params.problemOrder != ''">
  236. and iac.problem_order like "${params.problemOrder}%"
  237. </if>
  238. <if test="params.cityId != null and params.cityId != ''">
  239. and io.deptid like "${params.cityId}%"
  240. </if>
  241. <if test="params.countyId != null and params.countyId != ''">
  242. and io.deptid like "${params.countyId}%"
  243. </if>
  244. <if test="params.houseId != null and params.houseId != ''">
  245. and io.deptid like "${params.houseId}%"
  246. </if>
  247. <if test="params.operatorId != null and params.operatorId != ''">
  248. and io.userid = #{params.operatorId}
  249. </if>
  250. <if test="params.operatorName != null and params.operatorName != ''">
  251. and io.username = #{params.operatorName}
  252. </if>
  253. <if test="params.auditId != null and params.auditId != ''">
  254. and iac.new_operator_id = #{params.auditId}
  255. </if>
  256. <if test="params.agreeId != null and params.agreeId != ''">
  257. and iac.agreement_id = #{params.agreeId}
  258. </if>
  259. <if test="params.managementSource != null and params.managementSource != ''">
  260. and sd.management_source = #{params.managementSource}
  261. </if>
  262. <if test="params.signStartDateStr != null and params.signStartDateStr != '' and params.signEndDateStr != null and params.signEndDateStr != ''">
  263. and DATE_FORMAT(iac.signing_time, '%Y-%m-%d') between #{params.signStartDateStr} AND
  264. #{params.signEndDateStr}
  265. </if>
  266. <if test="params.payStartDateStr != null and params.payStartDateStr != '' and params.payEndDateStr != null and params.payEndDateStr != ''">
  267. and iac.pay_date between #{params.payStartDateStr} AND #{params.payEndDateStr}
  268. </if>
  269. <if test="params.isExternal != null and params.isExternal != ''">
  270. and io.is_external = #{params.isExternal}
  271. </if>
  272. <if test="params.jqPolicyNo != null and params.jqPolicyNo != ''">
  273. and iac.jqpolicyno = #{params.jqPolicyNo}
  274. </if>
  275. <if test="params.syPolicyNo != null and params.syPolicyNo != ''">
  276. and iac.sypolicyno = #{params.syPolicyNo}
  277. </if>
  278. <if test="params.noPolicyNo != null and params.noPolicyNo != ''">
  279. and iac.cross_insurance like concat('%', #{params.noPolicyNo}, '%')
  280. </if>
  281. <if test="params.checkUser != null and params.checkUser != ''">
  282. and CASE ifa.audituser WHEN '自动审核' THEN ifa.audituser
  283. ELSE su2.name END = #{params.checkUser}
  284. </if>
  285. <if test="params.checkType != null and params.checkType != ''">
  286. and CASE ifa.audituser
  287. WHEN '自动审核' THEN '2'
  288. ELSE '1' END = #{params.checkType}
  289. </if>
  290. order by iac.createtime desc
  291. </select>
  292. <select id="getByUserId" resultType="com.ydtech.modules.order.entity.InsOrders">
  293. SELECT
  294. io.*,
  295. sd.management_source
  296. FROM
  297. ins_orders io left join sys_user su on su.id = io.userid left join sys_dept sd on sd.id = su.dept_id
  298. WHERE
  299. orderno IN (
  300. SELECT
  301. orderno
  302. FROM
  303. ins_area_company
  304. WHERE
  305. id IN ( SELECT ins_order_no FROM ins_fee_order_new WHERE id NOT IN ( SELECT ins_order_no FROM ins_fee_audit ) )
  306. AND orderstatus = 3
  307. )
  308. AND
  309. io.orderstatus= 3
  310. <if test="orderNo != null and orderNo != ''">
  311. AND orderno = #{orderNo}
  312. </if>
  313. <if test="licenseNo != null and licenseNo != ''">
  314. AND licenseno = #{licenseNo}
  315. </if>
  316. <if test="frameNo != null and frameNo != ''">
  317. AND frameno = #{frameNo}
  318. </if>
  319. <if test="userId != null and userId != ''">
  320. AND userid = #{userId}
  321. </if>
  322. <if test="insuredname != null and insuredname != ''">
  323. AND insuredname = #{insuredname}
  324. </if>
  325. <if test="startDateStr != null and startDateStr != ''">
  326. AND createtime BETWEEN #{startDateStr} and #{endDateStr}
  327. </if>
  328. </select>
  329. <select id="selectFirstPromotionBy" resultType="com.ydtech.modules.order.entity.InsOrders">
  330. SELECT
  331. sum(a.first_detail_premiums) as "willFirstPremiums"
  332. FROM
  333. ins_fee_order_new a
  334. LEFT JOIN ins_area_company iac on iac.id=a.ins_order_no
  335. left join ins_fee_audit iff on a.ins_order_no=iff.ins_order_no
  336. WHERE
  337. iff.auditstatus=0
  338. AND iac.orderstatus =3
  339. <if test="firstUserId != null and firstUserId != ''">
  340. AND a.first_level_user_id = #{firstUserId}
  341. </if>
  342. <if test="secondUserId != null and secondUserId != ''">
  343. AND a.two_level_user_id = #{secondUserId}
  344. </if>
  345. <if test="thirdUserId != null and thirdUserId != ''">
  346. AND a.three_level_user_id = #{thirdUserId}
  347. </if>
  348. <if test="id != null and id != ''">
  349. AND a.id = #{id}
  350. </if>
  351. </select>
  352. <select id="selectSecondPromotionBy" resultType="com.ydtech.modules.order.entity.InsOrders">
  353. SELECT
  354. sum( fee.p ) as "willFirstPremiums"
  355. FROM
  356. (
  357. SELECT
  358. sum( a.first_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.first_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.third_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.three_level_user_id = #{userId}
  385. </if>
  386. <if test="id != null and id!=''">
  387. AND a.id =#{id}
  388. </if>
  389. </where>
  390. UNION
  391. SELECT
  392. sum( a.second_detail_premiums ) AS p
  393. FROM
  394. ins_fee_order_new a
  395. LEFT JOIN ins_area_company iac ON iac.id = a.ins_order_no
  396. left join ins_fee_audit iff on a.ins_order_no=iff.ins_order_no
  397. <where>
  398. iff.auditstatus=0
  399. and iac.orderstatus = '3'
  400. <if test="userId!=null and userId!= ''">
  401. AND a.two_level_user_id = #{userId}
  402. </if>
  403. <if test="id != null and id!=''">
  404. AND a.id =#{id}
  405. </if>
  406. </where>
  407. ) AS fee
  408. </select>
  409. <select id="selectThirdPromotionBy" resultType="com.ydtech.modules.order.entity.InsOrders">
  410. SELECT
  411. sum(a.third_detail_premiums) as "willThreePremiums"
  412. FROM
  413. ins_fee_order_new a
  414. LEFT JOIN ins_area_company iac on iac.id=a.ins_order_no
  415. left join ins_fee_audit iff on a.ins_order_no=iff.ins_order_no
  416. WHERE
  417. iff.auditstatus=0
  418. AND iac.orderstatus =3
  419. <if test="firstUserId != null and firstUserId != ''">
  420. AND a.first_level_user_id = #{firstUserId}
  421. </if>
  422. <if test="secondUserId != null and secondUserId != ''">
  423. AND a.two_level_user_id = #{secondUserId}
  424. </if>
  425. <if test="thirdUserId != null and thirdUserId != ''">
  426. AND a.three_level_user_id = #{thirdUserId}
  427. </if>
  428. <if test="id != null and id != ''">
  429. AND a.id = #{id}
  430. </if>
  431. </select>
  432. <select id="getAlreadyAuditOrders" resultType="com.ydtech.modules.order.entity.InsOrders">
  433. SELECT
  434. io.*,
  435. sd.management_source,
  436. su2.name AS auditUser,
  437. ifa.audittime as auditTime
  438. FROM
  439. ins_orders io
  440. LEFT JOIN ins_fee_audit ifa ON ifa.orderno = io.orderno
  441. LEFT JOIN sys_user su ON su.id = io.userid
  442. LEFT JOIN sys_dept sd ON sd.id = su.dept_id
  443. LEFT JOIN sys_user su2 on ifa.audituser = su2.id
  444. WHERE
  445. io.orderno IN (
  446. SELECT
  447. orderno
  448. FROM
  449. ins_area_company
  450. WHERE
  451. id IN (
  452. SELECT
  453. ifon.ins_order_no
  454. FROM
  455. ins_fee_order_new ifon
  456. RIGHT JOIN ins_fee_audit ifa ON ifon.ins_order_no = ifa.ins_order_no
  457. WHERE
  458. ifa.auditstatus = #{params.auditStatus}
  459. )
  460. )
  461. AND orderstatus = 3
  462. <!-- <if test="params.orderNo != null and params.orderNo != ''">-->
  463. <!-- AND orderno = #{params.orderNo}-->
  464. <!-- </if>-->
  465. <if test="params.licenseNo != null and params.licenseNo != ''">
  466. AND licenseno = #{params.licenseNo}
  467. </if>
  468. <if test="params.frameNo != null and params.frameNo != ''">
  469. AND frameno = #{params.frameNo}
  470. </if>
  471. <if test="params.insuredName != null and params.insuredName != ''">
  472. AND insuredname = #{params.insuredName}
  473. </if>
  474. <if test="params.companyId != null and params.companyId != ''">
  475. AND company_id = #{params.companyId}
  476. </if>
  477. <if test="params.startDateStr != null and params.startDateStr != ''">
  478. AND createtime BETWEEN #{params.startDateStr} and #{params.endDateStr}
  479. </if>
  480. </select>
  481. <select id="selectListByDateStr" resultType="com.ydtech.modules.order.entity.InsAreaCompany">
  482. -- 查询订单信息
  483. SELECT
  484. iac.*
  485. FROM
  486. ins_area_company iac
  487. left JOIN ins_orders AS io ON io.orderno = iac.orderno
  488. WHERE
  489. 1=1
  490. <if test="dateStr != null and dateStr != ''">
  491. AND DATE_FORMAT(io.createtime, '%Y-%m') =#{dateStr}
  492. </if>
  493. </select>
  494. <select id="selectListById" resultMap="BaseResultMap">
  495. SELECT
  496. iac.*
  497. FROM
  498. ins_area_company iac
  499. WHERE
  500. 1=1
  501. <if test="id != null and id != ''">
  502. AND iac.id =#{id}
  503. </if>
  504. </select>
  505. <select id="selectSecondPromotionByNew" resultType="com.ydtech.modules.order.entity.InsOrders">
  506. SELECT
  507. sum( fee.p ) as "willFirstPremiums"
  508. FROM
  509. (
  510. SELECT
  511. sum( a.first_detail_premiums ) AS p
  512. FROM
  513. ins_fee_order_new a
  514. LEFT JOIN ins_area_company iac ON iac.id = a.ins_order_no
  515. left join ins_fee_audit iff on a.ins_order_no=iff.ins_order_no
  516. <where>
  517. <choose>
  518. <when test='type == "1"'>
  519. iff.auditstatus=0
  520. </when>
  521. <otherwise>
  522. iff.auditstatus=1
  523. </otherwise>
  524. </choose>
  525. and iac.orderstatus = '3'
  526. <if test="userId!=null and userId!= ''">
  527. AND a.first_level_user_id = #{userId}
  528. </if>
  529. <if test="id != null and id!=''">
  530. AND a.id =#{id}
  531. </if>
  532. </where>
  533. UNION
  534. SELECT
  535. sum( a.third_detail_premiums ) AS p
  536. FROM
  537. ins_fee_order_new a
  538. LEFT JOIN ins_area_company iac ON iac.id = a.ins_order_no
  539. left join ins_fee_audit iff on a.ins_order_no=iff.ins_order_no
  540. <where>
  541. <choose>
  542. <when test='type == "1"'>
  543. iff.auditstatus=0
  544. </when>
  545. <otherwise>
  546. iff.auditstatus=1
  547. </otherwise>
  548. </choose>
  549. and iac.orderstatus = '3'
  550. <if test="userId!=null and userId!= ''">
  551. AND a.three_level_user_id = #{userId}
  552. </if>
  553. <if test="id != null and id!=''">
  554. AND a.id =#{id}
  555. </if>
  556. </where>
  557. UNION
  558. SELECT
  559. sum( a.second_detail_premiums ) AS p
  560. FROM
  561. ins_fee_order_new a
  562. LEFT JOIN ins_area_company iac ON iac.id = a.ins_order_no
  563. left join ins_fee_audit iff on a.ins_order_no=iff.ins_order_no
  564. <where>
  565. <choose>
  566. <when test='type == "1"'>
  567. iff.auditstatus=0
  568. </when>
  569. <otherwise>
  570. iff.auditstatus=1
  571. </otherwise>
  572. </choose>
  573. and iac.orderstatus = '3'
  574. <if test="userId!=null and userId!= ''">
  575. AND a.two_level_user_id = #{userId}
  576. </if>
  577. <if test="id != null and id!=''">
  578. AND a.id =#{id}
  579. </if>
  580. </where>
  581. ) AS fee
  582. </select>
  583. <select id="getSubOrderDetails" resultType="com.ydtech.modules.admin.model.vo.SubOrder">
  584. SELECT
  585. iac.id as subOrderId,
  586. iac.signing_time as signingTime,
  587. iac.jqpremium as jqpremium,
  588. iac.sypremium as sypremium,
  589. iac.jypremium as jypremium,
  590. io.licenseno as licenseno,
  591. io.userid as userId
  592. FROM
  593. ins_area_company iac
  594. LEFT JOIN ins_orders AS io ON io.orderno = iac.orderno
  595. WHERE
  596. iac.id=#{subOrderId}
  597. </select>
  598. <select id="premiumReportYear" resultType="com.ydtech.modules.admin.model.dto.PremiumReportDto">
  599. SELECT
  600. CONCAT(YEAR(iac.createtime),'-',LPAD(MONTH(iac.createtime), 2, '0')) reportDate,
  601. sum(jqpremium) jqpremium,
  602. sum(sypremium) sypremium,
  603. sum(sumpremium) sumpremium
  604. FROM
  605. ins_area_company iac left join ins_orders io on iac.orderno=io.orderno
  606. WHERE
  607. iac.orderstatus = 3 and
  608. iac.createtime &gt;= #{beginTime} and iac.createtime &lt;= #{endTime}
  609. and io.userid=#{userId}
  610. GROUP BY CONCAT(YEAR(iac.createtime),'-',LPAD(MONTH(iac.createtime), 2, '0'))
  611. </select>
  612. <select id="premiumReportMonth" resultType="com.ydtech.modules.admin.model.dto.PremiumReportDto">
  613. SELECT
  614. CONCAT(YEAR(iac.createtime),'-',LPAD(MONTH(iac.createtime), 2, '0'),'-',LPAD(Day(iac.createtime), 2, '0')) reportDate,
  615. sum(jqpremium) jqpremium,
  616. sum(sypremium) sypremium,
  617. sum(sumpremium) sumpremium
  618. FROM
  619. ins_area_company iac left join ins_orders io on iac.orderno=io.orderno
  620. WHERE
  621. iac.orderstatus = 3 and
  622. iac.createtime &gt;= #{beginTime} and iac.createtime &lt;= #{endTime}
  623. and io.userid=#{userId}
  624. GROUP BY CONCAT(YEAR(iac.createtime),'-',LPAD(MONTH(iac.createtime), 2, '0'),'-',LPAD(Day(iac.createtime), 2, '0'))
  625. </select>
  626. <select id="premiumReportDay" resultType="com.ydtech.modules.admin.model.dto.PremiumReportDto">
  627. SELECT
  628. CONCAT(YEAR ( iac.createtime ),'-',LPAD( MONTH ( iac.createtime ), 2, '0' ),'-',LPAD( DAY ( iac.createtime ), 2, '0' ),' ',LPAD( HOUR ( iac.createtime ), 2, '0' ))
  629. reportDate,
  630. sum( jqpremium ) jqpremium,
  631. sum( sypremium ) sypremium,
  632. sum( sumpremium ) sumpremium
  633. FROM
  634. ins_area_company iac left join ins_orders io on iac.orderno=io.orderno
  635. WHERE
  636. iac.orderstatus = 3 and
  637. iac.createtime &gt;= #{beginTime} and iac.createtime &lt;= #{endTime}
  638. and io.userid=#{userId}
  639. GROUP BY CONCAT(YEAR ( iac.createtime ),'-',LPAD( MONTH ( iac.createtime ), 2, '0' ),'-',LPAD( DAY ( iac.createtime ), 2, '0' ),' ',LPAD( HOUR ( iac.createtime ), 2, '0' ))
  640. </select>
  641. <select id="getAllpremium" resultType="com.ydtech.modules.admin.model.dto.AllpremiumDto">
  642. SELECT
  643. ifnull(sum( iac.jqpremium + iac.sypremium + iac.jypremium ),0) as sumPremium,
  644. count( 0 ) as sumCount
  645. FROM
  646. ins_area_company iac left join ins_orders io on iac.orderno=io.orderno
  647. WHERE
  648. iac.orderstatus = 3
  649. and io.userid=#{userId}
  650. AND YEAR (iac.createtime) = #{year}
  651. </select>
  652. <select id="getRejectOrder" resultType="com.ydtech.modules.order.entity.InsAreaCompany">
  653. select
  654. iac.id,
  655. iac.orderno,
  656. iac.agreement_id,
  657. iac.jqpremium,
  658. iac.sypremium,
  659. iac.jypremium,
  660. iac.taxamount,
  661. iac.sumpremium,
  662. io.licenseno,
  663. ifa.audittime,
  664. ifa.audituser as auditname,
  665. ifa.rejectinfo,
  666. "1" as orderExternalStatus
  667. FROM
  668. ins_fee_audit ifa
  669. LEFT JOIN
  670. ins_area_company iac on iac.id = ifa.ins_order_no
  671. LEFT JOIN
  672. ins_orders io on iac.orderno = io.orderno
  673. left join
  674. sys_user su on su.id= ifa.audituser
  675. WHERE
  676. iac.operator_id = #{userId}
  677. AND
  678. ifa.auditstatus = 2 and IFNULL(iac.del_flag,'') != '0'
  679. <if test="vo.id != null and vo.id!=''">
  680. and iac.id = #{vo.id}
  681. </if>
  682. <if test="vo.licenseno != null and vo.licenseno!='' ">
  683. and io.licenseno like CONCAT('%', #{vo.licenseno}, '%')
  684. </if>
  685. <if test="vo.auditname != null and vo.auditname!='' ">
  686. and su.name like CONCAT('%', #{vo.auditname}, '%')
  687. </if>
  688. </select>
  689. <select id="queryBusinessDataPage"
  690. resultType="com.ydtech.modules.admin.model.report.opetationData.BusinessDataDto">
  691. SELECT
  692. <if test="flag != null and flag!='' and flag='1'">
  693. o.userid as userId,
  694. o.username as userName,
  695. </if>
  696. sum( iac.sumpremium ) as signeSumPremiumAmount,
  697. sum( iac.jqpremium ) as jqPremiumAmount,
  698. sum( iac.sypremium ) as syPremiumAmount,
  699. sum( iac.taxamount ) as taxAmount,
  700. sum( ion.no_premium ) as fcFeeAmount
  701. FROM
  702. ins_area_company iac
  703. LEFT JOIN ins_orders o ON iac.orderno = o.orderno
  704. LEFT JOIN ins_fee_order_new ion ON iac.id = ion.ins_order_no
  705. where iac.orderstatus = 3 and ion.id is not null
  706. <if test="userList != null and userList.size()>0 ">
  707. and o.userid IN
  708. <foreach item="item" collection="userList" open="(" separator="," close=")">
  709. #{item}
  710. </foreach>
  711. </if>
  712. <if test="flag != null and flag!='' and flag='1'">
  713. group by o.userid,o.username
  714. </if>
  715. </select>
  716. <select id="queryQuotationSubOrderCountDataPage"
  717. resultType="com.ydtech.modules.admin.model.report.opetationData.QuotationCountDataDto">
  718. SELECT
  719. <if test="flag != null and flag!='' and flag='1'">
  720. o.userid as userId,
  721. o.username as userName,
  722. </if>
  723. iac.orderstatus as orderStatus
  724. FROM
  725. ins_area_company iac
  726. LEFT JOIN ins_orders o ON iac.orderno = o.orderno
  727. where (iac.orderstatus = 0 or iac.orderstatus = 2 or iac.orderstatus = 3 )
  728. <if test="userList != null and userList.size()>0 ">
  729. and o.userid IN
  730. <foreach item="item" collection="userList" open="(" separator="," close=")">
  731. #{item}
  732. </foreach>
  733. </if>
  734. <if test="flag != null and flag!='' and flag='1'">
  735. group by o.userid,o.username,iac.orderstatus
  736. </if>
  737. </select>
  738. <select id="queryQuotationOrderCountDataPage"
  739. resultType="com.ydtech.modules.admin.model.report.opetationData.QuotationCountDataDto">
  740. SELECT
  741. a.userId as userId,
  742. a.userName as userName,
  743. b.qutationCount AS insOrderQutationCount,
  744. b.qutationInsureCount as insOrderQutationInsureCount,
  745. b.closeRate AS insOrderCloseRate as insOrderCloseRate,
  746. a.qutationCount as subOrderQutationCount,
  747. a.underwritingCount as subOrderUnderwritingCount,
  748. a.qutationInsureCount as subOrderQutationInsureCount,
  749. a.passRate as subOrderCloseRate,
  750. a.closeRate as subOrderPassRate,
  751. a.contributionRate as subOrderContributionRate
  752. FROM
  753. (
  754. SELECT
  755. inso.userid AS userId,
  756. inso.username AS userName,
  757. COUNT( CASE WHEN iac.orderstatus = 0 THEN 1 END ) AS qutationCount,
  758. COUNT( CASE WHEN iac.orderstatus = 2 THEN 1 END ) AS underwritingCount,
  759. COUNT( CASE WHEN iac.orderstatus = 3 THEN 1 END ) AS qutationInsureCount,
  760. COUNT( CASE WHEN iac.orderstatus = 0 THEN 1 END )/ count( iac.orderstatus ) AS passRate,
  761. COUNT( CASE WHEN iac.orderstatus = 3 THEN 1 END )/ count( iac.orderstatus ) AS closeRate,
  762. COUNT( CASE WHEN iac.orderstatus = 3 THEN 1 END )/ COUNT( CASE WHEN iac.orderstatus = 2 THEN 1 END ) AS contributionRate
  763. FROM
  764. ins_area_company iac
  765. LEFT JOIN ins_orders inso ON iac.orderno = inso.orderno
  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. ) a
  778. LEFT JOIN (
  779. SELECT
  780. inso.userid AS userId,
  781. inso.username AS userName,
  782. count( inso.orderstatus ) AS qutationCount,
  783. count( CASE WHEN inso.orderstatus = 3 THEN 1 END ) AS qutationInsureCount,
  784. COUNT( CASE WHEN inso.orderstatus = 3 THEN 1 END )/ count( inso.orderstatus ) AS closeRate
  785. FROM
  786. ins_orders inso
  787. <where>
  788. <if test="userList != null and userList.size()>0 ">
  789. and o.userid IN
  790. <foreach item="item" collection="userList" open="(" separator="," close=")">
  791. #{item}
  792. </foreach>
  793. </if>
  794. </where>
  795. GROUP BY
  796. inso.userid,
  797. inso.username
  798. ) b ON a.userId = b.userId
  799. </select>
  800. <select id="queryCompanyPremiumDataPage"
  801. resultType="com.ydtech.modules.admin.model.report.company.CompanyPremiumDataDto">
  802. SELECT
  803. agree.insurance_company_id AS companyId,
  804. agree.insurance_company AS companyName,
  805. agree.partner_companies_id AS parterCompanyId,
  806. ins.NAME AS parterCompanyName,
  807. sum( iac.sumpremium ) AS signeSumPremiumAmount
  808. FROM
  809. ins_area_company iac
  810. LEFT JOIN ptl_agreement agree ON iac.agreement_id = agree.id
  811. LEFT JOIN esm_ins_company ins ON agree.partner_companies_id = ins.id
  812. WHERE
  813. iac.orderstatus = 3
  814. and
  815. agree.id is not null
  816. <if test="vo.companyId != null and vo.companyId!='' ">
  817. agree.insurance_company_id = #{vo.companyId}
  818. </if>
  819. <if test="vo.parterCompanyId != null and vo.parterCompanyId!='' ">
  820. agree.insurance_company_id = #{vo.parterCompanyId}
  821. </if>
  822. GROUP BY
  823. agree.insurance_company_id,
  824. agree.insurance_company,
  825. agree.partner_companies_id,
  826. ins.NAME
  827. </select>
  828. <select id="queryCompanyQutationCountDataPage"
  829. resultType="com.ydtech.modules.admin.model.report.company.CompanyQutationCountDataDto">
  830. SELECT
  831. a.* ,
  832. (select ins.namesimple from esm_ins_company
  833. ins where a.parterCompanyId = ins.id) as "parterCompanyName"
  834. FROM
  835. (
  836. SELECT
  837. count(agree.partner_companies_id) as "orderSuccessNumber",
  838. agree.insurance_company AS companyName,
  839. agree.partner_companies_id AS parterCompanyId,
  840. iac.company_id as "companyId",
  841. count( iac.orderstatus ) AS qutationCount,
  842. count( iac.id ) AS orderSuccessNumberRate,
  843. COUNT( CASE WHEN iac.orderstatus = 2 THEN 1 END ) + COUNT( CASE WHEN iac.orderstatus = 3 THEN 1 END ) AS underwritingCount,
  844. COUNT( CASE WHEN iac.orderstatus = 3 THEN 1 END ) AS qutationInsureCount,
  845. (COUNT( CASE WHEN iac.orderstatus = 2 THEN 1 END ) + COUNT( CASE WHEN iac.orderstatus = 3 THEN 1 END )) / count( iac.orderstatus ) AS passRate,
  846. COUNT( CASE WHEN iac.orderstatus = 3 THEN 1 END ) / (COUNT( CASE WHEN iac.orderstatus = 2 THEN 1 END ) + COUNT( CASE WHEN iac.orderstatus = 3 THEN 1 END )) AS closeRate,
  847. COUNT( CASE WHEN iac.orderstatus = 3 THEN 1 END )/ count( iac.orderstatus ) AS contributionRate,
  848. COUNT(CASE WHEN agree.audit_type =1 and ifa.auditstatus =1 and iac.orderstatus =3 THEN 1 END) as "numberManual"
  849. FROM
  850. ins_area_company iac
  851. LEFT JOIN ptl_agreement agree ON iac.agreement_id = agree.id
  852. LEFT JOIN ins_orders io ON iac.orderno = io.orderno
  853. LEFT JOIN sys_dept sd ON sd.id = io.deptid
  854. LEFT JOIN ins_fee_audit ifa on ifa.ins_order_no =iac.id
  855. WHERE
  856. agree.id IS NOT NULL
  857. <if test="vo.companyId != null and vo.companyId!='' ">
  858. AND agree.insurance_company_id = #{vo.companyId}
  859. </if>
  860. <if test="vo.parterCompanyId != null and vo.parterCompanyId!='' ">
  861. AND agree.partner_companies_id = #{vo.parterCompanyId}
  862. </if>
  863. <if test="vo.beginDate != null and vo.beginDate!='' and vo.endDate != null and vo.endDate!=''">
  864. AND iac.createtime BETWEEN #{vo.beginDate} AND #{vo.endDate}
  865. </if>
  866. <if test="vo.managementSource != null and vo.managementSource!=''">
  867. AND sd.management_source =#{vo.managementSource}
  868. </if>
  869. <if test="vo.userId != null and vo.userId !=''">
  870. AND io.userid =#{vo.userId}
  871. </if>
  872. <if test="vo.deptId != null and vo.deptId !=''">
  873. AND io.deptId like concat('%',#{vo.deptId},'%')
  874. </if>
  875. <if test="vo.deptIds != null and vo.deptIds != '' and vo.deptIds.size() > 0">
  876. AND sd.id in
  877. <foreach collection="vo.deptIds" item="item" open="(" separator="," close=")">
  878. #{item}
  879. </foreach>
  880. </if>
  881. <if test="vo.userIds != null and vo.userIds != '' and vo.userIds.size() > 0">
  882. AND io.userid in
  883. <foreach collection="taskStatisticsVo.userIds" item="item" open="(" separator="," close=")">
  884. #{item}
  885. </foreach>
  886. </if>
  887. GROUP BY
  888. agree.insurance_company,
  889. iac.company_id,
  890. agree.partner_companies_id
  891. ) a
  892. order by a.parterCompanyId
  893. </select>
  894. <select id="getInsAreaCompanyError"
  895. resultType="com.ydtech.modules.admin.model.report.company.CompanyQutationCountDataDto">
  896. SELECT
  897. count(iace.id) as "areaCompanyErrNumber"
  898. FROM
  899. ins_area_company_error iace
  900. LEFT JOIN ptl_agreement agree ON iace.agreement_id = agree.id
  901. <where>
  902. 1=1
  903. <if test="vo.companyId != null and vo.companyId!='' ">
  904. AND agree.insurance_company_id = #{vo.companyId}
  905. </if>
  906. <if test="vo.parterCompanyId != null and vo.parterCompanyId!='' ">
  907. AND agree.partner_companies_id = #{vo.parterCompanyId}
  908. </if>
  909. <if test="vo.userId != null and vo.userId!=''">
  910. AND iace.user_id =#{vo.userId}
  911. </if>
  912. <if test="vo.beginDate != null and vo.beginDate!='' and vo.endDate != null and vo.endDate!=''">
  913. AND iace.create_time BETWEEN #{vo.beginDate} AND #{vo.endDate}
  914. </if>
  915. <if test="vo.deptIds != null and vo.deptIds != '' and vo.deptIds.size() > 0">
  916. AND iace.dept_id in
  917. <foreach collection="vo.deptIds" item="item" open="(" separator="," close=")">
  918. #{item}
  919. </foreach>
  920. </if>
  921. <if test="vo.userIds != null and vo.userIds != '' and vo.userIds.size() > 0">
  922. AND iace.user_id in
  923. <foreach collection="taskStatisticsVo.userIds" item="item" open="(" separator="," close=")">
  924. #{item}
  925. </foreach>
  926. </if>
  927. </where>
  928. </select>
  929. <select id="queryCompanyQutationCountDataPageTotal"
  930. resultType="java.lang.Long">
  931. SELECT
  932. count(0)
  933. FROM
  934. (
  935. SELECT
  936. agree.partner_companies_id
  937. FROM
  938. ins_area_company iac
  939. LEFT JOIN ptl_agreement agree ON iac.agreement_id = agree.id
  940. LEFT JOIN ins_orders io ON iac.orderno = io.orderno
  941. LEFT JOIN sys_dept sd ON sd.id = io.deptid
  942. WHERE
  943. agree.id IS NOT NULL
  944. <if test="vo.companyId != null and vo.companyId!='' ">
  945. AND agree.insurance_company_id = #{vo.companyId}
  946. </if>
  947. <if test="vo.parterCompanyId != null and vo.parterCompanyId!='' ">
  948. AND agree.partner_companies_id = #{vo.parterCompanyId}
  949. </if>
  950. <if test="vo.beginDate != null and vo.beginDate!='' and vo.endDate != null and vo.endDate!=''">
  951. AND iac.createtime BETWEEN #{vo.beginDate} AND #{vo.endDate}
  952. </if>
  953. <if test="vo.managementSource != null and vo.managementSource!=''">
  954. AND sd.management_source =#{vo.managementSource}
  955. </if>
  956. <if test="vo.userId != null and vo.userId !=''">
  957. AND io.userid =#{vo.userId}
  958. </if>
  959. <if test="vo.deptId != null and vo.deptId !=''">
  960. AND io.deptId like concat('%',#{vo.deptId},'%')
  961. </if>
  962. <if test="vo.deptIds != null and vo.deptIds != '' and vo.deptIds.size() > 0">
  963. AND sd.id in
  964. <foreach collection="vo.deptIds" item="item" open="(" separator="," close=")">
  965. #{item}
  966. </foreach>
  967. </if>
  968. <if test="vo.userIds != null and vo.userIds != '' and vo.userIds.size() > 0">
  969. AND io.userid in
  970. <foreach collection="taskStatisticsVo.userIds" item="item" open="(" separator="," close=")">
  971. #{item}
  972. </foreach>
  973. </if>
  974. GROUP BY
  975. agree.partner_companies_id
  976. ) a
  977. </select>
  978. <select id="getStageOrder" resultType="com.ydtech.modules.order.entity.InsAreaCompany">
  979. select
  980. iac.id,
  981. iac.orderno,
  982. iac.agreement_id,
  983. iac.jqpremium,
  984. iac.sypremium,
  985. iac.jypremium,
  986. iac.taxamount,
  987. iac.sumpremium,
  988. io.licenseno,
  989. iac.createtime,
  990. "0" as orderExternalStatus
  991. FROM
  992. ins_area_company iac
  993. LEFT JOIN
  994. ins_orders io on iac.orderno = io.orderno
  995. left join ptl_agreement agree on iac.agreement_id =agree.id
  996. WHERE
  997. iac.operator_id = #{userId}
  998. AND
  999. iac.orderstatus = 0
  1000. and agree.is_external =1
  1001. <if test="vo.id != null and vo.id!='' ">
  1002. and iac.id = #{vo.id}
  1003. </if>
  1004. <if test="vo.licenseno != null and vo.licenseno!='' ">
  1005. and io.licenseno like CONCAT('%', #{vo.licenseno}, '%')
  1006. </if>
  1007. </select>
  1008. <select id="queryPageTaskStatistics" resultType="com.ydtech.modules.admin.model.dto.TaskStatisticsDto">
  1009. select a.*, su.name as "userName",
  1010. inf.url as "logo",
  1011. sui.sex as "sex",
  1012. su.leader_name as "leaderName"
  1013. from (
  1014. SELECT
  1015. sd.NAME AS "deptName",
  1016. io.userid AS "userId",
  1017. sd.parent_id as "deptId",
  1018. COUNT( CASE WHEN iac.orderstatus = 0 THEN 1 END ) AS qutationCount,
  1019. COUNT( CASE WHEN iac.orderstatus = 2 THEN 1 END ) AS underwritingCount,
  1020. COUNT( CASE WHEN iac.orderstatus = 3 THEN 1 END ) AS qutationInsureCount,
  1021. COUNT( CASE WHEN iac.orderstatus = 4 THEN 1 END ) AS underwritingReturn,
  1022. COUNT( CASE WHEN iac.orderstatus = 2 THEN 1 END ) / COUNT( CASE WHEN iac.orderstatus = 0 THEN 1 END ) AS "passingRate",
  1023. COUNT( CASE WHEN iac.orderstatus = 3 THEN 1 END ) / COUNT( iac.orderstatus ) AS "closeRate",
  1024. (COUNT( CASE WHEN iac.orderstatus = 3 THEN 1 END ) + COUNT( CASE WHEN iac.orderstatus = 2 THEN 1 END ))/ COUNT( iac.orderstatus ) AS "contributionRate",
  1025. COUNT( CASE WHEN iac.orderstatus = 0 THEN 1 END ) / COUNT( iac.orderstatus ) AS "quotationRate",
  1026. COUNT(CASE WHEN io.order_source = 0 and iac.orderstatus = 0 THEN 1 END) as "pcOrderSource",
  1027. COUNT(CASE WHEN io.order_source = 1 and iac.orderstatus = 0 THEN 1 END) as "appOrderSource",
  1028. COUNT( CASE WHEN iac.orderstatus = 1 THEN 1 END ) AS "auditOrder"
  1029. FROM
  1030. ins_area_company iac
  1031. LEFT JOIN ins_orders io ON io.orderno = iac.orderno
  1032. LEFT JOIN sys_dept sd ON sd.id = io.deptid
  1033. <where>
  1034. sd.management_source = '1'
  1035. <if test="taskStatisticsVo.provinceId != null and taskStatisticsVo.provinceId != ''">
  1036. and io.deptid like "${taskStatisticsVo.provinceId}%"
  1037. </if>
  1038. <if test="taskStatisticsVo.cityId != null and taskStatisticsVo.cityId != ''">
  1039. and io.deptid like "${taskStatisticsVo.cityId}%"
  1040. </if>
  1041. <if test="taskStatisticsVo.countyId != null and taskStatisticsVo.countyId != ''">
  1042. and io.deptid like "${taskStatisticsVo.countyId}%"
  1043. </if>
  1044. <if test="taskStatisticsVo.houseId != null and taskStatisticsVo.houseId != ''">
  1045. and io.deptid like "${taskStatisticsVo.houseId}%"
  1046. </if>
  1047. <if test="taskStatisticsVo.userId != null and taskStatisticsVo.userId != ''">
  1048. and io.userid =#{taskStatisticsVo.userId}
  1049. </if>
  1050. <if test="taskStatisticsVo.createtimeStart !=null and taskStatisticsVo.createtimeStart != '' and taskStatisticsVo.createtimeEnd !=null and taskStatisticsVo.createtimeEnd != ''">
  1051. AND DATE_FORMAT( io.createtime, '%Y-%m-%d') BETWEEN #{taskStatisticsVo.createtimeStart} AND #{taskStatisticsVo.createtimeEnd}
  1052. </if>
  1053. <if test="taskStatisticsVo.beginDate !=null and taskStatisticsVo.beginDate != '' and taskStatisticsVo.endDate !=null and taskStatisticsVo.endDate != ''">
  1054. AND DATE_FORMAT( iac.signing_time, '%Y-%m-%d') BETWEEN DATE_FORMAT( #{taskStatisticsVo.beginDate}, '%Y-%m-%d') AND DATE_FORMAT( #{taskStatisticsVo.endDate}, '%Y-%m-%d')
  1055. </if>
  1056. <if test="taskStatisticsVo.days !=null and taskStatisticsVo.days !='' ">
  1057. and iac.createtime >= DATE_SUB(NOW(), INTERVAL #{taskStatisticsVo.days} DAY)
  1058. </if>
  1059. <if test="taskStatisticsVo.deptIds != null and taskStatisticsVo.deptIds != '' and taskStatisticsVo.deptIds.size() > 0">
  1060. AND sd.id in
  1061. <foreach collection="taskStatisticsVo.deptIds" item="item" open="(" separator="," close=")">
  1062. #{item}
  1063. </foreach>
  1064. </if>
  1065. <if test="taskStatisticsVo.userIds != null and taskStatisticsVo.userIds != '' and taskStatisticsVo.userIds.size() > 0">
  1066. AND io.userid in
  1067. <foreach collection="taskStatisticsVo.userIds" item="item" open="(" separator="," close=")">
  1068. #{item}
  1069. </foreach>
  1070. </if>
  1071. <if test="taskStatisticsVo.days !=null and taskStatisticsVo.days !='' ">
  1072. <choose>
  1073. <when test="taskStatisticsVo.days =='1'">
  1074. and io.createtime >= DATE_SUB(NOW(), INTERVAL 1 DAY)
  1075. </when>
  1076. <when test="taskStatisticsVo.days =='7'">
  1077. and io.createtime >= DATE_SUB(NOW(), INTERVAL 7 DAY)
  1078. </when>
  1079. <when test="taskStatisticsVo.days =='30'">
  1080. and io.createtime >= DATE_SUB(NOW(), INTERVAL 30 DAY)
  1081. </when>
  1082. </choose>
  1083. </if>
  1084. </where>
  1085. GROUP BY
  1086. io.userid,
  1087. sd.NAME,
  1088. sd.id
  1089. ) a
  1090. left join sys_user su on su.id =a.userId
  1091. LEFT JOIN ins_upload_files inf on su.head_sculpture =inf.id
  1092. LEFT JOIN sys_user_info sui on sui .id =su.id
  1093. <where>
  1094. <if test='taskStatisticsVo.userName !=null and taskStatisticsVo.userName!="" '>
  1095. and su.name like concat('%',#{taskStatisticsVo.userName},'%')
  1096. </if>
  1097. <if test='taskStatisticsVo.leaderId !=null and taskStatisticsVo.leaderId!="" '>
  1098. and su.leader_id =#{taskStatisticsVo.leaderId}
  1099. </if>
  1100. <if test='taskStatisticsVo.userId !=null and taskStatisticsVo.userId!="" '>
  1101. and su.id =#{taskStatisticsVo.userId}
  1102. </if>
  1103. </where>
  1104. </select>
  1105. <select id="queryPageTaskStatisticsTotal" resultType="java.lang.Long">
  1106. select count(0) from (
  1107. SELECT
  1108. io.userid
  1109. FROM
  1110. ins_area_company iac
  1111. LEFT JOIN ins_orders io ON io.orderno = iac.orderno
  1112. LEFT JOIN sys_dept sd ON sd.id = io.deptid
  1113. <where>
  1114. sd.management_source = '1'
  1115. <if test="taskStatisticsVo.provinceId != null and taskStatisticsVo.provinceId != ''">
  1116. and io.deptid like "${taskStatisticsVo.provinceId}%"
  1117. </if>
  1118. <if test="taskStatisticsVo.cityId != null and taskStatisticsVo.cityId != ''">
  1119. and io.deptid like "${taskStatisticsVo.cityId}%"
  1120. </if>
  1121. <if test="taskStatisticsVo.countyId != null and taskStatisticsVo.countyId != ''">
  1122. and io.deptid like "${taskStatisticsVo.countyId}%"
  1123. </if>
  1124. <if test="taskStatisticsVo.houseId != null and taskStatisticsVo.houseId != ''">
  1125. and io.deptid like "${taskStatisticsVo.houseId}%"
  1126. </if>
  1127. <if test="taskStatisticsVo.createtimeStart !=null and taskStatisticsVo.createtimeStart != '' and taskStatisticsVo.createtimeEnd !=null and taskStatisticsVo.createtimeEnd != ''">
  1128. AND DATE_FORMAT( io.createtime, '%Y-%m-%d') BETWEEN #{taskStatisticsVo.createtimeStart} AND #{taskStatisticsVo.createtimeEnd}
  1129. </if>
  1130. <if test="taskStatisticsVo.beginDate !=null and taskStatisticsVo.beginDate != '' and taskStatisticsVo.endDate !=null and taskStatisticsVo.endDate != ''">
  1131. AND DATE_FORMAT( iac.signing_time, '%Y-%m-%d') BETWEEN DATE_FORMAT( #{taskStatisticsVo.beginDate}, '%Y-%m-%d') AND DATE_FORMAT( #{taskStatisticsVo.endDate}, '%Y-%m-%d')
  1132. </if>
  1133. <if test="taskStatisticsVo.days !=null and taskStatisticsVo.days !='' ">
  1134. and iac.createtime >= DATE_SUB(NOW(), INTERVAL #{taskStatisticsVo.days} DAY)
  1135. </if>
  1136. <if test="taskStatisticsVo.userId != null and taskStatisticsVo.userId != ''">
  1137. and io.userid =#{taskStatisticsVo.userId}
  1138. </if>
  1139. <if test="taskStatisticsVo.deptIds != null and taskStatisticsVo.deptIds != '' and taskStatisticsVo.deptIds.size() > 0">
  1140. AND sd.id in
  1141. <foreach collection="taskStatisticsVo.deptIds" item="item" open="(" separator="," close=")">
  1142. #{item}
  1143. </foreach>
  1144. </if>
  1145. <if test="taskStatisticsVo.userIds != null and taskStatisticsVo.userIds != '' and taskStatisticsVo.userIds.size() > 0">
  1146. AND io.userid in
  1147. <foreach collection="taskStatisticsVo.userIds" item="item" open="(" separator="," close=")">
  1148. #{item}
  1149. </foreach>
  1150. </if>
  1151. <if test="taskStatisticsVo.days !=null and taskStatisticsVo.days !='' ">
  1152. <choose>
  1153. <when test="taskStatisticsVo.days =='1'">
  1154. and io.createtime >= DATE_SUB(NOW(), INTERVAL 1 DAY)
  1155. </when>
  1156. <when test="taskStatisticsVo.days =='7'">
  1157. and io.createtime >= DATE_SUB(NOW(), INTERVAL 7 DAY)
  1158. </when>
  1159. <when test="taskStatisticsVo.days =='30'">
  1160. and io.createtime >= DATE_SUB(NOW(), INTERVAL 30 DAY)
  1161. </when>
  1162. </choose>
  1163. </if>
  1164. </where>
  1165. GROUP BY
  1166. io.userid
  1167. ) a
  1168. </select>
  1169. <select id="insuranceCompanyQueryPage" resultType="com.ydtech.modules.admin.model.dto.TaskStatisticsDto">
  1170. SELECT
  1171. a.*,
  1172. ( SELECT eic.namesimple FROM esm_ins_company eic WHERE eic.id = a.partner_companies_id ) AS "partnerCompaniesName"
  1173. FROM
  1174. (
  1175. SELECT
  1176. pa.insurance_company_id,
  1177. pa.partner_companies_id,
  1178. pa.insurance_company AS "insuranceCompanyName",
  1179. COUNT( CASE WHEN iac.orderstatus = 0 THEN 1 END ) AS qutationCount,
  1180. COUNT( CASE WHEN iac.orderstatus = 2 THEN 1 END ) AS underwritingCount,
  1181. COUNT( CASE WHEN iac.orderstatus = 3 THEN 1 END ) AS qutationInsureCount,
  1182. COUNT( CASE WHEN iac.orderstatus = 4 THEN 1 END ) AS underwritingReturn,
  1183. COUNT( CASE WHEN iac.orderstatus = 2 THEN 1 END ) / COUNT( CASE WHEN iac.orderstatus = 0 THEN 1 END ) AS "passingRate",
  1184. COUNT( CASE WHEN iac.orderstatus = 3 THEN 1 END ) / COUNT( CASE WHEN iac.orderstatus = 0 THEN 1 END ) AS "closeRate",
  1185. COUNT( CASE WHEN iac.orderstatus = 3 THEN 1 END ) / COUNT( iac.orderstatus ) AS "contributionRate",
  1186. COUNT( CASE WHEN iac.orderstatus = 0 THEN 1 END ) / COUNT( iac.orderstatus ) AS "quotationRate",
  1187. COUNT( CASE WHEN iac.orderstatus = 1 THEN 1 END ) AS "auditOrder"
  1188. FROM
  1189. ins_area_company iac
  1190. LEFT JOIN ins_fee_audit ifa ON ifa.ins_order_no = iac.id
  1191. LEFT JOIN ptl_agreement pa ON pa.id = iac.agreement_id
  1192. LEFT JOIN ins_orders io ON io.orderno = iac.orderno
  1193. <where>
  1194. pa.insurance_company_id IS NOT NULL
  1195. <if test="taskStatisticsVo.provinceId != null and taskStatisticsVo.provinceId != ''">
  1196. and io.deptid like concat('%', #{taskStatisticsVo.provinceId}, '%')
  1197. </if>
  1198. <if test="taskStatisticsVo.cityId != null and taskStatisticsVo.cityId != ''">
  1199. and io.deptid like concat('%', #{taskStatisticsVo.cityId}, '%')
  1200. </if>
  1201. <if test="taskStatisticsVo.countyId != null and taskStatisticsVo.countyId != ''">
  1202. and io.deptid like concat('%', #{taskStatisticsVo.countyId}, '%')
  1203. </if>
  1204. <if test="taskStatisticsVo.houseId != null and taskStatisticsVo.houseId != ''">
  1205. and io.deptid like concat('%', #{taskStatisticsVo.houseId}, '%')
  1206. </if>
  1207. <if test="taskStatisticsVo.createtimeStart !=null and taskStatisticsVo.createtimeStart != '' and taskStatisticsVo.createtimeEnd !=null and taskStatisticsVo.createtimeEnd != ''">
  1208. AND DATE_FORMAT( io.createtime, '%Y-%m-%d') BETWEEN #{taskStatisticsVo.createtimeStart} AND #{taskStatisticsVo.createtimeEnd}
  1209. </if>
  1210. <if test="taskStatisticsVo.beginDate !=null and taskStatisticsVo.beginDate != '' and taskStatisticsVo.endDate !=null and taskStatisticsVo.endDate != ''">
  1211. AND DATE_FORMAT( iac.signing_time, '%Y-%m-%d') BETWEEN DATE_FORMAT( #{taskStatisticsVo.beginDate}, '%Y-%m-%d') AND DATE_FORMAT( #{taskStatisticsVo.endDate}, '%Y-%m-%d')
  1212. </if>
  1213. <if test="taskStatisticsVo.companyId !=null and taskStatisticsVo.companyId != ''">
  1214. AND iac.company_id =#{taskStatisticsVo.companyId}
  1215. </if>
  1216. <if test="taskStatisticsVo.days !=null and taskStatisticsVo.days !='' ">
  1217. and iac.createtime >= DATE_SUB(NOW(), INTERVAL #{taskStatisticsVo.days} DAY)
  1218. </if>
  1219. <if test="taskStatisticsVo.deptIds != null and taskStatisticsVo.deptIds != '' and taskStatisticsVo.deptIds.size() > 0">
  1220. AND io.deptid in
  1221. <foreach collection="taskStatisticsVo.deptIds" item="item" open="(" separator="," close=")">
  1222. #{item}
  1223. </foreach>
  1224. </if>
  1225. <if test="taskStatisticsVo.userIds != null and taskStatisticsVo.userIds != '' and taskStatisticsVo.userIds.size() > 0">
  1226. AND io.userid in
  1227. <foreach collection="taskStatisticsVo.userIds" item="item" open="(" separator="," close=")">
  1228. #{item}
  1229. </foreach>
  1230. </if>
  1231. </where>
  1232. GROUP BY
  1233. pa.insurance_company_id,
  1234. pa.partner_companies_id,
  1235. pa.insurance_company
  1236. ) a
  1237. </select>
  1238. <select id="insuranceCompanyQueryTotal" resultType="java.lang.Long">
  1239. SELECT
  1240. COUNT(0)
  1241. FROM
  1242. (
  1243. SELECT
  1244. pa.insurance_company_id,
  1245. pa.partner_companies_id
  1246. FROM
  1247. ins_area_company iac
  1248. LEFT JOIN ins_fee_audit ifa ON ifa.ins_order_no = iac.id
  1249. LEFT JOIN ptl_agreement pa ON pa.id = iac.agreement_id
  1250. LEFT JOIN ins_orders io ON io.orderno = iac.orderno
  1251. <where>
  1252. pa.insurance_company_id IS NOT NULL
  1253. <if test="taskStatisticsVo.provinceId != null and taskStatisticsVo.provinceId != ''">
  1254. and io.deptid like concat('%', #{taskStatisticsVo.provinceId}, '%')
  1255. </if>
  1256. <if test="taskStatisticsVo.cityId != null and taskStatisticsVo.cityId != ''">
  1257. and io.deptid like concat('%', #{taskStatisticsVo.cityId}, '%')
  1258. </if>
  1259. <if test="taskStatisticsVo.countyId != null and taskStatisticsVo.countyId != ''">
  1260. and io.deptid like concat('%', #{taskStatisticsVo.countyId}, '%')
  1261. </if>
  1262. <if test="taskStatisticsVo.houseId != null and taskStatisticsVo.houseId != ''">
  1263. and io.deptid like concat('%', #{taskStatisticsVo.houseId}, '%')
  1264. </if>
  1265. <if test="taskStatisticsVo.createtimeStart !=null and taskStatisticsVo.createtimeStart != '' and taskStatisticsVo.createtimeEnd !=null and taskStatisticsVo.createtimeEnd != ''">
  1266. AND io.createtime BETWEEN #{taskStatisticsVo.createtimeStart} AND #{taskStatisticsVo.createtimeEnd}
  1267. </if>
  1268. <if test="taskStatisticsVo.beginDate !=null and taskStatisticsVo.beginDate != '' and taskStatisticsVo.endDate !=null and taskStatisticsVo.endDate != ''">
  1269. AND iac.signing_time BETWEEN #{taskStatisticsVo.beginDate} AND #{taskStatisticsVo.endDate}
  1270. </if>
  1271. <if test="taskStatisticsVo.days !=null and taskStatisticsVo.days !='' ">
  1272. and iac.createtime >= DATE_SUB(NOW(), INTERVAL #{taskStatisticsVo.days} DAY)
  1273. </if>
  1274. <if test="taskStatisticsVo.deptIds != null and taskStatisticsVo.deptIds != '' and taskStatisticsVo.deptIds.size() > 0">
  1275. AND io.deptid in
  1276. <foreach collection="taskStatisticsVo.deptIds" item="item" open="(" separator="," close=")">
  1277. #{item}
  1278. </foreach>
  1279. </if>
  1280. <if test="taskStatisticsVo.userIds != null and taskStatisticsVo.userIds != '' and taskStatisticsVo.userIds.size() > 0">
  1281. AND io.userid in
  1282. <foreach collection="taskStatisticsVo.userIds" item="item" open="(" separator="," close=")">
  1283. #{item}
  1284. </foreach>
  1285. </if>
  1286. </where>
  1287. GROUP BY
  1288. pa.insurance_company_id,
  1289. pa.partner_companies_id
  1290. ) total
  1291. </select>
  1292. <select id="agentStatisticsQueryPage" resultType="com.ydtech.modules.admin.model.dto.TaskStatisticsDto">
  1293. SELECT
  1294. sd.name as "deptName",
  1295. su.name as "userName",
  1296. io.userid as "userId",
  1297. sd.id as "deptId",
  1298. suLeader.name as "leaderName",
  1299. COUNT( CASE WHEN iac.orderstatus = 0 THEN 1 END ) AS qutationCount,
  1300. COUNT( CASE WHEN iac.orderstatus = 2 THEN 1 END ) AS underwritingCount,
  1301. COUNT( CASE WHEN iac.orderstatus = 3 THEN 1 END ) AS qutationInsureCount,
  1302. COUNT( CASE WHEN iac.orderstatus = 4 THEN 1 END ) AS underwritingReturn,
  1303. (COUNT( CASE WHEN iac.orderstatus = 2 THEN 1 END ) +COUNT( CASE WHEN iac.orderstatus = 3 THEN 1 END )) / COUNT(iac.orderstatus) as "passingRate",
  1304. COUNT( CASE WHEN iac.orderstatus = 3 THEN 1 END ) / COUNT( CASE WHEN iac.orderstatus = 0 THEN 1 END ) as "closeRate",
  1305. COUNT( CASE WHEN iac.orderstatus = 3 THEN 1 END ) / COUNT(iac.orderstatus) as "contributionRate",
  1306. COUNT( CASE WHEN iac.orderstatus = 0 THEN 1 END ) / COUNT(iac.orderstatus) as "quotationRate",
  1307. COUNT( CASE WHEN iac.orderstatus = 1 THEN 1 END ) as "auditOrder"
  1308. FROM
  1309. ins_area_company iac
  1310. left join ins_orders io on io.orderno = iac.orderno
  1311. left join sys_dept sd on sd.id=io.deptid
  1312. left join sys_user su on su.id=io.userid
  1313. left join sys_user suLeader on suLeader.id =su.leader_id
  1314. <where>
  1315. sd.management_source = '2'
  1316. <if test="taskStatisticsVo.provinceId != null and taskStatisticsVo.provinceId != ''">
  1317. and io.deptid like "${taskStatisticsVo.provinceId}%"
  1318. </if>
  1319. <if test="taskStatisticsVo.cityId != null and taskStatisticsVo.cityId != ''">
  1320. and io.deptid like "${taskStatisticsVo.cityId}%"
  1321. </if>
  1322. <if test="taskStatisticsVo.countyId != null and taskStatisticsVo.countyId != ''">
  1323. and io.deptid like "${taskStatisticsVo.countyId}%"
  1324. </if>
  1325. <if test="taskStatisticsVo.houseId != null and taskStatisticsVo.houseId != ''">
  1326. and io.deptid like "${taskStatisticsVo.houseId}%"
  1327. </if>
  1328. <if test="taskStatisticsVo.userId !=null and taskStatisticsVo.userId!='' ">
  1329. and io.userid =#{taskStatisticsVo.userId}
  1330. </if>
  1331. <if test='taskStatisticsVo.userName !=null and taskStatisticsVo.userName!="" '>
  1332. and su.name like concat('%',#{taskStatisticsVo.userName},'%')
  1333. </if>
  1334. <if test='taskStatisticsVo.leaderId !=null and taskStatisticsVo.leaderId!="" '>
  1335. and su.leader_id =#{taskStatisticsVo.leaderId}
  1336. </if>
  1337. <if test='taskStatisticsVo.userId !=null and taskStatisticsVo.userId!="" '>
  1338. and su.id =#{taskStatisticsVo.userId}
  1339. </if>
  1340. <if test="taskStatisticsVo.createtimeStart !=null and taskStatisticsVo.createtimeStart != '' and taskStatisticsVo.createtimeEnd !=null and taskStatisticsVo.createtimeEnd != ''">
  1341. AND DATE_FORMAT( io.createtime, '%Y-%m-%d') BETWEEN #{taskStatisticsVo.createtimeStart} AND #{taskStatisticsVo.createtimeEnd}
  1342. </if>
  1343. <if test="taskStatisticsVo.beginDate !=null and taskStatisticsVo.beginDate != '' and taskStatisticsVo.endDate !=null and taskStatisticsVo.endDate != ''">
  1344. AND DATE_FORMAT( iac.signing_time, '%Y-%m-%d') BETWEEN DATE_FORMAT( #{taskStatisticsVo.beginDate}, '%Y-%m-%d') AND DATE_FORMAT( #{taskStatisticsVo.endDate}, '%Y-%m-%d')
  1345. </if>
  1346. <if test="taskStatisticsVo.days !=null and taskStatisticsVo.days !='' ">
  1347. and iac.createtime >= DATE_SUB(NOW(), INTERVAL #{taskStatisticsVo.days} DAY)
  1348. </if>
  1349. <if test="taskStatisticsVo.deptIds != null and taskStatisticsVo.deptIds != '' and taskStatisticsVo.deptIds.size() > 0">
  1350. AND sd.id in
  1351. <foreach collection="taskStatisticsVo.deptIds" item="item" open="(" separator="," close=")">
  1352. #{item}
  1353. </foreach>
  1354. </if>
  1355. <if test="taskStatisticsVo.userIds != null and taskStatisticsVo.userIds != '' and taskStatisticsVo.userIds.size() > 0">
  1356. AND io.userid in
  1357. <foreach collection="taskStatisticsVo.userIds" item="item" open="(" separator="," close=")">
  1358. #{item}
  1359. </foreach>
  1360. </if>
  1361. <if test="taskStatisticsVo.days !=null and taskStatisticsVo.days !='' ">
  1362. <choose>
  1363. <when test="taskStatisticsVo.days =='1'">
  1364. and io.createtime >= DATE_SUB(NOW(), INTERVAL 1 DAY)
  1365. </when>
  1366. <when test="taskStatisticsVo.days =='7'">
  1367. and io.createtime >= DATE_SUB(NOW(), INTERVAL 7 DAY)
  1368. </when>
  1369. <when test="taskStatisticsVo.days =='30'">
  1370. and io.createtime >= DATE_SUB(NOW(), INTERVAL 30 DAY)
  1371. </when>
  1372. </choose>
  1373. </if>
  1374. </where>
  1375. GROUP BY io.userid , su.name, sd.id , sd.name
  1376. </select>
  1377. <select id="agentStatisticsQueryPageTotal" resultType="java.lang.Long">
  1378. select count(0) from (
  1379. SELECT
  1380. io.userid as "userId"
  1381. FROM
  1382. ins_area_company iac
  1383. left join ins_orders io on io.orderno = iac.orderno
  1384. left join sys_dept sd on sd.id=io.deptid
  1385. left join sys_user su on su.id=io.userid
  1386. <where>
  1387. sd.management_source = '2'
  1388. <if test="taskStatisticsVo.provinceId != null and taskStatisticsVo.provinceId != ''">
  1389. and io.deptid like "${taskStatisticsVo.provinceId}%"
  1390. </if>
  1391. <if test="taskStatisticsVo.cityId != null and taskStatisticsVo.cityId != ''">
  1392. and io.deptid like "${taskStatisticsVo.cityId}%"
  1393. </if>
  1394. <if test="taskStatisticsVo.countyId != null and taskStatisticsVo.countyId != ''">
  1395. and io.deptid like "${taskStatisticsVo.countyId}%"
  1396. </if>
  1397. <if test="taskStatisticsVo.houseId != null and taskStatisticsVo.houseId != ''">
  1398. and io.deptid like "${taskStatisticsVo.houseId}%"
  1399. </if>
  1400. <if test='taskStatisticsVo.userName !=null and taskStatisticsVo.userName!="" '>
  1401. and su.name like concat('%',#{taskStatisticsVo.userName},'%')
  1402. </if>
  1403. <if test='taskStatisticsVo.leaderId !=null and taskStatisticsVo.leaderId!="" '>
  1404. and su.leader_id =#{taskStatisticsVo.leaderId}
  1405. </if>
  1406. <if test='taskStatisticsVo.userId !=null and taskStatisticsVo.userId!="" '>
  1407. and su.id =#{taskStatisticsVo.userId}
  1408. </if>
  1409. <if test="taskStatisticsVo.createtimeStart !=null and taskStatisticsVo.createtimeStart != '' and taskStatisticsVo.createtimeEnd !=null and taskStatisticsVo.createtimeEnd != ''">
  1410. AND DATE_FORMAT( io.createtime, '%Y-%m-%d') BETWEEN #{taskStatisticsVo.createtimeStart} AND #{taskStatisticsVo.createtimeEnd}
  1411. </if>
  1412. <if test="taskStatisticsVo.beginDate !=null and taskStatisticsVo.beginDate != '' and taskStatisticsVo.endDate !=null and taskStatisticsVo.endDate != ''">
  1413. AND DATE_FORMAT( iac.signing_time, '%Y-%m-%d') BETWEEN DATE_FORMAT( #{taskStatisticsVo.beginDate}, '%Y-%m-%d') AND DATE_FORMAT( #{taskStatisticsVo.endDate}, '%Y-%m-%d')
  1414. </if>
  1415. <if test="taskStatisticsVo.userId !=null and taskStatisticsVo.userId!='' ">
  1416. and io.userid =#{taskStatisticsVo.userId}
  1417. </if>
  1418. <if test="taskStatisticsVo.days !=null and taskStatisticsVo.days !='' ">
  1419. and iac.createtime >= DATE_SUB(NOW(), INTERVAL #{taskStatisticsVo.days} DAY)
  1420. </if>
  1421. <if test="taskStatisticsVo.days !=null and taskStatisticsVo.days !='' ">
  1422. <choose>
  1423. <when test="taskStatisticsVo.days =='1'">
  1424. and io.createtime >= DATE_SUB(NOW(), INTERVAL 1 DAY)
  1425. </when>
  1426. <when test="taskStatisticsVo.days =='7'">
  1427. and io.createtime >= DATE_SUB(NOW(), INTERVAL 7 DAY)
  1428. </when>
  1429. <when test="taskStatisticsVo.days =='30'">
  1430. and io.createtime >= DATE_SUB(NOW(), INTERVAL 30 DAY)
  1431. </when>
  1432. </choose>
  1433. </if>
  1434. </where>
  1435. GROUP BY io.userid
  1436. ) a
  1437. </select>
  1438. <select id="costCenter" resultType="com.ydtech.modules.admin.model.dto.TaskStatisticsDto">
  1439. SELECT
  1440. iac.company_id,
  1441. iac.inscompany as "insuranceCompanyName",
  1442. COUNT( CASE WHEN ifa.auditstatus = 1 THEN 1 END ) AS "auditstatusOrders",
  1443. COUNT( CASE WHEN ifa.auditstatus = 0 THEN 1 END ) AS "auditOrder",
  1444. COUNT( CASE WHEN ifa.auditstatus = 1 and ifa.audituser != '自动审核' THEN 1 END ) AS "persionAudit",
  1445. COUNT( CASE WHEN ifa.audituser = '自动审核' THEN 1 END ) AS "automaticAudit"
  1446. FROM
  1447. ins_fee_audit ifa
  1448. LEFT JOIN ins_orders io ON io.orderno = ifa.orderno
  1449. LEFT JOIN ins_area_company iac ON iac.orderno = io.orderno
  1450. AND iac.orderstatus = 3
  1451. LEFT JOIN ptl_agreement pa ON pa.id = iac.agreement_id
  1452. LEFT JOIN esm_ins_company eic ON eic.id = pa.partner_companies_id
  1453. <where>
  1454. 1=1
  1455. and iac.id = ifa.ins_order_no
  1456. AND iac.orderstatus = 3
  1457. <if test="taskStatisticsVo.reviewer !=null and taskStatisticsVo.reviewer !=''">
  1458. and ifa.audituser =#{taskStatisticsVo.reviewer}
  1459. </if>
  1460. <if test="taskStatisticsVo.audittime !=null and taskStatisticsVo.audittime !=''">
  1461. and ifa.audittime =#{taskStatisticsVo.audittime}
  1462. </if>
  1463. <if test="taskStatisticsVo.companyId !=null and taskStatisticsVo.companyId !=''">
  1464. and iac.company_id =#{taskStatisticsVo.companyId}
  1465. </if>
  1466. <if test="taskStatisticsVo.createtimeStart !=null and taskStatisticsVo.createtimeStart != '' and taskStatisticsVo.createtimeEnd !=null and taskStatisticsVo.createtimeEnd != ''">
  1467. AND DATE_FORMAT( ifa.audittime, '%Y-%m-%d') BETWEEN DATE_FORMAT( #{taskStatisticsVo.createtimeStart}, '%Y-%m-%d') AND DATE_FORMAT( #{taskStatisticsVo.createtimeEnd}, '%Y-%m-%d')
  1468. </if>
  1469. <if test="taskStatisticsVo.beginDate !=null and taskStatisticsVo.beginDate != '' and taskStatisticsVo.endDate !=null and taskStatisticsVo.endDate != ''">
  1470. AND DATE_FORMAT( ifa.signing_time, '%Y-%m-%d') BETWEEN DATE_FORMAT( #{taskStatisticsVo.beginDate}, '%Y-%m-%d') AND DATE_FORMAT( #{taskStatisticsVo.endDate}, '%Y-%m-%d')
  1471. </if>
  1472. <if test="taskStatisticsVo.deptIds != null and taskStatisticsVo.deptIds != '' and taskStatisticsVo.deptIds.size() > 0">
  1473. AND io.deptid in
  1474. <foreach collection="taskStatisticsVo.deptIds" item="item" open="(" separator="," close=")">
  1475. #{item}
  1476. </foreach>
  1477. </if>
  1478. <if test="taskStatisticsVo.userIds != null and taskStatisticsVo.userIds != '' and taskStatisticsVo.userIds.size() > 0">
  1479. AND su.id in
  1480. <foreach collection="taskStatisticsVo.userIds" item="item" open="(" separator="," close=")">
  1481. #{item}
  1482. </foreach>
  1483. </if>
  1484. <choose>
  1485. <when test="taskStatisticsVo.riskCode != null and taskStatisticsVo.riskCode != '' and taskStatisticsVo.riskCode != 'all' ">
  1486. and iac.product = #{taskStatisticsVo.riskCode}
  1487. </when>
  1488. </choose>
  1489. </where>
  1490. GROUP BY
  1491. iac.company_id,
  1492. iac.inscompany
  1493. </select>
  1494. <select id="getOrderManpower" resultType="com.ydtech.modules.admin.model.dto.QxFrontlineAgentDto">
  1495. SELECT
  1496. count( a.numberUserId ) as "orderManpower",
  1497. sum( a.orderAmount ) as "totalPremium",
  1498. sum( a.orderAmount )/ count( a.numberUserId ) as "averagePremium"
  1499. FROM
  1500. (
  1501. SELECT
  1502. count( io.userid ) AS "numberUserId",
  1503. SUM(IFNULL(iac.jqpremium, 0)) +
  1504. SUM(IFNULL(iac.sypremium, 0)) +
  1505. SUM(IFNULL(iac.jypremium, 0)) AS "orderAmount"
  1506. FROM
  1507. `ins_area_company` iac
  1508. LEFT JOIN ins_orders io ON io.orderno = iac.orderno
  1509. <where>
  1510. iac.orderstatus = '3'
  1511. <if test="ids != null and ids.size()>0 ">
  1512. AND io.userid IN
  1513. <foreach item="item" collection="ids" open="(" separator="," close=")">
  1514. #{item}
  1515. </foreach>
  1516. </if>
  1517. </where>
  1518. GROUP BY
  1519. io.userid
  1520. ) a
  1521. </select>
  1522. <select id="getOrderManpowerNew" resultType="com.ydtech.modules.admin.model.dto.QxFrontlineAgentDto">
  1523. SELECT
  1524. count( a.numberUserId ) as "orderManpower",
  1525. IFNULL(sum( a.orderAmount ),0) as "totalPremium",
  1526. ROUND(sum( a.orderAmount )/ sum(a.ordernoNumber),2) AS "averagePremium"
  1527. FROM
  1528. (
  1529. SELECT
  1530. count( io.userid ) AS "numberUserId",
  1531. count( iac.orderno ) AS "ordernoNumber",
  1532. SUM(IFNULL(iac.jqpremium, 0)
  1533. +IFNULL(iac.sypremium, 0)
  1534. +IFNULL(iac.jypremium, 0)
  1535. ) AS "orderAmount"
  1536. FROM
  1537. `ins_area_company` iac
  1538. LEFT JOIN ins_orders io ON io.orderno = iac.orderno
  1539. <where>
  1540. iac.orderstatus = '3'
  1541. <if test="vo.ids != null and vo.ids.size()>0 ">
  1542. AND io.userid IN
  1543. <foreach item="item" collection="vo.ids" open="(" separator="," close=")">
  1544. #{item}
  1545. </foreach>
  1546. </if>
  1547. <if test="vo.createtimeStart != null and vo.createtimeStart!='' and vo.createtimeEnd != null and vo.createtimeEnd!=''">
  1548. AND iac.signing_time BETWEEN #{vo.createtimeStart} AND #{vo.createtimeEnd}
  1549. </if>
  1550. </where>
  1551. GROUP BY
  1552. io.userid
  1553. ) a
  1554. order by sum( a.orderAmount ) desc
  1555. </select>
  1556. <select id="getChannelOrderManpowerNew" resultType="com.ydtech.modules.admin.model.dto.QxFrontlineAgentDto">
  1557. SELECT
  1558. a.userId as "userId",
  1559. a.userName as "name",
  1560. a.orderNumber as "orderNumber",
  1561. a.underwritingCount as "underwritingCount",
  1562. a.qutationInsureCount as "qutationInsureCount",
  1563. IFNULL(a.jqpremium,0) + IFNULL(a.sypremium,0) + IFNULL(a.jypremium,0) as "totalPremium",
  1564. a.isFactorVerify as "isFactorVerify",
  1565. a.isNotFactorVerify as "isNotFactorVerify"
  1566. FROM
  1567. (
  1568. SELECT
  1569. io.userid as "userId",
  1570. io.username as "userName",
  1571. count( iac.orderno ) AS "orderNumber",
  1572. sum(CASE WHEN iac.orderstatus = 3 THEN iac.jqpremium END ) AS jqpremium,
  1573. sum(CASE WHEN iac.orderstatus = 3 THEN iac.sypremium END ) AS sypremium,
  1574. sum(CASE WHEN iac.orderstatus = 3 THEN iac.jypremium END ) AS jypremium,
  1575. COUNT( CASE WHEN iac.orderstatus = 2 THEN 1 END ) AS underwritingCount,
  1576. COUNT( CASE WHEN iac.orderstatus = 3 THEN 1 END ) AS qutationInsureCount,
  1577. COUNT( CASE WHEN su.factor_verify = 1 THEN 1 END ) AS isFactorVerify,
  1578. COUNT( CASE WHEN su.factor_verify = 0 THEN 1 END ) AS isNotFactorVerify
  1579. FROM
  1580. `ins_area_company` iac
  1581. LEFT JOIN ins_orders io ON io.orderno = iac.orderno
  1582. left join sys_user su on su.id=io.userid
  1583. <where>
  1584. <if test="vo.ids != null and vo.ids.size()>0 ">
  1585. AND io.userid IN
  1586. <foreach item="item" collection="vo.ids" open="(" separator="," close=")">
  1587. #{item}
  1588. </foreach>
  1589. </if>
  1590. <if test="vo.createtimeStart != null and vo.createtimeStart!='' and vo.createtimeEnd != null and vo.createtimeEnd!=''">
  1591. AND iac.signing_time BETWEEN #{vo.createtimeStart} AND #{vo.createtimeEnd}
  1592. </if>
  1593. <if test="vo.beginDate != null and vo.beginDate!='' and vo.endDate != null and vo.endDate!=''">
  1594. AND iac.createtime BETWEEN #{vo.beginDate} AND #{vo.endDate}
  1595. </if>
  1596. <if test="vo.deptIds != null and vo.deptIds != '' and vo.deptIds.size() > 0">
  1597. AND io.deptid in
  1598. <foreach collection="vo.deptIds" item="item" open="(" separator="," close=")">
  1599. #{item}
  1600. </foreach>
  1601. </if>
  1602. <if test="vo.userIds != null and vo.userIds != '' and vo.userIds.size() > 0">
  1603. AND io.userid in
  1604. <foreach collection="vo.userIds" item="item" open="(" separator="," close=")">
  1605. #{item}
  1606. </foreach>
  1607. </if>
  1608. </where>
  1609. GROUP BY
  1610. io.userid,
  1611. io.username
  1612. ) a
  1613. left join sys_user su on su.id=a.userId
  1614. </select>
  1615. <select id="NumberQuotations" resultType="com.ydtech.modules.admin.model.dto.TaskStatisticsDto">
  1616. SELECT
  1617. count(iac.id) as "orderNumber",
  1618. COUNT( CASE WHEN iac.orderstatus = 2 THEN 1 END ) AS underwritingCount,
  1619. COUNT( CASE WHEN iac.orderstatus = 3 THEN 1 END ) AS qutationInsureCount,
  1620. sum( CASE WHEN iac.orderstatus = 3 THEN IFNULL(iac.jqpremium, 0) + IFNULL(iac.sypremium, 0) + IFNULL(iac.jypremium, 0) END ) AS totalPremium
  1621. FROM
  1622. ins_area_company iac
  1623. left join ins_orders io on io.orderno = iac.orderno
  1624. left join sys_dept sd on sd.id=io.deptid
  1625. left join sys_user su on su.id=io.userid
  1626. left join ins_fee_audit ifa on ifa .ins_order_no =iac.id
  1627. <where>
  1628. sd.management_source = '2'
  1629. <if test="userId !=null and userId !=''">
  1630. and io.userId =#{userId}
  1631. </if>
  1632. </where>
  1633. </select>
  1634. <select id="totalQuotation" resultType="com.ydtech.modules.admin.model.dto.TaskStatisticsDto">
  1635. SELECT
  1636. agree.insurance_company_id AS companyId,
  1637. agree.insurance_company AS companyName,
  1638. agree.partner_companies_id AS parterCompanyId,
  1639. ins.namesimple AS parterCompanyName,
  1640. count(iac.orderstatus) AS orderNumber,
  1641. '-' as bigQutationCount,
  1642. '-' as bigUnderwritingCount,
  1643. '-' as bigCloseRate,
  1644. COUNT( CASE WHEN iac.orderstatus = 2 THEN 1 END ) AS underwritingCount,
  1645. COUNT( CASE WHEN iac.orderstatus = 3 THEN 1 END ) AS qutationInsureCount,
  1646. COUNT( CASE WHEN iac.orderstatus = 0 THEN 1 END )/ count(iac.orderstatus) AS passRate,
  1647. COUNT( CASE WHEN iac.orderstatus = 2 THEN 1 END )/ count(iac.orderstatus) AS underwritingCountRate,
  1648. COUNT( CASE WHEN iac.orderstatus = 3 THEN 1 END )/ count(iac.orderstatus) AS closeRate,
  1649. COUNT( CASE WHEN iac.orderstatus = 3 THEN 1 END )/ COUNT( CASE WHEN iac.orderstatus = 2 THEN 1 END ) AS
  1650. contributionRate
  1651. FROM
  1652. ins_area_company iac
  1653. LEFT JOIN ptl_agreement agree ON iac.agreement_id = agree.id
  1654. LEFT JOIN ins_orders io on io.orderno = iac.orderno
  1655. LEFT JOIN esm_ins_company ins ON agree.partner_companies_id = ins.id
  1656. WHERE
  1657. agree.id IS NOT NULL
  1658. <if test="vo.companyId != null and vo.companyId!='' ">
  1659. agree.insurance_company_id = #{vo.companyId}
  1660. </if>
  1661. <if test="vo.parterCompanyId != null and vo.parterCompanyId!='' ">
  1662. agree.partner_companies_id = #{vo.parterCompanyId}
  1663. </if>
  1664. <if test="vo.beginDate != null and vo.beginDate!='' and vo.endDate != null and vo.endDate!=''">
  1665. AND iac.createtime BETWEEN #{vo.beginDate} AND #{vo.endDate}
  1666. </if>
  1667. <if test="vo.provinceId != null and vo.provinceId != ''">
  1668. and io.deptid like "${vo.provinceId}%"
  1669. </if>
  1670. <if test="vo.cityId != null and vo.cityId != ''">
  1671. and io.deptid like "${vo.cityId}%"
  1672. </if>
  1673. <if test="vo.countyId != null and vo.countyId != ''">
  1674. and io.deptid like "${vo.countyId}%"
  1675. </if>
  1676. <if test="taskStatisticsVo.houseId != null and vo.houseId != ''">
  1677. and io.deptid like "${vo.houseId}%"
  1678. </if>
  1679. GROUP BY
  1680. agree.insurance_company_id,
  1681. agree.insurance_company,
  1682. agree.partner_companies_id,
  1683. ins.NAME
  1684. </select>
  1685. <select id="getBusinessData" resultType="com.ydtech.modules.admin.model.dto.TaskStatisticsDto">
  1686. select
  1687. a.companyId as "companyId",
  1688. a.insuranceCompanyName as "insuranceCompanyName",
  1689. a.parterCompanyId as "parterCompanyId",
  1690. a.partnerCompaniesName as "partnerCompaniesName",
  1691. a.totalPremium as "totalPremium",
  1692. a.qutationInsureCount as "qutationInsureCount",
  1693. ROUND(a.averagePremium, 2) as "averagePremium",
  1694. a.userNumber as "userNumber",
  1695. ROUND(a.perCapitaAmount, 2) as "perCapitaAmount",
  1696. c.docking_person as "dockingPerson",
  1697. c.docking_phone as "dockingPhone",
  1698. c.agreement_type as "agreementType",
  1699. b.logo as "logo"
  1700. from (
  1701. SELECT
  1702. agree.insurance_company_id AS "companyId",
  1703. agree.insurance_company AS "insuranceCompanyName",
  1704. agree.partner_companies_id AS "parterCompanyId",
  1705. ins.namesimple AS "partnerCompaniesName",
  1706. agree.id as "agreeId",
  1707. IFNULL(sum(iac.jqpremium),0) + IFNULL(sum(iac.sypremium),0) +IFNULL(sum(iac.jypremium),0) as "totalPremium",
  1708. COUNT(0 ) AS "qutationInsureCount",
  1709. (IFNULL(sum(iac.jqpremium),0) + IFNULL(sum(iac.sypremium),0) +IFNULL(sum(iac.jypremium),0)) / COUNT(0 ) AS "averagePremium",
  1710. COUNT(DISTINCT io.userId) AS "userNumber",
  1711. (IFNULL(sum(iac.jqpremium),0) + IFNULL(sum(iac.sypremium),0) +IFNULL(sum(iac.jypremium),0)) / COUNT(DISTINCT io.userId) as "perCapitaAmount"
  1712. FROM
  1713. ins_area_company iac
  1714. LEFT JOIN ptl_agreement agree ON iac.agreement_id = agree.id
  1715. LEFT JOIN ins_orders io on io.orderno = iac.orderno
  1716. LEFT JOIN esm_ins_company ins ON agree.partner_companies_id = ins.id
  1717. WHERE
  1718. agree.id IS NOT NULL
  1719. and iac.orderstatus = '3'
  1720. <if test="vo.companyId != null and vo.companyId!='' ">
  1721. and agree.insurance_company_id = #{vo.companyId}
  1722. </if>
  1723. <if test="vo.parterCompanyId != null and vo.parterCompanyId!='' ">
  1724. and agree.partner_companies_id = #{vo.parterCompanyId}
  1725. </if>
  1726. <if test="vo.createtimeStart != null and vo.createtimeStart!='' and vo.createtimeEnd != null and vo.createtimeEnd!=''">
  1727. AND DATE_FORMAT( iac.signing_time, '%Y-%m-%d') BETWEEN DATE_FORMAT( #{vo.createtimeStart}, '%Y-%m-%d') AND DATE_FORMAT( #{vo.createtimeEnd}, '%Y-%m-%d')
  1728. </if>
  1729. <if test="vo.provinceId != null and vo.provinceId != '' and vo.cityId == null and vo.countyId == null and vo.houseId == null ">
  1730. and io.deptid like "${vo.provinceId}%"
  1731. </if>
  1732. <if test="vo.cityId != null and vo.cityId != '' and vo.countyId ==null and vo.houseId ==null">
  1733. and io.deptid like "${vo.cityId}%"
  1734. </if>
  1735. <if test="vo.countyId != null and vo.countyId != '' and vo.houseId ==null">
  1736. and io.deptid like "${vo.countyId}%"
  1737. </if>
  1738. <if test="vo.houseId != null and vo.houseId != ''">
  1739. and io.deptid like "${vo.houseId}%"
  1740. </if>
  1741. <if test="vo.deptIds != null and vo.deptIds != '' and vo.deptIds.size() > 0">
  1742. AND io.deptid in
  1743. <foreach collection="vo.deptIds" item="item" open="(" separator="," close=")">
  1744. #{item}
  1745. </foreach>
  1746. </if>
  1747. <if test="vo.userIds != null and vo.userIds != '' and vo.userIds.size() > 0">
  1748. AND io.userid in
  1749. <foreach collection="vo.userIds" item="item" open="(" separator="," close=")">
  1750. #{item}
  1751. </foreach>
  1752. </if>
  1753. GROUP BY
  1754. agree.insurance_company_id,
  1755. agree.insurance_company,
  1756. agree.partner_companies_id,
  1757. agree.id
  1758. <choose>
  1759. <when test="vo.orderSort != null and vo.orderSort != '' and vo.userNumberSort == null ">
  1760. order by
  1761. sum(sumpremium) ${vo.orderSort == 'asc' ? 'asc' : 'desc'}
  1762. </when>
  1763. <when test="vo.userNumberSort != null and vo.userNumberSort != '' and vo.orderSort == null ">
  1764. order by
  1765. COUNT(DISTINCT io.userId) ${vo.userNumberSort == 'asc' ? 'asc' : 'desc'}
  1766. </when>
  1767. <when test="vo.userNumberSort != null and vo.userNumberSort != '' and vo.orderSort != null and vo.orderSort != '' ">
  1768. order by
  1769. COUNT(DISTINCT io.userId) ${vo.userNumberSort == 'asc' ? 'asc' : 'desc'}, sum(sumpremium) ${vo.orderSort == 'asc' ? 'asc' : 'desc'}
  1770. </when>
  1771. </choose>
  1772. ) a
  1773. left join esm_ins_company b on b.id =a.companyId
  1774. left join ptl_agreement c on c.id =a.agreeId
  1775. </select>
  1776. <select id="getDistribution" resultType="com.ydtech.modules.admin.model.dto.TaskStatisticsDto">
  1777. SELECT
  1778. agree.insurance_company_id AS "companyId",
  1779. agree.insurance_company AS "insuranceCompanyName",
  1780. agree.partner_companies_id AS "parterCompanyId",
  1781. ins.namesimple AS "partnerCompaniesName",
  1782. IFNULL(sum(iac.jqpremium),0) + IFNULL(sum(iac.sypremium),0) +IFNULL(sum(iac.jypremium),0) as "totalPremium",
  1783. COUNT(0) AS "qutationInsureCount",
  1784. ROUND((IFNULL(sum(iac.jqpremium),0) + IFNULL(sum(iac.sypremium),0) +IFNULL(sum(iac.jypremium),0)) / COUNT(0), 2) AS "averagePremium",
  1785. COUNT(DISTINCT io.userId) AS "userNumber",
  1786. ROUND((IFNULL(sum(iac.jqpremium),0) + IFNULL(sum(iac.sypremium),0) +IFNULL(sum(iac.jypremium),0)) / COUNT(DISTINCT io.userId) ,2) as "perCapitaAmount"
  1787. FROM
  1788. ins_area_company iac
  1789. LEFT JOIN ptl_agreement agree ON iac.agreement_id = agree.id
  1790. LEFT JOIN ins_orders io on io.orderno = iac.orderno
  1791. LEFT JOIN esm_ins_company ins ON agree.partner_companies_id = ins.id
  1792. WHERE
  1793. agree.id IS NOT NULL
  1794. <if test="vo.companyId != null and vo.companyId!='' ">
  1795. and agree.insurance_company_id = #{vo.companyId}
  1796. </if>
  1797. <if test="vo.parterCompanyId != null and vo.parterCompanyId!='' ">
  1798. and agree.partner_companies_id = #{vo.parterCompanyId}
  1799. </if>
  1800. <if test="vo.createtimeStart != null and vo.createtimeStart!='' and vo.createtimeEnd != null and vo.createtimeEnd!=''">
  1801. AND DATE_FORMAT( iac.signing_time, '%Y-%m-%d') BETWEEN DATE_FORMAT( #{vo.createtimeStart}, '%Y-%m-%d') AND DATE_FORMAT( #{vo.createtimeEnd}, '%Y-%m-%d')
  1802. </if>
  1803. <if test="vo.days !=null and vo.days !='' and vo.days != 0 ">
  1804. and iac.createtime >= DATE_SUB(NOW(), INTERVAL #{vo.days} DAY)
  1805. </if>
  1806. <if test="vo.provinceId != null and vo.provinceId != ''">
  1807. and io.deptid like "${vo.provinceId}%"
  1808. </if>
  1809. <if test="vo.cityId != null and vo.cityId != ''">
  1810. and io.deptid like "${vo.cityId}%"
  1811. </if>
  1812. <if test="vo.countyId != null and vo.countyId != ''">
  1813. and io.deptid like "${vo.countyId}%"
  1814. </if>
  1815. <if test="vo.houseId != null and vo.houseId != ''">
  1816. and io.deptid like "${vo.houseId}%"
  1817. </if>
  1818. <if test="vo.quotationStatus != null and vo.quotationStatus != ''">
  1819. and iac.orderstatus =#{vo.quotationStatus}
  1820. </if>
  1821. <if test="vo.deptIds != null and vo.deptIds != '' and vo.deptIds.size() > 0">
  1822. AND io.deptid in
  1823. <foreach collection="vo.deptIds" item="item" open="(" separator="," close=")">
  1824. #{item}
  1825. </foreach>
  1826. </if>
  1827. <if test="vo.userIds != null and vo.userIds != '' and vo.userIds.size() > 0">
  1828. AND io.userid in
  1829. <foreach collection="vo.userIds" item="item" open="(" separator="," close=")">
  1830. #{item}
  1831. </foreach>
  1832. </if>
  1833. GROUP BY
  1834. agree.insurance_company_id,
  1835. agree.insurance_company,
  1836. agree.partner_companies_id,
  1837. ins.namesimple
  1838. </select>
  1839. <select id="getOrderPremiumByUserIds" resultType="Double">
  1840. SELECT
  1841. IFNULL(
  1842. SUM( IFNULL( iac.jqpremium, 0 ) + IFNULL( iac.sypremium, 0 ) + IFNULL( iac.jypremium, 0 ) ),
  1843. 0
  1844. ) AS "totalPremium"
  1845. FROM
  1846. `ins_area_company` iac
  1847. LEFT JOIN ins_orders io ON io.orderno = iac.orderno
  1848. <where>
  1849. iac.orderstatus = '3'
  1850. <if test="ids != null and ids.size()>0 ">
  1851. AND io.userid IN
  1852. <foreach item="item" collection="ids" open="(" separator="," close=")">
  1853. #{item}
  1854. </foreach>
  1855. </if>
  1856. </where>
  1857. </select>
  1858. <select id="querOrdersDataPage" resultType="com.ydtech.modules.admin.model.report.company.OrdersDataDto">
  1859. SELECT
  1860. count( 0 ) AS "orderNumber",
  1861. b.licenseno as "licenseno",
  1862. b.frameno as "frameno",
  1863. b.modelCode as "modelCode",
  1864. b.modelcname as "modelcname"
  1865. FROM
  1866. (
  1867. SELECT
  1868. io.orderstatus AS orderstatus,
  1869. io.frameno AS frameno,
  1870. REPLACE(JSON_EXTRACT(io.carinfo, '$.engineNo'), '"', '') as "modelCode",
  1871. REPLACE(JSON_EXTRACT(io.carinfo, '$.modelcname'), '"', '') as "modelcname",
  1872. ifnull(io.licenseno, '') AS licenseno
  1873. FROM
  1874. ins_orders io
  1875. LEFT JOIN sys_user su on io.userid=su.id
  1876. <where>
  1877. 1=1
  1878. <if test="vo.beginDate != null and vo.beginDate!='' and vo.endDate != null and vo.endDate!=''">
  1879. AND io.createtime BETWEEN #{vo.beginDate} AND #{vo.endDate}
  1880. </if>
  1881. <if test="vo.licenseno != null and vo.licenseno!='' ">
  1882. AND io.licenseno =#{vo.licenseno}
  1883. </if>
  1884. <if test="vo.userId != null and vo.userId!='' ">
  1885. AND io.userid =#{vo.userId}
  1886. </if>
  1887. <if test="vo.userName != null and vo.userName!='' ">
  1888. AND su.name =#{vo.userName}
  1889. </if>
  1890. <if test="vo.mobile != null and vo.mobile!='' ">
  1891. AND su.mobile =#{vo.mobile}
  1892. </if>
  1893. <if test="vo.frameno != null and vo.frameno!='' ">
  1894. AND io.frameno =#{vo.frameno}
  1895. </if>
  1896. <if test="vo.deptId != null and vo.deptId!='' ">
  1897. and io.deptid like concat('%', #{vo.deptId}, '%')
  1898. </if>
  1899. <if test="vo.year != null and vo.year!='' ">
  1900. AND DATE_FORMAT( io.createtime, '%Y') =#{vo.year}
  1901. </if>
  1902. <if test="vo.deptIds != null and vo.deptIds != '' and vo.deptIds.size() > 0">
  1903. AND io.deptid in
  1904. <foreach collection="vo.deptIds" item="item" open="(" separator="," close=")">
  1905. #{item}
  1906. </foreach>
  1907. </if>
  1908. <if test="vo.userIds != null and vo.userIds != '' and vo.userIds.size() > 0">
  1909. AND io.userid in
  1910. <foreach collection="vo.userIds" item="item" open="(" separator="," close=")">
  1911. #{item}
  1912. </foreach>
  1913. </if>
  1914. </where>
  1915. ) b
  1916. GROUP BY
  1917. b.licenseno,
  1918. b.frameno,
  1919. b.modelCode,
  1920. b.modelcname
  1921. </select>
  1922. <select id="getOrdersGroupByLicenseno" resultType="com.ydtech.modules.admin.model.report.company.OrdersDataDto">
  1923. SELECT
  1924. io.licenseno AS "licenseno",
  1925. io.frameno AS "frameno",
  1926. io.orderstatus as "orderstatus",
  1927. io.orderno as "orderno"
  1928. FROM
  1929. ins_orders io
  1930. LEFT JOIN sys_user su on io.userid=su.id
  1931. <where>
  1932. io.licenseno is not null
  1933. <if test="vo.beginDate != null and vo.beginDate!='' and vo.endDate != null and vo.endDate!=''">
  1934. AND io.createtime BETWEEN #{vo.beginDate} AND #{vo.endDate}
  1935. </if>
  1936. <if test="vo.licenseno != null and vo.licenseno!='' ">
  1937. AND io.licenseno =#{vo.licenseno}
  1938. </if>
  1939. <if test="vo.userId != null and vo.userId!='' ">
  1940. AND io.userId =#{vo.userId}
  1941. </if>
  1942. <if test="vo.userName != null and vo.userName!='' ">
  1943. AND su.name =#{vo.userName}
  1944. </if>
  1945. <if test="vo.mobile != null and vo.mobile!='' ">
  1946. AND su.mobile =#{vo.mobile}
  1947. </if>
  1948. <if test="vo.frameno != null and vo.frameno!='' ">
  1949. AND su.frameno =#{vo.frameno}
  1950. </if>
  1951. <if test="vo.deptId != null and vo.deptId!='' ">
  1952. and io.deptid like concat('%', #{vo.deptId}, '%')
  1953. </if>
  1954. </where>
  1955. </select>
  1956. <select id="querOrdersamountTo" resultType="com.ydtech.modules.admin.model.report.company.OrdersDataDto">
  1957. select sum(a.orderNumber) as "orderNumber",
  1958. count(a.licenseno) as "b.frameno"
  1959. from (
  1960. SELECT
  1961. count( 0 ) AS "orderNumber",
  1962. b.licenseno as "licenseno",
  1963. b.frameno as "frameno"
  1964. FROM
  1965. (
  1966. SELECT
  1967. io.orderstatus AS orderstatus,
  1968. io.frameno AS frameno,
  1969. ifnull(io.licenseno, '') AS licenseno
  1970. FROM
  1971. ins_orders io
  1972. LEFT JOIN sys_user su on io.userid=su.id
  1973. <where>
  1974. 1=1
  1975. <if test="vo.beginDate != null and vo.beginDate!='' and vo.endDate != null and vo.endDate!=''">
  1976. AND io.createtime BETWEEN #{vo.beginDate} AND #{vo.endDate}
  1977. </if>
  1978. <if test="vo.licenseno != null and vo.licenseno!='' ">
  1979. AND io.licenseno =#{vo.licenseno}
  1980. </if>
  1981. <if test="vo.userId != null and vo.userId!='' ">
  1982. AND io.userid =#{vo.userId}
  1983. </if>
  1984. <if test="vo.userName != null and vo.userName!='' ">
  1985. AND su.name =#{vo.userName}
  1986. </if>
  1987. <if test="vo.mobile != null and vo.mobile!='' ">
  1988. AND su.mobile =#{vo.mobile}
  1989. </if>
  1990. <if test="vo.frameno != null and vo.frameno!='' ">
  1991. AND io.frameno =#{vo.frameno}
  1992. </if>
  1993. <if test="vo.deptId != null and vo.deptId!='' ">
  1994. and io.deptid like concat('%', #{vo.deptId}, '%')
  1995. </if>
  1996. </where>
  1997. ) b
  1998. GROUP BY
  1999. b.licenseno,
  2000. b.frameno
  2001. ) a
  2002. </select>
  2003. <select id="querResultOrderNumber" resultType="com.ydtech.modules.admin.model.report.company.OrdersDataDto">
  2004. SELECT
  2005. count( io.orderno ) AS "orderNumber",
  2006. IFNULL(count(CASE WHEN io.orderstatus = '3' THEN 1 ELSE 0 END),0) / (IFNULL(count(CASE WHEN io.orderstatus = '2' THEN 1 ELSE 0 END),0) + IFNULL(count(CASE WHEN io.orderstatus = '3' THEN 1 ELSE 0 END),0)) AS "closeRate"
  2007. FROM
  2008. ins_orders io
  2009. LEFT JOIN ins_area_company iac ON iac.orderno = io.orderno
  2010. LEFT JOIN sys_user su ON io.userid = su.id
  2011. <where>
  2012. 1=1
  2013. <if test="vo.beginDate != null and vo.beginDate!='' and vo.endDate != null and vo.endDate!=''">
  2014. AND io.createtime BETWEEN #{vo.beginDate} AND #{vo.endDate}
  2015. </if>
  2016. <if test="vo.licenseno != null and vo.licenseno!='' ">
  2017. AND io.licenseno =#{vo.licenseno}
  2018. </if>
  2019. <if test="vo.userId != null and vo.userId!='' ">
  2020. AND io.userid =#{vo.userId}
  2021. </if>
  2022. <if test="vo.userName != null and vo.userName!='' ">
  2023. AND su.name =#{vo.userName}
  2024. </if>
  2025. <if test="vo.mobile != null and vo.mobile!='' ">
  2026. AND su.mobile =#{vo.mobile}
  2027. </if>
  2028. <if test="vo.frameno != null and vo.frameno!='' ">
  2029. AND su.frameno =#{vo.frameno}
  2030. </if>
  2031. <if test="vo.deptId != null and vo.deptId!='' ">
  2032. and io.deptid like concat('%', #{vo.deptId}, '%')
  2033. </if>
  2034. </where>
  2035. </select>
  2036. <select id="numberQuotationsByUserIds" resultType="com.ydtech.modules.admin.model.dto.TaskStatisticsDto">
  2037. SELECT
  2038. count(iac.id) as "orderNumber",
  2039. COUNT( CASE WHEN iac.orderstatus = 2 THEN 1 END ) AS underwritingCount,
  2040. COUNT( CASE WHEN iac.orderstatus = 3 THEN 1 END ) AS qutationInsureCount,
  2041. sum( CASE WHEN iac.orderstatus = 3 THEN IFNULL(iac.jqpremium, 0) + IFNULL(iac.sypremium, 0) + IFNULL(iac.jypremium, 0) END ) AS totalPremium
  2042. FROM
  2043. ins_area_company iac
  2044. left join ins_orders io on io.orderno = iac.orderno
  2045. <where>
  2046. <if test="ids != null and ids.size()>0 ">
  2047. AND io.userid IN
  2048. <foreach item="item" collection="ids" open="(" separator="," close=")">
  2049. #{item}
  2050. </foreach>
  2051. </if>
  2052. <if test="month != null and month!='' ">
  2053. AND DATE_FORMAT(iac.createtime, '%Y-%m') =#{month}
  2054. </if>
  2055. </where>
  2056. </select>
  2057. <select id="selectByOrdersDataVo" resultType="com.ydtech.modules.admin.model.report.company.OrdersDataDto">
  2058. select
  2059. iac.inscompany as "namesimple"
  2060. from
  2061. ins_area_company iac
  2062. <where>
  2063. 1=1
  2064. <if test="vo.orderstatus != null and vo.orderstatus != '' ">
  2065. AND iac.orderstatus =#{vo.orderstatus}
  2066. </if>
  2067. <if test="vo.orderno !=null and vo.orderno !='' ">
  2068. AND iac.orderno =#{vo.orderno}
  2069. </if>
  2070. </where>
  2071. </select>
  2072. <select id="channelExcel" resultType="com.ydtech.modules.admin.model.dto.TaskStatisticsExcel">
  2073. select a.*,(select name from sys_user where id =a.userId) as "userName"
  2074. from (
  2075. SELECT
  2076. sd.NAME AS "deptName",
  2077. io.userid AS "userId",
  2078. sd.parent_id as "deptId",
  2079. COUNT( CASE WHEN iac.orderstatus = 0 THEN 1 END ) AS qutationCount,
  2080. COUNT( CASE WHEN iac.orderstatus = 2 THEN 1 END ) AS underwritingCount,
  2081. COUNT( CASE WHEN iac.orderstatus = 3 THEN 1 END ) AS qutationInsureCount,
  2082. COUNT( CASE WHEN iac.orderstatus = 4 THEN 1 END ) AS underwritingReturn,
  2083. (COUNT( CASE WHEN iac.orderstatus = 2 THEN 1 END ) / COUNT( CASE WHEN iac.orderstatus = 0 THEN 1 END )) * 100 AS "passingRate",
  2084. (COUNT( CASE WHEN iac.orderstatus = 3 THEN 1 END ) / COUNT( iac.orderstatus )) * 100 AS "closeRate",
  2085. ((COUNT( CASE WHEN iac.orderstatus = 3 THEN 1 END ) + COUNT( CASE WHEN iac.orderstatus = 2 THEN 1 END ))/ COUNT( iac.orderstatus )) * 100 AS "contributionRate",
  2086. (COUNT( CASE WHEN iac.orderstatus = 0 THEN 1 END ) / COUNT( iac.orderstatus )) * 100 AS "quotationRate",
  2087. COUNT( CASE WHEN iac.orderstatus = 1 THEN 1 END ) AS "auditOrder"
  2088. FROM
  2089. ins_area_company iac
  2090. LEFT JOIN ins_orders io ON io.orderno = iac.orderno
  2091. LEFT JOIN sys_dept sd ON sd.id = io.deptid
  2092. <where>
  2093. 1=1
  2094. <if test="taskStatisticsVo.provinceId != null and taskStatisticsVo.provinceId != ''">
  2095. and io.deptid like "${taskStatisticsVo.provinceId}%"
  2096. </if>
  2097. <if test="taskStatisticsVo.cityId != null and taskStatisticsVo.cityId != ''">
  2098. and io.deptid like "${taskStatisticsVo.cityId}%"
  2099. </if>
  2100. <if test="taskStatisticsVo.countyId != null and taskStatisticsVo.countyId != ''">
  2101. and io.deptid like "${taskStatisticsVo.countyId}%"
  2102. </if>
  2103. <if test="taskStatisticsVo.houseId != null and taskStatisticsVo.houseId != ''">
  2104. and io.deptid like "${taskStatisticsVo.houseId}%"
  2105. </if>
  2106. <if test="taskStatisticsVo.createtimeStart !=null and taskStatisticsVo.createtimeStart != '' and taskStatisticsVo.createtimeEnd !=null and taskStatisticsVo.createtimeEnd != ''">
  2107. AND DATE_FORMAT( io.createtime, '%Y-%m-%d') BETWEEN #{taskStatisticsVo.createtimeStart} AND #{taskStatisticsVo.createtimeEnd}
  2108. </if>
  2109. <if test="taskStatisticsVo.beginDate !=null and taskStatisticsVo.beginDate != '' and taskStatisticsVo.endDate !=null and taskStatisticsVo.endDate != ''">
  2110. AND DATE_FORMAT( iac.createtime, '%Y-%m-%d') BETWEEN DATE_FORMAT( #{taskStatisticsVo.beginDate}, '%Y-%m-%d') AND DATE_FORMAT( #{taskStatisticsVo.endDate}, '%Y-%m-%d')
  2111. </if>
  2112. <if test="taskStatisticsVo.days !=null and taskStatisticsVo.days !='' ">
  2113. and iac.createtime >= DATE_SUB(NOW(), INTERVAL #{taskStatisticsVo.days} DAY)
  2114. </if>
  2115. <if test="taskStatisticsVo.managementSource!=null and taskStatisticsVo.managementSource!=''">
  2116. and sd.management_source=#{taskStatisticsVo.managementSource}
  2117. </if>
  2118. <if test="taskStatisticsVo.days !=null and taskStatisticsVo.days !='' ">
  2119. <choose>
  2120. <when test="taskStatisticsVo.days =='1'">
  2121. and io.createtime >= DATE_SUB(NOW(), INTERVAL 1 DAY)
  2122. </when>
  2123. <when test="taskStatisticsVo.days =='7'">
  2124. and io.createtime >= DATE_SUB(NOW(), INTERVAL 7 DAY)
  2125. </when>
  2126. <when test="taskStatisticsVo.days =='30'">
  2127. and io.createtime >= DATE_SUB(NOW(), INTERVAL 30 DAY)
  2128. </when>
  2129. </choose>
  2130. </if>
  2131. </where>
  2132. GROUP BY
  2133. io.userid,
  2134. sd.NAME,
  2135. sd.id
  2136. ) a
  2137. </select>
  2138. <select id="insuranceCompanyExcel" resultType="com.ydtech.modules.admin.model.dto.InsuranceCompanyExcel">
  2139. SELECT
  2140. a.*,
  2141. ( SELECT eic.namesimple FROM esm_ins_company eic WHERE eic.id = a.partner_companies_id ) AS "partnerCompaniesName"
  2142. FROM
  2143. (
  2144. SELECT
  2145. pa.insurance_company_id,
  2146. pa.partner_companies_id,
  2147. pa.insurance_company AS "insuranceCompanyName",
  2148. COUNT( CASE WHEN iac.orderstatus = 0 THEN 1 END ) AS qutationCount,
  2149. COUNT( CASE WHEN iac.orderstatus = 2 THEN 1 END ) AS underwritingCountRate,
  2150. COUNT( CASE WHEN iac.orderstatus = 3 THEN 1 END ) AS qutationInsureCount,
  2151. COUNT( CASE WHEN iac.orderstatus = 4 THEN 1 END ) AS underwritingReturn,
  2152. COUNT( CASE WHEN iac.orderstatus = 2 THEN 1 END ) / COUNT( CASE WHEN iac.orderstatus = 0 THEN 1 END ) AS "passingRate",
  2153. COUNT( CASE WHEN iac.orderstatus = 3 THEN 1 END ) / COUNT( CASE WHEN iac.orderstatus = 0 THEN 1 END ) AS "closeRate",
  2154. COUNT( CASE WHEN iac.orderstatus = 3 THEN 1 END ) / COUNT( iac.orderstatus ) AS "contributionRate",
  2155. COUNT( CASE WHEN iac.orderstatus = 0 THEN 1 END ) / COUNT( iac.orderstatus ) AS "quotationRate",
  2156. COUNT( CASE WHEN ifa.auditstatus = 1 THEN 1 END ) AS "auditOrder"
  2157. FROM
  2158. ins_area_company iac
  2159. LEFT JOIN ins_fee_audit ifa ON ifa.ins_order_no = iac.id
  2160. LEFT JOIN ptl_agreement pa ON pa.id = iac.agreement_id
  2161. <where>
  2162. pa.insurance_company_id IS NOT NULL
  2163. <if test="taskStatisticsVo.provinceId != null and taskStatisticsVo.provinceId != ''">
  2164. and io.deptid like "${taskStatisticsVo.provinceId}%"
  2165. </if>
  2166. <if test="taskStatisticsVo.cityId != null and taskStatisticsVo.cityId != ''">
  2167. and io.deptid like "${taskStatisticsVo.cityId}%"
  2168. </if>
  2169. <if test="taskStatisticsVo.countyId != null and taskStatisticsVo.countyId != ''">
  2170. and io.deptid like "${taskStatisticsVo.countyId}%"
  2171. </if>
  2172. <if test="taskStatisticsVo.houseId != null and taskStatisticsVo.houseId != ''">
  2173. and io.deptid like "${taskStatisticsVo.houseId}%"
  2174. </if>
  2175. <if test="taskStatisticsVo.createtimeStart !=null and taskStatisticsVo.createtimeStart != '' and taskStatisticsVo.createtimeEnd !=null and taskStatisticsVo.createtimeEnd != ''">
  2176. AND DATE_FORMAT( io.createtime, '%Y-%m-%d') BETWEEN #{taskStatisticsVo.createtimeStart} AND #{taskStatisticsVo.createtimeEnd}
  2177. </if>
  2178. <if test="taskStatisticsVo.beginDate !=null and taskStatisticsVo.beginDate != '' and taskStatisticsVo.endDate !=null and taskStatisticsVo.endDate != ''">
  2179. AND DATE_FORMAT( iac.createtime, '%Y-%m-%d') BETWEEN DATE_FORMAT( #{taskStatisticsVo.beginDate}, '%Y-%m-%d') AND DATE_FORMAT( #{taskStatisticsVo.endDate}, '%Y-%m-%d')
  2180. </if>
  2181. <if test="taskStatisticsVo.companyId !=null and taskStatisticsVo.companyId != ''">
  2182. AND iac.company_id =#{taskStatisticsVo.companyId}
  2183. </if>
  2184. <if test="taskStatisticsVo.days !=null and taskStatisticsVo.days !='' ">
  2185. and iac.createtime >= DATE_SUB(NOW(), INTERVAL #{taskStatisticsVo.days} DAY)
  2186. </if>
  2187. </where>
  2188. GROUP BY
  2189. pa.insurance_company_id,
  2190. pa.partner_companies_id,
  2191. pa.insurance_company
  2192. ) a
  2193. </select>
  2194. <select id="getSumBigOrderCount" resultType="com.ydtech.modules.admin.model.report.company.OrdersDataDto">
  2195. select count(0) as "orderNumber",
  2196. GROUP_CONCAT(inscompany ORDER BY inscompany SEPARATOR ',') as "namesimple"
  2197. from ins_area_company iac
  2198. left join ins_orders io on io.orderno = iac.orderno
  2199. <where>
  2200. 1=1
  2201. and iac.orderstatus ='3'
  2202. and io.orderstatus ='3'
  2203. <if test="vo.licenseno !=null and vo.licenseno!=''">
  2204. AND io.licenseno =#{vo.licenseno}
  2205. </if>
  2206. <if test="vo.frameno !=null and vo.frameno!=''">
  2207. AND io.frameno =#{vo.frameno}
  2208. </if>
  2209. <if test="vo.beginDate != null and vo.beginDate!='' and vo.endDate != null and vo.endDate!=''">
  2210. AND io.createtime BETWEEN #{vo.beginDate} AND #{vo.endDate}
  2211. </if>
  2212. <if test="vo.year != null and vo.year!='' ">
  2213. AND DATE_FORMAT( io.createtime, '%Y') =#{vo.year}
  2214. </if>
  2215. </where>
  2216. limit 10
  2217. </select>
  2218. <select id="queryAgencyUserInsAreaPage" resultType="com.ydtech.modules.admin.model.vo.AgencyUserInsAreaVo">
  2219. select
  2220. io.userid as userId,
  2221. io.username as userName,
  2222. io.licenseno as licenseno,
  2223. iac.id as companyId,
  2224. iac.jqpremium as jqpremium,
  2225. iac.sypremium as sypremium,
  2226. iac.jypremium as jypremium,
  2227. iac.createtime as createtime,
  2228. iac.orderstatus as orderstatus
  2229. from ins_area_company iac
  2230. left join ins_orders io on io.orderno = iac.orderno
  2231. <where>
  2232. iac.orderstatus=3
  2233. <if test="dto.userId !=null and dto.userId !=''">
  2234. and io.userid = #{dto.userId}
  2235. </if>
  2236. <if test="dto.deptId !=null and dto.deptId !=''">
  2237. and io.deptid like concat( #{dto.deptId}, '%')
  2238. </if>
  2239. <if test="dto.startTime !=null and dto.startTime !=''">
  2240. and io.createtime >= #{dto.startTime}
  2241. </if>
  2242. </where>
  2243. ORDER BY iac.createtime
  2244. </select>
  2245. <select id="querOrdersDataListExcel" resultType="com.ydtech.modules.admin.model.dto.OrdersDataExcel">
  2246. SELECT
  2247. count( 0 ) AS "orderNumber",
  2248. b.licenseno as "licenseno",
  2249. b.frameno as "frameno",
  2250. b.modelCode as "modelCode",
  2251. b.modelcname as "modelcname"
  2252. FROM
  2253. (
  2254. SELECT
  2255. io.orderstatus AS orderstatus,
  2256. io.frameno AS frameno,
  2257. REPLACE(JSON_EXTRACT(io.carinfo, '$.engineNo'), '"', '') as "modelCode",
  2258. REPLACE(JSON_EXTRACT(io.carinfo, '$.modelcname'), '"', '') as "modelcname",
  2259. ifnull(io.licenseno, '') AS licenseno
  2260. FROM
  2261. ins_orders io
  2262. LEFT JOIN sys_user su on io.userid=su.id
  2263. <where>
  2264. 1=1
  2265. <if test="vo.beginDate != null and vo.beginDate!='' and vo.endDate != null and vo.endDate!=''">
  2266. AND io.createtime BETWEEN #{vo.beginDate} AND #{vo.endDate}
  2267. </if>
  2268. <if test="vo.licenseno != null and vo.licenseno!='' ">
  2269. AND io.licenseno =#{vo.licenseno}
  2270. </if>
  2271. <if test="vo.userId != null and vo.userId!='' ">
  2272. AND io.userid =#{vo.userId}
  2273. </if>
  2274. <if test="vo.userName != null and vo.userName!='' ">
  2275. AND su.name =#{vo.userName}
  2276. </if>
  2277. <if test="vo.mobile != null and vo.mobile!='' ">
  2278. AND su.mobile =#{vo.mobile}
  2279. </if>
  2280. <if test="vo.frameno != null and vo.frameno!='' ">
  2281. AND io.frameno =#{vo.frameno}
  2282. </if>
  2283. <if test="vo.deptId != null and vo.deptId!='' ">
  2284. and io.deptid like concat('%', #{vo.deptId}, '%')
  2285. </if>
  2286. <if test="vo.year != null and vo.year!='' ">
  2287. AND DATE_FORMAT( io.createtime, '%Y') =#{vo.year}
  2288. </if>
  2289. <if test="vo.deptIds != null and vo.deptIds != '' and vo.deptIds.size() > 0">
  2290. AND io.deptid in
  2291. <foreach collection="vo.deptIds" item="item" open="(" separator="," close=")">
  2292. #{item}
  2293. </foreach>
  2294. </if>
  2295. <if test="vo.userIds != null and vo.userIds != '' and vo.userIds.size() > 0">
  2296. AND io.userid in
  2297. <foreach collection="vo.userIds" item="item" open="(" separator="," close=")">
  2298. #{item}
  2299. </foreach>
  2300. </if>
  2301. </where>
  2302. ) b
  2303. GROUP BY
  2304. b.licenseno,
  2305. b.frameno,
  2306. b.modelCode,
  2307. b.modelcname
  2308. </select>
  2309. <select id="orderCheckPage" resultType="com.ydtech.modules.order.entity.InsAreaCompany">
  2310. select
  2311. iac.id,
  2312. iac.orderno,
  2313. iac.agreement_id,
  2314. iac.jqpremium,
  2315. iac.sypremium,
  2316. iac.jypremium,
  2317. iac.taxamount,
  2318. iac.sumpremium,
  2319. io.licenseno,
  2320. iac.createtime,
  2321. su.name as auditname
  2322. FROM
  2323. ins_area_company iac
  2324. LEFT JOIN
  2325. ins_orders io on iac.orderno = io.orderno
  2326. left join ptl_agreement agree on iac.agreement_id =agree.id
  2327. left join ins_fee_audit ifa on iac.id = ifa.ins_order_no
  2328. left join sys_user su on su.id= ifa.audituser
  2329. WHERE
  2330. iac.operator_id = #{userId}
  2331. AND
  2332. iac.orderstatus = 3
  2333. and agree.is_external =1
  2334. and auditstatus =1
  2335. <if test="vo.id != null and vo.id!='' ">
  2336. and iac.id = #{vo.id}
  2337. </if>
  2338. <if test="vo.licenseno != null and vo.licenseno!='' ">
  2339. and io.licenseno like CONCAT('%', #{vo.licenseno}, '%')
  2340. </if>
  2341. </select>
  2342. <select id="costCenterTotal" resultType="java.util.HashMap">
  2343. SELECT
  2344. COUNT( CASE WHEN ifa.auditstatus = 1 THEN 1 END ) AS "allAuditstatusOrders",
  2345. COUNT( CASE WHEN ifa.auditstatus = 0 THEN 1 END ) AS "allAuditOrder",
  2346. COUNT( CASE WHEN ifa.auditstatus = 1 and ifa.audituser != '自动审核' THEN 1 END ) AS "allPersionAudit",
  2347. COUNT( CASE WHEN ifa.audituser = '自动审核' THEN 1 END ) AS "allAutomaticAudit"
  2348. FROM
  2349. ins_fee_audit ifa
  2350. LEFT JOIN ins_orders io ON io.orderno = ifa.orderno
  2351. LEFT JOIN ins_area_company iac ON iac.orderno = io.orderno
  2352. AND iac.orderstatus = 3
  2353. LEFT JOIN ptl_agreement pa ON pa.id = iac.agreement_id
  2354. LEFT JOIN esm_ins_company eic ON eic.id = pa.partner_companies_id
  2355. <where>
  2356. 1=1
  2357. and iac.id = ifa.ins_order_no
  2358. AND iac.orderstatus = 3
  2359. <if test="taskStatisticsVo.reviewer !=null and taskStatisticsVo.reviewer !=''">
  2360. and ifa.audituser =#{taskStatisticsVo.reviewer}
  2361. </if>
  2362. <if test="taskStatisticsVo.audittime !=null and taskStatisticsVo.audittime !=''">
  2363. and ifa.audittime =#{taskStatisticsVo.audittime}
  2364. </if>
  2365. <if test="taskStatisticsVo.companyId !=null and taskStatisticsVo.companyId !=''">
  2366. and iac.company_id =#{taskStatisticsVo.companyId}
  2367. </if>
  2368. <if test="taskStatisticsVo.createtimeStart !=null and taskStatisticsVo.createtimeStart != '' and taskStatisticsVo.createtimeEnd !=null and taskStatisticsVo.createtimeEnd != ''">
  2369. AND DATE_FORMAT( ifa.audittime, '%Y-%m-%d') BETWEEN DATE_FORMAT( #{taskStatisticsVo.createtimeStart}, '%Y-%m-%d') AND DATE_FORMAT( #{taskStatisticsVo.createtimeEnd}, '%Y-%m-%d')
  2370. </if>
  2371. <if test="taskStatisticsVo.beginDate !=null and taskStatisticsVo.beginDate != '' and taskStatisticsVo.endDate !=null and taskStatisticsVo.endDate != ''">
  2372. AND DATE_FORMAT( ifa.signing_time, '%Y-%m-%d') BETWEEN DATE_FORMAT( #{taskStatisticsVo.beginDate}, '%Y-%m-%d') AND DATE_FORMAT( #{taskStatisticsVo.endDate}, '%Y-%m-%d')
  2373. </if>
  2374. <if test="taskStatisticsVo.deptIds != null and taskStatisticsVo.deptIds != '' and taskStatisticsVo.deptIds.size() > 0">
  2375. AND io.deptid in
  2376. <foreach collection="taskStatisticsVo.deptIds" item="item" open="(" separator="," close=")">
  2377. #{item}
  2378. </foreach>
  2379. </if>
  2380. <if test="taskStatisticsVo.userIds != null and taskStatisticsVo.userIds != '' and taskStatisticsVo.userIds.size() > 0">
  2381. AND su.id in
  2382. <foreach collection="taskStatisticsVo.userIds" item="item" open="(" separator="," close=")">
  2383. #{item}
  2384. </foreach>
  2385. </if>
  2386. <choose>
  2387. <when test="taskStatisticsVo.riskCode != null and taskStatisticsVo.riskCode != '' and taskStatisticsVo.riskCode != 'all' ">
  2388. and iac.product = #{taskStatisticsVo.riskCode}
  2389. </when>
  2390. </choose>
  2391. </where>
  2392. </select>
  2393. <select id="getSubOrderCountDTO" resultType="com.ydtech.modules.order.entity.dto.SubOrderCountDTO">
  2394. select orderno, orderstatus, count(*)as count
  2395. from (select orderno, company_id, orderstatus
  2396. from ins_area_company
  2397. where orderno in
  2398. <foreach collection="orderNo" open="(" separator="," close=")" item="item" index="index">
  2399. #{item,jdbcType=VARCHAR}
  2400. </foreach>
  2401. and del_flag = '1'
  2402. group by orderno, company_id, orderstatus) as iac
  2403. group by orderno, orderstatus
  2404. </select>
  2405. <select id="getAllRejectOrders" resultType="com.ydtech.modules.order.entity.InsAreaCompany">
  2406. select
  2407. iac.id,
  2408. iac.orderno,
  2409. iac.agreement_id,
  2410. iac.jqpremium,
  2411. iac.sypremium,
  2412. iac.jypremium,
  2413. iac.taxamount,
  2414. iac.sumpremium,
  2415. io.licenseno,
  2416. ifa.audittime,
  2417. ifa.audituser as auditname,
  2418. ifa.rejectinfo,
  2419. "1" as orderExternalStatus
  2420. FROM
  2421. ins_fee_audit ifa
  2422. LEFT JOIN
  2423. ins_area_company iac on iac.id = ifa.ins_order_no
  2424. LEFT JOIN
  2425. ins_orders io on iac.orderno = io.orderno
  2426. left join
  2427. sys_user su on su.id= ifa.audituser
  2428. WHERE
  2429. ifa.auditstatus = 2 and IFNULL(iac.del_flag,'') != '0'
  2430. <if test="vo.id != null and vo.id!=''">
  2431. and iac.id = #{vo.id}
  2432. </if>
  2433. <if test="vo.licenseno != null and vo.licenseno!='' ">
  2434. and io.licenseno like CONCAT('%', #{vo.licenseno}, '%')
  2435. </if>
  2436. <if test="vo.auditname != null and vo.auditname!='' ">
  2437. and su.name like CONCAT('%', #{vo.auditname}, '%')
  2438. </if>
  2439. order by io.createtime
  2440. </select>
  2441. </mapper>