Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
gf_back
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
tianchao
gf_back
Commits
2bc14fe1
Commit
2bc14fe1
authored
Sep 12, 2024
by
ZWT
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(吉林演示): 松原
1.天气数据接收定时任务,解决代码扫描问题,修改文件读取相关代码,解决资源未关流问题; BREAKING CHANGE: 无 Closes 无 [skip ci]
parent
710821ad
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
11 deletions
+27
-11
C09-base/pps-core-base/src/main/java/pps/core/base/service/BaseWeatherCloudServiceImpl.java
...va/pps/core/base/service/BaseWeatherCloudServiceImpl.java
+27
-11
No files found.
C09-base/pps-core-base/src/main/java/pps/core/base/service/BaseWeatherCloudServiceImpl.java
View file @
2bc14fe1
...
@@ -6,7 +6,6 @@ import cn.hutool.core.date.DateUtil;
...
@@ -6,7 +6,6 @@ import cn.hutool.core.date.DateUtil;
import
cn.hutool.core.io.FileUtil
;
import
cn.hutool.core.io.FileUtil
;
import
cn.hutool.core.io.IoUtil
;
import
cn.hutool.core.io.IoUtil
;
import
cn.hutool.core.io.NioUtil
;
import
cn.hutool.core.io.NioUtil
;
import
cn.hutool.core.io.file.FileReader
;
import
cn.hutool.core.text.CharSequenceUtil
;
import
cn.hutool.core.text.CharSequenceUtil
;
import
cn.hutool.core.util.ObjectUtil
;
import
cn.hutool.core.util.ObjectUtil
;
import
com.alibaba.fastjson2.JSON
;
import
com.alibaba.fastjson2.JSON
;
...
@@ -59,6 +58,7 @@ public class BaseWeatherCloudServiceImpl implements IBaseWeatherCloudService {
...
@@ -59,6 +58,7 @@ public class BaseWeatherCloudServiceImpl implements IBaseWeatherCloudService {
private
static
final
String
username
=
XStartup
.
getCurrent
().
getProperty
(
"weather.mail.username"
);
private
static
final
String
username
=
XStartup
.
getCurrent
().
getProperty
(
"weather.mail.username"
);
private
static
final
String
password
=
XStartup
.
getCurrent
().
getProperty
(
"weather.mail.password"
);
private
static
final
String
password
=
XStartup
.
getCurrent
().
getProperty
(
"weather.mail.password"
);
private
static
final
String
protocol
=
XStartup
.
getCurrent
().
getProperty
(
"weather.mail.protocol"
);
private
static
final
String
protocol
=
XStartup
.
getCurrent
().
getProperty
(
"weather.mail.protocol"
);
private
static
final
String
storeDir
=
XStartup
.
getCurrent
().
getProperty
(
"weather.file.temp.path"
);
/**
/**
* 天气数据接收Cloud模块--天气数据处理
* 天气数据接收Cloud模块--天气数据处理
...
@@ -95,9 +95,7 @@ public class BaseWeatherCloudServiceImpl implements IBaseWeatherCloudService {
...
@@ -95,9 +95,7 @@ public class BaseWeatherCloudServiceImpl implements IBaseWeatherCloudService {
re
.
getMailContent
(
message
);
re
.
getMailContent
(
message
);
String
tempFilePath
=
this
.
saveAttachment
(
message
);
String
tempFilePath
=
this
.
saveAttachment
(
message
);
logger
.
info
(
"------ weatherDataProcess load file: {}"
,
tempFilePath
);
logger
.
info
(
"------ weatherDataProcess load file: {}"
,
tempFilePath
);
FileReader
fileReader
=
new
FileReader
(
tempFilePath
);
JSONObject
jsonObject
=
JSON
.
parseObject
(
FileUtil
.
readUtf8String
(
tempFilePath
));
String
jsonString
=
fileReader
.
readString
();
JSONObject
jsonObject
=
JSON
.
parseObject
(
jsonString
);
jsonObjectList
.
add
(
jsonObject
);
jsonObjectList
.
add
(
jsonObject
);
logger
.
info
(
"------ weatherDataProcess del temp file path: {}"
,
tempFilePath
);
logger
.
info
(
"------ weatherDataProcess del temp file path: {}"
,
tempFilePath
);
FileUtil
.
del
(
tempFilePath
);
FileUtil
.
del
(
tempFilePath
);
...
@@ -180,9 +178,8 @@ public class BaseWeatherCloudServiceImpl implements IBaseWeatherCloudService {
...
@@ -180,9 +178,8 @@ public class BaseWeatherCloudServiceImpl implements IBaseWeatherCloudService {
re
.
getMailContent
(
message
);
re
.
getMailContent
(
message
);
String
tempFilePath
=
this
.
saveAttachment
(
message
);
String
tempFilePath
=
this
.
saveAttachment
(
message
);
logger
.
info
(
"------ weatherApiDataProcess load file: {}"
,
tempFilePath
);
logger
.
info
(
"------ weatherApiDataProcess load file: {}"
,
tempFilePath
);
FileReader
fileReader
=
new
FileReader
(
tempFilePath
);
String
jsonString
=
fileReader
.
readString
();
//处理读取流部分数据丢失精度问题
//处理读取流部分数据丢失精度问题
String
jsonString
=
FileUtil
.
readUtf8String
(
tempFilePath
);
jsonString
=
CharSequenceUtil
.
replace
(
jsonString
,
"%"
,
"."
);
jsonString
=
CharSequenceUtil
.
replace
(
jsonString
,
"%"
,
"."
);
List
<
Weather15mData
>
weather15mDataList
=
JSON
.
parseArray
(
jsonString
,
Weather15mData
.
class
);
List
<
Weather15mData
>
weather15mDataList
=
JSON
.
parseArray
(
jsonString
,
Weather15mData
.
class
);
if
(
CollUtil
.
isEmpty
(
weather15mDataList
))
{
if
(
CollUtil
.
isEmpty
(
weather15mDataList
))
{
...
@@ -370,15 +367,13 @@ public class BaseWeatherCloudServiceImpl implements IBaseWeatherCloudService {
...
@@ -370,15 +367,13 @@ public class BaseWeatherCloudServiceImpl implements IBaseWeatherCloudService {
if
(
CharSequenceUtil
.
isNotEmpty
(
fileName
)
&&
StringUtils
.
lowerCase
(
fileName
).
contains
(
"GB2312"
))
{
if
(
CharSequenceUtil
.
isNotEmpty
(
fileName
)
&&
StringUtils
.
lowerCase
(
fileName
).
contains
(
"GB2312"
))
{
fileName
=
MimeUtility
.
decodeText
(
fileName
);
fileName
=
MimeUtility
.
decodeText
(
fileName
);
}
}
fileName
=
CharSequenceUtil
.
replace
(
fileName
,
"\\?|="
,
""
);
filePath
=
this
.
saveTempFile
(
mPart
,
CharSequenceUtil
.
replace
(
fileName
,
"\\?|="
,
""
));
filePath
=
this
.
saveTempFile
(
fileName
,
mPart
.
getInputStream
());
}
else
if
(
mPart
.
isMimeType
(
"multipart/*"
))
{
}
else
if
(
mPart
.
isMimeType
(
"multipart/*"
))
{
this
.
saveAttachment
(
mPart
);
this
.
saveAttachment
(
mPart
);
}
else
{
}
else
{
fileName
=
mPart
.
getFileName
();
fileName
=
mPart
.
getFileName
();
if
(
CharSequenceUtil
.
isNotEmpty
(
fileName
)
&&
StringUtils
.
lowerCase
(
fileName
).
contains
(
"GB2312"
))
{
if
(
CharSequenceUtil
.
isNotEmpty
(
fileName
)
&&
StringUtils
.
lowerCase
(
fileName
).
contains
(
"GB2312"
))
{
fileName
=
MimeUtility
.
decodeText
(
fileName
);
filePath
=
this
.
saveTempFile
(
mPart
,
MimeUtility
.
decodeText
(
fileName
));
filePath
=
this
.
saveTempFile
(
fileName
,
mPart
.
getInputStream
());
}
}
}
}
}
}
...
@@ -396,7 +391,6 @@ public class BaseWeatherCloudServiceImpl implements IBaseWeatherCloudService {
...
@@ -396,7 +391,6 @@ public class BaseWeatherCloudServiceImpl implements IBaseWeatherCloudService {
* @return {@link String}
* @return {@link String}
*/
*/
private
String
saveTempFile
(
String
fileName
,
InputStream
in
)
{
private
String
saveTempFile
(
String
fileName
,
InputStream
in
)
{
String
storeDir
=
XStartup
.
getCurrent
().
getProperty
(
"weather.file.temp.path"
);
StringBuilder
stringBuilder
=
new
StringBuilder
(
storeDir
)
StringBuilder
stringBuilder
=
new
StringBuilder
(
storeDir
)
.
append
(
File
.
separator
)
.
append
(
File
.
separator
)
.
append
(
DateTime
.
now
().
toString
(
"yyyyMMdd"
));
.
append
(
DateTime
.
now
().
toString
(
"yyyyMMdd"
));
...
@@ -407,6 +401,28 @@ public class BaseWeatherCloudServiceImpl implements IBaseWeatherCloudService {
...
@@ -407,6 +401,28 @@ public class BaseWeatherCloudServiceImpl implements IBaseWeatherCloudService {
return
filePath
;
return
filePath
;
}
}
/**
* 保存临时文件
*
* @param mPart m部分
* @param fileName 文件名
* @return {@link String }
*/
private
String
saveTempFile
(
BodyPart
mPart
,
String
fileName
)
{
String
filePath
;
try
(
InputStream
inputStream
=
mPart
.
getInputStream
())
{
StringBuilder
stringBuilder
=
new
StringBuilder
(
storeDir
)
.
append
(
File
.
separator
)
.
append
(
DateTime
.
now
().
toString
(
"yyyyMMdd"
));
filePath
=
stringBuilder
.
append
(
File
.
separator
).
append
(
fileName
).
toString
();
FileUtil
.
touch
(
filePath
);
FileUtil
.
writeFromStream
(
inputStream
,
filePath
);
}
catch
(
IOException
|
MessagingException
e
)
{
throw
new
RuntimeException
(
e
);
}
return
filePath
;
}
/**
/**
* 零填充
* 零填充
*
*
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment