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.PmPonoWtStaticTraService;
import org.springframework.stereotype.Service;
import com.xisc.pm.domain.entity.PmPonoWtStaticTra;
import com.xisc.pm.domain.repository.PmPonoWtStaticTraRepository;

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

/**
 * 炉重静态表履历表(PmPonoWtStaticTra)应用服务
 *
 * @author 纪文桃 wentao.ji01@hand-china.com
 * @since 2024-07-25 09:12:31
 */
@Service
public class PmPonoWtStaticTraServiceImpl implements PmPonoWtStaticTraService {
    @Autowired
    private PmPonoWtStaticTraRepository pmPonoWtStaticTraRepository;

    @Override
    public Page<PmPonoWtStaticTra> selectList(PageRequest pageRequest, PmPonoWtStaticTra pmPonoWtStaticTra) {
        return PageHelper.doPageAndSort(pageRequest, () -> pmPonoWtStaticTraRepository.selectList(pmPonoWtStaticTra));
    }

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

