采购人员领取采购单功能
本章编写采购人员领取采购单的功能,对应的API文档:
06、领取采购单
POST
/ware/purchase/received
请求参数
[1,2,3,4]//采购单id
分页数据
响应数据
{
"msg": "success",
"code": 0
}
首先需要在系统中添加一位采购人员:
同时添加一份采购单:
之后合并需求成为一张整单采购单:
对应数据库中也有了采购单的数据
之后来到postman来模拟请求:
此时的返回是404,之后来编写这个借口来完成这个服务。首先添加controller:
/**
* 领取采购单
* @return
*/
@PostMapping("/received")
public R received(@RequestBody List<Long> ids){
purchaseService.received(ids);
return R.ok();
}
之后实现方法received(ids):
/**
*
* @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> entities = detailService.listDetailByPurchaseId(item.getId());
List<PurchaseDetailEntity> detailEntities = entities.stream().map(entity -> {
PurchaseDetailEntity entity1 = new PurchaseDetailEntity();
entity1.setId(entity.getId());
entity1.setStatus(WareConstant.PurchaseDetailStatusEnum.BUYING.getCode());
return entity1;
}).collect(Collectors.toList());
detailService.updateBatchById(detailEntities);
});
}
其中要创建新加一个方法listDetailByPurchaseId,通过请求单ID来获取请求单全部信息的方法:
@Override
public List<PurchaseDetailEntity> listDetailByPurchaseId(Long id) {
List<PurchaseDetailEntity> purchaseId = this.list(new QueryWrapper<PurchaseDetailEntity>().eq("purchase_id", id));
return purchaseId;
}
之后可以来到postman进行模拟领取采购单:
领取成功之后来到前端代码,可以看到采购单已经领取: