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.PmSteelCastFlowService;
import org.springframework.stereotype.Service;
import com.xisc.pm.domain.entity.PmSteelCastFlow;
import com.xisc.pm.domain.repository.PmSteelCastFlowRepository;

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

/**
 * 炼钢连铸制造命令铸机流表(PmSteelCastFlow)应用服务
 *
 * @author 纪文桃 wentao.ji01@hand-china.com
 * @since 2024-08-15 11:11:19
 */
@Service
public class PmSteelCastFlowServiceImpl implements PmSteelCastFlowService {

    private PmSteelCastFlowRepository pmSteelCastFlowRepository;

    public PmSteelCastFlowServiceImpl(PmSteelCastFlowRepository pmSteelCastFlowRepository) {
        this.pmSteelCastFlowRepository = pmSteelCastFlowRepository;
    }

    @Override
    public Page<PmSteelCastFlow> selectList(PageRequest pageRequest, PmSteelCastFlow pmSteelCastFlow) {
        return PageHelper.doPageAndSort(pageRequest, () -> pmSteelCastFlowRepository.selectList(pmSteelCastFlow));
    }

    @Override
    public void saveData(List<PmSteelCastFlow> pmSteelCastFlows) {
        List<PmSteelCastFlow> insertList = pmSteelCastFlows.stream().filter(line -> line.getSteelCastFlowId() == null).collect(Collectors.toList());
        List<PmSteelCastFlow> updateList = pmSteelCastFlows.stream().filter(line -> line.getSteelCastFlowId() != null).collect(Collectors.toList());
        pmSteelCastFlowRepository.batchInsertSelective(insertList);
        pmSteelCastFlowRepository.batchUpdateByPrimaryKeySelective(updateList);
    }
}

