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

import java.util.List;
import java.util.Set;

import org.hzero.mybatis.base.impl.BaseRepositoryImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.google.common.collect.Sets;
import com.xisc.pm.domain.entity.MmHtmrslt;
import com.xisc.pm.domain.repository.MmHtmrsltRepository;
import com.xisc.pm.infra.mapper.MmHtmrsltMapper;

/**
 * 热处理实绩表 资源库实现
 *
 * @author 曾俊 jun.zeng@hand-china.com 2024-08-27 13:39:27
 */
@Component
public class MmHtmrsltRepositoryImpl extends BaseRepositoryImpl<MmHtmrslt> implements MmHtmrsltRepository {
    
    @Autowired
    private MmHtmrsltMapper mmHtmrsltMapper;

    @Override
    public Set<String> getHotTreatMethodByMatNo(String matNo, Long tenantId) {
        List<String> mmHtmrslts = mmHtmrsltMapper.getHotTreatMethodByMatNo(matNo, tenantId);
        if (mmHtmrslts != null && !mmHtmrslts.isEmpty()) {
            return Sets.newHashSet(mmHtmrslts);
        }
        if (matNo == null || matNo.length() < 8) {
            return Sets.newHashSet("0");
        }
        // 从第二位开始截取7个字符
        String defaultMatNo = matNo.substring(1, Math.min(matNo.length(), 8)) + "000";
        mmHtmrslts = mmHtmrsltMapper.getHotTreatMethodByMatNo(defaultMatNo, tenantId);
        if (mmHtmrslts != null && !mmHtmrslts.isEmpty()) {
            // 获取最大的实绩记录表
            return Sets.newHashSet(mmHtmrslts);
        }
        return Sets.newHashSet("0");
    }

}
