网站改版提案,武清网站建设公司,互联网挣钱好项目,企业网站做的漂亮目录
#x1f9c2;1.发布商品
#x1f953;2.获取分类关联品牌
#x1f32d;3.获取分类下所有分组和关联属性
#x1f37f;4.商品保存功能
#x1f9c8;5.sup检索
#x1f95e;6.sku检索 1.发布商品
获取用户系统等级~#xff0c;前面生成了后端代码#xff…
目录
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) {ListBrandEntity vos categoryBrandRelationService.getBrandByCatId(catId);ListObject 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 ListBrandEntity getBrandsByCatId(Long catId) {ListCategoryBrandRelationEntity catelogId relationDao.selectList(new QueryWrapperCategoryBrandRelationEntity().eq(catelog_id, catId));ListBrandEntity 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.查出每个属性分组的所有属性ListAtttrGroupWithAttrsVo vos attrGroupService.getAttrGroupWithAttrsByCatelogId(catelog_id);return R.ok().put(data,vos);}2.service 如果前端爆foreach异常但后端数据正常检查一下属性分组里面必须保证每一个组名至少关联一个属性名否则为null后端需要判断 Overridepublic ListAtttrGroupWithAttrsVo getAttrGroupWithAttrsByCatelogId(Long catelogId) {//com.atguigu.gulimall.product.vo//1、查询分组信息ListAttrGroupEntity attrGroupEntities this.list(new QueryWrapperAttrGroupEntity().eq(catelog_id, catelogId));//2、查询所有属性ListAtttrGroupWithAttrsVo collect attrGroupEntities.stream().map(group - {AtttrGroupWithAttrsVo attrsVo new AtttrGroupWithAttrsVo();BeanUtils.copyProperties(group, attrsVo);ListAttrEntity 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要调用服务的名称与具体的请求地址 TransactionalOverridepublic 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的描述图片ListString decript vo.getDecript();SpuInfoDescEntity descEntity new SpuInfoDescEntity();descEntity.setSpuId(infoEntity.getId());descEntity.setDecript(String.join(,, decript));spuInfoDescService.saveSpuInfoDesc(descEntity);//3.保存spu的图片集ListString images vo.getImages();imagesService.saveImages(infoEntity.getId(), images);//4.保存sup的规格参数ListBaseAttrs baseAttrs vo.getBaseAttrs();ListProductAttrValueEntity 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的基本信息ListSkus 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();ListSkuImagesEntity 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);ListAttr attr item.getAttr();ListSkuSaleAttrValueEntity 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 MapString, Object params){PageUtils page spuInfoService.queryPageByCondition(params);return R.ok().put(page, page);}
2.service service用PageUtils封装模糊查询拼接 Overridepublic PageUtils queryPageByCondition(MapString, Object params) {QueryWrapperSpuInfoEntity 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);}IPageSpuInfoEntity page this.page(new QuerySpuInfoEntity().getPage(params),wrapper);return new PageUtils(page);}
6.sku检索 1.controller
RequestMapping(/list)//RequiresPermissions(product:skuinfo:list)public R list(RequestParam MapString, Object params){PageUtils page skuInfoService.queryPageByCondition(params);return R.ok().put(page, page);}
2.service Overridepublic PageUtils queryPageByCondition(MapString, Object params) {QueryWrapperSpuInfoEntity 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);}IPageSpuInfoEntity page this.page(new QuerySpuInfoEntity().getPage(params),wrapper);return new PageUtils(page);}