FinanceRealFundMapper.xml 81 KB

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