123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367 |
- <?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.FinanceClaimMapper">
- <!-- 通用查询映射结果 -->
- <resultMap id="BaseResultMap" type="com.dayou.entity.FinanceClaim">
- <result column="id" property="id" />
- <result column="created" property="created" />
- <result column="deleted" property="deleted" />
- <result column="modified" property="modified" />
- <result column="real_fund_id" property="realFundId" />
- <result column="production_fund_id" property="productionFundId" />
- <result column="claim_user_id" property="claimUserId" />
- <result column="claim_datetime" property="claimDatetime" />
- <result column="claim_amount" property="claimAmount" />
- </resultMap>
- <!-- 通用查询结果列 -->
- <sql id="Base_Column_List">
- id,
- created,
- deleted,
- modified,
- real_fund_id, production_fund_id, claim_user_id, claim_datetime, claim_amount
- </sql>
- <select id="getList" parameterType="com.dayou.entity.FinanceClaim" resultType="com.dayou.vo.FinanceClaimVO">
- SELECT
- fc.id,
- fc.real_fund_id,
- ( CASE orf.business_type WHEN 'MAJOR_BUSINESS' THEN '大中型业务' WHEN 'PERSONAL_BUSINESS' THEN '个贷业务' WHEN 'ASSET_BUSINESS' THEN '资产业务' WHEN 'ITEM_BUSINESS' THEN '土规业务' ELSE '-' END ) AS businessType,
- orf.should_amount,
- fc.claim_amount,
- u.NAME AS claimName,
- fc.created,
- orf.order_id,
- orf.order_name,
- orf.remark,
- off.production_should_amount,
- off.production_no
- FROM
- finance_claim fc
- LEFT JOIN order_fund orf ON fc.order_fund_id = orf.id
- LEFT JOIN ( SELECT id,order_fund_id,production_no,production_should_amount FROM production_fund WHERE deleted = 0) off ON (off.order_fund_id = fc.order_fund_id and fc.production_fund_id = off.id)
- LEFT JOIN user u ON u.id = fc.claim_user_id
- WHERE
- fc.real_fund_id = #{realFundId}
- AND fc.deleted = 0
- ORDER BY
- fc.created DESC
- </select>
- <select id="getTotalClaimAmountByProductionFundId" parameterType="java.lang.Long" resultType="java.math.BigDecimal">
- select ifnull(sum(claim_amount),0) from finance_claim where production_fund_id = #{productionFundId} and deleted = 0
- </select>
- <select id="getTotalClaimAmountByOrderFundId" parameterType="java.lang.Long" resultType="java.math.BigDecimal">
- select ifnull(sum(claim_amount),0) from finance_claim where order_fund_id = #{orderFundId} and deleted = 0
- </select>
- <select id="residueAmount" parameterType="java.lang.Long" resultType="java.math.BigDecimal">
- SELECT amount -( SELECT IFNULL( sum( claim_amount ), 0 ) FROM `finance_claim` WHERE deleted = 0 AND real_fund_id = #{financeFundId} ) AS residueAmount
- FROM
- finance_real_fund
- WHERE
- id = #{financeFundId} and deleted = 0
- </select>
- <sql id="majorStatQuery">
- SELECT
- fc.*,
- f.oId,
- f.pId,
- f.production_no as reportNo,
- f.order_id,
- f.should_amount as orderShouldAmount,
- m.financial,
- m.members,
- m.bailor,
- m.NAME AS orderName,
- mp.NAME,
- mp.if_save_file,
- mp.evaluate_amount,
- mp.production as productionType,
- u.NAME AS clientManager,
- u1.NAME AS principal,
- cc1.NAME AS clientName,
- cc2.NAME AS clientSubName,
- frf.pay_datetime,
- frf.payer,
- u2.NAME AS claimUser,
- d.NAME AS evaluateDepartment,
- (
- SELECT
- GROUP_CONCAT( NAME SEPARATOR '、' )
- FROM
- department
- WHERE
- id IN (
- SELECT
- department_id
- FROM
- post
- WHERE
- id IN ( SELECT post_id FROM user_post WHERE user_id = u.id ))) AS marketDepartment
- FROM
- (
- SELECT
- p.order_fund_id oId,
- p.id AS pId,
- p.business_id,
- o.order_id,
- p.production_no,
- o.should_amount
- FROM
- production_fund p left join (select id,order_id,should_amount from order_fund where business_type='MAJOR_BUSINESS' and deleted = 0) o on o.id = p.order_fund_id
- WHERE
- p.business_type = 'MAJOR_BUSINESS'
- AND p.deleted = 0
- ) f
- INNER JOIN finance_claim fc ON
- ( fc.order_fund_id = f.oId and fc.production_fund_id = f.pId)
- LEFT JOIN major m ON f.business_id = m.id
- LEFT JOIN user u ON u.id = m.client_manager_id
- LEFT JOIN user u1 ON u1.id = m.principal_id
- LEFT JOIN department d ON d.id = m.department_id
- LEFT JOIN customer_company cc1 ON cc1.id = m.clientele_id
- LEFT JOIN customer_company cc2 ON cc2.id = m.clientele_sub_id
- LEFT JOIN customer_linkman cl1 ON cl1.id = m.clientele_contact_id
- LEFT JOIN finance_real_fund frf ON frf.id = fc.real_fund_id
- LEFT JOIN ( SELECT major_id, report_no,production, evaluate_amount, if_save_file, NAME FROM major_production WHERE deleted = 0 ) mp ON ( mp.major_id = m.id AND mp.report_no = f.production_no )
- LEFT JOIN user u2 ON u2.id = fc.claim_user_id
- where m.deleted = 0
- <if test="keyword!=null and keyword!='' ">
- and (
- f.order_id like concat ('%',#{keyword},'%')
- or f.production_no like concat ('%',#{keyword},'%')
- or u1.name like concat ('%',#{keyword},'%')
- or fc.claim_amount = #{keyword}
- or u2.NAME like concat ('%',#{keyword},'%')
- )
- </if>
- <if test="majorStat!=null and majorStat.startDate!=null and majorStat.startDate!='' ">
- and fc.claim_datetime >= #{majorStat.startDate}
- </if>
- <if test="majorStat!=null and majorStat.endDate!=null and majorStat.endDate!='' ">
- and fc.claim_datetime <= #{majorStat.endDate}
- </if>
- <if test="majorStat!=null and majorStat.payStartDate!=null and majorStat.payStartDate!='' ">
- and frf.pay_datetime >= #{majorStat.payStartDate}
- </if>
- <if test="majorStat!=null and majorStat.payEndDate!=null and majorStat.payEndDate!='' ">
- and frf.pay_datetime <= #{majorStat.payEndDate}
- </if>
- <if test="majorStat!=null and majorStat.ifSaveFile!=null ">
- and mp.if_save_file = #{majorStat.ifSaveFile}
- </if>
- <if test="majorStat!=null and majorStat.financial!=null ">
- and m.financial = #{majorStat.financial}
- </if>
- </sql>
- <select id="majorStat" parameterType="com.dayou.vo.RealFundMajorStatVO" resultType="com.dayou.vo.RealFundMajorStatVO">
- <include refid="majorStatQuery" />
- ORDER BY
- fc.claim_datetime DESC
- </select>
- <select id="majorStatExport" parameterType="com.dayou.vo.RealFundMajorStatVO" resultType="com.dayou.vo.RealFundMajorStatVO">
- <include refid="majorStatQuery" />
- ORDER BY
- fc.claim_datetime ASC
- </select>
- <!--资产实收款统计-->
- <sql id="assetsStatQuery">
- SELECT
- claim.real_fund_id,
- claim.order_fund_id,
- claim.production_fund_id,
- claim.id,
- prod.production_no AS reportNo,
- assets.order_id AS orderId,
- assets.`name` AS orderName,
- (
- SELECT
- GROUP_CONCAT( department.name SEPARATOR '、' )
- FROM
- department,
- post,
- user_post,
- `user`
- WHERE
- `user`.id = user_post.user_id
- AND user_post.post_id = post.id
- AND post.department_id = department.id
- AND `user`.id = assets.client_manager_id
- AND user_post.deleted = 0
- ) AS marketDepartment,
- ( SELECT department.name FROM department WHERE department.id = assets.department_id ) AS evaluateDepartment,
- managerUser.name AS clientManagerName,
- principalUser.name AS principalName,
- realFund.payer AS payer,
- realFund.pay_datetime AS payDateTime,
- order_fund.should_amount AS orderShouldAmount,
- prodFund.production_should_amount AS prodShouldAmount,
- claim.claim_amount AS claimAmount,
- claimUser.name AS claimUser,
- claim.claim_datetime AS claimDatetime,
- assets.assets_business_gener AS assetsBusinessGener,
- ( SELECT customer_company.name FROM customer_company WHERE customer_company.id = assets.clientele_id ) AS clientName,
- ( SELECT customer_company.name FROM customer_company WHERE customer_company.id = assets.clientele_sub_id ) AS clientSubName,
- assets.bailor AS bailor,
- prod.evaluate_amount,
- (
- CASE
- WHEN prod.production_type = 'REPORT' THEN '评估报告'
- WHEN prod.production_type = 'CONSULT' THEN '咨询报告'
- WHEN prod.production_type = 'LETTER' THEN '意见函'
- ELSE '其他'
- END
- ) AS productionType,
- prod.if_save_file AS ifSaveFile
- FROM
- finance_claim AS claim
- LEFT JOIN finance_real_fund AS realFund ON realFund.id = claim.real_fund_id
- LEFT JOIN order_fund ON order_fund.id = claim.order_fund_id
- LEFT JOIN production_fund AS prodFund ON prodFund.id = claim.production_fund_id
- LEFT JOIN assets ON assets.id = order_fund.business_id
- AND assets.order_id = order_fund.order_id
- LEFT JOIN `user` AS managerUser ON managerUser.id = assets.client_manager_id
- LEFT JOIN `user` AS principalUser ON principalUser.id = assets.principal_id
- LEFT JOIN `user` AS claimUser ON claimUser.id = claim.claim_user_id
- LEFT JOIN assets_production AS prod ON assets.id = prod.business_id AND prodFund.production_no = prod.production_no
- WHERE order_fund.business_type = 'ASSET_BUSINESS'
- <if test="keyword!=null and keyword!='' ">
- and (
- assets.order_id like concat ('%',#{keyword},'%')
- or prod.production_no like concat ('%',#{keyword},'%')
- )
- </if>
- <if test="dto != null and dto.principalId != null and dto.principalId != ''">
- AND assets.principal_id = #{dto.principalId}
- </if>
- <if test="dto != null and dto.claimUserId != null and dto.claimUserId != ''">
- AND claim.claim_user_id = #{dto.claimUserId}
- </if>
- <if test="dto != null and dto.claimAmount != null and dto.claimAmount != ''">
- AND claim.claim_amount = #{dto.claimAmount}
- </if>
- <if test="dto != null and dto.assetsBusinessGener != null and dto.assetsBusinessGener != ''">
- AND assets.assets_business_gener = #{dto.assetsBusinessGener}
- </if>
- <if test="dto != null and dto.ifSaveFile != null and dto.ifSaveFile != ''">
- AND prod.if_save_file = #{dto.ifSaveFile}
- </if>
- <if test="dto != null and dto.startTime != null and dto.endTime!= null">
- AND (claim.claim_datetime BETWEEN #{dto.startTime} AND #{dto.endTime})
- </if>
- <if test="dto != null and dto.payStartTime != null and dto.payEndTime!= null">
- AND (realFund.pay_datetime BETWEEN #{dto.payStartTime} AND #{dto.payEndTime})
- </if>
- ORDER BY claim.claim_datetime DESC
- </sql>
- <!--查询资产实收款统计-->
- <select id="assetsSate" parameterType="com.dayou.dto.RealFundAssetsStatDTO" resultType="com.dayou.vo.RealFundAssetsStatVO">
- <include refid="assetsStatQuery" />
- </select>
- <!--资产实收款统计导出-->
- <select id="assetsSateExport" resultType="com.dayou.vo.RealFundAssetsStatVO">
- <include refid="assetsStatQuery" />
- </select>
- <sql id="personalStatSql">
- SELECT
- fc.*,
- f.should_amount,
- p.order_id,
- p.location,
- u.NAME AS clientManager,
- cc1.NAME AS clientName,
- cc2.NAME AS clientSubName,
- frf.pay_datetime,
- u2.NAME AS claimUser,
- p.bailorA,
- ( pt.amount / 10000 ) AS amount,
- p.if_save_file,
- (
- SELECT
- GROUP_CONCAT( NAME SEPARATOR '、' )
- FROM
- department
- WHERE
- id IN (
- SELECT
- department_id
- FROM
- post
- WHERE
- id IN ( SELECT post_id FROM user_post WHERE user_id = u.id ))) AS marketDepartment
- FROM
- (
- SELECT
- orderFund.id AS oId,
- orderFund.business_id,
- orderFund.order_id,
- orderFund.should_amount
- FROM
- order_fund orderFund
- WHERE
- orderFund.business_type = 'PERSONAL_BUSINESS'
- AND orderFund.deleted = 0
- ) f
- INNER JOIN finance_claim fc ON fc.order_fund_id = f.oId
- LEFT JOIN personal p ON f.business_id = p.id
- LEFT JOIN user u ON u.id = p.client_manager_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 finance_real_fund frf ON frf.id = fc.real_fund_id
- LEFT JOIN user u2 ON u2.id = fc.claim_user_id
- LEFT JOIN personal_target pt ON pt.personal_id = p.id
- WHERE
- p.deleted = 0
- <if test="dto != null and dto.orderId != null and dto.orderId != ''">
- AND p.order_id = #{dto.orderId}
- </if>
- <if test="dto != null and dto.claimUser != null and dto.claimUser != ''">
- AND u2.NAME like concat ('%',#{dto.claimUser},'%')
- </if>
- <if test="dto != null and dto.claimAmount != null and dto.claimAmount != ''">
- AND fc.claim_amount = #{dto.claimAmount}
- </if>
- <if test="dto != null and dto.ifSaveFile != null">
- AND p.if_save_file = #{dto.ifSaveFile}
- </if>
- <if test="dto != null and dto.startTime != null and dto.endTime!= null">
- AND (fc.claim_datetime BETWEEN #{dto.startTime} AND #{dto.endTime})
- </if>
- <if test="dto != null and dto.payStartTime != null and dto.payEndTime!= null">
- AND (frf.pay_datetime BETWEEN #{dto.payStartTime} AND #{dto.payEndTime})
- </if>
- ORDER BY
- fc.claim_datetime DESC
- </sql>
- <select id="personalStat" parameterType="com.dayou.vo.RealFundPersonalVO" resultType="com.dayou.vo.RealFundPersonalVO">
- <include refid="personalStatSql" />
- </select>
- <select id="personalStatExport" parameterType="com.dayou.vo.RealFundPersonalVO" resultType="com.dayou.vo.RealFundPersonalVO">
- <include refid="personalStatSql" />
- </select>
- <select id="queryOrderTotalAmount" resultType="com.dayou.entity.OrderFund">
- SELECT
- fc.order_fund_id as id,
- realAmount,
- oof.business_type
- FROM
- ( SELECT order_fund_id, sum( claim_amount ) realAmount FROM finance_claim WHERE deleted = 0 GROUP BY order_fund_id ) fc
- LEFT JOIN order_fund oof ON oof.id = fc.order_fund_id
- </select>
- </mapper>
|