All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.seal.system.service.impl.SysOperLogServiceImpl Maven / Gradle / Ivy

The newest version!
package com.seal.system.service.impl;

import com.alibaba.fastjson.JSON;
import com.seal.common.enums.BusinessStatus;
import com.seal.common.enums.OperatorType;
import com.seal.common.utils.SecurityUtils;
import com.seal.common.utils.ServletUtils;
import com.seal.common.utils.StringUtils;
import com.seal.common.utils.ip.IpUtils;
import com.seal.system.domain.SysOperLog;
import com.seal.system.mapper.SysOperLogMapper;
import com.seal.system.service.ISysOperLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 操作日志 服务层处理
 *
 * @author silianpan
 */
@Service
public class SysOperLogServiceImpl implements ISysOperLogService {
    @Autowired
    private SysOperLogMapper operLogMapper;

    /**
     * 新增操作日志
     *
     * @param operLog 操作日志对象
     */
    @Override
    public void insertOperlog(SysOperLog operLog) {
        operLogMapper.insertOperlog(operLog);
    }

    @Override
    public void insertOperlog(Integer businessType, String businessTitle, String methodName, Object paramsObj, Object jsonResult) {
        SysOperLog operLog = new SysOperLog();
        try {
            operLog.setStatus(BusinessStatus.SUCCESS.ordinal());
            // 请求的地址
            String ip = IpUtils.getIpAddr(ServletUtils.getRequest());
            operLog.setOperIp(ip);
            // 返回参数
            if (null != jsonResult) {
                operLog.setJsonResult(JSON.toJSONString(jsonResult));
            }
            operLog.setOperUrl(ServletUtils.getRequest().getRequestURI());
            // 获取当前的用户
            operLog.setOperName(SecurityUtils.getUsername());
            // 设置方法名称
            operLog.setMethod(methodName);
            // 设置请求方式
            operLog.setRequestMethod(ServletUtils.getRequest().getMethod());
            // 处理设置注解上的参数
            // 设置action动作
            operLog.setBusinessType(businessType);
            // 设置标题
            operLog.setTitle(businessTitle);
            // 设置操作人类别
            operLog.setOperatorType(OperatorType.MANAGE.ordinal());
            // 是否需要保存request,参数和值
            if (null != paramsObj) {
                operLog.setOperParam(StringUtils.substring(JSON.toJSONString(paramsObj), 0, 2000));
            }
        } catch (Exception e) {
            operLog.setStatus(BusinessStatus.FAIL.ordinal());
            operLog.setErrorMsg(StringUtils.substring(e.getMessage(), 0, 2000));
        } finally {
            // 保存数据库
            operLogMapper.insertOperlog(operLog);
        }
    }

    /**
     * 查询系统操作日志集合
     *
     * @param operLog 操作日志对象
     * @return 操作日志集合
     */
    @Override
    public List selectOperLogList(SysOperLog operLog) {
        return operLogMapper.selectOperLogList(operLog);
    }

    /**
     * 批量删除系统操作日志
     *
     * @param operIds 需要删除的操作日志ID
     * @return 结果
     */
    @Override
    public int deleteOperLogByIds(Long[] operIds) {
        return operLogMapper.deleteOperLogByIds(operIds);
    }

    /**
     * 查询操作日志详细
     *
     * @param operId 操作ID
     * @return 操作日志对象
     */
    @Override
    public SysOperLog selectOperLogById(Long operId) {
        return operLogMapper.selectOperLogById(operId);
    }

    /**
     * 清空操作日志
     */
    @Override
    public void cleanOperLog() {
        operLogMapper.cleanOperLog();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy