InsAreaCompanyMapper.xml 61 KB

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