1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059 |
- <?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>
- <sql id="pageListSql">
- 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>
- </sql>
- <sql id="pageListSql1">
- SELECT
- #{userId} as userId,
- 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
- </sql>
- <resultMap id="realAmountClaimMap" type="com.dayou.vo.FinanceRealFundVO">
- <result column="userId" property="userId" />
- <result column="id" property="id" />
- <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" />
- <result column="creator" property="creator" />
- <result column="claimAmount" property="claimAmount" />
- <result column="notClaimAmount" property="notClaimAmount" />
- <collection property="recommends" select="findRecommends" ofType="java.lang.String" column="{amount=amount,userId=userId}" />
- </resultMap>
- <select id="getPage" parameterType="com.dayou.entity.FinanceRealFund" resultType="com.dayou.vo.FinanceRealFundVO">
- <include refid="pageListSql" />
- ORDER BY
- ifnull(t.ca,0) ASC ,frf.created DESC
- </select>
- <select id="claimPage" resultMap="realAmountClaimMap">
- SELECT
- #{userId} as userId,
- 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
- frf.created DESC
- </select>
- <select id="findRecommends" resultType="java.lang.String">
- SELECT
- tt1.business_type
- FROM
- (
- SELECT
- order_fund.real_amount,
- order_fund.business_type,
- temp.invoiceAmount
- FROM
- (
- SELECT
- order_fund_id,
- sum( real_amount ) AS invoiceAmount
- FROM
- finance_invoice
- WHERE
- state = '已开票'
- AND deleted = 0
- AND production_fund_id IS NULL
- <if test="userId!=null">
- and apply_id = #{userId}
- </if>
- GROUP BY
- order_fund_id UNION ALL
- SELECT
- order_fund_id,
- sum( real_amount ) AS invoiceAmount
- FROM
- finance_invoice
- WHERE
- state = '已开票'
- AND deleted = 0
- AND production_fund_id IS NOT NULL
- <if test="userId!=null">
- and apply_id = #{userId}
- </if>
- GROUP BY
- production_fund_id
- ) temp
- LEFT JOIN order_fund ON order_fund.id = temp.order_fund_id
- ) tt1
- WHERE
- tt1.invoiceAmount = #{amount}
- AND tt1.real_amount IS NULL
- </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,
- pf.production,
- 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 as shouldAmount,
- mp.*
- FROM
- ( SELECT business_id, production_no,
- ( CASE production_type WHEN 'STATEMENT' THEN '意见书' WHEN 'REPORT' THEN '报告' WHEN 'LETTER' THEN '复评函' ELSE '' END ) production,
- production_type
- , production_should_amount, real_amount FROM production_fund WHERE business_type = 'MAJOR_BUSINESS'
- AND deleted = 0 and production_should_amount is not null and production_should_amount!=0 and real_amount is null) pf
- inner join
- (
- SELECT
- id,
- major_id,
- report_no,
- production as productionType,
- NAME,
- evaluate_amount,
- repertory_out_time,
- standard_amount
- FROM
- major_production mp
- WHERE
- deleted = 0
- AND repertory_out_time IS NOT NULL
- ) mp
- ON ( mp.major_id = pf.business_id AND mp.report_no = pf.production_no and mp.productionType = pf.production_type )
- 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>
- <if test="overdueVO!=null and overdueVO.overdueMin!=null">
- AND DATEDIFF(CURDATE(),DATE( mp.repertory_out_time )) >= #{overdueVO.overdueMin}
- </if>
- <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>
- <if test="overdueVO!=null and overdueVO.userIds!=null and overdueVO.userIds.size!=0">
- and m.client_manager_id in
- <foreach collection="overdueVO.userIds" open="(" close=")" separator="," item="userId">
- #{userId}
- </foreach>
- </if>
- </where>
- order by overdueDay ASC
- </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" />
- <result property="payDateTime" column="pay_datetime" />
- <!-- <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
- fc.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,
- frf.pay_datetime
- FROM
- (
- SELECT
- id,
- claim_amount,
- order_fund_id,
- production_fund_id,
- claim_datetime,
- real_fund_id
- FROM
- finance_claim
- WHERE
- deleted = 0
- AND production_fund_id IS NOT NULL
- ) fc
- INNER JOIN ( SELECT id, pay_datetime FROM finance_real_fund WHERE deleted = 0
- <if test="settleVO!=null and settleVO.payStartDate!=null and settleVO.payStartDate!='' ">
- AND pay_datetime >= #{settleVO.payStartDate}
- </if>
- <if test="settleVO!=null and settleVO.payEndDate!=null and settleVO.payEndDate!='' ">
- AND pay_datetime <= #{settleVO.payEndDate}
- </if>
- ) frf ON frf.id = fc.real_fund_id
- 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,
- fund.real_amount
- FROM
- major_production mpr
- INNER JOIN ( SELECT production_no, real_amount, production_type FROM production_fund WHERE deleted = 0 AND business_type = 'MAJOR_BUSINESS' ) fund ON ( fund.production_no = mpr.report_no AND fund.production_type = mpr.production )
- WHERE
- fund.real_amount IS NOT NULL
- AND mpr.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
- <where>
- <if test="keyword!=null and keyword!='' ">
- and (
- mp.report_no like concat ('%',#{keyword},'%')
- or fc.claim_amount =#{keyword}
- or m.order_id like concat('%',#{keyword},'%')
- or u.name like concat('%',#{keyword},'%')
- or u1.name like concat('%',#{keyword},'%')
- )
- </if>
- <if test="settleVO!=null and settleVO.startDate!=null and settleVO.startDate!='' ">
- AND (select IF
- ( fc.claim_datetime > mp.save_file_date, fc.claim_datetime, mp.save_file_date )) >= #{settleVO.startDate}
- </if>
- <if test="settleVO!=null and settleVO.endDate!=null and settleVO.endDate!='' ">
- AND (select IF
- ( fc.claim_datetime > mp.save_file_date, fc.claim_datetime, mp.save_file_date )) <= #{settleVO.endDate}
- </if>
- </where>
- order by fc.claim_datetime ASC
- </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
- fc.id,
- fc.claim_amount,
- m.order_id,
- mp.report_no,
- fc.claim_datetime AS claimDate,
- mp.delivery_date AS deliveryDate,
- 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,
- frf.pay_datetime
- FROM
- (
- SELECT
- id,
- claim_amount,
- order_fund_id,
- production_fund_id,
- claim_datetime,
- real_fund_id
- FROM
- finance_claim
- WHERE
- deleted = 0
- AND production_fund_id IS NOT NULL
- ) fc
- INNER JOIN ( SELECT id, pay_datetime FROM finance_real_fund WHERE deleted = 0
- <if test="settleVO!=null and settleVO.payStartDate!=null and settleVO.payStartDate!='' ">
- AND pay_datetime >= #{settleVO.payStartDate}
- </if>
- <if test="settleVO!=null and settleVO.payEndDate!=null and settleVO.payEndDate!='' ">
- AND pay_datetime <= #{settleVO.payEndDate}
- </if>
- ) frf ON frf.id = fc.real_fund_id
- 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,
- fund.real_amount
- FROM
- major_production mpr
- INNER JOIN ( SELECT production_no, real_amount, production_type FROM production_fund WHERE deleted = 0 AND business_type = 'MAJOR_BUSINESS' ) fund ON ( fund.production_no = mpr.report_no AND fund.production_type = mpr.production )
- WHERE
- fund.real_amount IS NOT NULL
- AND mpr.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
- <where>
- <if test="keyword!=null and keyword!='' ">
- and (
- mp.report_no like concat ('%',#{keyword},'%')
- or fc.claim_amount =#{keyword}
- or m.order_id like concat('%',#{keyword},'%')
- or u.name like concat('%',#{keyword},'%')
- or u1.name like concat('%',#{keyword},'%')
- )
- </if>
- <if test="settleVO!=null and settleVO.startDate!=null and settleVO.startDate!='' ">
- AND (select IF
- ( fc.claim_datetime > mp.delivery_date, fc.claim_datetime, mp.delivery_date )) >= #{settleVO.startDate}
- </if>
- <if test="settleVO!=null and settleVO.endDate!=null and settleVO.endDate!='' ">
- AND (select IF
- ( fc.claim_datetime > mp.delivery_date, fc.claim_datetime, mp.delivery_date )) <= #{settleVO.endDate}
- </if>
- </where>
- order by fc.claim_datetime ASC
- </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}
- ) 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,
- fund.real_amount
- FROM
- major_production mpr
- INNER JOIN ( SELECT production_no, real_amount, production_type FROM production_fund WHERE deleted = 0 AND business_type = 'MAJOR_BUSINESS' ) fund ON ( fund.production_no = mpr.report_no AND fund.production_type = mpr.production )
- WHERE
- fund.real_amount IS NOT NULL
- AND mpr.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 = 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.userIds!=null and vo.userIds.size!=0">
- mpa.user_id in
- <foreach collection="vo.userIds" open="(" close=")" separator="," item="userId">
- #{userId}
- </foreach>
- </if>
- </where>
- 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}
- ) 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,
- fund.real_amount,
- created
- FROM
- major_production mpr
- INNER JOIN ( SELECT production_no, real_amount, production_type FROM production_fund WHERE deleted = 0 AND business_type = 'MAJOR_BUSINESS' ) fund ON ( fund.production_no = mpr.report_no AND fund.production_type = mpr.production )
- WHERE
- fund.real_amount IS NOT NULL
- AND mpr.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 = 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}
- ) 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,
- fund.real_amount
- FROM
- major_production mpr
- INNER JOIN ( SELECT production_no, real_amount, production_type FROM production_fund WHERE deleted = 0 AND business_type = 'MAJOR_BUSINESS' ) fund ON ( fund.production_no = mpr.report_no AND fund.production_type = mpr.production )
- WHERE
- fund.real_amount IS NOT NULL
- AND mpr.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 = 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}
- ) 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,
- fund.real_amount,
- created
- FROM
- major_production mpr
- INNER JOIN ( SELECT production_no, real_amount, production_type FROM production_fund WHERE deleted = 0 AND business_type = 'MAJOR_BUSINESS' ) fund ON ( fund.production_no = mpr.report_no AND fund.production_type = mpr.production )
- WHERE
- fund.real_amount IS NOT NULL
- AND mpr.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 = 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}
- ) 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,
- fund.real_amount
- FROM
- major_production mpr
- INNER JOIN ( SELECT production_no, real_amount, production_type FROM production_fund WHERE deleted = 0 AND business_type = 'MAJOR_BUSINESS' ) fund ON ( fund.production_no = mpr.report_no AND fund.production_type = mpr.production )
- WHERE
- fund.real_amount IS NOT NULL
- AND mpr.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 = 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
- <where>
- <if test="vo!=null and vo.userIds!=null and vo.userIds.size!=0">
- mpa.user_id in
- <foreach collection="vo.userIds" open="(" close=")" separator="," item="userId">
- #{userId}
- </foreach>
- </if>
- </where>
- 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.delivery_date, fc.claim_datetime, mp.delivery_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}
- ) 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,
- fund.real_amount,
- created
- FROM
- major_production mpr
- INNER JOIN ( SELECT production_no, real_amount, production_type FROM production_fund WHERE deleted = 0 AND business_type = 'MAJOR_BUSINESS' ) fund ON ( fund.production_no = mpr.report_no AND fund.production_type = mpr.production )
- WHERE
- fund.real_amount IS NOT NULL
- AND mpr.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 = 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}
- ) 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,
- fund.real_amount
- FROM
- major_production mpr
- INNER JOIN ( SELECT production_no, real_amount, production_type FROM production_fund WHERE deleted = 0 AND business_type = 'MAJOR_BUSINESS' ) fund ON ( fund.production_no = mpr.report_no AND fund.production_type = mpr.production )
- WHERE
- fund.real_amount IS NOT NULL
- AND mpr.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 = 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.delivery_date, fc.claim_datetime, mp.delivery_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}
- ) 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,
- fund.real_amount,
- created
- FROM
- major_production mpr
- INNER JOIN ( SELECT production_no, real_amount, production_type FROM production_fund WHERE deleted = 0 AND business_type = 'MAJOR_BUSINESS' ) fund ON ( fund.production_no = mpr.report_no AND fund.production_type = mpr.production )
- WHERE
- fund.real_amount IS NOT NULL
- AND mpr.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 = 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
- inner JOIN personal_target pt ON pt.personal_id = p.id
- inner JOIN ( SELECT business_id, should_amount, real_amount FROM order_fund WHERE business_type = 'PERSONAL_BUSINESS' AND deleted = 0 AND real_amount IS NULL ) ofu ON ofu.business_id = p.id
- inner JOIN ( SELECT target_id,( repertory_out_time ) rot FROM personal_production WHERE repertory_out_time IS NOT NULL GROUP BY target_id ) pp ON pp.target_id = pt.id
- 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>
- <if test="overdueVO!=null and overdueVO.overdueMin!=null">
- AND DATEDIFF(CURDATE(),DATE ( pp.rot )) >= #{overdueVO.overdueMin}
- </if>
- <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 p.order_id = #{overdueVO.orderId}
- </if>
- <if test="overdueVO!=null and overdueVO.userIds!=null and overdueVO.userIds.size!=0">
- and p.client_manager_id in
- <foreach collection="overdueVO.userIds" open="(" close=")" separator="," item="userId">
- #{userId}
- </foreach>
- </if>
- </where>
- ORDER BY
- overdueDay ASC
- </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,
- a.name as projectName,
- 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,
- 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 )
- <if test="overdueVO!=null and overdueVO.overdueMin!=null">
- AND DATEDIFF(CURDATE(),DATE( ap.repertory_out_time )) >= #{overdueVO.overdueMin}
- </if>
- <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>
- <if test="overdueVO!=null and overdueVO.userIds!=null and overdueVO.userIds.size!=0">
- and a.client_manager_id in
- <foreach collection="overdueVO.userIds" open="(" close=")" separator="," item="userId">
- #{userId}
- </foreach>
- </if>
- order by overdueDay asc
- </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" />
- <result property="payDateTime" column="pay_datetime" />
- <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
- fc.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,
- frf.pay_datetime
- FROM
- (
- SELECT
- id,
- claim_amount,
- order_fund_id,
- production_fund_id,
- claim_datetime,
- real_fund_id
- 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 id,allot_amount AS claim_amount, order_fund_id, production_fund_id, created AS claim_datetime,real_fund_id FROM
- order_fund_allot WHERE deleted = 0
- AND created >= #{settleVO.startDate}
- AND created <= #{settleVO.endDate}
- ) fc
- inner join (
- select id,pay_datetime from finance_real_fund
- where deleted = 0
- <if test="settleVO!=null and settleVO.payStartDate!=null and settleVO.payStartDate!='' ">
- AND pay_datetime >= #{settleVO.payStartDate}
- </if>
- <if test="settleVO!=null and settleVO.payEndDate!=null and settleVO.payEndDate!='' ">
- AND pay_datetime <= #{settleVO.payEndDate}
- </if>
- ) frf on frf.id = fc.real_fund_id
- 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="keyword!=null and keyword!='' ">
- and (
- a.order_id = #{keyword}
- or ap.production_no like concat ('%',#{keyword},'%')
- or u.name like concat ('%',#{keyword},'%')
- or u1.name like concat ('%',#{keyword},'%')
- )
- </if>
- </where>
- order by fc.claim_datetime ASC
- </sql>
- <!--资产结算项目查询-->
- <select id="assetsMarketSettleProd" resultMap="settleAssetsProductionVOMap">
- <include refid="assetsMarketerSettleSql" />
- </select>
- <!--资产结算项目导出-->
- <select id="assetsMarketSettleExport" resultMap="settleAssetsProductionVOMap">
- <include refid="assetsMarketerSettleSql" />
- </select>
- <!--资产评估人员结算项目Sql-->
- <sql id="assetsEvaluatorSettleSql">
- SELECT
- fc.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,
- IF(ap.assets_name IS NOT NULL, ap.assets_name, a.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,
- frf.pay_datetime
- FROM
- (
- SELECT
- id,
- claim_amount,
- order_fund_id,
- production_fund_id,
- claim_datetime,
- real_fund_id
- 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 id, allot_amount AS claim_amount, order_fund_id, production_fund_id, created AS claim_datetime ,real_fund_id FROM order_fund_allot WHERE deleted = 0
- AND created >= #{settleVO.startDate}
- AND created <= #{settleVO.endDate}
- ) fc
- inner join (
- select id,pay_datetime from finance_real_fund
- where deleted = 0
- <if test="settleVO!=null and settleVO.payStartDate!=null and settleVO.payStartDate!='' ">
- AND pay_datetime >= #{settleVO.payStartDate}
- </if>
- <if test="settleVO!=null and settleVO.payEndDate!=null and settleVO.payEndDate!='' ">
- AND pay_datetime <= #{settleVO.payEndDate}
- </if>
- ) frf on frf.id = fc.real_fund_id
- 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="keyword!=null and keyword!='' ">
- and (
- a.order_id = #{keyword}
- or ap.production_no like concat ('%',#{keyword},'%')
- or u.name like concat ('%',#{keyword},'%')
- or u1.name like concat ('%',#{keyword},'%')
- )
- </if>
- </where>
- order by fc.claim_datetime ASC
- </sql>
- <!--资产评估人员结算项目查询-->
- <select id="assetsEvaluatorSettleProd" resultMap="settleAssetsProductionVOMap">
- <include refid="assetsEvaluatorSettleSql" />
- </select>
- <!--资产评估人员结算项目导出-->
- <select id="assetsEvaluatorSettleExport" resultMap="settleAssetsProductionVOMap">
- <include refid="assetsEvaluatorSettleSql" />
- </select>
- <select id="exportList" parameterType="com.dayou.entity.FinanceRealFund" resultType="com.dayou.dto.FinanceRealFundExportDTO">
- <include refid="pageListSql" />
- ORDER BY frf.pay_datetime DESC
- </select>
- <sql id="realAmountClaimedSQL">
- SELECT
- claimd.id,
- fr.amount,
- fr.payer,
- fr.pay_datetime,
- fr.remark,
- claimd.claimAmount,
- claimd.claimDate,
- u.NAME AS creator,
- u1.NAME AS claimUser
- FROM
- (
- SELECT
- frf.id,
- sum( fc.claim_amount ) claimAmount,
- max( fc.claim_datetime ) claimDate,
- fc.claim_user_id
- FROM
- finance_claim fc
- LEFT JOIN finance_real_fund frf ON frf.id = fc.real_fund_id
- WHERE
- frf.deleted = 0
- AND fc.deleted = 0
- GROUP BY
- frf.id
- ) claimd
- LEFT JOIN finance_real_fund fr ON fr.id = claimd.id
- LEFT JOIN user u ON u.id = fr.creator_id
- LEFT JOIN user u1 ON u1.id = claimd.claim_user_id
- <where>
- <if test="keyword!=null and keyword!='' ">
- and (
- fr.payer like concat ('%',#{keyword},'%')
- or u1.name like concat('%',#{keyword},'%')
- or claimd.claimAmount = #{keyword}
- or fr.amount = #{keyword}
- or fr.remark like concat('%',#{keyword},'%')
- )
- </if>
- <if test="vo!=null and vo.startDate!=null and vo.startDate!=''">
- and fr.pay_datetime >= #{vo.startDate}
- </if>
- <if test="vo!=null and vo.endDate!=null and vo.endDate!=''">
- and fr.pay_datetime <= #{vo.endDate}
- </if>
- <if test="vo!=null and vo.xStartDate!=null and vo.xStartDate!=''">
- and claimd.claimDate >= #{vo.xStartDate}
- </if>
- <if test="vo!=null and vo.xEndDate!=null and vo.xEndDate!=''">
- and claimd.claimDate <= #{vo.xEndDate}
- </if>
- </where>
- ORDER BY
- claimd.claimDate DESC
- </sql>
- <select id="realAmountClaimed" parameterType="com.dayou.vo.FinanceRealFundVO" resultType="com.dayou.vo.FinanceRealFundVO">
- <include refid="realAmountClaimedSQL" />
- </select>
- <select id="realClaimedExport" parameterType="com.dayou.vo.FinanceRealFundVO" resultType="com.dayou.dto.FinanceRealFundExportDTO">
- <include refid="realAmountClaimedSQL" />
- </select>
- <select id="financeRealFundNotClaimExport" parameterType="com.dayou.entity.FinanceRealFund" resultType="com.dayou.dto.FinanceRealNotClaimDTO">
- <include refid="pageListSql" />
- ORDER BY
- ifnull(t.ca,0) ASC ,frf.created DESC
- </select>
- </mapper>
|