Commit 76b97ee14a88b95d2b20bea4e35d44445d501aca
1 parent
1d01b24e
feature(bug): 额外薪酬事务处理
额外薪酬事务处理
Showing
2 changed files
with
26 additions
and
7 deletions
fw-morax-server/src/main/java/cn/fw/morax/server/task/SalaryCalcTask.java
@@ -38,7 +38,7 @@ public class SalaryCalcTask { | @@ -38,7 +38,7 @@ public class SalaryCalcTask { | ||
38 | /** | 38 | /** |
39 | * 重试额外薪资数据持久化 | 39 | * 重试额外薪资数据持久化 |
40 | */ | 40 | */ |
41 | - @Scheduled(initialDelay = 1000L * 10, fixedRate = 1000L * 30) | 41 | + @Scheduled(initialDelay = 1000L * 10, fixedRate = 1000L * 180) |
42 | @Async | 42 | @Async |
43 | public void retrySaveExtra() { | 43 | public void retrySaveExtra() { |
44 | salaryReportService.retrySaveReward(); | 44 | salaryReportService.retrySaveReward(); |
fw-morax-service/src/main/java/cn/fw/morax/service/biz/salary/SalaryReportService.java
@@ -34,6 +34,9 @@ import org.springframework.data.redis.core.BoundListOperations; | @@ -34,6 +34,9 @@ import org.springframework.data.redis.core.BoundListOperations; | ||
34 | import org.springframework.data.redis.core.ListOperations; | 34 | import org.springframework.data.redis.core.ListOperations; |
35 | import org.springframework.data.redis.core.StringRedisTemplate; | 35 | import org.springframework.data.redis.core.StringRedisTemplate; |
36 | import org.springframework.stereotype.Service; | 36 | import org.springframework.stereotype.Service; |
37 | +import org.springframework.transaction.PlatformTransactionManager; | ||
38 | +import org.springframework.transaction.TransactionDefinition; | ||
39 | +import org.springframework.transaction.TransactionStatus; | ||
37 | import org.springframework.transaction.annotation.Transactional; | 40 | import org.springframework.transaction.annotation.Transactional; |
38 | import org.springframework.util.CollectionUtils; | 41 | import org.springframework.util.CollectionUtils; |
39 | 42 | ||
@@ -67,6 +70,8 @@ public class SalaryReportService { | @@ -67,6 +70,8 @@ public class SalaryReportService { | ||
67 | private final SalaryGroupService salaryGroupService; | 70 | private final SalaryGroupService salaryGroupService; |
68 | private final SalaryPoolCommonService salaryPoolCommonService; | 71 | private final SalaryPoolCommonService salaryPoolCommonService; |
69 | private final StringRedisTemplate stringRedisTemplate; | 72 | private final StringRedisTemplate stringRedisTemplate; |
73 | + private final PlatformTransactionManager platformTransactionManager; | ||
74 | + private final TransactionDefinition transactionDefinition; | ||
70 | @Value("${spring.cache.custom.global-prefix}:extra-salary") | 75 | @Value("${spring.cache.custom.global-prefix}:extra-salary") |
71 | @Getter | 76 | @Getter |
72 | private String extraSalaryKey; | 77 | private String extraSalaryKey; |
@@ -85,7 +90,7 @@ public class SalaryReportService { | @@ -85,7 +90,7 @@ public class SalaryReportService { | ||
85 | if (Objects.isNull(dto)) { | 90 | if (Objects.isNull(dto)) { |
86 | continue; | 91 | continue; |
87 | } | 92 | } |
88 | - saveExtraProject(dto); | 93 | + saveExtraProjectTX(dto); |
89 | } catch (Exception e) { | 94 | } catch (Exception e) { |
90 | failList.add(str); | 95 | failList.add(str); |
91 | log.error("薪酬额外薪资数据保存失败", e); | 96 | log.error("薪酬额外薪资数据保存失败", e); |
@@ -106,7 +111,7 @@ public class SalaryReportService { | @@ -106,7 +111,7 @@ public class SalaryReportService { | ||
106 | public void salaryRewardReport(SalaryRewardReq req) { | 111 | public void salaryRewardReport(SalaryRewardReq req) { |
107 | SalaryExtraDTO extraDTO = transferExtraProject(req); | 112 | SalaryExtraDTO extraDTO = transferExtraProject(req); |
108 | try { | 113 | try { |
109 | - saveExtraProject(extraDTO); | 114 | + saveExtraProjectTX(extraDTO); |
110 | } catch (Exception e) { | 115 | } catch (Exception e) { |
111 | cacheFailProject(extraDTO, getExtraSalaryKey()); | 116 | cacheFailProject(extraDTO, getExtraSalaryKey()); |
112 | log.error("奖惩项薪资上报数据处理失败", e); | 117 | log.error("奖惩项薪资上报数据处理失败", e); |
@@ -121,7 +126,7 @@ public class SalaryReportService { | @@ -121,7 +126,7 @@ public class SalaryReportService { | ||
121 | public void socialSecurityProject(GeneralSalaryProjectReq req) { | 126 | public void socialSecurityProject(GeneralSalaryProjectReq req) { |
122 | SalaryExtraDTO extraDTO = transferExtraProject(req, ExtraSalaryTypeEnum.NECESSARY); | 127 | SalaryExtraDTO extraDTO = transferExtraProject(req, ExtraSalaryTypeEnum.NECESSARY); |
123 | try { | 128 | try { |
124 | - saveExtraProject(extraDTO); | 129 | + saveExtraProjectTX(extraDTO); |
125 | } catch (Exception e) { | 130 | } catch (Exception e) { |
126 | cacheFailProject(extraDTO, getExtraSalaryKey()); | 131 | cacheFailProject(extraDTO, getExtraSalaryKey()); |
127 | log.error("社保项上报数据处理失败", e); | 132 | log.error("社保项上报数据处理失败", e); |
@@ -136,7 +141,7 @@ public class SalaryReportService { | @@ -136,7 +141,7 @@ public class SalaryReportService { | ||
136 | public void personTaxProject(GeneralSalaryProjectReq req) { | 141 | public void personTaxProject(GeneralSalaryProjectReq req) { |
137 | SalaryExtraDTO extraDTO = transferExtraProject(req, ExtraSalaryTypeEnum.PERSON_TAX); | 142 | SalaryExtraDTO extraDTO = transferExtraProject(req, ExtraSalaryTypeEnum.PERSON_TAX); |
138 | try { | 143 | try { |
139 | - saveExtraProject(extraDTO); | 144 | + saveExtraProjectTX(extraDTO); |
140 | } catch (Exception e) { | 145 | } catch (Exception e) { |
141 | cacheFailProject(extraDTO, getExtraSalaryKey()); | 146 | cacheFailProject(extraDTO, getExtraSalaryKey()); |
142 | log.error("社保项上报数据处理失败", e); | 147 | log.error("社保项上报数据处理失败", e); |
@@ -151,20 +156,34 @@ public class SalaryReportService { | @@ -151,20 +156,34 @@ public class SalaryReportService { | ||
151 | public void subsidyProject(GeneralSalaryProjectReq req) { | 156 | public void subsidyProject(GeneralSalaryProjectReq req) { |
152 | SalaryExtraDTO extraDTO = transferExtraProject(req, ExtraSalaryTypeEnum.SUBSIDY); | 157 | SalaryExtraDTO extraDTO = transferExtraProject(req, ExtraSalaryTypeEnum.SUBSIDY); |
153 | try { | 158 | try { |
154 | - saveExtraProject(extraDTO); | 159 | + saveExtraProjectTX(extraDTO); |
155 | } catch (Exception e) { | 160 | } catch (Exception e) { |
156 | cacheFailProject(extraDTO, getExtraSalaryKey()); | 161 | cacheFailProject(extraDTO, getExtraSalaryKey()); |
157 | log.error("补贴项薪资上报数据处理失败", e); | 162 | log.error("补贴项薪资上报数据处理失败", e); |
158 | } | 163 | } |
159 | } | 164 | } |
160 | 165 | ||
166 | + /** | ||
167 | + * 事务保存额外薪酬项 | ||
168 | + * | ||
169 | + * @param extraDTO | ||
170 | + */ | ||
171 | + public void saveExtraProjectTX(SalaryExtraDTO extraDTO) { | ||
172 | + TransactionStatus transactionStatus = platformTransactionManager.getTransaction(transactionDefinition); | ||
173 | + try { | ||
174 | + saveExtraProject(extraDTO); | ||
175 | + platformTransactionManager.commit(transactionStatus); | ||
176 | + } catch (Exception e) { | ||
177 | + platformTransactionManager.rollback(transactionStatus); | ||
178 | + throw e; | ||
179 | + } | ||
180 | + } | ||
161 | 181 | ||
162 | /** | 182 | /** |
163 | * 保存额外薪酬项 | 183 | * 保存额外薪酬项 |
164 | * | 184 | * |
165 | * @param extraDTO | 185 | * @param extraDTO |
166 | */ | 186 | */ |
167 | - @Transactional(rollbackFor = Exception.class) | ||
168 | public void saveExtraProject(SalaryExtraDTO extraDTO) { | 187 | public void saveExtraProject(SalaryExtraDTO extraDTO) { |
169 | Optional<SalaryPool> optional = queryPoolByUser(extraDTO.getUserId(), extraDTO.getPostId(), extraDTO.getShopId(), extraDTO.getDataDate()); | 188 | Optional<SalaryPool> optional = queryPoolByUser(extraDTO.getUserId(), extraDTO.getPostId(), extraDTO.getShopId(), extraDTO.getDataDate()); |
170 | Long fundShopId; | 189 | Long fundShopId; |