系统异常日志模块的迁移

This commit is contained in:
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 约定为演示账号 // Admin 编号等于 0 约定为演示账号
if (Objects.equals(AdminSecurityContextHolder.getAdminId(), 0) if (Objects.equals(AdminSecurityContextHolder.getAdminId(), 0)
&& request.getMethod().equalsIgnoreCase(HttpMethod.POST.toString())) { && request.getMethod().equalsIgnoreCase(HttpMethod.POST.toString())) {
throw ServiceExceptionUtil.exception(SystemErrorCodeEnum.AUTHORIZATION_DEMO_PERMISSION_DENY); throw ServiceExceptionUtil.exception(SystemErrorCodeEnum.PERMISSION_DEMO_PERMISSION_DENY);
} }
return true; 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 @Data
public class SystemAccessLogPageDTO extends PageParam { public class SystemAccessLogPageDTO extends PageParam {
@ApiModelProperty(value = "用户编号") @ApiModelProperty(value = "用户编号", example = "1")
private Integer userId; private Integer userId;
@ApiModelProperty(value = "用户类型") @ApiModelProperty(value = "用户类型", example = "2")
private Integer userType; private Integer userType;
@ApiModelProperty(value = "应用名", required = true) @ApiModelProperty(value = "应用名", example = "xxx-service-application")
private String applicationName; 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_PARENT_ERROR(1002007005, "不能设置自己为父资源"),
DEPARTMENT_EXISTS_ADMIN(1002007006, "部门中存在员工,无法删除"), DEPARTMENT_EXISTS_ADMIN(1002007006, "部门中存在员工,无法删除"),
// ========== 权模块 1002008000 ========== // ========== 模块 1002008000 ==========
AUTHORIZATION_PERMISSION_DENY(1002008001, "没有该操作权限"), PERMISSION_DENY(1002008001, "没有该操作权限"),
AUTHORIZATION_DEMO_PERMISSION_DENY(1002008002, "演示账号暂不允许写操作。欢迎加入我们的交流群http://t.cn/EKEr5WE"), PERMISSION_DEMO_PERMISSION_DENY(1002008002, "演示账号暂不允许写操作。欢迎加入我们的交流群http://t.cn/EKEr5WE"),
AUTHORIZATION_ROLE_ASSIGN_RESOURCE_NOT_EXISTS(1002008004, "分配角色资源时,有资源不存在"), PERMISSION_ROLE_ASSIGN_RESOURCE_NOT_EXISTS(1002008004, "分配角色资源时,有资源不存在"),
// ========== 错误码模块 1002009000 ========== // ========== 错误码模块 1002009000 ==========
ERROR_CODE_NOT_EXISTS(1002009000, "错误码不存在"), ERROR_CODE_NOT_EXISTS(1002009000, "错误码不存在"),
ERROR_CODE_DUPLICATE(1002009001, "已经存在编码为【{}}】的错误码"), ERROR_CODE_DUPLICATE(1002009001, "已经存在编码为【{}}】的错误码"),
ERROR_CAN_NOT_UPDATE_SYSTEM_TYPE_ERROR(1002004003, "不能修改类型为系统内置的错误码"), 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; package cn.iocoder.mall.systemservice.rpc.systemlog;
import cn.iocoder.common.framework.vo.CommonResult; 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.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 { public interface SystemExceptionLogRpc {
/**
* 创建系统异常日志
*
* @param createDTO 创建系统异常日志 DTO
* @return 成功
*/
CommonResult<Boolean> createSystemExceptionLog(SystemExceptionLogCreateDTO createDTO); 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; 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.dal.mysql.dataobject.systemlog.SystemExceptionLogDO;
import cn.iocoder.mall.systemservice.rpc.systemlog.dto.SystemExceptionLogCreateDTO; 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.SystemExceptionLogCreateBO;
import cn.iocoder.mall.systemservice.service.systemlog.bo.SystemExceptionLogPageBO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.mapstruct.Mapper; import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers; import org.mapstruct.factory.Mappers;
@ -15,4 +21,14 @@ public interface SystemExceptionLogConvert {
SystemExceptionLogCreateBO convert(SystemExceptionLogCreateDTO bean); 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.common.framework.enums.UserTypeEnum;
import cn.iocoder.mall.mybatis.dataobject.BaseDO; 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 com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
@ -117,4 +119,21 @@ public class SystemExceptionLogDO extends BaseDO {
*/ */
private Integer exceptionLineNumber; 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; 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.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.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
@Repository @Repository
public interface SystemExceptionLogMapper extends BaseMapper<SystemExceptionLogDO> { 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.Map;
import java.util.Set; 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 * 权限 Manager
@ -98,7 +98,7 @@ public class PermissionManager {
// 查询管理员拥有的角色关联数据 // 查询管理员拥有的角色关联数据
Set<Integer> roleIds = permissionService.listAdminRoleIds(checkDTO.getAdminId()); Set<Integer> roleIds = permissionService.listAdminRoleIds(checkDTO.getAdminId());
if (CollectionUtil.isEmpty(roleIds)) { // 如果没有角色默认无法访问 if (CollectionUtil.isEmpty(roleIds)) { // 如果没有角色默认无法访问
throw ServiceExceptionUtil.exception(AUTHORIZATION_PERMISSION_DENY); throw ServiceExceptionUtil.exception(PERMISSION_DENY);
} }
// 判断是否为超管若是超管默认有所有权限 // 判断是否为超管若是超管默认有所有权限
if (roleService.hasSuperAdmin(roleIds)) { if (roleService.hasSuperAdmin(roleIds)) {

View File

@ -1,8 +1,13 @@
package cn.iocoder.mall.systemservice.manager.systemlog; 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.convert.systemlog.SystemExceptionLogConvert;
import cn.iocoder.mall.systemservice.rpc.systemlog.dto.SystemExceptionLogCreateDTO; 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.SystemExceptionLogService;
import cn.iocoder.mall.systemservice.service.systemlog.bo.SystemExceptionLogBO;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -13,10 +18,47 @@ import org.springframework.stereotype.Service;
public class SystemExceptionLogManager { public class SystemExceptionLogManager {
@Autowired @Autowired
private SystemExceptionLogService systemLogService; private SystemExceptionLogService systemExceptionLogService;
/**
* 创建系统异常日志
*
* @param createDTO 创建系统异常日志 DTO
*/
public void createSystemExceptionLog(SystemExceptionLogCreateDTO createDTO) { 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; package cn.iocoder.mall.systemservice.rpc.systemlog;
import cn.iocoder.common.framework.vo.CommonResult; 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.manager.systemlog.SystemExceptionLogManager;
import cn.iocoder.mall.systemservice.rpc.systemlog.dto.SystemExceptionLogCreateDTO; 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.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import static cn.iocoder.common.framework.vo.CommonResult.success;
@Service(version = "${dubbo.provider.SystemExceptionLogRpc.version}", validation = "false") @Service(version = "${dubbo.provider.SystemExceptionLogRpc.version}", validation = "false")
public class SystemExceptionLogRpcImpl implements SystemExceptionLogRpc { public class SystemExceptionLogRpcImpl implements SystemExceptionLogRpc {
@ -15,6 +21,22 @@ public class SystemExceptionLogRpcImpl implements SystemExceptionLogRpc {
@Override @Override
public CommonResult<Boolean> createSystemExceptionLog(SystemExceptionLogCreateDTO createDTO) { public CommonResult<Boolean> createSystemExceptionLog(SystemExceptionLogCreateDTO createDTO) {
systemExceptionLogManager.createSystemExceptionLog(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); return CommonResult.success(true);
} }

View File

@ -68,7 +68,7 @@ public class PermissionService {
if (!CollectionUtils.isEmpty(resourceIds)) { if (!CollectionUtils.isEmpty(resourceIds)) {
int dbResourceSize = resourceMapper.selectCountByIdsAndType(resourceIds, null); int dbResourceSize = resourceMapper.selectCountByIdsAndType(resourceIds, null);
if (resourceIds.size() != dbResourceSize) { if (resourceIds.size() != dbResourceSize) {
throw ServiceExceptionUtil.exception(AUTHORIZATION_ROLE_ASSIGN_RESOURCE_NOT_EXISTS); throw ServiceExceptionUtil.exception(PERMISSION_ROLE_ASSIGN_RESOURCE_NOT_EXISTS);
} }
} }
// TODO 芋艿这里先简单实现即方式是删除老的分配的资源关系然后添加新的分配的资源关系 // TODO 芋艿这里先简单实现即方式是删除老的分配的资源关系然后添加新的分配的资源关系
@ -150,13 +150,13 @@ public class PermissionService {
// 权限验证 // 权限验证
List<RoleResourceDO> roleResourceDOs = roleResourceMapper.selectListByResourceIds(permissionIds); List<RoleResourceDO> roleResourceDOs = roleResourceMapper.selectListByResourceIds(permissionIds);
if (CollectionUtil.isEmpty(roleResourceDOs)) { // 资源未授予任何角色必然权限验证不通过 if (CollectionUtil.isEmpty(roleResourceDOs)) { // 资源未授予任何角色必然权限验证不通过
throw ServiceExceptionUtil.exception(AUTHORIZATION_PERMISSION_DENY); throw ServiceExceptionUtil.exception(PERMISSION_DENY);
} }
Map<Integer, List<Integer>> resourceRoleMap = CollectionUtils.convertMultiMap(roleResourceDOs, Map<Integer, List<Integer>> resourceRoleMap = CollectionUtils.convertMultiMap(roleResourceDOs,
RoleResourceDO::getResourceId, RoleResourceDO::getRoleId); RoleResourceDO::getResourceId, RoleResourceDO::getRoleId);
for (Map.Entry<Integer, List<Integer>> entry : resourceRoleMap.entrySet()) { for (Map.Entry<Integer, List<Integer>> entry : resourceRoleMap.entrySet()) {
if (!CollectionUtil.containsAny(roleIds, entry.getValue())) { // 所以有任一不满足就验证失败抛出异常 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; 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.convert.systemlog.SystemExceptionLogConvert;
import cn.iocoder.mall.systemservice.dal.mysql.dataobject.systemlog.SystemExceptionLogDO; 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.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.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.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; 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 * 系统异常日志 Service
*/ */
@ -16,9 +25,51 @@ public class SystemExceptionLogService {
@Autowired @Autowired
private SystemExceptionLogMapper systemExceptionLogMapper; private SystemExceptionLogMapper systemExceptionLogMapper;
/**
* 创建系统异常日志
*
* @param createBO 创建 BO
*/
public void createSystemExceptionLog(SystemExceptionLogCreateBO createBO) { public void createSystemExceptionLog(SystemExceptionLogCreateBO createBO) {
SystemExceptionLogDO logDO = SystemExceptionLogConvert.INSTANCE.convert(createBO); SystemExceptionLogDO logDO = SystemExceptionLogConvert.INSTANCE.convert(createBO);
logDO.setProcessStatus(SystemExceptionLogProcessStatusEnum.INIT.getStatus());
systemExceptionLogMapper.insert(logDO); 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;
}
}