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.PmSlabMergeService;
import org.springframework.stereotype.Service;
import com.xisc.pm.domain.entity.PmSlabMerge;
import com.xisc.pm.domain.repository.PmSlabMergeRepository;

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

/**
 * 组炉板坯合并表(PmSlabMerge)应用服务
 *
 * @author 纪文桃 wentao.ji01@hand-china.com
 * @since 2024-09-04 15:13:40
 */
@Service
public class PmSlabMergeServiceImpl implements PmSlabMergeService {
    @Autowired
    private PmSlabMergeRepository pmSlabMergeRepository;

    @Override
    public Page<PmSlabMerge> selectList(PageRequest pageRequest, PmSlabMerge pmSlabMerge) {
        return PageHelper.doPageAndSort(pageRequest, () -> pmSlabMergeRepository.selectList(pmSlabMerge));
    }

    @Override
    public void saveData(List<PmSlabMerge> pmSlabMerges) {
        List<PmSlabMerge> insertList = pmSlabMerges.stream().filter(line -> line.getId() == null).collect(Collectors.toList());
        List<PmSlabMerge> updateList = pmSlabMerges.stream().filter(line -> line.getId() != null).collect(Collectors.toList());
        pmSlabMergeRepository.batchInsertSelective(insertList);
        pmSlabMergeRepository.batchUpdateByPrimaryKeySelective(updateList);
    }
}

