|
@@ -1,10 +1,8 @@
|
|
|
package com.sd.wln.service.impl;
|
|
|
|
|
|
import cn.hutool.core.convert.Convert;
|
|
|
-import cn.hutool.core.date.DateTime;
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
|
|
-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;
|
|
@@ -12,7 +10,6 @@ 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;
|
|
@@ -36,74 +33,79 @@ public class WlnStatementOfAccountImpl implements WlnStatementOfAccount {
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
@Override
|
|
|
public void createStatementOfAccount() {
|
|
|
- Date date = new Date();
|
|
|
- DateTime beginDay = DateUtil.beginOfDay(date);
|
|
|
- DateTime endDay = DateUtil.endOfDay(date);
|
|
|
|
|
|
List<StatementOfAccount> saveStatementOfAccountList = new ArrayList<>();
|
|
|
List<OrderInfo> editOrderInfoList = new ArrayList<>();
|
|
|
|
|
|
- // 获取当天出库单
|
|
|
- List<OutboundOrder> list = outboundOrderService.list(q -> q.between(BasePo::getCreateTime, beginDay, endDay));
|
|
|
-
|
|
|
- if (list.size() == 0) {
|
|
|
+ // 获取没绑定对账单的订单
|
|
|
+ List<OrderInfo> orderList = orderService.list(q -> q
|
|
|
+ .ge(OrderInfo::getStatus, OrderStatusEnum.IN_PRODUCTION.getKey())
|
|
|
+ .isNotNull(OrderInfo::getWlnCode)
|
|
|
+ .isNull(OrderInfo::getStatementOfAccountId));
|
|
|
+ if (orderList.size() == 0) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- // 根据出库单查询订单
|
|
|
- Map<String, Date> map = list.stream().collect(
|
|
|
- Collectors.toMap(OutboundOrder::getOrderWlnCode, OutboundOrder::getOutboundTime, (t1, t2) -> t1));
|
|
|
+ // 订单万里牛编号集合
|
|
|
+ List<String> wlnCodeList = orderList.stream().map(OrderInfo::getWlnCode).collect(Collectors.toList());
|
|
|
|
|
|
- // 查询与出库单关联的订单
|
|
|
- List<OrderInfo> orderList = orderService.list(q -> q
|
|
|
- .in(OrderInfo::getWlnCode, map.keySet())
|
|
|
- .ge(OrderInfo::getStatus, OrderStatusEnum.IN_PRODUCTION.getKey())
|
|
|
- .isNull(OrderInfo::getStatementOfAccountId)
|
|
|
- );
|
|
|
-
|
|
|
- if (orderList.size() == 0) {
|
|
|
+ // 根据万里牛编号查询出库记录
|
|
|
+ List<OutboundOrder> outboundOrderList = outboundOrderService.list(q -> q.in(OutboundOrder::getOrderWlnCode, wlnCodeList));
|
|
|
+ if (outboundOrderList.size() == 0) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
+ // 订单编号以及出库时间
|
|
|
+ Map<String, Date> map = outboundOrderList.stream().collect(
|
|
|
+ Collectors.toMap(OutboundOrder::getOrderWlnCode, OutboundOrder::getOutboundTime, (t1, t2) -> t1));
|
|
|
+
|
|
|
// 生成对账单
|
|
|
- Map<Long, StatementOfAccount> statementOfAccountMap = statementOfAccountService.mapKEntity(
|
|
|
- StatementOfAccount::getDepartmentId,
|
|
|
- q -> q.eq(StatementOfAccount::getType, 2).between(BasePo::getCreateTime, beginDay, endDay));
|
|
|
-
|
|
|
- Map<String, String> codeMap = new HashMap<>(1);
|
|
|
- Map<Long, List<OrderInfo>> orderByDepartmentIdMap = orderList.stream().collect(Collectors.groupingBy(OrderInfo::getDepartmentId));
|
|
|
- orderByDepartmentIdMap.forEach((departmentId, tempOrderList) -> {
|
|
|
-
|
|
|
- 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.setId(IdWorker.getId());
|
|
|
- tempStatementOfAccount.setCode(codeMap.get("code"));
|
|
|
- tempStatementOfAccount.setDepartmentId(departmentId);
|
|
|
- tempStatementOfAccount.setTimePeriod(date);
|
|
|
- tempStatementOfAccount.setType(2);
|
|
|
- saveStatementOfAccountList.add(tempStatementOfAccount);
|
|
|
- return tempStatementOfAccount;
|
|
|
- });
|
|
|
-
|
|
|
- for (OrderInfo order : tempOrderList) {
|
|
|
- OrderInfo editOrderInfo = new OrderInfo();
|
|
|
- editOrderInfo.setId(order.getId());
|
|
|
- editOrderInfo.setStatementOfAccountId(statementOfAccount.getId());
|
|
|
- if (order.getStatus().equals(OrderStatusEnum.IN_PRODUCTION.getKey())) {
|
|
|
- editOrderInfo.setStatus(OrderStatusEnum.COMPLETION_PRODUCTION.getKey());
|
|
|
- editOrderInfo.setShippingTime(map.get(order.getWlnCode()));
|
|
|
- }
|
|
|
- editOrderInfoList.add(editOrderInfo);
|
|
|
+ Map<String, List<StatementOfAccount>> statementOfAccountMap = new HashMap<>();
|
|
|
+
|
|
|
+ for (OrderInfo order : orderList) {
|
|
|
+
|
|
|
+ Date date = map.get(order.getWlnCode());
|
|
|
+ if (date == null) {
|
|
|
+ continue;
|
|
|
}
|
|
|
|
|
|
- });
|
|
|
+ String outDate = DateUtil.format(date, "yyMMdd");
|
|
|
+ Date timePeriod = DateUtil.parse(DateUtil.format(date, "yyyy-MM-dd 19:00:00"));
|
|
|
+ Date beginDate = DateUtil.beginOfDay(date);
|
|
|
+ Date endDate = DateUtil.endOfDay(date);
|
|
|
+
|
|
|
+ List<StatementOfAccount> statementOfAccountList = statementOfAccountMap.computeIfAbsent(outDate, item ->
|
|
|
+ statementOfAccountService.list(q -> q.between(StatementOfAccount::getTimePeriod, beginDate, endDate)));
|
|
|
+
|
|
|
+ StatementOfAccount statementOfAccount = statementOfAccountList.stream()
|
|
|
+ .filter(item -> Objects.equals(item.getType(), 2))
|
|
|
+ .filter(item -> Objects.equals(item.getDepartmentId(), order.getDepartmentId()))
|
|
|
+ .findFirst().orElse(null);
|
|
|
+
|
|
|
+ if (statementOfAccount == null) {
|
|
|
+ int codeNumber = statementOfAccountList.stream()
|
|
|
+ .mapToInt(item -> Convert.toInt(item.getCode().split("-")[2]))
|
|
|
+ .max().orElse(0);
|
|
|
+
|
|
|
+ statementOfAccount = new StatementOfAccount();
|
|
|
+ statementOfAccount.setId(IdWorker.getId());
|
|
|
+ statementOfAccount.setCode("SOA-" + outDate + "-" + (codeNumber + 1));
|
|
|
+ statementOfAccount.setDepartmentId(order.getDepartmentId());
|
|
|
+ statementOfAccount.setTimePeriod(timePeriod);
|
|
|
+ statementOfAccount.setType(2);
|
|
|
+ statementOfAccountList.add(statementOfAccount);
|
|
|
+ saveStatementOfAccountList.add(statementOfAccount);
|
|
|
+ }
|
|
|
+
|
|
|
+ OrderInfo editOrderInfo = new OrderInfo();
|
|
|
+ editOrderInfo.setId(order.getId());
|
|
|
+ editOrderInfo.setStatementOfAccountId(statementOfAccount.getId());
|
|
|
+ if (order.getStatus().equals(OrderStatusEnum.IN_PRODUCTION.getKey())) {
|
|
|
+ editOrderInfo.setStatus(OrderStatusEnum.COMPLETION_PRODUCTION.getKey());
|
|
|
+ editOrderInfo.setShippingTime(map.get(order.getWlnCode()));
|
|
|
+ }
|
|
|
+ editOrderInfoList.add(editOrderInfo);
|
|
|
+ }
|
|
|
|
|
|
orderService.updateBatchById(editOrderInfoList);
|
|
|
|