6009 个人收支汇总上期余额会出现负数

This commit is contained in:
gaowdong 2025-05-16 18:38:34 +08:00
parent 3504872a5a
commit 4d3b41ad07
1 changed files with 53 additions and 15 deletions

View File

@ -69,7 +69,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
at2.actual_amount
end, 0)) as income,
SUM(IFNULL(CASE
WHEN at2.trade_type in (30, 100, 110) then
WHEN at2.trade_type in (30, 100, 110, 120) then
at2.actual_amount
end, 0)) as outcome
from
@ -128,21 +128,21 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<select id="selectUserIncomeOutcome" resultType="com.bonus.canteen.core.report.domain.UserIncomeOutcomeVO">
SELECT
c.user_id,
b.user_id,
b.phonenumber,
b.dept_id,
b.dept_name,
b.dept_full_name,
b.nick_name,
c.wallet_bal_user as wallet_bal,
c.wallet_bal_user as wallet_bal_now,
(b.income - b.outcome) as wallet_bal_now,
b.income,
b.outcome,
(c.wallet_bal_user + b.outcome - b.income) as last_wallet_bal
(d.income - d.outcome) as last_wallet_bal
from
(
select
at2.user_id,
su.user_id,
su.nick_name,
su.phonenumber,
sd.dept_id,
@ -153,34 +153,73 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
at2.actual_amount
end, 0)) as income,
SUM(IFNULL(CASE
WHEN at2.trade_type in (30, 100, 110) then
WHEN at2.trade_type in (30, 100, 110, 120) then
at2.actual_amount
end, 0)) as outcome
from
acc_trade at2
left join sys_user su on
sys_user su
left join acc_trade at2 on
at2.user_id = su.user_id
and at2.trade_time <![CDATA[ >= ]]> #{param.startDateTime}
and at2.trade_time <![CDATA[ <= ]]> #{param.endDateTime}
and at2.pay_state = 3
left join sys_dept sd on
su.dept_id = sd.dept_id
where
at2.pay_state = 3
1 = 1
<if test="param.deptIdList != null and param.deptIdList.size() > 0">
and su.dept_id in
<foreach collection="param.deptIdList" item="deptId" separator="," open="(" close=")">
#{deptId}
</foreach>
</if>
and at2.trade_time <![CDATA[ >= ]]> #{param.startDateTime}
and at2.trade_time <![CDATA[ <= ]]> #{param.endDateTime}
GROUP BY
at2.user_id
su.user_id
) b
left join
(
select
su.user_id,
su.nick_name,
su.phonenumber,
sd.dept_id,
sd.dept_name,
sd.dept_full_name,
SUM(IFNULL(CASE
WHEN at2.trade_type in (10, 20, 130) then
at2.actual_amount
end, 0)) as income,
SUM(IFNULL(CASE
WHEN at2.trade_type in (30, 100, 110, 120) then
at2.actual_amount
end, 0)) as outcome
from
sys_user su
left join acc_trade at2 on
at2.user_id = su.user_id
and at2.trade_time <![CDATA[ < ]]> #{param.startDateTime}
and at2.pay_state = 3
left join sys_dept sd on
su.dept_id = sd.dept_id
where
1 = 1
<if test="param.deptIdList != null and param.deptIdList.size() > 0">
and su.dept_id in
<foreach collection="param.deptIdList" item="deptId" separator="," open="(" close=")">
#{deptId}
</foreach>
</if>
GROUP BY
su.user_id
) d on b.user_id = d.user_id
left join
(
select
IFNULL(sum(a.wallet_bal), 0) as wallet_bal_user ,
su.user_id
from
sys_user su
left join
(
select
awi.user_id,
@ -189,8 +228,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
acc_wallet_info awi
group by
awi.user_id ) a
left join sys_user su on
a.user_id = su.user_id
on a.user_id = su.user_id
where
1 = 1
<if test="param.deptIdList != null and param.deptIdList.size() > 0">
@ -211,6 +249,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
or c.user_id like CONCAT('%',#{param.searchValue},'%')
)
</if>
order by c.user_id
order by outcome desc
</select>
</mapper>