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

import com.xisc.pm.api.dto.export.PmSgDetermineDTO;
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.PmSgDetermineService;
import org.springframework.stereotype.Service;
import com.xisc.pm.domain.entity.PmSgDetermine;
import com.xisc.pm.domain.repository.PmSgDetermineRepository;

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

/**
 * 钢种改判表(PmSgDetermine)应用服务
 *
 * @author BKGY
 * @since 2025-01-17 14:25:16
 */
@Service
public class PmSgDetermineServiceImpl implements PmSgDetermineService {
    @Autowired
    private PmSgDetermineRepository pmSgDetermineRepository;

    @Override
    public Page<PmSgDetermine> selectList(PageRequest pageRequest, PmSgDetermine pmSgDetermine) {
        return PageHelper.doPageAndSort(pageRequest, () -> pmSgDetermineRepository.selectList(pmSgDetermine));
    }

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

    @Override
    public List<PmSgDetermineDTO> exportList(PmSgDetermine pmSgDetermine) {
        return pmSgDetermineRepository.exportList(pmSgDetermine);
    }
}

