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

import com.xisc.pm.domain.entity.PmCmdCont;
import com.xisc.pm.domain.repository.PmCmdContRepository;
import com.xisc.pm.infra.mapper.PmCmdContMapper;
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;

/**
 * 命令参数表(PmCmdCont)资源库
 *
 * @author 纪文桃 wentao.ji01@hand-china.com
 * @since 2024-08-01 10:25:08
 */
@Component
public class PmCmdContRepositoryImpl extends BaseRepositoryImpl<PmCmdCont> implements PmCmdContRepository {
    @Resource
    private PmCmdContMapper pmCmdContMapper;

    @Override
    public List<PmCmdCont> selectList(PmCmdCont pmCmdCont) {
        return pmCmdContMapper.selectList(pmCmdCont);
    }

    @Override
    public PmCmdCont selectByPrimary(Long pmCmdContId) {
        PmCmdCont pmCmdCont = new PmCmdCont();
        pmCmdCont.setPmCmdContId(pmCmdContId);
        List<PmCmdCont> pmCmdConts = pmCmdContMapper.selectList(pmCmdCont);
        if (CollectionUtils.isEmpty(pmCmdConts)) {
            return null;
        }
        return pmCmdConts.get(0);
    }

    @Override
    public List<PmCmdCont> selectByPonoSlabList(List<String> ponoSlabList, Long tenantId) {
        return this.selectByCondition(Condition.builder(PmCmdCont.class)
                        .andWhere(Sqls.custom().andIn(PmCmdCont.FIELD_PONO_SLAB_NO, ponoSlabList))
                        .andWhere(Sqls.custom().andEqualTo(PmCmdCont.FIELD_TENANT_ID, tenantId))
                .build());
    }

    @Override
    public List<PmCmdCont> selectByTmpSlabNoList(List<String> tmpSlabNoList, Long tenantId) {
        return this.selectByCondition(Condition.builder(PmCmdCont.class)
                .andWhere(Sqls.custom().andIn(PmCmdCont.FIELD_TMP_SLAB_NO, tmpSlabNoList))
                .andWhere(Sqls.custom().andEqualTo(PmCmdCont.FIELD_TENANT_ID, tenantId))
                .build());
    }

    @Override
    public List<PmCmdCont> selectByPonoAndPlateNo(List<String> ponoSlabNoList, List<String> plateNoList, Long tenantId) {
        return  this.selectByCondition(Condition.builder(PmCmdCont.class)
                .andWhere(Sqls.custom().andIn(PmCmdCont.FIELD_PONO_SLAB_NO, ponoSlabNoList))
                .andWhere(Sqls.custom().andIn(PmCmdCont.FIELD_PLATE_NO, plateNoList))
                .andWhere(Sqls.custom().andEqualTo(PmCmdCont.FIELD_TENANT_ID, tenantId))
                .build());
    }
}
