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