feat:添加APP版本管理相关代码

This commit is contained in:
aguanleishen
2026-07-28 08:32:50 +08:00
parent 9894ac7a34
commit 15854b40ac
4 changed files with 699 additions and 1 deletions
@@ -127,6 +127,12 @@ public interface AppConstant {
*/
String APPLICATION_DEMO_NAME = APPLICATION_NAME_PREFIX + "demo";
/**
* 文件模块模块名称
*/
String APPLICATION_FILE_NAME =APPLICATION_NAME_PREFIX +"file";
/**
* 开发环境
*/
@@ -0,0 +1,221 @@
package org.springblade.core.tool.api;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.NullSerializer;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.servlet.http.HttpServletResponse;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import org.springblade.core.tool.constant.BladeConstant;
import org.springblade.core.tool.utils.ObjectUtil;
import org.springframework.lang.Nullable;
import java.io.Serial;
import java.util.Optional;
/**
* feign 统一API响应结果封装
* @author bfhuange
* @since 2024/11/28
*/
@Getter
@Setter
@ToString
@Schema(description = "返回信息")
@NoArgsConstructor
public class FR<T> extends R<T> {
@Serial
private static final long serialVersionUID = 1L;
@JsonSerialize(nullsUsing = NullSerializer.class)
@Schema(description = "承载数据")
private T data;
private FR(IResultCode resultCode) {
this(resultCode, null, resultCode.getMessage());
}
private FR(IResultCode resultCode, String msg) {
this(resultCode, null, msg);
}
private FR(IResultCode resultCode, T data) {
this(resultCode, data, resultCode.getMessage());
}
private FR(IResultCode resultCode, T data, String msg) {
this(resultCode.getCode(), data, msg);
}
private FR(int code, T data, String msg) {
super(code, data, msg);
this.data = data;
}
public void setData(T data) {
this.data = data;
super.setData(data);
}
/**
* 判断返回是否为成功
*
* @param result Result
* @return 是否成功
*/
public static boolean isSuccess(@Nullable FR<?> result) {
return Optional.ofNullable(result)
.map(x -> ObjectUtil.nullSafeEquals(ResultCode.SUCCESS.getCode(), x.getCode()))
.orElse(Boolean.FALSE);
}
/**
* 判断返回是否为成功
*
* @param result Result
* @return 是否成功
*/
public static boolean isNotSuccess(@Nullable FR<?> result) {
return !FR.isSuccess(result);
}
/**
* 返回R
*
* @param data 数据
* @param <T> T 泛型标记
* @return R
*/
public static <T> FR<T> data(T data) {
return data(data, BladeConstant.DEFAULT_SUCCESS_MESSAGE);
}
/**
* 返回R
*
* @param data 数据
* @param msg 消息
* @param <T> T 泛型标记
* @return R
*/
public static <T> FR<T> data(T data, String msg) {
return data(HttpServletResponse.SC_OK, data, msg);
}
/**
* 返回R
*
* @param code 状态码
* @param data 数据
* @param msg 消息
* @param <T> T 泛型标记
* @return R
*/
public static <T> FR<T> data(int code, T data, String msg) {
return new FR<>(code, data, data == null ? BladeConstant.DEFAULT_NULL_MESSAGE : msg);
}
/**
* 返回R
*
* @param msg 消息
* @param <T> T 泛型标记
* @return R
*/
public static <T> FR<T> success(String msg) {
return new FR<>(ResultCode.SUCCESS, msg);
}
/**
* 返回R
*
* @param resultCode 业务代码
* @param <T> T 泛型标记
* @return R
*/
public static <T> FR<T> success(IResultCode resultCode) {
return new FR<>(resultCode);
}
/**
* 返回R
*
* @param resultCode 业务代码
* @param msg 消息
* @param <T> T 泛型标记
* @return R
*/
public static <T> FR<T> success(IResultCode resultCode, String msg) {
return new FR<>(resultCode, msg);
}
/**
* 返回R
*
* @param msg 消息
* @param <T> T 泛型标记
* @return R
*/
public static <T> FR<T> fail(String msg) {
return new FR<>(ResultCode.FAILURE, msg);
}
/**
* 返回R
*
* @param code 状态码
* @param msg 消息
* @param <T> T 泛型标记
* @return R
*/
public static <T> FR<T> fail(int code, String msg) {
return new FR<>(code, null, msg);
}
/**
* 返回R
*
* @param resultCode 业务代码
* @param <T> T 泛型标记
* @return R
*/
public static <T> FR<T> fail(IResultCode resultCode) {
return new FR<>(resultCode);
}
/**
* 返回R
*
* @param resultCode 业务代码
* @param msg 消息
* @param <T> T 泛型标记
* @return R
*/
public static <T> FR<T> fail(IResultCode resultCode, String msg) {
return new FR<>(resultCode, msg);
}
/**
* 返回R
*
* @param flag 成功状态
* @return R
*/
public static <T> FR<T> status(boolean flag) {
return flag ? success(BladeConstant.DEFAULT_SUCCESS_MESSAGE) : fail(BladeConstant.DEFAULT_FAILURE_MESSAGE);
}
/**
* 从r复制
* @param result
* @return
* @param <T>
*/
public static <T> FR<T> copy(R<T> result) {
return new FR<>(result.getCode(), result.getData(), result.getMsg());
}
}
@@ -79,7 +79,7 @@ public class R<T> implements Serializable {
this(resultCode.getCode(), data, msg);
}
private R(int code, T data, String msg) {
protected R(int code, T data, String msg) {
this.code = code;
this.data = data;
this.msg = msg;
@@ -0,0 +1,471 @@
package org.springblade.core.log.utils;
import org.springblade.core.log.exception.ServiceException;
import org.springblade.core.tool.api.IResultCode;
import org.springblade.core.tool.utils.StringUtil;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* @author bfhuange
* @date 2024/8/27
**/
public class AssertUtils {
/**
* 对象非空
* @param object
* @param message
*/
public static void notNull(Object object, String message) throws ServiceException {
if (object == null) {
throw new ServiceException(message);
}
}
/**
* 对象非空
* @param object
* @param resultCode
*/
public static void notNull(Object object, IResultCode resultCode) throws ServiceException {
if (object == null) {
throw new ServiceException(resultCode);
}
}
/**
* Map非空
* @param map
* @param message
*/
public static void notEmpty(Map<?, ?> map, String message) throws ServiceException {
if (CollectionUtils.isEmpty(map)) {
throw new ServiceException(message);
}
}
/**
* Map非空
* @param map
* @param resultCode
*/
public static void notEmpty(Map<?, ?> map, IResultCode resultCode) throws ServiceException {
if (CollectionUtils.isEmpty(map)) {
throw new ServiceException(resultCode);
}
}
/**
* 列表非空
* @param collection
* @param message
*/
public static void notEmpty(Collection<?> collection, String message) throws ServiceException {
if (CollectionUtils.isEmpty(collection)) {
throw new ServiceException(message);
}
}
/**
* 列表非空
* @param collection
* @param resultCode
*/
public static void notEmpty(Collection<?> collection, IResultCode resultCode) throws ServiceException {
if (CollectionUtils.isEmpty(collection)) {
throw new ServiceException(resultCode);
}
}
/**
* 数组非空
* @param array
* @param message
*/
public static void notEmpty(Object[] array, String message) throws ServiceException {
if (ObjectUtils.isEmpty(array)) {
throw new ServiceException(message);
}
}
/**
* 数组非空
* @param array
* @param resultCode
*/
public static void notEmpty(Object[] array, IResultCode resultCode) throws ServiceException {
if (ObjectUtils.isEmpty(array)) {
throw new ServiceException(resultCode);
}
}
/**
* 字符串非空
* @param value
* @param message
*/
public static void notEmpty(String value, String message) throws ServiceException {
if (StringUtil.hasLength(value)) {
throw new ServiceException(message);
}
}
/**
* 字符串非空
* @param value
* @param resultCode
*/
public static void notEmpty(String value, IResultCode resultCode) throws ServiceException {
if (StringUtil.hasLength(value)) {
throw new ServiceException(resultCode);
}
}
/**
* 字符串去除空格非空
* @param value
* @param message
*/
public static void notBlank(String value, String message) throws ServiceException {
if (StringUtil.isBlank(value)) {
throw new ServiceException(message);
}
}
/**
* 字符串去除空格非空
* @param value
* @param resultCode
*/
public static void notBlank(String value, IResultCode resultCode) throws ServiceException {
if (StringUtil.isBlank(value)) {
throw new ServiceException(resultCode);
}
}
/**
* 获取重复数据
* @param dataList
* @return
* @throws ServiceException
*/
public static List<String> getRepeatData(List<String> dataList) throws ServiceException {
if(CollectionUtils.isEmpty(dataList)) {
return null;
}
//判断是否有重复数据
List<String> distinctDataList = dataList.stream().distinct().toList();
if(dataList.size() == distinctDataList.size()) {
return null;
}
List<String> repeatList = new ArrayList<>();
Map<String,Long> dataMap = dataList.stream().collect(Collectors.groupingBy(p -> p,Collectors.counting()));
//处理重复数据
for(Map.Entry<String,Long> entry:dataMap.entrySet()) {
if(entry.getValue() > 1) {
repeatList.add(entry.getKey());
}
}
return repeatList;
}
/**
* 数据不允许重复
* @param dataList
* @param message
* @throws ServiceException
*/
public static void notRepeat(List<String> dataList,String message) throws ServiceException {
//获取重复数据
List<String> repeatList = getRepeatData(dataList);
//若有重复数据,则校验不通过处理
if(!CollectionUtils.isEmpty(repeatList)) {
String repeatData = String.join(",",repeatList);
throw new ServiceException(String.format(message,repeatData));
}
}
/**
* 字符串相等校验
* @param str1
* @param str2
* @param message
* @throws ServiceException
*/
public static void equals(String str1, String str2, String message) throws ServiceException {
if (!StringUtil.equals(str1,str2)) {
throw new ServiceException(message);
}
}
/**
* 字符串相等校验
* @param str1
* @param str2
* @param resultCode
* @throws ServiceException
*/
public static void equals(String str1, String str2, IResultCode resultCode) throws ServiceException {
if (!StringUtil.equals(str1,str2)) {
throw new ServiceException(resultCode);
}
}
/**
* 数字相等校验
* @param num1
* @param num2
* @param message
* @throws ServiceException
*/
public static void equals(BigDecimal num1, BigDecimal num2, String message) throws ServiceException {
if (num1.compareTo(num2) != 0) {
throw new ServiceException(message);
}
}
/**
* 数字相等校验
* @param num1
* @param num2
* @param resultCode
* @throws ServiceException
*/
public static void equals(BigDecimal num1, BigDecimal num2, IResultCode resultCode) throws ServiceException {
if (num1.compareTo(num2) != 0) {
throw new ServiceException(resultCode);
}
}
/**
* 数字不大于校验
* @param num1
* @param num2
* @param message
* @throws ServiceException
*/
public static void notGreaterThan(BigDecimal num1, BigDecimal num2, String message) throws ServiceException {
if(num1.compareTo(num2) > 0) {
throw new ServiceException(message);
}
}
/**
* 数字不大于校验
* @param num1
* @param num2
* @param resultCode
* @throws ServiceException
*/
public static void notGreaterThan(BigDecimal num1, BigDecimal num2, IResultCode resultCode) throws ServiceException {
if(num1.compareTo(num2) > 0) {
throw new ServiceException(resultCode);
}
}
/**
* 数字不大于校验
* @param num1
* @param num2
* @param message
* @throws ServiceException
*/
public static void notGreaterThan(Integer num1, Integer num2, String message) throws ServiceException {
if(num1 > num2) {
throw new ServiceException(message);
}
}
/**
* 数字不大于校验
* @param num1
* @param num2
* @param resultCode
* @throws ServiceException
*/
public static void notGreaterThan(Integer num1, Integer num2, IResultCode resultCode) throws ServiceException {
if(num1 > num2) {
throw new ServiceException(resultCode);
}
}
/**
* 数字不小于校验
* @param num1
* @param num2
* @param message
* @throws ServiceException
*/
public static void notLessThan(BigDecimal num1, BigDecimal num2, String message) throws ServiceException {
if(num1.compareTo(num2) < 0) {
throw new ServiceException(message);
}
}
/**
* 数字不小于校验
* @param num1
* @param num2
* @param resultCode
* @throws ServiceException
*/
public static void notLessThan(BigDecimal num1, BigDecimal num2, IResultCode resultCode) throws ServiceException {
if(num1.compareTo(num2) < 0) {
throw new ServiceException(resultCode);
}
}
/**
* 表达式为真判断校验
* @param expression
* @param message
* @throws ServiceException
*/
public static void isTrue(boolean expression, String message) throws ServiceException {
if(!expression) {
throw new ServiceException(message);
}
}
/**
* 表达式为真判断校验
* @param expression
* @param resultCode
* @throws ServiceException
*/
public static void isTrue(boolean expression, IResultCode resultCode) throws ServiceException {
if(!expression) {
throw new ServiceException(resultCode);
}
}
/**
* 表达式判断为假校验
* @param expression
* @param message
* @throws ServiceException
*/
public static void isFalse(boolean expression, String message) throws ServiceException {
if(expression) {
throw new ServiceException(message);
}
}
/**
* 表达式判断为假校验
* @param expression
* @param resultCode
* @throws ServiceException
*/
public static void isFalse(boolean expression, IResultCode resultCode) throws ServiceException {
if(expression) {
throw new ServiceException(resultCode);
}
}
/**
* 字符串不相等校验
* @param str1
* @param str2
* @param message
* @throws ServiceException
*/
public static void notEquals(String str1, String str2, String message) throws ServiceException {
if (StringUtil.equals(str1,str2)) {
throw new ServiceException(message);
}
}
/**
* 字符串不相等校验
* @param str1
* @param str2
* @param resultCode
* @throws ServiceException
*/
public static void notEquals(String str1, String str2, IResultCode resultCode) throws ServiceException {
if (StringUtil.equals(str1,str2)) {
throw new ServiceException(resultCode);
}
}
/**
* 对象为空
* @param object
* @param message
*/
public static void isNull(Object object, String message) throws ServiceException {
if (object != null) {
throw new ServiceException(message);
}
}
/**
* 对象为空
* @param object
* @param resultCode
*/
public static void isNull(Object object, IResultCode resultCode) throws ServiceException {
if (object != null) {
throw new ServiceException(resultCode);
}
}
/**
* 对象为数值
* @param value
* @param message
* @throws ServiceException
*/
public static void isInteger(String value,String message) throws ServiceException {
try {
Integer.valueOf(value);
} catch (NumberFormatException e) {
throw new ServiceException(message);
}
}
/**
* 对象为数值
* @param value
* @param resultCode
* @throws ServiceException
*/
public static void isInteger(String value,IResultCode resultCode) throws ServiceException {
try {
Integer.valueOf(value);
} catch (NumberFormatException e) {
throw new ServiceException(resultCode);
}
}
/**
* 列表为空
* @param collection
* @param message
*/
public static void isEmpty(Collection<?> collection, String message) throws ServiceException {
if (!CollectionUtils.isEmpty(collection)) {
throw new ServiceException(message);
}
}
/**
* 列表为空
* @param collection
* @param resultCode
*/
public static void isEmpty(Collection<?> collection, IResultCode resultCode) throws ServiceException {
if (!CollectionUtils.isEmpty(collection)) {
throw new ServiceException(resultCode);
}
}
}