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.PmPonoWtStaticGdTraService;
import org.springframework.stereotype.Service;
import com.xisc.pm.domain.entity.PmPonoWtStaticGdTra;
import com.xisc.pm.domain.repository.PmPonoWtStaticGdTraRepository;

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

/**
 * 炉重静态表_钢锭履历表(PmPonoWtStaticGdTra)应用服务
 *
 * @author 纪文桃 wentao.ji01@hand-china.com
 * @since 2024-07-25 09:41:45
 */
@Service
public class PmPonoWtStaticGdTraServiceImpl implements PmPonoWtStaticGdTraService {
    @Autowired
    private PmPonoWtStaticGdTraRepository pmPonoWtStaticGdTraRepository;

    @Override
    public Page<PmPonoWtStaticGdTra> selectList(PageRequest pageRequest, PmPonoWtStaticGdTra pmPonoWtStaticGdTra) {
        return PageHelper.doPageAndSort(pageRequest, () -> pmPonoWtStaticGdTraRepository.selectList(pmPonoWtStaticGdTra));
    }

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

