refactor:商品分类接口优化完善

This commit is contained in:
haoxr 2021-02-27 23:39:25 +08:00
parent ac97045bb2
commit 538da1f3e1
7 changed files with 38 additions and 26 deletions

View File

@ -3,19 +3,19 @@ package com.youlai.mall.pms.pojo.domain;
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 PmsCategorySpec {
public class PmsCategorySpec extends BaseEntity {
@TableId(type = IdType.AUTO)
private Long id;
private Long categoryId;
private String name;
private boolean selected;
@TableField(exist = false)
private List<PmsSpuSpecValue> values = new ArrayList<>();

View File

@ -16,17 +16,17 @@ import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.stream.Collectors;
@Api(tags = "【系统管理】分类属性")
@Api(tags = "【系统管理】商品属性")
@RestController
@RequestMapping("/admin-api/v1/attrs")
@RequestMapping("/api.admin/v1/attributes")
@Slf4j
@AllArgsConstructor
public class AttrController {
public class AttributeController {
private IPmsCategoryAttrService iPmsCategoryAttrService;
@ApiOperation(value = "分类属性列表", httpMethod = "GET")
@ApiOperation(value = "商品属性列表", httpMethod = "GET")
@ApiImplicitParams({
@ApiImplicitParam(name = "categoryId", value = "分类ID", paramType = "query", dataType = "Long")
@ -34,13 +34,14 @@ public class AttrController {
@GetMapping
public Result list(Long categoryId) {
List<PmsCategoryAttr> list = iPmsCategoryAttrService
.list(new LambdaQueryWrapper<PmsCategoryAttr>().eq(PmsCategoryAttr::getCategoryId, categoryId));
.list(new LambdaQueryWrapper<PmsCategoryAttr>()
.eq(PmsCategoryAttr::getCategoryId, categoryId));
return Result.success(list);
}
@ApiOperation(value = "新增属性", httpMethod = "POST")
@ApiImplicitParam(name = "attrCategories", value = "实体JSON对象", required = true, paramType = "body", dataType = "PmsAttrCategory")
@ApiImplicitParam(name = "attrCategories", value = "实体JSON对象", required = true, paramType = "body", dataType = "PmsCategoryAttr")
@PostMapping
public Result saveBatch(@RequestBody List<PmsCategoryAttr> attrCategories) {

View File

@ -23,7 +23,7 @@ import java.util.List;
@Api(tags = "【系统管理】品牌接口")
@RestController
@RequestMapping("/brands")
@RequestMapping("/api.admin/v1/brands")
@Slf4j
@AllArgsConstructor
public class BrandController {

View File

@ -6,7 +6,9 @@ import com.youlai.common.enums.QueryModeEnum;
import com.youlai.common.result.Result;
import com.youlai.mall.pms.pojo.domain.PmsCategory;
import com.youlai.mall.pms.pojo.vo.CategoryVO;
import com.youlai.mall.pms.service.IPmsCategoryAttrService;
import com.youlai.mall.pms.service.IPmsCategoryService;
import com.youlai.mall.pms.service.IPmsCategorySpecService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
@ -17,17 +19,22 @@ import org.springframework.web.bind.annotation.*;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
@Api(tags = "【系统管理】商品分类")
@RestController
@RequestMapping("/categories")
@RequestMapping("/api.admin/v1/categories")
@Slf4j
@AllArgsConstructor
public class CategoryController {
private IPmsCategoryService iPmsCategoryService;
private IPmsCategoryAttrService iPmsCategoryAttrService;
private IPmsCategorySpecService iPmsCategorySpecService;
@ApiOperation(value = "列表分页", httpMethod = "GET")
@ApiImplicitParams({
@ApiImplicitParam(name = "queryMode", paramType = "query", dataType = "String"),
@ -82,22 +89,27 @@ public class CategoryController {
@ApiImplicitParam(name = "ids", value = "id集合,以英文逗号','分隔", required = true, paramType = "query", dataType = "String")
@DeleteMapping
public Result delete(@RequestParam String ids) {
iPmsCategoryService.removeByIds(Arrays.asList(ids.split(",")).stream().map(id -> Long.parseLong(id)).collect(Collectors.toList()));
List<String> idList = Arrays.asList(ids.split(","));
Optional.ofNullable(idList).ifPresent(list -> {
list.forEach(id -> {
iPmsCategoryAttrService.removeById(id);
iPmsCategorySpecService.removeById(id);
});
iPmsCategoryService.removeByIds(idList.stream().map(id -> Long.parseLong(id)).collect(Collectors.toList()));
});
return Result.success();
}
@ApiOperation(value = "修改商品分类(部分更新)", httpMethod = "PATCH")
@ApiOperation(value = "修改商品分类", httpMethod = "PATCH")
@ApiImplicitParams({
@ApiImplicitParam(name = "id", value = "用户id", required = true, paramType = "path", dataType = "Long"),
@ApiImplicitParam(name = "category", value = "实体JSON对象", required = true, paramType = "body", dataType = "PmsCategory")
})
@PatchMapping(value = "/{id}")
public Result patch(@PathVariable Integer id, @RequestBody PmsCategory category) {
LambdaUpdateWrapper<PmsCategory> luw = new LambdaUpdateWrapper<PmsCategory>().eq(PmsCategory::getId, id);
if (category.getStatus() != null) { // 状态更新
luw.set(PmsCategory::getStatus, category.getStatus());
}
boolean update = iPmsCategoryService.update(luw);
LambdaUpdateWrapper<PmsCategory> updateWrapper = new LambdaUpdateWrapper<PmsCategory>().eq(PmsCategory::getId, id);
updateWrapper.set(category.getStatus() != null, PmsCategory::getStatus, category.getStatus());
boolean update = iPmsCategoryService.update(updateWrapper);
return Result.success(update);
}
}

View File

@ -18,12 +18,12 @@ import org.springframework.web.bind.annotation.*;
@RequestMapping("/api.admin/v1/inventories")
@Slf4j
@AllArgsConstructor
public class SkuController {
public class InventoryController {
private IPmsSkuService iPmsSkuService;
@ApiOperation(value = "库存明细", httpMethod = "GET")
@ApiImplicitParam(name = "id", value = "商品SKU ID", required = true, paramType = "path", dataType = "Long")
@ApiOperation(value = "商品库存明细", httpMethod = "GET")
@ApiImplicitParam(name = "id", value = "商品SkuID", required = true, paramType = "path", dataType = "Long")
@GetMapping("/{id}")
public Result<SkuDTO> detail(@PathVariable Long id) {
PmsSku sku = iPmsSkuService.getById(id);

View File

@ -96,7 +96,7 @@ public class ProductController {
return Result.success();
}
@ApiOperation(value = "修改商品(部分更新)", httpMethod = "PATCH")
@ApiOperation(value = "修改商品", httpMethod = "PATCH")
@ApiImplicitParams({
@ApiImplicitParam(name = "id", value = "用户id", required = true, paramType = "path", dataType = "Long"),
@ApiImplicitParam(name = "spu", value = "实体JSON对象", required = true, paramType = "body", dataType = "PmsSpu")
@ -104,9 +104,7 @@ public class ProductController {
@PatchMapping(value = "/{id}")
public Result patch(@PathVariable Integer id, @RequestBody PmsSpu spu) {
LambdaUpdateWrapper<PmsSpu> updateWrapper = new LambdaUpdateWrapper<PmsSpu>().eq(PmsSpu::getId, id);
if (spu.getStatus() != null) { // 状态更新
updateWrapper.set(PmsSpu::getStatus, spu.getStatus());
}
updateWrapper.set(spu.getStatus() != null, PmsSpu::getStatus, spu.getStatus());
boolean update = iPmsSpuService.update(updateWrapper);
return Result.success(update);
}

View File

@ -18,7 +18,7 @@ import java.util.stream.Collectors;
@Api(tags = "【系统管理】商品规格")
@RestController
@RequestMapping("/admin-api/v1/specifications")
@RequestMapping("/api.admin/v1/specifications")
@Slf4j
@AllArgsConstructor
public class SpecificationController {
@ -32,7 +32,8 @@ public class SpecificationController {
@GetMapping
public Result list(Long categoryId) {
List<PmsCategorySpec> list = iPmsCategorySpecService
.list(new LambdaQueryWrapper<PmsCategorySpec>().eq(PmsCategorySpec::getCategoryId, categoryId));
.list(new LambdaQueryWrapper<PmsCategorySpec>()
.eq(PmsCategorySpec::getCategoryId, categoryId));
return Result.success(list);
}