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.PmIngotTypeBtTraService;
import org.springframework.stereotype.Service;
import com.xisc.pm.domain.entity.PmIngotTypeBtTra;
import com.xisc.pm.domain.repository.PmIngotTypeBtTraRepository;

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

/**
 * 锭坯型基表履历表(PmIngotTypeBtTra)应用服务
 *
 * @author 纪文桃 wentao.ji01@hand-china.com
 * @since 2024-07-29 14:54:30
 */
@Service
public class PmIngotTypeBtTraServiceImpl implements PmIngotTypeBtTraService {
    @Autowired
    private PmIngotTypeBtTraRepository pmIngotTypeBtTraRepository;

    @Override
    public Page<PmIngotTypeBtTra> selectList(PageRequest pageRequest, PmIngotTypeBtTra pmIngotTypeBtTra) {
        return PageHelper.doPageAndSort(pageRequest, () -> pmIngotTypeBtTraRepository.selectList(pmIngotTypeBtTra));
    }

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

