| | |
| | | package com.vincent.rsf.server.manager.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.vincent.rsf.framework.common.Cools; |
| | |
| | | import java.math.BigDecimal; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | import java.util.stream.Stream; |
| | | |
| | | import com.vincent.rsf.server.manager.enums.WaveRuleType; |
| | | |
| | |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public R genOutStock(List<Long> ids, Long loginUserId) { |
| | | if (Objects.isNull(ids) || ids.isEmpty()) { |
| | | throw new CoolException("参数不能为空!!"); |
| | | } |
| | | List<DeliveryItem> items = deliveryItemService.list(new LambdaQueryWrapper<DeliveryItem>().in(DeliveryItem::getId, ids)); |
| | | public R genOutStock(List<DeliveryItem> items, Long loginUserId) { |
| | | if (items.isEmpty()) { |
| | | throw new CoolException("单据不存在!!"); |
| | | throw new CoolException("参数不能为空!!"); |
| | | } |
| | | Map<Long, List<DeliveryItem>> listMap = items.stream().collect(Collectors.groupingBy(DeliveryItem::getDeliveryId)); |
| | | listMap.keySet().forEach(key -> { |
| | |
| | | AsnOrder order = new AsnOrder(); |
| | | BeanUtils.copyProperties(delivery, order); |
| | | String ruleCode = SerialRuleUtils.generateRuleCode(SerialRuleCode.SYS_OUT_STOCK_CODE, order); |
| | | if (Objects.isNull(ruleCode) || StringUtils.isBlank(ruleCode)) { |
| | | if (StringUtils.isBlank(ruleCode)) { |
| | | throw new CoolException("编码规则错误:请检查 「SYS_OUT_STOCK_CODE」编码是否设置成功"); |
| | | } |
| | | order.setExceStatus(AsnExceStatus.OUT_STOCK_STATUS_TASK_INIT.val) |
| | |
| | | } |
| | | List<AsnOrderItem> orderItems = new ArrayList<>(); |
| | | listMap.get(key).forEach(item -> { |
| | | DeliveryItem deliveryItem = deliveryItemService.getById(item.getId()); |
| | | AsnOrderItem orderItem = new AsnOrderItem(); |
| | | Double anfme = Math.round((item.getAnfme() - item.getWorkQty() - item.getQty()) * 10000) / 10000.0; |
| | | if (item.getAnfme().compareTo(0.0) <= 0) { |
| | | throw new CoolException("出库数量不能小于或等于零!!"); |
| | | } |
| | | Double anfme = Math.round((deliveryItem.getAnfme() - item.getAnfme()) * 10000) / 10000.0; |
| | | if (anfme.compareTo(0.0) < 0) { |
| | | throw new CoolException("出库数量不足!!"); |
| | | } |
| | | |
| | | BeanUtils.copyProperties(item, orderItem); |
| | | orderItem.setId(null) |
| | | .setPoCode(order.getPoCode()) |
| | | .setMaktx(item.getMaktx()) |
| | | .setMatnrCode(item.getMatnrCode()) |
| | | .setFieldsIndex(item.getFieldsIndex()) |
| | | .setAnfme(anfme) |
| | | .setAnfme(item.getAnfme()) |
| | | .setWorkQty(0.0) |
| | | .setAsnId(order.getId()) |
| | | .setAsnCode(order.getCode()) |
| | |
| | | .eq(Delivery::getId, key))) { |
| | | throw new CoolException("主单修改失败!!"); |
| | | } |
| | | |
| | | }); |
| | | return R.ok(); |
| | | } |
| | |
| | | throw new CoolException("策略参数为空"); |
| | | } |
| | | if (Cools.isEmpty(param.getOrderId())) { |
| | | throw new CoolException("单据id为空"); |
| | | throw new CoolException("单据ID为空"); |
| | | } |
| | | WaveRule waveRule = waveRuleService.getOne(new LambdaQueryWrapper<WaveRule>().eq(WaveRule::getId, param.getWaveId())); |
| | | if (Cools.isEmpty(waveRule)) { |
| | |
| | | * 生成出库任务 |
| | | * |
| | | * @param params |
| | | * @param outId |
| | | * @return |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public R genOutStockTask(List<OutStockToTaskParams> params, Long loginUserId) { |
| | | public R genOutStockTask(List<OutStockToTaskParams> params, Long loginUserId, Long outId) { |
| | | if (params.isEmpty()) { |
| | | throw new CoolException("参数不能为空!!"); |
| | | } |
| | | |
| | | //优先生成浅库位任务 |
| | | List<OutStockToTaskParams> Items = params.stream().sorted(Comparator.comparing(OutStockToTaskParams::getLocCode).thenComparing(item -> { |
| | | return LocUtils.isShallowLoc(item.getLocCode()) ? 1 : 0; |
| | |
| | | if (Objects.isNull(param)) { |
| | | continue; |
| | | } |
| | | Loc loc = locService.getOne(new LambdaQueryWrapper<Loc>().eq(Loc::getBarcode, param.getBarcode())); |
| | | Loc loc = locService.getOne(new LambdaQueryWrapper<Loc>().eq(Loc::getCode, param.getLocCode()).eq(Loc::getBarcode, param.getBarcode())); |
| | | if (!Objects.isNull(loc)) { |
| | | List<LocItem> locItems = new ArrayList<>(); |
| | | LocItem locItem = locItemService.getById(param.getId()); |
| | | locItem.setOutQty(param.getOutQty()).setBatch(param.getBatch()); |
| | | |
| | | AsnOrderItem orderItem = outStockItemService.getOne(new LambdaQueryWrapper<AsnOrderItem>() |
| | | .eq(AsnOrderItem::getAsnId, outId) |
| | | .eq(StringUtils.isNotBlank(locItem.getBatch()), AsnOrderItem::getSplrBatch, locItem.getBatch()) |
| | | .eq(StringUtils.isNotBlank(locItem.getFieldsIndex()), AsnOrderItem::getFieldsIndex, locItem.getFieldsIndex()) |
| | | .eq(AsnOrderItem::getMatnrId, locItem.getMatnrId())); |
| | | |
| | | if (Objects.isNull(orderItem)) { |
| | | throw new CoolException("单据明细不存在!!"); |
| | | } |
| | | |
| | | locItem.setOutQty(param.getOutQty()) |
| | | .setBatch(param.getBatch()) |
| | | .setSourceId(outId) |
| | | .setSourceCode(orderItem.getAsnCode()) |
| | | .setSource(orderItem.getId()); |
| | | locItems.add(locItem); |
| | | |
| | | LocToTaskParams taskParams = new LocToTaskParams(); |
| | | taskParams.setType(Constants.TASK_TYPE_OUT_STOCK) |
| | | taskParams.setType(Constants.TASK_TYPE_ORDER_OUT_STOCK) |
| | | .setOrgLoc(loc.getCode()) |
| | | .setItems(locItems) |
| | | .setSourceId(outId) |
| | | .setSiteNo(param.getSiteNo()); |
| | | try { |
| | | locItemService.generateTask(taskParams, loginUserId); |
| | | //生成出库任务 |
| | | locItemService.generateTask(TaskResouceType.TASK_RESOUCE_ORDER_TYPE.val, taskParams, loginUserId); |
| | | } catch (Exception e) { |
| | | logger.error("UNK", e); |
| | | throw new CoolException(e.getMessage()); |
| | | } |
| | | |
| | | |
| | | Double workQty = Math.round((orderItem.getWorkQty() + locItem.getOutQty()) * 10000) / 10000.0; |
| | | |
| | | orderItem.setUpdateBy(loginUserId).setUpdateTime(new Date()).setWorkQty(workQty); |
| | | |
| | | if (!outStockItemService.updateById(orderItem)) { |
| | | throw new CoolException("单据明细修改失败!!"); |
| | | } |
| | | } |
| | | } |
| | | |
| | | Double sum = Items.stream().mapToDouble(OutStockToTaskParams::getOutQty).sum(); |
| | | //更新出库单明细及主单 |
| | | AsnOrder outOrder = outStockService.getById(outId); |
| | | if (Objects.isNull(outOrder)) { |
| | | throw new CoolException("出库单据不存在!!"); |
| | | } |
| | | Double workQty = Math.round((outOrder.getWorkQty() + sum) * 10000) / 10000.0; |
| | | |
| | | outOrder.setWorkQty(workQty).setExceStatus(AsnExceStatus.OUT_STOCK_STATUS_TASK_CREATE.val); |
| | | |
| | | if (!outStockService.updateById(outOrder)) { |
| | | throw new CoolException("出库单状态修改失败!!"); |
| | | } |
| | | |
| | | return R.ok(); |
| | | } |
| | | |
| | | /** |
| | | * 获取出库站点 |
| | | * |
| | | * @return |
| | | */ |
| | | @Override |
| | | public R getSiteNos() { |
| | | List<Integer> list = Arrays.asList(TaskType.TASK_TYPE_MERGE_OUT.type, |
| | | TaskType.TASK_TYPE_OUT.type, |
| | | TaskType.TASK_TYPE_MERGE_OUT.type, |
| | | TaskType.TASK_TYPE_PICK_AGAIN_OUT.type); |
| | | List<DeviceSite> sites = deviceSiteService.list(new LambdaQueryWrapper<DeviceSite>().in(DeviceSite::getType, list).groupBy(DeviceSite::getSite)); |
| | | return R.ok(sites); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public R cancelOutOrderByItems(List<AsnOrderItem> orderItems) { |
| | | Map<Long, List<AsnOrderItem>> listMap = orderItems.stream().collect(Collectors.groupingBy(AsnOrderItem::getAsnId)); |
| | | for (Long key : listMap.keySet()) { |
| | | AsnOrder order = this.getById(key); |
| | | if (Objects.isNull(order)) { |
| | | throw new CoolException("单据不存在!!"); |
| | | } |
| | | List<AsnOrderItem> items = listMap.get(key); |
| | | if (!items.isEmpty()) { |
| | | for (AsnOrderItem orderItem : items) { |
| | | DeliveryItem deliveryItem = deliveryItemService.getById(orderItem.getPoDetlId()); |
| | | Double workQty = Math.round((deliveryItem.getWorkQty() - orderItem.getAnfme()) * 10000) / 10000.0; |
| | | deliveryItem.setWorkQty(workQty.compareTo(0.0) >= 0 ? workQty : 0); |
| | | if (!deliveryItemService.updateById(deliveryItem)) { |
| | | throw new CoolException("DO单明细更新失败!!"); |
| | | } |
| | | |
| | | Delivery delivery = deliveryService.getOne(new LambdaQueryWrapper<Delivery>().eq(Delivery::getCode, orderItem.getPoCode())); |
| | | if (!Objects.isNull(delivery)) { |
| | | Double wkQty = Math.round((delivery.getWorkQty() - delivery.getAnfme()) * 10000) / 10000.0; |
| | | delivery.setWorkQty(wkQty.compareTo(0.0) >= 0 ? wkQty : 0).setExceStatus(POExceStatus.PO_EXCE_STATUS_UN_EXCE.val); |
| | | if (!deliveryService.updateById(delivery)) { |
| | | throw new CoolException("DO单据修改失败!!"); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | if (!this.remove(new LambdaQueryWrapper<AsnOrder>().eq(AsnOrder::getId, key))) { |
| | | throw new CoolException("主单删除失败!!"); |
| | | } |
| | | if (!outStockItemService.remove(new LambdaQueryWrapper<AsnOrderItem>() |
| | | .eq(AsnOrderItem::getAsnId, key))) { |
| | | throw new CoolException("单据明细删除失败!!"); |
| | | } |
| | | } |
| | | return R.ok("操作成功"); |
| | | } |
| | | |
| | | |
| | |
| | | ); |
| | | locItemQueryWrapper.apply(applySql); |
| | | List<LocItem> locItems = locItemService.list(locItemQueryWrapper); |
| | | locItems.sort(Comparator |
| | | .comparing((LocItem item) -> !LocUtils.isShallowLoc(item.getLocCode())) |
| | | ); |
| | | locItems.sort(Comparator.comparing((LocItem item) -> !LocUtils.isShallowLoc(item.getLocCode()))); |
| | | List<LocItem> locsSet = locItems.stream().filter(locItem -> locItem.getAnfme().compareTo(asnOrderItem.getAnfme()) == 0.0).collect(Collectors.toList()); |
| | | if (!locsSet.isEmpty()) { |
| | | return locsSet; |
| | | } |
| | | return locItems; |
| | | } |
| | | |
| | |
| | | |
| | | private List<OrderOutItemDto> getOutOrderList(Long orderId, WaveRule waveRule) { |
| | | List<AsnOrderItem> asnOrderItems = asnOrderItemService.list(new LambdaQueryWrapper<AsnOrderItem>() |
| | | .eq(AsnOrderItem::getAsnId, orderId) |
| | | ); |
| | | .eq(AsnOrderItem::getAsnId, orderId)); |
| | | List<OrderOutItemDto> list = new ArrayList<>(); |
| | | Set<ExistDto> existDtos = new HashSet<>(); |
| | | |
| | |
| | | if (issued.doubleValue() <= 0) { |
| | | continue; |
| | | } |
| | | List<LocItem> locItems = null; |
| | | List<LocItem> locItems = new ArrayList<>(); |
| | | if (WaveRuleType.Efficiency_First.type.equals(waveRule.getType())) { |
| | | locItems = getEfficiencyFirstItemList(asnOrderItem); |
| | | } else if (WaveRuleType.First_In_First_Out.type.equals(waveRule.getType())) { |
| | |
| | | .eq(DeviceSite::getChannel, loc.getChannel()) |
| | | .eq(DeviceSite::getType, issued.doubleValue() >= locItem.getAnfme() && itemList.size() == 1 ? TaskType.TASK_TYPE_OUT.type : TaskType.TASK_TYPE_PICK_AGAIN_OUT.type) |
| | | ); |
| | | List<OrderOutItemDto.staListDto> maps = new ArrayList<>(); |
| | | for (DeviceSite sta : deviceSites) { |
| | | OrderOutItemDto.staListDto staListDto = new OrderOutItemDto.staListDto(); |
| | | staListDto.setStaNo(sta.getSite()); |
| | | staListDto.setStaName(sta.getSite()); |
| | | maps.add(staListDto); |
| | | |
| | | if (!deviceSites.isEmpty()) { |
| | | List<OrderOutItemDto.staListDto> maps = new ArrayList<>(); |
| | | for (DeviceSite sta : deviceSites) { |
| | | OrderOutItemDto.staListDto staListDto = new OrderOutItemDto.staListDto(); |
| | | staListDto.setStaNo(sta.getSite()); |
| | | staListDto.setStaName(sta.getSite()); |
| | | maps.add(staListDto); |
| | | } |
| | | orderOutItemDto.setStaNos(maps); |
| | | //默认获取第一站点 |
| | | DeviceSite deviceSite = deviceSites.stream().findFirst().get(); |
| | | orderOutItemDto.setSiteNo(deviceSite.getSite()); |
| | | } |
| | | orderOutItemDto.setStaNos(maps); |
| | | |
| | | list.add(orderOutItemDto); |
| | | |
| | | issued = issued.subtract(new BigDecimal(locItem.getAnfme().toString())); |
| | | } |
| | | } |
| | | } else { |
| | | |
| | | } |
| | | } |
| | | if (issued.doubleValue() > 0) { |
| | | LocItem locItem = new LocItem() |
| | | .setId(new Random().nextLong()) |
| | | .setMatnrCode(asnOrderItem.getMatnrCode()) |
| | | .setMaktx(asnOrderItem.getMaktx()) |
| | | .setAnfme(0.00) |
| | | .setWorkQty(issued.doubleValue()) |
| | | .setOutQty(issued.doubleValue()) |
| | | .setUnit(asnOrderItem.getStockUnit()) |
| | | .setBatch(asnOrderItem.getSplrBatch()); |
| | | OrderOutItemDto orderOutItemDto = new OrderOutItemDto(); |
| | | orderOutItemDto.setLocItem(locItem); |
| | | list.add(orderOutItemDto); |
| | | } |
| | | } |
| | | |