xuhy
2024-09-06 06a5f91f1d621cb331ccb41c4ae975b2a949fbbf
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TOrderStockServiceImpl.java
@@ -18,6 +18,7 @@
import com.ruoyi.system.vo.TOrderStockVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.math.BigDecimal;
import java.time.LocalDateTime;
@@ -48,7 +49,10 @@
//        dto.setStockTotalPrice(sum);
        this.save(dto);
        // 添加商品
        orderStockGoods.forEach(orderSaleGoods1 -> orderSaleGoods1.setOrderId(dto.getId()));
        orderStockGoods.forEach(orderSaleGoods1 -> {
            orderSaleGoods1.setId(null);
            orderSaleGoods1.setOrderId(dto.getId());
        });
        tOrderStockGoodsService.saveBatch(orderStockGoods);
    }
@@ -62,7 +66,10 @@
        tOrderStockGoodsService.remove(Wrappers.lambdaQuery(TOrderStockGoods.class)
                .eq(TOrderStockGoods::getOrderId,dto.getId()));
        // 添加商品
        orderStockGoods.forEach(orderSaleGoods1 -> orderSaleGoods1.setOrderId(dto.getId()));
        orderStockGoods.forEach(orderSaleGoods1 -> {
            orderSaleGoods1.setId(null);
            orderSaleGoods1.setOrderId(dto.getId());
        });
        tOrderStockGoodsService.saveBatch(orderStockGoods);
    }
@@ -102,12 +109,17 @@
        List<TOrderStockVO> list = this.baseMapper.pageList(query,pageInfo);
        // 查询商品
        List<Long> orderIds = list.stream().map(TOrderStockVO::getId).collect(Collectors.toList());
        List<TOrderStockGoods> orderStockGoods = tOrderStockGoodsService.list(Wrappers.lambdaQuery(TOrderStockGoods.class)
                .in(TOrderStockGoods::getOrderId, orderIds));
        list.forEach(orderSale -> {
            List<TOrderStockGoods> collect = orderStockGoods.stream().filter(orderSaleGoods -> orderSaleGoods.getOrderId().equals(orderSale.getId())).collect(Collectors.toList());
            orderSale.setOrderStockGoods(collect);
        });
        if(!CollectionUtils.isEmpty(orderIds)){
            List<TOrderStockGoods> orderStockGoods = tOrderStockGoodsService.list(Wrappers.lambdaQuery(TOrderStockGoods.class)
                    .in(TOrderStockGoods::getOrderId, orderIds));
            list.forEach(orderSale -> {
                List<TOrderStockGoods> collect = orderStockGoods.stream().filter(orderSaleGoods -> orderSaleGoods.getOrderId().equals(orderSale.getId())).collect(Collectors.toList());
                if(!CollectionUtils.isEmpty(collect)){
                    orderSale.setOrderStockGoods(collect);
                    orderSale.setTotalPrice(collect.stream().map(TOrderStockGoods::getCostPrice).reduce(BigDecimal::add).get());
                }
            });
        }
        pageInfo.setRecords(list);
        return pageInfo;
    }