liusheng
18 小时以前 5b6bd2b10c8c87b658b888f4d0384aec3ed491ce
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
@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};