目录
1.仓库维护
1.1配置网关陆游规则
1.2修改模糊查询
2.仓库库存
3.采购需需求
3.1采购的模糊检索
3.2合并采购单
3.3领取采购单
3.4完成采购
4.spu规格
4.1 获取spu规格
4.2更新spu规格
开打界面查看发送的请求路径,因为我们配置类网关,所以目前报错
配置完网关之后,我们再次刷新页面,就可以查询到结果,包括新增,修改和删除共功能,以为之前逆向工程已经生成好后端接口
点击查询,发送请求,根据请求路径找到相应的controller,并对相应的service方法添加模糊查询
@RequestMapping("/list")
//@RequiresPermissions("ware:wareinfo:list")
public R list(@RequestParam Map params){
PageUtils page = wareInfoService.queryPage(params);
return R.ok().put("page", page);
}
@Override
public PageUtils queryPage(Map params) {
QueryWrapper wrapper = new QueryWrapper<>();
String key = (String) params.get("key");
if (!StringUtils.isEmpty(key)) {
wrapper.eq("id", key)
.or().like("name", key)
.or().like("address", key)
.or().eq("areacode", key);
}
IPage page = this.page(
new Query().getPage(params),
wrapper
);
return new PageUtils(page);
}
在service上拼接条件,添加两个模糊查询
@Override
public PageUtils queryPage(Map params) {
QueryWrapper wrapper = new QueryWrapper<>();
String skuId =(String) params.get("skuId");
if (!StringUtils.isEmpty(skuId)){
wrapper.eq("sku_id",skuId);
}
String wareId =(String) params.get("wareId");
if (!StringUtils.isEmpty(wareId)){
wrapper.eq("ware_id",wareId);
}
IPage page = this.page(
new Query().getPage(params),
wrapper
);
return new PageUtils(page);
}
@RequestMapping("/list")
//@RequiresPermissions("ware:purchasedetail:list")
public R list(@RequestParam Map params){
PageUtils page = purchaseDetailService.queryPage(params);
return R.ok().put("page", page);
}
@Override
public PageUtils queryPage(Map params) {
QueryWrapper wrapper = new QueryWrapper<>();
String key = (String) params.get("key");
if (!StringUtils.isEmpty(key)){
wrapper.and((w)->{
w.eq("purchase_id",key).or().eq("sku_id",key);
});
}
String status = (String) params.get("status");
if (!StringUtils.isEmpty(status)){
wrapper.eq("status",status);
}
String wareId = (String) params.get("wareId");
if (!StringUtils.isEmpty(wareId)){
wrapper.eq("ware_id",wareId);
}
IPage page = this.page(
new Query().getPage(params),
wrapper
);
return new PageUtils(page);
}
@PostMapping("/merge")
public R merge(@RequestBody MergeVo mergeVo) {
purchaseService.mergePurchase(mergeVo);
return R.ok();
}
@Transactional
@Override
public void mergePurchase(MergeVo mergeVo) {
Long purchaseId = mergeVo.getPurchaseId();
if (purchaseId == null) {
//1.新建
PurchaseEntity purchaseEntity = new PurchaseEntity();
purchaseEntity.setStatus(WareConstant.PurchaseStatusEnum.CREATE.getCode());
purchaseEntity.setCreateTime(new Date());
purchaseEntity.setUpdateTime(new Date());
this.save(purchaseEntity);
purchaseId = purchaseEntity.getId();
}
List items = mergeVo.getItems();
Long finalPurchaseId = purchaseId;
List collect = items.stream().map(i -> {
PurchaseDetailEntity detailEntity = new PurchaseDetailEntity();
detailEntity.setId(i);
detailEntity.setPurchaseId(finalPurchaseId);
detailEntity.setStatus(WareConstant.PurchaseDetailStatusEnum.ASSIGNED.getCode());
return detailEntity;
}).collect(Collectors.toList());
detailService.updateBatchById(collect);
PurchaseEntity purchaseEntity = new PurchaseEntity();
purchaseEntity.setId(purchaseId);
purchaseEntity.setUpdateTime(new Date());
this.updateById(purchaseEntity);
}
使用postman发送采购请求
@PostMapping("/received")
public R received(@RequestBody List ids){
purchaseService.received(ids);
return R.ok();
}
@Override
public void received(List ids) {
//1.确认当前采购单是新建或已分配状态
List collect = ids.stream().map(id -> {
PurchaseEntity byId = this.getById(id);
return byId;
}).filter(item -> {
if (item.getStatus() == WareConstant.PurchaseStatusEnum.CREATE.getCode() ||
item.getStatus() == WareConstant.PurchaseStatusEnum.ASSIGNED.getCode()) {
return true;
}
return false;
}).map(item -> {
item.setStatus(WareConstant.PurchaseStatusEnum.RECEIVE.getCode());
return item;
}).collect(Collectors.toList());
//2.改变采购单的状态
this.updateBatchById(collect);
//3.改变采购项的状态
collect.forEach((item) -> {
List entities = detailService.listDetailByPurchaseId(item.getId());
List 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);
});
}
@PostMapping("/done")
public R finish(@RequestBody PurchaseDoneVo doneVo) {
purchaseService.done(doneVo);
return R.ok();
}
@Override
public void addStock(Long skuId, Long wareId, Integer skuNum) {
//1.判断如果还没有库存记录。那就是新增操作,如果有,才更新
List entities = wareSkuDao.selectList(new QueryWrapper().eq("sku_id", skuId).eq("ware_id", wareId));
if (entities == null || entities.size() == 0) {
WareSkuEntity skuEntity = new WareSkuEntity();
skuEntity.setSkuId(skuId);
skuEntity.setStock(skuNum);
skuEntity.setWareId(wareId);
skuEntity.setStockLocked(0);
// TODO 远程查询sku的名字,如果失败整个事务无需回滚
//1.自己catch调异常
// TODO 还可以异常出现以后不会回滚
try {
R info = productFeignService.info(skuId);
if (info.getCode() == 0) {
Map data = (Map) info.get("skuInfo");
skuEntity.setSkuName((String) data.get("skuName"));
}
} catch (Exception e) {
}
wareSkuDao.insert(skuEntity);
} else {
wareSkuDao.addStock(skuId, wareId, skuNum);
}
}
点击不显示的,修改前端页面:src --->index.js
添加:
{path: '/product-attrupdate', component: _import('modules/product/attrupdate'), name: 'attr-update', meta: {title: '规格维护', isTab: true}}
@GetMapping("/base/listforspu/{spuId}")
public R baseAttrListForSpu(@PathVariable("spuId") Long spuId) {
List entities = productAttrValueService.baseAttrListForSpu(spuId);
return R.ok().put("data", entities);
}
@Override
public List baseAttrListForSpu(Long spuId) {
List entities = this.baseMapper.selectList(new QueryWrapper().eq("spu_id", spuId));
return entities;
}
@PostMapping("/update/{spuId}")
public R updateSpuAttr(@PathVariable("spuId") Long spuId,@RequestBody List entities){
productAttrValueService.updateSpuAttr(spuId,entities);
return R.ok();
}
@Transactional
@Override
public void updateSpuAttr(Long spuId, List entities) {
//1.删除spuId之前对应的所有属性
this.baseMapper.delete(new QueryWrapper().eq("spu_id",spuId));
List collect = entities.stream().map(item -> {
item.setSpuId(spuId);
return item;
}).collect(Collectors.toList());
this.saveBatch(collect);
}