Commit 6328a313e5879f97abaac5633109b4e44789a036

Authored by 房远帅
1 parent 38bb355b

账期:台账明细-存款平账

... ... @@ -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 }
... ...
... ... @@ -37,6 +37,10 @@ import org.springframework.transaction.annotation.Transactional;
37 37 import org.springframework.stereotype.Service;
38 38 import javax.annotation.Resource;
39 39 import java.math.BigDecimal;
  40 +import java.time.LocalDateTime;
  41 +import java.time.LocalTime;
  42 +import java.time.format.DateTimeFormatter;
  43 +import java.time.temporal.TemporalAdjusters;
40 44 import java.util.Comparator;
41 45 import java.util.List;
42 46 import java.util.stream.Collectors;
... ... @@ -95,6 +99,23 @@ public class RecapitalizeServiceImpl extends BaseMpServiceImpl<RecapitalizeMappe
95 99 vo1.setFactoryType(vo.getFactoryType());
96 100 vo1.setDeptId(vo.getDeptId());
97 101 vo1.setType(vo.getType());
  102 + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
  103 + // 获取当前日期时间(不带时区)
  104 + LocalDateTime now = LocalDateTime.now();
  105 + // 当前月的第一天 00:00:00
  106 + LocalDateTime firstDay = now.with(TemporalAdjusters.firstDayOfMonth())
  107 + .with(LocalTime.MIN); // 等价于 .withHour(0).withMinute(0).withSecond(0)
  108 + // 当前月的最后一天 23:59:59
  109 + LocalDateTime lastDay = now.with(TemporalAdjusters.lastDayOfMonth())
  110 + .withHour(23)
  111 + .withMinute(59)
  112 + .withSecond(59)
  113 + .withNano(0);
  114 + // 格式化为字符串
  115 + String startStr = firstDay.format(formatter);
  116 + String endStr = lastDay.format(formatter);
  117 + vo1.setCreateTimeStart(startStr);
  118 + vo1.setCreateTimeEnd(endStr);
98 119 List<ReceiptLedgerInfo> query = receiptLedgerInfoService.query(vo1);
99 120 if (CollectionUtil.isNotEmpty(query)) {
100 121 //不为空代表有欠款-需要平账
... ...
... ... @@ -788,4 +788,22 @@ public class ReceiptLedgerInfoServiceImpl extends BaseMpServiceImpl<ReceiptLedge
788 788 }
789 789 return result;
790 790 }
  791 +
  792 + @OpLog(type = OtherOpLogType.class, name = "存款平账,ID:{}", params = {"#id"})
  793 + @Transactional(rollbackFor = Exception.class)
  794 + @Override
  795 + public void depositReconciliation(UpdateReceiptLedgerInfoVo vo) {
  796 + ReceiptLedgerInfo data = getBaseMapper().selectById(vo.getId());
  797 + if (ObjectUtil.isNull(data)) {
  798 + throw new DefaultClientException("应收款台账明细不存在!");
  799 + }
  800 + LambdaUpdateWrapper<ReceiptLedgerInfo> updateWrapper = Wrappers.lambdaUpdate(ReceiptLedgerInfo.class)
  801 + .set(ReceiptLedgerInfo::getEndAccountReceivable, BigDecimal.ZERO)
  802 + .set(ReceiptLedgerInfo::getDebtStatus, "CLEARED")
  803 + .eq(ReceiptLedgerInfo::getId, vo.getId());
  804 +
  805 + getBaseMapper().update(updateWrapper);
  806 + OpLogUtil.setVariable("id", data.getId());
  807 + OpLogUtil.setExtra(vo);
  808 + }
791 809 }
... ...
... ... @@ -107,7 +107,7 @@ public interface ReceiptLedgerInfoService extends BaseMpService<ReceiptLedgerInf
107 107 void updateCoordinateDate(String id, LocalDate coordinateDate, String debtStatus);
108 108
109 109 /**
110   - * 平账
  110 + * 欠款平账
111 111 *
112 112 * @param vo 数据
113 113 */
... ... @@ -123,4 +123,11 @@ public interface ReceiptLedgerInfoService extends BaseMpService<ReceiptLedgerInf
123 123 * 重新生成新的台账数据
124 124 */
125 125 void againGenerate();
  126 +
  127 + /**
  128 + * 存款平账
  129 + *
  130 + * @param vo
  131 + */
  132 + void depositReconciliation(UpdateReceiptLedgerInfoVo vo);
126 133 }
... ...
... ... @@ -87,4 +87,7 @@ public class QueryReceiptLedgerInfoVo extends PageVo implements BaseVo, Serializ
87 87 @ApiModelProperty("厂别")
88 88 private String factoryType;
89 89
  90 + @ApiModelProperty("欠款状态")
  91 + private String debtStatus;
  92 +
90 93 }
... ...
... ... @@ -128,6 +128,9 @@
128 128 <if test="vo.deptName != null and vo.deptName != ''">
129 129 AND d.name LIKE CONCAT('%', #{vo.deptName}, '%')
130 130 </if>
  131 + <if test="vo.debtStatus != null and vo.debtStatus != ''">
  132 + AND tb.debt_status = #{vo.debtStatus}
  133 + </if>
131 134 </where>
132 135 </select>
133 136
... ...