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.PmSubCheckChmService;
import org.springframework.stereotype.Service;
import com.xisc.pm.domain.entity.PmSubCheckChm;
import com.xisc.pm.domain.repository.PmSubCheckChmRepository;

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

/**
 * 化学成分检测结果表(PmSubCheckChm)应用服务
 *
 * @author BKGY
 * @since 2025-03-26 16:22:53
 */
@Service
public class PmSubCheckChmServiceImpl implements PmSubCheckChmService {
    @Autowired
    private PmSubCheckChmRepository pmSubCheckChmRepository;

    @Override
    public Page<PmSubCheckChm> selectList(PageRequest pageRequest, PmSubCheckChm pmSubCheckChm) {
        return PageHelper.doPageAndSort(pageRequest, () -> pmSubCheckChmRepository.selectList(pmSubCheckChm));
    }

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

