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.PmPdTmpYieldBtTraService;
import org.springframework.stereotype.Service;
import com.xisc.pm.domain.entity.PmPdTmpYieldBtTra;
import com.xisc.pm.domain.repository.PmPdTmpYieldBtTraRepository;

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

/**
 * 组板临时收得率基准表履历表(PmPdTmpYieldBtTra)应用服务
 *
 * @author 纪文桃 wentao.ji01@hand-china.com
 * @since 2024-07-24 10:10:18
 */
@Service
public class PmPdTmpYieldBtTraServiceImpl implements PmPdTmpYieldBtTraService {
    @Autowired
    private PmPdTmpYieldBtTraRepository pmPdTmpYieldBtTraRepository;

    @Override
    public Page<PmPdTmpYieldBtTra> selectList(PageRequest pageRequest, PmPdTmpYieldBtTra pmPdTmpYieldBtTra) {
        return PageHelper.doPageAndSort(pageRequest, () -> pmPdTmpYieldBtTraRepository.selectList(pmPdTmpYieldBtTra));
    }

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

