|
...
|
...
|
@@ -10,7 +10,6 @@ import com.lframework.xingyun.sc.vo.ledger.receipt.*; |
|
10
|
10
|
import com.lframework.xingyun.sc.service.ledger.ReceiptLedgerInfoService;
|
|
11
|
11
|
import com.lframework.xingyun.sc.entity.ReceiptLedgerInfo;
|
|
12
|
12
|
import com.lframework.starter.web.core.utils.PageResultUtil;
|
|
13
|
|
-
|
|
14
|
13
|
import javax.annotation.Resource;
|
|
15
|
14
|
import javax.validation.constraints.NotBlank;
|
|
16
|
15
|
import com.lframework.starter.common.exceptions.impl.DefaultClientException;
|
|
...
|
...
|
@@ -28,8 +27,13 @@ import com.lframework.starter.web.core.controller.DefaultBaseController; |
|
28
|
27
|
import com.lframework.starter.web.core.annotations.security.HasPermission;
|
|
29
|
28
|
import org.springframework.validation.annotation.Validated;
|
|
30
|
29
|
import org.springframework.web.bind.annotation.*;
|
|
31
|
|
-
|
|
32
|
30
|
import javax.validation.Valid;
|
|
|
31
|
+import java.math.BigDecimal;
|
|
|
32
|
+import java.time.LocalDateTime;
|
|
|
33
|
+import java.time.LocalTime;
|
|
|
34
|
+import java.time.format.DateTimeFormatter;
|
|
|
35
|
+import java.time.temporal.TemporalAdjusters;
|
|
|
36
|
+import java.util.Comparator;
|
|
33
|
37
|
import java.util.List;
|
|
34
|
38
|
import java.util.stream.Collectors;
|
|
35
|
39
|
|
|
...
|
...
|
@@ -182,4 +186,76 @@ public class ReceiptLedgerInfoController extends DefaultBaseController { |
|
182
|
186
|
receiptLedgerInfoService.againGenerate();
|
|
183
|
187
|
return InvokeResultBuilder.success();
|
|
184
|
188
|
}
|
|
|
189
|
+
|
|
|
190
|
+ /**
|
|
|
191
|
+ * 存款平账
|
|
|
192
|
+ */
|
|
|
193
|
+ @ApiOperation("存款平账")
|
|
|
194
|
+ @HasPermission({"account-manage:ledger-detail:reconciliation"})
|
|
|
195
|
+ @PostMapping("/depositReconciliation")
|
|
|
196
|
+ public InvokeResult<Void> reconciliation(@NotBlank(message = "id不能为空!") String id) {
|
|
|
197
|
+ ReceiptLedgerInfo data = receiptLedgerInfoService.findById(id);
|
|
|
198
|
+ if (data == null) {
|
|
|
199
|
+ throw new DefaultClientException("应收款台账明细不存在!");
|
|
|
200
|
+ }
|
|
|
201
|
+ //订货单位、厂别、办事处、贸易类型匹配台账数据
|
|
|
202
|
+ QueryReceiptLedgerInfoVo vo1 = new QueryReceiptLedgerInfoVo();
|
|
|
203
|
+ vo1.setCustomerId(data.getCustomerId());
|
|
|
204
|
+ vo1.setFactoryType(data.getFactoryType());
|
|
|
205
|
+ vo1.setDeptId(data.getDeptId());
|
|
|
206
|
+ vo1.setType(data.getType());
|
|
|
207
|
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
208
|
+ // 获取当前日期时间(不带时区)
|
|
|
209
|
+ LocalDateTime now = LocalDateTime.now();
|
|
|
210
|
+ // 当前月的第一天 00:00:00
|
|
|
211
|
+ LocalDateTime firstDay = now.with(TemporalAdjusters.firstDayOfMonth())
|
|
|
212
|
+ .with(LocalTime.MIN); // 等价于 .withHour(0).withMinute(0).withSecond(0)
|
|
|
213
|
+ // 当前月的最后一天 23:59:59
|
|
|
214
|
+ LocalDateTime lastDay = now.with(TemporalAdjusters.lastDayOfMonth())
|
|
|
215
|
+ .withHour(23)
|
|
|
216
|
+ .withMinute(59)
|
|
|
217
|
+ .withSecond(59)
|
|
|
218
|
+ .withNano(0);
|
|
|
219
|
+ // 格式化为字符串
|
|
|
220
|
+ String startStr = firstDay.format(formatter);
|
|
|
221
|
+ String endStr = lastDay.format(formatter);
|
|
|
222
|
+ vo1.setCreateTimeStart(startStr);
|
|
|
223
|
+ vo1.setCreateTimeEnd(endStr);
|
|
|
224
|
+ //存款
|
|
|
225
|
+ vo1.setDebtStatus("DEPOSIT");
|
|
|
226
|
+ List<ReceiptLedgerInfo> query = receiptLedgerInfoService.query(vo1);
|
|
|
227
|
+ if (CollectionUtil.isNotEmpty(query)) {
|
|
|
228
|
+ //不为空代表有存款-可以平账
|
|
|
229
|
+ //回笼资金=期初应收款 有多条占用天数多的先平账
|
|
|
230
|
+ List<ReceiptLedgerInfo> result = query.stream()
|
|
|
231
|
+ // 1. 过滤:startAccountReceivable 等于 returnedAmount
|
|
|
232
|
+ .filter(item -> {
|
|
|
233
|
+ BigDecimal start = item.getReturnedAmount();
|
|
|
234
|
+ return start != null
|
|
|
235
|
+ && data.getStartAccountReceivable() != null
|
|
|
236
|
+ && start.compareTo(data.getStartAccountReceivable()) == 0;
|
|
|
237
|
+ })
|
|
|
238
|
+ // 2. 排序:按 actualReturnedDate 升序(早的在前)
|
|
|
239
|
+ .sorted(Comparator.comparing(ReceiptLedgerInfo::getActualReturnedDate))
|
|
|
240
|
+ .collect(Collectors.toList());
|
|
|
241
|
+ if (CollectionUtil.isNotEmpty(result)) {
|
|
|
242
|
+ //欠款平账
|
|
|
243
|
+ UpdateReceiptLedgerInfoVo updateVo = new UpdateReceiptLedgerInfoVo();
|
|
|
244
|
+ updateVo.setReturnedAmount(result.get(0).getReturnedAmount());
|
|
|
245
|
+ updateVo.setActualReturnedDate(result.get(0).getActualReturnedDate());
|
|
|
246
|
+ updateVo.setEndAccountReceivable(BigDecimal.ZERO);
|
|
|
247
|
+ updateVo.setId(id);
|
|
|
248
|
+ receiptLedgerInfoService.reconciliation(updateVo);
|
|
|
249
|
+ //存款平账
|
|
|
250
|
+ UpdateReceiptLedgerInfoVo updateVo1 = new UpdateReceiptLedgerInfoVo();
|
|
|
251
|
+ updateVo1.setId(result.get(0).getId());
|
|
|
252
|
+ receiptLedgerInfoService.depositReconciliation(updateVo);
|
|
|
253
|
+ } else {
|
|
|
254
|
+ throw new DefaultClientException("没有匹配的存款台账明细数据!");
|
|
|
255
|
+ }
|
|
|
256
|
+ } else {
|
|
|
257
|
+ throw new DefaultClientException("没有匹配的存款台账明细数据!");
|
|
|
258
|
+ }
|
|
|
259
|
+ return InvokeResultBuilder.success();
|
|
|
260
|
+ }
|
|
185
|
261
|
} |
...
|
...
|
|