|
@@ -4,14 +4,12 @@ import cn.hutool.core.collection.CollUtil;
|
|
|
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.ProductPropertyValueRespVO;
|
|
|
import cn.iocoder.yudao.module.product.controller.admin.property.vo.value.ProductPropertyValueUpdateReqVO;
|
|
|
import cn.iocoder.yudao.module.product.convert.propertyvalue.ProductPropertyValueConvert;
|
|
|
import cn.iocoder.yudao.module.product.dal.dataobject.property.ProductPropertyDO;
|
|
|
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.property.bo.ProductPropertyValueDetailRespBO;
|
|
|
-import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import org.springframework.context.annotation.Lazy;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
@@ -24,6 +22,7 @@ import java.util.List;
|
|
|
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
|
|
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
|
|
|
import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.PROPERTY_VALUE_EXISTS;
|
|
|
+import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.PROPERTY_VALUE_NOT_EXISTS;
|
|
|
|
|
|
/**
|
|
|
* 商品属性值 Service 实现类
|
|
@@ -43,34 +42,47 @@ public class ProductPropertyValueServiceImpl implements ProductPropertyValueServ
|
|
|
|
|
|
@Override
|
|
|
public Long createPropertyValue(ProductPropertyValueCreateReqVO createReqVO) {
|
|
|
+ // 校验名字唯一
|
|
|
if (productPropertyValueMapper.selectByName(createReqVO.getPropertyId(), createReqVO.getName()) != null) {
|
|
|
throw exception(PROPERTY_VALUE_EXISTS);
|
|
|
}
|
|
|
- ProductPropertyValueDO convert = ProductPropertyValueConvert.INSTANCE.convert(createReqVO);
|
|
|
- productPropertyValueMapper.insert(convert);
|
|
|
- return convert.getId();
|
|
|
+
|
|
|
+ // 新增
|
|
|
+ ProductPropertyValueDO value = ProductPropertyValueConvert.INSTANCE.convert(createReqVO);
|
|
|
+ productPropertyValueMapper.insert(value);
|
|
|
+ return value.getId();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void updatePropertyValue(ProductPropertyValueUpdateReqVO updateReqVO) {
|
|
|
- ProductPropertyValueDO productPropertyValueDO = productPropertyValueMapper.selectByName(updateReqVO.getPropertyId(), updateReqVO.getName());
|
|
|
+ validatePropertyValueExists(updateReqVO.getId());
|
|
|
+ // 校验名字唯一
|
|
|
+ ProductPropertyValueDO productPropertyValueDO = productPropertyValueMapper.selectByName
|
|
|
+ (updateReqVO.getPropertyId(), updateReqVO.getName());
|
|
|
if (productPropertyValueDO != null && !productPropertyValueDO.getId().equals(updateReqVO.getId())) {
|
|
|
throw exception(PROPERTY_VALUE_EXISTS);
|
|
|
}
|
|
|
- ProductPropertyValueDO convert = ProductPropertyValueConvert.INSTANCE.convert(updateReqVO);
|
|
|
- productPropertyValueMapper.updateById(convert);
|
|
|
+
|
|
|
+ // 更新
|
|
|
+ ProductPropertyValueDO updateObj = ProductPropertyValueConvert.INSTANCE.convert(updateReqVO);
|
|
|
+ productPropertyValueMapper.updateById(updateObj);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void deletePropertyValue(Long id) {
|
|
|
+ validatePropertyValueExists(id);
|
|
|
productPropertyValueMapper.deleteById(id);
|
|
|
}
|
|
|
|
|
|
+ private void validatePropertyValueExists(Long id) {
|
|
|
+ if (productPropertyValueMapper.selectById(id) == null) {
|
|
|
+ throw exception(PROPERTY_VALUE_NOT_EXISTS);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
- public ProductPropertyValueRespVO getPropertyValue(Long id) {
|
|
|
- ProductPropertyValueDO productPropertyValueDO = productPropertyValueMapper.selectOne(new LambdaQueryWrapper<ProductPropertyValueDO>()
|
|
|
- .eq(ProductPropertyValueDO::getId, id));
|
|
|
- return ProductPropertyValueConvert.INSTANCE.convert(productPropertyValueDO);
|
|
|
+ public ProductPropertyValueDO getPropertyValue(Long id) {
|
|
|
+ return productPropertyValueMapper.selectById(id);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -95,19 +107,14 @@ public class ProductPropertyValueServiceImpl implements ProductPropertyValueServ
|
|
|
return ProductPropertyValueConvert.INSTANCE.convertList(values, keys);
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public List<ProductPropertyValueRespVO> getPropertyValueListByPropertyId(List<Long> propertyIds) {
|
|
|
- return ProductPropertyValueConvert.INSTANCE.convertList(productPropertyValueMapper.selectList("property_id", propertyIds));
|
|
|
- }
|
|
|
-
|
|
|
@Override
|
|
|
public Integer getPropertyValueCountByPropertyId(Long propertyId) {
|
|
|
return productPropertyValueMapper.selectCountByPropertyId(propertyId);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public PageResult<ProductPropertyValueRespVO> getPropertyValueListPage(ProductPropertyValuePageReqVO pageReqVO) {
|
|
|
- return ProductPropertyValueConvert.INSTANCE.convertPage(productPropertyValueMapper.selectPage(pageReqVO));
|
|
|
+ public PageResult<ProductPropertyValueDO> getPropertyValuePage(ProductPropertyValuePageReqVO pageReqVO) {
|
|
|
+ return productPropertyValueMapper.selectPage(pageReqVO);
|
|
|
}
|
|
|
|
|
|
@Override
|