系统异常日志模块的迁移

pull/3/head
YunaiV 2020-07-16 09:04:18 +08:00
parent 42e30bf380
commit 02dda60e60
35 changed files with 814 additions and 428 deletions

View File

@ -22,7 +22,7 @@ public class AdminDemoInterceptor extends HandlerInterceptorAdapter {
// 当 Admin 编号等于 0 时,约定为演示账号
if (Objects.equals(AdminSecurityContextHolder.getAdminId(), 0)
&& request.getMethod().equalsIgnoreCase(HttpMethod.POST.toString())) {
throw ServiceExceptionUtil.exception(SystemErrorCodeEnum.AUTHORIZATION_DEMO_PERMISSION_DENY);
throw ServiceExceptionUtil.exception(SystemErrorCodeEnum.PERMISSION_DEMO_PERMISSION_DENY);
}
return true;
}

View File

@ -0,0 +1,46 @@
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.vo.SystemExceptionLogDetailVO;
import cn.iocoder.mall.managementweb.controller.systemlog.vo.SystemExceptionLogVO;
import cn.iocoder.mall.managementweb.manager.systemlog.SystemExceptionLogManager;
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 static cn.iocoder.common.framework.vo.CommonResult.success;
/**
* Controller
*/
@RestController
@RequestMapping("/system-exception-log")
@Api(tags = "系统异常日志")
@Validated
public class SystemExceptionLogController {
@Autowired
private SystemExceptionLogManager systemExceptionLogManager;
@GetMapping("/get")
@ApiOperation("获得系统异常日志明细")
@ApiImplicitParam(name = "logId", value = "系统异常日志编号", required = true)
public CommonResult<SystemExceptionLogDetailVO> getSystemExceptionLogDetail(@RequestParam("logId") Integer logId) {
return success(systemExceptionLogManager.getSystemExceptionLogDetail(logId));
}
@GetMapping("/page")
@ApiOperation("获得系统异常日志分页")
public CommonResult<PageResult<SystemExceptionLogVO>> pageSystemExceptionLog(SystemExceptionLogPageDTO pageDTO) {
return success(systemExceptionLogManager.pageSystemExceptionLog(pageDTO));
}
}

View File

@ -9,11 +9,11 @@ import lombok.Data;
@Data
public class SystemAccessLogPageDTO extends PageParam {
@ApiModelProperty(value = "用户编号")
@ApiModelProperty(value = "用户编号", example = "1")
private Integer userId;
@ApiModelProperty(value = "用户类型")
@ApiModelProperty(value = "用户类型", example = "2")
private Integer userType;
@ApiModelProperty(value = "应用名", required = true)
@ApiModelProperty(value = "应用名", example = "xxx-service-application")
private String applicationName;
}

View File

@ -0,0 +1,21 @@
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;
@ApiModel("系统异常日志分页 DTO")
@Data
public class SystemExceptionLogPageDTO extends PageParam {
@ApiModelProperty(value = "用户编号", example = "1")
private Integer userId;
@ApiModelProperty(value = "用户类型", example = "2")
private Integer userType;
@ApiModelProperty(value = "应用名", example = "xxx-service-application")
private String applicationName;
@ApiModelProperty(value = "处理状态", notes = "对应 SystemExceptionLogProcessStatusEnum 枚举类", example = "1")
private Integer processStatus;
}

View File

@ -0,0 +1,4 @@
package cn.iocoder.mall.managementweb.controller.systemlog.vo;
public class SystemExceptionLogDetailVO {
}

View File

@ -0,0 +1,58 @@
package cn.iocoder.mall.managementweb.controller.systemlog.vo;
import lombok.*;
import io.swagger.annotations.*;
import java.util.*;
@ApiModel("系统异常日志 VO")
@Data
public class SystemExceptionLogVO {
@ApiModelProperty(value = "编号", required = true)
private Integer id;
@ApiModelProperty(value = "用户编号")
private Integer userId;
@ApiModelProperty(value = "用户类型")
private Integer userType;
@ApiModelProperty(value = "链路追踪编", required = true)
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 = "处理管理员编号", example = "1024")
private Integer processAdminId;
@ApiModelProperty(value = "创建时间", required = true)
private Date createTime;
}

View File

@ -0,0 +1,18 @@
package cn.iocoder.mall.managementweb.convert.systemlog;
import cn.iocoder.common.framework.vo.PageResult;
import cn.iocoder.mall.managementweb.controller.systemlog.vo.SystemExceptionLogVO;
import cn.iocoder.mall.systemservice.rpc.systemlog.dto.SystemExceptionLogPageDTO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
@Mapper
public interface SystemExceptionLogConvert {
SystemExceptionLogConvert INSTANCE = Mappers.getMapper(SystemExceptionLogConvert.class);
SystemExceptionLogPageDTO convert(cn.iocoder.mall.managementweb.controller.systemlog.dto.SystemExceptionLogPageDTO bean);
PageResult<SystemExceptionLogVO> convertPage(PageResult<cn.iocoder.mall.systemservice.rpc.systemlog.vo.SystemExceptionLogVO> page);
}

View File

@ -0,0 +1,49 @@
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.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.systemlog.SystemExceptionLogRpc;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.stereotype.Service;
/**
* Manager
*/
@Service
public class SystemExceptionLogManager {
@Reference(version = "$ {dubbo.consumer.SystemExceptionLogRpc.version}", validation = "false")
private SystemExceptionLogRpc systemExceptionLogRpc;
/**
*
*
* @param systemExceptionLogId
* @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;
}
/**
*
*
* @param pageDTO
* @return
*/
public PageResult<SystemExceptionLogVO> pageSystemExceptionLog(SystemExceptionLogPageDTO pageDTO) {
CommonResult<PageResult<cn.iocoder.mall.systemservice.rpc.systemlog.vo.SystemExceptionLogVO>> pageSystemExceptionLogResult
= systemExceptionLogRpc.pageSystemExceptionLog(SystemExceptionLogConvert.INSTANCE.convert(pageDTO));
pageSystemExceptionLogResult.checkError();
return SystemExceptionLogConvert.INSTANCE.convertPage(pageSystemExceptionLogResult.getData());
}
}

View File

@ -69,15 +69,20 @@ public enum SystemErrorCodeEnum implements ServiceExceptionUtil.Enumerable<Syste
DEPARTMENT_PARENT_ERROR(1002007005, "不能设置自己为父资源"),
DEPARTMENT_EXISTS_ADMIN(1002007006, "部门中存在员工,无法删除"),
// ========== 权模块 1002008000 ==========
AUTHORIZATION_PERMISSION_DENY(1002008001, "没有该操作权限"),
AUTHORIZATION_DEMO_PERMISSION_DENY(1002008002, "演示账号暂不允许写操作。欢迎加入我们的交流群http://t.cn/EKEr5WE"),
AUTHORIZATION_ROLE_ASSIGN_RESOURCE_NOT_EXISTS(1002008004, "分配角色资源时,有资源不存在"),
// ========== 模块 1002008000 ==========
PERMISSION_DENY(1002008001, "没有该操作权限"),
PERMISSION_DEMO_PERMISSION_DENY(1002008002, "演示账号暂不允许写操作。欢迎加入我们的交流群http://t.cn/EKEr5WE"),
PERMISSION_ROLE_ASSIGN_RESOURCE_NOT_EXISTS(1002008004, "分配角色资源时,有资源不存在"),
// ========== 错误码模块 1002009000 ==========
ERROR_CODE_NOT_EXISTS(1002009000, "错误码不存在"),
ERROR_CODE_DUPLICATE(1002009001, "已经存在编码为【{}}】的错误码"),
ERROR_CAN_NOT_UPDATE_SYSTEM_TYPE_ERROR(1002004003, "不能修改类型为系统内置的错误码"),
// ========== 系统异常日志模块 1002010000 ==========
SYSTEM_EXCEPTION_LOG_NOT_FOUND(1002010000, "系统异常日志不存在"),
SYSTEM_EXCEPTION_LOG_PROCESSED(1002010001, "系统异常日志已处理"),
;

View File

@ -0,0 +1,45 @@
package cn.iocoder.mall.systemservice.enums.systemlog;
import cn.iocoder.common.framework.core.IntArrayValuable;
import java.util.Arrays;
/**
*
*/
public enum SystemExceptionLogProcessStatusEnum implements IntArrayValuable {
INIT(0, "未处理"),
DONE(1, "已处理"),
IGNORE(2, "已忽略");
public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(SystemExceptionLogProcessStatusEnum::getStatus).toArray();
/**
*
*/
private final Integer status;
/**
*
*/
private final String name;
SystemExceptionLogProcessStatusEnum(Integer status, String name) {
this.status = status;
this.name = name;
}
public Integer getStatus() {
return status;
}
public String getName() {
return name;
}
@Override
public int[] array() {
return ARRAYS;
}
}

View File

@ -1,10 +1,47 @@
package cn.iocoder.mall.systemservice.rpc.systemlog;
import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.common.framework.vo.PageResult;
import cn.iocoder.mall.systemservice.rpc.systemlog.dto.SystemExceptionLogCreateDTO;
import cn.iocoder.mall.systemservice.rpc.systemlog.dto.SystemExceptionLogPageDTO;
import cn.iocoder.mall.systemservice.rpc.systemlog.dto.SystemExceptionLogProcessDTO;
import cn.iocoder.mall.systemservice.rpc.systemlog.vo.SystemExceptionLogVO;
/**
* Rpc
*/
public interface SystemExceptionLogRpc {
/**
*
*
* @param createDTO DTO
* @return
*/
CommonResult<Boolean> createSystemExceptionLog(SystemExceptionLogCreateDTO createDTO);
/**
*
*
* @param systemExceptionLogId
* @return
*/
CommonResult<SystemExceptionLogVO> getSystemExceptionLog(Integer systemExceptionLogId);
/**
*
*
* @param pageDTO
* @return
*/
CommonResult<PageResult<SystemExceptionLogVO>> pageSystemExceptionLog(SystemExceptionLogPageDTO pageDTO);
/**
*
*
* @param processDTO DTO
* @return
*/
CommonResult<Boolean> processSystemExceptionLog(SystemExceptionLogProcessDTO processDTO);
}

View File

@ -0,0 +1,35 @@
package cn.iocoder.mall.systemservice.rpc.systemlog.dto;
import cn.iocoder.common.framework.vo.PageParam;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
/**
* DTO
*/
@Data
@EqualsAndHashCode(callSuper = true)
@Accessors(chain = true)
public class SystemExceptionLogPageDTO extends PageParam {
/**
*
*/
private Integer userId;
/**
*
*/
private Integer userType;
/**
*
*
* spring.application.name
*/
private String applicationName;
/**
*
*/
private Integer processStatus;
}

View File

@ -0,0 +1,29 @@
package cn.iocoder.mall.systemservice.rpc.systemlog.dto;
import cn.iocoder.common.framework.vo.PageParam;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
/**
* DTO
*/
@Data
@EqualsAndHashCode(callSuper = true)
@Accessors(chain = true)
public class SystemExceptionLogProcessDTO extends PageParam {
/**
*
*/
private Integer logId;
/**
*
*/
private Integer processStatus;
/**
*
*/
private Integer processAdminId;
}

View File

@ -0,0 +1,125 @@
package cn.iocoder.mall.systemservice.rpc.systemlog.vo;
import lombok.Data;
import lombok.experimental.Accessors;
import java.io.Serializable;
import java.util.Date;
/**
* VO
*/
@Data
@Accessors(chain = true)
public class SystemExceptionLogVO implements Serializable {
/**
*
*/
private Integer id;
/**
*
*/
private Integer userId;
/**
*
*/
private Integer userType;
/**
*
*
* 访logger
*/
private String traceId;
/**
*
*
* spring.application.name
*/
private String applicationName;
/**
* 访
*/
private String uri;
/**
*
*/
private String queryString;
/**
* http
*/
private String method;
/**
* userAgent
*/
private String userAgent;
/**
* ip
*/
private String ip;
/**
*
*/
private Date exceptionTime;
/**
*
*
* {@link Throwable#getClass()}
*/
private String exceptionName;
/**
*
*
* {@link cn.iocoder.common.framework.util.ExceptionUtil#getMessage(Throwable)}
*/
private String exceptionMessage;
/**
*
*
* {@link cn.iocoder.common.framework.util.ExceptionUtil#getRootCauseMessage(Throwable)}
*/
private String exceptionRootCauseMessage;
/**
*
*
* {@link cn.iocoder.common.framework.util.ExceptionUtil#getServiceException(Exception)}
*/
private String exceptionStackTrace;
/**
*
*
* {@link StackTraceElement#getClassName()}
*/
private String exceptionClassName;
/**
*
*
* {@link StackTraceElement#getFileName()}
*/
private String exceptionFileName;
/**
*
*
* {@link StackTraceElement#getMethodName()}
*/
private String exceptionMethodName;
/**
*
*
* {@link StackTraceElement#getLineNumber()}
*/
private Integer exceptionLineNumber;
/**
*
*/
private Integer processStatus;
/**
*
*/
private Date processTime;
/**
*
*/
private Integer processAdminId;
}

View File

@ -1,8 +1,14 @@
package cn.iocoder.mall.systemservice.convert.systemlog;
import cn.iocoder.common.framework.vo.PageResult;
import cn.iocoder.mall.systemservice.dal.mysql.dataobject.systemlog.SystemExceptionLogDO;
import cn.iocoder.mall.systemservice.rpc.systemlog.dto.SystemExceptionLogCreateDTO;
import cn.iocoder.mall.systemservice.rpc.systemlog.dto.SystemExceptionLogPageDTO;
import cn.iocoder.mall.systemservice.rpc.systemlog.vo.SystemExceptionLogVO;
import cn.iocoder.mall.systemservice.service.systemlog.bo.SystemExceptionLogBO;
import cn.iocoder.mall.systemservice.service.systemlog.bo.SystemExceptionLogCreateBO;
import cn.iocoder.mall.systemservice.service.systemlog.bo.SystemExceptionLogPageBO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
@ -15,4 +21,14 @@ public interface SystemExceptionLogConvert {
SystemExceptionLogCreateBO convert(SystemExceptionLogCreateDTO bean);
PageResult<SystemExceptionLogBO> convertPage(IPage<SystemExceptionLogDO> page);
SystemExceptionLogBO convert(SystemExceptionLogDO bean);
SystemExceptionLogVO convert(SystemExceptionLogBO bean);
SystemExceptionLogPageBO convert(SystemExceptionLogPageDTO bean);
PageResult<SystemExceptionLogVO> convertPage(PageResult<SystemExceptionLogBO> page);
}

View File

@ -2,6 +2,8 @@ package cn.iocoder.mall.systemservice.dal.mysql.dataobject.systemlog;
import cn.iocoder.common.framework.enums.UserTypeEnum;
import cn.iocoder.mall.mybatis.dataobject.BaseDO;
import cn.iocoder.mall.systemservice.dal.mysql.dataobject.admin.AdminDO;
import cn.iocoder.mall.systemservice.enums.systemlog.SystemExceptionLogProcessStatusEnum;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import lombok.EqualsAndHashCode;
@ -117,4 +119,21 @@ public class SystemExceptionLogDO extends BaseDO {
*/
private Integer exceptionLineNumber;
/**
*
*
* {@link SystemExceptionLogProcessStatusEnum}
*/
private Integer processStatus;
/**
*
*/
private Date processTime;
/**
*
*
* {@link AdminDO#getId()}
*/
private Integer processAdminId;
}

View File

@ -1,10 +1,24 @@
package cn.iocoder.mall.systemservice.dal.mysql.mapper.systemlog;
import cn.iocoder.mall.mybatis.query.QueryWrapperX;
import cn.iocoder.mall.systemservice.dal.mysql.dataobject.systemlog.SystemExceptionLogDO;
import cn.iocoder.mall.systemservice.service.systemlog.bo.SystemExceptionLogPageBO;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.stereotype.Repository;
@Repository
public interface SystemExceptionLogMapper extends BaseMapper<SystemExceptionLogDO> {
default IPage<SystemExceptionLogDO> selectPage(SystemExceptionLogPageBO pageBO) {
return selectPage(new Page<>(pageBO.getPageNo(), pageBO.getPageSize()),
new QueryWrapperX<SystemExceptionLogDO>()
.eqIfPresent("user_id", pageBO.getUserId())
.eqIfPresent("user_type", pageBO.getUserType())
.eqIfPresent("application_name", pageBO.getApplicationName())
.eqIfPresent("processStatus", pageBO.getProcessStatus())
.orderByDesc("start_time"));
}
}

View File

@ -18,7 +18,7 @@ import java.util.Collections;
import java.util.Map;
import java.util.Set;
import static cn.iocoder.mall.systemservice.enums.SystemErrorCodeEnum.AUTHORIZATION_PERMISSION_DENY;
import static cn.iocoder.mall.systemservice.enums.SystemErrorCodeEnum.PERMISSION_DENY;
/**
* Manager
@ -98,7 +98,7 @@ public class PermissionManager {
// 查询管理员拥有的角色关联数据
Set<Integer> roleIds = permissionService.listAdminRoleIds(checkDTO.getAdminId());
if (CollectionUtil.isEmpty(roleIds)) { // 如果没有角色,默认无法访问
throw ServiceExceptionUtil.exception(AUTHORIZATION_PERMISSION_DENY);
throw ServiceExceptionUtil.exception(PERMISSION_DENY);
}
// 判断是否为超管。若是超管,默认有所有权限
if (roleService.hasSuperAdmin(roleIds)) {

View File

@ -1,8 +1,13 @@
package cn.iocoder.mall.systemservice.manager.systemlog;
import cn.iocoder.common.framework.vo.PageResult;
import cn.iocoder.mall.systemservice.convert.systemlog.SystemExceptionLogConvert;
import cn.iocoder.mall.systemservice.rpc.systemlog.dto.SystemExceptionLogCreateDTO;
import cn.iocoder.mall.systemservice.rpc.systemlog.dto.SystemExceptionLogPageDTO;
import cn.iocoder.mall.systemservice.rpc.systemlog.dto.SystemExceptionLogProcessDTO;
import cn.iocoder.mall.systemservice.rpc.systemlog.vo.SystemExceptionLogVO;
import cn.iocoder.mall.systemservice.service.systemlog.SystemExceptionLogService;
import cn.iocoder.mall.systemservice.service.systemlog.bo.SystemExceptionLogBO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@ -13,10 +18,47 @@ import org.springframework.stereotype.Service;
public class SystemExceptionLogManager {
@Autowired
private SystemExceptionLogService systemLogService;
private SystemExceptionLogService systemExceptionLogService;
/**
*
*
* @param createDTO DTO
*/
public void createSystemExceptionLog(SystemExceptionLogCreateDTO createDTO) {
systemLogService.createSystemExceptionLog(SystemExceptionLogConvert.INSTANCE.convert(createDTO));
systemExceptionLogService.createSystemExceptionLog(SystemExceptionLogConvert.INSTANCE.convert(createDTO));
}
/**
*
*
* @param systemExceptionLogId
* @return
*/
public SystemExceptionLogVO getSystemExceptionLog(Integer systemExceptionLogId) {
SystemExceptionLogBO systemExceptionLogBO = systemExceptionLogService.getSystemExceptionLog(systemExceptionLogId);
return SystemExceptionLogConvert.INSTANCE.convert(systemExceptionLogBO);
}
/**
*
*
* @param pageDTO
* @return
*/
public PageResult<SystemExceptionLogVO> pageSystemExceptionLog(SystemExceptionLogPageDTO pageDTO) {
PageResult<SystemExceptionLogBO> pageResultBO = systemExceptionLogService.pageSystemExceptionLog(SystemExceptionLogConvert.INSTANCE.convert(pageDTO));
return SystemExceptionLogConvert.INSTANCE.convertPage(pageResultBO);
}
/**
*
*
* @param processDTO DTO
*/
public void processSystemExceptionLog(SystemExceptionLogProcessDTO processDTO) {
systemExceptionLogService.processSystemExceptionLog(processDTO.getLogId(), processDTO.getProcessAdminId(),
processDTO.getProcessStatus());
}
}

View File

@ -1,11 +1,17 @@
package cn.iocoder.mall.systemservice.rpc.systemlog;
import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.common.framework.vo.PageResult;
import cn.iocoder.mall.systemservice.manager.systemlog.SystemExceptionLogManager;
import cn.iocoder.mall.systemservice.rpc.systemlog.dto.SystemExceptionLogCreateDTO;
import cn.iocoder.mall.systemservice.rpc.systemlog.dto.SystemExceptionLogPageDTO;
import cn.iocoder.mall.systemservice.rpc.systemlog.dto.SystemExceptionLogProcessDTO;
import cn.iocoder.mall.systemservice.rpc.systemlog.vo.SystemExceptionLogVO;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import static cn.iocoder.common.framework.vo.CommonResult.success;
@Service(version = "${dubbo.provider.SystemExceptionLogRpc.version}", validation = "false")
public class SystemExceptionLogRpcImpl implements SystemExceptionLogRpc {
@ -15,6 +21,22 @@ public class SystemExceptionLogRpcImpl implements SystemExceptionLogRpc {
@Override
public CommonResult<Boolean> createSystemExceptionLog(SystemExceptionLogCreateDTO createDTO) {
systemExceptionLogManager.createSystemExceptionLog(createDTO);
return success(true);
}
@Override
public CommonResult<SystemExceptionLogVO> getSystemExceptionLog(Integer systemExceptionLogId) {
return success(systemExceptionLogManager.getSystemExceptionLog(systemExceptionLogId));
}
@Override
public CommonResult<PageResult<SystemExceptionLogVO>> pageSystemExceptionLog(SystemExceptionLogPageDTO pageDTO) {
return success(systemExceptionLogManager.pageSystemExceptionLog(pageDTO));
}
@Override
public CommonResult<Boolean> processSystemExceptionLog(SystemExceptionLogProcessDTO processDTO) {
systemExceptionLogManager.processSystemExceptionLog(processDTO);
return CommonResult.success(true);
}

View File

@ -68,7 +68,7 @@ public class PermissionService {
if (!CollectionUtils.isEmpty(resourceIds)) {
int dbResourceSize = resourceMapper.selectCountByIdsAndType(resourceIds, null);
if (resourceIds.size() != dbResourceSize) {
throw ServiceExceptionUtil.exception(AUTHORIZATION_ROLE_ASSIGN_RESOURCE_NOT_EXISTS);
throw ServiceExceptionUtil.exception(PERMISSION_ROLE_ASSIGN_RESOURCE_NOT_EXISTS);
}
}
// TODO 芋艿,这里先简单实现。即方式是,删除老的分配的资源关系,然后添加新的分配的资源关系
@ -150,13 +150,13 @@ public class PermissionService {
// 权限验证
List<RoleResourceDO> roleResourceDOs = roleResourceMapper.selectListByResourceIds(permissionIds);
if (CollectionUtil.isEmpty(roleResourceDOs)) { // 资源未授予任何角色,必然权限验证不通过
throw ServiceExceptionUtil.exception(AUTHORIZATION_PERMISSION_DENY);
throw ServiceExceptionUtil.exception(PERMISSION_DENY);
}
Map<Integer, List<Integer>> resourceRoleMap = CollectionUtils.convertMultiMap(roleResourceDOs,
RoleResourceDO::getResourceId, RoleResourceDO::getRoleId);
for (Map.Entry<Integer, List<Integer>> entry : resourceRoleMap.entrySet()) {
if (!CollectionUtil.containsAny(roleIds, entry.getValue())) { // 所以有任一不满足,就验证失败,抛出异常
throw ServiceExceptionUtil.exception(AUTHORIZATION_PERMISSION_DENY);
throw ServiceExceptionUtil.exception(PERMISSION_DENY);
}
}
}

View File

@ -1,12 +1,21 @@
package cn.iocoder.mall.systemservice.service.systemlog;
import cn.iocoder.common.framework.util.ServiceExceptionUtil;
import cn.iocoder.common.framework.vo.PageResult;
import cn.iocoder.mall.systemservice.convert.systemlog.SystemExceptionLogConvert;
import cn.iocoder.mall.systemservice.dal.mysql.dataobject.systemlog.SystemExceptionLogDO;
import cn.iocoder.mall.systemservice.dal.mysql.mapper.systemlog.SystemExceptionLogMapper;
import cn.iocoder.mall.systemservice.enums.systemlog.SystemExceptionLogProcessStatusEnum;
import cn.iocoder.mall.systemservice.service.systemlog.bo.SystemExceptionLogBO;
import cn.iocoder.mall.systemservice.service.systemlog.bo.SystemExceptionLogCreateBO;
import cn.iocoder.mall.systemservice.service.systemlog.bo.SystemExceptionLogPageBO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import static cn.iocoder.mall.systemservice.enums.SystemErrorCodeEnum.SYSTEM_EXCEPTION_LOG_NOT_FOUND;
import static cn.iocoder.mall.systemservice.enums.SystemErrorCodeEnum.SYSTEM_EXCEPTION_LOG_PROCESSED;
/**
* Service
*/
@ -16,9 +25,51 @@ public class SystemExceptionLogService {
@Autowired
private SystemExceptionLogMapper systemExceptionLogMapper;
/**
*
*
* @param createBO BO
*/
public void createSystemExceptionLog(SystemExceptionLogCreateBO createBO) {
SystemExceptionLogDO logDO = SystemExceptionLogConvert.INSTANCE.convert(createBO);
logDO.setProcessStatus(SystemExceptionLogProcessStatusEnum.INIT.getStatus());
systemExceptionLogMapper.insert(logDO);
}
/**
*
*
* @param logId
* @param processAdminId
* @param processStatus
*/
public void processSystemExceptionLog(Integer logId, Integer processAdminId, Integer processStatus) {
SystemExceptionLogDO logDO = systemExceptionLogMapper.selectById(logId);
if (logDO == null) {
throw ServiceExceptionUtil.exception(SYSTEM_EXCEPTION_LOG_NOT_FOUND);
}
if (!SystemExceptionLogProcessStatusEnum.INIT.getStatus().equals(logDO.getProcessStatus())) {
throw ServiceExceptionUtil.exception(SYSTEM_EXCEPTION_LOG_PROCESSED);
}
// 标记处理
SystemExceptionLogDO updateObj = new SystemExceptionLogDO().setId(logId)
.setProcessAdminId(processAdminId).setProcessStatus(processStatus);
systemExceptionLogMapper.updateById(updateObj);
}
/**
*
*
* @param pageBO
* @return
*/
public PageResult<SystemExceptionLogBO> pageSystemExceptionLog(SystemExceptionLogPageBO pageBO) {
IPage<SystemExceptionLogDO> systemExceptionLogDOPage = systemExceptionLogMapper.selectPage(pageBO);
return SystemExceptionLogConvert.INSTANCE.convertPage(systemExceptionLogDOPage);
}
public SystemExceptionLogBO getSystemExceptionLog(Integer logId) {
SystemExceptionLogDO logDO = systemExceptionLogMapper.selectById(logId);
return SystemExceptionLogConvert.INSTANCE.convert(logDO);
}
}

View File

@ -0,0 +1,128 @@
package cn.iocoder.mall.systemservice.service.systemlog.bo;
import lombok.Data;
import lombok.experimental.Accessors;
import java.util.Date;
/**
* BO
*/
@Data
@Accessors(chain = true)
public class SystemExceptionLogBO {
/**
*
*/
private Integer id;
/**
*
*/
private Integer userId;
/**
*
*/
private Integer userType;
/**
*
*
* 访logger
*/
private String traceId;
/**
*
*
* spring.application.name
*/
private String applicationName;
/**
* 访
*/
private String uri;
/**
*
*/
private String queryString;
/**
* http
*/
private String method;
/**
* userAgent
*/
private String userAgent;
/**
* ip
*/
private String ip;
/**
*
*/
private Date exceptionTime;
/**
*
*
* {@link Throwable#getClass()}
*/
private String exceptionName;
/**
*
*
* {@link cn.iocoder.common.framework.util.ExceptionUtil#getMessage(Throwable)}
*/
private String exceptionMessage;
/**
*
*
* {@link cn.iocoder.common.framework.util.ExceptionUtil#getRootCauseMessage(Throwable)}
*/
private String exceptionRootCauseMessage;
/**
*
*
* {@link cn.iocoder.common.framework.util.ExceptionUtil#getServiceException(Exception)}
*/
private String exceptionStackTrace;
/**
*
*
* {@link StackTraceElement#getClassName()}
*/
private String exceptionClassName;
/**
*
*
* {@link StackTraceElement#getFileName()}
*/
private String exceptionFileName;
/**
*
*
* {@link StackTraceElement#getMethodName()}
*/
private String exceptionMethodName;
/**
*
*
* {@link StackTraceElement#getLineNumber()}
*/
private Integer exceptionLineNumber;
/**
*
*/
private Integer processStatus;
/**
*
*/
private Date processTime;
/**
*
*/
private Integer processAdminId;
/**
*
*/
private Date createTime;
}

View File

@ -0,0 +1,35 @@
package cn.iocoder.mall.systemservice.service.systemlog.bo;
import cn.iocoder.common.framework.vo.PageParam;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
/**
* BO
*/
@Data
@EqualsAndHashCode(callSuper = true)
@Accessors(chain = true)
public class SystemExceptionLogPageBO extends PageParam {
/**
*
*/
private Integer userId;
/**
*
*/
private Integer userType;
/**
*
*
* spring.application.name
*/
private String applicationName;
/**
*
*/
private Integer processStatus;
}

View File

@ -1,41 +0,0 @@
package cn.iocoder.mall.system.api.bo.systemlog;
import lombok.Data;
import lombok.experimental.Accessors;
import java.io.Serializable;
import java.util.Date;
/**
* @author:ycjx
* @descriptio
* @create:2019-06-23 17:26
*/
@Data
@Accessors(chain = true)
public class AccessLogBO implements Serializable {
private String traceId;
private Integer userId;
private Integer userType;
private String applicationName;
private String uri;
private String queryString;
private String method;
private String userAgent;
private String ip;
private Date startTime;
private Integer responseTime;
private Integer errorCode;
}

View File

@ -1,27 +0,0 @@
package cn.iocoder.mall.system.api.bo.systemlog;
import lombok.Data;
import lombok.experimental.Accessors;
import java.io.Serializable;
import java.util.List;
/**
* @author:ycjx
* @descriptio
* @create:2019-06-23 17:26
*/
@Data
@Accessors(chain = true)
public class AccessLogPageBO implements Serializable {
/**
*
*/
private List<AccessLogBO> list;
/**
*
*/
private Integer total;
}

View File

@ -1,36 +0,0 @@
package cn.iocoder.mall.system.api.dto.datadict;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
@ApiModel("数据字典添加 DTO")
@Data
@Accessors(chain = true)
public class DataDictAddDTO implements Serializable {
@ApiModelProperty(value = "大类枚举值", required = true, example = "gender")
@NotEmpty(message = "大类枚举值不能为空")
private String enumValue;
@ApiModelProperty(value = "小类数值", required = true, example = "1")
@NotEmpty(message = "小类数值不能为空")
private String value;
@ApiModelProperty(value = "展示名", required = true, example = "男")
@NotEmpty(message = "展示名不能为空")
private String displayName;
@ApiModelProperty(required = true, value = "排序值", example = "123")
@NotNull(message = "排序值不能为空")
private Integer sort;
@ApiModelProperty(value = "备注", example = "你猜我猜不猜")
private String memo;
}

View File

@ -1,41 +0,0 @@
package cn.iocoder.mall.system.api.dto.datadict;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
/**
* DTO
*/
@Data
@Accessors(chain = true)
public class DataDictUpdateDTO implements Serializable {
@ApiModelProperty(value = "数据字典编号", required = true, example = "1")
@NotNull(message = "数据字典编号不能为空")
private Integer id;
@ApiModelProperty(value = "大类枚举值", required = true, example = "gender")
@NotEmpty(message = "大类枚举值不能为空")
private String enumValue;
@ApiModelProperty(value = "小类数值", required = true, example = "1")
@NotEmpty(message = "小类数值不能为空")
private String value;
@ApiModelProperty(value = "展示名", required = true, example = "男")
@NotEmpty(message = "展示名不能为空")
private String displayName;
@ApiModelProperty(required = true, value = "排序值", example = "123")
@NotNull(message = "排序值不能为空")
private Integer sort;
@ApiModelProperty(value = "备注", example = "你猜我猜不猜")
private String memo;
}

View File

@ -1,28 +0,0 @@
package cn.iocoder.mall.system.api.dto.systemlog;
import lombok.Data;
import lombok.experimental.Accessors;
import javax.validation.constraints.NotNull;
/**
* @author:ycjx
* @descriptio
* @create:2019-06-23 16:53
*/
@Data
@Accessors(chain = true)
public class AccessLogPageDTO {
/**
* id
*/
private Integer userId;
@NotNull(message = "页码不能为空")
private Integer pageNo;
@NotNull(message = "每页条数不能为空")
private Integer pageSize;
}

View File

@ -1,31 +0,0 @@
package cn.iocoder.mall.admin.convert;
import cn.iocoder.common.framework.vo.PageResult;
import cn.iocoder.mall.system.api.bo.systemlog.AccessLogBO;
import cn.iocoder.mall.system.api.dto.systemlog.AccessLogAddDTO;
import cn.iocoder.mall.system.api.dto.systemlog.ExceptionLogAddDTO;
import cn.iocoder.mall.admin.dataobject.AccessLogDO;
import cn.iocoder.mall.admin.dataobject.ExceptionLogDO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers;
@Mapper
public interface AccessLogConvert {
AccessLogConvert INSTANCE = Mappers.getMapper(AccessLogConvert.class);
@Mappings({})
AccessLogDO convert(AccessLogAddDTO accessLogAddDTO);
@Mappings({})
ExceptionLogDO convert(ExceptionLogAddDTO exceptionLogAddDTO);
@Mappings({
@Mapping(source = "records", target = "list"),
})
PageResult<AccessLogBO> convert(IPage<AccessLogDO> page);
}

View File

@ -1,25 +0,0 @@
package cn.iocoder.mall.admin.convert;
import cn.iocoder.mall.system.api.bo.datadict.DataDictBO;
import cn.iocoder.mall.system.api.dto.datadict.DataDictAddDTO;
import cn.iocoder.mall.system.api.dto.datadict.DataDictUpdateDTO;
import cn.iocoder.mall.admin.dataobject.DataDictDO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import java.util.List;
@Mapper
public interface DataDictConvert {
DataDictConvert INSTANCE = Mappers.getMapper(DataDictConvert.class);
DataDictDO convert(DataDictAddDTO dataDictAddDTO);
DataDictDO convert(DataDictUpdateDTO dataDictUpdateDTO);
DataDictBO convert(DataDictDO dataDictDO);
List<DataDictBO> convert(List<DataDictDO> dataDictDOs);
}

View File

@ -1,15 +0,0 @@
package cn.iocoder.mall.system.application;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableAsync;
@SpringBootApplication(scanBasePackages = {"cn.iocoder.mall.system"})
@EnableAsync(proxyTargetClass = true)
public class SystemApplication {
public static void main(String[] args) {
SpringApplication.run(SystemApplication.class, args);
}
}

View File

@ -1,21 +0,0 @@
package cn.iocoder.mall.system.application.config;
import com.qiniu.util.Auth;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class QiniuConfiguration {
@Value("${qiniu.access-key}")
private String accessKey;
@Value("${qiniu.secret-key}")
private String secretKey;
@Bean
public Auth auth() {
return Auth.create(accessKey, secretKey);
}
}

View File

@ -1,114 +0,0 @@
package cn.iocoder.mall.system.application.controller.admins;
import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.common.framework.vo.PageResult;
import cn.iocoder.mall.system.api.DeptmentService;
import cn.iocoder.mall.system.api.bo.deptment.DeptmentBO;
import cn.iocoder.mall.system.api.constant.ResourceConstants;
import cn.iocoder.mall.system.api.dto.depetment.DeptmentAddDTO;
import cn.iocoder.mall.system.api.dto.depetment.DeptmentPageDTO;
import cn.iocoder.mall.system.api.dto.depetment.DeptmentUpdateDTO;
import cn.iocoder.mall.system.application.convert.DeptmentConvert;
import cn.iocoder.mall.system.application.vo.deptment.DeptmentVO;
import cn.iocoder.mall.system.sdk.context.AdminSecurityContextHolder;
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.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import static cn.iocoder.common.framework.vo.CommonResult.success;
/**
* Description:
*
* @author: zhenxianyimeng
* @date: 2019-06-14
* @time: 19:07
*/
@RestController
@RequestMapping("admins/dept")
@Api("部门模块")
public class DeptmentController {
@Autowired
private DeptmentService deptmentService;
@GetMapping("tree/all")
@ApiOperation(value = "根部门的部门树")
public CommonResult<List<DeptmentVO>> treeAll(){
List<DeptmentBO> list = deptmentService.getAllDeptments();
List<DeptmentVO> voList = DeptmentConvert.INSTANCE.convert(list);
Map<Integer, DeptmentVO> nodeMap = calcNodeMap(voList);
// 获得到所有的根节点
List<DeptmentVO> rootNodes = nodeMap.values().stream()
.filter(node -> node.getPid().equals(ResourceConstants.PID_ROOT))
.collect(Collectors.toList());
return success(rootNodes);
}
@GetMapping("tree/page")
@ApiOperation(value = "根部门分页的部门树")
public CommonResult<PageResult<DeptmentVO>> treePage(@Validated DeptmentPageDTO deptmentPageDTO){
PageResult<DeptmentBO> pageResult = deptmentService.getPageRootDeptment(deptmentPageDTO);
PageResult<DeptmentVO> voPageResult = DeptmentConvert.INSTANCE.convert(pageResult);
List<DeptmentBO> list = deptmentService.getAllDeptments();
List<DeptmentVO> voList = DeptmentConvert.INSTANCE.convert(list);
Map<Integer, DeptmentVO> nodeMap = calcNodeMap(voList);
voPageResult.getList().forEach(d->{
d.setChildren(nodeMap.get(d.getId()).getChildren());
});
return success(voPageResult);
}
@PostMapping("add")
@ApiOperation(value = "新增部门", notes = "选择部门名称,父级部门")
public CommonResult<DeptmentBO> add(@RequestBody DeptmentAddDTO deptmentAddDTO){
return success(deptmentService.addDeptment(
AdminSecurityContextHolder.getContext().getAdminId(), deptmentAddDTO));
}
@PostMapping("delete")
@ApiOperation(value = "删除部门")
@ApiImplicitParam(name = "id", value = "部门id", required = true, example = "1")
public CommonResult<Boolean> delete(@RequestParam("id") Integer id){
return success(deptmentService.deleteDeptment(
AdminSecurityContextHolder.getContext().getAdminId(), id
));
}
@PostMapping("update")
@ApiOperation(value = "更新部门")
public CommonResult<Boolean> update(@RequestBody DeptmentUpdateDTO deptmentUpdateDTO){
return success(deptmentService.updateDeptment(
AdminSecurityContextHolder.getContext().getAdminId(), deptmentUpdateDTO
));
}
private Map<Integer, DeptmentVO> calcNodeMap(List<DeptmentVO> voList){
Map<Integer, DeptmentVO> nodeMap = voList.stream().collect(Collectors.toMap(e->e.getId(), e->e));
nodeMap.values().stream()
.filter(node -> !node.getPid().equals(ResourceConstants.PID_ROOT))
.forEach((childNode) -> {
// 获得父节点
DeptmentVO parentNode = nodeMap.get(childNode.getPid());
if (parentNode.getChildren() == null) { // 初始化 children 数组
parentNode.setChildren(new ArrayList<>());
}
// 将自己添加到父节点中
parentNode.getChildren().add(childNode);
});
return nodeMap;
}
}

View File

@ -1,34 +0,0 @@
package cn.iocoder.mall.system.application.vo.datadict;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import java.util.List;
@ApiModel("数据字典枚举 VO")
@Data
@Accessors(chain = true)
public class DataDictEnumVO {
@ApiModelProperty(value = "大类枚举值", required = true, example = "gender")
private String enumValue;
@ApiModelProperty(value = "小类数值数组", required = true)
private List<Value> values;
@ApiModel("数据字典枚举值 VO")
@Data
@Accessors(chain = true)
public static class Value {
@ApiModelProperty(value = "小类数值", required = true, example = "1")
private String value;
@ApiModelProperty(value = "展示名", required = true, example = "男")
private String displayName;
}
}