chen.lin
10 小时以前 82065a03737fa1370eb9f4f01ab5332933baf08a
rsf-server/src/main/java/com/vincent/rsf/server/manager/service/impl/AsnOrderServiceImpl.java
@@ -17,6 +17,7 @@
import com.vincent.rsf.server.manager.controller.params.BatchUpdateParam;
import com.vincent.rsf.server.manager.entity.*;
import com.vincent.rsf.server.manager.enums.*;
import com.vincent.rsf.server.common.utils.QuantityUtils;
import com.vincent.rsf.server.manager.mapper.AsnOrderMapper;
import com.vincent.rsf.server.manager.service.*;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@@ -69,6 +70,8 @@
    private AsnOrderService asnOrderService;
    @Autowired
    private TaskService taskService;
    @Autowired
    private WaitPakinItemService waitPakinItemService;
    @Override
    public boolean notifyInspect(List<WkOrder> orders) {
@@ -143,6 +146,10 @@
     * @param loginUserId
     * @return
     */
    /** 入库单业务类型:拣料入库、盘点入库等不可修改明细,此处为字典 value,按实际配置补充 */
    private static final Set<String> ASN_WKTYPE_NO_EDIT = Collections.unmodifiableSet(new HashSet<>(
            Arrays.asList("53", "57"))); // 53=拣料再入库 57=盘点再入库(与 TaskType 一致,若字典不同请改为实际 value)
    @Override
    @Transactional(rollbackFor = Exception.class)
    public R updateOrderItem(AsnOrderAndItemsParams params, Long loginUserId) throws Exception {
@@ -153,11 +160,23 @@
        if (Objects.isNull(orders.getId())) {
            throw new CoolException("数据错误:单据ID不能为空!!");
        }
        if (!this.updateById(orders)) {
            throw new CoolException("主单修改失败!!");
        WkOrder currentOrder = this.getById(orders.getId());
        if (Objects.isNull(currentOrder)) {
            throw new CoolException("单据不存在!!");
        }
        // 仅未执行状态可修改
        if (!Objects.equals(currentOrder.getExceStatus(), AsnExceStatus.ASN_EXCE_STATUS_UN_EXCE.val)) {
            throw new CoolException("当前单据状态不允许修改,仅未执行状态可修改");
        }
        // 拣料入库、盘点入库类型不可修改
        if (StringUtils.isNotBlank(currentOrder.getWkType()) && ASN_WKTYPE_NO_EDIT.contains(currentOrder.getWkType())) {
            throw new CoolException("拣料入库、盘点入库类型的单据不能修改");
        }
        if (Objects.isNull(params.getItems()) || params.getItems().isEmpty()) {
            return R.ok("明细参数不能为空!!");
            throw new CoolException("明细参数不能为空!!");
        }
        if (!this.updateById(orders)) {
            throw new CoolException("主单修改失败!!");
        }
        svaeOrUpdateOrderItem(params, loginUserId);
@@ -299,7 +318,7 @@
            }
            PurchaseItem service = purchaseItemService.getById(item.getId());
            Double qty = Math.round((service.getQty() + item.getAnfme()) * 10000) / 10000.0;
            Double qty = Math.round((service.getQty() + item.getAnfme()) * 1000000) / 1000000.0;
            if (qty.compareTo(service.getAnfme()) > 0) {
                throw new CoolException("新建单据数量不能大于计划数量!!");
            }
@@ -326,7 +345,7 @@
                throw new CoolException("单据不存在!!");
            }
            Double toQty = Math.round((purchaseItem.getQty() + item.getAnfme()) * 10000) / 10000.0;
            Double toQty = Math.round((purchaseItem.getQty() + item.getAnfme()) * 1000000) / 1000000.0;
            purchaseItem.setQty(toQty);
            if (!purchaseItemService.updateById(purchaseItem)) {
                throw new CoolException("PO单明细修改失败!!");
@@ -339,7 +358,7 @@
            throw new CoolException(("Asn单据明细保存失败!!"));
        }
        //任务执行完成,修改已完成数量和PO单执行状态
        Double qty = Math.round((sum + purchase.getQty()) * 10000) / 10000.0;
        Double qty = Math.round((sum + purchase.getQty()) * 1000000) / 1000000.0;
        purchase.setQty(qty)
                .setExceStatus(POExceStatus.PO_EXCE_STATUS_EXCE_ING.val);
@@ -363,6 +382,12 @@
    @Override
    @Transactional(rollbackFor = Exception.class)
    public R removeOrders(List<Long> ids) {
        // 已组托不可删除,需先解除组托
        long palletizedCount = waitPakinItemService.count(new LambdaQueryWrapper<WaitPakinItem>()
                .in(WaitPakinItem::getAsnId, ids).eq(WaitPakinItem::getDeleted, 0));
        if (palletizedCount > 0) {
            throw new CoolException("单据已组托,请先解除组托后再删除!!");
        }
        for (Long id : ids) {
            List<WkOrderItem> list = asnOrderItemService.list(new LambdaQueryWrapper<WkOrderItem>()
                    .eq(WkOrderItem::getOrderId, id));
@@ -373,7 +398,7 @@
            list.forEach(item -> {
                PurchaseItem purchaseItem = purchaseItemService.getById(item.getPoDetlId());
                if (!Objects.isNull(purchaseItem)) {
                    Double minusQty = Math.round((purchaseItem.getQty() - item.getAnfme()) * 10000) / 10000.0;
                    Double minusQty = Math.round((purchaseItem.getQty() - item.getAnfme()) * 1000000) / 1000000.0;
                    purchaseItem.setQty(minusQty);
                    if (!purchaseItemService.updateById(purchaseItem)) {
                        throw new CoolException("PO单明细更新失败!!");
@@ -386,7 +411,7 @@
            Purchase purchase = purchaseService.getOne(new LambdaQueryWrapper<Purchase>()
                    .eq(Purchase::getCode, list.stream().findFirst().get().getPoCode()));
            if (!Objects.isNull(purchase)) {
                Double qty = Math.round((purchase.getQty() - sum) * 10000) / 10000.0;
                Double qty = Math.round((purchase.getQty() - sum) * 1000000) / 1000000.0;
                purchase.setQty(qty)
                        .setExceStatus(POExceStatus.PO_EXCE_STATUS_EXCE_ING.val);
@@ -428,7 +453,7 @@
        //获取执行中任务数量
        List<Task> tasks = taskService.list(new LambdaQueryWrapper<>());
        if (!tasks.isEmpty()) {
            outTrand.setTaskQty(tasks.size());
            dto.setTaskQty(tasks.size());
        }
        return R.ok().add(dto);
    }
@@ -494,30 +519,38 @@
//            throw new CoolException("收货数量不能为零!!");
//        }
        WkOrder order = this.getById(asrder.getId());
        AsnOrderLog orderLog = new AsnOrderLog();
//        order.setExceStatus(AsnExceStatus.ASN_EXCE_STATUS_TASK_DONE.val);
        BeanUtils.copyProperties(order, orderLog);
        orderLog.setId(null);
        orderLog.setAsnId(order.getId());
//        if (!this.saveOrUpdate(order)) {
//            throw new CoolException("状态修改失败!!");
//        }
//        orderLog.setExceStatus(AsnExceStatus.ASN_EXCE_STATUS_TASK_CLOSE.val);
        if (!asnOrderLogService.save(orderLog)) {
            throw new CoolException("主单历史档添加失败!!");
        AsnOrderLog one = asnOrderLogService.getOne(new LambdaQueryWrapper<AsnOrderLog>().eq(AsnOrderLog::getCode, order.getCode()), false);
        AsnOrderLog orderLog;
        if (Objects.isNull(one)) {
            orderLog = new AsnOrderLog();
            BeanUtils.copyProperties(order, orderLog);
            orderLog.setId(null);
            orderLog.setAsnId(order.getId());
            if (!asnOrderLogService.save(orderLog)) {
                throw new CoolException("主单历史档添加失败!!");
            }
        } else {
            long existingLogId = one.getId();
            BeanUtils.copyProperties(order, one);
            one.setId(existingLogId);
            one.setAsnId(order.getId());
            if (!asnOrderLogService.updateById(one)) {
                throw new CoolException("主单历史档更新失败!!");
            }
            orderLog = one;
            asnOrderItemLogService.remove(new LambdaQueryWrapper<AsnOrderItemLog>().eq(AsnOrderItemLog::getLogId, existingLogId));
        }
        List<AsnOrderItemLog> logs = new ArrayList<>();
        List<WkOrderItem> items = asnOrderItemService.list(new LambdaQueryWrapper<WkOrderItem>().eq(WkOrderItem::getOrderId, order.getId()));
        items.forEach(item -> {
            AsnOrderItemLog itemLog = new AsnOrderItemLog();
            BeanUtils.copyProperties(item, itemLog);
            itemLog.setAsnItemId(itemLog.getId())
            itemLog.setAsnItemId(item.getId())
                    .setId(null)
                    .setLogId(orderLog.getId())
                    .setAsnId(item.getOrderId());
            logs.add(itemLog);
        });
        if (!asnOrderItemLogService.saveBatch(logs)) {
            throw new CoolException("通知单明细历史档保存失败!!");
        }
@@ -528,4 +561,26 @@
            throw new CoolException("原单据删除失败!!");
        }
    }
    @Override
    public void fillPalletQty(List<WkOrder> orders) {
        if (orders == null || orders.isEmpty()) {
            return;
        }
        List<Long> orderIds = orders.stream().map(WkOrder::getId).filter(Objects::nonNull).collect(Collectors.toList());
        if (orderIds.isEmpty()) {
            return;
        }
        List<WaitPakinItem> allItems = waitPakinItemService.list(
                new LambdaQueryWrapper<WaitPakinItem>().in(WaitPakinItem::getAsnId, orderIds).eq(WaitPakinItem::getDeleted, 0));
        Map<Long, Double> sumByAsnId = allItems.stream()
                .collect(Collectors.groupingBy(WaitPakinItem::getAsnId,
                        Collectors.summingDouble(w -> w.getAnfme() != null ? w.getAnfme() : 0.0)));
        sumByAsnId.replaceAll((k, v) -> QuantityUtils.roundToScale(v));
        for (WkOrder order : orders) {
            if (order.getId() != null) {
                order.setPalletQty(sumByAsnId.getOrDefault(order.getId(), 0.0));
            }
        }
    }
}