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

import com.xisc.pm.domain.entity.PmHotDest;
import com.xisc.pm.domain.repository.PmHotDestRepository;
import com.xisc.pm.infra.mapper.PmHotDestMapper;
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;

/**
 * 炼钢炉次计划热处理去向表(PmTpssmHot)资源库
 *
 * @author 纪文桃 wentao.ji01@hand-china.com
 * @since 2024-08-19 14:48:29
 */
@Component
public class PmHotDestRepositoryImpl extends BaseRepositoryImpl<PmHotDest> implements PmHotDestRepository {
    @Resource
    private PmHotDestMapper pmHotDestMapper;

    @Override
    public List<PmHotDest> selectList(PmHotDest pmTpssmHot) {
        return pmHotDestMapper.selectList(pmTpssmHot);
    }

    @Override
    public PmHotDest selectByPrimary(Long id) {
        PmHotDest pmHotDest = new PmHotDest();
        pmHotDest.setId(id);
        List<PmHotDest> pmTpssmHots = pmHotDestMapper.selectList(pmHotDest);
        if (CollectionUtils.isEmpty(pmTpssmHots)) {
            return null;
        }
        return pmTpssmHots.get(0);
    }

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