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

import com.xisc.pm.api.dto.PmSubLogRequestDTO;
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.PmSubLogService;
import org.springframework.stereotype.Service;
import com.xisc.pm.domain.entity.PmSubLog;
import com.xisc.pm.domain.repository.PmSubLogRepository;

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

/**
 * 自动替代日志表(PmSubLog)应用服务
 *
 * @author BKGY
 * @since 2024-12-26 15:08:28
 */
@Service
public class PmSubLogServiceImpl implements PmSubLogService {
    @Autowired
    private PmSubLogRepository pmSubLogRepository;

    @Override
    public Page<PmSubLog> selectList(PageRequest pageRequest, PmSubLogRequestDTO pmSubLogRequestDTO) {
        return PageHelper.doPageAndSort(pageRequest, () -> pmSubLogRepository.selectList(pmSubLogRequestDTO));
    }

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

