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.PmMinThickTolBtTraService;
import org.springframework.stereotype.Service;
import com.xisc.pm.domain.entity.PmMinThickTolBtTra;
import com.xisc.pm.domain.repository.PmMinThickTolBtTraRepository;

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

/**
 * 最小轧制厚度公差范围基准表(PmMinThickTolBtTra)应用服务
 *
 * @author 纪文桃 wentao.ji01@hand-china.com
 * @since 2024-07-23 11:11:59
 */
@Service
public class PmMinThickTolBtTraServiceImpl implements PmMinThickTolBtTraService {
    @Autowired
    private PmMinThickTolBtTraRepository pmMinThickTolBtTraRepository;

    @Override
    public Page<PmMinThickTolBtTra> selectList(PageRequest pageRequest, PmMinThickTolBtTra pmMinThickTolBtTra) {
        return PageHelper.doPageAndSort(pageRequest, () -> pmMinThickTolBtTraRepository.selectList(pmMinThickTolBtTra));
    }

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

