商品品牌的迁移,准备和前端管理后台对接

This commit is contained in:
YunaiV
2020-07-25 22:29:38 +08:00
parent 2b8459680b
commit 24f3e697b8
81 changed files with 931 additions and 2169 deletions

View File

@@ -1,26 +0,0 @@
package cn.iocoder.mall.product.application;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.config.ConfigFileApplicationListener;
import org.springframework.scheduling.annotation.EnableAsync;
@SpringBootApplication(scanBasePackages = {"cn.iocoder.mall.product"})
@EnableAsync(proxyTargetClass = true)
public class ProductApplication {
/**
* 设置需要读取的配置文件的名字。
* 基于 {@link org.springframework.boot.context.config.ConfigFileApplicationListener#CONFIG_NAME_PROPERTY} 实现。
*/
private static final String CONFIG_NAME_VALUE = "biz,rest,rpc,application";
public static void main(String[] args) {
// 设置环境变量
System.setProperty(ConfigFileApplicationListener.CONFIG_NAME_PROPERTY, CONFIG_NAME_VALUE);
// 启动 Spring Boot 应用
SpringApplication.run(ProductApplication.class, args);
}
}

View File

@@ -1,113 +0,0 @@
package cn.iocoder.mall.product.application.controller.admins;
import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.mall.product.api.ProductBrandService;
import cn.iocoder.mall.product.api.bo.ProductBrandBO;
import cn.iocoder.mall.product.api.bo.ProductBrangPageBO;
import cn.iocoder.mall.product.api.dto.ProductBrandAddDTO;
import cn.iocoder.mall.product.api.dto.ProductBrandPageDTO;
import cn.iocoder.mall.product.api.dto.ProductBrandUpdateDTO;
import cn.iocoder.mall.product.application.convert.ProductBrandConvert;
import cn.iocoder.mall.product.application.vo.admins.AdminsProductBrandVO;
import cn.iocoder.mall.product.application.vo.admins.AdminsProductBrangPageVO;
import cn.iocoder.mall.security.core.context.AdminSecurityContextHolder;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.*;
import static cn.iocoder.common.framework.vo.CommonResult.success;
@RestController
@RequestMapping("admins/brand")
@Api("商品品牌")
public class AdminsProductBrandController {
@Reference(validation = "true", version = "${dubbo.provider.ProductBrandService.version}")
private ProductBrandService productBrandService;
@PostMapping("/add")
@ApiOperation("创建品牌")
@ApiImplicitParams({
@ApiImplicitParam(name = "name", value = "品牌名称", required = true, example = "安踏"),
@ApiImplicitParam(name = "description", value = "品牌描述", required = true, example = "安踏拖鞋"),
@ApiImplicitParam(name = "picUrl", value = "品牌图片", required = true, example = "http://www.iocoder.cn"),
@ApiImplicitParam(name = "status", value = "状态 1开启 2禁用", required = true, example = "1")
})
public CommonResult<AdminsProductBrandVO> add(@RequestParam("name") String name,
@RequestParam("description") String description,
@RequestParam("picUrl") String picUrl,
@RequestParam("status") Integer status) {
// 创建 ProductBrandAddDTO 对象
ProductBrandAddDTO productBrandAddDTO = new ProductBrandAddDTO().setName(name).setDescription(description)
.setPicUrl(picUrl).setStatus(status);
// 保存商品
ProductBrandBO result = productBrandService.addProductBrand(AdminSecurityContextHolder.getContext().getAdminId(), productBrandAddDTO);
// 返回结果
return success(ProductBrandConvert.INSTANCE.convert(result));
}
@PostMapping("/update")
@ApiOperation("更新商品")
@ApiImplicitParams({
@ApiImplicitParam(name = "id", value = "品牌主键", required = true, example = "1"),
@ApiImplicitParam(name = "name", value = "品牌名称", required = true, example = "安踏"),
@ApiImplicitParam(name = "description", value = "品牌描述", required = true, example = "安踏拖鞋"),
@ApiImplicitParam(name = "picUrl", value = "品牌图片", required = true, example = "http://www.iocoder.cn"),
@ApiImplicitParam(name = "status", value = "状态 1开启 2禁用", required = true, example = "1")
})
public CommonResult<Boolean> update(@RequestParam("id") Integer id,
@RequestParam("name") String name,
@RequestParam("description") String description,
@RequestParam("picUrl") String picUrl,
@RequestParam("status") Integer status) {
// 创建 productBrandUpdateDTO 对象
ProductBrandUpdateDTO productBrandUpdateDTO = new ProductBrandUpdateDTO().setId(id).setName(name).setDescription(description)
.setPicUrl(picUrl).setStatus(status);
// 更新商品
productBrandService.updateProductBrand(AdminSecurityContextHolder.getContext().getAdminId(), productBrandUpdateDTO);
return success(true);
}
@GetMapping("/get")
@ApiOperation("获取品牌")
@ApiImplicitParams({
@ApiImplicitParam(name = "id", value = "品牌主键", required = true, example = "1")
})
public CommonResult<AdminsProductBrandVO> add(@RequestParam("id") Integer id) {
// 保存商品
ProductBrandBO result = productBrandService.getProductBrand(id);
// 返回结果
return success(ProductBrandConvert.INSTANCE.convert(result));
}
@GetMapping("/page")
@ApiOperation("获得品牌分页")
@ApiImplicitParams({
@ApiImplicitParam(name = "name", value = "品牌名称", required = true, example = "安踏"),
@ApiImplicitParam(name = "description", value = "品牌描述", required = true, example = "安踏拖鞋"),
@ApiImplicitParam(name = "status", value = "状态 1开启 2禁用", required = true, example = "1"),
@ApiImplicitParam(name = "pageNo", value = "页码", required = true, example = "1"),
@ApiImplicitParam(name = "pageSize", value = "页面大小", required = true, example = "10")
})
public CommonResult<AdminsProductBrangPageVO> attrPage(@RequestParam(value = "name", required = false) String name,
@RequestParam(value = "description", required = false) String description,
@RequestParam(value = "status", required = false) Integer status,
@RequestParam(value = "pageNo", defaultValue = "1") Integer pageNo,
@RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
// 创建 ProductAttrPageDTO 对象
ProductBrandPageDTO productBrandPageDTO = new ProductBrandPageDTO().setName(name)
.setDescription(description)
.setStatus(status)
.setPageNo(pageNo)
.setPageSize(pageSize);
// 查询分页
ProductBrangPageBO result = productBrandService.getProductBrandPage(productBrandPageDTO);
// 返回结果
return success(ProductBrandConvert.INSTANCE.convert(result));
}
}

View File

@@ -1,126 +0,0 @@
package cn.iocoder.mall.product.application.controller.admins;
import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.mall.product.api.ProductCategoryService;
import cn.iocoder.mall.product.api.bo.ProductCategoryBO;
import cn.iocoder.mall.product.api.constant.ProductCategoryConstants;
import cn.iocoder.mall.product.api.dto.ProductCategoryAddDTO;
import cn.iocoder.mall.product.api.dto.ProductCategoryUpdateDTO;
import cn.iocoder.mall.product.application.convert.ProductCategoryConvert;
import cn.iocoder.mall.product.application.vo.admins.AdminsProductCategoryTreeNodeVO;
import cn.iocoder.mall.product.application.vo.admins.AdminsProductCategoryVO;
import cn.iocoder.mall.security.core.context.AdminSecurityContextHolder;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import static cn.iocoder.common.framework.vo.CommonResult.success;
@RestController
@RequestMapping("admins/category")
@Api("商品分类")
public class AdminsProductCategoryController {
@Reference(validation = "true", version = "${dubbo.provider.ProductCategoryService.version}")
private ProductCategoryService productCategoryService;
@GetMapping("/tree")
@ApiOperation("获得分类树结构")
public CommonResult<List<AdminsProductCategoryTreeNodeVO>> tree() {
List<ProductCategoryBO> productCategories = productCategoryService.getAll();
// 创建 ProductCategoryTreeNodeVO Map
Map<Integer, AdminsProductCategoryTreeNodeVO> treeNodeMap = productCategories.stream().collect(Collectors.toMap(ProductCategoryBO::getId, ProductCategoryConvert.Admins.INSTANCE::convert));
// 处理父子关系
treeNodeMap.values().stream()
.filter(node -> !node.getPid().equals(ProductCategoryConstants.PID_ROOT))
.forEach((childNode) -> {
// 获得父节点
AdminsProductCategoryTreeNodeVO parentNode = treeNodeMap.get(childNode.getPid());
if (parentNode.getChildren() == null) { // 初始化 children 数组
parentNode.setChildren(new ArrayList<>());
}
// 将自己添加到父节点中
parentNode.getChildren().add(childNode);
});
// 获得到所有的根节点
List<AdminsProductCategoryTreeNodeVO> rootNodes = treeNodeMap.values().stream()
.filter(node -> node.getPid().equals(ProductCategoryConstants.PID_ROOT))
.sorted(Comparator.comparing(AdminsProductCategoryTreeNodeVO::getSort))
.collect(Collectors.toList());
return success(rootNodes);
}
@PostMapping("/add")
@ApiOperation(value = "创建商品分类")
@ApiImplicitParams({
@ApiImplicitParam(name = "pid", value = "父级分类编号", required = true, example = "1"),
@ApiImplicitParam(name = "name", value = "分类名字(标识)", required = true, example = "admin/info"),
@ApiImplicitParam(name = "description", value = "描述", required = true, example = "1"),
@ApiImplicitParam(name = "picUrl", value = "分类图片", example = "http://www.iocoder.cn/images/common/wechat_mp_2017_07_31_bak.jpg/"),
@ApiImplicitParam(name = "sort", value = "排序", required = true, example = "1"),
})
public CommonResult<AdminsProductCategoryVO> add(@RequestParam("pid") Integer pid,
@RequestParam("name") String name,
@RequestParam("description") String description,
@RequestParam(value = "picUrl", required = false) String picUrl,
@RequestParam("sort") Integer sort) {
// 创建 ProductCategoryAddDTO 对象
ProductCategoryAddDTO productCategoryAddDTO = new ProductCategoryAddDTO().setPid(pid).setName(name)
.setDescription(description).setPicUrl(picUrl).setSort(sort);
// 创建商品分类
ProductCategoryBO result = productCategoryService.addProductCategory(AdminSecurityContextHolder.getContext().getAdminId(), productCategoryAddDTO);
// 返回结果
return success(ProductCategoryConvert.Admins.INSTANCE.convert2(result));
}
@PostMapping("/update")
@ApiOperation(value = "更新商品分类")
@ApiImplicitParams({
@ApiImplicitParam(name = "id", value = "分类编号", required = true, example = "1"),
@ApiImplicitParam(name = "pid", value = "父级分类编号", required = true, example = "1"),
@ApiImplicitParam(name = "name", value = "分类名字(标识)", required = true, example = "admin/info"),
@ApiImplicitParam(name = "description", value = "描述", required = true, example = "1"),
@ApiImplicitParam(name = "picUrl", value = "分类图片", example = "http://www.iocoder.cn/images/common/wechat_mp_2017_07_31_bak.jpg/"),
@ApiImplicitParam(name = "sort", value = "排序", required = true, example = "1"),
})
public CommonResult<Boolean> update(@RequestParam("id") Integer id,
@RequestParam("pid") Integer pid,
@RequestParam("name") String name,
@RequestParam("description") String description,
@RequestParam(value = "picUrl", required = false) String picUrl,
@RequestParam("sort") Integer sort) {
// 创建 ProductCategoryUpdateDTO 对象
ProductCategoryUpdateDTO productCategoryAddDTO = new ProductCategoryUpdateDTO().setId(id).setPid(pid).setName(name)
.setDescription(description).setPicUrl(picUrl).setSort(sort);
// 更新商品分类
return success(productCategoryService.updateProductCategory(AdminSecurityContextHolder.getContext().getAdminId(), productCategoryAddDTO));
}
@PostMapping("/update_status")
@ApiOperation(value = "更新商品分类状态")
@ApiImplicitParams({
@ApiImplicitParam(name = "id", value = "商品分类编号", required = true, example = "1"),
@ApiImplicitParam(name = "status", value = "状态。1 - 开启2 - 禁用", required = true, example = "1"),
})
public CommonResult<Boolean> updateStatus(@RequestParam("id") Integer id,
@RequestParam("status") Integer status) {
return success(productCategoryService.updateProductCategoryStatus(AdminSecurityContextHolder.getContext().getAdminId(), id, status));
}
@PostMapping("/delete")
@ApiOperation(value = "删除商品分类")
@ApiImplicitParam(name = "id", value = "商品分类编号", required = true, example = "1")
public CommonResult<Boolean> delete(@RequestParam("id") Integer id) {
return success(productCategoryService.deleteProductCategory(AdminSecurityContextHolder.getContext().getAdminId(), id));
}
}

View File

@@ -1,22 +0,0 @@
package cn.iocoder.mall.product.application.convert;
import cn.iocoder.mall.product.api.bo.ProductBrandBO;
import cn.iocoder.mall.product.api.bo.ProductBrangPageBO;
import cn.iocoder.mall.product.application.vo.admins.AdminsProductBrandVO;
import cn.iocoder.mall.product.application.vo.admins.AdminsProductBrangPageVO;
import org.mapstruct.Mapper;
import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers;
@Mapper
public interface ProductBrandConvert {
ProductBrandConvert INSTANCE = Mappers.getMapper(ProductBrandConvert.class);
@Mappings({})
AdminsProductBrandVO convert(ProductBrandBO result);
@Mappings({})
AdminsProductBrangPageVO convert(ProductBrangPageBO result);
}

View File

@@ -1,41 +0,0 @@
package cn.iocoder.mall.product.application.convert;
import cn.iocoder.mall.product.api.bo.ProductCategoryBO;
import cn.iocoder.mall.product.application.vo.admins.AdminsProductCategoryTreeNodeVO;
import cn.iocoder.mall.product.application.vo.admins.AdminsProductCategoryVO;
import cn.iocoder.mall.product.application.vo.users.UsersProductCategoryVO;
import org.mapstruct.Mapper;
import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers;
import java.util.List;
public interface ProductCategoryConvert {
@Mapper
interface Users {
Users INSTANCE = Mappers.getMapper(Users.class);
@Mappings({})
UsersProductCategoryVO convertToVO(ProductCategoryBO category);
@Mappings({})
List<UsersProductCategoryVO> convertToVO(List<ProductCategoryBO> categoryList);
}
@Mapper
interface Admins {
Admins INSTANCE = Mappers.getMapper(Admins.class);
@Mappings({})
AdminsProductCategoryTreeNodeVO convert(ProductCategoryBO category);
@Mappings({})
AdminsProductCategoryVO convert2(ProductCategoryBO result);
}
}

View File

@@ -1,38 +0,0 @@
package cn.iocoder.mall.product.application.vo.admins;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
/**
* 商品品牌 VO
*/
@ApiModel(value = "商品品牌 VO")
@Data
@Accessors(chain = true)
public class AdminsProductBrandVO {
/**
* 品牌编号
*/
@ApiModelProperty(value = "品牌编号", required = true, example = "1")
private Integer id;
@ApiModelProperty(value = "名称", required = true, example = "安踏")
private String name;
@ApiModelProperty(value = "描述", required = true, example = "安踏拖鞋")
private String description;
@ApiModelProperty(value = "图片地址", required = true, example = "http://www.iocoder.cn")
private String picUrl;
@ApiModelProperty(value = "状态 1-开启 2-禁用", required = true, example = "1")
private Integer status;
}

View File

@@ -1,25 +0,0 @@
package cn.iocoder.mall.product.application.vo.admins;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import java.util.List;
/**
* 商品品牌分页 BO
*/
@ApiModel("商品品牌分页")
@Data
@Accessors(chain = true)
public class AdminsProductBrangPageVO {
@ApiModelProperty(value = "品牌数组", required = true)
private List<AdminsProductBrandVO> brands;
@ApiModelProperty(value = "总数", required = true)
private Integer count;
}

View File

@@ -1,35 +0,0 @@
package cn.iocoder.mall.product.application.vo.admins;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import java.util.Date;
import java.util.List;
@ApiModel("产品分类树节点 VO")
@Data
@Accessors(chain = true)
public class AdminsProductCategoryTreeNodeVO {
@ApiModelProperty(value = "分类编号", required = true, example = "1")
private Integer id;
@ApiModelProperty(value = "父分类编号", required = true, example = "0")
private Integer pid;
@ApiModelProperty(value = "分类名", required = true, example = "手机")
private String name;
@ApiModelProperty(value = "描述", required = true, example = "这个商品很吊")
private String description;
@ApiModelProperty(value = "分类图片", notes = "一般情况下,只有根分类才有图片", example = "http://www.iocoder.cn/images/common/wechat_mp_2017_07_31_bak.jpg")
private String picUrl;
@ApiModelProperty(value = "排序值", required = true, example = "10")
private Integer sort;
@ApiModelProperty(value = "状态", required = true, notes = "1-开启2-关闭", example = "1")
private Integer status;
@ApiModelProperty(value = "创建时间", required = true, example = "时间戳")
private Date createTime;
@ApiModelProperty(value = "子节点数组")
private List<AdminsProductCategoryTreeNodeVO> children;
}

View File

@@ -1,32 +0,0 @@
package cn.iocoder.mall.product.application.vo.admins;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import java.util.Date;
@ApiModel("产品分类 VO")
@Data
@Accessors(chain = true)
public class AdminsProductCategoryVO {
@ApiModelProperty(value = "分类编号", required = true, example = "1")
private Integer id;
@ApiModelProperty(value = "父分类编号", required = true, example = "0")
private Integer pid;
@ApiModelProperty(value = "分类名", required = true, example = "手机")
private String name;
@ApiModelProperty(value = "描述", required = true, example = "这个商品很吊")
private String description;
@ApiModelProperty(value = "分类图片", notes = "一般情况下,只有根分类才有图片", example = "http://www.iocoder.cn/images/common/wechat_mp_2017_07_31_bak.jpg")
private String picUrl;
@ApiModelProperty(value = "排序值", required = true, example = "10")
private Integer sort;
@ApiModelProperty(value = "状态", required = true, notes = "1-开启2-关闭", example = "1")
private Integer status;
@ApiModelProperty(value = "创建时间", required = true, example = "时间戳")
private Date createTime;
}

View File

@@ -1,6 +0,0 @@
swagger:
enable: true
title: 商品子系统
description: 商品子系统
version: 1.0.0
base-package: cn.iocoder.mall.product.application.controller

View File

@@ -1,34 +0,0 @@
spring:
application:
name: product-application
# Spring Cloud 配置项
cloud:
# Spring Cloud Sentinel 配置项
sentinel:
transport:
dashboard: s1.iocoder.cn:12088 # Sentinel Dashboard 服务地址
eager: true # 项目启动时,直接连接到 Sentinel
# server
server:
port: 18081
servlet:
context-path: /product-api/
management:
endpoints:
web:
exposure:
include: health,info,env,metrics,prometheus
metrics:
enabled: true
swagger:
enable: true
title: 商品子系统
description: 商品子系统
version: 1.0.0
base-package: cn.iocoder.mall.product.application.controller