|
@@ -4,15 +4,18 @@ 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.cif.dto.OrderParam;
|
|
|
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;
|
|
|
import com.txz.mall.model.*;
|
|
|
import com.txz.mall.service.*;
|
|
|
+import com.txz.mall.util.I18nUtil;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
import org.apache.commons.lang.time.DateUtils;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
@@ -21,6 +24,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;
|
|
|
|
|
@@ -45,21 +49,22 @@ 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) {
|
|
|
+ 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(I18nUtil.get("order.does.not.exist.id") + id);
|
|
|
}
|
|
|
- id =storeOrder.getId();
|
|
|
+ id = storeOrder.getId();
|
|
|
Condition infoCondition = new Condition(StoreOrderInfo.class);
|
|
|
Example.Criteria infoCriteria = infoCondition.createCriteria();
|
|
|
infoCriteria.andEqualTo("isDelete", 0);
|
|
@@ -73,28 +78,31 @@ public class OrderServiceBusinessImpl implements OrderServiceBusiness {
|
|
|
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());
|
|
|
+ List<OrderParam> orderCodeList = new ArrayList<>();
|
|
|
+ OrderParam orderParam = new OrderParam();
|
|
|
+ orderParam.setOrderNo(storeOrder.getOrderId());
|
|
|
+ orderParam.setUserId(storeOrder.getUid());
|
|
|
+ orderCodeList.add(orderParam);
|
|
|
|
|
|
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());
|
|
|
}
|
|
|
|
|
@@ -102,14 +110,67 @@ public class OrderServiceBusinessImpl implements OrderServiceBusiness {
|
|
|
vo.setOrderAddressVO(userAddress);
|
|
|
vo.setOrderStatusVO(logList);
|
|
|
|
|
|
-// vo.setUserVO(user);
|
|
|
+ // vo.setUserVO(user);
|
|
|
return vo;
|
|
|
}
|
|
|
|
|
|
-//
|
|
|
-// @Override
|
|
|
-// public List<StoreCombinationRankVO> getRank() {
|
|
|
-// List<StoreCombinationRankVO> list = new ArrayList<>();
|
|
|
+ //
|
|
|
+ // @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;
|
|
|
+ // }
|
|
|
+ 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) {
|
|
@@ -117,101 +178,51 @@ public class OrderServiceBusinessImpl implements OrderServiceBusiness {
|
|
|
// 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;
|
|
|
-// }
|
|
|
|
|
|
+ Date date = new Date();
|
|
|
+ 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("pid")+"") , a -> a, (b, c) -> c));
|
|
|
+ List<Long> pidList = rank.stream().map(a -> Long.valueOf(a.get("pid")+"")).collect(Collectors.toList());
|
|
|
+
|
|
|
+ Condition storeCombinationCondition = new Condition(StoreCombination.class);
|
|
|
+ Example.Criteria storeCombinationCriteria = storeCombinationCondition.createCriteria();
|
|
|
+ storeCombinationCriteria.andIn("productId", pidList);
|
|
|
+ List<StoreCombination> combinationList = storeCombinationService.findByCondition(storeCombinationCondition);
|
|
|
+ Map<Long, StoreCombination> storeCombinationMap = new HashMap<>();
|
|
|
+ if(!CollectionUtils.isEmpty(combinationList)){
|
|
|
+ storeCombinationMap = combinationList.stream().collect(Collectors.toMap(StoreCombination::getProductId, a -> a, (b, c) -> c));
|
|
|
+ }
|
|
|
+ for (Map<String, Object> stringObjectMap : rank) {
|
|
|
|
|
|
|
|
|
- @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;
|
|
|
- }
|
|
|
+ Object pid = stringObjectMap.get("pid");
|
|
|
+ Object num = stringObjectMap.get("num");
|
|
|
|
|
|
- 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);
|
|
|
- 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);
|
|
|
+ StoreCombination storeCombination = storeCombinationMap.get(Long.parseLong(pid + ""));
|
|
|
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());
|
|
|
+ rankVO.setSales(Integer.valueOf(num+""));
|
|
|
+ rankVO.setFicti(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);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ // redisUtil.set(key, list);
|
|
|
return list;
|
|
|
}
|
|
|
|