xuhy
2024-10-31 0b00c7532a0330785d0c8cf46bcb05dfc63e65c4
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TOrderSaleServiceImpl.java
@@ -22,10 +22,7 @@
import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.*;
import java.util.stream.Collectors;
/**
@@ -45,6 +42,8 @@
    private TOrderStockGoodsService orderStockGoodsService;
    @Autowired
    private TOrderSaleGoodsMapper orderSaleGoodsMapper;
    @Autowired
    private TGoodsService goodsService;
    @Override
    public void add(TOrderSaleDTO dto) {
        // 查询菜品分类
@@ -58,6 +57,18 @@
        }
        dto.setOrderMoney(sum);
        this.save(dto);
        List<TGoods> goods = goodsService.list(Wrappers.lambdaQuery(TGoods.class).eq(TGoods::getShopId,dto.getShopId()));
        List<TGoods> goodsList = new ArrayList<>();
        for (TOrderSaleGoods orderSaleGood : orderSaleGoods) {
            goods.forEach(good -> {
                if(orderSaleGood.getGoodsNum().equals(good.getGoodsNum())){
                    good.setInventory(good.getInventory()-orderSaleGood.getGoodsCount());
                    goodsList.add(good);
                }
            });
        }
        goodsService.updateBatchById(goodsList);
        // 查询进货数据
        List<TOrderStockGoods> orderStockGoodsList = orderStockGoodsService.getListByTimeAndShopId(DateUtils.localDateToString(dto.getOrderTime()), dto.getShopId());
@@ -241,19 +252,54 @@
        }
        List<TOrderSaleVO> list = this.baseMapper.exportOrderSale(query);
        List<Long> ids = list.stream().map(TOrderSaleVO::getId).collect(Collectors.toList());
        List<TOrderSaleGoods> list1 = orderSaleGoodsService.list(Wrappers.lambdaQuery(TOrderSaleGoods.class)
                .in(TOrderSaleGoods::getOrderId,ids));
        // 查询商品信息
        for (TOrderSaleVO orderSaleVO : list) {
            List<TOrderSaleGoods> collect = list1.stream().filter(e -> e.getOrderId().equals(orderSaleVO.getId())).collect(Collectors.toList());
            orderSaleVO.setOrderSaleGoods(collect);
        if(!CollectionUtils.isEmpty(ids)){
            List<TOrderSaleGoods> list1 = orderSaleGoodsService.list(Wrappers.lambdaQuery(TOrderSaleGoods.class)
                    .in(TOrderSaleGoods::getOrderId, ids));
            list.forEach(e->{
                List<TOrderSaleGoods> collect = list1.stream().filter(m -> m.getOrderId().equals(e.getId())).collect(Collectors.toList());
                if(!CollectionUtils.isEmpty(collect)){
                    BigDecimal goodsAmount = BigDecimal.ZERO;
                    Integer count = 0;
                    for (TOrderSaleGoods tOrderSaleGoods : collect) {
                        goodsAmount = goodsAmount.add(tOrderSaleGoods.getThisSalePrice().multiply(new BigDecimal(tOrderSaleGoods.getGoodsCount())));
                        count = count+tOrderSaleGoods.getGoodsCount();
                    }
                    e.setGoodsAmount(goodsAmount);
                    e.setGoodsCount(count);
                    e.setOrderSaleGoods(collect);
                }
            });
        }
        return list;
    }
    @Override
    public List<OrderTrendsVO> orderingTrends(TDataStatisticsQuery query) {
        return this.baseMapper.orderingTrends(query);
        List<OrderTrendsVO> orderTrendsVOS = this.baseMapper.orderingTrends(query);
        LocalDate localDate = DateUtils.stringToLocalDateTime(query.getEndTime()).toLocalDate();
        for (int i = 0; i < 7; i++) {
            if(i == 0){
                LocalDate finalLocalDate = localDate;
                OrderTrendsVO orderTrendsVO = orderTrendsVOS.stream().filter(e -> finalLocalDate.compareTo(DateUtils.stringToLocalDate(e.getDayTime())) == 0).findFirst().orElse(null);
                if(Objects.isNull(orderTrendsVO)){
                    orderTrendsVO = new OrderTrendsVO();
                    orderTrendsVO.setDayTime(DateUtils.localDateToString(localDate));
                    orderTrendsVO.setOrderCount(0);
                    orderTrendsVOS.add(orderTrendsVO);
                }
            }else {
                localDate = localDate.minusDays(1);
                LocalDate finalLocalDate1 = localDate;
                OrderTrendsVO orderTrendsVO = orderTrendsVOS.stream().filter(e -> finalLocalDate1.compareTo(DateUtils.stringToLocalDate(e.getDayTime())) == 0).findFirst().orElse(null);
                if(Objects.isNull(orderTrendsVO)){
                    orderTrendsVO = new OrderTrendsVO();
                    orderTrendsVO.setDayTime(DateUtils.localDateToString(finalLocalDate1));
                    orderTrendsVO.setOrderCount(0);
                    orderTrendsVOS.add(orderTrendsVO);
                }
            }
        }
        return orderTrendsVOS.stream().sorted(Comparator.comparing(OrderTrendsVO::getDayTime)).collect(Collectors.toList());
    }
    @Override
@@ -339,9 +385,6 @@
        orderSale.setPayType(dto.getPayType());
        orderSale.setPayMoney(dto.getPayMoney());
        orderSale.setStatus(2);
        this.updateById(orderSale);
    }
@@ -404,4 +447,9 @@
    public List<GoodsProfitVO> profitDetailsExport(ProfitDetailsQuery query) {
        return this.baseMapper.profitDetailsExport(query);
    }
    @Override
    public void deleteByShopId(Long shopId) {
        this.baseMapper.deleteByShopId(shopId);
    }
}