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

import com.xisc.pm.app.service.PmHotDestService;
import com.xisc.pm.domain.entity.PmHotDest;
import com.xisc.pm.domain.repository.PmHotDestRepository;
import io.choerodon.core.domain.Page;
import io.choerodon.mybatis.pagehelper.PageHelper;
import io.choerodon.mybatis.pagehelper.domain.PageRequest;
import org.springframework.stereotype.Service;

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

/**
 * 炼钢炉次计划热处理去向表(PmTpssmHot)应用服务
 *
 * @author 纪文桃 wentao.ji01@hand-china.com
 * @since 2024-08-19 14:48:30
 */
@Service
public class PmHotDestServiceImpl implements PmHotDestService {

    private PmHotDestRepository pmHotDestRepository;

    public PmHotDestServiceImpl(PmHotDestRepository pmHotDestRepository) {
        this.pmHotDestRepository = pmHotDestRepository;
    }

    @Override
    public Page<PmHotDest> selectList(PageRequest pageRequest, PmHotDest pmTpssmHot) {
        return PageHelper.doPageAndSort(pageRequest, () -> pmHotDestRepository.selectList(pmTpssmHot));
    }

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

