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

import com.xisc.pm.api.dto.PmCompositeSlaParamDTO;
import com.xisc.pm.api.dto.PmCompositeSlabPdDTO;
import com.xisc.pm.api.dto.PmCompositeSlabReqDTO;
import com.xisc.pm.domain.entity.PmCompositeSlab;
import com.xisc.pm.domain.repository.PmCompositeSlabRepository;
import com.xisc.pm.domain.vo.CtDetVO;
import com.xisc.pm.infra.mapper.PmCompositeSlabMapper;
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.List;

/**
 * 复合/叠轧坯基本信息表(PmCompositeSlab)资源库
 *
 * @author 纪文桃 wentao.ji01@hand-china.com
 * @since 2024-08-01 15:46:27
 */
@Component
public class PmCompositeSlabRepositoryImpl extends BaseRepositoryImpl<PmCompositeSlab>
        implements PmCompositeSlabRepository {
    @Resource
    private PmCompositeSlabMapper pmCompositeSlabMapper;

    @Override
    public List<PmCompositeSlab> selectList(PmCompositeSlab pmCompositeSlab) {
        return pmCompositeSlabMapper.selectList(pmCompositeSlab);
    }

    @Override
    public PmCompositeSlab selectByPrimary(Long slabId) {
        PmCompositeSlab pmCompositeSlab = new PmCompositeSlab();
        pmCompositeSlab.setSlabId(slabId);
        List<PmCompositeSlab> pmCompositeSlabs = pmCompositeSlabMapper.selectList(pmCompositeSlab);
        if (CollectionUtils.isEmpty(pmCompositeSlabs)) {
            return null;
        }
        return pmCompositeSlabs.get(0);
    }

    @Override
    public List<PmCompositeSlab> selectSlabIds(PmCompositeSlabReqDTO dto, Long tenantId) {
        return pmCompositeSlabMapper.selectSlabIds(dto, tenantId);
    }

    @Override
    public List<PmCompositeSlabPdDTO> compositePdList(PmCompositeSlaParamDTO dto) {
        return pmCompositeSlabMapper.compositePdList(dto);
    }

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

    @Override
    public List<CtDetVO> selectCtDetByOrderList(List<String> orderNoList, Long tenantId) {
        return pmCompositeSlabMapper.selectCtDetByOrderList(orderNoList, tenantId);
    }
}
