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

import com.xisc.pm.app.service.PmSlabEstaPlanHisService;
import com.xisc.pm.domain.entity.PmSlabEstaPlanHis;
import com.xisc.pm.domain.repository.PmSlabEstaPlanHisRepository;
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;

/**
 * 组炉编制历史表(PmSlabEstaPlanHis)应用服务
 *
 * @author 纪文桃 wentao.ji01@hand-china.com
 * @since 2025-01-03 14:11:14
 */
@Service
public class PmSlabEstaPlanHisServiceImpl implements PmSlabEstaPlanHisService {
    @Autowired
    private PmSlabEstaPlanHisRepository pmSlabEstaPlanHisRepository;

    @Override
    public Page<PmSlabEstaPlanHis> selectList(PageRequest pageRequest, PmSlabEstaPlanHis pmSlabEstaPlanHis) {
        return PageHelper.doPageAndSort(pageRequest, () -> pmSlabEstaPlanHisRepository.selectList(pmSlabEstaPlanHis));
    }

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

