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.PmSdivSpecLimitBtTraService;
import org.springframework.stereotype.Service;
import com.xisc.pm.domain.entity.PmSdivSpecLimitBtTra;
import com.xisc.pm.domain.repository.PmSdivSpecLimitBtTraRepository;

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

/**
 * 剖分组板设备规格限制表履历表(PmSdivSpecLimitBtTra)应用服务
 *
 * @author 纪文桃 wentao.ji01@hand-china.com
 * @since 2024-07-25 08:34:36
 */
@Service
public class PmSdivSpecLimitBtTraServiceImpl implements PmSdivSpecLimitBtTraService {
    @Autowired
    private PmSdivSpecLimitBtTraRepository pmSdivSpecLimitBtTraRepository;

    @Override
    public Page<PmSdivSpecLimitBtTra> selectList(PageRequest pageRequest, PmSdivSpecLimitBtTra pmSdivSpecLimitBtTra) {
        return PageHelper.doPageAndSort(pageRequest, () -> pmSdivSpecLimitBtTraRepository.selectList(pmSdivSpecLimitBtTra));
    }

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

