12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658 |
- <?xml version="1.0" encoding="UTF-8"?>
- <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
- <mapper namespace="com.dayou.mapper.FinanceRealFundMapper">
- <!-- 通用查询映射结果 -->
- <resultMap id="BaseResultMap" type="com.dayou.entity.FinanceRealFund">
- <result column="id" property="id" />
- <result column="deleted" property="deleted" />
- <result column="modified" property="modified" />
- <result column="created" property="created" />
- <result column="payer" property="payer" />
- <result column="payer_bank" property="payerBank" />
- <result column="payer_account" property="payerAccount" />
- <result column="amount" property="amount" />
- <result column="pay_datetime" property="payDatetime" />
- <result column="remark" property="remark" />
- <result column="creator_id" property="creatorId" />
- </resultMap>
- <!-- 通用查询结果列 -->
- <sql id="Base_Column_List">
- id,
- deleted,
- modified,
- created,
- payer, payer_bank, payer_account, amount, pay_datetime, remark, creator_id
- </sql>
- <select id="getPage" parameterType="com.dayou.entity.FinanceRealFund" resultType="com.dayou.vo.FinanceRealFundVO">
- SELECT
- frf.id,
- frf.created,
- frf.payer,
- frf.payer_bank,
- frf.payer_account,
- frf.amount,
- frf.pay_datetime,
- frf.remark,
- frf.creator_id,
- u.name AS creator,
- ifnull(t.ca,0) AS claimAmount,
- ( frf.amount - ifnull(t.ca,0) ) AS notClaimAmount
- FROM
- finance_real_fund frf
- LEFT JOIN user u ON u.id = frf.creator_id
- 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
- WHERE
- frf.deleted = 0
- <if test="vo!=null and vo.notFinished">
- and ifnull(t.ca,0) < frf.amount
- </if>
- <if test="vo!=null and !vo.notFinished">
- and ifnull(t.ca,0) >= frf.amount
- </if>
- <if test="keyword!=null and keyword!='' ">
- and (
- frf.payer like concat ('%',#{keyword},'%')
- or frf.payer_bank like concat('%',#{keyword},'%')
- or u.name like concat('%',#{keyword},'%')
- or frf.payer_account like concat('%',#{keyword},'%')
- or frf.amount like concat('%',#{keyword},'%')
- or frf.remark like concat('%',#{keyword},'%')
- )
- </if>
- <if test="vo!=null and vo.startDate!=null and vo.startDate!=''">
- and frf.pay_datetime >= #{vo.startDate}
- </if>
- <if test="vo!=null and vo.endDate!=null and vo.endDate!=''">
- and frf.pay_datetime <= #{vo.endDate}
- </if>
- <if test="vo!=null and vo.xStartDate!=null and vo.xStartDate!=''">
- and frf.created >= #{vo.xStartDate}
- </if>
- <if test="vo!=null and vo.xEndDate!=null and vo.xEndDate!=''">
- and frf.created <= #{vo.xEndDate}
- </if>
- ORDER BY
- ifnull(t.ca,0) ASC ,frf.created DESC
- </select>
- <select id="getNotClaimAmount" parameterType="java.lang.Long" resultType="java.math.BigDecimal">
- SELECT ( frf.amount -( SELECT ifnull( sum( claim_amount ), 0 ) AS ca FROM finance_claim WHERE deleted = 0 AND real_fund_id = #{realFundId} )
- ) AS notClaimAmount
- FROM
- finance_real_fund frf
- WHERE
- frf.id = #{realFundId}
- AND frf.deleted = 0
- </select>
- <sql id="majorOverdueSql">
- SELECT
- DATEDIFF(
- CURDATE(),
- DATE( mp.repertory_out_time )) AS overdueDay,
- m.allot_type,
- m.order_id,
- m.business_object_type,
- u.NAME AS clientManager,
- u1.NAME AS principal,
- cc1.NAME AS clientName,
- cc2.NAME AS clientSubName,
- pf.production_should_amount,
- ofu.should_amount,
- mp.*
- FROM
- (
- SELECT
- id,
- major_id,
- report_no,
- ( CASE production WHEN 'STATEMENT' THEN '意见书' WHEN 'REPORT' THEN '报告' WHEN 'LETTER' THEN '复评函' ELSE '' END ) production,
- NAME,
- evaluate_amount,
- repertory_out_time,
- standard_amount
- FROM
- major_production mp
- WHERE
- deleted = 0
- AND repertory_out_time IS NOT NULL and production != 'STATEMENT'
- ) mp
- 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 )
- 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
- LEFT JOIN major m ON m.id = mp.major_id
- LEFT JOIN user u ON u.id = m.client_manager_id
- LEFT JOIN user u1 ON u1.id = m.principal_id
- LEFT JOIN customer_company cc1 ON cc1.id = m.clientele_id
- LEFT JOIN customer_company cc2 ON cc2.id = m.clientele_sub_id
- WHERE
- mp.production != 'STATEMENT'
- AND ( pf.production_no IS NULL OR pf.real_amount IS NULL )
- AND DATEDIFF(CURDATE(),DATE( mp.repertory_out_time )) >= #{overdueVO.overdueMin}
- <if test="overdueVO!=null and overdueVO.overdueMax!=null">
- AND DATEDIFF(CURDATE(),DATE( mp.repertory_out_time )) <= #{overdueVO.overdueMax}
- </if>
- <if test="overdueVO!=null and overdueVO.orderId!=null and overdueVO.orderId!=''">
- and m.order_id = #{overdueVO.orderId}
- </if>
- <if test="overdueVO!=null and overdueVO.reportNo!=null and overdueVO.reportNo!=''">
- and mp.report_no like concat ('%',#{overdueVO.reportNo},'%')
- </if>
- <if test="overdueVO!=null and overdueVO.principal!=null and overdueVO.principal!=''">
- and u1.NAME like concat ('%',#{overdueVO.principal},'%')
- </if>
- order by overdueDay desc
- </sql>
- <select id="overdueMajor" parameterType="com.dayou.vo.MajorProdOverdueVO" resultType="com.dayou.vo.MajorProdOverdueVO">
- <include refid="majorOverdueSql" />
- </select>
- <select id="overdueMajorExport" parameterType="com.dayou.vo.MajorProdOverdueVO" resultType="com.dayou.vo.MajorProdOverdueVO">
- <include refid="majorOverdueSql" />
- </select>
- <resultMap id="settleeMajorProductionVOMap" type="com.dayou.vo.SettleMajorProductionVO">
- <id property="id" column="id" />
- <result property="id" column="id" />
- <result property="claimAmount" column="claim_amount" />
- <result property="orderId" column="order_id" />
- <result property="reportNo" column="report_no" />
- <result property="claimDate" column="claimDate" />
- <result property="saveFileDate" column="save_file_date" />
- <result property="settleDate" column="settleDate" />
- <result property="deliveryDate" column="deliveryDate" />
- <result property="name" column="name" />
- <result property="bailor" column="bailor" />
- <result property="evaluateAmount" column="evaluate_amount" />
- <result property="principal" column="principal" />
- <result property="clientManager" column="clientManager" />
- <result property="clientName" column="clientName" />
- <result property="clientSubName" column="clientSubName" />
- <result property="evaluateDepartmentName" column="evaluateDepartmentName" />
- <result property="marketDepartmentName" column="marketDepartmentName" />
- <collection property="invoices" ofType="com.dayou.vo.SettleProInvoiceVo">
- <result property="invoiceDate" column="invoiceDate" />
- <result property="invoiceUser" column="invoiceUser" />
- <result property="invoiceNo" column="invoiceNo" />
- </collection>
- </resultMap>
- <sql id="majorEvaluatorSettleSql">
- SELECT
- mp.id,
- fc.claim_amount,
- m.order_id,
- mp.report_no,
- fc.claim_datetime as claimDate,
- mp.save_file_date,
- IF
- ( fc.claim_datetime > mp.save_file_date, fc.claim_datetime, mp.save_file_date ) AS settleDate,
- mp.name,
- m.bailor,
- mp.evaluate_amount,
- u.name AS principal,
- u1.name AS clientManager,
- cc.name AS clientName,
- cc1.name AS clientSubName,
- d.name AS evaluateDepartmentName,
- (
- SELECT
- GROUP_CONCAT( name )
- FROM
- department
- WHERE
- id IN (
- SELECT
- department_id
- FROM
- post
- WHERE
- id IN ( SELECT post_id FROM user_post WHERE user_id = m.client_manager_id ))) AS marketDepartmentName,
- invoice.name AS invoiceUser,
- invoice.real_make_date AS invoiceDate,
- invoice.tax_no AS invoiceNo
- FROM
- (
- SELECT
- claim_amount,
- order_fund_id,
- production_fund_id,
- claim_datetime
- FROM
- finance_claim
- WHERE
- deleted = 0
- AND production_fund_id IS NOT NULL
- AND claim_datetime >= #{settleVO.startDate}
- AND claim_datetime <= #{settleVO.endDate} 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
- AND created >= #{settleVO.startDate}
- AND created <= #{settleVO.endDate}
- ) fc
- 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 )
- 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
- LEFT JOIN major m ON m.id = mp.major_id
- LEFT JOIN user u ON u.id = m.principal_id
- LEFT JOIN user u1 ON u1.id = m.client_manager_id
- LEFT JOIN customer_company cc ON cc.id = m.clientele_id
- LEFT JOIN customer_company cc1 ON cc1.id = m.clientele_sub_id
- LEFT JOIN department d ON d.id = m.department_id
- LEFT JOIN (
- SELECT real_make_date, name, tax_no, order_fund_id, production_fund_id
- FROM finance_invoice, user
- WHERE maker_id = user.id
- AND finance_invoice.deleted = 0
- AND state = '已开票'
- ) 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)
- <where>
- <if test="settleVO!=null and settleVO.orderId!=null and settleVO.orderId!='' ">
- and m.order_id = #{settleVO.orderId}
- </if>
- <if test="settleVO!=null and settleVO.reportNo!=null and settleVO.reportNo!='' ">
- and mp.report_no like concat ('%',#{settleVO.reportNo},'%')
- </if>
- <if test="settleVO!=null and settleVO.principal!=null and settleVO.principal!='' ">
- and u.name like concat ('%',#{settleVO.principal},'%')
- </if>
- <if test="settleVO!=null and settleVO.clientManager!=null and settleVO.clientManager!='' ">
- and u1.name like concat ('%',#{settleVO.clientManager},'%')
- </if>
- </where>
- order by settleDate DESC
- </sql>
- <select id="majorEvaluatorSettleProd" parameterType="com.dayou.vo.SettleMajorProductionVO" resultMap="settleeMajorProductionVOMap">
- <include refid="majorEvaluatorSettleSql" />
- </select>
- <select id="majorEvaluatorSettleExport" parameterType="com.dayou.vo.SettleMajorProductionVO" resultMap="settleeMajorProductionVOMap">
- <include refid="majorEvaluatorSettleSql" />
- </select>
- <sql id="majorMarketerSettleSql">
- SELECT
- mp.id,
- fc.claim_amount,
- m.order_id,
- mp.report_no,
- fc.claim_datetime,
- mp.delivery_date,
- IF
- ( fc.claim_datetime > mp.delivery_date, fc.claim_datetime, mp.delivery_date ) AS settleDate,
- mp.NAME,
- m.bailor,
- mp.evaluate_amount,
- u.NAME AS principal,
- u1.NAME AS clientManager,
- cc.NAME AS clientName,
- cc1.NAME AS clientSubName,
- d.NAME AS evaluateDepartmentName,
- (
- SELECT
- GROUP_CONCAT( NAME )
- FROM
- department
- WHERE
- id IN (
- SELECT
- department_id
- FROM
- post
- WHERE
- id IN ( SELECT post_id FROM user_post WHERE user_id = m.client_manager_id ))) AS marketDepartmentName,
- invoice.name AS invoiceUser,
- invoice.real_make_date AS invoiceDate,
- invoice.tax_no AS invoiceNo
- FROM
- (
- SELECT
- claim_amount,
- order_fund_id,
- production_fund_id,
- claim_datetime
- FROM
- finance_claim
- WHERE
- deleted = 0
- AND production_fund_id IS NOT NULL
- AND claim_datetime >= #{settleVO.startDate}
- AND claim_datetime <= #{settleVO.endDate} 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
- AND created >= #{settleVO.startDate}
- AND created <= #{settleVO.endDate}
- ) fc
- 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 )
- 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
- LEFT JOIN major m ON m.id = mp.major_id
- LEFT JOIN user u ON u.id = m.principal_id
- LEFT JOIN user u1 ON u1.id = m.client_manager_id
- LEFT JOIN customer_company cc ON cc.id = m.clientele_id
- LEFT JOIN customer_company cc1 ON cc1.id = m.clientele_sub_id
- LEFT JOIN department d ON d.id = m.department_id
- LEFT JOIN (
- SELECT real_make_date, name, tax_no, order_fund_id, production_fund_id
- FROM finance_invoice, user
- WHERE maker_id = user.id
- AND finance_invoice.deleted = 0
- AND state = '已开票'
- ) 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)
- <where>
- <if test="settleVO!=null and settleVO.orderId!=null and settleVO.orderId!='' ">
- and m.order_id = #{settleVO.orderId}
- </if>
- <if test="settleVO!=null and settleVO.reportNo!=null and settleVO.reportNo!='' ">
- and mp.report_no like concat ('%',#{settleVO.reportNo},'%')
- </if>
- <if test="settleVO!=null and settleVO.principal!=null and settleVO.principal!='' ">
- and u.name like concat ('%',#{settleVO.principal},'%')
- </if>
- <if test="settleVO!=null and settleVO.clientManager!=null and settleVO.clientManager!='' ">
- and u1.name like concat ('%',#{settleVO.clientManager},'%')
- </if>
- </where>
- order by settleDate DESC
- </sql>
- <select id="majorMarketerSettleProd" parameterType="com.dayou.vo.SettleMajorProductionVO" resultMap="settleeMajorProductionVOMap">
- <include refid="majorMarketerSettleSql" />
- </select>
- <select id="majorMarketSettleExport" parameterType="com.dayou.vo.SettleMajorProductionVO" resultMap="settleeMajorProductionVOMap">
- <include refid="majorMarketerSettleSql" />
- </select>
- <select id="majorEvaluatorCommission" parameterType="com.dayou.vo.UserCommissionTotalAmountVO" resultType="com.dayou.vo.UserCommissionTotalAmountVO">
- SELECT mpa.user_id as id, u.name as userName, sum(( fc.claim_amount * ( bcr.min_ratio / 100 )* mpa.ratio )) AS commissionTotalAmount
- FROM
- (
- SELECT
- claim_amount,
- order_fund_id,
- production_fund_id,
- claim_datetime
- FROM
- finance_claim
- WHERE
- deleted = 0
- AND production_fund_id IS NOT NULL
- AND claim_datetime >= #{vo.startDate}
- AND claim_datetime <= #{vo.endDate}
- 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
- AND created >= #{vo.startDate}
- AND created <= #{vo.endDate}
- ) fc
- 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 )
- 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
- LEFT JOIN major m ON m.id = mp.major_id
- 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 (
- cd.business_id = m.id
- AND ( cd.production_id IS NULL OR cd.production_id = mp.id ))
- LEFT JOIN business_commission_rate bcr ON bcr.id = cd.commission_rate_id
- LEFT JOIN dict_data dd ON dd.id = bcr.business_cate_id
- 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)
- LEFT JOIN user u ON u.id = mpa.user_id
- GROUP BY
- mpa.user_id
- having 1=1
- <if test="vo!=null and vo.userName!=null and vo.userName!=''">
- and u.name like concat ('%',#{vo.userName},'%')
- </if>
- order by commissionTotalAmount DESC
- </select>
- <select id="majorEvaluatorCommissionDetail" parameterType="com.dayou.vo.UserCommissionProdVO" resultType="com.dayou.vo.UserCommissionProdVO">
- SELECT
- mp.id,
- fc.claim_amount as realAmount,
- mp.report_no,
- IF
- ( fc.claim_datetime > mp.save_file_date, fc.claim_datetime, mp.save_file_date ) AS settleDate,
- mp.NAME,
- mp.created,
- dd.NAME AS businessCate,
- bcr.min_ratio AS ratio,
- mpa.user_id,
- mpa.ratio AS allotRatio,
- ( fc.claim_amount * ( bcr.min_ratio / 100 )* mpa.ratio ) AS commissionAmount,
- ( fc.claim_amount * ( bcr.min_ratio / 100 ) ) AS totalAmount,
- u.name as userName
- FROM
- (
- SELECT
- claim_amount,
- order_fund_id,
- production_fund_id,
- claim_datetime
- FROM
- finance_claim
- WHERE
- deleted = 0
- AND production_fund_id IS NOT NULL
- AND claim_datetime >= #{vo.startDate}
- AND claim_datetime <= #{vo.endDate}
- 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
- AND created >= #{vo.startDate}
- AND created <= #{vo.endDate}
- ) fc
- 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 )
- 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
- LEFT JOIN major m ON m.id = mp.major_id
- 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 (
- cd.business_id = m.id
- AND ( cd.production_id IS NULL OR cd.production_id = mp.id ))
- LEFT JOIN business_commission_rate bcr ON bcr.id = cd.commission_rate_id
- LEFT JOIN dict_data dd ON dd.id = bcr.business_cate_id
- 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)
- LEFT JOIN user u on u.id = mpa.user_id
- WHERE
- mpa.user_id = #{vo.userId}
- order by settleDate DESC
- </select>
- <select id="majorEvaluatorTotalAmountExport" parameterType="com.dayou.vo.UserCommissionTotalAmountVO" resultType="com.dayou.vo.UserCommissionTotalAmountVO">
- SELECT mpa.user_id as id, u.name as userName, ROUND(sum(( fc.claim_amount * ( bcr.min_ratio / 100 )* mpa.ratio )),2) AS commissionTotalAmount,
- '评估人员' as userType,
- '大中型业务' as businessType,
- #{vo.startDate} as startDate,
- #{vo.endDate} as endDate
- FROM
- (
- SELECT
- claim_amount,
- order_fund_id,
- production_fund_id,
- claim_datetime
- FROM
- finance_claim
- WHERE
- deleted = 0
- AND production_fund_id IS NOT NULL
- AND claim_datetime >= #{vo.startDate}
- AND claim_datetime <= #{vo.endDate}
- 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
- AND created >= #{vo.startDate}
- AND created <= #{vo.endDate}
- ) fc
- 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 )
- 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
- LEFT JOIN major m ON m.id = mp.major_id
- 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 (
- cd.business_id = m.id
- AND ( cd.production_id IS NULL OR cd.production_id = mp.id ))
- LEFT JOIN business_commission_rate bcr ON bcr.id = cd.commission_rate_id
- LEFT JOIN dict_data dd ON dd.id = bcr.business_cate_id
- 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)
- LEFT JOIN user u ON u.id = mpa.user_id
- GROUP BY
- mpa.user_id
- </select>
- <select id="evaluatorUserDetailExport" parameterType="com.dayou.vo.UserCommissionProdVO" resultType="com.dayou.vo.UserCommissionProdVO">
- SELECT
- mp.id,
- ROUND(fc.claim_amount,2) as realAmount,
- mp.report_no,
- IF
- ( fc.claim_datetime > mp.save_file_date, fc.claim_datetime, mp.save_file_date ) AS settleDate,
- mp.NAME,
- mp.created,
- dd.NAME AS businessCate,
- ROUND(bcr.min_ratio,2) AS ratio,
- mpa.user_id,
- ROUND(mpa.ratio*100,2) AS allotRatio,
- ROUND(( fc.claim_amount * ( bcr.min_ratio / 100 )* mpa.ratio ),2) AS commissionAmount,
- ROUND(( fc.claim_amount * ( bcr.min_ratio / 100 ) ),2) AS totalAmount,
- u.name as userName
- FROM
- (
- SELECT
- claim_amount,
- order_fund_id,
- production_fund_id,
- claim_datetime
- FROM
- finance_claim
- WHERE
- deleted = 0
- AND production_fund_id IS NOT NULL
- AND claim_datetime >= #{vo.startDate}
- AND claim_datetime <= #{vo.endDate}
- 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
- AND created >= #{vo.startDate}
- AND created <= #{vo.endDate}
- ) fc
- 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 )
- 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
- LEFT JOIN major m ON m.id = mp.major_id
- 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 (
- cd.business_id = m.id
- AND ( cd.production_id IS NULL OR cd.production_id = mp.id ))
- LEFT JOIN business_commission_rate bcr ON bcr.id = cd.commission_rate_id
- LEFT JOIN dict_data dd ON dd.id = bcr.business_cate_id
- 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)
- LEFT JOIN user u on u.id = mpa.user_id
- <where>
- <if test="vo!=null and vo.userId!=null">
- and mpa.user_id = #{vo.userId}
- </if>
- </where>
- order by mpa.user_id
- </select>
- <select id="majorMarketCommission" parameterType="com.dayou.vo.UserCommissionTotalAmountVO" resultType="com.dayou.vo.UserCommissionTotalAmountVO">
- SELECT mpa.user_id as id, u.name as userName, sum(( fc.claim_amount * ( bcr.min_ratio / 100 )* mpa.ratio )) AS commissionTotalAmount
- FROM
- (
- SELECT
- claim_amount,
- order_fund_id,
- production_fund_id,
- claim_datetime
- FROM
- finance_claim
- WHERE
- deleted = 0
- AND production_fund_id IS NOT NULL
- AND claim_datetime >= #{vo.startDate}
- AND claim_datetime <= #{vo.endDate}
- 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
- AND created >= #{vo.startDate}
- AND created <= #{vo.endDate}
- ) fc
- 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 )
- 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
- LEFT JOIN major m ON m.id = mp.major_id
- 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 (
- cd.business_id = m.id
- AND ( cd.production_id IS NULL OR cd.production_id = mp.id ))
- LEFT JOIN business_commission_rate bcr ON bcr.id = cd.commission_rate_id
- LEFT JOIN dict_data dd ON dd.id = bcr.business_cate_id
- LEFT JOIN ( SELECT major_id, major_production_id,declare_id, user_id, ratio 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 ))
- LEFT JOIN user u ON u.id = mpa.user_id
- GROUP BY
- mpa.user_id
- having 1=1
- <if test="vo!=null and vo.userName!=null and vo.userName!=''">
- and u.name like concat ('%',#{vo.userName},'%')
- </if>
- order by commissionTotalAmount DESC
- </select>
- <select id="majorMarketCommissionDetail" parameterType="com.dayou.vo.UserCommissionProdVO" resultType="com.dayou.vo.UserCommissionProdVO">
- SELECT
- mp.id,
- fc.claim_amount as realAmount,
- mp.report_no,
- IF
- ( fc.claim_datetime > mp.save_file_date, fc.claim_datetime, mp.save_file_date ) AS settleDate,
- mp.NAME,
- mp.created,
- dd.NAME AS businessCate,
- bcr.min_ratio AS ratio,
- mpa.user_id,
- mpa.ratio AS allotRatio,
- ( fc.claim_amount * ( bcr.min_ratio / 100 )* mpa.ratio ) AS commissionAmount,
- ( fc.claim_amount * ( bcr.min_ratio / 100 ) ) AS totalAmount,
- u.name as userName
- FROM
- (
- SELECT
- claim_amount,
- order_fund_id,
- production_fund_id,
- claim_datetime
- FROM
- finance_claim
- WHERE
- deleted = 0
- AND production_fund_id IS NOT NULL
- AND claim_datetime >= #{vo.startDate}
- AND claim_datetime <= #{vo.endDate}
- 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
- AND created >= #{vo.startDate}
- AND created <= #{vo.endDate}
- ) fc
- 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 )
- 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
- LEFT JOIN major m ON m.id = mp.major_id
- 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 (
- cd.business_id = m.id
- AND ( cd.production_id IS NULL OR cd.production_id = mp.id ))
- LEFT JOIN business_commission_rate bcr ON bcr.id = cd.commission_rate_id
- LEFT JOIN dict_data dd ON dd.id = bcr.business_cate_id
- 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 ))
- LEFT JOIN user u on u.id = mpa.user_id
- WHERE
- mpa.user_id = #{vo.userId}
- order by settleDate DESC
- </select>
- <select id="majorMarketTotalAmountExport" parameterType="com.dayou.vo.UserCommissionTotalAmountVO" resultType="com.dayou.vo.UserCommissionTotalAmountVO">
- SELECT mpa.user_id as id, u.name as userName, ROUND(sum(( fc.claim_amount * ( bcr.min_ratio / 100 )* mpa.ratio )),2) AS commissionTotalAmount,
- '市场人员' as userType,
- '大中型业务' as businessType,
- #{vo.startDate} as startDate,
- #{vo.endDate} as endDate
- FROM
- (
- SELECT
- claim_amount,
- order_fund_id,
- production_fund_id,
- claim_datetime
- FROM
- finance_claim
- WHERE
- deleted = 0
- AND production_fund_id IS NOT NULL
- AND claim_datetime >= #{vo.startDate}
- AND claim_datetime <= #{vo.endDate}
- 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
- AND created >= #{vo.startDate}
- AND created <= #{vo.endDate}
- ) fc
- 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 )
- 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
- LEFT JOIN major m ON m.id = mp.major_id
- 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 (
- cd.business_id = m.id
- AND ( cd.production_id IS NULL OR cd.production_id = mp.id ))
- LEFT JOIN business_commission_rate bcr ON bcr.id = cd.commission_rate_id
- LEFT JOIN dict_data dd ON dd.id = bcr.business_cate_id
- LEFT JOIN ( SELECT major_id, major_production_id,declare_id, user_id, ratio 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 ))
- LEFT JOIN user u ON u.id = mpa.user_id
- GROUP BY
- mpa.user_id
- order by commissionTotalAmount DESC
- </select>
- <select id="marketUserDetailExport" parameterType="com.dayou.vo.UserCommissionProdVO" resultType="com.dayou.vo.UserCommissionProdVO">
- SELECT
- mp.id,
- ROUND(fc.claim_amount,2) as realAmount,
- mp.report_no,
- IF
- ( fc.claim_datetime > mp.save_file_date, fc.claim_datetime, mp.save_file_date ) AS settleDate,
- mp.NAME,
- mp.created,
- dd.NAME AS businessCate,
- ROUND(bcr.min_ratio,2) AS ratio,
- mpa.user_id,
- ROUND(mpa.ratio*100,2) AS allotRatio,
- ROUND(( fc.claim_amount * ( bcr.min_ratio / 100 )* mpa.ratio ),2) AS commissionAmount,
- ROUND(( fc.claim_amount * ( bcr.min_ratio / 100 ) ),2) AS totalAmount,
- u.name as userName
- FROM
- (
- SELECT
- claim_amount,
- order_fund_id,
- production_fund_id,
- claim_datetime
- FROM
- finance_claim
- WHERE
- deleted = 0
- AND production_fund_id IS NOT NULL
- AND claim_datetime >= #{vo.startDate}
- AND claim_datetime <= #{vo.endDate}
- 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
- AND created >= #{vo.startDate}
- AND created <= #{vo.endDate}
- ) fc
- 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 )
- 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
- LEFT JOIN major m ON m.id = mp.major_id
- 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 (
- cd.business_id = m.id
- AND ( cd.production_id IS NULL OR cd.production_id = mp.id ))
- LEFT JOIN business_commission_rate bcr ON bcr.id = cd.commission_rate_id
- LEFT JOIN dict_data dd ON dd.id = bcr.business_cate_id
- 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 ))
- LEFT JOIN user u on u.id = mpa.user_id
- <where>
- <if test="vo!=null and vo.userId!=null">
- and mpa.user_id = #{vo.userId}
- </if>
- </where>
- order by mpa.user_id
- </select>
- <sql id="personalOverdueSql">
- SELECT
- DATEDIFF(
- CURDATE(),
- DATE ( pp.rot )) AS overdueDay,
- p.*,
- pt.acreage,
- pt.price,
- pt.amount,
- cc1.NAME AS clientName,
- cc2.NAME AS clientSubName,
- cl1.NAME AS contactName,
- cl1.mobile AS contactTel,
- u.NAME AS clientManager,
- u1.NAME AS outwardStaffName,
- u2.NAME AS inwardStaffName,
- u3.NAME AS pricingStaffName,
- pp.rot
- FROM
- (
- SELECT
- id,
- location,
- order_id,
- agent,
- bailorA,
- bailorB,
- clientele_id,
- clientele_sub_id,
- clientele_contact_id,
- client_manager_id,
- outward_staff,
- inward_staff,
- pricing_staff
- FROM
- personal
- WHERE
- deleted = 0
- ) p
- LEFT JOIN personal_target pt ON pt.personal_id = p.id
- 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
- 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
- LEFT JOIN customer_company cc1 ON cc1.id = p.clientele_id
- LEFT JOIN customer_company cc2 ON cc2.id = p.clientele_sub_id
- LEFT JOIN customer_linkman cl1 ON cl1.id = p.clientele_contact_id
- LEFT JOIN `user` u ON u.id = p.client_manager_id
- LEFT JOIN `user` u1 ON u1.id = p.outward_staff
- LEFT JOIN `user` u2 ON u2.id = p.inward_staff
- LEFT JOIN `user` u3 ON u3.id = p.pricing_staff
- WHERE
- DATEDIFF(
- CURDATE(),
- DATE ( pp.rot )) >= #{overdueVO.overdueMin}
- <if test="overdueVO!=null and overdueVO.overdueMax!=null">
- AND DATEDIFF(CURDATE(),DATE( pp.rot )) <= #{overdueVO.overdueMax}
- </if>
- <if test="overdueVO!=null and overdueVO.orderId!=null and overdueVO.orderId!=''">
- and m.order_id = #{overdueVO.orderId}
- </if>
- ORDER BY
- overdueDay DESC
- </sql>
- <select id="overduePersonal" parameterType="com.dayou.vo.PersonalOverdueVO" resultType="com.dayou.vo.PersonalOverdueVO">
- <include refid="personalOverdueSql" />
- </select>
- <select id="overduePersonalList" parameterType="com.dayou.vo.PersonalOverdueVO" resultType="com.dayou.vo.PersonalOverdueVO">
- <include refid="personalOverdueSql" />
- </select>
- <!--资产评估人员提成计算-->
- <select id="assetsEvaluatorCommission" resultType="com.dayou.vo.UserCommissionTotalAmountVO">
- SELECT bpd.member_id as id,
- u.name as userName,
- SUM(IF(cd.defined_low_limit_amount < fc.claim_amount,
- fc.claim_amount * (cd.ratio / 100) * (bpd.performance_distribution / 100),
- cd.defined_low_limit_amount * (cd.ratio / 100) * (bpd.performance_distribution / 100)
- )) AS allCommissionTotalAmount,
- SUM(IF(ap.save_file_date IS NOT NULL, (IF(cd.defined_low_limit_amount < fc.claim_amount,
- fc.claim_amount * (cd.ratio / 100) * (bpd.performance_distribution / 100),
- cd.defined_low_limit_amount * (cd.ratio / 100) * (bpd.performance_distribution / 100)
- )), 0)) AS commissionTotalAmount
- FROM
- (
- SELECT
- claim_amount,
- order_fund_id,
- production_fund_id,
- claim_datetime
- FROM
- finance_claim
- WHERE
- deleted = 0
- AND production_fund_id IS NOT NULL
- AND claim_datetime >= #{vo.startDate}
- AND claim_datetime <= #{vo.endDate}
- 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
- AND created >= #{vo.startDate}
- AND created <= #{vo.endDate}
- ) fc
- 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
- )
- 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
- LEFT JOIN assets a ON a.id = ap.business_id
- 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 (
- cd.business_id = a.id
- AND ( cd.production_id IS NULL OR cd.production_id = ap.id ))
- LEFT JOIN business_commission_rate bcr ON bcr.id = cd.commission_rate_id
- LEFT JOIN dict_data dd ON dd.id = bcr.business_cate_id
- 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)
- LEFT JOIN user u ON u.id = bpd.member_id
- GROUP BY
- bpd.member_id
- having 1=1
- <if test="vo!=null and vo.userName!=null and vo.userName!=''">
- and u.name like concat ('%',#{vo.userName},'%')
- </if>
- order by commissionTotalAmount DESC
- </select>
- <!--资产评估人员提成计算详情-->
- <select id="assetsEvaluatorCommissionDetail" resultType="com.dayou.vo.UserCommissionProdAssetsVO">
- SELECT
- ap.id,
- fc.claim_amount as realAmount,
- ap.production_no AS reportNo,
- IF
- ( fc.claim_datetime > ap.save_file_date, fc.claim_datetime, ap.save_file_date ) AS settleDate,
- ap.assets_name AS name,
- ap.created,
- dd.name AS businessCate,
- IFNULL(cd.ratio,bcr.min_ratio) AS ratio,
- cd.defined_low_limit_amount AS lowLimitAmount,
- bpd.member_id,
- bpd.performance_distribution AS allotRatio,
- IF(cd.defined_low_limit_amount < fc.claim_amount,
- fc.claim_amount * (cd.ratio / 100) * (bpd.performance_distribution / 100),
- cd.defined_low_limit_amount * (cd.ratio / 100) * (bpd.performance_distribution / 100)
- ) AS commissionAmount,
- IF(cd.defined_low_limit_amount < fc.claim_amount,
- fc.claim_amount * (cd.ratio / 100),
- cd.defined_low_limit_amount * (cd.ratio / 100)
- ) AS totalAmount,
- u.name AS userName,
- pf.modified AS realFundDateTime
- FROM
- (
- SELECT
- claim_amount,
- order_fund_id,
- production_fund_id,
- claim_datetime
- FROM
- finance_claim
- WHERE
- deleted = 0
- AND production_fund_id IS NOT NULL
- AND claim_datetime >= #{vo.startDate}
- AND claim_datetime <= #{vo.endDate}
- 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
- AND created >= #{vo.startDate}
- AND created <= #{vo.endDate}
- ) fc
- 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 )
- 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
- LEFT JOIN assets a ON a.id = ap.business_id
- 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 (
- cd.business_id = a.id
- AND ( cd.production_id IS NULL OR cd.production_id = ap.id ))
- LEFT JOIN business_commission_rate bcr ON bcr.id = cd.commission_rate_id
- LEFT JOIN dict_data dd ON dd.id = bcr.business_cate_id
- 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)
- LEFT JOIN user u on u.id = bpd.member_id
- WHERE
- bpd.member_id = #{vo.userId}
- order by settleDate DESC
- </select>
- <!--资产评估人员合计导出-->
- <select id="assetsEvaluatorTotalAmountExport" resultType="com.dayou.vo.UserCommissionTotalAmountVO">
- SELECT bpd.member_id as id,
- u.name as userName,
- ROUND(SUM(IF(cd.defined_low_limit_amount < fc.claim_amount,
- fc.claim_amount * (cd.ratio / 100) * (bpd.performance_distribution / 100),
- cd.defined_low_limit_amount * (cd.ratio / 100) * (bpd.performance_distribution / 100)
- )), 2) AS allCommissionTotalAmount,
- ROUND(SUM(IF(ap.save_file_date IS NOT NULL, (IF(cd.defined_low_limit_amount < fc.claim_amount,
- fc.claim_amount * (cd.ratio / 100) * (bpd.performance_distribution / 100),
- cd.defined_low_limit_amount * (cd.ratio / 100) * (bpd.performance_distribution / 100)
- )), 0)), 2) AS commissionTotalAmount,
- '评估人员' as userType,
- '资产业务' as businessType,
- #{vo.startDate} as startDate,
- #{vo.endDate} as endDate
- FROM (SELECT claim_amount,
- order_fund_id,
- production_fund_id,
- claim_datetime
- FROM finance_claim
- WHERE deleted = 0
- AND production_fund_id IS NOT NULL
- AND claim_datetime >= #{vo.startDate}
- AND claim_datetime <= #{vo.endDate}
- 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
- AND created >= #{vo.startDate}
- AND created <= #{vo.endDate}) fc
- 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)
- 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
- LEFT JOIN assets a ON a.id = ap.business_id
- INNER JOIN (SELECT id, business_id, production_id, commission_rate_id, defined_low_limit_amount, ratio
- FROM commission_declare
- WHERE business_type = 'COMMISSION_DECLARE_ASSET_EVALUATE'
- AND deleted = 0
- AND declare_result = '审核通过') cd ON (
- cd.business_id = a.id
- AND (cd.production_id IS NULL OR cd.production_id = ap.id))
- LEFT JOIN business_commission_rate bcr ON bcr.id = cd.commission_rate_id
- LEFT JOIN dict_data dd ON dd.id = bcr.business_cate_id
- 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)
- LEFT JOIN user u ON u.id = bpd.member_id
- GROUP BY bpd.member_id
- </select>
- <!--资产评估人员提成信息导出-->
- <select id="assetsEvaluatorUserDetailExport" resultType="com.dayou.vo.UserCommissionProdAssetsVO">
- SELECT
- ap.id,
- ROUND(fc.claim_amount,2) as realAmount,
- ap.production_no AS reportNo,
- IF
- ( fc.claim_datetime > ap.save_file_date, fc.claim_datetime, ap.save_file_date ) AS settleDate,
- ap.assets_name AS name,
- ap.created,
- dd.NAME AS businessCate,
- IFNULL(cd.ratio,bcr.min_ratio) AS ratio,
- cd.defined_low_limit_amount AS lowLimitAmount,
- ROUND(bcr.min_ratio,2) AS ratio,
- bpd.member_id AS userId,
- ROUND(bpd.performance_distribution,2) AS allotRatio,
- ROUND(IF(cd.defined_low_limit_amount < fc.claim_amount,
- fc.claim_amount * (cd.ratio / 100) * (bpd.performance_distribution / 100),
- cd.defined_low_limit_amount * (cd.ratio / 100) * (bpd.performance_distribution / 100)
- ),2) AS commissionAmount,
- ROUND(IF(cd.defined_low_limit_amount < fc.claim_amount,
- fc.claim_amount * (cd.ratio / 100),
- cd.defined_low_limit_amount * (cd.ratio / 100)
- ),2) AS totalAmount,
- u.name as userName,
- pf.modified AS realFundDateTime
- FROM
- (
- SELECT
- claim_amount,
- order_fund_id,
- production_fund_id,
- claim_datetime
- FROM
- finance_claim
- WHERE
- deleted = 0
- AND production_fund_id IS NOT NULL
- AND claim_datetime >= #{vo.startDate}
- AND claim_datetime <= #{vo.endDate}
- 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
- AND created >= #{vo.startDate}
- AND created <= #{vo.endDate}
- ) fc
- 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 )
- 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
- LEFT JOIN assets a ON a.id = ap.business_id
- 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 (
- cd.business_id = a.id
- AND ( cd.production_id IS NULL OR cd.production_id = ap.id ))
- LEFT JOIN business_commission_rate bcr ON bcr.id = cd.commission_rate_id
- LEFT JOIN dict_data dd ON dd.id = bcr.business_cate_id
- 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)
- LEFT JOIN user u on u.id = bpd.member_id
- <where>
- <if test="vo!=null and vo.userId!=null">
- and bpd.member_id = #{vo.userId}
- </if>
- </where>
- order by bpd.member_id
- </select>
- <!--资产市场人员提成计算-->
- <select id="assetsMarketCommission" resultType="com.dayou.vo.UserCommissionTotalAmountVO">
- SELECT bpd.member_id as id,
- u.name as userName,
- SUM(( fc.claim_amount * ( bcr.min_ratio / 100 ) * (bpd.performance_distribution / 100))) AS commissionTotalAmount
- FROM
- (
- SELECT
- claim_amount,
- order_fund_id,
- production_fund_id,
- claim_datetime
- FROM
- finance_claim
- WHERE
- deleted = 0
- AND production_fund_id IS NOT NULL
- AND claim_datetime >= #{vo.startDate}
- AND claim_datetime <= #{vo.endDate}
- 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
- AND created >= #{vo.startDate}
- AND created <= #{vo.endDate}
- ) fc
- 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 )
- 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
- LEFT JOIN assets a ON a.id = ap.business_id
- 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 (
- cd.business_id = a.id
- AND ( cd.production_id IS NULL OR cd.production_id = ap.id ))
- LEFT JOIN business_commission_rate bcr ON bcr.id = cd.commission_rate_id
- LEFT JOIN dict_data dd ON dd.id = bcr.business_cate_id
- LEFT JOIN ( SELECT business_id, report_no,declare_id, member_id, performance_distribution FROM business_performance_distribution WHERE deleted = 0 AND user_type = '市场人员'
- ) 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 ))
- LEFT JOIN user u ON u.id = bpd.member_id
- GROUP BY
- bpd.member_id
- having 1=1
- <if test="vo!=null and vo.userName!=null and vo.userName!=''">
- and u.name like concat ('%',#{vo.userName},'%')
- </if>
- order by commissionTotalAmount DESC
- </select>
- <!--资产市场人员提成计算详情-->
- <select id="assetsMarketCommissionDetail" resultType="com.dayou.vo.UserCommissionProdVO">
- SELECT
- ap.id,
- fc.claim_amount as realAmount,
- ap.production_no AS reportNo,
- IF
- ( fc.claim_datetime > ap.save_file_date, fc.claim_datetime, ap.save_file_date ) AS settleDate,
- ap.assets_name AS name,
- ap.created,
- dd.NAME AS businessCate,
- bcr.min_ratio AS ratio,
- bpd.member_id AS userId,
- bpd.performance_distribution AS allotRatio,
- ( fc.claim_amount * ( bcr.min_ratio / 100 ) * (bpd.performance_distribution / 100) ) AS commissionAmount,
- ( fc.claim_amount * ( bcr.min_ratio / 100 ) ) AS totalAmount,
- u.name as userName
- FROM
- (
- SELECT
- claim_amount,
- order_fund_id,
- production_fund_id,
- claim_datetime
- FROM
- finance_claim
- WHERE
- deleted = 0
- AND production_fund_id IS NOT NULL
- AND claim_datetime >= #{vo.startDate}
- AND claim_datetime <= #{vo.endDate}
- 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
- AND created >= #{vo.startDate}
- AND created <= #{vo.endDate}
- ) fc
- 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 )
- 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
- LEFT JOIN assets a ON a.id = ap.business_id
- 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 (
- cd.business_id = a.id
- AND ( cd.production_id IS NULL OR cd.production_id = ap.id ))
- LEFT JOIN business_commission_rate bcr ON bcr.id = cd.commission_rate_id
- LEFT JOIN dict_data dd ON dd.id = bcr.business_cate_id
- LEFT JOIN ( SELECT business_id, report_no, member_id, performance_distribution,declare_id FROM business_performance_distribution WHERE deleted = 0 AND user_type = '市场人员' ) 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 ))
- LEFT JOIN user u on u.id = bpd.member_id
- WHERE
- bpd.member_id = #{vo.userId}
- order by settleDate DESC
- </select>
- <!--资产市场人员提成合计导出-->
- <select id="assetsMarketTotalAmountExport" resultType="com.dayou.vo.UserCommissionTotalAmountVO">
- SELECT bpd.member_id as id,
- u.name as userName,
- ROUND(SUM((fc.claim_amount * (bcr.min_ratio / 100) * (bpd.performance_distribution / 100))),
- 2) AS commissionTotalAmount,
- '市场人员' as userType,
- '资产业务' as businessType,
- #{vo.startDate} as startDate,
- #{vo.endDate} as endDate
- FROM (SELECT claim_amount,
- order_fund_id,
- production_fund_id,
- claim_datetime
- FROM finance_claim
- WHERE deleted = 0
- AND production_fund_id IS NOT NULL
- AND claim_datetime >= #{vo.startDate}
- AND claim_datetime <= #{vo.endDate}
- 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
- AND created >= #{vo.startDate}
- AND created <= #{vo.endDate}) fc
- 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)
- 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
- LEFT JOIN assets a ON a.id = ap.business_id
- 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 (
- cd.business_id = a.id
- AND (cd.production_id IS NULL OR cd.production_id = ap.id))
- LEFT JOIN business_commission_rate bcr ON bcr.id = cd.commission_rate_id
- LEFT JOIN dict_data dd ON dd.id = bcr.business_cate_id
- LEFT JOIN (SELECT business_id, report_no, declare_id, member_id, performance_distribution
- FROM business_performance_distribution
- WHERE deleted = 0
- AND user_type = '市场人员') 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))
- LEFT JOIN user u ON u.id = bpd.member_id
- GROUP BY bpd.member_id
- ORDER BY commissionTotalAmount DESC
- </select>
- <!--资产市场人员提成信息导出-->
- <select id="assetsMarketUserDetailExport" resultType="com.dayou.vo.UserCommissionProdVO">
- SELECT
- ap.id,
- ROUND(fc.claim_amount,2) as realAmount,
- ap.production_no AS reportNo,
- IF
- ( fc.claim_datetime > ap.save_file_date, fc.claim_datetime, ap.save_file_date ) AS settleDate,
- ap.assets_name AS name,
- ap.created,
- dd.`name` AS businessCate,
- ROUND(bcr.min_ratio,2) AS ratio,
- bpd.member_id AS userId,
- ROUND(bpd.performance_distribution,2) AS allotRatio,
- ROUND(( fc.claim_amount * ( bcr.min_ratio / 100 ) * (bpd.performance_distribution / 100) ),2) AS
- commissionAmount,
- ROUND(( fc.claim_amount * ( bcr.min_ratio / 100 ) ),2) AS totalAmount,
- u.name as userName
- FROM
- (
- SELECT
- claim_amount,
- order_fund_id,
- production_fund_id,
- claim_datetime
- FROM
- finance_claim
- WHERE
- deleted = 0
- AND production_fund_id IS NOT NULL
- AND claim_datetime >= #{vo.startDate}
- AND claim_datetime <= #{vo.endDate}
- 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
- AND created >= #{vo.startDate}
- AND created <= #{vo.endDate}
- ) fc
- 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
- )
- 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
- LEFT JOIN assets a ON a.id = ap.business_id
- 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 (
- cd.business_id = a.id
- AND ( cd.production_id IS NULL OR cd.production_id = ap.id ))
- LEFT JOIN business_commission_rate bcr ON bcr.id = cd.commission_rate_id
- LEFT JOIN dict_data dd ON dd.id = bcr.business_cate_id
- LEFT JOIN ( SELECT business_id, report_no, member_id, performance_distribution, declare_id FROM
- business_performance_distribution WHERE deleted = 0 AND user_type = '市场人员' ) 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 ))
- LEFT JOIN user u on u.id = bpd.member_id
- <where>
- <if test="vo!=null and vo.userId!=null">
- and bpd.member_id = #{vo.userId}
- </if>
- </where>
- order by bpd.member_id
- </select>
- <!--资产收款逾期查询Sql-->
- <sql id="assetsOverdueSql">
- SELECT
- DATEDIFF(CURDATE(), DATE( ap.repertory_out_time )) AS overdueDay,
- a.allot_type,
- a.order_id,
- a.assets_business_gener,
- u.name AS clientManager,
- u1.name AS principal,
- cc1.name AS clientName,
- cc2.name AS clientSubName,
- pf.production_should_amount,
- `of`.should_amount,
- pf.standard_amount,
- ap.*
- FROM
- (
- SELECT
- id,
- business_id,
- production_no,
- ( CASE production_type WHEN 'STATEMENT' THEN '意见书' WHEN 'REPORT' THEN '评估报告' WHEN 'LETTER' THEN '意见函' WHEN 'CONSULT' THEN '咨询报告' ELSE '' END ) productionType,
- assets_name,
- evaluate_amount,
- repertory_out_time
- FROM
- assets_production ap
- WHERE
- deleted = 0
- AND repertory_out_time IS NOT NULL
- AND production_type != 'STATEMENT'
- ) ap
- 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
- ON ( ap.business_id = pf.business_id AND ap.production_no = pf.production_no )
- 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
- LEFT JOIN assets a ON a.id = ap.business_id
- LEFT JOIN user u ON u.id = a.client_manager_id
- LEFT JOIN user u1 ON u1.id = a.principal_id
- LEFT JOIN customer_company cc1 ON cc1.id = a.clientele_id
- LEFT JOIN customer_company cc2 ON cc2.id = a.clientele_sub_id
- WHERE
- ap.productionType != 'STATEMENT'
- AND ( pf.production_no IS NULL OR pf.real_amount IS NULL )
- AND DATEDIFF(CURDATE(),DATE( ap.repertory_out_time )) >= #{overdueVO.overdueMin}
- <if test="overdueVO!=null and overdueVO.overdueMax!=null">
- AND DATEDIFF(CURDATE(),DATE( ap.repertory_out_time )) <= #{overdueVO.overdueMax}
- </if>
- <if test="overdueVO!=null and overdueVO.orderId!=null and overdueVO.orderId!=''">
- and a.order_id = #{overdueVO.orderId}
- </if>
- <if test="overdueVO!=null and overdueVO.productionNo!=null and overdueVO.productionNo!=''">
- and ap.production_no like concat ('%',#{overdueVO.productionNo},'%')
- </if>
- <if test="overdueVO!=null and overdueVO.principal!=null and overdueVO.principal!=''">
- and u1.name like concat ('%',#{overdueVO.principal},'%')
- </if>
- order by overdueDay desc
- </sql>
- <!--资产收款逾期列表-->
- <select id="overdueAssets" resultType="com.dayou.vo.AssetsProdOverdueVO">
- <include refid="assetsOverdueSql" />
- </select>
- <!--资产收款逾期列表导出-->
- <select id="overdueAssetsExport" resultType="com.dayou.vo.AssetsProdOverdueVO">
- <include refid="assetsOverdueSql" />
- </select>
- <resultMap id="settleAssetsProductionVOMap" type="com.dayou.vo.SettleAssetsProductionVO">
- <id property="id" column="id" />
- <result property="id" column="id" />
- <result property="claimAmount" column="claim_amount" />
- <result property="orderId" column="order_id" />
- <result property="productionNo" column="production_no" />
- <result property="claimDate" column="claimDate" />
- <result property="saveFileDate" column="save_file_date" />
- <result property="settleDate" column="settleDate" />
- <result property="deliveryDate" column="deliveryDate" />
- <result property="projectName" column="projectName" />
- <result property="bailor" column="bailor" />
- <result property="evaluateAmount" column="evaluate_amount" />
- <result property="principal" column="principal" />
- <result property="clientManager" column="clientManager" />
- <result property="clientName" column="clientName" />
- <result property="clientSubName" column="clientSubName" />
- <result property="evaluateDepartmentName" column="evaluateDepartmentName" />
- <result property="marketDepartmentName" column="marketDepartmentName" />
- <collection property="invoices" ofType="com.dayou.vo.SettleProInvoiceVo">
- <result property="invoiceDate" column="invoiceDate" />
- <result property="invoiceUser" column="invoiceUser" />
- <result property="invoiceNo" column="invoiceNo" />
- </collection>
- </resultMap>
- <!--资产市场人员结算项目Sql-->
- <sql id="assetsMarketerSettleSql">
- SELECT
- ap.id,
- fc.claim_amount,
- a.order_id,
- ap.production_no,
- fc.claim_datetime as claimDate,
- ap.delivery_date AS deliveryDate,
- ap.save_file_date,
- IF
- ( fc.claim_datetime > ap.delivery_date, fc.claim_datetime, ap.delivery_date ) AS settleDate,
- ap.assets_name AS projectName,
- a.bailor,
- ap.evaluate_amount,
- u.name AS principal,
- u1.name AS clientManager,
- cc.name AS clientName,
- cc1.name AS clientSubName,
- d.name AS evaluateDepartmentName,
- (
- SELECT
- GROUP_CONCAT( department.name )
- FROM
- department
- WHERE
- id IN (
- SELECT
- department_id
- FROM
- post
- WHERE
- id IN ( SELECT post_id FROM user_post WHERE user_id = a.client_manager_id ))) AS marketDepartmentName,
- invoice.name AS invoiceUser,
- invoice.real_make_date AS invoiceDate,
- invoice.tax_no AS invoiceNo
- FROM
- (
- SELECT
- claim_amount,
- order_fund_id,
- production_fund_id,
- claim_datetime
- FROM
- finance_claim
- WHERE
- deleted = 0
- AND production_fund_id IS NOT NULL
- AND claim_datetime >= #{settleVO.startDate}
- AND claim_datetime <= #{settleVO.endDate} 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
- AND created >= #{settleVO.startDate}
- AND created <= #{settleVO.endDate}
- ) fc
- 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
- )
- INNER JOIN ( SELECT id, business_id, assets_name, production_no, production_type, evaluate_amount,
- delivery_date, save_file_date FROM assets_production WHERE deleted = 0 AND delivery = true ) ap ON ap.production_no =
- pf.production_no
- LEFT JOIN assets a ON a.id = ap.business_id
- LEFT JOIN user u ON u.id = a.principal_id
- LEFT JOIN user u1 ON u1.id = a.client_manager_id
- LEFT JOIN customer_company cc ON cc.id = a.clientele_id
- LEFT JOIN customer_company cc1 ON cc1.id = a.clientele_sub_id
- LEFT JOIN department d ON d.id = a.department_id
- LEFT JOIN (
- SELECT real_make_date, name, tax_no, order_fund_id, production_fund_id
- FROM finance_invoice, user
- WHERE maker_id = user.id
- AND finance_invoice.deleted = 0
- AND state = '已开票'
- ) 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)
- <where>
- <if test="settleVO!=null and settleVO.orderId!=null and settleVO.orderId!='' ">
- and a.order_id = #{settleVO.orderId}
- </if>
- <if test="settleVO!=null and settleVO.productionNo!=null and settleVO.productionNo!='' ">
- and ap.report_no like concat ('%',#{settleVO.productionNo},'%')
- </if>
- <if test="settleVO!=null and settleVO.principal!=null and settleVO.principal!='' ">
- and u.name like concat ('%',#{settleVO.principal},'%')
- </if>
- <if test="settleVO!=null and settleVO.clientManager!=null and settleVO.clientManager!='' ">
- and u1.name like concat ('%',#{settleVO.clientManager},'%')
- </if>
- </where>
- order by settleDate DESC
- </sql>
- <!--资产结算项目查询-->
- <select id="assetsMarketSettleProd" resultMap="settleAssetsProductionVOMap">
- <include refid="assetsMarketerSettleSql" />
- </select>
- <!--资产结算项目导出-->
- <select id="assetsMarketSettleExport" resultMap="settleAssetsProductionVOMap">
- <include refid="assetsMarketerSettleSql" />
- </select>
- <!--资产评估人员结算项目Sql-->
- <sql id="assetsEvaluatorSettleSql">
- SELECT
- ap.id,
- fc.claim_amount,
- a.order_id,
- ap.production_no,
- fc.claim_datetime as claimDate,
- ap.save_file_date,
- IF( fc.claim_datetime > ap.save_file_date, fc.claim_datetime, ap.save_file_date ) AS settleDate,
- ap.assets_name AS projectName,
- a.bailor,
- ap.evaluate_amount,
- u.name AS principal,
- u1.name AS clientManager,
- cc.name AS clientName,
- cc1.name AS clientSubName,
- d.name AS evaluateDepartmentName,
- (
- SELECT
- GROUP_CONCAT( NAME )
- FROM
- department
- WHERE
- id IN (
- SELECT
- department_id
- FROM
- post
- WHERE
- id IN ( SELECT post_id FROM user_post WHERE user_id = a.client_manager_id ))) AS marketDepartmentName,
- invoice.name AS invoiceUser,
- invoice.real_make_date AS invoiceDate,
- invoice.tax_no AS invoiceNo
- FROM
- (
- SELECT
- claim_amount,
- order_fund_id,
- production_fund_id,
- claim_datetime
- FROM
- finance_claim
- WHERE
- deleted = 0
- AND production_fund_id IS NOT NULL
- AND claim_datetime >= #{settleVO.startDate}
- AND claim_datetime <= #{settleVO.endDate} 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
- AND created >= #{settleVO.startDate}
- AND created <= #{settleVO.endDate}
- ) fc
- 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 )
- 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
- LEFT JOIN assets a ON a.id = ap.business_id
- LEFT JOIN user u ON u.id = a.principal_id
- LEFT JOIN user u1 ON u1.id = a.client_manager_id
- LEFT JOIN customer_company cc ON cc.id = a.clientele_id
- LEFT JOIN customer_company cc1 ON cc1.id = a.clientele_sub_id
- LEFT JOIN department d ON d.id = a.department_id
- LEFT JOIN (
- SELECT real_make_date, name, tax_no, order_fund_id, production_fund_id
- FROM finance_invoice, user
- WHERE maker_id = user.id
- AND finance_invoice.deleted = 0
- AND state = '已开票'
- ) 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)
- <where>
- <if test="settleVO!=null and settleVO.orderId!=null and settleVO.orderId!='' ">
- and a.order_id = #{settleVO.orderId}
- </if>
- <if test="settleVO!=null and settleVO.productionNo!=null and settleVO.productionNo!='' ">
- and ap.production_no like concat ('%',#{settleVO.productionNo},'%')
- </if>
- <if test="settleVO!=null and settleVO.principal!=null and settleVO.principal!='' ">
- and u.name like concat ('%',#{settleVO.principal},'%')
- </if>
- <if test="settleVO!=null and settleVO.clientManager!=null and settleVO.clientManager!='' ">
- and u1.name like concat ('%',#{settleVO.clientManager},'%')
- </if>
- </where>
- order by settleDate DESC
- </sql>
- <!--资产评估人员结算项目查询-->
- <select id="assetsEvaluatorSettleProd" resultMap="settleAssetsProductionVOMap">
- <include refid="assetsEvaluatorSettleSql" />
- </select>
- <!--资产评估人员结算项目导出-->
- <select id="assetsEvaluatorSettleExport" resultMap="settleAssetsProductionVOMap">
- <include refid="assetsEvaluatorSettleSql" />
- </select>
- </mapper>
|