parent
f8d3cf876c
commit
4e84e370c1
|
@ -1,58 +0,0 @@
|
|||
server.port=9276
|
||||
# 根据自身环境修改
|
||||
server.tomcat.basedir=./basedir
|
||||
# 多个项目放在nginx下同个端口,通过该配置区分
|
||||
server.servlet.context-path=/dispose
|
||||
# 配置数据源
|
||||
spring.datasource.url=jdbc:mysql://172.28.72.118:33061/dispose_cl?serverTimezone=Asia/Shanghai&zeroDateTimeBehavior\
|
||||
=convertToNull&useUnicode=true
|
||||
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
|
||||
spring.datasource.username=phoenix
|
||||
spring.datasource.password=Hy@rfph32
|
||||
|
||||
# 配置连接池
|
||||
spring.datasource.type=org.apache.commons.dbcp2.BasicDataSource
|
||||
spring.datasource.dbcp2.max-total=128
|
||||
spring.datasource.dbcp2.max-wait-millis=10000
|
||||
spring.datasource.dbcp2.max-idle=32
|
||||
spring.datasource.dbcp2.min-idle=8
|
||||
spring.datasource.dbcp2.initial-size=8
|
||||
spring.datasource.dbcp2.validation-query=SELECT 1
|
||||
spring.datasource.dbcp2.test-while-idle=true
|
||||
spring.datasource.dbcp2.connection-properties=characterEncoding=utf8
|
||||
#mybatis 配置
|
||||
# 下划线转驼峰 将带有下划线的表字段映射为驼峰格式的实体类属性
|
||||
#mybatis.configuration.map-underscore-to-camel-case: true
|
||||
mybatis.mapper-locations=classpath*:mappers/*.xml
|
||||
mybatis.type-aliases-package=com.dispose.pojo.entity
|
||||
mybatis.configuration.default-enum-type-handler=com.dispose.common.CommonEnumHandler
|
||||
#config log
|
||||
logging.config=file:config/logback.xml
|
||||
#config tomcat
|
||||
server.tomcat.max-threads=128
|
||||
#Json sort
|
||||
spring.jackson.mapper.sort-properties-alphabetically=true
|
||||
#Json strict type
|
||||
spring.jackson.mapper.allow-coercion-of-scalars=false
|
||||
#====custom config,begin with phoenix====
|
||||
#test
|
||||
phoenix.system-name=phoenix framework
|
||||
#config the swagger api switch true:可访问;false:不可访问
|
||||
phoenix.swagger-switch=true
|
||||
#config which client to use in redis,
|
||||
#jedis or redisson-sentinel,redisson-single
|
||||
phoenix.redis.type=redisson-single
|
||||
#config redis info
|
||||
#jedis config example>redis://:dfu56li_jdo8pd@172.28.72.111:7379/0,多个用逗号分隔
|
||||
#redisson sentinel config example>redis://172.28.72.104:28379,redis://172.28.72.124:28380,redis://172.28.72.124:28381
|
||||
#redisson single config example>redis://172.28.72.104:8380
|
||||
#phoenix.redis-server=redis://172.28.72.104:8380
|
||||
phoenix.redis-redisson-sentinel-master-name=mymaster
|
||||
phoenix.redis-redisson-pwd=cmcc2019
|
||||
#config request dec switch,true=dec,false=plain do nothing
|
||||
phoenix.request-dec-switch=false
|
||||
#config response enc switch,true=enc,false=plain do nothing
|
||||
phoenix.response-enc-switch=false
|
||||
#config aes 128 key,用于上述body的加解密
|
||||
phoenix.aes-key=Wt4EJu6Rrq5udd/42bNpCQ==
|
||||
#====custom config,begin with phoenix====
|
|
@ -2,10 +2,9 @@ package com.dispose.pojo.dto.protocol.device.manager;
|
|||
|
||||
import com.dispose.common.DisposeCapacityType;
|
||||
import com.dispose.common.DisposeObjectType;
|
||||
import com.dispose.common.IpAddrType;
|
||||
import com.dispose.validation.group.ValidGroups;
|
||||
import com.dispose.validation.valids.ValidAddCapacityInfo;
|
||||
import com.dispose.validation.valids.ValidBaseEnum;
|
||||
import com.dispose.validation.valids.ValidIpSegment;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
|
||||
import lombok.AllArgsConstructor;
|
||||
|
@ -13,8 +12,10 @@ import lombok.Builder;
|
|||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import javax.validation.GroupSequence;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
|
||||
/**
|
||||
* The type Add capacity info.
|
||||
*
|
||||
|
@ -26,6 +27,8 @@ import javax.validation.constraints.NotNull;
|
|||
@AllArgsConstructor
|
||||
@JsonPropertyOrder({"capacityType", "objectType", "ipType", "protectIp", "reserveNetflow"})
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
@ValidAddCapacityInfo(groups = ValidGroups.UpgradeDeviceValid.class)
|
||||
@GroupSequence({ValidGroups.UpgradeDeviceValid.class, ValidGroups.AddDeviceValid.class, AddCapacityInfo.class})
|
||||
public class AddCapacityInfo {
|
||||
/**
|
||||
* The Capacity type.
|
||||
|
@ -44,20 +47,15 @@ public class AddCapacityInfo {
|
|||
/**
|
||||
* The Ip type.
|
||||
*/
|
||||
@NotNull(message = "ipType IP地址类型不能为空", groups = ValidGroups.UpgradeDeviceValid.class)
|
||||
@ValidBaseEnum(enumClass = IpAddrType.class, groups = ValidGroups.UpgradeDeviceValid.class)
|
||||
private Integer ipType;
|
||||
|
||||
/**
|
||||
* The Protect ip.
|
||||
*/
|
||||
@NotNull(message = "protectIp 处置IP不能为空", groups = ValidGroups.UpgradeDeviceValid.class)
|
||||
@ValidIpSegment(message = "protectIp Ip地址格式错误", groups = ValidGroups.UpgradeDeviceValid.class)
|
||||
private String protectIp;
|
||||
|
||||
/**
|
||||
* The Reserve netflow.
|
||||
*/
|
||||
@NotNull(message = "reserveNetflow 清洗储备流量不能为空", groups = ValidGroups.UpgradeDeviceValid.class)
|
||||
private Integer reserveNetflow;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
package com.dispose.validation.valids;
|
||||
|
||||
import com.dispose.validation.valids.impl.ValidAddCapacityInfoImpl;
|
||||
|
||||
import javax.validation.Constraint;
|
||||
import javax.validation.Payload;
|
||||
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;
|
||||
|
||||
/**
|
||||
* The interface Valid add capacity info.
|
||||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
@Target({ElementType.TYPE, ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
@Constraint(validatedBy = {ValidAddCapacityInfoImpl.class})
|
||||
public @interface ValidAddCapacityInfo {
|
||||
/**
|
||||
* Message string.
|
||||
*
|
||||
* @return the string
|
||||
*/
|
||||
String message() default "";
|
||||
|
||||
/**
|
||||
* Groups class [ ].
|
||||
*
|
||||
* @return the class [ ]
|
||||
*/
|
||||
Class<?>[] groups() default {};
|
||||
|
||||
/**
|
||||
* Payload class [ ].
|
||||
*
|
||||
* @return the class [ ]
|
||||
*/
|
||||
Class<? extends Payload>[] payload() default {};
|
||||
}
|
|
@ -0,0 +1,112 @@
|
|||
package com.dispose.validation.valids.impl;
|
||||
|
||||
import com.dispose.common.ConstValue;
|
||||
import com.dispose.common.DisposeCapacityType;
|
||||
import com.dispose.common.DisposeConfigValue;
|
||||
import com.dispose.common.IpAddrType;
|
||||
import com.dispose.pojo.dto.protocol.device.manager.AddCapacityInfo;
|
||||
import com.dispose.validation.valids.ValidAddCapacityInfo;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.hibernate.validator.internal.engine.constraintvalidation.ConstraintValidatorContextImpl;
|
||||
|
||||
import javax.validation.ConstraintValidator;
|
||||
import javax.validation.ConstraintValidatorContext;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* The type Valid add capacity info.
|
||||
*
|
||||
* @author <huangxin@cmhi.chinamoblie.com>
|
||||
*/
|
||||
@Slf4j
|
||||
public class ValidAddCapacityInfoImpl implements ConstraintValidator<ValidAddCapacityInfo, AddCapacityInfo> {
|
||||
/**
|
||||
* The Message.
|
||||
*/
|
||||
private String message;
|
||||
|
||||
/**
|
||||
* Initialize.
|
||||
*
|
||||
* @param constraintAnnotation the constraint annotation
|
||||
*/
|
||||
@Override
|
||||
public void initialize(ValidAddCapacityInfo constraintAnnotation) {
|
||||
this.message = constraintAnnotation.message();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets field name.
|
||||
*
|
||||
* @param ctx the ctx
|
||||
* @return the field name
|
||||
*/
|
||||
private String getFieldName(ConstraintValidatorContext ctx) {
|
||||
return ((ConstraintValidatorContextImpl) ctx).getConstraintViolationCreationContexts()
|
||||
.get(0).getPath().getLeafNode().getName();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Is valid boolean.
|
||||
*
|
||||
* @param addCapacityInfo the add capacity info
|
||||
* @param ctx the ctx
|
||||
* @return the boolean
|
||||
*/
|
||||
@Override
|
||||
public boolean isValid(AddCapacityInfo addCapacityInfo, ConstraintValidatorContext ctx) {
|
||||
boolean ret = true;
|
||||
|
||||
if (addCapacityInfo == null || addCapacityInfo.getCapacityType() == null) {
|
||||
// 重新设置消息
|
||||
ctx.disableDefaultConstraintViolation();
|
||||
ctx.buildConstraintViolationWithTemplate(this.message + " 字段 " + getFieldName(ctx) + " 不能为null")
|
||||
.addConstraintViolation();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
List<String> errMsg = new ArrayList<>();
|
||||
|
||||
if (addCapacityInfo.getCapacityType().equals(DisposeCapacityType.CLEANUP.getValue())) {
|
||||
if (addCapacityInfo.getIpType() == null) {
|
||||
errMsg.add("字段 ipType 不能为null");
|
||||
ret = false;
|
||||
}
|
||||
|
||||
if (Arrays.stream(IpAddrType.values()).noneMatch(v -> v.getValue().equals(addCapacityInfo.getIpType()))) {
|
||||
List<Integer> val = Arrays.stream(IpAddrType.values()).map(IpAddrType::getValue).collect(Collectors.toList());
|
||||
errMsg.add("字段 ipType 值 {}, 错误, 合理取值范围为:" + val.toString());
|
||||
ret = false;
|
||||
}
|
||||
|
||||
if (addCapacityInfo.getProtectIp() == null || addCapacityInfo.getProtectIp().length() == 0) {
|
||||
errMsg.add("字段 protectIp 不能为空");
|
||||
ret = false;
|
||||
} else {
|
||||
for (String s : addCapacityInfo.getProtectIp().split(DisposeConfigValue.SPLIT_CHAR)) {
|
||||
if (!Pattern.matches(ConstValue.IP_ADDR_SEGMENT_REG, s.replace(" ", ""))) {
|
||||
errMsg.add("字段 protectIp 包含非法值: " + s);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (addCapacityInfo.getReserveNetflow() == null) {
|
||||
errMsg.add("字段 reserveNetflow 不能为null");
|
||||
ret = false;
|
||||
}
|
||||
}
|
||||
|
||||
// 重新设置消息
|
||||
ctx.disableDefaultConstraintViolation();
|
||||
ctx.buildConstraintViolationWithTemplate(this.message + " " + errMsg.toString()).addConstraintViolation();
|
||||
|
||||
return ret;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue