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.PmPlateSpecYieldBtTraService;
import org.springframework.stereotype.Service;
import com.xisc.pm.domain.entity.PmPlateSpecYieldBtTra;
import com.xisc.pm.domain.repository.PmPlateSpecYieldBtTraRepository;

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

/**
 * 钢板轧制规格对应收得率基准表履历表(PmPlateSpecYieldBtTra)应用服务
 *
 * @author 纪文桃 wentao.ji01@hand-china.com
 * @since 2024-07-23 16:38:55
 */
@Service
public class PmPlateSpecYieldBtTraServiceImpl implements PmPlateSpecYieldBtTraService {
    @Autowired
    private PmPlateSpecYieldBtTraRepository pmPlateSpecYieldBtTraRepository;

    @Override
    public Page<PmPlateSpecYieldBtTra> selectList(PageRequest pageRequest, PmPlateSpecYieldBtTra pmPlateSpecYieldBtTra) {
        return PageHelper.doPageAndSort(pageRequest, () -> pmPlateSpecYieldBtTraRepository.selectList(pmPlateSpecYieldBtTra));
    }

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

