|
@@ -1,11 +1,14 @@
|
|
|
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.StoreOrderMapper;
|
|
|
+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;
|
|
@@ -20,6 +23,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.util.ObjectUtils;
|
|
|
import tk.mybatis.mapper.entity.Condition;
|
|
|
import tk.mybatis.mapper.entity.Example;
|
|
|
+import tk.mybatis.mapper.entity.SqlsCriteria;
|
|
|
import vo.StoreCombinationRankVO;
|
|
|
import vo.StoreOrderVO;
|
|
|
|
|
@@ -44,6 +48,7 @@ public class OrderServiceBusinessImpl implements OrderServiceBusiness {
|
|
|
private final StorePinkService storePinkService;
|
|
|
private final RedisUtil redisUtil;
|
|
|
private final CifRedEnvelopeDubboServiceClient cifRedEnvelopeDubboServiceClient;
|
|
|
+ private final StoreOrderMapper storeOrderMapper;
|
|
|
|
|
|
@Override
|
|
|
public StoreOrderVO orderDetail(Long id, String orderNo) {
|
|
@@ -55,8 +60,8 @@ public class OrderServiceBusinessImpl implements OrderServiceBusiness {
|
|
|
storeOrder = storeOrderService.findBy("orderId", orderNo);
|
|
|
}
|
|
|
|
|
|
- if(ObjectUtils.isEmpty(storeOrder)){
|
|
|
- throw new ServiceException(I18nUtil.get("order.does.not.exist.id")+id);
|
|
|
+ if (ObjectUtils.isEmpty(storeOrder)) {
|
|
|
+ throw new ServiceException(I18nUtil.get("order.does.not.exist.id") + id);
|
|
|
}
|
|
|
id = storeOrder.getId();
|
|
|
Condition infoCondition = new Condition(StoreOrderInfo.class);
|
|
@@ -155,60 +160,53 @@ public class OrderServiceBusinessImpl implements OrderServiceBusiness {
|
|
|
// redisUtil.set(key, list);
|
|
|
// return list;
|
|
|
// }
|
|
|
-
|
|
|
+ private StorePinkMapper storePinkMapper;
|
|
|
|
|
|
@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();
|
|
|
+// 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;
|
|
|
+// }
|
|
|
+
|
|
|
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);
|
|
|
- List<Integer> statusList = new ArrayList<>();
|
|
|
- statusList.add(PinkOrderStatusEnum.GROUP_ORDER_TO_RECEIVE.getKey());
|
|
|
- statusList.add(PinkOrderStatusEnum.GROUP_ORDER_TO_SHIP.getKey());
|
|
|
- statusList.add(PinkOrderStatusEnum.GROUP_ORDER_COMPLETED.getKey());
|
|
|
- statusList.add(PinkOrderStatusEnum.GROUP_ORDER_CLOSED.getKey());
|
|
|
- orderCriteria.andIn("status", statusList);
|
|
|
- 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())
|
|
|
- .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());
|
|
|
- if (CollectionUtils.isNotEmpty(collect)) {
|
|
|
- StoreCombination combination = collect.get(0);
|
|
|
+ Date date1 = DateUtils.addDays(date, -7);
|
|
|
+ // List<Map<String, Object>> rank = storeOrderMapper.getRank(date1);
|
|
|
+ List<Map<String, Object>> rank = storePinkMapper.getRank(date1);
|
|
|
+
|
|
|
+
|
|
|
+ if (!CollectionUtils.isEmpty(rank)) {
|
|
|
+ Map<Long, Map<String, Object>> saleMap = rank.stream().collect(Collectors.toMap(a -> Long.valueOf(a.get("combination_id")+"") , a -> a, (b, c) -> c));
|
|
|
+ List<Long> combinationId = rank.stream().map(a -> Long.valueOf(a.get("combination_id")+"")).collect(Collectors.toList());
|
|
|
+ Condition storeCombinationCondition = new Condition(StoreCombination.class);
|
|
|
+ Example.Criteria storeCombinationCriteria = storeCombinationCondition.createCriteria();
|
|
|
+ storeCombinationCriteria.andIn("id", combinationId);
|
|
|
+ List<StoreCombination> combinationList = storeCombinationService.findByCondition(storeCombinationCondition);
|
|
|
+ for (StoreCombination storeCombination : combinationList) {
|
|
|
+ Map<String, Object> stringObjectMap = saleMap.get(storeCombination.getId());
|
|
|
StoreCombinationRankVO rankVO = new StoreCombinationRankVO();
|
|
|
- rankVO.setProductId(combination.getProductId());
|
|
|
- rankVO.setProductName(combination.getProductName());
|
|
|
- rankVO.setSales(combination.getSales());
|
|
|
- rankVO.setImage(combination.getImage());
|
|
|
- rankVO.setPrice(combination.getPrice());
|
|
|
+ rankVO.setProductId(storeCombination.getProductId());
|
|
|
+ rankVO.setProductName(storeCombination.getProductName());
|
|
|
+ String num = stringObjectMap.get("num") + "";
|
|
|
+ rankVO.setSales(Integer.valueOf(num));
|
|
|
+ rankVO.setImage(storeCombination.getImage());
|
|
|
+ rankVO.setPrice(storeCombination.getPrice());
|
|
|
list.add(rankVO);
|
|
|
}
|
|
|
+ if(!CollectionUtils.isEmpty(list)){
|
|
|
+ list =list.stream().sorted(Comparator.comparing(StoreCombinationRankVO::getSales).reversed()).collect(Collectors.toList());
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
// redisUtil.set(key, list);
|
|
|
return list;
|
|
|
}
|