|
@@ -2,82 +2,95 @@
|
|
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
|
|
<mapper namespace="com.dayou.mapper.BusinessIncomeMapper">
|
|
|
|
|
|
- <select id="myMajorIncome" parameterType="com.dayou.vo.UserCommissionProdVO" resultType="com.dayou.vo.UserCommissionProdVO">
|
|
|
+ <sql id="myMajorIncomeSql">
|
|
|
+ SELECT
|
|
|
+ mpa.id,
|
|
|
+ fc.claim_amount as realAmount,
|
|
|
+ mp.report_no,
|
|
|
+ if(mpa.user_type='EVALUATE',IF
|
|
|
+ ( fc.claim_datetime > mp.save_file_date, fc.claim_datetime, mp.save_file_date ),
|
|
|
+ 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,
|
|
|
+ (case mpa.user_type when 'EVALUATE' then '评估人员' else '市场人员' end) as userType
|
|
|
+ FROM
|
|
|
+ (
|
|
|
SELECT
|
|
|
- mpa.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,
|
|
|
- (case mpa.user_type when 'EVALUATE' then '评估人员' else '市场人员' end) as userType
|
|
|
+ claim_amount,
|
|
|
+ order_fund_id,
|
|
|
+ production_fund_id,
|
|
|
+ claim_datetime
|
|
|
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
|
|
|
+ finance_claim
|
|
|
+ WHERE
|
|
|
+ deleted = 0
|
|
|
+ AND production_fund_id IS NOT NULL
|
|
|
|
|
|
- ) 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, business_type ,commission_rate_id FROM commission_declare WHERE 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 id,major_id,user_type, major_production_id, user_id, ratio ,declare_id FROM major_production_allot WHERE deleted = 0 ) mpa
|
|
|
- ON ( mpa.major_id = m.id and mpa.major_production_id = mp.id
|
|
|
- and if(mpa.user_type='MARKET','COMMISSION_DECLARE_MAJOR_MARKET','COMMISSION_DECLARE_MAJOR_EVALUATE') = cd.business_type
|
|
|
- )
|
|
|
+ ) fc
|
|
|
+ INNER JOIN ( SELECT id,order_fund_id, business_id, production_no,production_type 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,
|
|
|
+ save_file_date
|
|
|
+ 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 and mp.production = pf.production_type)
|
|
|
+ LEFT JOIN major m ON m.id = mp.major_id
|
|
|
+ INNER JOIN ( SELECT id,business_id, production_id, business_type ,commission_rate_id FROM commission_declare WHERE 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 id,major_id,user_type, major_production_id, user_id, ratio ,declare_id FROM major_production_allot WHERE deleted = 0 ) mpa
|
|
|
+ ON ( mpa.major_id = m.id and mpa.major_production_id = mp.id
|
|
|
+ and if(mpa.user_type='MARKET','COMMISSION_DECLARE_MAJOR_MARKET','COMMISSION_DECLARE_MAJOR_EVALUATE') = cd.business_type
|
|
|
+ )
|
|
|
|
|
|
- left join user u on u.id = mpa.user_id
|
|
|
+ left join user u on u.id = mpa.user_id
|
|
|
|
|
|
WHERE
|
|
|
- u.id= #{vo.userId}
|
|
|
- <if test="vo!=null and vo.startDate!=null and vo.startDate!='' ">
|
|
|
- AND (select IF
|
|
|
+ u.id= #{vo.userId}
|
|
|
+ <if test="vo!=null and vo.startDate!=null and vo.endDate!=null">
|
|
|
+ and if(mpa.user_type='EVALUATE',( (select IF
|
|
|
+ ( fc.claim_datetime > mp.save_file_date, fc.claim_datetime, mp.save_file_date )) >= #{vo.startDate}
|
|
|
+ AND (select IF
|
|
|
+ ( fc.claim_datetime > mp.save_file_date, fc.claim_datetime, mp.save_file_date )) <= #{vo.endDate}),
|
|
|
+ ( (select IF
|
|
|
( fc.claim_datetime > mp.delivery_date, fc.claim_datetime, mp.delivery_date )) >= #{vo.startDate}
|
|
|
- </if>
|
|
|
- <if test="vo!=null and vo.endDate!=null and vo.endDate!='' ">
|
|
|
- AND (select IF
|
|
|
- ( fc.claim_datetime > mp.delivery_date, fc.claim_datetime, mp.delivery_date )) <= #{vo.endDate}
|
|
|
+ AND (select IF
|
|
|
+ ( fc.claim_datetime > mp.delivery_date, fc.claim_datetime, mp.delivery_date )) <= #{vo.endDate}))
|
|
|
</if>
|
|
|
order by settleDate DESC
|
|
|
+ </sql>
|
|
|
+
|
|
|
+ <select id="myMajorIncome" parameterType="com.dayou.vo.UserCommissionProdVO" resultType="com.dayou.vo.UserCommissionProdVO">
|
|
|
+ <include refid="myMajorIncomeSql" />
|
|
|
</select>
|
|
|
|
|
|
+ <select id="myMajorIncomeExport" parameterType="com.dayou.vo.UserCommissionProdVO" resultType="com.dayou.vo.UserCommissionProdVO">
|
|
|
+ <include refid="myMajorIncomeSql" />
|
|
|
+ </select>
|
|
|
<!--资产我的提成-->
|
|
|
<sql id="myAssetsIncomeSql">
|
|
|
SELECT bpd.id,
|