package com.xisc.pm.app.service.impl;

import io.choerodon.core.domain.Page;
import io.choerodon.mybatis.pagehelper.PageHelper;
import io.choerodon.mybatis.pagehelper.domain.PageRequest;
import org.springframework.beans.factory.annotation.Autowired;
import com.xisc.pm.app.service.PmSlabReplBtTraService;
import org.springframework.stereotype.Service;
import com.xisc.pm.domain.entity.PmSlabReplBtTra;
import com.xisc.pm.domain.repository.PmSlabReplBtTraRepository;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 余材组板内部钢种以优充次对照表履历表(PmSlabReplBtTra)应用服务
 *
 * @author 纪文桃 wentao.ji01@hand-china.com
 * @since 2024-07-24 11:30:49
 */
@Service
public class PmSlabReplBtTraServiceImpl implements PmSlabReplBtTraService {
    @Autowired
    private PmSlabReplBtTraRepository pmSlabReplBtTraRepository;

    @Override
    public Page<PmSlabReplBtTra> selectList(PageRequest pageRequest, PmSlabReplBtTra pmSlabReplBtTra) {
        return PageHelper.doPageAndSort(pageRequest, () -> pmSlabReplBtTraRepository.selectList(pmSlabReplBtTra));
    }

    @Override
    public void saveData(List<PmSlabReplBtTra> pmSlabReplBtTras) {
        List<PmSlabReplBtTra> insertList = pmSlabReplBtTras.stream().filter(line -> line.getTraId() == null).collect(Collectors.toList());
        List<PmSlabReplBtTra> updateList = pmSlabReplBtTras.stream().filter(line -> line.getTraId() != null).collect(Collectors.toList());
        pmSlabReplBtTraRepository.batchInsertSelective(insertList);
        pmSlabReplBtTraRepository.batchUpdateByPrimaryKeySelective(updateList);
    }
}

