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 com.xisc.pm.app.service.PmHotDestTraService;
import org.springframework.stereotype.Service;
import com.xisc.pm.domain.entity.PmHotDestTra;
import com.xisc.pm.domain.repository.PmHotDestTraRepository;

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

/**
 * 修改炼钢炉次计划热处理去向履历表(PmTpssmHotLog)应用服务
 *
 * @author 纪文桃 wentao.ji01@hand-china.com
 * @since 2024-08-19 15:14:00
 */
@Service
public class PmHotDestTraServiceImpl implements PmHotDestTraService {

    private PmHotDestTraRepository pmHotDestTraRepository;

    public PmHotDestTraServiceImpl(PmHotDestTraRepository pmHotDestTraRepository) {
        this.pmHotDestTraRepository = pmHotDestTraRepository;
    }

    @Override
    public Page<PmHotDestTra> selectList(PageRequest pageRequest, PmHotDestTra pmTpssmHotLog) {
        return PageHelper.doPageAndSort(pageRequest, () -> pmHotDestTraRepository.selectList(pmTpssmHotLog));
    }

    @Override
    public void saveData(List<PmHotDestTra> pmTpssmHotLogs) {
        List<PmHotDestTra> insertList = pmTpssmHotLogs.stream().filter(line -> line.getId() == null).collect(Collectors.toList());
        List<PmHotDestTra> updateList = pmTpssmHotLogs.stream().filter(line -> line.getId() != null).collect(Collectors.toList());
        pmHotDestTraRepository.batchInsertSelective(insertList);
        pmHotDestTraRepository.batchUpdateByPrimaryKeySelective(updateList);
    }
}

