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.PmPdConstBtTraService;
import org.springframework.stereotype.Service;
import com.xisc.pm.domain.entity.PmPdConstBtTra;
import com.xisc.pm.domain.repository.PmPdConstBtTraRepository;

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

/**
 * 组板常数基准表履历表(PmPdConstBtTra)应用服务
 *
 * @author 纪文桃 wentao.ji01@hand-china.com
 * @since 2024-07-24 09:08:43
 */
@Service
public class PmPdConstBtTraServiceImpl implements PmPdConstBtTraService {
    @Autowired
    private PmPdConstBtTraRepository pmPdConstBtTraRepository;

    @Override
    public Page<PmPdConstBtTra> selectList(PageRequest pageRequest, PmPdConstBtTra pmPdConstBtTra) {
        return PageHelper.doPageAndSort(pageRequest, () -> pmPdConstBtTraRepository.selectList(pmPdConstBtTra));
    }

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

