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.PmSteelCastLotService;
import org.springframework.stereotype.Service;
import com.xisc.pm.domain.entity.PmSteelCastLot;
import com.xisc.pm.domain.repository.PmSteelCastLotRepository;

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

/**
 * 炼钢连铸制造命令LOT表(PmSteelCastLot)应用服务
 *
 * @author 纪文桃 wentao.ji01@hand-china.com
 * @since 2024-08-16 08:25:59
 */
@Service
public class PmSteelCastLotServiceImpl implements PmSteelCastLotService {

    private PmSteelCastLotRepository pmSteelCastLotRepository;

    public PmSteelCastLotServiceImpl(PmSteelCastLotRepository pmSteelCastLotRepository) {
        this.pmSteelCastLotRepository = pmSteelCastLotRepository;
    }

    @Override
    public Page<PmSteelCastLot> selectList(PageRequest pageRequest, PmSteelCastLot pmSteelCastLot) {
        return PageHelper.doPageAndSort(pageRequest, () -> pmSteelCastLotRepository.selectList(pmSteelCastLot));
    }

    @Override
    public void saveData(List<PmSteelCastLot> pmSteelCastLots) {
        List<PmSteelCastLot> insertList = pmSteelCastLots.stream().filter(line -> line.getSteelCastLotId() == null).collect(Collectors.toList());
        List<PmSteelCastLot> updateList = pmSteelCastLots.stream().filter(line -> line.getSteelCastLotId() != null).collect(Collectors.toList());
        pmSteelCastLotRepository.batchInsertSelective(insertList);
        pmSteelCastLotRepository.batchUpdateByPrimaryKeySelective(updateList);
    }
}

