|
@@ -1,10 +1,7 @@
|
|
|
package cn.iocoder.yudao.module.product.service.property;
|
|
|
|
|
|
-import cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil;
|
|
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
|
|
import cn.iocoder.yudao.module.product.controller.admin.property.vo.*;
|
|
|
-import cn.iocoder.yudao.module.product.controller.admin.property.vo.ProductPropertyCreateReqVO;
|
|
|
-import cn.iocoder.yudao.module.product.controller.admin.property.vo.ProductPropertyUpdateReqVO;
|
|
|
import cn.iocoder.yudao.module.product.controller.admin.propertyvalue.vo.ProductPropertyValueCreateReqVO;
|
|
|
import cn.iocoder.yudao.module.product.controller.admin.propertyvalue.vo.ProductPropertyValueRespVO;
|
|
|
import cn.iocoder.yudao.module.product.convert.property.ProductPropertyConvert;
|
|
@@ -12,7 +9,7 @@ import cn.iocoder.yudao.module.product.convert.propertyvalue.ProductPropertyValu
|
|
|
import cn.iocoder.yudao.module.product.dal.dataobject.property.ProductPropertyDO;
|
|
|
import cn.iocoder.yudao.module.product.dal.dataobject.propertyvalue.ProductPropertyValueDO;
|
|
|
import cn.iocoder.yudao.module.product.dal.mysql.property.ProductPropertyMapper;
|
|
|
-import cn.iocoder.yudao.module.product.service.propertyvalue.ProductPropertyValueService;
|
|
|
+import cn.iocoder.yudao.module.product.dal.mysql.propertyvalue.ProductPropertyValueMapper;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
@@ -21,6 +18,7 @@ import javax.annotation.Resource;
|
|
|
import java.util.Arrays;
|
|
|
import java.util.Collection;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
|
@@ -39,7 +37,7 @@ public class ProductPropertyServiceImpl implements ProductPropertyService {
|
|
|
private ProductPropertyMapper productPropertyMapper;
|
|
|
|
|
|
@Resource
|
|
|
- private ProductPropertyValueService productPropertyValueService;
|
|
|
+ private ProductPropertyValueMapper productPropertyValueMapper;
|
|
|
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@@ -52,7 +50,7 @@ public class ProductPropertyServiceImpl implements ProductPropertyService {
|
|
|
List<ProductPropertyValueCreateReqVO> propertyValueList = createReqVO.getPropertyValueList();
|
|
|
List<ProductPropertyValueDO> productPropertyValueDOList = ProductPropertyValueConvert.INSTANCE.convertList03(propertyValueList);
|
|
|
productPropertyValueDOList.stream().forEach(x-> x.setPropertyId(property.getId()));
|
|
|
- productPropertyValueService.batchInsert(productPropertyValueDOList);
|
|
|
+ productPropertyValueMapper.insertBatch(productPropertyValueDOList);
|
|
|
// 返回
|
|
|
return property.getId();
|
|
|
}
|
|
@@ -66,11 +64,11 @@ public class ProductPropertyServiceImpl implements ProductPropertyService {
|
|
|
ProductPropertyDO updateObj = ProductPropertyConvert.INSTANCE.convert(updateReqVO);
|
|
|
productPropertyMapper.updateById(updateObj);
|
|
|
//更新属性值,先删后加
|
|
|
- productPropertyValueService.deletePropertyValueByPropertyId(updateReqVO.getId());
|
|
|
+ productPropertyValueMapper.deletePropertyValueByPropertyId(updateReqVO.getId());
|
|
|
List<ProductPropertyValueCreateReqVO> propertyValueList = updateReqVO.getPropertyValueList();
|
|
|
List<ProductPropertyValueDO> productPropertyValueDOList = ProductPropertyValueConvert.INSTANCE.convertList03(propertyValueList);
|
|
|
productPropertyValueDOList.stream().forEach(x-> x.setPropertyId(updateReqVO.getId()));
|
|
|
- productPropertyValueService.batchInsert(productPropertyValueDOList);
|
|
|
+ productPropertyValueMapper.insertBatch(productPropertyValueDOList);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -80,7 +78,7 @@ public class ProductPropertyServiceImpl implements ProductPropertyService {
|
|
|
// 删除
|
|
|
productPropertyMapper.deleteById(id);
|
|
|
//同步删除属性值
|
|
|
- productPropertyValueService.deletePropertyValueByPropertyId(id);
|
|
|
+ productPropertyValueMapper.deletePropertyValueByPropertyId(id);
|
|
|
}
|
|
|
|
|
|
private void validatePropertyExists(Long id) {
|
|
@@ -117,7 +115,7 @@ public class ProductPropertyServiceImpl implements ProductPropertyService {
|
|
|
List<Long> propertyIds = propertyRespVOPageResult.getList().stream().map(ProductPropertyRespVO::getId).collect(Collectors.toList());
|
|
|
|
|
|
//获取属性值列表
|
|
|
- List<ProductPropertyValueDO> productPropertyValueDOList = productPropertyValueService.getPropertyValueListByPropertyId(propertyIds);
|
|
|
+ List<ProductPropertyValueDO> productPropertyValueDOList = productPropertyValueMapper.getPropertyValueListByPropertyId(propertyIds);
|
|
|
List<ProductPropertyValueRespVO> propertyValueRespVOList = ProductPropertyValueConvert.INSTANCE.convertList(productPropertyValueDOList);
|
|
|
//组装一对多
|
|
|
propertyRespVOPageResult.getList().forEach(x->{
|
|
@@ -128,13 +126,17 @@ public class ProductPropertyServiceImpl implements ProductPropertyService {
|
|
|
return propertyRespVOPageResult;
|
|
|
}
|
|
|
|
|
|
+ private List<ProductPropertyValueDO> getPropertyValueListByPropertyId(List<Long> propertyIds) {
|
|
|
+ return productPropertyValueMapper.getPropertyValueListByPropertyId(propertyIds);
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public ProductPropertyRespVO getPropertyResp(Long id) {
|
|
|
//查询规格
|
|
|
ProductPropertyDO property = getProperty(id);
|
|
|
ProductPropertyRespVO propertyRespVO = ProductPropertyConvert.INSTANCE.convert(property);
|
|
|
//查询属性值
|
|
|
- List<ProductPropertyValueDO> valueDOList = productPropertyValueService.getPropertyValueListByPropertyId(Arrays.asList(id));
|
|
|
+ List<ProductPropertyValueDO> valueDOList = productPropertyValueMapper.getPropertyValueListByPropertyId(Arrays.asList(id));
|
|
|
List<ProductPropertyValueRespVO> propertyValueRespVOS = ProductPropertyValueConvert.INSTANCE.convertList(valueDOList);
|
|
|
//组装
|
|
|
propertyRespVO.setPropertyValueList(propertyValueRespVOS);
|
|
@@ -142,7 +144,12 @@ public class ProductPropertyServiceImpl implements ProductPropertyService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public List<ProductPropertyRespVO> selectByIds(List<Integer> propertyIds) {
|
|
|
- return ProductPropertyConvert.INSTANCE.convertList(productPropertyMapper.selectBatchIds(propertyIds));
|
|
|
+ public List<ProductPropertyRespVO> selectByIds(List<Long> propertyIds) {
|
|
|
+ List<ProductPropertyRespVO> productPropertyRespVO = ProductPropertyConvert.INSTANCE.convertList(productPropertyMapper.selectBatchIds(propertyIds));
|
|
|
+ //查询属性值
|
|
|
+ List<ProductPropertyValueDO> valueDOList = productPropertyValueMapper.getPropertyValueListByPropertyId(propertyIds);
|
|
|
+ Map<Long, List<ProductPropertyValueDO>> propertyValuesMap = valueDOList.stream().collect(Collectors.groupingBy(ProductPropertyValueDO::getPropertyId));
|
|
|
+ productPropertyRespVO.forEach(p -> p.setPropertyValueList(ProductPropertyValueConvert.INSTANCE.convertList(propertyValuesMap.get(p.getId()))));
|
|
|
+ return productPropertyRespVO;
|
|
|
}
|
|
|
}
|