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

import com.xisc.pm.app.service.PmThickAddvBtTraService;
import com.xisc.pm.domain.entity.PmThickAddvBtTra;
import com.xisc.pm.domain.repository.PmThickAddvBtTraRepository;
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;

/**
 * 钢板厚度余量基准表履历表(PmThickAddvBtTra)应用服务
 *
 * @author 蒋雨航 yuhang.jiang02@hand-china.com
 * @since 2024-09-06 08:41:57
 */
@Service
public class PmThickAddvBtTraServiceImpl implements PmThickAddvBtTraService {
    @Autowired
    private PmThickAddvBtTraRepository pmThickAddvBtTraRepository;

    @Override
    public Page<PmThickAddvBtTra> selectList(PageRequest pageRequest, PmThickAddvBtTra pmThickAddvBtTra) {
        return PageHelper.doPageAndSort(pageRequest, () -> pmThickAddvBtTraRepository.selectList(pmThickAddvBtTra));
    }

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

