InsAreaCompanyMapper.xml 94 KB

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