Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
E
event
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
陈世强
event
Commits
1d03540e
提交
1d03540e
authored
4月 14, 2025
作者:
yanxin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
资讯标编辑新增base64转图片处理
上级
fb64d8ca
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
59 行增加
和
2 行删除
+59
-2
InformationServiceImpl.java
...a/com/zzsn/event/service/impl/InformationServiceImpl.java
+6
-2
ImageUtil.java
src/main/java/com/zzsn/event/util/ImageUtil.java
+53
-0
没有找到文件。
src/main/java/com/zzsn/event/service/impl/InformationServiceImpl.java
浏览文件 @
1d03540e
...
...
@@ -20,8 +20,6 @@ import com.zzsn.event.es.EsService;
import
com.zzsn.event.mapper.SubjectMapper
;
import
com.zzsn.event.service.*
;
import
com.zzsn.event.util.*
;
import
com.zzsn.event.util.tree.Node
;
import
com.zzsn.event.util.user.AuthUtil
;
import
com.zzsn.event.util.user.UserUtil
;
import
com.zzsn.event.util.user.UserVo
;
import
com.zzsn.event.vo.*
;
...
...
@@ -92,6 +90,8 @@ public class InformationServiceImpl implements InformationService {
private
SysDictItemService
sysDictItemService
;
@Autowired
private
PythonUtil
pythonUtil
;
@Autowired
private
ImageUtil
imageUtil
;
private
String
subjectId
=
"1898653164373065730"
;
//中外智库专栏对应专题id
@Override
...
...
@@ -629,10 +629,14 @@ public class InformationServiceImpl implements InformationService {
if
(
StringUtils
.
isNotBlank
(
specialInformation
.
getContentWithTag
()))
{
String
content
=
Jsoup
.
parse
(
specialInformation
.
getContentWithTag
()).
text
();
specialInformation
.
setContent
(
content
);
//base64图片转url
specialInformation
.
setContentWithTag
(
imageUtil
.
changeBase64ToUrl
(
specialInformation
.
getContentWithTag
()));
}
if
(
StringUtils
.
isNotBlank
(
specialInformation
.
getContentWithTagRaw
()))
{
String
contentRaw
=
Jsoup
.
parse
(
specialInformation
.
getContentWithTagRaw
()).
text
();
specialInformation
.
setContentRaw
(
contentRaw
);
//base64图片转url
specialInformation
.
setContentWithTag
(
imageUtil
.
changeBase64ToUrl
(
specialInformation
.
getContentWithTag
()));
}
//处理时间格式
specialInformation
.
setPublishDate
(
EsDateUtil
.
esFieldDateFormat
(
specialInformation
.
getPublishDate
()));
...
...
src/main/java/com/zzsn/event/util/ImageUtil.java
0 → 100644
浏览文件 @
1d03540e
package
com
.
zzsn
.
event
.
util
;
import
cn.hutool.http.HttpUtil
;
import
com.alibaba.fastjson2.JSON
;
import
com.alibaba.fastjson2.JSONObject
;
import
lombok.extern.slf4j.Slf4j
;
import
org.jsoup.Jsoup
;
import
org.jsoup.nodes.Document
;
import
org.jsoup.nodes.Element
;
import
org.jsoup.select.Elements
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Component
;
@Component
@Slf4j
public
class
ImageUtil
{
@Value
(
"${util.getUrlPath:https://clb.ciglobal.cn/clb-api/common/getUrlByBase64Data}"
)
private
String
getUrlPath
;
/**
* base64图片转url
* @param html
*/
public
String
changeBase64ToUrl
(
String
html
){
try
{
Document
htmlDoc
=
Jsoup
.
parse
(
html
);
Elements
imgs
=
htmlDoc
.
select
(
"img"
);
// 获取所有的<img>标签
boolean
flag
=
false
;
for
(
Element
img
:
imgs
)
{
// 获取src属性
String
baseData
=
img
.
attr
(
"src"
);
if
(
baseData
!=
null
&&
baseData
.
startsWith
(
"data:image/"
)){
//base64图片,需要转为url存储
String
post
=
HttpUtil
.
post
(
getUrlPath
,
baseData
);
JSONObject
jsonObject
=
JSON
.
parseObject
(
post
);
if
(
jsonObject
.
getInteger
(
"code"
)
==
200
){
log
.
info
(
"base64图片转url成功:{}"
,
jsonObject
.
getString
(
"result"
));
img
.
attr
(
"src"
,
jsonObject
.
getString
(
"result"
));
flag
=
true
;
}
}
}
if
(
flag
){
html
=
htmlDoc
.
html
();
}
}
catch
(
Exception
e
){
log
.
error
(
"base64图片转url失败:{}"
,
e
.
getMessage
());
}
return
html
;
}
}
\ No newline at end of file
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论