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.PmMidSlabAddvBtTraService;
import org.springframework.stereotype.Service;
import com.xisc.pm.domain.entity.PmMidSlabAddvBtTra;
import com.xisc.pm.domain.repository.PmMidSlabAddvBtTraRepository;

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

/**
 * 中间坯加量基准表-履历表(PmMidSlabAddvBtTra)应用服务
 *
 * @author 纪文桃 wentao.ji01@hand-china.com
 * @since 2024-09-18 18:31:44
 */
@Service
public class PmMidSlabAddvBtTraServiceImpl implements PmMidSlabAddvBtTraService {
    @Autowired
    private PmMidSlabAddvBtTraRepository pmMidSlabAddvBtTraRepository;

    @Override
    public Page<PmMidSlabAddvBtTra> selectList(PageRequest pageRequest, PmMidSlabAddvBtTra pmMidSlabAddvBtTra) {
        return PageHelper.doPageAndSort(pageRequest, () -> pmMidSlabAddvBtTraRepository.selectList(pmMidSlabAddvBtTra));
    }

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

