| | |
| | | package com.vincent.rsf.server.manager.schedules; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
| | | import com.vincent.rsf.framework.exception.CoolException; |
| | | import com.vincent.rsf.server.api.entity.enums.TaskStsType; |
| | | import com.vincent.rsf.server.manager.entity.*; |
| | | import com.vincent.rsf.server.manager.service.*; |
| | | import com.vincent.rsf.server.system.constant.SerialRuleCode; |
| | | import com.vincent.rsf.server.system.enums.LocStsType; |
| | | import com.vincent.rsf.server.system.utils.SerialRuleUtils; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.scheduling.annotation.Scheduled; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.sql.Array; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Objects; |
| | |
| | | if (taskItems.isEmpty()) { |
| | | throw new CoolException("任务明细为空!!"); |
| | | } |
| | | //获取单据明细ID |
| | | List<Long> ids = taskItems.stream().map(TaskItem::getOrderItemId).collect(Collectors.toList()); |
| | | List<AsnOrderItem> items = asnOrderItemService.list(new LambdaQueryWrapper<AsnOrderItem>().in(AsnOrderItem::getAsnId, ids)); |
| | | if (items.isEmpty()) { |
| | | throw new CoolException("数据错误:明细单据不存在"); |
| | | } |
| | | /**获取订单*/ |
| | | List<Long> orders = items.stream().map(AsnOrderItem::getAsnId).collect(Collectors.toList()); |
| | | Map<Long, List<AsnOrderItem>> listMap = items.stream().collect(Collectors.groupingBy(AsnOrderItem::getAsnId)); |
| | | |
| | | listMap.keySet().forEach(key -> { |
| | | AsnOrder order = asnOrderService.getOne(new LambdaQueryWrapper<AsnOrder>().eq(AsnOrder::getId, key)); |
| | | Map<Long, List<TaskItem>> listMap = taskItems.stream().collect(Collectors.groupingBy(TaskItem::getTaskId)); |
| | | List<StockItem> stockItems = new ArrayList<>(); |
| | | for (Task task : tasks) { |
| | | List<TaskItem> taskItem = listMap.get(task.getId()); |
| | | if (taskItem.isEmpty()) { |
| | | throw new CoolException("数据错误 ") |
| | | } |
| | | Stock stock = new Stock(); |
| | | |
| | | listMap.get(task.getId()).forEach(item -> { |
| | | |
| | | }); |
| | | } |
| | | |
| | | |
| | | |
| | | taskItems.forEach(item -> { |
| | | Stock stock = new Stock(); |
| | | AsnOrder order = asnOrderService.getOne(new LambdaQueryWrapper<AsnOrder>() |
| | | .eq(AsnOrder::getId, item.getOrderId()) |
| | | .select(AsnOrder::getId, AsnOrder::getPoCode, AsnOrder::getCode)); |
| | | if (!Objects.isNull(order.getPoCode()) && StringUtils.isNotBlank(order.getPoCode())) { |
| | | Purchase purchase = purchaseService.getOne(new LambdaQueryWrapper<Purchase>().eq(Purchase::getCode, order.getPoCode())); |
| | | stock.setPlatOrderNo(purchase.getPlatCode()).setPlatToken(purchase.getPlatId()); |
| | |
| | | throw new CoolException("当前业务:" + SerialRuleCode.SYS_STOCK_CODE + ",编码规则不存在!!"); |
| | | } |
| | | stock.setAsnId(order.getId()).setAsnCode(order.getCode()); |
| | | |
| | | if (!stockService.save(stock)) { |
| | | throw new CoolException("库存保存失败!!"); |
| | | } |
| | | Task taskServiceOne = taskService.getOne(new LambdaQueryWrapper<Task>() |
| | | .select(Task::getId, Task::getTargLoc, Task::getOrgLoc, Task::getBarcode) |
| | | .eq(Task::getId, item.getTaskId())); |
| | | Loc loc = locService.getOne(new LambdaQueryWrapper<Loc>().eq(Loc::getCode, taskServiceOne.getTargLoc())); |
| | | if (Objects.isNull(loc)) { |
| | | throw new CoolException("库位不存在!!"); |
| | | } |
| | | AsnOrderItem orderItem = asnOrderItemService.getOne(new LambdaQueryWrapper<AsnOrderItem>().eq(AsnOrderItem::getId, item.getOrderItemId())); |
| | | if (Objects.isNull(orderItem)) { |
| | | throw new CoolException("单据明细不存在!!"); |
| | | } |
| | | StockItem stockItem = new StockItem(); |
| | | BeanUtils.copyProperties(orderItem, stockItem); |
| | | stockItem.setAsnItemId(item.getOrderItemId()) |
| | | .setBarcode(taskServiceOne.getBarcode()) |
| | | .setLocId(loc.getId()) |
| | | .setId(null) |
| | | .setStockId(stock.getId()); |
| | | stockItems.add(stockItem); |
| | | }); |
| | | |
| | | if (!stockItemService.saveBatch(stockItems)) { |
| | | throw new CoolException("库存修改架失败!!"); |
| | | } |
| | | List<String> locCodes = tasks.stream().map(Task::getTargLoc).collect(Collectors.toList()); |
| | | if (!locService.update(new LambdaUpdateWrapper<Loc>().set(Loc::getUseStatus, LocStsType.LOC_STS_TYPE_F.type).in(Loc::getCode, locCodes))) { |
| | | throw new CoolException("库位状态修改失败!!"); |
| | | } |
| | | } |
| | | |
| | | } |