feat:添加APP版本管理相关代码
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user