✅P98_仓库管理-领取采购单

gong_yz大约 1 分钟谷粒商城

需求描述

采购单分配给了采购人员,采购人员在手机端领取采购单,此时的采购单应该为新建或已分配状态,在采购人员领取后采购单的状态变为已领取,采购需求的状态变为正在采购。


接口信息

接口地址

POST:/ware/purchase/received

请求参数

[1,2,3,4]//采购单id

分页数据

响应数据

{
	"msg": "success",
	"code": 0
}

后端代码

cfmall-ware/src/main/java/com/gyz/cfmall/ware/controller/PurchaseController.java

    @Resource
    private PurchaseService purchaseService;

	/**
     * 领取采购单
     * @param ids
     * @return
     */
    @PostMapping(value = "/received")
    public R received(@RequestBody List<Long> ids) {

        purchaseService.received(ids);

        return R.ok();
    }

cfmall-ware/src/main/java/com/gyz/cfmall/ware/service/impl/PurchaseServiceImpl.java

    /**
     * 领取采购单
     * @param ids 采购单的id
     */
    @Override
    public void received(List<Long> ids) {

        //1、确认当前采购单是新建或者是已分配状态
        List<PurchaseEntity> collect = ids.stream().map(id -> {
            PurchaseEntity byId = this.getById(id);
            return byId;
        }).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(collect);

        //3、改变采购项的状态
        collect.forEach((item) -> {
            List<PurchaseDetailEntity> list = purchaseDetailService.listDetailByPurchaseId(item.getId());
            List<PurchaseDetailEntity> detailEntities = list.stream().map(entity -> {

                PurchaseDetailEntity purchaseDetailEntity = new PurchaseDetailEntity();
                purchaseDetailEntity.setId(entity.getId());
                purchaseDetailEntity.setStatus(WareConstant.PurchaseDetailStatusEnum.BUYING.getCode());
                return purchaseDetailEntity;
            }).collect(Collectors.toList());
            purchaseDetailService.updateBatchById(detailEntities);

        });

    }

cfmall-ware/src/main/java/com/gyz/cfmall/ware/service/PurchaseDetailService.java

List<PurchaseDetailEntity> listDetailByPurchaseId(Long id);

cfmall-ware/src/main/java/com/gyz/cfmall/ware/service/impl/PurchaseDetailServiceImpl.java

    @Override
    public List<PurchaseDetailEntity> listDetailByPurchaseId(Long id) {

        List<PurchaseDetailEntity> purchaseId = this.list(
                new QueryWrapper<PurchaseDetailEntity>().eq("purchase_id", id));

        return purchaseId;
    }