-{
- private static final long serialVersionUID = -1185015143654744140L;
-
- /**
- * SecureRandom 的单例
- *
- */
- private static class Holder
- {
- static final SecureRandom numberGenerator = getSecureRandom();
- }
-
- /** 此UUID的最高64有效位 */
- private final long mostSigBits;
-
- /** 此UUID的最低64有效位 */
- private final long leastSigBits;
-
- /**
- * 私有构造
- *
- * @param data 数据
- */
- private UUID(byte[] data)
- {
- long msb = 0;
- long lsb = 0;
- assert data.length == 16 : "data must be 16 bytes in length";
- for (int i = 0; i < 8; i++)
- {
- msb = (msb << 8) | (data[i] & 0xff);
- }
- for (int i = 8; i < 16; i++)
- {
- lsb = (lsb << 8) | (data[i] & 0xff);
- }
- this.mostSigBits = msb;
- this.leastSigBits = lsb;
- }
-
- /**
- * 使用指定的数据构造新的 UUID。
- *
- * @param mostSigBits 用于 {@code UUID} 的最高有效 64 位
- * @param leastSigBits 用于 {@code UUID} 的最低有效 64 位
- */
- public UUID(long mostSigBits, long leastSigBits)
- {
- this.mostSigBits = mostSigBits;
- this.leastSigBits = leastSigBits;
- }
-
- /**
- * 获取类型 4(伪随机生成的)UUID 的静态工厂。 使用加密的本地线程伪随机数生成器生成该 UUID。
- *
- * @return 随机生成的 {@code UUID}
- */
- public static UUID fastUUID()
- {
- return randomUUID(false);
- }
-
- /**
- * 获取类型 4(伪随机生成的)UUID 的静态工厂。 使用加密的强伪随机数生成器生成该 UUID。
- *
- * @return 随机生成的 {@code UUID}
- */
- public static UUID randomUUID()
- {
- return randomUUID(true);
- }
-
- /**
- * 获取类型 4(伪随机生成的)UUID 的静态工厂。 使用加密的强伪随机数生成器生成该 UUID。
- *
- * @param isSecure 是否使用{@link SecureRandom}如果是可以获得更安全的随机码,否则可以得到更好的性能
- * @return 随机生成的 {@code UUID}
- */
- public static UUID randomUUID(boolean isSecure)
- {
- final Random ng = isSecure ? Holder.numberGenerator : getRandom();
-
- byte[] randomBytes = new byte[16];
- ng.nextBytes(randomBytes);
- randomBytes[6] &= 0x0f; /* clear version */
- randomBytes[6] |= 0x40; /* set to version 4 */
- randomBytes[8] &= 0x3f; /* clear variant */
- randomBytes[8] |= 0x80; /* set to IETF variant */
- return new UUID(randomBytes);
- }
-
- /**
- * 根据指定的字节数组获取类型 3(基于名称的)UUID 的静态工厂。
- *
- * @param name 用于构造 UUID 的字节数组。
- *
- * @return 根据指定数组生成的 {@code UUID}
- */
- public static UUID nameUUIDFromBytes(byte[] name)
- {
- MessageDigest md;
- try
- {
- md = MessageDigest.getInstance("MD5");
- }
- catch (NoSuchAlgorithmException nsae)
- {
- throw new InternalError("MD5 not supported");
- }
- byte[] md5Bytes = md.digest(name);
- md5Bytes[6] &= 0x0f; /* clear version */
- md5Bytes[6] |= 0x30; /* set to version 3 */
- md5Bytes[8] &= 0x3f; /* clear variant */
- md5Bytes[8] |= 0x80; /* set to IETF variant */
- return new UUID(md5Bytes);
- }
-
- /**
- * 根据 {@link #toString()} 方法中描述的字符串标准表示形式创建{@code UUID}。
- *
- * @param name 指定 {@code UUID} 字符串
- * @return 具有指定值的 {@code UUID}
- * @throws IllegalArgumentException 如果 name 与 {@link #toString} 中描述的字符串表示形式不符抛出此异常
- *
- */
- public static UUID fromString(String name)
- {
- String[] components = name.split("-");
- if (components.length != 5)
- {
- throw new IllegalArgumentException("Invalid UUID string: " + name);
- }
- for (int i = 0; i < 5; i++)
- {
- components[i] = "0x" + components[i];
- }
-
- long mostSigBits = Long.decode(components[0]).longValue();
- mostSigBits <<= 16;
- mostSigBits |= Long.decode(components[1]).longValue();
- mostSigBits <<= 16;
- mostSigBits |= Long.decode(components[2]).longValue();
-
- long leastSigBits = Long.decode(components[3]).longValue();
- leastSigBits <<= 48;
- leastSigBits |= Long.decode(components[4]).longValue();
-
- return new UUID(mostSigBits, leastSigBits);
- }
-
- /**
- * 返回此 UUID 的 128 位值中的最低有效 64 位。
- *
- * @return 此 UUID 的 128 位值中的最低有效 64 位。
- */
- public long getLeastSignificantBits()
- {
- return leastSigBits;
- }
-
- /**
- * 返回此 UUID 的 128 位值中的最高有效 64 位。
- *
- * @return 此 UUID 的 128 位值中最高有效 64 位。
- */
- public long getMostSignificantBits()
- {
- return mostSigBits;
- }
-
- /**
- * 与此 {@code UUID} 相关联的版本号. 版本号描述此 {@code UUID} 是如何生成的。
- *
- * 版本号具有以下含意:
- *
- * - 1 基于时间的 UUID
- *
- 2 DCE 安全 UUID
- *
- 3 基于名称的 UUID
- *
- 4 随机生成的 UUID
- *
- *
- * @return 此 {@code UUID} 的版本号
- */
- public int version()
- {
- // Version is bits masked by 0x000000000000F000 in MS long
- return (int) ((mostSigBits >> 12) & 0x0f);
- }
-
- /**
- * 与此 {@code UUID} 相关联的变体号。变体号描述 {@code UUID} 的布局。
- *
- * 变体号具有以下含意:
- *
- * - 0 为 NCS 向后兼容保留
- *
- 2 IETF RFC 4122(Leach-Salz), 用于此类
- *
- 6 保留,微软向后兼容
- *
- 7 保留供以后定义使用
- *
- *
- * @return 此 {@code UUID} 相关联的变体号
- */
- public int variant()
- {
- // This field is composed of a varying number of bits.
- // 0 - - Reserved for NCS backward compatibility
- // 1 0 - The IETF aka Leach-Salz variant (used by this class)
- // 1 1 0 Reserved, Microsoft backward compatibility
- // 1 1 1 Reserved for future definition.
- return (int) ((leastSigBits >>> (64 - (leastSigBits >>> 62))) & (leastSigBits >> 63));
- }
-
- /**
- * 与此 UUID 相关联的时间戳值。
- *
- *
- * 60 位的时间戳值根据此 {@code UUID} 的 time_low、time_mid 和 time_hi 字段构造。
- * 所得到的时间戳以 100 毫微秒为单位,从 UTC(通用协调时间) 1582 年 10 月 15 日零时开始。
- *
- *
- * 时间戳值仅在在基于时间的 UUID(其 version 类型为 1)中才有意义。
- * 如果此 {@code UUID} 不是基于时间的 UUID,则此方法抛出 UnsupportedOperationException。
- *
- * @throws UnsupportedOperationException 如果此 {@code UUID} 不是 version 为 1 的 UUID。
- */
- public long timestamp() throws UnsupportedOperationException
- {
- checkTimeBase();
- return (mostSigBits & 0x0FFFL) << 48//
- | ((mostSigBits >> 16) & 0x0FFFFL) << 32//
- | mostSigBits >>> 32;
- }
-
- /**
- * 与此 UUID 相关联的时钟序列值。
- *
- *
- * 14 位的时钟序列值根据此 UUID 的 clock_seq 字段构造。clock_seq 字段用于保证在基于时间的 UUID 中的时间唯一性。
- *
- * {@code clockSequence} 值仅在基于时间的 UUID(其 version 类型为 1)中才有意义。 如果此 UUID 不是基于时间的 UUID,则此方法抛出
- * UnsupportedOperationException。
- *
- * @return 此 {@code UUID} 的时钟序列
- *
- * @throws UnsupportedOperationException 如果此 UUID 的 version 不为 1
- */
- public int clockSequence() throws UnsupportedOperationException
- {
- checkTimeBase();
- return (int) ((leastSigBits & 0x3FFF000000000000L) >>> 48);
- }
-
- /**
- * 与此 UUID 相关的节点值。
- *
- *
- * 48 位的节点值根据此 UUID 的 node 字段构造。此字段旨在用于保存机器的 IEEE 802 地址,该地址用于生成此 UUID 以保证空间唯一性。
- *
- * 节点值仅在基于时间的 UUID(其 version 类型为 1)中才有意义。
- * 如果此 UUID 不是基于时间的 UUID,则此方法抛出 UnsupportedOperationException。
- *
- * @return 此 {@code UUID} 的节点值
- *
- * @throws UnsupportedOperationException 如果此 UUID 的 version 不为 1
- */
- public long node() throws UnsupportedOperationException
- {
- checkTimeBase();
- return leastSigBits & 0x0000FFFFFFFFFFFFL;
- }
-
- /**
- * 返回此{@code UUID} 的字符串表现形式。
- *
- *
- * UUID 的字符串表示形式由此 BNF 描述:
- *
- *
- * {@code
- * UUID = ----
- * time_low = 4*
- * time_mid = 2*
- * time_high_and_version = 2*
- * variant_and_sequence = 2*
- * node = 6*
- * hexOctet =
- * hexDigit = [0-9a-fA-F]
- * }
- *
- *
- *
- *
- * @return 此{@code UUID} 的字符串表现形式
- * @see #toString(boolean)
- */
- @Override
- public String toString()
- {
- return toString(false);
- }
-
- /**
- * 返回此{@code UUID} 的字符串表现形式。
- *
- *
- * UUID 的字符串表示形式由此 BNF 描述:
- *
- *
- * {@code
- * UUID = ----
- * time_low = 4*
- * time_mid = 2*
- * time_high_and_version = 2*
- * variant_and_sequence = 2*
- * node = 6*
- * hexOctet =
- * hexDigit = [0-9a-fA-F]
- * }
- *
- *
- *
- *
- * @param isSimple 是否简单模式,简单模式为不带'-'的UUID字符串
- * @return 此{@code UUID} 的字符串表现形式
- */
- public String toString(boolean isSimple)
- {
- final StringBuilder builder = new StringBuilder(isSimple ? 32 : 36);
- // time_low
- builder.append(digits(mostSigBits >> 32, 8));
- if (false == isSimple)
- {
- builder.append('-');
- }
- // time_mid
- builder.append(digits(mostSigBits >> 16, 4));
- if (false == isSimple)
- {
- builder.append('-');
- }
- // time_high_and_version
- builder.append(digits(mostSigBits, 4));
- if (false == isSimple)
- {
- builder.append('-');
- }
- // variant_and_sequence
- builder.append(digits(leastSigBits >> 48, 4));
- if (false == isSimple)
- {
- builder.append('-');
- }
- // node
- builder.append(digits(leastSigBits, 12));
-
- return builder.toString();
- }
-
- /**
- * 返回此 UUID 的哈希码。
- *
- * @return UUID 的哈希码值。
- */
- @Override
- public int hashCode()
- {
- long hilo = mostSigBits ^ leastSigBits;
- return ((int) (hilo >> 32)) ^ (int) hilo;
- }
-
- /**
- * 将此对象与指定对象比较。
- *
- * 当且仅当参数不为 {@code null}、而是一个 UUID 对象、具有与此 UUID 相同的 varriant、包含相同的值(每一位均相同)时,结果才为 {@code true}。
- *
- * @param obj 要与之比较的对象
- *
- * @return 如果对象相同,则返回 {@code true};否则返回 {@code false}
- */
- @Override
- public boolean equals(Object obj)
- {
- if ((null == obj) || (obj.getClass() != UUID.class))
- {
- return false;
- }
- UUID id = (UUID) obj;
- return (mostSigBits == id.mostSigBits && leastSigBits == id.leastSigBits);
- }
-
- // Comparison Operations
-
- /**
- * 将此 UUID 与指定的 UUID 比较。
- *
- *
- * 如果两个 UUID 不同,且第一个 UUID 的最高有效字段大于第二个 UUID 的对应字段,则第一个 UUID 大于第二个 UUID。
- *
- * @param val 与此 UUID 比较的 UUID
- *
- * @return 在此 UUID 小于、等于或大于 val 时,分别返回 -1、0 或 1。
- *
- */
- @Override
- public int compareTo(UUID val)
- {
- // The ordering is intentionally set up so that the UUIDs
- // can simply be numerically compared as two numbers
- return (this.mostSigBits < val.mostSigBits ? -1 : //
- (this.mostSigBits > val.mostSigBits ? 1 : //
- (this.leastSigBits < val.leastSigBits ? -1 : //
- (this.leastSigBits > val.leastSigBits ? 1 : //
- 0))));
- }
-
- // -------------------------------------------------------------------------------------------------------------------
- // Private method start
- /**
- * 返回指定数字对应的hex值
- *
- * @param val 值
- * @param digits 位
- * @return 值
- */
- private static String digits(long val, int digits)
- {
- long hi = 1L << (digits * 4);
- return Long.toHexString(hi | (val & (hi - 1))).substring(1);
- }
-
- /**
- * 检查是否为time-based版本UUID
- */
- private void checkTimeBase()
- {
- if (version() != 1)
- {
- throw new UnsupportedOperationException("Not a time-based UUID");
- }
- }
-
- /**
- * 获取{@link SecureRandom},类提供加密的强随机数生成器 (RNG)
- *
- * @return {@link SecureRandom}
- */
- public static SecureRandom getSecureRandom()
- {
- try
- {
- return SecureRandom.getInstance("SHA1PRNG");
- }
- catch (NoSuchAlgorithmException e)
- {
- throw new UtilException(e);
- }
- }
-
- /**
- * 获取随机数生成器对象
- * ThreadLocalRandom是JDK 7之后提供并发产生随机数,能够解决多个线程发生的竞争争夺。
- *
- * @return {@link ThreadLocalRandom}
- */
- public static ThreadLocalRandom getRandom()
- {
- return ThreadLocalRandom.current();
- }
-}
diff --git a/hchyun/hchyun-framework/pom.xml b/hchyun/hchyun-framework/pom.xml
deleted file mode 100644
index 01d63dc..0000000
--- a/hchyun/hchyun-framework/pom.xml
+++ /dev/null
@@ -1,64 +0,0 @@
-
-
-
- hchyun
- com.hchyun
- 3.2.0
-
- 4.0.0
-
- hchyun-framework
-
-
- framework框架核心
-
-
-
-
-
-
- org.springframework.boot
- spring-boot-starter-web
-
-
-
-
- org.springframework.boot
- spring-boot-starter-aop
-
-
-
-
- com.alibaba
- druid-spring-boot-starter
-
-
-
-
- com.github.penggle
- kaptcha
-
-
- javax.servlet-api
- javax.servlet
-
-
-
-
-
-
- com.github.oshi
- oshi-core
-
-
-
-
- com.hchyun
- hchyun-system
-
-
-
-
-
\ No newline at end of file
diff --git a/hchyun/hchyun-framework/src/main/java/com/hchyun/framework/aspectj/DataScopeAspect.java b/hchyun/hchyun-framework/src/main/java/com/hchyun/framework/aspectj/DataScopeAspect.java
deleted file mode 100644
index b18e5b6..0000000
--- a/hchyun/hchyun-framework/src/main/java/com/hchyun/framework/aspectj/DataScopeAspect.java
+++ /dev/null
@@ -1,169 +0,0 @@
-package com.hchyun.framework.aspectj;
-
-import java.lang.reflect.Method;
-import org.aspectj.lang.JoinPoint;
-import org.aspectj.lang.Signature;
-import org.aspectj.lang.annotation.Aspect;
-import org.aspectj.lang.annotation.Before;
-import org.aspectj.lang.annotation.Pointcut;
-import org.aspectj.lang.reflect.MethodSignature;
-import org.springframework.stereotype.Component;
-import com.hchyun.common.annotation.DataScope;
-import com.hchyun.common.core.entity.BaseEntity;
-import com.hchyun.common.core.entity.entity.SysRole;
-import com.hchyun.common.core.entity.entity.SysUser;
-import com.hchyun.common.core.entity.model.LoginUser;
-import com.hchyun.common.utils.ServletUtils;
-import com.hchyun.common.utils.StringUtils;
-import com.hchyun.common.utils.spring.SpringUtils;
-import com.hchyun.framework.web.service.TokenService;
-
-/**
- * 数据过滤处理
- *
- * @author hchyun
- */
-@Aspect
-@Component
-public class DataScopeAspect
-{
- /**
- * 全部数据权限
- */
- public static final String DATA_SCOPE_ALL = "1";
-
- /**
- * 自定数据权限
- */
- public static final String DATA_SCOPE_CUSTOM = "2";
-
- /**
- * 部门数据权限
- */
- public static final String DATA_SCOPE_DEPT = "3";
-
- /**
- * 部门及以下数据权限
- */
- public static final String DATA_SCOPE_DEPT_AND_CHILD = "4";
-
- /**
- * 仅本人数据权限
- */
- public static final String DATA_SCOPE_SELF = "5";
-
- /**
- * 数据权限过滤关键字
- */
- public static final String DATA_SCOPE = "dataScope";
-
- // 配置织入点
- @Pointcut("@annotation(com.hchyun.common.annotation.DataScope)")
- public void dataScopePointCut()
- {
- }
-
- @Before("dataScopePointCut()")
- public void doBefore(JoinPoint point) throws Throwable
- {
- handleDataScope(point);
- }
-
- protected void handleDataScope(final JoinPoint joinPoint)
- {
- // 获得注解
- DataScope controllerDataScope = getAnnotationLog(joinPoint);
- if (controllerDataScope == null)
- {
- return;
- }
- // 获取当前的用户
- LoginUser loginUser = SpringUtils.getBean(TokenService.class).getLoginUser(ServletUtils.getRequest());
- if (StringUtils.isNotNull(loginUser))
- {
- SysUser currentUser = loginUser.getUser();
- // 如果是超级管理员,则不过滤数据
- if (StringUtils.isNotNull(currentUser) && !currentUser.isAdmin())
- {
- dataScopeFilter(joinPoint, currentUser, controllerDataScope.deptAlias(),
- controllerDataScope.userAlias());
- }
- }
- }
-
- /**
- * 数据范围过滤
- *
- * @param joinPoint 切点
- * @param user 用户
- * @param userAlias 别名
- */
- public static void dataScopeFilter(JoinPoint joinPoint, SysUser user, String deptAlias, String userAlias)
- {
- StringBuilder sqlString = new StringBuilder();
-
- for (SysRole role : user.getRoles())
- {
- String dataScope = role.getDataScope();
- if (DATA_SCOPE_ALL.equals(dataScope))
- {
- sqlString = new StringBuilder();
- break;
- }
- else if (DATA_SCOPE_CUSTOM.equals(dataScope))
- {
- sqlString.append(StringUtils.format(
- " OR {}.dept_id IN ( SELECT dept_id FROM sys_role_dept WHERE role_id = {} ) ", deptAlias,
- role.getRoleId()));
- }
- else if (DATA_SCOPE_DEPT.equals(dataScope))
- {
- sqlString.append(StringUtils.format(" OR {}.dept_id = {} ", deptAlias, user.getDeptId()));
- }
- else if (DATA_SCOPE_DEPT_AND_CHILD.equals(dataScope))
- {
- sqlString.append(StringUtils.format(
- " OR {}.dept_id IN ( SELECT dept_id FROM sys_dept WHERE dept_id = {} or find_in_set( {} , ancestors ) )",
- deptAlias, user.getDeptId(), user.getDeptId()));
- }
- else if (DATA_SCOPE_SELF.equals(dataScope))
- {
- if (StringUtils.isNotBlank(userAlias))
- {
- sqlString.append(StringUtils.format(" OR {}.user_id = {} ", userAlias, user.getUserId()));
- }
- else
- {
- // 数据权限为仅本人且没有userAlias别名不查询任何数据
- sqlString.append(" OR 1=0 ");
- }
- }
- }
-
- if (StringUtils.isNotBlank(sqlString.toString()))
- {
- Object params = joinPoint.getArgs()[0];
- if (StringUtils.isNotNull(params) && params instanceof BaseEntity)
- {
- BaseEntity baseEntity = (BaseEntity) params;
- baseEntity.getParams().put(DATA_SCOPE, " AND (" + sqlString.substring(4) + ")");
- }
- }
- }
-
- /**
- * 是否存在注解,如果存在就获取
- */
- private DataScope getAnnotationLog(JoinPoint joinPoint)
- {
- Signature signature = joinPoint.getSignature();
- MethodSignature methodSignature = (MethodSignature) signature;
- Method method = methodSignature.getMethod();
-
- if (method != null)
- {
- return method.getAnnotation(DataScope.class);
- }
- return null;
- }
-}
diff --git a/hchyun/hchyun-framework/src/main/java/com/hchyun/framework/aspectj/DataSourceAspect.java b/hchyun/hchyun-framework/src/main/java/com/hchyun/framework/aspectj/DataSourceAspect.java
deleted file mode 100644
index d065c81..0000000
--- a/hchyun/hchyun-framework/src/main/java/com/hchyun/framework/aspectj/DataSourceAspect.java
+++ /dev/null
@@ -1,72 +0,0 @@
-package com.hchyun.framework.aspectj;
-
-import java.util.Objects;
-import org.aspectj.lang.ProceedingJoinPoint;
-import org.aspectj.lang.annotation.Around;
-import org.aspectj.lang.annotation.Aspect;
-import org.aspectj.lang.annotation.Pointcut;
-import org.aspectj.lang.reflect.MethodSignature;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.core.annotation.AnnotationUtils;
-import org.springframework.core.annotation.Order;
-import org.springframework.stereotype.Component;
-import com.hchyun.common.annotation.DataSource;
-import com.hchyun.common.utils.StringUtils;
-import com.hchyun.framework.datasource.DynamicDataSourceContextHolder;
-
-/**
- * 多数据源处理
- *
- * @author hchyun
- */
-@Aspect
-@Order(1)
-@Component
-public class DataSourceAspect
-{
- protected Logger logger = LoggerFactory.getLogger(getClass());
-
- @Pointcut("@annotation(com.hchyun.common.annotation.DataSource)"
- + "|| @within(com.hchyun.common.annotation.DataSource)")
- public void dsPointCut()
- {
-
- }
-
- @Around("dsPointCut()")
- public Object around(ProceedingJoinPoint point) throws Throwable
- {
- DataSource dataSource = getDataSource(point);
-
- if (StringUtils.isNotNull(dataSource))
- {
- DynamicDataSourceContextHolder.setDataSourceType(dataSource.value().name());
- }
-
- try
- {
- return point.proceed();
- }
- finally
- {
- // 销毁数据源 在执行方法之后
- DynamicDataSourceContextHolder.clearDataSourceType();
- }
- }
-
- /**
- * 获取需要切换的数据源
- */
- public DataSource getDataSource(ProceedingJoinPoint point)
- {
- MethodSignature signature = (MethodSignature) point.getSignature();
- DataSource dataSource = AnnotationUtils.findAnnotation(signature.getMethod(), DataSource.class);
- if (Objects.nonNull(dataSource))
- {
- return dataSource;
- }
-
- return AnnotationUtils.findAnnotation(signature.getDeclaringType(), DataSource.class);
- }
-}
diff --git a/hchyun/hchyun-framework/src/main/java/com/hchyun/framework/aspectj/LogAspect.java b/hchyun/hchyun-framework/src/main/java/com/hchyun/framework/aspectj/LogAspect.java
deleted file mode 100644
index 279bb8f..0000000
--- a/hchyun/hchyun-framework/src/main/java/com/hchyun/framework/aspectj/LogAspect.java
+++ /dev/null
@@ -1,217 +0,0 @@
-package com.hchyun.framework.aspectj;
-
-import java.lang.reflect.Method;
-import java.util.Map;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import org.aspectj.lang.JoinPoint;
-import org.aspectj.lang.Signature;
-import org.aspectj.lang.annotation.AfterReturning;
-import org.aspectj.lang.annotation.AfterThrowing;
-import org.aspectj.lang.annotation.Aspect;
-import org.aspectj.lang.annotation.Pointcut;
-import org.aspectj.lang.reflect.MethodSignature;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.stereotype.Component;
-import org.springframework.web.multipart.MultipartFile;
-import org.springframework.web.servlet.HandlerMapping;
-import com.alibaba.fastjson.JSON;
-import com.hchyun.common.annotation.Log;
-import com.hchyun.common.core.entity.model.LoginUser;
-import com.hchyun.common.enums.BusinessStatus;
-import com.hchyun.common.enums.HttpMethod;
-import com.hchyun.common.utils.ServletUtils;
-import com.hchyun.common.utils.StringUtils;
-import com.hchyun.common.utils.ip.IpUtils;
-import com.hchyun.common.utils.spring.SpringUtils;
-import com.hchyun.framework.dao.AsyncDao;
-import com.hchyun.framework.dao.factory.AsyncFactory;
-import com.hchyun.framework.web.service.TokenService;
-import com.hchyun.system.entity.SysOperLog;
-
-/**
- * 操作日志记录处理
- *
- * @author hchyun
- */
-@Aspect
-@Component
-public class LogAspect
-{
- private static final Logger log = LoggerFactory.getLogger(LogAspect.class);
-
- // 配置织入点
- @Pointcut("@annotation(com.hchyun.common.annotation.Log)")
- public void logPointCut()
- {
- }
-
- /**
- * 处理完请求后执行
- *
- * @param joinPoint 切点
- */
- @AfterReturning(pointcut = "logPointCut()", returning = "jsonResult")
- public void doAfterReturning(JoinPoint joinPoint, Object jsonResult)
- {
- handleLog(joinPoint, null, jsonResult);
- }
-
- /**
- * 拦截异常操作
- *
- * @param joinPoint 切点
- * @param e 异常
- */
- @AfterThrowing(value = "logPointCut()", throwing = "e")
- public void doAfterThrowing(JoinPoint joinPoint, Exception e)
- {
- handleLog(joinPoint, e, null);
- }
-
- protected void handleLog(final JoinPoint joinPoint, final Exception e, Object jsonResult)
- {
- try
- {
- // 获得注解
- Log controllerLog = getAnnotationLog(joinPoint);
- if (controllerLog == null)
- {
- return;
- }
-
- // 获取当前的用户
- LoginUser loginUser = SpringUtils.getBean(TokenService.class).getLoginUser(ServletUtils.getRequest());
-
- // *========数据库日志=========*//
- SysOperLog operLog = new SysOperLog();
- operLog.setStatus(BusinessStatus.SUCCESS.ordinal());
- // 请求的地址
- String ip = IpUtils.getIpAddr(ServletUtils.getRequest());
- operLog.setOperIp(ip);
- // 返回参数
- operLog.setJsonResult(JSON.toJSONString(jsonResult));
-
- operLog.setOperUrl(ServletUtils.getRequest().getRequestURI());
- if (loginUser != null)
- {
- operLog.setOperName(loginUser.getUsername());
- }
-
- if (e != null)
- {
- operLog.setStatus(BusinessStatus.FAIL.ordinal());
- operLog.setErrorMsg(StringUtils.substring(e.getMessage(), 0, 2000));
- }
- // 设置方法名称
- String className = joinPoint.getTarget().getClass().getName();
- String methodName = joinPoint.getSignature().getName();
- operLog.setMethod(className + "." + methodName + "()");
- // 设置请求方式
- operLog.setRequestMethod(ServletUtils.getRequest().getMethod());
- // 处理设置注解上的参数
- getControllerMethodDescription(joinPoint, controllerLog, operLog);
- // 保存数据库
- AsyncDao.me().execute(AsyncFactory.recordOper(operLog));
- }
- catch (Exception exp)
- {
- // 记录本地异常日志
- log.error("==前置通知异常==");
- log.error("异常信息:{}", exp.getMessage());
- exp.printStackTrace();
- }
- }
-
- /**
- * 获取注解中对方法的描述信息 用于Controller层注解
- *
- * @param log 日志
- * @param operLog 操作日志
- * @throws Exception
- */
- public void getControllerMethodDescription(JoinPoint joinPoint, Log log, SysOperLog operLog) throws Exception
- {
- // 设置action动作
- operLog.setBusinessType(log.businessType().ordinal());
- // 设置标题
- operLog.setTitle(log.title());
- // 设置操作人类别
- operLog.setOperatorType(log.operatorType().ordinal());
- // 是否需要保存request,参数和值
- if (log.isSaveRequestData())
- {
- // 获取参数的信息,传入到数据库中。
- setRequestValue(joinPoint, operLog);
- }
- }
-
- /**
- * 获取请求的参数,放到log中
- *
- * @param operLog 操作日志
- * @throws Exception 异常
- */
- private void setRequestValue(JoinPoint joinPoint, SysOperLog operLog) throws Exception
- {
- String requestMethod = operLog.getRequestMethod();
- if (HttpMethod.PUT.name().equals(requestMethod) || HttpMethod.POST.name().equals(requestMethod))
- {
- String params = argsArrayToString(joinPoint.getArgs());
- operLog.setOperParam(StringUtils.substring(params, 0, 2000));
- }
- else
- {
- Map, ?> paramsMap = (Map, ?>) ServletUtils.getRequest().getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE);
- operLog.setOperParam(StringUtils.substring(paramsMap.toString(), 0, 2000));
- }
- }
-
- /**
- * 是否存在注解,如果存在就获取
- */
- private Log getAnnotationLog(JoinPoint joinPoint) throws Exception
- {
- Signature signature = joinPoint.getSignature();
- MethodSignature methodSignature = (MethodSignature) signature;
- Method method = methodSignature.getMethod();
-
- if (method != null)
- {
- return method.getAnnotation(Log.class);
- }
- return null;
- }
-
- /**
- * 参数拼装
- */
- private String argsArrayToString(Object[] paramsArray)
- {
- String params = "";
- if (paramsArray != null && paramsArray.length > 0)
- {
- for (int i = 0; i < paramsArray.length; i++)
- {
- if (!isFilterObject(paramsArray[i]))
- {
- Object jsonObj = JSON.toJSON(paramsArray[i]);
- params += jsonObj.toString() + " ";
- }
- }
- }
- return params.trim();
- }
-
- /**
- * 判断是否需要过滤的对象。
- *
- * @param o 对象信息。
- * @return 如果是需要过滤的对象,则返回true;否则返回false。
- */
- public boolean isFilterObject(final Object o)
- {
- return o instanceof MultipartFile || o instanceof HttpServletRequest || o instanceof HttpServletResponse;
- }
-}
diff --git a/hchyun/hchyun-framework/src/main/java/com/hchyun/framework/config/ApplicationConfig.java b/hchyun/hchyun-framework/src/main/java/com/hchyun/framework/config/ApplicationConfig.java
deleted file mode 100644
index 6cfaf79..0000000
--- a/hchyun/hchyun-framework/src/main/java/com/hchyun/framework/config/ApplicationConfig.java
+++ /dev/null
@@ -1,30 +0,0 @@
-package com.hchyun.framework.config;
-
-import java.util.TimeZone;
-import org.mybatis.spring.annotation.MapperScan;
-import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.context.annotation.EnableAspectJAutoProxy;
-
-/**
- * 程序注解配置
- *
- * @author hchyun
- */
-@Configuration
-// 表示通过aop框架暴露该代理对象,AopContext能够访问
-@EnableAspectJAutoProxy(exposeProxy = true)
-// 指定要扫描的dao类的包的路径
-@MapperScan("com.hchyun.**.dao")
-public class ApplicationConfig
-{
- /**
- * 时区配置
- */
- @Bean
- public Jackson2ObjectMapperBuilderCustomizer jacksonObjectMapperCustomization()
- {
- return jacksonObjectMapperBuilder -> jacksonObjectMapperBuilder.timeZone(TimeZone.getDefault());
- }
-}
diff --git a/hchyun/hchyun-framework/src/main/java/com/hchyun/framework/config/CaptchaConfig.java b/hchyun/hchyun-framework/src/main/java/com/hchyun/framework/config/CaptchaConfig.java
deleted file mode 100644
index 6b0372f..0000000
--- a/hchyun/hchyun-framework/src/main/java/com/hchyun/framework/config/CaptchaConfig.java
+++ /dev/null
@@ -1,83 +0,0 @@
-package com.hchyun.framework.config;
-
-import java.util.Properties;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-import com.google.code.kaptcha.impl.DefaultKaptcha;
-import com.google.code.kaptcha.util.Config;
-import static com.google.code.kaptcha.Constants.*;
-
-/**
- * 验证码配置
- *
- * @author hchyun
- */
-@Configuration
-public class CaptchaConfig
-{
- @Bean(name = "captchaProducer")
- public DefaultKaptcha getKaptchaBean()
- {
- DefaultKaptcha defaultKaptcha = new DefaultKaptcha();
- Properties properties = new Properties();
- // 是否有边框 默认为true 我们可以自己设置yes,no
- properties.setProperty(KAPTCHA_BORDER, "yes");
- // 验证码文本字符颜色 默认为Color.BLACK
- properties.setProperty(KAPTCHA_TEXTPRODUCER_FONT_COLOR, "black");
- // 验证码图片宽度 默认为200
- properties.setProperty(KAPTCHA_IMAGE_WIDTH, "160");
- // 验证码图片高度 默认为50
- properties.setProperty(KAPTCHA_IMAGE_HEIGHT, "60");
- // 验证码文本字符大小 默认为40
- properties.setProperty(KAPTCHA_TEXTPRODUCER_FONT_SIZE, "38");
- // KAPTCHA_SESSION_KEY
- properties.setProperty(KAPTCHA_SESSION_CONFIG_KEY, "kaptchaCode");
- // 验证码文本字符长度 默认为5
- properties.setProperty(KAPTCHA_TEXTPRODUCER_CHAR_LENGTH, "4");
- // 验证码文本字体样式 默认为new Font("Arial", 1, fontSize), new Font("Courier", 1, fontSize)
- properties.setProperty(KAPTCHA_TEXTPRODUCER_FONT_NAMES, "Arial,Courier");
- // 图片样式 水纹com.google.code.kaptcha.impl.WaterRipple 鱼眼com.google.code.kaptcha.impl.FishEyeGimpy 阴影com.google.code.kaptcha.impl.ShadowGimpy
- properties.setProperty(KAPTCHA_OBSCURIFICATOR_IMPL, "com.google.code.kaptcha.impl.ShadowGimpy");
- Config config = new Config(properties);
- defaultKaptcha.setConfig(config);
- return defaultKaptcha;
- }
-
- @Bean(name = "captchaProducerMath")
- public DefaultKaptcha getKaptchaBeanMath()
- {
- DefaultKaptcha defaultKaptcha = new DefaultKaptcha();
- Properties properties = new Properties();
- // 是否有边框 默认为true 我们可以自己设置yes,no
- properties.setProperty(KAPTCHA_BORDER, "yes");
- // 边框颜色 默认为Color.BLACK
- properties.setProperty(KAPTCHA_BORDER_COLOR, "105,179,90");
- // 验证码文本字符颜色 默认为Color.BLACK
- properties.setProperty(KAPTCHA_TEXTPRODUCER_FONT_COLOR, "blue");
- // 验证码图片宽度 默认为200
- properties.setProperty(KAPTCHA_IMAGE_WIDTH, "160");
- // 验证码图片高度 默认为50
- properties.setProperty(KAPTCHA_IMAGE_HEIGHT, "60");
- // 验证码文本字符大小 默认为40
- properties.setProperty(KAPTCHA_TEXTPRODUCER_FONT_SIZE, "35");
- // KAPTCHA_SESSION_KEY
- properties.setProperty(KAPTCHA_SESSION_CONFIG_KEY, "kaptchaCodeMath");
- // 验证码文本生成器
- properties.setProperty(KAPTCHA_TEXTPRODUCER_IMPL, "com.hchyun.framework.config.KaptchaTextCreator");
- // 验证码文本字符间距 默认为2
- properties.setProperty(KAPTCHA_TEXTPRODUCER_CHAR_SPACE, "3");
- // 验证码文本字符长度 默认为5
- properties.setProperty(KAPTCHA_TEXTPRODUCER_CHAR_LENGTH, "6");
- // 验证码文本字体样式 默认为new Font("Arial", 1, fontSize), new Font("Courier", 1, fontSize)
- properties.setProperty(KAPTCHA_TEXTPRODUCER_FONT_NAMES, "Arial,Courier");
- // 验证码噪点颜色 默认为Color.BLACK
- properties.setProperty(KAPTCHA_NOISE_COLOR, "white");
- // 干扰实现类
- properties.setProperty(KAPTCHA_NOISE_IMPL, "com.google.code.kaptcha.impl.NoNoise");
- // 图片样式 水纹com.google.code.kaptcha.impl.WaterRipple 鱼眼com.google.code.kaptcha.impl.FishEyeGimpy 阴影com.google.code.kaptcha.impl.ShadowGimpy
- properties.setProperty(KAPTCHA_OBSCURIFICATOR_IMPL, "com.google.code.kaptcha.impl.ShadowGimpy");
- Config config = new Config(properties);
- defaultKaptcha.setConfig(config);
- return defaultKaptcha;
- }
-}
diff --git a/hchyun/hchyun-framework/src/main/java/com/hchyun/framework/config/DruidConfig.java b/hchyun/hchyun-framework/src/main/java/com/hchyun/framework/config/DruidConfig.java
deleted file mode 100644
index dfe8987..0000000
--- a/hchyun/hchyun-framework/src/main/java/com/hchyun/framework/config/DruidConfig.java
+++ /dev/null
@@ -1,126 +0,0 @@
-package com.hchyun.framework.config;
-
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.Map;
-import javax.servlet.Filter;
-import javax.servlet.FilterChain;
-import javax.servlet.ServletException;
-import javax.servlet.ServletRequest;
-import javax.servlet.ServletResponse;
-import javax.sql.DataSource;
-import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
-import org.springframework.boot.context.properties.ConfigurationProperties;
-import org.springframework.boot.web.servlet.FilterRegistrationBean;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.context.annotation.Primary;
-import com.alibaba.druid.pool.DruidDataSource;
-import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceBuilder;
-import com.alibaba.druid.spring.boot.autoconfigure.properties.DruidStatProperties;
-import com.alibaba.druid.util.Utils;
-import com.hchyun.common.enums.DataSourceType;
-import com.hchyun.common.utils.spring.SpringUtils;
-import com.hchyun.framework.config.properties.DruidProperties;
-import com.hchyun.framework.datasource.DynamicDataSource;
-
-/**
- * druid 配置多数据源
- *
- * @author hchyun
- */
-@Configuration
-public class DruidConfig
-{
- @Bean
- @ConfigurationProperties("spring.datasource.druid.master")
- public DataSource masterDataSource(DruidProperties druidProperties)
- {
- DruidDataSource dataSource = DruidDataSourceBuilder.create().build();
- return druidProperties.dataSource(dataSource);
- }
-
- @Bean
- @ConfigurationProperties("spring.datasource.druid.slave")
- @ConditionalOnProperty(prefix = "spring.datasource.druid.slave", name = "enabled", havingValue = "true")
- public DataSource slaveDataSource(DruidProperties druidProperties)
- {
- DruidDataSource dataSource = DruidDataSourceBuilder.create().build();
- return druidProperties.dataSource(dataSource);
- }
-
- @Bean(name = "dynamicDataSource")
- @Primary
- public DynamicDataSource dataSource(DataSource masterDataSource)
- {
- Map