trade:增加管理后台的订单分页接口

pull/2/head
YunaiV 2022-12-09 00:20:38 +08:00
parent fac3e7c726
commit fe1ae23b71
24 changed files with 309 additions and 48 deletions

View File

@ -0,0 +1,23 @@
package cn.iocoder.yudao.module.product.api.property;
import cn.iocoder.yudao.module.product.api.property.dto.ProductPropertyValueDetailRespDTO;
import java.util.Collection;
import java.util.List;
/**
* API
*
* @author
*/
public interface ProductPropertyValueApi {
/**
*
*
* @param ids
* @return
*/
List<ProductPropertyValueDetailRespDTO> getPropertyValueDetailList(Collection<Long> ids);
}

View File

@ -0,0 +1,33 @@
package cn.iocoder.yudao.module.product.api.property.dto;
import lombok.Data;
/**
* Response DTO
*
* @author
*/
@Data
public class ProductPropertyValueDetailRespDTO {
/**
*
*/
private Long propertyId;
/**
*
*/
private String propertyName;
/**
*
*/
private Long valueId;
/**
*
*/
private String valueName;
}

View File

@ -0,0 +1,31 @@
package cn.iocoder.yudao.module.product.api.property;
import cn.iocoder.yudao.module.product.api.property.dto.ProductPropertyValueDetailRespDTO;
import cn.iocoder.yudao.module.product.convert.propertyvalue.ProductPropertyValueConvert;
import cn.iocoder.yudao.module.product.service.property.ProductPropertyValueService;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource;
import java.util.Collection;
import java.util.List;
/**
* API
*
* @author
*/
@Service
@Validated
public class ProductPropertyValueApiImpl implements ProductPropertyValueApi {
@Resource
private ProductPropertyValueService productPropertyValueService;
@Override
public List<ProductPropertyValueDetailRespDTO> getPropertyValueDetailList(Collection<Long> ids) {
return ProductPropertyValueConvert.INSTANCE.convertList02(
productPropertyValueService.getPropertyValueDetailList(ids));
}
}

View File

@ -63,7 +63,7 @@ public class ProductPropertyController {
@ApiOperation("获得属性项列表")
@PreAuthorize("@ss.hasPermission('product:property:query')")
public CommonResult<List<ProductPropertyRespVO>> getPropertyList(@Valid ProductPropertyListReqVO listReqVO) {
return success(productPropertyService.getPropertyList(listReqVO));
return success(productPropertyService.getPropertyVOList(listReqVO));
}
@GetMapping("/page")

View File

@ -1,14 +1,22 @@
package cn.iocoder.yudao.module.product.convert.propertyvalue;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
import cn.iocoder.yudao.framework.common.util.collection.MapUtils;
import cn.iocoder.yudao.module.product.api.property.dto.ProductPropertyValueDetailRespDTO;
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.ProductPropertyDO;
import cn.iocoder.yudao.module.product.dal.dataobject.property.ProductPropertyValueDO;
import cn.iocoder.yudao.module.product.service.property.bo.ProductPropertyValueDetailRespBO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import java.util.List;
import java.util.Map;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap;
/**
* Convert
@ -30,6 +38,18 @@ public interface ProductPropertyValueConvert {
PageResult<ProductPropertyValueRespVO> convertPage(PageResult<ProductPropertyValueDO> page);
List<ProductPropertyValueDO> convertList03(List<ProductPropertyValueCreateReqVO> list);
default List<ProductPropertyValueDetailRespBO> convertList(List<ProductPropertyValueDO> values, List<ProductPropertyDO> keys) {
Map<Long, ProductPropertyDO> keyMap = convertMap(keys, ProductPropertyDO::getId);
return CollectionUtils.convertList(values, value -> {
ProductPropertyValueDetailRespBO valueDetail = new ProductPropertyValueDetailRespBO()
.setValueId(value.getId()).setValueName(value.getName());
// 设置属性项
MapUtils.findAndThen(keyMap, value.getPropertyId(),
key -> valueDetail.setPropertyId(key.getId()).setPropertyName(key.getName()));
return valueDetail;
});
}
List<ProductPropertyValueDetailRespDTO> convertList02(List<ProductPropertyValueDetailRespBO> list);
}

View File

@ -2,6 +2,7 @@ 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.property.*;
import cn.iocoder.yudao.module.product.dal.dataobject.property.ProductPropertyDO;
import javax.validation.Valid;
import java.util.Collection;
@ -41,7 +42,7 @@ public interface ProductPropertyService {
* @param listReqVO
* @return
*/
List<ProductPropertyRespVO> getPropertyList(ProductPropertyListReqVO listReqVO);
List<ProductPropertyRespVO> getPropertyVOList(ProductPropertyListReqVO listReqVO);
/**
*
@ -65,7 +66,15 @@ public interface ProductPropertyService {
* @param ids
* @return
*/
List<ProductPropertyRespVO> getPropertyList(Collection<Long> ids);
List<ProductPropertyDO> getPropertyList(Collection<Long> ids);
/**
*
*
* @param ids
* @return
*/
List<ProductPropertyRespVO> getPropertyVOList(Collection<Long> ids);
/**
* +

View File

@ -83,7 +83,7 @@ public class ProductPropertyServiceImpl implements ProductPropertyService {
}
@Override
public List<ProductPropertyRespVO> getPropertyList(ProductPropertyListReqVO listReqVO) {
public List<ProductPropertyRespVO> getPropertyVOList(ProductPropertyListReqVO listReqVO) {
return ProductPropertyConvert.INSTANCE.convertList(productPropertyMapper.selectList(new LambdaQueryWrapperX<ProductPropertyDO>()
.likeIfPresent(ProductPropertyDO::getName, listReqVO.getName())
.eqIfPresent(ProductPropertyDO::getStatus, listReqVO.getStatus())));
@ -101,16 +101,21 @@ public class ProductPropertyServiceImpl implements ProductPropertyService {
return ProductPropertyConvert.INSTANCE.convert(property);
}
@Override
public List<ProductPropertyDO> getPropertyList(Collection<Long> ids) {
return productPropertyMapper.selectBatchIds(ids);
}
// TODO @芋艿:丢到 Controller
@Override
public List<ProductPropertyRespVO> getPropertyList(Collection<Long> ids) {
public List<ProductPropertyRespVO> getPropertyVOList(Collection<Long> ids) {
return ProductPropertyConvert.INSTANCE.convertList(productPropertyMapper.selectBatchIds(ids));
}
// TODO @芋艿:丢到 Controller
@Override
public List<ProductPropertyAndValueRespVO> getPropertyAndValueList(ProductPropertyListReqVO listReqVO) {
List<ProductPropertyRespVO> propertyList = getPropertyList(listReqVO);
List<ProductPropertyRespVO> propertyList = getPropertyVOList(listReqVO);
// 查询属性值
List<ProductPropertyValueDO> valueDOList = productPropertyValueMapper.selectListByPropertyId(CollectionUtils.convertList(propertyList, ProductPropertyRespVO::getId));

View File

@ -5,7 +5,9 @@ import cn.iocoder.yudao.module.product.controller.admin.property.vo.value.Produc
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.service.property.bo.ProductPropertyValueDetailRespBO;
import java.util.Collection;
import java.util.List;
/**
@ -45,6 +47,14 @@ public interface ProductPropertyValueService {
*/
ProductPropertyValueRespVO getPropertyValue(Long id);
/**
*
*
* @param ids
* @return
*/
List<ProductPropertyValueDetailRespBO> getPropertyValueDetailList(Collection<Long> ids);
/**
*
*

View File

@ -1,21 +1,28 @@
package cn.iocoder.yudao.module.product.service.property;
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;
import javax.annotation.Resource;
import java.util.Collection;
import java.util.Collections;
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;
/**
@ -30,6 +37,10 @@ public class ProductPropertyValueServiceImpl implements ProductPropertyValueServ
@Resource
private ProductPropertyValueMapper productPropertyValueMapper;
@Resource
@Lazy // 延迟加载,避免循环依赖
private ProductPropertyService productPropertyService;
@Override
public Long createPropertyValue(ProductPropertyValueCreateReqVO createReqVO) {
if (productPropertyValueMapper.selectByName(createReqVO.getPropertyId(), createReqVO.getName()) != null) {
@ -62,6 +73,23 @@ public class ProductPropertyValueServiceImpl implements ProductPropertyValueServ
return ProductPropertyValueConvert.INSTANCE.convert(productPropertyValueDO);
}
@Override
public List<ProductPropertyValueDetailRespBO> getPropertyValueDetailList(Collection<Long> ids) {
// 获得属性值列表
if (CollUtil.isEmpty(ids)) {
return Collections.emptyList();
}
List<ProductPropertyValueDO> values = productPropertyValueMapper.selectBatchIds(ids);
if (CollUtil.isEmpty(values)) {
return Collections.emptyList();
}
// 获得属性项列表
List<ProductPropertyDO> keys = productPropertyService.getPropertyList(
convertSet(values, ProductPropertyValueDO::getPropertyId));
// 组装明细
return ProductPropertyValueConvert.INSTANCE.convertList(values, keys);
}
@Override
public List<ProductPropertyValueRespVO> getPropertyValueListByPropertyId(List<Long> id) {
return ProductPropertyValueConvert.INSTANCE.convertList(productPropertyValueMapper.selectList("property_id", id));

View File

@ -89,7 +89,7 @@ public class ProductSkuServiceImpl implements ProductSkuService {
.flatMap(p -> p.getProperties().stream()) // 遍历多个 Property 属性
.map(ProductSkuBaseVO.Property::getPropertyId) // 将每个 Property 转换成对应的 propertyId最后形成集合
.collect(Collectors.toSet());
List<ProductPropertyRespVO> propertyList = productPropertyService.getPropertyList(propertyIds);
List<ProductPropertyRespVO> propertyList = productPropertyService.getPropertyVOList(propertyIds);
if (propertyList.size() != propertyIds.size()) {
throw exception(PROPERTY_NOT_EXISTS);
}

View File

@ -142,7 +142,7 @@ public class ProductSpuServiceImpl implements ProductSpuService {
Map<Long, List<ProductSkuBaseVO.Property>> propertyMaps = properties.stream().collect(Collectors.groupingBy(ProductSkuBaseVO.Property::getPropertyId));
List<ProductPropertyValueRespVO> propertyValueList = productPropertyValueService.getPropertyValueListByPropertyId(new ArrayList<>(propertyMaps.keySet()));
List<ProductPropertyRespVO> propertyList = productPropertyService.getPropertyList(new ArrayList<>(propertyMaps.keySet()));
List<ProductPropertyRespVO> propertyList = productPropertyService.getPropertyVOList(new ArrayList<>(propertyMaps.keySet()));
// 装载组装过后的属性
List<ProductPropertyViewRespVO> productPropertyViews = new ArrayList<>();
propertyList.forEach(p -> {

View File

@ -188,7 +188,7 @@ public class ProductSpuServiceImplTest extends BaseDbUnitTest {
Mockito.when(productSkuService.getSkusBySpuId(createReqVO.getId())).thenReturn(productSkuDOS);
Mockito.when(productPropertyValueService.getPropertyValueListByPropertyId(new ArrayList<>(collect.keySet()))).thenReturn(productPropertyValueRespVO);
Mockito.when(productPropertyService.getPropertyList(new ArrayList<>(collect.keySet()))).thenReturn(productPropertyRespVOS);
Mockito.when(productPropertyService.getPropertyVOList(new ArrayList<>(collect.keySet()))).thenReturn(productPropertyRespVOS);
// 调用
ProductSpuDetailRespVO spuDetail = productSpuService.getSpuDetail(createReqVO.getId());

View File

@ -0,0 +1,4 @@
### 获得交易售后分页 => 成功
GET {{baseUrl}}/trade/after-sale/page?pageNo=1&pageSize=10
Authorization: Bearer {{token}}
tenant-id: {{adminTenentId}}

View File

@ -5,6 +5,8 @@ import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.member.api.user.MemberUserApi;
import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO;
import cn.iocoder.yudao.module.product.api.property.ProductPropertyValueApi;
import cn.iocoder.yudao.module.product.api.property.dto.ProductPropertyValueDetailRespDTO;
import cn.iocoder.yudao.module.trade.controller.admin.aftersale.vo.TradeAfterSaleDisagreeReqVO;
import cn.iocoder.yudao.module.trade.controller.admin.aftersale.vo.TradeAfterSalePageReqVO;
import cn.iocoder.yudao.module.trade.controller.admin.aftersale.vo.TradeAfterSaleRefuseReqVO;
@ -22,6 +24,7 @@ import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;
import java.util.Map;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
@ -41,20 +44,26 @@ public class TradeAfterSaleController {
@Resource
private MemberUserApi memberUserApi;
@Resource
private ProductPropertyValueApi productPropertyValueApi;
@GetMapping("/page")
@ApiOperation("获得交易售后分页")
@PreAuthorize("@ss.hasPermission('trade:after-sale:query')")
public CommonResult<PageResult<TradeAfterSaleRespPageItemVO>> getAfterSalePage(@Valid TradeAfterSalePageReqVO pageVO) {
// 查询售后
PageResult<TradeAfterSaleDO> pageResult = afterSaleService.getAfterSalePage(pageVO);
if (CollUtil.isEmpty(pageResult.getList())) {
return success(PageResult.empty());
}
// 拼接数据
// 查询商品属性
List<ProductPropertyValueDetailRespDTO> propertyValueDetails = productPropertyValueApi
.getPropertyValueDetailList(TradeAfterSaleConvert.INSTANCE.convertPropertyValueIds(pageResult.getList()));
// 查询会员
Map<Long, MemberUserRespDTO> memberUsers = memberUserApi.getUserMap(
convertSet(pageResult.getList(), TradeAfterSaleDO::getUserId));
return success(TradeAfterSaleConvert.INSTANCE.convertPage(pageResult, memberUsers));
return success(TradeAfterSaleConvert.INSTANCE.convertPage(pageResult, memberUsers, propertyValueDetails));
}
@PutMapping("/agree")

View File

@ -1,6 +1,5 @@
package cn.iocoder.yudao.module.trade.controller.admin.aftersale.vo;
import cn.iocoder.yudao.module.trade.controller.admin.base.product.property.ProductPropertyValueDetailRespVO;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;
@ -72,9 +71,6 @@ public class TradeAfterSaleBaseVO {
@NotNull(message = "商品 SKU 编号不能为空")
private Long skuId;
@ApiModelProperty(value = "商品属性数组")
private List<ProductPropertyValueDetailRespVO> properties;
@ApiModelProperty(value = "商品图片", example = "https://www.iocoder.cn/2.png")
private String picUrl;

View File

@ -1,6 +1,7 @@
package cn.iocoder.yudao.module.trade.controller.admin.aftersale.vo;
import cn.iocoder.yudao.module.trade.controller.admin.base.member.user.MemberUserRespVO;
import cn.iocoder.yudao.module.trade.controller.admin.base.product.property.ProductPropertyValueDetailRespVO;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@ -8,6 +9,7 @@ import lombok.EqualsAndHashCode;
import lombok.ToString;
import java.time.LocalDateTime;
import java.util.List;
@ApiModel("管理后台 - 交易售后分页的每一条记录 Response VO")
@Data
@ -21,6 +23,11 @@ public class TradeAfterSaleRespPageItemVO extends TradeAfterSaleBaseVO {
@ApiModelProperty(value = "创建时间", required = true)
private LocalDateTime createTime;
/**
*
*/
private List<ProductPropertyValueDetailRespVO> properties;
/**
*
*/

View File

@ -0,0 +1,4 @@
### 获得交易订单分页 => 成功
GET {{baseUrl}}/trade/order/page?pageNo=1&pageSize=10
Authorization: Bearer {{token}}
tenant-id: {{adminTenentId}}

View File

@ -3,6 +3,8 @@ package cn.iocoder.yudao.module.trade.controller.admin.order;
import cn.hutool.core.collection.CollUtil;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.product.api.property.ProductPropertyValueApi;
import cn.iocoder.yudao.module.product.api.property.dto.ProductPropertyValueDetailRespDTO;
import cn.iocoder.yudao.module.trade.controller.admin.order.vo.TradeOrderDeliveryReqVO;
import cn.iocoder.yudao.module.trade.controller.admin.order.vo.TradeOrderPageItemRespVO;
import cn.iocoder.yudao.module.trade.controller.admin.order.vo.TradeOrderPageReqVO;
@ -19,7 +21,6 @@ import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
import java.util.Set;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
@ -35,6 +36,9 @@ public class TradeOrderController {
@Resource
private TradeOrderService tradeOrderService;
@Resource
private ProductPropertyValueApi productPropertyValueApi;
@GetMapping("/page")
@ApiOperation("获得交易订单分页")
@PreAuthorize("@ss.hasPermission('trade:order:query')")
@ -44,15 +48,14 @@ public class TradeOrderController {
if (CollUtil.isEmpty(pageResult.getList())) {
return success(PageResult.empty());
}
// 查询订单项
List<TradeOrderItemDO> orderItems = tradeOrderService.getOrderItems(
List<TradeOrderItemDO> orderItems = tradeOrderService.getOrderItemListByOrderId(
convertSet(pageResult.getList(), TradeOrderDO::getId));
// 查询属性
Set<Long> propertyValueIds = TradeOrderConvert.INSTANCE.convertPropertyValueIds(orderItems);
return success(null);
// 查询商品属性
List<ProductPropertyValueDetailRespDTO> propertyValueDetails = productPropertyValueApi
.getPropertyValueDetailList(TradeOrderConvert.INSTANCE.convertPropertyValueIds(orderItems));
// 最终组合
return success(TradeOrderConvert.INSTANCE.convertPage(pageResult, orderItems, propertyValueDetails));
}
@PostMapping("/delivery")

View File

@ -8,7 +8,7 @@ import java.util.List;
@ApiModel("管理后台 - 交易订单的分页项 Response VO")
@Data
public class TradeOrderPageItemRespVO {
public class TradeOrderPageItemRespVO extends TradeOrderBaseVO {
/**
*

View File

@ -1,10 +1,13 @@
package cn.iocoder.yudao.module.trade.convert.aftersale;
import cn.hutool.core.collection.CollUtil;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO;
import cn.iocoder.yudao.module.pay.api.refund.dto.PayRefundCreateReqDTO;
import cn.iocoder.yudao.module.product.api.property.dto.ProductPropertyValueDetailRespDTO;
import cn.iocoder.yudao.module.trade.controller.admin.aftersale.vo.TradeAfterSaleRespPageItemVO;
import cn.iocoder.yudao.module.trade.controller.admin.base.member.user.MemberUserRespVO;
import cn.iocoder.yudao.module.trade.controller.admin.base.product.property.ProductPropertyValueDetailRespVO;
import cn.iocoder.yudao.module.trade.controller.app.aftersale.vo.AppTradeAfterSaleCreateReqVO;
import cn.iocoder.yudao.module.trade.dal.dataobject.aftersale.TradeAfterSaleDO;
import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderItemDO;
@ -14,7 +17,10 @@ import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers;
import java.util.Map;
import java.util.*;
import java.util.stream.Collectors;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap;
@Mapper
public interface TradeAfterSaleConvert {
@ -43,10 +49,41 @@ public interface TradeAfterSaleConvert {
PageResult<TradeAfterSaleRespPageItemVO> convertPage(PageResult<TradeAfterSaleDO> page);
default PageResult<TradeAfterSaleRespPageItemVO> convertPage(PageResult<TradeAfterSaleDO> pageResult,
Map<Long, MemberUserRespDTO> memberUsers) {
Map<Long, MemberUserRespDTO> memberUsers, List<ProductPropertyValueDetailRespDTO> propertyValueDetails) {
PageResult<TradeAfterSaleRespPageItemVO> pageVOResult = convertPage(pageResult);
pageVOResult.getList().forEach(item -> item.setUser(convert(memberUsers.get(item.getUserId()))));
// 处理会员 + 商品属性等关联信息
Map<Long, ProductPropertyValueDetailRespDTO> propertyValueDetailMap = convertMap(propertyValueDetails, ProductPropertyValueDetailRespDTO::getValueId);
for (int i = 0; i < pageResult.getList().size(); i++) {
TradeAfterSaleRespPageItemVO afterSaleVO = pageVOResult.getList().get(i);
TradeAfterSaleDO afterSaleDO = pageResult.getList().get(i);
// 会员
afterSaleVO.setUser(convert(memberUsers.get(afterSaleDO.getUserId())));
// 商品属性
if (CollUtil.isNotEmpty(afterSaleDO.getProperties())) {
afterSaleVO.setProperties(new ArrayList<>(afterSaleDO.getProperties().size()));
// 遍历每个 properties设置到 TradeOrderPageItemRespVO.Item 中
afterSaleDO.getProperties().forEach(property -> {
ProductPropertyValueDetailRespDTO propertyValueDetail = propertyValueDetailMap.get(property.getValueId());
if (propertyValueDetail == null) {
return;
}
afterSaleVO.getProperties().add(convert(propertyValueDetail));
});
}
}
return pageVOResult;
}
ProductPropertyValueDetailRespVO convert(ProductPropertyValueDetailRespDTO bean);
default Set<Long> convertPropertyValueIds(List<TradeAfterSaleDO> list) {
if (CollUtil.isEmpty(list)) {
return new HashSet<>();
}
return list.stream().filter(item -> item.getProperties() != null)
.flatMap(p -> p.getProperties().stream()) // 遍历多个 Property 属性
.map(TradeOrderItemDO.Property::getValueId) // 将每个 Property 转换成对应的 propertyId最后形成集合
.collect(Collectors.toSet());
}
}

View File

@ -1,14 +1,18 @@
package cn.iocoder.yudao.module.trade.convert.order;
import cn.hutool.core.collection.CollUtil;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
import cn.iocoder.yudao.module.member.api.address.dto.AddressRespDTO;
import cn.iocoder.yudao.module.pay.api.order.dto.PayOrderCreateReqDTO;
import cn.iocoder.yudao.module.product.api.property.dto.ProductPropertyValueDetailRespDTO;
import cn.iocoder.yudao.module.product.api.sku.dto.ProductSkuRespDTO;
import cn.iocoder.yudao.module.product.api.sku.dto.ProductSkuUpdateStockReqDTO;
import cn.iocoder.yudao.module.product.api.spu.dto.ProductSpuRespDTO;
import cn.iocoder.yudao.module.promotion.api.price.dto.PriceCalculateReqDTO;
import cn.iocoder.yudao.module.promotion.api.price.dto.PriceCalculateRespDTO;
import cn.iocoder.yudao.module.trade.controller.admin.base.product.property.ProductPropertyValueDetailRespVO;
import cn.iocoder.yudao.module.trade.controller.admin.order.vo.TradeOrderPageItemRespVO;
import cn.iocoder.yudao.module.trade.controller.app.order.vo.AppTradeOrderCreateReqVO;
import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderDO;
import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderItemDO;
@ -19,13 +23,11 @@ import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.*;
import java.util.stream.Collectors;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMultiMap;
import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.addTime;
@Mapper
@ -92,14 +94,50 @@ public interface TradeOrderConvert {
return createReqDTO;
}
default Set<Long> convertPropertyValueIds(List<TradeOrderItemDO> orderItems) {
if (CollUtil.isEmpty(orderItems)) {
default Set<Long> convertPropertyValueIds(List<TradeOrderItemDO> list) {
if (CollUtil.isEmpty(list)) {
return new HashSet<>();
}
return orderItems.stream().filter(item -> item.getProperties() != null)
return list.stream().filter(item -> item.getProperties() != null)
.flatMap(p -> p.getProperties().stream()) // 遍历多个 Property 属性
.map(TradeOrderItemDO.Property::getValueId) // 将每个 Property 转换成对应的 propertyId最后形成集合
.collect(Collectors.toSet());
}
default PageResult<TradeOrderPageItemRespVO> convertPage(PageResult<TradeOrderDO> pageResult, List<TradeOrderItemDO> orderItems,
List<ProductPropertyValueDetailRespDTO> propertyValueDetails) {
Map<Long, List<TradeOrderItemDO>> orderItemMap = convertMultiMap(orderItems, TradeOrderItemDO::getOrderId);
Map<Long, ProductPropertyValueDetailRespDTO> propertyValueDetailMap = convertMap(propertyValueDetails, ProductPropertyValueDetailRespDTO::getValueId);
// 转化 List
List<TradeOrderPageItemRespVO> orderVOs = CollectionUtils.convertList(pageResult.getList(), order -> {
List<TradeOrderItemDO> xOrderItems = orderItemMap.get(order.getId());
TradeOrderPageItemRespVO orderVO = convert(order, xOrderItems);
if (CollUtil.isNotEmpty(xOrderItems)) {
// 处理商品属性
for (int i = 0; i < xOrderItems.size(); i++) {
List<TradeOrderItemDO.Property> properties = xOrderItems.get(i).getProperties();
if (CollUtil.isEmpty(properties)) {
continue;
}
TradeOrderPageItemRespVO.Item item = orderVO.getItems().get(i);
item.setProperties(new ArrayList<>(properties.size()));
// 遍历每个 properties设置到 TradeOrderPageItemRespVO.Item 中
properties.forEach(property -> {
ProductPropertyValueDetailRespDTO propertyValueDetail = propertyValueDetailMap.get(property.getValueId());
if (propertyValueDetail == null) {
return;
}
item.getProperties().add(convert(propertyValueDetail));
});
}
}
return orderVO;
});
return new PageResult<>(orderVOs, pageResult.getTotal());
}
TradeOrderPageItemRespVO convert(TradeOrderDO order, List<TradeOrderItemDO> items);
ProductPropertyValueDetailRespVO convert(ProductPropertyValueDetailRespDTO bean);
}

View File

@ -5,6 +5,7 @@ import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderItemDO;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import org.apache.ibatis.annotations.Mapper;
import java.util.Collection;
import java.util.List;
@Mapper
@ -19,4 +20,8 @@ public interface TradeOrderItemMapper extends BaseMapperX<TradeOrderItemDO> {
return selectList(TradeOrderItemDO::getOrderId, orderId);
}
default List<TradeOrderItemDO> selectListByOrderId(Collection<Long> orderIds) {
return selectList(TradeOrderItemDO::getOrderId, orderIds);
}
}

View File

@ -9,9 +9,6 @@ import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderItemDO;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMultiMap;
/**
* Service
@ -97,22 +94,19 @@ public interface TradeOrderService {
Integer newAfterSaleStatus, Integer refundPrice);
/**
*
*
*
* @param ids
* @return
*/
List<TradeOrderItemDO> getOrderItems(Collection<Long> ids);
List<TradeOrderItemDO> getOrderItemList(Collection<Long> ids);
/**
* Map
*
*
* @param ids
* @return Map
* @param orderIds
* @return
*/
default Map<Long, List<TradeOrderItemDO>> getOrderItemMap(Collection<Long> ids) {
List<TradeOrderItemDO> orderItems = getOrderItems(ids);
return convertMultiMap(orderItems, TradeOrderItemDO::getOrderId);
}
List<TradeOrderItemDO> getOrderItemListByOrderId(Collection<Long> orderIds);
}

View File

@ -473,10 +473,15 @@ public class TradeOrderServiceImpl implements TradeOrderService {
}
@Override
public List<TradeOrderItemDO> getOrderItems(Collection<Long> ids) {
public List<TradeOrderItemDO> getOrderItemList(Collection<Long> ids) {
return tradeOrderItemMapper.selectBatchIds(ids);
}
@Override
public List<TradeOrderItemDO> getOrderItemListByOrderId(Collection<Long> orderIds) {
return tradeOrderItemMapper.selectListByOrderId(orderIds);
}
/**
*
*