ReportInsurancePolicyMapper.xml 78 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353
  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.report.dao.ReportInsurancePolicyMapper">
  6. <resultMap id="BaseResultMap" type="com.ydtech.modules.report.model.ReportInsurancePolicy">
  7. <result property="companyId" column="company_id" jdbcType="VARCHAR"/>
  8. <result property="insCompany" column="ins_company" jdbcType="VARCHAR"/>
  9. <result property="agreementId" column="agreement_id" jdbcType="VARCHAR"/>
  10. <result property="agreementName" column="agreement_name" jdbcType="VARCHAR"/>
  11. <result property="policyno" column="policyno" jdbcType="VARCHAR"/>
  12. <result property="insidePayTime" column="inside_pay_time" jdbcType="TIMESTAMP"/>
  13. <result property="startDate" column="start_date" jdbcType="VARCHAR"/>
  14. <result property="endDate" column="end_date" jdbcType="VARCHAR"/>
  15. <result property="riskCode" column="risk_code" jdbcType="VARCHAR"/>
  16. <result property="riskName" column="risk_name" jdbcType="VARCHAR"/>
  17. <result property="sumpremium" column="sumpremium" jdbcType="DECIMAL"/>
  18. <result property="taxpremium" column="taxpremium" jdbcType="DECIMAL"/>
  19. <result property="taxLaterPremium" column="tax_later_premium" jdbcType="DECIMAL"/>
  20. <result property="insuranceSubAmount" column="insurance_sub_amount" jdbcType="VARCHAR"/>
  21. <result property="frameno" column="frameno" jdbcType="VARCHAR"/>
  22. <result property="licenseno" column="licenseno" jdbcType="VARCHAR"/>
  23. <result property="vehicleUse" column="vehicle_use" jdbcType="VARCHAR"/>
  24. <result property="powerType" column="power_type" jdbcType="VARCHAR"/>
  25. <result property="cimodelclass" column="cimodelclass" jdbcType="VARCHAR"/>
  26. <result property="limitLoad" column="limit_load" jdbcType="VARCHAR"/>
  27. <result property="appliName" column="appli_name" jdbcType="VARCHAR"/>
  28. <result property="insureName" column="insure_name" jdbcType="VARCHAR"/>
  29. <result property="deptid" column="deptid" jdbcType="VARCHAR"/>
  30. <result property="deptname" column="deptname" jdbcType="VARCHAR"/>
  31. <result property="userid" column="userid" jdbcType="VARCHAR"/>
  32. <result property="username" column="username" jdbcType="VARCHAR"/>
  33. <result property="productid" column="productid" jdbcType="VARCHAR"/>
  34. <result property="product" column="product" jdbcType="VARCHAR"/>
  35. <result property="operatorid" column="operatorid" jdbcType="VARCHAR"/>
  36. <result property="sumCostsPremiums" column="sum_costs_premiums" jdbcType="DECIMAL"/>
  37. <result property="superviseCostsPremiums" column="supervise_costs_premiums" jdbcType="DECIMAL"/>
  38. <result property="otherCostsPremiums" column="other_costs_premiums" jdbcType="DECIMAL"/>
  39. <result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
  40. </resultMap>
  41. <select id="queryOrderAndCostData" resultMap="OrderAndCostDataMap">
  42. SELECT
  43. <!--下钻查询时拼接-->
  44. <if test="reportReqVo.isDrilling != null and reportReqVo.isDrilling == '1'.toString()">
  45. <!--按团队下钻时-->
  46. <if test="reportReqVo.drilType != null and reportReqVo.drilType == '1'.toString()">
  47. p.`username`,p.userid userId,
  48. </if>
  49. <!--按机构下钻时-->
  50. <if test="reportReqVo.drilType != null and reportReqVo.drilType == '0'.toString()">
  51. <!--下钻的是五级机构时,下钻到团队-->
  52. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '5'.toString()">
  53. p.deptid,
  54. </if>
  55. <!--下钻的是四级机构时-->
  56. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '4'.toString()">
  57. substr(p.deptid,1,11) institutionId,
  58. </if>
  59. <!--下钻的是三级机构时-->
  60. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '3'.toString()">
  61. substr(p.deptid,1,8) institutionId,
  62. </if>
  63. <!--下钻的是二级机构时-->
  64. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '2'.toString()">
  65. substr(p.deptid,1,6) institutionId,
  66. </if>
  67. <!--下钻的是一级机构时-->
  68. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '1'.toString()">
  69. substr(p.deptid,1,4) institutionId,
  70. </if>
  71. <!--下钻的是总部时-->
  72. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == 'X'.toString()">
  73. substr(p.deptid,1,2) institutionId,
  74. </if>
  75. </if>
  76. <!--返回上层时-->
  77. <if test="reportReqVo.drilType != null and reportReqVo.drilType == '2'.toString()">
  78. <!--返回的是五级机构时-->
  79. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '5'.toString()">
  80. substr(p.deptid,1,11) institutionId,
  81. </if>
  82. <!--返回的是四级机构时-->
  83. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '4'.toString()">
  84. substr(p.deptid,1,8) institutionId,
  85. </if>
  86. <!--返回的是三级机构时-->
  87. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '3'.toString()">
  88. substr(p.deptid,1,6) institutionId,
  89. </if>
  90. <!--返回的是二级机构时-->
  91. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '2'.toString()">
  92. substr(p.deptid,1,4) institutionId,
  93. </if>
  94. <!--返回的是一级机构时-->
  95. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '1'.toString()">
  96. substr(p.deptid,1,2) institutionId,
  97. </if>
  98. <!--返回的是总部时-->
  99. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == 'X'.toString()">
  100. substr(p.deptid,1,1) institutionId,
  101. </if>
  102. </if>
  103. </if>
  104. <if test="reportReqVo.riskCode != null and reportReqVo.riskCode != ''">
  105. <if test="reportReqVo.riskCode!='ALL'.toString()">
  106. p.`risk_name` risk_name,
  107. </if>
  108. </if>
  109. count(distinct policyno) policy_count,
  110. SUM(p.`sumpremium`) sumpremium,
  111. SUM(p.`supervise_costs_premiums`) supervise_costs_premiums,
  112. SUM(p.`other_costs_premiums`) other_costs_premiums,
  113. SUM(p.`sum_costs_premiums`) sum_costs_premiums
  114. FROM
  115. report_insurance_policy p WHERE 1=1
  116. <!--下钻查询时拼接-->
  117. <if test="reportReqVo.isDrilling != null and reportReqVo.isDrilling == '1'.toString()">
  118. <!--按团队下钻时-->
  119. <if test="reportReqVo.drilType != null and reportReqVo.drilType == '1'.toString()">
  120. <if test="reportReqVo.teamCode != null and reportReqVo.teamCode != ''">
  121. and p.deptid = #{reportReqVo.teamCode}
  122. </if>
  123. </if>
  124. <!--按机构下钻时-->
  125. <if test="reportReqVo.drilType != null and reportReqVo.drilType == '0'.toString()">
  126. <!--下钻的是五级机构时,下钻到团队-->
  127. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '5'.toString()">
  128. and p.deptid in (SELECT id FROM `sys_dept` WHERE parent_id= #{reportReqVo.deptId} )
  129. </if>
  130. <!--下钻的是四级机构时-->
  131. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '4'.toString()">
  132. and substr(p.deptid,1,11) in (SELECT id FROM `sys_dept` WHERE parent_id= #{reportReqVo.deptId} )
  133. </if>
  134. <!--下钻的是三级机构时-->
  135. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '3'.toString()">
  136. and substr(p.deptid,1,8) in (SELECT id FROM `sys_dept` WHERE parent_id= #{reportReqVo.deptId} )
  137. </if>
  138. <!--下钻的是二级机构时-->
  139. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '2'.toString()">
  140. and substr(p.deptid,1,6) in (SELECT id FROM `sys_dept` WHERE parent_id= #{reportReqVo.deptId} )
  141. </if>
  142. <!--下钻的是一级机构时-->
  143. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '1'.toString()">
  144. and substr(p.deptid,1,4) in (SELECT id FROM `sys_dept` WHERE parent_id= #{reportReqVo.deptId} )
  145. </if>
  146. <!--下钻的是总部时-->
  147. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == 'X'.toString()">
  148. and substr(p.deptid,1,2) in (SELECT id FROM `sys_dept` WHERE parent_id= #{reportReqVo.deptId} )
  149. </if>
  150. </if>
  151. <!--返回上层时-->
  152. <if test="reportReqVo.drilType != null and reportReqVo.drilType == '2'.toString()">
  153. <!--返回的是五级机构时-->
  154. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '5'.toString()">
  155. and substr(p.deptid,1,8) = #{reportReqVo.deptId}
  156. </if>
  157. <!--返回的是四级机构时-->
  158. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '4'.toString()">
  159. and substr(p.deptid,1,6) = #{reportReqVo.deptId}
  160. </if>
  161. <!--返回的是三级机构时-->
  162. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '3'.toString()">
  163. and substr(p.deptid,1,4) = #{reportReqVo.deptId}
  164. </if>
  165. <!--返回的是二级机构时-->
  166. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '2'.toString()">
  167. and substr(p.deptid,1,2) = #{reportReqVo.deptId}
  168. </if>
  169. <!--返回的是一级机构时-->
  170. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '1'.toString()">
  171. and substr(p.deptid,1,1) = #{reportReqVo.deptId}
  172. </if>
  173. <!--返回的是总部时-->
  174. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == 'X'.toString()">
  175. and substr(p.deptid,1,1) = #{reportReqVo.deptId}
  176. </if>
  177. </if>
  178. </if>
  179. <!--非下钻查询时拼接-->
  180. <if test="reportReqVo.isDrilling != null and reportReqVo.isDrilling == '0'.toString()">
  181. <choose>
  182. <!--条件中团队不为空时,直接拼接团队-->
  183. <when test="reportReqVo.teamCode != null and reportReqVo.teamCode != ''">
  184. and p.deptid = #{reportReqVo.teamCode}
  185. </when>
  186. <!--条件中团队为空时,使用机构模糊查询-->
  187. <otherwise>
  188. <if test="reportReqVo.deptId != null and reportReqVo.deptId != ''">
  189. and p.deptid like #{reportReqVo.deptId}"%"
  190. </if>
  191. </otherwise>
  192. </choose>
  193. <if test="reportReqVo.userId != null and reportReqVo.userId != ''">
  194. and p.userid = #{reportReqVo.userId}
  195. </if>
  196. </if>
  197. <!--通用查询条件拼接-->
  198. <if test="reportReqVo.insCompany != null and reportReqVo.insCompany != ''">
  199. and p.company_id = #{reportReqVo.insCompany}
  200. </if>
  201. <if test="reportReqVo.riskCode != null and reportReqVo.riskCode != ''">
  202. <if test="reportReqVo.riskCode!='ALL'.toString()">
  203. and p.risk_code = #{reportReqVo.riskCode}
  204. </if>
  205. </if>
  206. <if test="reportReqVo.quoteStartDate != null and reportReqVo.quoteEndDate != null">
  207. and p.inside_pay_time between #{reportReqVo.quoteStartDate} AND #{reportReqVo.quoteEndDate}
  208. </if>
  209. <choose>
  210. <when test="reportReqVo.riskCode != null and reportReqVo.riskCode!='ALL'.toString()">
  211. GROUP BY p.`risk_name`
  212. <!--下钻查询时拼接-->
  213. <if test="reportReqVo.isDrilling != null and reportReqVo.isDrilling == '1'.toString()">
  214. <!--按团队下钻时-->
  215. <if test="reportReqVo.drilType != null and reportReqVo.drilType == '1'.toString()">
  216. ,p.`username`,p.userid order by p.`username`,p.`risk_name`
  217. </if>
  218. <!--按机构下钻时-->
  219. <if test="reportReqVo.drilType != null and reportReqVo.drilType == '0'.toString()">
  220. <!--下钻的是五级机构时,下钻到团队-->
  221. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '5'.toString()">
  222. ,p.deptid order by p.deptid,p.`risk_name`
  223. </if>
  224. <!--下钻的是四级机构时-->
  225. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '4'.toString()">
  226. ,substr(p.deptid,1,11) order by substr(p.deptid,1,11),p.`risk_name`
  227. </if>
  228. <!--下钻的是三级机构时-->
  229. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '3'.toString()">
  230. ,substr(p.deptid,1,8) order by substr(p.deptid,1,8),p.`risk_name`
  231. </if>
  232. <!--下钻的是二级机构时-->
  233. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '2'.toString()">
  234. ,substr(p.deptid,1,6) order by substr(p.deptid,1,6),p.`risk_name`
  235. </if>
  236. <!--下钻的是一级机构时-->
  237. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '1'.toString()">
  238. ,substr(p.deptid,1,4) order by substr(p.deptid,1,4),p.`risk_name`
  239. </if>
  240. <!--下钻的是总部时-->
  241. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == 'X'.toString()">
  242. ,substr(p.deptid,1,2) order by substr(p.deptid,1,2),p.`risk_name`
  243. </if>
  244. </if>
  245. <!--返回上层时-->
  246. <if test="reportReqVo.drilType != null and reportReqVo.drilType == '2'.toString()">
  247. <!--返回的是五级机构时-->
  248. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '5'.toString()">
  249. ,substr(p.deptid,1,11) order by substr(p.deptid,1,11)
  250. </if>
  251. <!--返回的是四级机构时-->
  252. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '4'.toString()">
  253. ,substr(p.deptid,1,8) order by substr(p.deptid,1,8)
  254. </if>
  255. <!--返回的是三级机构时-->
  256. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '3'.toString()">
  257. ,substr(p.deptid,1,6) order by substr(p.deptid,1,6)
  258. </if>
  259. <!--返回的是二级机构时-->
  260. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '2'.toString()">
  261. ,substr(p.deptid,1,4) order by substr(p.deptid,1,4)
  262. </if>
  263. <!--返回的是一级机构时-->
  264. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '1'.toString()">
  265. ,substr(p.deptid,1,2) order by substr(p.deptid,1,2)
  266. </if>
  267. <!--返回的是总部时-->
  268. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == 'X'.toString()">
  269. ,substr(p.deptid,1,1) order by substr(p.deptid,1,1)
  270. </if>
  271. </if>
  272. </if>
  273. </when>
  274. <otherwise>
  275. <!--下钻查询时拼接-->
  276. <if test="reportReqVo.isDrilling != null and reportReqVo.isDrilling == '1'.toString()">
  277. <!--按团队下钻时-->
  278. <if test="reportReqVo.drilType != null and reportReqVo.drilType == '1'.toString()">
  279. group by p.`username`,p.userid order by p.`username`
  280. </if>
  281. <!--按机构下钻时-->
  282. <if test="reportReqVo.drilType != null and reportReqVo.drilType == '0'.toString()">
  283. <!--下钻的是五级机构时,下钻到团队-->
  284. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '5'.toString()">
  285. group by p.deptid order by p.deptid
  286. </if>
  287. <!--下钻的是四级机构时-->
  288. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '4'.toString()">
  289. group by substr(p.deptid,1,11) order by substr(p.deptid,1,11)
  290. </if>
  291. <!--下钻的是三级机构时-->
  292. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '3'.toString()">
  293. group by substr(p.deptid,1,8) order by substr(p.deptid,1,8)
  294. </if>
  295. <!--下钻的是二级机构时-->
  296. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '2'.toString()">
  297. group by substr(p.deptid,1,6) order by substr(p.deptid,1,6)
  298. </if>
  299. <!--下钻的是一级机构时-->
  300. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '1'.toString()">
  301. group by substr(p.deptid,1,4) order by substr(p.deptid,1,4)
  302. </if>
  303. <!--下钻的是总部时-->
  304. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == 'X'.toString()">
  305. group by substr(p.deptid,1,2) order by substr(p.deptid,1,2)
  306. </if>
  307. </if>
  308. <!--返回上层时-->
  309. <if test="reportReqVo.drilType != null and reportReqVo.drilType == '2'.toString()">
  310. <!--返回的是五级机构时-->
  311. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '5'.toString()">
  312. group by substr(p.deptid,1,11) order by substr(p.deptid,1,11)
  313. </if>
  314. <!--返回的是四级机构时-->
  315. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '4'.toString()">
  316. group by substr(p.deptid,1,8) order by substr(p.deptid,1,8)
  317. </if>
  318. <!--返回的是三级机构时-->
  319. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '3'.toString()">
  320. group by substr(p.deptid,1,6) order by substr(p.deptid,1,6)
  321. </if>
  322. <!--返回的是二级机构时-->
  323. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '2'.toString()">
  324. group by substr(p.deptid,1,4) order by substr(p.deptid,1,4)
  325. </if>
  326. <!--返回的是一级机构时-->
  327. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '1'.toString()">
  328. group by substr(p.deptid,1,2) order by substr(p.deptid,1,2)
  329. </if>
  330. <!--返回的是总部时-->
  331. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == 'X'.toString()">
  332. group by substr(p.deptid,1,1) order by substr(p.deptid,1,1)
  333. </if>
  334. </if>
  335. </if>
  336. </otherwise>
  337. </choose>
  338. </select>
  339. <resultMap id="OrderAndCostDataMap" type="com.ydtech.modules.report.model.vo.OrderVolumeAndCostStatisticsResVo">
  340. <result property="institution" column="institution" jdbcType="VARCHAR"/>
  341. <result property="deptname" column="deptname" jdbcType="VARCHAR"/>
  342. <result property="username" column="username" jdbcType="VARCHAR"/>
  343. <result property="riskName" column="risk_name" jdbcType="VARCHAR"/>
  344. <result property="policyCount" column="policy_count" jdbcType="DECIMAL"/>
  345. <result property="sumPremium" column="sumremium" jdbcType="DECIMAL"/>
  346. <result property="sumCostsPremiums" column="sum_costs_premiums" jdbcType="DECIMAL"/>
  347. <result property="superviseCostsPremiums" column="supervise_costs_premiums" jdbcType="DECIMAL"/>
  348. <result property="otherCostsPremiums" column="other_costs_premiums" jdbcType="DECIMAL"/>
  349. </resultMap>
  350. <select id="queryOrderAndCostDataCount" resultType="Long">
  351. select
  352. count(1)
  353. from (
  354. SELECT
  355. <!--下钻查询时拼接-->
  356. <if test="reportReqVo.isDrilling != null and reportReqVo.isDrilling == '1'.toString()">
  357. <!--按团队下钻时-->
  358. <if test="reportReqVo.drilType != null and reportReqVo.drilType == '1'.toString()">
  359. p.`username`,p.userid userId,
  360. </if>
  361. <!--按机构下钻时-->
  362. <if test="reportReqVo.drilType != null and reportReqVo.drilType == '0'.toString()">
  363. <!--下钻的是五级机构时,下钻到团队-->
  364. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '5'.toString()">
  365. p.deptid,
  366. </if>
  367. <!--下钻的是四级机构时-->
  368. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '4'.toString()">
  369. substr(p.deptid,1,11) institutionId,
  370. </if>
  371. <!--下钻的是三级机构时-->
  372. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '3'.toString()">
  373. substr(p.deptid,1,8) institutionId,
  374. </if>
  375. <!--下钻的是二级机构时-->
  376. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '2'.toString()">
  377. substr(p.deptid,1,6) institutionId,
  378. </if>
  379. <!--下钻的是一级机构时-->
  380. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '1'.toString()">
  381. substr(p.deptid,1,4) institutionId,
  382. </if>
  383. <!--下钻的是总部时-->
  384. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == 'X'.toString()">
  385. substr(p.deptid,1,2) institutionId,
  386. </if>
  387. </if>
  388. <!--返回上层时-->
  389. <if test="reportReqVo.drilType != null and reportReqVo.drilType == '2'.toString()">
  390. <!--返回的是五级机构时-->
  391. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '5'.toString()">
  392. substr(p.deptid,1,11) institutionId,
  393. </if>
  394. <!--返回的是四级机构时-->
  395. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '4'.toString()">
  396. substr(p.deptid,1,8) institutionId,
  397. </if>
  398. <!--返回的是三级机构时-->
  399. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '3'.toString()">
  400. substr(p.deptid,1,6) institutionId,
  401. </if>
  402. <!--返回的是二级机构时-->
  403. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '2'.toString()">
  404. substr(p.deptid,1,4) institutionId,
  405. </if>
  406. <!--返回的是一级机构时-->
  407. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '1'.toString()">
  408. substr(p.deptid,1,2) institutionId,
  409. </if>
  410. <!--返回的是总部时-->
  411. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == 'X'.toString()">
  412. substr(p.deptid,1,1) institutionId,
  413. </if>
  414. </if>
  415. </if>
  416. <if test="reportReqVo.riskCode != null and reportReqVo.riskCode != ''">
  417. <if test="reportReqVo.riskCode!='ALL'.toString()">
  418. p.`risk_name` risk_name,
  419. </if>
  420. </if>
  421. count(distinct policyno) policy_count,
  422. SUM(p.`sumpremium`) sumpremium,
  423. SUM(p.`supervise_costs_premiums`) supervise_costs_premiums,
  424. SUM(p.`other_costs_premiums`) other_costs_premiums,
  425. SUM(p.`sum_costs_premiums`) sum_costs_premiums
  426. FROM
  427. report_insurance_policy p WHERE 1=1
  428. <!--下钻查询时拼接-->
  429. <if test="reportReqVo.isDrilling != null and reportReqVo.isDrilling == '1'.toString()">
  430. <!--按团队下钻时-->
  431. <if test="reportReqVo.drilType != null and reportReqVo.drilType == '1'.toString()">
  432. <if test="reportReqVo.teamCode != null and reportReqVo.teamCode != ''">
  433. and p.deptid = #{reportReqVo.teamCode}
  434. </if>
  435. </if>
  436. <!--按机构下钻时-->
  437. <if test="reportReqVo.drilType != null and reportReqVo.drilType == '0'.toString()">
  438. <!--下钻的是五级机构时,下钻到团队-->
  439. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '5'.toString()">
  440. and p.deptid in (SELECT id FROM `sys_dept` WHERE parent_id= #{reportReqVo.deptId} )
  441. </if>
  442. <!--下钻的是四级机构时-->
  443. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '4'.toString()">
  444. and substr(p.deptid,1,11) in (SELECT id FROM `sys_dept` WHERE parent_id= #{reportReqVo.deptId} )
  445. </if>
  446. <!--下钻的是三级机构时-->
  447. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '3'.toString()">
  448. and substr(p.deptid,1,8) in (SELECT id FROM `sys_dept` WHERE parent_id= #{reportReqVo.deptId} )
  449. </if>
  450. <!--下钻的是二级机构时-->
  451. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '2'.toString()">
  452. and substr(p.deptid,1,6) in (SELECT id FROM `sys_dept` WHERE parent_id= #{reportReqVo.deptId} )
  453. </if>
  454. <!--下钻的是一级机构时-->
  455. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '1'.toString()">
  456. and substr(p.deptid,1,4) in (SELECT id FROM `sys_dept` WHERE parent_id= #{reportReqVo.deptId} )
  457. </if>
  458. <!--下钻的是总部时-->
  459. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == 'X'.toString()">
  460. and substr(p.deptid,1,2) in (SELECT id FROM `sys_dept` WHERE parent_id= #{reportReqVo.deptId} )
  461. </if>
  462. </if>
  463. <!--返回上层时-->
  464. <if test="reportReqVo.drilType != null and reportReqVo.drilType == '2'.toString()">
  465. <!--返回的是五级机构时-->
  466. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '5'.toString()">
  467. and substr(p.deptid,1,8) = #{reportReqVo.deptId}
  468. </if>
  469. <!--返回的是四级机构时-->
  470. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '4'.toString()">
  471. and substr(p.deptid,1,6) = #{reportReqVo.deptId}
  472. </if>
  473. <!--返回的是三级机构时-->
  474. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '3'.toString()">
  475. and substr(p.deptid,1,4) = #{reportReqVo.deptId}
  476. </if>
  477. <!--返回的是二级机构时-->
  478. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '2'.toString()">
  479. and substr(p.deptid,1,2) = #{reportReqVo.deptId}
  480. </if>
  481. <!--返回的是一级机构时-->
  482. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '1'.toString()">
  483. and substr(p.deptid,1,1) = #{reportReqVo.deptId}
  484. </if>
  485. <!--返回的是总部时-->
  486. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == 'X'.toString()">
  487. and substr(p.deptid,1,1) = #{reportReqVo.deptId}
  488. </if>
  489. </if>
  490. </if>
  491. <!--非下钻查询时拼接-->
  492. <if test="reportReqVo.isDrilling != null and reportReqVo.isDrilling == '0'.toString()">
  493. <choose>
  494. <!--条件中团队不为空时,直接拼接团队-->
  495. <when test="reportReqVo.teamCode != null and reportReqVo.teamCode != ''">
  496. and p.deptid = #{reportReqVo.teamCode}
  497. </when>
  498. <!--条件中团队为空时,使用机构模糊查询-->
  499. <otherwise>
  500. <if test="reportReqVo.deptId != null and reportReqVo.deptId != ''">
  501. and p.deptid like #{reportReqVo.deptId}"%"
  502. </if>
  503. </otherwise>
  504. </choose>
  505. <if test="reportReqVo.userId != null and reportReqVo.userId != ''">
  506. and p.userid = #{reportReqVo.userId}
  507. </if>
  508. </if>
  509. <!--通用查询条件拼接-->
  510. <if test="reportReqVo.insCompany != null and reportReqVo.insCompany != ''">
  511. and p.company_id = #{reportReqVo.insCompany}
  512. </if>
  513. <if test="reportReqVo.riskCode != null and reportReqVo.riskCode != ''">
  514. <if test="reportReqVo.riskCode!='ALL'.toString()">
  515. and p.risk_code = #{reportReqVo.riskCode}
  516. </if>
  517. </if>
  518. <if test="reportReqVo.quoteStartDate != null and reportReqVo.quoteEndDate != null">
  519. and p.inside_pay_time between #{reportReqVo.quoteStartDate} AND #{reportReqVo.quoteEndDate}
  520. </if>
  521. <choose>
  522. <when test="reportReqVo.riskCode != null and reportReqVo.riskCode!='ALL'.toString()">
  523. GROUP BY p.`risk_name`
  524. <!--下钻查询时拼接-->
  525. <if test="reportReqVo.isDrilling != null and reportReqVo.isDrilling == '1'.toString()">
  526. <!--按团队下钻时-->
  527. <if test="reportReqVo.drilType != null and reportReqVo.drilType == '1'.toString()">
  528. ,p.`username`,p.userid order by p.`username`,p.`risk_name`
  529. </if>
  530. <!--按机构下钻时-->
  531. <if test="reportReqVo.drilType != null and reportReqVo.drilType == '0'.toString()">
  532. <!--下钻的是五级机构时,下钻到团队-->
  533. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '5'.toString()">
  534. ,p.deptid order by p.deptid,p.`risk_name`
  535. </if>
  536. <!--下钻的是四级机构时-->
  537. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '4'.toString()">
  538. ,substr(p.deptid,1,11) order by substr(p.deptid,1,11),p.`risk_name`
  539. </if>
  540. <!--下钻的是三级机构时-->
  541. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '3'.toString()">
  542. ,substr(p.deptid,1,8) order by substr(p.deptid,1,8),p.`risk_name`
  543. </if>
  544. <!--下钻的是二级机构时-->
  545. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '2'.toString()">
  546. ,substr(p.deptid,1,6) order by substr(p.deptid,1,6),p.`risk_name`
  547. </if>
  548. <!--下钻的是一级机构时-->
  549. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '1'.toString()">
  550. ,substr(p.deptid,1,4) order by substr(p.deptid,1,4),p.`risk_name`
  551. </if>
  552. <!--下钻的是总部时-->
  553. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == 'X'.toString()">
  554. ,substr(p.deptid,1,2) order by substr(p.deptid,1,2),p.`risk_name`
  555. </if>
  556. </if>
  557. <!--返回上层时-->
  558. <if test="reportReqVo.drilType != null and reportReqVo.drilType == '2'.toString()">
  559. <!--返回的是五级机构时-->
  560. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '5'.toString()">
  561. ,substr(p.deptid,1,11) order by substr(p.deptid,1,11)
  562. </if>
  563. <!--返回的是四级机构时-->
  564. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '4'.toString()">
  565. ,substr(p.deptid,1,8) order by substr(p.deptid,1,8)
  566. </if>
  567. <!--返回的是三级机构时-->
  568. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '3'.toString()">
  569. ,substr(p.deptid,1,6) order by substr(p.deptid,1,6)
  570. </if>
  571. <!--返回的是二级机构时-->
  572. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '2'.toString()">
  573. ,substr(p.deptid,1,4) order by substr(p.deptid,1,4)
  574. </if>
  575. <!--返回的是一级机构时-->
  576. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '1'.toString()">
  577. ,substr(p.deptid,1,2) order by substr(p.deptid,1,2)
  578. </if>
  579. <!--返回的是总部时-->
  580. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == 'X'.toString()">
  581. ,substr(p.deptid,1,1) order by substr(p.deptid,1,1)
  582. </if>
  583. </if>
  584. </if>
  585. </when>
  586. <otherwise>
  587. <!--下钻查询时拼接-->
  588. <if test="reportReqVo.isDrilling != null and reportReqVo.isDrilling == '1'.toString()">
  589. <!--按团队下钻时-->
  590. <if test="reportReqVo.drilType != null and reportReqVo.drilType == '1'.toString()">
  591. group by p.`username`,p.userid order by p.`username`
  592. </if>
  593. <!--按机构下钻时-->
  594. <if test="reportReqVo.drilType != null and reportReqVo.drilType == '0'.toString()">
  595. <!--下钻的是五级机构时,下钻到团队-->
  596. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '5'.toString()">
  597. group by p.deptid order by p.deptid
  598. </if>
  599. <!--下钻的是四级机构时-->
  600. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '4'.toString()">
  601. group by substr(p.deptid,1,11) order by substr(p.deptid,1,11)
  602. </if>
  603. <!--下钻的是三级机构时-->
  604. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '3'.toString()">
  605. group by substr(p.deptid,1,8) order by substr(p.deptid,1,8)
  606. </if>
  607. <!--下钻的是二级机构时-->
  608. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '2'.toString()">
  609. group by substr(p.deptid,1,6) order by substr(p.deptid,1,6)
  610. </if>
  611. <!--下钻的是一级机构时-->
  612. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '1'.toString()">
  613. group by substr(p.deptid,1,4) order by substr(p.deptid,1,4)
  614. </if>
  615. <!--下钻的是总部时-->
  616. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == 'X'.toString()">
  617. group by substr(p.deptid,1,2) order by substr(p.deptid,1,2)
  618. </if>
  619. </if>
  620. <!--返回上层时-->
  621. <if test="reportReqVo.drilType != null and reportReqVo.drilType == '2'.toString()">
  622. <!--返回的是五级机构时-->
  623. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '5'.toString()">
  624. group by substr(p.deptid,1,11) order by substr(p.deptid,1,11)
  625. </if>
  626. <!--返回的是四级机构时-->
  627. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '4'.toString()">
  628. group by substr(p.deptid,1,8) order by substr(p.deptid,1,8)
  629. </if>
  630. <!--返回的是三级机构时-->
  631. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '3'.toString()">
  632. group by substr(p.deptid,1,6) order by substr(p.deptid,1,6)
  633. </if>
  634. <!--返回的是二级机构时-->
  635. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '2'.toString()">
  636. group by substr(p.deptid,1,4) order by substr(p.deptid,1,4)
  637. </if>
  638. <!--返回的是一级机构时-->
  639. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '1'.toString()">
  640. group by substr(p.deptid,1,2) order by substr(p.deptid,1,2)
  641. </if>
  642. <!--返回的是总部时-->
  643. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == 'X'.toString()">
  644. group by substr(p.deptid,1,1) order by substr(p.deptid,1,1)
  645. </if>
  646. </if>
  647. </if>
  648. </otherwise>
  649. </choose>
  650. ) as s
  651. </select>
  652. <resultMap id="OrderVolumeAndCostStatisticsListResMap" type="com.ydtech.modules.report.model.vo.OrderVolumeAndCostStatisticsListResVo">
  653. <result property="insCompany" column="ins_company" jdbcType="VARCHAR"/>
  654. <result property="agreementName" column="agreement_name" jdbcType="VARCHAR"/>
  655. <result property="policyno" column="policyno" jdbcType="VARCHAR"/>
  656. <result property="insidePayTime" column="inside_pay_time" jdbcType="VARCHAR"/>
  657. <result property="startDate" column="start_date" jdbcType="VARCHAR"/>
  658. <result property="endDate" column="end_date" jdbcType="VARCHAR"/>
  659. <result property="riskName" column="risk_name" jdbcType="VARCHAR"/>
  660. <result property="sumpremium" column="sumpremium" jdbcType="DECIMAL"/>
  661. <result property="taxpremium" column="taxpremium" jdbcType="DECIMAL"/>
  662. <result property="taxLaterPremium" column="tax_later_premium" jdbcType="DECIMAL"/>
  663. <result property="insuranceSubAmount" column="insurance_sub_amount" jdbcType="VARCHAR"/>
  664. <result property="frameno" column="frameno" jdbcType="VARCHAR"/>
  665. <result property="licenseno" column="licenseno" jdbcType="VARCHAR"/>
  666. <result property="vehicleUse" column="vehicle_use" jdbcType="VARCHAR"/>
  667. <result property="powerType" column="power_type" jdbcType="VARCHAR"/>
  668. <result property="cimodelclass" column="cimodelclass" jdbcType="VARCHAR"/>
  669. <result property="limitLoad" column="limit_load" jdbcType="VARCHAR"/>
  670. <result property="appliName" column="appli_name" jdbcType="VARCHAR"/>
  671. <result property="insureName" column="insure_name" jdbcType="VARCHAR"/>
  672. <result property="deptname" column="deptname" jdbcType="VARCHAR"/>
  673. <result property="username" column="username" jdbcType="VARCHAR"/>
  674. <result property="product" column="product" jdbcType="VARCHAR"/>
  675. <result property="sumCostsPremiums" column="sum_costs_premiums" jdbcType="DECIMAL"/>
  676. <result property="superviseCostsPremiums" column="supervise_costs_premiums" jdbcType="DECIMAL"/>
  677. <result property="otherCostsPremiums" column="other_costs_premiums" jdbcType="DECIMAL"/>
  678. </resultMap>
  679. <select id="queryOrderAndCostList" resultMap="OrderVolumeAndCostStatisticsListResMap">
  680. SELECT
  681. ins_company,
  682. agreement_name,
  683. policyno,
  684. DATE_FORMAT(inside_pay_time, '%Y-%m-%d') inside_pay_time,
  685. DATE_FORMAT(start_date, '%Y-%m-%d') start_date,
  686. DATE_FORMAT(end_date, '%Y-%m-%d') end_date,
  687. risk_name,
  688. sumpremium,
  689. taxpremium,
  690. tax_later_premium,
  691. insurance_sub_amount,
  692. frameno,
  693. licenseno,
  694. vehicle_use,
  695. power_type,
  696. cimodelclass,
  697. limit_load,
  698. appli_name,
  699. insure_name,
  700. deptname,
  701. username,
  702. product,
  703. sum_costs_premiums,
  704. supervise_costs_premiums,
  705. other_costs_premiums
  706. FROM
  707. report_insurance_policy p WHERE 1=1
  708. <choose>
  709. <!--条件中团队不为空时,直接拼接团队-->
  710. <when test="reportReqVo.teamCode != null and reportReqVo.teamCode != ''">
  711. and p.deptid = #{reportReqVo.teamCode}
  712. </when>
  713. <!--条件中团队为空时,使用机构模糊查询-->
  714. <otherwise>
  715. <if test="reportReqVo.deptId != null and reportReqVo.deptId != ''">
  716. and p.deptid like #{reportReqVo.deptId}"%"
  717. </if>
  718. </otherwise>
  719. </choose>
  720. <if test="reportReqVo.userId != null and reportReqVo.userId != ''">
  721. and p.userid = #{reportReqVo.userId}
  722. </if>
  723. <!--通用查询条件拼接-->
  724. <if test="reportReqVo.insCompany != null and reportReqVo.insCompany != ''">
  725. and p.company_id = #{reportReqVo.insCompany}
  726. </if>
  727. <if test="reportReqVo.riskCode != null and reportReqVo.riskCode != ''">
  728. <if test="reportReqVo.riskCode!='ALL'.toString()">
  729. and p.risk_code = #{reportReqVo.riskCode}
  730. </if>
  731. </if>
  732. <if test="reportReqVo.quoteStartDate != null and reportReqVo.quoteEndDate != null">
  733. and p.inside_pay_time between #{reportReqVo.quoteStartDate} AND #{reportReqVo.quoteEndDate}
  734. </if>
  735. </select>
  736. <!--===========================================分割线=======报表手续费和分销费=================================================-->
  737. <resultMap id="PayApplyUserReportDataMap" type="com.ydtech.modules.report.model.vo.PayApplyUserReportResVo">
  738. <result property="institution" column="institution" jdbcType="VARCHAR"/>
  739. <result property="institutionId" column="institutionId" jdbcType="VARCHAR"/>
  740. <result property="deptname" column="deptname" jdbcType="VARCHAR"/>
  741. <result property="username" column="username" jdbcType="VARCHAR"/>
  742. <result property="waitPayCostsPremiums" column="wait_pay_costs_premiums" jdbcType="DECIMAL"/>
  743. <result property="paidCostsPremiums" column="paid_costs_premiums" jdbcType="DECIMAL"/>
  744. <result property="sumCostsPremiums" column="sum_costs_premiums" jdbcType="DECIMAL"/>
  745. <result property="waitPayRetailPremiums" column="wait_pay_retail_premiums" jdbcType="DECIMAL"/>
  746. <result property="paidRetailPremiums" column="paid_retail_premiums" jdbcType="DECIMAL"/>
  747. <result property="sumRetailPremiums" column="sum_retail_premiums" jdbcType="DECIMAL"/>
  748. </resultMap>
  749. <select id="queryPayApplyUserReportData" resultMap="PayApplyUserReportDataMap">
  750. SELECT
  751. <!--下钻查询时拼接-->
  752. <if test="reportReqVo.isDrilling != null and reportReqVo.isDrilling == '1'.toString()">
  753. <!--按团队下钻时-->
  754. <if test="reportReqVo.drilType != null and reportReqVo.drilType == '1'.toString()">
  755. p.`username`,p.userid userId,
  756. </if>
  757. <!--按机构下钻时-->
  758. <if test="reportReqVo.drilType != null and reportReqVo.drilType == '0'.toString()">
  759. <!--下钻的是五级机构时,下钻到团队-->
  760. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '5'.toString()">
  761. p.deptid,
  762. </if>
  763. <!--下钻的是四级机构时-->
  764. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '4'.toString()">
  765. substr(p.deptid,1,11) institutionId,
  766. </if>
  767. <!--下钻的是三级机构时-->
  768. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '3'.toString()">
  769. substr(p.deptid,1,8) institutionId,
  770. </if>
  771. <!--下钻的是二级机构时-->
  772. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '2'.toString()">
  773. substr(p.deptid,1,6) institutionId,
  774. </if>
  775. <!--下钻的是一级机构时-->
  776. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '1'.toString()">
  777. substr(p.deptid,1,4) institutionId,
  778. </if>
  779. <!--下钻的是总部时-->
  780. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == 'X'.toString()">
  781. substr(p.deptid,1,2) institutionId,
  782. </if>
  783. </if>
  784. <!--返回上层时-->
  785. <if test="reportReqVo.drilType != null and reportReqVo.drilType == '2'.toString()">
  786. <!--返回的是五级机构时-->
  787. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '5'.toString()">
  788. substr(p.deptid,1,11) institutionId,
  789. </if>
  790. <!--返回的是四级机构时-->
  791. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '4'.toString()">
  792. substr(p.deptid,1,8) institutionId,
  793. </if>
  794. <!--返回的是三级机构时-->
  795. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '3'.toString()">
  796. substr(p.deptid,1,6) institutionId,
  797. </if>
  798. <!--返回的是二级机构时-->
  799. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '2'.toString()">
  800. substr(p.deptid,1,4) institutionId,
  801. </if>
  802. <!--返回的是一级机构时-->
  803. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '1'.toString()">
  804. substr(p.deptid,1,2) institutionId,
  805. </if>
  806. <!--返回的是总部时-->
  807. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == 'X'.toString()">
  808. substr(p.deptid,1,1) institutionId,
  809. </if>
  810. </if>
  811. </if>
  812. SUM( CASE feetype WHEN '1' THEN totalfee ELSE 0 END ) AS sum_costs_premiums,
  813. SUM( CASE feetype WHEN '1' THEN paidfee ELSE 0 END ) AS paid_costs_premiums,
  814. SUM( CASE feetype WHEN '1' THEN totalfee-paidfee ELSE 0 END ) AS wait_pay_costs_premiums,
  815. SUM( CASE feetype WHEN '2' THEN totalfee ELSE 0 END ) AS sum_retail_premiums,
  816. SUM( CASE feetype WHEN '2' THEN paidfee ELSE 0 END ) AS paid_retail_premiums,
  817. SUM( CASE feetype WHEN '2' THEN totalfee-paidfee ELSE 0 END ) AS wait_pay_retail_premiums
  818. FROM report_payable_basedata p WHERE 1=1
  819. <!--下钻查询时拼接-->
  820. <if test="reportReqVo.isDrilling != null and reportReqVo.isDrilling == '1'.toString()">
  821. <!--按团队下钻时-->
  822. <if test="reportReqVo.drilType != null and reportReqVo.drilType == '1'.toString()">
  823. <if test="reportReqVo.teamCode != null and reportReqVo.teamCode != ''">
  824. and p.deptid = #{reportReqVo.teamCode}
  825. </if>
  826. </if>
  827. <!--按机构下钻时-->
  828. <if test="reportReqVo.drilType != null and reportReqVo.drilType == '0'.toString()">
  829. <!--下钻的是五级机构时,下钻到团队-->
  830. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '5'.toString()">
  831. and p.deptid in (SELECT id FROM `sys_dept` WHERE parent_id= #{reportReqVo.deptId} )
  832. </if>
  833. <!--下钻的是四级机构时-->
  834. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '4'.toString()">
  835. and substr(p.deptid,1,11) in (SELECT id FROM `sys_dept` WHERE parent_id= #{reportReqVo.deptId} )
  836. </if>
  837. <!--下钻的是三级机构时-->
  838. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '3'.toString()">
  839. and substr(p.deptid,1,8) in (SELECT id FROM `sys_dept` WHERE parent_id= #{reportReqVo.deptId} )
  840. </if>
  841. <!--下钻的是二级机构时-->
  842. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '2'.toString()">
  843. and substr(p.deptid,1,6) in (SELECT id FROM `sys_dept` WHERE parent_id= #{reportReqVo.deptId} )
  844. </if>
  845. <!--下钻的是一级机构时-->
  846. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '1'.toString()">
  847. and substr(p.deptid,1,4) in (SELECT id FROM `sys_dept` WHERE parent_id= #{reportReqVo.deptId} )
  848. </if>
  849. <!--下钻的是总部时-->
  850. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == 'X'.toString()">
  851. and substr(p.deptid,1,2) in (SELECT id FROM `sys_dept` WHERE parent_id= #{reportReqVo.deptId} )
  852. </if>
  853. </if>
  854. <!--返回上层时-->
  855. <if test="reportReqVo.drilType != null and reportReqVo.drilType == '2'.toString()">
  856. <!--返回的是五级机构时-->
  857. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '5'.toString()">
  858. and substr(p.deptid,1,8) = #{reportReqVo.deptId}
  859. </if>
  860. <!--返回的是四级机构时-->
  861. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '4'.toString()">
  862. and substr(p.deptid,1,6) = #{reportReqVo.deptId}
  863. </if>
  864. <!--返回的是三级机构时-->
  865. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '3'.toString()">
  866. and substr(p.deptid,1,4) = #{reportReqVo.deptId}
  867. </if>
  868. <!--返回的是二级机构时-->
  869. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '2'.toString()">
  870. and substr(p.deptid,1,2) = #{reportReqVo.deptId}
  871. </if>
  872. <!--返回的是一级机构时-->
  873. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '1'.toString()">
  874. and substr(p.deptid,1,1) = #{reportReqVo.deptId}
  875. </if>
  876. <!--返回的是总部时-->
  877. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == 'X'.toString()">
  878. and substr(p.deptid,1,1) = #{reportReqVo.deptId}
  879. </if>
  880. </if>
  881. </if>
  882. <!--非下钻查询时拼接-->
  883. <if test="reportReqVo.isDrilling != null and reportReqVo.isDrilling == '0'.toString()">
  884. <choose>
  885. <!--条件中团队不为空时,直接拼接团队-->
  886. <when test="reportReqVo.teamCode != null and reportReqVo.teamCode != ''">
  887. and p.deptid = #{reportReqVo.teamCode}
  888. </when>
  889. <!--条件中团队为空时,使用机构模糊查询-->
  890. <otherwise>
  891. <if test="reportReqVo.deptId != null and reportReqVo.deptId != ''">
  892. and p.deptid like #{reportReqVo.deptId}"%"
  893. </if>
  894. </otherwise>
  895. </choose>
  896. <if test="reportReqVo.userId != null and reportReqVo.userId != ''">
  897. and p.userid = #{reportReqVo.userId}
  898. </if>
  899. </if>
  900. <!--通用查询条件拼接-->
  901. <if test="reportReqVo.insCompany != null and reportReqVo.insCompany != ''">
  902. and p.company_id = #{reportReqVo.insCompany}
  903. </if>
  904. <if test="reportReqVo.quoteStartDate != null and reportReqVo.quoteEndDate != null">
  905. and p.signdate between #{reportReqVo.quoteStartDate} AND #{reportReqVo.quoteEndDate}
  906. </if>
  907. <!--下钻查询时拼接-->
  908. <if test="reportReqVo.isDrilling != null and reportReqVo.isDrilling == '1'.toString()">
  909. <!--按团队下钻时-->
  910. <if test="reportReqVo.drilType != null and reportReqVo.drilType == '1'.toString()">
  911. group by p.`username`,p.userid order by p.`username`
  912. </if>
  913. <!--按机构下钻时-->
  914. <if test="reportReqVo.drilType != null and reportReqVo.drilType == '0'.toString()">
  915. <!--下钻的是五级机构时,下钻到团队-->
  916. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '5'.toString()">
  917. group by p.deptid order by p.deptid
  918. </if>
  919. <!--下钻的是四级机构时-->
  920. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '4'.toString()">
  921. group by substr(p.deptid,1,11) order by substr(p.deptid,1,11)
  922. </if>
  923. <!--下钻的是三级机构时-->
  924. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '3'.toString()">
  925. group by substr(p.deptid,1,8) order by substr(p.deptid,1,8)
  926. </if>
  927. <!--下钻的是二级机构时-->
  928. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '2'.toString()">
  929. group by substr(p.deptid,1,6) order by substr(p.deptid,1,6)
  930. </if>
  931. <!--下钻的是一级机构时-->
  932. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '1'.toString()">
  933. group by substr(p.deptid,1,4) order by substr(p.deptid,1,4)
  934. </if>
  935. <!--下钻的是总部时-->
  936. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == 'X'.toString()">
  937. group by substr(p.deptid,1,2) order by substr(p.deptid,1,2)
  938. </if>
  939. </if>
  940. <!--返回上层时-->
  941. <if test="reportReqVo.drilType != null and reportReqVo.drilType == '2'.toString()">
  942. <!--返回的是五级机构时-->
  943. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '5'.toString()">
  944. group by substr(p.deptid,1,11) order by substr(p.deptid,1,11)
  945. </if>
  946. <!--返回的是四级机构时-->
  947. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '4'.toString()">
  948. group by substr(p.deptid,1,8) order by substr(p.deptid,1,8)
  949. </if>
  950. <!--返回的是三级机构时-->
  951. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '3'.toString()">
  952. group by substr(p.deptid,1,6) order by substr(p.deptid,1,6)
  953. </if>
  954. <!--返回的是二级机构时-->
  955. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '2'.toString()">
  956. group by substr(p.deptid,1,4) order by substr(p.deptid,1,4)
  957. </if>
  958. <!--返回的是一级机构时-->
  959. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '1'.toString()">
  960. group by substr(p.deptid,1,2) order by substr(p.deptid,1,2)
  961. </if>
  962. <!--返回的是总部时-->
  963. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == 'X'.toString()">
  964. group by substr(p.deptid,1,1) order by substr(p.deptid,1,1)
  965. </if>
  966. </if>
  967. </if>
  968. </select>
  969. <select id="queryPayApplyUserReportDataCount" resultType="Long">
  970. select
  971. count(1)
  972. from (
  973. SELECT
  974. <!--下钻查询时拼接-->
  975. <if test="reportReqVo.isDrilling != null and reportReqVo.isDrilling == '1'.toString()">
  976. <!--按团队下钻时-->
  977. <if test="reportReqVo.drilType != null and reportReqVo.drilType == '1'.toString()">
  978. p.`username`,p.userid userId,
  979. </if>
  980. <!--按机构下钻时-->
  981. <if test="reportReqVo.drilType != null and reportReqVo.drilType == '0'.toString()">
  982. <!--下钻的是五级机构时,下钻到团队-->
  983. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '5'.toString()">
  984. p.deptid,
  985. </if>
  986. <!--下钻的是四级机构时-->
  987. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '4'.toString()">
  988. substr(p.deptid,1,11) institutionId,
  989. </if>
  990. <!--下钻的是三级机构时-->
  991. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '3'.toString()">
  992. substr(p.deptid,1,8) institutionId,
  993. </if>
  994. <!--下钻的是二级机构时-->
  995. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '2'.toString()">
  996. substr(p.deptid,1,6) institutionId,
  997. </if>
  998. <!--下钻的是一级机构时-->
  999. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '1'.toString()">
  1000. substr(p.deptid,1,4) institutionId,
  1001. </if>
  1002. <!--下钻的是总部时-->
  1003. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == 'X'.toString()">
  1004. substr(p.deptid,1,2) institutionId,
  1005. </if>
  1006. </if>
  1007. <!--返回上层时-->
  1008. <if test="reportReqVo.drilType != null and reportReqVo.drilType == '2'.toString()">
  1009. <!--返回的是五级机构时-->
  1010. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '5'.toString()">
  1011. substr(p.deptid,1,11) institutionId,
  1012. </if>
  1013. <!--返回的是四级机构时-->
  1014. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '4'.toString()">
  1015. substr(p.deptid,1,8) institutionId,
  1016. </if>
  1017. <!--返回的是三级机构时-->
  1018. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '3'.toString()">
  1019. substr(p.deptid,1,6) institutionId,
  1020. </if>
  1021. <!--返回的是二级机构时-->
  1022. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '2'.toString()">
  1023. substr(p.deptid,1,4) institutionId,
  1024. </if>
  1025. <!--返回的是一级机构时-->
  1026. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '1'.toString()">
  1027. substr(p.deptid,1,2) institutionId,
  1028. </if>
  1029. <!--返回的是总部时-->
  1030. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == 'X'.toString()">
  1031. substr(p.deptid,1,1) institutionId,
  1032. </if>
  1033. </if>
  1034. </if>
  1035. SUM( CASE feetype WHEN '1' THEN totalfee ELSE 0 END ) AS sum_costs_premiums,
  1036. SUM( CASE feetype WHEN '1' THEN paidfee ELSE 0 END ) AS paid_costs_premiums,
  1037. SUM( CASE feetype WHEN '1' THEN totalfee-paidfee ELSE 0 END ) AS wait_pay_costs_premiums,
  1038. SUM( CASE feetype WHEN '2' THEN totalfee ELSE 0 END ) AS sum_retail_premiums,
  1039. SUM( CASE feetype WHEN '2' THEN paidfee ELSE 0 END ) AS paid_retail_premiums,
  1040. SUM( CASE feetype WHEN '2' THEN totalfee-paidfee ELSE 0 END ) AS wait_pay_retail_premiums
  1041. FROM report_payable_basedata p WHERE 1=1
  1042. <!--下钻查询时拼接-->
  1043. <if test="reportReqVo.isDrilling != null and reportReqVo.isDrilling == '1'.toString()">
  1044. <!--按团队下钻时-->
  1045. <if test="reportReqVo.drilType != null and reportReqVo.drilType == '1'.toString()">
  1046. <if test="reportReqVo.teamCode != null and reportReqVo.teamCode != ''">
  1047. and p.deptid = #{reportReqVo.teamCode}
  1048. </if>
  1049. </if>
  1050. <!--按机构下钻时-->
  1051. <if test="reportReqVo.drilType != null and reportReqVo.drilType == '0'.toString()">
  1052. <!--下钻的是五级机构时,下钻到团队-->
  1053. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '5'.toString()">
  1054. and p.deptid in (SELECT id FROM `sys_dept` WHERE parent_id= #{reportReqVo.deptId} )
  1055. </if>
  1056. <!--下钻的是四级机构时-->
  1057. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '4'.toString()">
  1058. and substr(p.deptid,1,11) in (SELECT id FROM `sys_dept` WHERE parent_id= #{reportReqVo.deptId} )
  1059. </if>
  1060. <!--下钻的是三级机构时-->
  1061. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '3'.toString()">
  1062. and substr(p.deptid,1,8) in (SELECT id FROM `sys_dept` WHERE parent_id= #{reportReqVo.deptId} )
  1063. </if>
  1064. <!--下钻的是二级机构时-->
  1065. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '2'.toString()">
  1066. and substr(p.deptid,1,6) in (SELECT id FROM `sys_dept` WHERE parent_id= #{reportReqVo.deptId} )
  1067. </if>
  1068. <!--下钻的是一级机构时-->
  1069. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '1'.toString()">
  1070. and substr(p.deptid,1,4) in (SELECT id FROM `sys_dept` WHERE parent_id= #{reportReqVo.deptId} )
  1071. </if>
  1072. <!--下钻的是总部时-->
  1073. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == 'X'.toString()">
  1074. and substr(p.deptid,1,2) in (SELECT id FROM `sys_dept` WHERE parent_id= #{reportReqVo.deptId} )
  1075. </if>
  1076. </if>
  1077. <!--返回上层时-->
  1078. <if test="reportReqVo.drilType != null and reportReqVo.drilType == '2'.toString()">
  1079. <!--返回的是五级机构时-->
  1080. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '5'.toString()">
  1081. and substr(p.deptid,1,8) = #{reportReqVo.deptId}
  1082. </if>
  1083. <!--返回的是四级机构时-->
  1084. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '4'.toString()">
  1085. and substr(p.deptid,1,6) = #{reportReqVo.deptId}
  1086. </if>
  1087. <!--返回的是三级机构时-->
  1088. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '3'.toString()">
  1089. and substr(p.deptid,1,4) = #{reportReqVo.deptId}
  1090. </if>
  1091. <!--返回的是二级机构时-->
  1092. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '2'.toString()">
  1093. and substr(p.deptid,1,2) = #{reportReqVo.deptId}
  1094. </if>
  1095. <!--返回的是一级机构时-->
  1096. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '1'.toString()">
  1097. and substr(p.deptid,1,1) = #{reportReqVo.deptId}
  1098. </if>
  1099. <!--返回的是总部时-->
  1100. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == 'X'.toString()">
  1101. and substr(p.deptid,1,1) = #{reportReqVo.deptId}
  1102. </if>
  1103. </if>
  1104. </if>
  1105. <!--非下钻查询时拼接-->
  1106. <if test="reportReqVo.isDrilling != null and reportReqVo.isDrilling == '0'.toString()">
  1107. <choose>
  1108. <!--条件中团队不为空时,直接拼接团队-->
  1109. <when test="reportReqVo.teamCode != null and reportReqVo.teamCode != ''">
  1110. and p.deptid = #{reportReqVo.teamCode}
  1111. </when>
  1112. <!--条件中团队为空时,使用机构模糊查询-->
  1113. <otherwise>
  1114. <if test="reportReqVo.deptId != null and reportReqVo.deptId != ''">
  1115. and p.deptid like #{reportReqVo.deptId}"%"
  1116. </if>
  1117. </otherwise>
  1118. </choose>
  1119. <if test="reportReqVo.userId != null and reportReqVo.userId != ''">
  1120. and p.userid = #{reportReqVo.userId}
  1121. </if>
  1122. </if>
  1123. <!--通用查询条件拼接-->
  1124. <if test="reportReqVo.insCompany != null and reportReqVo.insCompany != ''">
  1125. and p.company_id = #{reportReqVo.insCompany}
  1126. </if>
  1127. <if test="reportReqVo.quoteStartDate != null and reportReqVo.quoteEndDate != null">
  1128. and p.signdate between #{reportReqVo.quoteStartDate} AND #{reportReqVo.quoteEndDate}
  1129. </if>
  1130. <!--下钻查询时拼接-->
  1131. <if test="reportReqVo.isDrilling != null and reportReqVo.isDrilling == '1'.toString()">
  1132. <!--按团队下钻时-->
  1133. <if test="reportReqVo.drilType != null and reportReqVo.drilType == '1'.toString()">
  1134. group by p.`username`,p.userid order by p.`username`
  1135. </if>
  1136. <!--按机构下钻时-->
  1137. <if test="reportReqVo.drilType != null and reportReqVo.drilType == '0'.toString()">
  1138. <!--下钻的是五级机构时,下钻到团队-->
  1139. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '5'.toString()">
  1140. group by p.deptid order by p.deptid
  1141. </if>
  1142. <!--下钻的是四级机构时-->
  1143. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '4'.toString()">
  1144. group by substr(p.deptid,1,11) order by substr(p.deptid,1,11)
  1145. </if>
  1146. <!--下钻的是三级机构时-->
  1147. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '3'.toString()">
  1148. group by substr(p.deptid,1,8) order by substr(p.deptid,1,8)
  1149. </if>
  1150. <!--下钻的是二级机构时-->
  1151. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '2'.toString()">
  1152. group by substr(p.deptid,1,6) order by substr(p.deptid,1,6)
  1153. </if>
  1154. <!--下钻的是一级机构时-->
  1155. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '1'.toString()">
  1156. group by substr(p.deptid,1,4) order by substr(p.deptid,1,4)
  1157. </if>
  1158. <!--下钻的是总部时-->
  1159. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == 'X'.toString()">
  1160. group by substr(p.deptid,1,2) order by substr(p.deptid,1,2)
  1161. </if>
  1162. </if>
  1163. <!--返回上层时-->
  1164. <if test="reportReqVo.drilType != null and reportReqVo.drilType == '2'.toString()">
  1165. <!--返回的是五级机构时-->
  1166. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '5'.toString()">
  1167. group by substr(p.deptid,1,11) order by substr(p.deptid,1,11)
  1168. </if>
  1169. <!--返回的是四级机构时-->
  1170. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '4'.toString()">
  1171. group by substr(p.deptid,1,8) order by substr(p.deptid,1,8)
  1172. </if>
  1173. <!--返回的是三级机构时-->
  1174. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '3'.toString()">
  1175. group by substr(p.deptid,1,6) order by substr(p.deptid,1,6)
  1176. </if>
  1177. <!--返回的是二级机构时-->
  1178. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '2'.toString()">
  1179. group by substr(p.deptid,1,4) order by substr(p.deptid,1,4)
  1180. </if>
  1181. <!--返回的是一级机构时-->
  1182. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == '1'.toString()">
  1183. group by substr(p.deptid,1,2) order by substr(p.deptid,1,2)
  1184. </if>
  1185. <!--返回的是总部时-->
  1186. <if test="reportReqVo.drilFlag != null and reportReqVo.drilFlag == 'X'.toString()">
  1187. group by substr(p.deptid,1,1) order by substr(p.deptid,1,1)
  1188. </if>
  1189. </if>
  1190. </if>
  1191. ) as s
  1192. </select>
  1193. <resultMap id="PayApplyUserReportListDataMap" type="com.ydtech.modules.report.model.vo.PayApplyUserReportResVo">
  1194. <result property="institution" column="institution" jdbcType="VARCHAR"/>
  1195. <result property="deptname" column="deptname" jdbcType="VARCHAR"/>
  1196. <result property="username" column="username" jdbcType="VARCHAR"/>
  1197. <result property="inscompany" column="inscompany" jdbcType="VARCHAR"/>
  1198. <result property="policyno" column="policyno" jdbcType="VARCHAR"/>
  1199. <result property="riskcode" column="riskcode" jdbcType="VARCHAR"/>
  1200. <result property="waitPayCostsPremiums" column="wait_pay_costs_premiums" jdbcType="DECIMAL"/>
  1201. <result property="paidCostsPremiums" column="paid_costs_premiums" jdbcType="DECIMAL"/>
  1202. <result property="sumCostsPremiums" column="sum_costs_premiums" jdbcType="DECIMAL"/>
  1203. <result property="waitPayRetailPremiums" column="wait_pay_retail_premiums" jdbcType="DECIMAL"/>
  1204. <result property="paidRetailPremiums" column="paid_retail_premiums" jdbcType="DECIMAL"/>
  1205. <result property="sumRetailPremiums" column="sum_retail_premiums" jdbcType="DECIMAL"/>
  1206. </resultMap>
  1207. <select id="queryPayApplyUserReportList" resultMap="PayApplyUserReportListDataMap">
  1208. SELECT deptname,username,inscompany,policyno,riskcode,
  1209. CASE feetype WHEN '1' THEN totalfee ELSE 0 END AS sum_costs_premiums,
  1210. CASE feetype WHEN '1' THEN paidfee ELSE 0 END AS paid_costs_premiums,
  1211. CASE feetype WHEN '1' THEN totalfee-paidfee ELSE 0 END AS wait_pay_costs_premiums,
  1212. CASE feetype WHEN '2' THEN totalfee ELSE 0 END AS sum_retail_premiums,
  1213. CASE feetype WHEN '2' THEN paidfee ELSE 0 END AS paid_retail_premiums,
  1214. CASE feetype WHEN '2' THEN totalfee-paidfee ELSE 0 END AS wait_pay_retail_premiums
  1215. FROM report_payable_basedata p WHERE 1=1
  1216. <choose>
  1217. <!--条件中团队不为空时,直接拼接团队-->
  1218. <when test="reportReqVo.teamCode != null and reportReqVo.teamCode != ''">
  1219. and p.deptid = #{reportReqVo.teamCode}
  1220. </when>
  1221. <!--条件中团队为空时,使用机构模糊查询-->
  1222. <otherwise>
  1223. <if test="reportReqVo.deptId != null and reportReqVo.deptId != ''">
  1224. and p.deptid like #{reportReqVo.deptId}"%"
  1225. </if>
  1226. </otherwise>
  1227. </choose>
  1228. <if test="reportReqVo.userId != null and reportReqVo.userId != ''">
  1229. and p.userId = #{reportReqVo.userId}
  1230. </if>
  1231. <if test="reportReqVo.insCompany != null and reportReqVo.insCompany != ''">
  1232. and p.inscompany = #{reportReqVo.insCompany}
  1233. </if>
  1234. <if test="reportReqVo.quoteStartDate != null and reportReqVo.quoteEndDate != null">
  1235. and p.signdate between #{reportReqVo.quoteStartDate} AND #{reportReqVo.quoteEndDate}
  1236. </if>
  1237. </select>
  1238. <!--===========================================分割线=======报表管理费=================================================-->
  1239. <resultMap id="PayApplyDeptReportDataMap" type="com.ydtech.modules.report.model.vo.PayApplyDeptReportResVo">
  1240. <result property="institutionId" column="institutionId" jdbcType="VARCHAR"/>
  1241. <result property="waitPayCostsPremiums" column="wait_pay_costs_premiums" jdbcType="DECIMAL"/>
  1242. <result property="paidCostsPremiums" column="paid_costs_premiums" jdbcType="DECIMAL"/>
  1243. <result property="sumCostsPremiums" column="sum_costs_premiums" jdbcType="DECIMAL"/>
  1244. </resultMap>
  1245. <select id="queryPayApplyDeptReportData" resultMap="PayApplyDeptReportDataMap">
  1246. SELECT comcode as institutionId,
  1247. sum( t.keepamount + t.addamount ) AS sum_costs_premiums,
  1248. sum( CASE WHEN settlestatus = '1' THEN t.keepamount + t.addamount ELSE 0 END ) AS paid_costs_premiums ,
  1249. sum( t.keepamount + t.addamount ) - sum( CASE WHEN settlestatus = '1' THEN t.keepamount + t.addamount ELSE 0 END ) as wait_pay_costs_premiums
  1250. FROM ins_deptfee t WHERE 1=1
  1251. <if test="reportReqVo.groupInsCompanyArr != null and reportReqVo.groupInsCompanyArr != ''">
  1252. and t.comcode in
  1253. <foreach collection="reportReqVo.groupInsCompanyArr" item="comcode" open="("
  1254. separator="," close=")">
  1255. #{comcode}
  1256. </foreach>
  1257. </if>
  1258. <if test="reportReqVo.insCompany != null and reportReqVo.insCompany != ''">
  1259. and t.inscompany = #{reportReqVo.insCompany}
  1260. </if>
  1261. <if test="reportReqVo.quoteStartDate != null and reportReqVo.quoteEndDate != null">
  1262. and t.signdate between #{reportReqVo.quoteStartDate} AND #{reportReqVo.quoteEndDate}
  1263. </if>
  1264. group by comcode
  1265. </select>
  1266. <select id="queryPayApplyDeptReportDataCount" resultType="Long">
  1267. select count(1) from (
  1268. SELECT comcode as institutionId,
  1269. sum( t.keepamount + t.addamount ) AS sum_costs_premiums,
  1270. sum( CASE WHEN settlestatus = '1' THEN t.keepamount + t.addamount ELSE 0 END ) AS paid_costs_premiums ,
  1271. sum( t.keepamount + t.addamount ) - sum( CASE WHEN settlestatus = '1' THEN t.keepamount + t.addamount ELSE 0 END ) as wait_pay_costs_premiums
  1272. FROM ins_deptfee t WHERE 1=1
  1273. <if test="reportReqVo.groupInsCompanyArr != null and reportReqVo.groupInsCompanyArr != ''">
  1274. and t.comcode in
  1275. <foreach collection="reportReqVo.groupInsCompanyArr" item="comcode" open="("
  1276. separator="," close=")">
  1277. #{comcode}
  1278. </foreach>
  1279. </if>
  1280. <if test="reportReqVo.insCompany != null and reportReqVo.insCompany != ''">
  1281. and t.inscompany = #{reportReqVo.insCompany}
  1282. </if>
  1283. <if test="reportReqVo.quoteStartDate != null and reportReqVo.quoteEndDate != null">
  1284. and t.signdate between #{reportReqVo.quoteStartDate} AND #{reportReqVo.quoteEndDate}
  1285. </if>
  1286. group by comcode
  1287. ) as s
  1288. </select>
  1289. <resultMap id="PayApplyDeptReportListResMap" type="com.ydtech.modules.report.model.vo.PayApplyDeptReportListResVo">
  1290. <result column="orderno" property="orderno" />
  1291. <result column="policyno" property="policyno" />
  1292. <result column="riskcode" property="riskcode" />
  1293. <result column="licenseno" property="licenseno" />
  1294. <result column="comlevel" property="comlevel" />
  1295. <result column="comcode" property="comcode" />
  1296. <result column="keeprate" property="keeprate" />
  1297. <result column="addrate" property="addrate" />
  1298. <result column="keepamount" property="keepamount" />
  1299. <result column="addamount" property="addamount" />
  1300. <result column="auditstatus" property="auditstatus" />
  1301. <result column="settlestatus" property="settlestatus" />
  1302. <result column="inscompany" property="inscompany" />
  1303. <result column="signDate" property="signDate" />
  1304. </resultMap>
  1305. <select id="exportPayApplyDeptReportListData" resultMap="PayApplyDeptReportListResMap">
  1306. SELECT
  1307. p.orderno,
  1308. p.policyno,
  1309. p.riskcode,
  1310. p.licenseno,
  1311. p.comlevel,
  1312. p.comcode,
  1313. p.keeprate,
  1314. p.addrate,
  1315. p.keepamount,
  1316. p.addamount,
  1317. p.auditstatus,
  1318. p.settlestatus,
  1319. p.inscompany,
  1320. p.signDate
  1321. FROM
  1322. ins_deptfee p WHERE 1=1
  1323. <if test="reportReqVo.deptId != null and reportReqVo.deptId != ''">
  1324. and p.comcode = #{reportReqVo.deptId}
  1325. </if>
  1326. <if test="reportReqVo.insCompany != null and reportReqVo.insCompany != ''">
  1327. and p.inscompany = #{reportReqVo.insCompany}
  1328. </if>
  1329. </select>
  1330. </mapper>