From 4207b2b61d6c8b0573b2ceb2e62db9bd8884a7df Mon Sep 17 00:00:00 2001 From: luowenfeng <1092164058@qq.com> Date: Wed, 31 Aug 2022 18:52:26 +0800 Subject: [PATCH] =?UTF-8?q?feature(uniapp=E5=95=86=E5=93=81):=20=E5=95=86?= =?UTF-8?q?=E5=93=81=E5=8A=A0=E8=BD=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/brand/ProductBrandController.java | 15 +++ .../admin/brand/vo/ProductBrandListReqVO.java | 14 +++ .../dal/dataobject/sku/ProductSkuDO.java | 8 +- .../dal/mysql/brand/ProductBrandMapper.java | 9 ++ .../service/brand/ProductBrandService.java | 18 ++- .../brand/ProductBrandServiceImpl.java | 18 ++- .../service/sku/ProductSkuServiceImpl.java | 3 +- .../service/spu/ProductSpuServiceImpl.java | 52 +++++---- yudao-ui-admin/src/api/mall/product/brand.js | 9 ++ .../src/views/mall/product/spu/index.vue | 109 +++--------------- .../src/views/mall/product/spu/save.vue | 65 +++++++++-- 11 files changed, 187 insertions(+), 133 deletions(-) create mode 100644 yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/brand/vo/ProductBrandListReqVO.java diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/brand/ProductBrandController.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/brand/ProductBrandController.java index 14ffef881..c159883be 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/brand/ProductBrandController.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/brand/ProductBrandController.java @@ -5,8 +5,12 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; import cn.iocoder.yudao.module.product.controller.admin.brand.vo.*; +import cn.iocoder.yudao.module.product.controller.admin.category.vo.ProductCategoryListReqVO; +import cn.iocoder.yudao.module.product.controller.admin.category.vo.ProductCategoryRespVO; import cn.iocoder.yudao.module.product.convert.brand.ProductBrandConvert; +import cn.iocoder.yudao.module.product.convert.category.ProductCategoryConvert; import cn.iocoder.yudao.module.product.dal.dataobject.brand.ProductBrandDO; +import cn.iocoder.yudao.module.product.dal.dataobject.category.ProductCategoryDO; import cn.iocoder.yudao.module.product.service.brand.ProductBrandService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; @@ -19,6 +23,7 @@ import javax.annotation.Resource; import javax.servlet.http.HttpServletResponse; import javax.validation.Valid; import java.io.IOException; +import java.util.Comparator; import java.util.List; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; @@ -74,4 +79,14 @@ public class ProductBrandController { return success(ProductBrandConvert.INSTANCE.convertPage(pageResult)); } + @GetMapping("/list") + @ApiOperation("获得品牌列表") + @PreAuthorize("@ss.hasPermission('product:brand:query')") + public CommonResult> getProductCategoryList(@Valid ProductBrandListReqVO listVO) { + List list = brandService.getBrandList(listVO); + list.sort(Comparator.comparing(ProductBrandDO::getSort)); + return success(ProductBrandConvert.INSTANCE.convertList(list)); + } + + } diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/brand/vo/ProductBrandListReqVO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/brand/vo/ProductBrandListReqVO.java new file mode 100644 index 000000000..5367e2dfe --- /dev/null +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/brand/vo/ProductBrandListReqVO.java @@ -0,0 +1,14 @@ +package cn.iocoder.yudao.module.product.controller.admin.brand.vo; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +@ApiModel(value = "管理后台 - 商品品牌分页 Request VO") +@Data +public class ProductBrandListReqVO { + + @ApiModelProperty(value = "品牌名称", example = "芋道") + private String name; + +} diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/dataobject/sku/ProductSkuDO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/dataobject/sku/ProductSkuDO.java index 2057aa1ae..6d3d374fc 100755 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/dataobject/sku/ProductSkuDO.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/dataobject/sku/ProductSkuDO.java @@ -40,7 +40,7 @@ public class ProductSkuDO extends BaseDO { private String name; /** * SPU 编号 - * + *

* 关联 {@link ProductSpuDO#getId()} */ private Long spuId; @@ -71,7 +71,7 @@ public class ProductSkuDO extends BaseDO { private String picUrl; /** * SKU 状态 - * + *

* 枚举 {@link CommonStatusEnum} */ private Integer status; @@ -100,13 +100,13 @@ public class ProductSkuDO extends BaseDO { /** * 属性编号 - * + *

* 关联 {@link ProductPropertyDO#getId()} */ private Long propertyId; /** * 属性值编号 - * + *

* 关联 {@link ProductPropertyValueDO#getId()} */ private Long valueId; diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/brand/ProductBrandMapper.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/brand/ProductBrandMapper.java index e33884d1c..38558564c 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/brand/ProductBrandMapper.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/brand/ProductBrandMapper.java @@ -3,10 +3,14 @@ package cn.iocoder.yudao.module.product.dal.mysql.brand; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; +import cn.iocoder.yudao.module.product.controller.admin.brand.vo.ProductBrandBaseVO; +import cn.iocoder.yudao.module.product.controller.admin.brand.vo.ProductBrandListReqVO; import cn.iocoder.yudao.module.product.controller.admin.brand.vo.ProductBrandPageReqVO; import cn.iocoder.yudao.module.product.dal.dataobject.brand.ProductBrandDO; import org.apache.ibatis.annotations.Mapper; +import java.util.List; + @Mapper public interface ProductBrandMapper extends BaseMapperX { @@ -18,4 +22,9 @@ public interface ProductBrandMapper extends BaseMapperX { .orderByDesc(ProductBrandDO::getId)); } + + default List selectList(ProductBrandListReqVO reqVO) { + return selectList(new LambdaQueryWrapperX() + .likeIfPresent(ProductBrandDO::getName, reqVO.getName())); + } } diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/brand/ProductBrandService.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/brand/ProductBrandService.java index 6d54cd26f..4c9060055 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/brand/ProductBrandService.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/brand/ProductBrandService.java @@ -1,9 +1,7 @@ package cn.iocoder.yudao.module.product.service.brand; import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.product.controller.admin.brand.vo.ProductBrandCreateReqVO; -import cn.iocoder.yudao.module.product.controller.admin.brand.vo.ProductBrandPageReqVO; -import cn.iocoder.yudao.module.product.controller.admin.brand.vo.ProductBrandUpdateReqVO; +import cn.iocoder.yudao.module.product.controller.admin.brand.vo.*; import cn.iocoder.yudao.module.product.dal.dataobject.brand.ProductBrandDO; import javax.validation.Valid; @@ -55,6 +53,20 @@ public interface ProductBrandService { */ List getBrandList(Collection ids); + /** + * 获得品牌列表 + * @param listVo 请求参数 + * @return 品牌列表 + */ + List getBrandList(ProductBrandListReqVO listVo); + + /** + * 验证选择的商品分类是否合法 + * + * @param id 分类编号 + */ + void validateProductBrand(Long id); + /** * 获得品牌分页 * diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/brand/ProductBrandServiceImpl.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/brand/ProductBrandServiceImpl.java index 8adfa71c3..be67260ff 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/brand/ProductBrandServiceImpl.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/brand/ProductBrandServiceImpl.java @@ -1,12 +1,11 @@ package cn.iocoder.yudao.module.product.service.brand; import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.product.controller.admin.brand.vo.ProductBrandCreateReqVO; -import cn.iocoder.yudao.module.product.controller.admin.brand.vo.ProductBrandPageReqVO; -import cn.iocoder.yudao.module.product.controller.admin.brand.vo.ProductBrandUpdateReqVO; +import cn.iocoder.yudao.module.product.controller.admin.brand.vo.*; import cn.iocoder.yudao.module.product.convert.brand.ProductBrandConvert; import cn.iocoder.yudao.module.product.dal.dataobject.brand.ProductBrandDO; import cn.iocoder.yudao.module.product.dal.mysql.brand.ProductBrandMapper; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; @@ -16,6 +15,7 @@ import java.util.List; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.PRODUCT_BRAND_NOT_EXISTS; +import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.PRODUCT_CATEGORY_LEVEL; /** * 品牌 Service 实现类 @@ -71,6 +71,18 @@ public class ProductBrandServiceImpl implements ProductBrandService { return brandMapper.selectBatchIds(ids); } + @Override + public List getBrandList(ProductBrandListReqVO listVo) { + return brandMapper.selectList(listVo); + } + + @Override + public void validateProductBrand(Long id) { + if(getBrand(id) == null){ + throw exception(PRODUCT_BRAND_NOT_EXISTS); + } + } + @Override public PageResult getBrandPage(ProductBrandPageReqVO pageReqVO) { return brandMapper.selectPage(pageReqVO); diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/sku/ProductSkuServiceImpl.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/sku/ProductSkuServiceImpl.java index 1843617aa..60191d1b0 100755 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/sku/ProductSkuServiceImpl.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/sku/ProductSkuServiceImpl.java @@ -140,7 +140,8 @@ public class ProductSkuServiceImpl implements ProductSkuService { @Override public List getSkusBySpuId(Long spuId) { - return productSkuMapper.selectBySpuIds(Collections.singletonList(spuId)); + List productSkuDOS = productSkuMapper.selectBySpuIds(Collections.singletonList(spuId)); + return productSkuDOS; } @Override diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/spu/ProductSpuServiceImpl.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/spu/ProductSpuServiceImpl.java index ad27ead18..253fb93ae 100755 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/spu/ProductSpuServiceImpl.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/spu/ProductSpuServiceImpl.java @@ -20,6 +20,7 @@ import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO; import cn.iocoder.yudao.module.product.dal.dataobject.spu.ProductSpuDO; import cn.iocoder.yudao.module.product.dal.mysql.spu.ProductSpuMapper; import cn.iocoder.yudao.module.product.enums.spu.ProductSpuSpecTypeEnum; +import cn.iocoder.yudao.module.product.service.brand.ProductBrandService; import cn.iocoder.yudao.module.product.service.category.ProductCategoryService; import cn.iocoder.yudao.module.product.service.property.ProductPropertyService; import cn.iocoder.yudao.module.product.service.sku.ProductSkuService; @@ -55,17 +56,19 @@ public class ProductSpuServiceImpl implements ProductSpuService { @Resource private ProductPropertyService productPropertyService; + @Resource + private ProductBrandService brandService; + @Override @Transactional public Long createProductSpu(ProductSpuCreateReqVO createReqVO) { // 校验分类 categoryService.validateProductCategory(createReqVO.getCategoryId()); - // TODO @:校验品牌 - + // 校验品牌 + brandService.validateProductBrand(createReqVO.getBrandId()); // 校验SKU List skuCreateReqList = createReqVO.getSkus(); productSkuService.validateProductSkus(skuCreateReqList, createReqVO.getSpecType()); - // 插入 SPU ProductSpuDO spu = ProductSpuConvert.INSTANCE.convert(createReqVO); spu.setMarketPrice(CollectionUtils.getMaxValue(skuCreateReqList, ProductSkuCreateOrUpdateReqVO::getMarketPrice)); @@ -73,7 +76,6 @@ public class ProductSpuServiceImpl implements ProductSpuService { spu.setMinPrice(CollectionUtils.getMinValue(skuCreateReqList, ProductSkuCreateOrUpdateReqVO::getPrice)); spu.setTotalStock(CollectionUtils.getSumValue(skuCreateReqList, ProductSkuCreateOrUpdateReqVO::getStock, Integer::sum)); ProductSpuMapper.insert(spu); - // 插入 SKU productSkuService.createProductSkus(skuCreateReqList, spu.getId()); // 返回 @@ -128,27 +130,29 @@ public class ProductSpuServiceImpl implements ProductSpuService { spuVO.setSkus(skuReqs); List properties = new ArrayList<>(); // 组合 sku 规格属性 - for (ProductSkuRespVO productSkuRespVO : skuReqs) { - properties.addAll(productSkuRespVO.getProperties()); - } - Map> propertyMaps = properties.stream().collect(Collectors.groupingBy(ProductSkuBaseVO.Property::getPropertyId)); - List propertyAndValueList = productPropertyService.selectByIds(new ArrayList<>(propertyMaps.keySet())); - // 装载组装过后的属性 - List productPropertyViews = new ArrayList<>(); - propertyAndValueList.forEach(p -> { - ProductPropertyViewRespVO productPropertyViewRespVO = new ProductPropertyViewRespVO(); - productPropertyViewRespVO.setPropertyId(p.getId()); - productPropertyViewRespVO.setName(p.getName()); - Set propertyValues = new HashSet<>(); - Map propertyValueMaps = p.getPropertyValueList().stream().collect(Collectors.toMap(ProductPropertyValueRespVO::getId, pv -> pv)); - propertyMaps.get(p.getId()).forEach(pv -> { - ProductPropertyViewRespVO.Tuple2 tuple2 = new ProductPropertyViewRespVO.Tuple2(pv.getValueId(), propertyValueMaps.get(pv.getValueId()).getName()); - propertyValues.add(tuple2); + if(spu.getSpecType().equals(ProductSpuSpecTypeEnum.DISABLE.getType())) { + for (ProductSkuRespVO productSkuRespVO : skuReqs) { + properties.addAll(productSkuRespVO.getProperties()); + } + Map> propertyMaps = properties.stream().collect(Collectors.groupingBy(ProductSkuBaseVO.Property::getPropertyId)); + List propertyAndValueList = productPropertyService.selectByIds(new ArrayList<>(propertyMaps.keySet())); + // 装载组装过后的属性 + List productPropertyViews = new ArrayList<>(); + propertyAndValueList.forEach(p -> { + ProductPropertyViewRespVO productPropertyViewRespVO = new ProductPropertyViewRespVO(); + productPropertyViewRespVO.setPropertyId(p.getId()); + productPropertyViewRespVO.setName(p.getName()); + Set propertyValues = new HashSet<>(); + Map propertyValueMaps = p.getPropertyValueList().stream().collect(Collectors.toMap(ProductPropertyValueRespVO::getId, pv -> pv)); + propertyMaps.get(p.getId()).forEach(pv -> { + ProductPropertyViewRespVO.Tuple2 tuple2 = new ProductPropertyViewRespVO.Tuple2(pv.getValueId(), propertyValueMaps.get(pv.getValueId()).getName()); + propertyValues.add(tuple2); + }); + productPropertyViewRespVO.setPropertyValues(propertyValues); + productPropertyViews.add(productPropertyViewRespVO); }); - productPropertyViewRespVO.setPropertyValues(propertyValues); - productPropertyViews.add(productPropertyViewRespVO); - }); - spuVO.setProductPropertyViews(productPropertyViews); + spuVO.setProductPropertyViews(productPropertyViews); + } // 组合分类 if (null != spuVO.getCategoryId()) { LinkedList categoryArray = new LinkedList<>(); diff --git a/yudao-ui-admin/src/api/mall/product/brand.js b/yudao-ui-admin/src/api/mall/product/brand.js index 69cb61c08..2218f42cb 100644 --- a/yudao-ui-admin/src/api/mall/product/brand.js +++ b/yudao-ui-admin/src/api/mall/product/brand.js @@ -34,6 +34,15 @@ export function getBrand(id) { }) } +// 获得品牌list +export function getBrandList() { + return request({ + url: '/product/brand/list', + method: 'get' + }) +} + + // 获得品牌分页 export function getBrandPage(query) { return request({ diff --git a/yudao-ui-admin/src/views/mall/product/spu/index.vue b/yudao-ui-admin/src/views/mall/product/spu/index.vue index e9f59febc..801f7870f 100644 --- a/yudao-ui-admin/src/views/mall/product/spu/index.vue +++ b/yudao-ui-admin/src/views/mall/product/spu/index.vue @@ -179,7 +179,7 @@ - + @@ -257,6 +257,10 @@ export default { title: "", // 是否显示弹出层 open: false, + // 弹出层类型 + dialogType: "add", + // 弹出层参数 + dialogObj:{}, dateRangeCreateTime: [], // 查询参数 queryParams: { @@ -570,75 +574,25 @@ export default { }, /** 新增按钮操作 */ handleAdd() { - this.reset(); + this.dialogType = "add"; + this.dialogObj={}; this.open = true; this.title = "添加商品spu"; - this.getPropertyPageList(); }, /** 修改按钮操作 */ handleUpdate(row) { - this.reset(); - const id = row.id; - getSpu(id).then((response) => { - let dataSpu = response.data; - this.form = { - id: dataSpu.id, - name: dataSpu.name, - sellPoint: dataSpu.sellPoint, - description: dataSpu.sellPoint, - categoryId: dataSpu.sellPoint, - categoryIds: dataSpu.categoryIds, - picUrls: dataSpu.picUrls, - sort: dataSpu.sort, - likeCount: dataSpu.likeCount, - price: dataSpu.price, - quantity: dataSpu.quantity, - status: dataSpu.status, - isShowTagInput: undefined, - skus: [], - skusList: dataSpu.skus, - productPropertyViews: dataSpu.productPropertyViews, - // skus:dataSpu.productSkuRespVOS, - }; - this.getDataHandle(); - this.open = true; - this.title = "修改商品spu"; - }); + this.dialogType = "upd"; + this.dialogObj.id = row.id; + this.open = true; + console.log("修改") + this.title = "修改商品spu"; }, - getDataHandle() { - let that = this; - let productPropertyViews = JSON.parse( - JSON.stringify(this.form.productPropertyViews) - ); - productPropertyViews = productPropertyViews.sort( - (a, b) => a.propertyId - b.propertyId - ); - productPropertyViews.forEach((item) => { - item.propertyValues = item.propertyValues.sort((a, b) => a.v1 - b.v1); - }); - let skuIds = []; - for (let i = 0; i < productPropertyViews.length; i++) { - let han = { - name: productPropertyViews[i].name, - propertyId: productPropertyViews[i].propertyId, - selectValues: [], - selectValueIds: [], - }; - for ( - let j = 0; - j < productPropertyViews[i].propertyValues.length; - j++ - ) { - han.selectValues.push(productPropertyViews[i].propertyValues[j].v2); - han.selectValueIds.push(productPropertyViews[i].propertyValues[j].v1); - } - skuIds.push(han); - } - this.skuTags = skuIds; - this.unUseTags = this.allhistoryTags.filter((v) => - skuIds.every((val) => val.name != v.name) - ); - this.getHandleTable(); + closeDialog(){ + console.log("关闭") + this.dialogType = "add"; + this.dialogObj={}; + this.open = false; + this.getList() }, getHandleTable() { this.form.skus = []; @@ -699,33 +653,6 @@ export default { } }); }, - /** 提交按钮 */ - submitForm() { - this.$refs["form"].validate((valid) => { - if (!valid) { - return; - } - this.form.picUrls = this.form.picUrls.split(","); - this.form.categoryId = - this.form.categoryIds[this.form.categoryIds.length - 1]; - this.form.status = Number(this.form.status); - // 修改的提交 - if (this.form.id != null) { - updateSpu(this.form).then((response) => { - this.$modal.msgSuccess("修改成功"); - this.open = false; - this.getList(); - }); - return; - } - // 添加的提交 - createSpu(this.form).then((response) => { - this.$modal.msgSuccess("新增成功"); - this.open = false; - this.getList(); - }); - }); - }, /** 删除按钮操作 */ handleDelete(row) { const id = row.id; diff --git a/yudao-ui-admin/src/views/mall/product/spu/save.vue b/yudao-ui-admin/src/views/mall/product/spu/save.vue index 2cd3eeaf6..089b2d128 100644 --- a/yudao-ui-admin/src/views/mall/product/spu/save.vue +++ b/yudao-ui-admin/src/views/mall/product/spu/save.vue @@ -193,6 +193,16 @@ + + + + + + @@ -221,8 +231,10 @@