| | |
| | | import com.ruoyi.system.domain.*; |
| | | import com.ruoyi.system.dto.CheckoutDTO; |
| | | import com.ruoyi.system.dto.TOrderSaleDTO; |
| | | import com.ruoyi.system.mapper.TOrderSaleGoodsMapper; |
| | | import com.ruoyi.system.mapper.TOrderSaleMapper; |
| | | import com.ruoyi.system.query.*; |
| | | import com.ruoyi.system.service.TGoodsService; |
| | |
| | | |
| | | @Autowired |
| | | private TOrderSaleGoodsService orderSaleGoodsService; |
| | | @Autowired |
| | | private TOrderSaleGoodsMapper orderSaleGoodsMapper; |
| | | @Autowired |
| | | private TGoodsTypeService goodsTypeService; |
| | | @Autowired |
| | |
| | | } |
| | | |
| | | @Override |
| | | public List<SalesRankingVO> salesRanking(TDataStatisticsQuery query) { |
| | | public PageInfo<SalesRankingVO> salesRanking(TDataStatisticsQuery query) { |
| | | PageInfo<SalesRankingVO> pageInfo = new PageInfo<>(query.getPageNum(),query.getPageSize()); |
| | | List<TOrderSale> list = this.list(Wrappers.lambdaQuery(TOrderSale.class) |
| | | .eq(TOrderSale::getShopId, query.getShopId()) |
| | | .between(TOrderSale::getOrderTime, query.getStartTime(), query.getEndTime())); |
| | | List<Long> ids = list.stream().map(TOrderSale::getId).collect(Collectors.toList()); |
| | | List<SalesRankingVO> salesRankingVOS = new ArrayList<>(); |
| | | if(!CollectionUtils.isEmpty(ids)){ |
| | | List<TOrderSaleGoods> list1 = orderSaleGoodsService.list(Wrappers.lambdaQuery(TOrderSaleGoods.class) |
| | | .in(TOrderSaleGoods::getOrderId, ids)); |
| | | Map<Long, List<TOrderSaleGoods>> listMap = list1.stream().collect(Collectors.groupingBy(TOrderSaleGoods::getTypeId)); |
| | | List<TGoodsType> list2 = goodsTypeService.list(); |
| | | listMap.forEach((k,v)->{ |
| | | SalesRankingVO salesRankingVO = new SalesRankingVO(); |
| | | salesRankingVO.setTypeName(list2.stream().filter(e->e.getId().equals(k)).findFirst().get().getTypeName()); |
| | | salesRankingVO.setSalesVolume(v.stream().map(item->item.getGoodsSalePrice().multiply(new BigDecimal(item.getGoodsCount()))).reduce(BigDecimal.ZERO, BigDecimal::add)); |
| | | salesRankingVOS.add(salesRankingVO); |
| | | }); |
| | | if(CollectionUtils.isEmpty(ids)){ |
| | | return new PageInfo<>(); |
| | | } |
| | | return salesRankingVOS; |
| | | List<SalesRankingVO> salesRankingVOS = orderSaleGoodsMapper.salesRanking(ids,pageInfo); |
| | | pageInfo.setRecords(salesRankingVOS); |
| | | return pageInfo; |
| | | } |
| | | |
| | | @Override |