OCT
REM: 1. 重构内部类中枚举到独立类 2. 删除Redis等无用代码 3. 增加处置任务数据库查询接口
This commit is contained in:
parent
b96a9c6ce7
commit
84c7539c69
|
@ -1,30 +0,0 @@
|
||||||
package com.dispose.annotation;
|
|
||||||
|
|
||||||
import com.dispose.annotation.validator.UserIdValidator;
|
|
||||||
import java.lang.annotation.Documented;
|
|
||||||
import java.lang.annotation.ElementType;
|
|
||||||
import java.lang.annotation.Retention;
|
|
||||||
import java.lang.annotation.RetentionPolicy;
|
|
||||||
import java.lang.annotation.Target;
|
|
||||||
import javax.validation.Constraint;
|
|
||||||
import javax.validation.Payload;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author phoenix
|
|
||||||
* @date 2020年2月8日
|
|
||||||
*/
|
|
||||||
@Documented
|
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
|
||||||
@Target({ElementType.FIELD, ElementType.ANNOTATION_TYPE})
|
|
||||||
//指定注解的处理类
|
|
||||||
@Constraint(validatedBy = {UserIdValidator.class})
|
|
||||||
public @interface UserId {
|
|
||||||
|
|
||||||
String value() default "";
|
|
||||||
|
|
||||||
String message() default "用户 ID 不存在";
|
|
||||||
|
|
||||||
Class<?>[] groups() default {};
|
|
||||||
|
|
||||||
Class<? extends Payload>[] payload() default {};
|
|
||||||
}
|
|
|
@ -1,17 +0,0 @@
|
||||||
package com.dispose.annotation.bodyencdec;
|
|
||||||
|
|
||||||
import java.lang.annotation.ElementType;
|
|
||||||
import java.lang.annotation.Retention;
|
|
||||||
import java.lang.annotation.RetentionPolicy;
|
|
||||||
import java.lang.annotation.Target;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author phoenix
|
|
||||||
* @date 2020年2月10日
|
|
||||||
*/
|
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
|
||||||
@Target(ElementType.METHOD)
|
|
||||||
public @interface ReqDec {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,17 +0,0 @@
|
||||||
package com.dispose.annotation.bodyencdec;
|
|
||||||
|
|
||||||
import java.lang.annotation.ElementType;
|
|
||||||
import java.lang.annotation.Retention;
|
|
||||||
import java.lang.annotation.RetentionPolicy;
|
|
||||||
import java.lang.annotation.Target;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author phoenix
|
|
||||||
* @date 2020年2月10日
|
|
||||||
*/
|
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
|
||||||
@Target(ElementType.METHOD)
|
|
||||||
public @interface RespEnc {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,33 +0,0 @@
|
||||||
package com.dispose.annotation.validator;
|
|
||||||
|
|
||||||
import com.dispose.annotation.UserId;
|
|
||||||
import com.google.common.collect.Sets;
|
|
||||||
import java.util.Set;
|
|
||||||
import javax.validation.ConstraintValidator;
|
|
||||||
import javax.validation.ConstraintValidatorContext;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author phoenix
|
|
||||||
* @date 2020年2月8日
|
|
||||||
*/
|
|
||||||
public class UserIdValidator implements ConstraintValidator<UserId, Long> {
|
|
||||||
|
|
||||||
private final Set<Long> idSet = Sets.newHashSet(1L, 2L);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 快速失败模式下,这里无法注入依赖 参数校验的数据源相关校验放到controller里 方法抽象到下层service中
|
|
||||||
*/
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isValid(Long aLong, ConstraintValidatorContext constraintValidatorContext) {
|
|
||||||
if (aLong == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return existsById(aLong);
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean existsById(long aId) {
|
|
||||||
return idSet.contains(aId);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,55 +0,0 @@
|
||||||
package com.dispose.aop;
|
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
|
||||||
import javax.servlet.http.HttpServletResponse;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
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.springframework.stereotype.Component;
|
|
||||||
import org.springframework.web.context.request.RequestContextHolder;
|
|
||||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* AOP切面
|
|
||||||
*
|
|
||||||
* @author phoenix
|
|
||||||
* @date 2020年2月4日
|
|
||||||
*/
|
|
||||||
@Aspect
|
|
||||||
@Component
|
|
||||||
@Slf4j
|
|
||||||
public class MyInterceptor {
|
|
||||||
|
|
||||||
public static final String EXEC = "execution(* com.cmcc.hy.phoenix.controller.*.*(..))"
|
|
||||||
+ "&& !execution(* com.cmcc.hy.phoenix.controller.*.get*(..))"
|
|
||||||
+ "&& !execution(* com.cmcc.hy.phoenix.controller.*.set*(..))";
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
@Pointcut(EXEC)
|
|
||||||
public void interceptor() {
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param point
|
|
||||||
* @return
|
|
||||||
* @throws Throwable
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("unused")
|
|
||||||
@Around("interceptor()")
|
|
||||||
public Object doAround(ProceedingJoinPoint point) throws Throwable {
|
|
||||||
Method method = ((MethodSignature) point.getSignature()).getMethod();
|
|
||||||
log.info("方法:" + method.getName());
|
|
||||||
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes())
|
|
||||||
.getRequest();
|
|
||||||
HttpServletResponse response = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes())
|
|
||||||
.getResponse();
|
|
||||||
|
|
||||||
return point.proceed();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,36 +0,0 @@
|
||||||
package com.dispose.aop.cache;
|
|
||||||
|
|
||||||
import java.lang.annotation.Documented;
|
|
||||||
import java.lang.annotation.ElementType;
|
|
||||||
import java.lang.annotation.Inherited;
|
|
||||||
import java.lang.annotation.Retention;
|
|
||||||
import java.lang.annotation.RetentionPolicy;
|
|
||||||
import java.lang.annotation.Target;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 在数据更新、删除情况下,先删除缓存
|
|
||||||
*
|
|
||||||
* @author phoenix
|
|
||||||
* @date 2020年2月25日
|
|
||||||
*/
|
|
||||||
@Target({ElementType.TYPE, ElementType.METHOD})
|
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
|
||||||
@Inherited
|
|
||||||
@Documented
|
|
||||||
public @interface CacheDel {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 什么对象
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
* @Description: TODO(这里用一句话描述这个方法的作用)
|
|
||||||
*/
|
|
||||||
Class<?> clazz();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return
|
|
||||||
* @Description: TODO(这里用一句话描述这个方法的作用)
|
|
||||||
*/
|
|
||||||
String[] key() default {};
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,46 +0,0 @@
|
||||||
package com.dispose.aop.cache;
|
|
||||||
|
|
||||||
import java.lang.annotation.Documented;
|
|
||||||
import java.lang.annotation.ElementType;
|
|
||||||
import java.lang.annotation.Inherited;
|
|
||||||
import java.lang.annotation.Retention;
|
|
||||||
import java.lang.annotation.RetentionPolicy;
|
|
||||||
import java.lang.annotation.Target;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 先从缓存读取,读不到走数据层读取,并存入缓存
|
|
||||||
*
|
|
||||||
* @author phoenix
|
|
||||||
* @date 2020年2月25日
|
|
||||||
*/
|
|
||||||
@Target({ElementType.TYPE, ElementType.METHOD})
|
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
|
||||||
@Inherited
|
|
||||||
@Documented
|
|
||||||
public @interface CacheGet {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 缓存的有效期,默认300秒
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
* @Description:
|
|
||||||
*/
|
|
||||||
int ttl() default 300;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return
|
|
||||||
* @Description: TODO(这里用一句话描述这个方法的作用)
|
|
||||||
*/
|
|
||||||
String[] key();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 是否缓存空值,防止缓存穿透使用
|
|
||||||
* 慎用
|
|
||||||
* 如果使用了空缓存,而不使用CachePut,则数据影响周期就是ttl时间
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
* @Description: TODO(这里用一句话描述这个方法的作用)
|
|
||||||
*/
|
|
||||||
boolean cacheNull() default false;
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,37 +0,0 @@
|
||||||
package com.dispose.aop.cache;
|
|
||||||
|
|
||||||
import java.lang.annotation.Documented;
|
|
||||||
import java.lang.annotation.ElementType;
|
|
||||||
import java.lang.annotation.Inherited;
|
|
||||||
import java.lang.annotation.Retention;
|
|
||||||
import java.lang.annotation.RetentionPolicy;
|
|
||||||
import java.lang.annotation.Target;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 新增数据,直接设置缓存,目的适合缓存穿透结合使用
|
|
||||||
* 减少空缓存影响时间
|
|
||||||
*
|
|
||||||
* @author phoenix
|
|
||||||
* @date 2020年2月25日
|
|
||||||
*/
|
|
||||||
@Target({ElementType.TYPE, ElementType.METHOD})
|
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
|
||||||
@Inherited
|
|
||||||
@Documented
|
|
||||||
public @interface CachePut {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 缓存的有效期,默认300秒
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
* @Description:
|
|
||||||
*/
|
|
||||||
int ttl() default 300;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return
|
|
||||||
* @Description: TODO(这里用一句话描述这个方法的作用)
|
|
||||||
*/
|
|
||||||
String[] key() default {};
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,28 +0,0 @@
|
||||||
package com.dispose.aop.cache;
|
|
||||||
|
|
||||||
import java.lang.annotation.Documented;
|
|
||||||
import java.lang.annotation.ElementType;
|
|
||||||
import java.lang.annotation.Inherited;
|
|
||||||
import java.lang.annotation.Retention;
|
|
||||||
import java.lang.annotation.RetentionPolicy;
|
|
||||||
import java.lang.annotation.Target;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 某些方法需要组合注解的用这个注解标注
|
|
||||||
*
|
|
||||||
* @author phoenix
|
|
||||||
* @date 2020年3月4日
|
|
||||||
*/
|
|
||||||
@Target({ElementType.TYPE, ElementType.METHOD})
|
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
|
||||||
@Inherited
|
|
||||||
@Documented
|
|
||||||
public @interface MyCache {
|
|
||||||
|
|
||||||
CachePut[] put() default {};//保存数据同时设置多个key缓存
|
|
||||||
|
|
||||||
//CacheGet[] get() default {};
|
|
||||||
|
|
||||||
CacheDel[] del() default {};//删除对象,需要删除该对象的所有缓存数据
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,215 +0,0 @@
|
||||||
package com.dispose.aop.cache;
|
|
||||||
|
|
||||||
import com.dispose.common.Utils;
|
|
||||||
import com.dispose.redis.RedisClient;
|
|
||||||
import java.io.Serializable;
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
import javax.annotation.Resource;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.apache.commons.lang3.ArrayUtils;
|
|
||||||
import org.apache.commons.lang3.ObjectUtils;
|
|
||||||
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.springframework.core.LocalVariableTableParameterNameDiscoverer;
|
|
||||||
import org.springframework.expression.EvaluationContext;
|
|
||||||
import org.springframework.expression.Expression;
|
|
||||||
import org.springframework.expression.ExpressionParser;
|
|
||||||
import org.springframework.expression.spel.standard.SpelExpressionParser;
|
|
||||||
import org.springframework.expression.spel.support.StandardEvaluationContext;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 自定义封装manager缓存统一管理 TODO 未完待续
|
|
||||||
*
|
|
||||||
* @author phoenix
|
|
||||||
* @date 2020年2月10日
|
|
||||||
*/
|
|
||||||
@Aspect
|
|
||||||
@Component
|
|
||||||
@Slf4j
|
|
||||||
public class MyCacheInterceptor {
|
|
||||||
|
|
||||||
public static final String EXEC = "execution(* com.cmcc.hy.phoenix.manager.*.* (..))";
|
|
||||||
// + "&& !execution(* com.cmcc.hy.phoenix.manager.impl.*.get*(..))"
|
|
||||||
// + "&& !execution(* com.cmcc.hy.phoenix.manager.impl.*.set*(..))";
|
|
||||||
/**
|
|
||||||
* 缓存key分隔符
|
|
||||||
*/
|
|
||||||
public static final String SPILIT = "#";
|
|
||||||
/**
|
|
||||||
* 系统统一缓存key前缀
|
|
||||||
*/
|
|
||||||
public static final String CACHE_PREFIX = "PHOENIX_IC" + SPILIT;
|
|
||||||
// SpelExpressionParser spelExpressionParser = new SpelExpressionParser();
|
|
||||||
public static final String CACHE_NULL = "NULL";
|
|
||||||
private static final ExpressionParser parser = new SpelExpressionParser();
|
|
||||||
@Resource
|
|
||||||
private RedisClient redisClient;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
@Pointcut(EXEC)
|
|
||||||
public void cache() {
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 切记,这三个缓存注解,不可同时在一个方法上使用 如果出现,一定是你的业务设计有问题
|
|
||||||
*
|
|
||||||
* @param point
|
|
||||||
* @return
|
|
||||||
* @throws Throwable
|
|
||||||
* @数据操作可归结为 CRUD 操作(增加、读取、更新、删除)
|
|
||||||
* @组合操作 MyCache
|
|
||||||
* @增加:可能需要CachePut
|
|
||||||
* @读取:可能需要CacheGet
|
|
||||||
* @更新:可能需要CacheDel 这里不要加CachePut,简化操作,简单就是高效
|
|
||||||
* @删除:可能需要CacheDel
|
|
||||||
*/
|
|
||||||
@Around("cache()")
|
|
||||||
public Object doAround(ProceedingJoinPoint point) throws Throwable {
|
|
||||||
Method method = ((MethodSignature) point.getSignature()).getMethod();
|
|
||||||
log.info("CACHE拦截方法:" + point.getSignature().getName());
|
|
||||||
MyCache mc = method.getAnnotation(MyCache.class);
|
|
||||||
if (mc != null) {
|
|
||||||
Object obj = point.proceed();
|
|
||||||
if ((int) obj > 0) {
|
|
||||||
//说明增删改操作有实际数据生效
|
|
||||||
log.info("方法 {} 检查到注解 @MyCache", method.getName());
|
|
||||||
CachePut[] puts = mc.put();
|
|
||||||
if (ArrayUtils.isNotEmpty(puts)) {
|
|
||||||
log.info("方法 {} 检查到组合注解 @CachePut", method.getName());
|
|
||||||
for (int i = 0; i < puts.length; i++) {
|
|
||||||
putHandle(point, puts[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
CacheDel[] dels = mc.del();
|
|
||||||
if (ArrayUtils.isNotEmpty(dels)) {
|
|
||||||
log.info("方法 {} 检查到组合注解 @CacheDel", method.getName());
|
|
||||||
for (int i = 0; i < dels.length; i++) {
|
|
||||||
delHandle(point, dels[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return obj;
|
|
||||||
} else {
|
|
||||||
log.info("方法 {} 未实际产生数据影响", method.getName());
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
CacheGet get = method.getAnnotation(CacheGet.class);
|
|
||||||
if (get != null) {
|
|
||||||
log.info("方法 {} 检查到独立注解 @CacheGet", method.getName());
|
|
||||||
return getHandle(point, get);
|
|
||||||
}
|
|
||||||
Object obj = point.proceed();
|
|
||||||
CachePut put = method.getAnnotation(CachePut.class);
|
|
||||||
if (put != null) {
|
|
||||||
log.info("方法 {} 检查到独立注解 @CachePut", method.getName());
|
|
||||||
if ((int) obj > 0) {
|
|
||||||
putHandle(point, put);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
CacheDel del = method.getAnnotation(CacheDel.class);
|
|
||||||
if (del != null) {
|
|
||||||
log.info("方法 {} 检查到独立注解 @CacheDel", method.getName());
|
|
||||||
if ((int) obj > 0) {
|
|
||||||
delHandle(point, del);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return obj;
|
|
||||||
}
|
|
||||||
return point.proceed();
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
private void putHandle(ProceedingJoinPoint point, CachePut put) throws Throwable {
|
|
||||||
log.info("CachePut操作");
|
|
||||||
Method method = ((MethodSignature) point.getSignature()).getMethod();
|
|
||||||
Class<? extends Serializable>[] clazz = (Class<? extends Serializable>[]) method.getParameterTypes();
|
|
||||||
String[] keys = put.key();
|
|
||||||
String key = genKey(point, clazz[0], keys);
|
|
||||||
log.info("key = " + key);
|
|
||||||
Object[] obj = point.getArgs();
|
|
||||||
if (ObjectUtils.isEmpty(obj[0])) {
|
|
||||||
log.warn("参数为NULL,不要使用CachePut注解");
|
|
||||||
} else {
|
|
||||||
redisClient.put(key, clazz[0].cast(obj[0]), Utils.randomTTL(put.ttl()));
|
|
||||||
log.info("设置缓存 {}", key);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void delHandle(ProceedingJoinPoint point, CacheDel del) throws Throwable {
|
|
||||||
// 说明要删除缓存
|
|
||||||
log.info("CacheDel操作");
|
|
||||||
String[] keys = del.key();
|
|
||||||
String key = genKey(point, del.clazz(), keys);
|
|
||||||
log.info("key = " + key);
|
|
||||||
redisClient.del(key);
|
|
||||||
log.info("缓存清空 {}", key);
|
|
||||||
// point.proceed();
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
private Object getHandle(ProceedingJoinPoint point, CacheGet get) throws Throwable {
|
|
||||||
// 说明是读数据操作,优先读取缓存
|
|
||||||
log.info("CacheGet操作");
|
|
||||||
Method method = ((MethodSignature) point.getSignature()).getMethod();
|
|
||||||
Class<? extends Serializable> clazz = (Class<? extends Serializable>) method.getReturnType();
|
|
||||||
String key = genKey(point, clazz, get.key());
|
|
||||||
log.info("key = " + key);
|
|
||||||
int ttl = Utils.randomTTL(get.ttl());
|
|
||||||
Object obj = redisClient.get(key, clazz);
|
|
||||||
if (ObjectUtils.isEmpty(obj)) {
|
|
||||||
log.info("缓存查询为空");
|
|
||||||
obj = point.proceed();
|
|
||||||
if (ObjectUtils.isNotEmpty(obj)) {
|
|
||||||
log.info("数据库查询到数据 {}", obj);
|
|
||||||
redisClient.put(key, clazz.cast(obj), ttl);
|
|
||||||
log.info("成功将数据存入缓存");
|
|
||||||
} else {
|
|
||||||
log.info("数据库查询依然为空");
|
|
||||||
// 开启防缓存穿透,设置空缓存
|
|
||||||
if (get.cacheNull()) {
|
|
||||||
redisClient.put(key, CACHE_NULL, ttl);
|
|
||||||
log.info("设置空缓存,防缓存穿透");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (CACHE_NULL.equals(obj)) {
|
|
||||||
// 缓存查询对象不为空,判断是否是空缓存
|
|
||||||
obj = null;
|
|
||||||
}
|
|
||||||
return obj;
|
|
||||||
}
|
|
||||||
|
|
||||||
private String genKey(ProceedingJoinPoint point, Class<?> clazz, String[] keys) {
|
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
String clazzName = clazz.getSimpleName();
|
|
||||||
sb.append(CACHE_PREFIX).append(clazzName);
|
|
||||||
EvaluationContext context = getContext(point.getArgs(), point);
|
|
||||||
for (int i = 0; i < keys.length; i++) {
|
|
||||||
sb.append(SPILIT).append(getValue(context, keys[i], String.class));
|
|
||||||
}
|
|
||||||
return sb.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
private <T> T getValue(EvaluationContext context, String key, Class<T> clazz) {
|
|
||||||
Expression expression = parser.parseExpression(key);
|
|
||||||
return expression.getValue(context, clazz);
|
|
||||||
}
|
|
||||||
|
|
||||||
private EvaluationContext getContext(Object[] arguments, ProceedingJoinPoint point) {
|
|
||||||
String[] parameterNames = new LocalVariableTableParameterNameDiscoverer()
|
|
||||||
.getParameterNames(((MethodSignature) point.getSignature()).getMethod());
|
|
||||||
if (parameterNames == null) {
|
|
||||||
throw new RuntimeException("参数列表不能为null");
|
|
||||||
}
|
|
||||||
EvaluationContext context = new StandardEvaluationContext();
|
|
||||||
for (int i = 0; i < arguments.length; i++) {
|
|
||||||
context.setVariable(parameterNames[i], arguments[i]);
|
|
||||||
}
|
|
||||||
return context;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -4,192 +4,6 @@ package com.dispose.common;
|
||||||
* The type Const value.
|
* The type Const value.
|
||||||
*/
|
*/
|
||||||
public class ConstValue {
|
public class ConstValue {
|
||||||
/**
|
|
||||||
* The enum Dispose device type.
|
|
||||||
*/
|
|
||||||
public enum DisposeDeviceType {
|
|
||||||
/**
|
|
||||||
* The Dptech umc.
|
|
||||||
*/
|
|
||||||
DPTECH_UMC(0, "迪普UMC管理平台"),
|
|
||||||
/**
|
|
||||||
* The Haohan platform.
|
|
||||||
*/
|
|
||||||
HAOHAN_PLATFORM(1, "浩瀚处置设备"),
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Virtual dispose dispose device type.
|
|
||||||
*/
|
|
||||||
VIRTUAL_DISPOSE(999, "虚拟处置设备");
|
|
||||||
|
|
||||||
private final int code;
|
|
||||||
private final String readme;
|
|
||||||
|
|
||||||
DisposeDeviceType(int code, String readme) {
|
|
||||||
this.code = code;
|
|
||||||
this.readme = readme;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets code.
|
|
||||||
*
|
|
||||||
* @return the code
|
|
||||||
*/
|
|
||||||
public int getCode() {
|
|
||||||
return this.code;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets readme.
|
|
||||||
*
|
|
||||||
* @return the readme
|
|
||||||
*/
|
|
||||||
public String getReadme() {
|
|
||||||
return this.readme;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The enum Device capacity.
|
|
||||||
*/
|
|
||||||
public enum DeviceCapacity {
|
|
||||||
/**
|
|
||||||
* The Cleanup.
|
|
||||||
*/
|
|
||||||
CLEANUP(0, "清洗能力"),
|
|
||||||
/**
|
|
||||||
* The Hidepend.
|
|
||||||
*/
|
|
||||||
HIDEPEND(1, "高防能力"),
|
|
||||||
/**
|
|
||||||
* The Blackhool.
|
|
||||||
*/
|
|
||||||
BLACKHOOL(2, "黑洞能力"),
|
|
||||||
/**
|
|
||||||
* The Detecive.
|
|
||||||
*/
|
|
||||||
DETECIVE(3, "检测能力");
|
|
||||||
|
|
||||||
private final int code;
|
|
||||||
private final String readme;
|
|
||||||
|
|
||||||
DeviceCapacity(int code, String readme) {
|
|
||||||
this.code = code;
|
|
||||||
this.readme = readme;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets code.
|
|
||||||
*
|
|
||||||
* @return the code
|
|
||||||
*/
|
|
||||||
public int getCode() {
|
|
||||||
return this.code;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets readme.
|
|
||||||
*
|
|
||||||
* @return the readme
|
|
||||||
*/
|
|
||||||
public String getReadme() {
|
|
||||||
return this.readme;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The enum Ip addr type.
|
|
||||||
*/
|
|
||||||
public enum IPAddrType {
|
|
||||||
/**
|
|
||||||
* The Ipv 4 type.
|
|
||||||
*/
|
|
||||||
IPV4_TYPE,
|
|
||||||
/**
|
|
||||||
* The Ipv 6 type.
|
|
||||||
*/
|
|
||||||
IPV6_TYPE;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets ip addr type.
|
|
||||||
*
|
|
||||||
* @param ipAddr the ip addr
|
|
||||||
* @return the ip addr type
|
|
||||||
*/
|
|
||||||
public static IPAddrType getIpAddrType(String ipAddr) {
|
|
||||||
if (ipAddr.contains(":")) {
|
|
||||||
return IPV6_TYPE;
|
|
||||||
} else {
|
|
||||||
return IPV4_TYPE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public enum DisposeTaskStatus {
|
|
||||||
TASK_NEW(0, "新建"),
|
|
||||||
TASK_RUNNING(1, "运行中"),
|
|
||||||
TASK_STOP(2, "停止"),
|
|
||||||
TASK_FINISH(3, "结束"),
|
|
||||||
TASK_DELETE(4, "删除");
|
|
||||||
|
|
||||||
private final int code;
|
|
||||||
private final String readme;
|
|
||||||
|
|
||||||
DisposeTaskStatus(int code, String readme) {
|
|
||||||
this.code = code;
|
|
||||||
this.readme = readme;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets code.
|
|
||||||
*
|
|
||||||
* @return the code
|
|
||||||
*/
|
|
||||||
public int getCode() {
|
|
||||||
return this.code;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets readme.
|
|
||||||
*
|
|
||||||
* @return the readme
|
|
||||||
*/
|
|
||||||
public String getReadme() {
|
|
||||||
return this.readme;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public enum FlowDirection {
|
|
||||||
DIRECTION_INPUT(0, "流入"),
|
|
||||||
DIRECTION_OUTPUT(1, "流出"),
|
|
||||||
DIRECTION_TWOWAY(2, "双向");
|
|
||||||
|
|
||||||
private final int code;
|
|
||||||
private final String readme;
|
|
||||||
|
|
||||||
FlowDirection(int code, String readme) {
|
|
||||||
this.code = code;
|
|
||||||
this.readme = readme;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets code.
|
|
||||||
*
|
|
||||||
* @return the code
|
|
||||||
*/
|
|
||||||
public int getCode() {
|
|
||||||
return this.code;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets readme.
|
|
||||||
*
|
|
||||||
* @return the readme
|
|
||||||
*/
|
|
||||||
public String getReadme() {
|
|
||||||
return this.readme;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The type Global configure.
|
* The type Global configure.
|
||||||
|
|
|
@ -0,0 +1,49 @@
|
||||||
|
package com.dispose.common;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The enum Device capacity.
|
||||||
|
*/
|
||||||
|
public enum DeviceCapacity {
|
||||||
|
/**
|
||||||
|
* The Cleanup.
|
||||||
|
*/
|
||||||
|
CLEANUP(0, "清洗能力"),
|
||||||
|
/**
|
||||||
|
* The Hidepend.
|
||||||
|
*/
|
||||||
|
HIDEPEND(1, "高防能力"),
|
||||||
|
/**
|
||||||
|
* The Blackhool.
|
||||||
|
*/
|
||||||
|
BLACKHOOL(2, "黑洞能力"),
|
||||||
|
/**
|
||||||
|
* The Detecive.
|
||||||
|
*/
|
||||||
|
DETECIVE(3, "检测能力");
|
||||||
|
|
||||||
|
private final int code;
|
||||||
|
private final String readme;
|
||||||
|
|
||||||
|
DeviceCapacity(int code, String readme) {
|
||||||
|
this.code = code;
|
||||||
|
this.readme = readme;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets code.
|
||||||
|
*
|
||||||
|
* @return the code
|
||||||
|
*/
|
||||||
|
public int getCode() {
|
||||||
|
return this.code;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets readme.
|
||||||
|
*
|
||||||
|
* @return the readme
|
||||||
|
*/
|
||||||
|
public String getReadme() {
|
||||||
|
return this.readme;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,46 @@
|
||||||
|
package com.dispose.common;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The enum Dispose device type.
|
||||||
|
*/
|
||||||
|
public enum DisposeDeviceType {
|
||||||
|
/**
|
||||||
|
* The Dptech umc.
|
||||||
|
*/
|
||||||
|
DPTECH_UMC(0, "迪普UMC管理平台"),
|
||||||
|
/**
|
||||||
|
* The Haohan platform.
|
||||||
|
*/
|
||||||
|
HAOHAN_PLATFORM(1, "浩瀚处置设备"),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Virtual dispose dispose device type.
|
||||||
|
*/
|
||||||
|
VIRTUAL_DISPOSE(999, "虚拟处置设备");
|
||||||
|
|
||||||
|
private final int code;
|
||||||
|
private final String readme;
|
||||||
|
|
||||||
|
DisposeDeviceType(int code, String readme) {
|
||||||
|
this.code = code;
|
||||||
|
this.readme = readme;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets code.
|
||||||
|
*
|
||||||
|
* @return the code
|
||||||
|
*/
|
||||||
|
public int getCode() {
|
||||||
|
return this.code;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets readme.
|
||||||
|
*
|
||||||
|
* @return the readme
|
||||||
|
*/
|
||||||
|
public String getReadme() {
|
||||||
|
return this.readme;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,35 @@
|
||||||
|
package com.dispose.common;
|
||||||
|
|
||||||
|
public enum DisposeTaskStatus {
|
||||||
|
TASK_NEW(0, "新建"),
|
||||||
|
TASK_RUNNING(1, "运行中"),
|
||||||
|
TASK_STOP(2, "停止"),
|
||||||
|
TASK_FINISH(3, "结束"),
|
||||||
|
TASK_DELETE(4, "删除");
|
||||||
|
|
||||||
|
private final int code;
|
||||||
|
private final String readme;
|
||||||
|
|
||||||
|
DisposeTaskStatus(int code, String readme) {
|
||||||
|
this.code = code;
|
||||||
|
this.readme = readme;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets code.
|
||||||
|
*
|
||||||
|
* @return the code
|
||||||
|
*/
|
||||||
|
public int getCode() {
|
||||||
|
return this.code;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets readme.
|
||||||
|
*
|
||||||
|
* @return the readme
|
||||||
|
*/
|
||||||
|
public String getReadme() {
|
||||||
|
return this.readme;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,33 @@
|
||||||
|
package com.dispose.common;
|
||||||
|
|
||||||
|
public enum FlowDirection {
|
||||||
|
DIRECTION_INPUT(0, "流入"),
|
||||||
|
DIRECTION_OUTPUT(1, "流出"),
|
||||||
|
DIRECTION_TWOWAY(2, "双向");
|
||||||
|
|
||||||
|
private final int code;
|
||||||
|
private final String readme;
|
||||||
|
|
||||||
|
FlowDirection(int code, String readme) {
|
||||||
|
this.code = code;
|
||||||
|
this.readme = readme;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets code.
|
||||||
|
*
|
||||||
|
* @return the code
|
||||||
|
*/
|
||||||
|
public int getCode() {
|
||||||
|
return this.code;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets readme.
|
||||||
|
*
|
||||||
|
* @return the readme
|
||||||
|
*/
|
||||||
|
public String getReadme() {
|
||||||
|
return this.readme;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,29 @@
|
||||||
|
package com.dispose.common;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The enum Ip addr type.
|
||||||
|
*/
|
||||||
|
public enum IPAddrType {
|
||||||
|
/**
|
||||||
|
* The Ipv 4 type.
|
||||||
|
*/
|
||||||
|
IPV4_TYPE,
|
||||||
|
/**
|
||||||
|
* The Ipv 6 type.
|
||||||
|
*/
|
||||||
|
IPV6_TYPE;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets ip addr type.
|
||||||
|
*
|
||||||
|
* @param ipAddr the ip addr
|
||||||
|
* @return the ip addr type
|
||||||
|
*/
|
||||||
|
public static IPAddrType getIpAddrType(String ipAddr) {
|
||||||
|
if (ipAddr.contains(":")) {
|
||||||
|
return IPV6_TYPE;
|
||||||
|
} else {
|
||||||
|
return IPV4_TYPE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,7 +1,8 @@
|
||||||
package com.dispose.dispose;
|
package com.dispose.dispose;
|
||||||
|
|
||||||
import com.dispose.common.ConstValue;
|
import com.dispose.common.DisposeDeviceType;
|
||||||
import com.dispose.common.GlobalVar;
|
import com.dispose.common.GlobalVar;
|
||||||
|
import com.dispose.common.IPAddrType;
|
||||||
import com.dispose.dispose.impl.DPTechImpl;
|
import com.dispose.dispose.impl.DPTechImpl;
|
||||||
import com.dispose.dispose.impl.VirtualDeviceImpl;
|
import com.dispose.dispose.impl.VirtualDeviceImpl;
|
||||||
|
|
||||||
|
@ -18,13 +19,13 @@ public class DeviceRouter {
|
||||||
* @param ipType the ip type
|
* @param ipType the ip type
|
||||||
* @return the dispose entry manager
|
* @return the dispose entry manager
|
||||||
*/
|
*/
|
||||||
public static DisposeEntryManager deviceRouterFactory(int devType, String ipAddr, ConstValue.IPAddrType ipType) {
|
public static DisposeEntryManager deviceRouterFactory(int devType, String ipAddr, IPAddrType ipType) {
|
||||||
|
|
||||||
if (GlobalVar.USED_VIRTUAL_DISPOSE_MODE) {
|
if (GlobalVar.USED_VIRTUAL_DISPOSE_MODE) {
|
||||||
return new VirtualDeviceImpl(ipAddr);
|
return new VirtualDeviceImpl(ipAddr);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (devType == ConstValue.DisposeDeviceType.DPTECH_UMC.getCode()) {
|
if (devType == DisposeDeviceType.DPTECH_UMC.getCode()) {
|
||||||
return new DPTechImpl(ipAddr);
|
return new DPTechImpl(ipAddr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,6 +40,6 @@ public class DeviceRouter {
|
||||||
* @return the dispose entry manager
|
* @return the dispose entry manager
|
||||||
*/
|
*/
|
||||||
public static DisposeEntryManager deviceRouterFactory(int devType, String ipAddr) {
|
public static DisposeEntryManager deviceRouterFactory(int devType, String ipAddr) {
|
||||||
return deviceRouterFactory(devType, ipAddr, ConstValue.IPAddrType.IPV4_TYPE);
|
return deviceRouterFactory(devType, ipAddr, IPAddrType.IPV4_TYPE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,9 @@ package com.dispose.dispose.impl;
|
||||||
|
|
||||||
import com.dispose.Interceptor.SoapPasswordCallbackHandler;
|
import com.dispose.Interceptor.SoapPasswordCallbackHandler;
|
||||||
import com.dispose.common.ConstValue;
|
import com.dispose.common.ConstValue;
|
||||||
|
import com.dispose.common.DeviceCapacity;
|
||||||
import com.dispose.common.GlobalVar;
|
import com.dispose.common.GlobalVar;
|
||||||
|
import com.dispose.common.IPAddrType;
|
||||||
import com.dispose.config.DisposeConfigure;
|
import com.dispose.config.DisposeConfigure;
|
||||||
import com.dispose.dispose.DisposeEntryManager;
|
import com.dispose.dispose.DisposeEntryManager;
|
||||||
import com.dispose.dispose.po.DeviceInfo;
|
import com.dispose.dispose.po.DeviceInfo;
|
||||||
|
@ -75,7 +77,7 @@ public class DPTechImpl implements DisposeEntryManager {
|
||||||
* @param ipAddr the ip addr
|
* @param ipAddr the ip addr
|
||||||
* @param type the type
|
* @param type the type
|
||||||
*/
|
*/
|
||||||
public DPTechImpl(String ipAddr, ConstValue.IPAddrType type) {
|
public DPTechImpl(String ipAddr, IPAddrType type) {
|
||||||
this(ipAddr);
|
this(ipAddr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -123,7 +125,7 @@ public class DPTechImpl implements DisposeEntryManager {
|
||||||
|
|
||||||
if (devs != null && devs.length() > 0) {
|
if (devs != null && devs.length() > 0) {
|
||||||
capList.add(DisposeDeviceCapacity.builder()
|
capList.add(DisposeDeviceCapacity.builder()
|
||||||
.capacity(ConstValue.DeviceCapacity.DETECIVE.getCode())
|
.capacity(DeviceCapacity.DETECIVE.getCode())
|
||||||
.tolFlowCapacity(0)
|
.tolFlowCapacity(0)
|
||||||
.build());
|
.build());
|
||||||
}
|
}
|
||||||
|
@ -147,7 +149,7 @@ public class DPTechImpl implements DisposeEntryManager {
|
||||||
});
|
});
|
||||||
|
|
||||||
capList.add(DisposeDeviceCapacity.builder()
|
capList.add(DisposeDeviceCapacity.builder()
|
||||||
.capacity(ConstValue.DeviceCapacity.CLEANUP.getCode())
|
.capacity(DeviceCapacity.CLEANUP.getCode())
|
||||||
.tolFlowCapacity(0)
|
.tolFlowCapacity(0)
|
||||||
.protectIpV4(proIPv4.toArray(new String[0]))
|
.protectIpV4(proIPv4.toArray(new String[0]))
|
||||||
.protectIpV6(proIPv6.toArray(new String[0]))
|
.protectIpV6(proIPv6.toArray(new String[0]))
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package com.dispose.dispose.impl;
|
package com.dispose.dispose.impl;
|
||||||
|
|
||||||
import com.dispose.common.ConstValue;
|
import com.dispose.common.DeviceCapacity;
|
||||||
|
import com.dispose.common.IPAddrType;
|
||||||
import com.dispose.dispose.DisposeEntryManager;
|
import com.dispose.dispose.DisposeEntryManager;
|
||||||
import com.dispose.dispose.po.DeviceInfo;
|
import com.dispose.dispose.po.DeviceInfo;
|
||||||
import com.dispose.pojo.po.DisposeDeviceCapacity;
|
import com.dispose.pojo.po.DisposeDeviceCapacity;
|
||||||
|
@ -15,7 +16,7 @@ public class VirtualDeviceImpl implements DisposeEntryManager {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public VirtualDeviceImpl(String ipAddr, ConstValue.IPAddrType type) {
|
public VirtualDeviceImpl(String ipAddr, IPAddrType type) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,14 +71,14 @@ public class VirtualDeviceImpl implements DisposeEntryManager {
|
||||||
List<DisposeDeviceCapacity> capList = new ArrayList<>();
|
List<DisposeDeviceCapacity> capList = new ArrayList<>();
|
||||||
|
|
||||||
capList.add(DisposeDeviceCapacity.builder()
|
capList.add(DisposeDeviceCapacity.builder()
|
||||||
.capacity(ConstValue.DeviceCapacity.CLEANUP.getCode())
|
.capacity(DeviceCapacity.CLEANUP.getCode())
|
||||||
.protectIpV4(new String[]{"192.168.1.1", "192.168.1.2"})
|
.protectIpV4(new String[]{"192.168.1.1", "192.168.1.2"})
|
||||||
.protectIpV6(new String[]{})
|
.protectIpV6(new String[]{})
|
||||||
.tolFlowCapacity(1024)
|
.tolFlowCapacity(1024)
|
||||||
.build());
|
.build());
|
||||||
|
|
||||||
capList.add(DisposeDeviceCapacity.builder()
|
capList.add(DisposeDeviceCapacity.builder()
|
||||||
.capacity(ConstValue.DeviceCapacity.DETECIVE.getCode())
|
.capacity(DeviceCapacity.DETECIVE.getCode())
|
||||||
.protectIpV4(new String[]{"192.168.2.1", "192.168.2.2"})
|
.protectIpV4(new String[]{"192.168.2.1", "192.168.2.2"})
|
||||||
.protectIpV6(new String[]{})
|
.protectIpV6(new String[]{})
|
||||||
.tolFlowCapacity(0)
|
.tolFlowCapacity(0)
|
||||||
|
@ -103,6 +104,7 @@ public class VirtualDeviceImpl implements DisposeEntryManager {
|
||||||
* @return the all detection object
|
* @return the all detection object
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
public <T> T getAllDetectionObject() {
|
public <T> T getAllDetectionObject() {
|
||||||
List<String> detectionObjects = new ArrayList<>();
|
List<String> detectionObjects = new ArrayList<>();
|
||||||
|
|
||||||
|
@ -117,6 +119,7 @@ public class VirtualDeviceImpl implements DisposeEntryManager {
|
||||||
* @return the all protection object
|
* @return the all protection object
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
public <T> T getAllProtectionObject() {
|
public <T> T getAllProtectionObject() {
|
||||||
List<String> protectObjects = new ArrayList<>();
|
List<String> protectObjects = new ArrayList<>();
|
||||||
|
|
||||||
|
|
|
@ -58,7 +58,7 @@ public interface DisposeTaskMapper extends Mapper<TaskInfoDetail>,
|
||||||
* @param ipAddr the ip addr
|
* @param ipAddr the ip addr
|
||||||
* @return the all task by dispose ip
|
* @return the all task by dispose ip
|
||||||
*/
|
*/
|
||||||
List<TaskInfoDetail> getAllTaskByDisposeIp(String ipAddr);
|
List<TaskInfoDetail> getAllTaskByDisposeIp(@Param("ipAddr")String ipAddr);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets all task by node dev id.
|
* Gets all task by node dev id.
|
||||||
|
@ -69,10 +69,38 @@ public interface DisposeTaskMapper extends Mapper<TaskInfoDetail>,
|
||||||
List<TaskInfoDetail> getAllTaskByNodeDevId(Long devId);
|
List<TaskInfoDetail> getAllTaskByNodeDevId(Long devId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets all task by node user id.
|
* Gets node all task by user id.
|
||||||
*
|
*
|
||||||
* @param userId the user id
|
* @param userId the user id
|
||||||
* @return the all task by node user id
|
* @return the node all task by user id
|
||||||
*/
|
*/
|
||||||
List<TaskInfoDetail> getAllTaskByNodeUserId(Long userId);
|
List<TaskInfoDetail> getNodeAllTaskByUserId(Long userId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets node task by ip and status.
|
||||||
|
*
|
||||||
|
* @param devId the dev id
|
||||||
|
* @param ipAddr the ip addr
|
||||||
|
* @param status the status
|
||||||
|
* @return the node task by ip and status
|
||||||
|
*/
|
||||||
|
List<TaskInfoDetail> getNodeTaskByIpAndStatus(@Param("devId")Long devId,
|
||||||
|
@Param("ipAddr")String ipAddr,
|
||||||
|
@Param("status") int status);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets all task by ip.
|
||||||
|
*
|
||||||
|
* @param ipAddr the ip addr
|
||||||
|
* @return the all task by ip
|
||||||
|
*/
|
||||||
|
List<TaskInfoDetail> getAllTaskByIp(@Param("ipAddr")String ipAddr);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets all task by status.
|
||||||
|
*
|
||||||
|
* @param status the status
|
||||||
|
* @return the all task by status
|
||||||
|
*/
|
||||||
|
List<TaskInfoDetail> getAllTaskByStatus(@Param("status") int status);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,93 +0,0 @@
|
||||||
package com.dispose.redis;
|
|
||||||
|
|
||||||
import com.dispose.common.Utils;
|
|
||||||
import com.dispose.config.MyConfig;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import javax.annotation.Resource;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
|
|
||||||
import org.redisson.Redisson;
|
|
||||||
import org.redisson.api.RedissonClient;
|
|
||||||
import org.redisson.config.Config;
|
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
import redis.clients.jedis.JedisShardInfo;
|
|
||||||
import redis.clients.jedis.ShardedJedisPool;
|
|
||||||
import redis.clients.jedis.util.Hashing;
|
|
||||||
import redis.clients.jedis.util.Sharded;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author phoenix
|
|
||||||
* @date 2020年3月10日
|
|
||||||
*/
|
|
||||||
@Configuration
|
|
||||||
@Slf4j
|
|
||||||
public class MyRedisConfiguration {
|
|
||||||
|
|
||||||
@Resource
|
|
||||||
private MyConfig myConfig;
|
|
||||||
|
|
||||||
@SuppressWarnings("rawtypes")
|
|
||||||
@ConditionalOnProperty(prefix = "phoenix", name = "redis.type", havingValue = "jedis")
|
|
||||||
@Bean
|
|
||||||
public ShardedJedisPool shardedJedisPool() {
|
|
||||||
GenericObjectPoolConfig config = new GenericObjectPoolConfig();
|
|
||||||
// 连接数配置也可放到外部配置文件去
|
|
||||||
config.setMaxTotal(128);
|
|
||||||
config.setMaxIdle(16);
|
|
||||||
config.setMinIdle(4);
|
|
||||||
config.setMaxWaitMillis(1000L);
|
|
||||||
config.setTestWhileIdle(true);
|
|
||||||
config.setTimeBetweenEvictionRunsMillis(30000L);
|
|
||||||
config.setMinEvictableIdleTimeMillis(600000L);
|
|
||||||
config.setNumTestsPerEvictionRun(-1);
|
|
||||||
config.setJmxEnabled(false);
|
|
||||||
List<JedisShardInfo> shards = new ArrayList<JedisShardInfo>();
|
|
||||||
String[] serverList = myConfig.getRedisServer().split(",", 0);
|
|
||||||
for (String server : serverList) {
|
|
||||||
JedisShardInfo jsi = new JedisShardInfo(server);
|
|
||||||
jsi.setConnectionTimeout(5000);
|
|
||||||
jsi.setSoTimeout(5000);
|
|
||||||
shards.add(jsi);
|
|
||||||
}
|
|
||||||
log.info("Redis Type = jedis ,initialized success");
|
|
||||||
return new ShardedJedisPool(config, shards, Hashing.MURMUR_HASH, Sharded.DEFAULT_KEY_TAG_PATTERN);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return
|
|
||||||
* @Description: Redisson哨兵模式实例 具体API操作参照Redisson Github对照表
|
|
||||||
* https://github.com/redisson/redisson/wiki/11
|
|
||||||
* .-Redis%E5%91%BD%E4%BB%A4%E5%92%8CRedisson%E5%AF%B9%E8%B1%A1%E5%8C%B9%E9%85%8D%E5%88%97%E8%A1%A8
|
|
||||||
* @blog https://blog.csdn.net/unclecoco/article/details/99412915
|
|
||||||
*/
|
|
||||||
@ConditionalOnProperty(prefix = "phoenix", name = "redis.type", havingValue = "redisson-sentinel")
|
|
||||||
@Bean
|
|
||||||
public RedissonClient redissonSentinel() {
|
|
||||||
List<String> servers = Utils.splitStr2List(myConfig.getRedisServer(), ",");
|
|
||||||
Config config = new Config();
|
|
||||||
String masterName = myConfig.getRedisRedissonSentinelMasterName();
|
|
||||||
config.useSentinelServers().setMasterName(masterName).setPassword(myConfig.getRedisRedissonPwd())
|
|
||||||
.addSentinelAddress(servers.toArray(new String[0]));
|
|
||||||
log.info("Redis Type = redisson-sentinel ,initialized success");
|
|
||||||
return Redisson.create(config);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 在redis服务端通过KP做主备
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
* @Description: redisson single
|
|
||||||
*/
|
|
||||||
@ConditionalOnProperty(prefix = "phoenix", name = "redis.type", havingValue = "redisson-single")
|
|
||||||
@Bean
|
|
||||||
public RedissonClient redissonSingle() {
|
|
||||||
Config config = new Config();
|
|
||||||
config.useSingleServer().setAddress(myConfig.getRedisServer()).setPassword(myConfig.getRedisRedissonPwd());
|
|
||||||
log.info("Redis Type = redisson-single ,initialized success");
|
|
||||||
return Redisson.create(config);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,101 +0,0 @@
|
||||||
package com.dispose.redis;
|
|
||||||
|
|
||||||
import io.protostuff.LinkedBuffer;
|
|
||||||
import io.protostuff.ProtostuffIOUtil;
|
|
||||||
import io.protostuff.Schema;
|
|
||||||
import io.protostuff.runtime.RuntimeSchema;
|
|
||||||
import java.math.BigDecimal;
|
|
||||||
import java.math.BigInteger;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
|
||||||
import org.objenesis.Objenesis;
|
|
||||||
import org.objenesis.ObjenesisStd;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author phoenix
|
|
||||||
* @date 2020年2月8日
|
|
||||||
*/
|
|
||||||
public class ProtobufSerializer {
|
|
||||||
|
|
||||||
private static final Map<Class<?>, Schema<?>> cachedSchema = new ConcurrentHashMap<Class<?>, Schema<?>>();
|
|
||||||
|
|
||||||
private static final Objenesis objenesis = new ObjenesisStd(true);
|
|
||||||
|
|
||||||
static {
|
|
||||||
cachedSchema.put(Boolean.class, RuntimeSchema.createFrom(Boolean.class));
|
|
||||||
cachedSchema.put(Byte.class, RuntimeSchema.createFrom(Byte.class));
|
|
||||||
cachedSchema.put(Short.class, RuntimeSchema.createFrom(Short.class));
|
|
||||||
cachedSchema.put(Integer.class, RuntimeSchema.createFrom(Integer.class));
|
|
||||||
cachedSchema.put(Long.class, RuntimeSchema.createFrom(Long.class));
|
|
||||||
cachedSchema.put(Float.class, RuntimeSchema.createFrom(Float.class));
|
|
||||||
cachedSchema.put(Double.class, RuntimeSchema.createFrom(Double.class));
|
|
||||||
cachedSchema.put(Character.class, RuntimeSchema.createFrom(Character.class));
|
|
||||||
cachedSchema.put(String.class, RuntimeSchema.createFrom(String.class));
|
|
||||||
cachedSchema.put(BigInteger.class, RuntimeSchema.createFrom(BigInteger.class));
|
|
||||||
cachedSchema.put(BigDecimal.class, RuntimeSchema.createFrom(BigDecimal.class));
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
private static <T> Schema<T> getSchema(Class<T> cls) {
|
|
||||||
Schema<T> schema = (Schema<T>) cachedSchema.get(cls);
|
|
||||||
if (schema == null) {
|
|
||||||
schema = RuntimeSchema.createFrom(cls);
|
|
||||||
if (schema != null) {
|
|
||||||
cachedSchema.put(cls, schema);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return schema;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param obj
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public static <T> byte[] serialize(T obj) {
|
|
||||||
Class<T> cls = (Class<T>) obj.getClass();
|
|
||||||
LinkedBuffer buffer = LinkedBuffer.allocate(LinkedBuffer.DEFAULT_BUFFER_SIZE);
|
|
||||||
try {
|
|
||||||
Schema<T> schema = getSchema(cls);
|
|
||||||
return ProtostuffIOUtil.toByteArray(obj, schema, buffer);
|
|
||||||
} catch (Exception e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
} finally {
|
|
||||||
buffer.clear();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param bytes
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public static <T> T deserialize(byte[] bytes) {
|
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param bytes
|
|
||||||
* @param cls
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public static <T> T deserialize(byte[] bytes, Class<T> cls) {
|
|
||||||
try {
|
|
||||||
T message = objenesis.newInstance(cls);
|
|
||||||
Schema<T> schema = getSchema(cls);
|
|
||||||
ProtostuffIOUtil.mergeFrom(bytes, message, schema);
|
|
||||||
return message;
|
|
||||||
} catch (Exception e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Revision history
|
|
||||||
* -------------------------------------------------------------------------
|
|
||||||
* <p>
|
|
||||||
* Date Author Note
|
|
||||||
* -------------------------------------------------------------------------
|
|
||||||
* 2016年6月6日 chiwei create
|
|
||||||
*/
|
|
|
@ -1,92 +0,0 @@
|
||||||
package com.dispose.redis;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author phoenix
|
|
||||||
* @date 2020年2月8日
|
|
||||||
*/
|
|
||||||
public interface RedisClient {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param k
|
|
||||||
* @param v
|
|
||||||
* @param seconds
|
|
||||||
*/
|
|
||||||
void put(String k, String v, int seconds);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 序列化
|
|
||||||
*
|
|
||||||
* @param v
|
|
||||||
* @param seconds
|
|
||||||
*/
|
|
||||||
<T extends Serializable> void put(String key, T v, int seconds);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param key
|
|
||||||
* @return
|
|
||||||
* @Description: TODO(这里用一句话描述这个方法的作用)
|
|
||||||
*/
|
|
||||||
boolean setLock(String key);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param key
|
|
||||||
* @Description: TODO(这里用一句话描述这个方法的作用)
|
|
||||||
*/
|
|
||||||
void delLock(String key);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param key
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
String get(String key);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param key
|
|
||||||
* @param cls
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
<T extends Serializable> T get(String key, Class<T> cls);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param key
|
|
||||||
*/
|
|
||||||
void del(String key);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* llen:(). <br/>
|
|
||||||
*
|
|
||||||
* @param key
|
|
||||||
* @return
|
|
||||||
* @author chiwei
|
|
||||||
* @since JDK 1.6
|
|
||||||
*/
|
|
||||||
long llen(String key);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param key
|
|
||||||
* @param seconds
|
|
||||||
*/
|
|
||||||
void expire(String key, int seconds);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param key
|
|
||||||
* @param value
|
|
||||||
*/
|
|
||||||
void lpush(String key, String value);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param key
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
String rpop(String key);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param key
|
|
||||||
* @param timeout seconds ;0 means hold until get data
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
String brpop(String key, int timeout);
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,211 +0,0 @@
|
||||||
package com.dispose.redis.jedis;
|
|
||||||
|
|
||||||
import com.dispose.redis.ProtobufSerializer;
|
|
||||||
import com.dispose.redis.RedisClient;
|
|
||||||
import java.io.Serializable;
|
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
import java.util.List;
|
|
||||||
import javax.annotation.Resource;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
import redis.clients.jedis.Jedis;
|
|
||||||
import redis.clients.jedis.ShardedJedis;
|
|
||||||
import redis.clients.jedis.ShardedJedisPool;
|
|
||||||
import redis.clients.jedis.params.SetParams;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author phoenix
|
|
||||||
* @date 2020年2月8日
|
|
||||||
*/
|
|
||||||
@ConditionalOnBean(ShardedJedisPool.class)
|
|
||||||
@Component
|
|
||||||
@Slf4j
|
|
||||||
public class RedisClientJedisImpl implements RedisClient {
|
|
||||||
|
|
||||||
@Resource
|
|
||||||
private ShardedJedisPool shardedJedisPool;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void put(String k, String v, int seconds) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
ShardedJedis sj = null;
|
|
||||||
try {
|
|
||||||
sj = shardedJedisPool.getResource();
|
|
||||||
sj.setex(k, seconds, v);
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("KV存储异常", e);
|
|
||||||
} finally {
|
|
||||||
sj.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean setLock(String key) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
ShardedJedis sj = null;
|
|
||||||
try {
|
|
||||||
sj = shardedJedisPool.getResource();
|
|
||||||
// nx 不存在set,ex秒
|
|
||||||
String res = sj.set(key, key, SetParams.setParams().nx().ex(60));
|
|
||||||
return "OK".equals(res);
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("锁异常", e);
|
|
||||||
sj.del(key);
|
|
||||||
} finally {
|
|
||||||
sj.close();
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String get(String key) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
ShardedJedis sj = null;
|
|
||||||
try {
|
|
||||||
sj = shardedJedisPool.getResource();
|
|
||||||
return sj.get(key);
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("获取数据异常", e);
|
|
||||||
} finally {
|
|
||||||
sj.close();
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void del(String key) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
ShardedJedis sj = null;
|
|
||||||
try {
|
|
||||||
sj = shardedJedisPool.getResource();
|
|
||||||
sj.del(key);
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("key删除异常", e);
|
|
||||||
} finally {
|
|
||||||
sj.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public <T extends Serializable> void put(String key, T v, int seconds) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
ShardedJedis sj = null;
|
|
||||||
try {
|
|
||||||
sj = shardedJedisPool.getResource();
|
|
||||||
sj.setex(key.getBytes(StandardCharsets.UTF_8), seconds, ProtobufSerializer.serialize(v));
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("数据序列化存入异常", e);
|
|
||||||
} finally {
|
|
||||||
sj.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public <T extends Serializable> T get(String key, Class<T> cls) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
ShardedJedis sj = null;
|
|
||||||
try {
|
|
||||||
sj = shardedJedisPool.getResource();
|
|
||||||
byte[] ret = sj.get(key.getBytes(StandardCharsets.UTF_8));
|
|
||||||
return ret == null ? null : ProtobufSerializer.deserialize(ret, cls);
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("数据序列化取出异常", e);
|
|
||||||
} finally {
|
|
||||||
sj.close();
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void expire(String key, int seconds) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
ShardedJedis sj = null;
|
|
||||||
try {
|
|
||||||
sj = shardedJedisPool.getResource();
|
|
||||||
sj.expire(key, seconds);
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("key设置有效期异常", e);
|
|
||||||
} finally {
|
|
||||||
sj.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String rpop(String key) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
ShardedJedis sj = null;
|
|
||||||
try {
|
|
||||||
sj = shardedJedisPool.getResource();
|
|
||||||
return sj.rpop(key);
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("队列取数据异常", e);
|
|
||||||
} finally {
|
|
||||||
sj.close();
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void lpush(String key, String value) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
ShardedJedis sj = null;
|
|
||||||
try {
|
|
||||||
sj = shardedJedisPool.getResource();
|
|
||||||
sj.lpush(key, value);
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("数据存入队列异常", e);
|
|
||||||
} finally {
|
|
||||||
sj.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public long llen(String key) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
ShardedJedis sj = null;
|
|
||||||
try {
|
|
||||||
sj = shardedJedisPool.getResource();
|
|
||||||
return sj.llen(key);
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("获取队列长度异常", e);
|
|
||||||
return 0;
|
|
||||||
} finally {
|
|
||||||
sj.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String brpop(String key, int timeout) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
Jedis jedis = null;
|
|
||||||
try {
|
|
||||||
jedis = shardedJedisPool.getResource().getShard(key);
|
|
||||||
List<String> ret = jedis.brpop(timeout, key);
|
|
||||||
return ret == null ? null : ret.get(1);
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("数据取出队列异常", e);
|
|
||||||
} finally {
|
|
||||||
jedis.close();
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void delLock(String key) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
//网上很多方法解锁通过LUA脚本判断value去解锁
|
|
||||||
//这里大家可以把加锁的key细化,不同业务用不同的key即可,
|
|
||||||
//不要整个系统用一个key,再通过value去细分不同业务的锁
|
|
||||||
ShardedJedis sj = null;
|
|
||||||
try {
|
|
||||||
sj = shardedJedisPool.getResource();
|
|
||||||
sj.del(key);
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("解锁异常", e);
|
|
||||||
} finally {
|
|
||||||
sj.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,132 +0,0 @@
|
||||||
package com.dispose.redis.redisson;
|
|
||||||
|
|
||||||
import com.dispose.redis.ProtobufSerializer;
|
|
||||||
import com.dispose.redis.RedisClient;
|
|
||||||
import java.io.Serializable;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
import javax.annotation.Resource;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.redisson.api.RBlockingDeque;
|
|
||||||
import org.redisson.api.RBucket;
|
|
||||||
import org.redisson.api.RDeque;
|
|
||||||
import org.redisson.api.RKeys;
|
|
||||||
import org.redisson.api.RList;
|
|
||||||
import org.redisson.api.RLock;
|
|
||||||
import org.redisson.api.RMap;
|
|
||||||
import org.redisson.api.RedissonClient;
|
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author phoenix
|
|
||||||
* @date 2020年3月10日
|
|
||||||
*/
|
|
||||||
@ConditionalOnBean(RedissonClient.class)
|
|
||||||
@Slf4j
|
|
||||||
@Component
|
|
||||||
public class RedisClientRedissonImpl implements RedisClient {
|
|
||||||
|
|
||||||
@Resource
|
|
||||||
private RedissonClient redissonClient;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void put(String k, String v, int seconds) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
RBucket<String> cache = redissonClient.getBucket(k);
|
|
||||||
cache.set(v, seconds, TimeUnit.SECONDS);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public <T extends Serializable> void put(String key, T v, int seconds) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
RBucket<Object> cache = redissonClient.getBucket(key);
|
|
||||||
cache.set(ProtobufSerializer.serialize(v), seconds, TimeUnit.SECONDS);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean setLock(String key) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
// 抢占式上锁
|
|
||||||
RLock lock = redissonClient.getLock(key);
|
|
||||||
// 公平锁,按照线程的优先顺序
|
|
||||||
// redissonClient.getFairLock(key);
|
|
||||||
// waitTime 超时时间
|
|
||||||
// leaseTime 有效期,过期自动失效
|
|
||||||
try {
|
|
||||||
return lock.tryLock(5, 600, TimeUnit.SECONDS);
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("Redisson 加锁异常", e);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void delLock(String key) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
RLock lock = redissonClient.getLock(key);
|
|
||||||
// lock.forceUnlock();
|
|
||||||
lock.unlock();
|
|
||||||
// lock.forceUnlockAsync();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String get(String key) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
RBucket<String> cache = redissonClient.getBucket(key);
|
|
||||||
return cache.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public <T extends Serializable> T get(String key, Class<T> cls) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
RBucket<byte[]> cache = redissonClient.getBucket(key);
|
|
||||||
return cache.get() == null ? null : ProtobufSerializer.deserialize(cache.get(), cls);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void del(String key) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
RKeys k = redissonClient.getKeys();
|
|
||||||
k.delete(key);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public long llen(String key) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
RList<Object> list = redissonClient.getList(key);
|
|
||||||
return list.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void expire(String key, int seconds) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
RMap<Object, Object> map = redissonClient.getMap(key);
|
|
||||||
map.expire(seconds, TimeUnit.SECONDS);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void lpush(String key, String value) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
RDeque<String> list = redissonClient.getDeque(key);
|
|
||||||
list.addFirst(value);// lpush
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String rpop(String key) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
RDeque<String> list = redissonClient.getDeque(key);
|
|
||||||
return list.pollLast();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String brpop(String key, int timeout) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
RBlockingDeque<String> list = redissonClient.getBlockingDeque(key);
|
|
||||||
try {
|
|
||||||
return list.pollLast(timeout, TimeUnit.SECONDS);
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
log.error("BRPOP异常", e);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,7 +1,7 @@
|
||||||
package com.dispose.service.impl;
|
package com.dispose.service.impl;
|
||||||
|
|
||||||
import com.dispose.common.ConstValue;
|
|
||||||
import com.dispose.common.ErrorCode;
|
import com.dispose.common.ErrorCode;
|
||||||
|
import com.dispose.common.IPAddrType;
|
||||||
import com.dispose.dispose.DeviceRouter;
|
import com.dispose.dispose.DeviceRouter;
|
||||||
import com.dispose.dispose.DisposeEntryManager;
|
import com.dispose.dispose.DisposeEntryManager;
|
||||||
import com.dispose.mapper.DisposeDeviceMapper;
|
import com.dispose.mapper.DisposeDeviceMapper;
|
||||||
|
@ -41,7 +41,7 @@ public class DisposeNodeManagerImpl implements DisposeNodeManager {
|
||||||
devList.forEach(v -> {
|
devList.forEach(v -> {
|
||||||
DisposeEntryManager dp = DeviceRouter.deviceRouterFactory(v.getType(),
|
DisposeEntryManager dp = DeviceRouter.deviceRouterFactory(v.getType(),
|
||||||
v.getIpAddr(),
|
v.getIpAddr(),
|
||||||
ConstValue.IPAddrType.getIpAddrType(v.getIpAddr()));
|
IPAddrType.getIpAddrType(v.getIpAddr()));
|
||||||
|
|
||||||
v.setLinkStatus(dp.getDeviceLinkStatus() ? 1 : 0);
|
v.setLinkStatus(dp.getDeviceLinkStatus() ? 1 : 0);
|
||||||
v.setVersion(dp.getVersion());
|
v.setVersion(dp.getVersion());
|
||||||
|
@ -109,7 +109,7 @@ public class DisposeNodeManagerImpl implements DisposeNodeManager {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
dp = DeviceRouter.deviceRouterFactory(dev.getType(),
|
dp = DeviceRouter.deviceRouterFactory(dev.getType(),
|
||||||
dev.getIpAddr(), ConstValue.IPAddrType.getIpAddrType(dev.getIpAddr()));
|
dev.getIpAddr(), IPAddrType.getIpAddrType(dev.getIpAddr()));
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
return new MReturnType<>(ErrorCode.ERR_NOSUCHDEVICE, String.valueOf(-1));
|
return new MReturnType<>(ErrorCode.ERR_NOSUCHDEVICE, String.valueOf(-1));
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,128 +0,0 @@
|
||||||
package com.dispose.session;
|
|
||||||
|
|
||||||
import javax.servlet.http.Cookie;
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
|
||||||
import javax.servlet.http.HttpServletResponse;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author phoenix
|
|
||||||
* @date 2020年2月24日
|
|
||||||
*/
|
|
||||||
public class MyCookie {
|
|
||||||
|
|
||||||
private final HttpServletRequest request;
|
|
||||||
private final HttpServletResponse response;
|
|
||||||
|
|
||||||
public MyCookie(HttpServletRequest req, HttpServletResponse res) {
|
|
||||||
request = req;
|
|
||||||
response = res;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getRemoteIp() {
|
|
||||||
String ip = request.getHeader("X-Forwarded-For");
|
|
||||||
if (isEffective(ip) && ip.indexOf(",") > -1) {
|
|
||||||
String[] array = ip.split(",");
|
|
||||||
for (String str : array) {
|
|
||||||
if (isEffective(str)) {
|
|
||||||
ip = str;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!isEffective(ip)) {
|
|
||||||
ip = request.getHeader("Proxy-Client-IP");
|
|
||||||
}
|
|
||||||
if (!isEffective(ip)) {
|
|
||||||
ip = request.getHeader("WL-Proxy-Client-IP");
|
|
||||||
}
|
|
||||||
if (!isEffective(ip)) {
|
|
||||||
ip = request.getHeader("HTTP_CLIENT_IP");
|
|
||||||
}
|
|
||||||
if (!isEffective(ip)) {
|
|
||||||
ip = request.getHeader("HTTP_X_FORWARDED_FOR");
|
|
||||||
}
|
|
||||||
if (!isEffective(ip)) {
|
|
||||||
ip = request.getRemoteAddr();
|
|
||||||
}
|
|
||||||
return ip;
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isEffective(String remoteAddr) {
|
|
||||||
return (null != remoteAddr) && (!"".equals(remoteAddr.trim()))
|
|
||||||
&& (!"unknown".equalsIgnoreCase(remoteAddr.trim()));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 设置cookie
|
|
||||||
*
|
|
||||||
* @param name
|
|
||||||
* @param value
|
|
||||||
* @param domain
|
|
||||||
* @param expire
|
|
||||||
*/
|
|
||||||
public void setCookie(String name, String value, String domain, int expire) {
|
|
||||||
Cookie cookie = new Cookie(name, value);
|
|
||||||
cookie.setDomain(domain);
|
|
||||||
cookie.setPath("/");
|
|
||||||
if (expire >= 0) {
|
|
||||||
cookie.setMaxAge(expire);
|
|
||||||
}
|
|
||||||
cookie.setHttpOnly(true);
|
|
||||||
response.addCookie(cookie);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取某个cookie值
|
|
||||||
*
|
|
||||||
* @param name
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public String getCookieValue(String name) {
|
|
||||||
Cookie[] cookies = request.getCookies();
|
|
||||||
if (cookies == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
Cookie cookie = null;
|
|
||||||
for (int i = 0; i < cookies.length; i++) {
|
|
||||||
cookie = cookies[i];
|
|
||||||
if (cookie.getName().equalsIgnoreCase(name)) {
|
|
||||||
return cookie.getValue();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* setCookie:(). <br/>
|
|
||||||
*
|
|
||||||
* @param name
|
|
||||||
* @param value
|
|
||||||
* @param domain
|
|
||||||
* @author chiwei
|
|
||||||
* @since JDK 1.6
|
|
||||||
*/
|
|
||||||
public void setCookie(String name, String value, String domain) {
|
|
||||||
// maxage=-1表示关闭浏览器则cookie失效
|
|
||||||
setCookie(name, value, domain, -1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param name
|
|
||||||
* @param domain
|
|
||||||
*/
|
|
||||||
public void clearCookie(String name, String domain) {
|
|
||||||
setCookie(name, "", domain, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* clearSession:(). <br/>
|
|
||||||
*
|
|
||||||
* @param name
|
|
||||||
* @return
|
|
||||||
* @author chiwei
|
|
||||||
* @since JDK 1.6
|
|
||||||
*/
|
|
||||||
public void clearSession(String name) {
|
|
||||||
request.getSession().removeAttribute(name);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,6 +1,6 @@
|
||||||
package com.dispose.task;
|
package com.dispose.task;
|
||||||
|
|
||||||
import com.dispose.common.ConstValue;
|
import com.dispose.common.IPAddrType;
|
||||||
import com.dispose.dispose.DeviceRouter;
|
import com.dispose.dispose.DeviceRouter;
|
||||||
import com.dispose.dispose.DisposeEntryManager;
|
import com.dispose.dispose.DisposeEntryManager;
|
||||||
import com.dispose.pojo.entity.DisposeDevice;
|
import com.dispose.pojo.entity.DisposeDevice;
|
||||||
|
@ -32,14 +32,12 @@ public class DeviceManagerTask {
|
||||||
devList.forEach(v -> {
|
devList.forEach(v -> {
|
||||||
DisposeEntryManager dp = DeviceRouter.deviceRouterFactory(v.getType(),
|
DisposeEntryManager dp = DeviceRouter.deviceRouterFactory(v.getType(),
|
||||||
v.getIpAddr(),
|
v.getIpAddr(),
|
||||||
ConstValue.IPAddrType.getIpAddrType(v.getIpAddr()));
|
IPAddrType.getIpAddrType(v.getIpAddr()));
|
||||||
|
|
||||||
if (dp != null) {
|
v.setLinkStatus(dp.getDeviceLinkStatus() ? 1 : 0);
|
||||||
v.setLinkStatus(dp.getDeviceLinkStatus() ? 1 : 0);
|
v.setVersion(dp.getVersion());
|
||||||
v.setVersion(dp.getVersion());
|
v.setDevInfo(dp.getDeviceInfo());
|
||||||
v.setDevInfo(dp.getDeviceInfo());
|
log.info("Upgrade {} Device Status", v.getIpAddr());
|
||||||
log.info("Upgrade {} Device Status", v.getIpAddr());
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,19 +46,43 @@
|
||||||
<select id="getAllTaskByDisposeIp" resultType="com.dispose.pojo.vo.common.TaskInfoDetail">
|
<select id="getAllTaskByDisposeIp" resultType="com.dispose.pojo.vo.common.TaskInfoDetail">
|
||||||
SELECT * FROM dispose_task
|
SELECT * FROM dispose_task
|
||||||
WHERE
|
WHERE
|
||||||
disposeIp = #{disposeIp, jdbcType=VARCHAR}
|
disposeIp = #{ipAddr, jdbcType=VARCHAR} AND
|
||||||
|
currentStatus != ${@com.dispose.common.DisposeTaskStatus@TASK_DELETE.getCode()}
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="getAllTaskByNodeDevId" resultType="com.dispose.pojo.vo.common.TaskInfoDetail">
|
<select id="getAllTaskByNodeDevId" resultType="com.dispose.pojo.vo.common.TaskInfoDetail">
|
||||||
SELECT * FROM dispose_task
|
SELECT * FROM dispose_task
|
||||||
WHERE
|
WHERE
|
||||||
deviceId = #{devId, jdbcType=INTEGER}
|
deviceId = #{devId, jdbcType=INTEGER} AND
|
||||||
|
currentStatus != ${@com.dispose.common.DisposeTaskStatus@TASK_DELETE.getCode()}
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="getAllTaskByNodeUserId" resultType="com.dispose.pojo.vo.common.TaskInfoDetail">
|
<select id="getNodeAllTaskByUserId" resultType="com.dispose.pojo.vo.common.TaskInfoDetail">
|
||||||
SELECT * FROM dispose_task
|
SELECT * FROM dispose_task
|
||||||
WHERE
|
WHERE
|
||||||
deviceId = #{userId, jdbcType=INTEGER}
|
accountId = #{userId, jdbcType=INTEGER} AND
|
||||||
|
currentStatus != ${@com.dispose.common.DisposeTaskStatus@TASK_DELETE.getCode()}
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<select id="getNodeTaskByIpAndStatus" resultType="com.dispose.pojo.vo.common.TaskInfoDetail">
|
||||||
|
SELECT * FROM dispose_task
|
||||||
|
WHERE
|
||||||
|
deviceId = #{devId, jdbcType=INTEGER} AND
|
||||||
|
disposeIp = #{ipAddr, jdbcType=VARCHAR} AND
|
||||||
|
currentStatus = #{status, jdbcType=INTEGER}
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<select id="getAllTaskByIp" resultType="com.dispose.pojo.vo.common.TaskInfoDetail">
|
||||||
|
SELECT * FROM dispose_task
|
||||||
|
WHERE
|
||||||
|
disposeIp = #{ipAddr, jdbcType=VARCHAR} AND
|
||||||
|
currentStatus != ${@com.dispose.common.DisposeTaskStatus@TASK_DELETE.getCode()}
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<select id="getAllTaskByStatus" resultType="com.dispose.pojo.vo.common.TaskInfoDetail">
|
||||||
|
SELECT * FROM dispose_task
|
||||||
|
WHERE
|
||||||
|
currentStatus = #{status, jdbcType=INTEGER}
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
</mapper>
|
</mapper>
|
|
@ -248,7 +248,7 @@ public class DeviceNodeInfoControllerTest extends InitTestEnvironment {
|
||||||
reqInfo.setTimeStamp(System.currentTimeMillis());
|
reqInfo.setTimeStamp(System.currentTimeMillis());
|
||||||
reqInfo.setMsgContent(objectMapper.writeValueAsString(reqData));
|
reqInfo.setMsgContent(objectMapper.writeValueAsString(reqData));
|
||||||
|
|
||||||
mockMvc.perform(MockMvcRequestBuilders
|
String var = mockMvc.perform(MockMvcRequestBuilders
|
||||||
.post("/information/protected_ip")
|
.post("/information/protected_ip")
|
||||||
.contentType(MediaType.APPLICATION_JSON)
|
.contentType(MediaType.APPLICATION_JSON)
|
||||||
.header("Authorization", "Bearer " + getLogToken())
|
.header("Authorization", "Bearer " + getLogToken())
|
||||||
|
|
|
@ -2,6 +2,7 @@ package com.dispose.controller;
|
||||||
|
|
||||||
import com.dispose.Global.InitTestEnvironment;
|
import com.dispose.Global.InitTestEnvironment;
|
||||||
import com.dispose.common.ConstValue;
|
import com.dispose.common.ConstValue;
|
||||||
|
import com.dispose.common.DisposeDeviceType;
|
||||||
import com.dispose.pojo.dto.ProtocolReqDTO;
|
import com.dispose.pojo.dto.ProtocolReqDTO;
|
||||||
import com.dispose.pojo.po.NewNodeInfo;
|
import com.dispose.pojo.po.NewNodeInfo;
|
||||||
import com.dispose.pojo.vo.common.IDArrayReq;
|
import com.dispose.pojo.vo.common.IDArrayReq;
|
||||||
|
@ -51,7 +52,7 @@ public class DeviceNodeManagerControllerTest extends InitTestEnvironment {
|
||||||
|
|
||||||
addReq.getItems().add(NewNodeInfo.builder()
|
addReq.getItems().add(NewNodeInfo.builder()
|
||||||
.ipAddr("10.88.77.15")
|
.ipAddr("10.88.77.15")
|
||||||
.type(ConstValue.DisposeDeviceType.DPTECH_UMC.getCode())
|
.type(DisposeDeviceType.DPTECH_UMC.getCode())
|
||||||
.areaCode(0)
|
.areaCode(0)
|
||||||
.name("中移杭研实验室清洗设备")
|
.name("中移杭研实验室清洗设备")
|
||||||
.manufacturer("DPTech")
|
.manufacturer("DPTech")
|
||||||
|
|
|
@ -2,6 +2,7 @@ package com.dispose.controller;
|
||||||
|
|
||||||
import com.dispose.Global.InitTestEnvironment;
|
import com.dispose.Global.InitTestEnvironment;
|
||||||
import com.dispose.common.ConstValue;
|
import com.dispose.common.ConstValue;
|
||||||
|
import com.dispose.common.DeviceCapacity;
|
||||||
import com.dispose.pojo.dto.ProtocolReqDTO;
|
import com.dispose.pojo.dto.ProtocolReqDTO;
|
||||||
import com.dispose.pojo.vo.common.IDArrayReq;
|
import com.dispose.pojo.vo.common.IDArrayReq;
|
||||||
import com.dispose.pojo.vo.task.StartTaskReq;
|
import com.dispose.pojo.vo.task.StartTaskReq;
|
||||||
|
@ -50,7 +51,7 @@ public class TaskControllerTest extends InitTestEnvironment {
|
||||||
public void t1_startTask() throws Exception {
|
public void t1_startTask() throws Exception {
|
||||||
StartTaskReq reqData = StartTaskReq.builder()
|
StartTaskReq reqData = StartTaskReq.builder()
|
||||||
.id(210)
|
.id(210)
|
||||||
.type(ConstValue.DeviceCapacity.CLEANUP.getCode())
|
.type(DeviceCapacity.CLEANUP.getCode())
|
||||||
.disposeIp("192.168.0.1")
|
.disposeIp("192.168.0.1")
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
|
@ -110,7 +111,7 @@ public class TaskControllerTest extends InitTestEnvironment {
|
||||||
public void t3_stopNodeIpTask() throws Exception {
|
public void t3_stopNodeIpTask() throws Exception {
|
||||||
StopTaskData itemData = StopTaskData.builder()
|
StopTaskData itemData = StopTaskData.builder()
|
||||||
.disposeIp("192.168.1.1")
|
.disposeIp("192.168.1.1")
|
||||||
.type(ConstValue.DeviceCapacity.CLEANUP.getCode())
|
.type(DeviceCapacity.CLEANUP.getCode())
|
||||||
.id("210")
|
.id("210")
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
|
@ -145,7 +146,7 @@ public class TaskControllerTest extends InitTestEnvironment {
|
||||||
@Test
|
@Test
|
||||||
public void t4_stopNodeTask() throws Exception {
|
public void t4_stopNodeTask() throws Exception {
|
||||||
StopTaskData itemData = StopTaskData.builder()
|
StopTaskData itemData = StopTaskData.builder()
|
||||||
.type(ConstValue.DeviceCapacity.CLEANUP.getCode())
|
.type(DeviceCapacity.CLEANUP.getCode())
|
||||||
.id("210")
|
.id("210")
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
|
@ -180,7 +181,7 @@ public class TaskControllerTest extends InitTestEnvironment {
|
||||||
@Test
|
@Test
|
||||||
public void t5_stopAllTask() throws Exception {
|
public void t5_stopAllTask() throws Exception {
|
||||||
StopTaskData itemData = StopTaskData.builder()
|
StopTaskData itemData = StopTaskData.builder()
|
||||||
.type(ConstValue.DeviceCapacity.CLEANUP.getCode())
|
.type(DeviceCapacity.CLEANUP.getCode())
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
StopTaskReq reqData = new StopTaskReq();
|
StopTaskReq reqData = new StopTaskReq();
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package com.dispose.dptech;
|
package com.dispose.dptech;
|
||||||
|
|
||||||
import com.dispose.Global.InitTestEnvironment;
|
import com.dispose.Global.InitTestEnvironment;
|
||||||
import com.dispose.common.ConstValue;
|
import com.dispose.common.DisposeDeviceType;
|
||||||
import com.dispose.dispose.DeviceRouter;
|
import com.dispose.dispose.DeviceRouter;
|
||||||
import com.dispose.dispose.DisposeEntryManager;
|
import com.dispose.dispose.DisposeEntryManager;
|
||||||
import com.dispose.pojo.po.DisposeDeviceCapacity;
|
import com.dispose.pojo.po.DisposeDeviceCapacity;
|
||||||
|
@ -40,7 +40,7 @@ public class DPTechInterfaceTestCase extends InitTestEnvironment {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
DisposeEntryManager dp =
|
DisposeEntryManager dp =
|
||||||
DeviceRouter.deviceRouterFactory(ConstValue.DisposeDeviceType.DPTECH_UMC.getCode(), "10.88.77.15");
|
DeviceRouter.deviceRouterFactory(DisposeDeviceType.DPTECH_UMC.getCode(), "10.88.77.15");
|
||||||
|
|
||||||
List<DetectionObjectDataForService> detDevs = dp.getAllDetectionObject();
|
List<DetectionObjectDataForService> detDevs = dp.getAllDetectionObject();
|
||||||
|
|
||||||
|
@ -59,7 +59,7 @@ public class DPTechInterfaceTestCase extends InitTestEnvironment {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
DisposeEntryManager dp =
|
DisposeEntryManager dp =
|
||||||
DeviceRouter.deviceRouterFactory(ConstValue.DisposeDeviceType.DPTECH_UMC.getCode(), "10.88.77.15");
|
DeviceRouter.deviceRouterFactory(DisposeDeviceType.DPTECH_UMC.getCode(), "10.88.77.15");
|
||||||
|
|
||||||
String proDevs = dp.getProtectDevices();
|
String proDevs = dp.getProtectDevices();
|
||||||
|
|
||||||
|
@ -78,7 +78,7 @@ public class DPTechInterfaceTestCase extends InitTestEnvironment {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
DisposeEntryManager dp =
|
DisposeEntryManager dp =
|
||||||
DeviceRouter.deviceRouterFactory(ConstValue.DisposeDeviceType.DPTECH_UMC.getCode(), "10.88.77.15");
|
DeviceRouter.deviceRouterFactory(DisposeDeviceType.DPTECH_UMC.getCode(), "10.88.77.15");
|
||||||
|
|
||||||
List<ProtectionObjectDataForService> proObjs = dp.getAllProtectionObject();
|
List<ProtectionObjectDataForService> proObjs = dp.getAllProtectionObject();
|
||||||
|
|
||||||
|
@ -95,7 +95,7 @@ public class DPTechInterfaceTestCase extends InitTestEnvironment {
|
||||||
@Test
|
@Test
|
||||||
public void t4_getLinkStatus() {
|
public void t4_getLinkStatus() {
|
||||||
|
|
||||||
DisposeEntryManager dp = DeviceRouter.deviceRouterFactory(ConstValue.DisposeDeviceType.DPTECH_UMC.getCode(),
|
DisposeEntryManager dp = DeviceRouter.deviceRouterFactory(DisposeDeviceType.DPTECH_UMC.getCode(),
|
||||||
"10.88.77.15");
|
"10.88.77.15");
|
||||||
|
|
||||||
Assert.assertTrue(dp.getDeviceLinkStatus());
|
Assert.assertTrue(dp.getDeviceLinkStatus());
|
||||||
|
@ -109,7 +109,7 @@ public class DPTechInterfaceTestCase extends InitTestEnvironment {
|
||||||
@Test
|
@Test
|
||||||
public void t5_getDeviceCapacity() throws JsonProcessingException {
|
public void t5_getDeviceCapacity() throws JsonProcessingException {
|
||||||
|
|
||||||
DisposeEntryManager dp = DeviceRouter.deviceRouterFactory(ConstValue.DisposeDeviceType.DPTECH_UMC.getCode(),
|
DisposeEntryManager dp = DeviceRouter.deviceRouterFactory(DisposeDeviceType.DPTECH_UMC.getCode(),
|
||||||
"10.88.77.15");
|
"10.88.77.15");
|
||||||
|
|
||||||
List<DisposeDeviceCapacity> capList = dp.getDeviceCapacity();
|
List<DisposeDeviceCapacity> capList = dp.getDeviceCapacity();
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package com.dispose.mapper;
|
package com.dispose.mapper;
|
||||||
|
|
||||||
import com.dispose.Global.InitTestEnvironment;
|
import com.dispose.Global.InitTestEnvironment;
|
||||||
import com.dispose.common.ConstValue;
|
import com.dispose.common.DisposeDeviceType;
|
||||||
import com.dispose.pojo.entity.DisposeDevice;
|
import com.dispose.pojo.entity.DisposeDevice;
|
||||||
import com.dispose.pojo.po.DisposeDeviceCapacity;
|
import com.dispose.pojo.po.DisposeDeviceCapacity;
|
||||||
import com.dispose.service.DisposeNodeManager;
|
import com.dispose.service.DisposeNodeManager;
|
||||||
|
@ -48,7 +48,7 @@ public class DisposeDeviceMapperTest extends InitTestEnvironment {
|
||||||
List<DisposeDeviceCapacity> devCaps = new ArrayList<>();
|
List<DisposeDeviceCapacity> devCaps = new ArrayList<>();
|
||||||
dev.setId(devId);
|
dev.setId(devId);
|
||||||
dev.setIpAddr("10.88.77.15");
|
dev.setIpAddr("10.88.77.15");
|
||||||
dev.setType(ConstValue.DisposeDeviceType.DPTECH_UMC.getCode());
|
dev.setType(DisposeDeviceType.DPTECH_UMC.getCode());
|
||||||
dev.setName("中移杭研实验室清洗设备");
|
dev.setName("中移杭研实验室清洗设备");
|
||||||
dev.setManufacturer("DPTech");
|
dev.setManufacturer("DPTech");
|
||||||
dev.setModel("UMC");
|
dev.setModel("UMC");
|
||||||
|
|
|
@ -1,12 +1,16 @@
|
||||||
package com.dispose.mapper;
|
package com.dispose.mapper;
|
||||||
|
|
||||||
import com.dispose.Global.InitTestEnvironment;
|
import com.dispose.Global.InitTestEnvironment;
|
||||||
import com.dispose.common.ConstValue;
|
import com.dispose.common.DeviceCapacity;
|
||||||
|
import com.dispose.common.DisposeTaskStatus;
|
||||||
|
import com.dispose.common.FlowDirection;
|
||||||
import com.dispose.pojo.vo.common.TaskInfoDetail;
|
import com.dispose.pojo.vo.common.TaskInfoDetail;
|
||||||
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.FixMethodOrder;
|
import org.junit.FixMethodOrder;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
@ -21,6 +25,7 @@ import org.springframework.test.context.junit4.SpringRunner;
|
||||||
@RunWith(SpringRunner.class)
|
@RunWith(SpringRunner.class)
|
||||||
@SpringBootTest
|
@SpringBootTest
|
||||||
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
||||||
|
@Slf4j
|
||||||
public class DisposeTaskMapperTest extends InitTestEnvironment {
|
public class DisposeTaskMapperTest extends InitTestEnvironment {
|
||||||
/**
|
/**
|
||||||
* The Obj mapper.
|
* The Obj mapper.
|
||||||
|
@ -76,10 +81,11 @@ public class DisposeTaskMapperTest extends InitTestEnvironment {
|
||||||
.id(-1L)
|
.id(-1L)
|
||||||
.deviceId(deviceId)
|
.deviceId(deviceId)
|
||||||
.accountId(accountId)
|
.accountId(accountId)
|
||||||
.type(ConstValue.DeviceCapacity.CLEANUP.getCode())
|
.type(DeviceCapacity.CLEANUP.getCode())
|
||||||
.disposeIp("192.168.0.1")
|
.disposeIp("192.168.0.1")
|
||||||
.flowDirection(ConstValue.FlowDirection.DIRECTION_TWOWAY.getCode())
|
.attackType("0")
|
||||||
.currentStatus(ConstValue.DisposeTaskStatus.TASK_NEW.getCode())
|
.flowDirection(FlowDirection.DIRECTION_TWOWAY.getCode())
|
||||||
|
.currentStatus(DisposeTaskStatus.TASK_NEW.getCode())
|
||||||
.planEndTime(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")))
|
.planEndTime(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")))
|
||||||
.endTime(endTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")))
|
.endTime(endTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")))
|
||||||
.build();
|
.build();
|
||||||
|
@ -96,7 +102,7 @@ public class DisposeTaskMapperTest extends InitTestEnvironment {
|
||||||
@Test
|
@Test
|
||||||
public void t2_changeTaskStatusTest() {
|
public void t2_changeTaskStatusTest() {
|
||||||
disposeTaskMapper.selectAll().forEach(v -> {
|
disposeTaskMapper.selectAll().forEach(v -> {
|
||||||
for (ConstValue.DisposeTaskStatus k : ConstValue.DisposeTaskStatus.values()) {
|
for (DisposeTaskStatus k : DisposeTaskStatus.values()) {
|
||||||
disposeTaskMapper.changeTaskCurrentStatus(v.getId(), k.getCode());
|
disposeTaskMapper.changeTaskCurrentStatus(v.getId(), k.getCode());
|
||||||
Assert.assertEquals(disposeTaskMapper.getTaskCurrentStatus(v.getId()), k.getCode());
|
Assert.assertEquals(disposeTaskMapper.getTaskCurrentStatus(v.getId()), k.getCode());
|
||||||
}
|
}
|
||||||
|
@ -112,6 +118,12 @@ public class DisposeTaskMapperTest extends InitTestEnvironment {
|
||||||
TaskInfoDetail taskInfo = disposeTaskMapper.getTaskInfoById(v.getId());
|
TaskInfoDetail taskInfo = disposeTaskMapper.getTaskInfoById(v.getId());
|
||||||
Assert.assertNotNull(taskInfo);
|
Assert.assertNotNull(taskInfo);
|
||||||
Assert.assertEquals(taskInfo.getId(), v.getId());
|
Assert.assertEquals(taskInfo.getId(), v.getId());
|
||||||
|
try {
|
||||||
|
log.info(objMapper.writerWithDefaultPrettyPrinter().writeValueAsString(taskInfo));
|
||||||
|
} catch (JsonProcessingException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
Assert.fail();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -122,27 +134,68 @@ public class DisposeTaskMapperTest extends InitTestEnvironment {
|
||||||
public void t4_getAllTaskByDisposeIpTest() {
|
public void t4_getAllTaskByDisposeIpTest() {
|
||||||
disposeTaskMapper.selectAll().forEach(v -> disposeTaskMapper
|
disposeTaskMapper.selectAll().forEach(v -> disposeTaskMapper
|
||||||
.getAllTaskByDisposeIp(v.getDisposeIp())
|
.getAllTaskByDisposeIp(v.getDisposeIp())
|
||||||
.forEach(k -> Assert.assertEquals(k.getDisposeIp(), v.getDisposeIp())));
|
.forEach(k -> {
|
||||||
|
Assert.assertEquals(k.getDisposeIp(), v.getDisposeIp());
|
||||||
|
try {
|
||||||
|
log.info(objMapper.writerWithDefaultPrettyPrinter().writeValueAsString(k));
|
||||||
|
} catch (JsonProcessingException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
Assert.fail();
|
||||||
|
}
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* T 5 get all task by node dev id.
|
* T 5 get all task by node dev id.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void t5_getAllTaskByNodeDevId() {
|
public void t5_getAllTaskByNodeDevIdTest() {
|
||||||
disposeTaskMapper.selectAll().forEach(v -> disposeTaskMapper
|
disposeTaskMapper.selectAll().forEach(v -> disposeTaskMapper
|
||||||
.getAllTaskByNodeDevId(v.getDeviceId())
|
.getAllTaskByNodeDevId(v.getDeviceId())
|
||||||
.forEach(k -> Assert.assertEquals(k.getDeviceId(), v.getDeviceId())));
|
.forEach(k -> {
|
||||||
|
Assert.assertEquals(k.getDeviceId(), v.getDeviceId());
|
||||||
|
try {
|
||||||
|
log.info(objMapper.writerWithDefaultPrettyPrinter().writeValueAsString(k));
|
||||||
|
} catch (JsonProcessingException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
Assert.fail();
|
||||||
|
}
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* T 6 get all task by node user id.
|
* T 6 get all task by node user id.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void t6_getAllTaskByNodeUserId() {
|
public void t6_getNodeAllTaskByUserIdTest() {
|
||||||
disposeTaskMapper.selectAll().forEach(v -> disposeTaskMapper
|
disposeTaskMapper.selectAll().forEach(v -> disposeTaskMapper
|
||||||
.getAllTaskByNodeUserId(v.getAccountId())
|
.getNodeAllTaskByUserId(v.getAccountId())
|
||||||
.forEach(k -> Assert.assertEquals(k.getAccountId(), v.getAccountId())));
|
.forEach(k -> {
|
||||||
|
Assert.assertEquals(k.getAccountId(), v.getAccountId());
|
||||||
|
try {
|
||||||
|
log.info(objMapper.writerWithDefaultPrettyPrinter().writeValueAsString(k));
|
||||||
|
} catch (JsonProcessingException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
Assert.fail();
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void t7_getNodeTaskByIpAndStatusTest() {
|
||||||
|
disposeTaskMapper.selectAll().forEach(v -> disposeTaskMapper
|
||||||
|
.getNodeTaskByIpAndStatus(v.getAccountId(), v.getDisposeIp(), v.getCurrentStatus())
|
||||||
|
.forEach(k -> {
|
||||||
|
Assert.assertEquals(k.getAccountId(), v.getAccountId());
|
||||||
|
Assert.assertEquals(k.getDisposeIp(), v.getDisposeIp());
|
||||||
|
Assert.assertEquals(k.getCurrentStatus(), v.getCurrentStatus());
|
||||||
|
try {
|
||||||
|
log.info(objMapper.writerWithDefaultPrettyPrinter().writeValueAsString(k));
|
||||||
|
} catch (JsonProcessingException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
Assert.fail();
|
||||||
|
}
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue