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

import com.xisc.pm.app.service.PmSlabPoolInHisService;
import com.xisc.pm.domain.entity.PmSlabPoolInHis;
import com.xisc.pm.domain.repository.PmSlabPoolInHisRepository;
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;

/**
 * 组炉收池历史表(PmSlabPoolInHis)应用服务
 *
 * @author 纪文桃 wentao.ji01@hand-china.com
 * @since 2025-01-03 14:12:23
 */
@Service
public class PmSlabPoolInHisServiceImpl implements PmSlabPoolInHisService {
    @Autowired
    private PmSlabPoolInHisRepository pmSlabPoolInHisRepository;

    @Override
    public Page<PmSlabPoolInHis> selectList(PageRequest pageRequest, PmSlabPoolInHis pmSlabPoolInHis) {
        return PageHelper.doPageAndSort(pageRequest, () -> pmSlabPoolInHisRepository.selectList(pmSlabPoolInHis));
    }

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

