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

import com.xisc.pm.app.service.PmHotConfigTraService;
import com.xisc.pm.domain.entity.PmHotConfigTra;
import com.xisc.pm.domain.repository.PmHotConfigTraRepository;
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;

/**
 * 组炉默认热处理去向配置表履历表(PmHotConfigTra)应用服务
 *
 * @author 纪文桃 wentao.ji01@hand-china.com
 * @since 2024-07-25 10:19:24
 */
@Service
public class PmHotConfigTraServiceImpl implements PmHotConfigTraService {
    @Autowired
    private PmHotConfigTraRepository pmHotConfigTraRepository;

    @Override
    public Page<PmHotConfigTra> selectList(PageRequest pageRequest, PmHotConfigTra pmHotConfigTra) {
        return PageHelper.doPageAndSort(pageRequest, () -> pmHotConfigTraRepository.selectList(pmHotConfigTra));
    }

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

