package com.xisc.pm.infra.repository.impl;

import com.google.common.collect.Sets;
import com.xisc.pm.api.dto.ObtainWitnessPointDTO;
import com.xisc.pm.api.dto.PmProContPoolRequestDTO;
import com.xisc.pm.api.dto.PmProContPoolResposeDTO;
import com.xisc.pm.domain.repository.PmQdToPoOrderRepository;
import com.xisc.pm.domain.vo.QdToPoLineCombVO;
import com.xisc.pm.domain.vo.QdToPoOrderVO1;
import com.xisc.pm.infra.mapper.QdToPoOrderMapper;
import org.apache.commons.collections.CollectionUtils;
import org.hzero.mybatis.base.impl.BaseRepositoryImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * MES合同主档(ToPoOrder)资源库
 *
 * @author jun.zeng
 * @since 2024-08-09 09:17:27
 */
@Component
public class PmQdToPoOrderRepositoryImpl extends BaseRepositoryImpl<QdToPoOrderVO1> implements PmQdToPoOrderRepository {

    @Autowired
    private QdToPoOrderMapper qdToPoOrderMapper;

    @Override
    public List<PmProContPoolResposeDTO> selectByOrderNoList(PmProContPoolRequestDTO request) {
        return qdToPoOrderMapper.selectQdToPoOrder(request);
    }

    @Override
    public List<QdToPoOrderVO1> selectList(QdToPoOrderVO1 qdToPoOrderVO1) {
        return qdToPoOrderMapper.selectList(qdToPoOrderVO1);
    }
    
    @Override
    public QdToPoOrderVO1 selectByOrderNo(String orderNo, Long tenantId) {
        QdToPoOrderVO1 qdToPoOrderVO1 = new QdToPoOrderVO1();
        qdToPoOrderVO1.setOrderNo(orderNo);
        qdToPoOrderVO1.setTenantId(tenantId);
        List<QdToPoOrderVO1> list = qdToPoOrderMapper.selectList(qdToPoOrderVO1);
        if(list == null || list.isEmpty()) {
            return null;
        }
        return list.get(0);
    }

    @Override
    public QdToPoOrderVO1 selectByPrimary(Long pomId) {
        QdToPoOrderVO1 qdToPoOrderVO1 = new QdToPoOrderVO1();
        qdToPoOrderVO1.setPomId(pomId);
        List<QdToPoOrderVO1> qdToPoOrderVO1s = qdToPoOrderMapper.selectList(qdToPoOrderVO1);
        if (CollectionUtils.isEmpty(qdToPoOrderVO1s)) {
            return null;
        }
        return qdToPoOrderVO1s.get(0);
    }

    @Override
    public List<QdToPoOrderVO1> surplusSteelPlateOrderList(QdToPoOrderVO1 qdToPoOrderVO1) {
        return qdToPoOrderMapper.orderList(qdToPoOrderVO1);
    }

    @Override
    public List<QdToPoOrderVO1> surplusSlabOrderList(QdToPoOrderVO1 qdToPoOrderVO1) {
        return qdToPoOrderMapper.surplusSlabOrderList(qdToPoOrderVO1);
    }

    @Override
    public Set<String> qdToLineupResultSampleOrderList(List<String> orderNoList, Long tenantId) {
        List<String> orderList = qdToPoOrderMapper.qdToLineupResultSampleOrderList(orderNoList, tenantId);
        if (orderList == null || orderList.isEmpty()) {
            return new HashSet<>();
        }
        return Sets.newHashSet(orderList);
    }
    
    @Override
    public Set<String> qdToLineupResultSampleAllOrderList(List<String> orderNoList, Long tenantId) {
        List<String> orderList = qdToPoOrderMapper.qdToLineupResultSampleAllOrderList(orderNoList, tenantId);
        if (orderList == null || orderList.isEmpty()) {
            return new HashSet<>();
        }
        return Sets.newHashSet(orderList);
    }



    @Override
    public List<String> selectFhbOrderNoByBaseOrderNo(Long tenantId, String baseOrderNo, String slabType, String qfhQueryFlag,
                                                      List<String> lovHavingComList, List<String> lovNotHavingComList,
                                                      List<String> lovNotHavingComEList) {
        return qdToPoOrderMapper.selectFhbOrderNoByBaseOrderNo(baseOrderNo, tenantId, slabType, qfhQueryFlag, lovHavingComList, lovNotHavingComList, lovNotHavingComEList);
    }

    @Override
    public List<QdToPoOrderVO1> selectQdOrderList(List<String> orderNoList, Long tenantId) {
        return qdToPoOrderMapper.selectQdOrderList(orderNoList, tenantId);
    }

    @Override
    public List<ObtainWitnessPointDTO> selectWitnessOrderPass(List<String> orderNoList, List<String> witnessPointList, Long tenantId) {
        return qdToPoOrderMapper.selectWitnessOrderPass(orderNoList, witnessPointList, tenantId);
    }

    @Override
    public List<QdToPoLineCombVO> selectQdToPoLineCombList(List<String> orderNoList, List<String> mscLineNoList, Long tenantId) {
        return qdToPoOrderMapper.selectQdToPoLineCombList(orderNoList, mscLineNoList, tenantId);
    }

    @Override
    public List<QdToPoLineCombVO> selectByOrderAndMscLineList(List<String> orderNoList, List<String> mscLineNoList, Long tenantId) {
        return qdToPoOrderMapper.selectByOrderAndMscLineList(orderNoList, mscLineNoList, tenantId);
    }
}
