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

import com.xisc.pm.app.service.PmIngotThickAddvBtTraService;
import com.xisc.pm.domain.entity.PmIngotThickAddvBtTra;
import com.xisc.pm.domain.repository.PmIngotThickAddvBtTraRepository;
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;

/**
 * 钢锭厚度余量基准表履历表(PmIgnotThickAddvBtTra)应用服务
 *
 * @author 纪文桃 wentao.ji01@hand-china.com
 * @since 2024-07-24 15:35:35
 */
@Service
public class PmIngotThickAddvBtTraServiceImpl implements PmIngotThickAddvBtTraService {

    private PmIngotThickAddvBtTraRepository pmIngotThickAddvBtTraRepository;

    public PmIngotThickAddvBtTraServiceImpl(PmIngotThickAddvBtTraRepository pmIngotThickAddvBtTraRepository) {
        this.pmIngotThickAddvBtTraRepository = pmIngotThickAddvBtTraRepository;
    }

    @Override
    public Page<PmIngotThickAddvBtTra> selectList(PageRequest pageRequest, PmIngotThickAddvBtTra pmIngotThickAddvBtTra) {
        return PageHelper.doPageAndSort(pageRequest, () -> pmIngotThickAddvBtTraRepository.selectList(pmIngotThickAddvBtTra));
    }

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

