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

import com.xisc.pm.app.service.PmCutPlaceBtTraService;
import com.xisc.pm.domain.entity.PmCutPlaceBtTra;
import com.xisc.pm.domain.repository.PmCutPlaceBtTraRepository;
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;

/**
 * 粗切位置决定基准表履历表(PmCutPlaceBtTra)应用服务
 *
 * @author 纪文桃 wentao.ji01@hand-china.com
 * @since 2024-07-24 08:41:00
 */
@Service
public class PmCutPlaceBtTraServiceImpl implements PmCutPlaceBtTraService {

    private final PmCutPlaceBtTraRepository pmCutPlaceBtTraRepository;

    public PmCutPlaceBtTraServiceImpl(PmCutPlaceBtTraRepository pmCutPlaceBtTraRepository) {
        this.pmCutPlaceBtTraRepository = pmCutPlaceBtTraRepository;
    }

    @Override
    public Page<PmCutPlaceBtTra> selectList(PageRequest pageRequest, PmCutPlaceBtTra pmCutPlaceBtTra) {
        return PageHelper.doPageAndSort(pageRequest, () -> pmCutPlaceBtTraRepository.selectList(pmCutPlaceBtTra));
    }

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

