package com.rf.psychological.opLog.service.impl;

import com.rf.psychological.dao.repository.SysLogRepository;
import com.rf.psychological.opLog.dao.SysLogEntity;
import com.rf.psychological.opLog.service.SysLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * @author lpf
 * @description:
 * @date 2022/1/614:35
 */
@Service
public class SysLogServiceImpl implements SysLogService {

    @Autowired
    private SysLogRepository sysLogRepository;

    @Override
    public SysLogEntity save(SysLogEntity sysLogEntity) {
        return sysLogRepository.save(sysLogEntity);
    }

    @Override
    public void deleteById(String id) {
        sysLogRepository.deleteById(id);
    }

    @Override
    public Page<SysLogEntity> findByInstitutionNo(String institutionNo, String searchKey, Date beginTime, Date endTime, String searchUserName, String type, int beginNum, int pageSize) {
        switch (type) {
            case "0":
                type = "user";
                break;
            case "1":
                type = "admin";
                break;
            case "2":
                type = "superAdmin";
                break;
            default:
                type = "";
                break;
        }
        return sysLogRepository.findByInstitutionNo(institutionNo, searchKey, beginTime, endTime, searchUserName, type, PageRequest.of(beginNum - 1, pageSize));
    }
}
