1.接口文档
2.PurchaseController中添加received方法
/**
* 领取采购单
* @return
*/
@PostMapping("/received")
public R received(@RequestBody List<Long> ids){
purchaseService.received(ids);
return R.ok();
}
3.PurchaseService中添加received方法
void received(List<Long> ids);
4.PurchaseServiceImpl中添加received方法实现
/**
* 领取采购单
* @param ids 采购单id
*/
@Override
public void received(List<Long> ids) {
//1、确认当前采购单是新建或者已分配状态
List<PurchaseEntity> purchaseEntityList = 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(purchaseEntityList);
//3、改变采购项的状态
purchaseEntityList.forEach((item)->{
List<PurchaseDetailEntity> purchaseDetailEntityList = purchaseDetailService.listDetailByPurchaseId(item.getId());
List<PurchaseDetailEntity> detailEntities = purchaseDetailEntityList.stream().map(entity -> {
PurchaseDetailEntity purchaseDetail = new PurchaseDetailEntity();
purchaseDetail.setId(entity.getId());
purchaseDetail.setStatus(WareConstant.PurchaseDetailStatusEnum.BUYING.getCode());
return purchaseDetail;
}).collect(Collectors.toList());
purchaseDetailService.updateBatchById(detailEntities);
});
}
5.PurchaseDetailService中添加listDetailByPurchaseId方法
/**
* 根据采购单id查询所有采购项
* @param id
* @return
*/
List<PurchaseDetailEntity> listDetailByPurchaseId(Long id);
6.PurchaseDetailServiceImpl中添加listDetailByPurchaseId方法实现
@Override
public List<PurchaseDetailEntity> listDetailByPurchaseId(Long id) {
List<PurchaseDetailEntity> purchaseDetailEntityList = this.list(
new QueryWrapper<PurchaseDetailEntity>().eq("purchase_id", id));
return purchaseDetailEntityList;
}
2号采购单对应2号,4号采购需求
用postman模拟采购人员领取采购单
采购需求中对应的采购项状态由已分配改为正在采购
采购单中状态由已分配改为已领取