-
mentioned in commit f31f5c81
Showing
2 changed files
fw-morax-server/src/main/java/cn/fw/morax/server/task/SalaryCalcTask.java
... | ... | @@ -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 | 42 | @Async |
43 | 43 | public void retrySaveExtra() { |
44 | 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 | 34 | import org.springframework.data.redis.core.ListOperations; |
35 | 35 | import org.springframework.data.redis.core.StringRedisTemplate; |
36 | 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 | 40 | import org.springframework.transaction.annotation.Transactional; |
38 | 41 | import org.springframework.util.CollectionUtils; |
39 | 42 | |
... | ... | @@ -67,6 +70,8 @@ public class SalaryReportService { |
67 | 70 | private final SalaryGroupService salaryGroupService; |
68 | 71 | private final SalaryPoolCommonService salaryPoolCommonService; |
69 | 72 | private final StringRedisTemplate stringRedisTemplate; |
73 | + private final PlatformTransactionManager platformTransactionManager; | |
74 | + private final TransactionDefinition transactionDefinition; | |
70 | 75 | @Value("${spring.cache.custom.global-prefix}:extra-salary") |
71 | 76 | @Getter |
72 | 77 | private String extraSalaryKey; |
... | ... | @@ -85,7 +90,7 @@ public class SalaryReportService { |
85 | 90 | if (Objects.isNull(dto)) { |
86 | 91 | continue; |
87 | 92 | } |
88 | - saveExtraProject(dto); | |
93 | + saveExtraProjectTX(dto); | |
89 | 94 | } catch (Exception e) { |
90 | 95 | failList.add(str); |
91 | 96 | log.error("薪酬额外薪资数据保存失败", e); |
... | ... | @@ -106,7 +111,7 @@ public class SalaryReportService { |
106 | 111 | public void salaryRewardReport(SalaryRewardReq req) { |
107 | 112 | SalaryExtraDTO extraDTO = transferExtraProject(req); |
108 | 113 | try { |
109 | - saveExtraProject(extraDTO); | |
114 | + saveExtraProjectTX(extraDTO); | |
110 | 115 | } catch (Exception e) { |
111 | 116 | cacheFailProject(extraDTO, getExtraSalaryKey()); |
112 | 117 | log.error("奖惩项薪资上报数据处理失败", e); |
... | ... | @@ -121,7 +126,7 @@ public class SalaryReportService { |
121 | 126 | public void socialSecurityProject(GeneralSalaryProjectReq req) { |
122 | 127 | SalaryExtraDTO extraDTO = transferExtraProject(req, ExtraSalaryTypeEnum.NECESSARY); |
123 | 128 | try { |
124 | - saveExtraProject(extraDTO); | |
129 | + saveExtraProjectTX(extraDTO); | |
125 | 130 | } catch (Exception e) { |
126 | 131 | cacheFailProject(extraDTO, getExtraSalaryKey()); |
127 | 132 | log.error("社保项上报数据处理失败", e); |
... | ... | @@ -136,7 +141,7 @@ public class SalaryReportService { |
136 | 141 | public void personTaxProject(GeneralSalaryProjectReq req) { |
137 | 142 | SalaryExtraDTO extraDTO = transferExtraProject(req, ExtraSalaryTypeEnum.PERSON_TAX); |
138 | 143 | try { |
139 | - saveExtraProject(extraDTO); | |
144 | + saveExtraProjectTX(extraDTO); | |
140 | 145 | } catch (Exception e) { |
141 | 146 | cacheFailProject(extraDTO, getExtraSalaryKey()); |
142 | 147 | log.error("社保项上报数据处理失败", e); |
... | ... | @@ -151,20 +156,34 @@ public class SalaryReportService { |
151 | 156 | public void subsidyProject(GeneralSalaryProjectReq req) { |
152 | 157 | SalaryExtraDTO extraDTO = transferExtraProject(req, ExtraSalaryTypeEnum.SUBSIDY); |
153 | 158 | try { |
154 | - saveExtraProject(extraDTO); | |
159 | + saveExtraProjectTX(extraDTO); | |
155 | 160 | } catch (Exception e) { |
156 | 161 | cacheFailProject(extraDTO, getExtraSalaryKey()); |
157 | 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 | 185 | * @param extraDTO |
166 | 186 | */ |
167 | - @Transactional(rollbackFor = Exception.class) | |
168 | 187 | public void saveExtraProject(SalaryExtraDTO extraDTO) { |
169 | 188 | Optional<SalaryPool> optional = queryPoolByUser(extraDTO.getUserId(), extraDTO.getPostId(), extraDTO.getShopId(), extraDTO.getDataDate()); |
170 | 189 | Long fundShopId; | ... | ... |