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

import com.xisc.pm.app.service.PmSlabLenConfigTraService;
import com.xisc.pm.domain.entity.PmSlabLenConfigTra;
import com.xisc.pm.domain.repository.PmSlabLenConfigTraRepository;
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 org.springframework.stereotype.Service;

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

/**
 * 板坯组矩长度配置表履历表(PmSlabLenConfigTra)应用服务
 *
 * @author 纪文桃 wentao.ji01@hand-china.com
 * @since 2024-07-25 10:30:36
 */
@Service
public class PmSlabLenConfigTraServiceImpl implements PmSlabLenConfigTraService {
    @Autowired
    private PmSlabLenConfigTraRepository pmSlabLenConfigTraRepository;

    @Override
    public Page<PmSlabLenConfigTra> selectList(PageRequest pageRequest, PmSlabLenConfigTra pmSlabLenConfigTra) {
        return PageHelper.doPageAndSort(pageRequest, () -> pmSlabLenConfigTraRepository.selectList(pmSlabLenConfigTra));
    }

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

