package com.trade.service.trade.salesorder.service.impl;

import java.util.List;

import com.trade.service.trade.salesorder.vo.SalesOrderGoodsVO;
import com.trade.service.trade.salesorder.domain.SalesOrderGoods;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.trade.service.trade.salesorder.mapper.SalesOrderGoodsMapper;
import com.trade.service.trade.salesorder.service.ISalesOrderGoodsService;

/**
 * <p>
 * 销售订单-关联商品 服务实现类
 * </p>
 *
 * @author zhangchenm
 * @since 2024-09-06
 */
@Service
public class SalesOrderGoodsServiceImpl extends ServiceImpl<SalesOrderGoodsMapper, SalesOrderGoods> implements ISalesOrderGoodsService {

    @Override
    public List<SalesOrderGoodsVO> listByOrderId(Long orderId) {
        return this.baseMapper.listByOrderId(orderId);
    }

    @Override
    public void removeByOrderId(Long orderId) {
        this.baseMapper.physicallyDeleteByOrderId(orderId);
    }

    @Override
    public List<SalesOrderGoods> getByCommodityId(Long salesCommodityId) {
        return lambdaQuery().eq(SalesOrderGoods::getSalesCommodityId, salesCommodityId).list();
    }

    @Override
    public Long countBySaleOrderId(Long saleOrderId, Integer receivePaymentStatus) {
        return this.lambdaQuery().eq(SalesOrderGoods::getSaleOrderId, saleOrderId)
                .eq(SalesOrderGoods::getReceivePaymentStatus, receivePaymentStatus).count();
    }

    @Override
    public SalesOrderGoods getMaxAmountByIds(List<Long> ids) {
        return this.lambdaQuery().in(SalesOrderGoods::getId, ids).orderByDesc(SalesOrderGoods::getPriceTotal).one();
    }
}
