优化订单查询速度
This commit is contained in:
+148
-8
@@ -2465,25 +2465,165 @@ public class YxStoreOrderServiceImpl extends BaseServiceImpl<StoreOrderMapper, Y
|
||||
List<YxStoreOrderDto> storeOrderDTOS = new ArrayList<>();
|
||||
for (YxStoreOrder yxStoreOrder : page.getList()) {
|
||||
this.orderList(storeOrderDTOS, yxStoreOrder);
|
||||
|
||||
}
|
||||
// List<YxStoreOrderDto> list=this.newAssemble(page.getList());
|
||||
Map<String, Object> map = new LinkedHashMap<>(2);
|
||||
map.put("content", storeOrderDTOS);
|
||||
// map.put("content", list);
|
||||
map.put("totalElements", page.getTotal());
|
||||
return map;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param orderList 订单列表
|
||||
* @return 组装后的订单列表
|
||||
*/
|
||||
private List<YxStoreOrderDto> newAssemble(List<YxStoreOrder> orderList){
|
||||
//返回的数据List
|
||||
List<YxStoreOrderDto> dtoList = new ArrayList<>();
|
||||
if (!orderList.isEmpty()){
|
||||
//店铺名id
|
||||
List<Integer> storeIdList = orderList.stream().filter(item -> item.getStoreId() > 0)
|
||||
.map(YxStoreOrder::getStoreId).collect(Collectors.toList());
|
||||
List<YxSystemStore> systemStoreList = storeIdList.isEmpty() ? new ArrayList<>() : systemStoreService.listByIds(storeIdList);
|
||||
|
||||
//购物车
|
||||
List<Long> orderIdList = orderList.stream().map(YxStoreOrder::getId).collect(Collectors.toList());
|
||||
List<YxStoreOrderCartInfo> cartInfoList = orderIdList.isEmpty() ? new ArrayList<>() :
|
||||
storeOrderCartInfoService.list(
|
||||
new LambdaQueryWrapper<YxStoreOrderCartInfo>().in(YxStoreOrderCartInfo::getOid, orderIdList));
|
||||
|
||||
//用户id
|
||||
List<Long> uidList = orderList.stream().map(YxStoreOrder::getUid).collect(Collectors.toList());
|
||||
List<YxUser> userList = uidList.isEmpty() ? new ArrayList<>() : userService.listByIds(uidList);
|
||||
|
||||
dtoList = generator.convert(orderList, YxStoreOrderDto.class);
|
||||
|
||||
//订单类型处理
|
||||
Map<Long, String> orderTypeMap = this.assembleOrderType(dtoList);
|
||||
|
||||
//返回的数据List
|
||||
|
||||
for (YxStoreOrderDto yxStoreOrderDto : dtoList) {
|
||||
Integer _status = OrderUtil.orderStatus(yxStoreOrderDto.getPaid(), yxStoreOrderDto.getStatus(),
|
||||
yxStoreOrderDto.getRefundStatus());
|
||||
|
||||
//订单状态
|
||||
String orderStatusStr = OrderUtil.orderStatusStr(yxStoreOrderDto.getPaid()
|
||||
, yxStoreOrderDto.getStatus(), yxStoreOrderDto.getShippingType()
|
||||
, yxStoreOrderDto.getRefundStatus());
|
||||
|
||||
//订单匹配店铺名
|
||||
systemStoreList.stream().filter(item -> item.getId() == yxStoreOrderDto.getStoreId()).findAny()
|
||||
.ifPresent(store -> {
|
||||
yxStoreOrderDto.setStoreName(store.getName());
|
||||
});
|
||||
|
||||
if (_status == 3) {
|
||||
String refundTime = DateUtil.formatDateTime(yxStoreOrderDto.getRefundReasonTime());
|
||||
String str = "<b style='color:#f124c7'>申请退款</b><br/>" +
|
||||
"<span>退款原因:" + yxStoreOrderDto.getRefundReasonWap() + "</span><br/>" +
|
||||
"<span>备注说明:" + yxStoreOrderDto.getRefundReasonWapExplain() + "</span><br/>" +
|
||||
"<span>退款时间:" + refundTime + "</span><br/>";
|
||||
orderStatusStr = str;
|
||||
}
|
||||
|
||||
yxStoreOrderDto.setStatusName(orderStatusStr);
|
||||
|
||||
yxStoreOrderDto.set_status(_status);
|
||||
|
||||
//支付类型
|
||||
String payTypeName = OrderUtil.payTypeName(yxStoreOrderDto.getPayType(), yxStoreOrderDto.getPaid());
|
||||
yxStoreOrderDto.setPayTypeName(payTypeName);
|
||||
|
||||
//订单类型处理
|
||||
yxStoreOrderDto.setPinkName(orderTypeMap.get(yxStoreOrderDto.getId()).isEmpty() ?
|
||||
this.orderType(yxStoreOrderDto.getId()
|
||||
, yxStoreOrderDto.getPinkId(), yxStoreOrderDto.getCombinationId()
|
||||
, yxStoreOrderDto.getSeckillId(), yxStoreOrderDto.getBargainId(),
|
||||
yxStoreOrderDto.getShippingType(), yxStoreOrderDto.getPayIntegral())
|
||||
: orderTypeMap.get(yxStoreOrderDto.getId()));
|
||||
|
||||
//购物车
|
||||
List<YxStoreOrderCartInfo> orderCartList = cartInfoList.stream().filter(item -> item.getOid().equals(yxStoreOrderDto.getId())).collect(Collectors.toList());
|
||||
List<StoreOrderCartInfoDto> cartInfoDTOS = new ArrayList<>();
|
||||
for (YxStoreOrderCartInfo cartInfo : orderCartList) {
|
||||
StoreOrderCartInfoDto cartInfoDTO = new StoreOrderCartInfoDto();
|
||||
cartInfoDTO.setCartInfoMap(JSON.parseObject(cartInfo.getCartInfo()));
|
||||
cartInfoDTOS.add(cartInfoDTO);
|
||||
}
|
||||
yxStoreOrderDto.setCartInfoList(cartInfoDTOS);
|
||||
|
||||
//用户信息
|
||||
userList.stream().filter(item -> item.getUid().equals(yxStoreOrderDto.getUid())).findFirst()
|
||||
.ifPresent(user ->{
|
||||
yxStoreOrderDto.setUserDTO(generator.convert(user, YxUserDto.class));
|
||||
});
|
||||
if (yxStoreOrderDto.getUserDTO() == null) {
|
||||
yxStoreOrderDto.setUserDTO(new YxUserDto());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return dtoList;
|
||||
}
|
||||
|
||||
|
||||
private Map<Long, String> assembleOrderType(List<YxStoreOrderDto> dtoList) {
|
||||
Map<Long, String> map = new HashMap<>();
|
||||
List<YxStoreOrderDto> storePinkIdList = dtoList.stream().filter(item -> item.getPinkId() > 0 || item.getCombinationId() > 0).collect(Collectors.toList());
|
||||
List<YxStorePink> storePinkList = storePinkIdList.isEmpty() ? new ArrayList<>() :
|
||||
storePinkService.list(Wrappers.<YxStorePink>lambdaQuery().in(YxStorePink::getOrderIdKey, storePinkIdList));
|
||||
for (YxStoreOrderDto dto : dtoList) {
|
||||
String str = "[普通订单]";
|
||||
if (dto.getPinkId() > 0 || dto.getCombinationId() > 0) {
|
||||
Optional<YxStorePink> pink = storePinkList.stream().filter(item -> item.getOrderIdKey().equals(dto.getId())).findFirst();
|
||||
if (pink.isPresent()){
|
||||
YxStorePink storePink = pink.get();
|
||||
if (OrderInfoEnum.PINK_STATUS_1.getValue().equals(storePink.getStatus())) {
|
||||
str = "[拼团订单]拼团进行中";
|
||||
} else if (OrderInfoEnum.PINK_STATUS_2.getValue().equals(storePink.getStatus())) {
|
||||
str = "[拼团订单]拼团完成";
|
||||
} else if (OrderInfoEnum.PINK_STATUS_3.getValue().equals(storePink.getStatus())) {
|
||||
str = "[拼团订单]拼团失败";
|
||||
} else {
|
||||
str = "[拼团订单]历史订单";
|
||||
}
|
||||
}else {
|
||||
str = "[拼团订单]";
|
||||
}
|
||||
}else if (dto.getSeckillId() > 0) {
|
||||
str = "[秒杀订单]";
|
||||
} else if (dto.getBargainId() > 0) {
|
||||
str = "[砍价订单]";
|
||||
}
|
||||
|
||||
if (OrderInfoEnum.SHIPPIING_TYPE_2.getValue().equals(dto.getShippingType())) {
|
||||
str = "[核销订单]";
|
||||
}
|
||||
if (dto.getPayIntegral().compareTo(new BigDecimal("0.00")) == 1) {
|
||||
str = "[积分兑换]";
|
||||
}
|
||||
map.put(dto.getId(), str);
|
||||
}
|
||||
return map;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> queryAll(YxStoreOrderQueryCriteria criteria, Pageable pageable) {
|
||||
getPage(pageable);
|
||||
PageInfo<YxStoreOrder> page = new PageInfo<>(queryAll(criteria));
|
||||
List<YxStoreOrderDto> storeOrderDTOS = new ArrayList<>();
|
||||
for (YxStoreOrder yxStoreOrder : page.getList()) {
|
||||
this.orderList(storeOrderDTOS, yxStoreOrder);
|
||||
|
||||
}
|
||||
// List<YxStoreOrderDto> storeOrderDTOS = new ArrayList<>();
|
||||
// for (YxStoreOrder yxStoreOrder : page.getList()) {
|
||||
// this.orderList(storeOrderDTOS, yxStoreOrder);
|
||||
//
|
||||
// }
|
||||
List<YxStoreOrderDto> list=this.newAssemble(page.getList());
|
||||
Map<String, Object> map = new LinkedHashMap<>(2);
|
||||
map.put("content", storeOrderDTOS);
|
||||
// map.put("content", storeOrderDTOS);
|
||||
map.put("content",list);
|
||||
map.put("totalElements", page.getTotal());
|
||||
return map;
|
||||
}
|
||||
@@ -2536,7 +2676,7 @@ public class YxStoreOrderServiceImpl extends BaseServiceImpl<StoreOrderMapper, Y
|
||||
pBrand.append(yxStoreBrandService.getById(yxStoreProduct.getBrandId()).getBrandName());
|
||||
}
|
||||
if (ObjectUtil.isNotNull(yxStoreCategoryService.getById(yxStoreProduct.getCateId()))){
|
||||
YxStoreCategory yxStoreCategory=yxStoreCategoryService.getById(yxStoreProduct.getCateId());
|
||||
// YxStoreCategory yxStoreCategory=yxStoreCategoryService.getById(yxStoreProduct.getCateId());
|
||||
pCate.append(yxStoreCategoryService.getById(yxStoreProduct.getCateId()).getCateName());
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user