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

import com.xisc.pm.api.dto.PmSubHisRequestDTO;
import com.xisc.pm.api.dto.PmSubHisResponseDTO;
import com.xisc.pm.infra.mapper.PmSubHisMapper;
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.PmSubHisService;
import org.springframework.stereotype.Service;
import com.xisc.pm.domain.entity.PmSubHis;
import com.xisc.pm.domain.repository.PmSubHisRepository;

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

/**
 * 自动替代履历表(PmSubHis)应用服务
 *
 * @author BKGY
 * @since 2024-12-26 09:57:36
 */
@Service
public class PmSubHisServiceImpl implements PmSubHisService {
    @Autowired
    private PmSubHisRepository pmSubHisRepository;

    @Autowired
    private PmSubHisMapper pmSubHisMapper;

    @Override
    public Page<PmSubHis> selectList(PageRequest pageRequest, PmSubHisRequestDTO pmSubHisRequestDTO) {
        return PageHelper.doPageAndSort(pageRequest, () -> pmSubHisRepository.selectList(pmSubHisRequestDTO));
    }

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

    @Override
    public Page<PmSubHisResponseDTO> selectStatisticsList(PageRequest pageRequest, PmSubHisRequestDTO pmSubHisRequestDTO) {
        return PageHelper.doPageAndSort(pageRequest, () -> pmSubHisMapper.selectStatisticsList(pmSubHisRequestDTO));
    }
}

