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.PmSubCheckLowService;
import org.springframework.stereotype.Service;
import com.xisc.pm.domain.entity.PmSubCheckLow;
import com.xisc.pm.domain.repository.PmSubCheckLowRepository;

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

/**
 * 低倍检测结果表(PmSubCheckLow)应用服务
 *
 * @author BKGY
 * @since 2025-03-26 16:27:38
 */
@Service
public class PmSubCheckLowServiceImpl implements PmSubCheckLowService {
    @Autowired
    private PmSubCheckLowRepository pmSubCheckLowRepository;

    @Override
    public Page<PmSubCheckLow> selectList(PageRequest pageRequest, PmSubCheckLow pmSubCheckLow) {
        return PageHelper.doPageAndSort(pageRequest, () -> pmSubCheckLowRepository.selectList(pmSubCheckLow));
    }

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

