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

import com.xisc.pm.app.service.PmCmdSmallPltService;
import com.xisc.pm.domain.entity.PmCmdSmallPlt;
import com.xisc.pm.domain.repository.PmCmdSmallPltRepository;
import io.choerodon.core.domain.Page;
import io.choerodon.mybatis.pagehelper.PageHelper;
import io.choerodon.mybatis.pagehelper.domain.PageRequest;
import org.springframework.stereotype.Service;

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

/**
 * 命令小板表(PmCmdSmallPlt)应用服务
 *
 * @author 纪文桃 wentao.ji01@hand-china.com
 * @since 2024-08-01 10:25:35
 */
@Service
public class PmCmdSmallPltServiceImpl implements PmCmdSmallPltService {

    private PmCmdSmallPltRepository pmCmdSmallPltRepository;

    public PmCmdSmallPltServiceImpl(PmCmdSmallPltRepository pmCmdSmallPltRepository) {
        this.pmCmdSmallPltRepository = pmCmdSmallPltRepository;
    }

    @Override
    public Page<PmCmdSmallPlt> selectList(PageRequest pageRequest, PmCmdSmallPlt pmCmdSmallPlt) {
        return PageHelper.doPage(pageRequest, () -> pmCmdSmallPltRepository.selectList(pmCmdSmallPlt));
    }

    @Override
    public void saveData(List<PmCmdSmallPlt> pmCmdSmallPlts) {
        List<PmCmdSmallPlt> insertList = pmCmdSmallPlts.stream().filter(line -> line.getPmCmdSmallPltId() == null).collect(Collectors.toList());
        List<PmCmdSmallPlt> updateList = pmCmdSmallPlts.stream().filter(line -> line.getPmCmdSmallPltId() != null).collect(Collectors.toList());
        pmCmdSmallPltRepository.batchInsertSelective(insertList);
        pmCmdSmallPltRepository.batchUpdateByPrimaryKeySelective(updateList);
    }
}

