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

import com.xisc.pm.domain.entity.PmCompositeSlabList;
import com.xisc.pm.domain.entity.PmProContProdTtr;
import com.xisc.pm.domain.repository.PmCompositeSlabListRepository;
import com.xisc.pm.infra.mapper.PmCompositeSlabListMapper;
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;

/**
 * 复合/叠轧坯明细信息表(PmCompositeSlabList)资源库
 *
 * @author 纪文桃 wentao.ji01@hand-china.com
 * @since 2024-08-01 15:40:18
 */
@Component
public class PmCompositeSlabListRepositoryImpl extends BaseRepositoryImpl<PmCompositeSlabList>
        implements PmCompositeSlabListRepository {
    @Resource
    private PmCompositeSlabListMapper pmCompositeSlabListMapper;

    @Override
    public List<PmCompositeSlabList> selectList(PmCompositeSlabList pmCompositeSlabList) {
        return pmCompositeSlabListMapper.selectList(pmCompositeSlabList);
    }

    @Override
    public PmCompositeSlabList selectByPrimary(Long listId) {
        PmCompositeSlabList pmCompositeSlabList = new PmCompositeSlabList();
        pmCompositeSlabList.setListId(listId);
        List<PmCompositeSlabList> pmCompositeSlabLists = pmCompositeSlabListMapper.selectList(pmCompositeSlabList);
        if (CollectionUtils.isEmpty(pmCompositeSlabLists)) {
            return null;
        }
        return pmCompositeSlabLists.get(0);
    }

    @Override
    public List<PmProContProdTtr> queryOrderAttrByOrderNo(List<String> orderNoList, Long tenantId) {
        return pmCompositeSlabListMapper.queryOrderAttrByOrderNo(orderNoList, tenantId);
    }

    @Override
    public PmCompositeSlabList selectFirstLayer(Long tenantId, Long slabId) {
        PmCompositeSlabList firstLayer = new PmCompositeSlabList();
        firstLayer.setTenantId(tenantId);
        firstLayer.setSlabId(slabId);
        firstLayer.setLayerNo(1L);
        return this.selectOne(firstLayer);
    }

    @Override
    public List<PmCompositeSlabList> selectBySlabIdList(List<Long> slabIdList, Long tenantId) {
        return this.selectByCondition(Condition.builder(PmCompositeSlabList.class)
                        .andWhere(Sqls.custom().andIn(PmCompositeSlabList.FIELD_SLAB_ID, slabIdList))
                        .andWhere(Sqls.custom().andEqualTo(PmCompositeSlabList.FIELD_TENANT_ID, tenantId))
                .build());
    }

    @Override
    public List<PmCompositeSlabList> selectByBaseMatNoList(List<String> baseMatNoList, Long tenantId) {
        return this.selectByCondition(Condition.builder(PmCompositeSlabList.class)
                .andWhere(Sqls.custom().andIn(PmCompositeSlabList.FIELD_BASE_MAT_NO, baseMatNoList))
                .andWhere(Sqls.custom().andEqualTo(PmCompositeSlabList.FIELD_TENANT_ID, tenantId))
                .build());
    }
}
