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

import com.xisc.pm.api.dto.PmPdContPanelMaterialDTO;
import com.xisc.pm.domain.entity.PmPdContSum;
import com.xisc.pm.domain.repository.PmPdContSumRepository;
import com.xisc.pm.infra.mapper.PmPdContSumMapper;
import org.apache.commons.collections.CollectionUtils;
import org.hzero.mybatis.base.impl.BaseRepositoryImpl;
import org.hzero.mybatis.domian.Condition;
import org.hzero.mybatis.util.Sqls;
import org.springframework.stereotype.Component;

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

/**
 * 组板合同总量表(PmPdContSum)资源库
 *
 * @author 纪文桃 wentao.ji01@hand-china.com
 * @since 2024-07-30 10:29:33
 */
@Component
public class PmPdContSumRepositoryImpl extends BaseRepositoryImpl<PmPdContSum> implements PmPdContSumRepository {
    @Resource
    private PmPdContSumMapper pmPdContSumMapper;

    @Override
    public List<PmPdContSum> selectList(PmPdContSum pmPdContSum) {
        return pmPdContSumMapper.selectList(pmPdContSum);
    }

    @Override
    public PmPdContSum selectByPrimary(Long ppcsId) {
        PmPdContSum pmPdContSum = new PmPdContSum();
        pmPdContSum.setPpcsId(ppcsId);
        List<PmPdContSum> pmPdContSums = pmPdContSumMapper.selectList(pmPdContSum);
        if (CollectionUtils.isEmpty(pmPdContSums)) {
            return null;
        }
        return pmPdContSums.get(0);
    }

    @Override
    public List<PmPdContPanelMaterialDTO> selectConPanelMaterialsList(String orderNoFrom, String orderNoTo,
            Long tenantId) {
        return pmPdContSumMapper.selectConPanelMaterialsList(orderNoFrom, orderNoTo, tenantId);
    }

    @Override
    public List<PmPdContSum> selectByOrderNoList(List<String> orderNoList, Long tenantId) {
        if (null == orderNoList || orderNoList.isEmpty()) {
            return new ArrayList<PmPdContSum>();
        }
        return this.selectByCondition(Condition.builder(PmPdContSum.class).andWhere(Sqls.custom()
                .andIn(PmPdContSum.FIELD_ORDER_NO, orderNoList).andEqualTo(PmPdContSum.FIELD_TENANT_ID, tenantId))
                .build());
    }

    @Override
    public List<PmPdContSum> selectByPdMatNo(Long tenantId, String virtualSlabNo) {
        PmPdContSum record = new PmPdContSum();
        record.setTenantId(tenantId);
        record.setPdMatNo(virtualSlabNo);
        return this.select(record);
    }

    @Override
    public int deleteByMatNo(Long tenantId, List<String> removePdMatNo) {
        return pmPdContSumMapper.deleteByMatNo(tenantId, removePdMatNo);
    }

    @Override
    public List<PmPdContSum> selectByPdMatNoList(Long tenantId, List<String> virtualSlabNoList) {
        return this.selectByCondition(Condition.builder(PmPdContSum.class).andWhere(Sqls.custom()
                        .andIn(PmPdContSum.FIELD_PD_MAT_NO, virtualSlabNoList)
                        .andEqualTo(PmPdContSum.FIELD_TENANT_ID, tenantId))
                .build());
    }

    @Override
    public List<PmPdContSum> selectBySlabNoList(List<String> slabNoList, Long tenantId) {
        return this.selectByCondition(Condition.builder(PmPdContSum.class).andWhere(Sqls.custom()
                        .andIn(PmPdContSum.FIELD_SLAB_NO, slabNoList)
                        .andEqualTo(PmPdContSum.FIELD_TENANT_ID, tenantId))
                .build());
    }
}
