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.PmStCodeBtTraService;
import org.springframework.stereotype.Service;
import com.xisc.pm.domain.entity.PmStCodeBtTra;
import com.xisc.pm.domain.repository.PmStCodeBtTraRepository;

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

/**
 * 强度级别对照基准表履历表(PmStCodeBtTra)应用服务
 *
 * @author 纪文桃 wentao.ji01@hand-china.com
 * @since 2024-07-26 14:15:35
 */
@Service
public class PmStCodeBtTraServiceImpl implements PmStCodeBtTraService {
    @Autowired
    private PmStCodeBtTraRepository pmStCodeBtTraRepository;

    @Override
    public Page<PmStCodeBtTra> selectList(PageRequest pageRequest, PmStCodeBtTra pmStCodeBtTra) {
        return PageHelper.doPageAndSort(pageRequest, () -> pmStCodeBtTraRepository.selectList(pmStCodeBtTra));
    }

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

