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

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.commons.collections.CollectionUtils;
import org.hzero.mybatis.base.impl.BaseRepositoryImpl;
import org.springframework.stereotype.Component;

import com.xisc.pm.domain.entity.PmRuntimeContract;
import com.xisc.pm.domain.repository.PmRuntimeContractRepository;
import com.xisc.pm.infra.mapper.PmRuntimeContractMapper;

/**
 * 合同范围表(PmRuntimeContract)资源库
 *
 * @author 纪文桃 wentao.ji01@hand-china.com
 * @since 2024-10-11 09:35:44
 */
@Component
public class PmRuntimeContractRepositoryImpl extends BaseRepositoryImpl<PmRuntimeContract>
        implements PmRuntimeContractRepository {
    @Resource
    private PmRuntimeContractMapper pmRuntimeContractMapper;

    @Override
    public List<PmRuntimeContract> selectList(PmRuntimeContract pmRuntimeContract) {
        return pmRuntimeContractMapper.selectList(pmRuntimeContract);
    }

    @Override
    public PmRuntimeContract selectByPrimary(Long contractId) {
        PmRuntimeContract pmRuntimeContract = new PmRuntimeContract();
        pmRuntimeContract.setContractId(contractId);
        List<PmRuntimeContract> pmRuntimeContracts = pmRuntimeContractMapper.selectList(pmRuntimeContract);
        if (CollectionUtils.isEmpty(pmRuntimeContracts)) {
            return null;
        }
        return pmRuntimeContracts.get(0);
    }

    @Override
    public BigDecimal selectAllNumberByRemainingFlag(Long requestId, Long tenantId) {
        return pmRuntimeContractMapper.selectAllNumberByRemainingFlag(requestId, tenantId);
    }

    @Override
    public int deleteByRequestId(List<Long> requestIds) {
        return pmRuntimeContractMapper.deleteByRequestId(requestIds);
    }

    @Override
    public Map<String, PmRuntimeContract> selectWt(Long requestId, Long tenantId) {
        Map<String, PmRuntimeContract> result = new HashMap<String, PmRuntimeContract>();
        List<PmRuntimeContract> pmRuntimeContracts = pmRuntimeContractMapper.selectWt(requestId, tenantId);
        if(pmRuntimeContracts != null) {
            for (PmRuntimeContract pmRuntimeContract : pmRuntimeContracts) {
                result.put(pmRuntimeContract.getStNo(), pmRuntimeContract);
            }
        }
        return result;
    }
}
