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.PmSpeStAddvBtTraService;
import org.springframework.stereotype.Service;
import com.xisc.pm.domain.entity.PmSpeStAddvBtTra;
import com.xisc.pm.domain.repository.PmSpeStAddvBtTraRepository;

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

/**
 * 特殊钢种余量增加表履历表(PmSpeStAddvBtTra)应用服务
 *
 * @author 纪文桃 wentao.ji01@hand-china.com
 * @since 2024-07-25 08:50:36
 */
@Service
public class PmSpeStAddvBtTraServiceImpl implements PmSpeStAddvBtTraService {

    private PmSpeStAddvBtTraRepository pmSpeStAddvBtTraRepository;

    public PmSpeStAddvBtTraServiceImpl(PmSpeStAddvBtTraRepository pmSpeStAddvBtTraRepository) {
        this.pmSpeStAddvBtTraRepository = pmSpeStAddvBtTraRepository;
    }

    @Override
    public Page<PmSpeStAddvBtTra> selectList(PageRequest pageRequest, PmSpeStAddvBtTra pmSpeStAddvBtTra) {
        return PageHelper.doPageAndSort(pageRequest, () -> pmSpeStAddvBtTraRepository.selectList(pmSpeStAddvBtTra));
    }

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

