This commit is contained in:
haoxr 2021-07-12 21:14:07 +08:00
parent 770def4ce3
commit 66c79457b4
57 changed files with 514 additions and 724 deletions

View File

@ -1,7 +1,7 @@
package com.youlai.mall.oms; package com.youlai.mall.oms;
import com.youlai.mall.pms.api.SkuFeignClient; import com.youlai.mall.pms.api.GoodsFeignClient;
import com.youlai.mall.ums.api.MemberFeignClient; import com.youlai.mall.ums.api.MemberFeignClient;
import org.springframework.amqp.rabbit.annotation.EnableRabbit; import org.springframework.amqp.rabbit.annotation.EnableRabbit;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
@ -12,7 +12,7 @@ import org.springframework.cloud.openfeign.EnableFeignClients;
@SpringBootApplication(exclude = DataSourceAutoConfiguration.class) @SpringBootApplication(exclude = DataSourceAutoConfiguration.class)
@EnableDiscoveryClient @EnableDiscoveryClient
@EnableFeignClients(basePackageClasses = { MemberFeignClient.class, SkuFeignClient.class}) @EnableFeignClients(basePackageClasses = { MemberFeignClient.class, GoodsFeignClient.class})
@EnableRabbit @EnableRabbit
public class OmsApplication { public class OmsApplication {

View File

@ -3,7 +3,7 @@ package com.youlai.mall.oms.listener;
import com.rabbitmq.client.Channel; import com.rabbitmq.client.Channel;
import com.youlai.mall.oms.service.IOrderItemService; import com.youlai.mall.oms.service.IOrderItemService;
import com.youlai.mall.oms.service.IOrderService; import com.youlai.mall.oms.service.IOrderService;
import com.youlai.mall.pms.api.SkuFeignClient; import com.youlai.mall.pms.api.GoodsFeignClient;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message; import org.springframework.amqp.core.Message;
@ -24,7 +24,7 @@ public class OrderListener {
IOrderService orderService; IOrderService orderService;
IOrderItemService orderItemService; IOrderItemService orderItemService;
SkuFeignClient skuFeignService; GoodsFeignClient skuFeignService;
RabbitTemplate rabbitTemplate; RabbitTemplate rabbitTemplate;
/** /**

View File

@ -4,7 +4,7 @@ import com.youlai.common.web.util.JwtUtils;
import com.youlai.mall.oms.constant.OmsConstants; import com.youlai.mall.oms.constant.OmsConstants;
import com.youlai.mall.oms.pojo.vo.CartVO; import com.youlai.mall.oms.pojo.vo.CartVO;
import com.youlai.mall.oms.service.ICartService; import com.youlai.mall.oms.service.ICartService;
import com.youlai.mall.pms.api.SkuFeignClient; import com.youlai.mall.pms.api.GoodsFeignClient;
import com.youlai.mall.pms.pojo.dto.SkuDTO; import com.youlai.mall.pms.pojo.dto.SkuDTO;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@ -32,7 +32,7 @@ import java.util.concurrent.CompletableFuture;
public class CartServiceImpl implements ICartService { public class CartServiceImpl implements ICartService {
private RedisTemplate redisTemplate; private RedisTemplate redisTemplate;
private SkuFeignClient skuFeignService; private GoodsFeignClient skuFeignService;
/** /**
* 获取用户购物车 * 获取用户购物车

View File

@ -26,7 +26,7 @@ import com.youlai.mall.oms.pojo.vo.OrderSubmitVO;
import com.youlai.mall.oms.service.ICartService; import com.youlai.mall.oms.service.ICartService;
import com.youlai.mall.oms.service.IOrderItemService; import com.youlai.mall.oms.service.IOrderItemService;
import com.youlai.mall.oms.service.IOrderService; import com.youlai.mall.oms.service.IOrderService;
import com.youlai.mall.pms.api.SkuFeignClient; import com.youlai.mall.pms.api.GoodsFeignClient;
import com.youlai.mall.pms.pojo.dto.SkuDTO; import com.youlai.mall.pms.pojo.dto.SkuDTO;
import com.youlai.mall.pms.pojo.dto.SkuLockDTO; import com.youlai.mall.pms.pojo.dto.SkuLockDTO;
import com.youlai.mall.ums.api.MemberAddressFeignClient; import com.youlai.mall.ums.api.MemberAddressFeignClient;
@ -57,7 +57,7 @@ import static com.youlai.mall.oms.constant.OmsConstants.*;
public class OrderServiceImpl extends ServiceImpl<OrderMapper, OmsOrder> implements IOrderService { public class OrderServiceImpl extends ServiceImpl<OrderMapper, OmsOrder> implements IOrderService {
private ICartService cartService; private ICartService cartService;
private SkuFeignClient skuFeignService; private GoodsFeignClient skuFeignService;
private MemberAddressFeignClient addressFeignService; private MemberAddressFeignClient addressFeignService;
private IOrderItemService orderItemService; private IOrderItemService orderItemService;
private RabbitTemplate rabbitTemplate; private RabbitTemplate rabbitTemplate;

View File

@ -9,28 +9,31 @@ import org.springframework.web.bind.annotation.*;
import java.util.List; import java.util.List;
@FeignClient(value = "mall-pms") @FeignClient(value = "mall-pms")
public interface SkuFeignClient { public interface GoodsFeignClient {
/** /**
* 获取库存信息 * 获取商品信息
*/ */
@GetMapping("/app-api/v1/skus/{id}") @GetMapping("/app-api/v1/goods/{id}")
Result<SkuDTO> getSkuById(@PathVariable Long id); Result<SkuDTO> getSkuById(@PathVariable Long id);
/** /**
* 锁定库存 * 锁定库存
*/ */
@PutMapping("/app-api/v1/skus/lock_stock") @PutMapping("/app-api/v1/goods/stocks/_lock")
Result lockStock(@RequestBody List<SkuLockDTO> list); Result lockStock(@RequestBody List<SkuLockDTO> list);
/** /**
* 解锁库存 * 解锁库存
*/ */
@PutMapping("/app-api/v1/skus/unlock_stock") @PutMapping("/app-api/v1/goods/stocks/_unlock")
Result<Boolean> unlockStock(@RequestParam String orderToken); Result<Boolean> unlockStock(@RequestParam String orderToken);
@PutMapping("/app-api/v1/skus/deduct_stock") /**
* 扣减库存
*/
@PutMapping("/app-api/v1/goods/stocks/_deduct")
Result deductStock(@RequestParam String orderToken); Result deductStock(@RequestParam String orderToken);

View File

@ -0,0 +1,41 @@
package com.youlai.mall.pms.pojo.dto.admin;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.List;
@Data
@ApiModel("属性表单对象")
public class AttributeFormDTO {
@ApiModelProperty("分类ID")
@NotNull
private Long categoryId;
@ApiModelProperty("属性类型1规格2属性")
@NotNull
private Integer type;
@ApiModelProperty("属性集合")
@NotEmpty
private List<Attribute> attributes;
@Data
public static class Attribute {
@ApiModelProperty("属性ID")
private Long id;
@ApiModelProperty("属性名称")
@NotBlank
private String name;
}
}

View File

@ -1,26 +1,22 @@
package com.youlai.mall.pms.pojo.dto.admin; 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.PmsSku;
import com.youlai.mall.pms.pojo.entity.PmsSpuAttributeValue; import com.youlai.mall.pms.pojo.entity.PmsSpuAttributeValue;
import com.youlai.mall.pms.pojo.entity.PmsSpuSpecValue;
import com.youlai.mall.pms.pojo.dto.SpuDTO;
import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List; import java.util.List;
/**
* @author <a href="mailto:xianrui0365@163.com">xianrui</a>
*/
@Data @Data
@AllArgsConstructor
@NoArgsConstructor
public class ProductFormDTO { public class ProductFormDTO {
private SpuDTO spu; private SpuDTO spu;
private List<PmsSpuAttributeValue> attrs; private List<PmsSpuAttributeValue> attrs;
private List<PmsSpuSpecValue> specs;
private List<PmsSku> skus; 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.PmsSku;
import com.youlai.mall.pms.pojo.entity.PmsSpuAttributeValue; import com.youlai.mall.pms.pojo.entity.PmsSpuAttributeValue;
import com.youlai.mall.pms.pojo.entity.PmsSpec;
import com.youlai.mall.pms.pojo.dto.SpuDTO; import com.youlai.mall.pms.pojo.dto.SpuDTO;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
@ -19,7 +18,6 @@ public class ProductFormDTO {
private List<PmsSpuAttributeValue> attrs; private List<PmsSpuAttributeValue> attrs;
private List<PmsSpec> specs;
private List<PmsSku> skus; private List<PmsSku> skus;

View File

@ -2,14 +2,27 @@ package com.youlai.mall.pms.pojo.entity;
import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableId;
import com.youlai.common.base.BaseEntity;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor;
@Data @Data
public class PmsAttribute { @Builder
@NoArgsConstructor
@AllArgsConstructor
public class PmsAttribute extends BaseEntity {
@TableId(type=IdType.AUTO) @TableId(type=IdType.AUTO)
private Long id; private Long id;
private Long categoryId; private Long categoryId;
private String name; private String name;
/**
* 类型(1:规格;2:属性;)
*/
private Integer type;
} }

View File

@ -5,6 +5,8 @@ import com.baomidou.mybatisplus.annotation.TableId;
import com.youlai.common.base.BaseEntity; import com.youlai.common.base.BaseEntity;
import lombok.Data; import lombok.Data;
import javax.validation.constraints.NotBlank;
@Data @Data
public class PmsBrand extends BaseEntity { public class PmsBrand extends BaseEntity {
@ -12,13 +14,10 @@ public class PmsBrand extends BaseEntity {
@TableId(type= IdType.AUTO) @TableId(type= IdType.AUTO)
private Long id; private Long id;
@NotBlank
private String name; private String name;
private String logo; private String logoUrl;
private String firstLetter;
private Integer sort; private Integer sort;
private Integer status;
} }

View File

@ -13,11 +13,11 @@ public class PmsCategory extends BaseEntity {
private Long id; private Long id;
private String name; private String name;
private Long parentId; private Long parentId;
private String icon; private String iconUrl;
@JsonInclude(value = JsonInclude.Include.NON_NULL) @JsonInclude(value = JsonInclude.Include.NON_NULL)
private Integer level; private Integer level;
@JsonInclude(value = JsonInclude.Include.NON_NULL) @JsonInclude(value = JsonInclude.Include.NON_NULL)
private Integer sort; private Integer sort;
@JsonInclude(value = JsonInclude.Include.NON_NULL) @JsonInclude(value = JsonInclude.Include.NON_NULL)
private Integer status; private Integer visible;
} }

View File

@ -0,0 +1,13 @@
package com.youlai.mall.pms.pojo.entity;
import com.youlai.common.base.BaseEntity;
import lombok.Data;
@Data
public class PmsCategoryBrand extends BaseEntity {
private Long categoryId;
private Long brandId;
}

View File

@ -7,16 +7,15 @@ import lombok.Data;
@Data @Data
public class PmsSku extends BaseEntity { public class PmsSku extends BaseEntity {
@TableId(type = IdType.AUTO) @TableId(type = IdType.AUTO)
private Long id; private Long id;
private Long spuId; private Long spuId;
private String name; private String name;
private String code; private String sn;
private String pic; private String picUrl;
private String specifications;
private Long originPrice; private Long originPrice;
private Long price; private Long price;
private Integer stock; private Integer stock;
private Integer lockedStock; private Integer lockedStock;
private String specValueIds;
} }

View File

@ -1,26 +0,0 @@
package com.youlai.mall.pms.pojo.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.youlai.common.base.BaseEntity;
import lombok.Data;
import java.util.ArrayList;
import java.util.List;
@Data
public class PmsSpec extends BaseEntity {
/**
* 全面屏手机 颜色 版本
*/
@TableId(type = IdType.AUTO)
private Long id;
private Long categoryId;
private String name;
@TableField(exist = false)
private List<PmsSpuSpecValue> values = new ArrayList<>();
}

View File

@ -9,8 +9,7 @@ import lombok.experimental.Accessors;
import java.util.List; import java.util.List;
/** /**
* @author haoxr * @author <a href="mailto:xianrui0365@163.com">xianrui</a>
* @date 2020-11-06
*/ */
@Data @Data
@Accessors(chain = true) @Accessors(chain = true)
@ -24,8 +23,8 @@ public class PmsSpu extends BaseEntity {
private Long originPrice; private Long originPrice;
private Long price; private Long price;
private Integer sales; private Integer sales;
private String pic; private String picUrl;
private String pics; private String album;
private String unit; private String unit;
private String description; private String description;
private String detail; private String detail;
@ -38,8 +37,5 @@ public class PmsSpu extends BaseEntity {
private String brandName; private String brandName;
@TableField(exist = false) @TableField(exist = false)
private List<PmsSku> skus; private List<PmsSku> skuList;
@TableField(exist = false)
private List<String> picList;
} }

View File

@ -18,5 +18,7 @@ public class PmsSpuAttributeValue extends BaseEntity {
private Long attributeId; private Long attributeId;
private String name; private String name;
private String value; private String value;
private Integer type;
private String picUrl;
} }

View File

@ -1,20 +0,0 @@
package com.youlai.mall.pms.pojo.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.youlai.common.base.BaseEntity;
import lombok.Data;
/**
* @author haoxr
* @date 2020-11-06
*/
@Data
public class PmsSpuSpecValue extends BaseEntity {
@TableId(type = IdType.INPUT)
private Long id;
private Long spuId;
private Long specId;
private String value;
}

View File

@ -16,13 +16,11 @@ public class CategoryVO {
private Integer level; private Integer level;
private String icon; private String iconUrl;
private Integer sort; private Integer sort;
private String unit; private Integer visible;
private Integer status;
private List<CategoryVO> children=new ArrayList<>(); private List<CategoryVO> children=new ArrayList<>();

View File

@ -1,8 +1,8 @@
package com.youlai.mall.pms.controller.admin; package com.youlai.mall.pms.controller.admin;
import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.youlai.common.result.Result; import com.youlai.common.result.Result;
import com.youlai.mall.pms.pojo.dto.admin.AttributeFormDTO;
import com.youlai.mall.pms.pojo.entity.PmsAttribute; import com.youlai.mall.pms.pojo.entity.PmsAttribute;
import com.youlai.mall.pms.service.IPmsAttributeService; import com.youlai.mall.pms.service.IPmsAttributeService;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
@ -14,9 +14,11 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
@Api(tags = "【系统管理】商品属性") /**
* @author <a href="mailto:xianrui0365@163.com">xianrui</a>
*/
@Api(tags = "系统管理端-属性信息")
@RestController @RestController
@RequestMapping("/api/v1/attributes") @RequestMapping("/api/v1/attributes")
@Slf4j @Slf4j
@ -27,45 +29,23 @@ public class AttributeController {
@ApiOperation(value = "属性列表") @ApiOperation(value = "属性列表")
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "categoryId", value = "商品分类ID", paramType = "query", dataType = "Long") @ApiImplicitParam(name = "categoryId", value = "分类ID", paramType = "query", dataType = "Long"),
@ApiImplicitParam(name = "type", value = "属性类型1规格2属性", paramType = "query", dataType = "Integer"),
}) })
@GetMapping @GetMapping
public Result list(Long categoryId) { public Result list(Long categoryId, Integer type) {
List<PmsAttribute> list = iPmsAttributeService.list(new LambdaQueryWrapper<PmsAttribute>() List<PmsAttribute> list = iPmsAttributeService.list(new LambdaQueryWrapper<PmsAttribute>()
.eq(PmsAttribute::getCategoryId, categoryId)); .eq(categoryId != null, PmsAttribute::getCategoryId, categoryId)
.eq(type != null, PmsAttribute::getType, type)
);
return Result.success(list); return Result.success(list);
} }
@ApiOperation(value = "批量新增") @ApiOperation(value = "批量新增/修改")
@ApiImplicitParam(name = "attributes", value = "实体JSON对象", required = true, paramType = "body", dataType = "PmsAttribute") @ApiImplicitParam(name = "attributeForm", value = "实体JSON对象", required = true, paramType = "body", dataType = "AttributeFormDTO")
@PostMapping("/batch") @PostMapping("/batch")
public Result saveBatch(@RequestBody List<PmsAttribute> attributes) { public Result saveBatch(@RequestBody AttributeFormDTO attributeForm) {
boolean result = iPmsAttributeService.saveBatch(attributeForm);
if (CollectionUtil.isEmpty(attributes)) {
return Result.failed("请至少提交一条属性");
}
Long categoryId = attributes.get(0).getCategoryId();
List<Long> formIds = attributes.stream().map(item -> item.getId()).collect(Collectors.toList());
List<Long> dbIds = iPmsAttributeService
.list(new LambdaQueryWrapper<PmsAttribute>()
.eq(PmsAttribute::getCategoryId, categoryId)
.select(PmsAttribute::getId))
.stream()
.map(item -> item.getId())
.collect(Collectors.toList());
// 提交删除
if (CollectionUtil.isNotEmpty(dbIds)) {
List<Long> removeIds = dbIds.stream()
.filter(id -> CollectionUtil.isEmpty(formIds) || !formIds.contains(id))
.collect(Collectors.toList());
if (CollectionUtil.isNotEmpty(removeIds)) {
iPmsAttributeService.removeByIds(removeIds);
}
}
boolean result = iPmsAttributeService.saveOrUpdateBatch(attributes);
return Result.judge(result); return Result.judge(result);
} }
} }

View File

@ -2,60 +2,54 @@ package com.youlai.mall.pms.controller.admin;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.youlai.common.constant.GlobalConstants;
import com.youlai.common.enums.QueryModeEnum;
import com.youlai.common.result.Result; import com.youlai.common.result.Result;
import com.youlai.common.result.ResultCode;
import com.youlai.mall.pms.pojo.entity.PmsBrand; import com.youlai.mall.pms.pojo.entity.PmsBrand;
import com.youlai.mall.pms.service.IPmsBrandService; import com.youlai.mall.pms.service.IPmsBrandService;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
@Api(tags = "【系统管理】品牌接口") /**
* @author <a href="mailto:xianrui0365@163.com">xianrui</a>
*/
@Api(tags = "系统管理端-品牌信息")
@RestController @RestController
@RequestMapping("/api/v1/brands") @RequestMapping("/api/v1/brands")
@Slf4j @RequiredArgsConstructor
@AllArgsConstructor
public class BrandController { public class BrandController {
private IPmsBrandService iPmsBrandService; private final IPmsBrandService iPmsBrandService;
@ApiOperation(value = "列表分页") @ApiOperation(value = "品牌列表分页")
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "queryMode", paramType = "query", dataType = "QueryModeEnum"),
@ApiImplicitParam(name = "page", value = "页码", paramType = "query", dataType = "Long"), @ApiImplicitParam(name = "page", value = "页码", paramType = "query", dataType = "Long"),
@ApiImplicitParam(name = "limit", value = "每页数量", paramType = "query", dataType = "Long"), @ApiImplicitParam(name = "limit", value = "每页数量", paramType = "query", dataType = "Long"),
@ApiImplicitParam(name = "name", value = "品牌名称", paramType = "query", dataType = "String") @ApiImplicitParam(name = "name", value = "品牌名称", paramType = "query", dataType = "String")
}) })
@GetMapping @GetMapping("/page")
public Result list(String queryMode, Integer page, Integer limit, String name) { public Result page(Integer page, Integer limit, String name) {
QueryModeEnum queryModeEnum = QueryModeEnum.getByCode(queryMode); LambdaQueryWrapper<PmsBrand> queryWrapper = new LambdaQueryWrapper<PmsBrand>().like(StrUtil.isNotBlank(name), PmsBrand::getName, name);
LambdaQueryWrapper<PmsBrand> queryWrapper = new LambdaQueryWrapper<>(); Page<PmsBrand> result = iPmsBrandService.page(new Page<>(page, limit), queryWrapper);
switch (queryModeEnum) { return Result.success(result.getRecords(), result.getTotal());
case PAGE:
queryWrapper.like(StrUtil.isNotBlank(name), PmsBrand::getName, name);
Page<PmsBrand> result = iPmsBrandService.page(new Page<>(page, limit), queryWrapper);
return Result.success(result.getRecords(), result.getTotal());
case LIST:
queryWrapper.eq(PmsBrand::getStatus, GlobalConstants.STATUS_YES)
.select(PmsBrand::getId, PmsBrand::getName);
List<PmsBrand> list = iPmsBrandService.list(queryWrapper);
return Result.success(list);
default:
return Result.failed(ResultCode.QUERY_MODE_IS_NULL);
}
} }
@ApiOperation(value = "品牌列表")
@GetMapping
public Result list() {
List<PmsBrand> list = iPmsBrandService.list(new LambdaQueryWrapper<PmsBrand>()
.select(PmsBrand::getId, PmsBrand::getName));
return Result.success(list);
}
@ApiOperation(value = "品牌详情") @ApiOperation(value = "品牌详情")
@ApiImplicitParam(name = "id", value = "品牌id", required = true, paramType = "path", dataType = "Long") @ApiImplicitParam(name = "id", value = "品牌id", required = true, paramType = "path", dataType = "Long")
@GetMapping("/{id}") @GetMapping("/{id}")
@ -92,17 +86,4 @@ public class BrandController {
boolean status = iPmsBrandService.removeByIds(Arrays.asList(ids.split(","))); boolean status = iPmsBrandService.removeByIds(Arrays.asList(ids.split(",")));
return Result.judge(status); return Result.judge(status);
} }
@ApiOperation(value = "修改品牌")
@ApiImplicitParams({
@ApiImplicitParam(name = "id", value = "用户ID", required = true, paramType = "path", dataType = "Long"),
@ApiImplicitParam(name = "brand", value = "实体JSON对象", required = true, paramType = "body", dataType = "PmsBrand")
})
@PatchMapping(value = "/{id}")
public Result patch(@PathVariable Long id, @RequestBody PmsBrand brand) {
LambdaUpdateWrapper<PmsBrand> updateWrapper = new LambdaUpdateWrapper<PmsBrand>().eq(PmsBrand::getId, id);
updateWrapper.set(brand.getStatus()!=null,PmsBrand::getStatus, brand.getStatus());
boolean result = iPmsBrandService.update(updateWrapper);
return Result.success(result);
}
} }

View File

@ -1,57 +1,53 @@
package com.youlai.mall.pms.controller.admin; package com.youlai.mall.pms.controller.admin;
import cn.hutool.core.bean.BeanUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.youlai.common.enums.QueryModeEnum;
import com.youlai.common.result.Result; import com.youlai.common.result.Result;
import com.youlai.mall.pms.pojo.entity.PmsAttribute;
import com.youlai.mall.pms.pojo.entity.PmsCategory; import com.youlai.mall.pms.pojo.entity.PmsCategory;
import com.youlai.mall.pms.pojo.vo.CategoryVO; import com.youlai.mall.pms.pojo.vo.CategoryVO;
import com.youlai.mall.pms.service.IPmsAttributeService; import com.youlai.mall.pms.service.IPmsAttributeService;
import com.youlai.mall.pms.service.IPmsCategoryService; import com.youlai.mall.pms.service.IPmsCategoryService;
import com.youlai.mall.pms.service.IPmsSpecService;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
import java.util.stream.Collectors;
@Api(tags = "【系统管理】商品分类") /**
* @author <a href="mailto:xianrui0365@163.com">xianrui</a>
*/
@Api(tags = "系统管理端-分类信息")
@RestController @RestController
@RequestMapping("/api/v1/categories") @RequestMapping("/api/v1/categories")
@Slf4j
@AllArgsConstructor @AllArgsConstructor
public class CategoryController { public class CategoryController {
private IPmsCategoryService iPmsCategoryService; private IPmsCategoryService iPmsCategoryService;
private IPmsAttributeService iPmsAttributeService; private IPmsAttributeService iPmsAttributeService;
private IPmsSpecService iPmsSpecService;
@ApiOperation(value = "分类列表") @ApiOperation(value = "分类列表")
@ApiImplicitParams({
@ApiImplicitParam(name = "queryMode", paramType = "query", dataType = "String"),
})
@GetMapping @GetMapping
public Result list(String queryMode) { public Result<List<CategoryVO>> list() {
QueryModeEnum queryModeEnum = QueryModeEnum.getByCode(queryMode); List<CategoryVO> list = iPmsCategoryService.listTreeCategory(null);
PmsCategory category = new PmsCategory(); return Result.success(list);
List list;
switch (queryModeEnum) {
case CASCADER:
list = iPmsCategoryService.listForCascader(category);
return Result.success(list);
default:
list = iPmsCategoryService.listForTree(category);
return Result.success(list);
}
} }
@ApiOperation(value = "分类级联列表")
@GetMapping("/cascade")
public Result cascadeCategoryList() {
List list = iPmsCategoryService.listCascadeCategory();
return Result.success(list);
}
@ApiOperation(value = "分类详情") @ApiOperation(value = "分类详情")
@ApiImplicitParam(name = "id", value = "商品分类id", required = true, paramType = "path", dataType = "Long") @ApiImplicitParam(name = "id", value = "商品分类id", required = true, paramType = "path", dataType = "Long")
@GetMapping("/{id}") @GetMapping("/{id}")
@ -64,10 +60,8 @@ public class CategoryController {
@ApiImplicitParam(name = "category", value = "实体JSON对象", required = true, paramType = "body", dataType = "PmsCategory") @ApiImplicitParam(name = "category", value = "实体JSON对象", required = true, paramType = "body", dataType = "PmsCategory")
@PostMapping @PostMapping
public Result add(@RequestBody PmsCategory category) { public Result add(@RequestBody PmsCategory category) {
iPmsCategoryService.save(category); boolean result = iPmsCategoryService.save(category);
CategoryVO categoryVO = new CategoryVO(); return Result.judge(result);
BeanUtil.copyProperties(category, categoryVO);
return Result.success(categoryVO);
} }
@ApiOperation(value = "修改分类") @ApiOperation(value = "修改分类")
@ -76,38 +70,33 @@ public class CategoryController {
@ApiImplicitParam(name = "category", value = "实体JSON对象", required = true, paramType = "body", dataType = "PmsCategory") @ApiImplicitParam(name = "category", value = "实体JSON对象", required = true, paramType = "body", dataType = "PmsCategory")
}) })
@PutMapping(value = "/{id}") @PutMapping(value = "/{id}")
public Result update( public Result update(@RequestBody PmsCategory category) {
@PathVariable Long id, boolean result = iPmsCategoryService.updateById(category);
@RequestBody PmsCategory category) { return Result.judge(result);
iPmsCategoryService.updateById(category);
return Result.success(category);
} }
@ApiOperation(value = "删除商品分类") @ApiOperation(value = "删除分类")
@ApiImplicitParam(name = "ids", value = "id集合,以英文逗号','分隔", required = true, paramType = "query", dataType = "String") @ApiImplicitParam(name = "ids", value = "id集合,以英文逗号','分隔", required = true, paramType = "query", dataType = "String")
@DeleteMapping("/{ids}") @DeleteMapping("/{ids}")
public Result delete(@PathVariable String ids) { public Result delete(@PathVariable String ids) {
List<String> idList = Arrays.asList(ids.split(",")); List<String> categoryIds = Arrays.asList(ids.split(","));
Optional.ofNullable(idList).ifPresent(list -> { Optional.ofNullable(categoryIds).ifPresent(categoryIdList -> {
list.forEach(id -> { categoryIdList.forEach(categoryId -> iPmsAttributeService.remove(new LambdaQueryWrapper<PmsAttribute>().eq(PmsAttribute::getCategoryId, categoryId)));
iPmsAttributeService.removeById(id);
iPmsSpecService.removeById(id);
});
iPmsCategoryService.removeByIds(idList.stream().map(id -> Long.parseLong(id)).collect(Collectors.toList()));
}); });
return Result.success(); boolean result = iPmsCategoryService.removeByIds(categoryIds);
return Result.judge(result);
} }
@ApiOperation(value = "修改分类") @ApiOperation(value = "选择性修改分类")
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "id", value = "用户ID", required = true, paramType = "path", dataType = "Long"), @ApiImplicitParam(name = "id", value = "分类ID", required = true, paramType = "path", dataType = "Long"),
@ApiImplicitParam(name = "category", value = "实体JSON对象", required = true, paramType = "body", dataType = "PmsCategory") @ApiImplicitParam(name = "category", value = "实体JSON对象", required = true, paramType = "body", dataType = "PmsCategory")
}) })
@PatchMapping(value = "/{id}") @PatchMapping(value = "/{id}")
public Result patch(@PathVariable Long id, @RequestBody PmsCategory category) { public Result patch(@PathVariable Long id, @RequestBody PmsCategory category) {
LambdaUpdateWrapper<PmsCategory> updateWrapper = new LambdaUpdateWrapper<PmsCategory>().eq(PmsCategory::getId, id); LambdaUpdateWrapper<PmsCategory> updateWrapper = new LambdaUpdateWrapper<PmsCategory>().eq(PmsCategory::getId, id);
updateWrapper.set(category.getStatus() != null, PmsCategory::getStatus, category.getStatus()); updateWrapper.set(category.getVisible() != null, PmsCategory::getVisible, category.getVisible());
boolean update = iPmsCategoryService.update(updateWrapper); boolean result = iPmsCategoryService.update(updateWrapper);
return Result.success(update); return Result.judge(result);
} }
} }

View File

@ -3,9 +3,7 @@ package com.youlai.mall.pms.controller.admin;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.youlai.common.enums.QueryModeEnum;
import com.youlai.common.result.Result; import com.youlai.common.result.Result;
import com.youlai.common.result.ResultCode;
import com.youlai.mall.pms.pojo.dto.admin.ProductFormDTO; import com.youlai.mall.pms.pojo.dto.admin.ProductFormDTO;
import com.youlai.mall.pms.pojo.entity.PmsSpu; import com.youlai.mall.pms.pojo.entity.PmsSpu;
import com.youlai.mall.pms.service.IPmsSpuService; import com.youlai.mall.pms.service.IPmsSpuService;
@ -14,64 +12,44 @@ import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.Arrays; import java.util.Arrays;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@Api(tags = "【系统管理】商品信息") /**
* @author <a href="mailto:xianrui0365@163.com">xianrui</a>
*/
@Api(tags = "系统管理端-商品信息")
@RestController @RestController
@RequestMapping("/api/v1/spus") @RequestMapping("/api/v1/products")
@Slf4j
@AllArgsConstructor @AllArgsConstructor
public class SpuController { public class GoodsController {
private IPmsSpuService iPmsSpuService; private IPmsSpuService iPmsSpuService;
@ApiOperation(value = "列表分页") @ApiOperation(value = "商品分页列表")
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "queryMode", value = "查询模式", paramType = "query", dataType = "QueryModeEnum"),
@ApiImplicitParam(name = "page", value = "页码", paramType = "query", dataType = "Long"), @ApiImplicitParam(name = "page", value = "页码", paramType = "query", dataType = "Long"),
@ApiImplicitParam(name = "limit", value = "每页数量", paramType = "query", dataType = "Long"), @ApiImplicitParam(name = "limit", value = "每页数量", paramType = "query", dataType = "Long"),
@ApiImplicitParam(name = "name", value = "商品名称", paramType = "query", dataType = "String"), @ApiImplicitParam(name = "categoryId", value = "分类ID", paramType = "query", dataType = "Long"),
@ApiImplicitParam(name = "categoryId", value = "商品类目", paramType = "query", dataType = "Long") @ApiImplicitParam(name = "name", value = "商品名称", paramType = "query", dataType = "String")
}) })
@GetMapping @GetMapping("/page")
public Result list( public Result list(Integer page, Integer limit, String name, Long categoryId) {
String queryMode, IPage<PmsSpu> result = iPmsSpuService.list(
Integer page, new Page<>(page, limit),
Integer limit, new PmsSpu().setName(name).setCategoryId(categoryId)
String name, );
Long categoryId return Result.success(result.getRecords(), result.getTotal());
) {
QueryModeEnum queryModeEnum = QueryModeEnum.getByCode(queryMode);
switch (queryModeEnum) {
case PAGE:
IPage<PmsSpu> result = iPmsSpuService.list(
new Page<>(page, limit),
new PmsSpu().setName(name).setCategoryId(categoryId)
);
return Result.success(result.getRecords(), result.getTotal());
default:
return Result.failed(ResultCode.QUERY_MODE_IS_NULL);
}
} }
@ApiOperation(value = "商品详情")
@ApiImplicitParam(name = "id", value = "商品id", required = true, paramType = "path", dataType = "Long")
@GetMapping("/{id}")
public Result detail(@PathVariable Long id) {
ProductFormDTO spu = iPmsSpuService.getBySpuId(id);
return Result.success(spu);
}
@ApiOperation(value = "新增商品") @ApiOperation(value = "新增商品")
@ApiImplicitParam(name = "productBO", value = "实体JSON对象", required = true, paramType = "body", dataType = "ProductBO") @ApiImplicitParam(name = "productForm", value = "实体JSON对象", required = true, paramType = "body", dataType = "ProductFormDTO")
@PostMapping @PostMapping
public Result add(@RequestBody ProductFormDTO productFormDTO) { public Result add(@RequestBody ProductFormDTO productForm) {
boolean status = iPmsSpuService.add(productFormDTO); boolean status = iPmsSpuService.add(productForm);
return Result.judge(status); return Result.judge(status);
} }
@ -81,9 +59,7 @@ public class SpuController {
@ApiImplicitParam(name = "spu", value = "实体JSON对象", required = true, paramType = "body", dataType = "PmsSpu") @ApiImplicitParam(name = "spu", value = "实体JSON对象", required = true, paramType = "body", dataType = "PmsSpu")
}) })
@PutMapping(value = "/{id}") @PutMapping(value = "/{id}")
public Result update( public Result update(@PathVariable Long id, @RequestBody ProductFormDTO spu) {
@PathVariable Long id,
@RequestBody ProductFormDTO spu) {
boolean status = iPmsSpuService.updateById(spu); boolean status = iPmsSpuService.updateById(spu);
return Result.judge(status); return Result.judge(status);
} }
@ -96,9 +72,9 @@ public class SpuController {
return Result.success(); return Result.success();
} }
@ApiOperation(value = "修改商品") @ApiOperation(value = "选择性修改商品")
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "id", value = "用户ID", required = true, paramType = "path", dataType = "Long"), @ApiImplicitParam(name = "id", value = "商品ID", required = true, paramType = "path", dataType = "Long"),
@ApiImplicitParam(name = "spu", value = "实体JSON对象", required = true, paramType = "body", dataType = "PmsSpu") @ApiImplicitParam(name = "spu", value = "实体JSON对象", required = true, paramType = "body", dataType = "PmsSpu")
}) })
@PatchMapping(value = "/{id}") @PatchMapping(value = "/{id}")

View File

@ -1,73 +0,0 @@
package com.youlai.mall.pms.controller.admin;
import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.youlai.common.result.Result;
import com.youlai.mall.pms.pojo.entity.PmsSpec;
import com.youlai.mall.pms.service.IPmsSpecService;
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;
import java.util.stream.Collectors;
@Api(tags = "【系统管理】商品规格")
@RestController
@RequestMapping("/api/v1/specs")
@Slf4j
@AllArgsConstructor
public class SpecController {
private IPmsSpecService iPmsSpecService;
@ApiOperation(value = "分类规格列表")
@ApiImplicitParams({
@ApiImplicitParam(name = "categoryId", value = "分类ID", paramType = "query", dataType = "Long")
})
@GetMapping
public Result list(Long categoryId) {
List<PmsSpec> list = iPmsSpecService
.list(new LambdaQueryWrapper<PmsSpec>()
.eq(PmsSpec::getCategoryId, categoryId));
return Result.success(list);
}
@ApiOperation(value = "新增规格")
@ApiImplicitParam(name = "specCategories", value = "实体JSON对象", required = true, paramType = "body", dataType = "PmsSpecCategory")
@PostMapping
public Result save(@RequestBody List<PmsSpec> specCategories) {
if (CollectionUtil.isEmpty(specCategories)) {
return Result.failed("至少提交一条规格");
}
Long categoryId = specCategories.get(0).getCategoryId();
List<Long> formIds = specCategories.stream().map(item -> item.getId()).collect(Collectors.toList());
List<Long> databaseIds = iPmsSpecService
.list(new LambdaQueryWrapper<PmsSpec>()
.eq(PmsSpec::getCategoryId, categoryId)
.select(PmsSpec::getId)
).stream()
.map(item -> item.getId())
.collect(Collectors.toList());
// 删除的商品分类规格
if (CollectionUtil.isNotEmpty(databaseIds)) {
List<Long> removeIds = databaseIds.stream()
.filter(id -> CollectionUtil.isEmpty(formIds) || !formIds.contains(id))
.collect(Collectors.toList());
if (CollectionUtil.isNotEmpty(removeIds)) {
iPmsSpecService.removeByIds(removeIds);
}
}
boolean result = iPmsSpecService.saveOrUpdateBatch(specCategories);
return Result.judge(result);
}
}

View File

@ -7,21 +7,22 @@ import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
@Api(tags = "【系统管理】商品库存") /**
* @author <a href="mailto:xianrui0365@163.com">xianrui</a>
*/
@Api(tags = "系统管理端-库存信息")
@RestController @RestController
@RequestMapping("/api/v1/skus") @RequestMapping("/api/v1/goods")
@Slf4j @RequiredArgsConstructor
@AllArgsConstructor public class StockController {
public class SkuController {
private IPmsSkuService iPmsSkuService; private final IPmsSkuService iPmsSkuService;
@ApiOperation(value = "商品详情") @ApiOperation(value = "商品库存详情")
@ApiImplicitParam(name = "id", value = "商品SkuID", required = true, paramType = "path", dataType = "Long") @ApiImplicitParam(name = "id", value = "商品ID", required = true, paramType = "path", dataType = "Long")
@GetMapping("/{id}") @GetMapping("/{id}")
public Result detail(@PathVariable Long id) { public Result detail(@PathVariable Long id) {
PmsSku sku = iPmsSkuService.getById(id); PmsSku sku = iPmsSkuService.getById(id);
@ -30,29 +31,26 @@ public class SkuController {
@ApiOperation(value = "修改库存") @ApiOperation(value = "修改库存")
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "id", value = "商品id", required = true, paramType = "path", dataType = "Long"), @ApiImplicitParam(name = "id", value = "商品ID", required = true, paramType = "path", dataType = "Long"),
@ApiImplicitParam(name = "sku", value = "实体JSON对象", required = true, paramType = "body", dataType = "PmsSku") @ApiImplicitParam(name = "sku", value = "实体JSON对象", required = true, paramType = "body", dataType = "PmsSku")
}) })
@PutMapping(value = "/{id}") @PutMapping(value = "/{id}")
public Result update( public Result update(@PathVariable Long id, @RequestBody PmsSku sku) {
@PathVariable Long id,
@RequestBody PmsSku sku) {
boolean status = iPmsSkuService.updateById(sku); boolean status = iPmsSkuService.updateById(sku);
return Result.judge(status); return Result.judge(status);
} }
@ApiOperation(value = "修改库存") @ApiOperation(value = "修改商品库存")
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "id", value = "Sku ID", required = true, paramType = "path", dataType = "Long"), @ApiImplicitParam(name = "id", value = "商品ID", required = true, paramType = "path", dataType = "Long"),
@ApiImplicitParam(name = "num", value = "库存数量", required = true, paramType = "query", dataType = "Long") @ApiImplicitParam(name = "num", value = "库存数量", required = true, paramType = "query", dataType = "Long")
}) })
@PutMapping("/{id}/stock") @PatchMapping("/{id}/stock")
public Result updateStock(@PathVariable Long id, @RequestParam Integer num) { public Result updateStock(@PathVariable Long id, @RequestParam Integer num) {
PmsSku sku = iPmsSkuService.getById(id); PmsSku sku = iPmsSkuService.getById(id);
sku.setStock(sku.getStock() + num); sku.setStock(sku.getStock() + num);
boolean result = iPmsSkuService.updateById(sku); boolean result = iPmsSkuService.updateById(sku);
return Result.judge(result); return Result.judge(result);
} }
} }

View File

@ -1,13 +1,10 @@
package com.youlai.mall.pms.controller.app; package com.youlai.mall.pms.controller.app;
import com.youlai.common.constant.GlobalConstants;
import com.youlai.common.result.Result; import com.youlai.common.result.Result;
import com.youlai.mall.pms.pojo.entity.PmsCategory;
import com.youlai.mall.pms.pojo.vo.CategoryVO; import com.youlai.mall.pms.pojo.vo.CategoryVO;
import com.youlai.mall.pms.service.IPmsCategoryService; import com.youlai.mall.pms.service.IPmsCategoryService;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@ -17,8 +14,11 @@ import org.springframework.web.bind.annotation.RestController;
import java.util.List; import java.util.List;
@Api(tags = "【移动端】商品分类") /**
@RestController("APPCategoryController") * @author <a href="mailto:xianrui0365@163.com">xianrui</a>
*/
@Api(tags = "移动端-分类信息")
@RestController("AppCategoryController")
@RequestMapping("/app-api/v1/categories") @RequestMapping("/app-api/v1/categories")
@Slf4j @Slf4j
@AllArgsConstructor @AllArgsConstructor
@ -27,15 +27,10 @@ public class CategoryController {
private IPmsCategoryService iPmsCategoryService; private IPmsCategoryService iPmsCategoryService;
@ApiOperation(value = "分类列表") @ApiOperation(value = "分类列表")
@ApiImplicitParams({ @ApiImplicitParam(name = "parentId", paramType = "query", dataType = "Long")
@ApiImplicitParam(name = "parentId", paramType = "query", dataType = "Long")
})
@GetMapping @GetMapping
public Result list(Long parentId) { public Result list(Long parentId) {
PmsCategory category = new PmsCategory(); List<CategoryVO> list = iPmsCategoryService.listTreeCategory(parentId);
category.setParentId(parentId);
category.setStatus(GlobalConstants.STATUS_YES);
List<CategoryVO> list = iPmsCategoryService.listForTree(category);
return Result.success(list); return Result.success(list);
} }
} }

View File

@ -12,11 +12,11 @@ import org.springframework.web.bind.annotation.*;
import java.util.List; import java.util.List;
@Api(tags = "【移动端】商品库存") @Api(tags = "移动端-商品")
@RestController("APPSkuController") @RestController("appGoodsController")
@RequestMapping("/app-api/v1/skus") @RequestMapping("/app-api/v1/goods")
@AllArgsConstructor @AllArgsConstructor
public class SkuController { public class GoodsController {
private IPmsSkuService iPmsSkuService; private IPmsSkuService iPmsSkuService;
@ -39,7 +39,7 @@ public class SkuController {
@ApiOperation(value = "锁定库存") @ApiOperation(value = "锁定库存")
@ApiImplicitParam(name = "list", value = "商品列表", required = true, paramType = "body", dataType = "SkuLockDTO") @ApiImplicitParam(name = "list", value = "商品列表", required = true, paramType = "body", dataType = "SkuLockDTO")
@PutMapping("/lock_stock") @PutMapping("/stocks/_lock")
public Result<Boolean> lockStock(@RequestBody List<SkuLockDTO> list) { public Result<Boolean> lockStock(@RequestBody List<SkuLockDTO> list) {
boolean result = iPmsSkuService.lockStock(list); boolean result = iPmsSkuService.lockStock(list);
return Result.judge(result); return Result.judge(result);
@ -48,7 +48,7 @@ public class SkuController {
@ApiOperation(value = "解锁库存") @ApiOperation(value = "解锁库存")
@ApiImplicitParam(name = "orderToken", value = "订单令牌", required = true, paramType = "body", dataType = "String") @ApiImplicitParam(name = "orderToken", value = "订单令牌", required = true, paramType = "body", dataType = "String")
@PutMapping("/unlock_stock") @PutMapping("/stocks/_unlock")
public Result<Boolean> unlockStock(String orderToken) { public Result<Boolean> unlockStock(String orderToken) {
boolean result = iPmsSkuService.unlockStock(orderToken); boolean result = iPmsSkuService.unlockStock(orderToken);
return Result.judge(result); return Result.judge(result);
@ -56,11 +56,9 @@ public class SkuController {
@ApiOperation(value = "扣减库存") @ApiOperation(value = "扣减库存")
@ApiImplicitParam(name = "orderToken", value = "订单令牌", required = true, paramType = "body", dataType = "String") @ApiImplicitParam(name = "orderToken", value = "订单令牌", required = true, paramType = "body", dataType = "String")
@PutMapping("/deduct_stock") @PutMapping("/stocks/_deduct")
public Result<Boolean> deductStock(String orderToken) { public Result<Boolean> deductStock(String orderToken) {
boolean result = iPmsSkuService.deductStock(orderToken); boolean result = iPmsSkuService.deductStock(orderToken);
return Result.judge(result); return Result.judge(result);
} }
} }

View File

@ -20,8 +20,8 @@ import org.springframework.web.bind.annotation.*;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@Api(tags = "【移动端】商品信息") @Api(tags = "移动端-产品")
@RestController("APPSpuController") @RestController("appSpuController")
@RequestMapping("/app-api/v1/products") @RequestMapping("/app-api/v1/products")
@AllArgsConstructor @AllArgsConstructor
public class ProductController { public class ProductController {
@ -49,7 +49,7 @@ public class ProductController {
.like(StrUtil.isNotBlank(name), PmsSpu::getName, name) .like(StrUtil.isNotBlank(name), PmsSpu::getName, name)
.select(PmsSpu::getId, .select(PmsSpu::getId,
PmsSpu::getName, PmsSpu::getName,
PmsSpu::getPic, PmsSpu::getPicUrl,
PmsSpu::getPrice, PmsSpu::getPrice,
PmsSpu::getSales PmsSpu::getSales
) )

View File

@ -1,37 +0,0 @@
package com.youlai.mall.pms.controller.app;
import com.youlai.common.result.Result;
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.*;
/**
* @author haoxr
* @description TODO
* @createTime 2021/3/7 22:55
*/
@Api(tags = "【移动端】商品搜索")
@RestController("APPSearchController")
@RequestMapping("/app-api/v1/search")
@AllArgsConstructor
public class SearchController {
@ApiOperation(value = "关键字搜索商品")
@ApiImplicitParams({
@ApiImplicitParam(name = "key", value = "关键字", paramType = "query", dataType = "String"),
})
@GetMapping("/{name}")
public Result searchByName(@PathVariable String name) {
/* SearchSourceBuilder builder = new SearchSourceBuilder();
builder.query(QueryBuilders.matchQuery("name", name));
List<PmsProduct> list = elasticSearchService.search(builder.query(), PmsProduct.class, "pms_spu");
return Result.success(list);*/
return null;
}
}

View File

@ -0,0 +1,11 @@
package com.youlai.mall.pms.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.youlai.mall.pms.pojo.entity.PmsCategory;
import com.youlai.mall.pms.pojo.entity.PmsCategoryBrand;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface PmsCategoryBrandMapper extends BaseMapper<PmsCategoryBrand> {
}

View File

@ -1,26 +0,0 @@
package com.youlai.mall.pms.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.youlai.mall.pms.pojo.entity.PmsSpec;
import org.apache.ibatis.annotations.*;
import java.util.List;
@Mapper
public interface PmsSpecMapper extends BaseMapper<PmsSpec> {
@Select("<script>" +
" SELECT " +
" t1.id,t1.category_id,t1.name,t2.id AS spuId " +
" FROM " +
" pms_spec t1 " +
" LEFT JOIN pms_spu t2 ON t1.category_id = t2.category_id " +
" WHERE " +
" t2.id =#{spuId} " +
"</script>")
@Results({
@Result(id = true, column = "id", property = "id"),
@Result(property = "values", column = "{specId= t1.id,spuId=spuId}", many = @Many(select = "com.youlai.mall.pms.mapper.PmsSpuSpecValueMapper.listByCondition"))
})
List<PmsSpec> listBySpuId(Long spuId);
}

View File

@ -3,39 +3,15 @@ package com.youlai.mall.pms.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.youlai.mall.pms.pojo.entity.PmsSpu; import com.youlai.mall.pms.pojo.entity.PmsSpu;
import org.apache.ibatis.annotations.Many;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import java.util.List; import java.util.List;
/** /**
* @author haoxr * @author <a href="mailto:xianrui0365@163.com">xianrui</a>
* @date 2020-11-06
*/ */
@Mapper @Mapper
public interface PmsSpuMapper extends BaseMapper<PmsSpu> { public interface PmsSpuMapper extends BaseMapper<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"))
})
List<PmsSpu> list(Page<PmsSpu> page, PmsSpu spu); List<PmsSpu> list(Page<PmsSpu> page, PmsSpu spu);
} }

View File

@ -1,32 +0,0 @@
package com.youlai.mall.pms.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.youlai.mall.pms.pojo.entity.PmsSpuSpecValue;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
import java.util.Map;
/**
* @author haoxr
* @date 2020-11-06
*/
@Mapper
public interface PmsSpuSpecValueMapper extends BaseMapper<PmsSpuSpecValue> {
@Select("<script>" +
" SELECT " +
" id, " +
" spu_id, " +
" spec_id, " +
" value" +
" FROM " +
" pms_spu_spec_value " +
" WHERE " +
" spu_id = #{spuId} " +
" AND spec_id = #{specId} " +
"</script>")
List<PmsSpuSpecValue> listByCondition(Map<String, String> param);
}

View File

@ -1,10 +1,11 @@
package com.youlai.mall.pms.service; package com.youlai.mall.pms.service;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import com.youlai.mall.pms.pojo.dto.admin.AttributeFormDTO;
import com.youlai.mall.pms.pojo.entity.PmsAttribute; import com.youlai.mall.pms.pojo.entity.PmsAttribute;
public interface IPmsAttributeService extends IService<PmsAttribute> { public interface IPmsAttributeService extends IService<PmsAttribute> {
boolean saveBatch(AttributeFormDTO attributeForm);
} }

View File

@ -0,0 +1,12 @@
package com.youlai.mall.pms.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.youlai.mall.pms.pojo.entity.PmsCategoryBrand;
/**
* @author <a href="mailto:xianrui0365@163.com">xianrui</a>
*/
public interface IPmsCategoryBrandService extends IService<PmsCategoryBrand> {
}

View File

@ -1,15 +1,20 @@
package com.youlai.mall.pms.service; package com.youlai.mall.pms.service;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import com.youlai.common.web.vo.CascaderVO; import com.youlai.common.pojo.vo.CascadeVO;
import com.youlai.mall.pms.pojo.entity.PmsCategory; import com.youlai.mall.pms.pojo.entity.PmsCategory;
import com.youlai.mall.pms.pojo.vo.CategoryVO; import com.youlai.mall.pms.pojo.vo.CategoryVO;
import java.util.List; import java.util.List;
/**
* @author <a href="mailto:xianrui0365@163.com">xianrui</a>
*/
public interface IPmsCategoryService extends IService<PmsCategory> { public interface IPmsCategoryService extends IService<PmsCategory> {
List<CategoryVO> listForTree(PmsCategory category);
List<CascaderVO> listForCascader(PmsCategory category); List<CategoryVO> listTreeCategory(Long parentId);
List<CascadeVO> listCascadeCategory();
} }

View File

@ -1,12 +0,0 @@
package com.youlai.mall.pms.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.youlai.mall.pms.pojo.entity.PmsSpec;
import java.util.List;
public interface IPmsSpecService extends IService<PmsSpec> {
List<PmsSpec> listBySpuId(Long spuId);
}

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.entity.PmsSpuSpecValue;
public interface IPmsSpuSpecValueService extends IService<PmsSpuSpecValue> {
}

View File

@ -1,16 +1,61 @@
package com.youlai.mall.pms.service.impl; package com.youlai.mall.pms.service.impl;
import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.youlai.mall.pms.mapper.PmsAttributeMapper; import com.youlai.mall.pms.mapper.PmsAttributeMapper;
import com.youlai.mall.pms.pojo.dto.admin.AttributeFormDTO;
import com.youlai.mall.pms.pojo.entity.PmsAttribute; import com.youlai.mall.pms.pojo.entity.PmsAttribute;
import com.youlai.mall.pms.service.IPmsAttributeService; import com.youlai.mall.pms.service.IPmsAttributeService;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
/** /**
* @author haoxr * @author <a href="mailto:xianrui0365@163.com">xianrui</a>
* @date 2020-11-06
*/ */
@Service @Service
public class PmsAttributeServiceImpl extends ServiceImpl<PmsAttributeMapper, PmsAttribute> implements IPmsAttributeService { public class PmsAttributeServiceImpl extends ServiceImpl<PmsAttributeMapper, PmsAttribute> implements IPmsAttributeService {
@Override
public boolean saveBatch(AttributeFormDTO attributeForm) {
Long categoryId = attributeForm.getCategoryId();
Integer type = attributeForm.getType();
List<Long> formIds = attributeForm.getAttributes().stream()
.filter(item -> item.getId() != null)
.map(item -> item.getId())
.collect(Collectors.toList());
List<Long> dbIds = this.list(new LambdaQueryWrapper<PmsAttribute>()
.eq(PmsAttribute::getCategoryId, categoryId)
.eq(PmsAttribute::getType, attributeForm.getType())
.select(PmsAttribute::getId)).stream()
.map(item -> item.getId())
.collect(Collectors.toList());
// 删除此次表单没有的属性ID
if (CollectionUtil.isNotEmpty(dbIds)) {
List<Long> rmIds = dbIds.stream()
.filter(id -> CollectionUtil.isEmpty(formIds) || !formIds.contains(id))
.collect(Collectors.toList());
if (CollectionUtil.isNotEmpty(rmIds)) {
this.removeByIds(rmIds);
}
}
// 新增/修改表单提交的属性
List<AttributeFormDTO.Attribute> formAttributes = attributeForm.getAttributes();
List<PmsAttribute> attributeList = new ArrayList<>();
formAttributes.forEach(item -> {
PmsAttribute attribute = PmsAttribute.builder().id(item.getId()).categoryId(categoryId).type(type).name(item.getName()).build();
attributeList.add(attribute);
});
boolean result = this.saveOrUpdateBatch(attributeList);
return result;
}
} }

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.mapper.PmsCategoryBrandMapper;
import com.youlai.mall.pms.pojo.entity.PmsCategoryBrand;
import com.youlai.mall.pms.service.IPmsCategoryBrandService;
import org.springframework.stereotype.Service;
@Service
public class PmsCategoryBrandServiceImpl extends ServiceImpl<PmsCategoryBrandMapper, PmsCategoryBrand> implements IPmsCategoryBrandService {
}

View File

@ -3,7 +3,8 @@ package com.youlai.mall.pms.service.impl;
import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.youlai.common.web.vo.CascaderVO; import com.youlai.common.constant.GlobalConstants;
import com.youlai.common.pojo.vo.CascadeVO;
import com.youlai.mall.pms.pojo.entity.PmsCategory; import com.youlai.mall.pms.pojo.entity.PmsCategory;
import com.youlai.mall.pms.mapper.PmsCategoryMapper; import com.youlai.mall.pms.mapper.PmsCategoryMapper;
import com.youlai.mall.pms.service.IPmsCategoryService; import com.youlai.mall.pms.service.IPmsCategoryService;
@ -17,25 +18,28 @@ import java.util.Optional;
@Service @Service
public class PmsCategoryServiceImpl extends ServiceImpl<PmsCategoryMapper, PmsCategory> implements IPmsCategoryService { public class PmsCategoryServiceImpl extends ServiceImpl<PmsCategoryMapper, PmsCategory> implements IPmsCategoryService {
@Override @Override
public List<CategoryVO> listForTree(PmsCategory category) { public List<CategoryVO> listTreeCategory(Long parentId) {
List<PmsCategory> categoryList = this.list( List<PmsCategory> categoryList = this.list(new LambdaQueryWrapper<PmsCategory>()
new LambdaQueryWrapper<PmsCategory>() .eq(PmsCategory::getVisible, GlobalConstants.STATUS_YES).orderByDesc(PmsCategory::getSort));
.eq(category.getStatus() != null, PmsCategory::getStatus, category.getStatus()) List<CategoryVO> list = recursionTree(parentId != null ? parentId : 0l, categoryList);
.orderByAsc(PmsCategory::getSort)
);
Long parentId = 0l;
if (category.getParentId() != null) {
parentId = category.getParentId();
}
List<CategoryVO> list = recursionForTreeList(parentId, categoryList);
return list; return list;
} }
private static List<CategoryVO> recursionForTreeList(Long parentId, List<PmsCategory> categoryList) { @Override
public List<CascadeVO> listCascadeCategory() {
List<PmsCategory> categoryList = this.list(
new LambdaQueryWrapper<PmsCategory>()
.eq(PmsCategory::getVisible, GlobalConstants.STATUS_YES)
.orderByAsc(PmsCategory::getSort)
);
List<CascadeVO> list = recursionCascade(0l, categoryList);
return list;
}
private static List<CategoryVO> recursionTree(Long parentId, List<PmsCategory> categoryList) {
List<CategoryVO> list = new ArrayList<>(); List<CategoryVO> list = new ArrayList<>();
Optional.ofNullable(categoryList) Optional.ofNullable(categoryList)
.ifPresent(categories -> .ifPresent(categories ->
@ -44,40 +48,31 @@ public class PmsCategoryServiceImpl extends ServiceImpl<PmsCategoryMapper, PmsCa
.forEach(category -> { .forEach(category -> {
CategoryVO categoryVO = new CategoryVO(); CategoryVO categoryVO = new CategoryVO();
BeanUtil.copyProperties(category, categoryVO); BeanUtil.copyProperties(category, categoryVO);
List<CategoryVO> children = recursionForTreeList(category.getId(), categoryList); List<CategoryVO> children = recursionTree(category.getId(), categoryList);
categoryVO.setChildren(children); categoryVO.setChildren(children);
list.add(categoryVO); list.add(categoryVO);
})); }));
return list; return list;
} }
private List<CascadeVO> recursionCascade(Long parentId, List<PmsCategory> categoryList) {
@Override List<CascadeVO> list = new ArrayList<>();
public List<CascaderVO> listForCascader(PmsCategory category) {
List<PmsCategory> categoryList = this.list(
new LambdaQueryWrapper<PmsCategory>()
.eq(category.getStatus() != null, PmsCategory::getStatus, category.getStatus())
);
List<CascaderVO> list = recursionForCascaderList(0l, categoryList);
return list;
}
private List<CascaderVO> recursionForCascaderList(Long parentId, List<PmsCategory> categoryList) {
List<CascaderVO> list = new ArrayList<>();
Optional.ofNullable(categoryList) Optional.ofNullable(categoryList)
.ifPresent(categories -> .ifPresent(categories ->
categories.stream().filter(category -> categories.stream().filter(category ->
category.getParentId().equals(parentId)) category.getParentId().equals(parentId))
.forEach(category -> { .forEach(category -> {
CascaderVO categoryVO = new CascaderVO() CascadeVO categoryVO = new CascadeVO()
.setLabel(category.getName()) .setLabel(category.getName())
.setValue(category.getId().toString()); .setValue(category.getId().toString());
BeanUtil.copyProperties(category, categoryVO); BeanUtil.copyProperties(category, categoryVO);
List<CascaderVO> children = recursionForCascaderList(category.getId(), categoryList); List<CascadeVO> children = recursionCascade(category.getId(), categoryList);
categoryVO.setChildren(children); categoryVO.setChildren(children);
list.add(categoryVO); list.add(categoryVO);
}) })
); );
return list; return list;
} }
} }

View File

@ -1,23 +0,0 @@
package com.youlai.mall.pms.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.youlai.mall.pms.mapper.PmsSpecMapper;
import com.youlai.mall.pms.pojo.entity.PmsSpec;
import com.youlai.mall.pms.service.IPmsSpecService;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* @author haoxr
* @date 2020-11-06
*/
@Service
public class PmsSpecServiceImpl extends ServiceImpl<PmsSpecMapper, PmsSpec> implements IPmsSpecService {
@Override
public List<PmsSpec> listBySpuId(Long spuId) {
List<PmsSpec> list = this.baseMapper.listBySpuId(spuId);
return list;
}
}

View File

@ -24,16 +24,14 @@ import java.util.stream.Collectors;
import static com.youlai.mall.pms.common.constant.PmsConstants.PRODUCT_REDIS_BLOOM_FILTER; import static com.youlai.mall.pms.common.constant.PmsConstants.PRODUCT_REDIS_BLOOM_FILTER;
/** /**
* @author haoxr * @author <a href="mailto:xianrui0365@163.com">xianrui</a>
* @date 2020-11-06
*/ */
@Service @Service
@AllArgsConstructor @AllArgsConstructor
public class PmsSpuServiceImpl extends ServiceImpl<PmsSpuMapper, PmsSpu> implements IPmsSpuService { public class PmsSpuServiceImpl extends ServiceImpl<PmsSpuMapper, PmsSpu> implements IPmsSpuService {
private IPmsSkuService iPmsSkuService; private IPmsSkuService iPmsSkuService;
private IPmsSpuAttributeValueService iPmsSpuAttributeValueService; private IPmsSpuAttributeValueService iPmsSpuAttributeValueService;
private IPmsSpuSpecValueService iPmsSpuSpecValueService; private IPmsAttributeService attributeService;
private IPmsSpecService iPmsSpecService;
private BloomRedisService bloomRedisService; private BloomRedisService bloomRedisService;
@ -49,7 +47,7 @@ public class PmsSpuServiceImpl extends ServiceImpl<PmsSpuMapper, PmsSpu> impleme
public boolean add(ProductFormDTO productFormDTO) { public boolean add(ProductFormDTO productFormDTO) {
SpuDTO SpuDTO = productFormDTO.getSpu(); SpuDTO SpuDTO = productFormDTO.getSpu();
List<PmsSpuAttributeValue> attrValues = productFormDTO.getAttrs(); List<PmsSpuAttributeValue> attrValues = productFormDTO.getAttrs();
List<PmsSpuSpecValue> specs = productFormDTO.getSpecs(); List<PmsSpuAttributeValue> specs = productFormDTO.getAttrs();
List<PmsSku> skuList = productFormDTO.getSkus(); List<PmsSku> skuList = productFormDTO.getSkus();
// spu保存 // spu保存
@ -57,7 +55,7 @@ public class PmsSpuServiceImpl extends ServiceImpl<PmsSpuMapper, PmsSpu> impleme
BeanUtil.copyProperties(SpuDTO, spu); BeanUtil.copyProperties(SpuDTO, spu);
if (SpuDTO.getPics() != null) { if (SpuDTO.getPics() != null) {
String picUrls = JSONUtil.toJsonStr(SpuDTO.getPics()); String picUrls = JSONUtil.toJsonStr(SpuDTO.getPics());
spu.setPics(picUrls); spu.setAlbum(picUrls);
} }
this.save(spu); this.save(spu);
@ -69,8 +67,8 @@ public class PmsSpuServiceImpl extends ServiceImpl<PmsSpuMapper, PmsSpu> impleme
// 规格保存 // 规格保存
Optional.ofNullable(specs).ifPresent(list -> { Optional.ofNullable(specs).ifPresent(list -> {
list.forEach(item -> item.setSpuId(spu.getId())); /* list.forEach(item -> item.setSpuId(spu.getId()));
iPmsSpuSpecValueService.saveBatch(list); iPmsSpuSpecValueService.saveBatch(list);*/
}); });
// sku保存 // sku保存
@ -89,9 +87,9 @@ public class PmsSpuServiceImpl extends ServiceImpl<PmsSpuMapper, PmsSpu> impleme
PmsSpu spu = this.getById(id); PmsSpu spu = this.getById(id);
BeanUtil.copyProperties(spu, spuDTO); BeanUtil.copyProperties(spu, spuDTO);
if (StrUtil.isNotBlank(spu.getPics())) { if (StrUtil.isNotBlank(spu.getAlbum())) {
// spu专辑图片转换处理 json字符串 -> List // spu专辑图片转换处理 json字符串 -> List
List<String> pics = JSONUtil.toList(JSONUtil.parseArray(spu.getPics()), String.class); List<String> pics = JSONUtil.toList(JSONUtil.parseArray(spu.getAlbum()), String.class);
spuDTO.setPics(pics); spuDTO.setPics(pics);
} }
@ -99,12 +97,13 @@ public class PmsSpuServiceImpl extends ServiceImpl<PmsSpuMapper, PmsSpu> impleme
List<PmsSpuAttributeValue> attrs = iPmsSpuAttributeValueService. List<PmsSpuAttributeValue> attrs = iPmsSpuAttributeValueService.
list(new LambdaQueryWrapper<PmsSpuAttributeValue>().eq(PmsSpuAttributeValue::getSpuId, id)); list(new LambdaQueryWrapper<PmsSpuAttributeValue>().eq(PmsSpuAttributeValue::getSpuId, id));
// 规格 // 规格
List<PmsSpuSpecValue> specs = iPmsSpuSpecValueService.list(new LambdaQueryWrapper<PmsSpuSpecValue>().eq(PmsSpuSpecValue::getSpuId, id)); List<PmsSpuAttributeValue> specs = iPmsSpuAttributeValueService.list(new LambdaQueryWrapper<PmsSpuAttributeValue>().eq(PmsSpuAttributeValue::getSpuId, id));
// sku // sku
List<PmsSku> skus = iPmsSkuService.list(new LambdaQueryWrapper<PmsSku>().eq(PmsSku::getSpuId, id)); List<PmsSku> skus = iPmsSkuService.list(new LambdaQueryWrapper<PmsSku>().eq(PmsSku::getSpuId, id));
// 组合 // 组合
ProductFormDTO productFormDTO = new ProductFormDTO(spuDTO, attrs, specs, skus); // ProductFormDTO productFormDTO = new ProductFormDTO(spuDTO, attrs, specs, skus);
ProductFormDTO productFormDTO = new ProductFormDTO();
return productFormDTO; return productFormDTO;
} }
@ -114,7 +113,7 @@ public class PmsSpuServiceImpl extends ServiceImpl<PmsSpuMapper, PmsSpu> impleme
SpuDTO SpuDTO = productFormDTO.getSpu(); SpuDTO SpuDTO = productFormDTO.getSpu();
List<PmsSpuAttributeValue> attrValues = productFormDTO.getAttrs(); List<PmsSpuAttributeValue> attrValues = productFormDTO.getAttrs();
List<PmsSpuSpecValue> specs = productFormDTO.getSpecs(); List<PmsSpuAttributeValue> specs = productFormDTO.getAttrs();
List<PmsSku> skuList = productFormDTO.getSkus(); List<PmsSku> skuList = productFormDTO.getSkus();
// spu保存 // spu保存
@ -122,7 +121,7 @@ public class PmsSpuServiceImpl extends ServiceImpl<PmsSpuMapper, PmsSpu> impleme
BeanUtil.copyProperties(SpuDTO, spu); BeanUtil.copyProperties(SpuDTO, spu);
if (SpuDTO.getPics() != null) { if (SpuDTO.getPics() != null) {
String pics = JSONUtil.toJsonStr(SpuDTO.getPics()); String pics = JSONUtil.toJsonStr(SpuDTO.getPics());
spu.setPics(pics); spu.setAlbum(pics);
} }
this.updateById(spu); this.updateById(spu);
@ -149,15 +148,15 @@ public class PmsSpuServiceImpl extends ServiceImpl<PmsSpuMapper, PmsSpu> impleme
// 删除此次保存删除的 // 删除此次保存删除的
List<Long> ids = list.stream().map(item -> item.getId()).collect(Collectors.toList()); 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()) List<Long> dbIds = iPmsSpuAttributeValueService.list(new LambdaQueryWrapper<PmsSpuAttributeValue>().eq(PmsSpuAttributeValue::getSpuId, spu.getId())
.select(PmsSpuSpecValue::getId)) .select(PmsSpuAttributeValue::getId))
.stream() .stream()
.map(item -> item.getId()) .map(item -> item.getId())
.collect(Collectors.toList()); .collect(Collectors.toList());
List<Long> removeIds = dbIds.stream().filter(id -> !ids.contains(id)).collect(Collectors.toList()); List<Long> removeIds = dbIds.stream().filter(id -> !ids.contains(id)).collect(Collectors.toList());
iPmsSpuSpecValueService.removeByIds(removeIds); iPmsSpuAttributeValueService.removeByIds(removeIds);
iPmsSpuSpecValueService.saveOrUpdateBatch(list); iPmsSpuAttributeValueService.saveOrUpdateBatch(list);
}); });
// sku保存 // sku保存
@ -186,7 +185,7 @@ public class PmsSpuServiceImpl extends ServiceImpl<PmsSpuMapper, PmsSpu> impleme
// sku // sku
iPmsSkuService.remove(new LambdaQueryWrapper<PmsSku>().eq(PmsSku::getSpuId, spuId)); iPmsSkuService.remove(new LambdaQueryWrapper<PmsSku>().eq(PmsSku::getSpuId, spuId));
// 规格 // 规格
iPmsSpuSpecValueService.remove(new LambdaQueryWrapper<PmsSpuSpecValue>().eq(PmsSpuSpecValue::getId, spuId)); iPmsSpuAttributeValueService.remove(new LambdaQueryWrapper<PmsSpuAttributeValue>().eq(PmsSpuAttributeValue::getId, spuId));
// 属性 // 属性
iPmsSpuAttributeValueService.remove(new LambdaQueryWrapper<PmsSpuAttributeValue>().eq(PmsSpuAttributeValue::getSpuId, spuId)); iPmsSpuAttributeValueService.remove(new LambdaQueryWrapper<PmsSpuAttributeValue>().eq(PmsSpuAttributeValue::getSpuId, spuId));
// spu // spu
@ -202,9 +201,9 @@ public class PmsSpuServiceImpl extends ServiceImpl<PmsSpuMapper, PmsSpu> impleme
PmsSpu spu = this.getById(spuId); PmsSpu spu = this.getById(spuId);
SpuDTO SpuDTO = new SpuDTO(); SpuDTO SpuDTO = new SpuDTO();
BeanUtil.copyProperties(spu, SpuDTO); BeanUtil.copyProperties(spu, SpuDTO);
if (StrUtil.isNotBlank(spu.getPics())) { if (StrUtil.isNotBlank(spu.getAlbum())) {
// spu专辑图片转换处理 json字符串 -> List // spu专辑图片转换处理 json字符串 -> List
List<String> pics = JSONUtil.toList(JSONUtil.parseArray(spu.getPics()), String.class); List<String> pics = JSONUtil.toList(JSONUtil.parseArray(spu.getAlbum()), String.class);
SpuDTO.setPics(pics); SpuDTO.setPics(pics);
} }
// 属性 // 属性
@ -214,12 +213,13 @@ public class PmsSpuServiceImpl extends ServiceImpl<PmsSpuMapper, PmsSpu> impleme
); );
// 规格 // 规格
List<PmsSpec> specs = iPmsSpecService.listBySpuId(spuId); // List<PmsAttribute> specs = attributeService.listBySpuId(spuId);
List<PmsAttribute> specs = null;
// sku // sku
List<PmsSku> skuList = iPmsSkuService.list(new LambdaQueryWrapper<PmsSku>().eq(PmsSku::getSpuId, spuId)); 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(SpuDTO, attrs, specs, skuList);
com.youlai.mall.pms.pojo.dto.app.ProductFormDTO product=new com.youlai.mall.pms.pojo.dto.app.ProductFormDTO();
return product; return product;
} }
} }

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.entity.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

@ -10,12 +10,12 @@ import com.youlai.mall.pms.config.ProductLocalCache;
import com.youlai.mall.pms.mapper.PmsSpuMapper; import com.youlai.mall.pms.mapper.PmsSpuMapper;
import com.youlai.mall.pms.pojo.dto.SpuDTO; import com.youlai.mall.pms.pojo.dto.SpuDTO;
import com.youlai.mall.pms.pojo.dto.app.ProductFormDTO; 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; import com.youlai.mall.pms.pojo.entity.PmsSku;
import com.youlai.mall.pms.pojo.entity.PmsSpec;
import com.youlai.mall.pms.pojo.entity.PmsSpu; import com.youlai.mall.pms.pojo.entity.PmsSpu;
import com.youlai.mall.pms.pojo.entity.PmsSpuAttributeValue; import com.youlai.mall.pms.pojo.entity.PmsSpuAttributeValue;
import com.youlai.mall.pms.service.IPmsAttributeService;
import com.youlai.mall.pms.service.IPmsSkuService; import com.youlai.mall.pms.service.IPmsSkuService;
import com.youlai.mall.pms.service.IPmsSpecService;
import com.youlai.mall.pms.service.IPmsSpuAttributeValueService; import com.youlai.mall.pms.service.IPmsSpuAttributeValueService;
import com.youlai.mall.pms.service.IProductService; import com.youlai.mall.pms.service.IProductService;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
@ -40,7 +40,7 @@ public class ProductServiceImpl extends ServiceImpl<PmsSpuMapper, PmsSpu> implem
private final IPmsSkuService iPmsSkuService; private final IPmsSkuService iPmsSkuService;
private final IPmsSpuAttributeValueService iPmsSpuAttributeValueService; private final IPmsSpuAttributeValueService iPmsSpuAttributeValueService;
private final IPmsSpecService iPmsSpecService; private final IPmsAttributeService iPmsSpecService;
private final RedisUtils redisUtils; private final RedisUtils redisUtils;
private final RedissonClient redissonClient; private final RedissonClient redissonClient;
private final ProductLocalCache productLocalCache; private final ProductLocalCache productLocalCache;
@ -68,9 +68,9 @@ public class ProductServiceImpl extends ServiceImpl<PmsSpuMapper, PmsSpu> implem
PmsSpu spu = this.getById(spuId); PmsSpu spu = this.getById(spuId);
SpuDTO SpuDTO = new SpuDTO(); SpuDTO SpuDTO = new SpuDTO();
BeanUtil.copyProperties(spu, SpuDTO); BeanUtil.copyProperties(spu, SpuDTO);
if (StrUtil.isNotBlank(spu.getPics())) { if (StrUtil.isNotBlank(spu.getAlbum())) {
// spu专辑图片转换处理 json字符串 -> List // spu专辑图片转换处理 json字符串 -> List
List<String> pics = JSONUtil.toList(JSONUtil.parseArray(spu.getPics()), String.class); List<String> pics = JSONUtil.toList(JSONUtil.parseArray(spu.getAlbum()), String.class);
SpuDTO.setPics(pics); SpuDTO.setPics(pics);
} }
// 属性 // 属性
@ -79,11 +79,14 @@ public class ProductServiceImpl extends ServiceImpl<PmsSpuMapper, PmsSpu> implem
).eq(PmsSpuAttributeValue::getSpuId, spuId) ).eq(PmsSpuAttributeValue::getSpuId, spuId)
); );
// 规格 // 规格
List<PmsSpec> specs = iPmsSpecService.listBySpuId(spuId); // List<PmsSpec> specs = iPmsSpecService.listBySpuId(spuId);
List<PmsAttribute> specs=null;
// sku // sku
List<PmsSku> skuList = iPmsSkuService.list(new LambdaQueryWrapper<PmsSku>().eq(PmsSku::getSpuId, spuId)); List<PmsSku> skuList = iPmsSkuService.list(new LambdaQueryWrapper<PmsSku>().eq(PmsSku::getSpuId, spuId));
product = new ProductFormDTO(SpuDTO, attrs, specs, skuList); // product = new ProductFormDTO(SpuDTO, attrs, specs, skuList);
product = new ProductFormDTO();
//TODO 4需要判断商品是否是秒杀商品根据秒杀信息更新商品秒杀相关信息 //TODO 4需要判断商品是否是秒杀商品根据秒杀信息更新商品秒杀相关信息
log.info("get db product:" + product); log.info("get db product:" + product);
redisUtils.set(PRODUCT_DETAIL_CACHE + spuId, product, 3600); redisUtils.set(PRODUCT_DETAIL_CACHE + spuId, product, 3600);

View File

@ -0,0 +1,28 @@
<?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">
<resultMap id="BaseResultMap" type="com.youlai.mall.pms.pojo.entity.PmsSku">
<id property="id" column="id" jdbcType="BIGINT"/>
<result property="spuId" column="spu_id" jdbcType="BIGINT"/>
<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="originPrice" column="origin_price" jdbcType="BIGINT"/>
<result property="price" column="price" jdbcType="BIGINT"/>
<result property="stock" column="stock" jdbcType="INTEGER"/>
<result property="lockedStock" column="locked_stock" jdbcType="INTEGER"/>
<result property="gmtCreate" column="gmt_create" jdbcType="TIMESTAMP"/>
<result property="gmtModified" column="gmt_modified" jdbcType="TIMESTAMP"/>
</resultMap>
<sql id="Base_Column_List">
id,spu_id,name,
sn,pic_url,specifications,
origin_price,price,stock,
locked_stock,gmt_create,gmt_modified
</sql>
</mapper>

View File

@ -0,0 +1,58 @@
<?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.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>
</collection>
</resultMap>
<sql id="Base_Column_List">
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>
</mapper>

View File

@ -1,75 +0,0 @@
package com.youlai.mall.pms.controller;
import com.youlai.common.result.ResultCode;
import com.youlai.mall.pms.pojo.dto.app.ProductFormDTO;
import com.youlai.mall.pms.controller.admin.SpuController;
import com.youlai.mall.pms.pojo.entity.PmsSpec;
import com.youlai.mall.pms.service.IPmsSpuAttributeValueService;
import com.youlai.mall.pms.service.IPmsSpecService;
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.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.HttpMethod;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.MvcResult;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
import java.util.List;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
@AutoConfigureMockMvc
@SpringBootTest
@Slf4j
public class ProductControllerTest {
@Autowired
public MockMvc mockMvc;
@Autowired
public SpuController spuController;
@Test
public void saveGoods() throws Exception {
String goods = "{\"spu\":{\"name\":\"小米手机10\",\"categoryId\":\"8\",\"brandId\":\"1\",\"originPrice\":599900,\"price\":499900,\"pic\":\"http://101.37.69.49:9000/default/40ffc46040ca431aba23c48798a82bb8.jpg\",\"album\":\"[\\\"http://101.37.69.49:9000/default/dbb1c4e37b6244f3a6b0f635db90bf54.jpg\\\"]\",\"unit\":\"\",\"description\":\"商品简介\",\"detail\":\"<p>商品详情</p>\",\"status\":1},\"attributes\":[{\"name\":\"上市时间\",\"value\":\"2020-10-10\"}],\"specifications\":[{\"name\":\"颜色\",\"value\":\"黑色\"},{\"name\":\"颜色\",\"value\":\"白色\"},{\"name\":\"内存\",\"value\":\"4G\"},{\"name\":\"内存\",\"value\":\"6G\"},{\"name\":\"存储\",\"value\":\"64G\"},{\"name\":\"存储\",\"value\":\"128G\"}],\"skuList\":[{\"颜色\":\"黑色\",\"内存\":\"4G\",\"存储\":\"64G\",\"price\":401,\"originPrice\":1,\"stock\":2,\"pic\":\"http://101.37.69.49:9000/default/d7c36e289eb14dcea67d20ebcac79d87.jpg\",\"barCode\":\"1605317058485\",\"specification\":\"{\\\"颜色\\\":\\\"黑色\\\",\\\"内存\\\":\\\"4G\\\",\\\"存储\\\":\\\"64G\\\"}\"},{\"颜色\":\"黑色\",\"内存\":\"4G\",\"存储\":\"128G\",\"price\":301,\"originPrice\":1,\"stock\":1,\"pic\":\"http://101.37.69.49:9000/default/29697a3f43f64172b91b4d1d241ca602.jpg\",\"barCode\":\"1605317059016\",\"specification\":\"{\\\"颜色\\\":\\\"黑色\\\",\\\"内存\\\":\\\"4G\\\",\\\"存储\\\":\\\"128G\\\"}\"},{\"颜色\":\"黑色\",\"内存\":\"6G\",\"存储\":\"64G\",\"price\":200.99999999999997,\"originPrice\":1,\"stock\":1,\"pic\":\"http://101.37.69.49:9000/default/d4b46f2405b54635bb1c0589f68a74e6.png\",\"barCode\":\"1605317059753\",\"specification\":\"{\\\"颜色\\\":\\\"黑色\\\",\\\"内存\\\":\\\"6G\\\",\\\"存储\\\":\\\"64G\\\"}\"},{\"颜色\":\"黑色\",\"内存\":\"6G\",\"存储\":\"128G\",\"price\":301,\"originPrice\":1,\"stock\":1,\"pic\":\"http://101.37.69.49:9000/default/432579106d32465296f930d15eafd466.png\",\"barCode\":\"1605317060895\",\"specification\":\"{\\\"颜色\\\":\\\"黑色\\\",\\\"内存\\\":\\\"6G\\\",\\\"存储\\\":\\\"128G\\\"}\"},{\"颜色\":\"白色\",\"内存\":\"4G\",\"存储\":\"64G\",\"price\":200.99999999999997,\"originPrice\":2.01,\"stock\":1,\"pic\":\"http://101.37.69.49:9000/default/f5eb5e307adf439cb7da0f847f4ddace.png\",\"barCode\":\"1605317061416\",\"specification\":\"{\\\"颜色\\\":\\\"白色\\\",\\\"内存\\\":\\\"4G\\\",\\\"存储\\\":\\\"64G\\\"}\"},{\"颜色\":\"白色\",\"内存\":\"4G\",\"存储\":\"128G\",\"price\":200.99999999999997,\"originPrice\":1.01,\"stock\":1,\"pic\":\"http://101.37.69.49:9000/default/9de00b77c06245538572c09ad689dfda.jpg\",\"specification\":\"{\\\"颜色\\\":\\\"白色\\\",\\\"内存\\\":\\\"4G\\\",\\\"存储\\\":\\\"128G\\\"}\"},{\"颜色\":\"白色\",\"内存\":\"6G\",\"存储\":\"64G\",\"price\":200.99999999999997,\"originPrice\":1.01,\"stock\":1,\"pic\":\"http://101.37.69.49:9000/default/d48ac97541f44cea8087b8f26da588c4.jpg\",\"barCode\":\"1605317062900\",\"specification\":\"{\\\"颜色\\\":\\\"白色\\\",\\\"内存\\\":\\\"6G\\\",\\\"存储\\\":\\\"64G\\\"}\"},{\"颜色\":\"白色\",\"内存\":\"6G\",\"存储\":\"128G\",\"price\":301,\"originPrice\":0.01,\"stock\":1,\"pic\":\"http://101.37.69.49:9000/default/9b2a4dfae67b44b89cc9589de691ee8d.jpg\",\"barCode\":\"1605317063290\",\"specification\":\"{\\\"颜色\\\":\\\"白色\\\",\\\"内存\\\":\\\"6G\\\",\\\"存储\\\":\\\"128G\\\"}\"}]}";
MvcResult result = mockMvc.perform(MockMvcRequestBuilders.request(HttpMethod.POST, "/goods")
.contentType("application/json")
.content(goods))
.andExpect(MockMvcResultMatchers.status().isOk())
.andExpect(MockMvcResultMatchers.jsonPath("$.code").value(ResultCode.SUCCESS.getCode()))
.andDo(print())
.andReturn();
log.info(result.getResponse().getContentAsString());
}
@Autowired
public IPmsSpecService iPmsSpecService;
@Test
public void getProductSpecList() {
List<PmsSpec> specifications = iPmsSpecService.listBySpuId(1l);
log.info(specifications.toString());
}
@Autowired
public IPmsSpuAttributeValueService iPmsSpuAttributeValueService;
@Autowired
private IPmsSpuService iPmsSpuService;
@Test
public void getProduct() {
ProductFormDTO product = iPmsSpuService.getProductByIdForApp(1l);
log.info(product.toString());
}
}

View File

@ -3,7 +3,7 @@ package com.youlai.admin.common.util;
import cn.hutool.json.JSONUtil; import cn.hutool.json.JSONUtil;
import com.nimbusds.jose.JWSObject; import com.nimbusds.jose.JWSObject;
import com.youlai.common.constant.AuthConstants; import com.youlai.common.constant.AuthConstants;
import com.youlai.common.domain.JWTPayload; import com.youlai.common.pojo.JwtPayload;
import lombok.SneakyThrows; import lombok.SneakyThrows;
import org.apache.logging.log4j.util.Strings; import org.apache.logging.log4j.util.Strings;
@ -20,10 +20,10 @@ public class JWTUtils {
* @return * @return
*/ */
@SneakyThrows @SneakyThrows
public static JWTPayload getJWTPayload(String token) { public static JwtPayload getJWTPayload(String token) {
token = token.replace(AuthConstants.AUTHORIZATION_PREFIX, Strings.EMPTY); token = token.replace(AuthConstants.AUTHORIZATION_PREFIX, Strings.EMPTY);
JWSObject jwsObject = JWSObject.parse(token); JWSObject jwsObject = JWSObject.parse(token);
JWTPayload payload = JSONUtil.toBean(jwsObject.getPayload().toString(), JWTPayload.class); JwtPayload payload = JSONUtil.toBean(jwsObject.getPayload().toString(), JwtPayload.class);
return payload; return payload;
} }
@ -33,7 +33,7 @@ public class JWTUtils {
* @return * @return
*/ */
public static boolean isExpired(String token) { public static boolean isExpired(String token) {
JWTPayload payload = getJWTPayload(token); JwtPayload payload = getJWTPayload(token);
// 计算是否过期 // 计算是否过期
long currentTimeSeconds = System.currentTimeMillis() / 1000; long currentTimeSeconds = System.currentTimeMillis() / 1000;
Long exp = payload.getExp(); Long exp = payload.getExp();

View File

@ -4,7 +4,7 @@ package com.youlai.admin.service.impl;
import com.youlai.admin.common.util.JWTUtils; import com.youlai.admin.common.util.JWTUtils;
import com.youlai.admin.service.ITokenService; import com.youlai.admin.service.ITokenService;
import com.youlai.common.constant.AuthConstants; import com.youlai.common.constant.AuthConstants;
import com.youlai.common.domain.JWTPayload; import com.youlai.common.pojo.JwtPayload;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.SneakyThrows; import lombok.SneakyThrows;
import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.RedisTemplate;
@ -27,7 +27,7 @@ public class TokenServiceImpl implements ITokenService {
@SneakyThrows @SneakyThrows
public boolean invalidateToken(String token) { public boolean invalidateToken(String token) {
JWTPayload payload = JWTUtils.getJWTPayload(token); JwtPayload payload = JWTUtils.getJWTPayload(token);
// 计算是否过期 // 计算是否过期
long currentTimeSeconds = System.currentTimeMillis() / 1000; long currentTimeSeconds = System.currentTimeMillis() / 1000;
@ -42,7 +42,7 @@ public class TokenServiceImpl implements ITokenService {
@Override @Override
public int getTokenStatus(String token) { public int getTokenStatus(String token) {
JWTPayload payload = JWTUtils.getJWTPayload(token); JwtPayload payload = JWTUtils.getJWTPayload(token);
// 计算是否过期 // 计算是否过期
long currentTimeSeconds = System.currentTimeMillis() / 1000; long currentTimeSeconds = System.currentTimeMillis() / 1000;

View File

@ -1,13 +1,15 @@
package com.youlai.common.domain; package com.youlai.common.pojo;
import lombok.Data; import lombok.Data;
/** /**
* JWT载体
*
* @author hxr * @author hxr
* @date 2021-03-10 * @date 2021-03-10
*/ */
@Data @Data
public class JWTPayload { public class JwtPayload {
private String jti; private String jti;

View File

@ -1,18 +1,21 @@
package com.youlai.common.web.vo; package com.youlai.common.pojo.vo;
import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data; import lombok.Data;
import lombok.experimental.Accessors; import lombok.experimental.Accessors;
import java.util.List; import java.util.List;
/**
* 级联试图对象
*/
@Data @Data
@Accessors(chain = true) @Accessors(chain = true)
public class CascaderVO { public class CascadeVO {
private String value; private String value;
private String label; private String label;
@JsonInclude(JsonInclude.Include.NON_EMPTY) @JsonInclude(JsonInclude.Include.NON_EMPTY)
private List<CascaderVO> children; private List<CascadeVO> children;
} }

View File

@ -2,7 +2,6 @@ package com.youlai.common.result;
/** /**
* @author haoxr * @author haoxr
* @date 2020-06-23
**/ **/
public interface IResultCode { public interface IResultCode {

View File

@ -1,16 +1,17 @@
package com.youlai.common.result; package com.youlai.common.result;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data; import lombok.Data;
import java.io.Serializable; import java.io.Serializable;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
/** /**
* @author haoxr * @author haoxr
* @date 2020-06-23
**/ **/
@Data @Data
// 忽略null值
@JsonInclude(JsonInclude.Include.NON_NULL) @JsonInclude(JsonInclude.Include.NON_NULL)
public class Result<T> implements Serializable { public class Result<T> implements Serializable {
@ -44,6 +45,8 @@ public class Result<T> implements Serializable {
return result; return result;
} }
public static <T> Result<T> failed() { public static <T> Result<T> failed() {
return result(ResultCode.SYSTEM_EXECUTION_ERROR.getCode(), ResultCode.SYSTEM_EXECUTION_ERROR.getMsg(), null); return result(ResultCode.SYSTEM_EXECUTION_ERROR.getCode(), ResultCode.SYSTEM_EXECUTION_ERROR.getMsg(), null);
} }

View File

@ -1,6 +1,5 @@
package com.youlai.common.result; package com.youlai.common.result;
import com.youlai.common.enums.QueryModeEnum;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;

View File

@ -10,8 +10,11 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.annotation.EnableTransactionManagement; import org.springframework.transaction.annotation.EnableTransactionManagement;
/**
* @author <a href="mailto:xianrui0365@163.com">xianrui</a>
*/
@Configuration @Configuration
@Slf4j
@EnableTransactionManagement @EnableTransactionManagement
public class MybatisPlusConfig { public class MybatisPlusConfig {

View File

@ -13,13 +13,13 @@ public class FieldFillHandler implements MetaObjectHandler {
@Override @Override
public void insertFill(MetaObject metaObject) { public void insertFill(MetaObject metaObject) {
this.setFieldValByName("createTime", new Date(), metaObject); this.setFieldValByName("gmtCreate", new Date(), metaObject);
this.setFieldValByName("updateTime", new Date(), metaObject); this.setFieldValByName("gmtModified", new Date(), metaObject);
} }
@Override @Override
public void updateFill(MetaObject metaObject) { public void updateFill(MetaObject metaObject) {
this.setFieldValByName("updateTime", new Date(), metaObject); this.setFieldValByName("gmtModified", new Date(), metaObject);
} }
} }

View File

@ -17,6 +17,11 @@
<artifactId>common-core</artifactId> <artifactId>common-core</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId> <artifactId>spring-boot-starter-web</artifactId>