This commit is contained in:
haoxr 2021-07-27 20:46:27 +08:00
parent 66c79457b4
commit 4f468f751c
37 changed files with 400 additions and 279 deletions

View File

@ -1,6 +1,5 @@
package com.youlai.mall.oms.enums;
import lombok.AllArgsConstructor;
import lombok.Getter;
/**
@ -9,25 +8,31 @@ import lombok.Getter;
* @email huawei_code@163.com
* @date 2021/1/16
*/
@AllArgsConstructor
public enum PayTypeEnum {
public enum PayTypeEnum {
WEIXIN(1, "微信支付"),
ALIPAY(2, "支付宝支付"),
BALANCE(3, "会员余额支付");
PayTypeEnum(int code, String text) {
this.code = code;
this.text = text;
}
WEIXIN(1,"微信支付"),
ALIPAY(2,"支付宝支付"),
BALANCE(3,"会员余额支付")
;
@Getter
private Integer code;
@Getter
private String text;
public static PayTypeEnum getByCode(Integer code){
public static PayTypeEnum getByCode(Integer code) {
PayTypeEnum payTypeEnum = null;
for (PayTypeEnum value : values()) {
if (value.getCode().equals(code)) {
return value;
payTypeEnum = value;
}
}
return null;
return payTypeEnum;
}
}

View File

@ -5,7 +5,7 @@ import com.youlai.mall.oms.constant.OmsConstants;
import com.youlai.mall.oms.pojo.vo.CartVO;
import com.youlai.mall.oms.service.ICartService;
import com.youlai.mall.pms.api.GoodsFeignClient;
import com.youlai.mall.pms.pojo.dto.SkuDTO;
import com.youlai.mall.pms.pojo.dto.app.SkuDTO;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.BoundHashOperations;

View File

@ -27,8 +27,8 @@ import com.youlai.mall.oms.service.ICartService;
import com.youlai.mall.oms.service.IOrderItemService;
import com.youlai.mall.oms.service.IOrderService;
import com.youlai.mall.pms.api.GoodsFeignClient;
import com.youlai.mall.pms.pojo.dto.SkuDTO;
import com.youlai.mall.pms.pojo.dto.SkuLockDTO;
import com.youlai.mall.pms.pojo.dto.app.SkuDTO;
import com.youlai.mall.pms.pojo.dto.app.SkuLockDTO;
import com.youlai.mall.ums.api.MemberAddressFeignClient;
import com.youlai.mall.ums.api.MemberFeignClient;
import com.youlai.mall.ums.pojo.entity.UmsAddress;

View File

@ -1,12 +1,10 @@
package com.youlai.mall.pms.api;
import com.youlai.common.result.Result;
import com.youlai.mall.pms.pojo.dto.SkuDTO;
import com.youlai.mall.pms.pojo.dto.SkuLockDTO;
import com.youlai.mall.pms.pojo.dto.app.SkuDTO;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
@FeignClient(value = "mall-pms")
public interface GoodsFeignClient {
@ -16,25 +14,4 @@ public interface GoodsFeignClient {
*/
@GetMapping("/app-api/v1/goods/{id}")
Result<SkuDTO> getSkuById(@PathVariable Long id);
/**
* 锁定库存
*/
@PutMapping("/app-api/v1/goods/stocks/_lock")
Result lockStock(@RequestBody List<SkuLockDTO> list);
/**
* 解锁库存
*/
@PutMapping("/app-api/v1/goods/stocks/_unlock")
Result<Boolean> unlockStock(@RequestParam String orderToken);
/**
* 扣减库存
*/
@PutMapping("/app-api/v1/goods/stocks/_deduct")
Result deductStock(@RequestParam String orderToken);
}

View File

@ -0,0 +1,33 @@
package com.youlai.mall.pms.api;
import com.youlai.common.result.Result;
import com.youlai.mall.pms.pojo.dto.app.SkuLockDTO;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@FeignClient(value = "mall-pms")
public interface StockFeignClient {
/**
* 锁定库存
*/
@PutMapping("/app-api/v1/stocks/_lock")
Result lockStock(@RequestBody List<SkuLockDTO> list);
/**
* 解锁库存
*/
@PutMapping("/app-api/v1/stocks/_unlock")
Result<Boolean> unlockStock(@RequestParam String orderToken);
/**
* 扣减库存
*/
@PutMapping("/app-api/v1/stocks/_deduct")
Result deductStock(@RequestParam String orderToken);
}

View File

@ -1,22 +0,0 @@
package com.youlai.mall.pms.pojo.dto;
import lombok.Data;
import java.util.List;
@Data
public class SpuDTO {
private Long id;
private String name;
private Long categoryId;
private Long brandId;
private Long originPrice;
private Long price;
private Integer sales;
private String pic;
private List<String> pics;
private String unit;
private String description;
private String detail;
private Integer status;
}

View File

@ -11,7 +11,7 @@ import java.util.List;
@Data
@ApiModel("属性表单对象")
@ApiModel("属性表单")
public class AttributeFormDTO {
@ApiModelProperty("分类ID")

View File

@ -0,0 +1,29 @@
package com.youlai.mall.pms.pojo.dto.admin;
import com.youlai.mall.pms.pojo.entity.PmsSku;
import com.youlai.mall.pms.pojo.entity.PmsSpuAttributeValue;
import lombok.Data;
import java.util.List;
/**
* @author <a href="mailto:xianrui0365@163.com">xianrui</a>
*/
@Data
public class GoodsFormDTO {
private Long id;
private String name;
private Long categoryId;
private Long brandId;
private Long originPrice;
private Long price;
private String picUrl;
private List<String> album;
private String description;
private String detail;
private List<PmsSpuAttributeValue> attrValueList;
private List<PmsSku> skuList;
}

View File

@ -1,22 +0,0 @@
package com.youlai.mall.pms.pojo.dto.admin;
import com.youlai.mall.pms.pojo.dto.SpuDTO;
import com.youlai.mall.pms.pojo.entity.PmsSku;
import com.youlai.mall.pms.pojo.entity.PmsSpuAttributeValue;
import lombok.Data;
import java.util.List;
/**
* @author <a href="mailto:xianrui0365@163.com">xianrui</a>
*/
@Data
public class ProductFormDTO {
private SpuDTO spu;
private List<PmsSpuAttributeValue> attrs;
private List<PmsSku> skus;
}

View File

@ -2,7 +2,6 @@ package com.youlai.mall.pms.pojo.dto.app;
import com.youlai.mall.pms.pojo.entity.PmsSku;
import com.youlai.mall.pms.pojo.entity.PmsSpuAttributeValue;
import com.youlai.mall.pms.pojo.dto.SpuDTO;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@ -14,11 +13,29 @@ import java.util.List;
@NoArgsConstructor
public class ProductFormDTO {
private SpuDTO spu;
private SpuInfo spuInfo;
private List<PmsSpuAttributeValue> attrs;
private List<PmsSpuAttributeValue> attrValueList;
private List<PmsSku> skus;
private List<PmsSku> skuList;
@Data
public static class SpuInfo {
private Long id;
private String name;
private Long categoryId;
private Long brandId;
private Long originPrice;
private Long price;
private Integer sales;
private String picUrl;
private List<String> album;
private String unit;
private String description;
private String detail;
private Integer status;
}
}

View File

@ -1,4 +1,4 @@
package com.youlai.mall.pms.pojo.dto;
package com.youlai.mall.pms.pojo.dto.app;
import lombok.Data;

View File

@ -1,4 +1,4 @@
package com.youlai.mall.pms.pojo.dto;
package com.youlai.mall.pms.pojo.dto.app;
import lombok.AllArgsConstructor;
import lombok.Builder;

View File

@ -13,7 +13,7 @@ public class PmsSku extends BaseEntity {
private String name;
private String sn;
private String picUrl;
private String specifications;
private String specs;
private Long originPrice;
private Long price;
private Integer stock;

View File

@ -0,0 +1,46 @@
package com.youlai.mall.pms.pojo.vo.admin;
import com.youlai.mall.pms.pojo.entity.PmsSku;
import com.youlai.mall.pms.pojo.entity.PmsSpuAttributeValue;
import lombok.Data;
import lombok.ToString;
import java.util.List;
/**
* 商品详情视图层对象
*
* @author <a href="mailto:xianrui0365@163.com">xianrui</a>
*/
@Data
@ToString
public class GoodsDetailVO {
private Long id;
private String name;
private Long categoryId;
private Long brandId;
private Long originPrice;
private Long price;
private String picUrl;
private List<String> subPicUrls;
private String description;
private String detail;
private List<PmsSpuAttributeValue> attrList;
private List<PmsSpuAttributeValue> specList;
private List<PmsSku> skuList;
}

View File

@ -0,0 +1,37 @@
package com.youlai.mall.pms.common.enums;
import lombok.Getter;
/**
* 商品属性类型枚举
*
* @author <a href="mailto:xianrui0365@163.com">xianrui</a>
*/
public enum GoodsAttrTypeEnum {
SPECIFICATION(1, "规格"),
ATTRIBUTE(2, "属性");
GoodsAttrTypeEnum(int value, String name) {
this.value = value;
this.name = name;
}
@Getter
private Integer value;
@Getter
private String name;
public static GoodsAttrTypeEnum getByValue(Integer value) {
GoodsAttrTypeEnum goodsAttrTypeEnum = null;
for (GoodsAttrTypeEnum item : values()) {
if (item.getValue().equals(value)) {
goodsAttrTypeEnum = item;
}
}
return goodsAttrTypeEnum;
}
}

View File

@ -4,8 +4,9 @@ import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.youlai.common.result.Result;
import com.youlai.mall.pms.pojo.dto.admin.ProductFormDTO;
import com.youlai.mall.pms.pojo.dto.admin.GoodsFormDTO;
import com.youlai.mall.pms.pojo.entity.PmsSpu;
import com.youlai.mall.pms.pojo.vo.admin.GoodsDetailVO;
import com.youlai.mall.pms.service.IPmsSpuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
@ -13,7 +14,6 @@ import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;
import java.util.Arrays;
import java.util.stream.Collectors;
@ -22,7 +22,7 @@ import java.util.stream.Collectors;
*/
@Api(tags = "系统管理端-商品信息")
@RestController
@RequestMapping("/api/v1/products")
@RequestMapping("/api/v1/goods")
@AllArgsConstructor
public class GoodsController {
@ -38,30 +38,35 @@ public class GoodsController {
})
@GetMapping("/page")
public Result list(Integer page, Integer limit, String name, Long categoryId) {
IPage<PmsSpu> result = iPmsSpuService.list(
new Page<>(page, limit),
new PmsSpu().setName(name).setCategoryId(categoryId)
);
IPage<PmsSpu> result = iPmsSpuService.list(new Page<>(page, limit), name, categoryId);
return Result.success(result.getRecords(), result.getTotal());
}
@ApiOperation(value = "商品详情")
@ApiImplicitParam(name = "id", value = "商品id", required = true, paramType = "path", dataType = "Long")
@GetMapping("/{id}")
public Result detail(@PathVariable Long id) {
GoodsDetailVO goodsDetail = iPmsSpuService.getGoodsById(id);
return Result.success(goodsDetail);
}
@ApiOperation(value = "新增商品")
@ApiImplicitParam(name = "productForm", value = "实体JSON对象", required = true, paramType = "body", dataType = "ProductFormDTO")
@ApiImplicitParam(name = "goodsForm", value = "实体JSON对象", required = true, paramType = "body", dataType = "GoodsFormDTO")
@PostMapping
public Result add(@RequestBody ProductFormDTO productForm) {
boolean status = iPmsSpuService.add(productForm);
return Result.judge(status);
public Result add(@RequestBody GoodsFormDTO goodsForm) {
boolean result = iPmsSpuService.addGoods(goodsForm);
return Result.judge(result);
}
@ApiOperation(value = "修改商品")
@ApiImplicitParams({
@ApiImplicitParam(name = "id", value = "商品id", required = true, paramType = "path", dataType = "Long"),
@ApiImplicitParam(name = "spu", value = "实体JSON对象", required = true, paramType = "body", dataType = "PmsSpu")
@ApiImplicitParam(name = "goodsForm", value = "实体JSON对象", required = true, paramType = "body", dataType = "GoodsFormDTO")
})
@PutMapping(value = "/{id}")
public Result update(@PathVariable Long id, @RequestBody ProductFormDTO spu) {
boolean status = iPmsSpuService.updateById(spu);
return Result.judge(status);
public Result update(@PathVariable Long id, @RequestBody GoodsFormDTO goodsForm) {
boolean result = iPmsSpuService.updateGoods(goodsForm);
return Result.judge(result);
}
@ApiOperation(value = "删除商品")

View File

@ -15,7 +15,7 @@ import org.springframework.web.bind.annotation.*;
*/
@Api(tags = "系统管理端-库存信息")
@RestController
@RequestMapping("/api/v1/goods")
@RequestMapping("/api/v1/inventories")
@RequiredArgsConstructor
public class StockController {

View File

@ -18,7 +18,7 @@ import java.util.List;
* @author <a href="mailto:xianrui0365@163.com">xianrui</a>
*/
@Api(tags = "移动端-分类信息")
@RestController("AppCategoryController")
@RestController("appCategoryController")
@RequestMapping("/app-api/v1/categories")
@Slf4j
@AllArgsConstructor

View File

@ -1,8 +1,8 @@
package com.youlai.mall.pms.controller.app;
import com.youlai.common.result.Result;
import com.youlai.mall.pms.pojo.dto.SkuDTO;
import com.youlai.mall.pms.pojo.dto.SkuLockDTO;
import com.youlai.mall.pms.pojo.dto.app.SkuDTO;
import com.youlai.mall.pms.pojo.dto.app.SkuLockDTO;
import com.youlai.mall.pms.service.IPmsSkuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;

View File

@ -2,7 +2,7 @@ package com.youlai.mall.pms.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.youlai.mall.pms.pojo.entity.PmsSku;
import com.youlai.mall.pms.pojo.dto.SkuDTO;
import com.youlai.mall.pms.pojo.dto.app.SkuDTO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

View File

@ -13,5 +13,5 @@ import java.util.List;
@Mapper
public interface PmsSpuMapper extends BaseMapper<PmsSpu> {
List<PmsSpu> list(Page<PmsSpu> page, PmsSpu spu);
List<PmsSpu> list(Page<PmsSpu> page, String name, Long categoryId);
}

View File

@ -2,8 +2,8 @@ package com.youlai.mall.pms.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.youlai.mall.pms.pojo.entity.PmsSku;
import com.youlai.mall.pms.pojo.dto.SkuDTO;
import com.youlai.mall.pms.pojo.dto.SkuLockDTO;
import com.youlai.mall.pms.pojo.dto.app.SkuDTO;
import com.youlai.mall.pms.pojo.dto.app.SkuLockDTO;
import java.util.List;

View File

@ -3,22 +3,22 @@ package com.youlai.mall.pms.service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.youlai.mall.pms.pojo.dto.app.ProductFormDTO;
import com.youlai.mall.pms.pojo.dto.admin.GoodsFormDTO;
import com.youlai.mall.pms.pojo.entity.PmsSpu;
import com.youlai.mall.pms.pojo.vo.admin.GoodsDetailVO;
import java.util.List;
public interface IPmsSpuService extends IService<PmsSpu> {
IPage<PmsSpu> list(Page<PmsSpu> page, PmsSpu spu);
IPage<PmsSpu> list(Page<PmsSpu> page, String name,Long categoryId);
boolean add(com.youlai.mall.pms.pojo.dto.admin.ProductFormDTO productFormDTO);
com.youlai.mall.pms.pojo.dto.admin.ProductFormDTO getBySpuId(Long id);
boolean addGoods(GoodsFormDTO goodsFormDTO);
boolean removeBySpuIds(List<Long> spuIds);
boolean updateById(com.youlai.mall.pms.pojo.dto.admin.ProductFormDTO productFormDTO);
boolean updateGoods(GoodsFormDTO goodsFormDTO);
ProductFormDTO getProductByIdForApp(Long id);
GoodsDetailVO getGoodsById(Long id);
}

View File

@ -10,8 +10,8 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.youlai.common.web.exception.BizException;
import com.youlai.mall.pms.mapper.PmsSkuMapper;
import com.youlai.mall.pms.pojo.entity.PmsSku;
import com.youlai.mall.pms.pojo.dto.SkuDTO;
import com.youlai.mall.pms.pojo.dto.SkuLockDTO;
import com.youlai.mall.pms.pojo.dto.app.SkuDTO;
import com.youlai.mall.pms.pojo.dto.app.SkuLockDTO;
import com.youlai.mall.pms.service.IPmsSkuService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
@ -126,8 +126,8 @@ public class PmsSkuServiceImpl extends ServiceImpl<PmsSkuMapper, PmsSku> impleme
skuLockList.forEach(item -> {
boolean result = this.update(new LambdaUpdateWrapper<PmsSku>()
.eq(PmsSku::getId, item.getSkuId())
.setSql("stock = stock - " + item.getCount()) // 扣减库存
.setSql("locked_stock = locked_stock - " + item.getCount())
.setSql("inventory = inventory - " + item.getCount()) // 扣减库存
.setSql("locked_inventory = locked_inventory - " + item.getCount())
);
if (!result) {
throw new BizException("扣减库存失败,商品" + item.getSkuId() + "库存不足");

View File

@ -1,54 +1,58 @@
package com.youlai.mall.pms.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.lang.Assert;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.youlai.mall.pms.common.enums.GoodsAttrTypeEnum;
import com.youlai.mall.pms.component.BloomRedisService;
import com.youlai.mall.pms.mapper.PmsSpuMapper;
import com.youlai.mall.pms.pojo.dto.SpuDTO;
import com.youlai.mall.pms.pojo.dto.admin.ProductFormDTO;
import com.youlai.mall.pms.pojo.entity.*;
import com.youlai.mall.pms.service.*;
import com.youlai.mall.pms.pojo.dto.admin.GoodsFormDTO;
import com.youlai.mall.pms.pojo.entity.PmsSku;
import com.youlai.mall.pms.pojo.entity.PmsSpu;
import com.youlai.mall.pms.pojo.entity.PmsSpuAttributeValue;
import com.youlai.mall.pms.pojo.vo.admin.GoodsDetailVO;
import com.youlai.mall.pms.service.IPmsAttributeService;
import com.youlai.mall.pms.service.IPmsSkuService;
import com.youlai.mall.pms.service.IPmsSpuAttributeValueService;
import com.youlai.mall.pms.service.IPmsSpuService;
import lombok.AllArgsConstructor;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import static com.youlai.mall.pms.common.constant.PmsConstants.PRODUCT_REDIS_BLOOM_FILTER;
/**
* @author <a href="mailto:xianrui0365@163.com">xianrui</a>
*/
@Service
@AllArgsConstructor
@RequiredArgsConstructor
public class PmsSpuServiceImpl extends ServiceImpl<PmsSpuMapper, PmsSpu> implements IPmsSpuService {
private IPmsSkuService iPmsSkuService;
private IPmsSpuAttributeValueService iPmsSpuAttributeValueService;
private IPmsAttributeService attributeService;
private BloomRedisService bloomRedisService;
private final IPmsSkuService iPmsSkuService;
private final IPmsSpuAttributeValueService iPmsSpuAttributeValueService;
private final IPmsAttributeService attributeService;
private final BloomRedisService bloomRedisService;
@Override
public IPage<PmsSpu> list(Page<PmsSpu> page, PmsSpu spu) {
List<PmsSpu> list = this.baseMapper.list(page, spu);
public IPage<PmsSpu> list(Page<PmsSpu> page, String name, Long categoryId) {
List<PmsSpu> list = this.baseMapper.list(page, name, categoryId);
page.setRecords(list);
return page;
}
@Override
@Transactional
public boolean add(ProductFormDTO productFormDTO) {
SpuDTO SpuDTO = productFormDTO.getSpu();
List<PmsSpuAttributeValue> attrValues = productFormDTO.getAttrs();
List<PmsSpuAttributeValue> specs = productFormDTO.getAttrs();
List<PmsSku> skuList = productFormDTO.getSkus();
public boolean addGoods(GoodsFormDTO goodsForm) {
/* SpuDTO SpuDTO = goodsForm.getSpu();
List<PmsSpuAttributeValue> attrValues = goodsForm.getAttrs();
List<PmsSpuAttributeValue> specs = goodsForm.getAttrs();
List<PmsSku> skuList = goodsForm.getSkus();
// spu保存
PmsSpu spu = new PmsSpu();
@ -67,8 +71,8 @@ public class PmsSpuServiceImpl extends ServiceImpl<PmsSpuMapper, PmsSpu> impleme
// 规格保存
Optional.ofNullable(specs).ifPresent(list -> {
/* list.forEach(item -> item.setSpuId(spu.getId()));
iPmsSpuSpecValueService.saveBatch(list);*/
*//* list.forEach(item -> item.setSpuId(spu.getId()));
iPmsSpuSpecValueService.saveBatch(list);*//*
});
// sku保存
@ -76,45 +80,18 @@ public class PmsSpuServiceImpl extends ServiceImpl<PmsSpuMapper, PmsSpu> impleme
list.forEach(item -> item.setSpuId(spu.getId()));
iPmsSkuService.saveBatch(skuList);
});
bloomRedisService.addByBloomFilter(PRODUCT_REDIS_BLOOM_FILTER, spu.getId() + "");
bloomRedisService.addByBloomFilter(PRODUCT_REDIS_BLOOM_FILTER, spu.getId() + "");*/
return true;
}
@Override
public ProductFormDTO getBySpuId(Long id) {
// spu
SpuDTO spuDTO = new SpuDTO();
PmsSpu spu = this.getById(id);
BeanUtil.copyProperties(spu, spuDTO);
if (StrUtil.isNotBlank(spu.getAlbum())) {
// spu专辑图片转换处理 json字符串 -> List
List<String> pics = JSONUtil.toList(JSONUtil.parseArray(spu.getAlbum()), String.class);
spuDTO.setPics(pics);
}
// 属性
List<PmsSpuAttributeValue> attrs = iPmsSpuAttributeValueService.
list(new LambdaQueryWrapper<PmsSpuAttributeValue>().eq(PmsSpuAttributeValue::getSpuId, id));
// 规格
List<PmsSpuAttributeValue> specs = iPmsSpuAttributeValueService.list(new LambdaQueryWrapper<PmsSpuAttributeValue>().eq(PmsSpuAttributeValue::getSpuId, id));
// sku
List<PmsSku> skus = iPmsSkuService.list(new LambdaQueryWrapper<PmsSku>().eq(PmsSku::getSpuId, id));
// 组合
// ProductFormDTO productFormDTO = new ProductFormDTO(spuDTO, attrs, specs, skus);
ProductFormDTO productFormDTO = new ProductFormDTO();
return productFormDTO;
}
@Override
public boolean updateById(ProductFormDTO productFormDTO) {
SpuDTO SpuDTO = productFormDTO.getSpu();
public boolean updateGoods(GoodsFormDTO goodsFormDTO) {
/* SpuDTO SpuDTO = goodsFormDTO.getSpu();
List<PmsSpuAttributeValue> attrValues = productFormDTO.getAttrs();
List<PmsSpuAttributeValue> specs = productFormDTO.getAttrs();
List<PmsSku> skuList = productFormDTO.getSkus();
List<PmsSpuAttributeValue> attrValues = goodsFormDTO.getAttrs();
List<PmsSpuAttributeValue> specs = goodsFormDTO.getAttrs();
List<PmsSku> skuList = goodsFormDTO.getSkus();
// spu保存
PmsSpu spu = new PmsSpu();
@ -174,10 +151,48 @@ public class PmsSpuServiceImpl extends ServiceImpl<PmsSpuMapper, PmsSpu> impleme
iPmsSkuService.removeByIds(removeIds);
iPmsSkuService.saveOrUpdateBatch(skuList);
});
});*/
return true;
}
@Override
public GoodsDetailVO getGoodsById(Long id) {
GoodsDetailVO goodsDetailVO = new GoodsDetailVO();
PmsSpu spu = this.getById(id);
Assert.isTrue(spu != null, "商品不存在");
BeanUtil.copyProperties(spu, goodsDetailVO);
// 商品图册JSON字符串转JSON
String album = spu.getAlbum();
if (StrUtil.isNotBlank(album)) {
List<String> picUrls = JSONUtil.toList(album, String.class);
goodsDetailVO.setSubPicUrls(picUrls);
}
// 商品属性列表
List<PmsSpuAttributeValue> attrList = iPmsSpuAttributeValueService.list(new LambdaQueryWrapper<PmsSpuAttributeValue>()
.eq(PmsSpuAttributeValue::getSpuId, id)
.eq(PmsSpuAttributeValue::getType, GoodsAttrTypeEnum.ATTRIBUTE.getValue())
);
goodsDetailVO.setAttrList(attrList);
// 商品规格列表
List<PmsSpuAttributeValue> specList = iPmsSpuAttributeValueService.list(new LambdaQueryWrapper<PmsSpuAttributeValue>()
.eq(PmsSpuAttributeValue::getSpuId, id)
.eq(PmsSpuAttributeValue::getType, GoodsAttrTypeEnum.SPECIFICATION.getValue())
);
goodsDetailVO.setSpecList(specList);
// 商品SKU列表
List<PmsSku> skuList = iPmsSkuService.list(new LambdaQueryWrapper<PmsSku>().eq(PmsSku::getSpuId, id));
goodsDetailVO.setSkuList(skuList);
return goodsDetailVO;
}
@Override
public boolean removeBySpuIds(List<Long> spuIds) {
Optional.ofNullable(spuIds).ifPresent(
@ -195,31 +210,5 @@ public class PmsSpuServiceImpl extends ServiceImpl<PmsSpuMapper, PmsSpu> impleme
return true;
}
@Override
public com.youlai.mall.pms.pojo.dto.app.ProductFormDTO getProductByIdForApp(Long spuId) {
// spu
PmsSpu spu = this.getById(spuId);
SpuDTO SpuDTO = new SpuDTO();
BeanUtil.copyProperties(spu, SpuDTO);
if (StrUtil.isNotBlank(spu.getAlbum())) {
// spu专辑图片转换处理 json字符串 -> List
List<String> pics = JSONUtil.toList(JSONUtil.parseArray(spu.getAlbum()), String.class);
SpuDTO.setPics(pics);
}
// 属性
List<PmsSpuAttributeValue> attrs = iPmsSpuAttributeValueService.list(
new LambdaQueryWrapper<PmsSpuAttributeValue>(
).eq(PmsSpuAttributeValue::getSpuId, spuId)
);
// 规格
// List<PmsAttribute> specs = attributeService.listBySpuId(spuId);
List<PmsAttribute> specs = null;
// sku
List<PmsSku> skuList = iPmsSkuService.list(new LambdaQueryWrapper<PmsSku>().eq(PmsSku::getSpuId, spuId));
// com.youlai.mall.pms.pojo.dto.app.ProductFormDTO product = new com.youlai.mall.pms.pojo.dto.app.ProductFormDTO(SpuDTO, attrs, specs, skuList);
com.youlai.mall.pms.pojo.dto.app.ProductFormDTO product=new com.youlai.mall.pms.pojo.dto.app.ProductFormDTO();
return product;
}
}

View File

@ -8,7 +8,6 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.youlai.common.redis.utils.RedisUtils;
import com.youlai.mall.pms.config.ProductLocalCache;
import com.youlai.mall.pms.mapper.PmsSpuMapper;
import com.youlai.mall.pms.pojo.dto.SpuDTO;
import com.youlai.mall.pms.pojo.dto.app.ProductFormDTO;
import com.youlai.mall.pms.pojo.entity.PmsAttribute;
import com.youlai.mall.pms.pojo.entity.PmsSku;
@ -50,7 +49,7 @@ public class ProductServiceImpl extends ServiceImpl<PmsSpuMapper, PmsSpu> implem
public ProductFormDTO getProductById(Long spuId) {
//1一级本地缓存设置
ProductFormDTO product = productLocalCache.get(PRODUCT_DETAIL_CACHE + spuId);
if (null != product) {
/* if (null != product) {
log.info("get LocalCache product:" + product);
return product;
}
@ -104,7 +103,7 @@ public class ProductServiceImpl extends ServiceImpl<PmsSpuMapper, PmsSpu> implem
lock.unlock();
}
}
}
}*/
return product;
}
}

View File

@ -10,7 +10,7 @@
<result property="name" column="name" jdbcType="VARCHAR"/>
<result property="sn" column="sn" jdbcType="VARCHAR"/>
<result property="picUrl" column="pic_url" jdbcType="VARCHAR"/>
<result property="specifications" column="specifications" jdbcType="VARCHAR"/>
<result property="specs" column="specs" jdbcType="VARCHAR"/>
<result property="originPrice" column="origin_price" jdbcType="BIGINT"/>
<result property="price" column="price" jdbcType="BIGINT"/>
<result property="stock" column="stock" jdbcType="INTEGER"/>
@ -21,7 +21,7 @@
<sql id="Base_Column_List">
id,spu_id,name,
sn,pic_url,specifications,
sn,pic_url,specs,
origin_price,price,stock,
locked_stock,gmt_create,gmt_modified
</sql>

View File

@ -3,56 +3,67 @@
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.youlai.mall.pms.mapper.PmsSpuMapper">
<resultMap id="BaseResultMap" type="com.youlai.mall.pms.pojo.entity.PmsSpu">
<id property="id" column="id" jdbcType="BIGINT"/>
<result property="name" column="name" jdbcType="VARCHAR"/>
<result property="categoryId" column="category_id" jdbcType="BIGINT"/>
<result property="brandId" column="brand_id" jdbcType="BIGINT"/>
<result property="originPrice" column="origin_price" jdbcType="BIGINT"/>
<result property="price" column="price" jdbcType="BIGINT"/>
<result property="sales" column="sales" jdbcType="INTEGER"/>
<result property="picUrl" column="pic_url" jdbcType="VARCHAR"/>
<result property="album" column="album" jdbcType="OTHER"/>
<result property="unit" column="unit" jdbcType="VARCHAR"/>
<result property="description" column="description" jdbcType="VARCHAR"/>
<result property="detail" column="detail" jdbcType="VARCHAR"/>
<result property="status" column="status" jdbcType="TINYINT"/>
<result property="gmtCreate" column="gmt_create" jdbcType="TIMESTAMP"/>
<result property="gmtModified" column="gmt_modified" jdbcType="TIMESTAMP"/>
<collection property="skuList" ofType="string" javaType="list">
<result column="roleCode"></result>
<id property="id" column="id" jdbcType="BIGINT"/>
<result property="name" column="name" jdbcType="VARCHAR"/>
<result property="categoryId" column="category_id" jdbcType="BIGINT"/>
<result property="brandId" column="brand_id" jdbcType="BIGINT"/>
<result property="originPrice" column="origin_price" jdbcType="BIGINT"/>
<result property="price" column="price" jdbcType="BIGINT"/>
<result property="sales" column="sales" jdbcType="INTEGER"/>
<result property="picUrl" column="pic_url" jdbcType="VARCHAR"/>
<result property="album" column="album" jdbcType="OTHER"/>
<result property="unit" column="unit" jdbcType="VARCHAR"/>
<result property="description" column="description" jdbcType="VARCHAR"/>
<result property="detail" column="detail" jdbcType="VARCHAR"/>
<result property="status" column="status" jdbcType="TINYINT"/>
<result property="gmtCreate" column="gmt_create" jdbcType="TIMESTAMP"/>
<result property="gmtModified" column="gmt_modified" jdbcType="TIMESTAMP"/>
<result property="categoryName" column="categoryName" jdbcType="VARCHAR"/>
<result property="brandName" column="brandName" jdbcType="VARCHAR"/>
<collection property="skuList" ofType="com.youlai.mall.pms.pojo.entity.PmsSku" javaType="list">
<id property="id" column="skuId" jdbcType="BIGINT"/>
<result property="name" column="skuName" jdbcType="VARCHAR"/>
<result property="sn" column="sn" jdbcType="VARCHAR"/>
<result property="picUrl" column="skuPicUrl" jdbcType="VARCHAR"/>
<result property="specifications" column="specifications" jdbcType="VARCHAR"/>
<result property="originPrice" column="skuOriginPrice" jdbcType="BIGINT"/>
<result property="price" column="skuPrice" jdbcType="BIGINT"/>
<result property="stock" column="stock" jdbcType="INTEGER"/>
<result property="lockedStock" column="locked_stock" jdbcType="INTEGER"/>
</collection>
</resultMap>
<sql id="Base_Column_List">
id,name,category_id,
id
,name,category_id,
brand_id,origin_price,price,
sales,pic_url,album,
unit,description,detail,
status,gmt_create,gmt_modified
</sql>
<select id="list" resultType="com.youlai.mall.pms.pojo.entity.PmsSpu">
@Select("<script>" +
" SELECT " +
" t1.*," +
" t2.NAME AS category_name ," +
" t3.NAME AS brand_name " +
" FROM " +
" pms_spu t1" +
" LEFT JOIN pms_category t2 ON t1.category_id = t2.id " +
" LEFT JOIN pms_brand t3 ON t1.brand_id = t3.id " +
" WHERE 1=1 " +
" <if test ='spu.categoryId !=null and spu.categoryId > 0' >" +
" AND t2.id = #{spu.categoryId} " +
" </if>" +
" ORDER BY t1.gmt_create DESC" +
"</script>")
@Results({
@Result(id = true, column = "id", property = "id"),
@Result(property = "skus",column = "id",many = @Many(select="com.youlai.mall.pms.mapper.PmsSkuMapper.listBySpuId"))
})
<select id="list" resultMap="BaseResultMap">
SELECT t1.*,
t3.NAME categoryName,
t4.NAME brandName,
t2.id skuId,
t2.NAME skuName,
t2.sn,
t2.pic_url skuPicUrl,
t2.specifications,
t2.origin_price skuOriginPrice,
t2.price skuPrice,
t2.stock
FROM pms_spu t1
LEFT JOIN pms_sku t2 ON t1.id = t2.spu_id
LEFT JOIN pms_category t3 ON t1.category_id = t3.id
LEFT JOIN pms_brand t4 ON t1.brand_id = t4.id
WHERE 1 = 1
<if test="categoryId!=null">
AND t1.category_id =#{categoryId}
</if>
<if test='name!=null and name neq ""'>
AND t1.category_id =#{categoryId}
</if>
</select>
</mapper>

View File

@ -0,0 +1,26 @@
package com.youlai.mall.pms.service.impl;
import com.youlai.mall.pms.pojo.vo.admin.GoodsDetailVO;
import com.youlai.mall.pms.service.IPmsSpuService;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
/**
* @author <a href="mailto:xianrui0365@163.com">xianrui</a>
* @date 2021/7/17
*/
@SpringBootTest
@Slf4j
class PmsSpuServiceImplTest {
@Autowired
private IPmsSpuService iPmsSpuService;
@Test
void getGoodsById() {
GoodsDetailVO goodsDetail = iPmsSpuService.getGoodsById(1l);
log.info(goodsDetail.toString());
}
}

View File

@ -1,6 +1,6 @@
package com.youlai.mall.sms.pojo.to;
import com.youlai.mall.pms.pojo.dto.SkuDTO;
import com.youlai.mall.pms.pojo.dto.app.SkuDTO;
import lombok.Data;
import lombok.ToString;

View File

@ -1,6 +1,6 @@
package com.youlai.mall.sms.pojo.vo;
import com.youlai.mall.pms.pojo.dto.SkuDTO;
import com.youlai.mall.pms.pojo.dto.app.SkuDTO;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

View File

@ -24,17 +24,12 @@ public class SysMenu extends BaseEntity {
private String name;
private String icon;
/**
* 路由名称
*/
private String routeName;
private String iconUrl;
/**
* 路由路径
*/
private String routePath;
private String path;
private String component;

View File

@ -6,9 +6,8 @@ import lombok.Setter;
/**
* 权限类型
*
* @Author haoxr
* @Date 2021-02-05 10:10
* @Version 1.0.0
* @author xianrui
* @date 2021-02-05
*/
public enum PermTypeEnum {

View File

@ -20,7 +20,7 @@ import java.util.Arrays;
import java.util.List;
/**
* @author haoxr
* @author xianrui
* @date 2020-11-06
*/
@Api(tags = "菜单接口")

View File

@ -14,9 +14,8 @@ import org.springframework.web.bind.annotation.RestController;
import java.util.List;
/**
* @author haoxr
* @description TODO
* @createTime 2021/6/1 22:40
* @author xianrui
* @date 2021/6/1 22:40
*/
@Api(tags = "路由接口")
@RestController

View File

@ -20,8 +20,8 @@ import java.util.Optional;
/**
* @Author haoxr
* @Date 2020-11-06
* @author xianrui
* @date 2020-11-06
*/
@Service
public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> implements ISysMenuService {
@ -107,13 +107,13 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
RouteVO routeVO = new RouteVO();
routeVO.setName(menu.getId() + ""); // 根据name路由跳转 this.$router.push({path:xxx})
routeVO.setPath(menu.getRoutePath()); // 根据path路由跳转 this.$router.push({name:xxx})
routeVO.setPath(menu.getPath()); // 根据path路由跳转 this.$router.push({name:xxx})
routeVO.setRedirect(menu.getRedirect());
routeVO.setComponent(menu.getComponent());
routeVO.setRedirect(menu.getRedirect());
routeVO.setMeta(routeVO.new Meta(
menu.getName(),
menu.getIcon(),
menu.getIconUrl(),
menu.getRoles()
));
// 菜单显示隐藏

View File

@ -7,11 +7,10 @@
<id property="id" column="id" jdbcType="BIGINT"/>
<result property="name" column="name" jdbcType="VARCHAR"/>
<result property="parentId" column="parent_id" jdbcType="BIGINT"/>
<result property="routeName" column="route_name" jdbcType="VARCHAR"/>
<result property="routePath" column="route_path" jdbcType="VARCHAR"/>
<result property="path" column="path" jdbcType="VARCHAR"/>
<result property="component" column="component" jdbcType="VARCHAR"/>
<result property="redirect" column="redirect" jdbcType="VARCHAR"/>
<result property="icon" column="icon" jdbcType="VARCHAR"/>
<result property="iconUrl" column="icon_url" jdbcType="VARCHAR"/>
<result property="sort" column="sort" jdbcType="INTEGER"/>
<result property="visible" column="visible" jdbcType="BOOLEAN"/>
<result property="gmtCreate" column="gmt_create" jdbcType="TIMESTAMP"/>
@ -33,10 +32,9 @@
select t1.id,
t1.name,
t1.parent_id,
t1.route_name,
t1.route_path,
t1.path,
t1.component,
t1.icon,
t1.icon_url,
t1.sort,
t1.visible,
t1.redirect,