基础信息提交
This commit is contained in:
5
njcn-springboot/readMe.md
Normal file
5
njcn-springboot/readMe.md
Normal file
@@ -0,0 +1,5 @@
|
||||
#### 统一springboot依赖版本,包括:
|
||||
|
||||
* springboot
|
||||
* spring MVC
|
||||
* swagger
|
||||
@@ -58,7 +58,6 @@
|
||||
<version>${spring-boot.version}</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<!--API接口文档-->
|
||||
<dependency>
|
||||
<groupId>com.github.xiaoymin</groupId>
|
||||
@@ -71,6 +70,7 @@
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.github.xiaoymin</groupId>
|
||||
<artifactId>knife4j-spring-ui</artifactId>
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.njcn.web.controller;
|
||||
|
||||
|
||||
import com.njcn.web.utils.ReflectCommonUtil;
|
||||
|
||||
/**
|
||||
* @author hongawen
|
||||
* @version 1.0.0
|
||||
*/
|
||||
public class BaseController {
|
||||
|
||||
|
||||
/**
|
||||
* 获取当前类指定方法上@ApiOperate内容
|
||||
* @param methodName 方法名
|
||||
*/
|
||||
public String getMethodDescribe(String methodName){
|
||||
return ReflectCommonUtil.getMethodDescribeByClassAndMethodName(this.getClass(),methodName);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.njcn.web.factory;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.njcn.web.pojo.param.BaseParam;
|
||||
|
||||
/**
|
||||
* @author hongawen
|
||||
* @version 1.0
|
||||
* @data 2024/10/30 15:10
|
||||
*/
|
||||
public class PageFactory {
|
||||
|
||||
|
||||
/**
|
||||
* 默认第一页
|
||||
* @param baseParam 查询参数
|
||||
*/
|
||||
public static Integer getPageNum(BaseParam baseParam) {
|
||||
return ObjectUtil.isNull(baseParam.getPageNum()) || baseParam.getPageNum() == 0 ? 1 : baseParam.getPageNum();
|
||||
}
|
||||
|
||||
/**
|
||||
* 默认10条记录
|
||||
* @param baseParam 查询参数
|
||||
*/
|
||||
public static Integer getPageSize(BaseParam baseParam) {
|
||||
return ObjectUtil.isNull(baseParam.getPageSize()) || baseParam.getPageSize() == 0 ? 10 : baseParam.getPageSize();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
package com.njcn.web.pojo.dto;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
|
||||
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* @author hongawen
|
||||
* @version 1.0.0
|
||||
* @date 2021年07月08日 20:03
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class LogInfoDTO implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 登录名
|
||||
*/
|
||||
private String loginName;
|
||||
|
||||
/**
|
||||
* 用户已登录:用户名
|
||||
*/
|
||||
private String userName;
|
||||
|
||||
|
||||
private String ip;
|
||||
|
||||
private String operate;
|
||||
|
||||
private String operateType;
|
||||
|
||||
/**
|
||||
* 操作结果 0.失败 1.成功
|
||||
*/
|
||||
private Integer result;
|
||||
|
||||
/**
|
||||
* 失败原因
|
||||
*/
|
||||
private String failReason;
|
||||
|
||||
/**
|
||||
* 严重度 0.普通 1.中等 2.严重
|
||||
*/
|
||||
private Integer level;
|
||||
|
||||
/**
|
||||
* 事件类型 0.业务事件 1.系统事件
|
||||
*/
|
||||
private Integer type;
|
||||
|
||||
private String serviceName;
|
||||
|
||||
/**
|
||||
* 0 未登录; 1 已登录
|
||||
*/
|
||||
private String userIndex;
|
||||
|
||||
/**
|
||||
* 0 未登录; 1 已登录
|
||||
*/
|
||||
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
|
||||
@JsonSerialize(using = LocalDateTimeSerializer.class)
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private LocalDateTime createTime;
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.njcn.web.pojo.dto;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author hongawen
|
||||
* @version 1.0.0
|
||||
* @date 2023年07月25日 09:40
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class SelectOption implements Serializable {
|
||||
|
||||
private String name;
|
||||
|
||||
private String value;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.njcn.web.pojo.dto;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author hongawen
|
||||
* @version 1.0.0
|
||||
* @date 2022年03月18日 12:30
|
||||
*/
|
||||
@Data
|
||||
public class SimpleDTO implements Serializable {
|
||||
|
||||
@ApiModelProperty(name = "name", value = "名称")
|
||||
private String name;
|
||||
|
||||
@ApiModelProperty(name = "id", value = "索引")
|
||||
private String id;
|
||||
|
||||
@ApiModelProperty(name = "code", value = "编码")
|
||||
private String code;
|
||||
|
||||
@ApiModelProperty(name = "value", value = "数值")
|
||||
private String value;
|
||||
|
||||
private Integer sort;
|
||||
|
||||
private Integer algoDescribe;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.njcn.web.pojo.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author hongawen
|
||||
* @version 1.0.0
|
||||
* @date 2022年03月24日 16:02
|
||||
*/
|
||||
@Data
|
||||
public class SimpleTreeDTO extends SimpleDTO implements Serializable {
|
||||
|
||||
private List<SimpleDTO> children;
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package com.njcn.web.pojo.dto;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
|
||||
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* @author hongawen
|
||||
* @version 1.0.0
|
||||
* @date 2022年03月11日 11:29
|
||||
*/
|
||||
@Data
|
||||
public class UserTokenInfo implements Serializable {
|
||||
|
||||
/**
|
||||
* 通行token
|
||||
*/
|
||||
private String accessTokenJti;
|
||||
|
||||
/**
|
||||
* 刷新token
|
||||
*/
|
||||
private String refreshToken;
|
||||
|
||||
|
||||
/**
|
||||
* refreshToken的生命周期结点
|
||||
*/
|
||||
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
|
||||
@JsonSerialize(using = LocalDateTimeSerializer.class)
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private LocalDateTime refreshTokenExpire;
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package com.njcn.web.pojo.param;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author hongawen
|
||||
* @version 1.0.0
|
||||
* @date 2021年12月20日 15:35
|
||||
*/
|
||||
@Data
|
||||
public class BaseParam implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@ApiModelProperty("搜索值")
|
||||
private String searchValue;
|
||||
|
||||
@ApiModelProperty("开始时间")
|
||||
private String searchBeginTime;
|
||||
|
||||
@ApiModelProperty("结束时间")
|
||||
private String searchEndTime;
|
||||
|
||||
@ApiModelProperty("状态")
|
||||
private Integer searchState;
|
||||
|
||||
@ApiModelProperty("排序字段")
|
||||
private String sortBy;
|
||||
|
||||
@ApiModelProperty("排序方式:asc-升序,desc-降序")
|
||||
private String orderBy;
|
||||
|
||||
@ApiModelProperty("页码")
|
||||
private Integer pageNum;
|
||||
|
||||
@ApiModelProperty("页面尺寸")
|
||||
private Integer pageSize;
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package com.njcn.web.utils;
|
||||
|
||||
import cn.hutool.core.text.StrFormatter;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
||||
import com.njcn.common.pojo.exception.BusinessException;
|
||||
import com.njcn.common.pojo.response.HttpResult;
|
||||
|
||||
/**
|
||||
* @author hongawen
|
||||
* @version 1.0
|
||||
* @data 2024/10/30 14:51
|
||||
*/
|
||||
public class HttpResultUtil {
|
||||
|
||||
/**
|
||||
* 组装结果集
|
||||
*/
|
||||
public static <T> HttpResult<T> assembleResult(String code, T result, String message) {
|
||||
HttpResult<T> httpResult = new HttpResult<>();
|
||||
httpResult.setCode(code);
|
||||
httpResult.setMessage(message);
|
||||
httpResult.setData(result);
|
||||
return httpResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* 组装通用结果集
|
||||
*/
|
||||
public static <T> HttpResult<T> assembleCommonResponseResult(CommonResponseEnum responseEnum, T result, String methodDescribe) {
|
||||
String message = responseEnum.getMessage();
|
||||
if (responseEnum.equals(CommonResponseEnum.METHOD_ARGUMENT_NOT_VALID_EXCEPTION)) {
|
||||
message = (String) result;
|
||||
}
|
||||
return assembleResult(responseEnum.getCode(), result, StrFormatter.format("{}{}{}", methodDescribe, StrUtil.C_COMMA, message));
|
||||
}
|
||||
|
||||
/**
|
||||
* 业务异常组装结果集
|
||||
*/
|
||||
public static <T> HttpResult<T> assembleBusinessExceptionResult(BusinessException businessException, T result, String methodDescribe) {
|
||||
return assembleResult(businessException.getCode(), result, StrFormatter.format("{}{}{}", methodDescribe, StrUtil.C_COMMA, businessException.getMessage()));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
package com.njcn.web.utils;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.util.ReflectUtil;
|
||||
import com.njcn.common.pojo.annotation.OperateInfo;
|
||||
import com.njcn.common.pojo.constant.LogInfo;
|
||||
import com.njcn.common.pojo.constant.OperateType;
|
||||
import com.njcn.common.pojo.enums.common.LogEnum;
|
||||
import com.njcn.common.utils.ExceptionUtil;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* @author hongawen
|
||||
*/
|
||||
@Slf4j
|
||||
public class ReflectCommonUtil {
|
||||
|
||||
|
||||
/**
|
||||
* 根据异常获取系统内controller中的方法
|
||||
* @param exception 运行时异常
|
||||
*/
|
||||
public static Method getMethod(Exception exception) {
|
||||
List<String> stackInfo = ExceptionUtil.getFirstControllerAndMethodName(exception);
|
||||
Method method = null;
|
||||
if (!CollectionUtil.isEmpty(stackInfo)) {
|
||||
String controllerName = stackInfo.get(0);
|
||||
String methodName = stackInfo.get(1);
|
||||
try {
|
||||
method = ReflectUtil.getMethodByName(Class.forName(controllerName), methodName);
|
||||
} catch (ClassNotFoundException e) {
|
||||
log.error("根据controller名以及方法名反射获取方法体异常,controller为:{},方法为:{},异常为:{}", controllerName, methodName, e.getMessage());
|
||||
}
|
||||
}
|
||||
return method;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 从异常堆栈信息里找出controller上@ApiOperation内容
|
||||
*
|
||||
* @param exception 异常
|
||||
*/
|
||||
public static String getMethodDescribeByException(Exception exception) {
|
||||
List<String> stackInfo = ExceptionUtil.getFirstControllerAndMethodName(exception);
|
||||
String operate = LogInfo.UNKNOWN_OPERATE;
|
||||
if (!CollectionUtil.isEmpty(stackInfo)) {
|
||||
String controllerName = stackInfo.get(0);
|
||||
String methodName = stackInfo.get(1);
|
||||
try {
|
||||
operate = ReflectCommonUtil.getMethodDescribeByClassAndMethodName(Class.forName(controllerName), methodName);
|
||||
} catch (ClassNotFoundException e) {
|
||||
log.error("根据controller名以及方法名获取操作注解内容异常,controller为:{},方法为:{},异常为:{}", controllerName, methodName, e.getMessage());
|
||||
}
|
||||
}
|
||||
return operate;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取controller上方法@ApiOperation注解的值,作为当前方法的简短描述
|
||||
*/
|
||||
public static String getMethodDescribeByClassAndMethodName(Class<?> clazz, String methodName) {
|
||||
Method method = ReflectUtil.getMethodByName(clazz, methodName);
|
||||
return getMethodDescribeByMethod(method);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取方法上@ApiOperation注解的值,作为当前方法的简短描述
|
||||
*/
|
||||
public static String getMethodDescribeByMethod(Method method) {
|
||||
String operate = LogInfo.UNKNOWN_OPERATE;
|
||||
if (Objects.nonNull(method) && method.isAnnotationPresent(ApiOperation.class)) {
|
||||
operate = method.getAnnotation(ApiOperation.class).value();
|
||||
}
|
||||
return operate;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据controller上的方法@OperateInfo注解的内容,返回当前[业务类型]以及[严重度]
|
||||
*/
|
||||
public static LogEnum getOperateInfoByMethod(Method method) {
|
||||
LogEnum logEnum = LogEnum.BUSINESS_COMMON;
|
||||
if(Objects.nonNull(method) && method.isAnnotationPresent(OperateInfo.class)){
|
||||
logEnum = method.getAnnotation(OperateInfo.class).info();
|
||||
}
|
||||
return logEnum;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据controller上的方法@OperateInfo注解的内容,返回当前操作类型
|
||||
*/
|
||||
public static String getOperateTypeByMethod(Method method) {
|
||||
String operateType = OperateType.QUERY;
|
||||
if(Objects.nonNull(method) && method.isAnnotationPresent(OperateInfo.class)){
|
||||
operateType = method.getAnnotation(OperateInfo.class).operateType();
|
||||
}
|
||||
return operateType;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user