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.PmWmWwBtTraService;
import org.springframework.stereotype.Service;
import com.xisc.pm.domain.entity.PmWmWwBtTra;
import com.xisc.pm.domain.repository.PmWmWwBtTraRepository;

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

/**
 * 厚板产线_命令余材长度基准表-履历表(PmWmWwBtTra)应用服务
 *
 * @author 纪文桃 wentao.ji01@hand-china.com
 * @since 2024-09-11 15:03:17
 */
@Service
public class PmWmWwBtTraServiceImpl implements PmWmWwBtTraService {
    @Autowired
    private PmWmWwBtTraRepository pmWmWwBtTraRepository;

    @Override
    public Page<PmWmWwBtTra> selectList(PageRequest pageRequest, PmWmWwBtTra pmWmWwBtTra) {
        return PageHelper.doPageAndSort(pageRequest, () -> pmWmWwBtTraRepository.selectList(pmWmWwBtTra));
    }

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

