InsAreaCompanyMapper.xml 117 KB

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