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 org.springframework.beans.factory.annotation.Autowired;
import com.xisc.pm.app.service.PmSteelCastSlabService;
import org.springframework.stereotype.Service;
import com.xisc.pm.domain.entity.PmSteelCastSlab;
import com.xisc.pm.domain.repository.PmSteelCastSlabRepository;

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

/**
 * 炼钢连铸制造命令板坯表(PmSteelCastSlab)应用服务
 *
 * @author 纪文桃 wentao.ji01@hand-china.com
 * @since 2024-08-15 10:21:18
 */
@Service
public class PmSteelCastSlabServiceImpl implements PmSteelCastSlabService {

    private PmSteelCastSlabRepository pmSteelCastSlabRepository;

    public PmSteelCastSlabServiceImpl(PmSteelCastSlabRepository pmSteelCastSlabRepository) {
        this.pmSteelCastSlabRepository = pmSteelCastSlabRepository;
    }

    @Override
    public Page<PmSteelCastSlab> selectList(PageRequest pageRequest, PmSteelCastSlab pmSteelCastSlab) {
        return PageHelper.doPageAndSort(pageRequest, () -> pmSteelCastSlabRepository.selectList(pmSteelCastSlab));
    }

    @Override
    public void saveData(List<PmSteelCastSlab> pmSteelCastSlabs) {
        List<PmSteelCastSlab> insertList = pmSteelCastSlabs.stream().filter(line -> line.getSteelCastSlabId() == null).collect(Collectors.toList());
        List<PmSteelCastSlab> updateList = pmSteelCastSlabs.stream().filter(line -> line.getSteelCastSlabId() != null).collect(Collectors.toList());
        pmSteelCastSlabRepository.batchInsertSelective(insertList);
        pmSteelCastSlabRepository.batchUpdateByPrimaryKeySelective(updateList);
    }
}

