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

import com.xisc.pm.app.service.PmHtolStaticTraService;
import com.xisc.pm.domain.entity.PmHtolStaticTra;
import com.xisc.pm.domain.repository.PmHtolStaticTraRepository;
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 org.springframework.stereotype.Service;

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

/**
 * 以优充次静态表履历表(PmHtolStaticTra)应用服务
 *
 * @author 纪文桃 wentao.ji01@hand-china.com
 * @since 2024-07-25 10:07:54
 */
@Service
public class PmHtolStaticTraServiceImpl implements PmHtolStaticTraService {
    @Autowired
    private PmHtolStaticTraRepository pmHtolStaticTraRepository;

    @Override
    public Page<PmHtolStaticTra> selectList(PageRequest pageRequest, PmHtolStaticTra pmHtolStaticTra) {
        return PageHelper.doPageAndSort(pageRequest, () -> pmHtolStaticTraRepository.selectList(pmHtolStaticTra));
    }

    @Override
    public void saveData(List<PmHtolStaticTra> pmHtolStaticTras) {
        List<PmHtolStaticTra> insertList = pmHtolStaticTras.stream().filter(line -> line.getTraId() == null).collect(Collectors.toList());
        List<PmHtolStaticTra> updateList = pmHtolStaticTras.stream().filter(line -> line.getTraId() != null).collect(Collectors.toList());
        pmHtolStaticTraRepository.batchInsertSelective(insertList);
        pmHtolStaticTraRepository.batchUpdateByPrimaryKeySelective(updateList);
    }
}

