Files
intc-cloud/intc-modules/intc-invest/src/main/resources/mapper/invest/StatisticAnalysisMapper.xml

898 lines
26 KiB
XML

<?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.intc.invest.mapper.StatisticAnalysisMapper">
<resultMap type="BankCardLendVo" id="BankCardLendResult">
<result property="id" column="id" />
<result property="name" column="name" />
<result property="type" column="type" />
<result property="code" column="code" />
<result property="openingBank" column="opening_bank" />
<result property="activationDate" column="activation_date" />
<result property="billDate" column="bill_date" />
<result property="payDate" column="pay_date" />
<result property="delayPeriod" column="delay_period" />
<result property="creditLimit" column="credit_limit" />
<result property="effectiveDate" column="effective_date" />
<result property="cvv" column="cvv" />
<result property="createBy" column="create_by" />
<result property="createTime" column="create_time" />
<result property="updateBy" column="update_by" />
<result property="updateTime" column="update_time" />
<result property="delFlag" column="del_flag" />
<result property="remark" column="remark" />
<result property="debitType" column="debit_type" />
<result property="lendType" column="lend_type" />
</resultMap>
<sql id="selectBankCardLendVo">
select
a.name,
a.type,
a.credit_limit
from
bank_card_lend a
</sql>
<select id="selectBankCardLendList" parameterType="BankCardLendDto" resultMap="BankCardLendResult">
<include refid="selectBankCardLendVo"/>
<where>
a.del_flag='0'
<if test="name != null and name != ''"> and a.name like '%'|| #{name}||'%'</if>
<if test="type != null and type != ''"> and a.type = #{type}</if>
<if test="creditCardId != null "> and a.id = #{creditCardId}</if>
<if test="lendType != null and lendType != ''"> and a.lend_type = #{lendType}</if>
</where>
<!-- 数据范围过滤 -->
${params.dataScope}
</select>
<resultMap type="AccountsDealRecordVo" id="AccountsDealRecordResult">
<result property="id" column="id" />
<result property="name" column="name" />
<result property="code" column="code" />
<result property="type" column="type" />
<result property="accountId" column="account_id" />
<result property="amount" column="amount" />
<result property="dealType" column="deal_type" />
<result property="createBy" column="create_by" />
<result property="createTime" column="create_time" />
<result property="updateBy" column="update_by" />
<result property="updateTime" column="update_time" />
<result property="delFlag" column="del_flag" />
<result property="remark" column="remark" />
<result property="dealCategory" column="deal_category" />
<result property="accountName" column="account_name" />
<result property="transferRecordId" column="transfer_record_id" />
<result property="currentBalance" column="current_balance" />
<result property="childCategory" column="child_category" />
</resultMap>
<select id="selectAccountsOutInList" parameterType="AccountsDealRecordDto" resultMap="AccountsDealRecordResult">
select
a.*
from
(
select
atr.id ,
'13' as deal_category,
'2' as deal_type,
atr.commission as amount,
atr.create_time ,
atr.pos_id as account_id ,
atr.create_by,
atr.remark,
p."name" as account_name ,
p.code
from
accounts_transfer_record atr
left join accounts p on
p.id = atr.pos_id
where
atr."type" = '1'
and atr.del_flag = '0'
union
select
ihd.id ,
case
when ihd."type" = '2' then '14'
when ihd."type" = '3' then '15'
end as deal_category,
'2' as deal_type,
ihd.interest as amount,
ihd.repayment_date as create_time,
ihd.bank_card_lend_id as account_id ,
ihd.create_by,
ihd.remark,
a."name" as account_name ,
a.code
from
installment_history_detail ihd
left join accounts a on
a.id = ihd.bank_card_lend_id
where
ihd.del_flag = '0'
union
select
adr.id ,
adr.deal_category,
adr.deal_type,
adr.amount,
adr.create_time ,
adr.account_id ,
adr.create_by,
adr.remark,
a."name" as account_name ,
a.code
from
accounts_deal_record adr
left join accounts a on
a.id = adr.account_id
where
adr.del_flag = '0'
and (
adr.deal_category = '1'
or adr.deal_category = '2'
or adr.deal_category = '11'
)
) a
<where>
1=1
<if test="endTime!=null and endTime !=''">
and #{endTime}>=to_char(a.create_time, 'yyyy-MM-dd')
</if>
<if test="startTime!=null and startTime !=''">
and to_char(a.create_time, 'yyyy-MM-dd')>=#{startTime}
</if>
<if test="dealCategory != null and dealCategory != ''"> and a.deal_category = #{dealCategory}</if>
</where>
<!-- 数据范围过滤 -->
${params.dataScope}
order by a.create_time desc
</select>
<select id="selectDailyExpensesList" parameterType="AccountsDealRecordDto" resultMap="AccountsDealRecordResult">
select
sum(a.amount) as amount ,
a.child_category
from
accounts_deal_record a
<where>
a.del_flag='0'
and a.deal_category = '1'
<if test="endTime!=null and endTime !=''">
and #{endTime}>=to_char(a.create_time, 'yyyy-MM-dd')
</if>
<if test="startTime!=null and startTime !=''">
and to_char(a.create_time, 'yyyy-MM-dd')>=#{startTime}
</if>
<if test="accountId != null and accountId != ''"> and a.account_id = #{accountId}</if>
<if test="childCategory != null and childCategory != ''"> and a.child_category = #{childCategory}</if>
</where>
<!-- 数据范围过滤 -->
${params.dataScope}
group by
a.child_category
order by sum(a.amount) desc
</select>
<resultMap type="AccountCalendarVo" id="AccountCalendarResult">
<result property="title" column="title" />
<result property="name" column="name" />
<result property="start" column="start" />
<result property="color" column="color" />
</resultMap>
<select id="selectDailyExpensesByDate" parameterType="AccountsDealRecordDto" resultMap="AccountCalendarResult">
select
to_char(a.create_time,
'yyyy-MM-dd') as start,
concat('日常支出:',
sum(a.amount)) as title,
'magenta' as color,
5 as type
from
accounts_deal_record a
<where>
a.del_flag='0'
and a.deal_type = '2'
and a.deal_category = '1'
<if test="endTime!=null and endTime !=''">
and #{endTime}>=to_char(a.create_time, 'yyyy-MM-dd')
</if>
<if test="startTime!=null and startTime !=''">
and to_char(a.create_time, 'yyyy-MM-dd')>=#{startTime}
</if>
</where>
<!-- 数据范围过滤 -->
${params.dataScope}
group by
to_char(a.create_time,
'yyyy-MM-dd')
</select>
<select id="selectSalaryByDate" parameterType="AccountsDealRecordDto" resultMap="AccountCalendarResult">
select
to_char(a.create_time,
'yyyy-MM-dd') as start,
concat('工资收入:',
sum(a.amount)) as title,
8 as type
from
accounts_deal_record a
<where>
a.del_flag='0'
and a.deal_type = '1'
and a.deal_category = '11'
<if test="endTime!=null and endTime !=''">
and #{endTime}>=to_char(a.create_time, 'yyyy-MM-dd')
</if>
<if test="startTime!=null and startTime !=''">
and to_char(a.create_time, 'yyyy-MM-dd')>=#{startTime}
</if>
</where>
<!-- 数据范围过滤 -->
${params.dataScope}
group by
to_char(a.create_time,
'yyyy-MM-dd')
</select>
<select id="selectDailyExpensesDateList" parameterType="AccountsDealRecordDto" resultMap="AccountsDealRecordResult">
select
sum(a.amount) as amount ,
to_char(a.create_time,
'yyyy-MM-dd') as dateStr
from
accounts_deal_record a
<where>
a.del_flag = '0'
and a.deal_type = '2'
and a.deal_category = '1'
<if test="endTime!=null and endTime !=''">
and #{endTime}>=to_char(a.create_time, 'yyyy-MM-dd')
</if>
<if test="startTime!=null and startTime !=''">
and to_char(a.create_time, 'yyyy-MM-dd')>=#{startTime}
</if>
</where>
<!-- 数据范围过滤 -->
${params.dataScope}
group by
to_char(a.create_time,
'yyyy-MM-dd')
order by
to_char(a.create_time,
'yyyy-MM-dd') desc
</select>
<select id="selectCreditCardList" parameterType="BankCardLendDto" resultType="com.intc.invest.domain.vo.AccountsVo">
select
a."name" ,
sum(a.available_limit) as availableLimit
from
accounts a
where
a."type" = '2'
and a.status = '1'
<!-- 数据范围过滤 -->
${params.dataScope}
group by a."name"
</select>
<select id="selectDebitCardPosList" parameterType="AccountsDto" resultType="com.intc.invest.domain.vo.AccountsDebitPosVo">
select
t.*
from
(
select
a.id ,
a."name" ,
a.code ,
a.create_by,
(
select
case
when sum(atr.actual_amount) is null then 0
else sum(atr.actual_amount)
end
from
accounts_transfer_record atr
where
atr.type = '1'
and atr.del_flag = '0'
and atr.in_account_id = a.id
and to_char( atr.create_time,
'yyyy-MM-dd') = to_char(CURRENT_DATE,
'yyyy-MM-dd')
) as todayAmount
,
(
select
count(atr.actual_amount)
from
accounts_transfer_record atr
where
atr.type = '1'
and atr.del_flag = '0'
and atr.in_account_id = a.id
and to_char( atr.create_time,
'yyyy-MM-dd') = to_char(CURRENT_DATE,
'yyyy-MM-dd')
) as todayCount,
(
select
case
when sum(atr.actual_amount) is null then 0
else sum(atr.actual_amount)
end
from
accounts_transfer_record atr
where
atr.type = '1'
and atr.del_flag = '0'
and atr.in_account_id = a.id
and atr.create_time >= CURRENT_DATE - interval '7 days'
) as sevenDayAmount
,
(
select
count(atr.actual_amount)
from
accounts_transfer_record atr
where
atr.type = '1'
and atr.del_flag = '0'
and atr.in_account_id = a.id
and atr.create_time >= CURRENT_DATE - interval '7 days'
) as sevenDayCount,
(
select
case
when sum(atr.actual_amount) is null then 0
else sum(atr.actual_amount)
end
from
accounts_transfer_record atr
where
atr.type = '1'
and atr.del_flag = '0'
and atr.in_account_id = a.id
and atr.create_time >= CURRENT_DATE - interval '1 months'
) as oneMonthAmount
,
(
select
count(atr.actual_amount)
from
accounts_transfer_record atr
where
atr.type = '1'
and atr.del_flag = '0'
and atr.in_account_id = a.id
and atr.create_time >= CURRENT_DATE - interval '1 months'
) as oneMonthCount,
(
select
case
when sum(atr.actual_amount) is null then 0
else sum(atr.actual_amount)
end
from
accounts_transfer_record atr
where
atr.type = '1'
and atr.del_flag = '0'
and atr.in_account_id = a.id
and atr.create_time >= CURRENT_DATE - interval '3 months'
) as threeMonthAmount ,
(
select
count(atr.actual_amount)
from
accounts_transfer_record atr
where
atr.type = '1'
and atr.del_flag = '0'
and atr.in_account_id = a.id
and atr.create_time >= CURRENT_DATE - interval '3 months'
) as threeMonthCount,
(
select
case
when sum(atr.actual_amount) is null then 0
else sum(atr.actual_amount)
end
from
accounts_transfer_record atr
where
atr.type = '1'
and atr.del_flag = '0'
and atr.in_account_id = a.id
and atr.create_time >= CURRENT_DATE - interval '6 months'
) as sixMonthAmount,
(
select
count(atr.actual_amount)
from
accounts_transfer_record atr
where
atr.type = '1'
and atr.del_flag = '0'
and atr.in_account_id = a.id
and atr.create_time >= CURRENT_DATE - interval '6 months'
) as sixMonthCount,
(
select
case
when sum(atr.actual_amount) is null then 0
else sum(atr.actual_amount)
end
from
accounts_transfer_record atr
where
atr.type = '1'
and atr.del_flag = '0'
and atr.in_account_id = a.id
and atr.create_time >= CURRENT_DATE - interval '1 years'
) as oneYearAmount,
(
select
count(atr.actual_amount)
from
accounts_transfer_record atr
where
atr.type = '1'
and atr.del_flag = '0'
and atr.in_account_id = a.id
and atr.create_time >= CURRENT_DATE - interval '1 years'
) as oneYearCount,
(
select
case
when sum(atr.actual_amount) is null then 0
else sum(atr.actual_amount)
end
from
accounts_transfer_record atr
where
atr.type = '1'
and atr.del_flag = '0'
and atr.in_account_id = a.id
and atr.create_time >= CURRENT_DATE - interval '2 years'
) as twoYearAmount,
(
select
count(atr.actual_amount)
from
accounts_transfer_record atr
where
atr.type = '1'
and atr.del_flag = '0'
and atr.in_account_id = a.id
and atr.create_time >= CURRENT_DATE - interval '2 years'
) as twoYearCount,
(
select
case
when sum(atr.actual_amount) is null then 0
else sum(atr.actual_amount)
end
from
accounts_transfer_record atr
where
atr.type = '1'
and atr.del_flag = '0'
and atr.in_account_id = a.id
and atr.create_time >= CURRENT_DATE - interval '5 years'
) as fiveYearAmount,
(
select
count(atr.actual_amount)
from
accounts_transfer_record atr
where
atr.type = '1'
and atr.del_flag = '0'
and atr.in_account_id = a.id
and atr.create_time >= CURRENT_DATE - interval '5 years'
) as fiveYearCount,
(
select
case
when sum(atr.actual_amount) is null then 0
else sum(atr.actual_amount)
end
from
accounts_transfer_record atr
where
atr.type = '1'
and atr.del_flag = '0'
and atr.in_account_id = a.id
) as totalAmount,
(
select
count(atr.actual_amount)
from
accounts_transfer_record atr
where
atr.type = '1'
and atr.del_flag = '0'
and atr.in_account_id = a.id
) as totalCount
from
accounts a
where
a.status = '1'
and a."type" = '1'
and a.del_flag = '0'
and a.account_id in
(
select
distinct adr.account_id
from
accounts_deal_record adr
where
adr.deal_category = '5'
and adr.del_flag = '0' )) t
where 0=0
<!-- 数据范围过滤 -->
${params.dataScope}
order by
t.oneMonthCount desc
</select>
<select id="selectPosStaticList" parameterType="AccountsDto" resultType="com.intc.invest.domain.vo.AccountsDebitPosVo">
select
t.*
from
(
select
a.id ,
a."name" ,
a.merchant_name as merchantName,
a.pay_company as payCompany,
a.create_by,
(
select
case
when sum(atr.amount) is null then 0
else sum(atr.amount)
end
from
accounts_transfer_record atr
where
atr.type = '1'
and atr.del_flag = '0'
and atr.pos_id = a.id
and to_char( atr.create_time,
'yyyy-MM-dd') = to_char(CURRENT_DATE,
'yyyy-MM-dd')
) as todayAmount
,
(
select
count(atr.amount)
from
accounts_transfer_record atr
where
atr.type = '1'
and atr.del_flag = '0'
and atr.pos_id = a.id
and to_char( atr.create_time,
'yyyy-MM-dd') = to_char(CURRENT_DATE,
'yyyy-MM-dd')
) as todayCount,
(
select
case
when sum(atr.amount) is null then 0
else sum(atr.amount)
end
from
accounts_transfer_record atr
where
atr.type = '1'
and atr.del_flag = '0'
and atr.pos_id = a.id
and atr.create_time >= CURRENT_DATE - interval '7 days'
) as sevenDayAmount
,
(
select
count(atr.amount)
from
accounts_transfer_record atr
where
atr.type = '1'
and atr.del_flag = '0'
and atr.pos_id = a.id
and atr.create_time >= CURRENT_DATE - interval '7 days'
) as sevenDayCount,
(
select
case
when sum(atr.amount) is null then 0
else sum(atr.amount)
end
from
accounts_transfer_record atr
where
atr.type = '1'
and atr.del_flag = '0'
and atr.pos_id = a.id
and atr.create_time >= CURRENT_DATE - interval '1 months'
) as oneMonthAmount
,
(
select
count(atr.amount)
from
accounts_transfer_record atr
where
atr.type = '1'
and atr.del_flag = '0'
and atr.pos_id = a.id
and atr.create_time >= CURRENT_DATE - interval '1 months'
) as oneMonthCount,
(
select
case
when sum(atr.amount) is null then 0
else sum(atr.amount)
end
from
accounts_transfer_record atr
where
atr.type = '1'
and atr.del_flag = '0'
and atr.pos_id = a.id
and atr.create_time >= CURRENT_DATE - interval '3 months'
) as threeMonthAmount ,
(
select
count(atr.amount)
from
accounts_transfer_record atr
where
atr.type = '1'
and atr.del_flag = '0'
and atr.pos_id = a.id
and atr.create_time >= CURRENT_DATE - interval '3 months'
) as threeMonthCount,
(
select
case
when sum(atr.amount) is null then 0
else sum(atr.amount)
end
from
accounts_transfer_record atr
where
atr.type = '1'
and atr.del_flag = '0'
and atr.pos_id = a.id
and atr.create_time >= CURRENT_DATE - interval '6 months'
) as sixMonthAmount,
(
select
count(atr.amount)
from
accounts_transfer_record atr
where
atr.type = '1'
and atr.del_flag = '0'
and atr.pos_id = a.id
and atr.create_time >= CURRENT_DATE - interval '6 months'
) as sixMonthCount,
(
select
case
when sum(atr.amount) is null then 0
else sum(atr.amount)
end
from
accounts_transfer_record atr
where
atr.type = '1'
and atr.del_flag = '0'
and atr.pos_id = a.id
and atr.create_time >= CURRENT_DATE - interval '1 years'
) as oneYearAmount,
(
select
count(atr.amount)
from
accounts_transfer_record atr
where
atr.type = '1'
and atr.del_flag = '0'
and atr.pos_id = a.id
and atr.create_time >= CURRENT_DATE - interval '1 years'
) as oneYearCount,
(
select
case
when sum(atr.amount) is null then 0
else sum(atr.amount)
end
from
accounts_transfer_record atr
where
atr.type = '1'
and atr.del_flag = '0'
and atr.pos_id = a.id
and atr.create_time >= CURRENT_DATE - interval '2 years'
) as twoYearAmount,
(
select
count(atr.amount)
from
accounts_transfer_record atr
where
atr.type = '1'
and atr.del_flag = '0'
and atr.pos_id = a.id
and atr.create_time >= CURRENT_DATE - interval '2 years'
) as twoYearCount,
(
select
case
when sum(atr.amount) is null then 0
else sum(atr.amount)
end
from
accounts_transfer_record atr
where
atr.type = '1'
and atr.del_flag = '0'
and atr.pos_id = a.id
and atr.create_time >= CURRENT_DATE - interval '5 years'
) as fiveYearAmount,
(
select
count(atr.amount)
from
accounts_transfer_record atr
where
atr.type = '1'
and atr.del_flag = '0'
and atr.pos_id = a.id
and atr.create_time >= CURRENT_DATE - interval '5 years'
) as fiveYearCount,
(
select
case
when sum(atr.amount) is null then 0
else sum(atr.amount)
end
from
accounts_transfer_record atr
where
atr.type = '1'
and atr.del_flag = '0'
and atr.pos_id = a.id
) as totalAmount,
(
select
count(atr.amount)
from
accounts_transfer_record atr
where
atr.type = '1'
and atr.del_flag = '0'
and atr.pos_id = a.id
) as totalCount
from
pos_machine a
where
a.del_flag = '0'
) t
where 0=0
<!-- 数据范围过滤 -->
${params.dataScope}
order by
t.oneMonthCount desc
</select>
<resultMap type="AccountsVo" id="AccountsResult">
<result property="id" column="id" />
<result property="name" column="name" />
<result property="type" column="type" />
<result property="code" column="code" />
<result property="balance" column="balance" />
<result property="creditLimit" column="credit_limit" />
<result property="availableLimit" column="available_limit" />
<result property="createBy" column="create_by" />
<result property="createTime" column="create_time" />
<result property="updateBy" column="update_by" />
<result property="updateTime" column="update_time" />
<result property="delFlag" column="del_flag" />
<result property="remark" column="remark" />
<result property="accountId" column="account_id" />
<result property="state" column="state" />
<result property="billDate" column="bill_date" />
<result property="payDate" column="pay_date" />
<result property="creditLimit" column="credit_limit" />
<result property="debitType" column="debit_type" />
<result property="lendType" column="lend_type" />
<result property="status" column="status" />
<result property="recentDealTime" column="recent_deal_time" />
</resultMap>
<select id="selectAccountsList" parameterType="AccountsDto" resultMap="AccountsResult">
select
t.*
from
(
select
a.id,
a.name,
a.type,
a.code,
a.balance,
a.credit_limit,
a.available_limit,
a.create_by,
a.create_time,
a.update_by,
a.update_time,
a.del_flag,
a.remark,
a.account_id,
a.state,
a.status,
bcl.bill_date ,
bcl.pay_date ,
bcl.credit_limit ,
bcl.debit_type,
bcl.lend_type,
case
when (
select
create_time
from
accounts_deal_record adr
where
adr.account_id = a.account_id
order by
adr.create_time desc
limit 1
) is null then a.create_time
else
(
select
create_time
from
accounts_deal_record adr
where
adr.account_id = a.account_id
order by
adr.create_time desc
limit 1
)
end
as recent_deal_time
from
accounts a
left join bank_card_lend bcl on
bcl.id = a.id
<where>
a.del_flag='0'
and ( a.type ='1')
and( a.status != '2' and a.status != '0')
<if test="name != null and name != ''">and a.name like '%'|| #{name}||'%'</if>
<if test="accountId != null and accountId != ''"> and a.account_id = #{accountId}</if>
<if test="repayFlag != null and repayFlag != ''"> and bcl.debit_type in('1','2') </if>
</where>
<!-- 数据范围过滤 -->
${params.dataScope}
) t
order by t.recent_deal_time asc
</select>
</mapper>