五十六.领取采购单功能编写

PurchaseController类添加相关接口,如下:

   /**
     * 领取采购单
     *
     * @return
     */
    @PostMapping("/received")
    public R received(@RequestBody List<Long> ids) {
        purchaseService.received(ids);
        return R.ok();
    }

PurchaseService类添加如下方法:

    /**
     * 领取采购单
     *
     * @param ids
     */
    void received(List<Long> ids);

PurchaseServiceImpl类中添加该方法的实现,如下:

@Override
    public void received(List<Long> ids) {
        //1、过滤掉采购单不是新建或者已分配状态的数据
        List<PurchaseEntity> purchaseEntities = ids.stream().map(id -> {
            PurchaseEntity purchaseEntity = this.getById(id);
            return purchaseEntity;
        }).filter(item -> {
            if (item.getStatus() == WareConstant.PurchaseStatusEnum.CREATED.getCode() ||
                    item.getStatus() == WareConstant.PurchaseStatusEnum.ASSIGNED.getCode()) {
                return true;
            }
            return false;
        }).map(item -> {
            item.setStatus(WareConstant.PurchaseStatusEnum.RECEIVE.getCode());
            item.setUpdateTime(new Date());
            return item;
        }).collect(Collectors.toList());

        //2、更新采购单的状态
        this.updateBatchById(purchaseEntities);


        //3、更新采购需求的状态
        purchaseEntities.forEach((item) -> {
            List<PurchaseDetailEntity> entities = detailService.listDetailByPurchaseId(item.getId());
            List<PurchaseDetailEntity> detailEntities = entities.stream().map(entity -> {
                PurchaseDetailEntity purchaseDetailEntity = new PurchaseDetailEntity();
                purchaseDetailEntity.setId(entity.getId());
                purchaseDetailEntity.setStatus(WareConstant.PurchaseDetailStatusEnum.BUYING.getCode());
                return purchaseDetailEntity;
            }).collect(Collectors.toList());
            detailService.updateBatchById(detailEntities);
        });
    }

领取采购单功能相关代码完成。

你可能感兴趣的:(从零开始搭建一个电商系统,领取采购单功能编写,java)