0
点赞
收藏
分享

微信扫一扫

K8S存储之Secret

钟罗敏 2023-06-25 阅读 28

电商项目10:商品管理、仓库管理

1、商品管理

1.1、spu检索

1.1.1、后端

spu检索接口文档
在这里插入图片描述

SpuInfoController

/**
     * 列表
     */
    @RequestMapping("/list")
    // @RequiresPermissions("product:spuinfo:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = spuInfoService.queryPageCondition(params);

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

SpuInfoService

PageUtils queryPageCondition(Map<String, Object> params);

SpuInfoServiceImpl

 @Override
    public PageUtils queryPageCondition(Map<String, Object> params) {
        QueryWrapper<SpuInfoEntity> wrapper = new QueryWrapper<>();
        // 关键字检索
        Object key = params.get("key");
        // 三级分类id
        Object catalogId = params.get("catalogId");
        // 品牌id
        Object brandId = params.get("brandId");
        // 状态 0-新建 1-上架 2-下架
        Object status = params.get("status");
        if (!StringUtils.isEmpty(key)){
            wrapper.and((w) -> {
                w.eq("id",key).or().like("spu_name",key);
            });
        }
        if (!StringUtils.isEmpty(catalogId)){
            wrapper.eq("catalog_id",catalogId);
        }
        if (!StringUtils.isEmpty(brandId)){
            wrapper.eq("brand_id",brandId);
        }
        if (!StringUtils.isEmpty(status)){
            wrapper.eq("publish_status",status);
        }

        IPage<SpuInfoEntity> page = this.page(
                new Query<SpuInfoEntity>().getPage(params),
                wrapper
        );

        return new PageUtils(page);
    }

查询时创建时间不是年月日时分秒类型。可以在全局配置文件中配置:

  jackson:
    date-format: yyyy-MM-dd HH:mm:ss

后端代码修改:
SpuInfoServiceImpl

 if (!StringUtils.isEmpty(catalogId) && !"0".equals(catalogId)){
            wrapper.eq("catalog_id",catalogId);
        }
        if (!StringUtils.isEmpty(brandId) && !"0".equals(brandId)){
            wrapper.eq("brand_id",brandId);
        }

1.1.2、前端

前端调用时出现第一次进入页面。搜索时输入框条件未置空,且为0.是因为业务规则,传0就查全部。后端需要改代码。
在这里插入图片描述

1.2、sku检索

1.2.1、后端

sku检索
在这里插入图片描述
SkuInfoController

   /**
     * 列表
     */
    @RequestMapping("/list")
    // @RequiresPermissions("product:skuinfo:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = skuInfoService.queryPageByCondition(params);

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

SkuInfoService

PageUtils queryPageByCondition(Map<String, Object> params);

SkuInfoServiceImpl

 @Override
    public PageUtils queryPageByCondition(Map<String, Object> params) {
        QueryWrapper<SkuInfoEntity> wrapper = new QueryWrapper<>();
        Object key = params.get("key");
        Object catelogId = params.get("catelogId");
        Object brandId = params.get("brandId");
        Object min = params.get("min");
        Object max = params.get("max");
        if (!StringUtils.isEmpty(key)){
            wrapper.and((w) -> {
                w.eq("sku_id",key).or().like("sku_name",key);
            });
        }
        if (!StringUtils.isEmpty(catelogId) && !"0".equals(catelogId)){
            wrapper.eq("catalog_id",catelogId);
        }
        if (!StringUtils.isEmpty(brandId) && !"0".equals(brandId)){
            wrapper.eq("brand_id",brandId);
        }
        if (!StringUtils.isEmpty(min)){
            wrapper.ge("price",min);
        }
        if (!StringUtils.isEmpty(max)){
            BigDecimal bigDecimal = new BigDecimal((String) max);
            if (bigDecimal.compareTo(new BigDecimal("0")) > 0){
                // 当价格区间的最大值大于0才去拼接
                wrapper.le("price",max);
            }
        }
        IPage<SkuInfoEntity> page = this.page(
                new Query<SkuInfoEntity>().getPage(params),
                wrapper
        );

        return new PageUtils(page);
    }

2、库存管理

2.1、启动ware后端微服务

application.yml

  application:
    name: gulimall-ware

GulimallWareApplication

@SpringBootApplication
@EnableDiscoveryClient
@EnableTransactionManagement
@MapperScan("com.ljs.gulimall.ware.dao")
public class GulimallWareApplication {

    public static void main(String[] args) {
        SpringApplication.run(GulimallWareApplication.class, args);
    }

}

启动ware服务。登录nacos

在这里插入图片描述
代表已经注册成功

gulimall-gateway配置路由规则

application.yml

   - id: ware_route
            #负载均衡到member服务
     uri: lb://gulimall-ware
     predicates:
        - Path=/api/ware/**
              #网关重写
     filters:
        - RewritePath=/api/(?<segment>.*),/$\{segment}

在这里插入图片描述

2.2、仓库维护查询

仓库列表
WareInfoServiceImpl

@Override
    public PageUtils queryPage(Map<String, Object> params) {
        QueryWrapper<WareInfoEntity> wrapper = new QueryWrapper<>();
        Object key = params.get("key");
        if (!StringUtils.isEmpty(key)){
            wrapper.eq("id", key).or().like("name",key).or().
                    like("address",key).or().like("areacode",key);
        }
        IPage<WareInfoEntity> page = this.page(
                new Query<WareInfoEntity>().getPage(params),
                wrapper
        );

        return new PageUtils(page);
    }

2.3、查询商品库存

查询商品库存
WareSkuServiceImpl

 @Override
    public PageUtils queryPage(Map<String, Object> params) {
        QueryWrapper<WareSkuEntity> wrapper = new QueryWrapper<>();
        Object skuId = params.get("skuId");
        if (!StringUtils.isEmpty(skuId)){
            wrapper.eq("sku_id",skuId);
        }
        Object wareId = 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);
    }

2.4、查询采购需求

查询采购需求

PurchaseDetailServiceImpl

 @Override
 public PageUtils queryPage(Map<String, Object> params) {
        QueryWrapper<PurchaseDetailEntity> wrapper = new QueryWrapper<>();
        Object key = params.get("key");
        if (!StringUtils.isEmpty(key)){
            wrapper.and((w) -> {
               w.eq("id",key).or().eq("sku_id",key).or().eq("sku_num",key);
            });
        }
        Object status = params.get("status");
        if (!StringUtils.isEmpty(status)){
            wrapper.eq("status",status);
        }
        Object wareId = 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);
    }
举报

相关推荐

0 条评论