package com.loan.system.service.Impl;

import com.loan.system.domain.entity.ExceptionLog;
import com.loan.system.repository.ExceptionLogDao;
import com.loan.system.service.ExceptionLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;

@Service
public class ExceptionServiceImpl implements ExceptionLogService {

    ExceptionLogDao exceptionLogDao;

    @Autowired
    public ExceptionServiceImpl(ExceptionLogDao exceptionLogDao) {
        this.exceptionLogDao = exceptionLogDao;
    }

    @Override
    public void insertExceptionLog(ExceptionLog e) {
            exceptionLogDao.save(e);
    }

    @Override
    public ExceptionLog getOne(int id) {
        return exceptionLogDao.getOne(id);
    }

    @Override
    public Page<ExceptionLog> getExceptionLogByPage(int page, int size) {
        Sort sort = Sort.by(Sort.Direction.DESC, "operTime");
        Pageable pageable = PageRequest.of(page, size, sort);
        return exceptionLogDao.getExceptionLogByPage(pageable);

    }
}
