@startuml
|
!theme plain
|
skinparam backgroundColor white
|
skinparam defaultFontName Microsoft YaHei
|
|
title /batchFundTax 业务逻辑流程图
|
|
start
|
|
:用户调用 /batchFundTax 接口;
|
:传入 FundTaxVO 参数;
|
|
if (fundTaxId 是否为空?) then (是)
|
:抛出异常: "分批算税出问题了,请检查后再进行计算";
|
stop
|
else (否)
|
if (addOrupdate == 1?) then (是)
|
:获取最大 fundTaxId;
|
note right: SQL: SELECT MAX(id) FROM service_fundtax;
|
if (当前 fundTaxId != 最大 fundTaxId?) then (是)
|
:抛出异常: "该批数据不能算税";
|
stop
|
else (否)
|
:继续执行;
|
endif
|
else (否)
|
:继续执行;
|
endif
|
endif
|
|
:根据 fundTaxId 查询所有 ServiceFund 记录;
|
note right: SQL: SELECT * FROM service_fund WHERE fund_tax_id = #{fundTaxId} AND del_flag = 0;
|
:遍历每个 ServiceFund;
|
|
while (还有 ServiceFund 未处理?) is (是)
|
:获取当前 ServiceFund 的 fundid;
|
:根据 fundid 查询所有 ServiceFunddetail;
|
note right: SQL: SELECT * FROM service_funddetail WHERE fundid = #{fundid};
|
|
while (还有 ServiceFunddetail 未处理?) is (是)
|
:获取当前 ServiceFunddetail;
|
|
if (身份证号是否为空?) then (是)
|
if (servicesscopename 包含"税后"?) then (是)
|
:设置 amount = taxedamount;
|
else (否)
|
:设置 taxedamount = amount;
|
endif
|
:设置 taxamount = 0;
|
:更新数据库;
|
note right: SQL: UPDATE service_funddetail SET amount=#{amount}, taxedamount=#{taxedamount}, taxamount=0 WHERE id=#{id};
|
:累加 pretaxcost 和 taxedcost;
|
else (否)
|
:获取当月第一天;
|
:查询该身份证号本月最大序号;
|
note right: SQL: SELECT MAX(xh) FROM service_funddetail WHERE idcardno = #{idcardno} AND tax_time >= #{firstDay} AND tax_time <= #{taxTime};
|
:设置序号;
|
|
:查询该身份证号本月累计税前、税金、税后;
|
note right: SQL: SELECT SUM(amount) as amounts, SUM(taxamount) as taxAmounts, SUM(taxedamount) as taxedAmounts FROM service_funddetail a LEFT JOIN service_fund b ON a.fundid = b.id WHERE a.idcardno = #{idcardno} AND a.tax_time >= #{firstDay} AND a.tax_time <= #{taxTime} AND a.xh < #{xh} AND b.fundtaxtime <= #{fundtaxtime};
|
|
if (temporarySave 中有相同身份证号?) then (是)
|
:累加临时保存的数据到 taxSum;
|
endif
|
|
if (servicesscopename 包含"税后"?) then (是)
|
:税后算税逻辑;
|
:计算本次税前金额;
|
:计算本次税金;
|
else (否)
|
:税前算税逻辑;
|
:计算本次税金;
|
:计算本次税后金额;
|
endif
|
|
:设置算税时间;
|
:更新数据库;
|
note right: SQL: UPDATE service_funddetail SET amount=#{amount}, taxamount=#{taxamount}, taxedamount=#{taxedamount}, tax_time=#{taxTime}, xh=#{xh} WHERE id=#{id};
|
:累加 pretaxcost 和 taxedcost;
|
:添加到 temporarySave;
|
endif
|
endwhile (否)
|
endwhile (否)
|
|
:更新 ServiceFund 表;
|
note right: SQL: UPDATE service_fund SET pretaxcost=#{pretaxcost}, taxedcost=#{taxedcost}, fundtaxtime=#{fundtaxtime}, istax=1 WHERE id=#{id};
|
:设置 pretaxcost 和 taxedcost;
|
:设置 fundtaxtime;
|
:设置 istax = 1;
|
|
:返回成功;
|
|
stop
|
|
@enduml
|
|
'主要SQL语句说明:
|
|
-- 1. 获取最大fundTaxId
|
SELECT MAX(id) FROM service_fundtax;
|
|
-- 2. 根据fundTaxId查询ServiceFund记录
|
SELECT * FROM service_fund
|
WHERE fund_tax_id = #{fundTaxId} AND del_flag = 0;
|
|
-- 3. 根据fundid查询ServiceFunddetail记录
|
SELECT * FROM service_funddetail
|
WHERE fundid = #{fundid};
|
|
-- 4. 查询该身份证号本月最大序号
|
SELECT MAX(xh) FROM service_funddetail
|
WHERE idcardno = #{idcardno}
|
AND tax_time >= #{firstDay}
|
AND tax_time <= #{taxTime};
|
|
-- 5. 查询该身份证号本月累计税前、税金、税后(不包含本次)
|
SELECT
|
SUM(amount) as amounts,
|
SUM(taxamount) as taxAmounts,
|
SUM(taxedamount) as taxedAmounts
|
FROM service_funddetail a
|
LEFT JOIN service_fund b ON a.fundid = b.id
|
WHERE a.idcardno = #{idcardno}
|
AND a.tax_time >= #{firstDay}
|
AND a.tax_time <= #{taxTime}
|
AND a.xh < #{xh}
|
AND b.fundtaxtime <= #{fundtaxtime};
|
|
-- 6. 更新ServiceFunddetail记录
|
UPDATE service_funddetail
|
SET
|
amount = #{amount},
|
taxamount = #{taxamount},
|
taxedamount = #{taxedamount},
|
tax_time = #{taxTime},
|
xh = #{xh}
|
WHERE id = #{id};
|
|
-- 7. 更新ServiceFund记录
|
UPDATE service_fund
|
SET
|
pretaxcost = #{pretaxcost},
|
taxedcost = #{taxedcost},
|
fundtaxtime = #{fundtaxtime},
|
istax = 1
|
WHERE id = #{id};
|