refactor:商品模块调整

This commit is contained in:
haoxr 2021-03-05 00:31:45 +08:00
parent a270b36d10
commit e7aa267818
39 changed files with 297 additions and 238 deletions

View File

@ -87,11 +87,11 @@ public class CartItemVo implements Serializable {
this.skuName = skuName;
}
public Integer getStock() {
public Integer getInventory() {
return stock;
}
public void setStock(Integer stock) {
public void setInventory(Integer stock) {
this.stock = stock;
}

View File

@ -72,7 +72,7 @@ public class CartServiceImpl implements CartService {
cartItem.setSkuImg(data.getPicUrl());
cartItem.setNumber(1);
cartItem.setPrice(data.getPrice());
cartItem.setStock(data.getStock());
cartItem.setInventory(data.getInventory());
});
//2远程查询商品属性

View File

@ -1,8 +1,8 @@
package com.youlai.mall.pms.bo.admin;
import com.youlai.mall.pms.pojo.domain.PmsSku;
import com.youlai.mall.pms.pojo.domain.PmsSpuAttrValue;
import com.youlai.mall.pms.pojo.domain.PmsSpuSpecValue;
import com.youlai.mall.pms.pojo.domain.PmsInventory;
import com.youlai.mall.pms.pojo.domain.PmsProductAttrValue;
import com.youlai.mall.pms.pojo.domain.PmsProductSpecValue;
import com.youlai.mall.pms.pojo.dto.SpuDTO;
import lombok.AllArgsConstructor;
import lombok.Data;
@ -17,10 +17,10 @@ public class ProductBO {
private SpuDTO spu;
private List<PmsSpuAttrValue> attrs;
private List<PmsProductAttrValue> attrs;
private List<PmsSpuSpecValue> specs;
private List<PmsProductSpecValue> specs;
private List<PmsSku> skuList;
private List<PmsInventory> skuList;
}

View File

@ -1,7 +1,7 @@
package com.youlai.mall.pms.bo.app;
import com.youlai.mall.pms.pojo.domain.PmsSku;
import com.youlai.mall.pms.pojo.domain.PmsSpuAttrValue;
import com.youlai.mall.pms.pojo.domain.PmsInventory;
import com.youlai.mall.pms.pojo.domain.PmsProductAttrValue;
import com.youlai.mall.pms.pojo.domain.PmsCategorySpec;
import com.youlai.mall.pms.pojo.dto.SpuDTO;
import lombok.AllArgsConstructor;
@ -17,10 +17,10 @@ public class ProductBO {
private SpuDTO spu;
private List<PmsSpuAttrValue> attrs;
private List<PmsProductAttrValue> attrs;
private List<PmsCategorySpec> specs;
private List<PmsSku> skuList;
private List<PmsInventory> skuList;
}

View File

@ -18,6 +18,6 @@ public class PmsCategorySpec extends BaseEntity {
private String name;
@TableField(exist = false)
private List<PmsSpuSpecValue> values = new ArrayList<>();
private List<PmsProductSpecValue> values = new ArrayList<>();
}

View File

@ -6,16 +6,17 @@ import com.youlai.common.base.BaseEntity;
import lombok.Data;
@Data
public class PmsSku extends BaseEntity {
public class PmsInventory extends BaseEntity {
@TableId(type = IdType.AUTO)
private Long id;
private Long spuId;
private Long productId;
private String name;
private String code;
private String picUrl;
private Long originPrice;
private Long price;
private Integer stock;
private Integer inventory;
private Integer lockInventory;
private String specValueIds;
}

View File

@ -18,7 +18,7 @@ import java.util.List;
@Data
@Accessors(chain = true)
@Document(indexName = "pms_spu", replicas = 1, shards = 1, createIndex = true)
public class PmsSpu extends BaseEntity {
public class PmsProduct extends BaseEntity {
@Id
@TableId(type = IdType.AUTO)
@ -43,5 +43,5 @@ public class PmsSpu extends BaseEntity {
private String brandName;
@TableField(exist = false)
private List<PmsSku> skuList;
private List<PmsInventory> skuList;
}

View File

@ -10,12 +10,12 @@ import lombok.Data;
* @date 2020-11-06
*/
@Data
public class PmsSpuAttrValue extends BaseEntity {
public class PmsProductAttrValue extends BaseEntity {
@TableId(type = IdType.AUTO)
private Long id;
private Long spuId;
private Long attrId;
private Long productId;
private Long categoryAttrId;
private String name;
private String value;

View File

@ -10,11 +10,11 @@ import lombok.Data;
* @date 2020-11-06
*/
@Data
public class PmsSpuSpecValue extends BaseEntity {
public class PmsProductSpecValue extends BaseEntity {
@TableId(type = IdType.INPUT)
private Long id;
private Long spuId;
private Long specId;
private Long productId;
private Long categorySpecId;
private String value;
}

View File

@ -1,4 +1,4 @@
package com.youlai.mall.pms.common;
package com.youlai.mall.pms.common.constant;
/**
* @author haoxr

View File

@ -0,0 +1,31 @@
package com.youlai.mall.pms.common.enums;
import lombok.Getter;
import lombok.Setter;
public enum InventoryOperationEnum {
PAGE("page" ), // 分页查询
LIST("list"), //列表查询
TREE("tree"),//树形列表
CASCADER("cascader"), // 级联列表 对应级联选择器的下拉格式数据
ROUTER("router") ;// 路由列表
@Getter
@Setter
private String code;
InventoryOperationEnum(String code) {
this.code=code;
}
public static InventoryOperationEnum getValue(String code){
for (InventoryOperationEnum value : values()) {
if (value.getCode().equals(code)) {
return value;
}
}
return PAGE;
}
}

View File

@ -2,9 +2,9 @@ package com.youlai.mall.pms.controller.admin;
import cn.hutool.core.bean.BeanUtil;
import com.youlai.common.result.Result;
import com.youlai.mall.pms.pojo.domain.PmsSku;
import com.youlai.mall.pms.pojo.domain.PmsInventory;
import com.youlai.mall.pms.pojo.dto.SkuDTO;
import com.youlai.mall.pms.service.IPmsSkuService;
import com.youlai.mall.pms.service.IPmsInventoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
@ -20,13 +20,13 @@ import org.springframework.web.bind.annotation.*;
@AllArgsConstructor
public class InventoryController {
private IPmsSkuService iPmsSkuService;
private IPmsInventoryService iPmsInventoryService;
@ApiOperation(value = "商品库存明细", httpMethod = "GET")
@ApiImplicitParam(name = "id", value = "商品SkuID", required = true, paramType = "path", dataType = "Long")
@GetMapping("/{id}")
public Result<SkuDTO> detail(@PathVariable Long id) {
PmsSku sku = iPmsSkuService.getById(id);
PmsInventory sku = iPmsInventoryService.getById(id);
SkuDTO skuDTO = new SkuDTO();
BeanUtil.copyProperties(sku, skuDTO);
return Result.success(skuDTO);
@ -40,8 +40,8 @@ public class InventoryController {
@PutMapping(value = "/{id}")
public Result update(
@PathVariable Long id,
@RequestBody PmsSku sku) {
boolean status = iPmsSkuService.updateById(sku);
@RequestBody PmsInventory sku) {
boolean status = iPmsInventoryService.updateById(sku);
return Result.judge(status);
}
@ -53,9 +53,9 @@ public class InventoryController {
})
@PutMapping("/{id}/stock")
public Result updateStock(@PathVariable Long id, @RequestParam Integer num) {
PmsSku sku = iPmsSkuService.getById(id);
sku.setStock(sku.getStock() + num);
boolean result = iPmsSkuService.updateById(sku);
PmsInventory sku = iPmsInventoryService.getById(id);
sku.setInventory(sku.getInventory() + num);
boolean result = iPmsInventoryService.updateById(sku);
return Result.judge(result);
}

View File

@ -7,8 +7,8 @@ import com.youlai.common.enums.QueryModeEnum;
import com.youlai.common.result.Result;
import com.youlai.common.result.ResultCode;
import com.youlai.mall.pms.bo.admin.ProductBO;
import com.youlai.mall.pms.pojo.domain.PmsSpu;
import com.youlai.mall.pms.service.IPmsSpuService;
import com.youlai.mall.pms.pojo.domain.PmsProduct;
import com.youlai.mall.pms.service.IPmsProductService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
@ -27,7 +27,7 @@ import java.util.stream.Collectors;
@AllArgsConstructor
public class ProductController {
private IPmsSpuService iPmsSpuService;
private IPmsProductService iPmsProductService;
@ApiOperation(value = "列表分页", httpMethod = "GET")
@ApiImplicitParams({
@ -48,9 +48,9 @@ public class ProductController {
QueryModeEnum queryModeEnum = QueryModeEnum.getValue(queryMode);
switch (queryModeEnum) {
case PAGE:
IPage<PmsSpu> result = iPmsSpuService.list(
IPage<PmsProduct> result = iPmsProductService.list(
new Page<>(page, limit),
new PmsSpu().setName(name).setCategoryId(categoryId)
new PmsProduct().setName(name).setCategoryId(categoryId)
);
return Result.success(result.getRecords(), result.getTotal());
default:
@ -62,7 +62,7 @@ public class ProductController {
@ApiImplicitParam(name = "id", value = "商品id", required = true, paramType = "path", dataType = "Long")
@GetMapping("/{id}")
public Result detail(@PathVariable Long id) {
ProductBO spu = iPmsSpuService.getBySpuId(id);
ProductBO spu = iPmsProductService.getBySpuId(id);
return Result.success(spu);
}
@ -71,7 +71,7 @@ public class ProductController {
@ApiImplicitParam(name = "spuBO", value = "实体JSON对象", required = true, paramType = "body", dataType = "PmsSpuBO")
@PostMapping
public Result add(@RequestBody ProductBO spuBO) {
boolean status = iPmsSpuService.add(spuBO);
boolean status = iPmsProductService.add(spuBO);
return Result.judge(status);
}
@ -84,7 +84,7 @@ public class ProductController {
public Result update(
@PathVariable Long id,
@RequestBody ProductBO spu) {
boolean status = iPmsSpuService.updateById(spu);
boolean status = iPmsProductService.updateById(spu);
return Result.judge(status);
}
@ -92,7 +92,7 @@ public class ProductController {
@ApiImplicitParam(name = "ids", value = "id集合,以英文逗号','分隔", required = true, paramType = "query", dataType = "String")
@DeleteMapping("/{ids}")
public Result delete(@PathVariable String ids) {
iPmsSpuService.removeBySpuIds(Arrays.asList(ids.split(",")).stream().map(id -> Long.parseLong(id)).collect(Collectors.toList()));
iPmsProductService.removeBySpuIds(Arrays.asList(ids.split(",")).stream().map(id -> Long.parseLong(id)).collect(Collectors.toList()));
return Result.success();
}
@ -102,10 +102,10 @@ public class ProductController {
@ApiImplicitParam(name = "spu", value = "实体JSON对象", required = true, paramType = "body", dataType = "PmsSpu")
})
@PatchMapping(value = "/{id}")
public Result patch(@PathVariable Integer id, @RequestBody PmsSpu spu) {
LambdaUpdateWrapper<PmsSpu> updateWrapper = new LambdaUpdateWrapper<PmsSpu>().eq(PmsSpu::getId, id);
updateWrapper.set(spu.getStatus() != null, PmsSpu::getStatus, spu.getStatus());
boolean update = iPmsSpuService.update(updateWrapper);
public Result patch(@PathVariable Integer id, @RequestBody PmsProduct spu) {
LambdaUpdateWrapper<PmsProduct> updateWrapper = new LambdaUpdateWrapper<PmsProduct>().eq(PmsProduct::getId, id);
updateWrapper.set(spu.getStatus() != null, PmsProduct::getStatus, spu.getStatus());
boolean update = iPmsProductService.update(updateWrapper);
return Result.success(update);
}
}

View File

@ -1,46 +1,71 @@
package com.youlai.mall.pms.controller.app;
import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.youlai.common.result.Result;
import com.youlai.mall.pms.pojo.domain.PmsSku;
import com.youlai.mall.pms.pojo.domain.PmsInventory;
import com.youlai.mall.pms.pojo.dto.SkuDTO;
import com.youlai.mall.pms.pojo.vo.SkuInfoVO;
import com.youlai.mall.pms.pojo.vo.WareSkuStockVO;
import com.youlai.mall.pms.service.IPmsSkuService;
import com.youlai.mall.pms.service.IPmsInventoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@Api(tags = "【移动端】商品库存")
@RestController("AppInventoryController")
@RequestMapping("/api.app/v1/inventories")
@AllArgsConstructor
public class InventoryController {
private IPmsSkuService iPmsSkuService;
private IPmsInventoryService iPmsInventoryService;
@ApiOperation(value = "商品库存详情", httpMethod = "GET")
@ApiImplicitParam(name = "id", value = "商品SkuId", required = true, paramType = "path", dataType = "Long")
@ApiImplicitParam(name = "id", value = "商品库存ID", required = true, paramType = "path", dataType = "Long")
@GetMapping("/{id}")
public Result<SkuDTO> detail(@PathVariable Long id) {
PmsSku sku = iPmsSkuService.getById(id);
PmsInventory sku = iPmsInventoryService.getById(id);
SkuDTO skuDTO = new SkuDTO();
BeanUtil.copyProperties(sku, skuDTO);
return Result.success(skuDTO);
}
@ApiImplicitParam(name = "id", value = "商品SkuId", required = true, paramType = "path", dataType = "Long")
@GetMapping("/{skuId}/inventory")
public Result<Integer> getInventoryBySkuId(@PathVariable Long skuId) {
Integer inventory = iPmsSkuService.getInventoryBySkuId(skuId);
@ApiImplicitParam(name = "id", value = "商品库存ID", required = true, paramType = "path", dataType = "Long")
@GetMapping("/{id}/inventory")
public Result<Integer> getInventoryById(@PathVariable Long id) {
Integer inventory = iPmsInventoryService.getInventoryById(id);
return Result.success(inventory);
}
@ApiOperation(value = "订单提交锁定库存", httpMethod = "POST")
@ApiImplicitParam(name = "skuStockVO", value = "订单库存信息", required = true, paramType = "body", dataType = "WareSkuStockVO")
@PostMapping("/batch/lock")
public Result<Boolean> lockStock(@RequestBody WareSkuStockVO skuStockVO) {
try {
iPmsInventoryService.lockStock(skuStockVO);
return Result.success();
} catch (Exception e) {
return Result.failed();
}
}
@ApiOperation(value = "订单取消释放库存", httpMethod = "POST")
@ApiImplicitParam(name = "skuStockVO", value = "订单库存信息", required = true, paramType = "body", dataType = "WareSkuStockVO")
@PostMapping("/stock/release")
public Result<Boolean> releaseStock(@RequestBody WareSkuStockVO skuStockVO) {
try {
iPmsInventoryService.releaseStock(skuStockVO);
return Result.success();
} catch (Exception e) {
return Result.failed();
}
}
}

View File

@ -4,8 +4,8 @@ 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.bo.app.ProductBO;
import com.youlai.mall.pms.pojo.domain.PmsSpu;
import com.youlai.mall.pms.service.IPmsSpuService;
import com.youlai.mall.pms.pojo.domain.PmsProduct;
import com.youlai.mall.pms.service.IPmsProductService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
@ -19,7 +19,7 @@ import org.springframework.web.bind.annotation.*;
@AllArgsConstructor
public class ProductController {
private IPmsSpuService iPmsSpuService;
private IPmsProductService iPmsProductService;
@ApiOperation(value = "列表分页", httpMethod = "GET")
@ApiImplicitParams({
@ -35,9 +35,9 @@ public class ProductController {
String name,
Long categoryId
) {
IPage<PmsSpu> result = iPmsSpuService.list(
IPage<PmsProduct> result = iPmsProductService.list(
new Page<>(page, limit),
new PmsSpu().setName(name).setCategoryId(categoryId)
new PmsProduct().setName(name).setCategoryId(categoryId)
);
return Result.success(result.getRecords(), result.getTotal());
}
@ -46,7 +46,7 @@ public class ProductController {
@ApiImplicitParam(name = "id", value = "商品id", required = true, paramType = "path", dataType = "Long")
@GetMapping("/{id}")
public Result<ProductBO> detail(@PathVariable Long id) {
ProductBO product = iPmsSpuService.getProductByIdForApp(id);
ProductBO product = iPmsProductService.getProductByIdForApp(id);
return Result.success(product);
}

View File

@ -2,17 +2,16 @@ package com.youlai.mall.pms.controller.app;
import cn.hutool.core.bean.BeanUtil;
import com.youlai.common.result.Result;
import com.youlai.mall.pms.pojo.domain.PmsSku;
import com.youlai.mall.pms.pojo.domain.PmsInventory;
import com.youlai.mall.pms.pojo.dto.SkuDTO;
import com.youlai.mall.pms.pojo.vo.SkuInfoVO;
import com.youlai.mall.pms.pojo.vo.WareSkuStockVO;
import com.youlai.mall.pms.service.IPmsSkuService;
import com.youlai.mall.pms.service.IPmsInventoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@ -23,14 +22,14 @@ import java.util.List;
@AllArgsConstructor
public class SkuController {
private IPmsSkuService iPmsSkuService;
private IPmsInventoryService iPmsInventoryService;
@ApiOperation(value = "商品sku详情", httpMethod = "GET")
@ApiImplicitParam(name = "id", value = "商品sku id", required = true, paramType = "path", dataType = "Long")
@GetMapping("/{id}")
public Result<SkuDTO> detail(@PathVariable Long id) {
PmsSku sku = iPmsSkuService.getById(id);
PmsInventory sku = iPmsInventoryService.getById(id);
SkuDTO skuDTO = new SkuDTO();
BeanUtil.copyProperties(sku, skuDTO);
return Result.success(skuDTO);
@ -44,9 +43,9 @@ public class SkuController {
})
@PutMapping("/{id}/stock")
public Result updateStock(@PathVariable Long id, @RequestParam Integer num) {
PmsSku sku = iPmsSkuService.getById(id);
sku.setStock(sku.getStock() + num);
boolean result = iPmsSkuService.updateById(sku);
PmsInventory sku = iPmsInventoryService.getById(id);
sku.setInventory(sku.getInventory() + num);
boolean result = iPmsInventoryService.updateById(sku);
return Result.judge(result);
}
@ -54,7 +53,7 @@ public class SkuController {
@ApiImplicitParam(name = "skuIds", value = "Sku ID 集合", required = true, paramType = "param", dataType = "List")
@GetMapping("/infos")
public Result<List<SkuInfoVO>> infos(@RequestParam("skuId") List<String> skuIds) {
List<SkuInfoVO> infos = iPmsSkuService.getSkuInfoByIds(skuIds);
List<SkuInfoVO> infos = iPmsInventoryService.getSkuInfoByIds(skuIds);
return Result.success(infos);
}
@ -65,7 +64,7 @@ public class SkuController {
public Result<Boolean> lockStock(@RequestBody WareSkuStockVO skuStockVO) {
try {
iPmsSkuService.lockStock(skuStockVO);
iPmsInventoryService.lockStock(skuStockVO);
return Result.success();
} catch (Exception e) {
return Result.failed();
@ -78,7 +77,7 @@ public class SkuController {
public Result<Boolean> releaseStock(@RequestBody WareSkuStockVO skuStockVO) {
try {
iPmsSkuService.releaseStock(skuStockVO);
iPmsInventoryService.releaseStock(skuStockVO);
return Result.success();
} catch (Exception e) {
return Result.failed();

View File

@ -1,7 +1,7 @@
package com.youlai.mall.pms.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.youlai.mall.pms.pojo.domain.PmsSku;
import com.youlai.mall.pms.pojo.domain.PmsInventory;
import com.youlai.mall.pms.pojo.vo.SkuInfoVO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
@ -10,12 +10,12 @@ import org.apache.ibatis.annotations.Mapper;
import java.util.List;
@Mapper
public interface PmsSkuMapper extends BaseMapper<PmsSku> {
public interface PmsInventoryMapper extends BaseMapper<PmsInventory> {
@Select("<script>" +
" select * from pms_sku where spu_id=#{spuId} " +
"</script>")
List<PmsSku> listBySpuId(Long spuId);
List<PmsInventory> listBySpuId(Long spuId);
/**
* 批量获取商品详情
@ -30,6 +30,8 @@ public interface PmsSkuMapper extends BaseMapper<PmsSku> {
* @param number 涉及商品数量
* @return
*/
Long lockStock(@Param("skuId") Long skuId, @Param("number") Integer number);
/**

View File

@ -1,7 +1,7 @@
package com.youlai.mall.pms.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.youlai.mall.pms.pojo.domain.PmsSpuAttrValue;
import com.youlai.mall.pms.pojo.domain.PmsProductAttrValue;
import org.apache.ibatis.annotations.Mapper;
/**
@ -9,6 +9,6 @@ import org.apache.ibatis.annotations.Mapper;
* @date 2020-11-06
*/
@Mapper
public interface PmsSpuAttrValueMapper extends BaseMapper<PmsSpuAttrValue> {
public interface PmsProductAttrValueMapper extends BaseMapper<PmsProductAttrValue> {
}

View File

@ -2,7 +2,7 @@ package com.youlai.mall.pms.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.youlai.mall.pms.pojo.domain.PmsSpu;
import com.youlai.mall.pms.pojo.domain.PmsProduct;
import org.apache.ibatis.annotations.Many;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
@ -16,7 +16,7 @@ import java.util.List;
* @date 2020-11-06
*/
@Mapper
public interface PmsSpuMapper extends BaseMapper<PmsSpu> {
public interface PmsProductMapper extends BaseMapper<PmsProduct> {
@Select("<script>" +
" SELECT " +
@ -37,5 +37,5 @@ public interface PmsSpuMapper extends BaseMapper<PmsSpu> {
@Result(id = true, column = "id", property = "id"),
@Result(property = "skuList",column = "id",many = @Many(select="com.youlai.mall.pms.mapper.PmsSkuMapper.listBySpuId"))
})
List<PmsSpu> list(Page<PmsSpu> page, PmsSpu spu);
List<PmsProduct> list(Page<PmsProduct> page, PmsProduct spu);
}

View File

@ -1,7 +1,7 @@
package com.youlai.mall.pms.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.youlai.mall.pms.pojo.domain.PmsSpuSpecValue;
import com.youlai.mall.pms.pojo.domain.PmsProductSpecValue;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Mapper;
@ -13,7 +13,7 @@ import java.util.Map;
* @date 2020-11-06
*/
@Mapper
public interface PmsSpuSpecValueMapper extends BaseMapper<PmsSpuSpecValue> {
public interface PmsProductSpecValueMapper extends BaseMapper<PmsProductSpecValue> {
@Select("<script>" +
@ -28,6 +28,6 @@ public interface PmsSpuSpecValueMapper extends BaseMapper<PmsSpuSpecValue> {
" spu_id = #{spuId} " +
" AND spec_id = #{specId} " +
"</script>")
List<PmsSpuSpecValue> listBySpuIdAndSpecId(Map<String, String> param);
List<PmsProductSpecValue> listBySpuIdAndSpecId(Map<String, String> param);
}

View File

@ -1,13 +1,13 @@
package com.youlai.mall.pms.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.youlai.mall.pms.pojo.domain.PmsSku;
import com.youlai.mall.pms.pojo.domain.PmsInventory;
import com.youlai.mall.pms.pojo.vo.SkuInfoVO;
import com.youlai.mall.pms.pojo.vo.WareSkuStockVO;
import java.util.List;
public interface IPmsSkuService extends IService<PmsSku> {
public interface IPmsInventoryService extends IService<PmsInventory> {
/**
* 批量获取商品详情
@ -33,8 +33,8 @@ public interface IPmsSkuService extends IService<PmsSku> {
/**
* 获取商品库存
* @param skuId
* @param id 库存ID
* @return
*/
Integer getInventoryBySkuId(Long skuId);
Integer getInventoryById(Long id);
}

View File

@ -0,0 +1,10 @@
package com.youlai.mall.pms.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.youlai.mall.pms.pojo.domain.PmsProductAttrValue;
public interface IPmsProductAttrValueService extends IService<PmsProductAttrValue> {
}

View File

@ -4,13 +4,13 @@ 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.bo.app.ProductBO;
import com.youlai.mall.pms.pojo.domain.PmsSpu;
import com.youlai.mall.pms.pojo.domain.PmsProduct;
import java.util.List;
public interface IPmsSpuService extends IService<PmsSpu> {
public interface IPmsProductService extends IService<PmsProduct> {
IPage<PmsSpu> list(Page<PmsSpu> page, PmsSpu spu);
IPage<PmsProduct> list(Page<PmsProduct> page, PmsProduct spu);
boolean add(com.youlai.mall.pms.bo.admin.ProductBO spuBO);

View File

@ -0,0 +1,9 @@
package com.youlai.mall.pms.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.youlai.mall.pms.pojo.domain.PmsProductSpecValue;
public interface IPmsProductSpecValueService extends IService<PmsProductSpecValue> {
}

View File

@ -1,10 +0,0 @@
package com.youlai.mall.pms.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.youlai.mall.pms.pojo.domain.PmsSpuAttrValue;
public interface IPmsSpuAttrValueService extends IService<PmsSpuAttrValue> {
}

View File

@ -1,9 +0,0 @@
package com.youlai.mall.pms.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.youlai.mall.pms.pojo.domain.PmsSpuSpecValue;
public interface IPmsSpuSpecValueService extends IService<PmsSpuSpecValue> {
}

View File

@ -4,13 +4,13 @@ import cn.hutool.core.convert.Convert;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.youlai.common.web.exception.BizException;
import com.youlai.mall.pms.common.RedisConstants;
import com.youlai.mall.pms.mapper.PmsSkuMapper;
import com.youlai.mall.pms.pojo.domain.PmsSku;
import com.youlai.mall.pms.common.constant.RedisConstants;
import com.youlai.mall.pms.mapper.PmsInventoryMapper;
import com.youlai.mall.pms.pojo.domain.PmsInventory;
import com.youlai.mall.pms.pojo.vo.SkuInfoVO;
import com.youlai.mall.pms.pojo.vo.SkuStockVO;
import com.youlai.mall.pms.pojo.vo.WareSkuStockVO;
import com.youlai.mall.pms.service.IPmsSkuService;
import com.youlai.mall.pms.service.IPmsInventoryService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.RedisTemplate;
@ -22,7 +22,7 @@ import java.util.List;
@Service
@Slf4j
@AllArgsConstructor
public class PmsSkuServiceImpl extends ServiceImpl<PmsSkuMapper, PmsSku> implements IPmsSkuService {
public class PmsInventoryServiceImpl extends ServiceImpl<PmsInventoryMapper, PmsInventory> implements IPmsInventoryService {
private RedisTemplate redisTemplate;
@ -65,28 +65,28 @@ public class PmsSkuServiceImpl extends ServiceImpl<PmsSkuMapper, PmsSku> impleme
* Cache-Aside pattern 缓存数据库读写模式
* 1. 读取数据先读缓存没有就去读数据库然后将结果写入缓存
* 2. 写入数据先更新数据库再删除缓存
* @param skuId
* @param id 库存ID
* @return
*/
@Override
public Integer getInventoryBySkuId(Long skuId) {
public Integer getInventoryById(Long id) {
Integer inventory = 0;
// ->缓存
Object cacheVal = redisTemplate.opsForValue().get(RedisConstants.PRODUCT_INVENTORY_PREFIX + skuId);
Object cacheVal = redisTemplate.opsForValue().get(RedisConstants.PRODUCT_INVENTORY_PREFIX + id);
if (cacheVal != null) {
inventory = Convert.toInt(cacheVal);
return inventory;
}
// ->数据库
PmsSku pmsInventory = this.getOne(new LambdaQueryWrapper<PmsSku>()
.eq(PmsSku::getId, skuId)
.select(PmsSku::getStock));
PmsInventory pmsInventory = this.getOne(new LambdaQueryWrapper<PmsInventory>()
.eq(PmsInventory::getId, id)
.select(PmsInventory::getInventory));
if (pmsInventory != null) {
inventory = pmsInventory.getStock();
inventory = pmsInventory.getInventory();
// ->缓存
redisTemplate.opsForValue().set(RedisConstants.PRODUCT_INVENTORY_PREFIX + skuId, inventory);
redisTemplate.opsForValue().set(RedisConstants.PRODUCT_INVENTORY_PREFIX + id, inventory);
}
return inventory;

View File

@ -0,0 +1,17 @@
package com.youlai.mall.pms.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.youlai.mall.pms.pojo.domain.PmsProductAttrValue;
import com.youlai.mall.pms.mapper.PmsProductAttrValueMapper;
import com.youlai.mall.pms.service.IPmsProductAttrValueService;
import org.springframework.stereotype.Service;
/**
* @author haoxr
* @date 2020-12-12
*/
@Service
public class PmsProductAttrValueServiceImpl extends ServiceImpl<PmsProductAttrValueMapper, PmsProductAttrValue> implements IPmsProductAttrValueService {
}

View File

@ -8,7 +8,7 @@ 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.bo.app.ProductBO;
import com.youlai.mall.pms.mapper.PmsSpuMapper;
import com.youlai.mall.pms.mapper.PmsProductMapper;
import com.youlai.mall.pms.pojo.domain.*;
import com.youlai.mall.pms.pojo.dto.SpuDTO;
import com.youlai.mall.pms.service.*;
@ -26,17 +26,17 @@ import java.util.stream.Collectors;
*/
@Service
@AllArgsConstructor
public class PmsSpuServiceImpl extends ServiceImpl<PmsSpuMapper, PmsSpu> implements IPmsSpuService {
public class PmsProductServiceImpl extends ServiceImpl<PmsProductMapper, PmsProduct> implements IPmsProductService {
private IPmsSkuService iPmsSkuService;
private IPmsSpuAttrValueService iPmsSpuAttrValueService;
private IPmsSpuSpecValueService iPmsSpuSpecValueService;
private IPmsInventoryService iPmsInventoryService;
private IPmsProductAttrValueService iPmsProductAttrValueService;
private IPmsProductSpecValueService iPmsProductSpecValueService;
private IPmsCategorySpecService iPmsCategorySpecService;
@Override
public IPage<PmsSpu> list(Page<PmsSpu> page, PmsSpu spu) {
List<PmsSpu> list = this.baseMapper.list(page, spu);
public IPage<PmsProduct> list(Page<PmsProduct> page, PmsProduct spu) {
List<PmsProduct> list = this.baseMapper.list(page, spu);
page.setRecords(list);
return page;
}
@ -45,12 +45,12 @@ public class PmsSpuServiceImpl extends ServiceImpl<PmsSpuMapper, PmsSpu> impleme
@Transactional
public boolean add(com.youlai.mall.pms.bo.admin.ProductBO spuBO) {
SpuDTO spuDTO = spuBO.getSpu();
List<PmsSpuAttrValue> attrs = spuBO.getAttrs();
List<PmsSpuSpecValue> specs = spuBO.getSpecs();
List<PmsSku> skuList = spuBO.getSkuList();
List<PmsProductAttrValue> attrs = spuBO.getAttrs();
List<PmsProductSpecValue> specs = spuBO.getSpecs();
List<PmsInventory> skuList = spuBO.getSkuList();
// spu保存
PmsSpu spu = new PmsSpu();
PmsProduct spu = new PmsProduct();
BeanUtil.copyProperties(spuDTO, spu);
if (spuDTO.getPicUrls() != null) {
String picUrls = JSONUtil.toJsonStr(spuDTO.getPicUrls());
@ -60,20 +60,20 @@ public class PmsSpuServiceImpl extends ServiceImpl<PmsSpuMapper, PmsSpu> impleme
// 属性保存
Optional.ofNullable(attrs).ifPresent(list -> {
list.forEach(item -> item.setSpuId(spu.getId()));
iPmsSpuAttrValueService.saveBatch(list);
list.forEach(item -> item.setProductId(spu.getId()));
iPmsProductAttrValueService.saveBatch(list);
});
// 规格保存
Optional.ofNullable(specs).ifPresent(list -> {
list.forEach(item -> item.setSpuId(spu.getId()));
iPmsSpuSpecValueService.saveBatch(list);
list.forEach(item -> item.setProductId(spu.getId()));
iPmsProductSpecValueService.saveBatch(list);
});
// sku保存
Optional.ofNullable(skuList).ifPresent(list -> {
list.forEach(item -> item.setSpuId(spu.getId()));
iPmsSkuService.saveBatch(skuList);
list.forEach(item -> item.setProductId(spu.getId()));
iPmsInventoryService.saveBatch(skuList);
});
return true;
@ -83,7 +83,7 @@ public class PmsSpuServiceImpl extends ServiceImpl<PmsSpuMapper, PmsSpu> impleme
public com.youlai.mall.pms.bo.admin.ProductBO getBySpuId(Long id) {
// spu
SpuDTO spuDTO = new SpuDTO();
PmsSpu spu = this.getById(id);
PmsProduct spu = this.getById(id);
BeanUtil.copyProperties(spu, spuDTO);
if (StrUtil.isNotBlank(spu.getPicUrls())) {
@ -93,12 +93,12 @@ public class PmsSpuServiceImpl extends ServiceImpl<PmsSpuMapper, PmsSpu> impleme
}
// 属性
List<PmsSpuAttrValue> attrs = iPmsSpuAttrValueService.
list(new LambdaQueryWrapper<PmsSpuAttrValue>().eq(PmsSpuAttrValue::getSpuId, id));
List<PmsProductAttrValue> attrs = iPmsProductAttrValueService.
list(new LambdaQueryWrapper<PmsProductAttrValue>().eq(PmsProductAttrValue::getProductId, id));
// 规格
List<PmsSpuSpecValue> specs = iPmsSpuSpecValueService.list(new LambdaQueryWrapper<PmsSpuSpecValue>().eq(PmsSpuSpecValue::getSpuId, id));
List<PmsProductSpecValue> specs = iPmsProductSpecValueService.list(new LambdaQueryWrapper<PmsProductSpecValue>().eq(PmsProductSpecValue::getProductId, id));
// sku
List<PmsSku> skuList = iPmsSkuService.list(new LambdaQueryWrapper<PmsSku>().eq(PmsSku::getSpuId, id));
List<PmsInventory> skuList = iPmsInventoryService.list(new LambdaQueryWrapper<PmsInventory>().eq(PmsInventory::getProductId, id));
// 组合
com.youlai.mall.pms.bo.admin.ProductBO spuBO = new com.youlai.mall.pms.bo.admin.ProductBO(spuDTO, attrs, specs, skuList);
@ -110,12 +110,12 @@ public class PmsSpuServiceImpl extends ServiceImpl<PmsSpuMapper, PmsSpu> impleme
public boolean updateById(com.youlai.mall.pms.bo.admin.ProductBO spuBO) {
SpuDTO spuDTO = spuBO.getSpu();
List<PmsSpuAttrValue> attrs = spuBO.getAttrs();
List<PmsSpuSpecValue> specs = spuBO.getSpecs();
List<PmsSku> skuList = spuBO.getSkuList();
List<PmsProductAttrValue> attrs = spuBO.getAttrs();
List<PmsProductSpecValue> specs = spuBO.getSpecs();
List<PmsInventory> skuList = spuBO.getSkuList();
// spu保存
PmsSpu spu = new PmsSpu();
PmsProduct spu = new PmsProduct();
BeanUtil.copyProperties(spuDTO, spu);
if (spuDTO.getPicUrls() != null) {
String picUrls = JSONUtil.toJsonStr(spuDTO.getPicUrls());
@ -125,53 +125,53 @@ public class PmsSpuServiceImpl extends ServiceImpl<PmsSpuMapper, PmsSpu> impleme
// 属性保存
Optional.ofNullable(attrs).ifPresent(list -> {
list.forEach(item -> item.setSpuId(spu.getId()));
list.forEach(item -> item.setProductId(spu.getId()));
// 删除此次保存删除的
List<Long> ids = list.stream().map(item -> item.getId()).collect(Collectors.toList());
List<Long> dbIds = iPmsSpuAttrValueService.list(new LambdaQueryWrapper<PmsSpuAttrValue>().eq(PmsSpuAttrValue::getSpuId, spu.getId())
.select(PmsSpuAttrValue::getId))
List<Long> dbIds = iPmsProductAttrValueService.list(new LambdaQueryWrapper<PmsProductAttrValue>().eq(PmsProductAttrValue::getProductId, spu.getId())
.select(PmsProductAttrValue::getId))
.stream()
.map(item -> item.getId())
.collect(Collectors.toList());
List<Long> removeIds = dbIds.stream().filter(id -> !ids.contains(id)).collect(Collectors.toList());
iPmsSpuAttrValueService.removeByIds(removeIds);
iPmsProductAttrValueService.removeByIds(removeIds);
iPmsSpuAttrValueService.saveOrUpdateBatch(list);
iPmsProductAttrValueService.saveOrUpdateBatch(list);
});
// 规格保存
Optional.ofNullable(specs).ifPresent(list -> {
list.forEach(item -> item.setSpuId(spu.getId()));
list.forEach(item -> item.setProductId(spu.getId()));
// 删除此次保存删除的
List<Long> ids = list.stream().map(item -> item.getId()).collect(Collectors.toList());
List<Long> dbIds = iPmsSpuSpecValueService.list(new LambdaQueryWrapper<PmsSpuSpecValue>().eq(PmsSpuSpecValue::getSpuId, spu.getId())
.select(PmsSpuSpecValue::getId))
List<Long> dbIds = iPmsProductSpecValueService.list(new LambdaQueryWrapper<PmsProductSpecValue>().eq(PmsProductSpecValue::getProductId, spu.getId())
.select(PmsProductSpecValue::getId))
.stream()
.map(item -> item.getId())
.collect(Collectors.toList());
List<Long> removeIds = dbIds.stream().filter(id -> !ids.contains(id)).collect(Collectors.toList());
iPmsSpuSpecValueService.removeByIds(removeIds);
iPmsProductSpecValueService.removeByIds(removeIds);
iPmsSpuSpecValueService.saveOrUpdateBatch(list);
iPmsProductSpecValueService.saveOrUpdateBatch(list);
});
// sku保存
Optional.ofNullable(skuList).ifPresent(list -> {
list.forEach(item -> item.setSpuId(spu.getId()));
list.forEach(item -> item.setProductId(spu.getId()));
// 删除此次保存删除的
List<Long> ids = list.stream().map(item -> item.getId()).collect(Collectors.toList());
List<Long> dbIds = iPmsSkuService.list(new LambdaQueryWrapper<PmsSku>().eq(PmsSku::getSpuId, spu.getId())
.select(PmsSku::getId))
List<Long> dbIds = iPmsInventoryService.list(new LambdaQueryWrapper<PmsInventory>().eq(PmsInventory::getProductId, spu.getId())
.select(PmsInventory::getId))
.stream()
.map(item -> item.getId())
.collect(Collectors.toList());
List<Long> removeIds = dbIds.stream().filter(id -> !ids.contains(id)).collect(Collectors.toList());
iPmsSkuService.removeByIds(removeIds);
iPmsInventoryService.removeByIds(removeIds);
iPmsSkuService.saveOrUpdateBatch(skuList);
iPmsInventoryService.saveOrUpdateBatch(skuList);
});
return true;
}
@ -181,11 +181,11 @@ public class PmsSpuServiceImpl extends ServiceImpl<PmsSpuMapper, PmsSpu> impleme
Optional.ofNullable(spuIds).ifPresent(
ids -> ids.forEach(spuId -> {
// sku
iPmsSkuService.remove(new LambdaQueryWrapper<PmsSku>().eq(PmsSku::getSpuId, spuId));
iPmsInventoryService.remove(new LambdaQueryWrapper<PmsInventory>().eq(PmsInventory::getProductId, spuId));
// 规格
iPmsSpuSpecValueService.remove(new LambdaQueryWrapper<PmsSpuSpecValue>().eq(PmsSpuSpecValue::getId, spuId));
iPmsProductSpecValueService.remove(new LambdaQueryWrapper<PmsProductSpecValue>().eq(PmsProductSpecValue::getId, spuId));
// 属性
iPmsSpuAttrValueService.remove(new LambdaQueryWrapper<PmsSpuAttrValue>().eq(PmsSpuAttrValue::getSpuId, spuId));
iPmsProductAttrValueService.remove(new LambdaQueryWrapper<PmsProductAttrValue>().eq(PmsProductAttrValue::getProductId, spuId));
// spu
this.removeById(spuId);
})
@ -196,7 +196,7 @@ public class PmsSpuServiceImpl extends ServiceImpl<PmsSpuMapper, PmsSpu> impleme
@Override
public ProductBO getProductByIdForApp(Long spuId) {
// spu
PmsSpu spu = this.getById(spuId);
PmsProduct spu = this.getById(spuId);
SpuDTO spuDTO = new SpuDTO();
BeanUtil.copyProperties(spu, spuDTO);
if (StrUtil.isNotBlank(spu.getPicUrls())) {
@ -205,16 +205,16 @@ public class PmsSpuServiceImpl extends ServiceImpl<PmsSpuMapper, PmsSpu> impleme
spuDTO.setPicUrls(pics);
}
// 属性
List<PmsSpuAttrValue> attrs = iPmsSpuAttrValueService.list(
new LambdaQueryWrapper<PmsSpuAttrValue>(
).eq(PmsSpuAttrValue::getSpuId, spuId)
List<PmsProductAttrValue> attrs = iPmsProductAttrValueService.list(
new LambdaQueryWrapper<PmsProductAttrValue>(
).eq(PmsProductAttrValue::getProductId, spuId)
);
// 规格
List<PmsCategorySpec> specs = iPmsCategorySpecService.listBySpuId(spuId);
// sku
List<PmsSku> skuList = iPmsSkuService.list(new LambdaQueryWrapper<PmsSku>().eq(PmsSku::getSpuId, spuId));
List<PmsInventory> skuList = iPmsInventoryService.list(new LambdaQueryWrapper<PmsInventory>().eq(PmsInventory::getProductId, spuId));
ProductBO product = new ProductBO(spuDTO, attrs, specs, skuList);
return product;

View File

@ -0,0 +1,16 @@
package com.youlai.mall.pms.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.youlai.mall.pms.pojo.domain.PmsProductSpecValue;
import com.youlai.mall.pms.mapper.PmsProductSpecValueMapper;
import com.youlai.mall.pms.service.IPmsProductSpecValueService;
import org.springframework.stereotype.Service;
/**
* @author haoxr
* @date 2020-11-06
*/
@Service
public class PmsProductSpecValueServiceImpl extends ServiceImpl<PmsProductSpecValueMapper, PmsProductSpecValue> implements IPmsProductSpecValueService {
}

View File

@ -1,17 +0,0 @@
package com.youlai.mall.pms.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.youlai.mall.pms.pojo.domain.PmsSpuAttrValue;
import com.youlai.mall.pms.mapper.PmsSpuAttrValueMapper;
import com.youlai.mall.pms.service.IPmsSpuAttrValueService;
import org.springframework.stereotype.Service;
/**
* @author haoxr
* @date 2020-12-12
*/
@Service
public class PmsSpuAttrValueServiceImpl extends ServiceImpl<PmsSpuAttrValueMapper, PmsSpuAttrValue> implements IPmsSpuAttrValueService {
}

View File

@ -1,16 +0,0 @@
package com.youlai.mall.pms.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.youlai.mall.pms.pojo.domain.PmsSpuSpecValue;
import com.youlai.mall.pms.mapper.PmsSpuSpecValueMapper;
import com.youlai.mall.pms.service.IPmsSpuSpecValueService;
import org.springframework.stereotype.Service;
/**
* @author haoxr
* @date 2020-11-06
*/
@Service
public class PmsSpuSpecValueServiceImpl extends ServiceImpl<PmsSpuSpecValueMapper, PmsSpuSpecValue> implements IPmsSpuSpecValueService {
}

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.youlai.mall.pms.mapper.PmsSkuMapper">
<mapper namespace="com.youlai.mall.pms.mapper.PmsInventoryMapper">
<update id="lockStock">
update pms_sku
@ -45,4 +45,4 @@
</foreach>
</where>
</select>
</mapper>
</mapper>

View File

@ -4,9 +4,9 @@ import com.youlai.common.result.ResultCode;
import com.youlai.mall.pms.bo.app.ProductBO;
import com.youlai.mall.pms.controller.admin.ProductController;
import com.youlai.mall.pms.pojo.domain.PmsCategorySpec;
import com.youlai.mall.pms.service.IPmsSpuAttrValueService;
import com.youlai.mall.pms.service.IPmsProductAttrValueService;
import com.youlai.mall.pms.service.IPmsCategorySpecService;
import com.youlai.mall.pms.service.IPmsSpuService;
import com.youlai.mall.pms.service.IPmsProductService;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
@ -60,16 +60,16 @@ public class ProductControllerTest {
}
@Autowired
public IPmsSpuAttrValueService iPmsSpuAttrValueService;
public IPmsProductAttrValueService iPmsProductAttrValueService;
@Autowired
private IPmsSpuService iPmsSpuService;
private IPmsProductService iPmsProductService;
@Test
public void getProduct() {
ProductBO product = iPmsSpuService.getProductByIdForApp(1l);
ProductBO product = iPmsProductService.getProductByIdForApp(1l);
log.info(product.toString());
}
}

View File

@ -1,6 +1,6 @@
package com.youlai.mall.pms.search.service;
import com.youlai.mall.pms.pojo.domain.PmsSpu;
import com.youlai.mall.pms.pojo.domain.PmsProduct;
import java.io.IOException;
import java.util.List;
@ -13,7 +13,7 @@ public interface IPmsSearchService {
* @return
* @throws IOException
*/
PmsSpu searchSpuById(String id) throws IOException;
PmsProduct searchSpuById(String id) throws IOException;
/**
* 根据商品名称关键字搜索商品
@ -21,5 +21,5 @@ public interface IPmsSearchService {
* @param key 商品名称关键字
* @return SKU商品集合
*/
List<PmsSpu> searchSpuByKey(String key) throws IOException;
List<PmsProduct> searchSpuByKey(String key) throws IOException;
}

View File

@ -1,6 +1,6 @@
package com.youlai.mall.pms.search.service.impl;
import com.youlai.mall.pms.pojo.domain.PmsSpu;
import com.youlai.mall.pms.pojo.domain.PmsProduct;
import com.youlai.mall.pms.search.service.IPmsSearchService;
import com.youlai.mall.pms.search.utils.ElasticsearchConvertUtils;
import com.youlai.mall.pms.search.utils.ElasticsearchUtils;
@ -24,17 +24,17 @@ public class PmsSearchServiceImpl implements IPmsSearchService {
private ElasticsearchUtils elasticsearchUtils;
@Override
public PmsSpu searchSpuById(String id) throws IOException {
public PmsProduct searchSpuById(String id) throws IOException {
log.info("根据文档id查询商品信息,id:{}", id);
return elasticsearchUtils.findById(PMS_SPU, id, PmsSpu.class);
return elasticsearchUtils.findById(PMS_SPU, id, PmsProduct.class);
}
@Override
public List<PmsSpu> searchSpuByKey(String key) throws IOException {
public List<PmsProduct> searchSpuByKey(String key) throws IOException {
log.info("根据商品名称查询商品信息,name:{}", key);
SearchSourceBuilder builder = new SearchSourceBuilder();
builder.query(QueryBuilders.matchQuery("name", key));
SearchHits<PmsSpu> searchHits = elasticsearchUtils.search(PMS_SPU, PmsSpu.class, builder.query());
SearchHits<PmsProduct> searchHits = elasticsearchUtils.search(PMS_SPU, PmsProduct.class, builder.query());
return ElasticsearchConvertUtils.searchHitsConvertDataList(searchHits);
}
}

View File

@ -5,7 +5,7 @@ import lombok.Setter;
/**
* @author haoxr
* @date 2021-02-17 13:13
* @date 2021-02-17
*/
public enum BusinessTypeEnum {

View File

@ -5,17 +5,17 @@ import lombok.Setter;
public enum QueryModeEnum {
PAGE("page", "分页查询"),
LIST("list","列表查询"),
TREE("tree","树形列表"),
CASCADER("cascader","级联列表"), // 对应级联选择器的下拉格式数据
ROUTER("router","路由列表") ;
PAGE("page" ), // 分页查询
LIST("list"), //列表查询
TREE("tree"),//树形列表
CASCADER("cascader"), // 级联列表 对应级联选择器的下拉格式数据
ROUTER("router") ;// 路由列表
@Getter
@Setter
private String code;
QueryModeEnum(String code, String desc) {
QueryModeEnum(String code) {
this.code=code;
}

View File

@ -13,7 +13,8 @@
</pattern>
</encoder>
</appender>
<!-- -->
<!-- Logstash收集日志输出到ElasticSearch -->
<appender name="LOGIN_LOGSTASH" class="net.logstash.logback.appender.LogstashTcpSocketAppender">
<destination>g.youlai.store:5044</destination>
<encoder charset="UTF-8" class="net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder">
@ -33,7 +34,7 @@
"class": "%logger",
"message": "%message",
"stack_trace": "%exception{20}",
"appname": "login" <!-- 登录日志记录索引名 logstash-%{appname}-yyyy.MM.dd -->
"action": "login" <!-- 自定义字段 登录日志索引名 logstash-%{action}-yyyy.MM.dd -->
}
</pattern>
</pattern>
@ -42,12 +43,12 @@
<keepAliveDuration>5 minutes</keepAliveDuration>
</appender>
<!-- additivity="false" 不会将日志反馈到root中 -->
<logger name="com.youlai.common.web.aspect.LoginLogAspect" level="INFO" additivity="false">
<appender-ref ref="CONSOLE" />
<!-- additivity="true" 默认是true 会向上传递至root -->
<logger name="com.youlai.common.web.aspect.LoginLogAspect" level="INFO" additivity="true">
<appender-ref ref="LOGIN_LOGSTASH"/>
</logger>
<!-- 根logger -->
<root level="INFO">
<appender-ref ref="CONSOLE" />
</root>