谷粒商城【成神路】-【6】——商品维护

目录

🧂1.发布商品

🥓2.获取分类关联品牌 

🌭3.获取分类下所有分组和关联属性 

🍿4.商品保存功能

🧈5.sup检索 

🥞6.sku检索


1.发布商品

获取用户系统等级~,前面生成了后端代码,在因为添加了网关,所以要配置陆游规则

在网管层配置会员服务的路由规则,精确的路由放到上面

        #会员服务- id: member_routeuri: lb://gulimall-memberpredicates:- Path=/api/member/**filters:- RewritePath=/api/(?<segment>.*),/$\{segment}

 配置会员服务的配置

1.添加nacos的注册中心地址

2.添加nacos的配置中心地址

3.将配置文件写在bootstrap.yml中

spring:#数据源datasource:driver-class-name: com.mysql.cj.jdbc.Driverurl: jdbc:mysql://192.168.20.129:3306/gulimall_umsusername: rootpassword: rootcloud:nacos:discovery:# 这里使用了Ngingxserver-addr: 192.168.20.50:1111config:server-addr: 192.168.20.50:1111application:name: gulimall-member

2.获取分类关联品牌 

2.1controller

controller处理请求,接收和校验数据,接收service处理完的数据,封装页面指定的vo

  @GetMapping("/brands/list")public R relationBrandList(@RequestParam(value = "catId", required = true) Long catId) {List<BrandEntity> vos = categoryBrandRelationService.getBrandByCatId(catId);List<Object> collect = vos.stream().map((item) -> {BrandVo brandVo = new BrandVo();brandVo.setBrandId(item.getBrandId());brandVo.setBrandName(item.getName());return brandVo;}).collect(Collectors.toList());return R.ok().put("data",collect);}

2.2service

service来接收controller传来的数据,进行业务处理

@Overridepublic List<BrandEntity> getBrandsByCatId(Long catId) {List<CategoryBrandRelationEntity> catelogId = relationDao.selectList(new QueryWrapper<CategoryBrandRelationEntity>().eq("catelog_id", catId));List<BrandEntity> collect = catelogId.stream().map(item -> {Long brandId = item.getBrandId();BrandEntity byId = brandService.getById(brandId);return byId;}).collect(Collectors.toList());return collect;}

 

3.获取分类下所有分组和关联属性 

1.controller

/*** 获取当前分类下的所有属性分组** @return*/@GetMapping("/{catelog_id}/withattr")public R getAttrGroupWithAttrs(@PathVariable("catelog_id") Long catelog_id) {//1.查出当前分类下的所有属性分组//2.查出每个属性分组的所有属性List<AtttrGroupWithAttrsVo> vos = attrGroupService.getAttrGroupWithAttrsByCatelogId(catelog_id);return R.ok().put("data",vos);}

2.service

如果前端爆foreach异常,但后端数据正常,检查一下属性分组里面,必须保证每一个组名至少关联一个属性名,否则为null,后端需要判断

 @Overridepublic List<AtttrGroupWithAttrsVo> getAttrGroupWithAttrsByCatelogId(Long catelogId) {//com.atguigu.gulimall.product.vo//1、查询分组信息List<AttrGroupEntity> attrGroupEntities = this.list(new QueryWrapper<AttrGroupEntity>().eq("catelog_id", catelogId));//2、查询所有属性List<AtttrGroupWithAttrsVo> collect = attrGroupEntities.stream().map(group -> {AtttrGroupWithAttrsVo attrsVo = new AtttrGroupWithAttrsVo();BeanUtils.copyProperties(group, attrsVo);List<AttrEntity> attrs = attrService.geRelationAttr(attrsVo.getAttrGroupId());attrsVo.setAttrs(attrs);return attrsVo;}).collect(Collectors.toList());return collect;}

4.商品保存功能

1.controller

 @RequestMapping("/save")//@RequiresPermissions("product:spuinfo:save")public R save(@RequestBody SpuSaveVo vo){
//		spuInfoService.save(spuInfo);spuInfoService.saveSpuInfo(vo);return R.ok();}

2.service 

service使用feign调用远程服务,注意feign要调用服务的名称,与具体的请求地址

 

 @Transactional@Overridepublic void saveSpuInfo(SpuSaveVo vo) {//1.保存spu基本信息SpuInfoEntity infoEntity = new SpuInfoEntity();BeanUtils.copyProperties(vo, infoEntity);infoEntity.setCreateTime(new Date());infoEntity.setUpdateTime(new Date());this.saveBaseSpuInfo(infoEntity);//2.保存spu的描述图片List<String> decript = vo.getDecript();SpuInfoDescEntity descEntity = new SpuInfoDescEntity();descEntity.setSpuId(infoEntity.getId());descEntity.setDecript(String.join(",", decript));spuInfoDescService.saveSpuInfoDesc(descEntity);//3.保存spu的图片集List<String> images = vo.getImages();imagesService.saveImages(infoEntity.getId(), images);//4.保存sup的规格参数List<BaseAttrs> baseAttrs = vo.getBaseAttrs();List<ProductAttrValueEntity> collect = baseAttrs.stream().map((attr) -> {ProductAttrValueEntity valueEntity = new ProductAttrValueEntity();valueEntity.setAttrId(attr.getAttrId());AttrEntity id = attrService.getById(attr.getAttrId());valueEntity.setAttrName(id.getAttrName());valueEntity.setAttrValue(attr.getAttrValues());valueEntity.setQuickShow(attr.getShowDesc());valueEntity.setSpuId(infoEntity.getId());return valueEntity;}).collect(Collectors.toList());attrValueService.saveProductAttr(collect);//5.保存spu的积分信息Bounds bounds = vo.getBounds();SpuBoundTo spuBoundTo = new SpuBoundTo();BeanUtils.copyProperties(bounds, spuBoundTo);spuBoundTo.setSpuId(infoEntity.getId());R r = couponFeignService.saveSpuBounds(spuBoundTo);if (r.getCode() != 0) {log.error("远程保存spu积分信息失败");}//5.保存当前spu对应的sku信息//5.1、保存sku的基本信息List<Skus> skus = vo.getSkus();if (skus != null && skus.size() > 0) {skus.forEach(item -> {String defaultImg = "";for (Images image : item.getImages()) {if (image.getDefaultImg() == 1) {defaultImg = image.getImgUrl();}SkuInfoEntity skuInfoEntity = new SkuInfoEntity();BeanUtils.copyProperties(item, skuInfoEntity);skuInfoEntity.setBrandId(infoEntity.getBrandId());skuInfoEntity.setCatalogId(infoEntity.getCatalogId());skuInfoEntity.setSaleCount(0L);skuInfoEntity.setSpuId(infoEntity.getId());skuInfoEntity.setSkuDefaultImg(defaultImg);skuInfoService.saveSkuInfo(skuInfoEntity);Long skuId = skuInfoEntity.getSkuId();List<SkuImagesEntity> imagesEntities = item.getImages().stream().map((img) -> {SkuImagesEntity skuImagesEntity = new SkuImagesEntity();skuImagesEntity.setSkuId(skuId);skuImagesEntity.setImgUrl(img.getImgUrl());skuImagesEntity.setDefaultImg(img.getDefaultImg());return skuImagesEntity;}).filter(entity -> {//返回true就是需要,false就是剔除return !StringUtils.isEmpty(entity.getImgUrl());}).collect(Collectors.toList());//5.2、sku的图片信息// TODO 没有图片路径的无需保存skuImagesService.saveBatch(imagesEntities);List<Attr> attr = item.getAttr();List<SkuSaleAttrValueEntity> saleAttrValueEntityList = attr.stream().map(a -> {SkuSaleAttrValueEntity attrValueEntity = new SkuSaleAttrValueEntity();BeanUtils.copyProperties(a, attrValueEntity);attrValueEntity.setSkuId(skuId);return attrValueEntity;}).collect(Collectors.toList());//5.3、sku的销售属性skuSaleAttrValueService.saveBatch(saleAttrValueEntityList);// 5.4、sku的优惠满减信息SkuReductionTo skuReductionTo = new SkuReductionTo();BeanUtils.copyProperties(item, skuReductionTo);skuReductionTo.setSkuId(skuId);if (skuReductionTo.getFullCount() > 0 || skuReductionTo.getFullPrice().compareTo(new BigDecimal("0"))==1) {R r1 = couponFeignService.saveSkuReduction(skuReductionTo);if (r1.getCode() != 0) {log.error("远程保存spu积分优惠失败");}}}});}}

5.sup检索 

 

1.controller

@RequestMapping("/list")//@RequiresPermissions("product:spuinfo:list")public R list(@RequestParam Map<String, Object> params){PageUtils page = spuInfoService.queryPageByCondition(params);return R.ok().put("page", page);}

2.service 

  service用PageUtils封装模糊查询拼接

@Overridepublic PageUtils queryPageByCondition(Map<String, Object> params) {QueryWrapper<SpuInfoEntity> wrapper = new QueryWrapper<>();String key = (String) params.get("key");if (!StringUtils.isEmpty(params.get(key))) {wrapper.and((w) -> {w.eq("id", key).or().like("spu_name", key);});}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)) {wrapper.eq("brand_id", brandId);}String catelogId = (String) params.get("catelogId");if (!StringUtils.isEmpty(catelogId)) {wrapper.eq("catalog_id", catelogId);}IPage<SpuInfoEntity> page = this.page(new Query<SpuInfoEntity>().getPage(params),wrapper);return new PageUtils(page);}

6.sku检索

1.controller

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

2.service

 @Overridepublic 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);});}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);}IPage<SpuInfoEntity> page = this.page(new Query<SpuInfoEntity>().getPage(params),wrapper);return new PageUtils(page);}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/682006.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Rust的if let语法:更简洁的模式匹配

在Rust中&#xff0c;if let是一种简洁的模式匹配语法&#xff0c;用于处理只关心一种匹配而忽略其他匹配的情况。这种语法不仅使代码更精炼&#xff0c;减少了缩进和模板代码&#xff0c;还放弃了穷举所有可能的情况&#xff0c;使得代码更加简洁易读。 if let语法的基本使用…

寒假思维训练day21

今天更新一道不错的状态压缩DP题&#xff0c;顺带总结一下状态压缩DP。 摘要&#xff1a; Part1 浅谈状态压缩DP的理解 Part2 浅谈对状态机DP的理解 Part3 关于状态压缩DP的1道例题 Part1 状态压缩DP 1、状态压缩DP&#xff1a; 事物的状态可能包含多个特征&#xff0c;…

算法基础——单调栈,单调队列

目录 1.单调栈 例题&#xff1a;【模板】单调栈 例题:求和 2.单调队列 例题&#xff1a;滑动窗口 1.单调栈 例题&#xff1a;【模板】单调栈 可以想象出一个柱状图&#xff0c;值越大&#xff0c;这个柱子越高 以此题的样例为例&#xff1a; 第一个数为7&#xff0c;想…

mysql全国省市县三级联动创表sql(一)

1. 建表sql CREATE TABLE province (id VARCHAR ( 32 ) PRIMARY KEY COMMENT 主键,code CHAR ( 6 ) NOT NULL COMMENT 省份编码,name VARCHAR ( 40 ) NOT NULL COMMENT 省份名称 ) COMMENT 省份信息表;CREATE TABLE city (id VARCHAR ( 32 ) PRIMARY KEY COMMENT 主键,code …

Atmel ATSHA204应用总结

1 ACES软件安装 Atmel Crypto Evaluation Studio (ACES) https://www.microchip.com/DevelopmentTools/ProductDetails/PartNO/Atmel%20Crypto%20%20Studio%20(ACES) 2 基本概念 ACES CE&#xff1a;Atmel Crypto Evalution Studio Configuration Environment&#xff08;基于加…

[Python] 如何用import导入模块

本篇博客来记以下关于import导入模块的笔记~ 可莉将这篇博客收录在了&#xff1a;《Python》 可莉推荐的优质博主主页&#xff1a;Kevin ’ s blog 我们在Python中可以使用import从标准库中导入一天模块&#xff0c;模块相当于是一个 .py 文件&#xff0c;我们导入后调用相当于…

Linux Chrome无法启动的原因(适用于Linux Edge)

文章目录 前言问题发现解决方案推广到Edge 前言 被Windows给贯坏了&#xff0c;因为Windows重启之后能够始终加载上一次没能关闭的页面&#xff0c;这就让我使用这种方法保存当前不想关、收藏了也容易忘的页面。结果这种操作直接导致Linux上的chrome就直接启动不了。记录一下解…

crack实验

资源下载 【免费】crack资源&#xff08;这玩意还要不少于11字&#xff09;资源-CSDN文库 内容 源码 这是一段简单的密码判断程序 流程 exe直接用ida开&#xff08;因该是release的exe&#xff09; 选中分支点直接按空格 此时的va地址是0010106e用动态调试软件调试&#xf…

tar 磁带归档工具

tar.gz 或者 tgz 文件的创建 1.先使用libtar 完成归档 2.在使用zlib gzip 压缩tar.gz 或者 tgz 文件的解压缩 1.先使用zlib gzip 解压缩 2.在使用libtar 解归档比较容易实现的方式

轻松入门MySQL:利用MySQL时间函数优化产品销售数据统计与分析(9)

在产品销售数据的统计与分析过程中&#xff0c;MySQL的时间函数是不可或缺的工具。这些函数能够帮助我们轻松处理各类时间需求&#xff0c;从而更有效地了解销售情况、评估业绩趋势和管理库存。本文将深入讨论不同类型的时间函数及其在产品销售数据分析中的应用&#xff0c;并结…

windows10|音视频剪辑|FFMPEG录屏和网络推流源初步的生成

前言&#xff1a; FFMPEG的功能强大是毋庸置疑的&#xff0c;那么录屏的需求大家在某些时候大家可能是非常需要的&#xff0c;例如&#xff0c;现有的项目需要演示&#xff0c;因此录制一段演示视频&#xff1b;亦或者做内容分发直播的&#xff0c;比如游戏主播&#xff0c;需…

人力资源智能化管理项目(day07:员工详情)

学习源码可以看我的个人前端学习笔记 (github.com):qdxzw/humanResourceIntelligentManagementProject 页面结构和路由 <template><div class"dashboard-container"><div class"app-container"><div class"edit-form">…

使用python给程序添加授权码,设置授权时间、撤销授权和管理授权

文章目录 引言思路1思路2思路3客户端逻辑注册机逻辑服务器逻辑源码引言 有很多同学在开发程序的同时想要保护自己的源码不被他人窃取,这时候给程序添加授权就显得非常有必要了,下面主要分三块来讲述下如何开发,可以直接嵌入在你的程序中。 思路1 软件授权方案大概分成两个…

【实战】一、Jest 前端自动化测试框架基础入门(三) —— 前端要学的测试课 从Jest入门到TDD BDD双实战(三)

文章目录 一、Jest 前端自动化测试框架基础入门7.异步代码的测试方法8.Jest 中的钩子函数9.钩子函数的作用域 学习内容来源&#xff1a;Jest入门到TDD/BDD双实战_前端要学的测试课 相对原教程&#xff0c;我在学习开始时&#xff08;2023.08&#xff09;采用的是当前最新版本&a…

python 通过ssh增量同步文件夹

要通过 SSH 使用 Python 进行文件夹的增量同步&#xff0c;你可以使用 paramiko 库来创建 SSH 连接并执行文件传输操作。paramiko 是一个 Python 实现的 SSHv2 协议库&#xff0c;可以用于进行 SSH 连接、文件传输等任务。 以下是一个简单的示例&#xff0c;展示如何使用 para…

ES实战-高级聚合

多桶型聚合 1.词条聚合–terms 2.范围聚合–range 3,直方图聚合–histogram 4.嵌套聚合 5.地理距离聚合 include(包含)exclude(不包含) GET /get-together/_search?pretty {"size": 0,"aggs": {"tags": {"terms": {"field"…

【教3妹学编程-算法题】捕获黑皇后需要的最少移动次数

3妹&#xff1a;2哥&#xff0c;新年好鸭~ 2哥 : 新年好&#xff0c;3妹这么早啊 3妹&#xff1a;是啊&#xff0c;新年第一天要起早&#xff0c;这样就可以起早一整年 2哥 :得&#xff0c;我还不了解你&#xff0c;每天晒到日上三竿 3妹&#xff1a;嘿嘿嘿嘿&#xff0c;一年是…

LeetCode、901. 股票价格跨度【中等,单调栈】

文章目录 前言LeetCode、901. 股票价格跨度【中等&#xff0c;单调栈】题目链接及分类思路思路1&#xff1a;暴力思路2&#xff1a;单调栈写法优化&#xff1a;单调栈简化写法(数组替代栈集合) 资料获取 前言 博主介绍&#xff1a;✌目前全网粉丝2W&#xff0c;csdn博客专家、…

别人卖了 2W 的一套 ChatGPT 自动身份提示词!

别人卖了 2W 的一套 ChatGPT 自动身份提示词! 英文版 You are an Expert level ChatGPT Prompt Engineer with expertise in various subject matters. Throughout our interaction, you will refer to me as (your name). Lets collaborate to create the best possible Cha…

深度学习-吴恩达L1W2作业

作业1&#xff1a;吴恩达《深度学习》L1W2作业1 - Heywhale.com 作业2&#xff1a;吴恩达《深度学习》L1W2作业2 - Heywhale.com 作业1 你需要记住的内容&#xff1a; -np.exp&#xff08;x&#xff09;适用于任何np.array x并将指数函数应用于每个坐标 -sigmoid函数及其梯度…