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.PmPlateTrimBtTraService;
import org.springframework.stereotype.Service;
import com.xisc.pm.domain.entity.PmPlateTrimBtTra;
import com.xisc.pm.domain.repository.PmPlateTrimBtTraRepository;

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

/**
 * 钢板切边量基准表履历表(PmPlateTrimBtTra)应用服务
 *
 * @author 纪文桃 wentao.ji01@hand-china.com
 * @since 2024-07-24 10:38:01
 */
@Service
public class PmPlateTrimBtTraServiceImpl implements PmPlateTrimBtTraService {
    @Autowired
    private PmPlateTrimBtTraRepository pmPlateTrimBtTraRepository;

    @Override
    public Page<PmPlateTrimBtTra> selectList(PageRequest pageRequest, PmPlateTrimBtTra pmPlateTrimBtTra) {
        return PageHelper.doPageAndSort(pageRequest, () -> pmPlateTrimBtTraRepository.selectList(pmPlateTrimBtTra));
    }

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

