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

import com.xisc.pm.app.service.PmIngotCutLenBtTraService;
import com.xisc.pm.domain.entity.PmIngotCutLenBtTra;
import com.xisc.pm.domain.repository.PmIngotCutLenBtTraRepository;
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;

/**
 * 钢锭切缝量基准表履历表(PmIgnotCutLenBtTra)应用服务
 *
 * @author 纪文桃 wentao.ji01@hand-china.com
 * @since 2024-07-24 15:55:25
 */
@Service
public class PmIngotCutLenBtTraServiceImpl implements PmIngotCutLenBtTraService {

    private PmIngotCutLenBtTraRepository pmIngotCutLenBtTraRepository;

    public PmIngotCutLenBtTraServiceImpl(PmIngotCutLenBtTraRepository pmIngotCutLenBtTraRepository) {
        this.pmIngotCutLenBtTraRepository = pmIngotCutLenBtTraRepository;
    }

    @Override
    public Page<PmIngotCutLenBtTra> selectList(PageRequest pageRequest, PmIngotCutLenBtTra pmIngotCutLenBtTra) {
        return PageHelper.doPageAndSort(pageRequest, () -> pmIngotCutLenBtTraRepository.selectList(pmIngotCutLenBtTra));
    }

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

