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.PmPnsortTraService;
import org.springframework.stereotype.Service;
import com.xisc.pm.domain.entity.PmPnsortTra;
import com.xisc.pm.domain.repository.PmPnsortTraRepository;

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

/**
 * 组炉规则配置表-履历表(PmPnsortTra)应用服务
 *
 * @author 纪文桃 wentao.ji01@hand-china.com
 * @since 2024-09-11 16:00:12
 */
@Service
public class PmPnsortTraServiceImpl implements PmPnsortTraService {
    @Autowired
    private PmPnsortTraRepository pmPnsortTraRepository;

    @Override
    public Page<PmPnsortTra> selectList(PageRequest pageRequest, PmPnsortTra pmPnsortTra) {
        return PageHelper.doPageAndSort(pageRequest, () -> pmPnsortTraRepository.selectList(pmPnsortTra));
    }

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

