• 谷粒商城 (二十七) --------- 商品服务 API 商品管理



    一、spu 检索

    SpuInfoController 中修改 list 接口:

    在这里插入图片描述
    queryPageByCondition 方法实现:

    @Override
    public PageUtils queryPageByCondition(Map<String, Object> params) {
    
    
        QueryWrapper<SpuInfoEntity> wrapper = new QueryWrapper<>();
    
        String key = (String) params.get("key");
        if(!StringUtils.isEmpty(key)){
            wrapper.and((w)->{
                w.eq("id",key).or().like("spu_name",key);
            });
        }
        // status=1 and (id=1 or spu_name like xxx)
        String status = (String) params.get("status");
        if(!StringUtils.isEmpty(status)){
            wrapper.eq("publish_status",status);
        }
    
        String brandId = (String) params.get("brandId");
        if(!StringUtils.isEmpty(brandId)&&!"0".equalsIgnoreCase(brandId)){
            wrapper.eq("brand_id",brandId);
        }
    
        String catelogId = (String) params.get("catelogId");
        if(!StringUtils.isEmpty(catelogId)&&!"0".equalsIgnoreCase(catelogId)){
            wrapper.eq("catalog_id",catelogId);
        }
    
        /**
         * status: 2
         * key:
         * brandId: 9
         * catelogId: 225
         */
    
        IPage<SpuInfoEntity> page = this.page(
                new Query<SpuInfoEntity>().getPage(params),
                wrapper
        );
    
        return new PageUtils(page);
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42

    让日期以年月日的格式显示,可以在这里配置日期的格式化
    在这里插入图片描述

    二、sku 检索

    同样的 SkuInfoController 中:

    在这里插入图片描述
    SkuInfoServiceImpl 实现 queryPageCondition 方法

    @Override
    public PageUtils queryPageCondition(Map<String, Object> params) {
        QueryWrapper<SkuInfoEntity> queryWrapper = new QueryWrapper<>();
        /**
         * key:
         * catelogId: 0
         * brandId: 0
         * min: 0
         * max: 0
         */
        String key = (String) params.get("key");
        if(!StringUtils.isEmpty(key)){
            queryWrapper.and((wrapper)->{
                wrapper.eq("sku_id",key).or().like("sku_name",key);
            });
        }
    
        String catelogId = (String) params.get("catelogId");
        if(!StringUtils.isEmpty(catelogId)&&!"0".equalsIgnoreCase(catelogId)){
    
            queryWrapper.eq("catalog_id",catelogId);
        }
    
        String brandId = (String) params.get("brandId");
        if(!StringUtils.isEmpty(brandId)&&!"0".equalsIgnoreCase(catelogId)){
            queryWrapper.eq("brand_id",brandId);
        }
    
        String min = (String) params.get("min");
        if(!StringUtils.isEmpty(min)){
            queryWrapper.ge("price",min);
        }
    
        String max = (String) params.get("max");
    
        if(!StringUtils.isEmpty(max)  ){
            try{
                BigDecimal bigDecimal = new BigDecimal(max);
    
                if(bigDecimal.compareTo(new BigDecimal("0"))==1){
                    queryWrapper.le("price",max);
                }
            }catch (Exception e){
    
            }
    
        }
        IPage<SkuInfoEntity> page = this.page(
                new Query<SkuInfoEntity>().getPage(params),
                queryWrapper
        );
    
        return new PageUtils(page);
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54

    三、获取 spu 规格

    AttrController 中:

    在这里插入图片描述

    ProductAttrValueServiceImpl 中实现方法 baseAttrlistforspu

    @Override
    public List<ProductAttrValueEntity> baseAttrlistforspu(Long spuId) {
        List<ProductAttrValueEntity> entities = this.baseMapper.selectList(new QueryWrapper<ProductAttrValueEntity>().eq("spu_id", spuId));
        return entities;
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5

    四、修改商品规格

    AttrController 中:

    在这里插入图片描述

    ProductAttrValueService 中 updateSpuAttr 方法实现

     @Transactional
     @Override
     public 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);
     }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13

    这里实现的是批量修改。。。。

  • 相关阅读:
    Betaflight关于STM32F405 SBUS协议兼容硬件电气特性问题
    SpringMVC
    从入门到精通,mac电脑录屏软件使用教程!
    量子笔记:量子纠缠祛魅,贝尔纠缠态
    免费采集器-网页数据采集器
    流量控制&可靠传输机制&停止-等待协议
    Android 11.0 无源码apk授予QUERY_ALL_PACKAGES权限
    Linux下安装配置各种软件和服务
    【C++历险记】国庆专辑---探索多态迷宫的代码之旅!
    ant使用import导入另外一个build文件到当前项目中
  • 原文地址:https://blog.csdn.net/m0_51111980/article/details/126790545