|
@@ -1,18 +1,26 @@
|
|
|
package com.sd.wln.service.impl;
|
|
|
|
|
|
+import cn.hutool.core.convert.Convert;
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
+import com.ruoyi.common.core.domain.BaseIdPo;
|
|
|
import com.ruoyi.common.core.domain.BasePo;
|
|
|
+import com.sd.business.entity.order.enums.OrderStatusEnum;
|
|
|
+import com.sd.business.entity.order.po.OrderInfo;
|
|
|
import com.sd.business.entity.outbound.po.OutboundOrder;
|
|
|
import com.sd.business.entity.statement.po.StatementOfAccount;
|
|
|
+import com.sd.business.service.order.OrderService;
|
|
|
import com.sd.business.service.outbound.OutboundOrderService;
|
|
|
import com.sd.business.service.statement.StatementOfAccountService;
|
|
|
+import com.sd.business.util.CodeEnum;
|
|
|
import com.sd.wln.service.WlnStatementOfAccount;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
-import java.util.Date;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.*;
|
|
|
+import java.util.function.Function;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
@Service
|
|
|
public class WlnStatementOfAccountImpl implements WlnStatementOfAccount {
|
|
@@ -23,20 +31,98 @@ public class WlnStatementOfAccountImpl implements WlnStatementOfAccount {
|
|
|
@Autowired
|
|
|
private OutboundOrderService outboundOrderService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private OrderService orderService;
|
|
|
+
|
|
|
+ @Transactional
|
|
|
@Override
|
|
|
public void createStatementOfAccount() {
|
|
|
Date date = new Date();
|
|
|
|
|
|
- Map<Long, StatementOfAccount> statementOfAccountMap = statementOfAccountService.mapKEntity(
|
|
|
- StatementOfAccount::getDepartmentId,
|
|
|
- q -> q
|
|
|
- .eq(StatementOfAccount::getType, 2)
|
|
|
- .between(BasePo::getCreateTime, DateUtil.beginOfDay(date), DateUtil.endOfDay(date))
|
|
|
- );
|
|
|
+ List<OrderInfo> editOrderList = new ArrayList<>();
|
|
|
|
|
|
+ // 获取当天出库单
|
|
|
List<OutboundOrder> list = outboundOrderService.list(q -> q
|
|
|
.between(BasePo::getCreateTime, DateUtil.beginOfDay(date), DateUtil.endOfDay(date)));
|
|
|
+ if (list.size() == 0) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 根据出库单查询订单
|
|
|
+ Map<String, Date> map = list.stream().collect(
|
|
|
+ Collectors.toMap(OutboundOrder::getOrderWlnCode, OutboundOrder::getOutboundTime, (t1, t2) -> t1));
|
|
|
+
|
|
|
+ // 查询与出库单关联的订单
|
|
|
+ List<OrderInfo> orderList = orderService.list(q -> q
|
|
|
+ .in(OrderInfo::getWlnCode, map.keySet())
|
|
|
+ .ge(OrderInfo::getStatus, OrderStatusEnum.IN_PRODUCTION.getKey())
|
|
|
+ .notIn(OrderInfo::getStatus, OrderStatusEnum.DELETE.getKey(), OrderStatusEnum.EXCEPTION.getKey())
|
|
|
+ );
|
|
|
+
|
|
|
+ // 循环订单,把生产中的订单改为生产完成
|
|
|
+ for (OrderInfo orderInfo : orderList) {
|
|
|
+ Integer status = orderInfo.getStatus();
|
|
|
+ if (status.equals(OrderStatusEnum.IN_PRODUCTION.getKey())) {
|
|
|
+ OrderInfo tempOrderInfo = new OrderInfo();
|
|
|
+ tempOrderInfo.setStatus(OrderStatusEnum.COMPLETION_PRODUCTION.getKey());
|
|
|
+ tempOrderInfo.setShippingTime(map.get(orderInfo.getWlnCode()));
|
|
|
+ editOrderList.add(tempOrderInfo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 生成对账单
|
|
|
+ List<StatementOfAccount> statementOfAccountList = statementOfAccountService.list(q -> q
|
|
|
+ .eq(StatementOfAccount::getType, 2)
|
|
|
+ .between(BasePo::getCreateTime, DateUtil.beginOfDay(date), DateUtil.endOfDay(date))
|
|
|
+ );
|
|
|
+ Map<Long, StatementOfAccount> statementOfAccountMap = statementOfAccountList.stream()
|
|
|
+ .collect(Collectors.toMap(StatementOfAccount::getDepartmentId, Function.identity()));
|
|
|
+
|
|
|
+ Map<String, String> codeMap = new HashMap<>(1);
|
|
|
+
|
|
|
+ Map<Long, List<OrderInfo>> orderByDepartmentIdMap = orderList.stream().collect(Collectors.groupingBy(OrderInfo::getDepartmentId));
|
|
|
+
|
|
|
+ orderByDepartmentIdMap.forEach((departmentId, order) -> {
|
|
|
+ StatementOfAccount statementOfAccount = statementOfAccountMap.computeIfAbsent(departmentId, item -> {
|
|
|
+ String code = codeMap.get("code");
|
|
|
+ if (code == null) {
|
|
|
+ codeMap.put("code", CodeEnum.STATEMENT_OF_ACCOUNT_CODE.getCode());
|
|
|
+ } else {
|
|
|
+ int number = Convert.toInt(code.substring(code.length() - 6));
|
|
|
+ codeMap.put("code", code.substring(0, code.length() - 6) + String.format("%06d", number + 1));
|
|
|
+ }
|
|
|
+
|
|
|
+ StatementOfAccount tempStatementOfAccount = new StatementOfAccount();
|
|
|
+ tempStatementOfAccount.setCode(codeMap.get("code"));
|
|
|
+ tempStatementOfAccount.setDepartmentId(departmentId);
|
|
|
+ tempStatementOfAccount.setTimePeriodBegin(DateUtil.beginOfDay(date));
|
|
|
+ tempStatementOfAccount.setTimePeriodEnd(DateUtil.endOfDay(date));
|
|
|
+ tempStatementOfAccount.setType(2);
|
|
|
+ return tempStatementOfAccount;
|
|
|
+ });
|
|
|
+
|
|
|
+ String orderIdJoin = order.stream()
|
|
|
+ .map(BaseIdPo::getId)
|
|
|
+ .distinct()
|
|
|
+ .map(Convert::toStr)
|
|
|
+ .collect(Collectors.joining(","));
|
|
|
+ statementOfAccount.setOrderIdJoin(orderIdJoin);
|
|
|
+
|
|
|
+ BigDecimal amount = order.stream()
|
|
|
+ .map(OrderInfo::getTotalAmount)
|
|
|
+ .reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ statementOfAccount.setAmount(amount);
|
|
|
+
|
|
|
+ });
|
|
|
+
|
|
|
+ if (editOrderList.size() > 0) {
|
|
|
+ orderService.updateBatchById(editOrderList);
|
|
|
+ }
|
|
|
|
|
|
+ List<StatementOfAccount> editStatementOfAccountList = new ArrayList<>(statementOfAccountMap.values());
|
|
|
+ if (editStatementOfAccountList.size() > 0) {
|
|
|
+ statementOfAccountService.saveOrUpdateBatch(editStatementOfAccountList);
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
|