✅P97_仓库管理-合并采购需求
大约 3 分钟
采购简要流程
新建采购需求后还要可以提供合并采购单,比如一个仓库的东西可以合并到一起,让采购人员一趟采购完!
查询未领取的采购单
接口信息
接口地址
GET:/ware/purchase/unreceive/list
请求参数
无
响应数据
{
"msg": "success",
"code": 0,
"page": {
"totalCount": 0,
"pageSize": 10,
"totalPage": 0,
"currPage": 1,
"list": [{
"id": 1,
"assigneeId": 1,
"assigneeName": "aa",
"phone": "123",
"priority": 1,
"status": 1,
"wareId": 1,
"amount": 22.0000,
"createTime": "2019-12-12",
"updateTime": "2019-12-12"
}]
}
}
后端代码
cfmall-ware/src/main/java/com/gyz/cfmall/ware/controller/PurchaseController.java
@Resource
private PurchaseService purchaseService;
@GetMapping(value = "/unreceive/list")
public R unreceiveList(@RequestParam Map<String, Object> params){
PageUtils page = purchaseService.queryPageUnreceive(params);
return R.ok().put("page", page);
}
cfmall-ware/src/main/java/com/gyz/cfmall/ware/service/impl/PurchaseServiceImpl.java
/**
* 查询未领取的采购单
* @param params
* @return
*/
@Override
public PageUtils queryPageUnreceive(Map<String, Object> params) {
QueryWrapper<PurchaseEntity> queryWrapper = new QueryWrapper<PurchaseEntity>()
.eq("status",0).or().eq("status",1);
IPage<PurchaseEntity> page = this.page(
new Query<PurchaseEntity>().getPage(params),
queryWrapper
);
return new PageUtils(page);
}
合并采购需求
接口信息
接口地址
POST:/ware/purchase/merge
请求参数
{
purchaseId: 1, //整单id
items:[1,2,3,4] //合并项集合
}
分页数据
响应数据
{
"msg": "success",
"code": 0
}
后端代码
cfmall-ware/src/main/java/com/gyz/cfmall/ware/controller/PurchaseController.java
@Resource
private PurchaseService purchaseService;
/**
* 合并整单
* @param mergeVo
* @return
*/
@PostMapping(value = "/merge")
public R merge(@RequestBody MergeVo mergeVo) {
purchaseService.mergePurchase(mergeVo);
return R.ok();
}
cfmall-ware/src/main/java/com/gyz/cfmall/ware/vo/MergeVo.java
@Data
public class MergeVo {
private Long purchaseId;
private List<Long> items;
}
cfmall-ware/src/main/java/com/gyz/cfmall/ware/service/impl/PurchaseServiceImpl.java
/**
* 合并采购需求
* @param mergeVo
*/
@Transactional(rollbackFor = Exception.class)
@Override
public void mergePurchase(MergeVo mergeVo) {
Long purchaseId = mergeVo.getPurchaseId();
//没有选择任何【采购单】,将自动创建新单进行合并。
if (purchaseId == null) {
PurchaseEntity purchaseEntity = new PurchaseEntity();
//设置采购单的默认状态
purchaseEntity.setStatus(WareConstant.PurchaseStatusEnum.CREATED.getCode());
purchaseEntity.setCreateTime(new Date());
purchaseEntity.setUpdateTime(new Date());
this.save(purchaseEntity);
//获取新建采购单的id
purchaseId = purchaseEntity.getId();
}
List<Long> items = mergeVo.getItems();
//TODO 确认采购单状态是0,1才可以合并
Collection<PurchaseDetailEntity> purchaseDetailEntities = purchaseDetailService.listByIds(items);
purchaseDetailEntities.forEach((item) -> {
if (!item.getStatus().equals(WareConstant.PurchaseDetailStatusEnum.CREATED.getCode())
&& !item.getStatus().equals(WareConstant.PurchaseDetailStatusEnum.ASSIGNED.getCode())) {
throw new IllegalArgumentException("正在采购,无法进行分配");
}
});
Long finalPurchaseId = purchaseId;
List<PurchaseDetailEntity> collect = items.stream().map(i -> {
PurchaseDetailEntity purchaseDetailEntity = new PurchaseDetailEntity();
purchaseDetailEntity.setId(i);
purchaseDetailEntity.setPurchaseId(finalPurchaseId);
purchaseDetailEntity.setStatus(WareConstant.PurchaseDetailStatusEnum.ASSIGNED.getCode());
return purchaseDetailEntity;
}).collect(Collectors.toList());
//批量修改
purchaseDetailService.updateBatchById(collect);
PurchaseEntity purchaseEntity = new PurchaseEntity();
purchaseEntity.setId(purchaseId);
purchaseEntity.setUpdateTime(new Date());
this.updateById(purchaseEntity);
}
cfmall-common/src/main/java/com/gyz/common/constant/WareConstant.java
package com.gyz.common.constant;
/**
* @Description
* @Author GongYuZhuo
* @Version 1.0.0
*/
public class WareConstant {
public enum PurchaseStatusEnum {
CREATED(0, "新建"),
ASSIGNED(1, "已分配"),
RECEIVE(2, "已领取"),
FINISH(3, "已完成"),
HASERROR(4, "有异常"),
;
private int code;
private String msg;
public int getCode() {
return code;
}
public String getMsg() {
return msg;
}
PurchaseStatusEnum(int code, String msg) {
this.code = code;
this.msg = msg;
}
}
public enum PurchaseDetailStatusEnum {
CREATED(0, "新建"),
ASSIGNED(1, "已分配"),
BUYING(2, "正在采购"),
FINISH(3, "已完成"),
HASERROR(4, "采购失败"),
;
private int code;
private String msg;
public int getCode() {
return code;
}
public String getMsg() {
return msg;
}
PurchaseDetailStatusEnum(int code, String msg) {
this.code = code;
this.msg = msg;
}
}
}
功能优化
添加新建和修改时间
时间格式化:cfmall-ware/src/main/resources/application.yml
spring:
jackson:
date-format: yyyy-MM-dd HH:mm:ss # 时间格式化