|
@@ -799,7 +799,7 @@
|
|
|
# ,
|
|
|
# u.name,
|
|
|
# commissionTotalAmount
|
|
|
-# having 1=1
|
|
|
+ having 1=1
|
|
|
<if test="vo!=null and vo.userName!=null and vo.userName!=''">
|
|
|
and u.name like concat ('%',#{vo.userName},'%')
|
|
|
</if>
|
|
@@ -820,8 +820,14 @@
|
|
|
bcr.min_ratio AS ratio,
|
|
|
bpd.member_id,
|
|
|
bpd.performance_distribution AS allotRatio,
|
|
|
- ( fc.claim_amount * ( bcr.min_ratio / 100 )* bpd.performance_distribution ) AS commissionAmount,
|
|
|
- ( fc.claim_amount * ( bcr.min_ratio / 100 ) ) AS totalAmount,
|
|
|
+ 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
|
|
|
FROM
|
|
|
(
|
|
@@ -853,7 +859,7 @@
|
|
|
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, project_name, production_no, production_type, save_file_date, created 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
|
|
|
- INNER JOIN ( SELECT id, business_id, production_id, commission_rate_id FROM commission_declare WHERE business_type = 'COMMISSION_DECLARE_ASSET_EVALUATE' AND deleted = 0 AND declare_result = '审核通过' ) cd ON (
|
|
|
+ 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
|
|
@@ -864,4 +870,619 @@
|
|
|
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 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,
|
|
|
+ project_name,
|
|
|
+ production_no,
|
|
|
+ production_type,
|
|
|
+ save_file_date,
|
|
|
+ created
|
|
|
+ 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
|
|
|
+ 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.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.project_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(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
|
|
|
+ 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, project_name, production_no, production_type, save_file_date, created 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
|
|
|
+ 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, project_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.project_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, project_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,
|
|
|
+ project_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.project_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, project_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,
|
|
|
+ project_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>
|
|
|
+
|
|
|
+ <!--资产市场人员结算项目Sql-->
|
|
|
+ <sql id="assetsMarketerSettleSql">
|
|
|
+ SELECT
|
|
|
+ ap.id,
|
|
|
+ fc.claim_amount,
|
|
|
+ a.order_id,
|
|
|
+ ap.production_no,
|
|
|
+ fc.claim_datetime as claimDate,
|
|
|
+ ap.delivery_date,
|
|
|
+ ap.save_file_date,
|
|
|
+ IF
|
|
|
+ ( fc.claim_datetime > ap.delivery_date, fc.claim_datetime, ap.delivery_date ) AS settleDate,
|
|
|
+ ap.project_name,
|
|
|
+ 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
|
|
|
+ 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, project_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
|
|
|
+ <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" resultType="com.dayou.vo.SettleAssetsProductionVO">
|
|
|
+ <include refid="assetsMarketerSettleSql" />
|
|
|
+ </select>
|
|
|
+
|
|
|
+ <!--资产结算项目导出-->
|
|
|
+ <select id="assetsMarketSettleExport" resultType="com.dayou.vo.SettleAssetsProductionVO">
|
|
|
+ <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.project_name,
|
|
|
+ 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
|
|
|
+ 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, project_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
|
|
|
+ <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" resultType="com.dayou.vo.SettleAssetsProductionVO">
|
|
|
+ <include refid="assetsEvaluatorSettleSql" />
|
|
|
+ </select>
|
|
|
+
|
|
|
+ <!--资产评估人员结算项目导出-->
|
|
|
+ <select id="assetsEvaluatorSettleExport" resultType="com.dayou.vo.SettleAssetsProductionVO">
|
|
|
+ <include refid="assetsEvaluatorSettleSql" />
|
|
|
+ </select>
|
|
|
+
|
|
|
</mapper>
|