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

import com.xisc.pm.domain.entity.PmSteelCastFlowItf;
import com.xisc.pm.domain.repository.PmSteelCastFlowItfRepository;
import com.xisc.pm.infra.constant.Constants;
import com.xisc.pm.infra.mapper.PmSteelCastFlowItfMapper;
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;

/**
 * 炼钢连铸制造命令铸机流-接口表(PmSteelCastFlowItf)资源库
 *
 * @author jie.yang04@hand-chian.com
 * @since 2024-10-15 10:29:37
 */
@Component
public class PmSteelCastFlowItfRepositoryImpl extends BaseRepositoryImpl<PmSteelCastFlowItf> implements PmSteelCastFlowItfRepository {
    @Resource
    private PmSteelCastFlowItfMapper pmSteelCastFlowItfMapper;

    @Override
    public List<PmSteelCastFlowItf> selectList(PmSteelCastFlowItf pmSteelCastFlowItf) {
        return pmSteelCastFlowItfMapper.selectList(pmSteelCastFlowItf);
    }

    @Override
    public PmSteelCastFlowItf selectByPrimary(Long itfId) {
        PmSteelCastFlowItf pmSteelCastFlowItf = new PmSteelCastFlowItf();
        pmSteelCastFlowItf.setItfId(itfId);
        List<PmSteelCastFlowItf> pmSteelCastFlowItfs = pmSteelCastFlowItfMapper.selectList(pmSteelCastFlowItf);
        if (CollectionUtils.isEmpty(pmSteelCastFlowItfs)) {
            return null;
        }
        return pmSteelCastFlowItfs.get(0);
    }

    @Override
    public List<PmSteelCastFlowItf> selectByPonoList(List<String> ponoList, Long tenantId) {
        return this.selectByCondition(Condition.builder(PmSteelCastFlowItf.class)
                .andWhere(Sqls.custom().andIn(PmSteelCastFlowItf.FIELD_PONO, ponoList))
                .andWhere(Sqls.custom().andEqualTo(PmSteelCastFlowItf.FIELD_TENANT_ID, tenantId))
                .andWhere(Sqls.custom().andEqualTo(PmSteelCastFlowItf.FIELD_ITF_STATUS, Constants.ItfStatus.N))
                .build());
    }
}

