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

import com.xisc.pm.api.dto.PmSubOrdResponseDTO;
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.PmSubOrdService;
import org.springframework.stereotype.Service;
import com.xisc.pm.domain.entity.PmSubOrd;
import com.xisc.pm.domain.repository.PmSubOrdRepository;

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

/**
 * 组板履历合同表(PmSubOrd)应用服务
 *
 * @author BKGY
 * @since 2025-01-02 10:39:49
 */
@Service
public class PmSubOrdServiceImpl implements PmSubOrdService {
    @Autowired
    private PmSubOrdRepository pmSubOrdRepository;

    @Override
    public Page<PmSubOrd> selectList(PageRequest pageRequest, PmSubOrd pmSubOrd) {
        return PageHelper.doPageAndSort(pageRequest, () -> pmSubOrdRepository.selectList(pmSubOrd));
    }

    @Override
    public void saveData(List<PmSubOrd> pmSubOrds) {
        List<PmSubOrd> insertList = pmSubOrds.stream().filter(line -> line.getId() == null).collect(Collectors.toList());
        List<PmSubOrd> updateList = pmSubOrds.stream().filter(line -> line.getId() != null).collect(Collectors.toList());
        pmSubOrdRepository.batchInsertSelective(insertList);
        pmSubOrdRepository.batchUpdateByPrimaryKeySelective(updateList);
    }

    @Override
    public Page<PmSubOrdResponseDTO> selectOrdList(PageRequest pageRequest, PmSubOrd pmSubOrd) {
        return PageHelper.doPageAndSort(pageRequest, () -> pmSubOrdRepository.selectOrdList(pmSubOrd));
    }
}

