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.PmIngotYieldBtTraService;
import org.springframework.stereotype.Service;
import com.xisc.pm.domain.entity.PmIngotYieldBtTra;
import com.xisc.pm.domain.repository.PmIngotYieldBtTraRepository;

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

/**
 * 钢锭收得率基准表履历表(PmIngotYieldBtTra)应用服务
 *
 * @author 纪文桃 wentao.ji01@hand-china.com
 * @since 2024-09-05 18:23:43
 */
@Service
public class PmIngotYieldBtTraServiceImpl implements PmIngotYieldBtTraService {
    @Autowired
    private PmIngotYieldBtTraRepository pmIngotYieldBtTraRepository;

    @Override
    public Page<PmIngotYieldBtTra> selectList(PageRequest pageRequest, PmIngotYieldBtTra pmIngotYieldBtTra) {
        return PageHelper.doPageAndSort(pageRequest, () -> pmIngotYieldBtTraRepository.selectList(pmIngotYieldBtTra));
    }

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

