处理 SpringMVC 全局处理
This commit is contained in:
@@ -22,7 +22,20 @@ POST {{baseUrl}}/admin/update-status
|
||||
Content-Type: application/x-www-form-urlencoded
|
||||
Authorization: Bearer {{accessToken}}
|
||||
|
||||
id=31&status=1
|
||||
adminId=31&status=1
|
||||
|
||||
### /admin/update-status 失败,参数缺失
|
||||
POST {{baseUrl}}/admin/update-status
|
||||
Content-Type: application/x-www-form-urlencoded
|
||||
Authorization: Bearer {{accessToken}}
|
||||
|
||||
adminId=31
|
||||
|
||||
### admin/update-status 失败,地址不存在
|
||||
GET {{baseUrl}}/admin/update-status---
|
||||
Content-Type: application/x-www-form-urlencoded
|
||||
Authorization: Bearer {{accessToken}}
|
||||
|
||||
adminId=31&status=sss
|
||||
|
||||
###
|
||||
|
||||
|
||||
@@ -14,18 +14,21 @@ import cn.iocoder.security.annotations.RequiresPermissions;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.validation.Valid;
|
||||
|
||||
import static cn.iocoder.common.framework.vo.CommonResult.success;
|
||||
|
||||
@Api("管理员 API")
|
||||
@RestController
|
||||
@RequestMapping("/admin")
|
||||
@Validated
|
||||
public class AdminController {
|
||||
|
||||
@Autowired
|
||||
@@ -56,7 +59,7 @@ public class AdminController {
|
||||
@PostMapping("/update-status")
|
||||
@ApiOperation(value = "更新管理员状态")
|
||||
@RequiresPermissions("system:admin:update-status")
|
||||
public CommonResult<Boolean> updateAdminStatus(AdminUpdateStatusDTO updateStatusDTO) {
|
||||
public CommonResult<Boolean> updateAdminStatus(@Valid AdminUpdateStatusDTO updateStatusDTO) {
|
||||
adminManager.updateAdminStatus(updateStatusDTO);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import cn.iocoder.common.framework.vo.PageResult;
|
||||
import cn.iocoder.mall.managementweb.controller.systemlog.dto.SystemAccessLogPageDTO;
|
||||
import cn.iocoder.mall.managementweb.controller.systemlog.vo.SystemAccessLogVO;
|
||||
import cn.iocoder.mall.managementweb.manager.systemlog.SystemAccessLogManager;
|
||||
import cn.iocoder.security.annotations.RequiresPermissions;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -29,6 +30,7 @@ public class SystemAccessLogController {
|
||||
|
||||
@GetMapping("/page")
|
||||
@ApiOperation("获得系统访问日志分页")
|
||||
@RequiresPermissions("system:system-access-log:page")
|
||||
public CommonResult<PageResult<SystemAccessLogVO>> pageSystemAccessLog(SystemAccessLogPageDTO pageDTO) {
|
||||
return success(systemAccessLogManager.pageSystemAccessLog(pageDTO));
|
||||
}
|
||||
|
||||
@@ -3,18 +3,18 @@ package cn.iocoder.mall.managementweb.controller.systemlog;
|
||||
import cn.iocoder.common.framework.vo.CommonResult;
|
||||
import cn.iocoder.common.framework.vo.PageResult;
|
||||
import cn.iocoder.mall.managementweb.controller.systemlog.dto.SystemExceptionLogPageDTO;
|
||||
import cn.iocoder.mall.managementweb.controller.systemlog.dto.SystemExceptionLogProcessDTO;
|
||||
import cn.iocoder.mall.managementweb.controller.systemlog.vo.SystemExceptionLogDetailVO;
|
||||
import cn.iocoder.mall.managementweb.controller.systemlog.vo.SystemExceptionLogVO;
|
||||
import cn.iocoder.mall.managementweb.manager.systemlog.SystemExceptionLogManager;
|
||||
import cn.iocoder.mall.security.admin.core.context.AdminSecurityContextHolder;
|
||||
import cn.iocoder.security.annotations.RequiresPermissions;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import static cn.iocoder.common.framework.vo.CommonResult.success;
|
||||
|
||||
@@ -33,14 +33,24 @@ public class SystemExceptionLogController {
|
||||
@GetMapping("/get")
|
||||
@ApiOperation("获得系统异常日志明细")
|
||||
@ApiImplicitParam(name = "logId", value = "系统异常日志编号", required = true)
|
||||
@RequiresPermissions("system:system-exception-log:page")
|
||||
public CommonResult<SystemExceptionLogDetailVO> getSystemExceptionLogDetail(@RequestParam("logId") Integer logId) {
|
||||
return success(systemExceptionLogManager.getSystemExceptionLogDetail(logId));
|
||||
}
|
||||
|
||||
@GetMapping("/page")
|
||||
@ApiOperation("获得系统异常日志分页")
|
||||
@RequiresPermissions("system:system-exception-log:page")
|
||||
public CommonResult<PageResult<SystemExceptionLogVO>> pageSystemExceptionLog(SystemExceptionLogPageDTO pageDTO) {
|
||||
return success(systemExceptionLogManager.pageSystemExceptionLog(pageDTO));
|
||||
}
|
||||
|
||||
@PostMapping("/process")
|
||||
@ApiOperation("处理系统异常日志")
|
||||
@RequiresPermissions("system:system-exception-log:process")
|
||||
public CommonResult<Boolean> processSystemExceptionLog(SystemExceptionLogProcessDTO processDTO) {
|
||||
systemExceptionLogManager.processSystemExceptionLog(AdminSecurityContextHolder.getAdminId(), processDTO);
|
||||
return CommonResult.success(true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package cn.iocoder.mall.managementweb.controller.systemlog.dto;
|
||||
|
||||
import cn.iocoder.common.framework.vo.PageParam;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
@ApiModel("系统异常日志处理 DTO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class SystemExceptionLogProcessDTO extends PageParam {
|
||||
|
||||
@ApiModelProperty(value = "系统异常日志编号", required = true, example = "1")
|
||||
private Integer logId;
|
||||
@ApiModelProperty(value = "处理状态", required = true, notes = "对应 SystemExceptionLogProcessStatusEnum 枚举类", example = "1")
|
||||
private Integer processStatus;
|
||||
|
||||
}
|
||||
@@ -8,7 +8,7 @@ import java.util.*;
|
||||
@Data
|
||||
public class SystemAccessLogVO {
|
||||
|
||||
@ApiModelProperty(value = "编号", required = true)
|
||||
@ApiModelProperty(value = "编号", required = true, example = "1")
|
||||
private Integer id;
|
||||
@ApiModelProperty(value = "用户编号", example = "1024")
|
||||
private Integer userId;
|
||||
|
||||
@@ -1,4 +1,76 @@
|
||||
package cn.iocoder.mall.managementweb.controller.systemlog.vo;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@ApiModel("系统异常日志明细 DTO")
|
||||
@Data
|
||||
public class SystemExceptionLogDetailVO {
|
||||
|
||||
@ApiModel("管理员")
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public static class Admin {
|
||||
|
||||
@ApiModelProperty(value = "管理员编号", required = true, example = "1")
|
||||
private Integer id;
|
||||
@ApiModelProperty(value = "真实名字", required = true, example = "小王")
|
||||
private String name;
|
||||
|
||||
}
|
||||
|
||||
@ApiModelProperty(value = "编号", required = true, example = "1")
|
||||
private Integer id;
|
||||
@ApiModelProperty(value = "用户编号", example = "1024")
|
||||
private Integer userId;
|
||||
@ApiModelProperty(value = "用户类型", example = "1")
|
||||
private Integer userType;
|
||||
@ApiModelProperty(value = "链路追踪编号", example = "89aca178-a370-411c-ae02-3f0d672be4ab")
|
||||
private String traceId;
|
||||
@ApiModelProperty(value = "应用名", required = true, example = "user-shop-application")
|
||||
private String applicationName;
|
||||
@ApiModelProperty(value = "访问地址", required = true, example = "/management-api/system-access-log/page")
|
||||
private String uri;
|
||||
@ApiModelProperty(value = "参数", required = true, example = "pageNo=1&pageSize=10")
|
||||
private String queryString;
|
||||
@ApiModelProperty(value = "http 方法", required = true, example = "GET")
|
||||
private String method;
|
||||
@ApiModelProperty(value = "userAgent", required = true, example = "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:47.0) Gecko/20100101 Firefox/47.0")
|
||||
private String userAgent;
|
||||
@ApiModelProperty(value = "ip", required = true, example = "127.0.0.1")
|
||||
private String ip;
|
||||
@ApiModelProperty(value = "异常发生时间", required = true)
|
||||
private Date exceptionTime;
|
||||
@ApiModelProperty(value = "异常名, {@link Throwable#getClass()} 的类全名", required = true)
|
||||
private String exceptionName;
|
||||
@ApiModelProperty(value = "异常导致的消息, {@link cn.iocoder.common.framework.util.ExceptionUtil#getMessage(Throwable)}", required = true)
|
||||
private String exceptionMessage;
|
||||
@ApiModelProperty(value = "异常导致的根消息, {@link cn.iocoder.common.framework.util.ExceptionUtil#getRootCauseMessage(Throwable)}", required = true)
|
||||
private String exceptionRootCauseMessage;
|
||||
@ApiModelProperty(value = "异常的栈轨迹, {@link cn.iocoder.common.framework.util.ExceptionUtil#getServiceException(Exception)}", required = true)
|
||||
private String exceptionStackTrace;
|
||||
@ApiModelProperty(value = "异常发生的类全名, {@link StackTraceElement#getClassName()}", required = true)
|
||||
private String exceptionClassName;
|
||||
@ApiModelProperty(value = "异常发生的类文件, {@link StackTraceElement#getFileName()}", required = true)
|
||||
private String exceptionFileName;
|
||||
@ApiModelProperty(value = "异常发生的方法名, {@link StackTraceElement#getMethodName()}", required = true)
|
||||
private String exceptionMethodName;
|
||||
@ApiModelProperty(value = "异常发生的方法所在行, {@link StackTraceElement#getLineNumber()}", required = true)
|
||||
private Integer exceptionLineNumber;
|
||||
@ApiModelProperty(value = "处理状态", required = true, notes = "对应 SystemExceptionLogProcessStatusEnum 枚举类", example = "1")
|
||||
private Integer processStatus;
|
||||
@ApiModelProperty(value = "处理时间")
|
||||
private Date processTime;
|
||||
@ApiModelProperty(value = "创建时间", required = true)
|
||||
private Date createTime;
|
||||
|
||||
/**
|
||||
* 处理的管理员信息
|
||||
*/
|
||||
private Admin processAdmin;
|
||||
|
||||
}
|
||||
|
||||
@@ -8,13 +8,13 @@ import java.util.*;
|
||||
@Data
|
||||
public class SystemExceptionLogVO {
|
||||
|
||||
@ApiModelProperty(value = "编号", required = true)
|
||||
@ApiModelProperty(value = "编号", required = true, example = "1")
|
||||
private Integer id;
|
||||
@ApiModelProperty(value = "用户编号")
|
||||
@ApiModelProperty(value = "用户编号", example = "1024")
|
||||
private Integer userId;
|
||||
@ApiModelProperty(value = "用户类型")
|
||||
@ApiModelProperty(value = "用户类型", example = "1")
|
||||
private Integer userType;
|
||||
@ApiModelProperty(value = "链路追踪编", required = true)
|
||||
@ApiModelProperty(value = "链路追踪编号", example = "89aca178-a370-411c-ae02-3f0d672be4ab")
|
||||
private String traceId;
|
||||
@ApiModelProperty(value = "应用名", required = true, example = "user-shop-application")
|
||||
private String applicationName;
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
package cn.iocoder.mall.managementweb.convert.systemlog;
|
||||
|
||||
import cn.iocoder.common.framework.vo.PageResult;
|
||||
import cn.iocoder.mall.managementweb.controller.systemlog.vo.SystemExceptionLogDetailVO;
|
||||
import cn.iocoder.mall.managementweb.controller.systemlog.vo.SystemExceptionLogVO;
|
||||
import cn.iocoder.mall.systemservice.rpc.admin.vo.AdminVO;
|
||||
import cn.iocoder.mall.systemservice.rpc.systemlog.dto.SystemExceptionLogPageDTO;
|
||||
import cn.iocoder.mall.systemservice.rpc.systemlog.dto.SystemExceptionLogProcessDTO;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
@@ -15,4 +18,10 @@ public interface SystemExceptionLogConvert {
|
||||
|
||||
PageResult<SystemExceptionLogVO> convertPage(PageResult<cn.iocoder.mall.systemservice.rpc.systemlog.vo.SystemExceptionLogVO> page);
|
||||
|
||||
SystemExceptionLogDetailVO convert(cn.iocoder.mall.systemservice.rpc.systemlog.vo.SystemExceptionLogVO bean);
|
||||
|
||||
SystemExceptionLogDetailVO.Admin convert(AdminVO bean);
|
||||
|
||||
SystemExceptionLogProcessDTO convert(cn.iocoder.mall.managementweb.controller.systemlog.dto.SystemExceptionLogProcessDTO bean);
|
||||
|
||||
}
|
||||
|
||||
@@ -18,10 +18,13 @@ import cn.iocoder.mall.systemservice.rpc.permission.RoleRpc;
|
||||
import cn.iocoder.mall.systemservice.rpc.permission.vo.RoleVO;
|
||||
import org.apache.dubbo.config.annotation.Reference;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import java.util.*;
|
||||
|
||||
@Service
|
||||
@Validated
|
||||
public class AdminManager {
|
||||
|
||||
@Reference(version = "${dubbo.consumer.AdminRpc.version}", validation = "false")
|
||||
@@ -104,7 +107,7 @@ public class AdminManager {
|
||||
updateAdminResult.checkError();
|
||||
}
|
||||
|
||||
public void updateAdminStatus(AdminUpdateStatusDTO updateStatusDTO) {
|
||||
public void updateAdminStatus(@Valid AdminUpdateStatusDTO updateStatusDTO) {
|
||||
CommonResult<Boolean> updateAdminResult = adminRpc.updateAdmin(AdminConvert.INSTANCE.convert(updateStatusDTO));
|
||||
updateAdminResult.checkError();
|
||||
}
|
||||
|
||||
@@ -3,9 +3,12 @@ package cn.iocoder.mall.managementweb.manager.systemlog;
|
||||
import cn.iocoder.common.framework.vo.CommonResult;
|
||||
import cn.iocoder.common.framework.vo.PageResult;
|
||||
import cn.iocoder.mall.managementweb.controller.systemlog.dto.SystemExceptionLogPageDTO;
|
||||
import cn.iocoder.mall.managementweb.controller.systemlog.dto.SystemExceptionLogProcessDTO;
|
||||
import cn.iocoder.mall.managementweb.controller.systemlog.vo.SystemExceptionLogDetailVO;
|
||||
import cn.iocoder.mall.managementweb.controller.systemlog.vo.SystemExceptionLogVO;
|
||||
import cn.iocoder.mall.managementweb.convert.systemlog.SystemExceptionLogConvert;
|
||||
import cn.iocoder.mall.systemservice.rpc.admin.AdminRpc;
|
||||
import cn.iocoder.mall.systemservice.rpc.admin.vo.AdminVO;
|
||||
import cn.iocoder.mall.systemservice.rpc.systemlog.SystemExceptionLogRpc;
|
||||
import org.apache.dubbo.config.annotation.Reference;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -16,8 +19,10 @@ import org.springframework.stereotype.Service;
|
||||
@Service
|
||||
public class SystemExceptionLogManager {
|
||||
|
||||
@Reference(version = "$ {dubbo.consumer.SystemExceptionLogRpc.version}", validation = "false")
|
||||
@Reference(version = "${dubbo.consumer.SystemExceptionLogRpc.version}", validation = "false")
|
||||
private SystemExceptionLogRpc systemExceptionLogRpc;
|
||||
@Reference(version = "${dubbo.consumer.AdminRpc.version}", validation = "false")
|
||||
private AdminRpc adminRpc;
|
||||
|
||||
/**
|
||||
* 获得系统异常日志
|
||||
@@ -26,11 +31,21 @@ public class SystemExceptionLogManager {
|
||||
* @return 系统异常日志
|
||||
*/
|
||||
public SystemExceptionLogDetailVO getSystemExceptionLogDetail(Integer systemExceptionLogId) {
|
||||
// 获得系统异常明细
|
||||
CommonResult<cn.iocoder.mall.systemservice.rpc.systemlog.vo.SystemExceptionLogVO> getSystemExceptionLogResult
|
||||
= systemExceptionLogRpc.getSystemExceptionLog(systemExceptionLogId);
|
||||
getSystemExceptionLogResult.checkError();
|
||||
// return SystemExceptionLogConvert.INSTANCE.convert(getSystemExceptionLogResult.getData());
|
||||
return null;
|
||||
SystemExceptionLogDetailVO logDetailVO = SystemExceptionLogConvert.INSTANCE.convert(getSystemExceptionLogResult.getData());
|
||||
// 拼接处理管理员信息
|
||||
if (getSystemExceptionLogResult.getData().getProcessAdminId() != null) {
|
||||
CommonResult<AdminVO> adminVOResult = adminRpc.getAdmin(getSystemExceptionLogResult.getData().getProcessAdminId());
|
||||
adminVOResult.checkError();
|
||||
if (adminVOResult.getData() != null) {
|
||||
SystemExceptionLogDetailVO.Admin admin = SystemExceptionLogConvert.INSTANCE.convert(adminVOResult.getData());
|
||||
logDetailVO.setProcessAdmin(admin);
|
||||
}
|
||||
}
|
||||
return logDetailVO;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -46,4 +61,16 @@ public class SystemExceptionLogManager {
|
||||
return SystemExceptionLogConvert.INSTANCE.convertPage(pageSystemExceptionLogResult.getData());
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理系统异常日志
|
||||
*
|
||||
* @param processAdminId 处理管理员编号
|
||||
* @param processDTO 处理系统异常日志 DTO
|
||||
*/
|
||||
public void processSystemExceptionLog(Integer processAdminId, SystemExceptionLogProcessDTO processDTO) {
|
||||
CommonResult<Boolean> processSystemExceptionLogResult = systemExceptionLogRpc.processSystemExceptionLog(
|
||||
SystemExceptionLogConvert.INSTANCE.convert(processDTO).setProcessAdminId(processAdminId));
|
||||
processSystemExceptionLogResult.checkError();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user