FinanceRealFundMapper.xml 81 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658
  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. <select id="getPage" parameterType="com.dayou.entity.FinanceRealFund" resultType="com.dayou.vo.FinanceRealFundVO">
  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. ORDER BY
  75. ifnull(t.ca,0) ASC ,frf.created DESC
  76. </select>
  77. <select id="getNotClaimAmount" parameterType="java.lang.Long" resultType="java.math.BigDecimal">
  78. SELECT ( frf.amount -( SELECT ifnull( sum( claim_amount ), 0 ) AS ca FROM finance_claim WHERE deleted = 0 AND real_fund_id = #{realFundId} )
  79. ) AS notClaimAmount
  80. FROM
  81. finance_real_fund frf
  82. WHERE
  83. frf.id = #{realFundId}
  84. AND frf.deleted = 0
  85. </select>
  86. <sql id="majorOverdueSql">
  87. SELECT
  88. DATEDIFF(
  89. CURDATE(),
  90. DATE( mp.repertory_out_time )) AS overdueDay,
  91. m.allot_type,
  92. m.order_id,
  93. m.business_object_type,
  94. u.NAME AS clientManager,
  95. u1.NAME AS principal,
  96. cc1.NAME AS clientName,
  97. cc2.NAME AS clientSubName,
  98. pf.production_should_amount,
  99. ofu.should_amount,
  100. mp.*
  101. FROM
  102. (
  103. SELECT
  104. id,
  105. major_id,
  106. report_no,
  107. ( CASE production WHEN 'STATEMENT' THEN '意见书' WHEN 'REPORT' THEN '报告' WHEN 'LETTER' THEN '复评函' ELSE '' END ) production,
  108. NAME,
  109. evaluate_amount,
  110. repertory_out_time,
  111. standard_amount
  112. FROM
  113. major_production mp
  114. WHERE
  115. deleted = 0
  116. AND repertory_out_time IS NOT NULL and production != 'STATEMENT'
  117. ) mp
  118. LEFT JOIN ( SELECT business_id, production_no, production_should_amount, real_amount FROM production_fund WHERE business_type = 'MAJOR_BUSINESS' AND deleted = 0 ) pf ON ( mp.major_id = pf.business_id AND mp.report_no = pf.production_no )
  119. left join ( SELECT business_id,should_amount FROM order_fund WHERE business_type = 'MAJOR_BUSINESS' AND deleted = 0 ) ofu ON ofu.business_id = mp.major_id
  120. LEFT JOIN major m ON m.id = mp.major_id
  121. LEFT JOIN user u ON u.id = m.client_manager_id
  122. LEFT JOIN user u1 ON u1.id = m.principal_id
  123. LEFT JOIN customer_company cc1 ON cc1.id = m.clientele_id
  124. LEFT JOIN customer_company cc2 ON cc2.id = m.clientele_sub_id
  125. WHERE
  126. mp.production != 'STATEMENT'
  127. AND ( pf.production_no IS NULL OR pf.real_amount IS NULL )
  128. AND DATEDIFF(CURDATE(),DATE( mp.repertory_out_time )) >= #{overdueVO.overdueMin}
  129. <if test="overdueVO!=null and overdueVO.overdueMax!=null">
  130. AND DATEDIFF(CURDATE(),DATE( mp.repertory_out_time )) &lt;= #{overdueVO.overdueMax}
  131. </if>
  132. <if test="overdueVO!=null and overdueVO.orderId!=null and overdueVO.orderId!=''">
  133. and m.order_id = #{overdueVO.orderId}
  134. </if>
  135. <if test="overdueVO!=null and overdueVO.reportNo!=null and overdueVO.reportNo!=''">
  136. and mp.report_no like concat ('%',#{overdueVO.reportNo},'%')
  137. </if>
  138. <if test="overdueVO!=null and overdueVO.principal!=null and overdueVO.principal!=''">
  139. and u1.NAME like concat ('%',#{overdueVO.principal},'%')
  140. </if>
  141. order by overdueDay desc
  142. </sql>
  143. <select id="overdueMajor" parameterType="com.dayou.vo.MajorProdOverdueVO" resultType="com.dayou.vo.MajorProdOverdueVO">
  144. <include refid="majorOverdueSql" />
  145. </select>
  146. <select id="overdueMajorExport" parameterType="com.dayou.vo.MajorProdOverdueVO" resultType="com.dayou.vo.MajorProdOverdueVO">
  147. <include refid="majorOverdueSql" />
  148. </select>
  149. <resultMap id="settleeMajorProductionVOMap" type="com.dayou.vo.SettleMajorProductionVO">
  150. <id property="id" column="id" />
  151. <result property="id" column="id" />
  152. <result property="claimAmount" column="claim_amount" />
  153. <result property="orderId" column="order_id" />
  154. <result property="reportNo" column="report_no" />
  155. <result property="claimDate" column="claimDate" />
  156. <result property="saveFileDate" column="save_file_date" />
  157. <result property="settleDate" column="settleDate" />
  158. <result property="deliveryDate" column="deliveryDate" />
  159. <result property="name" column="name" />
  160. <result property="bailor" column="bailor" />
  161. <result property="evaluateAmount" column="evaluate_amount" />
  162. <result property="principal" column="principal" />
  163. <result property="clientManager" column="clientManager" />
  164. <result property="clientName" column="clientName" />
  165. <result property="clientSubName" column="clientSubName" />
  166. <result property="evaluateDepartmentName" column="evaluateDepartmentName" />
  167. <result property="marketDepartmentName" column="marketDepartmentName" />
  168. <collection property="invoices" ofType="com.dayou.vo.SettleProInvoiceVo">
  169. <result property="invoiceDate" column="invoiceDate" />
  170. <result property="invoiceUser" column="invoiceUser" />
  171. <result property="invoiceNo" column="invoiceNo" />
  172. </collection>
  173. </resultMap>
  174. <sql id="majorEvaluatorSettleSql">
  175. SELECT
  176. mp.id,
  177. fc.claim_amount,
  178. m.order_id,
  179. mp.report_no,
  180. fc.claim_datetime as claimDate,
  181. mp.save_file_date,
  182. IF
  183. ( fc.claim_datetime > mp.save_file_date, fc.claim_datetime, mp.save_file_date ) AS settleDate,
  184. mp.name,
  185. m.bailor,
  186. mp.evaluate_amount,
  187. u.name AS principal,
  188. u1.name AS clientManager,
  189. cc.name AS clientName,
  190. cc1.name AS clientSubName,
  191. d.name AS evaluateDepartmentName,
  192. (
  193. SELECT
  194. GROUP_CONCAT( name )
  195. FROM
  196. department
  197. WHERE
  198. id IN (
  199. SELECT
  200. department_id
  201. FROM
  202. post
  203. WHERE
  204. id IN ( SELECT post_id FROM user_post WHERE user_id = m.client_manager_id ))) AS marketDepartmentName,
  205. invoice.name AS invoiceUser,
  206. invoice.real_make_date AS invoiceDate,
  207. invoice.tax_no AS invoiceNo
  208. FROM
  209. (
  210. SELECT
  211. claim_amount,
  212. order_fund_id,
  213. production_fund_id,
  214. claim_datetime
  215. FROM
  216. finance_claim
  217. WHERE
  218. deleted = 0
  219. AND production_fund_id IS NOT NULL
  220. AND claim_datetime &gt;= #{settleVO.startDate}
  221. AND claim_datetime &lt;= #{settleVO.endDate} UNION ALL
  222. SELECT allot_amount AS claim_amount, order_fund_id, production_fund_id, created AS claim_datetime FROM order_fund_allot WHERE deleted = 0
  223. AND created &gt;= #{settleVO.startDate}
  224. AND created &lt;= #{settleVO.endDate}
  225. ) fc
  226. 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 )
  227. INNER JOIN ( SELECT id, major_id, NAME, report_no, production, evaluate_amount, save_file_date FROM major_production WHERE deleted = 0 AND save_file_date IS NOT NULL ) mp ON mp.report_no = pf.production_no
  228. LEFT JOIN major m ON m.id = mp.major_id
  229. LEFT JOIN user u ON u.id = m.principal_id
  230. LEFT JOIN user u1 ON u1.id = m.client_manager_id
  231. LEFT JOIN customer_company cc ON cc.id = m.clientele_id
  232. LEFT JOIN customer_company cc1 ON cc1.id = m.clientele_sub_id
  233. LEFT JOIN department d ON d.id = m.department_id
  234. LEFT JOIN (
  235. SELECT real_make_date, name, tax_no, order_fund_id, production_fund_id
  236. FROM finance_invoice, user
  237. WHERE maker_id = user.id
  238. AND finance_invoice.deleted = 0
  239. AND state = '已开票'
  240. ) 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)
  241. <where>
  242. <if test="settleVO!=null and settleVO.orderId!=null and settleVO.orderId!='' ">
  243. and m.order_id = #{settleVO.orderId}
  244. </if>
  245. <if test="settleVO!=null and settleVO.reportNo!=null and settleVO.reportNo!='' ">
  246. and mp.report_no like concat ('%',#{settleVO.reportNo},'%')
  247. </if>
  248. <if test="settleVO!=null and settleVO.principal!=null and settleVO.principal!='' ">
  249. and u.name like concat ('%',#{settleVO.principal},'%')
  250. </if>
  251. <if test="settleVO!=null and settleVO.clientManager!=null and settleVO.clientManager!='' ">
  252. and u1.name like concat ('%',#{settleVO.clientManager},'%')
  253. </if>
  254. </where>
  255. order by settleDate DESC
  256. </sql>
  257. <select id="majorEvaluatorSettleProd" parameterType="com.dayou.vo.SettleMajorProductionVO" resultMap="settleeMajorProductionVOMap">
  258. <include refid="majorEvaluatorSettleSql" />
  259. </select>
  260. <select id="majorEvaluatorSettleExport" parameterType="com.dayou.vo.SettleMajorProductionVO" resultMap="settleeMajorProductionVOMap">
  261. <include refid="majorEvaluatorSettleSql" />
  262. </select>
  263. <sql id="majorMarketerSettleSql">
  264. SELECT
  265. mp.id,
  266. fc.claim_amount,
  267. m.order_id,
  268. mp.report_no,
  269. fc.claim_datetime,
  270. mp.delivery_date,
  271. IF
  272. ( fc.claim_datetime > mp.delivery_date, fc.claim_datetime, mp.delivery_date ) AS settleDate,
  273. mp.NAME,
  274. m.bailor,
  275. mp.evaluate_amount,
  276. u.NAME AS principal,
  277. u1.NAME AS clientManager,
  278. cc.NAME AS clientName,
  279. cc1.NAME AS clientSubName,
  280. d.NAME AS evaluateDepartmentName,
  281. (
  282. SELECT
  283. GROUP_CONCAT( NAME )
  284. FROM
  285. department
  286. WHERE
  287. id IN (
  288. SELECT
  289. department_id
  290. FROM
  291. post
  292. WHERE
  293. id IN ( SELECT post_id FROM user_post WHERE user_id = m.client_manager_id ))) AS marketDepartmentName,
  294. invoice.name AS invoiceUser,
  295. invoice.real_make_date AS invoiceDate,
  296. invoice.tax_no AS invoiceNo
  297. FROM
  298. (
  299. SELECT
  300. claim_amount,
  301. order_fund_id,
  302. production_fund_id,
  303. claim_datetime
  304. FROM
  305. finance_claim
  306. WHERE
  307. deleted = 0
  308. AND production_fund_id IS NOT NULL
  309. AND claim_datetime &gt;= #{settleVO.startDate}
  310. AND claim_datetime &lt;= #{settleVO.endDate} UNION ALL
  311. SELECT allot_amount AS claim_amount, order_fund_id, production_fund_id, created AS claim_datetime FROM order_fund_allot WHERE deleted = 0
  312. AND created &gt;= #{settleVO.startDate}
  313. AND created &lt;= #{settleVO.endDate}
  314. ) fc
  315. 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 )
  316. INNER JOIN ( SELECT id, major_id, NAME, report_no, production, evaluate_amount, delivery_date FROM major_production WHERE deleted = 0 AND delivery_date IS NOT NULL ) mp ON mp.report_no = pf.production_no
  317. LEFT JOIN major m ON m.id = mp.major_id
  318. LEFT JOIN user u ON u.id = m.principal_id
  319. LEFT JOIN user u1 ON u1.id = m.client_manager_id
  320. LEFT JOIN customer_company cc ON cc.id = m.clientele_id
  321. LEFT JOIN customer_company cc1 ON cc1.id = m.clientele_sub_id
  322. LEFT JOIN department d ON d.id = m.department_id
  323. LEFT JOIN (
  324. SELECT real_make_date, name, tax_no, order_fund_id, production_fund_id
  325. FROM finance_invoice, user
  326. WHERE maker_id = user.id
  327. AND finance_invoice.deleted = 0
  328. AND state = '已开票'
  329. ) 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)
  330. <where>
  331. <if test="settleVO!=null and settleVO.orderId!=null and settleVO.orderId!='' ">
  332. and m.order_id = #{settleVO.orderId}
  333. </if>
  334. <if test="settleVO!=null and settleVO.reportNo!=null and settleVO.reportNo!='' ">
  335. and mp.report_no like concat ('%',#{settleVO.reportNo},'%')
  336. </if>
  337. <if test="settleVO!=null and settleVO.principal!=null and settleVO.principal!='' ">
  338. and u.name like concat ('%',#{settleVO.principal},'%')
  339. </if>
  340. <if test="settleVO!=null and settleVO.clientManager!=null and settleVO.clientManager!='' ">
  341. and u1.name like concat ('%',#{settleVO.clientManager},'%')
  342. </if>
  343. </where>
  344. order by settleDate DESC
  345. </sql>
  346. <select id="majorMarketerSettleProd" parameterType="com.dayou.vo.SettleMajorProductionVO" resultMap="settleeMajorProductionVOMap">
  347. <include refid="majorMarketerSettleSql" />
  348. </select>
  349. <select id="majorMarketSettleExport" parameterType="com.dayou.vo.SettleMajorProductionVO" resultMap="settleeMajorProductionVOMap">
  350. <include refid="majorMarketerSettleSql" />
  351. </select>
  352. <select id="majorEvaluatorCommission" parameterType="com.dayou.vo.UserCommissionTotalAmountVO" resultType="com.dayou.vo.UserCommissionTotalAmountVO">
  353. SELECT mpa.user_id as id, u.name as userName, sum(( fc.claim_amount * ( bcr.min_ratio / 100 )* mpa.ratio )) AS commissionTotalAmount
  354. FROM
  355. (
  356. SELECT
  357. claim_amount,
  358. order_fund_id,
  359. production_fund_id,
  360. claim_datetime
  361. FROM
  362. finance_claim
  363. WHERE
  364. deleted = 0
  365. AND production_fund_id IS NOT NULL
  366. AND claim_datetime &gt;= #{vo.startDate}
  367. AND claim_datetime &lt;= #{vo.endDate}
  368. UNION ALL
  369. SELECT
  370. allot_amount AS claim_amount,
  371. order_fund_id,
  372. production_fund_id,
  373. created AS claim_datetime
  374. FROM
  375. order_fund_allot
  376. WHERE
  377. deleted = 0
  378. AND created &gt;= #{vo.startDate}
  379. AND created &lt;= #{vo.endDate}
  380. ) fc
  381. 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 )
  382. INNER JOIN ( SELECT id, major_id, NAME, report_no, production, save_file_date, created FROM major_production WHERE deleted = 0 AND save_file_date IS NOT NULL ) mp ON mp.report_no = pf.production_no
  383. LEFT JOIN major m ON m.id = mp.major_id
  384. 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 (
  385. cd.business_id = m.id
  386. AND ( cd.production_id IS NULL OR cd.production_id = mp.id ))
  387. LEFT JOIN business_commission_rate bcr ON bcr.id = cd.commission_rate_id
  388. LEFT JOIN dict_data dd ON dd.id = bcr.business_cate_id
  389. LEFT JOIN ( SELECT major_id, major_production_id, user_id, ratio FROM major_production_allot WHERE deleted = 0 AND user_type = 'EVALUATE'
  390. ) mpa ON ( mpa.major_id = m.id AND mpa.major_production_id = mp.id)
  391. LEFT JOIN user u ON u.id = mpa.user_id
  392. GROUP BY
  393. mpa.user_id
  394. having 1=1
  395. <if test="vo!=null and vo.userName!=null and vo.userName!=''">
  396. and u.name like concat ('%',#{vo.userName},'%')
  397. </if>
  398. order by commissionTotalAmount DESC
  399. </select>
  400. <select id="majorEvaluatorCommissionDetail" parameterType="com.dayou.vo.UserCommissionProdVO" resultType="com.dayou.vo.UserCommissionProdVO">
  401. SELECT
  402. mp.id,
  403. fc.claim_amount as realAmount,
  404. mp.report_no,
  405. IF
  406. ( fc.claim_datetime > mp.save_file_date, fc.claim_datetime, mp.save_file_date ) AS settleDate,
  407. mp.NAME,
  408. mp.created,
  409. dd.NAME AS businessCate,
  410. bcr.min_ratio AS ratio,
  411. mpa.user_id,
  412. mpa.ratio AS allotRatio,
  413. ( fc.claim_amount * ( bcr.min_ratio / 100 )* mpa.ratio ) AS commissionAmount,
  414. ( fc.claim_amount * ( bcr.min_ratio / 100 ) ) AS totalAmount,
  415. u.name as userName
  416. FROM
  417. (
  418. SELECT
  419. claim_amount,
  420. order_fund_id,
  421. production_fund_id,
  422. claim_datetime
  423. FROM
  424. finance_claim
  425. WHERE
  426. deleted = 0
  427. AND production_fund_id IS NOT NULL
  428. AND claim_datetime &gt;= #{vo.startDate}
  429. AND claim_datetime &lt;= #{vo.endDate}
  430. UNION ALL
  431. SELECT
  432. allot_amount AS claim_amount,
  433. order_fund_id,
  434. production_fund_id,
  435. created AS claim_datetime
  436. FROM
  437. order_fund_allot
  438. WHERE
  439. deleted = 0
  440. AND created &gt;= #{vo.startDate}
  441. AND created &lt;= #{vo.endDate}
  442. ) fc
  443. 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 )
  444. INNER JOIN ( SELECT id, major_id, NAME, report_no, production, save_file_date, created FROM major_production WHERE deleted = 0 AND save_file_date IS NOT NULL ) mp ON mp.report_no = pf.production_no
  445. LEFT JOIN major m ON m.id = mp.major_id
  446. 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 (
  447. cd.business_id = m.id
  448. AND ( cd.production_id IS NULL OR cd.production_id = mp.id ))
  449. LEFT JOIN business_commission_rate bcr ON bcr.id = cd.commission_rate_id
  450. LEFT JOIN dict_data dd ON dd.id = bcr.business_cate_id
  451. 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)
  452. LEFT JOIN user u on u.id = mpa.user_id
  453. WHERE
  454. mpa.user_id = #{vo.userId}
  455. order by settleDate DESC
  456. </select>
  457. <select id="majorEvaluatorTotalAmountExport" parameterType="com.dayou.vo.UserCommissionTotalAmountVO" resultType="com.dayou.vo.UserCommissionTotalAmountVO">
  458. SELECT mpa.user_id as id, u.name as userName, ROUND(sum(( fc.claim_amount * ( bcr.min_ratio / 100 )* mpa.ratio )),2) AS commissionTotalAmount,
  459. '评估人员' as userType,
  460. '大中型业务' as businessType,
  461. #{vo.startDate} as startDate,
  462. #{vo.endDate} as endDate
  463. FROM
  464. (
  465. SELECT
  466. claim_amount,
  467. order_fund_id,
  468. production_fund_id,
  469. claim_datetime
  470. FROM
  471. finance_claim
  472. WHERE
  473. deleted = 0
  474. AND production_fund_id IS NOT NULL
  475. AND claim_datetime &gt;= #{vo.startDate}
  476. AND claim_datetime &lt;= #{vo.endDate}
  477. UNION ALL
  478. SELECT
  479. allot_amount AS claim_amount,
  480. order_fund_id,
  481. production_fund_id,
  482. created AS claim_datetime
  483. FROM
  484. order_fund_allot
  485. WHERE
  486. deleted = 0
  487. AND created &gt;= #{vo.startDate}
  488. AND created &lt;= #{vo.endDate}
  489. ) fc
  490. 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 )
  491. INNER JOIN ( SELECT id, major_id, NAME, report_no, production, save_file_date, created FROM major_production WHERE deleted = 0 AND save_file_date IS NOT NULL ) mp ON mp.report_no = pf.production_no
  492. LEFT JOIN major m ON m.id = mp.major_id
  493. 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 (
  494. cd.business_id = m.id
  495. AND ( cd.production_id IS NULL OR cd.production_id = mp.id ))
  496. LEFT JOIN business_commission_rate bcr ON bcr.id = cd.commission_rate_id
  497. LEFT JOIN dict_data dd ON dd.id = bcr.business_cate_id
  498. LEFT JOIN ( SELECT major_id, major_production_id, user_id, ratio FROM major_production_allot WHERE deleted = 0 AND user_type = 'EVALUATE'
  499. ) mpa ON ( mpa.major_id = m.id AND mpa.major_production_id = mp.id)
  500. LEFT JOIN user u ON u.id = mpa.user_id
  501. GROUP BY
  502. mpa.user_id
  503. </select>
  504. <select id="evaluatorUserDetailExport" parameterType="com.dayou.vo.UserCommissionProdVO" resultType="com.dayou.vo.UserCommissionProdVO">
  505. SELECT
  506. mp.id,
  507. ROUND(fc.claim_amount,2) as realAmount,
  508. mp.report_no,
  509. IF
  510. ( fc.claim_datetime > mp.save_file_date, fc.claim_datetime, mp.save_file_date ) AS settleDate,
  511. mp.NAME,
  512. mp.created,
  513. dd.NAME AS businessCate,
  514. ROUND(bcr.min_ratio,2) AS ratio,
  515. mpa.user_id,
  516. ROUND(mpa.ratio*100,2) AS allotRatio,
  517. ROUND(( fc.claim_amount * ( bcr.min_ratio / 100 )* mpa.ratio ),2) AS commissionAmount,
  518. ROUND(( fc.claim_amount * ( bcr.min_ratio / 100 ) ),2) AS totalAmount,
  519. u.name as userName
  520. FROM
  521. (
  522. SELECT
  523. claim_amount,
  524. order_fund_id,
  525. production_fund_id,
  526. claim_datetime
  527. FROM
  528. finance_claim
  529. WHERE
  530. deleted = 0
  531. AND production_fund_id IS NOT NULL
  532. AND claim_datetime &gt;= #{vo.startDate}
  533. AND claim_datetime &lt;= #{vo.endDate}
  534. UNION ALL
  535. SELECT
  536. allot_amount AS claim_amount,
  537. order_fund_id,
  538. production_fund_id,
  539. created AS claim_datetime
  540. FROM
  541. order_fund_allot
  542. WHERE
  543. deleted = 0
  544. AND created &gt;= #{vo.startDate}
  545. AND created &lt;= #{vo.endDate}
  546. ) fc
  547. 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 )
  548. INNER JOIN ( SELECT id, major_id, NAME, report_no, production, save_file_date, created FROM major_production WHERE deleted = 0 AND save_file_date IS NOT NULL ) mp ON mp.report_no = pf.production_no
  549. LEFT JOIN major m ON m.id = mp.major_id
  550. 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 (
  551. cd.business_id = m.id
  552. AND ( cd.production_id IS NULL OR cd.production_id = mp.id ))
  553. LEFT JOIN business_commission_rate bcr ON bcr.id = cd.commission_rate_id
  554. LEFT JOIN dict_data dd ON dd.id = bcr.business_cate_id
  555. 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)
  556. LEFT JOIN user u on u.id = mpa.user_id
  557. <where>
  558. <if test="vo!=null and vo.userId!=null">
  559. and mpa.user_id = #{vo.userId}
  560. </if>
  561. </where>
  562. order by mpa.user_id
  563. </select>
  564. <select id="majorMarketCommission" parameterType="com.dayou.vo.UserCommissionTotalAmountVO" resultType="com.dayou.vo.UserCommissionTotalAmountVO">
  565. SELECT mpa.user_id as id, u.name as userName, sum(( fc.claim_amount * ( bcr.min_ratio / 100 )* mpa.ratio )) AS commissionTotalAmount
  566. FROM
  567. (
  568. SELECT
  569. claim_amount,
  570. order_fund_id,
  571. production_fund_id,
  572. claim_datetime
  573. FROM
  574. finance_claim
  575. WHERE
  576. deleted = 0
  577. AND production_fund_id IS NOT NULL
  578. AND claim_datetime &gt;= #{vo.startDate}
  579. AND claim_datetime &lt;= #{vo.endDate}
  580. 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
  581. AND created &gt;= #{vo.startDate}
  582. AND created &lt;= #{vo.endDate}
  583. ) fc
  584. 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 )
  585. INNER JOIN ( SELECT id, major_id, NAME, report_no, production, save_file_date, created FROM major_production WHERE deleted = 0 AND delivery_date IS NOT NULL ) mp ON mp.report_no = pf.production_no
  586. LEFT JOIN major m ON m.id = mp.major_id
  587. 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 (
  588. cd.business_id = m.id
  589. AND ( cd.production_id IS NULL OR cd.production_id = mp.id ))
  590. LEFT JOIN business_commission_rate bcr ON bcr.id = cd.commission_rate_id
  591. LEFT JOIN dict_data dd ON dd.id = bcr.business_cate_id
  592. LEFT JOIN ( SELECT major_id, major_production_id,declare_id, user_id, ratio FROM major_production_allot WHERE deleted = 0 AND user_type = 'MARKET'
  593. ) 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 ))
  594. LEFT JOIN user u ON u.id = mpa.user_id
  595. GROUP BY
  596. mpa.user_id
  597. having 1=1
  598. <if test="vo!=null and vo.userName!=null and vo.userName!=''">
  599. and u.name like concat ('%',#{vo.userName},'%')
  600. </if>
  601. order by commissionTotalAmount DESC
  602. </select>
  603. <select id="majorMarketCommissionDetail" parameterType="com.dayou.vo.UserCommissionProdVO" resultType="com.dayou.vo.UserCommissionProdVO">
  604. SELECT
  605. mp.id,
  606. fc.claim_amount as realAmount,
  607. mp.report_no,
  608. IF
  609. ( fc.claim_datetime > mp.save_file_date, fc.claim_datetime, mp.save_file_date ) AS settleDate,
  610. mp.NAME,
  611. mp.created,
  612. dd.NAME AS businessCate,
  613. bcr.min_ratio AS ratio,
  614. mpa.user_id,
  615. mpa.ratio AS allotRatio,
  616. ( fc.claim_amount * ( bcr.min_ratio / 100 )* mpa.ratio ) AS commissionAmount,
  617. ( fc.claim_amount * ( bcr.min_ratio / 100 ) ) AS totalAmount,
  618. u.name as userName
  619. FROM
  620. (
  621. SELECT
  622. claim_amount,
  623. order_fund_id,
  624. production_fund_id,
  625. claim_datetime
  626. FROM
  627. finance_claim
  628. WHERE
  629. deleted = 0
  630. AND production_fund_id IS NOT NULL
  631. AND claim_datetime &gt;= #{vo.startDate}
  632. AND claim_datetime &lt;= #{vo.endDate}
  633. UNION ALL
  634. SELECT
  635. allot_amount AS claim_amount,
  636. order_fund_id,
  637. production_fund_id,
  638. created AS claim_datetime
  639. FROM
  640. order_fund_allot
  641. WHERE
  642. deleted = 0
  643. AND created &gt;= #{vo.startDate}
  644. AND created &lt;= #{vo.endDate}
  645. ) fc
  646. 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 )
  647. INNER JOIN ( SELECT id, major_id, NAME, report_no, production, save_file_date, created FROM major_production WHERE deleted = 0 AND delivery_date IS NOT NULL ) mp ON mp.report_no = pf.production_no
  648. LEFT JOIN major m ON m.id = mp.major_id
  649. 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 (
  650. cd.business_id = m.id
  651. AND ( cd.production_id IS NULL OR cd.production_id = mp.id ))
  652. LEFT JOIN business_commission_rate bcr ON bcr.id = cd.commission_rate_id
  653. LEFT JOIN dict_data dd ON dd.id = bcr.business_cate_id
  654. 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 ))
  655. LEFT JOIN user u on u.id = mpa.user_id
  656. WHERE
  657. mpa.user_id = #{vo.userId}
  658. order by settleDate DESC
  659. </select>
  660. <select id="majorMarketTotalAmountExport" parameterType="com.dayou.vo.UserCommissionTotalAmountVO" resultType="com.dayou.vo.UserCommissionTotalAmountVO">
  661. SELECT mpa.user_id as id, u.name as userName, ROUND(sum(( fc.claim_amount * ( bcr.min_ratio / 100 )* mpa.ratio )),2) AS commissionTotalAmount,
  662. '市场人员' as userType,
  663. '大中型业务' as businessType,
  664. #{vo.startDate} as startDate,
  665. #{vo.endDate} as endDate
  666. FROM
  667. (
  668. SELECT
  669. claim_amount,
  670. order_fund_id,
  671. production_fund_id,
  672. claim_datetime
  673. FROM
  674. finance_claim
  675. WHERE
  676. deleted = 0
  677. AND production_fund_id IS NOT NULL
  678. AND claim_datetime &gt;= #{vo.startDate}
  679. AND claim_datetime &lt;= #{vo.endDate}
  680. UNION ALL
  681. SELECT allot_amount AS claim_amount, order_fund_id, production_fund_id, created AS claim_datetime FROM order_fund_allot WHERE deleted = 0
  682. AND created &gt;= #{vo.startDate}
  683. AND created &lt;= #{vo.endDate}
  684. ) fc
  685. 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 )
  686. INNER JOIN ( SELECT id, major_id, NAME, report_no, production, save_file_date, created FROM major_production WHERE deleted = 0 AND delivery_date IS NOT NULL ) mp ON mp.report_no = pf.production_no
  687. LEFT JOIN major m ON m.id = mp.major_id
  688. 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 (
  689. cd.business_id = m.id
  690. AND ( cd.production_id IS NULL OR cd.production_id = mp.id ))
  691. LEFT JOIN business_commission_rate bcr ON bcr.id = cd.commission_rate_id
  692. LEFT JOIN dict_data dd ON dd.id = bcr.business_cate_id
  693. LEFT JOIN ( SELECT major_id, major_production_id,declare_id, user_id, ratio FROM major_production_allot WHERE deleted = 0 AND user_type = 'MARKET'
  694. ) 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 ))
  695. LEFT JOIN user u ON u.id = mpa.user_id
  696. GROUP BY
  697. mpa.user_id
  698. order by commissionTotalAmount DESC
  699. </select>
  700. <select id="marketUserDetailExport" parameterType="com.dayou.vo.UserCommissionProdVO" resultType="com.dayou.vo.UserCommissionProdVO">
  701. SELECT
  702. mp.id,
  703. ROUND(fc.claim_amount,2) as realAmount,
  704. mp.report_no,
  705. IF
  706. ( fc.claim_datetime > mp.save_file_date, fc.claim_datetime, mp.save_file_date ) AS settleDate,
  707. mp.NAME,
  708. mp.created,
  709. dd.NAME AS businessCate,
  710. ROUND(bcr.min_ratio,2) AS ratio,
  711. mpa.user_id,
  712. ROUND(mpa.ratio*100,2) AS allotRatio,
  713. ROUND(( fc.claim_amount * ( bcr.min_ratio / 100 )* mpa.ratio ),2) AS commissionAmount,
  714. ROUND(( fc.claim_amount * ( bcr.min_ratio / 100 ) ),2) AS totalAmount,
  715. u.name as userName
  716. FROM
  717. (
  718. SELECT
  719. claim_amount,
  720. order_fund_id,
  721. production_fund_id,
  722. claim_datetime
  723. FROM
  724. finance_claim
  725. WHERE
  726. deleted = 0
  727. AND production_fund_id IS NOT NULL
  728. AND claim_datetime &gt;= #{vo.startDate}
  729. AND claim_datetime &lt;= #{vo.endDate}
  730. UNION ALL
  731. SELECT
  732. allot_amount AS claim_amount,
  733. order_fund_id,
  734. production_fund_id,
  735. created AS claim_datetime
  736. FROM
  737. order_fund_allot
  738. WHERE
  739. deleted = 0
  740. AND created &gt;= #{vo.startDate}
  741. AND created &lt;= #{vo.endDate}
  742. ) fc
  743. 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 )
  744. INNER JOIN ( SELECT id, major_id, NAME, report_no, production, save_file_date, created FROM major_production WHERE deleted = 0 AND delivery_date IS NOT NULL ) mp ON mp.report_no = pf.production_no
  745. LEFT JOIN major m ON m.id = mp.major_id
  746. 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 (
  747. cd.business_id = m.id
  748. AND ( cd.production_id IS NULL OR cd.production_id = mp.id ))
  749. LEFT JOIN business_commission_rate bcr ON bcr.id = cd.commission_rate_id
  750. LEFT JOIN dict_data dd ON dd.id = bcr.business_cate_id
  751. 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 ))
  752. LEFT JOIN user u on u.id = mpa.user_id
  753. <where>
  754. <if test="vo!=null and vo.userId!=null">
  755. and mpa.user_id = #{vo.userId}
  756. </if>
  757. </where>
  758. order by mpa.user_id
  759. </select>
  760. <sql id="personalOverdueSql">
  761. SELECT
  762. DATEDIFF(
  763. CURDATE(),
  764. DATE ( pp.rot )) AS overdueDay,
  765. p.*,
  766. pt.acreage,
  767. pt.price,
  768. pt.amount,
  769. cc1.NAME AS clientName,
  770. cc2.NAME AS clientSubName,
  771. cl1.NAME AS contactName,
  772. cl1.mobile AS contactTel,
  773. u.NAME AS clientManager,
  774. u1.NAME AS outwardStaffName,
  775. u2.NAME AS inwardStaffName,
  776. u3.NAME AS pricingStaffName,
  777. pp.rot
  778. FROM
  779. (
  780. SELECT
  781. id,
  782. location,
  783. order_id,
  784. agent,
  785. bailorA,
  786. bailorB,
  787. clientele_id,
  788. clientele_sub_id,
  789. clientele_contact_id,
  790. client_manager_id,
  791. outward_staff,
  792. inward_staff,
  793. pricing_staff
  794. FROM
  795. personal
  796. WHERE
  797. deleted = 0
  798. ) p
  799. LEFT JOIN personal_target pt ON pt.personal_id = p.id
  800. LEFT 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
  801. LEFT 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
  802. LEFT JOIN customer_company cc1 ON cc1.id = p.clientele_id
  803. LEFT JOIN customer_company cc2 ON cc2.id = p.clientele_sub_id
  804. LEFT JOIN customer_linkman cl1 ON cl1.id = p.clientele_contact_id
  805. LEFT JOIN `user` u ON u.id = p.client_manager_id
  806. LEFT JOIN `user` u1 ON u1.id = p.outward_staff
  807. LEFT JOIN `user` u2 ON u2.id = p.inward_staff
  808. LEFT JOIN `user` u3 ON u3.id = p.pricing_staff
  809. WHERE
  810. DATEDIFF(
  811. CURDATE(),
  812. DATE ( pp.rot )) >= #{overdueVO.overdueMin}
  813. <if test="overdueVO!=null and overdueVO.overdueMax!=null">
  814. AND DATEDIFF(CURDATE(),DATE( pp.rot )) &lt;= #{overdueVO.overdueMax}
  815. </if>
  816. <if test="overdueVO!=null and overdueVO.orderId!=null and overdueVO.orderId!=''">
  817. and m.order_id = #{overdueVO.orderId}
  818. </if>
  819. ORDER BY
  820. overdueDay DESC
  821. </sql>
  822. <select id="overduePersonal" parameterType="com.dayou.vo.PersonalOverdueVO" resultType="com.dayou.vo.PersonalOverdueVO">
  823. <include refid="personalOverdueSql" />
  824. </select>
  825. <select id="overduePersonalList" parameterType="com.dayou.vo.PersonalOverdueVO" resultType="com.dayou.vo.PersonalOverdueVO">
  826. <include refid="personalOverdueSql" />
  827. </select>
  828. <!--资产评估人员提成计算-->
  829. <select id="assetsEvaluatorCommission" resultType="com.dayou.vo.UserCommissionTotalAmountVO">
  830. SELECT bpd.member_id as id,
  831. u.name as userName,
  832. SUM(IF(cd.defined_low_limit_amount &lt; fc.claim_amount,
  833. fc.claim_amount * (cd.ratio / 100) * (bpd.performance_distribution / 100),
  834. cd.defined_low_limit_amount * (cd.ratio / 100) * (bpd.performance_distribution / 100)
  835. )) AS allCommissionTotalAmount,
  836. SUM(IF(ap.save_file_date IS NOT NULL, (IF(cd.defined_low_limit_amount &lt; fc.claim_amount,
  837. fc.claim_amount * (cd.ratio / 100) * (bpd.performance_distribution / 100),
  838. cd.defined_low_limit_amount * (cd.ratio / 100) * (bpd.performance_distribution / 100)
  839. )), 0)) AS commissionTotalAmount
  840. FROM
  841. (
  842. SELECT
  843. claim_amount,
  844. order_fund_id,
  845. production_fund_id,
  846. claim_datetime
  847. FROM
  848. finance_claim
  849. WHERE
  850. deleted = 0
  851. AND production_fund_id IS NOT NULL
  852. AND claim_datetime &gt;= #{vo.startDate}
  853. AND claim_datetime &lt;= #{vo.endDate}
  854. UNION ALL
  855. SELECT
  856. allot_amount AS claim_amount,
  857. order_fund_id,
  858. production_fund_id,
  859. created AS claim_datetime
  860. FROM
  861. order_fund_allot
  862. WHERE
  863. deleted = 0
  864. AND created &gt;= #{vo.startDate}
  865. AND created &lt;= #{vo.endDate}
  866. ) fc
  867. INNER JOIN ( SELECT id, order_fund_id, business_id, production_no FROM production_fund WHERE business_type =
  868. 'ASSET_BUSINESS' AND deleted = 0 ) pf ON ( pf.id = fc.production_fund_id AND pf.order_fund_id = fc.order_fund_id
  869. )
  870. INNER JOIN ( SELECT id, business_id, assets_name, production_no, production_type, save_file_date, created FROM
  871. assets_production
  872. WHERE deleted = 0) ap ON ap.production_no = pf.production_no
  873. LEFT JOIN assets a ON a.id = ap.business_id
  874. INNER JOIN ( SELECT id, business_id, production_id, commission_rate_id, ratio, defined_low_limit_amount FROM
  875. commission_declare WHERE
  876. business_type = 'COMMISSION_DECLARE_ASSET_EVALUATE' AND deleted = 0 AND declare_result = '审核通过' ) cd ON (
  877. cd.business_id = a.id
  878. AND ( cd.production_id IS NULL OR cd.production_id = ap.id ))
  879. LEFT JOIN business_commission_rate bcr ON bcr.id = cd.commission_rate_id
  880. LEFT JOIN dict_data dd ON dd.id = bcr.business_cate_id
  881. LEFT JOIN ( SELECT business_id, report_no, member_id, performance_distribution FROM
  882. business_performance_distribution WHERE deleted = 0
  883. AND user_type = '评估人员'
  884. ) bpd ON ( bpd.business_id = a.id AND bpd.report_no = ap.production_no)
  885. LEFT JOIN user u ON u.id = bpd.member_id
  886. GROUP BY
  887. bpd.member_id
  888. having 1=1
  889. <if test="vo!=null and vo.userName!=null and vo.userName!=''">
  890. and u.name like concat ('%',#{vo.userName},'%')
  891. </if>
  892. order by commissionTotalAmount DESC
  893. </select>
  894. <!--资产评估人员提成计算详情-->
  895. <select id="assetsEvaluatorCommissionDetail" resultType="com.dayou.vo.UserCommissionProdAssetsVO">
  896. SELECT
  897. ap.id,
  898. fc.claim_amount as realAmount,
  899. ap.production_no AS reportNo,
  900. IF
  901. ( fc.claim_datetime > ap.save_file_date, fc.claim_datetime, ap.save_file_date ) AS settleDate,
  902. ap.assets_name AS name,
  903. ap.created,
  904. dd.name AS businessCate,
  905. IFNULL(cd.ratio,bcr.min_ratio) AS ratio,
  906. cd.defined_low_limit_amount AS lowLimitAmount,
  907. bpd.member_id,
  908. bpd.performance_distribution AS allotRatio,
  909. IF(cd.defined_low_limit_amount &lt; fc.claim_amount,
  910. fc.claim_amount * (cd.ratio / 100) * (bpd.performance_distribution / 100),
  911. cd.defined_low_limit_amount * (cd.ratio / 100) * (bpd.performance_distribution / 100)
  912. ) AS commissionAmount,
  913. IF(cd.defined_low_limit_amount &lt; fc.claim_amount,
  914. fc.claim_amount * (cd.ratio / 100),
  915. cd.defined_low_limit_amount * (cd.ratio / 100)
  916. ) AS totalAmount,
  917. u.name AS userName,
  918. pf.modified AS realFundDateTime
  919. FROM
  920. (
  921. SELECT
  922. claim_amount,
  923. order_fund_id,
  924. production_fund_id,
  925. claim_datetime
  926. FROM
  927. finance_claim
  928. WHERE
  929. deleted = 0
  930. AND production_fund_id IS NOT NULL
  931. AND claim_datetime &gt;= #{vo.startDate}
  932. AND claim_datetime &lt;= #{vo.endDate}
  933. UNION ALL
  934. SELECT
  935. allot_amount AS claim_amount,
  936. order_fund_id,
  937. production_fund_id,
  938. created AS claim_datetime
  939. FROM
  940. order_fund_allot
  941. WHERE
  942. deleted = 0
  943. AND created &gt;= #{vo.startDate}
  944. AND created &lt;= #{vo.endDate}
  945. ) fc
  946. 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 )
  947. 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
  948. LEFT JOIN assets a ON a.id = ap.business_id
  949. 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 (
  950. cd.business_id = a.id
  951. AND ( cd.production_id IS NULL OR cd.production_id = ap.id ))
  952. LEFT JOIN business_commission_rate bcr ON bcr.id = cd.commission_rate_id
  953. LEFT JOIN dict_data dd ON dd.id = bcr.business_cate_id
  954. 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)
  955. LEFT JOIN user u on u.id = bpd.member_id
  956. WHERE
  957. bpd.member_id = #{vo.userId}
  958. order by settleDate DESC
  959. </select>
  960. <!--资产评估人员合计导出-->
  961. <select id="assetsEvaluatorTotalAmountExport" resultType="com.dayou.vo.UserCommissionTotalAmountVO">
  962. SELECT bpd.member_id as id,
  963. u.name as userName,
  964. ROUND(SUM(IF(cd.defined_low_limit_amount &lt; fc.claim_amount,
  965. fc.claim_amount * (cd.ratio / 100) * (bpd.performance_distribution / 100),
  966. cd.defined_low_limit_amount * (cd.ratio / 100) * (bpd.performance_distribution / 100)
  967. )), 2) AS allCommissionTotalAmount,
  968. ROUND(SUM(IF(ap.save_file_date IS NOT NULL, (IF(cd.defined_low_limit_amount &lt; fc.claim_amount,
  969. fc.claim_amount * (cd.ratio / 100) * (bpd.performance_distribution / 100),
  970. cd.defined_low_limit_amount * (cd.ratio / 100) * (bpd.performance_distribution / 100)
  971. )), 0)), 2) AS commissionTotalAmount,
  972. '评估人员' as userType,
  973. '资产业务' as businessType,
  974. #{vo.startDate} as startDate,
  975. #{vo.endDate} as endDate
  976. FROM (SELECT claim_amount,
  977. order_fund_id,
  978. production_fund_id,
  979. claim_datetime
  980. FROM finance_claim
  981. WHERE deleted = 0
  982. AND production_fund_id IS NOT NULL
  983. AND claim_datetime &gt;= #{vo.startDate}
  984. AND claim_datetime &lt;= #{vo.endDate}
  985. UNION ALL
  986. SELECT allot_amount AS claim_amount,
  987. order_fund_id,
  988. production_fund_id,
  989. created AS claim_datetime
  990. FROM order_fund_allot
  991. WHERE deleted = 0
  992. AND created &gt;= #{vo.startDate}
  993. AND created &lt;= #{vo.endDate}) fc
  994. INNER JOIN (SELECT id, order_fund_id, business_id, production_no
  995. FROM production_fund
  996. WHERE business_type = 'ASSET_BUSINESS'
  997. AND deleted = 0) pf
  998. ON (pf.id = fc.production_fund_id AND pf.order_fund_id = fc.order_fund_id)
  999. INNER JOIN (SELECT id,
  1000. business_id,
  1001. assets_name,
  1002. production_no,
  1003. production_type,
  1004. save_file_date,
  1005. created
  1006. FROM assets_production
  1007. WHERE deleted = 0) ap ON ap.production_no = pf.production_no
  1008. LEFT JOIN assets a ON a.id = ap.business_id
  1009. INNER JOIN (SELECT id, business_id, production_id, commission_rate_id, defined_low_limit_amount, ratio
  1010. FROM commission_declare
  1011. WHERE business_type = 'COMMISSION_DECLARE_ASSET_EVALUATE'
  1012. AND deleted = 0
  1013. AND declare_result = '审核通过') cd ON (
  1014. cd.business_id = a.id
  1015. AND (cd.production_id IS NULL OR cd.production_id = ap.id))
  1016. LEFT JOIN business_commission_rate bcr ON bcr.id = cd.commission_rate_id
  1017. LEFT JOIN dict_data dd ON dd.id = bcr.business_cate_id
  1018. LEFT JOIN (SELECT business_id, report_no, member_id, performance_distribution
  1019. FROM business_performance_distribution
  1020. WHERE deleted = 0
  1021. AND user_type = '评估人员') bpd
  1022. ON (bpd.business_id = a.id AND bpd.report_no = ap.production_no)
  1023. LEFT JOIN user u ON u.id = bpd.member_id
  1024. GROUP BY bpd.member_id
  1025. </select>
  1026. <!--资产评估人员提成信息导出-->
  1027. <select id="assetsEvaluatorUserDetailExport" resultType="com.dayou.vo.UserCommissionProdAssetsVO">
  1028. SELECT
  1029. ap.id,
  1030. ROUND(fc.claim_amount,2) as realAmount,
  1031. ap.production_no AS reportNo,
  1032. IF
  1033. ( fc.claim_datetime > ap.save_file_date, fc.claim_datetime, ap.save_file_date ) AS settleDate,
  1034. ap.assets_name AS name,
  1035. ap.created,
  1036. dd.NAME AS businessCate,
  1037. IFNULL(cd.ratio,bcr.min_ratio) AS ratio,
  1038. cd.defined_low_limit_amount AS lowLimitAmount,
  1039. ROUND(bcr.min_ratio,2) AS ratio,
  1040. bpd.member_id AS userId,
  1041. ROUND(bpd.performance_distribution,2) AS allotRatio,
  1042. ROUND(IF(cd.defined_low_limit_amount &lt; fc.claim_amount,
  1043. fc.claim_amount * (cd.ratio / 100) * (bpd.performance_distribution / 100),
  1044. cd.defined_low_limit_amount * (cd.ratio / 100) * (bpd.performance_distribution / 100)
  1045. ),2) AS commissionAmount,
  1046. ROUND(IF(cd.defined_low_limit_amount &lt; fc.claim_amount,
  1047. fc.claim_amount * (cd.ratio / 100),
  1048. cd.defined_low_limit_amount * (cd.ratio / 100)
  1049. ),2) AS totalAmount,
  1050. u.name as userName,
  1051. pf.modified AS realFundDateTime
  1052. FROM
  1053. (
  1054. SELECT
  1055. claim_amount,
  1056. order_fund_id,
  1057. production_fund_id,
  1058. claim_datetime
  1059. FROM
  1060. finance_claim
  1061. WHERE
  1062. deleted = 0
  1063. AND production_fund_id IS NOT NULL
  1064. AND claim_datetime &gt;= #{vo.startDate}
  1065. AND claim_datetime &lt;= #{vo.endDate}
  1066. UNION ALL
  1067. SELECT
  1068. allot_amount AS claim_amount,
  1069. order_fund_id,
  1070. production_fund_id,
  1071. created AS claim_datetime
  1072. FROM
  1073. order_fund_allot
  1074. WHERE
  1075. deleted = 0
  1076. AND created &gt;= #{vo.startDate}
  1077. AND created &lt;= #{vo.endDate}
  1078. ) fc
  1079. 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 )
  1080. 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
  1081. LEFT JOIN assets a ON a.id = ap.business_id
  1082. 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 (
  1083. cd.business_id = a.id
  1084. AND ( cd.production_id IS NULL OR cd.production_id = ap.id ))
  1085. LEFT JOIN business_commission_rate bcr ON bcr.id = cd.commission_rate_id
  1086. LEFT JOIN dict_data dd ON dd.id = bcr.business_cate_id
  1087. 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)
  1088. LEFT JOIN user u on u.id = bpd.member_id
  1089. <where>
  1090. <if test="vo!=null and vo.userId!=null">
  1091. and bpd.member_id = #{vo.userId}
  1092. </if>
  1093. </where>
  1094. order by bpd.member_id
  1095. </select>
  1096. <!--资产市场人员提成计算-->
  1097. <select id="assetsMarketCommission" resultType="com.dayou.vo.UserCommissionTotalAmountVO">
  1098. SELECT bpd.member_id as id,
  1099. u.name as userName,
  1100. SUM(( fc.claim_amount * ( bcr.min_ratio / 100 ) * (bpd.performance_distribution / 100))) AS commissionTotalAmount
  1101. FROM
  1102. (
  1103. SELECT
  1104. claim_amount,
  1105. order_fund_id,
  1106. production_fund_id,
  1107. claim_datetime
  1108. FROM
  1109. finance_claim
  1110. WHERE
  1111. deleted = 0
  1112. AND production_fund_id IS NOT NULL
  1113. AND claim_datetime &gt;= #{vo.startDate}
  1114. AND claim_datetime &lt;= #{vo.endDate}
  1115. 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
  1116. AND created &gt;= #{vo.startDate}
  1117. AND created &lt;= #{vo.endDate}
  1118. ) fc
  1119. 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 )
  1120. 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
  1121. LEFT JOIN assets a ON a.id = ap.business_id
  1122. 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 (
  1123. cd.business_id = a.id
  1124. AND ( cd.production_id IS NULL OR cd.production_id = ap.id ))
  1125. LEFT JOIN business_commission_rate bcr ON bcr.id = cd.commission_rate_id
  1126. LEFT JOIN dict_data dd ON dd.id = bcr.business_cate_id
  1127. LEFT JOIN ( SELECT business_id, report_no,declare_id, member_id, performance_distribution FROM business_performance_distribution WHERE deleted = 0 AND user_type = '市场人员'
  1128. ) 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 ))
  1129. LEFT JOIN user u ON u.id = bpd.member_id
  1130. GROUP BY
  1131. bpd.member_id
  1132. having 1=1
  1133. <if test="vo!=null and vo.userName!=null and vo.userName!=''">
  1134. and u.name like concat ('%',#{vo.userName},'%')
  1135. </if>
  1136. order by commissionTotalAmount DESC
  1137. </select>
  1138. <!--资产市场人员提成计算详情-->
  1139. <select id="assetsMarketCommissionDetail" resultType="com.dayou.vo.UserCommissionProdVO">
  1140. SELECT
  1141. ap.id,
  1142. fc.claim_amount as realAmount,
  1143. ap.production_no AS reportNo,
  1144. IF
  1145. ( fc.claim_datetime > ap.save_file_date, fc.claim_datetime, ap.save_file_date ) AS settleDate,
  1146. ap.assets_name AS name,
  1147. ap.created,
  1148. dd.NAME AS businessCate,
  1149. bcr.min_ratio AS ratio,
  1150. bpd.member_id AS userId,
  1151. bpd.performance_distribution AS allotRatio,
  1152. ( fc.claim_amount * ( bcr.min_ratio / 100 ) * (bpd.performance_distribution / 100) ) AS commissionAmount,
  1153. ( fc.claim_amount * ( bcr.min_ratio / 100 ) ) AS totalAmount,
  1154. u.name as userName
  1155. FROM
  1156. (
  1157. SELECT
  1158. claim_amount,
  1159. order_fund_id,
  1160. production_fund_id,
  1161. claim_datetime
  1162. FROM
  1163. finance_claim
  1164. WHERE
  1165. deleted = 0
  1166. AND production_fund_id IS NOT NULL
  1167. AND claim_datetime &gt;= #{vo.startDate}
  1168. AND claim_datetime &lt;= #{vo.endDate}
  1169. UNION ALL
  1170. SELECT
  1171. allot_amount AS claim_amount,
  1172. order_fund_id,
  1173. production_fund_id,
  1174. created AS claim_datetime
  1175. FROM
  1176. order_fund_allot
  1177. WHERE
  1178. deleted = 0
  1179. AND created &gt;= #{vo.startDate}
  1180. AND created &lt;= #{vo.endDate}
  1181. ) fc
  1182. 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 )
  1183. 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
  1184. LEFT JOIN assets a ON a.id = ap.business_id
  1185. 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 (
  1186. cd.business_id = a.id
  1187. AND ( cd.production_id IS NULL OR cd.production_id = ap.id ))
  1188. LEFT JOIN business_commission_rate bcr ON bcr.id = cd.commission_rate_id
  1189. LEFT JOIN dict_data dd ON dd.id = bcr.business_cate_id
  1190. LEFT JOIN ( SELECT business_id, report_no, member_id, performance_distribution,declare_id FROM business_performance_distribution WHERE deleted = 0 AND user_type = '市场人员' ) bpd
  1191. 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 ))
  1192. LEFT JOIN user u on u.id = bpd.member_id
  1193. WHERE
  1194. bpd.member_id = #{vo.userId}
  1195. order by settleDate DESC
  1196. </select>
  1197. <!--资产市场人员提成合计导出-->
  1198. <select id="assetsMarketTotalAmountExport" resultType="com.dayou.vo.UserCommissionTotalAmountVO">
  1199. SELECT bpd.member_id as id,
  1200. u.name as userName,
  1201. ROUND(SUM((fc.claim_amount * (bcr.min_ratio / 100) * (bpd.performance_distribution / 100))),
  1202. 2) AS commissionTotalAmount,
  1203. '市场人员' as userType,
  1204. '资产业务' as businessType,
  1205. #{vo.startDate} as startDate,
  1206. #{vo.endDate} as endDate
  1207. FROM (SELECT claim_amount,
  1208. order_fund_id,
  1209. production_fund_id,
  1210. claim_datetime
  1211. FROM finance_claim
  1212. WHERE deleted = 0
  1213. AND production_fund_id IS NOT NULL
  1214. AND claim_datetime &gt;= #{vo.startDate}
  1215. AND claim_datetime &lt;= #{vo.endDate}
  1216. UNION ALL
  1217. SELECT allot_amount AS claim_amount, order_fund_id, production_fund_id, created AS claim_datetime
  1218. FROM order_fund_allot
  1219. WHERE deleted = 0
  1220. AND created &gt;= #{vo.startDate}
  1221. AND created &lt;= #{vo.endDate}) fc
  1222. INNER JOIN (SELECT id, order_fund_id, business_id, production_no
  1223. FROM production_fund
  1224. WHERE business_type = 'ASSET_BUSINESS'
  1225. AND deleted = 0) pf
  1226. ON (pf.id = fc.production_fund_id AND pf.order_fund_id = fc.order_fund_id)
  1227. INNER JOIN (SELECT id,
  1228. business_id,
  1229. assets_name,
  1230. production_no,
  1231. production_type,
  1232. save_file_date,
  1233. created
  1234. FROM assets_production
  1235. WHERE deleted = 0
  1236. AND delivery = true) ap ON ap.production_no = pf.production_no
  1237. LEFT JOIN assets a ON a.id = ap.business_id
  1238. INNER JOIN (SELECT id, business_id, production_id, commission_rate_id
  1239. FROM commission_declare
  1240. WHERE business_type = 'COMMISSION_DECLARE_ASSET_MARKET'
  1241. AND deleted = 0
  1242. AND declare_result = '审核通过') cd ON (
  1243. cd.business_id = a.id
  1244. AND (cd.production_id IS NULL OR cd.production_id = ap.id))
  1245. LEFT JOIN business_commission_rate bcr ON bcr.id = cd.commission_rate_id
  1246. LEFT JOIN dict_data dd ON dd.id = bcr.business_cate_id
  1247. LEFT JOIN (SELECT business_id, report_no, declare_id, member_id, performance_distribution
  1248. FROM business_performance_distribution
  1249. WHERE deleted = 0
  1250. AND user_type = '市场人员') bpd ON (bpd.business_id = a.id AND cd.id = bpd.declare_id AND
  1251. (bpd.report_no is null or bpd.report_no = ap.production_no))
  1252. LEFT JOIN user u ON u.id = bpd.member_id
  1253. GROUP BY bpd.member_id
  1254. ORDER BY commissionTotalAmount DESC
  1255. </select>
  1256. <!--资产市场人员提成信息导出-->
  1257. <select id="assetsMarketUserDetailExport" resultType="com.dayou.vo.UserCommissionProdVO">
  1258. SELECT
  1259. ap.id,
  1260. ROUND(fc.claim_amount,2) as realAmount,
  1261. ap.production_no AS reportNo,
  1262. IF
  1263. ( fc.claim_datetime > ap.save_file_date, fc.claim_datetime, ap.save_file_date ) AS settleDate,
  1264. ap.assets_name AS name,
  1265. ap.created,
  1266. dd.`name` AS businessCate,
  1267. ROUND(bcr.min_ratio,2) AS ratio,
  1268. bpd.member_id AS userId,
  1269. ROUND(bpd.performance_distribution,2) AS allotRatio,
  1270. ROUND(( fc.claim_amount * ( bcr.min_ratio / 100 ) * (bpd.performance_distribution / 100) ),2) AS
  1271. commissionAmount,
  1272. ROUND(( fc.claim_amount * ( bcr.min_ratio / 100 ) ),2) AS totalAmount,
  1273. u.name as userName
  1274. FROM
  1275. (
  1276. SELECT
  1277. claim_amount,
  1278. order_fund_id,
  1279. production_fund_id,
  1280. claim_datetime
  1281. FROM
  1282. finance_claim
  1283. WHERE
  1284. deleted = 0
  1285. AND production_fund_id IS NOT NULL
  1286. AND claim_datetime &gt;= #{vo.startDate}
  1287. AND claim_datetime &lt;= #{vo.endDate}
  1288. UNION ALL
  1289. SELECT
  1290. allot_amount AS claim_amount,
  1291. order_fund_id,
  1292. production_fund_id,
  1293. created AS claim_datetime
  1294. FROM
  1295. order_fund_allot
  1296. WHERE
  1297. deleted = 0
  1298. AND created &gt;= #{vo.startDate}
  1299. AND created &lt;= #{vo.endDate}
  1300. ) fc
  1301. INNER JOIN ( SELECT id, order_fund_id, business_id, production_no FROM production_fund WHERE business_type =
  1302. 'ASSET_BUSINESS' AND deleted = 0 ) pf ON ( pf.id = fc.production_fund_id AND pf.order_fund_id = fc.order_fund_id
  1303. )
  1304. INNER JOIN ( SELECT id, business_id, assets_name, production_no, production_type, save_file_date, created FROM
  1305. assets_production WHERE deleted = 0 AND delivery = true ) ap ON ap.production_no = pf.production_no
  1306. LEFT JOIN assets a ON a.id = ap.business_id
  1307. INNER JOIN ( SELECT id, business_id, production_id, commission_rate_id FROM commission_declare WHERE
  1308. business_type = 'COMMISSION_DECLARE_ASSET_MARKET' AND deleted = 0 AND declare_result = '审核通过' ) cd ON (
  1309. cd.business_id = a.id
  1310. AND ( cd.production_id IS NULL OR cd.production_id = ap.id ))
  1311. LEFT JOIN business_commission_rate bcr ON bcr.id = cd.commission_rate_id
  1312. LEFT JOIN dict_data dd ON dd.id = bcr.business_cate_id
  1313. LEFT JOIN ( SELECT business_id, report_no, member_id, performance_distribution, declare_id FROM
  1314. business_performance_distribution WHERE deleted = 0 AND user_type = '市场人员' ) bpd
  1315. ON ( bpd.business_id = a.id AND cd.id = bpd.declare_id AND (bpd.report_no is null or bpd.report_no =
  1316. ap.production_no ))
  1317. LEFT JOIN user u on u.id = bpd.member_id
  1318. <where>
  1319. <if test="vo!=null and vo.userId!=null">
  1320. and bpd.member_id = #{vo.userId}
  1321. </if>
  1322. </where>
  1323. order by bpd.member_id
  1324. </select>
  1325. <!--资产收款逾期查询Sql-->
  1326. <sql id="assetsOverdueSql">
  1327. SELECT
  1328. DATEDIFF(CURDATE(), DATE( ap.repertory_out_time )) AS overdueDay,
  1329. a.allot_type,
  1330. a.order_id,
  1331. a.assets_business_gener,
  1332. u.name AS clientManager,
  1333. u1.name AS principal,
  1334. cc1.name AS clientName,
  1335. cc2.name AS clientSubName,
  1336. pf.production_should_amount,
  1337. `of`.should_amount,
  1338. pf.standard_amount,
  1339. ap.*
  1340. FROM
  1341. (
  1342. SELECT
  1343. id,
  1344. business_id,
  1345. production_no,
  1346. ( CASE production_type WHEN 'STATEMENT' THEN '意见书' WHEN 'REPORT' THEN '评估报告' WHEN 'LETTER' THEN '意见函' WHEN 'CONSULT' THEN '咨询报告' ELSE '' END ) productionType,
  1347. assets_name,
  1348. evaluate_amount,
  1349. repertory_out_time
  1350. FROM
  1351. assets_production ap
  1352. WHERE
  1353. deleted = 0
  1354. AND repertory_out_time IS NOT NULL
  1355. AND production_type != 'STATEMENT'
  1356. ) ap
  1357. 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
  1358. ON ( ap.business_id = pf.business_id AND ap.production_no = pf.production_no )
  1359. 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
  1360. LEFT JOIN assets a ON a.id = ap.business_id
  1361. LEFT JOIN user u ON u.id = a.client_manager_id
  1362. LEFT JOIN user u1 ON u1.id = a.principal_id
  1363. LEFT JOIN customer_company cc1 ON cc1.id = a.clientele_id
  1364. LEFT JOIN customer_company cc2 ON cc2.id = a.clientele_sub_id
  1365. WHERE
  1366. ap.productionType != 'STATEMENT'
  1367. AND ( pf.production_no IS NULL OR pf.real_amount IS NULL )
  1368. AND DATEDIFF(CURDATE(),DATE( ap.repertory_out_time )) &gt;= #{overdueVO.overdueMin}
  1369. <if test="overdueVO!=null and overdueVO.overdueMax!=null">
  1370. AND DATEDIFF(CURDATE(),DATE( ap.repertory_out_time )) &lt;= #{overdueVO.overdueMax}
  1371. </if>
  1372. <if test="overdueVO!=null and overdueVO.orderId!=null and overdueVO.orderId!=''">
  1373. and a.order_id = #{overdueVO.orderId}
  1374. </if>
  1375. <if test="overdueVO!=null and overdueVO.productionNo!=null and overdueVO.productionNo!=''">
  1376. and ap.production_no like concat ('%',#{overdueVO.productionNo},'%')
  1377. </if>
  1378. <if test="overdueVO!=null and overdueVO.principal!=null and overdueVO.principal!=''">
  1379. and u1.name like concat ('%',#{overdueVO.principal},'%')
  1380. </if>
  1381. order by overdueDay desc
  1382. </sql>
  1383. <!--资产收款逾期列表-->
  1384. <select id="overdueAssets" resultType="com.dayou.vo.AssetsProdOverdueVO">
  1385. <include refid="assetsOverdueSql" />
  1386. </select>
  1387. <!--资产收款逾期列表导出-->
  1388. <select id="overdueAssetsExport" resultType="com.dayou.vo.AssetsProdOverdueVO">
  1389. <include refid="assetsOverdueSql" />
  1390. </select>
  1391. <resultMap id="settleAssetsProductionVOMap" type="com.dayou.vo.SettleAssetsProductionVO">
  1392. <id property="id" column="id" />
  1393. <result property="id" column="id" />
  1394. <result property="claimAmount" column="claim_amount" />
  1395. <result property="orderId" column="order_id" />
  1396. <result property="productionNo" column="production_no" />
  1397. <result property="claimDate" column="claimDate" />
  1398. <result property="saveFileDate" column="save_file_date" />
  1399. <result property="settleDate" column="settleDate" />
  1400. <result property="deliveryDate" column="deliveryDate" />
  1401. <result property="projectName" column="projectName" />
  1402. <result property="bailor" column="bailor" />
  1403. <result property="evaluateAmount" column="evaluate_amount" />
  1404. <result property="principal" column="principal" />
  1405. <result property="clientManager" column="clientManager" />
  1406. <result property="clientName" column="clientName" />
  1407. <result property="clientSubName" column="clientSubName" />
  1408. <result property="evaluateDepartmentName" column="evaluateDepartmentName" />
  1409. <result property="marketDepartmentName" column="marketDepartmentName" />
  1410. <collection property="invoices" ofType="com.dayou.vo.SettleProInvoiceVo">
  1411. <result property="invoiceDate" column="invoiceDate" />
  1412. <result property="invoiceUser" column="invoiceUser" />
  1413. <result property="invoiceNo" column="invoiceNo" />
  1414. </collection>
  1415. </resultMap>
  1416. <!--资产市场人员结算项目Sql-->
  1417. <sql id="assetsMarketerSettleSql">
  1418. SELECT
  1419. ap.id,
  1420. fc.claim_amount,
  1421. a.order_id,
  1422. ap.production_no,
  1423. fc.claim_datetime as claimDate,
  1424. ap.delivery_date AS deliveryDate,
  1425. ap.save_file_date,
  1426. IF
  1427. ( fc.claim_datetime > ap.delivery_date, fc.claim_datetime, ap.delivery_date ) AS settleDate,
  1428. ap.assets_name AS projectName,
  1429. a.bailor,
  1430. ap.evaluate_amount,
  1431. u.name AS principal,
  1432. u1.name AS clientManager,
  1433. cc.name AS clientName,
  1434. cc1.name AS clientSubName,
  1435. d.name AS evaluateDepartmentName,
  1436. (
  1437. SELECT
  1438. GROUP_CONCAT( department.name )
  1439. FROM
  1440. department
  1441. WHERE
  1442. id IN (
  1443. SELECT
  1444. department_id
  1445. FROM
  1446. post
  1447. WHERE
  1448. id IN ( SELECT post_id FROM user_post WHERE user_id = a.client_manager_id ))) AS marketDepartmentName,
  1449. invoice.name AS invoiceUser,
  1450. invoice.real_make_date AS invoiceDate,
  1451. invoice.tax_no AS invoiceNo
  1452. FROM
  1453. (
  1454. SELECT
  1455. claim_amount,
  1456. order_fund_id,
  1457. production_fund_id,
  1458. claim_datetime
  1459. FROM
  1460. finance_claim
  1461. WHERE
  1462. deleted = 0
  1463. AND production_fund_id IS NOT NULL
  1464. AND claim_datetime &gt;= #{settleVO.startDate}
  1465. AND claim_datetime &lt;= #{settleVO.endDate} UNION ALL
  1466. SELECT allot_amount AS claim_amount, order_fund_id, production_fund_id, created AS claim_datetime FROM
  1467. order_fund_allot WHERE deleted = 0
  1468. AND created &gt;= #{settleVO.startDate}
  1469. AND created &lt;= #{settleVO.endDate}
  1470. ) fc
  1471. INNER JOIN ( SELECT id, order_fund_id, business_id, production_no FROM production_fund WHERE business_type =
  1472. 'ASSET_BUSINESS' AND deleted = 0 ) pf ON ( pf.id = fc.production_fund_id AND pf.order_fund_id = fc.order_fund_id
  1473. )
  1474. INNER JOIN ( SELECT id, business_id, assets_name, production_no, production_type, evaluate_amount,
  1475. delivery_date, save_file_date FROM assets_production WHERE deleted = 0 AND delivery = true ) ap ON ap.production_no =
  1476. pf.production_no
  1477. LEFT JOIN assets a ON a.id = ap.business_id
  1478. LEFT JOIN user u ON u.id = a.principal_id
  1479. LEFT JOIN user u1 ON u1.id = a.client_manager_id
  1480. LEFT JOIN customer_company cc ON cc.id = a.clientele_id
  1481. LEFT JOIN customer_company cc1 ON cc1.id = a.clientele_sub_id
  1482. LEFT JOIN department d ON d.id = a.department_id
  1483. LEFT JOIN (
  1484. SELECT real_make_date, name, tax_no, order_fund_id, production_fund_id
  1485. FROM finance_invoice, user
  1486. WHERE maker_id = user.id
  1487. AND finance_invoice.deleted = 0
  1488. AND state = '已开票'
  1489. ) 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)
  1490. <where>
  1491. <if test="settleVO!=null and settleVO.orderId!=null and settleVO.orderId!='' ">
  1492. and a.order_id = #{settleVO.orderId}
  1493. </if>
  1494. <if test="settleVO!=null and settleVO.productionNo!=null and settleVO.productionNo!='' ">
  1495. and ap.report_no like concat ('%',#{settleVO.productionNo},'%')
  1496. </if>
  1497. <if test="settleVO!=null and settleVO.principal!=null and settleVO.principal!='' ">
  1498. and u.name like concat ('%',#{settleVO.principal},'%')
  1499. </if>
  1500. <if test="settleVO!=null and settleVO.clientManager!=null and settleVO.clientManager!='' ">
  1501. and u1.name like concat ('%',#{settleVO.clientManager},'%')
  1502. </if>
  1503. </where>
  1504. order by settleDate DESC
  1505. </sql>
  1506. <!--资产结算项目查询-->
  1507. <select id="assetsMarketSettleProd" resultMap="settleAssetsProductionVOMap">
  1508. <include refid="assetsMarketerSettleSql" />
  1509. </select>
  1510. <!--资产结算项目导出-->
  1511. <select id="assetsMarketSettleExport" resultMap="settleAssetsProductionVOMap">
  1512. <include refid="assetsMarketerSettleSql" />
  1513. </select>
  1514. <!--资产评估人员结算项目Sql-->
  1515. <sql id="assetsEvaluatorSettleSql">
  1516. SELECT
  1517. ap.id,
  1518. fc.claim_amount,
  1519. a.order_id,
  1520. ap.production_no,
  1521. fc.claim_datetime as claimDate,
  1522. ap.save_file_date,
  1523. IF( fc.claim_datetime > ap.save_file_date, fc.claim_datetime, ap.save_file_date ) AS settleDate,
  1524. ap.assets_name AS projectName,
  1525. a.bailor,
  1526. ap.evaluate_amount,
  1527. u.name AS principal,
  1528. u1.name AS clientManager,
  1529. cc.name AS clientName,
  1530. cc1.name AS clientSubName,
  1531. d.name AS evaluateDepartmentName,
  1532. (
  1533. SELECT
  1534. GROUP_CONCAT( NAME )
  1535. FROM
  1536. department
  1537. WHERE
  1538. id IN (
  1539. SELECT
  1540. department_id
  1541. FROM
  1542. post
  1543. WHERE
  1544. id IN ( SELECT post_id FROM user_post WHERE user_id = a.client_manager_id ))) AS marketDepartmentName,
  1545. invoice.name AS invoiceUser,
  1546. invoice.real_make_date AS invoiceDate,
  1547. invoice.tax_no AS invoiceNo
  1548. FROM
  1549. (
  1550. SELECT
  1551. claim_amount,
  1552. order_fund_id,
  1553. production_fund_id,
  1554. claim_datetime
  1555. FROM
  1556. finance_claim
  1557. WHERE
  1558. deleted = 0
  1559. AND production_fund_id IS NOT NULL
  1560. AND claim_datetime &gt;= #{settleVO.startDate}
  1561. AND claim_datetime &lt;= #{settleVO.endDate} UNION ALL
  1562. SELECT allot_amount AS claim_amount, order_fund_id, production_fund_id, created AS claim_datetime FROM order_fund_allot WHERE deleted = 0
  1563. AND created &gt;= #{settleVO.startDate}
  1564. AND created &lt;= #{settleVO.endDate}
  1565. ) fc
  1566. 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 )
  1567. 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
  1568. LEFT JOIN assets a ON a.id = ap.business_id
  1569. LEFT JOIN user u ON u.id = a.principal_id
  1570. LEFT JOIN user u1 ON u1.id = a.client_manager_id
  1571. LEFT JOIN customer_company cc ON cc.id = a.clientele_id
  1572. LEFT JOIN customer_company cc1 ON cc1.id = a.clientele_sub_id
  1573. LEFT JOIN department d ON d.id = a.department_id
  1574. LEFT JOIN (
  1575. SELECT real_make_date, name, tax_no, order_fund_id, production_fund_id
  1576. FROM finance_invoice, user
  1577. WHERE maker_id = user.id
  1578. AND finance_invoice.deleted = 0
  1579. AND state = '已开票'
  1580. ) 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)
  1581. <where>
  1582. <if test="settleVO!=null and settleVO.orderId!=null and settleVO.orderId!='' ">
  1583. and a.order_id = #{settleVO.orderId}
  1584. </if>
  1585. <if test="settleVO!=null and settleVO.productionNo!=null and settleVO.productionNo!='' ">
  1586. and ap.production_no like concat ('%',#{settleVO.productionNo},'%')
  1587. </if>
  1588. <if test="settleVO!=null and settleVO.principal!=null and settleVO.principal!='' ">
  1589. and u.name like concat ('%',#{settleVO.principal},'%')
  1590. </if>
  1591. <if test="settleVO!=null and settleVO.clientManager!=null and settleVO.clientManager!='' ">
  1592. and u1.name like concat ('%',#{settleVO.clientManager},'%')
  1593. </if>
  1594. </where>
  1595. order by settleDate DESC
  1596. </sql>
  1597. <!--资产评估人员结算项目查询-->
  1598. <select id="assetsEvaluatorSettleProd" resultMap="settleAssetsProductionVOMap">
  1599. <include refid="assetsEvaluatorSettleSql" />
  1600. </select>
  1601. <!--资产评估人员结算项目导出-->
  1602. <select id="assetsEvaluatorSettleExport" resultMap="settleAssetsProductionVOMap">
  1603. <include refid="assetsEvaluatorSettleSql" />
  1604. </select>
  1605. </mapper>