skyouc
2 天以前 1068673dcf41cdf7a7a06a26aaeb5652d734eb2d
rsf-server/src/main/java/com/vincent/rsf/server/api/service/impl/PdaOutStockServiceImpl.java
@@ -17,11 +17,14 @@
import com.vincent.rsf.server.manager.service.impl.LocItemWorkingServiceImpl;
import com.vincent.rsf.server.manager.service.impl.StockItemServiceImpl;
import com.vincent.rsf.server.manager.service.impl.StockServiceImpl;
import com.vincent.rsf.server.system.constant.GlobalConfigCode;
import com.vincent.rsf.server.system.constant.SerialRuleCode;
import com.vincent.rsf.server.system.entity.Config;
import com.vincent.rsf.server.system.entity.Fields;
import com.vincent.rsf.server.system.entity.FieldsItem;
import com.vincent.rsf.server.system.service.FieldsItemService;
import com.vincent.rsf.server.system.service.FieldsService;
import com.vincent.rsf.server.system.service.impl.ConfigServiceImpl;
import com.vincent.rsf.server.system.service.impl.FieldsItemServiceImpl;
import com.vincent.rsf.server.system.service.impl.FieldsServiceImpl;
import com.vincent.rsf.server.system.utils.SerialRuleUtils;
@@ -68,6 +71,8 @@
    private LocItemService locItemService;
    @Autowired
    private LocItemWorkingService locItemWorkingService;
    @Autowired
    private ConfigServiceImpl configService;
    @Override
    public R getOutStockTaskItem(String barcode) {
@@ -275,12 +280,20 @@
            if (Objects.isNull(orderItem)) {
                throw new CoolException("数据错误,拣料不在单据需求中!!");
            }
            //taskItems为拣货明细,作参数上报
            Double summed = items.stream().mapToDouble(TaskItem::getAnfme).sum();
            //加上历史拣料数量
            Double pickQty = Math.round((orderItem.getQty() + summed) * 100) / 100.0;
            if (pickQty.compareTo(orderItem.getAnfme()) > 0.0) {
                throw new CoolException("播种数量不能超出订单需求数量");
            Config config = configService.getOne(new LambdaQueryWrapper<Config>().eq(Config::getFlag, GlobalConfigCode.ALLOW_OVER_CHANGE));
            //判断是否允许超收,不允许超收添加拒收判断
            if (!Objects.isNull(config)) {
                if (!Boolean.parseBoolean(config.getVal())) {
                    if (pickQty.compareTo(orderItem.getAnfme()) > 0.0) {
                        throw new CoolException("播种数量不能超出订单需求数量");
                    }
                }
            }
            orderItem.setQty(pickQty);
            if (!asnOrderItemService.updateById(orderItem)) {
@@ -310,13 +323,32 @@
           List<StockItem> stockItems = new ArrayList<>();
            items.forEach(taskItem -> {
                taskItem.setQty(taskItem.getAnfme()).setOrderId(order.getId()).setOrderItemId(orderItem.getId());
                if (!taskItemService.updateById(taskItem)) {
                TaskItem item = taskItemService.getById(taskItem.getId());
                //判断是否允许超收,不允许超收添加拒收判断
                if (!Objects.isNull(config)) {
                    LocItemWorking serviceOne = locItemWorkingService.getOne(new LambdaQueryWrapper<LocItemWorking>().eq(LocItemWorking::getFieldsIndex, item.getFieldsIndex()));
                    if (Objects.isNull(serviceOne)) {
                        throw new CoolException("缓存数据丢失!!");
                    }
                    //不管是否允许超收,都需判断是否超出库存范围
                    if (taskItem.getAnfme().compareTo(serviceOne.getAnfme()) > 0) {
                        throw new CoolException("拣货数量超出当前票号库存数量!!");
                    }
                    if (!Boolean.parseBoolean(config.getVal())) {
                        if (item.getAnfme().compareTo(item.getQty() + taskItem.getAnfme()) < 0.0) {
                            throw new CoolException("前当物料已超出可拣范围,请核对后再操作!!");
                        }
                    }
                }
                item.setQty(item.getQty() + taskItem.getAnfme()).setOrderId(order.getId()).setOrderItemId(orderItem.getId());
                if (!taskItemService.updateById(item)) {
                    throw new CoolException("状态完成失败!!");
                }
                StockItem stockItem = new StockItem();
                BeanUtils.copyProperties(taskItem, stockItem);
                stockItem.setStockId(stock.getId()).setStockCode(stock.getCode()).setSourceItemId(orderItem.getId());
                BeanUtils.copyProperties(item, stockItem);
                //taskItem为上报数据
                stockItem.setStockId(stock.getId()).setAnfme(taskItem.getAnfme()).setStockCode(stock.getCode()).setSourceItemId(orderItem.getId());
                stockItems.add(stockItem);
            });
            if (!stockItemService.saveBatch(stockItems)) {
@@ -326,8 +358,8 @@
        List<WkOrderItem> orderItems = asnOrderItemService.list(new LambdaQueryWrapper<WkOrderItem>().eq(WkOrderItem::getOrderId, params.getOrderId()));
        double total = orderItems.stream().mapToDouble(WkOrderItem::getQty).sum();
        double wkQty = orderItems.stream().mapToDouble(WkOrderItem::getWorkQty).sum();
        order.setQty(total).setWorkQty(order.getWorkQty() - wkQty);
        Double wkQty = orderItems.stream().mapToDouble(WkOrderItem::getWorkQty).sum();
        order.setQty(total).setWorkQty(order.getWorkQty().compareTo(wkQty) < 0 ? 0.0 : (total - wkQty));
        if (!asnOrderService.updateById(order)) {
            throw new CoolException("订单数量更新失败!!");
        }
@@ -454,12 +486,19 @@
            return R.error("任务状态不是待揀狀態");
        }
        List<TaskItem> taskItems = taskItemService.list(new LambdaQueryWrapper<TaskItem>().eq(TaskItem::getTaskId, task.getId()));
        taskItems.forEach(taskItem -> {
           if (!(taskItem.getQty().compareTo(taskItem.getAnfme()) == 0)) {
               throw new CoolException("有单据物料未拣,请拣完后再确认!!");
           }
        });
        Config config = configService.getOne(new LambdaQueryWrapper<Config>().eq(Config::getFlag, GlobalConfigCode.ALLOW_OVER_CHANGE));
        //判断是否允许超收,不允许超收添加拒收判断
        if (!Objects.isNull(config)) {
            if (!Boolean.parseBoolean(config.getVal())) {
                List<TaskItem> taskItems = taskItemService.list(new LambdaQueryWrapper<TaskItem>().eq(TaskItem::getTaskId, task.getId()));
                taskItems.forEach(taskItem -> {
                    if ((taskItem.getQty().compareTo(taskItem.getAnfme()) < 0)) {
                        throw new CoolException("有单据物料未拣,请拣完后再确认!!");
                    }
                });
            }
        }
        try {
            if (task.getTaskType().equals(TaskType.TASK_TYPE_PICK_AGAIN_OUT.type) || task.getTaskType().equals(TaskType.TASK_TYPE_CHECK_OUT.type)) {