xuhy
2024-08-27 96483f10fdb66727c3767826fcec6c99958e74b6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package com.ruoyi.system.service.impl;
 
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.constant.OrderNumConstants;
import com.ruoyi.common.utils.CodeGenerateUtils;
import com.ruoyi.system.domain.TOrderSale;
import com.ruoyi.system.domain.TOrderSaleGoods;
import com.ruoyi.system.dto.TOrderSaleDTO;
import com.ruoyi.system.mapper.TOrderSaleMapper;
import com.ruoyi.system.service.TOrderSaleGoodsService;
import com.ruoyi.system.service.TOrderSaleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.math.BigDecimal;
import java.util.List;
 
/**
 * <p>
 * 销售订单 服务实现类
 * </p>
 *
 * @author xiaochen
 * @since 2024-08-14
 */
@Service
public class TOrderSaleServiceImpl extends ServiceImpl<TOrderSaleMapper, TOrderSale> implements TOrderSaleService {
 
    @Autowired
    private TOrderSaleGoodsService orderSaleGoodsService;
 
    @Override
    public void add(TOrderSaleDTO dto) {
        // 销售单号
        dto.setOrderNum(OrderNumConstants.SALE + CodeGenerateUtils.generateOrderSn());
        List<TOrderSaleGoods> orderSaleGoods = dto.getOrderSaleGoods();
        BigDecimal sum = orderSaleGoods.stream().map(TOrderSaleGoods::getGoodsSalePrice).reduce(BigDecimal::add).get();
        dto.setOrderMoney(sum);
        dto.setPayMoney(sum);
        this.save(dto);
        // 添加商品
        orderSaleGoods.forEach(orderSaleGoods1 -> orderSaleGoods1.setOrderId(dto.getId()));
        orderSaleGoodsService.saveBatch(orderSaleGoods);
    }
}