pigx-common-core

This commit is contained in:
sxu 2025-03-14 14:43:25 +08:00
parent faa33247ca
commit 40938c20b6
14 changed files with 47 additions and 312 deletions

View File

@ -1,9 +1,7 @@
package com.pig4cloud.pigx.common.core.constant;
public interface CacheConstants {
String USER_DETAILS = "user_details";
String YUN_PREFIX = "yst:";
String YUNSHITANG = "yunshitang";
String DATASCREEN = "datascreen:";
String DATASCREEN_USER = "user:";
String MENUAI = "menuai:";

View File

@ -7,14 +7,8 @@ public interface LeConstants {
Integer DATA_DEFAULT_INTEGER = -1;
Integer COMMON_YES = 1;
Integer COMMON_NO = 2;
Integer MAX_CARD_NUM = 100000;
Integer MAX_CUST_LIMIT_ID = 65535;
Integer MIN_DATA_NUM = 1;
Integer MAX_CUST_PSN_TYPE = 100;
String DEFAULT_GRADE_NAME = "普通会员";
String DEFAULT_PSN_TYPE_NAME = "类别";
String MAPPING_OBJECT = "object";
String MAPPING_PAGE = "page";
String MERCHANT_ID = "MERCHANT-ID";
String MERCHANT_ID_LOW = "merchant-id";
String OPENID = "openid";

View File

@ -1,9 +1,5 @@
package com.pig4cloud.pigx.common.core.constant;
public interface WechatConstants {
String COMMON_SUCC = "SUCCESS";
String TRADE_STATE_SUCCESS = "SUCCESS";
String TRADE_STATE_NOTPAY = "NOTPAY";
String TRADE_STATE_USERPAYING = "USERPAYING";
String REFUND_STATUS_SUCCESS = "SUCCESS";
}

View File

@ -4,7 +4,6 @@ import com.pig4cloud.pigx.common.core.util.RetCodeEnum;
import net.xnzn.framework.config.exception.BizException;
public class LeCheckedException extends BizException {
private static final long serialVersionUID = 1L;
private static final Integer DEFAULT_ERROR_CODE = 40004;
public LeCheckedException(String message) {

View File

@ -4,7 +4,6 @@ import com.pig4cloud.pigx.common.core.util.RetCodeEnum;
import net.xnzn.framework.config.exception.BizRuntimeException;
public class LeException extends BizRuntimeException {
private static final long serialVersionUID = 1L;
private static final Integer DEFAULT_ERROR_CODE = 40004;
public LeException(String message) {

View File

@ -9,6 +9,7 @@ import com.fasterxml.jackson.databind.ser.ContextualSerializer;
import com.pig4cloud.pigx.common.core.util.DesensitizedUtils;
import java.io.IOException;
import java.util.Objects;
import lombok.Generated;
public class SensitiveSerialize extends JsonSerializer<String> implements ContextualSerializer {
private SensitiveTypeEnum type;
@ -73,9 +74,11 @@ public class SensitiveSerialize extends JsonSerializer<String> implements Contex
}
}
@Generated
public SensitiveSerialize() {
}
@Generated
public SensitiveSerialize(final SensitiveTypeEnum type, final Integer prefixNoMaskLen, final Integer suffixNoMaskLen, final String maskStr) {
this.type = type;
this.prefixNoMaskLen = prefixNoMaskLen;

View File

@ -1,11 +1,13 @@
package com.pig4cloud.pigx.common.core.util;
import java.lang.reflect.Field;
import lombok.Generated;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.ObjectUtils;
public class IsEmptyUtil {
@Generated
private static final Logger log = LoggerFactory.getLogger(IsEmptyUtil.class);
public static boolean allFieldIsNULL(Object o) {

View File

@ -1,58 +1,8 @@
package com.pig4cloud.pigx.common.core.util;
import com.alibaba.fastjson.JSON;
import com.pig4cloud.pigx.common.core.exception.LeException;
import java.beans.PropertyDescriptor;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.BeanWrapper;
import org.springframework.beans.BeanWrapperImpl;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
public class LeBeanUtil {
public static String[] getNullPropertyNames(Object source) {
BeanWrapper src = new BeanWrapperImpl(source);
PropertyDescriptor[] pds = src.getPropertyDescriptors();
Set<String> emptyNames = new HashSet();
PropertyDescriptor[] var4 = pds;
int var5 = pds.length;
for(int var6 = 0; var6 < var5; ++var6) {
PropertyDescriptor pd = var4[var6];
Object srcValue = src.getPropertyValue(pd.getName());
if (srcValue == null) {
emptyNames.add(pd.getName());
}
}
String[] result = new String[emptyNames.size()];
return (String[])emptyNames.toArray(result);
}
public static void copyProperties(Object source, Object target) {
if (source != null && target != null) {
BeanUtils.copyProperties(source, target, getNullPropertyNames(source));
} else {
throw new LeException("复制对象时,源和目标对象均不能为空");
}
}
public static void copyProperties(Object source, Object target, String... ignoreProperties) {
BeanUtils.copyProperties(source, target, ignoreProperties);
}
public static <T> T copyCreateProperties(Object source, Class<T> tClass) {
return source == null ? new Object() : JSON.parseObject(JSON.toJSONString(source), tClass);
}
public static <T> List copyCreateList(List sourceList, Class<T> tClass) {
return (List)(CollectionUtils.isEmpty(sourceList) ? new ArrayList() : JSON.parseArray(JSON.toJSONString(sourceList), tClass));
}
public static String fieldLikeHandle(String fieldName) {
return StringUtils.hasText(fieldName) ? "%" + fieldName + "%" : null;
}

View File

@ -1,212 +1,50 @@
package com.pig4cloud.pigx.common.core.util;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.time.temporal.TemporalAdjusters;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;
import java.util.Locale;
import java.util.Objects;
import java.util.stream.Stream;
import lombok.Generated;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class LeDateUtils {
@Generated
private static final Logger log = LoggerFactory.getLogger(LeDateUtils.class);
public static boolean isEffectiveDate(LocalTime startTime, LocalTime endTime) {
if (startTime != null && endTime != null) {
LocalTime currentTime = LocalTime.now();
return currentTime.compareTo(startTime) >= 0 && currentTime.compareTo(endTime) <= 0;
} else {
return false;
}
}
public static boolean isEffectiveDate(LocalDate startDate, LocalDate endDate) {
if (startDate != null && endDate != null) {
LocalDate currentDate = LocalDate.now();
return currentDate.compareTo(startDate) >= 0 && currentDate.compareTo(endDate) <= 0;
} else {
return false;
}
}
public static boolean isEffectiveDate(LocalDateTime startDate, LocalDateTime endDate) {
if (startDate != null && endDate != null) {
LocalDateTime currentDate = LocalDateTime.now();
return currentDate.compareTo(startDate) >= 0 && currentDate.compareTo(endDate) <= 0;
} else {
return false;
}
}
public static boolean checkConfEffectiveDate(LocalTime startTime, LocalTime endTime) {
if (startTime == null && endTime == null) {
return true;
} else {
LocalTime currentTime = LocalTime.now();
if (startTime != null && currentTime.compareTo(startTime) < 0) {
return false;
} else {
return endTime == null || currentTime.compareTo(endTime) <= 0;
}
}
}
public static boolean checkConfEffectiveDate(LocalDateTime startTime, LocalDateTime endTime) {
if (startTime == null && endTime == null) {
return true;
} else {
LocalDateTime currentTime = LocalDateTime.now();
if (startTime != null && currentTime.compareTo(startTime) < 0) {
return false;
} else {
return endTime == null || currentTime.compareTo(endTime) <= 0;
}
}
}
public static boolean checkYearAndMonth(LocalDate startDate, LocalDate endDate) {
return startDate.getYear() == endDate.getYear() && startDate.getMonthValue() == endDate.getMonthValue();
}
public static LocalDateTime getDayBeforeMinTime() {
return LocalDateTime.of(LocalDate.now(), LocalTime.MIN).minusDays(1L);
}
public static LocalDateTime getDayBeforeMaxTime() {
return LocalDateTime.of(LocalDate.now(), LocalTime.MAX).minusDays(1L);
}
public static LocalDateTime getDateSpecifyMinTime(LocalDate localDate) {
return LocalDateTime.of(localDate, LocalTime.MIN);
}
public static LocalDateTime getDateSpecifyMaxTime(LocalDate localDate) {
return LocalDateTime.of(localDate, LocalTime.MAX);
}
public static LocalDateTime getTodayMinTime() {
return LocalDateTime.of(LocalDate.now(), LocalTime.MIN);
}
public static LocalDateTime getTodayMaxTime() {
return LocalDateTime.of(LocalDate.now(), LocalTime.MAX);
}
public static LocalDateTime getMonthMinTime() {
LocalDate today = LocalDate.now();
LocalDate minDay = today.with(TemporalAdjusters.firstDayOfMonth());
return LocalDateTime.of(minDay, LocalTime.MIN);
}
public static LocalDateTime getMonthMaxTime() {
LocalDate today = LocalDate.now();
LocalDate maxDay = today.with(TemporalAdjusters.lastDayOfMonth());
return LocalDateTime.of(maxDay, LocalTime.MAX);
}
public static LocalDateTime convertWechartTime(String timeEnd) {
int year = Integer.valueOf(timeEnd.substring(0, 4));
int month = Integer.valueOf(timeEnd.substring(4, 6));
int dayOfMonth = Integer.valueOf(timeEnd.substring(6, 8));
int hour = Integer.valueOf(timeEnd.substring(8, 10));
int minute = Integer.valueOf(timeEnd.substring(10, 12));
int second = Integer.valueOf(timeEnd.substring(12));
return LocalDateTime.of(year, month, dayOfMonth, hour, minute, second);
}
public static LocalDate covertFormatDate(String date) {
try {
int year = Integer.valueOf(date.substring(0, 4));
int month = Integer.valueOf(date.substring(4, 6));
int dayOfMonth = Integer.valueOf(date.substring(6, 8));
int year = Integer.parseInt(date.substring(0, 4));
int month = Integer.parseInt(date.substring(4, 6));
int dayOfMonth = Integer.parseInt(date.substring(6, 8));
return LocalDate.of(year, month, dayOfMonth);
} catch (Exception var4) {
return null;
}
}
public static LocalDateTime convertStringDateTime(String dateTime) {
DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
LocalDateTime localDateTime = LocalDateTime.parse(dateTime, df);
return localDateTime;
}
public static LocalDate convertStringDate(String dateTime) {
DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
LocalDateTime localDateTime = LocalDateTime.parse(dateTime, df);
return localDateTime.toLocalDate();
}
public static LocalDate convertOfficeDate(String excelNumber) {
LocalDate localDate = null;
Calendar calendar = new GregorianCalendar();
calendar.set(1900, 0, 1);
calendar.add(5, Integer.valueOf(excelNumber));
SimpleDateFormat sFormat = new SimpleDateFormat("yyyy-MM-dd");
String format = sFormat.format(calendar.getTime());
DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd");
localDate = LocalDate.parse(format, df);
return localDate;
}
public static LocalDateTime convertOfficeDateTime(String excelNumber) {
LocalDateTime datetime = null;
Calendar calendar = new GregorianCalendar();
calendar.set(1900, 0, 1);
calendar.add(5, Integer.valueOf(excelNumber));
SimpleDateFormat sFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String format = sFormat.format(calendar.getTime());
DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
datetime = LocalDateTime.parse(format, df);
return datetime;
}
public static String dateTimeToStr(LocalDateTime localDateTime) {
DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
return df.format(localDateTime);
}
public static LocalDateTime strToDateTime(String localDateTime) {
DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
return LocalDateTime.parse(localDateTime, df);
}
public static String timeToStr(LocalTime localTime) {
DateTimeFormatter df = DateTimeFormatter.ofPattern("HH:mm:ss");
return df.format(localTime);
}
public static LocalTime strToTime(String time) {
DateTimeFormatter df = DateTimeFormatter.ofPattern("HH:mm:ss");
return LocalTime.parse(time, df);
}
public static long getDayRemainingSecond() {
LocalDateTime assignDateTime = LocalDateTime.now().plusDays(1L).withHour(0).withMinute(0).withSecond(0).withNano(0);
return getAssignRemainingSecond(assignDateTime);
}
public static long getAssignRemainingSecond(LocalTime assignTime) {
LocalDateTime assignDateTime = LocalDateTime.of(LocalDate.now(), assignTime);
return getAssignRemainingSecond(assignDateTime);
}
public static long getAssignRemainingSecond(LocalDateTime assignDateTime) {
long seconds = ChronoUnit.SECONDS.between(LocalDateTime.now(), assignDateTime);
return seconds < 0L ? 0L : seconds;
}
public static List<LocalDate> getBetweenDate(LocalDate startDate, LocalDate endDate) {
List<LocalDate> list = new ArrayList();
long distance = ChronoUnit.DAYS.between(startDate, endDate);
@ -229,77 +67,4 @@ public class LeDateUtils {
int value = localDate.getDayOfWeek().getValue();
return value == 7 ? 1 : value + 1;
}
public static LocalDate getCurrentWeekDate(Integer week) {
if (week == 1) {
week = 7;
} else {
week = week - 1;
}
int day = 0;
int nowWeek = LocalDate.now().getDayOfWeek().getValue();
if (week < nowWeek) {
day = week + 7 - nowWeek;
} else if (week > nowWeek) {
day = week - nowWeek;
}
return LocalDate.now().plusDays((long)day);
}
public static LocalDateTime dateToLocalDateTime(Date date) {
ZoneId zoneId = ZoneId.systemDefault();
LocalDateTime localDateTime = null;
if (date != null) {
localDateTime = LocalDateTime.ofInstant(date.toInstant(), zoneId);
}
return localDateTime;
}
public static LocalDateTime getBeginDayOfLastWeek() {
Date date = TimeUtil.getBeginDayOfLastWeek();
return dateToLocalDateTime(date);
}
public static LocalDateTime getEndDayOfLastWeek() {
Date date = TimeUtil.getEndDayOfLastWeek();
return dateToLocalDateTime(date);
}
public static LocalDateTime getBeginDayOfLastMonth() {
Date date = TimeUtil.getBeginDayOfLastMonth();
return dateToLocalDateTime(date);
}
public static LocalDateTime getEndDayOfLastMonth() {
Date date = TimeUtil.getEndDayOfLastMonth();
return dateToLocalDateTime(date);
}
public static LocalDateTime dateStyleToLocalDateTime(String dateTime) {
try {
Date date = (new SimpleDateFormat("EEE MMM dd HH:mm:ss yyyy", Locale.UK)).parse(dateTime);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String strDate = sdf.format(date);
return LocalDateTime.parse(strDate, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
} catch (Throwable var4) {
throw var4;
}
}
public static String dateStyleToPatDateTime(String dateTime, String pattern) {
try {
Date date = (new SimpleDateFormat("EEE MMM dd HH:mm:ss yyyy", Locale.UK)).parse(dateTime);
SimpleDateFormat sdf = new SimpleDateFormat(pattern);
return sdf.format(date);
} catch (Throwable var4) {
throw var4;
}
}
public static void main(String[] args) {
System.out.println(getMonthMaxTime());
}
}

View File

@ -5,19 +5,19 @@ import org.springframework.util.StringUtils;
public class LeFieldCheckUtil {
static String idCardRegex = "(^[1-9]\\d{5}(18|19|20)\\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\\d{3}[0-9Xx]$)|(^[1-9]\\d{5}\\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\\d{3}$)";
static String emailRegex = "^([a-z0-9A-Z]+[-|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$";
private static String numRegex = "^[a-z0-9A-Z]+$";
private static String positiveIntRegex = "[0-9]+";
private static String amountRegex = "[0-9]{1,7}+";
public static boolean checkNum(String number) {
String numRegex = "^[a-z0-9A-Z]+$";
return baseRegexCheck(numRegex, number);
}
public static boolean checkPositiveInt(String positiveInt) {
String positiveIntRegex = "[0-9]+";
return baseRegexCheck(positiveIntRegex, positiveInt);
}
public static boolean checkAmountInt(String amountInt) {
String amountRegex = "[0-9]{1,7}+";
return baseRegexCheck(amountRegex, amountInt);
}

View File

@ -2,6 +2,7 @@ package com.pig4cloud.pigx.common.core.util;
import io.swagger.annotations.ApiModelProperty;
import jakarta.validation.Valid;
import lombok.Generated;
public class LeRequest<T> {
@ApiModelProperty("版本控制")
@ -17,54 +18,67 @@ public class LeRequest<T> {
@ApiModelProperty("签名")
private String sign;
@Generated
public String getVersion() {
return this.version;
}
@Generated
public String getNonceStr() {
return this.nonceStr;
}
@Generated
public String getTimestamp() {
return this.timestamp;
}
@Generated
public String getSignType() {
return this.signType;
}
@Generated
public T getContent() {
return this.content;
}
@Generated
public String getSign() {
return this.sign;
}
@Generated
public void setVersion(final String version) {
this.version = version;
}
@Generated
public void setNonceStr(final String nonceStr) {
this.nonceStr = nonceStr;
}
@Generated
public void setTimestamp(final String timestamp) {
this.timestamp = timestamp;
}
@Generated
public void setSignType(final String signType) {
this.signType = signType;
}
@Generated
public void setContent(final T content) {
this.content = content;
}
@Generated
public void setSign(final String sign) {
this.sign = sign;
}
@Generated
public boolean equals(final Object o) {
if (o == this) {
return true;
@ -148,10 +162,12 @@ public class LeRequest<T> {
}
}
@Generated
protected boolean canEqual(final Object other) {
return other instanceof LeRequest;
}
@Generated
public int hashCode() {
int PRIME = true;
int result = 1;
@ -170,6 +186,7 @@ public class LeRequest<T> {
return result;
}
@Generated
public String toString() {
String var10000 = this.getVersion();
return "LeRequest(version=" + var10000 + ", nonceStr=" + this.getNonceStr() + ", timestamp=" + this.getTimestamp() + ", signType=" + this.getSignType() + ", content=" + String.valueOf(this.getContent()) + ", sign=" + this.getSign() + ")";

View File

@ -1,6 +1,7 @@
package com.pig4cloud.pigx.common.core.util;
import io.swagger.annotations.ApiModel;
import lombok.Generated;
import net.xnzn.framework.config.response.ResponseWrapper;
@ApiModel(
@ -67,6 +68,7 @@ public class LeResponse<T> extends ResponseWrapper<T> {
return apiResult;
}
@Generated
public boolean equals(final Object o) {
if (o == this) {
return true;
@ -82,15 +84,18 @@ public class LeResponse<T> extends ResponseWrapper<T> {
}
}
@Generated
protected boolean canEqual(final Object other) {
return other instanceof LeResponse;
}
@Generated
public int hashCode() {
int result = super.hashCode();
return result;
}
@Generated
public String toString() {
return "LeResponse(super=" + super.toString() + ")";
}

View File

@ -1,5 +1,7 @@
package com.pig4cloud.pigx.common.core.util;
import lombok.Generated;
public enum RetCodeEnum {
SUCC(10000, "成功"),
SUCC_MAC_ORD(10001, "设备单号重复,特殊成功标识"),
@ -165,10 +167,12 @@ public enum RetCodeEnum {
this.desc = desc;
}
@Generated
public Integer getKey() {
return this.key;
}
@Generated
public String getDesc() {
return this.desc;
}

View File

@ -1,5 +1,6 @@
package com.pig4cloud.pigx.common.core.util;
import lombok.Generated;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.DisposableBean;
@ -12,13 +13,10 @@ import org.springframework.stereotype.Service;
@Service
@Lazy(false)
public class SpringContextHolder implements ApplicationContextAware, DisposableBean {
@Generated
private static final Logger log = LoggerFactory.getLogger(SpringContextHolder.class);
private static ApplicationContext applicationContext = null;
public static ApplicationContext getApplicationContext() {
return applicationContext;
}
public void setApplicationContext(ApplicationContext applicationContext) {
SpringContextHolder.applicationContext = applicationContext;
}
@ -33,7 +31,7 @@ public class SpringContextHolder implements ApplicationContextAware, DisposableB
public static void clearHolder() {
if (log.isDebugEnabled()) {
log.debug("清除SpringContextHolder中的ApplicationContext:" + String.valueOf(applicationContext));
log.debug("清除SpringContextHolder中的ApplicationContext:{}", applicationContext);
}
applicationContext = null;
@ -48,4 +46,9 @@ public class SpringContextHolder implements ApplicationContextAware, DisposableB
public void destroy() {
clearHolder();
}
@Generated
public static ApplicationContext getApplicationContext() {
return applicationContext;
}
}