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

import com.xisc.pm.domain.entity.PmSteelCastLotItf;
import com.xisc.pm.domain.repository.PmSteelCastLotItfRepository;
import com.xisc.pm.infra.constant.Constants;
import com.xisc.pm.infra.mapper.PmSteelCastLotItfMapper;
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;

/**
 * 炼钢连铸制造命令LOT-接口表(PmSteelCastLotItf)资源库
 *
 * @author jie.yang04@hand-chian.com
 * @since 2024-10-15 10:30:10
 */
@Component
public class PmSteelCastLotItfRepositoryImpl extends BaseRepositoryImpl<PmSteelCastLotItf> implements PmSteelCastLotItfRepository {
    @Resource
    private PmSteelCastLotItfMapper pmSteelCastLotItfMapper;

    @Override
    public List<PmSteelCastLotItf> selectList(PmSteelCastLotItf pmSteelCastLotItf) {
        return pmSteelCastLotItfMapper.selectList(pmSteelCastLotItf);
    }

    @Override
    public PmSteelCastLotItf selectByPrimary(Long itfId) {
        PmSteelCastLotItf pmSteelCastLotItf = new PmSteelCastLotItf();
        pmSteelCastLotItf.setItfId(itfId);
        List<PmSteelCastLotItf> pmSteelCastLotItfs = pmSteelCastLotItfMapper.selectList(pmSteelCastLotItf);
        if (CollectionUtils.isEmpty(pmSteelCastLotItfs)) {
            return null;
        }
        return pmSteelCastLotItfs.get(0);
    }

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

