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

import com.xisc.pm.app.service.PmPonoWtInfoService;
import com.xisc.pm.domain.entity.PmPonoWtInfo;
import com.xisc.pm.domain.repository.PmPonoWtInfoRepository;
import io.choerodon.core.domain.Page;
import io.choerodon.mybatis.pagehelper.PageHelper;
import io.choerodon.mybatis.pagehelper.domain.PageRequest;
import org.springframework.stereotype.Service;

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

/**
 * 炉重信息表(PmPonoWtInfo)应用服务
 *
 * @author 纪文桃 wentao.ji01@hand-china.com
 * @since 2024-08-12 08:26:59
 */
@Service
public class PmPonoWtInfoServiceImpl implements PmPonoWtInfoService {

    private PmPonoWtInfoRepository pmPonoWtInfoRepository;

    public PmPonoWtInfoServiceImpl(PmPonoWtInfoRepository pmPonoWtInfoRepository) {
        this.pmPonoWtInfoRepository = pmPonoWtInfoRepository;
    }

    @Override
    public Page<PmPonoWtInfo> selectList(PageRequest pageRequest, PmPonoWtInfo pmPonoWtInfo) {
        return PageHelper.doPageAndSort(pageRequest, () -> pmPonoWtInfoRepository.selectList(pmPonoWtInfo));
    }

    @Override
    public void saveData(List<PmPonoWtInfo> pmPonoWtInfos) {
        List<PmPonoWtInfo> insertList = pmPonoWtInfos.stream().filter(line -> line.getPmPonoWtInfoId() == null).collect(Collectors.toList());
        List<PmPonoWtInfo> updateList = pmPonoWtInfos.stream().filter(line -> line.getPmPonoWtInfoId() != null).collect(Collectors.toList());
        pmPonoWtInfoRepository.batchInsertSelective(insertList);
        pmPonoWtInfoRepository.batchUpdateByPrimaryKeySelective(updateList);
    }
}

