package com.jwipc.inquiry.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jwipc.inquiry.entity.Inquiry;
import com.jwipc.inquiry.entity.PriceInfo;
import com.jwipc.inquiry.mapper.PriceInfoMapper;
import com.jwipc.inquiry.model.po.CreatePriceInfoPO;
import com.jwipc.inquiry.model.po.HistoryPriceInfoPO;
import com.jwipc.inquiry.model.po.InquiryMaterialPO;
import com.jwipc.inquiry.model.po.PriceInfoPO;
import com.jwipc.inquiry.model.query.PriceInfoQuery;
import com.jwipc.inquiry.service.IPriceInfoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * <p>
 * 价格信息记录主表 服务实现类
 * </p>
 *
 * @author shenyang.ou
 * @since 2024-02-28
 */
@Service
public class PriceInfoServiceImpl extends ServiceImpl<PriceInfoMapper, PriceInfo> implements IPriceInfoService {

    /**
     * 根据询价id组装价格信息记录数据
     *
     * @param inquiryId 询价id
     * @return 价格信息记录数据
     */
    @Override
    public List<CreatePriceInfoPO> getByInquiryId(Long inquiryId) {
        return baseMapper.getByInquiryId(inquiryId);
    }

    @Override
    public List<PriceInfoPO> findPageByQuery(Page<Inquiry> dbPage, PriceInfoQuery query) {
        if (dbPage==null){
            return baseMapper.findPageByQuery(query);
        }
        return baseMapper.findPageByQuery(dbPage,query);
    }

    /**
     * 根据调价id组装价格信息记录
     *
     * @param id 调价id
     * @return 价格信息记录
     */
    @Override
    public List<CreatePriceInfoPO> getByAuditId(Long id) {
        return baseMapper.getByAuditId(id);
    }

    /**
     * 根据物料编码和工厂获取历史最低价
     *
     * @param materialCode 物料编码
     * @param factoryCode  工厂编码
     * @return 历史最低价
     */
    @Override
    public HistoryPriceInfoPO getHistoryLowPrice(String materialCode, String factoryCode) {
        return baseMapper.getHistoryLowPrice(materialCode,factoryCode);
    }

    /**
     * 根据物料编码和工厂获取上次中标价
     *
     * @param materialCode 物料编码
     * @param factoryCode  工厂编码
     * @return 上次中标价
     */
    @Override
    public HistoryPriceInfoPO getLastBidPrice(String materialCode, String factoryCode) {
        return baseMapper.getLastBidPrice(materialCode,factoryCode);
    }

    /**
     * 根据供应商编码和物料编码和工厂获取上次中标价
     *
     * @param supplierCode 供应商编码
     * @param materialCode 物料编码
     * @param factoryCode  工厂编码
     * @return 上次中标价
     */
    @Override
    public PriceInfoPO getSupplierLastBidPrice(String supplierCode, String materialCode, String factoryCode) {
        return baseMapper.getSupplierLastBidPrice(supplierCode,materialCode,factoryCode);
    }

    /**
     * 组装转询价物料列表
     *
     * @param priceInfoIdList 价格信息记录ids
     * @return 询价物料列表
     */
    @Override
    public List<InquiryMaterialPO> makeInquiryMaterial(List<String> priceInfoIdList) {
        return baseMapper.makeInquiryMaterial(priceInfoIdList);
    }

    @Override
    public PriceInfoPO getLastPrice(String materialCode, String factoryCode, String supplierCode) {
        return baseMapper.getLastPrice(materialCode,factoryCode,supplierCode);
    }

    @Override
    public List<PriceInfo> getEffectiveMinPrice(List<String> materialCodes, Date date) {
        return baseMapper.getEffectiveMinPrice(materialCodes, date);
    }
}
