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.PmIngotSpecTrimBtTraService;
import org.springframework.stereotype.Service;
import com.xisc.pm.domain.entity.PmIngotSpecTrimBtTra;
import com.xisc.pm.domain.repository.PmIngotSpecTrimBtTraRepository;

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

/**
 * 钢锭轧制规格及切边量基准表履历表(PmIgnotSpecTrimBtTra)应用服务
 *
 * @author 纪文桃 wentao.ji01@hand-china.com
 * @since 2024-07-24 15:02:15
 */
@Service
public class PmIngotSpecTrimBtTraServiceImpl implements PmIngotSpecTrimBtTraService {
    @Autowired
    private PmIngotSpecTrimBtTraRepository pmIngotSpecTrimBtTraRepository;

    @Override
    public Page<PmIngotSpecTrimBtTra> selectList(PageRequest pageRequest, PmIngotSpecTrimBtTra pmIngotSpecTrimBtTra) {
        return PageHelper.doPageAndSort(pageRequest, () -> pmIngotSpecTrimBtTraRepository.selectList(pmIngotSpecTrimBtTra));
    }

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

