| | |
| | | } |
| | | String operationMsg = "执行了" + className + "的" + operationTypeName + "操作."; |
| | | String operationDetail = "具体调用方法为:" + methodName + ",具体参数为:" + map.toString(); |
| | | //根据当前的语言环境设置不同的日志记录 |
| | | String lang = ActionUtil.getLang(); |
| | | if (!lang.contains("zh")) { |
| | | operationMsg = "executed:" + className + " " + operationTypeNameEn + " operation "; |
| | | operationDetail = "Specific calling method is " + methodName + ",Specific parameters are " + map.toString(); |
| | | } |
| | | service.record(uId, operationType, operationTime, terminalIp, operationMsg, operationDetail); |
| | | String operationMsgEnUs = "executed:" + className + " " + operationTypeNameEn + " operation "; |
| | | String operationDetailEnUs = "Specific calling method is " + methodName + ",Specific parameters are " + map.toString(); |
| | | |
| | | service.record(uId, operationType, operationTime, terminalIp, operationMsg, operationDetail, operationMsgEnUs, operationDetailEnUs); |
| | | } |
| | | |
| | | } |
| | |
| | | public Response sendErrorResponse2Defined(Exception e, HttpServletResponse response, HttpServletRequest request){ |
| | | String exceptionStr = e.toString(); |
| | | String requestURI = request.getRequestURI(); |
| | | //根据当前的语言环境设置不同的日志记录 |
| | | String lang = ActionUtil.getLang(); |
| | | //单项提取-登录超时 |
| | | if (exceptionStr.contains("login") && exceptionStr.contains("imeout")) { |
| | | if (lang.contains("zh")) { |
| | | CommonUtil.record(ActionUtil.getUser().getUId(), UserOperation.TYPE_LOGIN_TIMEOUT.getType(), "登录请求超时", "异常信息:" + exceptionStr); |
| | | CommonUtil.record(ActionUtil.getUser().getUId(), UserOperation.TYPE_LOGIN_TIMEOUT.getType(), "登录请求超时", "异常信息:" + exceptionStr, UserOperation.TYPE_LOGIN_TIMEOUT.getTypeNameEn(), "exception message:" + exceptionStr); |
| | | } else { |
| | | CommonUtil.record(ActionUtil.getUser().getUId(), UserOperation.TYPE_LOGIN_TIMEOUT.getType(), UserOperation.TYPE_LOGIN_TIMEOUT.getTypeNameEn(), "exception message:" + exceptionStr); |
| | | } |
| | | } else { |
| | | if (lang.contains("zh")) { |
| | | CommonUtil.record(ActionUtil.getUser().getUId(), UserOperation.TYPE_EXCEPTION.getType(), "接口调用异常:调用接口" + requestURI + "发生错误:" + exceptionStr); |
| | | } else { |
| | | CommonUtil.record(ActionUtil.getUser().getUId(), UserOperation.TYPE_EXCEPTION.getType(), UserOperation.TYPE_EXCEPTION.getTypeNameEn() + "Call Interface:" + requestURI + "error occurred:" + exceptionStr); |
| | | } |
| | | CommonUtil.record(ActionUtil.getUser().getUId(), UserOperation.TYPE_EXCEPTION.getType(), "接口调用异常:调用接口" + requestURI + "发生错误:" + exceptionStr, UserOperation.TYPE_EXCEPTION.getTypeNameEn() + "Call Interface:" + requestURI + "error occurred:" + exceptionStr); |
| | | } |
| | | return new Response().setII(0, "接口请求异常,请联系软件人员进行处理.异常信息" + exceptionStr); |
| | | } |
| | |
| | | if (user == null) { |
| | | //越权访问 |
| | | //CommonUtil.record(0, UserOperation.TYPE_UNAUTHORIZED_ACCESS.getType(), "越权访问", "越权访问接口:" + requestURI); |
| | | CommonUtil.record2(request, 0, UserOperation.TYPE_UNAUTHORIZED_ACCESS.getType(), "越权访问", "越权访问接口:" + requestURI); |
| | | CommonUtil.record2(request, 0, UserOperation.TYPE_UNAUTHORIZED_ACCESS.getType() |
| | | , "越权访问", "越权访问接口:" + requestURI, "Unauthorized access", "Unauthorized access interface:" + requestURI); |
| | | response.setStatus(401); |
| | | response.setContentType("text/html;charset=utf-8"); |
| | | response.getWriter().write("非法请求,身份未验证"); |
| | |
| | | private String terminalIp; |
| | | @TableField("uOprateMsg") |
| | | private String operationMsg; |
| | | @TableField("uOprateMsgEnUs") |
| | | private String operationMsgEnUs; |
| | | private String operationDetail; |
| | | private String operationDetailEnUs; |
| | | |
| | | |
| | | public OperationLog() { |
| | | } |
| | | |
| | | public OperationLog(Long num, Integer uId, Integer operationType, Date operationTime, String terminalIp, String operationMsg, String operationDetail) { |
| | | public OperationLog(Long num, Integer uId, Integer operationType, Date operationTime, String terminalIp |
| | | , String operationMsg, String operationDetail, String operationMsgEnUs, String operationDetailEnUs) { |
| | | this.num = num; |
| | | this.uId = uId; |
| | | this.operationType = operationType; |
| | |
| | | public void setOperationDetail(String operationDetail) { |
| | | this.operationDetail = operationDetail; |
| | | } |
| | | |
| | | public String getOperationMsgEnUs() { |
| | | return operationMsgEnUs; |
| | | } |
| | | |
| | | public void setOperationMsgEnUs(String operationMsgEnUs) { |
| | | this.operationMsgEnUs = operationMsgEnUs; |
| | | } |
| | | |
| | | public String getOperationDetailEnUs() { |
| | | return operationDetailEnUs; |
| | | } |
| | | |
| | | public void setOperationDetailEnUs(String operationDetailEnUs) { |
| | | this.operationDetailEnUs = operationDetailEnUs; |
| | | } |
| | | } |
| | |
| | | private String operationMsg; |
| | | private String operationDetail; |
| | | private Integer readFlag; |
| | | @TableField("uOprateMsgEnUs") |
| | | private String operationMsgEnUs; |
| | | private String operationDetailEnUs; |
| | | |
| | | @TableField(exist = false) |
| | | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "Asia/Shanghai") |
| | |
| | | public void setRecordYear(String recordYear) { |
| | | this.recordYear = recordYear; |
| | | } |
| | | |
| | | public String getOperationMsgEnUs() { |
| | | return operationMsgEnUs; |
| | | } |
| | | |
| | | public void setOperationMsgEnUs(String operationMsgEnUs) { |
| | | this.operationMsgEnUs = operationMsgEnUs; |
| | | } |
| | | |
| | | public String getOperationDetailEnUs() { |
| | | return operationDetailEnUs; |
| | | } |
| | | |
| | | public void setOperationDetailEnUs(String operationDetailEnUs) { |
| | | this.operationDetailEnUs = operationDetailEnUs; |
| | | } |
| | | } |
| | |
| | | } else { |
| | | servletContext.setAttribute(userName + "_login_fail_times_" + System.currentTimeMillis(), 0); |
| | | } |
| | | //根据当前的语言环境设置不同的日志记录 |
| | | String lang = ActionUtil.getLang(); |
| | | if (lang.contains("zh")) { |
| | | CommonUtil.record(0, UserOperation.TYPE_LOGIN_FAIL.getType(), UserOperation.TYPE_LOGIN_FAIL.getTypeName()); |
| | | } else { |
| | | CommonUtil.record(0, UserOperation.TYPE_LOGIN_FAIL.getType(), UserOperation.TYPE_LOGIN_FAIL.getTypeNameEn()); |
| | | } |
| | | |
| | | CommonUtil.record(0, UserOperation.TYPE_LOGIN_FAIL.getType(), UserOperation.TYPE_LOGIN_FAIL.getTypeName(), UserOperation.TYPE_LOGIN_FAIL.getTypeNameEn()); |
| | | return response.set(1, false, MessageUtils.getMessage("PasswordError")); |
| | | } |
| | | return response.set(1, false, message); |
| | |
| | | //查询激活的地图 |
| | | String mapName = mapOutlineService.selectMapName(); |
| | | dataList.add(mapName); |
| | | //根据当前的语言环境设置不同的日志记录 |
| | | String lang = ActionUtil.getLang(); |
| | | if (lang.contains("zh")) { |
| | | CommonUtil.record(((UserInf) subject.getPrincipal()).getUId(), UserOperation.TYPE_LOGIN.getType(), UserOperation.TYPE_LOGIN.getTypeName()); |
| | | } else { |
| | | CommonUtil.record(((UserInf) subject.getPrincipal()).getUId(), UserOperation.TYPE_LOGIN.getType(), UserOperation.TYPE_LOGIN.getTypeNameEn()); |
| | | } |
| | | |
| | | CommonUtil.record(((UserInf) subject.getPrincipal()).getUId(), UserOperation.TYPE_LOGIN.getType(), UserOperation.TYPE_LOGIN.getTypeName(), UserOperation.TYPE_LOGIN.getTypeNameEn()); |
| | | return new Response<>().setII(1, true, dataList, MessageUtils.getMessage("LoginSucceeded")); |
| | | } |
| | | return new Response().set(1, false, MessageUtils.getMessage("AuthenticationFailed")); |
| | |
| | | } else { |
| | | servletContext.setAttribute(userName + "_login_fail_times_" + System.currentTimeMillis(), 0); |
| | | } |
| | | //根据当前的语言环境设置不同的日志记录 |
| | | String lang = ActionUtil.getLang(); |
| | | if (lang.contains("zh")) { |
| | | CommonUtil.record(0, UserOperation.TYPE_LOGIN_FAIL.getType(), UserOperation.TYPE_LOGIN_FAIL.getTypeName()); |
| | | } else { |
| | | CommonUtil.record(0, UserOperation.TYPE_LOGIN_FAIL.getType(), UserOperation.TYPE_LOGIN_FAIL.getTypeNameEn()); |
| | | } |
| | | CommonUtil.record(0, UserOperation.TYPE_LOGIN_FAIL.getType(), UserOperation.TYPE_LOGIN_FAIL.getTypeName(), UserOperation.TYPE_LOGIN_FAIL.getTypeNameEn()); |
| | | return response.set(1, false, "密码错误"); |
| | | } |
| | | return response.set(1, false, message); |
| | |
| | | int permitGroupId = permitGroup.getPermitGroupId(); |
| | | dataList.add(permitGroupId); |
| | | } |
| | | //根据当前的语言环境设置不同的日志记录 |
| | | String lang = ActionUtil.getLang(); |
| | | if (lang.contains("zh")) { |
| | | CommonUtil.record(((UserInf) subject.getPrincipal()).getUId(), UserOperation.TYPE_LOGIN.getType(), UserOperation.TYPE_LOGIN.getTypeName()); |
| | | } else { |
| | | CommonUtil.record(((UserInf) subject.getPrincipal()).getUId(), UserOperation.TYPE_LOGIN.getType(), UserOperation.TYPE_LOGIN.getTypeNameEn()); |
| | | } |
| | | CommonUtil.record(((UserInf) subject.getPrincipal()).getUId(), UserOperation.TYPE_LOGIN.getType(), UserOperation.TYPE_LOGIN.getTypeName(), UserOperation.TYPE_LOGIN.getTypeNameEn()); |
| | | return new Response<>().setII(1, true, dataList, "登录成功"); |
| | | } |
| | | return new Response<>().set(1,false,"密码错误"); |
| | |
| | | int permitGroupId = permitGroup.getPermitGroupId(); |
| | | dataList.add(permitGroupId); |
| | | } |
| | | //根据当前的语言环境设置不同的日志记录 |
| | | String lang = ActionUtil.getLang(); |
| | | if (lang.contains("zh")) { |
| | | CommonUtil.record(((UserInf) subject.getPrincipal()).getUId(), UserOperation.TYPE_LOGIN_NO_PASS.getType(), UserOperation.TYPE_LOGIN_NO_PASS.getTypeName()); |
| | | } else { |
| | | CommonUtil.record(((UserInf) subject.getPrincipal()).getUId(), UserOperation.TYPE_LOGIN_NO_PASS.getType(), UserOperation.TYPE_LOGIN_NO_PASS.getTypeNameEn()); |
| | | } |
| | | CommonUtil.record(((UserInf) subject.getPrincipal()).getUId(), UserOperation.TYPE_LOGIN_NO_PASS.getType(), UserOperation.TYPE_LOGIN_NO_PASS.getTypeName(), UserOperation.TYPE_LOGIN_NO_PASS.getTypeNameEn()); |
| | | return new Response<>().setII(1, true, dataList, "登录成功"); |
| | | } |
| | | return new Response().set(1,false,"认证未通过"); |
| | |
| | | @Resource |
| | | private OperationLogMapper mapper; |
| | | |
| | | public void record(Long uId, Integer operationType, Date operationTime, String terminalIp, String operationMsg, String operationDetail) { |
| | | OperationLog operationLog = new OperationLog(null, uId.intValue(), operationType, operationTime, terminalIp, operationMsg, operationDetail); |
| | | public void record(Long uId, Integer operationType, Date operationTime, String terminalIp |
| | | , String operationMsg, String operationDetail, String operationMsgEnUs, String operationDetailEnUs) { |
| | | OperationLog operationLog = new OperationLog(null, uId.intValue(), operationType, operationTime, terminalIp |
| | | , operationMsg, operationDetail, operationMsgEnUs, operationDetailEnUs); |
| | | mapper.insert(operationLog); |
| | | } |
| | | } |
| | |
| | | ExcelUtil.exportExcel("UserLog-" + now, "sheet1", columnTitleArr, value, new HSSFWorkbook(), response); |
| | | } |
| | | |
| | | public void record(long uId, int operationType, String msg) { |
| | | public void record(long uId, int operationType, String msg, String msgEnUS) { |
| | | UserLog userLog = new UserLog(); |
| | | userLog.setTerminalIp(ActionUtil.getRequest().getRemoteAddr()); |
| | | //userLog.setTerminalIp(request.getRemoteAddr()); |
| | |
| | | userLog.setUId((int)(uId)); |
| | | userLog.setOperationType(operationType); |
| | | userLog.setOperationMsg(msg); |
| | | userLog.setOperationMsgEnUs(msgEnUS); |
| | | mapper.insert(userLog); |
| | | } |
| | | |
| | | public void record(long uId, int operationType, String msg,String msgDetail) { |
| | | public void record(long uId, int operationType, String msg, String msgDetail, String msgEnUs, String msgDetailEnUs) { |
| | | UserLog userLog = new UserLog(); |
| | | userLog.setTerminalIp(ActionUtil.getRequest().getRemoteAddr()); |
| | | //userLog.setTerminalIp(request.getRemoteAddr()); |
| | |
| | | userLog.setOperationType(operationType); |
| | | userLog.setOperationMsg(msg); |
| | | userLog.setOperationDetail(msgDetail); |
| | | userLog.setOperationMsg(msgEnUs); |
| | | userLog.setOperationDetail(msgDetailEnUs); |
| | | mapper.insert(userLog); |
| | | } |
| | | |
| | | public void record2(HttpServletRequest request,long uId, int operationType, String msg,String msgDetail) { |
| | | public void record2(HttpServletRequest request, long uId, int operationType, String msg, String msgDetail, String msgEnUs, String msgDetailEnUs) { |
| | | UserLog userLog = new UserLog(); |
| | | userLog.setTerminalIp(request.getRemoteAddr()); |
| | | //userLog.setTerminalIp(request.getRemoteAddr()); |
| | |
| | | userLog.setOperationType(operationType); |
| | | userLog.setOperationMsg(msg); |
| | | userLog.setOperationDetail(msgDetail); |
| | | userLog.setOperationMsg(msgEnUs); |
| | | userLog.setOperationDetail(msgDetailEnUs); |
| | | mapper.insert(userLog); |
| | | } |
| | | |
| | |
| | | import org.springframework.boot.system.ApplicationHome; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import java.io.File; |
| | | import java.text.ParseException; |
| | |
| | | return baseDirPath; |
| | | } |
| | | |
| | | /**手动记录特定日志*/ |
| | | public static void record(long uId, int operationType, String msg){ |
| | | userLogService.record(uId,operationType,msg); |
| | | } |
| | | |
| | | /**手动记录特定日志*/ |
| | | public static void record(long uId, int operationType, String msg,String msgDetail){ |
| | | userLogService.record(uId,operationType,msg,msgDetail); |
| | | } |
| | | /**手动记录特定日志*/ |
| | | public static void record2(HttpServletRequest request,long uId, int operationType, String msg,String msgDetail){ |
| | | userLogService.record2(request,uId,operationType,msg,msgDetail); |
| | | /** |
| | | * 手动记录特定日志 |
| | | */ |
| | | public static void record(long uId, int operationType, String msg, String msgEnUs) { |
| | | userLogService.record(uId, operationType, msg, msgEnUs); |
| | | } |
| | | |
| | | /** |
| | | * |
| | | * 手动记录特定日志 |
| | | */ |
| | | public static void record(long uId, int operationType, String msg, String msgDetail, String msgEnUs, String msgDetailEnUs) { |
| | | userLogService.record(uId, operationType, msg, msgDetail, msgEnUs, msgDetailEnUs); |
| | | } |
| | | |
| | | /** |
| | | * 手动记录特定日志 |
| | | */ |
| | | public static void record2(HttpServletRequest request, long uId, int operationType, String msg, String msgDetail, String msgEnUs, String msgDetailEnUs) { |
| | | userLogService.record2(request, uId, operationType, msg, msgDetail, msgEnUs, msgDetailEnUs); |
| | | } |
| | | |
| | | /** |
| | | * 在分表的情况下使用,按年分表,查询需要切割查询使用 |
| | | * |
| | | * <p> |
| | | * 根据传入的起止时间,按照年切割成不同时间段 |
| | | * |
| | | * @param startTimeStr 2021-01-01 10:00:00 |
| | | * @param endTimeStr 2023-05-01 10:10:10 |
| | | * @return 示例[2021,2022,2023] |
| | |
| | | datasource: |
| | | type: com.alibaba.druid.pool.DruidDataSource |
| | | driver-class-name: com.mysql.cj.jdbc.Driver |
| | | url: jdbc:mysql://192.168.10.79:3360/db_user?characterEncoding=utf8&serverTimezone=Asia/Shanghai&allowMultiQueries=true&rewriteBatchedStatements=true |
| | | url: jdbc:mysql://192.168.10.250:3360/db_user?characterEncoding=utf8&serverTimezone=Asia/Shanghai&allowMultiQueries=true&rewriteBatchedStatements=true |
| | | # url: jdbc:mysql://192.168.10.80:3360/db_user?characterEncoding=utf8&serverTimezone=Asia/Shanghai&allowMultiQueries=true&rewriteBatchedStatements=true |
| | | # url: jdbc:mysql://118.89.139.230:3360/db_user?characterEncoding=utf8&serverTimezone=Asia/Shanghai&allowMultiQueries=true&rewriteBatchedStatements=true |
| | | username: root |