目录
🧈1.仓库维护
🍟🍟1.1配置网关陆游规则
🍟🍟1.2修改模糊查询
🥞2.仓库库存
🍿3.采购需需求
🍟🍟3.1采购的模糊检索
🍟🍟3.2合并采购单
🍟🍟3.3领取采购单
🍟🍟3.4完成采购
🌭4.spu规格
🍟🍟4.1 获取spu规格
🍟🍟4.2更新spu规格
1.仓库维护
开打界面查看发送的请求路径,因为我们配置类网关,所以目前报错
- 将库存服务启动,注册到nacos服务中心
1.1配置网关陆游规则
配置完网关之后,我们再次刷新页面,就可以查询到结果,包括新增,修改和删除共功能,以为之前逆向工程已经生成好后端接口
1.2修改模糊查询
点击查询,发送请求,根据请求路径找到相应的controller,并对相应的service方法添加模糊查询
1.controller
@RequestMapping("/list")//@RequiresPermissions("ware:wareinfo:list")public R list(@RequestParam Map<String, Object> params){PageUtils page = wareInfoService.queryPage(params);return R.ok().put("page", page);}
2.service
@Overridepublic PageUtils queryPage(Map<String, Object> params) {QueryWrapper<WareInfoEntity> 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<WareInfoEntity> page = this.page(new Query<WareInfoEntity>().getPage(params),wrapper);return new PageUtils(page);}
3.添加日志,并查看sql语句
2.仓库库存
在service上拼接条件,添加两个模糊查询
@Overridepublic PageUtils queryPage(Map<String, Object> params) {QueryWrapper<WareSkuEntity> 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<WareSkuEntity> page = this.page(new Query<WareSkuEntity>().getPage(params),wrapper);return new PageUtils(page);}
3.采购需需求
3.1采购的模糊检索
1.controller
@RequestMapping("/list")//@RequiresPermissions("ware:purchasedetail:list")public R list(@RequestParam Map<String, Object> params){PageUtils page = purchaseDetailService.queryPage(params);return R.ok().put("page", page);}
2.service
@Overridepublic PageUtils queryPage(Map<String, Object> params) {QueryWrapper<PurchaseDetailEntity> 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<PurchaseDetailEntity> page = this.page(new Query<PurchaseDetailEntity>().getPage(params),wrapper);return new PageUtils(page);}
3.2合并采购单
1.controller
@PostMapping("/merge")public R merge(@RequestBody MergeVo mergeVo) {purchaseService.mergePurchase(mergeVo);return R.ok();}
2.service
@Transactional@Overridepublic 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<Long> items = mergeVo.getItems();Long finalPurchaseId = purchaseId;List<PurchaseDetailEntity> 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);}
3.3领取采购单
使用postman发送采购请求
1.controller
@PostMapping("/received")public R received(@RequestBody List<Long> ids){purchaseService.received(ids);return R.ok();}
2.service
@Overridepublic 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.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<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);});}
3.4完成采购
1.controller
@PostMapping("/done")public R finish(@RequestBody PurchaseDoneVo doneVo) {purchaseService.done(doneVo);return R.ok();}
2.service
@Overridepublic void addStock(Long skuId, Long wareId, Integer skuNum) {//1.判断如果还没有库存记录。那就是新增操作,如果有,才更新List<WareSkuEntity> entities = wareSkuDao.selectList(new QueryWrapper<WareSkuEntity>().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<String, Object> data = (Map<String, Object>) info.get("skuInfo");skuEntity.setSkuName((String) data.get("skuName"));}} catch (Exception e) {}wareSkuDao.insert(skuEntity);} else {wareSkuDao.addStock(skuId, wareId, skuNum);}}
4.spu规格
点击不显示的,修改前端页面:src --->index.js
添加:
{path: '/product-attrupdate', component: _import('modules/product/attrupdate'), name: 'attr-update', meta: {title: '规格维护', isTab: true}}
4.1 获取spu规格
1.controller
@GetMapping("/base/listforspu/{spuId}")public R baseAttrListForSpu(@PathVariable("spuId") Long spuId) {List<ProductAttrValueEntity> entities = productAttrValueService.baseAttrListForSpu(spuId);return R.ok().put("data", entities);}
2.service
@Overridepublic List<ProductAttrValueEntity> baseAttrListForSpu(Long spuId) {List<ProductAttrValueEntity> entities = this.baseMapper.selectList(new QueryWrapper<ProductAttrValueEntity>().eq("spu_id", spuId));return entities;}
4.2更新spu规格
1.controller
@PostMapping("/update/{spuId}")public R updateSpuAttr(@PathVariable("spuId") Long spuId,@RequestBody List<ProductAttrValueEntity> entities){productAttrValueService.updateSpuAttr(spuId,entities);return R.ok();}
2.service
@Transactional@Overridepublic void updateSpuAttr(Long spuId, List<ProductAttrValueEntity> entities) {//1.删除spuId之前对应的所有属性this.baseMapper.delete(new QueryWrapper<ProductAttrValueEntity>().eq("spu_id",spuId));List<ProductAttrValueEntity> collect = entities.stream().map(item -> {item.setSpuId(spuId);return item;}).collect(Collectors.toList());this.saveBatch(collect);}