|
@@ -1,13 +1,11 @@
|
|
|
package com.txz.mall.business.impl;
|
|
|
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
-import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
|
import com.txz.cif.dto.EarningsDTO;
|
|
|
import com.txz.mall.business.OrderServiceBusiness;
|
|
|
import com.txz.mall.core.RedisUtil;
|
|
|
import com.txz.mall.core.ServiceException;
|
|
|
-import com.txz.mall.dao.StorePinkMapper;
|
|
|
import com.txz.mall.dubbo.client.CifRedEnvelopeDubboServiceClient;
|
|
|
import com.txz.mall.dubbo.client.CifUserDubboServiceClient;
|
|
|
import com.txz.mall.enums.PinkOrderStatusEnum;
|
|
@@ -35,7 +33,7 @@ import java.util.stream.Collectors;
|
|
|
@Transactional
|
|
|
@AllArgsConstructor
|
|
|
public class OrderServiceBusinessImpl implements OrderServiceBusiness {
|
|
|
-
|
|
|
+
|
|
|
private final StoreOrderService storeOrderService;
|
|
|
private final StoreOrderInfoService storeOrderInfoService;
|
|
|
private final UserAddressService userAddressService;
|
|
@@ -45,131 +43,130 @@ public class OrderServiceBusinessImpl implements OrderServiceBusiness {
|
|
|
private final StorePinkService storePinkService;
|
|
|
private final RedisUtil redisUtil;
|
|
|
private final CifRedEnvelopeDubboServiceClient cifRedEnvelopeDubboServiceClient;
|
|
|
-
|
|
|
+
|
|
|
@Override
|
|
|
- public StoreOrderVO orderDetail(Long id ,String orderNo) {
|
|
|
+ public StoreOrderVO orderDetail(Long id, String orderNo) {
|
|
|
StoreOrderVO vo = new StoreOrderVO();
|
|
|
StoreOrder storeOrder = null;
|
|
|
- if(!ObjectUtils.isEmpty(id)){
|
|
|
- storeOrder = storeOrderService.findById(id);
|
|
|
- }else if(!ObjectUtils.isEmpty(orderNo)){
|
|
|
- storeOrder = storeOrderService.findBy("orderId",orderNo);
|
|
|
+ if (!ObjectUtils.isEmpty(id)) {
|
|
|
+ storeOrder = storeOrderService.findById(id);
|
|
|
+ } else if (!ObjectUtils.isEmpty(orderNo)) {
|
|
|
+ storeOrder = storeOrderService.findBy("orderId", orderNo);
|
|
|
}
|
|
|
-
|
|
|
- if(ObjectUtils.isEmpty(storeOrder)){
|
|
|
- throw new ServiceException("订单不存在 ID:"+id);
|
|
|
+
|
|
|
+ if (ObjectUtils.isEmpty(storeOrder)) {
|
|
|
+ throw new ServiceException("订单不存在 ID:" + id);
|
|
|
}
|
|
|
- id =storeOrder.getId();
|
|
|
+ id = storeOrder.getId();
|
|
|
Condition infoCondition = new Condition(StoreOrderInfo.class);
|
|
|
Example.Criteria infoCriteria = infoCondition.createCriteria();
|
|
|
infoCriteria.andEqualTo("isDelete", 0);
|
|
|
infoCriteria.andEqualTo("orderId", storeOrder.getId());
|
|
|
List<StoreOrderInfo> infoList = storeOrderInfoService.findByCondition(infoCondition);
|
|
|
List<StoreOrderStatus> logList = storeOrderStatusService.getLogList(storeOrder.getId());
|
|
|
-
|
|
|
+
|
|
|
Condition storePinkCondition = new Condition(StorePink.class);
|
|
|
Example.Criteria storePinkCriteria = storePinkCondition.createCriteria();
|
|
|
storePinkCriteria.andEqualTo("isDelete", 0);
|
|
|
storePinkCriteria.andEqualTo("orderIdKey", id);
|
|
|
-
|
|
|
+
|
|
|
List<StorePink> byCondition = storePinkService.findByCondition(storePinkCondition);
|
|
|
- if(!org.springframework.util.CollectionUtils.isEmpty(byCondition)){
|
|
|
+ if (!org.springframework.util.CollectionUtils.isEmpty(byCondition)) {
|
|
|
StorePink storePink = byCondition.get(0);
|
|
|
vo.setStorePink(storePink);
|
|
|
}
|
|
|
-// UserDTO user = userDubboServiceClient.getUser(storeOrder.getUid());
|
|
|
+ // UserDTO user = userDubboServiceClient.getUser(storeOrder.getUid());
|
|
|
UserAddress userAddress = userAddressService.findById(storeOrder.getAddressId());
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
List<String> orderCodeList = new ArrayList<>();
|
|
|
orderCodeList.add(storeOrder.getOrderId());
|
|
|
-
|
|
|
+
|
|
|
Map<String, EarningsDTO> collect = new HashMap<>();
|
|
|
- //查询订单收益
|
|
|
+ // 查询订单收益
|
|
|
List<EarningsDTO> earningsByOrders = cifRedEnvelopeDubboServiceClient.getEarningsByOrders(orderCodeList);
|
|
|
- if(!org.springframework.util.CollectionUtils.isEmpty(earningsByOrders)){
|
|
|
- collect = earningsByOrders.stream().filter(a -> !ObjectUtils.isEmpty(a)).collect(Collectors.toMap(EarningsDTO::getOrderNo, a -> a, (b, c) -> c));
|
|
|
-
|
|
|
+ if (!org.springframework.util.CollectionUtils.isEmpty(earningsByOrders)) {
|
|
|
+ collect = earningsByOrders.stream().filter(a -> !ObjectUtils.isEmpty(a)).collect(Collectors.toMap(EarningsDTO::getOrderNo, a -> a, (b, c) -> c));
|
|
|
+
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
BeanUtils.copyProperties(storeOrder, vo);
|
|
|
EarningsDTO earningsDTO = collect.get(storeOrder.getOrderId());
|
|
|
- if(!ObjectUtils.isEmpty(earningsDTO)){
|
|
|
+ if (!ObjectUtils.isEmpty(earningsDTO)) {
|
|
|
vo.setBrokerage(earningsDTO.getEarnings());
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
vo.setOrderInfoVO(infoList);
|
|
|
vo.setOrderAddressVO(userAddress);
|
|
|
vo.setOrderStatusVO(logList);
|
|
|
-
|
|
|
-// vo.setUserVO(user);
|
|
|
+
|
|
|
+ // vo.setUserVO(user);
|
|
|
return vo;
|
|
|
}
|
|
|
-
|
|
|
-//
|
|
|
-// @Override
|
|
|
-// public List<StoreCombinationRankVO> getRank() {
|
|
|
-// List<StoreCombinationRankVO> list = new ArrayList<>();
|
|
|
-// String key = "order:rank:";
|
|
|
-// boolean exists = redisUtil.hasKey("order:rank");
|
|
|
-// if (exists) {
|
|
|
-// String orderVoString = redisUtil.get(key).toString();
|
|
|
-// list = JSONObject.parseArray(orderVoString, StoreCombinationRankVO.class);
|
|
|
-// return list;
|
|
|
-// }
|
|
|
-//
|
|
|
-// Condition orderCondition = new Condition(StoreOrder.class);
|
|
|
-// Example.Criteria orderCriteria = orderCondition.createCriteria();
|
|
|
-// Date date = new Date();
|
|
|
-// Date startDate = DateUtil.beginOfDay(DateUtils.addDays(date, -7));
|
|
|
-// Date endDate = DateUtil.endOfDay(date);
|
|
|
-// orderCriteria.andEqualTo("isDelete", 0);
|
|
|
-// orderCriteria.andBetween("createTime", startDate, endDate);
|
|
|
-// orderCriteria.andEqualTo("paid", 1);
|
|
|
-// List<StoreOrder> orderList = storeOrderService.findByCondition(orderCondition);
|
|
|
-// Map<Long, Long> combinationCountMap = orderList.stream()
|
|
|
-// .collect(Collectors.groupingBy(
|
|
|
-// StoreOrder::getCombinationId,
|
|
|
-// Collectors.counting()
|
|
|
-// ));
|
|
|
-//
|
|
|
-// // 获取前10个热门商品组合
|
|
|
-// List<Map.Entry<Long, Long>> topCombinations = combinationCountMap.entrySet()
|
|
|
-// .stream()
|
|
|
-// .sorted(Map.Entry.<Long, Long>comparingByValue().reversed())
|
|
|
-// .collect(Collectors.toList());
|
|
|
-//
|
|
|
-// List<StoreCombination> combinationList = storeCombinationService.findByIds(String.join(",", topCombinations.stream().map(Map.Entry::getKey).map(Object::toString).collect(Collectors.toList())));
|
|
|
-// for (StoreCombination storeCombination : combinationList) {
|
|
|
-// List<StoreCombination> collect = combinationList.stream().filter(c -> c.getId().equals(storeCombination.getId())).collect(Collectors.toList());
|
|
|
-// if (CollectionUtils.isNotEmpty(collect)) {
|
|
|
-// StoreCombination combination = collect.get(0);
|
|
|
-// StoreCombinationRankVO rankVO = new StoreCombinationRankVO();
|
|
|
-// rankVO.setProductId(combination.getProductId());
|
|
|
-// rankVO.setProductName(combination.getProductName());
|
|
|
-// rankVO.setSales(combination.getSales());
|
|
|
-// rankVO.setImage(combination.getImage());
|
|
|
-// rankVO.setPrice(combination.getPrice());
|
|
|
-// list.add(rankVO);
|
|
|
-// }
|
|
|
-// }
|
|
|
-// redisUtil.set(key, list);
|
|
|
-// return list;
|
|
|
-// }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
+ //
|
|
|
+ // @Override
|
|
|
+ // public List<StoreCombinationRankVO> getRank() {
|
|
|
+ // List<StoreCombinationRankVO> list = new ArrayList<>();
|
|
|
+ // String key = "order:rank:";
|
|
|
+ // boolean exists = redisUtil.hasKey("order:rank");
|
|
|
+ // if (exists) {
|
|
|
+ // String orderVoString = redisUtil.get(key).toString();
|
|
|
+ // list = JSONObject.parseArray(orderVoString, StoreCombinationRankVO.class);
|
|
|
+ // return list;
|
|
|
+ // }
|
|
|
+ //
|
|
|
+ // Condition orderCondition = new Condition(StoreOrder.class);
|
|
|
+ // Example.Criteria orderCriteria = orderCondition.createCriteria();
|
|
|
+ // Date date = new Date();
|
|
|
+ // Date startDate = DateUtil.beginOfDay(DateUtils.addDays(date, -7));
|
|
|
+ // Date endDate = DateUtil.endOfDay(date);
|
|
|
+ // orderCriteria.andEqualTo("isDelete", 0);
|
|
|
+ // orderCriteria.andBetween("createTime", startDate, endDate);
|
|
|
+ // orderCriteria.andEqualTo("paid", 1);
|
|
|
+ // List<StoreOrder> orderList = storeOrderService.findByCondition(orderCondition);
|
|
|
+ // Map<Long, Long> combinationCountMap = orderList.stream()
|
|
|
+ // .collect(Collectors.groupingBy(
|
|
|
+ // StoreOrder::getCombinationId,
|
|
|
+ // Collectors.counting()
|
|
|
+ // ));
|
|
|
+ //
|
|
|
+ // // 获取前10个热门商品组合
|
|
|
+ // List<Map.Entry<Long, Long>> topCombinations = combinationCountMap.entrySet()
|
|
|
+ // .stream()
|
|
|
+ // .sorted(Map.Entry.<Long, Long>comparingByValue().reversed())
|
|
|
+ // .collect(Collectors.toList());
|
|
|
+ //
|
|
|
+ // List<StoreCombination> combinationList = storeCombinationService.findByIds(String.join(",", topCombinations.stream().map(Map.Entry::getKey).map(Object::toString).collect(Collectors.toList())));
|
|
|
+ // for (StoreCombination storeCombination : combinationList) {
|
|
|
+ // List<StoreCombination> collect = combinationList.stream().filter(c -> c.getId().equals(storeCombination.getId())).collect(Collectors.toList());
|
|
|
+ // if (CollectionUtils.isNotEmpty(collect)) {
|
|
|
+ // StoreCombination combination = collect.get(0);
|
|
|
+ // StoreCombinationRankVO rankVO = new StoreCombinationRankVO();
|
|
|
+ // rankVO.setProductId(combination.getProductId());
|
|
|
+ // rankVO.setProductName(combination.getProductName());
|
|
|
+ // rankVO.setSales(combination.getSales());
|
|
|
+ // rankVO.setImage(combination.getImage());
|
|
|
+ // rankVO.setPrice(combination.getPrice());
|
|
|
+ // list.add(rankVO);
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // redisUtil.set(key, list);
|
|
|
+ // return list;
|
|
|
+ // }
|
|
|
+
|
|
|
+
|
|
|
@Override
|
|
|
public List<StoreCombinationRankVO> getRank() {
|
|
|
List<StoreCombinationRankVO> list = new ArrayList<>();
|
|
|
- String key = "order:rank:";
|
|
|
- boolean exists = redisUtil.hasKey("order:rank");
|
|
|
- if (exists) {
|
|
|
- String orderVoString = redisUtil.get(key).toString();
|
|
|
- list = JSONObject.parseArray(orderVoString, StoreCombinationRankVO.class);
|
|
|
- return list;
|
|
|
- }
|
|
|
-
|
|
|
+ // String key = "order:rank:";
|
|
|
+ // boolean exists = redisUtil.hasKey("order:rank");
|
|
|
+ // if (exists) {
|
|
|
+ // String orderVoString = redisUtil.get(key).toString();
|
|
|
+ // list = JSONObject.parseArray(orderVoString, StoreCombinationRankVO.class);
|
|
|
+ // return list;
|
|
|
+ // }
|
|
|
+
|
|
|
Condition orderCondition = new Condition(StoreOrder.class);
|
|
|
Example.Criteria orderCriteria = orderCondition.createCriteria();
|
|
|
Date date = new Date();
|
|
@@ -189,14 +186,14 @@ public class OrderServiceBusinessImpl implements OrderServiceBusiness {
|
|
|
StoreOrder::getCombinationId,
|
|
|
Collectors.counting()
|
|
|
));
|
|
|
-
|
|
|
+
|
|
|
// 获取前10个热门商品组合
|
|
|
List<Map.Entry<Long, Long>> topCombinations = combinationCountMap.entrySet()
|
|
|
.stream()
|
|
|
.sorted(Map.Entry.<Long, Long>comparingByValue().reversed())
|
|
|
.limit(10)
|
|
|
.collect(Collectors.toList());
|
|
|
-
|
|
|
+
|
|
|
List<StoreCombination> combinationList = storeCombinationService.findByIds(String.join(",", topCombinations.stream().map(Map.Entry::getKey).map(Object::toString).collect(Collectors.toList())));
|
|
|
for (StoreCombination storeCombination : combinationList) {
|
|
|
List<StoreCombination> collect = combinationList.stream().filter(c -> c.getId().equals(storeCombination.getId())).collect(Collectors.toList());
|
|
@@ -211,9 +208,9 @@ public class OrderServiceBusinessImpl implements OrderServiceBusiness {
|
|
|
list.add(rankVO);
|
|
|
}
|
|
|
}
|
|
|
- redisUtil.set(key, list);
|
|
|
+ // redisUtil.set(key, list);
|
|
|
return list;
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
}
|