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

import com.xisc.pm.app.service.PmCmdContService;
import com.xisc.pm.domain.entity.PmCmdCont;
import com.xisc.pm.domain.repository.PmCmdContRepository;
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;

/**
 * 命令参数表(PmCmdCont)应用服务
 *
 * @author 纪文桃 wentao.ji01@hand-china.com
 * @since 2024-08-01 10:25:08
 */
@Service
public class PmCmdContServiceImpl implements PmCmdContService {

    private PmCmdContRepository pmCmdContRepository;

    public PmCmdContServiceImpl(PmCmdContRepository pmCmdContRepository) {
        this.pmCmdContRepository = pmCmdContRepository;
    }

    @Override
    public Page<PmCmdCont> selectList(PageRequest pageRequest, PmCmdCont pmCmdCont) {
        return PageHelper.doPage(pageRequest, () -> pmCmdContRepository.selectList(pmCmdCont));
    }

    @Override
    public void saveData(List<PmCmdCont> pmCmdConts) {
        List<PmCmdCont> insertList = pmCmdConts.stream().filter(line -> line.getPmCmdContId() == null).collect(Collectors.toList());
        List<PmCmdCont> updateList = pmCmdConts.stream().filter(line -> line.getPmCmdContId() != null).collect(Collectors.toList());
        pmCmdContRepository.batchInsertSelective(insertList);
        pmCmdContRepository.batchUpdateByPrimaryKeySelective(updateList);
    }
}

