package cn.iocoder.yudao.module.system.service.supplier;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.system.controller.admin.supplier.vo.SupplierProductPageReqVO;
import cn.iocoder.yudao.module.system.controller.admin.supplier.vo.SupplierProductSaveReqVO;
import cn.iocoder.yudao.module.system.dal.dataobject.supplier.SupplierProductDO;
import cn.iocoder.yudao.module.system.dal.mysql.supplier.SupplierProductMapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;

import javax.annotation.Resource;
import java.util.List;

/**
 * 供应商商品 Service 实现类
 *
 * @author 艾楷
 */
@Service
@Validated
public class SupplierProductServiceImpl implements SupplierProductService {

    @Resource
    private SupplierProductMapper supplierProductMapper;

    @Override
    public Long createSupplierProduct(SupplierProductSaveReqVO createReqVO) {
        // 插入
        SupplierProductDO supplierProduct = BeanUtils.toBean(createReqVO, SupplierProductDO.class);
        supplierProductMapper.insert(supplierProduct);
        // 返回
        return supplierProduct.getId();
    }

    @Override
    public void updateSupplierProduct(SupplierProductSaveReqVO updateReqVO) {
        // 更新
        SupplierProductDO updateObj = BeanUtils.toBean(updateReqVO, SupplierProductDO.class);
        supplierProductMapper.updateById(updateObj);
    }

    @Override
    public void deleteSupplierProduct(Long id) {
        // 删除
        supplierProductMapper.deleteById(id);
    }

    @Override
    public SupplierProductDO getSupplierProduct(Long id) {
        return supplierProductMapper.selectById(id);
    }

    @Override
    public PageResult<SupplierProductDO> getSupplierProductPage(SupplierProductPageReqVO pageReqVO) {
        return supplierProductMapper.selectPage(pageReqVO);
    }

    @Override
    public List<SupplierProductDO> getBySupplierId(Long supplierId) {
        return supplierProductMapper.selectList(new LambdaQueryWrapper<SupplierProductDO>()
                .eq(SupplierProductDO::getSupplierId, supplierId));
    }

}
