InsAreaCompanyMapper.xml 155 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388
  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. <result property="feeMatchErrMsg" column="fee_match_err_msg" jdbcType="VARCHAR"/>
  74. <result property="quoteErrMsg" column="quote_err_msg" jdbcType="VARCHAR"/>
  75. </resultMap>
  76. <resultMap id="InsAreaCompanyQueryDto" type="com.ydtech.modules.order.entity.dto.InsAreaCompanyQueryDto"
  77. extends="BaseResultMap">
  78. <result property="agreementName" column="agreement_name" jdbcType="VARCHAR"/>
  79. <result property="fileStatus" column="fileStatus" jdbcType="VARCHAR"/>
  80. </resultMap>
  81. <sql id="Base_Column_List">
  82. id,orderno,inscompany,
  83. reqtxt,reptxt,jqapplyno,
  84. jqpolicyno,syapplyno,sypolicyno,
  85. riskinfo,kindinfo,jqpremium,
  86. sypremium,taxamount,sumpremium,
  87. jqdiscountrate,sydiscountrate,feerate,
  88. disrate,auditid,auditname,
  89. audittime,auditopinion,jqappoint,
  90. syappoint,createtime,payment_link
  91. </sql>
  92. <select id="selectByOrderNo" resultMap="InsAreaCompanyQueryDto">
  93. SELECT iac.*, pa.agreement_name,
  94. (select IF(count(0)>0,'true','false') from pingan_sh_uploafile where sub_order_no=iac.id AND status=0) as fileStatus
  95. FROM ins_area_company as iac
  96. left join ptl_agreement as pa on pa.id = iac.agreement_id
  97. INNER JOIN (SELECT company_id, max(createtime) AS max_createtime
  98. FROM ins_area_company
  99. WHERE orderno = #{orderNo}
  100. GROUP BY company_id) t ON t.company_id = iac.company_id
  101. AND t.max_createtime = iac.createtime
  102. WHERE iac.orderno = #{orderNo}
  103. </select>
  104. <select id="selectAcceptInsurance" resultMap="InsAreaCompanyQueryDto">
  105. SELECT iac.*, pa.agreement_name,io.is_external,
  106. (select IF(count(0)>0,'true','false') from pingan_sh_uploafile where sub_order_no=iac.id AND status=0) as fileStatus
  107. FROM ins_area_company as iac
  108. left join ptl_agreement as pa on pa.id = iac.agreement_id
  109. left join ins_orders io on iac.orderno=io.orderno
  110. WHERE iac.orderstatus = 3
  111. and iac.orderno = #{orderNo};
  112. </select>
  113. <select id="queryLatestStatus" resultType="java.lang.String">
  114. SELECT iac.orderstatus
  115. FROM ins_area_company as iac
  116. INNER JOIN (SELECT company_id, max(createtime) AS max_createtime
  117. FROM ins_area_company
  118. WHERE orderno = #{orderNo}
  119. GROUP BY company_id) t ON t.company_id = iac.company_id
  120. AND t.max_createtime = iac.createtime
  121. WHERE iac.orderno = #{orderNo}
  122. ORDER BY orderstatus DESC
  123. LIMIT 1
  124. </select>
  125. <select id="getorDerIds" resultType="com.ydtech.modules.order.entity.InsAreaCompany">
  126. SELECT a.id as "id",
  127. a.orderno as "orderno"
  128. FROM ins_area_company a
  129. LEFT JOIN ins_fee_order_new b ON a.id = b.ins_order_no
  130. WHERE a.orderstatus = '3'
  131. or a.orderstatus = '2'
  132. and b.id is not null
  133. </select>
  134. <select id="getAuditOrders" resultType="com.ydtech.modules.order.entity.InsOrders">
  135. SELECT
  136. iac.id as orderno,
  137. io.quoteno,
  138. io.orderstatus,
  139. io.company_id,
  140. io.ins_company,
  141. io.carinfo,
  142. io.userid,
  143. io.username,
  144. io.deptid,
  145. io.deptname,
  146. io.agreeid,
  147. iac.productid,
  148. iac.product,
  149. iac.createtime,
  150. io.frameno,
  151. io.licenseno,
  152. JSON_UNQUOTE(json_extract(io.insureinfo, '$.name')) as insuredname,
  153. io.is_external,
  154. iac.jq_start_date as jqstartdate,
  155. iac.jq_end_date as jqenddate,
  156. iac.sy_start_date as systartdate,
  157. iac.sy_end_date as syenddate,
  158. io.vehicle_and_vessel_tax,
  159. io.operatorid,
  160. iac.operator_name,
  161. sd.management_source,
  162. iac.problem_order,
  163. CASE ifa.audituser
  164. WHEN '自动审核' THEN ifa.audituser
  165. ELSE su2.name END
  166. AS auditUser,
  167. CASE ifa.audituser
  168. WHEN '自动审核' THEN '2'
  169. ELSE '1' END
  170. AS checkType,
  171. ifa.audittime as auditTime,
  172. ifa.auditstatus as auditStatus,
  173. eic.namesimple as partnerCompaniesName,
  174. iac.id as subOrderId,
  175. iac.signing_time as signingTime,
  176. iac.pay_date as payDate,
  177. pa.agreement_code as agreementCode,
  178. pa.agreement_name as agreementName,
  179. pa.business_description as businessDescription,
  180. pa.job_description as jobDescription,
  181. pa.agreement_title as agreementTitle,
  182. pa.docking_person as dockingPerson,
  183. io.entry_status
  184. FROM
  185. ins_fee_audit ifa
  186. LEFT JOIN ins_orders io ON io.orderno = ifa.orderno
  187. LEFT JOIN ins_area_company iac ON iac.orderno = io.orderno
  188. AND iac.orderstatus = 3
  189. LEFT JOIN sys_user su ON su.id = io.userid
  190. LEFT JOIN sys_dept sd ON sd.id = su.dept_id
  191. LEFT JOIN sys_user su2 ON ifa.audituser = su2.id
  192. LEFT JOIN ptl_agreement pa ON pa.id = iac.agreement_id
  193. LEFT JOIN esm_ins_company eic ON eic.id = pa.partner_companies_id
  194. WHERE
  195. iac.id = ifa.ins_order_no
  196. AND iac.orderstatus = 3
  197. <if test="params.auditStatus != null and params.auditStatus != ''">
  198. and ifa.auditstatus = #{params.auditStatus}
  199. </if>
  200. <if test="params.quoteStartDateStr != null and params.quoteStartDateStr != '' and params.quoteEndDateStr != null and params.quoteEndDateStr != ''">
  201. and DATE_FORMAT(iac.createtime, '%Y-%m-%d') between #{params.quoteStartDateStr} AND
  202. #{params.quoteEndDateStr}
  203. </if>
  204. <if test="params.orderNo != null and params.orderNo != ''">
  205. AND iac.id= #{params.orderNo}
  206. </if>
  207. <if test="params.licenseNo != null and params.licenseNo != ''">
  208. AND io.licenseno = #{params.licenseNo}
  209. </if>
  210. <if test="params.frameNo != null and params.frameNo != ''">
  211. AND io.frameno = #{params.frameNo}
  212. </if>
  213. <if test="params.insuredName != null and params.insuredName != ''">
  214. AND json_extract(io.insureinfo, '$.name') = #{params.insuredName}
  215. </if>
  216. <if test="params.companyId != null and params.companyId != ''">
  217. AND io.company_id = #{params.companyId}
  218. </if>
  219. <if test="params.engineNo != null and params.engineNo != ''">
  220. and JSON_EXTRACT( io.carinfo, '$.engineNo' ) = #{params.engineNo}
  221. </if>
  222. <if test="params.riskCode != null and params.riskCode != ''">
  223. and iac.product = #{params.riskCode}
  224. </if>
  225. <if test="params.attachStartDateStr != null and params.attachStartDateStr != '' and params.attachStartDateStr != null and params.attachStartDateStr != '' ">
  226. and ((
  227. DATE_FORMAT(iac.jq_start_date, '%Y-%m-%d') BETWEEN #{params.attachStartDateStr}
  228. AND #{params.attachEndDateStr}
  229. )
  230. OR ( DATE_FORMAT(iac.sy_start_date, '%Y-%m-%d') BETWEEN #{params.attachStartDateStr} AND
  231. #{params.attachEndDateStr} )
  232. )
  233. </if>
  234. <if test="params.provinceId != null and params.provinceId != ''">
  235. and io.deptid like "${params.provinceId}%"
  236. </if>
  237. <if test="params.problemOrder != null and params.problemOrder != ''">
  238. and iac.problem_order like "${params.problemOrder}%"
  239. </if>
  240. <if test="params.cityId != null and params.cityId != ''">
  241. and io.deptid like "${params.cityId}%"
  242. </if>
  243. <if test="params.countyId != null and params.countyId != ''">
  244. and io.deptid like "${params.countyId}%"
  245. </if>
  246. <if test="params.houseId != null and params.houseId != ''">
  247. and io.deptid like "${params.houseId}%"
  248. </if>
  249. <if test="params.operatorId != null and params.operatorId != ''">
  250. and io.userid = #{params.operatorId}
  251. </if>
  252. <if test="params.operatorName != null and params.operatorName != ''">
  253. and io.username = #{params.operatorName}
  254. </if>
  255. <if test="params.auditId != null and params.auditId != ''">
  256. and iac.new_operator_id = #{params.auditId}
  257. </if>
  258. <if test="params.agreeId != null and params.agreeId != ''">
  259. and iac.agreement_id = #{params.agreeId}
  260. </if>
  261. <if test="params.managementSource != null and params.managementSource != ''">
  262. and sd.management_source = #{params.managementSource}
  263. </if>
  264. <if test="params.signStartDateStr != null and params.signStartDateStr != '' and params.signEndDateStr != null and params.signEndDateStr != ''">
  265. and DATE_FORMAT(iac.signing_time, '%Y-%m-%d') between #{params.signStartDateStr} AND
  266. #{params.signEndDateStr}
  267. </if>
  268. <if test="params.payStartDateStr != null and params.payStartDateStr != '' and params.payEndDateStr != null and params.payEndDateStr != ''">
  269. and iac.pay_date between #{params.payStartDateStr} AND #{params.payEndDateStr}
  270. </if>
  271. <if test="params.isExternal != null and params.isExternal != ''">
  272. and io.is_external = #{params.isExternal}
  273. </if>
  274. <if test="params.jqPolicyNo != null and params.jqPolicyNo != ''">
  275. and iac.jqpolicyno = #{params.jqPolicyNo}
  276. </if>
  277. <if test="params.syPolicyNo != null and params.syPolicyNo != ''">
  278. and iac.sypolicyno = #{params.syPolicyNo}
  279. </if>
  280. <if test="params.noPolicyNo != null and params.noPolicyNo != ''">
  281. and iac.cross_insurance like concat('%', #{params.noPolicyNo}, '%')
  282. </if>
  283. <if test="params.checkUser != null and params.checkUser != ''">
  284. and CASE ifa.audituser WHEN '自动审核' THEN ifa.audituser
  285. ELSE su2.name END = #{params.checkUser}
  286. </if>
  287. <if test="params.checkType != null and params.checkType != ''">
  288. and CASE ifa.audituser
  289. WHEN '自动审核' THEN '2'
  290. ELSE '1' END = #{params.checkType}
  291. </if>
  292. order by iac.createtime desc
  293. </select>
  294. <select id="getByUserId" resultType="com.ydtech.modules.order.entity.InsOrders">
  295. SELECT
  296. io.*,
  297. sd.management_source
  298. FROM
  299. ins_orders io left join sys_user su on su.id = io.userid left join sys_dept sd on sd.id = su.dept_id
  300. WHERE
  301. orderno IN (
  302. SELECT
  303. orderno
  304. FROM
  305. ins_area_company
  306. WHERE
  307. id IN ( SELECT ins_order_no FROM ins_fee_order_new WHERE id NOT IN ( SELECT ins_order_no FROM ins_fee_audit ) )
  308. AND orderstatus = 3
  309. )
  310. AND
  311. io.orderstatus= 3
  312. <if test="orderNo != null and orderNo != ''">
  313. AND orderno = #{orderNo}
  314. </if>
  315. <if test="licenseNo != null and licenseNo != ''">
  316. AND licenseno = #{licenseNo}
  317. </if>
  318. <if test="frameNo != null and frameNo != ''">
  319. AND frameno = #{frameNo}
  320. </if>
  321. <if test="userId != null and userId != ''">
  322. AND userid = #{userId}
  323. </if>
  324. <if test="insuredname != null and insuredname != ''">
  325. AND insuredname = #{insuredname}
  326. </if>
  327. <if test="startDateStr != null and startDateStr != ''">
  328. AND createtime BETWEEN #{startDateStr} and #{endDateStr}
  329. </if>
  330. </select>
  331. <select id="selectFirstPromotionBy" resultType="com.ydtech.modules.order.entity.InsOrders">
  332. SELECT
  333. sum(a.first_detail_premiums) as "willFirstPremiums"
  334. FROM
  335. ins_fee_order_new a
  336. LEFT JOIN ins_area_company iac on iac.id=a.ins_order_no
  337. left join ins_fee_audit iff on a.ins_order_no=iff.ins_order_no
  338. WHERE
  339. iff.auditstatus=0
  340. AND iac.orderstatus =3
  341. <if test="firstUserId != null and firstUserId != ''">
  342. AND a.first_level_user_id = #{firstUserId}
  343. </if>
  344. <if test="secondUserId != null and secondUserId != ''">
  345. AND a.two_level_user_id = #{secondUserId}
  346. </if>
  347. <if test="thirdUserId != null and thirdUserId != ''">
  348. AND a.three_level_user_id = #{thirdUserId}
  349. </if>
  350. <if test="id != null and id != ''">
  351. AND a.id = #{id}
  352. </if>
  353. </select>
  354. <select id="selectSecondPromotionBy" resultType="com.ydtech.modules.order.entity.InsOrders">
  355. SELECT
  356. sum( fee.p ) as "willFirstPremiums"
  357. FROM
  358. (
  359. SELECT
  360. sum( a.first_detail_premiums ) AS p
  361. FROM
  362. ins_fee_order_new a
  363. LEFT JOIN ins_area_company iac ON iac.id = a.ins_order_no
  364. left join ins_fee_audit iff on a.ins_order_no=iff.ins_order_no
  365. <where>
  366. iff.auditstatus=0
  367. and iac.orderstatus = '3'
  368. <if test="userId!=null and userId!= ''">
  369. AND a.first_level_user_id = #{userId}
  370. </if>
  371. <if test="id != null and id!=''">
  372. AND a.id =#{id}
  373. </if>
  374. </where>
  375. UNION
  376. SELECT
  377. sum( a.third_detail_premiums ) AS p
  378. FROM
  379. ins_fee_order_new a
  380. LEFT JOIN ins_area_company iac ON iac.id = a.ins_order_no
  381. left join ins_fee_audit iff on a.ins_order_no=iff.ins_order_no
  382. <where>
  383. iff.auditstatus=0
  384. and iac.orderstatus = '3'
  385. <if test="userId!=null and userId!= ''">
  386. AND a.three_level_user_id = #{userId}
  387. </if>
  388. <if test="id != null and id!=''">
  389. AND a.id =#{id}
  390. </if>
  391. </where>
  392. UNION
  393. SELECT
  394. sum( a.second_detail_premiums ) AS p
  395. FROM
  396. ins_fee_order_new a
  397. LEFT JOIN ins_area_company iac ON iac.id = a.ins_order_no
  398. left join ins_fee_audit iff on a.ins_order_no=iff.ins_order_no
  399. <where>
  400. iff.auditstatus=0
  401. and iac.orderstatus = '3'
  402. <if test="userId!=null and userId!= ''">
  403. AND a.two_level_user_id = #{userId}
  404. </if>
  405. <if test="id != null and id!=''">
  406. AND a.id =#{id}
  407. </if>
  408. </where>
  409. ) AS fee
  410. </select>
  411. <select id="selectThirdPromotionBy" resultType="com.ydtech.modules.order.entity.InsOrders">
  412. SELECT
  413. sum(a.third_detail_premiums) as "willThreePremiums"
  414. FROM
  415. ins_fee_order_new a
  416. LEFT JOIN ins_area_company iac on iac.id=a.ins_order_no
  417. left join ins_fee_audit iff on a.ins_order_no=iff.ins_order_no
  418. WHERE
  419. iff.auditstatus=0
  420. AND iac.orderstatus =3
  421. <if test="firstUserId != null and firstUserId != ''">
  422. AND a.first_level_user_id = #{firstUserId}
  423. </if>
  424. <if test="secondUserId != null and secondUserId != ''">
  425. AND a.two_level_user_id = #{secondUserId}
  426. </if>
  427. <if test="thirdUserId != null and thirdUserId != ''">
  428. AND a.three_level_user_id = #{thirdUserId}
  429. </if>
  430. <if test="id != null and id != ''">
  431. AND a.id = #{id}
  432. </if>
  433. </select>
  434. <select id="getAlreadyAuditOrders" resultType="com.ydtech.modules.order.entity.InsOrders">
  435. SELECT
  436. io.*,
  437. sd.management_source,
  438. su2.name AS auditUser,
  439. ifa.audittime as auditTime
  440. FROM
  441. ins_orders io
  442. LEFT JOIN ins_fee_audit ifa ON ifa.orderno = io.orderno
  443. LEFT JOIN sys_user su ON su.id = io.userid
  444. LEFT JOIN sys_dept sd ON sd.id = su.dept_id
  445. LEFT JOIN sys_user su2 on ifa.audituser = su2.id
  446. WHERE
  447. io.orderno IN (
  448. SELECT
  449. orderno
  450. FROM
  451. ins_area_company
  452. WHERE
  453. id IN (
  454. SELECT
  455. ifon.ins_order_no
  456. FROM
  457. ins_fee_order_new ifon
  458. RIGHT JOIN ins_fee_audit ifa ON ifon.ins_order_no = ifa.ins_order_no
  459. WHERE
  460. ifa.auditstatus = #{params.auditStatus}
  461. )
  462. )
  463. AND orderstatus = 3
  464. <!-- <if test="params.orderNo != null and params.orderNo != ''">-->
  465. <!-- AND orderno = #{params.orderNo}-->
  466. <!-- </if>-->
  467. <if test="params.licenseNo != null and params.licenseNo != ''">
  468. AND licenseno = #{params.licenseNo}
  469. </if>
  470. <if test="params.frameNo != null and params.frameNo != ''">
  471. AND frameno = #{params.frameNo}
  472. </if>
  473. <if test="params.insuredName != null and params.insuredName != ''">
  474. AND insuredname = #{params.insuredName}
  475. </if>
  476. <if test="params.companyId != null and params.companyId != ''">
  477. AND company_id = #{params.companyId}
  478. </if>
  479. <if test="params.startDateStr != null and params.startDateStr != ''">
  480. AND createtime BETWEEN #{params.startDateStr} and #{params.endDateStr}
  481. </if>
  482. </select>
  483. <select id="selectListByDateStr" resultType="com.ydtech.modules.order.entity.InsAreaCompany">
  484. -- 查询订单信息
  485. SELECT
  486. iac.*
  487. FROM
  488. ins_area_company iac
  489. left JOIN ins_orders AS io ON io.orderno = iac.orderno
  490. WHERE
  491. 1=1
  492. <if test="dateStr != null and dateStr != ''">
  493. AND DATE_FORMAT(io.createtime, '%Y-%m') =#{dateStr}
  494. </if>
  495. </select>
  496. <select id="selectListById" resultMap="BaseResultMap">
  497. SELECT
  498. iac.*
  499. FROM
  500. ins_area_company iac
  501. WHERE
  502. 1=1
  503. <if test="id != null and id != ''">
  504. AND iac.id =#{id}
  505. </if>
  506. </select>
  507. <select id="selectSecondPromotionByNew" resultType="com.ydtech.modules.order.entity.InsOrders">
  508. SELECT
  509. sum( fee.p ) as "willFirstPremiums"
  510. FROM
  511. (
  512. SELECT
  513. sum( a.first_detail_premiums ) AS p
  514. FROM
  515. ins_fee_order_new a
  516. LEFT JOIN ins_area_company iac ON iac.id = a.ins_order_no
  517. left join ins_fee_audit iff on a.ins_order_no=iff.ins_order_no
  518. <where>
  519. <choose>
  520. <when test='type == "1"'>
  521. iff.auditstatus=0
  522. </when>
  523. <otherwise>
  524. iff.auditstatus=1
  525. </otherwise>
  526. </choose>
  527. and iac.orderstatus = '3'
  528. <if test="userId!=null and userId!= ''">
  529. AND a.first_level_user_id = #{userId}
  530. </if>
  531. <if test="id != null and id!=''">
  532. AND a.id =#{id}
  533. </if>
  534. </where>
  535. UNION
  536. SELECT
  537. sum( a.third_detail_premiums ) AS p
  538. FROM
  539. ins_fee_order_new a
  540. LEFT JOIN ins_area_company iac ON iac.id = a.ins_order_no
  541. left join ins_fee_audit iff on a.ins_order_no=iff.ins_order_no
  542. <where>
  543. <choose>
  544. <when test='type == "1"'>
  545. iff.auditstatus=0
  546. </when>
  547. <otherwise>
  548. iff.auditstatus=1
  549. </otherwise>
  550. </choose>
  551. and iac.orderstatus = '3'
  552. <if test="userId!=null and userId!= ''">
  553. AND a.three_level_user_id = #{userId}
  554. </if>
  555. <if test="id != null and id!=''">
  556. AND a.id =#{id}
  557. </if>
  558. </where>
  559. UNION
  560. SELECT
  561. sum( a.second_detail_premiums ) AS p
  562. FROM
  563. ins_fee_order_new a
  564. LEFT JOIN ins_area_company iac ON iac.id = a.ins_order_no
  565. left join ins_fee_audit iff on a.ins_order_no=iff.ins_order_no
  566. <where>
  567. <choose>
  568. <when test='type == "1"'>
  569. iff.auditstatus=0
  570. </when>
  571. <otherwise>
  572. iff.auditstatus=1
  573. </otherwise>
  574. </choose>
  575. and iac.orderstatus = '3'
  576. <if test="userId!=null and userId!= ''">
  577. AND a.two_level_user_id = #{userId}
  578. </if>
  579. <if test="id != null and id!=''">
  580. AND a.id =#{id}
  581. </if>
  582. </where>
  583. ) AS fee
  584. </select>
  585. <select id="getSubOrderDetails" resultType="com.ydtech.modules.admin.model.vo.SubOrder">
  586. SELECT
  587. iac.id as subOrderId,
  588. iac.signing_time as signingTime,
  589. iac.jqpremium as jqpremium,
  590. iac.sypremium as sypremium,
  591. iac.jypremium as jypremium,
  592. io.licenseno as licenseno,
  593. io.userid as userId
  594. FROM
  595. ins_area_company iac
  596. LEFT JOIN ins_orders AS io ON io.orderno = iac.orderno
  597. WHERE
  598. iac.id=#{subOrderId}
  599. </select>
  600. <select id="premiumReportYear" resultType="com.ydtech.modules.admin.model.dto.PremiumReportDto">
  601. SELECT
  602. CONCAT(YEAR(iac.createtime),'-',LPAD(MONTH(iac.createtime), 2, '0')) reportDate,
  603. sum(jqpremium) jqpremium,
  604. sum(sypremium) sypremium,
  605. sum(sumpremium) sumpremium
  606. FROM
  607. ins_area_company iac left join ins_orders io on iac.orderno=io.orderno
  608. WHERE
  609. iac.orderstatus = 3 and
  610. iac.createtime &gt;= #{beginTime} and iac.createtime &lt;= #{endTime}
  611. and io.userid=#{userId}
  612. GROUP BY CONCAT(YEAR(iac.createtime),'-',LPAD(MONTH(iac.createtime), 2, '0'))
  613. </select>
  614. <select id="premiumReportMonth" resultType="com.ydtech.modules.admin.model.dto.PremiumReportDto">
  615. SELECT
  616. CONCAT(YEAR(iac.createtime),'-',LPAD(MONTH(iac.createtime), 2, '0'),'-',LPAD(Day(iac.createtime), 2, '0')) reportDate,
  617. sum(jqpremium) jqpremium,
  618. sum(sypremium) sypremium,
  619. sum(sumpremium) sumpremium
  620. FROM
  621. ins_area_company iac left join ins_orders io on iac.orderno=io.orderno
  622. WHERE
  623. iac.orderstatus = 3 and
  624. iac.createtime &gt;= #{beginTime} and iac.createtime &lt;= #{endTime}
  625. and io.userid=#{userId}
  626. GROUP BY CONCAT(YEAR(iac.createtime),'-',LPAD(MONTH(iac.createtime), 2, '0'),'-',LPAD(Day(iac.createtime), 2, '0'))
  627. </select>
  628. <select id="premiumReportDay" resultType="com.ydtech.modules.admin.model.dto.PremiumReportDto">
  629. SELECT
  630. CONCAT(YEAR ( iac.createtime ),'-',LPAD( MONTH ( iac.createtime ), 2, '0' ),'-',LPAD( DAY ( iac.createtime ), 2, '0' ),' ',LPAD( HOUR ( iac.createtime ), 2, '0' ))
  631. reportDate,
  632. sum( jqpremium ) jqpremium,
  633. sum( sypremium ) sypremium,
  634. sum( sumpremium ) sumpremium
  635. FROM
  636. ins_area_company iac left join ins_orders io on iac.orderno=io.orderno
  637. WHERE
  638. iac.orderstatus = 3 and
  639. iac.createtime &gt;= #{beginTime} and iac.createtime &lt;= #{endTime}
  640. and io.userid=#{userId}
  641. GROUP BY CONCAT(YEAR ( iac.createtime ),'-',LPAD( MONTH ( iac.createtime ), 2, '0' ),'-',LPAD( DAY ( iac.createtime ), 2, '0' ),' ',LPAD( HOUR ( iac.createtime ), 2, '0' ))
  642. </select>
  643. <select id="getAllpremium" resultType="com.ydtech.modules.admin.model.dto.AllpremiumDto">
  644. SELECT
  645. ifnull(sum( iac.jqpremium + iac.sypremium + iac.jypremium ),0) as sumPremium,
  646. count( 0 ) as sumCount
  647. FROM
  648. ins_area_company iac left join ins_orders io on iac.orderno=io.orderno
  649. WHERE
  650. iac.orderstatus = 3
  651. and io.userid=#{userId}
  652. AND YEAR (iac.createtime) = #{year}
  653. </select>
  654. <select id="getRejectOrder" resultType="com.ydtech.modules.order.entity.InsAreaCompany">
  655. select
  656. iac.id,
  657. iac.orderno,
  658. iac.agreement_id,
  659. iac.jqpremium,
  660. iac.sypremium,
  661. iac.jypremium,
  662. iac.taxamount,
  663. iac.sumpremium,
  664. io.licenseno,
  665. ifa.audittime,
  666. ifa.audituser as auditname,
  667. ifa.rejectinfo,
  668. "1" as orderExternalStatus
  669. FROM
  670. ins_fee_audit ifa
  671. LEFT JOIN
  672. ins_area_company iac on iac.id = ifa.ins_order_no
  673. LEFT JOIN
  674. ins_orders io on iac.orderno = io.orderno
  675. left join
  676. sys_user su on su.id= ifa.audituser
  677. WHERE
  678. iac.operator_id = #{userId}
  679. AND
  680. ifa.auditstatus = 2 and IFNULL(iac.del_flag,'') != '0'
  681. <if test="vo.id != null and vo.id!=''">
  682. and iac.id = #{vo.id}
  683. </if>
  684. <if test="vo.licenseno != null and vo.licenseno!='' ">
  685. and io.licenseno like CONCAT('%', #{vo.licenseno}, '%')
  686. </if>
  687. <if test="vo.auditname != null and vo.auditname!='' ">
  688. and su.name like CONCAT('%', #{vo.auditname}, '%')
  689. </if>
  690. </select>
  691. <select id="queryBusinessDataPage"
  692. resultType="com.ydtech.modules.admin.model.report.opetationData.BusinessDataDto">
  693. SELECT
  694. <if test="flag != null and flag!='' and flag='1'">
  695. o.userid as userId,
  696. o.username as userName,
  697. </if>
  698. sum( iac.sumpremium ) as signeSumPremiumAmount,
  699. sum( iac.jqpremium ) as jqPremiumAmount,
  700. sum( iac.sypremium ) as syPremiumAmount,
  701. sum( iac.taxamount ) as taxAmount,
  702. sum( ion.no_premium ) as fcFeeAmount
  703. FROM
  704. ins_area_company iac
  705. LEFT JOIN ins_orders o ON iac.orderno = o.orderno
  706. LEFT JOIN ins_fee_order_new ion ON iac.id = ion.ins_order_no
  707. where iac.orderstatus = 3 and ion.id is not null
  708. <if test="userList != null and userList.size()>0 ">
  709. and o.userid IN
  710. <foreach item="item" collection="userList" open="(" separator="," close=")">
  711. #{item}
  712. </foreach>
  713. </if>
  714. <if test="flag != null and flag!='' and flag='1'">
  715. group by o.userid,o.username
  716. </if>
  717. </select>
  718. <select id="queryQuotationSubOrderCountDataPage"
  719. resultType="com.ydtech.modules.admin.model.report.opetationData.QuotationCountDataDto">
  720. SELECT
  721. <if test="flag != null and flag!='' and flag='1'">
  722. o.userid as userId,
  723. o.username as userName,
  724. </if>
  725. iac.orderstatus as orderStatus
  726. FROM
  727. ins_area_company iac
  728. LEFT JOIN ins_orders o ON iac.orderno = o.orderno
  729. where (iac.orderstatus = 0 or iac.orderstatus = 2 or iac.orderstatus = 3 )
  730. <if test="userList != null and userList.size()>0 ">
  731. and o.userid IN
  732. <foreach item="item" collection="userList" open="(" separator="," close=")">
  733. #{item}
  734. </foreach>
  735. </if>
  736. <if test="flag != null and flag!='' and flag='1'">
  737. group by o.userid,o.username,iac.orderstatus
  738. </if>
  739. </select>
  740. <select id="queryQuotationOrderCountDataPage"
  741. resultType="com.ydtech.modules.admin.model.report.opetationData.QuotationCountDataDto">
  742. SELECT
  743. a.userId as userId,
  744. a.userName as userName,
  745. b.qutationCount AS insOrderQutationCount,
  746. b.qutationInsureCount as insOrderQutationInsureCount,
  747. b.closeRate AS insOrderCloseRate as insOrderCloseRate,
  748. a.qutationCount as subOrderQutationCount,
  749. a.underwritingCount as subOrderUnderwritingCount,
  750. a.qutationInsureCount as subOrderQutationInsureCount,
  751. a.passRate as subOrderCloseRate,
  752. a.closeRate as subOrderPassRate,
  753. a.contributionRate as subOrderContributionRate
  754. FROM
  755. (
  756. SELECT
  757. inso.userid AS userId,
  758. inso.username AS userName,
  759. COUNT( CASE WHEN iac.orderstatus = 0 THEN 1 END ) AS qutationCount,
  760. COUNT( CASE WHEN iac.orderstatus = 2 THEN 1 END ) AS underwritingCount,
  761. COUNT( CASE WHEN iac.orderstatus = 3 THEN 1 END ) AS qutationInsureCount,
  762. COUNT( CASE WHEN iac.orderstatus = 0 THEN 1 END )/ count( iac.orderstatus ) AS passRate,
  763. COUNT( CASE WHEN iac.orderstatus = 3 THEN 1 END )/ count( iac.orderstatus ) AS closeRate,
  764. COUNT( CASE WHEN iac.orderstatus = 3 THEN 1 END )/ COUNT( CASE WHEN iac.orderstatus = 2 THEN 1 END ) AS contributionRate
  765. FROM
  766. ins_area_company iac
  767. LEFT JOIN ins_orders inso ON iac.orderno = inso.orderno
  768. <where>
  769. <if test="userList != null and userList.size()>0 ">
  770. and o.userid IN
  771. <foreach item="item" collection="userList" open="(" separator="," close=")">
  772. #{item}
  773. </foreach>
  774. </if>
  775. </where>
  776. GROUP BY
  777. inso.userid,
  778. inso.username
  779. ) a
  780. LEFT JOIN (
  781. SELECT
  782. inso.userid AS userId,
  783. inso.username AS userName,
  784. count( inso.orderstatus ) AS qutationCount,
  785. count( CASE WHEN inso.orderstatus = 3 THEN 1 END ) AS qutationInsureCount,
  786. COUNT( CASE WHEN inso.orderstatus = 3 THEN 1 END )/ count( inso.orderstatus ) AS closeRate
  787. FROM
  788. ins_orders inso
  789. <where>
  790. <if test="userList != null and userList.size()>0 ">
  791. and o.userid IN
  792. <foreach item="item" collection="userList" open="(" separator="," close=")">
  793. #{item}
  794. </foreach>
  795. </if>
  796. </where>
  797. GROUP BY
  798. inso.userid,
  799. inso.username
  800. ) b ON a.userId = b.userId
  801. </select>
  802. <select id="queryCompanyPremiumDataPage"
  803. resultType="com.ydtech.modules.admin.model.report.company.CompanyPremiumDataDto">
  804. SELECT
  805. agree.insurance_company_id AS companyId,
  806. agree.insurance_company AS companyName,
  807. agree.partner_companies_id AS parterCompanyId,
  808. ins.NAME AS parterCompanyName,
  809. sum( iac.sumpremium ) AS signeSumPremiumAmount
  810. FROM
  811. ins_area_company iac
  812. LEFT JOIN ptl_agreement agree ON iac.agreement_id = agree.id
  813. LEFT JOIN esm_ins_company ins ON agree.partner_companies_id = ins.id
  814. WHERE
  815. iac.orderstatus = 3
  816. and
  817. agree.id is not null
  818. <if test="vo.companyId != null and vo.companyId!='' ">
  819. agree.insurance_company_id = #{vo.companyId}
  820. </if>
  821. <if test="vo.parterCompanyId != null and vo.parterCompanyId!='' ">
  822. agree.insurance_company_id = #{vo.parterCompanyId}
  823. </if>
  824. GROUP BY
  825. agree.insurance_company_id,
  826. agree.insurance_company,
  827. agree.partner_companies_id,
  828. ins.NAME
  829. </select>
  830. <select id="queryCompanyQutationCountDataPage"
  831. resultType="com.ydtech.modules.admin.model.report.company.CompanyQutationCountDataDto">
  832. SELECT
  833. a.* ,
  834. (select ins.namesimple from esm_ins_company
  835. ins where a.parterCompanyId = ins.id) as "parterCompanyName"
  836. FROM
  837. (
  838. SELECT
  839. agree.insurance_company AS companyName,
  840. agree.partner_companies_id AS parterCompanyId,
  841. iac.company_id as "companyId",
  842. count( iac.orderstatus ) AS qutationCount,
  843. count( iac.id ) AS allNumber,
  844. count( CASE WHEN iac.orderstatus != '10' THEN 1 END ) AS orderSuccessNumber,
  845. count( CASE WHEN iac.orderstatus != '10' THEN 1 END ) / count( iac.id ) as "orderSuccessNumberRate",
  846. count( CASE WHEN iac.orderstatus = '10' THEN 1 END ) AS areaCompanyErrNumber,
  847. COUNT( CASE WHEN iac.orderstatus = '2' THEN 1 END ) + COUNT( CASE WHEN iac.orderstatus = 3 THEN 1 END ) AS underwritingCount,
  848. COUNT( CASE WHEN iac.orderstatus = '3' THEN 1 END ) AS qutationInsureCount,
  849. (COUNT( CASE WHEN iac.orderstatus = '2' THEN 1 END ) + COUNT( CASE WHEN iac.orderstatus = 3 THEN 1 END )) / count( iac.orderstatus ) AS passRate,
  850. 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,
  851. COUNT( CASE WHEN iac.orderstatus = '3' THEN 1 END ) / count( iac.orderstatus ) AS contributionRate,
  852. COUNT(CASE WHEN agree.audit_type ='1' and ifa.auditstatus =1 and iac.orderstatus =3 THEN 1 END) as "numberManual"
  853. FROM
  854. ins_area_company iac
  855. LEFT JOIN ptl_agreement agree ON iac.agreement_id = agree.id
  856. LEFT JOIN ins_orders io ON iac.orderno = io.orderno
  857. LEFT JOIN sys_dept sd ON sd.id = io.deptid
  858. LEFT JOIN ins_fee_audit ifa on ifa.ins_order_no =iac.id
  859. WHERE
  860. agree.id IS NOT NULL
  861. <if test="vo.companyId != null and vo.companyId!='' ">
  862. AND agree.insurance_company_id = #{vo.companyId}
  863. </if>
  864. <if test="vo.parterCompanyId != null and vo.parterCompanyId!='' ">
  865. AND agree.partner_companies_id = #{vo.parterCompanyId}
  866. </if>
  867. <if test="vo.beginDate != null and vo.beginDate!='' and vo.endDate != null and vo.endDate!=''">
  868. AND iac.createtime BETWEEN #{vo.beginDate} AND #{vo.endDate}
  869. </if>
  870. <if test="vo.managementSource != null and vo.managementSource!=''">
  871. AND sd.management_source =#{vo.managementSource}
  872. </if>
  873. <if test="vo.userId != null and vo.userId !=''">
  874. AND io.userid =#{vo.userId}
  875. </if>
  876. <if test="vo.deptId != null and vo.deptId !=''">
  877. AND io.deptId like concat('%',#{vo.deptId},'%')
  878. </if>
  879. <if test="vo.deptIds != null and vo.deptIds != '' and vo.deptIds.size() > 0">
  880. AND sd.id in
  881. <foreach collection="vo.deptIds" item="item" open="(" separator="," close=")">
  882. #{item}
  883. </foreach>
  884. </if>
  885. <if test="vo.userIds != null and vo.userIds != '' and vo.userIds.size() > 0">
  886. AND io.userid in
  887. <foreach collection="taskStatisticsVo.userIds" item="item" open="(" separator="," close=")">
  888. #{item}
  889. </foreach>
  890. </if>
  891. GROUP BY
  892. agree.insurance_company,
  893. iac.company_id,
  894. agree.partner_companies_id
  895. ) a
  896. order by a.parterCompanyId
  897. </select>
  898. <select id="getInsAreaCompanyError"
  899. resultType="com.ydtech.modules.admin.model.report.company.CompanyQutationCountDataDto">
  900. SELECT
  901. count(iace.id) as "areaCompanyErrNumber"
  902. FROM
  903. ins_area_company_error iace
  904. LEFT JOIN ptl_agreement agree ON iace.agreement_id = agree.id
  905. <where>
  906. 1=1
  907. <if test="vo.companyId != null and vo.companyId!='' ">
  908. AND agree.insurance_company_id = #{vo.companyId}
  909. </if>
  910. <if test="vo.parterCompanyId != null and vo.parterCompanyId!='' ">
  911. AND agree.partner_companies_id = #{vo.parterCompanyId}
  912. </if>
  913. <if test="vo.userId != null and vo.userId!=''">
  914. AND iace.user_id =#{vo.userId}
  915. </if>
  916. <if test="vo.beginDate != null and vo.beginDate!='' and vo.endDate != null and vo.endDate!=''">
  917. AND iace.create_time BETWEEN #{vo.beginDate} AND #{vo.endDate}
  918. </if>
  919. <if test="vo.deptIds != null and vo.deptIds != '' and vo.deptIds.size() > 0">
  920. AND iace.dept_id in
  921. <foreach collection="vo.deptIds" item="item" open="(" separator="," close=")">
  922. #{item}
  923. </foreach>
  924. </if>
  925. <if test="vo.deptId != null and vo.deptId !=''">
  926. AND iace.dept_id like concat('%',#{vo.deptId},'%')
  927. </if>
  928. <if test="vo.userIds != null and vo.userIds != '' and vo.userIds.size() > 0">
  929. AND iace.user_id in
  930. <foreach collection="taskStatisticsVo.userIds" item="item" open="(" separator="," close=")">
  931. #{item}
  932. </foreach>
  933. </if>
  934. </where>
  935. </select>
  936. <select id="queryCompanyQutationCountDataPageTotal"
  937. resultType="java.lang.Long">
  938. SELECT
  939. count(0)
  940. FROM
  941. (
  942. SELECT
  943. agree.partner_companies_id
  944. FROM
  945. ins_area_company iac
  946. LEFT JOIN ptl_agreement agree ON iac.agreement_id = agree.id
  947. LEFT JOIN ins_orders io ON iac.orderno = io.orderno
  948. LEFT JOIN sys_dept sd ON sd.id = io.deptid
  949. WHERE
  950. agree.id IS NOT NULL
  951. <if test="vo.companyId != null and vo.companyId!='' ">
  952. AND agree.insurance_company_id = #{vo.companyId}
  953. </if>
  954. <if test="vo.parterCompanyId != null and vo.parterCompanyId!='' ">
  955. AND agree.partner_companies_id = #{vo.parterCompanyId}
  956. </if>
  957. <if test="vo.beginDate != null and vo.beginDate!='' and vo.endDate != null and vo.endDate!=''">
  958. AND iac.createtime BETWEEN #{vo.beginDate} AND #{vo.endDate}
  959. </if>
  960. <if test="vo.managementSource != null and vo.managementSource!=''">
  961. AND sd.management_source =#{vo.managementSource}
  962. </if>
  963. <if test="vo.userId != null and vo.userId !=''">
  964. AND io.userid =#{vo.userId}
  965. </if>
  966. <if test="vo.deptId != null and vo.deptId !=''">
  967. AND io.deptId like concat('%',#{vo.deptId},'%')
  968. </if>
  969. <if test="vo.deptIds != null and vo.deptIds != '' and vo.deptIds.size() > 0">
  970. AND sd.id in
  971. <foreach collection="vo.deptIds" item="item" open="(" separator="," close=")">
  972. #{item}
  973. </foreach>
  974. </if>
  975. <if test="vo.userIds != null and vo.userIds != '' and vo.userIds.size() > 0">
  976. AND io.userid in
  977. <foreach collection="taskStatisticsVo.userIds" item="item" open="(" separator="," close=")">
  978. #{item}
  979. </foreach>
  980. </if>
  981. GROUP BY
  982. agree.partner_companies_id
  983. ) a
  984. </select>
  985. <select id="getStageOrder" resultType="com.ydtech.modules.order.entity.InsAreaCompany">
  986. select
  987. iac.id,
  988. iac.orderno,
  989. iac.agreement_id,
  990. iac.jqpremium,
  991. iac.sypremium,
  992. iac.jypremium,
  993. iac.taxamount,
  994. iac.sumpremium,
  995. io.licenseno,
  996. iac.createtime,
  997. "0" as orderExternalStatus
  998. FROM
  999. ins_area_company iac
  1000. LEFT JOIN
  1001. ins_orders io on iac.orderno = io.orderno
  1002. left join ptl_agreement agree on iac.agreement_id =agree.id
  1003. WHERE
  1004. iac.operator_id = #{userId}
  1005. AND
  1006. iac.orderstatus = 0
  1007. and agree.is_external =1
  1008. <if test="vo.id != null and vo.id!='' ">
  1009. and iac.id = #{vo.id}
  1010. </if>
  1011. <if test="vo.licenseno != null and vo.licenseno!='' ">
  1012. and io.licenseno like CONCAT('%', #{vo.licenseno}, '%')
  1013. </if>
  1014. </select>
  1015. <select id="queryPageTaskStatistics" resultType="com.ydtech.modules.admin.model.dto.TaskStatisticsDto">
  1016. select a.*, su.name as "userName",
  1017. inf.url as "logo",
  1018. sui.sex as "sex",
  1019. su.leader_name as "leaderName",
  1020. su2.mobile as "leaderMobile"
  1021. from (
  1022. SELECT
  1023. sd.NAME AS "deptName",
  1024. io.userid AS "userId",
  1025. sd.parent_id as "deptId",
  1026. sd.management_source as "managementSource",
  1027. COUNT( CASE WHEN iac.orderstatus = 0 THEN 1 END ) AS qutationCount,
  1028. COUNT( CASE WHEN iac.orderstatus = 2 THEN 1 END ) AS underwritingCount,
  1029. COUNT( CASE WHEN iac.orderstatus = 3 THEN 1 END ) AS qutationInsureCount,
  1030. COUNT( CASE WHEN iac.orderstatus = 4 THEN 1 END ) AS underwritingReturn,
  1031. COUNT( CASE WHEN iac.orderstatus = 2 THEN 1 END ) / COUNT( CASE WHEN iac.orderstatus = 0 THEN 1 END ) AS "passingRate",
  1032. COUNT( CASE WHEN iac.orderstatus = 3 THEN 1 END ) / COUNT( iac.orderstatus ) AS "closeRate",
  1033. (COUNT( CASE WHEN iac.orderstatus = 3 THEN 1 END ) + COUNT( CASE WHEN iac.orderstatus = 2 THEN 1 END ))/ COUNT( iac.orderstatus ) AS "contributionRate",
  1034. COUNT( CASE WHEN iac.orderstatus = 0 THEN 1 END ) / COUNT( iac.orderstatus ) AS "quotationRate",
  1035. COUNT(CASE WHEN io.order_source = 0 and iac.orderstatus = 0 THEN 1 END) as "pcOrderSource",
  1036. COUNT(CASE WHEN io.order_source = 1 and iac.orderstatus = 0 THEN 1 END) as "appOrderSource",
  1037. COUNT( CASE WHEN iac.orderstatus = 1 THEN 1 END ) AS "auditOrder"
  1038. FROM
  1039. ins_area_company iac
  1040. LEFT JOIN ins_orders io ON io.orderno = iac.orderno
  1041. LEFT JOIN sys_dept sd ON sd.id = io.deptid
  1042. <where>
  1043. sd.management_source = '1'
  1044. <if test="taskStatisticsVo.provinceId != null and taskStatisticsVo.provinceId != ''">
  1045. and io.deptid like "${taskStatisticsVo.provinceId}%"
  1046. </if>
  1047. <if test="taskStatisticsVo.cityId != null and taskStatisticsVo.cityId != ''">
  1048. and io.deptid like "${taskStatisticsVo.cityId}%"
  1049. </if>
  1050. <if test="taskStatisticsVo.countyId != null and taskStatisticsVo.countyId != ''">
  1051. and io.deptid like "${taskStatisticsVo.countyId}%"
  1052. </if>
  1053. <if test="taskStatisticsVo.houseId != null and taskStatisticsVo.houseId != ''">
  1054. and io.deptid like "${taskStatisticsVo.houseId}%"
  1055. </if>
  1056. <if test="taskStatisticsVo.userId != null and taskStatisticsVo.userId != ''">
  1057. and io.userid =#{taskStatisticsVo.userId}
  1058. </if>
  1059. <if test="taskStatisticsVo.createtimeStart !=null and taskStatisticsVo.createtimeStart != '' and taskStatisticsVo.createtimeEnd !=null and taskStatisticsVo.createtimeEnd != ''">
  1060. AND DATE_FORMAT( io.createtime, '%Y-%m-%d') BETWEEN #{taskStatisticsVo.createtimeStart} AND #{taskStatisticsVo.createtimeEnd}
  1061. </if>
  1062. <if test="taskStatisticsVo.beginDate !=null and taskStatisticsVo.beginDate != '' and taskStatisticsVo.endDate !=null and taskStatisticsVo.endDate != ''">
  1063. 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')
  1064. </if>
  1065. <if test="taskStatisticsVo.deptIds != null and taskStatisticsVo.deptIds != '' and taskStatisticsVo.deptIds.size() > 0">
  1066. AND sd.id in
  1067. <foreach collection="taskStatisticsVo.deptIds" item="item" open="(" separator="," close=")">
  1068. #{item}
  1069. </foreach>
  1070. </if>
  1071. <if test="taskStatisticsVo.userIds != null and taskStatisticsVo.userIds != '' and taskStatisticsVo.userIds.size() > 0">
  1072. AND io.userid in
  1073. <foreach collection="taskStatisticsVo.userIds" item="item" open="(" separator="," close=")">
  1074. #{item}
  1075. </foreach>
  1076. </if>
  1077. <if test="taskStatisticsVo.days !=null and taskStatisticsVo.days !='' ">
  1078. <choose>
  1079. <when test="taskStatisticsVo.days =='1'">
  1080. and io.createtime >= DATE_SUB(NOW(), INTERVAL 1 DAY)
  1081. </when>
  1082. <when test="taskStatisticsVo.days =='7'">
  1083. and io.createtime >= DATE_SUB(NOW(), INTERVAL 7 DAY)
  1084. </when>
  1085. <when test="taskStatisticsVo.days =='30'">
  1086. and io.createtime >= DATE_SUB(NOW(), INTERVAL 30 DAY)
  1087. </when>
  1088. </choose>
  1089. </if>
  1090. </where>
  1091. GROUP BY
  1092. io.userid,
  1093. sd.NAME,
  1094. sd.id,
  1095. sd.management_source
  1096. ) a
  1097. left join sys_user su on su.id =a.userId
  1098. LEFT JOIN ins_upload_files inf on su.head_sculpture =inf.id
  1099. LEFT JOIN sys_user_info sui on sui .id =su.id
  1100. LEFT JOIN sys_user su2 on su2.id =su.leader_id
  1101. <where>
  1102. <if test='taskStatisticsVo.userName !=null and taskStatisticsVo.userName!="" '>
  1103. and su.name like concat('%',#{taskStatisticsVo.userName},'%')
  1104. </if>
  1105. <if test='taskStatisticsVo.leaderId !=null and taskStatisticsVo.leaderId!="" '>
  1106. and su.leader_id =#{taskStatisticsVo.leaderId}
  1107. </if>
  1108. <if test='taskStatisticsVo.userId !=null and taskStatisticsVo.userId!="" '>
  1109. and su.id =#{taskStatisticsVo.userId}
  1110. </if>
  1111. </where>
  1112. </select>
  1113. <select id="queryPageElectric" resultType="com.ydtech.modules.admin.model.dto.TaskStatisticsDto">
  1114. select a.*, su.name as "userName",
  1115. inf.url as "logo",
  1116. sui.sex as "sex",
  1117. su.leader_name as "leaderName",
  1118. su2.mobile as "leaderMobile"
  1119. from (
  1120. SELECT
  1121. sd.NAME AS "deptName",
  1122. io.userid AS "userId",
  1123. sd.parent_id as "deptId",
  1124. sd.management_source as "managementSource",
  1125. COUNT( CASE WHEN iac.orderstatus = 0 THEN 1 END ) AS qutationCount,
  1126. COUNT( CASE WHEN iac.orderstatus = 2 THEN 1 END ) AS underwritingCount,
  1127. COUNT( CASE WHEN iac.orderstatus = 3 THEN 1 END ) AS qutationInsureCount,
  1128. COUNT( CASE WHEN iac.orderstatus = 4 THEN 1 END ) AS underwritingReturn,
  1129. COUNT( CASE WHEN iac.orderstatus = 2 THEN 1 END ) / COUNT( CASE WHEN iac.orderstatus = 0 THEN 1 END ) AS "passingRate",
  1130. COUNT( CASE WHEN iac.orderstatus = 3 THEN 1 END ) / COUNT( iac.orderstatus ) AS "closeRate",
  1131. (COUNT( CASE WHEN iac.orderstatus = 3 THEN 1 END ) + COUNT( CASE WHEN iac.orderstatus = 2 THEN 1 END ))/ COUNT( iac.orderstatus ) AS "contributionRate",
  1132. COUNT( CASE WHEN iac.orderstatus = 0 THEN 1 END ) / COUNT( iac.orderstatus ) AS "quotationRate",
  1133. COUNT(CASE WHEN io.order_source = 0 and iac.orderstatus = 0 THEN 1 END) as "pcOrderSource",
  1134. COUNT(CASE WHEN io.order_source = 1 and iac.orderstatus = 0 THEN 1 END) as "appOrderSource",
  1135. COUNT( CASE WHEN iac.orderstatus = 1 THEN 1 END ) AS "auditOrder"
  1136. FROM
  1137. ins_area_company iac
  1138. LEFT JOIN ins_orders io ON io.orderno = iac.orderno
  1139. LEFT JOIN sys_dept sd ON sd.id = io.deptid
  1140. <where>
  1141. sd.management_source = '3'
  1142. <if test="taskStatisticsVo.provinceId != null and taskStatisticsVo.provinceId != ''">
  1143. and io.deptid like "${taskStatisticsVo.provinceId}%"
  1144. </if>
  1145. <if test="taskStatisticsVo.cityId != null and taskStatisticsVo.cityId != ''">
  1146. and io.deptid like "${taskStatisticsVo.cityId}%"
  1147. </if>
  1148. <if test="taskStatisticsVo.countyId != null and taskStatisticsVo.countyId != ''">
  1149. and io.deptid like "${taskStatisticsVo.countyId}%"
  1150. </if>
  1151. <if test="taskStatisticsVo.houseId != null and taskStatisticsVo.houseId != ''">
  1152. and io.deptid like "${taskStatisticsVo.houseId}%"
  1153. </if>
  1154. <if test="taskStatisticsVo.userId != null and taskStatisticsVo.userId != ''">
  1155. and io.userid =#{taskStatisticsVo.userId}
  1156. </if>
  1157. <if test="taskStatisticsVo.createtimeStart !=null and taskStatisticsVo.createtimeStart != '' and taskStatisticsVo.createtimeEnd !=null and taskStatisticsVo.createtimeEnd != ''">
  1158. AND DATE_FORMAT( io.createtime, '%Y-%m-%d') BETWEEN #{taskStatisticsVo.createtimeStart} AND #{taskStatisticsVo.createtimeEnd}
  1159. </if>
  1160. <if test="taskStatisticsVo.beginDate !=null and taskStatisticsVo.beginDate != '' and taskStatisticsVo.endDate !=null and taskStatisticsVo.endDate != ''">
  1161. 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')
  1162. </if>
  1163. <if test="taskStatisticsVo.days !=null and taskStatisticsVo.days !='' ">
  1164. and iac.createtime >= DATE_SUB(NOW(), INTERVAL #{taskStatisticsVo.days} DAY)
  1165. </if>
  1166. <if test="taskStatisticsVo.deptIds != null and taskStatisticsVo.deptIds != '' and taskStatisticsVo.deptIds.size() > 0">
  1167. AND sd.id in
  1168. <foreach collection="taskStatisticsVo.deptIds" item="item" open="(" separator="," close=")">
  1169. #{item}
  1170. </foreach>
  1171. </if>
  1172. <if test="taskStatisticsVo.userIds != null and taskStatisticsVo.userIds != '' and taskStatisticsVo.userIds.size() > 0">
  1173. AND io.userid in
  1174. <foreach collection="taskStatisticsVo.userIds" item="item" open="(" separator="," close=")">
  1175. #{item}
  1176. </foreach>
  1177. </if>
  1178. <if test="taskStatisticsVo.days !=null and taskStatisticsVo.days !='' ">
  1179. <choose>
  1180. <when test="taskStatisticsVo.days =='1'">
  1181. and io.createtime >= DATE_SUB(NOW(), INTERVAL 1 DAY)
  1182. </when>
  1183. <when test="taskStatisticsVo.days =='7'">
  1184. and io.createtime >= DATE_SUB(NOW(), INTERVAL 7 DAY)
  1185. </when>
  1186. <when test="taskStatisticsVo.days =='30'">
  1187. and io.createtime >= DATE_SUB(NOW(), INTERVAL 30 DAY)
  1188. </when>
  1189. </choose>
  1190. </if>
  1191. </where>
  1192. GROUP BY
  1193. io.userid,
  1194. sd.NAME,
  1195. sd.id,
  1196. sd.management_source
  1197. ) a
  1198. left join sys_user su on su.id =a.userId
  1199. LEFT JOIN ins_upload_files inf on su.head_sculpture =inf.id
  1200. LEFT JOIN sys_user_info sui on sui .id =su.id
  1201. LEFT JOIN sys_user su2 on su2.id =su.leader_id
  1202. <where>
  1203. <if test='taskStatisticsVo.userName !=null and taskStatisticsVo.userName!="" '>
  1204. and su.name like concat('%',#{taskStatisticsVo.userName},'%')
  1205. </if>
  1206. <if test='taskStatisticsVo.leaderId !=null and taskStatisticsVo.leaderId!="" '>
  1207. and su.leader_id =#{taskStatisticsVo.leaderId}
  1208. </if>
  1209. <if test='taskStatisticsVo.userId !=null and taskStatisticsVo.userId!="" '>
  1210. and su.id =#{taskStatisticsVo.userId}
  1211. </if>
  1212. </where>
  1213. </select>
  1214. <select id="queryPageElectricTotal" resultType="java.lang.Long">
  1215. select count(0) from (
  1216. SELECT
  1217. io.userid
  1218. FROM
  1219. ins_area_company iac
  1220. LEFT JOIN ins_orders io ON io.orderno = iac.orderno
  1221. LEFT JOIN sys_dept sd ON sd.id = io.deptid
  1222. <where>
  1223. sd.management_source = '3'
  1224. <if test="taskStatisticsVo.provinceId != null and taskStatisticsVo.provinceId != ''">
  1225. and io.deptid like "${taskStatisticsVo.provinceId}%"
  1226. </if>
  1227. <if test="taskStatisticsVo.cityId != null and taskStatisticsVo.cityId != ''">
  1228. and io.deptid like "${taskStatisticsVo.cityId}%"
  1229. </if>
  1230. <if test="taskStatisticsVo.countyId != null and taskStatisticsVo.countyId != ''">
  1231. and io.deptid like "${taskStatisticsVo.countyId}%"
  1232. </if>
  1233. <if test="taskStatisticsVo.houseId != null and taskStatisticsVo.houseId != ''">
  1234. and io.deptid like "${taskStatisticsVo.houseId}%"
  1235. </if>
  1236. <if test="taskStatisticsVo.createtimeStart !=null and taskStatisticsVo.createtimeStart != '' and taskStatisticsVo.createtimeEnd !=null and taskStatisticsVo.createtimeEnd != ''">
  1237. AND DATE_FORMAT( io.createtime, '%Y-%m-%d') BETWEEN #{taskStatisticsVo.createtimeStart} AND #{taskStatisticsVo.createtimeEnd}
  1238. </if>
  1239. <if test="taskStatisticsVo.beginDate !=null and taskStatisticsVo.beginDate != '' and taskStatisticsVo.endDate !=null and taskStatisticsVo.endDate != ''">
  1240. 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')
  1241. </if>
  1242. <if test="taskStatisticsVo.days !=null and taskStatisticsVo.days !='' ">
  1243. and iac.createtime >= DATE_SUB(NOW(), INTERVAL #{taskStatisticsVo.days} DAY)
  1244. </if>
  1245. <if test="taskStatisticsVo.userId != null and taskStatisticsVo.userId != ''">
  1246. and io.userid =#{taskStatisticsVo.userId}
  1247. </if>
  1248. <if test="taskStatisticsVo.deptIds != null and taskStatisticsVo.deptIds != '' and taskStatisticsVo.deptIds.size() > 0">
  1249. AND sd.id in
  1250. <foreach collection="taskStatisticsVo.deptIds" item="item" open="(" separator="," close=")">
  1251. #{item}
  1252. </foreach>
  1253. </if>
  1254. <if test="taskStatisticsVo.userIds != null and taskStatisticsVo.userIds != '' and taskStatisticsVo.userIds.size() > 0">
  1255. AND io.userid in
  1256. <foreach collection="taskStatisticsVo.userIds" item="item" open="(" separator="," close=")">
  1257. #{item}
  1258. </foreach>
  1259. </if>
  1260. <if test="taskStatisticsVo.days !=null and taskStatisticsVo.days !='' ">
  1261. <choose>
  1262. <when test="taskStatisticsVo.days =='1'">
  1263. and io.createtime >= DATE_SUB(NOW(), INTERVAL 1 DAY)
  1264. </when>
  1265. <when test="taskStatisticsVo.days =='7'">
  1266. and io.createtime >= DATE_SUB(NOW(), INTERVAL 7 DAY)
  1267. </when>
  1268. <when test="taskStatisticsVo.days =='30'">
  1269. and io.createtime >= DATE_SUB(NOW(), INTERVAL 30 DAY)
  1270. </when>
  1271. </choose>
  1272. </if>
  1273. </where>
  1274. GROUP BY
  1275. io.userid
  1276. ) a
  1277. </select>
  1278. <select id="queryPageTaskStatisticsTotal" resultType="java.lang.Long">
  1279. select count(0) from (
  1280. SELECT
  1281. io.userid
  1282. FROM
  1283. ins_area_company iac
  1284. LEFT JOIN ins_orders io ON io.orderno = iac.orderno
  1285. LEFT JOIN sys_dept sd ON sd.id = io.deptid
  1286. <where>
  1287. sd.management_source = '1'
  1288. <if test="taskStatisticsVo.provinceId != null and taskStatisticsVo.provinceId != ''">
  1289. and io.deptid like "${taskStatisticsVo.provinceId}%"
  1290. </if>
  1291. <if test="taskStatisticsVo.cityId != null and taskStatisticsVo.cityId != ''">
  1292. and io.deptid like "${taskStatisticsVo.cityId}%"
  1293. </if>
  1294. <if test="taskStatisticsVo.countyId != null and taskStatisticsVo.countyId != ''">
  1295. and io.deptid like "${taskStatisticsVo.countyId}%"
  1296. </if>
  1297. <if test="taskStatisticsVo.houseId != null and taskStatisticsVo.houseId != ''">
  1298. and io.deptid like "${taskStatisticsVo.houseId}%"
  1299. </if>
  1300. <if test="taskStatisticsVo.createtimeStart !=null and taskStatisticsVo.createtimeStart != '' and taskStatisticsVo.createtimeEnd !=null and taskStatisticsVo.createtimeEnd != ''">
  1301. AND DATE_FORMAT( io.createtime, '%Y-%m-%d') BETWEEN #{taskStatisticsVo.createtimeStart} AND #{taskStatisticsVo.createtimeEnd}
  1302. </if>
  1303. <if test="taskStatisticsVo.beginDate !=null and taskStatisticsVo.beginDate != '' and taskStatisticsVo.endDate !=null and taskStatisticsVo.endDate != ''">
  1304. 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')
  1305. </if>
  1306. <if test="taskStatisticsVo.days !=null and taskStatisticsVo.days !='' ">
  1307. and iac.createtime >= DATE_SUB(NOW(), INTERVAL #{taskStatisticsVo.days} DAY)
  1308. </if>
  1309. <if test="taskStatisticsVo.userId != null and taskStatisticsVo.userId != ''">
  1310. and io.userid =#{taskStatisticsVo.userId}
  1311. </if>
  1312. <if test="taskStatisticsVo.deptIds != null and taskStatisticsVo.deptIds != '' and taskStatisticsVo.deptIds.size() > 0">
  1313. AND sd.id in
  1314. <foreach collection="taskStatisticsVo.deptIds" item="item" open="(" separator="," close=")">
  1315. #{item}
  1316. </foreach>
  1317. </if>
  1318. <if test="taskStatisticsVo.userIds != null and taskStatisticsVo.userIds != '' and taskStatisticsVo.userIds.size() > 0">
  1319. AND io.userid in
  1320. <foreach collection="taskStatisticsVo.userIds" item="item" open="(" separator="," close=")">
  1321. #{item}
  1322. </foreach>
  1323. </if>
  1324. <if test="taskStatisticsVo.days !=null and taskStatisticsVo.days !='' ">
  1325. <choose>
  1326. <when test="taskStatisticsVo.days =='1'">
  1327. and io.createtime >= DATE_SUB(NOW(), INTERVAL 1 DAY)
  1328. </when>
  1329. <when test="taskStatisticsVo.days =='7'">
  1330. and io.createtime >= DATE_SUB(NOW(), INTERVAL 7 DAY)
  1331. </when>
  1332. <when test="taskStatisticsVo.days =='30'">
  1333. and io.createtime >= DATE_SUB(NOW(), INTERVAL 30 DAY)
  1334. </when>
  1335. </choose>
  1336. </if>
  1337. </where>
  1338. GROUP BY
  1339. io.userid
  1340. ) a
  1341. </select>
  1342. <select id="insuranceCompanyQueryPage" resultType="com.ydtech.modules.admin.model.dto.TaskStatisticsDto">
  1343. SELECT
  1344. a.*,
  1345. ( SELECT eic.namesimple FROM esm_ins_company eic WHERE eic.id = a.partner_companies_id ) AS "partnerCompaniesName"
  1346. FROM
  1347. (
  1348. SELECT
  1349. pa.insurance_company_id,
  1350. pa.partner_companies_id,
  1351. pa.insurance_company AS "insuranceCompanyName",
  1352. COUNT( CASE WHEN iac.orderstatus = 0 THEN 1 END ) AS qutationCount,
  1353. COUNT( CASE WHEN iac.orderstatus = 2 THEN 1 END ) AS underwritingCount,
  1354. COUNT( CASE WHEN iac.orderstatus = 3 THEN 1 END ) AS qutationInsureCount,
  1355. COUNT( CASE WHEN iac.orderstatus = 4 THEN 1 END ) AS underwritingReturn,
  1356. COUNT( CASE WHEN iac.orderstatus = 2 THEN 1 END ) / COUNT( CASE WHEN iac.orderstatus = 0 THEN 1 END ) AS "passingRate",
  1357. COUNT( CASE WHEN iac.orderstatus = 3 THEN 1 END ) / COUNT( CASE WHEN iac.orderstatus = 0 THEN 1 END ) AS "closeRate",
  1358. COUNT( CASE WHEN iac.orderstatus = 3 THEN 1 END ) / COUNT( iac.orderstatus ) AS "contributionRate",
  1359. COUNT( CASE WHEN iac.orderstatus = 0 THEN 1 END ) / COUNT( iac.orderstatus ) AS "quotationRate",
  1360. COUNT( CASE WHEN iac.orderstatus = 1 THEN 1 END ) AS "auditOrder"
  1361. FROM
  1362. ins_area_company iac
  1363. LEFT JOIN ins_fee_audit ifa ON ifa.ins_order_no = iac.id
  1364. LEFT JOIN ptl_agreement pa ON pa.id = iac.agreement_id
  1365. LEFT JOIN ins_orders io ON io.orderno = iac.orderno
  1366. <where>
  1367. pa.insurance_company_id IS NOT NULL
  1368. <if test="taskStatisticsVo.provinceId != null and taskStatisticsVo.provinceId != ''">
  1369. and io.deptid like concat('%', #{taskStatisticsVo.provinceId}, '%')
  1370. </if>
  1371. <if test="taskStatisticsVo.cityId != null and taskStatisticsVo.cityId != ''">
  1372. and io.deptid like concat('%', #{taskStatisticsVo.cityId}, '%')
  1373. </if>
  1374. <if test="taskStatisticsVo.countyId != null and taskStatisticsVo.countyId != ''">
  1375. and io.deptid like concat('%', #{taskStatisticsVo.countyId}, '%')
  1376. </if>
  1377. <if test="taskStatisticsVo.houseId != null and taskStatisticsVo.houseId != ''">
  1378. and io.deptid like concat('%', #{taskStatisticsVo.houseId}, '%')
  1379. </if>
  1380. <if test="taskStatisticsVo.createtimeStart !=null and taskStatisticsVo.createtimeStart != '' and taskStatisticsVo.createtimeEnd !=null and taskStatisticsVo.createtimeEnd != ''">
  1381. AND DATE_FORMAT( iac.createtime, '%Y-%m-%d') BETWEEN DATE_FORMAT(#{taskStatisticsVo.createtimeStart},'%Y-%m-%d') AND DATE_FORMAT( #{taskStatisticsVo.createtimeEnd}, '%Y-%m-%d')
  1382. </if>
  1383. <if test="taskStatisticsVo.beginDate !=null and taskStatisticsVo.beginDate != '' and taskStatisticsVo.endDate !=null and taskStatisticsVo.endDate != ''">
  1384. AND DATE_FORMAT( iac.createtime, '%Y-%m-%d') BETWEEN DATE_FORMAT( #{taskStatisticsVo.beginDate}, '%Y-%m-%d') AND DATE_FORMAT( #{taskStatisticsVo.endDate}, '%Y-%m-%d')
  1385. </if>
  1386. <if test="taskStatisticsVo.companyId !=null and taskStatisticsVo.companyId != ''">
  1387. AND iac.company_id =#{taskStatisticsVo.companyId}
  1388. </if>
  1389. <if test="taskStatisticsVo.deptIds != null and taskStatisticsVo.deptIds != '' and taskStatisticsVo.deptIds.size() > 0">
  1390. AND io.deptid in
  1391. <foreach collection="taskStatisticsVo.deptIds" item="item" open="(" separator="," close=")">
  1392. #{item}
  1393. </foreach>
  1394. </if>
  1395. <if test="taskStatisticsVo.userIds != null and taskStatisticsVo.userIds != '' and taskStatisticsVo.userIds.size() > 0">
  1396. AND io.userid in
  1397. <foreach collection="taskStatisticsVo.userIds" item="item" open="(" separator="," close=")">
  1398. #{item}
  1399. </foreach>
  1400. </if>
  1401. </where>
  1402. GROUP BY
  1403. pa.insurance_company_id,
  1404. pa.partner_companies_id,
  1405. pa.insurance_company
  1406. ) a
  1407. </select>
  1408. <select id="insuranceCompanyQueryTotal" resultType="java.lang.Long">
  1409. SELECT
  1410. COUNT(0)
  1411. FROM
  1412. (
  1413. SELECT
  1414. pa.insurance_company_id,
  1415. pa.partner_companies_id
  1416. FROM
  1417. ins_area_company iac
  1418. LEFT JOIN ins_fee_audit ifa ON ifa.ins_order_no = iac.id
  1419. LEFT JOIN ptl_agreement pa ON pa.id = iac.agreement_id
  1420. LEFT JOIN ins_orders io ON io.orderno = iac.orderno
  1421. <where>
  1422. pa.insurance_company_id IS NOT NULL
  1423. <if test="taskStatisticsVo.provinceId != null and taskStatisticsVo.provinceId != ''">
  1424. and io.deptid like concat('%', #{taskStatisticsVo.provinceId}, '%')
  1425. </if>
  1426. <if test="taskStatisticsVo.cityId != null and taskStatisticsVo.cityId != ''">
  1427. and io.deptid like concat('%', #{taskStatisticsVo.cityId}, '%')
  1428. </if>
  1429. <if test="taskStatisticsVo.countyId != null and taskStatisticsVo.countyId != ''">
  1430. and io.deptid like concat('%', #{taskStatisticsVo.countyId}, '%')
  1431. </if>
  1432. <if test="taskStatisticsVo.houseId != null and taskStatisticsVo.houseId != ''">
  1433. and io.deptid like concat('%', #{taskStatisticsVo.houseId}, '%')
  1434. </if>
  1435. <if test="taskStatisticsVo.createtimeStart !=null and taskStatisticsVo.createtimeStart != '' and taskStatisticsVo.createtimeEnd !=null and taskStatisticsVo.createtimeEnd != ''">
  1436. AND DATE_FORMAT( iac.createtime, '%Y-%m-%d') BETWEEN DATE_FORMAT(#{taskStatisticsVo.createtimeStart},'%Y-%m-%d') AND DATE_FORMAT( #{taskStatisticsVo.createtimeEnd}, '%Y-%m-%d')
  1437. </if>
  1438. <if test="taskStatisticsVo.beginDate !=null and taskStatisticsVo.beginDate != '' and taskStatisticsVo.endDate !=null and taskStatisticsVo.endDate != ''">
  1439. AND DATE_FORMAT( iac.createtime, '%Y-%m-%d') BETWEEN DATE_FORMAT( #{taskStatisticsVo.beginDate}, '%Y-%m-%d') AND DATE_FORMAT( #{taskStatisticsVo.endDate}, '%Y-%m-%d')
  1440. </if>
  1441. <if test="taskStatisticsVo.deptIds != null and taskStatisticsVo.deptIds != '' and taskStatisticsVo.deptIds.size() > 0">
  1442. AND io.deptid in
  1443. <foreach collection="taskStatisticsVo.deptIds" item="item" open="(" separator="," close=")">
  1444. #{item}
  1445. </foreach>
  1446. </if>
  1447. <if test="taskStatisticsVo.userIds != null and taskStatisticsVo.userIds != '' and taskStatisticsVo.userIds.size() > 0">
  1448. AND io.userid in
  1449. <foreach collection="taskStatisticsVo.userIds" item="item" open="(" separator="," close=")">
  1450. #{item}
  1451. </foreach>
  1452. </if>
  1453. </where>
  1454. GROUP BY
  1455. pa.insurance_company_id,
  1456. pa.partner_companies_id
  1457. ) total
  1458. </select>
  1459. <select id="agentStatisticsQueryPage" resultType="com.ydtech.modules.admin.model.dto.TaskStatisticsDto">
  1460. SELECT
  1461. sd.name as "deptName",
  1462. su.name as "userName",
  1463. io.userid as "userId",
  1464. sd.id as "deptId",
  1465. suLeader.name as "leaderName",
  1466. suLeader.mobile as "leaderMobile",
  1467. sd.management_source as "managementSource",
  1468. COUNT( CASE WHEN iac.orderstatus = 0 THEN 1 END ) AS qutationCount,
  1469. COUNT( CASE WHEN iac.orderstatus = 2 THEN 1 END ) AS underwritingCount,
  1470. COUNT( CASE WHEN iac.orderstatus = 3 THEN 1 END ) AS qutationInsureCount,
  1471. COUNT( CASE WHEN iac.orderstatus = 4 THEN 1 END ) AS underwritingReturn,
  1472. (COUNT( CASE WHEN iac.orderstatus = 2 THEN 1 END ) +COUNT( CASE WHEN iac.orderstatus = 3 THEN 1 END )) / COUNT(iac.orderstatus) as "passingRate",
  1473. COUNT( CASE WHEN iac.orderstatus = 3 THEN 1 END ) / COUNT( CASE WHEN iac.orderstatus = 0 THEN 1 END ) as "closeRate",
  1474. COUNT( CASE WHEN iac.orderstatus = 3 THEN 1 END ) / COUNT(iac.orderstatus) as "contributionRate",
  1475. COUNT( CASE WHEN iac.orderstatus = 0 THEN 1 END ) / COUNT(iac.orderstatus) as "quotationRate",
  1476. COUNT( CASE WHEN iac.orderstatus = 1 THEN 1 END ) as "auditOrder"
  1477. FROM
  1478. ins_area_company iac
  1479. left join ins_orders io on io.orderno = iac.orderno
  1480. left join sys_dept sd on sd.id=io.deptid
  1481. left join sys_user su on su.id=io.userid
  1482. left join sys_user suLeader on suLeader.id =su.leader_id
  1483. <where>
  1484. sd.management_source = '2'
  1485. <if test="taskStatisticsVo.provinceId != null and taskStatisticsVo.provinceId != ''">
  1486. and io.deptid like "${taskStatisticsVo.provinceId}%"
  1487. </if>
  1488. <if test="taskStatisticsVo.cityId != null and taskStatisticsVo.cityId != ''">
  1489. and io.deptid like "${taskStatisticsVo.cityId}%"
  1490. </if>
  1491. <if test="taskStatisticsVo.countyId != null and taskStatisticsVo.countyId != ''">
  1492. and io.deptid like "${taskStatisticsVo.countyId}%"
  1493. </if>
  1494. <if test="taskStatisticsVo.houseId != null and taskStatisticsVo.houseId != ''">
  1495. and io.deptid like "${taskStatisticsVo.houseId}%"
  1496. </if>
  1497. <if test="taskStatisticsVo.userId !=null and taskStatisticsVo.userId!='' ">
  1498. and io.userid =#{taskStatisticsVo.userId}
  1499. </if>
  1500. <if test='taskStatisticsVo.userName !=null and taskStatisticsVo.userName!="" '>
  1501. and su.name like concat('%',#{taskStatisticsVo.userName},'%')
  1502. </if>
  1503. <if test='taskStatisticsVo.leaderId !=null and taskStatisticsVo.leaderId!="" '>
  1504. and su.leader_id =#{taskStatisticsVo.leaderId}
  1505. </if>
  1506. <if test='taskStatisticsVo.userId !=null and taskStatisticsVo.userId!="" '>
  1507. and su.id =#{taskStatisticsVo.userId}
  1508. </if>
  1509. <if test="taskStatisticsVo.createtimeStart !=null and taskStatisticsVo.createtimeStart != '' and taskStatisticsVo.createtimeEnd !=null and taskStatisticsVo.createtimeEnd != ''">
  1510. AND DATE_FORMAT( io.createtime, '%Y-%m-%d') BETWEEN #{taskStatisticsVo.createtimeStart} AND #{taskStatisticsVo.createtimeEnd}
  1511. </if>
  1512. <if test="taskStatisticsVo.beginDate !=null and taskStatisticsVo.beginDate != '' and taskStatisticsVo.endDate !=null and taskStatisticsVo.endDate != ''">
  1513. 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')
  1514. </if>
  1515. <if test="taskStatisticsVo.days !=null and taskStatisticsVo.days !='' ">
  1516. and iac.createtime >= DATE_SUB(NOW(), INTERVAL #{taskStatisticsVo.days} DAY)
  1517. </if>
  1518. <if test="taskStatisticsVo.deptIds != null and taskStatisticsVo.deptIds != '' and taskStatisticsVo.deptIds.size() > 0">
  1519. AND sd.id in
  1520. <foreach collection="taskStatisticsVo.deptIds" item="item" open="(" separator="," close=")">
  1521. #{item}
  1522. </foreach>
  1523. </if>
  1524. <if test="taskStatisticsVo.userIds != null and taskStatisticsVo.userIds != '' and taskStatisticsVo.userIds.size() > 0">
  1525. AND io.userid in
  1526. <foreach collection="taskStatisticsVo.userIds" item="item" open="(" separator="," close=")">
  1527. #{item}
  1528. </foreach>
  1529. </if>
  1530. <if test="taskStatisticsVo.days !=null and taskStatisticsVo.days !='' ">
  1531. <choose>
  1532. <when test="taskStatisticsVo.days =='1'">
  1533. and io.createtime >= DATE_SUB(NOW(), INTERVAL 1 DAY)
  1534. </when>
  1535. <when test="taskStatisticsVo.days =='7'">
  1536. and io.createtime >= DATE_SUB(NOW(), INTERVAL 7 DAY)
  1537. </when>
  1538. <when test="taskStatisticsVo.days =='30'">
  1539. and io.createtime >= DATE_SUB(NOW(), INTERVAL 30 DAY)
  1540. </when>
  1541. </choose>
  1542. </if>
  1543. </where>
  1544. GROUP BY io.userid , su.name, sd.id , sd.name,suLeader.name,suLeader.mobile,sd.management_source
  1545. </select>
  1546. <select id="agentStatisticsQueryPageTotal" resultType="java.lang.Long">
  1547. select count(0) from (
  1548. SELECT
  1549. io.userid as "userId"
  1550. FROM
  1551. ins_area_company iac
  1552. left join ins_orders io on io.orderno = iac.orderno
  1553. left join sys_dept sd on sd.id=io.deptid
  1554. left join sys_user su on su.id=io.userid
  1555. <where>
  1556. sd.management_source = '2'
  1557. <if test="taskStatisticsVo.provinceId != null and taskStatisticsVo.provinceId != ''">
  1558. and io.deptid like "${taskStatisticsVo.provinceId}%"
  1559. </if>
  1560. <if test="taskStatisticsVo.cityId != null and taskStatisticsVo.cityId != ''">
  1561. and io.deptid like "${taskStatisticsVo.cityId}%"
  1562. </if>
  1563. <if test="taskStatisticsVo.countyId != null and taskStatisticsVo.countyId != ''">
  1564. and io.deptid like "${taskStatisticsVo.countyId}%"
  1565. </if>
  1566. <if test="taskStatisticsVo.houseId != null and taskStatisticsVo.houseId != ''">
  1567. and io.deptid like "${taskStatisticsVo.houseId}%"
  1568. </if>
  1569. <if test='taskStatisticsVo.userName !=null and taskStatisticsVo.userName!="" '>
  1570. and su.name like concat('%',#{taskStatisticsVo.userName},'%')
  1571. </if>
  1572. <if test='taskStatisticsVo.leaderId !=null and taskStatisticsVo.leaderId!="" '>
  1573. and su.leader_id =#{taskStatisticsVo.leaderId}
  1574. </if>
  1575. <if test='taskStatisticsVo.userId !=null and taskStatisticsVo.userId!="" '>
  1576. and su.id =#{taskStatisticsVo.userId}
  1577. </if>
  1578. <if test="taskStatisticsVo.createtimeStart !=null and taskStatisticsVo.createtimeStart != '' and taskStatisticsVo.createtimeEnd !=null and taskStatisticsVo.createtimeEnd != ''">
  1579. AND DATE_FORMAT( io.createtime, '%Y-%m-%d') BETWEEN #{taskStatisticsVo.createtimeStart} AND #{taskStatisticsVo.createtimeEnd}
  1580. </if>
  1581. <if test="taskStatisticsVo.beginDate !=null and taskStatisticsVo.beginDate != '' and taskStatisticsVo.endDate !=null and taskStatisticsVo.endDate != ''">
  1582. 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')
  1583. </if>
  1584. <if test="taskStatisticsVo.userId !=null and taskStatisticsVo.userId!='' ">
  1585. and io.userid =#{taskStatisticsVo.userId}
  1586. </if>
  1587. <if test="taskStatisticsVo.days !=null and taskStatisticsVo.days !='' ">
  1588. and iac.createtime >= DATE_SUB(NOW(), INTERVAL #{taskStatisticsVo.days} DAY)
  1589. </if>
  1590. <if test="taskStatisticsVo.days !=null and taskStatisticsVo.days !='' ">
  1591. <choose>
  1592. <when test="taskStatisticsVo.days =='1'">
  1593. and io.createtime >= DATE_SUB(NOW(), INTERVAL 1 DAY)
  1594. </when>
  1595. <when test="taskStatisticsVo.days =='7'">
  1596. and io.createtime >= DATE_SUB(NOW(), INTERVAL 7 DAY)
  1597. </when>
  1598. <when test="taskStatisticsVo.days =='30'">
  1599. and io.createtime >= DATE_SUB(NOW(), INTERVAL 30 DAY)
  1600. </when>
  1601. </choose>
  1602. </if>
  1603. </where>
  1604. GROUP BY io.userid
  1605. ) a
  1606. </select>
  1607. <select id="costCenter" resultType="com.ydtech.modules.admin.model.dto.TaskStatisticsDto">
  1608. SELECT
  1609. iac.company_id,
  1610. iac.inscompany as "insuranceCompanyName",
  1611. COUNT( CASE WHEN ifa.auditstatus = 1 THEN 1 END ) AS "auditstatusOrders",
  1612. COUNT( CASE WHEN ifa.auditstatus = 0 THEN 1 END ) AS "auditOrder",
  1613. COUNT( CASE WHEN ifa.auditstatus = 1 and ifa.audituser != '自动审核' THEN 1 END ) AS "persionAudit",
  1614. COUNT( CASE WHEN ifa.audituser = '自动审核' THEN 1 END ) AS "automaticAudit"
  1615. FROM
  1616. ins_fee_audit ifa
  1617. LEFT JOIN ins_orders io ON io.orderno = ifa.orderno
  1618. LEFT JOIN ins_area_company iac ON iac.orderno = io.orderno
  1619. AND iac.orderstatus = 3
  1620. LEFT JOIN ptl_agreement pa ON pa.id = iac.agreement_id
  1621. LEFT JOIN esm_ins_company eic ON eic.id = pa.partner_companies_id
  1622. left join sys_user su on su.id =ifa.audituser
  1623. <where>
  1624. 1=1
  1625. and iac.id = ifa.ins_order_no
  1626. AND iac.orderstatus = 3
  1627. <if test="taskStatisticsVo.reviewer !=null and taskStatisticsVo.reviewer !=''">
  1628. and su.name =#{taskStatisticsVo.reviewer}
  1629. </if>
  1630. <if test="taskStatisticsVo.audittime !=null and taskStatisticsVo.audittime !=''">
  1631. and ifa.audittime =#{taskStatisticsVo.audittime}
  1632. </if>
  1633. <if test="taskStatisticsVo.companyId !=null and taskStatisticsVo.companyId !=''">
  1634. and iac.company_id =#{taskStatisticsVo.companyId}
  1635. </if>
  1636. <if test="taskStatisticsVo.createtimeStart !=null and taskStatisticsVo.createtimeStart != '' and taskStatisticsVo.createtimeEnd !=null and taskStatisticsVo.createtimeEnd != ''">
  1637. AND DATE_FORMAT( iac.signing_time, '%Y-%m-%d') BETWEEN DATE_FORMAT( #{taskStatisticsVo.createtimeStart}, '%Y-%m-%d') AND DATE_FORMAT( #{taskStatisticsVo.createtimeEnd}, '%Y-%m-%d')
  1638. </if>
  1639. <if test="taskStatisticsVo.beginDate !=null and taskStatisticsVo.beginDate != '' and taskStatisticsVo.endDate !=null and taskStatisticsVo.endDate != ''">
  1640. 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')
  1641. </if>
  1642. <if test="taskStatisticsVo.deptIds != null and taskStatisticsVo.deptIds != '' and taskStatisticsVo.deptIds.size() > 0">
  1643. AND io.deptid in
  1644. <foreach collection="taskStatisticsVo.deptIds" item="item" open="(" separator="," close=")">
  1645. #{item}
  1646. </foreach>
  1647. </if>
  1648. <if test="taskStatisticsVo.userIds != null and taskStatisticsVo.userIds != '' and taskStatisticsVo.userIds.size() > 0">
  1649. AND su.id in
  1650. <foreach collection="taskStatisticsVo.userIds" item="item" open="(" separator="," close=")">
  1651. #{item}
  1652. </foreach>
  1653. </if>
  1654. <choose>
  1655. <when test="taskStatisticsVo.riskCode != null and taskStatisticsVo.riskCode != '' and taskStatisticsVo.riskCode != 'all' ">
  1656. and iac.product = #{taskStatisticsVo.riskCode}
  1657. </when>
  1658. </choose>
  1659. </where>
  1660. GROUP BY
  1661. iac.company_id,
  1662. iac.inscompany
  1663. </select>
  1664. <select id="costCenterDetails" resultType="com.ydtech.modules.admin.model.dto.TaskStatisticsDto">
  1665. SELECT
  1666. ifa.audituser as "audituser",
  1667. su.name as "audituserName",
  1668. su.mobile as "audituserMobile",
  1669. iac.inscompany as "insuranceCompanyName",
  1670. COUNT( CASE WHEN ifa.auditstatus = 1 THEN 1 END ) AS "auditstatusOrders",
  1671. COUNT( CASE WHEN ifa.auditstatus = 0 THEN 1 END ) AS "auditOrder"
  1672. FROM
  1673. ins_fee_audit ifa
  1674. LEFT JOIN ins_orders io ON io.orderno = ifa.orderno
  1675. LEFT JOIN ins_area_company iac ON iac.orderno = io.orderno
  1676. LEFT JOIN ptl_agreement pa ON pa.id = iac.agreement_id
  1677. LEFT JOIN esm_ins_company eic ON eic.id = pa.partner_companies_id
  1678. left join sys_user su on su.id =ifa.audituser
  1679. <where>
  1680. 1=1
  1681. and iac.id = ifa.ins_order_no
  1682. AND iac.orderstatus = 3
  1683. AND ifa.audituser != '自动审核'
  1684. AND (ifa.auditstatus ='1' or ifa.auditstatus ='0')
  1685. <if test="taskStatisticsVo.reviewer !=null and taskStatisticsVo.reviewer !=''">
  1686. and su.name =#{taskStatisticsVo.reviewer}
  1687. </if>
  1688. <if test="taskStatisticsVo.companyId !=null and taskStatisticsVo.companyId !=''">
  1689. and iac.company_id =#{taskStatisticsVo.companyId}
  1690. </if>
  1691. <if test="taskStatisticsVo.audittime !=null and taskStatisticsVo.audittime !=''">
  1692. and ifa.audittime =#{taskStatisticsVo.audittime}
  1693. </if>
  1694. <if test="taskStatisticsVo.companyId !=null and taskStatisticsVo.companyId !=''">
  1695. and iac.company_id =#{taskStatisticsVo.companyId}
  1696. </if>
  1697. <if test="taskStatisticsVo.createtimeStart !=null and taskStatisticsVo.createtimeStart != '' and taskStatisticsVo.createtimeEnd !=null and taskStatisticsVo.createtimeEnd != ''">
  1698. AND DATE_FORMAT( ifa.audittime, '%Y-%m-%d') BETWEEN DATE_FORMAT( #{taskStatisticsVo.createtimeStart}, '%Y-%m-%d') AND DATE_FORMAT( #{taskStatisticsVo.createtimeEnd}, '%Y-%m-%d')
  1699. </if>
  1700. <if test="taskStatisticsVo.beginDate !=null and taskStatisticsVo.beginDate != '' and taskStatisticsVo.endDate !=null and taskStatisticsVo.endDate != ''">
  1701. 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')
  1702. </if>
  1703. <if test="taskStatisticsVo.deptIds != null and taskStatisticsVo.deptIds != '' and taskStatisticsVo.deptIds.size() > 0">
  1704. AND io.deptid in
  1705. <foreach collection="taskStatisticsVo.deptIds" item="item" open="(" separator="," close=")">
  1706. #{item}
  1707. </foreach>
  1708. </if>
  1709. <if test="taskStatisticsVo.userIds != null and taskStatisticsVo.userIds != '' and taskStatisticsVo.userIds.size() > 0">
  1710. AND su.id in
  1711. <foreach collection="taskStatisticsVo.userIds" item="item" open="(" separator="," close=")">
  1712. #{item}
  1713. </foreach>
  1714. </if>
  1715. <choose>
  1716. <when test="taskStatisticsVo.riskCode != null and taskStatisticsVo.riskCode != '' and taskStatisticsVo.riskCode != 'all' ">
  1717. and iac.product = #{taskStatisticsVo.riskCode}
  1718. </when>
  1719. </choose>
  1720. </where>
  1721. GROUP BY
  1722. ifa.audituser,su.name,su.mobile,iac.inscompany
  1723. </select>
  1724. <select id="costCenterDetailsExcel" resultType="com.ydtech.modules.admin.model.dto.TaskStatisticsDtoExcel">
  1725. SELECT
  1726. ifa.audituser as "audituser",
  1727. su.name as "audituserName",
  1728. su.mobile as "audituserMobile",
  1729. iac.inscompany as "insuranceCompanyName",
  1730. COUNT( CASE WHEN ifa.auditstatus = 1 THEN 1 END ) AS "auditstatusOrders",
  1731. COUNT( CASE WHEN ifa.auditstatus = 0 THEN 1 END ) AS "auditOrder"
  1732. FROM
  1733. ins_fee_audit ifa
  1734. LEFT JOIN ins_orders io ON io.orderno = ifa.orderno
  1735. LEFT JOIN ins_area_company iac ON iac.orderno = io.orderno
  1736. LEFT JOIN ptl_agreement pa ON pa.id = iac.agreement_id
  1737. LEFT JOIN esm_ins_company eic ON eic.id = pa.partner_companies_id
  1738. left join sys_user su on su.id =ifa.audituser
  1739. <where>
  1740. 1=1
  1741. and iac.id = ifa.ins_order_no
  1742. AND iac.orderstatus = 3
  1743. AND ifa.audituser != '自动审核'
  1744. AND (ifa.auditstatus ='1' or ifa.auditstatus ='0')
  1745. <if test="taskStatisticsVo.reviewer !=null and taskStatisticsVo.reviewer !=''">
  1746. and su.name =#{taskStatisticsVo.reviewer}
  1747. </if>
  1748. <if test="taskStatisticsVo.companyId !=null and taskStatisticsVo.companyId !=''">
  1749. and iac.company_id =#{taskStatisticsVo.companyId}
  1750. </if>
  1751. <if test="taskStatisticsVo.audittime !=null and taskStatisticsVo.audittime !=''">
  1752. and ifa.audittime =#{taskStatisticsVo.audittime}
  1753. </if>
  1754. <if test="taskStatisticsVo.companyId !=null and taskStatisticsVo.companyId !=''">
  1755. and iac.company_id =#{taskStatisticsVo.companyId}
  1756. </if>
  1757. <if test="taskStatisticsVo.createtimeStart !=null and taskStatisticsVo.createtimeStart != '' and taskStatisticsVo.createtimeEnd !=null and taskStatisticsVo.createtimeEnd != ''">
  1758. AND DATE_FORMAT( ifa.audittime, '%Y-%m-%d') BETWEEN DATE_FORMAT( #{taskStatisticsVo.createtimeStart}, '%Y-%m-%d') AND DATE_FORMAT( #{taskStatisticsVo.createtimeEnd}, '%Y-%m-%d')
  1759. </if>
  1760. <if test="taskStatisticsVo.beginDate !=null and taskStatisticsVo.beginDate != '' and taskStatisticsVo.endDate !=null and taskStatisticsVo.endDate != ''">
  1761. 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')
  1762. </if>
  1763. <if test="taskStatisticsVo.deptIds != null and taskStatisticsVo.deptIds != '' and taskStatisticsVo.deptIds.size() > 0">
  1764. AND io.deptid in
  1765. <foreach collection="taskStatisticsVo.deptIds" item="item" open="(" separator="," close=")">
  1766. #{item}
  1767. </foreach>
  1768. </if>
  1769. <if test="taskStatisticsVo.userIds != null and taskStatisticsVo.userIds != '' and taskStatisticsVo.userIds.size() > 0">
  1770. AND su.id in
  1771. <foreach collection="taskStatisticsVo.userIds" item="item" open="(" separator="," close=")">
  1772. #{item}
  1773. </foreach>
  1774. </if>
  1775. <choose>
  1776. <when test="taskStatisticsVo.riskCode != null and taskStatisticsVo.riskCode != '' and taskStatisticsVo.riskCode != 'all' ">
  1777. and iac.product = #{taskStatisticsVo.riskCode}
  1778. </when>
  1779. </choose>
  1780. </where>
  1781. GROUP BY
  1782. ifa.audituser,su.name,su.mobile,iac.inscompany
  1783. </select>
  1784. <select id="costCenterDetailsLicense" resultType="com.ydtech.modules.admin.model.dto.TaskStatisticsDto">
  1785. SELECT
  1786. io.licenseno as "licenseno",
  1787. iac.createtime as "createTime",
  1788. ifa.audittime as "auditTime",
  1789. IFNULL(TIMESTAMPDIFF(SECOND, iac.createtime, ifa.audittime),0) as "timeDifference"
  1790. FROM
  1791. ins_fee_audit ifa
  1792. LEFT JOIN ins_orders io ON io.orderno = ifa.orderno
  1793. LEFT JOIN ins_area_company iac ON iac.orderno = io.orderno
  1794. LEFT JOIN ptl_agreement pa ON pa.id = iac.agreement_id
  1795. LEFT JOIN esm_ins_company eic ON eic.id = pa.partner_companies_id
  1796. left join sys_user su on su.id =ifa.audituser
  1797. <where>
  1798. 1=1
  1799. and iac.id = ifa.ins_order_no
  1800. AND iac.orderstatus = 3
  1801. AND io.orderstatus = 3
  1802. AND ifa.audituser != '自动审核'
  1803. AND (ifa.auditstatus ='1' or ifa.auditstatus ='0')
  1804. <if test="taskStatisticsVo.reviewer !=null and taskStatisticsVo.reviewer !=''">
  1805. and su.name =#{taskStatisticsVo.reviewer}
  1806. </if>
  1807. <if test="taskStatisticsVo.audituser !=null and taskStatisticsVo.audituser !=''">
  1808. and ifa.audituser =#{taskStatisticsVo.audituser}
  1809. </if>
  1810. <if test="taskStatisticsVo.companyId !=null and taskStatisticsVo.companyId !=''">
  1811. and iac.company_id =#{taskStatisticsVo.companyId}
  1812. </if>
  1813. <if test="taskStatisticsVo.audittime !=null and taskStatisticsVo.audittime !=''">
  1814. and ifa.audittime =#{taskStatisticsVo.audittime}
  1815. </if>
  1816. <if test="taskStatisticsVo.companyId !=null and taskStatisticsVo.companyId !=''">
  1817. and iac.company_id =#{taskStatisticsVo.companyId}
  1818. </if>
  1819. <if test="taskStatisticsVo.createtimeStart !=null and taskStatisticsVo.createtimeStart != '' and taskStatisticsVo.createtimeEnd !=null and taskStatisticsVo.createtimeEnd != ''">
  1820. AND DATE_FORMAT( ifa.audittime, '%Y-%m-%d') BETWEEN DATE_FORMAT( #{taskStatisticsVo.createtimeStart}, '%Y-%m-%d') AND DATE_FORMAT( #{taskStatisticsVo.createtimeEnd}, '%Y-%m-%d')
  1821. </if>
  1822. <if test="taskStatisticsVo.beginDate !=null and taskStatisticsVo.beginDate != '' and taskStatisticsVo.endDate !=null and taskStatisticsVo.endDate != ''">
  1823. 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')
  1824. </if>
  1825. <if test="taskStatisticsVo.deptIds != null and taskStatisticsVo.deptIds != '' and taskStatisticsVo.deptIds.size() > 0">
  1826. AND io.deptid in
  1827. <foreach collection="taskStatisticsVo.deptIds" item="item" open="(" separator="," close=")">
  1828. #{item}
  1829. </foreach>
  1830. </if>
  1831. <if test="taskStatisticsVo.userIds != null and taskStatisticsVo.userIds != '' and taskStatisticsVo.userIds.size() > 0">
  1832. AND su.id in
  1833. <foreach collection="taskStatisticsVo.userIds" item="item" open="(" separator="," close=")">
  1834. #{item}
  1835. </foreach>
  1836. </if>
  1837. <choose>
  1838. <when test="taskStatisticsVo.riskCode != null and taskStatisticsVo.riskCode != '' and taskStatisticsVo.riskCode != 'all' ">
  1839. and iac.product = #{taskStatisticsVo.riskCode}
  1840. </when>
  1841. </choose>
  1842. </where>
  1843. </select>
  1844. <select id="costCenterSecond" resultType="com.ydtech.modules.admin.model.dto.TaskStatisticsDtoNew">
  1845. SELECT
  1846. IFNULL(count(io.licenseno),0) as "orderNumber",
  1847. IFNULL(sum(TIMESTAMPDIFF(SECOND, iac.createtime, iac.audittime)),0) as "sumSecond",
  1848. ROUND(IFNULL(sum(TIMESTAMPDIFF(SECOND, iac.createtime, iac.audittime)),0) / count(io.licenseno),2) as "averageSecond"
  1849. FROM
  1850. ins_fee_audit ifa
  1851. LEFT JOIN ins_orders io ON io.orderno = ifa.orderno
  1852. LEFT JOIN ins_area_company iac ON iac.orderno = io.orderno
  1853. LEFT JOIN ptl_agreement pa ON pa.id = iac.agreement_id
  1854. LEFT JOIN esm_ins_company eic ON eic.id = pa.partner_companies_id
  1855. left join sys_user su on su.id =ifa.audituser
  1856. <where>
  1857. 1=1
  1858. and iac.id = ifa.ins_order_no
  1859. AND iac.orderstatus = 3
  1860. AND io.orderstatus = 3
  1861. AND ifa.audituser != '自动审核'
  1862. AND (ifa.auditstatus ='1' or ifa.auditstatus ='0')
  1863. <if test="taskStatisticsVo.reviewer !=null and taskStatisticsVo.reviewer !=''">
  1864. and su.name =#{taskStatisticsVo.reviewer}
  1865. </if>
  1866. <if test="taskStatisticsVo.audituser !=null and taskStatisticsVo.audituser !=''">
  1867. and ifa.audituser =#{taskStatisticsVo.audituser}
  1868. </if>
  1869. <if test="taskStatisticsVo.companyId !=null and taskStatisticsVo.companyId !=''">
  1870. and iac.company_id =#{taskStatisticsVo.companyId}
  1871. </if>
  1872. <if test="taskStatisticsVo.audittime !=null and taskStatisticsVo.audittime !=''">
  1873. and ifa.audittime =#{taskStatisticsVo.audittime}
  1874. </if>
  1875. <if test="taskStatisticsVo.companyId !=null and taskStatisticsVo.companyId !=''">
  1876. and iac.company_id =#{taskStatisticsVo.companyId}
  1877. </if>
  1878. <if test="taskStatisticsVo.createtimeStart !=null and taskStatisticsVo.createtimeStart != '' and taskStatisticsVo.createtimeEnd !=null and taskStatisticsVo.createtimeEnd != ''">
  1879. AND DATE_FORMAT( ifa.audittime, '%Y-%m-%d') BETWEEN DATE_FORMAT( #{taskStatisticsVo.createtimeStart}, '%Y-%m-%d') AND DATE_FORMAT( #{taskStatisticsVo.createtimeEnd}, '%Y-%m-%d')
  1880. </if>
  1881. <if test="taskStatisticsVo.beginDate !=null and taskStatisticsVo.beginDate != '' and taskStatisticsVo.endDate !=null and taskStatisticsVo.endDate != ''">
  1882. 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')
  1883. </if>
  1884. <if test="taskStatisticsVo.deptIds != null and taskStatisticsVo.deptIds != '' and taskStatisticsVo.deptIds.size() > 0">
  1885. AND io.deptid in
  1886. <foreach collection="taskStatisticsVo.deptIds" item="item" open="(" separator="," close=")">
  1887. #{item}
  1888. </foreach>
  1889. </if>
  1890. <if test="taskStatisticsVo.userIds != null and taskStatisticsVo.userIds != '' and taskStatisticsVo.userIds.size() > 0">
  1891. AND su.id in
  1892. <foreach collection="taskStatisticsVo.userIds" item="item" open="(" separator="," close=")">
  1893. #{item}
  1894. </foreach>
  1895. </if>
  1896. <choose>
  1897. <when test="taskStatisticsVo.riskCode != null and taskStatisticsVo.riskCode != '' and taskStatisticsVo.riskCode != 'all' ">
  1898. and iac.product = #{taskStatisticsVo.riskCode}
  1899. </when>
  1900. </choose>
  1901. </where>
  1902. </select>
  1903. <select id="getOrderManpower" resultType="com.ydtech.modules.admin.model.dto.QxFrontlineAgentDto">
  1904. SELECT
  1905. count( a.numberUserId ) as "orderManpower",
  1906. sum( a.orderAmount ) as "totalPremium",
  1907. sum( a.orderAmount )/ count( a.numberUserId ) as "averagePremium"
  1908. FROM
  1909. (
  1910. SELECT
  1911. count( io.userid ) AS "numberUserId",
  1912. SUM(IFNULL(iac.jqpremium, 0)) +
  1913. SUM(IFNULL(iac.sypremium, 0)) +
  1914. SUM(IFNULL(iac.jypremium, 0)) AS "orderAmount"
  1915. FROM
  1916. `ins_area_company` iac
  1917. LEFT JOIN ins_orders io ON io.orderno = iac.orderno
  1918. <where>
  1919. iac.orderstatus = '3'
  1920. <if test="ids != null and ids.size()>0 ">
  1921. AND io.userid IN
  1922. <foreach item="item" collection="ids" open="(" separator="," close=")">
  1923. #{item}
  1924. </foreach>
  1925. </if>
  1926. </where>
  1927. GROUP BY
  1928. io.userid
  1929. ) a
  1930. </select>
  1931. <select id="getOrderManpowerNew" resultType="com.ydtech.modules.admin.model.dto.QxFrontlineAgentDto">
  1932. SELECT
  1933. count( a.numberUserId ) as "orderManpower",
  1934. IFNULL(sum( a.orderAmount ),0) as "totalPremium",
  1935. ROUND(sum( a.orderAmount )/ sum(a.ordernoNumber),2) AS "averagePremium"
  1936. FROM
  1937. (
  1938. SELECT
  1939. count( io.userid ) AS "numberUserId",
  1940. count( iac.orderno ) AS "ordernoNumber",
  1941. SUM(IFNULL(iac.jqpremium, 0)
  1942. +IFNULL(iac.sypremium, 0)
  1943. +IFNULL(iac.jypremium, 0)
  1944. ) AS "orderAmount"
  1945. FROM
  1946. `ins_area_company` iac
  1947. LEFT JOIN ins_orders io ON io.orderno = iac.orderno
  1948. <where>
  1949. iac.orderstatus = '3'
  1950. <if test="vo.ids != null and vo.ids.size()>0 ">
  1951. AND io.userid IN
  1952. <foreach item="item" collection="vo.ids" open="(" separator="," close=")">
  1953. #{item}
  1954. </foreach>
  1955. </if>
  1956. <if test="vo.createtimeStart != null and vo.createtimeStart!='' and vo.createtimeEnd != null and vo.createtimeEnd!=''">
  1957. AND iac.signing_time BETWEEN #{vo.createtimeStart} AND #{vo.createtimeEnd}
  1958. </if>
  1959. </where>
  1960. GROUP BY
  1961. io.userid
  1962. ) a
  1963. <where>
  1964. <if test="vo.outThere != null and vo.outThere!=''">
  1965. <choose>
  1966. <when test=" vo.outThere == 0">
  1967. AND IFNULL(a.orderAmount,0) = 0
  1968. </when>
  1969. <when test="vo.outThere == 1">
  1970. AND IFNULL(a.orderAmount,0) > 0
  1971. </when>
  1972. </choose>
  1973. </if>
  1974. </where>
  1975. order by sum( a.orderAmount ) desc
  1976. </select>
  1977. <select id="getChannelOrderManpowerNew" resultType="com.ydtech.modules.admin.model.dto.QxFrontlineAgentDto">
  1978. SELECT
  1979. a.userId as "userId",
  1980. a.userName as "name",
  1981. a.orderNumber as "orderNumber",
  1982. a.underwritingCount as "underwritingCount",
  1983. a.qutationInsureCount as "qutationInsureCount",
  1984. IFNULL(a.jqpremium,0) + IFNULL(a.sypremium,0) + IFNULL(a.jypremium,0) as "totalPremium",
  1985. a.isFactorVerify as "isFactorVerify",
  1986. a.isNotFactorVerify as "isNotFactorVerify"
  1987. FROM
  1988. (
  1989. SELECT
  1990. io.userid as "userId",
  1991. io.username as "userName",
  1992. count( iac.orderno ) AS "orderNumber",
  1993. sum(CASE WHEN iac.orderstatus = 3 THEN iac.jqpremium END ) AS jqpremium,
  1994. sum(CASE WHEN iac.orderstatus = 3 THEN iac.sypremium END ) AS sypremium,
  1995. sum(CASE WHEN iac.orderstatus = 3 THEN iac.jypremium END ) AS jypremium,
  1996. COUNT( CASE WHEN iac.orderstatus = 2 THEN 1 END ) AS underwritingCount,
  1997. COUNT( CASE WHEN iac.orderstatus = 3 THEN 1 END ) AS qutationInsureCount,
  1998. COUNT( CASE WHEN su.factor_verify = 1 THEN 1 END ) AS isFactorVerify,
  1999. COUNT( CASE WHEN su.factor_verify = 0 THEN 1 END ) AS isNotFactorVerify
  2000. FROM
  2001. `ins_area_company` iac
  2002. LEFT JOIN ins_orders io ON io.orderno = iac.orderno
  2003. left join sys_user su on su.id=io.userid
  2004. <where>
  2005. <if test="vo.ids != null and vo.ids.size()>0 ">
  2006. AND io.userid IN
  2007. <foreach item="item" collection="vo.ids" open="(" separator="," close=")">
  2008. #{item}
  2009. </foreach>
  2010. </if>
  2011. <if test="vo.createtimeStart != null and vo.createtimeStart!='' and vo.createtimeEnd != null and vo.createtimeEnd!=''">
  2012. AND iac.signing_time BETWEEN #{vo.createtimeStart} AND #{vo.createtimeEnd}
  2013. </if>
  2014. <if test="vo.beginDate != null and vo.beginDate!='' and vo.endDate != null and vo.endDate!=''">
  2015. AND iac.createtime BETWEEN #{vo.beginDate} AND #{vo.endDate}
  2016. </if>
  2017. <if test="vo.deptIds != null and vo.deptIds != '' and vo.deptIds.size() > 0">
  2018. AND io.deptid in
  2019. <foreach collection="vo.deptIds" item="item" open="(" separator="," close=")">
  2020. #{item}
  2021. </foreach>
  2022. </if>
  2023. <if test="vo.userIds != null and vo.userIds != '' and vo.userIds.size() > 0">
  2024. AND io.userid in
  2025. <foreach collection="vo.userIds" item="item" open="(" separator="," close=")">
  2026. #{item}
  2027. </foreach>
  2028. </if>
  2029. </where>
  2030. GROUP BY
  2031. io.userid,
  2032. io.username
  2033. ) a
  2034. left join sys_user su on su.id=a.userId
  2035. </select>
  2036. <select id="NumberQuotations" 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. left join sys_dept sd on sd.id=io.deptid
  2046. left join sys_user su on su.id=io.userid
  2047. left join ins_fee_audit ifa on ifa .ins_order_no =iac.id
  2048. <where>
  2049. sd.management_source = '2'
  2050. <if test="userId !=null and userId !=''">
  2051. and io.userId =#{userId}
  2052. </if>
  2053. </where>
  2054. </select>
  2055. <select id="totalQuotation" resultType="com.ydtech.modules.admin.model.dto.TaskStatisticsDto">
  2056. SELECT
  2057. agree.insurance_company_id AS companyId,
  2058. agree.insurance_company AS companyName,
  2059. agree.partner_companies_id AS parterCompanyId,
  2060. ins.namesimple AS parterCompanyName,
  2061. count(iac.orderstatus) AS orderNumber,
  2062. '-' as bigQutationCount,
  2063. '-' as bigUnderwritingCount,
  2064. '-' as bigCloseRate,
  2065. COUNT( CASE WHEN iac.orderstatus = 2 THEN 1 END ) AS underwritingCount,
  2066. COUNT( CASE WHEN iac.orderstatus = 3 THEN 1 END ) AS qutationInsureCount,
  2067. COUNT( CASE WHEN iac.orderstatus = 0 THEN 1 END )/ count(iac.orderstatus) AS passRate,
  2068. COUNT( CASE WHEN iac.orderstatus = 2 THEN 1 END )/ count(iac.orderstatus) AS underwritingCountRate,
  2069. COUNT( CASE WHEN iac.orderstatus = 3 THEN 1 END )/ count(iac.orderstatus) AS closeRate,
  2070. COUNT( CASE WHEN iac.orderstatus = 3 THEN 1 END )/ COUNT( CASE WHEN iac.orderstatus = 2 THEN 1 END ) AS
  2071. contributionRate
  2072. FROM
  2073. ins_area_company iac
  2074. LEFT JOIN ptl_agreement agree ON iac.agreement_id = agree.id
  2075. LEFT JOIN ins_orders io on io.orderno = iac.orderno
  2076. LEFT JOIN esm_ins_company ins ON agree.partner_companies_id = ins.id
  2077. WHERE
  2078. agree.id IS NOT NULL
  2079. <if test="vo.companyId != null and vo.companyId!='' ">
  2080. agree.insurance_company_id = #{vo.companyId}
  2081. </if>
  2082. <if test="vo.parterCompanyId != null and vo.parterCompanyId!='' ">
  2083. agree.partner_companies_id = #{vo.parterCompanyId}
  2084. </if>
  2085. <if test="vo.beginDate != null and vo.beginDate!='' and vo.endDate != null and vo.endDate!=''">
  2086. AND iac.createtime BETWEEN #{vo.beginDate} AND #{vo.endDate}
  2087. </if>
  2088. <if test="vo.provinceId != null and vo.provinceId != ''">
  2089. and io.deptid like "${vo.provinceId}%"
  2090. </if>
  2091. <if test="vo.cityId != null and vo.cityId != ''">
  2092. and io.deptid like "${vo.cityId}%"
  2093. </if>
  2094. <if test="vo.countyId != null and vo.countyId != ''">
  2095. and io.deptid like "${vo.countyId}%"
  2096. </if>
  2097. <if test="taskStatisticsVo.houseId != null and vo.houseId != ''">
  2098. and io.deptid like "${vo.houseId}%"
  2099. </if>
  2100. GROUP BY
  2101. agree.insurance_company_id,
  2102. agree.insurance_company,
  2103. agree.partner_companies_id,
  2104. ins.NAME
  2105. </select>
  2106. <select id="getBusinessData" resultType="com.ydtech.modules.admin.model.dto.TaskStatisticsDto">
  2107. select
  2108. a.companyId as "companyId",
  2109. a.insuranceCompanyName as "insuranceCompanyName",
  2110. a.parterCompanyId as "parterCompanyId",
  2111. a.partnerCompaniesName as "partnerCompaniesName",
  2112. a.totalPremium as "totalPremium",
  2113. a.qutationInsureCount as "qutationInsureCount",
  2114. ROUND(a.averagePremium, 2) as "averagePremium",
  2115. a.userNumber as "userNumber",
  2116. ROUND(a.perCapitaAmount, 2) as "perCapitaAmount",
  2117. c.docking_person as "dockingPerson",
  2118. c.docking_phone as "dockingPhone",
  2119. c.agreement_type as "agreementType",
  2120. b.logo as "logo"
  2121. from (
  2122. SELECT
  2123. agree.insurance_company_id AS "companyId",
  2124. agree.insurance_company AS "insuranceCompanyName",
  2125. agree.partner_companies_id AS "parterCompanyId",
  2126. ins.namesimple AS "partnerCompaniesName",
  2127. agree.id as "agreeId",
  2128. IFNULL(sum(iac.jqpremium),0) + IFNULL(sum(iac.sypremium),0) +IFNULL(sum(iac.jypremium),0) as "totalPremium",
  2129. COUNT(0 ) AS "qutationInsureCount",
  2130. (IFNULL(sum(iac.jqpremium),0) + IFNULL(sum(iac.sypremium),0) +IFNULL(sum(iac.jypremium),0)) / COUNT(0 ) AS "averagePremium",
  2131. COUNT(DISTINCT io.userId) AS "userNumber",
  2132. (IFNULL(sum(iac.jqpremium),0) + IFNULL(sum(iac.sypremium),0) +IFNULL(sum(iac.jypremium),0)) / COUNT(DISTINCT io.userId) as "perCapitaAmount"
  2133. FROM
  2134. ins_area_company iac
  2135. LEFT JOIN ptl_agreement agree ON iac.agreement_id = agree.id
  2136. LEFT JOIN ins_orders io on io.orderno = iac.orderno
  2137. LEFT JOIN esm_ins_company ins ON agree.partner_companies_id = ins.id
  2138. WHERE
  2139. agree.id IS NOT NULL
  2140. and iac.orderstatus = '3'
  2141. <if test="vo.companyId != null and vo.companyId!='' ">
  2142. and agree.insurance_company_id = #{vo.companyId}
  2143. </if>
  2144. <if test="vo.parterCompanyId != null and vo.parterCompanyId!='' ">
  2145. and agree.partner_companies_id = #{vo.parterCompanyId}
  2146. </if>
  2147. <if test="vo.createtimeStart != null and vo.createtimeStart!='' and vo.createtimeEnd != null and vo.createtimeEnd!=''">
  2148. 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')
  2149. </if>
  2150. <if test="vo.provinceId != null and vo.provinceId != '' and vo.cityId == null and vo.countyId == null and vo.houseId == null ">
  2151. and io.deptid like "${vo.provinceId}%"
  2152. </if>
  2153. <if test="vo.cityId != null and vo.cityId != '' and vo.countyId ==null and vo.houseId ==null">
  2154. and io.deptid like "${vo.cityId}%"
  2155. </if>
  2156. <if test="vo.countyId != null and vo.countyId != '' and vo.houseId ==null">
  2157. and io.deptid like "${vo.countyId}%"
  2158. </if>
  2159. <if test="vo.houseId != null and vo.houseId != ''">
  2160. and io.deptid like "${vo.houseId}%"
  2161. </if>
  2162. <if test="vo.deptIds != null and vo.deptIds != '' and vo.deptIds.size() > 0">
  2163. AND io.deptid in
  2164. <foreach collection="vo.deptIds" item="item" open="(" separator="," close=")">
  2165. #{item}
  2166. </foreach>
  2167. </if>
  2168. <if test="vo.userIds != null and vo.userIds != '' and vo.userIds.size() > 0">
  2169. AND io.userid in
  2170. <foreach collection="vo.userIds" item="item" open="(" separator="," close=")">
  2171. #{item}
  2172. </foreach>
  2173. </if>
  2174. GROUP BY
  2175. agree.insurance_company_id,
  2176. agree.insurance_company,
  2177. agree.partner_companies_id,
  2178. agree.id
  2179. <choose>
  2180. <when test="vo.orderSort != null and vo.orderSort != '' and vo.userNumberSort == null ">
  2181. order by
  2182. sum(sumpremium) ${vo.orderSort == 'asc' ? 'asc' : 'desc'}
  2183. </when>
  2184. <when test="vo.userNumberSort != null and vo.userNumberSort != '' and vo.orderSort == null ">
  2185. order by
  2186. COUNT(DISTINCT io.userId) ${vo.userNumberSort == 'asc' ? 'asc' : 'desc'}
  2187. </when>
  2188. <when test="vo.userNumberSort != null and vo.userNumberSort != '' and vo.orderSort != null and vo.orderSort != '' ">
  2189. order by
  2190. COUNT(DISTINCT io.userId) ${vo.userNumberSort == 'asc' ? 'asc' : 'desc'}, sum(sumpremium) ${vo.orderSort == 'asc' ? 'asc' : 'desc'}
  2191. </when>
  2192. </choose>
  2193. ) a
  2194. left join esm_ins_company b on b.id =a.companyId
  2195. left join ptl_agreement c on c.id =a.agreeId
  2196. </select>
  2197. <select id="getCountBusinessData" resultType="com.ydtech.modules.admin.model.dto.TaskStatisticsDto">
  2198. select
  2199. sum(a.totalPremium) as "totalPremium",
  2200. sum(a.qutationInsureCount) as "qutationInsureCount",
  2201. sum(ROUND(a.averagePremium, 2)) as "averagePremium",
  2202. sum(a.userNumber) as "userNumber",
  2203. count(DISTINCT a.insuranceCompanyName) as "insuranceCompanyNumber",
  2204. sum(ROUND(a.perCapitaAmount, 2)) as "perCapitaAmount"
  2205. from (
  2206. SELECT
  2207. agree.insurance_company AS "insuranceCompanyName",
  2208. IFNULL(sum(iac.jqpremium),0) + IFNULL(sum(iac.sypremium),0) +IFNULL(sum(iac.jypremium),0) as "totalPremium",
  2209. COUNT(0 ) AS "qutationInsureCount",
  2210. (IFNULL(sum(iac.jqpremium),0) + IFNULL(sum(iac.sypremium),0) +IFNULL(sum(iac.jypremium),0)) / COUNT(0 ) AS "averagePremium",
  2211. COUNT(DISTINCT io.userId) AS "userNumber",
  2212. (IFNULL(sum(iac.jqpremium),0) + IFNULL(sum(iac.sypremium),0) +IFNULL(sum(iac.jypremium),0)) / COUNT(DISTINCT io.userId) as "perCapitaAmount"
  2213. FROM
  2214. ins_area_company iac
  2215. LEFT JOIN ptl_agreement agree ON iac.agreement_id = agree.id
  2216. LEFT JOIN ins_orders io on io.orderno = iac.orderno
  2217. WHERE
  2218. agree.id IS NOT NULL
  2219. and iac.orderstatus = '3'
  2220. <if test="vo.companyId != null and vo.companyId!='' ">
  2221. and agree.insurance_company_id = #{vo.companyId}
  2222. </if>
  2223. <if test="vo.parterCompanyId != null and vo.parterCompanyId!='' ">
  2224. and agree.partner_companies_id = #{vo.parterCompanyId}
  2225. </if>
  2226. <if test="vo.createtimeStart != null and vo.createtimeStart!='' and vo.createtimeEnd != null and vo.createtimeEnd!=''">
  2227. 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')
  2228. </if>
  2229. <if test="vo.provinceId != null and vo.provinceId != '' and vo.cityId == null and vo.countyId == null and vo.houseId == null ">
  2230. and io.deptid like "${vo.provinceId}%"
  2231. </if>
  2232. <if test="vo.cityId != null and vo.cityId != '' and vo.countyId ==null and vo.houseId ==null">
  2233. and io.deptid like "${vo.cityId}%"
  2234. </if>
  2235. <if test="vo.countyId != null and vo.countyId != '' and vo.houseId ==null">
  2236. and io.deptid like "${vo.countyId}%"
  2237. </if>
  2238. <if test="vo.houseId != null and vo.houseId != ''">
  2239. and io.deptid like "${vo.houseId}%"
  2240. </if>
  2241. <if test="vo.deptIds != null and vo.deptIds != '' and vo.deptIds.size() > 0">
  2242. AND io.deptid in
  2243. <foreach collection="vo.deptIds" item="item" open="(" separator="," close=")">
  2244. #{item}
  2245. </foreach>
  2246. </if>
  2247. <if test="vo.userIds != null and vo.userIds != '' and vo.userIds.size() > 0">
  2248. AND io.userid in
  2249. <foreach collection="vo.userIds" item="item" open="(" separator="," close=")">
  2250. #{item}
  2251. </foreach>
  2252. </if>
  2253. group by
  2254. agree.insurance_company,
  2255. agree.partner_companies_id
  2256. ) a
  2257. </select>
  2258. <select id="getDistribution" resultType="com.ydtech.modules.admin.model.dto.TaskStatisticsDto">
  2259. SELECT
  2260. agree.insurance_company_id AS "companyId",
  2261. agree.insurance_company AS "insuranceCompanyName",
  2262. agree.partner_companies_id AS "parterCompanyId",
  2263. ins.namesimple AS "partnerCompaniesName",
  2264. IFNULL(sum(iac.jqpremium),0) + IFNULL(sum(iac.sypremium),0) +IFNULL(sum(iac.jypremium),0) as "totalPremium",
  2265. COUNT(0) AS "qutationInsureCount",
  2266. ROUND((IFNULL(sum(iac.jqpremium),0) + IFNULL(sum(iac.sypremium),0) +IFNULL(sum(iac.jypremium),0)) / COUNT(0), 2) AS "averagePremium",
  2267. COUNT(DISTINCT io.userId) AS "userNumber",
  2268. ROUND((IFNULL(sum(iac.jqpremium),0) + IFNULL(sum(iac.sypremium),0) +IFNULL(sum(iac.jypremium),0)) / COUNT(DISTINCT io.userId) ,2) as "perCapitaAmount"
  2269. FROM
  2270. ins_area_company iac
  2271. LEFT JOIN ptl_agreement agree ON iac.agreement_id = agree.id
  2272. LEFT JOIN ins_orders io on io.orderno = iac.orderno
  2273. LEFT JOIN esm_ins_company ins ON agree.partner_companies_id = ins.id
  2274. WHERE
  2275. agree.id IS NOT NULL
  2276. <if test="vo.companyId != null and vo.companyId!='' ">
  2277. and agree.insurance_company_id = #{vo.companyId}
  2278. </if>
  2279. <if test="vo.parterCompanyId != null and vo.parterCompanyId!='' ">
  2280. and agree.partner_companies_id = #{vo.parterCompanyId}
  2281. </if>
  2282. <if test="vo.createtimeStart != null and vo.createtimeStart!='' and vo.createtimeEnd != null and vo.createtimeEnd!=''">
  2283. 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')
  2284. </if>
  2285. <if test="vo.days !=null and vo.days !='' and vo.days != 0 ">
  2286. and iac.createtime >= DATE_SUB(NOW(), INTERVAL #{vo.days} DAY)
  2287. </if>
  2288. <if test="vo.provinceId != null and vo.provinceId != ''">
  2289. and io.deptid like "${vo.provinceId}%"
  2290. </if>
  2291. <if test="vo.cityId != null and vo.cityId != ''">
  2292. and io.deptid like "${vo.cityId}%"
  2293. </if>
  2294. <if test="vo.countyId != null and vo.countyId != ''">
  2295. and io.deptid like "${vo.countyId}%"
  2296. </if>
  2297. <if test="vo.houseId != null and vo.houseId != ''">
  2298. and io.deptid like "${vo.houseId}%"
  2299. </if>
  2300. <if test="vo.quotationStatus != null and vo.quotationStatus != ''">
  2301. and iac.orderstatus =#{vo.quotationStatus}
  2302. </if>
  2303. <if test="vo.deptIds != null and vo.deptIds != '' and vo.deptIds.size() > 0">
  2304. AND io.deptid in
  2305. <foreach collection="vo.deptIds" item="item" open="(" separator="," close=")">
  2306. #{item}
  2307. </foreach>
  2308. </if>
  2309. <if test="vo.userIds != null and vo.userIds != '' and vo.userIds.size() > 0">
  2310. AND io.userid in
  2311. <foreach collection="vo.userIds" item="item" open="(" separator="," close=")">
  2312. #{item}
  2313. </foreach>
  2314. </if>
  2315. <if test="vo.riskCode != null and vo.riskCode != '' and vo.riskCode != 'all'">
  2316. and iac.product = #{vo.riskCode}
  2317. </if>
  2318. GROUP BY
  2319. agree.insurance_company_id,
  2320. agree.insurance_company,
  2321. agree.partner_companies_id,
  2322. ins.namesimple
  2323. </select>
  2324. <select id="getOrderPremiumByUserIds" resultType="Double">
  2325. SELECT
  2326. IFNULL(
  2327. SUM( IFNULL( iac.jqpremium, 0 ) + IFNULL( iac.sypremium, 0 ) + IFNULL( iac.jypremium, 0 ) ),
  2328. 0
  2329. ) AS "totalPremium"
  2330. FROM
  2331. `ins_area_company` iac
  2332. LEFT JOIN ins_orders io ON io.orderno = iac.orderno
  2333. <where>
  2334. iac.orderstatus = '3'
  2335. <if test="vo.ids != null and vo.ids.size()>0 ">
  2336. AND io.userid IN
  2337. <foreach item="item" collection="vo.ids" open="(" separator="," close=")">
  2338. #{item}
  2339. </foreach>
  2340. </if>
  2341. <if test="vo.createtimeStart != null and vo.createtimeStart!='' and vo.createtimeEnd != null and vo.createtimeEnd!=''">
  2342. AND iac.signing_time BETWEEN #{vo.createtimeStart} AND #{vo.createtimeEnd}
  2343. </if>
  2344. </where>
  2345. </select>
  2346. <select id="querOrdersDataPage" resultType="com.ydtech.modules.admin.model.report.company.OrdersDataDto">
  2347. SELECT
  2348. count( 0 ) AS "orderNumber",
  2349. b.licenseno as "licenseno",
  2350. b.frameno as "frameno",
  2351. b.modelCode as "modelCode",
  2352. b.modelcname as "modelcname"
  2353. FROM
  2354. (
  2355. SELECT
  2356. io.orderstatus AS orderstatus,
  2357. io.frameno AS frameno,
  2358. REPLACE(JSON_EXTRACT(io.carinfo, '$.engineNo'), '"', '') as "modelCode",
  2359. REPLACE(JSON_EXTRACT(io.carinfo, '$.modelcname'), '"', '') as "modelcname",
  2360. ifnull(io.licenseno, '') AS licenseno
  2361. FROM
  2362. ins_orders io
  2363. LEFT JOIN sys_user su on io.userid=su.id
  2364. <where>
  2365. 1=1
  2366. <if test="vo.beginDate != null and vo.beginDate!='' and vo.endDate != null and vo.endDate!=''">
  2367. AND io.createtime BETWEEN #{vo.beginDate} AND #{vo.endDate}
  2368. </if>
  2369. <if test="vo.licenseno != null and vo.licenseno!='' ">
  2370. AND io.licenseno =#{vo.licenseno}
  2371. </if>
  2372. <if test="vo.userId != null and vo.userId!='' ">
  2373. AND io.userid =#{vo.userId}
  2374. </if>
  2375. <if test="vo.userName != null and vo.userName!='' ">
  2376. AND su.name =#{vo.userName}
  2377. </if>
  2378. <if test="vo.mobile != null and vo.mobile!='' ">
  2379. AND su.mobile =#{vo.mobile}
  2380. </if>
  2381. <if test="vo.frameno != null and vo.frameno!='' ">
  2382. AND io.frameno =#{vo.frameno}
  2383. </if>
  2384. <if test="vo.deptId != null and vo.deptId!='' ">
  2385. and io.deptid like concat('%', #{vo.deptId}, '%')
  2386. </if>
  2387. <if test="vo.year != null and vo.year!='' ">
  2388. AND DATE_FORMAT( io.createtime, '%Y') =#{vo.year}
  2389. </if>
  2390. <if test="vo.deptIds != null and vo.deptIds != '' and vo.deptIds.size() > 0">
  2391. AND io.deptid in
  2392. <foreach collection="vo.deptIds" item="item" open="(" separator="," close=")">
  2393. #{item}
  2394. </foreach>
  2395. </if>
  2396. <if test="vo.userIds != null and vo.userIds != '' and vo.userIds.size() > 0">
  2397. AND io.userid in
  2398. <foreach collection="vo.userIds" item="item" open="(" separator="," close=")">
  2399. #{item}
  2400. </foreach>
  2401. </if>
  2402. </where>
  2403. ) b
  2404. GROUP BY
  2405. b.licenseno,
  2406. b.frameno,
  2407. b.modelCode,
  2408. b.modelcname
  2409. </select>
  2410. <select id="getOrdersGroupByLicenseno" resultType="com.ydtech.modules.admin.model.report.company.OrdersDataDto">
  2411. SELECT
  2412. io.licenseno AS "licenseno",
  2413. io.frameno AS "frameno",
  2414. io.orderstatus as "orderstatus",
  2415. io.orderno as "orderno"
  2416. FROM
  2417. ins_orders io
  2418. LEFT JOIN sys_user su on io.userid=su.id
  2419. <where>
  2420. io.licenseno is not null
  2421. <if test="vo.beginDate != null and vo.beginDate!='' and vo.endDate != null and vo.endDate!=''">
  2422. AND io.createtime BETWEEN #{vo.beginDate} AND #{vo.endDate}
  2423. </if>
  2424. <if test="vo.licenseno != null and vo.licenseno!='' ">
  2425. AND io.licenseno =#{vo.licenseno}
  2426. </if>
  2427. <if test="vo.userId != null and vo.userId!='' ">
  2428. AND io.userId =#{vo.userId}
  2429. </if>
  2430. <if test="vo.userName != null and vo.userName!='' ">
  2431. AND su.name =#{vo.userName}
  2432. </if>
  2433. <if test="vo.mobile != null and vo.mobile!='' ">
  2434. AND su.mobile =#{vo.mobile}
  2435. </if>
  2436. <if test="vo.frameno != null and vo.frameno!='' ">
  2437. AND su.frameno =#{vo.frameno}
  2438. </if>
  2439. <if test="vo.deptId != null and vo.deptId!='' ">
  2440. and io.deptid like concat('%', #{vo.deptId}, '%')
  2441. </if>
  2442. </where>
  2443. </select>
  2444. <select id="querOrdersamountTo" resultType="com.ydtech.modules.admin.model.report.company.OrdersDataDto">
  2445. select sum(a.orderNumber) as "orderNumber",
  2446. count(a.licenseno) as "b.frameno"
  2447. from (
  2448. SELECT
  2449. count( 0 ) AS "orderNumber",
  2450. b.licenseno as "licenseno",
  2451. b.frameno as "frameno"
  2452. FROM
  2453. (
  2454. SELECT
  2455. io.orderstatus AS orderstatus,
  2456. io.frameno AS frameno,
  2457. ifnull(io.licenseno, '') AS licenseno
  2458. FROM
  2459. ins_orders io
  2460. LEFT JOIN sys_user su on io.userid=su.id
  2461. <where>
  2462. 1=1
  2463. <if test="vo.beginDate != null and vo.beginDate!='' and vo.endDate != null and vo.endDate!=''">
  2464. AND io.createtime BETWEEN #{vo.beginDate} AND #{vo.endDate}
  2465. </if>
  2466. <if test="vo.licenseno != null and vo.licenseno!='' ">
  2467. AND io.licenseno =#{vo.licenseno}
  2468. </if>
  2469. <if test="vo.userId != null and vo.userId!='' ">
  2470. AND io.userid =#{vo.userId}
  2471. </if>
  2472. <if test="vo.userName != null and vo.userName!='' ">
  2473. AND su.name =#{vo.userName}
  2474. </if>
  2475. <if test="vo.mobile != null and vo.mobile!='' ">
  2476. AND su.mobile =#{vo.mobile}
  2477. </if>
  2478. <if test="vo.frameno != null and vo.frameno!='' ">
  2479. AND io.frameno =#{vo.frameno}
  2480. </if>
  2481. <if test="vo.deptId != null and vo.deptId!='' ">
  2482. and io.deptid like concat('%', #{vo.deptId}, '%')
  2483. </if>
  2484. </where>
  2485. ) b
  2486. GROUP BY
  2487. b.licenseno,
  2488. b.frameno
  2489. ) a
  2490. </select>
  2491. <select id="querResultOrderNumber" resultType="com.ydtech.modules.admin.model.report.company.OrdersDataDto">
  2492. SELECT
  2493. count( io.orderno ) AS "orderNumber",
  2494. 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"
  2495. FROM
  2496. ins_orders io
  2497. LEFT JOIN ins_area_company iac ON iac.orderno = io.orderno
  2498. LEFT JOIN sys_user su ON io.userid = su.id
  2499. <where>
  2500. 1=1
  2501. <if test="vo.beginDate != null and vo.beginDate!='' and vo.endDate != null and vo.endDate!=''">
  2502. AND io.createtime BETWEEN #{vo.beginDate} AND #{vo.endDate}
  2503. </if>
  2504. <if test="vo.licenseno != null and vo.licenseno!='' ">
  2505. AND io.licenseno =#{vo.licenseno}
  2506. </if>
  2507. <if test="vo.userId != null and vo.userId!='' ">
  2508. AND io.userid =#{vo.userId}
  2509. </if>
  2510. <if test="vo.userName != null and vo.userName!='' ">
  2511. AND su.name =#{vo.userName}
  2512. </if>
  2513. <if test="vo.mobile != null and vo.mobile!='' ">
  2514. AND su.mobile =#{vo.mobile}
  2515. </if>
  2516. <if test="vo.frameno != null and vo.frameno!='' ">
  2517. AND su.frameno =#{vo.frameno}
  2518. </if>
  2519. <if test="vo.deptId != null and vo.deptId!='' ">
  2520. and io.deptid like concat('%', #{vo.deptId}, '%')
  2521. </if>
  2522. </where>
  2523. </select>
  2524. <select id="numberQuotationsByUserIds" resultType="com.ydtech.modules.admin.model.dto.TaskStatisticsDto">
  2525. SELECT
  2526. count(iac.id) as "orderNumber",
  2527. COUNT( CASE WHEN iac.orderstatus = 2 THEN 1 END ) AS underwritingCount,
  2528. COUNT( CASE WHEN iac.orderstatus = 3 THEN 1 END ) AS qutationInsureCount,
  2529. sum( CASE WHEN iac.orderstatus = 3 THEN IFNULL(iac.jqpremium, 0) + IFNULL(iac.sypremium, 0) + IFNULL(iac.jypremium, 0) END ) AS totalPremium
  2530. FROM
  2531. ins_area_company iac
  2532. left join ins_orders io on io.orderno = iac.orderno
  2533. <where>
  2534. <if test="ids != null and ids.size()>0 ">
  2535. AND io.userid IN
  2536. <foreach item="item" collection="ids" open="(" separator="," close=")">
  2537. #{item}
  2538. </foreach>
  2539. </if>
  2540. <if test="month != null and month!='' ">
  2541. AND DATE_FORMAT(iac.createtime, '%Y-%m') =#{month}
  2542. </if>
  2543. </where>
  2544. </select>
  2545. <select id="selectByOrdersDataVo" resultType="com.ydtech.modules.admin.model.report.company.OrdersDataDto">
  2546. select
  2547. iac.inscompany as "namesimple"
  2548. from
  2549. ins_area_company iac
  2550. <where>
  2551. 1=1
  2552. <if test="vo.orderstatus != null and vo.orderstatus != '' ">
  2553. AND iac.orderstatus =#{vo.orderstatus}
  2554. </if>
  2555. <if test="vo.orderno !=null and vo.orderno !='' ">
  2556. AND iac.orderno =#{vo.orderno}
  2557. </if>
  2558. </where>
  2559. </select>
  2560. <select id="channelExcel" resultType="com.ydtech.modules.admin.model.dto.TaskStatisticsExcel">
  2561. select a.*,(select name from sys_user where id =a.userId) as "userName"
  2562. from (
  2563. SELECT
  2564. sd.NAME AS "deptName",
  2565. io.userid AS "userId",
  2566. sd.parent_id as "deptId",
  2567. COUNT( CASE WHEN iac.orderstatus = 0 THEN 1 END ) AS qutationCount,
  2568. COUNT( CASE WHEN iac.orderstatus = 2 THEN 1 END ) AS underwritingCount,
  2569. COUNT( CASE WHEN iac.orderstatus = 3 THEN 1 END ) AS qutationInsureCount,
  2570. COUNT( CASE WHEN iac.orderstatus = 4 THEN 1 END ) AS underwritingReturn,
  2571. (COUNT( CASE WHEN iac.orderstatus = 2 THEN 1 END ) / COUNT( CASE WHEN iac.orderstatus = 0 THEN 1 END )) * 100 AS "passingRate",
  2572. (COUNT( CASE WHEN iac.orderstatus = 3 THEN 1 END ) / COUNT( iac.orderstatus )) * 100 AS "closeRate",
  2573. ((COUNT( CASE WHEN iac.orderstatus = 3 THEN 1 END ) + COUNT( CASE WHEN iac.orderstatus = 2 THEN 1 END ))/ COUNT( iac.orderstatus )) * 100 AS "contributionRate",
  2574. (COUNT( CASE WHEN iac.orderstatus = 0 THEN 1 END ) / COUNT( iac.orderstatus )) * 100 AS "quotationRate",
  2575. COUNT( CASE WHEN iac.orderstatus = 1 THEN 1 END ) AS "auditOrder"
  2576. FROM
  2577. ins_area_company iac
  2578. LEFT JOIN ins_orders io ON io.orderno = iac.orderno
  2579. LEFT JOIN sys_dept sd ON sd.id = io.deptid
  2580. <where>
  2581. 1=1
  2582. <if test="taskStatisticsVo.provinceId != null and taskStatisticsVo.provinceId != ''">
  2583. and io.deptid like "${taskStatisticsVo.provinceId}%"
  2584. </if>
  2585. <if test="taskStatisticsVo.cityId != null and taskStatisticsVo.cityId != ''">
  2586. and io.deptid like "${taskStatisticsVo.cityId}%"
  2587. </if>
  2588. <if test="taskStatisticsVo.countyId != null and taskStatisticsVo.countyId != ''">
  2589. and io.deptid like "${taskStatisticsVo.countyId}%"
  2590. </if>
  2591. <if test="taskStatisticsVo.houseId != null and taskStatisticsVo.houseId != ''">
  2592. and io.deptid like "${taskStatisticsVo.houseId}%"
  2593. </if>
  2594. <if test="taskStatisticsVo.createtimeStart !=null and taskStatisticsVo.createtimeStart != '' and taskStatisticsVo.createtimeEnd !=null and taskStatisticsVo.createtimeEnd != ''">
  2595. AND DATE_FORMAT( io.createtime, '%Y-%m-%d') BETWEEN #{taskStatisticsVo.createtimeStart} AND #{taskStatisticsVo.createtimeEnd}
  2596. </if>
  2597. <if test="taskStatisticsVo.beginDate !=null and taskStatisticsVo.beginDate != '' and taskStatisticsVo.endDate !=null and taskStatisticsVo.endDate != ''">
  2598. AND DATE_FORMAT( iac.createtime, '%Y-%m-%d') BETWEEN DATE_FORMAT( #{taskStatisticsVo.beginDate}, '%Y-%m-%d') AND DATE_FORMAT( #{taskStatisticsVo.endDate}, '%Y-%m-%d')
  2599. </if>
  2600. <if test="taskStatisticsVo.days !=null and taskStatisticsVo.days !='' ">
  2601. and iac.createtime >= DATE_SUB(NOW(), INTERVAL #{taskStatisticsVo.days} DAY)
  2602. </if>
  2603. <if test="taskStatisticsVo.managementSource!=null and taskStatisticsVo.managementSource!=''">
  2604. and sd.management_source=#{taskStatisticsVo.managementSource}
  2605. </if>
  2606. <if test="taskStatisticsVo.days !=null and taskStatisticsVo.days !='' ">
  2607. <choose>
  2608. <when test="taskStatisticsVo.days =='1'">
  2609. and io.createtime >= DATE_SUB(NOW(), INTERVAL 1 DAY)
  2610. </when>
  2611. <when test="taskStatisticsVo.days =='7'">
  2612. and io.createtime >= DATE_SUB(NOW(), INTERVAL 7 DAY)
  2613. </when>
  2614. <when test="taskStatisticsVo.days =='30'">
  2615. and io.createtime >= DATE_SUB(NOW(), INTERVAL 30 DAY)
  2616. </when>
  2617. </choose>
  2618. </if>
  2619. </where>
  2620. GROUP BY
  2621. io.userid,
  2622. sd.NAME,
  2623. sd.id
  2624. ) a
  2625. </select>
  2626. <select id="insuranceCompanyExcel" resultType="com.ydtech.modules.admin.model.dto.InsuranceCompanyExcel">
  2627. SELECT
  2628. a.*,
  2629. ( SELECT eic.namesimple FROM esm_ins_company eic WHERE eic.id = a.partner_companies_id ) AS "partnerCompaniesName"
  2630. FROM
  2631. (
  2632. SELECT
  2633. pa.insurance_company_id,
  2634. pa.partner_companies_id,
  2635. pa.insurance_company AS "insuranceCompanyName",
  2636. COUNT( CASE WHEN iac.orderstatus = 0 THEN 1 END ) AS qutationCount,
  2637. COUNT( CASE WHEN iac.orderstatus = 2 THEN 1 END ) AS underwritingCountRate,
  2638. COUNT( CASE WHEN iac.orderstatus = 3 THEN 1 END ) AS qutationInsureCount,
  2639. COUNT( CASE WHEN iac.orderstatus = 4 THEN 1 END ) AS underwritingReturn,
  2640. COUNT( CASE WHEN iac.orderstatus = 2 THEN 1 END ) / COUNT( CASE WHEN iac.orderstatus = 0 THEN 1 END ) AS "passingRate",
  2641. COUNT( CASE WHEN iac.orderstatus = 3 THEN 1 END ) / COUNT( CASE WHEN iac.orderstatus = 0 THEN 1 END ) AS "closeRate",
  2642. COUNT( CASE WHEN iac.orderstatus = 3 THEN 1 END ) / COUNT( iac.orderstatus ) AS "contributionRate",
  2643. COUNT( CASE WHEN iac.orderstatus = 0 THEN 1 END ) / COUNT( iac.orderstatus ) AS "quotationRate",
  2644. COUNT( CASE WHEN iac.orderstatus = 1 THEN 1 END ) AS "auditOrder"
  2645. FROM
  2646. ins_area_company iac
  2647. LEFT JOIN ins_fee_audit ifa ON ifa.ins_order_no = iac.id
  2648. LEFT JOIN ptl_agreement pa ON pa.id = iac.agreement_id
  2649. <where>
  2650. pa.insurance_company_id IS NOT NULL
  2651. <if test="taskStatisticsVo.provinceId != null and taskStatisticsVo.provinceId != ''">
  2652. and io.deptid like "${taskStatisticsVo.provinceId}%"
  2653. </if>
  2654. <if test="taskStatisticsVo.cityId != null and taskStatisticsVo.cityId != ''">
  2655. and io.deptid like "${taskStatisticsVo.cityId}%"
  2656. </if>
  2657. <if test="taskStatisticsVo.countyId != null and taskStatisticsVo.countyId != ''">
  2658. and io.deptid like "${taskStatisticsVo.countyId}%"
  2659. </if>
  2660. <if test="taskStatisticsVo.houseId != null and taskStatisticsVo.houseId != ''">
  2661. and io.deptid like "${taskStatisticsVo.houseId}%"
  2662. </if>
  2663. <if test="taskStatisticsVo.createtimeStart !=null and taskStatisticsVo.createtimeStart != '' and taskStatisticsVo.createtimeEnd !=null and taskStatisticsVo.createtimeEnd != ''">
  2664. AND DATE_FORMAT( iac.createtime, '%Y-%m-%d') BETWEEN DATE_FORMAT(#{taskStatisticsVo.createtimeStart},'%Y-%m-%d') AND DATE_FORMAT( #{taskStatisticsVo.createtimeEnd}, '%Y-%m-%d')
  2665. </if>
  2666. <if test="taskStatisticsVo.beginDate !=null and taskStatisticsVo.beginDate != '' and taskStatisticsVo.endDate !=null and taskStatisticsVo.endDate != ''">
  2667. AND DATE_FORMAT( iac.createtime, '%Y-%m-%d') BETWEEN DATE_FORMAT( #{taskStatisticsVo.beginDate}, '%Y-%m-%d') AND DATE_FORMAT( #{taskStatisticsVo.endDate}, '%Y-%m-%d')
  2668. </if>
  2669. <if test="taskStatisticsVo.companyId !=null and taskStatisticsVo.companyId != ''">
  2670. AND iac.company_id =#{taskStatisticsVo.companyId}
  2671. </if>
  2672. <if test="taskStatisticsVo.days !=null and taskStatisticsVo.days !='' ">
  2673. and iac.createtime >= DATE_SUB(NOW(), INTERVAL #{taskStatisticsVo.days} DAY)
  2674. </if>
  2675. </where>
  2676. GROUP BY
  2677. pa.insurance_company_id,
  2678. pa.partner_companies_id,
  2679. pa.insurance_company
  2680. ) a
  2681. </select>
  2682. <select id="getSumBigOrderCount" resultType="com.ydtech.modules.admin.model.report.company.OrdersDataDto">
  2683. select count(0) as "orderNumber",
  2684. GROUP_CONCAT(inscompany ORDER BY inscompany SEPARATOR ',') as "namesimple"
  2685. from ins_area_company iac
  2686. left join ins_orders io on io.orderno = iac.orderno
  2687. <where>
  2688. 1=1
  2689. and iac.orderstatus ='3'
  2690. and io.orderstatus ='3'
  2691. <if test="vo.licenseno !=null and vo.licenseno!=''">
  2692. AND io.licenseno =#{vo.licenseno}
  2693. </if>
  2694. <if test="vo.frameno !=null and vo.frameno!=''">
  2695. AND io.frameno =#{vo.frameno}
  2696. </if>
  2697. <if test="vo.beginDate != null and vo.beginDate!='' and vo.endDate != null and vo.endDate!=''">
  2698. AND io.createtime BETWEEN #{vo.beginDate} AND #{vo.endDate}
  2699. </if>
  2700. <if test="vo.year != null and vo.year!='' ">
  2701. AND DATE_FORMAT( io.createtime, '%Y') =#{vo.year}
  2702. </if>
  2703. </where>
  2704. limit 10
  2705. </select>
  2706. <select id="queryAgencyUserInsAreaPage" resultType="com.ydtech.modules.admin.model.vo.AgencyUserInsAreaVo">
  2707. select
  2708. io.userid as userId,
  2709. io.username as userName,
  2710. io.licenseno as licenseno,
  2711. iac.id as companyId,
  2712. iac.jqpremium as jqpremium,
  2713. iac.sypremium as sypremium,
  2714. iac.jypremium as jypremium,
  2715. iac.createtime as createtime,
  2716. iac.orderstatus as orderstatus
  2717. from ins_area_company iac
  2718. left join ins_orders io on io.orderno = iac.orderno
  2719. <where>
  2720. iac.orderstatus=3
  2721. <if test="dto.userId !=null and dto.userId !=''">
  2722. and io.userid = #{dto.userId}
  2723. </if>
  2724. <if test="dto.deptId !=null and dto.deptId !=''">
  2725. and io.deptid like concat( #{dto.deptId}, '%')
  2726. </if>
  2727. <if test="dto.startTime !=null and dto.startTime !=''">
  2728. and io.createtime >= #{dto.startTime}
  2729. </if>
  2730. </where>
  2731. ORDER BY iac.createtime
  2732. </select>
  2733. <select id="querOrdersDataListExcel" resultType="com.ydtech.modules.admin.model.dto.OrdersDataExcel">
  2734. SELECT
  2735. count( 0 ) AS "orderNumber",
  2736. b.licenseno as "licenseno",
  2737. b.frameno as "frameno",
  2738. b.modelCode as "modelCode",
  2739. b.modelcname as "modelcname"
  2740. FROM
  2741. (
  2742. SELECT
  2743. io.orderstatus AS orderstatus,
  2744. io.frameno AS frameno,
  2745. REPLACE(JSON_EXTRACT(io.carinfo, '$.engineNo'), '"', '') as "modelCode",
  2746. REPLACE(JSON_EXTRACT(io.carinfo, '$.modelcname'), '"', '') as "modelcname",
  2747. ifnull(io.licenseno, '') AS licenseno
  2748. FROM
  2749. ins_orders io
  2750. LEFT JOIN sys_user su on io.userid=su.id
  2751. <where>
  2752. 1=1
  2753. <if test="vo.beginDate != null and vo.beginDate!='' and vo.endDate != null and vo.endDate!=''">
  2754. AND io.createtime BETWEEN #{vo.beginDate} AND #{vo.endDate}
  2755. </if>
  2756. <if test="vo.licenseno != null and vo.licenseno!='' ">
  2757. AND io.licenseno =#{vo.licenseno}
  2758. </if>
  2759. <if test="vo.userId != null and vo.userId!='' ">
  2760. AND io.userid =#{vo.userId}
  2761. </if>
  2762. <if test="vo.userName != null and vo.userName!='' ">
  2763. AND su.name =#{vo.userName}
  2764. </if>
  2765. <if test="vo.mobile != null and vo.mobile!='' ">
  2766. AND su.mobile =#{vo.mobile}
  2767. </if>
  2768. <if test="vo.frameno != null and vo.frameno!='' ">
  2769. AND io.frameno =#{vo.frameno}
  2770. </if>
  2771. <if test="vo.deptId != null and vo.deptId!='' ">
  2772. and io.deptid like concat('%', #{vo.deptId}, '%')
  2773. </if>
  2774. <if test="vo.year != null and vo.year!='' ">
  2775. AND DATE_FORMAT( io.createtime, '%Y') =#{vo.year}
  2776. </if>
  2777. <if test="vo.deptIds != null and vo.deptIds != '' and vo.deptIds.size() > 0">
  2778. AND io.deptid in
  2779. <foreach collection="vo.deptIds" item="item" open="(" separator="," close=")">
  2780. #{item}
  2781. </foreach>
  2782. </if>
  2783. <if test="vo.userIds != null and vo.userIds != '' and vo.userIds.size() > 0">
  2784. AND io.userid in
  2785. <foreach collection="vo.userIds" item="item" open="(" separator="," close=")">
  2786. #{item}
  2787. </foreach>
  2788. </if>
  2789. </where>
  2790. ) b
  2791. GROUP BY
  2792. b.licenseno,
  2793. b.frameno,
  2794. b.modelCode,
  2795. b.modelcname
  2796. </select>
  2797. <select id="orderCheckPage" resultType="com.ydtech.modules.order.entity.InsAreaCompany">
  2798. select
  2799. iac.id,
  2800. iac.orderno,
  2801. iac.agreement_id,
  2802. iac.jqpremium,
  2803. iac.sypremium,
  2804. iac.jypremium,
  2805. iac.taxamount,
  2806. iac.sumpremium,
  2807. io.licenseno,
  2808. iac.createtime,
  2809. su.name as auditname
  2810. FROM
  2811. ins_area_company iac
  2812. LEFT JOIN
  2813. ins_orders io on iac.orderno = io.orderno
  2814. left join ptl_agreement agree on iac.agreement_id =agree.id
  2815. left join ins_fee_audit ifa on iac.id = ifa.ins_order_no
  2816. left join sys_user su on su.id= ifa.audituser
  2817. WHERE
  2818. iac.operator_id = #{userId}
  2819. AND
  2820. iac.orderstatus = 3
  2821. and agree.is_external =1
  2822. and auditstatus =1
  2823. <if test="vo.id != null and vo.id!='' ">
  2824. and iac.id = #{vo.id}
  2825. </if>
  2826. <if test="vo.licenseno != null and vo.licenseno!='' ">
  2827. and io.licenseno like CONCAT('%', #{vo.licenseno}, '%')
  2828. </if>
  2829. </select>
  2830. <select id="costCenterTotal" resultType="java.util.HashMap">
  2831. SELECT
  2832. COUNT( CASE WHEN ifa.auditstatus = 1 THEN 1 END ) AS "allAuditstatusOrders",
  2833. COUNT( CASE WHEN ifa.auditstatus = 0 THEN 1 END ) AS "allAuditOrder",
  2834. COUNT( CASE WHEN ifa.auditstatus = 1 and ifa.audituser != '自动审核' THEN 1 END ) AS "allPersionAudit",
  2835. COUNT( CASE WHEN ifa.audituser = '自动审核' THEN 1 END ) AS "allAutomaticAudit"
  2836. FROM
  2837. ins_fee_audit ifa
  2838. LEFT JOIN ins_orders io ON io.orderno = ifa.orderno
  2839. LEFT JOIN ins_area_company iac ON iac.orderno = io.orderno
  2840. AND iac.orderstatus = 3
  2841. LEFT JOIN ptl_agreement pa ON pa.id = iac.agreement_id
  2842. LEFT JOIN esm_ins_company eic ON eic.id = pa.partner_companies_id
  2843. left join sys_user su on su.id =ifa.audituser
  2844. <where>
  2845. 1=1
  2846. and iac.id = ifa.ins_order_no
  2847. AND iac.orderstatus = 3
  2848. <if test="taskStatisticsVo.reviewer !=null and taskStatisticsVo.reviewer !=''">
  2849. and su.name =#{taskStatisticsVo.reviewer}
  2850. </if>
  2851. <if test="taskStatisticsVo.audittime !=null and taskStatisticsVo.audittime !=''">
  2852. and ifa.audittime =#{taskStatisticsVo.audittime}
  2853. </if>
  2854. <if test="taskStatisticsVo.companyId !=null and taskStatisticsVo.companyId !=''">
  2855. and iac.company_id =#{taskStatisticsVo.companyId}
  2856. </if>
  2857. <if test="taskStatisticsVo.createtimeStart !=null and taskStatisticsVo.createtimeStart != '' and taskStatisticsVo.createtimeEnd !=null and taskStatisticsVo.createtimeEnd != ''">
  2858. AND DATE_FORMAT( iac.signing_time, '%Y-%m-%d') BETWEEN DATE_FORMAT( #{taskStatisticsVo.createtimeStart}, '%Y-%m-%d') AND DATE_FORMAT( #{taskStatisticsVo.createtimeEnd}, '%Y-%m-%d')
  2859. </if>
  2860. <if test="taskStatisticsVo.beginDate !=null and taskStatisticsVo.beginDate != '' and taskStatisticsVo.endDate !=null and taskStatisticsVo.endDate != ''">
  2861. 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')
  2862. </if>
  2863. <if test="taskStatisticsVo.deptIds != null and taskStatisticsVo.deptIds != '' and taskStatisticsVo.deptIds.size() > 0">
  2864. AND io.deptid in
  2865. <foreach collection="taskStatisticsVo.deptIds" item="item" open="(" separator="," close=")">
  2866. #{item}
  2867. </foreach>
  2868. </if>
  2869. <if test="taskStatisticsVo.userIds != null and taskStatisticsVo.userIds != '' and taskStatisticsVo.userIds.size() > 0">
  2870. AND su.id in
  2871. <foreach collection="taskStatisticsVo.userIds" item="item" open="(" separator="," close=")">
  2872. #{item}
  2873. </foreach>
  2874. </if>
  2875. <choose>
  2876. <when test="taskStatisticsVo.riskCode != null and taskStatisticsVo.riskCode != '' and taskStatisticsVo.riskCode != 'all' ">
  2877. and iac.product = #{taskStatisticsVo.riskCode}
  2878. </when>
  2879. </choose>
  2880. </where>
  2881. </select>
  2882. <select id="getSubOrderCountDTO" resultType="com.ydtech.modules.order.entity.dto.SubOrderCountDTO">
  2883. select orderno, orderstatus, count(*)as count
  2884. from (select orderno, company_id, orderstatus
  2885. from ins_area_company
  2886. where orderno in
  2887. <foreach collection="orderNo" open="(" separator="," close=")" item="item" index="index">
  2888. #{item,jdbcType=VARCHAR}
  2889. </foreach>
  2890. and del_flag = '1'
  2891. group by orderno, company_id, orderstatus) as iac
  2892. group by orderno, orderstatus
  2893. </select>
  2894. <select id="getAllRejectOrders" resultType="com.ydtech.modules.order.entity.InsAreaCompany">
  2895. select
  2896. iac.id,
  2897. iac.orderno,
  2898. iac.agreement_id,
  2899. iac.jqpremium,
  2900. iac.sypremium,
  2901. iac.jypremium,
  2902. iac.taxamount,
  2903. iac.sumpremium,
  2904. io.licenseno,
  2905. ifa.audittime,
  2906. ifa.audituser as auditname,
  2907. ifa.rejectinfo,
  2908. "1" as orderExternalStatus
  2909. FROM
  2910. ins_fee_audit ifa
  2911. LEFT JOIN
  2912. ins_area_company iac on iac.id = ifa.ins_order_no
  2913. LEFT JOIN
  2914. ins_orders io on iac.orderno = io.orderno
  2915. left join
  2916. sys_user su on su.id= ifa.audituser
  2917. WHERE
  2918. ifa.auditstatus = 2 and IFNULL(iac.del_flag,'') != '0'
  2919. <if test="vo.id != null and vo.id!=''">
  2920. and iac.id = #{vo.id}
  2921. </if>
  2922. <if test="vo.licenseno != null and vo.licenseno!='' ">
  2923. and io.licenseno like CONCAT('%', #{vo.licenseno}, '%')
  2924. </if>
  2925. <if test="vo.auditname != null and vo.auditname!='' ">
  2926. and su.name like CONCAT('%', #{vo.auditname}, '%')
  2927. </if>
  2928. order by io.createtime
  2929. </select>
  2930. <select id="queryPageOrderCB" resultType="com.ydtech.modules.order.entity.InsOrders">
  2931. SELECT
  2932. iac.id as orderno,
  2933. io.quoteno,
  2934. io.orderstatus,
  2935. io.company_id,
  2936. io.ins_company,
  2937. io.carinfo,
  2938. io.userid,
  2939. io.username,
  2940. io.deptid,
  2941. io.deptname,
  2942. io.agreeid,
  2943. iac.productid,
  2944. iac.product,
  2945. iac.createtime,
  2946. io.frameno,
  2947. io.licenseno,
  2948. JSON_UNQUOTE(json_extract(io.insureinfo, '$.name')) as insuredname,
  2949. io.is_external,
  2950. iac.jq_start_date as jqstartdate,
  2951. iac.jq_end_date as jqenddate,
  2952. iac.sy_start_date as systartdate,
  2953. iac.sy_end_date as syenddate,
  2954. io.vehicle_and_vessel_tax,
  2955. io.operatorid,
  2956. iac.operator_name,
  2957. sd.management_source,
  2958. iac.problem_order,
  2959. eic.namesimple as partnerCompaniesName,
  2960. iac.id as subOrderId,
  2961. iac.signing_time as signingTime,
  2962. iac.pay_date as payDate,
  2963. pa.agreement_code as agreementCode,
  2964. pa.agreement_name as agreementName,
  2965. pa.business_description as businessDescription,
  2966. pa.job_description as jobDescription,
  2967. pa.agreement_title as agreementTitle,
  2968. pa.docking_person as dockingPerson,
  2969. io.entry_status
  2970. FROM
  2971. ins_area_company iac
  2972. LEFT JOIN ins_orders io ON iac.orderno = io.orderno
  2973. LEFT JOIN sys_user su ON su.id = io.userid
  2974. LEFT JOIN sys_dept sd ON sd.id = su.dept_id
  2975. LEFT JOIN ptl_agreement pa ON pa.id = iac.agreement_id
  2976. LEFT JOIN esm_ins_company eic ON eic.id = pa.partner_companies_id
  2977. WHERE
  2978. iac.orderstatus = 3
  2979. <if test="params.quoteStartDateStr != null and params.quoteStartDateStr != '' and params.quoteEndDateStr != null and params.quoteEndDateStr != ''">
  2980. and DATE_FORMAT(iac.createtime, '%Y-%m-%d') between #{params.quoteStartDateStr} AND
  2981. #{params.quoteEndDateStr}
  2982. </if>
  2983. <if test="params.orderNo != null and params.orderNo != ''">
  2984. AND iac.id= #{params.orderNo}
  2985. </if>
  2986. <if test="params.licenseNo != null and params.licenseNo != ''">
  2987. AND io.licenseno = #{params.licenseNo}
  2988. </if>
  2989. <if test="params.frameNo != null and params.frameNo != ''">
  2990. AND io.frameno = #{params.frameNo}
  2991. </if>
  2992. <if test="params.insuredName != null and params.insuredName != ''">
  2993. AND json_extract(io.insureinfo, '$.name') = #{params.insuredName}
  2994. </if>
  2995. <if test="params.companyId != null and params.companyId != ''">
  2996. AND io.company_id = #{params.companyId}
  2997. </if>
  2998. <if test="params.engineNo != null and params.engineNo != ''">
  2999. and JSON_EXTRACT( io.carinfo, '$.engineNo' ) = #{params.engineNo}
  3000. </if>
  3001. <if test="params.riskCode != null and params.riskCode != ''">
  3002. and iac.product = #{params.riskCode}
  3003. </if>
  3004. <if test="params.attachStartDateStr != null and params.attachStartDateStr != '' and params.attachStartDateStr != null and params.attachStartDateStr != '' ">
  3005. and ((
  3006. DATE_FORMAT(iac.jq_start_date, '%Y-%m-%d') BETWEEN #{params.attachStartDateStr}
  3007. AND #{params.attachEndDateStr}
  3008. )
  3009. OR ( DATE_FORMAT(iac.sy_start_date, '%Y-%m-%d') BETWEEN #{params.attachStartDateStr} AND
  3010. #{params.attachEndDateStr} )
  3011. )
  3012. </if>
  3013. <if test="params.provinceId != null and params.provinceId != ''">
  3014. and io.deptid like "${params.provinceId}%"
  3015. </if>
  3016. <if test="params.problemOrder != null and params.problemOrder != ''">
  3017. and iac.problem_order like "${params.problemOrder}%"
  3018. </if>
  3019. <if test="params.cityId != null and params.cityId != ''">
  3020. and io.deptid like "${params.cityId}%"
  3021. </if>
  3022. <if test="params.countyId != null and params.countyId != ''">
  3023. and io.deptid like "${params.countyId}%"
  3024. </if>
  3025. <if test="params.houseId != null and params.houseId != ''">
  3026. and io.deptid like "${params.houseId}%"
  3027. </if>
  3028. <if test="params.operatorId != null and params.operatorId != ''">
  3029. and io.userid = #{params.operatorId}
  3030. </if>
  3031. <if test="params.operatorName != null and params.operatorName != ''">
  3032. and io.username = #{params.operatorName}
  3033. </if>
  3034. <if test="params.auditId != null and params.auditId != ''">
  3035. and iac.new_operator_id = #{params.auditId}
  3036. </if>
  3037. <if test="params.agreeId != null and params.agreeId != ''">
  3038. and iac.agreement_id = #{params.agreeId}
  3039. </if>
  3040. <if test="params.managementSource != null and params.managementSource != ''">
  3041. and sd.management_source = #{params.managementSource}
  3042. </if>
  3043. <if test="params.signStartDateStr != null and params.signStartDateStr != '' and params.signEndDateStr != null and params.signEndDateStr != ''">
  3044. and DATE_FORMAT(iac.signing_time, '%Y-%m-%d') between #{params.signStartDateStr} AND
  3045. #{params.signEndDateStr}
  3046. </if>
  3047. <if test="params.payStartDateStr != null and params.payStartDateStr != '' and params.payEndDateStr != null and params.payEndDateStr != ''">
  3048. and iac.pay_date between #{params.payStartDateStr} AND #{params.payEndDateStr}
  3049. </if>
  3050. <if test="params.isExternal != null and params.isExternal != ''">
  3051. and io.is_external = #{params.isExternal}
  3052. </if>
  3053. <if test="params.jqPolicyNo != null and params.jqPolicyNo != ''">
  3054. and iac.jqpolicyno = #{params.jqPolicyNo}
  3055. </if>
  3056. <if test="params.syPolicyNo != null and params.syPolicyNo != ''">
  3057. and iac.sypolicyno = #{params.syPolicyNo}
  3058. </if>
  3059. <if test="params.noPolicyNo != null and params.noPolicyNo != ''">
  3060. and iac.cross_insurance like concat('%', #{params.noPolicyNo}, '%')
  3061. </if>
  3062. order by iac.createtime desc
  3063. </select>
  3064. <select id="getExpectNetProfit" resultType="com.ydtech.modules.order.entity.InsAreaCompany">
  3065. select
  3066. IFNULL(ifon.jq_costs_premiums,0) + IFNULL(ifon.sy_costs_premiums,0) + IFNULL (ifon.no_costs_premiums,0) as "entranceAllFee",
  3067. IFNULL(jq_export_other_costs_premiums,0) + IFNULL(jq_export_supervise_costs_premiums,0) +IFNULL(sy_export_other_costs_premiums,0) +IFNULL(sy_export_supervise_costs_premiums,0)
  3068. +IFNULL(no_export_supervise_costs_premiums,0)+IFNULL(no_export_supervise_costs_premiums,0) as "exportAllFee"
  3069. from ins_area_company iac
  3070. left join ins_orders io on io.orderno = iac.orderno
  3071. LEFT JOIN ins_fee_order_new ifon ON iac.id = ifon.ins_order_no
  3072. <where>
  3073. <if test="vo.userId !=null and vo.userId !=''">
  3074. iac.leader_id =#{vo.userId}
  3075. </if>
  3076. <if test="vo.ids != null and vo.ids.size()>0 ">
  3077. AND io.userid IN
  3078. <foreach item="item" collection="vo.ids" open="(" separator="," close=")">
  3079. #{item}
  3080. </foreach>
  3081. </if>
  3082. <if test="vo.createtimeStart != null and vo.createtimeStart!='' and vo.createtimeEnd != null and vo.createtimeEnd!=''">
  3083. AND iac.signing_time BETWEEN #{vo.createtimeStart} AND #{vo.createtimeEnd}
  3084. </if>
  3085. </where>
  3086. </select>
  3087. <select id="getDistributionAllAmount" resultType="java.util.HashMap">
  3088. select
  3089. IFNULL(sum(IFNULL(first_detail_premiums,0)),0) + IFNULL(b.secondDetailPremiums,0) +IFNULL(c.thirdDetailPremiums,0) as "distributionAmount"
  3090. from ins_area_company iac
  3091. left join ins_orders io on io.orderno = iac.orderno
  3092. LEFT JOIN ins_fee_order_new ifon ON iac.id = ifon.ins_order_no
  3093. <where>
  3094. <if test="vo.userId !=null and vo.userId !=''">
  3095. ifon.first_level_user_id =#{vo.userId}
  3096. </if>
  3097. <if test="vo.ids != null and vo.ids.size()>0 ">
  3098. AND io.userid IN
  3099. <foreach item="item" collection="vo.ids" open="(" separator="," close=")">
  3100. #{item}
  3101. </foreach>
  3102. </if>
  3103. <if test="vo.createtimeStart != null and vo.createtimeStart!='' and vo.createtimeEnd != null and vo.createtimeEnd!=''">
  3104. AND iac.signing_time BETWEEN #{vo.createtimeStart} AND #{vo.createtimeEnd}
  3105. </if>
  3106. </where>
  3107. group by ifon.first_level_user_id
  3108. left join (
  3109. select
  3110. sum(IFNULL(second_detail_premiums,0)) as "secondDetailPremiums",
  3111. ifon.two_level_user_id as "twoLevelUserId",
  3112. from ins_area_company iac
  3113. left join ins_orders io on io.orderno = iac.orderno
  3114. LEFT JOIN ins_fee_order_new ifon ON iac.id = ifon.ins_order_no
  3115. <where>
  3116. <if test="vo.userId !=null and vo.userId !=''">
  3117. ifon.two_level_user_id =#{vo.userId}
  3118. </if>
  3119. <if test="vo.ids != null and vo.ids.size()>0 ">
  3120. AND io.userid IN
  3121. <foreach item="item" collection="vo.ids" open="(" separator="," close=")">
  3122. #{item}
  3123. </foreach>
  3124. </if>
  3125. <if test="vo.createtimeStart != null and vo.createtimeStart!='' and vo.createtimeEnd != null and vo.createtimeEnd!=''">
  3126. AND iac.signing_time BETWEEN #{vo.createtimeStart} AND #{vo.createtimeEnd}
  3127. </if>
  3128. </where>
  3129. group by ifon.two_level_user_id
  3130. ) b on b.twoLevelUserId =ifon.first_level_user_id
  3131. left join (
  3132. select
  3133. sum(IFNULL(third_detail_premiums,0)) as "thirdDetailPremiums",
  3134. ifon.three_level_user_id as "threeLevelUserId",
  3135. from ins_area_company iac
  3136. left join ins_orders io on io.orderno = iac.orderno
  3137. LEFT JOIN ins_fee_order_new ifon ON iac.id = ifon.ins_order_no
  3138. <where>
  3139. <if test="vo.userId !=null and vo.userId !=''">
  3140. ifon.three_level_user_id =#{vo.userId}
  3141. </if>
  3142. <if test="vo.ids != null and vo.ids.size()>0 ">
  3143. AND io.userid IN
  3144. <foreach item="item" collection="vo.ids" open="(" separator="," close=")">
  3145. #{item}
  3146. </foreach>
  3147. </if>
  3148. <if test="vo.createtimeStart != null and vo.createtimeStart!='' and vo.createtimeEnd != null and vo.createtimeEnd!=''">
  3149. AND iac.signing_time BETWEEN #{vo.createtimeStart} AND #{vo.createtimeEnd}
  3150. </if>
  3151. </where>
  3152. group by ifon.three_level_user_id
  3153. ) c on c.threeLevelUserId = ifon.first_level_user_id
  3154. </select>
  3155. </mapper>