whycxzp
2023-12-13 bffd7fca80dd79adb5621b992beca63ab06b9d16
日志
3个文件已修改
72 ■■■■■ 已修改文件
src/main/java/com/whyc/aop/CustomExceptionResultHandler.java 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/aop/OperationLogAspect.java 56 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/constant/OperationLogEnum.java 11 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/aop/CustomExceptionResultHandler.java
@@ -33,10 +33,11 @@
        String exceptionStr = e.toString();
        String requestURI = request.getRequestURI();
        //单项提取-登录超时
        Integer type = OperationLogEnum.TYPE_1_SYS.getType();
        if (exceptionStr.contains("login") && exceptionStr.contains("imeout")) {
            logService.record(UserUtil.getUser().getUid(), OperationLogEnum.TYPE_1_SYS.getType(),OperationLogEnum.TYPE_2_CONNECTION_TIMEOUT.getName(), "登录请求超时", "异常信息:" + exceptionStr);
            logService.record(UserUtil.getUser().getUid(), OperationLogEnum.TYPE_1_SYS.getType(),OperationLogEnum.TYPE_2_CONNECTION_TIMEOUT.getType(), "登录请求超时", "异常信息:" + exceptionStr);
        } else {
            logService.record(UserUtil.getUser().getUid(), OperationLogEnum.TYPE_1_SYS.getType(),OperationLogEnum.TYPE_2_EXCEPTION.getName(),"接口调用异常", "接口调用异常:调用接口" + requestURI + "发生错误:" + exceptionStr);
            logService.record(UserUtil.getUser().getUid(), OperationLogEnum.TYPE_1_SYS.getType(),OperationLogEnum.TYPE_2_EXCEPTION.getType(),"接口调用异常", "接口调用异常:调用接口" + requestURI + "发生错误:" + exceptionStr);
        }
        return new Response().set(0, "接口请求异常,请联系软件人员进行处理.异常信息" + exceptionStr);
    }
src/main/java/com/whyc/aop/OperationLogAspect.java
@@ -1,5 +1,6 @@
package com.whyc.aop;
import com.whyc.constant.OperationLogEnum;
import com.whyc.dto.Response;
import com.whyc.service.OperationLogService;
import com.whyc.util.UserUtil;
@@ -59,59 +60,82 @@
        //类名
        // e.g: CKPowerDevRtSetController
        String classNameTrue = fullClassNameSplit[fullClassNameSplit.length - 1];
        Integer operationType = 0;
        String operationTypeName = null;
        Integer type1 = 0;
        Integer type2 = 0;
        String operationTypeName = "";
        //系统级
        if (classNameTrue.equals("UserInfController")) {
            if(methodName.contains("add")){ //用户新增
                //TODO
                type1 = OperationLogEnum.TYPE_1_SYS.getType();
                type2 = OperationLogEnum.TYPE_2_USER_ADD.getType();
                operationTypeName = OperationLogEnum.TYPE_2_USER_ADD.getName();
            }else if(methodName.contains("update")){ //用户修改
                //TODO
                type1 = OperationLogEnum.TYPE_1_SYS.getType();
                type2 = OperationLogEnum.TYPE_2_USER_UPDATE.getType();
                operationTypeName = OperationLogEnum.TYPE_2_USER_UPDATE.getName();
            }else if(methodName.contains("delete")){ //用户删除
                //TODO
            }else if(methodName.contains("update")){ //密码重置 TODO
                //TODO
                type1 = OperationLogEnum.TYPE_1_SYS.getType();
                type2 = OperationLogEnum.TYPE_2_USER_DELETE.getType();
                operationTypeName = OperationLogEnum.TYPE_2_USER_DELETE.getName();
            }else if(methodName.contains("updatePassword")){ //密码重置 TODO
                type1 = OperationLogEnum.TYPE_1_SYS.getType();
                type2 = OperationLogEnum.TYPE_2_USER_UPDATE_PASSWORD.getType();
                operationTypeName = OperationLogEnum.TYPE_2_USER_UPDATE_PASSWORD.getName();
            }
        }else if(classNameTrue.equals("LoginController")){
            if(methodName.equals("login")){
                if((boolean) response.getData()){ //用户登录
                    //TODO
                    type1 = OperationLogEnum.TYPE_1_SYS.getType();
                    type2 = OperationLogEnum.TYPE_2_LOGIN.getType();
                    operationTypeName = OperationLogEnum.TYPE_2_LOGIN.getName();
                }else { //用户登录失败
                    //TODO
                    type1 = OperationLogEnum.TYPE_1_SYS.getType();
                    type2 = OperationLogEnum.TYPE_2_LOGIN_FAIL.getType();
                    operationTypeName = OperationLogEnum.TYPE_2_LOGIN_FAIL.getName();
                }
            }else if(methodName.equals("logout")){ //用户退出
                //TODO
                type1 = OperationLogEnum.TYPE_1_SYS.getType();
                type2 = OperationLogEnum.TYPE_2_LOGOUT.getType();
                operationTypeName = OperationLogEnum.TYPE_2_LOGOUT.getName();
            }
        }
        //业务级
        else if(classNameTrue.equals("CKPowerDevSignalSetController")
        ||classNameTrue.equals("CKPowerDevRtSetController")){ //电源设备设置
            if(methodName.startsWith("update")){
                //TODO
                type1 = OperationLogEnum.TYPE_1_SERVICE.getType();
                type2 = OperationLogEnum.TYPE_2_POWER_UPDATE.getType();
                operationTypeName = OperationLogEnum.TYPE_2_POWER_UPDATE.getName();
            }
        }else if(classNameTrue.equals("CKPowerDevBattRtStateSetController")){ //核容装置设置
            if(methodName.startsWith("update")){
                //TODO
                type1 = OperationLogEnum.TYPE_1_SERVICE.getType();
                type2 = OperationLogEnum.TYPE_2_BATTERY_UPDATE.getType();
                operationTypeName = OperationLogEnum.TYPE_2_BATTERY_UPDATE.getName();
            }
        }else if(classNameTrue.contains("Alarm")
                ||classNameTrue.contains("Alm")){ //告警设置
            if(methodName.startsWith("update")){
                //TODO
                type1 = OperationLogEnum.TYPE_1_SERVICE.getType();
                type2 = OperationLogEnum.TYPE_2_ALARM.getType();
                operationTypeName = OperationLogEnum.TYPE_2_ALARM.getName();
            }
        }
        // TODO else if()
        String module = "模块";
        String className = classNameTrue.replace("Controller:", module);
        //操作时间
       /* //操作时间
        Date operationTime = new Date();
        //客户端ip
        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes()).getRequest();
        String terminalIp = request.getRemoteAddr();
        String terminalIp = request.getRemoteAddr();*/
        //操作信息
        //获取切点方法信息
@@ -127,7 +151,7 @@
        String operationMsg = "执行了" + className + "的" + operationTypeName + "操作.";
        String operationDetail = "具体调用方法为:" + methodName + ",具体参数为:" + map.toString();
        //service.record(uId, operationType, operationTime, terminalIp, operationMsg, operationDetail, operationMsgEnUs, operationDetailEnUs);
        service.record(uId, type1, type2, operationMsg, operationDetail);
    }
src/main/java/com/whyc/constant/OperationLogEnum.java
@@ -13,7 +13,7 @@
    TYPE_2_LOGOUT(103,"用户退出"),
    TYPE_2_USER_UPDATE(104,"用户信息修改"),
    TYPE_2_USER_ADD(105,"用户信息增加"),
    TYPE_2_USER_DEL(106,"用户信息删除"),
    TYPE_2_USER_DELETE(106,"用户信息删除"),
    TYPE_2_USER_UPDATE_PASSWORD(106,"密码重置"),
    TYPE_2_UNAUTHORIZED_ACCESS(107,"越权访问"),
    TYPE_2_CONNECTION_TIMEOUT(108,"连接超时"),
@@ -22,20 +22,23 @@
    //子级别-业务级
    TYPE_2_POWER_UPDATE(101,"电源设备设置"),
    TYPE_2_BATTERY_UPDATE(201,"核容装置设置"),
    TYPE_2_ALARM_PARAM(101,"告警设置"),
    TYPE_2_ALARM(101,"告警设置"),
    ;
    private Integer type;
    private Integer name;
    private String name;
    OperationLogEnum(Integer type, String name) {
        this.type = type;
        this.name = name;
    }
    public Integer getType() {
        return type;
    }
    public Integer getName() {
    public String getName() {
        return name;
    }
}