会员等级
将前端的六个模块的代码复制到自己的前端代码中
新增一个会员
查询品牌表中所有信息
CategoryBrandRelationController
/**
* 1.Controller:处理请求,接收和校验数据
* 2.Service接收controller传来的数据,进行业务处理
* 3.controller接收service处理完的数据,封装页面指定的vo
* @param catId
* @return
*/
@GetMapping("/brands/list")
public R relationBrandsList(@RequestParam(value = "catId",required = true)Long catId){
List<BrandEntity> vos = categoryBrandRelationService.getBrandsCatId(catId);
final List<BrandVo> collect = vos.stream().map(item -> {
final BrandVo brandVo = new BrandVo();
brandVo.setBrandId(item.getBrandId());
brandVo.setBrandName(item.getName());
return brandVo;
}).collect(Collectors.toList());
return R.ok().put("data",collect);
}
* 1.Controller:处理请求,接收和校验数据 * 2.Service接收controller传来的数据,进行业务处理 * 3.controller接收service处理完的数据,封装页面指定的vo
CategoryBrandRelationServiceImpl
@Autowired CategoryBrandRelationDao relationDao; @Autowired BrandService brandService;
@Override
public List<BrandEntity> getBrandsCatId(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;
}
效果 选择分类后有相应的品牌可以选择
获取分类下所有属性和分组
@Data
public class AttrGroupWithAttrsVo {
/**
* 分组id
*/
@TableId
private Long attrGroupId;
/**
* 组名
*/
private String attrGroupName;
/**
* 排序
*/
private Integer sort;
/**
* 描述
*/
private String descript;
/**
* 组图标
*/
private String icon;
/**
* 所属分类id
*/
private Long catelogId;
private List<AttrEntity> attrs;
}
AttrGroupController
@GetMapping("/{catelogId}/withattr")
public R getAttrGroupWithAttrs(@PathVariable("catelogId")Long catelogId){
//1.查出当前分类下的所有属性分组
List<AttrGroupWithAttrsVo> vos = attrGroupService.getAttrGroupWithAttrsByCatelogId(catelogId);
//2.查询每个属性分组的所有属性
return R.ok().put("data",vos);
}
AttrGroupServiceImpl
/**
* 根据分类id查出所有的分组以及这些组里面的属性
* @param catelogId
* @return
*/
@Override
public List<AttrGroupWithAttrsVo> getAttrGroupWithAttrsByCatelogId(Long catelogId) {
//查询分组信息
List<AttrGroupEntity> attrGroupEntities = this.list(new QueryWrapper<AttrGroupEntity>().eq("catelog_id", catelogId));
//查询所有属性
final List<AttrGroupWithAttrsVo> collect = attrGroupEntities.stream().map(group -> {
final AttrGroupWithAttrsVo attrsVo = new AttrGroupWithAttrsVo();
BeanUtils.copyProperties(group, attrsVo);
final List<AttrEntity> attrs = attrService.getRelationAttr(attrsVo.getAttrGroupId());
attrsVo.setAttrs(attrs);
return attrsVo;
}).collect(Collectors.toList());
return collect;
}
暂时取消校验
每一个属性分组一定要至少一个关联,否则会报错,太坑了
在 showBaseAttrs()方法中添加判断
录入数据
复制控制台的数据
逆向生成bean,下载生成的bean并放到vo包下
Class类名写错了是SpusaveVo
修改逆向生成个别属性类型
@Data
public class Attr {
private Long attrId;
private String attrName;
private String attrValue;
}
@Data
public class SpuSaveVo {
private String spuName;
private String spuDescription;
private Long catalogId;
private Long brandId;
private BigDecimal weight;
private int publishStatus;
private List<String> decript;
private List<String> images;
private Bounds bounds;
private List<BaseAttrs> baseAttrs;
private List<Skus> skus;
}
@Data
public class Skus {
private List<Attr> attr;
private String skuName;
private BigDecimal price;
private String skuTitle;
private String skuSubtitle;
private List<Images> images;
private List<String> descar;
private int fullCount;
private BigDecimal discount;
private int countStatus;
private BigDecimal fullPrice;
private BigDecimal reducePrice;
private int priceStatus;
private List<MemberPrice> memberPrice;
}
@Data
public class MemberPrice {
private Long id;
private String name;
private BigDecimal price;
}
@Data
public class BaseAttrs {
private Long attrId;
private String attrValues;
private int showDesc;
}
@Data
public class Bounds {
private BigDecimal buyBounds;
private BigDecimal growBounds;
}
@Data
public class Images {
private String imgUrl;
private int defaultImg;
}
新增商品
SpuInfoController
/**
* 保存
*/
@RequestMapping("/save")
//@RequiresPermissions("product:spuinfo:save")
public R save(@RequestBody SpuSaveVo vo){
// spuInfoService.save(spuInfo);
spuInfoService.saveSpuInfo(vo);
return R.ok();
}
保存Spu的描述图片 SpuInfoDescServiceImpl
@Override
public void saveSpuInfoDesc(SpuInfoDescEntity descEntity) {
this.baseMapper.insert(descEntity);
}
保存spu的图片集
批量保存图片---saveBatch需要的是传入SpuImagesEntity的集合
保存图片
SpuImagesServiceImpl
@Override
public void saveImages(Long id, List<String> images) {
if(images==null ||images.size() ==0){
}else{
final List<SpuImagesEntity> collect = images.stream().map(img -> {
final SpuImagesEntity spuImagesEntity = new SpuImagesEntity();
spuImagesEntity.setSpuId(id);
spuImagesEntity.setImgUrl(img);
return spuImagesEntity;
}).collect(Collectors.toList());
this.saveBatch(collect);
}
}
保存spu的规格参数 ProductAttrValueServiceImpl
@Override
public void saveProductAttr(List<ProductAttrValueEntity> collect) {
this.saveBatch(collect);//批量保存
}
保存spu的积分信息SkuInfoServiceImpl
@Override
public void saveSkuInfo(SkuInfoEntity skuInfoEntity) {
this.baseMapper.insert(skuInfoEntity);
}
远程调用coupon服务
A服务给B服务传数据,将发送的数据封装成对象,将对象发送给B,springcloud默认把对象转换成JSON,B接收JSON数据,并逆转成对象,整个传输区间称为TO【A <----> B】
To统一放在common中
积分SpuBoundTo
import lombok.Data;
import java.math.BigDecimal;
@Data
public class SpuBoundTo {
private Long spuId;
private BigDecimal buyBounds;
private BigDecimal growBounds;
}
创建SkuReductionTo,并 将product---vo的MemberPrice复制一份到common--to中
import lombok.Data;
import java.math.BigDecimal;
import java.util.List;
@Data
public class SkuReductionTo {
private Long skuId;
private int fullCount;
private BigDecimal discount;
private int countStatus;
private BigDecimal fullPrice;
private BigDecimal reducePrice;
private int priceStatus;
private List<MemberPrice> memberPrice;
}
满减SkuFullReductionController
/**
*保存满减信息
*/
@PostMapping("/saveinfo")
// @RequiresPermissions("coupon:skufullreduction:list")
public R saveInfo(@RequestBody SkuReductionTo reductionTo){
skuFullReductionService.saveSkuReduction(skuReductionTo);
return R.ok();
}
SkuFullReductionServiceImpl
@Override
public void saveSkuReduction(SkuReductionTo reductionTo) {
//5.4)、sku的优惠、满减等信息;gulimall_sms->sms_sku_ladder\sms_sku_full_reduction\sms_member_price
final SkuLadderEntity skuLadderEntity = new SkuLadderEntity();
skuLadderEntity.setSkuId(reductionTo.getSkuId());
skuLadderEntity.setFullCount(reductionTo.getFullCount());
skuLadderEntity.setDiscount(reductionTo.getDiscount());
skuLadderEntity.setAddOther(reductionTo.getCountStatus());
//折后价格
// skuLadderEntity.setPrice();
skuadderService.save(skuLadderEntity);
//满减信息
final SkuFullReductionEntity reductionEntity = new SkuFullReductionEntity();
BeanUtils.copyProperties(reductionTo,reductionEntity);
this.save(reductionEntity);
//会员价格
final List<MemberPrice> memberPrice = reductionTo.getMemberPrice();
final List<MemberPriceEntity> collect = memberPrice.stream().map(item -> {
final MemberPriceEntity priceEntity = new MemberPriceEntity();
priceEntity.setSkuId(reductionTo.getSkuId());
priceEntity.setMemberLevelId(item.getId());
priceEntity.setMemberLevelName(item.getName());
priceEntity.setMemberPrice(item.getPrice());
priceEntity.setAddOther(1);
return priceEntity;
}).collect(Collectors.toList());
memberPriceService.saveBatch(collect);
}
R中添加 ,为了判断远程是否成功
public Integer getCode(){
return Integer.parseInt((String) this.get("code"));
}
product.feign.CouponFeignService
@FeignClient("gulimall-coupon")
public interface CouponFeignService {
/**
* 1、CouponFeignService.saveSpuBounds(spuBoundTo);
* 1)、@RequestBody将这个对象转为json。
* 2)、找到gulimall-coupon服务,给/coupon/spubounds/save发送请求。
* 将上一步转的json放在请求体位置,发送请求;
* 3)、对方服务收到请求。请求体里有json数据。
* (@RequestBody SpuBoundsEntity spuBounds);将请求体的json转为SpuBoundsEntity;
*[只要1)发送中spuBoundTo的JSON对象属性名和3)接收方SpuBoundsEntity的JSON属性名一致,双
*方服务无需使用同一个to]
* 只要json数据模型是兼容的。双方服务无需使用同一个to
* @param spuBoundTo
* @return
*/
@PostMapping("/coupon/spubounds/save")
R saveSpuBounds(@RequestBody SpuBoundTo spuBoundTo);
@PostMapping("/coupon/skufullreduction/saveinfo")
R saveSkuReduction(@RequestBody SkuReductionTo skuReductionTo);
}
SpuInfoServiceImpl
@Transactional
@Override
public void saveSpuInfo(SpuSaveVo vo) {
//1、保存spu基本信息 pms_spu_info
final SpuInfoEntity infoEntity = new SpuInfoEntity();
BeanUtils.copyProperties(vo,infoEntity);
infoEntity.setCreateTime(new Date());
infoEntity.setUpdateTime(new Date());
this.saveBaseSpuInfo(infoEntity);
//2、保存Spu的描述图片 pms_spu_info_desc
final List<String> decript = vo.getDecript();
final SpuInfoDescEntity descEntity = new SpuInfoDescEntity();
descEntity.setSpuId(infoEntity.getId());
descEntity.setDecript(String.join(",",decript));
spuInfoDescService.saveSpuInfoDesc(descEntity);
//3、保存spu的图片集 pms_spu_images
final List<String> images = vo.getImages();
//保存所有图片,根据知道infoEntity.getId()哪个商品的图片,images
imagesService.saveImages(infoEntity.getId(),images);
//4、保存spu的规格参数;pms_product_attr_value
final List<BaseAttrs> baseAttrs = vo.getBaseAttrs();
final List<ProductAttrValueEntity> collect = baseAttrs.stream().map(attr -> {
final ProductAttrValueEntity valueEntity = new ProductAttrValueEntity();
valueEntity.setAttrId(attr.getAttrId());//设置当前商品属性的id
final 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);
//6、保存spu的积分信息;gulimall_sms->sms_spu_bounds
final Bounds bounds = vo.getBounds();
final 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的基本信息;pms_sku_info
final 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();
}
}
final 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);
final 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;
}).collect(Collectors.toList());
//5.2)、sku的图片信息;pms_sku_image
skuImagesService.saveBatch(imagesEntities);
final List<Attr> attr = item.getAttr();
final List<SkuSaleAttrValueEntity> skuSaleAttrValueEntities = attr.stream().map(a -> {
final SkuSaleAttrValueEntity attrValueEntity = new SkuSaleAttrValueEntity();
BeanUtils.copyProperties(a, attrValueEntity);
attrValueEntity.setSkuId(skuId);
return attrValueEntity;
}).collect(Collectors.toList());
//5.3)、sku的销售属性信息:pms_sku_sale_attr_value
skuSaleAttrValueService.saveBatch(skuSaleAttrValueEntities);
//5.4)、sku的优惠、满减等信息;gulimall_sms->sms_sku_ladder\sms_sku_full_reduction\sms_member_price
//需要调用远程服务
final SkuReductionTo skuReductionTo = new SkuReductionTo();
BeanUtils.copyProperties(item,skuReductionTo);
skuReductionTo.setSkuId(skuId);
final R r1 = couponFeignService.saveSkuReduction(skuReductionTo);
if(r1.getCode() !=0){
log.error("远程保存sku优惠信息失败");
}
});
}
}
@Override
public void saveBaseSpuInfo(SpuInfoEntity infoEntity) {
//保存基本信息
this.baseMapper.insert(infoEntity);
}
解决内存吃紧
每一个限制100M
pms_spu_info_desc的id不是自增的,插入数据只插入decript;mybatis默认id是自增的。
将id更改为输入模式
重启
降低MySQL的隔离级别,边debug边查看数据
SET SESSION TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;
public Integer getCode(){
return (Integer) this.get("code");
}
feign.FeignException$InternalServerError: [500] during [POST] to [http://gulimall-coupon/coupon/skufullreduction/saveinfo] [CouponFeignService#saveSkuReduction(SkuReductionTo)]: [{"timestamp":"2022-08-16T06:50:28.487+00:00","status":500,"error":"Internal Server Error","path":"/coupon/skufullreduction/saveinfo"}]
at feign.FeignException.serverErrorStatus(FeignException.java:250) ~[feign-core-11.8.jar:na]
at feign.FeignException.errorStatus(FeignException.java:197) ~[feign-core-11.8.jar:na]
at feign.FeignException.errorStatus(FeignException.java:185) ~[feign-core-11.8.jar:na]
at feign.codec.ErrorDecoder$Default.decode(ErrorDecoder.java:92) ~[feign-core-11.8.jar:na]
at feign.AsyncResponseHandler.handleResponse(AsyncResponseHandler.java:96) ~[feign-core-11.8.jar:na]
SkuFullReductionServiceImpl
java.lang.NullPointerException: null
at com.example.gulimall.coupon.service.impl.SkuFullReductionServiceImpl.saveSkuReduction(SkuFullReductionServiceImpl.java:62) ~[classes/:na]
at com.example.gulimall.coupon.service.impl.SkuFullReductionServiceImpl$$FastClassBySpringCGLIB$$778f5dc3.invoke(<generated>) ~[classes/:na]
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218) ~[spring-core-
解决SkuFullReductionServiceImpl-----saveSkuReduction
之所以出现MemberPrice为空是因为 MemberPrice不是复制到common下的to而是剪切,也就是product下的vo不能有MemberPrice
网上各种BeanUtils不能拷贝 List,可能是因为新版已经没有这个bug了。
优化代码
没有图片路径的无需保存
满减为0无意义
满折扣数为0也无意义
BigDecimal使用compareTo来做比较
skuReductionTo.getFullPrice().compareTo(new BigDecimal("0")返回值:-1,0,1
-1 less than小于; 0 equals to 等于; 1 greater than大于
SpuInfoServiceImpl
/**
* //TODO 高级部分来完善
* @param vo
*/
@Transactional
@Override
public void saveSpuInfo(SpuSaveVo vo) {
//1、保存spu基本信息 pms_spu_info
SpuInfoEntity infoEntity = new SpuInfoEntity();
BeanUtils.copyProperties(vo,infoEntity);
infoEntity.setCreateTime(new Date());
infoEntity.setUpdateTime(new Date());
this.saveBaseSpuInfo(infoEntity);
//2、保存Spu的描述图片 pms_spu_info_desc
final List<String> decript = vo.getDecript();
final SpuInfoDescEntity descEntity = new SpuInfoDescEntity();
descEntity.setSpuId(infoEntity.getId());
descEntity.setDecript(String.join(",",decript));
spuInfoDescService.saveSpuInfoDesc(descEntity);
//3、保存spu的图片集 pms_spu_images
final List<String> images = vo.getImages();
//保存所有图片,根据知道infoEntity.getId()哪个商品的图片,images
imagesService.saveImages(infoEntity.getId(),images);
//4、保存spu的规格参数;pms_product_attr_value
final List<BaseAttrs> baseAttrs = vo.getBaseAttrs();
final List<ProductAttrValueEntity> collect = baseAttrs.stream().map(attr -> {
final ProductAttrValueEntity valueEntity = new ProductAttrValueEntity();
valueEntity.setAttrId(attr.getAttrId());//设置当前商品属性的id
final 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);
//6、保存spu的积分信息;gulimall_sms->sms_spu_bounds
final Bounds bounds = vo.getBounds();
final 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信息;
final 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();
}
}
final 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);
//5.1)、sku的基本信息;pms_sku_info
skuInfoService.saveSkuInfo(skuInfoEntity);
final 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的图片信息;pms_sku_image
//TODO 没有图片路径的无需保存
skuImagesService.saveBatch(imagesEntities);
final List<Attr> attr = item.getAttr();
final List<SkuSaleAttrValueEntity> skuSaleAttrValueEntities = attr.stream().map(a -> {
final SkuSaleAttrValueEntity attrValueEntity = new SkuSaleAttrValueEntity();
BeanUtils.copyProperties(a, attrValueEntity);
attrValueEntity.setSkuId(skuId);
return attrValueEntity;
}).collect(Collectors.toList());
//5.3)、sku的销售属性信息:pms_sku_sale_attr_value
skuSaleAttrValueService.saveBatch(skuSaleAttrValueEntities);
//5.4)、sku的优惠、满减等信息;gulimall_sms->sms_sku_ladder\sms_sku_full_reduction\sms_member_price
//需要调用远程服务
final SkuReductionTo skuReductionTo = new SkuReductionTo();
BeanUtils.copyProperties(item,skuReductionTo);
//List集合属性不能使用BeanUtils.copyProperties赋值
// skuReductionTo.setMemberPrice(item.getMemberPrice());
skuReductionTo.setSkuId(skuId);
//优化
if(skuReductionTo.getFullCount() >0 || skuReductionTo.getFullPrice().compareTo(new BigDecimal("0"))==1){
final R r1 = couponFeignService.saveSkuReduction(skuReductionTo);
if(r1.getCode() !=0){
log.error("远程保存sku优惠信息失败");
}
}
});
}
SkuFullReductionServiceImpl
@Override
public void saveSkuReduction(SkuReductionTo reductionTo) {
//5.4)、sku的优惠、满减等信息;gulimall_sms->sms_sku_ladder\sms_sku_full_reduction\sms_member_price
final SkuLadderEntity skuLadderEntity = new SkuLadderEntity();
skuLadderEntity.setSkuId(reductionTo.getSkuId());
skuLadderEntity.setFullCount(reductionTo.getFullCount());
skuLadderEntity.setDiscount(reductionTo.getDiscount());
skuLadderEntity.setAddOther(reductionTo.getCountStatus());
//增加判断
if(reductionTo.getFullCount() >0){
//折后价格
// skuLadderEntity.setPrice();
skuadderService.save(skuLadderEntity);
}
//满减信息
final SkuFullReductionEntity reductionEntity = new SkuFullReductionEntity();
BeanUtils.copyProperties(reductionTo,reductionEntity);
//增加判断skuReductionTo.getFullPrice().compareTo(BigDecimal.ZERO) > 0
if(reductionEntity.getFullPrice().compareTo(new BigDecimal("0"))==1){
this.save(reductionEntity);
}
//会员价格
final List<MemberPrice> memberPrice = reductionTo.getMemberPrice();
if(reductionTo.getMemberPrice()!=null ) {//我加的
final List<MemberPriceEntity> collect = memberPrice.stream().map(item -> {
final MemberPriceEntity priceEntity = new MemberPriceEntity();
priceEntity.setSkuId(reductionTo.getSkuId());
priceEntity.setMemberLevelId(item.getId());
priceEntity.setMemberLevelName(item.getName());
priceEntity.setMemberPrice(item.getPrice());
priceEntity.setAddOther(1);
return priceEntity;
}).filter(item ->{ //优化
//过滤会员价为0的值
return item.getMemberPrice().compareTo(new BigDecimal("0"))==1;
}).collect(Collectors.toList());
memberPriceService.saveBatch(collect);
}
SPU检索
SpuInfoController
/**
* 列表
*/
@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);
}
SpuInfoServiceImpl
@Override
public PageUtils queryPageByCondition(Map<String, Object> params) {
final QueryWrapper<SpuInfoEntity> wrapper = new QueryWrapper<>();
//如果检索关键字不为空
String key = (String) params.get("key");
if(!StringUtils.isEmpty(key)){
wrapper.and((w)->{
//表pms_spu_info
//动态SQL语句
w.eq("id",key).or().like("spu_name",key);
});
}
String status = (String) params.get("status");
if(!StringUtils.isEmpty(status) ){
//wrapper.eq("数据库中的字段名",catelogId);
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);
}
在product---application.xml ----yyyy-MM-dd HH:mm:ss
商品管理--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);
}
SkuInfoServiceImpl
@Override
public PageUtils queryPageByCondition(Map<String, Object> params) {
final QueryWrapper<SkuInfoEntity> wrapper = new QueryWrapper<>();
String key = (String) params.get("key");
if(!StringUtils.isEmpty(key) ){
wrapper.eq("sku_id",key).or().like("sku_name",key);
}
String catelogId = (String) params.get("catelogId");
if(!StringUtils.isEmpty(catelogId) && !"0".equalsIgnoreCase(catelogId)){
wrapper.eq("catalog_id",catelogId);
}
String brandId = (String) params.get("brandId");
if(!StringUtils.isEmpty(brandId) && !"0".equalsIgnoreCase(brandId)){
wrapper.eq("brand_id",brandId);
}
String min = (String) params.get("min");
if(!StringUtils.isEmpty(min)){
wrapper.ge("price",min);
}
String max = (String) params.get("max");
if(!StringUtils.isEmpty(max) ){
try{
final BigDecimal bigDecimal = new BigDecimal(max);
if( bigDecimal.compareTo(new BigDecimal("0"))==1){
wrapper.le("price",max);
}
}catch(Exception e){
}
}
IPage<SkuInfoEntity> page = this.page(
new Query<SkuInfoEntity>().getPage(params),
wrapper
);
return new PageUtils(page);
}
仓储服务-仓库管理
添加日志
logging:
level:
com.example: debug
@EnableTransactionManagement //开启事务
@MapperScan("com.example.gulimall.ware.dao")
@EnableDiscoveryClient
@SpringBootApplication
public class GulimallWareApplication {
public static void main(String[] args) {
SpringApplication.run(GulimallWareApplication.class, args);
}
}
添加路由
- id: member_route
uri: lb://gulimall-ware
predicates:
- Path=/api/ware/**
filters:
- RewritePath=/api/(?<segment>.*),/$\{segment}
WareInfoServiceImpl
@Override
public PageUtils queryPage(Map<String, Object> params) {
final QueryWrapper<WareInfoEntity> wareInfoEntityQueryWrapper = new QueryWrapper<>();
final String key = (String) params.get("key");
//根据检索关键字查询
if(!StringUtils.isEmpty(key)){
wareInfoEntityQueryWrapper.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),
wareInfoEntityQueryWrapper
);
return new PageUtils(page);
}
商品管理---查询商品库存
WareSkuServiceImpl
@Override
public PageUtils queryPage(Map<String, Object> params) {
final QueryWrapper<WareSkuEntity> wareSkuEntityQueryWrapper = new QueryWrapper<>();
final String skuId = (String) params.get("skuId");
if(!StringUtils.isEmpty(skuId)){
wareSkuEntityQueryWrapper.eq("sku_id",skuId);
}
final String wareId = (String) params.get("wareId");
if(!StringUtils.isEmpty(skuId)){
wareSkuEntityQueryWrapper.eq("ware_id",wareId);
}
IPage<WareSkuEntity> page = this.page(
new Query<WareSkuEntity>().getPage(params),
wareSkuEntityQueryWrapper
);
return new PageUtils(page);
}
采购需求--检索
PurchaseDetailServiceImpl
@Override
public PageUtils queryPage(Map<String, Object> params) {
QueryWrapper<PurchaseDetailEntity> queryWrapper =new QueryWrapper<PurchaseDetailEntity>();
final String key = (String) params.get("key");
if(!StringUtils.isEmpty(key)){
queryWrapper.and(w ->{
w.eq("purchase_id",key).or().eq("sku_id",key);
});
}
final String status = (String) params.get("status");
if(!StringUtils.isEmpty(status)){
queryWrapper.and(w ->{
w.eq("status",status);
});
}
final String wareId = (String) params.get("wareId");
if(!StringUtils.isEmpty(wareId)){
queryWrapper.and(w ->{
w.eq("ware_id",wareId);
});
}
IPage<PurchaseDetailEntity> page = this.page(
new Query<PurchaseDetailEntity>().getPage(params),
queryWrapper
);
return new PageUtils(page);
}
合并采购需求
查询未领取的采购单
PurchaseController
@RequestMapping("/unreceive/list")
// @RequiresPermissions("ware:purchase:list")
public R unreceivelist(@RequestParam Map<String, Object> params){
PageUtils page = purchaseService.queryPageUnreceivePurchase(params);
return R.ok().put("page", page);
}
新建优先级为1,然后分配给ahei
合并采购需求
在ware下创建vo
@Data
public class MergeVo {
private Long purchaseId;
private List<Long> items;
}
PurchaseController
@PostMapping("/merge")
// @RequiresPermissions("ware:purchase:list")
public R merge(@RequestBody MergeVo mergeVo){
purchaseService.mergePurchase(mergeVo);
return R.ok();
}
/**
* 保存
*/
@RequestMapping("/save")
//@RequiresPermissions("ware:purchase:save")
public R save(@RequestBody PurchaseEntity purchase){
purchase.setUpdateTime(new Date());
purchase.setCreateTime(new Date());
purchaseService.save(purchase);
return R.ok();
}
PurchaseServiceImpl
@Transactional
@Override
public void mergePurchase(MergeVo mergeVo) {
Long purchaseId = mergeVo.getPurchaseId();
if(purchaseId ==null){
//新建一个
final PurchaseEntity purchaseEntity = new PurchaseEntity();
purchaseEntity.setStatus(WareConstant.PurchaseStatusEnum.CREATED.getCode());
purchaseEntity.setCreateTime(new Date());
purchaseEntity.setUpdateTime(new Date());
this.save(purchaseEntity);
purchaseId = purchaseEntity.getId();
}
//合并
List<Long> items = mergeVo.getItems();
Long finalPurchaseId = purchaseId;
final List<PurchaseDetailEntity> collect = items.stream().map(i -> {
final PurchaseDetailEntity detailEntity = new PurchaseDetailEntity();
detailEntity.setId(i);
detailEntity.setPurchaseId(finalPurchaseId);
detailEntity.setStatus(WareConstant.PurchaseDetailEnum.ASSIGNED.getCode());
return detailEntity;
}).collect(Collectors.toList());
//批量修改
purchaseDetailService.updateBatchById(collect);
PurchaseEntity purchaseEntity = new PurchaseEntity();
purchaseEntity.setId(purchaseId);
purchaseEntity.setUpdateTime(new Date());
this.updateById(purchaseEntity);
}
common中创建WareConstant
package com.example.common.constant;
public class WareConstant {
public enum PurchaseStatusEnum{
CREATED(0,"新建"),ASSIGNED(1,"已分配"),
QRECEIVE(2,"已领取"),FINISH(3,"已完成"),
HASERROR(4,"有异常");
private int code;
private String msg;
PurchaseStatusEnum(int code,String msg){
this.code =code;
this.msg =msg;
}
public int getCode(){
return code;
}
public String getMsg() {
return msg;
}
}
public enum PurchaseDetailEnum{
CREATED(0,"新建"),ASSIGNED(1,"已分配"),
BUYING(2,"正在采购"),FINISH(3,"已完成"),
HASERROR(4,"采购失败");
private int code;
private String msg;
PurchaseDetailEnum(int code,String msg){
this.code =code;
this.msg =msg;
}
public int getCode(){
return code;
}
public String getMsg() {
return msg;
}
}
}
确定