Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
有来技术
youlai-mall
提交
174d78a9
Y
youlai-mall
项目概览
有来技术
/
youlai-mall
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Y
youlai-mall
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
174d78a9
编写于
3月 10, 2021
作者:
H
haoxr
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat:删除登录记录
上级
eb6a762e
变更
14
显示空白变更内容
内联
并排
Showing
14 changed file
with
84 addition
and
37 deletion
+84
-37
mall-pms/pms-boot/src/main/java/com/youlai/mall/pms/controller/app/SearchController.java
.../com/youlai/mall/pms/controller/app/SearchController.java
+4
-2
youlai-admin/admin-api/src/main/java/com/youlai/admin/pojo/domain/LoginRecord.java
...c/main/java/com/youlai/admin/pojo/domain/LoginRecord.java
+2
-3
youlai-admin/admin-boot/pom.xml
youlai-admin/admin-boot/pom.xml
+1
-1
youlai-admin/admin-boot/src/main/java/com/youlai/admin/common/constant/ESConstants.java
...in/java/com/youlai/admin/common/constant/ESConstants.java
+2
-2
youlai-admin/admin-boot/src/main/java/com/youlai/admin/controller/DashboardController.java
...java/com/youlai/admin/controller/DashboardController.java
+4
-5
youlai-admin/admin-boot/src/main/java/com/youlai/admin/controller/LoginRecordController.java
...va/com/youlai/admin/controller/LoginRecordController.java
+11
-12
youlai-auth/pom.xml
youlai-auth/pom.xml
+2
-2
youlai-common/common-core/src/main/java/com/youlai/common/base/BaseDocument.java
...re/src/main/java/com/youlai/common/base/BaseDocument.java
+22
-0
youlai-common/common-elasticsearch/pom.xml
youlai-common/common-elasticsearch/pom.xml
+5
-0
youlai-common/common-elasticsearch/src/main/java/com/youlai/common/elasticsearch/service/ElasticSearchService.java
...ai/common/elasticsearch/service/ElasticSearchService.java
+22
-3
youlai-common/common-web/pom.xml
youlai-common/common-web/pom.xml
+0
-1
youlai-common/common-web/src/main/java/com/youlai/common/web/aspect/LoginLogAspect.java
...ain/java/com/youlai/common/web/aspect/LoginLogAspect.java
+1
-0
youlai-common/common-web/src/main/java/com/youlai/common/web/util/IPUtils.java
...web/src/main/java/com/youlai/common/web/util/IPUtils.java
+6
-4
youlai-gateway/pom.xml
youlai-gateway/pom.xml
+2
-2
未找到文件。
mall-pms/pms-boot/src/main/java/com/youlai/mall/pms/controller/app/SearchController.java
浏览文件 @
174d78a9
...
...
@@ -34,10 +34,12 @@ public class SearchController {
})
@GetMapping
(
"/{name}"
)
public
Result
searchByName
(
@PathVariable
String
name
)
{
SearchSourceBuilder
builder
=
new
SearchSourceBuilder
();
/*
SearchSourceBuilder builder = new SearchSourceBuilder();
builder.query(QueryBuilders.matchQuery("name", name));
List<PmsProduct> list = elasticSearchService.search(builder.query(), PmsProduct.class, "pms_spu");
return
Result
.
success
(
list
);
return Result.success(list);*/
return
null
;
}
}
youlai-admin/admin-api/src/main/java/com/youlai/admin/pojo/domain/LoginRecord.java
浏览文件 @
174d78a9
package
com.youlai.admin.pojo.domain
;
import
com.youlai.common.base.BaseDocument
;
import
lombok.Data
;
/**
...
...
@@ -7,9 +8,7 @@ import lombok.Data;
* @date 2021-03-09
*/
@Data
public
class
LoginRecord
{
private
String
_id
;
public
class
LoginRecord
extends
BaseDocument
{
private
String
description
;
...
...
youlai-admin/admin-boot/pom.xml
浏览文件 @
174d78a9
...
...
@@ -95,7 +95,7 @@
<version>
1.0.0
</version>
<executions>
<!--执行mvn package,即执行 mvn clean package docker:build-->
<!--
<execution>
<!--
<execution>
<id>build-image</id>
<phase>package</phase>
<goals>
...
...
youlai-admin/admin-boot/src/main/java/com/youlai/admin/common/constant/ESConstants.java
浏览文件 @
174d78a9
...
...
@@ -6,9 +6,9 @@ package com.youlai.admin.common.constant;
*/
public
interface
ESConstants
{
String
INDEX_LOGIN
_PREFIX
=
"youlai-auth-login-"
;
String
LOGIN_INDEX
_PREFIX
=
"youlai-auth-login-"
;
String
INDEX_LOGIN
_PATTERN
=
"youlai-auth-login-*"
;
String
LOGIN_INDEX
_PATTERN
=
"youlai-auth-login-*"
;
}
youlai-admin/admin-boot/src/main/java/com/youlai/admin/controller/DashboardController.java
浏览文件 @
174d78a9
...
...
@@ -26,8 +26,8 @@ import java.util.HashMap;
import
java.util.Map
;
/**
* @author hxr
* @description 首页控制台
* @author hxr
* @date 2021-03-08
*/
@Api
(
tags
=
"首页控制台"
)
...
...
@@ -54,14 +54,13 @@ public class DashboardController {
for
(
int
i
=
0
;
i
<
days
;
i
++)
{
String
date
=
now
.
plusDays
(-
i
).
format
(
formatter
);
xData
[
i
]
=
date
;
indices
[
i
]
=
ESConstants
.
INDEX_LOGIN
_PREFIX
+
date
;
indices
[
i
]
=
ESConstants
.
LOGIN_INDEX
_PREFIX
+
date
;
}
// 查询条件,范围内日期统计
RangeQueryBuilder
rangeQueryBuilder
=
QueryBuilders
.
rangeQuery
(
"date"
).
from
(
startDate
).
to
(
endDate
);
BoolQueryBuilder
boolQueryBuilder
=
QueryBuilders
.
boolQuery
()
.
must
(
rangeQueryBuilder
)
/*.must(QueryBuilders.wildcardQuery("accessToken", "*"))*/
;
// 登录成功统计
.
must
(
rangeQueryBuilder
);
// 总数统计
Map
<
String
,
Long
>
totalCountMap
=
elasticSearchService
.
dateHistogram
(
...
...
@@ -82,7 +81,7 @@ public class DashboardController {
Long
[]
totalCount
=
new
Long
[
days
];
Long
[]
myCount
=
new
Long
[
days
];
Arrays
.
sort
(
xData
);
// 默认升序
排序
Arrays
.
sort
(
xData
);
// 默认升序
for
(
int
i
=
0
;
i
<
days
;
i
++)
{
String
key
=
xData
[
i
];
totalCount
[
i
]
=
Convert
.
toLong
(
totalCountMap
.
get
(
key
),
0
l
);
...
...
youlai-admin/admin-boot/src/main/java/com/youlai/admin/controller/LoginRecordController.java
浏览文件 @
174d78a9
...
...
@@ -3,6 +3,7 @@ package com.youlai.admin.controller;
import
cn.hutool.core.util.StrUtil
;
import
com.youlai.admin.common.constant.ESConstants
;
import
com.youlai.admin.pojo.domain.LoginRecord
;
import
com.youlai.common.base.BaseDocument
;
import
com.youlai.common.elasticsearch.service.ElasticSearchService
;
import
com.youlai.common.result.Result
;
import
io.swagger.annotations.Api
;
...
...
@@ -18,6 +19,8 @@ import org.elasticsearch.search.sort.FieldSortBuilder;
import
org.elasticsearch.search.sort.SortOrder
;
import
org.springframework.web.bind.annotation.*
;
import
java.io.IOException
;
import
java.util.Arrays
;
import
java.util.List
;
/**
...
...
@@ -26,7 +29,7 @@ import java.util.List;
*/
@Api
(
tags
=
"登录记录"
)
@RestController
@RequestMapping
(
"/api.admin/v1/
records/login
"
)
@RequestMapping
(
"/api.admin/v1/
login_records
"
)
@Slf4j
@AllArgsConstructor
public
class
LoginRecordController
{
...
...
@@ -34,7 +37,6 @@ public class LoginRecordController {
ElasticSearchService
elasticSearchService
;
@ApiOperation
(
value
=
"列表分页"
,
httpMethod
=
"GET"
)
@ApiImplicitParams
({
@ApiImplicitParam
(
name
=
"page"
,
value
=
"页码"
,
defaultValue
=
"1"
,
paramType
=
"query"
,
dataType
=
"Long"
),
...
...
@@ -68,25 +70,22 @@ public class LoginRecordController {
queryBuilder
.
must
(
QueryBuilders
.
wildcardQuery
(
"clientIP"
,
"*"
+
clientIP
+
"*"
));
}
// 总记录数
long
count
=
elasticSearchService
.
count
(
queryBuilder
,
ESConstants
.
INDEX_LOGIN
_PATTERN
);
long
count
=
elasticSearchService
.
count
(
queryBuilder
,
ESConstants
.
LOGIN_INDEX
_PATTERN
);
// 排序
FieldSortBuilder
sortBuilder
=
new
FieldSortBuilder
(
"@timestamp"
).
order
(
SortOrder
.
DESC
);
// 分页
数
List
<
LoginRecord
>
list
=
elasticSearchService
.
search
(
queryBuilder
,
sortBuilder
,
page
,
limit
,
LoginRecord
.
class
,
ESConstants
.
INDEX_LOGIN
_PATTERN
);
// 分页
查询
List
<
LoginRecord
>
list
=
elasticSearchService
.
search
(
queryBuilder
,
sortBuilder
,
page
,
limit
,
LoginRecord
.
class
,
ESConstants
.
LOGIN_INDEX
_PATTERN
);
return
Result
.
success
(
list
,
count
);
}
@ApiOperation
(
value
=
"删除登录记录"
,
httpMethod
=
"DELETE"
)
@ApiImplicitParam
(
name
=
"ids"
,
value
=
"id集合"
,
required
=
true
,
paramType
=
"query"
,
dataType
=
"String"
)
@DeleteMapping
(
"/{ids}"
)
public
Result
delete
(
@PathVariable
String
ids
)
{
return
Result
.
judge
(
true
);
@DeleteMapping
public
Result
delete
(
@RequestBody
List
<
BaseDocument
>
documents
)
{
documents
.
forEach
(
document
->
elasticSearchService
.
deleteById
(
document
.
getId
(),
document
.
getIndex
()));
return
Result
.
success
();
}
}
youlai-auth/pom.xml
浏览文件 @
174d78a9
...
...
@@ -155,13 +155,13 @@
<version>
1.0.0
</version>
<executions>
<!--执行mvn package,即执行 mvn clean package docker:build-->
<
!--<
execution>
<execution>
<id>
build-image
</id>
<phase>
package
</phase>
<goals>
<goal>
build
</goal>
</goals>
</execution>
-->
</execution>
</executions>
<configuration>
...
...
youlai-common/common-core/src/main/java/com/youlai/common/base/BaseDocument.java
0 → 100644
浏览文件 @
174d78a9
package
com.youlai.common.base
;
import
lombok.Data
;
/**
* @description document 是 ES 里的一个 JSON 对象,包括零个或多个field,类比关系数据库的一行记录
* @author haoxr
* @createTime 2021/3/9 22:14
*/
@Data
public
class
BaseDocument
{
/**
* 数据唯一标识
*/
private
String
id
;
/**
* 索引名称
*/
private
String
index
;
}
youlai-common/common-elasticsearch/pom.xml
浏览文件 @
174d78a9
...
...
@@ -13,6 +13,11 @@
<dependencies>
<dependency>
<groupId>
com.youlai
</groupId>
<artifactId>
common-core
</artifactId>
</dependency>
<dependency>
<groupId>
org.elasticsearch.client
</groupId>
<artifactId>
elasticsearch-rest-high-level-client
</artifactId>
...
...
youlai-common/common-elasticsearch/src/main/java/com/youlai/common/elasticsearch/service/ElasticSearchService.java
浏览文件 @
174d78a9
...
...
@@ -2,9 +2,12 @@ package com.youlai.common.elasticsearch.service;
import
cn.hutool.core.collection.CollectionUtil
;
import
cn.hutool.json.JSONUtil
;
import
com.youlai.common.base.BaseDocument
;
import
com.youlai.common.elasticsearch.constant.ESConstants
;
import
lombok.AllArgsConstructor
;
import
lombok.SneakyThrows
;
import
org.elasticsearch.action.delete.DeleteRequest
;
import
org.elasticsearch.action.delete.DeleteResponse
;
import
org.elasticsearch.action.search.SearchRequest
;
import
org.elasticsearch.action.search.SearchResponse
;
import
org.elasticsearch.action.support.IndicesOptions
;
...
...
@@ -12,7 +15,12 @@ import org.elasticsearch.client.RequestOptions;
import
org.elasticsearch.client.RestHighLevelClient
;
import
org.elasticsearch.client.core.CountRequest
;
import
org.elasticsearch.client.core.CountResponse
;
import
org.elasticsearch.index.query.BoolQueryBuilder
;
import
org.elasticsearch.index.query.QueryBuilder
;
import
org.elasticsearch.index.query.QueryBuilders
;
import
org.elasticsearch.index.query.TermQueryBuilder
;
import
org.elasticsearch.index.reindex.BulkByScrollResponse
;
import
org.elasticsearch.index.reindex.DeleteByQueryRequest
;
import
org.elasticsearch.search.SearchHit
;
import
org.elasticsearch.search.SearchHits
;
import
org.elasticsearch.search.aggregations.AggregationBuilder
;
...
...
@@ -24,6 +32,7 @@ import org.elasticsearch.search.builder.SearchSourceBuilder;
import
org.elasticsearch.search.sort.SortBuilder
;
import
org.springframework.stereotype.Service
;
import
java.io.IOException
;
import
java.util.*
;
/**
...
...
@@ -105,20 +114,21 @@ public class ElasticSearchService {
}
@SneakyThrows
public
<
T
>
List
<
T
>
search
(
QueryBuilder
queryBuilder
,
Class
<
T
>
clazz
,
String
...
indices
)
{
public
<
T
extends
BaseDocument
>
List
<
T
>
search
(
QueryBuilder
queryBuilder
,
Class
<
T
>
clazz
,
String
...
indices
)
{
List
<
T
>
list
=
this
.
search
(
queryBuilder
,
null
,
1
,
ESConstants
.
DEFAULT_PAGE_SIZE
,
clazz
,
indices
);
return
list
;
}
@SneakyThrows
public
<
T
>
List
<
T
>
search
(
QueryBuilder
queryBuilder
,
Integer
page
,
Integer
size
,
Class
<
T
>
clazz
,
String
...
indices
)
{
public
<
T
extends
BaseDocument
>
List
<
T
>
search
(
QueryBuilder
queryBuilder
,
Integer
page
,
Integer
size
,
Class
<
T
>
clazz
,
String
...
indices
)
{
List
<
T
>
list
=
this
.
search
(
queryBuilder
,
null
,
1
,
ESConstants
.
DEFAULT_PAGE_SIZE
,
clazz
,
indices
);
return
list
;
}
@SneakyThrows
public
<
T
>
List
<
T
>
search
(
QueryBuilder
queryBuilder
,
SortBuilder
sortBuilder
,
Integer
page
,
Integer
size
,
Class
<
T
>
clazz
,
String
...
indices
)
{
public
<
T
extends
BaseDocument
>
List
<
T
>
search
(
QueryBuilder
queryBuilder
,
SortBuilder
sortBuilder
,
Integer
page
,
Integer
size
,
Class
<
T
>
clazz
,
String
...
indices
)
{
// 构造SearchSourceBuilder
SearchSourceBuilder
searchSourceBuilder
=
new
SearchSourceBuilder
();
searchSourceBuilder
.
query
(
queryBuilder
);
...
...
@@ -136,9 +146,18 @@ public class ElasticSearchService {
List
<
T
>
list
=
CollectionUtil
.
newArrayList
();
for
(
SearchHit
hit
:
searchHits
)
{
T
t
=
JSONUtil
.
toBean
(
hit
.
getSourceAsString
(),
clazz
);
t
.
setId
(
hit
.
getId
());
// 数据的唯一标识
t
.
setIndex
(
hit
.
getIndex
());
// 索引
list
.
add
(
t
);
}
return
list
;
}
@SneakyThrows
public
boolean
deleteById
(
String
id
,
String
index
)
{
DeleteRequest
deleteRequest
=
new
DeleteRequest
(
index
,
id
);
DeleteResponse
deleteResponse
=
client
.
delete
(
deleteRequest
,
RequestOptions
.
DEFAULT
);
return
true
;
}
}
youlai-common/common-web/pom.xml
浏览文件 @
174d78a9
...
...
@@ -50,7 +50,6 @@
<artifactId>
ip2region
</artifactId>
</dependency>
<dependency>
<groupId>
com.github.dozermapper
</groupId>
<artifactId>
dozer-core
</artifactId>
...
...
youlai-common/common-web/src/main/java/com/youlai/common/web/aspect/LoginLogAspect.java
浏览文件 @
174d78a9
...
...
@@ -74,6 +74,7 @@ public class LoginLogAspect {
token
=
jsonObject
.
getStr
(
"value"
);
}
String
clientIP
=
IPUtils
.
getClientIP
(
request
);
// 客户端请求IP(注意:如果使用Nginx代理需配置)
log
.
info
(
"222. {}"
,
clientIP
);
String
region
=
IPUtils
.
ip2region
(
clientIP
);
// IP对应的城市信息
// MDC 扩展logback字段,具体请看logback-spring.xml的自定义日志输出格式
...
...
youlai-common/common-web/src/main/java/com/youlai/common/web/util/IPUtils.java
浏览文件 @
174d78a9
...
...
@@ -91,23 +91,24 @@ public class IPUtils {
return
Strings
.
EMPTY
;
}
log
.
info
(
"1. {}"
,
ip
);
if
(
LOCAL_IP
.
equals
(
ip
)){
return
"本地访问"
;
}
log
.
info
(
"2. {}"
,
ip
);
String
filePath
=
IPUtils
.
class
.
getResource
(
"/data/ip2region.db"
).
getPath
();
File
file
=
new
File
(
filePath
);
if
(
file
.
exists
()
==
false
)
{
return
Strings
.
EMPTY
;
}
log
.
info
(
"3. {}"
,
ip
);
try
{
DbConfig
config
=
new
DbConfig
();
DbSearcher
searcher
=
new
DbSearcher
(
config
,
filePath
);
log
.
info
(
"4. {}"
,
ip
);
Method
method
=
searcher
.
getClass
().
getMethod
(
"btreeSearch"
,
String
.
class
);
DataBlock
dataBlock
=
(
DataBlock
)
method
.
invoke
(
searcher
,
ip
);
log
.
info
(
"5. {}"
,
ip
);
return
dataBlock
.
getRegion
();
}
catch
(
Exception
e
)
{
...
...
@@ -117,4 +118,5 @@ public class IPUtils {
}
}
youlai-gateway/pom.xml
浏览文件 @
174d78a9
...
...
@@ -128,13 +128,13 @@
<version>
1.0.0
</version>
<executions>
<!--执行mvn package,即执行 mvn clean package docker:build-->
<execution>
<
!--<
execution>
<id>build-image</id>
<phase>package</phase>
<goals>
<goal>build</goal>
</goals>
</execution>
</execution>
-->
</executions>
<configuration>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录