mirror of
https://codeup.aliyun.com/64f7d6b8ce01efaafef1e678/coal/coal.git
synced 2026-01-25 07:46:40 +08:00
完善ip黑名单
This commit is contained in:
@@ -33,6 +33,8 @@ public class DictCode {
|
||||
|
||||
public static final String LOGINUSERHIS_LOGINSTATUS = "loginUserHis.loginStatus";
|
||||
|
||||
public static final String IPLIST_ADDRESSTYPE = "ipList.addressType";
|
||||
|
||||
public static final String LOGINUSERHIS_LOGINTYPE = "loginUserHis.loginType";
|
||||
|
||||
public static final String LOGINUSERHIS_LOGOUTTYPE = "loginUserHis.logoutType";
|
||||
|
||||
@@ -12,6 +12,8 @@ import lombok.Data;
|
||||
import org.hibernate.annotations.Comment;
|
||||
import org.hibernate.annotations.Type;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Data
|
||||
public class CreateIpListDto extends CommonDto {
|
||||
@Type(PostgreSQLInetType.class)
|
||||
@@ -24,4 +26,11 @@ public class CreateIpListDto extends CommonDto {
|
||||
|
||||
@Comment("地址类型 0:黑名单 1:白名单")
|
||||
private String addressType;
|
||||
|
||||
|
||||
@Comment("开始时间")
|
||||
private LocalDateTime startTime;
|
||||
|
||||
@Comment("结束时间")
|
||||
private LocalDateTime endTime;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package cn.lihongjie.coal.ipList.dto;
|
||||
|
||||
import cn.lihongjie.coal.base.dto.CommonDto;
|
||||
import cn.lihongjie.coal.common.DictCode;
|
||||
import cn.lihongjie.coal.pojoProcessor.DictTranslate;
|
||||
|
||||
import io.hypersistence.utils.hibernate.type.basic.Inet;
|
||||
import io.hypersistence.utils.hibernate.type.basic.PostgreSQLInetType;
|
||||
@@ -12,6 +14,8 @@ import lombok.Data;
|
||||
import org.hibernate.annotations.Comment;
|
||||
import org.hibernate.annotations.Type;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Data
|
||||
public class IpListDto extends CommonDto {
|
||||
@Type(PostgreSQLInetType.class)
|
||||
@@ -24,4 +28,15 @@ public class IpListDto extends CommonDto {
|
||||
|
||||
@Comment("地址类型 0:黑名单 1:白名单")
|
||||
private String addressType;
|
||||
|
||||
|
||||
@DictTranslate(dictKey = DictCode.IPLIST_ADDRESSTYPE)
|
||||
private String addressTypeName;
|
||||
|
||||
@Comment("开始时间")
|
||||
private LocalDateTime startTime;
|
||||
|
||||
@Comment("结束时间")
|
||||
private LocalDateTime endTime;
|
||||
|
||||
}
|
||||
|
||||
@@ -12,6 +12,8 @@ import lombok.Data;
|
||||
import org.hibernate.annotations.Comment;
|
||||
import org.hibernate.annotations.Type;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Data
|
||||
public class UpdateIpListDto extends CommonDto {
|
||||
@Type(PostgreSQLInetType.class)
|
||||
@@ -24,4 +26,11 @@ public class UpdateIpListDto extends CommonDto {
|
||||
|
||||
@Comment("地址类型 0:黑名单 1:白名单")
|
||||
private String addressType;
|
||||
|
||||
|
||||
@Comment("开始时间")
|
||||
private LocalDateTime startTime;
|
||||
|
||||
@Comment("结束时间")
|
||||
private LocalDateTime endTime;
|
||||
}
|
||||
|
||||
@@ -6,8 +6,10 @@ import cn.lihongjie.coal.ipList.entity.IpListEntity;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Repository
|
||||
public interface IpListRepository extends BaseRepository<IpListEntity> {
|
||||
@Query(value = "select address_type from t_ip_list where address >>= cast(?1 as inet) order by address_type desc limit 1 ", nativeQuery = true)
|
||||
String getAddressType(String address);
|
||||
@Query(value = "select address_type from t_ip_list where address >>= cast(?1 as inet) and start_time <=?2 and end_time>=?2 order by address_type desc limit 1 ", nativeQuery = true)
|
||||
String getAddressType(String address, LocalDateTime now);
|
||||
}
|
||||
|
||||
@@ -23,6 +23,8 @@ import org.springframework.data.domain.Sort;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
@Transactional
|
||||
@@ -75,7 +77,13 @@ public class IpListService extends BaseService<IpListEntity, IpListRepository> {
|
||||
|
||||
@Cacheable(value = Constants.CACHE_ADDRESS_TYPE, key = "#address")
|
||||
public String getAddressType(String address) {
|
||||
return this.repository.getAddressType(address);
|
||||
|
||||
if (address.contains(",")){
|
||||
address = address.split(",")[0];
|
||||
address = address.trim();
|
||||
}
|
||||
|
||||
return this.repository.getAddressType(address, LocalDateTime.now());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,28 +35,50 @@ public class JacksonConfig {
|
||||
LocalDateTime.class, new LocalDateTimeDeserializer(dateTimeFormatter));
|
||||
|
||||
module.addDeserializer(String.class, new CustomStringDeserializer());
|
||||
module.addSerializer(Inet.class, new JsonSerializer<Inet>() {
|
||||
@Override
|
||||
public void serialize(Inet value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
|
||||
module.addSerializer(
|
||||
Inet.class,
|
||||
new JsonSerializer<Inet>() {
|
||||
@Override
|
||||
public void serialize(
|
||||
Inet value, JsonGenerator gen, SerializerProvider serializers)
|
||||
throws IOException {
|
||||
|
||||
gen.writeString(value.getAddress());
|
||||
}
|
||||
});
|
||||
|
||||
module.addSerializer(Timestamp.class, new JsonSerializer<Timestamp>() {
|
||||
@Override
|
||||
public void serialize(Timestamp value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
|
||||
gen.writeObject(value.toLocalDateTime());
|
||||
}
|
||||
});
|
||||
gen.writeString(value.getAddress());
|
||||
}
|
||||
});
|
||||
|
||||
module.addDeserializer(Inet.class, new JsonDeserializer<Inet>() {
|
||||
@Override
|
||||
public Inet deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
|
||||
return new Inet(p.getText());
|
||||
}
|
||||
module.addSerializer(
|
||||
Timestamp.class,
|
||||
new JsonSerializer<Timestamp>() {
|
||||
@Override
|
||||
public void serialize(
|
||||
Timestamp value, JsonGenerator gen, SerializerProvider serializers)
|
||||
throws IOException {
|
||||
gen.writeObject(value.toLocalDateTime());
|
||||
}
|
||||
});
|
||||
|
||||
module.addDeserializer(
|
||||
Inet.class,
|
||||
new JsonDeserializer<Inet>() {
|
||||
@Override
|
||||
public Inet deserialize(JsonParser p, DeserializationContext ctxt)
|
||||
throws IOException {
|
||||
return new Inet(p.getText());
|
||||
}
|
||||
});
|
||||
|
||||
module.addSerializer(
|
||||
Inet.class,
|
||||
new JsonSerializer<Inet>() {
|
||||
@Override
|
||||
public void serialize(
|
||||
Inet value, JsonGenerator gen, SerializerProvider serializers)
|
||||
throws IOException {
|
||||
gen.writeString(value.getAddress());
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
return module;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1892,6 +1892,21 @@
|
||||
]
|
||||
},
|
||||
|
||||
{
|
||||
"code": "ipList.addressType",
|
||||
"name": "ip地址类型",
|
||||
"item": [
|
||||
{
|
||||
"code": "0",
|
||||
"name": "黑名单"
|
||||
},
|
||||
{
|
||||
"code": "1",
|
||||
"name": "白名单"
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
{
|
||||
"code": "loginUserHis.loginType",
|
||||
"name": "登录类型",
|
||||
|
||||
Reference in New Issue
Block a user