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.PmPlateCutLenBtTraService;
import org.springframework.stereotype.Service;
import com.xisc.pm.domain.entity.PmPlateCutLenBtTra;
import com.xisc.pm.domain.repository.PmPlateCutLenBtTraRepository;

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

/**
 * 钢板切缝切头尾范围基准表履历表(PmPlateCutLenBtTra)应用服务
 *
 * @author 纪文桃 wentao.ji01@hand-china.com
 * @since 2024-07-24 09:27:03
 */
@Service
public class PmPlateCutLenBtTraServiceImpl implements PmPlateCutLenBtTraService {
    @Autowired
    private PmPlateCutLenBtTraRepository pmPlateCutLenBtTraRepository;

    @Override
    public Page<PmPlateCutLenBtTra> selectList(PageRequest pageRequest, PmPlateCutLenBtTra pmPlateCutLenBtTra) {
        return PageHelper.doPageAndSort(pageRequest, () -> pmPlateCutLenBtTraRepository.selectList(pmPlateCutLenBtTra));
    }

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

