skyouc
4 天以前 930cf3fe63ddea4720ca6818df94c2161a04054f
rsf-server/src/main/java/com/vincent/rsf/server/manager/service/impl/TaskServiceImpl.java
@@ -79,6 +79,10 @@
    private LocItemWorkingService locItemWorkingService;
    @Autowired
    private WcsService wcsService;
    @Autowired
    private OutStockService outStockService;
    @Autowired
    private OutStockItemService outStockItemService;
    @Override
    @Transactional(rollbackFor = Exception.class)
@@ -306,6 +310,7 @@
            task.setTaskCode(ruleCode)
                    .setTaskStatus(TaskStsType.GENERATE_IN.id)
                    .setTaskType(TaskType.TASK_TYPE_IN.type)
                    .setResource(TaskResouceType.TASK_RESOUCE_PAKIN_TYPE.val)
                    .setTargLoc(targetLoc)
                    .setBarcode(pakin.getBarcode())
                    .setOrgSite(deviceSite.getSite())
@@ -519,6 +524,7 @@
    /**
     * 任务完成后,判断深库位是否为空,如果为空生成移库任务
     *
     * @param loginUserId
     * @param curLoc
     */
@@ -753,8 +759,6 @@
                    if (!this.updateById(outTask)) {
                        throw new CoolException("任务信息修改失败!!");
                    }
                } else {
//                    throw new CoolException("无法生成新的移库任务,取消失败!!");
                }
            }
@@ -787,17 +791,47 @@
            if (!taskItems.isEmpty()) {
                for (TaskItem item : taskItems) {
                    if (item.getOrderType().equals(OrderType.ORDER_OUT.type)) {
                        Loc loc = locService.getOne(new LambdaQueryWrapper<Loc>().eq(Loc::getCode, task.getOrgLoc()));
                        if (Objects.isNull(loc)) {
                            throw new CoolException("数据错误:库位信息不存在!!");
                        }
                        loc.setUseStatus(LocStsType.LOC_STS_TYPE_F.type).setBarcode(task.getBarcode()).setUpdateBy(loginUserId).setUpdateTime(new Date());
                        if (!locService.updateById(loc)) {
                            throw new CoolException("库位信息修改失败!!");
                        }
                        //出库
                        if (item.getWkType().equals(Short.parseShort(OrderWorkType.ORDER_WORK_TYPE_STOCK_OUT.type))) {
                            //库存出库
                            Loc loc = locService.getOne(new LambdaQueryWrapper<Loc>().eq(Loc::getId, item.getSourceId()));
                            if (Objects.isNull(loc)) {
                                throw new CoolException("数据错误:库位信息不存在!!");
                        } else if (item.getWkType().equals(Short.parseShort(OrderWorkType.ORDER_WORK_TYPE_OTHER.type))) {
                            //其它出库
                        } else {
                            //出库单出库
                            AsnOrder asnOrder = outStockService.getById(item.getSourceId());
                            if (Objects.isNull(asnOrder)) {
                                throw new CoolException("数据错误:单据已不存在!!");
                            }
                            Double workQty = Math.round((asnOrder.getWorkQty() - item.getAnfme()) * 10000) / 10000.0;
                            asnOrder.setExceStatus(AsnExceStatus.OUT_STOCK_STATUS_TASK_INIT.val)
                                    .setWorkQty(workQty.compareTo(0.00) > 0 ? workQty : 0.00)
                                    .setUpdateBy(loginUserId)
                                    .setUpdateTime(new Date());
                            if (!outStockService.updateById(asnOrder)) {
                                throw new CoolException("原单据状态修改失败!!");
                            }
                            loc.setUseStatus(LocStsType.LOC_STS_TYPE_F.type).setBarcode(task.getBarcode()).setUpdateBy(loginUserId).setUpdateTime(new Date());
                            if (!locService.updateById(loc)) {
                                throw new CoolException("库位信息修改失败!!");
                            AsnOrderItem orderItem = outStockItemService.getById(item.getSource());
                            if (Objects.isNull(orderItem)) {
                                throw new CoolException("数据错误:单据明细已不存在!!");
                            }
                            Double workItmQty = Math.round((orderItem.getWorkQty() - item.getAnfme()) * 10000) / 10000.0;
                            orderItem.setWorkQty(workItmQty);
                            if (!outStockItemService.updateById(orderItem)) {
                                throw new CoolException("原单据明细修改失败!!");
                            }
                        }
                    } else {
@@ -998,19 +1032,34 @@
        if (Objects.isNull(list) || list.isEmpty()) {
            Map<Long, List<TaskItem>> maps = taskItems.stream().collect(Collectors.groupingBy(TaskItem::getSource));
            maps.keySet().forEach(key -> {
                WaveItem waveItem = waveItemService.getById(key);
                if (Objects.isNull(waveItem)) {
                    throw new CoolException("波次明细不存在!!");
                }
                try {
                    saveOutStockItem(maps.get(key), waveItem, loginUserId);
                } catch (Exception e) {
                    throw new CoolException(e.getMessage());
                if (task.getResource().equals(TaskResouceType.TASK_RESOUCE_WAVE_TYPE.val)) {
                    WaveItem waveItem = waveItemService.getById(key);
                    if (Objects.isNull(waveItem)) {
                        throw new CoolException("波次明细不存在!!");
                    }
                    try {
                        saveOutStockItem(maps.get(key), null, waveItem, loginUserId);
                    } catch (Exception e) {
                        throw new CoolException(e.getMessage());
                    }
                } else if (task.getResource().equals(TaskResouceType.TASK_RESOUCE_ORDER_TYPE.val)) {
                    AsnOrderItem orderItem = asnOrderItemService.getById(key);
                    if (Objects.isNull(orderItem)) {
                        throw new CoolException("单据明细不存在!!");
                    }
                    try {
                        saveOutStockItem(maps.get(key), orderItem, null, loginUserId);
                    } catch (Exception e) {
                        throw new CoolException(e.getMessage());
                    }
                } else {
                }
            });
        } else {
            try {
                saveOutStockItem(taskItems, null, loginUserId);
                saveOutStockItem(taskItems, null, null, loginUserId);
            } catch (Exception e) {
                throw new CoolException(e.getMessage());
            }
@@ -1057,7 +1106,7 @@
     * @version 1.0
     */
    @Transactional(rollbackFor = Exception.class)
    public void saveOutStockItem(List<TaskItem> taskItems, WaveItem waveItem, Long loginUserId) throws Exception {
    public void saveOutStockItem(List<TaskItem> taskItems, AsnOrderItem orderItem, WaveItem waveItem, Long loginUserId) throws Exception {
        Stock stock = new Stock();
        String ruleCode = SerialRuleUtils.generateRuleCode(SerialRuleCode.SYS_STOCK_CODE, null);
        if (StringUtils.isBlank(ruleCode)) {
@@ -1070,7 +1119,11 @@
                .setAnfme(sum);
        if (Objects.isNull(waveItem)) {
            stock.setWkType(Short.parseShort(OrderWorkType.ORDER_WORK_TYPE_STOCK_OUT.type))
                    .setMemo("出库单出库,无单据信息!!")
                    .setMemo("库存出库,无单据信息!!")
                    .setType(OrderType.ORDER_OUT.type);
        } else if (!Objects.isNull(orderItem) && StringUtils.isNotBlank(orderItem.getId() + "")) {
            AsnOrder asnOrder = asnOrderService.getById(orderItem.getAsnId());
            stock.setWkType(Short.parseShort(asnOrder.getWkType()))
                    .setType(OrderType.ORDER_OUT.type);
        } else {
            //TODO 生成波次时需要将波次号写入单据,通过物料,批次,动态字段等唯一值反查单据信息