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.PmSlabScrapLenBtTraService;
import org.springframework.stereotype.Service;
import com.xisc.pm.domain.entity.PmSlabScrapLenBtTra;
import com.xisc.pm.domain.repository.PmSlabScrapLenBtTraRepository;

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

/**
 * 余坯组板采用判定基准表履历表(PmSlabScrapLenBtTra)应用服务
 *
 * @author 纪文桃 wentao.ji01@hand-china.com
 * @since 2024-07-23 14:28:57
 */
@Service
public class PmSlabScrapLenBtTraServiceImpl implements PmSlabScrapLenBtTraService {
    @Autowired
    private PmSlabScrapLenBtTraRepository pmSlabScrapLenBtTraRepository;

    @Override
    public Page<PmSlabScrapLenBtTra> selectList(PageRequest pageRequest, PmSlabScrapLenBtTra pmSlabScrapLenBtTra) {
        return PageHelper.doPageAndSort(pageRequest, () -> pmSlabScrapLenBtTraRepository.selectList(pmSlabScrapLenBtTra));
    }

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

