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

import com.xisc.pm.app.service.PmSlabSpecBtTraService;
import com.xisc.pm.domain.entity.PmSlabSpecBtTra;
import com.xisc.pm.domain.repository.PmSlabSpecBtTraRepository;
import io.choerodon.core.domain.Page;
import io.choerodon.mybatis.pagehelper.PageHelper;
import io.choerodon.mybatis.pagehelper.domain.PageRequest;
import org.springframework.stereotype.Service;

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

/**
 * 连铸板坯生产规格基准表-履历表(PmSlabSpecBtTra)应用服务
 *
 * @author 纪文桃 wentao.ji01@hand-china.com
 * @since 2024-07-23 08:26:13
 */
@Service
public class PmSlabSpecBtTraServiceImpl implements PmSlabSpecBtTraService {

    private PmSlabSpecBtTraRepository pmSlabSpecBtTraRepository;

    public PmSlabSpecBtTraServiceImpl(PmSlabSpecBtTraRepository pmSlabSpecBtTraRepository) {
        this.pmSlabSpecBtTraRepository = pmSlabSpecBtTraRepository;
    }

    @Override
    public Page<PmSlabSpecBtTra> selectList(PageRequest pageRequest, PmSlabSpecBtTra pmSlabSpecBtTra) {
        return PageHelper.doPageAndSort(pageRequest, () -> pmSlabSpecBtTraRepository.selectList(pmSlabSpecBtTra));
    }

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

