谷粒商城【成神路】-【7】——库存系统

目录

1.仓库维护 

1.1配置网关陆游规则

1.2修改模糊查询  

2.仓库库存

3.采购需需求 

3.1采购的模糊检索 

3.2合并采购单 

3.3领取采购单 

3.4完成采购 

 4.spu规格

4.1 获取spu规格 

4.2更新spu规格


1.仓库维护 

开打界面查看发送的请求路径,因为我们配置类网关,所以目前报错

谷粒商城【成神路】-【7】——库存系统_第1张图片

  • 将库存服务启动,注册到nacos服务中心 

1.1配置网关陆游规则

谷粒商城【成神路】-【7】——库存系统_第2张图片

配置完网关之后,我们再次刷新页面,就可以查询到结果,包括新增,修改和删除共功能,以为之前逆向工程已经生成好后端接口 

谷粒商城【成神路】-【7】——库存系统_第3张图片

1.2修改模糊查询 

点击查询,发送请求,根据请求路径找到相应的controller,并对相应的service方法添加模糊查询

谷粒商城【成神路】-【7】——库存系统_第4张图片

1.controller

   @RequestMapping("/list")
    //@RequiresPermissions("ware:wareinfo:list")
    public R list(@RequestParam Map params){
        PageUtils page = wareInfoService.queryPage(params);

        return R.ok().put("page", page);
    }

2.service 

@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);
    }

3.添加日志,并查看sql语句 

谷粒商城【成神路】-【7】——库存系统_第5张图片

谷粒商城【成神路】-【7】——库存系统_第6张图片

2.仓库库存

谷粒商城【成神路】-【7】——库存系统_第7张图片

在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);
    }

3.采购需需求 

谷粒商城【成神路】-【7】——库存系统_第8张图片

3.1采购的模糊检索 

谷粒商城【成神路】-【7】——库存系统_第9张图片

1.controller

@RequestMapping("/list")
    //@RequiresPermissions("ware:purchasedetail:list")
    public R list(@RequestParam Map params){
        PageUtils page = purchaseDetailService.queryPage(params);

        return R.ok().put("page", page);
    }

2.service

@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);
    }

3.2合并采购单 

1.controller

 @PostMapping("/merge")
    public R merge(@RequestBody MergeVo mergeVo) {

        purchaseService.mergePurchase(mergeVo);
        return R.ok();
    }

2.service

    @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);
    }

3.3领取采购单 

使用postman发送采购请求

谷粒商城【成神路】-【7】——库存系统_第10张图片

谷粒商城【成神路】-【7】——库存系统_第11张图片 

1.controller

@PostMapping("/received")
    public R  received(@RequestBody List ids){
        purchaseService.received(ids);
        return R.ok();
    }

2.service

 @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);
        });
    }

3.4完成采购 

1.controller

@PostMapping("/done")
    public R finish(@RequestBody PurchaseDoneVo doneVo) {
        purchaseService.done(doneVo);
        return R.ok();
    }

2.service

    @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);
        }
    }

 4.spu规格

谷粒商城【成神路】-【7】——库存系统_第12张图片

点击不显示的,修改前端页面:src --->index.js

添加:

{path: '/product-attrupdate', component: _import('modules/product/attrupdate'), name: 'attr-update', meta: {title: '规格维护', isTab: true}}

谷粒商城【成神路】-【7】——库存系统_第13张图片 

4.1 获取spu规格 

1.controller


    @GetMapping("/base/listforspu/{spuId}")
    public R baseAttrListForSpu(@PathVariable("spuId") Long spuId) {
        List entities = productAttrValueService.baseAttrListForSpu(spuId);
        return R.ok().put("data", entities);
    }

2.service

@Override
    public List baseAttrListForSpu(Long spuId) {
        List entities = this.baseMapper.selectList(new QueryWrapper().eq("spu_id", spuId));
        return entities;
    }

4.2更新spu规格

1.controller

  @PostMapping("/update/{spuId}")
    public R updateSpuAttr(@PathVariable("spuId") Long spuId,@RequestBody List entities){
        productAttrValueService.updateSpuAttr(spuId,entities);
        return R.ok();
    }

2.service

@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);
    }

谷粒商城【成神路】-【7】——库存系统_第14张图片谷粒商城【成神路】-【7】——库存系统_第15张图片

你可能感兴趣的:(谷粒商城【弑神战】,java,graphql,spring,cloud,后端,分布式,spring,boot,架构)