package com.jwipc.order.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jwipc.exception.DaoException;
import com.jwipc.order.entity.ShortageData;
import com.jwipc.order.mapper.ShortageDataMapper;
import com.jwipc.order.model.po.ShortagePlanReplyPO;
import com.jwipc.order.model.query.BasicForeignQuotaQuery;
import com.jwipc.order.service.IShortageDataService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

/**
 * <p>
 * 欠料标准预测计划明细周期数据 服务实现类
 * </p>
 *
 * @author swq
 * @since 2024-04-28
 */
@Service
public class ShortageDataServiceImpl extends ServiceImpl<ShortageDataMapper, ShortageData>
        implements IShortageDataService
{



    @Override
    public List<ShortagePlanReplyPO> getSupplierReply(Page<ShortagePlanReplyPO> page, BasicForeignQuotaQuery query) {
        //避免因重置引起的欠料计划ID为空。
        if (null == query.getPlanId()) {
//            throw new DaoException("请重新查询，查询欠料计划ID不能为空！");
        }
        //先去掉空格
        if (StringUtils.isNotEmpty(query.getMaterial())) {
            query.setMaterial(query.getMaterial().trim());
        }
        if (StringUtils.isNotEmpty(query.getMaterial()) && query.getMaterial().indexOf(" ") > 0) {
            query.setMaterial(query.getMaterial().replaceAll(" ", "|"));
        }
        if (StringUtils.isNotEmpty(query.getMaterial()) && query.getMaterial().indexOf(",") > 0) {
            query.setMaterial(query.getMaterial().replace(",", "|"));
        }

        if(Objects.nonNull(page)){
            return this.baseMapper.findSupplierReply(page,query);
        }else{
            return this.baseMapper.findSupplierReply(query);
        }

    }

    @Override
    public void delShortAgeDetailBySerialNumber(String dateNumber) {
        this.baseMapper.delShortAgeDetailBySerialNumber(dateNumber);
    }

    @Override
    public void delShortAgeDataBySerialNumber(String dateNumber) {
        this.baseMapper.delShortAgeDataBySerialNumber(dateNumber);
    }


    @Override
    public ShortagePlanReplyPO findSupplierRecentReply(ShortagePlanReplyPO shortagePlanReplyPO) {
        return this.baseMapper.findSupplierRecentReply(shortagePlanReplyPO);
    }
}
