Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
E
event
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
陈世强
event
Commits
31fb8907
提交
31fb8907
authored
4月 12, 2025
作者:
yanxin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
资讯手动打标逻辑优化
上级
0857edbd
隐藏空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
110 行增加
和
33 行删除
+110
-33
InformationController.java
...m/zzsn/event/controller/common/InformationController.java
+23
-3
EsService.java
src/main/java/com/zzsn/event/es/EsService.java
+39
-0
InformationService.java
src/main/java/com/zzsn/event/service/InformationService.java
+3
-2
InformationServiceImpl.java
...a/com/zzsn/event/service/impl/InformationServiceImpl.java
+43
-28
DataBindLabelFrom.java
src/main/java/com/zzsn/event/vo/DataBindLabelFrom.java
+2
-0
没有找到文件。
src/main/java/com/zzsn/event/controller/common/InformationController.java
浏览文件 @
31fb8907
...
@@ -269,6 +269,20 @@ public class InformationController {
...
@@ -269,6 +269,20 @@ public class InformationController {
}
}
/**
/**
* 删除指定标签
* @param id
* @param relationId
* @param index
* @return
*/
@GetMapping
(
"/deleteLabel"
)
public
Result
<?>
delLabel
(
@RequestParam
(
"id"
)
String
id
,
@RequestParam
(
"relationId"
)
String
relationId
,
@RequestParam
(
"index"
)
String
index
)
{
informationService
.
removeLabelById
(
index
,
id
,
relationId
);
return
Result
.
OK
(
"删除成功"
);
}
/**
* 批量删除标签
* 批量删除标签
*
*
* @param searchCondition 筛选条件
* @param searchCondition 筛选条件
...
@@ -380,9 +394,15 @@ public class InformationController {
...
@@ -380,9 +394,15 @@ public class InformationController {
*/
*/
@PostMapping
(
value
=
"/modifyLabel"
)
@PostMapping
(
value
=
"/modifyLabel"
)
public
Result
<?>
modifyLabel
(
@RequestBody
DataBindLabelFrom
bindLabelFrom
)
{
public
Result
<?>
modifyLabel
(
@RequestBody
DataBindLabelFrom
bindLabelFrom
)
{
List
<
DictVO
>
nodes
=
subjectDictMapService
.
boundList
(
bindLabelFrom
.
getSubjectId
());
if
(
bindLabelFrom
.
getBindList
()==
null
||
bindLabelFrom
.
getBindList
().
isEmpty
()){
informationService
.
modifyLabel
(
bindLabelFrom
,
nodes
);
List
<
DictVO
>
boundList
=
subjectDictMapService
.
boundList
(
bindLabelFrom
.
getSubjectId
());
return
Result
.
OK
();
bindLabelFrom
.
setBindList
(
boundList
);
}
if
(
bindLabelFrom
.
getBindList
()==
null
||
bindLabelFrom
.
getBindList
().
isEmpty
()){
return
Result
.
FAIL
(
"专题未绑定标签,不可编辑"
);
}
informationService
.
modifyLabel
(
bindLabelFrom
);
return
Result
.
OK
(
"编辑成功"
);
}
}
/**
/**
...
...
src/main/java/com/zzsn/event/es/EsService.java
浏览文件 @
31fb8907
...
@@ -18,6 +18,7 @@ import com.zzsn.event.service.*;
...
@@ -18,6 +18,7 @@ import com.zzsn.event.service.*;
import
com.zzsn.event.util.DateUtil
;
import
com.zzsn.event.util.DateUtil
;
import
com.zzsn.event.util.EsDateUtil
;
import
com.zzsn.event.util.EsDateUtil
;
import
com.zzsn.event.util.EsIndexUtil
;
import
com.zzsn.event.util.EsIndexUtil
;
import
com.zzsn.event.util.EsOpUtil
;
import
com.zzsn.event.util.tree.Node
;
import
com.zzsn.event.util.tree.Node
;
import
com.zzsn.event.vo.*
;
import
com.zzsn.event.vo.*
;
import
com.zzsn.event.vo.es.DisplayInfo
;
import
com.zzsn.event.vo.es.DisplayInfo
;
...
@@ -27,8 +28,11 @@ import lombok.extern.slf4j.Slf4j;
...
@@ -27,8 +28,11 @@ import lombok.extern.slf4j.Slf4j;
import
lombok.val
;
import
lombok.val
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.lucene.search.join.ScoreMode
;
import
org.apache.lucene.search.join.ScoreMode
;
import
org.elasticsearch.action.get.GetRequest
;
import
org.elasticsearch.action.get.GetResponse
;
import
org.elasticsearch.action.search.SearchRequest
;
import
org.elasticsearch.action.search.SearchRequest
;
import
org.elasticsearch.action.search.SearchResponse
;
import
org.elasticsearch.action.search.SearchResponse
;
import
org.elasticsearch.action.update.UpdateRequest
;
import
org.elasticsearch.client.HttpAsyncResponseConsumerFactory
;
import
org.elasticsearch.client.HttpAsyncResponseConsumerFactory
;
import
org.elasticsearch.client.RequestOptions
;
import
org.elasticsearch.client.RequestOptions
;
import
org.elasticsearch.client.RestHighLevelClient
;
import
org.elasticsearch.client.RestHighLevelClient
;
...
@@ -51,6 +55,7 @@ import org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilde
...
@@ -51,6 +55,7 @@ import org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilde
import
org.elasticsearch.search.aggregations.metrics.Cardinality
;
import
org.elasticsearch.search.aggregations.metrics.Cardinality
;
import
org.elasticsearch.search.builder.SearchSourceBuilder
;
import
org.elasticsearch.search.builder.SearchSourceBuilder
;
import
org.elasticsearch.search.collapse.CollapseBuilder
;
import
org.elasticsearch.search.collapse.CollapseBuilder
;
import
org.elasticsearch.search.fetch.subphase.FetchSourceContext
;
import
org.elasticsearch.search.sort.SortBuilders
;
import
org.elasticsearch.search.sort.SortBuilders
;
import
org.elasticsearch.search.sort.SortOrder
;
import
org.elasticsearch.search.sort.SortOrder
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
@@ -92,6 +97,8 @@ public class EsService {
...
@@ -92,6 +97,8 @@ public class EsService {
private
ISubjectKeywordsMapService
subjectKeywordsMapService
;
private
ISubjectKeywordsMapService
subjectKeywordsMapService
;
@Autowired
@Autowired
private
CommonService
commonService
;
private
CommonService
commonService
;
@Autowired
private
EsOpUtil
esOpUtil
;
/**
/**
* 获取专题下的资讯
* 获取专题下的资讯
...
@@ -2569,4 +2576,36 @@ public class EsService {
...
@@ -2569,4 +2576,36 @@ public class EsService {
}
}
return
fullTextBoolQuery
;
return
fullTextBoolQuery
;
}
}
/**
* 根据id查询标签列表
* @param index
* @param id
* @return
*/
public
List
<
Label
>
getLabelsById
(
String
index
,
String
id
)
{
try
{
GetRequest
request
=
new
GetRequest
(
index
,
id
);
request
.
fetchSourceContext
(
new
FetchSourceContext
(
true
,
new
String
[]{
"labels"
,
"title"
},
null
));
request
.
realtime
(
true
);
GetResponse
documentFields
=
client
.
get
(
request
,
RequestOptions
.
DEFAULT
);
String
labelsStr
=
JSONArray
.
toJSONString
(
documentFields
.
getSourceAsMap
().
get
(
"labels"
));
return
JSONArray
.
parseArray
(
labelsStr
,
Label
.
class
);
}
catch
(
Exception
e
)
{
log
.
error
(
"根据数据id获取标签失败,id:{},e:{}"
,
id
,
e
.
getMessage
());
}
return
null
;
}
/**
* 根据id更新标签列表
* @param index
* @param id
* @param labels
*/
public
void
updateLabelsById
(
String
index
,
String
id
,
List
<
Label
>
labels
)
{
JSONObject
jsonObject
=
new
JSONObject
();
jsonObject
.
put
(
"labels"
,
labels
);
esOpUtil
.
docUpdateById
(
index
,
id
,
jsonObject
.
toString
());
}
}
}
src/main/java/com/zzsn/event/service/InformationService.java
浏览文件 @
31fb8907
...
@@ -138,11 +138,10 @@ public interface InformationService {
...
@@ -138,11 +138,10 @@ public interface InformationService {
* 资讯绑定标签
* 资讯绑定标签
*
*
* @param dataBindLabelFrom 绑定参数
* @param dataBindLabelFrom 绑定参数
* @param boundList 专题绑定的标签(数据字典)集合
* @author lkg
* @author lkg
* @date 2025/3/31
* @date 2025/3/31
*/
*/
void
modifyLabel
(
DataBindLabelFrom
dataBindLabelFrom
,
List
<
DictVO
>
boundList
);
void
modifyLabel
(
DataBindLabelFrom
dataBindLabelFrom
);
/**
/**
* 审核
* 审核
...
@@ -260,4 +259,6 @@ public interface InformationService {
...
@@ -260,4 +259,6 @@ public interface InformationService {
* @date 2025/2/28
* @date 2025/2/28
*/
*/
List
<
SpecialInformation
>
informationAllList
(
InfoDataSearchCondition
searchCondition
);
List
<
SpecialInformation
>
informationAllList
(
InfoDataSearchCondition
searchCondition
);
void
removeLabelById
(
String
index
,
String
id
,
String
relationId
);
}
}
src/main/java/com/zzsn/event/service/impl/InformationServiceImpl.java
浏览文件 @
31fb8907
...
@@ -651,39 +651,44 @@ public class InformationServiceImpl implements InformationService {
...
@@ -651,39 +651,44 @@ public class InformationServiceImpl implements InformationService {
}
}
@Override
@Override
public
void
modifyLabel
(
DataBindLabelFrom
dataBindLabelFrom
,
List
<
DictVO
>
boundList
)
{
public
void
modifyLabel
(
DataBindLabelFrom
dataBindLabelFrom
)
{
DisplayInfo
info
=
(
DisplayInfo
)
esOpUtil
.
getInfoById
(
dataBindLabelFrom
.
getIndex
(),
dataBindLabelFrom
.
getId
(),
DisplayInfo
.
class
);
List
<
DictVO
>
boundList
=
dataBindLabelFrom
.
getBindList
();
if
(
info
!=
null
)
{
List
<
String
>
labelMarks
=
new
ArrayList
<>();
List
<
Label
>
newLabels
=
new
ArrayList
<>();
for
(
DictVO
dictVO
:
boundList
)
{
List
<
SysDictItem
>
dictItemList
=
dataBindLabelFrom
.
getDictItemList
();
if
(
StringUtils
.
isNotEmpty
(
dictVO
.
getCode
())){
for
(
SysDictItem
sysDictItem
:
dictItemList
)
{
labelMarks
.
add
(
dictVO
.
getCode
());
Label
label
=
new
Label
();
}
else
{
label
.
setRelationId
(
sysDictItem
.
getId
());
labelMarks
.
add
(
dictVO
.
getLabelMark
());
label
.
setLabelMark
(
sysDictItem
.
getDictCode
());
label
.
setRelationName
(
sysDictItem
.
getItemText
());
newLabels
.
add
(
label
);
}
}
List
<
Label
>
labels
=
info
.
getLabels
();
}
if
(
CollectionUtils
.
isNotEmpty
(
labels
))
{
List
<
Label
>
dbLabels
=
esService
.
getLabelsById
(
dataBindLabelFrom
.
getIndex
(),
dataBindLabelFrom
.
getId
());
List
<
String
>
dictCodes
=
new
ArrayList
<>();
List
<
Label
>
newLabels
=
new
ArrayList
<>();
boundList
.
forEach
(
node
->
dictCodes
.
add
(
node
.
getCode
()));
List
<
SysDictItem
>
dictItemList
=
dataBindLabelFrom
.
getDictItemList
();
List
<
Label
>
collect
=
labels
.
stream
().
filter
(
label
->
dictCodes
.
contains
(
label
.
getLabelMark
())).
collect
(
Collectors
.
toList
());
for
(
SysDictItem
sysDictItem
:
dictItemList
)
{
if
(
CollectionUtils
.
isNotEmpty
(
collect
))
{
Label
label
=
new
Label
();
List
<
String
>
dictItemIds
=
new
ArrayList
<>();
label
.
setRelationId
(
sysDictItem
.
getId
());
dictItemList
.
forEach
(
sysDictItem
->
dictItemIds
.
add
(
sysDictItem
.
getId
()));
label
.
setLabelMark
(
sysDictItem
.
getDictCode
());
for
(
Label
label
:
collect
)
{
label
.
setRelationName
(
sysDictItem
.
getItemText
());
if
(
dictItemIds
.
contains
(
label
.
getRelationId
()))
{
newLabels
.
add
(
label
);
newLabels
.
add
(
label
);
}
}
if
(
CollectionUtils
.
isNotEmpty
(
dbLabels
))
{
List
<
Label
>
collect
=
dbLabels
.
stream
().
filter
(
label
->
labelMarks
.
contains
(
label
.
getLabelMark
())).
collect
(
Collectors
.
toList
());
if
(
CollectionUtils
.
isNotEmpty
(
collect
))
{
List
<
String
>
dictItemIds
=
new
ArrayList
<>();
dictItemList
.
forEach
(
sysDictItem
->
dictItemIds
.
add
(
sysDictItem
.
getId
()));
for
(
Label
label
:
collect
)
{
if
(
dictItemIds
.
contains
(
label
.
getRelationId
()))
{
//数据库中已存在的标签以当前存储为主,不做更新
newLabels
.
removeIf
(
item
->
item
.
getRelationId
().
equals
(
label
.
getRelationId
()));
newLabels
.
add
(
label
);
}
}
}
}
List
<
Label
>
otherCollect
=
labels
.
stream
().
filter
(
label
->
!
dictCodes
.
contains
(
label
.
getLabelMark
())).
collect
(
Collectors
.
toList
());
newLabels
.
addAll
(
otherCollect
);
}
}
List
<
Label
>
finalList
=
newLabels
.
stream
().
collect
(
Collectors
.
collectingAndThen
(
Collectors
.
toMap
(
Label:
:
getRelationId
,
p
->
p
,
(
p1
,
p2
)
->
p1
),
map
->
new
ArrayList
<>(
map
.
values
())));
List
<
Label
>
otherCollect
=
dbLabels
.
stream
().
filter
(
label
->
!
labelMarks
.
contains
(
label
.
getLabelMark
())).
collect
(
Collectors
.
toList
());
info
.
setLabels
(
finalList
);
newLabels
.
addAll
(
otherCollect
);
esOpUtil
.
docUpdateById
(
dataBindLabelFrom
.
getIndex
(),
info
.
getId
(),
JSON
.
toJSONString
(
info
));
}
}
esService
.
updateLabelsById
(
dataBindLabelFrom
.
getIndex
(),
dataBindLabelFrom
.
getId
(),
newLabels
);
}
}
@Override
@Override
...
@@ -1128,6 +1133,16 @@ public class InformationServiceImpl implements InformationService {
...
@@ -1128,6 +1133,16 @@ public class InformationServiceImpl implements InformationService {
return
informationList
;
return
informationList
;
}
}
@Override
public
void
removeLabelById
(
String
index
,
String
id
,
String
relationId
)
{
List
<
Label
>
labels
=
esService
.
getLabelsById
(
index
,
id
);
if
(
labels
==
null
){
return
;
}
labels
.
removeIf
(
e
->
e
.
getRelationId
().
equals
(
relationId
));
esService
.
updateLabelsById
(
index
,
id
,
labels
);
}
private
void
formatLabel
(
List
<
LabelModelVo
>
labelModelVos
,
DisplayInfo
info
)
{
private
void
formatLabel
(
List
<
LabelModelVo
>
labelModelVos
,
DisplayInfo
info
)
{
if
(
CollectionUtils
.
isNotEmpty
(
labelModelVos
))
{
if
(
CollectionUtils
.
isNotEmpty
(
labelModelVos
))
{
List
<
Label
>
list
=
info
.
getLabels
();
List
<
Label
>
list
=
info
.
getLabels
();
...
...
src/main/java/com/zzsn/event/vo/DataBindLabelFrom.java
浏览文件 @
31fb8907
...
@@ -22,4 +22,6 @@ public class DataBindLabelFrom {
...
@@ -22,4 +22,6 @@ public class DataBindLabelFrom {
private
String
subjectId
;
private
String
subjectId
;
/**字典id*/
/**字典id*/
private
List
<
SysDictItem
>
dictItemList
;
private
List
<
SysDictItem
>
dictItemList
;
/**专题绑定的标签类型*/
private
List
<
DictVO
>
bindList
;
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论