MALL:简化 SPU 属性 的 VO 转化

This commit is contained in:
YunaiV 2024-01-12 23:18:00 +08:00
parent f6c8159dac
commit bf966cd610
18 changed files with 81 additions and 255 deletions

View File

@ -2,8 +2,11 @@ package cn.iocoder.yudao.module.product.controller.admin.property;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.product.controller.admin.property.vo.property.*;
import cn.iocoder.yudao.module.product.convert.property.ProductPropertyConvert;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.product.controller.admin.property.vo.property.ProductPropertyPageReqVO;
import cn.iocoder.yudao.module.product.controller.admin.property.vo.property.ProductPropertyRespVO;
import cn.iocoder.yudao.module.product.controller.admin.property.vo.property.ProductPropertySaveReqVO;
import cn.iocoder.yudao.module.product.dal.dataobject.property.ProductPropertyDO;
import cn.iocoder.yudao.module.product.service.property.ProductPropertyService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
@ -14,8 +17,6 @@ import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
@Tag(name = "管理后台 - 商品属性项")
@ -30,14 +31,14 @@ public class ProductPropertyController {
@PostMapping("/create")
@Operation(summary = "创建属性项")
@PreAuthorize("@ss.hasPermission('product:property:create')")
public CommonResult<Long> createProperty(@Valid @RequestBody ProductPropertyCreateReqVO createReqVO) {
public CommonResult<Long> createProperty(@Valid @RequestBody ProductPropertySaveReqVO createReqVO) {
return success(productPropertyService.createProperty(createReqVO));
}
@PutMapping("/update")
@Operation(summary = "更新属性项")
@PreAuthorize("@ss.hasPermission('product:property:update')")
public CommonResult<Boolean> updateProperty(@Valid @RequestBody ProductPropertyUpdateReqVO updateReqVO) {
public CommonResult<Boolean> updateProperty(@Valid @RequestBody ProductPropertySaveReqVO updateReqVO) {
productPropertyService.updateProperty(updateReqVO);
return success(true);
}
@ -56,21 +57,16 @@ public class ProductPropertyController {
@Parameter(name = "id", description = "编号", required = true, example = "1024")
@PreAuthorize("@ss.hasPermission('product:property:query')")
public CommonResult<ProductPropertyRespVO> getProperty(@RequestParam("id") Long id) {
return success(ProductPropertyConvert.INSTANCE.convert(productPropertyService.getProperty(id)));
}
@GetMapping("/list")
@Operation(summary = "获得属性项列表")
@PreAuthorize("@ss.hasPermission('product:property:query')")
public CommonResult<List<ProductPropertyRespVO>> getPropertyList(@Valid ProductPropertyListReqVO listReqVO) {
return success(ProductPropertyConvert.INSTANCE.convertList(productPropertyService.getPropertyList(listReqVO)));
ProductPropertyDO property = productPropertyService.getProperty(id);
return success(BeanUtils.toBean(property, ProductPropertyRespVO.class));
}
@GetMapping("/page")
@Operation(summary = "获得属性项分页")
@PreAuthorize("@ss.hasPermission('product:property:query')")
public CommonResult<PageResult<ProductPropertyRespVO>> getPropertyPage(@Valid ProductPropertyPageReqVO pageVO) {
return success(ProductPropertyConvert.INSTANCE.convertPage(productPropertyService.getPropertyPage(pageVO)));
PageResult<ProductPropertyDO> pageResult = productPropertyService.getPropertyPage(pageVO);
return success(BeanUtils.toBean(pageResult, ProductPropertyRespVO.class));
}
}

View File

@ -2,22 +2,21 @@ package cn.iocoder.yudao.module.product.controller.admin.property;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.product.controller.admin.property.vo.value.ProductPropertyValueCreateReqVO;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.product.controller.admin.property.vo.value.ProductPropertyValuePageReqVO;
import cn.iocoder.yudao.module.product.controller.admin.property.vo.value.ProductPropertyValueRespVO;
import cn.iocoder.yudao.module.product.controller.admin.property.vo.value.ProductPropertyValueUpdateReqVO;
import cn.iocoder.yudao.module.product.convert.property.ProductPropertyValueConvert;
import cn.iocoder.yudao.module.product.controller.admin.property.vo.value.ProductPropertyValueSaveReqVO;
import cn.iocoder.yudao.module.product.dal.dataobject.property.ProductPropertyValueDO;
import cn.iocoder.yudao.module.product.service.property.ProductPropertyValueService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
@Tag(name = "管理后台 - 商品属性值")
@ -32,14 +31,14 @@ public class ProductPropertyValueController {
@PostMapping("/create")
@Operation(summary = "创建属性值")
@PreAuthorize("@ss.hasPermission('product:property:create')")
public CommonResult<Long> createPropertyValue(@Valid @RequestBody ProductPropertyValueCreateReqVO createReqVO) {
public CommonResult<Long> createPropertyValue(@Valid @RequestBody ProductPropertyValueSaveReqVO createReqVO) {
return success(productPropertyValueService.createPropertyValue(createReqVO));
}
@PutMapping("/update")
@Operation(summary = "更新属性值")
@PreAuthorize("@ss.hasPermission('product:property:update')")
public CommonResult<Boolean> updatePropertyValue(@Valid @RequestBody ProductPropertyValueUpdateReqVO updateReqVO) {
public CommonResult<Boolean> updatePropertyValue(@Valid @RequestBody ProductPropertyValueSaveReqVO updateReqVO) {
productPropertyValueService.updatePropertyValue(updateReqVO);
return success(true);
}
@ -58,13 +57,16 @@ public class ProductPropertyValueController {
@Parameter(name = "id", description = "编号", required = true, example = "1024")
@PreAuthorize("@ss.hasPermission('product:property:query')")
public CommonResult<ProductPropertyValueRespVO> getPropertyValue(@RequestParam("id") Long id) {
return success(ProductPropertyValueConvert.INSTANCE.convert(productPropertyValueService.getPropertyValue(id)));
ProductPropertyValueDO value = productPropertyValueService.getPropertyValue(id);
return success(BeanUtils.toBean(value, ProductPropertyValueRespVO.class));
}
@GetMapping("/page")
@Operation(summary = "获得属性值分页")
@PreAuthorize("@ss.hasPermission('product:property:query')")
public CommonResult<PageResult<ProductPropertyValueRespVO>> getPropertyValuePage(@Valid ProductPropertyValuePageReqVO pageVO) {
return success(ProductPropertyValueConvert.INSTANCE.convertPage(productPropertyValueService.getPropertyValuePage(pageVO)));
PageResult<ProductPropertyValueDO> pageResult = productPropertyValueService.getPropertyValuePage(pageVO);
return success(BeanUtils.toBean(pageResult, ProductPropertyValueRespVO.class));
}
}

View File

@ -1,15 +0,0 @@
package cn.iocoder.yudao.module.product.controller.admin.property.vo.property;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
@Schema(description = "管理后台 - 属性项创建 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class ProductPropertyCreateReqVO extends ProductPropertyBaseVO {
}

View File

@ -1,17 +0,0 @@
package cn.iocoder.yudao.module.product.controller.admin.property.vo.property;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.ToString;
import java.util.List;
@Schema(description = "管理后台 - 属性项 List Request VO")
@Data
@ToString(callSuper = true)
public class ProductPropertyListReqVO {
@Schema(description = "属性名称", example = "颜色")
private String name;
}

View File

@ -2,20 +2,22 @@ package cn.iocoder.yudao.module.product.controller.admin.property.vo.property;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import java.time.LocalDateTime;
@Schema(description = "管理后台 - 属性项 Response VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class ProductPropertyRespVO extends ProductPropertyBaseVO {
public class ProductPropertyRespVO {
@Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
private Long id;
@Schema(description = "名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "颜色")
private String name;
@Schema(description = "备注", example = "颜色")
private String remark;
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
private LocalDateTime createTime;

View File

@ -1,16 +1,15 @@
package cn.iocoder.yudao.module.product.controller.admin.property.vo.property;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import lombok.Data;
import jakarta.validation.constraints.NotBlank;
/**
* 商品属性项 Base VO提供给添加修改详细的子 VO 使用
* 如果子 VO 存在差异的字段请不要添加到这里影响 Swagger 文档生成
*/
@Schema(description = "管理后台 - 属性项新增/更新 Request VO")
@Data
public class ProductPropertyBaseVO {
public class ProductPropertySaveReqVO {
@Schema(description = "主键", example = "1")
private Long id;
@Schema(description = "名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "颜色")
@NotBlank(message = "名称不能为空")

View File

@ -1,20 +0,0 @@
package cn.iocoder.yudao.module.product.controller.admin.property.vo.property;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import jakarta.validation.constraints.NotNull;
@Schema(description = "管理后台 - 属性项更新 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class ProductPropertyUpdateReqVO extends ProductPropertyBaseVO {
@Schema(description = "主键", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
@NotNull(message = "主键不能为空")
private Long id;
}

View File

@ -1,14 +0,0 @@
package cn.iocoder.yudao.module.product.controller.admin.property.vo.value;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
@Schema(description = "管理后台 - 商品属性值创建 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class ProductPropertyValueCreateReqVO extends ProductPropertyValueBaseVO {
}

View File

@ -1,21 +1,30 @@
package cn.iocoder.yudao.module.product.controller.admin.property.vo.value;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import java.time.LocalDateTime;
@Schema(description = "管理后台 - 商品属性值 Response VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class ProductPropertyValueRespVO extends ProductPropertyValueBaseVO {
public class ProductPropertyValueRespVO {
@Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "10")
@Schema(description = "主键", example = "1024")
private Long id;
@Schema(description = "属性项的编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
@NotNull(message = "属性项的编号不能为空")
private Long propertyId;
@Schema(description = "名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "红色")
@NotEmpty(message = "名称名字不能为空")
private String name;
@Schema(description = "备注", example = "颜色")
private String remark;
@Schema(description = "创建时间")
private LocalDateTime createTime;

View File

@ -1,17 +1,16 @@
package cn.iocoder.yudao.module.product.controller.admin.property.vo.value;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
/**
* 属性值 Base VO提供给添加修改详细的子 VO 使用
* 如果子 VO 存在差异的字段请不要添加到这里影响 Swagger 文档生成
*/
@Schema(description = "管理后台 - 商品属性值新增/更新 Request VO")
@Data
public class ProductPropertyValueBaseVO {
public class ProductPropertyValueSaveReqVO {
@Schema(description = "主键", example = "1024")
private Long id;
@Schema(description = "属性项的编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
@NotNull(message = "属性项的编号不能为空")

View File

@ -1,20 +0,0 @@
package cn.iocoder.yudao.module.product.controller.admin.property.vo.value;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import jakarta.validation.constraints.NotNull;
@Schema(description = "管理后台 - 商品属性值更新 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class ProductPropertyValueUpdateReqVO extends ProductPropertyValueBaseVO {
@Schema(description = "主键", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
@NotNull(message = "主键不能为空")
private Long id;
}

View File

@ -1,33 +0,0 @@
package cn.iocoder.yudao.module.product.convert.property;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.product.controller.admin.property.vo.property.ProductPropertyCreateReqVO;
import cn.iocoder.yudao.module.product.controller.admin.property.vo.property.ProductPropertyRespVO;
import cn.iocoder.yudao.module.product.controller.admin.property.vo.property.ProductPropertyUpdateReqVO;
import cn.iocoder.yudao.module.product.dal.dataobject.property.ProductPropertyDO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import java.util.List;
/**
* 属性项 Convert
*
* @author 芋道源码
*/
@Mapper
public interface ProductPropertyConvert {
ProductPropertyConvert INSTANCE = Mappers.getMapper(ProductPropertyConvert.class);
ProductPropertyDO convert(ProductPropertyCreateReqVO bean);
ProductPropertyDO convert(ProductPropertyUpdateReqVO bean);
ProductPropertyRespVO convert(ProductPropertyDO bean);
List<ProductPropertyRespVO> convertList(List<ProductPropertyDO> list);
PageResult<ProductPropertyRespVO> convertPage(PageResult<ProductPropertyDO> page);
}

View File

@ -1,33 +0,0 @@
package cn.iocoder.yudao.module.product.convert.property;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.product.controller.admin.property.vo.value.ProductPropertyValueCreateReqVO;
import cn.iocoder.yudao.module.product.controller.admin.property.vo.value.ProductPropertyValueRespVO;
import cn.iocoder.yudao.module.product.controller.admin.property.vo.value.ProductPropertyValueUpdateReqVO;
import cn.iocoder.yudao.module.product.dal.dataobject.property.ProductPropertyValueDO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import java.util.List;
/**
* 属性值 Convert
*
* @author 芋道源码
*/
@Mapper
public interface ProductPropertyValueConvert {
ProductPropertyValueConvert INSTANCE = Mappers.getMapper(ProductPropertyValueConvert.class);
ProductPropertyValueDO convert(ProductPropertyValueCreateReqVO bean);
ProductPropertyValueDO convert(ProductPropertyValueUpdateReqVO bean);
ProductPropertyValueRespVO convert(ProductPropertyValueDO bean);
List<ProductPropertyValueRespVO> convertList(List<ProductPropertyValueDO> list);
PageResult<ProductPropertyValueRespVO> convertPage(PageResult<ProductPropertyValueDO> page);
}

View File

@ -3,13 +3,10 @@ package cn.iocoder.yudao.module.product.dal.mysql.property;
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.property.vo.property.ProductPropertyListReqVO;
import cn.iocoder.yudao.module.product.controller.admin.property.vo.property.ProductPropertyPageReqVO;
import cn.iocoder.yudao.module.product.dal.dataobject.property.ProductPropertyDO;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
@Mapper
public interface ProductPropertyMapper extends BaseMapperX<ProductPropertyDO> {
@ -24,9 +21,4 @@ public interface ProductPropertyMapper extends BaseMapperX<ProductPropertyDO> {
return selectOne(ProductPropertyDO::getName, name);
}
default List<ProductPropertyDO> selectList(ProductPropertyListReqVO listReqVO) {
return selectList(new LambdaQueryWrapperX<ProductPropertyDO>()
.eqIfPresent(ProductPropertyDO::getName, listReqVO.getName()));
}
}

View File

@ -22,14 +22,14 @@ public interface ProductPropertyService {
* @param createReqVO 创建信息
* @return 编号
*/
Long createProperty(@Valid ProductPropertyCreateReqVO createReqVO);
Long createProperty(@Valid ProductPropertySaveReqVO createReqVO);
/**
* 更新属性项
*
* @param updateReqVO 更新信息
*/
void updateProperty(@Valid ProductPropertyUpdateReqVO updateReqVO);
void updateProperty(@Valid ProductPropertySaveReqVO updateReqVO);
/**
* 删除属性项
@ -38,14 +38,6 @@ public interface ProductPropertyService {
*/
void deleteProperty(Long id);
/**
* 获得属性项列表
*
* @param listReqVO 集合查询
* @return 属性项集合
*/
List<ProductPropertyDO> getPropertyList(ProductPropertyListReqVO listReqVO);
/**
* 获取属性名称分页
*

View File

@ -2,20 +2,18 @@ package cn.iocoder.yudao.module.product.service.property;
import cn.hutool.core.util.ObjUtil;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.product.controller.admin.property.vo.property.ProductPropertyCreateReqVO;
import cn.iocoder.yudao.module.product.controller.admin.property.vo.property.ProductPropertyListReqVO;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.product.controller.admin.property.vo.property.ProductPropertyPageReqVO;
import cn.iocoder.yudao.module.product.controller.admin.property.vo.property.ProductPropertyUpdateReqVO;
import cn.iocoder.yudao.module.product.convert.property.ProductPropertyConvert;
import cn.iocoder.yudao.module.product.controller.admin.property.vo.property.ProductPropertySaveReqVO;
import cn.iocoder.yudao.module.product.dal.dataobject.property.ProductPropertyDO;
import cn.iocoder.yudao.module.product.dal.mysql.property.ProductPropertyMapper;
import cn.iocoder.yudao.module.product.service.sku.ProductSkuService;
import jakarta.annotation.Resource;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import jakarta.annotation.Resource;
import java.util.Collection;
import java.util.List;
@ -43,7 +41,7 @@ public class ProductPropertyServiceImpl implements ProductPropertyService {
@Override
@Transactional(rollbackFor = Exception.class)
public Long createProperty(ProductPropertyCreateReqVO createReqVO) {
public Long createProperty(ProductPropertySaveReqVO createReqVO) {
// 如果已经添加过该属性项直接返回
ProductPropertyDO dbProperty = productPropertyMapper.selectByName(createReqVO.getName());
if (dbProperty != null) {
@ -51,7 +49,7 @@ public class ProductPropertyServiceImpl implements ProductPropertyService {
}
// 插入
ProductPropertyDO property = ProductPropertyConvert.INSTANCE.convert(createReqVO);
ProductPropertyDO property = BeanUtils.toBean(createReqVO, ProductPropertyDO.class);
productPropertyMapper.insert(property);
// 返回
return property.getId();
@ -59,17 +57,17 @@ public class ProductPropertyServiceImpl implements ProductPropertyService {
@Override
@Transactional(rollbackFor = Exception.class)
public void updateProperty(ProductPropertyUpdateReqVO updateReqVO) {
public void updateProperty(ProductPropertySaveReqVO updateReqVO) {
validatePropertyExists(updateReqVO.getId());
// 校验名字重复
ProductPropertyDO productPropertyDO = productPropertyMapper.selectByName(updateReqVO.getName());
if (productPropertyDO != null &&
ObjUtil.notEqual(productPropertyDO.getId(), updateReqVO.getId())) {
ProductPropertyDO property = productPropertyMapper.selectByName(updateReqVO.getName());
if (property != null &&
ObjUtil.notEqual(property.getId(), updateReqVO.getId())) {
throw exception(PROPERTY_EXISTS);
}
// 更新
ProductPropertyDO updateObj = ProductPropertyConvert.INSTANCE.convert(updateReqVO);
ProductPropertyDO updateObj = BeanUtils.toBean(updateReqVO, ProductPropertyDO.class);
productPropertyMapper.updateById(updateObj);
// 更新 sku 相关属性
productSkuService.updateSkuProperty(updateObj.getId(), updateObj.getName());
@ -96,11 +94,6 @@ public class ProductPropertyServiceImpl implements ProductPropertyService {
}
}
@Override
public List<ProductPropertyDO> getPropertyList(ProductPropertyListReqVO listReqVO) {
return productPropertyMapper.selectList(listReqVO);
}
@Override
public PageResult<ProductPropertyDO> getPropertyPage(ProductPropertyPageReqVO pageReqVO) {
return productPropertyMapper.selectPage(pageReqVO);

View File

@ -1,9 +1,8 @@
package cn.iocoder.yudao.module.product.service.property;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.product.controller.admin.property.vo.value.ProductPropertyValueCreateReqVO;
import cn.iocoder.yudao.module.product.controller.admin.property.vo.value.ProductPropertyValuePageReqVO;
import cn.iocoder.yudao.module.product.controller.admin.property.vo.value.ProductPropertyValueUpdateReqVO;
import cn.iocoder.yudao.module.product.controller.admin.property.vo.value.ProductPropertyValueSaveReqVO;
import cn.iocoder.yudao.module.product.dal.dataobject.property.ProductPropertyValueDO;
import java.util.Collection;
@ -23,14 +22,14 @@ public interface ProductPropertyValueService {
* @param createReqVO 创建信息
* @return 编号
*/
Long createPropertyValue(ProductPropertyValueCreateReqVO createReqVO);
Long createPropertyValue(ProductPropertyValueSaveReqVO createReqVO);
/**
* 更新属性值
*
* @param updateReqVO 更新信息
*/
void updatePropertyValue(ProductPropertyValueUpdateReqVO updateReqVO);
void updatePropertyValue(ProductPropertyValueSaveReqVO updateReqVO);
/**
* 删除属性值

View File

@ -1,18 +1,17 @@
package cn.iocoder.yudao.module.product.service.property;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.product.controller.admin.property.vo.value.ProductPropertyValueCreateReqVO;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.product.controller.admin.property.vo.value.ProductPropertyValuePageReqVO;
import cn.iocoder.yudao.module.product.controller.admin.property.vo.value.ProductPropertyValueUpdateReqVO;
import cn.iocoder.yudao.module.product.convert.property.ProductPropertyValueConvert;
import cn.iocoder.yudao.module.product.controller.admin.property.vo.value.ProductPropertyValueSaveReqVO;
import cn.iocoder.yudao.module.product.dal.dataobject.property.ProductPropertyValueDO;
import cn.iocoder.yudao.module.product.dal.mysql.property.ProductPropertyValueMapper;
import cn.iocoder.yudao.module.product.service.sku.ProductSkuService;
import jakarta.annotation.Resource;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import jakarta.annotation.Resource;
import java.util.Collection;
import java.util.List;
@ -32,16 +31,12 @@ public class ProductPropertyValueServiceImpl implements ProductPropertyValueServ
@Resource
private ProductPropertyValueMapper productPropertyValueMapper;
@Resource
@Lazy // 延迟加载避免循环依赖
private ProductPropertyService productPropertyService;
@Resource
@Lazy // 延迟加载避免循环依赖
private ProductSkuService productSkuService;
@Override
public Long createPropertyValue(ProductPropertyValueCreateReqVO createReqVO) {
public Long createPropertyValue(ProductPropertyValueSaveReqVO createReqVO) {
// 如果已经添加过该属性值直接返回
ProductPropertyValueDO dbValue = productPropertyValueMapper.selectByName(
createReqVO.getPropertyId(), createReqVO.getName());
@ -50,23 +45,23 @@ public class ProductPropertyValueServiceImpl implements ProductPropertyValueServ
}
// 新增
ProductPropertyValueDO value = ProductPropertyValueConvert.INSTANCE.convert(createReqVO);
ProductPropertyValueDO value = BeanUtils.toBean(createReqVO, ProductPropertyValueDO.class);
productPropertyValueMapper.insert(value);
return value.getId();
}
@Override
public void updatePropertyValue(ProductPropertyValueUpdateReqVO updateReqVO) {
public void updatePropertyValue(ProductPropertyValueSaveReqVO updateReqVO) {
validatePropertyValueExists(updateReqVO.getId());
// 校验名字唯一
ProductPropertyValueDO productPropertyValueDO = productPropertyValueMapper.selectByName
ProductPropertyValueDO value = productPropertyValueMapper.selectByName
(updateReqVO.getPropertyId(), updateReqVO.getName());
if (productPropertyValueDO != null && !productPropertyValueDO.getId().equals(updateReqVO.getId())) {
if (value != null && !value.getId().equals(updateReqVO.getId())) {
throw exception(PROPERTY_VALUE_EXISTS);
}
// 更新
ProductPropertyValueDO updateObj = ProductPropertyValueConvert.INSTANCE.convert(updateReqVO);
ProductPropertyValueDO updateObj = BeanUtils.toBean(updateReqVO, ProductPropertyValueDO.class);
productPropertyValueMapper.updateById(updateObj);
// 更新 sku 相关属性
productSkuService.updateSkuPropertyValue(updateObj.getId(), updateObj.getName());