FinanceRealFundMapper.xml 93 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  3. <mapper namespace="com.dayou.mapper.FinanceRealFundMapper">
  4. <!-- 通用查询映射结果 -->
  5. <resultMap id="BaseResultMap" type="com.dayou.entity.FinanceRealFund">
  6. <result column="id" property="id" />
  7. <result column="deleted" property="deleted" />
  8. <result column="modified" property="modified" />
  9. <result column="created" property="created" />
  10. <result column="payer" property="payer" />
  11. <result column="payer_bank" property="payerBank" />
  12. <result column="payer_account" property="payerAccount" />
  13. <result column="amount" property="amount" />
  14. <result column="pay_datetime" property="payDatetime" />
  15. <result column="remark" property="remark" />
  16. <result column="creator_id" property="creatorId" />
  17. </resultMap>
  18. <!-- 通用查询结果列 -->
  19. <sql id="Base_Column_List">
  20. id,
  21. deleted,
  22. modified,
  23. created,
  24. payer, payer_bank, payer_account, amount, pay_datetime, remark, creator_id
  25. </sql>
  26. <sql id="pageListSql">
  27. SELECT
  28. frf.id,
  29. frf.created,
  30. frf.payer,
  31. frf.payer_bank,
  32. frf.payer_account,
  33. frf.amount,
  34. frf.pay_datetime,
  35. frf.remark,
  36. frf.creator_id,
  37. u.name AS creator,
  38. ifnull(t.ca,0) AS claimAmount,
  39. ( frf.amount - ifnull(t.ca,0) ) AS notClaimAmount
  40. FROM
  41. finance_real_fund frf
  42. LEFT JOIN user u ON u.id = frf.creator_id
  43. LEFT JOIN ( SELECT real_fund_id, sum(ifnull(claim_amount,0)) ca FROM finance_claim WHERE deleted = 0 GROUP BY real_fund_id ) t ON t.real_fund_id = frf.id
  44. WHERE
  45. frf.deleted = 0
  46. <if test="vo!=null and vo.notFinished">
  47. and ifnull(t.ca,0) &lt; frf.amount
  48. </if>
  49. <if test="vo!=null and !vo.notFinished">
  50. and ifnull(t.ca,0) &gt;= frf.amount
  51. </if>
  52. <if test="keyword!=null and keyword!='' ">
  53. and (
  54. frf.payer like concat ('%',#{keyword},'%')
  55. or frf.payer_bank like concat('%',#{keyword},'%')
  56. or u.name like concat('%',#{keyword},'%')
  57. or frf.payer_account like concat('%',#{keyword},'%')
  58. or frf.amount like concat('%',#{keyword},'%')
  59. or frf.remark like concat('%',#{keyword},'%')
  60. )
  61. </if>
  62. <if test="vo!=null and vo.startDate!=null and vo.startDate!=''">
  63. and frf.pay_datetime &gt;= #{vo.startDate}
  64. </if>
  65. <if test="vo!=null and vo.endDate!=null and vo.endDate!=''">
  66. and frf.pay_datetime &lt;= #{vo.endDate}
  67. </if>
  68. <if test="vo!=null and vo.xStartDate!=null and vo.xStartDate!=''">
  69. and frf.created &gt;= #{vo.xStartDate}
  70. </if>
  71. <if test="vo!=null and vo.xEndDate!=null and vo.xEndDate!=''">
  72. and frf.created &lt;= #{vo.xEndDate}
  73. </if>
  74. </sql>
  75. <sql id="pageListSql1">
  76. SELECT
  77. #{userId} as userId,
  78. frf.id,
  79. frf.created,
  80. frf.payer,
  81. frf.payer_bank,
  82. frf.payer_account,
  83. frf.amount,
  84. frf.pay_datetime,
  85. frf.remark,
  86. frf.creator_id,
  87. u.name AS creator,
  88. ifnull(t.ca,0) AS claimAmount,
  89. ( frf.amount - ifnull(t.ca,0) ) AS notClaimAmount
  90. FROM
  91. finance_real_fund frf
  92. LEFT JOIN user u ON u.id = frf.creator_id
  93. LEFT JOIN ( SELECT real_fund_id, sum(ifnull(claim_amount,0)) ca FROM finance_claim WHERE deleted = 0 GROUP BY real_fund_id ) t ON t.real_fund_id = frf.id
  94. WHERE
  95. frf.deleted = 0
  96. <if test="vo!=null and vo.notFinished">
  97. and ifnull(t.ca,0) &lt; frf.amount
  98. </if>
  99. <if test="vo!=null and !vo.notFinished">
  100. and ifnull(t.ca,0) &gt;= frf.amount
  101. </if>
  102. <if test="keyword!=null and keyword!='' ">
  103. and (
  104. frf.payer like concat ('%',#{keyword},'%')
  105. or frf.payer_bank like concat('%',#{keyword},'%')
  106. or u.name like concat('%',#{keyword},'%')
  107. or frf.payer_account like concat('%',#{keyword},'%')
  108. or frf.amount like concat('%',#{keyword},'%')
  109. or frf.remark like concat('%',#{keyword},'%')
  110. )
  111. </if>
  112. <if test="vo!=null and vo.startDate!=null and vo.startDate!=''">
  113. and frf.pay_datetime &gt;= #{vo.startDate}
  114. </if>
  115. <if test="vo!=null and vo.endDate!=null and vo.endDate!=''">
  116. and frf.pay_datetime &lt;= #{vo.endDate}
  117. </if>
  118. <if test="vo!=null and vo.xStartDate!=null and vo.xStartDate!=''">
  119. and frf.created &gt;= #{vo.xStartDate}
  120. </if>
  121. <if test="vo!=null and vo.xEndDate!=null and vo.xEndDate!=''">
  122. and frf.created &lt;= #{vo.xEndDate}
  123. </if>
  124. ORDER BY
  125. ifnull(t.ca,0) ASC ,frf.created DESC
  126. </sql>
  127. <resultMap id="realAmountClaimMap" type="com.dayou.vo.FinanceRealFundVO">
  128. <result column="userId" property="userId" />
  129. <result column="id" property="id" />
  130. <result column="created" property="created" />
  131. <result column="payer" property="payer" />
  132. <result column="payer_bank" property="payerBank" />
  133. <result column="payer_account" property="payerAccount" />
  134. <result column="amount" property="amount" />
  135. <result column="pay_datetime" property="payDatetime" />
  136. <result column="remark" property="remark" />
  137. <result column="creator_id" property="creatorId" />
  138. <result column="creator" property="creator" />
  139. <result column="claimAmount" property="claimAmount" />
  140. <result column="notClaimAmount" property="notClaimAmount" />
  141. <collection property="recommends" select="findRecommends" ofType="java.lang.String" column="{amount=amount,userId=userId}" />
  142. </resultMap>
  143. <select id="getPage" parameterType="com.dayou.entity.FinanceRealFund" resultType="com.dayou.vo.FinanceRealFundVO">
  144. <include refid="pageListSql" />
  145. ORDER BY
  146. ifnull(t.ca,0) ASC ,frf.created DESC
  147. </select>
  148. <select id="claimPage" resultMap="realAmountClaimMap">
  149. SELECT
  150. #{userId} as userId,
  151. frf.id,
  152. frf.created,
  153. frf.payer,
  154. frf.payer_bank,
  155. frf.payer_account,
  156. frf.amount,
  157. frf.pay_datetime,
  158. frf.remark,
  159. frf.creator_id,
  160. u.name AS creator,
  161. ifnull(t.ca,0) AS claimAmount,
  162. ( frf.amount - ifnull(t.ca,0) ) AS notClaimAmount
  163. FROM
  164. finance_real_fund frf
  165. LEFT JOIN user u ON u.id = frf.creator_id
  166. LEFT JOIN ( SELECT real_fund_id, sum(ifnull(claim_amount,0)) ca FROM finance_claim WHERE deleted = 0 GROUP BY real_fund_id ) t ON t.real_fund_id = frf.id
  167. WHERE
  168. frf.deleted = 0
  169. <if test="vo!=null and vo.notFinished">
  170. and ifnull(t.ca,0) &lt; frf.amount
  171. </if>
  172. <if test="vo!=null and !vo.notFinished">
  173. and ifnull(t.ca,0) &gt;= frf.amount
  174. </if>
  175. <if test="keyword!=null and keyword!='' ">
  176. and (
  177. frf.payer like concat ('%',#{keyword},'%')
  178. or frf.payer_bank like concat('%',#{keyword},'%')
  179. or u.name like concat('%',#{keyword},'%')
  180. or frf.payer_account like concat('%',#{keyword},'%')
  181. or frf.amount like concat('%',#{keyword},'%')
  182. or frf.remark like concat('%',#{keyword},'%')
  183. )
  184. </if>
  185. <if test="vo!=null and vo.startDate!=null and vo.startDate!=''">
  186. and frf.pay_datetime &gt;= #{vo.startDate}
  187. </if>
  188. <if test="vo!=null and vo.endDate!=null and vo.endDate!=''">
  189. and frf.pay_datetime &lt;= #{vo.endDate}
  190. </if>
  191. <if test="vo!=null and vo.xStartDate!=null and vo.xStartDate!=''">
  192. and frf.created &gt;= #{vo.xStartDate}
  193. </if>
  194. <if test="vo!=null and vo.xEndDate!=null and vo.xEndDate!=''">
  195. and frf.created &lt;= #{vo.xEndDate}
  196. </if>
  197. ORDER BY
  198. frf.created DESC
  199. </select>
  200. <select id="findRecommends" resultType="java.lang.String">
  201. SELECT
  202. tt1.business_type
  203. FROM
  204. (
  205. SELECT
  206. order_fund.real_amount,
  207. order_fund.business_type,
  208. temp.invoiceAmount
  209. FROM
  210. (
  211. SELECT
  212. order_fund_id,
  213. sum( real_amount ) AS invoiceAmount
  214. FROM
  215. finance_invoice
  216. WHERE
  217. state = '已开票'
  218. AND deleted = 0
  219. AND production_fund_id IS NULL
  220. <if test="userId!=null">
  221. and apply_id = #{userId}
  222. </if>
  223. GROUP BY
  224. order_fund_id UNION ALL
  225. SELECT
  226. order_fund_id,
  227. sum( real_amount ) AS invoiceAmount
  228. FROM
  229. finance_invoice
  230. WHERE
  231. state = '已开票'
  232. AND deleted = 0
  233. AND production_fund_id IS NOT NULL
  234. <if test="userId!=null">
  235. and apply_id = #{userId}
  236. </if>
  237. GROUP BY
  238. production_fund_id
  239. ) temp
  240. LEFT JOIN order_fund ON order_fund.id = temp.order_fund_id
  241. ) tt1
  242. WHERE
  243. tt1.invoiceAmount = #{amount}
  244. AND tt1.real_amount IS NULL
  245. </select>
  246. <select id="getNotClaimAmount" parameterType="java.lang.Long" resultType="java.math.BigDecimal">
  247. SELECT ( frf.amount -( SELECT ifnull( sum( claim_amount ), 0 ) AS ca FROM finance_claim WHERE deleted = 0 AND real_fund_id = #{realFundId} )
  248. ) AS notClaimAmount
  249. FROM
  250. finance_real_fund frf
  251. WHERE
  252. frf.id = #{realFundId}
  253. AND frf.deleted = 0
  254. </select>
  255. <sql id="majorOverdueSql">
  256. SELECT
  257. DATEDIFF(
  258. CURDATE(),
  259. DATE( mp.repertory_out_time )) AS overdueDay,
  260. pf.production,
  261. m.allot_type,
  262. m.order_id,
  263. m.business_object_type,
  264. u.NAME AS clientManager,
  265. u1.NAME AS principal,
  266. cc1.NAME AS clientName,
  267. cc2.NAME AS clientSubName,
  268. pf.production_should_amount as shouldAmount,
  269. mp.*
  270. FROM
  271. ( SELECT business_id, production_no,
  272. ( CASE production_type WHEN 'STATEMENT' THEN '意见书' WHEN 'REPORT' THEN '报告' WHEN 'LETTER' THEN '复评函' ELSE '' END ) production,
  273. production_type
  274. , production_should_amount, real_amount FROM production_fund WHERE business_type = 'MAJOR_BUSINESS'
  275. AND deleted = 0 and production_should_amount is not null and production_should_amount!=0 and real_amount is null) pf
  276. inner join
  277. (
  278. SELECT
  279. id,
  280. major_id,
  281. report_no,
  282. production as productionType,
  283. NAME,
  284. evaluate_amount,
  285. repertory_out_time,
  286. standard_amount
  287. FROM
  288. major_production mp
  289. WHERE
  290. deleted = 0
  291. AND repertory_out_time IS NOT NULL
  292. ) mp
  293. ON ( mp.major_id = pf.business_id AND mp.report_no = pf.production_no and mp.productionType = pf.production_type )
  294. LEFT JOIN major m ON m.id = mp.major_id
  295. LEFT JOIN user u ON u.id = m.client_manager_id
  296. LEFT JOIN user u1 ON u1.id = m.principal_id
  297. LEFT JOIN customer_company cc1 ON cc1.id = m.clientele_id
  298. LEFT JOIN customer_company cc2 ON cc2.id = m.clientele_sub_id
  299. <where>
  300. and mp.repertory_out_time>'2024-01-01 00:00:00'
  301. <if test="overdueVO!=null and overdueVO.overdueMin!=null">
  302. AND DATEDIFF(CURDATE(),DATE( mp.repertory_out_time )) >= #{overdueVO.overdueMin}
  303. </if>
  304. <if test="overdueVO!=null and overdueVO.overdueMax!=null">
  305. AND DATEDIFF(CURDATE(),DATE( mp.repertory_out_time )) &lt;= #{overdueVO.overdueMax}
  306. </if>
  307. <if test="overdueVO!=null and overdueVO.orderId!=null and overdueVO.orderId!=''">
  308. and m.order_id = #{overdueVO.orderId}
  309. </if>
  310. <if test="overdueVO!=null and overdueVO.reportNo!=null and overdueVO.reportNo!=''">
  311. and mp.report_no like concat ('%',#{overdueVO.reportNo},'%')
  312. </if>
  313. <if test="overdueVO!=null and overdueVO.principal!=null and overdueVO.principal!=''">
  314. and u1.NAME like concat ('%',#{overdueVO.principal},'%')
  315. </if>
  316. <if test="overdueVO!=null and overdueVO.userIds!=null and overdueVO.userIds.size!=0">
  317. and m.client_manager_id in
  318. <foreach collection="overdueVO.userIds" open="(" close=")" separator="," item="userId">
  319. #{userId}
  320. </foreach>
  321. </if>
  322. </where>
  323. order by overdueDay ASC
  324. </sql>
  325. <select id="overdueMajor" parameterType="com.dayou.vo.MajorProdOverdueVO" resultType="com.dayou.vo.MajorProdOverdueVO">
  326. <include refid="majorOverdueSql" />
  327. </select>
  328. <select id="overdueMajorExport" parameterType="com.dayou.vo.MajorProdOverdueVO" resultType="com.dayou.vo.MajorProdOverdueVO">
  329. <include refid="majorOverdueSql" />
  330. </select>
  331. <resultMap id="settleeMajorProductionVOMap" type="com.dayou.vo.SettleMajorProductionVO">
  332. <id property="id" column="id" />
  333. <result property="id" column="id" />
  334. <result property="claimAmount" column="claim_amount" />
  335. <result property="orderId" column="order_id" />
  336. <result property="reportNo" column="report_no" />
  337. <result property="claimDate" column="claimDate" />
  338. <result property="saveFileDate" column="save_file_date" />
  339. <result property="settleDate" column="settleDate" />
  340. <result property="deliveryDate" column="deliveryDate" />
  341. <result property="name" column="name" />
  342. <result property="bailor" column="bailor" />
  343. <result property="evaluateAmount" column="evaluate_amount" />
  344. <result property="principal" column="principal" />
  345. <result property="clientManager" column="clientManager" />
  346. <result property="clientName" column="clientName" />
  347. <result property="clientSubName" column="clientSubName" />
  348. <result property="evaluateDepartmentName" column="evaluateDepartmentName" />
  349. <result property="marketDepartmentName" column="marketDepartmentName" />
  350. <result property="payDateTime" column="pay_datetime" />
  351. <result property="members" column="members" />
  352. <!-- <collection property="invoices" ofType="com.dayou.vo.SettleProInvoiceVo">-->
  353. <!-- <result property="invoiceDate" column="invoiceDate" />-->
  354. <!-- <result property="invoiceUser" column="invoiceUser" />-->
  355. <!-- <result property="invoiceNo" column="invoiceNo" />-->
  356. <!-- </collection>-->
  357. </resultMap>
  358. <sql id="majorEvaluatorSettleSql">
  359. SELECT
  360. fc.id,
  361. fc.claim_amount,
  362. m.order_id,
  363. mp.report_no,
  364. fc.claim_datetime as claimDate,
  365. mp.save_file_date,
  366. IF
  367. ( fc.claim_datetime > mp.save_file_date, fc.claim_datetime, mp.save_file_date ) AS settleDate,
  368. mp.name,
  369. m.bailor,
  370. m.members,
  371. mp.evaluate_amount,
  372. u.name AS principal,
  373. u1.name AS clientManager,
  374. cc.name AS clientName,
  375. cc1.name AS clientSubName,
  376. d.name AS evaluateDepartmentName,
  377. (
  378. SELECT
  379. GROUP_CONCAT( name )
  380. FROM
  381. department
  382. WHERE
  383. id IN (
  384. SELECT
  385. department_id
  386. FROM
  387. post
  388. WHERE
  389. id IN ( SELECT post_id FROM user_post WHERE user_id = m.client_manager_id ))) AS marketDepartmentName,
  390. frf.pay_datetime
  391. FROM
  392. (
  393. SELECT
  394. id,
  395. claim_amount,
  396. order_fund_id,
  397. production_fund_id,
  398. claim_datetime,
  399. real_fund_id
  400. FROM
  401. finance_claim
  402. WHERE
  403. deleted = 0
  404. AND production_fund_id IS NOT NULL
  405. ) fc
  406. INNER JOIN ( SELECT id, pay_datetime FROM finance_real_fund WHERE deleted = 0
  407. <if test="settleVO!=null and settleVO.payStartDate!=null and settleVO.payStartDate!='' ">
  408. AND pay_datetime &gt;= #{settleVO.payStartDate}
  409. </if>
  410. <if test="settleVO!=null and settleVO.payEndDate!=null and settleVO.payEndDate!='' ">
  411. AND pay_datetime &lt;= #{settleVO.payEndDate}
  412. </if>
  413. ) frf ON frf.id = fc.real_fund_id
  414. INNER JOIN ( SELECT id, order_fund_id, business_id, production_no FROM production_fund WHERE business_type = 'MAJOR_BUSINESS' AND deleted = 0 ) pf ON ( pf.id = fc.production_fund_id AND pf.order_fund_id = fc.order_fund_id )
  415. INNER JOIN (
  416. SELECT
  417. id,
  418. major_id,
  419. NAME,
  420. report_no,
  421. production,
  422. evaluate_amount,
  423. save_file_date,
  424. fund.real_amount
  425. FROM
  426. major_production mpr
  427. INNER JOIN ( SELECT production_no, real_amount, production_type FROM production_fund WHERE deleted = 0 AND business_type = 'MAJOR_BUSINESS' ) fund ON ( fund.production_no = mpr.report_no AND fund.production_type = mpr.production )
  428. WHERE
  429. fund.real_amount IS NOT NULL
  430. AND mpr.save_file_date IS NOT NULL
  431. ) mp ON mp.report_no = pf.production_no
  432. LEFT JOIN major m ON m.id = mp.major_id
  433. LEFT JOIN user u ON u.id = m.principal_id
  434. LEFT JOIN user u1 ON u1.id = m.client_manager_id
  435. LEFT JOIN customer_company cc ON cc.id = m.clientele_id
  436. LEFT JOIN customer_company cc1 ON cc1.id = m.clientele_sub_id
  437. LEFT JOIN department d ON d.id = m.department_id
  438. <where>
  439. m.financial is not null
  440. <if test="keyword!=null and keyword!='' ">
  441. and (
  442. mp.report_no like concat ('%',#{keyword},'%')
  443. or fc.claim_amount =#{keyword}
  444. or m.order_id like concat('%',#{keyword},'%')
  445. or u.name like concat('%',#{keyword},'%')
  446. or u1.name like concat('%',#{keyword},'%')
  447. )
  448. </if>
  449. <if test="settleVO!=null and settleVO.startDate!=null and settleVO.startDate!='' ">
  450. AND (select IF
  451. ( fc.claim_datetime > mp.save_file_date, fc.claim_datetime, mp.save_file_date )) &gt;= #{settleVO.startDate}
  452. </if>
  453. <if test="settleVO!=null and settleVO.endDate!=null and settleVO.endDate!='' ">
  454. AND (select IF
  455. ( fc.claim_datetime > mp.save_file_date, fc.claim_datetime, mp.save_file_date )) &lt;= #{settleVO.endDate}
  456. </if>
  457. </where>
  458. order by fc.claim_datetime ASC
  459. </sql>
  460. <select id="majorEvaluatorSettleProd" parameterType="com.dayou.vo.SettleMajorProductionVO" resultMap="settleeMajorProductionVOMap">
  461. <include refid="majorEvaluatorSettleSql" />
  462. </select>
  463. <select id="majorEvaluatorSettleExport" parameterType="com.dayou.vo.SettleMajorProductionVO" resultMap="settleeMajorProductionVOMap">
  464. <include refid="majorEvaluatorSettleSql" />
  465. </select>
  466. <sql id="majorMarketerSettleSql">
  467. SELECT
  468. fc.id,
  469. fc.claim_amount,
  470. m.order_id,
  471. mp.report_no,
  472. fc.claim_datetime AS claimDate,
  473. mp.delivery_date AS deliveryDate,
  474. IF
  475. ( fc.claim_datetime > mp.delivery_date, fc.claim_datetime, mp.delivery_date ) AS settleDate,
  476. mp.NAME,
  477. m.bailor,
  478. m.members,
  479. mp.evaluate_amount,
  480. u.NAME AS principal,
  481. u1.NAME AS clientManager,
  482. cc.NAME AS clientName,
  483. cc1.NAME AS clientSubName,
  484. d.NAME AS evaluateDepartmentName,
  485. (
  486. SELECT
  487. GROUP_CONCAT( NAME )
  488. FROM
  489. department
  490. WHERE
  491. id IN (
  492. SELECT
  493. department_id
  494. FROM
  495. post
  496. WHERE
  497. id IN ( SELECT post_id FROM user_post WHERE user_id = m.client_manager_id and deleted = 0 ))) AS marketDepartmentName,
  498. frf.pay_datetime
  499. FROM
  500. (
  501. SELECT
  502. id,
  503. claim_amount,
  504. order_fund_id,
  505. production_fund_id,
  506. claim_datetime,
  507. real_fund_id
  508. FROM
  509. finance_claim
  510. WHERE
  511. deleted = 0
  512. AND production_fund_id IS NOT NULL
  513. ) fc
  514. INNER JOIN ( SELECT id, pay_datetime FROM finance_real_fund WHERE deleted = 0
  515. <if test="settleVO!=null and settleVO.payStartDate!=null and settleVO.payStartDate!='' ">
  516. AND pay_datetime &gt;= #{settleVO.payStartDate}
  517. </if>
  518. <if test="settleVO!=null and settleVO.payEndDate!=null and settleVO.payEndDate!='' ">
  519. AND pay_datetime &lt;= #{settleVO.payEndDate}
  520. </if>
  521. ) frf ON frf.id = fc.real_fund_id
  522. INNER JOIN ( SELECT id, order_fund_id, business_id, production_no FROM production_fund WHERE business_type = 'MAJOR_BUSINESS' AND deleted = 0 ) pf ON ( pf.id = fc.production_fund_id AND pf.order_fund_id = fc.order_fund_id )
  523. INNER JOIN (
  524. SELECT
  525. id,
  526. major_id,
  527. NAME,
  528. report_no,
  529. production,
  530. evaluate_amount,
  531. delivery_date,
  532. fund.real_amount
  533. FROM
  534. major_production mpr
  535. INNER JOIN ( SELECT production_no, real_amount, production_type FROM production_fund WHERE deleted = 0 AND business_type = 'MAJOR_BUSINESS' ) fund ON ( fund.production_no = mpr.report_no AND fund.production_type = mpr.production )
  536. WHERE
  537. fund.real_amount IS NOT NULL
  538. AND mpr.delivery_date IS NOT NULL
  539. ) mp ON mp.report_no = pf.production_no
  540. LEFT JOIN major m ON m.id = mp.major_id
  541. LEFT JOIN user u ON u.id = m.principal_id
  542. LEFT JOIN user u1 ON u1.id = m.client_manager_id
  543. LEFT JOIN customer_company cc ON cc.id = m.clientele_id
  544. LEFT JOIN customer_company cc1 ON cc1.id = m.clientele_sub_id
  545. LEFT JOIN department d ON d.id = m.department_id
  546. <where>
  547. m.financial is not null
  548. <if test="keyword!=null and keyword!='' ">
  549. and (
  550. mp.report_no like concat ('%',#{keyword},'%')
  551. or fc.claim_amount =#{keyword}
  552. or m.order_id like concat('%',#{keyword},'%')
  553. or u.name like concat('%',#{keyword},'%')
  554. or u1.name like concat('%',#{keyword},'%')
  555. )
  556. </if>
  557. <if test="settleVO!=null and settleVO.startDate!=null and settleVO.startDate!='' ">
  558. AND (select IF
  559. ( fc.claim_datetime > mp.delivery_date, fc.claim_datetime, mp.delivery_date )) &gt;= #{settleVO.startDate}
  560. </if>
  561. <if test="settleVO!=null and settleVO.endDate!=null and settleVO.endDate!='' ">
  562. AND (select IF
  563. ( fc.claim_datetime > mp.delivery_date, fc.claim_datetime, mp.delivery_date )) &lt;= #{settleVO.endDate}
  564. </if>
  565. </where>
  566. order by fc.claim_datetime ASC
  567. </sql>
  568. <select id="majorMarketerSettleProd" parameterType="com.dayou.vo.SettleMajorProductionVO" resultMap="settleeMajorProductionVOMap">
  569. <include refid="majorMarketerSettleSql" />
  570. </select>
  571. <select id="majorMarketSettleExport" parameterType="com.dayou.vo.SettleMajorProductionVO" resultMap="settleeMajorProductionVOMap">
  572. <include refid="majorMarketerSettleSql" />
  573. </select>
  574. <select id="majorEvaluatorCommission" parameterType="com.dayou.vo.UserCommissionTotalAmountVO" resultType="com.dayou.vo.UserCommissionTotalAmountVO">
  575. SELECT mpa.user_id as id, u.name as userName, sum(( fc.claim_amount * ( bcr.min_ratio / 100 )* mpa.ratio )) AS commissionTotalAmount
  576. FROM
  577. (
  578. SELECT
  579. claim_amount,
  580. order_fund_id,
  581. production_fund_id,
  582. claim_datetime
  583. FROM
  584. finance_claim
  585. WHERE
  586. deleted = 0
  587. AND production_fund_id IS NOT NULL
  588. AND claim_datetime &gt;= #{vo.startDate}
  589. AND claim_datetime &lt;= #{vo.endDate}
  590. ) fc
  591. INNER JOIN ( SELECT id, order_fund_id, business_id, production_no FROM production_fund WHERE business_type = 'MAJOR_BUSINESS' AND deleted = 0 ) pf ON ( pf.id = fc.production_fund_id AND pf.order_fund_id = fc.order_fund_id )
  592. INNER JOIN (
  593. SELECT
  594. id,
  595. major_id,
  596. NAME,
  597. report_no,
  598. production,
  599. evaluate_amount,
  600. save_file_date,
  601. fund.real_amount
  602. FROM
  603. major_production mpr
  604. INNER JOIN ( SELECT production_no, real_amount, production_type FROM production_fund WHERE deleted = 0 AND business_type = 'MAJOR_BUSINESS' ) fund ON ( fund.production_no = mpr.report_no AND fund.production_type = mpr.production )
  605. WHERE
  606. fund.real_amount IS NOT NULL
  607. AND mpr.save_file_date IS NOT NULL
  608. ) mp ON mp.report_no = pf.production_no
  609. LEFT JOIN (select * from major where financial is not null) m ON m.id = mp.major_id
  610. INNER JOIN ( SELECT id, business_id, production_id, commission_rate_id FROM commission_declare WHERE business_type = 'COMMISSION_DECLARE_MAJOR_EVALUATE' AND deleted = 0 AND declare_result = '审核通过' ) cd ON (
  611. cd.business_id = m.id
  612. AND cd.production_id = mp.id )
  613. LEFT JOIN business_commission_rate bcr ON bcr.id = cd.commission_rate_id
  614. LEFT JOIN dict_data dd ON dd.id = bcr.business_cate_id
  615. LEFT JOIN ( SELECT major_id, major_production_id, user_id, ratio FROM major_production_allot WHERE deleted = 0 AND user_type = 'EVALUATE'
  616. ) mpa ON ( mpa.major_id = m.id AND mpa.major_production_id = mp.id)
  617. LEFT JOIN user u ON u.id = mpa.user_id
  618. <where>
  619. <if test="vo!=null and vo.userIds!=null and vo.userIds.size!=0">
  620. mpa.user_id in
  621. <foreach collection="vo.userIds" open="(" close=")" separator="," item="userId">
  622. #{userId}
  623. </foreach>
  624. </if>
  625. </where>
  626. GROUP BY
  627. mpa.user_id
  628. having 1=1
  629. <if test="vo!=null and vo.userName!=null and vo.userName!=''">
  630. and u.name like concat ('%',#{vo.userName},'%')
  631. </if>
  632. order by commissionTotalAmount DESC
  633. </select>
  634. <select id="majorEvaluatorCommissionDetail" parameterType="com.dayou.vo.UserCommissionProdVO" resultType="com.dayou.vo.UserCommissionProdVO">
  635. SELECT
  636. mp.id,
  637. fc.claim_amount as realAmount,
  638. mp.report_no,
  639. IF
  640. ( fc.claim_datetime > mp.save_file_date, fc.claim_datetime, mp.save_file_date ) AS settleDate,
  641. mp.NAME,
  642. mp.created,
  643. dd.NAME AS businessCate,
  644. bcr.min_ratio AS ratio,
  645. mpa.user_id,
  646. mpa.ratio AS allotRatio,
  647. ( fc.claim_amount * ( bcr.min_ratio / 100 )* mpa.ratio ) AS commissionAmount,
  648. ( fc.claim_amount * ( bcr.min_ratio / 100 ) ) AS totalAmount,
  649. u.name as userName
  650. FROM
  651. (
  652. SELECT
  653. claim_amount,
  654. order_fund_id,
  655. production_fund_id,
  656. claim_datetime
  657. FROM
  658. finance_claim
  659. WHERE
  660. deleted = 0
  661. AND production_fund_id IS NOT NULL
  662. AND claim_datetime &gt;= #{vo.startDate}
  663. AND claim_datetime &lt;= #{vo.endDate}
  664. ) fc
  665. INNER JOIN ( SELECT id, order_fund_id, business_id, production_no FROM production_fund WHERE business_type = 'MAJOR_BUSINESS' AND deleted = 0 ) pf ON ( pf.id = fc.production_fund_id AND pf.order_fund_id = fc.order_fund_id )
  666. INNER JOIN (
  667. SELECT
  668. id,
  669. major_id,
  670. NAME,
  671. report_no,
  672. production,
  673. evaluate_amount,
  674. save_file_date,
  675. fund.real_amount,
  676. created
  677. FROM
  678. major_production mpr
  679. INNER JOIN ( SELECT production_no, real_amount, production_type FROM production_fund WHERE deleted = 0 AND business_type = 'MAJOR_BUSINESS' ) fund ON ( fund.production_no = mpr.report_no AND fund.production_type = mpr.production )
  680. WHERE
  681. fund.real_amount IS NOT NULL
  682. AND mpr.save_file_date IS NOT NULL
  683. ) mp ON mp.report_no = pf.production_no
  684. LEFT JOIN major m ON m.id = mp.major_id
  685. INNER JOIN ( SELECT id, business_id, production_id, commission_rate_id FROM commission_declare WHERE business_type = 'COMMISSION_DECLARE_MAJOR_EVALUATE' AND deleted = 0 AND declare_result = '审核通过' ) cd ON (
  686. cd.business_id = m.id
  687. AND cd.production_id = mp.id )
  688. LEFT JOIN business_commission_rate bcr ON bcr.id = cd.commission_rate_id
  689. LEFT JOIN dict_data dd ON dd.id = bcr.business_cate_id
  690. LEFT JOIN ( SELECT major_id, major_production_id, user_id, ratio FROM major_production_allot WHERE deleted = 0 AND user_type = 'EVALUATE' ) mpa ON ( mpa.major_id = m.id AND mpa.major_production_id = mp.id)
  691. LEFT JOIN user u on u.id = mpa.user_id
  692. WHERE
  693. m.financial is not null and
  694. mpa.user_id = #{vo.userId}
  695. order by settleDate DESC
  696. </select>
  697. <select id="majorEvaluatorTotalAmountExport" parameterType="com.dayou.vo.UserCommissionTotalAmountVO" resultType="com.dayou.vo.UserCommissionTotalAmountVO">
  698. SELECT mpa.user_id as id, u.name as userName, ROUND(sum(( fc.claim_amount * ( bcr.min_ratio / 100 )* mpa.ratio )),2) AS commissionTotalAmount,
  699. '评估人员' as userType,
  700. '大中型业务' as businessType,
  701. #{vo.startDate} as startDate,
  702. #{vo.endDate} as endDate
  703. FROM
  704. (
  705. SELECT
  706. claim_amount,
  707. order_fund_id,
  708. production_fund_id,
  709. claim_datetime
  710. FROM
  711. finance_claim
  712. WHERE
  713. deleted = 0
  714. AND production_fund_id IS NOT NULL
  715. AND claim_datetime &gt;= #{vo.startDate}
  716. AND claim_datetime &lt;= #{vo.endDate}
  717. ) fc
  718. INNER JOIN ( SELECT id, order_fund_id, business_id, production_no FROM production_fund WHERE business_type = 'MAJOR_BUSINESS' AND deleted = 0 ) pf ON ( pf.id = fc.production_fund_id AND pf.order_fund_id = fc.order_fund_id )
  719. INNER JOIN (
  720. SELECT
  721. id,
  722. major_id,
  723. NAME,
  724. report_no,
  725. production,
  726. evaluate_amount,
  727. save_file_date,
  728. fund.real_amount
  729. FROM
  730. major_production mpr
  731. INNER JOIN ( SELECT production_no, real_amount, production_type FROM production_fund WHERE deleted = 0 AND business_type = 'MAJOR_BUSINESS' ) fund ON ( fund.production_no = mpr.report_no AND fund.production_type = mpr.production )
  732. WHERE
  733. fund.real_amount IS NOT NULL
  734. AND mpr.save_file_date IS NOT NULL
  735. ) mp ON mp.report_no = pf.production_no
  736. LEFT JOIN major m ON m.id = mp.major_id
  737. INNER JOIN ( SELECT id, business_id, production_id, commission_rate_id FROM commission_declare WHERE business_type = 'COMMISSION_DECLARE_MAJOR_EVALUATE' AND deleted = 0 AND declare_result = '审核通过' ) cd ON (
  738. cd.business_id = m.id
  739. AND cd.production_id = mp.id )
  740. LEFT JOIN business_commission_rate bcr ON bcr.id = cd.commission_rate_id
  741. LEFT JOIN dict_data dd ON dd.id = bcr.business_cate_id
  742. LEFT JOIN ( SELECT major_id, major_production_id, user_id, ratio FROM major_production_allot WHERE deleted = 0 AND user_type = 'EVALUATE'
  743. ) mpa ON ( mpa.major_id = m.id AND mpa.major_production_id = mp.id)
  744. LEFT JOIN user u ON u.id = mpa.user_id
  745. GROUP BY
  746. mpa.user_id
  747. </select>
  748. <select id="evaluatorUserDetailExport" parameterType="com.dayou.vo.UserCommissionProdVO" resultType="com.dayou.vo.UserCommissionProdVO">
  749. SELECT
  750. mp.id,
  751. ROUND(fc.claim_amount,2) as realAmount,
  752. mp.report_no,
  753. IF
  754. ( fc.claim_datetime > mp.save_file_date, fc.claim_datetime, mp.save_file_date ) AS settleDate,
  755. mp.NAME,
  756. mp.created,
  757. dd.NAME AS businessCate,
  758. ROUND(bcr.min_ratio,2) AS ratio,
  759. mpa.user_id,
  760. ROUND(mpa.ratio*100,2) AS allotRatio,
  761. ROUND(( fc.claim_amount * ( bcr.min_ratio / 100 )* mpa.ratio ),2) AS commissionAmount,
  762. ROUND(( fc.claim_amount * ( bcr.min_ratio / 100 ) ),2) AS totalAmount,
  763. u.name as userName
  764. FROM
  765. (
  766. SELECT
  767. claim_amount,
  768. order_fund_id,
  769. production_fund_id,
  770. claim_datetime
  771. FROM
  772. finance_claim
  773. WHERE
  774. deleted = 0
  775. AND production_fund_id IS NOT NULL
  776. AND claim_datetime &gt;= #{vo.startDate}
  777. AND claim_datetime &lt;= #{vo.endDate}
  778. ) fc
  779. INNER JOIN ( SELECT id, order_fund_id, business_id, production_no FROM production_fund WHERE business_type = 'MAJOR_BUSINESS' AND deleted = 0 ) pf ON ( pf.id = fc.production_fund_id AND pf.order_fund_id = fc.order_fund_id )
  780. INNER JOIN (
  781. SELECT
  782. id,
  783. major_id,
  784. NAME,
  785. report_no,
  786. production,
  787. evaluate_amount,
  788. save_file_date,
  789. fund.real_amount,
  790. created
  791. FROM
  792. major_production mpr
  793. INNER JOIN ( SELECT production_no, real_amount, production_type FROM production_fund WHERE deleted = 0 AND business_type = 'MAJOR_BUSINESS' ) fund ON ( fund.production_no = mpr.report_no AND fund.production_type = mpr.production )
  794. WHERE
  795. fund.real_amount IS NOT NULL
  796. AND mpr.save_file_date IS NOT NULL
  797. ) mp ON mp.report_no = pf.production_no
  798. LEFT JOIN major m ON m.id = mp.major_id
  799. INNER JOIN ( SELECT id, business_id, production_id, commission_rate_id FROM commission_declare WHERE business_type = 'COMMISSION_DECLARE_MAJOR_EVALUATE' AND deleted = 0 AND declare_result = '审核通过' ) cd ON (
  800. cd.business_id = m.id
  801. AND cd.production_id = mp.id )
  802. LEFT JOIN business_commission_rate bcr ON bcr.id = cd.commission_rate_id
  803. LEFT JOIN dict_data dd ON dd.id = bcr.business_cate_id
  804. LEFT JOIN ( SELECT major_id, major_production_id, user_id, ratio FROM major_production_allot WHERE deleted = 0 AND user_type = 'EVALUATE' ) mpa ON ( mpa.major_id = m.id AND mpa.major_production_id = mp.id)
  805. LEFT JOIN user u on u.id = mpa.user_id
  806. <where>
  807. <if test="vo!=null and vo.userId!=null">
  808. and mpa.user_id = #{vo.userId}
  809. </if>
  810. </where>
  811. order by mpa.user_id
  812. </select>
  813. <select id="majorMarketCommission" parameterType="com.dayou.vo.UserCommissionTotalAmountVO" resultType="com.dayou.vo.UserCommissionTotalAmountVO">
  814. SELECT mpa.user_id as id, u.name as userName, sum(( fc.claim_amount * ( bcr.min_ratio / 100 )* mpa.ratio )) AS commissionTotalAmount
  815. FROM
  816. (
  817. SELECT
  818. claim_amount,
  819. order_fund_id,
  820. production_fund_id,
  821. claim_datetime
  822. FROM
  823. finance_claim
  824. WHERE
  825. deleted = 0
  826. AND production_fund_id IS NOT NULL
  827. AND claim_datetime &gt;= #{vo.startDate}
  828. AND claim_datetime &lt;= #{vo.endDate}
  829. ) fc
  830. INNER JOIN ( SELECT id, order_fund_id, business_id, production_no FROM production_fund WHERE business_type = 'MAJOR_BUSINESS' AND deleted = 0 ) pf ON ( pf.id = fc.production_fund_id AND pf.order_fund_id = fc.order_fund_id )
  831. INNER JOIN (
  832. SELECT
  833. id,
  834. major_id,
  835. NAME,
  836. report_no,
  837. production,
  838. evaluate_amount,
  839. delivery_date,
  840. fund.real_amount
  841. FROM
  842. major_production mpr
  843. INNER JOIN ( SELECT production_no, real_amount, production_type FROM production_fund WHERE deleted = 0 AND business_type = 'MAJOR_BUSINESS' ) fund ON ( fund.production_no = mpr.report_no AND fund.production_type = mpr.production )
  844. WHERE
  845. fund.real_amount IS NOT NULL
  846. AND mpr.delivery_date IS NOT NULL
  847. ) mp ON mp.report_no = pf.production_no
  848. LEFT JOIN (select * from major where financial is not null) m ON m.id = mp.major_id
  849. INNER JOIN ( SELECT id, business_id, production_id, commission_rate_id FROM commission_declare WHERE business_type = 'COMMISSION_DECLARE_MAJOR_MARKET' AND deleted = 0 AND declare_result = '审核通过' ) cd ON (
  850. cd.business_id = m.id
  851. AND cd.production_id = mp.id )
  852. LEFT JOIN business_commission_rate bcr ON bcr.id = cd.commission_rate_id
  853. LEFT JOIN dict_data dd ON dd.id = bcr.business_cate_id
  854. LEFT JOIN ( SELECT major_id, major_production_id,declare_id, user_id, ratio FROM major_production_allot WHERE deleted = 0 AND user_type = 'MARKET'
  855. ) mpa ON ( mpa.major_id = m.id AND cd.id = mpa.declare_id AND (mpa.major_production_id is null or mpa.major_production_id = mp.id ))
  856. LEFT JOIN user u ON u.id = mpa.user_id
  857. <where>
  858. <if test="vo!=null and vo.userIds!=null and vo.userIds.size!=0">
  859. mpa.user_id in
  860. <foreach collection="vo.userIds" open="(" close=")" separator="," item="userId">
  861. #{userId}
  862. </foreach>
  863. </if>
  864. </where>
  865. GROUP BY
  866. mpa.user_id
  867. having 1=1
  868. <if test="vo!=null and vo.userName!=null and vo.userName!=''">
  869. and u.name like concat ('%',#{vo.userName},'%')
  870. </if>
  871. order by commissionTotalAmount DESC
  872. </select>
  873. <select id="majorMarketCommissionDetail" parameterType="com.dayou.vo.UserCommissionProdVO" resultType="com.dayou.vo.UserCommissionProdVO">
  874. SELECT
  875. mp.id,
  876. fc.claim_amount as realAmount,
  877. mp.report_no,
  878. IF
  879. ( fc.claim_datetime > mp.delivery_date, fc.claim_datetime, mp.delivery_date ) AS settleDate,
  880. mp.NAME,
  881. mp.created,
  882. dd.NAME AS businessCate,
  883. bcr.min_ratio AS ratio,
  884. mpa.user_id,
  885. mpa.ratio AS allotRatio,
  886. ( fc.claim_amount * ( bcr.min_ratio / 100 )* mpa.ratio ) AS commissionAmount,
  887. ( fc.claim_amount * ( bcr.min_ratio / 100 ) ) AS totalAmount,
  888. u.name as userName
  889. FROM
  890. (
  891. SELECT
  892. claim_amount,
  893. order_fund_id,
  894. production_fund_id,
  895. claim_datetime
  896. FROM
  897. finance_claim
  898. WHERE
  899. deleted = 0
  900. AND production_fund_id IS NOT NULL
  901. AND claim_datetime &gt;= #{vo.startDate}
  902. AND claim_datetime &lt;= #{vo.endDate}
  903. ) fc
  904. INNER JOIN ( SELECT id, order_fund_id, business_id, production_no FROM production_fund WHERE business_type = 'MAJOR_BUSINESS' AND deleted = 0 ) pf ON ( pf.id = fc.production_fund_id AND pf.order_fund_id = fc.order_fund_id )
  905. INNER JOIN (
  906. SELECT
  907. id,
  908. major_id,
  909. NAME,
  910. report_no,
  911. production,
  912. evaluate_amount,
  913. delivery_date,
  914. fund.real_amount,
  915. created
  916. FROM
  917. major_production mpr
  918. INNER JOIN ( SELECT production_no, real_amount, production_type FROM production_fund WHERE deleted = 0 AND business_type = 'MAJOR_BUSINESS' ) fund ON ( fund.production_no = mpr.report_no AND fund.production_type = mpr.production )
  919. WHERE
  920. fund.real_amount IS NOT NULL
  921. AND mpr.delivery_date IS NOT NULL
  922. ) mp ON mp.report_no = pf.production_no
  923. LEFT JOIN major m ON m.id = mp.major_id
  924. INNER JOIN ( SELECT id, business_id, production_id, commission_rate_id FROM commission_declare WHERE business_type = 'COMMISSION_DECLARE_MAJOR_MARKET' AND deleted = 0 AND declare_result = '审核通过' ) cd ON (
  925. cd.business_id = m.id
  926. AND cd.production_id = mp.id )
  927. LEFT JOIN business_commission_rate bcr ON bcr.id = cd.commission_rate_id
  928. LEFT JOIN dict_data dd ON dd.id = bcr.business_cate_id
  929. LEFT JOIN ( SELECT major_id, major_production_id, user_id, ratio,declare_id FROM major_production_allot WHERE deleted = 0 AND user_type = 'MARKET' ) mpa ON ( mpa.major_id = m.id AND cd.id = mpa.declare_id AND (mpa.major_production_id is null or mpa.major_production_id = mp.id ))
  930. LEFT JOIN user u on u.id = mpa.user_id
  931. WHERE
  932. m.financial is not null and
  933. mpa.user_id = #{vo.userId}
  934. order by settleDate DESC
  935. </select>
  936. <select id="majorMarketTotalAmountExport" parameterType="com.dayou.vo.UserCommissionTotalAmountVO" resultType="com.dayou.vo.UserCommissionTotalAmountVO">
  937. SELECT mpa.user_id as id, u.name as userName, ROUND(sum(( fc.claim_amount * ( bcr.min_ratio / 100 )* mpa.ratio )),2) AS commissionTotalAmount,
  938. '市场人员' as userType,
  939. '大中型业务' as businessType,
  940. #{vo.startDate} as startDate,
  941. #{vo.endDate} as endDate
  942. FROM
  943. (
  944. SELECT
  945. claim_amount,
  946. order_fund_id,
  947. production_fund_id,
  948. claim_datetime
  949. FROM
  950. finance_claim
  951. WHERE
  952. deleted = 0
  953. AND production_fund_id IS NOT NULL
  954. AND claim_datetime &gt;= #{vo.startDate}
  955. AND claim_datetime &lt;= #{vo.endDate}
  956. ) fc
  957. INNER JOIN ( SELECT id, order_fund_id, business_id, production_no FROM production_fund WHERE business_type = 'MAJOR_BUSINESS' AND deleted = 0 ) pf ON ( pf.id = fc.production_fund_id AND pf.order_fund_id = fc.order_fund_id )
  958. INNER JOIN (
  959. SELECT
  960. id,
  961. major_id,
  962. NAME,
  963. report_no,
  964. production,
  965. evaluate_amount,
  966. delivery_date,
  967. fund.real_amount
  968. FROM
  969. major_production mpr
  970. INNER JOIN ( SELECT production_no, real_amount, production_type FROM production_fund WHERE deleted = 0 AND business_type = 'MAJOR_BUSINESS' ) fund ON ( fund.production_no = mpr.report_no AND fund.production_type = mpr.production )
  971. WHERE
  972. fund.real_amount IS NOT NULL
  973. AND mpr.delivery_date IS NOT NULL
  974. ) mp ON mp.report_no = pf.production_no
  975. LEFT JOIN major m ON m.id = mp.major_id
  976. INNER JOIN ( SELECT id, business_id, production_id, commission_rate_id FROM commission_declare WHERE business_type = 'COMMISSION_DECLARE_MAJOR_MARKET' AND deleted = 0 AND declare_result = '审核通过' ) cd ON (
  977. cd.business_id = m.id
  978. AND cd.production_id = mp.id )
  979. LEFT JOIN business_commission_rate bcr ON bcr.id = cd.commission_rate_id
  980. LEFT JOIN dict_data dd ON dd.id = bcr.business_cate_id
  981. LEFT JOIN ( SELECT major_id, major_production_id,declare_id, user_id, ratio FROM major_production_allot WHERE deleted = 0 AND user_type = 'MARKET'
  982. ) mpa ON ( mpa.major_id = m.id AND cd.id = mpa.declare_id AND (mpa.major_production_id is null or mpa.major_production_id = mp.id ))
  983. LEFT JOIN user u ON u.id = mpa.user_id
  984. GROUP BY
  985. mpa.user_id
  986. order by commissionTotalAmount DESC
  987. </select>
  988. <select id="marketUserDetailExport" parameterType="com.dayou.vo.UserCommissionProdVO" resultType="com.dayou.vo.UserCommissionProdVO">
  989. SELECT
  990. mp.id,
  991. ROUND(fc.claim_amount,2) as realAmount,
  992. mp.report_no,
  993. IF
  994. ( fc.claim_datetime > mp.delivery_date, fc.claim_datetime, mp.delivery_date ) AS settleDate,
  995. mp.NAME,
  996. mp.created,
  997. dd.NAME AS businessCate,
  998. ROUND(bcr.min_ratio,2) AS ratio,
  999. mpa.user_id,
  1000. ROUND(mpa.ratio*100,2) AS allotRatio,
  1001. ROUND(( fc.claim_amount * ( bcr.min_ratio / 100 )* mpa.ratio ),2) AS commissionAmount,
  1002. ROUND(( fc.claim_amount * ( bcr.min_ratio / 100 ) ),2) AS totalAmount,
  1003. u.name as userName
  1004. FROM
  1005. (
  1006. SELECT
  1007. claim_amount,
  1008. order_fund_id,
  1009. production_fund_id,
  1010. claim_datetime
  1011. FROM
  1012. finance_claim
  1013. WHERE
  1014. deleted = 0
  1015. AND production_fund_id IS NOT NULL
  1016. AND claim_datetime &gt;= #{vo.startDate}
  1017. AND claim_datetime &lt;= #{vo.endDate}
  1018. ) fc
  1019. INNER JOIN ( SELECT id, order_fund_id, business_id, production_no FROM production_fund WHERE business_type = 'MAJOR_BUSINESS' AND deleted = 0 ) pf ON ( pf.id = fc.production_fund_id AND pf.order_fund_id = fc.order_fund_id )
  1020. INNER JOIN (
  1021. SELECT
  1022. id,
  1023. major_id,
  1024. NAME,
  1025. report_no,
  1026. production,
  1027. evaluate_amount,
  1028. delivery_date,
  1029. fund.real_amount,
  1030. created
  1031. FROM
  1032. major_production mpr
  1033. INNER JOIN ( SELECT production_no, real_amount, production_type FROM production_fund WHERE deleted = 0 AND business_type = 'MAJOR_BUSINESS' ) fund ON ( fund.production_no = mpr.report_no AND fund.production_type = mpr.production )
  1034. WHERE
  1035. fund.real_amount IS NOT NULL
  1036. AND mpr.delivery_date IS NOT NULL
  1037. ) mp ON mp.report_no = pf.production_no
  1038. LEFT JOIN major m ON m.id = mp.major_id
  1039. INNER JOIN ( SELECT id, business_id, production_id, commission_rate_id FROM commission_declare WHERE business_type = 'COMMISSION_DECLARE_MAJOR_MARKET' AND deleted = 0 AND declare_result = '审核通过' ) cd ON (
  1040. cd.business_id = m.id
  1041. AND cd.production_id = mp.id )
  1042. LEFT JOIN business_commission_rate bcr ON bcr.id = cd.commission_rate_id
  1043. LEFT JOIN dict_data dd ON dd.id = bcr.business_cate_id
  1044. LEFT JOIN ( SELECT major_id, major_production_id, user_id, ratio,declare_id FROM major_production_allot WHERE deleted = 0 AND user_type = 'MARKET' ) mpa ON ( mpa.major_id = m.id AND cd.id = mpa.declare_id AND (mpa.major_production_id is null or mpa.major_production_id = mp.id ))
  1045. LEFT JOIN user u on u.id = mpa.user_id
  1046. <where>
  1047. <if test="vo!=null and vo.userId!=null">
  1048. and mpa.user_id = #{vo.userId}
  1049. </if>
  1050. </where>
  1051. order by mpa.user_id
  1052. </select>
  1053. <sql id="personalOverdueSql">
  1054. SELECT
  1055. DATEDIFF(
  1056. CURDATE(),
  1057. DATE ( pp.rot )) AS overdueDay,
  1058. p.*,
  1059. pt.acreage,
  1060. pt.price,
  1061. pt.amount,
  1062. cc1.NAME AS clientName,
  1063. cc2.NAME AS clientSubName,
  1064. cl1.NAME AS contactName,
  1065. cl1.mobile AS contactTel,
  1066. u.NAME AS clientManager,
  1067. u1.NAME AS outwardStaffName,
  1068. u2.NAME AS inwardStaffName,
  1069. u3.NAME AS pricingStaffName,
  1070. pp.rot
  1071. FROM
  1072. (
  1073. SELECT
  1074. id,
  1075. location,
  1076. order_id,
  1077. agent,
  1078. bailorA,
  1079. bailorB,
  1080. clientele_id,
  1081. clientele_sub_id,
  1082. clientele_contact_id,
  1083. client_manager_id,
  1084. outward_staff,
  1085. inward_staff,
  1086. pricing_staff
  1087. FROM
  1088. personal
  1089. WHERE
  1090. deleted = 0
  1091. ) p
  1092. inner JOIN personal_target pt ON pt.personal_id = p.id
  1093. inner JOIN ( SELECT business_id, should_amount, real_amount FROM order_fund WHERE business_type = 'PERSONAL_BUSINESS' AND deleted = 0 AND real_amount IS NULL ) ofu ON ofu.business_id = p.id
  1094. inner JOIN ( SELECT target_id,( repertory_out_time ) rot FROM personal_production WHERE repertory_out_time IS NOT NULL GROUP BY target_id ) pp ON pp.target_id = pt.id
  1095. LEFT JOIN customer_company cc1 ON cc1.id = p.clientele_id
  1096. LEFT JOIN customer_company cc2 ON cc2.id = p.clientele_sub_id
  1097. LEFT JOIN customer_linkman cl1 ON cl1.id = p.clientele_contact_id
  1098. LEFT JOIN `user` u ON u.id = p.client_manager_id
  1099. LEFT JOIN `user` u1 ON u1.id = p.outward_staff
  1100. LEFT JOIN `user` u2 ON u2.id = p.inward_staff
  1101. LEFT JOIN `user` u3 ON u3.id = p.pricing_staff
  1102. <where>
  1103. pp.rot>'2024-01-01 00:00:00'
  1104. <if test="overdueVO!=null and overdueVO.overdueMin!=null">
  1105. AND DATEDIFF(CURDATE(),DATE ( pp.rot )) >= #{overdueVO.overdueMin}
  1106. </if>
  1107. <if test="overdueVO!=null and overdueVO.overdueMax!=null">
  1108. AND DATEDIFF(CURDATE(),DATE( pp.rot )) &lt;= #{overdueVO.overdueMax}
  1109. </if>
  1110. <if test="overdueVO!=null and overdueVO.orderId!=null and overdueVO.orderId!=''">
  1111. and p.order_id = #{overdueVO.orderId}
  1112. </if>
  1113. <if test="overdueVO!=null and overdueVO.userIds!=null and overdueVO.userIds.size!=0">
  1114. and p.client_manager_id in
  1115. <foreach collection="overdueVO.userIds" open="(" close=")" separator="," item="userId">
  1116. #{userId}
  1117. </foreach>
  1118. </if>
  1119. </where>
  1120. ORDER BY
  1121. overdueDay ASC
  1122. </sql>
  1123. <select id="overduePersonal" parameterType="com.dayou.vo.PersonalOverdueVO" resultType="com.dayou.vo.PersonalOverdueVO">
  1124. <include refid="personalOverdueSql" />
  1125. </select>
  1126. <select id="overduePersonalList" parameterType="com.dayou.vo.PersonalOverdueVO" resultType="com.dayou.vo.PersonalOverdueVO">
  1127. <include refid="personalOverdueSql" />
  1128. </select>
  1129. <!--资产评估人员提成计算-->
  1130. <select id="assetsEvaluatorCommission" resultType="com.dayou.vo.UserCommissionTotalAmountVO">
  1131. SELECT bpd.member_id as id,
  1132. u.name as userName,
  1133. SUM(IF(cd.defined_low_limit_amount &lt; fc.claim_amount,
  1134. fc.claim_amount * (cd.ratio / 100) * (bpd.performance_distribution / 100),
  1135. cd.defined_low_limit_amount * (cd.ratio / 100) * (bpd.performance_distribution / 100)
  1136. )) AS allCommissionTotalAmount,
  1137. SUM(IF(ap.save_file_date IS NOT NULL, (IF(cd.defined_low_limit_amount &lt; fc.claim_amount,
  1138. fc.claim_amount * (cd.ratio / 100) * (bpd.performance_distribution / 100),
  1139. cd.defined_low_limit_amount * (cd.ratio / 100) * (bpd.performance_distribution / 100)
  1140. )), 0)) AS commissionTotalAmount
  1141. FROM
  1142. (
  1143. SELECT
  1144. claim_amount,
  1145. order_fund_id,
  1146. production_fund_id,
  1147. claim_datetime
  1148. FROM
  1149. finance_claim
  1150. WHERE
  1151. deleted = 0
  1152. AND production_fund_id IS NOT NULL
  1153. AND claim_datetime &gt;= #{vo.startDate}
  1154. AND claim_datetime &lt;= #{vo.endDate}
  1155. UNION ALL
  1156. SELECT
  1157. allot_amount AS claim_amount,
  1158. order_fund_id,
  1159. production_fund_id,
  1160. created AS claim_datetime
  1161. FROM
  1162. order_fund_allot
  1163. WHERE
  1164. deleted = 0
  1165. AND created &gt;= #{vo.startDate}
  1166. AND created &lt;= #{vo.endDate}
  1167. ) fc
  1168. INNER JOIN ( SELECT id, order_fund_id, business_id, production_no FROM production_fund WHERE business_type =
  1169. 'ASSET_BUSINESS' AND deleted = 0 ) pf ON ( pf.id = fc.production_fund_id AND pf.order_fund_id = fc.order_fund_id
  1170. )
  1171. INNER JOIN ( SELECT id, business_id, assets_name, production_no, production_type, save_file_date, created FROM
  1172. assets_production
  1173. WHERE deleted = 0) ap ON ap.production_no = pf.production_no
  1174. LEFT JOIN assets a ON a.id = ap.business_id
  1175. INNER JOIN ( SELECT id, business_id, production_id, commission_rate_id, ratio, defined_low_limit_amount FROM
  1176. commission_declare WHERE
  1177. business_type = 'COMMISSION_DECLARE_ASSET_EVALUATE' AND deleted = 0 AND declare_result = '审核通过' ) cd ON (
  1178. cd.business_id = a.id
  1179. AND ( cd.production_id IS NULL OR cd.production_id = ap.id ))
  1180. LEFT JOIN business_commission_rate bcr ON bcr.id = cd.commission_rate_id
  1181. LEFT JOIN dict_data dd ON dd.id = bcr.business_cate_id
  1182. LEFT JOIN ( SELECT business_id, report_no, member_id, performance_distribution FROM
  1183. business_performance_distribution WHERE deleted = 0
  1184. AND user_type = '评估人员'
  1185. ) bpd ON ( bpd.business_id = a.id AND bpd.report_no = ap.production_no)
  1186. LEFT JOIN user u ON u.id = bpd.member_id
  1187. GROUP BY
  1188. bpd.member_id
  1189. having 1=1
  1190. <if test="vo!=null and vo.userName!=null and vo.userName!=''">
  1191. and u.name like concat ('%',#{vo.userName},'%')
  1192. </if>
  1193. order by commissionTotalAmount DESC
  1194. </select>
  1195. <!--资产评估人员提成计算详情-->
  1196. <select id="assetsEvaluatorCommissionDetail" resultType="com.dayou.vo.UserCommissionProdAssetsVO">
  1197. SELECT
  1198. ap.id,
  1199. fc.claim_amount as realAmount,
  1200. ap.production_no AS reportNo,
  1201. IF
  1202. ( fc.claim_datetime > ap.save_file_date, fc.claim_datetime, ap.save_file_date ) AS settleDate,
  1203. ap.assets_name AS name,
  1204. ap.created,
  1205. dd.name AS businessCate,
  1206. IFNULL(cd.ratio,bcr.min_ratio) AS ratio,
  1207. cd.defined_low_limit_amount AS lowLimitAmount,
  1208. bpd.member_id,
  1209. bpd.performance_distribution AS allotRatio,
  1210. IF(cd.defined_low_limit_amount &lt; fc.claim_amount,
  1211. fc.claim_amount * (cd.ratio / 100) * (bpd.performance_distribution / 100),
  1212. cd.defined_low_limit_amount * (cd.ratio / 100) * (bpd.performance_distribution / 100)
  1213. ) AS commissionAmount,
  1214. IF(cd.defined_low_limit_amount &lt; fc.claim_amount,
  1215. fc.claim_amount * (cd.ratio / 100),
  1216. cd.defined_low_limit_amount * (cd.ratio / 100)
  1217. ) AS totalAmount,
  1218. u.name AS userName,
  1219. pf.modified AS realFundDateTime
  1220. FROM
  1221. (
  1222. SELECT
  1223. claim_amount,
  1224. order_fund_id,
  1225. production_fund_id,
  1226. claim_datetime
  1227. FROM
  1228. finance_claim
  1229. WHERE
  1230. deleted = 0
  1231. AND production_fund_id IS NOT NULL
  1232. AND claim_datetime &gt;= #{vo.startDate}
  1233. AND claim_datetime &lt;= #{vo.endDate}
  1234. UNION ALL
  1235. SELECT
  1236. allot_amount AS claim_amount,
  1237. order_fund_id,
  1238. production_fund_id,
  1239. created AS claim_datetime
  1240. FROM
  1241. order_fund_allot
  1242. WHERE
  1243. deleted = 0
  1244. AND created &gt;= #{vo.startDate}
  1245. AND created &lt;= #{vo.endDate}
  1246. ) fc
  1247. INNER JOIN ( SELECT id, order_fund_id, business_id, production_no,modified FROM production_fund WHERE business_type = 'ASSET_BUSINESS' AND deleted = 0 ) pf ON ( pf.id = fc.production_fund_id AND pf.order_fund_id = fc.order_fund_id )
  1248. INNER JOIN ( SELECT id, business_id, assets_name, production_no, production_type, save_file_date, created FROM assets_production WHERE deleted = 0) ap ON ap.production_no = pf.production_no
  1249. LEFT JOIN assets a ON a.id = ap.business_id
  1250. INNER JOIN ( SELECT id, business_id, production_id, commission_rate_id, ratio,defined_low_limit_amount FROM commission_declare WHERE business_type = 'COMMISSION_DECLARE_ASSET_EVALUATE' AND deleted = 0 AND declare_result = '审核通过' ) cd ON (
  1251. cd.business_id = a.id
  1252. AND ( cd.production_id IS NULL OR cd.production_id = ap.id ))
  1253. LEFT JOIN business_commission_rate bcr ON bcr.id = cd.commission_rate_id
  1254. LEFT JOIN dict_data dd ON dd.id = bcr.business_cate_id
  1255. LEFT JOIN ( SELECT business_id, report_no, member_id, performance_distribution FROM business_performance_distribution WHERE deleted = 0 AND user_type = '评估人员' ) bpd ON ( bpd.business_id = a.id AND bpd.report_no = ap.production_no)
  1256. LEFT JOIN user u on u.id = bpd.member_id
  1257. WHERE
  1258. bpd.member_id = #{vo.userId}
  1259. order by settleDate DESC
  1260. </select>
  1261. <!--资产评估人员合计导出-->
  1262. <select id="assetsEvaluatorTotalAmountExport" resultType="com.dayou.vo.UserCommissionTotalAmountVO">
  1263. SELECT bpd.member_id as id,
  1264. u.name as userName,
  1265. ROUND(SUM(IF(cd.defined_low_limit_amount &lt; fc.claim_amount,
  1266. fc.claim_amount * (cd.ratio / 100) * (bpd.performance_distribution / 100),
  1267. cd.defined_low_limit_amount * (cd.ratio / 100) * (bpd.performance_distribution / 100)
  1268. )), 2) AS allCommissionTotalAmount,
  1269. ROUND(SUM(IF(ap.save_file_date IS NOT NULL, (IF(cd.defined_low_limit_amount &lt; fc.claim_amount,
  1270. fc.claim_amount * (cd.ratio / 100) * (bpd.performance_distribution / 100),
  1271. cd.defined_low_limit_amount * (cd.ratio / 100) * (bpd.performance_distribution / 100)
  1272. )), 0)), 2) AS commissionTotalAmount,
  1273. '评估人员' as userType,
  1274. '资产业务' as businessType,
  1275. #{vo.startDate} as startDate,
  1276. #{vo.endDate} as endDate
  1277. FROM (SELECT claim_amount,
  1278. order_fund_id,
  1279. production_fund_id,
  1280. claim_datetime
  1281. FROM finance_claim
  1282. WHERE deleted = 0
  1283. AND production_fund_id IS NOT NULL
  1284. AND claim_datetime &gt;= #{vo.startDate}
  1285. AND claim_datetime &lt;= #{vo.endDate}
  1286. UNION ALL
  1287. SELECT allot_amount AS claim_amount,
  1288. order_fund_id,
  1289. production_fund_id,
  1290. created AS claim_datetime
  1291. FROM order_fund_allot
  1292. WHERE deleted = 0
  1293. AND created &gt;= #{vo.startDate}
  1294. AND created &lt;= #{vo.endDate}) fc
  1295. INNER JOIN (SELECT id, order_fund_id, business_id, production_no
  1296. FROM production_fund
  1297. WHERE business_type = 'ASSET_BUSINESS'
  1298. AND deleted = 0) pf
  1299. ON (pf.id = fc.production_fund_id AND pf.order_fund_id = fc.order_fund_id)
  1300. INNER JOIN (SELECT id,
  1301. business_id,
  1302. assets_name,
  1303. production_no,
  1304. production_type,
  1305. save_file_date,
  1306. created
  1307. FROM assets_production
  1308. WHERE deleted = 0) ap ON ap.production_no = pf.production_no
  1309. LEFT JOIN assets a ON a.id = ap.business_id
  1310. INNER JOIN (SELECT id, business_id, production_id, commission_rate_id, defined_low_limit_amount, ratio
  1311. FROM commission_declare
  1312. WHERE business_type = 'COMMISSION_DECLARE_ASSET_EVALUATE'
  1313. AND deleted = 0
  1314. AND declare_result = '审核通过') cd ON (
  1315. cd.business_id = a.id
  1316. AND (cd.production_id IS NULL OR cd.production_id = ap.id))
  1317. LEFT JOIN business_commission_rate bcr ON bcr.id = cd.commission_rate_id
  1318. LEFT JOIN dict_data dd ON dd.id = bcr.business_cate_id
  1319. LEFT JOIN (SELECT business_id, report_no, member_id, performance_distribution
  1320. FROM business_performance_distribution
  1321. WHERE deleted = 0
  1322. AND user_type = '评估人员') bpd
  1323. ON (bpd.business_id = a.id AND bpd.report_no = ap.production_no)
  1324. LEFT JOIN user u ON u.id = bpd.member_id
  1325. GROUP BY bpd.member_id
  1326. </select>
  1327. <!--资产评估人员提成信息导出-->
  1328. <select id="assetsEvaluatorUserDetailExport" resultType="com.dayou.vo.UserCommissionProdAssetsVO">
  1329. SELECT
  1330. ap.id,
  1331. ROUND(fc.claim_amount,2) as realAmount,
  1332. ap.production_no AS reportNo,
  1333. IF
  1334. ( fc.claim_datetime > ap.save_file_date, fc.claim_datetime, ap.save_file_date ) AS settleDate,
  1335. ap.assets_name AS name,
  1336. ap.created,
  1337. dd.NAME AS businessCate,
  1338. IFNULL(cd.ratio,bcr.min_ratio) AS ratio,
  1339. cd.defined_low_limit_amount AS lowLimitAmount,
  1340. ROUND(bcr.min_ratio,2) AS ratio,
  1341. bpd.member_id AS userId,
  1342. ROUND(bpd.performance_distribution,2) AS allotRatio,
  1343. ROUND(IF(cd.defined_low_limit_amount &lt; fc.claim_amount,
  1344. fc.claim_amount * (cd.ratio / 100) * (bpd.performance_distribution / 100),
  1345. cd.defined_low_limit_amount * (cd.ratio / 100) * (bpd.performance_distribution / 100)
  1346. ),2) AS commissionAmount,
  1347. ROUND(IF(cd.defined_low_limit_amount &lt; fc.claim_amount,
  1348. fc.claim_amount * (cd.ratio / 100),
  1349. cd.defined_low_limit_amount * (cd.ratio / 100)
  1350. ),2) AS totalAmount,
  1351. u.name as userName,
  1352. pf.modified AS realFundDateTime
  1353. FROM
  1354. (
  1355. SELECT
  1356. claim_amount,
  1357. order_fund_id,
  1358. production_fund_id,
  1359. claim_datetime
  1360. FROM
  1361. finance_claim
  1362. WHERE
  1363. deleted = 0
  1364. AND production_fund_id IS NOT NULL
  1365. AND claim_datetime &gt;= #{vo.startDate}
  1366. AND claim_datetime &lt;= #{vo.endDate}
  1367. UNION ALL
  1368. SELECT
  1369. allot_amount AS claim_amount,
  1370. order_fund_id,
  1371. production_fund_id,
  1372. created AS claim_datetime
  1373. FROM
  1374. order_fund_allot
  1375. WHERE
  1376. deleted = 0
  1377. AND created &gt;= #{vo.startDate}
  1378. AND created &lt;= #{vo.endDate}
  1379. ) fc
  1380. INNER JOIN ( SELECT id, order_fund_id, business_id, production_no,modified FROM production_fund WHERE business_type = 'ASSET_BUSINESS' AND deleted = 0 ) pf ON ( pf.id = fc.production_fund_id AND pf.order_fund_id = fc.order_fund_id )
  1381. INNER JOIN ( SELECT id, business_id, assets_name, production_no, production_type, save_file_date, created FROM assets_production WHERE deleted = 0 ) ap ON ap.production_no = pf.production_no
  1382. LEFT JOIN assets a ON a.id = ap.business_id
  1383. INNER JOIN ( SELECT id, business_id, production_id, commission_rate_id, ratio, defined_low_limit_amount FROM commission_declare WHERE business_type = 'COMMISSION_DECLARE_ASSET_EVALUATE' AND deleted = 0 AND declare_result = '审核通过' ) cd ON (
  1384. cd.business_id = a.id
  1385. AND ( cd.production_id IS NULL OR cd.production_id = ap.id ))
  1386. LEFT JOIN business_commission_rate bcr ON bcr.id = cd.commission_rate_id
  1387. LEFT JOIN dict_data dd ON dd.id = bcr.business_cate_id
  1388. LEFT JOIN ( SELECT business_id, report_no, member_id, performance_distribution FROM business_performance_distribution WHERE deleted = 0 AND user_type = '评估人员' ) bpd ON ( bpd.business_id = a.id AND bpd.report_no = ap.production_no)
  1389. LEFT JOIN user u on u.id = bpd.member_id
  1390. <where>
  1391. <if test="vo!=null and vo.userId!=null">
  1392. and bpd.member_id = #{vo.userId}
  1393. </if>
  1394. </where>
  1395. order by bpd.member_id
  1396. </select>
  1397. <!--资产市场人员提成计算-->
  1398. <select id="assetsMarketCommission" resultType="com.dayou.vo.UserCommissionTotalAmountVO">
  1399. SELECT bpd.member_id as id,
  1400. u.name as userName,
  1401. SUM(( fc.claim_amount * ( bcr.min_ratio / 100 ) * (bpd.performance_distribution / 100))) AS commissionTotalAmount
  1402. FROM
  1403. (
  1404. SELECT
  1405. claim_amount,
  1406. order_fund_id,
  1407. production_fund_id,
  1408. claim_datetime
  1409. FROM
  1410. finance_claim
  1411. WHERE
  1412. deleted = 0
  1413. AND production_fund_id IS NOT NULL
  1414. AND claim_datetime &gt;= #{vo.startDate}
  1415. AND claim_datetime &lt;= #{vo.endDate}
  1416. UNION ALL SELECT allot_amount AS claim_amount, order_fund_id, production_fund_id, created AS claim_datetime FROM order_fund_allot WHERE deleted = 0
  1417. AND created &gt;= #{vo.startDate}
  1418. AND created &lt;= #{vo.endDate}
  1419. ) fc
  1420. INNER JOIN ( SELECT id, order_fund_id, business_id, production_no FROM production_fund WHERE business_type = 'ASSET_BUSINESS' AND deleted = 0 ) pf ON ( pf.id = fc.production_fund_id AND pf.order_fund_id = fc.order_fund_id )
  1421. INNER JOIN ( SELECT id, business_id, assets_name, production_no, production_type, save_file_date, created FROM assets_production WHERE deleted = 0 AND delivery = TRUE ) ap ON ap.production_no = pf.production_no
  1422. LEFT JOIN assets a ON a.id = ap.business_id
  1423. INNER JOIN ( SELECT id, business_id, production_id, commission_rate_id FROM commission_declare WHERE business_type = 'COMMISSION_DECLARE_ASSET_MARKET' AND deleted = 0 AND declare_result = '审核通过' ) cd ON (
  1424. cd.business_id = a.id
  1425. AND ( cd.production_id IS NULL OR cd.production_id = ap.id ))
  1426. LEFT JOIN business_commission_rate bcr ON bcr.id = cd.commission_rate_id
  1427. LEFT JOIN dict_data dd ON dd.id = bcr.business_cate_id
  1428. LEFT JOIN ( SELECT business_id, report_no,declare_id, member_id, performance_distribution FROM business_performance_distribution WHERE deleted = 0 AND user_type = '市场人员'
  1429. ) bpd ON ( bpd.business_id = a.id AND cd.id = bpd.declare_id AND (bpd.report_no is null or bpd.report_no = ap.production_no ))
  1430. LEFT JOIN user u ON u.id = bpd.member_id
  1431. GROUP BY
  1432. bpd.member_id
  1433. having 1=1
  1434. <if test="vo!=null and vo.userName!=null and vo.userName!=''">
  1435. and u.name like concat ('%',#{vo.userName},'%')
  1436. </if>
  1437. order by commissionTotalAmount DESC
  1438. </select>
  1439. <!--资产市场人员提成计算详情-->
  1440. <select id="assetsMarketCommissionDetail" resultType="com.dayou.vo.UserCommissionProdVO">
  1441. SELECT
  1442. ap.id,
  1443. fc.claim_amount as realAmount,
  1444. ap.production_no AS reportNo,
  1445. IF
  1446. ( fc.claim_datetime > ap.save_file_date, fc.claim_datetime, ap.save_file_date ) AS settleDate,
  1447. ap.assets_name AS name,
  1448. ap.created,
  1449. dd.NAME AS businessCate,
  1450. bcr.min_ratio AS ratio,
  1451. bpd.member_id AS userId,
  1452. bpd.performance_distribution AS allotRatio,
  1453. ( fc.claim_amount * ( bcr.min_ratio / 100 ) * (bpd.performance_distribution / 100) ) AS commissionAmount,
  1454. ( fc.claim_amount * ( bcr.min_ratio / 100 ) ) AS totalAmount,
  1455. u.name as userName
  1456. FROM
  1457. (
  1458. SELECT
  1459. claim_amount,
  1460. order_fund_id,
  1461. production_fund_id,
  1462. claim_datetime
  1463. FROM
  1464. finance_claim
  1465. WHERE
  1466. deleted = 0
  1467. AND production_fund_id IS NOT NULL
  1468. AND claim_datetime &gt;= #{vo.startDate}
  1469. AND claim_datetime &lt;= #{vo.endDate}
  1470. UNION ALL
  1471. SELECT
  1472. allot_amount AS claim_amount,
  1473. order_fund_id,
  1474. production_fund_id,
  1475. created AS claim_datetime
  1476. FROM
  1477. order_fund_allot
  1478. WHERE
  1479. deleted = 0
  1480. AND created &gt;= #{vo.startDate}
  1481. AND created &lt;= #{vo.endDate}
  1482. ) fc
  1483. INNER JOIN ( SELECT id, order_fund_id, business_id, production_no FROM production_fund WHERE business_type = 'ASSET_BUSINESS' AND deleted = 0 ) pf ON ( pf.id = fc.production_fund_id AND pf.order_fund_id = fc.order_fund_id )
  1484. INNER JOIN ( SELECT id, business_id, assets_name, production_no, production_type, save_file_date, created FROM assets_production WHERE deleted = 0 AND delivery = TRUE ) ap ON ap.production_no = pf.production_no
  1485. LEFT JOIN assets a ON a.id = ap.business_id
  1486. INNER JOIN ( SELECT id, business_id, production_id, commission_rate_id FROM commission_declare WHERE business_type = 'COMMISSION_DECLARE_ASSET_MARKET' AND deleted = 0 AND declare_result = '审核通过' ) cd ON (
  1487. cd.business_id = a.id
  1488. AND ( cd.production_id IS NULL OR cd.production_id = ap.id ))
  1489. LEFT JOIN business_commission_rate bcr ON bcr.id = cd.commission_rate_id
  1490. LEFT JOIN dict_data dd ON dd.id = bcr.business_cate_id
  1491. LEFT JOIN ( SELECT business_id, report_no, member_id, performance_distribution,declare_id FROM business_performance_distribution WHERE deleted = 0 AND user_type = '市场人员' ) bpd
  1492. ON ( bpd.business_id = a.id AND cd.id = bpd.declare_id AND (bpd.report_no is null or bpd.report_no = ap.production_no ))
  1493. LEFT JOIN user u on u.id = bpd.member_id
  1494. WHERE
  1495. bpd.member_id = #{vo.userId}
  1496. order by settleDate DESC
  1497. </select>
  1498. <!--资产市场人员提成合计导出-->
  1499. <select id="assetsMarketTotalAmountExport" resultType="com.dayou.vo.UserCommissionTotalAmountVO">
  1500. SELECT bpd.member_id as id,
  1501. u.name as userName,
  1502. ROUND(SUM((fc.claim_amount * (bcr.min_ratio / 100) * (bpd.performance_distribution / 100))),
  1503. 2) AS commissionTotalAmount,
  1504. '市场人员' as userType,
  1505. '资产业务' as businessType,
  1506. #{vo.startDate} as startDate,
  1507. #{vo.endDate} as endDate
  1508. FROM (SELECT claim_amount,
  1509. order_fund_id,
  1510. production_fund_id,
  1511. claim_datetime
  1512. FROM finance_claim
  1513. WHERE deleted = 0
  1514. AND production_fund_id IS NOT NULL
  1515. AND claim_datetime &gt;= #{vo.startDate}
  1516. AND claim_datetime &lt;= #{vo.endDate}
  1517. UNION ALL
  1518. SELECT allot_amount AS claim_amount, order_fund_id, production_fund_id, created AS claim_datetime
  1519. FROM order_fund_allot
  1520. WHERE deleted = 0
  1521. AND created &gt;= #{vo.startDate}
  1522. AND created &lt;= #{vo.endDate}) fc
  1523. INNER JOIN (SELECT id, order_fund_id, business_id, production_no
  1524. FROM production_fund
  1525. WHERE business_type = 'ASSET_BUSINESS'
  1526. AND deleted = 0) pf
  1527. ON (pf.id = fc.production_fund_id AND pf.order_fund_id = fc.order_fund_id)
  1528. INNER JOIN (SELECT id,
  1529. business_id,
  1530. assets_name,
  1531. production_no,
  1532. production_type,
  1533. save_file_date,
  1534. created
  1535. FROM assets_production
  1536. WHERE deleted = 0
  1537. AND delivery = true) ap ON ap.production_no = pf.production_no
  1538. LEFT JOIN assets a ON a.id = ap.business_id
  1539. INNER JOIN (SELECT id, business_id, production_id, commission_rate_id
  1540. FROM commission_declare
  1541. WHERE business_type = 'COMMISSION_DECLARE_ASSET_MARKET'
  1542. AND deleted = 0
  1543. AND declare_result = '审核通过') cd ON (
  1544. cd.business_id = a.id
  1545. AND (cd.production_id IS NULL OR cd.production_id = ap.id))
  1546. LEFT JOIN business_commission_rate bcr ON bcr.id = cd.commission_rate_id
  1547. LEFT JOIN dict_data dd ON dd.id = bcr.business_cate_id
  1548. LEFT JOIN (SELECT business_id, report_no, declare_id, member_id, performance_distribution
  1549. FROM business_performance_distribution
  1550. WHERE deleted = 0
  1551. AND user_type = '市场人员') bpd ON (bpd.business_id = a.id AND cd.id = bpd.declare_id AND
  1552. (bpd.report_no is null or bpd.report_no = ap.production_no))
  1553. LEFT JOIN user u ON u.id = bpd.member_id
  1554. GROUP BY bpd.member_id
  1555. ORDER BY commissionTotalAmount DESC
  1556. </select>
  1557. <!--资产市场人员提成信息导出-->
  1558. <select id="assetsMarketUserDetailExport" resultType="com.dayou.vo.UserCommissionProdVO">
  1559. SELECT
  1560. ap.id,
  1561. ROUND(fc.claim_amount,2) as realAmount,
  1562. ap.production_no AS reportNo,
  1563. IF
  1564. ( fc.claim_datetime > ap.save_file_date, fc.claim_datetime, ap.save_file_date ) AS settleDate,
  1565. ap.assets_name AS name,
  1566. ap.created,
  1567. dd.`name` AS businessCate,
  1568. ROUND(bcr.min_ratio,2) AS ratio,
  1569. bpd.member_id AS userId,
  1570. ROUND(bpd.performance_distribution,2) AS allotRatio,
  1571. ROUND(( fc.claim_amount * ( bcr.min_ratio / 100 ) * (bpd.performance_distribution / 100) ),2) AS
  1572. commissionAmount,
  1573. ROUND(( fc.claim_amount * ( bcr.min_ratio / 100 ) ),2) AS totalAmount,
  1574. u.name as userName
  1575. FROM
  1576. (
  1577. SELECT
  1578. claim_amount,
  1579. order_fund_id,
  1580. production_fund_id,
  1581. claim_datetime
  1582. FROM
  1583. finance_claim
  1584. WHERE
  1585. deleted = 0
  1586. AND production_fund_id IS NOT NULL
  1587. AND claim_datetime &gt;= #{vo.startDate}
  1588. AND claim_datetime &lt;= #{vo.endDate}
  1589. UNION ALL
  1590. SELECT
  1591. allot_amount AS claim_amount,
  1592. order_fund_id,
  1593. production_fund_id,
  1594. created AS claim_datetime
  1595. FROM
  1596. order_fund_allot
  1597. WHERE
  1598. deleted = 0
  1599. AND created &gt;= #{vo.startDate}
  1600. AND created &lt;= #{vo.endDate}
  1601. ) fc
  1602. INNER JOIN ( SELECT id, order_fund_id, business_id, production_no FROM production_fund WHERE business_type =
  1603. 'ASSET_BUSINESS' AND deleted = 0 ) pf ON ( pf.id = fc.production_fund_id AND pf.order_fund_id = fc.order_fund_id
  1604. )
  1605. INNER JOIN ( SELECT id, business_id, assets_name, production_no, production_type, save_file_date, created FROM
  1606. assets_production WHERE deleted = 0 AND delivery = true ) ap ON ap.production_no = pf.production_no
  1607. LEFT JOIN assets a ON a.id = ap.business_id
  1608. INNER JOIN ( SELECT id, business_id, production_id, commission_rate_id FROM commission_declare WHERE
  1609. business_type = 'COMMISSION_DECLARE_ASSET_MARKET' AND deleted = 0 AND declare_result = '审核通过' ) cd ON (
  1610. cd.business_id = a.id
  1611. AND ( cd.production_id IS NULL OR cd.production_id = ap.id ))
  1612. LEFT JOIN business_commission_rate bcr ON bcr.id = cd.commission_rate_id
  1613. LEFT JOIN dict_data dd ON dd.id = bcr.business_cate_id
  1614. LEFT JOIN ( SELECT business_id, report_no, member_id, performance_distribution, declare_id FROM
  1615. business_performance_distribution WHERE deleted = 0 AND user_type = '市场人员' ) bpd
  1616. ON ( bpd.business_id = a.id AND cd.id = bpd.declare_id AND (bpd.report_no is null or bpd.report_no =
  1617. ap.production_no ))
  1618. LEFT JOIN user u on u.id = bpd.member_id
  1619. <where>
  1620. <if test="vo!=null and vo.userId!=null">
  1621. and bpd.member_id = #{vo.userId}
  1622. </if>
  1623. </where>
  1624. order by bpd.member_id
  1625. </select>
  1626. <!--资产收款逾期查询Sql-->
  1627. <sql id="assetsOverdueSql">
  1628. SELECT
  1629. DATEDIFF(CURDATE(), DATE( ap.repertory_out_time )) AS overdueDay,
  1630. a.allot_type,
  1631. a.order_id,
  1632. a.assets_business_gener,
  1633. u.name AS clientManager,
  1634. u1.name AS principal,
  1635. cc1.name AS clientName,
  1636. cc2.name AS clientSubName,
  1637. pf.production_should_amount,
  1638. `of`.should_amount,
  1639. pf.standard_amount,
  1640. a.name as projectName,
  1641. ap.*
  1642. FROM
  1643. (
  1644. SELECT
  1645. id,
  1646. business_id,
  1647. production_no,
  1648. ( CASE production_type WHEN 'STATEMENT' THEN '意见书' WHEN 'REPORT' THEN '评估报告' WHEN 'LETTER' THEN '意见函' WHEN 'CONSULT' THEN '咨询报告' ELSE '' END ) productionType,
  1649. evaluate_amount,
  1650. repertory_out_time
  1651. FROM
  1652. assets_production ap
  1653. WHERE
  1654. deleted = 0
  1655. AND repertory_out_time IS NOT NULL
  1656. AND production_type != 'STATEMENT'
  1657. ) ap
  1658. LEFT JOIN ( SELECT business_id, production_no, production_should_amount, real_amount, standard_amount FROM production_fund WHERE business_type = 'ASSET_BUSINESS' AND deleted = 0 ) pf
  1659. ON ( ap.business_id = pf.business_id AND ap.production_no = pf.production_no )
  1660. LEFT JOIN ( SELECT business_id,should_amount FROM order_fund WHERE business_type = 'ASSET_BUSINESS' AND deleted = 0 ) `of` ON `of`.business_id = ap.business_id
  1661. LEFT JOIN assets a ON a.id = ap.business_id
  1662. LEFT JOIN user u ON u.id = a.client_manager_id
  1663. LEFT JOIN user u1 ON u1.id = a.principal_id
  1664. LEFT JOIN customer_company cc1 ON cc1.id = a.clientele_id
  1665. LEFT JOIN customer_company cc2 ON cc2.id = a.clientele_sub_id
  1666. WHERE
  1667. ap.productionType != 'STATEMENT'
  1668. AND ( pf.production_no IS NULL OR pf.real_amount IS NULL )
  1669. and ap.repertory_out_time>'2024-01-01 00:00:00'
  1670. <if test="overdueVO!=null and overdueVO.overdueMin!=null">
  1671. AND DATEDIFF(CURDATE(),DATE( ap.repertory_out_time )) &gt;= #{overdueVO.overdueMin}
  1672. </if>
  1673. <if test="overdueVO!=null and overdueVO.overdueMax!=null">
  1674. AND DATEDIFF(CURDATE(),DATE( ap.repertory_out_time )) &lt;= #{overdueVO.overdueMax}
  1675. </if>
  1676. <if test="overdueVO!=null and overdueVO.orderId!=null and overdueVO.orderId!=''">
  1677. and a.order_id = #{overdueVO.orderId}
  1678. </if>
  1679. <if test="overdueVO!=null and overdueVO.productionNo!=null and overdueVO.productionNo!=''">
  1680. and ap.production_no like concat ('%',#{overdueVO.productionNo},'%')
  1681. </if>
  1682. <if test="overdueVO!=null and overdueVO.principal!=null and overdueVO.principal!=''">
  1683. and u1.name like concat ('%',#{overdueVO.principal},'%')
  1684. </if>
  1685. <if test="overdueVO!=null and overdueVO.userIds!=null and overdueVO.userIds.size!=0">
  1686. and a.client_manager_id in
  1687. <foreach collection="overdueVO.userIds" open="(" close=")" separator="," item="userId">
  1688. #{userId}
  1689. </foreach>
  1690. </if>
  1691. order by overdueDay asc
  1692. </sql>
  1693. <!--资产收款逾期列表-->
  1694. <select id="overdueAssets" resultType="com.dayou.vo.AssetsProdOverdueVO">
  1695. <include refid="assetsOverdueSql" />
  1696. </select>
  1697. <!--资产收款逾期列表导出-->
  1698. <select id="overdueAssetsExport" resultType="com.dayou.vo.AssetsProdOverdueVO">
  1699. <include refid="assetsOverdueSql" />
  1700. </select>
  1701. <resultMap id="settleAssetsProductionVOMap" type="com.dayou.vo.SettleAssetsProductionVO">
  1702. <id property="id" column="id" />
  1703. <result property="id" column="id" />
  1704. <result property="claimAmount" column="claim_amount" />
  1705. <result property="orderId" column="order_id" />
  1706. <result property="projectName" column="name" />
  1707. <result property="productionNo" column="production_no" />
  1708. <result property="claimDate" column="claimDate" />
  1709. <result property="saveFileDate" column="save_file_date" />
  1710. <result property="settleDate" column="settleDate" />
  1711. <result property="deliveryDate" column="deliveryDate" />
  1712. <result property="projectName" column="projectName" />
  1713. <result property="bailor" column="bailor" />
  1714. <result property="evaluateAmount" column="evaluate_amount" />
  1715. <result property="principal" column="principal" />
  1716. <result property="clientManager" column="clientManager" />
  1717. <result property="clientName" column="clientName" />
  1718. <result property="clientSubName" column="clientSubName" />
  1719. <result property="evaluateDepartmentName" column="evaluateDepartmentName" />
  1720. <result property="marketDepartmentName" column="marketDepartmentName" />
  1721. <result property="payDateTime" column="pay_datetime" />
  1722. <result property="members" column="members" />
  1723. <collection property="invoices" ofType="com.dayou.vo.SettleProInvoiceVo">
  1724. <result property="invoiceDate" column="invoiceDate" />
  1725. <result property="invoiceUser" column="invoiceUser" />
  1726. <result property="invoiceNo" column="invoiceNo" />
  1727. </collection>
  1728. </resultMap>
  1729. <!--资产市场人员结算项目Sql-->
  1730. <sql id="assetsMarketerSettleSql">
  1731. SELECT
  1732. fc.id,
  1733. fc.claim_amount,
  1734. a.order_id,
  1735. ap.production_no,
  1736. fc.claim_datetime AS claimDate,
  1737. ap.delivery_date AS deliveryDate,
  1738. ap.save_file_date,
  1739. IF
  1740. ( fc.claim_datetime > ap.delivery_date, fc.claim_datetime, ap.delivery_date ) AS settleDate,
  1741. ap.assets_name AS projectName,
  1742. a.bailor,
  1743. a.name,
  1744. a.members,
  1745. ap.evaluate_amount,
  1746. u.NAME AS principal,
  1747. u1.NAME AS clientManager,
  1748. cc.NAME AS clientName,
  1749. cc1.NAME AS clientSubName,
  1750. d.NAME AS evaluateDepartmentName,
  1751. (
  1752. SELECT
  1753. GROUP_CONCAT( department.NAME )
  1754. FROM
  1755. department
  1756. WHERE
  1757. id IN (
  1758. SELECT
  1759. department_id
  1760. FROM
  1761. post
  1762. WHERE
  1763. id IN ( SELECT post_id FROM user_post WHERE user_id = a.client_manager_id ))) AS marketDepartmentName,
  1764. invoice.NAME AS invoiceUser,
  1765. invoice.real_make_date AS invoiceDate,
  1766. invoice.tax_no AS invoiceNo,
  1767. frf.pay_datetime
  1768. FROM
  1769. (
  1770. SELECT
  1771. id,
  1772. claim_amount,
  1773. order_fund_id,
  1774. production_fund_id,
  1775. claim_datetime,
  1776. real_fund_id
  1777. FROM
  1778. finance_claim
  1779. WHERE
  1780. deleted = 0
  1781. AND production_fund_id IS NOT NULL
  1782. ) fc
  1783. inner join (
  1784. select id,pay_datetime from finance_real_fund
  1785. where deleted = 0
  1786. <if test="settleVO!=null and settleVO.payStartDate!=null and settleVO.payStartDate!='' ">
  1787. AND pay_datetime &gt;= #{settleVO.payStartDate}
  1788. </if>
  1789. <if test="settleVO!=null and settleVO.payEndDate!=null and settleVO.payEndDate!='' ">
  1790. AND pay_datetime &lt;= #{settleVO.payEndDate}
  1791. </if>
  1792. ) frf on frf.id = fc.real_fund_id
  1793. INNER JOIN ( SELECT id, order_fund_id, business_id, production_no FROM production_fund WHERE business_type =
  1794. 'ASSET_BUSINESS' AND deleted = 0 ) pf ON ( pf.id = fc.production_fund_id AND pf.order_fund_id = fc.order_fund_id
  1795. )
  1796. INNER JOIN ( SELECT id, business_id, assets_name, production_no, production_type, evaluate_amount,
  1797. delivery_date, save_file_date FROM assets_production WHERE deleted = 0 AND delivery = true ) ap ON ap.production_no =
  1798. pf.production_no
  1799. LEFT JOIN assets a ON a.id = ap.business_id
  1800. LEFT JOIN user u ON u.id = a.principal_id
  1801. LEFT JOIN user u1 ON u1.id = a.client_manager_id
  1802. LEFT JOIN customer_company cc ON cc.id = a.clientele_id
  1803. LEFT JOIN customer_company cc1 ON cc1.id = a.clientele_sub_id
  1804. LEFT JOIN department d ON d.id = a.department_id
  1805. LEFT JOIN (
  1806. SELECT real_make_date, name, tax_no, order_fund_id, production_fund_id
  1807. FROM finance_invoice, user
  1808. WHERE maker_id = user.id
  1809. AND finance_invoice.deleted = 0
  1810. AND state = '已开票' order by user.created desc limit 1
  1811. ) AS invoice ON IF(invoice.production_fund_id IS NOT NULL ,invoice.order_fund_id = pf.order_fund_id AND invoice.production_fund_id = pf.id,invoice.order_fund_id = pf.order_fund_id)
  1812. <where>
  1813. IF( fc.claim_datetime > ap.delivery_date, fc.claim_datetime, ap.delivery_date ) &gt;= #{settleVO.startDate}
  1814. AND IF( fc.claim_datetime > ap.delivery_date, fc.claim_datetime, ap.delivery_date ) &lt;= #{settleVO.endDate}
  1815. <if test="keyword!=null and keyword!='' ">
  1816. and (
  1817. a.order_id = #{keyword}
  1818. or ap.production_no like concat ('%',#{keyword},'%')
  1819. or u.name like concat ('%',#{keyword},'%')
  1820. or u1.name like concat ('%',#{keyword},'%')
  1821. )
  1822. </if>
  1823. </where>
  1824. order by fc.claim_datetime ASC
  1825. </sql>
  1826. <!--资产结算项目查询-->
  1827. <select id="assetsMarketSettleProd" resultMap="settleAssetsProductionVOMap">
  1828. <include refid="assetsMarketerSettleSql" />
  1829. </select>
  1830. <!--资产结算项目导出-->
  1831. <select id="assetsMarketSettleExport" resultMap="settleAssetsProductionVOMap">
  1832. <include refid="assetsMarketerSettleSql" />
  1833. </select>
  1834. <!--资产评估人员结算项目Sql-->
  1835. <sql id="assetsEvaluatorSettleSql">
  1836. SELECT
  1837. fc.id,
  1838. fc.claim_amount,
  1839. a.order_id,
  1840. ap.production_no,
  1841. fc.claim_datetime as claimDate,
  1842. ap.save_file_date,
  1843. IF( fc.claim_datetime > ap.save_file_date, fc.claim_datetime, ap.save_file_date ) AS settleDate,
  1844. IF(ap.assets_name IS NOT NULL, ap.assets_name, a.name ) AS projectName,
  1845. a.bailor,
  1846. a.members,
  1847. ap.evaluate_amount,
  1848. u.name AS principal,
  1849. u1.name AS clientManager,
  1850. cc.name AS clientName,
  1851. cc1.name AS clientSubName,
  1852. d.name AS evaluateDepartmentName,
  1853. (
  1854. SELECT
  1855. GROUP_CONCAT( NAME )
  1856. FROM
  1857. department
  1858. WHERE
  1859. id IN (
  1860. SELECT
  1861. department_id
  1862. FROM
  1863. post
  1864. WHERE
  1865. id IN ( SELECT post_id FROM user_post WHERE user_id = a.client_manager_id ))) AS marketDepartmentName,
  1866. invoice.name AS invoiceUser,
  1867. invoice.real_make_date AS invoiceDate,
  1868. invoice.tax_no AS invoiceNo,
  1869. frf.pay_datetime
  1870. FROM
  1871. (
  1872. SELECT
  1873. id,
  1874. claim_amount,
  1875. order_fund_id,
  1876. production_fund_id,
  1877. claim_datetime,
  1878. real_fund_id
  1879. FROM
  1880. finance_claim
  1881. WHERE
  1882. deleted = 0
  1883. AND production_fund_id IS NOT NULL
  1884. ) fc
  1885. inner join (
  1886. select id,pay_datetime from finance_real_fund
  1887. where deleted = 0
  1888. <if test="settleVO!=null and settleVO.payStartDate!=null and settleVO.payStartDate!='' ">
  1889. AND pay_datetime &gt;= #{settleVO.payStartDate}
  1890. </if>
  1891. <if test="settleVO!=null and settleVO.payEndDate!=null and settleVO.payEndDate!='' ">
  1892. AND pay_datetime &lt;= #{settleVO.payEndDate}
  1893. </if>
  1894. ) frf on frf.id = fc.real_fund_id
  1895. INNER JOIN ( SELECT id, order_fund_id, business_id, production_no FROM production_fund WHERE business_type = 'ASSET_BUSINESS' AND deleted = 0 ) pf ON ( pf.id = fc.production_fund_id AND pf.order_fund_id = fc.order_fund_id )
  1896. INNER JOIN ( SELECT id, business_id, assets_name, production_no, production_type, evaluate_amount, save_file_date FROM assets_production WHERE deleted = 0 AND save_file_date IS NOT NULL ) ap ON ap.production_no = pf.production_no
  1897. LEFT JOIN assets a ON a.id = ap.business_id
  1898. LEFT JOIN user u ON u.id = a.principal_id
  1899. LEFT JOIN user u1 ON u1.id = a.client_manager_id
  1900. LEFT JOIN customer_company cc ON cc.id = a.clientele_id
  1901. LEFT JOIN customer_company cc1 ON cc1.id = a.clientele_sub_id
  1902. LEFT JOIN department d ON d.id = a.department_id
  1903. LEFT JOIN (
  1904. SELECT real_make_date, name, tax_no, order_fund_id, production_fund_id
  1905. FROM finance_invoice, user
  1906. WHERE maker_id = user.id
  1907. AND finance_invoice.deleted = 0
  1908. AND state = '已开票' order by user.created desc limit 1
  1909. ) AS invoice ON IF(invoice.production_fund_id IS NOT NULL ,invoice.order_fund_id = pf.order_fund_id AND invoice.production_fund_id = pf.id,invoice.order_fund_id = pf.order_fund_id)
  1910. <where>
  1911. AND IF( fc.claim_datetime > ap.save_file_date, fc.claim_datetime, ap.save_file_date ) &gt;= #{settleVO.startDate}
  1912. AND IF( fc.claim_datetime > ap.save_file_date, fc.claim_datetime, ap.save_file_date ) &lt;= #{settleVO.endDate}
  1913. <if test="keyword!=null and keyword!='' ">
  1914. and (
  1915. a.order_id = #{keyword}
  1916. or ap.production_no like concat ('%',#{keyword},'%')
  1917. or u.name like concat ('%',#{keyword},'%')
  1918. or u1.name like concat ('%',#{keyword},'%')
  1919. )
  1920. </if>
  1921. </where>
  1922. order by fc.claim_datetime ASC
  1923. </sql>
  1924. <!--资产评估人员结算项目查询-->
  1925. <select id="assetsEvaluatorSettleProd" resultMap="settleAssetsProductionVOMap">
  1926. <include refid="assetsEvaluatorSettleSql" />
  1927. </select>
  1928. <!--资产评估人员结算项目导出-->
  1929. <select id="assetsEvaluatorSettleExport" resultMap="settleAssetsProductionVOMap">
  1930. <include refid="assetsEvaluatorSettleSql" />
  1931. </select>
  1932. <select id="exportList" parameterType="com.dayou.entity.FinanceRealFund" resultType="com.dayou.dto.FinanceRealFundExportDTO">
  1933. <include refid="pageListSql" />
  1934. ORDER BY frf.pay_datetime DESC
  1935. </select>
  1936. <sql id="realAmountClaimedSQL">
  1937. SELECT
  1938. claimd.id,
  1939. fr.amount,
  1940. fr.payer,
  1941. fr.pay_datetime,
  1942. fr.remark,
  1943. claimd.claimAmount,
  1944. claimd.claimDate,
  1945. u.NAME AS creator,
  1946. u1.NAME AS claimUser,
  1947. (fr.amount-claimd.claimAmount) as notClaimAmount
  1948. FROM
  1949. (
  1950. SELECT
  1951. frf.id,
  1952. sum( fc.claim_amount ) claimAmount,
  1953. max( fc.claim_datetime ) claimDate,
  1954. fc.claim_user_id
  1955. FROM
  1956. finance_claim fc
  1957. LEFT JOIN finance_real_fund frf ON frf.id = fc.real_fund_id
  1958. WHERE
  1959. frf.deleted = 0
  1960. AND fc.deleted = 0
  1961. GROUP BY
  1962. frf.id
  1963. ) claimd
  1964. LEFT JOIN finance_real_fund fr ON fr.id = claimd.id
  1965. LEFT JOIN user u ON u.id = fr.creator_id
  1966. LEFT JOIN user u1 ON u1.id = claimd.claim_user_id
  1967. <where>
  1968. <if test="keyword!=null and keyword!='' ">
  1969. and (
  1970. fr.payer like concat ('%',#{keyword},'%')
  1971. or u1.name like concat('%',#{keyword},'%')
  1972. or claimd.claimAmount = #{keyword}
  1973. or fr.amount = #{keyword}
  1974. or fr.remark like concat('%',#{keyword},'%')
  1975. )
  1976. </if>
  1977. <if test="vo!=null and vo.startDate!=null and vo.startDate!=''">
  1978. and fr.pay_datetime &gt;= #{vo.startDate}
  1979. </if>
  1980. <if test="vo!=null and vo.endDate!=null and vo.endDate!=''">
  1981. and fr.pay_datetime &lt;= #{vo.endDate}
  1982. </if>
  1983. <if test="vo!=null and vo.xStartDate!=null and vo.xStartDate!=''">
  1984. and claimd.claimDate &gt;= #{vo.xStartDate}
  1985. </if>
  1986. <if test="vo!=null and vo.xEndDate!=null and vo.xEndDate!=''">
  1987. and claimd.claimDate &lt;= #{vo.xEndDate}
  1988. </if>
  1989. </where>
  1990. ORDER BY
  1991. claimd.claimDate DESC
  1992. </sql>
  1993. <select id="realAmountClaimed" parameterType="com.dayou.vo.FinanceRealFundVO" resultType="com.dayou.vo.FinanceRealFundVO">
  1994. <include refid="realAmountClaimedSQL" />
  1995. </select>
  1996. <select id="realClaimedExport" parameterType="com.dayou.vo.FinanceRealFundVO" resultType="com.dayou.dto.FinanceRealFundExportDTO">
  1997. <include refid="realAmountClaimedSQL" />
  1998. </select>
  1999. <select id="financeRealFundNotClaimExport" parameterType="com.dayou.entity.FinanceRealFund" resultType="com.dayou.dto.FinanceRealNotClaimDTO">
  2000. <include refid="pageListSql" />
  2001. ORDER BY
  2002. ifnull(t.ca,0) ASC ,frf.created DESC
  2003. </select>
  2004. </mapper>