package com.xisc.pm.app.service.impl;

import com.xisc.pm.app.service.PmHeatTreatFurnaceBtTraService;
import com.xisc.pm.domain.entity.PmHeatTreatFurnaceBtTra;
import com.xisc.pm.domain.repository.PmHeatTreatFurnaceBtTraRepository;
import io.choerodon.core.domain.Page;
import io.choerodon.mybatis.pagehelper.PageHelper;
import io.choerodon.mybatis.pagehelper.domain.PageRequest;
import org.springframework.stereotype.Service;

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

/**
 * 热处理炉基准规格表履历表(PmHeatTreatFurnaceBtTra)应用服务
 *
 * @author 纪文桃 wentao.ji01@hand-china.com
 * @since 2024-07-24 12:25:00
 */
@Service
public class PmHeatTreatFurnaceBtTraServiceImpl implements PmHeatTreatFurnaceBtTraService {

    private PmHeatTreatFurnaceBtTraRepository pmHeatTreatFurnaceBtTraRepository;

    public PmHeatTreatFurnaceBtTraServiceImpl(PmHeatTreatFurnaceBtTraRepository pmHeatTreatFurnaceBtTraRepository) {
        this.pmHeatTreatFurnaceBtTraRepository = pmHeatTreatFurnaceBtTraRepository;
    }

    @Override
    public Page<PmHeatTreatFurnaceBtTra> selectList(PageRequest pageRequest, PmHeatTreatFurnaceBtTra pmHeatTreatFurnaceBtTra) {
        return PageHelper.doPageAndSort(pageRequest, () -> pmHeatTreatFurnaceBtTraRepository.selectList(pmHeatTreatFurnaceBtTra));
    }

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

